Skip to content

Commit 3ed2a82

Browse files
committed
added raycaster test
1 parent 4212858 commit 3ed2a82

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

docs/components/raycaster.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ AFRAME.registerComponent('collider-check', {
5050

5151
## Properties
5252

53-
| Property | Description | Default Value |
54-
| -------- | ----------- | ------------- |
55-
| autoRefresh | Whether to automatically refresh raycaster's list of objects to test for intersection using mutation observers to detect added or removed entities and components. | true |
56-
| direction | Vector3 coordinate of which direction the ray should point from relative to the entity's origin. | 0, 0, -1 |
57-
| enabled | Whether raycaster is actively checking for intersections. | true |
58-
| far | Maximum distance under which resulting entities are returned. Cannot be lower than `near`. | Infinity |
59-
| 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 |
60-
| 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. | null |
62-
| origin | Vector3 coordinate of where the ray should originate from relative to the entity's origin. | 0, 0, 0 |
63-
| recursive | Checks all children of objects if set. Else only checks intersections with root objects. | true |
64-
| showLine | Whether or not to display the raycaster visually with the [line component][line]. | false |
65-
| useWorldCoordinates | Whether the raycaster origin and direction properties are specified in world coordinates. | false |
53+
| Property | Description | Default Value |
54+
| -------- | ----------- | ------------- |
55+
| autoRefresh | Whether to automatically refresh raycaster's list of objects to test for intersection using mutation observers to detect added or removed entities and components. | true |
56+
| direction | Vector3 coordinate of which direction the ray should point from relative to the entity's origin. | 0, 0, -1 |
57+
| enabled | Whether raycaster is actively checking for intersections. | true |
58+
| far | Maximum distance under which resulting entities are returned. Cannot be lower than `near`. | Infinity |
59+
| 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 |
60+
| 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 |
62+
| 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 |
64+
| showLine | Whether or not to display the raycaster visually with the [line component][line]. | false |
65+
| useWorldCoordinates | Whether the raycaster origin and direction properties are specified in world coordinates. | false |
6666

6767
## Events
6868

src/components/raycaster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ module.exports.Component = registerComponent('raycaster', {
388388
* so that non-recursive raycasting remains useful.
389389
*
390390
* Only push children defined as component attachemnts (e.g., setObject3D),
391-
* not actual children in the scene graph hierarchy.
391+
* NOT actual children in the scene graph hierarchy.
392392
*
393393
* @param {Array<Element>} els
394394
* @return {Array<THREE.Object3D>}

tests/components/raycaster.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ suite('raycaster', function () {
8282
sceneEl.appendChild(el2);
8383
});
8484

85+
test('cannot have redundant objects', function (done) {
86+
const el1 = document.createElement('a-entity');
87+
el1.setAttribute('geometry', 'primitive: box');
88+
const el2 = document.createElement('a-entity');
89+
el2.setAttribute('geometry', 'primitive: box');
90+
el1.appendChild(el2);
91+
92+
el1.addEventListener('loaded', function () {
93+
component.refreshObjects();
94+
const mesh = el2.getObject3D('mesh');
95+
let count = 0;
96+
component.objects.forEach(obj => {
97+
if (obj === mesh) { count++; }
98+
});
99+
assert.equal(count, 1);
100+
done();
101+
});
102+
sceneEl.appendChild(el1);
103+
});
104+
85105
test('can whitelist objects to intersect', function (done) {
86106
var el2 = document.createElement('a-entity');
87107
var el3 = document.createElement('a-entity');

0 commit comments

Comments
 (0)