@@ -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
190226void 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)
0 commit comments