@needle-tools/materialx 1.1.1-next.623fc20 → 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.
@@ -0,0 +1,4 @@
1
+ # ensure LF line endings
2
+ *.data binary
3
+ *.data.txt binary
4
+ *.wasm binary
@@ -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
@@ -0,0 +1,2 @@
1
+ export * from "./src/index.js";
2
+ export { useNeedleMaterialX } from "./src/loader/loader.three.js";
@@ -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
@@ -0,0 +1,2 @@
1
+ export * from "./src/index.js";
2
+ export { useNeedleMaterialX } from "./src/loader/loader.needle.js";
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "@needle-tools/materialx",
3
- "version": "1.1.1-next.623fc20",
3
+ "version": "1.1.1-next.8e8afe1",
4
4
  "type": "module",
5
- "main": "index.ts",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "exports": {
7
8
  ".": {
8
- "import": "./index.ts",
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 };
package/src/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { ready } 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
+ const Experimental_API = {
8
+ createMaterialXMaterial
9
+ }
10
+
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>;
@@ -0,0 +1,351 @@
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
+ import { debug } from "../utils.js";
5
+ import { MaterialXMaterial } from "../materialx.material.js";
6
+
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
+ */
15
+
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
+ */
21
+
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
+ */
39
+
40
+ // MaterialX loader extension for js GLTFLoader
41
+ export class MaterialXLoader {
42
+ /** @readonly */
43
+ name = "NEEDLE_materials_mtlx";
44
+
45
+ /** @type {MaterialXMaterial[]} */
46
+ _generatedMaterials = [];
47
+
48
+ /** @type {Promise<any> | null} */
49
+ _documentReadyPromise = null;
50
+
51
+ get materialX_root_data() {
52
+ return /** @type {MaterialX_root_extension | null} */ (this.parser.json.extensions?.[this.name]) || null;
53
+ }
54
+
55
+ /** Generated materialX materials */
56
+ get materials() {
57
+ return this._generatedMaterials;
58
+ }
59
+
60
+ /**
61
+ * MaterialXLoader constructor
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
65
+ */
66
+ constructor(parser, options, context) {
67
+ this.parser = parser;
68
+ this.options = options;
69
+ this.context = context;
70
+
71
+ if (debug) console.log("MaterialXLoader created for parser");
72
+ // Start loading of MaterialX environment if the root extension exists
73
+ if (this.materialX_root_data) {
74
+ ready();
75
+ }
76
+ }
77
+
78
+ /**
79
+ * @param {number} materialIndex
80
+ * @returns {Promise<Material> | null}
81
+ */
82
+ loadMaterial(materialIndex) {
83
+ const materialDef = this.parser.json.materials?.[materialIndex];
84
+ if (!materialDef?.extensions?.[this.name]) {
85
+ return null;
86
+ }
87
+ // Wrap the async implementation
88
+ return this._loadMaterialAsync(materialIndex);
89
+ }
90
+
91
+ /**
92
+ * @private
93
+ * @param {number} materialIndex
94
+ * @returns {Promise<Material>}
95
+ */
96
+ async _loadMaterialAsync(materialIndex) {
97
+
98
+ /** @type {MaterialDefinition} */
99
+ const materialDef = this.parser.json.materials?.[materialIndex];
100
+ if (debug) console.log("[MaterialX] extension found in material:", materialDef.extensions?.[this.name]);
101
+
102
+ // Handle different types of MaterialX data
103
+ /** @type {MaterialX_material_extension} */
104
+ const ext = materialDef.extensions?.[this.name];
105
+
106
+ const mtlx = this.materialX_root_data?.mtlx;
107
+
108
+ if (ext && mtlx) {
109
+
110
+ /** @type {MaterialXMaterialOptions} */
111
+ const materialOptions = {
112
+ ...this.options,
113
+ }
114
+
115
+ if (!materialOptions.parameters) materialOptions.parameters = {};
116
+
117
+ if (materialOptions.parameters?.side === undefined && materialDef.doubleSided !== undefined) {
118
+ materialOptions.parameters.side = materialDef.doubleSided ? DoubleSide : FrontSide;
119
+ }
120
+
121
+ return createMaterialXMaterial(mtlx, ext.name, {
122
+ cacheKey: this.options.cacheKey || "",
123
+ getTexture: async url => {
124
+ // Find the index of the texture in the parser
125
+ const filenameWithoutExt = url.split('/').pop()?.split('.').shift() || '';
126
+
127
+ // Resolve the texture from the MaterialX root extension
128
+ if (this.materialX_root_data) {
129
+ const textures = this.materialX_root_data.textures || [];
130
+ let index = -1;
131
+ for (const texture of textures) {
132
+ // Find the texture by name and use the pointer string to get the index
133
+ if (texture.name === filenameWithoutExt) {
134
+ const ptr = texture.pointer;
135
+ const indexStr = ptr.substring("/textures/".length);
136
+ index = parseInt(indexStr);
137
+
138
+ if (isNaN(index) || index < 0) {
139
+ console.error("[MaterialX] Invalid texture index in pointer:", ptr);
140
+ return;
141
+ }
142
+ else {
143
+ if (debug) console.log("[MaterialX] Texture index found:", index, "for", filenameWithoutExt);
144
+ }
145
+ }
146
+ }
147
+
148
+ if (index < 0) {
149
+ console.error("[MaterialX] Texture not found in parser:", filenameWithoutExt, this.parser.json);
150
+ return;
151
+ }
152
+ return this.parser.getDependency("texture", index);
153
+ }
154
+ return null;
155
+ }
156
+ }, materialOptions, this.context)
157
+ // Cache and return the generated material
158
+ .then(mat => {
159
+ if (mat instanceof MaterialXMaterial) this._generatedMaterials.push(mat);
160
+ return mat;
161
+ })
162
+ }
163
+
164
+ // Return fallback material instead of null
165
+ const fallbackMaterial = new MeshStandardMaterial();
166
+ fallbackMaterial.name = "MaterialX_Fallback";
167
+ return fallbackMaterial;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Add the MaterialXLoader to the GLTFLoader instance.
173
+ * @param {GLTFLoader} loader
174
+ * @param {MaterialXLoaderOptions} [options]
175
+ * @param {import('../materialx.js').MaterialXContext} [context]
176
+ */
177
+ export function useNeedleMaterialX(loader, options, context) {
178
+ loader.register(p => {
179
+ const loader = new MaterialXLoader(p, options || {}, context || {});
180
+ return loader;
181
+ });
182
+ }
183
+
184
+ /**
185
+ * Parse the MaterialX document once and cache it
186
+ * @param {string} mtlx
187
+ * @returns {Promise<any>}
188
+ */
189
+ async function load(mtlx) {
190
+ // Ensure MaterialX is initialized
191
+ await ready();
192
+ if (!state.materialXModule) {
193
+ throw new Error("[MaterialX] module failed to initialize");
194
+ }
195
+ // Create MaterialX document and parse ALL the XML data from root
196
+ const doc = state.materialXModule.createDocument();
197
+ doc.setDataLibrary(state.materialXStdLib);
198
+ // Parse all MaterialX XML strings from the root data
199
+ await state.materialXModule.readFromXmlString(doc, mtlx, "");
200
+ if (debug) console.log("[MaterialX] root document parsed successfully");
201
+ return doc;
202
+ }
203
+
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) {
213
+ try {
214
+ if (debug) console.log(`Creating MaterialX material: ${materialNodeName}`);
215
+
216
+ const doc = await load(mtlx);
217
+
218
+ if (!state.materialXModule || !state.materialXGenerator || !state.materialXGenContext) {
219
+ console.warn("[MaterialX] WASM module not ready, returning fallback material");
220
+ const fallbackMaterial = new MeshStandardMaterial();
221
+ fallbackMaterial.name = `MaterialX_Fallback_${materialNodeName}`;
222
+ return fallbackMaterial;
223
+ }
224
+
225
+ // Find the renderable element following MaterialX example pattern exactly
226
+ let renderableElement = null;
227
+ let foundRenderable = false;
228
+
229
+ if (debug) console.log("[MaterialX] document", doc);
230
+
231
+ // Search for material nodes first (following the reference pattern)
232
+ const materialNodes = doc.getMaterialNodes();
233
+ if (debug) console.log(`[MaterialX] Found ${materialNodes.length} material nodes in document`, materialNodes);
234
+
235
+ // Handle both array and vector-like APIs
236
+ for (let i = 0; i < materialNodes.length; ++i) {
237
+ const materialNode = materialNodes[i];
238
+ if (materialNode) {
239
+ const name = materialNode.getNamePath();
240
+ if (debug) console.log(`[MaterialX] Scan material[${i}]: ${name}`);
241
+
242
+ // Find the matching material
243
+ if (materialNodes.length === 1 || name == materialNodeName) {
244
+ materialNodeName = name;
245
+ renderableElement = materialNode;
246
+ foundRenderable = true;
247
+ if (debug) console.log(`[MaterialX] Use material node: '${name}'`);
248
+ break;
249
+ }
250
+ }
251
+ }
252
+
253
+ /*
254
+ // If no material nodes found, search nodeGraphs
255
+ if (!foundRenderable) {
256
+ const nodeGraphs = doc.getNodeGraphs();
257
+ console.log(`Found ${nodeGraphs.length} node graphs in document`);
258
+ const nodeGraphsLength = nodeGraphs.length;
259
+ for (let i = 0; i < nodeGraphsLength; ++i) {
260
+ const nodeGraph = nodeGraphs[i];
261
+ if (nodeGraph) {
262
+ // Skip any nodegraph that has nodedef or sourceUri
263
+ if ((nodeGraph as any).hasAttribute('nodedef') || (nodeGraph as any).hasSourceUri()) {
264
+ continue;
265
+ }
266
+ // Skip any nodegraph that is connected to something downstream
267
+ if ((nodeGraph as any).getDownstreamPorts().length > 0) {
268
+ continue;
269
+ }
270
+ const outputs = (nodeGraph as any).getOutputs();
271
+ for (let j = 0; j < outputs.length; ++j) {
272
+ const output = outputs[j];
273
+ if (output && !foundRenderable) {
274
+ renderableElement = output;
275
+ foundRenderable = true;
276
+ break;
277
+ }
278
+ }
279
+ if (foundRenderable) break;
280
+ }
281
+ }
282
+ }
283
+
284
+ // If still no element found, search document outputs
285
+ if (!foundRenderable) {
286
+ const outputs = doc.getOutputs();
287
+ console.log(`Found ${outputs.length} output nodes in document`);
288
+ const outputsLength = outputs.length;
289
+ for (let i = 0; i < outputsLength; ++i) {
290
+ const output = outputs[i];
291
+ if (output && !foundRenderable) {
292
+ renderableElement = output;
293
+ foundRenderable = true;
294
+ break;
295
+ }
296
+ }
297
+ }
298
+ */
299
+
300
+ if (!renderableElement) {
301
+ console.warn(`[MaterialX] No renderable element found in MaterialX document (${materialNodeName})`);
302
+ const fallbackMaterial = new MeshStandardMaterial();
303
+ fallbackMaterial.color.set(0xff00ff);
304
+ fallbackMaterial.name = `MaterialX_NoRenderable_${materialNodeName}`;
305
+ return fallbackMaterial;
306
+ }
307
+
308
+ if (debug) console.log("[MaterialX] Using renderable element for shader generation");
309
+
310
+ // Check transparency and set context options like the reference
311
+ const isTransparent = state.materialXModule.isTransparentSurface(renderableElement, state.materialXGenerator.getTarget());
312
+ state.materialXGenContext.getOptions().hwTransparency = isTransparent;
313
+
314
+ // Generate shaders using the element's name path
315
+ if (debug) console.log("[MaterialX] Generating MaterialX shaders...");
316
+ const elementName = renderableElement.getNamePath ? renderableElement.getNamePath() : renderableElement.getName();
317
+
318
+ const shader = state.materialXGenerator.generate(elementName, renderableElement, state.materialXGenContext);
319
+
320
+ // const rootExtension = this.materialX_root_data;
321
+
322
+ // const shaderInfo = rootExtension && material_extension.shader !== undefined && material_extension.shader >= 0
323
+ // ? rootExtension.shaders?.[material_extension.shader]
324
+ // : null;
325
+
326
+ const shaderMaterial = new MaterialXMaterial({
327
+ name: materialNodeName,
328
+ shaderName: null, //shaderInfo?.originalName || shaderInfo?.name || null,
329
+ shader,
330
+ context: context || {},
331
+ parameters: {
332
+ transparent: isTransparent,
333
+ ...options?.parameters,
334
+ },
335
+ loaders: loaders,
336
+ });
337
+
338
+ // Add debugging to see if the material compiles correctly
339
+ if (debug) console.log("[MaterialX] material created:", shaderMaterial.name);
340
+ return shaderMaterial;
341
+
342
+ } catch (error) {
343
+ // This is a wasm error (an int) that we need to resolve
344
+ console.error(`[MaterialX] Error creating MaterialX material (${materialNodeName}):`, error);
345
+ // Return a fallback material with stored MaterialX data
346
+ const fallbackMaterial = new MeshStandardMaterial();
347
+ fallbackMaterial.color.set(0xff00ff);
348
+ fallbackMaterial.name = `MaterialX_Error_${materialNodeName}`;
349
+ return fallbackMaterial;
350
+ }
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;