Răsfoiți Sursa

Reflector: Add `forceUpdate`. (#30569)

* Add needsUpdate to Reflector

* Rename needsUpdate to forceUpdate in Reflector

* Update Reflector.js

Improved code style.

* Add forceUpdate to ReflectorBaseNode

* ReflectorNode.js Eslint fix

* Update ReflectorNode.js

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
Shane 10 luni în urmă
părinte
comite
a8a6faf14b
2 a modificat fișierele cu 18 adăugiri și 4 ștergeri
  1. 5 2
      examples/jsm/objects/Reflector.js
  2. 13 2
      src/nodes/utils/ReflectorNode.js

+ 5 - 2
examples/jsm/objects/Reflector.js

@@ -21,6 +21,7 @@ class Reflector extends Mesh {
 		this.isReflector = true;
 
 		this.type = 'Reflector';
+		this.forceUpdate = false;
 		this.camera = new PerspectiveCamera();
 
 		const scope = this;
@@ -76,9 +77,10 @@ class Reflector extends Mesh {
 
 			view.subVectors( reflectorWorldPosition, cameraWorldPosition );
 
-			// Avoid rendering when reflector is facing away
+			// Avoid rendering when reflector is facing away unless forcing an update
+			const isFacingAway = view.dot( normal ) > 0;
 
-			if ( view.dot( normal ) > 0 ) return;
+			if ( isFacingAway === true && this.forceUpdate === false ) return;
 
 			view.reflect( normal ).negate();
 			view.add( reflectorWorldPosition );
@@ -172,6 +174,7 @@ class Reflector extends Mesh {
 			}
 
 			scope.visible = true;
+			this.forceUpdate = false;
 
 		};
 

+ 13 - 2
src/nodes/utils/ReflectorNode.js

@@ -273,6 +273,14 @@ class ReflectorBaseNode extends Node {
 		 */
 		this.renderTargets = new WeakMap();
 
+		/**
+		 * Force render even if reflector is facing away from camera.
+		 *
+		 * @type {boolean}
+		 * @default {false}
+		 */
+		this.forceUpdate = false;
+
 	}
 
 	/**
@@ -387,9 +395,10 @@ class ReflectorBaseNode extends Node {
 
 		_view.subVectors( _reflectorWorldPosition, _cameraWorldPosition );
 
-		// Avoid rendering when reflector is facing away
+		// Avoid rendering when reflector is facing away unless forcing an update
+		const isFacingAway = _view.dot( _normal ) > 0;
 
-		if ( _view.dot( _normal ) > 0 ) return;
+		if ( isFacingAway === true && this.forceUpdate === false ) return;
 
 		_view.reflect( _normal ).negate();
 		_view.add( _reflectorWorldPosition );
@@ -474,6 +483,8 @@ class ReflectorBaseNode extends Node {
 
 		_inReflector = false;
 
+		this.forceUpdate = false;
+
 	}
 
 }

粤ICP备19079148号