From 5320d7f84d437146909ebc0e824e80fc15ce7b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Sobczy=C5=84ski?= Date: Thu, 29 Oct 2020 17:47:28 +0100 Subject: [PATCH] draw refactoring #1 --- src/engine/include/models/math/vector3.hpp | 6 +- src/engine/include/models/md2_model.hpp | 1 - src/engine/include/models/mesh_frame.hpp | 26 ++++++++ src/engine/include/models/mesh_material.hpp | 64 +++++++++++++++++++ src/engine/include/models/obj_model.hpp | 21 ++++--- src/engine/loaders/obj_loader.cpp | 40 ++++++------ src/engine/models/math/vector3.cpp | 9 ++- src/engine/models/md2_model.cpp | 5 +- src/engine/models/mesh.cpp | 3 +- src/engine/models/mesh_frame.cpp | 24 +++++++ src/engine/models/mesh_material.cpp | 68 ++++++++++++++++++++ src/engine/models/obj_model.cpp | 69 +++++++++------------ src/engine/modules/renderer.cpp | 3 + src/samples/ari/Makefile | 2 + src/samples/ari/ari.cpp | 4 ++ 15 files changed, 267 insertions(+), 78 deletions(-) create mode 100644 src/engine/include/models/mesh_frame.hpp create mode 100644 src/engine/include/models/mesh_material.hpp create mode 100644 src/engine/models/mesh_frame.cpp create mode 100644 src/engine/models/mesh_material.cpp diff --git a/src/engine/include/models/math/vector3.hpp b/src/engine/include/models/math/vector3.hpp index c173d8b..b8996ba 100644 --- a/src/engine/include/models/math/vector3.hpp +++ b/src/engine/include/models/math/vector3.hpp @@ -48,10 +48,10 @@ public: u8 isOnSquare(Vector3 &t_min, Vector3 &t_max); float length(); void normalize(); - void setByLerp(const Vector3 &v1, const Vector3 &v2, const float t_interp); + void setByLerp(const Vector3 &v1, const Vector3 &v2, const float &t_interp, const float &t_scale); float innerProduct(Vector3 &v); - void set(Vector3 &v); - void set(float x, float y, float z); + void set(const Vector3 &v); + void set(const float &x, const float &y, const float &z); void copy(Vector3 &v); float distanceTo(Vector3 &v); void print(); diff --git a/src/engine/include/models/md2_model.hpp b/src/engine/include/models/md2_model.hpp index 4c00f3a..e57a178 100644 --- a/src/engine/include/models/md2_model.hpp +++ b/src/engine/include/models/md2_model.hpp @@ -42,7 +42,6 @@ public: void allocateMemory(); private: - Vector3 calcVector; Vector3 calc3Vectors[3]; }; diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp new file mode 100644 index 0000000..f8d25f2 --- /dev/null +++ b/src/engine/include/models/mesh_frame.hpp @@ -0,0 +1,26 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#ifndef _TYRA_MESH_FRAME_ +#define _TYRA_MESH_FRAME_ + +#include + +class MeshFrame +{ + +public: + MeshFrame(); + ~MeshFrame(); + +private: +}; + +#endif diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp new file mode 100644 index 0000000..a511b39 --- /dev/null +++ b/src/engine/include/models/mesh_material.hpp @@ -0,0 +1,64 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#ifndef _TYRA_MESH_MATERIAL_ +#define _TYRA_MESH_MATERIAL_ + +#include + +class MeshMaterial +{ + +public: + MeshMaterial(); + ~MeshMaterial(); + + /** Material name. */ + char *getName() const { return name; }; + const u32 &getFacesCount() const { return facesCount; }; + /** Indexes of vertices. Each 3 faces will give you vertices of next triangle. */ + const u32 &getVertexFace(const u32 &i) const { return vertexFaces[i]; }; + /** Indexes of texture coords. Each 3 faces will give you texture coords of next triangle. */ + const u32 &getStFace(const u32 &i) const { return stFaces[i]; }; + /** Indexes of normal vectors used for lighting. Each 3 faces will give you normal vectors of next triangle. */ + const u32 &getNormalFace(const u32 &i) const { return normalFaces[i]; }; + /** Array of vertex faces. Size of getFacesCount() */ + const u32 *getVertexFaces() const { return vertexFaces; }; + /** Array of texture coords faces. Size of getFacesCount() */ + const u32 *getStFaces() const { return stFaces; }; + /** Array of normal vector faces. Size of getFacesCount() */ + const u32 *getNormalFaces() const { return normalFaces; }; + + /** Set faces count and allocate faces memory. */ + void setFacesCount(const u32 &t_val); + + /** Set vertex face. Do not call this method until you know what you do. + * Should be called by data loader. */ + void setVertexFace(const u32 &t_index, const u32 &t_val) { vertexFaces[t_index] = t_val; } + + /** Set st face. Do not call this method until you know what you do. + * Should be called by data loader. */ + void setStFace(const u32 &t_index, const u32 &t_val) { stFaces[t_index] = t_val; } + + /** Set vertex face. Do not call this method until you know what you do. + * Should be called by data loader. */ + void setNormalFace(const u32 &t_index, const u32 &t_val) { normalFaces[t_index] = t_val; } + + /** Set material name. */ + void setName(char *t_val); + +private: + u32 facesCount; + u32 *vertexFaces, *stFaces, *normalFaces; + u8 isNameAllocated, areFacesAllocated; + char *name; +}; + +#endif diff --git a/src/engine/include/models/obj_model.hpp b/src/engine/include/models/obj_model.hpp index 38ca884..faac561 100644 --- a/src/engine/include/models/obj_model.hpp +++ b/src/engine/include/models/obj_model.hpp @@ -14,13 +14,21 @@ #include #include #include "math/vector3.hpp" +#include "utils/debug.hpp" #include "./anim_state.hpp" +#include "./mesh_material.hpp" -struct ObjMaterial +class Frame2 { - char *materialName; - u32 facesCount; - u32 *verticeFaces, *coordinateFaces, *normalFaces; +public: + Frame2() { printf("Frame2 constructor\n"); }; + ~Frame2() { printf("Frame2 destructor\n"); }; + u16 number; + u32 verticesCount, coordinatesCount, normalsCount, materialsCount; + Vector3 *vertices __attribute__((aligned(16))), + *coordinates __attribute__((aligned(16))), + *normals __attribute__((aligned(16))); + MeshMaterial *materials; }; struct Frame @@ -30,7 +38,7 @@ struct Frame Vector3 *vertices __attribute__((aligned(16))), *coordinates __attribute__((aligned(16))), *normals __attribute__((aligned(16))); - ObjMaterial *materials; + MeshMaterial *materials; }; /** Class which have common types for all 3D objects */ @@ -46,14 +54,13 @@ public: ObjModel(char *t_objFile); ~ObjModel(); + void animate(); u32 getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled); u32 getFacesCount(); 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); }; #endif diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 973c962..89fb317 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -67,7 +67,7 @@ void ObjLoader::load(Frame *o_result, char *t_filename, float t_scale) { char temp[30]; fscanf(file, "%s\n", temp); - o_result->materials[++materialsI].materialName = String::createCopy(temp); + o_result->materials[++materialsI].setName(temp); faceI = 0; } else if (strcmp(lineHeader, "f") == 0) @@ -80,17 +80,17 @@ void ObjLoader::load(Frame *o_result, char *t_filename, float t_scale) PRINT_ERR(".obj can't be read by this simple parser. Try exporting with other options"); else { - o_result->materials[materialsI].verticeFaces[faceI] = vertexIndex[0] - 1; - o_result->materials[materialsI].verticeFaces[faceI + 1] = vertexIndex[1] - 1; - o_result->materials[materialsI].verticeFaces[faceI + 2] = vertexIndex[2] - 1; + o_result->materials[materialsI].setVertexFace(faceI, vertexIndex[0] - 1); + o_result->materials[materialsI].setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->materials[materialsI].setVertexFace(faceI + 2, vertexIndex[2] - 1); - o_result->materials[materialsI].coordinateFaces[faceI] = coordIndex[0] - 1; - o_result->materials[materialsI].coordinateFaces[faceI + 1] = coordIndex[1] - 1; - o_result->materials[materialsI].coordinateFaces[faceI + 2] = coordIndex[2] - 1; + o_result->materials[materialsI].setStFace(faceI, coordIndex[0] - 1); + o_result->materials[materialsI].setStFace(faceI + 1, coordIndex[1] - 1); + o_result->materials[materialsI].setStFace(faceI + 2, coordIndex[2] - 1); - o_result->materials[materialsI].normalFaces[faceI] = normalIndex[0] - 1; - o_result->materials[materialsI].normalFaces[faceI + 1] = normalIndex[1] - 1; - o_result->materials[materialsI].normalFaces[faceI + 2] = normalIndex[2] - 1; + o_result->materials[materialsI].setNormalFace(faceI, normalIndex[0] - 1); + o_result->materials[materialsI].setNormalFace(faceI + 1, normalIndex[1] - 1); + o_result->materials[materialsI].setNormalFace(faceI + 2, normalIndex[2] - 1); faceI += 3; } } @@ -128,11 +128,11 @@ void ObjLoader::allocateObjMemory(FILE *t_file, Frame *o_result) break; } - o_result->materials = new ObjMaterial[o_result->materialsCount]; + o_result->materials = new MeshMaterial[o_result->materialsCount]; s16 currentMatI = -1; fseek(t_file, 0, SEEK_SET); - + u32 facesCounter = 0; while (1) { char lineHeader[128]; @@ -140,20 +140,20 @@ void ObjLoader::allocateObjMemory(FILE *t_file, Frame *o_result) if (res != EOF) { if (strcmp(lineHeader, "usemtl") == 0) - o_result->materials[++currentMatI].facesCount = 0; + { + if (currentMatI >= 0) // Skip -1 + o_result->materials[currentMatI].setFacesCount(facesCounter); + currentMatI++; + } else if (strcmp(lineHeader, "f") == 0) - o_result->materials[currentMatI].facesCount += 3; + facesCounter += 3; } else break; } - for (u16 i = 0; i < o_result->materialsCount; i++) - { - o_result->materials[i].coordinateFaces = new u32[o_result->materials[i].facesCount]; - o_result->materials[i].normalFaces = new u32[o_result->materials[i].facesCount]; - o_result->materials[i].verticeFaces = new u32[o_result->materials[i].facesCount]; - } + o_result->materials[currentMatI].setFacesCount(facesCounter); // Allocate last one + o_result->vertices = new Vector3[o_result->verticesCount]; o_result->coordinates = new Vector3[o_result->coordinatesCount]; o_result->normals = new Vector3[o_result->normalsCount]; diff --git a/src/engine/models/math/vector3.cpp b/src/engine/models/math/vector3.cpp index 482c0df..b5c95ea 100644 --- a/src/engine/models/math/vector3.cpp +++ b/src/engine/models/math/vector3.cpp @@ -33,7 +33,7 @@ Vector3::Vector3(const Vector3 &another) z = another.z; } -void Vector3::setByLerp(const Vector3 &v1, const Vector3 &v2, const float t_interp) +void Vector3::setByLerp(const Vector3 &v1, const Vector3 &v2, const float &t_interp, const float &t_scale) { asm volatile( "lqc2 vf4, 0x0(%1) \n\t" // vf4 = v1 @@ -47,6 +47,9 @@ void Vector3::setByLerp(const Vector3 &v1, const Vector3 &v2, const float t_inte : : "r"(&this->xyz), "r"(&v1.xyz), "r"(&v2.xyz), "f"(t_interp) : "$8"); + x *= t_scale; + y *= t_scale; + z *= t_scale; } /** Create empty vector */ @@ -245,14 +248,14 @@ float Vector3::innerProduct(Vector3 &v) // return (x * v.x + y * v.y + z * v.z); } -void Vector3::set(float x, float y, float z) +void Vector3::set(const float &x, const float &y, const float &z) { this->x = x; this->y = y; this->z = z; } -void Vector3::set(Vector3 &v) +void Vector3::set(const Vector3 &v) { this->x = v.x; this->y = v.y; diff --git a/src/engine/models/md2_model.cpp b/src/engine/models/md2_model.cpp index ed0098a..3267981 100644 --- a/src/engine/models/md2_model.cpp +++ b/src/engine/models/md2_model.cpp @@ -83,10 +83,7 @@ u32 MD2Model::getCurrentFrameData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR const u32 NEXT_VERTICE = triangles[iTri].verticeIndexes[iVert] + (verticesPerFrameCount * animState.nextFrame); - calcVector.setByLerp(vertices[CURR_VERTICE], vertices[NEXT_VERTICE], animState.interpolation); - calc3Vectors[iVert].x = calcVector.x * t_scale; - calc3Vectors[iVert].y = calcVector.y * t_scale; - calc3Vectors[iVert].z = calcVector.z * t_scale; + calc3Vectors[iVert].setByLerp(vertices[CURR_VERTICE], vertices[NEXT_VERTICE], animState.interpolation, t_scale); } } if (!t_shouldBeBackfaceCulled || Vector3::shouldBeBackfaceCulled(&t_cameraPos, &calc3Vectors[2], &calc3Vectors[1], &calc3Vectors[0]) == 0) diff --git a/src/engine/models/mesh.cpp b/src/engine/models/mesh.cpp index 619eccf..680c491 100644 --- a/src/engine/models/mesh.cpp +++ b/src/engine/models/mesh.cpp @@ -93,6 +93,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float for (u16 i = 0; i < framesAmount; i++) { + // obj->frames[i] = Frame(); char *part3 = String::createU32ToString(i + 1); // 0 -> "1" char *part4 = String::createWithLeadingZeros(part3); // "000001" char *part5 = String::createConcatenated(part2, part4); // "folder/object_000001" @@ -182,7 +183,7 @@ void Mesh::loadTextures(char *t_subfolder, char *t_extension) spec->textures = new Texture[obj->frames[0].materialsCount]; for (u8 i = 0; i < obj->frames[0].materialsCount; i++) { - bmpLoader.load(spec->textures[i], t_subfolder, obj->frames[0].materials[i].materialName, t_extension); + bmpLoader.load(spec->textures[i], t_subfolder, obj->frames[0].materials[i].getName(), t_extension); setDefaultWrapSettings(spec->textures[i].wrapSettings); } } diff --git a/src/engine/models/mesh_frame.cpp b/src/engine/models/mesh_frame.cpp new file mode 100644 index 0000000..17ebf2e --- /dev/null +++ b/src/engine/models/mesh_frame.cpp @@ -0,0 +1,24 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "../include/models/mesh_frame.hpp" +#include "../include/utils/debug.hpp" + +// ---- +// Constructors/Destructors +// ---- + +MeshFrame::MeshFrame() {} + +MeshFrame::~MeshFrame() {} + +// ---- +// Methods +// ---- diff --git a/src/engine/models/mesh_material.cpp b/src/engine/models/mesh_material.cpp new file mode 100644 index 0000000..91077e5 --- /dev/null +++ b/src/engine/models/mesh_material.cpp @@ -0,0 +1,68 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "../include/models/mesh_material.hpp" +#include "../include/utils/debug.hpp" +#include "../include/utils/string.hpp" + +// ---- +// Constructors/Destructors +// ---- + +MeshMaterial::MeshMaterial() +{ + facesCount = 0; + isNameAllocated = false; + areFacesAllocated = false; +} + +MeshMaterial::~MeshMaterial() +{ + + if (areFacesAllocated) + { + delete[] vertexFaces; + delete[] stFaces; + delete[] normalFaces; + } + if (isNameAllocated) + { + delete[] name; + } +} + +// ---- +// Methods +// ---- + +void MeshMaterial::setFacesCount(const u32 &t_val) +{ + if (areFacesAllocated) + { + PRINT_ERR("Can't set faces, because faces were already set!"); + return; + } + facesCount = t_val; + stFaces = new u32[t_val]; + normalFaces = new u32[t_val]; + vertexFaces = new u32[t_val]; + areFacesAllocated = true; +} + +void MeshMaterial::setName(char *t_val) +{ + if (isNameAllocated) + { + PRINT_ERR("Can't set name, because was already set!"); + return; + } + name = String::createCopy(t_val); + isNameAllocated = true; +} diff --git a/src/engine/models/obj_model.cpp b/src/engine/models/obj_model.cpp index 472a4a5..a49c620 100644 --- a/src/engine/models/obj_model.cpp +++ b/src/engine/models/obj_model.cpp @@ -56,15 +56,13 @@ u32 ObjModel::getFacesCount() { u32 result = 0; // TODO for (u16 i = 0; i < frames[0].materialsCount; i++) - result += frames[0].materials[i].facesCount; + result += frames[0].materials[i].getFacesCount(); return result; } -u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) +void ObjModel::animate() { - u32 addedFaces = 0; - - animState.interpolation += animState.speed; // TODO move it out + animState.interpolation += animState.speed; if (animState.interpolation >= 1.0F) { animState.interpolation = 0.0F; @@ -72,44 +70,42 @@ u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_nor if (++animState.nextFrame > animState.endFrame) animState.nextFrame = animState.startFrame; } +} - for (u32 j = 0; j < frames[animState.currentFrame].materials[t_materialIndex].facesCount; j += 3) +u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) +{ +#define CURR_FRAME frames[animState.currentFrame] +#define NEXT_FRAME frames[animState.nextFrame] +#define MATERIAL CURR_FRAME.materials[t_materialIndex] +#define CURR_VERT CURR_FRAME.vertices[MATERIAL.getVertexFace(matI + vertI)] +#define NEXT_VERT NEXT_FRAME.vertices[MATERIAL.getVertexFace(matI + vertI)] + u32 addedFaces = 0; + + for (u32 matI = 0; matI < MATERIAL.getFacesCount(); matI += 3) { - for (u32 iVert = 0; iVert < 3; iVert++) - { - const ObjMaterial CURR_MAT = frames[animState.currentFrame].materials[t_materialIndex]; - const Vector3 CURR_VERT = frames[animState.currentFrame].vertices[CURR_MAT.verticeFaces[j + iVert]]; + for (u32 vertI = 0; vertI < 3; vertI++) if (animState.startFrame == animState.endFrame) - { - calc3Vectors[iVert].x = CURR_VERT.x * t_scale; - calc3Vectors[iVert].y = CURR_VERT.y * t_scale; - calc3Vectors[iVert].z = CURR_VERT.z * t_scale; - } + calc3Vectors[vertI].set(CURR_VERT * t_scale); else + calc3Vectors[vertI].setByLerp(CURR_VERT, NEXT_VERT, animState.interpolation, t_scale); + + if (!t_shouldBeBackfaceCulled || + Vector3::shouldBeBackfaceCulled(&t_cameraPos, &calc3Vectors[2], &calc3Vectors[1], &calc3Vectors[0])) + + for (u32 vertI = 0; vertI < 3; vertI++) { - const Vector3 NEXT_VERT = frames[animState.nextFrame].vertices[CURR_MAT.verticeFaces[j + iVert]]; - calcVector.setByLerp(CURR_VERT, NEXT_VERT, animState.interpolation); - calc3Vectors[iVert].x = calcVector.x * t_scale; - calc3Vectors[iVert].y = calcVector.y * t_scale; - calc3Vectors[iVert].z = calcVector.z * t_scale; - } - } - if (!t_shouldBeBackfaceCulled || Vector3::shouldBeBackfaceCulled(&t_cameraPos, &calc3Vectors[2], &calc3Vectors[1], &calc3Vectors[0]) == 0) - for (u32 iVert = 0; iVert < 3; iVert++) - { - const u32 CURR_FRAME = animState.currentFrame; - o_vertices[addedFaces][0] = calc3Vectors[iVert].x; - o_vertices[addedFaces][1] = calc3Vectors[iVert].y; - o_vertices[addedFaces][2] = calc3Vectors[iVert].z; + o_vertices[addedFaces][0] = calc3Vectors[vertI].x; + o_vertices[addedFaces][1] = calc3Vectors[vertI].y; + o_vertices[addedFaces][2] = calc3Vectors[vertI].z; o_vertices[addedFaces][3] = 1.0F; - o_normals[addedFaces][0] = frames[CURR_FRAME].normals[frames[CURR_FRAME].materials[t_materialIndex].normalFaces[j]].x; - o_normals[addedFaces][1] = frames[CURR_FRAME].normals[frames[CURR_FRAME].materials[t_materialIndex].normalFaces[j]].y; - o_normals[addedFaces][2] = frames[CURR_FRAME].normals[frames[CURR_FRAME].materials[t_materialIndex].normalFaces[j]].z; + o_normals[addedFaces][0] = CURR_FRAME.normals[MATERIAL.getNormalFace(matI + vertI)].x; + o_normals[addedFaces][1] = CURR_FRAME.normals[MATERIAL.getNormalFace(matI + vertI)].y; + o_normals[addedFaces][2] = CURR_FRAME.normals[MATERIAL.getNormalFace(matI + vertI)].z; o_normals[addedFaces][3] = 1.0F; - o_coordinates[addedFaces][0] = frames[CURR_FRAME].coordinates[frames[CURR_FRAME].materials[t_materialIndex].coordinateFaces[j]].x; - o_coordinates[addedFaces][1] = frames[CURR_FRAME].coordinates[frames[CURR_FRAME].materials[t_materialIndex].coordinateFaces[j]].y; + o_coordinates[addedFaces][0] = CURR_FRAME.coordinates[MATERIAL.getStFace(matI + vertI)].x; + o_coordinates[addedFaces][1] = CURR_FRAME.coordinates[MATERIAL.getStFace(matI + vertI)].y; o_coordinates[addedFaces][2] = 1.0F; o_coordinates[addedFaces][3] = 1.0F; @@ -118,11 +114,6 @@ u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_nor o_colors[addedFaces][2] = 1.0F; o_colors[addedFaces++][3] = 1.0F; } - // fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, t_materialIndex, j, addedFaces++); } return addedFaces; } - -void ObjModel::fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u32 t_materialI, u32 t_getI, u32 t_setI) -{ -} diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index 7d034a3..e70a1f1 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -181,12 +181,15 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) VECTOR *coordinates = new VECTOR[vertCount]; VECTOR *colors = new VECTOR[vertCount]; if (t_mesh->isObjLoaded) + { + t_mesh->obj->animate(); for (u32 i = 0; i < t_mesh->obj->frames[0].materialsCount; i++) { changeTexture(t_mesh, i); vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, colors, *renderData.cameraPosition); vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, colors, t_mesh, t_bulbs, t_bulbsCount); } + } else if (t_mesh->isMd2Loaded) { changeTexture(t_mesh, 0); diff --git a/src/samples/ari/Makefile b/src/samples/ari/Makefile index 403b307..3e5f0a1 100644 --- a/src/samples/ari/Makefile +++ b/src/samples/ari/Makefile @@ -7,6 +7,8 @@ EE_OBJS = \ ../../engine/models/math/vector3.o \ ../../engine/models/dff_model.o \ ../../engine/models/md2_model.o \ + ../../engine/models/mesh_frame.o \ + ../../engine/models/mesh_material.o \ ../../engine/models/mesh.o \ ../../engine/models/mesh_spec.o \ ../../engine/models/obj_model.o \ diff --git a/src/samples/ari/ari.cpp b/src/samples/ari/ari.cpp index 43d623f..73406c3 100644 --- a/src/samples/ari/ari.cpp +++ b/src/samples/ari/ari.cpp @@ -65,6 +65,8 @@ void calcSpiral(int X, int Y) } // TEST END +#include "models/mesh_frame.hpp" + void Ari::onInit() { player = new Player(); @@ -91,6 +93,7 @@ void Ari::onInit() Vector3 testpos = Vector3(0.0F, 10.0F, 0.0F); test->loadObj("objanim/", "untitled", testpos, 10.0F, 2); test->playAnimation(0, 1); + test->shouldBeBackfaceCulled = true; // test->shouldBeFrustumCulled = true; // skybox = new Mesh(); @@ -130,6 +133,7 @@ void Ari::initBulb() void Ari::onUpdate() { + if (engine.pad.isCrossClicked) printf("FPS:%f\n", engine.fps); camera->update(engine.pad, player->mesh);