@babylonjs/loaders 5.25.0 → 5.26.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 +12 -31
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.d.ts +133 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.js +169 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +54 -204
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +2 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +42 -8
- package/glTF/2.0/glTFLoader.js +204 -47
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderAnimation.d.ts +29 -0
- package/glTF/2.0/glTFLoaderAnimation.js +66 -0
- package/glTF/2.0/glTFLoaderAnimation.js.map +1 -0
- package/glTF/2.0/glTFLoaderExtension.d.ts +14 -1
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +38 -11
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/package.json +3 -3
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.d.ts +0 -15
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js +0 -454
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js.map +0 -1
- package/glTF/2.0/glTFUtilities.d.ts +0 -7
- package/glTF/2.0/glTFUtilities.js +0 -23
- package/glTF/2.0/glTFUtilities.js.map +0 -1
@@ -1,11 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
|
5
|
-
import { getDataAccessorElementCount } from "../glTFUtilities.js";
|
6
|
-
const NAME = GLTFLoader._KHRAnimationPointerName;
|
1
|
+
import { GLTFLoader } from "../glTFLoader.js";
|
2
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
3
|
+
import { animationPointerTree } from "./KHR_animation_pointer.data.js";
|
4
|
+
const NAME = "KHR_animation_pointer";
|
7
5
|
/**
|
8
6
|
* [Specification PR](https://github.com/KhronosGroup/glTF/pull/2147)
|
7
|
+
* !!! Experimental Extension Subject to Changes !!!
|
9
8
|
*/
|
10
9
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
11
10
|
export class KHR_animation_pointer {
|
@@ -13,10 +12,6 @@ export class KHR_animation_pointer {
|
|
13
12
|
* @internal
|
14
13
|
*/
|
15
14
|
constructor(loader) {
|
16
|
-
/**
|
17
|
-
* used to gently ignore invalid pointer. If false, invalid pointer will throw exception.
|
18
|
-
*/
|
19
|
-
this.ignoreInvalidPointer = true;
|
20
15
|
/**
|
21
16
|
* The name of this extension.
|
22
17
|
*/
|
@@ -34,232 +29,87 @@ export class KHR_animation_pointer {
|
|
34
29
|
this._loader = null;
|
35
30
|
}
|
36
31
|
/**
|
37
|
-
*
|
38
|
-
* It is not allowed to animate a glTFid property, as it does change the structure of the glTF in general
|
39
|
-
* It is not allowed to animate a name property in general.
|
40
|
-
* @internal
|
41
|
-
*/
|
42
|
-
accept(property) {
|
43
|
-
return property != "name";
|
44
|
-
}
|
45
|
-
loadAnimationAsync(context, animation) {
|
46
|
-
// ensure an animation group is present.
|
47
|
-
if (!animation._babylonAnimationGroup) {
|
48
|
-
this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;
|
49
|
-
const group = new AnimationGroup(animation.name || `animation${animation.index}`, this._loader.babylonScene);
|
50
|
-
group._parentContainer = this._loader._assetContainer;
|
51
|
-
this._loader.babylonScene._blockEntityCollection = false;
|
52
|
-
animation._babylonAnimationGroup = group;
|
53
|
-
}
|
54
|
-
const babylonAnimationGroup = animation._babylonAnimationGroup;
|
55
|
-
const promises = new Array();
|
56
|
-
ArrayItem.Assign(animation.channels);
|
57
|
-
ArrayItem.Assign(animation.samplers);
|
58
|
-
for (const channel of animation.channels) {
|
59
|
-
promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel.index}`, context, animation, channel));
|
60
|
-
}
|
61
|
-
return Promise.all(promises).then(() => {
|
62
|
-
babylonAnimationGroup.normalize(0);
|
63
|
-
return babylonAnimationGroup;
|
64
|
-
});
|
65
|
-
}
|
66
|
-
/**
|
67
|
-
* @internal Loads a glTF animation channel.
|
32
|
+
* Loads a glTF animation channel.
|
68
33
|
* @param context The context when loading the asset
|
69
34
|
* @param animationContext The context of the animation when loading the asset
|
70
35
|
* @param animation The glTF animation property
|
71
36
|
* @param channel The glTF animation channel property
|
72
|
-
* @param
|
73
|
-
* @returns A void promise when the
|
37
|
+
* @param onLoad Called for each animation loaded
|
38
|
+
* @returns A void promise that resolves when the load is complete or null if not handled
|
74
39
|
*/
|
75
|
-
_loadAnimationChannelAsync(context, animationContext, animation, channel,
|
76
|
-
|
77
|
-
|
40
|
+
_loadAnimationChannelAsync(context, animationContext, animation, channel, onLoad) {
|
41
|
+
const extension = channel.target.extensions?.KHR_animation_pointer;
|
42
|
+
if (!extension) {
|
43
|
+
return null;
|
44
|
+
}
|
45
|
+
if (channel.target.path !== "pointer" /* POINTER */) {
|
46
|
+
Logger.Warn(`${context}/target/path: Value (${channel.target.path}) must be (${"pointer" /* POINTER */}) when using the ${this.name} extension`);
|
78
47
|
}
|
79
48
|
if (channel.target.node != undefined) {
|
80
|
-
|
81
|
-
// If this extension is used, the animation.channel.target.node must not be set.
|
82
|
-
// Because the node is defined, the channel is ignored and not animated due to the specification.
|
83
|
-
return Promise.resolve();
|
49
|
+
Logger.Warn(`${context}/target/node: Value (${channel.target.node}) must not be present when using the ${this.name} extension`);
|
84
50
|
}
|
85
|
-
const
|
51
|
+
const extensionContext = `${context}/extensions/${this.name}`;
|
52
|
+
const pointer = extension.pointer;
|
86
53
|
if (!pointer) {
|
87
|
-
throw new Error(`${
|
88
|
-
}
|
89
|
-
const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);
|
90
|
-
return this._loadAnimationSamplerAsync(`${context}/samplers/${channel.sampler}`, sampler).then((data) => {
|
91
|
-
// this is where we process the pointer.
|
92
|
-
const animationTarget = this._parseAnimationPointer(`${context}/extensions/${this.name}/pointer`, pointer);
|
93
|
-
if (!animationTarget) {
|
94
|
-
return;
|
95
|
-
}
|
96
|
-
// build the keys
|
97
|
-
// build the animations into the group
|
98
|
-
const babylonAnimationGroup = animation._babylonAnimationGroup;
|
99
|
-
if (!babylonAnimationGroup) {
|
100
|
-
return;
|
101
|
-
}
|
102
|
-
const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);
|
103
|
-
// stride is the size of each element stored into the output buffer.
|
104
|
-
const stride = animationTarget.stride ?? getDataAccessorElementCount(outputAccessor.type);
|
105
|
-
const fps = this._loader.parent.targetFps;
|
106
|
-
// we extract the corresponding values from the read value.
|
107
|
-
// the reason for that is one GLTF value may be dispatched to several Babylon properties
|
108
|
-
// one of example is baseColorFactor which is a Color4 under GLTF and dispatched to
|
109
|
-
// - albedoColor as Color3(Color4.r,Color4.g,Color4.b)
|
110
|
-
// - alpha as Color4.a
|
111
|
-
for (const propertyInfo of animationTarget.properties) {
|
112
|
-
// Ignore animations that have no animation valid targets.
|
113
|
-
if (!propertyInfo.isValid(animationTarget.target)) {
|
114
|
-
return;
|
115
|
-
}
|
116
|
-
// build the keys.
|
117
|
-
const keys = new Array(data.input.length);
|
118
|
-
let outputOffset = 0;
|
119
|
-
switch (data.interpolation) {
|
120
|
-
case "STEP" /* STEP */: {
|
121
|
-
for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
|
122
|
-
keys[frameIndex] = {
|
123
|
-
frame: data.input[frameIndex] * fps,
|
124
|
-
value: propertyInfo.get(animationTarget.target, data.output, outputOffset),
|
125
|
-
interpolation: AnimationKeyInterpolation.STEP,
|
126
|
-
};
|
127
|
-
outputOffset += stride;
|
128
|
-
}
|
129
|
-
break;
|
130
|
-
}
|
131
|
-
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
132
|
-
const invfps = 1 / fps;
|
133
|
-
for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
|
134
|
-
const k = {
|
135
|
-
frame: data.input[frameIndex] * fps,
|
136
|
-
};
|
137
|
-
(k.inTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);
|
138
|
-
(k.value = propertyInfo.get(animationTarget.target, data.output, outputOffset)), (outputOffset += stride);
|
139
|
-
(k.outTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);
|
140
|
-
keys[frameIndex] = k;
|
141
|
-
}
|
142
|
-
break;
|
143
|
-
}
|
144
|
-
case "LINEAR" /* LINEAR */:
|
145
|
-
default: {
|
146
|
-
for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
|
147
|
-
keys[frameIndex] = {
|
148
|
-
frame: data.input[frameIndex] * fps,
|
149
|
-
value: propertyInfo.get(animationTarget.target, data.output, outputOffset),
|
150
|
-
};
|
151
|
-
outputOffset += stride;
|
152
|
-
}
|
153
|
-
break;
|
154
|
-
}
|
155
|
-
}
|
156
|
-
// each properties has its own build animation process.
|
157
|
-
// these logics are located into KHR_animation_pointer.map.ts
|
158
|
-
propertyInfo.buildAnimations(animationTarget.target, fps, keys, babylonAnimationGroup, animationTargetOverride, animationTarget.params);
|
159
|
-
}
|
160
|
-
});
|
161
|
-
}
|
162
|
-
_loadAnimationSamplerAsync(context, sampler) {
|
163
|
-
if (sampler._data) {
|
164
|
-
return sampler._data;
|
54
|
+
throw new Error(`${extensionContext}: Pointer is missing`);
|
165
55
|
}
|
166
|
-
const
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
171
|
-
break;
|
172
|
-
}
|
173
|
-
default: {
|
174
|
-
throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);
|
175
|
-
}
|
56
|
+
const targetInfo = this._parseAnimationPointer(`${extensionContext}/pointer`, pointer);
|
57
|
+
if (!targetInfo) {
|
58
|
+
Logger.Warn(`${extensionContext}/pointer: Invalid pointer (${pointer}) skipped`);
|
59
|
+
return null;
|
176
60
|
}
|
177
|
-
|
178
|
-
const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);
|
179
|
-
sampler._data = Promise.all([
|
180
|
-
this._loader._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),
|
181
|
-
this._loader._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor),
|
182
|
-
]).then(([inputData, outputData]) => {
|
183
|
-
return {
|
184
|
-
input: inputData,
|
185
|
-
interpolation: interpolation,
|
186
|
-
output: outputData,
|
187
|
-
};
|
188
|
-
});
|
189
|
-
return sampler._data;
|
61
|
+
return this._loader._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);
|
190
62
|
}
|
191
63
|
/**
|
192
|
-
*
|
193
|
-
*
|
194
|
-
*
|
195
|
-
|
196
|
-
* <animationPointer> := <sep><assetContainer><sep><assetIndex><sep><propertyPath>
|
197
|
-
* <assetContainer> := "nodes" | "materials" | "meshes" | "cameras" | "extensions"
|
64
|
+
* The pointer string is represented by a [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901).
|
65
|
+
* <animationPointer> := /<rootNode>/<assetIndex>/<propertyPath>
|
66
|
+
* <rootNode> := "nodes" | "materials" | "meshes" | "cameras" | "extensions"
|
198
67
|
* <assetIndex> := <digit> | <name>
|
199
68
|
* <propertyPath> := <extensionPath> | <standardPath>
|
200
|
-
* <extensionPath> := "extensions"
|
201
|
-
* <standardPath> := <name> | <name
|
202
|
-
* <sep>:= "/"
|
69
|
+
* <extensionPath> := "extensions"/<name>/<standardPath>
|
70
|
+
* <standardPath> := <name> | <name>/<standardPath>
|
203
71
|
* <name> := W+
|
204
72
|
* <digit> := D+
|
205
73
|
*
|
206
|
-
*
|
74
|
+
* Examples:
|
207
75
|
* - "/nodes/0/rotation"
|
208
76
|
* - "/materials/2/emissiveFactor"
|
209
77
|
* - "/materials/2/pbrMetallicRoughness/baseColorFactor"
|
210
78
|
* - "/materials/2/extensions/KHR_materials_emissive_strength/emissiveStrength"
|
211
|
-
* @param context
|
212
|
-
* @param pointer
|
213
|
-
* @returns
|
214
79
|
*/
|
215
80
|
_parseAnimationPointer(context, pointer) {
|
216
|
-
|
217
|
-
|
218
|
-
|
81
|
+
if (!pointer.startsWith("/")) {
|
82
|
+
Logger.Warn(`${context}: Value (${pointer}) must start with a slash`);
|
83
|
+
return null;
|
219
84
|
}
|
220
|
-
const parts = pointer.split(
|
221
|
-
//
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
85
|
+
const parts = pointer.split("/");
|
86
|
+
// Remove the first part since it will be empty string as pointers must start with a slash.
|
87
|
+
parts.shift();
|
88
|
+
let node = animationPointerTree;
|
89
|
+
let gltfCurrentNode = this._loader.gltf;
|
90
|
+
let gltfTargetNode = undefined;
|
91
|
+
for (const part of parts) {
|
92
|
+
if (node.__array__) {
|
93
|
+
node = node.__array__;
|
94
|
+
}
|
95
|
+
else {
|
228
96
|
node = node[part];
|
229
97
|
if (!node) {
|
230
|
-
|
231
|
-
break;
|
232
|
-
}
|
233
|
-
if (node.getTarget) {
|
234
|
-
getTarget = node.getTarget;
|
235
|
-
}
|
236
|
-
if (node.hasIndex) {
|
237
|
-
indices.push(parts[++i]);
|
238
|
-
// move to the next part
|
239
|
-
continue;
|
240
|
-
}
|
241
|
-
if (node.isIndex) {
|
242
|
-
indices.push(part);
|
243
|
-
// move to the next part
|
244
|
-
continue;
|
245
|
-
}
|
246
|
-
if (node.properties && getTarget) {
|
247
|
-
const t = getTarget(this._loader.gltf, indices[0]);
|
248
|
-
if (t != null) {
|
249
|
-
return {
|
250
|
-
target: t,
|
251
|
-
stride: node.getStride ? node.getStride(t) : undefined,
|
252
|
-
properties: node.properties,
|
253
|
-
params: indices,
|
254
|
-
};
|
255
|
-
}
|
98
|
+
return null;
|
256
99
|
}
|
257
100
|
}
|
101
|
+
gltfCurrentNode = gltfCurrentNode && gltfCurrentNode[part];
|
102
|
+
if (node.__target__) {
|
103
|
+
gltfTargetNode = gltfCurrentNode;
|
104
|
+
}
|
258
105
|
}
|
259
|
-
if (
|
106
|
+
if (!gltfTargetNode || !Array.isArray(node)) {
|
260
107
|
return null;
|
261
108
|
}
|
262
|
-
|
109
|
+
return {
|
110
|
+
target: gltfTargetNode,
|
111
|
+
properties: node,
|
112
|
+
};
|
263
113
|
}
|
264
114
|
}
|
265
115
|
GLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_animation_pointer.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/KHR_animation_pointer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAKhE,OAAO,EAAE,yBAAyB,EAAE,mDAAqC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,IAAI,GAAG,UAAU,CAAC,wBAAwB,CAAC;AASjD;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAa9B;;OAEG;IACH,YAAY,MAAkB;QAf9B;;WAEG;QACI,yBAAoB,GAAY,IAAI,CAAC;QAE5C;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAQxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,gBAAgB;IACT,OAAO;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CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;oBACzB,wBAAwB;oBACxB,SAAS;iBACZ;gBAED,IAAI,IAAI,CAAC,OAAO,EAAE;oBACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACnB,wBAAwB;oBACxB,SAAS;iBACZ;gBAED,IAAI,IAAI,CAAC,UAAU,IAAI,SAAS,EAAE;oBAC9B,MAAM,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;oBACnD,IAAI,CAAC,IAAI,IAAI,EAAE;wBACX,OAAO;4BACH,MAAM,EAAE,CAAC;4BACT,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;4BACtD,UAAU,EAAE,IAAI,CAAC,UAAU;4BAC3B,MAAM,EAAE,OAAO;yBAClB,CAAC;qBACL;iBACJ;aACJ;SACJ;QACD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,OAAO,IAAI,CAAC;SACf;QACD,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,qBAAqB,OAAO,EAAE,CAAC,CAAC;IAC9D,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 { ArrayItem, GLTFLoader } from \"../glTFLoader\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport type { IAnimatable } from \"core/Animations/animatable.interface\";\r\nimport type { IAnimation, IAnimationChannel, _IAnimationSamplerData, IAnimationSampler } from \"../glTFLoaderInterfaces\";\r\n\r\nimport { AnimationChannelTargetPath, AnimationSamplerInterpolation } from \"babylonjs-gltf2interface\";\r\nimport { AnimationKeyInterpolation } from \"core/Animations/animationKey\";\r\nimport { CoreAnimationPointerMap } from \"./KHR_animation_pointer.map\";\r\nimport type { GetGltfNodeTargetFn, IAnimationPointerPropertyInfos } from \"./KHR_animation_pointer.map\";\r\nimport { getDataAccessorElementCount } from \"../glTFUtilities\";\r\n\r\nconst NAME = GLTFLoader._KHRAnimationPointerName;\r\n\r\ninterface IAnimationChannelTarget {\r\n stride?: number;\r\n target: any;\r\n properties: Array<IAnimationPointerPropertyInfos>;\r\n params: any;\r\n}\r\n\r\n/**\r\n * [Specification PR](https://github.com/KhronosGroup/glTF/pull/2147)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_animation_pointer implements IGLTFLoaderExtension {\r\n /**\r\n * used to gently ignore invalid pointer. If false, invalid pointer will throw exception.\r\n */\r\n public ignoreInvalidPointer: boolean = true;\r\n\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\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\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 }\r\n\r\n /**\r\n * according to specification,\r\n * It is not allowed to animate a glTFid property, as it does change the structure of the glTF in general\r\n * It is not allowed to animate a name property in general.\r\n * @internal\r\n */\r\n public accept(property: string): boolean {\r\n return property != \"name\";\r\n }\r\n\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n // ensure an animation group is present.\r\n if (!animation._babylonAnimationGroup) {\r\n this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;\r\n const group = new AnimationGroup(animation.name || `animation${animation.index}`, this._loader.babylonScene);\r\n group._parentContainer = this._loader._assetContainer;\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n animation._babylonAnimationGroup = group;\r\n }\r\n const babylonAnimationGroup = animation._babylonAnimationGroup;\r\n\r\n const promises = new Array<Promise<any>>();\r\n ArrayItem.Assign(animation.channels);\r\n ArrayItem.Assign(animation.samplers);\r\n\r\n for (const channel of animation.channels) {\r\n promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel.index}`, context, animation, channel));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n babylonAnimationGroup.normalize(0);\r\n return babylonAnimationGroup;\r\n });\r\n }\r\n\r\n /**\r\n * @internal 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 animationTargetOverride The babylon animation channel target override property. My be null.\r\n * @returns A void promise when the channel load is complete\r\n */\r\n public _loadAnimationChannelAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n channel: IAnimationChannel,\r\n animationTargetOverride: Nullable<IAnimatable> = null\r\n ): Promise<void> {\r\n if (channel.target.path != AnimationChannelTargetPath.POINTER) {\r\n throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);\r\n }\r\n\r\n if (channel.target.node != undefined) {\r\n // According to KHR_animation_pointer specification\r\n // If this extension is used, the animation.channel.target.node must not be set.\r\n // Because the node is defined, the channel is ignored and not animated due to the specification.\r\n return Promise.resolve();\r\n }\r\n\r\n const pointer = channel.target.extensions?.KHR_animation_pointer?.pointer;\r\n if (!pointer) {\r\n throw new Error(`${context}/target/extensions/${this.name}: Pointer is missing`);\r\n }\r\n\r\n const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);\r\n\r\n return this._loadAnimationSamplerAsync(`${context}/samplers/${channel.sampler}`, sampler).then((data) => {\r\n // this is where we process the pointer.\r\n const animationTarget = this._parseAnimationPointer(`${context}/extensions/${this.name}/pointer`, pointer);\r\n\r\n if (!animationTarget) {\r\n return;\r\n }\r\n // build the keys\r\n // build the animations into the group\r\n const babylonAnimationGroup = animation._babylonAnimationGroup;\r\n if (!babylonAnimationGroup) {\r\n return;\r\n }\r\n\r\n const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);\r\n // stride is the size of each element stored into the output buffer.\r\n const stride = animationTarget.stride ?? getDataAccessorElementCount(outputAccessor.type);\r\n const fps = this._loader.parent.targetFps;\r\n\r\n // we extract the corresponding values from the read value.\r\n // the reason for that is one GLTF value may be dispatched to several Babylon properties\r\n // one of example is baseColorFactor which is a Color4 under GLTF and dispatched to\r\n // - albedoColor as Color3(Color4.r,Color4.g,Color4.b)\r\n // - alpha as Color4.a\r\n for (const propertyInfo of animationTarget.properties) {\r\n // Ignore animations that have no animation valid targets.\r\n if (!propertyInfo.isValid(animationTarget.target)) {\r\n return;\r\n }\r\n\r\n // build the keys.\r\n const keys = new Array(data.input.length);\r\n let outputOffset = 0;\r\n\r\n switch (data.interpolation) {\r\n case AnimationSamplerInterpolation.STEP: {\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n keys[frameIndex] = {\r\n frame: data.input[frameIndex] * fps,\r\n value: propertyInfo.get(animationTarget.target, data.output, outputOffset),\r\n interpolation: AnimationKeyInterpolation.STEP,\r\n };\r\n outputOffset += stride;\r\n }\r\n break;\r\n }\r\n case AnimationSamplerInterpolation.CUBICSPLINE: {\r\n const invfps = 1 / fps;\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n const k: any = {\r\n frame: data.input[frameIndex] * fps,\r\n };\r\n\r\n (k.inTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);\r\n (k.value = propertyInfo.get(animationTarget.target, data.output, outputOffset)), (outputOffset += stride);\r\n (k.outTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);\r\n\r\n keys[frameIndex] = k;\r\n }\r\n break;\r\n }\r\n case AnimationSamplerInterpolation.LINEAR:\r\n default: {\r\n for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {\r\n keys[frameIndex] = {\r\n frame: data.input[frameIndex] * fps,\r\n value: propertyInfo.get(animationTarget.target, data.output, outputOffset),\r\n };\r\n outputOffset += stride;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n // each properties has its own build animation process.\r\n // these logics are located into KHR_animation_pointer.map.ts\r\n propertyInfo.buildAnimations(animationTarget.target, fps, keys, babylonAnimationGroup, animationTargetOverride, animationTarget.params);\r\n }\r\n });\r\n }\r\n\r\n private _loadAnimationSamplerAsync(context: string, sampler: IAnimationSampler): Promise<_IAnimationSamplerData> {\r\n if (sampler._data) {\r\n return sampler._data;\r\n }\r\n\r\n const interpolation = sampler.interpolation || AnimationSamplerInterpolation.LINEAR;\r\n switch (interpolation) {\r\n case AnimationSamplerInterpolation.STEP:\r\n case AnimationSamplerInterpolation.LINEAR:\r\n case AnimationSamplerInterpolation.CUBICSPLINE: {\r\n break;\r\n }\r\n default: {\r\n throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);\r\n }\r\n }\r\n\r\n const inputAccessor = ArrayItem.Get(`${context}/input`, this._loader.gltf.accessors, sampler.input);\r\n const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);\r\n sampler._data = Promise.all([\r\n this._loader._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),\r\n this._loader._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor),\r\n ]).then(([inputData, outputData]) => {\r\n return {\r\n input: inputData,\r\n interpolation: interpolation,\r\n output: outputData,\r\n };\r\n });\r\n\r\n return sampler._data;\r\n }\r\n\r\n /**\r\n * parsing animation pointer is the core of animation channel.\r\n * Animation pointer is a Json pointer, which mean it locate an item into the json hierarchy.\r\n * Consequentely the pointer has the following BNF\r\n \r\n * <animationPointer> := <sep><assetContainer><sep><assetIndex><sep><propertyPath>\r\n * <assetContainer> := \"nodes\" | \"materials\" | \"meshes\" | \"cameras\" | \"extensions\" \r\n * <assetIndex> := <digit> | <name>\r\n * <propertyPath> := <extensionPath> | <standardPath>\r\n * <extensionPath> := \"extensions\"<sep><name><sep><standardPath>\r\n * <standardPath> := <name> | <name><sep><standardPath> \r\n * <sep>:= \"/\"\r\n * <name> := W+\r\n * <digit> := D+\r\n * \r\n * examples of pointer are\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 * @param context \r\n * @param pointer \r\n * @returns \r\n */\r\n private _parseAnimationPointer(context: string, pointer: string): Nullable<IAnimationChannelTarget> {\r\n const sep = \"/\";\r\n if (pointer.charAt(0) == sep) {\r\n pointer = pointer.substring(1);\r\n }\r\n const parts = pointer.split(sep);\r\n // we have a least 3 part\r\n if (parts.length >= 3) {\r\n let node = CoreAnimationPointerMap; // the map of possible path\r\n const indices = [];\r\n let getTarget: Nullable<GetGltfNodeTargetFn> = null;\r\n for (let i = 0; i < parts.length; i++) {\r\n const part = parts[i];\r\n node = node[part];\r\n\r\n if (!node) {\r\n // nothing to do so far\r\n break;\r\n }\r\n\r\n if (node.getTarget) {\r\n getTarget = node.getTarget;\r\n }\r\n\r\n if (node.hasIndex) {\r\n indices.push(parts[++i]);\r\n // move to the next part\r\n continue;\r\n }\r\n\r\n if (node.isIndex) {\r\n indices.push(part);\r\n // move to the next part\r\n continue;\r\n }\r\n\r\n if (node.properties && getTarget) {\r\n const t = getTarget(this._loader.gltf, indices[0]);\r\n if (t != null) {\r\n return {\r\n target: t,\r\n stride: node.getStride ? node.getStride(t) : undefined,\r\n properties: node.properties,\r\n params: indices,\r\n };\r\n }\r\n }\r\n }\r\n }\r\n if (this.ignoreInvalidPointer) {\r\n return null;\r\n }\r\n throw new Error(`${context} invalid pointer. ${pointer}`);\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_animation_pointer.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/KHR_animation_pointer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAQ9B;;OAEG;IACH,YAAY,MAAkB;QAV9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAQxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;;;;;;;OAQG;IACI,0BAA0B,CAC7B,OAAe,EACf,gBAAwB,EACxB,SAAqB,EACrB,OAA0B,EAC1B,MAA6E;QAE7E,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,qBAA6C,CAAC;QAC3F,IAAI,CAAC,SAAS,EAAE;YACZ,OAAO,IAAI,CAAC;SACf;QAED,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,4BAAuC,EAAE;YAC5D,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,wBAAwB,OAAO,CAAC,MAAM,CAAC,IAAI,cAAc,uBAAkC,oBAAoB,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC;SAC/J;QAED,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,SAAS,EAAE;YAClC,M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,IAAI,KAAK,EAAE;YACtB,IAAI,IAAI,CAAC,SAAS,EAAE;gBAChB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;aACzB;iBAAM;gBACH,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;gBAClB,IAAI,CAAC,IAAI,EAAE;oBACP,OAAO,IAAI,CAAC;iBACf;aACJ;YAED,eAAe,GAAG,eAAe,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;YAE3D,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjB,cAAc,GAAG,eAAe,CAAC;aACpC;SACJ;QAED,IAAI,CAAC,cAAc,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACzC,OAAO,IAAI,CAAC;SACf;QAED,OAAO;YACH,MAAM,EAAE,cAAc;YACtB,UAAU,EAAE,IAAI;SACnB,CAAC;IACN,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 { IAnimationTargetInfo } 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 } 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\n\r\nconst NAME = \"KHR_animation_pointer\";\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\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\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 }\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) {\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 const targetInfo = this._parseAnimationPointer(`${extensionContext}/pointer`, pointer);\r\n if (!targetInfo) {\r\n Logger.Warn(`${extensionContext}/pointer: Invalid pointer (${pointer}) skipped`);\r\n return null;\r\n }\r\n\r\n return this._loader._loadAnimationChannelFromTargetInfoAsync(context, animationContext, animation, channel, targetInfo, onLoad);\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 private _parseAnimationPointer(context: string, pointer: string): Nullable<IAnimationTargetInfo> {\r\n if (!pointer.startsWith(\"/\")) {\r\n Logger.Warn(`${context}: Value (${pointer}) must start with a slash`);\r\n return null;\r\n }\r\n\r\n const parts = pointer.split(\"/\");\r\n\r\n // Remove the first part since it will be empty string as pointers must start with a slash.\r\n parts.shift();\r\n\r\n let node: any = animationPointerTree;\r\n let gltfCurrentNode: any = this._loader.gltf;\r\n let gltfTargetNode: any = undefined;\r\n for (const part of parts) {\r\n if (node.__array__) {\r\n node = node.__array__;\r\n } else {\r\n node = node[part];\r\n if (!node) {\r\n return null;\r\n }\r\n }\r\n\r\n gltfCurrentNode = gltfCurrentNode && gltfCurrentNode[part];\r\n\r\n if (node.__target__) {\r\n gltfTargetNode = gltfCurrentNode;\r\n }\r\n }\r\n\r\n if (!gltfTargetNode || !Array.isArray(node)) {\r\n return null;\r\n }\r\n\r\n return {\r\n target: gltfTargetNode,\r\n properties: node,\r\n };\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));\r\n"]}
|
@@ -32,6 +32,7 @@ export class KHR_lights {
|
|
32
32
|
if (extensions && extensions[this.name]) {
|
33
33
|
const extension = extensions[this.name];
|
34
34
|
this._lights = extension.lights;
|
35
|
+
ArrayItem.Assign(this._lights);
|
35
36
|
}
|
36
37
|
}
|
37
38
|
/**
|
@@ -67,13 +68,13 @@ export class KHR_lights {
|
|
67
68
|
}
|
68
69
|
babylonLight._parentContainer = this._loader._assetContainer;
|
69
70
|
this._loader.babylonScene._blockEntityCollection = false;
|
71
|
+
light._babylonLight = babylonLight;
|
70
72
|
babylonLight.falloffType = Light.FALLOFF_GLTF;
|
71
73
|
babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White();
|
72
74
|
babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
|
73
75
|
babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
|
74
76
|
babylonLight.parent = babylonMesh;
|
75
77
|
this._loader._babylonLights.push(babylonLight);
|
76
|
-
light._babylonLight = babylonLight;
|
77
78
|
GLTFLoader.AddPointerMetadata(babylonLight, extensionContext);
|
78
79
|
assign(babylonMesh);
|
79
80
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,gBAAgB,EAAE,mDAAqC;AAChE,OAAO,EAAE,UAAU,EAAE,6CAA+B;AACpD,OAAO,EAAE,SAAS,EAAE,4CAA8B;AAClD,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAO1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,UAAU;IAenB;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,gBAAgB;IACT,SAAS;QACZ,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAQ,CAAC;YAC/C,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,gBAAgB,EAAE,mDAAqC;AAChE,OAAO,EAAE,UAAU,EAAE,6CAA+B;AACpD,OAAO,EAAE,SAAS,EAAE,4CAA8B;AAClD,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAO1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,UAAU;IAenB;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM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GAAG,KAAK,CAAC;gBACzD,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC;gBAEnC,YAAY,CAAC,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC;gBAC9C,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBACpF,YAAY,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;gBAC5E,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC/E,YAAY,CAAC,MAAM,GAAG,WAAW,CAAC;gBAElC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAE/C,UAAU,CAAC,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;gBAE9D,MAAM,CAAC,WAAW,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { PointLight } from \"core/Lights/pointLight\";\r\nimport { SpotLight } from \"core/Lights/spotLight\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\n\r\nimport type { IKHRLightsPunctual_LightReference } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { INode, IKHRLightsPunctual_Light } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)\r\n */\r\nexport class KHR_lights implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /** hidden */\r\n private _loader: GLTFLoader;\r\n private _lights?: IKHRLightsPunctual_Light[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = 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._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as any;\r\n this._lights = extension.lights;\r\n ArrayItem.Assign(this._lights);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRLightsPunctual_LightReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n return this._loader.loadNodeAsync(context, node, (babylonMesh) => {\r\n let babylonLight: Light;\r\n\r\n const light = ArrayItem.Get(extensionContext, this._lights, extension.light);\r\n const name = light.name || babylonMesh.name;\r\n\r\n this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;\r\n\r\n switch (light.type) {\r\n case KHRLightsPunctual_LightType.DIRECTIONAL: {\r\n babylonLight = new DirectionalLight(name, Vector3.Backward(), this._loader.babylonScene);\r\n break;\r\n }\r\n case KHRLightsPunctual_LightType.POINT: {\r\n babylonLight = new PointLight(name, Vector3.Zero(), this._loader.babylonScene);\r\n break;\r\n }\r\n case KHRLightsPunctual_LightType.SPOT: {\r\n const babylonSpotLight = new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene);\r\n babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;\r\n babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;\r\n babylonLight = babylonSpotLight;\r\n break;\r\n }\r\n default: {\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n throw new Error(`${extensionContext}: Invalid light type (${light.type})`);\r\n }\r\n }\r\n\r\n babylonLight._parentContainer = this._loader._assetContainer;\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n light._babylonLight = babylonLight;\r\n\r\n babylonLight.falloffType = Light.FALLOFF_GLTF;\r\n babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White();\r\n babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;\r\n babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;\r\n babylonLight.parent = babylonMesh;\r\n\r\n this._loader._babylonLights.push(babylonLight);\r\n\r\n GLTFLoader.AddPointerMetadata(babylonLight, extensionContext);\r\n\r\n assign(babylonMesh);\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_lights(loader));\r\n"]}
|
package/glTF/2.0/glTFLoader.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import type { Nullable } from "@babylonjs/core/types.js";
|
2
2
|
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
3
|
+
import type { Animation } from "@babylonjs/core/Animations/animation.js";
|
4
|
+
import type { IAnimatable } from "@babylonjs/core/Animations/animatable.interface.js";
|
3
5
|
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
|
4
6
|
import { Material } from "@babylonjs/core/Materials/material.js";
|
5
7
|
import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
@@ -9,13 +11,17 @@ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
|
9
11
|
import type { ISceneLoaderAsyncResult, ISceneLoaderProgressEvent } from "@babylonjs/core/Loading/sceneLoader.js";
|
10
12
|
import type { Scene } from "@babylonjs/core/scene.js";
|
11
13
|
import type { IProperty } from "babylonjs-gltf2interface";
|
12
|
-
import type { IGLTF, ISampler, INode, IScene, IMesh, IAccessor, ICamera, IAnimation, IBuffer, IBufferView, IMaterial, ITextureInfo, ITexture, IImage, IMeshPrimitive, IArrayItem
|
14
|
+
import type { IGLTF, ISampler, INode, IScene, IMesh, IAccessor, ICamera, IAnimation, IBuffer, IBufferView, IMaterial, ITextureInfo, ITexture, IImage, IMeshPrimitive, IArrayItem, IAnimationChannel } from "./glTFLoaderInterfaces";
|
13
15
|
import type { IGLTFLoaderExtension } from "./glTFLoaderExtension";
|
14
16
|
import type { IGLTFLoader, IGLTFLoaderData } from "../glTFFileLoader";
|
15
17
|
import { GLTFFileLoader } from "../glTFFileLoader";
|
16
18
|
import type { IDataBuffer } from "@babylonjs/core/Misc/dataReader.js";
|
17
19
|
import type { Light } from "@babylonjs/core/Lights/light.js";
|
18
20
|
import type { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
21
|
+
import type { AnimationPropertyInfo } from "./glTFLoaderAnimation";
|
22
|
+
interface IWithMetadata {
|
23
|
+
metadata: any;
|
24
|
+
}
|
19
25
|
/**
|
20
26
|
* Helper class for working with arrays when loading the glTF asset
|
21
27
|
*/
|
@@ -32,14 +38,19 @@ export declare class ArrayItem {
|
|
32
38
|
* Assign an `index` field to each item of the given array.
|
33
39
|
* @param array The array of items
|
34
40
|
*/
|
35
|
-
static Assign(array?:
|
41
|
+
static Assign(array?: IArrayItem[]): void;
|
42
|
+
}
|
43
|
+
/** @internal */
|
44
|
+
export interface IAnimationTargetInfo {
|
45
|
+
/** @internal */
|
46
|
+
target: any;
|
47
|
+
/** @internal */
|
48
|
+
properties: Array<AnimationPropertyInfo>;
|
36
49
|
}
|
37
50
|
/**
|
38
51
|
* The glTF 2.0 loader
|
39
52
|
*/
|
40
53
|
export declare class GLTFLoader implements IGLTFLoader {
|
41
|
-
/** @internal */
|
42
|
-
static readonly _KHRAnimationPointerName = "KHR_animation_pointer";
|
43
54
|
/** @internal */
|
44
55
|
readonly _completePromises: Promise<any>[];
|
45
56
|
/** @internal */
|
@@ -179,6 +190,30 @@ export declare class GLTFLoader implements IGLTFLoader {
|
|
179
190
|
* @returns A promise that resolves with the loaded Babylon animation group when the load is complete
|
180
191
|
*/
|
181
192
|
loadAnimationAsync(context: string, animation: IAnimation): Promise<AnimationGroup>;
|
193
|
+
/**
|
194
|
+
* @hidden
|
195
|
+
* Loads a glTF animation channel.
|
196
|
+
* @param context The context when loading the asset
|
197
|
+
* @param animationContext The context of the animation when loading the asset
|
198
|
+
* @param animation The glTF animation property
|
199
|
+
* @param channel The glTF animation channel property
|
200
|
+
* @param onLoad Called for each animation loaded
|
201
|
+
* @returns A void promise that resolves when the load is complete
|
202
|
+
*/
|
203
|
+
_loadAnimationChannelAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, onLoad: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): Promise<void>;
|
204
|
+
/**
|
205
|
+
* @hidden
|
206
|
+
* Loads a glTF animation channel.
|
207
|
+
* @param context The context when loading the asset
|
208
|
+
* @param animationContext The context of the animation when loading the asset
|
209
|
+
* @param animation The glTF animation property
|
210
|
+
* @param channel The glTF animation channel property
|
211
|
+
* @param targetInfo The glTF target and properties
|
212
|
+
* @param onLoad Called for each animation loaded
|
213
|
+
* @returns A void promise that resolves when the load is complete
|
214
|
+
*/
|
215
|
+
_loadAnimationChannelFromTargetInfoAsync(context: string, animationContext: string, animation: IAnimation, channel: IAnimationChannel, targetInfo: IAnimationTargetInfo, onLoad: (babylonAnimatable: IAnimatable, babylonAnimation: Animation) => void): Promise<void>;
|
216
|
+
private _loadAnimationSamplerAsync;
|
182
217
|
/**
|
183
218
|
* Loads a glTF buffer.
|
184
219
|
* @param context The context when loading the asset
|
@@ -276,12 +311,9 @@ export declare class GLTFLoader implements IGLTFLoader {
|
|
276
311
|
/**
|
277
312
|
* Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
|
278
313
|
* @param babylonObject the Babylon object with metadata
|
279
|
-
* @param babylonObject.metadata
|
280
314
|
* @param pointer the JSON pointer
|
281
315
|
*/
|
282
|
-
static AddPointerMetadata(babylonObject:
|
283
|
-
metadata: any;
|
284
|
-
}, pointer: string): void;
|
316
|
+
static AddPointerMetadata(babylonObject: IWithMetadata, pointer: string): void;
|
285
317
|
private static _GetTextureWrapMode;
|
286
318
|
private static _GetTextureSamplingMode;
|
287
319
|
private static _GetTypedArrayConstructor;
|
@@ -309,6 +341,7 @@ export declare class GLTFLoader implements IGLTFLoader {
|
|
309
341
|
private _extensionsLoadTextureInfoAsync;
|
310
342
|
private _extensionsLoadTextureAsync;
|
311
343
|
private _extensionsLoadAnimationAsync;
|
344
|
+
private _extensionsLoadAnimationChannelAsync;
|
312
345
|
private _extensionsLoadSkinAsync;
|
313
346
|
private _extensionsLoadUriAsync;
|
314
347
|
private _extensionsLoadBufferViewAsync;
|
@@ -362,3 +395,4 @@ export declare class GLTFLoader implements IGLTFLoader {
|
|
362
395
|
*/
|
363
396
|
endPerformanceCounter(counterName: string): void;
|
364
397
|
}
|
398
|
+
export {};
|