added skybox and multitexture feature in .obj
This commit is contained in:
@@ -25,7 +25,7 @@ public:
|
|||||||
void load(ObjModel *o_result, char *t_fileName, float t_scale);
|
void load(ObjModel *o_result, char *t_fileName, float t_scale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setObjDataQuantities(FILE *t_file, ObjModel *t_result);
|
void allocateObjMemory(FILE *t_file, ObjModel *t_result);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,28 +15,35 @@
|
|||||||
#include <math3d.h>
|
#include <math3d.h>
|
||||||
#include "math/vector3.hpp"
|
#include "math/vector3.hpp"
|
||||||
|
|
||||||
|
struct ObjMaterial
|
||||||
|
{
|
||||||
|
char *materialName;
|
||||||
|
u32 facesCount;
|
||||||
|
u32 *verticeFaces, *coordinateFaces, *normalFaces;
|
||||||
|
};
|
||||||
|
|
||||||
/** Class which have common types for all 3D objects */
|
/** Class which have common types for all 3D objects */
|
||||||
class ObjModel
|
class ObjModel
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
u32 verticesCount, coordinatesCount, normalsCount, facesCount;
|
u32 verticesCount, coordinatesCount, normalsCount, materialsCount;
|
||||||
Vector3 *vertices __attribute__((aligned(16))),
|
Vector3 *vertices __attribute__((aligned(16))),
|
||||||
*coordinates __attribute__((aligned(16))),
|
*coordinates __attribute__((aligned(16))),
|
||||||
*normals __attribute__((aligned(16)));
|
*normals __attribute__((aligned(16)));
|
||||||
u32 *verticeFaces, *coordinateFaces, *normalFaces;
|
|
||||||
|
|
||||||
/** File name without extension */
|
/** File name without extension */
|
||||||
char *filename;
|
char *filename;
|
||||||
|
ObjMaterial *materials;
|
||||||
|
|
||||||
ObjModel(char *t_objFile);
|
ObjModel(char *t_objFile);
|
||||||
~ObjModel();
|
~ObjModel();
|
||||||
u32 getDrawData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled);
|
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);
|
||||||
void allocateMemory();
|
u32 getFacesCount();
|
||||||
|
u8 isMemoryAllocated;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u32 t_getI, u32 t_setI);
|
void fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u32 t_materialI, u32 t_getI, u32 t_setI);
|
||||||
u8 isMemoryAllocated;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ void BmpLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char *
|
|||||||
o_texture.height = height;
|
o_texture.height = height;
|
||||||
o_texture.data = new unsigned char[width * height * 3];
|
o_texture.data = new unsigned char[width * height * 3];
|
||||||
printf("BMPLoader - width: %d | height: %d\n", width, height);
|
printf("BMPLoader - width: %d | height: %d\n", width, height);
|
||||||
|
if (width > 128 || height > 128)
|
||||||
|
PRINT_ERR("Given texture is big for PS2. Please strict to 128x128 max");
|
||||||
|
|
||||||
u64 rowPadded = (width * 3 + 3) & (~3);
|
u64 rowPadded = (width * 3 + 3) & (~3);
|
||||||
|
|
||||||
@@ -76,4 +78,5 @@ void BmpLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char *
|
|||||||
}
|
}
|
||||||
delete[] t_path;
|
delete[] t_path;
|
||||||
delete[] data;
|
delete[] data;
|
||||||
|
// fclose(file); // wtf?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "../include/loaders/obj_loader.hpp"
|
#include "../include/loaders/obj_loader.hpp"
|
||||||
|
|
||||||
#include "../include/utils/debug.hpp"
|
#include "../include/utils/debug.hpp"
|
||||||
|
#include "../include/utils/string.hpp"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
@@ -25,15 +26,18 @@ ObjLoader::~ObjLoader() {}
|
|||||||
// Methods
|
// Methods
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
/** Load, parse .obj file and load data into given MeshSpec */
|
/** Parse .obj file, allocate output data and store it. Multitexture support
|
||||||
|
* Notice: At this moment textures names are MATERIAL names from .obj file!
|
||||||
|
*/
|
||||||
void ObjLoader::load(ObjModel *o_result, char *t_filename, float t_scale)
|
void ObjLoader::load(ObjModel *o_result, char *t_filename, float t_scale)
|
||||||
{
|
{
|
||||||
FILE *file = fopen(t_filename, "rb");
|
FILE *file = fopen(t_filename, "rb");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
PRINT_ERR("Failed to load .obj file!");
|
PRINT_ERR("Failed to load .obj file!");
|
||||||
setObjDataQuantities(file, o_result);
|
allocateObjMemory(file, o_result);
|
||||||
o_result->allocateMemory();
|
fseek(file, 0, SEEK_SET);
|
||||||
u32 verticesI = 0, cordsI = 0, normalsI = 0, i = 0, vertexIndex[3], coordIndex[3], normalIndex[3];
|
u32 verticesI = 0, cordsI = 0, normalsI = 0, faceI = 0, vertexIndex[3], coordIndex[3], normalIndex[3];
|
||||||
|
s16 materialsI = -1;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
char lineHeader[128]; // read the first word of the line
|
char lineHeader[128]; // read the first word of the line
|
||||||
@@ -58,6 +62,13 @@ void ObjLoader::load(ObjModel *o_result, char *t_filename, float t_scale)
|
|||||||
fscanf(file, "%f %f %f\n", &vector.x, &vector.y, &vector.z);
|
fscanf(file, "%f %f %f\n", &vector.x, &vector.y, &vector.z);
|
||||||
o_result->normals[normalsI++] = vector;
|
o_result->normals[normalsI++] = vector;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(lineHeader, "usemtl") == 0)
|
||||||
|
{
|
||||||
|
char temp[30];
|
||||||
|
fscanf(file, "%s\n", temp);
|
||||||
|
o_result->materials[++materialsI].materialName = String::createCopy(temp);
|
||||||
|
faceI = 0;
|
||||||
|
}
|
||||||
else if (strcmp(lineHeader, "f") == 0)
|
else if (strcmp(lineHeader, "f") == 0)
|
||||||
{
|
{
|
||||||
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",
|
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",
|
||||||
@@ -68,18 +79,18 @@ void ObjLoader::load(ObjModel *o_result, char *t_filename, float t_scale)
|
|||||||
PRINT_ERR(".obj can't be read by this simple parser. Try exporting with other options");
|
PRINT_ERR(".obj can't be read by this simple parser. Try exporting with other options");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
o_result->verticeFaces[i] = vertexIndex[0] - 1;
|
o_result->materials[materialsI].verticeFaces[faceI] = vertexIndex[0] - 1;
|
||||||
o_result->verticeFaces[i + 1] = vertexIndex[1] - 1;
|
o_result->materials[materialsI].verticeFaces[faceI + 1] = vertexIndex[1] - 1;
|
||||||
o_result->verticeFaces[i + 2] = vertexIndex[2] - 1;
|
o_result->materials[materialsI].verticeFaces[faceI + 2] = vertexIndex[2] - 1;
|
||||||
|
|
||||||
o_result->coordinateFaces[i] = coordIndex[0] - 1;
|
o_result->materials[materialsI].coordinateFaces[faceI] = coordIndex[0] - 1;
|
||||||
o_result->coordinateFaces[i + 1] = coordIndex[1] - 1;
|
o_result->materials[materialsI].coordinateFaces[faceI + 1] = coordIndex[1] - 1;
|
||||||
o_result->coordinateFaces[i + 2] = coordIndex[2] - 1;
|
o_result->materials[materialsI].coordinateFaces[faceI + 2] = coordIndex[2] - 1;
|
||||||
|
|
||||||
o_result->normalFaces[i] = normalIndex[0] - 1;
|
o_result->materials[materialsI].normalFaces[faceI] = normalIndex[0] - 1;
|
||||||
o_result->normalFaces[i + 1] = normalIndex[1] - 1;
|
o_result->materials[materialsI].normalFaces[faceI + 1] = normalIndex[1] - 1;
|
||||||
o_result->normalFaces[i + 2] = normalIndex[2] - 1;
|
o_result->materials[materialsI].normalFaces[faceI + 2] = normalIndex[2] - 1;
|
||||||
i += 3;
|
faceI += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,15 +100,14 @@ void ObjLoader::load(ObjModel *o_result, char *t_filename, float t_scale)
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calculate how many vertices(v), coordinates(vt), normals(vn) and faces(f) have .obj file
|
/** Calculate how many vertices(v), coordinates(vt), normals(vn) and faces(f) have .obj file */
|
||||||
* When done, file read offset is resetted to the begginning of file
|
void ObjLoader::allocateObjMemory(FILE *t_file, ObjModel *o_result)
|
||||||
*/
|
|
||||||
void ObjLoader::setObjDataQuantities(FILE *t_file, ObjModel *o_result)
|
|
||||||
{
|
{
|
||||||
o_result->verticesCount = 0;
|
o_result->verticesCount = 0;
|
||||||
o_result->coordinatesCount = 0;
|
o_result->coordinatesCount = 0;
|
||||||
o_result->normalsCount = 0;
|
o_result->normalsCount = 0;
|
||||||
o_result->facesCount = 0;
|
o_result->materialsCount = 0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
char lineHeader[128];
|
char lineHeader[128];
|
||||||
@@ -110,11 +120,41 @@ void ObjLoader::setObjDataQuantities(FILE *t_file, ObjModel *o_result)
|
|||||||
o_result->coordinatesCount += 1;
|
o_result->coordinatesCount += 1;
|
||||||
else if (strcmp(lineHeader, "vn") == 0)
|
else if (strcmp(lineHeader, "vn") == 0)
|
||||||
o_result->normalsCount += 1;
|
o_result->normalsCount += 1;
|
||||||
else if (strcmp(lineHeader, "f") == 0)
|
else if (strcmp(lineHeader, "usemtl") == 0)
|
||||||
o_result->facesCount += 3;
|
o_result->materialsCount += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
o_result->materials = new ObjMaterial[o_result->materialsCount];
|
||||||
|
s16 currentMatI = -1;
|
||||||
|
|
||||||
fseek(t_file, 0, SEEK_SET);
|
fseek(t_file, 0, SEEK_SET);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
char lineHeader[128];
|
||||||
|
int res = fscanf(t_file, "%s", lineHeader);
|
||||||
|
if (res != EOF)
|
||||||
|
{
|
||||||
|
if (strcmp(lineHeader, "usemtl") == 0)
|
||||||
|
o_result->materials[++currentMatI].facesCount = 0;
|
||||||
|
else if (strcmp(lineHeader, "f") == 0)
|
||||||
|
o_result->materials[currentMatI].facesCount += 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->vertices = new Vector3[o_result->verticesCount];
|
||||||
|
o_result->coordinates = new Vector3[o_result->coordinatesCount];
|
||||||
|
o_result->normals = new Vector3[o_result->normalsCount];
|
||||||
|
o_result->isMemoryAllocated = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, Vector3 &t_initPos, float
|
|||||||
loader.load(obj, objPath, t_scale);
|
loader.load(obj, objPath, t_scale);
|
||||||
delete[] objPath;
|
delete[] objPath;
|
||||||
position = t_initPos;
|
position = t_initPos;
|
||||||
setVerticesReference(obj->facesCount, obj->vertices);
|
setVerticesReference(obj->getFacesCount(), obj->vertices);
|
||||||
setDefaultColor();
|
setDefaultColor();
|
||||||
isObjLoaded = true;
|
isObjLoaded = true;
|
||||||
loadTextures(t_subfolder, ".bmp");
|
loadTextures(t_subfolder, ".bmp");
|
||||||
@@ -100,7 +100,7 @@ void Mesh::setObj(Vector3 &t_initPos, ObjModel *t_objModel, MeshSpec *t_spec)
|
|||||||
spec = t_spec;
|
spec = t_spec;
|
||||||
isSpecInitialized = true;
|
isSpecInitialized = true;
|
||||||
obj = t_objModel;
|
obj = t_objModel;
|
||||||
setVerticesReference(obj->facesCount, obj->vertices);
|
setVerticesReference(obj->getFacesCount(), obj->vertices);
|
||||||
setDefaultColor();
|
setDefaultColor();
|
||||||
isObjLoaded = true;
|
isObjLoaded = true;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ u32 Mesh::getVertexCount()
|
|||||||
if (isMd2Loaded)
|
if (isMd2Loaded)
|
||||||
return md2->trianglesCount * 3;
|
return md2->trianglesCount * 3;
|
||||||
else if (isObjLoaded)
|
else if (isObjLoaded)
|
||||||
return obj->facesCount;
|
return obj->getFacesCount();
|
||||||
else if (isDffLoaded)
|
else if (isDffLoaded)
|
||||||
return dff->clump.geometryList.geometries[0].data.dataHeader.triangleCount * 3;
|
return dff->clump.geometryList.geometries[0].data.dataHeader.triangleCount * 3;
|
||||||
else
|
else
|
||||||
@@ -157,13 +157,19 @@ void Mesh::setDefaultWrapSettings(texwrap_t &t_wrapSettings)
|
|||||||
void Mesh::loadTextures(char *t_subfolder, char *t_extension)
|
void Mesh::loadTextures(char *t_subfolder, char *t_extension)
|
||||||
{
|
{
|
||||||
BmpLoader bmpLoader = BmpLoader();
|
BmpLoader bmpLoader = BmpLoader();
|
||||||
if (isMd2Loaded || isObjLoaded)
|
if (isObjLoaded)
|
||||||
|
{
|
||||||
|
spec->textures = new Texture[obj->materialsCount];
|
||||||
|
for (u8 i = 0; i < obj->materialsCount; i++)
|
||||||
|
{
|
||||||
|
bmpLoader.load(spec->textures[i], t_subfolder, obj->materials[i].materialName, t_extension);
|
||||||
|
setDefaultWrapSettings(spec->textures[i].wrapSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isMd2Loaded)
|
||||||
{
|
{
|
||||||
spec->textures = new Texture[1];
|
spec->textures = new Texture[1];
|
||||||
if (isMd2Loaded)
|
|
||||||
bmpLoader.load(spec->textures[0], t_subfolder, md2->filename, t_extension);
|
bmpLoader.load(spec->textures[0], t_subfolder, md2->filename, t_extension);
|
||||||
if (isObjLoaded)
|
|
||||||
bmpLoader.load(spec->textures[0], t_subfolder, obj->filename, t_extension);
|
|
||||||
setDefaultWrapSettings(spec->textures[0].wrapSettings);
|
setDefaultWrapSettings(spec->textures[0].wrapSettings);
|
||||||
}
|
}
|
||||||
else if (isDffLoaded)
|
else if (isDffLoaded)
|
||||||
@@ -186,7 +192,7 @@ u32 Mesh::getDrawData(u32 splitIndex, VECTOR *t_vertices, VECTOR *t_normals, VEC
|
|||||||
if (isMd2Loaded)
|
if (isMd2Loaded)
|
||||||
return md2->getCurrentFrameData(t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled);
|
return md2->getCurrentFrameData(t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled);
|
||||||
else if (isObjLoaded)
|
else if (isObjLoaded)
|
||||||
return obj->getDrawData(t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled);
|
return obj->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled);
|
||||||
else if (isDffLoaded)
|
else if (isDffLoaded)
|
||||||
return dff->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled);
|
return dff->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled);
|
||||||
PRINT_ERR("Can't get draw data, because no 3D model was loaded!");
|
PRINT_ERR("Can't get draw data, because no 3D model was loaded!");
|
||||||
|
|||||||
@@ -29,10 +29,14 @@ ObjModel::~ObjModel()
|
|||||||
delete[] vertices;
|
delete[] vertices;
|
||||||
delete[] coordinates;
|
delete[] coordinates;
|
||||||
delete[] normals;
|
delete[] normals;
|
||||||
|
for (u16 i = 0; i < materialsCount; i++)
|
||||||
delete[] verticeFaces;
|
{
|
||||||
delete[] coordinateFaces;
|
delete[] materials[i].verticeFaces;
|
||||||
delete[] normalFaces;
|
delete[] materials[i].coordinateFaces;
|
||||||
|
delete[] materials[i].normalFaces;
|
||||||
|
delete[] materials[i].materialName;
|
||||||
|
}
|
||||||
|
delete[] materials;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,55 +44,45 @@ ObjModel::~ObjModel()
|
|||||||
// Methods
|
// Methods
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
u32 ObjModel::getDrawData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled)
|
u32 ObjModel::getFacesCount()
|
||||||
{
|
{
|
||||||
u32 addedFaces = 0;
|
u32 result = 0;
|
||||||
for (u32 i = 0; i < facesCount; i += 3)
|
for (u16 i = 0; i < materialsCount; i++)
|
||||||
if (!t_shouldBeBackfaceCulled || Vector3::shouldBeBackfaceCulled(
|
result += materials[i].facesCount;
|
||||||
&t_cameraPos,
|
return result;
|
||||||
&vertices[verticeFaces[i]],
|
|
||||||
&vertices[verticeFaces[i + 1]],
|
|
||||||
&vertices[verticeFaces[i + 2]]) == 0)
|
|
||||||
{
|
|
||||||
fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, i, addedFaces++);
|
|
||||||
fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, i + 1, addedFaces++);
|
|
||||||
fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, i + 2, addedFaces++);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
u32 addedFaces = 0;
|
||||||
|
for (u32 j = 0; j < materials[t_materialIndex].facesCount; j += 3)
|
||||||
|
if (!t_shouldBeBackfaceCulled || Vector3::shouldBeBackfaceCulled(
|
||||||
|
&t_cameraPos,
|
||||||
|
&vertices[materials[t_materialIndex].verticeFaces[j]],
|
||||||
|
&vertices[materials[t_materialIndex].verticeFaces[j + 1]],
|
||||||
|
&vertices[materials[t_materialIndex].verticeFaces[j + 2]]) == 0)
|
||||||
|
{
|
||||||
|
fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, t_materialIndex, j, addedFaces++);
|
||||||
|
fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, t_materialIndex, j + 1, addedFaces++);
|
||||||
|
fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, t_materialIndex, j + 2, addedFaces++);
|
||||||
|
}
|
||||||
return addedFaces;
|
return addedFaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Allocate memory for vertices,coords etc.
|
void ObjModel::fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u32 t_materialI, u32 t_getI, u32 t_setI)
|
||||||
* Called by ObjLoader
|
|
||||||
*/
|
|
||||||
void ObjModel::allocateMemory()
|
|
||||||
{
|
{
|
||||||
PRINT_LOG("Allocating 3D object specification memory");
|
o_vertices[t_setI][0] = vertices[materials[t_materialI].verticeFaces[t_getI]].x;
|
||||||
vertices = new Vector3[verticesCount];
|
o_vertices[t_setI][1] = vertices[materials[t_materialI].verticeFaces[t_getI]].y;
|
||||||
coordinates = new Vector3[coordinatesCount];
|
o_vertices[t_setI][2] = vertices[materials[t_materialI].verticeFaces[t_getI]].z;
|
||||||
normals = new Vector3[normalsCount];
|
|
||||||
|
|
||||||
verticeFaces = new u32[facesCount];
|
|
||||||
coordinateFaces = new u32[facesCount];
|
|
||||||
normalFaces = new u32[facesCount];
|
|
||||||
isMemoryAllocated = true;
|
|
||||||
PRINT_LOG("3D object specification memory allocated!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjModel::fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u32 t_getI, u32 t_setI)
|
|
||||||
{
|
|
||||||
o_vertices[t_setI][0] = vertices[verticeFaces[t_getI]].x;
|
|
||||||
o_vertices[t_setI][1] = vertices[verticeFaces[t_getI]].y;
|
|
||||||
o_vertices[t_setI][2] = vertices[verticeFaces[t_getI]].z;
|
|
||||||
o_vertices[t_setI][3] = 1.0F;
|
o_vertices[t_setI][3] = 1.0F;
|
||||||
|
|
||||||
o_normals[t_setI][0] = normals[normalFaces[t_getI]].x;
|
o_normals[t_setI][0] = normals[materials[t_materialI].normalFaces[t_getI]].x;
|
||||||
o_normals[t_setI][1] = normals[normalFaces[t_getI]].y;
|
o_normals[t_setI][1] = normals[materials[t_materialI].normalFaces[t_getI]].y;
|
||||||
o_normals[t_setI][2] = normals[normalFaces[t_getI]].z;
|
o_normals[t_setI][2] = normals[materials[t_materialI].normalFaces[t_getI]].z;
|
||||||
o_normals[t_setI][3] = 1.0F;
|
o_normals[t_setI][3] = 1.0F;
|
||||||
|
|
||||||
o_coordinates[t_setI][0] = coordinates[coordinateFaces[t_getI]].x;
|
o_coordinates[t_setI][0] = coordinates[materials[t_materialI].coordinateFaces[t_getI]].x;
|
||||||
o_coordinates[t_setI][1] = coordinates[coordinateFaces[t_getI]].y;
|
o_coordinates[t_setI][1] = coordinates[materials[t_materialI].coordinateFaces[t_getI]].y;
|
||||||
o_coordinates[t_setI][2] = 1.0F;
|
o_coordinates[t_setI][2] = 1.0F;
|
||||||
o_coordinates[t_setI][3] = 1.0F;
|
o_coordinates[t_setI][3] = 1.0F;
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,14 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
|||||||
VECTOR *normals = new VECTOR[vertCount];
|
VECTOR *normals = new VECTOR[vertCount];
|
||||||
VECTOR *coordinates = new VECTOR[vertCount];
|
VECTOR *coordinates = new VECTOR[vertCount];
|
||||||
VECTOR *colors = new VECTOR[vertCount];
|
VECTOR *colors = new VECTOR[vertCount];
|
||||||
if (t_mesh->isObjLoaded || t_mesh->isMd2Loaded)
|
if (t_mesh->isObjLoaded)
|
||||||
|
for (u32 i = 0; i < t_mesh->obj->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);
|
changeTexture(t_mesh, 0);
|
||||||
vertCount = t_mesh->getDrawData(0, vertices, normals, coordinates, colors, *renderData.cameraPosition);
|
vertCount = t_mesh->getDrawData(0, vertices, normals, coordinates, colors, *renderData.cameraPosition);
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ void Ari::onInit()
|
|||||||
islandAddons->shouldBeFrustumCulled = false;
|
islandAddons->shouldBeFrustumCulled = false;
|
||||||
|
|
||||||
skybox = new Mesh();
|
skybox = new Mesh();
|
||||||
Vector3 skyboxPos = Vector3(0.0F, 0.0F, 0.0F);
|
Vector3 skyboxPos = Vector3(0.0F, 10.0F, 0.0F);
|
||||||
skybox->loadObj("skybox/", "skybox.obj", skyboxPos, 100.0F);
|
skybox->loadObj("skybox/", "skybox.obj", skyboxPos, 80.0F);
|
||||||
skybox->shouldBeFrustumCulled = true;
|
skybox->shouldBeFrustumCulled = true;
|
||||||
|
|
||||||
waterFloors = new Mesh *[WATER_TILES_COUNT];
|
waterFloors = new Mesh *[WATER_TILES_COUNT];
|
||||||
@@ -114,8 +114,6 @@ void Ari::onInit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 currentTexI = 0;
|
|
||||||
|
|
||||||
void Ari::initBulb()
|
void Ari::initBulb()
|
||||||
{
|
{
|
||||||
bulb.intensity = 15;
|
bulb.intensity = 15;
|
||||||
@@ -130,7 +128,7 @@ void Ari::onUpdate()
|
|||||||
engine.renderer->draw(skybox);
|
engine.renderer->draw(skybox);
|
||||||
engine.renderer->draw(island);
|
engine.renderer->draw(island);
|
||||||
engine.renderer->draw(islandAddons);
|
engine.renderer->draw(islandAddons);
|
||||||
engine.renderer->draw(&player->mesh);
|
// engine.renderer->draw(&player->mesh);
|
||||||
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
|
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
|
||||||
engine.renderer->draw(waterFloors[i]); // TODO
|
engine.renderer->draw(waterFloors[i]); // TODO
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ Player::Player()
|
|||||||
this->gravity = 0.1F;
|
this->gravity = 0.1F;
|
||||||
this->lift = -1.0F;
|
this->lift = -1.0F;
|
||||||
Vector3 initPos = Vector3(0.0F, 8.0F, 0.0F);
|
Vector3 initPos = Vector3(0.0F, 8.0F, 0.0F);
|
||||||
this->mesh.loadMD2("ari/", "ari.md2", initPos, 0.0001F);
|
// this->mesh.loadMD2("ari/", "ari.md2", initPos, 0.0001F);
|
||||||
this->mesh.shouldBeBackfaceCulled = true;
|
// this->mesh.shouldBeBackfaceCulled = true;
|
||||||
this->mesh.shouldBeFrustumCulled = false;
|
// this->mesh.shouldBeFrustumCulled = false;
|
||||||
// this->mesh.shouldBeLighted = true;
|
// this->mesh.shouldBeLighted = true;
|
||||||
this->mesh.setAnimSpeed(0.05F);
|
// this->mesh.setAnimSpeed(0.05F);
|
||||||
this->mesh.playAnimation(0, 1);
|
// this->mesh.playAnimation(0, 1);
|
||||||
PRINT_LOG("Player object created!");
|
PRINT_LOG("Player object created!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user