@needle-tools/materialx 1.7.0-next.57183d6 → 1.7.0-next.8333b4d
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 +0 -3
- package/bin/JsMaterialXCore.js +1 -1
- package/bin/JsMaterialXGenShader.js +1 -1
- package/package.json +2 -5
- package/src/constants.js +4 -4
- package/src/materialx.helper.js +4 -15
- package/src/materialx.js +1 -17
- package/src/utils.js +9 -16
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/materialx",
|
|
3
3
|
"description": "MaterialX material support for three.js and Needle Engine – render physically based MaterialX shaders in the browser via WebAssembly",
|
|
4
|
-
"version": "1.7.0-next.
|
|
4
|
+
"version": "1.7.0-next.8333b4d",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
7
7
|
"main": "index.js",
|
|
@@ -27,10 +27,7 @@
|
|
|
27
27
|
"three": ">=0.160.0"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"test": "node --import=./tests/unit/register-json-loader.js --test tests/unit/**/*.test.js"
|
|
31
|
-
"test:runtime:node": "node tests/runtime/materialx-runtime-smoke.mjs",
|
|
32
|
-
"test:runtime:deno": "deno run --allow-read --no-lock --node-modules-dir=auto tests/runtime/materialx-runtime-smoke.mjs",
|
|
33
|
-
"test:runtime:bun": "bun tests/runtime/materialx-runtime-smoke.mjs"
|
|
30
|
+
"test": "node --import=./tests/unit/register-json-loader.js --test tests/unit/**/*.test.js"
|
|
34
31
|
},
|
|
35
32
|
"devDependencies": {
|
|
36
33
|
"@needle-tools/engine": "4.x",
|
package/src/constants.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
import pkg from '../package.json'
|
|
1
|
+
// Bare JSON import works in bundlers (Vite, Webpack, Rollup) and keeps the
|
|
2
|
+
// runtime version tied to package.json. Node.js 22+ requires JSON import
|
|
3
|
+
// attributes, so unit tests use tests/unit/register-json-loader.js.
|
|
4
|
+
import pkg from '../package.json';
|
|
5
5
|
export const VERSION = pkg.version;
|
package/src/materialx.helper.js
CHANGED
|
@@ -71,22 +71,10 @@ function fromMatrix(matrix, dimension) {
|
|
|
71
71
|
* @property {(path: string) => Promise<THREE.Texture | null | void>} getTexture - Get a texture by path
|
|
72
72
|
*/
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
* @param {string} src
|
|
76
|
-
* @returns {HTMLImageElement | { src: string }}
|
|
77
|
-
*/
|
|
78
|
-
function createPortableImage(src) {
|
|
79
|
-
if (typeof Image !== 'undefined') {
|
|
80
|
-
const image = new Image();
|
|
81
|
-
image.src = src;
|
|
82
|
-
return image;
|
|
83
|
-
}
|
|
84
|
-
return { src };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
74
|
const defaultTexture = new THREE.Texture();
|
|
88
75
|
defaultTexture.needsUpdate = true;
|
|
89
|
-
defaultTexture.image =
|
|
76
|
+
defaultTexture.image = new Image();
|
|
77
|
+
defaultTexture.image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRFr6+vGqg52AAAAAxJREFUeJxjZGBEgQAAWAAJLpjsTQAAAABJRU5ErkJggg=="
|
|
90
78
|
// defaultTexture.image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAB5QTFRFAAAABAQEw8PD////v7+/vb29Xl5eQEBA+/v7PDw8GPBYkgAAAB1JREFUeJxjZGBgYFQSABIUMlxgDGMGBtaIAnIZAKwQCSDYUEZEAAAAAElFTkSuQmCC";
|
|
91
79
|
// defaultTexture.wrapS = THREE.RepeatWrapping;
|
|
92
80
|
// defaultTexture.wrapT = THREE.RepeatWrapping;
|
|
@@ -96,7 +84,8 @@ defaultTexture.image = createPortableImage("data:image/png;base64,iVBORw0KGgoAAA
|
|
|
96
84
|
|
|
97
85
|
const defaultNormalTexture = new THREE.Texture();
|
|
98
86
|
defaultNormalTexture.needsUpdate = true;
|
|
99
|
-
defaultNormalTexture.image =
|
|
87
|
+
defaultNormalTexture.image = new Image();
|
|
88
|
+
defaultNormalTexture.image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIBAMAAAA2IaO4AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAABJQTFRFgYH4gIH4gYH3gIH3gIH5gID4m94ORAAAADFJREFUeJxjZBBkfMdo9P/BB0aBj/8FGB0ufghgFGT4r8wo+P8rD2Pgo3sMjIz8jAwAMLoN0ZjS5hgAAAAASUVORK5CYII=";
|
|
100
89
|
|
|
101
90
|
/**
|
|
102
91
|
* @param {string} key
|
package/src/materialx.js
CHANGED
|
@@ -17,19 +17,6 @@ function isTextureLike(value) {
|
|
|
17
17
|
return !!value && typeof value === "object" && /** @type {{ isTexture?: unknown }} */(value).isTexture === true;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function isNodeRuntime() {
|
|
21
|
-
return !!globalThis.process?.versions?.node && globalThis.process?.type !== "renderer";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function getNodePackageAssetPaths() {
|
|
25
|
-
const { fileURLToPath } = await import(/* @vite-ignore */ "node:url");
|
|
26
|
-
return [
|
|
27
|
-
fileURLToPath(new URL("../bin/JsMaterialXCore.wasm", import.meta.url)),
|
|
28
|
-
fileURLToPath(new URL("../bin/JsMaterialXGenShader.wasm", import.meta.url)),
|
|
29
|
-
fileURLToPath(new URL("../bin/JsMaterialXGenShader.data.txt", import.meta.url)),
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
20
|
|
|
34
21
|
/**
|
|
35
22
|
* Preloads the MaterialX WebAssembly module.
|
|
@@ -82,10 +69,7 @@ export async function ready() {
|
|
|
82
69
|
|
|
83
70
|
const location = globalThis.NEEDLE_MATERIALX_LOCATION;
|
|
84
71
|
|
|
85
|
-
if (
|
|
86
|
-
urls = await getNodePackageAssetPaths();
|
|
87
|
-
}
|
|
88
|
-
else if (location === "package" || location === "bin/" || location === "./bin/" || location === "../bin/") {
|
|
72
|
+
if (location === "package" || location === "bin/" || location === "./bin/" || location === "../bin/") {
|
|
89
73
|
// Use local files from the @needle-tools/materialx npm package.
|
|
90
74
|
// Vite's ?url suffix copies these files to the output directory
|
|
91
75
|
// and returns their URL automatically — no CDN download needed.
|
package/src/utils.js
CHANGED
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
* @returns {boolean|string} Parameter value or false if not found
|
|
8
8
|
*/
|
|
9
9
|
export function getParam(name) {
|
|
10
|
-
const
|
|
11
|
-
if (!search) return false;
|
|
12
|
-
const urlParams = new URLSearchParams(search);
|
|
10
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
13
11
|
const param = urlParams.get(name);
|
|
14
12
|
if (param == null || param === "0" || param === "false") return false;
|
|
15
13
|
if (param === "") return true;
|
|
@@ -37,26 +35,22 @@ export function getFrame() {
|
|
|
37
35
|
return frame;
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
const
|
|
41
|
-
|| globalThis.window?.performance
|
|
42
|
-
|| /** @type {any} */ (globalThis.window)?.webkitPerformance
|
|
43
|
-
|| /** @type {any} */ (globalThis.window)?.mozPerformance
|
|
44
|
-
|| { now: () => Date.now() };
|
|
38
|
+
const performance = window.performance || /** @type {any} */ (window).webkitPerformance || /** @type {any} */ (window).mozPerformance;
|
|
45
39
|
|
|
46
40
|
function updateTime() {
|
|
47
|
-
time =
|
|
41
|
+
time = performance.now() / 1000; // Convert to seconds
|
|
48
42
|
frame++;
|
|
49
|
-
|
|
43
|
+
window.requestAnimationFrame(updateTime);
|
|
50
44
|
}
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
window.requestAnimationFrame(updateTime);
|
|
53
47
|
|
|
54
48
|
|
|
55
49
|
|
|
56
50
|
|
|
57
51
|
export async function waitForNetworkIdle() {
|
|
58
|
-
if (typeof
|
|
59
|
-
return new Promise(res =>
|
|
52
|
+
if (typeof requestIdleCallback !== "undefined") {
|
|
53
|
+
return new Promise(res => requestIdleCallback(res));
|
|
60
54
|
}
|
|
61
55
|
else {
|
|
62
56
|
console.debug("[MaterialX] Can not wait for network idle, using fallback");
|
|
@@ -67,6 +61,5 @@ export async function waitForNetworkIdle() {
|
|
|
67
61
|
|
|
68
62
|
export function isDevEnvironment() {
|
|
69
63
|
// check if we're in localhost or using an ip address
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
64
|
+
return window.location.hostname === "localhost" || /^\d{1,3}(\.\d{1,3}){3}$/.test(window.location.hostname);
|
|
65
|
+
}
|