@vizij/render 0.0.3 → 0.0.5
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.
- package/README.md +3 -2
- package/dist/index.d.mts +48 -12
- package/dist/index.d.ts +48 -12
- package/dist/index.js +624 -434
- package/dist/index.mjs +493 -300
- package/package.json +2 -3
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import { memo } from "react";
|
|
3
|
-
import { useShallow } from "zustand/react/shallow";
|
|
4
|
-
import { clsx } from "clsx";
|
|
1
|
+
// src/vizij.tsx
|
|
5
2
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
Suspense,
|
|
4
|
+
memo as memo6,
|
|
5
|
+
useContext as useContext3,
|
|
6
|
+
useEffect as useEffect6
|
|
7
|
+
} from "react";
|
|
8
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
9
|
+
import {
|
|
10
|
+
Object3D as Object3D4,
|
|
11
|
+
SRGBColorSpace,
|
|
12
|
+
NoToneMapping
|
|
13
|
+
} from "three";
|
|
14
|
+
import { Canvas, useThree } from "@react-three/fiber";
|
|
15
|
+
import { Line as Line3, OrthographicCamera, Text } from "@react-three/drei";
|
|
16
|
+
import { useShallow as useShallow6 } from "zustand/react/shallow";
|
|
17
|
+
|
|
18
|
+
// src/renderables/renderable.tsx
|
|
19
|
+
import { memo as memo5, useMemo as useMemo5 } from "react";
|
|
20
|
+
import { useShallow as useShallow5 } from "zustand/react/shallow";
|
|
9
21
|
|
|
10
22
|
// src/hooks/use-vizij-store.ts
|
|
11
23
|
import { useContext } from "react";
|
|
@@ -22,218 +34,16 @@ function useVizijStore(selector) {
|
|
|
22
34
|
return useStore(store, selector);
|
|
23
35
|
}
|
|
24
36
|
|
|
25
|
-
// src/controllers/controller.tsx
|
|
26
|
-
import { jsx } from "react/jsx-runtime";
|
|
27
|
-
function InnerController({
|
|
28
|
-
animatableId,
|
|
29
|
-
namespace,
|
|
30
|
-
subfield,
|
|
31
|
-
className
|
|
32
|
-
}) {
|
|
33
|
-
const setValue = useVizijStore(useShallow((state) => state.setValue));
|
|
34
|
-
const animatable = useVizijStore(
|
|
35
|
-
useShallow((state) => state.animatables[animatableId])
|
|
36
|
-
);
|
|
37
|
-
const lookupId = getLookup(namespace ?? "default", animatableId);
|
|
38
|
-
const rawValue = useVizijStore(
|
|
39
|
-
useShallow((state) => state.values.get(lookupId))
|
|
40
|
-
);
|
|
41
|
-
if (animatable.type === "number") {
|
|
42
|
-
return /* @__PURE__ */ jsx("div", { className: clsx("flex flex-col w-full", className), children: /* @__PURE__ */ jsx(
|
|
43
|
-
SliderNumberField,
|
|
44
|
-
{
|
|
45
|
-
size: Size.Sm,
|
|
46
|
-
value: rawValue ?? animatable.default,
|
|
47
|
-
onChange: (v) => {
|
|
48
|
-
setValue(animatableId, namespace ?? "default", v);
|
|
49
|
-
},
|
|
50
|
-
min: animatable.constraints.min,
|
|
51
|
-
max: animatable.constraints.max
|
|
52
|
-
}
|
|
53
|
-
) });
|
|
54
|
-
} else if (animatable.type === "vector3" && !subfield) {
|
|
55
|
-
return /* @__PURE__ */ jsx("div", { className: clsx("flex flex-col gap-2", className), children: ["x", "y", "z"].map((axis) => {
|
|
56
|
-
return /* @__PURE__ */ jsx(
|
|
57
|
-
InnerController,
|
|
58
|
-
{
|
|
59
|
-
animatableId,
|
|
60
|
-
namespace,
|
|
61
|
-
subfield: axis
|
|
62
|
-
},
|
|
63
|
-
axis
|
|
64
|
-
);
|
|
65
|
-
}) });
|
|
66
|
-
} else if (animatable.type === "vector2" && !subfield) {
|
|
67
|
-
return /* @__PURE__ */ jsx("div", { className: clsx("flex flex-col gap-2", className), children: ["x", "y"].map((axis) => {
|
|
68
|
-
return /* @__PURE__ */ jsx(
|
|
69
|
-
InnerController,
|
|
70
|
-
{
|
|
71
|
-
animatableId,
|
|
72
|
-
namespace,
|
|
73
|
-
subfield: axis
|
|
74
|
-
},
|
|
75
|
-
axis
|
|
76
|
-
);
|
|
77
|
-
}) });
|
|
78
|
-
} else if (animatable.type === "euler" && !subfield) {
|
|
79
|
-
return /* @__PURE__ */ jsx("div", { className: clsx("flex flex-col gap-2", className), children: ["x", "y", "z"].map((axis) => {
|
|
80
|
-
return /* @__PURE__ */ jsx(
|
|
81
|
-
InnerController,
|
|
82
|
-
{
|
|
83
|
-
animatableId,
|
|
84
|
-
namespace,
|
|
85
|
-
subfield: axis
|
|
86
|
-
},
|
|
87
|
-
axis
|
|
88
|
-
);
|
|
89
|
-
}) });
|
|
90
|
-
} else if (animatable.type === "rgb" && !subfield) {
|
|
91
|
-
return /* @__PURE__ */ jsx("div", { className: clsx("flex flex-col gap-2", className), children: /* @__PURE__ */ jsx(
|
|
92
|
-
ColorPickerPopover,
|
|
93
|
-
{
|
|
94
|
-
value: rawValue ? convertRGBRange(rawValue, "255") : convertRGBRange(animatable.default, "255"),
|
|
95
|
-
onChange: (v) => {
|
|
96
|
-
setValue(
|
|
97
|
-
animatableId,
|
|
98
|
-
namespace ?? "default",
|
|
99
|
-
convertRGBRange(v, "1")
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
) });
|
|
104
|
-
} else if (animatable.type === "vector3" && subfield && ["x", "y", "z"].includes(subfield)) {
|
|
105
|
-
const axis = subfield;
|
|
106
|
-
const currentVec = rawValue ?? animatable.default;
|
|
107
|
-
return /* @__PURE__ */ jsx(
|
|
108
|
-
SliderNumberField,
|
|
109
|
-
{
|
|
110
|
-
label: axis,
|
|
111
|
-
size: Size.Sm,
|
|
112
|
-
value: currentVec[axis],
|
|
113
|
-
onChange: (v) => {
|
|
114
|
-
setValue(animatableId, namespace ?? "default", {
|
|
115
|
-
...currentVec,
|
|
116
|
-
[axis]: v
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
120
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
} else if (animatable.type === "vector2" && subfield && ["x", "y"].includes(subfield)) {
|
|
124
|
-
const axis = subfield;
|
|
125
|
-
const currentVec = rawValue ?? animatable.default;
|
|
126
|
-
return /* @__PURE__ */ jsx(
|
|
127
|
-
SliderNumberField,
|
|
128
|
-
{
|
|
129
|
-
label: axis,
|
|
130
|
-
size: Size.Sm,
|
|
131
|
-
value: currentVec[axis],
|
|
132
|
-
onChange: (v) => {
|
|
133
|
-
setValue(animatableId, namespace ?? "default", {
|
|
134
|
-
...currentVec,
|
|
135
|
-
[axis]: v
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
139
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
} else if (animatable.type === "euler" && subfield && ["x", "y", "z"].includes(subfield)) {
|
|
143
|
-
const axis = subfield;
|
|
144
|
-
const currentVec = rawValue ?? animatable.default;
|
|
145
|
-
return /* @__PURE__ */ jsx(
|
|
146
|
-
SliderNumberField,
|
|
147
|
-
{
|
|
148
|
-
label: axis,
|
|
149
|
-
size: Size.Sm,
|
|
150
|
-
value: currentVec[axis],
|
|
151
|
-
onChange: (v) => {
|
|
152
|
-
setValue(animatableId, namespace ?? "default", {
|
|
153
|
-
...currentVec,
|
|
154
|
-
[axis]: v
|
|
155
|
-
});
|
|
156
|
-
},
|
|
157
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
158
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
} else if (animatable.type === "rgb" && subfield && ["r", "g", "b"].includes(subfield)) {
|
|
162
|
-
const axis = subfield;
|
|
163
|
-
const currentVec = rawValue ?? animatable.default;
|
|
164
|
-
return /* @__PURE__ */ jsx(
|
|
165
|
-
SliderNumberField,
|
|
166
|
-
{
|
|
167
|
-
label: axis,
|
|
168
|
-
size: Size.Sm,
|
|
169
|
-
value: currentVec[axis],
|
|
170
|
-
strictText: true,
|
|
171
|
-
strictSlider: true,
|
|
172
|
-
onChange: (v) => {
|
|
173
|
-
setValue(animatableId, namespace ?? "default", {
|
|
174
|
-
...currentVec,
|
|
175
|
-
[axis]: v
|
|
176
|
-
});
|
|
177
|
-
},
|
|
178
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
179
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
180
|
-
}
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
var Controller = memo(InnerController);
|
|
185
|
-
var vectorIndexLookup = {
|
|
186
|
-
x: 0,
|
|
187
|
-
y: 1,
|
|
188
|
-
z: 2,
|
|
189
|
-
r: 0,
|
|
190
|
-
g: 1,
|
|
191
|
-
b: 2
|
|
192
|
-
};
|
|
193
|
-
var convertRGBRange = (color, to) => {
|
|
194
|
-
if (to === "255") {
|
|
195
|
-
return {
|
|
196
|
-
r: color.r * 255,
|
|
197
|
-
g: color.g * 255,
|
|
198
|
-
b: color.b * 255
|
|
199
|
-
};
|
|
200
|
-
} else if (to === "1") {
|
|
201
|
-
return {
|
|
202
|
-
r: color.r / 255,
|
|
203
|
-
g: color.g / 255,
|
|
204
|
-
b: color.b / 255
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
return color;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
// src/vizij.tsx
|
|
211
|
-
import {
|
|
212
|
-
Suspense,
|
|
213
|
-
memo as memo7,
|
|
214
|
-
useContext as useContext3,
|
|
215
|
-
useEffect as useEffect6
|
|
216
|
-
} from "react";
|
|
217
|
-
import { ErrorBoundary } from "react-error-boundary";
|
|
218
|
-
import { Object3D as Object3D4 } from "three";
|
|
219
|
-
import { Canvas, useThree } from "@react-three/fiber";
|
|
220
|
-
import { Line as Line3, OrthographicCamera, Text } from "@react-three/drei";
|
|
221
|
-
import { useShallow as useShallow7 } from "zustand/react/shallow";
|
|
222
|
-
|
|
223
|
-
// src/renderables/renderable.tsx
|
|
224
|
-
import { memo as memo6, useMemo as useMemo5 } from "react";
|
|
225
|
-
import { useShallow as useShallow6 } from "zustand/react/shallow";
|
|
226
|
-
|
|
227
37
|
// src/renderables/group.tsx
|
|
228
38
|
import {
|
|
229
|
-
memo
|
|
39
|
+
memo,
|
|
230
40
|
useCallback,
|
|
231
41
|
useEffect as useEffect2,
|
|
232
42
|
useRef,
|
|
233
43
|
useMemo
|
|
234
44
|
} from "react";
|
|
235
45
|
import * as THREE from "three";
|
|
236
|
-
import { useShallow
|
|
46
|
+
import { useShallow } from "zustand/react/shallow";
|
|
237
47
|
import {
|
|
238
48
|
instanceOfRawEuler,
|
|
239
49
|
instanceOfRawNumber,
|
|
@@ -244,7 +54,7 @@ import {
|
|
|
244
54
|
// src/hooks/use-features.ts
|
|
245
55
|
import { useEffect, useContext as useContext2 } from "react";
|
|
246
56
|
import { shallow } from "zustand/shallow";
|
|
247
|
-
import { getLookup
|
|
57
|
+
import { getLookup } from "@vizij/utils";
|
|
248
58
|
function useFeatures(namespace, features, callbacks, debugInfo) {
|
|
249
59
|
const store = useContext2(VizijContext);
|
|
250
60
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
@@ -274,7 +84,7 @@ function useFeatures(namespace, features, callbacks, debugInfo) {
|
|
|
274
84
|
}
|
|
275
85
|
};
|
|
276
86
|
const defaultValue = animatableValueInfo.default;
|
|
277
|
-
const lookupKey =
|
|
87
|
+
const lookupKey = getLookup(namespace, animatableValueInfo.id);
|
|
278
88
|
const unsubscribe = store.subscribe(
|
|
279
89
|
(state) => state.values.get(lookupKey) ?? defaultValue,
|
|
280
90
|
cb,
|
|
@@ -321,7 +131,7 @@ function createStoredRenderable(data, animatableValues) {
|
|
|
321
131
|
}
|
|
322
132
|
|
|
323
133
|
// src/renderables/group.tsx
|
|
324
|
-
import { jsx
|
|
134
|
+
import { jsx } from "react/jsx-runtime";
|
|
325
135
|
THREE.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
326
136
|
function InnerRenderedGroup({
|
|
327
137
|
id,
|
|
@@ -329,11 +139,11 @@ function InnerRenderedGroup({
|
|
|
329
139
|
chain
|
|
330
140
|
}) {
|
|
331
141
|
const ref = useRef();
|
|
332
|
-
const group = useVizijStore(
|
|
142
|
+
const group = useVizijStore(useShallow((state) => state.world[id]));
|
|
333
143
|
const refIsNull = !group.refs[namespace]?.current;
|
|
334
|
-
const animatables = useVizijStore(
|
|
144
|
+
const animatables = useVizijStore(useShallow((state) => state.animatables));
|
|
335
145
|
const setHoveredElement = useVizijStore(
|
|
336
|
-
|
|
146
|
+
useShallow((state) => state.setHoveredElement)
|
|
337
147
|
);
|
|
338
148
|
const animatableValues = useMemo(() => {
|
|
339
149
|
const av = {};
|
|
@@ -386,7 +196,7 @@ function InnerRenderedGroup({
|
|
|
386
196
|
}
|
|
387
197
|
});
|
|
388
198
|
const setReference = useVizijStore(
|
|
389
|
-
|
|
199
|
+
useShallow((state) => state.setReference)
|
|
390
200
|
);
|
|
391
201
|
useEffect2(() => {
|
|
392
202
|
if (ref.current && refIsNull) {
|
|
@@ -416,7 +226,7 @@ function InnerRenderedGroup({
|
|
|
416
226
|
},
|
|
417
227
|
[setHoveredElement]
|
|
418
228
|
);
|
|
419
|
-
return /* @__PURE__ */
|
|
229
|
+
return /* @__PURE__ */ jsx(
|
|
420
230
|
"group",
|
|
421
231
|
{
|
|
422
232
|
ref,
|
|
@@ -424,7 +234,7 @@ function InnerRenderedGroup({
|
|
|
424
234
|
userData,
|
|
425
235
|
onPointerOver: handlePointerOver,
|
|
426
236
|
onPointerOut: handlePointerOut,
|
|
427
|
-
children: group.children.map((child) => /* @__PURE__ */
|
|
237
|
+
children: group.children.map((child) => /* @__PURE__ */ jsx(
|
|
428
238
|
Renderable,
|
|
429
239
|
{
|
|
430
240
|
id: child,
|
|
@@ -436,17 +246,17 @@ function InnerRenderedGroup({
|
|
|
436
246
|
}
|
|
437
247
|
);
|
|
438
248
|
}
|
|
439
|
-
var RenderedGroup =
|
|
249
|
+
var RenderedGroup = memo(InnerRenderedGroup);
|
|
440
250
|
|
|
441
251
|
// src/renderables/ellipse.tsx
|
|
442
252
|
import {
|
|
443
|
-
memo as
|
|
253
|
+
memo as memo2,
|
|
444
254
|
useCallback as useCallback2,
|
|
445
255
|
useEffect as useEffect3,
|
|
446
256
|
useRef as useRef2,
|
|
447
257
|
useMemo as useMemo2
|
|
448
258
|
} from "react";
|
|
449
|
-
import { useShallow as
|
|
259
|
+
import { useShallow as useShallow2 } from "zustand/react/shallow";
|
|
450
260
|
import {
|
|
451
261
|
instanceOfRawNumber as instanceOfRawNumber2,
|
|
452
262
|
instanceOfRawVector2 as instanceOfRawVector22,
|
|
@@ -456,7 +266,7 @@ import {
|
|
|
456
266
|
instanceOfRawHSL
|
|
457
267
|
} from "@vizij/utils";
|
|
458
268
|
import { Circle, Line } from "@react-three/drei";
|
|
459
|
-
import { Fragment, jsx as
|
|
269
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
460
270
|
function InnerRenderedEllipse({
|
|
461
271
|
id,
|
|
462
272
|
namespace,
|
|
@@ -468,16 +278,16 @@ function InnerRenderedEllipse({
|
|
|
468
278
|
const strokeOffsetRef = useRef2(0);
|
|
469
279
|
const strokeWidthRef = useRef2(0);
|
|
470
280
|
const onElementClick = useVizijStore(
|
|
471
|
-
|
|
281
|
+
useShallow2((state) => state.onElementClick)
|
|
472
282
|
);
|
|
473
283
|
const setHoveredElement = useVizijStore(
|
|
474
|
-
|
|
284
|
+
useShallow2((state) => state.setHoveredElement)
|
|
475
285
|
);
|
|
476
286
|
const ellipse = useVizijStore(
|
|
477
|
-
|
|
287
|
+
useShallow2((state) => state.world[id])
|
|
478
288
|
);
|
|
479
289
|
const refIsNull = !ellipse.refs[namespace]?.current;
|
|
480
|
-
const animatables = useVizijStore(
|
|
290
|
+
const animatables = useVizijStore(useShallow2((state) => state.animatables));
|
|
481
291
|
const animatableValues = useMemo2(() => {
|
|
482
292
|
const av = {};
|
|
483
293
|
Object.values(ellipse.features).forEach((feat) => {
|
|
@@ -664,7 +474,7 @@ function InnerRenderedEllipse({
|
|
|
664
474
|
}
|
|
665
475
|
});
|
|
666
476
|
const setReference = useVizijStore(
|
|
667
|
-
|
|
477
|
+
useShallow2((state) => state.setReference)
|
|
668
478
|
);
|
|
669
479
|
const points = useMemo2(() => {
|
|
670
480
|
const n = 600;
|
|
@@ -697,7 +507,7 @@ function InnerRenderedEllipse({
|
|
|
697
507
|
[setHoveredElement]
|
|
698
508
|
);
|
|
699
509
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
700
|
-
/* @__PURE__ */
|
|
510
|
+
/* @__PURE__ */ jsx2(
|
|
701
511
|
Circle,
|
|
702
512
|
{
|
|
703
513
|
ref: ellipseRef,
|
|
@@ -708,10 +518,10 @@ function InnerRenderedEllipse({
|
|
|
708
518
|
onClick: (e) => {
|
|
709
519
|
onElementClick({ id, type: "ellipse", namespace }, [...chain, id], e);
|
|
710
520
|
},
|
|
711
|
-
children: /* @__PURE__ */
|
|
521
|
+
children: /* @__PURE__ */ jsx2("meshStandardMaterial", { attach: "material", ref: materialRef })
|
|
712
522
|
}
|
|
713
523
|
),
|
|
714
|
-
showLine(ellipse) && /* @__PURE__ */
|
|
524
|
+
showLine(ellipse) && /* @__PURE__ */ jsx2(
|
|
715
525
|
Line,
|
|
716
526
|
{
|
|
717
527
|
ref: lineRef,
|
|
@@ -722,7 +532,7 @@ function InnerRenderedEllipse({
|
|
|
722
532
|
)
|
|
723
533
|
] });
|
|
724
534
|
}
|
|
725
|
-
var RenderedEllipse =
|
|
535
|
+
var RenderedEllipse = memo2(InnerRenderedEllipse);
|
|
726
536
|
var showLine = (ellipse) => {
|
|
727
537
|
if ("strokeOpacity" in ellipse.features) {
|
|
728
538
|
return true;
|
|
@@ -738,13 +548,13 @@ var showLine = (ellipse) => {
|
|
|
738
548
|
|
|
739
549
|
// src/renderables/rectangle.tsx
|
|
740
550
|
import {
|
|
741
|
-
memo as
|
|
551
|
+
memo as memo3,
|
|
742
552
|
useCallback as useCallback3,
|
|
743
553
|
useEffect as useEffect4,
|
|
744
554
|
useRef as useRef3,
|
|
745
555
|
useMemo as useMemo3
|
|
746
556
|
} from "react";
|
|
747
|
-
import { useShallow as
|
|
557
|
+
import { useShallow as useShallow3 } from "zustand/react/shallow";
|
|
748
558
|
import {
|
|
749
559
|
instanceOfRawNumber as instanceOfRawNumber3,
|
|
750
560
|
instanceOfRawVector2 as instanceOfRawVector23,
|
|
@@ -754,7 +564,7 @@ import {
|
|
|
754
564
|
instanceOfRawHSL as instanceOfRawHSL2
|
|
755
565
|
} from "@vizij/utils";
|
|
756
566
|
import { Plane, Line as Line2 } from "@react-three/drei";
|
|
757
|
-
import { Fragment as Fragment2, jsx as
|
|
567
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
758
568
|
function InnerRenderedRectangle({
|
|
759
569
|
id,
|
|
760
570
|
namespace,
|
|
@@ -766,16 +576,16 @@ function InnerRenderedRectangle({
|
|
|
766
576
|
const strokeOffsetRef = useRef3(0);
|
|
767
577
|
const strokeWidthRef = useRef3(0);
|
|
768
578
|
const onElementClick = useVizijStore(
|
|
769
|
-
|
|
579
|
+
useShallow3((state) => state.onElementClick)
|
|
770
580
|
);
|
|
771
581
|
const setHoveredElement = useVizijStore(
|
|
772
|
-
|
|
582
|
+
useShallow3((state) => state.setHoveredElement)
|
|
773
583
|
);
|
|
774
584
|
const rectangle = useVizijStore(
|
|
775
|
-
|
|
585
|
+
useShallow3((state) => state.world[id])
|
|
776
586
|
);
|
|
777
587
|
const refIsNull = !rectangle.refs[namespace]?.current;
|
|
778
|
-
const animatables = useVizijStore(
|
|
588
|
+
const animatables = useVizijStore(useShallow3((state) => state.animatables));
|
|
779
589
|
const animatableValues = useMemo3(() => {
|
|
780
590
|
const av = {};
|
|
781
591
|
Object.values(rectangle.features).forEach((feat) => {
|
|
@@ -962,7 +772,7 @@ function InnerRenderedRectangle({
|
|
|
962
772
|
}
|
|
963
773
|
});
|
|
964
774
|
const setReference = useVizijStore(
|
|
965
|
-
|
|
775
|
+
useShallow3((state) => state.setReference)
|
|
966
776
|
);
|
|
967
777
|
const points = useMemo3(() => {
|
|
968
778
|
return [
|
|
@@ -992,7 +802,7 @@ function InnerRenderedRectangle({
|
|
|
992
802
|
[setHoveredElement]
|
|
993
803
|
);
|
|
994
804
|
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
995
|
-
/* @__PURE__ */
|
|
805
|
+
/* @__PURE__ */ jsx3(
|
|
996
806
|
Plane,
|
|
997
807
|
{
|
|
998
808
|
ref: rectangleRef,
|
|
@@ -1007,10 +817,10 @@ function InnerRenderedRectangle({
|
|
|
1007
817
|
e
|
|
1008
818
|
);
|
|
1009
819
|
},
|
|
1010
|
-
children: /* @__PURE__ */
|
|
820
|
+
children: /* @__PURE__ */ jsx3("meshStandardMaterial", { attach: "material", ref: materialRef })
|
|
1011
821
|
}
|
|
1012
822
|
),
|
|
1013
|
-
showLine2(rectangle) && /* @__PURE__ */
|
|
823
|
+
showLine2(rectangle) && /* @__PURE__ */ jsx3(
|
|
1014
824
|
Line2,
|
|
1015
825
|
{
|
|
1016
826
|
ref: lineRef,
|
|
@@ -1021,7 +831,7 @@ function InnerRenderedRectangle({
|
|
|
1021
831
|
)
|
|
1022
832
|
] });
|
|
1023
833
|
}
|
|
1024
|
-
var RenderedRectangle =
|
|
834
|
+
var RenderedRectangle = memo3(InnerRenderedRectangle);
|
|
1025
835
|
var showLine2 = (rectangle) => {
|
|
1026
836
|
if ("strokeOpacity" in rectangle.features) {
|
|
1027
837
|
return true;
|
|
@@ -1037,14 +847,14 @@ var showLine2 = (rectangle) => {
|
|
|
1037
847
|
|
|
1038
848
|
// src/renderables/shape.tsx
|
|
1039
849
|
import {
|
|
1040
|
-
memo as
|
|
850
|
+
memo as memo4,
|
|
1041
851
|
useCallback as useCallback4,
|
|
1042
852
|
useRef as useRef4,
|
|
1043
853
|
useMemo as useMemo4,
|
|
1044
854
|
useEffect as useEffect5
|
|
1045
855
|
} from "react";
|
|
1046
856
|
import * as THREE2 from "three";
|
|
1047
|
-
import { useShallow as
|
|
857
|
+
import { useShallow as useShallow4 } from "zustand/react/shallow";
|
|
1048
858
|
import {
|
|
1049
859
|
instanceOfRawEuler as instanceOfRawEuler4,
|
|
1050
860
|
instanceOfRawHSL as instanceOfRawHSL3,
|
|
@@ -1052,7 +862,7 @@ import {
|
|
|
1052
862
|
instanceOfRawRGB as instanceOfRawRGB3,
|
|
1053
863
|
instanceOfRawVector3 as instanceOfRawVector34
|
|
1054
864
|
} from "@vizij/utils";
|
|
1055
|
-
import { jsx as
|
|
865
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1056
866
|
THREE2.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
1057
867
|
function InnerRenderedShape({
|
|
1058
868
|
id,
|
|
@@ -1061,12 +871,12 @@ function InnerRenderedShape({
|
|
|
1061
871
|
}) {
|
|
1062
872
|
const refGroup = useRef4();
|
|
1063
873
|
const ref = useRef4();
|
|
1064
|
-
const shape = useVizijStore(
|
|
874
|
+
const shape = useVizijStore(useShallow4((state) => state.world[id]));
|
|
1065
875
|
const refs = useVizijStore(
|
|
1066
|
-
|
|
876
|
+
useShallow4((state) => state.world[id].refs)
|
|
1067
877
|
);
|
|
1068
878
|
const refIsNull = !refs[namespace]?.current;
|
|
1069
|
-
const animatables = useVizijStore(
|
|
879
|
+
const animatables = useVizijStore(useShallow4((state) => state.animatables));
|
|
1070
880
|
const animatableValues = useMemo4(() => {
|
|
1071
881
|
const av = {};
|
|
1072
882
|
Object.values(shape.features).forEach((feat) => {
|
|
@@ -1197,12 +1007,12 @@ function InnerRenderedShape({
|
|
|
1197
1007
|
},
|
|
1198
1008
|
shape
|
|
1199
1009
|
);
|
|
1200
|
-
const setReference = useVizijStore(
|
|
1010
|
+
const setReference = useVizijStore(useShallow4((state) => state.setReference));
|
|
1201
1011
|
const onElementClick = useVizijStore(
|
|
1202
|
-
|
|
1012
|
+
useShallow4((state) => state.onElementClick)
|
|
1203
1013
|
);
|
|
1204
1014
|
const setHoveredElement = useVizijStore(
|
|
1205
|
-
|
|
1015
|
+
useShallow4((state) => state.setHoveredElement)
|
|
1206
1016
|
);
|
|
1207
1017
|
useEffect5(() => {
|
|
1208
1018
|
if (ref.current && refIsNull) setReference(shape.id, namespace, ref);
|
|
@@ -1254,7 +1064,7 @@ function InnerRenderedShape({
|
|
|
1254
1064
|
onElementClick({ id, type: "shape", namespace }, [...chain, id], e);
|
|
1255
1065
|
},
|
|
1256
1066
|
children: [
|
|
1257
|
-
shape.material === "basic" && /* @__PURE__ */
|
|
1067
|
+
shape.material === "basic" && /* @__PURE__ */ jsx4(
|
|
1258
1068
|
"meshBasicMaterial",
|
|
1259
1069
|
{
|
|
1260
1070
|
attach: "material",
|
|
@@ -1262,7 +1072,7 @@ function InnerRenderedShape({
|
|
|
1262
1072
|
side: THREE2.DoubleSide
|
|
1263
1073
|
}
|
|
1264
1074
|
),
|
|
1265
|
-
shape.material === "lambert" && /* @__PURE__ */
|
|
1075
|
+
shape.material === "lambert" && /* @__PURE__ */ jsx4(
|
|
1266
1076
|
"meshLambertMaterial",
|
|
1267
1077
|
{
|
|
1268
1078
|
attach: "material",
|
|
@@ -1270,7 +1080,7 @@ function InnerRenderedShape({
|
|
|
1270
1080
|
side: THREE2.DoubleSide
|
|
1271
1081
|
}
|
|
1272
1082
|
),
|
|
1273
|
-
shape.material === "phong" && /* @__PURE__ */
|
|
1083
|
+
shape.material === "phong" && /* @__PURE__ */ jsx4(
|
|
1274
1084
|
"meshPhongMaterial",
|
|
1275
1085
|
{
|
|
1276
1086
|
attach: "material",
|
|
@@ -1278,7 +1088,7 @@ function InnerRenderedShape({
|
|
|
1278
1088
|
side: THREE2.DoubleSide
|
|
1279
1089
|
}
|
|
1280
1090
|
),
|
|
1281
|
-
shape.material === "standard" && /* @__PURE__ */
|
|
1091
|
+
shape.material === "standard" && /* @__PURE__ */ jsx4(
|
|
1282
1092
|
"meshStandardMaterial",
|
|
1283
1093
|
{
|
|
1284
1094
|
attach: "material",
|
|
@@ -1286,7 +1096,7 @@ function InnerRenderedShape({
|
|
|
1286
1096
|
side: THREE2.DoubleSide
|
|
1287
1097
|
}
|
|
1288
1098
|
),
|
|
1289
|
-
shape.material === "normal" && /* @__PURE__ */
|
|
1099
|
+
shape.material === "normal" && /* @__PURE__ */ jsx4(
|
|
1290
1100
|
"meshNormalMaterial",
|
|
1291
1101
|
{
|
|
1292
1102
|
attach: "material",
|
|
@@ -1294,7 +1104,7 @@ function InnerRenderedShape({
|
|
|
1294
1104
|
side: THREE2.DoubleSide
|
|
1295
1105
|
}
|
|
1296
1106
|
),
|
|
1297
|
-
shape.children?.map((child) => /* @__PURE__ */
|
|
1107
|
+
shape.children?.map((child) => /* @__PURE__ */ jsx4(
|
|
1298
1108
|
Renderable,
|
|
1299
1109
|
{
|
|
1300
1110
|
id: child,
|
|
@@ -1307,7 +1117,7 @@ function InnerRenderedShape({
|
|
|
1307
1117
|
}
|
|
1308
1118
|
);
|
|
1309
1119
|
}
|
|
1310
|
-
var RenderedShape =
|
|
1120
|
+
var RenderedShape = memo4(InnerRenderedShape);
|
|
1311
1121
|
var MATERIAL_FEATURE_KEYS = [
|
|
1312
1122
|
"color",
|
|
1313
1123
|
"opacity",
|
|
@@ -1355,14 +1165,14 @@ function extractMaterialName(name) {
|
|
|
1355
1165
|
}
|
|
1356
1166
|
|
|
1357
1167
|
// src/renderables/renderable.tsx
|
|
1358
|
-
import { Fragment as Fragment3, jsx as
|
|
1168
|
+
import { Fragment as Fragment3, jsx as jsx5 } from "react/jsx-runtime";
|
|
1359
1169
|
function InnerRenderable({
|
|
1360
1170
|
id,
|
|
1361
1171
|
namespace,
|
|
1362
1172
|
chain
|
|
1363
1173
|
}) {
|
|
1364
|
-
const type = useVizijStore(
|
|
1365
|
-
const refs = useVizijStore(
|
|
1174
|
+
const type = useVizijStore(useShallow5((state) => state.world[id].type));
|
|
1175
|
+
const refs = useVizijStore(useShallow5((state) => state.world[id].refs));
|
|
1366
1176
|
const resolvedNamespaces = useMemo5(() => {
|
|
1367
1177
|
let namespaces = [namespace];
|
|
1368
1178
|
if (namespace in refs) {
|
|
@@ -1375,10 +1185,10 @@ function InnerRenderable({
|
|
|
1375
1185
|
if (resolvedNamespaces.length === 0) {
|
|
1376
1186
|
return null;
|
|
1377
1187
|
}
|
|
1378
|
-
return /* @__PURE__ */
|
|
1188
|
+
return /* @__PURE__ */ jsx5(Fragment3, { children: resolvedNamespaces.map((ns) => {
|
|
1379
1189
|
switch (type) {
|
|
1380
1190
|
case "group":
|
|
1381
|
-
return /* @__PURE__ */
|
|
1191
|
+
return /* @__PURE__ */ jsx5(
|
|
1382
1192
|
RenderedGroup,
|
|
1383
1193
|
{
|
|
1384
1194
|
id,
|
|
@@ -1388,7 +1198,7 @@ function InnerRenderable({
|
|
|
1388
1198
|
`${ns}.${id}`
|
|
1389
1199
|
);
|
|
1390
1200
|
case "ellipse":
|
|
1391
|
-
return /* @__PURE__ */
|
|
1201
|
+
return /* @__PURE__ */ jsx5(
|
|
1392
1202
|
RenderedEllipse,
|
|
1393
1203
|
{
|
|
1394
1204
|
id,
|
|
@@ -1398,7 +1208,7 @@ function InnerRenderable({
|
|
|
1398
1208
|
`${ns}.${id}`
|
|
1399
1209
|
);
|
|
1400
1210
|
case "rectangle":
|
|
1401
|
-
return /* @__PURE__ */
|
|
1211
|
+
return /* @__PURE__ */ jsx5(
|
|
1402
1212
|
RenderedRectangle,
|
|
1403
1213
|
{
|
|
1404
1214
|
id,
|
|
@@ -1408,7 +1218,7 @@ function InnerRenderable({
|
|
|
1408
1218
|
`${ns}.${id}`
|
|
1409
1219
|
);
|
|
1410
1220
|
case "shape":
|
|
1411
|
-
return /* @__PURE__ */
|
|
1221
|
+
return /* @__PURE__ */ jsx5(
|
|
1412
1222
|
RenderedShape,
|
|
1413
1223
|
{
|
|
1414
1224
|
id,
|
|
@@ -1422,14 +1232,14 @@ function InnerRenderable({
|
|
|
1422
1232
|
}
|
|
1423
1233
|
}) });
|
|
1424
1234
|
}
|
|
1425
|
-
var Renderable =
|
|
1235
|
+
var Renderable = memo5(InnerRenderable);
|
|
1426
1236
|
|
|
1427
1237
|
// src/store.ts
|
|
1428
1238
|
import { create } from "zustand";
|
|
1429
1239
|
import { subscribeWithSelector } from "zustand/middleware";
|
|
1430
1240
|
import { produce, enableMapSet } from "immer";
|
|
1431
1241
|
import * as THREE3 from "three";
|
|
1432
|
-
import { getLookup as
|
|
1242
|
+
import { getLookup as getLookup2 } from "@vizij/utils";
|
|
1433
1243
|
|
|
1434
1244
|
// src/actions/create-new-element.ts
|
|
1435
1245
|
import { createRef } from "react";
|
|
@@ -1725,7 +1535,7 @@ var VizijSlice = (set, get) => ({
|
|
|
1725
1535
|
setValue: (id, namespace, value) => {
|
|
1726
1536
|
set(
|
|
1727
1537
|
produce((state) => {
|
|
1728
|
-
const lookupId =
|
|
1538
|
+
const lookupId = getLookup2(namespace, id);
|
|
1729
1539
|
if (typeof value === "function") {
|
|
1730
1540
|
const current = state.values.get(lookupId);
|
|
1731
1541
|
if (current !== void 0) {
|
|
@@ -1872,8 +1682,8 @@ var VizijSlice = (set, get) => ({
|
|
|
1872
1682
|
setSlot: (parentId, parentNamespace, childId, childNamespace) => {
|
|
1873
1683
|
set(
|
|
1874
1684
|
produce((state) => {
|
|
1875
|
-
const parentLookupId =
|
|
1876
|
-
const childLookupId =
|
|
1685
|
+
const parentLookupId = getLookup2(parentNamespace, parentId);
|
|
1686
|
+
const childLookupId = getLookup2(childNamespace, childId);
|
|
1877
1687
|
state.slotConfig[parentLookupId] = childLookupId;
|
|
1878
1688
|
})
|
|
1879
1689
|
);
|
|
@@ -1892,7 +1702,7 @@ var VizijSlice = (set, get) => ({
|
|
|
1892
1702
|
clearSlot: (parentId, parentNamespace) => {
|
|
1893
1703
|
set(
|
|
1894
1704
|
produce((state) => {
|
|
1895
|
-
const parentLookupId =
|
|
1705
|
+
const parentLookupId = getLookup2(parentNamespace, parentId);
|
|
1896
1706
|
delete state.slotConfig[parentLookupId];
|
|
1897
1707
|
})
|
|
1898
1708
|
);
|
|
@@ -1942,7 +1752,7 @@ var createVizijStore = (initial) => create()(
|
|
|
1942
1752
|
);
|
|
1943
1753
|
|
|
1944
1754
|
// src/vizij.tsx
|
|
1945
|
-
import { Fragment as Fragment4, jsx as
|
|
1755
|
+
import { Fragment as Fragment4, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1946
1756
|
Object3D4.DEFAULT_UP.set(0, 0, 1);
|
|
1947
1757
|
function Vizij({
|
|
1948
1758
|
style,
|
|
@@ -1954,14 +1764,19 @@ function Vizij({
|
|
|
1954
1764
|
}) {
|
|
1955
1765
|
const ctx = useContext3(VizijContext);
|
|
1956
1766
|
if (ctx) {
|
|
1957
|
-
return /* @__PURE__ */
|
|
1767
|
+
return /* @__PURE__ */ jsx6(
|
|
1958
1768
|
Canvas,
|
|
1959
1769
|
{
|
|
1960
1770
|
shadows: false,
|
|
1961
1771
|
style,
|
|
1962
1772
|
className,
|
|
1963
1773
|
onPointerMissed,
|
|
1964
|
-
|
|
1774
|
+
gl: {
|
|
1775
|
+
outputColorSpace: SRGBColorSpace,
|
|
1776
|
+
toneMapping: NoToneMapping,
|
|
1777
|
+
antialias: true
|
|
1778
|
+
},
|
|
1779
|
+
children: /* @__PURE__ */ jsx6(
|
|
1965
1780
|
MemoizedInnerVizij,
|
|
1966
1781
|
{
|
|
1967
1782
|
rootId,
|
|
@@ -1972,13 +1787,18 @@ function Vizij({
|
|
|
1972
1787
|
}
|
|
1973
1788
|
);
|
|
1974
1789
|
} else {
|
|
1975
|
-
return /* @__PURE__ */
|
|
1790
|
+
return /* @__PURE__ */ jsx6(VizijContext.Provider, { value: useDefaultVizijStore, children: /* @__PURE__ */ jsx6(
|
|
1976
1791
|
Canvas,
|
|
1977
1792
|
{
|
|
1978
1793
|
style,
|
|
1979
1794
|
className,
|
|
1980
1795
|
onPointerMissed,
|
|
1981
|
-
|
|
1796
|
+
gl: {
|
|
1797
|
+
outputColorSpace: SRGBColorSpace,
|
|
1798
|
+
toneMapping: NoToneMapping,
|
|
1799
|
+
antialias: true
|
|
1800
|
+
},
|
|
1801
|
+
children: /* @__PURE__ */ jsx6(
|
|
1982
1802
|
MemoizedInnerVizij,
|
|
1983
1803
|
{
|
|
1984
1804
|
rootId,
|
|
@@ -2001,8 +1821,8 @@ function InnerVizij({
|
|
|
2001
1821
|
height: container.height * container.resolution
|
|
2002
1822
|
} : void 0;
|
|
2003
1823
|
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
2004
|
-
/* @__PURE__ */
|
|
2005
|
-
/* @__PURE__ */
|
|
1824
|
+
/* @__PURE__ */ jsx6("ambientLight", { intensity: Math.PI / 2 }),
|
|
1825
|
+
/* @__PURE__ */ jsx6(
|
|
2006
1826
|
OrthographicCamera,
|
|
2007
1827
|
{
|
|
2008
1828
|
makeDefault: true,
|
|
@@ -2011,7 +1831,7 @@ function InnerVizij({
|
|
|
2011
1831
|
far: 101
|
|
2012
1832
|
}
|
|
2013
1833
|
),
|
|
2014
|
-
/* @__PURE__ */
|
|
1834
|
+
/* @__PURE__ */ jsx6(Suspense, { fallback: null, children: /* @__PURE__ */ jsx6(
|
|
2015
1835
|
World,
|
|
2016
1836
|
{
|
|
2017
1837
|
rootId,
|
|
@@ -2019,17 +1839,17 @@ function InnerVizij({
|
|
|
2019
1839
|
parentSizing: sceneParentSizing
|
|
2020
1840
|
}
|
|
2021
1841
|
) }),
|
|
2022
|
-
showSafeArea && /* @__PURE__ */
|
|
1842
|
+
showSafeArea && /* @__PURE__ */ jsx6(SafeAreaRenderer, { rootId })
|
|
2023
1843
|
] });
|
|
2024
1844
|
}
|
|
2025
|
-
var MemoizedInnerVizij =
|
|
1845
|
+
var MemoizedInnerVizij = memo6(InnerVizij);
|
|
2026
1846
|
function InnerWorld({
|
|
2027
1847
|
rootId,
|
|
2028
1848
|
namespace = "default",
|
|
2029
1849
|
parentSizing
|
|
2030
1850
|
}) {
|
|
2031
1851
|
const [present, rootBounds] = useVizijStore(
|
|
2032
|
-
|
|
1852
|
+
useShallow6((state) => {
|
|
2033
1853
|
const group = state.world[rootId];
|
|
2034
1854
|
const bounds = group?.rootBounds ?? defaultRootBounds;
|
|
2035
1855
|
return [group !== void 0, bounds];
|
|
@@ -2068,8 +1888,8 @@ function InnerWorld({
|
|
|
2068
1888
|
}
|
|
2069
1889
|
}, [rootBounds, camera, parentSizing, size]);
|
|
2070
1890
|
return /* @__PURE__ */ jsxs4(ErrorBoundary, { fallback: null, children: [
|
|
2071
|
-
present && /* @__PURE__ */
|
|
2072
|
-
!present && /* @__PURE__ */
|
|
1891
|
+
present && /* @__PURE__ */ jsx6(Renderable, { id: rootId, namespace, chain: [] }),
|
|
1892
|
+
!present && /* @__PURE__ */ jsx6(
|
|
2073
1893
|
Text,
|
|
2074
1894
|
{
|
|
2075
1895
|
position: [0, 0, 0],
|
|
@@ -2082,7 +1902,7 @@ function InnerWorld({
|
|
|
2082
1902
|
)
|
|
2083
1903
|
] });
|
|
2084
1904
|
}
|
|
2085
|
-
var World =
|
|
1905
|
+
var World = memo6(InnerWorld);
|
|
2086
1906
|
function SafeAreaRenderer({ rootId }) {
|
|
2087
1907
|
const rootBounds = useVizijStore((state) => {
|
|
2088
1908
|
const group = state.world[rootId];
|
|
@@ -2092,7 +1912,7 @@ function SafeAreaRenderer({ rootId }) {
|
|
|
2092
1912
|
const right = rootBounds.center.x + rootBounds.size.x / 2;
|
|
2093
1913
|
const top = rootBounds.center.y + rootBounds.size.y / 2;
|
|
2094
1914
|
const bottom = rootBounds.center.y - rootBounds.size.y / 2;
|
|
2095
|
-
return /* @__PURE__ */
|
|
1915
|
+
return /* @__PURE__ */ jsx6(
|
|
2096
1916
|
Line3,
|
|
2097
1917
|
{
|
|
2098
1918
|
points: [
|
|
@@ -2868,6 +2688,375 @@ function applyVizijBundle(object, bundle) {
|
|
|
2868
2688
|
};
|
|
2869
2689
|
}
|
|
2870
2690
|
|
|
2691
|
+
// src/functions/gltf-loading/extract-animations.ts
|
|
2692
|
+
var CHANNEL_PATH_TO_TRACK_PROPERTY = {
|
|
2693
|
+
translation: "position",
|
|
2694
|
+
rotation: "quaternion",
|
|
2695
|
+
scale: "scale",
|
|
2696
|
+
weights: "morphTargetInfluences"
|
|
2697
|
+
};
|
|
2698
|
+
function isPlainObject(value) {
|
|
2699
|
+
return Boolean(
|
|
2700
|
+
value && typeof value === "object" && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]"
|
|
2701
|
+
);
|
|
2702
|
+
}
|
|
2703
|
+
function clonePlainObject(value) {
|
|
2704
|
+
if (!value) {
|
|
2705
|
+
return void 0;
|
|
2706
|
+
}
|
|
2707
|
+
return JSON.parse(JSON.stringify(value));
|
|
2708
|
+
}
|
|
2709
|
+
function inferValueSize(valueType) {
|
|
2710
|
+
switch (valueType) {
|
|
2711
|
+
case "boolean":
|
|
2712
|
+
case "number":
|
|
2713
|
+
case "string":
|
|
2714
|
+
return 1;
|
|
2715
|
+
case "vector2":
|
|
2716
|
+
return 2;
|
|
2717
|
+
case "vector3":
|
|
2718
|
+
case "euler":
|
|
2719
|
+
case "rgb":
|
|
2720
|
+
case "hsl":
|
|
2721
|
+
return 3;
|
|
2722
|
+
case "vector4":
|
|
2723
|
+
case "quaternion":
|
|
2724
|
+
return 4;
|
|
2725
|
+
default:
|
|
2726
|
+
return 1;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
function componentNameToIndex(component) {
|
|
2730
|
+
if (!component || typeof component !== "string") {
|
|
2731
|
+
return void 0;
|
|
2732
|
+
}
|
|
2733
|
+
const normalized = component.trim().toLowerCase();
|
|
2734
|
+
if (normalized.length === 0) {
|
|
2735
|
+
return void 0;
|
|
2736
|
+
}
|
|
2737
|
+
const componentOrder = {
|
|
2738
|
+
x: 0,
|
|
2739
|
+
y: 1,
|
|
2740
|
+
z: 2,
|
|
2741
|
+
w: 3,
|
|
2742
|
+
r: 0,
|
|
2743
|
+
g: 1,
|
|
2744
|
+
b: 2,
|
|
2745
|
+
a: 3,
|
|
2746
|
+
u: 0,
|
|
2747
|
+
v: 1
|
|
2748
|
+
};
|
|
2749
|
+
return componentOrder[normalized];
|
|
2750
|
+
}
|
|
2751
|
+
function readComponentInfo(target) {
|
|
2752
|
+
if (!target || typeof target !== "object") {
|
|
2753
|
+
return {};
|
|
2754
|
+
}
|
|
2755
|
+
const sources = [];
|
|
2756
|
+
const record = target;
|
|
2757
|
+
const extensions = record.extensions;
|
|
2758
|
+
if (extensions && typeof extensions === "object") {
|
|
2759
|
+
const vizijChannel = extensions.VizijChannel;
|
|
2760
|
+
if (isPlainObject(vizijChannel)) {
|
|
2761
|
+
sources.push(vizijChannel);
|
|
2762
|
+
}
|
|
2763
|
+
const robotChannel = extensions.RobotChannel;
|
|
2764
|
+
if (isPlainObject(robotChannel)) {
|
|
2765
|
+
sources.push(robotChannel);
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
const extras = record.extras;
|
|
2769
|
+
if (isPlainObject(extras)) {
|
|
2770
|
+
sources.push(extras);
|
|
2771
|
+
}
|
|
2772
|
+
let component;
|
|
2773
|
+
let componentIndex;
|
|
2774
|
+
for (const source of sources) {
|
|
2775
|
+
if (!isPlainObject(source)) {
|
|
2776
|
+
continue;
|
|
2777
|
+
}
|
|
2778
|
+
if (typeof source.component === "string" && !component) {
|
|
2779
|
+
component = source.component;
|
|
2780
|
+
}
|
|
2781
|
+
if (typeof source.axis === "string" && !component) {
|
|
2782
|
+
component = source.axis;
|
|
2783
|
+
}
|
|
2784
|
+
if (typeof source.channel === "string" && !component) {
|
|
2785
|
+
component = source.channel;
|
|
2786
|
+
}
|
|
2787
|
+
if (Object.prototype.hasOwnProperty.call(source, "componentIndex") && componentIndex == null) {
|
|
2788
|
+
const value = source.componentIndex;
|
|
2789
|
+
if (typeof value === "number") {
|
|
2790
|
+
componentIndex = value;
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
if (Object.prototype.hasOwnProperty.call(source, "axisIndex") && componentIndex == null) {
|
|
2794
|
+
const value = source.axisIndex;
|
|
2795
|
+
if (typeof value === "number") {
|
|
2796
|
+
componentIndex = value;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
if (componentIndex == null) {
|
|
2801
|
+
componentIndex = componentNameToIndex(component);
|
|
2802
|
+
}
|
|
2803
|
+
return { component, componentIndex };
|
|
2804
|
+
}
|
|
2805
|
+
function resolveRobotNodeIndex(parserJson) {
|
|
2806
|
+
const indexMap = /* @__PURE__ */ new Map();
|
|
2807
|
+
if (!parserJson || typeof parserJson !== "object") {
|
|
2808
|
+
return indexMap;
|
|
2809
|
+
}
|
|
2810
|
+
const json = parserJson;
|
|
2811
|
+
const nodes = Array.isArray(json.nodes) ? json.nodes : [];
|
|
2812
|
+
nodes.forEach((node, nodeIndex) => {
|
|
2813
|
+
if (!node || typeof node !== "object") {
|
|
2814
|
+
return;
|
|
2815
|
+
}
|
|
2816
|
+
const extensions = node.extensions;
|
|
2817
|
+
if (!extensions || typeof extensions !== "object") {
|
|
2818
|
+
return;
|
|
2819
|
+
}
|
|
2820
|
+
const robotData = extensions.RobotData;
|
|
2821
|
+
if (!robotData || typeof robotData !== "object") {
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
const renderableId = typeof robotData.id === "string" ? robotData.id : void 0;
|
|
2825
|
+
if (!renderableId) {
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2828
|
+
const nodeName = typeof node.name === "string" && node.name.length > 0 ? node.name : void 0;
|
|
2829
|
+
const features = {};
|
|
2830
|
+
const robotFeatures = robotData.features;
|
|
2831
|
+
if (robotFeatures && typeof robotFeatures === "object") {
|
|
2832
|
+
Object.entries(robotFeatures).forEach(
|
|
2833
|
+
([featureKey, featureValue]) => {
|
|
2834
|
+
if (!featureValue || typeof featureValue !== "object" || !featureValue.animated) {
|
|
2835
|
+
return;
|
|
2836
|
+
}
|
|
2837
|
+
const value = featureValue.value;
|
|
2838
|
+
const componentId = value && typeof value === "object" && typeof value.id === "string" ? value.id : void 0;
|
|
2839
|
+
if (!componentId) {
|
|
2840
|
+
return;
|
|
2841
|
+
}
|
|
2842
|
+
const valueType = value && typeof value === "object" && typeof value.type === "string" ? value.type : void 0;
|
|
2843
|
+
features[featureKey] = {
|
|
2844
|
+
feature: featureKey,
|
|
2845
|
+
componentId,
|
|
2846
|
+
valueType
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
indexMap.set(nodeIndex, {
|
|
2852
|
+
renderableId,
|
|
2853
|
+
nodeName,
|
|
2854
|
+
features
|
|
2855
|
+
});
|
|
2856
|
+
});
|
|
2857
|
+
return indexMap;
|
|
2858
|
+
}
|
|
2859
|
+
function mapChannelPathToProperty(path) {
|
|
2860
|
+
if (typeof path !== "string") {
|
|
2861
|
+
return void 0;
|
|
2862
|
+
}
|
|
2863
|
+
return CHANNEL_PATH_TO_TRACK_PROPERTY[path] ?? path;
|
|
2864
|
+
}
|
|
2865
|
+
function resolveFeatureKey(channelTarget) {
|
|
2866
|
+
if (!channelTarget || typeof channelTarget !== "object") {
|
|
2867
|
+
return void 0;
|
|
2868
|
+
}
|
|
2869
|
+
const target = channelTarget;
|
|
2870
|
+
const extensions = target.extensions;
|
|
2871
|
+
if (extensions && typeof extensions === "object") {
|
|
2872
|
+
const vizij = extensions.VizijChannel;
|
|
2873
|
+
if (isPlainObject(vizij)) {
|
|
2874
|
+
const feature = vizij.feature;
|
|
2875
|
+
if (typeof feature === "string") {
|
|
2876
|
+
return feature;
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
const robot = extensions.RobotChannel;
|
|
2880
|
+
if (isPlainObject(robot)) {
|
|
2881
|
+
const feature = robot.feature;
|
|
2882
|
+
if (typeof feature === "string") {
|
|
2883
|
+
return feature;
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
const extras = target.extras;
|
|
2888
|
+
if (isPlainObject(extras)) {
|
|
2889
|
+
const feature = extras.feature;
|
|
2890
|
+
if (typeof feature === "string") {
|
|
2891
|
+
return feature;
|
|
2892
|
+
}
|
|
2893
|
+
const channel = extras.channel;
|
|
2894
|
+
if (typeof channel === "string") {
|
|
2895
|
+
return channel;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
const path = target.path;
|
|
2899
|
+
return typeof path === "string" ? path : void 0;
|
|
2900
|
+
}
|
|
2901
|
+
function resolveTrackForChannel(clip, channelIndex, expectedProperty, nodeName) {
|
|
2902
|
+
if (!clip) {
|
|
2903
|
+
return void 0;
|
|
2904
|
+
}
|
|
2905
|
+
const orderedTrack = clip.tracks[channelIndex];
|
|
2906
|
+
if (orderedTrack) {
|
|
2907
|
+
return orderedTrack;
|
|
2908
|
+
}
|
|
2909
|
+
if (!expectedProperty) {
|
|
2910
|
+
return void 0;
|
|
2911
|
+
}
|
|
2912
|
+
const property = expectedProperty;
|
|
2913
|
+
const matches = (track) => {
|
|
2914
|
+
const name = track?.name ?? "";
|
|
2915
|
+
if (!name) {
|
|
2916
|
+
return false;
|
|
2917
|
+
}
|
|
2918
|
+
if (nodeName && name === `${nodeName}.${property}`) {
|
|
2919
|
+
return true;
|
|
2920
|
+
}
|
|
2921
|
+
if (nodeName && name.startsWith(`${nodeName}.`) && name.endsWith(property)) {
|
|
2922
|
+
return true;
|
|
2923
|
+
}
|
|
2924
|
+
if (!nodeName && name.endsWith(property)) {
|
|
2925
|
+
return true;
|
|
2926
|
+
}
|
|
2927
|
+
return false;
|
|
2928
|
+
};
|
|
2929
|
+
return clip.tracks.find(matches);
|
|
2930
|
+
}
|
|
2931
|
+
function toNumberArray(arrayLike) {
|
|
2932
|
+
if (!arrayLike) {
|
|
2933
|
+
return [];
|
|
2934
|
+
}
|
|
2935
|
+
return Array.from(arrayLike, (value) => Number(value));
|
|
2936
|
+
}
|
|
2937
|
+
function resolveClipDuration(clip, tracks) {
|
|
2938
|
+
if (clip && Number.isFinite(clip.duration) && clip.duration >= 0) {
|
|
2939
|
+
return clip.duration;
|
|
2940
|
+
}
|
|
2941
|
+
let maxTime = 0;
|
|
2942
|
+
tracks.forEach((track) => {
|
|
2943
|
+
if (!track.times.length) {
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2946
|
+
const lastTime = track.times[track.times.length - 1] ?? 0;
|
|
2947
|
+
if (lastTime > maxTime) {
|
|
2948
|
+
maxTime = lastTime;
|
|
2949
|
+
}
|
|
2950
|
+
});
|
|
2951
|
+
return maxTime;
|
|
2952
|
+
}
|
|
2953
|
+
function resolveClipId(animation, clip, index) {
|
|
2954
|
+
if (typeof animation.name === "string" && animation.name.length > 0) {
|
|
2955
|
+
return animation.name;
|
|
2956
|
+
}
|
|
2957
|
+
if (clip?.name && clip.name.length > 0) {
|
|
2958
|
+
return clip.name;
|
|
2959
|
+
}
|
|
2960
|
+
return `gltf-animation-${index}`;
|
|
2961
|
+
}
|
|
2962
|
+
function extractVizijAnimations(parserJson, clips) {
|
|
2963
|
+
const animations = [];
|
|
2964
|
+
if (!parserJson || typeof parserJson !== "object") {
|
|
2965
|
+
return animations;
|
|
2966
|
+
}
|
|
2967
|
+
const robotNodeIndex = resolveRobotNodeIndex(parserJson);
|
|
2968
|
+
if (robotNodeIndex.size === 0) {
|
|
2969
|
+
return animations;
|
|
2970
|
+
}
|
|
2971
|
+
const json = parserJson;
|
|
2972
|
+
const gltfAnimations = Array.isArray(json.animations) ? json.animations : [];
|
|
2973
|
+
if (gltfAnimations.length === 0) {
|
|
2974
|
+
return animations;
|
|
2975
|
+
}
|
|
2976
|
+
gltfAnimations.forEach((animation, animationIndex) => {
|
|
2977
|
+
if (!animation || typeof animation !== "object") {
|
|
2978
|
+
return;
|
|
2979
|
+
}
|
|
2980
|
+
const animationRecord = animation;
|
|
2981
|
+
const channels = Array.isArray(animationRecord.channels) ? animationRecord.channels : [];
|
|
2982
|
+
if (channels.length === 0) {
|
|
2983
|
+
return;
|
|
2984
|
+
}
|
|
2985
|
+
const samplers = Array.isArray(animationRecord.samplers) ? animationRecord.samplers : [];
|
|
2986
|
+
const clip = Array.isArray(clips) ? clips[animationIndex] : void 0;
|
|
2987
|
+
const trackData = [];
|
|
2988
|
+
channels.forEach((channel, channelIndex) => {
|
|
2989
|
+
if (!channel || typeof channel !== "object") {
|
|
2990
|
+
return;
|
|
2991
|
+
}
|
|
2992
|
+
const channelRecord = channel;
|
|
2993
|
+
const target = channelRecord.target;
|
|
2994
|
+
const nodeIndex = target && typeof target === "object" && typeof target.node === "number" ? target.node : void 0;
|
|
2995
|
+
if (nodeIndex == null || !robotNodeIndex.has(nodeIndex)) {
|
|
2996
|
+
return;
|
|
2997
|
+
}
|
|
2998
|
+
const robotNode = robotNodeIndex.get(nodeIndex);
|
|
2999
|
+
const featureKey = resolveFeatureKey(target);
|
|
3000
|
+
if (!featureKey) {
|
|
3001
|
+
return;
|
|
3002
|
+
}
|
|
3003
|
+
const featureInfo = robotNode.features[featureKey];
|
|
3004
|
+
if (!featureInfo) {
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
const propertyName = mapChannelPathToProperty(
|
|
3008
|
+
target && typeof target === "object" ? target.path : void 0
|
|
3009
|
+
);
|
|
3010
|
+
const track = resolveTrackForChannel(
|
|
3011
|
+
clip,
|
|
3012
|
+
channelIndex,
|
|
3013
|
+
propertyName,
|
|
3014
|
+
robotNode.nodeName
|
|
3015
|
+
);
|
|
3016
|
+
if (!track) {
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
const samplerIndex = typeof channelRecord.sampler === "number" ? channelRecord.sampler : -1;
|
|
3020
|
+
const sampler = samplerIndex >= 0 && samplerIndex < samplers.length ? samplers[samplerIndex] : void 0;
|
|
3021
|
+
const interpolation = sampler && typeof sampler.interpolation === "string" ? sampler.interpolation : void 0;
|
|
3022
|
+
let valueSize = typeof track.getValueSize === "function" ? track.getValueSize() : inferValueSize(featureInfo.valueType);
|
|
3023
|
+
if (!Number.isFinite(valueSize) || valueSize <= 0) {
|
|
3024
|
+
valueSize = inferValueSize(featureInfo.valueType);
|
|
3025
|
+
}
|
|
3026
|
+
const { component, componentIndex } = readComponentInfo(target);
|
|
3027
|
+
trackData.push({
|
|
3028
|
+
componentId: featureInfo.componentId,
|
|
3029
|
+
feature: featureInfo.feature,
|
|
3030
|
+
renderableId: robotNode.renderableId,
|
|
3031
|
+
nodeIndex,
|
|
3032
|
+
nodeName: robotNode.nodeName,
|
|
3033
|
+
path: target && typeof target === "object" && typeof target.path === "string" ? target.path : void 0,
|
|
3034
|
+
component,
|
|
3035
|
+
componentIndex,
|
|
3036
|
+
valueType: featureInfo.valueType,
|
|
3037
|
+
valueSize,
|
|
3038
|
+
interpolation,
|
|
3039
|
+
times: toNumberArray(track.times),
|
|
3040
|
+
values: toNumberArray(track.values)
|
|
3041
|
+
});
|
|
3042
|
+
});
|
|
3043
|
+
if (trackData.length === 0) {
|
|
3044
|
+
return;
|
|
3045
|
+
}
|
|
3046
|
+
animations.push({
|
|
3047
|
+
id: resolveClipId(animationRecord, clip, animationIndex),
|
|
3048
|
+
name: typeof animationRecord.name === "string" && animationRecord.name.length > 0 ? animationRecord.name : clip?.name,
|
|
3049
|
+
duration: resolveClipDuration(clip, trackData),
|
|
3050
|
+
index: animationIndex,
|
|
3051
|
+
metadata: clonePlainObject(
|
|
3052
|
+
animationRecord.extras
|
|
3053
|
+
),
|
|
3054
|
+
tracks: trackData
|
|
3055
|
+
});
|
|
3056
|
+
});
|
|
3057
|
+
return animations;
|
|
3058
|
+
}
|
|
3059
|
+
|
|
2871
3060
|
// src/functions/load-gltf.ts
|
|
2872
3061
|
THREE5.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
2873
3062
|
var EmptyModelError = class extends Error {
|
|
@@ -2886,9 +3075,10 @@ async function loadGLTF(url, namespaces, aggressiveImport = false, rootBounds) {
|
|
|
2886
3075
|
actualizedNamespaces,
|
|
2887
3076
|
aggressiveImport,
|
|
2888
3077
|
rootBounds,
|
|
2889
|
-
modelData?.parser?.json
|
|
3078
|
+
modelData?.parser?.json,
|
|
3079
|
+
modelData.animations
|
|
2890
3080
|
);
|
|
2891
|
-
return [asset.world, asset.animatables];
|
|
3081
|
+
return [asset.world, asset.animatables, asset.animations];
|
|
2892
3082
|
}
|
|
2893
3083
|
async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, rootBounds) {
|
|
2894
3084
|
const actualizedNamespaces = namespaces.length > 0 ? namespaces : ["default"];
|
|
@@ -2901,7 +3091,7 @@ async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, root
|
|
|
2901
3091
|
aggressiveImport,
|
|
2902
3092
|
rootBounds
|
|
2903
3093
|
);
|
|
2904
|
-
return [asset.world, asset.animatables];
|
|
3094
|
+
return [asset.world, asset.animatables, asset.animations];
|
|
2905
3095
|
} finally {
|
|
2906
3096
|
URL.revokeObjectURL(objectUrl);
|
|
2907
3097
|
}
|
|
@@ -2920,9 +3110,10 @@ async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, root
|
|
|
2920
3110
|
actualizedNamespaces,
|
|
2921
3111
|
aggressiveImport,
|
|
2922
3112
|
rootBounds,
|
|
2923
|
-
gltf?.parser?.json
|
|
3113
|
+
gltf?.parser?.json,
|
|
3114
|
+
gltf.animations
|
|
2924
3115
|
);
|
|
2925
|
-
resolve([asset.world, asset.animatables]);
|
|
3116
|
+
resolve([asset.world, asset.animatables, asset.animations]);
|
|
2926
3117
|
} catch (error) {
|
|
2927
3118
|
if (error instanceof Error) {
|
|
2928
3119
|
reject(error);
|
|
@@ -2937,7 +3128,7 @@ async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, root
|
|
|
2937
3128
|
);
|
|
2938
3129
|
});
|
|
2939
3130
|
}
|
|
2940
|
-
function parseScene(scene, namespaces, aggressiveImport, rootBounds, parserJson) {
|
|
3131
|
+
function parseScene(scene, namespaces, aggressiveImport, rootBounds, parserJson, clips) {
|
|
2941
3132
|
const [world, animatables] = traverseThree(
|
|
2942
3133
|
scene,
|
|
2943
3134
|
namespaces,
|
|
@@ -2945,7 +3136,8 @@ function parseScene(scene, namespaces, aggressiveImport, rootBounds, parserJson)
|
|
|
2945
3136
|
rootBounds
|
|
2946
3137
|
);
|
|
2947
3138
|
const bundle = extractVizijBundle(scene, parserJson);
|
|
2948
|
-
|
|
3139
|
+
const animations = extractVizijAnimations(parserJson, clips);
|
|
3140
|
+
return { world, animatables, bundle, animations };
|
|
2949
3141
|
}
|
|
2950
3142
|
async function loadGLTFWithBundle(url, namespaces, aggressiveImport = false, rootBounds) {
|
|
2951
3143
|
const modelLoader = new GLTFLoader();
|
|
@@ -2957,7 +3149,8 @@ async function loadGLTFWithBundle(url, namespaces, aggressiveImport = false, roo
|
|
|
2957
3149
|
actualizedNamespaces,
|
|
2958
3150
|
aggressiveImport,
|
|
2959
3151
|
rootBounds,
|
|
2960
|
-
modelData?.parser?.json
|
|
3152
|
+
modelData?.parser?.json,
|
|
3153
|
+
modelData.animations
|
|
2961
3154
|
);
|
|
2962
3155
|
}
|
|
2963
3156
|
async function loadGLTFFromBlobWithBundle(blob, namespaces, aggressiveImport = false, rootBounds) {
|
|
@@ -2989,7 +3182,8 @@ async function loadGLTFFromBlobWithBundle(blob, namespaces, aggressiveImport = f
|
|
|
2989
3182
|
actualizedNamespaces,
|
|
2990
3183
|
aggressiveImport,
|
|
2991
3184
|
rootBounds,
|
|
2992
|
-
gltf?.parser?.json
|
|
3185
|
+
gltf?.parser?.json,
|
|
3186
|
+
gltf.animations
|
|
2993
3187
|
);
|
|
2994
3188
|
resolve(asset);
|
|
2995
3189
|
} catch (error) {
|
|
@@ -3098,7 +3292,6 @@ function exportScene(data, fileNameOrOptions = "scene.glb") {
|
|
|
3098
3292
|
}
|
|
3099
3293
|
}
|
|
3100
3294
|
export {
|
|
3101
|
-
Controller,
|
|
3102
3295
|
EmptyModelError,
|
|
3103
3296
|
InnerVizij,
|
|
3104
3297
|
ShapeMaterial,
|