removed dff model
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#ifndef _TYRA_DFF_LOADER_
|
||||
#define _TYRA_DFF_LOADER_
|
||||
|
||||
#include "../models/dff_model.hpp"
|
||||
#include "../models/mesh_frame.hpp"
|
||||
#include "./dff_structure.hpp"
|
||||
|
||||
/** Class responsible for loading&parsing .obj 3D files */
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
DffLoader();
|
||||
~DffLoader();
|
||||
|
||||
void load(RwClump &o_clump, char *t_fileName, float t_scale);
|
||||
void load(MeshFrame *o_result, char *t_fileName, float t_scale, u8 t_invertT);
|
||||
void serialize(RwClump &t_clump, u8 *t_data, float t_scale);
|
||||
|
||||
static u8 readByteFromArrayLE(u8 *t_buffer, u32 &t_ptrPos);
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
void readSectionHeader(RwSectionHeader &t_sh, u8 *t_buffer, u32 &t_ptrPos);
|
||||
|
||||
private:
|
||||
void convert(MeshFrame *frames, RwClump &t_clump, u8 t_invertT);
|
||||
// ---
|
||||
void readFrameListData(RwFrameListData &t_frd, u8 *t_buffer, u32 &t_ptrPos);
|
||||
void readClumpData(RwClumpData &t_cd, u8 *t_buffer, u32 &t_ptrPos);
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
ObjLoader();
|
||||
~ObjLoader();
|
||||
|
||||
void load(MeshFrame *o_result, char *t_fileName, float t_scale, u8 invertT);
|
||||
void load(MeshFrame *o_result, char *t_fileName, float t_scale, u8 t_invertT);
|
||||
|
||||
private:
|
||||
void allocateObjMemory(FILE *t_file, MeshFrame *t_result);
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_DFF_MODEL_
|
||||
#define _TYRA_DFF_MODEL_
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <math3d.h>
|
||||
#include "../loaders/dff_structure.hpp"
|
||||
#include "./math/vector3.hpp"
|
||||
|
||||
/** Class which have common types for all 3D objects */
|
||||
class DffModel
|
||||
{
|
||||
|
||||
public:
|
||||
DffModel();
|
||||
~DffModel();
|
||||
|
||||
u32 getDrawData(u32 splitIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled);
|
||||
RwClump clump;
|
||||
|
||||
private:
|
||||
void fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, u8 geometry, u32 t_getI, u32 t_setI);
|
||||
u8 isMemoryAllocated;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -26,12 +26,12 @@ public:
|
||||
float xy[2] __attribute__((__aligned__(16)));
|
||||
};
|
||||
|
||||
Point(float t_x, float t_y);
|
||||
Point(const float &t_x, const float &t_y);
|
||||
Point(const Point &v);
|
||||
Point();
|
||||
~Point();
|
||||
|
||||
void set(float t_x, float t_y);
|
||||
void set(const float &t_x, const float &t_y);
|
||||
void set(const Point &v);
|
||||
void print();
|
||||
};
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#include "math/vector3.hpp"
|
||||
#include "math/plane.hpp"
|
||||
#include "dff_model.hpp"
|
||||
#include "md2_model.hpp"
|
||||
#include "./mesh_texture.hpp"
|
||||
#include "./mesh_frame.hpp"
|
||||
@@ -31,17 +30,16 @@ public:
|
||||
u8 shouldBeLighted, shouldBeBackfaceCulled, shouldBeFrustumCulled;
|
||||
|
||||
MD2Model *md2;
|
||||
DffModel *dff;
|
||||
float scale;
|
||||
color_t color;
|
||||
|
||||
Mesh();
|
||||
~Mesh();
|
||||
|
||||
void loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float t_scale, u16 t_framesCount);
|
||||
void loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float t_scale, u16 t_framesCount, u8 t_invertT);
|
||||
// void setObj(Vector3 &t_initPos); // TODO
|
||||
void loadDff(char *t_subfolder, char *t_dffFile, Vector3 &t_initPos, float t_scale);
|
||||
void setDff(Vector3 &t_initPos, DffModel *t_dffModel);
|
||||
// void setDff(Vector3 &t_initPos, DffModel *t_dffModel);
|
||||
void loadMD2(char *t_subfolder, char *t_md2File, Vector3 &t_initPos, float t_scale);
|
||||
void getMinMax(Vector3 *t_min, Vector3 *t_max);
|
||||
void playAnimation(u32 t_startFrame, u32 t_endFrame);
|
||||
@@ -50,7 +48,7 @@ public:
|
||||
u32 getDrawData(u32 splitIndex, VECTOR *t_vertices, VECTOR *t_normals, VECTOR *t_coordinates, Vector3 &t_cameraPos);
|
||||
u8 isInFrustum(Plane *t_frustumPlanes);
|
||||
|
||||
u8 isMd2Loaded, isObjLoaded, isDffLoaded, isSpecInitialized;
|
||||
u8 isMd2Loaded, isObjLoaded, isSpecInitialized;
|
||||
clutbuffer_t clut;
|
||||
lod_t lod;
|
||||
u32 id;
|
||||
|
||||
@@ -36,7 +36,6 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
|
||||
char *t_path_part = String::createConcatenated(t_subfolder, t_name);
|
||||
char *t_path = String::createConcatenated(t_path_part, t_extension);
|
||||
delete[] t_path_part;
|
||||
|
||||
FILE *file = fopen(t_path, "rb");
|
||||
|
||||
if (file == NULL)
|
||||
|
||||
@@ -34,7 +34,7 @@ DffLoader::~DffLoader() {}
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
void DffLoader::load(RwClump &o_clump, char *t_filename, float t_scale)
|
||||
void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
|
||||
{
|
||||
PRINT_LOG("Loading dff file");
|
||||
FILE *file = fopen(t_filename, "rb");
|
||||
@@ -46,11 +46,65 @@ void DffLoader::load(RwClump &o_clump, char *t_filename, float t_scale)
|
||||
rewind(file);
|
||||
fread(data, sizeof(u8), fileSize, file);
|
||||
fclose(file);
|
||||
serialize(o_clump, data, t_scale);
|
||||
RwClump *clump = new RwClump();
|
||||
serialize(*clump, data, t_scale);
|
||||
delete[] data;
|
||||
// delete[] clump; // TODO
|
||||
convert(o_result, *clump, t_invertT);
|
||||
PRINT_LOG("Dff file loaded!");
|
||||
}
|
||||
|
||||
void DffLoader::convert(MeshFrame *frames, RwClump &t_clump, u8 t_invertT)
|
||||
{
|
||||
#define GEOMETRY t_clump.geometryList.geometries[0]
|
||||
|
||||
MeshFrame *frame = &frames[0];
|
||||
u32 vertNormalStCount = GEOMETRY.data.dataHeader.vertexCount;
|
||||
frame->allocateVertices(vertNormalStCount);
|
||||
frame->allocateNormals(vertNormalStCount);
|
||||
frame->allocateSTs(vertNormalStCount);
|
||||
|
||||
Vector3 tempVec = Vector3();
|
||||
Point tempPoint = Point();
|
||||
for (u32 i = 0; i < vertNormalStCount; i++)
|
||||
{
|
||||
tempVec.set(
|
||||
GEOMETRY.data.vertexInformation[i].x,
|
||||
GEOMETRY.data.vertexInformation[i].y,
|
||||
GEOMETRY.data.vertexInformation[i].z);
|
||||
frame->setVertex(i, tempVec);
|
||||
tempVec.set(
|
||||
GEOMETRY.data.normalInformation[i].x,
|
||||
GEOMETRY.data.normalInformation[i].y,
|
||||
GEOMETRY.data.normalInformation[i].z);
|
||||
frame->setNormal(i, tempVec);
|
||||
tempPoint.set(
|
||||
GEOMETRY.data.textureMappingInformation[i].u,
|
||||
GEOMETRY.data.textureMappingInformation[i].v);
|
||||
if (t_invertT)
|
||||
tempPoint.y = 1.0F - tempPoint.y;
|
||||
frame->setST(i, tempPoint);
|
||||
}
|
||||
|
||||
#define CURR_SPLIT GEOMETRY.extension.materialSplit.splitInformation[i]
|
||||
u32 materialsCount = GEOMETRY.extension.materialSplit.header.splitCount;
|
||||
frame->allocateMaterials(materialsCount);
|
||||
for (u32 i = 0; i < materialsCount; i++)
|
||||
{
|
||||
u32 facesCount = CURR_SPLIT.faceIndex;
|
||||
u32 materialIndex = CURR_SPLIT.materialIndex;
|
||||
frame->getMaterial(i).allocateFaces(facesCount);
|
||||
char **materialName = &GEOMETRY.materialList.materials[materialIndex].textures[0].textureName.text;
|
||||
frame->getMaterial(i).setName(*materialName);
|
||||
for (u32 j = 0; j < facesCount; j++)
|
||||
{
|
||||
frame->getMaterial(i).setVertexFace(j, CURR_SPLIT.vertexInformation[j].vertex1);
|
||||
frame->getMaterial(i).setNormalFace(j, CURR_SPLIT.vertexInformation[j].vertex1);
|
||||
frame->getMaterial(i).setSTFace(j, CURR_SPLIT.vertexInformation[j].vertex1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DffLoader::serialize(RwClump &t_clump, u8 *t_data, float t_scale)
|
||||
{
|
||||
u32 ptrPos = 0;
|
||||
|
||||
@@ -30,7 +30,7 @@ ObjLoader::~ObjLoader() {}
|
||||
* Notice: At this moment textures names are MATERIAL names from .obj file!
|
||||
* Notice 2: Faces MUST be triangulated (check out blender export settings).
|
||||
*/
|
||||
void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 invertT)
|
||||
void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT)
|
||||
{
|
||||
FILE *file = fopen(t_filename, "rb");
|
||||
if (file == NULL)
|
||||
@@ -55,7 +55,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 in
|
||||
{
|
||||
Point point = Point();
|
||||
fscanf(file, "%f %f\n", &point.x, &point.y);
|
||||
if (invertT)
|
||||
if (t_invertT)
|
||||
point.y = 1.0F - point.y;
|
||||
o_result->setST(cordsI++, point);
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "../include/models/dff_model.hpp"
|
||||
|
||||
#include "../include/utils/debug.hpp"
|
||||
|
||||
// ----
|
||||
// Constructors/Destructors
|
||||
// ----
|
||||
|
||||
DffModel::DffModel() {}
|
||||
|
||||
DffModel::~DffModel() {}
|
||||
|
||||
// ----
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
u32 DffModel::getDrawData(u32 splitIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled)
|
||||
{
|
||||
u32 result = 0;
|
||||
for (u32 i = 0; i < clump.geometryList.geometries[0].extension.materialSplit.splitInformation[splitIndex].faceIndex; i++)
|
||||
fillNextFace(o_vertices, o_normals, o_coordinates, 0,
|
||||
clump.geometryList.geometries[0].extension.materialSplit.splitInformation[splitIndex].vertexInformation[i].vertex1,
|
||||
result++);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DffModel::fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, u8 geometry, u32 t_getI, u32 t_setI)
|
||||
{
|
||||
o_vertices[t_setI][0] = clump.geometryList.geometries[geometry].data.vertexInformation[t_getI].x;
|
||||
o_vertices[t_setI][1] = clump.geometryList.geometries[geometry].data.vertexInformation[t_getI].y;
|
||||
o_vertices[t_setI][2] = clump.geometryList.geometries[geometry].data.vertexInformation[t_getI].z;
|
||||
o_vertices[t_setI][3] = 1.0F;
|
||||
|
||||
o_normals[t_setI][0] = clump.geometryList.geometries[geometry].data.normalInformation[t_getI].x;
|
||||
o_normals[t_setI][1] = clump.geometryList.geometries[geometry].data.normalInformation[t_getI].y;
|
||||
o_normals[t_setI][2] = clump.geometryList.geometries[geometry].data.normalInformation[t_getI].z;
|
||||
o_normals[t_setI][3] = 1.0F;
|
||||
|
||||
o_coordinates[t_setI][0] = clump.geometryList.geometries[geometry].data.textureMappingInformation[t_getI].u;
|
||||
o_coordinates[t_setI][1] = 1.0F - clump.geometryList.geometries[geometry].data.textureMappingInformation[t_getI].v;
|
||||
o_coordinates[t_setI][2] = 1.0F;
|
||||
o_coordinates[t_setI][3] = 1.0F;
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
// ----
|
||||
|
||||
/** Create by specifying values */
|
||||
Point::Point(float t_x, float t_y)
|
||||
Point::Point(const float &t_x, const float &t_y)
|
||||
{
|
||||
x = t_x;
|
||||
y = t_y;
|
||||
@@ -43,10 +43,10 @@ Point::~Point() {}
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
void Point::set(float t_x, float t_y)
|
||||
void Point::set(const float &t_x, const float &t_y)
|
||||
{
|
||||
x = x;
|
||||
y = y;
|
||||
x = t_x;
|
||||
y = t_y;
|
||||
}
|
||||
|
||||
void Point::set(const Point &v)
|
||||
|
||||
+59
-59
@@ -30,7 +30,6 @@ Mesh::Mesh()
|
||||
shouldBeLighted = false;
|
||||
isMd2Loaded = false;
|
||||
isObjLoaded = false;
|
||||
isDffLoaded = false;
|
||||
isSpecInitialized = false;
|
||||
id = rand() % 1000000;
|
||||
scale = 1.0F;
|
||||
@@ -49,8 +48,6 @@ Mesh::~Mesh()
|
||||
// TODO
|
||||
if (isMd2Loaded)
|
||||
delete md2;
|
||||
if (isDffLoaded)
|
||||
delete dff;
|
||||
}
|
||||
|
||||
// ----
|
||||
@@ -89,9 +86,7 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals
|
||||
for (u32 matI = 0; matI < MATERIAL.getFacesCount(); matI += 3)
|
||||
{
|
||||
for (u32 vertI = 0; vertI < 3; vertI++)
|
||||
if (animState.startFrame == animState.endFrame)
|
||||
calc3Vectors[vertI].set(CURR_VERT * t_scale);
|
||||
else
|
||||
if (animState.startFrame != animState.endFrame)
|
||||
calc3Vectors[vertI].setByLerp(CURR_VERT, NEXT_VERT, animState.interpolation, t_scale);
|
||||
|
||||
if (!t_shouldBeBackfaceCulled ||
|
||||
@@ -99,9 +94,19 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals
|
||||
|
||||
for (u32 vertI = 0; vertI < 3; vertI++)
|
||||
{
|
||||
o_vertices[addedFaces][0] = calc3Vectors[vertI].x;
|
||||
o_vertices[addedFaces][1] = calc3Vectors[vertI].y;
|
||||
o_vertices[addedFaces][2] = calc3Vectors[vertI].z;
|
||||
|
||||
if (animState.startFrame == animState.endFrame)
|
||||
{
|
||||
o_vertices[addedFaces][0] = CURR_FRAME.getVertex(MATERIAL.getVertexFace(matI + vertI)).x;
|
||||
o_vertices[addedFaces][1] = CURR_FRAME.getVertex(MATERIAL.getVertexFace(matI + vertI)).y;
|
||||
o_vertices[addedFaces][2] = CURR_FRAME.getVertex(MATERIAL.getVertexFace(matI + vertI)).z;
|
||||
}
|
||||
else
|
||||
{
|
||||
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] = CURR_FRAME.getNormal(MATERIAL.getNormalFace(matI + vertI)).x;
|
||||
@@ -122,58 +127,67 @@ void Mesh::loadDff(char *t_subfolder, char *t_dffFile, Vector3 &t_initPos, float
|
||||
{
|
||||
createSpecIfNotCreated();
|
||||
DffLoader loader = DffLoader();
|
||||
dff = new DffModel();
|
||||
char *dffPath = String::createConcatenated(t_subfolder, t_dffFile);
|
||||
loader.load(dff->clump, dffPath, t_scale);
|
||||
framesCount = 1;
|
||||
frames = new MeshFrame[1];
|
||||
loader.load(frames, dffPath, t_scale, true);
|
||||
delete[] dffPath;
|
||||
position = t_initPos;
|
||||
setVerticesReference(
|
||||
dff->clump.geometryList.geometries[0].data.dataHeader.vertexCount,
|
||||
dff->clump.geometryList.geometries[0].data.vertexInformation);
|
||||
setVerticesReference(getFacesCount(), frames[0].getVertices());
|
||||
setDefaultColor();
|
||||
isDffLoaded = true;
|
||||
loadTextures(t_subfolder, ".bmp");
|
||||
isObjLoaded = true;
|
||||
// position = t_initPos;
|
||||
// setVerticesReference(
|
||||
// dff->clump.geometryList.geometries[0].data.dataHeader.vertexCount,
|
||||
// dff->clump.geometryList.geometries[0].data.vertexInformation);
|
||||
// setDefaultColor();
|
||||
// isDffLoaded = true;
|
||||
// loadTextures(t_subfolder, ".bmp");
|
||||
}
|
||||
|
||||
void Mesh::setDff(Vector3 &t_initPos, DffModel *t_dffModel)
|
||||
{
|
||||
position = t_initPos;
|
||||
isSpecInitialized = 1;
|
||||
dff = t_dffModel;
|
||||
setVerticesReference(
|
||||
dff->clump.geometryList.geometries[0].data.dataHeader.vertexCount,
|
||||
dff->clump.geometryList.geometries[0].data.vertexInformation);
|
||||
setDefaultColor();
|
||||
isDffLoaded = true;
|
||||
}
|
||||
// void Mesh::setDff(Vector3 &t_initPos, DffModel *t_dffModel)
|
||||
// {
|
||||
// position = t_initPos;
|
||||
// isSpecInitialized = 1;
|
||||
// dff = t_dffModel;
|
||||
// setVerticesReference(
|
||||
// dff->clump.geometryList.geometries[0].data.dataHeader.vertexCount,
|
||||
// dff->clump.geometryList.geometries[0].data.vertexInformation);
|
||||
// setDefaultColor();
|
||||
// isDffLoaded = true;
|
||||
// }
|
||||
|
||||
void Mesh::loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float t_scale, u16 t_framesCount)
|
||||
void Mesh::loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float t_scale, u16 t_framesCount, u8 t_invertT)
|
||||
{
|
||||
createSpecIfNotCreated();
|
||||
ObjLoader loader = ObjLoader();
|
||||
|
||||
framesCount = t_framesCount;
|
||||
|
||||
frames = new MeshFrame[framesCount];
|
||||
|
||||
char *part1 = String::createConcatenated(t_subfolder, t_objFile); // "folder/object"
|
||||
char *part2 = String::createConcatenated(part1, "_"); // "folder/object_"
|
||||
delete[] part1;
|
||||
|
||||
for (u16 i = 0; i < framesCount; i++)
|
||||
if (framesCount == 1)
|
||||
{
|
||||
char *part3 = String::createU32ToString(i + 1); // 0 -> "1"
|
||||
char *part4 = String::createWithLeadingZeros(part3); // "000001"
|
||||
char *part5 = String::createConcatenated(part2, part4); // "folder/object_000001"
|
||||
char *finalPath = String::createConcatenated(part5, ".obj"); // "folder/object_000001.obj"
|
||||
loader.load(&frames[i], finalPath, t_scale, false);
|
||||
delete[] part3;
|
||||
delete[] part4;
|
||||
delete[] part5;
|
||||
char *finalPath = String::createConcatenated(part1, ".obj"); // "folder/object.obj"
|
||||
loader.load(&frames[0], finalPath, t_scale, t_invertT);
|
||||
delete[] finalPath;
|
||||
}
|
||||
|
||||
delete[] part2;
|
||||
else
|
||||
{
|
||||
char *part2 = String::createConcatenated(part1, "_"); // "folder/object_"
|
||||
for (u16 i = 0; i < framesCount; i++)
|
||||
{
|
||||
char *part3 = String::createU32ToString(i + 1); // 0 -> "1"
|
||||
char *part4 = String::createWithLeadingZeros(part3); // "000001"
|
||||
char *part5 = String::createConcatenated(part2, part4); // "folder/object_000001"
|
||||
char *finalPath = String::createConcatenated(part5, ".obj"); // "folder/object_000001.obj"
|
||||
loader.load(&frames[i], finalPath, t_scale, t_invertT);
|
||||
delete[] part3;
|
||||
delete[] part4;
|
||||
delete[] part5;
|
||||
delete[] finalPath;
|
||||
}
|
||||
delete[] part2;
|
||||
}
|
||||
delete[] part1;
|
||||
|
||||
position = t_initPos;
|
||||
setVerticesReference(getFacesCount(), frames[0].getVertices());
|
||||
@@ -215,8 +229,6 @@ u32 Mesh::getVertexCount()
|
||||
return md2->trianglesCount * 3;
|
||||
else if (isObjLoaded)
|
||||
return getFacesCount();
|
||||
else if (isDffLoaded)
|
||||
return dff->clump.geometryList.geometries[0].data.dataHeader.triangleCount * 3;
|
||||
else
|
||||
{
|
||||
PRINT_ERR("Can't get vertex count, because no 3D model was loaded!");
|
||||
@@ -246,16 +258,6 @@ void Mesh::loadTextures(char *t_subfolder, char *t_extension)
|
||||
bmpLoader.load(textures[0], t_subfolder, md2->filename, t_extension);
|
||||
// setDefaultWrapSettings(spec->textures[0].wrapSettings);
|
||||
}
|
||||
else if (isDffLoaded)
|
||||
{
|
||||
textures = new MeshTexture[dff->clump.geometryList.geometries[0].materialList.data.materialCount];
|
||||
for (u8 i = 0; i < dff->clump.geometryList.geometries[0].materialList.data.materialCount; i++)
|
||||
for (u8 j = 0; j < dff->clump.geometryList.geometries[0].materialList.materials[i].data.textureCount; j++)
|
||||
{
|
||||
bmpLoader.load(textures[i], t_subfolder, dff->clump.geometryList.geometries[0].materialList.materials[i].textures[j].textureName.text, t_extension);
|
||||
// setDefaultWrapSettings(spec->textures[i].wrapSettings);
|
||||
}
|
||||
}
|
||||
else
|
||||
PRINT_ERR("Can't load textures, because no 3D model was loaded!");
|
||||
}
|
||||
@@ -267,8 +269,6 @@ u32 Mesh::getDrawData(u32 splitIndex, VECTOR *t_vertices, VECTOR *t_normals, VEC
|
||||
return md2->getCurrentFrameData(t_vertices, t_normals, t_coordinates, t_cameraPos, scale, shouldBeBackfaceCulled);
|
||||
else if (isObjLoaded)
|
||||
return getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_cameraPos, scale, shouldBeBackfaceCulled);
|
||||
else if (isDffLoaded)
|
||||
return dff->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_cameraPos, scale, shouldBeBackfaceCulled);
|
||||
PRINT_ERR("Can't get draw data, because no 3D model was loaded!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -201,12 +201,14 @@ void Renderer::draw(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bul
|
||||
draw(t_meshes[i], t_bulbs, t_bulbsCount);
|
||||
}
|
||||
|
||||
u8 once = true;
|
||||
|
||||
/** PATH1 Single + lighting */
|
||||
void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
{
|
||||
beginFrameIfNeeded();
|
||||
// TODO VU1 send single list here
|
||||
if (!t_mesh->isObjLoaded && !t_mesh->isDffLoaded && !t_mesh->isMd2Loaded)
|
||||
if (!t_mesh->isObjLoaded && !t_mesh->isMd2Loaded)
|
||||
return;
|
||||
u32 vertCount = t_mesh->getVertexCount();
|
||||
VECTOR *vertices = new VECTOR[vertCount];
|
||||
@@ -214,13 +216,17 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
VECTOR *coordinates = new VECTOR[vertCount];
|
||||
if (t_mesh->isObjLoaded)
|
||||
{
|
||||
t_mesh->animate();
|
||||
if (t_mesh->animState.startFrame != t_mesh->animState.endFrame)
|
||||
t_mesh->animate();
|
||||
for (u32 i = 0; i < t_mesh->getMaterialsCount(); i++)
|
||||
{
|
||||
changeTexture(t_mesh, t_mesh->getMaterial(i).getId());
|
||||
if (once)
|
||||
printf("Changing material to:%d\n", t_mesh->getMaterial(i).getId());
|
||||
vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition);
|
||||
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
|
||||
}
|
||||
once = false;
|
||||
}
|
||||
else if (t_mesh->isMd2Loaded)
|
||||
{
|
||||
@@ -228,14 +234,6 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
vertCount = t_mesh->getDrawData(0, vertices, normals, coordinates, *renderData.cameraPosition);
|
||||
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
|
||||
}
|
||||
else if (t_mesh->isDffLoaded)
|
||||
for (u32 i = 0; i < t_mesh->dff->clump.geometryList.geometries[0].extension.materialSplit.header.splitCount; i++)
|
||||
{
|
||||
const u32 currentTexI = t_mesh->dff->clump.geometryList.geometries[0].extension.materialSplit.splitInformation[i].materialIndex;
|
||||
changeTexture(t_mesh, currentTexI);
|
||||
vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition);
|
||||
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
|
||||
}
|
||||
delete[] vertices;
|
||||
delete[] normals;
|
||||
delete[] coordinates;
|
||||
|
||||
@@ -5,7 +5,6 @@ EE_OBJS = \
|
||||
../../engine/models/math/plane.o \
|
||||
../../engine/models/math/point.o \
|
||||
../../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 \
|
||||
|
||||
+25
-23
@@ -79,11 +79,12 @@ void Ari::onInit()
|
||||
texRepo = engine.renderer->getTextureRepository();
|
||||
// engine.audio.play();
|
||||
|
||||
// Vector3 islandPos = Vector3(0.0F, 10.0F, 0.0F);
|
||||
// island = new Mesh();
|
||||
// island->rotation.x = -1.6F;
|
||||
// island->loadDff("sunnyisl/", "sunnyisl.dff", islandPos, 0.1F);
|
||||
// island->shouldBeFrustumCulled = false;
|
||||
Vector3 islandPos = Vector3(0.0F, 10.0F, 0.0F);
|
||||
island = new Mesh();
|
||||
island->rotation.x = -1.6F;
|
||||
island->loadDff("sunnyisl/", "sunnyisl.dff", islandPos, 0.1F);
|
||||
texRepo->addByMesh("sunnyisl/", *island);
|
||||
island->shouldBeFrustumCulled = false;
|
||||
// island->shouldBeBackfaceCulled = true;
|
||||
|
||||
// islandAddons = new Mesh();
|
||||
@@ -91,17 +92,17 @@ void Ari::onInit()
|
||||
// islandAddons->loadDff("sunnyisl/", "sunnyisl3.dff", islandPos, 0.1F);
|
||||
// islandAddons->shouldBeFrustumCulled = false;
|
||||
|
||||
test = new Mesh();
|
||||
Vector3 testpos = Vector3(0.0F, 10.0F, 0.0F);
|
||||
test->loadObj("objanim/", "untitled", testpos, 10.0F, 2);
|
||||
texRepo->addByMesh("objanim/", *test);
|
||||
std::vector<MeshTexture *> *textures = texRepo->getAll();
|
||||
textures->at(0)->removeLink(test->id, test->getMaterial(0).getId());
|
||||
MeshTexture *tex = texRepo->add("objanim/", "water");
|
||||
tex->addLink(test->id, test->getMaterial(0).getId());
|
||||
texRepo->removeById(textures->at(0)->getId());
|
||||
test->playAnimation(0, 1);
|
||||
test->shouldBeBackfaceCulled = true;
|
||||
// test = new Mesh();
|
||||
// Vector3 testpos = Vector3(0.0F, 00.0F, 0.0F);
|
||||
// test->loadObj("pillar/", "pillar", testpos, .1F, 1);
|
||||
// texRepo->addByMesh("pillar/", *test);
|
||||
// std::vector<MeshTexture *> *textures = texRepo->getAll();
|
||||
// textures->at(0)->removeLink(test->id, test->getMaterial(0).getId());
|
||||
// MeshTexture *tex = texRepo->add("objanim/", "water");
|
||||
// tex->addLink(test->id, test->getMaterial(0).getId());
|
||||
// texRepo->removeById(textures->at(0)->getId());
|
||||
// test->playAnimation(0, 0);
|
||||
// test->shouldBeBackfaceCulled = true;
|
||||
|
||||
// TODO 1 - Merge dff/md2
|
||||
// TODO 2 - Refactor
|
||||
@@ -110,10 +111,11 @@ void Ari::onInit()
|
||||
|
||||
// test->shouldBeFrustumCulled = true;
|
||||
|
||||
// skybox = new Mesh();
|
||||
// Vector3 skyboxPos = Vector3(0.0F, 10.0F, 0.0F);
|
||||
// skybox->loadObj("skybox/", "skybox.obj", skyboxPos, 80.0F);
|
||||
// skybox->shouldBeFrustumCulled = true;
|
||||
skybox = new Mesh();
|
||||
Vector3 skyboxPos = Vector3(0.0F, 10.0F, 0.0F);
|
||||
skybox->loadObj("skybox/", "skybox", skyboxPos, 80.0F, 1, false);
|
||||
skybox->shouldBeFrustumCulled = true;
|
||||
texRepo->addByMesh("skybox/", *skybox);
|
||||
|
||||
// waterFloors = new Mesh *[WATER_TILES_COUNT];
|
||||
// spirals = new Point[WATER_TILES_COUNT];
|
||||
@@ -151,9 +153,9 @@ void Ari::onUpdate()
|
||||
if (engine.pad.isCrossClicked)
|
||||
printf("FPS:%f\n", engine.fps);
|
||||
camera->update(engine.pad, player->mesh);
|
||||
engine.renderer->draw(test);
|
||||
// engine.renderer->draw(skybox);
|
||||
// engine.renderer->draw(island);
|
||||
// engine.renderer->draw(test);
|
||||
engine.renderer->draw(skybox);
|
||||
engine.renderer->draw(island);
|
||||
// engine.renderer->draw(islandAddons);
|
||||
// // engine.renderer->draw(&player->mesh);
|
||||
// for (u8 i = 0; i < WATER_TILES_COUNT; i++)
|
||||
|
||||
Reference in New Issue
Block a user