refactored texturelink, loadFrom(), mesh color
This commit is contained in:
+10
-15
@@ -28,6 +28,7 @@ Mesh::Mesh()
|
||||
shouldBeFrustumCulled = true;
|
||||
shouldBeBackfaceCulled = false;
|
||||
shouldBeLighted = false;
|
||||
_areFramesAllocated = false;
|
||||
_isMother = false;
|
||||
scale = 1.0F;
|
||||
framesCount = 0;
|
||||
@@ -40,13 +41,12 @@ Mesh::Mesh()
|
||||
animState.isStayFrameSet = false;
|
||||
animState.nextFrame = 0;
|
||||
animState.speed = 0.1F;
|
||||
setDefaultColor();
|
||||
setDefaultLODAndClut();
|
||||
}
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
if (_isMother)
|
||||
if (_areFramesAllocated)
|
||||
delete[] frames;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, const float &t_scale, con
|
||||
ObjLoader loader = ObjLoader();
|
||||
framesCount = 1;
|
||||
frames = new MeshFrame[framesCount];
|
||||
_areFramesAllocated = true;
|
||||
char *part1 = String::createConcatenated(t_subfolder, t_objFile); // "folder/object"
|
||||
char *finalPath = String::createConcatenated(part1, ".obj"); // "folder/object.obj"
|
||||
loader.load(&frames[0], finalPath, t_scale, t_invertT);
|
||||
@@ -78,6 +79,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, const float &t_scale, con
|
||||
ObjLoader loader = ObjLoader();
|
||||
framesCount = t_framesCount;
|
||||
frames = new MeshFrame[framesCount];
|
||||
_areFramesAllocated = true;
|
||||
char *part1 = String::createConcatenated(t_subfolder, t_objFile); // "folder/object"
|
||||
char *part2 = String::createConcatenated(part1, "_"); // "folder/object_"
|
||||
for (u32 i = 0; i < framesCount; i++)
|
||||
@@ -105,6 +107,7 @@ void Mesh::loadDff(char *t_subfolder, char *t_dffFile, const float &t_scale, con
|
||||
char *dffPath = String::createConcatenated(part1, ".dff");
|
||||
framesCount = 1;
|
||||
frames = new MeshFrame[1];
|
||||
_areFramesAllocated = true;
|
||||
loader.load(frames, dffPath, t_scale, t_invertT);
|
||||
delete[] part1;
|
||||
delete[] dffPath;
|
||||
@@ -120,8 +123,11 @@ void Mesh::loadMD2(char *t_subfolder, char *t_md2File, const float &t_scale, con
|
||||
|
||||
void Mesh::loadFrom(const Mesh &t_mesh)
|
||||
{
|
||||
frames = t_mesh.frames;
|
||||
framesCount = t_mesh.framesCount;
|
||||
frames = new MeshFrame[framesCount];
|
||||
_areFramesAllocated = true;
|
||||
for (u32 i = 0; i < framesCount; i++)
|
||||
frames[i].copyFrom(&t_mesh.getFrame(i));
|
||||
}
|
||||
|
||||
void Mesh::playAnimation(const u32 &t_startFrame, const u32 &t_endFrame)
|
||||
@@ -254,8 +260,7 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals
|
||||
"r"(nextVerts[vertFaces[faceI]].xyz),
|
||||
"r"(nextVerts[vertFaces[faceI + 1]].xyz),
|
||||
"r"(nextVerts[vertFaces[faceI + 2]].xyz),
|
||||
"f"(animState.interpolation)
|
||||
: "$10");
|
||||
"f"(animState.interpolation));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -375,16 +380,6 @@ u8 Mesh::isInFrustum(Plane *t_frustumPlanes)
|
||||
return boxResult;
|
||||
}
|
||||
|
||||
/** Set's default object color + no transparency */
|
||||
void Mesh::setDefaultColor()
|
||||
{
|
||||
color.r = 0x80;
|
||||
color.g = 0x80;
|
||||
color.b = 0x80;
|
||||
color.a = 0x80;
|
||||
color.q = 1.0F;
|
||||
}
|
||||
|
||||
/** Sets texture level of details settings and CLUT settings */
|
||||
void Mesh::setDefaultLODAndClut()
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include "../include/models/mesh_frame.hpp"
|
||||
#include "../include/utils/debug.hpp"
|
||||
|
||||
@@ -17,6 +18,7 @@
|
||||
|
||||
MeshFrame::MeshFrame()
|
||||
{
|
||||
id = rand() % 1000000;
|
||||
vertexCount = 0;
|
||||
stsCount = 0;
|
||||
normalsCount = 0;
|
||||
@@ -27,19 +29,23 @@ MeshFrame::MeshFrame()
|
||||
_areMaterialsAllocated = false;
|
||||
_areSTsPresent = false;
|
||||
_areNormalsPresent = false;
|
||||
_isMother = true;
|
||||
}
|
||||
|
||||
MeshFrame::~MeshFrame()
|
||||
{
|
||||
if (_areSTsAllocated)
|
||||
delete[] sts;
|
||||
if (_areVerticesAllocated)
|
||||
delete[] vertices;
|
||||
if (_areNormalsAllocated)
|
||||
delete[] normals;
|
||||
if (_isMother)
|
||||
{
|
||||
if (_areSTsAllocated)
|
||||
delete[] sts;
|
||||
if (_areVerticesAllocated)
|
||||
delete[] vertices;
|
||||
if (_areNormalsAllocated)
|
||||
delete[] normals;
|
||||
delete boundingBoxObj;
|
||||
}
|
||||
if (_areMaterialsAllocated)
|
||||
delete[] materials;
|
||||
delete boundingBoxObj;
|
||||
}
|
||||
|
||||
// ----
|
||||
@@ -96,14 +102,12 @@ void MeshFrame::allocateMaterials(const u32 &t_val)
|
||||
|
||||
void MeshFrame::calculateBoundingBoxes()
|
||||
{
|
||||
Vector3 boundingBox[8];
|
||||
if (!_areVerticesAllocated)
|
||||
{
|
||||
PRINT_ERR("Can't calculate bounding box, because vertices were not allocated!");
|
||||
return;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < materialsCount; i++)
|
||||
materials->calculateBoundingBox(vertices, vertexCount);
|
||||
|
||||
float lowX, lowY, lowZ, hiX, hiY, hiZ;
|
||||
lowX = hiX = vertices[0].x;
|
||||
lowY = hiY = vertices[0].y;
|
||||
@@ -126,6 +130,7 @@ void MeshFrame::calculateBoundingBoxes()
|
||||
hiZ = vertices[i].z;
|
||||
}
|
||||
|
||||
Vector3 boundingBox[8];
|
||||
boundingBox[0].set(lowX, lowY, lowZ);
|
||||
boundingBox[1].set(lowX, lowY, hiZ);
|
||||
boundingBox[2].set(lowX, hiY, lowZ);
|
||||
@@ -137,7 +142,32 @@ void MeshFrame::calculateBoundingBoxes()
|
||||
boundingBox[7].set(hiX, hiY, hiZ);
|
||||
_isBoundingBoxCalculated = true;
|
||||
|
||||
//BoundingBox is declared on the heap to prevent any ill-formed default
|
||||
//constructor instantiated BoundingBox objects.
|
||||
// BoundingBox is declared on the heap to prevent any ill-formed default
|
||||
// constructor instantiated BoundingBox objects.
|
||||
boundingBoxObj = new BoundingBox(boundingBox);
|
||||
}
|
||||
|
||||
void MeshFrame::copyFrom(MeshFrame *t_refCopy)
|
||||
{
|
||||
vertexCount = t_refCopy->vertexCount;
|
||||
stsCount = t_refCopy->stsCount;
|
||||
normalsCount = t_refCopy->normalsCount;
|
||||
materialsCount = t_refCopy->materialsCount;
|
||||
materials = new MeshMaterial[materialsCount];
|
||||
for (u32 i = 0; i < materialsCount; i++)
|
||||
materials[i].copyFrom(&t_refCopy->materials[i]);
|
||||
_areSTsAllocated = true;
|
||||
_areVerticesAllocated = true;
|
||||
_areNormalsAllocated = true;
|
||||
_areMaterialsAllocated = true;
|
||||
_areSTsPresent = t_refCopy->_areSTsPresent;
|
||||
_areNormalsPresent = t_refCopy->_areNormalsPresent;
|
||||
vertices = t_refCopy->vertices;
|
||||
sts = t_refCopy->sts;
|
||||
normals = t_refCopy->normals;
|
||||
|
||||
boundingBoxObj = t_refCopy->boundingBoxObj;
|
||||
_isBoundingBoxCalculated = true;
|
||||
|
||||
_isMother = false;
|
||||
}
|
||||
|
||||
@@ -25,18 +25,23 @@ MeshMaterial::MeshMaterial()
|
||||
_isNameSet = false;
|
||||
_areFacesAllocated = false;
|
||||
_isBoundingBoxCalculated = false;
|
||||
_isMother = true;
|
||||
setDefaultColor();
|
||||
}
|
||||
|
||||
MeshMaterial::~MeshMaterial()
|
||||
{
|
||||
if (_areFacesAllocated)
|
||||
if (_isMother)
|
||||
{
|
||||
delete[] vertexFaces;
|
||||
delete[] stFaces;
|
||||
delete[] normalFaces;
|
||||
if (_areFacesAllocated)
|
||||
{
|
||||
delete[] vertexFaces;
|
||||
delete[] stFaces;
|
||||
delete[] normalFaces;
|
||||
}
|
||||
if (_isNameSet)
|
||||
delete[] name;
|
||||
}
|
||||
if (_isNameSet)
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
// ----
|
||||
@@ -102,7 +107,6 @@ u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position)
|
||||
|
||||
void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount)
|
||||
{
|
||||
Vector3 boundingBox[8];
|
||||
float lowX, lowY, lowZ, hiX, hiY, hiZ;
|
||||
lowX = hiX = t_vertices[vertexFaces[0]].x;
|
||||
lowY = hiY = t_vertices[vertexFaces[0]].y;
|
||||
@@ -124,6 +128,8 @@ void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount)
|
||||
if (hiZ < t_vertices[vertexFaces[i]].z)
|
||||
hiZ = t_vertices[vertexFaces[i]].z;
|
||||
}
|
||||
|
||||
Vector3 boundingBox[8];
|
||||
boundingBox[0].set(lowX, lowY, lowZ);
|
||||
boundingBox[1].set(lowX, lowY, hiZ);
|
||||
boundingBox[2].set(lowX, hiY, lowZ);
|
||||
@@ -139,3 +145,30 @@ void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount)
|
||||
//constructor instantiated BoundingBox objects.
|
||||
boundingBoxObj = new BoundingBox(boundingBox);
|
||||
}
|
||||
|
||||
void MeshMaterial::copyFrom(MeshMaterial *t_refCopy)
|
||||
{
|
||||
_isNameSet = true;
|
||||
name = t_refCopy->name;
|
||||
|
||||
_isBoundingBoxCalculated = true;
|
||||
boundingBoxObj = t_refCopy->boundingBoxObj;
|
||||
|
||||
vertexFaces = t_refCopy->vertexFaces;
|
||||
stFaces = t_refCopy->stFaces;
|
||||
normalFaces = t_refCopy->normalFaces;
|
||||
facesCount = t_refCopy->facesCount;
|
||||
_areFacesAllocated = true;
|
||||
|
||||
_isMother = false;
|
||||
}
|
||||
|
||||
/** Set's default object color + no transparency */
|
||||
void MeshMaterial::setDefaultColor()
|
||||
{
|
||||
color.r = 0x80;
|
||||
color.g = 0x80;
|
||||
color.b = 0x80;
|
||||
color.a = 0x80;
|
||||
color.q = 1.0F;
|
||||
}
|
||||
|
||||
@@ -82,18 +82,9 @@ void Texture::setWrapSettings(const WrapSettings t_horizontal, const WrapSetting
|
||||
wrapSettings.vertical = t_vertical;
|
||||
}
|
||||
|
||||
void Texture::addLink(const u32 &t_meshId, const u32 &t_materialId)
|
||||
void Texture::addLink(const u32 &t_id)
|
||||
{
|
||||
TextureLink link;
|
||||
link.materialId = t_materialId;
|
||||
link.meshOrSpriteId = t_meshId;
|
||||
texLinks.push_back(link);
|
||||
}
|
||||
|
||||
void Texture::addLink(const u32 &t_spriteId)
|
||||
{
|
||||
TextureLink link;
|
||||
link.materialId = 0;
|
||||
link.meshOrSpriteId = t_spriteId;
|
||||
link.id = t_id;
|
||||
texLinks.push_back(link);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user