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

orbitcontrols keep state #87

Open
macrozone opened this issue Oct 26, 2016 · 2 comments
Open

orbitcontrols keep state #87

macrozone opened this issue Oct 26, 2016 · 2 comments
Assignees

Comments

@macrozone
Copy link
Contributor

Hi there,

if my scene gets re-rendered because a prop or state changes, orbit-controls resets to the initial position.

How can i keep it's state?

@Izzimach Izzimach self-assigned this Oct 26, 2016
@Izzimach
Copy link
Owner

Yeah, this is because the orbits controls don't work in the normal flow of React updates. I could maybe add a flag to the Camera component so that it ignores location settings after the initial mount. A better solution would be to rewrite the orbit camera to send props down to the camera, but that would be a chunk of work.

@macrozone
Copy link
Contributor Author

Sorry for the late response.

In my project (for school) I ended up extending the scene-object with a property onOrbit, which is called when the scene is rotated or changed with the orbit controls.

It takes a function and passed the current camera as the only argument.

I further disabled the automatic raycasting to every child on the scene in projectPointerEvent. I had a pointCloud with over a million points in the scene and this killed the performance. Instead i added two properties:

  • onClickRay: is called when user clicks on the scene, no matter if he clicked on an object. It passes the click event, the current ray (from the camera) and the position
  • onMouseMoveRay: same as above but on every mouse move.

I think automatic raycasting should be optional

See this gist: https://gist.github.com/macrozone/5d6b08289c45e17399ce6caf55dc6ed2

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

No branches or pull requests

2 participants