react-three-game 0.0.60 → 0.0.61

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.
Files changed (58) hide show
  1. package/package.json +9 -3
  2. package/.gitattributes +0 -2
  3. package/.github/copilot-instructions.md +0 -83
  4. package/.github/workflows/nextjs.yml +0 -99
  5. package/.gitmodules +0 -3
  6. package/assets/architecture.png +0 -0
  7. package/assets/editor.gif +0 -0
  8. package/assets/favicon.ico +0 -0
  9. package/assets/react-three-game-logo.png +0 -0
  10. package/dist/tools/dragdrop/page.d.ts +0 -1
  11. package/dist/tools/dragdrop/page.js +0 -11
  12. package/dist/tools/prefabeditor/EntityEvents.d.ts +0 -54
  13. package/dist/tools/prefabeditor/EntityEvents.js +0 -85
  14. package/dist/tools/prefabeditor/page.d.ts +0 -1
  15. package/dist/tools/prefabeditor/page.js +0 -5
  16. package/react-three-game-skill/.gitattributes +0 -2
  17. package/react-three-game-skill/README.md +0 -7
  18. package/react-three-game-skill/react-three-game/SKILL.md +0 -514
  19. package/react-three-game-skill/react-three-game/rules/ADVANCED_PHYSICS.md +0 -472
  20. package/react-three-game-skill/react-three-game/rules/LIGHTING.md +0 -6
  21. package/src/helpers/SoundManager.ts +0 -130
  22. package/src/helpers/index.ts +0 -91
  23. package/src/index.ts +0 -59
  24. package/src/shared/ContactShadow.tsx +0 -74
  25. package/src/shared/GameCanvas.tsx +0 -52
  26. package/src/tools/assetviewer/page.tsx +0 -425
  27. package/src/tools/dragdrop/DragDropLoader.tsx +0 -159
  28. package/src/tools/dragdrop/index.ts +0 -4
  29. package/src/tools/dragdrop/modelLoader.ts +0 -204
  30. package/src/tools/dragdrop/page.tsx +0 -45
  31. package/src/tools/prefabeditor/Dropdown.tsx +0 -112
  32. package/src/tools/prefabeditor/EditorContext.tsx +0 -25
  33. package/src/tools/prefabeditor/EditorTree.tsx +0 -452
  34. package/src/tools/prefabeditor/EditorTreeMenus.tsx +0 -307
  35. package/src/tools/prefabeditor/EditorUI.tsx +0 -204
  36. package/src/tools/prefabeditor/EventSystem.tsx +0 -36
  37. package/src/tools/prefabeditor/GameEvents.ts +0 -191
  38. package/src/tools/prefabeditor/InstanceProvider.tsx +0 -466
  39. package/src/tools/prefabeditor/PrefabEditor.tsx +0 -256
  40. package/src/tools/prefabeditor/PrefabRoot.tsx +0 -767
  41. package/src/tools/prefabeditor/components/AmbientLightComponent.tsx +0 -34
  42. package/src/tools/prefabeditor/components/CameraComponent.tsx +0 -117
  43. package/src/tools/prefabeditor/components/ComponentRegistry.ts +0 -40
  44. package/src/tools/prefabeditor/components/DirectionalLightComponent.tsx +0 -210
  45. package/src/tools/prefabeditor/components/EnvironmentComponent.tsx +0 -47
  46. package/src/tools/prefabeditor/components/GeometryComponent.tsx +0 -133
  47. package/src/tools/prefabeditor/components/Input.tsx +0 -820
  48. package/src/tools/prefabeditor/components/MaterialComponent.tsx +0 -431
  49. package/src/tools/prefabeditor/components/ModelComponent.tsx +0 -176
  50. package/src/tools/prefabeditor/components/PhysicsComponent.tsx +0 -188
  51. package/src/tools/prefabeditor/components/SpotLightComponent.tsx +0 -109
  52. package/src/tools/prefabeditor/components/TextComponent.tsx +0 -137
  53. package/src/tools/prefabeditor/components/TransformComponent.tsx +0 -173
  54. package/src/tools/prefabeditor/components/index.ts +0 -26
  55. package/src/tools/prefabeditor/page.tsx +0 -10
  56. package/src/tools/prefabeditor/styles.ts +0 -235
  57. package/src/tools/prefabeditor/types.ts +0 -20
  58. package/src/tools/prefabeditor/utils.ts +0 -312
@@ -1,307 +0,0 @@
1
- import { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react';
2
- import { createPortal } from 'react-dom';
3
- import { Prefab } from './types';
4
- import { menu } from './styles';
5
- import { useEditorContext } from './EditorContext';
6
- import { getComponent } from './components/ComponentRegistry';
7
- import { loadJson, saveJson, regenerateIds, updateNodeById } from './utils';
8
-
9
- export type TreeContextMenuState = { nodeId: string; x: number; y: number } | null;
10
-
11
- function createEmptyPrefab(): Prefab {
12
- return {
13
- id: crypto.randomUUID(),
14
- name: 'New Scene',
15
- root: {
16
- id: crypto.randomUUID(),
17
- name: 'Scene',
18
- components: {
19
- transform: {
20
- type: 'Transform',
21
- properties: { ...getComponent('Transform')?.defaultProperties }
22
- }
23
- },
24
- children: []
25
- }
26
- };
27
- }
28
-
29
- function MenuPanel({
30
- children,
31
- style,
32
- }: {
33
- children: React.ReactNode;
34
- style?: React.CSSProperties;
35
- }) {
36
- return (
37
- <div style={{ ...menu.container, position: 'static', ...style }} onClick={(e) => e.stopPropagation()}>
38
- {children}
39
- </div>
40
- );
41
- }
42
-
43
- function MenuItemButton({
44
- children,
45
- onClick,
46
- danger = false,
47
- style,
48
- }: {
49
- children: React.ReactNode;
50
- onClick: () => void;
51
- danger?: boolean;
52
- style?: React.CSSProperties;
53
- }) {
54
- return (
55
- <button
56
- style={danger ? { ...menu.item, ...menu.danger, ...style } : { ...menu.item, ...style }}
57
- onClick={onClick}
58
- >
59
- {children}
60
- </button>
61
- );
62
- }
63
-
64
- function MenuSubmenu({
65
- label,
66
- children,
67
- }: {
68
- label: string;
69
- children: React.ReactNode;
70
- }) {
71
- const [isOpen, setIsOpen] = useState(false);
72
-
73
- return (
74
- <div
75
- style={{ position: 'relative' }}
76
- onMouseEnter={() => setIsOpen(true)}
77
- onMouseLeave={() => setIsOpen(false)}
78
- >
79
- <MenuItemButton
80
- onClick={() => setIsOpen(open => !open)}
81
- style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}
82
- >
83
- <span>{label}</span>
84
- <span aria-hidden="true">›</span>
85
- </MenuItemButton>
86
- {isOpen && (
87
- <div
88
- style={{
89
- position: 'absolute',
90
- top: 0,
91
- left: '100%',
92
- zIndex: 1,
93
- }}
94
- >
95
- <MenuPanel>{children}</MenuPanel>
96
- </div>
97
- )}
98
- </div>
99
- );
100
- }
101
-
102
- export function MenuTriggerButton({
103
- buttonRef,
104
- onToggle,
105
- title,
106
- style,
107
- children,
108
- }: {
109
- buttonRef: React.RefObject<HTMLButtonElement | null>;
110
- onToggle: () => void;
111
- title: string;
112
- style: React.CSSProperties;
113
- children: React.ReactNode;
114
- }) {
115
- return (
116
- <button
117
- ref={buttonRef}
118
- style={style}
119
- onClick={(e) => {
120
- e.stopPropagation();
121
- onToggle();
122
- }}
123
- title={title}
124
- >
125
- {children}
126
- </button>
127
- );
128
- }
129
-
130
- export function TreeNodeMenu({
131
- isRoot,
132
- nodeId,
133
- onAddChild,
134
- onFocus,
135
- onDuplicate,
136
- onDelete,
137
- onClose,
138
- }: {
139
- isRoot: boolean;
140
- nodeId: string;
141
- onAddChild: (parentId: string) => void;
142
- onFocus: (nodeId: string) => void;
143
- onDuplicate?: (nodeId: string) => void;
144
- onDelete?: (nodeId: string) => void;
145
- onClose: () => void;
146
- }) {
147
- return (
148
- <MenuPanel>
149
- <MenuItemButton onClick={() => { onAddChild(nodeId); onClose(); }}>
150
- Add Child
151
- </MenuItemButton>
152
- <MenuItemButton onClick={() => { onFocus(nodeId); onClose(); }}>
153
- Focus Camera
154
- </MenuItemButton>
155
- {!isRoot && onDuplicate && (
156
- <MenuItemButton onClick={() => { onDuplicate(nodeId); onClose(); }}>
157
- Duplicate
158
- </MenuItemButton>
159
- )}
160
- {!isRoot && onDelete && (
161
- <MenuItemButton danger onClick={() => { onDelete(nodeId); onClose(); }}>
162
- Delete
163
- </MenuItemButton>
164
- )}
165
- </MenuPanel>
166
- );
167
- }
168
-
169
- export function TreeContextMenu({
170
- contextMenu,
171
- onClose,
172
- children,
173
- }: {
174
- contextMenu: TreeContextMenuState;
175
- onClose: () => void;
176
- children: (nodeId: string, onClose: () => void) => React.ReactNode;
177
- }) {
178
- const panelRef = useRef<HTMLDivElement>(null);
179
- const [position, setPosition] = useState<{ left: number; top: number } | null>(null);
180
-
181
- useEffect(() => {
182
- if (!contextMenu) return;
183
-
184
- const handlePointerDown = (event: PointerEvent) => {
185
- const target = event.target as Node | null;
186
- if (!target) return;
187
- if (panelRef.current?.contains(target)) return;
188
- onClose();
189
- };
190
-
191
- const handleKeyDown = (event: KeyboardEvent) => {
192
- if (event.key === 'Escape') onClose();
193
- };
194
-
195
- document.addEventListener('pointerdown', handlePointerDown);
196
- document.addEventListener('keydown', handleKeyDown);
197
-
198
- return () => {
199
- document.removeEventListener('pointerdown', handlePointerDown);
200
- document.removeEventListener('keydown', handleKeyDown);
201
- };
202
- }, [contextMenu, onClose]);
203
-
204
- useEffect(() => {
205
- if (!contextMenu || !panelRef.current || typeof window === 'undefined') return;
206
-
207
- const panelRect = panelRef.current.getBoundingClientRect();
208
- const left = Math.max(8, Math.min(contextMenu.x, window.innerWidth - panelRect.width - 8));
209
- const top = Math.max(8, Math.min(contextMenu.y, window.innerHeight - panelRect.height - 8));
210
- setPosition({ left, top });
211
- }, [contextMenu]);
212
-
213
- useEffect(() => {
214
- if (!contextMenu) {
215
- setPosition(null);
216
- }
217
- }, [contextMenu]);
218
-
219
- if (!contextMenu || typeof document === 'undefined') return null;
220
-
221
- return createPortal(
222
- <div
223
- ref={panelRef}
224
- style={{
225
- position: 'fixed',
226
- left: position?.left ?? contextMenu.x,
227
- top: position?.top ?? contextMenu.y,
228
- zIndex: 1000,
229
- }}
230
- onMouseLeave={onClose}
231
- onContextMenu={(e) => e.preventDefault()}
232
- >
233
- {children(contextMenu.nodeId, onClose)}
234
- </div>,
235
- document.body
236
- );
237
- }
238
-
239
- export function FileMenu({
240
- prefabData,
241
- setPrefabData,
242
- onClose
243
- }: {
244
- prefabData: Prefab;
245
- setPrefabData: Dispatch<SetStateAction<Prefab>>;
246
- onClose: () => void;
247
- }) {
248
- const { onScreenshot, onExportGLB } = useEditorContext();
249
-
250
- const handleNewScene = () => {
251
- setPrefabData(createEmptyPrefab());
252
- onClose();
253
- };
254
-
255
- const handleNewSceneFromPrefab = async () => {
256
- const loadedPrefab = await loadJson();
257
- if (!loadedPrefab) return;
258
- setPrefabData(loadedPrefab);
259
- onClose();
260
- };
261
-
262
- const handleSave = () => {
263
- saveJson(prefabData, 'prefab');
264
- onClose();
265
- };
266
-
267
- const handleLoadIntoScene = async () => {
268
- const loadedPrefab = await loadJson();
269
- if (!loadedPrefab) return;
270
-
271
- setPrefabData(prev => ({
272
- ...prev,
273
- root: updateNodeById(prev.root, prev.root.id, root => ({
274
- ...root,
275
- children: [...(root.children ?? []), regenerateIds(loadedPrefab.root)]
276
- }))
277
- }));
278
- onClose();
279
- };
280
-
281
- return (
282
- <MenuPanel style={{ overflow: 'visible' }}>
283
- <MenuSubmenu label="File">
284
- <MenuItemButton onClick={handleNewScene}>
285
- New Scene
286
- </MenuItemButton>
287
- <MenuItemButton onClick={handleNewSceneFromPrefab}>
288
- New Scene from Prefab
289
- </MenuItemButton>
290
- <MenuItemButton onClick={handleLoadIntoScene}>
291
- Load Prefab into Scene
292
- </MenuItemButton>
293
- <MenuItemButton onClick={handleSave}>
294
- Save Prefab
295
- </MenuItemButton>
296
- </MenuSubmenu>
297
- <MenuSubmenu label="Export">
298
- <MenuItemButton onClick={() => { onExportGLB?.(); onClose(); }}>
299
- GLB
300
- </MenuItemButton>
301
- <MenuItemButton onClick={() => { onScreenshot?.(); onClose(); }}>
302
- PNG
303
- </MenuItemButton>
304
- </MenuSubmenu>
305
- </MenuPanel>
306
- );
307
- }
@@ -1,204 +0,0 @@
1
- import { Dispatch, SetStateAction, useState, useEffect } from 'react';
2
- import { Prefab, GameObject as GameObjectType } from "./types";
3
- import EditorTree from './EditorTree';
4
- import { getAllComponents } from './components/ComponentRegistry';
5
- import { base, colors, inspector, scrollbarCSS, componentCard } from './styles';
6
- import { findNode, updateNode, deleteNode } from './utils';
7
-
8
- function EditorUI({
9
- prefabData,
10
- setPrefabData,
11
- selectedId,
12
- setSelectedId,
13
- basePath,
14
- onUndo,
15
- onRedo,
16
- canUndo,
17
- canRedo
18
- }: {
19
- prefabData?: Prefab;
20
- setPrefabData?: Dispatch<SetStateAction<Prefab>>;
21
- selectedId: string | null;
22
- setSelectedId: Dispatch<SetStateAction<string | null>>;
23
- basePath?: string;
24
- onUndo?: () => void;
25
- onRedo?: () => void;
26
- canUndo?: boolean;
27
- canRedo?: boolean;
28
- }) {
29
- const [collapsed, setCollapsed] = useState(false);
30
-
31
- const updateNodeHandler = (updater: (n: GameObjectType) => GameObjectType) => {
32
- if (!prefabData || !setPrefabData || !selectedId) return;
33
- setPrefabData(prev => ({
34
- ...prev,
35
- root: updateNode(prev.root, selectedId, updater)
36
- }));
37
- };
38
-
39
- const deleteNodeHandler = () => {
40
- if (!prefabData || !setPrefabData || !selectedId || selectedId === prefabData.root.id) return;
41
- setPrefabData(prev => ({ ...prev, root: deleteNode(prev.root, selectedId)! }));
42
- setSelectedId(null);
43
- };
44
-
45
- const selectedNode = selectedId && prefabData ? findNode(prefabData.root, selectedId) : null;
46
-
47
- return <>
48
- <style>{scrollbarCSS}</style>
49
- <div style={inspector.panel}>
50
- <div style={base.header} onClick={() => setCollapsed(!collapsed)}>
51
- <span>Inspector</span>
52
- <span>{collapsed ? '◀' : '▼'}</span>
53
- </div>
54
- {!collapsed && selectedNode && (
55
- <NodeInspector
56
- node={selectedNode}
57
- updateNode={updateNodeHandler}
58
- deleteNode={deleteNodeHandler}
59
- basePath={basePath}
60
- />
61
- )}
62
- </div>
63
- <div style={{ position: 'absolute', top: 8, left: 8, zIndex: 20 }}>
64
- <EditorTree
65
- prefabData={prefabData}
66
- setPrefabData={setPrefabData}
67
- selectedId={selectedId}
68
- setSelectedId={setSelectedId}
69
- onUndo={onUndo}
70
- onRedo={onRedo}
71
- canUndo={canUndo}
72
- canRedo={canRedo}
73
- />
74
- </div>
75
- </>;
76
- }
77
-
78
-
79
- function NodeInspector({
80
- node,
81
- updateNode,
82
- deleteNode,
83
- basePath
84
- }: {
85
- node: GameObjectType;
86
- updateNode: (updater: (n: GameObjectType) => GameObjectType) => void;
87
- deleteNode: () => void;
88
- basePath?: string;
89
- }) {
90
- const ALL_COMPONENTS = getAllComponents();
91
- const allKeys = Object.keys(ALL_COMPONENTS);
92
- const available = allKeys.filter(k => !node.components?.[k.toLowerCase()]);
93
- const [addType, setAddType] = useState(available[0] || "");
94
-
95
- useEffect(() => {
96
- const newAvailable = allKeys.filter(k => !node.components?.[k.toLowerCase()]);
97
- if (!newAvailable.includes(addType)) setAddType(newAvailable[0] || "");
98
- }, [Object.keys(node.components || {}).join(',')]);
99
-
100
- return <div style={inspector.content} className="prefab-scroll">
101
- {/* Node Name */}
102
- <div style={base.section}>
103
- <div style={{ display: "flex", marginBottom: 8, alignItems: 'center', gap: 8 }}>
104
- <div style={{ fontSize: 10, color: colors.textDim, wordBreak: 'break-all', border: `1px solid ${colors.border}`, padding: '2px 6px', borderRadius: 3, flex: 1, fontFamily: 'monospace' }}>
105
- {node.id}
106
- </div>
107
- <button style={{ ...base.btn, ...base.btnDanger }} title="Delete Node" onClick={deleteNode}>❌</button>
108
- </div>
109
-
110
- <input
111
- style={base.input}
112
- value={node.name ?? ""}
113
- placeholder='Node name'
114
- onChange={e =>
115
- updateNode(n => ({ ...n, name: e.target.value }))
116
- }
117
- />
118
- </div>
119
-
120
- {/* Components */}
121
- <div style={base.section}>
122
- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
123
- <div style={base.label}>Components</div>
124
- </div>
125
-
126
- {node.components && Object.entries(node.components).map(([key, comp]: [string, any]) => {
127
- if (!comp) return null;
128
- const def = ALL_COMPONENTS[comp.type];
129
- if (!def) return <div key={key} style={{ color: colors.danger, fontSize: 11 }}>
130
- Unknown: {comp.type}
131
- </div>;
132
-
133
- return (
134
- <div key={key} style={componentCard.container}>
135
- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 4 }}>
136
- <div style={{ fontSize: 11, fontWeight: 500 }}>{key}</div>
137
- <button
138
- style={{ ...base.btn, padding: '2px 6px' }}
139
- title="Remove Component"
140
- onClick={() => updateNode(n => {
141
- const { [key]: _, ...rest } = n.components || {};
142
- return { ...n, components: rest };
143
- })}
144
- >
145
-
146
- </button>
147
- </div>
148
- {def.Editor && (
149
- <def.Editor
150
- component={comp}
151
- node={node}
152
- onUpdate={(newProps: any) => updateNode(n => ({
153
- ...n,
154
- components: {
155
- ...n.components,
156
- [key]: { ...comp, properties: { ...comp.properties, ...newProps } }
157
- }
158
- }))}
159
- basePath={basePath}
160
- />
161
- )}
162
- </div>
163
- );
164
- })}
165
- </div>
166
-
167
- {/* Add Component */}
168
- {available.length > 0 && (
169
- <div>
170
- <div style={base.row}>
171
- <select
172
- style={{ ...base.input, flex: 1 }}
173
- value={addType}
174
- onChange={e => setAddType(e.target.value)}
175
- >
176
- {available.map(k => <option key={k} value={k}>{k}</option>)}
177
- </select>
178
- <button
179
- style={base.btn}
180
- disabled={!addType}
181
- onClick={() => {
182
- if (!addType) return;
183
- const def = ALL_COMPONENTS[addType];
184
- if (def) {
185
- updateNode(n => ({
186
- ...n,
187
- components: {
188
- ...n.components,
189
- [addType.toLowerCase()]: { type: def.name, properties: def.defaultProperties }
190
- }
191
- }));
192
- }
193
- }}
194
- title="Add Component"
195
- >
196
- +
197
- </button>
198
- </div>
199
- </div>
200
- )}
201
- </div>
202
- }
203
-
204
- export default EditorUI;
@@ -1,36 +0,0 @@
1
- import { useRef, useImperativeHandle, forwardRef, useCallback } from 'react';
2
-
3
- interface EventSystemRef {
4
- fire: (eventType: string, data?: any) => void;
5
- }
6
-
7
- const EventSystemHook = forwardRef<EventSystemRef, { entityId: string }>(
8
- ({ entityId }, ref) => {
9
- const targetRef = useRef<EventTarget>(typeof window !== 'undefined' ? window : null);
10
-
11
- // Fire a global JS event with entityId as source
12
- const fire = useCallback((eventType: string, data?: any) => {
13
- if (!targetRef.current) return;
14
-
15
- const event = new CustomEvent(eventType, {
16
- detail: {
17
- entityId,
18
- data,
19
- },
20
- });
21
-
22
- targetRef.current.dispatchEvent(event);
23
- }, [entityId]);
24
-
25
- // Expose ref API
26
- useImperativeHandle(ref, () => ({
27
- fire,
28
- }), [fire]);
29
-
30
- return null;
31
- }
32
- );
33
-
34
- EventSystemHook.displayName = 'EventSystemHook';
35
-
36
- export default EventSystemHook;