Skip to content

Commit b409e5b

Browse files
committed
Proper merge with mrdoob's branch.
All cube mapping examples should work and be consistent between MeshCubeMaterial and 6 texture versions.
2 parents 9cd7308 + a1d014c commit b409e5b

35 files changed

+680
-632
lines changed

build/Three.js

+83-83
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/ThreeDebug.js

+85-85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/geometry_vr.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@
6969
context.fillRect( 0, 0, texture_placeholder.width, texture_placeholder.height );
7070

7171
var materials = [];
72-
materials.push( [ loadTexture( 'textures/skymap_px.jpg' ), wireframe ] ); // right
73-
materials.push( [ loadTexture( 'textures/skymap_nx.jpg' ), wireframe ] ); // left
74-
materials.push( [ loadTexture( 'textures/skymap_py.jpg' ), wireframe ] ); // top
75-
materials.push( [ loadTexture( 'textures/skymap_ny.jpg' ), wireframe ] ); // bottom
76-
materials.push( [ loadTexture( 'textures/skymap_pz.jpg' ), wireframe ] ); // back
77-
materials.push( [ loadTexture( 'textures/skymap_nz.jpg' ), wireframe ] ); // front
72+
materials.push( [ loadTexture( 'textures/cube/skybox/px.jpg' ), wireframe ] ); // right
73+
materials.push( [ loadTexture( 'textures/cube/skybox/nx.jpg' ), wireframe ] ); // left
74+
materials.push( [ loadTexture( 'textures/cube/skybox/py.jpg' ), wireframe ] ); // top
75+
materials.push( [ loadTexture( 'textures/cube/skybox/ny.jpg' ), wireframe ] ); // bottom
76+
materials.push( [ loadTexture( 'textures/cube/skybox/pz.jpg' ), wireframe ] ); // back
77+
materials.push( [ loadTexture( 'textures/cube/skybox/nz.jpg' ), wireframe ] ); // front
7878

7979
mesh = new THREE.Mesh( new Cube( 300, 300, 300, 7, 7, materials, true ), new THREE.MeshFaceMaterial() );
8080
mesh.overdraw = true;
@@ -198,7 +198,7 @@
198198

199199
lat = Math.max( - 85, Math.min( 85, lat ) );
200200
phi = ( 90 - lat ) * Math.PI / 180;
201-
theta = ( lon + 180 ) * Math.PI / 180;
201+
theta = lon * Math.PI / 180;
202202

203203
camera.target.position.x = 500 * Math.sin( phi ) * Math.cos( theta );
204204
camera.target.position.y = 500 * Math.cos( phi );

examples/materials_cubemap.html

+11-18
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
4141
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
4242
<script type="text/javascript" src="../src/extras/io/Loader.js"></script>
43-
43+
<script type="text/javascript" src="../src/extras/ImageUtils.js"></script>
44+
4445
<script type="text/javascript" src="js/Stats.js"></script>
4546

4647
<script type="text/javascript">
@@ -93,24 +94,16 @@
9394
lightMesh.scale.x = lightMesh.scale.y = lightMesh.scale.z = 0.05;
9495
scene.addObject(lightMesh);
9596

96-
// material samples
97-
var r = "textures/cube/SwedishRoyalCastle/";
97+
var path = "textures/cube/SwedishRoyalCastle/";
98+
var format = '.jpg';
99+
var urls = [
100+
path + 'px' + format, path + 'nx' + format,
101+
path + 'py' + format, path + 'ny' + format,
102+
path + 'pz' + format, path + 'nz' + format
103+
];
104+
105+
var images = ImageUtils.loadArray( urls );
98106

99-
/* right-handed */
100-
101-
var urls = [ r + "px.jpg", r + "nx.jpg",
102-
r + "py.jpg", r + "ny.jpg",
103-
r + "pz.jpg", r + "nz.jpg" ];
104-
105-
/* left handed */
106-
/*
107-
var urls = [ r + "nx.jpg", r + "px.jpg",
108-
r + "py.jpg", r + "ny.jpg",
109-
r + "pz.jpg", r + "nz.jpg" ];
110-
*/
111-
112-
var images = THREE.loadImageArray( urls );
113-
114107
var reflectionCube = new THREE.TextureCube( images );
115108
var refractionCube = new THREE.TextureCube( images, THREE.RefractionMap );
116109

examples/materials_cubemap_sky.html examples/materials_cubemap_balls_reflection.html

+15-10
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
</head>
3131

3232
<body>
33-
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl cube reflection demo. skybox by <a href="http://www.zfight.com/" target="_blank">Jochum Skoglund</a></div>
33+
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl cube reflection demo. skybox by <a href="http://ict.debevec.org/~debevec/" target="_blank">Paul Debevec</a></div>
3434

3535
<script type="text/javascript" src="../build/Three.js"></script>
3636

3737
<script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
3838
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
39-
4039
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
4140
<script type="text/javascript" src="../src/extras/GeometryUtils.js"></script>
41+
<script type="text/javascript" src="../src/extras/ImageUtils.js"></script>
4242

4343
<script type="text/javascript" src="js/Stats.js"></script>
4444

@@ -92,24 +92,29 @@
9292
// Merging spheres in a single geometry
9393

9494
GeometryUtils.merge( geometry, sphere );
95-
9695
}
9796

98-
var r = "textures/skymap_";
99-
var urls = [ r + "px.jpg", r + "nx.jpg",
100-
r + "py.jpg", r + "ny.jpg",
101-
r + "pz.jpg", r + "nz.jpg" ];
97+
var path = "textures/cube/pisa/";
98+
var format = '.png';
99+
var urls = [
100+
path + 'px' + format, path + 'nx' + format,
101+
path + 'py' + format, path + 'ny' + format,
102+
path + 'pz' + format, path + 'nz' + format
103+
];
102104

103-
var images = THREE.loadImageArray( urls );
105+
var images = ImageUtils.loadArray( urls );
104106
var textureCube = new THREE.TextureCube( images );
107+
// var textureCube = new THREE.TextureCube( images, THREE.RefractionMap );
108+
105109
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, env_map: textureCube } );
106110

107111
var mesh = new THREE.Mesh( geometry, material );
112+
mesh.position.x = 100;
108113
scene.addObject( mesh );
109114

110115
//createCubePlanes( 100000, images );
111-
createCube( 100000, images );
112-
//createCubeWebGL( 100000, textureCube );
116+
//createCube( 100000, images );
117+
createCubeWebGL( 100000, textureCube );
113118

114119
webglRenderer = new THREE.WebGLRenderer( scene );
115120
webglRenderer.setSize( window.innerWidth, window.innerHeight );

examples/materials_cubemap_sky_refraction.html examples/materials_cubemap_balls_refraction.html

+9-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
3939
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
4040
<script type="text/javascript" src="../src/extras/GeometryUtils.js"></script>
41+
<script type="text/javascript" src="../src/extras/ImageUtils.js"></script>
4142

4243
<script type="text/javascript" src="js/Stats.js"></script>
4344

@@ -92,12 +93,15 @@
9293
GeometryUtils.merge( geometry, sphere );
9394
}
9495

95-
var r = "textures/skymap_";
96-
var urls = [ r + "px.jpg", r + "nx.jpg",
97-
r + "py.jpg", r + "ny.jpg",
98-
r + "pz.jpg", r + "nz.jpg" ];
96+
var path = "textures/cube/skybox/";
97+
var format = '.jpg';
98+
var urls = [
99+
path + 'px' + format, path + 'nx' + format,
100+
path + 'py' + format, path + 'ny' + format,
101+
path + 'pz' + format, path + 'nz' + format
102+
];
99103

100-
var images = THREE.loadImageArray( urls );
104+
var images = ImageUtils.loadArray( urls );
101105
var textureCube = new THREE.TextureCube( images, THREE.RefractionMap );
102106
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, env_map: textureCube, refraction_ratio: 0.75 } );
103107

examples/materials_cubemap_escher.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
3636
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
3737
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
38+
<script type="text/javascript" src="../src/extras/ImageUtils.js"></script>
3839

3940
<script type="text/javascript" src="js/Stats.js"></script>
4041

@@ -78,7 +79,7 @@
7879
r + "py.jpg", r + "ny.jpg",
7980
r + "pz.jpg", r + "nz.jpg" ];
8081

81-
var images = THREE.loadImageArray( urls );
82+
var images = ImageUtils.loadArray( urls );
8283

8384
var textureCube = new THREE.TextureCube( images );
8485
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, env_map: textureCube } )
@@ -89,8 +90,8 @@
8990
scene.addObject( mesh );
9091

9192
//createCubePlanes( 6000, images );
92-
createCube( 6000, images );
93-
//createCubeWebGL( 6000, textureCube );
93+
//createCube( 6000, images );
94+
createCubeWebGL( 6000, textureCube );
9495

9596
webglRenderer = new THREE.WebGLRenderer( scene );
9697
webglRenderer.setSize( window.innerWidth, window.innerHeight );

examples/materials_cubemap_refraction.html

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
4040
<script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
4141
<script type="text/javascript" src="../src/extras/io/Loader.js"></script>
42+
<script type="text/javascript" src="../src/extras/ImageUtils.js"></script>
4243

4344
<script type="text/javascript" src="js/Stats.js"></script>
4445

@@ -102,7 +103,7 @@
102103
r + "py.jpg", r + "ny.jpg",
103104
r + "pz.jpg", r + "nz.jpg" ];
104105

105-
var images = THREE.loadImageArray( urls );
106+
var images = ImageUtils.loadArray( urls );
106107
var textureCube = new THREE.TextureCube( images, THREE.RefractionMap );
107108

108109
var cubeMaterial3 = new THREE.MeshBasicMaterial( { color: 0xccddff, env_map: textureCube, refraction_ratio: 0.98, reflectivity:0.9 } );
@@ -181,12 +182,12 @@
181182
function createCube( size, images ) {
182183

183184
var materials = [];
184-
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[1] ) } ) );
185185
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[0] ) } ) );
186-
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[4] ) } ) );
187-
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[5] ) } ) );
186+
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[1] ) } ) );
188187
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[2] ) } ) );
189188
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[3] ) } ) );
189+
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[4] ) } ) );
190+
materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[5] ) } ) );
190191

191192
mesh = new THREE.Mesh( new Cube( size, size, size, 1, 1, materials, true ), new THREE.MeshFaceMaterial() );
192193
sceneCube.addObject( mesh );
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Author
2+
======
3+
4+
This is the work of Emil Persson, aka Humus.
5+
http://www.humus.name
6+
7+
8+
9+
10+
Legal stuff
11+
===========
12+
13+
This work is free and may be used by anyone for any purpose
14+
and may be distributed freely to anyone using any distribution
15+
media or distribution method as long as this file is included.
16+
Distribution without this file is allowed if it's distributed
17+
with free non-commercial software; however, fair credit of the
18+
original author is expected.
19+
Any commercial distribution of this software requires the written
20+
approval of Emil Persson.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Author
2+
======
3+
4+
This is the work of Emil Persson, aka Humus.
5+
http://www.humus.name
6+
7+
8+
9+
10+
Legal stuff
11+
===========
12+
13+
This work is free and may be used by anyone for any purpose
14+
and may be distributed freely to anyone using any distribution
15+
media or distribution method as long as this file is included.
16+
Distribution without this file is allowed if it's distributed
17+
with free non-commercial software; however, fair credit of the
18+
original author is expected.
19+
Any commercial distribution of this software requires the written
20+
approval of Emil Persson.

examples/textures/cube/pisa/nx.png

61.5 KB
Loading

examples/textures/cube/pisa/ny.png

80.3 KB
Loading

examples/textures/cube/pisa/nz.png

83 KB
Loading

examples/textures/cube/pisa/px.png

71.2 KB
Loading

examples/textures/cube/pisa/py.png

74.8 KB
Loading

examples/textures/cube/pisa/pz.png

86.6 KB
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60.8 KB
Loading
58.8 KB
Loading
58.1 KB
Loading
66.7 KB
Loading
28.8 KB
Loading
63.8 KB
Loading

src/extras/ImageUtils.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var ImageUtils = {
2+
3+
loadArray: function ( array ) {
4+
5+
var i, l, images = [];
6+
7+
images.loadCount = 0;
8+
9+
for ( i = 0, l = array.length; i < l; ++i ) {
10+
11+
images[ i ] = new Image();
12+
images[ i ].loaded = 0;
13+
images[ i ].onload = function () { images.loadCount += 1; this.loaded = 1; }
14+
images[ i ].src = array[ i ];
15+
16+
}
17+
18+
return images;
19+
20+
}
21+
22+
}

src/extras/primitives/Cube.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
3737

3838
}
3939

40-
buildPlane( 'z', 'y', - 1 * flip, - 1, depth, height, width_half, this.materials[ 0 ] ); // right
41-
buildPlane( 'z', 'y', 1 * flip, - 1, depth, height, - width_half, this.materials[ 1 ] ); // left
42-
43-
buildPlane( 'x', 'z', - 1 * flip, - 1, width, depth, height_half, this.materials[ 2 ] ); // top
44-
buildPlane( 'x', 'z', - 1 * flip, 1, width, depth, - height_half, this.materials[ 3 ] ); // bottom
45-
46-
buildPlane( 'x', 'y', 1 * flip, - 1, width, height, depth_half, this.materials[ 4 ] ); // back
47-
buildPlane( 'x', 'y', - 1 * flip, - 1, width, height, - depth_half, this.materials[ 5 ] ); // front
40+
buildPlane( 'z', 'y', 1 * flip, - 1, depth, height, - width_half, this.materials[ 0 ] ); // px
41+
buildPlane( 'z', 'y', - 1 * flip, - 1, depth, height, width_half, this.materials[ 1 ] ); // nx
42+
buildPlane( 'x', 'z', 1 * flip, 1, width, depth, height_half, this.materials[ 2 ] ); // py
43+
buildPlane( 'x', 'z', 1 * flip, - 1, width, depth, - height_half, this.materials[ 3 ] ); // ny
44+
buildPlane( 'x', 'y', 1 * flip, - 1, width, height, depth_half, this.materials[ 4 ] ); // pz
45+
buildPlane( 'x', 'y', - 1 * flip, - 1, width, height, - depth_half, this.materials[ 5 ] ); // nz
4846

4947
mergeVertices();
5048

src/materials/textures/TextureCube.js

-20
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,3 @@ THREE.TextureCube = function ( image, mapping ) {
1919
};
2020

2121
};
22-
23-
THREE.loadImageArray = function ( urls ) {
24-
25-
var i, images = [];
26-
27-
images.loadCount = 0;
28-
29-
for ( i = 0; i < urls.length; ++i ) {
30-
31-
images[i] = new Image();
32-
images[i].loaded = 0;
33-
images[i].onload = function() { images.loadCount += 1; this.loaded = 1; }
34-
images[i].src = urls[i];
35-
36-
}
37-
38-
return images;
39-
40-
};
41-

src/renderers/CanvasRenderer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ THREE.CanvasRenderer = function () {
3333
_bboxRect = new THREE.Rectangle(),
3434

3535
_enableLighting = false,
36-
_color = new THREE.Color( 0xffffffff ),
37-
_light = new THREE.Color( 0xffffffff ),
38-
_ambientLight = new THREE.Color( 0xff000000 ),
39-
_directionalLights = new THREE.Color( 0xff000000 ),
40-
_pointLights = new THREE.Color( 0xff000000 ),
36+
_color = new THREE.Color( 0xffffff ),
37+
_light = new THREE.Color( 0xffffff ),
38+
_ambientLight = new THREE.Color( 0x000000 ),
39+
_directionalLights = new THREE.Color( 0x000000 ),
40+
_pointLights = new THREE.Color( 0x000000 ),
4141

4242
_pi2 = Math.PI * 2,
4343
_vector3 = new THREE.Vector3(), // Needed for PointLight

0 commit comments

Comments
 (0)