Skip to content

Commit

Permalink
Implemented triangle selection for NiTriShape and Skyrim skin partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Jan 26, 2025
1 parent 1904c02 commit 75002db
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
27 changes: 25 additions & 2 deletions src/gl/bsshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,22 @@ QModelIndex BSShape::triangleAt( int idx ) const

auto blk = iBlock;
if ( iSkinPart.isValid() ) {
// TODO: Triangles are on NiSkinPartition in version 100
// Triangles are on NiSkinPartition in version 100
auto iPartitions = nif->getIndex( iSkinPart, "Partitions" );
if ( iPartitions.isValid() && nif->isArray( iPartitions ) ) {
for ( int i = 0; i < nif->rowCount( iPartitions ); i++ ) {
auto iPart = nif->getIndex( iPartitions, i );
if ( !iPart.isValid() )
continue;
auto iTriangles = nif->getIndex( iPart, "Triangles" );
if ( !( iTriangles.isValid() && nif->isArray( iTriangles ) ) )
continue;
int n = nif->rowCount( iTriangles );
if ( idx < n )
return nif->getIndex( iTriangles, idx );
idx -= n;
}
}
return QModelIndex();
}

Expand Down Expand Up @@ -482,8 +497,16 @@ void BSShape::drawSelection() const
// Draw Triangles
if ( n == "Triangles" ) {
int s = -1;
if ( n == p )
if ( n == p ) {
s = idx.row();
if ( iSkinPart.isValid() ) {
int i = idx.parent().parent().row();
while ( i-- > 0 ) {
if ( auto j = nif->getIndex( nif->getIndex( iSkinPart, "Partitions" ), i ); j.isValid() )
s += int( nif->get<quint32>( j, "Num Triangles" ) );
}
}
}
Shape::drawWireframe( scene->wireframeColor );
if ( s >= 0 && s < triangles.size() )
Shape::drawTriangles( s, 1, scene->highlightColor );
Expand Down
13 changes: 10 additions & 3 deletions src/gl/glmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ void Mesh::updateData_NiTriShape( const NifModel * nif )

QModelIndex Mesh::vertexAt( int idx ) const
{
auto nif = NifModel::fromIndex( iBlock );
auto nif = scene->nifModel;
if ( !nif )
return QModelIndex();

Expand All @@ -653,9 +653,16 @@ QModelIndex Mesh::vertexAt( int idx ) const
return iVertex;
}

bool compareTriangles( const QPair<int, float> & tri1, const QPair<int, float> & tri2 )
QModelIndex Mesh::triangleAt( int idx ) const
{
return ( tri1.second < tri2.second );
auto nif = scene->nifModel;
if ( nif && iData.isValid() ) {
// TODO: implement support for triangle strips and skin partitions
auto iTriangleData = nif->getIndex( iData, "Triangles" );
if ( iTriangleData.isValid() && nif->isArray( iTriangleData ) )
return nif->getIndex( iTriangleData, idx );
}
return QModelIndex();
}

void Mesh::transformShapes()
Expand Down
1 change: 1 addition & 0 deletions src/gl/glmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Mesh : public Shape

void drawVerts() const;
QModelIndex vertexAt( int ) const override;
QModelIndex triangleAt( int ) const override;
void updateLodLevel() override;

protected:
Expand Down

0 comments on commit 75002db

Please sign in to comment.