mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-15 07:00:58 +00:00
Merge remote-tracking branch 'HarrievG/679-gltf-map-support2' into 679-gltf-map-support2
This commit is contained in:
commit
6e3a048833
1 changed files with 12 additions and 34 deletions
|
@ -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,16 +289,10 @@ 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( );
|
||||
|
@ -324,6 +300,8 @@ 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() );
|
||||
}
|
||||
|
||||
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( ) );
|
||||
|
|
Loading…
Reference in a new issue