import { Laya } from "Laya" ; import { Animator } from "laya/d3/component/Animator" ; 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 { SkinnedMeshSprite3D } from "laya/d3/core/SkinnedMeshSprite3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Matrix4x4 } from "laya/d3/math/Matrix4x4" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { SkyBox } from "laya/d3/resource/models/SkyBox" ; import { SkyRenderer } from "laya/d3/resource/models/SkyRenderer" ; import { Shader3D } from "laya/d3/shader/Shader3D" ; 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" ; import { PrimitiveMesh } from "laya/d3/resource/models/PrimitiveMesh" ; import { PBRStandardMaterial , PBRMetallicSmoothnessSource } from "laya/d3/core/material/PBRStandardMaterial" ; import { Texture2D } from "laya/resource/Texture2D" ; import { Mesh } from "laya/d3/resource/models/Mesh" ; import { Vector4 } from "laya/d3/math/Vector4" ; export class SceneLoad4 { monkeyRow : number = 10 ; monkeyCount : number = 0 ; modelRow : number = 40 ; _scene : Scene3D ; particles : Array < Sprite3D > ; skinmodels : Array < Sprite3D > ; baseUrl : String = "http://10.10.20.200:8889/" ; constructor ( ) { Laya3D . init ( 0 , 0 ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; var _this = this ; Scene3D . load ( this . baseUrl + "res/threeDimen/scene/TerrainScene/XunLongShi.ls" , Handler . create ( this , function ( scene ) : void { Laya . stage . addChild ( scene ) ; scene . enableFog = false ; scene . fogColor = new Vector3 ( 0 , 0 , 0.6 ) ; scene . fogStart = 10 ; scene . fogRange = 40 ; var camera = new Camera ( ) ; var rotSprite = new Sprite3D ( ) ; rotSprite . addChild ( camera ) ; scene . addChild ( rotSprite ) ; camera . transform . translate ( new Vector3 ( 0 , 18 , - 50 ) ) ; camera . transform . rotate ( new Vector3 ( - 20 , 180 , 0 ) , false , false ) ; camera . aspectRatio = 0 ; camera . nearPlane = 0.1 ; camera . farPlane = 1000 ; camera . clearFlag = BaseCamera . CLEARFLAG_SKY ; camera . fieldOfView = 60 ; camera . addComponent ( CameraMoveScript ) ; var light = ( < DirectionLight > scene . addChild ( new DirectionLight ( ) ) ) ; light . transform . translate ( new Vector3 ( 0 , 2 , 5 ) ) ; var mat = light . transform . worldMatrix ; mat . setForward ( new Vector3 ( 0 , - 5 , 1 ) ) ; light . transform . worldMatrix = mat ; light . color = new Vector3 ( 1.0 , 1.0 , 1.0 ) ; ( ( < MeshSprite3D > scene . getChildByName ( 'Scenes' ) . getChildByName ( 'HeightMap' ) ) ) . active = false ; ( ( < MeshSprite3D > scene . getChildByName ( 'Scenes' ) . getChildByName ( 'Area' ) ) ) . active = false ; _this . _scene = scene ; _this . loadStaticModel ( ) ; _this . loadParticle ( ) ; this . camera1 = rotSprite ; this . lights = light ; Laya . timer . frameLoop ( 1 , this , this . rotateSprite ) ; } ) ) ; } public camera1 : Sprite3D ; public lights : DirectionLight ; rotateSprite ( ) { this . camera1 . transform . rotate ( new Vector3 ( 0 , 1 , 0 ) , false , false ) ; var ve = this . lights . transform . rotationEuler ; ve . setValue ( ve . x + 2 , ve . y + 2 , ve . z + 2 ) ; this . lights . transform . rotationEuler = ve ; } loadParticle ( ) { var _this = this ; this . particles = new Array < Sprite3D > ( ) ; Sprite3D . load ( this . baseUrl + "res/threeDimen/particle/lv_guangci.lh" , Handler . create ( null , function ( lm ) : void { _this . particles . push ( lm ) ; if ( _this . particles . length >= 5 ) { _this . createParticle ( ) ; } } ) ) ; Sprite3D . load ( this . baseUrl + "res/threeDimen/particle/lv_kuosan.lh" , Handler . create ( null , function ( lm ) : void { _this . particles . push ( lm ) ; if ( _this . particles . length >= 5 ) { _this . createParticle ( ) ; } } ) ) ; Sprite3D . load ( this . baseUrl + "res/threeDimen/particle/lv_qiu2.lh" , Handler . create ( null , function ( lm ) : void { _this . particles . push ( lm ) ; if ( _this . particles . length >= 5 ) { _this . createParticle ( ) ; } } ) ) ; Sprite3D . load ( this . baseUrl + "res/threeDimen/particle/lv_sd.lh" , Handler . create ( null , function ( lm ) : void { _this . particles . push ( lm ) ; if ( _this . particles . length >= 5 ) { _this . createParticle ( ) ; } } ) ) ; Sprite3D . load ( this . baseUrl + "res/threeDimen/particle/lv_kuosan1.lh" , Handler . create ( null , function ( lm ) : void { _this . particles . push ( lm ) ; if ( _this . particles . length >= 5 ) { _this . createParticle ( ) ; } } ) ) ; } createParticle ( ) { var nNum = this . monkeyRow * this . monkeyRow ; for ( let i = 0 ; i < nNum ; i ++ ) { var x = parseInt ( ( i / this . monkeyRow ) . toString ( ) ) ; var y = parseInt ( ( i % this . monkeyRow ) . toString ( ) ) ; var sp = Sprite3D . instantiate ( this . particles [ i % 5 ] , this . _scene , false , new Vector3 ( ( - this . monkeyRow / 2 + x ) , 9 , 20 + - y ) ) ; this . _scene . addChild ( sp ) ; } } loadStaticModel ( ) { var _this = this ; this . skinmodels = new Array < Sprite3D > ( ) ; Mesh . load ( "res/threeDimen/pbrtest/PBRAssets02/Sphere.lm" , Handler . create ( this , function ( mesh ) : void { var meshSprite3D = new MeshSprite3D ( mesh ) ; _this . skinmodels . push ( meshSprite3D ) ; var sphereMat = new PBRStandardMaterial ( ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets02/Materials/Textures/Barrel_AlbedoTransparency.png' , Handler . create ( this , function ( texture ) : void { sphereMat . albedoTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets02/Materials/Textures/Barrel_Normal.png' , Handler . create ( this , function ( texture ) : void { sphereMat . normalTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets02/Materials/Textures/Barrel_MetallicSmoothness.png' , Handler . create ( this , function ( texture ) : void { sphereMat . metallicGlossTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets02/Materials/Textures/Barrel_Occlusion.png' , Handler . create ( this , function ( texture ) : void { sphereMat . occlusionTexture = texture ; } ) ) ; sphereMat . albedoColor = new Vector4 ( 1.1 , 1.1 , 1.1 , 1.1 ) ; sphereMat . smoothnessTextureScale = 1.1 ; sphereMat . occlusionTextureStrength = 1.1 ; sphereMat . smoothnessSource = PBRMetallicSmoothnessSource . MetallicGlossTextureAlpha ; meshSprite3D . meshRenderer . sharedMaterial = sphereMat ; if ( _this . skinmodels . length > 3 ) { _this . createSkinmodel ( ) ; } } ) ) ; Mesh . load ( "res/threeDimen/pbrtest/PBRAssets01/Mesh/Wooden_Barrel-Barrel_Low[28772].lm" , Handler . create ( this , function ( mesh ) : void { var meshSprite3D = new MeshSprite3D ( mesh ) ; _this . skinmodels . push ( meshSprite3D ) ; var barrelMat = new PBRStandardMaterial ( ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets01/Materials/Textures/Barrel_AlbedoTransparency.png' , Handler . create ( this , function ( texture ) : void { barrelMat . albedoTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets01/Materials/Textures/Barrel_Normal.png' , Handler . create ( this , function ( texture ) : void { barrelMat . normalTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets01/Materials/Textures/Barrel_MetallicSmoothness.png' , Handler . create ( this , function ( texture ) : void { barrelMat . metallicGlossTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets01/Materials/Textures/Barrel_Occlusion.png' , Handler . create ( this , function ( texture ) : void { barrelMat . occlusionTexture = texture ; } ) ) ; barrelMat . albedoColor = new Vector4 ( 1.2 , 1.2 , 1.2 , 1.2 ) ; barrelMat . smoothnessTextureScale = 1.2 ; barrelMat . occlusionTextureStrength = 1.2 ; barrelMat . smoothnessSource = PBRMetallicSmoothnessSource . MetallicGlossTextureAlpha ; meshSprite3D . meshRenderer . sharedMaterial = barrelMat ; if ( _this . skinmodels . length > 3 ) { _this . createSkinmodel ( ) ; } } ) ) ; Mesh . load ( "res/threeDimen/skinModel/LayaMonkey/Assets/LayaMonkey/LayaMonkey-LayaMonkey.lm" , Handler . create ( this , function ( mesh ) : void { var meshSprite3D = new MeshSprite3D ( mesh ) ; meshSprite3D . transform . scale = new Vector3 ( 0.3 , 0.3 , 0.3 ) ; meshSprite3D . transform . rotate ( new Vector3 ( - 90 , 0 , 0 ) , true , false ) ; _this . skinmodels . push ( meshSprite3D ) ; var layaMonkeyMat = new PBRStandardMaterial ( ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets03/Materials/Textures/Barrel_AlbedoTransparency.png' , Handler . create ( this , function ( texture ) : void { layaMonkeyMat . albedoTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets03/Materials/Textures/Barrel_Normal.png' , Handler . create ( this , function ( texture ) : void { layaMonkeyMat . normalTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets03/Materials/Textures/Barrel_MetallicSmoothness.png' , Handler . create ( this , function ( texture ) : void { layaMonkeyMat . metallicGlossTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets03/Materials/Textures/Barrel_Occlusion.png' , Handler . create ( this , function ( texture ) : void { layaMonkeyMat . occlusionTexture = texture ; } ) ) ; layaMonkeyMat . albedoColor = new Vector4 ( 1.3 , 1.3 , 1.3 , 1.3 ) ; layaMonkeyMat . smoothnessTextureScale = 1.3 ; layaMonkeyMat . occlusionTextureStrength = 1.3 ; layaMonkeyMat . smoothnessSource = PBRMetallicSmoothnessSource . MetallicGlossTextureAlpha ; meshSprite3D . meshRenderer . sharedMaterial = layaMonkeyMat ; if ( _this . skinmodels . length > 3 ) { _this . createSkinmodel ( ) ; } } ) ) ; Mesh . load ( "res/threeDimen/staticModel/teapot/teapot-Teapot001.lm" , Handler . create ( this , function ( mesh ) : void { var meshSprite3D = new MeshSprite3D ( mesh ) ; meshSprite3D . transform . scale = new Vector3 ( 2 , 2 , 2 ) ; _this . skinmodels . push ( meshSprite3D ) ; var teapotMat = new PBRStandardMaterial ( ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets04/Materials/Textures/Barrel_AlbedoTransparency.png' , Handler . create ( this , function ( texture ) : void { teapotMat . albedoTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets04/Materials/Textures/Barrel_Normal.png' , Handler . create ( this , function ( texture ) : void { teapotMat . normalTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets04/Materials/Textures/Barrel_MetallicSmoothness.png' , Handler . create ( this , function ( texture ) : void { teapotMat . metallicGlossTexture = texture ; } ) ) ; Texture2D . load ( 'res/threeDimen/pbrtest/PBRAssets04/Materials/Textures/Barrel_Occlusion.png' , Handler . create ( this , function ( texture ) : void { teapotMat . occlusionTexture = texture ; } ) ) ; teapotMat . albedoColor = new Vector4 ( 1.4 , 1.4 , 1.4 , 1.4 ) ; teapotMat . smoothnessTextureScale = 1.4 ; teapotMat . occlusionTextureStrength = 1.4 ; teapotMat . smoothnessSource = PBRMetallicSmoothnessSource . MetallicGlossTextureAlpha ; meshSprite3D . meshRenderer . sharedMaterial = teapotMat ; if ( _this . skinmodels . length > 3 ) { _this . createSkinmodel ( ) ; } } ) ) ; } createSkinmodel ( ) { var nNum = this . modelRow * this . modelRow ; for ( let i = 0 ; i < nNum ; i ++ ) { var x = parseInt ( ( i / this . modelRow ) . toString ( ) ) ; var y = parseInt ( ( i % this . modelRow ) . toString ( ) ) ; var sp = Sprite3D . instantiate ( this . skinmodels [ i % 4 ] , this . _scene , false , new Vector3 ( ( - this . modelRow / 2 + x ) , 9 , 20 + - y ) ) ; this . _scene . addChild ( sp ) ; } } }