@babylonjs/serializers 8.30.2 → 8.30.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ import { Engine } from "@babylonjs/core/Engines/engine.js";
9
9
  import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
10
10
  import { GLTFMaterialExporter } from "./glTFMaterialExporter.js";
11
11
  import { GLTFData } from "./glTFData.js";
12
- import { ConvertToRightHandedPosition, ConvertToRightHandedRotation, DataArrayToUint8Array, GetAccessorType, GetAttributeType, GetMinMax, GetPrimitiveMode, IsTriangleFillMode, IsChildCollapsible, FloatsNeed16BitInteger, IsStandardVertexAttribute, IndicesArrayToTypedArray, GetVertexBufferInfo, CollapseChildIntoParent, Rotate180Y, DefaultTranslation, DefaultScale, DefaultRotation, ConvertToRightHandedTransformMatrix, } from "./glTFUtilities.js";
12
+ import { ConvertToRightHandedPosition, ConvertToRightHandedRotation, DataArrayToUint8Array, GetAccessorType, GetAttributeType, GetMinMax, GetPrimitiveMode, IsTriangleFillMode, IsChildCollapsible, FloatsNeed16BitInteger, IsStandardVertexAttribute, IndicesArrayToTypedSubarray, GetVertexBufferInfo, CollapseChildIntoParent, Rotate180Y, DefaultTranslation, DefaultScale, DefaultRotation, ConvertToRightHandedTransformMatrix, } from "./glTFUtilities.js";
13
13
  import { IsNoopNode } from "../../exportUtils.js";
14
14
  import { BufferManager } from "./bufferManager.js";
15
15
  import { Camera } from "@babylonjs/core/Cameras/camera.js";
@@ -499,14 +499,26 @@ export class GLTFExporter {
499
499
  }
500
500
  }
501
501
  _setCameraTransformation(node, babylonCamera, convertToRightHanded) {
502
- if (!babylonCamera.position.equalsWithEpsilon(DefaultTranslation, Epsilon)) {
503
- const translation = TmpVectors.Vector3[0].copyFrom(babylonCamera.position);
502
+ // Camera types store rotation differently (e.g., ArcRotateCamera uses alpha/beta, others use rotationQuaternion).
503
+ // Extract the transform from the world matrix instead of handling each case separately.
504
+ const translation = TmpVectors.Vector3[0];
505
+ const rotationQuaternion = TmpVectors.Quaternion[0];
506
+ const cameraWorldMatrix = babylonCamera.getWorldMatrix();
507
+ if (babylonCamera.parent) {
508
+ // Camera.getWorldMatrix returns global coordinates. GLTF node must use local coordinates. If camera has parent we need to use local translation/rotation.
509
+ const parentInvWorldMatrix = babylonCamera.parent.getWorldMatrix().invertToRef(TmpVectors.Matrix[0]);
510
+ const cameraLocal = cameraWorldMatrix.multiplyToRef(parentInvWorldMatrix, TmpVectors.Matrix[1]);
511
+ cameraLocal.decompose(undefined, rotationQuaternion, translation);
512
+ }
513
+ else {
514
+ cameraWorldMatrix.decompose(undefined, rotationQuaternion, translation);
515
+ }
516
+ if (!translation.equalsWithEpsilon(DefaultTranslation, Epsilon)) {
504
517
  if (convertToRightHanded) {
505
518
  ConvertToRightHandedPosition(translation);
506
519
  }
507
520
  node.translation = translation.asArray();
508
521
  }
509
- const rotationQuaternion = babylonCamera.rotationQuaternion || Quaternion.FromEulerAngles(babylonCamera.rotation.x, babylonCamera.rotation.y, babylonCamera.rotation.z);
510
522
  if (convertToRightHanded) {
511
523
  ConvertToRightHandedRotation(rotationQuaternion);
512
524
  }
@@ -1030,7 +1042,7 @@ export class GLTFExporter {
1030
1042
  if (indicesToExport) {
1031
1043
  let accessorIndex = state.getIndicesAccessor(indices, start, count, offset, flip);
1032
1044
  if (accessorIndex === undefined) {
1033
- const bytes = IndicesArrayToTypedArray(indicesToExport, 0, count, is32Bits);
1045
+ const bytes = IndicesArrayToTypedSubarray(indicesToExport, start, count, is32Bits);
1034
1046
  const bufferView = this._bufferManager.createBufferView(bytes);
1035
1047
  const componentType = is32Bits ? 5125 /* AccessorComponentType.UNSIGNED_INT */ : 5123 /* AccessorComponentType.UNSIGNED_SHORT */;
1036
1048
  this._accessors.push(this._bufferManager.createAccessor(bufferView, "SCALAR" /* AccessorType.SCALAR */, componentType, count, 0));