three.js 性能优化之模型转化与压缩
模型转换
obj转gltf
安装插件
1 | npm i -g obj2gltf |
1 | 执行转换命令 |
1 | obj2gltf -i 11-6.obj -o 11-6.gltf -u |
模型压缩
安装gltf-pipeline
1 | npm i -g gltf-pipeline |
1 | 执行压缩命令 |
1 | gltf-pipeline -i 11-6.gltf -o 11-6_mini.gltf -d |
加载压缩后的模型
import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader'
import {DRACOLoader} from 'three/examples/jsm/loaders/DRACOLoader'
//加载模型 let loader = new GLTFLoader(); let dracoLoader = new DRACOLoader(); dracoLoader.setDecoderPath("/static/models/draco/");//加载draco算法,这样才能解析压缩后的gltf模型格式,具体的draco算法文件,直接可以three依赖文件中找到,赋值到static目录下面就好了 loader.setDRACOLoader(dracoLoader); loader.load("mini.gltf",//引入压缩的gltf模型 function(obj) { // 这个obj就是解析后的模型,可添加到scene内。 obj.scene.position.set(-27.5, 0, -2);//设置物体的位置 obj.scene.scale.set(0.00065, 0.00065, 0.00065);//设置物体的大小 that.scene.add(obj.scene);// 在场景中添加物体 }, // called while loading is progressing function(xhr) { console.log((xhr.loaded / xhr.total) * 100 + "% loaded"); }, // called when loading has errors function(error) { console.log("An error happened"); } );
本文来自博客园,作者:脆,转载请注明原文链接:https://www.cnblogs.com/Wei-notes/p/17130395.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2022-02-17 WebSocket事件