@needle-tools/engine 4.7.0-next.da47826 → 4.7.0-next.ef983f9
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 +5 -0
- package/dist/{needle-engine.bundle-CO1Ub9sm.js → needle-engine.bundle-450ujan4.js} +585 -574
- package/dist/{needle-engine.bundle-D95XN5pP.min.js → needle-engine.bundle-BDMr_I34.min.js} +33 -30
- package/dist/{needle-engine.bundle-Bu88IoKB.umd.cjs → needle-engine.bundle-CbNroJbN.umd.cjs} +32 -29
- 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 +4 -3
- 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 +8 -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 +15 -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 +223 -0
- package/plugins/types/userconfig.d.ts +3 -1
- package/plugins/vite/alias.js +55 -40
- package/plugins/vite/imports-logger.js +1 -1
- package/plugins/vite/index.js +4 -0
- package/plugins/vite/logger.client.js +216 -0
- package/plugins/vite/logger.js +85 -0
- package/plugins/vite/materialx.js +32 -0
- package/plugins/vite/transform.js +1 -0
- package/src/engine/engine_context.ts +4 -3
- 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 +8 -1
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -1
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +14 -2
- package/src/engine-components/postprocessing/Volume.ts +1 -1
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
message = stringifyLog(message);
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
import.meta.hot.send("needle:client-log", { level, message: message });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
// const obj = {
|
|
18
|
+
// hello: "world"
|
|
19
|
+
// }
|
|
20
|
+
// obj["test"] = obj;
|
|
21
|
+
// sendLogToServer("internal", "Test circular reference", obj);
|
|
22
|
+
|
|
23
|
+
if (import.meta && "hot" in import.meta) {
|
|
24
|
+
|
|
25
|
+
const originalLog = console.log;
|
|
26
|
+
const originalWarn = console.warn;
|
|
27
|
+
const originalInfo = console.info;
|
|
28
|
+
const originalDebug = console.debug;
|
|
29
|
+
const originalError = console.error;
|
|
30
|
+
|
|
31
|
+
console.log = (...args) => {
|
|
32
|
+
originalLog(...args);
|
|
33
|
+
sendLogToServer("log", ...args);
|
|
34
|
+
}
|
|
35
|
+
console.warn = (...args) => {
|
|
36
|
+
originalWarn(...args);
|
|
37
|
+
sendLogToServer("warn", ...args);
|
|
38
|
+
}
|
|
39
|
+
console.info = (...args) => {
|
|
40
|
+
originalInfo(...args);
|
|
41
|
+
sendLogToServer("info", ...args);
|
|
42
|
+
}
|
|
43
|
+
console.debug = (...args) => {
|
|
44
|
+
originalDebug(...args);
|
|
45
|
+
sendLogToServer("debug", ...args);
|
|
46
|
+
}
|
|
47
|
+
console.error = (...args) => {
|
|
48
|
+
originalError(...args);
|
|
49
|
+
sendLogToServer("error", ...args);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
sendLogToServer("internal", `Page loaded
|
|
54
|
+
URL: ${window.location.href}
|
|
55
|
+
UserAgent: ${navigator.userAgent}
|
|
56
|
+
Screen: ${window.innerWidth} x ${window.innerHeight}px
|
|
57
|
+
Device Pixel Ratio: ${window.devicePixelRatio}
|
|
58
|
+
Device Memory: ${"deviceMemory" in navigator ? navigator.deviceMemory : "Not available"} GB
|
|
59
|
+
Online: ${navigator.onLine}
|
|
60
|
+
Language: ${navigator.language}
|
|
61
|
+
Timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}
|
|
62
|
+
Connection: ${"connection" in navigator ? JSON.stringify(navigator.connection) : "Not available"}
|
|
63
|
+
User Activation: ${"userActivation" in navigator ? JSON.stringify(navigator.userActivation) : "Not available"}
|
|
64
|
+
`);
|
|
65
|
+
|
|
66
|
+
if ("gpu" in navigator) {
|
|
67
|
+
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
navigator.gpu.requestAdapter()
|
|
70
|
+
.then(adapter => adapter ? adapter.requestDevice() : null)
|
|
71
|
+
.then(device => {
|
|
72
|
+
if (device) {
|
|
73
|
+
const adapterInfo = device.adapterInfo;
|
|
74
|
+
if (adapterInfo) {
|
|
75
|
+
sendLogToServer("internal", [`WebGPU adapter info`, {
|
|
76
|
+
vendor: adapterInfo.vendor,
|
|
77
|
+
architecture: adapterInfo.architecture,
|
|
78
|
+
device: adapterInfo.device,
|
|
79
|
+
description: adapterInfo.description,
|
|
80
|
+
features: adapterInfo.features,
|
|
81
|
+
limits: adapterInfo.limits
|
|
82
|
+
}]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
// silently fail
|
|
90
|
+
sendLogToServer("error", `Error during initial log: ${e.message}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
window.addEventListener('error', (event) => {
|
|
94
|
+
const errorMessage = event.error ? event.error.stack || event.error.message : event.message;
|
|
95
|
+
sendLogToServer("error", errorMessage);
|
|
96
|
+
});
|
|
97
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
98
|
+
const reason = event.reason ? event.reason.stack || event.reason.message : "Unhandled rejection without reason";
|
|
99
|
+
sendLogToServer("error", `Unhandled promise rejection: ${reason}`);
|
|
100
|
+
});
|
|
101
|
+
window.addEventListener('beforeunload', () => {
|
|
102
|
+
sendLogToServer("internal", "Page is unloading");
|
|
103
|
+
});
|
|
104
|
+
document.addEventListener('visibilitychange', () => {
|
|
105
|
+
console.log("Visibility changed:", document.visibilityState);
|
|
106
|
+
if (document.visibilityState === 'hidden') {
|
|
107
|
+
sendLogToServer("internal", "Page is hidden");
|
|
108
|
+
}
|
|
109
|
+
else if (document.visibilityState === 'visible') {
|
|
110
|
+
sendLogToServer("internal", "Page is visible again");
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
sendLogToServer("internal", `Page visibility changed to ${document.visibilityState}`);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
window.addEventListener("focus", () => {
|
|
117
|
+
sendLogToServer("internal", "Page gained focus");
|
|
118
|
+
});
|
|
119
|
+
window.addEventListener("blur", () => {
|
|
120
|
+
sendLogToServer("internal", "Page lost focus");
|
|
121
|
+
});
|
|
122
|
+
window.addEventListener('load', () => {
|
|
123
|
+
sendLogToServer("internal", "Page fully loaded");
|
|
124
|
+
});
|
|
125
|
+
window.addEventListener('DOMContentLoaded', () => {
|
|
126
|
+
sendLogToServer("internal", "DOM fully loaded and parsed");
|
|
127
|
+
});
|
|
128
|
+
window.addEventListener('online', () => {
|
|
129
|
+
sendLogToServer("internal", "Browser is online");
|
|
130
|
+
});
|
|
131
|
+
window.addEventListener('offline', () => {
|
|
132
|
+
sendLogToServer("warn", "Browser is offline");
|
|
133
|
+
});
|
|
134
|
+
window.addEventListener('resize', () => {
|
|
135
|
+
sendLogToServer("internal", `Window resized to ${window.innerWidth}x${window.innerHeight}px`);
|
|
136
|
+
});
|
|
137
|
+
window.addEventListener('orientationchange', () => {
|
|
138
|
+
sendLogToServer("internal", `Orientation changed to ${screen.orientation.type}`);
|
|
139
|
+
});
|
|
140
|
+
window.addEventListener('fullscreenchange', () => {
|
|
141
|
+
if (document.fullscreenElement) {
|
|
142
|
+
sendLogToServer("internal", "Entered fullscreen mode");
|
|
143
|
+
} else {
|
|
144
|
+
sendLogToServer("internal", "Exited fullscreen mode");
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
// url change event
|
|
150
|
+
window.addEventListener('hashchange', () => {
|
|
151
|
+
sendLogToServer("internal", `URL hash changed to ${location.hash}`);
|
|
152
|
+
});
|
|
153
|
+
window.addEventListener('popstate', () => {
|
|
154
|
+
sendLogToServer("internal", `History state changed: ${JSON.stringify(history.state)}`);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
// #region copied from common/logger.js
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Stringifies a log message, handling circular references and formatting.
|
|
172
|
+
* @param {any} log
|
|
173
|
+
* @param {Set<any>} [seen]
|
|
174
|
+
*/
|
|
175
|
+
function stringifyLog(log, seen = new Set()) {
|
|
176
|
+
|
|
177
|
+
if (typeof log === "string") {
|
|
178
|
+
if (log.length > 2000) log = `${log.slice(0, 2000)}... [truncated: ${log.length - 2000} more characters]`;
|
|
179
|
+
return log;
|
|
180
|
+
}
|
|
181
|
+
if (typeof log === "number" || typeof log === "boolean") {
|
|
182
|
+
return String(log);
|
|
183
|
+
}
|
|
184
|
+
if (log === null) {
|
|
185
|
+
return "null";
|
|
186
|
+
}
|
|
187
|
+
if (log === undefined) {
|
|
188
|
+
return "undefined";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (seen.has(log)) return "[circular]";
|
|
192
|
+
seen.add(log);
|
|
193
|
+
|
|
194
|
+
if (Array.isArray(log)) {
|
|
195
|
+
|
|
196
|
+
let res = "";
|
|
197
|
+
for (let i = 0; i < log.length; i++) {
|
|
198
|
+
let item = log[i];
|
|
199
|
+
if (res) res += ", ";
|
|
200
|
+
if (i > 100) res += "[truncated: " + (log.length - i) + " more items]";
|
|
201
|
+
res += stringifyLog(item, seen);
|
|
202
|
+
}
|
|
203
|
+
return res;
|
|
204
|
+
}
|
|
205
|
+
if (typeof log === "object") {
|
|
206
|
+
let entries = Object.entries(log).map(([key, value], index) => {
|
|
207
|
+
if (index > 100) return `"${key}": [truncated]`;
|
|
208
|
+
return `"${key}": ${stringifyLog(value, seen)}`;
|
|
209
|
+
});
|
|
210
|
+
return `{ ${entries.join(", ")} }`;
|
|
211
|
+
}
|
|
212
|
+
if (log instanceof Buffer) {
|
|
213
|
+
return `Buffer(${log.length}, ${log.byteLength}, ${log.byteOffset})`;
|
|
214
|
+
}
|
|
215
|
+
return String(log);
|
|
216
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
|
|
3
|
+
const materialx_packagejson_path = "node_modules/@needle-tools/materialx/package.json";
|
|
4
|
+
const materialx_import_chunk = `
|
|
5
|
+
import { useNeedleMaterialX } from "@needle-tools/materialx/needle";
|
|
6
|
+
useNeedleMaterialX();
|
|
7
|
+
`
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Vite plugin to automatically setup the MaterialX loader for Needle Engine.
|
|
11
|
+
* @param {string} command
|
|
12
|
+
* @param {object} config
|
|
13
|
+
* @param {import('../types/userconfig.js').userSettings} userSettings
|
|
14
|
+
* @returns {import('vite').Plugin}
|
|
15
|
+
*/
|
|
16
|
+
export const needleMaterialXLoader = (command, config, userSettings) => {
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
name: 'needle-materialx-loader',
|
|
20
|
+
transform: (code, id) => {
|
|
21
|
+
if (id.endsWith("src/main.ts")) {
|
|
22
|
+
if (userSettings?.loadMaterialX !== false && existsSync(materialx_packagejson_path)) {
|
|
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
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return code;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -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();
|
|
@@ -1618,10 +1618,11 @@ export class Context implements IContext {
|
|
|
1618
1618
|
}
|
|
1619
1619
|
|
|
1620
1620
|
const backgroundColor = this.renderer.getClearColor(this._tempClearColor);
|
|
1621
|
+
const clearAlpha = this.renderer.getClearAlpha();
|
|
1621
1622
|
this._tempClearColor2.copy(backgroundColor);
|
|
1622
|
-
this.renderer.setClearColor(backgroundColor.convertSRGBToLinear());
|
|
1623
|
+
this.renderer.setClearColor(backgroundColor.convertSRGBToLinear(), this.renderer.getClearAlpha());
|
|
1623
1624
|
this.composer.render(this.time.deltaTime);
|
|
1624
|
-
this.renderer.setClearColor(this._tempClearColor2); // restore clear color
|
|
1625
|
+
this.renderer.setClearColor(this._tempClearColor2, clearAlpha); // restore clear color
|
|
1625
1626
|
}
|
|
1626
1627
|
else if (camera) {
|
|
1627
1628
|
// Workaround for issue on Vision Pro –
|
|
@@ -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) {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { MODULES } from "../../../engine/engine_modules.js";
|
|
2
2
|
import { serializable } from "../../../engine/engine_serialization.js";
|
|
3
|
+
import { getParam } from "../../../engine/engine_utils.js";
|
|
3
4
|
import { type EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect.js";
|
|
4
5
|
import { VolumeParameter } from "../VolumeParameter.js";
|
|
5
6
|
import { registerCustomEffectType } from "../VolumeProfile.js";
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
const debug = getParam("debugpost");
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
export enum QualityLevel {
|
|
10
13
|
LOW = 0,
|
|
@@ -32,15 +35,19 @@ export class Antialiasing extends PostProcessingEffect {
|
|
|
32
35
|
|
|
33
36
|
onCreateEffect(): EffectProviderResult {
|
|
34
37
|
const effect = new MODULES.POSTPROCESSING.MODULE.SMAAEffect({
|
|
35
|
-
preset: MODULES.POSTPROCESSING.MODULE.SMAAPreset.HIGH,
|
|
38
|
+
preset: this.preset?.value ?? MODULES.POSTPROCESSING.MODULE.SMAAPreset.HIGH,
|
|
36
39
|
edgeDetectionMode: MODULES.POSTPROCESSING.MODULE.EdgeDetectionMode.LUMA,
|
|
37
40
|
// Keep predication mode disabled (default) since it looks better
|
|
38
41
|
// predicationMode: MODULES.POSTPROCESSING.MODULE.PredicationMode.DEPTH,
|
|
39
42
|
});
|
|
40
43
|
|
|
41
44
|
this.preset.onValueChanged = (newValue) => {
|
|
45
|
+
if(debug) console.log("Antialiasing preset changed to", newValue);
|
|
42
46
|
effect.applyPreset(newValue);
|
|
43
47
|
};
|
|
48
|
+
// setInterval(()=> {
|
|
49
|
+
// effect.applyPreset(Math.floor(Math.random()*3))
|
|
50
|
+
// }, 1000)
|
|
44
51
|
|
|
45
52
|
// effect.edgeDetectionMaterial.edgeDetectionThreshold = .01;
|
|
46
53
|
|
|
@@ -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);
|
|
@@ -162,9 +162,11 @@ export class PostProcessingHandler {
|
|
|
162
162
|
const res = component.apply(ctx);
|
|
163
163
|
if (!res) continue;
|
|
164
164
|
|
|
165
|
+
const name = component.typeName || component.constructor.name;
|
|
165
166
|
|
|
166
167
|
if (Array.isArray(res)) {
|
|
167
168
|
for (const effect of res) {
|
|
169
|
+
if (!validateEffect(name, effect)) continue;
|
|
168
170
|
this._effects.push({
|
|
169
171
|
effect,
|
|
170
172
|
typeName: component.typeName,
|
|
@@ -173,12 +175,23 @@ export class PostProcessingHandler {
|
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
else {
|
|
178
|
+
if (!validateEffect(name, res)) continue;
|
|
176
179
|
this._effects.push({
|
|
177
180
|
effect: res,
|
|
178
181
|
typeName: component.typeName,
|
|
179
182
|
priority: component.order
|
|
180
183
|
});
|
|
181
184
|
}
|
|
185
|
+
|
|
186
|
+
function validateEffect(source: string, effect: Effect | Pass): boolean {
|
|
187
|
+
if (!effect) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (!(effect instanceof MODULES.POSTPROCESSING.MODULE.Effect || effect instanceof MODULES.POSTPROCESSING.MODULE.Pass)) {
|
|
191
|
+
console.warn(`PostprocessingEffect ${source} created neither Effect nor Pass - this might be caused by a bundler error or false import. Below you find some possible solutions:\n- If you create custom effect try creating it like this: 'new NEEDLE_ENGINE_MODULES.POSTPROCESSING.MODULE.Effect(...)' instead of 'new Effect(...)'`);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
182
195
|
}
|
|
183
196
|
}
|
|
184
197
|
else {
|
|
@@ -403,7 +416,7 @@ export class PostProcessingHandler {
|
|
|
403
416
|
if (attributes & convolution) {
|
|
404
417
|
if (debug) console.log("[PostProcessing] Convolution effect: " + ef.name);
|
|
405
418
|
if (hasConvolutionEffectInArray) {
|
|
406
|
-
if (debug) console.log("[PostProcessing] Merging effects
|
|
419
|
+
if (debug) console.log("[PostProcessing] → Merging effects [" + effectsToMerge.map(e => e.name).join(", ") + "]");
|
|
407
420
|
this.createPassForMergeableEffects(effectsToMerge, composer, cam, scene);
|
|
408
421
|
}
|
|
409
422
|
hasConvolutionEffectInArray = true;
|
|
@@ -448,7 +461,6 @@ export class PostProcessingHandler {
|
|
|
448
461
|
}
|
|
449
462
|
foundEnabled = true;
|
|
450
463
|
}
|
|
451
|
-
|
|
452
464
|
pass.renderToScreen = renderToScreen;
|
|
453
465
|
|
|
454
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
|
}
|