提交 2fda472d 编写于 作者: W WestLangley

Sprite: fix raycasting bugs

上级 ca37c0dd
......@@ -67,11 +67,11 @@
sprite.scale.set( 2, 5, 1 );
group.add( sprite );
var sprite = new THREE.Sprite( new THREE.SpriteMaterial( { color: '#69f' } ) );
var sprite = new THREE.Sprite( new THREE.SpriteMaterial( { color: '#69f', sizeAttenuation: false } ) );
sprite.material.rotation = Math.PI / 3 * 4;
sprite.position.set( 8, - 2, 2 );
sprite.center.set( 0.5, 0 );
sprite.scale.set( 1, - 5, 1 );
sprite.scale.set( .1, .5, .1 );
group.add( sprite );
var group2 = new THREE.Object3D();
......
......@@ -79,11 +79,13 @@ Object.assign( Raycaster.prototype, {
this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
this.camera = camera;
} else if ( ( camera && camera.isOrthographicCamera ) ) {
this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
this.camera = camera;
} else {
......
......@@ -101,9 +101,18 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
return function raycast( raycaster, intersects ) {
worldScale.setFromMatrixScale( this.matrixWorld );
viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
viewWorldMatrix.copy( raycaster.camera.matrixWorld );
this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
mvPosition.setFromMatrixPosition( this.modelViewMatrix );
if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
worldScale.multiplyScalar( - mvPosition.z );
}
var rotation = this.material.rotation;
var sin, cos;
if ( rotation !== 0 ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册