Add default UV's for CGeometryCreator::createConeMesh

Thanks @randomMesh for reporting that they were missing: https://irrlicht.sourceforge.io/forum/viewtopic.php?p=307308
Also simplified that code a bit (same could probably also be done for createCylinderMesh, but too lazy right now)
Changed also UV's for top/bottom center vertex in CGeometryCreator::createCylinderMesh to use center for X (slight improvement, but would have to copy vertices to make it better)



git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6580 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2023-12-31 16:48:36 +00:00
parent 8372a70f21
commit 245dd395cb
3 changed files with 33 additions and 25 deletions

View File

@ -1,6 +1,8 @@
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- Change in UV's for top/bottom center vertex in CGeometryCreator::createCylinderMesh
- Add some default UV's in CGeometryCreator::createConeMesh
- Bugfix: CTriangleSelector::getTriangles with bounding-box parameter no longer ignores an additionally passed matrix transformation in the box check - Bugfix: CTriangleSelector::getTriangles with bounding-box parameter no longer ignores an additionally passed matrix transformation in the box check
- Fix: CGUITabControl now catching EMIE_LMOUSE_PRESSED_DOWN - Fix: CGUITabControl now catching EMIE_LMOUSE_PRESSED_DOWN
- Add options for transparency node sorting algorithm. - Add options for transparency node sorting algorithm.

View File

@ -135,8 +135,8 @@ public:
//! Create an arrow mesh, composed of a cylinder and a cone. //! Create an arrow mesh, composed of a cylinder and a cone.
/** /**
\param tessellationCylinder Number of quads composing the cylinder. \param tessellationCylinder Number of quads composing half the cylinder.
\param tessellationCone Number of triangles composing the cone's roof. \param tessellationCone Number of triangles composing half the cone's roof.
\param height Total height of the arrow \param height Total height of the arrow
\param cylinderHeight Total height of the cylinder, should be lesser \param cylinderHeight Total height of the cylinder, should be lesser
than total height than total height
@ -168,7 +168,7 @@ public:
/** /**
\param radius Radius of the cylinder. \param radius Radius of the cylinder.
\param length Length of the cylinder. \param length Length of the cylinder.
\param tessellation Number of quads around the circumference of the cylinder. \param tessellation Number of quads around half the circumference of the cylinder.
\param color The color of the cylinder. \param color The color of the cylinder.
\param closeTop If true, close the ends of the cylinder, otherwise leave them open. \param closeTop If true, close the ends of the cylinder, otherwise leave them open.
\param oblique X-offset (shear) of top compared to bottom. \param oblique X-offset (shear) of top compared to bottom.
@ -191,7 +191,7 @@ public:
/** /**
\param radius Radius of the cone. \param radius Radius of the cone.
\param length Length of the cone. \param length Length of the cone.
\param tessellation Number of quads around the circumference of the cone. \param tessellation Number of triangles around half the circumference of the cone.
\param colorTop The color of the top of the cone. \param colorTop The color of the top of the cone.
\param colorBottom The color of the bottom of the cone. \param colorBottom The color of the bottom of the cone.
\param oblique (to be documented) \param oblique (to be documented)

View File

@ -841,7 +841,7 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
v.Normal.X = 0.f; v.Normal.X = 0.f;
v.Normal.Y = -1.f; v.Normal.Y = -1.f;
v.Normal.Z = 0.f; v.Normal.Z = 0.f;
v.TCoords.X = 1.f; v.TCoords.X = 0.5f;
v.TCoords.Y = 1.f; v.TCoords.Y = 1.f;
buffer->Vertices.push_back(v); buffer->Vertices.push_back(v);
@ -867,7 +867,7 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
v.Normal.X = 0.f; v.Normal.X = 0.f;
v.Normal.Y = 1.f; v.Normal.Y = 1.f;
v.Normal.Z = 0.f; v.Normal.Z = 0.f;
v.TCoords.X = 0.f; v.TCoords.X = 0.5f;
v.TCoords.Y = 0.f; v.TCoords.Y = 0.f;
buffer->Vertices.push_back(v); buffer->Vertices.push_back(v);
@ -903,32 +903,34 @@ IMesh* CGeometryCreator::createConeMesh(f32 radius, f32 length, u32 tessellation
{ {
SMeshBuffer* buffer = new SMeshBuffer(); SMeshBuffer* buffer = new SMeshBuffer();
// TODO: For backward compatibility tessellation is per semi-circle
// We probably need another parameter to allow odd numbered tesselation without breaking existing code :-(
if ( tessellation > 0 )
tessellation = 2*tessellation;
if ( tessellation < 2 )
tessellation = 2;
const f32 angleStep = (core::PI * 2.f ) / tessellation; const f32 angleStep = (core::PI * 2.f ) / tessellation;
const f32 angleStepHalf = angleStep*0.5f;
video::S3DVertex v; video::S3DVertex v;
u32 i; v.Pos.Y = 0.f;
v.Color = colorTop; v.Color = colorTop;
for ( i = 0; i != tessellation; ++i ) for (u32 i = 0; i != tessellation; ++i )
{ {
f32 angle = angleStep * f32(i); const f32 angle = angleStep * f32(i);
const f32 cosAngle = cosf(angle);
const f32 sinAngle = sinf(angle);
v.Pos.X = radius * cosf(angle); v.TCoords.X = (1.f+cosAngle)*0.5f;
v.Pos.Y = 0.f; v.TCoords.Y = (1.f+sinAngle)*0.5f;
v.Pos.Z = radius * sinf(angle); v.Pos.X = radius * cosAngle;
v.Normal = v.Pos; v.Pos.Z = radius * sinAngle;
v.Normal.normalize();
buffer->Vertices.push_back(v);
angle += angleStepHalf;
v.Pos.X = radius * cosf(angle);
v.Pos.Y = 0.f;
v.Pos.Z = radius * sinf(angle);
v.Normal = v.Pos; v.Normal = v.Pos;
v.Normal.normalize(); v.Normal.normalize();
buffer->Vertices.push_back(v); buffer->Vertices.push_back(v);
} }
const u32 nonWrappedSize = buffer->Vertices.size() - 1; const u32 nonWrappedSize = buffer->Vertices.size() - 1;
// close top // close top
@ -938,18 +940,20 @@ IMesh* CGeometryCreator::createConeMesh(f32 radius, f32 length, u32 tessellation
v.Normal.X = 0.f; v.Normal.X = 0.f;
v.Normal.Y = 1.f; v.Normal.Y = 1.f;
v.Normal.Z = 0.f; v.Normal.Z = 0.f;
v.TCoords.X = 0.5f;
v.TCoords.Y = 0.5f;
buffer->Vertices.push_back(v); buffer->Vertices.push_back(v);
u32 index = buffer->Vertices.size() - 1; u32 index = buffer->Vertices.size() - 1;
for ( i = 0; i != nonWrappedSize; i += 1 ) for (u32 i = 0; i != nonWrappedSize; ++i)
{ {
buffer->Indices.push_back(i + 0); buffer->Indices.push_back(i + 0);
buffer->Indices.push_back(index); buffer->Indices.push_back(index);
buffer->Indices.push_back(i + 1); buffer->Indices.push_back(i + 1);
} }
buffer->Indices.push_back(i + 0); buffer->Indices.push_back(nonWrappedSize);
buffer->Indices.push_back(index); buffer->Indices.push_back(index);
buffer->Indices.push_back(0); buffer->Indices.push_back(0);
@ -961,11 +965,13 @@ IMesh* CGeometryCreator::createConeMesh(f32 radius, f32 length, u32 tessellation
v.Normal.X = 0.f; v.Normal.X = 0.f;
v.Normal.Y = -1.f; v.Normal.Y = -1.f;
v.Normal.Z = 0.f; v.Normal.Z = 0.f;
v.TCoords.X = 0.5f;
v.TCoords.Y = 0.5f;
buffer->Vertices.push_back(v); buffer->Vertices.push_back(v);
index = buffer->Vertices.size() - 1; index = buffer->Vertices.size() - 1;
for ( i = 0; i != nonWrappedSize; i += 1 ) for (u32 i = 0; i != nonWrappedSize; i += 1 )
{ {
buffer->Indices.push_back(index); buffer->Indices.push_back(index);
buffer->Indices.push_back(i + 0); buffer->Indices.push_back(i + 0);
@ -973,7 +979,7 @@ IMesh* CGeometryCreator::createConeMesh(f32 radius, f32 length, u32 tessellation
} }
buffer->Indices.push_back(index); buffer->Indices.push_back(index);
buffer->Indices.push_back(i + 0); buffer->Indices.push_back(nonWrappedSize);
buffer->Indices.push_back(0); buffer->Indices.push_back(0);
buffer->recalculateBoundingBox(); buffer->recalculateBoundingBox();