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

切换天空盒

第一步先把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?.();
        });
    }
}
相关推荐
郑寿昌6 天前
虚幻引擎6:Lumen半透明材质新突破
材质
一只数据集6 天前
柏林道路路面图像数据集-971张沥青与鹅卵石路面图片-训练测试集划分-支持道路材质识别与自动驾驶视觉算法训练
算法·自动驾驶·材质
魔士于安6 天前
Unity UI图片 复活节UI,卡通风格
游戏·ui·unity·游戏引擎·材质·贴图
重庆若鱼文化创意7 天前
包装设计公司哪家好?价格差很多时,关键看材质、印刷工艺和实际包装成本
人工智能·python·材质
佛漏米8 天前
上海别墅新古典风格落地指南:从比例控制到材质搭配的工程化方法
材质·别墅装修·装修避坑·装修风格
RReality8 天前
【Unity Shader URP】模板遮罩 / 传送门 实战教程
ui·unity·游戏引擎·图形渲染·材质
郑寿昌10 天前
虚幻引擎UE5 Lumen兼容PBR材质全解析
服务器·网络·材质
郑寿昌10 天前
UE5中FBX材质丢失终极修复指南
ue5·材质
RReality10 天前
【Unity Shader URP】屏幕空间扭曲后处理(Screen Space Distortion)实战教程
ui·unity·游戏引擎·图形渲染·材质
3DVisionary11 天前
混凝土结构力学测试新方案:利用3D DIC技术实现动态裂纹演化三维监测
数码相机·材质·dic技术·新拓三维·混凝土结构·裂纹扩展·材料力学