import { Laya } from "Laya" ; import { Camera } from "laya/d3/core/Camera" ; import { DirectionLight } from "laya/d3/core/light/DirectionLight" ; import { BlinnPhongMaterial } from "laya/d3/core/material/BlinnPhongMaterial" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { SkinnedMeshSprite3D } from "laya/d3/core/SkinnedMeshSprite3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { Stage } from "laya/display/Stage" ; 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" ; author export class BlinnPhong_SpecularMap { private scene : Scene3D ; private rotation : Vector3 = new Vector3 ( 0 , 0.01 , 0 ) ; private specularMapUrl : any [ ] = [ "res/threeDimen/skinModel/dude/Assets/dude/headS.png" , "res/threeDimen/skinModel/dude/Assets/dude/jacketS.png" , "res/threeDimen/skinModel/dude/Assets/dude/pantsS.png" , "res/threeDimen/skinModel/dude/Assets/dude/upBodyS.png" , "res/threeDimen/skinModel/dude/Assets/dude/upBodyS.png" ] ; 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 , 1000 ) ) ) ) ; camera . transform . translate ( new Vector3 ( 0 , 3 , 5 ) ) ; camera . transform . rotate ( new Vector3 ( - 15 , 0 , 0 ) , true , false ) ; camera . addComponent ( CameraMoveScript ) ; var directionLight = ( < DirectionLight > this . scene . addChild ( new DirectionLight ( ) ) ) ; directionLight . color . setValue ( 1 , 1 , 1 ) ; Laya . loader . create ( "res/threeDimen/skinModel/dude/dude.lh" , Handler . create ( this , this . onComplete ) ) ; } onComplete ( ) { Sprite3D . load ( "res/threeDimen/skinModel/dude/dude.lh" , Handler . create ( this , function ( sprite ) : void { var dude1 = ( < Sprite3D > this . scene . addChild ( sprite ) ) ; dude1 . transform . position = new Vector3 ( - 1.5 , 0 , 0 ) ; var dude2 = Sprite3D . instantiate ( dude1 , this . scene , false , new Vector3 ( 1.5 , 0 , 0 ) ) ; var skinnedMeshSprite3d = ( < SkinnedMeshSprite3D > dude2 . getChildAt ( 0 ) . getChildAt ( 0 ) ) ; for ( var i = 0 ; i < skinnedMeshSprite3d . skinnedMeshRenderer . materials . length ; i ++ ) { var material = ( < BlinnPhongMaterial > skinnedMeshSprite3d . skinnedMeshRenderer . materials [ i ] ) ; Texture2D . load ( this . specularMapUrl [ i ] , Handler . create ( this , function ( mat , tex ) : void { mat . specularTexture = tex ; } , [ material ] ) ) ; } Laya . timer . frameLoop ( 1 , this , function ( ) : void { dude1 . transform . rotate ( this . rotation ) ; dude2 . transform . rotate ( this . rotation ) ; } ) ; } ) ) ; } }