【3Dtiles】3Dmax模型处理为gltf和3dtiles,包含LOD效果
在閱讀glTF,3d tiles官方文檔后,嘗試使用官方的一些免費工具將3dmax模型處理成gltf和3d tiles模型。
3dmax版本:2018
模型資源:模型? ? ? ? ? ? 提取碼:cuog
一、glTF
在3D Max中安裝3DS Max exporter插件(該插件要求3D max版本為2015以上),可以直接從3dmax中導出glTF/glb。
同時為了之后轉換的3d tiles有LOD效果,在3D Max對模型進行了三角網優化,復制兩個相同模型,分別減少50%的頂點和75%的頂點。
二、3d tiles
gltf/glb轉化為3d tiles模型,需要將其轉換為.b3dm文件格式,再編寫tileset.json文件。
推薦在vs code中安裝glTF Tools直接查看glTF,并且可以驗證glTF有效性。
為了減小.b3dm文件大小,加快前端加載速度,可使用KHR_draco_mesh_compression擴展壓縮幾何數據(坐標、動畫、蒙皮數據等),同時減小貼圖大小,盡量不超過1024X1024。
使用管網工具gltf-pipeline可以給gltf模型添加KHR_draco_mesh_compression擴展,還可以進行gltf/glb互轉
//安裝 npm install -g gltf-pipeline//壓縮glTF幾何數據 gltf-pipeline -i model.gltf -o modelDraco.gltf -d//結合gulp以類庫的方式使用gltf-pipelineconst gltfPipeline = require('gltf-pipeline'); const fsExtra = require('fs-extra'); const processGltf = gltfPipeline.processGltf; const gltf = fsExtra.readJsonSync('model.gltf'); const options = {separateTextures: true,compressionLevel: 7 //壓縮級別 [0-10] }; processGltf(gltf, options).then(function(results) {fsExtra.writeJsonSync('model-separate.gltf', results.gltf);// 保存貼圖,.bin數據文件const separateResources = results.separateResources;for (const relativePath in separateResources) {if (separateResources.hasOwnProperty(relativePath)) {const resource = separateResources[relativePath];fsExtra.writeFileSync(relativePath, resource);}}});glbToB3dm
接下來將三個級別的glTF模型轉換為.b3dm文件。在vs code中將glTF轉換為glb格式。
下載cesium官方的轉換工具的開源代碼
https://github.com/CesiumGS/3d-tiles-validator/tree/master/tools
//下載后安裝依賴npm install在根目錄下,運行以下命令,將glb轉換為.b3dm
node ./bin/3d-tiles-tools.js glbToB3dm -i ./specs/data/CesiumTexturedBox/CesiumTexturedBox.glb -o ./output/CesiumTexturedBox.b3dm三個級別的glb文件依次轉換為.b3dm文件。
最后寫一個簡單的tileset.json文件,在3dmax查看模型的尺寸,用于3d tiles中的包圍盒參數。
tileset.json
tileset.json中參數的意義請查看規范文檔:https://github.com/ComeformPC/3d-tiles/tree/master/specification
{"asset": {"version": "1.0"},"geometricError": 500, //幾何誤差,判斷是否渲染子節點"root": {"transform": [ //使用Cesium.Transforms.eastNorthUpToFixedFrame(origin)設置模型位置0.05602263155122217,0.6403416087687968,0.7660444431189781,0,-0.9961946980917457,0.08715574274765825,0,0,-0.06676517241775076,-0.7631294127377697,0.6427876096865391,0,-426427.5649314479,-4874089.370505605,4077985.572200376,1],"boundingVolume": { //因為gltf是Y軸向上,3d tiles為Z軸向上,cesium會將gltf旋轉90度"box": [0,0,0,30.6, //X軸尺寸一半,X軸不變0,0,0,28.9, //Z軸尺寸一半0,0,0,8.73 //Y軸尺寸一半]},"geometricError": 0.2,"refine": "REPLACE","content": {"uri": "scene-low.b3dm"},"children": [{"boundingVolume": {"box": [0,0,0,30.6,0,0,0,28.9,0,0,0,8.73]},"geometricError": 0.1,"content": {"uri": "scene-medium.b3dm"},"children": [{"boundingVolume": {"box": [0,0,0,30.6,0,0,0,28.9,0,0,0,8.73]},"geometricError": 0,"content": {"uri": "scene-origin.b3dm"}}]}]} }在我的開源項目中有轉換后的3dtiles。有興趣可以看一下。
https://github.com/ComeformPC/cesiumProject/tree/master/public/data/tilesets/architecture
總結
以上是生活随笔為你收集整理的【3Dtiles】3Dmax模型处理为gltf和3dtiles,包含LOD效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html如何设置多级列表,如何在Word
- 下一篇: Qt对word文档操作总结