react-three-game 0.0.93 → 0.0.95
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 +35 -77
- package/dist/index.d.ts +9 -6
- package/dist/index.js +5 -3
- package/dist/tools/prefabeditor/EditorTree.js +8 -12
- package/dist/tools/prefabeditor/EditorUI.js +4 -4
- package/dist/tools/prefabeditor/PrefabEditor.d.ts +12 -33
- package/dist/tools/prefabeditor/PrefabEditor.js +137 -161
- package/dist/tools/prefabeditor/PrefabRoot.d.ts +24 -12
- package/dist/tools/prefabeditor/PrefabRoot.js +117 -59
- package/dist/tools/prefabeditor/assetRuntime.d.ts +11 -17
- package/dist/tools/prefabeditor/assetRuntime.js +15 -15
- package/dist/tools/prefabeditor/components/CameraComponent.js +2 -2
- package/dist/tools/prefabeditor/components/DirectionalLightComponent.js +2 -2
- package/dist/tools/prefabeditor/components/Input.js +5 -9
- package/dist/tools/prefabeditor/components/MaterialComponent.d.ts +5 -2
- package/dist/tools/prefabeditor/components/MaterialComponent.js +40 -24
- package/dist/tools/prefabeditor/components/ModelComponent.js +3 -5
- package/dist/tools/prefabeditor/components/PointLightComponent.js +2 -2
- package/dist/tools/prefabeditor/components/SoundComponent.js +2 -2
- package/dist/tools/prefabeditor/components/SpotLightComponent.js +2 -2
- package/dist/tools/prefabeditor/components/SpriteComponent.d.ts +8 -0
- package/dist/tools/prefabeditor/components/SpriteComponent.js +27 -0
- package/dist/tools/prefabeditor/components/index.js +22 -14
- package/dist/tools/prefabeditor/prefab.d.ts +1 -2
- package/dist/tools/prefabeditor/prefab.js +2 -3
- package/dist/tools/prefabeditor/prefabStore.d.ts +0 -6
- package/dist/tools/prefabeditor/prefabStore.js +1 -33
- package/package.json +49 -49
|
@@ -9,8 +9,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx,
|
|
13
|
-
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
14
14
|
import { Euler, Matrix4, } from "three";
|
|
15
15
|
import { useStore } from "zustand";
|
|
16
16
|
import { useClickValid } from "./useClickValid";
|
|
@@ -20,8 +20,8 @@ import { builtinComponents } from "./components";
|
|
|
20
20
|
import { loadModel, loadSound, loadTexture } from "../dragdrop";
|
|
21
21
|
import { GameInstance, GameInstanceProvider, getRepeatAxesFromModelProperties, useInstanceCheck } from "./InstanceProvider";
|
|
22
22
|
import { composeTransform, decompose } from "./utils";
|
|
23
|
-
import { createPrefabStore, PrefabStoreProvider,
|
|
24
|
-
import { AssetRuntimeContext,
|
|
23
|
+
import { createPrefabStore, PrefabStoreProvider, usePrefabChildIds, usePrefabNode, usePrefabRootId } from "./prefabStore";
|
|
24
|
+
import { AssetRuntimeContext, NodeScope } from "./assetRuntime";
|
|
25
25
|
import { gameEvents } from "./GameEvents";
|
|
26
26
|
import { sound as soundManager } from "../../helpers/SoundManager";
|
|
27
27
|
builtinComponents.forEach(registerComponent);
|
|
@@ -50,8 +50,20 @@ function getNodeMetadataProps(node) {
|
|
|
50
50
|
userData: Object.assign(Object.assign({ prefabNodeId: node.id }, (nodeName ? { prefabNodeName: nodeName } : {})), getNodeUserData(node)),
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
export
|
|
54
|
-
|
|
53
|
+
export var PrefabEditorMode;
|
|
54
|
+
(function (PrefabEditorMode) {
|
|
55
|
+
PrefabEditorMode["Edit"] = "edit";
|
|
56
|
+
PrefabEditorMode["Play"] = "play";
|
|
57
|
+
})(PrefabEditorMode || (PrefabEditorMode = {}));
|
|
58
|
+
export const SceneContext = createContext(null);
|
|
59
|
+
export function useScene() {
|
|
60
|
+
const scene = useContext(SceneContext);
|
|
61
|
+
if (!scene) {
|
|
62
|
+
throw new Error("useScene must be used within a PrefabRoot or PrefabEditor scene provider");
|
|
63
|
+
}
|
|
64
|
+
return scene;
|
|
65
|
+
}
|
|
66
|
+
export const PrefabRoot = forwardRef(({ editMode, data, store, selectedId, onSelect, onClick, onEditNodeClick, basePath = "", children }, ref) => {
|
|
55
67
|
const [models, setModels] = useState({});
|
|
56
68
|
const [textures, setTextures] = useState({});
|
|
57
69
|
const [sounds, setSounds] = useState({});
|
|
@@ -64,31 +76,33 @@ export const PrefabRootInternal = forwardRef(({ editMode, data, store, selectedI
|
|
|
64
76
|
const failedSounds = useRef(new Set());
|
|
65
77
|
const objectRefs = useRef({});
|
|
66
78
|
const nodeHandles = useRef(new Map());
|
|
67
|
-
const parentStore = useOptionalPrefabStoreApi();
|
|
68
79
|
const [ownedStore] = useState(() => {
|
|
80
|
+
if (store)
|
|
81
|
+
return null;
|
|
69
82
|
if (data)
|
|
70
83
|
return createPrefabStore(data);
|
|
71
|
-
if (store || parentStore)
|
|
72
|
-
return null;
|
|
73
84
|
throw new Error("PrefabRoot requires either a `data` or `store` prop");
|
|
74
85
|
});
|
|
75
|
-
const resolvedStore =
|
|
86
|
+
const resolvedStore = store !== null && store !== void 0 ? store : ownedStore;
|
|
76
87
|
const usesOwnedStore = resolvedStore === ownedStore;
|
|
77
|
-
const shouldProvideStoreContext = !parentStore || parentStore !== resolvedStore;
|
|
78
88
|
const rootId = useStore(resolvedStore, state => state.rootId);
|
|
79
89
|
const assetManifestKey = useStore(resolvedStore, state => state.assetManifestKey);
|
|
80
90
|
const availableModels = useMemo(() => (Object.assign(Object.assign({}, models), injectedModels)), [models, injectedModels]);
|
|
81
91
|
const availableTextures = useMemo(() => (Object.assign(Object.assign({}, textures), injectedTextures)), [textures, injectedTextures]);
|
|
82
92
|
const availableSounds = useMemo(() => (Object.assign(Object.assign({}, sounds), injectedSounds)), [sounds, injectedSounds]);
|
|
83
|
-
const
|
|
93
|
+
const getObject = useCallback((id) => {
|
|
84
94
|
var _a;
|
|
85
95
|
return (_a = objectRefs.current[id]) !== null && _a !== void 0 ? _a : null;
|
|
86
96
|
}, []);
|
|
87
|
-
const
|
|
97
|
+
const getHandle = useCallback((id, kind) => {
|
|
88
98
|
var _a, _b;
|
|
89
99
|
return (_b = (_a = nodeHandles.current.get(id)) === null || _a === void 0 ? void 0 : _a.get(kind)) !== null && _b !== void 0 ? _b : null;
|
|
90
100
|
}, []);
|
|
91
|
-
const
|
|
101
|
+
const getNode = useCallback((nodeId) => {
|
|
102
|
+
var _a;
|
|
103
|
+
return (_a = resolvedStore.getState().nodesById[nodeId]) !== null && _a !== void 0 ? _a : null;
|
|
104
|
+
}, [resolvedStore]);
|
|
105
|
+
const registerHandle = useCallback((id, kind, handle) => {
|
|
92
106
|
const current = nodeHandles.current.get(id);
|
|
93
107
|
if (handle == null) {
|
|
94
108
|
if (!current)
|
|
@@ -105,20 +119,33 @@ export const PrefabRootInternal = forwardRef(({ editMode, data, store, selectedI
|
|
|
105
119
|
}
|
|
106
120
|
nodeHandles.current.set(id, new Map([[kind, handle]]));
|
|
107
121
|
}, []);
|
|
108
|
-
|
|
122
|
+
const sceneValue = useMemo(() => ({
|
|
109
123
|
get root() {
|
|
110
124
|
var _a;
|
|
111
125
|
return (_a = objectRefs.current[rootId]) !== null && _a !== void 0 ? _a : null;
|
|
112
126
|
},
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
mode: editMode ? PrefabEditorMode.Edit : PrefabEditorMode.Play,
|
|
128
|
+
get: getNode,
|
|
129
|
+
getObject,
|
|
130
|
+
getHandle,
|
|
131
|
+
add: (node, parentId) => {
|
|
132
|
+
const state = resolvedStore.getState();
|
|
133
|
+
state.addChild(parentId !== null && parentId !== void 0 ? parentId : state.rootId, node);
|
|
134
|
+
return node;
|
|
135
|
+
},
|
|
136
|
+
update: (id, fn) => resolvedStore.getState().updateNode(id, fn),
|
|
137
|
+
remove: (id) => resolvedStore.getState().deleteNode(id),
|
|
138
|
+
duplicate: (id) => resolvedStore.getState().duplicateNode(id),
|
|
139
|
+
move: (draggedId, targetId, position) => resolvedStore.getState().moveNode(draggedId, targetId, position),
|
|
140
|
+
replace: (prefab) => resolvedStore.getState().replacePrefab(prefab),
|
|
115
141
|
addModel: (path, model) => setInjectedModels(prev => (Object.assign(Object.assign({}, prev), { [path]: model }))),
|
|
116
142
|
addTexture: (path, texture) => setInjectedTextures(prev => (Object.assign(Object.assign({}, prev), { [path]: texture }))),
|
|
117
143
|
addSound: (path, sound) => {
|
|
118
144
|
soundManager.setBuffer(path, sound);
|
|
119
145
|
setInjectedSounds(prev => (Object.assign(Object.assign({}, prev), { [path]: sound })));
|
|
120
146
|
},
|
|
121
|
-
}), [
|
|
147
|
+
}), [editMode, getHandle, getNode, getObject, resolvedStore, rootId]);
|
|
148
|
+
useImperativeHandle(ref, () => sceneValue, [sceneValue]);
|
|
122
149
|
const registerRef = useCallback((id, obj) => {
|
|
123
150
|
objectRefs.current[id] = obj;
|
|
124
151
|
}, []);
|
|
@@ -153,31 +180,27 @@ export const PrefabRootInternal = forwardRef(({ editMode, data, store, selectedI
|
|
|
153
180
|
return;
|
|
154
181
|
loading.current.add(file);
|
|
155
182
|
void loader(resolveAssetPath(basePath, file)).then(result => {
|
|
183
|
+
loading.current.delete(file);
|
|
156
184
|
if (!result.success) {
|
|
157
185
|
console.warn(`Failed to load asset: ${file}`, result.error);
|
|
158
|
-
loading.current.delete(file);
|
|
159
186
|
failed.add(file);
|
|
160
187
|
}
|
|
161
188
|
});
|
|
162
189
|
};
|
|
163
|
-
modelsToLoad.forEach(file => loadAsset(file, models, injectedModels, failedModels.current,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
setModels(m => (Object.assign(Object.assign({}, m), { [file]: model })));
|
|
167
|
-
}
|
|
190
|
+
modelsToLoad.forEach(file => loadAsset(file, models, injectedModels, failedModels.current, path => loadModel(path).then(result => {
|
|
191
|
+
if (result.success && result.model)
|
|
192
|
+
setModels(m => (Object.assign(Object.assign({}, m), { [file]: result.model })));
|
|
168
193
|
return result;
|
|
169
194
|
})));
|
|
170
|
-
texturesToLoad.forEach(file => loadAsset(file, textures, injectedTextures, failedTextures.current,
|
|
171
|
-
if (result.success && result.texture)
|
|
195
|
+
texturesToLoad.forEach(file => loadAsset(file, textures, injectedTextures, failedTextures.current, path => loadTexture(path).then(result => {
|
|
196
|
+
if (result.success && result.texture)
|
|
172
197
|
setTextures(t => (Object.assign(Object.assign({}, t), { [file]: result.texture })));
|
|
173
|
-
}
|
|
174
198
|
return result;
|
|
175
199
|
})));
|
|
176
|
-
soundsToLoad.forEach(file => loadAsset(file, sounds, injectedSounds, failedSounds.current,
|
|
200
|
+
soundsToLoad.forEach(file => loadAsset(file, sounds, injectedSounds, failedSounds.current, path => loadSound(path).then(result => {
|
|
177
201
|
if (result.success && result.sound) {
|
|
178
202
|
soundManager.setBuffer(file, result.sound);
|
|
179
|
-
setSounds(
|
|
180
|
-
loading.current.delete(file);
|
|
203
|
+
setSounds(s => (Object.assign(Object.assign({}, s), { [file]: result.sound })));
|
|
181
204
|
}
|
|
182
205
|
return result;
|
|
183
206
|
})));
|
|
@@ -185,14 +208,14 @@ export const PrefabRootInternal = forwardRef(({ editMode, data, store, selectedI
|
|
|
185
208
|
syncAssets();
|
|
186
209
|
}, [resolvedStore, assetManifestKey, basePath, injectedModels, injectedSounds, injectedTextures, models, sounds, textures]);
|
|
187
210
|
const assetRuntime = useMemo(() => ({
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
211
|
+
registerHandle,
|
|
212
|
+
getHandle,
|
|
213
|
+
getObject,
|
|
191
214
|
getModel: (path) => { var _a; return (_a = availableModels[path]) !== null && _a !== void 0 ? _a : null; },
|
|
192
215
|
getTexture: (path) => { var _a; return (_a = availableTextures[path]) !== null && _a !== void 0 ? _a : null; },
|
|
193
216
|
getSound: (path) => { var _a; return (_a = availableSounds[path]) !== null && _a !== void 0 ? _a : null; },
|
|
194
217
|
getAssetRevision: () => `${Object.keys(availableTextures).sort().join('|')}::${Object.keys(availableModels).sort().join('|')}`,
|
|
195
|
-
}), [
|
|
218
|
+
}), [registerHandle, getHandle, getObject, availableModels, availableTextures, availableSounds]);
|
|
196
219
|
const handleNodeClick = useCallback((event, nodeId, fallbackObject) => {
|
|
197
220
|
const node = resolvedStore.getState().nodesById[nodeId];
|
|
198
221
|
if (!node)
|
|
@@ -201,14 +224,10 @@ export const PrefabRootInternal = forwardRef(({ editMode, data, store, selectedI
|
|
|
201
224
|
emitNodePointerEvent(clickEventName, event, nodeId, node, fallbackObject);
|
|
202
225
|
onClick === null || onClick === void 0 ? void 0 : onClick(event, node);
|
|
203
226
|
}, [onClick, resolvedStore]);
|
|
204
|
-
const content = (
|
|
205
|
-
const runtimeContent = _jsx(AssetRuntimeContext.Provider, { value: assetRuntime, children: content });
|
|
206
|
-
if (!shouldProvideStoreContext) {
|
|
207
|
-
return runtimeContent;
|
|
208
|
-
}
|
|
227
|
+
const content = (_jsxs(GameInstanceProvider, { models: availableModels, selectedId: selectedId, editMode: editMode, onSelect: editMode ? onSelect : undefined, onClick: editMode ? undefined : handleNodeClick, registerRef: registerRef, children: [_jsx(StoreRootNode, { selectedId: selectedId, onSelect: editMode ? onSelect : undefined, onClick: editMode ? undefined : handleNodeClick, onEditNodeClick: editMode ? onEditNodeClick : undefined, registerRef: registerRef, loadedModels: availableModels, editMode: editMode, parentMatrix: IDENTITY }), children] }));
|
|
228
|
+
const runtimeContent = (_jsx(SceneContext.Provider, { value: sceneValue, children: _jsx(AssetRuntimeContext.Provider, { value: assetRuntime, children: content }) }));
|
|
209
229
|
return _jsx(PrefabStoreProvider, { store: resolvedStore, children: runtimeContent });
|
|
210
230
|
});
|
|
211
|
-
export const PrefabRoot = PrefabRootInternal;
|
|
212
231
|
function StoreRootNode(props) {
|
|
213
232
|
const rootId = usePrefabRootId();
|
|
214
233
|
return _jsx(GameObjectRenderer, Object.assign({}, props, { nodeId: rootId }));
|
|
@@ -221,11 +240,12 @@ function getClickEventName(component) {
|
|
|
221
240
|
return typeof eventName === 'string' && eventName.trim() ? eventName.trim() : null;
|
|
222
241
|
}
|
|
223
242
|
function analyzeNodeComponents(node) {
|
|
224
|
-
var _a, _b, _c;
|
|
243
|
+
var _a, _b, _c, _d;
|
|
225
244
|
let bufferGeometry;
|
|
226
245
|
let geometry;
|
|
227
246
|
let material;
|
|
228
247
|
let model;
|
|
248
|
+
let sprite;
|
|
229
249
|
const composition = [];
|
|
230
250
|
for (const [key, component] of Object.entries((_a = node.components) !== null && _a !== void 0 ? _a : {})) {
|
|
231
251
|
if (!(component === null || component === void 0 ? void 0 : component.type))
|
|
@@ -245,6 +265,9 @@ function analyzeNodeComponents(node) {
|
|
|
245
265
|
case "Model":
|
|
246
266
|
model = component;
|
|
247
267
|
break;
|
|
268
|
+
case "Sprite":
|
|
269
|
+
sprite = component;
|
|
270
|
+
break;
|
|
248
271
|
default: {
|
|
249
272
|
const def = getComponentDef(component.type);
|
|
250
273
|
if (!(def === null || def === void 0 ? void 0 : def.View))
|
|
@@ -262,7 +285,8 @@ function analyzeNodeComponents(node) {
|
|
|
262
285
|
geometry: bufferGeometry !== null && bufferGeometry !== void 0 ? bufferGeometry : geometry,
|
|
263
286
|
material,
|
|
264
287
|
model,
|
|
265
|
-
|
|
288
|
+
sprite,
|
|
289
|
+
clickEventName: (_d = (_c = (_b = getClickEventName(bufferGeometry)) !== null && _b !== void 0 ? _b : getClickEventName(geometry)) !== null && _c !== void 0 ? _c : getClickEventName(model)) !== null && _d !== void 0 ? _d : getClickEventName(sprite),
|
|
266
290
|
composition,
|
|
267
291
|
};
|
|
268
292
|
}
|
|
@@ -379,7 +403,7 @@ function StandardNode({ nodeId, selectedId, onSelect, onClick, onEditNodeClick,
|
|
|
379
403
|
const inner = renderNodeContent(analyzedComponents, loadedModels, primaryClickHandlers, childNodes);
|
|
380
404
|
const editAnchor = editMode ? (_jsx("mesh", { visible: false, children: _jsx("boxGeometry", { args: [0.01, 0.01, 0.01] }) })) : null;
|
|
381
405
|
const standardNode = (_jsxs("group", Object.assign({ ref: handleGroupRef }, groupProps, { visible: nodeVisible }, (editMode ? editClickHandlers : undefined), { children: [editAnchor, inner] })));
|
|
382
|
-
return (_jsx(
|
|
406
|
+
return (_jsx(NodeScope, { nodeId: nodeId, editMode: editMode, isSelected: isSelected, children: standardNode }));
|
|
383
407
|
}
|
|
384
408
|
function ChildNodes(_a) {
|
|
385
409
|
var { childIds, parentMatrix } = _a, props = __rest(_a, ["childIds", "parentMatrix"]);
|
|
@@ -452,24 +476,58 @@ function getNodeTransformProps(node) {
|
|
|
452
476
|
function renderNodeContent(analyzedComponents, loadedModels, primaryClickHandlers, childNodes) {
|
|
453
477
|
var _a, _b, _c, _d;
|
|
454
478
|
const geometry = analyzedComponents.geometry;
|
|
455
|
-
const
|
|
456
|
-
const
|
|
457
|
-
const
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
479
|
+
const model = analyzedComponents.model;
|
|
480
|
+
const material = analyzedComponents.material;
|
|
481
|
+
const sprite = analyzedComponents.sprite;
|
|
482
|
+
const shapeKind = (sprite === null || sprite === void 0 ? void 0 : sprite.type) ? 'sprite' : (geometry === null || geometry === void 0 ? void 0 : geometry.type) ? 'mesh' : (model === null || model === void 0 ? void 0 : model.type) ? 'model' : 'none';
|
|
483
|
+
let materialContent = null;
|
|
484
|
+
switch (shapeKind) {
|
|
485
|
+
case 'sprite': {
|
|
486
|
+
const materialDef = (material === null || material === void 0 ? void 0 : material.type) ? getComponentDef(material.type) : undefined;
|
|
487
|
+
if ((material === null || material === void 0 ? void 0 : material.properties) && (materialDef === null || materialDef === void 0 ? void 0 : materialDef.View)) {
|
|
488
|
+
const materialIsSprite = material.properties.materialType === 'sprite';
|
|
489
|
+
materialContent = (_jsx(materialDef.View, { properties: Object.assign(Object.assign({}, material.properties), { materialType: 'sprite', transparent: materialIsSprite ? material.properties.transparent : true, depthTest: materialIsSprite ? material.properties.depthTest : false, depthWrite: materialIsSprite ? material.properties.depthWrite : false }) }, "material"));
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
case 'mesh': {
|
|
494
|
+
const materialDef = (material === null || material === void 0 ? void 0 : material.type) ? getComponentDef(material.type) : undefined;
|
|
495
|
+
if ((material === null || material === void 0 ? void 0 : material.properties) && (materialDef === null || materialDef === void 0 ? void 0 : materialDef.View)) {
|
|
496
|
+
materialContent = _jsx(materialDef.View, { properties: material.properties }, "material");
|
|
497
|
+
}
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
465
500
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
501
|
+
let primaryContent = null;
|
|
502
|
+
let contentChildren = childNodes;
|
|
503
|
+
switch (shapeKind) {
|
|
504
|
+
case 'sprite': {
|
|
505
|
+
primaryContent = (_jsxs("sprite", Object.assign({ center: (_b = (_a = sprite === null || sprite === void 0 ? void 0 : sprite.properties) === null || _a === void 0 ? void 0 : _a.center) !== null && _b !== void 0 ? _b : [0.5, 0.5] }, primaryClickHandlers, { children: [materialContent, childNodes] })));
|
|
506
|
+
contentChildren = null;
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
case 'mesh': {
|
|
510
|
+
const geometryDef = (geometry === null || geometry === void 0 ? void 0 : geometry.type) ? getComponentDef(geometry.type) : undefined;
|
|
511
|
+
if (!(geometry === null || geometry === void 0 ? void 0 : geometry.properties) || !(geometryDef === null || geometryDef === void 0 ? void 0 : geometryDef.View))
|
|
512
|
+
break;
|
|
513
|
+
const GeometryView = geometryDef.View;
|
|
514
|
+
const geometryProperties = (_c = geometry.properties) !== null && _c !== void 0 ? _c : {};
|
|
515
|
+
const visible = geometryProperties.visible !== false;
|
|
516
|
+
primaryContent = (_jsxs("mesh", Object.assign({ visible: visible, castShadow: visible && geometryProperties.castShadow !== false, receiveShadow: visible && geometryProperties.receiveShadow !== false }, primaryClickHandlers, { children: [_jsx(GeometryView, { properties: geometry.properties }), materialContent] })));
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
case 'model': {
|
|
520
|
+
if (!(model === null || model === void 0 ? void 0 : model.type) || ((_d = model.properties) === null || _d === void 0 ? void 0 : _d.instanced) || !isNodeReady(model, loadedModels))
|
|
521
|
+
break;
|
|
522
|
+
const modelDef = getComponentDef(model.type);
|
|
523
|
+
if (!(modelDef === null || modelDef === void 0 ? void 0 : modelDef.View))
|
|
524
|
+
break;
|
|
525
|
+
const modelContent = _jsx(modelDef.View, { properties: model.properties });
|
|
526
|
+
primaryContent = primaryClickHandlers ? _jsx("group", Object.assign({}, primaryClickHandlers, { children: modelContent })) : modelContent;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
471
529
|
}
|
|
472
|
-
let content = _jsxs(_Fragment, { children: [primaryContent,
|
|
530
|
+
let content = _jsxs(_Fragment, { children: [primaryContent, contentChildren] });
|
|
473
531
|
for (const { key, View, properties } of analyzedComponents.composition) {
|
|
474
532
|
content = (_jsx(View, { properties: properties, children: content }, key));
|
|
475
533
|
}
|
|
@@ -1,36 +1,30 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { Object3D, Texture } from "three";
|
|
3
3
|
export interface AssetRuntime {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
registerHandle: (id: string, kind: string, handle: unknown) => void;
|
|
5
|
+
getHandle: <T = unknown>(id: string, kind: string) => T | null;
|
|
6
6
|
getModel: (path: string) => Object3D | null;
|
|
7
7
|
getTexture: (path: string) => Texture | null;
|
|
8
8
|
getSound: (path: string) => AudioBuffer | null;
|
|
9
9
|
getAssetRevision: () => string;
|
|
10
|
-
|
|
10
|
+
getObject: (id: string) => Object3D | null;
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
13
|
-
}
|
|
14
|
-
export interface CurrentNodeRuntime {
|
|
12
|
+
export interface NodeApi {
|
|
15
13
|
nodeId: string;
|
|
16
14
|
editMode?: boolean;
|
|
17
15
|
isSelected?: boolean;
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
getObject: <T extends Object3D = Object3D>() => T | null;
|
|
17
|
+
getHandle: <T = unknown>(kind: string) => T | null;
|
|
20
18
|
}
|
|
21
19
|
export interface LiveRef<T> {
|
|
22
20
|
readonly current: T | null;
|
|
23
21
|
}
|
|
24
|
-
export
|
|
25
|
-
export type LiveHandleRef<T = unknown> = LiveRef<T>;
|
|
26
|
-
export type CurrentNodeObjectRef<T extends Object3D = Object3D> = LiveObjectRef<T>;
|
|
27
|
-
export type CurrentNodeHandleRef<T = unknown> = LiveHandleRef<T>;
|
|
28
|
-
export declare const AssetRuntimeContext: import("react").Context<AssetRuntimeContextValue | null>;
|
|
22
|
+
export declare const AssetRuntimeContext: import("react").Context<AssetRuntime | null>;
|
|
29
23
|
export declare function useAssetRuntime(): AssetRuntime;
|
|
30
|
-
export declare function
|
|
31
|
-
export declare function
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
24
|
+
export declare function useNode(): NodeApi;
|
|
25
|
+
export declare function useNodeObject<T extends Object3D = Object3D>(): LiveRef<T>;
|
|
26
|
+
export declare function useNodeHandle<T = unknown>(kind: string): LiveRef<T>;
|
|
27
|
+
export declare function NodeScope({ nodeId, editMode, isSelected, children, }: {
|
|
34
28
|
nodeId: string;
|
|
35
29
|
editMode?: boolean;
|
|
36
30
|
isSelected?: boolean;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useMemo } from "react";
|
|
3
3
|
export const AssetRuntimeContext = createContext(null);
|
|
4
|
-
const
|
|
4
|
+
const NodeContext = createContext(null);
|
|
5
5
|
export function useAssetRuntime() {
|
|
6
6
|
const ctx = useContext(AssetRuntimeContext);
|
|
7
7
|
if (!ctx)
|
|
8
8
|
throw new Error("useAssetRuntime must be used inside <PrefabRoot>");
|
|
9
9
|
return ctx;
|
|
10
10
|
}
|
|
11
|
-
export function
|
|
12
|
-
const ctx = useContext(
|
|
11
|
+
export function useNode() {
|
|
12
|
+
const ctx = useContext(NodeContext);
|
|
13
13
|
if (!ctx)
|
|
14
|
-
throw new Error("
|
|
14
|
+
throw new Error("useNode must be used inside a component View rendered by <PrefabRoot>");
|
|
15
15
|
return ctx;
|
|
16
16
|
}
|
|
17
|
-
export function
|
|
18
|
-
const {
|
|
19
|
-
return useMemo(() => ({ get current() { return
|
|
17
|
+
export function useNodeObject() {
|
|
18
|
+
const { getObject } = useNode();
|
|
19
|
+
return useMemo(() => ({ get current() { return getObject(); } }), [getObject]);
|
|
20
20
|
}
|
|
21
|
-
export function
|
|
22
|
-
const {
|
|
23
|
-
return useMemo(() => ({ get current() { return
|
|
21
|
+
export function useNodeHandle(kind) {
|
|
22
|
+
const { getHandle } = useNode();
|
|
23
|
+
return useMemo(() => ({ get current() { return getHandle(kind); } }), [getHandle, kind]);
|
|
24
24
|
}
|
|
25
|
-
export function
|
|
25
|
+
export function NodeScope({ nodeId, editMode, isSelected, children, }) {
|
|
26
26
|
const asset = useContext(AssetRuntimeContext);
|
|
27
27
|
if (!asset)
|
|
28
|
-
throw new Error("
|
|
28
|
+
throw new Error("NodeScope must be used inside <PrefabRoot>");
|
|
29
29
|
const value = useMemo(() => ({
|
|
30
30
|
nodeId,
|
|
31
31
|
editMode,
|
|
32
32
|
isSelected,
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
getObject: () => asset.getObject(nodeId),
|
|
34
|
+
getHandle: (kind) => asset.getHandle(nodeId, kind),
|
|
35
35
|
}), [asset, editMode, isSelected, nodeId]);
|
|
36
|
-
return _jsx(
|
|
36
|
+
return _jsx(NodeContext.Provider, { value: value, children: children });
|
|
37
37
|
}
|
|
@@ -3,7 +3,7 @@ import { OrthographicCamera, PerspectiveCamera, useHelper } from '@react-three/d
|
|
|
3
3
|
import { useRef } from 'react';
|
|
4
4
|
import { CameraHelper } from 'three';
|
|
5
5
|
import { useFrame, useThree } from '@react-three/fiber';
|
|
6
|
-
import {
|
|
6
|
+
import { useNode } from '../assetRuntime';
|
|
7
7
|
import { FieldGroup, NumberField, SelectField } from './Input';
|
|
8
8
|
const CAMERA_PROJECTION_OPTIONS = [
|
|
9
9
|
{ value: 'perspective', label: 'Perspective' },
|
|
@@ -25,7 +25,7 @@ function CameraComponentEditor({ component, onUpdate }) {
|
|
|
25
25
|
}
|
|
26
26
|
function CameraComponentView({ properties, children }) {
|
|
27
27
|
var _a;
|
|
28
|
-
const { editMode, isSelected } =
|
|
28
|
+
const { editMode, isSelected } = useNode();
|
|
29
29
|
const { size } = useThree();
|
|
30
30
|
const merged = Object.assign(Object.assign({}, cameraDefaults), properties);
|
|
31
31
|
const projection = (_a = merged.projection) !== null && _a !== void 0 ? _a : cameraDefaults.projection;
|
|
@@ -3,7 +3,7 @@ import { useHelper } from "@react-three/drei";
|
|
|
3
3
|
import { useRef, useEffect, useState } from "react";
|
|
4
4
|
import { useFrame } from "@react-three/fiber";
|
|
5
5
|
import { CameraHelper } from "three";
|
|
6
|
-
import {
|
|
6
|
+
import { useNode } from "../assetRuntime";
|
|
7
7
|
import { BooleanField, ColorField, NumberField, NumberInput, Vector3Input } from "./Input";
|
|
8
8
|
import { LightSection, ShadowBiasField, mergeWithDefaults } from "./lightUtils";
|
|
9
9
|
import { colors } from "../styles";
|
|
@@ -102,7 +102,7 @@ function DirectionalLightComponentEditor({ component, onUpdate }) {
|
|
|
102
102
|
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 8 }, children: [_jsxs(LightSection, { title: "Light", children: [_jsx(ColorField, { name: "color", label: "Color", values: values, onChange: onUpdate }), _jsx(NumberField, { name: "intensity", label: "Intensity", values: values, onChange: onUpdate, min: 0, step: 0.1, fallback: 1 }), _jsx(Vector3Input, { label: "Target Offset", value: values.targetOffset, onChange: targetOffset => onUpdate({ targetOffset }), snap: 0.5 })] }), _jsxs(LightSection, { title: "Shadow", children: [_jsx(BooleanField, { name: "castShadow", label: "Cast Shadow", values: values, onChange: onUpdate, fallback: false }), values.castShadow ? (_jsxs(_Fragment, { children: [_jsx(BooleanField, { name: "shadowAutoUpdate", label: "Auto Update", values: values, onChange: onUpdate, fallback: true }), _jsx(NumberField, { name: "shadowMapSize", label: "Map Size", values: values, onChange: onUpdate, min: 128, step: 128, fallback: 512 }), _jsx(ShadowBiasField, { name: "shadowBias", label: "Bias", values: values, onChange: onUpdate, fallback: 0 }), _jsx(ShadowBiasField, { name: "shadowNormalBias", label: "Normal Bias", values: values, onChange: onUpdate, fallback: 0 }), _jsx(NumberField, { name: "shadowCameraNear", label: "Near", values: values, onChange: onUpdate, min: 0.001, step: 0.1, fallback: 0.5 }), _jsx(NumberField, { name: "shadowCameraFar", label: "Far", values: values, onChange: onUpdate, min: 0.1, step: 1, fallback: 500 }), _jsx(ShadowFrustumField, { values: values, onChange: onUpdate })] })) : null] })] }));
|
|
103
103
|
}
|
|
104
104
|
function DirectionalLightView({ properties, children }) {
|
|
105
|
-
const { editMode, isSelected } =
|
|
105
|
+
const { editMode, isSelected } = useNode();
|
|
106
106
|
const merged = mergeWithDefaults(directionalLightDefaults, properties);
|
|
107
107
|
const color = merged.color;
|
|
108
108
|
const intensity = merged.intensity;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { colors, ui } from '../styles';
|
|
4
|
-
import {
|
|
4
|
+
import { usePrefabStoreApi } from '../prefabStore';
|
|
5
5
|
// ============================================================================
|
|
6
6
|
// Shared Styles (derived from shared color tokens)
|
|
7
7
|
// ============================================================================
|
|
@@ -278,14 +278,10 @@ export function ColorInput({ label, value, onChange }) {
|
|
|
278
278
|
export function StringInput({ label, value, onChange, placeholder }) {
|
|
279
279
|
return (_jsxs("div", { children: [label && _jsx(Label, { children: label }), _jsx("input", { type: "text", style: styles.input, value: value, onChange: e => onChange(e.target.value), placeholder: placeholder })] }));
|
|
280
280
|
}
|
|
281
|
-
function
|
|
282
|
-
const store =
|
|
283
|
-
const [state, setState] = useState(() =>
|
|
281
|
+
function usePrefabSnapshot() {
|
|
282
|
+
const store = usePrefabStoreApi();
|
|
283
|
+
const [state, setState] = useState(() => store.getState());
|
|
284
284
|
useEffect(() => {
|
|
285
|
-
if (!store) {
|
|
286
|
-
setState(null);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
285
|
setState(store.getState());
|
|
290
286
|
return store.subscribe(nextState => setState(nextState));
|
|
291
287
|
}, [store]);
|
|
@@ -323,7 +319,7 @@ function SearchSuggestionList({ query, options, onSelect, emptyMessage, }) {
|
|
|
323
319
|
}, children: [_jsx("span", { style: { fontSize: 11, fontWeight: 500 }, children: option.label }), option.description ? (_jsx("span", { style: { fontSize: 10, color: colors.textMuted, fontFamily: 'monospace' }, children: option.description })) : null] }, option.value))) })] }));
|
|
324
320
|
}
|
|
325
321
|
export function NodeInput({ label, value, onChange, placeholder, includeRoot = true, }) {
|
|
326
|
-
const prefabState =
|
|
322
|
+
const prefabState = usePrefabSnapshot();
|
|
327
323
|
const [query, setQuery] = useState('');
|
|
328
324
|
const options = useMemo(() => {
|
|
329
325
|
var _a;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { ThreeElement } from '@react-three/fiber';
|
|
3
3
|
import { Component } from './ComponentRegistry';
|
|
4
|
-
import { MeshBasicNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';
|
|
4
|
+
import { MeshBasicNodeMaterial, MeshStandardNodeMaterial, SpriteNodeMaterial } from 'three/webgpu';
|
|
5
5
|
import { MeshBasicMaterialProperties, MeshStandardMaterialProperties } from 'three';
|
|
6
6
|
declare module '@react-three/fiber' {
|
|
7
7
|
interface ThreeElements {
|
|
8
8
|
meshBasicNodeMaterial: ThreeElement<typeof MeshBasicNodeMaterial>;
|
|
9
9
|
meshStandardNodeMaterial: ThreeElement<typeof MeshStandardNodeMaterial>;
|
|
10
|
+
spriteNodeMaterial: ThreeElement<typeof SpriteNodeMaterial>;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
export interface MaterialProps extends Omit<MeshStandardMaterialProperties & MeshBasicMaterialProperties, 'args' | 'normalScale'> {
|
|
13
|
-
materialType?: 'standard' | 'basic';
|
|
14
|
+
materialType?: 'standard' | 'basic' | 'sprite';
|
|
14
15
|
transmission?: number;
|
|
15
16
|
thickness?: number;
|
|
16
17
|
ior?: number;
|
|
18
|
+
rotation?: number;
|
|
19
|
+
sizeAttenuation?: boolean;
|
|
17
20
|
texture?: string;
|
|
18
21
|
offset?: [number, number];
|
|
19
22
|
repeat?: boolean;
|