@needle-tools/materialx 1.0.0-next.12f185d → 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 +1 -1
  2. package/src/materialx.ts +28 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
- "version": "1.0.0-next.12f185d",
3
+ "version": "1.0.0-next.2fb4497",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "exports": {
package/src/materialx.ts CHANGED
@@ -5,42 +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
- // @ts-ignore
9
- import coreWasmUrl from "../bin/JsMaterialXCore.wasm?url";
10
- // @ts-ignore
11
- import shaderWasmUrl from "../bin/JsMaterialXGenShader.wasm?url";
12
- // @ts-ignore
13
- import shaderDataUrl from "../bin/JsMaterialXGenShader.data?url&inline";
14
-
15
-
16
- // Configure MaterialX with the correct path for its data files
17
- const materialXConfig = {
18
- locateFile: (path: string, scriptDirectory: string) => {
19
- if (debug) console.debug("MaterialX locateFile called:", { path, scriptDirectory });
20
-
21
- // Return the correct path for MaterialX data files
22
- if (path.endsWith('.data') || path.endsWith('.wasm')) {
23
- if(path.includes("JsMaterialXCore.wasm")) {
24
- return coreWasmUrl; // Use the URL for the core WASM file
25
- }
26
- else if (path.includes("JsMaterialXGenShader.wasm")) {
27
- return shaderWasmUrl; // Use the URL for the shader WASM file
28
- }
29
- else if (path.includes("JsMaterialXGenShader.data")) {
30
- return shaderDataUrl; // Use the URL for the shader data file
31
- }
32
- // For Vite dev server, we need to use the correct module path
33
- // const url = new URL(`../bin/${path}?url`, import.meta.url);
34
- // const correctPath = url.href;
35
- // if (debug) console.debug("MaterialX locateFile resolved:", correctPath, { url, meta_url: import.meta.url });
36
- // return correctPath;
37
- }
38
- return scriptDirectory + path;
39
- },
40
- // Add buffer allocation to handle the data file properly
41
- wasmBinary: null,
42
- wasmMemory: null
43
- };
44
8
 
45
9
  // Global MaterialX module instance - initialized lazily
46
10
  export const state = new class {
@@ -58,7 +22,6 @@ export const state = new class {
58
22
  }
59
23
  }
60
24
 
61
-
62
25
  // Initialize MaterialX WASM module lazily
63
26
  export async function initializeMaterialX(): Promise<void> {
64
27
  if (state.materialXInitPromise) {
@@ -68,7 +31,34 @@ export async function initializeMaterialX(): Promise<void> {
68
31
  if (state.materialXModule) return; // Already initialized
69
32
  if (debug) console.log("Initializing MaterialX WASM module...");
70
33
  try {
71
- 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
+ });
72
62
  if (debug) console.log("MaterialXLoader module loaded", module);
73
63
  state.materialXModule = module;
74
64