From c7ebe82131db2c94d01c87803df588b367cd29d3 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Thu, 2 Aug 2018 17:13:50 -0500 Subject: [PATCH] Calculate bounds for unanimated IQM models Bounds are optional for animated IQM models but are not possible to include with unanimated models (seems intended for use with separate model containing animations and bounds). Calculating bounds for unanimated IQM models fixes culling and head model on HUD which calculates position from model bounds. --- code/renderergl1/tr_model_iqm.c | 14 ++++++++++++++ code/renderergl2/tr_model_iqm.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/code/renderergl1/tr_model_iqm.c b/code/renderergl1/tr_model_iqm.c index 3e699619..02616469 100644 --- a/code/renderergl1/tr_model_iqm.c +++ b/code/renderergl1/tr_model_iqm.c @@ -566,6 +566,8 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na } if( header->ofs_bounds ) { size += header->num_frames * 6 * sizeof(float); // model bounds + } else if( header->num_meshes && header->num_frames == 0 ) { + size += 6 * sizeof(float); // model bounds } mod->type = MOD_IQM; @@ -641,6 +643,9 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na if( header->ofs_bounds ) { iqmData->bounds = (float*)dataPtr; dataPtr += header->num_frames * 6 * sizeof(float); // model bounds + } else if( header->num_meshes && header->num_frames == 0 ) { + iqmData->bounds = (float*)dataPtr; + dataPtr += 6 * sizeof(float); // model bounds } if( header->num_meshes ) @@ -907,6 +912,15 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na bounds++; } } + else if( header->num_meshes && header->num_frames == 0 ) + { + mat = iqmData->bounds; + + ClearBounds( &iqmData->bounds[0], &iqmData->bounds[3] ); + for ( i = 0 ; i < header->num_vertexes ; i++ ) { + AddPointToBounds( &iqmData->positions[i*3], &iqmData->bounds[0], &iqmData->bounds[3] ); + } + } return qtrue; } diff --git a/code/renderergl2/tr_model_iqm.c b/code/renderergl2/tr_model_iqm.c index 63a5d92a..1a6e1e5a 100644 --- a/code/renderergl2/tr_model_iqm.c +++ b/code/renderergl2/tr_model_iqm.c @@ -569,6 +569,8 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na } if( header->ofs_bounds ) { size += header->num_frames * 6 * sizeof(float); // model bounds + } else if( header->num_meshes && header->num_frames == 0 ) { + size += 6 * sizeof(float); // model bounds } mod->type = MOD_IQM; @@ -644,6 +646,9 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na if( header->ofs_bounds ) { iqmData->bounds = (float*)dataPtr; dataPtr += header->num_frames * 6 * sizeof(float); // model bounds + } else if( header->num_meshes && header->num_frames == 0 ) { + iqmData->bounds = (float*)dataPtr; + dataPtr += 6 * sizeof(float); // model bounds } if( header->num_meshes ) @@ -910,6 +915,15 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na bounds++; } } + else if( header->num_meshes && header->num_frames == 0 ) + { + mat = iqmData->bounds; + + ClearBounds( &iqmData->bounds[0], &iqmData->bounds[3] ); + for ( i = 0 ; i < header->num_vertexes ; i++ ) { + AddPointToBounds( &iqmData->positions[i*3], &iqmData->bounds[0], &iqmData->bounds[3] ); + } + } // Create VAO surfaces if ( iqmData->num_surfaces && iqmData->num_joints <= glRefConfig.glslMaxAnimatedBones )