import { Laya } from "Laya" ; import { Camera } from "laya/d3/core/Camera" ; import { DirectionLight } from "laya/d3/core/light/DirectionLight" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { Stage } from "laya/display/Stage" ; import { Loader } from "laya/net/Loader" ; import { Image } from "laya/ui/Image" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Laya3D } from "Laya3D" ; import { Vector4 } from "laya/d3/math/Vector4" ; export class Secne3DPlayer2D { private _scene : Scene3D ; private _camera : Camera ; private _layaMonkey2D : Image ; private _position : Vector3 = new Vector3 ( ) ; private _outPos : Vector4 = new Vector4 ( ) ; private _translate : Vector3 = new Vector3 ( 0 , 0.35 , 1 ) ; private _rotation : Vector3 = new Vector3 ( - 3.14 / 3 , 0 , 0 ) ; private scaleDelta : number = 0 ; constructor ( ) { Laya3D . init ( 0 , 0 ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; this . _scene = ( < Scene3D > Laya . stage . addChild ( new Scene3D ( ) ) ) ; this . _camera = ( < Camera > this . _scene . addChild ( new Camera ( 0 , 0.1 , 100 ) ) ) ; this . _camera . transform . translate ( this . _translate ) ; this . _camera . transform . rotate ( this . _rotation , true , false ) ; var directionLight = ( < DirectionLight > this . _scene . addChild ( new DirectionLight ( ) ) ) ; var tmpColor = directionLight . color ; tmpColor . setValue ( 1 , 1 , 1 ) ; directionLight . transform . rotate ( this . _rotation ) ; Laya . loader . create ( "res/threeDimen/staticModel/grid/plane.lh" , Handler . create ( this , this . onComplete ) ) ; } onComplete ( ) { var grid = ( < Sprite3D > this . _scene . addChild ( Loader . getRes ( "res/threeDimen/staticModel/grid/plane.lh" ) ) ) ; this . _layaMonkey2D = ( < Image > Laya . stage . addChild ( new Image ( "res/threeDimen/monkey.png" ) ) ) ; Laya . timer . frameLoop ( 1 , this , this . animate ) ; } private animate ( ) { this . _position . x = Math . sin ( this . scaleDelta += 0.01 ) ; var outPos = this . _outPos ; this . _camera . viewport . project ( this . _position , this . _camera . projectionViewMatrix , outPos ) ; this . _layaMonkey2D . pos ( outPos . x / Laya . stage . clientScaleX , outPos . y / Laya . stage . clientScaleY ) ; } }