mesh -> dynamicmesh
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||
#include "./dynamic_mesh_frame.hpp"
|
||||
#include "./dynamic_mesh_material_frame.hpp"
|
||||
#include "./dynamic_mesh_anim_state.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class DynamicMesh {
|
||||
public:
|
||||
explicit DynamicMesh(const MeshBuilderData& data);
|
||||
explicit DynamicMesh(const DynamicMesh& mesh);
|
||||
~DynamicMesh();
|
||||
|
||||
/** Translation matrix */
|
||||
M4x4 translation;
|
||||
|
||||
/** Rotation matrix */
|
||||
M4x4 rotation;
|
||||
|
||||
/** Scale matrix */
|
||||
M4x4 scale;
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
|
||||
const u8& isMother() const { return _isMother; }
|
||||
|
||||
/** Get position from translation matrix */
|
||||
Vec4* getPosition() {
|
||||
return reinterpret_cast<Vec4*>(&translation.data[3 * 4]);
|
||||
}
|
||||
|
||||
void setPosition(const Vec4& v) {
|
||||
TYRA_ASSERT(v.w == 1.0F, "Vec4 must be homogeneous");
|
||||
reinterpret_cast<Vec4*>(&translation.data[3 * 4])->set(v);
|
||||
}
|
||||
|
||||
/** Returns material, which is a mesh "subgroup". */
|
||||
DynamicMeshMaterial* getMaterial(const u32& i) const { return materials[i]; }
|
||||
|
||||
const u32& getMaterialsCount() const { return materialsCount; }
|
||||
|
||||
const DynamicMeshAnimState& getAnimState() const { return animState; }
|
||||
|
||||
/** Count of all vertices. */
|
||||
u32 getVertexCount() { return frames[0]->getVertexCount(); }
|
||||
|
||||
/** Returns single frame. */
|
||||
DynamicMeshFrame* getFrame(const u32& i) const { return frames[i]; }
|
||||
|
||||
/** 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; }
|
||||
|
||||
M4x4 getModelMatrix() const;
|
||||
|
||||
// /**
|
||||
// * Returns material, which is a mesh "subgroup".
|
||||
// * NULL if not found.
|
||||
// */
|
||||
// DynamicMeshMaterial* getMaterialById(const u32& t_id) const;
|
||||
|
||||
/** @returns bounding box object of current frame. */
|
||||
const BBox& getCurrentBoundingBox() const {
|
||||
return frames[animState.currentFrame]->getBBox();
|
||||
}
|
||||
|
||||
/** Check if are there any frames */
|
||||
u8 isDataLoaded() const { return framesCount > 0; }
|
||||
|
||||
/** Loop in one frame */
|
||||
void playAnimation(const u32& t_frame) { playAnimation(t_frame, t_frame); }
|
||||
|
||||
/** Play animation in loop from startFrame to endFrame */
|
||||
void playAnimation(const u32& t_startFrame, const u32& t_endFrame);
|
||||
|
||||
/** Play animation from startFrame to endFrame and after loop in stayFrame
|
||||
*/
|
||||
void playAnimation(const u32& t_startFrame, const u32& t_endFrame,
|
||||
const u32& t_stayFrame);
|
||||
|
||||
void setAnimSpeed(const float& t_value) { animState.speed = t_value; }
|
||||
|
||||
void animate();
|
||||
|
||||
/**
|
||||
* Check if this class loaded mesh data first.
|
||||
* Meshes which use loadFrom() method have false there.
|
||||
*/
|
||||
const u8& isStayAnimationSet() const { return animState.isStayFrameSet; }
|
||||
|
||||
private:
|
||||
void initMesh();
|
||||
DynamicMeshAnimState animState;
|
||||
u8 _isMother;
|
||||
u32 id, framesCount, materialsCount;
|
||||
DynamicMeshFrame** frames;
|
||||
DynamicMeshMaterial** materials;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tamtypes.h>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
typedef struct {
|
||||
u32 startFrame;
|
||||
u32 endFrame;
|
||||
u32 stayFrame;
|
||||
u8 isStayFrameSet;
|
||||
float speed;
|
||||
float interpolation;
|
||||
u32 animType;
|
||||
u32 currentFrame;
|
||||
u32 nextFrame;
|
||||
} DynamicMeshAnimState;
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./dynamic_mesh_material.hpp"
|
||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||
#include "renderer/3d/bbox/bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class DynamicMeshFrame {
|
||||
public:
|
||||
explicit DynamicMeshFrame(const MeshBuilderData& data, const u32& index);
|
||||
explicit DynamicMeshFrame(const DynamicMeshFrame& frame);
|
||||
~DynamicMeshFrame();
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
const u32& getVertexCount() const { return vertexCount; }
|
||||
const u32& getTextureCoordsCount() const { return textureCoordsCount; }
|
||||
const u32& getNormalsCount() const { return normalsCount; }
|
||||
const u32& getColorsCount() const { return colorsCount; }
|
||||
const u8& isMother() const { return _isMother; }
|
||||
const BBox& getBBox() const { return *bbox; }
|
||||
|
||||
Vec4* getVertices() const { return vertices; }
|
||||
Vec4* getNormals() const { return normals; }
|
||||
Vec4* getTextureCoords() const { return textureCoords; }
|
||||
Color* getColors() const { return colors; }
|
||||
|
||||
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, vertexCount, textureCoordsCount, normalsCount, colorsCount;
|
||||
Vec4 *vertices, *textureCoords, *normals;
|
||||
Color* colors;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug/debug.hpp"
|
||||
#include "loaders/3d/builder/mesh_builder_data.hpp"
|
||||
#include "renderer/3d/mesh/dynamic/dynamic_mesh_material_frame.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class DynamicMeshMaterial {
|
||||
public:
|
||||
explicit DynamicMeshMaterial(const MeshBuilderData& data,
|
||||
const u32& materialIndex);
|
||||
explicit DynamicMeshMaterial(const DynamicMeshMaterial& material);
|
||||
~DynamicMeshMaterial();
|
||||
|
||||
Color singleColor;
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
const std::string& getName() const { return _name; }
|
||||
const u32& getFacesCount() const { return facesCount; }
|
||||
const u8& isMother() const { return _isMother; }
|
||||
const u8& isSingleColorActivated() const { return singleColorFlag; }
|
||||
|
||||
u32* getVertexFaces() const { return vertexFaces; }
|
||||
u32* getTextureCoordFaces() const { return textureCoordFaces; }
|
||||
u32* getNormalFaces() const { return normalFaces; }
|
||||
u32* getColorFaces() const { return normalFaces; }
|
||||
DynamicMeshMaterialFrame* getFrames() const { return *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:
|
||||
DynamicMeshMaterialFrame** frames;
|
||||
|
||||
std::string _name;
|
||||
u8 _isMother, singleColorFlag;
|
||||
u32 id, facesCount, framesCount;
|
||||
u32 *vertexFaces, *textureCoordFaces, *normalFaces, *colorFaces;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "./renderer/3d/bbox/bbox.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class DynamicMeshMaterialFrame {
|
||||
public:
|
||||
explicit DynamicMeshMaterialFrame(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex);
|
||||
explicit DynamicMeshMaterialFrame(const DynamicMeshMaterialFrame& frame);
|
||||
~DynamicMeshMaterialFrame();
|
||||
|
||||
const u32& getId() const { return id; }
|
||||
const u8& isMother() const { return _isMother; }
|
||||
const BBox& getBBox() const { return *bbox; }
|
||||
|
||||
private:
|
||||
BBox* bbox;
|
||||
|
||||
u8 _isMother;
|
||||
u32 id;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
Reference in New Issue
Block a user