I need to render Babylon JS in an external ThreeJS context.
For this, I am creating Babylon engine with webgl2 context(with preserveDrawingBuffer= true). I have the detached control from scene (detachControl) and used a camera from three JS. Here is the source code link.
Both Three JS and Babylon render wireframe boxes.
I rendered the Three JS engine first and Babylon after it.
While the Babylon engine is rendering I ensured scene autoClear and autoClearDepthAndStencil so that it won’t overwrite three js frame buffers.
Upon rendering, below is the result looks like:-
This is incorrect; (a) the Babylon box is not fully rendered (b) the ThreeJS box is invible.
Now, let set Babylon box’s position.y to 2 and here is the output:-
Now, the box is rendering half window, but the ThreeJS box is still invisible.
Further, when this box position.y is set to 10, here the threeJS box start appearing.
I have used Babylon with other external engines, and it works well, here, it seems pretty much closer but not rendering the result as expected.
I am pretty sure some webgl context states have not been reset between both renders and resetting them would work but introduce quite some level of inefficiency in your pipeline.
What are you doing in three that you can not do in babylon ?
Thanks @sebavan. We have our Graphics engine written in Babylon JS, we used it as a library (npm package to integrate with client-side products.
The client projects are using 3rd party rendering engines like MapBox GL.
Some clients are using ThreeJS in their products widely, so it makes sense for us to reuse our rendering engine in their system.
Yes this is expected (somehow). Each engine will keep track on their states and will not know what the other engine is doing. When you call wipeCaches, babylonjs will assume it has to reset everything so it will work for babylon. You may need to find a similar api in threejs maybe?
Other idea: create 2 canvases and use a transparent clear color on the second one
There was some breaking change in three maybe 2 years ago that prevented using phaser within the three context. Im sure same limitation applies to bjs/whatever else.