@vizij/render 0.0.3 → 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/dist/index.d.mts +2 -10
- package/dist/index.d.ts +2 -10
- package/dist/index.js +231 -425
- package/dist/index.mjs +96 -291
- 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,16 @@ 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
|
-
children: /* @__PURE__ */ (0,
|
|
1772
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1966
1773
|
MemoizedInnerVizij,
|
|
1967
1774
|
{
|
|
1968
1775
|
rootId,
|
|
@@ -1973,13 +1780,13 @@ function Vizij({
|
|
|
1973
1780
|
}
|
|
1974
1781
|
);
|
|
1975
1782
|
} else {
|
|
1976
|
-
return /* @__PURE__ */ (0,
|
|
1783
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(VizijContext.Provider, { value: useDefaultVizijStore, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1977
1784
|
import_fiber.Canvas,
|
|
1978
1785
|
{
|
|
1979
1786
|
style,
|
|
1980
1787
|
className,
|
|
1981
1788
|
onPointerMissed,
|
|
1982
|
-
children: /* @__PURE__ */ (0,
|
|
1789
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1983
1790
|
MemoizedInnerVizij,
|
|
1984
1791
|
{
|
|
1985
1792
|
rootId,
|
|
@@ -2001,9 +1808,9 @@ function InnerVizij({
|
|
|
2001
1808
|
width: container.width * container.resolution,
|
|
2002
1809
|
height: container.height * container.resolution
|
|
2003
1810
|
} : void 0;
|
|
2004
|
-
return /* @__PURE__ */ (0,
|
|
2005
|
-
/* @__PURE__ */ (0,
|
|
2006
|
-
/* @__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)(
|
|
2007
1814
|
import_drei3.OrthographicCamera,
|
|
2008
1815
|
{
|
|
2009
1816
|
makeDefault: true,
|
|
@@ -2012,7 +1819,7 @@ function InnerVizij({
|
|
|
2012
1819
|
far: 101
|
|
2013
1820
|
}
|
|
2014
1821
|
),
|
|
2015
|
-
/* @__PURE__ */ (0,
|
|
1822
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react10.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2016
1823
|
World,
|
|
2017
1824
|
{
|
|
2018
1825
|
rootId,
|
|
@@ -2020,17 +1827,17 @@ function InnerVizij({
|
|
|
2020
1827
|
parentSizing: sceneParentSizing
|
|
2021
1828
|
}
|
|
2022
1829
|
) }),
|
|
2023
|
-
showSafeArea && /* @__PURE__ */ (0,
|
|
1830
|
+
showSafeArea && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SafeAreaRenderer, { rootId })
|
|
2024
1831
|
] });
|
|
2025
1832
|
}
|
|
2026
|
-
var MemoizedInnerVizij = (0,
|
|
1833
|
+
var MemoizedInnerVizij = (0, import_react10.memo)(InnerVizij);
|
|
2027
1834
|
function InnerWorld({
|
|
2028
1835
|
rootId,
|
|
2029
1836
|
namespace = "default",
|
|
2030
1837
|
parentSizing
|
|
2031
1838
|
}) {
|
|
2032
1839
|
const [present, rootBounds] = useVizijStore(
|
|
2033
|
-
(0,
|
|
1840
|
+
(0, import_shallow7.useShallow)((state) => {
|
|
2034
1841
|
const group = state.world[rootId];
|
|
2035
1842
|
const bounds = group?.rootBounds ?? defaultRootBounds;
|
|
2036
1843
|
return [group !== void 0, bounds];
|
|
@@ -2040,7 +1847,7 @@ function InnerWorld({
|
|
|
2040
1847
|
camera: state.camera,
|
|
2041
1848
|
size: state.size
|
|
2042
1849
|
}));
|
|
2043
|
-
(0,
|
|
1850
|
+
(0, import_react10.useEffect)(() => {
|
|
2044
1851
|
const width = rootBounds.size.x;
|
|
2045
1852
|
const height = rootBounds.size.y;
|
|
2046
1853
|
if (camera && parentSizing === void 0 && camera.isOrthographicCamera) {
|
|
@@ -2068,9 +1875,9 @@ function InnerWorld({
|
|
|
2068
1875
|
camera.updateProjectionMatrix();
|
|
2069
1876
|
}
|
|
2070
1877
|
}, [rootBounds, camera, parentSizing, size]);
|
|
2071
|
-
return /* @__PURE__ */ (0,
|
|
2072
|
-
present && /* @__PURE__ */ (0,
|
|
2073
|
-
!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)(
|
|
2074
1881
|
import_drei3.Text,
|
|
2075
1882
|
{
|
|
2076
1883
|
position: [0, 0, 0],
|
|
@@ -2083,7 +1890,7 @@ function InnerWorld({
|
|
|
2083
1890
|
)
|
|
2084
1891
|
] });
|
|
2085
1892
|
}
|
|
2086
|
-
var World = (0,
|
|
1893
|
+
var World = (0, import_react10.memo)(InnerWorld);
|
|
2087
1894
|
function SafeAreaRenderer({ rootId }) {
|
|
2088
1895
|
const rootBounds = useVizijStore((state) => {
|
|
2089
1896
|
const group = state.world[rootId];
|
|
@@ -2093,7 +1900,7 @@ function SafeAreaRenderer({ rootId }) {
|
|
|
2093
1900
|
const right = rootBounds.center.x + rootBounds.size.x / 2;
|
|
2094
1901
|
const top = rootBounds.center.y + rootBounds.size.y / 2;
|
|
2095
1902
|
const bottom = rootBounds.center.y - rootBounds.size.y / 2;
|
|
2096
|
-
return /* @__PURE__ */ (0,
|
|
1903
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2097
1904
|
import_drei3.Line,
|
|
2098
1905
|
{
|
|
2099
1906
|
points: [
|
|
@@ -2124,11 +1931,11 @@ var ShapeMaterial = /* @__PURE__ */ ((ShapeMaterial2) => {
|
|
|
2124
1931
|
})(ShapeMaterial || {});
|
|
2125
1932
|
|
|
2126
1933
|
// src/hooks/use-vizij-store-subscription.ts
|
|
2127
|
-
var
|
|
1934
|
+
var import_react11 = require("react");
|
|
2128
1935
|
function useVizijStoreSubscription(selector, listener) {
|
|
2129
|
-
const store = (0,
|
|
1936
|
+
const store = (0, import_react11.useContext)(VizijContext);
|
|
2130
1937
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2131
|
-
(0,
|
|
1938
|
+
(0, import_react11.useEffect)(() => {
|
|
2132
1939
|
const initialValue = selector(store.getState());
|
|
2133
1940
|
listener(initialValue);
|
|
2134
1941
|
return store.subscribe(selector, listener);
|
|
@@ -2136,17 +1943,17 @@ function useVizijStoreSubscription(selector, listener) {
|
|
|
2136
1943
|
}
|
|
2137
1944
|
|
|
2138
1945
|
// src/hooks/use-vizij-store-setter.ts
|
|
2139
|
-
var
|
|
1946
|
+
var import_react12 = require("react");
|
|
2140
1947
|
function useVizijStoreSetter() {
|
|
2141
|
-
const store = (0,
|
|
1948
|
+
const store = (0, import_react12.useContext)(VizijContext);
|
|
2142
1949
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2143
1950
|
return store.setState;
|
|
2144
1951
|
}
|
|
2145
1952
|
|
|
2146
1953
|
// src/hooks/use-vizij-store-getter.ts
|
|
2147
|
-
var
|
|
1954
|
+
var import_react13 = require("react");
|
|
2148
1955
|
function useVizijStoreGetter() {
|
|
2149
|
-
const store = (0,
|
|
1956
|
+
const store = (0, import_react13.useContext)(VizijContext);
|
|
2150
1957
|
if (!store) throw new Error("Missing VizijProvider in the tree");
|
|
2151
1958
|
return store.getState;
|
|
2152
1959
|
}
|
|
@@ -2156,7 +1963,7 @@ var THREE5 = __toESM(require("three"));
|
|
|
2156
1963
|
var import_three_stdlib = require("three-stdlib");
|
|
2157
1964
|
|
|
2158
1965
|
// src/functions/gltf-loading/traverse-three.ts
|
|
2159
|
-
var
|
|
1966
|
+
var import_react15 = require("react");
|
|
2160
1967
|
var THREE4 = __toESM(require("three"));
|
|
2161
1968
|
|
|
2162
1969
|
// src/functions/gltf-loading/map-features.ts
|
|
@@ -2188,9 +1995,9 @@ var import_three4 = require("three");
|
|
|
2188
1995
|
var import_three3 = require("three");
|
|
2189
1996
|
|
|
2190
1997
|
// src/functions/util.ts
|
|
2191
|
-
var
|
|
1998
|
+
var import_react14 = require("react");
|
|
2192
1999
|
function namespaceArrayToRefs(namespaces) {
|
|
2193
|
-
return namespaces.reduce((acc, ns) => ({ ...acc, [ns]: (0,
|
|
2000
|
+
return namespaces.reduce((acc, ns) => ({ ...acc, [ns]: (0, import_react14.createRef)() }), {});
|
|
2194
2001
|
}
|
|
2195
2002
|
|
|
2196
2003
|
// src/functions/gltf-loading/import-mesh.ts
|
|
@@ -2539,7 +2346,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2539
2346
|
loadedData = {
|
|
2540
2347
|
...data,
|
|
2541
2348
|
refs: namespaces.reduce(
|
|
2542
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2349
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2543
2350
|
{}
|
|
2544
2351
|
)
|
|
2545
2352
|
};
|
|
@@ -2554,7 +2361,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2554
2361
|
...data,
|
|
2555
2362
|
geometry: child.geometry,
|
|
2556
2363
|
refs: namespaces.reduce(
|
|
2557
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2364
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2558
2365
|
{}
|
|
2559
2366
|
)
|
|
2560
2367
|
};
|
|
@@ -2568,7 +2375,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2568
2375
|
loadedData = {
|
|
2569
2376
|
...data,
|
|
2570
2377
|
refs: namespaces.reduce(
|
|
2571
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2378
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2572
2379
|
{}
|
|
2573
2380
|
)
|
|
2574
2381
|
};
|
|
@@ -2582,7 +2389,7 @@ function traverseThree(group, namespaces, aggressiveImport = false, rootBounds)
|
|
|
2582
2389
|
loadedData = {
|
|
2583
2390
|
...data,
|
|
2584
2391
|
refs: namespaces.reduce(
|
|
2585
|
-
(acc, ns) => ({ ...acc, [ns]: (0,
|
|
2392
|
+
(acc, ns) => ({ ...acc, [ns]: (0, import_react15.createRef)() }),
|
|
2586
2393
|
{}
|
|
2587
2394
|
)
|
|
2588
2395
|
};
|
|
@@ -3098,7 +2905,6 @@ function exportScene(data, fileNameOrOptions = "scene.glb") {
|
|
|
3098
2905
|
}
|
|
3099
2906
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3100
2907
|
0 && (module.exports = {
|
|
3101
|
-
Controller,
|
|
3102
2908
|
EmptyModelError,
|
|
3103
2909
|
InnerVizij,
|
|
3104
2910
|
ShapeMaterial,
|