react-three-game 0.0.18 → 0.0.19
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/.github/copilot-instructions.md +54 -183
- package/README.md +69 -214
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -0
- package/dist/tools/prefabeditor/EditorTree.d.ts +2 -4
- package/dist/tools/prefabeditor/EditorTree.js +20 -194
- package/dist/tools/prefabeditor/EditorUI.js +43 -224
- package/dist/tools/prefabeditor/PrefabEditor.js +33 -99
- package/dist/tools/prefabeditor/PrefabRoot.d.ts +0 -1
- package/dist/tools/prefabeditor/PrefabRoot.js +7 -23
- package/dist/tools/prefabeditor/components/DirectionalLightComponent.js +31 -43
- package/dist/tools/prefabeditor/styles.d.ts +1809 -0
- package/dist/tools/prefabeditor/styles.js +168 -0
- package/dist/tools/prefabeditor/types.d.ts +3 -14
- package/dist/tools/prefabeditor/types.js +0 -1
- package/dist/tools/prefabeditor/utils.d.ts +19 -0
- package/dist/tools/prefabeditor/utils.js +72 -0
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/src/tools/prefabeditor/EditorTree.tsx +38 -270
- package/src/tools/prefabeditor/EditorUI.tsx +105 -322
- package/src/tools/prefabeditor/PrefabEditor.tsx +40 -151
- package/src/tools/prefabeditor/PrefabRoot.tsx +11 -32
- package/src/tools/prefabeditor/components/DirectionalLightComponent.tsx +38 -53
- package/src/tools/prefabeditor/styles.ts +195 -0
- package/src/tools/prefabeditor/types.ts +4 -12
- package/src/tools/prefabeditor/utils.ts +80 -0
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
// import { ThreeElements } from "@react-three/fiber"
|
|
2
|
-
|
|
3
1
|
export interface Prefab {
|
|
4
2
|
id?: string;
|
|
5
3
|
name?: string;
|
|
6
|
-
|
|
7
|
-
author?: string;
|
|
8
|
-
version?: string;
|
|
9
|
-
assets?: string[] | {[assetName: string]: string}; // List of asset URLs or a mapping of asset names to URLs
|
|
10
|
-
onStart?: (target: any) => void; // The logic function to run when the map starts
|
|
11
|
-
root: GameObject; // The root node of the scene graph
|
|
4
|
+
root: GameObject;
|
|
12
5
|
}
|
|
13
6
|
|
|
14
7
|
export interface GameObject {
|
|
15
8
|
id: string;
|
|
16
9
|
disabled?: boolean;
|
|
17
10
|
hidden?: boolean;
|
|
18
|
-
ref?: any;
|
|
19
11
|
children?: GameObject[];
|
|
20
12
|
components?: {
|
|
21
|
-
[
|
|
13
|
+
[key: string]: ComponentData | undefined;
|
|
22
14
|
};
|
|
23
15
|
}
|
|
24
16
|
|
|
25
|
-
interface
|
|
17
|
+
export interface ComponentData {
|
|
26
18
|
type: string;
|
|
27
|
-
properties:
|
|
19
|
+
properties: Record<string, any>;
|
|
28
20
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { GameObject } from "./types";
|
|
2
|
+
|
|
3
|
+
/** Find a node by ID in the tree */
|
|
4
|
+
export function findNode(root: GameObject, id: string): GameObject | null {
|
|
5
|
+
if (root.id === id) return root;
|
|
6
|
+
for (const child of root.children ?? []) {
|
|
7
|
+
const found = findNode(child, id);
|
|
8
|
+
if (found) return found;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Find the parent of a node by ID */
|
|
14
|
+
export function findParent(root: GameObject, id: string): GameObject | null {
|
|
15
|
+
for (const child of root.children ?? []) {
|
|
16
|
+
if (child.id === id) return root;
|
|
17
|
+
const found = findParent(child, id);
|
|
18
|
+
if (found) return found;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Find all nodes matching a predicate */
|
|
24
|
+
export function findAll(root: GameObject, predicate: (node: GameObject) => boolean): GameObject[] {
|
|
25
|
+
const results: GameObject[] = [];
|
|
26
|
+
if (predicate(root)) results.push(root);
|
|
27
|
+
for (const child of root.children ?? []) {
|
|
28
|
+
results.push(...findAll(child, predicate));
|
|
29
|
+
}
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Find all nodes that have a specific component type */
|
|
34
|
+
export function findByComponent(root: GameObject, componentType: string): GameObject[] {
|
|
35
|
+
return findAll(root, node =>
|
|
36
|
+
Object.values(node.components ?? {}).some(c => c?.type === componentType)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Get a flattened list of all nodes */
|
|
41
|
+
export function flatten(root: GameObject): GameObject[] {
|
|
42
|
+
return findAll(root, () => true);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Immutably update a node by ID */
|
|
46
|
+
export function updateNode(root: GameObject, id: string, update: (node: GameObject) => GameObject): GameObject {
|
|
47
|
+
if (root.id === id) return update(root);
|
|
48
|
+
if (!root.children) return root;
|
|
49
|
+
return {
|
|
50
|
+
...root,
|
|
51
|
+
children: root.children.map(child => updateNode(child, id, update))
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Immutably delete a node by ID */
|
|
56
|
+
export function deleteNode(root: GameObject, id: string): GameObject | null {
|
|
57
|
+
if (root.id === id) return null;
|
|
58
|
+
if (!root.children) return root;
|
|
59
|
+
return {
|
|
60
|
+
...root,
|
|
61
|
+
children: root.children
|
|
62
|
+
.map(child => deleteNode(child, id))
|
|
63
|
+
.filter((child): child is GameObject => child !== null)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Deep clone a node with new IDs */
|
|
68
|
+
export function cloneNode(node: GameObject): GameObject {
|
|
69
|
+
return {
|
|
70
|
+
...node,
|
|
71
|
+
id: crypto.randomUUID(),
|
|
72
|
+
children: node.children?.map(cloneNode)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Get component data from a node */
|
|
77
|
+
export function getComponent<T = any>(node: GameObject, type: string): T | undefined {
|
|
78
|
+
const comp = Object.values(node.components ?? {}).find(c => c?.type === type);
|
|
79
|
+
return comp?.properties as T | undefined;
|
|
80
|
+
}
|