mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-26 05:37:46 +00:00
Fix bitangents being slightly off when importing
This commit is contained in:
parent
3820b77ace
commit
f747033aac
1 changed files with 4 additions and 4 deletions
|
@ -144,14 +144,14 @@ void importModel(physis_MDL &existingModel, const QString &filename)
|
||||||
// calculate binormal, because glTF won't give us those!!
|
// calculate binormal, because glTF won't give us those!!
|
||||||
const glm::vec3 normal = glm::vec3(vertex.normal[0], vertex.normal[1], vertex.normal[2]);
|
const glm::vec3 normal = glm::vec3(vertex.normal[0], vertex.normal[1], vertex.normal[2]);
|
||||||
const glm::vec4 tangent = *tangent1Data;
|
const glm::vec4 tangent = *tangent1Data;
|
||||||
const glm::vec3 bitangent = glm::cross(normal, glm::vec3(tangent)) * tangent.w;
|
const glm::vec3 bitangent = glm::normalize(glm::cross(normal, glm::vec3(tangent)) * tangent.w);
|
||||||
|
|
||||||
const float handedness = glm::dot(glm::cross(glm::vec3(tangent), bitangent), normal) > 0 ? 1 : -1;
|
const float handedness = glm::dot(glm::cross(glm::vec3(tangent), bitangent), normal) > 0 ? 1 : -1;
|
||||||
|
|
||||||
// In a cruel twist of fate, Tangent1 is actually the **BINORMAL** and not the tangent data. Square Enix is AMAZING.
|
// In a cruel twist of fate, Tangent1 is actually the **BINORMAL** and not the tangent data. Square Enix is AMAZING.
|
||||||
vertex.bitangent[0] = bitangent.x;
|
vertex.bitangent[0] = bitangent.x * handedness;
|
||||||
vertex.bitangent[1] = bitangent.y;
|
vertex.bitangent[1] = bitangent.y * handedness;
|
||||||
vertex.bitangent[2] = bitangent.z;
|
vertex.bitangent[2] = bitangent.z * handedness;
|
||||||
vertex.bitangent[3] = handedness;
|
vertex.bitangent[3] = handedness;
|
||||||
|
|
||||||
if (colorAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) {
|
if (colorAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue