Geometry.js 16.2 KB
Newer Older
M
Mr.doob 已提交
1
/**
M
Mr.doob 已提交
2
 * @author mrdoob / http://mrdoob.com/
M
Mr.doob 已提交
3
 * @author kile / http://kile.stravaganza.org/
M
Mr.doob 已提交
4
 * @author alteredq / http://alteredqualia.com/
5
 * @author mikael emtinger / http://gomo.se/
6
 * @author zz85 / http://www.lab4games.net/zz85/blog
M
Mr.doob 已提交
7 8
 */

M
Mr.doob 已提交
9
THREE.Geometry = function () {
10

M
Mr.doob 已提交
11
	THREE.GeometryLibrary.push( this );
M
Mr.doob 已提交
12

M
Mr.doob 已提交
13 14
	this.id = THREE.GeometryIdCount ++;

M
Mr.doob 已提交
15 16
	this.name = '';

M
Mr.doob 已提交
17
	this.vertices = [];
18 19
	this.colors = [];  // one-to-one vertex colors, used in ParticleSystem, Line and Ribbon
	this.normals = []; // one-to-one vertex normals, used in Ribbon
20

M
Mr.doob 已提交
21
	this.faces = [];
22

23 24
	this.faceUvs = [[]];
	this.faceVertexUvs = [[]];
25

26
	this.morphTargets = [];
M
Mr.doob 已提交
27
	this.morphColors = [];
A
alteredq 已提交
28
	this.morphNormals = [];
M
Mr.doob 已提交
29

30 31
	this.skinWeights = [];
	this.skinIndices = [];
M
Mr.doob 已提交
32

33 34
	this.lineDistances = [];

35 36 37
	this.boundingBox = null;
	this.boundingSphere = null;

38
	this.hasTangents = false;
39

A
alteredq 已提交
40
	this.dynamic = true; // the intermediate typed arrays will be deleted when set to false
41

42 43 44 45 46 47 48 49
	// update flags

	this.verticesNeedUpdate = false;
	this.elementsNeedUpdate = false;
	this.uvsNeedUpdate = false;
	this.normalsNeedUpdate = false;
	this.tangentsNeedUpdate = false;
	this.colorsNeedUpdate = false;
50
	this.lineDistancesNeedUpdate = false;
51

A
alteredq 已提交
52 53
	this.buffersNeedUpdate = false;

M
Mr.doob 已提交
54 55 56 57
};

THREE.Geometry.prototype = {

58 59
	constructor : THREE.Geometry,

60 61
	applyMatrix: function ( matrix ) {

62 63 64
		var normalMatrix = new THREE.Matrix3();

		normalMatrix.getInverse( matrix ).transpose();
65 66 67 68 69

		for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {

			var vertex = this.vertices[ i ];

70
			matrix.multiplyVector3( vertex );
71 72 73 74 75 76 77

		}

		for ( var i = 0, il = this.faces.length; i < il; i ++ ) {

			var face = this.faces[ i ];

78
			normalMatrix.multiplyVector3( face.normal ).normalize();
79 80 81

			for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {

82
				normalMatrix.multiplyVector3( face.vertexNormals[ j ] ).normalize();
83 84 85 86 87 88 89 90 91

			}

			matrix.multiplyVector3( face.centroid );

		}

	},

M
Mr.doob 已提交
92 93 94 95
	computeCentroids: function () {

		var f, fl, face;

M
Mr.doob 已提交
96
		for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
M
Mr.doob 已提交
97 98 99 100 101 102

			face = this.faces[ f ];
			face.centroid.set( 0, 0, 0 );

			if ( face instanceof THREE.Face3 ) {

103 104 105
				face.centroid.addSelf( this.vertices[ face.a ] );
				face.centroid.addSelf( this.vertices[ face.b ] );
				face.centroid.addSelf( this.vertices[ face.c ] );
M
Mr.doob 已提交
106 107 108 109
				face.centroid.divideScalar( 3 );

			} else if ( face instanceof THREE.Face4 ) {

110 111 112 113
				face.centroid.addSelf( this.vertices[ face.a ] );
				face.centroid.addSelf( this.vertices[ face.b ] );
				face.centroid.addSelf( this.vertices[ face.c ] );
				face.centroid.addSelf( this.vertices[ face.d ] );
M
Mr.doob 已提交
114 115 116 117 118 119 120 121
				face.centroid.divideScalar( 4 );

			}

		}

	},

122
	computeFaceNormals: function () {
123

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

M
Mr.doob 已提交
127
		for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
128

M
Mr.doob 已提交
129
			face = this.faces[ f ];
130

131 132 133
			vA = this.vertices[ face.a ];
			vB = this.vertices[ face.b ];
			vC = this.vertices[ face.c ];
U
unknown 已提交
134

135 136
			cb.sub( vC, vB );
			ab.sub( vA, vB );
137
			cb.crossSelf( ab );
U
unknown 已提交
138

W
WestLangley 已提交
139
			cb.normalize();
140

141 142
			face.normal.copy( cb );

143 144 145 146
		}

	},

147
	computeVertexNormals: function ( areaWeighted ) {
148

149
		var v, vl, f, fl, face, vertices;
150

151 152
		// create internal buffers for reuse when calling this method repeatedly
		// (otherwise memory allocation / deallocation every frame is big resource hog)
M
Mr.doob 已提交
153

154
		if ( this.__tmpVertices === undefined ) {
M
Mr.doob 已提交
155

156 157
			this.__tmpVertices = new Array( this.vertices.length );
			vertices = this.__tmpVertices;
M
Mr.doob 已提交
158

159 160 161 162 163
			for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {

				vertices[ v ] = new THREE.Vector3();

			}
M
Mr.doob 已提交
164

165 166 167 168 169 170 171
			for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {

				face = this.faces[ f ];

				if ( face instanceof THREE.Face3 ) {

					face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
M
Mr.doob 已提交
172

173
				} else if ( face instanceof THREE.Face4 ) {
M
Mr.doob 已提交
174

175 176 177 178 179
					face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];

				}

			}
M
Mr.doob 已提交
180

181
		} else {
M
Mr.doob 已提交
182

183
			vertices = this.__tmpVertices;
M
Mr.doob 已提交
184

185 186 187 188 189
			for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {

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

			}
M
Mr.doob 已提交
190

M
Mr.doob 已提交
191 192
		}

193
		if ( areaWeighted ) {
M
Mr.doob 已提交
194

195 196
			// vertex normals weighted by triangle areas
			// http://www.iquilezles.org/www/articles/normals/normals.htm
M
Mr.doob 已提交
197

198 199 200
			var vA, vB, vC, vD;
			var cb = new THREE.Vector3(), ab = new THREE.Vector3(),
				db = new THREE.Vector3(), dc = new THREE.Vector3(), bc = new THREE.Vector3();
201

202
			for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
M
Mr.doob 已提交
203

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
				face = this.faces[ f ];

				if ( face instanceof THREE.Face3 ) {

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

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

					vertices[ face.a ].addSelf( cb );
					vertices[ face.b ].addSelf( cb );
					vertices[ face.c ].addSelf( cb );

				} else if ( face instanceof THREE.Face4 ) {

					vA = this.vertices[ face.a ];
					vB = this.vertices[ face.b ];
					vC = this.vertices[ face.c ];
					vD = this.vertices[ face.d ];

					// abd

					db.sub( vD, vB );
					ab.sub( vA, vB );
					db.crossSelf( ab );

					vertices[ face.a ].addSelf( db );
					vertices[ face.b ].addSelf( db );
					vertices[ face.d ].addSelf( db );

					// bcd

					dc.sub( vD, vC );
					bc.sub( vB, vC );
					dc.crossSelf( bc );
M
Mr.doob 已提交
242

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
					vertices[ face.b ].addSelf( dc );
					vertices[ face.c ].addSelf( dc );
					vertices[ face.d ].addSelf( dc );

				}

			}

		} else {

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

				face = this.faces[ f ];

				if ( face instanceof THREE.Face3 ) {

					vertices[ face.a ].addSelf( face.normal );
					vertices[ face.b ].addSelf( face.normal );
					vertices[ face.c ].addSelf( face.normal );

				} else if ( face instanceof THREE.Face4 ) {

					vertices[ face.a ].addSelf( face.normal );
					vertices[ face.b ].addSelf( face.normal );
					vertices[ face.c ].addSelf( face.normal );
					vertices[ face.d ].addSelf( face.normal );

				}
M
Mr.doob 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287

			}

		}

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

			vertices[ v ].normalize();

		}

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

			face = this.faces[ f ];

			if ( face instanceof THREE.Face3 ) {

288 289 290
				face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
				face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
				face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
M
Mr.doob 已提交
291 292 293

			} else if ( face instanceof THREE.Face4 ) {

294 295 296 297
				face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
				face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
				face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
				face.vertexNormals[ 3 ].copy( vertices[ face.d ] );
M
Mr.doob 已提交
298 299

			}
300 301 302 303 304

		}

	},

305 306 307 308
	computeMorphNormals: function () {

		var i, il, f, fl, face;

309 310 311
		// save original normals
		// - create temp variables on first access
		//   otherwise just copy (for faster repeated calls)
312 313 314 315

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

			face = this.faces[ f ];
316 317 318 319 320 321 322 323 324 325 326 327

			if ( ! face.__originalFaceNormal ) {

				face.__originalFaceNormal = face.normal.clone();

			} else {

				face.__originalFaceNormal.copy( face.normal );

			}

			if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
328 329 330

			for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {

331 332 333 334 335 336 337 338 339
				if ( ! face.__originalVertexNormals[ i ] ) {

					face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();

				} else {

					face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );

				}
340 341 342 343 344 345 346 347 348 349 350 351

			}

		}

		// use temp geometry to compute face and vertex normals for each morph

		var tmpGeo = new THREE.Geometry();
		tmpGeo.faces = this.faces;

		for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {

352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
			// create on first access

			if ( ! this.morphNormals[ i ] ) {

				this.morphNormals[ i ] = {};
				this.morphNormals[ i ].faceNormals = [];
				this.morphNormals[ i ].vertexNormals = [];

				var dstNormalsFace = this.morphNormals[ i ].faceNormals;
				var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;

				var faceNormal, vertexNormals;

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

					face = this.faces[ f ];

					faceNormal = new THREE.Vector3();

					if ( face instanceof THREE.Face3 ) {

						vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };

					} else {

						vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3(), d: new THREE.Vector3() };

					}

					dstNormalsFace.push( faceNormal );
					dstNormalsVertex.push( vertexNormals );

				}

			}

388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
			var morphNormals = this.morphNormals[ i ];

			// set vertices to morph target

			tmpGeo.vertices = this.morphTargets[ i ].vertices;

			// compute morph normals

			tmpGeo.computeFaceNormals();
			tmpGeo.computeVertexNormals();

			// store morph normals

			var faceNormal, vertexNormals;

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

				face = this.faces[ f ];

				faceNormal = morphNormals.faceNormals[ f ];
				vertexNormals = morphNormals.vertexNormals[ f ];

				faceNormal.copy( face.normal );

				if ( face instanceof THREE.Face3 ) {

					vertexNormals.a.copy( face.vertexNormals[ 0 ] );
					vertexNormals.b.copy( face.vertexNormals[ 1 ] );
					vertexNormals.c.copy( face.vertexNormals[ 2 ] );

				} else {

					vertexNormals.a.copy( face.vertexNormals[ 0 ] );
					vertexNormals.b.copy( face.vertexNormals[ 1 ] );
					vertexNormals.c.copy( face.vertexNormals[ 2 ] );
					vertexNormals.d.copy( face.vertexNormals[ 3 ] );

				}

			}

		}

431
		// restore original normals
432 433 434 435

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

			face = this.faces[ f ];
436 437

			face.normal = face.__originalFaceNormal;
438 439 440 441 442 443
			face.vertexNormals = face.__originalVertexNormals;

		}

	},

444
	computeTangents: function () {
445

446 447
		// based on http://www.terathon.com/code/tangent.html
		// tangents go to vertices
448

449 450
		var f, fl, v, vl, i, il, vertexIndex,
			face, uv, vA, vB, vC, uvA, uvB, uvC,
451
			x1, x2, y1, y2, z1, z2,
452
			s1, s2, t1, t2, r, t, test,
453 454
			tan1 = [], tan2 = [],
			sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
455
			tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
456
			n = new THREE.Vector3(), w;
457

458 459 460 461 462 463
		for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {

			tan1[ v ] = new THREE.Vector3();
			tan2[ v ] = new THREE.Vector3();

		}
464

M
Mr.doob 已提交
465
		function handleTriangle( context, a, b, c, ua, ub, uc ) {
466

467 468 469
			vA = context.vertices[ a ];
			vB = context.vertices[ b ];
			vC = context.vertices[ c ];
470

M
Mr.doob 已提交
471 472 473
			uvA = uv[ ua ];
			uvB = uv[ ub ];
			uvC = uv[ uc ];
474

475 476 477 478 479 480 481 482 483 484 485 486 487
			x1 = vB.x - vA.x;
			x2 = vC.x - vA.x;
			y1 = vB.y - vA.y;
			y2 = vC.y - vA.y;
			z1 = vB.z - vA.z;
			z2 = vC.z - vA.z;

			s1 = uvB.u - uvA.u;
			s2 = uvC.u - uvA.u;
			t1 = uvB.v - uvA.v;
			t2 = uvC.v - uvA.v;

			r = 1.0 / ( s1 * t2 - s2 * t1 );
488
			sdir.set( ( t2 * x1 - t1 * x2 ) * r,
489 490
					  ( t2 * y1 - t1 * y2 ) * r,
					  ( t2 * z1 - t1 * z2 ) * r );
491
			tdir.set( ( s1 * x2 - s2 * x1 ) * r,
492 493
					  ( s1 * y2 - s2 * y1 ) * r,
					  ( s1 * z2 - s2 * z1 ) * r );
494

495 496 497
			tan1[ a ].addSelf( sdir );
			tan1[ b ].addSelf( sdir );
			tan1[ c ].addSelf( sdir );
498

499 500 501
			tan2[ a ].addSelf( tdir );
			tan2[ b ].addSelf( tdir );
			tan2[ c ].addSelf( tdir );
502

503
		}
504

505
		for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
506

507
			face = this.faces[ f ];
508
			uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
509

510
			if ( face instanceof THREE.Face3 ) {
511

M
Mr.doob 已提交
512
				handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
513

514
			} else if ( face instanceof THREE.Face4 ) {
515

M
Mr.doob 已提交
516
				handleTriangle( this, face.a, face.b, face.d, 0, 1, 3 );
517
				handleTriangle( this, face.b, face.c, face.d, 1, 2, 3 );
518 519

			}
520

521
		}
522

523
		var faceIndex = [ 'a', 'b', 'c', 'd' ];
524

525
		for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
526

527
			face = this.faces[ f ];
528

529
			for ( i = 0; i < face.vertexNormals.length; i++ ) {
530

531
				n.copy( face.vertexNormals[ i ] );
532

533
				vertexIndex = face[ faceIndex[ i ] ];
534

535
				t = tan1[ vertexIndex ];
536

537
				// Gram-Schmidt orthogonalize
538

539 540
				tmp.copy( t );
				tmp.subSelf( n.multiplyScalar( n.dot( t ) ) ).normalize();
541

542
				// Calculate handedness
543

544 545 546
				tmp2.cross( face.vertexNormals[ i ], t );
				test = tmp2.dot( tan2[ vertexIndex ] );
				w = (test < 0.0) ? -1.0 : 1.0;
547

548
				face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
549

550
			}
551

552
		}
553

554
		this.hasTangents = true;
555

556
	},
557

558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
	computeLineDistances: function ( ) {

		var d = 0;
		var vertices = this.vertices;

		for ( var i = 0, il = vertices.length; i < il; i ++ ) {

			if ( i > 0 ) {

				d += vertices[ i ].distanceTo( vertices[ i - 1 ] );

			}

			this.lineDistances[ i ] = d;

		}

	},

577
	computeBoundingBox: function () {
578

579
		if ( ! this.boundingBox ) {
580

581
			this.boundingBox = { min: new THREE.Vector3(), max: new THREE.Vector3() };
582

583
		}
584

585
		if ( this.vertices.length > 0 ) {
586

587
			var position, firstPosition = this.vertices[ 0 ];
588

589 590
			this.boundingBox.min.copy( firstPosition );
			this.boundingBox.max.copy( firstPosition );
591 592 593

			var min = this.boundingBox.min,
				max = this.boundingBox.max;
594

M
Mr.doob 已提交
595
			for ( var v = 1, vl = this.vertices.length; v < vl; v ++ ) {
596

597
				position = this.vertices[ v ];
598

599
				if ( position.x < min.x ) {
600

601
					min.x = position.x;
602

603
				} else if ( position.x > max.x ) {
604

605
					max.x = position.x;
606 607 608

				}

609
				if ( position.y < min.y ) {
610

611
					min.y = position.y;
612

613
				} else if ( position.y > max.y ) {
614

615
					max.y = position.y;
616 617 618

				}

619
				if ( position.z < min.z ) {
620

621
					min.z = position.z;
622

623
				} else if ( position.z > max.z ) {
624

625
					max.z = position.z;
626 627 628 629

				}

			}
630

631 632 633 634 635
		} else {

			this.boundingBox.min.set( 0, 0, 0 );
			this.boundingBox.max.set( 0, 0, 0 );

636 637
		}

M
Mr.doob 已提交
638 639
	},

640
	computeBoundingSphere: function () {
641

642
		var maxRadiusSq = 0;
643

644 645 646
		if ( this.boundingSphere === null ) this.boundingSphere = { radius: 0 };

		for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
647 648

			var radiusSq = this.vertices[ i ].lengthSq();
649
			if ( radiusSq > maxRadiusSq ) maxRadiusSq = radiusSq;
650 651 652

		}

653
		this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
654

655
	},
656 657 658

	/*
	 * Checks for duplicate vertices with hashmap.
659
	 * Duplicated vertices are removed
660
	 * and faces' vertices are updated.
661
	 */
662

663
	mergeVertices: function () {
664

665
		var verticesMap = {}; // Hashmap for looking up vertice by position coordinates (and making sure they are unique)
666
		var unique = [], changes = [];
667

668
		var v, key;
669 670
		var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
		var precision = Math.pow( 10, precisionPoints );
671
		var i,il, face;
Z
zz85 已提交
672
		var abcd = 'abcd', o, k, j, jl, u;
673 674 675

		for ( i = 0, il = this.vertices.length; i < il; i ++ ) {

676
			v = this.vertices[ i ];
677 678 679 680 681 682 683 684
			key = [ Math.round( v.x * precision ), Math.round( v.y * precision ), Math.round( v.z * precision ) ].join( '_' );

			if ( verticesMap[ key ] === undefined ) {

				verticesMap[ key ] = i;
				unique.push( this.vertices[ i ] );
				changes[ i ] = unique.length - 1;

685
			} else {
686

687
				//console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
688 689
				changes[ i ] = changes[ verticesMap[ key ] ];

690
			}
691

692
		};
693 694 695 696


		// Start to patch face indices

697 698 699 700 701
		for( i = 0, il = this.faces.length; i < il; i ++ ) {

			face = this.faces[ i ];

			if ( face instanceof THREE.Face3 ) {
702 703 704 705 706 707 708 709 710 711 712 713

				face.a = changes[ face.a ];
				face.b = changes[ face.b ];
				face.c = changes[ face.c ];

			} else if ( face instanceof THREE.Face4 ) {

				face.a = changes[ face.a ];
				face.b = changes[ face.b ];
				face.c = changes[ face.c ];
				face.d = changes[ face.d ];

714
				// check dups in (a, b, c, d) and convert to -> face3
715 716 717 718 719 720 721

				o = [ face.a, face.b, face.c, face.d ];

				for ( k = 3; k > 0; k -- ) {

					if ( o.indexOf( face[ abcd[ k ] ] ) !== k ) {

722
						// console.log('faces', face.a, face.b, face.c, face.d, 'dup at', k);
723 724 725 726 727 728 729 730 731 732

						o.splice( k, 1 );

						this.faces[ i ] = new THREE.Face3( o[0], o[1], o[2], face.normal, face.color, face.materialIndex );

						for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {

							u = this.faceVertexUvs[ j ][ i ];
							if ( u ) u.splice( k, 1 );

Z
zz85 已提交
733
						}
734

Z
zz85 已提交
735
						this.faces[ i ].vertexColors = face.vertexColors;
736

Z
zz85 已提交
737
						break;
738 739
					}

740
				}
741

742
			}
743

744
		}
745

746
		// Use unique set of vertices
747

Z
zz85 已提交
748
		var diff = this.vertices.length - unique.length;
749
		this.vertices = unique;
Z
zz85 已提交
750
		return diff;
751

752 753 754 755 756 757
	},

	clone: function () {

		// TODO

758 759 760 761
	},

	deallocate: function () {

M
Mr.doob 已提交
762 763
		var index = THREE.GeometryLibrary.indexOf( this );
		if ( index !== -1 ) THREE.GeometryLibrary.splice( index, 1 );
764

765
	}
766

M
Mr.doob 已提交
767
};
768

M
Mr.doob 已提交
769
THREE.GeometryIdCount = 0;
M
Mr.doob 已提交
770
THREE.GeometryLibrary = [];