Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as bjs from 'babylonjs';
- import {
- generateSkybox,
- generateWaterMaterial
- } from '../global/utils'
- import {
- ddsGc256SpecularHDR,
- } from '../global/assets'
- export interface IScene
- {
- title: string;
- canvas : HTMLElement;
- engine : bjs.Engine;
- scene : bjs.Scene;
- camera : bjs.Camera;
- light : bjs.PointLight;
- }
- export class Scene implements IScene
- {
- engine : bjs.Engine;
- scene : bjs.Scene;
- camera : bjs.ArcRotateCamera;
- light : bjs.PointLight;
- hdrSkybox : bjs.Mesh;
- constructor(public title: string, public canvas : HTMLElement)
- {
- this.engine = new bjs.Engine(this.canvas as HTMLCanvasElement);
- this.scene = new bjs.Scene(this.engine);
- this.createBaseScene();
- }
- public createBaseScene () {
- this.scene.clearColor = new bjs.Color4(0.05, 0.05, 0.1, 1.0);
- this.camera = new bjs.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 300, bjs.Vector3.Zero(), this.scene);
- this.camera.lowerBetaLimit = ((Math.PI /2) * 0.25);
- this.camera.upperBetaLimit = (Math.PI /2) - ((Math.PI /2) * 0.025);
- this.camera.lowerRadiusLimit = 30;
- this.camera.upperRadiusLimit = 300;
- this.camera.alpha= Math.PI / 2 - (Math.PI * 0.2);
- this.camera.beta = Math.PI / 2 - (Math.PI * 0.1);
- this.camera.attachControl(this.canvas, true);
- // Environment Texture
- const hdrTexture: bjs.CubeTexture = bjs.CubeTexture.CreateFromPrefilteredData(ddsGc256SpecularHDR, this.scene);
- this.scene.imageProcessingConfiguration.exposure = 0.6;
- this.scene.imageProcessingConfiguration.contrast = 1.6;
- // Skybox
- this.hdrSkybox = generateSkybox(1000.0, hdrTexture, this.scene);
- const light: bjs.HemisphericLight = new bjs.HemisphericLight("HemiLight", new bjs.Vector3(0.5, 1, 1), this.scene);
- this.light = new bjs.PointLight("light", new bjs.Vector3(0, 0, 0), this.scene);
- this.light.diffuse = new bjs.Color3(1, 1, 1);
- this.light.intensity = 1.0;
- this.scene.activeCameras = [this.camera];
- this.scene.registerBeforeRender(() => {
- this.light.position = this.camera.position;
- });
- this.engine.runRenderLoop(() => {
- if (this.scene) {
- this.light.position = this.camera.position;
- this.scene.render();
- }
- });
- this.createScene();
- }
- protected createScene()
- {
- //to be filled in by sublass
- }
- }
- export class HomeScene extends Scene
- {
- protected createScene()
- {
- // Water material
- const waterMaterial: bjs.WaterMaterial = generateWaterMaterial(this.scene);
- // Water mesh
- const waterMesh: bjs.Mesh = bjs.Mesh.CreateGround("waterMesh", 512, 512, 32, this.scene, false);
- waterMesh.position.y = -35;
- waterMesh.material = waterMaterial;
- waterMaterial.addToRenderList(this.hdrSkybox);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement