@needle-tools/engine 4.7.0-next.da47826 → 4.7.0-next.fe38209
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/{gltf-progressive-Bl4okF1b.min.js → gltf-progressive-60Qk5ebF.min.js} +6 -6
- package/dist/{gltf-progressive-DSpdn0QT.js → gltf-progressive-DM5ZiecW.js} +176 -170
- package/dist/gltf-progressive-wxtaVmio.umd.cjs +8 -0
- package/dist/{needle-engine.bundle-CO1Ub9sm.js → needle-engine.bundle-9cpwwMWz.js} +3929 -3906
- package/dist/{needle-engine.bundle-Bu88IoKB.umd.cjs → needle-engine.bundle-B5YoLPqw.umd.cjs} +117 -114
- package/dist/{needle-engine.bundle-D95XN5pP.min.js → needle-engine.bundle-DlHpd9LP.min.js} +115 -112
- package/dist/needle-engine.js +3 -3
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_addressables.d.ts +1 -3
- package/lib/engine/engine_addressables.js +5 -12
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_context.js +4 -3
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_lightdata.js +12 -2
- package/lib/engine/engine_lightdata.js.map +1 -1
- package/lib/engine/engine_lods.d.ts +4 -0
- package/lib/engine/engine_lods.js +19 -5
- package/lib/engine/engine_lods.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 +2 -2
- package/plugins/common/logger.js +328 -0
- package/plugins/types/userconfig.d.ts +6 -2
- 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 +272 -0
- package/plugins/vite/logger.js +101 -0
- package/plugins/vite/materialx.js +32 -0
- package/plugins/vite/transform.js +1 -0
- package/src/engine/engine_addressables.ts +6 -15
- package/src/engine/engine_context.ts +4 -3
- package/src/engine/engine_lightdata.ts +10 -2
- package/src/engine/engine_lods.ts +23 -5
- 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
- package/dist/gltf-progressive-P8b8a0qY.umd.cjs +0 -8
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
// keep messages below payload limit
|
|
12
|
+
if(message.length > 100_000) {
|
|
13
|
+
message = message.slice(0, 100_000) + "... <truncated>";
|
|
14
|
+
}
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import.meta.hot.send("needle:client-log", { level, message: message });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// const obj = {
|
|
21
|
+
// hello: "world"
|
|
22
|
+
// }
|
|
23
|
+
// obj["test"] = obj;
|
|
24
|
+
// sendLogToServer("internal", "Test circular reference", obj);
|
|
25
|
+
|
|
26
|
+
if (import.meta && "hot" in import.meta) {
|
|
27
|
+
|
|
28
|
+
const originalLog = console.log;
|
|
29
|
+
const originalWarn = console.warn;
|
|
30
|
+
const originalInfo = console.info;
|
|
31
|
+
const originalDebug = console.debug;
|
|
32
|
+
const originalError = console.error;
|
|
33
|
+
|
|
34
|
+
console.log = (...args) => {
|
|
35
|
+
originalLog(...args);
|
|
36
|
+
sendLogToServer("log", ...args);
|
|
37
|
+
}
|
|
38
|
+
console.warn = (...args) => {
|
|
39
|
+
originalWarn(...args);
|
|
40
|
+
sendLogToServer("warn", ...args);
|
|
41
|
+
}
|
|
42
|
+
console.info = (...args) => {
|
|
43
|
+
originalInfo(...args);
|
|
44
|
+
sendLogToServer("info", ...args);
|
|
45
|
+
}
|
|
46
|
+
console.debug = (...args) => {
|
|
47
|
+
originalDebug(...args);
|
|
48
|
+
sendLogToServer("debug", ...args);
|
|
49
|
+
}
|
|
50
|
+
console.error = (...args) => {
|
|
51
|
+
originalError(...args);
|
|
52
|
+
sendLogToServer("error", ...args);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
sendLogToServer("internal", `Page loaded
|
|
57
|
+
URL: ${window.location.href}
|
|
58
|
+
UserAgent: ${navigator.userAgent}
|
|
59
|
+
Screen: ${window.innerWidth} x ${window.innerHeight}px
|
|
60
|
+
Device Pixel Ratio: ${window.devicePixelRatio}
|
|
61
|
+
Device Memory: ${"deviceMemory" in navigator ? navigator.deviceMemory : "Not available"} GB
|
|
62
|
+
Online: ${navigator.onLine}
|
|
63
|
+
Language: ${navigator.language}
|
|
64
|
+
Timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}
|
|
65
|
+
Connection: ${"connection" in navigator ? JSON.stringify(navigator.connection) : "Not available"}
|
|
66
|
+
User Activation: ${"userActivation" in navigator ? JSON.stringify(navigator.userActivation) : "Not available"}
|
|
67
|
+
`);
|
|
68
|
+
|
|
69
|
+
if ("gpu" in navigator) {
|
|
70
|
+
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
navigator.gpu.requestAdapter()
|
|
73
|
+
.then(adapter => adapter ? adapter.requestDevice() : null)
|
|
74
|
+
.then(device => {
|
|
75
|
+
if (device) {
|
|
76
|
+
const adapterInfo = device.adapterInfo;
|
|
77
|
+
if (adapterInfo) {
|
|
78
|
+
sendLogToServer("internal", [`WebGPU adapter info`, {
|
|
79
|
+
vendor: adapterInfo.vendor,
|
|
80
|
+
architecture: adapterInfo.architecture,
|
|
81
|
+
device: adapterInfo.device,
|
|
82
|
+
description: adapterInfo.description,
|
|
83
|
+
features: adapterInfo.features,
|
|
84
|
+
limits: adapterInfo.limits
|
|
85
|
+
}]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
// silently fail
|
|
93
|
+
sendLogToServer("error", `Error during initial log: ${e.message}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
window.addEventListener('error', (event) => {
|
|
97
|
+
const errorMessage = event.error ? event.error.stack || event.error.message : event.message;
|
|
98
|
+
sendLogToServer("error", errorMessage);
|
|
99
|
+
});
|
|
100
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
101
|
+
const reason = event.reason ? event.reason.stack || event.reason.message : "Unhandled rejection without reason";
|
|
102
|
+
sendLogToServer("error", `Unhandled promise rejection: ${reason}`);
|
|
103
|
+
});
|
|
104
|
+
window.addEventListener('beforeunload', () => {
|
|
105
|
+
sendLogToServer("internal", "Page is unloading");
|
|
106
|
+
});
|
|
107
|
+
document.addEventListener('visibilitychange', () => {
|
|
108
|
+
console.log("Visibility changed:", document.visibilityState);
|
|
109
|
+
if (document.visibilityState === 'hidden') {
|
|
110
|
+
sendLogToServer("internal", "Page is hidden");
|
|
111
|
+
}
|
|
112
|
+
else if (document.visibilityState === 'visible') {
|
|
113
|
+
sendLogToServer("internal", "Page is visible again");
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
sendLogToServer("internal", `Page visibility changed to ${document.visibilityState}`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
window.addEventListener("focus", () => {
|
|
120
|
+
sendLogToServer("internal", "Page gained focus");
|
|
121
|
+
});
|
|
122
|
+
window.addEventListener("blur", () => {
|
|
123
|
+
sendLogToServer("internal", "Page lost focus");
|
|
124
|
+
});
|
|
125
|
+
window.addEventListener('load', () => {
|
|
126
|
+
sendLogToServer("internal", "Page fully loaded");
|
|
127
|
+
});
|
|
128
|
+
window.addEventListener('DOMContentLoaded', () => {
|
|
129
|
+
sendLogToServer("internal", "DOM fully loaded and parsed");
|
|
130
|
+
});
|
|
131
|
+
window.addEventListener('online', () => {
|
|
132
|
+
sendLogToServer("internal", "Browser is online");
|
|
133
|
+
});
|
|
134
|
+
window.addEventListener('offline', () => {
|
|
135
|
+
sendLogToServer("warn", "Browser is offline");
|
|
136
|
+
});
|
|
137
|
+
window.addEventListener('resize', () => {
|
|
138
|
+
sendLogToServer("internal", `Window resized to ${window.innerWidth}x${window.innerHeight}px`);
|
|
139
|
+
});
|
|
140
|
+
window.addEventListener('orientationchange', () => {
|
|
141
|
+
sendLogToServer("internal", `Orientation changed to ${screen.orientation.type}`);
|
|
142
|
+
});
|
|
143
|
+
window.addEventListener('fullscreenchange', () => {
|
|
144
|
+
if (document.fullscreenElement) {
|
|
145
|
+
sendLogToServer("internal", "Entered fullscreen mode");
|
|
146
|
+
} else {
|
|
147
|
+
sendLogToServer("internal", "Exited fullscreen mode");
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
// url change event
|
|
153
|
+
window.addEventListener('hashchange', () => {
|
|
154
|
+
sendLogToServer("internal", `URL hash changed to ${location.hash}`);
|
|
155
|
+
});
|
|
156
|
+
window.addEventListener('popstate', () => {
|
|
157
|
+
sendLogToServer("internal", `History state changed: ${JSON.stringify(history.state)}`);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// #region copied from common/logger.js
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Stringifies a log message, handling circular references and formatting.
|
|
173
|
+
* @param {any} log
|
|
174
|
+
* @param {Set<any>} [seen]
|
|
175
|
+
*/
|
|
176
|
+
function stringifyLog(log, seen = new Set(), depth = 0) {
|
|
177
|
+
|
|
178
|
+
const isServer = typeof window === "undefined";
|
|
179
|
+
const stringify_limits = {
|
|
180
|
+
string: isServer ? 100_000 : 2000,
|
|
181
|
+
object_keys: isServer ? 300 : 100,
|
|
182
|
+
object_depth: isServer ? 10 : 3,
|
|
183
|
+
array_items: isServer ? 2_000 : 100,
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (typeof log === "string") {
|
|
187
|
+
if (log.length > stringify_limits.string) log = `${log.slice(0, stringify_limits.string)}... <truncated ${log.length - stringify_limits.string} characters>`;
|
|
188
|
+
return log;
|
|
189
|
+
}
|
|
190
|
+
if (typeof log === "number" || typeof log === "boolean") {
|
|
191
|
+
return String(log);
|
|
192
|
+
}
|
|
193
|
+
if (log === null) {
|
|
194
|
+
return "null";
|
|
195
|
+
}
|
|
196
|
+
if (log === undefined) {
|
|
197
|
+
return "undefined";
|
|
198
|
+
}
|
|
199
|
+
if (typeof log === "function") {
|
|
200
|
+
return "<function>";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (seen.has(log)) return "<circular>";
|
|
204
|
+
|
|
205
|
+
if (Array.isArray(log)) {
|
|
206
|
+
seen.add(log);
|
|
207
|
+
return stringifyArray(log);
|
|
208
|
+
}
|
|
209
|
+
if (typeof log === "object") {
|
|
210
|
+
|
|
211
|
+
if (depth > stringify_limits.object_depth) {
|
|
212
|
+
return "<object too deep>";
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
seen.add(log);
|
|
216
|
+
// const str = JSON.stringify(log, (key, value) => {
|
|
217
|
+
// if (typeof value === "function") return "<function>";
|
|
218
|
+
// if (typeof value === "string") return stringifyLog(value, seen, depth + 1);
|
|
219
|
+
// if (typeof value === "object") {
|
|
220
|
+
// if (seen.has(value)) return "<circular>";
|
|
221
|
+
// seen.add(value);
|
|
222
|
+
// }
|
|
223
|
+
// return value;
|
|
224
|
+
// });
|
|
225
|
+
// return str;
|
|
226
|
+
const keys = Object.keys(log);
|
|
227
|
+
let res = "{";
|
|
228
|
+
for (let i = 0; i < keys.length; i++) {
|
|
229
|
+
const key = keys[i];
|
|
230
|
+
let value = log[key];
|
|
231
|
+
|
|
232
|
+
if (typeof value === "number") {
|
|
233
|
+
// clamp precision for numbers
|
|
234
|
+
value = Number(value.toFixed(6));
|
|
235
|
+
}
|
|
236
|
+
let str = stringifyLog(value, seen, depth + 1);
|
|
237
|
+
if (typeof value === "object") {
|
|
238
|
+
if (Array.isArray(value)) {
|
|
239
|
+
str = `[${str}]`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (typeof value === "string") {
|
|
243
|
+
str = `"${str}"`;
|
|
244
|
+
}
|
|
245
|
+
if (i > 0) res += ", ";
|
|
246
|
+
res += `"${key}":${str}`;
|
|
247
|
+
}
|
|
248
|
+
res += "}";
|
|
249
|
+
return res;
|
|
250
|
+
// let entries = Object.entries(log).map(([key, value], index) => {
|
|
251
|
+
// if (index > stringify_limits.object_keys) return `"${key}": <truncated>`;
|
|
252
|
+
// return `"${key}": ${stringifyLog(value, seen, depth + 1)}`;
|
|
253
|
+
// });
|
|
254
|
+
// return `{ ${entries.join(", ")} }`;
|
|
255
|
+
}
|
|
256
|
+
return String(log);
|
|
257
|
+
|
|
258
|
+
function stringifyArray(arr) {
|
|
259
|
+
let res = "";
|
|
260
|
+
for (let i = 0; i < arr.length; i++) {
|
|
261
|
+
let entry = arr[i];
|
|
262
|
+
if (res && i > 0) res += ", ";
|
|
263
|
+
if (i > stringify_limits.array_items) {
|
|
264
|
+
res += "<truncated " + (arr.length - i) + ">";
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
res += stringifyLog(entry, seen, depth + 1);
|
|
268
|
+
}
|
|
269
|
+
return res;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -188,14 +188,11 @@ export class AssetReference {
|
|
|
188
188
|
private _urlName: string;
|
|
189
189
|
private _progressListeners: ProgressCallback[] = [];
|
|
190
190
|
|
|
191
|
-
private _hash?: string;
|
|
192
|
-
private _hashedUri: string;
|
|
193
|
-
|
|
194
191
|
private _isLoadingRawBinary: boolean = false;
|
|
195
192
|
private _rawBinary?: ArrayBufferLike | null;
|
|
196
193
|
|
|
197
194
|
/** @internal */
|
|
198
|
-
constructor(uri: string,
|
|
195
|
+
constructor(uri: string, _hash?: string, asset: any = null) {
|
|
199
196
|
this._url = uri;
|
|
200
197
|
|
|
201
198
|
const lastUriPart = uri.lastIndexOf("/");
|
|
@@ -210,14 +207,8 @@ export class AssetReference {
|
|
|
210
207
|
else {
|
|
211
208
|
this._urlName = uri;
|
|
212
209
|
}
|
|
213
|
-
|
|
214
|
-
this._hash = hash;
|
|
215
|
-
if (uri.includes("?v="))
|
|
216
|
-
this._hashedUri = uri;
|
|
217
|
-
else
|
|
218
|
-
this._hashedUri = hash ? uri + "?v=" + hash : uri;
|
|
210
|
+
|
|
219
211
|
if (asset !== null) this.asset = asset;
|
|
220
|
-
|
|
221
212
|
registerPrefabProvider(this._url, this.onResolvePrefab.bind(this));
|
|
222
213
|
}
|
|
223
214
|
|
|
@@ -263,8 +254,8 @@ export class AssetReference {
|
|
|
263
254
|
if (this._isLoadingRawBinary) return null;
|
|
264
255
|
if (this._rawBinary !== undefined) return this._rawBinary;
|
|
265
256
|
this._isLoadingRawBinary = true;
|
|
266
|
-
if (debug) console.log("Preload", this.
|
|
267
|
-
const res = await BlobStorage.download(this.
|
|
257
|
+
if (debug) console.log("Preload", this.url);
|
|
258
|
+
const res = await BlobStorage.download(this.url, p => {
|
|
268
259
|
this.raiseProgressEvent(p);
|
|
269
260
|
});
|
|
270
261
|
this._rawBinary = res?.buffer ?? null;
|
|
@@ -294,7 +285,7 @@ export class AssetReference {
|
|
|
294
285
|
// console.log("START LOADING");
|
|
295
286
|
if (this._rawBinary) {
|
|
296
287
|
if (!(this._rawBinary instanceof ArrayBuffer)) {
|
|
297
|
-
console.error("Invalid raw binary data"
|
|
288
|
+
console.error("Failed loading: Invalid raw binary data. Must be of type ArrayBuffer. " + (typeof this._rawBinary));
|
|
298
289
|
return null;
|
|
299
290
|
}
|
|
300
291
|
this._loading = getLoader().parseSync(context, this._rawBinary, this.url, null);
|
|
@@ -302,7 +293,7 @@ export class AssetReference {
|
|
|
302
293
|
}
|
|
303
294
|
else {
|
|
304
295
|
if (debug) console.log("Load async", this.url);
|
|
305
|
-
this._loading = getLoader().loadSync(context, this.
|
|
296
|
+
this._loading = getLoader().loadSync(context, this.url, this.url, null, prog => {
|
|
306
297
|
this.raiseProgressEvent(prog);
|
|
307
298
|
});
|
|
308
299
|
}
|
|
@@ -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 –
|
|
@@ -53,10 +53,12 @@ export class LightDataRegistry implements ILightDataRegistry {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
tryGetSkybox(sourceId?: SourceIdentifier | null): Texture | null {
|
|
56
|
+
if (debugLightmap) console.log("[Get Skybox]", sourceId, this._lightmaps)
|
|
56
57
|
return this.tryGet(sourceId, LightmapType.Skybox, 0);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
tryGetReflection(sourceId?: SourceIdentifier | null): Texture | null {
|
|
61
|
+
if (debugLightmap) console.log("[Get Reflection]", sourceId, this._lightmaps)
|
|
60
62
|
return this.tryGet(sourceId, LightmapType.Reflection, 0);
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -66,9 +68,15 @@ export class LightDataRegistry implements ILightDataRegistry {
|
|
|
66
68
|
return null;
|
|
67
69
|
}
|
|
68
70
|
const entry = this._lightmaps.get(sourceId);
|
|
69
|
-
if (!entry)
|
|
71
|
+
if (!entry) {
|
|
72
|
+
if (debugLightmap) console.warn(`[Lighting] No ${LightmapType[type]} texture entry for`, sourceId);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
70
75
|
const arr = entry.get(type);
|
|
71
|
-
if (arr === undefined)
|
|
76
|
+
if (arr === undefined) {
|
|
77
|
+
if (debugLightmap) console.warn(`[Lighting] No ${LightmapType[type]} texture for`, sourceId, "index", index);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
72
80
|
if (!arr?.length || arr.length <= index) return null;
|
|
73
81
|
return arr[index];
|
|
74
82
|
}
|
|
@@ -23,6 +23,9 @@ export class LODsManager implements NEEDLE_progressive_plugin {
|
|
|
23
23
|
readonly context: Context;
|
|
24
24
|
private _lodsManager?: _LODsManager;
|
|
25
25
|
|
|
26
|
+
private _settings: Partial<Pick<_LODsManager, "skinnedMeshAutoUpdateBoundsInterval" | "targetTriangleDensity">> = {
|
|
27
|
+
}
|
|
28
|
+
|
|
26
29
|
/**
|
|
27
30
|
* The internal LODs manager. See @needle-tools/gltf-progressive for more information.
|
|
28
31
|
* @link https://npmjs.com/package/@needle-tools/gltf-progressive
|
|
@@ -31,24 +34,38 @@ export class LODsManager implements NEEDLE_progressive_plugin {
|
|
|
31
34
|
return this._lodsManager;
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
get skinnedMeshAutoUpdateBoundsInterval() {
|
|
38
|
+
return this._lodsManager?.skinnedMeshAutoUpdateBoundsInterval || this._settings.skinnedMeshAutoUpdateBoundsInterval || 0;
|
|
39
|
+
}
|
|
40
|
+
set skinnedMeshAutoUpdateBoundsInterval(value: number) {
|
|
41
|
+
this._settings.skinnedMeshAutoUpdateBoundsInterval = value;
|
|
42
|
+
this.applySettings();
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
/**
|
|
35
46
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
36
47
|
* @default 200_000
|
|
37
48
|
*/
|
|
38
49
|
get targetTriangleDensity() {
|
|
39
|
-
return this._lodsManager?.targetTriangleDensity
|
|
50
|
+
return this._lodsManager?.targetTriangleDensity || this._settings.targetTriangleDensity || 200_000; // default value
|
|
40
51
|
}
|
|
41
52
|
set targetTriangleDensity(value: number) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
this._lodsManager.targetTriangleDensity = value;
|
|
53
|
+
this._settings.targetTriangleDensity = value;
|
|
54
|
+
this.applySettings();
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
constructor(context: Context) {
|
|
49
58
|
this.context = context;
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
private applySettings() {
|
|
62
|
+
if(this._lodsManager) {
|
|
63
|
+
for(const key in this._settings) {
|
|
64
|
+
this._lodsManager[key] = this._settings[key];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
52
69
|
/** @internal */
|
|
53
70
|
setRenderer(renderer: WebGLRenderer) {
|
|
54
71
|
this._lodsManager?.disable();
|
|
@@ -56,6 +73,7 @@ export class LODsManager implements NEEDLE_progressive_plugin {
|
|
|
56
73
|
_LODsManager.addPlugin(this);
|
|
57
74
|
_LODsManager.debugDrawLine = Gizmos.DrawLine;
|
|
58
75
|
this._lodsManager = _LODsManager.get(renderer);
|
|
76
|
+
this.applySettings();
|
|
59
77
|
this._lodsManager.enable();
|
|
60
78
|
}
|
|
61
79
|
|
|
@@ -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) {
|