mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-06-06 08:42:35 +00:00
Added tangent and binormal calculation, corrected scale, rotate and translate order of operations.
This commit is contained in:
@@ -24,6 +24,8 @@ namespace BSP
|
|||||||
vec4_t color;
|
vec4_t color;
|
||||||
vec2_t texCoord;
|
vec2_t texCoord;
|
||||||
vec3_t normal;
|
vec3_t normal;
|
||||||
|
vec3_t tangent;
|
||||||
|
vec3_t binormal;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BSPMaterial
|
struct BSPMaterial
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "XModel/Gltf/Internal/GltfBuffer.h"
|
#include "XModel/Gltf/Internal/GltfBuffer.h"
|
||||||
#include "XModel/Gltf/Internal/GltfBufferView.h"
|
#include "XModel/Gltf/Internal/GltfBufferView.h"
|
||||||
#include "XModel/Gltf/JsonGltf.h"
|
#include "XModel/Gltf/JsonGltf.h"
|
||||||
|
#include "XModel/Tangentspace.h"
|
||||||
|
|
||||||
#pragma warning(push, 0)
|
#pragma warning(push, 0)
|
||||||
#include <Eigen>
|
#include <Eigen>
|
||||||
@@ -182,9 +183,9 @@ namespace
|
|||||||
Eigen::Vector3d scale(localScale[0], localScale[1], localScale[2]);
|
Eigen::Vector3d scale(localScale[0], localScale[1], localScale[2]);
|
||||||
|
|
||||||
Eigen::Affine3d transform = Eigen::Affine3d::Identity();
|
Eigen::Affine3d transform = Eigen::Affine3d::Identity();
|
||||||
transform.translate(translation);
|
|
||||||
transform.rotate(rotation);
|
|
||||||
transform.scale(scale);
|
transform.scale(scale);
|
||||||
|
transform.rotate(rotation);
|
||||||
|
transform.translate(translation);
|
||||||
|
|
||||||
return transform.matrix();
|
return transform.matrix();
|
||||||
}
|
}
|
||||||
@@ -293,6 +294,22 @@ namespace
|
|||||||
m_bsp->gfxWorld.vertices.emplace_back(vertex);
|
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;
|
return vertexOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,10 @@ namespace BSP
|
|||||||
gfxVertex->color.packed = pack32::Vec4PackGfxColor(bspVertex.color.v);
|
gfxVertex->color.packed = pack32::Vec4PackGfxColor(bspVertex.color.v);
|
||||||
gfxVertex->texCoord.packed = pack32::Vec2PackTexCoordsUV(bspVertex.texCoord.v);
|
gfxVertex->texCoord.packed = pack32::Vec2PackTexCoordsUV(bspVertex.texCoord.v);
|
||||||
gfxVertex->normal.packed = pack32::Vec3PackUnitVecThirdBased(bspVertex.normal.v);
|
gfxVertex->normal.packed = pack32::Vec3PackUnitVecThirdBased(bspVertex.normal.v);
|
||||||
// gfxVertex->tangent.packed = pack32::Vec3PackUnitVecThirdBased(bspVertex.tangent.v);
|
gfxVertex->tangent.packed = pack32::Vec3PackUnitVecThirdBased(bspVertex.tangent.v);
|
||||||
gfxVertex->tangent.packed = 0;
|
gfxVertex->binormalSign = bspVertex.binormal.v[0] > 0.0f ? 1.0f : -1.0f;
|
||||||
|
|
||||||
// unimplemented variables
|
// lightmap isn't implemented currently
|
||||||
gfxVertex->binormalSign = 0.0f;
|
|
||||||
gfxVertex->lmapCoord.packed = 0;
|
gfxVertex->lmapCoord.packed = 0;
|
||||||
}
|
}
|
||||||
gfxWorld->draw.vd0.data = reinterpret_cast<char*>(vertexBuffer);
|
gfxWorld->draw.vd0.data = reinterpret_cast<char*>(vertexBuffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user