import { Laya } from "Laya" ; import { Camera } from "laya/d3/core/Camera" ; import { DirectionLight } from "laya/d3/core/light/DirectionLight" ; import { MeshSprite3D } from "laya/d3/core/MeshSprite3D" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Transform3D } from "laya/d3/core/Transform3D" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { Stage } from "laya/display/Stage" ; import { Loader } from "laya/net/Loader" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Laya3D } from "Laya3D" ; import { CameraMoveScript } from "../common/CameraMoveScript" ; author ...
  export class TransformDemo { private _scene : Scene3D ; private tmpVector : Vector3 = new Vector3 ( 0 , 0 , 0 ) ; private _position : Vector3 = new Vector3 ( 0 , 0 , 0 ) ; private _position1 : Vector3 = new Vector3 ( 0 , 0 , 0 ) ; private _rotate : Vector3 = new Vector3 ( 0 , 1 , 0 ) ; private _rotate1 : Vector3 = new Vector3 ( 0 , 0 , 0 ) ; private _scale : Vector3 = new Vector3 ( ) ; private scaleDelta : number = 0 ; private scaleValue : number = 0 ; private layaMonkey_clone1 : Sprite3D ; private layaMonkey_clone2 : Sprite3D ; private layaMonkey_clone3 : Sprite3D ; private clone1Transform : Transform3D ; private clone2Transform : Transform3D ; private clone3Transform : Transform3D ; 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 ( ) ) ) ; var camera = ( < Camera > ( this . _scene . addChild ( new Camera ( 0 , 0.1 , 100 ) ) ) ) ; camera . transform . translate ( new Vector3 ( 0 , 2.0 , 5 ) ) ; camera . transform . rotate ( new Vector3 ( - 30 , 0 , 0 ) , true , false ) ; camera . addComponent ( CameraMoveScript ) ; var directionLight = ( < DirectionLight > this . _scene . addChild ( new DirectionLight ( ) ) ) ; directionLight . color = new Vector3 ( 1 , 1 , 1 ) ; directionLight . transform . rotate ( new Vector3 ( - 3.14 / 3 , 0 , 0 ) ) ; Laya . loader . create ( [ "res/threeDimen/staticModel/grid/plane.lh" , "res/threeDimen/skinModel/LayaMonkey/LayaMonkey.lh" ] , Handler . create ( this , this . onComplete ) ) ; } private onComplete ( ) { var grid = ( < Sprite3D > this . _scene . addChild ( Loader . getRes ( "res/threeDimen/staticModel/grid/plane.lh" ) ) ) ; var staticLayaMonkey = ( < MeshSprite3D > Loader . getRes ( "res/threeDimen/skinModel/LayaMonkey/LayaMonkey.lh" ) ) ; var staticMonkeyTransform = staticLayaMonkey . transform ; var staticMonkeyScale = staticMonkeyTransform . localScale ; staticMonkeyScale . setValue ( 0.3 , 0.3 , 0.3 ) ; staticMonkeyTransform . localScale = staticMonkeyScale ; this . layaMonkey_clone1 = Sprite3D . instantiate ( staticLayaMonkey , this . _scene , false , this . _position1 ) ; this . layaMonkey_clone2 = Sprite3D . instantiate ( staticLayaMonkey , this . _scene , false , this . _position1 ) ; this . layaMonkey_clone3 = Sprite3D . instantiate ( staticLayaMonkey , this . _scene , false , this . _position1 ) ; this . clone1Transform = this . layaMonkey_clone1 . transform ; this . clone2Transform = this . layaMonkey_clone2 . transform ; this . clone3Transform = this . layaMonkey_clone3 . transform ; this . _position1 . setValue ( 0.0 , 0 , 0.0 ) ; this . clone1Transform . translate ( this . _position1 ) ; this . _position1 . setValue ( - 1.5 , 0 , 0.0 ) ; this . clone2Transform . translate ( this . _position1 ) ; this . _position1 . setValue ( 1.0 , 0 , 0.0 ) ; this . clone3Transform . translate ( this . _position1 ) ; this . _rotate1 . setValue ( 0 , 60 , 0 ) ; this . clone2Transform . rotate ( this . _rotate1 , false , false ) ; var scale = this . clone3Transform . localScale ; scale . setValue ( 0.1 , 0.1 , 0.1 ) ; this . clone3Transform . localScale = scale ; staticLayaMonkey . destroy ( ) ; Laya . timer . frameLoop ( 1 , this , this . animate ) ; } private animate ( ) { this . scaleValue = Math . sin ( this . scaleDelta += 0.1 ) ; this . _position . y = Math . max ( 0 , this . scaleValue / 2 ) ; this . clone1Transform . position = this . _position ; this . clone2Transform . rotate ( this . _rotate , false , false ) ; this . _scale . x = this . _scale . y = this . _scale . z = Math . abs ( this . scaleValue ) / 5 ; this . clone3Transform . localScale = this . _scale ; } }