@needle-tools/materialx 1.0.0-next.ed2b37f → 1.0.0

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 CHANGED
@@ -1,20 +1 @@
1
- # Needle MaterialX
2
-
3
- ## How to use
4
-
5
- To use with Needle Engine simply import the module
6
-
7
- ```ts
8
- import "@needle-tools/materialx"
9
- ```
10
-
11
- <br />
12
-
13
- # Contact ✒️
14
- <b>[🌵 Needle](https://needle.tools)</b> •
15
- [Github](https://github.com/needle-tools) •
16
- [Twitter](https://twitter.com/NeedleTools) •
17
- [Discord](https://discord.needle.tools) •
18
- [Forum](https://forum.needle.tools) •
19
- [Youtube](https://www.youtube.com/@needle-tools)
20
1
 
package/bin/README.md ADDED
@@ -0,0 +1,5 @@
1
+ Source: https://github.com/AcademySoftwareFoundation/MaterialX/tree/gh-pages
2
+
3
+ Edits:
4
+
5
+ - `JsMaterialXGenShader.js` added `export default MaterialX;` at bottom
package/package.json CHANGED
@@ -1,24 +1,17 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
- "version": "1.0.0-next.ed2b37f",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
- "exports": {
7
- ".": {
8
- "import": "./index.ts",
9
- "require": "./index.js"
10
- },
11
- "./package.json": "./package.json"
12
- },
6
+ "dependencies": {},
13
7
  "peerDependencies": {
14
8
  "@needle-tools/engine": "4.x",
15
9
  "three": "npm:@needle-tools/three@^0.169.5"
16
10
  },
17
11
  "devDependencies": {
18
12
  "@needle-tools/engine": "4.x",
19
- "@types/three": "0.169.0",
20
13
  "three": "npm:@needle-tools/three@^0.169.5",
21
- "vite": "^7.0.3"
14
+ "@types/three": "0.169.0"
22
15
  },
23
16
  "publishConfig": {
24
17
  "access": "public",
package/src/materialx.ts CHANGED
@@ -5,6 +5,24 @@ import { renderPMREMToEquirect } from "./textureHelper.js";
5
5
  import { Light, MeshBasicMaterial, Object3D, PMREMGenerator } from "three";
6
6
  import { registerLights } from "./helper.js";
7
7
 
8
+ // Configure MaterialX with the correct path for its data files
9
+ const materialXConfig = {
10
+ locateFile: (path: string, scriptDirectory: string) => {
11
+ if (debug) console.debug("MaterialX locateFile called:", { path, scriptDirectory });
12
+
13
+ // Return the correct path for MaterialX data files
14
+ if (path.endsWith('.data') || path.endsWith('.wasm')) {
15
+ // For Vite dev server, we need to use the correct module path
16
+ const correctPath = new URL(`../bin/${path}`, import.meta.url).href;
17
+ if (debug) console.log("Resolved path:", correctPath);
18
+ return correctPath;
19
+ }
20
+ return scriptDirectory + path;
21
+ },
22
+ // Add buffer allocation to handle the data file properly
23
+ wasmBinary: null,
24
+ wasmMemory: null
25
+ };
8
26
 
9
27
  // Global MaterialX module instance - initialized lazily
10
28
  export const state = new class {
@@ -22,6 +40,7 @@ export const state = new class {
22
40
  }
23
41
  }
24
42
 
43
+
25
44
  // Initialize MaterialX WASM module lazily
26
45
  export async function initializeMaterialX(): Promise<void> {
27
46
  if (state.materialXInitPromise) {
@@ -31,34 +50,7 @@ export async function initializeMaterialX(): Promise<void> {
31
50
  if (state.materialXModule) return; // Already initialized
32
51
  if (debug) console.log("Initializing MaterialX WASM module...");
33
52
  try {
34
-
35
- const urls: Array<string> = await Promise.all([
36
- /** @ts-ignore */
37
- import(`../bin/JsMaterialXCore.wasm?url`).then(m => m.default || m),
38
- /** @ts-ignore */
39
- import(`../bin/JsMaterialXGenShader.wasm?url`).then(m => m.default || m),
40
- /** @ts-ignore */
41
- import(`../bin/JsMaterialXGenShader.data.txt?url`).then(m => m.default || m),
42
- ]);
43
- const [JsMaterialXCore, JsMaterialXGenShader, JsMaterialXGenShader_data] = urls;
44
-
45
- const module = await MaterialX({
46
- locateFile: (path: string, scriptDirectory: string) => {
47
- if (debug) console.debug("MaterialX locateFile called:", { path, scriptDirectory });
48
-
49
- if (path.includes("JsMaterialXCore.wasm")) {
50
- return JsMaterialXCore; // Use the URL for the core WASM file
51
- }
52
- else if (path.includes("JsMaterialXGenShader.wasm")) {
53
- return JsMaterialXGenShader; // Use the URL for the shader WASM file
54
- }
55
- else if (path.includes("JsMaterialXGenShader.data")) {
56
- return JsMaterialXGenShader_data; // Use the URL for the shader data file
57
- }
58
-
59
- return scriptDirectory + path;
60
- },
61
- });
53
+ const module = await MaterialX(materialXConfig);
62
54
  if (debug) console.log("MaterialXLoader module loaded", module);
63
55
  state.materialXModule = module;
64
56
 
@@ -72,15 +64,15 @@ export async function initializeMaterialX(): Promise<void> {
72
64
  tempDoc.setDataLibrary(state.materialXStdLib);
73
65
 
74
66
  // Initialize basic lighting with default light rig
75
- // const defaultLightRigXml = `<?xml version="1.0"?>
76
- // <materialx version="1.39">
77
- // <!-- Default directional light -->
78
- // <directional_light name="default_light" type="lightshader">
79
- // <input name="direction" type="vector3" value="0.0, -1.0, -0.5" />
80
- // <input name="color" type="color3" value="1.0, 1.0, 1.0" />
81
- // <input name="intensity" type="float" value="1.0" />
82
- // </directional_light>
83
- // </materialx>`;
67
+ const defaultLightRigXml = `<?xml version="1.0"?>
68
+ <materialx version="1.39">
69
+ <!-- Default directional light -->
70
+ <directional_light name="default_light" type="lightshader">
71
+ <input name="direction" type="vector3" value="0.0, -1.0, -0.5" />
72
+ <input name="color" type="color3" value="1.0, 1.0, 1.0" />
73
+ <input name="intensity" type="float" value="1.0" />
74
+ </directional_light>
75
+ </materialx>`;
84
76
 
85
77
  // This prewarms the shader generation context to have all light types
86
78
  await registerLights(state.materialXModule, [], state.materialXGenContext);