PolyhedronGeometry
PolyhedronGeometry ⟵ BufferGeometry
A geometry class for polyhedrons with custom vertices and faces.
PolyhedronGeometry creates a polyhedron geometry from custom vertex and face data. Vertices are projected onto a sphere and subdivided to create smooth shapes. This class serves as the base for regular polyhedrons like octahedron, icosahedron, dodecahedron, and tetrahedron.
Methods
PolyhedronGeometry(const vector<f32>& vertices, const vector<u32>& indices, f32 radius, u32 detail, const Color& color)
Universal constructor - covers all cases with smart defaults
| vertices | Array of vertex coordinates (x,y,z,x,y,z,...) | |
| indices | Array of face indices (a,b,c,a,b,c,...) | |
| radius | Radius of the final shape | 1.0f |
| detail | Number of subdivision levels (0 = original shape) | 0 |
| color | RGBA color for all vertices | 0xFFFFFFFF |
PolyhedronGeometry* clone(bool recursive) const
Creates a copy of this geometry
| recursive | Whether to clone descendants as well | false |
void copy(const PolyhedronGeometry& geometry)
Copies properties from another geometry
| geometry | Source geometry to copy from |
void buildPolyhedron()
Builds the polyhedron geometry with vertices, indices, and colors
void subdivide(f32 radius, u32 detail)
Subdivides the geometry to create smoother shapes
| radius | Radius to project vertices onto | |
| detail | Number of subdivision levels |
void projectToSphere(f32 radius)
Projects vertices onto a sphere of given radius
| radius | Radius of the sphere |
u32 getOrCreateMidpoint(u32 a, u32 b, vector<f32>& newVertices, std::map<std::pair<u32, u32>, u32>& edgeMap, u32& vertexCount)
Gets or creates a midpoint vertex for edge subdivision
| a | First vertex index | |
| b | Second vertex index | |
| newVertices | Vector to add new vertices to | |
| edgeMap | Map of edges to midpoint indices | |
| vertexCount | Current vertex count |
void dispose()
Frees GPU-related resources
Properties
| radius | f32 | Radius of the final shape |
| detail | u32 | Number of subdivision levels |
| color | Color | RGBA color for all vertices |
| vertices | vector |
Source vertex coordinates |
| indices | vector |
Source face indices |
| generatedVertices | vector |
Final vertex positions |
| generatedNormals | vector |
Final vertex normals |
| generatedUVs | vector |
Final UV coordinates |
| generatedIndices | vector |
Final triangle indices |