Is there a way to export/import objects like scene, camera etc in different files (js) without having to pass them as parameters?
The 3 JS files below is what I use now. I was wondering if there is a better way.
I am using vue and vuex if it matters, but a lot of the babylon code is seperate, which makes things a bit complicated for me.
render.js
export const render = () => {
const canvas = document.getElementById('renderCanvas');
const engine = new BABYLON.Engine(canvas, true);
const scene = createScene(canvas, engine);
engine.runRenderLoop(function() {
scene.render();
});
window.addEventListener('resize', function() {
engine.resize();
});
};
createScene.js
export const createScene = function(canvas, engine) {
const scene = new BABYLON.Scene(engine),
camera = resetZoom(canvas, scene),
light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene),
ground = createGround(scene),
axis = new BABYLON.Debug.AxesViewer();
createFloorplan(scene, ground, camera, canvas);
return scene;
}
createFloorplan.js
export const createFloorplan = (scene, ground, camera, canvas) => {
// Lots of code that uses all these parameters
}