|
|
@@ -8,6 +8,12 @@ import { CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflection
|
|
|
|
|
|
const _cache = new WeakMap();
|
|
|
|
|
|
+/**
|
|
|
+ * This node can be used to automatically convert environment maps in the
|
|
|
+ * equirectangular format into the cube map format.
|
|
|
+ *
|
|
|
+ * @augments TempNode
|
|
|
+ */
|
|
|
class CubeMapNode extends TempNode {
|
|
|
|
|
|
static get type() {
|
|
|
@@ -16,20 +22,59 @@ class CubeMapNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new cube map node.
|
|
|
+ *
|
|
|
+ * @param {Node} envNode - The node representing the environment map.
|
|
|
+ */
|
|
|
constructor( envNode ) {
|
|
|
|
|
|
super( 'vec3' );
|
|
|
|
|
|
+ /**
|
|
|
+ * The node representing the environment map.
|
|
|
+ *
|
|
|
+ * @type {Node}
|
|
|
+ */
|
|
|
this.envNode = envNode;
|
|
|
|
|
|
+ /**
|
|
|
+ * A reference to the internal cube texture.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {CubeTexture}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this._cubeTexture = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the internal cube texture node.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {CubeTextureNode}
|
|
|
+ */
|
|
|
this._cubeTextureNode = cubeTexture();
|
|
|
|
|
|
const defaultTexture = new CubeTexture();
|
|
|
defaultTexture.isRenderTargetTexture = true;
|
|
|
|
|
|
+ /**
|
|
|
+ * A default cube texture that acts as a placeholder.
|
|
|
+ * It is used when the conversion from equirectangular to cube
|
|
|
+ * map has not finished yet for a givent texture.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {CubeTexture}
|
|
|
+ */
|
|
|
this._defaultTexture = defaultTexture;
|
|
|
|
|
|
+ /**
|
|
|
+ * The `updateBeforeType` is set to `NodeUpdateType.RENDER` since the node updates
|
|
|
+ * the texture once per render in its {@link CubeMapNode#updateBefore} method.
|
|
|
+ *
|
|
|
+ * @type {String}
|
|
|
+ * @default 'render'
|
|
|
+ */
|
|
|
this.updateBeforeType = NodeUpdateType.RENDER;
|
|
|
|
|
|
}
|
|
|
@@ -117,6 +162,14 @@ class CubeMapNode extends TempNode {
|
|
|
|
|
|
export default CubeMapNode;
|
|
|
|
|
|
+/**
|
|
|
+ * Returns true if the given equirectangular image has been fully loaded
|
|
|
+ * and is ready for further processing.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @param {Image} image - The equirectangular image to check.
|
|
|
+ * @return {Boolean} Whether the image is ready or not.
|
|
|
+ */
|
|
|
function isEquirectangularMapReady( image ) {
|
|
|
|
|
|
if ( image === null || image === undefined ) return false;
|
|
|
@@ -125,6 +178,14 @@ function isEquirectangularMapReady( image ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * This function is executed when `dispose()` is called on the equirectangular
|
|
|
+ * texture. In this case, the generated cube map with its render target
|
|
|
+ * is deleted as well.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @param {Object} event - The event object.
|
|
|
+ */
|
|
|
function onTextureDispose( event ) {
|
|
|
|
|
|
const texture = event.target;
|
|
|
@@ -143,6 +204,14 @@ function onTextureDispose( event ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * This function makes sure the generated cube map uses the correct
|
|
|
+ * texture mapping that corresponds to the equirectangular original.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @param {Texture} texture - The cube texture.
|
|
|
+ * @param {Number} mapping - The original texture mapping.
|
|
|
+ */
|
|
|
function mapTextureMapping( texture, mapping ) {
|
|
|
|
|
|
if ( mapping === EquirectangularReflectionMapping ) {
|