@needle-tools/materialx 1.0.0-next.1935162 → 1.0.0-next.2fb4497

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.
Files changed (2) hide show
  1. package/package.json +10 -3
  2. package/src/materialx.ts +28 -21
package/package.json CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
- "version": "1.0.0-next.1935162",
3
+ "version": "1.0.0-next.2fb4497",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
- "dependencies": {},
6
+ "exports": {
7
+ ".": {
8
+ "import": "./index.ts",
9
+ "require": "./index.js"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
7
13
  "peerDependencies": {
8
14
  "@needle-tools/engine": "4.x",
9
15
  "three": "npm:@needle-tools/three@^0.169.5"
10
16
  },
11
17
  "devDependencies": {
12
18
  "@needle-tools/engine": "4.x",
19
+ "@types/three": "0.169.0",
13
20
  "three": "npm:@needle-tools/three@^0.169.5",
14
- "@types/three": "0.169.0"
21
+ "vite": "^7.0.3"
15
22
  },
16
23
  "publishConfig": {
17
24
  "access": "public",
package/src/materialx.ts CHANGED
@@ -5,25 +5,6 @@ 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 url = new URL(`../bin/${path}?url`, import.meta.url);
17
- const correctPath = url.href;
18
- if (debug) console.debug("MaterialX locateFile resolved:", correctPath, { url, meta_url: import.meta.url });
19
- return correctPath;
20
- }
21
- return scriptDirectory + path;
22
- },
23
- // Add buffer allocation to handle the data file properly
24
- wasmBinary: null,
25
- wasmMemory: null
26
- };
27
8
 
28
9
  // Global MaterialX module instance - initialized lazily
29
10
  export const state = new class {
@@ -41,7 +22,6 @@ export const state = new class {
41
22
  }
42
23
  }
43
24
 
44
-
45
25
  // Initialize MaterialX WASM module lazily
46
26
  export async function initializeMaterialX(): Promise<void> {
47
27
  if (state.materialXInitPromise) {
@@ -51,7 +31,34 @@ export async function initializeMaterialX(): Promise<void> {
51
31
  if (state.materialXModule) return; // Already initialized
52
32
  if (debug) console.log("Initializing MaterialX WASM module...");
53
33
  try {
54
- const module = await MaterialX(materialXConfig);
34
+
35
+ const urls = await Promise.all([
36
+ /** @ts-ignore */
37
+ import(`../bin/JsMaterialXCore.wasm?url`),
38
+ /** @ts-ignore */
39
+ import(`../bin/JsMaterialXGenShader.wasm?url`),
40
+ /** @ts-ignore */
41
+ import(`../bin/JsMaterialXGenShader.data?url`),
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
+ });
55
62
  if (debug) console.log("MaterialXLoader module loaded", module);
56
63
  state.materialXModule = module;
57
64