提交 f6f4d8d3 编写于 作者: 0 06wj

add Triangle.uvIntersection

上级 239627a2
import { Vector2 } from './Vector2.js';
import { Vector3 } from './Vector3.js';
/**
......@@ -94,6 +95,29 @@ Object.assign( Triangle, {
}(),
uvIntersection: 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 ) {
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 );
v1.add( v2 ).add( v3 );
return result.copy( v1 );
};
}(),
containsPoint: function () {
var v1 = new Vector3();
......
......@@ -140,25 +140,9 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
var uvB = new Vector2();
var uvC = new Vector2();
var barycoord = new Vector3();
var intersectionPoint = new Vector3();
var intersectionPointWorld = new Vector3();
function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
Triangle.getBarycoord( point, p1, p2, p3, barycoord );
uv1.multiplyScalar( barycoord.x );
uv2.multiplyScalar( barycoord.y );
uv3.multiplyScalar( barycoord.z );
uv1.add( uv2 ).add( uv3 );
return uv1.clone();
}
function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
var intersect;
......@@ -206,7 +190,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
uvB.fromBufferAttribute( uv, b );
uvC.fromBufferAttribute( uv, c );
intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
intersection.uv = Triangle.uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
}
......@@ -448,7 +432,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
uvB.copy( uvs_f[ 1 ] );
uvC.copy( uvs_f[ 2 ] );
intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
intersection.uv = Triangle.uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
}
......
......@@ -98,22 +98,6 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
}
var barycoord = new Vector3();
function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
Triangle.getBarycoord( point, p1, p2, p3, barycoord );
uv1.multiplyScalar( barycoord.x );
uv2.multiplyScalar( barycoord.y );
uv3.multiplyScalar( barycoord.z );
uv1.add( uv2 ).add( uv3 );
return uv1.clone();
}
return function raycast( raycaster, intersects ) {
worldScale.setFromMatrixScale( this.matrixWorld );
......@@ -165,7 +149,7 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
distance: distance,
point: intersectPoint.clone(),
uv: uvIntersection( intersectPoint, vA, vB, vC, uvA, uvB, uvC ),
uv: Triangle.uvIntersection( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
face: null,
object: this
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册