@needle-tools/materialx 1.4.3 → 1.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -0,0 +1,3 @@
1
+ import pkg from '../package.json' with { type: 'json' };
2
+
3
+ export const VERSION = pkg.version;
@@ -3,6 +3,7 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
3
3
  import { ready, state } from "../materialx.js";
4
4
  import { debug } from "../utils.js";
5
5
  import { MaterialXMaterial } from "../materialx.material.js";
6
+ import { VERSION } from "../constants.js";
6
7
 
7
8
  /**
8
9
  * @import { MaterialX_root_extension, MaterialX_material_extension, MaterialXLoaderOptions } from "./loader.three.d.ts"
@@ -92,7 +93,6 @@ export class MaterialXLoader {
92
93
 
93
94
  /** @type {MaterialDefinition} */
94
95
  const materialDef = this.parser.json.materials?.[materialIndex];
95
- if (debug) console.debug("[MaterialX] extension found in material:", materialDef.extensions?.[this.name]);
96
96
 
97
97
  // Handle different types of MaterialX data
98
98
  /** @type {MaterialX_material_extension} */
@@ -101,6 +101,8 @@ export class MaterialXLoader {
101
101
  const materialX_root_data = this.materialX_root_data?.[documentIndex];
102
102
  const mtlx = materialX_root_data.mtlx || null;
103
103
 
104
+ if (debug) console.debug(`[MaterialX] extension found in material[${materialIndex}]:`, materialDef.extensions?.[this.name], "\n→ MTLX root data:", materialX_root_data);
105
+
104
106
  if (ext && mtlx) {
105
107
 
106
108
  /** @type {MaterialXMaterialOptions} */
@@ -336,7 +338,7 @@ export async function createMaterialXMaterial(mtlx, materialNodeNameOrIndex, loa
336
338
 
337
339
  } catch (error) {
338
340
  // This is a wasm error (an int) that we need to resolve
339
- console.error(`[MaterialX] Error creating MaterialX material (${materialNodeNameOrIndex}):`, error);
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);
340
342
  // Return a fallback material with stored MaterialX data
341
343
  const fallbackMaterial = new MeshStandardMaterial();
342
344
  fallbackMaterial.color.set(0xff00ff);
package/src/materialx.js CHANGED
@@ -4,6 +4,7 @@ import { renderPMREMToEquirect } from "./utils.texture.js";
4
4
  import { Light, Mesh, MeshBasicMaterial, Object3D, PlaneGeometry, PMREMGenerator, Scene, Texture, WebGLRenderer } from "three";
5
5
  import { registerLights, getLightData } from "./materialx.helper.js";
6
6
  import { whiteTexture } from "./utils.texture.js";
7
+ import { VERSION } from "./constants.js";
7
8
 
8
9
 
9
10
  /**
@@ -45,7 +46,7 @@ export async function ready() {
45
46
  }
46
47
  return state.materialXInitPromise = (async () => {
47
48
  if (state.materialXModule) return; // Already initialized
48
- if (debug) console.log("[MaterialX] Initializing WASM module...");
49
+ if (debug) console.log(`[MaterialX v${VERSION}] Initializing WASM module...`);
49
50
  try {
50
51
 
51
52
  // NOTE: This must be a plain string literal (not a template) so that the
@@ -61,11 +62,11 @@ export async function ready() {
61
62
  // Use local files from the @needle-tools/materialx npm package.
62
63
  // Vite's ?url suffix copies these files to the output directory
63
64
  // and returns their URL automatically — no CDN download needed.
64
- urls = await Promise.all([
65
+ urls = /** @type {string[]} */ (await Promise.all([
65
66
  import('../bin/JsMaterialXCore.wasm?url').then(m => m.default || m),
66
67
  import('../bin/JsMaterialXGenShader.wasm?url').then(m => m.default || m),
67
68
  import('../bin/JsMaterialXGenShader.data.txt?url').then(m => m.default || m),
68
- ]);
69
+ ]));
69
70
  }
70
71
  else if (location) {
71
72
  // Custom path: use as base URL for CDN or self-hosted files
@@ -143,9 +144,9 @@ export async function ready() {
143
144
  // This prewarms the shader generation context to have all light types
144
145
  await registerLights(state.materialXModule, state.materialXGenContext);
145
146
 
146
- if (debug) console.log("[MaterialX] Generator initialized successfully");
147
+ if (debug) console.log(`[MaterialX v${VERSION}] Generator initialized successfully`);
147
148
  } catch (error) {
148
- console.error("[MaterialX] Failed to load MaterialX module:", error);
149
+ console.error(`[MaterialX v${VERSION}] Failed to load MaterialX module:`, error);
149
150
  throw error;
150
151
  }
151
152
  })();