管道基础大数据平台系统开发-【前端】-新系統界面
584911253@qq.com
2023-03-16 ddd0f49e2deb89f45fde892e1ff0953ec0ca2621
三维截取功能修改
已修改2个文件
219 ■■■■ 文件已修改
src/views/Synthesis/LeftMenu.vue 217 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/Tools/LayerTree.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/Synthesis/LeftMenu.vue
@@ -1554,7 +1554,7 @@
          var that = this;
          that.modelClip = !that.modelClip;
          if (that.modelClip) {
            that.$store.state.propertiesFlag = '3';
            // that.$store.state.propertiesFlag = '3';
            if (window.model) {
              that.modelClipping();
            }
@@ -1579,7 +1579,7 @@
            }
          }
          else {
            that.$store.state.propertiesFlag = '';
            // that.$store.state.propertiesFlag = '';
            Viewer.entities.removeAll();
          }
          // window.model = sgworld.Creator.create3DTilesets(
@@ -1757,138 +1757,139 @@
    //模型裁切
    modelClipping() {
      const scene = Viewer.scene;
      let targetY = 0.0;
      let targetY = 40.0;
      let planeEntities = [];
      let selectedPlane;
      // let clippingPlanes = new Cesium.ClippingPlaneCollection({
      //   planes: [ // ClippingPlane对象数组集合
      //     new Cesium.ClippingPlane( // 裁切面
      //       new Cesium.Cartesian3(0.0, 0.0, -1.0), // 法线方向
      //       0// 原点到平面的最短距离,设置0就好
      //     ),
      //   ],
      //   enabled: true,
      //   edgeWidth: 1.0, // 模型被裁切部分的截面线宽
      // });
      let clippingPlanes = new Cesium.ClippingPlaneCollection({
        planes: [ // ClippingPlane对象数组集合
          //前后切割
          new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 1, 0), 0), //后
          new Cesium.ClippingPlane(new Cesium.Cartesian3(0, -1, 0), 0),  //前
          // 左右切割
          new Cesium.ClippingPlane(new Cesium.Cartesian3(1.0, 0.0, 0), 0), //左
          new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0), 0),  //右
          // 上下切割
          new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, -1), 0),  //上→下
          // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, 1), 0),  //下→上、
          new Cesium.ClippingPlane( // 裁切面
            new Cesium.Cartesian3(0.0, 0.0, -1.0), // 法线方向
            0// 原点到平面的最短距离,设置0就好
          ),
        ],
        enabled: true,
        edgeWidth: 1.0, // 模型被裁切部分的截面线宽
        unionClippingRegions: true, //true 才能多个切割
      });
      // let clippingPlanes = new Cesium.ClippingPlaneCollection({
      //   planes: [ // ClippingPlane对象数组集合
      //     //前后切割
      //     new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 1, 0), 0), //后
      //     new Cesium.ClippingPlane(new Cesium.Cartesian3(0, -1, 0), 0),  //前
      //     // 左右切割
      //     new Cesium.ClippingPlane(new Cesium.Cartesian3(1.0, 0.0, 0), 0), //左
      //     new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0), 0),  //右
      //     // 上下切割
      //     new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, -1), 0),  //上→下
      //     // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, 1), 0),  //下→上、
      //   ],
      //   enabled: true,
      //   edgeWidth: 1.0, // 模型被裁切部分的截面线宽
      //   unionClippingRegions: true, //true 才能多个切割
      // });
      let boundingSphere = window.model.boundingSphere;
      // 创建一个坐标轴,便于测试
      var transform = Cesium.Transforms.eastNorthUpToFixedFrame(boundingSphere.center);
      var modelMatrixPrimitive = Viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
        // modelMatrix: transform,
        length: 140.0
      }));
      // var transform = Cesium.Transforms.eastNorthUpToFixedFrame(boundingSphere.center);
      // var modelMatrixPrimitive = Viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
      //   // modelMatrix: transform,
      //   length: 140.0
      // }));
      // // 创建添加裁剪平面
      // for (let i = 0; i < clippingPlanes.length; ++i) {
      //   const plane = clippingPlanes.get(i);
      //   const planeEntity = Viewer.entities.add({
      //     position: boundingSphere.center,
      //     plane: {
      //       dimensions: new Cesium.Cartesian2(
      //         boundingSphere.radius * 1.5,
      //         boundingSphere.radius * 1.5
      //       ),//切面的长和宽
      //       material: Cesium.Color.WHITE.withAlpha(0.1),
      //       plane: new Cesium.CallbackProperty(
      //         // 添加绑定事件,不断调用
      //         createPlaneUpdateFunction(plane),
      //         false
      //       ),
      //       outline: true,
      //       outlineColor: Cesium.Color.WHITE,
      //     },
      //   });
      //   planeEntities.push(planeEntity);
      // }
      // 创建添加裁剪平面
      let m_box;
      for (let i = 0; i < clippingPlanes.length; ++i) {
        let plane = clippingPlanes.get(i);
        let getPlaneType = getType4Plane(plane);
        let planeEntity = Viewer.entities.add({ //添加平面实体 直观裁切面
          id: 'ClipPlane' + i,
          position: boundingSphere.center,// 根据3dtiles同步调整裁切面高度
        const plane = clippingPlanes.get(i);
        const planeEntity = Viewer.entities.add({
          position: boundingSphere.center,
          plane: {
            dimensions: new Cesium.Cartesian2(80, 80),//切面的长和宽
            plane: new Cesium.CallbackProperty(createPlaneUpdateFunction_box(plane, getPlaneType, boundingSphere.center), false),
            material: Cesium.Color.WHITE.withAlpha(0.01),
            outline: false,
            dimensions: new Cesium.Cartesian2(
              boundingSphere.radius * 1.5,
              boundingSphere.radius * 1.5
            ),//切面的长和宽
            material: Cesium.Color.WHITE.withAlpha(0.1),
            plane: new Cesium.CallbackProperty(
              // 添加绑定事件,不断调用
              createPlaneUpdateFunction(plane),
              false
            ),
            outline: true,
            outlineColor: Cesium.Color.WHITE,
          }
          },
        });
        if (!m_box) {
          m_box = Viewer.entities.add({
            id: 'ClopBox',
            modelMatrixPrimitive: modelMatrixPrimitive,
            position: boundingSphere.center,
            box: {
              dimensions: new Cesium.Cartesian3(boundingSphere.radius * 1.2, boundingSphere.radius * 1.2, 40),
              material: Cesium.Color.WHITE.withAlpha(0.3),
            }
          })
        }
        planeEntities.push(planeEntity);
      }
      // 创建添加裁剪平面
      // let m_box;
      // for (let i = 0; i < clippingPlanes.length; ++i) {
      //   let plane = clippingPlanes.get(i);
      //   let getPlaneType = getType4Plane(plane);
      //   let planeEntity = Viewer.entities.add({ //添加平面实体 直观裁切面
      //     id: 'ClipPlane' + i,
      //     position: boundingSphere.center,// 根据3dtiles同步调整裁切面高度
      //     plane: {
      //       dimensions: new Cesium.Cartesian2(80, 80),//切面的长和宽
      //       plane: new Cesium.CallbackProperty(createPlaneUpdateFunction_box(plane, getPlaneType, boundingSphere.center), false),
      //       material: Cesium.Color.WHITE.withAlpha(0.2),
      //       outline: false,
      //       outlineColor: Cesium.Color.WHITE,
      //     }
      //   });
      //   if (!m_box) {
      //     m_box = Viewer.entities.add({
      //       id: 'ClopBox',
      //       modelMatrixPrimitive: modelMatrixPrimitive,
      //       position: boundingSphere.center,
      //       box: {
      //         dimensions: new Cesium.Cartesian3(boundingSphere.radius * 1.2, boundingSphere.radius * 1.2, 40),
      //         material: Cesium.Color.WHITE.withAlpha(0.3),
      //       }
      //     })
      //   }
      // }
      window.model.clippingPlanes = clippingPlanes;
      // 绑定上移动事件
      // const downHandler = new Cesium.ScreenSpaceEventHandler(
      //   Viewer.scene.canvas
      // );
      // downHandler.setInputAction(function (movement) {
      //   const pickedObject = scene.pick(movement.position);
      //   if (
      //     Cesium.defined(pickedObject) &&
      //     Cesium.defined(pickedObject.id.plane)
      //   ) {
      //     selectedPlane = pickedObject.id.plane;
      //     selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05);
      //     selectedPlane.outlineColor = Cesium.Color.WHITE;
      //     scene.screenSpaceCameraController.enableInputs = false;
      //   }
      // }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
      const downHandler = new Cesium.ScreenSpaceEventHandler(
        Viewer.scene.canvas
      );
      downHandler.setInputAction(function (movement) {
        const pickedObject = scene.pick(movement.position);
        if (
          Cesium.defined(pickedObject) &&
          Cesium.defined(pickedObject.id.plane)
        ) {
          selectedPlane = pickedObject.id.plane;
          selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05);
          selectedPlane.outlineColor = Cesium.Color.WHITE;
          scene.screenSpaceCameraController.enableInputs = false;
        }
      }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
      // 绑定下移动事件
      // const upHandler = new Cesium.ScreenSpaceEventHandler(
      //   Viewer.scene.canvas
      // );
      // upHandler.setInputAction(function () {
      //   if (Cesium.defined(selectedPlane)) {
      //     selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1);
      //     selectedPlane.outlineColor = Cesium.Color.WHITE;
      //     selectedPlane = undefined;
      //   }
      //   scene.screenSpaceCameraController.enableInputs = true;
      // }, Cesium.ScreenSpaceEventType.LEFT_UP);
      const upHandler = new Cesium.ScreenSpaceEventHandler(
        Viewer.scene.canvas
      );
      upHandler.setInputAction(function () {
        if (Cesium.defined(selectedPlane)) {
          selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1);
          selectedPlane.outlineColor = Cesium.Color.WHITE;
          selectedPlane = undefined;
        }
        scene.screenSpaceCameraController.enableInputs = true;
      }, Cesium.ScreenSpaceEventType.LEFT_UP);
      // Update plane on mouse move
      // const moveHandler = new Cesium.ScreenSpaceEventHandler(
      //   Viewer.scene.canvas
      // );
      // moveHandler.setInputAction(function (movement) {
      //   if (Cesium.defined(selectedPlane)) {
      //     const deltaY = movement.startPosition.y - movement.endPosition.y;
      //     targetY += deltaY;
      //     console.log("targetY----",targetY)
      //   }
      // }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
      const moveHandler = new Cesium.ScreenSpaceEventHandler(
        Viewer.scene.canvas
      );
      moveHandler.setInputAction(function (movement) {
        if (Cesium.defined(selectedPlane)) {
          const deltaY = movement.startPosition.y - movement.endPosition.y;
          targetY += deltaY;
          // console.log("targetY----",targetY)
        }
      }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
      function createPlaneUpdateFunction(plane) {
        return function () {
          plane.distance = targetY;
          // console.log("targetY----",targetY)
          return plane;
        };
      }
src/views/Tools/LayerTree.vue
@@ -650,7 +650,7 @@
          this.tileSet(tileset, parseFloat(res.elev))
          Viewer.flyTo(tileset);
        });
        // window.model = tileset
        window.model = tileset
      }
    },