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

切换天空盒

第一步先把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?.();
        });
    }
}
相关推荐
心前阳光1 天前
Unity之运行时标准材质半透明无效果
unity·游戏引擎·材质
星夜泊客2 天前
unity 海底海洋资源OceanEnviromentPackUrp材质丢失修正
unity·游戏引擎·材质
_李小白4 天前
【OSG学习笔记】Day 35: Material(材质)
笔记·学习·材质
康谋自动驾驶6 天前
3DGS 与 OpenMATERIAL:场景表示与材质标准的分层协同
3d·材质·仿真·3dgs·openmaterial
2401_863801468 天前
制作转换3Dtiles时候cesium(b3dm)模型没有阴影,没有材质感,发白显示太假怎么办
3d·arcgis·材质·3dtiles
白狐_79810 天前
基于 Google Opal 的批量产品图改色工作流实践:从参考材质图到 5 张商品图一致化输出
人工智能·材质
mxwin12 天前
Unity Mask 贴图:用一张纹理的 RGBA 通道分别控制 PBR 材质参数
unity·材质·贴图
UTwelve15 天前
【UE】如何正确旋转法线贴图
性能优化·ue5·材质·贴图·着色器
智算菩萨17 天前
【OpenGL】6 真实感光照渲染实战:Phong模型、材质系统与PBR基础
开发语言·python·游戏引擎·游戏程序·pygame·材质·opengl
mxwin21 天前
Unity ShaderLab 完全指南深入了解 Unity 特有的声明式语法,用于定义材质面板、渲染回退、细节层次等核心功能
unity·游戏引擎·材质·shader