react-three-game 0.0.106 → 0.0.108

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 (28) hide show
  1. package/README.md +7 -0
  2. package/dist/plugins/crashcat/CrashcatPhysicsComponent.js +74 -46
  3. package/dist/plugins/crashcat/CrashcatRagdoll.d.ts +58 -0
  4. package/dist/plugins/crashcat/CrashcatRagdoll.js +410 -0
  5. package/dist/plugins/crashcat/CrashcatRuntime.js +23 -32
  6. package/dist/plugins/crashcat/index.d.ts +1 -0
  7. package/dist/plugins/crashcat/index.js +1 -0
  8. package/dist/tools/assetviewer/page.js +4 -4
  9. package/dist/tools/prefabeditor/EditorTree.js +5 -2
  10. package/dist/tools/prefabeditor/EditorTreeMenus.d.ts +2 -1
  11. package/dist/tools/prefabeditor/EditorTreeMenus.js +17 -5
  12. package/dist/tools/prefabeditor/GameEvents.d.ts +1 -0
  13. package/dist/tools/prefabeditor/PrefabEditor.d.ts +2 -1
  14. package/dist/tools/prefabeditor/PrefabEditor.js +26 -13
  15. package/dist/tools/prefabeditor/PrefabRoot.d.ts +3 -1
  16. package/dist/tools/prefabeditor/PrefabRoot.js +61 -25
  17. package/dist/tools/prefabeditor/components/ComponentRegistry.d.ts +15 -0
  18. package/dist/tools/prefabeditor/components/PrefabRefComponent.d.ts +3 -0
  19. package/dist/tools/prefabeditor/components/PrefabRefComponent.js +72 -0
  20. package/dist/tools/prefabeditor/components/TextComponent.js +8 -5
  21. package/dist/tools/prefabeditor/components/index.js +2 -0
  22. package/dist/tools/prefabeditor/modelPrefab.d.ts +3 -0
  23. package/dist/tools/prefabeditor/modelPrefab.js +44 -11
  24. package/dist/tools/prefabeditor/prefab.d.ts +5 -4
  25. package/dist/tools/prefabeditor/prefab.js +47 -29
  26. package/dist/tools/prefabeditor/utils.d.ts +8 -1
  27. package/dist/tools/prefabeditor/utils.js +74 -22
  28. package/package.json +13 -13
@@ -8,17 +8,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { findComponent } from "./types";
11
- import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js';
12
- import { Box3, Euler, Matrix4, PerspectiveCamera, Quaternion, Vector3 } from 'three';
11
+ import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter.js";
12
+ import { Box3, Euler, Matrix4, PerspectiveCamera, Quaternion, Vector3, } from "three";
13
+ export function isExternalPath(path) {
14
+ return (path.startsWith("data:") ||
15
+ path.startsWith("http://") ||
16
+ path.startsWith("https://"));
17
+ }
18
+ export function withBasePath(basePath, path) {
19
+ if (!path)
20
+ return (basePath !== null && basePath !== void 0 ? basePath : "").replace(/\/$/, "");
21
+ if (isExternalPath(path))
22
+ return path;
23
+ const normalizedBasePath = (basePath !== null && basePath !== void 0 ? basePath : "").replace(/\/$/, "");
24
+ return path.startsWith("/") ? `${normalizedBasePath}${path}` : `${normalizedBasePath}/${path}`;
25
+ }
13
26
  /** Save scene JSON, showing a Save As dialog when supported */
14
27
  export function saveJson(data, filename) {
15
28
  return __awaiter(this, void 0, void 0, function* () {
16
29
  const json = JSON.stringify(data, null, 2);
17
- if ('showSaveFilePicker' in window) {
30
+ if ("showSaveFilePicker" in window) {
18
31
  try {
19
32
  const handle = yield window.showSaveFilePicker({
20
- suggestedName: `${filename || 'scene'}.json`,
21
- types: [{ description: 'JSON', accept: { 'application/json': ['.json'] } }],
33
+ suggestedName: `${filename || "scene"}.json`,
34
+ types: [
35
+ { description: "JSON", accept: { "application/json": [".json"] } },
36
+ ],
22
37
  });
23
38
  const writable = yield handle.createWritable();
24
39
  yield writable.write(json);
@@ -26,38 +41,70 @@ export function saveJson(data, filename) {
26
41
  return;
27
42
  }
28
43
  catch (e) {
29
- if ((e === null || e === void 0 ? void 0 : e.name) === 'AbortError')
44
+ if ((e === null || e === void 0 ? void 0 : e.name) === "AbortError")
30
45
  return; // user cancelled
31
46
  }
32
47
  }
33
48
  // Fallback for browsers without File System Access API
34
- const a = document.createElement('a');
49
+ const a = document.createElement("a");
35
50
  a.href = "data:text/json;charset=utf-8," + encodeURIComponent(json);
36
- a.download = `${filename || 'scene'}.json`;
51
+ a.download = `${filename || "scene"}.json`;
37
52
  a.click();
38
53
  });
39
54
  }
40
55
  /** Load scene JSON from a file */
41
56
  export function loadJson() {
42
- return new Promise(resolve => {
43
- const input = document.createElement('input');
44
- input.type = 'file';
45
- input.accept = '.json,application/json';
46
- input.onchange = e => {
57
+ return new Promise((resolve) => {
58
+ const input = document.createElement("input");
59
+ input.type = "file";
60
+ input.accept = ".json,application/json";
61
+ input.onchange = (e) => {
47
62
  var _a;
48
63
  const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
49
64
  if (!file)
50
65
  return resolve(undefined);
51
66
  const reader = new FileReader();
52
- reader.onload = e => {
67
+ reader.onload = (e) => {
53
68
  var _a;
54
69
  try {
55
70
  const text = (_a = e.target) === null || _a === void 0 ? void 0 : _a.result;
56
- if (typeof text === 'string')
71
+ if (typeof text === "string")
57
72
  resolve(JSON.parse(text));
58
73
  }
59
74
  catch (err) {
60
- console.error('Error parsing scene JSON:', err);
75
+ console.error("Error parsing scene JSON:", err);
76
+ resolve(undefined);
77
+ }
78
+ };
79
+ reader.readAsText(file);
80
+ };
81
+ input.click();
82
+ });
83
+ }
84
+ /** Load scene JSON from a file, also returning the original filename */
85
+ export function loadJsonFile() {
86
+ return new Promise((resolve) => {
87
+ const input = document.createElement("input");
88
+ input.type = "file";
89
+ input.accept = ".json,application/json";
90
+ input.onchange = (e) => {
91
+ var _a;
92
+ const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
93
+ if (!file)
94
+ return resolve(undefined);
95
+ const reader = new FileReader();
96
+ reader.onload = (ev) => {
97
+ var _a;
98
+ try {
99
+ const text = (_a = ev.target) === null || _a === void 0 ? void 0 : _a.result;
100
+ if (typeof text === "string")
101
+ resolve({
102
+ prefab: JSON.parse(text),
103
+ filename: file.name,
104
+ });
105
+ }
106
+ catch (err) {
107
+ console.error("Error parsing scene JSON:", err);
61
108
  resolve(undefined);
62
109
  }
63
110
  };
@@ -79,12 +126,12 @@ export function exportGLBData(sceneRoot) {
79
126
  */
80
127
  export function exportGLB(sceneRoot_1) {
81
128
  return __awaiter(this, arguments, void 0, function* (sceneRoot, options = {}) {
82
- const { filename = 'scene.glb' } = options;
129
+ const { filename = "scene.glb" } = options;
83
130
  const data = yield exportGLBData(sceneRoot);
84
131
  if (filename) {
85
- const blob = new Blob([data], { type: 'application/octet-stream' });
132
+ const blob = new Blob([data], { type: "application/octet-stream" });
86
133
  const url = URL.createObjectURL(blob);
87
- const a = document.createElement('a');
134
+ const a = document.createElement("a");
88
135
  a.href = url;
89
136
  a.download = filename;
90
137
  a.click();
@@ -110,11 +157,16 @@ export function focusCameraOnObject(object, camera, target, update) {
110
157
  const radius = Math.max(size.length() * 0.5, 1);
111
158
  const forward = new Vector3(0, 0, 1).applyQuaternion(quaternion).normalize();
112
159
  const worldUp = new Vector3(0, 1, 0);
113
- const elevatedDirection = forward.clone().addScaledVector(worldUp, 0.65).normalize();
160
+ const elevatedDirection = forward
161
+ .clone()
162
+ .addScaledVector(worldUp, 0.65)
163
+ .normalize();
114
164
  const distance = camera instanceof PerspectiveCamera
115
- ? Math.max(radius / Math.tan((camera.fov * Math.PI) / 360) * 1.8, radius * 3.5)
165
+ ? Math.max((radius / Math.tan((camera.fov * Math.PI) / 360)) * 1.8, radius * 3.5)
116
166
  : radius * 4.5;
117
- const nextPosition = center.clone().add(elevatedDirection.multiplyScalar(distance));
167
+ const nextPosition = center
168
+ .clone()
169
+ .add(elevatedDirection.multiplyScalar(distance));
118
170
  camera.position.copy(nextPosition);
119
171
  camera.lookAt(center);
120
172
  target.copy(center);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-three-game",
3
- "version": "0.0.106",
3
+ "version": "0.0.108",
4
4
  "description": "high performance 3D game engine built in React",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -57,18 +57,18 @@
57
57
  }
58
58
  },
59
59
  "devDependencies": {
60
- "@react-three/drei": "^10.7.7",
61
- "@react-three/fiber": "^9.5.0",
62
- "@types/react": "^19.2.9",
63
- "@types/react-dom": "^19.2.3",
64
- "@types/three": "^0.182.0",
65
- "concurrently": "^9.2.1",
66
- "crashcat": "^0.0.4",
67
- "react": "^19.2.4",
68
- "react-dom": "^19.2.4",
69
- "three": "^0.184.0",
70
- "typescript": "^5.9.3",
71
- "vite": "^7.3.1"
60
+ "@react-three/drei": ">=10.7.7",
61
+ "@react-three/fiber": ">=9.6.0",
62
+ "@types/react": ">=19.2.9",
63
+ "@types/react-dom": ">=19.2.3",
64
+ "@types/three": ">=0.184.0",
65
+ "concurrently": ">=9.2.1",
66
+ "crashcat": ">=0.0.4",
67
+ "react": ">=19.2.5",
68
+ "react-dom": ">=19.2.5",
69
+ "three": ">=0.184.0",
70
+ "typescript": ">=6.0.3",
71
+ "vite": ">=8.0.10"
72
72
  },
73
73
  "dependencies": {
74
74
  "zustand": "^5.0.12"