@needle-tools/materialx 1.1.1-next.714bc32 → 1.1.1-next.8e8afe1
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/bin/.gitattributes +4 -0
- package/{index.ts → index.d.ts} +1 -1
- package/index.js +2 -0
- package/{needle.ts → needle.d.ts} +1 -1
- package/needle.js +2 -0
- package/package.json +11 -8
- package/src/index.d.ts +11 -0
- package/src/{index.ts → index.js} +2 -4
- package/src/loader/loader.needle.d.ts +15 -0
- package/src/loader/loader.needle.js +62 -0
- package/src/loader/loader.three.d.ts +61 -0
- package/src/loader/{loader.three.ts → loader.three.js} +92 -82
- package/src/materialx.d.ts +60 -0
- package/src/materialx.helper.d.ts +31 -0
- package/src/{materialx.helper.ts → materialx.helper.js} +97 -63
- package/src/{materialx.ts → materialx.js} +109 -63
- package/src/materialx.material.d.ts +37 -0
- package/src/{materialx.material.ts → materialx.material.js} +70 -35
- package/src/utils.d.ts +17 -0
- package/src/{utils.ts → utils.js} +18 -5
- package/src/utils.texture.d.ts +13 -0
- package/src/{utils.texture.ts → utils.texture.js} +18 -17
- package/src/loader/loader.needle.ts +0 -43
package/{index.ts → index.d.ts}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./src/index.js";
|
|
2
|
-
export { useNeedleMaterialX } from "./src/loader/loader.three.js";
|
|
2
|
+
export { useNeedleMaterialX } from "./src/loader/loader.three.js";
|
package/index.js
ADDED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./src/index.js";
|
|
2
|
-
export { useNeedleMaterialX } from "./src/loader/loader.needle.js";
|
|
2
|
+
export { useNeedleMaterialX } from "./src/loader/loader.needle.js";
|
package/needle.js
ADDED
package/package.json
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/materialx",
|
|
3
|
-
"version": "1.1.1-next.
|
|
3
|
+
"version": "1.1.1-next.8e8afe1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "index.
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
|
-
"import": "./index.
|
|
9
|
-
"require": "./index.js"
|
|
9
|
+
"import": "./index.js",
|
|
10
|
+
"require": "./index.js",
|
|
11
|
+
"types": "./index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./needle": {
|
|
14
|
+
"import": "./needle.js",
|
|
15
|
+
"require": "./needle.js",
|
|
16
|
+
"types": "./needle.d.ts"
|
|
10
17
|
},
|
|
11
18
|
"./package.json": "./package.json",
|
|
12
19
|
"./codegen/register_types.ts": {
|
|
13
20
|
"import": "./codegen/register_types.ts",
|
|
14
21
|
"require": "./codegen/register_types.js"
|
|
15
|
-
},
|
|
16
|
-
"./needle": {
|
|
17
|
-
"import": "./needle.ts",
|
|
18
|
-
"require": "./needle.js"
|
|
19
22
|
}
|
|
20
23
|
},
|
|
21
24
|
"peerDependencies": {
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ready, type MaterialXContext } from "./materialx.js";
|
|
2
|
+
export { MaterialXMaterial } from "./materialx.material.js";
|
|
3
|
+
export { MaterialXLoader } from "./loader/loader.three.js";
|
|
4
|
+
|
|
5
|
+
import { createMaterialXMaterial } from "./loader/loader.three.js";
|
|
6
|
+
|
|
7
|
+
declare const Experimental_API: {
|
|
8
|
+
createMaterialXMaterial: typeof createMaterialXMaterial;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { Experimental_API };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
export { ready } from "./materialx.js";
|
|
2
2
|
export { MaterialXMaterial } from "./materialx.material.js";
|
|
3
3
|
export { MaterialXLoader } from "./loader/loader.three.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
import { createMaterialXMaterial } from "./loader/loader.three.js";
|
|
7
6
|
|
|
8
7
|
const Experimental_API = {
|
|
9
8
|
createMaterialXMaterial
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
export { Experimental_API }
|
|
11
|
+
export { Experimental_API }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Context, GLTF, INeedleGLTFExtensionPlugin } from "@needle-tools/engine";
|
|
2
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
3
|
+
import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
4
|
+
import { MaterialXLoader } from "./loader.three.js";
|
|
5
|
+
|
|
6
|
+
export declare class MaterialXLoaderPlugin implements INeedleGLTFExtensionPlugin {
|
|
7
|
+
readonly name: "MaterialXLoaderPlugin";
|
|
8
|
+
private loader: MaterialXLoader | null;
|
|
9
|
+
|
|
10
|
+
onImport(loader: GLTFLoader, url: string, context: Context): void;
|
|
11
|
+
onLoaded(url: string, gltf: GLTF, _context: Context): void;
|
|
12
|
+
onExport(_exporter: GLTFExporter, _context: Context): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export declare function useNeedleMaterialX(): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { addCustomExtensionPlugin, Context } from "@needle-tools/engine";
|
|
2
|
+
import { useNeedleMaterialX as _useNeedleMaterialX } from "./loader.three.js";
|
|
3
|
+
import { debug } from "../utils.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import("@needle-tools/engine").INeedleGLTFExtensionPlugin} INeedleGLTFExtensionPlugin
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MaterialX Loader Plugin for Needle Engine
|
|
11
|
+
* @implements {INeedleGLTFExtensionPlugin}
|
|
12
|
+
*/
|
|
13
|
+
export class MaterialXLoaderPlugin {
|
|
14
|
+
/** @readonly */
|
|
15
|
+
name = "MaterialXLoaderPlugin";
|
|
16
|
+
|
|
17
|
+
/** @type {import("./loader.three.d.ts").MaterialXLoader | null} */
|
|
18
|
+
loader = null;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {import('three/examples/jsm/loaders/GLTFLoader.js').GLTFLoader} loader
|
|
22
|
+
* @param {string} url
|
|
23
|
+
* @param {Context} context
|
|
24
|
+
*/
|
|
25
|
+
onImport = (loader, url, context) => {
|
|
26
|
+
if (debug) console.log("MaterialXLoaderPlugin: Registering MaterialX extension for", url);
|
|
27
|
+
_useNeedleMaterialX(loader, {
|
|
28
|
+
cacheKey: url,
|
|
29
|
+
parameters: {
|
|
30
|
+
precision: /** @type {import('three').MaterialParameters["precision"]} */ (context.renderer.capabilities.getMaxPrecision("highp")),
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
getTime: () => context.time.time,
|
|
34
|
+
getFrame: () => context.time.frame,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} url
|
|
40
|
+
* @param {import("@needle-tools/engine").GLTF} gltf
|
|
41
|
+
* @param {Context} _context
|
|
42
|
+
*/
|
|
43
|
+
onLoaded = (url, gltf, _context) => {
|
|
44
|
+
if (debug) console.log("[MaterialX] MaterialXLoaderPlugin: glTF loaded", { url, scene: gltf.scene, materialX_root_data: this.loader?.materialX_root_data });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {import('three/examples/jsm/exporters/GLTFExporter.js').GLTFExporter} _exporter
|
|
49
|
+
* @param {Context} _context
|
|
50
|
+
*/
|
|
51
|
+
onExport = (_exporter, _context) => {
|
|
52
|
+
console.warn("[MaterialX] Export is not supported");
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Add the MaterialXLoaderPlugin to the Needle Engine.
|
|
58
|
+
* @returns {Promise<void>}
|
|
59
|
+
*/
|
|
60
|
+
export async function useNeedleMaterialX() {
|
|
61
|
+
addCustomExtensionPlugin(new MaterialXLoaderPlugin());
|
|
62
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Material, MaterialParameters } from "three";
|
|
2
|
+
import { GLTFLoader, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
3
|
+
import { MaterialXContext } from "../materialx.js";
|
|
4
|
+
import { MaterialXMaterial } from "../materialx.material.js";
|
|
5
|
+
import { Callbacks } from "../materialx.helper.js";
|
|
6
|
+
|
|
7
|
+
export interface MaterialX_root_extension {
|
|
8
|
+
version: string;
|
|
9
|
+
name: string;
|
|
10
|
+
mtlx: string;
|
|
11
|
+
textures: Array<{ name: string, pointer: string }>;
|
|
12
|
+
shaders?: Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
originalName: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MaterialX_material_extension {
|
|
19
|
+
name: string;
|
|
20
|
+
shader?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MaterialXLoaderOptions {
|
|
24
|
+
cacheKey?: string;
|
|
25
|
+
parameters?: Pick<MaterialParameters, "precision">;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export declare class MaterialXLoader implements GLTFLoaderPlugin {
|
|
29
|
+
readonly name: "NEEDLE_materials_mtlx";
|
|
30
|
+
private readonly _generatedMaterials: MaterialXMaterial[];
|
|
31
|
+
private _documentReadyPromise: Promise<any> | null;
|
|
32
|
+
private parser: GLTFParser;
|
|
33
|
+
private options: MaterialXLoaderOptions;
|
|
34
|
+
private context: MaterialXContext;
|
|
35
|
+
|
|
36
|
+
get materialX_root_data(): MaterialX_root_extension | null;
|
|
37
|
+
get materials(): MaterialXMaterial[];
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
parser: GLTFParser,
|
|
41
|
+
options: MaterialXLoaderOptions,
|
|
42
|
+
context: MaterialXContext
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
loadMaterial(materialIndex: number): Promise<Material> | null;
|
|
46
|
+
private _loadMaterialAsync(materialIndex: number): Promise<Material>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare function useNeedleMaterialX(
|
|
50
|
+
loader: GLTFLoader,
|
|
51
|
+
options?: MaterialXLoaderOptions,
|
|
52
|
+
context?: MaterialXContext
|
|
53
|
+
): void;
|
|
54
|
+
|
|
55
|
+
export declare function createMaterialXMaterial(
|
|
56
|
+
mtlx: string,
|
|
57
|
+
materialNodeName: string,
|
|
58
|
+
loaders: Callbacks,
|
|
59
|
+
options?: MaterialXLoaderOptions,
|
|
60
|
+
context?: MaterialXContext
|
|
61
|
+
): Promise<Material>;
|
|
@@ -1,61 +1,55 @@
|
|
|
1
|
-
import { Material, MeshStandardMaterial, DoubleSide, FrontSide
|
|
2
|
-
import { GLTFLoader
|
|
3
|
-
import { ready, state
|
|
1
|
+
import { Material, MeshStandardMaterial, DoubleSide, FrontSide } from "three";
|
|
2
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
3
|
+
import { ready, state } from "../materialx.js";
|
|
4
4
|
import { debug } from "../utils.js";
|
|
5
5
|
import { MaterialXMaterial } from "../materialx.material.js";
|
|
6
|
-
import { Callbacks as callbacks } from "../materialx.helper.js";
|
|
7
|
-
|
|
8
|
-
// TypeScript interfaces matching the C# data structures
|
|
9
|
-
export type MaterialX_root_extension = {
|
|
10
|
-
/** e.g. 1.39 */
|
|
11
|
-
version: string;
|
|
12
|
-
/** e.g. "Material" */
|
|
13
|
-
name: string;
|
|
14
|
-
/** MaterialX xml content */
|
|
15
|
-
mtlx: string;
|
|
16
|
-
/** MaterialX texture pointers */
|
|
17
|
-
textures: Array<{ name: string, pointer: string }>;
|
|
18
|
-
shaders?: Array<{
|
|
19
|
-
/** The materialx node name */
|
|
20
|
-
name: string,
|
|
21
|
-
/** The original name of the shader */
|
|
22
|
-
originalName: string,
|
|
23
|
-
}>,
|
|
24
|
-
}
|
|
25
6
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} MaterialX_root_extension
|
|
9
|
+
* @property {string} version - e.g. 1.39
|
|
10
|
+
* @property {string} name - e.g. "Material"
|
|
11
|
+
* @property {string} mtlx - MaterialX xml content
|
|
12
|
+
* @property {Array<{name: string, pointer: string}>} textures - MaterialX texture pointers
|
|
13
|
+
* @property {Array<{name: string, originalName: string}>} [shaders] - MaterialX shaders
|
|
14
|
+
*/
|
|
32
15
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} MaterialX_material_extension
|
|
18
|
+
* @property {string} name - The MaterialX material name
|
|
19
|
+
* @property {number} [shader] - The index of the shader in the shaders array of the root extension
|
|
20
|
+
*/
|
|
40
21
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {Object} MaterialDefinition
|
|
24
|
+
* @property {string} [name] - Optional name for the material
|
|
25
|
+
* @property {boolean} [doubleSided] - Whether the material is double-sided
|
|
26
|
+
* @property {Object<string, any>} [extensions] - Extensions for the material, including MaterialX
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {Object} MaterialXLoaderOptions
|
|
31
|
+
* @property {string} [cacheKey] - The URL of the GLTF file being loaded
|
|
32
|
+
* @property {import('three').MaterialParameters} [parameters] - Parameters for the MaterialX loader
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {Object} MaterialXMaterialOptions
|
|
37
|
+
* @property {import('three').MaterialParameters} [parameters]
|
|
38
|
+
*/
|
|
48
39
|
|
|
49
40
|
// MaterialX loader extension for js GLTFLoader
|
|
50
|
-
export class MaterialXLoader
|
|
51
|
-
readonly
|
|
41
|
+
export class MaterialXLoader {
|
|
42
|
+
/** @readonly */
|
|
43
|
+
name = "NEEDLE_materials_mtlx";
|
|
52
44
|
|
|
53
|
-
|
|
45
|
+
/** @type {MaterialXMaterial[]} */
|
|
46
|
+
_generatedMaterials = [];
|
|
54
47
|
|
|
55
|
-
|
|
48
|
+
/** @type {Promise<any> | null} */
|
|
49
|
+
_documentReadyPromise = null;
|
|
56
50
|
|
|
57
51
|
get materialX_root_data() {
|
|
58
|
-
return this.parser.json.extensions?.[this.name]
|
|
52
|
+
return /** @type {MaterialX_root_extension | null} */ (this.parser.json.extensions?.[this.name]) || null;
|
|
59
53
|
}
|
|
60
54
|
|
|
61
55
|
/** Generated materialX materials */
|
|
@@ -65,15 +59,15 @@ export class MaterialXLoader implements GLTFLoaderPlugin {
|
|
|
65
59
|
|
|
66
60
|
/**
|
|
67
61
|
* MaterialXLoader constructor
|
|
68
|
-
* @param parser The GLTFParser instance
|
|
69
|
-
* @param
|
|
70
|
-
* @param context The context for the GLTF loading process
|
|
62
|
+
* @param {import('three/examples/jsm/loaders/GLTFLoader.js').GLTFParser} parser - The GLTFParser instance
|
|
63
|
+
* @param {MaterialXLoaderOptions} options - The loader options
|
|
64
|
+
* @param {import('../materialx.js').MaterialXContext} context - The context for the GLTF loading process
|
|
71
65
|
*/
|
|
72
|
-
constructor(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
constructor(parser, options, context) {
|
|
67
|
+
this.parser = parser;
|
|
68
|
+
this.options = options;
|
|
69
|
+
this.context = context;
|
|
70
|
+
|
|
77
71
|
if (debug) console.log("MaterialXLoader created for parser");
|
|
78
72
|
// Start loading of MaterialX environment if the root extension exists
|
|
79
73
|
if (this.materialX_root_data) {
|
|
@@ -81,8 +75,11 @@ export class MaterialXLoader implements GLTFLoaderPlugin {
|
|
|
81
75
|
}
|
|
82
76
|
}
|
|
83
77
|
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
/**
|
|
79
|
+
* @param {number} materialIndex
|
|
80
|
+
* @returns {Promise<Material> | null}
|
|
81
|
+
*/
|
|
82
|
+
loadMaterial(materialIndex) {
|
|
86
83
|
const materialDef = this.parser.json.materials?.[materialIndex];
|
|
87
84
|
if (!materialDef?.extensions?.[this.name]) {
|
|
88
85
|
return null;
|
|
@@ -91,20 +88,27 @@ export class MaterialXLoader implements GLTFLoaderPlugin {
|
|
|
91
88
|
return this._loadMaterialAsync(materialIndex);
|
|
92
89
|
}
|
|
93
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @private
|
|
93
|
+
* @param {number} materialIndex
|
|
94
|
+
* @returns {Promise<Material>}
|
|
95
|
+
*/
|
|
96
|
+
async _loadMaterialAsync(materialIndex) {
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const materialDef = this.parser.json.materials?.[materialIndex] as MaterialDefinition;
|
|
98
|
+
/** @type {MaterialDefinition} */
|
|
99
|
+
const materialDef = this.parser.json.materials?.[materialIndex];
|
|
98
100
|
if (debug) console.log("[MaterialX] extension found in material:", materialDef.extensions?.[this.name]);
|
|
99
101
|
|
|
100
102
|
// Handle different types of MaterialX data
|
|
101
|
-
|
|
103
|
+
/** @type {MaterialX_material_extension} */
|
|
104
|
+
const ext = materialDef.extensions?.[this.name];
|
|
102
105
|
|
|
103
106
|
const mtlx = this.materialX_root_data?.mtlx;
|
|
104
107
|
|
|
105
108
|
if (ext && mtlx) {
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
/** @type {MaterialXMaterialOptions} */
|
|
111
|
+
const materialOptions = {
|
|
108
112
|
...this.options,
|
|
109
113
|
}
|
|
110
114
|
|
|
@@ -162,29 +166,27 @@ export class MaterialXLoader implements GLTFLoaderPlugin {
|
|
|
162
166
|
fallbackMaterial.name = "MaterialX_Fallback";
|
|
163
167
|
return fallbackMaterial;
|
|
164
168
|
}
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
type MaterialXMaterialOptions = {
|
|
170
|
-
parameters?: MaterialParameters;
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
/**
|
|
174
172
|
* Add the MaterialXLoader to the GLTFLoader instance.
|
|
173
|
+
* @param {GLTFLoader} loader
|
|
174
|
+
* @param {MaterialXLoaderOptions} [options]
|
|
175
|
+
* @param {import('../materialx.js').MaterialXContext} [context]
|
|
175
176
|
*/
|
|
176
|
-
export function useNeedleMaterialX(loader
|
|
177
|
+
export function useNeedleMaterialX(loader, options, context) {
|
|
177
178
|
loader.register(p => {
|
|
178
179
|
const loader = new MaterialXLoader(p, options || {}, context || {});
|
|
179
180
|
return loader;
|
|
180
181
|
});
|
|
181
182
|
}
|
|
182
183
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Parse the MaterialX document once and cache it
|
|
186
|
+
* @param {string} mtlx
|
|
187
|
+
* @returns {Promise<any>}
|
|
188
|
+
*/
|
|
189
|
+
async function load(mtlx) {
|
|
188
190
|
// Ensure MaterialX is initialized
|
|
189
191
|
await ready();
|
|
190
192
|
if (!state.materialXModule) {
|
|
@@ -199,7 +201,15 @@ async function load(mtlx: string): Promise<any> {
|
|
|
199
201
|
return doc;
|
|
200
202
|
}
|
|
201
203
|
|
|
202
|
-
|
|
204
|
+
/**
|
|
205
|
+
* @param {string} mtlx
|
|
206
|
+
* @param {string} materialNodeName
|
|
207
|
+
* @param {import('../materialx.helper.js').Callbacks} loaders
|
|
208
|
+
* @param {MaterialXLoaderOptions} [options]
|
|
209
|
+
* @param {import('../materialx.js').MaterialXContext} [context]
|
|
210
|
+
* @returns {Promise<Material>}
|
|
211
|
+
*/
|
|
212
|
+
export async function createMaterialXMaterial(mtlx, materialNodeName, loaders, options, context) {
|
|
203
213
|
try {
|
|
204
214
|
if (debug) console.log(`Creating MaterialX material: ${materialNodeName}`);
|
|
205
215
|
|
|
@@ -213,7 +223,7 @@ export async function createMaterialXMaterial(mtlx: string, materialNodeName: st
|
|
|
213
223
|
}
|
|
214
224
|
|
|
215
225
|
// Find the renderable element following MaterialX example pattern exactly
|
|
216
|
-
let renderableElement
|
|
226
|
+
let renderableElement = null;
|
|
217
227
|
let foundRenderable = false;
|
|
218
228
|
|
|
219
229
|
if (debug) console.log("[MaterialX] document", doc);
|
|
@@ -288,10 +298,10 @@ export async function createMaterialXMaterial(mtlx: string, materialNodeName: st
|
|
|
288
298
|
*/
|
|
289
299
|
|
|
290
300
|
if (!renderableElement) {
|
|
291
|
-
console.warn(`[MaterialX] No renderable element found in MaterialX document (${
|
|
301
|
+
console.warn(`[MaterialX] No renderable element found in MaterialX document (${materialNodeName})`);
|
|
292
302
|
const fallbackMaterial = new MeshStandardMaterial();
|
|
293
303
|
fallbackMaterial.color.set(0xff00ff);
|
|
294
|
-
fallbackMaterial.name = `MaterialX_NoRenderable_${
|
|
304
|
+
fallbackMaterial.name = `MaterialX_NoRenderable_${materialNodeName}`;
|
|
295
305
|
return fallbackMaterial;
|
|
296
306
|
}
|
|
297
307
|
|
|
@@ -303,7 +313,7 @@ export async function createMaterialXMaterial(mtlx: string, materialNodeName: st
|
|
|
303
313
|
|
|
304
314
|
// Generate shaders using the element's name path
|
|
305
315
|
if (debug) console.log("[MaterialX] Generating MaterialX shaders...");
|
|
306
|
-
const elementName =
|
|
316
|
+
const elementName = renderableElement.getNamePath ? renderableElement.getNamePath() : renderableElement.getName();
|
|
307
317
|
|
|
308
318
|
const shader = state.materialXGenerator.generate(elementName, renderableElement, state.materialXGenContext);
|
|
309
319
|
|
|
@@ -331,11 +341,11 @@ export async function createMaterialXMaterial(mtlx: string, materialNodeName: st
|
|
|
331
341
|
|
|
332
342
|
} catch (error) {
|
|
333
343
|
// This is a wasm error (an int) that we need to resolve
|
|
334
|
-
console.error(`[MaterialX] Error creating MaterialX material (${
|
|
344
|
+
console.error(`[MaterialX] Error creating MaterialX material (${materialNodeName}):`, error);
|
|
335
345
|
// Return a fallback material with stored MaterialX data
|
|
336
346
|
const fallbackMaterial = new MeshStandardMaterial();
|
|
337
347
|
fallbackMaterial.color.set(0xff00ff);
|
|
338
|
-
fallbackMaterial.name = `MaterialX_Error_${
|
|
348
|
+
fallbackMaterial.name = `MaterialX_Error_${materialNodeName}`;
|
|
339
349
|
return fallbackMaterial;
|
|
340
350
|
}
|
|
341
|
-
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Light, Scene, Texture, WebGLRenderer } from "three";
|
|
2
|
+
import type { MaterialX as MX } from "./materialx.types.js";
|
|
3
|
+
|
|
4
|
+
export type MaterialXContext = {
|
|
5
|
+
getTime?(): number;
|
|
6
|
+
getFrame?(): number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type EnvironmentTextureSet = {
|
|
10
|
+
radianceTexture: Texture | null;
|
|
11
|
+
irradianceTexture: Texture | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare const state: {
|
|
15
|
+
materialXModule: MX.MODULE | null;
|
|
16
|
+
materialXGenerator: any | null;
|
|
17
|
+
materialXGenContext: any | null;
|
|
18
|
+
materialXStdLib: any | null;
|
|
19
|
+
materialXInitPromise: Promise<void> | null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Wait for the MaterialX WASM module to be ready.
|
|
24
|
+
*/
|
|
25
|
+
export declare function ready(): Promise<void>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* MaterialXEnvironment manages the environment settings for MaterialX materials.
|
|
29
|
+
*/
|
|
30
|
+
export declare class MaterialXEnvironment {
|
|
31
|
+
static get(scene: Scene): MaterialXEnvironment | null;
|
|
32
|
+
private static _environments: WeakMap<Scene, MaterialXEnvironment>;
|
|
33
|
+
private static getEnvironment(scene: Scene): MaterialXEnvironment;
|
|
34
|
+
|
|
35
|
+
private _lights: Array<Light>;
|
|
36
|
+
private _lightData: any[] | null;
|
|
37
|
+
private _lightCount: number;
|
|
38
|
+
private _initializePromise: Promise<boolean> | null;
|
|
39
|
+
private _isInitialized: boolean;
|
|
40
|
+
private _lastUpdateFrame: number;
|
|
41
|
+
private _scene: Scene;
|
|
42
|
+
|
|
43
|
+
constructor(_scene: Scene);
|
|
44
|
+
|
|
45
|
+
initialize(renderer: WebGLRenderer): Promise<boolean>;
|
|
46
|
+
update(frame: number, scene: Scene, renderer: WebGLRenderer): void;
|
|
47
|
+
reset(): void;
|
|
48
|
+
|
|
49
|
+
get lights(): Array<Light>;
|
|
50
|
+
get lightData(): any[] | null;
|
|
51
|
+
get lightCount(): number;
|
|
52
|
+
getTextures(material: any): EnvironmentTextureSet;
|
|
53
|
+
|
|
54
|
+
private _pmremGenerator: any | null;
|
|
55
|
+
private _renderer: WebGLRenderer | null;
|
|
56
|
+
private _texturesCache: Map<Texture | null, EnvironmentTextureSet>;
|
|
57
|
+
private _initialize(renderer: WebGLRenderer): Promise<boolean>;
|
|
58
|
+
private _getTextures(texture: Texture | null | undefined): EnvironmentTextureSet;
|
|
59
|
+
private updateLighting(collectLights?: boolean): void;
|
|
60
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
export interface Callbacks {
|
|
4
|
+
readonly cacheKey?: string;
|
|
5
|
+
readonly getTexture: (path: string) => Promise<THREE.Texture | null | void>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface LightData {
|
|
9
|
+
type: number;
|
|
10
|
+
position: THREE.Vector3;
|
|
11
|
+
direction: THREE.Vector3;
|
|
12
|
+
color: THREE.Color;
|
|
13
|
+
intensity: number;
|
|
14
|
+
decay_rate: number;
|
|
15
|
+
inner_angle: number;
|
|
16
|
+
outer_angle: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function prepareEnvTexture(texture: THREE.Texture, capabilities: any): THREE.Texture;
|
|
20
|
+
|
|
21
|
+
export function getLightRotation(): THREE.Matrix4;
|
|
22
|
+
|
|
23
|
+
export function findLights(doc: any): Array<any>;
|
|
24
|
+
|
|
25
|
+
export function registerLights(mx: any, genContext: any): Promise<void>;
|
|
26
|
+
|
|
27
|
+
export function getLightData(lights: Array<THREE.Light>, genContext: any): { lightData: LightData[], lightCount: number };
|
|
28
|
+
|
|
29
|
+
export function getUniformValues(shaderStage: any, loaders: Callbacks, searchPath: string): Record<string, THREE.Uniform>;
|
|
30
|
+
|
|
31
|
+
export function generateMaterialPropertiesForUniforms(material: THREE.ShaderMaterial, shaderStage: any): void;
|