mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-06-06 08:42:35 +00:00
Refactored light direction calculation.
This commit is contained in:
@@ -335,29 +335,13 @@ namespace
|
|||||||
m_bsp->lights[lightIndex].pos = vec3_t{transformedPosition.x(), transformedPosition.y(), transformedPosition.z()};
|
m_bsp->lights[lightIndex].pos = vec3_t{transformedPosition.x(), transformedPosition.y(), transformedPosition.z()};
|
||||||
RhcToLhcCoordinates(m_bsp->lights[lightIndex].pos.v);
|
RhcToLhcCoordinates(m_bsp->lights[lightIndex].pos.v);
|
||||||
|
|
||||||
// BO2 uses -Z up and the default light direction is straight down
|
// GLTF spec uses +Y up and the default light direction is straight down
|
||||||
Eigen::Vector3f defaultDirection(0.0f, 0.0f, 1.0f);
|
Eigen::Vector3f defaultDirection(0.0f, -1.0f, 0.0f);
|
||||||
Eigen::Vector3f outputDirection;
|
Eigen::Affine3f affineTransform(nodeMatrix);
|
||||||
|
Eigen::Matrix3f rotationMatrix = affineTransform.rotation();
|
||||||
if (node.rotation)
|
Eigen::Vector3f outputDirection = rotationMatrix * defaultDirection;
|
||||||
{
|
|
||||||
Eigen::Quaternionf rotationQuat(
|
|
||||||
(*node.rotation)[3], (*node.rotation)[0], (*node.rotation)[1], (*node.rotation)[2]); // GLTF is XYZW, Eigen is WXYZ
|
|
||||||
outputDirection = rotationQuat * defaultDirection;
|
|
||||||
}
|
|
||||||
else if (node.matrix)
|
|
||||||
{
|
|
||||||
con::error("matrix rotation unimpelemted");
|
|
||||||
assert(false);
|
|
||||||
// Eigen::Quaternionf rotationQuat;
|
|
||||||
// rotationQuat = nodeMatrix;
|
|
||||||
// outputDirection = rotationQuat * defaultDirection;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
outputDirection = defaultDirection;
|
|
||||||
outputDirection.normalize();
|
outputDirection.normalize();
|
||||||
m_bsp->lights[lightIndex].direction = vec3_t{outputDirection.x(), outputDirection.y(), outputDirection.z()};
|
m_bsp->lights[lightIndex].direction = vec3_t{outputDirection.x(), outputDirection.y(), outputDirection.z()};
|
||||||
RhcToLhcCoordinates(m_bsp->lights[lightIndex].direction.v);
|
|
||||||
|
|
||||||
m_bsp->lights[lightIndex].hasPosBeenSet = true;
|
m_bsp->lights[lightIndex].hasPosBeenSet = true;
|
||||||
|
|
||||||
@@ -399,6 +383,8 @@ namespace
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<unsigned> GetRootNodes(const JsonRoot& jRoot)
|
static std::vector<unsigned> GetRootNodes(const JsonRoot& jRoot)
|
||||||
@@ -533,12 +519,12 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!jsLight.intensity)
|
if (!jsLight.intensity)
|
||||||
light.intensity = 100000.0f; // adjusted from GLTF spec to better match BO2
|
light.intensity = 100000.0f; // adjusted from spec to better match BO2
|
||||||
else
|
else
|
||||||
light.intensity = *jsLight.intensity;
|
light.intensity = *jsLight.intensity;
|
||||||
|
|
||||||
if (!jsLight.range)
|
if (!jsLight.range)
|
||||||
light.range = 1000.0f; // adjusted from GLTF spec to better match BO2
|
light.range = 1000.0f; // adjusted from spec to better match BO2
|
||||||
else
|
else
|
||||||
light.range = *jsLight.range;
|
light.range = *jsLight.range;
|
||||||
|
|
||||||
@@ -553,15 +539,15 @@ namespace
|
|||||||
else // JsonPunctualLightType::SPOT
|
else // JsonPunctualLightType::SPOT
|
||||||
{
|
{
|
||||||
light.type = LIGHT_TYPE_SPOT;
|
light.type = LIGHT_TYPE_SPOT;
|
||||||
assert(jsLight.spot);
|
|
||||||
|
|
||||||
|
assert(jsLight.spot);
|
||||||
if (!jsLight.spot->innerConeAngle)
|
if (!jsLight.spot->innerConeAngle)
|
||||||
light.innerConeAngle = 0.0f;
|
light.innerConeAngle = 0.0f;
|
||||||
else
|
else
|
||||||
light.innerConeAngle = *jsLight.spot->innerConeAngle;
|
light.innerConeAngle = *jsLight.spot->innerConeAngle;
|
||||||
|
|
||||||
if (!jsLight.spot->outerConeAngle)
|
if (!jsLight.spot->outerConeAngle)
|
||||||
light.outerConeAngle = 3.14159265359f / 4.0f; /// 45 degrees
|
light.outerConeAngle = 3.14159265359f / 4.0f; /// spec of 45 degrees
|
||||||
else
|
else
|
||||||
light.outerConeAngle = *jsLight.spot->outerConeAngle;
|
light.outerConeAngle = *jsLight.spot->outerConeAngle;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user