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

improve raycaster component (fixes #829) #1196

Merged
merged 1 commit into from
Apr 13, 2016
Merged

Conversation

ngokevin
Copy link
Member

Description: Improve overall cursor + raycaster components with respect to performance, configuration, and code quality. This is a stepping stone for more complex cursor/interactions later on.

DEMO

Changes proposed:

  • Don't use requestInterval which adds an additional requestAnimationFrame call. Work off of the existing tick handler.
  • Generalize raycaster component for general use rather than just the cursor. Allow specifying the near, far, recursive. Thus decoupling raycaster and cursor, and having cursor be an abstraction of the raycaster.
  • Raycaster origin/direction can be set with position/rotation of entities
  • Allow passing in a list of entities (via selector) that the raycaster should intersect rather than intersecting everything
  • Allow passing in a list of entities to ignore
  • Return full intersection data in events
  • Move intersectioncleared/mouseleave logic to the cursor component to remove cursor/raycaster coupling
  • Be able to update the raycaster
  • Prefix event/state names with respective component (cursor-/raycaster-)
  • Removed cursor.maxDistance as it was redundant with raycaster.far
  • Fully unit test the raycaster and cursor components

@amberroy
Copy link
Contributor

Cool, I was also thinking it would be useful to get the full intersection data in events. I got it working in my cursor-hitpoint branch, with an example: amberroy@593ab4c

@ngokevin
Copy link
Member Author

Yeah, returning full intersection data is part of the changes in that huge list.

@ngokevin ngokevin changed the title [WIP] improve raycaster component (fixes #829) improve raycaster component (fixes #829) Mar 21, 2016
<a-mixin id="green" material="color: green"></a-mixin>
<a-mixin id="blue" material="color: blue"></a-mixin>
<a-mixin id="yellow" material="color: yellow"></a-mixin>
<a-mixin id="cube-hovered" material="color: #CC435F"></a-mixin>
Copy link
Member

Choose a reason for hiding this comment

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

Why are you replacing color names with hex values?

Copy link
Member Author

Choose a reason for hiding this comment

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

Color palette.

@ngokevin ngokevin force-pushed the raycaster branch 3 times, most recently from e35f581 to 73864d5 Compare March 23, 2016 16:48
@ngokevin ngokevin force-pushed the raycaster branch 3 times, most recently from 64d2bbe to 6d18e04 Compare March 29, 2016 00:50
@ngokevin ngokevin removed this from the 0.3.0 milestone Mar 29, 2016
@ngokevin ngokevin force-pushed the raycaster branch 2 times, most recently from 7ec81cc to 25edaac Compare March 31, 2016 02:45
@ngokevin
Copy link
Member Author

@dmarcos r?

@ngokevin ngokevin force-pushed the raycaster branch 2 times, most recently from 616841e to 095fe62 Compare March 31, 2016 04:32
</a-assets>

<!-- Camera + Cursor. -->
<a-entity camera look-controls>
<a-entity mixin="cursor" position="0 0 -3">
Copy link
Member

Choose a reason for hiding this comment

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

we should not be using primitives here.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is gonna be the boilerplate. <a-cursor> is one of the times i prefer the primitive because manually configuring the inner/outer radius of the ring is hard.

// Update matrix world.
object3D.updateMatrixWorld();
// Grab the position and rotation.
object3D.matrixWorld.decompose(originVec3, directionHelper, scaleDummy);
Copy link
Member

Choose a reason for hiding this comment

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

I would still make directionHelper, originVec3 and scaleDummy private to this function so no other method relies on it to store any state. Like in this example:
https://github.com/aframevr/aframe/blob/master/src/components/look-controls.js#L111

Copy link
Member

Choose a reason for hiding this comment

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

We should wrap directionHelper, originVec3 and scaleDummy in a closure of the method so they're not allocated on every frame. Like the example I had pointed out:
https://github.com/aframevr/aframe/blob/master/src/components/look-controls.js#L111

// Update matrix world.
object3D.updateMatrixWorld();
// Grab the position and rotation.
object3D.matrixWorld.decompose(originVec3, directionHelper, scaleDummy);
Copy link
Member

Choose a reason for hiding this comment

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

You can add scaleDummy to the closure as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not actually using scaleDummy. I just pass it because decompose will expect it.

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

Successfully merging this pull request may close these issues.

3 participants