Browse Source

rename Triangle.uvIntersection to getUV

06wj 7 years ago
parent
commit
c48d55fc3a
3 changed files with 12 additions and 17 deletions
  1. 9 14
      src/math/Triangle.js
  2. 2 2
      src/objects/Mesh.js
  3. 1 1
      src/objects/Sprite.js

+ 9 - 14
src/math/Triangle.js

@@ -1,4 +1,3 @@
-import { Vector2 } from './Vector2.js';
 import { Vector3 } from './Vector3.js';
 
 /**
@@ -109,24 +108,20 @@ Object.assign( Triangle, {
 
 	}(),
 
-	uvIntersection: function () {
+	getUV: function () {
 
 		var barycoord = new Vector3();
-		var v1 = new Vector2();
-		var v2 = new Vector2();
-		var v3 = new Vector2();
 
-		return function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3, result ) {
+		return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
 
 			this.getBarycoord( point, p1, p2, p3, barycoord );
 
-			v1.copy( uv1 ).multiplyScalar( barycoord.x );
-			v2.copy( uv2 ).multiplyScalar( barycoord.y );
-			v3.copy( uv3 ).multiplyScalar( barycoord.z );
+			target.set( 0, 0 );
+			target.addScaledVector( uv1, barycoord.x );
+			target.addScaledVector( uv2, barycoord.y );
+			target.addScaledVector( uv3, barycoord.z );
 
-			v1.add( v2 ).add( v3 );
-
-			return result.copy( v1 );
+			return target;
 
 		};
 
@@ -232,9 +227,9 @@ Object.assign( Triangle.prototype, {
 
 	},
 
-	uvIntersection: function ( point, uv1, uv2, uv3, result ) {
+	getUV: function ( point, uv1, uv2, uv3, result ) {
 
-		return Triangle.uvIntersection( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
+		return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
 
 	},
 

+ 2 - 2
src/objects/Mesh.js

@@ -190,7 +190,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
 					uvB.fromBufferAttribute( uv, b );
 					uvC.fromBufferAttribute( uv, c );
 
-					intersection.uv = Triangle.uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
+					intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
 
 				}
 
@@ -432,7 +432,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
 							uvB.copy( uvs_f[ 1 ] );
 							uvC.copy( uvs_f[ 2 ] );
 
-							intersection.uv = Triangle.uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
+							intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
 
 						}
 

+ 1 - 1
src/objects/Sprite.js

@@ -149,7 +149,7 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 				distance: distance,
 				point: intersectPoint.clone(),
-				uv: Triangle.uvIntersection( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
+				uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
 				face: null,
 				object: this