From 46a2e38202c721981f901cd1cff431960668f262 Mon Sep 17 00:00:00 2001 From: Edoardo Canepa Date: Thu, 1 Sep 2022 16:59:16 +0200 Subject: [PATCH] TextureTool set vertex colors on parallax --- gui/src/models/NIFTreeModel.cpp | 10 +++---- gui/src/widgets/TextureTool.cpp | 50 +++++++++++++++++++++++++++++---- gui/src/widgets/TextureTool.h | 3 +- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/gui/src/models/NIFTreeModel.cpp b/gui/src/models/NIFTreeModel.cpp index f63ee09..17ab826 100644 --- a/gui/src/models/NIFTreeModel.cpp +++ b/gui/src/models/NIFTreeModel.cpp @@ -64,7 +64,7 @@ QVariant NIFTreeModel::data(const QModelIndex& index, int role) const if (role != Qt::DisplayRole) return QVariant(); - if (index.internalId() == -1 && index.row() < _files.size()) + if (index.internalId() == (quintptr)-1 && index.row() < _files.size()) { return _files.at(index.row()).fileName.c_str(); } @@ -101,7 +101,7 @@ QModelIndex NIFTreeModel::index(int row, int col, const QModelIndex& parent) con if (!parent.isValid()) { - return createIndex(row, col, -1); + return createIndex(row, col, (quintptr)-1); } return createIndex(row, col, parent.row()); @@ -112,10 +112,10 @@ QModelIndex NIFTreeModel::parent(const QModelIndex& index) const if (!index.isValid()) return QModelIndex(); - if (index.internalId() == -1) + if (index.internalId() == (quintptr)-1) return QModelIndex(); - return createIndex(index.internalId(), 0, -1); + return createIndex(index.internalId(), 0, (quintptr)-1); } int NIFTreeModel::rowCount(const QModelIndex& index) const @@ -123,7 +123,7 @@ int NIFTreeModel::rowCount(const QModelIndex& index) const if (!index.isValid()) return _files.size(); - if (index.internalId() == -1 && index.row() < _files.size()) + if (index.internalId() == (quintptr)-1 && index.row() < _files.size()) { auto& nif_file = _files.at(index.row()); return nif_file.getNumBlocks({ NiTriShape::TYPE, BSTriShape::TYPE }); diff --git a/gui/src/widgets/TextureTool.cpp b/gui/src/widgets/TextureTool.cpp index 92c7453..51c0b9f 100644 --- a/gui/src/widgets/TextureTool.cpp +++ b/gui/src/widgets/TextureTool.cpp @@ -176,15 +176,51 @@ void TextureTool::on_nifView_selectionChanged(const QModelIndex& current, const { if (viewModeCheckBox->isChecked()) { - populateValues(current); + populateValues(_proxyModel->mapToSource(current)); } } -void TextureTool::SetShaderType(BSLightingShaderPropertyRef property) +void TextureTool::CheckShaderRequirements(BSLightingShaderPropertyShaderType type, NiAVObjectRef obj) +{ + if (type == ST_PARALLAX) + { + //needs VC + if (obj->IsSameType(BSTriShape::TYPE)) + { + auto bs_shape = DynamicCast(obj); + bool hasVC = bs_shape->GetVertexDesc().HasFlag(VA_Vertex_Colors); + if (!bs_shape->GetVertexDesc().HasFlag(VA_Vertex_Colors)) + { + auto desc = bs_shape->GetVertexDesc(); + desc.SetFlag(VA_Vertex_Colors); + auto data = bs_shape->GetVertexData(); + for (auto& entry : data) + { + entry.SetVertexColor(Niflib::Color4(1., 1., 1.)); + } + bs_shape->SetVertexData(data); + bs_shape->SetVertexDesc(desc); + } + } + else if (obj->IsSameType(NiTriShape::TYPE)) + { + auto ni_shape = DynamicCast(obj); + if (ni_shape->GetData()->GetVertexColors().empty()) + { + auto colors = vector(ni_shape->GetData()->GetVertices().size(), Niflib::Color4(1., 1., 1.)); + ni_shape->GetData()->SetVertexColors(colors); + ni_shape->GetData()->SetHasVertexColors(true); + } + } + } +} + +BSLightingShaderPropertyShaderType TextureTool::SetShaderType(BSLightingShaderPropertyRef property) { auto type = (BSLightingShaderPropertyShaderType)shaderTypeComboBox->currentIndex(); LOGINFO << "Setting shader type: " << NifFile::shader_type_name(type) << endl; property->SetSkyrimShaderType(type); + return type; } void TextureTool::SetTextures(BSLightingShaderPropertyRef property) @@ -270,7 +306,7 @@ void TextureTool::accept() bool setShaderFlags = shaderFlagsCheckBox->isChecked(); bool viewMode = viewModeCheckBox->isChecked(); - if (!viewMode && (overrideTextures || setShaderFlags || viewMode)) + if (!viewMode && (overrideTextures || setShaderFlags || setShaderType)) { auto selection = nifView->selectionModel()->selectedIndexes(); if (!selection.empty()) @@ -281,8 +317,9 @@ void TextureTool::accept() if (reply == QMessageBox::Yes) { LOGINFO << "Tool running" << endl; QModelIndex last_file_index = QModelIndex(); - for (auto& index : selection) + for (auto& proxy_index : selection) { + auto index = _proxyModel->mapToSource(proxy_index); auto block = _model->block(index); LOGINFO << "Block: " << block->GetName() << endl; if (nullptr != block) @@ -293,7 +330,10 @@ void TextureTool::accept() if (nullptr != property) { if (setShaderType) - SetShaderType(property); + { + auto type = SetShaderType(property); + CheckShaderRequirements(type, block); + } if (overrideTextures) SetTextures(property); if (setShaderFlags) diff --git a/gui/src/widgets/TextureTool.h b/gui/src/widgets/TextureTool.h index 06cfd7a..8e4a81a 100644 --- a/gui/src/widgets/TextureTool.h +++ b/gui/src/widgets/TextureTool.h @@ -20,9 +20,10 @@ class TextureTool : public QDialog, private Ui::TextureTool void populateValues(const QModelIndex& current); - void SetShaderType(Niflib::BSLightingShaderPropertyRef property); + Niflib::BSLightingShaderPropertyShaderType SetShaderType(Niflib::BSLightingShaderPropertyRef property); void SetTextures(Niflib::BSLightingShaderPropertyRef property); void SetFlags(Niflib::BSLightingShaderPropertyRef property); + void CheckShaderRequirements(Niflib::BSLightingShaderPropertyShaderType type, Niflib::NiAVObjectRef obj); private slots: