@babylonjs/loaders 6.36.0 → 6.37.0
Sign up to get free protection for your applications and to get access to all the features.
- package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +1 -18
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +18 -55
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_interactivity.d.ts +1 -0
- package/glTF/2.0/Extensions/KHR_interactivity.js +7 -14
- package/glTF/2.0/Extensions/KHR_interactivity.js.map +1 -1
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.d.ts +31 -0
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.js +62 -0
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.js.map +1 -0
- package/glTF/2.0/Extensions/interactivityFunctions.js +1 -4
- package/glTF/2.0/Extensions/interactivityFunctions.js.map +1 -1
- package/glTF/2.0/Extensions/interactivityPathToObjectConverter.d.ts +9 -0
- package/glTF/2.0/Extensions/interactivityPathToObjectConverter.js +32 -0
- package/glTF/2.0/Extensions/interactivityPathToObjectConverter.js.map +1 -0
- package/glTF/2.0/glTFLoader.d.ts +2 -1
- package/glTF/2.0/glTFLoader.js +12 -10
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/package.json +3 -3
- package/glTF/2.0/Extensions/interactivityPathCameraExtensions.d.ts +0 -7
- package/glTF/2.0/Extensions/interactivityPathCameraExtensions.js +0 -77
- package/glTF/2.0/Extensions/interactivityPathCameraExtensions.js.map +0 -1
- package/glTF/2.0/Extensions/interactivityPathExtensions.d.ts +0 -2
- package/glTF/2.0/Extensions/interactivityPathExtensions.js +0 -5
- package/glTF/2.0/Extensions/interactivityPathExtensions.js.map +0 -1
- package/glTF/2.0/Extensions/interactivityPathMaterialExtensions.d.ts +0 -7
- package/glTF/2.0/Extensions/interactivityPathMaterialExtensions.js +0 -87
- package/glTF/2.0/Extensions/interactivityPathMaterialExtensions.js.map +0 -1
- package/glTF/2.0/Extensions/interactivityPathTransformNodeExtensions.d.ts +0 -2
- package/glTF/2.0/Extensions/interactivityPathTransformNodeExtensions.js +0 -50
- package/glTF/2.0/Extensions/interactivityPathTransformNodeExtensions.js.map +0 -1
@@ -14,6 +14,7 @@ export declare class KHR_animation_pointer implements IGLTFLoaderExtension {
|
|
14
14
|
*/
|
15
15
|
readonly name = "KHR_animation_pointer";
|
16
16
|
private _loader;
|
17
|
+
private _pathToObjectConverter?;
|
17
18
|
/**
|
18
19
|
* @internal
|
19
20
|
*/
|
@@ -34,22 +35,4 @@ export declare class KHR_animation_pointer implements IGLTFLoaderExtension {
|
|
34
35
|
* @returns A void promise that resolves when the load is complete or null if not handled
|
35
36
|
*/
|
36
37
|
_loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, onLoad: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): Nullable<Promise<void>>;
|
37
|
-
/**
|
38
|
-
* The pointer string is represented by a [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901).
|
39
|
-
* <animationPointer> := /<rootNode>/<assetIndex>/<propertyPath>
|
40
|
-
* <rootNode> := "nodes" | "materials" | "meshes" | "cameras" | "extensions"
|
41
|
-
* <assetIndex> := <digit> | <name>
|
42
|
-
* <propertyPath> := <extensionPath> | <standardPath>
|
43
|
-
* <extensionPath> := "extensions"/<name>/<standardPath>
|
44
|
-
* <standardPath> := <name> | <name>/<standardPath>
|
45
|
-
* <name> := W+
|
46
|
-
* <digit> := D+
|
47
|
-
*
|
48
|
-
* Examples:
|
49
|
-
* - "/nodes/0/rotation"
|
50
|
-
* - "/materials/2/emissiveFactor"
|
51
|
-
* - "/materials/2/pbrMetallicRoughness/baseColorFactor"
|
52
|
-
* - "/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength"
|
53
|
-
*/
|
54
|
-
private _parseAnimationPointer;
|
55
38
|
}
|
@@ -1,7 +1,17 @@
|
|
1
1
|
import { GLTFLoader } from "../glTFLoader.js";
|
2
2
|
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
3
3
|
import { animationPointerTree } from "./KHR_animation_pointer.data.js";
|
4
|
+
import { GLTFPathToObjectConverter } from "./gltfPathToObjectConverter.js";
|
4
5
|
const NAME = "KHR_animation_pointer";
|
6
|
+
/**
|
7
|
+
* Class to convert an animation pointer path to a smart object that
|
8
|
+
* gets data from the animation buffer and creates animations.
|
9
|
+
*/
|
10
|
+
class AnimationPointerPathToObjectConverter extends GLTFPathToObjectConverter {
|
11
|
+
constructor(gltf) {
|
12
|
+
super(gltf, animationPointerTree);
|
13
|
+
}
|
14
|
+
}
|
5
15
|
/**
|
6
16
|
* [Specification PR](https://github.com/KhronosGroup/glTF/pull/2147)
|
7
17
|
* !!! Experimental Extension Subject to Changes !!!
|
@@ -17,6 +27,7 @@ export class KHR_animation_pointer {
|
|
17
27
|
*/
|
18
28
|
this.name = NAME;
|
19
29
|
this._loader = loader;
|
30
|
+
this._pathToObjectConverter = new AnimationPointerPathToObjectConverter(this._loader.gltf);
|
20
31
|
}
|
21
32
|
/**
|
22
33
|
* Defines whether this extension is enabled.
|
@@ -27,6 +38,7 @@ export class KHR_animation_pointer {
|
|
27
38
|
/** @internal */
|
28
39
|
dispose() {
|
29
40
|
this._loader = null;
|
41
|
+
delete this._pathToObjectConverter; // GC
|
30
42
|
}
|
31
43
|
/**
|
32
44
|
* Loads a glTF animation channel.
|
@@ -40,7 +52,7 @@ export class KHR_animation_pointer {
|
|
40
52
|
_loadAnimationChannelAsync(context, animationContext, animation, channel, onLoad) {
|
41
53
|
var _a;
|
42
54
|
const extension = (_a = channel.target.extensions) === null || _a === void 0 ? void 0 : _a.KHR_animation_pointer;
|
43
|
-
if (!extension) {
|
55
|
+
if (!extension || !this._pathToObjectConverter) {
|
44
56
|
return null;
|
45
57
|
}
|
46
58
|
if (channel.target.path !== "pointer" /* AnimationChannelTargetPath.POINTER */) {
|
@@ -54,63 +66,14 @@ export class KHR_animation_pointer {
|
|
54
66
|
if (!pointer) {
|
55
67
|
throw new Error(`${extensionContext}: Pointer is missing`);
|
56
68
|
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
return null;
|
69
|
+
try {
|
70
|
+
const targetInfo = this._pathToObjectConverter.convert(pointer);
|
71
|
+
return this._loader._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);
|
61
72
|
}
|
62
|
-
|
63
|
-
|
64
|
-
/**
|
65
|
-
* The pointer string is represented by a [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901).
|
66
|
-
* <animationPointer> := /<rootNode>/<assetIndex>/<propertyPath>
|
67
|
-
* <rootNode> := "nodes" | "materials" | "meshes" | "cameras" | "extensions"
|
68
|
-
* <assetIndex> := <digit> | <name>
|
69
|
-
* <propertyPath> := <extensionPath> | <standardPath>
|
70
|
-
* <extensionPath> := "extensions"/<name>/<standardPath>
|
71
|
-
* <standardPath> := <name> | <name>/<standardPath>
|
72
|
-
* <name> := W+
|
73
|
-
* <digit> := D+
|
74
|
-
*
|
75
|
-
* Examples:
|
76
|
-
* - "/nodes/0/rotation"
|
77
|
-
* - "/materials/2/emissiveFactor"
|
78
|
-
* - "/materials/2/pbrMetallicRoughness/baseColorFactor"
|
79
|
-
* - "/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength"
|
80
|
-
*/
|
81
|
-
_parseAnimationPointer(context, pointer) {
|
82
|
-
if (!pointer.startsWith("/")) {
|
83
|
-
Logger.Warn(`${context}: Value (${pointer}) must start with a slash`);
|
84
|
-
return null;
|
85
|
-
}
|
86
|
-
const parts = pointer.split("/");
|
87
|
-
// Remove the first part since it will be empty string as pointers must start with a slash.
|
88
|
-
parts.shift();
|
89
|
-
let node = animationPointerTree;
|
90
|
-
let gltfCurrentNode = this._loader.gltf;
|
91
|
-
let gltfTargetNode = undefined;
|
92
|
-
for (const part of parts) {
|
93
|
-
if (node.__array__) {
|
94
|
-
node = node.__array__;
|
95
|
-
}
|
96
|
-
else {
|
97
|
-
node = node[part];
|
98
|
-
if (!node) {
|
99
|
-
return null;
|
100
|
-
}
|
101
|
-
}
|
102
|
-
gltfCurrentNode = gltfCurrentNode && gltfCurrentNode[part];
|
103
|
-
if (node.__target__) {
|
104
|
-
gltfTargetNode = gltfCurrentNode;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
if (!gltfTargetNode || !Array.isArray(node)) {
|
73
|
+
catch (e) {
|
74
|
+
Logger.Warn(`${extensionContext}/pointer: Invalid pointer (${pointer}) skipped`);
|
108
75
|
return null;
|
109
76
|
}
|
110
|
-
return {
|
111
|
-
target: gltfTargetNode,
|
112
|
-
properties: node,
|
113
|
-
};
|
114
77
|
}
|
115
78
|
}
|
116
79
|
GLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_animation_pointer.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_animation_pointer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"KHR_animation_pointer.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_animation_pointer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;;GAGG;AACH,MAAM,qCAAsC,SAAQ,yBAAkD;IAClG,YAAmB,IAAW;QAC1B,KAAK,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IACtC,CAAC;CACJ;AAED;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAS9B;;OAEG;IACH,YAAY,MAAkB;QAX9B;;WAEG;QACa,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AE;YACV,MAAM,IAAI,KAAK,CAAC,GAAG,gBAAgB,sBAAsB,CAAC,CAAC;SAC9D;QAED,IAAI;YACA,MAAM,UAAU,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC,OAAO,CAAC,wCAAwC,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;SACnI;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,CAAC,IAAI,CAAC,GAAG,gBAAgB,8BAA8B,OAAO,WAAW,CAAC,CAAC;YACjF,OAAO,IAAI,CAAC;SACf;IACL,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Animation } from \"core/Animations/animation\";\r\nimport type { IAnimatable } from \"core/Animations/animatable.interface\";\r\nimport type { IAnimation, IAnimationChannel, IGLTF } from \"../glTFLoaderInterfaces\";\r\nimport type { IKHRAnimationPointer } from \"babylonjs-gltf2interface\";\r\nimport { AnimationChannelTargetPath } from \"babylonjs-gltf2interface\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { animationPointerTree } from \"./KHR_animation_pointer.data\";\r\nimport { GLTFPathToObjectConverter } from \"./gltfPathToObjectConverter\";\r\nimport type { AnimationPropertyInfo } from \"../glTFLoaderAnimation\";\r\n\r\nconst NAME = \"KHR_animation_pointer\";\r\n\r\n/**\r\n * Class to convert an animation pointer path to a smart object that\r\n * gets data from the animation buffer and creates animations.\r\n */\r\nclass AnimationPointerPathToObjectConverter extends GLTFPathToObjectConverter<AnimationPropertyInfo[]> {\r\n public constructor(gltf: IGLTF) {\r\n super(gltf, animationPointerTree);\r\n }\r\n}\r\n\r\n/**\r\n * [Specification PR](https://github.com/KhronosGroup/glTF/pull/2147)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_animation_pointer implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n private _loader: GLTFLoader;\r\n private _pathToObjectConverter?: AnimationPointerPathToObjectConverter;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this._pathToObjectConverter = new AnimationPointerPathToObjectConverter(this._loader.gltf);\r\n }\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public get enabled(): boolean {\r\n return this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._pathToObjectConverter; // GC\r\n }\r\n\r\n /**\r\n * Loads a glTF animation channel.\r\n * @param context The context when loading the asset\r\n * @param animationContext The context of the animation when loading the asset\r\n * @param animation The glTF animation property\r\n * @param channel The glTF animation channel property\r\n * @param onLoad Called for each animation loaded\r\n * @returns A void promise that resolves when the load is complete or null if not handled\r\n */\r\n public _loadAnimationChannelAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n channel: IAnimationChannel,\r\n onLoad: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void\r\n ): Nullable<Promise<void>> {\r\n const extension = channel.target.extensions?.KHR_animation_pointer as IKHRAnimationPointer;\r\n if (!extension || !this._pathToObjectConverter) {\r\n return null;\r\n }\r\n\r\n if (channel.target.path !== AnimationChannelTargetPath.POINTER) {\r\n Logger.Warn(`${context}/target/path: Value (${channel.target.path}) must be (${AnimationChannelTargetPath.POINTER}) when using the ${this.name} extension`);\r\n }\r\n\r\n if (channel.target.node != undefined) {\r\n Logger.Warn(`${context}/target/node: Value (${channel.target.node}) must not be present when using the ${this.name} extension`);\r\n }\r\n\r\n const extensionContext = `${context}/extensions/${this.name}`;\r\n\r\n const pointer = extension.pointer;\r\n if (!pointer) {\r\n throw new Error(`${extensionContext}: Pointer is missing`);\r\n }\r\n\r\n try {\r\n const targetInfo = this._pathToObjectConverter.convert(pointer);\r\n return this._loader._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);\r\n } catch (e) {\r\n Logger.Warn(`${extensionContext}/pointer: Invalid pointer (${pointer}) skipped`);\r\n return null;\r\n }\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));\r\n"]}
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import { GLTFLoader } from "../glTFLoader.js";
|
2
2
|
import { FlowGraphCoordinator } from "@babylonjs/core/FlowGraph/flowGraphCoordinator.js";
|
3
3
|
import { FlowGraph } from "@babylonjs/core/FlowGraph/flowGraph.js";
|
4
|
-
import { FlowGraphPath } from "@babylonjs/core/FlowGraph/flowGraphPath.js";
|
5
4
|
import { convertGLTFToSerializedFlowGraph } from "./interactivityFunctions.js";
|
6
|
-
import {
|
5
|
+
import { InteractivityPathToObjectConverter } from "./interactivityPathToObjectConverter.js";
|
7
6
|
const NAME = "KHR_interactivity";
|
8
7
|
/**
|
9
8
|
* Loader extension for KHR_interactivity
|
@@ -20,28 +19,22 @@ export class KHR_interactivity {
|
|
20
19
|
*/
|
21
20
|
this.name = NAME;
|
22
21
|
this.enabled = this._loader.isExtensionUsed(NAME);
|
22
|
+
this._pathConverter = new InteractivityPathToObjectConverter(this._loader.gltf);
|
23
23
|
}
|
24
24
|
dispose() {
|
25
25
|
this._loader = null;
|
26
|
+
delete this._pathConverter;
|
26
27
|
}
|
27
28
|
onReady() {
|
28
29
|
var _a;
|
29
|
-
if (!this._loader.babylonScene) {
|
30
|
+
if (!this._loader.babylonScene || !this._pathConverter) {
|
30
31
|
return;
|
31
32
|
}
|
32
33
|
const scene = this._loader.babylonScene;
|
33
|
-
const
|
34
|
-
|
35
|
-
for (const extension of interactivityPathExensions) {
|
36
|
-
if (!FlowGraphPath.Extensions.includes(extension)) {
|
37
|
-
FlowGraphPath.Extensions.push(extension);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
const json = convertGLTFToSerializedFlowGraph(definition);
|
34
|
+
const interactivityDefinition = (_a = this._loader.gltf.extensions) === null || _a === void 0 ? void 0 : _a.KHR_interactivity;
|
35
|
+
const json = convertGLTFToSerializedFlowGraph(interactivityDefinition);
|
41
36
|
const coordinator = new FlowGraphCoordinator({ scene });
|
42
|
-
|
43
|
-
const context = graph.getContext(0);
|
44
|
-
context.setVariable("gltf", this._loader.gltf);
|
37
|
+
FlowGraph.Parse(json, { coordinator, pathConverter: this._pathConverter });
|
45
38
|
coordinator.start();
|
46
39
|
}
|
47
40
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_interactivity.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_interactivity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,0DAA4C;AAC3E,OAAO,EAAE,SAAS,EAAE,+CAAiC;AACrD,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"KHR_interactivity.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_interactivity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,0DAA4C;AAC3E,OAAO,EAAE,SAAS,EAAE,+CAAiC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAE1F,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAY1B;;;OAGG;IACH,YAAoB,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QAfvC;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAaxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,cAAc,GAAG,IAAI,kCAAkC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,CAAC;IAEM,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAEM,OAAO;;QACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACpD,OAAO;SACV;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QACxC,MAAM,uBAAuB,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,0CAAE,iBAAsC,CAAC;QAErG,MAAM,IAAI,GAAG,gCAAgC,CAAC,uBAAuB,CAAC,CAAC;QACvE,MAAM,WAAW,GAAG,IAAI,oBAAoB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACxD,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAE3E,WAAW,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { IKHRInteractivity } from \"babylonjs-gltf2interface\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { FlowGraphCoordinator } from \"core/FlowGraph/flowGraphCoordinator\";\r\nimport { FlowGraph } from \"core/FlowGraph/flowGraph\";\r\nimport { convertGLTFToSerializedFlowGraph } from \"./interactivityFunctions\";\r\nimport { InteractivityPathToObjectConverter } from \"./interactivityPathToObjectConverter\";\r\n\r\nconst NAME = \"KHR_interactivity\";\r\n\r\n/**\r\n * Loader extension for KHR_interactivity\r\n */\r\nexport class KHR_interactivity implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _pathConverter?: InteractivityPathToObjectConverter;\r\n\r\n /**\r\n * @internal\r\n * @param _loader\r\n */\r\n constructor(private _loader: GLTFLoader) {\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n this._pathConverter = new InteractivityPathToObjectConverter(this._loader.gltf);\r\n }\r\n\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._pathConverter;\r\n }\r\n\r\n public onReady(): void {\r\n if (!this._loader.babylonScene || !this._pathConverter) {\r\n return;\r\n }\r\n const scene = this._loader.babylonScene;\r\n const interactivityDefinition = this._loader.gltf.extensions?.KHR_interactivity as IKHRInteractivity;\r\n\r\n const json = convertGLTFToSerializedFlowGraph(interactivityDefinition);\r\n const coordinator = new FlowGraphCoordinator({ scene });\r\n FlowGraph.Parse(json, { coordinator, pathConverter: this._pathConverter });\r\n\r\n coordinator.start();\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_interactivity(loader));\r\n"]}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import type { IObjectInfo, IPathToObjectConverter } from "@babylonjs/core/ObjectModel/objectModelInterfaces.js";
|
2
|
+
import type { IGLTF } from "../glTFLoaderInterfaces";
|
3
|
+
/**
|
4
|
+
* A converter that takes a glTF Object Model JSON Pointer
|
5
|
+
* and transforms it into an ObjectAccessorContainer, allowing
|
6
|
+
* objects referenced in the glTF to be associated with their
|
7
|
+
* respective Babylon.js objects.
|
8
|
+
*/
|
9
|
+
export declare class GLTFPathToObjectConverter<T> implements IPathToObjectConverter<T> {
|
10
|
+
private _gltf;
|
11
|
+
private _infoTree;
|
12
|
+
constructor(_gltf: IGLTF, _infoTree: any);
|
13
|
+
/**
|
14
|
+
* The pointer string is represented by a [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901).
|
15
|
+
* <animationPointer> := /<rootNode>/<assetIndex>/<propertyPath>
|
16
|
+
* <rootNode> := "nodes" | "materials" | "meshes" | "cameras" | "extensions"
|
17
|
+
* <assetIndex> := <digit> | <name>
|
18
|
+
* <propertyPath> := <extensionPath> | <standardPath>
|
19
|
+
* <extensionPath> := "extensions"/<name>/<standardPath>
|
20
|
+
* <standardPath> := <name> | <name>/<standardPath>
|
21
|
+
* <name> := W+
|
22
|
+
* <digit> := D+
|
23
|
+
*
|
24
|
+
* Examples:
|
25
|
+
* - "/nodes/0/rotation"
|
26
|
+
* - "/materials/2/emissiveFactor"
|
27
|
+
* - "/materials/2/pbrMetallicRoughness/baseColorFactor"
|
28
|
+
* - "/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength"
|
29
|
+
*/
|
30
|
+
convert(path: string): IObjectInfo<T>;
|
31
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/**
|
2
|
+
* A converter that takes a glTF Object Model JSON Pointer
|
3
|
+
* and transforms it into an ObjectAccessorContainer, allowing
|
4
|
+
* objects referenced in the glTF to be associated with their
|
5
|
+
* respective Babylon.js objects.
|
6
|
+
*/
|
7
|
+
export class GLTFPathToObjectConverter {
|
8
|
+
constructor(_gltf, _infoTree) {
|
9
|
+
this._gltf = _gltf;
|
10
|
+
this._infoTree = _infoTree;
|
11
|
+
}
|
12
|
+
/**
|
13
|
+
* The pointer string is represented by a [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901).
|
14
|
+
* <animationPointer> := /<rootNode>/<assetIndex>/<propertyPath>
|
15
|
+
* <rootNode> := "nodes" | "materials" | "meshes" | "cameras" | "extensions"
|
16
|
+
* <assetIndex> := <digit> | <name>
|
17
|
+
* <propertyPath> := <extensionPath> | <standardPath>
|
18
|
+
* <extensionPath> := "extensions"/<name>/<standardPath>
|
19
|
+
* <standardPath> := <name> | <name>/<standardPath>
|
20
|
+
* <name> := W+
|
21
|
+
* <digit> := D+
|
22
|
+
*
|
23
|
+
* Examples:
|
24
|
+
* - "/nodes/0/rotation"
|
25
|
+
* - "/materials/2/emissiveFactor"
|
26
|
+
* - "/materials/2/pbrMetallicRoughness/baseColorFactor"
|
27
|
+
* - "/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength"
|
28
|
+
*/
|
29
|
+
convert(path) {
|
30
|
+
let objectTree = this._gltf;
|
31
|
+
let infoTree = this._infoTree;
|
32
|
+
let target = undefined;
|
33
|
+
if (!path.startsWith("/")) {
|
34
|
+
throw new Error("Path must start with a /");
|
35
|
+
}
|
36
|
+
const parts = path.split("/");
|
37
|
+
parts.shift();
|
38
|
+
for (const part of parts) {
|
39
|
+
if (infoTree.__array__) {
|
40
|
+
infoTree = infoTree.__array__;
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
infoTree = infoTree[part];
|
44
|
+
if (!infoTree) {
|
45
|
+
throw new Error(`Path ${path} is invalid`);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
if (objectTree === undefined) {
|
49
|
+
throw new Error(`Path ${path} is invalid`);
|
50
|
+
}
|
51
|
+
objectTree = objectTree[part];
|
52
|
+
if (infoTree.__target__) {
|
53
|
+
target = objectTree;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return {
|
57
|
+
object: target,
|
58
|
+
info: infoTree,
|
59
|
+
};
|
60
|
+
}
|
61
|
+
}
|
62
|
+
//# sourceMappingURL=gltfPathToObjectConverter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gltfPathToObjectConverter.js","source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CAAC;IACN,CAAC;CACJ","sourcesContent":["import type { IObjectInfo, IPathToObjectConverter } from \"core/ObjectModel/objectModelInterfaces\";\r\nimport type { IGLTF } from \"../glTFLoaderInterfaces\";\r\n\r\n/**\r\n * A converter that takes a glTF Object Model JSON Pointer\r\n * and transforms it into an ObjectAccessorContainer, allowing\r\n * objects referenced in the glTF to be associated with their\r\n * respective Babylon.js objects.\r\n */\r\nexport class GLTFPathToObjectConverter<T> implements IPathToObjectConverter<T> {\r\n public constructor(\r\n private _gltf: IGLTF,\r\n private _infoTree: any\r\n ) {}\r\n\r\n /**\r\n * The pointer string is represented by a [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901).\r\n * <animationPointer> := /<rootNode>/<assetIndex>/<propertyPath>\r\n * <rootNode> := \"nodes\" | \"materials\" | \"meshes\" | \"cameras\" | \"extensions\"\r\n * <assetIndex> := <digit> | <name>\r\n * <propertyPath> := <extensionPath> | <standardPath>\r\n * <extensionPath> := \"extensions\"/<name>/<standardPath>\r\n * <standardPath> := <name> | <name>/<standardPath>\r\n * <name> := W+\r\n * <digit> := D+\r\n *\r\n * Examples:\r\n * - \"/nodes/0/rotation\"\r\n * - \"/materials/2/emissiveFactor\"\r\n * - \"/materials/2/pbrMetallicRoughness/baseColorFactor\"\r\n * - \"/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength\"\r\n */\r\n public convert(path: string): IObjectInfo<T> {\r\n let objectTree: any = this._gltf;\r\n let infoTree: any = this._infoTree;\r\n let target: any = undefined;\r\n\r\n if (!path.startsWith(\"/\")) {\r\n throw new Error(\"Path must start with a /\");\r\n }\r\n const parts = path.split(\"/\");\r\n parts.shift();\r\n\r\n for (const part of parts) {\r\n if (infoTree.__array__) {\r\n infoTree = infoTree.__array__;\r\n } else {\r\n infoTree = infoTree[part];\r\n if (!infoTree) {\r\n throw new Error(`Path ${path} is invalid`);\r\n }\r\n }\r\n if (objectTree === undefined) {\r\n throw new Error(`Path ${path} is invalid`);\r\n }\r\n objectTree = objectTree[part];\r\n\r\n if (infoTree.__target__) {\r\n target = objectTree;\r\n }\r\n }\r\n\r\n return {\r\n object: target,\r\n info: infoTree,\r\n };\r\n }\r\n}\r\n"]}
|
@@ -45,10 +45,7 @@ function convertConfiguration(gltfBlock, definition, id) {
|
|
45
45
|
else if (configObject.id === "path") {
|
46
46
|
// Convert from a GLTF path to a reference to the Babylon.js object
|
47
47
|
const pathValue = configObject.value;
|
48
|
-
converted.path =
|
49
|
-
path: pathValue,
|
50
|
-
className: "FGPath",
|
51
|
-
};
|
48
|
+
converted.path = pathValue;
|
52
49
|
}
|
53
50
|
else {
|
54
51
|
converted[configObject.id] = convertValueWithType(configObject, definition, `/extensions/KHR_interactivity/nodes/${id}`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"interactivityFunctions.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/interactivityFunctions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,qCAAuB;AAC5C,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,yDAA2C;AAE7E,SAAS,oBAAoB,CAAC,YAA6C,EAAE,UAA6B,EAAE,OAAe;IACvH,IAAI,YAAY,CAAC,IAAI,KAAK,SAAS,EAAE;QACjC,sCAAsC;QACtC,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI,EAAE;YACP,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,mBAAmB,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;SACrE;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,UAAU,YAAY,CAAC,IAAI,mBAAmB,C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AAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACvD;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,oBAAoB,YAAY,YAAY,CAAC,EAAE,CAAC,CAAC;aAC5G;SACJ;KACJ;IAED,MAAM,SAAS,GAAG,MAAA,IAAI,CAAC,SAAS,mCAAI,EAAE,CAAC;IACvC,kBAAkB;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACvC,MAAM,QAAQ,GAA+B,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,QAAQ,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,oBAAoB,CAAC,QAA2C,EAAE,IAAI,EAAE,2CAA2C,CAAC,EAAE,CAAC,CAAC;KAClK;IAED,OAAO;QACH,SAAS,EAAE,mBAAmB;QAC9B,iBAAiB;KACpB,CAAC;AACN,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { IKHRInteractivity, IKHRInteractivity_Configuration, IKHRInteractivity_Node, IKHRInteractivity_Variable } from \"babylonjs-gltf2interface\";\r\nimport type { IFlowGraphBlockConfiguration } from \"core/FlowGraph/flowGraphBlock\";\r\nimport type { ISerializedFlowGraph, ISerializedFlowGraphBlock, ISerializedFlowGraphConnection, ISerializedFlowGraphContext } from \"core/FlowGraph/typeDefinitions\";\r\nimport { RandomGUID } from \"core/Misc/guid\";\r\nimport { gltfToFlowGraphTypeMap, gltfTypeToBabylonType } from \"./interactivityUtils\";\r\nimport { FlowGraphConnectionType } from \"core/FlowGraph/flowGraphConnection\";\r\n\r\nfunction convertValueWithType(configObject: IKHRInteractivity_Configuration, definition: IKHRInteractivity, context: string) {\r\n if (configObject.type !== undefined) {\r\n // get the type on the gltf definition\r\n const type = definition.types && definition.types[configObject.type];\r\n if (!type) {\r\n throw new Error(`${context}: Unknown type: ${configObject.type}`);\r\n }\r\n const signature = type.signature;\r\n if (!signature) {\r\n throw new Error(`${context}: Type ${configObject.type} has no signature`);\r\n }\r\n const convertedType = gltfTypeToBabylonType[signature];\r\n return {\r\n value: configObject.value,\r\n className: convertedType,\r\n };\r\n } else {\r\n return configObject.value;\r\n }\r\n}\r\n\r\nfunction convertConfiguration(gltfBlock: IKHRInteractivity_Node, definition: IKHRInteractivity, id: string): IFlowGraphBlockConfiguration {\r\n const converted: IFlowGraphBlockConfiguration = {};\r\n const configurationList: IKHRInteractivity_Configuration[] = gltfBlock.configuration ?? [];\r\n for (const configObject of configurationList) {\r\n if (configObject.id === \"customEvent\") {\r\n const customEvent = definition.customEvents && definition.customEvents[configObject.value];\r\n if (!customEvent) {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${id}: Unknown custom event: ${configObject.value}`);\r\n }\r\n converted.eventId = customEvent.id;\r\n converted.eventData = customEvent.values.map((v) => v.id);\r\n } else if (configObject.id === \"variable\") {\r\n const variable = definition.variables && definition.variables[configObject.value];\r\n if (!variable) {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${id}: Unknown variable: ${configObject.value}`);\r\n }\r\n converted.variableName = variable.id;\r\n } else if (configObject.id === \"path\") {\r\n // Convert from a GLTF path to a reference to the Babylon.js object\r\n const pathValue = configObject.value as string;\r\n converted.path = {\r\n path: pathValue,\r\n className: \"FGPath\",\r\n };\r\n } else {\r\n converted[configObject.id] = convertValueWithType(configObject, definition, `/extensions/KHR_interactivity/nodes/${id}`);\r\n }\r\n }\r\n return converted;\r\n}\r\n\r\nfunction convertBlock(id: number, gltfBlock: IKHRInteractivity_Node, definition: IKHRInteractivity): ISerializedFlowGraphBlock {\r\n const className = gltfToFlowGraphTypeMap[gltfBlock.type];\r\n if (!className) {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${id}: Unknown block type: ${gltfBlock.type}`);\r\n }\r\n const uniqueId = id.toString();\r\n const config = convertConfiguration(gltfBlock, definition, uniqueId);\r\n const metadata = gltfBlock.metadata;\r\n const dataInputs: ISerializedFlowGraphConnection[] = [];\r\n const dataOutputs: ISerializedFlowGraphConnection[] = [];\r\n const signalInputs: ISerializedFlowGraphConnection[] = [];\r\n const signalOutputs: ISerializedFlowGraphConnection[] = [];\r\n return {\r\n className,\r\n config,\r\n uniqueId,\r\n metadata,\r\n dataInputs,\r\n dataOutputs,\r\n signalInputs,\r\n signalOutputs,\r\n };\r\n}\r\n\r\n/**\r\n * @internal\r\n * Converts a glTF Interactivity Extension to a serialized flow graph.\r\n * @param gltf the interactivity data\r\n * @returns a serialized flow graph\r\n */\r\nexport function convertGLTFToSerializedFlowGraph(gltf: IKHRInteractivity): ISerializedFlowGraph {\r\n // create an empty serialized context to store the values of the connections\r\n const context: ISerializedFlowGraphContext = {\r\n uniqueId: RandomGUID(),\r\n _userVariables: {},\r\n _connectionValues: {},\r\n };\r\n const executionContexts = [context];\r\n\r\n // Blocks converted to the flow graph json format\r\n const flowGraphJsonBlocks: ISerializedFlowGraphBlock[] = [];\r\n\r\n for (let i = 0; i < gltf.nodes.length; i++) {\r\n const gltfBlock = gltf.nodes[i];\r\n const flowGraphJsonBlock = convertBlock(i, gltfBlock, gltf);\r\n flowGraphJsonBlocks.push(flowGraphJsonBlock);\r\n }\r\n\r\n // Parse the connections\r\n for (let i = 0; i < gltf.nodes.length; i++) {\r\n const gltfBlock = gltf.nodes[i];\r\n // get the block that was created in the previous step\r\n const fgBlock = flowGraphJsonBlocks[i];\r\n const gltfFlows = gltfBlock.flows ?? [];\r\n // for each output flow of the gltf block\r\n for (const flow of gltfFlows) {\r\n const socketOutName = flow.id;\r\n // create an output connection for the flow graph block\r\n const socketOut: ISerializedFlowGraphConnection = {\r\n uniqueId: RandomGUID(),\r\n name: socketOutName,\r\n _connectionType: FlowGraphConnectionType.Output, // Output\r\n connectedPointIds: [],\r\n };\r\n fgBlock.signalOutputs.push(socketOut);\r\n // get the input node of this flow\r\n const nodeInId = flow.node;\r\n const nodeInSocketName = flow.socket;\r\n // find the corresponding flow graph node\r\n const nodeIn = flowGraphJsonBlocks[nodeInId];\r\n if (!nodeIn) {\r\n throw new Error(\r\n `/extensions/KHR_interactivity/nodes/${i}: Could not find node with id ${nodeInId} that connects its input with with node ${i}'s output ${socketOutName}`\r\n );\r\n }\r\n // in all of the flow graph input connections, find the one with the same name as the socket\r\n let socketIn = nodeIn.signalInputs.find((s) => s.name === nodeInSocketName);\r\n // if the socket doesn't exist, create the input socket for the connection\r\n if (!socketIn) {\r\n socketIn = {\r\n uniqueId: RandomGUID(),\r\n name: nodeInSocketName,\r\n _connectionType: FlowGraphConnectionType.Input, // Input\r\n connectedPointIds: [],\r\n };\r\n nodeIn.signalInputs.push(socketIn);\r\n }\r\n // connect the sockets\r\n socketIn.connectedPointIds.push(socketOut.uniqueId);\r\n socketOut.connectedPointIds.push(socketIn.uniqueId);\r\n }\r\n // for each input value of the gltf block\r\n const gltfValues = gltfBlock.values ?? [];\r\n for (const value of gltfValues) {\r\n const socketInName = value.id;\r\n // create an input data connection for the flow graph block\r\n const socketIn: ISerializedFlowGraphConnection = {\r\n uniqueId: RandomGUID(),\r\n name: socketInName,\r\n _connectionType: FlowGraphConnectionType.Input,\r\n connectedPointIds: [],\r\n };\r\n fgBlock.dataInputs.push(socketIn);\r\n if (value.value !== undefined) {\r\n // if the value is set on the socket itself, store it in the context\r\n const convertedValue = convertValueWithType(value as IKHRInteractivity_Configuration, gltf, `/extensions/KHR_interactivity/nodes/${i}`);\r\n // convertBlockInputType(gltfBlock, value, convertedValue, `/extensions/KHR_interactivity/nodes/${i}`);\r\n context._connectionValues[socketIn.uniqueId] = convertedValue;\r\n } else if (value.node !== undefined && value.socket !== undefined) {\r\n // if the value is connected with the output data of another socket, connect the two\r\n const nodeOutId = value.node;\r\n const nodeOutSocketName = value.socket;\r\n // find the flow graph node that owns that output socket\r\n const nodeOut = flowGraphJsonBlocks[nodeOutId];\r\n if (!nodeOut) {\r\n throw new Error(\r\n `/extensions/KHR_interactivity/nodes/${i}: Could not find node with id ${nodeOutId} that connects its output with node${i}'s input ${socketInName}`\r\n );\r\n }\r\n let socketOut = nodeOut.dataOutputs.find((s) => s.name === nodeOutSocketName);\r\n // if the socket doesn't exist, create it\r\n if (!socketOut) {\r\n socketOut = {\r\n uniqueId: RandomGUID(),\r\n name: nodeOutSocketName,\r\n _connectionType: FlowGraphConnectionType.Output,\r\n connectedPointIds: [],\r\n };\r\n nodeOut.dataOutputs.push(socketOut);\r\n }\r\n // connect the sockets\r\n socketIn.connectedPointIds.push(socketOut.uniqueId);\r\n socketOut.connectedPointIds.push(socketIn.uniqueId);\r\n } else {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${i}: Invalid socket ${socketInName} in node ${i}`);\r\n }\r\n }\r\n }\r\n\r\n const variables = gltf.variables ?? [];\r\n // Parse variables\r\n for (let i = 0; i < variables.length; i++) {\r\n const variable: IKHRInteractivity_Variable = variables[i];\r\n const variableName = variable.id;\r\n context._userVariables[variableName] = convertValueWithType(variable as IKHRInteractivity_Configuration, gltf, `/extensions/KHR_interactivity/variables/${i}`);\r\n }\r\n\r\n return {\r\n allBlocks: flowGraphJsonBlocks,\r\n executionContexts,\r\n };\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"interactivityFunctions.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/interactivityFunctions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,qCAAuB;AAC5C,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,yDAA2C;AAE7E,SAAS,oBAAoB,CAAC,YAA6C,EAAE,UAA6B,EAAE,OAAe;IACvH,IAAI,YAAY,CAAC,IAAI,KAAK,SAAS,EAAE;QACjC,sCAAsC;QACtC,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,IAAI,UAAU,C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AI,EAAE,iBAAiB;wBACvB,eAAe,EAAE,uBAAuB,CAAC,MAAM;wBAC/C,iBAAiB,EAAE,EAAE;qBACxB,CAAC;oBACF,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBACvC;gBACD,sBAAsB;gBACtB,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBACpD,SAAS,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACvD;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,oBAAoB,YAAY,YAAY,CAAC,EAAE,CAAC,CAAC;aAC5G;SACJ;KACJ;IAED,MAAM,SAAS,GAAG,MAAA,IAAI,CAAC,SAAS,mCAAI,EAAE,CAAC;IACvC,kBAAkB;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACvC,MAAM,QAAQ,GAA+B,SAAS,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,QAAQ,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,oBAAoB,CAAC,QAA2C,EAAE,IAAI,EAAE,2CAA2C,CAAC,EAAE,CAAC,CAAC;KAClK;IAED,OAAO;QACH,SAAS,EAAE,mBAAmB;QAC9B,iBAAiB;KACpB,CAAC;AACN,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { IKHRInteractivity, IKHRInteractivity_Configuration, IKHRInteractivity_Node, IKHRInteractivity_Variable } from \"babylonjs-gltf2interface\";\r\nimport type { IFlowGraphBlockConfiguration } from \"core/FlowGraph/flowGraphBlock\";\r\nimport type { ISerializedFlowGraph, ISerializedFlowGraphBlock, ISerializedFlowGraphConnection, ISerializedFlowGraphContext } from \"core/FlowGraph/typeDefinitions\";\r\nimport { RandomGUID } from \"core/Misc/guid\";\r\nimport { gltfToFlowGraphTypeMap, gltfTypeToBabylonType } from \"./interactivityUtils\";\r\nimport { FlowGraphConnectionType } from \"core/FlowGraph/flowGraphConnection\";\r\n\r\nfunction convertValueWithType(configObject: IKHRInteractivity_Configuration, definition: IKHRInteractivity, context: string) {\r\n if (configObject.type !== undefined) {\r\n // get the type on the gltf definition\r\n const type = definition.types && definition.types[configObject.type];\r\n if (!type) {\r\n throw new Error(`${context}: Unknown type: ${configObject.type}`);\r\n }\r\n const signature = type.signature;\r\n if (!signature) {\r\n throw new Error(`${context}: Type ${configObject.type} has no signature`);\r\n }\r\n const convertedType = gltfTypeToBabylonType[signature];\r\n return {\r\n value: configObject.value,\r\n className: convertedType,\r\n };\r\n } else {\r\n return configObject.value;\r\n }\r\n}\r\n\r\nfunction convertConfiguration(gltfBlock: IKHRInteractivity_Node, definition: IKHRInteractivity, id: string): IFlowGraphBlockConfiguration {\r\n const converted: IFlowGraphBlockConfiguration = {};\r\n const configurationList: IKHRInteractivity_Configuration[] = gltfBlock.configuration ?? [];\r\n for (const configObject of configurationList) {\r\n if (configObject.id === \"customEvent\") {\r\n const customEvent = definition.customEvents && definition.customEvents[configObject.value];\r\n if (!customEvent) {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${id}: Unknown custom event: ${configObject.value}`);\r\n }\r\n converted.eventId = customEvent.id;\r\n converted.eventData = customEvent.values.map((v) => v.id);\r\n } else if (configObject.id === \"variable\") {\r\n const variable = definition.variables && definition.variables[configObject.value];\r\n if (!variable) {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${id}: Unknown variable: ${configObject.value}`);\r\n }\r\n converted.variableName = variable.id;\r\n } else if (configObject.id === \"path\") {\r\n // Convert from a GLTF path to a reference to the Babylon.js object\r\n const pathValue = configObject.value as string;\r\n converted.path = pathValue;\r\n } else {\r\n converted[configObject.id] = convertValueWithType(configObject, definition, `/extensions/KHR_interactivity/nodes/${id}`);\r\n }\r\n }\r\n return converted;\r\n}\r\n\r\nfunction convertBlock(id: number, gltfBlock: IKHRInteractivity_Node, definition: IKHRInteractivity): ISerializedFlowGraphBlock {\r\n const className = gltfToFlowGraphTypeMap[gltfBlock.type];\r\n if (!className) {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${id}: Unknown block type: ${gltfBlock.type}`);\r\n }\r\n const uniqueId = id.toString();\r\n const config = convertConfiguration(gltfBlock, definition, uniqueId);\r\n const metadata = gltfBlock.metadata;\r\n const dataInputs: ISerializedFlowGraphConnection[] = [];\r\n const dataOutputs: ISerializedFlowGraphConnection[] = [];\r\n const signalInputs: ISerializedFlowGraphConnection[] = [];\r\n const signalOutputs: ISerializedFlowGraphConnection[] = [];\r\n return {\r\n className,\r\n config,\r\n uniqueId,\r\n metadata,\r\n dataInputs,\r\n dataOutputs,\r\n signalInputs,\r\n signalOutputs,\r\n };\r\n}\r\n\r\n/**\r\n * @internal\r\n * Converts a glTF Interactivity Extension to a serialized flow graph.\r\n * @param gltf the interactivity data\r\n * @returns a serialized flow graph\r\n */\r\nexport function convertGLTFToSerializedFlowGraph(gltf: IKHRInteractivity): ISerializedFlowGraph {\r\n // create an empty serialized context to store the values of the connections\r\n const context: ISerializedFlowGraphContext = {\r\n uniqueId: RandomGUID(),\r\n _userVariables: {},\r\n _connectionValues: {},\r\n };\r\n const executionContexts = [context];\r\n\r\n // Blocks converted to the flow graph json format\r\n const flowGraphJsonBlocks: ISerializedFlowGraphBlock[] = [];\r\n\r\n for (let i = 0; i < gltf.nodes.length; i++) {\r\n const gltfBlock = gltf.nodes[i];\r\n const flowGraphJsonBlock = convertBlock(i, gltfBlock, gltf);\r\n flowGraphJsonBlocks.push(flowGraphJsonBlock);\r\n }\r\n\r\n // Parse the connections\r\n for (let i = 0; i < gltf.nodes.length; i++) {\r\n const gltfBlock = gltf.nodes[i];\r\n // get the block that was created in the previous step\r\n const fgBlock = flowGraphJsonBlocks[i];\r\n const gltfFlows = gltfBlock.flows ?? [];\r\n // for each output flow of the gltf block\r\n for (const flow of gltfFlows) {\r\n const socketOutName = flow.id;\r\n // create an output connection for the flow graph block\r\n const socketOut: ISerializedFlowGraphConnection = {\r\n uniqueId: RandomGUID(),\r\n name: socketOutName,\r\n _connectionType: FlowGraphConnectionType.Output, // Output\r\n connectedPointIds: [],\r\n };\r\n fgBlock.signalOutputs.push(socketOut);\r\n // get the input node of this flow\r\n const nodeInId = flow.node;\r\n const nodeInSocketName = flow.socket;\r\n // find the corresponding flow graph node\r\n const nodeIn = flowGraphJsonBlocks[nodeInId];\r\n if (!nodeIn) {\r\n throw new Error(\r\n `/extensions/KHR_interactivity/nodes/${i}: Could not find node with id ${nodeInId} that connects its input with with node ${i}'s output ${socketOutName}`\r\n );\r\n }\r\n // in all of the flow graph input connections, find the one with the same name as the socket\r\n let socketIn = nodeIn.signalInputs.find((s) => s.name === nodeInSocketName);\r\n // if the socket doesn't exist, create the input socket for the connection\r\n if (!socketIn) {\r\n socketIn = {\r\n uniqueId: RandomGUID(),\r\n name: nodeInSocketName,\r\n _connectionType: FlowGraphConnectionType.Input, // Input\r\n connectedPointIds: [],\r\n };\r\n nodeIn.signalInputs.push(socketIn);\r\n }\r\n // connect the sockets\r\n socketIn.connectedPointIds.push(socketOut.uniqueId);\r\n socketOut.connectedPointIds.push(socketIn.uniqueId);\r\n }\r\n // for each input value of the gltf block\r\n const gltfValues = gltfBlock.values ?? [];\r\n for (const value of gltfValues) {\r\n const socketInName = value.id;\r\n // create an input data connection for the flow graph block\r\n const socketIn: ISerializedFlowGraphConnection = {\r\n uniqueId: RandomGUID(),\r\n name: socketInName,\r\n _connectionType: FlowGraphConnectionType.Input,\r\n connectedPointIds: [],\r\n };\r\n fgBlock.dataInputs.push(socketIn);\r\n if (value.value !== undefined) {\r\n // if the value is set on the socket itself, store it in the context\r\n const convertedValue = convertValueWithType(value as IKHRInteractivity_Configuration, gltf, `/extensions/KHR_interactivity/nodes/${i}`);\r\n // convertBlockInputType(gltfBlock, value, convertedValue, `/extensions/KHR_interactivity/nodes/${i}`);\r\n context._connectionValues[socketIn.uniqueId] = convertedValue;\r\n } else if (value.node !== undefined && value.socket !== undefined) {\r\n // if the value is connected with the output data of another socket, connect the two\r\n const nodeOutId = value.node;\r\n const nodeOutSocketName = value.socket;\r\n // find the flow graph node that owns that output socket\r\n const nodeOut = flowGraphJsonBlocks[nodeOutId];\r\n if (!nodeOut) {\r\n throw new Error(\r\n `/extensions/KHR_interactivity/nodes/${i}: Could not find node with id ${nodeOutId} that connects its output with node${i}'s input ${socketInName}`\r\n );\r\n }\r\n let socketOut = nodeOut.dataOutputs.find((s) => s.name === nodeOutSocketName);\r\n // if the socket doesn't exist, create it\r\n if (!socketOut) {\r\n socketOut = {\r\n uniqueId: RandomGUID(),\r\n name: nodeOutSocketName,\r\n _connectionType: FlowGraphConnectionType.Output,\r\n connectedPointIds: [],\r\n };\r\n nodeOut.dataOutputs.push(socketOut);\r\n }\r\n // connect the sockets\r\n socketIn.connectedPointIds.push(socketOut.uniqueId);\r\n socketOut.connectedPointIds.push(socketIn.uniqueId);\r\n } else {\r\n throw new Error(`/extensions/KHR_interactivity/nodes/${i}: Invalid socket ${socketInName} in node ${i}`);\r\n }\r\n }\r\n }\r\n\r\n const variables = gltf.variables ?? [];\r\n // Parse variables\r\n for (let i = 0; i < variables.length; i++) {\r\n const variable: IKHRInteractivity_Variable = variables[i];\r\n const variableName = variable.id;\r\n context._userVariables[variableName] = convertValueWithType(variable as IKHRInteractivity_Configuration, gltf, `/extensions/KHR_interactivity/variables/${i}`);\r\n }\r\n\r\n return {\r\n allBlocks: flowGraphJsonBlocks,\r\n executionContexts,\r\n };\r\n}\r\n"]}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { IGLTF } from "../glTFLoaderInterfaces";
|
2
|
+
import { GLTFPathToObjectConverter } from "./gltfPathToObjectConverter";
|
3
|
+
import type { IObjectAccessor } from "@babylonjs/core/FlowGraph.js";
|
4
|
+
/**
|
5
|
+
* Class to convert an interactivity pointer path to a smart object
|
6
|
+
*/
|
7
|
+
export declare class InteractivityPathToObjectConverter extends GLTFPathToObjectConverter<IObjectAccessor> {
|
8
|
+
constructor(gltf: IGLTF);
|
9
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { GLTFPathToObjectConverter } from "./gltfPathToObjectConverter.js";
|
2
|
+
/**
|
3
|
+
* Class to convert an interactivity pointer path to a smart object
|
4
|
+
*/
|
5
|
+
export class InteractivityPathToObjectConverter extends GLTFPathToObjectConverter {
|
6
|
+
constructor(gltf) {
|
7
|
+
super(gltf, gltfTree);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
const nodesTree = {
|
11
|
+
__array__: {
|
12
|
+
__target__: true,
|
13
|
+
translation: {
|
14
|
+
type: "Vector3",
|
15
|
+
get: (node) => {
|
16
|
+
const babylonObject = node._babylonTransformNode;
|
17
|
+
return babylonObject.position;
|
18
|
+
},
|
19
|
+
set: (value, node) => {
|
20
|
+
const babylonObject = node._babylonTransformNode;
|
21
|
+
babylonObject.position = value;
|
22
|
+
},
|
23
|
+
getObject(node) {
|
24
|
+
return node._babylonTransformNode;
|
25
|
+
},
|
26
|
+
},
|
27
|
+
},
|
28
|
+
};
|
29
|
+
const gltfTree = {
|
30
|
+
nodes: nodesTree,
|
31
|
+
};
|
32
|
+
//# sourceMappingURL=interactivityPathToObjectConverter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"interactivityPathToObjectConverter.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/interactivityPathToObjectConverter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAIxE;;GAEG;AACH,MAAM,OAAO,kCAAmC,SAAQ,yBAA0C;IAC9F,YAAmB,IAAW;QAC1B,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1B,CAAC;CACJ;AAED,MAAM,SAAS,GAAG;IACd,SAAS,EAAE;QACP,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE;YACT,IAAI,EAAE,SAAS;YACf,GAAG,EAAE,CAAC,IAAW,EAAE,EAAE;gBACjB,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAsC,CAAC;gBAClE,OAAO,aAAa,CAAC,QAAQ,CAAC;YAClC,CAAC;YACD,GAAG,EAAE,CAAC,KAAU,EAAE,IAAW,EAAE,EAAE;gBAC7B,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAsC,CAAC;gBAClE,aAAa,CAAC,QAAQ,GAAG,KAAK,CAAC;YACnC,CAAC;YACD,SAAS,CAAC,IAAW;gBACjB,OAAO,IAAI,CAAC,qBAAqB,CAAC;YACtC,CAAC;SACJ;KACJ;CACJ,CAAC;AAEF,MAAM,QAAQ,GAAG;IACb,KAAK,EAAE,SAAS;CACnB,CAAC","sourcesContent":["import type { IGLTF, INode } from \"../glTFLoaderInterfaces\";\r\nimport { GLTFPathToObjectConverter } from \"./gltfPathToObjectConverter\";\r\nimport type { TransformNode } from \"core/Meshes\";\r\nimport type { IObjectAccessor } from \"core/FlowGraph\";\r\n\r\n/**\r\n * Class to convert an interactivity pointer path to a smart object\r\n */\r\nexport class InteractivityPathToObjectConverter extends GLTFPathToObjectConverter<IObjectAccessor> {\r\n public constructor(gltf: IGLTF) {\r\n super(gltf, gltfTree);\r\n }\r\n}\r\n\r\nconst nodesTree = {\r\n __array__: {\r\n __target__: true,\r\n translation: {\r\n type: \"Vector3\",\r\n get: (node: INode) => {\r\n const babylonObject = node._babylonTransformNode as TransformNode;\r\n return babylonObject.position;\r\n },\r\n set: (value: any, node: INode) => {\r\n const babylonObject = node._babylonTransformNode as TransformNode;\r\n babylonObject.position = value;\r\n },\r\n getObject(node: INode) {\r\n return node._babylonTransformNode;\r\n },\r\n },\r\n },\r\n};\r\n\r\nconst gltfTree = {\r\n nodes: nodesTree,\r\n};\r\n"]}
|
package/glTF/2.0/glTFLoader.d.ts
CHANGED
@@ -20,6 +20,7 @@ import type { IDataBuffer } from "@babylonjs/core/Misc/dataReader.js";
|
|
20
20
|
import type { Light } from "@babylonjs/core/Lights/light.js";
|
21
21
|
import type { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
22
22
|
import type { AnimationPropertyInfo } from "./glTFLoaderAnimation";
|
23
|
+
import type { IObjectInfo } from "@babylonjs/core/ObjectModel/objectModelInterfaces.js";
|
23
24
|
interface IWithMetadata {
|
24
25
|
metadata: any;
|
25
26
|
_internalMetadata: any;
|
@@ -223,7 +224,7 @@ export declare class GLTFLoader implements IGLTFLoader {
|
|
223
224
|
* @param onLoad Called for each animation loaded
|
224
225
|
* @returns A void promise that resolves when the load is complete
|
225
226
|
*/
|
226
|
-
_loadAnimationChannelFromTargetInfoAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, targetInfo:
|
227
|
+
_loadAnimationChannelFromTargetInfoAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, targetInfo: IObjectInfo<AnimationPropertyInfo[]>, onLoad: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): Promise<void>;
|
227
228
|
private _loadAnimationSamplerAsync;
|
228
229
|
/**
|
229
230
|
* Loads a glTF buffer.
|
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -1274,8 +1274,8 @@ export class GLTFLoader {
|
|
1274
1274
|
}
|
1275
1275
|
}
|
1276
1276
|
const targetInfo = {
|
1277
|
-
|
1278
|
-
|
1277
|
+
object: targetNode,
|
1278
|
+
info: properties,
|
1279
1279
|
};
|
1280
1280
|
return this._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);
|
1281
1281
|
}
|
@@ -1296,13 +1296,15 @@ export class GLTFLoader {
|
|
1296
1296
|
const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);
|
1297
1297
|
return this._loadAnimationSamplerAsync(`${animationContext}/samplers/${channel.sampler}`, sampler).then((data) => {
|
1298
1298
|
let numAnimations = 0;
|
1299
|
+
const target = targetInfo.object;
|
1300
|
+
const propertyInfos = targetInfo.info;
|
1299
1301
|
// Extract the corresponding values from the read value.
|
1300
1302
|
// GLTF values may be dispatched to several Babylon properties.
|
1301
1303
|
// For example, baseColorFactor [`r`, `g`, `b`, `a`] is dispatched to
|
1302
1304
|
// - albedoColor as Color3(`r`, `g`, `b`)
|
1303
1305
|
// - alpha as `a`
|
1304
|
-
for (const
|
1305
|
-
const stride =
|
1306
|
+
for (const propertyInfo of propertyInfos) {
|
1307
|
+
const stride = propertyInfo.getStride(target);
|
1306
1308
|
const input = data.input;
|
1307
1309
|
const output = data.output;
|
1308
1310
|
const keys = new Array(input.length);
|
@@ -1310,7 +1312,7 @@ export class GLTFLoader {
|
|
1310
1312
|
switch (data.interpolation) {
|
1311
1313
|
case "STEP" /* AnimationSamplerInterpolation.STEP */: {
|
1312
1314
|
for (let index = 0; index < input.length; index++) {
|
1313
|
-
const value =
|
1315
|
+
const value = propertyInfo.getValue(target, output, outputOffset, 1);
|
1314
1316
|
outputOffset += stride;
|
1315
1317
|
keys[index] = {
|
1316
1318
|
frame: input[index] * fps,
|
@@ -1322,11 +1324,11 @@ export class GLTFLoader {
|
|
1322
1324
|
}
|
1323
1325
|
case "CUBICSPLINE" /* AnimationSamplerInterpolation.CUBICSPLINE */: {
|
1324
1326
|
for (let index = 0; index < input.length; index++) {
|
1325
|
-
const inTangent =
|
1327
|
+
const inTangent = propertyInfo.getValue(target, output, outputOffset, invfps);
|
1326
1328
|
outputOffset += stride;
|
1327
|
-
const value =
|
1329
|
+
const value = propertyInfo.getValue(target, output, outputOffset, 1);
|
1328
1330
|
outputOffset += stride;
|
1329
|
-
const outTangent =
|
1331
|
+
const outTangent = propertyInfo.getValue(target, output, outputOffset, invfps);
|
1330
1332
|
outputOffset += stride;
|
1331
1333
|
keys[index] = {
|
1332
1334
|
frame: input[index] * fps,
|
@@ -1339,7 +1341,7 @@ export class GLTFLoader {
|
|
1339
1341
|
}
|
1340
1342
|
case "LINEAR" /* AnimationSamplerInterpolation.LINEAR */: {
|
1341
1343
|
for (let index = 0; index < input.length; index++) {
|
1342
|
-
const value =
|
1344
|
+
const value = propertyInfo.getValue(target, output, outputOffset, 1);
|
1343
1345
|
outputOffset += stride;
|
1344
1346
|
keys[index] = {
|
1345
1347
|
frame: input[index] * fps,
|
@@ -1351,7 +1353,7 @@ export class GLTFLoader {
|
|
1351
1353
|
}
|
1352
1354
|
if (outputOffset > 0) {
|
1353
1355
|
const name = `${animation.name || `animation${animation.index}`}_channel${channel.index}_${numAnimations}`;
|
1354
|
-
|
1356
|
+
propertyInfo.buildAnimations(target, name, fps, keys, (babylonAnimatable, babylonAnimation) => {
|
1355
1357
|
++numAnimations;
|
1356
1358
|
onLoad(babylonAnimatable, babylonAnimation);
|
1357
1359
|
});
|