浏览代码

fix: 修改复制逻辑

bill 1 年之前
父节点
当前提交
5c12c10e73
共有 3 个文件被更改,包括 18 次插入16 次删除
  1. 3 10
      src/app/liantong/index.ts
  2. 0 1
      src/board/packages/container.ts
  3. 15 5
      src/board/shared/entity-utils.ts

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

@@ -1,11 +1,4 @@
-import {
-  Euler,
-  MathUtils,
-  Matrix4,
-  OrthographicCamera,
-  Quaternion,
-  Vector3,
-} from "three";
+import { Matrix4, OrthographicCamera, Vector3 } from "three";
 import {
   CameraQueryPlugin,
   EditPoi,
@@ -70,7 +63,7 @@ export const createBoard = (
       board.history.clear();
     },
     setCamera(camera: OrthographicCamera) {
-      // -1 - 1转到屏幕
+      // // -1 - 1转到屏幕
       // const bound = board.bound.bound;
       // const realWidth = bound[2] - bound[0];
       // const realHeight = bound[3] - bound[1];
@@ -91,7 +84,7 @@ export const createBoard = (
       // const cameraMat = tStageMat.toArray();
       // board.bound.setCameraMat(cameraMat);
 
-      board.bound.bus.off("cameraChange");
+      // board.bound.bus.off("cameraChange");
 
       // -1 - 1转到屏幕
       const bound = board.bound.bound;

+ 0 - 1
src/board/packages/container.ts

@@ -250,7 +250,6 @@ export class Container<
     euler.setFromQuaternion(quaternion, "XYZ");
     // 提取绕Z轴的旋转,即二维旋转角度
     const rotationZ = euler.z; // 在Three.js中,角度是以弧度表示的
-    console.log(MathUtils.radToDeg(euler.z));
     // 更新Konva Stage的位置和缩放
     this.stage.scale({ x: scale.x, y: scale.y });
     this.stage.position({ x: translate.x, y: translate.y });

+ 15 - 5
src/board/shared/entity-utils.ts

@@ -4,7 +4,12 @@ import { Container } from "../packages";
 import { EntityType, Entity } from "../packages/entity";
 import { Attrib, ShapeType } from "../type";
 import { getTouchOffset } from "./act";
-import { createLineByDire, getDireDist } from "./math";
+import {
+  createLineByDire,
+  getDireDist,
+  getLineIntersection,
+  getLineProjection,
+} from "./math";
 import { inRevise } from "./public";
 import { disableMouse, enableMouse } from "./shape-mose";
 import { generateId, getChangePart } from "./util";
@@ -126,16 +131,21 @@ export const copyEntityAttrib = <T extends Entity = Entity>(
 ) => {
   const count = props.count || 1;
   const dire = props.dire || [1, 0];
-  const halfSize = props.size;
+  const size = props.size;
   const entity = props.entity;
   const start = entity.shape.getPosition();
-  const unit = getDireDist(halfSize);
+  const line = createLineByDire(dire, [start.x, start.y], 10);
   const items = entity.container.getSameLevelData(entity) as Attrib[];
 
   for (let i = 0; i < count; i++) {
-    const line = createLineByDire(dire, [start.x, start.y], unit * (i + 1));
+    const offset = size.map((p) => (p *= i + 1));
+    const point = getLineProjection(line, [
+      start.x + offset[0],
+      start.y + offset[1],
+    ]).point;
+
     const newAttrib = {
-      ...props.factoryAttrib([line[2], line[3]]),
+      ...props.factoryAttrib(point),
       id: generateId(items),
     };
     items.push(newAttrib as any);