Skip to content

Conversation

@ngokevin
Copy link
Member

@ngokevin ngokevin commented Oct 6, 2017

Description:

Rather than emit an event + object on the raycaster entity on each cleared intersection, emit one with no event detail, and event handlers can look it up themselves, but this event is rarely used.

Changes proposed:

  • raycaster.clearedIntersectedEls member.
  • Emit raycaster-intersection-cleared only once per tick.
@dmarcos dmarcos merged commit cb348ec into aframevr:master Oct 6, 2017
clearedIntersectedEls.length = 0;
for (i = 0; i < prevIntersectedEls.length; i++) {
if (intersectedEls.indexOf(prevIntersectedEls[i]) !== -1) { return; }
el.emit('raycaster-intersection-cleared', {el: prevIntersectedEls[i]});
Copy link
Contributor

@vincentfretin vincentfretin Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail only for GearVR and Daydream, because other controllers don't use raycaster, but sphere collider.
I guess in super-hands, we need to get the raycaster component with
var raycaster = this.el.querySelector('[raycaster]') and iterate over raycaster.clearedIntersectedEls. But I'm not sure what do to with your if condition @wmurphyrd to detect if it's a raycaster event or an sphere-collider event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's continue the discussion there c-frame/aframe-super-hands-component#79

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you'd iterate over them and clear them all at once versus one at a time.

@wmurphyrd
Copy link
Collaborator

What's the advantage of not including clearedIntersectedEls in the details of the raycaster-intersection-cleared event?

The disadvantage is other components would have to directly access the raycaster component instance object to learn the details, something I thought was discouraged

@ngokevin
Copy link
Member Author

ngokevin commented Oct 6, 2017

Component members can be part of the public API, it's not discouraged to expose properties/methods. Not including would just save creating an object on each tick for garbage collection purposes. Is it able to fix?

@ngokevin
Copy link
Member Author

ngokevin commented Oct 6, 2017

Oh, never mind, I guess you can maybe pass the array without creating an object.

@machenmusik
Copy link
Contributor

This breaks everything using raycaster, right? As there is no way AFAIK to detect the behavior change, if we’re going to break the existing contract, maybe better to change event name so compatibility can be achieved by supporting both old and new event names...

@dmarcos
Copy link
Member

dmarcos commented Oct 6, 2017

@wmurphyrd I opened #3128 to pass the cleared elements as a detail of the event.

@ngokevin
Copy link
Member Author

ngokevin commented Oct 6, 2017

I think versions are allowed to have some small breaking changes, especially in 0.x.x, if there's some gains, as long as things can easily adapt. It'd only break things directly using the raycaster events emitted from the raycasting entity, which I thought was not used often. The contract only applies within versions, but yeah, I wish it didn't break things.

@machenmusik
Copy link
Contributor

Maybe it would be nicer to have a helper component that adds a listener that calls the prior contract, so if you need the old behavior you can add raycaster-legacy-events or sonething

@machenmusik
Copy link
Contributor

I completely agree that small breaking changes are allowed, but now that the framework has more traction and wider usage, correspondingly small affordances to ease migration seem more worthwhile to consider. Along the lines of gltf next and legacy, having legacy helper components that throw deprecation warnings once for a point release might be a reasonable approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants