优化顶底板空间分析

pull/93/head
Zoe 6 years ago
parent 23cdcfc7f7
commit 5162d4106f

@ -1,15 +1,15 @@
import { Matrix4, Vector3 } from 'three';
import { Vector3 } from 'three';
import { app } from '../../ApplicationServices/Application';
import { Singleton } from '../../Common/Singleton';
import { Board, BoardType } from '../../DatabaseServices/Board';
import { Command } from '../../Editor/CommandMachine';
import { PromptStatus } from '../../Editor/PromptResult';
import { MoveMatrix } from '../../Geometry/GeUtils';
import { TopBottomBoardStore } from '../../UI/Store/BoardStore';
import { BoardModalType } from '../../UI/Components/Board/BoardModal';
import { SurroundSpaceParse } from '../../Geometry/SpaceParse/SurroundSpaceParse';
import { BoardModalType } from '../../UI/Components/Board/BoardModal';
import { ModalState, TBBoardOption } from '../../UI/Store/BoardInterface';
import { Singleton } from '../../Common/Singleton';
import { TopBottomBoardStore } from '../../UI/Store/BoardStore';
export class DrawTopBottomBoard implements Command
{
@ -64,7 +64,7 @@ export class DrawTopBottomBoard implements Command
let thickness = parseFloat(opt.thickness);
let offset = parseFloat(opt.offset);
let rot = new Matrix4().extractRotation(spaceParse.SpaceOCS)
let rot = spaceParse.SpaceOCS;
if (opt.isWrapSide)
{

@ -1,9 +1,9 @@
import { SpaceParse } from "./SpaceParse";
import { Vector3, Matrix4 } from "three";
import { BoardType, Board } from "../../DatabaseServices/Board";
import { equalv3, equaln } from "../GeUtils";
import { PromptStatus } from "../../Editor/PromptResult";
import { Vector3 } from "three";
import { app } from "../../ApplicationServices/Application";
import { Board, BoardType } from "../../DatabaseServices/Board";
import { PromptStatus } from "../../Editor/PromptResult";
import { equaln, equalv3 } from "../GeUtils";
import { SpaceParse } from "./SpaceParse";
/**
*(,)
@ -31,13 +31,9 @@ export class SurroundSpaceParse extends SpaceParse
private m_BaseBehindPoint: Vector3;
private m_BehindLength: number;
private m_BaseFootPoint: Vector3;
//是否需要选择标准板
protected isSetStandardBoard: boolean = true;
constructor(boards: Board[], isSet?: boolean)
constructor(boards: Board[])
{
super(boards);
if (isSet !== undefined)
this.isSetStandardBoard = isSet;
}
get IsVail()
{
@ -90,61 +86,66 @@ export class SurroundSpaceParse extends SpaceParse
let lrBoards = this.boardMap.get(BoardType.Vertical);
if (lrBoards.length === 2)
{
let b1 = lrBoards[0].Clone() as Board;
let b2 = lrBoards[1].Clone() as Board;
let pt1 = lrBoards[0].Position.applyMatrix4(this.SpaceOCSInv);
let pt2 = lrBoards[1].Position.applyMatrix4(this.SpaceOCSInv);
b1.ApplyMatrix(new Matrix4().extractRotation(b1.BoardOCSInv));
b2.ApplyMatrix(new Matrix4().extractRotation(b2.BoardOCSInv));
[this.m_LeftBoard, this.m_RightBoard] =
pt1.x < pt2.x ? [lrBoards[0], lrBoards[1]] : [lrBoards[1], lrBoards[0]];
[this.m_LeftBoard, this.m_RightBoard, b1, b2] =
b1.Position.x < b2.Position.x ? [lrBoards[0], lrBoards[1], b1, b2] : [lrBoards[1], lrBoards[0], b2, b1];
if (this.ParseLRBoards(b1, b2))
if (this.ParseLRBoards())
{
let res = await this.GetStandardBoard(b1, b2);
let res = await this.GetStandardBoard();
//选择基准板错误
if (res)
{
this.m_IsVail = true;
this.ParseGeometry(b1, b2);
this.ParseGeometry();
}
}
else
this.m_IsVail = false;
}
}
ParseLRBoards(b1: Board, b2: Board)
ParseLRBoards()
{
if (b1 && b2)
if (this.m_LeftBoard && this.m_LeftBoard)
{
//左右侧板在世界空间位置
let pt1 = this.m_LeftBoard.Position.applyMatrix4(this.SpaceOCSInv);
let pt2 = this.m_RightBoard.Position.applyMatrix4(this.SpaceOCSInv);
// 左右侧板位置相等,无效
if (equalv3(b1.Position, b2.Position))
if (equalv3(pt1, pt2))
return false;
//左右侧板不平行,无效
if (!equaln(Math.abs(b1.Normal.dot(b2.Normal)), 1, 1e-6))
if (!equaln(Math.abs(this.m_LeftBoard.Normal.dot(this.m_RightBoard.Normal)), 1, 1e-6))
{
return false;
}
let lMinPt = b1.MinPoint;
let rMinPt = b2.MinPoint;
//左右侧板在世界空间最左下角点
let lMinPt = this.m_LeftBoard.MinPoint.applyMatrix4(this.SpaceOCSInv);
let rMinPt = this.m_RightBoard.MinPoint.applyMatrix4(this.SpaceOCSInv);
return Math.abs(lMinPt.x + rMinPt.x) > Math.max(b1.Thickness, b2.Thickness)
&& Math.abs(lMinPt.y - rMinPt.y) + 1e-6 < Math.max(b1.Width, b2.Width)
&& Math.abs(lMinPt.z - rMinPt.z) + 1e-6 < Math.max(b1.Lenght, b2.Lenght);
return Math.abs(lMinPt.x + rMinPt.x) > Math.max(this.m_LeftBoard.Thickness, this.m_RightBoard.Thickness)
&& Math.abs(lMinPt.y - rMinPt.y) + 1e-6 < Math.max(this.m_LeftBoard.Width, this.m_RightBoard.Width)
&& Math.abs(lMinPt.z - rMinPt.z) + 1e-6 < Math.max(this.m_LeftBoard.Lenght, this.m_RightBoard.Lenght);
}
return false;
}
ParseGeometry(b1: Board, b2: Board)
ParseGeometry()
{
let lMinPt = b1.MinPoint;
let rMinPt = b2.MinPoint;
let lMaxPt = b1.MaxPoint;
let rMaxPt = b2.MaxPoint;
//左右侧板在世界空间最左下角点
let lMinPt = this.m_LeftBoard.MinPoint.applyMatrix4(this.SpaceOCSInv);
let rMinPt = this.m_RightBoard.MinPoint.applyMatrix4(this.SpaceOCSInv);
//左右侧板在世界空间最右点
let lMaxPt = this.m_LeftBoard.MaxPoint.applyMatrix4(this.SpaceOCSInv);
let rMaxPt = this.m_RightBoard.MaxPoint.applyMatrix4(this.SpaceOCSInv);
//标准板点
let sMinPt: Vector3;
let sMaxPt: Vector3;
@ -152,9 +153,9 @@ export class SurroundSpaceParse extends SpaceParse
let dist = rMinPt.x - lMinPt.x;
//空间净长
this.m_Spacelength = dist - b1.Thickness;
this.m_Spacelength = dist - this.m_LeftBoard.Thickness;
//总宽
this.m_TotalLength = dist + b2.Thickness;
this.m_TotalLength = dist + this.m_RightBoard.Thickness;
//空间宽度
this.m_SpaceWidth = this.m_StandardBoard.Width;
@ -165,14 +166,14 @@ export class SurroundSpaceParse extends SpaceParse
[sMinPt, sMaxPt] = [lMinPt, lMaxPt];
this.m_BaseTopDownPoint = new Vector3(rMinPt.x, lMinPt.y);
this.m_BaseTopUpPoint = new Vector3(rMinPt.x + b2.Thickness, lMinPt.y);
this.m_BaseTopUpPoint = new Vector3(rMinPt.x + this.m_RightBoard.Thickness, lMinPt.y);
}
else
{
[sMinPt, sMaxPt] = [rMinPt, rMaxPt];
this.m_BaseTopDownPoint = new Vector3(rMinPt.x, rMinPt.y);
this.m_BaseTopUpPoint = new Vector3(rMinPt.x + b2.Thickness, rMinPt.y)
this.m_BaseTopUpPoint = new Vector3(rMinPt.x + this.m_RightBoard.Thickness, rMinPt.y)
}
this.m_BaseBottomUpPoint = this.m_BaseTopDownPoint.clone();
@ -185,12 +186,14 @@ export class SurroundSpaceParse extends SpaceParse
this.m_BaseBottomUpPoint.setZ(Math.max(lMinPt.z, rMinPt.z));
this.m_BaseBottomDownPoint.setZ(Math.min(lMinPt.z, rMinPt.z));
let pt1 = this.m_LeftBoard.Position.applyMatrix4(this.SpaceOCSInv);
//背板基点位置
this.m_BaseBehindPoint = new Vector3(b1.Position.x, Math.min(lMaxPt.y, rMaxPt.y), Math.min(lMinPt.z, rMinPt.z));
this.m_BaseBehindPoint = new Vector3(pt1.x, Math.min(lMaxPt.y, rMaxPt.y), Math.min(lMinPt.z, rMinPt.z));
//地脚板基点位置
this.m_BaseFootPoint = this.m_BaseBottomDownPoint.clone();
this.m_BaseFootPoint.setX(b1.Position.x);
this.m_BaseFootPoint.setX(pt1.x);
//背板长
this.m_BehindLength =
@ -202,30 +205,29 @@ export class SurroundSpaceParse extends SpaceParse
{
let behindBoard = behindBoards[0];
let b3 = behindBoard.Clone() as Board;
let behindNormal = b3.Normal;
let bMinPt = b3.MinPoint;
let behindNormal = behindBoard.Normal.applyMatrix4(this.SpaceOCSInv);
let bMinPt = behindBoard.MinPoint.applyMatrix4(this.SpaceOCSInv);
let lbNormal = this.m_LeftBoard.Normal.applyMatrix4(this.SpaceOCSInv);
//背板和左右侧板垂直
if (equaln(behindNormal.angleTo(b1.Normal), Math.PI / 2, 1e-6))
if (equaln(behindNormal.angleTo(lbNormal), Math.PI / 2, 1e-6))
{
if (bMinPt.y < sMaxPt.y - b3.Thickness && bMinPt.y > sMinPt.y + b3.Thickness)
if (bMinPt.y < sMaxPt.y - behindBoard.Thickness && bMinPt.y > sMinPt.y + behindBoard.Thickness)
{
// 背板在左右侧板上,更新空间的宽度
this.m_SpaceWidth = Math.abs(bMinPt.y - sMinPt.y + b3.Thickness)
this.m_SpaceWidth = Math.abs(bMinPt.y - sMinPt.y + behindBoard.Thickness)
}
}
}
}
async GetStandardBoard(b1: Board, b2: Board)
async GetStandardBoard()
{
let lMinPt = b1.MinPoint;
let rMinPt = b2.MinPoint;
let lMinPt = this.m_LeftBoard.MinPoint.applyMatrix4(this.SpaceOCSInv);
let rMinPt = this.m_RightBoard.MinPoint.applyMatrix4(this.SpaceOCSInv);
if ((equaln(lMinPt.y, rMinPt.y)
&& equaln(lMinPt.z, rMinPt.z)
&& equaln(b1.Width, b2.Width)
&& equaln(b1.Lenght, b2.Lenght))
|| !this.isSetStandardBoard
&& equaln(this.m_LeftBoard.Width, this.m_RightBoard.Width)
&& equaln(this.m_LeftBoard.Lenght, this.m_RightBoard.Lenght))
)
{
this.m_StandardBoard = this.m_LeftBoard;

Loading…
Cancel
Save