cesium二次开发-cesium-transformer

634 阅读1分钟

前半部分无关紧要, 可以直接跳到后半部分

因为之前是开发Babylon.js和Three.js的, 所以多少会接触编辑三维实体的业务,但它俩都有相应的工具gizmo和transformer.

在接触了cesium之后, 也遇到了类似需要编辑primitive的场景, 所以就在网上找有没有类似的工具. image.png

然后查到了 Cesium Ion SDK 这个东西, 很惊喜里面是有transformer-editor这个玩意的.

再想了解里面的使用方法时, 发现这个不是开源的... 原本想花钱买来他的license研究研究源码学习学习, 但官方告知, 目前 还 不对中国开放...

image.png

看过邮件的心情就像杰瑞一样~

image.png

然后就想着自己抽空写一个.

cesium-transformer

所以最近写了个npm包, cesium-transformer, 可以在cesium场景中对一些几何做translation, rotation, scale基本变换, 下面先上几组动图.

translation translation.gif

ratation rotation.gif

scale scale.gif

安装

pnpm install cesium-transformer

使用

  • Transformer({viewer, element, boundingSphere})

    • 在cesium场景中对特定元素做基本几何变换

    • Parameters:

      • viewer (Cesium.Viewer): 添加元素的容器.

      • element (Cesium.Model, Cesium.Primitive, Cesium.Cesium3DTileset): 目前支持的目标元素有 model, primitive 和 Cesium3DTileset.

      • boundingSphere (Cesium.BoundingSphere): 元素的包围球, 此为必填项, 需要计算大小坐标的相对位置.

  • 方法

    • changeMode(mode)

      • Parameters:

        • mode (string): 切换转换模式. 'translation', 'rotation', and 'scale'.
      • Example:

         transformer.changeMode('translation');  // 切换到位移模式
         transformer.changeMode('rotation');  // 切换到旋转模式
         transformer.changeMode('scale');   // 切换到缩放模式
        
    • destory

      • 执行后会销毁transformer

      • Example:

         transformer.destory()
        

项目地址: github.com/hujiaxu/ces…

开源不易, 欢迎大家提issuer,点star,后面有更好的开源作品也会分享给大家