-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
React Three Fiber integration #262
Comments
Thanks for using and your suggestion.
I think it works. Could you double-check that you have made a wrapper component of the original camera-controls like the example? or would you mind providing a demo that does not work as expected?
That would be nice and we could make another package with camera-control, however, I think just providing the example code is more flexible to use |
Yes, I got it to work eventually. I just had to install TypeScript since my code is Vanilla. I'm currently using OrbitControls, but it has some limitations and would really love to give this a try. Thank you for your effort! |
So here's Pauls (creator of r3f) simple wrapper using the r3f After that is on you to make it work for your project. What are you trying to do that you couldnt? I'm ALSO writing a r3f variant... |
I managed to get it to work. I was suggesting it would be nice to have this wrapper included in the library by default, instead of having to set it up. I'm not an expert in Three and React, quite contrary, so I'm having a difficult time trying to wrap my hand around this stuff and how it works. If I could just import a component and add it to my scene out of the box, like OrbitControls, that would be awesome. Anyway, thanks again for your feedback. |
First of all, I'm happy to see this conversation. Thank you for your suggestions again. If we provide r3f ready camera-controls in this repository, we also need to add additional dependencies which are React and r3f. but I think that is too much. So, I would make another repository, but I'm not sure that I could keep it updated. I personally encourage you to use our example Because ours can use more instance methods via the Ref! |
Alright, then a .jsx version would be fine. I would use that one instead of .tsx. In the future I think more and more people will migrate towards r3f though, since it's so much easier to use compared to vanilla Three. But I also understand it's a lot of work for just one person to keep this updated. |
Can you clarify this point? I saw the instance mentioned in your wrapper but Im not sure when you would be utilizing it. Pauls version is very basic but also has the ref exposed so I believe most generic methods would work |
@marcelpi Thanks for understanding. @DennisSmolek As you can see there are Also, provide types in ts. |
@marcelpi |
Thank you! |
I have mimicked the implementation of drei's It supports currently:
|
No need, this is why we have Drei. Happy to continue in pmndrs/drei#1237. |
|
@abernier @CodyJasonBennett That's big news for me! Thank you very much!! Now it's sort of official! Really appreciate it. |
Thank you @yomotsu it'a nice to see your enthusiasm about it :) After the release, @drcmda one of the author of r3f, pointed me out a small issue though... In react, in dev mode (with strict-mode) a component can be rendered twice(or more). As a consequence, it is important we can disconnect and re-connect all events, once the component is re-rendered. In other words, it is particularly important the CameraControls class's constructor does not have any side-effects (like binding events). Otherwise, events for example, will be bound multiple times. I think we could quite easily create a dedicated We could then have the following flow in React:
I will try submitting a PR for this, but will for sure need help from you ;) Footnotes
|
@yomotsu so happy to see you like it, i hope it will drive more users to this amazing library. btw here's how we handle the constructor side effect issue with all other controls: class OrbitControls extends EventDispatcher {
domElement: HTMLElement | undefined
constructor(object: Camera, domElement?: HTMLElement) {
this.connect = (domElement: HTMLElement): void => {
scope.domElement = domElement
scope.domElement.style.touchAction = 'none'
scope.domElement.addEventListener('contextmenu', onContextMenu)
...
}
this.dispose = (): void => {
scope.domElement?.removeEventListener('contextmenu', onContextMenu)
scope.domElement?.removeEventListener('pointerdown', onPointerDown)
...
}
// connect events
if (domElement !== undefined) this.connect(domElement) it's entirely optional and backward compatible. this standard way: const ctrl = new Controls(cam, domNode) and optionally const ctrl = new Controls(cam)
ctrl.connect(domNode)
// later ...
ctrl.dispose() this allows us to connect and re-connect to dom layers, but also takes care of this issue: mrdoob/three.js#20575 |
for the record, |
Is your feature request related to a problem? Please describe.
Please make this library easy to use in React Three Fiber. That would be a major time-saver as a lot of people are using R3F nowadays and there are plenty of projects developed in React.
Describe the solution you'd like
A component one can import and use right away, like .
I tried using it in R3F using the example you provided, but didn't manage to get it going.
Still, I would love to use it.
The text was updated successfully, but these errors were encountered: