@needle-tools/materialx 1.0.3 → 1.0.4-next.6620f9d
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 +2 -6
- package/src/materialx.helper.ts +1 -1
- package/src/materialx.material.ts +7 -3
- package/src/materialx.ts +10 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/materialx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4-next.6620f9d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -14,10 +14,6 @@
|
|
|
14
14
|
"require": "./codegen/register_types.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
"peerDependencies": {
|
|
18
|
-
"@needle-tools/engine": "4.x",
|
|
19
|
-
"three": "npm:@needle-tools/three@^0.169.5"
|
|
20
|
-
},
|
|
21
17
|
"devDependencies": {
|
|
22
18
|
"@needle-tools/engine": "4.x",
|
|
23
19
|
"@types/three": "0.169.0",
|
|
@@ -39,4 +35,4 @@
|
|
|
39
35
|
"mtlx",
|
|
40
36
|
"rendering"
|
|
41
37
|
]
|
|
42
|
-
}
|
|
38
|
+
}
|
package/src/materialx.helper.ts
CHANGED
|
@@ -370,7 +370,7 @@ function threeLightTypeToMaterialXNodeName(threeLightType) {
|
|
|
370
370
|
}
|
|
371
371
|
};
|
|
372
372
|
|
|
373
|
-
type LightData = {
|
|
373
|
+
export type LightData = {
|
|
374
374
|
type: number, // Light type ID
|
|
375
375
|
position: THREE.Vector3, // Position in world space
|
|
376
376
|
direction: THREE.Vector3, // Direction in world space
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Camera, DoubleSide, FrontSide, GLSL3, MaterialParameters, Matrix3, Matrix4, Object3D, ShaderMaterial, Texture, Vector3 } from "three";
|
|
2
2
|
import { debug } from "./utils.js";
|
|
3
3
|
import { MaterialXEnvironment } from "./materialx.js";
|
|
4
|
-
import { getUniformValues, Loaders } from "./materialx.helper.js";
|
|
4
|
+
import { getLightData, getUniformValues, Loaders } from "./materialx.helper.js";
|
|
5
5
|
import { Context } from "@needle-tools/engine";
|
|
6
6
|
|
|
7
7
|
|
|
@@ -122,7 +122,7 @@ export class MaterialXMaterial extends ShaderMaterial {
|
|
|
122
122
|
u_envIrradiance: { value: null, type: 't' },
|
|
123
123
|
u_refractionEnv: { value: true },
|
|
124
124
|
u_numActiveLightSources: { value: 0 },
|
|
125
|
-
u_lightData: { value: [] }, // Array of light data
|
|
125
|
+
u_lightData: { value: [], needsUpdate: false }, // Array of light data
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
if (debug) {
|
|
@@ -194,8 +194,12 @@ export class MaterialXMaterial extends ShaderMaterial {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
// Update light data
|
|
197
|
-
if (lightData) {
|
|
197
|
+
if (lightData?.length) {
|
|
198
198
|
this.uniforms.u_lightData.value = lightData;
|
|
199
|
+
if ("needsUpdate" in this.uniforms.u_lightData && this.uniforms.u_lightData.needsUpdate === false) {
|
|
200
|
+
if (debug) console.debug(`[MaterialX] LightData assigned (${this.name}, ${this.uuid})`, lightData);
|
|
201
|
+
this.uniforms.u_lightData.needsUpdate = undefined;
|
|
202
|
+
}
|
|
199
203
|
}
|
|
200
204
|
|
|
201
205
|
// Update environment uniforms
|
package/src/materialx.ts
CHANGED
|
@@ -4,7 +4,7 @@ import MaterialX from "../bin/JsMaterialXGenShader.js";
|
|
|
4
4
|
import { debug } from "./utils.js";
|
|
5
5
|
import { renderPMREMToEquirect } from "./textureHelper.js";
|
|
6
6
|
import { Light, Material, MeshBasicMaterial, Object3D, PMREMGenerator, Texture } from "three";
|
|
7
|
-
import { registerLights, getLightData } from "./materialx.helper.js";
|
|
7
|
+
import { registerLights, getLightData, LightData } from "./materialx.helper.js";
|
|
8
8
|
import type { MaterialXMaterial } from "./materialx.material.js";
|
|
9
9
|
|
|
10
10
|
|
|
@@ -115,7 +115,7 @@ type EnvironmentTextureSet = {
|
|
|
115
115
|
export class MaterialXEnvironment {
|
|
116
116
|
private _context: Context | null = null;
|
|
117
117
|
private _lights: Array<Light> = [];
|
|
118
|
-
private _lightData:
|
|
118
|
+
private _lightData: null | LightData[] = null;
|
|
119
119
|
private _lightCount: number = 0;
|
|
120
120
|
private _initializePromise: Promise<boolean> | null = null;
|
|
121
121
|
|
|
@@ -133,7 +133,13 @@ export class MaterialXEnvironment {
|
|
|
133
133
|
return this._initializePromise = this._initialize(context);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
get lightData() {
|
|
136
|
+
get lightData() {
|
|
137
|
+
// if (this._lightData === null) {
|
|
138
|
+
// if(debug) console.warn("[MaterialX] Light data is not initialized, updating lighting");
|
|
139
|
+
// this.updateLighting(true);
|
|
140
|
+
// }
|
|
141
|
+
return this._lightData;
|
|
142
|
+
}
|
|
137
143
|
get lightCount() { return this._lightCount || 0; }
|
|
138
144
|
getTextures(material: MaterialXMaterial) {
|
|
139
145
|
if (material.envMap) {
|
|
@@ -197,7 +203,7 @@ export class MaterialXEnvironment {
|
|
|
197
203
|
this._lightCount = 0;
|
|
198
204
|
this._pmremGenerator?.dispose();
|
|
199
205
|
this._pmremGenerator = null;
|
|
200
|
-
for(const textureSet of this._texturesCache.values()) {
|
|
206
|
+
for (const textureSet of this._texturesCache.values()) {
|
|
201
207
|
textureSet.radianceTexture?.dispose();
|
|
202
208
|
textureSet.irradianceTexture?.dispose();
|
|
203
209
|
}
|