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 { Material } from "laya/d3/core/material/Material" ; import { MeshSprite3D } from "laya/d3/core/MeshSprite3D" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Sprite3D } from "laya/d3/core/Sprite3D" ; import { Matrix4x4 } from "laya/d3/math/Matrix4x4" ; import { Vector3 } from "laya/d3/math/Vector3" ; import { Vector4 } from "laya/d3/math/Vector4" ; import { PrimitiveMesh } from "laya/d3/resource/models/PrimitiveMesh" ; 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" ; import { FilterMode } from "laya/resource/FilterMode" ; import { WarpMode } from "laya/resource/WrapMode" ; author ...
  export class TextureDemo { private sprite3D : Sprite3D ; 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 , 100 ) ) ) ; camera . transform . translate ( new Vector3 ( 0 , 2 , 5 ) ) ; camera . transform . rotate ( new Vector3 ( - 15 , 0 , 0 ) , true , false ) ; camera . addComponent ( CameraMoveScript ) ; camera . clearColor = new Vector4 ( 0.2 , 0.2 , 0.2 , 1.0 ) ; var directionLight = ( < DirectionLight > scene . addChild ( new DirectionLight ( ) ) ) ; var mat = directionLight . transform . worldMatrix ; mat . setForward ( new Vector3 ( - 1.0 , - 1.0 , - 1.0 ) ) ; directionLight . transform . worldMatrix = mat ; this . sprite3D = ( < Sprite3D > scene . addChild ( new Sprite3D ( ) ) ) ; var box = ( < MeshSprite3D > this . sprite3D . addChild ( new MeshSprite3D ( PrimitiveMesh . createBox ( 0.5 , 0.5 , 0.5 ) ) ) ) ; box . transform . position = new Vector3 ( 0.0 , 1.0 , 2.5 ) ; box . transform . rotate ( new Vector3 ( 0 , 0 , 0 ) , false , false ) ; var mat1 = new BlinnPhongMaterial ( ) ; Texture2D . load ( "res/threeDimen/texture/layabox.png" , Handler . create ( this , function ( texture ) : void { texture . wrapModeU = WarpMode . Repeat ; texture . wrapModeV = WarpMode . Repeat ; texture . filterMode = FilterMode . Bilinear ; texture . anisoLevel = 2 ; mat1 . albedoTexture = texture ; var tilingOffset = mat1 . tilingOffset ; tilingOffset . setValue ( 3 , 3 , 0.0 , 0.0 ) ; mat1 . tilingOffset = tilingOffset ; box . meshRenderer . material = mat1 as Material ; } ) ) ; } }