@vizij/render 0.0.2 → 0.0.4
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 +12 -0
- package/dist/index.d.mts +114 -12
- package/dist/index.d.ts +114 -12
- package/dist/index.js +475 -466
- package/dist/index.mjs +336 -332
- package/package.json +4 -6
package/dist/index.js
CHANGED
|
@@ -30,17 +30,20 @@ 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,
|
|
37
36
|
Vizij: () => Vizij,
|
|
38
37
|
VizijContext: () => VizijContext,
|
|
39
38
|
VizijSlice: () => VizijSlice,
|
|
39
|
+
applyVizijBundle: () => applyVizijBundle,
|
|
40
40
|
createVizijStore: () => createVizijStore,
|
|
41
41
|
exportScene: () => exportScene,
|
|
42
|
+
extractVizijBundle: () => extractVizijBundle,
|
|
42
43
|
loadGLTF: () => loadGLTF,
|
|
43
44
|
loadGLTFFromBlob: () => loadGLTFFromBlob,
|
|
45
|
+
loadGLTFFromBlobWithBundle: () => loadGLTFFromBlobWithBundle,
|
|
46
|
+
loadGLTFWithBundle: () => loadGLTFWithBundle,
|
|
44
47
|
loadGltfFromBlob: () => loadGltfFromBlob,
|
|
45
48
|
useDefaultVizijStore: () => useDefaultVizijStore,
|
|
46
49
|
useFeatures: () => useFeatures,
|
|
@@ -51,12 +54,17 @@ __export(index_exports, {
|
|
|
51
54
|
});
|
|
52
55
|
module.exports = __toCommonJS(index_exports);
|
|
53
56
|
|
|
54
|
-
// src/
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
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");
|
|
60
68
|
|
|
61
69
|
// src/hooks/use-vizij-store.ts
|
|
62
70
|
var import_react2 = require("react");
|
|
@@ -73,217 +81,20 @@ function useVizijStore(selector) {
|
|
|
73
81
|
return (0, import_zustand.useStore)(store, selector);
|
|
74
82
|
}
|
|
75
83
|
|
|
76
|
-
// src/controllers/controller.tsx
|
|
77
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
78
|
-
function InnerController({
|
|
79
|
-
animatableId,
|
|
80
|
-
namespace,
|
|
81
|
-
subfield,
|
|
82
|
-
className
|
|
83
|
-
}) {
|
|
84
|
-
const setValue = useVizijStore((0, import_shallow.useShallow)((state) => state.setValue));
|
|
85
|
-
const animatable = useVizijStore(
|
|
86
|
-
(0, import_shallow.useShallow)((state) => state.animatables[animatableId])
|
|
87
|
-
);
|
|
88
|
-
const lookupId = (0, import_utils.getLookup)(namespace ?? "default", animatableId);
|
|
89
|
-
const rawValue = useVizijStore(
|
|
90
|
-
(0, import_shallow.useShallow)((state) => state.values.get(lookupId))
|
|
91
|
-
);
|
|
92
|
-
if (animatable.type === "number") {
|
|
93
|
-
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)(
|
|
94
|
-
import_ui.SliderNumberField,
|
|
95
|
-
{
|
|
96
|
-
size: import_ui.Size.Sm,
|
|
97
|
-
value: rawValue ?? animatable.default,
|
|
98
|
-
onChange: (v) => {
|
|
99
|
-
setValue(animatableId, namespace ?? "default", v);
|
|
100
|
-
},
|
|
101
|
-
min: animatable.constraints.min,
|
|
102
|
-
max: animatable.constraints.max
|
|
103
|
-
}
|
|
104
|
-
) });
|
|
105
|
-
} else if (animatable.type === "vector3" && !subfield) {
|
|
106
|
-
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) => {
|
|
107
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
108
|
-
InnerController,
|
|
109
|
-
{
|
|
110
|
-
animatableId,
|
|
111
|
-
namespace,
|
|
112
|
-
subfield: axis
|
|
113
|
-
},
|
|
114
|
-
axis
|
|
115
|
-
);
|
|
116
|
-
}) });
|
|
117
|
-
} else if (animatable.type === "vector2" && !subfield) {
|
|
118
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_clsx.clsx)("flex flex-col gap-2", className), children: ["x", "y"].map((axis) => {
|
|
119
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
120
|
-
InnerController,
|
|
121
|
-
{
|
|
122
|
-
animatableId,
|
|
123
|
-
namespace,
|
|
124
|
-
subfield: axis
|
|
125
|
-
},
|
|
126
|
-
axis
|
|
127
|
-
);
|
|
128
|
-
}) });
|
|
129
|
-
} else if (animatable.type === "euler" && !subfield) {
|
|
130
|
-
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) => {
|
|
131
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
132
|
-
InnerController,
|
|
133
|
-
{
|
|
134
|
-
animatableId,
|
|
135
|
-
namespace,
|
|
136
|
-
subfield: axis
|
|
137
|
-
},
|
|
138
|
-
axis
|
|
139
|
-
);
|
|
140
|
-
}) });
|
|
141
|
-
} else if (animatable.type === "rgb" && !subfield) {
|
|
142
|
-
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)(
|
|
143
|
-
import_ui.ColorPickerPopover,
|
|
144
|
-
{
|
|
145
|
-
value: rawValue ? convertRGBRange(rawValue, "255") : convertRGBRange(animatable.default, "255"),
|
|
146
|
-
onChange: (v) => {
|
|
147
|
-
setValue(
|
|
148
|
-
animatableId,
|
|
149
|
-
namespace ?? "default",
|
|
150
|
-
convertRGBRange(v, "1")
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
) });
|
|
155
|
-
} else if (animatable.type === "vector3" && subfield && ["x", "y", "z"].includes(subfield)) {
|
|
156
|
-
const axis = subfield;
|
|
157
|
-
const currentVec = rawValue ?? animatable.default;
|
|
158
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
159
|
-
import_ui.SliderNumberField,
|
|
160
|
-
{
|
|
161
|
-
label: axis,
|
|
162
|
-
size: import_ui.Size.Sm,
|
|
163
|
-
value: currentVec[axis],
|
|
164
|
-
onChange: (v) => {
|
|
165
|
-
setValue(animatableId, namespace ?? "default", {
|
|
166
|
-
...currentVec,
|
|
167
|
-
[axis]: v
|
|
168
|
-
});
|
|
169
|
-
},
|
|
170
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
171
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
172
|
-
}
|
|
173
|
-
);
|
|
174
|
-
} else if (animatable.type === "vector2" && subfield && ["x", "y"].includes(subfield)) {
|
|
175
|
-
const axis = subfield;
|
|
176
|
-
const currentVec = rawValue ?? animatable.default;
|
|
177
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
178
|
-
import_ui.SliderNumberField,
|
|
179
|
-
{
|
|
180
|
-
label: axis,
|
|
181
|
-
size: import_ui.Size.Sm,
|
|
182
|
-
value: currentVec[axis],
|
|
183
|
-
onChange: (v) => {
|
|
184
|
-
setValue(animatableId, namespace ?? "default", {
|
|
185
|
-
...currentVec,
|
|
186
|
-
[axis]: v
|
|
187
|
-
});
|
|
188
|
-
},
|
|
189
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
190
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
191
|
-
}
|
|
192
|
-
);
|
|
193
|
-
} else if (animatable.type === "euler" && subfield && ["x", "y", "z"].includes(subfield)) {
|
|
194
|
-
const axis = subfield;
|
|
195
|
-
const currentVec = rawValue ?? animatable.default;
|
|
196
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
197
|
-
import_ui.SliderNumberField,
|
|
198
|
-
{
|
|
199
|
-
label: axis,
|
|
200
|
-
size: import_ui.Size.Sm,
|
|
201
|
-
value: currentVec[axis],
|
|
202
|
-
onChange: (v) => {
|
|
203
|
-
setValue(animatableId, namespace ?? "default", {
|
|
204
|
-
...currentVec,
|
|
205
|
-
[axis]: v
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
209
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
210
|
-
}
|
|
211
|
-
);
|
|
212
|
-
} else if (animatable.type === "rgb" && subfield && ["r", "g", "b"].includes(subfield)) {
|
|
213
|
-
const axis = subfield;
|
|
214
|
-
const currentVec = rawValue ?? animatable.default;
|
|
215
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
216
|
-
import_ui.SliderNumberField,
|
|
217
|
-
{
|
|
218
|
-
label: axis,
|
|
219
|
-
size: import_ui.Size.Sm,
|
|
220
|
-
value: currentVec[axis],
|
|
221
|
-
strictText: true,
|
|
222
|
-
strictSlider: true,
|
|
223
|
-
onChange: (v) => {
|
|
224
|
-
setValue(animatableId, namespace ?? "default", {
|
|
225
|
-
...currentVec,
|
|
226
|
-
[axis]: v
|
|
227
|
-
});
|
|
228
|
-
},
|
|
229
|
-
min: animatable.constraints.min?.[vectorIndexLookup[axis]] ?? void 0,
|
|
230
|
-
max: animatable.constraints.max?.[vectorIndexLookup[axis]] ?? void 0
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
var Controller = (0, import_react3.memo)(InnerController);
|
|
236
|
-
var vectorIndexLookup = {
|
|
237
|
-
x: 0,
|
|
238
|
-
y: 1,
|
|
239
|
-
z: 2,
|
|
240
|
-
r: 0,
|
|
241
|
-
g: 1,
|
|
242
|
-
b: 2
|
|
243
|
-
};
|
|
244
|
-
var convertRGBRange = (color, to) => {
|
|
245
|
-
if (to === "255") {
|
|
246
|
-
return {
|
|
247
|
-
r: color.r * 255,
|
|
248
|
-
g: color.g * 255,
|
|
249
|
-
b: color.b * 255
|
|
250
|
-
};
|
|
251
|
-
} else if (to === "1") {
|
|
252
|
-
return {
|
|
253
|
-
r: color.r / 255,
|
|
254
|
-
g: color.g / 255,
|
|
255
|
-
b: color.b / 255
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
return color;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// src/vizij.tsx
|
|
262
|
-
var import_react11 = require("react");
|
|
263
|
-
var import_react_error_boundary = require("react-error-boundary");
|
|
264
|
-
var import_three = require("three");
|
|
265
|
-
var import_fiber = require("@react-three/fiber");
|
|
266
|
-
var import_drei3 = require("@react-three/drei");
|
|
267
|
-
var import_shallow8 = require("zustand/react/shallow");
|
|
268
|
-
|
|
269
|
-
// src/renderables/renderable.tsx
|
|
270
|
-
var import_react9 = require("react");
|
|
271
|
-
var import_shallow7 = require("zustand/react/shallow");
|
|
272
|
-
|
|
273
84
|
// src/renderables/group.tsx
|
|
274
|
-
var
|
|
85
|
+
var import_react4 = require("react");
|
|
275
86
|
var THREE = __toESM(require("three"));
|
|
276
|
-
var
|
|
277
|
-
var
|
|
87
|
+
var import_shallow2 = require("zustand/react/shallow");
|
|
88
|
+
var import_utils2 = require("@vizij/utils");
|
|
278
89
|
|
|
279
90
|
// src/hooks/use-features.ts
|
|
280
|
-
var
|
|
281
|
-
var
|
|
282
|
-
var
|
|
91
|
+
var import_react3 = require("react");
|
|
92
|
+
var import_shallow = require("zustand/shallow");
|
|
93
|
+
var import_utils = require("@vizij/utils");
|
|
283
94
|
function useFeatures(namespace, features, callbacks, debugInfo) {
|
|
284
|
-
const store = (0,
|
|
95
|
+
const store = (0, import_react3.useContext)(VizijContext);
|
|
285
96
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
286
|
-
(0,
|
|
97
|
+
(0, import_react3.useEffect)(() => {
|
|
287
98
|
const unsubsribes = [];
|
|
288
99
|
Object.keys(callbacks).forEach((key) => {
|
|
289
100
|
if (!(key in features)) {
|
|
@@ -309,11 +120,11 @@ function useFeatures(namespace, features, callbacks, debugInfo) {
|
|
|
309
120
|
}
|
|
310
121
|
};
|
|
311
122
|
const defaultValue = animatableValueInfo.default;
|
|
312
|
-
const lookupKey = (0,
|
|
123
|
+
const lookupKey = (0, import_utils.getLookup)(namespace, animatableValueInfo.id);
|
|
313
124
|
const unsubscribe = store.subscribe(
|
|
314
125
|
(state) => state.values.get(lookupKey) ?? defaultValue,
|
|
315
126
|
cb,
|
|
316
|
-
{ equalityFn:
|
|
127
|
+
{ equalityFn: import_shallow.shallow, fireImmediately: true }
|
|
317
128
|
);
|
|
318
129
|
unsubsribes.push(unsubscribe);
|
|
319
130
|
}
|
|
@@ -356,21 +167,21 @@ function createStoredRenderable(data, animatableValues) {
|
|
|
356
167
|
}
|
|
357
168
|
|
|
358
169
|
// src/renderables/group.tsx
|
|
359
|
-
var
|
|
170
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
360
171
|
THREE.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
361
172
|
function InnerRenderedGroup({
|
|
362
173
|
id,
|
|
363
174
|
namespace,
|
|
364
175
|
chain
|
|
365
176
|
}) {
|
|
366
|
-
const ref = (0,
|
|
367
|
-
const group = useVizijStore((0,
|
|
177
|
+
const ref = (0, import_react4.useRef)();
|
|
178
|
+
const group = useVizijStore((0, import_shallow2.useShallow)((state) => state.world[id]));
|
|
368
179
|
const refIsNull = !group.refs[namespace]?.current;
|
|
369
|
-
const animatables = useVizijStore((0,
|
|
180
|
+
const animatables = useVizijStore((0, import_shallow2.useShallow)((state) => state.animatables));
|
|
370
181
|
const setHoveredElement = useVizijStore(
|
|
371
|
-
(0,
|
|
182
|
+
(0, import_shallow2.useShallow)((state) => state.setHoveredElement)
|
|
372
183
|
);
|
|
373
|
-
const animatableValues = (0,
|
|
184
|
+
const animatableValues = (0, import_react4.useMemo)(() => {
|
|
374
185
|
const av = {};
|
|
375
186
|
Object.values(group.features).forEach((feat) => {
|
|
376
187
|
if (feat.animated) {
|
|
@@ -387,33 +198,33 @@ function InnerRenderedGroup({
|
|
|
387
198
|
};
|
|
388
199
|
useFeatures(namespace, group.features, {
|
|
389
200
|
translation: (pos) => {
|
|
390
|
-
if (ref.current?.position && (0,
|
|
201
|
+
if (ref.current?.position && (0, import_utils2.instanceOfRawVector3)(pos)) {
|
|
391
202
|
ref.current.position.set(
|
|
392
203
|
pos.x,
|
|
393
204
|
pos.y,
|
|
394
205
|
pos.z
|
|
395
206
|
);
|
|
396
|
-
} else if (ref.current?.position && (0,
|
|
207
|
+
} else if (ref.current?.position && (0, import_utils2.instanceOfRawVector2)(pos)) {
|
|
397
208
|
const currentZ = ref.current.position.z;
|
|
398
209
|
ref.current.position.set(pos.x, pos.y, currentZ);
|
|
399
210
|
}
|
|
400
211
|
},
|
|
401
212
|
rotation: (rot) => {
|
|
402
|
-
if (ref.current?.rotation && (0,
|
|
213
|
+
if (ref.current?.rotation && (0, import_utils2.instanceOfRawEuler)(rot)) {
|
|
403
214
|
ref.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
404
|
-
} else if (ref.current?.rotation && (0,
|
|
215
|
+
} else if (ref.current?.rotation && (0, import_utils2.instanceOfRawNumber)(rot)) {
|
|
405
216
|
ref.current.rotation.set(0, 0, 0);
|
|
406
217
|
ref.current.rotateZ(rot);
|
|
407
218
|
}
|
|
408
219
|
},
|
|
409
220
|
scale: (scale) => {
|
|
410
|
-
if (ref.current?.scale && (0,
|
|
221
|
+
if (ref.current?.scale && (0, import_utils2.instanceOfRawVector3)(scale)) {
|
|
411
222
|
if (scale.x === null || scale.y === null || scale.z === null) {
|
|
412
223
|
ref.current.scale.set(0.1, 0.1, 0.1);
|
|
413
224
|
return;
|
|
414
225
|
}
|
|
415
226
|
ref.current.scale.set(scale.x, scale.y, scale.z);
|
|
416
|
-
} else if (ref.current && (0,
|
|
227
|
+
} else if (ref.current && (0, import_utils2.instanceOfRawNumber)(scale)) {
|
|
417
228
|
ref.current.scale.set(scale, scale, scale);
|
|
418
229
|
} else if (ref.current) {
|
|
419
230
|
ref.current.scale.set(1, 1, 1);
|
|
@@ -421,19 +232,19 @@ function InnerRenderedGroup({
|
|
|
421
232
|
}
|
|
422
233
|
});
|
|
423
234
|
const setReference = useVizijStore(
|
|
424
|
-
(0,
|
|
235
|
+
(0, import_shallow2.useShallow)((state) => state.setReference)
|
|
425
236
|
);
|
|
426
|
-
(0,
|
|
237
|
+
(0, import_react4.useEffect)(() => {
|
|
427
238
|
if (ref.current && refIsNull) {
|
|
428
239
|
setReference(group.id, namespace, ref);
|
|
429
240
|
}
|
|
430
241
|
}, [group.id, namespace, ref, setReference, refIsNull]);
|
|
431
|
-
(0,
|
|
242
|
+
(0, import_react4.useEffect)(() => {
|
|
432
243
|
if (ref.current) {
|
|
433
244
|
ref.current.name = group.name;
|
|
434
245
|
}
|
|
435
246
|
}, [group.name]);
|
|
436
|
-
const handlePointerOver = (0,
|
|
247
|
+
const handlePointerOver = (0, import_react4.useCallback)(
|
|
437
248
|
(event) => {
|
|
438
249
|
if (event.eventObject !== event.object) {
|
|
439
250
|
return;
|
|
@@ -442,7 +253,7 @@ function InnerRenderedGroup({
|
|
|
442
253
|
},
|
|
443
254
|
[id, namespace, setHoveredElement]
|
|
444
255
|
);
|
|
445
|
-
const handlePointerOut = (0,
|
|
256
|
+
const handlePointerOut = (0, import_react4.useCallback)(
|
|
446
257
|
(event) => {
|
|
447
258
|
if (event.eventObject !== event.object) {
|
|
448
259
|
return;
|
|
@@ -451,7 +262,7 @@ function InnerRenderedGroup({
|
|
|
451
262
|
},
|
|
452
263
|
[setHoveredElement]
|
|
453
264
|
);
|
|
454
|
-
return /* @__PURE__ */ (0,
|
|
265
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
455
266
|
"group",
|
|
456
267
|
{
|
|
457
268
|
ref,
|
|
@@ -459,7 +270,7 @@ function InnerRenderedGroup({
|
|
|
459
270
|
userData,
|
|
460
271
|
onPointerOver: handlePointerOver,
|
|
461
272
|
onPointerOut: handlePointerOut,
|
|
462
|
-
children: group.children.map((child) => /* @__PURE__ */ (0,
|
|
273
|
+
children: group.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
463
274
|
Renderable,
|
|
464
275
|
{
|
|
465
276
|
id: child,
|
|
@@ -471,36 +282,36 @@ function InnerRenderedGroup({
|
|
|
471
282
|
}
|
|
472
283
|
);
|
|
473
284
|
}
|
|
474
|
-
var RenderedGroup = (0,
|
|
285
|
+
var RenderedGroup = (0, import_react4.memo)(InnerRenderedGroup);
|
|
475
286
|
|
|
476
287
|
// src/renderables/ellipse.tsx
|
|
477
|
-
var
|
|
478
|
-
var
|
|
479
|
-
var
|
|
288
|
+
var import_react5 = require("react");
|
|
289
|
+
var import_shallow3 = require("zustand/react/shallow");
|
|
290
|
+
var import_utils3 = require("@vizij/utils");
|
|
480
291
|
var import_drei = require("@react-three/drei");
|
|
481
|
-
var
|
|
292
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
482
293
|
function InnerRenderedEllipse({
|
|
483
294
|
id,
|
|
484
295
|
namespace,
|
|
485
296
|
chain
|
|
486
297
|
}) {
|
|
487
|
-
const ellipseRef = (0,
|
|
488
|
-
const materialRef = (0,
|
|
489
|
-
const lineRef = (0,
|
|
490
|
-
const strokeOffsetRef = (0,
|
|
491
|
-
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);
|
|
492
303
|
const onElementClick = useVizijStore(
|
|
493
|
-
(0,
|
|
304
|
+
(0, import_shallow3.useShallow)((state) => state.onElementClick)
|
|
494
305
|
);
|
|
495
306
|
const setHoveredElement = useVizijStore(
|
|
496
|
-
(0,
|
|
307
|
+
(0, import_shallow3.useShallow)((state) => state.setHoveredElement)
|
|
497
308
|
);
|
|
498
309
|
const ellipse = useVizijStore(
|
|
499
|
-
(0,
|
|
310
|
+
(0, import_shallow3.useShallow)((state) => state.world[id])
|
|
500
311
|
);
|
|
501
312
|
const refIsNull = !ellipse.refs[namespace]?.current;
|
|
502
|
-
const animatables = useVizijStore((0,
|
|
503
|
-
const animatableValues = (0,
|
|
313
|
+
const animatables = useVizijStore((0, import_shallow3.useShallow)((state) => state.animatables));
|
|
314
|
+
const animatableValues = (0, import_react5.useMemo)(() => {
|
|
504
315
|
const av = {};
|
|
505
316
|
Object.values(ellipse.features).forEach((feat) => {
|
|
506
317
|
if (feat.animated) {
|
|
@@ -510,11 +321,11 @@ function InnerRenderedEllipse({
|
|
|
510
321
|
});
|
|
511
322
|
return av;
|
|
512
323
|
}, [ellipse.features, animatables]);
|
|
513
|
-
const selectionData = (0,
|
|
324
|
+
const selectionData = (0, import_react5.useMemo)(
|
|
514
325
|
() => ({ id, namespace, type: "ellipse" }),
|
|
515
326
|
[id, namespace]
|
|
516
327
|
);
|
|
517
|
-
const userData = (0,
|
|
328
|
+
const userData = (0, import_react5.useMemo)(
|
|
518
329
|
() => ({
|
|
519
330
|
gltfExtensions: {
|
|
520
331
|
RobotData: createStoredRenderable(ellipse, animatableValues)
|
|
@@ -525,13 +336,13 @@ function InnerRenderedEllipse({
|
|
|
525
336
|
);
|
|
526
337
|
useFeatures(namespace, ellipse.features, {
|
|
527
338
|
translation: (pos) => {
|
|
528
|
-
if (ellipseRef.current?.position && (0,
|
|
339
|
+
if (ellipseRef.current?.position && (0, import_utils3.instanceOfRawVector3)(pos)) {
|
|
529
340
|
ellipseRef.current.position.set(
|
|
530
341
|
pos.x,
|
|
531
342
|
pos.y,
|
|
532
343
|
pos.z
|
|
533
344
|
);
|
|
534
|
-
} else if (ellipseRef.current?.position && (0,
|
|
345
|
+
} else if (ellipseRef.current?.position && (0, import_utils3.instanceOfRawVector2)(pos)) {
|
|
535
346
|
const currentZ = ellipseRef.current.position.z;
|
|
536
347
|
ellipseRef.current.position.set(
|
|
537
348
|
pos.x,
|
|
@@ -539,13 +350,13 @@ function InnerRenderedEllipse({
|
|
|
539
350
|
currentZ
|
|
540
351
|
);
|
|
541
352
|
}
|
|
542
|
-
if (lineRef.current?.position && (0,
|
|
353
|
+
if (lineRef.current?.position && (0, import_utils3.instanceOfRawVector3)(pos)) {
|
|
543
354
|
lineRef.current.position.set(
|
|
544
355
|
pos.x,
|
|
545
356
|
pos.y,
|
|
546
357
|
pos.z
|
|
547
358
|
);
|
|
548
|
-
} else if (lineRef.current?.position && (0,
|
|
359
|
+
} else if (lineRef.current?.position && (0, import_utils3.instanceOfRawVector2)(pos)) {
|
|
549
360
|
const currentZ = lineRef.current.position.z;
|
|
550
361
|
lineRef.current.position.set(
|
|
551
362
|
pos.x,
|
|
@@ -555,21 +366,21 @@ function InnerRenderedEllipse({
|
|
|
555
366
|
}
|
|
556
367
|
},
|
|
557
368
|
rotation: (rot) => {
|
|
558
|
-
if (ellipseRef.current?.rotation && (0,
|
|
369
|
+
if (ellipseRef.current?.rotation && (0, import_utils3.instanceOfRawEuler)(rot)) {
|
|
559
370
|
ellipseRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
560
|
-
} else if (ellipseRef.current?.rotation && (0,
|
|
371
|
+
} else if (ellipseRef.current?.rotation && (0, import_utils3.instanceOfRawNumber)(rot)) {
|
|
561
372
|
ellipseRef.current.rotation.set(0, 0, 0);
|
|
562
373
|
ellipseRef.current.rotateZ(rot);
|
|
563
374
|
}
|
|
564
|
-
if (lineRef.current?.rotation && (0,
|
|
375
|
+
if (lineRef.current?.rotation && (0, import_utils3.instanceOfRawEuler)(rot)) {
|
|
565
376
|
lineRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
566
|
-
} else if (lineRef.current?.rotation && (0,
|
|
377
|
+
} else if (lineRef.current?.rotation && (0, import_utils3.instanceOfRawNumber)(rot)) {
|
|
567
378
|
lineRef.current.rotation.set(0, 0, 0);
|
|
568
379
|
lineRef.current.rotateZ(rot);
|
|
569
380
|
}
|
|
570
381
|
},
|
|
571
382
|
fillOpacity: (op) => {
|
|
572
|
-
if (materialRef.current?.opacity !== void 0 && (0,
|
|
383
|
+
if (materialRef.current?.opacity !== void 0 && (0, import_utils3.instanceOfRawNumber)(op)) {
|
|
573
384
|
materialRef.current.opacity = op;
|
|
574
385
|
if (op < 1) {
|
|
575
386
|
materialRef.current.transparent = true;
|
|
@@ -581,23 +392,23 @@ function InnerRenderedEllipse({
|
|
|
581
392
|
},
|
|
582
393
|
fillColor: (color) => {
|
|
583
394
|
if (materialRef.current?.color) {
|
|
584
|
-
if ((0,
|
|
395
|
+
if ((0, import_utils3.instanceOfRawRGB)(color)) {
|
|
585
396
|
materialRef.current.color.setRGB(color.r, color.g, color.b);
|
|
586
397
|
materialRef.current.needsUpdate = true;
|
|
587
|
-
} else if ((0,
|
|
398
|
+
} else if ((0, import_utils3.instanceOfRawVector3)(color)) {
|
|
588
399
|
materialRef.current.color.setRGB(color.x, color.y, color.z);
|
|
589
400
|
materialRef.current.needsUpdate = true;
|
|
590
|
-
} else if ((0,
|
|
401
|
+
} else if ((0, import_utils3.instanceOfRawHSL)(color)) {
|
|
591
402
|
materialRef.current.color.setHSL(color.h, color.s, color.l);
|
|
592
403
|
materialRef.current.needsUpdate = true;
|
|
593
404
|
}
|
|
594
405
|
}
|
|
595
406
|
},
|
|
596
407
|
height: (height) => {
|
|
597
|
-
if (ellipseRef.current && (0,
|
|
408
|
+
if (ellipseRef.current && (0, import_utils3.instanceOfRawNumber)(height)) {
|
|
598
409
|
ellipseRef.current.scale.set(ellipseRef.current.scale.x, height, 1);
|
|
599
410
|
}
|
|
600
|
-
if (ellipseRef.current && lineRef.current && (0,
|
|
411
|
+
if (ellipseRef.current && lineRef.current && (0, import_utils3.instanceOfRawNumber)(height)) {
|
|
601
412
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
602
413
|
lineRef.current.scale.set(
|
|
603
414
|
ellipseRef.current.scale.x + offset,
|
|
@@ -607,10 +418,10 @@ function InnerRenderedEllipse({
|
|
|
607
418
|
}
|
|
608
419
|
},
|
|
609
420
|
width: (width) => {
|
|
610
|
-
if (ellipseRef.current && (0,
|
|
421
|
+
if (ellipseRef.current && (0, import_utils3.instanceOfRawNumber)(width)) {
|
|
611
422
|
ellipseRef.current.scale.set(width, ellipseRef.current.scale.y, 1);
|
|
612
423
|
}
|
|
613
|
-
if (ellipseRef.current && lineRef.current && (0,
|
|
424
|
+
if (ellipseRef.current && lineRef.current && (0, import_utils3.instanceOfRawNumber)(width)) {
|
|
614
425
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
615
426
|
lineRef.current.scale.set(
|
|
616
427
|
width + offset,
|
|
@@ -620,7 +431,7 @@ function InnerRenderedEllipse({
|
|
|
620
431
|
}
|
|
621
432
|
},
|
|
622
433
|
strokeOpacity: (strokeOpacity) => {
|
|
623
|
-
if (lineRef.current?.material && (0,
|
|
434
|
+
if (lineRef.current?.material && (0, import_utils3.instanceOfRawNumber)(strokeOpacity)) {
|
|
624
435
|
lineRef.current.material.opacity = strokeOpacity;
|
|
625
436
|
if (strokeOpacity < 1) {
|
|
626
437
|
lineRef.current.material.transparent = true;
|
|
@@ -632,21 +443,21 @@ function InnerRenderedEllipse({
|
|
|
632
443
|
},
|
|
633
444
|
strokeColor: (strokeColor) => {
|
|
634
445
|
if (lineRef.current?.material.color) {
|
|
635
|
-
if ((0,
|
|
446
|
+
if ((0, import_utils3.instanceOfRawRGB)(strokeColor)) {
|
|
636
447
|
lineRef.current.material.color.setRGB(
|
|
637
448
|
strokeColor.r,
|
|
638
449
|
strokeColor.g,
|
|
639
450
|
strokeColor.b
|
|
640
451
|
);
|
|
641
452
|
lineRef.current.material.needsUpdate = true;
|
|
642
|
-
} else if ((0,
|
|
453
|
+
} else if ((0, import_utils3.instanceOfRawVector3)(strokeColor)) {
|
|
643
454
|
lineRef.current.material.color.setRGB(
|
|
644
455
|
strokeColor.x,
|
|
645
456
|
strokeColor.y,
|
|
646
457
|
strokeColor.z
|
|
647
458
|
);
|
|
648
459
|
lineRef.current.material.needsUpdate = true;
|
|
649
|
-
} else if ((0,
|
|
460
|
+
} else if ((0, import_utils3.instanceOfRawHSL)(strokeColor)) {
|
|
650
461
|
lineRef.current.material.color.setHSL(
|
|
651
462
|
strokeColor.h,
|
|
652
463
|
strokeColor.s,
|
|
@@ -658,7 +469,7 @@ function InnerRenderedEllipse({
|
|
|
658
469
|
},
|
|
659
470
|
strokeWidth: (strokeWidth) => {
|
|
660
471
|
if (lineRef.current?.material && ellipseRef.current) {
|
|
661
|
-
if ((0,
|
|
472
|
+
if ((0, import_utils3.instanceOfRawNumber)(strokeWidth)) {
|
|
662
473
|
strokeWidthRef.current = strokeWidth;
|
|
663
474
|
const offset = strokeWidth * strokeOffsetRef.current / 2 + strokeOffsetRef.current * -1;
|
|
664
475
|
lineRef.current.scale.set(
|
|
@@ -673,7 +484,7 @@ function InnerRenderedEllipse({
|
|
|
673
484
|
},
|
|
674
485
|
strokeOffset: (strokeOffset) => {
|
|
675
486
|
if (lineRef.current?.material && ellipseRef.current) {
|
|
676
|
-
if ((0,
|
|
487
|
+
if ((0, import_utils3.instanceOfRawNumber)(strokeOffset)) {
|
|
677
488
|
strokeOffsetRef.current = strokeOffset;
|
|
678
489
|
const offset = strokeOffset * strokeWidthRef.current / 2 + strokeOffset * -1;
|
|
679
490
|
lineRef.current.scale.set(
|
|
@@ -686,9 +497,9 @@ function InnerRenderedEllipse({
|
|
|
686
497
|
}
|
|
687
498
|
});
|
|
688
499
|
const setReference = useVizijStore(
|
|
689
|
-
(0,
|
|
500
|
+
(0, import_shallow3.useShallow)((state) => state.setReference)
|
|
690
501
|
);
|
|
691
|
-
const points = (0,
|
|
502
|
+
const points = (0, import_react5.useMemo)(() => {
|
|
692
503
|
const n = 600;
|
|
693
504
|
const p = [];
|
|
694
505
|
const angleStep = 2 * Math.PI / n;
|
|
@@ -700,26 +511,26 @@ function InnerRenderedEllipse({
|
|
|
700
511
|
}
|
|
701
512
|
return p;
|
|
702
513
|
}, []);
|
|
703
|
-
(0,
|
|
514
|
+
(0, import_react5.useEffect)(() => {
|
|
704
515
|
if (ellipseRef.current && refIsNull)
|
|
705
516
|
setReference(ellipse.id, namespace, ellipseRef);
|
|
706
517
|
}, [ellipse.id, namespace, ellipseRef, setReference, refIsNull]);
|
|
707
|
-
const handlePointerOver = (0,
|
|
518
|
+
const handlePointerOver = (0, import_react5.useCallback)(
|
|
708
519
|
(event) => {
|
|
709
520
|
event.stopPropagation();
|
|
710
521
|
setHoveredElement({ id, namespace, type: "ellipse" });
|
|
711
522
|
},
|
|
712
523
|
[id, namespace, setHoveredElement]
|
|
713
524
|
);
|
|
714
|
-
const handlePointerOut = (0,
|
|
525
|
+
const handlePointerOut = (0, import_react5.useCallback)(
|
|
715
526
|
(event) => {
|
|
716
527
|
event.stopPropagation();
|
|
717
528
|
setHoveredElement(null);
|
|
718
529
|
},
|
|
719
530
|
[setHoveredElement]
|
|
720
531
|
);
|
|
721
|
-
return /* @__PURE__ */ (0,
|
|
722
|
-
/* @__PURE__ */ (0,
|
|
532
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
533
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
723
534
|
import_drei.Circle,
|
|
724
535
|
{
|
|
725
536
|
ref: ellipseRef,
|
|
@@ -730,10 +541,10 @@ function InnerRenderedEllipse({
|
|
|
730
541
|
onClick: (e) => {
|
|
731
542
|
onElementClick({ id, type: "ellipse", namespace }, [...chain, id], e);
|
|
732
543
|
},
|
|
733
|
-
children: /* @__PURE__ */ (0,
|
|
544
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("meshStandardMaterial", { attach: "material", ref: materialRef })
|
|
734
545
|
}
|
|
735
546
|
),
|
|
736
|
-
showLine(ellipse) && /* @__PURE__ */ (0,
|
|
547
|
+
showLine(ellipse) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
737
548
|
import_drei.Line,
|
|
738
549
|
{
|
|
739
550
|
ref: lineRef,
|
|
@@ -744,7 +555,7 @@ function InnerRenderedEllipse({
|
|
|
744
555
|
)
|
|
745
556
|
] });
|
|
746
557
|
}
|
|
747
|
-
var RenderedEllipse = (0,
|
|
558
|
+
var RenderedEllipse = (0, import_react5.memo)(InnerRenderedEllipse);
|
|
748
559
|
var showLine = (ellipse) => {
|
|
749
560
|
if ("strokeOpacity" in ellipse.features) {
|
|
750
561
|
return true;
|
|
@@ -759,33 +570,33 @@ var showLine = (ellipse) => {
|
|
|
759
570
|
};
|
|
760
571
|
|
|
761
572
|
// src/renderables/rectangle.tsx
|
|
762
|
-
var
|
|
763
|
-
var
|
|
764
|
-
var
|
|
573
|
+
var import_react6 = require("react");
|
|
574
|
+
var import_shallow4 = require("zustand/react/shallow");
|
|
575
|
+
var import_utils4 = require("@vizij/utils");
|
|
765
576
|
var import_drei2 = require("@react-three/drei");
|
|
766
|
-
var
|
|
577
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
767
578
|
function InnerRenderedRectangle({
|
|
768
579
|
id,
|
|
769
580
|
namespace,
|
|
770
581
|
chain
|
|
771
582
|
}) {
|
|
772
|
-
const rectangleRef = (0,
|
|
773
|
-
const materialRef = (0,
|
|
774
|
-
const lineRef = (0,
|
|
775
|
-
const strokeOffsetRef = (0,
|
|
776
|
-
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);
|
|
777
588
|
const onElementClick = useVizijStore(
|
|
778
|
-
(0,
|
|
589
|
+
(0, import_shallow4.useShallow)((state) => state.onElementClick)
|
|
779
590
|
);
|
|
780
591
|
const setHoveredElement = useVizijStore(
|
|
781
|
-
(0,
|
|
592
|
+
(0, import_shallow4.useShallow)((state) => state.setHoveredElement)
|
|
782
593
|
);
|
|
783
594
|
const rectangle = useVizijStore(
|
|
784
|
-
(0,
|
|
595
|
+
(0, import_shallow4.useShallow)((state) => state.world[id])
|
|
785
596
|
);
|
|
786
597
|
const refIsNull = !rectangle.refs[namespace]?.current;
|
|
787
|
-
const animatables = useVizijStore((0,
|
|
788
|
-
const animatableValues = (0,
|
|
598
|
+
const animatables = useVizijStore((0, import_shallow4.useShallow)((state) => state.animatables));
|
|
599
|
+
const animatableValues = (0, import_react6.useMemo)(() => {
|
|
789
600
|
const av = {};
|
|
790
601
|
Object.values(rectangle.features).forEach((feat) => {
|
|
791
602
|
if (feat.animated) {
|
|
@@ -795,11 +606,11 @@ function InnerRenderedRectangle({
|
|
|
795
606
|
});
|
|
796
607
|
return av;
|
|
797
608
|
}, [rectangle.features, animatables]);
|
|
798
|
-
const selectionData = (0,
|
|
609
|
+
const selectionData = (0, import_react6.useMemo)(
|
|
799
610
|
() => ({ id, namespace, type: "rectangle" }),
|
|
800
611
|
[id, namespace]
|
|
801
612
|
);
|
|
802
|
-
const userData = (0,
|
|
613
|
+
const userData = (0, import_react6.useMemo)(
|
|
803
614
|
() => ({
|
|
804
615
|
gltfExtensions: {
|
|
805
616
|
RobotData: createStoredRenderable(rectangle, animatableValues)
|
|
@@ -810,13 +621,13 @@ function InnerRenderedRectangle({
|
|
|
810
621
|
);
|
|
811
622
|
useFeatures(namespace, rectangle.features, {
|
|
812
623
|
translation: (pos) => {
|
|
813
|
-
if (rectangleRef.current?.position && (0,
|
|
624
|
+
if (rectangleRef.current?.position && (0, import_utils4.instanceOfRawVector3)(pos)) {
|
|
814
625
|
rectangleRef.current.position.set(
|
|
815
626
|
pos.x,
|
|
816
627
|
pos.y,
|
|
817
628
|
pos.z
|
|
818
629
|
);
|
|
819
|
-
} else if (rectangleRef.current?.position && (0,
|
|
630
|
+
} else if (rectangleRef.current?.position && (0, import_utils4.instanceOfRawVector2)(pos)) {
|
|
820
631
|
const currentZ = rectangleRef.current.position.z;
|
|
821
632
|
rectangleRef.current.position.set(
|
|
822
633
|
pos.x,
|
|
@@ -824,13 +635,13 @@ function InnerRenderedRectangle({
|
|
|
824
635
|
currentZ
|
|
825
636
|
);
|
|
826
637
|
}
|
|
827
|
-
if (lineRef.current?.position && (0,
|
|
638
|
+
if (lineRef.current?.position && (0, import_utils4.instanceOfRawVector3)(pos)) {
|
|
828
639
|
lineRef.current.position.set(
|
|
829
640
|
pos.x,
|
|
830
641
|
pos.y,
|
|
831
642
|
pos.z
|
|
832
643
|
);
|
|
833
|
-
} else if (lineRef.current?.position && (0,
|
|
644
|
+
} else if (lineRef.current?.position && (0, import_utils4.instanceOfRawVector2)(pos)) {
|
|
834
645
|
const currentZ = lineRef.current.position.z;
|
|
835
646
|
lineRef.current.position.set(
|
|
836
647
|
pos.x,
|
|
@@ -840,21 +651,21 @@ function InnerRenderedRectangle({
|
|
|
840
651
|
}
|
|
841
652
|
},
|
|
842
653
|
rotation: (rot) => {
|
|
843
|
-
if (rectangleRef.current?.rotation && (0,
|
|
654
|
+
if (rectangleRef.current?.rotation && (0, import_utils4.instanceOfRawEuler)(rot)) {
|
|
844
655
|
rectangleRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
845
|
-
} else if (rectangleRef.current?.rotation && (0,
|
|
656
|
+
} else if (rectangleRef.current?.rotation && (0, import_utils4.instanceOfRawNumber)(rot)) {
|
|
846
657
|
rectangleRef.current.rotation.set(0, 0, 0);
|
|
847
658
|
rectangleRef.current.rotateZ(rot);
|
|
848
659
|
}
|
|
849
|
-
if (lineRef.current?.rotation && (0,
|
|
660
|
+
if (lineRef.current?.rotation && (0, import_utils4.instanceOfRawEuler)(rot)) {
|
|
850
661
|
lineRef.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
851
|
-
} else if (lineRef.current?.rotation && (0,
|
|
662
|
+
} else if (lineRef.current?.rotation && (0, import_utils4.instanceOfRawNumber)(rot)) {
|
|
852
663
|
lineRef.current.rotation.set(0, 0, 0);
|
|
853
664
|
lineRef.current.rotateZ(rot);
|
|
854
665
|
}
|
|
855
666
|
},
|
|
856
667
|
fillOpacity: (op) => {
|
|
857
|
-
if (materialRef.current?.opacity !== void 0 && (0,
|
|
668
|
+
if (materialRef.current?.opacity !== void 0 && (0, import_utils4.instanceOfRawNumber)(op)) {
|
|
858
669
|
materialRef.current.opacity = op;
|
|
859
670
|
if (op < 1) {
|
|
860
671
|
materialRef.current.transparent = true;
|
|
@@ -866,23 +677,23 @@ function InnerRenderedRectangle({
|
|
|
866
677
|
},
|
|
867
678
|
fillColor: (color) => {
|
|
868
679
|
if (materialRef.current?.color) {
|
|
869
|
-
if ((0,
|
|
680
|
+
if ((0, import_utils4.instanceOfRawRGB)(color)) {
|
|
870
681
|
materialRef.current.color.setRGB(color.r, color.g, color.b);
|
|
871
682
|
materialRef.current.needsUpdate = true;
|
|
872
|
-
} else if ((0,
|
|
683
|
+
} else if ((0, import_utils4.instanceOfRawVector3)(color)) {
|
|
873
684
|
materialRef.current.color.setRGB(color.x, color.y, color.z);
|
|
874
685
|
materialRef.current.needsUpdate = true;
|
|
875
|
-
} else if ((0,
|
|
686
|
+
} else if ((0, import_utils4.instanceOfRawHSL)(color)) {
|
|
876
687
|
materialRef.current.color.setHSL(color.h, color.s, color.l);
|
|
877
688
|
materialRef.current.needsUpdate = true;
|
|
878
689
|
}
|
|
879
690
|
}
|
|
880
691
|
},
|
|
881
692
|
height: (height) => {
|
|
882
|
-
if (rectangleRef.current && (0,
|
|
693
|
+
if (rectangleRef.current && (0, import_utils4.instanceOfRawNumber)(height)) {
|
|
883
694
|
rectangleRef.current.scale.set(rectangleRef.current.scale.x, height, 1);
|
|
884
695
|
}
|
|
885
|
-
if (rectangleRef.current && lineRef.current && (0,
|
|
696
|
+
if (rectangleRef.current && lineRef.current && (0, import_utils4.instanceOfRawNumber)(height)) {
|
|
886
697
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
887
698
|
lineRef.current.scale.set(
|
|
888
699
|
rectangleRef.current.scale.x + offset,
|
|
@@ -892,10 +703,10 @@ function InnerRenderedRectangle({
|
|
|
892
703
|
}
|
|
893
704
|
},
|
|
894
705
|
width: (width) => {
|
|
895
|
-
if (rectangleRef.current && (0,
|
|
706
|
+
if (rectangleRef.current && (0, import_utils4.instanceOfRawNumber)(width)) {
|
|
896
707
|
rectangleRef.current.scale.set(width, rectangleRef.current.scale.y, 1);
|
|
897
708
|
}
|
|
898
|
-
if (rectangleRef.current && lineRef.current && (0,
|
|
709
|
+
if (rectangleRef.current && lineRef.current && (0, import_utils4.instanceOfRawNumber)(width)) {
|
|
899
710
|
const offset = strokeOffsetRef.current * strokeWidthRef.current / 2 + strokeOffsetRef.current * -1;
|
|
900
711
|
lineRef.current.scale.set(
|
|
901
712
|
width + offset,
|
|
@@ -905,7 +716,7 @@ function InnerRenderedRectangle({
|
|
|
905
716
|
}
|
|
906
717
|
},
|
|
907
718
|
strokeOpacity: (strokeOpacity) => {
|
|
908
|
-
if (lineRef.current?.material && (0,
|
|
719
|
+
if (lineRef.current?.material && (0, import_utils4.instanceOfRawNumber)(strokeOpacity)) {
|
|
909
720
|
lineRef.current.material.opacity = strokeOpacity;
|
|
910
721
|
if (strokeOpacity < 1) {
|
|
911
722
|
lineRef.current.material.transparent = true;
|
|
@@ -917,21 +728,21 @@ function InnerRenderedRectangle({
|
|
|
917
728
|
},
|
|
918
729
|
strokeColor: (strokeColor) => {
|
|
919
730
|
if (lineRef.current?.material.color) {
|
|
920
|
-
if ((0,
|
|
731
|
+
if ((0, import_utils4.instanceOfRawRGB)(strokeColor)) {
|
|
921
732
|
lineRef.current.material.color.setRGB(
|
|
922
733
|
strokeColor.r,
|
|
923
734
|
strokeColor.g,
|
|
924
735
|
strokeColor.b
|
|
925
736
|
);
|
|
926
737
|
lineRef.current.material.needsUpdate = true;
|
|
927
|
-
} else if ((0,
|
|
738
|
+
} else if ((0, import_utils4.instanceOfRawVector3)(strokeColor)) {
|
|
928
739
|
lineRef.current.material.color.setRGB(
|
|
929
740
|
strokeColor.x,
|
|
930
741
|
strokeColor.y,
|
|
931
742
|
strokeColor.z
|
|
932
743
|
);
|
|
933
744
|
lineRef.current.material.needsUpdate = true;
|
|
934
|
-
} else if ((0,
|
|
745
|
+
} else if ((0, import_utils4.instanceOfRawHSL)(strokeColor)) {
|
|
935
746
|
lineRef.current.material.color.setHSL(
|
|
936
747
|
strokeColor.h,
|
|
937
748
|
strokeColor.s,
|
|
@@ -943,7 +754,7 @@ function InnerRenderedRectangle({
|
|
|
943
754
|
},
|
|
944
755
|
strokeWidth: (strokeWidth) => {
|
|
945
756
|
if (lineRef.current?.material && rectangleRef.current) {
|
|
946
|
-
if ((0,
|
|
757
|
+
if ((0, import_utils4.instanceOfRawNumber)(strokeWidth)) {
|
|
947
758
|
strokeWidthRef.current = strokeWidth;
|
|
948
759
|
const offset = strokeWidth * strokeOffsetRef.current / 2 + strokeOffsetRef.current * -1;
|
|
949
760
|
lineRef.current.scale.set(
|
|
@@ -958,7 +769,7 @@ function InnerRenderedRectangle({
|
|
|
958
769
|
},
|
|
959
770
|
strokeOffset: (strokeOffset) => {
|
|
960
771
|
if (lineRef.current?.material && rectangleRef.current) {
|
|
961
|
-
if ((0,
|
|
772
|
+
if ((0, import_utils4.instanceOfRawNumber)(strokeOffset)) {
|
|
962
773
|
strokeOffsetRef.current = strokeOffset;
|
|
963
774
|
const offset = strokeOffset * strokeWidthRef.current / 2 + strokeOffset * -1;
|
|
964
775
|
lineRef.current.scale.set(
|
|
@@ -971,9 +782,9 @@ function InnerRenderedRectangle({
|
|
|
971
782
|
}
|
|
972
783
|
});
|
|
973
784
|
const setReference = useVizijStore(
|
|
974
|
-
(0,
|
|
785
|
+
(0, import_shallow4.useShallow)((state) => state.setReference)
|
|
975
786
|
);
|
|
976
|
-
const points = (0,
|
|
787
|
+
const points = (0, import_react6.useMemo)(() => {
|
|
977
788
|
return [
|
|
978
789
|
[-0.5, 0.5, 0],
|
|
979
790
|
[0.5, 0.5, 0],
|
|
@@ -982,26 +793,26 @@ function InnerRenderedRectangle({
|
|
|
982
793
|
[-0.5, 0.5, 0]
|
|
983
794
|
];
|
|
984
795
|
}, []);
|
|
985
|
-
(0,
|
|
796
|
+
(0, import_react6.useEffect)(() => {
|
|
986
797
|
if (rectangleRef.current && refIsNull)
|
|
987
798
|
setReference(rectangle.id, namespace, rectangleRef);
|
|
988
799
|
}, [rectangle.id, namespace, rectangleRef, setReference, refIsNull]);
|
|
989
|
-
const handlePointerOver = (0,
|
|
800
|
+
const handlePointerOver = (0, import_react6.useCallback)(
|
|
990
801
|
(event) => {
|
|
991
802
|
event.stopPropagation();
|
|
992
803
|
setHoveredElement({ id, namespace, type: "rectangle" });
|
|
993
804
|
},
|
|
994
805
|
[id, namespace, setHoveredElement]
|
|
995
806
|
);
|
|
996
|
-
const handlePointerOut = (0,
|
|
807
|
+
const handlePointerOut = (0, import_react6.useCallback)(
|
|
997
808
|
(event) => {
|
|
998
809
|
event.stopPropagation();
|
|
999
810
|
setHoveredElement(null);
|
|
1000
811
|
},
|
|
1001
812
|
[setHoveredElement]
|
|
1002
813
|
);
|
|
1003
|
-
return /* @__PURE__ */ (0,
|
|
1004
|
-
/* @__PURE__ */ (0,
|
|
814
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
815
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1005
816
|
import_drei2.Plane,
|
|
1006
817
|
{
|
|
1007
818
|
ref: rectangleRef,
|
|
@@ -1016,10 +827,10 @@ function InnerRenderedRectangle({
|
|
|
1016
827
|
e
|
|
1017
828
|
);
|
|
1018
829
|
},
|
|
1019
|
-
children: /* @__PURE__ */ (0,
|
|
830
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("meshStandardMaterial", { attach: "material", ref: materialRef })
|
|
1020
831
|
}
|
|
1021
832
|
),
|
|
1022
|
-
showLine2(rectangle) && /* @__PURE__ */ (0,
|
|
833
|
+
showLine2(rectangle) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1023
834
|
import_drei2.Line,
|
|
1024
835
|
{
|
|
1025
836
|
ref: lineRef,
|
|
@@ -1030,7 +841,7 @@ function InnerRenderedRectangle({
|
|
|
1030
841
|
)
|
|
1031
842
|
] });
|
|
1032
843
|
}
|
|
1033
|
-
var RenderedRectangle = (0,
|
|
844
|
+
var RenderedRectangle = (0, import_react6.memo)(InnerRenderedRectangle);
|
|
1034
845
|
var showLine2 = (rectangle) => {
|
|
1035
846
|
if ("strokeOpacity" in rectangle.features) {
|
|
1036
847
|
return true;
|
|
@@ -1045,26 +856,26 @@ var showLine2 = (rectangle) => {
|
|
|
1045
856
|
};
|
|
1046
857
|
|
|
1047
858
|
// src/renderables/shape.tsx
|
|
1048
|
-
var
|
|
859
|
+
var import_react7 = require("react");
|
|
1049
860
|
var THREE2 = __toESM(require("three"));
|
|
1050
|
-
var
|
|
1051
|
-
var
|
|
1052
|
-
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");
|
|
1053
864
|
THREE2.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
1054
865
|
function InnerRenderedShape({
|
|
1055
866
|
id,
|
|
1056
867
|
namespace,
|
|
1057
868
|
chain
|
|
1058
869
|
}) {
|
|
1059
|
-
const refGroup = (0,
|
|
1060
|
-
const ref = (0,
|
|
1061
|
-
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]));
|
|
1062
873
|
const refs = useVizijStore(
|
|
1063
|
-
(0,
|
|
874
|
+
(0, import_shallow5.useShallow)((state) => state.world[id].refs)
|
|
1064
875
|
);
|
|
1065
876
|
const refIsNull = !refs[namespace]?.current;
|
|
1066
|
-
const animatables = useVizijStore((0,
|
|
1067
|
-
const animatableValues = (0,
|
|
877
|
+
const animatables = useVizijStore((0, import_shallow5.useShallow)((state) => state.animatables));
|
|
878
|
+
const animatableValues = (0, import_react7.useMemo)(() => {
|
|
1068
879
|
const av = {};
|
|
1069
880
|
Object.values(shape.features).forEach((feat) => {
|
|
1070
881
|
if (feat.animated) {
|
|
@@ -1074,22 +885,22 @@ function InnerRenderedShape({
|
|
|
1074
885
|
});
|
|
1075
886
|
return av;
|
|
1076
887
|
}, [shape.features, animatables]);
|
|
1077
|
-
const materialName = (0,
|
|
888
|
+
const materialName = (0, import_react7.useMemo)(
|
|
1078
889
|
() => deriveMaterialName(shape, animatableValues),
|
|
1079
890
|
[shape, animatableValues]
|
|
1080
891
|
);
|
|
1081
|
-
const geometry = (0,
|
|
892
|
+
const geometry = (0, import_react7.useMemo)(() => {
|
|
1082
893
|
const cloned = shape.geometry.clone();
|
|
1083
894
|
if (shape.name) {
|
|
1084
895
|
cloned.name = shape.name;
|
|
1085
896
|
}
|
|
1086
897
|
return cloned;
|
|
1087
898
|
}, [shape.geometry, shape.name]);
|
|
1088
|
-
const selectionData = (0,
|
|
899
|
+
const selectionData = (0, import_react7.useMemo)(
|
|
1089
900
|
() => ({ id, namespace, type: "shape" }),
|
|
1090
901
|
[id, namespace]
|
|
1091
902
|
);
|
|
1092
|
-
const userData = (0,
|
|
903
|
+
const userData = (0, import_react7.useMemo)(
|
|
1093
904
|
() => ({
|
|
1094
905
|
gltfExtensions: {
|
|
1095
906
|
RobotData: createStoredRenderable(shape, animatableValues)
|
|
@@ -1098,8 +909,8 @@ function InnerRenderedShape({
|
|
|
1098
909
|
}),
|
|
1099
910
|
[shape, animatableValues, selectionData]
|
|
1100
911
|
);
|
|
1101
|
-
const material = (0,
|
|
1102
|
-
const morphTargetSettings = (0,
|
|
912
|
+
const material = (0, import_react7.useRef)();
|
|
913
|
+
const morphTargetSettings = (0, import_react7.useMemo)(() => {
|
|
1103
914
|
if (shape.morphTargets) {
|
|
1104
915
|
const dictionary = shape.morphTargets.reduce(
|
|
1105
916
|
(acc, target, i) => ({ ...acc, [target]: i }),
|
|
@@ -1109,7 +920,7 @@ function InnerRenderedShape({
|
|
|
1109
920
|
const morphFeatureHandlers = {};
|
|
1110
921
|
shape.morphTargets.forEach((target, i) => {
|
|
1111
922
|
morphFeatureHandlers[target] = (value) => {
|
|
1112
|
-
if (ref.current?.morphTargetInfluences && (0,
|
|
923
|
+
if (ref.current?.morphTargetInfluences && (0, import_utils5.instanceOfRawNumber)(value)) {
|
|
1113
924
|
ref.current.morphTargetInfluences[i] = value;
|
|
1114
925
|
}
|
|
1115
926
|
};
|
|
@@ -1124,14 +935,14 @@ function InnerRenderedShape({
|
|
|
1124
935
|
shape.features,
|
|
1125
936
|
{
|
|
1126
937
|
translation: (pos) => {
|
|
1127
|
-
if (ref.current?.position && (0,
|
|
938
|
+
if (ref.current?.position && (0, import_utils5.instanceOfRawVector3)(pos)) {
|
|
1128
939
|
ref.current.position.set(
|
|
1129
940
|
pos.x,
|
|
1130
941
|
pos.y,
|
|
1131
942
|
pos.z
|
|
1132
943
|
);
|
|
1133
944
|
}
|
|
1134
|
-
if (refGroup.current?.position && (0,
|
|
945
|
+
if (refGroup.current?.position && (0, import_utils5.instanceOfRawVector3)(pos)) {
|
|
1135
946
|
refGroup.current.position.set(
|
|
1136
947
|
pos.x,
|
|
1137
948
|
pos.y,
|
|
@@ -1140,24 +951,24 @@ function InnerRenderedShape({
|
|
|
1140
951
|
}
|
|
1141
952
|
},
|
|
1142
953
|
rotation: (rot) => {
|
|
1143
|
-
if (ref.current?.rotation && (0,
|
|
954
|
+
if (ref.current?.rotation && (0, import_utils5.instanceOfRawEuler)(rot)) {
|
|
1144
955
|
ref.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
1145
956
|
}
|
|
1146
|
-
if (refGroup.current?.rotation && (0,
|
|
957
|
+
if (refGroup.current?.rotation && (0, import_utils5.instanceOfRawEuler)(rot)) {
|
|
1147
958
|
refGroup.current.rotation.set(rot.x, rot.y, rot.z, "ZYX");
|
|
1148
959
|
}
|
|
1149
960
|
},
|
|
1150
961
|
scale: (scale) => {
|
|
1151
|
-
if (ref.current?.scale && (0,
|
|
962
|
+
if (ref.current?.scale && (0, import_utils5.instanceOfRawVector3)(scale)) {
|
|
1152
963
|
ref.current.scale.set(scale.x, scale.y, scale.z);
|
|
1153
|
-
} else if (ref.current && (0,
|
|
964
|
+
} else if (ref.current && (0, import_utils5.instanceOfRawNumber)(scale)) {
|
|
1154
965
|
ref.current.scale.set(scale, scale, scale);
|
|
1155
966
|
} else if (ref.current) {
|
|
1156
967
|
ref.current.scale.set(1, 1, 1);
|
|
1157
968
|
}
|
|
1158
969
|
},
|
|
1159
970
|
opacity: (op) => {
|
|
1160
|
-
if (material.current?.opacity !== void 0 && (0,
|
|
971
|
+
if (material.current?.opacity !== void 0 && (0, import_utils5.instanceOfRawNumber)(op)) {
|
|
1161
972
|
material.current.opacity = op;
|
|
1162
973
|
if (op < 1) {
|
|
1163
974
|
material.current.transparent = true;
|
|
@@ -1168,21 +979,21 @@ function InnerRenderedShape({
|
|
|
1168
979
|
}
|
|
1169
980
|
},
|
|
1170
981
|
color: (color) => {
|
|
1171
|
-
if ((material.current || void 0)?.color && (0,
|
|
982
|
+
if ((material.current || void 0)?.color && (0, import_utils5.instanceOfRawRGB)(color)) {
|
|
1172
983
|
material.current.color.setRGB(
|
|
1173
984
|
color.r,
|
|
1174
985
|
color.g,
|
|
1175
986
|
color.b
|
|
1176
987
|
);
|
|
1177
988
|
material.current.needsUpdate = true;
|
|
1178
|
-
} else if ((material.current || void 0)?.color && (0,
|
|
989
|
+
} else if ((material.current || void 0)?.color && (0, import_utils5.instanceOfRawVector3)(color)) {
|
|
1179
990
|
material.current.color.setRGB(
|
|
1180
991
|
color.x,
|
|
1181
992
|
color.y,
|
|
1182
993
|
color.z
|
|
1183
994
|
);
|
|
1184
995
|
material.current.needsUpdate = true;
|
|
1185
|
-
} else if (material.current && (0,
|
|
996
|
+
} else if (material.current && (0, import_utils5.instanceOfRawHSL)(color)) {
|
|
1186
997
|
material.current.color.setHSL(
|
|
1187
998
|
color.h,
|
|
1188
999
|
color.s,
|
|
@@ -1194,22 +1005,22 @@ function InnerRenderedShape({
|
|
|
1194
1005
|
},
|
|
1195
1006
|
shape
|
|
1196
1007
|
);
|
|
1197
|
-
const setReference = useVizijStore((0,
|
|
1008
|
+
const setReference = useVizijStore((0, import_shallow5.useShallow)((state) => state.setReference));
|
|
1198
1009
|
const onElementClick = useVizijStore(
|
|
1199
|
-
(0,
|
|
1010
|
+
(0, import_shallow5.useShallow)((state) => state.onElementClick)
|
|
1200
1011
|
);
|
|
1201
1012
|
const setHoveredElement = useVizijStore(
|
|
1202
|
-
(0,
|
|
1013
|
+
(0, import_shallow5.useShallow)((state) => state.setHoveredElement)
|
|
1203
1014
|
);
|
|
1204
|
-
(0,
|
|
1015
|
+
(0, import_react7.useEffect)(() => {
|
|
1205
1016
|
if (ref.current && refIsNull) setReference(shape.id, namespace, ref);
|
|
1206
1017
|
}, [shape.id, namespace, ref, setReference, refIsNull]);
|
|
1207
|
-
(0,
|
|
1018
|
+
(0, import_react7.useEffect)(() => {
|
|
1208
1019
|
if (ref.current) {
|
|
1209
1020
|
ref.current.name = shape.name;
|
|
1210
1021
|
}
|
|
1211
1022
|
}, [shape.name]);
|
|
1212
|
-
(0,
|
|
1023
|
+
(0, import_react7.useEffect)(() => {
|
|
1213
1024
|
if (!material.current) {
|
|
1214
1025
|
return;
|
|
1215
1026
|
}
|
|
@@ -1219,21 +1030,21 @@ function InnerRenderedShape({
|
|
|
1219
1030
|
material.current.name = shape.name;
|
|
1220
1031
|
}
|
|
1221
1032
|
}, [materialName, shape.name]);
|
|
1222
|
-
const handlePointerOver = (0,
|
|
1033
|
+
const handlePointerOver = (0, import_react7.useCallback)(
|
|
1223
1034
|
(event) => {
|
|
1224
1035
|
event.stopPropagation();
|
|
1225
1036
|
setHoveredElement({ id, namespace, type: "shape" });
|
|
1226
1037
|
},
|
|
1227
1038
|
[id, namespace, setHoveredElement]
|
|
1228
1039
|
);
|
|
1229
|
-
const handlePointerOut = (0,
|
|
1040
|
+
const handlePointerOut = (0, import_react7.useCallback)(
|
|
1230
1041
|
(event) => {
|
|
1231
1042
|
event.stopPropagation();
|
|
1232
1043
|
setHoveredElement(null);
|
|
1233
1044
|
},
|
|
1234
1045
|
[setHoveredElement]
|
|
1235
1046
|
);
|
|
1236
|
-
return /* @__PURE__ */ (0,
|
|
1047
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1237
1048
|
"mesh",
|
|
1238
1049
|
{
|
|
1239
1050
|
ref,
|
|
@@ -1251,7 +1062,7 @@ function InnerRenderedShape({
|
|
|
1251
1062
|
onElementClick({ id, type: "shape", namespace }, [...chain, id], e);
|
|
1252
1063
|
},
|
|
1253
1064
|
children: [
|
|
1254
|
-
shape.material === "basic" && /* @__PURE__ */ (0,
|
|
1065
|
+
shape.material === "basic" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1255
1066
|
"meshBasicMaterial",
|
|
1256
1067
|
{
|
|
1257
1068
|
attach: "material",
|
|
@@ -1259,7 +1070,7 @@ function InnerRenderedShape({
|
|
|
1259
1070
|
side: THREE2.DoubleSide
|
|
1260
1071
|
}
|
|
1261
1072
|
),
|
|
1262
|
-
shape.material === "lambert" && /* @__PURE__ */ (0,
|
|
1073
|
+
shape.material === "lambert" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1263
1074
|
"meshLambertMaterial",
|
|
1264
1075
|
{
|
|
1265
1076
|
attach: "material",
|
|
@@ -1267,7 +1078,7 @@ function InnerRenderedShape({
|
|
|
1267
1078
|
side: THREE2.DoubleSide
|
|
1268
1079
|
}
|
|
1269
1080
|
),
|
|
1270
|
-
shape.material === "phong" && /* @__PURE__ */ (0,
|
|
1081
|
+
shape.material === "phong" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1271
1082
|
"meshPhongMaterial",
|
|
1272
1083
|
{
|
|
1273
1084
|
attach: "material",
|
|
@@ -1275,7 +1086,7 @@ function InnerRenderedShape({
|
|
|
1275
1086
|
side: THREE2.DoubleSide
|
|
1276
1087
|
}
|
|
1277
1088
|
),
|
|
1278
|
-
shape.material === "standard" && /* @__PURE__ */ (0,
|
|
1089
|
+
shape.material === "standard" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1279
1090
|
"meshStandardMaterial",
|
|
1280
1091
|
{
|
|
1281
1092
|
attach: "material",
|
|
@@ -1283,7 +1094,7 @@ function InnerRenderedShape({
|
|
|
1283
1094
|
side: THREE2.DoubleSide
|
|
1284
1095
|
}
|
|
1285
1096
|
),
|
|
1286
|
-
shape.material === "normal" && /* @__PURE__ */ (0,
|
|
1097
|
+
shape.material === "normal" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1287
1098
|
"meshNormalMaterial",
|
|
1288
1099
|
{
|
|
1289
1100
|
attach: "material",
|
|
@@ -1291,7 +1102,7 @@ function InnerRenderedShape({
|
|
|
1291
1102
|
side: THREE2.DoubleSide
|
|
1292
1103
|
}
|
|
1293
1104
|
),
|
|
1294
|
-
shape.children?.map((child) => /* @__PURE__ */ (0,
|
|
1105
|
+
shape.children?.map((child) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1295
1106
|
Renderable,
|
|
1296
1107
|
{
|
|
1297
1108
|
id: child,
|
|
@@ -1304,7 +1115,7 @@ function InnerRenderedShape({
|
|
|
1304
1115
|
}
|
|
1305
1116
|
);
|
|
1306
1117
|
}
|
|
1307
|
-
var RenderedShape = (0,
|
|
1118
|
+
var RenderedShape = (0, import_react7.memo)(InnerRenderedShape);
|
|
1308
1119
|
var MATERIAL_FEATURE_KEYS = [
|
|
1309
1120
|
"color",
|
|
1310
1121
|
"opacity",
|
|
@@ -1352,15 +1163,15 @@ function extractMaterialName(name) {
|
|
|
1352
1163
|
}
|
|
1353
1164
|
|
|
1354
1165
|
// src/renderables/renderable.tsx
|
|
1355
|
-
var
|
|
1166
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1356
1167
|
function InnerRenderable({
|
|
1357
1168
|
id,
|
|
1358
1169
|
namespace,
|
|
1359
1170
|
chain
|
|
1360
1171
|
}) {
|
|
1361
|
-
const type = useVizijStore((0,
|
|
1362
|
-
const refs = useVizijStore((0,
|
|
1363
|
-
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)(() => {
|
|
1364
1175
|
let namespaces = [namespace];
|
|
1365
1176
|
if (namespace in refs) {
|
|
1366
1177
|
namespaces = [namespace];
|
|
@@ -1372,10 +1183,10 @@ function InnerRenderable({
|
|
|
1372
1183
|
if (resolvedNamespaces.length === 0) {
|
|
1373
1184
|
return null;
|
|
1374
1185
|
}
|
|
1375
|
-
return /* @__PURE__ */ (0,
|
|
1186
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: resolvedNamespaces.map((ns) => {
|
|
1376
1187
|
switch (type) {
|
|
1377
1188
|
case "group":
|
|
1378
|
-
return /* @__PURE__ */ (0,
|
|
1189
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1379
1190
|
RenderedGroup,
|
|
1380
1191
|
{
|
|
1381
1192
|
id,
|
|
@@ -1385,7 +1196,7 @@ function InnerRenderable({
|
|
|
1385
1196
|
`${ns}.${id}`
|
|
1386
1197
|
);
|
|
1387
1198
|
case "ellipse":
|
|
1388
|
-
return /* @__PURE__ */ (0,
|
|
1199
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1389
1200
|
RenderedEllipse,
|
|
1390
1201
|
{
|
|
1391
1202
|
id,
|
|
@@ -1395,7 +1206,7 @@ function InnerRenderable({
|
|
|
1395
1206
|
`${ns}.${id}`
|
|
1396
1207
|
);
|
|
1397
1208
|
case "rectangle":
|
|
1398
|
-
return /* @__PURE__ */ (0,
|
|
1209
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1399
1210
|
RenderedRectangle,
|
|
1400
1211
|
{
|
|
1401
1212
|
id,
|
|
@@ -1405,7 +1216,7 @@ function InnerRenderable({
|
|
|
1405
1216
|
`${ns}.${id}`
|
|
1406
1217
|
);
|
|
1407
1218
|
case "shape":
|
|
1408
|
-
return /* @__PURE__ */ (0,
|
|
1219
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1409
1220
|
RenderedShape,
|
|
1410
1221
|
{
|
|
1411
1222
|
id,
|
|
@@ -1419,17 +1230,17 @@ function InnerRenderable({
|
|
|
1419
1230
|
}
|
|
1420
1231
|
}) });
|
|
1421
1232
|
}
|
|
1422
|
-
var Renderable = (0,
|
|
1233
|
+
var Renderable = (0, import_react8.memo)(InnerRenderable);
|
|
1423
1234
|
|
|
1424
1235
|
// src/store.ts
|
|
1425
1236
|
var import_zustand2 = require("zustand");
|
|
1426
1237
|
var import_middleware = require("zustand/middleware");
|
|
1427
1238
|
var import_immer = require("immer");
|
|
1428
1239
|
var THREE3 = __toESM(require("three"));
|
|
1429
|
-
var
|
|
1240
|
+
var import_utils6 = require("@vizij/utils");
|
|
1430
1241
|
|
|
1431
1242
|
// src/actions/create-new-element.ts
|
|
1432
|
-
var
|
|
1243
|
+
var import_react9 = require("react");
|
|
1433
1244
|
var import_lodash3 = require("lodash");
|
|
1434
1245
|
|
|
1435
1246
|
// src/functions/create-world-element.ts
|
|
@@ -1459,7 +1270,7 @@ function createNewElement(state, type, root = false) {
|
|
|
1459
1270
|
});
|
|
1460
1271
|
if (Object.entries(state.world).length === 0) {
|
|
1461
1272
|
const name = `New-Root`;
|
|
1462
|
-
const refs = { default: (0,
|
|
1273
|
+
const refs = { default: (0, import_react9.createRef)() };
|
|
1463
1274
|
const newElement = createDefaultGroup({
|
|
1464
1275
|
name,
|
|
1465
1276
|
root: true,
|
|
@@ -1477,7 +1288,7 @@ function createNewElement(state, type, root = false) {
|
|
|
1477
1288
|
const name = `New-Body`;
|
|
1478
1289
|
const refs = (0, import_lodash3.mapValues)(
|
|
1479
1290
|
worldRootEntry.refs,
|
|
1480
|
-
() => (0,
|
|
1291
|
+
() => (0, import_react9.createRef)()
|
|
1481
1292
|
);
|
|
1482
1293
|
const newChild = createDefaultGroup({ name, root, refs });
|
|
1483
1294
|
worldRootEntry.children.push(newChild.id);
|
|
@@ -1722,7 +1533,7 @@ var VizijSlice = (set, get) => ({
|
|
|
1722
1533
|
setValue: (id, namespace, value) => {
|
|
1723
1534
|
set(
|
|
1724
1535
|
(0, import_immer.produce)((state) => {
|
|
1725
|
-
const lookupId = (0,
|
|
1536
|
+
const lookupId = (0, import_utils6.getLookup)(namespace, id);
|
|
1726
1537
|
if (typeof value === "function") {
|
|
1727
1538
|
const current = state.values.get(lookupId);
|
|
1728
1539
|
if (current !== void 0) {
|
|
@@ -1869,8 +1680,8 @@ var VizijSlice = (set, get) => ({
|
|
|
1869
1680
|
setSlot: (parentId, parentNamespace, childId, childNamespace) => {
|
|
1870
1681
|
set(
|
|
1871
1682
|
(0, import_immer.produce)((state) => {
|
|
1872
|
-
const parentLookupId = (0,
|
|
1873
|
-
const childLookupId = (0,
|
|
1683
|
+
const parentLookupId = (0, import_utils6.getLookup)(parentNamespace, parentId);
|
|
1684
|
+
const childLookupId = (0, import_utils6.getLookup)(childNamespace, childId);
|
|
1874
1685
|
state.slotConfig[parentLookupId] = childLookupId;
|
|
1875
1686
|
})
|
|
1876
1687
|
);
|
|
@@ -1889,7 +1700,7 @@ var VizijSlice = (set, get) => ({
|
|
|
1889
1700
|
clearSlot: (parentId, parentNamespace) => {
|
|
1890
1701
|
set(
|
|
1891
1702
|
(0, import_immer.produce)((state) => {
|
|
1892
|
-
const parentLookupId = (0,
|
|
1703
|
+
const parentLookupId = (0, import_utils6.getLookup)(parentNamespace, parentId);
|
|
1893
1704
|
delete state.slotConfig[parentLookupId];
|
|
1894
1705
|
})
|
|
1895
1706
|
);
|
|
@@ -1939,7 +1750,7 @@ var createVizijStore = (initial) => (0, import_zustand2.create)()(
|
|
|
1939
1750
|
);
|
|
1940
1751
|
|
|
1941
1752
|
// src/vizij.tsx
|
|
1942
|
-
var
|
|
1753
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1943
1754
|
import_three.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
1944
1755
|
function Vizij({
|
|
1945
1756
|
style,
|
|
@@ -1949,16 +1760,16 @@ function Vizij({
|
|
|
1949
1760
|
showSafeArea = false,
|
|
1950
1761
|
onPointerMissed
|
|
1951
1762
|
}) {
|
|
1952
|
-
const ctx = (0,
|
|
1763
|
+
const ctx = (0, import_react10.useContext)(VizijContext);
|
|
1953
1764
|
if (ctx) {
|
|
1954
|
-
return /* @__PURE__ */ (0,
|
|
1765
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1955
1766
|
import_fiber.Canvas,
|
|
1956
1767
|
{
|
|
1957
1768
|
shadows: false,
|
|
1958
1769
|
style,
|
|
1959
1770
|
className,
|
|
1960
1771
|
onPointerMissed,
|
|
1961
|
-
children: /* @__PURE__ */ (0,
|
|
1772
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1962
1773
|
MemoizedInnerVizij,
|
|
1963
1774
|
{
|
|
1964
1775
|
rootId,
|
|
@@ -1969,13 +1780,13 @@ function Vizij({
|
|
|
1969
1780
|
}
|
|
1970
1781
|
);
|
|
1971
1782
|
} else {
|
|
1972
|
-
return /* @__PURE__ */ (0,
|
|
1783
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(VizijContext.Provider, { value: useDefaultVizijStore, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1973
1784
|
import_fiber.Canvas,
|
|
1974
1785
|
{
|
|
1975
1786
|
style,
|
|
1976
1787
|
className,
|
|
1977
1788
|
onPointerMissed,
|
|
1978
|
-
children: /* @__PURE__ */ (0,
|
|
1789
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1979
1790
|
MemoizedInnerVizij,
|
|
1980
1791
|
{
|
|
1981
1792
|
rootId,
|
|
@@ -1997,9 +1808,9 @@ function InnerVizij({
|
|
|
1997
1808
|
width: container.width * container.resolution,
|
|
1998
1809
|
height: container.height * container.resolution
|
|
1999
1810
|
} : void 0;
|
|
2000
|
-
return /* @__PURE__ */ (0,
|
|
2001
|
-
/* @__PURE__ */ (0,
|
|
2002
|
-
/* @__PURE__ */ (0,
|
|
1811
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1812
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ambientLight", { intensity: Math.PI / 2 }),
|
|
1813
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2003
1814
|
import_drei3.OrthographicCamera,
|
|
2004
1815
|
{
|
|
2005
1816
|
makeDefault: true,
|
|
@@ -2008,7 +1819,7 @@ function InnerVizij({
|
|
|
2008
1819
|
far: 101
|
|
2009
1820
|
}
|
|
2010
1821
|
),
|
|
2011
|
-
/* @__PURE__ */ (0,
|
|
1822
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react10.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2012
1823
|
World,
|
|
2013
1824
|
{
|
|
2014
1825
|
rootId,
|
|
@@ -2016,17 +1827,17 @@ function InnerVizij({
|
|
|
2016
1827
|
parentSizing: sceneParentSizing
|
|
2017
1828
|
}
|
|
2018
1829
|
) }),
|
|
2019
|
-
showSafeArea && /* @__PURE__ */ (0,
|
|
1830
|
+
showSafeArea && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SafeAreaRenderer, { rootId })
|
|
2020
1831
|
] });
|
|
2021
1832
|
}
|
|
2022
|
-
var MemoizedInnerVizij = (0,
|
|
1833
|
+
var MemoizedInnerVizij = (0, import_react10.memo)(InnerVizij);
|
|
2023
1834
|
function InnerWorld({
|
|
2024
1835
|
rootId,
|
|
2025
1836
|
namespace = "default",
|
|
2026
1837
|
parentSizing
|
|
2027
1838
|
}) {
|
|
2028
1839
|
const [present, rootBounds] = useVizijStore(
|
|
2029
|
-
(0,
|
|
1840
|
+
(0, import_shallow7.useShallow)((state) => {
|
|
2030
1841
|
const group = state.world[rootId];
|
|
2031
1842
|
const bounds = group?.rootBounds ?? defaultRootBounds;
|
|
2032
1843
|
return [group !== void 0, bounds];
|
|
@@ -2036,7 +1847,7 @@ function InnerWorld({
|
|
|
2036
1847
|
camera: state.camera,
|
|
2037
1848
|
size: state.size
|
|
2038
1849
|
}));
|
|
2039
|
-
(0,
|
|
1850
|
+
(0, import_react10.useEffect)(() => {
|
|
2040
1851
|
const width = rootBounds.size.x;
|
|
2041
1852
|
const height = rootBounds.size.y;
|
|
2042
1853
|
if (camera && parentSizing === void 0 && camera.isOrthographicCamera) {
|
|
@@ -2064,9 +1875,9 @@ function InnerWorld({
|
|
|
2064
1875
|
camera.updateProjectionMatrix();
|
|
2065
1876
|
}
|
|
2066
1877
|
}, [rootBounds, camera, parentSizing, size]);
|
|
2067
|
-
return /* @__PURE__ */ (0,
|
|
2068
|
-
present && /* @__PURE__ */ (0,
|
|
2069
|
-
!present && /* @__PURE__ */ (0,
|
|
1878
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_error_boundary.ErrorBoundary, { fallback: null, children: [
|
|
1879
|
+
present && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Renderable, { id: rootId, namespace, chain: [] }),
|
|
1880
|
+
!present && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2070
1881
|
import_drei3.Text,
|
|
2071
1882
|
{
|
|
2072
1883
|
position: [0, 0, 0],
|
|
@@ -2079,7 +1890,7 @@ function InnerWorld({
|
|
|
2079
1890
|
)
|
|
2080
1891
|
] });
|
|
2081
1892
|
}
|
|
2082
|
-
var World = (0,
|
|
1893
|
+
var World = (0, import_react10.memo)(InnerWorld);
|
|
2083
1894
|
function SafeAreaRenderer({ rootId }) {
|
|
2084
1895
|
const rootBounds = useVizijStore((state) => {
|
|
2085
1896
|
const group = state.world[rootId];
|
|
@@ -2089,7 +1900,7 @@ function SafeAreaRenderer({ rootId }) {
|
|
|
2089
1900
|
const right = rootBounds.center.x + rootBounds.size.x / 2;
|
|
2090
1901
|
const top = rootBounds.center.y + rootBounds.size.y / 2;
|
|
2091
1902
|
const bottom = rootBounds.center.y - rootBounds.size.y / 2;
|
|
2092
|
-
return /* @__PURE__ */ (0,
|
|
1903
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2093
1904
|
import_drei3.Line,
|
|
2094
1905
|
{
|
|
2095
1906
|
points: [
|
|
@@ -2120,11 +1931,11 @@ var ShapeMaterial = /* @__PURE__ */ ((ShapeMaterial2) => {
|
|
|
2120
1931
|
})(ShapeMaterial || {});
|
|
2121
1932
|
|
|
2122
1933
|
// src/hooks/use-vizij-store-subscription.ts
|
|
2123
|
-
var
|
|
1934
|
+
var import_react11 = require("react");
|
|
2124
1935
|
function useVizijStoreSubscription(selector, listener) {
|
|
2125
|
-
const store = (0,
|
|
1936
|
+
const store = (0, import_react11.useContext)(VizijContext);
|
|
2126
1937
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2127
|
-
(0,
|
|
1938
|
+
(0, import_react11.useEffect)(() => {
|
|
2128
1939
|
const initialValue = selector(store.getState());
|
|
2129
1940
|
listener(initialValue);
|
|
2130
1941
|
return store.subscribe(selector, listener);
|
|
@@ -2132,17 +1943,17 @@ function useVizijStoreSubscription(selector, listener) {
|
|
|
2132
1943
|
}
|
|
2133
1944
|
|
|
2134
1945
|
// src/hooks/use-vizij-store-setter.ts
|
|
2135
|
-
var
|
|
1946
|
+
var import_react12 = require("react");
|
|
2136
1947
|
function useVizijStoreSetter() {
|
|
2137
|
-
const store = (0,
|
|
1948
|
+
const store = (0, import_react12.useContext)(VizijContext);
|
|
2138
1949
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2139
1950
|
return store.setState;
|
|
2140
1951
|
}
|
|
2141
1952
|
|
|
2142
1953
|
// src/hooks/use-vizij-store-getter.ts
|
|
2143
|
-
var
|
|
1954
|
+
var import_react13 = require("react");
|
|
2144
1955
|
function useVizijStoreGetter() {
|
|
2145
|
-
const store = (0,
|
|
1956
|
+
const store = (0, import_react13.useContext)(VizijContext);
|
|
2146
1957
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2147
1958
|
return store.getState;
|
|
2148
1959
|
}
|
|
@@ -2152,7 +1963,7 @@ var THREE5 = __toESM(require("three"));
|
|
|
2152
1963
|
var import_three_stdlib = require("three-stdlib");
|
|
2153
1964
|
|
|
2154
1965
|
// src/functions/gltf-loading/traverse-three.ts
|
|
2155
|
-
var
|
|
1966
|
+
var import_react15 = require("react");
|
|
2156
1967
|
var THREE4 = __toESM(require("three"));
|
|
2157
1968
|
|
|
2158
1969
|
// src/functions/gltf-loading/map-features.ts
|
|
@@ -2184,9 +1995,9 @@ var import_three4 = require("three");
|
|
|
2184
1995
|
var import_three3 = require("three");
|
|
2185
1996
|
|
|
2186
1997
|
// src/functions/util.ts
|
|
2187
|
-
var
|
|
1998
|
+
var import_react14 = require("react");
|
|
2188
1999
|
function namespaceArrayToRefs(namespaces) {
|
|
2189
|
-
return namespaces.reduce((acc, ns) => ({ ...acc, [ns]: (0,
|
|
2000
|
+
return namespaces.reduce((acc, ns) => ({ ...acc, [ns]: (0, import_react14.createRef)() }), {});
|
|
2190
2001
|
}
|
|
2191
2002
|
|
|
2192
2003
|
// src/functions/gltf-loading/import-mesh.ts
|
|
@@ -2521,7 +2332,9 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2521
2332
|
});
|
|
2522
2333
|
const useRobotData = !aggressiveImport || hasRobotData;
|
|
2523
2334
|
if (useRobotData) {
|
|
2524
|
-
|
|
2335
|
+
const stack = [group];
|
|
2336
|
+
while (stack.length > 0) {
|
|
2337
|
+
const child = stack.pop();
|
|
2525
2338
|
if (child.userData?.gltfExtensions?.RobotData) {
|
|
2526
2339
|
const data = child.userData.gltfExtensions.RobotData;
|
|
2527
2340
|
applyStoredRenderableNames(child, data);
|
|
@@ -2533,7 +2346,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2533
2346
|
loadedData = {
|
|
2534
2347
|
...data,
|
|
2535
2348
|
refs: namespaces.reduce(
|
|
2536
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2349
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2537
2350
|
{}
|
|
2538
2351
|
)
|
|
2539
2352
|
};
|
|
@@ -2548,7 +2361,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2548
2361
|
...data,
|
|
2549
2362
|
geometry: child.geometry,
|
|
2550
2363
|
refs: namespaces.reduce(
|
|
2551
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2364
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2552
2365
|
{}
|
|
2553
2366
|
)
|
|
2554
2367
|
};
|
|
@@ -2562,7 +2375,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2562
2375
|
loadedData = {
|
|
2563
2376
|
...data,
|
|
2564
2377
|
refs: namespaces.reduce(
|
|
2565
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2378
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2566
2379
|
{}
|
|
2567
2380
|
)
|
|
2568
2381
|
};
|
|
@@ -2576,7 +2389,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2576
2389
|
loadedData = {
|
|
2577
2390
|
...data,
|
|
2578
2391
|
refs: namespaces.reduce(
|
|
2579
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2392
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2580
2393
|
{}
|
|
2581
2394
|
)
|
|
2582
2395
|
};
|
|
@@ -2590,7 +2403,10 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2590
2403
|
throw new Error(`Unhandled type`);
|
|
2591
2404
|
}
|
|
2592
2405
|
}
|
|
2593
|
-
|
|
2406
|
+
if (child.children) {
|
|
2407
|
+
stack.push(...child.children);
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2594
2410
|
} else {
|
|
2595
2411
|
const derivedRootBounds = rootBounds ?? deriveRootBounds(group);
|
|
2596
2412
|
if (!derivedRootBounds) {
|
|
@@ -2758,6 +2574,106 @@ function deriveRootBounds(group) {
|
|
|
2758
2574
|
};
|
|
2759
2575
|
}
|
|
2760
2576
|
|
|
2577
|
+
// src/functions/vizij-bundle.ts
|
|
2578
|
+
var BUNDLE_KEYS = ["VIZIJ_bundle"];
|
|
2579
|
+
function cloneBundle(value) {
|
|
2580
|
+
return JSON.parse(JSON.stringify(value));
|
|
2581
|
+
}
|
|
2582
|
+
function readExtensionValue(extensionContainer) {
|
|
2583
|
+
for (const key of BUNDLE_KEYS) {
|
|
2584
|
+
if (extensionContainer && Object.prototype.hasOwnProperty.call(extensionContainer, key)) {
|
|
2585
|
+
const value = extensionContainer[key];
|
|
2586
|
+
if (value && typeof value === "object") {
|
|
2587
|
+
return { key, value };
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
return null;
|
|
2592
|
+
}
|
|
2593
|
+
function searchObjectForBundle(object) {
|
|
2594
|
+
const stack = [object];
|
|
2595
|
+
while (stack.length > 0) {
|
|
2596
|
+
const current = stack.pop();
|
|
2597
|
+
const extensions = current?.userData?.gltfExtensions ?? current?.userData?.extensions ?? null;
|
|
2598
|
+
if (extensions && typeof extensions === "object") {
|
|
2599
|
+
const match = readExtensionValue(extensions);
|
|
2600
|
+
if (match) {
|
|
2601
|
+
return cloneBundle(match.value);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
if (current.children && current.children.length > 0) {
|
|
2605
|
+
stack.push(...current.children);
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
return null;
|
|
2609
|
+
}
|
|
2610
|
+
function searchParserJsonForBundle(parserJson) {
|
|
2611
|
+
if (!parserJson || typeof parserJson !== "object") {
|
|
2612
|
+
return null;
|
|
2613
|
+
}
|
|
2614
|
+
const nodes = Array.isArray(parserJson.nodes) ? parserJson.nodes : [];
|
|
2615
|
+
for (const node of nodes) {
|
|
2616
|
+
const extensions = node && typeof node === "object" ? node.extensions : null;
|
|
2617
|
+
if (extensions && typeof extensions === "object") {
|
|
2618
|
+
const match = readExtensionValue(extensions);
|
|
2619
|
+
if (match) {
|
|
2620
|
+
return cloneBundle(match.value);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
const scenes = Array.isArray(parserJson.scenes) ? parserJson.scenes : [];
|
|
2625
|
+
for (const scene of scenes) {
|
|
2626
|
+
const extensions = scene && typeof scene === "object" ? scene.extensions : null;
|
|
2627
|
+
if (extensions && typeof extensions === "object") {
|
|
2628
|
+
const match = readExtensionValue(extensions);
|
|
2629
|
+
if (match) {
|
|
2630
|
+
return cloneBundle(match.value);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
return null;
|
|
2635
|
+
}
|
|
2636
|
+
function extractVizijBundle(object, parserJson) {
|
|
2637
|
+
const fromObject = searchObjectForBundle(object);
|
|
2638
|
+
if (fromObject) {
|
|
2639
|
+
return fromObject;
|
|
2640
|
+
}
|
|
2641
|
+
const fromParser = searchParserJsonForBundle(parserJson);
|
|
2642
|
+
if (fromParser) {
|
|
2643
|
+
return fromParser;
|
|
2644
|
+
}
|
|
2645
|
+
return null;
|
|
2646
|
+
}
|
|
2647
|
+
function applyVizijBundle(object, bundle) {
|
|
2648
|
+
const userData = object.userData && typeof object.userData === "object" ? object.userData : {};
|
|
2649
|
+
const originalExtensions = userData.gltfExtensions;
|
|
2650
|
+
let applied = false;
|
|
2651
|
+
if (bundle) {
|
|
2652
|
+
userData.gltfExtensions = {
|
|
2653
|
+
...originalExtensions ?? {},
|
|
2654
|
+
VIZIJ_bundle: bundle
|
|
2655
|
+
};
|
|
2656
|
+
object.userData = userData;
|
|
2657
|
+
applied = true;
|
|
2658
|
+
}
|
|
2659
|
+
return () => {
|
|
2660
|
+
if (!applied) {
|
|
2661
|
+
return;
|
|
2662
|
+
}
|
|
2663
|
+
if (originalExtensions) {
|
|
2664
|
+
userData.gltfExtensions = originalExtensions;
|
|
2665
|
+
} else {
|
|
2666
|
+
if (userData.gltfExtensions) {
|
|
2667
|
+
delete userData.gltfExtensions;
|
|
2668
|
+
}
|
|
2669
|
+
if (Object.keys(userData).length === 0) {
|
|
2670
|
+
delete object.userData;
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
applied = false;
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2761
2677
|
// src/functions/load-gltf.ts
|
|
2762
2678
|
THREE5.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
2763
2679
|
var EmptyModelError = class extends Error {
|
|
@@ -2771,19 +2687,91 @@ async function loadGLTF(url, namespaces, aggressiveImport = false, rootBounds) {
|
|
|
2771
2687
|
modelLoader.setDRACOLoader(new import_three_stdlib.DRACOLoader());
|
|
2772
2688
|
const modelData = await modelLoader.loadAsync(url);
|
|
2773
2689
|
const actualizedNamespaces = namespaces.length > 0 ? namespaces : ["default"];
|
|
2774
|
-
|
|
2690
|
+
const asset = parseScene(
|
|
2775
2691
|
modelData.scene,
|
|
2776
2692
|
actualizedNamespaces,
|
|
2777
2693
|
aggressiveImport,
|
|
2778
|
-
rootBounds
|
|
2694
|
+
rootBounds,
|
|
2695
|
+
modelData?.parser?.json
|
|
2779
2696
|
);
|
|
2697
|
+
return [asset.world, asset.animatables];
|
|
2780
2698
|
}
|
|
2781
2699
|
async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, rootBounds) {
|
|
2782
2700
|
const actualizedNamespaces = namespaces.length > 0 ? namespaces : ["default"];
|
|
2783
2701
|
if (typeof URL !== "undefined" && typeof URL.createObjectURL === "function") {
|
|
2784
2702
|
const objectUrl = URL.createObjectURL(blob);
|
|
2785
2703
|
try {
|
|
2786
|
-
|
|
2704
|
+
const asset = await loadGLTFWithBundle(
|
|
2705
|
+
objectUrl,
|
|
2706
|
+
actualizedNamespaces,
|
|
2707
|
+
aggressiveImport,
|
|
2708
|
+
rootBounds
|
|
2709
|
+
);
|
|
2710
|
+
return [asset.world, asset.animatables];
|
|
2711
|
+
} finally {
|
|
2712
|
+
URL.revokeObjectURL(objectUrl);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
const arrayBuffer = typeof blob.arrayBuffer === "function" ? await blob.arrayBuffer() : await new Response(blob).arrayBuffer();
|
|
2716
|
+
return new Promise((resolve, reject) => {
|
|
2717
|
+
const loader = new import_three_stdlib.GLTFLoader();
|
|
2718
|
+
loader.setDRACOLoader(new import_three_stdlib.DRACOLoader());
|
|
2719
|
+
loader.parse(
|
|
2720
|
+
arrayBuffer,
|
|
2721
|
+
"",
|
|
2722
|
+
(gltf) => {
|
|
2723
|
+
try {
|
|
2724
|
+
const asset = parseScene(
|
|
2725
|
+
gltf.scene,
|
|
2726
|
+
actualizedNamespaces,
|
|
2727
|
+
aggressiveImport,
|
|
2728
|
+
rootBounds,
|
|
2729
|
+
gltf?.parser?.json
|
|
2730
|
+
);
|
|
2731
|
+
resolve([asset.world, asset.animatables]);
|
|
2732
|
+
} catch (error) {
|
|
2733
|
+
if (error instanceof Error) {
|
|
2734
|
+
reject(error);
|
|
2735
|
+
} else {
|
|
2736
|
+
reject(new Error(String(error)));
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
},
|
|
2740
|
+
(error) => {
|
|
2741
|
+
reject(new Error(`Error loading GLTF: ${error.message}`));
|
|
2742
|
+
}
|
|
2743
|
+
);
|
|
2744
|
+
});
|
|
2745
|
+
}
|
|
2746
|
+
function parseScene(scene, namespaces, aggressiveImport, rootBounds, parserJson) {
|
|
2747
|
+
const [world, animatables] = traverseThree(
|
|
2748
|
+
scene,
|
|
2749
|
+
namespaces,
|
|
2750
|
+
aggressiveImport,
|
|
2751
|
+
rootBounds
|
|
2752
|
+
);
|
|
2753
|
+
const bundle = extractVizijBundle(scene, parserJson);
|
|
2754
|
+
return { world, animatables, bundle };
|
|
2755
|
+
}
|
|
2756
|
+
async function loadGLTFWithBundle(url, namespaces, aggressiveImport = false, rootBounds) {
|
|
2757
|
+
const modelLoader = new import_three_stdlib.GLTFLoader();
|
|
2758
|
+
modelLoader.setDRACOLoader(new import_three_stdlib.DRACOLoader());
|
|
2759
|
+
const modelData = await modelLoader.loadAsync(url);
|
|
2760
|
+
const actualizedNamespaces = namespaces.length > 0 ? namespaces : ["default"];
|
|
2761
|
+
return parseScene(
|
|
2762
|
+
modelData.scene,
|
|
2763
|
+
actualizedNamespaces,
|
|
2764
|
+
aggressiveImport,
|
|
2765
|
+
rootBounds,
|
|
2766
|
+
modelData?.parser?.json
|
|
2767
|
+
);
|
|
2768
|
+
}
|
|
2769
|
+
async function loadGLTFFromBlobWithBundle(blob, namespaces, aggressiveImport = false, rootBounds) {
|
|
2770
|
+
const actualizedNamespaces = namespaces.length > 0 ? namespaces : ["default"];
|
|
2771
|
+
if (typeof URL !== "undefined" && typeof URL.createObjectURL === "function") {
|
|
2772
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
2773
|
+
try {
|
|
2774
|
+
return await loadGLTFWithBundle(
|
|
2787
2775
|
objectUrl,
|
|
2788
2776
|
actualizedNamespaces,
|
|
2789
2777
|
aggressiveImport,
|
|
@@ -2802,14 +2790,14 @@ async function loadGLTFFromBlob(blob, namespaces, aggressiveImport = false, root
|
|
|
2802
2790
|
"",
|
|
2803
2791
|
(gltf) => {
|
|
2804
2792
|
try {
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
)
|
|
2793
|
+
const asset = parseScene(
|
|
2794
|
+
gltf.scene,
|
|
2795
|
+
actualizedNamespaces,
|
|
2796
|
+
aggressiveImport,
|
|
2797
|
+
rootBounds,
|
|
2798
|
+
gltf?.parser?.json
|
|
2812
2799
|
);
|
|
2800
|
+
resolve(asset);
|
|
2813
2801
|
} catch (error) {
|
|
2814
2802
|
if (error instanceof Error) {
|
|
2815
2803
|
reject(error);
|
|
@@ -2858,7 +2846,11 @@ var loadGltfFromBlob = (blob, namespaces) => {
|
|
|
2858
2846
|
var import_three_stdlib3 = require("three-stdlib");
|
|
2859
2847
|
var THREE6 = __toESM(require("three"));
|
|
2860
2848
|
THREE6.Object3D.DEFAULT_UP.set(0, 0, 1);
|
|
2861
|
-
function exportScene(data,
|
|
2849
|
+
function exportScene(data, fileNameOrOptions = "scene.glb") {
|
|
2850
|
+
const options = typeof fileNameOrOptions === "string" ? { fileName: fileNameOrOptions } : fileNameOrOptions ?? {};
|
|
2851
|
+
const fileName = options.fileName ?? "scene.glb";
|
|
2852
|
+
const animationClips = Array.isArray(options.animations) ? options.animations.filter(Boolean) : [];
|
|
2853
|
+
const shouldAttachBundle = Boolean(options.bundle);
|
|
2862
2854
|
const exporter = new import_three_stdlib3.GLTFExporter();
|
|
2863
2855
|
exporter.register(() => ({
|
|
2864
2856
|
writeMesh(mesh, meshDef) {
|
|
@@ -2868,48 +2860,65 @@ function exportScene(data, fileName = "scene.glb") {
|
|
|
2868
2860
|
}
|
|
2869
2861
|
}
|
|
2870
2862
|
}));
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2863
|
+
const detachBundle = shouldAttachBundle && options.bundle ? applyVizijBundle(data, options.bundle) : () => {
|
|
2864
|
+
};
|
|
2865
|
+
const binary = options.binary ?? true;
|
|
2866
|
+
const exporterOptions = {
|
|
2867
|
+
trs: true,
|
|
2868
|
+
onlyVisible: false,
|
|
2869
|
+
binary,
|
|
2870
|
+
includeCustomExtensions: true
|
|
2871
|
+
};
|
|
2872
|
+
if (animationClips.length > 0) {
|
|
2873
|
+
exporterOptions.animations = animationClips;
|
|
2874
|
+
}
|
|
2875
|
+
try {
|
|
2876
|
+
exporter.parse(
|
|
2877
|
+
data,
|
|
2878
|
+
(gltf) => {
|
|
2879
|
+
detachBundle();
|
|
2880
|
+
if (!(gltf instanceof ArrayBuffer)) {
|
|
2881
|
+
throw new Error("Failed to export scene!");
|
|
2882
|
+
}
|
|
2883
|
+
const link = document.createElement("a");
|
|
2884
|
+
link.href = URL.createObjectURL(
|
|
2885
|
+
new Blob([gltf], {
|
|
2886
|
+
type: "application/octet-stream"
|
|
2887
|
+
})
|
|
2888
|
+
);
|
|
2889
|
+
const trimmed = fileName.trim();
|
|
2890
|
+
const safeFileName = trimmed.length > 0 ? trimmed : "scene.glb";
|
|
2891
|
+
const downloadName = safeFileName.toLowerCase().endsWith(".glb") ? safeFileName : `${safeFileName}.glb`;
|
|
2892
|
+
link.download = downloadName;
|
|
2893
|
+
link.click();
|
|
2894
|
+
URL.revokeObjectURL(link.href);
|
|
2895
|
+
},
|
|
2896
|
+
() => {
|
|
2897
|
+
detachBundle();
|
|
2898
|
+
},
|
|
2899
|
+
exporterOptions
|
|
2900
|
+
);
|
|
2901
|
+
} catch (error) {
|
|
2902
|
+
detachBundle();
|
|
2903
|
+
throw error;
|
|
2904
|
+
}
|
|
2899
2905
|
}
|
|
2900
2906
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2901
2907
|
0 && (module.exports = {
|
|
2902
|
-
Controller,
|
|
2903
2908
|
EmptyModelError,
|
|
2904
2909
|
InnerVizij,
|
|
2905
2910
|
ShapeMaterial,
|
|
2906
2911
|
Vizij,
|
|
2907
2912
|
VizijContext,
|
|
2908
2913
|
VizijSlice,
|
|
2914
|
+
applyVizijBundle,
|
|
2909
2915
|
createVizijStore,
|
|
2910
2916
|
exportScene,
|
|
2917
|
+
extractVizijBundle,
|
|
2911
2918
|
loadGLTF,
|
|
2912
2919
|
loadGLTFFromBlob,
|
|
2920
|
+
loadGLTFFromBlobWithBundle,
|
|
2921
|
+
loadGLTFWithBundle,
|
|
2913
2922
|
loadGltfFromBlob,
|
|
2914
2923
|
useDefaultVizijStore,
|
|
2915
2924
|
useFeatures,
|