Skip to content

Commit 0c21e49

Browse files
authored
Merge pull request #115 from ReyeMe/feature/mesh-data-improvements
feat(Scene3D): Improvements to mesh and smoothmesh
2 parents 59fd0b4 + b6e2905 commit 0c21e49

2 files changed

Lines changed: 65 additions & 37 deletions

File tree

saturnringlib/srl_mesh.hpp

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ namespace SRL::Types
142142

143143
/** @brief Construct a new empty Attribute
144144
*/
145-
Attribute() :
145+
constexpr Attribute() :
146146
Visibility(FaceVisibility::SingleSided),
147147
Sort(0),
148148
Texture(0),
@@ -161,7 +161,7 @@ namespace SRL::Types
161161
* @param type Display type (sprite, polygon, etc)
162162
* @param options Display options (light, gouraud, depth shading)
163163
*/
164-
Attribute(const FaceVisibility visibility, const SortMode sort, const uint16_t texture, uint16_t color, uint16_t gouraud, uint16_t mode, uint32_t type, uint16_t options) :
164+
constexpr Attribute(const FaceVisibility visibility, const SortMode sort, const uint16_t texture, uint16_t color, uint16_t gouraud, uint16_t mode, uint32_t type, uint16_t options) :
165165
Visibility(visibility),
166166
Sort(sort | (((type) >> 16) & 0x1c) | options),
167167
Texture(texture),
@@ -181,7 +181,7 @@ namespace SRL::Types
181181
* @param type Display type of the quad
182182
* @param option Display options
183183
*/
184-
Attribute(
184+
constexpr Attribute(
185185
const FaceVisibility visibility,
186186
const SortMode sort,
187187
const uint16_t texture,
@@ -264,13 +264,13 @@ namespace SRL::Types
264264
{
265265
/** @brief Construct a new Polygon object
266266
*/
267-
Polygon() : Normal(), Vertices { 0, 0, 0, 0 } { }
267+
constexpr Polygon() : Normal(), Vertices { 0, 0, 0, 0 } { }
268268

269269
/** @brief Construct a new Polygon object
270270
* @param normal Normal vector
271271
* @param vertices Polygon vertex indicies
272272
*/
273-
Polygon(const SRL::Math::Types::Vector3D& normal, const uint16_t vertices[4]) : Normal(normal), Vertices { vertices[0], vertices[1], vertices[2], vertices[3] } { }
273+
constexpr Polygon(const SRL::Math::Types::Vector3D& normal, const uint16_t vertices[4]) : Normal(normal), Vertices { vertices[0], vertices[1], vertices[2], vertices[3] } { }
274274

275275
/** @brief Normal vector of the polygon
276276
*/
@@ -281,46 +281,59 @@ namespace SRL::Types
281281
uint16_t Vertices[4];
282282
};
283283

284-
/** @brief 3D mesh
284+
/** @brief 3D mesh data
285285
*/
286-
struct Mesh : public SRL::SGL::SglType<Mesh, PDATA>
286+
struct MeshData : public SRL::SGL::SglType<MeshData, PDATA>
287287
{
288+
/** @brief Construct a new empty mesh data object
289+
*/
290+
constexpr MeshData() { }
291+
288292
/** @brief Vertices of the mesh
289293
*/
290-
SRL::Math::Types::Vector3D *Vertices;
294+
SRL::Math::Types::Vector3D *Vertices = nullptr;
291295

292296
/** @brief Number of vertices of the mesh
293297
*/
294-
size_t VertexCount;
298+
size_t VertexCount = 0;
295299

296300
/** @brief Mesh faces
297301
*/
298-
Polygon *Faces;
302+
Polygon *Faces = nullptr;
299303

300304
/** @brief Number of faces
301305
*/
302-
size_t FaceCount;
306+
size_t FaceCount = 0;
303307

304308
/** @brief Face attributes
305309
*/
306-
Attribute *Attributes;
310+
Attribute *Attributes = nullptr;
311+
};
307312

313+
/** @brief 3D managed mesh data
314+
*/
315+
struct Mesh : public MeshData
316+
{
308317
/** @brief Construct a new empty mesh object
309318
*/
310-
Mesh() : Attributes(nullptr), FaceCount(0), Faces(nullptr), VertexCount(0), Vertices(nullptr) { }
319+
constexpr Mesh() : MeshData() { }
311320

312321
/** @brief Construct a new empty mesh object and initialize its arrays
322+
* @warning This constructor will also allocate Vertices, Faces and Attributes arrays
313323
* @param vertexCount Number of vertices in the mesh
314-
* @param polygonCount Number of polygons in the mesh
324+
* @param faceCount Number of faces in the mesh
315325
*/
316-
Mesh(const size_t& vertexCount, const size_t& polygonCount) : FaceCount(polygonCount), VertexCount(vertexCount)
326+
Mesh(const size_t& vertexCount, const size_t& faceCount) : MeshData()
317327
{
328+
this->FaceCount = faceCount;
329+
this->VertexCount = vertexCount;
318330
this->Vertices = autonew SRL::Math::Types::Vector3D[vertexCount];
319-
this->Faces = autonew Polygon[polygonCount];
320-
this->Attributes = autonew Attribute[polygonCount];
331+
this->Faces = autonew Polygon[faceCount];
332+
this->Attributes = autonew Attribute[faceCount];
321333
}
322334

323335
/** @brief Construct a new mesh object from existing data
336+
* @warning When object is deleted, referenced vertices, faces and attributes arrays are deleted as well
324337
* @param vertexCount Number of points
325338
* @param vertices Vertex data
326339
* @param faceCount Number of faces
@@ -331,8 +344,10 @@ namespace SRL::Types
331344
SRL::Math::Types::Vector3D* vertices,
332345
const size_t& faceCount,
333346
Polygon* faces,
334-
Attribute* attributes) : FaceCount(faceCount), VertexCount(vertexCount)
347+
Attribute* attributes) : MeshData()
335348
{
349+
this->VertexCount = vertexCount;
350+
this->FaceCount = faceCount;
336351
this->Vertices = vertices;
337352
this->Faces = faces;
338353
this->Attributes = attributes;
@@ -390,44 +405,55 @@ namespace SRL::Types
390405
}
391406
};
392407

393-
/** @brief 3D smooths mesh
408+
/** @brief 3D smooth mesh data
394409
*/
395-
struct SmoothMesh : public SRL::SGL::SglType<SmoothMesh, XPDATA>
410+
struct SmoothMeshData : public SRL::SGL::SglType<SmoothMeshData, XPDATA>
396411
{
412+
/** @brief Construct a new empty mesh data object
413+
*/
414+
constexpr SmoothMeshData() { }
415+
397416
/** @brief Vertices of the mesh
398417
*/
399-
SRL::Math::Types::Vector3D *Vertices;
418+
SRL::Math::Types::Vector3D *Vertices = nullptr;
400419

401420
/** @brief Number of vertices of the mesh
402421
*/
403-
size_t VertexCount;
422+
size_t VertexCount = 0;
404423

405424
/** @brief Mesh faces
406425
*/
407-
Polygon *Faces;
426+
Polygon *Faces = nullptr;
408427

409428
/** @brief Number of faces
410429
*/
411-
size_t FaceCount;
430+
size_t FaceCount = 0;
412431

413432
/** @brief Face attributes
414433
*/
415-
Attribute *Attributes;
416-
434+
Attribute *Attributes = nullptr;
435+
417436
/** @brief Normal vector data for vertices
418437
*/
419-
SRL::Math::Types::Vector3D* Normals;
438+
SRL::Math::Types::Vector3D* Normals = nullptr;
439+
};
420440

441+
/** @brief 3D smooth managed mesh
442+
*/
443+
struct SmoothMesh : public SmoothMeshData
444+
{
421445
/** @brief Construct a new empty mesh object
422446
*/
423-
SmoothMesh() : Normals(nullptr), Attributes(nullptr), FaceCount(0), Faces(nullptr), VertexCount(0), Vertices(nullptr) { }
447+
constexpr SmoothMesh() : SmoothMeshData() { }
424448

425449
/** @brief Construct a new empty mesh object and initialize its arrays
426450
* @param vertexCount Number of vertices in the mesh
427451
* @param faceCount Number of polygons in the mesh
428452
*/
429-
SmoothMesh(const size_t& vertexCount, const size_t& faceCount) : FaceCount(faceCount), VertexCount(vertexCount)
453+
SmoothMesh(const size_t& vertexCount, const size_t& faceCount) : SmoothMeshData()
430454
{
455+
this->VertexCount = vertexCount;
456+
this->FaceCount = faceCount;
431457
this->Vertices = autonew SRL::Math::Types::Vector3D[vertexCount];
432458
this->Faces = autonew Polygon[faceCount];
433459
this->Attributes = autonew Attribute[faceCount];
@@ -447,8 +473,10 @@ namespace SRL::Types
447473
const size_t& faceCount,
448474
Polygon* faces,
449475
Attribute* attributes,
450-
SRL::Math::Types::Vector3D* normals) : FaceCount(faceCount), VertexCount(vertexCount)
476+
SRL::Math::Types::Vector3D* normals) : SmoothMeshData()
451477
{
478+
this->VertexCount = vertexCount;
479+
this->FaceCount = faceCount;
452480
this->Vertices = vertices;
453481
this->Faces = faces;
454482
this->Attributes = attributes;

saturnringlib/srl_scene3d.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ namespace SRL
2424
* @{
2525
*/
2626

27-
/** @brief Draw SRL::Types::SmoothMesh
28-
* @param mesh SRL::Types::SmoothMesh to draw
27+
/** @brief Draw SRL::Types::SmoothMeshData
28+
* @param mesh SRL::Types::SmoothMeshData to draw
2929
* @param light Light direction unit vector (This is independent of the SRL::Scene3D::SetDirectionalLight)
3030
*/
31-
static void DrawSmoothMesh(Types::SmoothMesh& mesh, SRL::Math::Types::Vector3D& light)
31+
static void DrawSmoothMesh(Types::SmoothMeshData& mesh, SRL::Math::Types::Vector3D& light)
3232
{
3333
slPutPolygonX(mesh.SglPtr(), (FIXED*)&light);
3434
}
3535

3636
/** @brief Draw SRL::Types::Mesh
3737
* @param mesh SRL::Types::Mesh to draw
38-
* @param slaveOnly Value indicates whether processing of the SRL::Types::Mesh should be handled only on the slave CPU
38+
* @param slaveOnly Value indicates whether processing of the SRL::Types::MeshData should be handled only on the slave CPU
3939
* @return True on success
4040
*/
41-
static bool DrawMesh(Types::Mesh& mesh, const bool slaveOnly = false)
41+
static bool DrawMesh(Types::MeshData& mesh, const bool slaveOnly = false)
4242
{
4343
if (slaveOnly)
4444
{
@@ -51,10 +51,10 @@ namespace SRL
5151
/** @brief Draw SRL::Types::Mesh with orthographic projection
5252
* @note Light source calculations and clipping cannot be performed with this function.
5353
* @param mesh SRL::Types::Mesh to draw
54-
* @param attribute Indicates an attribute in the SRL::Types::Mesh that will be shared by all polygons.<br>If set to 0, each polygon is displayed using the data at the beginning of the attribute table, otherwise specified attribute data will be displayed.
54+
* @param attribute Indicates an attribute in the SRL::Types::MeshData that will be shared by all polygons.<br>If set to 0, each polygon is displayed using the data at the beginning of the attribute table, otherwise specified attribute data will be displayed.
5555
* @return True On success
5656
*/
57-
static bool DrawOrthographicMesh(Types::Mesh& mesh, uint16_t attribute)
57+
static bool DrawOrthographicMesh(Types::MeshData& mesh, uint16_t attribute)
5858
{
5959
return slDispPolygon(mesh.SglPtr(), attribute);
6060
}

0 commit comments

Comments
 (0)