@needle-tools/engine 4.7.0-next.22483b4 → 4.7.0-next.4bd7749
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 +10 -0
- package/dist/{needle-engine.bundle-RgZNbAgp.js → needle-engine.bundle-BGHUA0S1.js} +21 -19
- package/dist/{needle-engine.bundle-CP5AJL1A.umd.cjs → needle-engine.bundle-DQ8S9diA.umd.cjs} +9 -7
- package/dist/{needle-engine.bundle-BnGp0ASs.min.js → needle-engine.bundle-kBkeRoLs.min.js} +9 -7
- 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/lib/engine-components/postprocessing/Effects/Antialiasing.js +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/postprocessing/Volume.js +1 -1
- package/lib/engine-components/postprocessing/Volume.js.map +1 -1
- package/package.json +1 -1
- package/plugins/common/logger.js +321 -0
- package/plugins/types/userconfig.d.ts +4 -2
- package/plugins/vite/alias.js +7 -2
- package/plugins/vite/imports-logger.js +1 -1
- package/plugins/vite/index.js +2 -0
- package/plugins/vite/logger.client.js +262 -0
- package/plugins/vite/logger.js +101 -0
- package/plugins/vite/materialx.js +6 -4
- 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
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -1
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -2
- package/src/engine-components/postprocessing/Volume.ts +1 -1
|
@@ -0,0 +1,101 @@
|
|
|
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 | null}
|
|
14
|
+
*/
|
|
15
|
+
export const needleLogger = (command, config, userSettings) => {
|
|
16
|
+
|
|
17
|
+
if (userSettings?.disableLogging === true) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
patchConsoleLogs();
|
|
22
|
+
captureLogMessage("server", "info", "Vite started with command \"" + command + "\" in " + __dirname, null);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
name: "needle:logger",
|
|
26
|
+
enforce: 'pre',
|
|
27
|
+
configureServer(server) {
|
|
28
|
+
logRequests(server);
|
|
29
|
+
},
|
|
30
|
+
configurePreviewServer(server) {
|
|
31
|
+
logRequests(server);
|
|
32
|
+
},
|
|
33
|
+
transformIndexHtml: {
|
|
34
|
+
order: 'pre',
|
|
35
|
+
handler(html, ctx) {
|
|
36
|
+
// inject client logger script during development
|
|
37
|
+
if (command === 'serve') {
|
|
38
|
+
const file = path.join(__dirname, 'logger.client.js');
|
|
39
|
+
if (existsSync(file)) {
|
|
40
|
+
const scriptContent = readFileSync(file, 'utf8');
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
tag: 'script',
|
|
44
|
+
attrs: {
|
|
45
|
+
type: 'module',
|
|
46
|
+
},
|
|
47
|
+
children: scriptContent,
|
|
48
|
+
injectTo: 'head-prepend',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Logs HTTP requests to the console.
|
|
61
|
+
* This function is used in the Vite server to log incoming HTTP requests.
|
|
62
|
+
* @param {import('vite').PreviewServer | import('vite').ViteDevServer} server
|
|
63
|
+
*/
|
|
64
|
+
function logRequests(server, log_http_requests = false) {
|
|
65
|
+
/**
|
|
66
|
+
* Logs a message to the server console and captures it.
|
|
67
|
+
* @type {Map<import("vite").WebSocket, {id:string}>}
|
|
68
|
+
*/
|
|
69
|
+
const connectedClients = new Map();
|
|
70
|
+
let index = 0;
|
|
71
|
+
|
|
72
|
+
if ("ws" in server) {
|
|
73
|
+
// Clent connections
|
|
74
|
+
server.ws.on('connection', (socket, request) => {
|
|
75
|
+
const clientId = String(index++);
|
|
76
|
+
connectedClients.set(socket, { id: clientId });
|
|
77
|
+
const ip = request.socket.remoteAddress || 'unknown';
|
|
78
|
+
captureLogMessage("server", "connection", `New websocket connection established ${clientId} from ${ip}`, clientId);
|
|
79
|
+
socket.on('close', () => {
|
|
80
|
+
captureLogMessage("server", "connection", `Websocket connection closed ${clientId}`, clientId);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
// Client log messages via websocket
|
|
84
|
+
server.ws.on('needle:client-log', async (data, client) => {
|
|
85
|
+
if (!data || !data.level || !data.message) {
|
|
86
|
+
console.warn("Received empty log data, ignoring");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const socket = client.socket;
|
|
90
|
+
const info = connectedClients.get(socket);
|
|
91
|
+
captureLogMessage("client", data.level, data.message, info ? info.id : null);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// Log HTTP requests
|
|
95
|
+
if (log_http_requests) {
|
|
96
|
+
server.middlewares.use((req, res, next) => {
|
|
97
|
+
captureLogMessage("client-http", "info", [req.method, req.url], null);
|
|
98
|
+
next();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync } from 'fs';
|
|
2
2
|
|
|
3
3
|
const materialx_packagejson_path = "node_modules/@needle-tools/materialx/package.json";
|
|
4
|
-
const materialx_import_chunk =
|
|
5
|
-
|
|
4
|
+
const materialx_import_chunk = `
|
|
5
|
+
import { useNeedleMaterialX } from "@needle-tools/materialx/needle";
|
|
6
6
|
useNeedleMaterialX();
|
|
7
7
|
`
|
|
8
8
|
|
|
@@ -20,8 +20,10 @@ export const needleMaterialXLoader = (command, config, userSettings) => {
|
|
|
20
20
|
transform: (code, id) => {
|
|
21
21
|
if (id.endsWith("src/main.ts")) {
|
|
22
22
|
if (userSettings?.loadMaterialX !== false && existsSync(materialx_packagejson_path)) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (!code.includes("@needle-tools/materialx")) {
|
|
24
|
+
console.log("[needle-materialx-loader] Adding MaterialX import to main.ts");
|
|
25
|
+
code = materialx_import_chunk + "\n" + code;
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
return code;
|
|
@@ -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) {
|
|
@@ -42,7 +42,7 @@ export class Antialiasing extends PostProcessingEffect {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
this.preset.onValueChanged = (newValue) => {
|
|
45
|
-
if(debug) console.log("Antialiasing preset changed to", newValue
|
|
45
|
+
if(debug) console.log("Antialiasing preset changed to", newValue);
|
|
46
46
|
effect.applyPreset(newValue);
|
|
47
47
|
};
|
|
48
48
|
// setInterval(()=> {
|
|
@@ -124,7 +124,7 @@ export class ScreenSpaceAmbientOcclusionN8 extends PostProcessingEffect {
|
|
|
124
124
|
cam,
|
|
125
125
|
width, height
|
|
126
126
|
) as N8AOPostPass;
|
|
127
|
-
ssao.name = "
|
|
127
|
+
ssao.name = "SSAO_N8";
|
|
128
128
|
|
|
129
129
|
const mode = ScreenSpaceAmbientOcclusionN8QualityMode[this.quality];
|
|
130
130
|
ssao.setQualityMode(mode);
|
|
@@ -183,7 +183,7 @@ export class PostProcessingHandler {
|
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
function validateEffect(source:string, effect: Effect | Pass): boolean {
|
|
186
|
+
function validateEffect(source: string, effect: Effect | Pass): boolean {
|
|
187
187
|
if (!effect) {
|
|
188
188
|
return false;
|
|
189
189
|
}
|
|
@@ -461,7 +461,6 @@ export class PostProcessingHandler {
|
|
|
461
461
|
}
|
|
462
462
|
foundEnabled = true;
|
|
463
463
|
}
|
|
464
|
-
|
|
465
464
|
pass.renderToScreen = renderToScreen;
|
|
466
465
|
|
|
467
466
|
if ((pass as any)?.configuration !== undefined) {
|
|
@@ -194,7 +194,7 @@ export class Volume extends Behaviour implements IEditorModificationReceiver, IP
|
|
|
194
194
|
if (this._postprocessing.multisampling !== 0) {
|
|
195
195
|
this._postprocessing.multisampling = 0;
|
|
196
196
|
if (debug || isDevEnvironment()) {
|
|
197
|
-
console.
|
|
197
|
+
console.log(`[PostProcessing] multisampling is disabled because it's set to 'auto' on your PostprocessingManager/Volume component that also has an SMAA effect.\n\nIf you need multisampling consider changing 'auto' to a fixed value (e.g. 4).`);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
}
|