You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Skybox Creation: This function, skyBox, generates a skybox, a large cube rendered around the entire scene, providing the appearance of distant backgrounds. It uses a cube texture to achieve this effect.
GUI Button Creation: The function createSceneButton generates a GUI button on the screen. This button, upon click, triggers an action, such as transitioning to another scene (setSceneIndex(1)).
functioncreateSceneButton(scene: Scene,name: string,index: string,x: string,y: string,advtex){varbutton=GUI.Button.CreateSimpleButton(name,index);button.left=x;button.top=y;button.width="160px"button.height="60px";button.color="white";button.cornerRadius=20;button.background="#00008B";// Dark blue colorconstbuttonClick=newSound("MenuClickSFX","./assets/audio/menu-click.wav",scene,null,{loop: false,autoplay: false,});button.onPointerUpObservable.add(function(){buttonClick.play();setSceneIndex(1);});advtex.addControl(button);returnbutton;}
Music
Background Music: Initializes background music using a Sound object. It plays a sound file when triggered and handles audio unlock for mobile devices upon user interaction.
functioncreateBackgroundMusic(scene: Scene){constbackgroundMusic=newSound("BackgroundMusic","./assets/audio/391840__vabsounds__space.wav",scene,null,{loop: true,autoplay: true,});Engine.audioEngine!.useCustomUnlockedButton=true;// Unlock audio on first user interaction.window.addEventListener('click',()=>{if(!Engine.audioEngine!.unlocked){Engine.audioEngine!.unlock();}},{once: true});returnbackgroundMusic;}
Game Scene
Celestial Bodies
Skybox Creation: A skybox is generated using MeshBuilder.CreateBox and a cube texture representing a cosmic environment.
Planets: Multiple planets are constructed using MeshBuilder.CreateSphere, each with distinct textures for their surfaces. Physics interactions might be simulated for these planets.
functioncreatePlanet(scene: Scene,px: number,py: number,pz: number){letplanet=MeshBuilder.CreateSphere("planet",{diameter: 6,segments: 68},scene);planet.position.y=1;letplanetMaterial=newStandardMaterial("planetMaterial",scene);// planetMaterial.diffuseColor = new Color3(0, 0, 1);planetMaterial.diffuseTexture=newTexture("./assets/8k_sun.jpg",scene);// Adding the textureplanet.material=planetMaterial;planet.position.x=px;planet.position.y=py;planet.position.z=pz;returnplanet;}functioncreateSecondPlanet(scene: Scene,px: number,py: number,pz: number){letsecondPlanet=createPlanet(scene,px,py,pz);// Reusing the existing createPlanet functionsecondPlanet.scaling=newVector3(0.5,0.5,0.5);// Scaling the second planet downsecondPlanet.position.x=px+10;// Positioning the second planet to the right of the first onesecondPlanet.position.y=py-2;// Lowering the second planetsecondPlanet.position.z=pz;letsecondPlanetMaterial=newStandardMaterial("secondPlanetMaterial",scene);//planetMaterial.diffuseColor = new Color3(0, 0, 1);secondPlanetMaterial.diffuseTexture=newTexture("./assets/8k_jupiter.jpg",scene);// Adding the texturesecondPlanet.material=secondPlanetMaterial;returnsecondPlanet;}
Interactive Elements
Clickable Box: A clickable box triggers the creation of stars using createClickableBox function. This demonstrates interactive behavior upon user interaction.
Spotlight and Point Light: These light sources are dynamically positioned, influencing the scene's lighting and casting shadows on objects like planets.
Physics Aggregates: Elements like the ground, boxes, and player are assigned physics properties utilizing Babylon.js' physics aggregations (PhysicsAggregate), enabling realistic physical behaviors within the scene.
Twinkling Stars: The createStar function creates a continuous color-changing effect to simulate twinkling by altering the emissive color of the stars at intervals.
Camera and Controls
ArcRotateCamera: A camera allowing rotation around a target point, facilitating user interaction within the 3D environment.