import * as BABYLON from "babylonjs";

/**
 * Initialize Babylon.js engine and scene
 * @returns {{engine: BABYLON.Engine, scene: BABYLON.Scene}}
 */
export function initializeScene(canvas) {
    const engine = new BABYLON.Engine(canvas, true);
    const scene = new BABYLON.Scene(engine);
    
    scene.clearColor = new BABYLON.Color4(0.05, 0.07, 0.1, 1);
    scene.gravity = new BABYLON.Vector3(0, -0.2, 0);
    scene.collisionsEnabled = true;
    
    // Add hemispheric lighting
    new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
    
    return { engine, scene };
}

/**
 * Start the main render loop
 * @param {BABYLON.Engine} engine
 * @param {BABYLON.Scene} scene
 */
export function startRenderLoop(engine, scene) {
    engine.runRenderLoop(() => {
        scene.render();
    });
    
    window.addEventListener("resize", () => {
        engine.resize();
    });
}
