added animation support to obj

This commit is contained in:
Sandro Sobczyński
2020-10-28 20:42:17 +01:00
parent abda2fe3fa
commit 9e00ef3634
12 changed files with 242 additions and 119 deletions
+28
View File
@@ -0,0 +1,28 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#ifndef _TYRA_ANIM_STATE_
#define _TYRA_ANIM_STATE_
#include <tamtypes.h>
typedef struct
{
u32 startFrame;
u32 endFrame;
float speed;
float interpolation;
u32 animType;
u32 currentFrame;
u32 nextFrame;
} AnimState;
#endif
+2 -12
View File
@@ -15,17 +15,7 @@
#include <math3d.h>
#include "math/vector3.hpp"
#include "math/point.hpp"
typedef struct
{
u32 startFrame;
u32 endFrame;
float speed;
float interpolation;
u32 animType;
u32 currentFrame;
u32 nextFrame;
} MD2AnimState;
#include "./anim_state.hpp"
typedef struct
{
@@ -43,7 +33,7 @@ public:
Point *coordinates;
u32 *normalIndexes;
MD2Triangle *triangles;
MD2AnimState animState;
AnimState animState;
/** File name without extension */
char *filename;
MD2Model(char *t_md2File);
+1 -1
View File
@@ -39,7 +39,7 @@ public:
Mesh();
~Mesh();
void loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float t_scale);
void loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float t_scale, u16 framesAmount);
void setObj(Vector3 &t_initPos, ObjModel *t_objModel, MeshSpec *t_spec);
void loadDff(char *t_subfolder, char *t_dffFile, Vector3 &t_initPos, float t_scale);
void setDff(Vector3 &t_initPos, DffModel *t_dffModel, MeshSpec *t_spec);
+16 -6
View File
@@ -14,6 +14,7 @@
#include <tamtypes.h>
#include <math3d.h>
#include "math/vector3.hpp"
#include "./anim_state.hpp"
struct ObjMaterial
{
@@ -22,19 +23,26 @@ struct ObjMaterial
u32 *verticeFaces, *coordinateFaces, *normalFaces;
};
struct Frame
{
u16 number;
u32 verticesCount, coordinatesCount, normalsCount, materialsCount;
Vector3 *vertices __attribute__((aligned(16))),
*coordinates __attribute__((aligned(16))),
*normals __attribute__((aligned(16)));
ObjMaterial *materials;
};
/** Class which have common types for all 3D objects */
class ObjModel
{
public:
u32 verticesCount, coordinatesCount, normalsCount, materialsCount;
Vector3 *vertices __attribute__((aligned(16))),
*coordinates __attribute__((aligned(16))),
*normals __attribute__((aligned(16)));
/** File name without extension */
char *filename;
ObjMaterial *materials;
u16 frameCount;
Frame *frames;
AnimState animState;
ObjModel(char *t_objFile);
~ObjModel();
@@ -43,6 +51,8 @@ public:
u8 isMemoryAllocated;
private:
Vector3 calc3Vectors[3];
Vector3 calcVector;
void fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u32 t_materialI, u32 t_getI, u32 t_setI);
};