@babylonjs/serializers 7.44.0 → 7.45.0

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.
Files changed (34) hide show
  1. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +3 -3
  2. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +10 -42
  3. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  4. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +32 -0
  5. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +136 -0
  6. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -0
  7. package/glTF/2.0/Extensions/index.d.ts +1 -0
  8. package/glTF/2.0/Extensions/index.js +1 -0
  9. package/glTF/2.0/Extensions/index.js.map +1 -1
  10. package/glTF/2.0/bufferManager.d.ts +68 -0
  11. package/glTF/2.0/bufferManager.js +152 -0
  12. package/glTF/2.0/bufferManager.js.map +1 -0
  13. package/glTF/2.0/dataWriter.d.ts +5 -3
  14. package/glTF/2.0/dataWriter.js +30 -12
  15. package/glTF/2.0/dataWriter.js.map +1 -1
  16. package/glTF/2.0/glTFAnimation.d.ts +7 -7
  17. package/glTF/2.0/glTFAnimation.js +30 -51
  18. package/glTF/2.0/glTFAnimation.js.map +1 -1
  19. package/glTF/2.0/glTFExporter.d.ts +5 -4
  20. package/glTF/2.0/glTFExporter.js +89 -137
  21. package/glTF/2.0/glTFExporter.js.map +1 -1
  22. package/glTF/2.0/glTFExporterExtension.d.ts +14 -10
  23. package/glTF/2.0/glTFExporterExtension.js.map +1 -1
  24. package/glTF/2.0/glTFMaterialExporter.js +25 -15
  25. package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
  26. package/glTF/2.0/glTFMorphTargetsUtilities.d.ts +2 -2
  27. package/glTF/2.0/glTFMorphTargetsUtilities.js +23 -25
  28. package/glTF/2.0/glTFMorphTargetsUtilities.js.map +1 -1
  29. package/glTF/2.0/glTFSerializer.d.ts +8 -0
  30. package/glTF/2.0/glTFSerializer.js.map +1 -1
  31. package/glTF/2.0/glTFUtilities.d.ts +11 -27
  32. package/glTF/2.0/glTFUtilities.js +17 -49
  33. package/glTF/2.0/glTFUtilities.js.map +1 -1
  34. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferManager.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/bufferManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAQ1C,SAAS,uBAAuB,CAAC,UAAkB;IAC/C,IAAI,UAAU,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACnC,IAAI,UAAU,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACnC,OAAO,CAAC,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACI;;WAEG;QACK,sBAAiB,GAAwC,IAAI,GAAG,EAAkC,CAAC;QAE3G;;WAEG;QACK,4BAAuB,GAAgD,IAAI,GAAG,EAA0C,CAAC;QAEjI;;WAEG;QACK,0BAAqB,GAAgC,IAAI,GAAG,EAA0B,CAAC;IAoJnG,CAAC;IAlJG;;;;OAIG;IACI,cAAc,CAAC,WAA0B;QAC5C,wEAAwE;QACxE,IAAI,eAAe,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACpC,eAAe,IAAI,IAAI,CAAC,UAAU,CAAC;QACvC,CAAC,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC;QAEnD,4EAA4E;QAC5E,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC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,4EAA4E;gBAC5E,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;oBACpC,OAAO,QAAQ,CAAC,UAAU,CAAC;gBAC/B,CAAC;gBACD,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChD,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAEM,aAAa,CAAC,QAAmB;QACpC,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5D,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACnC,OAAO,UAAW,CAAC;IACvB,CAAC;IAEM,2BAA2B,CAAC,UAAuB;QACtD,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACjG,OAAO,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;IACzD,CAAC;IAEM,OAAO,CAAC,UAAuB;QAClC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;IACnD,CAAC;IAEO,iBAAiB,CAAC,UAAwB;QAC9C,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,cAAc,UAAU,8BAA8B,CAAC,CAAC;QAC5E,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { TypedArray } from \"core/types\";\nimport type { AccessorComponentType, AccessorType, IAccessor, IBufferView } from \"babylonjs-gltf2interface\";\nimport { DataWriter } from \"./dataWriter\";\n\ntype TypedArrayForglTF = Exclude<TypedArray, Float64Array | BigInt64Array | BigUint64Array>;\n\ninterface IPropertyWithBufferView {\n bufferView?: number;\n}\n\nfunction getHighestByteAlignment(byteLength: number): number {\n if (byteLength % 4 === 0) return 4;\n if (byteLength % 2 === 0) return 2;\n return 1;\n}\n\n/**\n * Utility class to centralize the management of binary data, bufferViews, and the objects that reference them.\n * @internal\n */\nexport class BufferManager {\n /**\n * Maps a bufferView to its data\n */\n private _bufferViewToData: Map<IBufferView, TypedArrayForglTF> = new Map<IBufferView, TypedArrayForglTF>();\n\n /**\n * Maps a bufferView to glTF objects that reference it via a \"bufferView\" property (e.g. accessors, images)\n */\n private _bufferViewToProperties: Map<IBufferView, IPropertyWithBufferView[]> = new Map<IBufferView, IPropertyWithBufferView[]>();\n\n /**\n * Maps an accessor to its bufferView\n */\n private _accessorToBufferView: Map<IAccessor, IBufferView> = new Map<IAccessor, IBufferView>();\n\n /**\n * Generates a binary buffer from the stored bufferViews. Also populates the bufferViews list.\n * @param bufferViews The list of bufferViews to be populated while writing the binary\n * @returns The binary buffer\n */\n public generateBinary(bufferViews: IBufferView[]): Uint8Array {\n // Construct a DataWriter with the total byte length to prevent resizing\n let totalByteLength = 0;\n this._bufferViewToData.forEach((data) => {\n totalByteLength += data.byteLength;\n });\n const dataWriter = new DataWriter(totalByteLength);\n\n // Order the bufferViews in descending order of their alignment requirements\n const orderedBufferViews = Array.from(this._bufferViewToData.keys()).sort((a, b) => getHighestByteAlignment(b.byteLength) - getHighestByteAlignment(a.byteLength));\n\n // Fill in the bufferViews list and missing bufferView index references while writing the binary\n for (const bufferView of orderedBufferViews) {\n bufferView.byteOffset = dataWriter.byteOffset;\n bufferViews.push(bufferView);\n\n const bufferViewIndex = bufferViews.length - 1;\n const properties = this.getPropertiesWithBufferView(bufferView);\n for (const object of properties) {\n object.bufferView = bufferViewIndex;\n }\n\n dataWriter.writeTypedArray(this._bufferViewToData.get(bufferView)!);\n\n this._bufferViewToData.delete(bufferView); // Try to free up memory ASAP\n }\n\n return dataWriter.getOutputData();\n }\n\n /**\n * Creates a buffer view based on the supplied arguments\n * @param data a TypedArray to create the bufferView for\n * @param byteStride byte distance between consecutive elements\n * @returns bufferView for glTF\n */\n public createBufferView(data: TypedArrayForglTF, byteStride?: number): IBufferView {\n const bufferView: IBufferView = {\n buffer: 0,\n byteOffset: undefined, // byteOffset will be set later, when we write the binary and decide bufferView ordering\n byteLength: data.byteLength,\n byteStride: byteStride,\n };\n this._bufferViewToData.set(bufferView, data);\n return bufferView;\n }\n\n /**\n * Creates an accessor based on the supplied arguments and assigns it to the bufferView\n * @param bufferView The glTF bufferView referenced by this accessor\n * @param type The type of the accessor\n * @param componentType The datatype of components in the attribute\n * @param count The number of attributes referenced by this accessor\n * @param byteOffset The offset relative to the start of the bufferView in bytes\n * @param minMax Minimum and maximum value of each component in this attribute\n * @param normalized Specifies whether integer data values are normalized before usage\n * @returns accessor for glTF\n */\n public createAccessor(\n bufferView: IBufferView,\n type: AccessorType,\n componentType: AccessorComponentType,\n count: number,\n byteOffset?: number,\n minMax?: { min: number[]; max: number[] },\n normalized?: boolean\n ): IAccessor {\n this._verifyBufferView(bufferView);\n const accessor: IAccessor = {\n bufferView: undefined, // bufferView will be set to a real index later, once we write the binary and decide bufferView ordering\n componentType: componentType,\n count: count,\n type: type,\n min: minMax?.min,\n max: minMax?.max,\n normalized: normalized,\n byteOffset: byteOffset,\n };\n this.setBufferView(accessor, bufferView);\n this._accessorToBufferView.set(accessor, bufferView);\n return accessor;\n }\n\n /**\n * Assigns a bufferView to a glTF object that references it\n * @param object The glTF object\n * @param bufferView The bufferView to assign\n */\n public setBufferView(object: IPropertyWithBufferView, bufferView: IBufferView) {\n this._verifyBufferView(bufferView);\n const properties = this.getPropertiesWithBufferView(bufferView);\n properties.push(object);\n }\n\n /**\n * Removes buffer view from the binary data, as well as from all its known references\n * @param bufferView the bufferView to remove\n */\n public removeBufferView(bufferView: IBufferView): void {\n const properties = this.getPropertiesWithBufferView(bufferView);\n for (const object of properties) {\n if (object.bufferView !== undefined) {\n delete object.bufferView;\n }\n }\n\n this._bufferViewToData.delete(bufferView);\n this._bufferViewToProperties.delete(bufferView);\n this._accessorToBufferView.forEach((bv, accessor) => {\n if (bv === bufferView) {\n // Additionally, remove byteOffset from accessor referencing this bufferView\n if (accessor.byteOffset !== undefined) {\n delete accessor.byteOffset;\n }\n this._accessorToBufferView.delete(accessor);\n }\n });\n }\n\n public getBufferView(accessor: IAccessor): IBufferView {\n const bufferView = this._accessorToBufferView.get(accessor);\n this._verifyBufferView(bufferView);\n return bufferView!;\n }\n\n public getPropertiesWithBufferView(bufferView: IBufferView): IPropertyWithBufferView[] {\n this._verifyBufferView(bufferView);\n this._bufferViewToProperties.set(bufferView, this._bufferViewToProperties.get(bufferView) ?? []);\n return this._bufferViewToProperties.get(bufferView)!;\n }\n\n public getData(bufferView: IBufferView): TypedArrayForglTF {\n this._verifyBufferView(bufferView);\n return this._bufferViewToData.get(bufferView)!;\n }\n\n private _verifyBufferView(bufferView?: IBufferView): void {\n if (bufferView === undefined || !this._bufferViewToData.has(bufferView)) {\n throw new Error(`BufferView ${bufferView} not found in BufferManager.`);\n }\n }\n}\n"]}
@@ -1,8 +1,10 @@
1
+ import type { TypedArray } from "@babylonjs/core/types.js";
1
2
  /** @internal */
2
3
  export declare class DataWriter {
3
4
  private _data;
4
5
  private _dataView;
5
6
  private _byteOffset;
7
+ writeTypedArray(value: Exclude<TypedArray, BigInt64Array | BigUint64Array>): void;
6
8
  constructor(byteLength: number);
7
9
  get byteOffset(): number;
8
10
  getOutputData(): Uint8Array;
@@ -10,9 +12,9 @@ export declare class DataWriter {
10
12
  writeInt8(value: number): void;
11
13
  writeInt16(entry: number): void;
12
14
  writeUInt16(value: number): void;
13
- writeUInt32(entry: number): void;
15
+ writeInt32(entry: number): void;
16
+ writeUInt32(value: number): void;
14
17
  writeFloat32(value: number): void;
15
- writeUint8Array(value: Uint8Array): void;
16
- writeUint16Array(value: Uint16Array): void;
18
+ writeFloat64(value: number): void;
17
19
  private _checkGrowBuffer;
18
20
  }
@@ -1,6 +1,24 @@
1
- /* eslint-disable babylonjs/available */
1
+ const TypedArrayToWriteMethod = new Map([
2
+ [Int8Array, (d, b, v) => d.setInt8(b, v)],
3
+ [Uint8Array, (dv, bo, v) => dv.setUint8(bo, v)],
4
+ [Uint8ClampedArray, (dv, bo, v) => dv.setUint8(bo, v)],
5
+ [Int16Array, (dv, bo, v) => dv.setInt16(bo, v, true)],
6
+ [Uint16Array, (dv, bo, v) => dv.setUint16(bo, v, true)],
7
+ [Int32Array, (dv, bo, v) => dv.setInt32(bo, v, true)],
8
+ [Uint32Array, (dv, bo, v) => dv.setUint32(bo, v, true)],
9
+ [Float32Array, (dv, bo, v) => dv.setFloat32(bo, v, true)],
10
+ [Float64Array, (dv, bo, v) => dv.setFloat64(bo, v, true)],
11
+ ]);
2
12
  /** @internal */
3
13
  export class DataWriter {
14
+ writeTypedArray(value) {
15
+ this._checkGrowBuffer(value.byteLength);
16
+ const setMethod = TypedArrayToWriteMethod.get(value.constructor);
17
+ for (let i = 0; i < value.length; i++) {
18
+ setMethod(this._dataView, this._byteOffset, value[i]);
19
+ this._byteOffset += value.BYTES_PER_ELEMENT;
20
+ }
21
+ }
4
22
  constructor(byteLength) {
5
23
  this._data = new Uint8Array(byteLength);
6
24
  this._dataView = new DataView(this._data.buffer);
@@ -32,9 +50,14 @@ export class DataWriter {
32
50
  this._dataView.setUint16(this._byteOffset, value, true);
33
51
  this._byteOffset += 2;
34
52
  }
35
- writeUInt32(entry) {
53
+ writeInt32(entry) {
36
54
  this._checkGrowBuffer(4);
37
- this._dataView.setUint32(this._byteOffset, entry, true);
55
+ this._dataView.setInt32(this._byteOffset, entry, true);
56
+ this._byteOffset += 4;
57
+ }
58
+ writeUInt32(value) {
59
+ this._checkGrowBuffer(4);
60
+ this._dataView.setUint32(this._byteOffset, value, true);
38
61
  this._byteOffset += 4;
39
62
  }
40
63
  writeFloat32(value) {
@@ -42,15 +65,10 @@ export class DataWriter {
42
65
  this._dataView.setFloat32(this._byteOffset, value, true);
43
66
  this._byteOffset += 4;
44
67
  }
45
- writeUint8Array(value) {
46
- this._checkGrowBuffer(value.byteLength);
47
- this._data.set(value, this._byteOffset);
48
- this._byteOffset += value.byteLength;
49
- }
50
- writeUint16Array(value) {
51
- this._checkGrowBuffer(value.byteLength);
52
- this._data.set(value, this._byteOffset);
53
- this._byteOffset += value.byteLength;
68
+ writeFloat64(value) {
69
+ this._checkGrowBuffer(8);
70
+ this._dataView.setFloat64(this._byteOffset, value, true);
71
+ this._byteOffset += 8;
54
72
  }
55
73
  _checkGrowBuffer(byteLength) {
56
74
  const newByteLength = this.byteOffset + byteLength;
@@ -1 +1 @@
1
- {"version":3,"file":"dataWriter.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/dataWriter.ts"],"names":[],"mappings":"AAAA,wCAAwC;AAExC,gBAAgB;AAChB,MAAM,OAAO,UAAU;IAKnB,YAAmB,UAAkB;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClE,CAAC;IAEM,UAAU,CAAC,KAAa;QAC3B,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,EAAE,CAAC;IACvB,C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AK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,UAAU,CAAC;IACzC,CAAC;IAEM,gBAAgB,CAAC,KAAkB;QACtC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,UAAU,CAAC;IACzC,CAAC;IAEO,gBAAgB,CAAC,UAAkB;QACvC,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QACnD,IAAI,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable babylonjs/available */\r\n\r\n/** @internal */\r\nexport class DataWriter {\r\n private _data: Uint8Array;\r\n private _dataView: DataView;\r\n private _byteOffset: number;\r\n\r\n public constructor(byteLength: number) {\r\n this._data = new Uint8Array(byteLength);\r\n this._dataView = new DataView(this._data.buffer);\r\n this._byteOffset = 0;\r\n }\r\n\r\n public get byteOffset(): number {\r\n return this._byteOffset;\r\n }\r\n\r\n public getOutputData(): Uint8Array {\r\n return new Uint8Array(this._data.buffer, 0, this._byteOffset);\r\n }\r\n\r\n public writeUInt8(value: number): void {\r\n this._checkGrowBuffer(1);\r\n this._dataView.setUint8(this._byteOffset, value);\r\n this._byteOffset++;\r\n }\r\n\r\n public writeInt8(value: number): void {\r\n this._checkGrowBuffer(1);\r\n this._dataView.setInt8(this._byteOffset, value);\r\n this._byteOffset++;\r\n }\r\n\r\n public writeInt16(entry: number): void {\r\n this._checkGrowBuffer(2);\r\n this._dataView.setInt16(this._byteOffset, entry, true);\r\n this._byteOffset += 2;\r\n }\r\n\r\n public writeUInt16(value: number): void {\r\n this._checkGrowBuffer(2);\r\n this._dataView.setUint16(this._byteOffset, value, true);\r\n this._byteOffset += 2;\r\n }\r\n\r\n public writeUInt32(entry: number): void {\r\n this._checkGrowBuffer(4);\r\n this._dataView.setUint32(this._byteOffset, entry, true);\r\n this._byteOffset += 4;\r\n }\r\n\r\n public writeFloat32(value: number): void {\r\n this._checkGrowBuffer(4);\r\n this._dataView.setFloat32(this._byteOffset, value, true);\r\n this._byteOffset += 4;\r\n }\r\n\r\n public writeUint8Array(value: Uint8Array): void {\r\n this._checkGrowBuffer(value.byteLength);\r\n this._data.set(value, this._byteOffset);\r\n this._byteOffset += value.byteLength;\r\n }\r\n\r\n public writeUint16Array(value: Uint16Array): void {\r\n this._checkGrowBuffer(value.byteLength);\r\n this._data.set(value, this._byteOffset);\r\n this._byteOffset += value.byteLength;\r\n }\r\n\r\n private _checkGrowBuffer(byteLength: number): void {\r\n const newByteLength = this.byteOffset + byteLength;\r\n if (newByteLength > this._data.byteLength) {\r\n const newData = new Uint8Array(newByteLength * 2);\r\n newData.set(this._data);\r\n this._data = newData;\r\n this._dataView = new DataView(this._data.buffer);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dataWriter.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/dataWriter.ts"],"names":[],"mappings":"AAIA,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAA4E;IAC/G,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CA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,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;IAC1B,CAAC;IAEO,gBAAgB,CAAC,UAAkB;QACvC,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QACnD,IAAI,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\n/* eslint-disable babylonjs/available */\r\nimport type { TypedArray } from \"core/types\";\r\n\r\nconst TypedArrayToWriteMethod = new Map<Function, (dataView: DataView, byteOffset: number, value: number) => void>([\r\n [Int8Array, (d, b, v) => d.setInt8(b, v)],\r\n [Uint8Array, (dv, bo, v) => dv.setUint8(bo, v)],\r\n [Uint8ClampedArray, (dv, bo, v) => dv.setUint8(bo, v)],\r\n [Int16Array, (dv, bo, v) => dv.setInt16(bo, v, true)],\r\n [Uint16Array, (dv, bo, v) => dv.setUint16(bo, v, true)],\r\n [Int32Array, (dv, bo, v) => dv.setInt32(bo, v, true)],\r\n [Uint32Array, (dv, bo, v) => dv.setUint32(bo, v, true)],\r\n [Float32Array, (dv, bo, v) => dv.setFloat32(bo, v, true)],\r\n [Float64Array, (dv, bo, v) => dv.setFloat64(bo, v, true)],\r\n]);\r\n\r\n/** @internal */\r\nexport class DataWriter {\r\n private _data: Uint8Array;\r\n private _dataView: DataView;\r\n private _byteOffset: number;\r\n\r\n public writeTypedArray(value: Exclude<TypedArray, BigInt64Array | BigUint64Array>): void {\r\n this._checkGrowBuffer(value.byteLength);\r\n const setMethod = TypedArrayToWriteMethod.get(value.constructor)!;\r\n for (let i = 0; i < value.length; i++) {\r\n setMethod(this._dataView, this._byteOffset, value[i] as number);\r\n this._byteOffset += value.BYTES_PER_ELEMENT;\r\n }\r\n }\r\n\r\n public constructor(byteLength: number) {\r\n this._data = new Uint8Array(byteLength);\r\n this._dataView = new DataView(this._data.buffer);\r\n this._byteOffset = 0;\r\n }\r\n\r\n public get byteOffset(): number {\r\n return this._byteOffset;\r\n }\r\n\r\n public getOutputData(): Uint8Array {\r\n return new Uint8Array(this._data.buffer, 0, this._byteOffset);\r\n }\r\n\r\n public writeUInt8(value: number): void {\r\n this._checkGrowBuffer(1);\r\n this._dataView.setUint8(this._byteOffset, value);\r\n this._byteOffset++;\r\n }\r\n\r\n public writeInt8(value: number): void {\r\n this._checkGrowBuffer(1);\r\n this._dataView.setInt8(this._byteOffset, value);\r\n this._byteOffset++;\r\n }\r\n\r\n public writeInt16(entry: number): void {\r\n this._checkGrowBuffer(2);\r\n this._dataView.setInt16(this._byteOffset, entry, true);\r\n this._byteOffset += 2;\r\n }\r\n\r\n public writeUInt16(value: number): void {\r\n this._checkGrowBuffer(2);\r\n this._dataView.setUint16(this._byteOffset, value, true);\r\n this._byteOffset += 2;\r\n }\r\n\r\n public writeInt32(entry: number): void {\r\n this._checkGrowBuffer(4);\r\n this._dataView.setInt32(this._byteOffset, entry, true);\r\n this._byteOffset += 4;\r\n }\r\n\r\n public writeUInt32(value: number): void {\r\n this._checkGrowBuffer(4);\r\n this._dataView.setUint32(this._byteOffset, value, true);\r\n this._byteOffset += 4;\r\n }\r\n\r\n public writeFloat32(value: number): void {\r\n this._checkGrowBuffer(4);\r\n this._dataView.setFloat32(this._byteOffset, value, true);\r\n this._byteOffset += 4;\r\n }\r\n\r\n public writeFloat64(value: number): void {\r\n this._checkGrowBuffer(8);\r\n this._dataView.setFloat64(this._byteOffset, value, true);\r\n this._byteOffset += 8;\r\n }\r\n\r\n private _checkGrowBuffer(byteLength: number): void {\r\n const newByteLength = this.byteOffset + byteLength;\r\n if (newByteLength > this._data.byteLength) {\r\n const newData = new Uint8Array(newByteLength * 2);\r\n newData.set(this._data);\r\n this._data = newData;\r\n this._dataView = new DataView(this._data.buffer);\r\n }\r\n }\r\n}\r\n"]}
@@ -4,7 +4,7 @@ import type { Node } from "@babylonjs/core/node.js";
4
4
  import type { Nullable } from "@babylonjs/core/types.js";
5
5
  import { Animation } from "@babylonjs/core/Animations/animation.js";
6
6
  import type { Scene } from "@babylonjs/core/scene.js";
7
- import type { DataWriter } from "./dataWriter";
7
+ import type { BufferManager } from "./bufferManager";
8
8
  /**
9
9
  * @internal
10
10
  * Interface to store animation data.
@@ -79,12 +79,12 @@ export declare class _GLTFAnimation {
79
79
  * @param idleGLTFAnimations
80
80
  * @param nodeMap
81
81
  * @param nodes
82
- * @param binaryWriter
82
+ * @param bufferManager
83
83
  * @param bufferViews
84
84
  * @param accessors
85
85
  * @param animationSampleRate
86
86
  */
87
- static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: Map<Node, number>, nodes: INode[], binaryWriter: DataWriter, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, useRightHanded: boolean, shouldExportAnimation?: (animation: Animation) => boolean): void;
87
+ static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: Map<Node, number>, nodes: INode[], bufferManager: BufferManager, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, useRightHanded: boolean, shouldExportAnimation?: (animation: Animation) => boolean): void;
88
88
  /**
89
89
  * @ignore
90
90
  * Create individual morph animations from the mesh's morph target animation tracks
@@ -93,12 +93,12 @@ export declare class _GLTFAnimation {
93
93
  * @param idleGLTFAnimations
94
94
  * @param nodeMap
95
95
  * @param nodes
96
- * @param binaryWriter
96
+ * @param bufferManager
97
97
  * @param bufferViews
98
98
  * @param accessors
99
99
  * @param animationSampleRate
100
100
  */
101
- static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: Map<Node, number>, nodes: INode[], binaryWriter: DataWriter, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, useRightHanded: boolean, shouldExportAnimation?: (animation: Animation) => boolean): void;
101
+ static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: Map<Node, number>, nodes: INode[], bufferManager: BufferManager, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, useRightHanded: boolean, shouldExportAnimation?: (animation: Animation) => boolean): void;
102
102
  /**
103
103
  * @internal
104
104
  * Create node and morph animations from the animation groups
@@ -106,12 +106,12 @@ export declare class _GLTFAnimation {
106
106
  * @param glTFAnimations
107
107
  * @param nodeMap
108
108
  * @param nodes
109
- * @param binaryWriter
109
+ * @param bufferManager
110
110
  * @param bufferViews
111
111
  * @param accessors
112
112
  * @param animationSampleRate
113
113
  */
114
- static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: IAnimation[], nodeMap: Map<Node, number>, binaryWriter: DataWriter, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, leftHandedNodes: Set<Node>, shouldExportAnimation?: (animation: Animation) => boolean): void;
114
+ static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: IAnimation[], nodeMap: Map<Node, number>, bufferManager: BufferManager, bufferViews: IBufferView[], accessors: IAccessor[], animationSampleRate: number, leftHandedNodes: Set<Node>, shouldExportAnimation?: (animation: Animation) => boolean): void;
115
115
  private static _AddAnimation;
116
116
  /**
117
117
  * Create a baked animation
@@ -6,7 +6,7 @@ import { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
6
6
  import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
7
7
  import { Camera } from "@babylonjs/core/Cameras/camera.js";
8
8
  import { Light } from "@babylonjs/core/Lights/light.js";
9
- import { CreateAccessor, CreateBufferView, GetAccessorElementCount, ConvertToRightHandedPosition, ConvertCameraRotationToGLTF, ConvertToRightHandedRotation, } from "./glTFUtilities.js";
9
+ import { GetAccessorElementCount, ConvertToRightHandedPosition, ConvertCameraRotationToGLTF, ConvertToRightHandedRotation } from "./glTFUtilities.js";
10
10
  /**
11
11
  * @internal
12
12
  * Enum for handling in tangent and out tangent.
@@ -132,12 +132,12 @@ export class _GLTFAnimation {
132
132
  * @param idleGLTFAnimations
133
133
  * @param nodeMap
134
134
  * @param nodes
135
- * @param binaryWriter
135
+ * @param bufferManager
136
136
  * @param bufferViews
137
137
  * @param accessors
138
138
  * @param animationSampleRate
139
139
  */
140
- static _CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, animationSampleRate, useRightHanded, shouldExportAnimation) {
140
+ static _CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, bufferManager, bufferViews, accessors, animationSampleRate, useRightHanded, shouldExportAnimation) {
141
141
  let glTFAnimation;
142
142
  if (_GLTFAnimation._IsTransformable(babylonNode)) {
143
143
  if (babylonNode.animations) {
@@ -152,7 +152,7 @@ export class _GLTFAnimation {
152
152
  samplers: [],
153
153
  channels: [],
154
154
  };
155
- _GLTFAnimation._AddAnimation(`${animation.name}`, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, useRightHanded);
155
+ _GLTFAnimation._AddAnimation(`${animation.name}`, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, bufferManager, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, useRightHanded);
156
156
  if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
157
157
  idleGLTFAnimations.push(glTFAnimation);
158
158
  }
@@ -169,12 +169,12 @@ export class _GLTFAnimation {
169
169
  * @param idleGLTFAnimations
170
170
  * @param nodeMap
171
171
  * @param nodes
172
- * @param binaryWriter
172
+ * @param bufferManager
173
173
  * @param bufferViews
174
174
  * @param accessors
175
175
  * @param animationSampleRate
176
176
  */
177
- static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, animationSampleRate, useRightHanded, shouldExportAnimation) {
177
+ static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, bufferManager, bufferViews, accessors, animationSampleRate, useRightHanded, shouldExportAnimation) {
178
178
  let glTFAnimation;
179
179
  if (babylonNode instanceof Mesh) {
180
180
  const morphTargetManager = babylonNode.morphTargetManager;
@@ -207,7 +207,7 @@ export class _GLTFAnimation {
207
207
  samplers: [],
208
208
  channels: [],
209
209
  };
210
- _GLTFAnimation._AddAnimation(animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, combinedAnimation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, useRightHanded, morphTargetManager.numTargets);
210
+ _GLTFAnimation._AddAnimation(animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, combinedAnimation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, bufferManager, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, useRightHanded, morphTargetManager.numTargets);
211
211
  if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
212
212
  idleGLTFAnimations.push(glTFAnimation);
213
213
  }
@@ -224,12 +224,12 @@ export class _GLTFAnimation {
224
224
  * @param glTFAnimations
225
225
  * @param nodeMap
226
226
  * @param nodes
227
- * @param binaryWriter
227
+ * @param bufferManager
228
228
  * @param bufferViews
229
229
  * @param accessors
230
230
  * @param animationSampleRate
231
231
  */
232
- static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene, glTFAnimations, nodeMap, binaryWriter, bufferViews, accessors, animationSampleRate, leftHandedNodes, shouldExportAnimation) {
232
+ static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene, glTFAnimations, nodeMap, bufferManager, bufferViews, accessors, animationSampleRate, leftHandedNodes, shouldExportAnimation) {
233
233
  let glTFAnimation;
234
234
  if (babylonScene.animationGroups) {
235
235
  const animationGroups = babylonScene.animationGroups;
@@ -256,7 +256,7 @@ export class _GLTFAnimation {
256
256
  if (animationInfo) {
257
257
  const babylonTransformNode = this._IsTransformable(target) ? target : this._IsTransformable(target[0]) ? target[0] : null;
258
258
  if (babylonTransformNode) {
259
- _GLTFAnimation._AddAnimation(`${animation.name}`, glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, convertToRightHanded);
259
+ _GLTFAnimation._AddAnimation(`${animation.name}`, glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, bufferManager, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, convertToRightHanded);
260
260
  }
261
261
  }
262
262
  }
@@ -335,7 +335,7 @@ export class _GLTFAnimation {
335
335
  combinedAnimationGroup.setKeys(animationKeys);
336
336
  const animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimationGroup);
337
337
  if (animationInfo) {
338
- _GLTFAnimation._AddAnimation(`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`, glTFAnimation, mesh, combinedAnimationGroup, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, false, morphTargetManager?.numTargets);
338
+ _GLTFAnimation._AddAnimation(`${animationGroup.name}_${mesh.name}_MorphWeightAnimation`, glTFAnimation, mesh, combinedAnimationGroup, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, bufferManager, bufferViews, accessors, animationInfo.useQuaternion, animationSampleRate, false, morphTargetManager?.numTargets);
339
339
  }
340
340
  });
341
341
  if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {
@@ -344,13 +344,12 @@ export class _GLTFAnimation {
344
344
  }
345
345
  }
346
346
  }
347
- static _AddAnimation(name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, useQuaternion, animationSampleRate, convertToRightHanded, morphAnimationChannels) {
347
+ static _AddAnimation(name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, bufferManager, bufferViews, accessors, useQuaternion, animationSampleRate, convertToRightHanded, morphAnimationChannels) {
348
348
  const animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, useQuaternion, animationSampleRate);
349
349
  let bufferView;
350
350
  let accessor;
351
351
  let keyframeAccessorIndex;
352
352
  let dataAccessorIndex;
353
- let outputLength;
354
353
  let animationSampler;
355
354
  let animationChannel;
356
355
  if (animationData) {
@@ -373,45 +372,37 @@ export class _GLTFAnimation {
373
372
  animationData.inputs = newInputs;
374
373
  }
375
374
  const nodeIndex = nodeMap.get(babylonTransformNode);
376
- // Creates buffer view and accessor for key frames.
377
- let byteLength = animationData.inputs.length * 4;
378
- const offset = binaryWriter.byteOffset;
379
- bufferView = CreateBufferView(0, offset, byteLength);
380
- bufferViews.push(bufferView);
381
- animationData.inputs.forEach(function (input) {
382
- binaryWriter.writeFloat32(input);
383
- });
384
- accessor = CreateAccessor(bufferViews.length - 1, "SCALAR" /* AccessorType.SCALAR */, 5126 /* AccessorComponentType.FLOAT */, animationData.inputs.length, null, {
375
+ // Create buffer view and accessor for key frames.
376
+ const inputData = new Float32Array(animationData.inputs);
377
+ bufferView = bufferManager.createBufferView(inputData);
378
+ accessor = bufferManager.createAccessor(bufferView, "SCALAR" /* AccessorType.SCALAR */, 5126 /* AccessorComponentType.FLOAT */, animationData.inputs.length, undefined, {
385
379
  min: [animationData.inputsMin],
386
380
  max: [animationData.inputsMax],
387
381
  });
388
382
  accessors.push(accessor);
389
383
  keyframeAccessorIndex = accessors.length - 1;
390
- // create bufferview and accessor for keyed values.
391
- outputLength = animationData.outputs.length;
392
- byteLength = GetAccessorElementCount(dataAccessorType) * 4 * animationData.outputs.length;
393
- // check for in and out tangents
394
- bufferView = CreateBufferView(0, binaryWriter.byteOffset, byteLength);
395
- bufferViews.push(bufferView);
384
+ // Perform conversions on keyed values while also building their buffer.
396
385
  const rotationQuaternion = new Quaternion();
397
386
  const eulerVec3 = new Vector3();
398
387
  const position = new Vector3();
399
388
  const isCamera = babylonTransformNode instanceof Camera;
400
- animationData.outputs.forEach(function (output) {
389
+ const elementCount = GetAccessorElementCount(dataAccessorType);
390
+ const outputData = new Float32Array(animationData.outputs.length * elementCount);
391
+ animationData.outputs.forEach(function (output, index) {
392
+ let outputToWrite = output;
401
393
  if (convertToRightHanded) {
402
394
  switch (animationChannelTargetPath) {
403
395
  case "translation" /* AnimationChannelTargetPath.TRANSLATION */:
404
396
  Vector3.FromArrayToRef(output, 0, position);
405
397
  ConvertToRightHandedPosition(position);
406
- binaryWriter.writeFloat32(position.x);
407
- binaryWriter.writeFloat32(position.y);
408
- binaryWriter.writeFloat32(position.z);
398
+ position.toArray(outputToWrite);
409
399
  break;
410
400
  case "rotation" /* AnimationChannelTargetPath.ROTATION */:
411
401
  if (output.length === 4) {
412
402
  Quaternion.FromArrayToRef(output, 0, rotationQuaternion);
413
403
  }
414
404
  else {
405
+ outputToWrite = new Array(4); // Will need 4, not 3, for a quaternion
415
406
  Vector3.FromArrayToRef(output, 0, eulerVec3);
416
407
  Quaternion.FromEulerVectorToRef(eulerVec3, rotationQuaternion);
417
408
  }
@@ -423,15 +414,7 @@ export class _GLTFAnimation {
423
414
  ConvertToRightHandedRotation(rotationQuaternion);
424
415
  }
425
416
  }
426
- binaryWriter.writeFloat32(rotationQuaternion.x);
427
- binaryWriter.writeFloat32(rotationQuaternion.y);
428
- binaryWriter.writeFloat32(rotationQuaternion.z);
429
- binaryWriter.writeFloat32(rotationQuaternion.w);
430
- break;
431
- default:
432
- output.forEach(function (entry) {
433
- binaryWriter.writeFloat32(entry);
434
- });
417
+ rotationQuaternion.toArray(outputToWrite);
435
418
  break;
436
419
  }
437
420
  }
@@ -442,26 +425,22 @@ export class _GLTFAnimation {
442
425
  Quaternion.FromArrayToRef(output, 0, rotationQuaternion);
443
426
  }
444
427
  else {
428
+ outputToWrite = new Array(4); // Will need 4, not 3, for a quaternion
445
429
  Vector3.FromArrayToRef(output, 0, eulerVec3);
446
430
  Quaternion.FromEulerVectorToRef(eulerVec3, rotationQuaternion);
447
431
  }
448
432
  if (isCamera) {
449
433
  ConvertCameraRotationToGLTF(rotationQuaternion);
450
434
  }
451
- binaryWriter.writeFloat32(rotationQuaternion.x);
452
- binaryWriter.writeFloat32(rotationQuaternion.y);
453
- binaryWriter.writeFloat32(rotationQuaternion.z);
454
- binaryWriter.writeFloat32(rotationQuaternion.w);
455
- break;
456
- default:
457
- output.forEach(function (entry) {
458
- binaryWriter.writeFloat32(entry);
459
- });
435
+ rotationQuaternion.toArray(outputToWrite);
460
436
  break;
461
437
  }
462
438
  }
439
+ outputData.set(outputToWrite, index * elementCount);
463
440
  });
464
- accessor = CreateAccessor(bufferViews.length - 1, dataAccessorType, 5126 /* AccessorComponentType.FLOAT */, outputLength, null);
441
+ // Create buffer view and accessor for keyed values.
442
+ bufferView = bufferManager.createBufferView(outputData);
443
+ accessor = bufferManager.createAccessor(bufferView, dataAccessorType, 5126 /* AccessorComponentType.FLOAT */, animationData.outputs.length);
465
444
  accessors.push(accessor);
466
445
  dataAccessorIndex = accessors.length - 1;
467
446
  // create sampler