tyrav2 init

This commit is contained in:
h4570
2022-07-17 10:21:35 +02:00
parent 44c1ee4fe8
commit c8b22ff331
249 changed files with 18187 additions and 0 deletions
+121
View File
@@ -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 "./mesh_frame.hpp"
#include "./mesh_material_frame.hpp"
#include "./mesh_anim_state.hpp"
namespace Tyra {
class Mesh {
public:
explicit Mesh(const MeshBuilderData& data);
explicit Mesh(const Mesh& mesh);
~Mesh();
/** 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". */
MeshMaterial* getMaterial(const u32& i) const { return materials[i]; }
const u32& getMaterialsCount() const { return materialsCount; }
const MeshAnimState& getAnimState() const { return animState; }
/** Count of all vertices. */
u32 getVertexCount() { return frames[0]->getVertexCount(); }
/** Returns single frame. */
MeshFrame* 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.
// */
// MeshMaterial* 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();
MeshAnimState animState;
u8 _isMother;
u32 id, framesCount, materialsCount;
MeshFrame** frames;
MeshMaterial** 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;
} MeshAnimState;
} // 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 "renderer/3d/mesh/mesh_material.hpp"
#include "loaders/3d/builder/mesh_builder_data.hpp"
#include "renderer/3d/bbox/bbox.hpp"
namespace Tyra {
class MeshFrame {
public:
explicit MeshFrame(const MeshBuilderData& data, const u32& index);
explicit MeshFrame(const MeshFrame& frame);
~MeshFrame();
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,57 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# 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/mesh_material_frame.hpp"
namespace Tyra {
class MeshMaterial {
public:
explicit MeshMaterial(const MeshBuilderData& data, const u32& materialIndex);
explicit MeshMaterial(const MeshMaterial& material);
~MeshMaterial();
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; }
MeshMaterialFrame* 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:
MeshMaterialFrame** frames;
std::string _name;
u8 _isMother, singleColorFlag;
u32 id, facesCount, framesCount;
u32 *vertexFaces, *textureCoordFaces, *normalFaces, *colorFaces;
};
} // namespace Tyra
@@ -0,0 +1,35 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# 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 MeshMaterialFrame {
public:
explicit MeshMaterialFrame(const MeshBuilderData& data, const u32& frameIndex,
const u32& materialIndex);
explicit MeshMaterialFrame(const MeshMaterialFrame& frame);
~MeshMaterialFrame();
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