@needle-tools/engine 4.7.0-next.968391f → 4.7.0-next.bbbc637
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/dist/{needle-engine.bundle-W3V0IktP.js → needle-engine.bundle-BOMrdPF_.js} +15 -15
- package/dist/{needle-engine.bundle-4ZErY29T.umd.cjs → needle-engine.bundle-Bb7oB8Qy.umd.cjs} +5 -5
- package/dist/{needle-engine.bundle-DtrPbYYj.min.js → needle-engine.bundle-rzZz_U5k.min.js} +5 -5
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_context.js +1 -1
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_three_utils.js +4 -0
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.attributes.d.ts +1 -1
- package/lib/engine-components/Camera.js +1 -1
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CameraUtils.js +5 -3
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/Skybox.js +4 -4
- package/lib/engine-components/Skybox.js.map +1 -1
- package/package.json +1 -1
- package/plugins/common/logger.js +213 -0
- package/plugins/types/userconfig.d.ts +1 -1
- package/plugins/vite/imports-logger.js +1 -1
- package/plugins/vite/index.js +2 -0
- package/plugins/vite/logger.client.js +149 -0
- package/plugins/vite/logger.js +85 -0
- package/src/engine/engine_context.ts +1 -1
- package/src/engine/engine_three_utils.ts +3 -0
- package/src/engine/webcomponents/needle-engine.attributes.ts +1 -1
- package/src/engine-components/Camera.ts +1 -1
- package/src/engine-components/CameraUtils.ts +5 -3
- package/src/engine-components/Skybox.ts +5 -5
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Patches console methods to capture log messages and send them to the server.
|
|
4
|
+
* This is useful for debugging and logging in the client.
|
|
5
|
+
* @param {"log" | "warn" | "info" | "debug" | "error" | "internal"} level
|
|
6
|
+
* @param {any} message - The log message to capture.
|
|
7
|
+
*/
|
|
8
|
+
function sendLogToServer(level, ...message) {
|
|
9
|
+
if ("hot" in import.meta) {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import.meta.hot.send("needle:client-log", { level, message: message });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if (import.meta && "hot" in import.meta) {
|
|
17
|
+
|
|
18
|
+
const originalLog = console.log;
|
|
19
|
+
const originalWarn = console.warn;
|
|
20
|
+
const originalInfo = console.info;
|
|
21
|
+
const originalDebug = console.debug;
|
|
22
|
+
const originalError = console.error;
|
|
23
|
+
|
|
24
|
+
console.log = (...args) => {
|
|
25
|
+
originalLog(...args);
|
|
26
|
+
sendLogToServer("log", ...args);
|
|
27
|
+
}
|
|
28
|
+
console.warn = (...args) => {
|
|
29
|
+
originalWarn(...args);
|
|
30
|
+
sendLogToServer("warn", ...args);
|
|
31
|
+
}
|
|
32
|
+
console.info = (...args) => {
|
|
33
|
+
originalInfo(...args);
|
|
34
|
+
sendLogToServer("info", ...args);
|
|
35
|
+
}
|
|
36
|
+
console.debug = (...args) => {
|
|
37
|
+
originalDebug(...args);
|
|
38
|
+
sendLogToServer("debug", ...args);
|
|
39
|
+
}
|
|
40
|
+
console.error = (...args) => {
|
|
41
|
+
originalError(...args);
|
|
42
|
+
sendLogToServer("error", ...args);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
sendLogToServer("internal", `Page loaded
|
|
47
|
+
URL: ${window.location.href}
|
|
48
|
+
UserAgent: ${navigator.userAgent}
|
|
49
|
+
Screen: ${window.innerWidth} x ${window.innerHeight}px
|
|
50
|
+
Device Pixel Ratio: ${window.devicePixelRatio}
|
|
51
|
+
Device Memory: ${"deviceMemory" in navigator ? navigator.deviceMemory : "Not available"} GB
|
|
52
|
+
Online: ${navigator.onLine}
|
|
53
|
+
Language: ${navigator.language}
|
|
54
|
+
Timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}
|
|
55
|
+
Connection: ${"connection" in navigator ? JSON.stringify(navigator.connection) : "Not available"}
|
|
56
|
+
User Activation: ${"userActivation" in navigator ? JSON.stringify(navigator.userActivation) : "Not available"}
|
|
57
|
+
`);
|
|
58
|
+
|
|
59
|
+
if ("gpu" in navigator) {
|
|
60
|
+
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
navigator.gpu.requestAdapter()
|
|
63
|
+
.then(adapter => adapter ? adapter.requestDevice() : null)
|
|
64
|
+
.then(device => {
|
|
65
|
+
if (device) {
|
|
66
|
+
const adapterInfo = device.adapterInfo;
|
|
67
|
+
if (adapterInfo) {
|
|
68
|
+
sendLogToServer("internal", [`WebGPU adapter info`,
|
|
69
|
+
[adapterInfo.vendor, adapterInfo.architecture, adapterInfo.device]
|
|
70
|
+
.filter(e => e.trim()?.length)
|
|
71
|
+
.join(", ")
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
// silently fail
|
|
80
|
+
sendLogToServer("error", `Error during initial log: ${e.message}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
window.addEventListener('error', (event) => {
|
|
84
|
+
const errorMessage = event.error ? event.error.stack || event.error.message : event.message;
|
|
85
|
+
sendLogToServer("error", errorMessage);
|
|
86
|
+
});
|
|
87
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
88
|
+
const reason = event.reason ? event.reason.stack || event.reason.message : "Unhandled rejection without reason";
|
|
89
|
+
sendLogToServer("error", `Unhandled promise rejection: ${reason}`);
|
|
90
|
+
});
|
|
91
|
+
window.addEventListener('beforeunload', () => {
|
|
92
|
+
sendLogToServer("internal", "Page is unloading");
|
|
93
|
+
});
|
|
94
|
+
document.addEventListener('visibilitychange', () => {
|
|
95
|
+
console.log("Visibility changed:", document.visibilityState);
|
|
96
|
+
if (document.visibilityState === 'hidden') {
|
|
97
|
+
sendLogToServer("internal", "Page is hidden");
|
|
98
|
+
}
|
|
99
|
+
else if (document.visibilityState === 'visible') {
|
|
100
|
+
sendLogToServer("internal", "Page is visible again");
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
sendLogToServer("internal", `Page visibility changed to ${document.visibilityState}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
window.addEventListener("focus", () => {
|
|
107
|
+
sendLogToServer("internal", "Page gained focus");
|
|
108
|
+
});
|
|
109
|
+
window.addEventListener("blur", () => {
|
|
110
|
+
sendLogToServer("internal", "Page lost focus");
|
|
111
|
+
});
|
|
112
|
+
window.addEventListener('load', () => {
|
|
113
|
+
sendLogToServer("internal", "Page fully loaded");
|
|
114
|
+
});
|
|
115
|
+
window.addEventListener('DOMContentLoaded', () => {
|
|
116
|
+
sendLogToServer("internal", "DOM fully loaded and parsed");
|
|
117
|
+
});
|
|
118
|
+
window.addEventListener('online', () => {
|
|
119
|
+
sendLogToServer("internal", "Browser is online");
|
|
120
|
+
});
|
|
121
|
+
window.addEventListener('offline', () => {
|
|
122
|
+
sendLogToServer("warn", "Browser is offline");
|
|
123
|
+
});
|
|
124
|
+
window.addEventListener('resize', () => {
|
|
125
|
+
sendLogToServer("internal", `Window resized to ${window.innerWidth}x${window.innerHeight}px`);
|
|
126
|
+
});
|
|
127
|
+
window.addEventListener('orientationchange', () => {
|
|
128
|
+
sendLogToServer("internal", `Orientation changed to ${screen.orientation.type}`);
|
|
129
|
+
});
|
|
130
|
+
window.addEventListener('fullscreenchange', () => {
|
|
131
|
+
if (document.fullscreenElement) {
|
|
132
|
+
sendLogToServer("internal", "Entered fullscreen mode");
|
|
133
|
+
} else {
|
|
134
|
+
sendLogToServer("internal", "Exited fullscreen mode");
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// url change event
|
|
140
|
+
window.addEventListener('hashchange', () => {
|
|
141
|
+
sendLogToServer("internal", `URL hash changed to ${location.hash}`);
|
|
142
|
+
});
|
|
143
|
+
window.addEventListener('popstate', () => {
|
|
144
|
+
sendLogToServer("internal", `History state changed: ${JSON.stringify(history.state)}`);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { captureLogMessage, patchConsoleLogs } from '../common/logger.js';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* write logs to local file
|
|
12
|
+
* @param {import('../types/userconfig.js').userSettings} userSettings
|
|
13
|
+
* @returns {import('vite').Plugin}
|
|
14
|
+
*/
|
|
15
|
+
export const needleLogger = (command, config, userSettings) => {
|
|
16
|
+
|
|
17
|
+
patchConsoleLogs();
|
|
18
|
+
captureLogMessage("server", "info", "Vite started with command \"" + command + "\" in " + __dirname);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
name: "needle:logger",
|
|
22
|
+
enforce: 'pre',
|
|
23
|
+
configureServer(server) {
|
|
24
|
+
logRequests(server);
|
|
25
|
+
},
|
|
26
|
+
configurePreviewServer(server) {
|
|
27
|
+
logRequests(server);
|
|
28
|
+
},
|
|
29
|
+
transformIndexHtml: {
|
|
30
|
+
order: 'pre',
|
|
31
|
+
handler(html, ctx) {
|
|
32
|
+
// inject client logger script during development
|
|
33
|
+
if (command === 'serve') {
|
|
34
|
+
const file = path.join(__dirname, 'logger.client.js');
|
|
35
|
+
if (existsSync(file)) {
|
|
36
|
+
const scriptContent = readFileSync(file, 'utf8');
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
tag: 'script',
|
|
40
|
+
attrs: {
|
|
41
|
+
type: 'module',
|
|
42
|
+
},
|
|
43
|
+
children: scriptContent,
|
|
44
|
+
injectTo: 'head-prepend',
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Logs HTTP requests to the console.
|
|
57
|
+
* This function is used in the Vite server to log incoming HTTP requests.
|
|
58
|
+
* @param {import('vite').PreviewServer | import('vite').ViteDevServer} server
|
|
59
|
+
*/
|
|
60
|
+
function logRequests(server, log_http_requests = false) {
|
|
61
|
+
if ("ws" in server) {
|
|
62
|
+
// Clent connections
|
|
63
|
+
server.ws.on('connection', (socket, request) => {
|
|
64
|
+
captureLogMessage("server", "connection", "New websocket connection established");
|
|
65
|
+
socket.on('close', () => {
|
|
66
|
+
captureLogMessage("server", "connection", "Websocket connection closed");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
// Client log messages via websocket
|
|
70
|
+
server.ws.on('needle:client-log', async (data, client) => {
|
|
71
|
+
if (!data || !data.level || !data.message) {
|
|
72
|
+
console.warn("Received empty log data, ignoring");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
captureLogMessage("client", data.level, data.message);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Log HTTP requests
|
|
79
|
+
if (log_http_requests) {
|
|
80
|
+
server.middlewares.use((req, res, next) => {
|
|
81
|
+
captureLogMessage("client-http", "info", [req.method, req.url]);
|
|
82
|
+
next();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -751,7 +751,7 @@ export class Context implements IContext {
|
|
|
751
751
|
ContextRegistry.dispatchCallback(ContextEvent.ContextClearing, this);
|
|
752
752
|
invokeLifecycleFunctions(this, ContextEvent.ContextClearing);
|
|
753
753
|
// NOTE: this does dispose the environment/background image too
|
|
754
|
-
// which is probably not desired if it is set via the
|
|
754
|
+
// which is probably not desired if it is set via the background-image attribute
|
|
755
755
|
destroy(this.scene, true, true);
|
|
756
756
|
this.scene = new Scene();
|
|
757
757
|
this.addressables?.dispose();
|
|
@@ -734,6 +734,9 @@ export function getBoundingBox(objects: Object3D | Object3D[], ignore: ((obj: Ob
|
|
|
734
734
|
console.warn(`Object \"${obj.name}\" has NaN values in position or scale.... will ignore it`, pos, scale);
|
|
735
735
|
return;
|
|
736
736
|
}
|
|
737
|
+
// Sanitize for the three.js method that only checks for undefined here
|
|
738
|
+
// @ts-ignore
|
|
739
|
+
if (obj.geometry === null) obj.geometry = undefined;
|
|
737
740
|
box.expandByObject(obj, true);
|
|
738
741
|
obj.children = children;
|
|
739
742
|
}
|
|
@@ -44,7 +44,7 @@ type LoadingAttributes = {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
type SkyboxAttributes = {
|
|
47
|
-
/**
|
|
47
|
+
/** @deprecated. Use background-image instead - URL to .exr, .hdr, .png, .jpg to be used as skybox */
|
|
48
48
|
"skybox-image"?: string,
|
|
49
49
|
/** URL to .exr, .hdr, .png, .jpg to be used as skybox */
|
|
50
50
|
"background-image"?: string,
|
|
@@ -560,7 +560,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
560
560
|
console.debug(msg);
|
|
561
561
|
}
|
|
562
562
|
|
|
563
|
-
const hasBackgroundImageOrColorAttribute = this.context.domElement.getAttribute("background-image") || this.context.domElement.getAttribute("background-color")
|
|
563
|
+
const hasBackgroundImageOrColorAttribute = this.context.domElement.getAttribute("background-image") || this.context.domElement.getAttribute("background-color");
|
|
564
564
|
|
|
565
565
|
switch (this._clearFlags) {
|
|
566
566
|
case ClearFlags.None:
|
|
@@ -36,12 +36,14 @@ ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
|
|
|
36
36
|
if (transparentAttribute != undefined) {
|
|
37
37
|
camInstance.clearFlags = ClearFlags.Uninitialized;
|
|
38
38
|
}
|
|
39
|
-
// Set the clearFlags to a skybox if we have one OR if the user set a
|
|
40
|
-
else if (evt.context.domElement.getAttribute("
|
|
39
|
+
// Set the clearFlags to a skybox if we have one OR if the user set a background-image attribute
|
|
40
|
+
else if (evt.context.domElement.getAttribute("background-image")?.length || (evt.context as Context).lightmaps.tryGetSkybox(camInstance.sourceId)) {
|
|
41
41
|
camInstance.clearFlags = ClearFlags.Skybox;
|
|
42
42
|
// TODO: can we store the backgroundBlurriness in the gltf file somewhere except inside the camera?
|
|
43
43
|
// e.g. when we export a scene from blender without a camera in the scene
|
|
44
|
-
|
|
44
|
+
if (evt.context.domElement.getAttribute("background-blurriness") === null) {
|
|
45
|
+
evt.context.scene.backgroundBlurriness = 0.2; // default value, same as in Blender
|
|
46
|
+
}
|
|
45
47
|
}
|
|
46
48
|
else {
|
|
47
49
|
camInstance.clearFlags = ClearFlags.SolidColor;
|
|
@@ -16,10 +16,10 @@ import { Behaviour, GameObject } from "./Component.js";
|
|
|
16
16
|
|
|
17
17
|
const debug = getParam("debugskybox");
|
|
18
18
|
|
|
19
|
-
registerObservableAttribute("
|
|
19
|
+
registerObservableAttribute("background-image");
|
|
20
20
|
registerObservableAttribute("environment-image");
|
|
21
21
|
|
|
22
|
-
function createRemoteSkyboxComponent(context: IContext, url: string, skybox: boolean, environment: boolean, attribute: "
|
|
22
|
+
function createRemoteSkyboxComponent(context: IContext, url: string, skybox: boolean, environment: boolean, attribute: "background-image" | "environment-image") {
|
|
23
23
|
const remote = new RemoteSkybox();
|
|
24
24
|
remote.allowDrop = false;
|
|
25
25
|
remote.allowNetworking = false;
|
|
@@ -42,7 +42,7 @@ function createRemoteSkyboxComponent(context: IContext, url: string, skybox: boo
|
|
|
42
42
|
const promises = new Array<Promise<any>>();
|
|
43
43
|
ContextRegistry.registerCallback(ContextEvent.ContextCreationStart, (args) => {
|
|
44
44
|
const context = args.context;
|
|
45
|
-
const skyboxImage = context.domElement.getAttribute("
|
|
45
|
+
const skyboxImage = context.domElement.getAttribute("background-image");
|
|
46
46
|
const environmentImage = context.domElement.getAttribute("environment-image");
|
|
47
47
|
if (skyboxImage) {
|
|
48
48
|
if (debug)
|
|
@@ -50,8 +50,8 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreationStart, (args) => {
|
|
|
50
50
|
// if the user is loading a GLB without a camera then the CameraUtils (which creates the default camera)
|
|
51
51
|
// checks if we have this attribute set and then sets the skybox clearflags accordingly
|
|
52
52
|
// if the user has a GLB with a camera but set to solid color then the skybox image is not visible -> we will just warn then and not override the camera settings
|
|
53
|
-
if (context.mainCameraComponent?.clearFlags !== ClearFlags.Skybox) console.warn("\"
|
|
54
|
-
const promise = createRemoteSkyboxComponent(context, skyboxImage, true, false, "
|
|
53
|
+
if (context.mainCameraComponent?.clearFlags !== ClearFlags.Skybox) console.warn("\"background-image\" attribute has no effect: camera clear flags are not set to \"Skybox\"");
|
|
54
|
+
const promise = createRemoteSkyboxComponent(context, skyboxImage, true, false, "background-image");
|
|
55
55
|
promises.push(promise);
|
|
56
56
|
}
|
|
57
57
|
if (environmentImage) {
|