|
@@ -9339,6 +9339,27 @@
|
|
|
CubeCamera.prototype = Object.create(Object3D.prototype);
|
|
|
CubeCamera.prototype.constructor = CubeCamera;
|
|
|
|
|
|
+ function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
|
|
|
+ images = images !== undefined ? images : [];
|
|
|
+ mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
|
|
|
+ format = format !== undefined ? format : RGBFormat;
|
|
|
+ Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
|
|
|
+ this.flipY = false;
|
|
|
+ this._needsFlipEnvMap = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ CubeTexture.prototype = Object.create(Texture.prototype);
|
|
|
+ CubeTexture.prototype.constructor = CubeTexture;
|
|
|
+ CubeTexture.prototype.isCubeTexture = true;
|
|
|
+ Object.defineProperty(CubeTexture.prototype, 'images', {
|
|
|
+ get: function get() {
|
|
|
+ return this.image;
|
|
|
+ },
|
|
|
+ set: function set(value) {
|
|
|
+ this.image = value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
function WebGLCubeRenderTarget(size, options, dummy) {
|
|
|
if (Number.isInteger(options)) {
|
|
|
console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
|
|
@@ -9346,7 +9367,9 @@
|
|
|
}
|
|
|
|
|
|
WebGLRenderTarget.call(this, size, size, options);
|
|
|
- this.texture.isWebGLCubeRenderTargetTexture = true; // HACK Why is texture not a CubeTexture?
|
|
|
+ options = options || {};
|
|
|
+ this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
|
|
|
+ this.texture._needsFlipEnvMap = false;
|
|
|
}
|
|
|
|
|
|
WebGLCubeRenderTarget.prototype = Object.create(WebGLRenderTarget.prototype);
|
|
@@ -10653,7 +10676,7 @@
|
|
|
renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
|
|
|
}
|
|
|
|
|
|
- if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.isWebGLCubeRenderTargetTexture || background.mapping === CubeUVReflectionMapping)) {
|
|
|
+ if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
|
|
|
if (boxMesh === undefined) {
|
|
|
boxMesh = new Mesh(new BoxBufferGeometry(1, 1, 1), new ShaderMaterial({
|
|
|
name: 'BackgroundCubeMaterial',
|
|
@@ -10687,7 +10710,7 @@
|
|
|
}
|
|
|
|
|
|
boxMesh.material.uniforms.envMap.value = background;
|
|
|
- boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture ? -1 : 1;
|
|
|
+ boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
|
|
|
|
|
|
if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
|
|
|
boxMesh.material.needsUpdate = true;
|
|
@@ -11881,26 +11904,6 @@
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
|
|
|
- images = images !== undefined ? images : [];
|
|
|
- mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
|
|
|
- format = format !== undefined ? format : RGBFormat;
|
|
|
- Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
|
|
|
- this.flipY = false;
|
|
|
- }
|
|
|
-
|
|
|
- CubeTexture.prototype = Object.create(Texture.prototype);
|
|
|
- CubeTexture.prototype.constructor = CubeTexture;
|
|
|
- CubeTexture.prototype.isCubeTexture = true;
|
|
|
- Object.defineProperty(CubeTexture.prototype, 'images', {
|
|
|
- get: function get() {
|
|
|
- return this.image;
|
|
|
- },
|
|
|
- set: function set(value) {
|
|
|
- this.image = value;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
function DataTexture2DArray(data, width, height, depth) {
|
|
|
Texture.call(this, null);
|
|
|
this.image = {
|
|
@@ -15287,97 +15290,15 @@
|
|
|
}
|
|
|
|
|
|
function setTextureCube(texture, slot) {
|
|
|
- if (texture.image.length !== 6) return;
|
|
|
var textureProperties = properties.get(texture);
|
|
|
|
|
|
if (texture.version > 0 && textureProperties.__version !== texture.version) {
|
|
|
- initTexture(textureProperties, texture);
|
|
|
- state.activeTexture(33984 + slot);
|
|
|
- state.bindTexture(34067, textureProperties.__webglTexture);
|
|
|
-
|
|
|
- _gl.pixelStorei(37440, texture.flipY);
|
|
|
-
|
|
|
- var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
|
|
|
- var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
|
|
|
- var cubeImage = [];
|
|
|
-
|
|
|
- for (var i = 0; i < 6; i++) {
|
|
|
- if (!isCompressed && !isDataTexture) {
|
|
|
- cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
|
|
|
- } else {
|
|
|
- cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var image = cubeImage[0],
|
|
|
- supportsMips = isPowerOfTwo(image) || isWebGL2,
|
|
|
- glFormat = utils.convert(texture.format),
|
|
|
- glType = utils.convert(texture.type),
|
|
|
- glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
|
|
|
- setTextureParameters(34067, texture, supportsMips);
|
|
|
- var mipmaps;
|
|
|
-
|
|
|
- if (isCompressed) {
|
|
|
- for (var _i = 0; _i < 6; _i++) {
|
|
|
- mipmaps = cubeImage[_i].mipmaps;
|
|
|
-
|
|
|
- for (var j = 0; j < mipmaps.length; j++) {
|
|
|
- var mipmap = mipmaps[j];
|
|
|
-
|
|
|
- if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
|
|
|
- if (glFormat !== null) {
|
|
|
- state.compressedTexImage2D(34069 + _i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
|
|
|
- } else {
|
|
|
- console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
|
|
|
- }
|
|
|
- } else {
|
|
|
- state.texImage2D(34069 + _i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- textureProperties.__maxMipLevel = mipmaps.length - 1;
|
|
|
- } else {
|
|
|
- mipmaps = texture.mipmaps;
|
|
|
-
|
|
|
- for (var _i2 = 0; _i2 < 6; _i2++) {
|
|
|
- if (isDataTexture) {
|
|
|
- state.texImage2D(34069 + _i2, 0, glInternalFormat, cubeImage[_i2].width, cubeImage[_i2].height, 0, glFormat, glType, cubeImage[_i2].data);
|
|
|
-
|
|
|
- for (var _j = 0; _j < mipmaps.length; _j++) {
|
|
|
- var _mipmap = mipmaps[_j];
|
|
|
- var mipmapImage = _mipmap.image[_i2].image;
|
|
|
- state.texImage2D(34069 + _i2, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
|
|
|
- }
|
|
|
- } else {
|
|
|
- state.texImage2D(34069 + _i2, 0, glInternalFormat, glFormat, glType, cubeImage[_i2]);
|
|
|
-
|
|
|
- for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
|
|
|
- var _mipmap2 = mipmaps[_j2];
|
|
|
- state.texImage2D(34069 + _i2, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i2]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- textureProperties.__maxMipLevel = mipmaps.length;
|
|
|
- }
|
|
|
-
|
|
|
- if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
|
|
|
- // We assume images for cube map have the same size.
|
|
|
- generateMipmap(34067, texture, image.width, image.height);
|
|
|
- }
|
|
|
-
|
|
|
- textureProperties.__version = texture.version;
|
|
|
- if (texture.onUpdate) texture.onUpdate(texture);
|
|
|
- } else {
|
|
|
- state.activeTexture(33984 + slot);
|
|
|
- state.bindTexture(34067, textureProperties.__webglTexture);
|
|
|
+ uploadCubeTexture(textureProperties, texture, slot);
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- function setTextureCubeDynamic(texture, slot) {
|
|
|
state.activeTexture(33984 + slot);
|
|
|
- state.bindTexture(34067, properties.get(texture).__webglTexture);
|
|
|
+ state.bindTexture(34067, textureProperties.__webglTexture);
|
|
|
}
|
|
|
|
|
|
var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
|
|
@@ -15530,17 +15451,17 @@
|
|
|
textureProperties.__maxMipLevel = 0;
|
|
|
}
|
|
|
} else if (texture.isCompressedTexture) {
|
|
|
- for (var _i3 = 0, _il = mipmaps.length; _i3 < _il; _i3++) {
|
|
|
- mipmap = mipmaps[_i3];
|
|
|
+ for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
|
|
|
+ mipmap = mipmaps[_i];
|
|
|
|
|
|
if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
|
|
|
if (glFormat !== null) {
|
|
|
- state.compressedTexImage2D(3553, _i3, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
|
|
|
+ state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
|
|
|
} else {
|
|
|
console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
|
|
|
}
|
|
|
} else {
|
|
|
- state.texImage2D(3553, _i3, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
|
|
|
+ state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -15557,9 +15478,9 @@
|
|
|
// if there are no manual mipmaps
|
|
|
// set 0 level mipmap and then use GL to generate other mipmap levels
|
|
|
if (mipmaps.length > 0 && supportsMips) {
|
|
|
- for (var _i4 = 0, _il2 = mipmaps.length; _i4 < _il2; _i4++) {
|
|
|
- mipmap = mipmaps[_i4];
|
|
|
- state.texImage2D(3553, _i4, glInternalFormat, glFormat, glType, mipmap);
|
|
|
+ for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
|
|
|
+ mipmap = mipmaps[_i2];
|
|
|
+ state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
|
|
|
}
|
|
|
|
|
|
texture.generateMipmaps = false;
|
|
@@ -15574,6 +15495,88 @@
|
|
|
generateMipmap(textureType, texture, image.width, image.height);
|
|
|
}
|
|
|
|
|
|
+ textureProperties.__version = texture.version;
|
|
|
+ if (texture.onUpdate) texture.onUpdate(texture);
|
|
|
+ }
|
|
|
+
|
|
|
+ function uploadCubeTexture(textureProperties, texture, slot) {
|
|
|
+ if (texture.image.length !== 6) return;
|
|
|
+ initTexture(textureProperties, texture);
|
|
|
+ state.activeTexture(33984 + slot);
|
|
|
+ state.bindTexture(34067, textureProperties.__webglTexture);
|
|
|
+
|
|
|
+ _gl.pixelStorei(37440, texture.flipY);
|
|
|
+
|
|
|
+ var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
|
|
|
+ var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
|
|
|
+ var cubeImage = [];
|
|
|
+
|
|
|
+ for (var i = 0; i < 6; i++) {
|
|
|
+ if (!isCompressed && !isDataTexture) {
|
|
|
+ cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
|
|
|
+ } else {
|
|
|
+ cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var image = cubeImage[0],
|
|
|
+ supportsMips = isPowerOfTwo(image) || isWebGL2,
|
|
|
+ glFormat = utils.convert(texture.format),
|
|
|
+ glType = utils.convert(texture.type),
|
|
|
+ glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
|
|
|
+ setTextureParameters(34067, texture, supportsMips);
|
|
|
+ var mipmaps;
|
|
|
+
|
|
|
+ if (isCompressed) {
|
|
|
+ for (var _i3 = 0; _i3 < 6; _i3++) {
|
|
|
+ mipmaps = cubeImage[_i3].mipmaps;
|
|
|
+
|
|
|
+ for (var j = 0; j < mipmaps.length; j++) {
|
|
|
+ var mipmap = mipmaps[j];
|
|
|
+
|
|
|
+ if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
|
|
|
+ if (glFormat !== null) {
|
|
|
+ state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
|
|
|
+ } else {
|
|
|
+ console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ textureProperties.__maxMipLevel = mipmaps.length - 1;
|
|
|
+ } else {
|
|
|
+ mipmaps = texture.mipmaps;
|
|
|
+
|
|
|
+ for (var _i4 = 0; _i4 < 6; _i4++) {
|
|
|
+ if (isDataTexture) {
|
|
|
+ state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
|
|
|
+
|
|
|
+ for (var _j = 0; _j < mipmaps.length; _j++) {
|
|
|
+ var _mipmap = mipmaps[_j];
|
|
|
+ var mipmapImage = _mipmap.image[_i4].image;
|
|
|
+ state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
|
|
|
+
|
|
|
+ for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
|
|
|
+ var _mipmap2 = mipmaps[_j2];
|
|
|
+ state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ textureProperties.__maxMipLevel = mipmaps.length;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
|
|
|
+ // We assume images for cube map have the same size.
|
|
|
+ generateMipmap(34067, texture, image.width, image.height);
|
|
|
+ }
|
|
|
+
|
|
|
textureProperties.__version = texture.version;
|
|
|
if (texture.onUpdate) texture.onUpdate(texture);
|
|
|
} // Render targets
|
|
@@ -15876,18 +15879,9 @@
|
|
|
}
|
|
|
|
|
|
texture = texture.texture;
|
|
|
- } // currently relying on the fact that WebGLCubeRenderTarget.texture is a Texture and NOT a CubeTexture
|
|
|
- // TODO: unify these code paths
|
|
|
-
|
|
|
-
|
|
|
- if (texture && texture.isCubeTexture || Array.isArray(texture.image) && texture.image.length === 6) {
|
|
|
- // CompressedTexture can have Array in image :/
|
|
|
- // this function alone should take care of cube textures
|
|
|
- setTextureCube(texture, slot);
|
|
|
- } else {
|
|
|
- // assumed: texture property of THREE.WebGLCubeRenderTarget
|
|
|
- setTextureCubeDynamic(texture, slot);
|
|
|
}
|
|
|
+
|
|
|
+ setTextureCube(texture, slot);
|
|
|
} //
|
|
|
|
|
|
|
|
@@ -15897,7 +15891,6 @@
|
|
|
this.setTexture2DArray = setTexture2DArray;
|
|
|
this.setTexture3D = setTexture3D;
|
|
|
this.setTextureCube = setTextureCube;
|
|
|
- this.setTextureCubeDynamic = setTextureCubeDynamic;
|
|
|
this.setupRenderTarget = setupRenderTarget;
|
|
|
this.updateRenderTargetMipmap = updateRenderTargetMipmap;
|
|
|
this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
|
|
@@ -16666,7 +16659,7 @@
|
|
|
|
|
|
if (envMap) {
|
|
|
uniforms.envMap.value = envMap;
|
|
|
- uniforms.flipEnvMap.value = envMap.isCubeTexture ? -1 : 1;
|
|
|
+ uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
|
|
|
uniforms.reflectivity.value = material.reflectivity;
|
|
|
uniforms.refractionRatio.value = material.refractionRatio;
|
|
|
|