@needle-tools/three-animation-pointer 1.0.2-next.a516fc5 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,40 +13,40 @@ const f = {
|
|
|
13
13
|
};
|
|
14
14
|
class j {
|
|
15
15
|
/** @type {import("three/examples/jsm/loaders/GLTFLoader").GLTFParser} */
|
|
16
|
-
constructor(
|
|
17
|
-
this.name = R, this.parser =
|
|
16
|
+
constructor(r) {
|
|
17
|
+
this.name = R, this.parser = r, this.animationPointerResolver = null;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* @param {import("..").AnimationPointerResolver | null} animationPointerResolver
|
|
21
21
|
*/
|
|
22
|
-
setAnimationPointerResolver(
|
|
23
|
-
return this.animationPointerResolver =
|
|
22
|
+
setAnimationPointerResolver(r) {
|
|
23
|
+
return this.animationPointerResolver = r, this;
|
|
24
24
|
}
|
|
25
25
|
/* DUPLICATE of functionality in GLTFLoader */
|
|
26
|
-
loadAnimationTargetFromChannel(
|
|
27
|
-
const
|
|
28
|
-
return this.parser.getDependency("node",
|
|
26
|
+
loadAnimationTargetFromChannel(r) {
|
|
27
|
+
const s = r.target, a = s.node !== void 0 ? s.node : s.id;
|
|
28
|
+
return this.parser.getDependency("node", a);
|
|
29
29
|
}
|
|
30
|
-
loadAnimationTargetFromChannelWithAnimationPointer(
|
|
30
|
+
loadAnimationTargetFromChannelWithAnimationPointer(r) {
|
|
31
31
|
var c;
|
|
32
32
|
B();
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
let e,
|
|
36
|
-
if (
|
|
37
|
-
const m =
|
|
33
|
+
const s = r.target, a = s.extensions && s.extensions[R] && s.path && s.path === "pointer";
|
|
34
|
+
if (!a) return null;
|
|
35
|
+
let e, t = f.node, n;
|
|
36
|
+
if (a) {
|
|
37
|
+
const m = s.extensions[R];
|
|
38
38
|
let o = m.pointer;
|
|
39
39
|
if (!o) {
|
|
40
|
-
console.warn("Invalid path", m,
|
|
40
|
+
console.warn("Invalid path", m, s);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
if (o.startsWith("/materials/") ?
|
|
44
|
-
console.warn("Failed resolving animation node id: " +
|
|
43
|
+
if (o.startsWith("/materials/") ? t = f.material : o.startsWith("/extensions/KHR_lights_punctual/lights/") ? t = f.light : o.startsWith("/cameras/") && (t = f.camera), n = this._tryResolveTargetId(o, t), n === null || isNaN(n)) {
|
|
44
|
+
console.warn("Failed resolving animation node id: " + n, o);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
switch (
|
|
47
|
+
switch (t) {
|
|
48
48
|
case f.material:
|
|
49
|
-
const x = ("/materials/" +
|
|
49
|
+
const x = ("/materials/" + n.toString() + "/").length, h = o.substring(0, x);
|
|
50
50
|
switch (e = o.substring(x), e) {
|
|
51
51
|
case "pbrMetallicRoughness/baseColorFactor":
|
|
52
52
|
e = "color";
|
|
@@ -133,7 +133,7 @@ class j {
|
|
|
133
133
|
o = h + e;
|
|
134
134
|
break;
|
|
135
135
|
case f.node:
|
|
136
|
-
const u = ("/nodes/" +
|
|
136
|
+
const u = ("/nodes/" + n.toString() + "/").length, l = o.substring(0, u);
|
|
137
137
|
switch (e = o.substring(u), e) {
|
|
138
138
|
case "translation":
|
|
139
139
|
e = "position";
|
|
@@ -151,7 +151,7 @@ class j {
|
|
|
151
151
|
o = l + e;
|
|
152
152
|
break;
|
|
153
153
|
case f.light:
|
|
154
|
-
const p = ("/extensions/KHR_lights_punctual/lights/" +
|
|
154
|
+
const p = ("/extensions/KHR_lights_punctual/lights/" + n.toString() + "/").length;
|
|
155
155
|
switch (e = o.substring(p), e) {
|
|
156
156
|
case "color":
|
|
157
157
|
break;
|
|
@@ -167,10 +167,10 @@ class j {
|
|
|
167
167
|
e = "distance";
|
|
168
168
|
break;
|
|
169
169
|
}
|
|
170
|
-
o = "/lights/" +
|
|
170
|
+
o = "/lights/" + n.toString() + "/" + e;
|
|
171
171
|
break;
|
|
172
172
|
case f.camera:
|
|
173
|
-
const g = ("/cameras/" +
|
|
173
|
+
const g = ("/cameras/" + n.toString() + "/").length, b = o.substring(0, g);
|
|
174
174
|
switch (e = o.substring(g), e) {
|
|
175
175
|
case "perspective/yfov":
|
|
176
176
|
e = "fov";
|
|
@@ -196,25 +196,25 @@ class j {
|
|
|
196
196
|
o = b + e;
|
|
197
197
|
break;
|
|
198
198
|
}
|
|
199
|
-
(c = this.animationPointerResolver) != null && c.resolvePath && (o = this.animationPointerResolver.resolvePath(o)),
|
|
199
|
+
(c = this.animationPointerResolver) != null && c.resolvePath && (o = this.animationPointerResolver.resolvePath(o)), s.extensions[R].pointer = o;
|
|
200
200
|
}
|
|
201
|
-
if (
|
|
202
|
-
console.warn("Failed resolving animation node id: " +
|
|
201
|
+
if (n == null || isNaN(n)) {
|
|
202
|
+
console.warn("Failed resolving animation node id: " + n, s);
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
205
|
let i;
|
|
206
|
-
return
|
|
206
|
+
return t === f.node ? i = this.parser.getDependency("node", n) : t === f.material ? i = this.parser.getDependency("material", n) : t === f.light ? i = this.parser.getDependency("light", n) : t === f.camera ? i = this.parser.getDependency("camera", n) : console.error("Unhandled type", t), i;
|
|
207
207
|
}
|
|
208
|
-
createAnimationTracksWithAnimationPointer(
|
|
209
|
-
if (!(
|
|
210
|
-
let i =
|
|
208
|
+
createAnimationTracksWithAnimationPointer(r, s, a, e, t) {
|
|
209
|
+
if (!(t.extensions && t.extensions[R] && t.path && t.path === "pointer")) return null;
|
|
210
|
+
let i = t.extensions[R].pointer;
|
|
211
211
|
if (!i) return null;
|
|
212
212
|
const c = [];
|
|
213
213
|
i = i.replaceAll("/", ".");
|
|
214
214
|
const m = i.split(".");
|
|
215
|
-
var x =
|
|
216
|
-
if (m[2] = x, m[3] === "morphTargetInfluences" &&
|
|
217
|
-
for (const u of
|
|
215
|
+
var x = r.name !== void 0 && r.name !== null ? r.name : r.uuid;
|
|
216
|
+
if (m[2] = x, m[3] === "morphTargetInfluences" && r.type === "Group") {
|
|
217
|
+
for (const u of r.children)
|
|
218
218
|
u instanceof S && u.morphTargetInfluences && (m[3] = u.name, m[4] = "morphTargetInfluences", h(this.parser));
|
|
219
219
|
return c;
|
|
220
220
|
}
|
|
@@ -222,7 +222,7 @@ class j {
|
|
|
222
222
|
function h(u) {
|
|
223
223
|
i = m.join(".");
|
|
224
224
|
let l;
|
|
225
|
-
switch (
|
|
225
|
+
switch (a.itemSize) {
|
|
226
226
|
case 1:
|
|
227
227
|
l = O;
|
|
228
228
|
break;
|
|
@@ -235,25 +235,25 @@ class j {
|
|
|
235
235
|
break;
|
|
236
236
|
}
|
|
237
237
|
if (!l) {
|
|
238
|
-
console.warn("Unsupported output accessor format",
|
|
238
|
+
console.warn("Unsupported output accessor format", a);
|
|
239
239
|
return;
|
|
240
240
|
}
|
|
241
241
|
const p = e.interpolation !== void 0 ? U[e.interpolation] : F;
|
|
242
|
-
let g = u._getArrayFromAccessor(
|
|
242
|
+
let g = u._getArrayFromAccessor(a);
|
|
243
243
|
i.endsWith(".fov") && (g = g.map((k) => k / Math.PI * 180));
|
|
244
244
|
const b = new l(
|
|
245
245
|
i,
|
|
246
|
-
|
|
246
|
+
s.array,
|
|
247
247
|
g,
|
|
248
248
|
p
|
|
249
249
|
);
|
|
250
|
-
if (p === "CUBICSPLINE" && u._createCubicSplineTrackInterpolant(b), c.push(b), i &&
|
|
250
|
+
if (p === "CUBICSPLINE" && u._createCubicSplineTrackInterpolant(b), c.push(b), i && a.itemSize === 4 && i.startsWith(".materials.") && i.endsWith(".color")) {
|
|
251
251
|
const k = new Float32Array(g.length / 4);
|
|
252
252
|
for (let T = 0, _ = g.length / 4; T < _; T += 1)
|
|
253
253
|
k[T] = g[T * 4 + 3];
|
|
254
254
|
const d = new l(
|
|
255
255
|
i.replace(".color", ".opacity"),
|
|
256
|
-
|
|
256
|
+
s.array,
|
|
257
257
|
k,
|
|
258
258
|
p
|
|
259
259
|
);
|
|
@@ -262,9 +262,9 @@ class j {
|
|
|
262
262
|
}
|
|
263
263
|
return c;
|
|
264
264
|
}
|
|
265
|
-
_tryResolveTargetId(
|
|
266
|
-
let
|
|
267
|
-
return
|
|
265
|
+
_tryResolveTargetId(r, s) {
|
|
266
|
+
let a = "";
|
|
267
|
+
return s === "node" ? a = r.substring(7) : s === "material" ? a = r.substring(11) : s === "light" ? a = r.substring(39) : s === "camera" && (a = r.substring(9)), a = a.substring(0, a.indexOf("/")), Number.parseInt(a);
|
|
268
268
|
}
|
|
269
269
|
/* MOSTLY DUPLICATE of GLTFLoader.loadAnimation, but also tries to resolve KHR_animation_pointer. */
|
|
270
270
|
/**
|
|
@@ -272,12 +272,12 @@ class j {
|
|
|
272
272
|
* @param {number} animationIndex
|
|
273
273
|
* @return {Promise<AnimationClip>}
|
|
274
274
|
*/
|
|
275
|
-
loadAnimation(
|
|
276
|
-
const
|
|
277
|
-
for (let h = 0, u =
|
|
278
|
-
const l =
|
|
279
|
-
let d =
|
|
280
|
-
d || (d =
|
|
275
|
+
loadAnimation(r) {
|
|
276
|
+
const s = this, a = this.parser.json, e = this.parser, t = a.animations[r], n = t.name ? t.name : "animation_" + r, i = [], c = [], m = [], o = [], x = [];
|
|
277
|
+
for (let h = 0, u = t.channels.length; h < u; h++) {
|
|
278
|
+
const l = t.channels[h], p = t.samplers[l.sampler], g = l.target, b = t.parameters !== void 0 ? t.parameters[p.input] : p.input, k = t.parameters !== void 0 ? t.parameters[p.output] : p.output;
|
|
279
|
+
let d = s.loadAnimationTargetFromChannelWithAnimationPointer(l);
|
|
280
|
+
d || (d = s.loadAnimationTargetFromChannel(l)), i.push(d), c.push(e.getDependency("accessor", b)), m.push(e.getDependency("accessor", k)), o.push(p), x.push(g);
|
|
281
281
|
}
|
|
282
282
|
return Promise.all([
|
|
283
283
|
Promise.all(i),
|
|
@@ -291,12 +291,12 @@ class j {
|
|
|
291
291
|
const _ = u[d], v = l[d], A = p[d], N = g[d], K = b[d];
|
|
292
292
|
if (_ === void 0) continue;
|
|
293
293
|
_.updateMatrix && (_.updateMatrix(), _.matrixAutoUpdate = !0);
|
|
294
|
-
let y =
|
|
294
|
+
let y = s.createAnimationTracksWithAnimationPointer(_, v, A, N, K);
|
|
295
295
|
if (y || (y = e._createAnimationTracks(_, v, A, N, K)), y)
|
|
296
296
|
for (let P = 0; P < y.length; P++)
|
|
297
297
|
k.push(y[P]);
|
|
298
298
|
}
|
|
299
|
-
return new W(
|
|
299
|
+
return new W(n, void 0, k);
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -305,37 +305,36 @@ function B() {
|
|
|
305
305
|
if (H) return;
|
|
306
306
|
H = !0;
|
|
307
307
|
const I = z || (z = C.findNode);
|
|
308
|
-
C.findNode = function(
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const r = t.split(".");
|
|
308
|
+
C.findNode = function(r, s) {
|
|
309
|
+
if (s.startsWith(".materials.")) {
|
|
310
|
+
const a = s.substring(11).substring(s.indexOf(".")), e = a.indexOf("."), t = e < 0 ? a : a.substring(0, e);
|
|
311
|
+
let n = null;
|
|
312
|
+
return r.traverse((i) => {
|
|
313
|
+
n !== null || i.type !== "Mesh" && i.type !== "SkinnedMesh" || i.material && (i.material.uuid === t || i.material.name === t) && (n = i.material, n !== null && (a.endsWith(".map") ? n = n.map : a.endsWith(".emissiveMap") && (n = n.emissiveMap)));
|
|
314
|
+
}), n;
|
|
315
|
+
} else if (s.startsWith(".nodes.") || s.startsWith(".lights.") || s.startsWith(".cameras.")) {
|
|
316
|
+
const a = s.split(".");
|
|
318
317
|
let e;
|
|
319
|
-
for (let
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
e =
|
|
323
|
-
else if (e && e[
|
|
324
|
-
const c = Number.parseInt(
|
|
325
|
-
let m =
|
|
318
|
+
for (let t = 1; t < a.length; t++) {
|
|
319
|
+
const n = a[t];
|
|
320
|
+
if (n.length == 36)
|
|
321
|
+
e = r.getObjectByProperty("uuid", n);
|
|
322
|
+
else if (e && e[n]) {
|
|
323
|
+
const c = Number.parseInt(n);
|
|
324
|
+
let m = n;
|
|
326
325
|
c >= 0 && (m = c), e = e[m];
|
|
327
326
|
} else {
|
|
328
|
-
const c =
|
|
327
|
+
const c = r.getObjectByName(n);
|
|
329
328
|
c && (e = c);
|
|
330
329
|
}
|
|
331
330
|
}
|
|
332
331
|
if (!e) {
|
|
333
|
-
const
|
|
334
|
-
return
|
|
332
|
+
const t = I(r, a[2]);
|
|
333
|
+
return t || console.warn(R + ": Property binding not found", s, r, r.name, a), t;
|
|
335
334
|
}
|
|
336
335
|
return e;
|
|
337
336
|
}
|
|
338
|
-
return I(
|
|
337
|
+
return I(r, s);
|
|
339
338
|
};
|
|
340
339
|
}
|
|
341
340
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/three-animation-pointer",
|
|
3
|
-
"version": "1.0.2
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "KHR_animation_pointer support for three.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/three-animation-pointer.js",
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"registry": "https://registry.npmjs.org/",
|
|
47
47
|
"access": "public"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
@@ -657,10 +657,6 @@ function _ensurePropertyBindingPatch() {
|
|
|
657
657
|
// "path" is the animated property path, just with translated material names.
|
|
658
658
|
PropertyBinding.findNode = function (node, path) {
|
|
659
659
|
|
|
660
|
-
// if the binding is empty fallback to original
|
|
661
|
-
if (!path) return findNode(node, path);
|
|
662
|
-
|
|
663
|
-
|
|
664
660
|
if (path.startsWith('.materials.')) {
|
|
665
661
|
|
|
666
662
|
if (_animationPointerDebug) console.log('FIND', path);
|