import { AssetEvent , Vector3D , AssetLibrary , IAsset , URLRequest , RequestAnimationFrame } from "@awayjs/core" ; import { Sprite , Scene } from "@awayjs/scene" ; import { MethodMaterial , DirectionalLight , StaticLightPicker } from "@awayjs/materials" ; import { AWDParser } from "@awayjs/parsers" ; import { View } from "@awayjs/view" ; class Basic_LoadAWD { private _scene : Scene ; private _light : DirectionalLight ; private _lightPicker : StaticLightPicker ; private _suzanne : Sprite ; private _timer : RequestAnimationFrame ; private _time : number = 0 ; /**
     * Constructor
     */ constructor ( ) { this . init ( ) ; } /**
     * Global initialise function
     */ private init ( ) { this . initEngine ( ) ; this . initLights ( ) ; this . initMaterials ( ) ; this . initObjects ( ) ; this . initListeners ( ) ; } /**
     * Initialise the engine
     */ private initEngine ( ) { this . _scene = new Scene ( ) ; this . _scene . view . backgroundColor = 0x1e2125 ; this . _scene . camera . z = - 2000 ; } /**
     * Initialise the entities
     */ private initLights ( ) { this . _light = new DirectionalLight ( ) ; this . _light . color = 0x683019 ; this . _light . direction = new Vector3D ( 1 , 0 , 0 ) ; this . _light . ambient = 0.5 ; this . _light . ambientColor = 0x30353b ; this . _light . diffuse = 2.8 ; this . _light . specular = 1.8 ; this . _lightPicker = new StaticLightPicker ( [ this . _light ] ) ; } /**
     * Initialise the materials
     */ private initMaterials ( ) { } /**
     * Initialise the scene objects
     */ private initObjects ( ) { } /**
     * Initialise the listeners
     */ private initListeners ( ) { window . onresize = ( event ) => this . onResize ( event ) ; this . onResize ( ) ; this . _timer = new RequestAnimationFrame ( this . onEnterFrame , this ) ; this . _timer . start ( ) ; AssetLibrary . enableParser ( AWDParser ) ; AssetLibrary . addEventListener ( AssetEvent . ASSET_COMPLETE , ( event ) => this . onAssetComplete ( event ) ) ; AssetLibrary . load ( new URLRequest ( 'assets/suzanne.awd' ) ) ; } /**
     * Navigation and render loop
     */ private onEnterFrame ( dt ) { this . _time += dt ; if ( this . _suzanne ) this . _suzanne . rotationY += 1 ; this . _scene . render ( ) ; } /**
     * Listener function for asset complete event on loader
     */ private onAssetComplete ( event ) { var asset = event . asset ; switch ( asset . assetType ) { case Sprite . assetType : var sprite = < Sprite > asset ; sprite . y = - 300 ; sprite . transform . scaleTo ( 900 , 900 , 900 ) ; this . _suzanne = sprite ; this . _scene . root . addChild ( sprite ) ; break ; case MethodMaterial . assetType : var material = < MethodMaterial > asset ; material . lightPicker = this . _lightPicker ; break ; } } /**
     * stage listener for resize events
     */ private onResize ( event = null ) { this . _scene . view . y = 0 ; this . _scene . view . x = 0 ; this . _scene . view . width = window . innerWidth ; this . _scene . view . height = window . innerHeight ; } } window . onload = function ( ) { new Basic_LoadAWD ( ) ; } ;