mesh refactor 3

This commit is contained in:
h4570
2022-08-10 21:58:32 +02:00
parent 10e0f52d44
commit 0a2d19b2d0
26 changed files with 321 additions and 356 deletions
@@ -16,19 +16,21 @@
namespace Tyra {
struct MD2LoaderOptions {
bool flipUVs = false;
float scale = 1.0F;
};
/** Class responsible for loading & parsing Quake's II ".md2" 3D files */
class MD2Loader : public Loader {
public:
MD2Loader();
~MD2Loader();
MeshBuilderData* load(const char* fullpath, const float& scale,
const bool& invertT);
inline MeshBuilderData* load(const std::string& fullpath, const float& scale,
const bool& invertT) {
return load(fullpath.c_str(), scale, invertT);
}
MeshBuilderData* load(const char* fullpath);
MeshBuilderData* load(const char* fullpath, MD2LoaderOptions options);
MeshBuilderData* load(const std::string& fullpath);
MeshBuilderData* load(const std::string& fullpath, MD2LoaderOptions options);
};
} // namespace Tyra
@@ -23,35 +23,17 @@ class DynamicMesh : public Mesh {
explicit DynamicMesh(const DynamicMesh& mesh);
~DynamicMesh();
const DynamicMeshAnimState& getAnimState() const { return animState; }
std::vector<MeshFrame*> frames;
/** Returns single frame. */
MeshFrame* getFrame(const u32& i) { return frames[i]; }
MeshFrame** getFrames() { return frames; }
/** Count of frames. Static object (not animated) will have only 1 frame. */
const u32& getFramesCount() const { return framesCount; }
const u32& getCurrentAnimationFrame() const { return animState.currentFrame; }
const u32& getNextAnimationFrame() const { return animState.nextFrame; }
const u32& getStartAnimationFrame() const { return animState.startFrame; }
const u32& getEndAnimationFrame() const { return animState.endFrame; }
const u32& getStayAnimationFrame() const { return animState.stayFrame; }
void setCurrentAnimationFrame(const u32& v) { animState.currentFrame = v; }
void setNextAnimationFrame(const u32& v) { animState.nextFrame = v; }
void setStartAnimationFrame(const u32& v) { animState.startFrame = v; }
void setEndAnimationFrame(const u32& v) { animState.endFrame = v; }
void setStayAnimationFrame(const u32& v) { animState.stayFrame = v; }
DynamicMeshAnimState animState;
/** @returns bounding box object of current frame. */
const BBox& getCurrentBoundingBox() const {
return frames[animState.currentFrame]->getBBox();
return *frames[animState.currentFrame]->bbox;
}
/** Loop in one frame */
void playAnimation(const u32& t_frame) { playAnimation(t_frame, t_frame); }
void playAnimation(const u32& t_frame);
/** Play animation in loop from startFrame to endFrame */
void playAnimation(const u32& t_startFrame, const u32& t_endFrame);
@@ -73,9 +55,6 @@ class DynamicMesh : public Mesh {
private:
void initAnimation();
DynamicMeshAnimState animState;
u32 framesCount;
MeshFrame** frames;
};
} // namespace Tyra
+5 -18
View File
@@ -23,17 +23,14 @@ class Mesh {
explicit Mesh(const Mesh& mesh);
~Mesh();
/** Translation matrix */
M4x4 translation;
u8 isMother;
/** Rotation matrix */
M4x4 rotation;
u32 id;
/** Scale matrix */
M4x4 scale;
M4x4 translation, rotation, scale;
std::vector<MeshMaterial*> materials;
inline const u32& getId() const { return id; }
inline const u8& isMother() const { return _isMother; }
M4x4 getModelMatrix() const;
/** Get position from translation matrix */
@@ -43,18 +40,8 @@ class Mesh {
void setPosition(const Vec4& v);
/** Returns material, which is a mesh "subgroup". */
MeshMaterial* getMaterial(const u32& i) const { return materials[i]; }
MeshMaterial** getMaterials() { return materials; }
const u32& getMaterialsCount() const { return materialsCount; }
protected:
void init();
u8 _isMother;
u32 id, materialsCount;
MeshMaterial** materials;
};
} // namespace Tyra
+5 -8
View File
@@ -22,19 +22,16 @@ class MeshFrame {
explicit MeshFrame(const MeshFrame& frame);
~MeshFrame();
const u32& getId() const { return id; }
const u8& isMother() const { return _isMother; }
const BBox& getBBox() const { return *bbox; }
u8 isMother;
u32 id;
BBox* bbox;
void print() const;
void print(const char* name) const;
void print(const std::string& name) const { print(name.c_str()); }
std::string getPrint(const char* name = nullptr) const;
private:
u8 _isMother;
BBox* bbox;
u32 id;
};
} // namespace Tyra
+7 -18
View File
@@ -22,33 +22,22 @@ class MeshMaterial {
explicit MeshMaterial(const MeshMaterial& material);
~MeshMaterial();
Color color;
u8 isMother, lightmapFlag;
const u32& getId() const { return id; }
const std::string& getName() const { return _name; }
const u8& isMother() const { return _isMother; }
const u32& getFramesCount() const { return framesCount; }
const u8& isSingleColorActivated() const {
return singleColorFlag;
} // TODO: colormode -> color / lightmap
u32 id;
MeshMaterialFrame** getFrames() const { return frames; }
MeshMaterialFrame* getFrame(const u32& i) const { return frames[i]; }
std::string name;
Color ambient;
std::vector<MeshMaterialFrame*> frames;
const BBox& getBBox(const u32& frame) const;
void setSingleColorFlag(const u8& flag);
void print() const;
void print(const char* name) const;
void print(const std::string& name) const { print(name.c_str()); }
std::string getPrint(const char* name = nullptr) const;
private:
MeshMaterialFrame** frames;
std::string _name;
u8 _isMother, singleColorFlag;
u32 id, framesCount;
};
} // namespace Tyra
@@ -22,28 +22,20 @@ class MeshMaterialFrame {
explicit MeshMaterialFrame(const MeshMaterialFrame& frame);
~MeshMaterialFrame();
const u32& getId() const { return id; }
const u8& isMother() const { return _isMother; }
const BBox& getBBox() const { return *bbox; }
u8 isMother;
const u32& getVertexCount() const { return count; }
Vec4* getVertices() const { return vertices; }
Vec4* getNormals() const { return normals; }
Vec4* getTextureCoords() const { return textureCoords; }
Color* getColors() const { return colors; }
u32 id, count;
Vec4 *vertices, *textureCoords, *normals;
Color* colors;
BBox* bbox;
void print() const;
void print(const char* name) const;
void print(const std::string& name) const { print(name.c_str()); }
std::string getPrint(const char* name = nullptr) const;
private:
BBox* bbox;
u8 _isMother;
u32 id, count;
Vec4 *vertices, *textureCoords, *normals;
Color* colors;
};
} // namespace Tyra
@@ -22,12 +22,6 @@ class StaticMesh : public Mesh {
StaticMesh(const StaticMesh& mesh);
~StaticMesh();
MeshFrame* getFrame() { return frame; }
/** @returns bounding box object of current frame. */
const BBox& getBoundingBox() const { return frame->getBBox(); }
private:
MeshFrame* frame;
};
@@ -30,10 +30,11 @@ class CoreBBox {
explicit CoreBBox(const std::vector<CoreBBox>& t_bboxes,
const u32& startIndex, const u32& stopIndex);
const Vec4& operator[](const u8& i) { return _vertices[i]; }
Vec4 vertices[8];
const Vec4& operator[](const u8& i) { return vertices[i]; }
const u8 getVertexCount() { return 8; }
const Vec4& getVertex(const u8& i) { return _vertices[i]; }
Vec4* getVertices() { return _vertices; }
void print() const;
void print(const char* name) const;
@@ -42,9 +43,6 @@ class CoreBBox {
CoreBBoxFrustum isInFrustum(const Plane* frustumPlanes, const M4x4& model,
const float* margins = nullptr) const;
protected:
Vec4 _vertices[8];
};
} // namespace Tyra