Change face parsing counter

This commit is contained in:
JackCarterSmith 2023-02-16 16:59:55 +01:00
parent 3614742343
commit 3307cfaab7
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
5 changed files with 55 additions and 25 deletions

2
Jenkinsfile vendored
View File

@ -5,7 +5,7 @@ pipeline {
} }
environment { environment {
CI_OUTPUT_NAME = "RSEModel" CI_OUTPUT_NAME = "RSEModel"
CI_VERSION = "2.3.0" CI_VERSION = "2.3.1"
CI_BUILD_NUMBER = "$BUILD_NUMBER" CI_BUILD_NUMBER = "$BUILD_NUMBER"
} }
stages { stages {

View File

@ -1,6 +1,6 @@
/** /**
* @file RSPModel_datatypes.h * @file RSPModel_datatypes.h
* @date 11/08/2022 * @date 16/02/2023
* @author JackCarterSmith * @author JackCarterSmith
* @copyright GPL-v3.0 * @copyright GPL-v3.0
* @brief RSP Model workflow structures definitions * @brief RSP Model workflow structures definitions
@ -55,8 +55,8 @@ typedef struct face_flags {
unsigned int fSeparateColorVertex:1; unsigned int fSeparateColorVertex:1;
unsigned int fHasColor:1; unsigned int fHasColor:1;
unsigned int fHasExtraBytesBeforeColor:1; unsigned int fHasExtraBytesBeforeColor:1;
unsigned int fIsTransparent:1;
unsigned int fUnknown7:1;
unsigned int fUnknown8:1; unsigned int fUnknown8:1;
unsigned int fUnknown9:1; unsigned int fUnknown9:1;
unsigned int fUnknown10:1; unsigned int fUnknown10:1;

View File

@ -1,6 +1,6 @@
/** /**
* @file hob_parser.c * @file hob_parser.c
* @date 18/01/2023 * @date 16/02/2023
* @author JackCarterSmith * @author JackCarterSmith
* @copyright GPL-v3.0 * @copyright GPL-v3.0
* @brief Process HOB file structure and extract its datas. * @brief Process HOB file structure and extract its datas.
@ -203,7 +203,7 @@ static unsigned short ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE
// Get meshdef1 (mesh descriptor) offset // Get meshdef1 (mesh descriptor) offset
pObject->object_parts[i].meshdef1_offset = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->meshdef1_offset_plus_4; pObject->object_parts[i].meshdef1_offset = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->meshdef1_offset_plus_4;
if (pParams->verbose_mode) printf("\n[DBG] > Face group meshdef1 offset: 0x%X\n", pObject->object_parts[i].meshdef1_offset); if (pParams->verbose_mode) printf("\n[DBG] > Face group vertices descriptor (meshdef1) offset: 0x%X\n", pObject->object_parts[i].meshdef1_offset);
if( ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved1 != 0 || if( ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved1 != 0 ||
((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved2 != 0 ) { ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved2 != 0 ) {
@ -226,6 +226,8 @@ static unsigned short ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE
// Get faces datas // Get faces datas
ExtractObjParts_faces(&pObject->object_parts[i], pMemfile, pParams); ExtractObjParts_faces(&pObject->object_parts[i], pMemfile, pParams);
} else {
if (pParams->verbose_mode) printf("\n[DBG] > No vertices datas (meshdef1 = 0x0).\n");
} }
// Get object part ID, used by animation? bones? // Get object part ID, used by animation? bones?
@ -260,7 +262,8 @@ static unsigned short ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE
* @return Error code, RSPLIB_SUCCESS when no error. * @return Error code, RSPLIB_SUCCESS when no error.
*/ */
static unsigned short ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) { static unsigned short ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) {
unsigned int i, facesExtraOffset = 0; unsigned int i, facesExtraOffset = 0, localOffset = 0;
unsigned short headerSeparator;
if (pObjPart == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; if (pObjPart == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL;
@ -274,55 +277,61 @@ static unsigned short ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, cons
} }
pObjPart->face_count = ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->faceCounts; pObjPart->face_count = ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->faceCounts;
if (pParams->debug_mode) printf("[DBG] > Faces count: %d\n", pObjPart->face_count);
pObjPart->faces = calloc(pObjPart->face_count, sizeof(T_RSPMODEL_FACE)); pObjPart->faces = calloc(pObjPart->face_count, sizeof(T_RSPMODEL_FACE));
for ( i = 0; i < pObjPart->face_count; i++ ) { for ( i = 0; i < pObjPart->face_count; i++ ) {
if (pParams->debug_mode) printf("\n----------------------Begin of Face part----------------------\n"); if (pParams->debug_mode) printf("\n----------------------Begin of Face part----------------------\n");
// Get flags // Get flags
pObjPart->faces[i].flags = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset pObjPart->faces[i].flags = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->flags; + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->flags;
// Get unknown bytes // Get unknown bytes
pObjPart->faces[i].b1 = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset pObjPart->faces[i].b1 = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->b1; + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->b1;
pObjPart->faces[i].b2 = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset pObjPart->faces[i].b2 = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->b2; + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->b2;
pObjPart->faces[i].b3 = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset pObjPart->faces[i].b3 = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->b3; + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->b3;
pObjPart->faces[i].bsize = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset pObjPart->faces[i].bsize = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->faceBlockIntSize * 4; // Multiply by 4 to get the bytes exact number + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->faceBlockIntSize * 4; // Multiply by 4 to get the bytes exact number
if (((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset + sizeof(T_HOBFILE_FACEBLOCK)
+ sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->headerSeparator != 0) { headerSeparator = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
if (pParams->god_mode) printf("[DBG] > Face header: uncommon separator!\n"); + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->headerSeparator;
if (headerSeparator != 0) {
if (pParams->god_mode) printf("[DBG] > Face header: uncommon separator! (0x%X)\n", headerSeparator);
} }
// Get materials index // Get materials index
pObjPart->faces[i].mt_index = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset pObjPart->faces[i].mt_index = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->materialIndex; + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->materialIndex;
// Get vertex indices // Get vertex indices
memcpy(pObjPart->faces[i].indices, ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset memcpy(pObjPart->faces[i].indices, ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->vertexIndices, + sizeof(T_HOBFILE_FACEBLOCK) + facesExtraOffset))->vertexIndices,
sizeof(unsigned short) * 4); sizeof(unsigned short) * 4);
// Recalculate the dynamic extra bytes offset size - if present // Recalculate the dynamic extra bytes offset size - if present
if (pObjPart->faces[i].flags_bits.fHasExtraBytesBeforeColor) facesExtraOffset += 8; //if (pObjPart->faces[i].flags_bits.fHasExtraBytesBeforeColor) facesExtraOffset += 8;
localOffset = pObjPart->faces[i].flags_bits.fHasExtraBytesBeforeColor ? 8 : 0;
// Get vertex color - if present // Get vertex color - if present
if (pObjPart->faces[i].flags_bits.fHasColor) { if (pObjPart->faces[i].flags_bits.fHasColor) {
facesExtraOffset += ExtractObjpart_Face_Colors(&pObjPart->faces[i], pMemfile + pObjPart->face_block_offset localOffset += ExtractObjpart_Face_Colors(&pObjPart->faces[i], pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) + sizeof(T_HOBFILE_FACES_HEADER) * i + sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * (i + 1)
+ facesExtraOffset); + facesExtraOffset + localOffset);
} }
// Get UV map - if present // Get UV map - if present
if (pObjPart->faces[i].flags_bits.fHasTexture) { if (pObjPart->faces[i].flags_bits.fHasTexture) {
facesExtraOffset += ExtractObjpart_Face_UVMaps(&pObjPart->faces[i], pMemfile + pObjPart->face_block_offset localOffset += ExtractObjpart_Face_UVMaps(&pObjPart->faces[i], pMemfile + pObjPart->face_block_offset
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) + sizeof(T_HOBFILE_FACES_HEADER) * i + sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * (i + 1)
+ facesExtraOffset); + facesExtraOffset + localOffset);
} }
facesExtraOffset += pObjPart->faces[i].bsize;
if (pParams->debug_mode) { if (pParams->debug_mode) {
printf("[DBG] > Face %d details: flags:0x%X b1:0x%X b2:0x%X b3:0x%X bsize:%d\n", i, pObjPart->faces[i].flags, printf("[DBG] > Face %d details: flags:0x%X b1:0x%X b2:0x%X b3:0x%X bsize:%d\n", i, pObjPart->faces[i].flags,
pObjPart->faces[i].b1, pObjPart->faces[i].b2, pObjPart->faces[i].b3, pObjPart->faces[i].bsize); pObjPart->faces[i].b1, pObjPart->faces[i].b2, pObjPart->faces[i].b3, pObjPart->faces[i].bsize);

View File

@ -1,6 +1,6 @@
/** /**
* @file hob_struct.h * @file hob_struct.h
* @date 26/07/2022 * @date 16/02/2023
* @author JackCarterSmith * @author JackCarterSmith
* @copyright GPL-v3.0 * @copyright GPL-v3.0
* @brief HOB file mapping definition. * @brief HOB file mapping definition.
@ -205,7 +205,7 @@ typedef struct PACK hobfile_faceblock {
typedef struct PACK hobfile_faces_header { typedef struct PACK hobfile_faces_header {
unsigned int flags; unsigned int flags;
unsigned char b1; // 74 = transparent / 75 = opaque unsigned char b1;
unsigned char b2; unsigned char b2;
unsigned char b3; unsigned char b3;
unsigned char faceBlockIntSize; // Bytes size divided by 4, count as number of UInt32 type. unsigned char faceBlockIntSize; // Bytes size divided by 4, count as number of UInt32 type.

View File

@ -0,0 +1,21 @@
/**
* @file mesh_builder.h
* @date 18/01/2023
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Mesh constructor of HOB objects.
*
*/
#include "RSPModel_datatypes.h"
#ifndef MESH_BUILDER_H_
#define MESH_BUILDER_H_
unsigned short RSP_ModelLib_HOBObjectToGL( const T_RSPMODEL_OBJECT* objStruct );
/*
unsigned short RSP_ModelLib_HOBObjectToGL( const T_RSPMODEL_OBJECT* objStruct, void* glObj );
unsigned short RSP_ModelLib_HOBObjectToD3D( const T_RSPMODEL_OBJECT* objStruct, void* D3DObj );
*/
#endif /* MESH_BUILDER_H_ */