react-three-game 0.0.92 → 0.0.93

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 (33) hide show
  1. package/README.md +68 -33
  2. package/dist/helpers/index.d.ts +0 -3
  3. package/dist/helpers/index.js +1 -8
  4. package/dist/index.d.ts +5 -8
  5. package/dist/index.js +3 -4
  6. package/dist/tools/prefabeditor/EditorTree.js +2 -2
  7. package/dist/tools/prefabeditor/GameEvents.d.ts +6 -12
  8. package/dist/tools/prefabeditor/GameEvents.js +0 -8
  9. package/dist/tools/prefabeditor/InstanceProvider.d.ts +6 -4
  10. package/dist/tools/prefabeditor/InstanceProvider.js +84 -199
  11. package/dist/tools/prefabeditor/PrefabEditor.d.ts +18 -6
  12. package/dist/tools/prefabeditor/PrefabEditor.js +55 -39
  13. package/dist/tools/prefabeditor/PrefabRoot.d.ts +15 -8
  14. package/dist/tools/prefabeditor/PrefabRoot.js +141 -117
  15. package/dist/tools/prefabeditor/assetRuntime.d.ts +13 -11
  16. package/dist/tools/prefabeditor/assetRuntime.js +15 -15
  17. package/dist/tools/prefabeditor/components/BufferGeometryComponent.js +1 -1
  18. package/dist/tools/prefabeditor/components/CameraComponent.js +2 -2
  19. package/dist/tools/prefabeditor/components/ComponentRegistry.d.ts +3 -3
  20. package/dist/tools/prefabeditor/components/DirectionalLightComponent.js +2 -2
  21. package/dist/tools/prefabeditor/components/ModelComponent.js +1 -1
  22. package/dist/tools/prefabeditor/components/PointLightComponent.js +2 -2
  23. package/dist/tools/prefabeditor/components/SoundComponent.js +2 -2
  24. package/dist/tools/prefabeditor/components/SpotLightComponent.js +2 -2
  25. package/dist/tools/prefabeditor/components/index.js +0 -2
  26. package/dist/tools/prefabeditor/types.d.ts +1 -0
  27. package/dist/tools/prefabeditor/usePointerEvents.d.ts +3 -3
  28. package/dist/tools/prefabeditor/usePointerEvents.js +5 -5
  29. package/package.json +1 -3
  30. package/dist/tools/prefabeditor/components/PhysicsComponent.d.ts +0 -26
  31. package/dist/tools/prefabeditor/components/PhysicsComponent.js +0 -302
  32. package/dist/tools/prefabeditor/scene.d.ts +0 -70
  33. package/dist/tools/prefabeditor/scene.js +0 -237
@@ -1,237 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { findComponentEntry } from "./types";
13
- import { createComponentData, createNode as createPrefabNode } from "./prefab";
14
- function missingNode(id) {
15
- throw new Error(`Scene node not found: ${id}`);
16
- }
17
- function normalizePath(path) {
18
- if (!path)
19
- return [];
20
- return Array.isArray(path) ? path : path.split(".").filter(Boolean);
21
- }
22
- function getValueAtPath(value, path) {
23
- const segments = normalizePath(path);
24
- let current = value;
25
- for (const segment of segments) {
26
- if (current == null || typeof current !== "object") {
27
- return undefined;
28
- }
29
- current = current[segment];
30
- }
31
- return current;
32
- }
33
- function setValueAtPath(value, path, nextValue) {
34
- const segments = normalizePath(path);
35
- if (segments.length === 0) {
36
- return nextValue;
37
- }
38
- const cloneBranch = (current, index) => {
39
- const segment = segments[index];
40
- const source = current == null ? undefined : current;
41
- const container = Array.isArray(source)
42
- ? [...source]
43
- : source && typeof source === "object"
44
- ? Object.assign({}, source) : typeof segment === "number"
45
- ? []
46
- : {};
47
- if (index === segments.length - 1) {
48
- container[segment] = nextValue;
49
- return container;
50
- }
51
- const child = source && typeof source === "object"
52
- ? source[segment]
53
- : undefined;
54
- container[segment] = cloneBranch(child, index + 1);
55
- return container;
56
- };
57
- return cloneBranch(value, 0);
58
- }
59
- export function createScene(adapter) {
60
- let batchBuffer = null;
61
- function routeUpdate(id, update) {
62
- if (batchBuffer) {
63
- const prev = batchBuffer.get(id);
64
- batchBuffer.set(id, prev ? (node) => update(prev(node)) : update);
65
- return;
66
- }
67
- adapter.updateNode(id, update);
68
- }
69
- function routeUpdates(updates) {
70
- if (batchBuffer) {
71
- for (const id in updates)
72
- routeUpdate(id, updates[id]);
73
- return;
74
- }
75
- adapter.updateNodes(updates);
76
- }
77
- function batch(fn) {
78
- if (batchBuffer) {
79
- fn();
80
- return;
81
- }
82
- batchBuffer = new Map();
83
- try {
84
- fn();
85
- if (batchBuffer.size > 0) {
86
- const updates = {};
87
- for (const [id, update] of batchBuffer)
88
- updates[id] = update;
89
- adapter.updateNodes(updates);
90
- }
91
- }
92
- finally {
93
- batchBuffer = null;
94
- }
95
- }
96
- const getNode = (id) => {
97
- if (!adapter.getNode(id))
98
- missingNode(id);
99
- return createNode(id);
100
- };
101
- function createComponent(entityId, componentKey, componentType) {
102
- return {
103
- key: componentKey,
104
- type: componentType,
105
- get(path) {
106
- var _a;
107
- const node = adapter.getNode(entityId);
108
- const component = (_a = node === null || node === void 0 ? void 0 : node.components) === null || _a === void 0 ? void 0 : _a[componentKey];
109
- if (!component) {
110
- return undefined;
111
- }
112
- return getValueAtPath(component.properties, path);
113
- },
114
- set(path, value) {
115
- routeUpdate(entityId, node => {
116
- var _a;
117
- const component = (_a = node.components) === null || _a === void 0 ? void 0 : _a[componentKey];
118
- if (!component) {
119
- return node;
120
- }
121
- return Object.assign(Object.assign({}, node), { components: Object.assign(Object.assign({}, node.components), { [componentKey]: Object.assign(Object.assign({}, component), { properties: setValueAtPath(component.properties, path, value) }) }) });
122
- });
123
- },
124
- update(update) {
125
- routeUpdate(entityId, node => {
126
- var _a;
127
- const component = (_a = node.components) === null || _a === void 0 ? void 0 : _a[componentKey];
128
- if (!component) {
129
- return node;
130
- }
131
- const nextProperties = update(component.properties);
132
- if (nextProperties === component.properties) {
133
- return node;
134
- }
135
- return Object.assign(Object.assign({}, node), { components: Object.assign(Object.assign({}, node.components), { [componentKey]: Object.assign(Object.assign({}, component), { properties: nextProperties }) }) });
136
- });
137
- },
138
- };
139
- }
140
- function createNode(id) {
141
- return {
142
- id,
143
- get name() {
144
- var _a;
145
- return (_a = adapter.getNode(id)) === null || _a === void 0 ? void 0 : _a.name;
146
- },
147
- get enabled() {
148
- var _a;
149
- return !((_a = adapter.getNode(id)) === null || _a === void 0 ? void 0 : _a.disabled);
150
- },
151
- get parent() {
152
- const parentId = adapter.getParentId(id);
153
- return parentId ? createNode(parentId) : null;
154
- },
155
- get children() {
156
- return adapter.getChildIds(id).map(createNode);
157
- },
158
- get object() {
159
- var _a, _b;
160
- return (_b = (_a = adapter.getObject) === null || _a === void 0 ? void 0 : _a.call(adapter, id)) !== null && _b !== void 0 ? _b : null;
161
- },
162
- get rigidBody() {
163
- var _a, _b;
164
- return (_b = (_a = adapter.getRigidBody) === null || _a === void 0 ? void 0 : _a.call(adapter, id)) !== null && _b !== void 0 ? _b : null;
165
- },
166
- set(data) {
167
- routeUpdate(id, () => data);
168
- },
169
- update(update) {
170
- routeUpdate(id, update);
171
- },
172
- getComponent(name) {
173
- const node = adapter.getNode(id);
174
- if (!node)
175
- return null;
176
- const entry = findComponentEntry(node, name);
177
- if (!entry)
178
- return null;
179
- const [componentKey, component] = entry;
180
- return createComponent(id, componentKey, component.type);
181
- },
182
- addComponent(type, properties) {
183
- const key = type.toLowerCase();
184
- routeUpdate(id, node => (Object.assign(Object.assign({}, node), { components: Object.assign(Object.assign({}, node.components), { [key]: createComponentData(type, properties) }) })));
185
- return createComponent(id, key, type);
186
- },
187
- removeComponent(name) {
188
- routeUpdate(id, node => {
189
- var _a;
190
- const entry = findComponentEntry(node, name);
191
- if (!entry)
192
- return node;
193
- const [key] = entry;
194
- const _b = (_a = node.components) !== null && _a !== void 0 ? _a : {}, _c = key, _ = _b[_c], rest = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
195
- return Object.assign(Object.assign({}, node), { components: rest });
196
- });
197
- },
198
- destroy() {
199
- adapter.removeNode(id);
200
- },
201
- };
202
- }
203
- function update(idOrUpdates, mutate) {
204
- if (typeof idOrUpdates === "string") {
205
- if (!mutate) {
206
- return;
207
- }
208
- routeUpdate(idOrUpdates, mutate);
209
- return;
210
- }
211
- if (Object.keys(idOrUpdates).length === 0) {
212
- return;
213
- }
214
- routeUpdates(idOrUpdates);
215
- }
216
- return {
217
- get rootId() {
218
- return adapter.getRootId();
219
- },
220
- find(id) {
221
- return adapter.getNode(id) ? createNode(id) : null;
222
- },
223
- get: getNode,
224
- create(name, components, options) {
225
- const node = createPrefabNode(name, components);
226
- return createNode(adapter.addNode(node, options));
227
- },
228
- update,
229
- add(node, options) {
230
- return createNode(adapter.addNode(node, options));
231
- },
232
- remove(id) {
233
- adapter.removeNode(id);
234
- },
235
- batch,
236
- };
237
- }