天天看點

gltf與glb格式轉換 gltf-pipeline、binary-gltf-utils

gltf與glb格式轉換

    • 1. [gltf-pipeline](https://github.com/seminar2012/gltf-pipeline)
    • 2. [binary-gltf-utils](https://github.com/seminar2012/binary-gltf-utils)
    • 3. [obj23dtiles](https://github.com/PrincessGod/objTo3d-tiles)
    • 4. gltf.json與.glb對比
    • 參考

.gltf: Graphics Language Transmission Format(圖形語言傳輸格式),本質是JSON檔案,表示3D内容的場景,可以想象成3D圖檔;是一種3D的标準格式;

.glb: Graphics Lanuage binary,二進制的gltf檔案;

1. gltf-pipeline

缺少啥model,使用npm install model_name

npm install fs-extra
  • -o 輸出檔案名
  • -b 輸出glb,預設同路徑下 name-processed.glt
  • -d draco壓縮,使用預設參數
node gltf-pipeline.js -i D:\learn1\gltf\outputGLTF\9\9.gltf -b
node gltf-pipeline.js -i D:\learn1\gltf\outputGLTF\9\9.gltf -o D:\learn1\gltf\outputGLTF\9\9_d.gltf -d
gltf與glb格式轉換 gltf-pipeline、binary-gltf-utils

2. binary-gltf-utils

3. obj23dtiles

obj2glb

obj2gltf

4. gltf.json與.glb對比

glb實質上是gltf.json+圖檔等資源打包後的二進制檔案;

無圖檔情況glb會減少10%~40%左右;有圖檔情況下glb比gltf.json大至少1倍以上;

gltf轉換glb,實質上是把gltf依賴的圖檔等全打包放進了glb中,是以對于沒有照片的gltf基本會變小,依賴過多照片的其檔案會變大;

使用Windows自帶的 3DViewer渲染可以看的出來,gltf.json+依賴圖檔作為靜态資源在同一個目錄才可渲染,而glb可直接渲染;

glb無論放在哪個目錄單獨要給檔案就可以渲染;

總體來說,gltf轉換glb後,其檔案大小有的變小(紅色),有的變大(藍色)。

gltf與glb格式轉換 gltf-pipeline、binary-gltf-utils

使用Draco壓縮算法回使生成的glb檔案變小一點,尤其對于有頂點資料的gltf;

gltf與glb格式轉換 gltf-pipeline、binary-gltf-utils

參考

  • https://juejin.cn/post/6931954784018628621
  • glTF-glb格式互相轉換