From 64cd34412c9fc277e9fc9f997e8ec73a36cb26ec Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Mon, 26 Sep 2022 00:30:20 +0200 Subject: [PATCH 1/3] Fixed math problem and transposed idMat4::ToMat3() --- neo/idlib/math/Matrix.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index 437de0f0..c78f1a72 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -976,14 +976,15 @@ ID_INLINE idMat3 idMat4::ToMat3() const { idMat3 m; + // RB - NOTE: idMat3 is transposed because it is column-major m[0][0] = mat[0][0]; - m[0][1] = mat[0][1]; - m[0][2] = mat[0][2]; - m[1][0] = mat[1][0]; + m[0][1] = mat[1][0]; + m[0][2] = mat[2][0]; + m[1][0] = mat[0][1]; m[1][1] = mat[1][1]; - m[1][2] = mat[1][2]; - m[2][0] = mat[2][0]; - m[2][1] = mat[2][1]; + m[1][2] = mat[2][1]; + m[2][0] = mat[0][2]; + m[2][1] = mat[1][2]; m[2][2] = mat[2][2]; return m; From 02941624f918d2fcc66f02098eadf77b2696756a Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Mon, 26 Sep 2022 00:31:47 +0200 Subject: [PATCH 2/3] Repaired glTF2 animations for the Y-Up case --- neo/renderer/Model_gltf.cpp | 37 ++++++++++++++++++++----------------- neo/renderer/Model_gltf.h | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 3f42932d..3ce2fd21 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -48,9 +48,8 @@ idCVar gltf_AnimSampleRate( "gltf_AnimSampleRate", "24", CVAR_SYSTEM | CVAR_INTE static const byte GLMB_VERSION = 101; static const unsigned int GLMB_MAGIC = ( 'M' << 24 ) | ( 'L' << 16 ) | ( 'G' << 8 ) | GLMB_VERSION; static const char* GLTF_SnapshotName = "_GLTF_Snapshot_"; -static const idAngles blenderToDoomAngels = idAngles( 0.0f, 0.0f, 90 ); -//static const idMat4 blenderToDoomTransform( blenderToDoomAngels.ToMat3(), vec3_origin ); -static const idMat4 blenderToDoomTransform = mat4_identity; +static const idMat4 blenderToDoomTransform( idAngles( 0.0f, 0.0f, 90 ).ToMat3(), vec3_origin ); +//static const idMat4 blenderToDoomTransform = mat4_identity; static idRenderModelGLTF* lastMeshFromFile = nullptr; bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh ) @@ -58,34 +57,34 @@ bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh ) return false; } -void idRenderModelGLTF::ProcessNode( gltfNode* modelNode, idMat4 trans, gltfData* data ) +void idRenderModelGLTF::ProcessNode_r( gltfNode* modelNode, idMat4 parentTransform, gltfData* data ) { auto& meshList = data->MeshList(); auto& nodeList = data->NodeList(); gltfData::ResolveNodeMatrix( modelNode ); - idMat4 curTrans = trans * modelNode->matrix; + idMat4 nodeToWorldTransform = parentTransform * modelNode->matrix; if( modelNode->mesh >= 0 ) { gltfMesh* targetMesh = meshList[modelNode->mesh]; - idMat4 newTrans; + idMat4 animTransform; if( !animIds.Num() ) { - newTrans = curTrans; + animTransform = nodeToWorldTransform; } else { - newTrans = mat4_identity; + animTransform = mat4_identity; } for( auto prim : targetMesh->primitives ) { //ConvertFromMeshGltf should only be used for the map, ConvertGltfMeshToModelsurfaces should be used. - auto* mesh = MapPolygonMesh::ConvertFromMeshGltf( prim, data, newTrans ); + auto* mesh = MapPolygonMesh::ConvertFromMeshGltf( prim, data, animTransform * blenderToDoomTransform ); modelSurface_t surf; gltfMaterial* mat = NULL; @@ -138,7 +137,7 @@ void idRenderModelGLTF::ProcessNode( gltfNode* modelNode, idMat4 trans, gltfData for( auto& child : modelNode->children ) { - ProcessNode( nodeList[child], curTrans, data ); + ProcessNode_r( nodeList[child], nodeToWorldTransform, data ); } } @@ -243,7 +242,7 @@ void idRenderModelGLTF::InitFromFile( const char* fileName ) hasAnimations = totalAnims > 0; model_state = hasAnimations ? DM_CACHED : DM_STATIC; - ProcessNode( root, mat4_identity, data ); + ProcessNode_r( root, mat4_identity, data ); if( surfaces.Num() <= 0 ) { @@ -538,7 +537,7 @@ idList GetPose( idList& bones, idJointMat* poseMat ) } idJointQuat& pose = ret[i]; - pose.q = ( trans.ToMat3().Transpose().ToQuat() ); + pose.q = ( trans.ToMat3().ToQuat() ); pose.t = idVec3( trans[0][3], trans[1][3], trans[2][3] ); pose.w = pose.q.CalcW(); } @@ -830,11 +829,15 @@ idFile_Memory* idRenderModelGLTF::GetAnimBin( idStr animName , const ID_TIME_T { if( node->parent == nullptr ) { - q = blenderToDoomAngels.ToQuat() * animBones[i][b].rotation; - if( animBones[i].Num() == 1 ) - { - q = -animBones[i][b].rotation; - } + //q = blenderToDoomAngels.ToQuat() * animBones[i][b].rotation; + + q = blenderToDoomTransform.ToMat3().ToQuat() * animBones[i][b].rotation; + + //if( animBones[i].Num() == 1 ) + //{ + // this is not hit + // q = -animBones[i][b].rotation; + //} } else { diff --git a/neo/renderer/Model_gltf.h b/neo/renderer/Model_gltf.h index a8f2023c..c8a5bf32 100644 --- a/neo/renderer/Model_gltf.h +++ b/neo/renderer/Model_gltf.h @@ -57,7 +57,7 @@ public: static idFile_Memory* GetAnimBin( idStr animName, const ID_TIME_T sourceTimeStamp ); int rootID; private: - void ProcessNode( gltfNode* modelNode, idMat4 trans, gltfData* data ); + void ProcessNode_r( gltfNode* modelNode, idMat4 trans, gltfData* data ); void UpdateSurface( const struct renderEntity_s* ent, const idJointMat* entJoints, const idJointMat* entJointsInverted, modelSurface_t* surf, const modelSurface_t& sourceSurf ); void UpdateMd5Joints(); From 0b677fe752e82f83b2b0ae15905a0530b4a1cb60 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Mon, 26 Sep 2022 10:06:13 +0200 Subject: [PATCH 3/3] Fixed dmap .glb world+entity geom for the Y-Up case --- neo/idlib/MapFile_gltf.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index 70105a94..49c5026b 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -31,9 +31,8 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop // files import as y-up. Use this transform to change the model to z-up. -static const idAngles blenderToDoomAngels = idAngles( 0.0f, 0.0f, 90 ); -//static const idMat4 blenderToDoomTransform( blenderToDoomAngels.ToMat3(), vec3_origin ); -static const idMat4 blenderToDoomTransform = mat4_identity; +static const idMat4 blenderToDoomTransform( idAngles( 0.0f, 0.0f, 90 ).ToMat3(), vec3_origin ); +//static const idMat4 blenderToDoomTransform = mat4_identity; MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* prim, gltfData* _data , const idMat4& transform ) { @@ -55,8 +54,6 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p idFile_Memory idxBin = idFile_Memory( "gltfChunkIndices", ( const char* )( ( data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset ) ), bv->byteLength ); - - for( int i = 0; i < accessor->count; i++ ) { idxBin.Read( ( void* )( &indices[i] ), accessor->typeSize ); @@ -309,7 +306,7 @@ static void ProcessSceneNode_r( idMapEntity* newEntity, gltfNode* node, const id for( auto* prim : data->MeshList()[node->mesh]->primitives ) { - newEntity->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, data, nodeToEntityTransform ) ); + newEntity->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, data, blenderToDoomTransform * nodeToEntityTransform ) ); } } @@ -328,7 +325,7 @@ static void AddMeshesToWorldspawn_r( idMapEntity* entity, gltfNode* node, const { for( auto prim : data->MeshList()[node->mesh]->primitives ) { - entity->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, data, nodeToWorldTransform ) ); + entity->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, data, blenderToDoomTransform * nodeToWorldTransform ) ); } } @@ -364,7 +361,7 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI // account all meshes starting with "worldspawn." or "BSP" in the name if( idStr::Icmpn( node->name, "BSP", 3 ) == 0 || idStr::Icmpn( node->name, "worldspawn.", 11 ) == 0 ) { - AddMeshesToWorldspawn_r( worldspawn, node, blenderToDoomTransform, data ); + AddMeshesToWorldspawn_r( worldspawn, node, mat4_identity, data ); } else { @@ -389,7 +386,7 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI // gather entity transform and bring it into id Tech 4 space gltfData::ResolveNodeMatrix( node ); - idMat4 entityToWorldTransform = blenderToDoomTransform * node->matrix; + idMat4 entityToWorldTransform = node->matrix; idMat4 worldToEntityTransform = entityToWorldTransform.Inverse(); // set entity transform in a way the game and physics code understand it