Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api/en/core/Raycaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ <h3>[property:float near]</h3>
This value shouldn't be negative and should be smaller than the far property.
</p>

<h3>[property:Camera camera]</h3>
<p>
The camera to use when raycasting against view-dependent objects such as billboarded objects like [page:Sprites]. This field
can be set manually or is set when calling "setFromCamera".

Defaults to null.
</p>

<h3>[property:Object params]</h3>
<p>
An object with the following properties:
Expand Down
6 changes: 6 additions & 0 deletions src/core/Raycaster.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export class Raycaster {
*/
far: number;

/**
* The camera to use when raycasting against view-dependent objects such as billboarded objects like Sprites. This field
* can be set manually or is set when calling "setFromCamera".
*/
camera: Camera;

params: RaycasterParameters;

/**
Expand Down
5 changes: 3 additions & 2 deletions src/core/Raycaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function Raycaster( origin, direction, near, far ) {

this.near = near || 0;
this.far = far || Infinity;
this.camera = null;

this.params = {
Mesh: {},
Expand Down Expand Up @@ -79,13 +80,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;
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;
this.camera = camera;

} else {

Expand Down
12 changes: 9 additions & 3 deletions src/objects/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {

raycast: function ( raycaster, intersects ) {

if ( raycaster.camera === null ) {

console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );

}

if ( _uvC === undefined ) {

_intersectPoint = new Vector3();
Expand All @@ -82,12 +88,12 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {

_worldScale.setFromMatrixScale( this.matrixWorld );

_viewWorldMatrix.copy( raycaster._camera.matrixWorld );
this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, 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 ) {
if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {

_worldScale.multiplyScalar( - _mvPosition.z );

Expand Down