From 4e9c91e86d71531b24c7c4b8dffd0e4e82e22898 Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 31 Oct 2025 16:00:12 +0500 Subject: [PATCH] add ModelGetTransform() --- tools/quake3/q3map2/light_trace.cpp | 34 ++++----------------- tools/quake3/q3map2/model.cpp | 46 ++++++++++++++--------------- tools/quake3/q3map2/model.h | 2 ++ 3 files changed, 29 insertions(+), 53 deletions(-) diff --git a/tools/quake3/q3map2/light_trace.cpp b/tools/quake3/q3map2/light_trace.cpp index 08c17abb..8ff94c7d 100644 --- a/tools/quake3/q3map2/light_trace.cpp +++ b/tools/quake3/q3map2/light_trace.cpp @@ -1053,8 +1053,7 @@ static void PopulateTraceNodes(){ /* add worldspawn triangles */ - Matrix4 transform( g_matrix4_identity ); - PopulateWithBSPModel( bspModels[ 0 ], transform ); + PopulateWithBSPModel( bspModels[ 0 ], g_matrix4_identity ); /* walk each entity list */ for ( std::size_t i = 1; i < entities.size(); ++i ) @@ -1071,29 +1070,6 @@ static void PopulateTraceNodes(){ continue; } - /* get entity origin */ - const Vector3 origin( e.vectorForKey( "origin" ) ); - - /* get scale */ - Vector3 scale( 1 ); - if( !e.read_keyvalue( scale, "modelscale_vec" ) ) - if( e.read_keyvalue( scale[0], "modelscale" ) ) - scale[1] = scale[2] = scale[0]; - - /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ - Vector3 angles( 0 ); - if ( e.read_keyvalue( angles, "angles" ) || e.read_keyvalue( angles.y(), "angle" ) ) - angles = angles_pyr2rpy( angles ); - - /* set transform matrix (thanks spog) */ - transform = g_matrix4_identity; - matrix4_transform_by_euler_xyz_degrees( transform, origin, angles, scale ); - - /* hack: Stable-1_2 and trunk have differing row/column major matrix order - this transpose is necessary with Stable-1_2 - uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */ - //% m4x4_transpose( transform ); - /* get model */ value = e.valueForKey( "model" ); @@ -1111,12 +1087,12 @@ static void PopulateTraceNodes(){ continue; } // using only origin for bmodels transform; only exception in vq3 is func_pendulum transform determined by angle/angles - PopulateWithBSPModel( bspModels[ m ], matrix4_translation_for_vec3( origin ) ); + PopulateWithBSPModel( bspModels[ m ], matrix4_translation_for_vec3( e.vectorForKey( "origin" ) ) ); break; /* external model */ default: - PopulateWithPicoModel( castShadows, LoadModelWalker( value, e.intForKey( "_frame", "frame" ) ), transform ); + PopulateWithPicoModel( castShadows, LoadModelWalker( value, e.intForKey( "_frame", "frame" ) ), ModelGetTransform( e ) ); continue; } @@ -1136,12 +1112,12 @@ static void PopulateTraceNodes(){ if ( m <= 0 || m >= bspModels.size() ) { continue; } - PopulateWithBSPModel( bspModels[ m ], matrix4_translation_for_vec3( origin ) ); + PopulateWithBSPModel( bspModels[ m ], matrix4_translation_for_vec3( e.vectorForKey( "origin" ) ) ); break; /* external model */ default: - PopulateWithPicoModel( castShadows, LoadModelWalker( value, e.intForKey( "_frame2" ) ), transform ); + PopulateWithPicoModel( castShadows, LoadModelWalker( value, e.intForKey( "_frame2" ) ), ModelGetTransform( e ) ); continue; } } diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 9bf38731..5f43d027 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -1052,11 +1052,6 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4& } } - /* hack: Stable-1_2 and trunk have differing row/column major matrix order - this transpose is necessary with Stable-1_2 - uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */ - //% m4x4_transpose( transform ); - /* each surface on the model will become a new map drawsurface */ //% Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces ); for ( const auto& surface : model->m_meshes ) @@ -1226,6 +1221,27 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4& } +Matrix4 ModelGetTransform( const entity_t& e, const Vector3& parent_origin /* = g_vector3_identity */ ){ + /* get origin */ + const Vector3 origin = e.vectorForKey( "origin" ) - parent_origin; /* offset by parent, it will be added ingame */ + + /* get scale */ + Vector3 scale( 1 ); + if( !e.read_keyvalue( scale, "modelscale_vec" ) ) + if( e.read_keyvalue( scale[0], "modelscale" ) ) + scale[1] = scale[2] = scale[0]; + + /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ + Vector3 angles( 0 ); + if ( e.read_keyvalue( angles, "angles" ) || e.read_keyvalue( angles.y(), "angle" ) ) + angles = angles_pyr2rpy( angles ); + + /* set transform matrix (thanks spog) */ + Matrix4 transform( g_matrix4_identity ); + matrix4_transform_by_euler_xyz_degrees( transform, origin, angles, scale ); + return transform; +} + /* AddTriangleModels() @@ -1276,24 +1292,6 @@ void AddTriangleModels( entity_t& eparent ){ /* get spawnflags */ const int spawnFlags = e.intForKey( "spawnflags" ); - /* get origin */ - const Vector3 origin = e.vectorForKey( "origin" ) - eparent.origin; /* offset by parent */ - - /* get scale */ - Vector3 scale( 1 ); - if( !e.read_keyvalue( scale, "modelscale_vec" ) ) - if( e.read_keyvalue( scale[0], "modelscale" ) ) - scale[1] = scale[2] = scale[0]; - - /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ - Vector3 angles( 0 ); - if ( e.read_keyvalue( angles, "angles" ) || e.read_keyvalue( angles.y(), "angle" ) ) - angles = angles_pyr2rpy( angles ); - - /* set transform matrix (thanks spog) */ - Matrix4 transform( g_matrix4_identity ); - matrix4_transform_by_euler_xyz_degrees( transform, origin, angles, scale ); - /* get shader remappings */ std::list remaps; for ( const auto& ep : e.epairs ) @@ -1343,6 +1341,6 @@ void AddTriangleModels( entity_t& eparent ){ const EntityCompileParams params = ParseEntityCompileParams( e, &eparent, &eparent == &entities[ 0 ] ); /* insert the model */ - InsertModel( model, skin, frame, transform, &remaps, eparent, spawnFlags, clipDepth, params ); + InsertModel( model, skin, frame, ModelGetTransform( e, eparent.origin ), &remaps, eparent, spawnFlags, clipDepth, params ); } } diff --git a/tools/quake3/q3map2/model.h b/tools/quake3/q3map2/model.h index ff3186b9..b8ae7b24 100644 --- a/tools/quake3/q3map2/model.h +++ b/tools/quake3/q3map2/model.h @@ -25,6 +25,8 @@ #include #include "generic/vector.h" +Matrix4 ModelGetTransform( const entity_t& e, const Vector3& parent_origin = g_vector3_identity ); + class AssMeshWalker { public: