import { Laya } from "Laya" ; import { Camera } from "laya/d3/core/Camera" ; import { BlinnPhongMaterial } from "laya/d3/core/material/BlinnPhongMaterial" ; import { PBRStandardMaterial } from "laya/d3/core/material/PBRStandardMaterial" ; import { MeshSprite3D } from "laya/d3/core/MeshSprite3D" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Stage } from "laya/display/Stage" ; import { Event } from "laya/events/Event" ; import { Loader } from "laya/net/Loader" ; import { Texture2D } from "laya/resource/Texture2D" ; import { Button } from "laya/ui/Button" ; import { Browser } from "laya/utils/Browser" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Utils } from "laya/utils/Utils" ; import { Laya3D } from "Laya3D" ; import Client from "../../Client" ; import { CameraMoveScript } from "../common/CameraMoveScript" ; author ...
  export class MaterialDemo { private sphere : MeshSprite3D ; private pbrStandardMaterial : PBRStandardMaterial ; private pbrTexture : Texture2D ; private billinMaterial : BlinnPhongMaterial ; private changeActionButton : Button ; private index : number = 0 ; /**实例类型*/ private btype : any = "MaterialDemo" ; /**场景内按钮类型*/ private stype : any = 0 ; constructor ( ) { Laya3D . init ( 0 , 0 ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Stat . show ( ) ; var resource = [ "res/threeDimen/scene/ChangeMaterialDemo/Conventional/scene.ls" , "res/threeDimen/texture/earth.png" ] ; Laya . loader . create ( resource , Handler . create ( this , this . onPreLoadFinish ) ) ; } onPreLoadFinish ( ) { var scene = ( < Scene3D > Laya . stage . addChild ( Loader . getRes ( "res/threeDimen/scene/ChangeMaterialDemo/Conventional/scene.ls" ) ) ) ; var camera = ( < Camera > scene . getChildByName ( "Main Camera" ) ) ; camera . addComponent ( CameraMoveScript ) ; this . sphere = ( < MeshSprite3D > scene . getChildByName ( "Sphere" ) ) ; this . billinMaterial = ( < BlinnPhongMaterial > this . sphere . meshRenderer . material ) ; this . pbrStandardMaterial = new PBRStandardMaterial ( ) ; this . pbrTexture = ( < Texture2D > Loader . getRes ( "res/threeDimen/texture/earth.png" ) ) ; this . pbrStandardMaterial . albedoTexture = this . pbrTexture ; this . loadUI ( ) ; } private loadUI ( ) { Laya . loader . load ( [ "res/threeDimen/ui/button.png" ] , Handler . create ( this , function ( ) : void { this . changeActionButton = ( < Button > Laya . stage . addChild ( new Button ( "res/threeDimen/ui/button.png" , "切换材质" ) ) ) ; this . changeActionButton . size ( 160 , 40 ) ; this . changeActionButton . labelBold = true ; this . changeActionButton . labelSize = 30 ; this . changeActionButton . sizeGrid = "4,4,4,4" ; this . changeActionButton . scale ( Browser . pixelRatio , Browser . pixelRatio ) ; this . changeActionButton . pos ( Laya . stage . width / 2 - this . changeActionButton . width * Browser . pixelRatio / 2 , Laya . stage . height - 100 * Browser . pixelRatio ) ; this . changeActionButton . on ( Event . CLICK , this , this . stypeFun0 ) ; } ) ) ; } stypeFun0 ( index = 0 ) { this . index ++ ; if ( this . index % 2 === 1 ) { this . sphere . meshRenderer . material = this . pbrStandardMaterial ; } else { this . sphere . meshRenderer . material = this . billinMaterial ; } index = this . index ; Client . instance . send ( { type : "next" , btype : this . btype , stype : 0 , value : index } ) ; } }