Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add raycaster.enabled property to toggle tick handler #3148

Merged
merged 1 commit into from
Oct 10, 2017
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
1 change: 1 addition & 0 deletions docs/components/raycaster.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ AFRAME.registerComponent('collider-check', {
| -------- | ----------- | ------------- |
| 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 |
| direction | Vector3 coordinate of which direction the ray should point from relative to the entity's origin. | 0, 0, 0 |
| enabled | Whether raycaster is actively checking for intersections. | true |
| far | Maximum distance under which resulting entities are returned. Cannot be lower then `near`. | Infinity |
| interval | Number of milliseconds to wait in between each intersection test. Lower number is better for faster updates. Higher number is better for performance. | 100 |
| near | Minimum distance over which resuilting entities are returned. Cannot be lower than 0. | 0 |
Expand Down
7 changes: 5 additions & 2 deletions src/components/raycaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ var OBSERVER_CONFIG = {
*/
module.exports.Component = registerComponent('raycaster', {
schema: {
autoRefresh: {default: true},
direction: {type: 'vec3', default: {x: 0, y: 0, z: -1}},
enabled: {default: true},
far: {default: 1000},
interval: {default: 100},
near: {default: 0},
objects: {default: ''},
origin: {type: 'vec3'},
recursive: {default: true},
showLine: {default: false},
useWorldCoordinates: {default: false},
autoRefresh: {default: true}
useWorldCoordinates: {default: false}
},

init: function () {
Expand Down Expand Up @@ -166,6 +167,8 @@ module.exports.Component = registerComponent('raycaster', {
var prevIntersectedEls = this.prevIntersectedEls;
var rawIntersections;

if (!this.data.enabled) { return; }

// Only check for intersection if interval time has passed.
if (prevCheckTime && (time - prevCheckTime < data.interval)) { return; }
// Update check time.
Expand Down