Geometry.js 796 字节
Newer Older
M
Mr.doob 已提交
1 2
/**
 * @author mr.doob / http://mrdoob.com/
M
Mr.doob 已提交
3
 * @author kile / http://kile.stravaganza.org/
M
Mr.doob 已提交
4 5
 */

M
Mr.doob 已提交
6
THREE.Geometry = function () {
7

M
Mr.doob 已提交
8 9
	this.vertices = [];
	this.faces = [];
10
	this.uvs = [];
M
Mr.doob 已提交
11

12 13
	this.computeNormals = function () {

14
		var v, f, vA, vB, vC, cb, ab;
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

		for ( v = 0; v < this.vertices.length; v++ ) {

			this.vertices[ v ].normal.set( 0, 0, 0 );

		}

		for ( f = 0; f < this.faces.length; f++ ) {

			vA = this.vertices[ this.faces[ f ].a ];
			vB = this.vertices[ this.faces[ f ].b ];
			vC = this.vertices[ this.faces[ f ].c ];

			cb = new THREE.Vector3();
			ab = new THREE.Vector3();

			cb.sub( vC.position, vB.position );
			ab.sub( vA.position, vB.position );
			cb.crossSelf( ab );

			if ( !cb.isZero() ) {

				cb.normalize();

			}

			this.faces[ f ].normal = cb;

		}

	};

M
Mr.doob 已提交
47
};