cesium加载三维模型3dtiles

1.将数据和代码放到一个目录下

目的:为避免跨域

输入cmd命令
python3 -m http.server 5500

2.三维服务地址

http://127.0.0.1:5500/data/mars3d-max-shihua-3dtiles-master/tileset.json

3.模型网页地址

http://127.0.0.1:5500/cesium/cesium%E5%8A%A0%E8%BD%BD3dtile2.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 Exampletitle>
    <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,3d,javascript,cesium)