I added a babylon scene to my react application and I need it to be responsive so that when the user restores down the web browser that he/she can still be able to see everything properly and work with objects on the scene.
Responsive usually defines the behavior on different screen sizes. But it seems like you refer to the user leaving and coming back to the browser. Babylon does support that, and there is no reason why it wouldn’t work in your app as well (just try leaving the playground and come back).
What is your use case, and what doesn’t work? without that it will be very hard to help
Hi ! Just like RaananW, I’m not sure what you mean by responsive. Did you mean “resize” instead of “restores” ?
If that is the case and you want the scene to resize when the window dimensions change, the way babylon does it is this :
// Initialize
const canvas = document.getElementById('renderCanvas')
const engine = new BABYLON.Engine(canvas)
// Watch canvas resize event to adjust the 3D scene
const resizeWatcher = new ResizeObserver(() => {
engine.resize()
})
resizeWatcher.observe(canvas)
Hello @Faber , Yes I mean resizing the window, I want the scene to be responsive in that meaning. The thing in my react application the scene is a jsx component that I created while following the setup of a babylon application in react and im not knowing where to add this code you are showing me.
Alright then, if it is in JSX there can be no playground. Can you share with us some of your code, especially where you are creating the Babylon engine and scene ?
@Faber Hello again, the thing is my scene is responsive and fits along with the size of the window, but Panels in the scene are not being responsive. Do you know why or how to fix this?
Do you want your 3d scene to be responsive as well? if doesn’t fit in the screen move it below?
@msDestiny14 might be able to help if you want your fullscreen GUI to be responsive, but it’s not an easy task to make an entire scene responsive. If this is what you want to achieve, you will need to check if a mesh is in the camera’s frustum, and move it accordingly. But a 3D scene is not a browser window. There is no “max width” and “max height”. there is also no grid system or flex boxes But as everyone else said, we will need to know a bit more what your use case is in order to help.
Certainly the ResizeObserver is needed if you are resizing panels and with only the window resize listener, the engine itself would not resize when your resize panels. ResizeObserver has broad enough support now that it should be on the official example (it was not available until last year, so before that sample code was written).
What i meant is that there is no native support for such a thing
I am sure there are many projects that support that, but there is no gl.setGridSize call, or a universal box.flex=1.