Skip to content

Commit 6b2c57e

Browse files
ngokevindmarcos
authored andcommitted
remove raycaster.recursive, update raycaster docs (#3980)
1 parent 6af69f5 commit 6b2c57e

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

docs/components/raycaster.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ checks for intersections at a certain interval against a list of objects, and
2121
will emit events on the entity when it detects intersections or clearing of
2222
intersections (i.e., when the raycaster is no longer intersecting an entity).
2323

24+
We prescribe that the set of objects that the raycaster tests for intersection
25+
is explicitly defined via the `objects` selector property described below.
26+
Raycasting is an expensive operation, and we should raycast against only
27+
targets that need to be interactable at any given time.
28+
2429
[cursor]: ./cursor.md
2530
[laser-controls]: ./laser-controls.md
2631

@@ -36,6 +41,9 @@ both build on top of the raycaster component.
3641
<a-entity class="collidable" geometry="primitive: box" position="1 0 0"></a-entity>
3742
```
3843

44+
Whenever an entity adds or removes the class `collidable`, the raycaster will
45+
refresh its list of objects it is raycasting against.
46+
3947
```js
4048
AFRAME.registerComponent('collider-check', {
4149
dependencies: ['raycaster'],
@@ -58,9 +66,8 @@ AFRAME.registerComponent('collider-check', {
5866
| far | Maximum distance under which resulting entities are returned. Cannot be lower than `near`. | Infinity |
5967
| interval | Number of milliseconds to wait in between each intersection test. Lower number is better for faster updates. Higher number is better for performance. Intersection tests are performed at most once per frame. | 0 |
6068
| near | Minimum distance over which resuilting entities are returned. Cannot be lower than 0. | 0 |
61-
| objects | Query selector to pick which objects to test for intersection. If not specified, all entities will be tested. Note that only objects attached via `.setObject3D` will be tested. | null |
69+
| objects | Query selector to pick which objects to test for intersection. If not specified, all entities will be tested. Note that only objects attached via `.setObject3D` and their recursive children will be tested. | null |
6270
| origin | Vector3 coordinate of where the ray should originate from relative to the entity's origin. | 0, 0, 0 |
63-
| recursive | Checks children of objects if set. Else only checks intersections with root objects. Note that only objects attached via `setObject3D` are tested. | true |
6471
| showLine | Whether or not to display the raycaster visually with the [line component][line]. | false |
6572
| useWorldCoordinates | Whether the raycaster origin and direction properties are specified in world coordinates. | false |
6673

src/components/raycaster.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ module.exports.Component = registerComponent('raycaster', {
4949
near: {default: 0},
5050
objects: {default: ''},
5151
origin: {type: 'vec3'},
52-
recursive: {default: true},
5352
showLine: {default: false},
5453
useWorldCoordinates: {default: false}
5554
},
@@ -224,7 +223,7 @@ module.exports.Component = registerComponent('raycaster', {
224223
// Raycast.
225224
this.updateOriginDirection();
226225
rawIntersections.length = 0;
227-
this.raycaster.intersectObjects(this.objects, data.recursive, rawIntersections);
226+
this.raycaster.intersectObjects(this.objects, true, rawIntersections);
228227

229228
// Only keep intersections against objects that have a reference to an entity.
230229
intersections.length = 0;

tests/components/raycaster.test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -356,29 +356,6 @@ suite('raycaster', function () {
356356
});
357357
});
358358

359-
suite('non-recursive raycaster', function () {
360-
var targetEl;
361-
362-
setup(function (done) {
363-
targetEl = document.createElement('a-entity');
364-
365-
el.setAttribute('position', '0 0 1');
366-
el.setAttribute('raycaster', {recursive: false, near: 0.1, far: 10});
367-
368-
targetEl.setAttribute('geometry', 'primitive: box');
369-
targetEl.setAttribute('position', '0 0 -1');
370-
targetEl.addEventListener('loaded', function () {
371-
setTimeout(() => { done(); });
372-
});
373-
sceneEl.appendChild(targetEl);
374-
});
375-
376-
test('can catch basic intersection', function (done) {
377-
targetEl.addEventListener('raycaster-intersected', function () { done(); });
378-
component.tick();
379-
});
380-
});
381-
382359
suite('updateOriginDirection', function () {
383360
test('updates ray origin if position changes', function () {
384361
var origin;

0 commit comments

Comments
 (0)