From 9e4cd947a151126c8d0fd85b79b219edc18db924 Mon Sep 17 00:00:00 2001 From: HarrievG Date: Mon, 20 Jun 2022 01:12:45 +0200 Subject: [PATCH 1/2] - cleanup YUP define - added rotation for entities - models scene can be overriden with cvar --- neo/renderer/Model_gltf.cpp | 48 ++++++++++--------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 05835304..79776bf5 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -35,9 +35,8 @@ If you have questions concerning this license or the applicable additional terms #include "Model_local.h" #include "RenderCommon.h" -#define GLTF_YUP 0 - idCVar gltf_ForceBspMeshTexture( "gltf_ForceBspMeshTexture", "0", CVAR_SYSTEM | CVAR_BOOL, "all world geometry has the same forced texture" ); +idCVar gltf_ModelSceneName( "gltf_ModelSceneName", "models", CVAR_SYSTEM , "Scene to use when loading specific models" ); bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh ) { @@ -128,16 +127,9 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p pos *= trans * axisTransform; -#if GLTF_YUP - // RB: proper glTF2 convention, requires Y-up export option ticked on in Blender - mesh->verts[i].xyz.x = pos.z; - mesh->verts[i].xyz.y = pos.x; - mesh->verts[i].xyz.z = pos.y; -#else mesh->verts[i].xyz.x = pos.x; mesh->verts[i].xyz.y = pos.y; mesh->verts[i].xyz.z = pos.z; -#endif if( attrBv->byteStride ) { @@ -167,16 +159,11 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p } idVec3 normal; -#if GLTF_YUP - // RB: proper glTF2 convention, requires Y-up export option ticked on in Blender - normal.x = vec.z; - normal.y = vec.x; - normal.z = vec.y; -#else + normal.x = vec.x; normal.y = vec.y; normal.z = vec.z; -#endif + normal *= axisTransform; mesh->verts[i].SetNormal( normal ); } @@ -216,16 +203,11 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p } idVec3 tangent; -#if GLTF_YUP - // RB: proper glTF2 convention, requires Y-up export option ticked on in Blender - tangent.x = vec.z; - tangent.y = vec.x; - tangent.z = vec.y; -#else + tangent.x = vec.x; tangent.y = vec.y; tangent.z = vec.z; -#endif + tangent *= axisTransform; mesh->verts[i].SetTangent( tangent ); @@ -307,23 +289,19 @@ void ProcessSceneNode( idMapEntity* newEntity, gltfNode* node, idMat4& trans, gl } #endif idVec3 origin; -#if GLTF_YUP - // RB: proper glTF2 convention, requires Y-up export option ticked on in Blender - origin.x = node->translation.z; - origin.y = node->translation.x; - origin.z = node->translation.y; -#else + origin.x = node->translation.x; origin.y = node->translation.y; origin.z = node->translation.z; -#endif - + // files import as y-up. Use this transform to change the model to z-up. idMat3 rotation = idAngles( 0.0f, 0.0f, 90.0f ).ToMat3( ); idMat4 axisTransform( rotation, vec3_origin ); origin *= axisTransform; newEntity->epairs.Set( "origin", origin.ToString() ); + + newEntity->epairs.Set( "rotation", node->rotation.ToMat3().Transpose().ToString()); } void Map_AddMeshes( idMapEntity* _Entity, gltfNode* _Node, idMat4& _Trans, gltfData* _Data ) @@ -386,6 +364,7 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI return entityCount; } + // not dots allowed in [%s]! // [filename].[%i|%s].[gltf/glb] bool gltfManager::ExtractMeshIdentifier( idStr& filename, int& meshId, idStr& meshName ) @@ -504,8 +483,10 @@ void idRenderModelGLTF::ProcessNode( gltfNode* modelNode, idMat4 trans, gltfData } //constructs a renderModel from a gltfScene node found in the "models" scene of the given gltfFile. +// override with gltf_ModelSceneName // warning : nodeName cannot have dots! //[fileName].[nodeName/nodeId].[gltf/glb] +//If no nodeName/nodeId is given, all primitives active in default scene will be added as surfaces. void idRenderModelGLTF::InitFromFile( const char* fileName ) { int meshID = -1; @@ -520,14 +501,12 @@ void idRenderModelGLTF::InitFromFile( const char* fileName ) { common->FatalError( "multiple GLTF file loading not supported" ); } - gltfParser->Load( gltfFileName ); } else { gltfParser->Load( gltfFileName ); } - timeStamp = fileSystem->GetTimestamp( gltfFileName ); gltfData* data = gltfParser->currentAsset; @@ -549,14 +528,13 @@ void idRenderModelGLTF::InitFromFile( const char* fileName ) } else { - gltfNode *modelNode = data->GetNode( "models", meshName ); + gltfNode *modelNode = data->GetNode( gltf_ModelSceneName.GetString(), meshName ); if ( modelNode ) { ProcessNode( modelNode, mat4_identity, data ); } } - if ( surfaces.Num( ) <= 0 ) { common->Warning( "Couldn't load model: '%s'", name.c_str( ) ); MakeDefaultModel( ); From d0b9d8f8a86418dd4df44ebe9fc6d19d648a7259 Mon Sep 17 00:00:00 2001 From: HarrievG Date: Mon, 20 Jun 2022 22:25:52 +0200 Subject: [PATCH 2/2] astyle --- neo/renderer/Model_gltf.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 79776bf5..431b1eca 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -49,7 +49,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p gltfAccessor* accessor = _data->AccessorList()[prim->indices]; gltfBufferView* bv = _data->BufferViewList()[accessor->bufferView]; gltfData* data = bv->parent; - + // files import as y-up. Use this transform to change the model to z-up. idMat3 rotation = idAngles( 0.0f, 0.0f, 90.0f ).ToMat3( ); idMat4 axisTransform( rotation, vec3_origin ); @@ -301,7 +301,7 @@ void ProcessSceneNode( idMapEntity* newEntity, gltfNode* node, idMat4& trans, gl origin *= axisTransform; newEntity->epairs.Set( "origin", origin.ToString() ); - newEntity->epairs.Set( "rotation", node->rotation.ToMat3().Transpose().ToString()); + newEntity->epairs.Set( "rotation", node->rotation.ToMat3().Transpose().ToString() ); } void Map_AddMeshes( idMapEntity* _Entity, gltfNode* _Node, idMat4& _Trans, gltfData* _Data ) @@ -424,7 +424,7 @@ void idRenderModelGLTF::ProcessNode( gltfNode* modelNode, idMat4 trans, gltfData gltfData::ResolveNodeMatrix( modelNode ); idMat4 curTrans = trans * modelNode->matrix; - gltfMesh *targetMesh = meshList[modelNode->mesh]; + gltfMesh* targetMesh = meshList[modelNode->mesh]; for( auto prim : targetMesh->primitives ) { @@ -483,7 +483,7 @@ void idRenderModelGLTF::ProcessNode( gltfNode* modelNode, idMat4 trans, gltfData } //constructs a renderModel from a gltfScene node found in the "models" scene of the given gltfFile. -// override with gltf_ModelSceneName +// override with gltf_ModelSceneName // warning : nodeName cannot have dots! //[fileName].[nodeName/nodeId].[gltf/glb] //If no nodeName/nodeId is given, all primitives active in default scene will be added as surfaces. @@ -502,7 +502,7 @@ void idRenderModelGLTF::InitFromFile( const char* fileName ) common->FatalError( "multiple GLTF file loading not supported" ); } } - else + else { gltfParser->Load( gltfFileName ); } @@ -511,31 +511,32 @@ void idRenderModelGLTF::InitFromFile( const char* fileName ) gltfData* data = gltfParser->currentAsset; bounds.Clear(); - + int sceneId = data->DefaultScene(); assert( sceneId >= 0 ); - if ( !meshName[0] ) + if( !meshName[0] ) { - auto & nodeList = data->NodeList(); + auto& nodeList = data->NodeList(); for( auto& nodeID : data->SceneList()[sceneId]->nodes ) { - gltfNode *modelNode = nodeList[nodeID]; - assert ( modelNode ); + gltfNode* modelNode = nodeList[nodeID]; + assert( modelNode ); ProcessNode( modelNode, mat4_identity, data ); } } else { - gltfNode *modelNode = data->GetNode( gltf_ModelSceneName.GetString(), meshName ); - if ( modelNode ) + gltfNode* modelNode = data->GetNode( gltf_ModelSceneName.GetString(), meshName ); + if( modelNode ) { ProcessNode( modelNode, mat4_identity, data ); } } - if ( surfaces.Num( ) <= 0 ) { + if( surfaces.Num( ) <= 0 ) + { common->Warning( "Couldn't load model: '%s'", name.c_str( ) ); MakeDefaultModel( ); return;