首页 > 其他分享 >Cesium模型贴地问题(八)

Cesium模型贴地问题(八)

时间:2023-01-12 17:14:19浏览次数:29  
标签:tileset Cartesian3 模型 param 问题 var Cesium new

2023-01-12

1.sampleTerrainMostDetailed

 

 

 根据提供的terrainPrivider和点的弧度坐标计算出当前点的高度信息。

 

      var p = new Cesium.Cartographic.fromCartesian(new Cesium.Cartesian3.fromDegrees(103.8603, 30.704));
      let promise = Cesium.sampleTerrainMostDetailed(this.viewer.terrainProvider, [p])
      Promise.resolve(promise).then(function(updatedPositions) {
        console.log(`updatedPositions为:${updatedPositions}`);
      });

updatePositions为:(1.8127041971090665, 0.535885893532339, 495.32088938674565)

获得了高度就可以去调整模型的位置了

 

 

2.heightReference属性

      var entity6 = this.viewer.entities.add({
        id:6,
        position:new Cesium.Cartesian3.fromDegrees(103.8603, 30.704,0),
        //设置朝向和翻滚角度
        orientation:orientation,
        model:{
          uri:"../../../static/3DModel/higokumaru__honkai_impact_3rd/scene.gltf",
          show:true,
          scale: 5.0 ,
          silhouetteColor : Cesium.Color.YELLOW,
          silhouetteSize : 0,
          colorBlendMode:Cesium.ColorBlendMode.MIX,
          colorBlendAmount: 0,
          heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
        }
      })

这样的前提是需要地形先加载好,不然的话模型会出现在地心

这种情况就是模型加载好了地形没加载好,找不到椭球就没法计算高度

 

 

 

3.3dtile矩阵变换

 

    var tileset = new Cesium.Cesium3DTileset({ 
      url: "../../../static/3DModel/sicauOSM/tileset.json",
    }); 
    this.viewer.scene.primitives.add(tileset);
    console.log(tileset);

    //3dtile加载完成后执行,进行位置变化
    tileset.readyPromise.then(function(tileset) {
    
    //高度偏差,向上是正数,向下是负数
    var heightOffset = 500.0;

    //计算tileset的绑定范围
    var boundingSphere = tileset.boundingSphere;

    //计算中心点位置
    /**
     * fromCartesian 方法是用经纬度和高度定义一个位置
     * A position defined by longitude, latitude, and height.
     */
    var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
      
    //计算中心点位置的地表坐标
    /**
     * Cartesian3 是一个3D点 笛卡尔坐标
     * Cartesian2 是屏幕坐标
     * cartographic 是椭球坐标
     * fromRadians 方法 Returns a Cartesian3 position from longitude and latitude values given in radians(弧度).
     * @param longitude
     * @param latitude
     * @param height
     * 因为建筑模型没他所在高度信息,所以填0
     */
    var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);

    //偏移后的坐标,也就是中心点本应在的高度(海拔)    
    var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);

    /**
     * subtract 方法 Computes the componentwise difference of two Cartesians.
     * 计算两个笛卡尔坐标的成分差异
     * @param 就是两个要计算的坐标
     * @param 第三个参数是要保存的结果
     */
    var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());

    //tileset.modelMatrix转换
    /**
     * Creates a Matrix4 instance from a Cartesian3 representing the translation.
     * @param {Cartesian3} translation - The upper right portion of the matrix representing the translation.
     * @param {    Matrix4} result - The object in which the result will be stored, if undefined a new instance will be created.
     * Cesium中使用Matrix4作为处理线性变换和位移变换的仿射矩阵
     * 三维空间的转换矩阵通常是3x3的就可以
     * 但是为了同时满足位移的需要增加了一个维度使用4x4的矩阵
     */
    tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);


    /**
     * 定位到3dtiles的位置,也就是让摄像头对准这个区域
     * viewBoundingSphere 方法
     * Sets the camera so that the current view contains the provided bounding sphere.
     * @param boundingSphere - The bounding sphere to view, in world coordinates.
     * @param offset  - The offset from the target in the local east-north-up reference frame centered at the target.
     */
    this.viewer.camera.viewBoundingSphere(tileset.boundingSphere, new Cesium.HeadingPitchRange(0, -20, 0));

    });

cesium中经常用到矩阵变换,基础要打好

标签:tileset,Cartesian3,模型,param,问题,var,Cesium,new
From: https://www.cnblogs.com/LJXXXX/p/17047050.html

相关文章

  • 解决问题 setlocale: LC_ALL: cannot change locale (en_US.UTF-8): No such file or
    解决字符集问题setlocale:LC_ALL:cannotchangelocale(en_US.UTF-8):Nosuchfileordirectory系统已经设置了默认地区_语言.字符集为en_US.UTF-8,但是在系统中没......
  • String.split()字符串分割问题
    stringObj.split([separator,[limit]])separator:可选项。字符串或正则表达式对象,它标识了分隔字符串时使用的是一个还是多个字符。如果忽略该选项,返回包含整个字符串......
  • 疑惑解决(2)—js使用与jQuery的src设置问题
    在单独js文件中引用Jquery之前提到过:使用js的方式  学了jquery  今天实际使用发现一个问题:如果我要使用script标签的方式引入js文件,而我又想在js中使用jQuery简......
  • 裂缝型碳酸盐岩岩石物理模型的构建流程
    (1)利用Voigt-Reuss-Hill或者Hashin-Shtrikman平均计算混合矿物的弹性模量;(2)利用DEM模型将孔隙加进系统,并计算干燥岩石骨架的体积模量和剪切模量;(3)利用Hudson理论和Schoenberg&Sa......
  • 【css】使用弹性盒子布局时,省略号问题
    栗子:<htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=dev......
  • Python金融风控模型案例实战大全
    作者Toby,来自​​Python金融风控模型案例实战大全​​大家好,我是Toby老师,今天介绍《Python金融风控模型案例实战大全》。1.《Python金融风控模型案例实战大全》程覆盖多个核......
  • @ConfigurationProperties使用中遇到的问题
    用Spingboot的小伙伴一定用过@ConfigurationProperties注解。这个注解的作用就是将properties或这yml中配置的参数值根据key注入到配置类(JavaBean)中,然后用@Autowri......
  • LeetCode刷题(76)~三步问题
    题目描述三步问题。有个小孩正在上楼梯,楼梯有n阶台阶,小孩一次可以上1阶、2阶或3阶。实现一种方法,计算小孩有多少种上楼梯的方式。结果可能很大,你需要对结果模1000000007。示......
  • nuget 打包 pre-release 版本需要注意的文件版本问题
    今天在发布EnyimMemcachedCore的一个预览版nuget包时遇到的问题,在这篇博文中记录一下。当时发布的版本是2.6.0-preview1,使用的打包脚本如下version=$1project=Enyi......
  • POI Excel格式报表生成 同步下载问题解决
    前言解决POI导出功能,过时方法和新增样式放在最下面或者参考下文POI样式调节0.maven(新版本)<poi.version>4.1.2</poi.version> <dependency> <groupId>org.ap......