@needle-tools/engine 4.7.0-next.2756168 → 4.7.0-next.7da7e6c
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-lLDHlwZU.umd.cjs → needle-engine.bundle-5RaHkjsI.umd.cjs} +29 -27
- package/dist/{needle-engine.bundle-S0N_qbSh.js → needle-engine.bundle-FwGYQmeZ.js} +368 -364
- package/dist/{needle-engine.bundle-C2wJAuPf.min.js → needle-engine.bundle-lPQ5zOtR.min.js} +30 -28
- 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/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.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 +214 -0
- package/plugins/types/userconfig.d.ts +3 -1
- package/plugins/vite/alias.js +7 -2
- package/plugins/vite/imports-logger.js +1 -1
- package/plugins/vite/index.js +4 -0
- package/plugins/vite/logger.client.js +124 -0
- package/plugins/vite/logger.js +85 -0
- package/plugins/vite/materialx.js +30 -0
- package/plugins/vite/transform.js +1 -0
- package/src/engine/engine_context.ts +1 -1
- 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 +1 -2
- package/src/engine-components/postprocessing/Volume.ts +1 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { createWriteStream, existsSync, mkdirSync, readdirSync, rmSync, statSync, write } from "fs";
|
|
2
|
+
|
|
3
|
+
const filename_timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {"server" | "client" | "client-http"} ProcessType
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
let originalConsoleLog = console.log;
|
|
11
|
+
let originalConsoleError = console.error;
|
|
12
|
+
let originalConsoleWarn = console.warn;
|
|
13
|
+
let originalConsoleInfo = console.info;
|
|
14
|
+
let originalConsoleDebug = console.debug;
|
|
15
|
+
let didPatch = false;
|
|
16
|
+
let unpatchFunction = null;
|
|
17
|
+
|
|
18
|
+
export function patchConsoleLogs() {
|
|
19
|
+
if (didPatch) return unpatchFunction;
|
|
20
|
+
didPatch = true;
|
|
21
|
+
|
|
22
|
+
console.log = (...args) => {
|
|
23
|
+
originalConsoleLog(...args);
|
|
24
|
+
captureLogMessage("server", 'log', args);
|
|
25
|
+
};
|
|
26
|
+
console.error = (...args) => {
|
|
27
|
+
originalConsoleError(...args);
|
|
28
|
+
captureLogMessage("server", 'error', args);
|
|
29
|
+
};
|
|
30
|
+
console.warn = (...args) => {
|
|
31
|
+
originalConsoleWarn(...args);
|
|
32
|
+
captureLogMessage("server", 'warn', args);
|
|
33
|
+
};
|
|
34
|
+
console.info = (...args) => {
|
|
35
|
+
originalConsoleInfo(...args);
|
|
36
|
+
captureLogMessage("server", 'info', args);
|
|
37
|
+
};
|
|
38
|
+
console.debug = (...args) => {
|
|
39
|
+
originalConsoleDebug(...args);
|
|
40
|
+
captureLogMessage("server", 'debug', args);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Restore original console methods
|
|
44
|
+
unpatchFunction = () => {
|
|
45
|
+
didPatch = false;
|
|
46
|
+
console.log = originalConsoleLog;
|
|
47
|
+
console.error = originalConsoleError;
|
|
48
|
+
console.warn = originalConsoleWarn;
|
|
49
|
+
console.info = originalConsoleInfo;
|
|
50
|
+
console.debug = originalConsoleDebug;
|
|
51
|
+
}
|
|
52
|
+
return unpatchFunction;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
let isCapturing = false;
|
|
57
|
+
|
|
58
|
+
/** @type {Array<{ process: ProcessType, key: string, log:any, timestamp:number }>} */
|
|
59
|
+
const queue = new Array();
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {ProcessType} process
|
|
63
|
+
* @param {string} key
|
|
64
|
+
* @param {any} log
|
|
65
|
+
*/
|
|
66
|
+
export function captureLogMessage(process, key, log, time = Date.now()) {
|
|
67
|
+
if (isCapturing) {
|
|
68
|
+
queue.push({ process, key, log, timestamp: Date.now() });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
isCapturing = true;
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const str = stringifyLog(log);
|
|
75
|
+
const prefix = `${getTimestamp(time, true)}, ${process}.${key}: `;
|
|
76
|
+
const separator = "";
|
|
77
|
+
writeToFile(process, indent(`${prefix}${separator}${str}`, prefix.length, separator));
|
|
78
|
+
} finally {
|
|
79
|
+
isCapturing = false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let queued = queue.pop();
|
|
83
|
+
if (queued) {
|
|
84
|
+
captureLogMessage(queued.process, queued.key, queued.log, queued.timestamp);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Returns the current timestamp in ISO format.
|
|
91
|
+
* @param {number} [date] - Optional date to format, defaults to current date.
|
|
92
|
+
*/
|
|
93
|
+
function getTimestamp(date, timeOnly = false) {
|
|
94
|
+
const now = date ? new Date(date) : new Date();
|
|
95
|
+
if (timeOnly) {
|
|
96
|
+
return now.toTimeString().split(' ')[0]; // HH:MM:SS
|
|
97
|
+
}
|
|
98
|
+
return now.toISOString();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {any} log
|
|
103
|
+
* @param {Set<any>} [seen]
|
|
104
|
+
*/
|
|
105
|
+
function stringifyLog(log, seen = new Set()) {
|
|
106
|
+
|
|
107
|
+
if (seen.has(log)) {
|
|
108
|
+
return "[circular]";
|
|
109
|
+
}
|
|
110
|
+
seen.add(log);
|
|
111
|
+
if (Array.isArray(log)) {
|
|
112
|
+
let res = "";
|
|
113
|
+
for (let item of log) {
|
|
114
|
+
if (res) res += ", ";
|
|
115
|
+
res += stringifyLog(item, seen);
|
|
116
|
+
}
|
|
117
|
+
return res;
|
|
118
|
+
}
|
|
119
|
+
if (typeof log === "object") {
|
|
120
|
+
if (seen.has(log)) {
|
|
121
|
+
return "[circular]";
|
|
122
|
+
}
|
|
123
|
+
let entries = Object.entries(log).map(([key, value]) => {
|
|
124
|
+
return `"${key}": ${stringifyLog(value, seen)}`;
|
|
125
|
+
});
|
|
126
|
+
return `{ ${entries.join(", ")} }`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (typeof log === "string") {
|
|
130
|
+
return log;
|
|
131
|
+
}
|
|
132
|
+
if (typeof log === "number" || typeof log === "boolean") {
|
|
133
|
+
return String(log);
|
|
134
|
+
}
|
|
135
|
+
if (log === null) {
|
|
136
|
+
return "null";
|
|
137
|
+
}
|
|
138
|
+
if (log === undefined) {
|
|
139
|
+
return "undefined";
|
|
140
|
+
}
|
|
141
|
+
return String(log);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Indents a string by a specified length.
|
|
146
|
+
* @param {string} str - The string to indent.
|
|
147
|
+
* @param {number} length - The number of spaces to indent each line.
|
|
148
|
+
* @returns {string} The indented string.
|
|
149
|
+
*/
|
|
150
|
+
function indent(str, length, separator = "") {
|
|
151
|
+
const lines = str.split("\n");
|
|
152
|
+
const prefixStr = " ".repeat(length) + separator;
|
|
153
|
+
for (let i = 1; i < lines.length; i++) {
|
|
154
|
+
let entry = lines[i].trim();
|
|
155
|
+
if (entry.length === 0) continue; // skip empty lines
|
|
156
|
+
// indent the line
|
|
157
|
+
lines[i] = prefixStr + entry;
|
|
158
|
+
}
|
|
159
|
+
return lines.join("\n");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
// #region log to file
|
|
164
|
+
|
|
165
|
+
/** @type {Map<ProcessType, import("fs").WriteStream>} */
|
|
166
|
+
const filestreams = new Map();
|
|
167
|
+
const fileLogDirectory = "node_modules/.needle/logs";
|
|
168
|
+
// cleanup old log files
|
|
169
|
+
if (existsSync(fileLogDirectory)) {
|
|
170
|
+
const files = readdirSync(fileLogDirectory);
|
|
171
|
+
// sort by age and keep the last 10 files
|
|
172
|
+
files.sort((a, b) => {
|
|
173
|
+
const aStat = statSync(`${fileLogDirectory}/${a}`);
|
|
174
|
+
const bStat = statSync(`${fileLogDirectory}/${b}`);
|
|
175
|
+
return aStat.mtimeMs - bStat.mtimeMs;
|
|
176
|
+
});
|
|
177
|
+
// remove all but the last 30 files
|
|
178
|
+
const filesToKeep = 30;
|
|
179
|
+
for (let i = 0; i < files.length - filesToKeep; i++) {
|
|
180
|
+
rmSync(`${fileLogDirectory}/${files[i]}`, { force: true });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Writes a log message to the file.
|
|
186
|
+
* @param {ProcessType} process
|
|
187
|
+
* @param {string} log
|
|
188
|
+
*/
|
|
189
|
+
function writeToFile(process, log) {
|
|
190
|
+
if (!filestreams.has(process)) {
|
|
191
|
+
if (!existsSync(fileLogDirectory)) {
|
|
192
|
+
mkdirSync(fileLogDirectory, { recursive: true });
|
|
193
|
+
}
|
|
194
|
+
filestreams.set(process, createWriteStream(`${fileLogDirectory}/needle.${filename_timestamp}.${process}.log`, { flags: 'a' }));
|
|
195
|
+
}
|
|
196
|
+
const writeStream = filestreams.get(process);
|
|
197
|
+
if (!writeStream) {
|
|
198
|
+
console.error(`No write stream for process: ${process}`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
writeStream.write(log + '\n');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
// #region process exit
|
|
207
|
+
function onExit() {
|
|
208
|
+
filestreams.forEach((stream) => stream.end());
|
|
209
|
+
filestreams.clear();
|
|
210
|
+
}
|
|
211
|
+
const events = ['SIGTERM', 'SIGINT', 'beforeExit', 'rejectionHandled', 'uncaughtException', 'exit'];
|
|
212
|
+
for (const event of events) {
|
|
213
|
+
process.on(event, onExit);
|
|
214
|
+
}
|
|
@@ -49,7 +49,7 @@ export type userSettings = {
|
|
|
49
49
|
/** Custom configuration for facebook instant games. */
|
|
50
50
|
facebookInstantGames?: {}
|
|
51
51
|
/** Set to true to create an imports.log file that shows all module imports. The file is generated when stopping the server. */
|
|
52
|
-
|
|
52
|
+
debugImportChains?: boolean;
|
|
53
53
|
|
|
54
54
|
/** Set to true to disable generating the buildinfo.json file in your output directory */
|
|
55
55
|
noBuildInfo?: boolean;
|
|
@@ -117,4 +117,6 @@ export type userSettings = {
|
|
|
117
117
|
* @default undefined
|
|
118
118
|
*/
|
|
119
119
|
openBrowser?: boolean;
|
|
120
|
+
|
|
121
|
+
loadMaterialX?: boolean;
|
|
120
122
|
}
|
package/plugins/vite/alias.js
CHANGED
|
@@ -42,18 +42,23 @@ const packages_to_resolve = {
|
|
|
42
42
|
because this is automatically done by vite according to whatever we define in our package.json exports
|
|
43
43
|
This did previously prevent us from declaring proper exports in package.json
|
|
44
44
|
*/
|
|
45
|
-
'@needle-tools/engine': (res, packageName, index,
|
|
45
|
+
'@needle-tools/engine': (res, packageName, index, _path) => {
|
|
46
46
|
// Check if the import is something like @needle-tools/engine/engine/engine_utils
|
|
47
47
|
// in which case we want to resolve into the lib directory
|
|
48
|
-
if (
|
|
48
|
+
if (_path.startsWith("@needle-tools/engine/engine")) {
|
|
49
49
|
return res + "/lib";
|
|
50
50
|
}
|
|
51
|
+
const node_modules_path = path.resolve(projectDir, 'node_modules', '@needle-tools/engine');
|
|
52
|
+
if (existsSync(node_modules_path)) {
|
|
53
|
+
return node_modules_path;
|
|
54
|
+
}
|
|
51
55
|
},
|
|
52
56
|
|
|
53
57
|
// Auto resolve to 'node_modules/<name>' or '@needle-tools/engine/node_modules/<name>'
|
|
54
58
|
'peerjs': "auto-resolve",
|
|
55
59
|
'websocket-ts': "auto-resolve",
|
|
56
60
|
'md5': "auto-resolve",
|
|
61
|
+
'three-mesh-bvh': "auto-resolve",
|
|
57
62
|
'postprocessing': "auto-resolve",
|
|
58
63
|
'@dimforge/rapier3d-compat': "auto-resolve",
|
|
59
64
|
}
|
package/plugins/vite/index.js
CHANGED
|
@@ -66,6 +66,8 @@ export { needleBuildInfo } from "./buildinfo.js";
|
|
|
66
66
|
import { needleServer } from "./server.js";
|
|
67
67
|
import { needleNPM } from "./npm.js";
|
|
68
68
|
import { needleTransformCode } from "./transform.js";
|
|
69
|
+
import { needleMaterialXLoader } from "./materialx.js";
|
|
70
|
+
import { needleLogger } from "./logger.js";
|
|
69
71
|
export { needleServer } from "./server.js";
|
|
70
72
|
|
|
71
73
|
|
|
@@ -110,6 +112,7 @@ export const needlePlugins = async (command, config = undefined, userSettings =
|
|
|
110
112
|
userSettings = { ...defaultUserSettings, ...userSettings };
|
|
111
113
|
|
|
112
114
|
const array = [
|
|
115
|
+
needleLogger(command, config, userSettings),
|
|
113
116
|
needleDefines(command, config, userSettings),
|
|
114
117
|
needleLicense(command, config, userSettings),
|
|
115
118
|
needleViteAlias(command, config, userSettings),
|
|
@@ -133,6 +136,7 @@ export const needlePlugins = async (command, config = undefined, userSettings =
|
|
|
133
136
|
needlePWA(command, config, userSettings),
|
|
134
137
|
needleServer(command, config, userSettings),
|
|
135
138
|
needleNPM(command, config, userSettings),
|
|
139
|
+
needleMaterialXLoader(command, config, userSettings),
|
|
136
140
|
];
|
|
137
141
|
|
|
138
142
|
const asap = await needleAsap(command, config, userSettings);
|
|
@@ -0,0 +1,124 @@
|
|
|
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 });
|
|
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
|
+
|
|
41
|
+
try {
|
|
42
|
+
sendLogToServer("internal", `Page loaded
|
|
43
|
+
URL: ${window.location.href}
|
|
44
|
+
UserAgent: ${navigator.userAgent}
|
|
45
|
+
Screen: ${window.innerWidth} x ${window.innerHeight}px
|
|
46
|
+
Device Pixel Ratio: ${window.devicePixelRatio}
|
|
47
|
+
Language: ${navigator.language}
|
|
48
|
+
Timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}
|
|
49
|
+
Connection: ${"connection" in navigator ? JSON.stringify(navigator.connection) : "Not available"}
|
|
50
|
+
User Activation: ${"userActivation" in navigator ? JSON.stringify(navigator.userActivation) : "Not available"}
|
|
51
|
+
`);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
// silently fail
|
|
55
|
+
sendLogToServer("error", `Error during initial log: ${e.message}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
window.addEventListener('error', (event) => {
|
|
59
|
+
const errorMessage = event.error ? event.error.stack || event.error.message : event.message;
|
|
60
|
+
sendLogToServer("error", errorMessage);
|
|
61
|
+
});
|
|
62
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
63
|
+
const reason = event.reason ? event.reason.stack || event.reason.message : "Unhandled rejection without reason";
|
|
64
|
+
sendLogToServer("error", `Unhandled promise rejection: ${reason}`);
|
|
65
|
+
});
|
|
66
|
+
window.addEventListener('beforeunload', () => {
|
|
67
|
+
sendLogToServer("internal", "Page is unloading");
|
|
68
|
+
});
|
|
69
|
+
document.addEventListener('visibilitychange', () => {
|
|
70
|
+
console.log("Visibility changed:", document.visibilityState);
|
|
71
|
+
if (document.visibilityState === 'hidden') {
|
|
72
|
+
sendLogToServer("internal", "Page is hidden");
|
|
73
|
+
}
|
|
74
|
+
else if (document.visibilityState === 'visible') {
|
|
75
|
+
sendLogToServer("internal", "Page is visible again");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
sendLogToServer("internal", `Page visibility changed to ${document.visibilityState}`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
window.addEventListener("focus", () => {
|
|
82
|
+
sendLogToServer("internal", "Page gained focus");
|
|
83
|
+
});
|
|
84
|
+
window.addEventListener("blur", () => {
|
|
85
|
+
sendLogToServer("internal", "Page lost focus");
|
|
86
|
+
});
|
|
87
|
+
window.addEventListener('load', () => {
|
|
88
|
+
sendLogToServer("internal", "Page fully loaded");
|
|
89
|
+
});
|
|
90
|
+
window.addEventListener('DOMContentLoaded', () => {
|
|
91
|
+
sendLogToServer("internal", "DOM fully loaded and parsed");
|
|
92
|
+
});
|
|
93
|
+
window.addEventListener('online', () => {
|
|
94
|
+
sendLogToServer("internal", "Browser is online");
|
|
95
|
+
});
|
|
96
|
+
window.addEventListener('offline', () => {
|
|
97
|
+
sendLogToServer("warn", "Browser is offline");
|
|
98
|
+
});
|
|
99
|
+
window.addEventListener('resize', () => {
|
|
100
|
+
sendLogToServer("internal", `Window resized to ${window.innerWidth}x${window.innerHeight}px`);
|
|
101
|
+
});
|
|
102
|
+
window.addEventListener('orientationchange', () => {
|
|
103
|
+
sendLogToServer("internal", `Orientation changed to ${screen.orientation.type}`);
|
|
104
|
+
});
|
|
105
|
+
window.addEventListener('fullscreenchange', () => {
|
|
106
|
+
if (document.fullscreenElement) {
|
|
107
|
+
sendLogToServer("internal", "Entered fullscreen mode");
|
|
108
|
+
} else {
|
|
109
|
+
sendLogToServer("internal", "Exited fullscreen mode");
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
// url change event
|
|
115
|
+
window.addEventListener('hashchange', () => {
|
|
116
|
+
sendLogToServer("internal", `URL hash changed to ${location.hash}`);
|
|
117
|
+
});
|
|
118
|
+
window.addEventListener('popstate', () => {
|
|
119
|
+
sendLogToServer("internal", `History state changed: ${JSON.stringify(history.state)}`);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
}
|
|
@@ -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,30 @@
|
|
|
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
|
+
console.log("[needle-materialx-loader] Adding MaterialX import to main.ts");
|
|
24
|
+
code = materialx_import_chunk + "\n" + code;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -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();
|
|
@@ -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);
|