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

How to use controlled TransformControls? #21

Closed
kevinresol opened this issue May 19, 2020 · 2 comments · Fixed by #27
Closed

How to use controlled TransformControls? #21

kevinresol opened this issue May 19, 2020 · 2 comments · Fixed by #27

Comments

@kevinresol
Copy link
Contributor

I tried something like this:

<TransformControls position={props.position} ref={ref}>
	<mesh position={props.position}>
		{/* geometry and material omitted for brevity */}
	</mesh>
</TransformControls>

and fire a callback like so:

ref.current.addEventListener('dragging-changed', function(e) {
  props.onChange(ref.current.object.position);
});

but when the position is updated and the view re-rendered, the mesh and the UI helper will jump away for the same distance of the last drag. My gut feeling is that there are some internal offset stored by the control which breaks this controlled pattern.

@drcmda
Copy link
Member

drcmda commented May 20, 2020

i dont know how transformcontrols works internally, but is it even possible to control them? they're for certain not made for react.

@kevinresol kevinresol changed the title How to used controlled TransformControls? How to use controlled TransformControls? May 20, 2020
@kevinresol
Copy link
Contributor Author

but is it even possible to control them

Apparently it doesn't right now. But I guess it could be done if transformcontrols expose some functions to reset its internally cached state.

kevinresol added a commit to kevinresol/drei that referenced this issue May 26, 2020
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

Successfully merging a pull request may close this issue.

2 participants