Skip to content

Commit

Permalink
Merge pull request #12872 from ngokevin/raycasteroptionaltarget
Browse files Browse the repository at this point in the history
add optionalTarget parameter to Raycaster.intersectObject(s) to allow array reuse
  • Loading branch information
mrdoob authored Mar 10, 2018
2 parents a683b26 + 81389ed commit 578273a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions docs/api/core/Raycaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ <h3>[method:null setFromCamera]( [param:Vector2 coords], [param:Camera camera] )
Updates the ray with a new origin and direction.
</div>


<h3>[method:Array intersectObject]( [param:Object3D object], [param:Boolean recursive] )</h3>
<h3>[method:Array intersectObject]( [page:Object3D object], [param:Boolean recursive], [param:Array optionalTarget] )</h3>
<div>
<p>
[page:Object3D object] — The object to check for intersection with the ray.<br />
[page:Boolean recursive] — If true, it also checks all descendants. Otherwise it only checks intersecton with the object. Default is false.
[page:Boolean recursive] — If true, it also checks all descendants. Otherwise it only checks intersecton with the object. Default is false.<br />
[page:Array optionalTarget] — (optional) target to set the result. Otherwise a new [page:Array] is instantiated. If set, you must clear this array prior to each call (i.e., array.length = 0;).
</p>
</div>
<div>
Expand Down Expand Up @@ -177,10 +177,11 @@ <h3>[method:Array intersectObject]( [param:Object3D object], [param:Boolean recu
</p>
</div>

<h3>[method:Array intersectObjects]( [param:Array objects], [param:Boolean recursive] )</h3>
<h3>[method:Array intersectObjects]( [param:Array objects], [param:Boolean recursive], [param:Array optionalTarget] )</h3>
<div>
[page:Array objects] — The objects to check for intersection with the ray.<br />
[page:Boolean recursive] — If true, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects. Default is false.
[page:Boolean recursive] — If true, it also checks all descendants of the objects. Otherwise it only checks intersecton with the objects. Default is false.<br />
[page:Array optionalTarget] — (optional) target to set the result. Otherwise a new [page:Array] is instantiated. If set, you must clear this array prior to each call (i.e., array.length = 0;).
</div>
<div>
Checks all intersection between the ray and the objects with or without the descendants. Intersections are returned sorted by distance, closest first. Intersections are of the same form as those returned by [page:.intersectObject].
Expand Down
8 changes: 4 additions & 4 deletions src/core/Raycaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ Object.assign( Raycaster.prototype, {

},

intersectObject: function ( object, recursive ) {
intersectObject: function ( object, recursive, optionalTarget ) {

var intersects = [];
var intersects = optionalTarget || [];

intersectObject( object, this, intersects, recursive );

Expand All @@ -105,9 +105,9 @@ Object.assign( Raycaster.prototype, {

},

intersectObjects: function ( objects, recursive ) {
intersectObjects: function ( objects, recursive, optionalTarget ) {

var intersects = [];
var intersects = optionalTarget || [];

if ( Array.isArray( objects ) === false ) {

Expand Down

0 comments on commit 578273a

Please sign in to comment.