Forráskód Böngészése

Added vertex uv calculation of ConvexGeometry

Xueqiao Xu 13 éve
szülő
commit
6794b2dae8
1 módosított fájl, 25 hozzáadás és 1 törlés
  1. 25 1
      src/extras/geometries/ConvexGeometry.js

+ 25 - 1
src/extras/geometries/ConvexGeometry.js

@@ -159,6 +159,17 @@ THREE.ConvexGeometry = function( vertices ) {
 
 	}
 
+
+	/**
+	 * XXX: Not sure if this is the correct approach. Need someone to review.
+	 */
+	function vertexUv( vertex ) {
+
+		var mag = vertex.length();
+		return new THREE.UV( vertex.x / mag, vertex.y / mag );
+
+	}
+
 	// Push vertices into `this.vertices`, skipping those inside the hull
 	var id = 0;
 	var newId = new Array( vertices.length ); // map from old vertex id to new id
@@ -192,6 +203,19 @@ THREE.ConvexGeometry = function( vertices ) {
 		) );
 
 	}
+
+	// Compute UVs
+	for ( var i = 0; i < this.faces.length; i++ ) {
+		
+		var face = this.faces[ i ];
+
+		this.faceVertexUvs[ 0 ].push( [
+			vertexUv( this.vertices[ face.a ] ),
+			vertexUv( this.vertices[ face.b ] ),
+			vertexUv( this.vertices[ face.c ])
+		] );
+
+	}
 	
 
 	this.computeCentroids();
@@ -201,4 +225,4 @@ THREE.ConvexGeometry = function( vertices ) {
 };
 
 THREE.ConvexGeometry.prototype = new THREE.Geometry();
-THREE.ConvexGeometry.prototype.constructor = THREE.ConvexGeometry;
+THREE.ConvexGeometry.prototype.constructor = THREE.ConvexGeometry;