Skip to content

Commit

Permalink
Use NifModel::checkInternalGeometry() in spells
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Oct 17, 2024
1 parent e93cdb2 commit d8dd116
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
== CHANGELOG ==

#### NifSkope-2.0.dev9-20241017

* The UV editor now allows selecting Starfield textures from all layers, and also blender masks. Textures are rendered in the editor with the UV scale, offset and wrap mode applied. The latter change is implemented for Skyrim to Fallout 76 as well, but wrap modes are not fully supported.
* Starfield texture coordinate sets can be selected in the UV editor, if the mesh has more than one and internal geometry is being used.
* Implemented support for editing and saving Starfield hair and vegetation settings. Note however that currently only hair roughness is used by the renderer.
Expand Down
43 changes: 25 additions & 18 deletions src/spells/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ class spFlipTexCoords final : public Spell

bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) )
return bool( nif->get<quint32>( index, "Flags" ) & 0x0200 );
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return true;
if ( nif->blockInherits( index, "BSTriShape" ) && nif->getIndex( index, "Vertex Data" ).isValid() )
return true;
return nif->itemStrType( index ).toLower() == "texcoord" || nif->blockInherits( index, "NiTriBasedGeomData" );
Expand All @@ -358,6 +358,8 @@ class spFlipTexCoords final : public Spell
} else if ( nif->itemStrType( index ).toLower() != "texcoord" ) {
idx = nif->getIndex( nif->getBlockIndex( index ), "UV Sets" );
}
} else if ( !nif->checkInternalGeometry( index ) ) {
return index;
}

QMenu menu;
Expand Down Expand Up @@ -546,8 +548,8 @@ class spFlipAllFaces final : public Spell

bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) )
return bool( nif->get<quint32>( index, "Flags" ) & 0x0200 );
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return true;
return getTriShapeData( nif, index ).isValid();
}

Expand All @@ -556,7 +558,8 @@ class spFlipAllFaces final : public Spell
QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) ) {
cast_Starfield( nif, index );
if ( nif->checkInternalGeometry( index ) )
cast_Starfield( nif, index );
return index;
}
QModelIndex iData = getTriShapeData( nif, index );
Expand Down Expand Up @@ -634,8 +637,8 @@ class spPruneRedundantTriangles final : public Spell

bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) )
return bool( nif->get<quint32>( index, "Flags" ) & 0x0200 );
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return true;
if ( nif->blockInherits( index, "BSTriShape" ) && nif->getIndex( index, "Triangles" ).isValid() )
return true;
return getTriShapeData( nif, index ).isValid();
Expand All @@ -654,9 +657,11 @@ class spPruneRedundantTriangles final : public Spell
QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) ) {
nif->setState( BaseModel::Processing );
cast_Starfield( nif, index );
nif->restoreState();
if ( nif->checkInternalGeometry( index ) ) {
nif->setState( BaseModel::Processing );
cast_Starfield( nif, index );
nif->restoreState();
}
return index;
}

Expand Down Expand Up @@ -839,8 +844,8 @@ class spRemoveDuplicateVertices final : public Spell

bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) )
return bool( nif->get<quint32>( index, "Flags" ) & 0x0200 );
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return true;
return spRemoveWasteVertices::getShape( nif, index ).isValid();
}

Expand All @@ -849,7 +854,7 @@ class spRemoveDuplicateVertices final : public Spell
QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) ) {
if ( nif->get<quint32>( index, "Flags" ) & 0x0200 ) {
if ( nif->checkInternalGeometry( index ) ) {
nif->setState( BaseModel::Processing );
cast_Starfield( nif, index );
spRemoveWasteVertices::cast_Starfield( nif, index, false );
Expand Down Expand Up @@ -1324,9 +1329,11 @@ void spRemoveWasteVertices::cast_Starfield( NifModel * nif, const QModelIndex &
QModelIndex spRemoveWasteVertices::cast( NifModel * nif, const QModelIndex & index )
{
if ( nif->blockInherits( index, "BSGeometry" ) ) {
nif->setState( BaseModel::Processing );
cast_Starfield( nif, index );
nif->restoreState();
if ( nif->checkInternalGeometry( index ) ) {
nif->setState( BaseModel::Processing );
cast_Starfield( nif, index );
nif->restoreState();
}
} else if ( nif->blockInherits( index, "BSTriShape" ) ) {
removeWasteVertices( nif, index );
} else {
Expand Down Expand Up @@ -1799,11 +1806,11 @@ QModelIndex spGenerateMeshlets::cast( NifModel * nif, const QModelIndex & index
return index;
}

if ( !nif->blockInherits( index, "BSGeometry" ) )
if ( !( nif->isNiBlock( index, "BSGeometry" ) && nif->checkInternalGeometry( index ) ) )
return index;

auto meshes = nif->getIndex( index, "Meshes" );
if ( meshes.isValid() && ( nif->get<quint32>(index, "Flags") & 0x0200 ) != 0 ) {
if ( meshes.isValid() ) {
for ( int i = 0; i <= 3; i++ ) {
auto mesh = nif->getIndex( meshes, i );
if ( !mesh.isValid() )
Expand Down
6 changes: 3 additions & 3 deletions src/spells/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class spGenerateMeshlets final : public Spell
return false;
if ( !index.isValid() )
return true;
return ( nif->blockInherits( index, "BSGeometry" ) && ( nif->get<quint32>(index, "Flags") & 0x0200 ) != 0 );
return nif->isNiBlock( index, "BSGeometry" );
}

static void clearMeshlets( NifModel * nif, const QModelIndex & iMeshData );
Expand All @@ -85,8 +85,8 @@ class spRemoveWasteVertices final : public Spell
{
if ( !nif )
return false;
if ( nif->getBSVersion() >= 170 && nif->blockInherits( index, "BSGeometry" ) )
return bool( nif->get<quint32>(index, "Flags") & 0x0200 );
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return true;
if ( nif->blockInherits( index, "BSTriShape" ) )
return nif->getIndex( index, "Vertex Data" ).isValid();
return getShape( nif, index ).isValid();
Expand Down
14 changes: 8 additions & 6 deletions src/spells/normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class spFaceNormals final : public Spell
bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return ( ( nif->get<quint32>(index, "Flags") & 0x0200 ) != 0 );
return true;
return getShapeData( nif, index ).isValid();
}

Expand All @@ -73,7 +73,8 @@ class spFaceNormals final : public Spell
QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) ) {
faceNormalsSFMesh( nif, index );
if ( nif->checkInternalGeometry( index ) )
faceNormalsSFMesh( nif, index );
return index;
}

Expand Down Expand Up @@ -267,7 +268,7 @@ class spFlipNormals final : public Spell
bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return ( ( nif->get<quint32>(index, "Flags") & 0x0200 ) != 0 );
return true;
QModelIndex iData = spFaceNormals::getShapeData( nif, index );
return ( iData.isValid() && nif->get<bool>( iData, "Has Normals" ) );
}
Expand All @@ -277,7 +278,8 @@ class spFlipNormals final : public Spell
QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) ) {
flipNormalsSFMesh( nif, index );
if ( nif->checkInternalGeometry( index ) )
flipNormalsSFMesh( nif, index );
return index;
}

Expand Down Expand Up @@ -335,7 +337,7 @@ class spSmoothNormals final : public Spell
bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->getBSVersion() >= 170 && nif->isNiBlock( index, "BSGeometry" ) )
return ( ( nif->get<quint32>(index, "Flags") & 0x0200 ) != 0 );
return true;
return spFaceNormals::getShapeData( nif, index ).isValid();
}

Expand All @@ -359,7 +361,7 @@ class spSmoothNormals final : public Spell

if ( !isSFMesh )
smoothNormals( nif, index, maxa, maxd );
else
else if ( nif->checkInternalGeometry( index ) )
smoothNormalsSFMesh( nif, index, maxa, maxd );

return index;
Expand Down
4 changes: 2 additions & 2 deletions src/spells/simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class spSimplifySFMesh final : public Spell
return false;
if ( !index.isValid() )
return true;
return ( nif->blockInherits( index, "BSGeometry" ) && ( nif->get<quint32>(index, "Flags") & 0x0200 ) != 0 );
return nif->isNiBlock( index, "BSGeometry" );
}

QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final;
Expand Down Expand Up @@ -366,7 +366,7 @@ void spSimplifySFMesh::Meshes::saveGeometryData( NifModel * nif ) const

QModelIndex spSimplifySFMesh::cast( NifModel * nif, const QModelIndex & index )
{
if ( !( nif && nif->getBSVersion() >= 170 ) )
if ( !( nif && nif->getBSVersion() >= 170 && nif->checkInternalGeometry( index ) ) )
return index;

Meshes m;
Expand Down
5 changes: 3 additions & 2 deletions src/spells/tangentspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bool spTangentSpace::isApplicable( const NifModel * nif, const QModelIndex & ind
if ( !i )
return false;
if ( nif->isNiBlock( index, "BSGeometry" ) )
return ( ( nif->get<quint32>(i, "Flags") & 0x0200 ) != 0 );
return true;
return i->hasStrType( "BSMeshData" );
}

Expand Down Expand Up @@ -51,7 +51,8 @@ bool spTangentSpace::isApplicable( const NifModel * nif, const QModelIndex & ind
QModelIndex spTangentSpace::cast( NifModel * nif, const QModelIndex & iBlock )
{
if ( nif->getBSVersion() >= 170 ) {
tangentSpaceSFMesh( nif, iBlock );
if ( nif->checkInternalGeometry( iBlock ) )
tangentSpaceSFMesh( nif, iBlock );
return iBlock;
}

Expand Down
5 changes: 3 additions & 2 deletions src/spells/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class spScaleVertices final : public Spell
{
return ( nif->blockInherits( index, "NiGeometry" )
|| ( nif->blockInherits( index, "BSTriShape" ) && nif->getIndex( index, "Vertex Data" ).isValid() )
|| ( nif->blockInherits( index, "BSGeometry" ) && ( nif->get<quint32>(index, "Flags") & 0x0200 ) ) );
|| nif->isNiBlock( index, "BSGeometry" ) );
}

static void cast_Starfield( NifModel * nif, const QModelIndex & index, FloatVector4 scaleVector, bool scaleNormals );
Expand Down Expand Up @@ -438,7 +438,8 @@ class spScaleVertices final : public Spell
settings.setValue( key, scaleNormals );

if ( nif->blockInherits( index, "BSGeometry" ) ) {
cast_Starfield( nif, index, scaleVector, scaleNormals );
if ( nif->checkInternalGeometry( index ) )
cast_Starfield( nif, index, scaleVector, scaleNormals );
return index;
}

Expand Down

0 comments on commit d8dd116

Please sign in to comment.