@needle-tools/engine 3.4.0-alpha → 3.5.0-alpha
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/CHANGELOG.md +9 -0
- package/dist/needle-engine.js +59357 -59090
- package/dist/needle-engine.min.js +368 -345
- package/dist/needle-engine.umd.cjs +386 -363
- package/lib/engine/api.d.ts +1 -0
- package/lib/engine/api.js +1 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/engine_context.d.ts +1 -1
- package/lib/engine/engine_context.js +21 -15
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_context_registry.d.ts +5 -3
- package/lib/engine/engine_context_registry.js +10 -2
- package/lib/engine/engine_context_registry.js.map +1 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.js +2 -3
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_input.d.ts +2 -2
- package/lib/engine/engine_physics.d.ts +20 -93
- package/lib/engine/engine_physics.js +20 -892
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_physics.types.js.map +1 -1
- package/lib/engine/engine_physics_rapier.d.ts +103 -0
- package/lib/engine/engine_physics_rapier.js +1003 -0
- package/lib/engine/engine_physics_rapier.js.map +1 -0
- package/lib/engine/engine_types.d.ts +50 -1
- package/lib/engine/engine_types.js +8 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine-components/Collider.js +6 -6
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Joints.js +2 -2
- package/lib/engine-components/Joints.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +0 -1
- package/lib/engine-components/RigidBody.js +24 -30
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +55 -27
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +8 -2
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +44 -7
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
- package/lib/engine-components/ui/RectTransform.js +3 -1
- package/lib/engine-components/ui/RectTransform.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/plugins/vite/config.js +2 -1
- package/plugins/vite/defines.js +30 -0
- package/plugins/vite/dependency-watcher.js +173 -0
- package/plugins/vite/editor-connection.js +37 -39
- package/plugins/vite/index.js +5 -1
- package/plugins/vite/reload.js +3 -1
- package/src/engine/api.ts +1 -0
- package/src/engine/codegen/register_types.js +2 -2
- package/src/engine/engine_context.ts +32 -23
- package/src/engine/engine_context_registry.ts +13 -6
- package/src/engine/engine_element.ts +2 -1
- package/src/engine/engine_element_loading.ts +2 -3
- package/src/engine/engine_input.ts +2 -2
- package/src/engine/engine_physics.ts +25 -1020
- package/src/engine/engine_physics.types.ts +1 -3
- package/src/engine/engine_physics_rapier.ts +1127 -0
- package/src/engine/engine_types.ts +66 -4
- package/src/engine-components/Collider.ts +6 -6
- package/src/engine-components/Joints.ts +2 -2
- package/src/engine-components/RigidBody.ts +24 -31
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +62 -30
- package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +51 -9
- package/src/engine-components/ui/RectTransform.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/engine",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0-alpha",
|
|
4
4
|
"description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in",
|
|
5
5
|
"main": "dist/needle-engine.umd.cjs",
|
|
6
6
|
"type": "module",
|
package/plugins/vite/config.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { loadConfig } from "./config.js";
|
|
2
|
+
|
|
3
|
+
/** used to pass config variables into vite.config.define
|
|
4
|
+
* for example "useRapier"
|
|
5
|
+
*/
|
|
6
|
+
export const needleDefines = (command, config, userSettings) => {
|
|
7
|
+
|
|
8
|
+
if (!userSettings) userSettings = {};
|
|
9
|
+
|
|
10
|
+
let useRapier = true;
|
|
11
|
+
if (config.useRapier === false || userSettings?.useRapier === false) useRapier = false;
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
name: 'needle-defines',
|
|
15
|
+
enforce: 'pre',
|
|
16
|
+
config(config) {
|
|
17
|
+
if (useRapier && userSettings?.useRapier !== true) {
|
|
18
|
+
const meta = loadConfig();
|
|
19
|
+
if (meta?.useRapier === false) {
|
|
20
|
+
useRapier = false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
console.log("UseRapier?", useRapier);
|
|
24
|
+
if (!config.define) config.define = {};
|
|
25
|
+
if (config.define.NEEDLE_USE_RAPIER === undefined) {
|
|
26
|
+
config.define.NEEDLE_USE_RAPIER = useRapier;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { exec, execSync } from 'child_process';
|
|
2
|
+
import { existsSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
|
|
6
|
+
const prefix = "[needle-dependency-watcher] ";
|
|
7
|
+
function log(...msg) {
|
|
8
|
+
console.log(prefix, ...msg)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const needleDependencyWatcher = (command, config, userSettings) => {
|
|
12
|
+
if (command === "build") return;
|
|
13
|
+
|
|
14
|
+
if (userSettings?.noDependencyWatcher === true) return;
|
|
15
|
+
|
|
16
|
+
const dir = process.cwd();
|
|
17
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
18
|
+
const viteCacheDir = path.join(dir, "node_modules", ".vite");
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
name: 'needle-dependency-watcher',
|
|
22
|
+
configureServer(server) {
|
|
23
|
+
watchPackageJson(server, dir, packageJsonPath, viteCacheDir);
|
|
24
|
+
manageClients(server);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const currentClients = new Set();
|
|
30
|
+
|
|
31
|
+
function manageClients(server) {
|
|
32
|
+
server.ws.on("connection", (socket) => {
|
|
33
|
+
currentClients.add(socket);
|
|
34
|
+
socket.on("close", () => {
|
|
35
|
+
currentClients.delete(socket);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function triggerReloadOnClients() {
|
|
41
|
+
log("Triggering reload on clients (todo)", currentClients.size)
|
|
42
|
+
// for (const client of currentClients) {
|
|
43
|
+
// client.send(JSON.stringify({ type: "full-reload" }));
|
|
44
|
+
// }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
let packageJsonStat;
|
|
49
|
+
let lastEditTime;
|
|
50
|
+
let packageJsonSize;
|
|
51
|
+
let packageJson;
|
|
52
|
+
let requireInstall = false;
|
|
53
|
+
|
|
54
|
+
function watchPackageJson(server, projectDir, packageJsonPath, cachePath) {
|
|
55
|
+
|
|
56
|
+
if (!existsSync(packageJsonPath)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
log("Watching project", packageJsonPath)
|
|
61
|
+
|
|
62
|
+
lastRestartTime = 0;
|
|
63
|
+
packageJsonStat = statSync(packageJsonPath);
|
|
64
|
+
lastEditTime = packageJsonStat.mtime;
|
|
65
|
+
packageJsonSize = packageJsonStat.size;
|
|
66
|
+
packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
67
|
+
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
requireInstall = testIfInstallIsRequired(projectDir, packageJson);
|
|
70
|
+
}, 1000);
|
|
71
|
+
|
|
72
|
+
setInterval(() => {
|
|
73
|
+
packageJsonStat = statSync(packageJsonPath);
|
|
74
|
+
let modified = false;
|
|
75
|
+
if (packageJsonStat.mtime > lastEditTime) {
|
|
76
|
+
modified = true;
|
|
77
|
+
}
|
|
78
|
+
if (packageJsonStat.size !== packageJsonSize) {
|
|
79
|
+
modified = true;
|
|
80
|
+
}
|
|
81
|
+
if (modified || requireInstall) {
|
|
82
|
+
if (modified)
|
|
83
|
+
log("package.json has changed")
|
|
84
|
+
|
|
85
|
+
let requireReload = false;
|
|
86
|
+
if (!requireInstall) {
|
|
87
|
+
requireInstall = testIfInstallIsRequired(projectDir, packageJson);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// test if dependencies changed
|
|
91
|
+
let newPackageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
92
|
+
for (const key in newPackageJson.dependencies) {
|
|
93
|
+
if (packageJson.dependencies[key] !== newPackageJson.dependencies[key] && newPackageJson.dependencies[key] !== undefined) {
|
|
94
|
+
log("Dependency added", key)
|
|
95
|
+
requireReload = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
packageJsonSize = packageJsonStat.size;
|
|
101
|
+
lastEditTime = packageJsonStat.mtime;
|
|
102
|
+
|
|
103
|
+
if (requireReload || requireInstall) {
|
|
104
|
+
restart(server, projectDir, cachePath);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, 1000);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function testIfInstallIsRequired(projectDir, packageJson) {
|
|
111
|
+
|
|
112
|
+
if (packageJson.dependencies) {
|
|
113
|
+
for (const key in packageJson.dependencies) {
|
|
114
|
+
// make sure the dependency is installed
|
|
115
|
+
const depPath = path.join(projectDir, "node_modules", key);
|
|
116
|
+
if (!existsSync(depPath)) {
|
|
117
|
+
log("Dependency not installed", key)
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let isRunningRestart = false;
|
|
126
|
+
let restartId = 0;
|
|
127
|
+
let lastRestartTime = 0;
|
|
128
|
+
|
|
129
|
+
async function restart(server, projectDir, cachePath) {
|
|
130
|
+
|
|
131
|
+
if (isRunningRestart) return;
|
|
132
|
+
isRunningRestart = true;
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const id = ++restartId;
|
|
136
|
+
|
|
137
|
+
if (requireInstall) {
|
|
138
|
+
requireInstall = false;
|
|
139
|
+
log("Installing dependencies...")
|
|
140
|
+
execSync("npm install", { cwd: projectDir, stdio: "inherit" });
|
|
141
|
+
requireInstall = false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (id !== restartId) return;
|
|
145
|
+
if (Date.now() - lastRestartTime < 1000) return;
|
|
146
|
+
log("Restarting server...")
|
|
147
|
+
lastRestartTime = Date.now();
|
|
148
|
+
requireInstall = false;
|
|
149
|
+
if (existsSync(cachePath))
|
|
150
|
+
rmSync(cachePath, { recursive: true, force: true });
|
|
151
|
+
triggerReloadOnClients();
|
|
152
|
+
|
|
153
|
+
// touch vite config to trigger reload
|
|
154
|
+
// const viteConfigPath = path.join(projectDir, "vite.config.js");
|
|
155
|
+
// if (existsSync(viteConfigPath)) {
|
|
156
|
+
// const content = readFileSync(viteConfigPath, "utf8");
|
|
157
|
+
// writeFileSync(viteConfigPath, content, "utf8");
|
|
158
|
+
// isRunningRestart = false;
|
|
159
|
+
// return;
|
|
160
|
+
// }
|
|
161
|
+
|
|
162
|
+
// check if server is running
|
|
163
|
+
if (server.httpServer.listening)
|
|
164
|
+
server.restart();
|
|
165
|
+
isRunningRestart = false;
|
|
166
|
+
console.log("-----------------------------------------------")
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
log("Error restarting server", err);
|
|
170
|
+
isRunningRestart = false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
}
|
|
@@ -73,48 +73,46 @@ function createPlugin(isInstalled) {
|
|
|
73
73
|
},
|
|
74
74
|
|
|
75
75
|
configureServer(server) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
try
|
|
77
|
+
{
|
|
78
|
+
server.ws.on('connection', (socket, _request) => {
|
|
79
|
+
|
|
80
|
+
// console.log("Send editor sync status: " + isInstalled);
|
|
81
|
+
const reply = {
|
|
82
|
+
type: "needle:editor-sync:installation-status",
|
|
83
|
+
data: isInstalled
|
|
84
|
+
}
|
|
85
|
+
socket.send(JSON.stringify(reply));
|
|
86
|
+
|
|
87
|
+
socket.on('message', async (bytes) => {
|
|
88
|
+
if (bytes?.length < 50) {
|
|
89
|
+
const message = Buffer.from(bytes).toString();
|
|
90
|
+
if (message === "needle:editor:restart") {
|
|
91
|
+
console.log("Received request for a soft restart of the vite server... ")
|
|
91
92
|
// This just restarts the vite server
|
|
92
93
|
server.restart();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
94
|
+
}
|
|
95
|
+
else if (message === "needle:editor:stop") {
|
|
96
|
+
process.exit();
|
|
97
|
+
}
|
|
98
|
+
else if (message === `{"type":"ping"}`) {
|
|
99
|
+
socket.send(JSON.stringify({ type: "pong" }));
|
|
100
|
+
}
|
|
101
|
+
else if (message === "needle:editor:editor-sync-enabled") {
|
|
102
|
+
console.log("Editor sync enabled")
|
|
103
|
+
editorSyncEnabled = true;
|
|
104
|
+
}
|
|
105
|
+
else if (message === "needle:editor:editor-sync-disabled") {
|
|
106
|
+
editorSyncEnabled = false;
|
|
107
|
+
}
|
|
107
108
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
});
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch(err){
|
|
113
|
+
console.error("Error in needle-editor-connection")
|
|
114
|
+
console.error(err)
|
|
115
|
+
}
|
|
118
116
|
}
|
|
119
117
|
|
|
120
118
|
}
|
package/plugins/vite/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { needleDefines } from "./defines.js";
|
|
1
2
|
import { needleBuild } from "./build.js";
|
|
2
3
|
import { needleMeta } from "./meta.js"
|
|
3
4
|
import { needlePoster } from "./poster.js"
|
|
@@ -9,6 +10,7 @@ import { needleViteAlias } from "./alias.js";
|
|
|
9
10
|
import { needleTransformCodegen } from "./transform-codegen.js";
|
|
10
11
|
import { needleLicense } from "./license.js";
|
|
11
12
|
import { needlePeerjs } from "./peer.js";
|
|
13
|
+
import { needleDependencyWatcher } from "./dependency-watcher.js";
|
|
12
14
|
|
|
13
15
|
export * from "./gzip.js";
|
|
14
16
|
export * from "./config.js";
|
|
@@ -22,6 +24,7 @@ export const needlePlugins = async (command, config, userSettings) => {
|
|
|
22
24
|
// ensure we have user settings initialized with defaults
|
|
23
25
|
userSettings = { ...defaultUserSettings, ...userSettings }
|
|
24
26
|
const array = [
|
|
27
|
+
needleDefines(command, config, userSettings),
|
|
25
28
|
needleLicense(command, config, userSettings),
|
|
26
29
|
needleViteAlias(command, config, userSettings),
|
|
27
30
|
needleMeta(command, config, userSettings),
|
|
@@ -31,7 +34,8 @@ export const needlePlugins = async (command, config, userSettings) => {
|
|
|
31
34
|
needleCopyFiles(command, config, userSettings),
|
|
32
35
|
needleTransformCodegen(command, config, userSettings),
|
|
33
36
|
needleDrop(command, config, userSettings),
|
|
34
|
-
needlePeerjs(command, config, userSettings)
|
|
37
|
+
needlePeerjs(command, config, userSettings),
|
|
38
|
+
needleDependencyWatcher(command, config, userSettings)
|
|
35
39
|
];
|
|
36
40
|
array.push(await editorConnection(command, config, userSettings, array));
|
|
37
41
|
return array;
|
package/plugins/vite/reload.js
CHANGED
|
@@ -14,6 +14,8 @@ let assetsDirectory = "";
|
|
|
14
14
|
export const needleReload = (command, config, userSettings) => {
|
|
15
15
|
if (command === "build") return;
|
|
16
16
|
|
|
17
|
+
if (userSettings?.noReload === true) return;
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
let isUpdatingConfig = false;
|
|
19
21
|
const updateConfig = async () => {
|
|
@@ -45,7 +47,7 @@ export const needleReload = (command, config, userSettings) => {
|
|
|
45
47
|
else if (!config.server.watch.ignored) config.server.watch.ignored = [];
|
|
46
48
|
for (const pattern of ignorePatterns)
|
|
47
49
|
config.server.watch.ignored.push(pattern);
|
|
48
|
-
if(config?.debug === true || userSettings?.debug === true)
|
|
50
|
+
if (config?.debug === true || userSettings?.debug === true)
|
|
49
51
|
setTimeout(() => console.log("Updated server ignore patterns: ", config.server.watch.ignored), 100);
|
|
50
52
|
},
|
|
51
53
|
handleHotUpdate(args) {
|
package/src/engine/api.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from "./engine_patcher"
|
|
|
27
27
|
export * from "./engine_playerview"
|
|
28
28
|
export * from "./engine_physics"
|
|
29
29
|
export * from "./engine_physics.types"
|
|
30
|
+
export * from "./engine_physics_rapier"
|
|
30
31
|
export * from "./engine_scenelighting"
|
|
31
32
|
export * from "./engine_input";
|
|
32
33
|
export * from "./engine_math";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypeStore } from "./../engine_typestore"
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
// Import types
|
|
4
4
|
import { __Ignore } from "../../engine-components/codegen/components";
|
|
5
5
|
import { ActionBuilder } from "../../engine-components/export/usdz/extensions/behavior/BehavioursBuilder";
|
|
@@ -214,7 +214,7 @@ import { XRGrabModel } from "../../engine-components/webxr/WebXRGrabRendering";
|
|
|
214
214
|
import { XRGrabRendering } from "../../engine-components/webxr/WebXRGrabRendering";
|
|
215
215
|
import { XRRig } from "../../engine-components/webxr/WebXRRig";
|
|
216
216
|
import { XRState } from "../../engine-components/XRFlag";
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
// Register types
|
|
219
219
|
TypeStore.add("__Ignore", __Ignore);
|
|
220
220
|
TypeStore.add("ActionBuilder", ActionBuilder);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
BufferGeometry, Camera, Clock, Color, DepthTexture, Group,
|
|
3
|
+
Material, NearestFilter, NoToneMapping, Object3D, PCFSoftShadowMap,
|
|
4
|
+
PerspectiveCamera, RGBAFormat, Scene, sRGBEncoding,
|
|
5
|
+
Texture, WebGLRenderer, WebGLRenderTarget
|
|
5
6
|
} from 'three'
|
|
6
7
|
import { Input } from './engine_input';
|
|
7
8
|
import { Physics } from './engine_physics';
|
|
@@ -27,6 +28,7 @@ import { PlayerViewManager } from './engine_playerview';
|
|
|
27
28
|
import { CoroutineData, ICamera, IComponent, IContext, ILight } from "./engine_types"
|
|
28
29
|
import { destroy, foreachComponent } from './engine_gameobject';
|
|
29
30
|
import { ContextEvent, ContextRegistry } from './engine_context_registry';
|
|
31
|
+
import { delay } from './engine_utils';
|
|
30
32
|
// import { createCameraWithOrbitControl } from '../engine-components/CameraUtils';
|
|
31
33
|
|
|
32
34
|
|
|
@@ -251,8 +253,8 @@ export class Context implements IContext {
|
|
|
251
253
|
this.isManagedExternally = true;
|
|
252
254
|
}
|
|
253
255
|
else {
|
|
254
|
-
this.renderer = new WebGLRenderer({
|
|
255
|
-
antialias: true
|
|
256
|
+
this.renderer = new WebGLRenderer({
|
|
257
|
+
antialias: true
|
|
256
258
|
});
|
|
257
259
|
|
|
258
260
|
// some tonemapping other than "NONE" is required for adjusting exposure with EXR environments
|
|
@@ -346,12 +348,13 @@ export class Context implements IContext {
|
|
|
346
348
|
camera.updateProjectionMatrix();
|
|
347
349
|
}
|
|
348
350
|
|
|
349
|
-
onCreate(buildScene?: (context: Context, loadingOptions?: LoadingOptions) => Promise<void>, opts?: LoadingOptions) {
|
|
351
|
+
async onCreate(buildScene?: (context: Context, loadingOptions?: LoadingOptions) => Promise<void>, opts?: LoadingOptions) {
|
|
350
352
|
if (this._isCreated) {
|
|
351
353
|
console.warn("Context already created");
|
|
352
354
|
return null;
|
|
353
355
|
}
|
|
354
356
|
this._isCreated = true;
|
|
357
|
+
await delay(1);
|
|
355
358
|
return this.internalOnCreate(buildScene, opts);
|
|
356
359
|
}
|
|
357
360
|
|
|
@@ -498,8 +501,8 @@ export class Context implements IContext {
|
|
|
498
501
|
|
|
499
502
|
private async internalOnCreate(buildScene?: (context: Context, opts?: LoadingOptions) => Promise<void>, opts?: LoadingOptions) {
|
|
500
503
|
|
|
501
|
-
|
|
502
|
-
await
|
|
504
|
+
Context.Current = this;
|
|
505
|
+
await ContextRegistry.dispatchCallback(ContextEvent.ContextCreationStart, this);
|
|
503
506
|
|
|
504
507
|
// load and create scene
|
|
505
508
|
let prepare_succeeded = true;
|
|
@@ -512,7 +515,7 @@ export class Context implements IContext {
|
|
|
512
515
|
console.error(err);
|
|
513
516
|
prepare_succeeded = false;
|
|
514
517
|
}
|
|
515
|
-
if (!prepare_succeeded) return;
|
|
518
|
+
if (!prepare_succeeded) return false;
|
|
516
519
|
|
|
517
520
|
this.internalOnUpdateVisible();
|
|
518
521
|
|
|
@@ -523,6 +526,9 @@ export class Context implements IContext {
|
|
|
523
526
|
|
|
524
527
|
Context.Current = this;
|
|
525
528
|
|
|
529
|
+
// TODO: we could configure if we need physics
|
|
530
|
+
// await this.physics.engine?.initialize();
|
|
531
|
+
|
|
526
532
|
// Setup
|
|
527
533
|
Context.Current = this;
|
|
528
534
|
for (let i = 0; i < this.new_scripts.length; i++) {
|
|
@@ -609,13 +615,13 @@ export class Context implements IContext {
|
|
|
609
615
|
if (debug)
|
|
610
616
|
logHierarchy(this.scene, true);
|
|
611
617
|
|
|
612
|
-
ContextRegistry.dispatchCallback(ContextEvent.ContextCreated, this);
|
|
618
|
+
return ContextRegistry.dispatchCallback(ContextEvent.ContextCreated, this);
|
|
613
619
|
}
|
|
614
620
|
|
|
615
621
|
private _accumulatedTime = 0;
|
|
616
622
|
private _framerateClock = new Clock();
|
|
617
623
|
|
|
618
|
-
private render(_, frame
|
|
624
|
+
private render(_, frame: XRFrame) {
|
|
619
625
|
this._xrFrame = frame;
|
|
620
626
|
|
|
621
627
|
this._currentFrameEvent = FrameEvent.Undefined;
|
|
@@ -627,7 +633,7 @@ export class Context implements IContext {
|
|
|
627
633
|
}
|
|
628
634
|
this._accumulatedTime = 0;
|
|
629
635
|
}
|
|
630
|
-
|
|
636
|
+
|
|
631
637
|
this._stats?.begin();
|
|
632
638
|
|
|
633
639
|
Context.Current = this;
|
|
@@ -696,16 +702,19 @@ export class Context implements IContext {
|
|
|
696
702
|
this.executeCoroutines(FrameEvent.LateUpdate);
|
|
697
703
|
if (this.onHandlePaused()) return;
|
|
698
704
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
705
|
+
if (this.physics.engine) {
|
|
706
|
+
const physicsSteps = 1;
|
|
707
|
+
const dt = this.time.deltaTime / physicsSteps;
|
|
708
|
+
for (let i = 0; i < physicsSteps; i++) {
|
|
709
|
+
this._currentFrameEvent = FrameEvent.PrePhysicsStep;
|
|
710
|
+
this.executeCoroutines(FrameEvent.PrePhysicsStep);
|
|
711
|
+
this.physics.engine.step(dt);
|
|
712
|
+
this._currentFrameEvent = FrameEvent.PostPhysicsStep;
|
|
713
|
+
this.executeCoroutines(FrameEvent.PostPhysicsStep);
|
|
714
|
+
}
|
|
715
|
+
this.physics.engine.postStep();
|
|
707
716
|
}
|
|
708
|
-
|
|
717
|
+
|
|
709
718
|
if (this.onHandlePaused()) return;
|
|
710
719
|
|
|
711
720
|
if (this.isVisibleToUser) {
|
|
@@ -781,7 +790,7 @@ export class Context implements IContext {
|
|
|
781
790
|
this.renderRequiredTextures();
|
|
782
791
|
// if (camera === this.mainCameraComponent?.cam) {
|
|
783
792
|
// if (this.mainCameraComponent.activeTexture) {
|
|
784
|
-
|
|
793
|
+
|
|
785
794
|
// }
|
|
786
795
|
// }
|
|
787
796
|
if (this.composer && !this.isInXR) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { IContext } from "./engine_types";
|
|
1
|
+
import { IComponent, IContext } from "./engine_types";
|
|
2
2
|
|
|
3
3
|
export enum ContextEvent {
|
|
4
4
|
/** called when the context is registered to the registry, the context is not fully initialized at this point */
|
|
5
5
|
ContextRegistered = "ContextRegistered",
|
|
6
|
+
/** called before the first glb is loaded, can be used to initialize physics engine, is awaited */
|
|
7
|
+
ContextCreationStart = "ContextCreationStart",
|
|
6
8
|
ContextCreated = "ContextCreated",
|
|
7
9
|
ContextDestroyed = "ContextDestroyed",
|
|
8
10
|
MissingCamera = "MissingCamera",
|
|
@@ -13,11 +15,11 @@ export type ContextEventArgs = {
|
|
|
13
15
|
context: IContext;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
export type ContextCallback = (evt: ContextEventArgs) => void;
|
|
18
|
+
export type ContextCallback = (evt: ContextEventArgs) => void | Promise<any> | IComponent;
|
|
17
19
|
|
|
18
20
|
export class ContextRegistry {
|
|
19
21
|
|
|
20
|
-
static get Current(): IContext{
|
|
22
|
+
static get Current(): IContext {
|
|
21
23
|
return globalThis["NeedleEngine.Context.Current"]
|
|
22
24
|
}
|
|
23
25
|
static set Current(ctx: IContext) {
|
|
@@ -51,10 +53,15 @@ export class ContextRegistry {
|
|
|
51
53
|
this._callbacks[evt].splice(index, 1);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
static dispatchCallback(evt: ContextEvent, context:IContext) {
|
|
55
|
-
if (!this._callbacks[evt]) return;
|
|
56
|
+
static dispatchCallback(evt: ContextEvent, context: IContext) {
|
|
57
|
+
if (!this._callbacks[evt]) return true;
|
|
56
58
|
const args = { event: evt, context }
|
|
57
|
-
|
|
59
|
+
const promises = new Array<Promise<any>>();
|
|
60
|
+
this._callbacks[evt].forEach(cb => {
|
|
61
|
+
const res = cb(args)
|
|
62
|
+
if (res instanceof Promise) promises.push(res);
|
|
63
|
+
});
|
|
64
|
+
return Promise.all(promises);
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
static addContextCreatedCallback(callback: ContextCallback) {
|
|
@@ -164,6 +164,7 @@ export class NeedleEngineHTMLElement extends HTMLElement implements INeedleEngin
|
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
|
|
167
168
|
this._previousSrc = src;
|
|
168
169
|
|
|
169
170
|
// Set the source attribute so codegen doesnt try to re-assign it again and we communicate to the outside which root files are being loaded
|
|
@@ -221,7 +222,7 @@ export class NeedleEngineHTMLElement extends HTMLElement implements INeedleEngin
|
|
|
221
222
|
if (!url.includes(".glb") && !url.includes(".gltf")) {
|
|
222
223
|
const warning = `Needle Engine: found suspicious src "${url}"`;
|
|
223
224
|
console.warn(warning);
|
|
224
|
-
if(isLocalNetwork()) showBalloonWarning(warning);
|
|
225
|
+
if (isLocalNetwork()) showBalloonWarning(warning);
|
|
225
226
|
}
|
|
226
227
|
const fileName = getNameFromUrl(url);
|
|
227
228
|
const progress: LoadingProgressArgs = {
|
|
@@ -73,7 +73,7 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
onLoadingBegin(message?: string) {
|
|
76
|
-
if (debug) console.
|
|
76
|
+
if (debug) console.warn("Begin Loading")
|
|
77
77
|
if (!this._loadingElement) {
|
|
78
78
|
for (let i = 0; i < this._element.children.length; i++) {
|
|
79
79
|
const el = this._element.children[i] as HTMLElement;
|
|
@@ -98,9 +98,8 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
onLoadingUpdate(progress: LoadingProgressArgs | ProgressEvent | number, message?: string) {
|
|
101
|
-
// if the element has no parent we want to add it
|
|
102
101
|
if (!this._loadingElement?.parentElement) {
|
|
103
|
-
|
|
102
|
+
return;
|
|
104
103
|
}
|
|
105
104
|
// console.log(callback.name, callback.progress.loaded / callback.progress.total, callback.index + "/" + callback.count);
|
|
106
105
|
let total01 = 0;
|
|
@@ -2,7 +2,7 @@ import { Vector2 } from 'three';
|
|
|
2
2
|
import { showBalloonMessage, showBalloonWarning } from './debug/debug';
|
|
3
3
|
import { assign } from './engine_serialization_core';
|
|
4
4
|
import { Context } from './engine_setup';
|
|
5
|
-
import { Vec2 } from './engine_types';
|
|
5
|
+
import { IInput, Vec2 } from './engine_types';
|
|
6
6
|
import { getParam } from './engine_utils';
|
|
7
7
|
|
|
8
8
|
const debug = getParam("debuginput");
|
|
@@ -52,7 +52,7 @@ export enum PointerType {
|
|
|
52
52
|
// }
|
|
53
53
|
// }
|
|
54
54
|
|
|
55
|
-
export class Input extends EventTarget {
|
|
55
|
+
export class Input extends EventTarget implements IInput {
|
|
56
56
|
|
|
57
57
|
_doubleClickTimeThreshold = .2;
|
|
58
58
|
_longPressTimeThreshold = 1;
|