@needle-tools/materialx 1.0.1-next.df0e959 → 1.0.2-next.81f48e0
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 +5 -0
- package/README.md +1 -1
- package/codegen/register_types.ts +2 -0
- package/package.json +1 -1
- package/src/loader/loader.needle.ts +22 -33
- package/src/loader/loader.three.ts +123 -393
- package/src/materialx.helper.ts +477 -0
- package/src/materialx.material.ts +217 -0
- package/src/materialx.ts +125 -92
- package/src/materialx.types.d.ts +50 -0
- package/src/textureHelper.ts +6 -6
- package/src/utils.ts +39 -4
- package/src/helper.js +0 -490
package/CHANGELOG.md
CHANGED
|
@@ -4,5 +4,10 @@ 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.0.2] - 2025-07-10
|
|
8
|
+
- Add: Material extension `doubleSided` support
|
|
9
|
+
- Improved lighting support
|
|
10
|
+
- Improved texture loading and fix bug where glTF texture index was not resolved properly
|
|
11
|
+
|
|
7
12
|
## [1.0.1] - 2025-07-08
|
|
8
13
|
- Initial release
|
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { TypeStore } from "@needle-tools/engine"
|
|
3
3
|
|
|
4
4
|
// Import types
|
|
5
|
+
import { MaterialXMaterial } from "../src/materialx.material.js";
|
|
5
6
|
import { MaterialXUniformUpdate } from "../src/loader/loader.needle.js";
|
|
6
7
|
|
|
7
8
|
// Register types
|
|
9
|
+
TypeStore.add("MaterialXMaterial", MaterialXMaterial);
|
|
8
10
|
TypeStore.add("MaterialXUniformUpdate", MaterialXUniformUpdate);
|
package/package.json
CHANGED
|
@@ -6,32 +6,21 @@ import type { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
|
6
6
|
import type { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
7
7
|
import { MaterialXLoader } from "./loader.three.js";
|
|
8
8
|
import { debug } from "../utils.js";
|
|
9
|
-
import { state } from "../materialx.js";
|
|
9
|
+
import { MaterialXEnvironment, state } from "../materialx.js";
|
|
10
|
+
import { MaterialXMaterial } from "../materialx.material.js";
|
|
10
11
|
|
|
11
12
|
//@dont-generate-component
|
|
12
13
|
export class MaterialXUniformUpdate extends Component {
|
|
13
14
|
|
|
14
|
-
static updateMaterial(mat: Material | Material[], object: Object3D, camera: Camera) {
|
|
15
|
-
if (Array.isArray(mat)) {
|
|
16
|
-
mat.forEach(m => {
|
|
17
|
-
if (m.userData?.updateUniforms) {
|
|
18
|
-
m.userData.updateUniforms(object, camera);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
} else if (mat.userData?.updateUniforms) {
|
|
22
|
-
mat.userData.updateUniforms(object, camera);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
15
|
onEnable(): void {
|
|
27
|
-
this.context.addBeforeRenderListener(this.gameObject, this.
|
|
16
|
+
this.context.addBeforeRenderListener(this.gameObject, this.onBeforeRenderThree);
|
|
28
17
|
}
|
|
29
18
|
|
|
30
19
|
onDisable(): void {
|
|
31
|
-
this.context.removeBeforeRenderListener(this.gameObject, this.
|
|
20
|
+
this.context.removeBeforeRenderListener(this.gameObject, this.onBeforeRenderThree);
|
|
32
21
|
}
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
onBeforeRenderThree = () => {
|
|
35
24
|
// Update uniforms or perform any pre-render logic here
|
|
36
25
|
const gameObject = this.gameObject as any as Mesh;
|
|
37
26
|
const material = gameObject?.material;
|
|
@@ -39,14 +28,16 @@ export class MaterialXUniformUpdate extends Component {
|
|
|
39
28
|
const camera = this.context.mainCamera;
|
|
40
29
|
if (!camera) return;
|
|
41
30
|
|
|
42
|
-
|
|
31
|
+
const env = state.materialXEnvironment;
|
|
43
32
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
33
|
+
if (Array.isArray(material)) {
|
|
34
|
+
for (const entry of material) {
|
|
35
|
+
if (entry && entry instanceof MaterialXMaterial) {
|
|
36
|
+
entry.updateUniforms(this.context, env, this.gameObject, camera);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} else if (material instanceof MaterialXMaterial) {
|
|
40
|
+
material.updateUniforms(this.context, env, this.gameObject, camera);
|
|
50
41
|
}
|
|
51
42
|
}
|
|
52
43
|
}
|
|
@@ -62,14 +53,18 @@ export class MaterialXLoaderPlugin implements INeedleGLTFExtensionPlugin {
|
|
|
62
53
|
// Register the MaterialX loader extension
|
|
63
54
|
// Environment initialization is now handled in the MaterialXLoader constructor
|
|
64
55
|
loader.register(p => {
|
|
65
|
-
this.loader = new MaterialXLoader(p, context);
|
|
56
|
+
this.loader = new MaterialXLoader(p, url, context);
|
|
66
57
|
return this.loader;
|
|
67
58
|
});
|
|
68
59
|
};
|
|
69
60
|
|
|
70
|
-
onLoaded = (url: string, gltf: GLTF,
|
|
71
|
-
if (debug) console.log("[MaterialX] MaterialXLoaderPlugin: glTF loaded", url, gltf.scene);
|
|
61
|
+
onLoaded = (url: string, gltf: GLTF, _context: Context) => {
|
|
62
|
+
if (debug) console.log("[MaterialX] MaterialXLoaderPlugin: glTF loaded", { url, scene: gltf.scene, materialX_root_data: this.loader?.materialX_root_data });
|
|
72
63
|
|
|
64
|
+
// If we don't have MaterialX data in the loaded glTF we don't need to do anything else here
|
|
65
|
+
if (!this.loader?.materialX_root_data) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
73
68
|
// Set up onBeforeRender callbacks for objects with MaterialX materials
|
|
74
69
|
// This ensures uniforms are updated properly during rendering
|
|
75
70
|
gltf.scene.traverse((child) => {
|
|
@@ -77,7 +72,7 @@ export class MaterialXLoaderPlugin implements INeedleGLTFExtensionPlugin {
|
|
|
77
72
|
const mesh = child as Mesh;
|
|
78
73
|
const material = mesh.material as Material;
|
|
79
74
|
|
|
80
|
-
if (material
|
|
75
|
+
if (material instanceof MaterialXMaterial) {
|
|
81
76
|
if (debug) console.log("[MaterialX] Adding MaterialX uniform update component to:", child.name);
|
|
82
77
|
child.addComponent(MaterialXUniformUpdate);
|
|
83
78
|
}
|
|
@@ -85,12 +80,6 @@ export class MaterialXLoaderPlugin implements INeedleGLTFExtensionPlugin {
|
|
|
85
80
|
});
|
|
86
81
|
|
|
87
82
|
if (debug) console.log("[MaterialX] Loaded: ", this.loader);
|
|
88
|
-
|
|
89
|
-
// Initialize MaterialX lighting system with scene data
|
|
90
|
-
const environment = state.materialXEnvironment;
|
|
91
|
-
environment.initializeFromContext(context).then(() => {
|
|
92
|
-
this.loader?.updateLightingFromEnvironment(environment);
|
|
93
|
-
});
|
|
94
83
|
};
|
|
95
84
|
|
|
96
85
|
onExport = (_exporter: GLTFExporter, _context: Context) => {
|