diff --git a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts index 86f0e8179..b3bab4a1c 100644 --- a/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts +++ b/src/Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool.ts @@ -33,7 +33,10 @@ import { IsDoor, IsHandle, IsHinge } from "../../HideSelect/HideSelectUtils"; * 偏移找到合适位置 * @type {*} * */ -const MoveNum = 8; +const MoveNum: number = 8; + +//绘制出的铰链与层板(左右开门时)或立板(上下开门时)最低间距 或偏移后最低间距 +export const BoxIntersectFuzz: number = 5; export class DrawDoorTool { @@ -618,7 +621,8 @@ export class DrawDoorTool br2GrooveOutlinesCache.set(br, grooveOutlines); } - if (brBox.clone().intersect(ironBox).isSolid()) + //门板不增加误差,防止隔壁门板误关联 + if (brBox.clone().intersect(ironBox).isSolid() || !IsDoor(br) && brBox.intersectsBox(ironBox, BoxIntersectFuzz)) { const center = ironBox.getCenter(new Vector3).applyMatrix4(br.OCSInv).setZ(0); if (grooveOutlines.some(c => c.PtInCurve(center)))//五金的中心在造型内部 @@ -675,9 +679,9 @@ export class DrawDoorTool { if (!IsHinge(ironware)) continue; - if (!IsBoxAndEntitysIntersect(ironBox, [otherEnt])) continue; - - if (IsDoor(otherEnt)) + let isDoor = IsDoor(otherEnt); + if (!IsBoxAndEntitysIntersect(ironBox, [otherEnt], BoxIntersectFuzz, undefined, isDoor)) continue; + if (isDoor) { //铰链归属复合门板 ironware.RelevanceBoards.push(otherEnt.Id); @@ -906,7 +910,7 @@ export class DrawDoorTool if (box1Info + (isUpDownDoor ? 10 : 100) < doorSpecs) { - if (!IsBoxAndEntitysIntersect(realityBox1, checkEnts)) + if (!IsBoxAndEntitysIntersect(realityBox1, checkEnts, BoxIntersectFuzz)) return number; else return this.MoveAgain(doorSpecs, inventedBox, realityBox, checkEnts, distance, number, isUpDownDoor); @@ -936,7 +940,7 @@ export class DrawDoorTool } if (box2Info - (isUpDownDoor ? 10 : 100) > 0) { - if (!IsBoxAndEntitysIntersect(realityBox2, checkEnts)) + if (!IsBoxAndEntitysIntersect(realityBox2, checkEnts, BoxIntersectFuzz)) return -number; else { @@ -1010,7 +1014,7 @@ export function SetHingeType(br: Board, ironware: HardwareCompositeEntity): void * @param checkEnts 校验的实体列表 * @param parentOCS 父空间的坐标系 */ -export function IsBoxAndEntitysIntersect(enBox: Box3, checkEnts: Entity[], parentOCS?: Matrix4): boolean +export function IsBoxAndEntitysIntersect(enBox: Box3, checkEnts: Entity[], fuzz?: number, parentOCS?: Matrix4, isDoor?: boolean): boolean { for (let checkEnt of checkEnts) { @@ -1019,22 +1023,29 @@ export function IsBoxAndEntitysIntersect(enBox: Box3, checkEnts: Entity[], paren let ocs = checkEnt.OCSNoClone; if (parentOCS) ocs = new Matrix4().multiplyMatrices(parentOCS, ocs); - if (IsBoxAndEntitysIntersect(enBox, checkEnt.Entitys, ocs)) + if (IsBoxAndEntitysIntersect(enBox, checkEnt.Entitys, fuzz, ocs, isDoor)) return true; } else { let box = checkEnt.BoundingBox as Box3Ext; if (parentOCS) box.applyMatrix4(parentOCS); - if (box.intersectsBox(enBox, 10)) - return true; + if (isDoor) + { + if (box.clone().intersect(enBox).Volume > 0) + return true; + } + else + { + if (box.intersectsBox(enBox, fuzz)) + return true; + } } } return false; } /** - * * 特殊铰链模板(多个实体编组) * 防止 hingeSpace.GetParam("SY").value 被覆盖 * diff --git a/src/UI/Components/Template/TemplateDrawHingeTool.ts b/src/UI/Components/Template/TemplateDrawHingeTool.ts index c62403179..d4c074a0a 100644 --- a/src/UI/Components/Template/TemplateDrawHingeTool.ts +++ b/src/UI/Components/Template/TemplateDrawHingeTool.ts @@ -1,5 +1,5 @@ import { Box3, Vector3 } from "three"; -import { IsBoxAndEntitysIntersect, RecordHingeTrSizeX, SetHingeType, SetNoPareTypeHigneName } from "../../../Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool"; +import { BoxIntersectFuzz, IsBoxAndEntitysIntersect, RecordHingeTrSizeX, SetHingeType, SetNoPareTypeHigneName } from "../../../Add-on/DrawBoard/DrawDoorDrawer/DrawDoorTool"; import { IsDoor, IsHandle, IsHinge } from "../../../Add-on/HideSelect/HideSelectUtils"; import { app } from "../../../ApplicationServices/Application"; import { EBoardKeyList } from "../../../Common/BoardKeyList"; @@ -402,7 +402,8 @@ export class TemplateDrawHingeTool outlinesCache.set(br, grooveOutlines); } - if (otherEntBox.clone().intersect(inventedBox).isSolid()) + //门板不增加误差,防止隔壁门板误关联 + if (otherEntBox.clone().intersect(inventedBox).isSolid() || !IsDoor(br) && otherEntBox.intersectsBox(inventedBox, BoxIntersectFuzz)) { const center = inventedBox.getCenter(new Vector3).applyMatrix4(br.OCSInv).setZ(0); if (grooveOutlines.some(c => c.PtInCurve(center))) @@ -447,7 +448,8 @@ export class TemplateDrawHingeTool { if (!IsHinge(ironware)) continue; - if (!IsBoxAndEntitysIntersect(realityBox, [otherEnt])) continue; + let isDoor = IsDoor(otherEnt); + if (!IsBoxAndEntitysIntersect(realityBox, [otherEnt], BoxIntersectFuzz, undefined, isDoor)) continue; if (IsDoor(otherEnt)) { @@ -511,7 +513,7 @@ export class TemplateDrawHingeTool realityBox1.translate(new Vector3(0, 0, distance * number)); let box1Z = inventedBox1.getCenter(new Vector3).z; - if (box1Z + 100 < doorHight && !IsBoxAndEntitysIntersect(realityBox1, layers)) + if (box1Z + 100 < doorHight && !IsBoxAndEntitysIntersect(realityBox1, layers, BoxIntersectFuzz)) return number * distance; else { @@ -522,7 +524,7 @@ export class TemplateDrawHingeTool let realityBox2 = realityBox.clone(); realityBox2.translate(new Vector3(0, 0, distance * -number)); - if (box2Z - 100 > 0 && !IsBoxAndEntitysIntersect(realityBox2, layers)) + if (box2Z - 100 > 0 && !IsBoxAndEntitysIntersect(realityBox2, layers, BoxIntersectFuzz)) return -number * distance; else { @@ -544,7 +546,7 @@ export class TemplateDrawHingeTool realityBox1.translate(new Vector3(distance * number, 0, 0)); - if (box1Z + 100 < doorHight && !IsBoxAndEntitysIntersect(realityBox1, verticals)) + if (box1Z + 100 < doorHight && !IsBoxAndEntitysIntersect(realityBox1, verticals, BoxIntersectFuzz)) return number * distance; else { @@ -555,7 +557,7 @@ export class TemplateDrawHingeTool let realityBox2 = realityBox.clone(); realityBox2.translate(new Vector3(distance * -number, 0, 0)); - if (box2Z - 100 > 0 && !IsBoxAndEntitysIntersect(realityBox2, verticals)) + if (box2Z - 100 > 0 && !IsBoxAndEntitysIntersect(realityBox2, verticals, BoxIntersectFuzz)) return -number * distance; else {