import { Laya } from "Laya" ; import { AnimationClip } from "laya/d3/animation/AnimationClip" ; import { Animator } from "laya/d3/component/Animator" ; import { AnimatorState } from "laya/d3/component/AnimatorState" ; import { BaseCamera } from "laya/d3/core/BaseCamera" ; import { Camera } from "laya/d3/core/Camera" ; import { DirectionLight } from "laya/d3/core/light/DirectionLight" ; import { BaseMaterial } from "laya/d3/core/material/BaseMaterial" ; import { BlinnPhongMaterial } from "laya/d3/core/material/BlinnPhongMaterial" ; import { MeshSprite3D } from "laya/d3/core/MeshSprite3D" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Quaternion } from "laya/d3/math/Quaternion" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { Mesh } from "laya/d3/resource/models/Mesh" ; import { PrimitiveMesh } from "laya/d3/resource/models/PrimitiveMesh" ; import { SkyBox } from "laya/d3/resource/models/SkyBox" ; import { SkyRenderer } from "laya/d3/resource/models/SkyRenderer" ; import { Stage } from "laya/display/Stage" ; import { Loader } from "laya/net/Loader" ; import { Texture2D } from "laya/resource/Texture2D" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Laya3D } from "Laya3D" ; import { CameraMoveScript } from "../common/CameraMoveScript" ; import { Material } from "laya/d3/core/material/Material" ; import { Shader3D } from "laya/d3/shader/Shader3D" ; author ...
  export class LoadResourceDemo { private _scene : Scene3D ; private sprite3D : Sprite3D ; private pangzi : Sprite3D ; private pangziAnimator : Animator ; constructor ( ) { Laya3D . init ( 0 , 0 ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; Shader3D . debugMode = true ; this . LoadRes ( ) ; } LoadRes ( ) { Scene3D . load ( "res/threeDimen/scene/TerrainScene/XunLongShi.ls" , Handler . create ( this , function ( scene ) : void { this . _scene = scene ; Laya . stage . addChild ( scene ) ; var camera = new Camera ( ) ; scene . addChild ( camera ) ; camera . clearFlag = BaseCamera . CLEARFLAG_SKY ; camera . transform . translate ( new Vector3 ( 3 , 20 , 47 ) ) ; camera . addComponent ( CameraMoveScript ) ; var directionLight = ( < DirectionLight > this . _scene . addChild ( new DirectionLight ( ) ) ) ; directionLight . color = new Vector3 ( 1 , 1 , 1 ) ; directionLight . transform . rotate ( new Vector3 ( - 1.14 / 3 , 0 , 0 ) ) ; Material . load ( "res/threeDimen/skyBox/skyBox2/skyBox2.lmat" , Handler . create ( this , function ( mat ) : void { var skyRenderer = camera . skyRenderer ; skyRenderer . mesh = SkyBox . instance ; skyRenderer . material = mat ; } ) ) ; ( ( < MeshSprite3D > scene . getChildByName ( 'Scenes' ) . getChildByName ( 'HeightMap' ) ) ) . active = false ; ( ( < MeshSprite3D > scene . getChildByName ( 'Scenes' ) . getChildByName ( 'Area' ) ) ) . active = false ; this . sprite3D = ( < Sprite3D > this . _scene . addChild ( new Sprite3D ( ) ) ) ; Texture2D . load ( "res/threeDimen/texture/earth.png" , Handler . create ( this , function ( tex ) : void { var earth1 = ( < MeshSprite3D > scene . addChild ( new MeshSprite3D ( PrimitiveMesh . createSphere ( 5 , 32 , 32 ) ) ) ) ; earth1 . transform . translate ( new Vector3 ( 17 , 20 , 0 ) ) ; var earthMat = new BlinnPhongMaterial ( ) ; earthMat . albedoTexture = tex ; earthMat . albedoIntensity = 1 ; earth1 . meshRenderer . material = earthMat ; } ) ) ; Mesh . load ( "res/threeDimen/skinModel/LayaMonkey/Assets/LayaMonkey/LayaMonkey-LayaMonkey.lm" , Handler . create ( this , function ( mesh ) : void { var layaMonkey = ( < MeshSprite3D > this . sprite3D . addChild ( new MeshSprite3D ( mesh ) ) ) ; var layaMonkeyTrans = layaMonkey . transform ; var layaMonkeyScale = layaMonkeyTrans . localScale ; layaMonkeyScale . setValue ( 4 , 4 , 4 ) ; layaMonkeyTrans . localScale = layaMonkeyScale ; layaMonkey . transform . rotation = new Quaternion ( 0.7071068 , 0 , 0 , - 0.7071067 ) ; layaMonkey . transform . translate ( new Vector3 ( 5 , 3 , 13 ) ) ; } ) ) ; Sprite3D . load ( "res/threeDimen/skinModel/LayaMonkey/LayaMonkey.lh" , Handler . create ( this , function ( sp ) : void { var layaMonkey2 = ( < Sprite3D > scene . addChild ( sp ) ) ; var layaMonkey2Trans = layaMonkey2 . transform ; var layaMonkey2Scale = layaMonkey2Trans . localScale ; layaMonkey2Scale . setValue ( 4 , 4 , 4 ) ; layaMonkey2Trans . localScale = layaMonkey2Scale ; layaMonkey2Trans . translate ( new Vector3 ( - 10 , 13 , 0 ) ) ; } ) ) ; Sprite3D . load ( "res/threeDimen/skinModel/BoneLinkScene/PangZiNoAni.lh" , Handler . create ( this , function ( sp ) : void { this . pangzi = ( < Sprite3D > scene . addChild ( sp ) ) ; var pangziTrans = this . pangzi . transform ; var pangziScale = pangziTrans . localScale ; pangziScale . setValue ( 4 , 4 , 4 ) ; pangziTrans . localScale = pangziScale ; pangziTrans . translate ( new Vector3 ( - 20 , 13 , 0 ) ) ; this . pangziAnimator = ( < Animator > this . pangzi . getChildAt ( 0 ) . getComponent ( Animator ) ) ; AnimationClip . load ( "res/threeDimen/skinModel/BoneLinkScene/Assets/Model3D/PangZi-Take 001.lani" , Handler . create ( this , function ( aniClip ) : void { var state1 = new AnimatorState ( ) ; state1 . name = "hello" ; state1 . clipStart = 0 / 581 ; state1 . clipEnd = 581 / 581 ; state1 . clip = aniClip ; state1 . clip . islooping = true ; this . pangziAnimator . getControllerLayer ( 0 ) . addState ( state1 ) ; this . pangziAnimator . play ( "hello" ) ; } ) ) ; } ) ) ; } ) ) ; } PreloadingRes ( ) { var resource = [ "res/threeDimen/scene/TerrainScene/XunLongShi.ls" , "res/threeDimen/skyBox/skyBox2/skyBox2.lmat" , "res/threeDimen/texture/earth.png" , "res/threeDimen/skinModel/LayaMonkey/Assets/LayaMonkey/LayaMonkey-LayaMonkey.lm" , "res/threeDimen/skinModel/LayaMonkey/LayaMonkey.lh" , "res/threeDimen/skinModel/BoneLinkScene/PangZiNoAni.lh" , "res/threeDimen/skinModel/BoneLinkScene/Assets/Model3D/PangZi-Take 001.lani" ] ; Laya . loader . create ( resource , Handler . create ( this , this . onPreLoadFinish ) ) ; } onPreLoadFinish ( ) { this . _scene = ( < Scene3D > Laya . stage . addChild ( Loader . getRes ( "res/threeDimen/scene/TerrainScene/XunLongShi.ls" ) ) ) ; var camera = new Camera ( ) ; this . _scene . addChild ( camera ) ; camera . clearFlag = BaseCamera . CLEARFLAG_SKY ; camera . transform . translate ( new Vector3 ( 4 , 20 , 47 ) ) ; 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 ) ) ; var skyboxMaterial = < Material > Loader . getRes ( "res/threeDimen/skyBox/skyBox2/skyBox2.lmat" ) ; var skyRenderer = camera . skyRenderer ; skyRenderer . mesh = SkyBox . instance ; skyRenderer . material = skyboxMaterial ; ( ( < MeshSprite3D > this . _scene . getChildByName ( 'Scenes' ) . getChildByName ( 'HeightMap' ) ) ) . active = false ; ( ( < MeshSprite3D > this . _scene . getChildByName ( 'Scenes' ) . getChildByName ( 'Area' ) ) ) . active = false ; var earth1 = ( < MeshSprite3D > this . _scene . addChild ( new MeshSprite3D ( PrimitiveMesh . createSphere ( 5 , 32 , 32 ) ) ) ) ; earth1 . transform . translate ( new Vector3 ( 17 , 20 , 0 ) ) ; var earthMat = new BlinnPhongMaterial ( ) ; earthMat . albedoTexture = ( < Texture2D > Loader . getRes ( "res/threeDimen/texture/earth.png" ) ) ; earthMat . albedoIntensity = 1 ; earth1 . meshRenderer . material = earthMat ; var mesh = ( < Mesh > Loader . getRes ( "res/threeDimen/skinModel/LayaMonkey/Assets/LayaMonkey/LayaMonkey-LayaMonkey.lm" ) ) ; var layaMonkey = ( < MeshSprite3D > this . _scene . addChild ( new MeshSprite3D ( mesh ) ) ) ; var layaMonkeyTrans = layaMonkey . transform ; var layaMonkeyScale = layaMonkeyTrans . localScale ; layaMonkeyScale . setValue ( 4 , 4 , 4 ) ; layaMonkeyTrans . localScale = layaMonkeyScale ; layaMonkeyTrans . rotation = new Quaternion ( 0.7071068 , 0 , 0 , - 0.7071067 ) ; layaMonkeyTrans . translate ( new Vector3 ( 5 , 3 , 13 ) ) ; var sp = ( < Sprite3D > Loader . getRes ( "res/threeDimen/skinModel/LayaMonkey/LayaMonkey.lh" ) ) ; var layaMonkey2 = ( < Sprite3D > this . _scene . addChild ( sp ) ) ; var layaMonkey2Trans = layaMonkey2 . transform ; var layaMonkey2Scale = layaMonkey2Trans . localScale ; layaMonkey2Scale . setValue ( 4 , 4 , 4 ) ; layaMonkey2Trans . localScale = layaMonkey2Scale ; layaMonkey2Trans . translate ( new Vector3 ( - 10 , 13 , 0 ) ) ; this . pangzi = ( < Sprite3D > Loader . getRes ( "res/threeDimen/skinModel/BoneLinkScene/PangZiNoAni.lh" ) ) ; this . pangzi = ( < Sprite3D > this . _scene . addChild ( this . pangzi ) ) ; var pangziTrans = this . pangzi . transform ; var pangziScale = pangziTrans . localScale ; pangziScale . setValue ( 4 , 4 , 4 ) ; pangziTrans . localScale = pangziScale ; pangziTrans . translate ( new Vector3 ( - 20 , 13 , 0 ) ) ; this . pangziAnimator = ( < Animator > this . pangzi . getChildAt ( 0 ) . getComponent ( Animator ) ) ; var pangAni = ( < AnimationClip > Loader . getRes ( "res/threeDimen/skinModel/BoneLinkScene/Assets/Model3D/PangZi-Take 001.lani" ) ) ; var state1 = new AnimatorState ( ) ; state1 . name = "hello" ; state1 . clipStart = 0 / 581 ; state1 . clipEnd = 581 / 581 ; state1 . clip = pangAni ; state1 . clip . islooping = true ; this . pangziAnimator . getControllerLayer ( 0 ) . addState ( state1 ) ; this . pangziAnimator . play ( "hello" ) ; } }