Kaynağa Gözat

NodeMaterialObserver: Reuse `lightsData` cache entry per frame. (#33425)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Renaud Rohlinger 2 ay önce
ebeveyn
işleme
d59fec9f0b
1 değiştirilmiş dosya ile 14 ekleme ve 12 silme
  1. 14 12
      src/materials/nodes/manager/NodeMaterialObserver.js

+ 14 - 12
src/materials/nodes/manager/NodeMaterialObserver.js

@@ -216,7 +216,7 @@ class NodeMaterialObserver {
 
 			}
 
-			data.lights = this.getLightsData( renderObject.lightsNode.getLights() );
+			data.lights = this.getLightsData( renderObject.lightsNode.getLights(), [] );
 
 			this.renderObjects.set( renderObject, data );
 
@@ -629,9 +629,9 @@ class NodeMaterialObserver {
 	 * @param {Array<Light>} materialLights - The material lights.
 	 * @return {Array<Object>} The lights data for the given material lights.
 	 */
-	getLightsData( materialLights ) {
+	getLightsData( materialLights, lights ) {
 
-		const lights = [];
+		lights.length = 0;
 
 		for ( const light of materialLights ) {
 
@@ -658,23 +658,25 @@ class NodeMaterialObserver {
 	 */
 	getLights( lightsNode, renderId ) {
 
-		if ( _lightsCache.has( lightsNode ) ) {
+		let cached = _lightsCache.get( lightsNode );
 
-			const cached = _lightsCache.get( lightsNode );
+		if ( cached === undefined ) {
 
-			if ( cached.renderId === renderId ) {
+			cached = { renderId: - 1, lightsData: [] };
+			_lightsCache.set( lightsNode, cached );
 
-				return cached.lightsData;
+		}
 
-			}
+		if ( cached.renderId === renderId ) {
 
-		}
+			return cached.lightsData;
 
-		const lightsData = this.getLightsData( lightsNode.getLights() );
+		}
 
-		_lightsCache.set( lightsNode, { renderId, lightsData } );
+		cached.renderId = renderId;
+		this.getLightsData( lightsNode.getLights(), cached.lightsData );
 
-		return lightsData;
+		return cached.lightsData;
 
 	}
 

粤ICP备19079148号