mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 22:50:45 +00:00
Repaired glTF2 animations for the Y-Up case
This commit is contained in:
parent
64cd34412c
commit
02941624f9
2 changed files with 21 additions and 18 deletions
|
@ -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<idJointQuat> GetPose( idList<gltfNode>& 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
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue