diff --git a/src/ObjLoading/Game/T6/BSP/BSP.h b/src/ObjLoading/Game/T6/BSP/BSP.h index 840c4122..5a571827 100644 --- a/src/ObjLoading/Game/T6/BSP/BSP.h +++ b/src/ObjLoading/Game/T6/BSP/BSP.h @@ -24,6 +24,8 @@ namespace BSP vec4_t color; vec2_t texCoord; vec3_t normal; + vec3_t tangent; + vec3_t binormal; }; struct BSPMaterial diff --git a/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp b/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp index 210d1646..377c148c 100644 --- a/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp +++ b/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp @@ -7,6 +7,7 @@ #include "XModel/Gltf/Internal/GltfBuffer.h" #include "XModel/Gltf/Internal/GltfBufferView.h" #include "XModel/Gltf/JsonGltf.h" +#include "XModel/Tangentspace.h" #pragma warning(push, 0) #include @@ -182,9 +183,9 @@ namespace Eigen::Vector3d scale(localScale[0], localScale[1], localScale[2]); Eigen::Affine3d transform = Eigen::Affine3d::Identity(); - transform.translate(translation); - transform.rotate(rotation); transform.scale(scale); + transform.rotate(rotation); + transform.translate(translation); return transform.matrix(); } @@ -293,6 +294,22 @@ namespace m_bsp->gfxWorld.vertices.emplace_back(vertex); } + // generate tangent and binormal vectors + tangent_space::VertexData vertexData{ + &m_bsp->gfxWorld.vertices[surface.indexOfFirstVertex].pos, + sizeof(BSPVertex), + &m_bsp->gfxWorld.vertices[surface.indexOfFirstVertex].normal, + sizeof(BSPVertex), + &m_bsp->gfxWorld.vertices[surface.indexOfFirstVertex].texCoord, + sizeof(BSPVertex), + &m_bsp->gfxWorld.vertices[surface.indexOfFirstVertex].tangent, + sizeof(BSPVertex), + &m_bsp->gfxWorld.vertices[surface.indexOfFirstVertex].binormal, + sizeof(BSPVertex), + &m_bsp->gfxWorld.indices[surface.indexOfFirstIndex], + }; + tangent_space::CalculateTangentSpace(vertexData, faceCount, vertexCount); + return vertexOffset; } diff --git a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp index 0ec1963e..c42b525b 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp @@ -27,11 +27,10 @@ namespace BSP gfxVertex->color.packed = pack32::Vec4PackGfxColor(bspVertex.color.v); gfxVertex->texCoord.packed = pack32::Vec2PackTexCoordsUV(bspVertex.texCoord.v); gfxVertex->normal.packed = pack32::Vec3PackUnitVecThirdBased(bspVertex.normal.v); - // gfxVertex->tangent.packed = pack32::Vec3PackUnitVecThirdBased(bspVertex.tangent.v); - gfxVertex->tangent.packed = 0; + gfxVertex->tangent.packed = pack32::Vec3PackUnitVecThirdBased(bspVertex.tangent.v); + gfxVertex->binormalSign = bspVertex.binormal.v[0] > 0.0f ? 1.0f : -1.0f; - // unimplemented variables - gfxVertex->binormalSign = 0.0f; + // lightmap isn't implemented currently gfxVertex->lmapCoord.packed = 0; } gfxWorld->draw.vd0.data = reinterpret_cast(vertexBuffer);