Browse Source

Added THREE.CubeTexture.

Mr.doob 11 years ago
parent
commit
6d3415e206

+ 1 - 1
examples/webgl_materials_cubemap.html

@@ -108,7 +108,7 @@
 				var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
 				reflectionCube.format = THREE.RGBFormat;
 
-				var refractionCube = new THREE.Texture( reflectionCube.image, new THREE.CubeRefractionMapping() );
+				var refractionCube = new THREE.CubeTexture( reflectionCube.image, new THREE.CubeRefractionMapping() );
 				refractionCube.format = THREE.RGBFormat;
 
 				//var cubeMaterial3 = new THREE.MeshPhongMaterial( { color: 0x000000, specular:0xaa0000, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.25 } );

+ 7 - 7
examples/webgl_shaders_ocean.html

@@ -121,7 +121,7 @@
 
 				// load skybox
 
-				var cubeMap = new THREE.Texture( [] );
+				var cubeMap = new THREE.CubeTexture( [] );
 				cubeMap.format = THREE.RGBFormat;
 				cubeMap.flipY = false;
 
@@ -143,12 +143,12 @@
 
 					};
 
-					cubeMap.image[ 0 ] = getSide( 2, 1 ); // px
-					cubeMap.image[ 1 ] = getSide( 0, 1 ); // nx
-					cubeMap.image[ 2 ] = getSide( 1, 0 ); // py
-					cubeMap.image[ 3 ] = getSide( 1, 2 ); // ny
-					cubeMap.image[ 4 ] = getSide( 1, 1 ); // pz
-					cubeMap.image[ 5 ] = getSide( 3, 1 ); // nz
+					cubeMap.images[ 0 ] = getSide( 2, 1 ); // px
+					cubeMap.images[ 1 ] = getSide( 0, 1 ); // nx
+					cubeMap.images[ 2 ] = getSide( 1, 0 ); // py
+					cubeMap.images[ 3 ] = getSide( 1, 2 ); // ny
+					cubeMap.images[ 4 ] = getSide( 1, 1 ); // pz
+					cubeMap.images[ 5 ] = getSide( 3, 1 ); // nz
 					cubeMap.needsUpdate = true;
 
 				} );

+ 1 - 4
src/extras/ImageUtils.js

@@ -42,10 +42,7 @@ THREE.ImageUtils = {
 		var loader = new THREE.ImageLoader();
 		loader.crossOrigin = this.crossOrigin;
 		
-		var texture = new THREE.Texture();
-		texture.image = images;
-		
-		if ( mapping !== undefined ) texture.mapping = mapping;
+		var texture = new THREE.CubeTexture( images, mapping );
 
 		// no flipping needed for cube textures
 

+ 1 - 1
src/renderers/WebGLRenderer.js

@@ -4906,7 +4906,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( !texture ) continue;
 
-				if ( texture.image instanceof Array && texture.image.length === 6 ) {
+				if ( texture instanceof THREE.CubeTexture /* || ( texture.image instanceof Array && texture.image.length === 6 ) */ ) {
 
 					setCubeTexture( texture, textureUnit );
 

+ 27 - 0
src/textures/CubeTexture.js

@@ -0,0 +1,27 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ * @author alteredq / http://alteredqualia.com/
+ * @author szimek / https://github.com/szimek/
+ */
+
+THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
+
+	THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
+
+	this.images = images;
+
+};
+
+THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
+
+THREE.CubeTexture.clone = function ( texture ) {
+
+	if ( texture === undefined ) texture = new THREE.CubeTexture();
+
+	THREE.Texture.prototype.clone.call( this, texture );
+
+	texture.images = this.images;
+
+	return texture;
+
+};

+ 1 - 0
utils/build/includes/common.json

@@ -64,6 +64,7 @@
 	"src/materials/SpriteMaterial.js",
 	"src/materials/SpriteCanvasMaterial.js",
 	"src/textures/Texture.js",
+	"src/textures/CubeTexture.js",
 	"src/textures/CompressedTexture.js",
 	"src/textures/DataTexture.js",
 	"src/objects/PointCloud.js",

+ 1 - 0
utils/build/includes/webgl.json

@@ -55,6 +55,7 @@
 	"src/materials/RawShaderMaterial.js",
 	"src/materials/SpriteMaterial.js",
 	"src/textures/Texture.js",
+	"src/textures/CubeTexture.js",
 	"src/textures/CompressedTexture.js",
 	"src/textures/DataTexture.js",
 	"src/objects/PointCloud.js",