babylonjs-serializers 9.26.1 → 9.27.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.
@@ -182,10 +182,79 @@ declare namespace BABYLON {
182
182
  export function OmitDefaultValues<T extends object>(object: T, defaultValues: Partial<T>): T;
183
183
 
184
184
 
185
+ /**
186
+ * Indexed glTF root collections that KHR_interactivity references can target.
187
+ */
188
+ export type KhrInteractivityRootCollection = "nodes" | "animations" | "cameras" | "materials" | "meshes" | "textures" | "images" | "samplers" | "skins" | "scenes";
185
189
  /**
186
190
  * Mesh compression methods.
187
191
  */
188
192
  export type MeshCompressionMethod = "None" | "Draco";
193
+ /**
194
+ * Final entity remapping context exposed to a KHR_interactivity export provider.
195
+ */
196
+ export interface IKHRInteractivityExportContext {
197
+ /**
198
+ * Gets the final number of glTF nodes.
199
+ * @returns final glTF node count
200
+ */
201
+ getNodeCount(): number;
202
+ /**
203
+ * Gets the final glTF node index for a Babylon node.
204
+ * @param node Babylon node to resolve
205
+ * @returns final glTF node index, or undefined when the node was not exported
206
+ */
207
+ getNodeIndex(node: Node): number | undefined;
208
+ /**
209
+ * Gets the final glTF animation index for a Babylon animation group.
210
+ * @param animation Babylon animation group to resolve
211
+ * @returns final glTF animation index, or undefined when the animation was not exported
212
+ */
213
+ getAnimationIndex(animation: AnimationGroup): number | undefined;
214
+ /**
215
+ * Gets the final glTF camera index for a Babylon camera.
216
+ * @param camera Babylon camera to resolve
217
+ * @returns final glTF camera index, or undefined when the camera was not exported
218
+ */
219
+ getCameraIndex(camera: Camera): number | undefined;
220
+ /**
221
+ * Gets the final glTF material index for a Babylon material.
222
+ * @param material Babylon material to resolve
223
+ * @returns final glTF material index, or undefined when the material was not exported
224
+ */
225
+ getMaterialIndex(material: Material): number | undefined;
226
+ /**
227
+ * Gets the final glTF index for an imported Babylon entity in a root collection.
228
+ * @param collection target glTF root collection
229
+ * @param entity imported Babylon entity associated with the source entry
230
+ * @returns final glTF index, or undefined when the entity was not exported uniquely
231
+ */
232
+ getRootIndex?(collection: KhrInteractivityRootCollection, entity: object): number | undefined;
233
+ /**
234
+ * Writes a companion extension on an already-exported glTF node.
235
+ * @param nodeIndex final glTF node index
236
+ * @param extensionName companion extension name
237
+ * @param value companion extension payload
238
+ */
239
+ setNodeExtension(nodeIndex: number, extensionName: string, value: unknown): void;
240
+ }
241
+ /**
242
+ * Supplies a detached canonical KHR_interactivity document to the glTF serializer.
243
+ */
244
+ export interface IKHRInteractivityExportProvider {
245
+ /** Whether KHR_interactivity must be listed in extensionsRequired. */
246
+ readonly required: boolean;
247
+ /** Additional operation or companion extensions referenced by the graph. */
248
+ readonly additionalExtensionsUsed: readonly string[];
249
+ /** Additional extensions that must be listed in extensionsRequired. */
250
+ readonly additionalExtensionsRequired: readonly string[];
251
+ /**
252
+ * Builds the extension after final glTF entity indices are available.
253
+ * @param context final serializer remapping context
254
+ * @returns canonical KHR_interactivity extension payload
255
+ */
256
+ build(context: IKHRInteractivityExportContext): BABYLON.GLTF2.IKHRInteractivity;
257
+ }
189
258
  /**
190
259
  * Holds a collection of exporter options and parameters
191
260
  */
@@ -222,7 +291,8 @@ declare namespace BABYLON {
222
291
  */
223
292
  exportUnusedUVs?: boolean;
224
293
  /**
225
- * Remove no-op root nodes when possible. Defaults to true.
294
+ * Remove no-op root nodes when possible. Defaults to true. No-op roots are preserved when
295
+ * {@link khrInteractivity} is provided because the graph may reference them.
226
296
  */
227
297
  removeNoopRootNodes?: boolean;
228
298
  /**
@@ -234,6 +304,11 @@ declare namespace BABYLON {
234
304
  * Indicates what compression method to apply to mesh data.
235
305
  */
236
306
  meshCompressionMethod?: MeshCompressionMethod;
307
+ /**
308
+ * Canonical KHR_interactivity export provider. The provider is evaluated only after scene
309
+ * nodes and animations have their final glTF indices.
310
+ */
311
+ khrInteractivity?: IKHRInteractivityExportProvider;
237
312
  }
238
313
  /**
239
314
  * Class for generating glTF data from a Babylon scene.
@@ -461,6 +536,7 @@ declare namespace BABYLON {
461
536
  readonly _bufferManager: BufferManager;
462
537
  private readonly _shouldExportNodeMap;
463
538
  private readonly _nodeMap;
539
+ private readonly _animationGroupMap;
464
540
  readonly _materialMap: Map<Material, number>;
465
541
  private readonly _camerasMap;
466
542
  private readonly _nodesCameraMap;
@@ -490,7 +566,7 @@ declare namespace BABYLON {
490
566
  private _loadExtensions;
491
567
  constructor(babylonScene?: Nullable<Scene>, options?: IExportOptions);
492
568
  dispose(): void;
493
- get options(): Required<IExportOptions>;
569
+ get options(): Required<Omit<IExportOptions, "khrInteractivity">> & Pick<IExportOptions, "khrInteractivity">;
494
570
  static RegisterExtension(name: string, factory: (exporter: GLTFExporter) => IGLTFExporterExtensionV2, order?: number): void;
495
571
  static UnregisterExtension(name: string): boolean;
496
572
  private _generateJSON;
@@ -510,6 +586,18 @@ declare namespace BABYLON {
510
586
  private _listAvailableSkeletons;
511
587
  private _exportAndAssignSkeletons;
512
588
  private _exportSceneAsync;
589
+ /** @internal */
590
+ _getNodeIndex(node: Node): number | undefined;
591
+ /** @internal */
592
+ _getAnimationIndex(animationGroup: AnimationGroup): number | undefined;
593
+ /** @internal */
594
+ _getCameraIndex(camera: Camera): number | undefined;
595
+ /** @internal */
596
+ _getMaterialIndex(material: Material): number | undefined;
597
+ /** @internal */
598
+ _getRootIndex(collection: KhrInteractivityRootCollection, entity: object): number | undefined;
599
+ /** @internal */
600
+ _setNodeExtension(nodeIndex: number, extensionName: string, value: unknown): void;
513
601
  private _shouldExportNode;
514
602
  private _exportNodesAsync;
515
603
  private _collectBuffers;
@@ -633,6 +721,8 @@ declare namespace BABYLON {
633
721
  * @param bufferViews
634
722
  * @param accessors
635
723
  * @param animationSampleRate
724
+ * @param useRightHanded
725
+ * @param shouldExportAnimation
636
726
  */
637
727
  static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: BABYLON.GLTF2.IAnimation, idleGLTFAnimations: BABYLON.GLTF2.IAnimation[], nodeMap: Map<Node, number>, nodes: BABYLON.GLTF2.INode[], bufferManager: BufferManager, bufferViews: BABYLON.GLTF2.IBufferView[], accessors: BABYLON.GLTF2.IAccessor[], animationSampleRate: number, useRightHanded: boolean, shouldExportAnimation?: (animation: Animation) => boolean): void;
638
728
  /**
@@ -647,6 +737,8 @@ declare namespace BABYLON {
647
737
  * @param bufferViews
648
738
  * @param accessors
649
739
  * @param animationSampleRate
740
+ * @param useRightHanded
741
+ * @param shouldExportAnimation
650
742
  */
651
743
  static _CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode: Node, runtimeGLTFAnimation: BABYLON.GLTF2.IAnimation, idleGLTFAnimations: BABYLON.GLTF2.IAnimation[], nodeMap: Map<Node, number>, nodes: BABYLON.GLTF2.INode[], bufferManager: BufferManager, bufferViews: BABYLON.GLTF2.IBufferView[], accessors: BABYLON.GLTF2.IAccessor[], animationSampleRate: number, useRightHanded: boolean, shouldExportAnimation?: (animation: Animation) => boolean): void;
652
744
  /**
@@ -660,8 +752,11 @@ declare namespace BABYLON {
660
752
  * @param bufferViews
661
753
  * @param accessors
662
754
  * @param animationSampleRate
755
+ * @param leftHandedNodes nodes that require right-handed conversion
756
+ * @param shouldExportAnimation optional animation filter
757
+ * @param animationGroupMap final glTF animation index for each exported Babylon animation group
663
758
  */
664
- static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: BABYLON.GLTF2.IAnimation[], nodeMap: Map<Node, number>, bufferManager: BufferManager, bufferViews: BABYLON.GLTF2.IBufferView[], accessors: BABYLON.GLTF2.IAccessor[], animationSampleRate: number, leftHandedNodes: Set<Node>, shouldExportAnimation?: (animation: Animation) => boolean): void;
759
+ static _CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene: Scene, glTFAnimations: BABYLON.GLTF2.IAnimation[], nodeMap: Map<Node, number>, bufferManager: BufferManager, bufferViews: BABYLON.GLTF2.IBufferView[], accessors: BABYLON.GLTF2.IAccessor[], animationSampleRate: number, leftHandedNodes: Set<Node>, shouldExportAnimation?: (animation: Animation) => boolean, animationGroupMap?: Map<AnimationGroup, number>): void;
665
760
  private static _AddAnimation;
666
761
  /**
667
762
  * Create a baked animation
@@ -1625,6 +1720,41 @@ declare namespace BABYLON {
1625
1720
  */
1626
1721
 
1627
1722
 
1723
+ /**
1724
+ * [Specification](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_interactivity)
1725
+ */
1726
+ export class KHR_interactivity implements IGLTFExporterExtensionV2 {
1727
+ private _exporter;
1728
+ /** The extension name. */
1729
+ readonly name = "KHR_interactivity";
1730
+ /** Whether this extension is enabled for the current export. */
1731
+ readonly enabled: boolean;
1732
+ /** Whether this extension is required for the exported asset. */
1733
+ readonly required: boolean;
1734
+ /**
1735
+ * @param _exporter owning glTF exporter
1736
+ */
1737
+ constructor(_exporter: GLTFExporter);
1738
+ /** @internal */
1739
+ dispose(): void;
1740
+ /** @internal */
1741
+ get wasUsed(): boolean;
1742
+ /** @internal */
1743
+ onExporting(): void;
1744
+ }
1745
+ /**
1746
+ * Registers the KHR_interactivity glTF serializer extension with the {@link GLTFExporter}.
1747
+ * Safe to call multiple times; only the first call has an effect.
1748
+ */
1749
+ export function RegisterKHR_interactivity(): void;
1750
+
1751
+
1752
+ /**
1753
+ * Re-exports the pure implementation and applies the runtime registration side effect.
1754
+ * Import "./KHR_interactivity.pure" for tree-shakeable, side-effect-free usage.
1755
+ */
1756
+
1757
+
1628
1758
  /**
1629
1759
  * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)
1630
1760
  */