meshoptimizer

创建日期:2024-10-18
更新日期:2025-01-12

开源项目

使网格更小、渲染更快的网格优化库:zeux/meshoptimizer: Mesh optimization library that makes meshes smaller and faster to render (github.com)

编译方法

1、使用Visual Studio 2022打开项目文件夹。

2、右键CMakeLists.txt,选择meshoptimizer的CMake设置。

3、在设置页面、CMake变量和缓存表格中,设置MESHOPT_BASISU_PATH为basis_universal项目根目录:E:/github/basis_universal

4、在设置页面、CMake变量和缓存表格中,勾选MESHOPT_BUILD_GLTFPACK选项。

5、点击工具类全部保存按钮,保存修改的配置。

6、右键CMakeLists.txt,选择生成。

7、在out\build\x64-Debug文件夹会生成可执行文件:gltfpack.exe

使用方法

Usage: gltfpack [options] -i input -o output

基础参数

-i 文件:待处理的输入文件,.obj/.gltf/.glb

-o 文件:输出文件路径,.gltf/.glb

-c:压缩gltf/glb文件(-cc可以生成高压缩率文件)

纹理参数

-tc:使用BasisU超级压缩把所有纹理转换为KTX2格式

-tu:当编码纹理时使用UASTC (高质量、大尺寸)

-tq N:设置纹理编码质量(默认:8;N 应该在1和10之间)

-ts R:按照比例R缩放纹理尺寸(默认:1;R应该在0和1之间)

-tl N: 限制纹理尺寸到N像素之内(默认:0 =无限制)

-tp:将纹理尺寸调整为最接近的2的幂,以符合WebGL1的限制

-tfy:在BasisU超级压缩过程中沿Y轴翻转纹理

-tj N:在压缩纹理时使用N个线程

-tr:保持引用原始纹理路径,而不是复制/嵌入图像

Texture classes:

-tc C: use ETC1S when encoding textures of class C

-tu C: use UASTC when encoding textures of class C

-tq C N: set texture encoding quality for class C

... where C is a comma-separated list (no spaces) with valid values color,normal,attrib

简化参数

-si R: simplify meshes targeting triangle/point count ratio R (default: 1; R should be between 0 and 1)

-se E: limit simplification error to E (default: 0.01 = 1% deviation; E should be between 0 and 1)

-sa: aggressively simplify to the target ratio disregarding quality

-sv: take vertex attributes into account when simplifying meshes

-slb: lock border vertices during simplification to avoid gaps on connected meshes

顶点精度参数

-vp N: use N-bit quantization for positions (default: 14; N should be between 1 and 16)

-vt N: use N-bit quantization for texture coordinates (default: 12; N should be between 1 and 16)

-vn N: use N-bit quantization for normals (default: 8; N should be between 1 and 16) and tangents (up to 8-bit)

-vc N: use N-bit quantization for colors (default: 8; N should be between 1 and 16)

顶点坐标参数

-vpi: use integer attributes for positions (default)

-vpn: use normalized attributes for positions

-vpf: use floating point attributes for positions

顶点属性参数

-vtf: use floating point attributes for texture coordinates

-vnf: use floating point attributes for normals

-kv: keep source vertex attributes even if they aren't used

动画属性参数

-at N: use N-bit quantization for translations (default: 16; N should be between 1 and 24)

-ar N: use N-bit quantization for rotations (default: 12; N should be between 4 and 16)

-as N: use N-bit quantization for scale (default: 16; N should be between 1 and 24)

-af N: resample animations at N Hz (default: 30)

-ac: keep constant animation tracks even if they don't modify the node transform

场景参数

-kn: keep named nodes and meshes attached to named nodes so that named nodes can be transformed externally

-km: keep named materials and disable named material merging

-ke: keep extras data

-mm: merge instances of the same mesh together when possible

-mi: use EXT_mesh_gpu_instancing when serializing multiple mesh instances

杂项参数

-cf: produce compressed gltf/glb files with fallback for loaders that don't support compression

-noq: disable quantization; produces much larger glTF files with no extensions

-v: verbose output (print version when used without other options)

-r file: output a JSON report to file

-h: display this help and exit

常用命令行

1、查看帮助。

.\gltfpack.exe

2、压缩glb文件。

@echo off
set name=文件名
echo 开始转换...
.\gltfpack.exe -i ./old/%name%.glb -o ./new/%name%.glb -cc -tc -kn -km -mm
echo 转换完成
pause