From 4d711ae49a2f467ec1d82b14cafd7f88aa04898b Mon Sep 17 00:00:00 2001 From: fuzzthink Date: Wed, 16 Mar 2011 17:20:24 -0700 Subject: [PATCH 1/4] Fixed only half bottom surfaces bug. Converted tabs to spaces. --- src/extras/geometries/Cylinder.js | 82 +++++++++++++++++-------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/src/extras/geometries/Cylinder.js b/src/extras/geometries/Cylinder.js index 235e0d8f..0c0cfe42 100644 --- a/src/extras/geometries/Cylinder.js +++ b/src/extras/geometries/Cylinder.js @@ -5,79 +5,85 @@ var Cylinder = function ( numSegs, topRad, botRad, height, topOffset, botOffset ) { - THREE.Geometry.call( this ); + THREE.Geometry.call( this ); - var scope = this, i, pi = Math.PI, halfHeight = height / 2; + var scope = this, i, pi = Math.PI, halfHeight = height / 2; - // Top circle vertices + // Top circle vertices - for ( i = 0; i < numSegs; i ++ ) { + for ( i = 0; i < numSegs; i ++ ) { - v( Math.sin( 2 * pi * i / numSegs ) * topRad, Math.cos( 2 * pi * i / numSegs ) * topRad, - halfHeight ); + v( Math.sin( 2 * pi * i / numSegs ) * topRad, Math.cos( 2 * pi * i / numSegs ) * topRad, - halfHeight ); - } + } - // Bottom circle vertices + // Bottom circle vertices - for ( i = 0; i < numSegs; i ++ ) { + for ( i = 0; i < numSegs; i ++ ) { - v( Math.sin( 2 * pi * i / numSegs ) * botRad, Math.cos( 2 * pi * i / numSegs ) * botRad, halfHeight ); + v( Math.sin( 2 * pi * i / numSegs ) * botRad, Math.cos( 2 * pi * i / numSegs ) * botRad, halfHeight ); - } + } - // Body faces + // Body faces - for ( i = 0; i < numSegs; i++ ) { + for ( i = 0; i < numSegs; i++ ) { - f4( i, i + numSegs, numSegs + ( i + 1 ) % numSegs, ( i + 1 ) % numSegs ); + f4( i, i + numSegs, numSegs + ( i + 1 ) % numSegs, ( i + 1 ) % numSegs ); - } + } - // Bottom circle faces + // Bottom circle faces - if ( botRad > 0 ) { + if ( botRad > 0 ) { - v( 0, 0, - halfHeight - ( botOffset || 0 ) ); + v( 0, 0, - halfHeight - ( botOffset || 0 ) ); - for ( i = numSegs; i < numSegs + ( numSegs / 2 ); i++ ) { + for ( i = numSegs; i < numSegs + ( numSegs / 2 ); i++ ) { - f4( 2 * numSegs, ( 2 * i - 2 * numSegs ) % numSegs, ( 2 * i - 2 * numSegs + 1 ) % numSegs, ( 2 * i - 2 * numSegs + 2 ) % numSegs ); + f4( 2 * numSegs, + ( 2 * i - 2 * numSegs ) % numSegs, + ( 2 * i - 2 * numSegs + 1 ) % numSegs, + ( 2 * i - 2 * numSegs + 2 ) % numSegs ); - } + } - } + } - // Top circle faces + // Top circle faces - if ( topRad > 0 ) { + if ( topRad > 0 ) { - v( 0, 0, halfHeight + ( topOffset || 0 ) ); + v( 0, 0, halfHeight + ( topOffset || 0 ) ); - for ( i = numSegs + ( numSegs / 2 ); i < 2 * numSegs; i ++ ) { + for ( i = numSegs + ( numSegs / 2 ); i < 2 * numSegs; i ++ ) { - f4( ( 2 * i - 2 * numSegs + 2 ) % numSegs + numSegs, ( 2 * i - 2 * numSegs + 1 ) % numSegs + numSegs, ( 2 * i - 2 * numSegs ) % numSegs+numSegs, 2 * numSegs + 1 ); + f4( 2 * numSegs + 1, + ( 2 * i - 2 * numSegs + 2 ) % numSegs + numSegs, + ( 2 * i - 2 * numSegs + 1 ) % numSegs + numSegs, + ( 2 * i - 2 * numSegs ) % numSegs + numSegs ); - } + } - } + } - this.computeCentroids(); - this.computeFaceNormals(); - // this.computeVertexNormals(); + this.computeCentroids(); + this.computeFaceNormals(); + //this.computeVertexNormals(); - function v( x, y, z ) { + function v( x, y, z ) { - scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) ); + scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) ); - } + } - function f4( a, b, c, d ) { + function f4( a, b, c, d ) { - scope.faces.push( new THREE.Face4( a, b, c, d ) ); + scope.faces.push( new THREE.Face4( a, b, c, d ) ); - } + } }; Cylinder.prototype = new THREE.Geometry(); -Cylinder.prototype.constructor = Cylinder; +Cylinder.prototype.constructor = Cylinder; \ No newline at end of file From c986eef0f9525176333ca286540c3d6f1bcaa2eb Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Thu, 17 Mar 2011 01:00:23 +0000 Subject: [PATCH 2/4] Compiled lib with new Cylinder. --- build/Three.js | 2 +- build/custom/ThreeExtras.js | 2 +- src/extras/geometries/Cylinder.js | 100 ++++++++++++++++-------------- 3 files changed, 57 insertions(+), 47 deletions(-) diff --git a/build/Three.js b/build/Three.js index 3654d55d..c64ad08c 100755 --- a/build/Three.js +++ b/build/Three.js @@ -336,7 +336,7 @@ za*X+ca,J+za*(X+1)+ca,J+1+za*(X+1)+ca,J+1+za*X+ca,null,N));t.uvs.push([new THREE k[B]);this.sides.px&&m("z","y",1*j,-1,b,c,-w,this.materials[0]);this.sides.nx&&m("z","y",-1*j,-1,b,c,w,this.materials[1]);this.sides.py&&m("x","z",1*j,1,a,b,u,this.materials[2]);this.sides.ny&&m("x","z",1*j,-1,a,b,-u,this.materials[3]);this.sides.pz&&m("x","y",1*j,-1,a,c,o,this.materials[4]);this.sides.nz&&m("x","y",-1*j,-1,a,c,-o,this.materials[5]);(function(){for(var F=[],x=[],G=0,y=t.vertices.length;G0){h(0,0,-m-(g||0));for(d=a;d0){h(0,0,m+(e||0)); -for(d=a+a/2;d<2*a;d++)j.faces.push(new THREE.Face4((2*d-2*a+2)%a+a,(2*d-2*a+1)%a+a,(2*d-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder; +for(d=a+a/2;d<2*a;d++)j.faces.push(new THREE.Face4(2*a+1,(2*d-2*a+2)%a+a,(2*d-2*a+1)%a+a,(2*d-2*a)%a+a))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder; var Icosahedron=function(a){function c(w,u,o){var v=Math.sqrt(w*w+u*u+o*o);return e.vertices.push(new THREE.Vertex(new THREE.Vector3(w/v,u/v,o/v)))-1}function b(w,u,o,v){v.faces.push(new THREE.Face3(w,u,o))}function d(w,u){var o=e.vertices[w].position,v=e.vertices[u].position;return c((o.x+v.x)/2,(o.y+v.y)/2,(o.z+v.z)/2)}var e=this,g=new THREE.Geometry,h;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;c(-1,a,0);c(1,a,0);c(-1,-a,0);c(1,-a,0);c(0,-1,a);c(0,1,a);c(0,-1,-a);c(0, 1,-a);c(a,0,-1);c(a,0,1);c(-a,0,-1);c(-a,0,1);b(0,11,5,g);b(0,5,1,g);b(0,1,7,g);b(0,7,10,g);b(0,10,11,g);b(1,5,9,g);b(5,11,4,g);b(11,10,2,g);b(10,7,6,g);b(7,1,8,g);b(3,9,4,g);b(3,4,2,g);b(3,2,6,g);b(3,6,8,g);b(3,8,9,g);b(4,9,5,g);b(2,4,11,g);b(6,2,10,g);b(8,6,7,g);b(9,8,1,g);for(a=0;a0){f(0,0,-l-(e||0));for(c=a;c0){f(0,0,l+(g||0)); -for(c=a+a/2;c<2*a;c++)h.faces.push(new THREE.Face4((2*c-2*a+2)%a+a,(2*c-2*a+1)%a+a,(2*c-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder; +for(c=a+a/2;c<2*a;c++)h.faces.push(new THREE.Face4(2*a+1,(2*c-2*a+2)%a+a,(2*c-2*a+1)%a+a,(2*c-2*a)%a+a))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder; var Icosahedron=function(a){function d(t,n,m){var p=Math.sqrt(t*t+n*n+m*m);return g.vertices.push(new THREE.Vertex(new THREE.Vector3(t/p,n/p,m/p)))-1}function b(t,n,m,p){p.faces.push(new THREE.Face3(t,n,m))}function c(t,n){var m=g.vertices[t].position,p=g.vertices[n].position;return d((m.x+p.x)/2,(m.y+p.y)/2,(m.z+p.z)/2)}var g=this,e=new THREE.Geometry,f;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;d(-1,a,0);d(1,a,0);d(-1,-a,0);d(1,-a,0);d(0,-1,a);d(0,1,a);d(0,-1,-a);d(0, 1,-a);d(a,0,-1);d(a,0,1);d(-a,0,-1);d(-a,0,1);b(0,11,5,e);b(0,5,1,e);b(0,1,7,e);b(0,7,10,e);b(0,10,11,e);b(1,5,9,e);b(5,11,4,e);b(11,10,2,e);b(10,7,6,e);b(7,1,8,e);b(3,9,4,e);b(3,4,2,e);b(3,2,6,e);b(3,6,8,e);b(3,8,9,e);b(4,9,5,e);b(2,4,11,e);b(6,2,10,e);b(8,6,7,e);b(9,8,1,e);for(a=0;a 0 ) { + if ( botRad > 0 ) { - v( 0, 0, - halfHeight - ( botOffset || 0 ) ); + v( 0, 0, - halfHeight - ( botOffset || 0 ) ); - for ( i = numSegs; i < numSegs + ( numSegs / 2 ); i++ ) { + for ( i = numSegs; i < numSegs + ( numSegs / 2 ); i++ ) { - f4( 2 * numSegs, - ( 2 * i - 2 * numSegs ) % numSegs, - ( 2 * i - 2 * numSegs + 1 ) % numSegs, - ( 2 * i - 2 * numSegs + 2 ) % numSegs ); + f4( + 2 * numSegs, + ( 2 * i - 2 * numSegs ) % numSegs, + ( 2 * i - 2 * numSegs + 1 ) % numSegs, + ( 2 * i - 2 * numSegs + 2 ) % numSegs + ); - } + } - } + } - // Top circle faces + // Top circle faces - if ( topRad > 0 ) { + if ( topRad > 0 ) { - v( 0, 0, halfHeight + ( topOffset || 0 ) ); + v( 0, 0, halfHeight + ( topOffset || 0 ) ); - for ( i = numSegs + ( numSegs / 2 ); i < 2 * numSegs; i ++ ) { + for ( i = numSegs + ( numSegs / 2 ); i < 2 * numSegs; i ++ ) { - f4( 2 * numSegs + 1, - ( 2 * i - 2 * numSegs + 2 ) % numSegs + numSegs, - ( 2 * i - 2 * numSegs + 1 ) % numSegs + numSegs, - ( 2 * i - 2 * numSegs ) % numSegs + numSegs ); + f4( + 2 * numSegs + 1, + ( 2 * i - 2 * numSegs + 2 ) % numSegs + numSegs, + ( 2 * i - 2 * numSegs + 1 ) % numSegs + numSegs, + ( 2 * i - 2 * numSegs ) % numSegs + numSegs + ); - } + } - } + } - this.computeCentroids(); - this.computeFaceNormals(); - //this.computeVertexNormals(); + this.computeCentroids(); + this.computeFaceNormals(); + // this.computeVertexNormals(); - function v( x, y, z ) { + function v( x, y, z ) { - scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) ); + scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) ); - } + } - function f4( a, b, c, d ) { + function f4( a, b, c, d ) { - scope.faces.push( new THREE.Face4( a, b, c, d ) ); + scope.faces.push( new THREE.Face4( a, b, c, d ) ); - } + } }; Cylinder.prototype = new THREE.Geometry(); -Cylinder.prototype.constructor = Cylinder; \ No newline at end of file +Cylinder.prototype.constructor = Cylinder; From a6379a26ce1d900fce98ef88d6821ac397496b4e Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Thu, 17 Mar 2011 01:03:46 +0000 Subject: [PATCH 3/4] Disabling antialias when you don't need it is always good ;) --- examples/webgl_particles_billboards.html | 4 ++-- examples/webgl_particles_billboards_colors.html | 2 +- examples/webgl_particles_random.html | 2 +- examples/webgl_particles_sprites.html | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/webgl_particles_billboards.html b/examples/webgl_particles_billboards.html index eb0f2bd5..fe3643ec 100644 --- a/examples/webgl_particles_billboards.html +++ b/examples/webgl_particles_billboards.html @@ -70,7 +70,7 @@ sprite = ImageUtils.loadTexture( "textures/sprites/circle.png" ); - for ( i = 0; i < 5000; i++ ) { + for ( i = 0; i < 10000; i++ ) { x = 2000 * Math.random() - 1000; y = 2000 * Math.random() - 1000; @@ -95,7 +95,7 @@ light.position.z = 1; scene.addLight( light ); - renderer = new THREE.WebGLRenderer( { clearAlpha: 1 }); + renderer = new THREE.WebGLRenderer( { antialias: false, clearAlpha: 1 }); renderer.setSize( window.innerWidth, window.innerHeight ); container.appendChild( renderer.domElement ); diff --git a/examples/webgl_particles_billboards_colors.html b/examples/webgl_particles_billboards_colors.html index bbea788d..2a7a3fac 100644 --- a/examples/webgl_particles_billboards_colors.html +++ b/examples/webgl_particles_billboards_colors.html @@ -99,7 +99,7 @@ light.position.z = 1; scene.addLight( light ); - renderer = new THREE.WebGLRenderer( { clearAlpha: 1 }); + renderer = new THREE.WebGLRenderer( { antialias: false, clearAlpha: 1 }); renderer.setSize( window.innerWidth, window.innerHeight ); container.appendChild( renderer.domElement ); diff --git a/examples/webgl_particles_random.html b/examples/webgl_particles_random.html index 9c729c00..cc3a023e 100644 --- a/examples/webgl_particles_random.html +++ b/examples/webgl_particles_random.html @@ -97,7 +97,7 @@ } - renderer = new THREE.WebGLRenderer(); + renderer = new THREE.WebGLRenderer( { antialias: false } ); renderer.setSize( window.innerWidth, window.innerHeight ); container.appendChild( renderer.domElement ); diff --git a/examples/webgl_particles_sprites.html b/examples/webgl_particles_sprites.html index 288f74a2..c6a1cfca 100644 --- a/examples/webgl_particles_sprites.html +++ b/examples/webgl_particles_sprites.html @@ -102,7 +102,7 @@ } - renderer = new THREE.WebGLRenderer( { clearAlpha: 1 }); + renderer = new THREE.WebGLRenderer( { antialias: false, clearAlpha: 1 }); renderer.setSize( window.innerWidth, window.innerHeight ); container.appendChild( renderer.domElement ); From dd525603699f0edc1ae3d58736f18252d19480bc Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Thu, 17 Mar 2011 04:42:46 +0000 Subject: [PATCH 4/4] Some basic performance optimisations on voxel examples. Bottleneck is still Ray caster anyway :/ --- examples/canvas_interactive_voxelpainter.html | 2 ++ examples/webgl_interactive_voxelpainter.html | 3 ++- src/core/Matrix4.js | 10 +++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/canvas_interactive_voxelpainter.html b/examples/canvas_interactive_voxelpainter.html index 341e5896..c436ae8f 100644 --- a/examples/canvas_interactive_voxelpainter.html +++ b/examples/canvas_interactive_voxelpainter.html @@ -151,6 +151,8 @@ voxel.position.x = Math.floor( position.x / 50 ) * 50 + 25; voxel.position.y = Math.floor( position.y / 50 ) * 50 + 25; voxel.position.z = Math.floor( position.z / 50 ) * 50 + 25; + voxel.matrixAutoUpdate = false; + voxel.updateMatrix(); voxel.overdraw = true; scene.addObject( voxel ); diff --git a/examples/webgl_interactive_voxelpainter.html b/examples/webgl_interactive_voxelpainter.html index 18629ced..b4e779da 100644 --- a/examples/webgl_interactive_voxelpainter.html +++ b/examples/webgl_interactive_voxelpainter.html @@ -189,7 +189,8 @@ var voxel = new THREE.Mesh( cubeGeo, cubeMaterial ); voxel.position.copy( voxelPosition ); - + voxel.matrixAutoUpdate = false; + voxel.updateMatrix(); scene.addObject( voxel ); } diff --git a/src/core/Matrix4.js b/src/core/Matrix4.js index 2695f479..a41df09e 100644 --- a/src/core/Matrix4.js +++ b/src/core/Matrix4.js @@ -72,20 +72,20 @@ THREE.Matrix4.prototype = { var x = THREE.Matrix4.__v1, y = THREE.Matrix4.__v2, z = THREE.Matrix4.__v3; z.sub( eye, center ).normalize(); - + if ( z.length() === 0 ) { - + z.z = 1; } - + x.cross( up, z ).normalize(); if ( x.length() === 0 ) { - + z.x += 0.0001; x.cross( up, z ).normalize(); - + } y.cross( z, x ).normalize();