Skip to content

Commit

Permalink
Implemented the Flip UV spell for BSTriShape geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Jun 8, 2024
1 parent e44c3e1 commit 09161dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
== CHANGELOG ==

#### NifSkope-2.0.dev9-20240608

* The UV editor now supports exporting Starfield .mesh files. Note: currently only the first available LOD can be edited, and to be able to render the model with the modifications, the file needs to be saved to a path where it is found by NifSkope as a resource, and the NIF reloaded (Alt+X) after closing resources (Alt+Q).
* Implemented the "Flip UV" and "Remove Unused Vertices" spells for BSTriShape geometry. Note that skinned meshes are not supported yet by the latter.
* Fixed the "Search Other Games if no match" resource setting, and the edit and browse path widgets not being enabled/disabled according to the game status.
* Implemented the "Remove Unused Vertices" spell for BSTriShape geometry. Note that skinned meshes are not supported yet.
* SizedString16 data fields are now shown and can be edited as strings.
* Anti-aliasing above 4x can be enabled on Linux by adding "Render\\General\\Antialiasing%20Limit=4" to the configuration file (NifTools/NifSkope 2.0.conf) under Settings.
* Minor Starfield rendering optimization.
Expand Down
22 changes: 20 additions & 2 deletions src/spells/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,18 @@ class spFlipTexCoords final : public Spell

bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final
{
if ( nif->blockInherits( index, "BSTriShape" ) && nif->getIndex( index, "Vertex Data" ).isValid() )
return true;
return nif->itemStrType( index ).toLower() == "texcoord" || nif->blockInherits( index, "NiTriBasedGeomData" );
}

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

if ( nif->itemStrType( index ).toLower() != "texcoord" ) {
if ( nif->blockInherits( index, "BSTriShape" ) ) {
idx = nif->getIndex( index, "Vertex Data" );
} else if ( nif->itemStrType( index ).toLower() != "texcoord" ) {
idx = nif->getIndex( nif->getBlockIndex( index ), "UV Sets" );
}

Expand All @@ -368,7 +372,21 @@ class spFlipTexCoords final : public Spell
//! Flips UV data in a model index
void flip( NifModel * nif, const QModelIndex & index, int f )
{
if ( nif->isArray( index ) ) {
if ( nif->itemStrType( index ) == "BSVertexData" ) {
// BSTriShape vertex data
int n = nif->rowCount( index );
for ( int i = 0; i < n; i++ ) {
auto v = QModelIndex_child( index, i );
if ( !v.isValid() )
continue;
auto iUV = nif->getIndex( v, "UV" );
if ( !iUV.isValid() )
continue;
HalfVector2 uv = nif->get<HalfVector2>( iUV );
flip( uv, f );
nif->set<HalfVector2>( iUV, uv );
}
} else if ( nif->isArray( index ) ) {
QModelIndex idx = QModelIndex_child( index );

if ( idx.isValid() ) {
Expand Down

0 comments on commit 09161dc

Please sign in to comment.