zoukankan      html  css  js  c++  java
  • 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

     

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

     

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

     

  • 相关阅读:
    python 基础2.5 循环中continue与breake用法
    python 基础 2.4 while 循环
    python 基础 2.3 for 循环
    python 基础 2.2 if流程控制(二)
    python 基础 2.1 if 流程控制(一)
    python 基础 1.6 python 帮助信息及数据类型间相互转换
    python 基础 1.5 python数据类型(四)--字典常用方法示例
    Tornado Web 框架
    LinkCode 第k个排列
    LeetCode 46. Permutations
  • 原文地址:https://www.cnblogs.com/yiliangmi/p/11204400.html
Copyright © 2011-2022 走看看