vue3+vite 添加3DTiles(模型数据),并调整位置,贴地

486 阅读1分钟

tiles.json数据

链接:pan.baidu.com/s/14XEidsB1… 提取码:v4rf

直接上源码


    Cesium.Ion.defaultAccessToken = 'your token'
    // Viewer是一切API的开始
    const esri = new Cesium.ArcGisMapServerImageryProvider({
        url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
        enablePickFeatures: false,
    });
    viewer = new Cesium.Viewer('cesium', {
        imageryProvider: esri,  //加载arcgis地图
        timeline: false,//时间按钮
        animation: false,//动画按钮
        geocoder: false,//搜索按钮
        homeButton: false,//主页按钮
        sceneModePicker: false,//投影按钮
        baseLayerPicker: false,//图层选择按钮 
        navigationHelpButton: false,//帮助手册按钮
        fullscreenButton: false,//全屏按钮
        infoBox: false,//右侧信息框
        selectionIndicator: false,//默认右键选中
    })
        // 使用cesium 3DTileset数据
        // const url = Cesium.IonResource.fromAssetId(75343) 
        const url = 'http://localhost:5173/tileset/tileset.json'
        entity = new Cesium.Cesium3DTileset({
            url: url,
            debugShowBoundingVolume: false,//渲染模型边界
        })
        // 给实体赋位置信息-----start
        entity.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
            Cesium.Cartesian3.fromDegrees(110, 29, 0)
        );
        // 给实体赋位置信息-----start
        // 旋转模型 ---start
        // const m = entity.modelMatrix
        // const m1 = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(30))
        // Cesium.Matrix4.multiplyByMatrix3(m,m1,m)
        // entity.modelMatrix = m
        // 旋转模型 ---end
        // 添加实体到场景中
        viewer.scene.primitives.add(entity)
        viewer.zoomTo(entity);