• 001使用gltf创建3d模型


    创建viewer,构建cesium可视化展示的主窗口

    var viewer = new Cesium.Viewer('cesiumContainer', {
            infoBox : true,
            selectionIndicator : true,
            shadows : true,
            shouldAnimate : true,
            timeline:true
        });

    其中涉及到的参数含义如下图所示:

    创建模型,并加载到视图中:

    function createModel(url, height) {
            //entities:包含entity的Collection(集合)
            //removeAll():移除entities中的所有entity
            viewer.entities.removeAll();
    
            //静态方法:根据经纬度(度)及高度(米),创建一个position对象
            //返回:Cartesian3
            var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
            //静态方法:度转为弧度
            var heading = Cesium.Math.toRadians(135);
            var pitch = Cesium.Math.toRadians(0);
            var roll = Cesium.Math.toRadians(0);
    
            //创建hpr对象,其中h,p,r均为弧度制
            var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
            //position:局部坐标系的原点
            //由HeadingPitchRoll创建的旋转矩阵Matrix3(或者四元数表示的)是把相机坐标系中的点坐标转换为原坐标系中(不一定是世界坐标系)的坐标。
            //headingPitchRollQuaternion中默认的是Transforms.eastNorthUpToFixedFrame,所以默认是把相机坐标系转为世界坐标系(WGS84)
            //cesium中的旋转矩阵:点或矢量随坐标系一起旋转
            var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
    
            //添加entity到EntityCollection中
            var entity = viewer.entities.add({
                name : '测试glb',
                position : position,
                orientation : orientation,  //用于表示三维空间中的旋转的一组4维坐标。
               /* model : {
                    uri : url,
                    minimumPixelSize : 128,
                    maximumScale : 20000
                }*/
               model:new Cesium.ModelGraphics({
                   uri : url,
                   minimumPixelSize : 1128,
                   maximumScale : 1     //3d模型缩放的最大倍数
               })
            });
    
            //深度检测,为true,不显示被挡住的部分
            viewer.scene.globe.depthTestAgainstTerrain = true;
            //获取或设置摄像头当前正在跟踪的Entity实例
            viewer.trackedEntity = entity;
        }

    最后,附上相关参考链接:

    1:Cesium中的相机—HeadingPitchRoll

    2:Cesium中的相机—四元素

    -------------------------------------------------------------------------------------------------

     

    QQ群:871934478

     

    版权所有,转载请注明源地址                          

     

    -------------------------------------------------------------------------------------------------

     

  • 相关阅读:
    应用图标大小
    AndroidStudio使用笔记
    shell 三剑客之 sed 命令详解
    shell 三剑客之 sed pattern 详解
    shell 文本处理三剑客之 grep 和 egrep
    Shell 编程中的常用工具
    shell 函数的高级用法
    shell 数学运算
    shell 变量的高级用法
    nginx 之 https 证书配置
  • 原文地址:https://www.cnblogs.com/yiliangmi/p/11204400.html
Copyright © 2020-2023  润新知