Skip to content

Commit

Permalink
Implemented spPruneRedundantTriangles for BSTriShape geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed May 25, 2024
1 parent 912668d commit ba14cda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Added limited (read only) Starfield support to the UV editor.
* Implemented texture slot selection in the UV editor for Fallout 3 and newer games.
* Fixed textures not being rendered in the UV editor.
* Implemented the Prune Triangles mesh spell for games using BSTriShape geometry.
* Layered emissivity settings are now shown in Starfield BSLightingShaderProperty blocks.
* Starfield rendering fixes.

Expand Down
13 changes: 10 additions & 3 deletions src/spells/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,19 @@ class spPruneRedundantTriangles final : public Spell

bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->blockInherits( index, "BSTriShape" ) && nif->getIndex( index, "Triangles" ).isValid() )
return true;
return getTriShapeData( nif, index ).isValid();
}

QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final
{
QModelIndex iData = getTriShapeData( nif, index );

QModelIndex iData;
bool isBSTriShape = nif->blockInherits( index, "BSTriShape" );
if ( !isBSTriShape )
iData = getTriShapeData( nif, index );
else
iData = index;
QList<Triangle> tris = nif->getArray<Triangle>( iData, "Triangles" ).toList();
int cnt = 0;

Expand Down Expand Up @@ -447,7 +453,8 @@ class spPruneRedundantTriangles final : public Spell
if ( cnt > 0 ) {
Message::info( nullptr, Spell::tr( "Removed %1 triangles" ).arg( cnt ) );
nif->set<int>( iData, "Num Triangles", tris.count() );
nif->set<int>( iData, "Num Triangle Points", tris.count() * 3 );
if ( !isBSTriShape )
nif->set<int>( iData, "Num Triangle Points", tris.count() * 3 );
nif->updateArraySize( iData, "Triangles" );
nif->setArray<Triangle>( iData, "Triangles", tris.toVector() );
}
Expand Down

0 comments on commit ba14cda

Please sign in to comment.