Advertisement
GlobalLiquidity

Untitled

Mar 12th, 2019
230
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. } from '../global/utils'
  7.  
  8. import {
  9.     ddsGc256SpecularHDR,
  10. } from '../global/assets'
  11.  
  12.  
  13. export interface IScene
  14. {
  15.     title: string;
  16.     canvas : HTMLElement;
  17.     engine : bjs.Engine;
  18.     scene : bjs.Scene;
  19.     camera : bjs.Camera;
  20.     light : bjs.PointLight;
  21. }
  22.  
  23. export class Scene implements IScene
  24. {
  25.     engine : bjs.Engine;
  26.     scene : bjs.Scene;
  27.     camera : bjs.ArcRotateCamera;
  28.     light : bjs.PointLight;
  29.  
  30.     constructor(public title: string, public canvas : HTMLElement)
  31.     {
  32.         this.engine = new bjs.Engine(this.canvas as HTMLCanvasElement);
  33.         this.scene = new bjs.Scene(this.engine);
  34.         this.createScene();
  35.     }
  36.  
  37.     createScene () {
  38.         this.scene.clearColor = new bjs.Color4(0.05, 0.05, 0.1, 1.0);
  39.  
  40.         this.camera = new bjs.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 300, bjs.Vector3.Zero(), this.scene);
  41.         this.camera.lowerBetaLimit = ((Math.PI /2) * 0.25);
  42.         this.camera.upperBetaLimit = (Math.PI /2) - ((Math.PI /2) * 0.025);
  43.         this.camera.lowerRadiusLimit = 30;
  44.         this.camera.upperRadiusLimit = 300;
  45.         this.camera.alpha=  Math.PI / 2 - (Math.PI * 0.2);
  46.         this.camera.beta = Math.PI / 2 - (Math.PI * 0.1);
  47.        
  48.         this.camera.attachControl(this.canvas, true);
  49.  
  50.         // Environment Texture
  51.         const hdrTexture: bjs.CubeTexture = bjs.CubeTexture.CreateFromPrefilteredData(ddsGc256SpecularHDR, this.scene);
  52.    
  53.         this.scene.imageProcessingConfiguration.exposure = 0.6;
  54.         this.scene.imageProcessingConfiguration.contrast = 1.6;
  55.        
  56.         // Skybox
  57.         const hdrSkybox: bjs.Mesh = generateSkybox(1000.0, hdrTexture, this.scene);
  58.         const light: bjs.HemisphericLight = new bjs.HemisphericLight("HemiLight", new bjs.Vector3(0.5, 1, 1), this.scene);
  59.  
  60.         this.light = new bjs.PointLight("light", new bjs.Vector3(0, 0, 0), this.scene);
  61.         this.light.diffuse = new bjs.Color3(1, 1, 1);
  62.         this.light.intensity = 1.0;
  63.  
  64.         this.scene.activeCameras = [this.camera];
  65.  
  66.         this.scene.registerBeforeRender(() => {
  67.             this.light.position = this.camera.position;
  68.         });
  69.  
  70.         this.engine.runRenderLoop(() => {
  71.             if (this.scene) {
  72.                 this.light.position = this.camera.position;
  73.                 this.scene.render();
  74.             }
  75.         });
  76.     }    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement