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

切换天空盒

第一步先把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?.();
        });
    }
}
相关推荐
哎呦哥哥和巨炮叔叔13 小时前
C4D + Corona 渲染玻璃材质详解:Thin Shell 与实心玻璃的正确使用方式
材质·建筑可视化·渲染技术·c4d·渲染101云渲染·corona渲染·材质系统
深念Y2 天前
乒乓球拍打磨抛光全攻略:告别手指不适与底板拉丝
材质·材料工程·材料·乒乓球·木材·打磨·球拍
freepopo3 天前
天津商业空间设计:材质肌理里的温度与质感[特殊字符]
python·材质
哈小奇5 天前
Unity URP管线Linear空间丝绸材质
unity·游戏引擎·材质
偶信科技11 天前
ADCP钛合金材质如何提升设备的耐用性?偶信科技 3.5kg钛合金ADCP成为新宠儿
人工智能·科技·材质·偶信科技·ocean·海洋仪器·adcp
阿拉丁的梦12 天前
【C4D实用脚本】清除废点及删除了面的选择tag和材质tag及材质--AI编程
服务器·前端·材质
guangzhoubao13 天前
上海高品质吸塑盒定制:医用级/食品级/电子防震包装解决方案
材质
UTwelve21 天前
【UE】材质与半透明 - 01.将半透明作为后期材质
ue5·材质·着色器
军军君0122 天前
Three.js基础功能学习二:场景图与材质
前端·javascript·学习·3d·材质·three·三维
GMATG_LIU23 天前
金属材质化学组成与标准分析技术
材质