-
Notifications
You must be signed in to change notification settings - Fork 108
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
feat: ✨ Html Component that will place DOM content on the canvas at the location of its parent babylon node. #165
Conversation
…he location of its parent babylon node. transform property does not work correctly, since matrix might be wrong. currently storybook example under GUI>Html Text does not work. Components within Html Component loose context.
Hi @brianzinn here is the Html component. I couldn't make it work in storybook, but should normally not have any issues, except if you want to use features, such as transform via css or keep context of parent react. This component creates a new react renderer for each Html component unfortunately... |
this is great @dennemark ! did you try the Portal on the |
@brianzinn unfortunately I did not find the time for #164 today. But will have a look at it soon. I actually tried to use ReactDOM.createPortal to create a portal to the parent element of the canvas. Unfortunately, some errors appeared. react-babylonjs thinks a dom element is added and returns this error:
But i feel the problem is deeper integrated in react: facebook/react#13332 Not sure if this approach would be a solution: https://dev.to/rihdusr/render-a-react-component-in-google-map-171o I think it would be good, if the Html component could avoid the ReactDOM.render function and use createPortal or something similar instead. Lets see.. |
yes, you cannot have any DOM elements inside the Essentially it would use a supplied canvas instead of creating one, but a selector could be added to find the canvas perhaps for a non-canvas. If it's not about attaching to an existing canvas then I need to understand a bit more about your use-case. I added the XR feature for DOM-Overlay to babylonjs and it used a CSS selector for the overlay feature. |
also zustand is an interesting option, since it fixes the pesky renderer boundary issue. need to investigate how it handles multiple scenes/etc. currently there are no dependencies outside of babylon, but that is a worthy consideration. |
zustand normally works with global state. there are ways to use it via context, too, which might be good for multiple scenes. concerning the dom elements within I am using chakra-ui and it has some nice benefits for css props. i.e.
|
maybe lefthanded vs righthanded is the matrix issue :D https://forum.babylonjs.com/t/html-in-3d-space-part-2-bjs-way-to-matrix-transform/3214/2 |
The context provider can be solved with a bridge like here: I see what you are on about now with rendering DOM as that is the HTML children. If you are trying to npm link to a project then you need to actually npm link the react libraries to both projects. If you want to start a test repo then I am happy to get a proper end to end working - or additionally I can publish NPMs as well on 164 as there are no public API changes. |
The context bridge seems to be a good approach for this issue! Thanks a lot! |
ok - I've merged everything - I think it's OK for now that accessing __rb_createdInstance is in place, but if I can fix without that would be better. It's a hectic week at work, but will make time. Cheers. |
I'll add also to readme and docs when I get the storybook running! Thanks 😄 |
translated from https://github.com/pmndrs/drei html component.
transform property does not work correctly, since matrix might be wrong - need to have a look at difference of threejs matrix and babylonjs matrix.
currently storybook example under GUI>Html Text does not work?Furthermore components within Html Component loose context. Creating Portal does not work, since react has issues with react-babylonjs. Might open a seperate issue for this.