Bringing existing C++ code base based on ecs to Babylon Native


First I want to thank you for Babylon Native. it is a great idea and I think it will be a game-changer.

What is the best strategy to bring some C++ game logic based on ECS physics for Babylon for rendering, audio, and input? Do we bring it as a plugin, or there is a specific mechanism for this sort of integration. Basically, most of the logic will happen in the C++ part, and then we will fill buffers that javascript will consume for rendering and presentation.

So basically my question is about a document that is not this document :slight_smile: BabylonNative/ at master · BabylonJS/BabylonNative · GitHub " An extremely straightforward example might be to create an application that uses Babylon Native to render a 3D scene and uses a completely seperate library such as ImGUI to render a user interface. This kind of “extension” is not the focus of this document. This document’s focus is on extending Babylon Native by adding features within the framework of Babylon Native itself."


Adding our native friends @bghgary @Cedric and @syntheticmagus who will know way better than me how to answer

Thanks @sebavan

(Thanks for the ping, sebavan!)

Hi kariem2k,

Welcome to Babylon, and thanks for checking out Babylon Native!

While I’m not familiar with ECS physics, what you’ve described sounds like it probably makes the most sense as a plugin since you want to add a C++ implementation which exposes new functionality to JavaScript. An example of how you might structure this would be to have your plugin expose a new N-API type that exposes the data buffers you want, then have that type either update itself per-frame (by, for instance, taking a Babylon Scene as a constructor argument and observe the onBeforeRenderObservable) or expose an update() method to allow users to manually trigger state refresh.

If something like that sounds like what you’re intending, probably the fastest way to get started on it would be to build off the Babylon Native Extension Template as described in the Quick-Start Guide. (That’s lower in the same document you linked to before, though, so it’s quite possible I’ve misinterpreted what you’re trying to do; if so, please help me understand better.) Hope this helps, and best of luck!


@syntheticmagus Thank you very much, yes I will try that. I have another last question, Bablyon native does not expose webgl context correct? so for example if I want to try Babylon.js and Pixi.js | Babylon.js Documentation it won’t work (which is fine, I just want to know my limits), correct?

Yup exactly, the native hooks are at the babylon engine level not webgl in order to provide us with more flexibility. You are not able to use any other gl framework with it.

1 Like