Przeglądaj źródła

ReflectorNode: Add `getDepthNode()`. (#29621)

Co-authored-by: sunag <sunagbrasil@gmail.com>
Michael Herzog 1 rok temu
rodzic
commit
09a680707b
1 zmienionych plików z 44 dodań i 5 usunięć
  1. 44 5
      src/nodes/utils/ReflectorNode.js

+ 44 - 5
src/nodes/utils/ReflectorNode.js

@@ -12,6 +12,7 @@ import { Vector3 } from '../../math/Vector3.js';
 import { Vector4 } from '../../math/Vector4.js';
 import { Vector4 } from '../../math/Vector4.js';
 import { Matrix4 } from '../../math/Matrix4.js';
 import { Matrix4 } from '../../math/Matrix4.js';
 import { RenderTarget } from '../../core/RenderTarget.js';
 import { RenderTarget } from '../../core/RenderTarget.js';
+import { DepthTexture } from '../../textures/DepthTexture.js';
 
 
 const _reflectorPlane = new Plane();
 const _reflectorPlane = new Plane();
 const _normal = new Vector3();
 const _normal = new Vector3();
@@ -30,6 +31,8 @@ const _size = new Vector2();
 const _defaultRT = new RenderTarget();
 const _defaultRT = new RenderTarget();
 const _defaultUV = screenUV.flipX();
 const _defaultUV = screenUV.flipX();
 
 
+_defaultRT.depthTexture = new DepthTexture( 1, 1 );
+
 let _inReflector = false;
 let _inReflector = false;
 
 
 class ReflectorNode extends TextureNode {
 class ReflectorNode extends TextureNode {
@@ -42,9 +45,10 @@ class ReflectorNode extends TextureNode {
 
 
 	constructor( parameters = {} ) {
 	constructor( parameters = {} ) {
 
 
-		super( _defaultRT.texture, _defaultUV );
+		super( parameters.defaultTexture || _defaultRT.texture, _defaultUV );
 
 
-		this._reflectorBaseNode = new ReflectorBaseNode( this, parameters );
+		this._reflectorBaseNode = parameters.reflector || new ReflectorBaseNode( this, parameters );
+		this._depthNode = null;
 
 
 		this.setUpdateMatrix( false );
 		this.setUpdateMatrix( false );
 
 
@@ -62,6 +66,27 @@ class ReflectorNode extends TextureNode {
 
 
 	}
 	}
 
 
+	getDepthNode() {
+
+		if ( this._depthNode === null ) {
+
+			if ( this._reflectorBaseNode.depth !== true ) {
+
+				throw new Error( 'THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ' );
+
+			}
+
+			this._depthNode = new ReflectorNode( {
+				defaultTexture: _defaultRT.depthTexture,
+				reflector: this._reflectorBaseNode
+			} );
+
+		}
+
+		return this._depthNode;
+
+	}
+
 	setup( builder ) {
 	setup( builder ) {
 
 
 		// ignore if used in post-processing
 		// ignore if used in post-processing
@@ -99,7 +124,8 @@ class ReflectorBaseNode extends Node {
 			target = new Object3D(),
 			target = new Object3D(),
 			resolution = 1,
 			resolution = 1,
 			generateMipmaps = false,
 			generateMipmaps = false,
-			bounces = true
+			bounces = true,
+			depth = false
 		} = parameters;
 		} = parameters;
 
 
 		//
 		//
@@ -110,6 +136,7 @@ class ReflectorBaseNode extends Node {
 		this.resolution = resolution;
 		this.resolution = resolution;
 		this.generateMipmaps = generateMipmaps;
 		this.generateMipmaps = generateMipmaps;
 		this.bounces = bounces;
 		this.bounces = bounces;
+		this.depth = depth;
 
 
 		this.updateBeforeType = bounces ? NodeUpdateType.RENDER : NodeUpdateType.FRAME;
 		this.updateBeforeType = bounces ? NodeUpdateType.RENDER : NodeUpdateType.FRAME;
 
 
@@ -162,8 +189,14 @@ class ReflectorBaseNode extends Node {
 
 
 			if ( this.generateMipmaps === true ) {
 			if ( this.generateMipmaps === true ) {
 
 
-			    renderTarget.texture.minFilter = LinearMipMapLinearFilter;
-			    renderTarget.texture.generateMipmaps = true;
+				renderTarget.texture.minFilter = LinearMipMapLinearFilter;
+				renderTarget.texture.generateMipmaps = true;
+
+			}
+
+			if ( this.depth === true ) {
+
+				renderTarget.depthTexture = new DepthTexture();
 
 
 			}
 			}
 
 
@@ -264,6 +297,12 @@ class ReflectorBaseNode extends Node {
 
 
 		this.textureNode.value = renderTarget.texture;
 		this.textureNode.value = renderTarget.texture;
 
 
+		if ( this.depth === true ) {
+
+			this.textureNode.getDepthNode().value = renderTarget.depthTexture;
+
+		}
+
 		material.visible = false;
 		material.visible = false;
 
 
 		const currentRenderTarget = renderer.getRenderTarget();
 		const currentRenderTarget = renderer.getRenderTarget();

粤ICP备19079148号