wavelength 1.0.0
Loading...
Searching...
No Matches
rndmesh.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <list>
5#include <memory>
6#include <vector>
7
8#include "math/box.h"
9#include "math/color.h"
10#include "math/plane.h"
11#include "math/sphere.h"
12#include "math/transform.h"
13#include "math/vector2.h"
14#include "math/vector3.h"
15#include "os/binstream.h"
16#include "os/mem.h"
17#include "os/prnstream.h"
18#include "rnd/rndcollideable.h"
19#include "rnd/rnddrawable.h"
20#include "rnd/rndmat.h"
22
31class RndMesh : public RndDrawable, public RndTransformable, public RndCollideable {
32public:
41
53
55 static constexpr int kCopyShareGeometry = 8;
56
58 static constexpr int kCopyBones = 0x20;
59
71
78 class alignas(16) Vert {
79 public:
81 Vert() {
82 mWeight1 = 0.0f;
83 mWeight2 = 0.0f;
84 mPos = Vector3{0.0f, 0.0f, 0.0f, 1.0f};
85 mNorm = Vector3{0.0f, 0.0f, 0.0f, 1.0f};
86 mColor.g = 1.0f;
87 mColor.a = 1.0f;
88 mColor.b = 1.0f;
89 mColor.r = 1.0f;
90 mTex.y = 0.0f;
91 mTex.x = 0.0f;
92 }
93
98 float mWeight1;
99 float mWeight2;
100 };
101
107 class Face {
108 public:
110 Face() : mVerts{} {
111 }
112
113 unsigned short mVerts[3];
114 };
115
121 class Edge {
122 public:
124 Edge() : mVerts{} {
125 }
126
127 unsigned short mVerts[2];
128 };
129
139
149 explicit RndMesh(const char *pszName);
150
157 ~RndMesh() override;
158
165 void *operator new(size_t nSize) {
166 return PoolMemAlloc(static_cast<int>(nSize), "Mesh", 0);
167 }
168
174 void operator delete(void *pBlock) {
175 PoolMemFree(pBlock);
176 }
177
188 void ListDrawObjects(std::list<RndObject *> &objects) override;
189
198 void ListDrawables(std::list<RndDrawable *> &drawables) override;
199
209 virtual void Sync([[maybe_unused]] int nFlags) {
210 }
211
213
224 void Collide(const Segment &segment, std::list<Collision> &collisions) override;
225
233 void DumpText(PrnStream &stream) override;
234
244 void Save(BinStream &stream) override;
245
256 void Replace(RndObject *pFrom, RndObject *pTo) override;
257
265 const char *ClassName() const override {
266 return sClassName;
267 }
268
280 void Copy(const RndObject *pSource, int nFlags) override;
281
289 void Load(BinStream &stream) override;
290
298 void SetMat(RndMat *pMat);
299
312 bool CheckLod(Sphere &worldSphere);
313
323 void BoundingBox(Box &box);
324
334 void TransformVerts(const Transform &xfm);
335
349 void AddQuad(unsigned short nV0, unsigned short nV1, unsigned short nV2, unsigned short nV3);
350
365 void AddQuadStrip(int nRowA, int nRowB, int nCount, int nStride, int nStep);
366
398 void FillEdges(int nEdgeA,
399 int nEdgeB,
400 int nCount,
401 int nStride,
402 const Vector3 &pointA0,
403 const Vector3 &pointB0,
404 const Vector3 &pointA1,
405 const Vector3 &pointB1,
406 const Vector2 &texA0,
407 const Vector2 &texB0,
408 const Vector2 &texA1,
409 const Vector2 &texB1,
410 const Vector2 &weightsA0,
411 const Vector2 &weightsB0,
412 const Vector2 &weightsA1,
413 const Vector2 &weightsB1,
414 const Color &colorA0,
415 const Color &colorB0,
416 const Color &colorA1,
417 const Color &colorB1,
418 const Vector3 &normA,
419 const Vector3 &normB);
420
429 static RndObject *New(const char *pszName) {
430 return new RndMesh(pszName);
431 }
432
439 static const char *sClassName;
440
446 static int sRev;
447
453 static int sLoadRev;
454
456 const std::vector<Face> &GetFaces() const {
457 return mFaces;
458 }
459
461 std::vector<Face> &GetFaces() {
462 return mFaces;
463 }
464
467 return mGeomOwner;
468 }
469
471 RndMat *GetMat() const {
472 return mMat;
473 }
474
476 float GetMinScreen() const {
477 return mMinScreen;
478 }
479
481 int GetMutable() const {
482 return mMutable;
483 }
484
486 void SetMutable(int nMutable) {
487 mMutable = nMutable;
488 }
489
491 const Sphere &GetSphere() const {
492 return mSphere;
493 }
494
497 return mSphere;
498 }
499
501 const std::vector<Vert> &GetVerts() const {
502 return mVerts;
503 }
504
506 std::vector<Vert> &GetVerts() {
507 return mVerts;
508 }
509
511 int GetZFunc() const {
512 return mZFunc;
513 }
514
516 void SetZFunc(int nZFunc) {
517 mZFunc = nZFunc;
518 }
519
521 int GetZMode() const {
522 return mZMode;
523 }
524
526 void SetZMode(int nZMode) {
527 mZMode = nZMode;
528 }
529
530protected:
541
552
553 int mZMode;
554
555 int mZFunc;
556
557 std::vector<Vert> mVerts;
558
559 std::vector<Face> mFaces;
560
561 std::vector<Edge> mEdges;
562
564
566
568
570
571 std::unique_ptr<Bones> mBones;
572
574
576
578};
579
590
601
612
623
634
645
658
669
682
693
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Axis-aligned bounding box.
Definition box.h:12
Text output stream.
Definition prnstream.h:16
virtual void Collide(const Segment &segment, std::list< Collision > &collisions)
Test a segment against the collideable and add what it strikes to a list.
RndCollideable()
Construct a collideable without children.
Definition rndcollideable.h:34
RndDrawable()
Construct a showing drawable without a highlight or children.
Definition rnddrawable.h:23
Surface description: blending, lighting colours, culling, and a list of texture stages.
Definition rndmat.h:20
One edge, as indices into the vertices.
Definition rndmesh.h:121
unsigned short mVerts[2]
Definition rndmesh.h:127
Edge()
Construct an edge from the first vertex to itself.
Definition rndmesh.h:124
One triangle, as indices into the vertices.
Definition rndmesh.h:107
unsigned short mVerts[3]
Definition rndmesh.h:113
Face()
Construct a triangle of the first vertex three times.
Definition rndmesh.h:110
One vertex.
Definition rndmesh.h:78
Vector3 mNorm
Definition rndmesh.h:95
Vert()
Construct a white vertex at the origin with no normal and no weights.
Definition rndmesh.h:81
Vector3 mPos
Definition rndmesh.h:94
Vector2 mTex
Definition rndmesh.h:97
Color mColor
Definition rndmesh.h:96
float mWeight1
Definition rndmesh.h:98
float mWeight2
Definition rndmesh.h:99
static RndObject * New(const char *pszName)
Create a mesh.
Definition rndmesh.h:429
void ListDrawables(std::list< RndDrawable * > &drawables) override
Add the mesh and then its children to a list, unless the mesh is outside the view of the current came...
RndMesh * mNext
Definition rndmesh.h:575
void FillEdges(int nEdgeA, int nEdgeB, int nCount, int nStride, const Vector3 &pointA0, const Vector3 &pointB0, const Vector3 &pointA1, const Vector3 &pointB1, const Vector2 &texA0, const Vector2 &texB0, const Vector2 &texA1, const Vector2 &texB1, const Vector2 &weightsA0, const Vector2 &weightsB0, const Vector2 &weightsA1, const Vector2 &weightsB1, const Color &colorA0, const Color &colorB0, const Color &colorA1, const Color &colorB1, const Vector3 &normA, const Vector3 &normB)
Fill the vertices of two edges of a tunnel panel, interpolating every field along them.
RndMesh(const char *pszName)
Construct an empty mesh that draws with a Z depth test and write, passing when nearer.
void SetZFunc(int nZFunc)
Definition rndmesh.h:516
float GetMinScreen() const
Definition rndmesh.h:476
RndTransformable * mTransOwner
Definition rndmesh.h:569
RndMat * mMat
Definition rndmesh.h:563
std::vector< Vert > mVerts
Definition rndmesh.h:557
void TransformVerts(const Transform &xfm)
Move every vertex of the geometry by a transform, then rebuild the positions and normals.
int GetMutable() const
Definition rndmesh.h:481
const Sphere & GetSphere() const
Definition rndmesh.h:491
std::unique_ptr< Bones > mBones
Definition rndmesh.h:571
void SetZMode(int nZMode)
Definition rndmesh.h:526
RndMesh * mGeomOwner
Definition rndmesh.h:567
static int sRev
The format version Save() writes and Load() accepts.
Definition rndmesh.h:446
void ReleaseRefs()
Drop the references on the next mesh, the material, the owners, and the bones, and delete the bones.
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a referenced object with another.
void Copy(const RndObject *pSource, int nFlags) override
Copy another mesh and its bases.
std::vector< Vert > & GetVerts()
Definition rndmesh.h:506
int mMutable
Definition rndmesh.h:577
void SetMutable(int nMutable)
Definition rndmesh.h:486
Sphere mSphere
Definition rndmesh.h:565
static const char * sClassName
The class name a .rnd file writes, Mesh.
Definition rndmesh.h:439
SyncFlags
The parts of the geometry Sync() rebuilds.
Definition rndmesh.h:61
@ kSyncAll
Definition rndmesh.h:69
@ kSyncVertexData
Definition rndmesh.h:66
@ kSyncPositions
Definition rndmesh.h:62
@ kSyncColors
Definition rndmesh.h:64
@ kSyncNormals
Definition rndmesh.h:63
@ kSyncFaces
Definition rndmesh.h:67
@ kSyncTexCoords
Definition rndmesh.h:65
@ kSyncEdges
Definition rndmesh.h:68
int mZMode
Definition rndmesh.h:553
void SetMat(RndMat *pMat)
Set the material.
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it.
static constexpr int kCopyBones
The bit of the Copy() flags that copies the bones.
Definition rndmesh.h:58
static int sLoadRev
The version Load() read last, which the vertex and face readers read by.
Definition rndmesh.h:453
float mMinScreen
Definition rndmesh.h:573
void AcquireRefs()
Take references on the next mesh, the material, the owners, and the bones, then rebuild everything.
virtual void Sync(int nFlags)
Rebuild what the back end derives from parts of the geometry.
Definition rndmesh.h:209
int GetZFunc() const
Definition rndmesh.h:511
ZMode
How drawing reads and writes depth.
Definition rndmesh.h:34
@ kZModeWReadWrite
Definition rndmesh.h:39
@ kZModeZReadOnly
Definition rndmesh.h:36
@ kZModeZReadWrite
Definition rndmesh.h:37
@ kZModeDisable
Definition rndmesh.h:35
@ kZModeWReadOnly
Definition rndmesh.h:38
const std::vector< Vert > & GetVerts() const
Definition rndmesh.h:501
int mZFunc
Definition rndmesh.h:555
RndMat * GetMat() const
Definition rndmesh.h:471
int GetZMode() const
Definition rndmesh.h:521
std::vector< Edge > mEdges
Definition rndmesh.h:561
std::vector< Face > mFaces
Definition rndmesh.h:559
void Save(BinStream &stream) override
Write the mesh and its bases.
Sphere & GetSphere()
Definition rndmesh.h:496
RndMesh * GetGeomOwner() const
Definition rndmesh.h:466
const char * ClassName() const override
Report the class name.
Definition rndmesh.h:265
std::vector< Face > & GetFaces()
Definition rndmesh.h:461
~RndMesh() override
Drop the references the mesh has.
const std::vector< Face > & GetFaces() const
Definition rndmesh.h:456
bool CheckLod(Sphere &worldSphere)
Report whether the mesh itself is to be drawn, drawing a lower detail mesh in its place when the curr...
void AddQuad(unsigned short nV0, unsigned short nV1, unsigned short nV2, unsigned short nV3)
Append the two triangles of a quad to the faces of mGeomOwner.
void ListDrawObjects(std::list< RndObject * > &objects) override
Add the mesh, its material, its owners, the textures of the material stages from the last,...
ZFunc
The depth comparison.
Definition rndmesh.h:43
@ kZFuncNotEqual
Definition rndmesh.h:49
@ kZFuncEqual
Definition rndmesh.h:46
@ kZFuncLessEqual
Definition rndmesh.h:47
@ kZFuncNever
Definition rndmesh.h:44
@ kZFuncLess
Definition rndmesh.h:45
@ kZFuncGreater
Definition rndmesh.h:48
@ kZFuncGreaterEqual
Definition rndmesh.h:50
@ kZFuncAlways
Definition rndmesh.h:51
static constexpr int kCopyShareGeometry
The bit of the Copy() flags that shares the source's geometry rather than copying it.
Definition rndmesh.h:55
void Collide(const Segment &segment, std::list< Collision > &collisions) override
Add each face the segment strikes, then what the children strike, to a list.
void AddQuadStrip(int nRowA, int nRowB, int nCount, int nStride, int nStep)
Append the quads between two rows of vertices with AddQuad().
void BoundingBox(Box &box)
Compute the bounding box of the vertices in the mesh's own space.
void DumpText(PrnStream &stream) override
Write a description of the mesh and its bases.
RndObject(const char *pszName)
Construct an object and register it under a name.
RndTransformable()
Construct a transformable with identity transforms, no origin offset, and no billboard.
Bounding sphere.
Definition sphere.h:17
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.
PrnStream & operator<<(PrnStream &stream, const RndMesh::Vert &vert)
Write a vertex.
BinStream & operator>>(BinStream &stream, RndMesh::Vert &vert)
Read a vertex the vertex writer wrote, or an earlier version of it.
Linear colour with four float components.
Definition color.h:12
The two bone transforms the vertex weights blend.
Definition rndmesh.h:135
Transform mXfms[2]
Definition rndmesh.h:137
RndTransformable * mTrans[2]
Definition rndmesh.h:136
Two points that fix a line or a segment.
Definition plane.h:39
Affine transform stored as three basis rows and a translation row.
Definition transform.h:18
Two-component vector, used for texture coordinates.
Definition vector2.h:12
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14