Skip to content

Commit 46a2e38

Browse files
committed
TextureTool set vertex colors on parallax
1 parent 7d0e9e1 commit 46a2e38

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

gui/src/models/NIFTreeModel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ QVariant NIFTreeModel::data(const QModelIndex& index, int role) const
6464
if (role != Qt::DisplayRole)
6565
return QVariant();
6666

67-
if (index.internalId() == -1 && index.row() < _files.size())
67+
if (index.internalId() == (quintptr)-1 && index.row() < _files.size())
6868
{
6969
return _files.at(index.row()).fileName.c_str();
7070
}
@@ -101,7 +101,7 @@ QModelIndex NIFTreeModel::index(int row, int col, const QModelIndex& parent) con
101101

102102
if (!parent.isValid())
103103
{
104-
return createIndex(row, col, -1);
104+
return createIndex(row, col, (quintptr)-1);
105105
}
106106

107107
return createIndex(row, col, parent.row());
@@ -112,18 +112,18 @@ QModelIndex NIFTreeModel::parent(const QModelIndex& index) const
112112
if (!index.isValid())
113113
return QModelIndex();
114114

115-
if (index.internalId() == -1)
115+
if (index.internalId() == (quintptr)-1)
116116
return QModelIndex();
117117

118-
return createIndex(index.internalId(), 0, -1);
118+
return createIndex(index.internalId(), 0, (quintptr)-1);
119119
}
120120

121121
int NIFTreeModel::rowCount(const QModelIndex& index) const
122122
{
123123
if (!index.isValid())
124124
return _files.size();
125125

126-
if (index.internalId() == -1 && index.row() < _files.size())
126+
if (index.internalId() == (quintptr)-1 && index.row() < _files.size())
127127
{
128128
auto& nif_file = _files.at(index.row());
129129
return nif_file.getNumBlocks({ NiTriShape::TYPE, BSTriShape::TYPE });

gui/src/widgets/TextureTool.cpp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,51 @@ void TextureTool::on_nifView_selectionChanged(const QModelIndex& current, const
176176
{
177177
if (viewModeCheckBox->isChecked())
178178
{
179-
populateValues(current);
179+
populateValues(_proxyModel->mapToSource(current));
180180
}
181181
}
182182

183-
void TextureTool::SetShaderType(BSLightingShaderPropertyRef property)
183+
void TextureTool::CheckShaderRequirements(BSLightingShaderPropertyShaderType type, NiAVObjectRef obj)
184+
{
185+
if (type == ST_PARALLAX)
186+
{
187+
//needs VC
188+
if (obj->IsSameType(BSTriShape::TYPE))
189+
{
190+
auto bs_shape = DynamicCast<BSTriShape>(obj);
191+
bool hasVC = bs_shape->GetVertexDesc().HasFlag(VA_Vertex_Colors);
192+
if (!bs_shape->GetVertexDesc().HasFlag(VA_Vertex_Colors))
193+
{
194+
auto desc = bs_shape->GetVertexDesc();
195+
desc.SetFlag(VA_Vertex_Colors);
196+
auto data = bs_shape->GetVertexData();
197+
for (auto& entry : data)
198+
{
199+
entry.SetVertexColor(Niflib::Color4(1., 1., 1.));
200+
}
201+
bs_shape->SetVertexData(data);
202+
bs_shape->SetVertexDesc(desc);
203+
}
204+
}
205+
else if (obj->IsSameType(NiTriShape::TYPE))
206+
{
207+
auto ni_shape = DynamicCast<NiTriShape>(obj);
208+
if (ni_shape->GetData()->GetVertexColors().empty())
209+
{
210+
auto colors = vector<Niflib::Color4>(ni_shape->GetData()->GetVertices().size(), Niflib::Color4(1., 1., 1.));
211+
ni_shape->GetData()->SetVertexColors(colors);
212+
ni_shape->GetData()->SetHasVertexColors(true);
213+
}
214+
}
215+
}
216+
}
217+
218+
BSLightingShaderPropertyShaderType TextureTool::SetShaderType(BSLightingShaderPropertyRef property)
184219
{
185220
auto type = (BSLightingShaderPropertyShaderType)shaderTypeComboBox->currentIndex();
186221
LOGINFO << "Setting shader type: " << NifFile::shader_type_name(type) << endl;
187222
property->SetSkyrimShaderType(type);
223+
return type;
188224
}
189225

190226
void TextureTool::SetTextures(BSLightingShaderPropertyRef property)
@@ -270,7 +306,7 @@ void TextureTool::accept()
270306
bool setShaderFlags = shaderFlagsCheckBox->isChecked();
271307
bool viewMode = viewModeCheckBox->isChecked();
272308

273-
if (!viewMode && (overrideTextures || setShaderFlags || viewMode))
309+
if (!viewMode && (overrideTextures || setShaderFlags || setShaderType))
274310
{
275311
auto selection = nifView->selectionModel()->selectedIndexes();
276312
if (!selection.empty())
@@ -281,8 +317,9 @@ void TextureTool::accept()
281317
if (reply == QMessageBox::Yes) {
282318
LOGINFO << "Tool running" << endl;
283319
QModelIndex last_file_index = QModelIndex();
284-
for (auto& index : selection)
320+
for (auto& proxy_index : selection)
285321
{
322+
auto index = _proxyModel->mapToSource(proxy_index);
286323
auto block = _model->block(index);
287324
LOGINFO << "Block: " << block->GetName() << endl;
288325
if (nullptr != block)
@@ -293,7 +330,10 @@ void TextureTool::accept()
293330
if (nullptr != property)
294331
{
295332
if (setShaderType)
296-
SetShaderType(property);
333+
{
334+
auto type = SetShaderType(property);
335+
CheckShaderRequirements(type, block);
336+
}
297337
if (overrideTextures)
298338
SetTextures(property);
299339
if (setShaderFlags)

gui/src/widgets/TextureTool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class TextureTool : public QDialog, private Ui::TextureTool
2020

2121
void populateValues(const QModelIndex& current);
2222

23-
void SetShaderType(Niflib::BSLightingShaderPropertyRef property);
23+
Niflib::BSLightingShaderPropertyShaderType SetShaderType(Niflib::BSLightingShaderPropertyRef property);
2424
void SetTextures(Niflib::BSLightingShaderPropertyRef property);
2525
void SetFlags(Niflib::BSLightingShaderPropertyRef property);
26+
void CheckShaderRequirements(Niflib::BSLightingShaderPropertyShaderType type, Niflib::NiAVObjectRef obj);
2627

2728
private slots:
2829

0 commit comments

Comments
 (0)