其他分享
首页 > 其他分享> > Cesium基础知识-创建模型,动画

Cesium基础知识-创建模型,动画

作者:互联网

  1. viewer = new Cesium.Viewer('cesiumContainer'
  2.     /*
  3.     ,{
  4.         shouldAnimate : true
  5.     }*/
  6. );
  7. //创建3d模型
  8. function Create3DModel() {
  9.     //var viewer = new Cesium.Viewer('cesiumContainer');
  10.     var entity = viewer.entities.add({
  11.         position: Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706),
  12.         model: {
  13.             //uri : '../Apps/SampleData/models/GroundVehicle/GroundVehicle.glb'
  14.             uri: '../Apps/SampleData/models/CesiumAir/Cesium_Air.glb'
  15.             //uri : '../Apps/SampleData/models/CesiumMan/Cesium_Man.glb',
  16.         }
  17.     });
  18.     viewer.trackedEntity = entity;
  19. }
  20. //Create3DModel();

  21.  
  22. //创建3d模型设置位置
  23. function Create3DModel2() {
  24.     var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706);
  25.     var heading = Cesium.Math.toRadians(45.0);
  26.     var pitch = Cesium.Math.toRadians(0);
  27.     var roll = Cesium.Math.toRadians(0);
  28.     var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(heading, pitch, roll));
  29.     var entity = viewer.entities.add({
  30.         position: position,
  31.         orientation: orientation,
  32.         model: {
  33.             uri: '../Apps/SampleData/models/GroundVehicle/GroundVehicle.glb'
  34.         }
  35.     });
  36.     viewer.trackedEntity = entity;
  37. }
  38. //Create3DModel2();

  39.  
  40. //创建模型gltf格式,可视化坐标
  41. function CreateModel() {
  42.     var scene = viewer.scene;
  43.     var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
  44.         Cesium.Cartesian3.fromDegrees(-75.62898254394531, 40.02804946899414, 0.0));
  45.     var model = scene.primitives.add(Cesium.Model.fromGltf({
  46.         //url : '../Apps/SampleData/models/GroundVehicle/GroundVehicle.glb',
  47.         url: '../Apps/SampleData/models/CesiumMan/Cesium_Man.glb',
  48.         //url : '../Apps/SampleData/models/CesiumAir/Cesium_Air.glb',
  49.         modelMatrix: modelMatrix,
  50.         scale: 20000.0
  51.     }));
  52.     viewer.extend(Cesium.viewerCesiumInspectorMixin);
  53. }
  54. //CreateModel();

  55.  
  56. //创建模型gltf格式,动画
  57. function CreateModelAni() {
  58.     var scene = viewer.scene;
  59.     var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
  60.         Cesium.Cartesian3.fromDegrees(-75.62898254394531, 40.02804946899414, 0.0));
  61.     var model = scene.primitives.add(Cesium.Model.fromGltf({
  62.         //url : '../Apps/SampleData/models/GroundVehicle/GroundVehicle.glb',
  63.         url: '../Apps/SampleData/models/CesiumMan/Cesium_Man.glb',
  64.         //url : '../Apps/SampleData/models/CesiumAir/Cesium_Air.glb',
  65.         modelMatrix: modelMatrix,
  66.         scale: 200000.0
  67.     }));
  68.     Cesium.when(model.readyPromise).then(function (model) {
  69.         model.activeAnimations.addAll({
  70.             loop: Cesium.ModelAnimationLoop.REPEAT,
  71.             speedup: 0.5,
  72.             reverse: false,
  73.         });
  74.     });
  75.     viewer.extend(Cesium.viewerCesiumInspectorMixin);
  76. //事件,鼠标点击模型,在控制台输出信息
  77.     var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  78.     handler.setInputAction(
  79.         function (movement) {
  80.             var pick = scene.pick(movement.endPosition);
  81.             if (Cesium.defined(pick) && Cesium.defined(pick.node) && Cesium.defined(pick.mesh)) {
  82.                 console.log('node: ' + pick.node.name + '. mesh: ' + pick.mesh.name);
  83.             }
  84.         },
  85.         Cesium.ScreenSpaceEventType.MOUSE_MOVE
  86.     );
  87. }
  88. CreateModelAni();

标签:动画,..,SampleData,glb,Apps,基础知识,var,Cesium
来源: https://blog.csdn.net/QQhelphelp/article/details/122580815