Advertisement
GlobalLiquidity

Untitled

Mar 12th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import * as bjs from 'babylonjs';
  3.  
  4. import {
  5.     generateSkybox,
  6.     generateWaterMaterial
  7. } from '../global/utils'
  8.  
  9. import {
  10.     ddsGc256SpecularHDR,
  11. } from '../global/assets'
  12.  
  13.  
  14. export interface IScene
  15. {
  16.     title: string;
  17.     canvas : HTMLElement;
  18.     engine : bjs.Engine;
  19.     scene : bjs.Scene;
  20.     camera : bjs.Camera;
  21.     light : bjs.PointLight;
  22. }
  23.  
  24. export class Scene implements IScene
  25. {
  26.     engine : bjs.Engine;
  27.     scene : bjs.Scene;
  28.     camera : bjs.ArcRotateCamera;
  29.     light : bjs.PointLight;
  30.     hdrSkybox : bjs.Mesh;
  31.  
  32.     constructor(public title: string, public canvas : HTMLElement)
  33.     {
  34.         this.engine = new bjs.Engine(this.canvas as HTMLCanvasElement);
  35.         this.scene = new bjs.Scene(this.engine);
  36.         this.createBaseScene();
  37.     }
  38.  
  39.     public createBaseScene () {
  40.         this.scene.clearColor = new bjs.Color4(0.05, 0.05, 0.1, 1.0);
  41.  
  42.         this.camera = new bjs.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 300, bjs.Vector3.Zero(), this.scene);
  43.         this.camera.lowerBetaLimit = ((Math.PI /2) * 0.25);
  44.         this.camera.upperBetaLimit = (Math.PI /2) - ((Math.PI /2) * 0.025);
  45.         this.camera.lowerRadiusLimit = 30;
  46.         this.camera.upperRadiusLimit = 300;
  47.         this.camera.alpha=  Math.PI / 2 - (Math.PI * 0.2);
  48.         this.camera.beta = Math.PI / 2 - (Math.PI * 0.1);
  49.        
  50.         this.camera.attachControl(this.canvas, true);
  51.  
  52.         // Environment Texture
  53.         const hdrTexture: bjs.CubeTexture = bjs.CubeTexture.CreateFromPrefilteredData(ddsGc256SpecularHDR, this.scene);
  54.    
  55.         this.scene.imageProcessingConfiguration.exposure = 0.6;
  56.         this.scene.imageProcessingConfiguration.contrast = 1.6;
  57.        
  58.         // Skybox
  59.         this.hdrSkybox = generateSkybox(1000.0, hdrTexture, this.scene);
  60.         const light: bjs.HemisphericLight = new bjs.HemisphericLight("HemiLight", new bjs.Vector3(0.5, 1, 1), this.scene);
  61.  
  62.         this.light = new bjs.PointLight("light", new bjs.Vector3(0, 0, 0), this.scene);
  63.         this.light.diffuse = new bjs.Color3(1, 1, 1);
  64.         this.light.intensity = 1.0;
  65.  
  66.         this.scene.activeCameras = [this.camera];
  67.  
  68.         this.scene.registerBeforeRender(() => {
  69.             this.light.position = this.camera.position;
  70.         });
  71.  
  72.         this.engine.runRenderLoop(() => {
  73.             if (this.scene) {
  74.                 this.light.position = this.camera.position;
  75.                 this.scene.render();
  76.             }
  77.         });
  78.  
  79.         this.createScene();
  80.     }
  81.    
  82.     protected createScene()
  83.     {
  84.         //to be filled in by sublass
  85.     }
  86. }
  87.  
  88. export class HomeScene extends Scene
  89. {
  90.     protected createScene()
  91.     {
  92.           // Water material
  93.           const waterMaterial: bjs.WaterMaterial = generateWaterMaterial(this.scene);
  94.  
  95.           // Water mesh
  96.           const waterMesh: bjs.Mesh = bjs.Mesh.CreateGround("waterMesh", 512, 512, 32, this.scene, false);
  97.           waterMesh.position.y = -35;
  98.           waterMesh.material = waterMaterial;
  99.           waterMaterial.addToRenderList(this.hdrSkybox);
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement