react-three-game 0.0.100 → 0.0.102

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 (38) hide show
  1. package/README.md +2 -1
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +1 -0
  4. package/dist/plugins/crashcat/CrashcatPhysicsComponent.d.ts +3 -0
  5. package/dist/plugins/crashcat/CrashcatPhysicsComponent.js +352 -0
  6. package/dist/plugins/crashcat/CrashcatRuntime.d.ts +27 -0
  7. package/dist/plugins/crashcat/CrashcatRuntime.js +154 -0
  8. package/dist/plugins/crashcat/index.d.ts +2 -0
  9. package/dist/plugins/crashcat/index.js +2 -0
  10. package/dist/plugins/index.d.ts +1 -0
  11. package/dist/plugins/index.js +1 -0
  12. package/dist/tools/assetviewer/page.js +95 -46
  13. package/dist/tools/dragdrop/DragDropLoader.d.ts +3 -0
  14. package/dist/tools/dragdrop/DragDropLoader.js +183 -44
  15. package/dist/tools/dragdrop/index.d.ts +1 -1
  16. package/dist/tools/dragdrop/index.js +1 -1
  17. package/dist/tools/dragdrop/modelLoader.js +2 -0
  18. package/dist/tools/prefabeditor/EditorUI.js +7 -8
  19. package/dist/tools/prefabeditor/PrefabEditor.d.ts +3 -0
  20. package/dist/tools/prefabeditor/PrefabEditor.js +28 -11
  21. package/dist/tools/prefabeditor/PrefabRoot.d.ts +2 -0
  22. package/dist/tools/prefabeditor/PrefabRoot.js +51 -35
  23. package/dist/tools/prefabeditor/components/BufferGeometryComponent.js +20 -0
  24. package/dist/tools/prefabeditor/components/ComponentRegistry.d.ts +5 -0
  25. package/dist/tools/prefabeditor/components/ComponentRegistry.js +31 -0
  26. package/dist/tools/prefabeditor/components/DataComponent.js +1 -0
  27. package/dist/tools/prefabeditor/components/EnvironmentComponent.js +1 -0
  28. package/dist/tools/prefabeditor/components/GeometryComponent.js +1 -0
  29. package/dist/tools/prefabeditor/components/MaterialComponent.d.ts +1 -0
  30. package/dist/tools/prefabeditor/components/MaterialComponent.js +85 -57
  31. package/dist/tools/prefabeditor/components/ModelComponent.js +45 -3
  32. package/dist/tools/prefabeditor/components/SpriteComponent.js +1 -0
  33. package/dist/tools/prefabeditor/components/TransformComponent.js +1 -0
  34. package/dist/tools/prefabeditor/modelPrefab.d.ts +16 -0
  35. package/dist/tools/prefabeditor/modelPrefab.js +180 -0
  36. package/dist/tools/prefabeditor/prefabStore.d.ts +1 -0
  37. package/dist/tools/prefabeditor/prefabStore.js +75 -42
  38. package/package.json +27 -2
@@ -5,6 +5,45 @@ import { createStore } from "zustand/vanilla";
5
5
  import { collectAssetRefsForIds, collectSubtreeAssetRefs, collectSubtreeIds, cloneSubtree, createPrefabPatch, denormalizePrefab, insertSubtree, isDescendant, normalizePrefab, updateAssetRefsForNodeChange, } from "./prefab";
6
6
  const PrefabStoreContext = createContext(null);
7
7
  const EMPTY_CHILD_IDS = [];
8
+ function addAssetRefs(assetRefCounts, refs) {
9
+ refs.forEach(ref => {
10
+ var _a;
11
+ assetRefCounts[ref] = ((_a = assetRefCounts[ref]) !== null && _a !== void 0 ? _a : 0) + 1;
12
+ });
13
+ }
14
+ function removeAssetRefs(assetRefCounts, refs) {
15
+ refs.forEach(ref => {
16
+ var _a;
17
+ const nextCount = ((_a = assetRefCounts[ref]) !== null && _a !== void 0 ? _a : 0) - 1;
18
+ if (nextCount > 0) {
19
+ assetRefCounts[ref] = nextCount;
20
+ return;
21
+ }
22
+ delete assetRefCounts[ref];
23
+ });
24
+ }
25
+ function cloneGraphState(state) {
26
+ return {
27
+ nodesById: Object.assign({}, state.nodesById),
28
+ childIdsById: Object.assign({}, state.childIdsById),
29
+ parentIdById: Object.assign({}, state.parentIdById),
30
+ assetRefCounts: Object.assign({}, state.assetRefCounts),
31
+ };
32
+ }
33
+ function removeSubtreeFromGraph(id, state, next) {
34
+ const ids = collectSubtreeIds(id, state.childIdsById);
35
+ removeAssetRefs(next.assetRefCounts, collectAssetRefsForIds(ids, state.nodesById));
36
+ ids.forEach(nodeId => {
37
+ delete next.nodesById[nodeId];
38
+ delete next.childIdsById[nodeId];
39
+ delete next.parentIdById[nodeId];
40
+ });
41
+ return ids;
42
+ }
43
+ function insertSubtreeIntoGraph(node, parentId, next) {
44
+ insertSubtree(node, parentId, next.nodesById, next.childIdsById, next.parentIdById);
45
+ addAssetRefs(next.assetRefCounts, collectSubtreeAssetRefs(node));
46
+ }
8
47
  export function PrefabStoreProvider({ store, children, }) {
9
48
  return createElement(PrefabStoreContext.Provider, { value: store }, children);
10
49
  }
@@ -42,26 +81,40 @@ export function createPrefabStore(prefab) {
42
81
  set(createPrefabPatch(state, {
43
82
  nodesById: Object.assign(Object.assign({}, state.nodesById), { [id]: nextNode }),
44
83
  }, nextAssetRefCounts));
84
+ }, replaceNode: (id, node) => {
85
+ var _a;
86
+ const state = get();
87
+ if (!state.nodesById[id])
88
+ return;
89
+ const parentId = state.parentIdById[id];
90
+ const next = cloneGraphState(state);
91
+ removeSubtreeFromGraph(id, state, next);
92
+ insertSubtreeIntoGraph(node, parentId, next);
93
+ const patch = {
94
+ nodesById: next.nodesById,
95
+ childIdsById: next.childIdsById,
96
+ parentIdById: next.parentIdById,
97
+ };
98
+ if (id === state.rootId) {
99
+ patch.rootId = node.id;
100
+ }
101
+ else if (parentId) {
102
+ next.childIdsById[parentId] = ((_a = next.childIdsById[parentId]) !== null && _a !== void 0 ? _a : []).map(childId => childId === id ? node.id : childId);
103
+ }
104
+ set(createPrefabPatch(state, patch, next.assetRefCounts));
45
105
  }, addChild: (parentId, node) => {
46
106
  var _a;
47
107
  const state = get();
48
108
  if (!state.nodesById[parentId])
49
109
  return;
50
- const nextNodesById = Object.assign({}, state.nodesById);
51
- const nextChildIdsById = Object.assign({}, state.childIdsById);
52
- const nextParentIdById = Object.assign({}, state.parentIdById);
53
- const nextAssetRefCounts = Object.assign({}, state.assetRefCounts);
54
- insertSubtree(node, parentId, nextNodesById, nextChildIdsById, nextParentIdById);
55
- nextChildIdsById[parentId] = [...((_a = nextChildIdsById[parentId]) !== null && _a !== void 0 ? _a : []), node.id];
56
- collectSubtreeAssetRefs(node).forEach(ref => {
57
- var _a;
58
- nextAssetRefCounts[ref] = ((_a = nextAssetRefCounts[ref]) !== null && _a !== void 0 ? _a : 0) + 1;
59
- });
110
+ const next = cloneGraphState(state);
111
+ insertSubtreeIntoGraph(node, parentId, next);
112
+ next.childIdsById[parentId] = [...((_a = next.childIdsById[parentId]) !== null && _a !== void 0 ? _a : []), node.id];
60
113
  set(createPrefabPatch(state, {
61
- nodesById: nextNodesById,
62
- childIdsById: nextChildIdsById,
63
- parentIdById: nextParentIdById,
64
- }, nextAssetRefCounts));
114
+ nodesById: next.nodesById,
115
+ childIdsById: next.childIdsById,
116
+ parentIdById: next.parentIdById,
117
+ }, next.assetRefCounts));
65
118
  }, deleteNode: (id) => {
66
119
  var _a;
67
120
  const state = get();
@@ -70,31 +123,14 @@ export function createPrefabStore(prefab) {
70
123
  const parentId = state.parentIdById[id];
71
124
  if (!parentId)
72
125
  return;
73
- const idsToDelete = collectSubtreeIds(id, state.childIdsById);
74
- const nextNodesById = Object.assign({}, state.nodesById);
75
- const nextChildIdsById = Object.assign({}, state.childIdsById);
76
- const nextParentIdById = Object.assign({}, state.parentIdById);
77
- const nextAssetRefCounts = Object.assign({}, state.assetRefCounts);
78
- collectAssetRefsForIds(idsToDelete, state.nodesById).forEach(ref => {
79
- var _a;
80
- const nextCount = ((_a = nextAssetRefCounts[ref]) !== null && _a !== void 0 ? _a : 0) - 1;
81
- if (nextCount > 0) {
82
- nextAssetRefCounts[ref] = nextCount;
83
- return;
84
- }
85
- delete nextAssetRefCounts[ref];
86
- });
87
- idsToDelete.forEach(nodeId => {
88
- delete nextNodesById[nodeId];
89
- delete nextChildIdsById[nodeId];
90
- delete nextParentIdById[nodeId];
91
- });
92
- nextChildIdsById[parentId] = ((_a = nextChildIdsById[parentId]) !== null && _a !== void 0 ? _a : []).filter(childId => childId !== id);
126
+ const next = cloneGraphState(state);
127
+ removeSubtreeFromGraph(id, state, next);
128
+ next.childIdsById[parentId] = ((_a = next.childIdsById[parentId]) !== null && _a !== void 0 ? _a : []).filter(childId => childId !== id);
93
129
  set(createPrefabPatch(state, {
94
- nodesById: nextNodesById,
95
- childIdsById: nextChildIdsById,
96
- parentIdById: nextParentIdById,
97
- }, nextAssetRefCounts));
130
+ nodesById: next.nodesById,
131
+ childIdsById: next.childIdsById,
132
+ parentIdById: next.parentIdById,
133
+ }, next.assetRefCounts));
98
134
  }, duplicateNode: (id) => {
99
135
  var _a;
100
136
  const state = get();
@@ -119,10 +155,7 @@ export function createPrefabStore(prefab) {
119
155
  }
120
156
  nextChildIdsById[parentId] = siblings;
121
157
  const nextAssetRefCounts = Object.assign({}, state.assetRefCounts);
122
- collectAssetRefsForIds(collectSubtreeIds(id, state.childIdsById), state.nodesById).forEach(ref => {
123
- var _a;
124
- nextAssetRefCounts[ref] = ((_a = nextAssetRefCounts[ref]) !== null && _a !== void 0 ? _a : 0) + 1;
125
- });
158
+ addAssetRefs(nextAssetRefCounts, collectAssetRefsForIds(collectSubtreeIds(id, state.childIdsById), state.nodesById));
126
159
  set(createPrefabPatch(state, {
127
160
  nodesById: nextNodesById,
128
161
  childIdsById: nextChildIdsById,
package/package.json CHANGED
@@ -1,10 +1,28 @@
1
1
  {
2
2
  "name": "react-three-game",
3
- "version": "0.0.100",
3
+ "version": "0.0.102",
4
4
  "description": "high performance 3D game engine built in React",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./plugins": {
15
+ "types": "./dist/plugins/index.d.ts",
16
+ "import": "./dist/plugins/index.js",
17
+ "default": "./dist/plugins/index.js"
18
+ },
19
+ "./plugins/crashcat": {
20
+ "types": "./dist/plugins/crashcat/index.d.ts",
21
+ "import": "./dist/plugins/crashcat/index.js",
22
+ "default": "./dist/plugins/crashcat/index.js"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
8
26
  "files": [
9
27
  "dist",
10
28
  "README.md",
@@ -30,7 +48,13 @@
30
48
  "react": ">=18.0.0",
31
49
  "react-dom": ">=18.0.0",
32
50
  "three": ">=0.182.0",
33
- "three-text": ">=0.4.4"
51
+ "three-text": ">=0.4.4",
52
+ "crashcat": ">=0.0.4"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "crashcat": {
56
+ "optional": true
57
+ }
34
58
  },
35
59
  "devDependencies": {
36
60
  "@react-three/drei": "^10.7.7",
@@ -39,6 +63,7 @@
39
63
  "@types/react-dom": "^19.2.3",
40
64
  "@types/three": "^0.182.0",
41
65
  "concurrently": "^9.2.1",
66
+ "crashcat": "^0.0.4",
42
67
  "react": "^19.2.4",
43
68
  "react-dom": "^19.2.4",
44
69
  "three": "^0.184.0",