From 09db56800fc658a2fecc515601eff369f105ce13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=89?= <940119273@qq.com> Date: Tue, 7 May 2024 10:17:26 +0000 Subject: [PATCH] =?UTF-8?q?!2597=20=E4=BF=AE=E5=A4=8D:=E9=93=B0=E9=93=BE?= =?UTF-8?q?=E9=81=BF=E8=AE=A9=E8=8E=B7=E5=8F=96=E7=9A=84obb=E5=A2=9E?= =?UTF-8?q?=E5=AE=BD=E7=9B=92=E5=AD=90=E4=B8=8D=E6=AD=A3=E7=A1=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawBoard/DrawDoorDrawer/DrawDoorTool.ts | 76 +++++++++---------- .../DrawDoorDrawer/DrawLeftRightOpenDoor.ts | 2 +- .../DrawDoorDrawer/DrawUpDownOpenDoor.ts | 2 +- .../Components/Template/TemplateComponent.tsx | 3 +- .../Template/TemplateDrawHingeTool.ts | 11 ++- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts index a32388e2a..bf7d74dfa 100644 --- a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts +++ b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts @@ -532,7 +532,7 @@ export class DrawDoorTool * @param isUpDownDoor 上下开门 否为左右开门 * @returns */ - protected RelativeMetalsToBoard(allEntitys: Entity[], isUpDownDoor: boolean) + protected RelativeMetalsToBoard(allEntitys: Entity[], isUpDownDoor: boolean, doorSpaceSize: Vector3, spaceOCS: Matrix4) { let boards: Board[] = []; let doors: Entity[] = []; @@ -584,14 +584,10 @@ export class DrawDoorTool doors.push(en); } - let scsInv = doors[0].SpaceOCSInv; - let doorBox = new Box3; - for (let door of doors) - doorBox.union(door.GetBoundingBoxInMtx(scsInv)); //获取门板空间盒子(在门板的空间坐标系中) + let scsInv = new Matrix4().getInverse(spaceOCS); - let doorSize = doorBox.getSize(new Vector3); - let doorWidth = doorSize.x; - let doorHight = doorSize.z; + const DoorSpaceWidth = doorSpaceSize.x; + const DoorSpaceHight = doorSpaceSize.z; let moveFail = false; let needUpdate = false; @@ -610,7 +606,8 @@ export class DrawDoorTool const isHinge = IsHinge(ironware); const XNormal = new Vector3().setFromMatrixColumn(ironware.OCSNoClone, 0); - const ZNormal = new Vector3().setFromMatrixColumn(ironware.OCSNoClone, 2); + //使用空间坐标系 左右开门时 向上为偏移正方向 上下开门时 向右为正方向 + const ZNormal = new Vector3().setFromMatrixColumn(spaceOCS, isUpDownDoor ? 0 : 2); for (let otherEnt of allOtherEntitys) { @@ -667,12 +664,12 @@ export class DrawDoorTool if (isUpDownDoor) { if (RecordHingeTrSizeX(hingeTr2Size_Map, hingeTr, size.x)) continue; - deviationNum = this.GetHingeMoveNum(doorWidth, ironBoxInDoorSpace, ironBox, ironware, verticalBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); + deviationNum = this.GetHingeMoveNum(DoorSpaceWidth, ironBoxInDoorSpace, ironBox, ironware, verticalBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); } else { if (RecordHingeTrSizeX(hingeTr2Size_Map, hingeTr, size.z)) continue; - deviationNum = this.GetHingeMoveNum(doorHight, ironBoxInDoorSpace, ironBox, ironware, layerBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); + deviationNum = this.GetHingeMoveNum(DoorSpaceHight, ironBoxInDoorSpace, ironBox, ironware, layerBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); } if (deviationNum === 0) @@ -733,15 +730,13 @@ export class DrawDoorTool let deviationNum = 1; if (isUpDownDoor) { - let doorWidth = doorBox.getSize(new Vector3).x; if (RecordHingeTrSizeX(hingeTr2Size_Map, hingeTr, ironSize.x)) continue; - deviationNum = this.GetHingeMoveNum(doorWidth, ironBoxInDoorSpace, ironBox, ironware, verticalBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); + deviationNum = this.GetHingeMoveNum(DoorSpaceWidth, ironBoxInDoorSpace, ironBox, ironware, verticalBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); } else { - let doorHight = doorBox.getSize(new Vector3).z; if (RecordHingeTrSizeX(hingeTr2Size_Map, hingeTr, ironSize.z)) continue; - deviationNum = this.GetHingeMoveNum(doorHight, ironBoxInDoorSpace, ironBox, ironware, layerBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); + deviationNum = this.GetHingeMoveNum(DoorSpaceHight, ironBoxInDoorSpace, ironBox, ironware, layerBoards, this.option.deviation, deviationNum, isUpDownDoor, ZNormal); } if (deviationNum === 0) { @@ -929,7 +924,8 @@ export class DrawDoorTool * @return {*} {number} * @memberof DrawDoorTool */ - private GetHingeMoveNum(doorSpecs: number, inventedBox: Box3, realityBox: Box3, ironware: Entity, checkEnts: Entity[], distance: number, deviationNum: number, isUpDownDoor: boolean, ZNormal: Vector3): number + private GetHingeMoveNum(doorSpecs: number, inventedBox: Box3, realityBox: Box3, ironware: Entity, checkEnts: Entity[], + distance: number, deviationNum: number, isUpDownDoor: boolean, ZNormal: Vector3): number { let box1 = inventedBox.clone(); let box1Info: number; @@ -952,6 +948,7 @@ export class DrawDoorTool let intersect = false; if (box1Info + (isUpDownDoor ? 10 : 100) < doorSpecs) { + translate = ZNormal.clone().multiplyScalar(distance * deviationNum); if (IsBoxAndEntitysIntersect(checkEnts, [ironware], ZNormal, false, translate)) intersect = true; } @@ -986,6 +983,7 @@ export class DrawDoorTool let intersect = false; if (box2Info - (isUpDownDoor ? 10 : 100) > 0) { + translate = ZNormal.clone().multiplyScalar(distance * -deviationNum); if (IsBoxAndEntitysIntersect(checkEnts, [ironware], ZNormal, false, translate)) intersect = true; } @@ -1137,44 +1135,42 @@ export function SetTypeHigneName(relativeDoors: Set, allSpaceEnts: Entit } } +//获取与铰链Z轴平行的向量 +function GetNormalAddSize(normal: Vector3, xNormal: Vector3, yNormal: Vector3): Vector3 +{ + if (isParallelTo(normal, xNormal)) + return new Vector3(10, -0.1, -0.1); + else if (isParallelTo(normal, yNormal)) + return new Vector3(-0.1, 10, -0.1); + else + return new Vector3(-0.1, -0.1, 10); +} + /** - * - * * @export * @param {OBB} obb * @param {Vector3} normalizeZ * @param {Matrix4} parentIntersectEntOCS - * @param {boolean} isExtrudeSolid + * @param {boolean} isSweepSolid * @param {boolean} isDoor 门板类型不增加误差值 * @return {*} {OBB} */ -export function getFuzzOBB(obb: OBB, normalizeZ: Vector3, parentIntersectEntOCS: Matrix4, isExtrudeSolid: boolean, isDoor: boolean): OBB +export function getFuzzOBB(obb: OBB, normalizeZ: Vector3, parentIntersectEntOCS: Matrix4, isSweepSolid: boolean, isDoor: boolean): OBB { - let addSize = isDoor ? new Vector3() : new Vector3(-0.1, -0.1, 10); - if (!isExtrudeSolid) - addSize.applyMatrix4(parentIntersectEntOCS.clone().setPosition(0, 0, 0)); - let halfSizes = obb.halfSizes.add(addSize.applyMatrix4((obb.ocs).clone().setPosition(0, 0, 0))); let ocs = obb.ocs.clone(); - let vz = normalizeZ.clone().multiplyScalar(10); - const XNormal = new Vector3().setFromMatrixColumn(ocs, 0).multiplyScalar(0.1); const YNormal = new Vector3().setFromMatrixColumn(ocs, 1).multiplyScalar(0.1); - const ZNormal = new Vector3().setFromMatrixColumn(ocs, 2).multiplyScalar(0.1); - ocs.elements[12] += XNormal.x; - ocs.elements[13] += XNormal.y; - ocs.elements[14] += XNormal.z; - ocs.elements[12] += YNormal.x; - ocs.elements[13] += YNormal.y; - ocs.elements[14] += YNormal.z; + let addSize = isDoor ? new Vector3() : GetNormalAddSize(normalizeZ, XNormal, YNormal); + if (isSweepSolid) + addSize.applyMatrix4(parentIntersectEntOCS.clone().setPosition(0, 0, 0)); + let halfSizes = obb.halfSizes.add(addSize); - ocs.elements[12] += ZNormal.x; - ocs.elements[13] += ZNormal.y; - ocs.elements[14] += ZNormal.z; + let vz = normalizeZ.clone().normalize().multiplyScalar(10); - ocs.elements[12] -= Math.abs(vz.x); - ocs.elements[13] -= Math.abs(vz.y); - ocs.elements[14] -= Math.abs(vz.z); + ocs.elements[12] -= vz.x; + ocs.elements[13] -= vz.y; + ocs.elements[14] -= vz.z; return new OBB(ocs, halfSizes); } @@ -1231,7 +1227,7 @@ export function IsBoxAndEntitysIntersect(checkEnts: Entity[], intersectEnts: Ent if (translate) ent.ApplyMatrix(backTranslate); if (parentIntersectEntOCS) ent.ApplyMatrix(backParentIntersectEntOCS); - let obb = getFuzzOBB(newCheckEnt.OBB, ZNormal, parentIntersectEntOCS, newCheckEnt instanceof ExtrudeSolid, isDoor); + let obb = getFuzzOBB(newCheckEnt.OBB, ZNormal, parentIntersectEntOCS, newCheckEnt instanceof SweepSolid, isDoor); if (obb.intersectsOBB(entOBB)) return true; } diff --git a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts index f79756012..209ea58ab 100644 --- a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts +++ b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawLeftRightOpenDoor.ts @@ -134,7 +134,7 @@ export class DrawLeftRightOpenDoor extends DrawDoorTool await SetTemplatePositionAndSetParent(this.spaceParse, templateSpace); let spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); - let needReUpdate = this.RelativeMetalsToBoard(spaceAllBoards, false); + let needReUpdate = this.RelativeMetalsToBoard(spaceAllBoards, false, this.spaceParse.Size, this.spaceParse.SpaceOCS); if (needReUpdate) await templateSpace.UpdateTemplateTree(); diff --git a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts index 9cea16ab8..762e5b22a 100644 --- a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts +++ b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawUpDownOpenDoor.ts @@ -135,7 +135,7 @@ export class DrawUpDownOpenDoor extends DrawDoorTool await SetTemplatePositionAndSetParent(this.spaceParse, templateSpace); let spaceAllBoards = this.getSpaceAllEnts(templateSpace.AllEntitys); - let needReUpdate = this.RelativeMetalsToBoard(spaceAllBoards, true); + let needReUpdate = this.RelativeMetalsToBoard(spaceAllBoards, true, this.spaceParse.Size, this.spaceParse.SpaceOCS); if (needReUpdate) await templateSpace.UpdateTemplateTree(); diff --git a/src/UI/Components/Template/TemplateComponent.tsx b/src/UI/Components/Template/TemplateComponent.tsx index de88d4d54..bbee8482e 100644 --- a/src/UI/Components/Template/TemplateComponent.tsx +++ b/src/UI/Components/Template/TemplateComponent.tsx @@ -2,6 +2,7 @@ import { Button, Checkbox, Classes, Intent, Label } from '@blueprintjs/core'; import { observable, toJS } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; +import { Matrix4 } from 'three'; import { AutoCutting } from '../../../Add-on/BoardCutting/AutoCuttingReactor'; import { DrillType } from "../../../Add-on/DrawDrilling/DrillType"; import { IsDoor, IsHandle, IsHinge } from '../../../Add-on/HideSelect/HideSelectUtils'; @@ -796,7 +797,7 @@ export class TemplateManage extends React.Component { //获取包含铰链的空间内实体 allEntitys = this.getSpaceAllEntitys(door); - let needReUpdate = this.TemplateDrawHingeTool.RelativeMetalsToBoard(allEntitys, isLROpen, door); + let needReUpdate = this.TemplateDrawHingeTool.RelativeMetalsToBoard(allEntitys, isLROpen, door, tempSpace.Positioning?.SpaceCS ?? new Matrix4); if (needReUpdate) await tempSpace.Root.UpdateTemplateTree(); } diff --git a/src/UI/Components/Template/TemplateDrawHingeTool.ts b/src/UI/Components/Template/TemplateDrawHingeTool.ts index bd8cff2e1..ea42bd635 100644 --- a/src/UI/Components/Template/TemplateDrawHingeTool.ts +++ b/src/UI/Components/Template/TemplateDrawHingeTool.ts @@ -328,7 +328,7 @@ export class TemplateDrawHingeTool }; //设置五金(拉手 铰链)和板的关联切割 - RelativeMetalsToBoard(allEntitys: Entity[], isLROpen: boolean, door: Board | HardwareCompositeEntity) + RelativeMetalsToBoard(allEntitys: Entity[], isLROpen: boolean, door: Board | HardwareCompositeEntity, spaceOCS: Matrix4) { let brs: Board[] = []; let ironwareEnts: HardwareCompositeEntity[] = []; @@ -394,7 +394,8 @@ export class TemplateDrawHingeTool let hingeSpace = hingeTemp.Parent.Object as TemplateRecord; const xNormal = new Vector3().setFromMatrixColumn(ironware.OCSNoClone, 0); - const ZNormal = new Vector3().setFromMatrixColumn(ironware.OCSNoClone, 2); + //使用空间坐标系 左右开门时 向上为偏移正方向 上下开门时 向右为正方向 + const ZNormal = new Vector3().setFromMatrixColumn(spaceOCS, isLROpen ? 2 : 0); for (let otherEnt of allOtherEntitys) { @@ -533,10 +534,9 @@ export class TemplateDrawHingeTool let intersect = false; if (box1Z + 100 < doorHight) { + translate = ZNormal.clone().multiplyScalar(distance * deviationNum); if (IsBoxAndEntitysIntersect(layers, [ironware], ZNormal, false, translate)) - { intersect = true; - } } else intersect = true; @@ -552,6 +552,7 @@ export class TemplateDrawHingeTool let intersect = false; if (box2Z - 100 > 0) { + translate = ZNormal.clone().multiplyScalar(distance * -deviationNum); if (IsBoxAndEntitysIntersect(layers, [ironware], ZNormal, false, translate)) intersect = true; } @@ -581,6 +582,7 @@ export class TemplateDrawHingeTool let intersect = false; if (box1Z + 100 < doorHight) { + translate = ZNormal.clone().multiplyScalar(distance * deviationNum); if (IsBoxAndEntitysIntersect(verticals, [ironware], ZNormal, false, translate)) intersect = true; } @@ -598,6 +600,7 @@ export class TemplateDrawHingeTool let intersect = false; if (box2Z - 100 > 0) { + translate = ZNormal.clone().multiplyScalar(distance * -deviationNum); if (IsBoxAndEntitysIntersect(verticals, [ironware], ZNormal, false, translate)) intersect = true; }