-
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
Portals #164
Comments
it's better here in issues, because i keep losing track of the discussions and i try to keep issue count down! :) I will definitely add that. I see what you mean as the Thanks for bringing this up, that will be a cool addition. You have lots of good ideas - wish I had more time to devote to them! |
I am wondering if the reconciler in r3f can live outside react/scene, because threejs in general is not limited to geometries being in a specific scene (we discussed this somewhere else already), so it might be correct, that you create the reconciler together with the scene. - it seems to work also outside of the scene, but i am not sure what happens, if we create multiple scenes. might still work. the advantage would be, that we could have a createPortal function. Thats how it is done within r3f. If however, the reconciler lives within Scene, we would need to expose it via a hook, which is different to the react api. I thought it could be something like the following code. However, I wasn't able to expose createPortal to use it within storybook. And when I found a workaround, there were the complains, I mentioned in my first post. But I guess it should be a good direction.
Concerning the context. I am often using zustand. Not sure though if it is usefule for this case, since it lives in global state. But the libraries of daishi (jotai, valtio, zustand) are all pretty nice concerning re-rendering. Not sure if it is necessary for the scene context though, since the scene itself, once created, would not trigger re-renders right?
Would be nicer if I could make a pull request, instead of only writing down ideas ;) But it came out of a demand and saw that react-three-fiber has it. They have many nice ideas. I was trying to convert the HTML overlay to babylonjs. Still needs some refinement, I hope I can push it soon. |
Yess!! That would be really nice to add as well. If you want to start a new issue/branch - would be happy to look even at a draft version 😄 |
OK @dennemark, don't know if you have time to try it out, but my brain is a bit fried from work today! I took a quick look and I will take a better look tomorrow. There is already a reconciler created and the I think we can assume people are not using primary renderer (or add an optional parameter like this) and in render.ts:
if you get it running a storybook would be cool! |
@brianzinn thanks a lot! Unfortunately I could not have a look at it today, too. Will need to have a closer look next week! But now I understand that you have two reconcilers! ( need to read, why you use two renderers ) |
The reason for 2 is just to allow somebody to use the primary renderer, which when I added that feature was an experimental. In other words, typically this reconciler is running as the secondary one (and DOM is the primary one). You can read more here: |
…ly caused by a bug in React. Please file an issue."
I think the current issue is that the public instance is not a "fiber". I will try to add a property to access to proper fiber - I'm working through the new typings on |
…` - seems like createPortal is adding to root container. Something wonky going on here. I may need to attach everything to the babylon object (and return directly as public instance) and that has some odd side-effects for swapping children/fibers etc.
alright @dennemark -so, that latest version seems at least to "work" (with some odd hacks in place) and now to work backwards from there to a clean solution. I feel like {(transformNodeRef.current) &&
createPortal(<box position={new Vector3(0, 1, 0)}>
<standardMaterial diffuseColor={Color3.Blue() } specularColor={Color3.Black()} />
</box>, transformNodeRef.current['__rb_createdInstance'])
} |
Hi, it looks pretty good! I made a pull request to fix the hack. If it is correct, you might laugh, because it was pretty simple ;) #166 Concerning the functionality, i realise the createPortal hook is not fully what I was searching for. I realise I have the same issue as with the html component. As soon as I send the ref outside of the Engine, it will always be null. I was hoping I could send data from somewhere else into the viewport though. Since my interface is living next to the viewport. A bit like this pseudocode:
What I came up with so far, is placing the children of PortalToBJS into a store (zustand). PortalToBJS does not return the children, so it does not complain. And then I read from the store in a another PortalExit component and place the children within the react tree. As I stated in the html #165 pr , this feels a bit hacked though, with unwanted side effects. I am not sure if a context bridge might work here, I will try it out later. |
…ly caused by a bug in React. Please file an issue."
…` - seems like createPortal is adding to root container. Something wonky going on here. I may need to attach everything to the babylon object (and return directly as public instance) and that has some odd side-effects for swapping children/fibers etc.
@dennemark the storybook is published with latest changes (ci)! |
@brianzinn thank! text floats in upper left corner in my case. i will have a look at it tomorrow! also am trying out some other promising approach for a kind of portal. hope to it will work properly! |
great. if it's easier for you to test in an external project let me know if publishing a new NPM would help. Cheers. |
I guess this one can be closed considering #167 Related approaches:
|
Hi,
I was wondering if it is possible to use the reconciler function to create a portal.
Looking at how react-three-fiber is doing it, it seems to be a simple function
However, currently the reconciler is not exposed. The createReconciler function lives within Scene and it does not return the reconciler itself.
I managed to get access to it, but it does not seem to be that easy :/ Getting error
Unexpected Fiber popped.
andExpected host context to exist
Even if I place the createReconciler function outside of Scene, so that it would be called only once, it leads to the same error.
Would it be straightforward and worth to implement?
For completeness, I was trying to achieve something like:
(I just realized, I should have posted it in disccusions....)
The text was updated successfully, but these errors were encountered: