1.将数据和代码放到一个目录下
目的:为避免跨域
输入cmd命令python3 -m http.server 5500
2.三维服务地址
http://127.0.0.1:5500/data/mars3d-max-shihua-3dtiles-master/tileset.json
文章来源:https://www.toymoban.com/news/detail-646822.html
3.模型网页地址
http://127.0.0.1:5500/cesium/cesium%E5%8A%A0%E8%BD%BD3dtile2.html
文章来源地址https://www.toymoban.com/news/detail-646822.html
附录:源代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cesium 3D Tiles Example</title>
<script src="https://cesium.com/downloads/cesiumjs/releases/1.92/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cesium.com/downloads/cesiumjs/releases/1.92/Build/Cesium/Widgets/widgets.css"/>
<script src="http://api.tianditu.gov.cn/cdn/plugins/cesium/cesiumTdt.js" ></script>
</head>
<body>
<div id="cesiumContainer" style="width: 100%; height: 100vh;"></div>
<script>
Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3MzRiZWQyNS1kMzgxLTQzNGItYmFiNS0wZWQ5OGM0OWM3ZTYiLCJpZCI6MTU4MjYyLCJpYXQiOjE2OTEwNTQyMzV9.7d6zouTOikfatIQuU6CpNm41CTGaS0hp_tzo8tQdLPM";
// 初始化Cesium Viewer
var viewer = new Cesium.Viewer('cesiumContainer');
//隐藏cesium的logo
viewer._cesiumWidget._creditContainer.style.display = "none";
// 加载3D Tiles数据
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: 'http://127.0.0.1:5500/data/mars3d-max-shihua-3dtiles-master/tileset.json'
}));
// 当3D Tiles数据加载完成后,定位到数据位置
tileset.readyPromise.then(function() {
// 获取3D Tiles数据的边界
var boundingSphere = tileset.boundingSphere;
// 定位到3D Tiles数据的位置
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0, -0.5, boundingSphere.radius));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});
</script>
</body>
</html>
4.可通过访问https://wkun.cc/查看示例。
到了这里,关于cesium加载三维模型3dtiles的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!