未验证 提交 fce051cf 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #16590 from sciecode/dev5

Triangle: include isFrontFacing
......@@ -30,6 +30,7 @@ export class Triangle {
getPlane( target: Vector3 ): Plane;
getBarycoord( point: Vector3, target: Vector3 ): Vector3;
containsPoint( point: Vector3 ): boolean;
isFrontFacing( direction: Vector3 ): boolean;
closestPointToPoint( point: Vector3, target: Vector3 ): Vector3;
equals( triangle: Triangle ): boolean;
......@@ -52,5 +53,11 @@ export class Triangle {
b: Vector3,
c: Vector3
): boolean;
static isFrontFacing(
a: Vector3,
b: Vector3,
c: Vector3,
direction: Vector3
): boolean;
}
......@@ -125,6 +125,23 @@ Object.assign( Triangle, {
};
}(),
isFrontFacing: function () {
var v0 = new Vector3();
var v1 = new Vector3();
return function isFrontFacing( a, b, c, direction ) {
v0.subVectors( c, b );
v1.subVectors( a, b );
// strictly front facing
return ( v0.cross( v1 ).dot( direction ) < 0 ) ? true : false;
};
}()
} );
......@@ -233,6 +250,12 @@ Object.assign( Triangle.prototype, {
},
isFrontFacing: function ( direction ) {
return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
},
intersectsBox: function ( box ) {
return box.intersectsTriangle( this );
......
......@@ -305,6 +305,21 @@ export default QUnit.module( 'Maths', () => {
} );
QUnit.test( "isFrontFacing", ( assert ) => {
var a = new Triangle();
var dir = new Vector3();
assert.ok( ! a.isFrontFacing( dir ), "Passed!" );
var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
var dir = new Vector3( 0, 0, - 1 );
assert.ok( a.isFrontFacing( dir ), "Passed!" );
var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 1, 0, 0 ) );
assert.ok( ! a.isFrontFacing( dir ), "Passed!" );
} );
QUnit.test( "equals", ( assert ) => {
var a = new Triangle(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册