@needle-tools/materialx 1.1.1-next.5900297 → 1.1.1-next.623fc20

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.1.1-next.5900297",
3
+ "version": "1.1.1-next.623fc20",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "exports": {
@@ -14,10 +14,19 @@ export type MaterialX_root_extension = {
14
14
  mtlx: string;
15
15
  /** MaterialX texture pointers */
16
16
  textures: Array<{ name: string, pointer: string }>;
17
+ shaders?: Array<{
18
+ /** The materialx node name */
19
+ name: string,
20
+ /** The original name of the shader */
21
+ originalName: string,
22
+ }>,
17
23
  }
18
24
 
19
25
  export type MaterialX_material_extension = {
20
- name: string; // Material name reference
26
+ /** The MaterialX material name */
27
+ name: string;
28
+ /** The index of the shader in the shaders array of the root extension. */
29
+ shader?: number;
21
30
  }
22
31
 
23
32
  type MaterialDefinition = {
@@ -240,8 +249,15 @@ export class MaterialXLoader implements GLTFLoaderPlugin {
240
249
 
241
250
  const shader = state.materialXGenerator.generate(elementName, renderableElement, state.materialXGenContext);
242
251
 
252
+ const rootExtension = this.materialX_root_data;
253
+
254
+ const shaderInfo = rootExtension && material_extension.shader !== undefined && material_extension.shader >= 0
255
+ ? rootExtension.shaders?.[material_extension.shader]
256
+ : null;
257
+
243
258
  const shaderMaterial = new MaterialXMaterial({
244
259
  name: material_extension.name,
260
+ shaderName: shaderInfo?.originalName || shaderInfo?.name || null,
245
261
  shader,
246
262
  context: this.context,
247
263
  parameters: {
@@ -256,9 +272,8 @@ export class MaterialXLoader implements GLTFLoaderPlugin {
256
272
  const filenameWithoutExt = url.split('/').pop()?.split('.').shift() || '';
257
273
 
258
274
  // Resolve the texture from the MaterialX root extension
259
- const ext = this.materialX_root_data;
260
- if (ext) {
261
- const textures = ext.textures || [];
275
+ if (rootExtension) {
276
+ const textures = rootExtension.textures || [];
262
277
  let index = -1;
263
278
  for (const texture of textures) {
264
279
  // Find the texture by name and use the pointer string to get the index
@@ -11,6 +11,7 @@ const worldViewPos = new Vector3();
11
11
 
12
12
  declare type MaterialXMaterialInitParameters = {
13
13
  name: string,
14
+ shaderName?: string | null, // Optional name of the shader
14
15
  shader: any,
15
16
  loaders: Loaders,
16
17
  context: MaterialXContext,
@@ -23,6 +24,9 @@ type Precision = "highp" | "mediump" | "lowp";
23
24
 
24
25
  export class MaterialXMaterial extends ShaderMaterial {
25
26
 
27
+ /** The original name of the shader */
28
+ readonly shaderName : string | null = null;
29
+
26
30
  copy(source: MaterialXMaterial): this {
27
31
  super.copy(source);
28
32
  this._context = source._context;
@@ -146,6 +150,7 @@ export class MaterialXMaterial extends ShaderMaterial {
146
150
  });
147
151
  this._context = init.context;
148
152
  this._shader = init.shader;
153
+ this.shaderName = init.shaderName || null;
149
154
 
150
155
  Object.assign(this.uniforms, {
151
156
  ...getUniformValues(init.shader.getStage('vertex'), init.loaders, searchPath),