使用反转法线材质球,实现切换天空盒相同的功能,优点:包体变小

切换天空盒

第一步先把SKY 天空球资源导入到工程里,

第二步:天空球文件下的SKY预制件拖入到场景里

第三步 选着SKY材质球,拖入自己的全景图片(图片分辨率不能超过5000*5000,否则手机无法显示)

如果并没有效果,看看图片的设置

还没有效果的话,重新烘焙场景,这样就能正常显示了

javascript 复制代码
const { regClass, property } = Laya;
import MeshRenderer = Laya.MeshRenderer;
import Material = Laya.Material;
@regClass()
export class Script extends Laya.Script {
    //declare owner : Laya.Sprite3D;
    //declare owner : Laya.Sprite;


    public scene3D: Laya.Scene3D;

    @property({ type: Laya.Button })
    public button: Laya.Button;

    switch: boolean = false;
    sky: MeshRenderer;
    public onStart() {
        console.log("Script Start");
        this.scene3D = Laya.stage.getChildAt(0) as Laya.Scene3D

        let sky = this.scene3D.getChildByName("SKY");
        if (sky) {
            this.sky = sky.getChildAt(0).getComponent(MeshRenderer)
        }
        else {
            console.log("没有找到SKY");
        }
        this.button.on(Laya.Event.CLICK, this, () => {
            this.switch = !this.switch;
            this.SwitchSkyBoxMaterial(this.switch ? "resources/1.lmat" : "resources/2.lmat", () => { });
        });
    }

    public SwitchSkyBoxMaterial(skyBoxPath: string, action: () => void) {
        //程序化天空盒
        Laya.loader.load(skyBoxPath).then((mat: Material) => {
            this.sky.material = mat;
            action?.();
        });
    }
}
相关推荐
Zhichao_974 天前
【UE UMG 材质】虚线框
ue5·材质
da_vinci_x9 天前
告别“塑料机甲”:Plasticity的次世代硬表面磨损与自定义贴花工作流
游戏·3d·aigc·材质·技术美术·游戏策划·游戏美术
da_vinci_x10 天前
告别“纸片树冠”:SpeedTree 10的次世代 Nanite 植被透射与程序化季相重构工作流
游戏·3d·重构·aigc·材质·技术美术·游戏策划
恪愚10 天前
three | 材质 Material
前端·javascript·材质
mojugang25 天前
DC53是什么材质
材质·模具钢
yj爆裂鼓手1 个月前
unity编辑器下ab包模式下textMeshPro文本不显示材质是紫色的异常,真机无异常的问题
unity·编辑器·材质
mojugang1 个月前
D2对应国内什么材质
材质·模具钢
ct9781 个月前
ThreeJs材质、模型加载、核心API
webgl·材质·threejs
洲创实业1 个月前
led灯珠材质寿命
材质·led灯珠
CG_MAGIC1 个月前
写实皮肤材质PBR渲染:核心流程与关键参数
3d·材质·贴图·渲云渲染·3d软件