added animation support to obj
This commit is contained in:
@@ -22,10 +22,10 @@ public:
|
||||
ObjLoader();
|
||||
~ObjLoader();
|
||||
|
||||
void load(ObjModel *o_result, char *t_fileName, float t_scale);
|
||||
void load(Frame *o_result, char *t_fileName, float t_scale);
|
||||
|
||||
private:
|
||||
void allocateObjMemory(FILE *t_file, ObjModel *t_result);
|
||||
void allocateObjMemory(FILE *t_file, Frame *t_result);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ class String
|
||||
{
|
||||
|
||||
public:
|
||||
static char *createU32ToString(u32 a);
|
||||
static char *createWithLeadingZeros(char *a);
|
||||
static char *createCopy(char *source);
|
||||
static u32 getLength(char *a);
|
||||
static char *createConcatenated(char *a, char *b);
|
||||
|
||||
Reference in New Issue
Block a user