@needle-tools/materialx 1.4.4-next.d2335d8 → 1.4.5
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/README.md +34 -26
- package/package.json +8 -2
- package/src/loader/loader.three.js +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
# Needle MaterialX
|
|
1
|
+
# Needle MaterialX – MaterialX Materials for three.js & the Web
|
|
2
2
|
|
|
3
|
-
Web runtime
|
|
3
|
+
Web runtime for [MaterialX](https://materialx.org/) materials in [Needle Engine](https://needle.tools) and [three.js](https://threejs.org/). Renders physically based MaterialX shaders in the browser using WebAssembly — load `.mtlx` files or glTF assets with the `NEEDLE_materials_mtlx` extension.
|
|
4
|
+
|
|
5
|
+
- MaterialX to WebGL/WebGPU shader generation via WASM
|
|
6
|
+
- glTF extension for embedding MaterialX materials in `.glb`/`.gltf` files
|
|
7
|
+
- Experimental support for loading raw MaterialX XML (`.mtlx`) files
|
|
8
|
+
- Works standalone with three.js or as a Needle Engine module
|
|
4
9
|
|
|
5
10
|
[Learn more in the Needle Engine documentation](https://engine.needle.tools/docs/how-to-guides/export/materialx.html)
|
|
6
11
|
|
|
7
|
-
[](https://engine.needle.tools/samples/material-x)
|
|
12
|
+
[](https://engine.needle.tools/samples/material-x)
|
|
8
13
|
|
|
9
14
|
|
|
10
15
|
## Installation
|
|
@@ -15,9 +20,31 @@ Web runtime support to load and display MaterialX materials in Needle Engine and
|
|
|
15
20
|
|
|
16
21
|
## How to use
|
|
17
22
|
|
|
23
|
+
### Use with Needle Engine
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { useNeedleMaterialX } from "@needle-tools/materialx/needle";
|
|
27
|
+
// Simply call this function in global scope as soon as possible
|
|
28
|
+
useNeedleMaterialX();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Use with three.js
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { useNeedleMaterialX } from "@needle-tools/materialx";
|
|
35
|
+
// Call the function with your GLTFLoader instance
|
|
36
|
+
useNeedleMaterialX(<yourGltfLoaderInstance>);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## WASM
|
|
40
|
+
|
|
41
|
+
### Default (CDN)
|
|
42
|
+
|
|
43
|
+
By default, MaterialX WASM files are loaded from the Needle CDN at `https://cdn.needle.tools/static/materialx/<version>/`. No configuration needed.
|
|
44
|
+
|
|
18
45
|
### Custom WASM Location
|
|
19
46
|
|
|
20
|
-
|
|
47
|
+
You can override the WASM location by setting `globalThis.NEEDLE_MATERIALX_LOCATION` **before** MaterialX loads (for example in global scope in a root script).
|
|
21
48
|
|
|
22
49
|
#### Package-local files
|
|
23
50
|
|
|
@@ -43,27 +70,8 @@ To use a custom base URL (for self-hosted deployments, air-gapped environments,
|
|
|
43
70
|
globalThis.NEEDLE_MATERIALX_LOCATION = "/assets/materialx/";
|
|
44
71
|
```
|
|
45
72
|
|
|
46
|
-
The value must end with a trailing slash (`/`).
|
|
47
|
-
|
|
48
|
-
#### Default (CDN)
|
|
49
|
-
|
|
50
|
-
By default, MaterialX WASM files are loaded from the Needle CDN. No configuration needed.
|
|
51
|
-
|
|
52
|
-
### Use with Needle Engine
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { useNeedleMaterialX } from "@needle-tools/materialx/needle";
|
|
56
|
-
// Simply call this function in global scope as soon as possible
|
|
57
|
-
useNeedleMaterialX();
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Use with three.js
|
|
73
|
+
IMPORTANT: The value must end with a trailing slash (`/`).
|
|
61
74
|
|
|
62
|
-
```ts
|
|
63
|
-
import { useNeedleMaterialX } from "@needle-tools/materialx";
|
|
64
|
-
// Call the function with your GLTFLoader instance
|
|
65
|
-
useNeedleMaterialX(<yourGltfLoaderInstance>);
|
|
66
|
-
```
|
|
67
75
|
|
|
68
76
|
## glTF Extension: NEEDLE_materials_mtlx
|
|
69
77
|
|
|
@@ -93,7 +101,7 @@ Materials can also contain the `NEEDLE_materials_mtlx` extension, which referenc
|
|
|
93
101
|
"name": "Perforated_Metal_normal"
|
|
94
102
|
}
|
|
95
103
|
],
|
|
96
|
-
"shaders": [
|
|
104
|
+
"shaders": [] ← optional
|
|
97
105
|
}
|
|
98
106
|
]
|
|
99
107
|
}
|
|
@@ -124,7 +132,7 @@ Materials can also contain the `NEEDLE_materials_mtlx` extension, which referenc
|
|
|
124
132
|
# Contact ✒️
|
|
125
133
|
<b>[🌵 Needle](https://needle.tools)</b> •
|
|
126
134
|
[Github](https://github.com/needle-tools) •
|
|
127
|
-
[
|
|
135
|
+
[X](https://x.com/NeedleTools) •
|
|
128
136
|
[Discord](https://discord.needle.tools) •
|
|
129
137
|
[Forum](https://forum.needle.tools) •
|
|
130
138
|
[Youtube](https://www.youtube.com/@needle-tools)
|
package/package.json
CHANGED
|
@@ -1,6 +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.4.5",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"types": "index.d.ts",
|
|
@@ -57,7 +58,12 @@
|
|
|
57
58
|
"threejs",
|
|
58
59
|
"three.js",
|
|
59
60
|
"webgl",
|
|
61
|
+
"webgpu",
|
|
60
62
|
"mtlx",
|
|
61
|
-
"rendering"
|
|
63
|
+
"rendering",
|
|
64
|
+
"gltf",
|
|
65
|
+
"pbr",
|
|
66
|
+
"3d",
|
|
67
|
+
"wasm"
|
|
62
68
|
]
|
|
63
69
|
}
|
|
@@ -338,7 +338,7 @@ export async function createMaterialXMaterial(mtlx, materialNodeNameOrIndex, loa
|
|
|
338
338
|
|
|
339
339
|
} catch (error) {
|
|
340
340
|
// This is a wasm error (an int) that we need to resolve
|
|
341
|
-
console.error(`[MaterialX v${VERSION}] Error creating MaterialX material (${materialNodeNameOrIndex}):`, error, `\n→ This may be caused by invalid MaterialX XML data or a problem in the shader generation process. Please provide the
|
|
341
|
+
console.error(`[MaterialX v${VERSION}] Error creating MaterialX material (${materialNodeNameOrIndex}):`, typeof error === "number" ? `CODE ${error}` : error, `\n→ This may be caused by invalid MaterialX XML data or a problem in the shader generation process. Please provide the MaterialX code below when reporting an issue:\n`, mtlx);
|
|
342
342
|
// Return a fallback material with stored MaterialX data
|
|
343
343
|
const fallbackMaterial = new MeshStandardMaterial();
|
|
344
344
|
fallbackMaterial.color.set(0xff00ff);
|