集成 mapbox-gl 与 threejs 实现在地圖上渲染 3dtiles 、3DGS、gltf 模型等功能。
最初考慮在 threejs 中渲染 3dtiles,以替換 mapbox-gl + deck.gl 的解決方案。 後來發現 threejs 上還可以做更多功能,例如 3DGS 模型、gltf 模型等。
因此,決定將 mapbox-gl 與 threejs 整合,以提供更強大的渲染功能。
更多功能已經實現,但未開源,請期待!
更多示例项目,后续将会在专门的开源库中分享: https://github.com/yangjs6/mapbox-3d-tiles-demos
初始化 mapbox-gl 的 map,在 map 的 load 事件中添加 ThreejsSceneLayer,并进一步添加 tileset 、 3dgs 、gltf、glb 等模型。
map.on('load', function () {
var scene = new ThreejsSceneLayer({
id: 'test-scene',
refCenter: refCenter,
});
map.addLayer(scene);
var tileset = scene.addTileset({
id: 'test-tileset',
url: tiles3DLayerUrl,
});
var tileset_3dgs = scene.addTileset({
id: 'test-tileset',
url: 'http://localhost:8804/splat-3dtiles/NNU_2_opt/tileset.json',
isGaussianSplatting: true, // 默认为 false,如果模型有3DGS效果,请设置为 true
maxGaussianSplatingCount: 4096 * 4096, // 当数据量大时,可调高到 8192 * 8192
});
scene.addModel({
id: 'NNU_2_new',
rootUrl: './data/splats/',
fileNames: 'surveyhouse.splat',
position: [118.9062412507131, 32.10569531706962],
rotation: [-90, 0, 0],
scale: 1,
offset: [0, 0, -30],
});
scene.addModel({
id: 'SM_Tesla',
rootUrl: './data/meshes/',
fileNames: 'SM_Tesla.glb',
position: [118.91083364082562, 32.116922266350315],
rotation: [90, 0, 0],
scale: 1,
offset: [-26.8, -4.2, 1.6],
});
});
杨建顺