@needle-tools/materialx 1.2.1-next.343c31f → 1.2.1-next.bc1fa29

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/CHANGELOG.md CHANGED
@@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.2.1] - 2025-07-23
8
+ - Fix: error caused by scene.environment being null
9
+
7
10
  ## [1.2.0] - 2025-07-23
8
11
  - Add: Support to load raw MaterialX materials (from mtlx as XML)
9
12
  - Fix: Warn if tangents are missing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
- "version": "1.2.1-next.343c31f",
3
+ "version": "1.2.1-next.bc1fa29",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/index.d.ts CHANGED
@@ -9,3 +9,6 @@ declare const Experimental_API: {
9
9
  };
10
10
 
11
11
  export { Experimental_API };
12
+
13
+
14
+ export function preloadWasm(trigger: "immediately" | "network_idle"): Promise<void>;
package/src/index.js CHANGED
@@ -1,11 +1,38 @@
1
+ import { createMaterialXMaterial } from "./loader/loader.three.js";
2
+ import { ready } from "./materialx.js";
3
+ import { waitForNetworkIdle } from "./utils.js";
4
+
5
+
1
6
  export { ready } from "./materialx.js";
2
7
  export { MaterialXMaterial } from "./materialx.material.js";
3
8
  export { MaterialXLoader } from "./loader/loader.three.js";
4
9
 
5
- import { createMaterialXMaterial } from "./loader/loader.three.js";
6
10
 
11
+ /**
12
+ * Preloads the MaterialX WebAssembly module.
13
+ * @type {import("./index.js").preloadWasm}
14
+ */
15
+ export async function preloadWasm(trigger) {
16
+ if (trigger === "immediately") {
17
+ // Load the WASM module immediately
18
+ await ready();
19
+ } else if (trigger === "network_idle") {
20
+ // Wait for network to be idle before loading
21
+ await waitForNetworkIdle();
22
+ await ready();
23
+ }
24
+ }
25
+
26
+
27
+
28
+
29
+ /**
30
+ * Experimental API for creating MaterialX materials.
31
+ */
7
32
  const Experimental_API = {
8
33
  createMaterialXMaterial
9
34
  }
10
35
 
11
36
  export { Experimental_API }
37
+
38
+
@@ -91,6 +91,7 @@ export class MaterialXMaterial extends ShaderMaterial {
91
91
  // Patch fragmentShader
92
92
  const precision = init.parameters?.precision || "highp";
93
93
  vertexShader = vertexShader.replace(/precision mediump float;/g, `precision ${precision} float;`);
94
+ vertexShader = vertexShader.replace(/#define M_FLOAT_EPS 1e-8/g, precision === "highp" ? `#define M_FLOAT_EPS 1e-8` : `#define M_FLOAT_EPS 1e-3`);
94
95
  fragmentShader = fragmentShader.replace(/precision mediump float;/g, `precision ${precision} float;`);
95
96
  fragmentShader = fragmentShader.replace(/#define M_FLOAT_EPS 1e-8/g, precision === "highp" ? `#define M_FLOAT_EPS 1e-8` : `#define M_FLOAT_EPS 1e-3`);
96
97
 
package/src/utils.d.ts CHANGED
@@ -15,3 +15,6 @@ export function getTime(): number;
15
15
  * Get current frame number
16
16
  */
17
17
  export function getFrame(): number;
18
+
19
+
20
+ export function waitForNetworkIdle(): Promise<void>;
package/src/utils.js CHANGED
@@ -44,3 +44,16 @@ function updateTime() {
44
44
  }
45
45
 
46
46
  window.requestAnimationFrame(updateTime);
47
+
48
+
49
+
50
+
51
+ export async function waitForNetworkIdle() {
52
+ if (typeof requestIdleCallback !== "undefined") {
53
+ return new Promise(res => requestIdleCallback(res));
54
+ }
55
+ else {
56
+ console.debug("[MaterialX] Can not wait for network idle, using fallback");
57
+ return new Promise(res => setTimeout(res, 100)); // Fallback to a short delay
58
+ }
59
+ }
@@ -1,5 +1,7 @@
1
1
  import { WebGLRenderer, WebGLRenderTarget, Texture } from 'three';
2
2
 
3
+ export const whiteTexture: Texture;
4
+
3
5
  /**
4
6
  * Renders a PMREM environment map to an equirectangular texture with specified roughness
5
7
  */