@babylonjs/serializers 5.0.0-rc.7 → 5.0.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 (74) hide show
  1. package/OBJ/index.d.ts +1 -1
  2. package/OBJ/index.js +1 -1
  3. package/OBJ/objSerializer.d.ts +21 -21
  4. package/OBJ/objSerializer.js +174 -174
  5. package/OBJ/objSerializer.js.map +1 -1
  6. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +41 -41
  7. package/glTF/2.0/Extensions/KHR_lights_punctual.js +189 -189
  8. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  9. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +24 -24
  10. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +90 -90
  11. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  12. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +24 -24
  13. package/glTF/2.0/Extensions/KHR_materials_sheen.js +73 -73
  14. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  15. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +20 -20
  16. package/glTF/2.0/Extensions/KHR_materials_unlit.js +51 -51
  17. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  18. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +30 -30
  19. package/glTF/2.0/Extensions/KHR_texture_transform.js +137 -137
  20. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  21. package/glTF/2.0/Extensions/index.d.ts +5 -5
  22. package/glTF/2.0/Extensions/index.js +5 -5
  23. package/glTF/2.0/glTFAnimation.d.ts +206 -205
  24. package/glTF/2.0/glTFAnimation.js +852 -852
  25. package/glTF/2.0/glTFAnimation.js.map +1 -1
  26. package/glTF/2.0/glTFData.d.ts +19 -19
  27. package/glTF/2.0/glTFData.js +52 -52
  28. package/glTF/2.0/glTFExporter.d.ts +456 -455
  29. package/glTF/2.0/glTFExporter.js +1975 -1972
  30. package/glTF/2.0/glTFExporter.js.map +1 -1
  31. package/glTF/2.0/glTFExporterExtension.d.ts +74 -74
  32. package/glTF/2.0/glTFExporterExtension.js +3 -3
  33. package/glTF/2.0/glTFExporterExtension.js.map +1 -1
  34. package/glTF/2.0/glTFMaterialExporter.d.ts +208 -207
  35. package/glTF/2.0/glTFMaterialExporter.js +1114 -1114
  36. package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
  37. package/glTF/2.0/glTFSerializer.d.ts +60 -60
  38. package/glTF/2.0/glTFSerializer.js +62 -62
  39. package/glTF/2.0/glTFSerializer.js.map +1 -1
  40. package/glTF/2.0/glTFUtilities.d.ts +99 -97
  41. package/glTF/2.0/glTFUtilities.js +196 -196
  42. package/glTF/2.0/glTFUtilities.js.map +1 -1
  43. package/glTF/2.0/index.d.ts +8 -8
  44. package/glTF/2.0/index.js +9 -8
  45. package/glTF/2.0/index.js.map +1 -1
  46. package/glTF/2.0/shaders/textureTransform.fragment.d.ts +5 -5
  47. package/glTF/2.0/shaders/textureTransform.fragment.js +8 -8
  48. package/glTF/glTFFileExporter.d.ts +20 -20
  49. package/glTF/glTFFileExporter.js +3 -3
  50. package/glTF/index.d.ts +2 -2
  51. package/glTF/index.js +3 -2
  52. package/glTF/index.js.map +1 -1
  53. package/index.d.ts +3 -3
  54. package/index.js +4 -3
  55. package/index.js.map +1 -1
  56. package/legacy/legacy-glTF2Serializer.d.ts +2 -2
  57. package/legacy/legacy-glTF2Serializer.js +44 -43
  58. package/legacy/legacy-glTF2Serializer.js.map +1 -1
  59. package/legacy/legacy-objSerializer.d.ts +1 -1
  60. package/legacy/legacy-objSerializer.js +13 -12
  61. package/legacy/legacy-objSerializer.js.map +1 -1
  62. package/legacy/legacy-stlSerializer.d.ts +1 -1
  63. package/legacy/legacy-stlSerializer.js +13 -12
  64. package/legacy/legacy-stlSerializer.js.map +1 -1
  65. package/legacy/legacy.d.ts +4 -4
  66. package/legacy/legacy.js +6 -5
  67. package/legacy/legacy.js.map +1 -1
  68. package/license.md +71 -0
  69. package/package.json +25 -6
  70. package/stl/index.d.ts +1 -1
  71. package/stl/index.js +1 -1
  72. package/stl/stlSerializer.d.ts +17 -17
  73. package/stl/stlSerializer.js +107 -107
  74. package/stl/stlSerializer.js.map +1 -1
@@ -1,455 +1,456 @@
1
- import { IBufferView, IAccessor, INode, IMaterial, ITexture, IImage, ISampler, ImageMimeType, IMeshPrimitive, IGLTF, AccessorComponentType, ITextureInfo, ISkin } from "babylonjs-gltf2interface";
2
- import { FloatArray, Nullable } from "@babylonjs/core/types.js";
3
- import { Vector3, Vector4 } from "@babylonjs/core/Maths/math.vector.js";
4
- import { Node } from "@babylonjs/core/node.js";
5
- import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
6
- import { SubMesh } from "@babylonjs/core/Meshes/subMesh.js";
7
- import { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
8
- import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
9
- import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
10
- import { Material } from "@babylonjs/core/Materials/material.js";
11
- import { Scene } from "@babylonjs/core/scene.js";
12
- import { IGLTFExporterExtensionV2 } from "./glTFExporterExtension";
13
- import { _GLTFMaterialExporter } from "./glTFMaterialExporter";
14
- import { IExportOptions } from "./glTFSerializer";
15
- import { GLTFData } from "./glTFData";
16
- /**
17
- * Converts Babylon Scene into glTF 2.0.
18
- * @hidden
19
- */
20
- export declare class _Exporter {
21
- /**
22
- * Stores the glTF to export
23
- */
24
- _glTF: IGLTF;
25
- /**
26
- * Stores all generated buffer views, which represents views into the main glTF buffer data
27
- */
28
- _bufferViews: IBufferView[];
29
- /**
30
- * Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF
31
- */
32
- _accessors: IAccessor[];
33
- /**
34
- * Stores all the generated nodes, which contains transform and/or mesh information per node
35
- */
36
- _nodes: INode[];
37
- /**
38
- * Stores all the generated glTF scenes, which stores multiple node hierarchies
39
- */
40
- private _scenes;
41
- /**
42
- * Stores all the generated glTF cameras
43
- */
44
- private _cameras;
45
- /**
46
- * Stores all the generated mesh information, each containing a set of primitives to render in glTF
47
- */
48
- private _meshes;
49
- /**
50
- * Stores all the generated material information, which represents the appearance of each primitive
51
- */
52
- _materials: IMaterial[];
53
- _materialMap: {
54
- [materialID: number]: number;
55
- };
56
- /**
57
- * Stores all the generated texture information, which is referenced by glTF materials
58
- */
59
- _textures: ITexture[];
60
- /**
61
- * Stores all the generated image information, which is referenced by glTF textures
62
- */
63
- _images: IImage[];
64
- /**
65
- * Stores all the texture samplers
66
- */
67
- _samplers: ISampler[];
68
- /**
69
- * Stores all the generated glTF skins
70
- */
71
- _skins: ISkin[];
72
- /**
73
- * Stores all the generated animation samplers, which is referenced by glTF animations
74
- */
75
- /**
76
- * Stores the animations for glTF models
77
- */
78
- private _animations;
79
- /**
80
- * Stores the total amount of bytes stored in the glTF buffer
81
- */
82
- private _totalByteLength;
83
- /**
84
- * Stores a reference to the Babylon scene containing the source geometry and material information
85
- */
86
- _babylonScene: Scene;
87
- /**
88
- * Stores a map of the image data, where the key is the file name and the value
89
- * is the image data
90
- */
91
- _imageData: {
92
- [fileName: string]: {
93
- data: Uint8Array;
94
- mimeType: ImageMimeType;
95
- };
96
- };
97
- protected _orderedImageData: Array<{
98
- data: Uint8Array;
99
- mimeType: ImageMimeType;
100
- }>;
101
- /**
102
- * Stores a map of the unique id of a node to its index in the node array
103
- */
104
- _nodeMap: {
105
- [key: number]: number;
106
- };
107
- /**
108
- * Specifies if the source Babylon scene was left handed, and needed conversion.
109
- */
110
- _convertToRightHandedSystem: boolean;
111
- /**
112
- * Specifies if a Babylon node should be converted to right-handed on export
113
- */
114
- _convertToRightHandedSystemMap: {
115
- [nodeId: number]: boolean;
116
- };
117
- _includeCoordinateSystemConversionNodes: boolean;
118
- /**
119
- * Baked animation sample rate
120
- */
121
- private _animationSampleRate;
122
- private _options;
123
- private _localEngine;
124
- _glTFMaterialExporter: _GLTFMaterialExporter;
125
- private _extensions;
126
- private static _ExtensionNames;
127
- private static _ExtensionFactories;
128
- private _applyExtension;
129
- private _applyExtensions;
130
- _extensionsPreExportTextureAsync(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Nullable<BaseTexture>>;
131
- _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<Nullable<IMeshPrimitive>>;
132
- _extensionsPostExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
133
- [key: number]: number;
134
- }): Promise<Nullable<INode>>;
135
- _extensionsPostExportMaterialAsync(context: string, material: Nullable<IMaterial>, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
136
- _extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[];
137
- _extensionsPostExportTextures(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
138
- private _forEachExtensions;
139
- private _extensionsOnExporting;
140
- /**
141
- * Load glTF serializer extensions
142
- */
143
- private _loadExtensions;
144
- /**
145
- * Creates a glTF Exporter instance, which can accept optional exporter options
146
- * @param babylonScene Babylon scene object
147
- * @param options Options to modify the behavior of the exporter
148
- */
149
- constructor(babylonScene?: Nullable<Scene>, options?: IExportOptions);
150
- dispose(): void;
151
- /**
152
- * Registers a glTF exporter extension
153
- * @param name Name of the extension to export
154
- * @param factory The factory function that creates the exporter extension
155
- */
156
- static RegisterExtension(name: string, factory: (exporter: _Exporter) => IGLTFExporterExtensionV2): void;
157
- /**
158
- * Un-registers an exporter extension
159
- * @param name The name fo the exporter extension
160
- * @returns A boolean indicating whether the extension has been un-registered
161
- */
162
- static UnregisterExtension(name: string): boolean;
163
- private _reorderIndicesBasedOnPrimitiveMode;
164
- /**
165
- * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
166
- * clock-wise during export to glTF
167
- * @param submesh BabylonJS submesh
168
- * @param primitiveMode Primitive mode of the mesh
169
- * @param sideOrientation the winding order of the submesh
170
- * @param vertexBufferKind The type of vertex attribute
171
- * @param meshAttributeArray The vertex attribute data
172
- * @param byteOffset The offset to the binary data
173
- * @param binaryWriter The binary data for the glTF file
174
- * @param convertToRightHandedSystem Converts the values to right-handed
175
- */
176
- private _reorderVertexAttributeDataBasedOnPrimitiveMode;
177
- /**
178
- * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
179
- * clock-wise during export to glTF
180
- * @param submesh BabylonJS submesh
181
- * @param primitiveMode Primitive mode of the mesh
182
- * @param sideOrientation the winding order of the submesh
183
- * @param vertexBufferKind The type of vertex attribute
184
- * @param meshAttributeArray The vertex attribute data
185
- * @param byteOffset The offset to the binary data
186
- * @param binaryWriter The binary data for the glTF file
187
- * @param convertToRightHandedSystem Converts the values to right-handed
188
- */
189
- private _reorderTriangleFillMode;
190
- /**
191
- * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
192
- * clock-wise during export to glTF
193
- * @param submesh BabylonJS submesh
194
- * @param primitiveMode Primitive mode of the mesh
195
- * @param sideOrientation the winding order of the submesh
196
- * @param vertexBufferKind The type of vertex attribute
197
- * @param meshAttributeArray The vertex attribute data
198
- * @param byteOffset The offset to the binary data
199
- * @param binaryWriter The binary data for the glTF file
200
- * @param convertToRightHandedSystem Converts the values to right-handed
201
- */
202
- private _reorderTriangleStripDrawMode;
203
- /**
204
- * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
205
- * clock-wise during export to glTF
206
- * @param submesh BabylonJS submesh
207
- * @param primitiveMode Primitive mode of the mesh
208
- * @param sideOrientation the winding order of the submesh
209
- * @param vertexBufferKind The type of vertex attribute
210
- * @param meshAttributeArray The vertex attribute data
211
- * @param byteOffset The offset to the binary data
212
- * @param binaryWriter The binary data for the glTF file
213
- * @param convertToRightHandedSystem Converts the values to right-handed
214
- */
215
- private _reorderTriangleFanMode;
216
- /**
217
- * Writes the vertex attribute data to binary
218
- * @param vertices The vertices to write to the binary writer
219
- * @param byteOffset The offset into the binary writer to overwrite binary data
220
- * @param vertexAttributeKind The vertex attribute type
221
- * @param meshAttributeArray The vertex attribute data
222
- * @param binaryWriter The writer containing the binary data
223
- * @param convertToRightHandedSystem Converts the values to right-handed
224
- */
225
- private _writeVertexAttributeData;
226
- /**
227
- * Writes mesh attribute data to a data buffer
228
- * Returns the bytelength of the data
229
- * @param vertexBufferKind Indicates what kind of vertex data is being passed in
230
- * @param attributeComponentKind
231
- * @param meshAttributeArray Array containing the attribute data
232
- * @param stride Specifies the space between data
233
- * @param binaryWriter The buffer to write the binary data to
234
- * @param convertToRightHandedSystem Converts the values to right-handed
235
- * @param babylonTransformNode
236
- */
237
- _writeAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, babylonTransformNode: TransformNode): void;
238
- /**
239
- * Writes mesh attribute data to a data buffer
240
- * Returns the bytelength of the data
241
- * @param vertexBufferKind Indicates what kind of vertex data is being passed in
242
- * @param attributeComponentKind
243
- * @param meshPrimitive
244
- * @param morphTarget
245
- * @param meshAttributeArray Array containing the attribute data
246
- * @param morphTargetAttributeArray
247
- * @param stride Specifies the space between data
248
- * @param binaryWriter The buffer to write the binary data to
249
- * @param convertToRightHandedSystem Converts the values to right-handed
250
- * @param minMax
251
- */
252
- writeMorphTargetAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshPrimitive: SubMesh, morphTarget: MorphTarget, meshAttributeArray: FloatArray, morphTargetAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, minMax?: any): void;
253
- /**
254
- * Generates glTF json data
255
- * @param shouldUseGlb Indicates whether the json should be written for a glb file
256
- * @param glTFPrefix Text to use when prefixing a glTF file
257
- * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
258
- * @returns json data as string
259
- */
260
- private _generateJSON;
261
- /**
262
- * Generates data for .gltf and .bin files based on the glTF prefix string
263
- * @param glTFPrefix Text to use when prefixing a glTF file
264
- * @param dispose Dispose the exporter
265
- * @returns GLTFData with glTF file data
266
- */
267
- _generateGLTFAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
268
- /**
269
- * Creates a binary buffer for glTF
270
- * @returns array buffer for binary data
271
- */
272
- private _generateBinaryAsync;
273
- /**
274
- * Pads the number to a multiple of 4
275
- * @param num number to pad
276
- * @returns padded number
277
- */
278
- private _getPadding;
279
- /**
280
- * @param glTFPrefix
281
- * @param dispose
282
- * @hidden
283
- */
284
- _generateGLBAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
285
- /**
286
- * Sets the TRS for each node
287
- * @param node glTF Node for storing the transformation data
288
- * @param babylonTransformNode Babylon mesh used as the source for the transformation data
289
- * @param convertToRightHandedSystem Converts the values to right-handed
290
- */
291
- private _setNodeTransformation;
292
- private _setCameraTransformation;
293
- private _getVertexBufferFromMesh;
294
- /**
295
- * Creates a bufferview based on the vertices type for the Babylon mesh
296
- * @param kind Indicates the type of vertices data
297
- * @param attributeComponentKind Indicates the numerical type used to store the data
298
- * @param babylonTransformNode The Babylon mesh to get the vertices data from
299
- * @param binaryWriter The buffer to write the bufferview data to
300
- * @param byteStride
301
- * @param convertToRightHandedSystem Converts the values to right-handed
302
- */
303
- private _createBufferViewKind;
304
- /**
305
- * Creates a bufferview based on the vertices type for the Babylon mesh
306
- * @param babylonSubMesh The Babylon submesh that the morph target is applied to
307
- * @param meshPrimitive
308
- * @param babylonMorphTarget the morph target to be exported
309
- * @param binaryWriter The buffer to write the bufferview data to
310
- * @param convertToRightHandedSystem Converts the values to right-handed
311
- */
312
- private _setMorphTargetAttributes;
313
- /**
314
- * The primitive mode of the Babylon mesh
315
- * @param babylonMesh The BabylonJS mesh
316
- */
317
- private _getMeshPrimitiveMode;
318
- /**
319
- * Sets the primitive mode of the glTF mesh primitive
320
- * @param meshPrimitive glTF mesh primitive
321
- * @param primitiveMode The primitive mode
322
- */
323
- private _setPrimitiveMode;
324
- /**
325
- * Sets the vertex attribute accessor based of the glTF mesh primitive
326
- * @param meshPrimitive glTF mesh primitive
327
- * @param attributeKind vertex attribute
328
- * @returns boolean specifying if uv coordinates are present
329
- */
330
- private _setAttributeKind;
331
- /**
332
- * Sets data for the primitive attributes of each submesh
333
- * @param mesh glTF Mesh object to store the primitive attribute information
334
- * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
335
- * @param binaryWriter Buffer to write the attribute data to
336
- * @param convertToRightHandedSystem Converts the values to right-handed
337
- */
338
- private _setPrimitiveAttributesAsync;
339
- /**
340
- * Check if the node is used to convert its descendants from a right handed coordinate system to the Babylon scene's coordinate system.
341
- * @param node The node to check
342
- * @returns True if the node is used to convert its descendants from right-handed to left-handed. False otherwise
343
- */
344
- private _isBabylonCoordinateSystemConvertingNode;
345
- /**
346
- * Creates a glTF scene based on the array of meshes
347
- * Returns the the total byte offset
348
- * @param babylonScene Babylon scene to get the mesh data from
349
- * @param binaryWriter Buffer to write binary data to
350
- */
351
- private _createSceneAsync;
352
- /**
353
- * Getting the nodes and materials that would be exported.
354
- * @param nodes Babylon transform nodes
355
- * @returns Array of nodes which would be exported.
356
- * @returns Set of materials which would be exported.
357
- */
358
- private _getExportNodes;
359
- /**
360
- * Creates a mapping of Node unique id to node index and handles animations
361
- * @param babylonScene Babylon Scene
362
- * @param nodes Babylon transform nodes
363
- * @param binaryWriter Buffer to write binary data to
364
- * @returns Node mapping of unique id to index
365
- */
366
- private _createNodeMapAndAnimationsAsync;
367
- /**
368
- * Creates a glTF node from a Babylon mesh
369
- * @param babylonNode Source Babylon mesh
370
- * @param binaryWriter Buffer for storing geometry data
371
- * @param convertToRightHandedSystem Converts the values to right-handed
372
- * @returns glTF node
373
- */
374
- private _createNodeAsync;
375
- /**
376
- * Creates a glTF skin from a Babylon skeleton
377
- * @param babylonScene Babylon Scene
378
- * @param nodeMap Babylon transform nodes
379
- * @param binaryWriter Buffer to write binary data to
380
- * @returns Node mapping of unique id to index
381
- */
382
- private _createSkinsAsync;
383
- }
384
- /**
385
- * @hidden
386
- *
387
- * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
388
- */
389
- export declare class _BinaryWriter {
390
- /**
391
- * Array buffer which stores all binary data
392
- */
393
- private _arrayBuffer;
394
- /**
395
- * View of the array buffer
396
- */
397
- private _dataView;
398
- /**
399
- * byte offset of data in array buffer
400
- */
401
- private _byteOffset;
402
- /**
403
- * Initialize binary writer with an initial byte length
404
- * @param byteLength Initial byte length of the array buffer
405
- */
406
- constructor(byteLength: number);
407
- /**
408
- * Resize the array buffer to the specified byte length
409
- * @param byteLength
410
- */
411
- private _resizeBuffer;
412
- /**
413
- * Get an array buffer with the length of the byte offset
414
- * @returns ArrayBuffer resized to the byte offset
415
- */
416
- getArrayBuffer(): ArrayBuffer;
417
- /**
418
- * Get the byte offset of the array buffer
419
- * @returns byte offset
420
- */
421
- getByteOffset(): number;
422
- /**
423
- * Stores an UInt8 in the array buffer
424
- * @param entry
425
- * @param byteOffset If defined, specifies where to set the value as an offset.
426
- */
427
- setUInt8(entry: number, byteOffset?: number): void;
428
- /**
429
- * Stores an UInt16 in the array buffer
430
- * @param entry
431
- * @param byteOffset If defined, specifies where to set the value as an offset.
432
- */
433
- setUInt16(entry: number, byteOffset?: number): void;
434
- /**
435
- * Gets an UInt32 in the array buffer
436
- * @param byteOffset If defined, specifies where to set the value as an offset.
437
- */
438
- getUInt32(byteOffset: number): number;
439
- getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
440
- setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
441
- getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
442
- setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
443
- /**
444
- * Stores a Float32 in the array buffer
445
- * @param entry
446
- * @param byteOffset
447
- */
448
- setFloat32(entry: number, byteOffset?: number): void;
449
- /**
450
- * Stores an UInt32 in the array buffer
451
- * @param entry
452
- * @param byteOffset If defined, specifies where to set the value as an offset.
453
- */
454
- setUInt32(entry: number, byteOffset?: number): void;
455
- }
1
+ import type { IBufferView, IAccessor, INode, IMaterial, ITexture, IImage, ISampler, IMeshPrimitive, IGLTF, ITextureInfo, ISkin } from "babylonjs-gltf2interface/.js";
2
+ import { ImageMimeType, AccessorComponentType } from "babylonjs-gltf2interface/.js";
3
+ import type { FloatArray, Nullable } from "@babylonjs/core/types.js";
4
+ import { Vector3, Vector4 } from "@babylonjs/core/Maths/math.vector.js";
5
+ import type { Node } from "@babylonjs/core/node.js";
6
+ import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
7
+ import type { SubMesh } from "@babylonjs/core/Meshes/subMesh.js";
8
+ import type { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
9
+ import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
10
+ import type { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
11
+ import { Material } from "@babylonjs/core/Materials/material.js";
12
+ import type { Scene } from "@babylonjs/core/scene.js";
13
+ import type { IGLTFExporterExtensionV2 } from "./glTFExporterExtension";
14
+ import { _GLTFMaterialExporter } from "./glTFMaterialExporter";
15
+ import type { IExportOptions } from "./glTFSerializer";
16
+ import { GLTFData } from "./glTFData";
17
+ /**
18
+ * Converts Babylon Scene into glTF 2.0.
19
+ * @hidden
20
+ */
21
+ export declare class _Exporter {
22
+ /**
23
+ * Stores the glTF to export
24
+ */
25
+ _glTF: IGLTF;
26
+ /**
27
+ * Stores all generated buffer views, which represents views into the main glTF buffer data
28
+ */
29
+ _bufferViews: IBufferView[];
30
+ /**
31
+ * Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF
32
+ */
33
+ _accessors: IAccessor[];
34
+ /**
35
+ * Stores all the generated nodes, which contains transform and/or mesh information per node
36
+ */
37
+ _nodes: INode[];
38
+ /**
39
+ * Stores all the generated glTF scenes, which stores multiple node hierarchies
40
+ */
41
+ private _scenes;
42
+ /**
43
+ * Stores all the generated glTF cameras
44
+ */
45
+ private _cameras;
46
+ /**
47
+ * Stores all the generated mesh information, each containing a set of primitives to render in glTF
48
+ */
49
+ private _meshes;
50
+ /**
51
+ * Stores all the generated material information, which represents the appearance of each primitive
52
+ */
53
+ _materials: IMaterial[];
54
+ _materialMap: {
55
+ [materialID: number]: number;
56
+ };
57
+ /**
58
+ * Stores all the generated texture information, which is referenced by glTF materials
59
+ */
60
+ _textures: ITexture[];
61
+ /**
62
+ * Stores all the generated image information, which is referenced by glTF textures
63
+ */
64
+ _images: IImage[];
65
+ /**
66
+ * Stores all the texture samplers
67
+ */
68
+ _samplers: ISampler[];
69
+ /**
70
+ * Stores all the generated glTF skins
71
+ */
72
+ _skins: ISkin[];
73
+ /**
74
+ * Stores all the generated animation samplers, which is referenced by glTF animations
75
+ */
76
+ /**
77
+ * Stores the animations for glTF models
78
+ */
79
+ private _animations;
80
+ /**
81
+ * Stores the total amount of bytes stored in the glTF buffer
82
+ */
83
+ private _totalByteLength;
84
+ /**
85
+ * Stores a reference to the Babylon scene containing the source geometry and material information
86
+ */
87
+ _babylonScene: Scene;
88
+ /**
89
+ * Stores a map of the image data, where the key is the file name and the value
90
+ * is the image data
91
+ */
92
+ _imageData: {
93
+ [fileName: string]: {
94
+ data: Uint8Array;
95
+ mimeType: ImageMimeType;
96
+ };
97
+ };
98
+ protected _orderedImageData: Array<{
99
+ data: Uint8Array;
100
+ mimeType: ImageMimeType;
101
+ }>;
102
+ /**
103
+ * Stores a map of the unique id of a node to its index in the node array
104
+ */
105
+ _nodeMap: {
106
+ [key: number]: number;
107
+ };
108
+ /**
109
+ * Specifies if the source Babylon scene was left handed, and needed conversion.
110
+ */
111
+ _convertToRightHandedSystem: boolean;
112
+ /**
113
+ * Specifies if a Babylon node should be converted to right-handed on export
114
+ */
115
+ _convertToRightHandedSystemMap: {
116
+ [nodeId: number]: boolean;
117
+ };
118
+ _includeCoordinateSystemConversionNodes: boolean;
119
+ /**
120
+ * Baked animation sample rate
121
+ */
122
+ private _animationSampleRate;
123
+ private _options;
124
+ private _localEngine;
125
+ _glTFMaterialExporter: _GLTFMaterialExporter;
126
+ private _extensions;
127
+ private static _ExtensionNames;
128
+ private static _ExtensionFactories;
129
+ private _applyExtension;
130
+ private _applyExtensions;
131
+ _extensionsPreExportTextureAsync(context: string, babylonTexture: Nullable<Texture>, mimeType: ImageMimeType): Promise<Nullable<BaseTexture>>;
132
+ _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<Nullable<IMeshPrimitive>>;
133
+ _extensionsPostExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
134
+ [key: number]: number;
135
+ }): Promise<Nullable<INode>>;
136
+ _extensionsPostExportMaterialAsync(context: string, material: Nullable<IMaterial>, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
137
+ _extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[];
138
+ _extensionsPostExportTextures(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
139
+ private _forEachExtensions;
140
+ private _extensionsOnExporting;
141
+ /**
142
+ * Load glTF serializer extensions
143
+ */
144
+ private _loadExtensions;
145
+ /**
146
+ * Creates a glTF Exporter instance, which can accept optional exporter options
147
+ * @param babylonScene Babylon scene object
148
+ * @param options Options to modify the behavior of the exporter
149
+ */
150
+ constructor(babylonScene?: Nullable<Scene>, options?: IExportOptions);
151
+ dispose(): void;
152
+ /**
153
+ * Registers a glTF exporter extension
154
+ * @param name Name of the extension to export
155
+ * @param factory The factory function that creates the exporter extension
156
+ */
157
+ static RegisterExtension(name: string, factory: (exporter: _Exporter) => IGLTFExporterExtensionV2): void;
158
+ /**
159
+ * Un-registers an exporter extension
160
+ * @param name The name fo the exporter extension
161
+ * @returns A boolean indicating whether the extension has been un-registered
162
+ */
163
+ static UnregisterExtension(name: string): boolean;
164
+ private _reorderIndicesBasedOnPrimitiveMode;
165
+ /**
166
+ * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
167
+ * clock-wise during export to glTF
168
+ * @param submesh BabylonJS submesh
169
+ * @param primitiveMode Primitive mode of the mesh
170
+ * @param sideOrientation the winding order of the submesh
171
+ * @param vertexBufferKind The type of vertex attribute
172
+ * @param meshAttributeArray The vertex attribute data
173
+ * @param byteOffset The offset to the binary data
174
+ * @param binaryWriter The binary data for the glTF file
175
+ * @param convertToRightHandedSystem Converts the values to right-handed
176
+ */
177
+ private _reorderVertexAttributeDataBasedOnPrimitiveMode;
178
+ /**
179
+ * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
180
+ * clock-wise during export to glTF
181
+ * @param submesh BabylonJS submesh
182
+ * @param primitiveMode Primitive mode of the mesh
183
+ * @param sideOrientation the winding order of the submesh
184
+ * @param vertexBufferKind The type of vertex attribute
185
+ * @param meshAttributeArray The vertex attribute data
186
+ * @param byteOffset The offset to the binary data
187
+ * @param binaryWriter The binary data for the glTF file
188
+ * @param convertToRightHandedSystem Converts the values to right-handed
189
+ */
190
+ private _reorderTriangleFillMode;
191
+ /**
192
+ * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
193
+ * clock-wise during export to glTF
194
+ * @param submesh BabylonJS submesh
195
+ * @param primitiveMode Primitive mode of the mesh
196
+ * @param sideOrientation the winding order of the submesh
197
+ * @param vertexBufferKind The type of vertex attribute
198
+ * @param meshAttributeArray The vertex attribute data
199
+ * @param byteOffset The offset to the binary data
200
+ * @param binaryWriter The binary data for the glTF file
201
+ * @param convertToRightHandedSystem Converts the values to right-handed
202
+ */
203
+ private _reorderTriangleStripDrawMode;
204
+ /**
205
+ * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
206
+ * clock-wise during export to glTF
207
+ * @param submesh BabylonJS submesh
208
+ * @param primitiveMode Primitive mode of the mesh
209
+ * @param sideOrientation the winding order of the submesh
210
+ * @param vertexBufferKind The type of vertex attribute
211
+ * @param meshAttributeArray The vertex attribute data
212
+ * @param byteOffset The offset to the binary data
213
+ * @param binaryWriter The binary data for the glTF file
214
+ * @param convertToRightHandedSystem Converts the values to right-handed
215
+ */
216
+ private _reorderTriangleFanMode;
217
+ /**
218
+ * Writes the vertex attribute data to binary
219
+ * @param vertices The vertices to write to the binary writer
220
+ * @param byteOffset The offset into the binary writer to overwrite binary data
221
+ * @param vertexAttributeKind The vertex attribute type
222
+ * @param meshAttributeArray The vertex attribute data
223
+ * @param binaryWriter The writer containing the binary data
224
+ * @param convertToRightHandedSystem Converts the values to right-handed
225
+ */
226
+ private _writeVertexAttributeData;
227
+ /**
228
+ * Writes mesh attribute data to a data buffer
229
+ * Returns the bytelength of the data
230
+ * @param vertexBufferKind Indicates what kind of vertex data is being passed in
231
+ * @param attributeComponentKind
232
+ * @param meshAttributeArray Array containing the attribute data
233
+ * @param stride Specifies the space between data
234
+ * @param binaryWriter The buffer to write the binary data to
235
+ * @param convertToRightHandedSystem Converts the values to right-handed
236
+ * @param babylonTransformNode
237
+ */
238
+ _writeAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, babylonTransformNode: TransformNode): void;
239
+ /**
240
+ * Writes mesh attribute data to a data buffer
241
+ * Returns the bytelength of the data
242
+ * @param vertexBufferKind Indicates what kind of vertex data is being passed in
243
+ * @param attributeComponentKind
244
+ * @param meshPrimitive
245
+ * @param morphTarget
246
+ * @param meshAttributeArray Array containing the attribute data
247
+ * @param morphTargetAttributeArray
248
+ * @param stride Specifies the space between data
249
+ * @param binaryWriter The buffer to write the binary data to
250
+ * @param convertToRightHandedSystem Converts the values to right-handed
251
+ * @param minMax
252
+ */
253
+ writeMorphTargetAttributeData(vertexBufferKind: string, attributeComponentKind: AccessorComponentType, meshPrimitive: SubMesh, morphTarget: MorphTarget, meshAttributeArray: FloatArray, morphTargetAttributeArray: FloatArray, stride: number, binaryWriter: _BinaryWriter, convertToRightHandedSystem: boolean, minMax?: any): void;
254
+ /**
255
+ * Generates glTF json data
256
+ * @param shouldUseGlb Indicates whether the json should be written for a glb file
257
+ * @param glTFPrefix Text to use when prefixing a glTF file
258
+ * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
259
+ * @returns json data as string
260
+ */
261
+ private _generateJSON;
262
+ /**
263
+ * Generates data for .gltf and .bin files based on the glTF prefix string
264
+ * @param glTFPrefix Text to use when prefixing a glTF file
265
+ * @param dispose Dispose the exporter
266
+ * @returns GLTFData with glTF file data
267
+ */
268
+ _generateGLTFAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
269
+ /**
270
+ * Creates a binary buffer for glTF
271
+ * @returns array buffer for binary data
272
+ */
273
+ private _generateBinaryAsync;
274
+ /**
275
+ * Pads the number to a multiple of 4
276
+ * @param num number to pad
277
+ * @returns padded number
278
+ */
279
+ private _getPadding;
280
+ /**
281
+ * @param glTFPrefix
282
+ * @param dispose
283
+ * @hidden
284
+ */
285
+ _generateGLBAsync(glTFPrefix: string, dispose?: boolean): Promise<GLTFData>;
286
+ /**
287
+ * Sets the TRS for each node
288
+ * @param node glTF Node for storing the transformation data
289
+ * @param babylonTransformNode Babylon mesh used as the source for the transformation data
290
+ * @param convertToRightHandedSystem Converts the values to right-handed
291
+ */
292
+ private _setNodeTransformation;
293
+ private _setCameraTransformation;
294
+ private _getVertexBufferFromMesh;
295
+ /**
296
+ * Creates a bufferview based on the vertices type for the Babylon mesh
297
+ * @param kind Indicates the type of vertices data
298
+ * @param attributeComponentKind Indicates the numerical type used to store the data
299
+ * @param babylonTransformNode The Babylon mesh to get the vertices data from
300
+ * @param binaryWriter The buffer to write the bufferview data to
301
+ * @param byteStride
302
+ * @param convertToRightHandedSystem Converts the values to right-handed
303
+ */
304
+ private _createBufferViewKind;
305
+ /**
306
+ * Creates a bufferview based on the vertices type for the Babylon mesh
307
+ * @param babylonSubMesh The Babylon submesh that the morph target is applied to
308
+ * @param meshPrimitive
309
+ * @param babylonMorphTarget the morph target to be exported
310
+ * @param binaryWriter The buffer to write the bufferview data to
311
+ * @param convertToRightHandedSystem Converts the values to right-handed
312
+ */
313
+ private _setMorphTargetAttributes;
314
+ /**
315
+ * The primitive mode of the Babylon mesh
316
+ * @param babylonMesh The BabylonJS mesh
317
+ */
318
+ private _getMeshPrimitiveMode;
319
+ /**
320
+ * Sets the primitive mode of the glTF mesh primitive
321
+ * @param meshPrimitive glTF mesh primitive
322
+ * @param primitiveMode The primitive mode
323
+ */
324
+ private _setPrimitiveMode;
325
+ /**
326
+ * Sets the vertex attribute accessor based of the glTF mesh primitive
327
+ * @param meshPrimitive glTF mesh primitive
328
+ * @param attributeKind vertex attribute
329
+ * @returns boolean specifying if uv coordinates are present
330
+ */
331
+ private _setAttributeKind;
332
+ /**
333
+ * Sets data for the primitive attributes of each submesh
334
+ * @param mesh glTF Mesh object to store the primitive attribute information
335
+ * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
336
+ * @param binaryWriter Buffer to write the attribute data to
337
+ * @param convertToRightHandedSystem Converts the values to right-handed
338
+ */
339
+ private _setPrimitiveAttributesAsync;
340
+ /**
341
+ * Check if the node is used to convert its descendants from a right handed coordinate system to the Babylon scene's coordinate system.
342
+ * @param node The node to check
343
+ * @returns True if the node is used to convert its descendants from right-handed to left-handed. False otherwise
344
+ */
345
+ private _isBabylonCoordinateSystemConvertingNode;
346
+ /**
347
+ * Creates a glTF scene based on the array of meshes
348
+ * Returns the the total byte offset
349
+ * @param babylonScene Babylon scene to get the mesh data from
350
+ * @param binaryWriter Buffer to write binary data to
351
+ */
352
+ private _createSceneAsync;
353
+ /**
354
+ * Getting the nodes and materials that would be exported.
355
+ * @param nodes Babylon transform nodes
356
+ * @returns Array of nodes which would be exported.
357
+ * @returns Set of materials which would be exported.
358
+ */
359
+ private _getExportNodes;
360
+ /**
361
+ * Creates a mapping of Node unique id to node index and handles animations
362
+ * @param babylonScene Babylon Scene
363
+ * @param nodes Babylon transform nodes
364
+ * @param binaryWriter Buffer to write binary data to
365
+ * @returns Node mapping of unique id to index
366
+ */
367
+ private _createNodeMapAndAnimationsAsync;
368
+ /**
369
+ * Creates a glTF node from a Babylon mesh
370
+ * @param babylonNode Source Babylon mesh
371
+ * @param binaryWriter Buffer for storing geometry data
372
+ * @param convertToRightHandedSystem Converts the values to right-handed
373
+ * @returns glTF node
374
+ */
375
+ private _createNodeAsync;
376
+ /**
377
+ * Creates a glTF skin from a Babylon skeleton
378
+ * @param babylonScene Babylon Scene
379
+ * @param nodeMap Babylon transform nodes
380
+ * @param binaryWriter Buffer to write binary data to
381
+ * @returns Node mapping of unique id to index
382
+ */
383
+ private _createSkinsAsync;
384
+ }
385
+ /**
386
+ * @hidden
387
+ *
388
+ * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
389
+ */
390
+ export declare class _BinaryWriter {
391
+ /**
392
+ * Array buffer which stores all binary data
393
+ */
394
+ private _arrayBuffer;
395
+ /**
396
+ * View of the array buffer
397
+ */
398
+ private _dataView;
399
+ /**
400
+ * byte offset of data in array buffer
401
+ */
402
+ private _byteOffset;
403
+ /**
404
+ * Initialize binary writer with an initial byte length
405
+ * @param byteLength Initial byte length of the array buffer
406
+ */
407
+ constructor(byteLength: number);
408
+ /**
409
+ * Resize the array buffer to the specified byte length
410
+ * @param byteLength
411
+ */
412
+ private _resizeBuffer;
413
+ /**
414
+ * Get an array buffer with the length of the byte offset
415
+ * @returns ArrayBuffer resized to the byte offset
416
+ */
417
+ getArrayBuffer(): ArrayBuffer;
418
+ /**
419
+ * Get the byte offset of the array buffer
420
+ * @returns byte offset
421
+ */
422
+ getByteOffset(): number;
423
+ /**
424
+ * Stores an UInt8 in the array buffer
425
+ * @param entry
426
+ * @param byteOffset If defined, specifies where to set the value as an offset.
427
+ */
428
+ setUInt8(entry: number, byteOffset?: number): void;
429
+ /**
430
+ * Stores an UInt16 in the array buffer
431
+ * @param entry
432
+ * @param byteOffset If defined, specifies where to set the value as an offset.
433
+ */
434
+ setUInt16(entry: number, byteOffset?: number): void;
435
+ /**
436
+ * Gets an UInt32 in the array buffer
437
+ * @param byteOffset If defined, specifies where to set the value as an offset.
438
+ */
439
+ getUInt32(byteOffset: number): number;
440
+ getVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
441
+ setVector3Float32FromRef(vector3: Vector3, byteOffset: number): void;
442
+ getVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
443
+ setVector4Float32FromRef(vector4: Vector4, byteOffset: number): void;
444
+ /**
445
+ * Stores a Float32 in the array buffer
446
+ * @param entry
447
+ * @param byteOffset
448
+ */
449
+ setFloat32(entry: number, byteOffset?: number): void;
450
+ /**
451
+ * Stores an UInt32 in the array buffer
452
+ * @param entry
453
+ * @param byteOffset If defined, specifies where to set the value as an offset.
454
+ */
455
+ setUInt32(entry: number, byteOffset?: number): void;
456
+ }