SuperMap iClient3D for WebGL模型编辑类介绍(ModelEditor)

kele

前言

在城市规划方案中,向系统添加模型是常用的方法,SuperMap iClient3D for WebGL在线范例中提供了编辑模型参数的方法(范例地址:http://support.supermap.com.cn:8090/webgl/examples/webgl/editor.html#addSymbols),这种方式的交互性不是很好,下面我向大家介绍另一种编辑小品的方式:ModelEditor


一、接口介绍

model:编辑模型对象,支持的模型格式有entity(gltf、glb),S3MInstance(s3m、s3mb)

scene:场景对象

offset:编辑控件偏移量,如果模型原点不在模型中心点,需要合理设置偏移量

scale:编辑控件大小比例

axesShow:{

        rotation:true         //旋转控件

        scale:true           //缩放控件

        translation:true         //平移控件

}

changeEvt:编辑模型时触发返回模型变换矩阵,获取偏移量和旋转量

lineWidthScale:控件线宽

二、使用方法

1.添加模型(entity或者s3mInstance)

    //gltf模型
    var url = "./SampleData/gltf/客机模型/客机模型.gltf";
    var gltf = viewer.entities.add({
      name: "gltf",
      position: new Cesium.Cartesian3.fromDegrees(116.4717575064941,39.92171235599680, 5),
      model: {
        uri: url
      }
    });
    viewer.zoomTo(gltf);
    //s3mInstance添加s3m模型
    var s3mInstanceColc = new Cesium.S3MInstanceCollection(scene._context);
    scene.primitives.add(s3mInstanceColc);
    s3mInstanceColc.add('./data/car/qiche10.s3m', {
      id: 1,
      position: new Cesium.Cartesian3.fromDegrees(116.4717575064941,39.92171235599680, 20),
      hpr: new Cesium.HeadingPitchRoll(0, 0, 0),
      scale: new Cesium.Cartesian3(1, 1, 1),
      color: Cesium.Color.WHITE
    });
    var s3m = s3mInstanceColc.getInstance('./data/car/qiche10.s3m',1);

2.模型编辑类

    var modeeditor = new Cesium.ModelEditor({
      model: s3m,      //或者 gltf
      scene: scene,
      scale: 1,
      offset: new Cesium.Cartesian3(0,0,0),
      lineWidthScale: 3,
      axesShow: {
        rotation: true,
        scale: true,
        translation: true
      },
    });
    modeeditor.activate()

3.添加监听

    var scratchPosition = new Cesium.Cartesian3(0,0,0);
    var scratchPositionMat = new Cesium.Cartesian3(0,0,0);
    var scratchQuaternion = new Cesium.Cartesian3(0,0,0);
    var headingPitchRoll = new Cesium.Cartesian3(0,0,0);

    modeeditor.changedEvt.addEventListener((param)=>{
      var modelMatrix = param.modelMatrix;
      Cesium.Matrix4.getTranslation(modelMatrix,scratchPosition);
      console.log("模型位置:" + scratchPosition.x,scratchPosition.y,scratchPosition.z);
      Cesium.Matrix4.getRotation(modelMatrix,scratchPositionMat);
      Cesium.Quaternion.fromRotationMatrix(scratchPositionMat,scratchQuaternion);
      Cesium.HeadingPitchRoll.fromQuaternion(scratchQuaternion,headingPitchRoll);
      console.log("模型旋转:heading:" + headingPitchRoll.heading + "pitch:" + headingPitchRoll.pitch + "roll:" + headingPitchRoll.roll);
    });

 

4.运行效果

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值