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

切换天空盒

第一步先把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?.();
        });
    }
}
相关推荐
melodymint3 天前
第六届材料物理与化学国际研讨会(ICMPC 2026)
科技·材质·物理·国际学术会议·物理化学
丫丫7237343 天前
Three.js 材质系统总结笔记
javascript·笔记·材质
da_vinci_x5 天前
Sampler AI + 滤波算法:解决 AIGC 贴图“噪点过剩”,构建风格化 PBR 工业管线
人工智能·算法·aigc·材质·贴图·技术美术·游戏美术
萘柰奈5 天前
Unity【小问题】----URP项目中加载AssetBundle中的预设体即使加载了依赖的材质依然是紫色的问题
unity·游戏引擎·材质
熊猫悟道6 天前
Unity shader 之,Shader内部时间离散处理
unity·游戏引擎·材质·着色器
da_vinci_x6 天前
Sampler 风格化滤镜:拒绝“写实”,AI 一键生成“塞尔达”风草地
人工智能·游戏·aigc·材质·技术美术·游戏美术·pbr
海伯森技术8 天前
赋予人形机器人“细腻触觉”:海伯森六维力传感器的材质与集成改革
人工智能·机器人·材质
回忆彡美好8 天前
OpenGL的3D编程个人笔记之材质贴图
笔记·3d·材质·opengl
云卓SKYDROID10 天前
无人机光纤遥控技术要点与应用分析
无人机·材质·光纤·高科技·云卓科技
da_vinci_x14 天前
PS 3D Viewer (Beta):概念美术的降维打击,白模直接在PS里转光打影出5张大片
人工智能·游戏·3d·prompt·aigc·材质·游戏美术