Added createRectangleMesh and createDiskMesh to geometry creator
MODIFY
include/irr/asset/IGeometryCreator.h
include/irr/asset/IGeometryCreator.h
@@ -96,6 +96,10 @@ public:
const video::SColor& colorBottom=video::SColor(0xffffffff),
float oblique=0.f) const =0;
+ virtual asset::ICPUMesh* createRectangleMesh(const core::vector2df_SIMD& size = core::vector2df_SIMD(0.5f, 0.5f)) const = 0;
+
+ virtual asset::ICPUMesh* createDiskMesh(float radius, uint32_t tesselation) const = 0;
+
};
} // end namespace asset

MODIFY
src/irr/asset/CGeometryCreator.cpp
src/irr/asset/CGeometryCreator.cpp
@@ -141,7 +141,7 @@ asset::ICPUMesh* CGeometryCreator::createCubeMesh(const core::vector3df& size) c
//setVertexAttrBuffer(asset::ICPUBuffer* attrBuf, const E_VERTEX_ATTRIBUTE_ID& attrId, E_COMPONENTS_PER_ATTRIBUTE components, E_COMPONENT_TYPE type, const size_t &stride=0, size_t offset=0)
desc->setVertexAttrBuffer(vertices,asset::EVAI_ATTR0,asset::EF_R32G32B32_SFLOAT,vertexSize, offsetof(CubeVertex, pos));
desc->setVertexAttrBuffer(vertices,asset::EVAI_ATTR1,asset::EF_R8G8B8A8_UNORM,vertexSize,offsetof(CubeVertex, color));
- desc->setVertexAttrBuffer(vertices,asset::EVAI_ATTR2,asset::EF_R8G8_UNORM,vertexSize,offsetof(CubeVertex, uv));
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR2, asset::EF_R8G8_USCALED, vertexSize, offsetof(CubeVertex, uv));
desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR3, asset::EF_R8G8B8_SNORM, vertexSize, offsetof(CubeVertex, normal));
vertices->drop();
@@ -568,6 +568,129 @@ asset::ICPUMesh* CGeometryCreator::createConeMesh(float radius, float length, ui
}
+asset::ICPUMesh* CGeometryCreator::createRectangleMesh(const core::vector2df_SIMD& _size) const
+{
+ asset::ICPUMeshDataFormatDesc* desc = new asset::ICPUMeshDataFormatDesc();
+ asset::ICPUMeshBuffer* buffer = new asset::ICPUMeshBuffer();
+ buffer->setMeshDataAndFormat(desc);
+ desc->drop();
+
+ // Create indices
+ uint16_t u[6];
+
+ /*
+ 0---1
+ | / |
+ 3---2
+ */
+ u[0] = 0;
+ u[1] = 3;
+ u[2] = 1;
+ u[3] = 1;
+ u[4] = 3;
+ u[5] = 2;
+
+ asset::ICPUBuffer* indices = new asset::ICPUBuffer(sizeof(u));
+ memcpy(indices->getPointer(), u, sizeof(u));
+ desc->setIndexBuffer(indices);
+ buffer->setIndexType(asset::EIT_16BIT);
+ buffer->setIndexCount(sizeof(u) / sizeof(*u));
+ indices->drop();
+
+ // Create vertices
+ const size_t vertexSize = sizeof(CGeometryCreator::RectangleVertex);
+ asset::ICPUBuffer* vertices = new asset::ICPUBuffer(4 * vertexSize);
+ RectangleVertex* ptr = (RectangleVertex*)vertices->getPointer();
+
+ ptr[0] = RectangleVertex(core::vector3df_SIMD(-1.0f, 1.0f, 0.0f) * _size, video::SColor(0xFFFFFFFFu),
+ core::vector2du32_SIMD(0u, 1u), core::vector3df_SIMD(0.0f, 0.0f, 1.0f));
+ ptr[1] = RectangleVertex(core::vector3df_SIMD( 1.0f, 1.0f, 0.0f) * _size, video::SColor(0xFFFFFFFFu),
+ core::vector2du32_SIMD(1u, 1u), core::vector3df_SIMD(0.0f, 0.0f, 1.0f));
+ ptr[2] = RectangleVertex(core::vector3df_SIMD( 1.0f, -1.0f, 0.0f) * _size, video::SColor(0xFFFFFFFFu),
+ core::vector2du32_SIMD(1u, 0u), core::vector3df_SIMD(0.0f, 0.0f, 1.0f));
+ ptr[3] = RectangleVertex(core::vector3df_SIMD(-1.0f, -1.0f, 0.0f) * _size, video::SColor(0xFFFFFFFFu),
+ core::vector2du32_SIMD(0u, 0u), core::vector3df_SIMD(0.0f, 0.0f, 1.0f));
+
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR0, asset::EF_R32G32B32_SFLOAT, vertexSize, offsetof(RectangleVertex, pos));
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR1, asset::EF_R8G8B8A8_UNORM, vertexSize, offsetof(RectangleVertex, color));
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR2, asset::EF_R8G8_USCALED, vertexSize, offsetof(RectangleVertex, uv));
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR3, asset::EF_R32G32B32_SFLOAT, vertexSize, offsetof(RectangleVertex, normal));
+ vertices->drop();
+
+ asset::SCPUMesh* mesh = new asset::SCPUMesh;
+ mesh->addMeshBuffer(buffer);
+ buffer->drop();
+
+ mesh->recalculateBoundingBox();
+ return mesh;
+}
+
+asset::ICPUMesh* CGeometryCreator::createDiskMesh(float radius, uint32_t tesselation) const
+{
+ asset::ICPUMeshDataFormatDesc* desc = new asset::ICPUMeshDataFormatDesc();
+ asset::ICPUMeshBuffer* buffer = new asset::ICPUMeshBuffer();
+ buffer->setPrimitiveType(asset::E_PRIMITIVE_TYPE::EPT_TRIANGLE_FAN);
+ buffer->setMeshDataAndFormat(desc);
+ desc->drop();
+
+ const size_t vertexCount = 1u + tesselation;
+
+ const size_t vertexSize = sizeof(CGeometryCreator::DiskVertex);
+ const float angle = 360.0f / static_cast<float>(tesselation);
+
+ asset::ICPUBuffer* vertices = new asset::ICPUBuffer(vertexCount * vertexSize);
+ DiskVertex* ptr = (DiskVertex*)vertices->getPointer();
+
+
+ /*
+ example:
+
+ v1 v0 v7
+ \ | /
+ v2 -- s -- v6
+ / | \
+ v3 v4 v5
+ */
+
+
+ const core::vectorSIMDf v0(0.0f, radius, 0.0f, 0.0f);
+ core::matrix3x4SIMD rotation;
+
+ //center
+ ptr[0] = DiskVertex(core::vector3df_SIMD(0.0f), video::SColor(0xFFFFFFFFu),
+ core::vector2du32_SIMD(0u, 1u), core::vector3df_SIMD(0.0f, 0.0f, 1.0f));
+
+ //v0
+ ptr[1] = DiskVertex(v0, video::SColor(0xFFFFFFFFu),
+ core::vector2du32_SIMD(0u, 1u), core::vector3df_SIMD(0.0f, 0.0f, 1.0f));
+
+ //v1, v2, ..., vn
+ for (int i = 2; i < vertexCount; i++)
+ {
+ core::vectorSIMDf vn;
+ core::matrix3x4SIMD rotMatrix;
+ rotMatrix.setRotation(core::quaternion(0.0f, 0.0f, core::degToRad(angle * (i - 1))));
+
+ rotMatrix.transformVect(vn, v0);
+ ptr[i] = DiskVertex(vn, video::SColor(0xFFFFFFFFu),
+ core::vector2du32_SIMD(0u, 1u), core::vector3df_SIMD(0.0f, 0.0f, 1.0f));
+ }
+
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR0, asset::EF_R32G32B32_SFLOAT, vertexSize, offsetof(DiskVertex, pos));
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR1, asset::EF_R8G8B8A8_UNORM, vertexSize, offsetof(DiskVertex, color));
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR2, asset::EF_R8G8_USCALED, vertexSize, offsetof(DiskVertex, uv));
+ desc->setVertexAttrBuffer(vertices, asset::EVAI_ATTR3, asset::EF_R32G32B32_SFLOAT, vertexSize, offsetof(DiskVertex, normal));
+ vertices->drop();
+
+ asset::SCPUMesh* mesh = new asset::SCPUMesh;
+ mesh->addMeshBuffer(buffer);
+ buffer->drop();
+
+ mesh->recalculateBoundingBox();
+ return mesh;
+}
+
+
} // end namespace asset
} // end namespace irr

MODIFY
src/irr/asset/CGeometryCreator.h
src/irr/asset/CGeometryCreator.h
@@ -33,6 +33,26 @@ private:
void setUv(uint8_t u, uint8_t v) { uv[0] = u; uv[1] = v; }
} PACK_STRUCT;
+ struct RectangleVertex
+ {
+ RectangleVertex(const core::vector3df_SIMD& _pos, const video::SColor& _color, const core::vector2du32_SIMD _uv, const core::vector3df_SIMD _normal)
+ {
+ memcpy(pos, _pos.pointer, sizeof(float) * 3);
+ _color.toOpenGLColor(color);
+ uv[0] = _uv.x;
+ uv[1] = _uv.y;
+ normal[0] = _normal.x;
+ normal[1] = _normal.y;
+ normal[2] = _normal.z;
+ }
+ float pos[3];
+ uint8_t color[4];
+ uint8_t uv[2];
+ float normal[3];
+ } PACK_STRUCT;
+
+ typedef RectangleVertex DiskVertex;
+
struct ConeVertex
{
inline ConeVertex(const core::vectorSIMDf& _pos, uint32_t _nml, const video::SColor& _color) : normal{_nml}
@@ -77,6 +97,10 @@ public:
const video::SColor& colorBottom=0xffffffff,
float oblique=0.f) const override;
+ virtual asset::ICPUMesh* createRectangleMesh(const core::vector2df_SIMD& _size = core::vector2df_SIMD(0.5f, 0.5f)) const override;
+
+ virtual asset::ICPUMesh* createDiskMesh(float radius, uint32_t tesselation) const override;
+
};
} // end namespace asset

Added createRectangleMesh and createDiskMesh to geometry creator