|
@@ -3,22 +3,21 @@ import { texture as TSL_Texture } from '../../nodes/accessors/TextureNode.js';
|
|
|
import { positionWorldDirection } from '../../nodes/accessors/Position.js';
|
|
import { positionWorldDirection } from '../../nodes/accessors/Position.js';
|
|
|
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
|
|
|
|
|
|
-import { WebGLCubeRenderTarget } from '../../renderers/WebGLCubeRenderTarget.js';
|
|
|
|
|
|
|
+import { RenderTarget } from '../../core/RenderTarget.js';
|
|
|
import { Scene } from '../../scenes/Scene.js';
|
|
import { Scene } from '../../scenes/Scene.js';
|
|
|
import { CubeCamera } from '../../cameras/CubeCamera.js';
|
|
import { CubeCamera } from '../../cameras/CubeCamera.js';
|
|
|
import { BoxGeometry } from '../../geometries/BoxGeometry.js';
|
|
import { BoxGeometry } from '../../geometries/BoxGeometry.js';
|
|
|
import { Mesh } from '../../objects/Mesh.js';
|
|
import { Mesh } from '../../objects/Mesh.js';
|
|
|
|
|
+import { CubeTexture } from '../../textures/CubeTexture.js';
|
|
|
import { BackSide, NoBlending, LinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
|
|
import { BackSide, NoBlending, LinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
|
|
|
|
|
|
|
|
-// @TODO: Consider rename WebGLCubeRenderTarget to just CubeRenderTarget
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* This class represents a cube render target. It is a special version
|
|
* This class represents a cube render target. It is a special version
|
|
|
* of `WebGLCubeRenderTarget` which is compatible with `WebGPURenderer`.
|
|
* of `WebGLCubeRenderTarget` which is compatible with `WebGPURenderer`.
|
|
|
*
|
|
*
|
|
|
- * @augments WebGLCubeRenderTarget
|
|
|
|
|
|
|
+ * @augments RenderTarget
|
|
|
*/
|
|
*/
|
|
|
-class CubeRenderTarget extends WebGLCubeRenderTarget {
|
|
|
|
|
|
|
+class CubeRenderTarget extends RenderTarget {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Constructs a new cube render target.
|
|
* Constructs a new cube render target.
|
|
@@ -28,7 +27,7 @@ class CubeRenderTarget extends WebGLCubeRenderTarget {
|
|
|
*/
|
|
*/
|
|
|
constructor( size = 1, options = {} ) {
|
|
constructor( size = 1, options = {} ) {
|
|
|
|
|
|
|
|
- super( size, options );
|
|
|
|
|
|
|
+ super( size, size, options );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* This flag can be used for type testing.
|
|
* This flag can be used for type testing.
|
|
@@ -39,6 +38,27 @@ class CubeRenderTarget extends WebGLCubeRenderTarget {
|
|
|
*/
|
|
*/
|
|
|
this.isCubeRenderTarget = true;
|
|
this.isCubeRenderTarget = true;
|
|
|
|
|
|
|
|
|
|
+ const image = { width: size, height: size, depth: 1 };
|
|
|
|
|
+ const images = [ image, image, image, image, image, image ];
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Overwritten with a different texture type.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @type {DataArrayTexture}
|
|
|
|
|
+ */
|
|
|
|
|
+ this.texture = new CubeTexture( images );
|
|
|
|
|
+ this._setTextureOptions( options );
|
|
|
|
|
+
|
|
|
|
|
+ // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
|
|
|
|
|
+ // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
|
|
|
|
|
+ // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
|
|
|
|
|
+
|
|
|
|
|
+ // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
|
|
|
|
|
+ // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
|
|
|
|
|
+ // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
|
|
|
|
|
+
|
|
|
|
|
+ this.texture.isRenderTargetTexture = true;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -98,6 +118,30 @@ class CubeRenderTarget extends WebGLCubeRenderTarget {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Clears this cube render target.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {Renderer} renderer - The renderer.
|
|
|
|
|
+ * @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
|
|
|
|
|
+ * @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
|
|
|
|
|
+ * @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
|
|
|
|
|
+ */
|
|
|
|
|
+ clear( renderer, color = true, depth = true, stencil = true ) {
|
|
|
|
|
+
|
|
|
|
|
+ const currentRenderTarget = renderer.getRenderTarget();
|
|
|
|
|
+
|
|
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
+
|
|
|
|
|
+ renderer.setRenderTarget( this, i );
|
|
|
|
|
+
|
|
|
|
|
+ renderer.clear( color, depth, stencil );
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ renderer.setRenderTarget( currentRenderTarget );
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default CubeRenderTarget;
|
|
export default CubeRenderTarget;
|