浏览代码

制作新功能

bill 9 月之前
父节点
当前提交
22dd350fa8

+ 14 - 3
src/app/liantong/index.ts

@@ -146,16 +146,27 @@ export const createBoard = (
       centerR = center;
       rotationZ = -angle;
       center = new Vector3(-center.x, center.y, -center.z);
+      const id = "Point181";
       setMat
         .identity()
         .multiply(new Matrix3().makeTranslation(-center.x, -center.z))
         .multiply(new Matrix3().makeRotation(rotationZ))
         .multiply(new Matrix3().makeTranslation(center.x, center.z));
-
-      return board.setData(rotateData(data, setMat));
+      console.log(data.rooms[0].points.find((p) => p.id === id));
+      data = rotateData(data, setMat);
+      console.log(data.rooms[0].points.find((p) => p.id === id));
+      return board.setData(data);
     },
     getData() {
-      return rotateData(board.getData(), setMat.clone().invert());
+      let data = board.getData();
+      const id = "Point181";
+      console.log(data.rooms[0].points.find((p) => p.id === id));
+      data = rotateData(data, setMat.clone().invert());
+      console.log(data.rooms[0].points.find((p) => p.id === id));
+
+      console.log("???", data);
+      // throw "1";
+      return data;
     },
     blurPoi() {
       if (activePoi) {

+ 17 - 17
src/board/packages/whole-line/editable/edit-whole-line.ts

@@ -14,7 +14,7 @@ import {
   getWholeLinePolygonLinesByPoint,
   getWholeLinePolygonPoints,
   getWholeLinePolygonRaw,
-  mergeWholeLinePointsByPoint,
+  // mergeWholeLinePointsByPoint,
   penWholeLinePoygonsEditWithHelperShapesMouse,
   repeatMoveWholeLineLine,
   spliceWholeLineLineByPoint,
@@ -156,23 +156,23 @@ export class EditWholeLine<
     return this.editPolygon();
   }
 
-  pointAfterHandler(pointAttrib: WholeLinePointAttrib) {
+  pointAfterHandler() {
     this.container.constant.use();
-    const merge = mergeWholeLinePointsByPoint(this.attrib, pointAttrib.id);
-    spliceWholeLineLineByPoint(
-      this.attrib,
-      merge?.info.main.id || pointAttrib.id
-    );
-    fixWholeLineConfig(this.attrib);
+    // const merge = mergeWholeLinePointsByPoint(this.attrib, pointAttrib.id);
+    // spliceWholeLineLineByPoint(
+    //   this.attrib,
+    //   merge?.info.main.id || pointAttrib.id
+    // );
+    // fixWholeLineConfig(this.attrib);
     this.container.constant.unuse();
   }
 
-  lineAfterHandler(lineAttrib: WholeLineLineAttrib) {
+  lineAfterHandler() {
     this.container.constant.use();
-    for (let i = 0; i < lineAttrib.pointIds.length; i++) {
-      spliceWholeLineLineByPoint(this.attrib, lineAttrib.pointIds[i]);
-    }
-    fixWholeLineConfig(this.attrib);
+    // for (let i = 0; i < lineAttrib.pointIds.length; i++) {
+    //   spliceWholeLineLineByPoint(this.attrib, lineAttrib.pointIds[i]);
+    // }
+    // fixWholeLineConfig(this.attrib);
     this.container.constant.unuse();
   }
 
@@ -204,8 +204,8 @@ export class EditWholeLine<
       moveHandler: (_, move, moveHandler) => {
         moveHandler(move);
       },
-      endHandler: (attrib) => {
-        this.lineAfterHandler(attrib);
+      endHandler: () => {
+        this.lineAfterHandler();
         this.container.bus.emit("dataChangeAfter");
       },
     };
@@ -251,10 +251,10 @@ export class EditWholeLine<
         pointAttrib.x = position[0];
         pointAttrib.y = position[1];
       },
-      endHandler: (attrib) => {
+      endHandler: () => {
         console.log("end");
         this.container.constant.unuse();
-        this.pointAfterHandler(attrib);
+        this.pointAfterHandler();
         this.container.bus.emit("dataChangeAfter");
       },
     };

+ 3 - 0
src/board/packages/whole-line/helper/whole-line-line-helper.ts

@@ -112,6 +112,9 @@ export class WholeLineLineHelper extends Entity<WholeLineLineAttrib, Group> {
         }
       }
     }
+    if (!labels.length) {
+      labels.push(`${this.attrib.id} ${this.attrib.pointIds.join(",")}`);
+    }
 
     const coords: number[] = [];
     points.forEach(({ x, y }, ndx) => {

+ 217 - 217
src/board/packages/whole-line/service/whole-line-tear-merge.ts

@@ -1,14 +1,14 @@
-import { MathUtils, Vector2 } from "three";
+// import { MathUtils, Vector2 } from "three";
 import { DEV } from "../../../env";
 import {
   getLineIntersection,
   getLineDist,
   getLineNearPointDist,
-  getDire2Angle,
-  getLineDire,
-  getVerticalDire,
-  createLineByDire,
-  getLineProjection,
+  // getDire2Angle,
+  // getLineDire,
+  // getVerticalDire,
+  // createLineByDire,
+  // getLineProjection,
   RelationshipEnum,
   round,
 } from "../../../shared/math";
@@ -20,17 +20,17 @@ import {
 import { currentConstant } from "../../view-constant";
 import {
   generateWholeLineLineId,
-  generateWholeLinePointId,
+  // generateWholeLinePointId,
   generateWholeLinePoygonId,
   getWholeLineLineRaw,
-  getWholeLineLinesRawByPointId,
+  // getWholeLineLinesRawByPointId,
   getWholeLinePoint,
   getWholeLinePoints,
   getWholeLinePolygonLines,
   getWholeLinePolygonLinesByPoint,
   wholeLineDelLineByPointIds,
   wholeLineLineAddPoint,
-  wholeLineLineIsolatePoint,
+  // wholeLineLineIsolatePoint,
   wholeLineReplacePoint,
 } from "./whole-line-base";
 import { wholeLineAddPoint } from "./whole-line-mouse";
@@ -464,169 +464,169 @@ export const mergeWholeLinePointsByPoint = (
 export const repeatMoveWholeLineLine = (
   config: WholeLineAttrib,
   lineAttrib: WholeLineLineAttrib,
-  initPosition: number[][],
-  angleRang = [10, 170]
+  initPosition: number[][]
+  // angleRang = [10, 170]
 ) => {
-  const cache: {
-    [key in string]: {
-      id: string;
-      split: boolean;
-      refDire: number[];
-      lineDire: number[];
-      isFirst: boolean;
-    };
-  } = {};
-  const linePointIds = lineAttrib.pointIds;
-  const line0 = getWholeLinePoints(config, [linePointIds[0], linePointIds[1]]);
-  const lineDire0 = getLineDire([
-    line0[0].x,
-    line0[0].y,
-    line0[1].x,
-    line0[1].y,
-  ]);
-  const line1 = getWholeLinePoints(config, [linePointIds[1], linePointIds[0]]);
-  const lineDire1 = getLineDire([
-    line1[0].x,
-    line1[0].y,
-    line1[1].x,
-    line1[1].y,
-  ]);
-
-  const getPointRefInfo = (moveDire: number[], ndx: number) => {
-    let isFirst = true;
-    const curPointId = linePointIds[ndx];
-    if (!cache[curPointId]) {
-      cache[curPointId] = {} as any;
-    } else {
-      isFirst = false;
-      // if (cache[curPointId].split) {
-      return { ...cache[curPointId], isFirst };
-      // }
-    }
-
-    const joinLines = getWholeLineLinesRawByPointId(config, curPointId).filter(
-      (line) =>
-        !(
-          line.pointIds.includes(linePointIds[0]) &&
-          line.pointIds.includes(linePointIds[1])
-        )
-    );
-    const joinLineDires: number[][] = [];
-    const lineDire = ndx === 0 ? lineDire0 : lineDire1;
-
-    let invAngle = Number.MAX_VALUE;
-    let invSelectLineId: string;
-    let invSelectLineDire: number[] | null = null;
-
-    let alongAngle = -Number.MAX_VALUE;
-    let alongSelectLineId: string;
-    let alongSelectLineDire: number[] | null = null;
-
-    for (let { pointIds: joinPointIds, id } of joinLines) {
-      joinPointIds = [
-        linePointIds[ndx],
-        ...joinPointIds.filter((id) => id !== linePointIds[ndx]),
-      ];
-      const joinLine = getWholeLinePoints(config, joinPointIds);
-      const joinLineDire = getLineDire([
-        joinLine[0].x,
-        joinLine[0].y,
-        joinLine[1].x,
-        joinLine[1].y,
-      ]);
-      joinLineDires.push(joinLineDire);
-      // if (["10", "14"].includes(id)) {
-      //   continue;
-      // }
-
-      const currentAngle = getDire2Angle(lineDire, joinLineDire);
-      // 逆时针
-      if (currentAngle > 0) {
-        if (currentAngle < invAngle) {
-          invAngle = currentAngle;
-          invSelectLineId = id;
-          invSelectLineDire = joinLineDire;
-        }
-      } else {
-        if (currentAngle > alongAngle) {
-          alongAngle = currentAngle;
-          alongSelectLineId = id;
-          alongSelectLineDire = joinLineDire;
-        }
-      }
-    }
-
-    let pointJointLineDire: number[] | null = null;
-    let angle: number | null = null;
-    let selectLineId: string | null = null;
-
-    if (!invSelectLineDire || !alongSelectLineDire) {
-      pointJointLineDire = invSelectLineDire || alongSelectLineDire;
-      selectLineId = invSelectLineDire ? invSelectLineId : alongSelectLineId;
-      angle = invSelectLineDire ? invAngle : alongAngle;
-    } else if (
-      Math.abs(getDire2Angle(moveDire, invSelectLineDire)) <
-      Math.abs(getDire2Angle(moveDire, alongSelectLineDire))
-    ) {
-      pointJointLineDire = invSelectLineDire;
-      selectLineId = invSelectLineId;
-      angle = invAngle;
-    } else {
-      pointJointLineDire = alongSelectLineDire;
-      selectLineId = alongSelectLineId;
-      angle = alongAngle;
-    }
-
-    let isSplitPoint = false;
-    // 需要判定,如果参考线与当前线段夹角超过多少则不适合作为参考线
-    let refLineAngle = Math.abs(MathUtils.radToDeg(angle));
-    if (
-      (pointJointLineDire !== null && refLineAngle > angleRang[1]) ||
-      refLineAngle < angleRang[0]
-    ) {
-      console.log(
-        "夹角不在范围,分割",
-        selectLineId,
-        ndx === 0 ? line0 : line1,
-        refLineAngle
-      );
-      selectLineId = null;
-      pointJointLineDire = getVerticalDire(pointJointLineDire);
-      isSplitPoint = true;
-
-      // 如果有多条线段,判断是否方向一致,不一致则要分割
-    } else if (joinLines.length > 1) {
-      const temp = pointJointLineDire;
-      for (let i = 0; i < joinLines.length; i++) {
-        if (temp === joinLineDires[i]) {
-          continue;
-        }
-        const angle =
-          (getDire2Angle(temp, joinLineDires[i]) + Math.PI) % Math.PI;
-
-        if (round(angle, 3) > 0) {
-          console.log("方向不同,分割");
-          isSplitPoint = true;
-          break;
-        }
-      }
-    }
-
-    cache[curPointId].refDire = pointJointLineDire;
-    cache[curPointId].lineDire = lineDire;
-    cache[curPointId].id = selectLineId;
-    cache[curPointId].split = isSplitPoint;
-    cache[curPointId].isFirst = isFirst;
-
-    return cache[curPointId];
-  };
+  // const cache: {
+  //   [key in string]: {
+  //     id: string;
+  //     split: boolean;
+  //     refDire: number[];
+  //     lineDire: number[];
+  //     isFirst: boolean;
+  //   };
+  // } = {};
+  // const linePointIds = lineAttrib.pointIds;
+  // const line0 = getWholeLinePoints(config, [linePointIds[0], linePointIds[1]]);
+  // const lineDire0 = getLineDire([
+  //   line0[0].x,
+  //   line0[0].y,
+  //   line0[1].x,
+  //   line0[1].y,
+  // ]);
+  // const line1 = getWholeLinePoints(config, [linePointIds[1], linePointIds[0]]);
+  // const lineDire1 = getLineDire([
+  //   line1[0].x,
+  //   line1[0].y,
+  //   line1[1].x,
+  //   line1[1].y,
+  // ]);
+
+  // const getPointRefInfo = (moveDire: number[], ndx: number) => {
+  //   let isFirst = true;
+  //   const curPointId = linePointIds[ndx];
+  //   if (!cache[curPointId]) {
+  //     cache[curPointId] = {} as any;
+  //   } else {
+  //     isFirst = false;
+  //     // if (cache[curPointId].split) {
+  //     return { ...cache[curPointId], isFirst };
+  //     // }
+  //   }
+
+  //   const joinLines = getWholeLineLinesRawByPointId(config, curPointId).filter(
+  //     (line) =>
+  //       !(
+  //         line.pointIds.includes(linePointIds[0]) &&
+  //         line.pointIds.includes(linePointIds[1])
+  //       )
+  //   );
+  //   const joinLineDires: number[][] = [];
+  //   const lineDire = ndx === 0 ? lineDire0 : lineDire1;
+
+  //   let invAngle = Number.MAX_VALUE;
+  //   let invSelectLineId: string;
+  //   let invSelectLineDire: number[] | null = null;
+
+  //   let alongAngle = -Number.MAX_VALUE;
+  //   let alongSelectLineId: string;
+  //   let alongSelectLineDire: number[] | null = null;
+
+  //   for (let { pointIds: joinPointIds, id } of joinLines) {
+  //     joinPointIds = [
+  //       linePointIds[ndx],
+  //       ...joinPointIds.filter((id) => id !== linePointIds[ndx]),
+  //     ];
+  //     const joinLine = getWholeLinePoints(config, joinPointIds);
+  //     const joinLineDire = getLineDire([
+  //       joinLine[0].x,
+  //       joinLine[0].y,
+  //       joinLine[1].x,
+  //       joinLine[1].y,
+  //     ]);
+  //     joinLineDires.push(joinLineDire);
+  //     // if (["10", "14"].includes(id)) {
+  //     //   continue;
+  //     // }
+
+  //     const currentAngle = getDire2Angle(lineDire, joinLineDire);
+  //     // 逆时针
+  //     if (currentAngle > 0) {
+  //       if (currentAngle < invAngle) {
+  //         invAngle = currentAngle;
+  //         invSelectLineId = id;
+  //         invSelectLineDire = joinLineDire;
+  //       }
+  //     } else {
+  //       if (currentAngle > alongAngle) {
+  //         alongAngle = currentAngle;
+  //         alongSelectLineId = id;
+  //         alongSelectLineDire = joinLineDire;
+  //       }
+  //     }
+  //   }
+
+  //   let pointJointLineDire: number[] | null = null;
+  //   let angle: number | null = null;
+  //   let selectLineId: string | null = null;
+
+  //   if (!invSelectLineDire || !alongSelectLineDire) {
+  //     pointJointLineDire = invSelectLineDire || alongSelectLineDire;
+  //     selectLineId = invSelectLineDire ? invSelectLineId : alongSelectLineId;
+  //     angle = invSelectLineDire ? invAngle : alongAngle;
+  //   } else if (
+  //     Math.abs(getDire2Angle(moveDire, invSelectLineDire)) <
+  //     Math.abs(getDire2Angle(moveDire, alongSelectLineDire))
+  //   ) {
+  //     pointJointLineDire = invSelectLineDire;
+  //     selectLineId = invSelectLineId;
+  //     angle = invAngle;
+  //   } else {
+  //     pointJointLineDire = alongSelectLineDire;
+  //     selectLineId = alongSelectLineId;
+  //     angle = alongAngle;
+  //   }
+
+  //   let isSplitPoint = false;
+  //   // 需要判定,如果参考线与当前线段夹角超过多少则不适合作为参考线
+  //   let refLineAngle = Math.abs(MathUtils.radToDeg(angle));
+  //   if (
+  //     (pointJointLineDire !== null && refLineAngle > angleRang[1]) ||
+  //     refLineAngle < angleRang[0]
+  //   ) {
+  //     console.log(
+  //       "夹角不在范围,分割",
+  //       selectLineId,
+  //       ndx === 0 ? line0 : line1,
+  //       refLineAngle
+  //     );
+  //     selectLineId = null;
+  //     pointJointLineDire = getVerticalDire(pointJointLineDire);
+  //     isSplitPoint = true;
+
+  //     // 如果有多条线段,判断是否方向一致,不一致则要分割
+  //   } else if (joinLines.length > 1) {
+  //     const temp = pointJointLineDire;
+  //     for (let i = 0; i < joinLines.length; i++) {
+  //       if (temp === joinLineDires[i]) {
+  //         continue;
+  //       }
+  //       const angle =
+  //         (getDire2Angle(temp, joinLineDires[i]) + Math.PI) % Math.PI;
+
+  //       if (round(angle, 3) > 0) {
+  //         console.log("方向不同,分割");
+  //         isSplitPoint = true;
+  //         break;
+  //       }
+  //     }
+  //   }
+
+  //   cache[curPointId].refDire = pointJointLineDire;
+  //   cache[curPointId].lineDire = lineDire;
+  //   cache[curPointId].id = selectLineId;
+  //   cache[curPointId].split = isSplitPoint;
+  //   cache[curPointId].isFirst = isFirst;
+
+  //   return cache[curPointId];
+  // };
 
   return (move: number[]) => {
-    const moveDire = new Vector2(move[0], move[1]).normalize().toArray();
-    const pointInfos = [
-      getPointRefInfo(moveDire, 0),
-      getPointRefInfo(moveDire, 1),
-    ];
+    // const moveDire = new Vector2(move[0], move[1]).normalize().toArray();
+    // const pointInfos = [
+    //   getPointRefInfo(moveDire, 0),
+    //   getPointRefInfo(moveDire, 1),
+    // ];
 
     // console.log(pointInfos);
     const positions = [
@@ -634,54 +634,54 @@ export const repeatMoveWholeLineLine = (
       [initPosition[1][0] + move[0], initPosition[1][1] + move[1]],
     ];
     const pointAttribs = getWholeLinePoints(config, lineAttrib.pointIds);
-    if (pointInfos[0].refDire || pointInfos[1].refDire) {
-      const currentPositions: number[][] = [];
-      const joinDires = pointInfos.map(({ refDire }) =>
-        refDire === null
-          ? pointInfos[0].refDire || pointInfos[1].refDire
-          : refDire
-      );
-
-      for (let i = 0; i < pointInfos.length; i++) {
-        const joinDire = joinDires[i];
-        const isSplit = pointInfos[i].split && pointInfos[i].isFirst;
-        const joinLine = createLineByDire(joinDire, initPosition[i], 10);
-
-        if (isSplit) {
-          const addPointId = generateWholeLinePointId(config);
-          config.points.push({
-            ...pointAttribs[i],
-            id: addPointId,
-          });
-          wholeLineLineIsolatePoint(
-            config,
-            line0,
-            lineAttrib.pointIds[i],
-            addPointId
-          );
-        }
-        currentPositions[i] = getLineProjection(joinLine, positions[i]).point;
-      }
-      const firstMain =
-        getLineDist(currentPositions[0], initPosition[0]) <
-        getLineDist(currentPositions[1], initPosition[1]);
-      const lineDire = firstMain ? lineDire0 : lineDire1;
-      const lineStart = firstMain ? currentPositions[0] : currentPositions[1];
-      const bitDire = firstMain ? joinDires[1] : joinDires[0];
-      const bitStart = firstMain ? initPosition[1] : initPosition[0];
-
-      const main = createLineByDire(lineDire, lineStart, 10);
-      const bit = createLineByDire(bitDire, bitStart, 10);
-      const lineEnd = getLineIntersection(main, bit);
-
-      if (firstMain) {
-        positions[0] = lineStart;
-        positions[1] = lineEnd;
-      } else {
-        positions[1] = lineStart;
-        positions[0] = lineEnd;
-      }
-    }
+    // if (pointInfos[0].refDire || pointInfos[1].refDire) {
+    //   const currentPositions: number[][] = [];
+    //   const joinDires = pointInfos.map(({ refDire }) =>
+    //     refDire === null
+    //       ? pointInfos[0].refDire || pointInfos[1].refDire
+    //       : refDire
+    //   );
+
+    //   for (let i = 0; i < pointInfos.length; i++) {
+    //     const joinDire = joinDires[i];
+    //     const isSplit = pointInfos[i].split && pointInfos[i].isFirst;
+    //     const joinLine = createLineByDire(joinDire, initPosition[i], 10);
+
+    //     if (isSplit) {
+    //       const addPointId = generateWholeLinePointId(config);
+    //       config.points.push({
+    //         ...pointAttribs[i],
+    //         id: addPointId,
+    //       });
+    //       wholeLineLineIsolatePoint(
+    //         config,
+    //         line0,
+    //         lineAttrib.pointIds[i],
+    //         addPointId
+    //       );
+    //     }
+    //     currentPositions[i] = getLineProjection(joinLine, positions[i]).point;
+    //   }
+    //   const firstMain =
+    //     getLineDist(currentPositions[0], initPosition[0]) <
+    //     getLineDist(currentPositions[1], initPosition[1]);
+    //   const lineDire = firstMain ? lineDire0 : lineDire1;
+    //   const lineStart = firstMain ? currentPositions[0] : currentPositions[1];
+    //   const bitDire = firstMain ? joinDires[1] : joinDires[0];
+    //   const bitStart = firstMain ? initPosition[1] : initPosition[0];
+
+    //   const main = createLineByDire(lineDire, lineStart, 10);
+    //   const bit = createLineByDire(bitDire, bitStart, 10);
+    //   const lineEnd = getLineIntersection(main, bit);
+
+    //   if (firstMain) {
+    //     positions[0] = lineStart;
+    //     positions[1] = lineEnd;
+    //   } else {
+    //     positions[1] = lineStart;
+    //     positions[0] = lineEnd;
+    //   }
+    // }
 
     pointAttribs[0].x = positions[0][0];
     pointAttribs[0].y = positions[0][1];