!2597 修复:铰链避让获取的obb增宽盒子不正确问题

pull/2735/MERGE
林三 5 months ago committed by ChenX
parent e202a6a07b
commit 09db56800f

@ -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<Entity>, 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;
}

@ -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();

@ -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();

@ -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<ITemplateManage, {}> {
//获取包含铰链的空间内实体
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();
}

@ -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;
}

Loading…
Cancel
Save