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

Merge pull request #12872 from ngokevin/raycasteroptionaltarget

add optionalTarget parameter to Raycaster.intersectObject(s) to allow array reuse
......@@ -144,12 +144,12 @@
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>
......@@ -177,10 +177,11 @@
</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].
......
......@@ -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 );
......@@ -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 ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册