@onerjs/serializers 8.56.4 → 9.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.
@@ -1,13 +1,85 @@
1
1
  import { type Node } from "@onerjs/core/node.js";
2
2
  import { type Scene } from "@onerjs/core/scene.js";
3
3
  import { type Animation } from "@onerjs/core/Animations/animation.js";
4
- import { type GLTFData } from "./glTFData.js";
4
+ import { type AnimationGroup } from "@onerjs/core/Animations/animationGroup.js";
5
+ import { type Camera } from "@onerjs/core/Cameras/camera.js";
5
6
  import { type Material } from "@onerjs/core/Materials/material.js";
7
+ import { type IKHRInteractivity } from "babylonjs-gltf2interface";
8
+ import { type GLTFData } from "./glTFData.js";
6
9
  import { type INode } from "babylonjs-gltf2interface";
10
+ /**
11
+ * Indexed glTF root collections that KHR_interactivity references can target.
12
+ */
13
+ export type KhrInteractivityRootCollection = "nodes" | "animations" | "cameras" | "materials" | "meshes" | "textures" | "images" | "samplers" | "skins" | "scenes";
7
14
  /**
8
15
  * Mesh compression methods.
9
16
  */
10
17
  export type MeshCompressionMethod = "None" | "Draco";
18
+ /**
19
+ * Final entity remapping context exposed to a KHR_interactivity export provider.
20
+ */
21
+ export interface IKHRInteractivityExportContext {
22
+ /**
23
+ * Gets the final number of glTF nodes.
24
+ * @returns final glTF node count
25
+ */
26
+ getNodeCount(): number;
27
+ /**
28
+ * Gets the final glTF node index for a Babylon node.
29
+ * @param node Babylon node to resolve
30
+ * @returns final glTF node index, or undefined when the node was not exported
31
+ */
32
+ getNodeIndex(node: Node): number | undefined;
33
+ /**
34
+ * Gets the final glTF animation index for a Babylon animation group.
35
+ * @param animation Babylon animation group to resolve
36
+ * @returns final glTF animation index, or undefined when the animation was not exported
37
+ */
38
+ getAnimationIndex(animation: AnimationGroup): number | undefined;
39
+ /**
40
+ * Gets the final glTF camera index for a Babylon camera.
41
+ * @param camera Babylon camera to resolve
42
+ * @returns final glTF camera index, or undefined when the camera was not exported
43
+ */
44
+ getCameraIndex(camera: Camera): number | undefined;
45
+ /**
46
+ * Gets the final glTF material index for a Babylon material.
47
+ * @param material Babylon material to resolve
48
+ * @returns final glTF material index, or undefined when the material was not exported
49
+ */
50
+ getMaterialIndex(material: Material): number | undefined;
51
+ /**
52
+ * Gets the final glTF index for an imported Babylon entity in a root collection.
53
+ * @param collection target glTF root collection
54
+ * @param entity imported Babylon entity associated with the source entry
55
+ * @returns final glTF index, or undefined when the entity was not exported uniquely
56
+ */
57
+ getRootIndex?(collection: KhrInteractivityRootCollection, entity: object): number | undefined;
58
+ /**
59
+ * Writes a companion extension on an already-exported glTF node.
60
+ * @param nodeIndex final glTF node index
61
+ * @param extensionName companion extension name
62
+ * @param value companion extension payload
63
+ */
64
+ setNodeExtension(nodeIndex: number, extensionName: string, value: unknown): void;
65
+ }
66
+ /**
67
+ * Supplies a detached canonical KHR_interactivity document to the glTF serializer.
68
+ */
69
+ export interface IKHRInteractivityExportProvider {
70
+ /** Whether KHR_interactivity must be listed in extensionsRequired. */
71
+ readonly required: boolean;
72
+ /** Additional operation or companion extensions referenced by the graph. */
73
+ readonly additionalExtensionsUsed: readonly string[];
74
+ /** Additional extensions that must be listed in extensionsRequired. */
75
+ readonly additionalExtensionsRequired: readonly string[];
76
+ /**
77
+ * Builds the extension after final glTF entity indices are available.
78
+ * @param context final serializer remapping context
79
+ * @returns canonical KHR_interactivity extension payload
80
+ */
81
+ build(context: IKHRInteractivityExportContext): IKHRInteractivity;
82
+ }
11
83
  /**
12
84
  * Holds a collection of exporter options and parameters
13
85
  */
@@ -46,7 +118,8 @@ export interface IExportOptions {
46
118
  */
47
119
  exportUnusedUVs?: boolean;
48
120
  /**
49
- * Remove no-op root nodes when possible. Defaults to true.
121
+ * Remove no-op root nodes when possible. Defaults to true. No-op roots are preserved when
122
+ * {@link khrInteractivity} is provided because the graph may reference them.
50
123
  */
51
124
  removeNoopRootNodes?: boolean;
52
125
  /**
@@ -66,6 +139,11 @@ export interface IExportOptions {
66
139
  * Indicates if force convert to right handed pos;
67
140
  */
68
141
  convectSkeletonToTightHanded?: boolean;
142
+ /**
143
+ * Canonical KHR_interactivity export provider. The provider is evaluated only after scene
144
+ * nodes and animations have their final glTF indices.
145
+ */
146
+ khrInteractivity?: IKHRInteractivityExportProvider;
69
147
  }
70
148
  /**
71
149
  * Class for generating glTF data from a Babylon scene.
@@ -1 +1 @@
1
- {"version":3,"file":"glTFSerializer.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFSerializer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAgF9C;;GAEG;AACH,MAAM,OAAO,WAAW;IACpB;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAY,EAAE,QAAgB,EAAE,OAAwB;QAClF,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,4BAA4B,EAAE,CAAC;YACpD,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;QACjF,QAAQ,CAAC,OAAO,EAAE,CAAC;QAEnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAY,EAAE,QAAgB,EAAE,OAAwB;QACjF,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,4BAA4B,EAAE,CAAC;YACpD,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;QAChF,QAAQ,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { type Node } from \"core/node\";\r\nimport { type Scene } from \"core/scene\";\r\nimport { type Animation } from \"core/Animations/animation\";\r\nimport { type GLTFData } from \"./glTFData\";\r\nimport { GLTFExporter } from \"./glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { type INode } from \"babylonjs-gltf2interface\";\r\n\r\n/**\r\n * Mesh compression methods.\r\n */\r\nexport type MeshCompressionMethod = \"None\" | \"Draco\";\r\n\r\n/**\r\n * Holds a collection of exporter options and parameters\r\n */\r\nexport interface IExportOptions {\r\n /**\r\n * Function which indicates whether a babylon node should be exported or not\r\n * @param node source Babylon node. It is used to check whether it should be exported to glTF or not\r\n * @returns boolean, which indicates whether the node should be exported (true) or not (false)\r\n */\r\n shouldExportNode?(node: Node): boolean;\r\n\r\n customCreateNode?(babylonNode: Node, gltfNode: INode): void;\r\n\r\n /**\r\n * Function which indicates whether an animation on the scene should be exported or not\r\n * @param animation source animation\r\n * @returns boolean, which indicates whether the animation should be exported (true) or not (false)\r\n */\r\n shouldExportAnimation?(animation: Animation): boolean;\r\n\r\n /**\r\n * Function to extract the part of the scene or node's `metadata` that will populate the corresponding\r\n * glTF object's `extras` field. If not defined, `node.metadata.gltf.extras` will be used.\r\n * @param metadata source metadata to read from\r\n * @returns the data to store into the glTF extras field\r\n */\r\n metadataSelector?(metadata: any): any;\r\n\r\n shouldExportMaterial?(material: Material): boolean;\r\n\r\n /**\r\n * The sample rate to bake animation curves. Defaults to 1 / 60.\r\n */\r\n animationSampleRate?: number;\r\n\r\n /**\r\n * Begin serialization without waiting for the scene to be ready. Defaults to false.\r\n */\r\n exportWithoutWaitingForScene?: boolean;\r\n\r\n /**\r\n * Indicates if unused vertex uv attributes should be included in export. Defaults to false.\r\n */\r\n exportUnusedUVs?: boolean;\r\n\r\n /**\r\n * Remove no-op root nodes when possible. Defaults to true.\r\n */\r\n removeNoopRootNodes?: boolean;\r\n\r\n /**\r\n * Indicates if coordinate system swapping root nodes should be included in export. Defaults to false.\r\n * @deprecated Please use removeNoopRootNodes instead\r\n */\r\n includeCoordinateSystemConversionNodes?: boolean;\r\n\r\n /**\r\n * Indicates what compression method to apply to mesh data.\r\n */\r\n meshCompressionMethod?: MeshCompressionMethod;\r\n\r\n /**\r\n * Indicates if force convert to right handed pos;\r\n */\r\n convertToRightHanded?: boolean;\r\n /**\r\n * Indicates if force convert to right handed pos;\r\n */\r\n convectSkeletonToTightHanded?: boolean;\r\n}\r\n\r\n/**\r\n * Class for generating glTF data from a Babylon scene.\r\n */\r\nexport class GLTF2Export {\r\n /**\r\n * Exports the scene to .gltf file format\r\n * @param scene Babylon scene\r\n * @param fileName Name to use for the .gltf file\r\n * @param options Exporter options\r\n * @returns Returns the exported data\r\n */\r\n public static async GLTFAsync(scene: Scene, fileName: string, options?: IExportOptions): Promise<GLTFData> {\r\n if (!options || !options.exportWithoutWaitingForScene) {\r\n await scene.whenReadyAsync();\r\n }\r\n\r\n const exporter = new GLTFExporter(scene, options);\r\n const data = await exporter.generateGLTFAsync(fileName.replace(/\\.[^/.]+$/, \"\"));\r\n exporter.dispose();\r\n\r\n return data;\r\n }\r\n\r\n /**\r\n * Exports the scene to .glb file format\r\n * @param scene Babylon scene\r\n * @param fileName Name to use for the .glb file\r\n * @param options Exporter options\r\n * @returns Returns the exported data\r\n */\r\n public static async GLBAsync(scene: Scene, fileName: string, options?: IExportOptions): Promise<GLTFData> {\r\n if (!options || !options.exportWithoutWaitingForScene) {\r\n await scene.whenReadyAsync();\r\n }\r\n\r\n const exporter = new GLTFExporter(scene, options);\r\n const data = await exporter.generateGLBAsync(fileName.replace(/\\.[^/.]+$/, \"\"));\r\n exporter.dispose();\r\n return data;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"glTFSerializer.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFSerializer.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA8J9C;;GAEG;AACH,MAAM,OAAO,WAAW;IACpB;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAY,EAAE,QAAgB,EAAE,OAAwB;QAClF,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,4BAA4B,EAAE,CAAC;YACpD,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;QACjF,QAAQ,CAAC,OAAO,EAAE,CAAC;QAEnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAY,EAAE,QAAgB,EAAE,OAAwB;QACjF,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,4BAA4B,EAAE,CAAC;YACpD,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;QAChF,QAAQ,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { type Node } from \"core/node\";\r\nimport { type Scene } from \"core/scene\";\r\nimport { type Animation } from \"core/Animations/animation\";\r\nimport { type AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport { type Camera } from \"core/Cameras/camera\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { type IKHRInteractivity } from \"babylonjs-gltf2interface\";\r\nimport { type GLTFData } from \"./glTFData\";\r\nimport { GLTFExporter } from \"./glTFExporter\";\r\nimport { type INode } from \"babylonjs-gltf2interface\";\r\n\r\n/**\r\n * Indexed glTF root collections that KHR_interactivity references can target.\r\n */\r\nexport type KhrInteractivityRootCollection = \"nodes\" | \"animations\" | \"cameras\" | \"materials\" | \"meshes\" | \"textures\" | \"images\" | \"samplers\" | \"skins\" | \"scenes\";\r\n\r\n/**\r\n * Mesh compression methods.\r\n */\r\nexport type MeshCompressionMethod = \"None\" | \"Draco\";\r\n\r\n/**\r\n * Final entity remapping context exposed to a KHR_interactivity export provider.\r\n */\r\nexport interface IKHRInteractivityExportContext {\r\n /**\r\n * Gets the final number of glTF nodes.\r\n * @returns final glTF node count\r\n */\r\n getNodeCount(): number;\r\n /**\r\n * Gets the final glTF node index for a Babylon node.\r\n * @param node Babylon node to resolve\r\n * @returns final glTF node index, or undefined when the node was not exported\r\n */\r\n getNodeIndex(node: Node): number | undefined;\r\n /**\r\n * Gets the final glTF animation index for a Babylon animation group.\r\n * @param animation Babylon animation group to resolve\r\n * @returns final glTF animation index, or undefined when the animation was not exported\r\n */\r\n getAnimationIndex(animation: AnimationGroup): number | undefined;\r\n /**\r\n * Gets the final glTF camera index for a Babylon camera.\r\n * @param camera Babylon camera to resolve\r\n * @returns final glTF camera index, or undefined when the camera was not exported\r\n */\r\n getCameraIndex(camera: Camera): number | undefined;\r\n /**\r\n * Gets the final glTF material index for a Babylon material.\r\n * @param material Babylon material to resolve\r\n * @returns final glTF material index, or undefined when the material was not exported\r\n */\r\n getMaterialIndex(material: Material): number | undefined;\r\n /**\r\n * Gets the final glTF index for an imported Babylon entity in a root collection.\r\n * @param collection target glTF root collection\r\n * @param entity imported Babylon entity associated with the source entry\r\n * @returns final glTF index, or undefined when the entity was not exported uniquely\r\n */\r\n getRootIndex?(collection: KhrInteractivityRootCollection, entity: object): number | undefined;\r\n /**\r\n * Writes a companion extension on an already-exported glTF node.\r\n * @param nodeIndex final glTF node index\r\n * @param extensionName companion extension name\r\n * @param value companion extension payload\r\n */\r\n setNodeExtension(nodeIndex: number, extensionName: string, value: unknown): void;\r\n}\r\n\r\n/**\r\n * Supplies a detached canonical KHR_interactivity document to the glTF serializer.\r\n */\r\nexport interface IKHRInteractivityExportProvider {\r\n /** Whether KHR_interactivity must be listed in extensionsRequired. */\r\n readonly required: boolean;\r\n /** Additional operation or companion extensions referenced by the graph. */\r\n readonly additionalExtensionsUsed: readonly string[];\r\n /** Additional extensions that must be listed in extensionsRequired. */\r\n readonly additionalExtensionsRequired: readonly string[];\r\n /**\r\n * Builds the extension after final glTF entity indices are available.\r\n * @param context final serializer remapping context\r\n * @returns canonical KHR_interactivity extension payload\r\n */\r\n build(context: IKHRInteractivityExportContext): IKHRInteractivity;\r\n}\r\n\r\n/**\r\n * Holds a collection of exporter options and parameters\r\n */\r\nexport interface IExportOptions {\r\n /**\r\n * Function which indicates whether a babylon node should be exported or not\r\n * @param node source Babylon node. It is used to check whether it should be exported to glTF or not\r\n * @returns boolean, which indicates whether the node should be exported (true) or not (false)\r\n */\r\n shouldExportNode?(node: Node): boolean;\r\n\r\n customCreateNode?(babylonNode: Node, gltfNode: INode): void;\r\n\r\n /**\r\n * Function which indicates whether an animation on the scene should be exported or not\r\n * @param animation source animation\r\n * @returns boolean, which indicates whether the animation should be exported (true) or not (false)\r\n */\r\n shouldExportAnimation?(animation: Animation): boolean;\r\n\r\n /**\r\n * Function to extract the part of the scene or node's `metadata` that will populate the corresponding\r\n * glTF object's `extras` field. If not defined, `node.metadata.gltf.extras` will be used.\r\n * @param metadata source metadata to read from\r\n * @returns the data to store into the glTF extras field\r\n */\r\n metadataSelector?(metadata: any): any;\r\n\r\n shouldExportMaterial?(material: Material): boolean;\r\n\r\n /**\r\n * The sample rate to bake animation curves. Defaults to 1 / 60.\r\n */\r\n animationSampleRate?: number;\r\n\r\n /**\r\n * Begin serialization without waiting for the scene to be ready. Defaults to false.\r\n */\r\n exportWithoutWaitingForScene?: boolean;\r\n\r\n /**\r\n * Indicates if unused vertex uv attributes should be included in export. Defaults to false.\r\n */\r\n exportUnusedUVs?: boolean;\r\n\r\n /**\r\n * Remove no-op root nodes when possible. Defaults to true. No-op roots are preserved when\r\n * {@link khrInteractivity} is provided because the graph may reference them.\r\n */\r\n removeNoopRootNodes?: boolean;\r\n\r\n /**\r\n * Indicates if coordinate system swapping root nodes should be included in export. Defaults to false.\r\n * @deprecated Please use removeNoopRootNodes instead\r\n */\r\n includeCoordinateSystemConversionNodes?: boolean;\r\n\r\n /**\r\n * Indicates what compression method to apply to mesh data.\r\n */\r\n meshCompressionMethod?: MeshCompressionMethod;\r\n\r\n /**\r\n * Indicates if force convert to right handed pos;\r\n */\r\n convertToRightHanded?: boolean;\r\n /**\r\n * Indicates if force convert to right handed pos;\r\n */\r\n convectSkeletonToTightHanded?: boolean;\r\n\r\n /**\r\n * Canonical KHR_interactivity export provider. The provider is evaluated only after scene\r\n * nodes and animations have their final glTF indices.\r\n */\r\n khrInteractivity?: IKHRInteractivityExportProvider;\r\n}\r\n\r\n/**\r\n * Class for generating glTF data from a Babylon scene.\r\n */\r\nexport class GLTF2Export {\r\n /**\r\n * Exports the scene to .gltf file format\r\n * @param scene Babylon scene\r\n * @param fileName Name to use for the .gltf file\r\n * @param options Exporter options\r\n * @returns Returns the exported data\r\n */\r\n public static async GLTFAsync(scene: Scene, fileName: string, options?: IExportOptions): Promise<GLTFData> {\r\n if (!options || !options.exportWithoutWaitingForScene) {\r\n await scene.whenReadyAsync();\r\n }\r\n\r\n const exporter = new GLTFExporter(scene, options);\r\n const data = await exporter.generateGLTFAsync(fileName.replace(/\\.[^/.]+$/, \"\"));\r\n exporter.dispose();\r\n\r\n return data;\r\n }\r\n\r\n /**\r\n * Exports the scene to .glb file format\r\n * @param scene Babylon scene\r\n * @param fileName Name to use for the .glb file\r\n * @param options Exporter options\r\n * @returns Returns the exported data\r\n */\r\n public static async GLBAsync(scene: Scene, fileName: string, options?: IExportOptions): Promise<GLTFData> {\r\n if (!options || !options.exportWithoutWaitingForScene) {\r\n await scene.whenReadyAsync();\r\n }\r\n\r\n const exporter = new GLTFExporter(scene, options);\r\n const data = await exporter.generateGLBAsync(fileName.replace(/\\.[^/.]+$/, \"\"));\r\n exporter.dispose();\r\n return data;\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onerjs/serializers",
3
- "version": "8.56.4",
3
+ "version": "9.0.1",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,10 +18,10 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6"
19
19
  },
20
20
  "devDependencies": {
21
- "@onerjs/core": "8.56.4",
21
+ "@onerjs/core": "9.0.1",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@dev/serializers": "^1.0.0",
24
- "babylonjs-gltf2interface": "^8.56.4"
24
+ "babylonjs-gltf2interface": "^9.32.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@onerjs/core": "^8.0.0",