提交 10e21dde 编写于 作者: M Mr.doob

`Geometry::computeNormals` → `Geometry::computeFaceNormals`

上级 1053ab24
......@@ -44,7 +44,7 @@ THREE.Face3=function(a,b,d,g,j){this.a=a;this.b=b;this.c=d;this.centroid=new THR
THREE.Face4=function(a,b,d,g,j,n){this.a=a;this.b=b;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=n instanceof Array?n:[n]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,g,j,n,m,l=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){l.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)l.addSelf(n.vertexNormals[b]);l.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];l.sub(m.position,
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,d,g,j,n,m,l=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){l.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)l.addSelf(n.vertexNormals[b]);l.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];l.sub(m.position,
d.position);o.sub(b.position,d.position);l.crossSelf(o)}l.isZero()||l.normalize();n.normal.copy(l)}},computeVertexNormals:function(){var a,b=[],d,g;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal)}else if(g instanceof THREE.Face4){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal);b[g.d].addSelf(g.normal)}}a=
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone()}else if(g instanceof THREE.Face4){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone();g.vertexNormals[3]=b[g.d].clone()}}},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={x:[this.vertices[0].position.x,
this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;
......
......@@ -44,7 +44,7 @@ THREE.Face3=function(a,b,d,g,j){this.a=a;this.b=b;this.c=d;this.centroid=new THR
THREE.Face4=function(a,b,d,g,j,n){this.a=a;this.b=b;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=n instanceof Array?n:[n]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,g,j,n,m,k=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){k.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)k.addSelf(n.vertexNormals[b]);k.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];k.sub(m.position,
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,d,g,j,n,m,k=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){k.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)k.addSelf(n.vertexNormals[b]);k.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];k.sub(m.position,
d.position);o.sub(b.position,d.position);k.crossSelf(o)}k.isZero()||k.normalize();n.normal.copy(k)}},computeVertexNormals:function(){var a,b=[],d,g;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal)}else if(g instanceof THREE.Face4){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal);b[g.d].addSelf(g.normal)}}a=
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone()}else if(g instanceof THREE.Face4){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone();g.vertexNormals[3]=b[g.d].clone()}}},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={x:[this.vertices[0].position.x,
this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;
......
此差异已折叠。
......@@ -80,7 +80,6 @@
}
plane.computeNormals();
plane.computeCentroids();
mesh = new THREE.Mesh( plane, material );
......
......@@ -87,10 +87,6 @@
}
// geometry.computeNormals();
// geometry.computeVertexNormals();
// geometry.sortFacesByMaterial();
texture = new THREE.Texture( generateTexture( data, worldWidth, worldDepth ), new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping );
mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map: texture } ) );
......
......@@ -2,7 +2,7 @@ var Bird = function () {
var scope = this;
THREE.Geometry.call(this);
THREE.Geometry.call( this );
v( 5, 0, 0 );
v( - 5, - 2, 1 );
......@@ -21,7 +21,7 @@ var Bird = function () {
f3( 5, 6, 7 );
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
function v( x, y, z ) {
......
......@@ -1434,7 +1434,7 @@ var Qrcode = function () {
f4(19,20,362,361,m2);
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
function v( x, y, z ) {
......
......@@ -4884,7 +4884,7 @@ var WaltHead = function () {
f3( 1222, 991, 646 );
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
function v( x, y, z ) {
......
......@@ -185,7 +185,7 @@
geometry.faces.push( face );
}
geometry.computeNormals();
geometry.computeFaceNormals();
geometry.computeCentroids();
geometry.sortFacesByMaterial();
......
......@@ -46,7 +46,7 @@ THREE.Geometry.prototype = {
},
computeNormals: function ( useVertexNormals ) {
computeFaceNormals: function ( useVertexNormals ) {
var n, nl, v, vl, vertex, f, fl, face, vA, vB, vC,
cb = new THREE.Vector3(), ab = new THREE.Vector3();
......
......@@ -244,7 +244,7 @@ THREE.Loader.prototype = {
currentOffset += init_quads_smooth_uv( currentOffset );
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
//var e = (new Date).getTime();
......@@ -706,7 +706,7 @@ THREE.Loader.prototype = {
init_faces();
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
function init_vertices() {
......
......@@ -173,7 +173,7 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
}
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
}
......
......@@ -2,82 +2,80 @@
* @author kile / http://kile.stravaganza.org/
*/
var Cylinder = function (numSegs, topRad, botRad, height, topOffset, botOffset) {
var Cylinder = function ( numSegs, topRad, botRad, height, topOffset, botOffset ) {
THREE.Geometry.call(this);
THREE.Geometry.call( this );
var scope = this, i;
var scope = this,
pi = Math.PI, i;
// 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, 0 );
v(
Math.sin(2 * 3.1415 * i / numSegs)*topRad,
Math.cos(2 * 3.1415 * i / numSegs)*topRad,
0);
}
// 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, height );
v(
Math.sin(2 * 3.1415 * i / numSegs)*botRad,
Math.cos(2 * 3.1415 * i / numSegs)*botRad,
height);
}
// FACES
// Body
for (i = 0; i < numSegs; i++) {
for ( i = 0; i < numSegs; i++ ) {
f4(i, i + numSegs, numSegs + (i + 1) % numSegs, (i + 1) % numSegs, '#ff0000');
f4( i, i + numSegs, numSegs + ( i + 1 ) % numSegs, ( i + 1 ) % numSegs, '#ff0000' );
}
// Bottom circle
if (botRad != 0) {
if ( botRad != 0 ) {
v( 0, 0, - topOffset );
v(0, 0, -topOffset);
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
if (topRad != 0) {
if ( topRad != 0 ) {
v( 0, 0, height + topOffset );
v(0, 0, height + topOffset);
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 * i - 2 * numSegs + 2) % numSegs + numSegs,
(2 * i - 2 * numSegs + 1) % numSegs + numSegs,
(2 * i - 2 * numSegs) % numSegs+numSegs,
2 * numSegs + 1);
}
}
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
function v(x, y, z) {
function v( 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 ) );
}
}
Cylinder.prototype = new THREE.Geometry();
......
......@@ -53,7 +53,7 @@ var Plane = function ( width, height, segments_width, segments_height ) {
}
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.sortFacesByMaterial();
}
......
......@@ -10,7 +10,7 @@ var Sphere = function ( radius, segments_width, segments_height ) {
var gridX = segments_width || 8,
gridY = segments_height || 6;
var i, j;
var i, j, pi = Math.PI;
var iHor = Math.max( 3, gridX );
var iVer = Math.max( 2, gridY );
var aVtc = [];
......@@ -18,16 +18,16 @@ var Sphere = function ( radius, segments_width, segments_height ) {
for ( j = 0; j < ( iVer + 1 ) ; j++ ) {
var fRad1 = j / iVer;
var fZ = radius * Math.cos( fRad1 * Math.PI );
var fRds = radius * Math.sin( fRad1 * Math.PI );
var fZ = radius * Math.cos( fRad1 * pi );
var fRds = radius * Math.sin( fRad1 * pi );
var aRow = [];
var oVtx = 0;
for ( i = 0; i < iHor; i++ ) {
var fRad2 = 2 * i / iHor;
var fX = fRds * Math.sin( fRad2 * Math.PI );
var fY = fRds * Math.cos( fRad2 * Math.PI );
var fX = fRds * Math.sin( fRad2 * pi );
var fY = fRds * Math.cos( fRad2 * pi );
if ( !( ( j == 0 || j == iVer ) && i > 0 ) ) {
......@@ -104,7 +104,8 @@ var Sphere = function ( radius, segments_width, segments_height ) {
}
this.computeCentroids();
this.computeNormals();
this.computeFaceNormals();
this.computeVertexNormals();
this.sortFacesByMaterial();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册