@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.js
CHANGED
|
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.tsx
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Controller: () => Controller,
|
|
34
33
|
EmptyModelError: () => EmptyModelError,
|
|
35
34
|
InnerVizij: () => InnerVizij,
|
|
36
35
|
ShapeMaterial: () => ShapeMaterial,
|
|
@@ -55,12 +54,17 @@ __export(index_exports, {
|
|
|
55
54
|
});
|
|
56
55
|
module.exports = __toCommonJS(index_exports);
|
|
57
56
|
|
|
58
|
-
// src/
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
var
|
|
57
|
+
// src/vizij.tsx
|
|
58
|
+
var import_react10 = require("react");
|
|
59
|
+
var import_react_error_boundary = require("react-error-boundary");
|
|
60
|
+
var import_three = require("three");
|
|
61
|
+
var import_fiber = require("@react-three/fiber");
|
|
62
|
+
var import_drei3 = require("@react-three/drei");
|
|
63
|
+
var import_shallow7 = require("zustand/react/shallow");
|
|
64
|
+
|
|
65
|
+
// src/renderables/renderable.tsx
|
|
66
|
+
var import_react8 = require("react");
|
|
67
|
+
var import_shallow6 = require("zustand/react/shallow");
|
|
64
68
|
|
|
65
69
|
// src/hooks/use-vizij-store.ts
|
|
66
70
|
var import_react2 = require("react");
|
|
@@ -77,217 +81,20 @@ function useVizijStore(selector) {
|
|
|
77
81
|
return (0, import_zustand.useStore)(store, selector);
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
// src/controllers/controller.tsx
|
|
81
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
82
|
-
function InnerController({
|
|
83
|
-
animatableId,
|
|
84
|
-
namespace,
|
|
85
|
-
subfield,
|
|
86
|
-
className
|
|
87
|
-
}) {
|
|
88
|
-
const setValue = useVizijStore((0, import_shallow.useShallow)((state) => state.setValue));
|
|
89
|
-
const animatable = useVizijStore(
|
|
90
|
-
(0, import_shallow.useShallow)((state) => state.animatables[animatableId])
|
|
91
|
-
);
|
|
92
|
-
const lookupId = (0, import_utils.getLookup)(namespace ?? "default", animatableId);
|
|
93
|
-
const rawValue = useVizijStore(
|
|
94
|
-
(0, import_shallow.useShallow)((state) => state.values.get(lookupId))
|
|
95
|
-
);
|
|
96
|
-
if (animatable.type === "number") {
|
|
97
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_clsx.clsx)("flex flex-col w-full", className), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
98
|
-
import_ui.SliderNumberField,
|
|
99
|
-
{
|
|
100
|
-
size: import_ui.Size.Sm,
|
|
101
|
-
value: rawValue ?? animatable.default,
|
|
102
|
-
onChange: (v) => {
|
|
103
|
-
setValue(animatableId, namespace ?? "default", v);
|
|
104
|
-
},
|
|
105
|
-
min: animatable.constraints.min,
|
|
106
|
-
max: animatable.constraints.max
|
|
107
|
-
}
|
|
108
|
-
) });
|
|
109
|
-
} else if (animatable.type === "vector3" && !subfield) {
|
|
110
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_clsx.clsx)("flex flex-col gap-2", className), children: ["x", "y", "z"].map((axis) => {
|
|
111
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
112
|
-
InnerController,
|
|
113
|
-
{
|
|
114
|
-
animatableId,
|
|
115
|
-
namespace,
|
|
116
|
-
subfield: axis
|
|
117
|
-
},
|
|
118
|
-
axis
|
|
119
|
-
);
|
|
120
|
-
}) });
|
|
121
|
-
} else if (animatable.type === "vector2" && !subfield) {
|
|
122
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_clsx.clsx)("flex flex-col gap-2", className), children: ["x", "y"].map((axis) => {
|
|
123
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
-
InnerController,
|
|
125
|
-
{
|
|
126
|
-
animatableId,
|
|
127
|
-
namespace,
|
|
128
|
-
subfield: axis
|
|
129
|
-
},
|
|
130
|
-
axis
|
|
131
|
-
);
|
|
132
|
-
}) });
|
|
133
|
-
} else if (animatable.type === "euler" && !subfield) {
|
|
134
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_clsx.clsx)("flex flex-col gap-2", className), children: ["x", "y", "z"].map((axis) => {
|
|
135
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
-
InnerController,
|
|
137
|
-
{
|
|
138
|
-
animatableId,
|
|
139
|
-
namespace,
|
|
140
|
-
subfield: axis
|
|
141
|
-
},
|
|
142
|
-
axis
|
|
143
|
-
);
|
|
144
|
-
}) });
|
|
145
|
-
} else if (animatable.type === "rgb" && !subfield) {
|
|
146
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_clsx.clsx)("flex flex-col gap-2", className), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
147
|
-
import_ui.ColorPickerPopover,
|
|
148
|
-
{
|
|
149
|
-
value: rawValue ? convertRGBRange(rawValue, "255") : convertRGBRange(animatable.default, "255"),
|
|
150
|
-
onChange: (v) => {
|
|
151
|
-
setValue(
|
|
152
|
-
animatableId,
|
|
153
|
-
namespace ?? "default",
|
|
154
|
-
convertRGBRange(v, "1")
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
) });
|
|
159
|
-
} else if (animatable.type === "vector3" && subfield && ["x", "y", "z"].includes(subfield)) {
|
|
160
|
-
const axis = subfield;
|
|
161
|
-
const currentVec = rawValue ?? animatable.default;
|
|
162
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
163
|
-
import_ui.SliderNumberField,
|
|
164
|
-
{
|
|
165
|
-
label: axis,
|
|
166
|
-
size: import_ui.Size.Sm,
|
|
167
|
-
value: currentVec[axis],
|
|
168
|
-
onChange: (v) => {
|
|
169
|
-
setValue(animatableId, namespace ?? "default", {
|
|
170
|
-
...currentVec,
|
|
171
|
-
[axis]: v
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
175
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
} else if (animatable.type === "vector2" && subfield && ["x", "y"].includes(subfield)) {
|
|
179
|
-
const axis = subfield;
|
|
180
|
-
const currentVec = rawValue ?? animatable.default;
|
|
181
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
182
|
-
import_ui.SliderNumberField,
|
|
183
|
-
{
|
|
184
|
-
label: axis,
|
|
185
|
-
size: import_ui.Size.Sm,
|
|
186
|
-
value: currentVec[axis],
|
|
187
|
-
onChange: (v) => {
|
|
188
|
-
setValue(animatableId, namespace ?? "default", {
|
|
189
|
-
...currentVec,
|
|
190
|
-
[axis]: v
|
|
191
|
-
});
|
|
192
|
-
},
|
|
193
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
194
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
} else if (animatable.type === "euler" && subfield && ["x", "y", "z"].includes(subfield)) {
|
|
198
|
-
const axis = subfield;
|
|
199
|
-
const currentVec = rawValue ?? animatable.default;
|
|
200
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
201
|
-
import_ui.SliderNumberField,
|
|
202
|
-
{
|
|
203
|
-
label: axis,
|
|
204
|
-
size: import_ui.Size.Sm,
|
|
205
|
-
value: currentVec[axis],
|
|
206
|
-
onChange: (v) => {
|
|
207
|
-
setValue(animatableId, namespace ?? "default", {
|
|
208
|
-
...currentVec,
|
|
209
|
-
[axis]: v
|
|
210
|
-
});
|
|
211
|
-
},
|
|
212
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
213
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
} else if (animatable.type === "rgb" && subfield && ["r", "g", "b"].includes(subfield)) {
|
|
217
|
-
const axis = subfield;
|
|
218
|
-
const currentVec = rawValue ?? animatable.default;
|
|
219
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
220
|
-
import_ui.SliderNumberField,
|
|
221
|
-
{
|
|
222
|
-
label: axis,
|
|
223
|
-
size: import_ui.Size.Sm,
|
|
224
|
-
value: currentVec[axis],
|
|
225
|
-
strictText: true,
|
|
226
|
-
strictSlider: true,
|
|
227
|
-
onChange: (v) => {
|
|
228
|
-
setValue(animatableId, namespace ?? "default", {
|
|
229
|
-
...currentVec,
|
|
230
|
-
[axis]: v
|
|
231
|
-
});
|
|
232
|
-
},
|
|
233
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
234
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
var Controller = (0, import_react3.memo)(InnerController);
|
|
240
|
-
var vectorIndexLookup = {
|
|
241
|
-
x: 0,
|
|
242
|
-
y: 1,
|
|
243
|
-
z: 2,
|
|
244
|
-
r: 0,
|
|
245
|
-
g: 1,
|
|
246
|
-
b: 2
|
|
247
|
-
};
|
|
248
|
-
var convertRGBRange = (color, to) => {
|
|
249
|
-
if (to === "255") {
|
|
250
|
-
return {
|
|
251
|
-
r: color.r * 255,
|
|
252
|
-
g: color.g * 255,
|
|
253
|
-
b: color.b * 255
|
|
254
|
-
};
|
|
255
|
-
} else if (to === "1") {
|
|
256
|
-
return {
|
|
257
|
-
r: color.r / 255,
|
|
258
|
-
g: color.g / 255,
|
|
259
|
-
b: color.b / 255
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
return color;
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// src/vizij.tsx
|
|
266
|
-
var import_react11 = require("react");
|
|
267
|
-
var import_react_error_boundary = require("react-error-boundary");
|
|
268
|
-
var import_three = require("three");
|
|
269
|
-
var import_fiber = require("@react-three/fiber");
|
|
270
|
-
var import_drei3 = require("@react-three/drei");
|
|
271
|
-
var import_shallow8 = require("zustand/react/shallow");
|
|
272
|
-
|
|
273
|
-
// src/renderables/renderable.tsx
|
|
274
|
-
var import_react9 = require("react");
|
|
275
|
-
var import_shallow7 = require("zustand/react/shallow");
|
|
276
|
-
|
|
277
84
|
// src/renderables/group.tsx
|
|
278
|
-
var
|
|
85
|
+
var import_react4 = require("react");
|
|
279
86
|
var THREE = __toESM(require("three"));
|
|
280
|
-
var
|
|
281
|
-
var
|
|
87
|
+
var import_shallow2 = require("zustand/react/shallow");
|
|
88
|
+
var import_utils2 = require("@vizij/utils");
|
|
282
89
|
|
|
283
90
|
// src/hooks/use-features.ts
|
|
284
|
-
var
|
|
285
|
-
var
|
|
286
|
-
var
|
|
91
|
+
var import_react3 = require("react");
|
|
92
|
+
var import_shallow = require("zustand/shallow");
|
|
93
|
+
var import_utils = require("@vizij/utils");
|
|
287
94
|
function useFeatures(namespace, features, callbacks, debugInfo) {
|
|
288
|
-
const store = (0,
|
|
95
|
+
const store = (0, import_react3.useContext)(VizijContext);
|
|
289
96
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
290
|
-
(0,
|
|
97
|
+
(0, import_react3.useEffect)(() => {
|
|
291
98
|
const unsubsribes = [];
|
|
292
99
|
Object.keys(callbacks).forEach((key) => {
|
|
293
100
|
if (!(key in features)) {
|
|
@@ -313,11 +120,11 @@ function useFeatures(namespace, features, callbacks, debugInfo) {
|
|
|
313
120
|
}
|
|
314
121
|
};
|
|
315
122
|
const defaultValue = animatableValueInfo.default;
|
|
316
|
-
const lookupKey = (0,
|
|
123
|
+
const lookupKey = (0, import_utils.getLookup)(namespace, animatableValueInfo.id);
|
|
317
124
|
const unsubscribe = store.subscribe(
|
|
318
125
|
(state) => state.values.get(lookupKey) ?? defaultValue,
|
|
319
126
|
cb,
|
|
320
|
-
{ equalityFn:
|
|
127
|
+
{ equalityFn: import_shallow.shallow, fireImmediately: true }
|
|
321
128
|
);
|
|
322
129
|
unsubsribes.push(unsubscribe);
|
|
323
130
|
}
|
|
@@ -360,21 +167,21 @@ function createStoredRenderable(data, animatableValues) {
|
|
|
360
167
|
}
|
|
361
168
|
|
|
362
169
|
// src/renderables/group.tsx
|
|
363
|
-
var
|
|
170
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
364
171
|
THREE.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
365
172
|
function InnerRenderedGroup({
|
|
366
173
|
id,
|
|
367
174
|
namespace,
|
|
368
175
|
chain
|
|
369
176
|
}) {
|
|
370
|
-
const ref = (0,
|
|
371
|
-
const group = useVizijStore((0,
|
|
177
|
+
const ref = (0, import_react4.useRef)();
|
|
178
|
+
const group = useVizijStore((0, import_shallow2.useShallow)((state) => state.world[id]));
|
|
372
179
|
const refIsNull = !group.refs[namespace]?.current;
|
|
373
|
-
const animatables = useVizijStore((0,
|
|
180
|
+
const animatables = useVizijStore((0, import_shallow2.useShallow)((state) => state.animatables));
|
|
374
181
|
const setHoveredElement = useVizijStore(
|
|
375
|
-
(0,
|
|
182
|
+
(0, import_shallow2.useShallow)((state) => state.setHoveredElement)
|
|
376
183
|
);
|
|
377
|
-
const animatableValues = (0,
|
|
184
|
+
const animatableValues = (0, import_react4.useMemo)(() => {
|
|
378
185
|
const av = {};
|
|
379
186
|
Object.values(group.features).forEach((feat) => {
|
|
380
187
|
if (feat.animated) {
|
|
@@ -391,33 +198,33 @@ function InnerRenderedGroup({
|
|
|
391
198
|
};
|
|
392
199
|
useFeatures(namespace, group.features, {
|
|
393
200
|
translation: (pos) => {
|
|
394
|
-
if (ref.current?.position && (0,
|
|
201
|
+
if (ref.current?.position && (0, import_utils2.instanceOfRawVector3)(pos)) {
|
|
395
202
|
ref.current.position.set(
|
|
396
203
|
pos.x,
|
|
397
204
|
pos.y,
|
|
398
205
|
pos.z
|
|
399
206
|
);
|
|
400
|
-
} else if (ref.current?.position && (0,
|
|
207
|
+
} else if (ref.current?.position && (0, import_utils2.instanceOfRawVector2)(pos)) {
|
|
401
208
|
const currentZ = ref.current.position.z;
|
|
402
209
|
ref.current.position.set(pos.x, pos.y, currentZ);
|
|
403
210
|
}
|
|
404
211
|
},
|
|
405
212
|
rotation: (rot) => {
|
|
406
|
-
if (ref.current?.rotation && (0,
|
|
213
|
+
if (ref.current?.rotation && (0, import_utils2.instanceOfRawEuler)(rot)) {
|
|
407
214
|
ref.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
408
|
-
} else if (ref.current?.rotation && (0,
|
|
215
|
+
} else if (ref.current?.rotation && (0, import_utils2.instanceOfRawNumber)(rot)) {
|
|
409
216
|
ref.current.rotation.set(0, 0, 0);
|
|
410
217
|
ref.current.rotateZ(rot);
|
|
411
218
|
}
|
|
412
219
|
},
|
|
413
220
|
scale: (scale) => {
|
|
414
|
-
if (ref.current?.scale && (0,
|
|
221
|
+
if (ref.current?.scale && (0, import_utils2.instanceOfRawVector3)(scale)) {
|
|
415
222
|
if (scale.x === null || scale.y === null || scale.z === null) {
|
|
416
223
|
ref.current.scale.set(0.1, 0.1, 0.1);
|
|
417
224
|
return;
|
|
418
225
|
}
|
|
419
226
|
ref.current.scale.set(scale.x, scale.y, scale.z);
|
|
420
|
-
} else if (ref.current && (0,
|
|
227
|
+
} else if (ref.current && (0, import_utils2.instanceOfRawNumber)(scale)) {
|
|
421
228
|
ref.current.scale.set(scale, scale, scale);
|
|
422
229
|
} else if (ref.current) {
|
|
423
230
|
ref.current.scale.set(1, 1, 1);
|
|
@@ -425,19 +232,19 @@ function InnerRenderedGroup({
|
|
|
425
232
|
}
|
|
426
233
|
});
|
|
427
234
|
const setReference = useVizijStore(
|
|
428
|
-
(0,
|
|
235
|
+
(0, import_shallow2.useShallow)((state) => state.setReference)
|
|
429
236
|
);
|
|
430
|
-
(0,
|
|
237
|
+
(0, import_react4.useEffect)(() => {
|
|
431
238
|
if (ref.current && refIsNull) {
|
|
432
239
|
setReference(group.id, namespace, ref);
|
|
433
240
|
}
|
|
434
241
|
}, [group.id, namespace, ref, setReference, refIsNull]);
|
|
435
|
-
(0,
|
|
242
|
+
(0, import_react4.useEffect)(() => {
|
|
436
243
|
if (ref.current) {
|
|
437
244
|
ref.current.name = group.name;
|
|
438
245
|
}
|
|
439
246
|
}, [group.name]);
|
|
440
|
-
const handlePointerOver = (0,
|
|
247
|
+
const handlePointerOver = (0, import_react4.useCallback)(
|
|
441
248
|
(event) => {
|
|
442
249
|
if (event.eventObject !== event.object) {
|
|
443
250
|
return;
|
|
@@ -446,7 +253,7 @@ function InnerRenderedGroup({
|
|
|
446
253
|
},
|
|
447
254
|
[id, namespace, setHoveredElement]
|
|
448
255
|
);
|
|
449
|
-
const handlePointerOut = (0,
|
|
256
|
+
const handlePointerOut = (0, import_react4.useCallback)(
|
|
450
257
|
(event) => {
|
|
451
258
|
if (event.eventObject !== event.object) {
|
|
452
259
|
return;
|
|
@@ -455,7 +262,7 @@ function InnerRenderedGroup({
|
|
|
455
262
|
},
|
|
456
263
|
[setHoveredElement]
|
|
457
264
|
);
|
|
458
|
-
return /* @__PURE__ */ (0,
|
|
265
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
459
266
|
"group",
|
|
460
267
|
{
|
|
461
268
|
ref,
|
|
@@ -463,7 +270,7 @@ function InnerRenderedGroup({
|
|
|
463
270
|
userData,
|
|
464
271
|
onPointerOver: handlePointerOver,
|
|
465
272
|
onPointerOut: handlePointerOut,
|
|
466
|
-
children: group.children.map((child) => /* @__PURE__ */ (0,
|
|
273
|
+
children: group.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
467
274
|
Renderable,
|
|
468
275
|
{
|
|
469
276
|
id: child,
|
|
@@ -475,36 +282,36 @@ function InnerRenderedGroup({
|
|
|
475
282
|
}
|
|
476
283
|
);
|
|
477
284
|
}
|
|
478
|
-
var RenderedGroup = (0,
|
|
285
|
+
var RenderedGroup = (0, import_react4.memo)(InnerRenderedGroup);
|
|
479
286
|
|
|
480
287
|
// src/renderables/ellipse.tsx
|
|
481
|
-
var
|
|
482
|
-
var
|
|
483
|
-
var
|
|
288
|
+
var import_react5 = require("react");
|
|
289
|
+
var import_shallow3 = require("zustand/react/shallow");
|
|
290
|
+
var import_utils3 = require("@vizij/utils");
|
|
484
291
|
var import_drei = require("@react-three/drei");
|
|
485
|
-
var
|
|
292
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
486
293
|
function InnerRenderedEllipse({
|
|
487
294
|
id,
|
|
488
295
|
namespace,
|
|
489
296
|
chain
|
|
490
297
|
}) {
|
|
491
|
-
const ellipseRef = (0,
|
|
492
|
-
const materialRef = (0,
|
|
493
|
-
const lineRef = (0,
|
|
494
|
-
const strokeOffsetRef = (0,
|
|
495
|
-
const strokeWidthRef = (0,
|
|
298
|
+
const ellipseRef = (0, import_react5.useRef)();
|
|
299
|
+
const materialRef = (0, import_react5.useRef)();
|
|
300
|
+
const lineRef = (0, import_react5.useRef)();
|
|
301
|
+
const strokeOffsetRef = (0, import_react5.useRef)(0);
|
|
302
|
+
const strokeWidthRef = (0, import_react5.useRef)(0);
|
|
496
303
|
const onElementClick = useVizijStore(
|
|
497
|
-
(0,
|
|
304
|
+
(0, import_shallow3.useShallow)((state) => state.onElementClick)
|
|
498
305
|
);
|
|
499
306
|
const setHoveredElement = useVizijStore(
|
|
500
|
-
(0,
|
|
307
|
+
(0, import_shallow3.useShallow)((state) => state.setHoveredElement)
|
|
501
308
|
);
|
|
502
309
|
const ellipse = useVizijStore(
|
|
503
|
-
(0,
|
|
310
|
+
(0, import_shallow3.useShallow)((state) => state.world[id])
|
|
504
311
|
);
|
|
505
312
|
const refIsNull = !ellipse.refs[namespace]?.current;
|
|
506
|
-
const animatables = useVizijStore((0,
|
|
507
|
-
const animatableValues = (0,
|
|
313
|
+
const animatables = useVizijStore((0, import_shallow3.useShallow)((state) => state.animatables));
|
|
314
|
+
const animatableValues = (0, import_react5.useMemo)(() => {
|
|
508
315
|
const av = {};
|
|
509
316
|
Object.values(ellipse.features).forEach((feat) => {
|
|
510
317
|
if (feat.animated) {
|
|
@@ -514,11 +321,11 @@ function InnerRenderedEllipse({
|
|
|
514
321
|
});
|
|
515
322
|
return av;
|
|
516
323
|
}, [ellipse.features, animatables]);
|
|
517
|
-
const selectionData = (0,
|
|
324
|
+
const selectionData = (0, import_react5.useMemo)(
|
|
518
325
|
() => ({ id, namespace, type: "ellipse" }),
|
|
519
326
|
[id, namespace]
|
|
520
327
|
);
|
|
521
|
-
const userData = (0,
|
|
328
|
+
const userData = (0, import_react5.useMemo)(
|
|
522
329
|
() => ({
|
|
523
330
|
gltfExtensions: {
|
|
524
331
|
RobotData: createStoredRenderable(ellipse, animatableValues)
|
|
@@ -529,13 +336,13 @@ function InnerRenderedEllipse({
|
|
|
529
336
|
);
|
|
530
337
|
useFeatures(namespace, ellipse.features, {
|
|
531
338
|
translation: (pos) => {
|
|
532
|
-
if (ellipseRef.current?.position && (0,
|
|
339
|
+
if (ellipseRef.current?.position && (0, import_utils3.instanceOfRawVector3)(pos)) {
|
|
533
340
|
ellipseRef.current.position.set(
|
|
534
341
|
pos.x,
|
|
535
342
|
pos.y,
|
|
536
343
|
pos.z
|
|
537
344
|
);
|
|
538
|
-
} else if (ellipseRef.current?.position && (0,
|
|
345
|
+
} else if (ellipseRef.current?.position && (0, import_utils3.instanceOfRawVector2)(pos)) {
|
|
539
346
|
const currentZ = ellipseRef.current.position.z;
|
|
540
347
|
ellipseRef.current.position.set(
|
|
541
348
|
pos.x,
|
|
@@ -543,13 +350,13 @@ function InnerRenderedEllipse({
|
|
|
543
350
|
currentZ
|
|
544
351
|
);
|
|
545
352
|
}
|
|
546
|
-
if (lineRef.current?.position && (0,
|
|
353
|
+
if (lineRef.current?.position && (0, import_utils3.instanceOfRawVector3)(pos)) {
|
|
547
354
|
lineRef.current.position.set(
|
|
548
355
|
pos.x,
|
|
549
356
|
pos.y,
|
|
550
357
|
pos.z
|
|
551
358
|
);
|
|
552
|
-
} else if (lineRef.current?.position && (0,
|
|
359
|
+
} else if (lineRef.current?.position && (0, import_utils3.instanceOfRawVector2)(pos)) {
|
|
553
360
|
const currentZ = lineRef.current.position.z;
|
|
554
361
|
lineRef.current.position.set(
|
|
555
362
|
pos.x,
|
|
@@ -559,21 +366,21 @@ function InnerRenderedEllipse({
|
|
|
559
366
|
}
|
|
560
367
|
},
|
|
561
368
|
rotation: (rot) => {
|
|
562
|
-
if (ellipseRef.current?.rotation && (0,
|
|
369
|
+
if (ellipseRef.current?.rotation && (0, import_utils3.instanceOfRawEuler)(rot)) {
|
|
563
370
|
ellipseRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
564
|
-
} else if (ellipseRef.current?.rotation && (0,
|
|
371
|
+
} else if (ellipseRef.current?.rotation && (0, import_utils3.instanceOfRawNumber)(rot)) {
|
|
565
372
|
ellipseRef.current.rotation.set(0, 0, 0);
|
|
566
373
|
ellipseRef.current.rotateZ(rot);
|
|
567
374
|
}
|
|
568
|
-
if (lineRef.current?.rotation && (0,
|
|
375
|
+
if (lineRef.current?.rotation && (0, import_utils3.instanceOfRawEuler)(rot)) {
|
|
569
376
|
lineRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
570
|
-
} else if (lineRef.current?.rotation && (0,
|
|
377
|
+
} else if (lineRef.current?.rotation && (0, import_utils3.instanceOfRawNumber)(rot)) {
|
|
571
378
|
lineRef.current.rotation.set(0, 0, 0);
|
|
572
379
|
lineRef.current.rotateZ(rot);
|
|
573
380
|
}
|
|
574
381
|
},
|
|
575
382
|
fillOpacity: (op) => {
|
|
576
|
-
if (materialRef.current?.opacity !== void 0 && (0,
|
|
383
|
+
if (materialRef.current?.opacity !== void 0 && (0, import_utils3.instanceOfRawNumber)(op)) {
|
|
577
384
|
materialRef.current.opacity = op;
|
|
578
385
|
if (op < 1) {
|
|
579
386
|
materialRef.current.transparent = true;
|
|
@@ -585,23 +392,23 @@ function InnerRenderedEllipse({
|
|
|
585
392
|
},
|
|
586
393
|
fillColor: (color) => {
|
|
587
394
|
if (materialRef.current?.color) {
|
|
588
|
-
if ((0,
|
|
395
|
+
if ((0, import_utils3.instanceOfRawRGB)(color)) {
|
|
589
396
|
materialRef.current.color.setRGB(color.r, color.g, color.b);
|
|
590
397
|
materialRef.current.needsUpdate = true;
|
|
591
|
-
} else if ((0,
|
|
398
|
+
} else if ((0, import_utils3.instanceOfRawVector3)(color)) {
|
|
592
399
|
materialRef.current.color.setRGB(color.x, color.y, color.z);
|
|
593
400
|
materialRef.current.needsUpdate = true;
|
|
594
|
-
} else if ((0,
|
|
401
|
+
} else if ((0, import_utils3.instanceOfRawHSL)(color)) {
|
|
595
402
|
materialRef.current.color.setHSL(color.h, color.s, color.l);
|
|
596
403
|
materialRef.current.needsUpdate = true;
|
|
597
404
|
}
|
|
598
405
|
}
|
|
599
406
|
},
|
|
600
407
|
height: (height) => {
|
|
601
|
-
if (ellipseRef.current && (0,
|
|
408
|
+
if (ellipseRef.current && (0, import_utils3.instanceOfRawNumber)(height)) {
|
|
602
409
|
ellipseRef.current.scale.set(ellipseRef.current.scale.x, height, 1);
|
|
603
410
|
}
|
|
604
|
-
if (ellipseRef.current && lineRef.current && (0,
|
|
411
|
+
if (ellipseRef.current && lineRef.current && (0, import_utils3.instanceOfRawNumber)(height)) {
|
|
605
412
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
606
413
|
lineRef.current.scale.set(
|
|
607
414
|
ellipseRef.current.scale.x + offset,
|
|
@@ -611,10 +418,10 @@ function InnerRenderedEllipse({
|
|
|
611
418
|
}
|
|
612
419
|
},
|
|
613
420
|
width: (width) => {
|
|
614
|
-
if (ellipseRef.current && (0,
|
|
421
|
+
if (ellipseRef.current && (0, import_utils3.instanceOfRawNumber)(width)) {
|
|
615
422
|
ellipseRef.current.scale.set(width, ellipseRef.current.scale.y, 1);
|
|
616
423
|
}
|
|
617
|
-
if (ellipseRef.current && lineRef.current && (0,
|
|
424
|
+
if (ellipseRef.current && lineRef.current && (0, import_utils3.instanceOfRawNumber)(width)) {
|
|
618
425
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
619
426
|
lineRef.current.scale.set(
|
|
620
427
|
width + offset,
|
|
@@ -624,7 +431,7 @@ function InnerRenderedEllipse({
|
|
|
624
431
|
}
|
|
625
432
|
},
|
|
626
433
|
strokeOpacity: (strokeOpacity) => {
|
|
627
|
-
if (lineRef.current?.material && (0,
|
|
434
|
+
if (lineRef.current?.material && (0, import_utils3.instanceOfRawNumber)(strokeOpacity)) {
|
|
628
435
|
lineRef.current.material.opacity = strokeOpacity;
|
|
629
436
|
if (strokeOpacity < 1) {
|
|
630
437
|
lineRef.current.material.transparent = true;
|
|
@@ -636,21 +443,21 @@ function InnerRenderedEllipse({
|
|
|
636
443
|
},
|
|
637
444
|
strokeColor: (strokeColor) => {
|
|
638
445
|
if (lineRef.current?.material.color) {
|
|
639
|
-
if ((0,
|
|
446
|
+
if ((0, import_utils3.instanceOfRawRGB)(strokeColor)) {
|
|
640
447
|
lineRef.current.material.color.setRGB(
|
|
641
448
|
strokeColor.r,
|
|
642
449
|
strokeColor.g,
|
|
643
450
|
strokeColor.b
|
|
644
451
|
);
|
|
645
452
|
lineRef.current.material.needsUpdate = true;
|
|
646
|
-
} else if ((0,
|
|
453
|
+
} else if ((0, import_utils3.instanceOfRawVector3)(strokeColor)) {
|
|
647
454
|
lineRef.current.material.color.setRGB(
|
|
648
455
|
strokeColor.x,
|
|
649
456
|
strokeColor.y,
|
|
650
457
|
strokeColor.z
|
|
651
458
|
);
|
|
652
459
|
lineRef.current.material.needsUpdate = true;
|
|
653
|
-
} else if ((0,
|
|
460
|
+
} else if ((0, import_utils3.instanceOfRawHSL)(strokeColor)) {
|
|
654
461
|
lineRef.current.material.color.setHSL(
|
|
655
462
|
strokeColor.h,
|
|
656
463
|
strokeColor.s,
|
|
@@ -662,7 +469,7 @@ function InnerRenderedEllipse({
|
|
|
662
469
|
},
|
|
663
470
|
strokeWidth: (strokeWidth) => {
|
|
664
471
|
if (lineRef.current?.material && ellipseRef.current) {
|
|
665
|
-
if ((0,
|
|
472
|
+
if ((0, import_utils3.instanceOfRawNumber)(strokeWidth)) {
|
|
666
473
|
strokeWidthRef.current = strokeWidth;
|
|
667
474
|
const offset = strokeWidth * strokeOffsetRef.current / 2 + strokeOffsetRef.current * -1;
|
|
668
475
|
lineRef.current.scale.set(
|
|
@@ -677,7 +484,7 @@ function InnerRenderedEllipse({
|
|
|
677
484
|
},
|
|
678
485
|
strokeOffset: (strokeOffset) => {
|
|
679
486
|
if (lineRef.current?.material && ellipseRef.current) {
|
|
680
|
-
if ((0,
|
|
487
|
+
if ((0, import_utils3.instanceOfRawNumber)(strokeOffset)) {
|
|
681
488
|
strokeOffsetRef.current = strokeOffset;
|
|
682
489
|
const offset = strokeOffset * strokeWidthRef.current / 2 + strokeOffset * -1;
|
|
683
490
|
lineRef.current.scale.set(
|
|
@@ -690,9 +497,9 @@ function InnerRenderedEllipse({
|
|
|
690
497
|
}
|
|
691
498
|
});
|
|
692
499
|
const setReference = useVizijStore(
|
|
693
|
-
(0,
|
|
500
|
+
(0, import_shallow3.useShallow)((state) => state.setReference)
|
|
694
501
|
);
|
|
695
|
-
const points = (0,
|
|
502
|
+
const points = (0, import_react5.useMemo)(() => {
|
|
696
503
|
const n = 600;
|
|
697
504
|
const p = [];
|
|
698
505
|
const angleStep = 2 * Math.PI / n;
|
|
@@ -704,26 +511,26 @@ function InnerRenderedEllipse({
|
|
|
704
511
|
}
|
|
705
512
|
return p;
|
|
706
513
|
}, []);
|
|
707
|
-
(0,
|
|
514
|
+
(0, import_react5.useEffect)(() => {
|
|
708
515
|
if (ellipseRef.current && refIsNull)
|
|
709
516
|
setReference(ellipse.id, namespace, ellipseRef);
|
|
710
517
|
}, [ellipse.id, namespace, ellipseRef, setReference, refIsNull]);
|
|
711
|
-
const handlePointerOver = (0,
|
|
518
|
+
const handlePointerOver = (0, import_react5.useCallback)(
|
|
712
519
|
(event) => {
|
|
713
520
|
event.stopPropagation();
|
|
714
521
|
setHoveredElement({ id, namespace, type: "ellipse" });
|
|
715
522
|
},
|
|
716
523
|
[id, namespace, setHoveredElement]
|
|
717
524
|
);
|
|
718
|
-
const handlePointerOut = (0,
|
|
525
|
+
const handlePointerOut = (0, import_react5.useCallback)(
|
|
719
526
|
(event) => {
|
|
720
527
|
event.stopPropagation();
|
|
721
528
|
setHoveredElement(null);
|
|
722
529
|
},
|
|
723
530
|
[setHoveredElement]
|
|
724
531
|
);
|
|
725
|
-
return /* @__PURE__ */ (0,
|
|
726
|
-
/* @__PURE__ */ (0,
|
|
532
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
533
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
727
534
|
import_drei.Circle,
|
|
728
535
|
{
|
|
729
536
|
ref: ellipseRef,
|
|
@@ -734,10 +541,10 @@ function InnerRenderedEllipse({
|
|
|
734
541
|
onClick: (e) => {
|
|
735
542
|
onElementClick({ id, type: "ellipse", namespace }, [...chain, id], e);
|
|
736
543
|
},
|
|
737
|
-
children: /* @__PURE__ */ (0,
|
|
544
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("meshStandardMaterial", { attach: "material", ref: materialRef })
|
|
738
545
|
}
|
|
739
546
|
),
|
|
740
|
-
showLine(ellipse) && /* @__PURE__ */ (0,
|
|
547
|
+
showLine(ellipse) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
741
548
|
import_drei.Line,
|
|
742
549
|
{
|
|
743
550
|
ref: lineRef,
|
|
@@ -748,7 +555,7 @@ function InnerRenderedEllipse({
|
|
|
748
555
|
)
|
|
749
556
|
] });
|
|
750
557
|
}
|
|
751
|
-
var RenderedEllipse = (0,
|
|
558
|
+
var RenderedEllipse = (0, import_react5.memo)(InnerRenderedEllipse);
|
|
752
559
|
var showLine = (ellipse) => {
|
|
753
560
|
if ("strokeOpacity" in ellipse.features) {
|
|
754
561
|
return true;
|
|
@@ -763,33 +570,33 @@ var showLine = (ellipse) => {
|
|
|
763
570
|
};
|
|
764
571
|
|
|
765
572
|
// src/renderables/rectangle.tsx
|
|
766
|
-
var
|
|
767
|
-
var
|
|
768
|
-
var
|
|
573
|
+
var import_react6 = require("react");
|
|
574
|
+
var import_shallow4 = require("zustand/react/shallow");
|
|
575
|
+
var import_utils4 = require("@vizij/utils");
|
|
769
576
|
var import_drei2 = require("@react-three/drei");
|
|
770
|
-
var
|
|
577
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
771
578
|
function InnerRenderedRectangle({
|
|
772
579
|
id,
|
|
773
580
|
namespace,
|
|
774
581
|
chain
|
|
775
582
|
}) {
|
|
776
|
-
const rectangleRef = (0,
|
|
777
|
-
const materialRef = (0,
|
|
778
|
-
const lineRef = (0,
|
|
779
|
-
const strokeOffsetRef = (0,
|
|
780
|
-
const strokeWidthRef = (0,
|
|
583
|
+
const rectangleRef = (0, import_react6.useRef)();
|
|
584
|
+
const materialRef = (0, import_react6.useRef)();
|
|
585
|
+
const lineRef = (0, import_react6.useRef)();
|
|
586
|
+
const strokeOffsetRef = (0, import_react6.useRef)(0);
|
|
587
|
+
const strokeWidthRef = (0, import_react6.useRef)(0);
|
|
781
588
|
const onElementClick = useVizijStore(
|
|
782
|
-
(0,
|
|
589
|
+
(0, import_shallow4.useShallow)((state) => state.onElementClick)
|
|
783
590
|
);
|
|
784
591
|
const setHoveredElement = useVizijStore(
|
|
785
|
-
(0,
|
|
592
|
+
(0, import_shallow4.useShallow)((state) => state.setHoveredElement)
|
|
786
593
|
);
|
|
787
594
|
const rectangle = useVizijStore(
|
|
788
|
-
(0,
|
|
595
|
+
(0, import_shallow4.useShallow)((state) => state.world[id])
|
|
789
596
|
);
|
|
790
597
|
const refIsNull = !rectangle.refs[namespace]?.current;
|
|
791
|
-
const animatables = useVizijStore((0,
|
|
792
|
-
const animatableValues = (0,
|
|
598
|
+
const animatables = useVizijStore((0, import_shallow4.useShallow)((state) => state.animatables));
|
|
599
|
+
const animatableValues = (0, import_react6.useMemo)(() => {
|
|
793
600
|
const av = {};
|
|
794
601
|
Object.values(rectangle.features).forEach((feat) => {
|
|
795
602
|
if (feat.animated) {
|
|
@@ -799,11 +606,11 @@ function InnerRenderedRectangle({
|
|
|
799
606
|
});
|
|
800
607
|
return av;
|
|
801
608
|
}, [rectangle.features, animatables]);
|
|
802
|
-
const selectionData = (0,
|
|
609
|
+
const selectionData = (0, import_react6.useMemo)(
|
|
803
610
|
() => ({ id, namespace, type: "rectangle" }),
|
|
804
611
|
[id, namespace]
|
|
805
612
|
);
|
|
806
|
-
const userData = (0,
|
|
613
|
+
const userData = (0, import_react6.useMemo)(
|
|
807
614
|
() => ({
|
|
808
615
|
gltfExtensions: {
|
|
809
616
|
RobotData: createStoredRenderable(rectangle, animatableValues)
|
|
@@ -814,13 +621,13 @@ function InnerRenderedRectangle({
|
|
|
814
621
|
);
|
|
815
622
|
useFeatures(namespace, rectangle.features, {
|
|
816
623
|
translation: (pos) => {
|
|
817
|
-
if (rectangleRef.current?.position && (0,
|
|
624
|
+
if (rectangleRef.current?.position && (0, import_utils4.instanceOfRawVector3)(pos)) {
|
|
818
625
|
rectangleRef.current.position.set(
|
|
819
626
|
pos.x,
|
|
820
627
|
pos.y,
|
|
821
628
|
pos.z
|
|
822
629
|
);
|
|
823
|
-
} else if (rectangleRef.current?.position && (0,
|
|
630
|
+
} else if (rectangleRef.current?.position && (0, import_utils4.instanceOfRawVector2)(pos)) {
|
|
824
631
|
const currentZ = rectangleRef.current.position.z;
|
|
825
632
|
rectangleRef.current.position.set(
|
|
826
633
|
pos.x,
|
|
@@ -828,13 +635,13 @@ function InnerRenderedRectangle({
|
|
|
828
635
|
currentZ
|
|
829
636
|
);
|
|
830
637
|
}
|
|
831
|
-
if (lineRef.current?.position && (0,
|
|
638
|
+
if (lineRef.current?.position && (0, import_utils4.instanceOfRawVector3)(pos)) {
|
|
832
639
|
lineRef.current.position.set(
|
|
833
640
|
pos.x,
|
|
834
641
|
pos.y,
|
|
835
642
|
pos.z
|
|
836
643
|
);
|
|
837
|
-
} else if (lineRef.current?.position && (0,
|
|
644
|
+
} else if (lineRef.current?.position && (0, import_utils4.instanceOfRawVector2)(pos)) {
|
|
838
645
|
const currentZ = lineRef.current.position.z;
|
|
839
646
|
lineRef.current.position.set(
|
|
840
647
|
pos.x,
|
|
@@ -844,21 +651,21 @@ function InnerRenderedRectangle({
|
|
|
844
651
|
}
|
|
845
652
|
},
|
|
846
653
|
rotation: (rot) => {
|
|
847
|
-
if (rectangleRef.current?.rotation && (0,
|
|
654
|
+
if (rectangleRef.current?.rotation && (0, import_utils4.instanceOfRawEuler)(rot)) {
|
|
848
655
|
rectangleRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
849
|
-
} else if (rectangleRef.current?.rotation && (0,
|
|
656
|
+
} else if (rectangleRef.current?.rotation && (0, import_utils4.instanceOfRawNumber)(rot)) {
|
|
850
657
|
rectangleRef.current.rotation.set(0, 0, 0);
|
|
851
658
|
rectangleRef.current.rotateZ(rot);
|
|
852
659
|
}
|
|
853
|
-
if (lineRef.current?.rotation && (0,
|
|
660
|
+
if (lineRef.current?.rotation && (0, import_utils4.instanceOfRawEuler)(rot)) {
|
|
854
661
|
lineRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
855
|
-
} else if (lineRef.current?.rotation && (0,
|
|
662
|
+
} else if (lineRef.current?.rotation && (0, import_utils4.instanceOfRawNumber)(rot)) {
|
|
856
663
|
lineRef.current.rotation.set(0, 0, 0);
|
|
857
664
|
lineRef.current.rotateZ(rot);
|
|
858
665
|
}
|
|
859
666
|
},
|
|
860
667
|
fillOpacity: (op) => {
|
|
861
|
-
if (materialRef.current?.opacity !== void 0 && (0,
|
|
668
|
+
if (materialRef.current?.opacity !== void 0 && (0, import_utils4.instanceOfRawNumber)(op)) {
|
|
862
669
|
materialRef.current.opacity = op;
|
|
863
670
|
if (op < 1) {
|
|
864
671
|
materialRef.current.transparent = true;
|
|
@@ -870,23 +677,23 @@ function InnerRenderedRectangle({
|
|
|
870
677
|
},
|
|
871
678
|
fillColor: (color) => {
|
|
872
679
|
if (materialRef.current?.color) {
|
|
873
|
-
if ((0,
|
|
680
|
+
if ((0, import_utils4.instanceOfRawRGB)(color)) {
|
|
874
681
|
materialRef.current.color.setRGB(color.r, color.g, color.b);
|
|
875
682
|
materialRef.current.needsUpdate = true;
|
|
876
|
-
} else if ((0,
|
|
683
|
+
} else if ((0, import_utils4.instanceOfRawVector3)(color)) {
|
|
877
684
|
materialRef.current.color.setRGB(color.x, color.y, color.z);
|
|
878
685
|
materialRef.current.needsUpdate = true;
|
|
879
|
-
} else if ((0,
|
|
686
|
+
} else if ((0, import_utils4.instanceOfRawHSL)(color)) {
|
|
880
687
|
materialRef.current.color.setHSL(color.h, color.s, color.l);
|
|
881
688
|
materialRef.current.needsUpdate = true;
|
|
882
689
|
}
|
|
883
690
|
}
|
|
884
691
|
},
|
|
885
692
|
height: (height) => {
|
|
886
|
-
if (rectangleRef.current && (0,
|
|
693
|
+
if (rectangleRef.current && (0, import_utils4.instanceOfRawNumber)(height)) {
|
|
887
694
|
rectangleRef.current.scale.set(rectangleRef.current.scale.x, height, 1);
|
|
888
695
|
}
|
|
889
|
-
if (rectangleRef.current && lineRef.current && (0,
|
|
696
|
+
if (rectangleRef.current && lineRef.current && (0, import_utils4.instanceOfRawNumber)(height)) {
|
|
890
697
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
891
698
|
lineRef.current.scale.set(
|
|
892
699
|
rectangleRef.current.scale.x + offset,
|
|
@@ -896,10 +703,10 @@ function InnerRenderedRectangle({
|
|
|
896
703
|
}
|
|
897
704
|
},
|
|
898
705
|
width: (width) => {
|
|
899
|
-
if (rectangleRef.current && (0,
|
|
706
|
+
if (rectangleRef.current && (0, import_utils4.instanceOfRawNumber)(width)) {
|
|
900
707
|
rectangleRef.current.scale.set(width, rectangleRef.current.scale.y, 1);
|
|
901
708
|
}
|
|
902
|
-
if (rectangleRef.current && lineRef.current && (0,
|
|
709
|
+
if (rectangleRef.current && lineRef.current && (0, import_utils4.instanceOfRawNumber)(width)) {
|
|
903
710
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
904
711
|
lineRef.current.scale.set(
|
|
905
712
|
width + offset,
|
|
@@ -909,7 +716,7 @@ function InnerRenderedRectangle({
|
|
|
909
716
|
}
|
|
910
717
|
},
|
|
911
718
|
strokeOpacity: (strokeOpacity) => {
|
|
912
|
-
if (lineRef.current?.material && (0,
|
|
719
|
+
if (lineRef.current?.material && (0, import_utils4.instanceOfRawNumber)(strokeOpacity)) {
|
|
913
720
|
lineRef.current.material.opacity = strokeOpacity;
|
|
914
721
|
if (strokeOpacity < 1) {
|
|
915
722
|
lineRef.current.material.transparent = true;
|
|
@@ -921,21 +728,21 @@ function InnerRenderedRectangle({
|
|
|
921
728
|
},
|
|
922
729
|
strokeColor: (strokeColor) => {
|
|
923
730
|
if (lineRef.current?.material.color) {
|
|
924
|
-
if ((0,
|
|
731
|
+
if ((0, import_utils4.instanceOfRawRGB)(strokeColor)) {
|
|
925
732
|
lineRef.current.material.color.setRGB(
|
|
926
733
|
strokeColor.r,
|
|
927
734
|
strokeColor.g,
|
|
928
735
|
strokeColor.b
|
|
929
736
|
);
|
|
930
737
|
lineRef.current.material.needsUpdate = true;
|
|
931
|
-
} else if ((0,
|
|
738
|
+
} else if ((0, import_utils4.instanceOfRawVector3)(strokeColor)) {
|
|
932
739
|
lineRef.current.material.color.setRGB(
|
|
933
740
|
strokeColor.x,
|
|
934
741
|
strokeColor.y,
|
|
935
742
|
strokeColor.z
|
|
936
743
|
);
|
|
937
744
|
lineRef.current.material.needsUpdate = true;
|
|
938
|
-
} else if ((0,
|
|
745
|
+
} else if ((0, import_utils4.instanceOfRawHSL)(strokeColor)) {
|
|
939
746
|
lineRef.current.material.color.setHSL(
|
|
940
747
|
strokeColor.h,
|
|
941
748
|
strokeColor.s,
|
|
@@ -947,7 +754,7 @@ function InnerRenderedRectangle({
|
|
|
947
754
|
},
|
|
948
755
|
strokeWidth: (strokeWidth) => {
|
|
949
756
|
if (lineRef.current?.material && rectangleRef.current) {
|
|
950
|
-
if ((0,
|
|
757
|
+
if ((0, import_utils4.instanceOfRawNumber)(strokeWidth)) {
|
|
951
758
|
strokeWidthRef.current = strokeWidth;
|
|
952
759
|
const offset = strokeWidth * strokeOffsetRef.current / 2 + strokeOffsetRef.current * -1;
|
|
953
760
|
lineRef.current.scale.set(
|
|
@@ -962,7 +769,7 @@ function InnerRenderedRectangle({
|
|
|
962
769
|
},
|
|
963
770
|
strokeOffset: (strokeOffset) => {
|
|
964
771
|
if (lineRef.current?.material && rectangleRef.current) {
|
|
965
|
-
if ((0,
|
|
772
|
+
if ((0, import_utils4.instanceOfRawNumber)(strokeOffset)) {
|
|
966
773
|
strokeOffsetRef.current = strokeOffset;
|
|
967
774
|
const offset = strokeOffset * strokeWidthRef.current / 2 + strokeOffset * -1;
|
|
968
775
|
lineRef.current.scale.set(
|
|
@@ -975,9 +782,9 @@ function InnerRenderedRectangle({
|
|
|
975
782
|
}
|
|
976
783
|
});
|
|
977
784
|
const setReference = useVizijStore(
|
|
978
|
-
(0,
|
|
785
|
+
(0, import_shallow4.useShallow)((state) => state.setReference)
|
|
979
786
|
);
|
|
980
|
-
const points = (0,
|
|
787
|
+
const points = (0, import_react6.useMemo)(() => {
|
|
981
788
|
return [
|
|
982
789
|
[-0.5, 0.5, 0],
|
|
983
790
|
[0.5, 0.5, 0],
|
|
@@ -986,26 +793,26 @@ function InnerRenderedRectangle({
|
|
|
986
793
|
[-0.5, 0.5, 0]
|
|
987
794
|
];
|
|
988
795
|
}, []);
|
|
989
|
-
(0,
|
|
796
|
+
(0, import_react6.useEffect)(() => {
|
|
990
797
|
if (rectangleRef.current && refIsNull)
|
|
991
798
|
setReference(rectangle.id, namespace, rectangleRef);
|
|
992
799
|
}, [rectangle.id, namespace, rectangleRef, setReference, refIsNull]);
|
|
993
|
-
const handlePointerOver = (0,
|
|
800
|
+
const handlePointerOver = (0, import_react6.useCallback)(
|
|
994
801
|
(event) => {
|
|
995
802
|
event.stopPropagation();
|
|
996
803
|
setHoveredElement({ id, namespace, type: "rectangle" });
|
|
997
804
|
},
|
|
998
805
|
[id, namespace, setHoveredElement]
|
|
999
806
|
);
|
|
1000
|
-
const handlePointerOut = (0,
|
|
807
|
+
const handlePointerOut = (0, import_react6.useCallback)(
|
|
1001
808
|
(event) => {
|
|
1002
809
|
event.stopPropagation();
|
|
1003
810
|
setHoveredElement(null);
|
|
1004
811
|
},
|
|
1005
812
|
[setHoveredElement]
|
|
1006
813
|
);
|
|
1007
|
-
return /* @__PURE__ */ (0,
|
|
1008
|
-
/* @__PURE__ */ (0,
|
|
814
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
815
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1009
816
|
import_drei2.Plane,
|
|
1010
817
|
{
|
|
1011
818
|
ref: rectangleRef,
|
|
@@ -1020,10 +827,10 @@ function InnerRenderedRectangle({
|
|
|
1020
827
|
e
|
|
1021
828
|
);
|
|
1022
829
|
},
|
|
1023
|
-
children: /* @__PURE__ */ (0,
|
|
830
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("meshStandardMaterial", { attach: "material", ref: materialRef })
|
|
1024
831
|
}
|
|
1025
832
|
),
|
|
1026
|
-
showLine2(rectangle) && /* @__PURE__ */ (0,
|
|
833
|
+
showLine2(rectangle) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1027
834
|
import_drei2.Line,
|
|
1028
835
|
{
|
|
1029
836
|
ref: lineRef,
|
|
@@ -1034,7 +841,7 @@ function InnerRenderedRectangle({
|
|
|
1034
841
|
)
|
|
1035
842
|
] });
|
|
1036
843
|
}
|
|
1037
|
-
var RenderedRectangle = (0,
|
|
844
|
+
var RenderedRectangle = (0, import_react6.memo)(InnerRenderedRectangle);
|
|
1038
845
|
var showLine2 = (rectangle) => {
|
|
1039
846
|
if ("strokeOpacity" in rectangle.features) {
|
|
1040
847
|
return true;
|
|
@@ -1049,26 +856,26 @@ var showLine2 = (rectangle) => {
|
|
|
1049
856
|
};
|
|
1050
857
|
|
|
1051
858
|
// src/renderables/shape.tsx
|
|
1052
|
-
var
|
|
859
|
+
var import_react7 = require("react");
|
|
1053
860
|
var THREE2 = __toESM(require("three"));
|
|
1054
|
-
var
|
|
1055
|
-
var
|
|
1056
|
-
var
|
|
861
|
+
var import_shallow5 = require("zustand/react/shallow");
|
|
862
|
+
var import_utils5 = require("@vizij/utils");
|
|
863
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1057
864
|
THREE2.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
1058
865
|
function InnerRenderedShape({
|
|
1059
866
|
id,
|
|
1060
867
|
namespace,
|
|
1061
868
|
chain
|
|
1062
869
|
}) {
|
|
1063
|
-
const refGroup = (0,
|
|
1064
|
-
const ref = (0,
|
|
1065
|
-
const shape = useVizijStore((0,
|
|
870
|
+
const refGroup = (0, import_react7.useRef)();
|
|
871
|
+
const ref = (0, import_react7.useRef)();
|
|
872
|
+
const shape = useVizijStore((0, import_shallow5.useShallow)((state) => state.world[id]));
|
|
1066
873
|
const refs = useVizijStore(
|
|
1067
|
-
(0,
|
|
874
|
+
(0, import_shallow5.useShallow)((state) => state.world[id].refs)
|
|
1068
875
|
);
|
|
1069
876
|
const refIsNull = !refs[namespace]?.current;
|
|
1070
|
-
const animatables = useVizijStore((0,
|
|
1071
|
-
const animatableValues = (0,
|
|
877
|
+
const animatables = useVizijStore((0, import_shallow5.useShallow)((state) => state.animatables));
|
|
878
|
+
const animatableValues = (0, import_react7.useMemo)(() => {
|
|
1072
879
|
const av = {};
|
|
1073
880
|
Object.values(shape.features).forEach((feat) => {
|
|
1074
881
|
if (feat.animated) {
|
|
@@ -1078,22 +885,22 @@ function InnerRenderedShape({
|
|
|
1078
885
|
});
|
|
1079
886
|
return av;
|
|
1080
887
|
}, [shape.features, animatables]);
|
|
1081
|
-
const materialName = (0,
|
|
888
|
+
const materialName = (0, import_react7.useMemo)(
|
|
1082
889
|
() => deriveMaterialName(shape, animatableValues),
|
|
1083
890
|
[shape, animatableValues]
|
|
1084
891
|
);
|
|
1085
|
-
const geometry = (0,
|
|
892
|
+
const geometry = (0, import_react7.useMemo)(() => {
|
|
1086
893
|
const cloned = shape.geometry.clone();
|
|
1087
894
|
if (shape.name) {
|
|
1088
895
|
cloned.name = shape.name;
|
|
1089
896
|
}
|
|
1090
897
|
return cloned;
|
|
1091
898
|
}, [shape.geometry, shape.name]);
|
|
1092
|
-
const selectionData = (0,
|
|
899
|
+
const selectionData = (0, import_react7.useMemo)(
|
|
1093
900
|
() => ({ id, namespace, type: "shape" }),
|
|
1094
901
|
[id, namespace]
|
|
1095
902
|
);
|
|
1096
|
-
const userData = (0,
|
|
903
|
+
const userData = (0, import_react7.useMemo)(
|
|
1097
904
|
() => ({
|
|
1098
905
|
gltfExtensions: {
|
|
1099
906
|
RobotData: createStoredRenderable(shape, animatableValues)
|
|
@@ -1102,8 +909,8 @@ function InnerRenderedShape({
|
|
|
1102
909
|
}),
|
|
1103
910
|
[shape, animatableValues, selectionData]
|
|
1104
911
|
);
|
|
1105
|
-
const material = (0,
|
|
1106
|
-
const morphTargetSettings = (0,
|
|
912
|
+
const material = (0, import_react7.useRef)();
|
|
913
|
+
const morphTargetSettings = (0, import_react7.useMemo)(() => {
|
|
1107
914
|
if (shape.morphTargets) {
|
|
1108
915
|
const dictionary = shape.morphTargets.reduce(
|
|
1109
916
|
(acc, target, i) => ({ ...acc, [target]: i }),
|
|
@@ -1113,7 +920,7 @@ function InnerRenderedShape({
|
|
|
1113
920
|
const morphFeatureHandlers = {};
|
|
1114
921
|
shape.morphTargets.forEach((target, i) => {
|
|
1115
922
|
morphFeatureHandlers[target] = (value) => {
|
|
1116
|
-
if (ref.current?.morphTargetInfluences && (0,
|
|
923
|
+
if (ref.current?.morphTargetInfluences && (0, import_utils5.instanceOfRawNumber)(value)) {
|
|
1117
924
|
ref.current.morphTargetInfluences[i] = value;
|
|
1118
925
|
}
|
|
1119
926
|
};
|
|
@@ -1128,14 +935,14 @@ function InnerRenderedShape({
|
|
|
1128
935
|
shape.features,
|
|
1129
936
|
{
|
|
1130
937
|
translation: (pos) => {
|
|
1131
|
-
if (ref.current?.position && (0,
|
|
938
|
+
if (ref.current?.position && (0, import_utils5.instanceOfRawVector3)(pos)) {
|
|
1132
939
|
ref.current.position.set(
|
|
1133
940
|
pos.x,
|
|
1134
941
|
pos.y,
|
|
1135
942
|
pos.z
|
|
1136
943
|
);
|
|
1137
944
|
}
|
|
1138
|
-
if (refGroup.current?.position && (0,
|
|
945
|
+
if (refGroup.current?.position && (0, import_utils5.instanceOfRawVector3)(pos)) {
|
|
1139
946
|
refGroup.current.position.set(
|
|
1140
947
|
pos.x,
|
|
1141
948
|
pos.y,
|
|
@@ -1144,24 +951,24 @@ function InnerRenderedShape({
|
|
|
1144
951
|
}
|
|
1145
952
|
},
|
|
1146
953
|
rotation: (rot) => {
|
|
1147
|
-
if (ref.current?.rotation && (0,
|
|
954
|
+
if (ref.current?.rotation && (0, import_utils5.instanceOfRawEuler)(rot)) {
|
|
1148
955
|
ref.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
1149
956
|
}
|
|
1150
|
-
if (refGroup.current?.rotation && (0,
|
|
957
|
+
if (refGroup.current?.rotation && (0, import_utils5.instanceOfRawEuler)(rot)) {
|
|
1151
958
|
refGroup.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
1152
959
|
}
|
|
1153
960
|
},
|
|
1154
961
|
scale: (scale) => {
|
|
1155
|
-
if (ref.current?.scale && (0,
|
|
962
|
+
if (ref.current?.scale && (0, import_utils5.instanceOfRawVector3)(scale)) {
|
|
1156
963
|
ref.current.scale.set(scale.x, scale.y, scale.z);
|
|
1157
|
-
} else if (ref.current && (0,
|
|
964
|
+
} else if (ref.current && (0, import_utils5.instanceOfRawNumber)(scale)) {
|
|
1158
965
|
ref.current.scale.set(scale, scale, scale);
|
|
1159
966
|
} else if (ref.current) {
|
|
1160
967
|
ref.current.scale.set(1, 1, 1);
|
|
1161
968
|
}
|
|
1162
969
|
},
|
|
1163
970
|
opacity: (op) => {
|
|
1164
|
-
if (material.current?.opacity !== void 0 && (0,
|
|
971
|
+
if (material.current?.opacity !== void 0 && (0, import_utils5.instanceOfRawNumber)(op)) {
|
|
1165
972
|
material.current.opacity = op;
|
|
1166
973
|
if (op < 1) {
|
|
1167
974
|
material.current.transparent = true;
|
|
@@ -1172,21 +979,21 @@ function InnerRenderedShape({
|
|
|
1172
979
|
}
|
|
1173
980
|
},
|
|
1174
981
|
color: (color) => {
|
|
1175
|
-
if ((material.current || void 0)?.color && (0,
|
|
982
|
+
if ((material.current || void 0)?.color && (0, import_utils5.instanceOfRawRGB)(color)) {
|
|
1176
983
|
material.current.color.setRGB(
|
|
1177
984
|
color.r,
|
|
1178
985
|
color.g,
|
|
1179
986
|
color.b
|
|
1180
987
|
);
|
|
1181
988
|
material.current.needsUpdate = true;
|
|
1182
|
-
} else if ((material.current || void 0)?.color && (0,
|
|
989
|
+
} else if ((material.current || void 0)?.color && (0, import_utils5.instanceOfRawVector3)(color)) {
|
|
1183
990
|
material.current.color.setRGB(
|
|
1184
991
|
color.x,
|
|
1185
992
|
color.y,
|
|
1186
993
|
color.z
|
|
1187
994
|
);
|
|
1188
995
|
material.current.needsUpdate = true;
|
|
1189
|
-
} else if (material.current && (0,
|
|
996
|
+
} else if (material.current && (0, import_utils5.instanceOfRawHSL)(color)) {
|
|
1190
997
|
material.current.color.setHSL(
|
|
1191
998
|
color.h,
|
|
1192
999
|
color.s,
|
|
@@ -1198,22 +1005,22 @@ function InnerRenderedShape({
|
|
|
1198
1005
|
},
|
|
1199
1006
|
shape
|
|
1200
1007
|
);
|
|
1201
|
-
const setReference = useVizijStore((0,
|
|
1008
|
+
const setReference = useVizijStore((0, import_shallow5.useShallow)((state) => state.setReference));
|
|
1202
1009
|
const onElementClick = useVizijStore(
|
|
1203
|
-
(0,
|
|
1010
|
+
(0, import_shallow5.useShallow)((state) => state.onElementClick)
|
|
1204
1011
|
);
|
|
1205
1012
|
const setHoveredElement = useVizijStore(
|
|
1206
|
-
(0,
|
|
1013
|
+
(0, import_shallow5.useShallow)((state) => state.setHoveredElement)
|
|
1207
1014
|
);
|
|
1208
|
-
(0,
|
|
1015
|
+
(0, import_react7.useEffect)(() => {
|
|
1209
1016
|
if (ref.current && refIsNull) setReference(shape.id, namespace, ref);
|
|
1210
1017
|
}, [shape.id, namespace, ref, setReference, refIsNull]);
|
|
1211
|
-
(0,
|
|
1018
|
+
(0, import_react7.useEffect)(() => {
|
|
1212
1019
|
if (ref.current) {
|
|
1213
1020
|
ref.current.name = shape.name;
|
|
1214
1021
|
}
|
|
1215
1022
|
}, [shape.name]);
|
|
1216
|
-
(0,
|
|
1023
|
+
(0, import_react7.useEffect)(() => {
|
|
1217
1024
|
if (!material.current) {
|
|
1218
1025
|
return;
|
|
1219
1026
|
}
|
|
@@ -1223,21 +1030,21 @@ function InnerRenderedShape({
|
|
|
1223
1030
|
material.current.name = shape.name;
|
|
1224
1031
|
}
|
|
1225
1032
|
}, [materialName, shape.name]);
|
|
1226
|
-
const handlePointerOver = (0,
|
|
1033
|
+
const handlePointerOver = (0, import_react7.useCallback)(
|
|
1227
1034
|
(event) => {
|
|
1228
1035
|
event.stopPropagation();
|
|
1229
1036
|
setHoveredElement({ id, namespace, type: "shape" });
|
|
1230
1037
|
},
|
|
1231
1038
|
[id, namespace, setHoveredElement]
|
|
1232
1039
|
);
|
|
1233
|
-
const handlePointerOut = (0,
|
|
1040
|
+
const handlePointerOut = (0, import_react7.useCallback)(
|
|
1234
1041
|
(event) => {
|
|
1235
1042
|
event.stopPropagation();
|
|
1236
1043
|
setHoveredElement(null);
|
|
1237
1044
|
},
|
|
1238
1045
|
[setHoveredElement]
|
|
1239
1046
|
);
|
|
1240
|
-
return /* @__PURE__ */ (0,
|
|
1047
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1241
1048
|
"mesh",
|
|
1242
1049
|
{
|
|
1243
1050
|
ref,
|
|
@@ -1255,7 +1062,7 @@ function InnerRenderedShape({
|
|
|
1255
1062
|
onElementClick({ id, type: "shape", namespace }, [...chain, id], e);
|
|
1256
1063
|
},
|
|
1257
1064
|
children: [
|
|
1258
|
-
shape.material === "basic" && /* @__PURE__ */ (0,
|
|
1065
|
+
shape.material === "basic" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1259
1066
|
"meshBasicMaterial",
|
|
1260
1067
|
{
|
|
1261
1068
|
attach: "material",
|
|
@@ -1263,7 +1070,7 @@ function InnerRenderedShape({
|
|
|
1263
1070
|
side: THREE2.DoubleSide
|
|
1264
1071
|
}
|
|
1265
1072
|
),
|
|
1266
|
-
shape.material === "lambert" && /* @__PURE__ */ (0,
|
|
1073
|
+
shape.material === "lambert" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1267
1074
|
"meshLambertMaterial",
|
|
1268
1075
|
{
|
|
1269
1076
|
attach: "material",
|
|
@@ -1271,7 +1078,7 @@ function InnerRenderedShape({
|
|
|
1271
1078
|
side: THREE2.DoubleSide
|
|
1272
1079
|
}
|
|
1273
1080
|
),
|
|
1274
|
-
shape.material === "phong" && /* @__PURE__ */ (0,
|
|
1081
|
+
shape.material === "phong" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1275
1082
|
"meshPhongMaterial",
|
|
1276
1083
|
{
|
|
1277
1084
|
attach: "material",
|
|
@@ -1279,7 +1086,7 @@ function InnerRenderedShape({
|
|
|
1279
1086
|
side: THREE2.DoubleSide
|
|
1280
1087
|
}
|
|
1281
1088
|
),
|
|
1282
|
-
shape.material === "standard" && /* @__PURE__ */ (0,
|
|
1089
|
+
shape.material === "standard" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1283
1090
|
"meshStandardMaterial",
|
|
1284
1091
|
{
|
|
1285
1092
|
attach: "material",
|
|
@@ -1287,7 +1094,7 @@ function InnerRenderedShape({
|
|
|
1287
1094
|
side: THREE2.DoubleSide
|
|
1288
1095
|
}
|
|
1289
1096
|
),
|
|
1290
|
-
shape.material === "normal" && /* @__PURE__ */ (0,
|
|
1097
|
+
shape.material === "normal" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1291
1098
|
"meshNormalMaterial",
|
|
1292
1099
|
{
|
|
1293
1100
|
attach: "material",
|
|
@@ -1295,7 +1102,7 @@ function InnerRenderedShape({
|
|
|
1295
1102
|
side: THREE2.DoubleSide
|
|
1296
1103
|
}
|
|
1297
1104
|
),
|
|
1298
|
-
shape.children?.map((child) => /* @__PURE__ */ (0,
|
|
1105
|
+
shape.children?.map((child) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1299
1106
|
Renderable,
|
|
1300
1107
|
{
|
|
1301
1108
|
id: child,
|
|
@@ -1308,7 +1115,7 @@ function InnerRenderedShape({
|
|
|
1308
1115
|
}
|
|
1309
1116
|
);
|
|
1310
1117
|
}
|
|
1311
|
-
var RenderedShape = (0,
|
|
1118
|
+
var RenderedShape = (0, import_react7.memo)(InnerRenderedShape);
|
|
1312
1119
|
var MATERIAL_FEATURE_KEYS = [
|
|
1313
1120
|
"color",
|
|
1314
1121
|
"opacity",
|
|
@@ -1356,15 +1163,15 @@ function extractMaterialName(name) {
|
|
|
1356
1163
|
}
|
|
1357
1164
|
|
|
1358
1165
|
// src/renderables/renderable.tsx
|
|
1359
|
-
var
|
|
1166
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1360
1167
|
function InnerRenderable({
|
|
1361
1168
|
id,
|
|
1362
1169
|
namespace,
|
|
1363
1170
|
chain
|
|
1364
1171
|
}) {
|
|
1365
|
-
const type = useVizijStore((0,
|
|
1366
|
-
const refs = useVizijStore((0,
|
|
1367
|
-
const resolvedNamespaces = (0,
|
|
1172
|
+
const type = useVizijStore((0, import_shallow6.useShallow)((state) => state.world[id].type));
|
|
1173
|
+
const refs = useVizijStore((0, import_shallow6.useShallow)((state) => state.world[id].refs));
|
|
1174
|
+
const resolvedNamespaces = (0, import_react8.useMemo)(() => {
|
|
1368
1175
|
let namespaces = [namespace];
|
|
1369
1176
|
if (namespace in refs) {
|
|
1370
1177
|
namespaces = [namespace];
|
|
@@ -1376,10 +1183,10 @@ function InnerRenderable({
|
|
|
1376
1183
|
if (resolvedNamespaces.length === 0) {
|
|
1377
1184
|
return null;
|
|
1378
1185
|
}
|
|
1379
|
-
return /* @__PURE__ */ (0,
|
|
1186
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: resolvedNamespaces.map((ns) => {
|
|
1380
1187
|
switch (type) {
|
|
1381
1188
|
case "group":
|
|
1382
|
-
return /* @__PURE__ */ (0,
|
|
1189
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1383
1190
|
RenderedGroup,
|
|
1384
1191
|
{
|
|
1385
1192
|
id,
|
|
@@ -1389,7 +1196,7 @@ function InnerRenderable({
|
|
|
1389
1196
|
`${ns}.${id}`
|
|
1390
1197
|
);
|
|
1391
1198
|
case "ellipse":
|
|
1392
|
-
return /* @__PURE__ */ (0,
|
|
1199
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1393
1200
|
RenderedEllipse,
|
|
1394
1201
|
{
|
|
1395
1202
|
id,
|
|
@@ -1399,7 +1206,7 @@ function InnerRenderable({
|
|
|
1399
1206
|
`${ns}.${id}`
|
|
1400
1207
|
);
|
|
1401
1208
|
case "rectangle":
|
|
1402
|
-
return /* @__PURE__ */ (0,
|
|
1209
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1403
1210
|
RenderedRectangle,
|
|
1404
1211
|
{
|
|
1405
1212
|
id,
|
|
@@ -1409,7 +1216,7 @@ function InnerRenderable({
|
|
|
1409
1216
|
`${ns}.${id}`
|
|
1410
1217
|
);
|
|
1411
1218
|
case "shape":
|
|
1412
|
-
return /* @__PURE__ */ (0,
|
|
1219
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1413
1220
|
RenderedShape,
|
|
1414
1221
|
{
|
|
1415
1222
|
id,
|
|
@@ -1423,17 +1230,17 @@ function InnerRenderable({
|
|
|
1423
1230
|
}
|
|
1424
1231
|
}) });
|
|
1425
1232
|
}
|
|
1426
|
-
var Renderable = (0,
|
|
1233
|
+
var Renderable = (0, import_react8.memo)(InnerRenderable);
|
|
1427
1234
|
|
|
1428
1235
|
// src/store.ts
|
|
1429
1236
|
var import_zustand2 = require("zustand");
|
|
1430
1237
|
var import_middleware = require("zustand/middleware");
|
|
1431
1238
|
var import_immer = require("immer");
|
|
1432
1239
|
var THREE3 = __toESM(require("three"));
|
|
1433
|
-
var
|
|
1240
|
+
var import_utils6 = require("@vizij/utils");
|
|
1434
1241
|
|
|
1435
1242
|
// src/actions/create-new-element.ts
|
|
1436
|
-
var
|
|
1243
|
+
var import_react9 = require("react");
|
|
1437
1244
|
var import_lodash3 = require("lodash");
|
|
1438
1245
|
|
|
1439
1246
|
// src/functions/create-world-element.ts
|
|
@@ -1463,7 +1270,7 @@ function createNewElement(state, type, root = false) {
|
|
|
1463
1270
|
});
|
|
1464
1271
|
if (Object.entries(state.world).length === 0) {
|
|
1465
1272
|
const name = `New-Root`;
|
|
1466
|
-
const refs = { default: (0,
|
|
1273
|
+
const refs = { default: (0, import_react9.createRef)() };
|
|
1467
1274
|
const newElement = createDefaultGroup({
|
|
1468
1275
|
name,
|
|
1469
1276
|
root: true,
|
|
@@ -1481,7 +1288,7 @@ function createNewElement(state, type, root = false) {
|
|
|
1481
1288
|
const name = `New-Body`;
|
|
1482
1289
|
const refs = (0, import_lodash3.mapValues)(
|
|
1483
1290
|
worldRootEntry.refs,
|
|
1484
|
-
() => (0,
|
|
1291
|
+
() => (0, import_react9.createRef)()
|
|
1485
1292
|
);
|
|
1486
1293
|
const newChild = createDefaultGroup({ name, root, refs });
|
|
1487
1294
|
worldRootEntry.children.push(newChild.id);
|
|
@@ -1726,7 +1533,7 @@ var VizijSlice = (set, get) => ({
|
|
|
1726
1533
|
setValue: (id, namespace, value) => {
|
|
1727
1534
|
set(
|
|
1728
1535
|
(0, import_immer.produce)((state) => {
|
|
1729
|
-
const lookupId = (0,
|
|
1536
|
+
const lookupId = (0, import_utils6.getLookup)(namespace, id);
|
|
1730
1537
|
if (typeof value === "function") {
|
|
1731
1538
|
const current = state.values.get(lookupId);
|
|
1732
1539
|
if (current !== void 0) {
|
|
@@ -1873,8 +1680,8 @@ var VizijSlice = (set, get) => ({
|
|
|
1873
1680
|
setSlot: (parentId, parentNamespace, childId, childNamespace) => {
|
|
1874
1681
|
set(
|
|
1875
1682
|
(0, import_immer.produce)((state) => {
|
|
1876
|
-
const parentLookupId = (0,
|
|
1877
|
-
const childLookupId = (0,
|
|
1683
|
+
const parentLookupId = (0, import_utils6.getLookup)(parentNamespace, parentId);
|
|
1684
|
+
const childLookupId = (0, import_utils6.getLookup)(childNamespace, childId);
|
|
1878
1685
|
state.slotConfig[parentLookupId] = childLookupId;
|
|
1879
1686
|
})
|
|
1880
1687
|
);
|
|
@@ -1893,7 +1700,7 @@ var VizijSlice = (set, get) => ({
|
|
|
1893
1700
|
clearSlot: (parentId, parentNamespace) => {
|
|
1894
1701
|
set(
|
|
1895
1702
|
(0, import_immer.produce)((state) => {
|
|
1896
|
-
const parentLookupId = (0,
|
|
1703
|
+
const parentLookupId = (0, import_utils6.getLookup)(parentNamespace, parentId);
|
|
1897
1704
|
delete state.slotConfig[parentLookupId];
|
|
1898
1705
|
})
|
|
1899
1706
|
);
|
|
@@ -1943,7 +1750,7 @@ var createVizijStore = (initial) => (0, import_zustand2.create)()(
|
|
|
1943
1750
|
);
|
|
1944
1751
|
|
|
1945
1752
|
// src/vizij.tsx
|
|
1946
|
-
var
|
|
1753
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1947
1754
|
import_three.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
1948
1755
|
function Vizij({
|
|
1949
1756
|
style,
|
|
@@ -1953,16 +1760,21 @@ function Vizij({
|
|
|
1953
1760
|
showSafeArea = false,
|
|
1954
1761
|
onPointerMissed
|
|
1955
1762
|
}) {
|
|
1956
|
-
const ctx = (0,
|
|
1763
|
+
const ctx = (0, import_react10.useContext)(VizijContext);
|
|
1957
1764
|
if (ctx) {
|
|
1958
|
-
return /* @__PURE__ */ (0,
|
|
1765
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1959
1766
|
import_fiber.Canvas,
|
|
1960
1767
|
{
|
|
1961
1768
|
shadows: false,
|
|
1962
1769
|
style,
|
|
1963
1770
|
className,
|
|
1964
1771
|
onPointerMissed,
|
|
1965
|
-
|
|
1772
|
+
gl: {
|
|
1773
|
+
outputColorSpace: import_three.SRGBColorSpace,
|
|
1774
|
+
toneMapping: import_three.NoToneMapping,
|
|
1775
|
+
antialias: true
|
|
1776
|
+
},
|
|
1777
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1966
1778
|
MemoizedInnerVizij,
|
|
1967
1779
|
{
|
|
1968
1780
|
rootId,
|
|
@@ -1973,13 +1785,18 @@ function Vizij({
|
|
|
1973
1785
|
}
|
|
1974
1786
|
);
|
|
1975
1787
|
} else {
|
|
1976
|
-
return /* @__PURE__ */ (0,
|
|
1788
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(VizijContext.Provider, { value: useDefaultVizijStore, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1977
1789
|
import_fiber.Canvas,
|
|
1978
1790
|
{
|
|
1979
1791
|
style,
|
|
1980
1792
|
className,
|
|
1981
1793
|
onPointerMissed,
|
|
1982
|
-
|
|
1794
|
+
gl: {
|
|
1795
|
+
outputColorSpace: import_three.SRGBColorSpace,
|
|
1796
|
+
toneMapping: import_three.NoToneMapping,
|
|
1797
|
+
antialias: true
|
|
1798
|
+
},
|
|
1799
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1983
1800
|
MemoizedInnerVizij,
|
|
1984
1801
|
{
|
|
1985
1802
|
rootId,
|
|
@@ -2001,9 +1818,9 @@ function InnerVizij({
|
|
|
2001
1818
|
width: container.width * container.resolution,
|
|
2002
1819
|
height: container.height * container.resolution
|
|
2003
1820
|
} : void 0;
|
|
2004
|
-
return /* @__PURE__ */ (0,
|
|
2005
|
-
/* @__PURE__ */ (0,
|
|
2006
|
-
/* @__PURE__ */ (0,
|
|
1821
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1822
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ambientLight", { intensity: Math.PI / 2 }),
|
|
1823
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2007
1824
|
import_drei3.OrthographicCamera,
|
|
2008
1825
|
{
|
|
2009
1826
|
makeDefault: true,
|
|
@@ -2012,7 +1829,7 @@ function InnerVizij({
|
|
|
2012
1829
|
far: 101
|
|
2013
1830
|
}
|
|
2014
1831
|
),
|
|
2015
|
-
/* @__PURE__ */ (0,
|
|
1832
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react10.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2016
1833
|
World,
|
|
2017
1834
|
{
|
|
2018
1835
|
rootId,
|
|
@@ -2020,17 +1837,17 @@ function InnerVizij({
|
|
|
2020
1837
|
parentSizing: sceneParentSizing
|
|
2021
1838
|
}
|
|
2022
1839
|
) }),
|
|
2023
|
-
showSafeArea && /* @__PURE__ */ (0,
|
|
1840
|
+
showSafeArea && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SafeAreaRenderer, { rootId })
|
|
2024
1841
|
] });
|
|
2025
1842
|
}
|
|
2026
|
-
var MemoizedInnerVizij = (0,
|
|
1843
|
+
var MemoizedInnerVizij = (0, import_react10.memo)(InnerVizij);
|
|
2027
1844
|
function InnerWorld({
|
|
2028
1845
|
rootId,
|
|
2029
1846
|
namespace = "default",
|
|
2030
1847
|
parentSizing
|
|
2031
1848
|
}) {
|
|
2032
1849
|
const [present, rootBounds] = useVizijStore(
|
|
2033
|
-
(0,
|
|
1850
|
+
(0, import_shallow7.useShallow)((state) => {
|
|
2034
1851
|
const group = state.world[rootId];
|
|
2035
1852
|
const bounds = group?.rootBounds ?? defaultRootBounds;
|
|
2036
1853
|
return [group !== void 0, bounds];
|
|
@@ -2040,7 +1857,7 @@ function InnerWorld({
|
|
|
2040
1857
|
camera: state.camera,
|
|
2041
1858
|
size: state.size
|
|
2042
1859
|
}));
|
|
2043
|
-
(0,
|
|
1860
|
+
(0, import_react10.useEffect)(() => {
|
|
2044
1861
|
const width = rootBounds.size.x;
|
|
2045
1862
|
const height = rootBounds.size.y;
|
|
2046
1863
|
if (camera && parentSizing === void 0 && camera.isOrthographicCamera) {
|
|
@@ -2068,9 +1885,9 @@ function InnerWorld({
|
|
|
2068
1885
|
camera.updateProjectionMatrix();
|
|
2069
1886
|
}
|
|
2070
1887
|
}, [rootBounds, camera, parentSizing, size]);
|
|
2071
|
-
return /* @__PURE__ */ (0,
|
|
2072
|
-
present && /* @__PURE__ */ (0,
|
|
2073
|
-
!present && /* @__PURE__ */ (0,
|
|
1888
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_error_boundary.ErrorBoundary, { fallback: null, children: [
|
|
1889
|
+
present && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Renderable, { id: rootId, namespace, chain: [] }),
|
|
1890
|
+
!present && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2074
1891
|
import_drei3.Text,
|
|
2075
1892
|
{
|
|
2076
1893
|
position: [0, 0, 0],
|
|
@@ -2083,7 +1900,7 @@ function InnerWorld({
|
|
|
2083
1900
|
)
|
|
2084
1901
|
] });
|
|
2085
1902
|
}
|
|
2086
|
-
var World = (0,
|
|
1903
|
+
var World = (0, import_react10.memo)(InnerWorld);
|
|
2087
1904
|
function SafeAreaRenderer({ rootId }) {
|
|
2088
1905
|
const rootBounds = useVizijStore((state) => {
|
|
2089
1906
|
const group = state.world[rootId];
|
|
@@ -2093,7 +1910,7 @@ function SafeAreaRenderer({ rootId }) {
|
|
|
2093
1910
|
const right = rootBounds.center.x + rootBounds.size.x / 2;
|
|
2094
1911
|
const top = rootBounds.center.y + rootBounds.size.y / 2;
|
|
2095
1912
|
const bottom = rootBounds.center.y - rootBounds.size.y / 2;
|
|
2096
|
-
return /* @__PURE__ */ (0,
|
|
1913
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2097
1914
|
import_drei3.Line,
|
|
2098
1915
|
{
|
|
2099
1916
|
points: [
|
|
@@ -2124,11 +1941,11 @@ var ShapeMaterial = /* @__PURE__ */ ((ShapeMaterial2) => {
|
|
|
2124
1941
|
})(ShapeMaterial || {});
|
|
2125
1942
|
|
|
2126
1943
|
// src/hooks/use-vizij-store-subscription.ts
|
|
2127
|
-
var
|
|
1944
|
+
var import_react11 = require("react");
|
|
2128
1945
|
function useVizijStoreSubscription(selector, listener) {
|
|
2129
|
-
const store = (0,
|
|
1946
|
+
const store = (0, import_react11.useContext)(VizijContext);
|
|
2130
1947
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2131
|
-
(0,
|
|
1948
|
+
(0, import_react11.useEffect)(() => {
|
|
2132
1949
|
const initialValue = selector(store.getState());
|
|
2133
1950
|
listener(initialValue);
|
|
2134
1951
|
return store.subscribe(selector, listener);
|
|
@@ -2136,17 +1953,17 @@ function useVizijStoreSubscription(selector, listener) {
|
|
|
2136
1953
|
}
|
|
2137
1954
|
|
|
2138
1955
|
// src/hooks/use-vizij-store-setter.ts
|
|
2139
|
-
var
|
|
1956
|
+
var import_react12 = require("react");
|
|
2140
1957
|
function useVizijStoreSetter() {
|
|
2141
|
-
const store = (0,
|
|
1958
|
+
const store = (0, import_react12.useContext)(VizijContext);
|
|
2142
1959
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2143
1960
|
return store.setState;
|
|
2144
1961
|
}
|
|
2145
1962
|
|
|
2146
1963
|
// src/hooks/use-vizij-store-getter.ts
|
|
2147
|
-
var
|
|
1964
|
+
var import_react13 = require("react");
|
|
2148
1965
|
function useVizijStoreGetter() {
|
|
2149
|
-
const store = (0,
|
|
1966
|
+
const store = (0, import_react13.useContext)(VizijContext);
|
|
2150
1967
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2151
1968
|
return store.getState;
|
|
2152
1969
|
}
|
|
@@ -2156,7 +1973,7 @@ var THREE5 = __toESM(require("three"));
|
|
|
2156
1973
|
var import_three_stdlib = require("three-stdlib");
|
|
2157
1974
|
|
|
2158
1975
|
// src/functions/gltf-loading/traverse-three.ts
|
|
2159
|
-
var
|
|
1976
|
+
var import_react15 = require("react");
|
|
2160
1977
|
var THREE4 = __toESM(require("three"));
|
|
2161
1978
|
|
|
2162
1979
|
// src/functions/gltf-loading/map-features.ts
|
|
@@ -2188,9 +2005,9 @@ var import_three4 = require("three");
|
|
|
2188
2005
|
var import_three3 = require("three");
|
|
2189
2006
|
|
|
2190
2007
|
// src/functions/util.ts
|
|
2191
|
-
var
|
|
2008
|
+
var import_react14 = require("react");
|
|
2192
2009
|
function namespaceArrayToRefs(namespaces) {
|
|
2193
|
-
return namespaces.reduce((acc, ns) => ({ ...acc, [ns]: (0,
|
|
2010
|
+
return namespaces.reduce((acc, ns) => ({ ...acc, [ns]: (0, import_react14.createRef)() }), {});
|
|
2194
2011
|
}
|
|
2195
2012
|
|
|
2196
2013
|
// src/functions/gltf-loading/import-mesh.ts
|
|
@@ -2539,7 +2356,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2539
2356
|
loadedData = {
|
|
2540
2357
|
...data,
|
|
2541
2358
|
refs: namespaces.reduce(
|
|
2542
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2359
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2543
2360
|
{}
|
|
2544
2361
|
)
|
|
2545
2362
|
};
|
|
@@ -2554,7 +2371,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2554
2371
|
...data,
|
|
2555
2372
|
geometry: child.geometry,
|
|
2556
2373
|
refs: namespaces.reduce(
|
|
2557
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2374
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2558
2375
|
{}
|
|
2559
2376
|
)
|
|
2560
2377
|
};
|
|
@@ -2568,7 +2385,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2568
2385
|
loadedData = {
|
|
2569
2386
|
...data,
|
|
2570
2387
|
refs: namespaces.reduce(
|
|
2571
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2388
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2572
2389
|
{}
|
|
2573
2390
|
)
|
|
2574
2391
|
};
|
|
@@ -2582,7 +2399,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2582
2399
|
loadedData = {
|
|
2583
2400
|
...data,
|
|
2584
2401
|
refs: namespaces.reduce(
|
|
2585
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2402
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2586
2403
|
{}
|
|
2587
2404
|
)
|
|
2588
2405
|
};
|
|
@@ -2867,6 +2684,375 @@ function applyVizijBundle(object, bundle) {
|
|
|
2867
2684
|
};
|
|
2868
2685
|
}
|
|
2869
2686
|
|
|
2687
|
+
// src/functions/gltf-loading/extract-animations.ts
|
|
2688
|
+
var CHANNEL_PATH_TO_TRACK_PROPERTY = {
|
|
2689
|
+
translation: "position",
|
|
2690
|
+
rotation: "quaternion",
|
|
2691
|
+
scale: "scale",
|
|
2692
|
+
weights: "morphTargetInfluences"
|
|
2693
|
+
};
|
|
2694
|
+
function isPlainObject(value) {
|
|
2695
|
+
return Boolean(
|
|
2696
|
+
value && typeof value === "object" && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]"
|
|
2697
|
+
);
|
|
2698
|
+
}
|
|
2699
|
+
function clonePlainObject(value) {
|
|
2700
|
+
if (!value) {
|
|
2701
|
+
return void 0;
|
|
2702
|
+
}
|
|
2703
|
+
return JSON.parse(JSON.stringify(value));
|
|
2704
|
+
}
|
|
2705
|
+
function inferValueSize(valueType) {
|
|
2706
|
+
switch (valueType) {
|
|
2707
|
+
case "boolean":
|
|
2708
|
+
case "number":
|
|
2709
|
+
case "string":
|
|
2710
|
+
return 1;
|
|
2711
|
+
case "vector2":
|
|
2712
|
+
return 2;
|
|
2713
|
+
case "vector3":
|
|
2714
|
+
case "euler":
|
|
2715
|
+
case "rgb":
|
|
2716
|
+
case "hsl":
|
|
2717
|
+
return 3;
|
|
2718
|
+
case "vector4":
|
|
2719
|
+
case "quaternion":
|
|
2720
|
+
return 4;
|
|
2721
|
+
default:
|
|
2722
|
+
return 1;
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
function componentNameToIndex(component) {
|
|
2726
|
+
if (!component || typeof component !== "string") {
|
|
2727
|
+
return void 0;
|
|
2728
|
+
}
|
|
2729
|
+
const normalized = component.trim().toLowerCase();
|
|
2730
|
+
if (normalized.length === 0) {
|
|
2731
|
+
return void 0;
|
|
2732
|
+
}
|
|
2733
|
+
const componentOrder = {
|
|
2734
|
+
x: 0,
|
|
2735
|
+
y: 1,
|
|
2736
|
+
z: 2,
|
|
2737
|
+
w: 3,
|
|
2738
|
+
r: 0,
|
|
2739
|
+
g: 1,
|
|
2740
|
+
b: 2,
|
|
2741
|
+
a: 3,
|
|
2742
|
+
u: 0,
|
|
2743
|
+
v: 1
|
|
2744
|
+
};
|
|
2745
|
+
return componentOrder[normalized];
|
|
2746
|
+
}
|
|
2747
|
+
function readComponentInfo(target) {
|
|
2748
|
+
if (!target || typeof target !== "object") {
|
|
2749
|
+
return {};
|
|
2750
|
+
}
|
|
2751
|
+
const sources = [];
|
|
2752
|
+
const record = target;
|
|
2753
|
+
const extensions = record.extensions;
|
|
2754
|
+
if (extensions && typeof extensions === "object") {
|
|
2755
|
+
const vizijChannel = extensions.VizijChannel;
|
|
2756
|
+
if (isPlainObject(vizijChannel)) {
|
|
2757
|
+
sources.push(vizijChannel);
|
|
2758
|
+
}
|
|
2759
|
+
const robotChannel = extensions.RobotChannel;
|
|
2760
|
+
if (isPlainObject(robotChannel)) {
|
|
2761
|
+
sources.push(robotChannel);
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
const extras = record.extras;
|
|
2765
|
+
if (isPlainObject(extras)) {
|
|
2766
|
+
sources.push(extras);
|
|
2767
|
+
}
|
|
2768
|
+
let component;
|
|
2769
|
+
let componentIndex;
|
|
2770
|
+
for (const source of sources) {
|
|
2771
|
+
if (!isPlainObject(source)) {
|
|
2772
|
+
continue;
|
|
2773
|
+
}
|
|
2774
|
+
if (typeof source.component === "string" && !component) {
|
|
2775
|
+
component = source.component;
|
|
2776
|
+
}
|
|
2777
|
+
if (typeof source.axis === "string" && !component) {
|
|
2778
|
+
component = source.axis;
|
|
2779
|
+
}
|
|
2780
|
+
if (typeof source.channel === "string" && !component) {
|
|
2781
|
+
component = source.channel;
|
|
2782
|
+
}
|
|
2783
|
+
if (Object.prototype.hasOwnProperty.call(source, "componentIndex") && componentIndex == null) {
|
|
2784
|
+
const value = source.componentIndex;
|
|
2785
|
+
if (typeof value === "number") {
|
|
2786
|
+
componentIndex = value;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
if (Object.prototype.hasOwnProperty.call(source, "axisIndex") && componentIndex == null) {
|
|
2790
|
+
const value = source.axisIndex;
|
|
2791
|
+
if (typeof value === "number") {
|
|
2792
|
+
componentIndex = value;
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
if (componentIndex == null) {
|
|
2797
|
+
componentIndex = componentNameToIndex(component);
|
|
2798
|
+
}
|
|
2799
|
+
return { component, componentIndex };
|
|
2800
|
+
}
|
|
2801
|
+
function resolveRobotNodeIndex(parserJson) {
|
|
2802
|
+
const indexMap = /* @__PURE__ */ new Map();
|
|
2803
|
+
if (!parserJson || typeof parserJson !== "object") {
|
|
2804
|
+
return indexMap;
|
|
2805
|
+
}
|
|
2806
|
+
const json = parserJson;
|
|
2807
|
+
const nodes = Array.isArray(json.nodes) ? json.nodes : [];
|
|
2808
|
+
nodes.forEach((node, nodeIndex) => {
|
|
2809
|
+
if (!node || typeof node !== "object") {
|
|
2810
|
+
return;
|
|
2811
|
+
}
|
|
2812
|
+
const extensions = node.extensions;
|
|
2813
|
+
if (!extensions || typeof extensions !== "object") {
|
|
2814
|
+
return;
|
|
2815
|
+
}
|
|
2816
|
+
const robotData = extensions.RobotData;
|
|
2817
|
+
if (!robotData || typeof robotData !== "object") {
|
|
2818
|
+
return;
|
|
2819
|
+
}
|
|
2820
|
+
const renderableId = typeof robotData.id === "string" ? robotData.id : void 0;
|
|
2821
|
+
if (!renderableId) {
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
const nodeName = typeof node.name === "string" && node.name.length > 0 ? node.name : void 0;
|
|
2825
|
+
const features = {};
|
|
2826
|
+
const robotFeatures = robotData.features;
|
|
2827
|
+
if (robotFeatures && typeof robotFeatures === "object") {
|
|
2828
|
+
Object.entries(robotFeatures).forEach(
|
|
2829
|
+
([featureKey, featureValue]) => {
|
|
2830
|
+
if (!featureValue || typeof featureValue !== "object" || !featureValue.animated) {
|
|
2831
|
+
return;
|
|
2832
|
+
}
|
|
2833
|
+
const value = featureValue.value;
|
|
2834
|
+
const componentId = value && typeof value === "object" && typeof value.id === "string" ? value.id : void 0;
|
|
2835
|
+
if (!componentId) {
|
|
2836
|
+
return;
|
|
2837
|
+
}
|
|
2838
|
+
const valueType = value && typeof value === "object" && typeof value.type === "string" ? value.type : void 0;
|
|
2839
|
+
features[featureKey] = {
|
|
2840
|
+
feature: featureKey,
|
|
2841
|
+
componentId,
|
|
2842
|
+
valueType
|
|
2843
|
+
};
|
|
2844
|
+
}
|
|
2845
|
+
);
|
|
2846
|
+
}
|
|
2847
|
+
indexMap.set(nodeIndex, {
|
|
2848
|
+
renderableId,
|
|
2849
|
+
nodeName,
|
|
2850
|
+
features
|
|
2851
|
+
});
|
|
2852
|
+
});
|
|
2853
|
+
return indexMap;
|
|
2854
|
+
}
|
|
2855
|
+
function mapChannelPathToProperty(path) {
|
|
2856
|
+
if (typeof path !== "string") {
|
|
2857
|
+
return void 0;
|
|
2858
|
+
}
|
|
2859
|
+
return CHANNEL_PATH_TO_TRACK_PROPERTY[path] ?? path;
|
|
2860
|
+
}
|
|
2861
|
+
function resolveFeatureKey(channelTarget) {
|
|
2862
|
+
if (!channelTarget || typeof channelTarget !== "object") {
|
|
2863
|
+
return void 0;
|
|
2864
|
+
}
|
|
2865
|
+
const target = channelTarget;
|
|
2866
|
+
const extensions = target.extensions;
|
|
2867
|
+
if (extensions && typeof extensions === "object") {
|
|
2868
|
+
const vizij = extensions.VizijChannel;
|
|
2869
|
+
if (isPlainObject(vizij)) {
|
|
2870
|
+
const feature = vizij.feature;
|
|
2871
|
+
if (typeof feature === "string") {
|
|
2872
|
+
return feature;
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
const robot = extensions.RobotChannel;
|
|
2876
|
+
if (isPlainObject(robot)) {
|
|
2877
|
+
const feature = robot.feature;
|
|
2878
|
+
if (typeof feature === "string") {
|
|
2879
|
+
return feature;
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
const extras = target.extras;
|
|
2884
|
+
if (isPlainObject(extras)) {
|
|
2885
|
+
const feature = extras.feature;
|
|
2886
|
+
if (typeof feature === "string") {
|
|
2887
|
+
return feature;
|
|
2888
|
+
}
|
|
2889
|
+
const channel = extras.channel;
|
|
2890
|
+
if (typeof channel === "string") {
|
|
2891
|
+
return channel;
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
const path = target.path;
|
|
2895
|
+
return typeof path === "string" ? path : void 0;
|
|
2896
|
+
}
|
|
2897
|
+
function resolveTrackForChannel(clip, channelIndex, expectedProperty, nodeName) {
|
|
2898
|
+
if (!clip) {
|
|
2899
|
+
return void 0;
|
|
2900
|
+
}
|
|
2901
|
+
const orderedTrack = clip.tracks[channelIndex];
|
|
2902
|
+
if (orderedTrack) {
|
|
2903
|
+
return orderedTrack;
|
|
2904
|
+
}
|
|
2905
|
+
if (!expectedProperty) {
|
|
2906
|
+
return void 0;
|
|
2907
|
+
}
|
|
2908
|
+
const property = expectedProperty;
|
|
2909
|
+
const matches = (track) => {
|
|
2910
|
+
const name = track?.name ?? "";
|
|
2911
|
+
if (!name) {
|
|
2912
|
+
return false;
|
|
2913
|
+
}
|
|
2914
|
+
if (nodeName && name === `${nodeName}.${property}`) {
|
|
2915
|
+
return true;
|
|
2916
|
+
}
|
|
2917
|
+
if (nodeName && name.startsWith(`${nodeName}.`) && name.endsWith(property)) {
|
|
2918
|
+
return true;
|
|
2919
|
+
}
|
|
2920
|
+
if (!nodeName && name.endsWith(property)) {
|
|
2921
|
+
return true;
|
|
2922
|
+
}
|
|
2923
|
+
return false;
|
|
2924
|
+
};
|
|
2925
|
+
return clip.tracks.find(matches);
|
|
2926
|
+
}
|
|
2927
|
+
function toNumberArray(arrayLike) {
|
|
2928
|
+
if (!arrayLike) {
|
|
2929
|
+
return [];
|
|
2930
|
+
}
|
|
2931
|
+
return Array.from(arrayLike, (value) => Number(value));
|
|
2932
|
+
}
|
|
2933
|
+
function resolveClipDuration(clip, tracks) {
|
|
2934
|
+
if (clip && Number.isFinite(clip.duration) && clip.duration >= 0) {
|
|
2935
|
+
return clip.duration;
|
|
2936
|
+
}
|
|
2937
|
+
let maxTime = 0;
|
|
2938
|
+
tracks.forEach((track) => {
|
|
2939
|
+
if (!track.times.length) {
|
|
2940
|
+
return;
|
|
2941
|
+
}
|
|
2942
|
+
const lastTime = track.times[track.times.length - 1] ?? 0;
|
|
2943
|
+
if (lastTime > maxTime) {
|
|
2944
|
+
maxTime = lastTime;
|
|
2945
|
+
}
|
|
2946
|
+
});
|
|
2947
|
+
return maxTime;
|
|
2948
|
+
}
|
|
2949
|
+
function resolveClipId(animation, clip, index) {
|
|
2950
|
+
if (typeof animation.name === "string" && animation.name.length > 0) {
|
|
2951
|
+
return animation.name;
|
|
2952
|
+
}
|
|
2953
|
+
if (clip?.name && clip.name.length > 0) {
|
|
2954
|
+
return clip.name;
|
|
2955
|
+
}
|
|
2956
|
+
return `gltf-animation-${index}`;
|
|
2957
|
+
}
|
|
2958
|
+
function extractVizijAnimations(parserJson, clips) {
|
|
2959
|
+
const animations = [];
|
|
2960
|
+
if (!parserJson || typeof parserJson !== "object") {
|
|
2961
|
+
return animations;
|
|
2962
|
+
}
|
|
2963
|
+
const robotNodeIndex = resolveRobotNodeIndex(parserJson);
|
|
2964
|
+
if (robotNodeIndex.size === 0) {
|
|
2965
|
+
return animations;
|
|
2966
|
+
}
|
|
2967
|
+
const json = parserJson;
|
|
2968
|
+
const gltfAnimations = Array.isArray(json.animations) ? json.animations : [];
|
|
2969
|
+
if (gltfAnimations.length === 0) {
|
|
2970
|
+
return animations;
|
|
2971
|
+
}
|
|
2972
|
+
gltfAnimations.forEach((animation, animationIndex) => {
|
|
2973
|
+
if (!animation || typeof animation !== "object") {
|
|
2974
|
+
return;
|
|
2975
|
+
}
|
|
2976
|
+
const animationRecord = animation;
|
|
2977
|
+
const channels = Array.isArray(animationRecord.channels) ? animationRecord.channels : [];
|
|
2978
|
+
if (channels.length === 0) {
|
|
2979
|
+
return;
|
|
2980
|
+
}
|
|
2981
|
+
const samplers = Array.isArray(animationRecord.samplers) ? animationRecord.samplers : [];
|
|
2982
|
+
const clip = Array.isArray(clips) ? clips[animationIndex] : void 0;
|
|
2983
|
+
const trackData = [];
|
|
2984
|
+
channels.forEach((channel, channelIndex) => {
|
|
2985
|
+
if (!channel || typeof channel !== "object") {
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2988
|
+
const channelRecord = channel;
|
|
2989
|
+
const target = channelRecord.target;
|
|
2990
|
+
const nodeIndex = target && typeof target === "object" && typeof target.node === "number" ? target.node : void 0;
|
|
2991
|
+
if (nodeIndex == null || !robotNodeIndex.has(nodeIndex)) {
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
const robotNode = robotNodeIndex.get(nodeIndex);
|
|
2995
|
+
const featureKey = resolveFeatureKey(target);
|
|
2996
|
+
if (!featureKey) {
|
|
2997
|
+
return;
|
|
2998
|
+
}
|
|
2999
|
+
const featureInfo = robotNode.features[featureKey];
|
|
3000
|
+
if (!featureInfo) {
|
|
3001
|
+
return;
|
|
3002
|
+
}
|
|
3003
|
+
const propertyName = mapChannelPathToProperty(
|
|
3004
|
+
target && typeof target === "object" ? target.path : void 0
|
|
3005
|
+
);
|
|
3006
|
+
const track = resolveTrackForChannel(
|
|
3007
|
+
clip,
|
|
3008
|
+
channelIndex,
|
|
3009
|
+
propertyName,
|
|
3010
|
+
robotNode.nodeName
|
|
3011
|
+
);
|
|
3012
|
+
if (!track) {
|
|
3013
|
+
return;
|
|
3014
|
+
}
|
|
3015
|
+
const samplerIndex = typeof channelRecord.sampler === "number" ? channelRecord.sampler : -1;
|
|
3016
|
+
const sampler = samplerIndex >= 0 && samplerIndex < samplers.length ? samplers[samplerIndex] : void 0;
|
|
3017
|
+
const interpolation = sampler && typeof sampler.interpolation === "string" ? sampler.interpolation : void 0;
|
|
3018
|
+
let valueSize = typeof track.getValueSize === "function" ? track.getValueSize() : inferValueSize(featureInfo.valueType);
|
|
3019
|
+
if (!Number.isFinite(valueSize) || valueSize <= 0) {
|
|
3020
|
+
valueSize = inferValueSize(featureInfo.valueType);
|
|
3021
|
+
}
|
|
3022
|
+
const { component, componentIndex } = readComponentInfo(target);
|
|
3023
|
+
trackData.push({
|
|
3024
|
+
componentId: featureInfo.componentId,
|
|
3025
|
+
feature: featureInfo.feature,
|
|
3026
|
+
renderableId: robotNode.renderableId,
|
|
3027
|
+
nodeIndex,
|
|
3028
|
+
nodeName: robotNode.nodeName,
|
|
3029
|
+
path: target && typeof target === "object" && typeof target.path === "string" ? target.path : void 0,
|
|
3030
|
+
component,
|
|
3031
|
+
componentIndex,
|
|
3032
|
+
valueType: featureInfo.valueType,
|
|
3033
|
+
valueSize,
|
|
3034
|
+
interpolation,
|
|
3035
|
+
times: toNumberArray(track.times),
|
|
3036
|
+
values: toNumberArray(track.values)
|
|
3037
|
+
});
|
|
3038
|
+
});
|
|
3039
|
+
if (trackData.length === 0) {
|
|
3040
|
+
return;
|
|
3041
|
+
}
|
|
3042
|
+
animations.push({
|
|
3043
|
+
id: resolveClipId(animationRecord, clip, animationIndex),
|
|
3044
|
+
name: typeof animationRecord.name === "string" && animationRecord.name.length > 0 ? animationRecord.name : clip?.name,
|
|
3045
|
+
duration: resolveClipDuration(clip, trackData),
|
|
3046
|
+
index: animationIndex,
|
|
3047
|
+
metadata: clonePlainObject(
|
|
3048
|
+
animationRecord.extras
|
|
3049
|
+
),
|
|
3050
|
+
tracks: trackData
|
|
3051
|
+
});
|
|
3052
|
+
});
|
|
3053
|
+
return animations;
|
|
3054
|
+
}
|
|
3055
|
+
|
|
2870
3056
|
// src/functions/load-gltf.ts
|
|
2871
3057
|
THREE5.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
2872
3058
|
var EmptyModelError = class extends Error {
|
|
@@ -2885,9 +3071,10 @@ async function loadGLTF(url, namespaces, aggressiveImport = false, rootBounds) {
|
|
|
2885
3071
|
actualizedNamespaces,
|
|
2886
3072
|
aggressiveImport,
|
|
2887
3073
|
rootBounds,
|
|
2888
|
-
modelData?.parser?.json
|
|
3074
|
+
modelData?.parser?.json,
|
|
3075
|
+
modelData.animations
|
|
2889
3076
|
);
|
|
2890
|
-
return [asset.world, asset.animatables];
|
|
3077
|
+
return [asset.world, asset.animatables, asset.animations];
|
|
2891
3078
|
}
|
|
2892
3079
|
async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, rootBounds) {
|
|
2893
3080
|
const actualizedNamespaces = namespaces.length > 0 ? namespaces : ["default"];
|
|
@@ -2900,7 +3087,7 @@ async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, root
|
|
|
2900
3087
|
aggressiveImport,
|
|
2901
3088
|
rootBounds
|
|
2902
3089
|
);
|
|
2903
|
-
return [asset.world, asset.animatables];
|
|
3090
|
+
return [asset.world, asset.animatables, asset.animations];
|
|
2904
3091
|
} finally {
|
|
2905
3092
|
URL.revokeObjectURL(objectUrl);
|
|
2906
3093
|
}
|
|
@@ -2919,9 +3106,10 @@ async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, root
|
|
|
2919
3106
|
actualizedNamespaces,
|
|
2920
3107
|
aggressiveImport,
|
|
2921
3108
|
rootBounds,
|
|
2922
|
-
gltf?.parser?.json
|
|
3109
|
+
gltf?.parser?.json,
|
|
3110
|
+
gltf.animations
|
|
2923
3111
|
);
|
|
2924
|
-
resolve([asset.world, asset.animatables]);
|
|
3112
|
+
resolve([asset.world, asset.animatables, asset.animations]);
|
|
2925
3113
|
} catch (error) {
|
|
2926
3114
|
if (error instanceof Error) {
|
|
2927
3115
|
reject(error);
|
|
@@ -2936,7 +3124,7 @@ async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, root
|
|
|
2936
3124
|
);
|
|
2937
3125
|
});
|
|
2938
3126
|
}
|
|
2939
|
-
function parseScene(scene, namespaces, aggressiveImport, rootBounds, parserJson) {
|
|
3127
|
+
function parseScene(scene, namespaces, aggressiveImport, rootBounds, parserJson, clips) {
|
|
2940
3128
|
const [world, animatables] = traverseThree(
|
|
2941
3129
|
scene,
|
|
2942
3130
|
namespaces,
|
|
@@ -2944,7 +3132,8 @@ function parseScene(scene, namespaces, aggressiveImport, rootBounds, parserJson)
|
|
|
2944
3132
|
rootBounds
|
|
2945
3133
|
);
|
|
2946
3134
|
const bundle = extractVizijBundle(scene, parserJson);
|
|
2947
|
-
|
|
3135
|
+
const animations = extractVizijAnimations(parserJson, clips);
|
|
3136
|
+
return { world, animatables, bundle, animations };
|
|
2948
3137
|
}
|
|
2949
3138
|
async function loadGLTFWithBundle(url, namespaces, aggressiveImport = false, rootBounds) {
|
|
2950
3139
|
const modelLoader = new import_three_stdlib.GLTFLoader();
|
|
@@ -2956,7 +3145,8 @@ async function loadGLTFWithBundle(url, namespaces, aggressiveImport = false, roo
|
|
|
2956
3145
|
actualizedNamespaces,
|
|
2957
3146
|
aggressiveImport,
|
|
2958
3147
|
rootBounds,
|
|
2959
|
-
modelData?.parser?.json
|
|
3148
|
+
modelData?.parser?.json,
|
|
3149
|
+
modelData.animations
|
|
2960
3150
|
);
|
|
2961
3151
|
}
|
|
2962
3152
|
async function loadGLTFFromBlobWithBundle(blob, namespaces, aggressiveImport = false, rootBounds) {
|
|
@@ -2988,7 +3178,8 @@ async function loadGLTFFromBlobWithBundle(blob, namespaces, aggressiveImport = f
|
|
|
2988
3178
|
actualizedNamespaces,
|
|
2989
3179
|
aggressiveImport,
|
|
2990
3180
|
rootBounds,
|
|
2991
|
-
gltf?.parser?.json
|
|
3181
|
+
gltf?.parser?.json,
|
|
3182
|
+
gltf.animations
|
|
2992
3183
|
);
|
|
2993
3184
|
resolve(asset);
|
|
2994
3185
|
} catch (error) {
|
|
@@ -3098,7 +3289,6 @@ function exportScene(data, fileNameOrOptions = "scene.glb") {
|
|
|
3098
3289
|
}
|
|
3099
3290
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3100
3291
|
0 && (module.exports = {
|
|
3101
|
-
Controller,
|
|
3102
3292
|
EmptyModelError,
|
|
3103
3293
|
InnerVizij,
|
|
3104
3294
|
ShapeMaterial,
|