@needle-tools/materialx 1.0.0-next.5e016a7 → 1.0.0-next.834eeec

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 +1,20 @@
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)
1
20
 
package/package.json CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
- "version": "1.0.0-next.5e016a7",
3
+ "version": "1.0.0-next.834eeec",
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/index.ts CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  const getMaterialXEnvironment = () => state.materialXEnvironment;
4
4
 
5
- export { initializeMaterialX, getMaterialXEnvironment };
5
+ export { initializeMaterialX, getMaterialXEnvironment };
6
+ export { needleMaterialX } from "./vite/index.js";
package/src/materialx.ts CHANGED
@@ -5,24 +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 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
- };
26
8
 
27
9
  // Global MaterialX module instance - initialized lazily
28
10
  export const state = new class {
@@ -40,7 +22,6 @@ export const state = new class {
40
22
  }
41
23
  }
42
24
 
43
-
44
25
  // Initialize MaterialX WASM module lazily
45
26
  export async function initializeMaterialX(): Promise<void> {
46
27
  if (state.materialXInitPromise) {
@@ -50,7 +31,34 @@ export async function initializeMaterialX(): Promise<void> {
50
31
  if (state.materialXModule) return; // Already initialized
51
32
  if (debug) console.log("Initializing MaterialX WASM module...");
52
33
  try {
53
- const module = await MaterialX(materialXConfig);
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
+ });
54
62
  if (debug) console.log("MaterialXLoader module loaded", module);
55
63
  state.materialXModule = module;
56
64
 
@@ -64,15 +72,15 @@ export async function initializeMaterialX(): Promise<void> {
64
72
  tempDoc.setDataLibrary(state.materialXStdLib);
65
73
 
66
74
  // Initialize basic lighting with default light rig
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>`;
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>`;
76
84
 
77
85
  // This prewarms the shader generation context to have all light types
78
86
  await registerLights(state.materialXModule, [], state.materialXGenContext);
@@ -1,36 +0,0 @@
1
- name: Release Workflow
2
- on:
3
- push:
4
- branches:
5
- - 'release/stable'
6
- - 'release/next'
7
- - 'release/experimental'
8
-
9
- jobs:
10
- run-release-script:
11
- runs-on: ubuntu-latest
12
- timeout-minutes: 5
13
- defaults:
14
- run:
15
- working-directory: ./
16
- steps:
17
- - name: Checkout code
18
- uses: actions/checkout@v4
19
-
20
- - name: Setup Node.js
21
- uses: actions/setup-node@v4
22
- with:
23
- node-version: '22'
24
-
25
- - name: Install dependencies
26
- run: npm ci
27
-
28
- - name: Publish to npm (stable branch)
29
- if: startsWith(github.ref_name, 'release/stable')
30
- run: npx --yes needle-publish-helper@stable publish "." --webhook "${{ secrets.DISCORD_WEBHOOK }}" --access-token "${{ secrets.NPM_TOKEN }}" --tag "stable" --create-tag "release/"
31
-
32
- - name: Publish to npm (next and experimental branches)
33
- if: ${{ !startsWith(github.ref_name, 'release/stable') }}
34
- run: npx --yes needle-publish-helper@stable publish "." --webhook "${{ secrets.DISCORD_WEBHOOK }}" --access-token "${{ secrets.NPM_TOKEN }}" --tag "${{ github.ref_name }}" --version+tag --version+hash --create-tag "release/"
35
-
36
-
package/bin/README.md DELETED
@@ -1,5 +0,0 @@
1
- Source: https://github.com/AcademySoftwareFoundation/MaterialX/tree/gh-pages
2
-
3
- Edits:
4
-
5
- - `JsMaterialXGenShader.js` added `export default MaterialX;` at bottom
@@ -1,18 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "."
5
- },
6
- {
7
- "name": "Needle",
8
- "path": "./node_modules/@needle-tools"
9
- }
10
- ],
11
- "settings": {
12
- "files.exclude": {
13
- "**/.git": true,
14
- "**/.DS_Store": true,
15
- "**/*.meta": true
16
- }
17
- }
18
- }