Dom in Babylonjs Editor?

Hi,
Is there any way to access the DOM when working with the babylonjs editor ?

Context : I’m on a web project running VueJS, working to add WebXR support. I want to make Babylonjs and Vue communicate information and assets (from Vue to babylonjs through the DOM mostly). Is this something that can be done through the editor ?

PS : fairly new to babylonjs + this is my first topic, feel free to remove if you think this is inappropriate here :slight_smile:
PS2 : Can make a feature request out of this topic if you think it’s a good idea!

Adding the awesome daddy of the editor @julien-moreau to the thread.

A consistent way could be to get a reference to the babylon engine’s canvas then get its owner document. If the canvas’s frame is in a child frame, u can check the window’s .top property for the root frame or iteratively walk up using the .parent property (if needed at all)

.Node.ownerDocument - Web APIs | MDN

. Window.top - Web APIs | MDN

1 Like

Hi @Wellandr !
All questions about babylonjs are appropriate here :slight_smile:

I’m not sure to understand, do you mean that you’de like to integrate your Babylon.JS Editor project in a Vue.JS project?

If yes, the “index.ts” file generated by the Editor (when you create a new workspace) is an entry point example that you can highly customize. The only important step is to call the “runScene” function that will attach the scripts once your scene has been loaded. Scripts you have attached can’t be instantiated by you but they can import any other TS file you have in your project. Sharing data/classes/etc. between your Vue app and the babylonjs part is free and there a not guideline I can share with you

I’m adding @jim-decocq in case he wants to share his experience :slight_smile:

Like @ julien-moreau say :

  • Import babylon.js.
  • Declare you canvas and engine inside vue.JS
  • Load the scene.babylon from the editor (put this in your assets and keep the same structure with a child Files directory)
  • import all .ts file from src directory inside babylon project.
  • And execute runScene .
  • Launch the renderloop

For all script you need to add the super inside constructor for es6.

I do that with angular and to avoid bind check on babylon engine the renderloop is executed outside ngZone.