import { AssetEvent , LoaderEvent , ParserEvent , URLRequest , RequestAnimationFrame , CoordinateSystem , PerspectiveProjection } from "@awayjs/core" ; import { Graphics , Shape } from "@awayjs/graphics" ; import { HoverController , TextField , Sprite , Billboard , Camera , LoaderContainer , MovieClip , Scene , SceneGraphPartition , DisplayObjectContainer } from "@awayjs/scene" ; import { MethodMaterial } from "@awayjs/materials" ; import { AWDParser } from "@awayjs/parsers" ; import { DefaultRenderer } from "@awayjs/renderer" ; import { View } from "@awayjs/view" ; import { AS2SceneGraphFactory } from "@awayjs/player" ; class AWD3ViewerMinimal { private _fps : number = 30 ; private _root : DisplayObjectContainer ; private _scene : Scene ; private _rootTimeLine : MovieClip ; private _timer : RequestAnimationFrame ; private _time : number = 0 ; private _projection : PerspectiveProjection ; private _hoverControl : HoverController ; private _stage_width : number ; private _stage_height : number ; private _material : MethodMaterial ; private _shapes : Array < Shape > = new Array < Shape > ( ) ; private counter : number ; /**
     * Constructor
     */ constructor ( ) { this . init ( ) ; } /**
     * Global initialise function
     */ private init ( ) { this . initEngine ( ) ; this . initObjects ( ) ; this . initListeners ( ) ; } /**
     * Initialise the engine
     */ private initEngine ( ) { this . _root = new DisplayObjectContainer ( ) ; this . _scene = new Scene ( new SceneGraphPartition ( this . _root ) ) ; this . _scene . renderer . renderableSorter = null ; this . _scene . view . backgroundColor = 0x000000 ; this . _stage_width = 550 ; this . _stage_height = 400 ; this . _projection = new PerspectiveProjection ( ) ; this . _projection . coordinateSystem = CoordinateSystem . RIGHT_HANDED ; this . _projection . originX = - 1 ; this . _projection . originY = 1 ; this . _projection . fieldOfView = Math . atan ( this . _stage_height / 1000 / 2 ) * 360 / Math . PI ; var camera = new Camera ( ) ; camera . projection = this . _projection ; this . _hoverControl = new HoverController ( camera , null , 180 , 0 , 1000 ) ; this . _scene . camera = camera ; } /**
     * Initialise the scene objects
     */ private initObjects ( ) { var loader = new LoaderContainer ( ) ; loader . addEventListener ( AssetEvent . ASSET_COMPLETE , ( event ) => this . onAssetComplete ( event ) ) ; loader . addEventListener ( LoaderEvent . LOAD_COMPLETE , ( event ) => this . onRessourceComplete ( event ) ) ; loader . addEventListener ( ParserEvent . PARSE_ERROR , ( event ) => this . onParseError ( event ) ) ; loader . load ( new URLRequest ( "assets/AWD3/MagnifyGlass.awd" ) , null , null , new AWDParser ( new AS2SceneGraphFactory ( this . _scene ) ) ) ; this . _material = new MethodMaterial ( 0x000001 ) ; this . _material . style . color = 0x000001 ; } /**
     * Initialise the listeners
     */ private initListeners ( ) { window . onresize = ( event ) => this . onResize ( event ) ; this . onResize ( ) ; this . _timer = new RequestAnimationFrame ( this . onEnterFrame , this ) ; this . _timer . start ( ) ; } /**
     * loader listener for asset complete events
     */ private onAssetComplete ( event ) { console . log ( "graphic: " + event . asset . assetType ) ; if ( event . asset . isAsset ( Graphics ) ) { var one_graphics = < Graphics > event . asset ; for ( var i = 0 ; i < one_graphics . count ; i ++ ) { this . _shapes . push ( < Shape > one_graphics . getShapeAt ( i ) ) ; } } else if ( event . asset . isAsset ( TextField ) ) { var one_textfield = < TextField > event . asset ; } else if ( event . asset . isAsset ( Sprite ) ) { var one_sprite = < Sprite > event . asset ; } else if ( event . asset . isAsset ( Billboard ) ) { var one_billboard = < Billboard > event . asset ; } else if ( event . asset . isAsset ( MovieClip ) ) { var movieClip = < MovieClip > event . asset ; if ( movieClip . name == "border" || movieClip . name == "dream" || movieClip . name == "IAP Menu" || movieClip . name == "language flag" || movieClip . name == "shoptag_shapes" || movieClip . name == "shoptag_cliffedges" || movieClip . name == "languages baked" || movieClip . name == "Character" || movieClip . name == "free" ) { movieClip . mouseEnabled = false ; movieClip . mouseChildren = false ; } this . _rootTimeLine = movieClip ; } } /**
     * loader listener for asset complete events
     */ /**
     * loader listener for asset complete events
     */ private onParseError ( event ) { console . log ( event . message ) ; } /**
     * loader listener for asset complete events
     */ private onRessourceComplete ( event ) { if ( this . _rootTimeLine ) { for ( var i = 0 ; i < this . _shapes . length ; i ++ ) { } this . _root . addChild ( this . _rootTimeLine ) ; } } private getText ( input_string ) { return "test getText" ; } /**
     * Render loop
     */ private onEnterFrame ( dt ) { var frameMarker = Math . floor ( 1000 / this . _fps ) ; this . _time += Math . min ( dt , frameMarker ) ; if ( this . _time >= frameMarker ) { this . _time -= frameMarker ; if ( this . _rootTimeLine != undefined ) this . _rootTimeLine . update ( ) ; this . _scene . render ( ) ; } } 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 ; this . _projection . originX = - ( window . innerHeight / this . _stage_height ) * ( this . _stage_width / window . innerWidth ) ; } } window . onload = function ( ) { ( < HTMLElement > document . getElementsByTagName ( "BODY" ) [ 0 ] ) . style . overflow = "hidden" ; new AWD3ViewerMinimal ( ) ; } ;