提交 1087e236 编写于 作者: M Mr.doob

Improved normal calculation on IcosahedronGeometry

UVs are hard indeed.
上级 45707694
...@@ -78,34 +78,40 @@ THREE.IcosahedronGeometry = function ( subdivisions ) { ...@@ -78,34 +78,40 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
f3(a, b, c, tempFaces); f3(a, b, c, tempFaces);
} }
tempScope.faces = tempFaces.faces; tempScope.faces = tempFaces.faces;
//tempScope.uvs = tempFaces.uvs; tempScope.faceVertexUvs[ 0 ] = tempFaces.faceVertexUvs[ 0 ];
} }
scope.faces = tempScope.faces; scope.faces = tempScope.faces;
//scope.uvs = tempScope.uvs; scope.faceVertexUvs[ 0 ] = tempScope.faceVertexUvs[ 0 ];
this.computeCentroids(); this.computeCentroids();
this.computeFaceNormals(); this.computeFaceNormals( true );
this.computeVertexNormals();
function v( x, y, z ) { function v( x, y, z ) {
var length = Math.sqrt(x * x + y * y + z * z); var length = Math.sqrt(x * x + y * y + z * z);
var i = scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x/length, y/length, z/length ) ) ); var i = scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x/length, y/length, z/length ) ) );
//var uv = getUv(x, y, z);
//temp_uv.push(uv);
return i-1; return i-1;
} }
function f3( a, b, c, inscope ) { function f3( a, b, c, inscope ) {
inscope.faces.push( new THREE.Face3( a, b, c ) );
/*inscope.uvs.push( [new THREE.UV( temp_uv[a].u, temp_uv[a].v ), var v1 = scope.vertices[ a ].position;
new THREE.UV( temp_uv[b].u, temp_uv[b].v ), var v2 = scope.vertices[ b ].position;
new THREE.UV( temp_uv[c].u, temp_uv[c].v ) var v3 = scope.vertices[ c ].position;
] );
*/ var face = new THREE.Face3( a, b, c );
face.vertexNormals.push( v1.clone().normalize(), v2.clone().normalize(), v3.clone().normalize() );
inscope.faces.push( face );
inscope.faceVertexUvs[ 0 ].push( [
new THREE.UV( Math.atan2( v1.z, v1.x ) / Math.PI, v1.y ),
new THREE.UV( Math.atan2( v2.z, v2.x ) / Math.PI, v2.y ),
new THREE.UV( Math.atan2( v3.z, v3.x ) / Math.PI, v3.y )
] );
} }
function getMiddlePoint(p1,p2) { function getMiddlePoint(p1,p2) {
...@@ -120,54 +126,6 @@ THREE.IcosahedronGeometry = function ( subdivisions ) { ...@@ -120,54 +126,6 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
return i; return i;
} }
/*function getUv(x,y,z) {
var u,v;
var px,py,pz,d;
d = Math.sqrt( x*x+y*y+z*z );
px = x/d;
py = y/d;
pz = z/d;
var normalisedX = 0;
var normalisedZ = -1;
if (((px * px) + (pz * pz)) > 0) {
normalisedX = Math.sqrt((px * px) / ((px * px) + (pz * pz)));
if (px < 0) {
normalisedX = -normalisedX;
}
normalisedZ = Math.sqrt((pz * pz) / ((px * px) + (pz * pz)));
if (pz < 0) {
normalisedZ = -normalisedZ;
}
}
if (normalisedZ == 0) {
u = ((normalisedX * Math.PI) / 2);
} else {
u = Math.atan(normalisedX / normalisedZ);
if (normalisedZ < 0) {
u += Math.PI;
}
}
if (u < 0) {
u += 2 * Math.PI;
}
u /= 2 * Math.PI;
v = (-py + 1) / 2;
return {u:u,v:v};
}*/
} }
THREE.IcosahedronGeometry.prototype = new THREE.Geometry(); THREE.IcosahedronGeometry.prototype = new THREE.Geometry();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册