admin 管理员组

文章数量: 887007

cesium加载模型

加载3dTiles
自己服务器发布的数据

 var palaceTileset = new Cesium.Cesium3DTileset({url: cesiumDomain + "/sample3D/tileset.json",  });viewer.scene.primitives.add(palaceTileset);palaceTileset.readyPromise.then((currentModel) => {viewer.zoomTo(currentModel);});

加载cesium账户上自己发布的数据

     var tileset = new Cesium.Cesium3DTileset({url: Cesium.IonResource.fromAssetId(454231),});viewer.scene.primitives.add(tileset);viewer.zoomTo(tileset);

点击显示经纬度

 var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);handler.setInputAction((event) => {var earthPosition = viewer.camera.pickEllipsoid(event.position,CesiumUtil.CesiumViewer.scene.globe.ellipsoid);if (earthPosition) {var cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(earthPosition);var log_String = Cesium.Math.toDegrees(cartographic.longitude).toFixed(4);var lat_String = Cesium.Math.toDegrees(cartographic.latitude).toFixed(4);console.log(log_String, lat_String);}}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

添加gltf
第一种

     var scene = viewer.scene;let height = 15;var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(118.7751, 32.0675, height)); //gltf数据加载位置var buildingGIFT = scene.primitives.add(Cesium.Model.fromGltf({url: cesiumDomain + "gltf/school1.gltf", //如果为bgltf则为.bgltfmodelMatrix: modelMatrix,scale: 5.0, //放大倍数color: Cesium.Color.LIME,}));//这里坐标值和范围要对,不然加载出来找不到地方viewer.camera.setView({destination: Cesium.Rectangle.fromDegrees(118.7751,32.0675,118.975275,31.943535),orientation: {heading: Cesium.Math.toRadians(45), // east, default value is 0.0 (north)pitch: Cesium.Math.toRadians(-45), // 向下45度roll: 0.0, // default value},});

第二种 以entities的方式加载gltf

  var position = Cesium.Cartesian3.fromDegrees(118.802266, 32.059887, 6.0);var heading = Cesium.Math.toRadians(45);var pitch = 0;var roll = 0;var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);var orientation = Cesium.Transforms.headingPitchRollQuaternion(position,hpr);var model_entity = viewer.entities.add({id: "build",position: position,orientation: orientation,model: {show: true,uri: cesiumDomain + "gltf/Huahailu.gltf",//注意是uri 不是url},});viewer.zoomTo(model_entity);

本文标签: cesium加载模型