react-three-game 0.0.14 → 0.0.16
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 +50 -66
- package/dist/helpers/index.d.ts +35 -0
- package/dist/helpers/index.js +44 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/shared/GameCanvas.js +13 -13
- package/dist/tools/dragdrop/DragDropLoader.js +1 -0
- package/dist/tools/prefabeditor/EditorTree.js +116 -4
- package/dist/tools/prefabeditor/EditorUI.js +160 -6
- package/dist/tools/prefabeditor/PrefabEditor.js +56 -4
- package/dist/tools/prefabeditor/PrefabRoot.js +1 -10
- package/dist/tools/prefabeditor/types.d.ts +4 -4
- package/dist/tools/prefabeditor/types.js +1 -0
- package/package.json +4 -1
- package/src/helpers/index.ts +95 -0
- package/src/index.ts +3 -0
- package/src/shared/GameCanvas.tsx +5 -2
- package/src/tools/dragdrop/DragDropLoader.tsx +1 -0
- package/src/tools/prefabeditor/EditorTree.tsx +154 -16
- package/src/tools/prefabeditor/EditorUI.tsx +198 -51
- package/src/tools/prefabeditor/PrefabEditor.tsx +67 -7
- package/src/tools/prefabeditor/PrefabRoot.tsx +2 -13
- package/src/tools/prefabeditor/types.ts +5 -5
|
@@ -15,8 +15,6 @@ const PrefabEditor = ({ basePath, initialPrefab, onPrefabChange, children }: { b
|
|
|
15
15
|
"name": "New Prefab",
|
|
16
16
|
"root": {
|
|
17
17
|
"id": "root",
|
|
18
|
-
"enabled": true,
|
|
19
|
-
"visible": true,
|
|
20
18
|
"components": {
|
|
21
19
|
"transform": {
|
|
22
20
|
"type": "Transform",
|
|
@@ -69,26 +67,88 @@ const PrefabEditor = ({ basePath, initialPrefab, onPrefabChange, children }: { b
|
|
|
69
67
|
</Physics>
|
|
70
68
|
</GameCanvas>
|
|
71
69
|
|
|
72
|
-
<div
|
|
70
|
+
<div
|
|
71
|
+
style={{
|
|
72
|
+
position: "absolute",
|
|
73
|
+
top: 8,
|
|
74
|
+
left: "50%",
|
|
75
|
+
transform: "translateX(-50%)",
|
|
76
|
+
display: "flex",
|
|
77
|
+
alignItems: "center",
|
|
78
|
+
gap: 6,
|
|
79
|
+
padding: "2px 4px",
|
|
80
|
+
background: "rgba(0,0,0,0.55)",
|
|
81
|
+
border: "1px solid rgba(255,255,255,0.12)",
|
|
82
|
+
borderRadius: 4,
|
|
83
|
+
color: "rgba(255,255,255,0.9)",
|
|
84
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",
|
|
85
|
+
fontSize: 11,
|
|
86
|
+
lineHeight: 1,
|
|
87
|
+
WebkitUserSelect: "none",
|
|
88
|
+
userSelect: "none",
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
73
91
|
<button
|
|
74
|
-
|
|
92
|
+
style={{
|
|
93
|
+
padding: "2px 6px",
|
|
94
|
+
font: "inherit",
|
|
95
|
+
background: "transparent",
|
|
96
|
+
color: "inherit",
|
|
97
|
+
border: "1px solid rgba(255,255,255,0.18)",
|
|
98
|
+
borderRadius: 3,
|
|
99
|
+
cursor: "pointer",
|
|
100
|
+
}}
|
|
75
101
|
onClick={() => setEditMode(!editMode)}
|
|
102
|
+
onPointerEnter={(e) => {
|
|
103
|
+
(e.currentTarget as HTMLButtonElement).style.background = "rgba(255,255,255,0.08)";
|
|
104
|
+
}}
|
|
105
|
+
onPointerLeave={(e) => {
|
|
106
|
+
(e.currentTarget as HTMLButtonElement).style.background = "transparent";
|
|
107
|
+
}}
|
|
76
108
|
>
|
|
77
109
|
{editMode ? "▶" : "⏸"}
|
|
78
110
|
</button>
|
|
79
|
-
<span
|
|
111
|
+
<span style={{ opacity: 0.35 }}>|</span>
|
|
80
112
|
<button
|
|
81
|
-
|
|
113
|
+
style={{
|
|
114
|
+
padding: "2px 6px",
|
|
115
|
+
font: "inherit",
|
|
116
|
+
background: "transparent",
|
|
117
|
+
color: "inherit",
|
|
118
|
+
border: "1px solid rgba(255,255,255,0.18)",
|
|
119
|
+
borderRadius: 3,
|
|
120
|
+
cursor: "pointer",
|
|
121
|
+
}}
|
|
82
122
|
onClick={async () => {
|
|
83
123
|
const prefab = await loadJson();
|
|
84
124
|
if (prefab) setLoadedPrefab(prefab);
|
|
85
125
|
}}
|
|
126
|
+
onPointerEnter={(e) => {
|
|
127
|
+
(e.currentTarget as HTMLButtonElement).style.background = "rgba(255,255,255,0.08)";
|
|
128
|
+
}}
|
|
129
|
+
onPointerLeave={(e) => {
|
|
130
|
+
(e.currentTarget as HTMLButtonElement).style.background = "transparent";
|
|
131
|
+
}}
|
|
86
132
|
>
|
|
87
133
|
📥
|
|
88
134
|
</button>
|
|
89
135
|
<button
|
|
90
|
-
|
|
136
|
+
style={{
|
|
137
|
+
padding: "2px 6px",
|
|
138
|
+
font: "inherit",
|
|
139
|
+
background: "transparent",
|
|
140
|
+
color: "inherit",
|
|
141
|
+
border: "1px solid rgba(255,255,255,0.18)",
|
|
142
|
+
borderRadius: 3,
|
|
143
|
+
cursor: "pointer",
|
|
144
|
+
}}
|
|
91
145
|
onClick={() => saveJson(loadedPrefab, "prefab")}
|
|
146
|
+
onPointerEnter={(e) => {
|
|
147
|
+
(e.currentTarget as HTMLButtonElement).style.background = "rgba(255,255,255,0.08)";
|
|
148
|
+
}}
|
|
149
|
+
onPointerLeave={(e) => {
|
|
150
|
+
(e.currentTarget as HTMLButtonElement).style.background = "transparent";
|
|
151
|
+
}}
|
|
92
152
|
>
|
|
93
153
|
💾
|
|
94
154
|
</button>
|
|
@@ -59,15 +59,6 @@ export const PrefabRoot = forwardRef<Group, {
|
|
|
59
59
|
}
|
|
60
60
|
}, [selectedId]);
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
// const [transformMode, setTransformMode] = useState<"translate" | "rotate" | "scale">("translate"); // Removed local state
|
|
64
|
-
|
|
65
|
-
const updateNode = (updater: (node: GameObjectType) => GameObjectType) => {
|
|
66
|
-
if (!selectedId || !onPrefabChange) return;
|
|
67
|
-
const newRoot = updatePrefabNode(data.root, selectedId, updater);
|
|
68
|
-
onPrefabChange({ ...data, root: newRoot });
|
|
69
|
-
};
|
|
70
|
-
|
|
71
62
|
const onTransformChange = () => {
|
|
72
63
|
if (!selectedId || !onPrefabChange) return;
|
|
73
64
|
const obj = objectRefs.current[selectedId];
|
|
@@ -167,7 +158,7 @@ export const PrefabRoot = forwardRef<Group, {
|
|
|
167
158
|
loadedModels={loadedModels}
|
|
168
159
|
loadedTextures={loadedTextures}
|
|
169
160
|
editMode={editMode}
|
|
170
|
-
parentMatrix={new Matrix4()}
|
|
161
|
+
parentMatrix={new Matrix4()}
|
|
171
162
|
/>
|
|
172
163
|
</GameInstanceProvider>
|
|
173
164
|
|
|
@@ -242,7 +233,7 @@ function GameObjectRenderer({
|
|
|
242
233
|
clickValid.current = false;
|
|
243
234
|
};
|
|
244
235
|
|
|
245
|
-
if (
|
|
236
|
+
if (gameObject.disabled === true || gameObject.hidden === true) return null;
|
|
246
237
|
|
|
247
238
|
// --- 2. If instanced, short-circuit to a tiny clean branch ---
|
|
248
239
|
const isInstanced = !!gameObject.components?.model?.properties?.instanced;
|
|
@@ -269,8 +260,6 @@ function GameObjectRenderer({
|
|
|
269
260
|
));
|
|
270
261
|
|
|
271
262
|
// --- 4. Wrap with physics if needed ---
|
|
272
|
-
// Only wrap the core content (geometry/model), not children
|
|
273
|
-
// Children should be siblings, not inside the physics body
|
|
274
263
|
const physicsWrapped = wrapPhysicsIfNeeded(gameObject, core, ctx);
|
|
275
264
|
|
|
276
265
|
// --- 6. Final group wrapper ---
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ThreeElements } from "@react-three/fiber"
|
|
1
|
+
// import { ThreeElements } from "@react-three/fiber"
|
|
2
2
|
|
|
3
3
|
export interface Prefab {
|
|
4
|
-
id
|
|
5
|
-
name
|
|
4
|
+
id?: string;
|
|
5
|
+
name?: string;
|
|
6
6
|
description?: string;
|
|
7
7
|
author?: string;
|
|
8
8
|
version?: string;
|
|
@@ -13,8 +13,8 @@ export interface Prefab {
|
|
|
13
13
|
|
|
14
14
|
export interface GameObject {
|
|
15
15
|
id: string;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
hidden?: boolean;
|
|
18
18
|
ref?: any;
|
|
19
19
|
children?: GameObject[];
|
|
20
20
|
components?: {
|