Skip to content

Commit 10e21dd

Browse files
committed
Geometry::computeNormalsGeometry::computeFaceNormals
1 parent 1053ab2 commit 10e21dd

15 files changed

+614
-620
lines changed

build/Three.js

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

build/ThreeDebug.js

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

build/ThreeExtras.js

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

examples/geometry_terrain.html

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080

8181
}
8282

83-
plane.computeNormals();
8483
plane.computeCentroids();
8584

8685
mesh = new THREE.Mesh( plane, material );

examples/geometry_terrain_gl.html

-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@
8787

8888
}
8989

90-
// geometry.computeNormals();
91-
// geometry.computeVertexNormals();
92-
// geometry.sortFacesByMaterial();
93-
9490
texture = new THREE.Texture( generateTexture( data, worldWidth, worldDepth ), new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping );
9591

9692
mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map: texture } ) );

examples/obj/Bird.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var Bird = function () {
22

33
var scope = this;
44

5-
THREE.Geometry.call(this);
5+
THREE.Geometry.call( this );
66

77
v( 5, 0, 0 );
88
v( - 5, - 2, 1 );
@@ -21,7 +21,7 @@ var Bird = function () {
2121
f3( 5, 6, 7 );
2222

2323
this.computeCentroids();
24-
this.computeNormals();
24+
this.computeFaceNormals();
2525
this.sortFacesByMaterial();
2626

2727
function v( x, y, z ) {

examples/obj/Qrcode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ var Qrcode = function () {
14341434
f4(19,20,362,361,m2);
14351435

14361436
this.computeCentroids();
1437-
this.computeNormals();
1437+
this.computeFaceNormals();
14381438
this.sortFacesByMaterial();
14391439

14401440
function v( x, y, z ) {

examples/obj/WaltHead.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4884,7 +4884,7 @@ var WaltHead = function () {
48844884
f3( 1222, 991, 646 );
48854885

48864886
this.computeCentroids();
4887-
this.computeNormals();
4887+
this.computeFaceNormals();
48884888
this.sortFacesByMaterial();
48894889

48904890
function v( x, y, z ) {
@@ -4908,4 +4908,4 @@ var WaltHead = function () {
49084908
}
49094909

49104910
WaltHead.prototype = new THREE.Geometry();
4911-
WaltHead.prototype.constructor = WaltHead;
4911+
WaltHead.prototype.constructor = WaltHead;

examples/uqbiquity_test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
geometry.faces.push( face );
186186
}
187187

188-
geometry.computeNormals();
188+
geometry.computeFaceNormals();
189189
geometry.computeCentroids();
190190
geometry.sortFacesByMaterial();
191191

src/core/Geometry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ THREE.Geometry.prototype = {
4646

4747
},
4848

49-
computeNormals: function ( useVertexNormals ) {
49+
computeFaceNormals: function ( useVertexNormals ) {
5050

5151
var n, nl, v, vl, vertex, f, fl, face, vA, vB, vC,
5252
cb = new THREE.Vector3(), ab = new THREE.Vector3();

src/extras/io/Loader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ THREE.Loader.prototype = {
244244
currentOffset += init_quads_smooth_uv( currentOffset );
245245

246246
this.computeCentroids();
247-
this.computeNormals();
247+
this.computeFaceNormals();
248248
this.sortFacesByMaterial();
249249

250250
//var e = (new Date).getTime();
@@ -706,7 +706,7 @@ THREE.Loader.prototype = {
706706
init_faces();
707707

708708
this.computeCentroids();
709-
this.computeNormals();
709+
this.computeFaceNormals();
710710
this.sortFacesByMaterial();
711711

712712
function init_vertices() {

src/extras/primitives/Cube.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
3838
}
3939

4040
this.sides = { px: true, nx: true, py: true, ny: true, pz: true, nz: true };
41-
41+
4242
if( sides != undefined ) {
43-
43+
4444
for( var s in sides ) {
45-
45+
4646
if ( this.sides[ s ] != undefined ) {
47-
47+
4848
this.sides[ s ] = sides[ s ];
49-
49+
5050
}
51-
51+
5252
}
53-
53+
5454
}
55-
55+
5656
this.sides.px && buildPlane( 'z', 'y', 1 * flip, - 1, depth, height, - width_half, this.materials[ 0 ] ); // px
5757
this.sides.nx && buildPlane( 'z', 'y', - 1 * flip, - 1, depth, height, width_half, this.materials[ 1 ] ); // nx
5858
this.sides.py && buildPlane( 'x', 'z', 1 * flip, 1, width, depth, height_half, this.materials[ 2 ] ); // py
@@ -173,7 +173,7 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
173173
}
174174

175175
this.computeCentroids();
176-
this.computeNormals();
176+
this.computeFaceNormals();
177177
this.sortFacesByMaterial();
178178

179179
}

src/extras/primitives/Cylinder.js

+31-33
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,80 @@
22
* @author kile / http://kile.stravaganza.org/
33
*/
44

5-
var Cylinder = function (numSegs, topRad, botRad, height, topOffset, botOffset) {
5+
var Cylinder = function ( numSegs, topRad, botRad, height, topOffset, botOffset ) {
66

7-
THREE.Geometry.call(this);
7+
THREE.Geometry.call( this );
88

9-
var scope = this, i;
9+
var scope = this,
10+
pi = Math.PI, i;
1011

1112
// VERTICES
1213

1314
// Top circle vertices
14-
for (i = 0; i < numSegs; i++) {
15+
for ( i = 0; i < numSegs; i ++ ) {
16+
17+
v( Math.sin( 2 * pi * i / numSegs ) * topRad, Math.cos( 2 * pi * i / numSegs ) * topRad, 0 );
1518

16-
v(
17-
Math.sin(2 * 3.1415 * i / numSegs)*topRad,
18-
Math.cos(2 * 3.1415 * i / numSegs)*topRad,
19-
0);
2019
}
2120

2221
// Bottom circle vertices
23-
for (i = 0; i < numSegs; i++) {
22+
for ( i = 0; i < numSegs; i ++ ) {
23+
24+
v( Math.sin( 2 * pi * i / numSegs ) * botRad, Math.cos( 2 * pi * i / numSegs ) * botRad, height );
2425

25-
v(
26-
Math.sin(2 * 3.1415 * i / numSegs)*botRad,
27-
Math.cos(2 * 3.1415 * i / numSegs)*botRad,
28-
height);
2926
}
3027

3128

3229
// FACES
3330

34-
// Body
35-
for (i = 0; i < numSegs; i++) {
31+
// Body
32+
for ( i = 0; i < numSegs; i++ ) {
3633

37-
f4(i, i + numSegs, numSegs + (i + 1) % numSegs, (i + 1) % numSegs, '#ff0000');
34+
f4( i, i + numSegs, numSegs + ( i + 1 ) % numSegs, ( i + 1 ) % numSegs, '#ff0000' );
3835
}
3936

4037
// Bottom circle
41-
if (botRad != 0) {
38+
if ( botRad != 0 ) {
39+
40+
v( 0, 0, - topOffset );
4241

43-
v(0, 0, -topOffset);
42+
for ( i = numSegs; i < numSegs + ( numSegs / 2 ); i++ ) {
4443

45-
for (i = numSegs; i < numSegs + (numSegs / 2); i++) {
44+
f4( 2 * numSegs, ( 2 * i - 2 * numSegs ) % numSegs, ( 2 * i - 2 * numSegs + 1 ) % numSegs, ( 2 * i - 2 * numSegs + 2 ) % numSegs );
4645

47-
f4(2 * numSegs,
48-
(2 * i - 2 * numSegs) % numSegs,
49-
(2 * i - 2 * numSegs + 1) % numSegs,
50-
(2 * i - 2 * numSegs + 2) % numSegs);
5146
}
47+
5248
}
5349

5450
// Top circle
55-
if (topRad != 0) {
51+
if ( topRad != 0 ) {
52+
53+
v( 0, 0, height + topOffset );
5654

57-
v(0, 0, height + topOffset);
55+
for ( i = numSegs + ( numSegs / 2 ); i < 2 * numSegs; i ++ ) {
5856

59-
for (i = numSegs + (numSegs / 2); i < 2 * numSegs; i++) {
57+
f4( ( 2 * i - 2 * numSegs + 2 ) % numSegs + numSegs, ( 2 * i - 2 * numSegs + 1 ) % numSegs + numSegs, ( 2 * i - 2 * numSegs ) % numSegs+numSegs, 2 * numSegs + 1 );
6058

61-
f4( (2 * i - 2 * numSegs + 2) % numSegs + numSegs,
62-
(2 * i - 2 * numSegs + 1) % numSegs + numSegs,
63-
(2 * i - 2 * numSegs) % numSegs+numSegs,
64-
2 * numSegs + 1);
6559
}
60+
6661
}
6762

6863
this.computeCentroids();
69-
this.computeNormals();
64+
this.computeFaceNormals();
7065
this.sortFacesByMaterial();
7166

72-
function v(x, y, z) {
67+
function v( x, y, z ) {
7368

7469
scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
70+
7571
}
7672

77-
function f4(a, b, c, d) {
73+
function f4( a, b, c, d ) {
7874

7975
scope.faces.push( new THREE.Face4( a, b, c, d ) );
76+
8077
}
78+
8179
}
8280

8381
Cylinder.prototype = new THREE.Geometry();

src/extras/primitives/Plane.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var Plane = function ( width, height, segments_width, segments_height ) {
5353
}
5454

5555
this.computeCentroids();
56-
this.computeNormals();
56+
this.computeFaceNormals();
5757
this.sortFacesByMaterial();
5858

5959
}

src/extras/primitives/Sphere.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ var Sphere = function ( radius, segments_width, segments_height ) {
1010
var gridX = segments_width || 8,
1111
gridY = segments_height || 6;
1212

13-
var i, j;
13+
var i, j, pi = Math.PI;
1414
var iHor = Math.max( 3, gridX );
1515
var iVer = Math.max( 2, gridY );
1616
var aVtc = [];
1717

1818
for ( j = 0; j < ( iVer + 1 ) ; j++ ) {
1919

2020
var fRad1 = j / iVer;
21-
var fZ = radius * Math.cos( fRad1 * Math.PI );
22-
var fRds = radius * Math.sin( fRad1 * Math.PI );
21+
var fZ = radius * Math.cos( fRad1 * pi );
22+
var fRds = radius * Math.sin( fRad1 * pi );
2323
var aRow = [];
2424
var oVtx = 0;
2525

2626
for ( i = 0; i < iHor; i++ ) {
2727

2828
var fRad2 = 2 * i / iHor;
29-
var fX = fRds * Math.sin( fRad2 * Math.PI );
30-
var fY = fRds * Math.cos( fRad2 * Math.PI );
29+
var fX = fRds * Math.sin( fRad2 * pi );
30+
var fY = fRds * Math.cos( fRad2 * pi );
3131

3232
if ( !( ( j == 0 || j == iVer ) && i > 0 ) ) {
3333

@@ -104,7 +104,8 @@ var Sphere = function ( radius, segments_width, segments_height ) {
104104
}
105105

106106
this.computeCentroids();
107-
this.computeNormals();
107+
this.computeFaceNormals();
108+
this.computeVertexNormals();
108109
this.sortFacesByMaterial();
109110

110111
}

0 commit comments

Comments
 (0)