optimized rendering, fixed dff

This commit is contained in:
Sandro Sobczyński
2020-11-02 23:09:55 +01:00
parent 06a440243a
commit 5aa2a9bdb5
12 changed files with 466 additions and 469 deletions
+1 -2
View File
@@ -32,7 +32,6 @@ BmpLoader::~BmpLoader() {}
*/
void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
{
char *t_path_part = String::createConcatenated(t_subfolder, t_name);
char *t_path = String::createConcatenated(t_path_part, t_extension);
delete[] t_path_part;
@@ -78,5 +77,5 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
}
delete[] t_path;
delete[] data;
// fclose(file); // wtf?
fclose(file);
}
+208 -220
View File
@@ -42,143 +42,128 @@ void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_
PRINT_ERR("Failed to load .obj file!");
fseek(file, 0L, SEEK_END);
long fileSize = ftell(file);
u8 *data = new u8[fileSize];
u8 data[fileSize];
rewind(file);
fread(data, sizeof(u8), fileSize, file);
fread(&data, sizeof(u8), fileSize, file);
fclose(file);
RwClump *clump = new RwClump();
serialize(*clump, data, t_scale);
delete[] data;
// delete[] clump; // TODO
convert(o_result, *clump, t_invertT);
serialize(o_result, t_invertT, data, t_scale);
o_result->calculateBoundingBox();
PRINT_LOG("Dff file loaded!");
}
void DffLoader::convert(MeshFrame *o_result, RwClump &t_clump, u8 t_invertT)
{
#define GEOMETRY t_clump.geometryList.geometries[0]
MeshFrame *frame = &o_result[0];
u32 vertNormalStCount = GEOMETRY.data.dataHeader.vertexCount;
frame->allocateVertices(vertNormalStCount);
frame->allocateNormals(vertNormalStCount); // can be optimized
frame->allocateSTs(vertNormalStCount); // can be optimized
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);
}
}
frame->calculateBoundingBox();
}
void DffLoader::serialize(RwClump &t_clump, u8 *t_data, float t_scale)
void DffLoader::serialize(MeshFrame *o_result, u8 t_invertT, u8 *t_data, float t_scale)
{
u32 ptrPos = 0;
readSectionHeader(t_clump, t_data, ptrPos);
readSectionHeader(t_clump.data, t_data, ptrPos);
readClumpData(t_clump.data, t_data, ptrPos);
readSectionHeader(t_clump.frameList, t_data, ptrPos);
readSectionHeader(t_clump.frameList.data, t_data, ptrPos);
readFrameListData(t_clump.frameList.data, t_data, ptrPos);
t_clump.frameList.extensions = new RwFrameListExtension[t_clump.frameList.data.frameCount];
for (u32 i = 0; i < t_clump.frameList.data.frameCount; i++)
// readSectionHeader(t_clump, t_data, ptrPos);
// readSectionHeader(t_clump.data, t_data, ptrPos);
// readClumpData(t_clump.data, t_data, ptrPos);
for (u8 i = 0; i < 3 * 3; i++)
ptrPos += sizeof(u32);
// readSectionHeader(t_clump.frameList, t_data, ptrPos);
// readSectionHeader(t_clump.frameList.data, t_data, ptrPos);
// readFrameListData(t_clump.frameList.data, t_data, ptrPos);
// t_clump.frameList.extensions = new RwFrameListExtension[t_clump.frameList.data.frameCount];
// for (u32 i = 0; i < t_clump.frameList.data.frameCount; i++)
// {
// readSectionHeader(t_clump.frameList.extensions[i], t_data, ptrPos);
// ptrPos += t_clump.frameList.extensions[i].sectionSize;
// }
RwSectionHeader header1 = RwSectionHeader();
readSectionHeader(header1, t_data, ptrPos);
ptrPos += header1.sectionSize;
// readSectionHeader(t_clump.geometryList, t_data, ptrPos);
// readSectionHeader(t_clump.geometryList.data, t_data, ptrPos);
for (u8 i = 0; i < 2 * 3; i++)
ptrPos += sizeof(u32);
// readGeometryListData(t_clump.geometryList.data, t_data, ptrPos);
ptrPos += sizeof(u32);
// readSectionHeader(geometry, t_data, ptrPos);
// readSectionHeader(geometry.data, t_data, ptrPos);
for (size_t i = 0; i < 2 * 3; i++)
ptrPos += sizeof(u32);
readGeometryData(o_result, t_invertT, t_data, ptrPos, t_scale);
// readSectionHeader(geometry.materialList, t_data, ptrPos);
// readSectionHeader(geometry.materialList.data, t_data, ptrPos);
for (size_t i = 0; i < 2 * 3; i++)
ptrPos += sizeof(u32);
RwMaterialListData materialListData = RwMaterialListData();
readMaterialListData(materialListData, t_data, ptrPos);
u32 materialCount = materialListData.materialCount;
char **materialNames = new char *[materialCount];
for (u32 j = 0; j < materialCount; j++)
{
readSectionHeader(t_clump.frameList.extensions[i], t_data, ptrPos);
ptrPos += t_clump.frameList.extensions[i].sectionSize;
// readSectionHeader(geometry.materialList.materials[j], t_data, ptrPos);
for (size_t i = 0; i < 3; i++)
ptrPos += sizeof(u32);
// RwMaterialData materialData = RwMaterialData();
// readSectionHeader(materialData, t_data, ptrPos);
// readMaterialData(materialData, t_data, ptrPos);
RwSectionHeader header1 = RwSectionHeader();
readSectionHeader(header1, t_data, ptrPos);
ptrPos += header1.sectionSize;
// for (u32 k = 0; k < textureCount; k++)
// {
// readSectionHeader(geometry.materialList.materials[j].textures[k], t_data, ptrPos);
// readSectionHeader(geometry.materialList.materials[j].textures[k].data, t_data, ptrPos);
for (size_t i = 0; i < 2 * 3; i++)
ptrPos += sizeof(u32);
// readTextureData(geometry.materialList.materials[j].textures[k].data, t_data, ptrPos);
ptrPos += sizeof(u32);
RwSectionHeader header1b = RwSectionHeader();
readSectionHeader(header1b, t_data, ptrPos);
materialNames[j] = readString(t_data, ptrPos, header1b.sectionSize);
// readSectionHeader(geometry.materialList.materials[j].textures[k].textureAlphaName, t_data, ptrPos);
// readStringData(geometry.materialList.materials[j].textures[k].textureAlphaName, t_data, ptrPos);
RwSectionHeader header2 = RwSectionHeader();
readSectionHeader(header2, t_data, ptrPos);
ptrPos += header2.sectionSize;
// The content of extension is Sky Mipmap Val
// readSectionHeader(geometry.materialList.materials[j].textures[k].extension, t_data, ptrPos);
RwSectionHeader header3 = RwSectionHeader();
readSectionHeader(header3, t_data, ptrPos);
ptrPos += header3.sectionSize;
// }
// Probably always void extension
// readSectionHeader(geometry.materialList.materials[j].extension, t_data, ptrPos);
RwSectionHeader header4 = RwSectionHeader();
readSectionHeader(header4, t_data, ptrPos);
ptrPos += header4.sectionSize;
}
// delete[] materialNames; // TODO
readSectionHeader(t_clump.geometryList, t_data, ptrPos);
readSectionHeader(t_clump.geometryList.data, t_data, ptrPos);
readGeometryListData(t_clump.geometryList.data, t_data, ptrPos);
// For Bin Mesh aka Material split
// readSectionHeader(geometry.extension, t_data, ptrPos);
for (size_t i = 0; i < 3; i++)
ptrPos += sizeof(u32);
readGeometryExtension(o_result, materialNames, t_data, ptrPos);
t_clump.geometryList.geometries = new RwGeometry[t_clump.geometryList.data.geometryCount];
printf("Geometries:%d\n", t_clump.geometryList.data.geometryCount);
for (u32 i = 0; i < t_clump.geometryList.data.geometryCount; i++)
{
readSectionHeader(t_clump.geometryList.geometries[i], t_data, ptrPos);
readSectionHeader(t_clump.geometryList.geometries[i].data, t_data, ptrPos);
readGeometryData(t_clump.geometryList.geometries[i].data, t_data, ptrPos, t_scale);
for (size_t i = 0; i < materialCount; i++)
delete[] materialNames[i];
readSectionHeader(t_clump.geometryList.geometries[i].materialList, t_data, ptrPos);
readSectionHeader(t_clump.geometryList.geometries[i].materialList.data, t_data, ptrPos);
readMaterialListData(t_clump.geometryList.geometries[i].materialList.data, t_data, ptrPos);
delete materialNames;
u32 materialCount = t_clump.geometryList.geometries[i].materialList.data.materialCount;
printf("Materials:%d\n", materialCount);
// ptrPos += geometry.extension.sectionSize;
t_clump.geometryList.geometries[i].materialList.materials = new RwMaterial[materialCount];
for (u32 j = 0; j < materialCount; j++)
{
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j], t_data, ptrPos);
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j].data, t_data, ptrPos);
readMaterialData(t_clump.geometryList.geometries[i].materialList.materials[j].data, t_data, ptrPos);
u32 textureCount = t_clump.geometryList.geometries[i].materialList.materials[j].data.textureCount;
t_clump.geometryList.geometries[i].materialList.materials[j].textures = new RwTexture[textureCount];
for (u32 k = 0; k < textureCount; k++)
{
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k], t_data, ptrPos);
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].data, t_data, ptrPos);
readTextureData(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].data, t_data, ptrPos);
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].textureName, t_data, ptrPos);
readStringData(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].textureName, t_data, ptrPos);
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].textureAlphaName, t_data, ptrPos);
readStringData(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].textureAlphaName, t_data, ptrPos);
// The content of extension is Sky Mipmap Val
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].extension, t_data, ptrPos);
ptrPos += t_clump.geometryList.geometries[i].materialList.materials[j].textures[k].extension.sectionSize;
}
// Probably always void extension
readSectionHeader(t_clump.geometryList.geometries[i].materialList.materials[j].extension, t_data, ptrPos);
ptrPos += t_clump.geometryList.geometries[i].materialList.materials[j].extension.sectionSize;
}
// For Bin Mesh aka Material split
readSectionHeader(t_clump.geometryList.geometries[i].extension, t_data, ptrPos);
readGeometryExtension(t_clump.geometryList.geometries[i].extension, t_data, ptrPos);
ptrPos += t_clump.geometryList.geometries[i].extension.sectionSize;
}
readSectionHeader(t_clump.atomic, t_data, ptrPos);
readSectionHeader(t_clump.atomic.data, t_data, ptrPos);
ptrPos += t_clump.atomic.data.sectionSize;
// readSectionHeader(t_clump.atomic, t_data, ptrPos);
// readSectionHeader(t_clump.atomic.data, t_data, ptrPos);
// ptrPos += t_clump.atomic.data.sectionSize;
}
void DffLoader::readSectionHeader(RwSectionHeader &t_sh, u8 *t_buffer, u32 &t_ptrPos)
@@ -192,139 +177,151 @@ void DffLoader::readSectionHeader(RwSectionHeader &t_sh, u8 *t_buffer, u32 &t_pt
void DffLoader::readFrameListData(RwFrameListData &t_frd, u8 *t_buffer, u32 &t_ptrPos)
{
t_frd.frameCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
printf("Frame count:%d\n", t_frd.frameCount);
t_frd.frameInformation = new RwFrameListChunk[t_frd.frameCount];
// t_frd.frameCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
// printf("Frame count:%d\n", t_frd.frameCount);
// t_frd.frameInformation = new RwFrameListChunk[t_frd.frameCount];
for (u32 i = 0; i < t_frd.frameCount; i++)
{
t_frd.frameInformation[i].rotationalMatrix = new float[t_frd.ROT_MAT_DIM];
for (u32 j = 0; j < t_frd.ROT_MAT_DIM; j++)
t_frd.frameInformation[i].rotationalMatrix[j] = readFloatFromArrayLE(t_buffer, t_ptrPos);
// for (u32 i = 0; i < t_frd.frameCount; i++)
// {
// t_frd.frameInformation[i].rotationalMatrix = new float[t_frd.ROT_MAT_DIM];
// for (u32 j = 0; j < t_frd.ROT_MAT_DIM; j++)
// t_frd.frameInformation[i].rotationalMatrix[j] = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_frd.frameInformation[i].coordinatesOffsetX = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_frd.frameInformation[i].coordinatesOffsetY = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_frd.frameInformation[i].coordinatesOffsetZ = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_frd.frameInformation[i]
.parentFrame = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_frd.frameInformation[i].unk1 = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
}
// t_frd.frameInformation[i].coordinatesOffsetX = readFloatFromArrayLE(t_buffer, t_ptrPos);
// t_frd.frameInformation[i].coordinatesOffsetY = readFloatFromArrayLE(t_buffer, t_ptrPos);
// t_frd.frameInformation[i].coordinatesOffsetZ = readFloatFromArrayLE(t_buffer, t_ptrPos);
// t_frd.frameInformation[i]
// .parentFrame = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
// t_frd.frameInformation[i].unk1 = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
// }
}
void DffLoader::readClumpData(RwClumpData &t_cd, u8 *t_buffer, u32 &t_ptrPos)
{
t_cd.objectCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_cd.unk1 = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_cd.unk2 = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
// t_cd.objectCount = readDwordFromArrayLE(t_buffer, t_ptrPos);
// t_cd.unk1 = readDwordFromArrayLE(t_buffer, t_ptrPos);
// t_cd.unk2 = readDwordFromArrayLE(t_buffer, t_ptrPos);
}
void DffLoader::readGeometryListData(RwGeometryListData &t_gld, u8 *t_buffer, u32 &t_ptrPos)
{
t_gld.geometryCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
// t_gld.geometryCount = readDwordFromArrayLE(t_buffer, t_ptrPos);
}
void DffLoader::readGeometryExtension(RwGeometryExtension &t_ge, u8 *t_buffer, u32 &t_ptrPos)
void DffLoader::readGeometryExtension(MeshFrame *o_frame, char **materialNames, u8 *t_buffer, u32 &t_ptrPos)
{
for (u8 i = 0; i < 3; i++)
t_ptrPos += sizeof(u32);
t_ge.materialSplit.header.triangleStrip = readDwordFromArrayLE(t_buffer, t_ptrPos);
t_ge.materialSplit.header.splitCount = readDwordFromArrayLE(t_buffer, t_ptrPos);
t_ge.materialSplit.header.faceCount = readDwordFromArrayLE(t_buffer, t_ptrPos);
RwMaterialSplitHeader header = RwMaterialSplitHeader();
header.triangleStrip = readDwordFromArrayLE(t_buffer, t_ptrPos);
header.splitCount = readDwordFromArrayLE(t_buffer, t_ptrPos);
header.faceCount = readDwordFromArrayLE(t_buffer, t_ptrPos);
t_ge.materialSplit.splitInformation = new RwGeometryListInfoChunk[t_ge.materialSplit.header.splitCount];
for (u32 i = 0; i < t_ge.materialSplit.header.splitCount; i++)
o_frame->allocateMaterials(header.splitCount);
for (u32 i = 0; i < header.splitCount; i++)
{
t_ge.materialSplit.splitInformation[i].faceIndex = readDwordFromArrayLE(t_buffer, t_ptrPos);
t_ge.materialSplit.splitInformation[i].materialIndex = readDwordFromArrayLE(t_buffer, t_ptrPos);
t_ge.materialSplit.splitInformation[i].vertexInformation = new RwGeometryListVertexInfoChunk[t_ge.materialSplit.splitInformation[i].faceIndex];
for (u32 j = 0; j < t_ge.materialSplit.splitInformation[i].faceIndex; j++)
t_ge.materialSplit.splitInformation[i].vertexInformation[j].vertex1 = readDwordFromArrayLE(t_buffer, t_ptrPos);
u32 facesCount = readDwordFromArrayLE(t_buffer, t_ptrPos);
u32 materialIndex = readDwordFromArrayLE(t_buffer, t_ptrPos);
o_frame->getMaterial(i).allocateFaces(facesCount);
o_frame->getMaterial(i).setName(materialNames[materialIndex]);
for (u32 j = 0; j < facesCount; j++)
{
u32 vertex1 = readDwordFromArrayLE(t_buffer, t_ptrPos);
o_frame->getMaterial(i).setVertexFace(j, vertex1);
o_frame->getMaterial(i).setNormalFace(j, vertex1);
o_frame->getMaterial(i).setSTFace(j, vertex1);
}
}
}
void DffLoader::readGeometryData(RwGeometryData &t_gd, u8 *t_buffer, u32 &t_ptrPos, float t_scale)
void DffLoader::readGeometryData(MeshFrame *o_frame, u8 t_invertT, u8 *t_buffer, u32 &t_ptrPos, float t_scale)
{
t_gd.dataHeader.flags = readWordFromArrayLE(t_buffer, t_ptrPos);
t_gd.dataHeader.unk1 = readWordFromArrayLE(t_buffer, t_ptrPos);
t_gd.dataHeader.triangleCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_gd.dataHeader.vertexCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_gd.dataHeader.morphTargetCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
Vector3 tempVec = Vector3();
Point tempPoint = Point();
RwGeometryDataHeader header;
header.flags = readWordFromArrayLE(t_buffer, t_ptrPos);
header.unk1 = readWordFromArrayLE(t_buffer, t_ptrPos);
header.triangleCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
header.vertexCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
header.morphTargetCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
if (false)
{ // version equals 4099 according to old documentation, disabled as for now
t_gd.lightingHeader.ambient = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_gd.lightingHeader.diffuse = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_gd.lightingHeader.specular = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
{ // version equals 4099 according to old documentation, disabled as for now
readDwordFromArrayLE(t_buffer, t_ptrPos); // ambient
readDwordFromArrayLE(t_buffer, t_ptrPos); // diffuse
readDwordFromArrayLE(t_buffer, t_ptrPos); // specular
}
if (t_gd.dataHeader.flags & rwOBJECT_VERTEX_PRELIT)
{
t_gd.colorInformation = new RwGeometryDataColorInformationChunk[t_gd.dataHeader.vertexCount];
for (u32 i = 0; i < t_gd.dataHeader.vertexCount; i++)
if (header.flags & rwOBJECT_VERTEX_PRELIT)
for (u32 i = 0; i < header.vertexCount; i++)
{
t_gd.colorInformation[i].red = readByteFromArrayLE(t_buffer, t_ptrPos);
t_gd.colorInformation[i].green = readByteFromArrayLE(t_buffer, t_ptrPos);
t_gd.colorInformation[i].blue = readByteFromArrayLE(t_buffer, t_ptrPos);
t_gd.colorInformation[i].alpha = readByteFromArrayLE(t_buffer, t_ptrPos);
readByteFromArrayLE(t_buffer, t_ptrPos); // r
readByteFromArrayLE(t_buffer, t_ptrPos); // g
readByteFromArrayLE(t_buffer, t_ptrPos); // b
readByteFromArrayLE(t_buffer, t_ptrPos); // a
}
if (header.flags & rwOBJECT_VERTEX_TEXTURED)
{
o_frame->allocateSTs(header.vertexCount);
for (u32 i = 0; i < header.vertexCount; i++)
{
float u = readFloatFromArrayLE(t_buffer, t_ptrPos);
float v = readFloatFromArrayLE(t_buffer, t_ptrPos);
tempPoint.set(u, v);
if (t_invertT)
tempPoint.y = 1.0F - tempPoint.y;
o_frame->setST(i, tempPoint);
}
}
if (t_gd.dataHeader.flags & rwOBJECT_VERTEX_TEXTURED)
for (u32 i = 0; i < header.triangleCount; i++)
{
t_gd.textureMappingInformation = new RwGeometryDataTextureMappingInformationChunk[t_gd.dataHeader.vertexCount];
for (u32 i = 0; i < t_gd.dataHeader.vertexCount; i++)
{
t_gd.textureMappingInformation[i].u = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_gd.textureMappingInformation[i].v = readFloatFromArrayLE(t_buffer, t_ptrPos);
}
readWordFromArrayLE(t_buffer, t_ptrPos); // vert2
readWordFromArrayLE(t_buffer, t_ptrPos); // vert1
readWordFromArrayLE(t_buffer, t_ptrPos); // flags
readWordFromArrayLE(t_buffer, t_ptrPos); // vert3
}
t_gd.faceInformation = new RwGeometryDataFaceInformation[t_gd.dataHeader.triangleCount];
for (u32 i = 0; i < t_gd.dataHeader.triangleCount; i++)
for (size_t i = 0; i < 6; i++)
t_ptrPos += sizeof(u32);
// t_gd.nonameInfo.boundingSphereX = readFloatFromArrayLE(t_buffer, t_ptrPos);
// t_gd.nonameInfo.boundingSphereY = readFloatFromArrayLE(t_buffer, t_ptrPos);
// t_gd.nonameInfo.boundingSphereZ = readFloatFromArrayLE(t_buffer, t_ptrPos);
// t_gd.nonameInfo.boundingSphereR = readFloatFromArrayLE(t_buffer, t_ptrPos);
// t_gd.nonameInfo.hasPosition = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
// t_gd.nonameInfo.hasNormals = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
o_frame->allocateVertices(header.vertexCount);
for (u32 i = 0; i < header.vertexCount; i++)
{
t_gd.faceInformation[i].vertex2 = readWordFromArrayLE(t_buffer, t_ptrPos);
t_gd.faceInformation[i].vertex1 = readWordFromArrayLE(t_buffer, t_ptrPos);
t_gd.faceInformation[i].flags = readWordFromArrayLE(t_buffer, t_ptrPos);
t_gd.faceInformation[i].vertex3 = readWordFromArrayLE(t_buffer, t_ptrPos);
float x = readFloatFromArrayLE(t_buffer, t_ptrPos) * t_scale;
float y = readFloatFromArrayLE(t_buffer, t_ptrPos) * t_scale;
float z = readFloatFromArrayLE(t_buffer, t_ptrPos) * t_scale;
tempVec.set(x, y, z);
o_frame->setVertex(i, tempVec);
}
t_gd.nonameInfo.boundingSphereX = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_gd.nonameInfo.boundingSphereY = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_gd.nonameInfo.boundingSphereZ = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_gd.nonameInfo.boundingSphereR = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_gd.nonameInfo.hasPosition = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_gd.nonameInfo.hasNormals = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_gd.vertexInformation = new Vector3[t_gd.dataHeader.vertexCount];
for (u32 i = 0; i < t_gd.dataHeader.vertexCount; i++)
o_frame->allocateNormals(header.vertexCount);
for (u32 i = 0; i < header.vertexCount; i++)
{
t_gd.vertexInformation[i].x = readFloatFromArrayLE(t_buffer, t_ptrPos) * t_scale;
t_gd.vertexInformation[i].y = readFloatFromArrayLE(t_buffer, t_ptrPos) * t_scale;
t_gd.vertexInformation[i].z = readFloatFromArrayLE(t_buffer, t_ptrPos) * t_scale;
}
if (t_gd.dataHeader.flags & rwOBJECT_VERTEX_NORMALS)
{
t_gd.normalInformation = new Vector3[t_gd.dataHeader.vertexCount];
for (u32 i = 0; i < t_gd.dataHeader.vertexCount; i++)
{
t_gd.normalInformation[i].x = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_gd.normalInformation[i].y = readFloatFromArrayLE(t_buffer, t_ptrPos);
t_gd.normalInformation[i].z = readFloatFromArrayLE(t_buffer, t_ptrPos);
}
float x = readFloatFromArrayLE(t_buffer, t_ptrPos);
float y = readFloatFromArrayLE(t_buffer, t_ptrPos);
float z = readFloatFromArrayLE(t_buffer, t_ptrPos);
tempVec.set(x, y, z);
o_frame->setNormal(i, tempVec);
}
}
void DffLoader::readMaterialListData(RwMaterialListData &t_mld, u8 *t_buffer, u32 &t_ptrPos)
{
t_mld.materialCount = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
t_mld.arrayOfUnks = new u32[t_mld.materialCount];
// t_mld.arrayOfUnks = new u32[t_mld.materialCount];
for (u32 i = 0; i < t_mld.materialCount; i++)
{
t_mld.arrayOfUnks[i] = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
}
readDwordFromArrayLE(t_buffer, t_ptrPos);
// t_mld.arrayOfUnks[i] = DffLoader::readDwordFromArrayLE(t_buffer, t_ptrPos);
}
void DffLoader::readMaterialData(RwMaterialData &t_md, u8 *t_buffer, u32 &t_ptrPos)
@@ -381,15 +378,6 @@ float DffLoader::readFloatFromArrayLE(u8 *t_buffer, u32 &t_ptrPos)
return res;
}
u8 *DffLoader::readData(u8 *t_buffer, u32 &t_ptrPos, u32 t_dataSize)
{
u8 *arr = new u8[t_dataSize];
for (u32 i = 0; i < t_dataSize; ++i)
arr[i] = t_buffer[i + t_ptrPos];
t_ptrPos += t_dataSize;
return arr;
}
char *DffLoader::readString(u8 *t_buffer, u32 &t_ptrPos, u32 t_dataSize)
{
u32 strLength = String::getLength((char *)&t_buffer[t_ptrPos]);