Parcourir la source

fix: 修改bug

bill il y a 10 mois
Parent
commit
7890e40f5c

Fichier diff supprimé car celui-ci est trop grand
+ 56 - 0
src/app/liantong/icon.ts


+ 75 - 7
src/app/liantong/index.ts

@@ -1,4 +1,4 @@
-import { Matrix4, OrthographicCamera, Vector3 } from "three";
+import { Matrix3, Matrix4, OrthographicCamera, Vector2, Vector3 } from "three";
 import {
   CameraQueryPlugin,
   EditPoi,
@@ -7,19 +7,19 @@ import {
   HistoryPlugin,
   Poi,
   PoiAttrib,
-  WholeLine,
   addEntityAttrib,
   register,
 } from "../../board";
 import "./icon";
 import mitt from "mitt";
-import { line, point, polygon } from "../../board/packages/whole-line/style";
+import { line, polygon } from "../../board/packages/whole-line/style";
 
 export * from "../../board";
-polygon.fill = point.stroke = point.fill = "rgba(0,0,0,0)";
+// point.fill =point.stroke =
+polygon.fill = "rgba(0,0,0,0)";
 line.stroke = "#fff";
 
-const types = { rooms: WholeLine, pois: EditPoi };
+const types = { rooms: EditWholeLine, pois: EditPoi };
 const initBoard = register(types, {
   bound: new CameraQueryPlugin({ move: true, wheel: true }),
   history: new HistoryPlugin(),
@@ -97,11 +97,66 @@ export const createBoard = (
     //   bus.emit("activePoi", activePoi as EditPoi);
     // }
   });
+  let rotationZ = 0;
+  let centerR: Vector3;
+  let cameraR: OrthographicCamera;
+  const setMat = new Matrix3();
+  setMat.identity();
+
+  const rotateData = (data: any, mat: Matrix3) => {
+    data = { ...data };
+    // mat.invert();
+    const v = new Vector2();
+    data.rooms = data.rooms.map((room) => ({
+      ...room,
+      points: room.points.map((point) => {
+        v.set(point.x, point.y);
+        v.applyMatrix3(mat);
+        return {
+          ...point,
+          x: v.x,
+          y: v.y,
+        };
+      }),
+    }));
+    //  {x: -1.0303030014038086, y: 2.282296130361026e-16, z: -3.7272729873657227}
+    // x
+    // 1.5097999572753906
+    // 2.042250156402588
+    data.pois = data.pois.map((poi) => {
+      v.set(poi.x, poi.y);
+      v.applyMatrix3(mat);
+      return {
+        ...poi,
+        x: v.x,
+        y: v.y,
+      };
+    });
+    return data;
+  };
 
   // const prevMat:
-  return {
+  const ret = {
     ...board,
     bus,
+    setData(data, { angle, center } = { angle: 0, center: new Vector3() }) {
+      // console.log(angle, center);
+      // center.x = 1.5097999572753906;
+      // center.z = -2.042250156402588;
+      centerR = center;
+      rotationZ = -angle;
+      center = new Vector3(-center.x, center.y, -center.z);
+      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));
+    },
+    getData() {
+      return rotateData(board.getData(), setMat.clone().invert());
+    },
     blurPoi() {
       if (activePoi) {
         activePoi.bus.emit("shapeStatusChange", {
@@ -118,7 +173,11 @@ export const createBoard = (
       } as any);
       board.history.clear();
     },
-    setCamera(camera: OrthographicCamera) {
+    setCamera(camera: OrthographicCamera, center: Vector3) {
+      center = center || centerR;
+      cameraR = camera;
+      if (!board.bound.bound) return;
+
       // // -1 - 1转到屏幕
       // const bound = board.bound.bound;
       // const realWidth = bound[2] - bound[0];
@@ -159,8 +218,11 @@ export const createBoard = (
         .invert();
 
       const tStageMat = prevMat.clone().multiply(temp);
+      rotationZ = board.bound.rotateZ = camera.rotation.z;
       board.bound.setCameraMat(tStageMat.toArray());
+      // board.tree.stage.position(camera.position);
 
+      // console.log(camera, center, MathUtils.radToDeg(rotationZ));
       board.bound.bus.on("cameraChange", () => {
         const cameraMat = board.bound.cameraMat
           .clone()
@@ -170,6 +232,8 @@ export const createBoard = (
 
         cameraMat.decompose(camera.position, camera.quaternion, camera.scale);
       });
+
+      // console.log(ret.getData());
     },
     showPois() {
       if (!board.tree.entrys.pois) return;
@@ -193,6 +257,7 @@ export const createBoard = (
       pois.forEach((poi) => poi.setShowLabel(false));
     },
     addPoi(type: string) {
+      console.error(type);
       if (!pois()) {
         const data = board.getData();
         data.pois = [];
@@ -219,9 +284,12 @@ export const createBoard = (
     mount(dom: HTMLDivElement) {
       board.mount(dom);
       board.bound.setSize(dom.offsetWidth, dom.offsetHeight);
+      ret.setCamera(cameraR, centerR);
     },
     get room() {
       return getRoom();
     },
   };
+
+  return ret;
 };

+ 106 - 0
src/app/liantong/temp

@@ -0,0 +1,106 @@
+[
+  {
+    name: "内墙",
+    type: "Wall",
+    icon: "icon-cad-neiqiang",
+    info: { type: "symbols" },
+  },
+  {
+    name: "外墙",
+    type: "OutWall",
+    icon: "icon-cad-waiqiang",
+    info: { type: "symbols" },
+  },
+
+  {
+    name: "单开门",
+    type: "SingleDoor",
+    icon: "icon-cad-men",
+    info: { type: "symbols" },
+  },
+  {
+    name: "双开门",
+    type: "DoubleDoor",
+    icon: "icon-cad-shuangkaimen",
+    info: { type: "symbols" },
+  },
+  {
+    name: "移门",
+    type: "SlideDoor",
+    icon: "icon-cad-yimen",
+    info: { type: "symbols" },
+  },
+  {
+    name: "垭口",
+    type: "Pass",
+    icon: "icon-cad-yakou",
+    info: { type: "symbols" },
+  },
+  {
+    name: "一字窗",
+    type: "SingleWindow",
+    icon: "icon-cad-chuang",
+    info: { type: "symbols" },
+  },
+  {
+    name: "一字飘窗",
+    type: "BayWindow",
+    icon: "icon-cad-piaochuang",
+    info: { type: "symbols" },
+  },
+  {
+    name: "落地窗",
+    type: "FrenchWindow",
+    icon: "icon-cad-luodichuang",
+    info: { type: "symbols" },
+  },
+  {
+    name: "柱子",
+    type: "Beam",
+    icon: "icon-cad-zhuzi",
+    info: { type: "symbols" },
+  },
+  {
+    name: "烟道",
+    type: "Flue",
+    icon: "icon-cad-yandao",
+    info: { type: "symbols" },
+  },
+  {
+    name: "楼道",
+    type: "Corridor",
+    icon: "icon-cad-loudao",
+    info: { type: "symbols" },
+  },
+  { name: "电视", type: "TV", icon: "icon-TV", info: { type: "furnitures" } },
+  {
+    name: "组合沙发",
+    type: "CombinationSofa",
+    icon: "icon-CombinationSofa",
+    info: { type: "furnitures" },
+  },
+  {
+    name: "单人沙发",
+    type: "SingleSofa",
+    icon: "icon-SingleSofa",
+    info: { type: "furnitures" },
+  },
+  {
+    name: "茶几",
+    type: "TeaTable",
+    icon: "icon-TeaTable",
+    info: { type: "furnitures" },
+  },
+  {
+    name: "地毯",
+    type: "Carpet",
+    icon: "icon-Carpet",
+    info: { type: "furnitures" },
+  },
+  {
+    name: "餐桌",
+    type: "DiningTable",
+    icon: "icon-DiningTable",
+    info: { type: "furnitures" },
+  },
+]

+ 6 - 2
src/board/packages/container.ts

@@ -190,7 +190,7 @@ export class Container<
 
   constant = constantFactory();
 
-  updateViewMat(mat: Matrix4) {
+  updateViewMat(mat: Matrix4, rotateZ?: number) {
     const translate = new Vector3();
     const quaternion = new Quaternion();
     const scale = new Vector3();
@@ -213,7 +213,11 @@ export class Container<
     const oldScale = this.stage.scale();
     this.stage.scale({ x: scale.x, y: scale.y });
     this.stage.position({ x: translate.x, y: translate.y });
-    this.stage.rotation(MathUtils.radToDeg(rotationZ));
+    if (typeof rotateZ == "number") {
+      this.stage.rotation(MathUtils.radToDeg(rotateZ));
+    } else {
+      this.stage.rotation(MathUtils.radToDeg(rotationZ));
+    }
     if (
       !(
         Math.abs(oldScale.x - scale.x) < 0.001 &&

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

@@ -229,7 +229,6 @@ export class EditWholeLine<
             ...points.slice(startNdx + 1, end),
             ...points.slice(0, startNdx),
           ];
-          console.log(points);
           return points.map((point) => [point.x, point.y]);
         });
         return pointsArray;
@@ -253,6 +252,7 @@ export class EditWholeLine<
         pointAttrib.y = position[1];
       },
       endHandler: (attrib) => {
+        console.log("end");
         this.container.constant.unuse();
         this.pointAfterHandler(attrib);
         this.container.bus.emit("dataChangeAfter");

+ 1 - 1
src/board/packages/whole-line/service/constant.ts

@@ -2,7 +2,7 @@
 export let WHOLE_LINE_POINT_EQ_DIST = 0.001;
 
 // 需要合并距离
-export let WHOLE_LINE_POINT_MERGE_DIST = 10;
+export let WHOLE_LINE_POINT_MERGE_DIST = 1;
 
 export const updateConstant = (scale: number) => {
   WHOLE_LINE_POINT_EQ_DIST *= scale;

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

@@ -704,6 +704,7 @@ export const fixWholeLineConfig = (config: WholeLineAttrib) => {
     );
     if (dist !== 0) continue;
     const change = wholeLineReplacePoint(config, [points[1].id], points[0].id);
+    console.log(change);
     i = Math.max(i - change.lineChange.del.length, 0);
   }
 

+ 6 - 1
src/board/plugins/camera-plugin.ts

@@ -133,6 +133,8 @@ export class CameraQueryPlugin {
     this.bus.emit("cameraChange", this.cameraMat.toArray());
   }
 
+  rotateZ: number;
+
   setCameraMat(mat: number[] | Matrix4) {
     if (mat instanceof Matrix4) {
       this.cameraMat = mat;
@@ -238,6 +240,9 @@ export class CameraQueryPlugin {
   }
 
   update() {
-    this.tree.updateViewMat(this.clipMat.clone().multiply(this.cameraMat));
+    this.tree.updateViewMat(
+      this.clipMat.clone().multiply(this.cameraMat),
+      this.rotateZ
+    );
   }
 }

+ 2 - 0
src/board/register.ts

@@ -63,6 +63,8 @@ export const register = <
       types,
       tree: container,
       setData(newData: Partial<DATA>) {
+        console.log("setData", newData);
+        // newData.pois = [];
         container.setAttrib({ data: newData as any });
       },
       getData() {