import { Laya } from "Laya" ; import { Animator } from "laya/d3/component/Animator" ; import { AnimatorState } from "laya/d3/component/AnimatorState" ; import { Camera } from "laya/d3/core/Camera" ; import { SpotLight } from "laya/d3/core/light/SpotLight" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Matrix4x4 } from "laya/d3/math/Matrix4x4" ; import { Quaternion } from "laya/d3/math/Quaternion" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { Stage } from "laya/display/Stage" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Laya3D } from "Laya3D" ; import { CameraMoveScript } from "../common/CameraMoveScript" ; author ...
  export class SpotLightDemo { private _quaternion : Quaternion = new Quaternion ( ) ; private _direction : Vector3 = new Vector3 ( ) ; constructor ( ) { Laya3D . init ( 0 , 0 ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; var scene = ( < Scene3D > Laya . stage . addChild ( new Scene3D ( ) ) ) ; var camera = ( < Camera > ( scene . addChild ( new Camera ( 0 , 0.1 , 1000 ) ) ) ) ; camera . transform . translate ( new Vector3 ( 0 , 0.7 , 1.3 ) ) ; camera . transform . rotate ( new Vector3 ( - 15 , 0 , 0 ) , true , false ) ; camera . addComponent ( CameraMoveScript ) ; var spotLight = ( < SpotLight > scene . addChild ( new SpotLight ( ) ) ) ; spotLight . color = new Vector3 ( 1 , 1 , 0 ) ; spotLight . transform . position = new Vector3 ( 0.0 , 1.2 , 0.0 ) ; var mat = spotLight . transform . worldMatrix ; mat . setForward ( new Vector3 ( 0.15 , - 1.0 , 0.0 ) ) ; spotLight . transform . worldMatrix = mat ; spotLight . range = 1.6 ; spotLight . intensity = 8.0 ; spotLight . spotAngle = 32 ; Sprite3D . load ( "res/threeDimen/staticModel/grid/plane.lh" , Handler . create ( this , function ( sprite ) : void { ( < Sprite3D > scene . addChild ( sprite ) ) ; Sprite3D . load ( "res/threeDimen/skinModel/LayaMonkey/LayaMonkey.lh" , Handler . create ( this , function ( layaMonkey ) : void { ( < Sprite3D > scene . addChild ( layaMonkey ) ) ; var aniSprite3d = ( < Sprite3D > layaMonkey . getChildAt ( 0 ) ) ; var animator = ( < Animator > aniSprite3d . getComponent ( Animator ) ) ; var animator = ( < Animator > aniSprite3d . getComponent ( Animator ) ) ; var state = new AnimatorState ( ) ; state . name = "happy" ; state . clipStart = 115 / 150 ; state . clipEnd = 150 / 150 ; state . clip = animator . getDefaultState ( ) . clip ; animator . getControllerLayer ( 0 ) . addState ( state ) ; animator . play ( "happy" ) ; Laya . timer . frameLoop ( 1 , this , function ( ) : void { Quaternion . createFromYawPitchRoll ( 0.025 , 0 , 0 , this . _quaternion ) ; spotLight . transform . worldMatrix . getForward ( this . _direction ) ; Vector3 . transformQuat ( this . _direction , this . _quaternion , this . _direction ) ; var mat = spotLight . transform . worldMatrix ; mat . setForward ( this . _direction ) ; spotLight . transform . worldMatrix = mat ; } ) ; } ) ) ; } ) ) ; } }