Skip to content

Commit

Permalink
TextureTool set vertex colors on parallax
Browse files Browse the repository at this point in the history
  • Loading branch information
aerisarn committed Sep 1, 2022
1 parent 7d0e9e1 commit 46a2e38
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
10 changes: 5 additions & 5 deletions gui/src/models/NIFTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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());
Expand All @@ -112,18 +112,18 @@ 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
{
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 });
Expand Down
50 changes: 45 additions & 5 deletions gui/src/widgets/TextureTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BSTriShape>(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<NiTriShape>(obj);
if (ni_shape->GetData()->GetVertexColors().empty())
{
auto colors = vector<Niflib::Color4>(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)
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion gui/src/widgets/TextureTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 46a2e38

Please sign in to comment.