@babylonjs/loaders 5.21.0 → 5.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/mtlFileLoader.js +25 -27
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.js +112 -124
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/solidParser.js +118 -125
- package/OBJ/solidParser.js.map +1 -1
- package/STL/stlFileLoader.js +61 -63
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.js +26 -30
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.js +409 -432
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.js +33 -37
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.js +27 -31
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +48 -59
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +24 -29
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +13 -16
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +13 -16
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +22 -26
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +63 -76
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js +90 -120
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +25 -28
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +27 -30
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +25 -28
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +15 -18
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js +21 -24
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +27 -31
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +24 -27
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +23 -26
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +23 -26
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +20 -23
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +82 -86
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +19 -22
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +79 -97
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +20 -23
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +6 -8
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +13 -16
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +12 -15
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +12 -15
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +77 -95
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +114 -139
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +12 -15
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +12 -15
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/glTFLoader.js +739 -823
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.js +337 -404
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +32 -39
- package/glTF/glTFValidation.js.map +1 -1
- package/legacy/legacy-glTF.js +3 -3
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.js +2 -2
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF2.js +12 -12
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-objFileLoader.js +2 -2
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.js +2 -2
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/package.json +3 -6
@@ -3,17 +3,17 @@ import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
|
|
3
3
|
import { AnimationKeyInterpolation } from "@babylonjs/core/Animations/animationKey.js";
|
4
4
|
import { CoreAnimationPointerMap } from "./KHR_animation_pointer.map.js";
|
5
5
|
import { getDataAccessorElementCount } from "../glTFUtilities.js";
|
6
|
-
|
6
|
+
const NAME = GLTFLoader._KHRAnimationPointerName;
|
7
7
|
/**
|
8
8
|
* [Specification PR](https://github.com/KhronosGroup/glTF/pull/2147)
|
9
9
|
*/
|
10
10
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
11
|
-
|
11
|
+
export class KHR_animation_pointer {
|
12
12
|
/**
|
13
13
|
* @param loader
|
14
14
|
* @hidden
|
15
15
|
*/
|
16
|
-
|
16
|
+
constructor(loader) {
|
17
17
|
/**
|
18
18
|
* used to gently ignore invalid pointer. If false, invalid pointer will throw exception.
|
19
19
|
*/
|
@@ -24,20 +24,16 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
24
24
|
this.name = NAME;
|
25
25
|
this._loader = loader;
|
26
26
|
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
},
|
34
|
-
enumerable: false,
|
35
|
-
configurable: true
|
36
|
-
});
|
27
|
+
/**
|
28
|
+
* Defines whether this extension is enabled.
|
29
|
+
*/
|
30
|
+
get enabled() {
|
31
|
+
return this._loader.isExtensionUsed(NAME);
|
32
|
+
}
|
37
33
|
/** @hidden */
|
38
|
-
|
34
|
+
dispose() {
|
39
35
|
this._loader = null;
|
40
|
-
}
|
36
|
+
}
|
41
37
|
/**
|
42
38
|
* according to specification,
|
43
39
|
* It is not allowed to animate a glTFid property, as it does change the structure of the glTF in general
|
@@ -45,31 +41,30 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
45
41
|
* @param property
|
46
42
|
* @hidden
|
47
43
|
*/
|
48
|
-
|
44
|
+
accept(property) {
|
49
45
|
return property != "name";
|
50
|
-
}
|
51
|
-
|
46
|
+
}
|
47
|
+
loadAnimationAsync(context, animation) {
|
52
48
|
// ensure an animation group is present.
|
53
49
|
if (!animation._babylonAnimationGroup) {
|
54
50
|
this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;
|
55
|
-
|
51
|
+
const group = new AnimationGroup(animation.name || `animation${animation.index}`, this._loader.babylonScene);
|
56
52
|
group._parentContainer = this._loader._assetContainer;
|
57
53
|
this._loader.babylonScene._blockEntityCollection = false;
|
58
54
|
animation._babylonAnimationGroup = group;
|
59
55
|
}
|
60
|
-
|
61
|
-
|
56
|
+
const babylonAnimationGroup = animation._babylonAnimationGroup;
|
57
|
+
const promises = new Array();
|
62
58
|
ArrayItem.Assign(animation.channels);
|
63
59
|
ArrayItem.Assign(animation.samplers);
|
64
|
-
for (
|
65
|
-
|
66
|
-
promises.push(this._loadAnimationChannelAsync("".concat(context, "/channels/").concat(channel.index), context, animation, channel));
|
60
|
+
for (const channel of animation.channels) {
|
61
|
+
promises.push(this._loadAnimationChannelAsync(`${context}/channels/${channel.index}`, context, animation, channel));
|
67
62
|
}
|
68
|
-
return Promise.all(promises).then(
|
63
|
+
return Promise.all(promises).then(() => {
|
69
64
|
babylonAnimationGroup.normalize(0);
|
70
65
|
return babylonAnimationGroup;
|
71
66
|
});
|
72
|
-
}
|
67
|
+
}
|
73
68
|
/**
|
74
69
|
* @hidden Loads a glTF animation channel.
|
75
70
|
* @param context The context when loading the asset
|
@@ -79,12 +74,9 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
79
74
|
* @param animationTargetOverride The babylon animation channel target override property. My be null.
|
80
75
|
* @returns A void promise when the channel load is complete
|
81
76
|
*/
|
82
|
-
|
83
|
-
var _this = this;
|
84
|
-
var _a, _b;
|
85
|
-
if (animationTargetOverride === void 0) { animationTargetOverride = null; }
|
77
|
+
_loadAnimationChannelAsync(context, animationContext, animation, channel, animationTargetOverride = null) {
|
86
78
|
if (channel.target.path != "pointer" /* POINTER */) {
|
87
|
-
throw new Error(
|
79
|
+
throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);
|
88
80
|
}
|
89
81
|
if (channel.target.node != undefined) {
|
90
82
|
// According to KHR_animation_pointer specification
|
@@ -92,45 +84,43 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
92
84
|
// Because the node is defined, the channel is ignored and not animated due to the specification.
|
93
85
|
return Promise.resolve();
|
94
86
|
}
|
95
|
-
|
87
|
+
const pointer = channel.target.extensions?.KHR_animation_pointer?.pointer;
|
96
88
|
if (!pointer) {
|
97
|
-
throw new Error(
|
89
|
+
throw new Error(`${context}/target/extensions/${this.name}: Pointer is missing`);
|
98
90
|
}
|
99
|
-
|
100
|
-
return this._loadAnimationSamplerAsync(
|
101
|
-
var _a;
|
91
|
+
const sampler = ArrayItem.Get(`${context}/sampler`, animation.samplers, channel.sampler);
|
92
|
+
return this._loadAnimationSamplerAsync(`${context}/samplers/${channel.sampler}`, sampler).then((data) => {
|
102
93
|
// this is where we process the pointer.
|
103
|
-
|
94
|
+
const animationTarget = this._parseAnimationPointer(`${context}/extensions/${this.name}/pointer`, pointer);
|
104
95
|
if (!animationTarget) {
|
105
96
|
return;
|
106
97
|
}
|
107
98
|
// build the keys
|
108
99
|
// build the animations into the group
|
109
|
-
|
100
|
+
const babylonAnimationGroup = animation._babylonAnimationGroup;
|
110
101
|
if (!babylonAnimationGroup) {
|
111
102
|
return;
|
112
103
|
}
|
113
|
-
|
104
|
+
const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);
|
114
105
|
// stride is the size of each element stored into the output buffer.
|
115
|
-
|
116
|
-
|
106
|
+
const stride = animationTarget.stride ?? getDataAccessorElementCount(outputAccessor.type);
|
107
|
+
const fps = this._loader.parent.targetFps;
|
117
108
|
// we extract the corresponding values from the read value.
|
118
109
|
// the reason for that is one GLTF value may be dispatched to several Babylon properties
|
119
110
|
// one of example is baseColorFactor which is a Color4 under GLTF and dispatched to
|
120
111
|
// - albedoColor as Color3(Color4.r,Color4.g,Color4.b)
|
121
112
|
// - alpha as Color4.a
|
122
|
-
for (
|
123
|
-
var propertyInfo = _b[_i];
|
113
|
+
for (const propertyInfo of animationTarget.properties) {
|
124
114
|
// Ignore animations that have no animation valid targets.
|
125
115
|
if (!propertyInfo.isValid(animationTarget.target)) {
|
126
116
|
return;
|
127
117
|
}
|
128
118
|
// build the keys.
|
129
|
-
|
130
|
-
|
119
|
+
const keys = new Array(data.input.length);
|
120
|
+
let outputOffset = 0;
|
131
121
|
switch (data.interpolation) {
|
132
122
|
case "STEP" /* STEP */: {
|
133
|
-
for (
|
123
|
+
for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
|
134
124
|
keys[frameIndex] = {
|
135
125
|
frame: data.input[frameIndex] * fps,
|
136
126
|
value: propertyInfo.get(animationTarget.target, data.output, outputOffset),
|
@@ -141,9 +131,9 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
141
131
|
break;
|
142
132
|
}
|
143
133
|
case "CUBICSPLINE" /* CUBICSPLINE */: {
|
144
|
-
|
145
|
-
for (
|
146
|
-
|
134
|
+
const invfps = 1 / fps;
|
135
|
+
for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
|
136
|
+
const k = {
|
147
137
|
frame: data.input[frameIndex] * fps,
|
148
138
|
};
|
149
139
|
(k.inTangent = propertyInfo.get(animationTarget.target, data.output, outputOffset, invfps)), (outputOffset += stride);
|
@@ -155,7 +145,7 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
155
145
|
}
|
156
146
|
case "LINEAR" /* LINEAR */:
|
157
147
|
default: {
|
158
|
-
for (
|
148
|
+
for (let frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
|
159
149
|
keys[frameIndex] = {
|
160
150
|
frame: data.input[frameIndex] * fps,
|
161
151
|
value: propertyInfo.get(animationTarget.target, data.output, outputOffset),
|
@@ -170,12 +160,12 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
170
160
|
propertyInfo.buildAnimations(animationTarget.target, fps, keys, babylonAnimationGroup, animationTargetOverride, animationTarget.params);
|
171
161
|
}
|
172
162
|
});
|
173
|
-
}
|
174
|
-
|
163
|
+
}
|
164
|
+
_loadAnimationSamplerAsync(context, sampler) {
|
175
165
|
if (sampler._data) {
|
176
166
|
return sampler._data;
|
177
167
|
}
|
178
|
-
|
168
|
+
const interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
|
179
169
|
switch (interpolation) {
|
180
170
|
case "STEP" /* STEP */:
|
181
171
|
case "LINEAR" /* LINEAR */:
|
@@ -183,16 +173,15 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
183
173
|
break;
|
184
174
|
}
|
185
175
|
default: {
|
186
|
-
throw new Error(
|
176
|
+
throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);
|
187
177
|
}
|
188
178
|
}
|
189
|
-
|
190
|
-
|
179
|
+
const inputAccessor = ArrayItem.Get(`${context}/input`, this._loader.gltf.accessors, sampler.input);
|
180
|
+
const outputAccessor = ArrayItem.Get(`${context}/output`, this._loader.gltf.accessors, sampler.output);
|
191
181
|
sampler._data = Promise.all([
|
192
|
-
this._loader._loadFloatAccessorAsync(
|
193
|
-
this._loader._loadFloatAccessorAsync(
|
194
|
-
]).then(
|
195
|
-
var inputData = _a[0], outputData = _a[1];
|
182
|
+
this._loader._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),
|
183
|
+
this._loader._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor),
|
184
|
+
]).then(([inputData, outputData]) => {
|
196
185
|
return {
|
197
186
|
input: inputData,
|
198
187
|
interpolation: interpolation,
|
@@ -200,7 +189,7 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
200
189
|
};
|
201
190
|
});
|
202
191
|
return sampler._data;
|
203
|
-
}
|
192
|
+
}
|
204
193
|
/**
|
205
194
|
* parsing animation pointer is the core of animation channel.
|
206
195
|
* Animation pointer is a Json pointer, which mean it locate an item into the json hierarchy.
|
@@ -225,19 +214,19 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
225
214
|
* @param pointer
|
226
215
|
* @return
|
227
216
|
*/
|
228
|
-
|
229
|
-
|
217
|
+
_parseAnimationPointer(context, pointer) {
|
218
|
+
const sep = "/";
|
230
219
|
if (pointer.charAt(0) == sep) {
|
231
220
|
pointer = pointer.substring(1);
|
232
221
|
}
|
233
|
-
|
222
|
+
const parts = pointer.split(sep);
|
234
223
|
// we have a least 3 part
|
235
224
|
if (parts.length >= 3) {
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
for (
|
240
|
-
|
225
|
+
let node = CoreAnimationPointerMap; // the map of possible path
|
226
|
+
const indices = [];
|
227
|
+
let getTarget = null;
|
228
|
+
for (let i = 0; i < parts.length; i++) {
|
229
|
+
const part = parts[i];
|
241
230
|
node = node[part];
|
242
231
|
if (!node) {
|
243
232
|
// nothing to do so far
|
@@ -257,7 +246,7 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
257
246
|
continue;
|
258
247
|
}
|
259
248
|
if (node.properties && getTarget) {
|
260
|
-
|
249
|
+
const t = getTarget(this._loader.gltf, indices[0]);
|
261
250
|
if (t != null) {
|
262
251
|
return {
|
263
252
|
target: t,
|
@@ -272,10 +261,8 @@ var KHR_animation_pointer = /** @class */ (function () {
|
|
272
261
|
if (this.ignoreInvalidPointer) {
|
273
262
|
return null;
|
274
263
|
}
|
275
|
-
throw new Error(
|
276
|
-
}
|
277
|
-
|
278
|
-
|
279
|
-
export { KHR_animation_pointer };
|
280
|
-
GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_animation_pointer(loader); });
|
264
|
+
throw new Error(`${context} invalid pointer. ${pointer}`);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
GLTFLoader.RegisterExtension(NAME, (loader) => new KHR_animation_pointer(loader));
|
281
268
|
//# sourceMappingURL=KHR_animation_pointer.js.map
|
@@ -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,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AM,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,UAAG,OAAO,+BAAqB,OAAO,CAAE,CAAC,CAAC;IAC9D,CAAC;IACL,4BAAC;AAAD,CAAC,AAvSD,IAuSC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,qBAAqB,CAAC,MAAM,CAAC,EAAjC,CAAiC,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 * @param loader\r\n * @hidden\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 /** @hidden */\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 * @param property\r\n * @hidden\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 * @hidden 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 * @return \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,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAKhE,OAAO,EAAE,yBAAyB,EAAE,mDAAqC;AACzE,OAAO,EAAE,uBAAuB,EA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AG,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 * @param loader\r\n * @hidden\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 /** @hidden */\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 * @param property\r\n * @hidden\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 * @hidden 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 * @return \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"]}
|