diff --git a/packages/dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts b/packages/dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts index 121208f334c..d95aa6d7825 100644 --- a/packages/dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts +++ b/packages/dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts @@ -107,17 +107,15 @@ export class KHR_lights_punctual implements IGLTFExporterExtensionV2 { node.translation = translation.asArray(); } - // Babylon lights have "constant" rotation and variable direction, while - // glTF lights have variable rotation and constant direction. Therefore, - // compute a quaternion that aligns the Babylon light's direction with glTF's constant one. + // Represent the Babylon light's direction as a quaternion + // relative to glTF lights' forward direction, (0, 0, -1). if (lightType !== KHRLightsPunctual_LightType.POINT) { const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]); if (convertToRightHanded) { ConvertToRightHandedPosition(direction); } - const angle = Math.acos(Vector3.Dot(LIGHTDIRECTION, direction)); - const axis = Vector3.Cross(LIGHTDIRECTION, direction); - const lightRotationQuaternion = Quaternion.RotationAxisToRef(axis, angle, TmpVectors.Quaternion[0]); + + const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]); if (!Quaternion.IsIdentity(lightRotationQuaternion)) { node.rotation = lightRotationQuaternion.asArray(); } diff --git a/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightLH.png b/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightLH.png index c7aea2bc650..487e06dd32f 100644 Binary files a/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightLH.png and b/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightLH.png differ diff --git a/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightRH.png b/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightRH.png index a3a149b1d3b..0b623e37986 100644 Binary files a/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightRH.png and b/packages/tools/tests/test/visualization/ReferenceImages/glTFSerializerKHRPunctualLightRH.png differ diff --git a/packages/tools/tests/test/visualization/config.json b/packages/tools/tests/test/visualization/config.json index 03d0d4f5280..77f62e02b5e 100644 --- a/packages/tools/tests/test/visualization/config.json +++ b/packages/tools/tests/test/visualization/config.json @@ -1048,13 +1048,13 @@ }, { "title": "GLTF Serializer KHR punctual light, left-handed", - "playgroundId": "#FLXW8B#25", + "playgroundId": "#FLXW8B#27", "replace": "//options//, roundtrip = true; useRightHandedSystem = false;", "referenceImage": "glTFSerializerKHRPunctualLightLH.png" }, { "title": "GLTF Serializer KHR punctual light, right-handed", - "playgroundId": "#FLXW8B#25", + "playgroundId": "#FLXW8B#27", "replace": "//options//, roundtrip = true; useRightHandedSystem = true;", "referenceImage": "glTFSerializerKHRPunctualLightRH.png" },