Skip to content

Commit

Permalink
Render bhkCylinderShape (hexabits/nifskope#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Nov 22, 2024
1 parent 603436f commit 34cdfc9
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
== CHANGELOG ==

* Implemented rendering bhkCylinderShape (fix to issue https://github.com/hexabits/nifskope/issues/37).
* Fixed the block types NiMeshPSysData and NiMeshParticleSystem being incorrectly filtered out by 'Block/Insert'.

#### NifSkope-2.0.dev9-20241112

* Implemented support for editing and saving Fallout 76 materials.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NifSkope is a tool for opening and editing the NetImmerse file format (NIF). NIF is used by video games such as Morrowind, Oblivion, Skyrim, Fallout 3/NV/4/76, Starfield, Civilization IV, and more.

This is an experimental fork of 2.0.dev9 with many improvements to Starfield support, and a number of fixes to issues related to older games. See [CHANGELOG.md](https://github.com/fo76utils/nifskope/blob/develop/CHANGELOG.md) for details.
This is an experimental fork of 2.0.dev9 with many fixes and improvements. See [CHANGELOG.md](https://github.com/fo76utils/nifskope/blob/develop/CHANGELOG.md) for details.

### Download

Expand Down
2 changes: 1 addition & 1 deletion build/README.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NifSkope is a tool for opening and editing the NetImmerse file format (NIF). NIF is used by video games such as Morrowind, Oblivion, Skyrim, Fallout 3/NV/4/76, Starfield, Civilization IV, and more.

This is an experimental fork of 2.0.dev9 with many improvements to Starfield support, and a number of fixes to issues related to older games. See [CHANGELOG.md](https://github.com/fo76utils/nifskope/blob/develop/CHANGELOG.md) for details.
This is an experimental fork of 2.0.dev9 with many fixes and improvements. See [CHANGELOG.md](https://github.com/fo76utils/nifskope/blob/develop/CHANGELOG.md) for details.

### Download

Expand Down
6 changes: 6 additions & 0 deletions src/gl/glnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,12 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStack<QMod
}

drawCapsule( nif->get<Vector3>( iShape, "First Point" ), nif->get<Vector3>( iShape, "Second Point" ), nif->get<float>( iShape, "Radius" ) );
} else if ( name == "bhkCylinderShape" ) {
if ( Node::SELECTING ) {
setColorKeyFromID( nif->getBlockNumber( iShape ) );
}

drawCylinder( Vector3( nif->get<Vector4>( iShape, "Vertex A" ) ), Vector3( nif->get<Vector4>( iShape, "Vertex B" ) ), nif->get<float>( iShape, "Cylinder Radius" ) );
} else if ( name == "bhkNiTriStripsShape" ) {
glPushMatrix();
float s = bhkInvScale( nif );
Expand Down
50 changes: 50 additions & 0 deletions src/gl/gltools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,56 @@ void drawCapsule( const Vector3 & a, const Vector3 & b, float r, int sd )
}
}

void drawCylinder( const Vector3 & a, const Vector3 & b, float r, int sd )
{
Vector3 d = b - a;

if ( d.length() < 0.001 ) {
drawSphere( a, r );
return;
}

Vector3 n = d;
n.normalize();

Vector3 x( n[1], n[2], n[0] );
Vector3 y = Vector3::crossproduct( n, x );
x = Vector3::crossproduct( n, y );

x *= r;
y *= r;

glBegin( GL_LINE_STRIP );

for ( int i = 0; i <= sd * 2; i++ )
glVertex( a + d / 2 + x * std::sin( PI / sd * i ) + y * std::cos( PI / sd * i ) );

glEnd();
glBegin( GL_LINES );

for ( int i = 0; i <= sd * 2; i++ ) {
glVertex( a + x * std::sin( PI / sd * i ) + y * std::cos( PI / sd * i ) );
glVertex( b + x * std::sin( PI / sd * i ) + y * std::cos( PI / sd * i ) );
}

glEnd();

for ( int j = 0; j <= sd; j++ ) {
glBegin( GL_LINE_STRIP );

for ( int i = 0; i <= sd * 2; i++ )
glVertex( a + x * std::sin( PI / sd * i ) + y * std::cos( PI / sd * i ) );

glEnd();
glBegin( GL_LINE_STRIP );

for ( int i = 0; i <= sd * 2; i++ )
glVertex( b + x * std::sin( PI / sd * i ) + y * std::cos( PI / sd * i ) );

glEnd();
}
}

void drawDashLine( const Vector3 & a, const Vector3 & b, int sd )
{
Vector3 d = ( b - a ) / float(sd);
Expand Down
1 change: 1 addition & 0 deletions src/gl/gltools.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void drawRagdollCone( const Vector3 & pivot, const Vector3 & twist, const Vector
void drawSphereSimple( const Vector3 & c, float r, int sd = 36 );
void drawSphere( const Vector3 & c, float r, int sd = 8 );
void drawCapsule( const Vector3 & a, const Vector3 & b, float r, int sd = 5 );
void drawCylinder( const Vector3 & a, const Vector3 & b, float r, int sd = 5 );
void drawDashLine( const Vector3 & a, const Vector3 & b, int sd = 15 );
void drawConvexHull( const NifModel * nif, const QModelIndex & iShape, float scale, bool solid = false );
void drawNiTSS( const NifModel * nif, const QModelIndex & iShape, bool solid = false );
Expand Down

0 comments on commit 34cdfc9

Please sign in to comment.