diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index 49c5026b..cb4787a7 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -164,6 +164,10 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p normal.z = vec.z; normal *= transform; + + // renormalize because previous transforms may contain scale operations + normal.Normalize(); + mesh->verts[i].SetNormal( normal ); } @@ -208,6 +212,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p tangent.z = vec.z; tangent *= transform; + tangent.Normalize(); mesh->verts[i].SetTangent( tangent ); mesh->verts[i].SetBiTangentSign( vec.w ); diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 3ce2fd21..624393f9 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -70,21 +70,10 @@ void idRenderModelGLTF::ProcessNode_r( gltfNode* modelNode, idMat4 parentTransfo { gltfMesh* targetMesh = meshList[modelNode->mesh]; - idMat4 animTransform; - - if( !animIds.Num() ) - { - animTransform = nodeToWorldTransform; - } - else - { - 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, animTransform * blenderToDoomTransform ); + auto* mesh = MapPolygonMesh::ConvertFromMeshGltf( prim, data, blenderToDoomTransform * nodeToWorldTransform ); modelSurface_t surf; gltfMaterial* mat = NULL; @@ -833,11 +822,11 @@ idFile_Memory* idRenderModelGLTF::GetAnimBin( idStr animName , const ID_TIME_T q = blenderToDoomTransform.ToMat3().ToQuat() * animBones[i][b].rotation; - //if( animBones[i].Num() == 1 ) - //{ - // this is not hit - // q = -animBones[i][b].rotation; - //} + if( animBones[i].Num() == 1 ) + { + // this is only hit for single bone or boneless (root is generated!) animations + q = blenderToDoomTransform.ToMat3().ToQuat() * -animBones[i][b].rotation; + } } else { diff --git a/neo/tools/compilers/dmap/dmap.cpp b/neo/tools/compilers/dmap/dmap.cpp index 1faeb6d7..cf88fe08 100644 --- a/neo/tools/compilers/dmap/dmap.cpp +++ b/neo/tools/compilers/dmap/dmap.cpp @@ -202,6 +202,7 @@ void ResetDmapGlobals() dmapGlobals.mapLights.Clear(); dmapGlobals.verbose = false; dmapGlobals.glview = false; + dmapGlobals.asciiTree = false; dmapGlobals.noOptimize = false; dmapGlobals.verboseentities = false; dmapGlobals.noCurves = false; @@ -271,6 +272,10 @@ void Dmap( const idCmdArgs& args ) { dmapGlobals.glview = true; } + else if( !idStr::Icmp( s, "asciiTree" ) ) + { + dmapGlobals.asciiTree = true; + } else if( !idStr::Icmp( s, "v" ) ) { common->Printf( "verbose = true\n" ); diff --git a/neo/tools/compilers/dmap/dmap.h b/neo/tools/compilers/dmap/dmap.h index d92cbb2f..491c1127 100644 --- a/neo/tools/compilers/dmap/dmap.h +++ b/neo/tools/compilers/dmap/dmap.h @@ -279,6 +279,7 @@ typedef struct bool verbose; bool glview; + bool asciiTree; // BSP tree visualization in the .proc file bool noOptimize; bool verboseentities; bool noCurves; diff --git a/neo/tools/compilers/dmap/output.cpp b/neo/tools/compilers/dmap/output.cpp index 38d69bf1..3a3a3001 100644 --- a/neo/tools/compilers/dmap/output.cpp +++ b/neo/tools/compilers/dmap/output.cpp @@ -358,7 +358,7 @@ static void WriteUTriangles( idFile* procFile, const srfTriangles_t* uTris, cons } // RB begin -static void WriteObjTriangles( idFile* objFile, const srfTriangles_t* uTris, const idVec3& offsetOrigin, const char* materialName ) +static void WriteObjTriangles( idFile* objFile, const srfTriangles_t* uTris, const idMat4& entityToWorldTransform, const char* materialName ) { int col; int i; @@ -376,9 +376,14 @@ static void WriteObjTriangles( idFile* objFile, const srfTriangles_t* uTris, con dv = &uTris->verts[i]; - vec[0] = dv->xyz[0] - offsetOrigin.x; - vec[1] = dv->xyz[1] - offsetOrigin.y; - vec[2] = dv->xyz[2] - offsetOrigin.z; + //vec[0] = dv->xyz[0] - offsetOrigin.x; + //vec[1] = dv->xyz[1] - offsetOrigin.y; + //vec[2] = dv->xyz[2] - offsetOrigin.z; + + idVec3 pos = ( entityToWorldTransform * idVec4( dv->xyz[0], dv->xyz[1], dv->xyz[2], 1 ) ).ToVec3(); + vec[0] = pos.x; + vec[1] = pos.y; + vec[2] = pos.z; idVec2 st = dv->GetTexCoord(); vec[3] = st.x; @@ -577,6 +582,8 @@ static void WriteOutputSurfaces( int entityNum, int areaNum, idFile* procFile, i procFile->WriteFloatString( "\"%s\" ", ambient->material->GetName() ); uTri = ShareMapTriVerts( ambient ); + idStrStatic<256> matName( ambient->material->GetName() ); + FreeTriList( ambient ); CleanupUTriangles( uTri ); WriteUTriangles( procFile, uTri, entity->originOffset ); @@ -584,10 +591,54 @@ static void WriteOutputSurfaces( int entityNum, int areaNum, idFile* procFile, i // RB if( objFile ) { - WriteObjTriangles( objFile, uTri, entity->originOffset, ambient->material->GetName() ); - } + idMat4 entityToWorldTransform( mat3_identity, entity->originOffset ); - FreeTriList( ambient ); + if( entityNum != 0 ) + { + idVec3 origin; + origin.Zero(); + + idMat3 rot; + rot.Identity(); + + origin = entity->epairs.GetVector( "origin", "0 0 0" ); + + if( !entity->epairs.GetMatrix( "rotation", "1 0 0 0 1 0 0 0 1", rot ) ) + { + idAngles angles; + + if( entity->epairs.GetAngles( "angles", "0 0 0", angles ) ) + { + if( angles.pitch != 0.0f || angles.yaw != 0.0f || angles.roll != 0.0f ) + { + rot = angles.ToMat3(); + } + else + { + rot.Identity(); + } + } + else + { + float angle = entity->epairs.GetFloat( "angle" ); + if( angle != 0.0f ) + { + rot = idAngles( 0.0f, angle, 0.0f ).ToMat3(); + } + else + { + rot.Identity(); + } + } + } + + idMat4 transform( rot, origin ); + entityToWorldTransform = transform; + } + + WriteObjTriangles( objFile, uTri, entityToWorldTransform, matName.c_str() ); + } + // RB end R_FreeStaticTriSurf( uTri ); @@ -796,7 +847,7 @@ static void WriteOutputNodes( node_t* node, idFile* procFile ) procFile->WriteFloatString( "/* negative child numbers are areas: (-1-child) */\n" ); // RB: draw an extra ASCII BSP tree visualization for YouTube tutorial - if( dmapGlobals.glview ) + if( dmapGlobals.asciiTree ) { WriteVisualBSPTree( node, procFile ); }