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,
- pngGlNormal,
- } from '../global/assets'
- import { create } from 'domain';
- export interface IScene
- {
- title: string;
- canvas : HTMLElement;
- engine : bjs.Engine;
- bjsScene : bjs.Scene;
- camera : bjs.Camera;
- light : bjs.PointLight;
- }
- export class Scene implements IScene
- {
- engine : bjs.Engine;
- bjsScene : bjs.Scene;
- camera : bjs.ArcRotateCamera;
- light : bjs.PointLight;
- hdrTexture : bjs.CubeTexture;
- hdrSkybox : bjs.Mesh;
- constructor(public title: string, public canvas : HTMLElement)
- {
- this.engine = new bjs.Engine(this.canvas as HTMLCanvasElement);
- this.bjsScene = new bjs.Scene(this.engine);
- this.createBaseScene();
- }
- public createBaseScene () {
- BABYLON.Tools.Log("Creating Base Scene");
- this.bjsScene.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.bjsScene);
- 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
- this.hdrTexture = bjs.CubeTexture.CreateFromPrefilteredData(ddsGc256SpecularHDR, this.bjsScene);
- this.bjsScene.imageProcessingConfiguration.exposure = 0.6;
- this.bjsScene.imageProcessingConfiguration.contrast = 1.6;
- // Skybox
- this.hdrSkybox = generateSkybox(1000.0, this.hdrTexture, this.bjsScene);
- const light: bjs.HemisphericLight = new bjs.HemisphericLight("HemiLight", new bjs.Vector3(0.5, 1, 1), this.bjsScene);
- this.light = new bjs.PointLight("light", new bjs.Vector3(0, 0, 0), this.bjsScene);
- this.light.diffuse = new bjs.Color3(1, 1, 1);
- this.light.intensity = 1.0;
- this.bjsScene.activeCameras = [this.camera];
- this.bjsScene.registerBeforeRender(() => {
- this.light.position = this.camera.position;
- });
- this.engine.runRenderLoop(() => {
- if (this.bjsScene) {
- this.light.position = this.camera.position;
- this.bjsScene.render();
- }
- });
- this.createScene();
- }
- protected createScene()
- {
- //to be filled in by sublass
- }
- }
- export interface ISceneElement
- {
- scene : IScene;
- transform : bjs.TransformNode;
- }
- export class SceneElement implements ISceneElement
- {
- scene : Scene;
- transform : bjs.TransformNode;
- constructor(public name:string, public x: number, public y: number, public z: number, scene:Scene)
- {
- BABYLON.Tools.Log("Scene Element Ctor");
- this.scene = scene;
- this.transform = new bjs.TransformNode(name);
- this.transform.setAbsolutePosition(new bjs.Vector3(x,y,z));
- this.create();
- }
- protected create()
- {
- }
- protected onRender()
- {
- }
- }
- export class GlobalLiqudityLogo extends SceneElement
- {
- public logo: bjs.Mesh;
- protected create()
- {
- BABYLON.Tools.Log("Logo : create()");
- const plasticMaterial: any = new bjs.PBRMaterial("plastic", this.scene.bjsScene);
- plasticMaterial.albedoColor = bjs.Color3.White();
- plasticMaterial.albedoColor = new bjs.Color3(0, 0, 0.2);
- plasticMaterial.normalTexture = new bjs.Texture(pngGlNormal, this.scene.bjsScene);
- plasticMaterial.microSurface = 0.75;
- plasticMaterial.reflectivityColor = new bjs.Color3(0.215, 0.351, 0.727);
- plasticMaterial.reflectionTexture = this.scene.hdrTexture;
- plasticMaterial.useLogarithmicDepth = false;
- BABYLON.Tools.Log("Loading Logo");
- bjs.SceneLoader.ImportMesh("", "./dist/", 'gl.babylon', this.scene.bjsScene, (newMeshes: Array<bjs.AbstractMesh>) => {
- newMeshes[0].position.set(0, 10, 0);
- newMeshes[0].rotation.y = Math.PI;
- newMeshes[0].scaling.set(0.125, 0.125, 0.125);
- newMeshes[0].material = plasticMaterial;
- this.logo = newMeshes[0] as bjs.Mesh;
- this.logo.parent = this.transform;
- });
- }
- }
- export class HomeScene extends Scene
- {
- logo : GlobalLiqudityLogo;
- protected createScene()
- {
- // Water material
- const waterMaterial: bjs.WaterMaterial = generateWaterMaterial(this.bjsScene);
- // Water mesh
- const waterMesh: bjs.Mesh = bjs.Mesh.CreateGround("waterMesh", 512, 512, 32, this.bjsScene, false);
- waterMesh.position.y = -35;
- waterMesh.material = waterMaterial;
- waterMaterial.addToRenderList(this.hdrSkybox);
- this.logo = new GlobalLiqudityLogo("logo",0,25,0,this);
- waterMaterial.addToRenderList(this.logo.logo)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment