@babylonjs/serializers 7.43.0 → 7.44.1

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 (37) hide show
  1. package/USDZ/usdzExporter.d.ts +3 -3
  2. package/USDZ/usdzExporter.js +3 -3
  3. package/USDZ/usdzExporter.js.map +1 -1
  4. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +3 -3
  5. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +10 -42
  6. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  7. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +32 -0
  8. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +136 -0
  9. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -0
  10. package/glTF/2.0/Extensions/index.d.ts +1 -0
  11. package/glTF/2.0/Extensions/index.js +1 -0
  12. package/glTF/2.0/Extensions/index.js.map +1 -1
  13. package/glTF/2.0/bufferManager.d.ts +68 -0
  14. package/glTF/2.0/bufferManager.js +152 -0
  15. package/glTF/2.0/bufferManager.js.map +1 -0
  16. package/glTF/2.0/dataWriter.d.ts +5 -3
  17. package/glTF/2.0/dataWriter.js +30 -12
  18. package/glTF/2.0/dataWriter.js.map +1 -1
  19. package/glTF/2.0/glTFAnimation.d.ts +7 -7
  20. package/glTF/2.0/glTFAnimation.js +30 -51
  21. package/glTF/2.0/glTFAnimation.js.map +1 -1
  22. package/glTF/2.0/glTFExporter.d.ts +5 -4
  23. package/glTF/2.0/glTFExporter.js +112 -146
  24. package/glTF/2.0/glTFExporter.js.map +1 -1
  25. package/glTF/2.0/glTFExporterExtension.d.ts +14 -10
  26. package/glTF/2.0/glTFExporterExtension.js.map +1 -1
  27. package/glTF/2.0/glTFMaterialExporter.js +25 -15
  28. package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
  29. package/glTF/2.0/glTFMorphTargetsUtilities.d.ts +2 -2
  30. package/glTF/2.0/glTFMorphTargetsUtilities.js +23 -25
  31. package/glTF/2.0/glTFMorphTargetsUtilities.js.map +1 -1
  32. package/glTF/2.0/glTFSerializer.d.ts +8 -0
  33. package/glTF/2.0/glTFSerializer.js.map +1 -1
  34. package/glTF/2.0/glTFUtilities.d.ts +11 -28
  35. package/glTF/2.0/glTFUtilities.js +16 -57
  36. package/glTF/2.0/glTFUtilities.js.map +1 -1
  37. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_draco_mesh_compression.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_draco_mesh_compression.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,OAAO,EAAE,YAAY,EAAE,2DAA6C;AACpE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,+CAAiC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAG1C,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C,SAAS,qBAAqB,CAAC,QAAgB;IAC3C,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,UAAU,CAAC;IACtB,CAAC;SAAM,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,QAAQ,CAAC;IACpB,CAAC;SAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC;IACnB,CAAC;SAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACzC,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,0BAA0B;IAqBnC,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,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AQ,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,gBAAgB;IACT,KAAK,CAAC,sBAAsB,CAAC,aAA4B;QAC5D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,OAAO;QACX,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAExC,+DAA+D;QAC/D,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACzC,MAAM,UAAU,GAAG,aAAa,CAAC,2BAA2B,CAAC,UAAU,CAAC,CAAC;YACzE,MAAM,2BAA2B,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;gBAC5D,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAmB,CAAC,CAAC,CAAC,wDAAwD;YACjH,CAAC,CAAC,CAAC;YACH,IAAI,2BAA2B,EAAE,CAAC;gBAC9B,aAAa,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { GLTFExporter } from \"../glTFExporter\";\nimport { MeshPrimitiveMode } from \"babylonjs-gltf2interface\";\nimport type { IAccessor, IBufferView, IKHRDracoMeshCompression, IMeshPrimitive } from \"babylonjs-gltf2interface\";\nimport type { BufferManager } from \"../bufferManager\";\nimport { DracoEncoder } from \"core/Meshes/Compression/dracoEncoder\";\nimport { GetFloatData, GetTypeByteLength } from \"core/Buffers/bufferUtils\";\nimport { GetAccessorElementCount } from \"../glTFUtilities\";\nimport type { DracoAttributeName, IDracoAttributeData, IDracoEncoderOptions } from \"core/Meshes/Compression/dracoEncoder.types\";\nimport { Logger } from \"core/Misc/logger\";\nimport type { Nullable } from \"core/types\";\n\nconst NAME = \"KHR_draco_mesh_compression\";\n\nfunction getDracoAttributeName(glTFName: string): DracoAttributeName {\n if (glTFName === \"POSITION\") {\n return \"POSITION\";\n } else if (glTFName === \"NORMAL\") {\n return \"NORMAL\";\n } else if (glTFName.startsWith(\"COLOR\")) {\n return \"COLOR\";\n } else if (glTFName.startsWith(\"TEXCOORD\")) {\n return \"TEX_COORD\";\n }\n return \"GENERIC\";\n}\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_draco_mesh_compression implements IGLTFExporterExtensionV2 {\n /** Name of this extension */\n public readonly name = NAME;\n\n /** Defines whether this extension is enabled */\n public enabled;\n\n /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */\n public required = true;\n\n /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */\n private _bufferViewsUsed: Set<IBufferView> = new Set();\n\n /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */\n private _accessorsUsed: Set<IAccessor> = new Set();\n\n /** Promise pool for Draco encoding work */\n private _encodePromises: Promise<void>[] = [];\n\n private _wasUsed = false;\n\n /** @internal */\n public get wasUsed() {\n return this._wasUsed;\n }\n\n /** @internal */\n constructor(exporter: GLTFExporter) {\n this.enabled = exporter.options.meshCompressionMethod === \"Draco\" && DracoEncoder.DefaultAvailable;\n }\n\n /** @internal */\n public dispose() {}\n\n /** @internal */\n public postExportMeshPrimitive(primitive: IMeshPrimitive, bufferManager: BufferManager, accessors: IAccessor[]): void {\n if (!this.enabled) {\n return;\n }\n\n if (primitive.mode !== MeshPrimitiveMode.TRIANGLES && primitive.mode !== MeshPrimitiveMode.TRIANGLE_STRIP) {\n Logger.Warn(\"Cannot compress primitive with mode \" + primitive.mode + \".\");\n return;\n }\n\n // Collect bufferViews and accessors used by this primitive\n const primitiveBufferViews: IBufferView[] = [];\n const primitiveAccessors: IAccessor[] = [];\n\n // Prepare indices for Draco encoding\n let indices: Nullable<Uint32Array | Uint16Array> = null;\n if (primitive.indices !== undefined) {\n const accessor = accessors[primitive.indices];\n const bufferView = bufferManager.getBufferView(accessor);\n // Per exportIndices, indices must be either Uint16Array or Uint32Array\n indices = bufferManager.getData(bufferView) as Uint32Array | Uint16Array;\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Prepare attributes for Draco encoding\n const attributes: IDracoAttributeData[] = [];\n for (const [name, accessorIndex] of Object.entries(primitive.attributes)) {\n const accessor = accessors[accessorIndex];\n const bufferView = bufferManager.getBufferView(accessor);\n const data = bufferManager.getData(bufferView);\n\n const size = GetAccessorElementCount(accessor.type);\n // TODO: Implement a way to preserve original data type, as Draco can handle more than just floats\n // TODO: Add flag in DracoEncoder API to prevent copying data (a second time) to transferable buffer\n const floatData = GetFloatData(\n data,\n size,\n accessor.componentType,\n accessor.byteOffset || 0,\n bufferView.byteStride || GetTypeByteLength(accessor.componentType) * size,\n accessor.normalized || false,\n accessor.count\n ) as Float32Array; // Because data is a TypedArray, GetFloatData will return a Float32Array\n\n attributes.push({ kind: name, dracoName: getDracoAttributeName(name), size: GetAccessorElementCount(accessor.type), data: floatData });\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Use sequential encoding to preserve vertex order for cases like morph targets\n const options: IDracoEncoderOptions = {\n method: primitive.targets ? \"MESH_SEQUENTIAL_ENCODING\" : \"MESH_EDGEBREAKER_ENCODING\",\n };\n\n const promise = DracoEncoder.Default._encodeAsync(attributes, indices, options)\n .then((encodedData) => {\n if (!encodedData) {\n Logger.Error(\"Draco encoding failed for primitive.\");\n return;\n }\n\n const dracoInfo: IKHRDracoMeshCompression = {\n bufferView: -1, // bufferView will be set to a real index later, when we write the binary and decide bufferView ordering\n attributes: encodedData.attributeIDs,\n };\n const bufferView = bufferManager.createBufferView(encodedData.data);\n bufferManager.setBufferView(dracoInfo, bufferView);\n\n for (const bufferView of primitiveBufferViews) {\n this._bufferViewsUsed.add(bufferView);\n }\n for (const accessor of primitiveAccessors) {\n this._accessorsUsed.add(accessor);\n }\n\n primitive.extensions ||= {};\n primitive.extensions[NAME] = dracoInfo;\n })\n .catch((error) => {\n Logger.Error(\"Draco encoding failed for primitive: \" + error);\n });\n\n this._encodePromises.push(promise);\n\n this._wasUsed = true;\n }\n\n /** @internal */\n public async preGenerateBinaryAsync(bufferManager: BufferManager): Promise<void> {\n if (!this.enabled) {\n return;\n }\n\n await Promise.all(this._encodePromises);\n\n // Cull obsolete bufferViews that were replaced with Draco data\n this._bufferViewsUsed.forEach((bufferView) => {\n const references = bufferManager.getPropertiesWithBufferView(bufferView);\n const onlyUsedByEncodedPrimitives = references.every((object) => {\n return this._accessorsUsed.has(object as IAccessor); // has() can handle any object, but TS doesn't know that\n });\n if (onlyUsedByEncodedPrimitives) {\n bufferManager.removeBufferView(bufferView);\n }\n });\n\n this._bufferViewsUsed.clear();\n this._accessorsUsed.clear();\n }\n}\n\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_draco_mesh_compression(exporter));\n"]}
@@ -1,4 +1,5 @@
1
1
  export * from "./EXT_mesh_gpu_instancing";
2
+ export * from "./KHR_draco_mesh_compression";
2
3
  export * from "./KHR_lights_punctual";
3
4
  export * from "./KHR_materials_anisotropy";
4
5
  export * from "./KHR_materials_clearcoat";
@@ -1,4 +1,5 @@
1
1
  export * from "./EXT_mesh_gpu_instancing.js";
2
+ export * from "./KHR_draco_mesh_compression.js";
2
3
  export * from "./KHR_lights_punctual.js";
3
4
  export * from "./KHR_materials_anisotropy.js";
4
5
  export * from "./KHR_materials_clearcoat.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC","sourcesContent":["export * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_materials_anisotropy\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_diffuse_transmission\";\r\nexport * from \"./KHR_materials_dispersion\";\r\nexport * from \"./KHR_materials_emissive_strength\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_texture_transform\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC","sourcesContent":["export * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./KHR_draco_mesh_compression\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_materials_anisotropy\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_diffuse_transmission\";\r\nexport * from \"./KHR_materials_dispersion\";\r\nexport * from \"./KHR_materials_emissive_strength\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_texture_transform\";\r\n"]}
@@ -0,0 +1,68 @@
1
+ import type { TypedArray } from "@babylonjs/core/types.js";
2
+ import type { AccessorComponentType, AccessorType, IAccessor, IBufferView } from "babylonjs-gltf2interface";
3
+ type TypedArrayForglTF = Exclude<TypedArray, Float64Array | BigInt64Array | BigUint64Array>;
4
+ interface IPropertyWithBufferView {
5
+ bufferView?: number;
6
+ }
7
+ /**
8
+ * Utility class to centralize the management of binary data, bufferViews, and the objects that reference them.
9
+ * @internal
10
+ */
11
+ export declare class BufferManager {
12
+ /**
13
+ * Maps a bufferView to its data
14
+ */
15
+ private _bufferViewToData;
16
+ /**
17
+ * Maps a bufferView to glTF objects that reference it via a "bufferView" property (e.g. accessors, images)
18
+ */
19
+ private _bufferViewToProperties;
20
+ /**
21
+ * Maps an accessor to its bufferView
22
+ */
23
+ private _accessorToBufferView;
24
+ /**
25
+ * Generates a binary buffer from the stored bufferViews. Also populates the bufferViews list.
26
+ * @param bufferViews The list of bufferViews to be populated while writing the binary
27
+ * @returns The binary buffer
28
+ */
29
+ generateBinary(bufferViews: IBufferView[]): Uint8Array;
30
+ /**
31
+ * Creates a buffer view based on the supplied arguments
32
+ * @param data a TypedArray to create the bufferView for
33
+ * @param byteStride byte distance between consecutive elements
34
+ * @returns bufferView for glTF
35
+ */
36
+ createBufferView(data: TypedArrayForglTF, byteStride?: number): IBufferView;
37
+ /**
38
+ * Creates an accessor based on the supplied arguments and assigns it to the bufferView
39
+ * @param bufferView The glTF bufferView referenced by this accessor
40
+ * @param type The type of the accessor
41
+ * @param componentType The datatype of components in the attribute
42
+ * @param count The number of attributes referenced by this accessor
43
+ * @param byteOffset The offset relative to the start of the bufferView in bytes
44
+ * @param minMax Minimum and maximum value of each component in this attribute
45
+ * @param normalized Specifies whether integer data values are normalized before usage
46
+ * @returns accessor for glTF
47
+ */
48
+ createAccessor(bufferView: IBufferView, type: AccessorType, componentType: AccessorComponentType, count: number, byteOffset?: number, minMax?: {
49
+ min: number[];
50
+ max: number[];
51
+ }, normalized?: boolean): IAccessor;
52
+ /**
53
+ * Assigns a bufferView to a glTF object that references it
54
+ * @param object The glTF object
55
+ * @param bufferView The bufferView to assign
56
+ */
57
+ setBufferView(object: IPropertyWithBufferView, bufferView: IBufferView): void;
58
+ /**
59
+ * Removes buffer view from the binary data, as well as from all its known references
60
+ * @param bufferView the bufferView to remove
61
+ */
62
+ removeBufferView(bufferView: IBufferView): void;
63
+ getBufferView(accessor: IAccessor): IBufferView;
64
+ getPropertiesWithBufferView(bufferView: IBufferView): IPropertyWithBufferView[];
65
+ getData(bufferView: IBufferView): TypedArrayForglTF;
66
+ private _verifyBufferView;
67
+ }
68
+ export {};
@@ -0,0 +1,152 @@
1
+ import { DataWriter } from "./dataWriter.js";
2
+ function getHighestByteAlignment(byteLength) {
3
+ if (byteLength % 4 === 0)
4
+ return 4;
5
+ if (byteLength % 2 === 0)
6
+ return 2;
7
+ return 1;
8
+ }
9
+ /**
10
+ * Utility class to centralize the management of binary data, bufferViews, and the objects that reference them.
11
+ * @internal
12
+ */
13
+ export class BufferManager {
14
+ constructor() {
15
+ /**
16
+ * Maps a bufferView to its data
17
+ */
18
+ this._bufferViewToData = new Map();
19
+ /**
20
+ * Maps a bufferView to glTF objects that reference it via a "bufferView" property (e.g. accessors, images)
21
+ */
22
+ this._bufferViewToProperties = new Map();
23
+ /**
24
+ * Maps an accessor to its bufferView
25
+ */
26
+ this._accessorToBufferView = new Map();
27
+ }
28
+ /**
29
+ * Generates a binary buffer from the stored bufferViews. Also populates the bufferViews list.
30
+ * @param bufferViews The list of bufferViews to be populated while writing the binary
31
+ * @returns The binary buffer
32
+ */
33
+ generateBinary(bufferViews) {
34
+ // Construct a DataWriter with the total byte length to prevent resizing
35
+ let totalByteLength = 0;
36
+ this._bufferViewToData.forEach((data) => {
37
+ totalByteLength += data.byteLength;
38
+ });
39
+ const dataWriter = new DataWriter(totalByteLength);
40
+ // Order the bufferViews in descending order of their alignment requirements
41
+ const orderedBufferViews = Array.from(this._bufferViewToData.keys()).sort((a, b) => getHighestByteAlignment(b.byteLength) - getHighestByteAlignment(a.byteLength));
42
+ // Fill in the bufferViews list and missing bufferView index references while writing the binary
43
+ for (const bufferView of orderedBufferViews) {
44
+ bufferView.byteOffset = dataWriter.byteOffset;
45
+ bufferViews.push(bufferView);
46
+ const bufferViewIndex = bufferViews.length - 1;
47
+ const properties = this.getPropertiesWithBufferView(bufferView);
48
+ for (const object of properties) {
49
+ object.bufferView = bufferViewIndex;
50
+ }
51
+ dataWriter.writeTypedArray(this._bufferViewToData.get(bufferView));
52
+ this._bufferViewToData.delete(bufferView); // Try to free up memory ASAP
53
+ }
54
+ return dataWriter.getOutputData();
55
+ }
56
+ /**
57
+ * Creates a buffer view based on the supplied arguments
58
+ * @param data a TypedArray to create the bufferView for
59
+ * @param byteStride byte distance between consecutive elements
60
+ * @returns bufferView for glTF
61
+ */
62
+ createBufferView(data, byteStride) {
63
+ const bufferView = {
64
+ buffer: 0,
65
+ byteOffset: undefined, // byteOffset will be set later, when we write the binary and decide bufferView ordering
66
+ byteLength: data.byteLength,
67
+ byteStride: byteStride,
68
+ };
69
+ this._bufferViewToData.set(bufferView, data);
70
+ return bufferView;
71
+ }
72
+ /**
73
+ * Creates an accessor based on the supplied arguments and assigns it to the bufferView
74
+ * @param bufferView The glTF bufferView referenced by this accessor
75
+ * @param type The type of the accessor
76
+ * @param componentType The datatype of components in the attribute
77
+ * @param count The number of attributes referenced by this accessor
78
+ * @param byteOffset The offset relative to the start of the bufferView in bytes
79
+ * @param minMax Minimum and maximum value of each component in this attribute
80
+ * @param normalized Specifies whether integer data values are normalized before usage
81
+ * @returns accessor for glTF
82
+ */
83
+ createAccessor(bufferView, type, componentType, count, byteOffset, minMax, normalized) {
84
+ this._verifyBufferView(bufferView);
85
+ const accessor = {
86
+ bufferView: undefined, // bufferView will be set to a real index later, once we write the binary and decide bufferView ordering
87
+ componentType: componentType,
88
+ count: count,
89
+ type: type,
90
+ min: minMax?.min,
91
+ max: minMax?.max,
92
+ normalized: normalized,
93
+ byteOffset: byteOffset,
94
+ };
95
+ this.setBufferView(accessor, bufferView);
96
+ this._accessorToBufferView.set(accessor, bufferView);
97
+ return accessor;
98
+ }
99
+ /**
100
+ * Assigns a bufferView to a glTF object that references it
101
+ * @param object The glTF object
102
+ * @param bufferView The bufferView to assign
103
+ */
104
+ setBufferView(object, bufferView) {
105
+ this._verifyBufferView(bufferView);
106
+ const properties = this.getPropertiesWithBufferView(bufferView);
107
+ properties.push(object);
108
+ }
109
+ /**
110
+ * Removes buffer view from the binary data, as well as from all its known references
111
+ * @param bufferView the bufferView to remove
112
+ */
113
+ removeBufferView(bufferView) {
114
+ const properties = this.getPropertiesWithBufferView(bufferView);
115
+ for (const object of properties) {
116
+ if (object.bufferView !== undefined) {
117
+ delete object.bufferView;
118
+ }
119
+ }
120
+ this._bufferViewToData.delete(bufferView);
121
+ this._bufferViewToProperties.delete(bufferView);
122
+ this._accessorToBufferView.forEach((bv, accessor) => {
123
+ if (bv === bufferView) {
124
+ // Additionally, remove byteOffset from accessor referencing this bufferView
125
+ if (accessor.byteOffset !== undefined) {
126
+ delete accessor.byteOffset;
127
+ }
128
+ this._accessorToBufferView.delete(accessor);
129
+ }
130
+ });
131
+ }
132
+ getBufferView(accessor) {
133
+ const bufferView = this._accessorToBufferView.get(accessor);
134
+ this._verifyBufferView(bufferView);
135
+ return bufferView;
136
+ }
137
+ getPropertiesWithBufferView(bufferView) {
138
+ this._verifyBufferView(bufferView);
139
+ this._bufferViewToProperties.set(bufferView, this._bufferViewToProperties.get(bufferView) ?? []);
140
+ return this._bufferViewToProperties.get(bufferView);
141
+ }
142
+ getData(bufferView) {
143
+ this._verifyBufferView(bufferView);
144
+ return this._bufferViewToData.get(bufferView);
145
+ }
146
+ _verifyBufferView(bufferView) {
147
+ if (bufferView === undefined || !this._bufferViewToData.has(bufferView)) {
148
+ throw new Error(`BufferView ${bufferView} not found in BufferManager.`);
149
+ }
150
+ }
151
+ }
152
+ //# sourceMappingURL=bufferManager.js.map
@@ -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;Q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AAuB;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,I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,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,CAAC,CAAC,CAAC;IACzC,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,iBAAiB,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC,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;IAEM,WAAW,CAAC,KAAa;QAC5B,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;IAC1B,CAAC;IAEM,YAAY,CAAC,KAAa;QAC7B,IAAI,CAAC,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;IAEM,YAAY,CAAC,KAAa;QAC7B,IAAI,CAAC,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