|
|
|
@ -6,6 +6,8 @@ import { Line } from "../../DatabaseServices/Line";
|
|
|
|
|
import { Box3Ext } from "../Box";
|
|
|
|
|
import { MoveMatrix, equal, equaln } from "../GeUtils";
|
|
|
|
|
import { testBox3 } from "../../Add-on/testEntity/TestCurve";
|
|
|
|
|
import { arrayLast } from "../../Common/ArrayExt";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*通用空间分析;类
|
|
|
|
@ -34,13 +36,211 @@ export class GeneralSpaceParse extends SpaceParse
|
|
|
|
|
this.parseBoards(boards, unionBoxes, spliteBoxes);
|
|
|
|
|
}
|
|
|
|
|
else if (boards.length === 1)
|
|
|
|
|
{
|
|
|
|
|
let b = boards[0].Clone() as Board;
|
|
|
|
|
b.ApplyMatrix(new Matrix4().extractRotation(b.BoardOCSInv))
|
|
|
|
|
let box = b.BoundingBox;
|
|
|
|
|
box.spliteType = boards[0].BoardType;
|
|
|
|
|
spliteBoxes.push(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.SpliteBoxs(this.MergeSpaces(unionBoxes) as Box3Ext, spliteBoxes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MergeSpaces(spaces: Box3Ext[])
|
|
|
|
|
{
|
|
|
|
|
let b1 = spaces.shift();
|
|
|
|
|
let isInt = false;
|
|
|
|
|
for (let box of spaces)
|
|
|
|
|
{
|
|
|
|
|
if (b1.intersectsBox(box))
|
|
|
|
|
{
|
|
|
|
|
isInt = true;
|
|
|
|
|
b1.intersect(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isInt && spaces.length === 2)
|
|
|
|
|
{
|
|
|
|
|
b1 = spaces[0];
|
|
|
|
|
let b2 = spaces[1];
|
|
|
|
|
if (b1.intersectsBox(b2))
|
|
|
|
|
{
|
|
|
|
|
return b1.intersect(b2);
|
|
|
|
|
}
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return b1;
|
|
|
|
|
}
|
|
|
|
|
private SpliteBoxs(box: Box3Ext, spliteBoxes: Box3Ext[])
|
|
|
|
|
{
|
|
|
|
|
if (spliteBoxes.length === 0)
|
|
|
|
|
this.m_Spaces = [box];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
let boxes = [box];
|
|
|
|
|
for (let i = 0; i < boxes.length; i++)
|
|
|
|
|
{
|
|
|
|
|
let box = boxes[i];
|
|
|
|
|
for (let j = 0; j < spliteBoxes.length; j++)
|
|
|
|
|
{
|
|
|
|
|
let bs = box.substract(spliteBoxes[j]);
|
|
|
|
|
if (bs.length > 0)
|
|
|
|
|
{
|
|
|
|
|
boxes.splice(i, 1, ...bs);
|
|
|
|
|
i -= (bs.length - 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (j === spliteBoxes.length - 1)
|
|
|
|
|
{
|
|
|
|
|
this.m_Spaces.push(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//分析2个盒子之间的空间
|
|
|
|
|
private parseBox3(b1: Box3Ext, b2: Box3Ext, boardType: BoardType)
|
|
|
|
|
{
|
|
|
|
|
let dist: number;
|
|
|
|
|
switch (boardType)
|
|
|
|
|
{
|
|
|
|
|
case BoardType.Layer:
|
|
|
|
|
return this.getSpace(b1, b2, "z");
|
|
|
|
|
case BoardType.Vertical:
|
|
|
|
|
return this.getSpace(b1, b2, "x");
|
|
|
|
|
case BoardType.Behind:
|
|
|
|
|
return this.getSpace(b1, b2, "y");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//获取2个盒子之间的空间
|
|
|
|
|
getSpace(b1: Box3Ext, b2: Box3Ext, axis: string)
|
|
|
|
|
{
|
|
|
|
|
[b1, b2] = b1.min[axis] < b2.min[axis] ? [b1, b2] : [b2, b1];
|
|
|
|
|
let dist = b2.min[axis] - b1.min[axis];
|
|
|
|
|
if (dist <= b1.getSize(new Vector3())[axis])
|
|
|
|
|
{
|
|
|
|
|
return new Box3Ext();
|
|
|
|
|
}
|
|
|
|
|
let vec = new Vector3();
|
|
|
|
|
vec[axis] = -dist;
|
|
|
|
|
b2.applyMatrix4(MoveMatrix(vec));
|
|
|
|
|
if (b1.intersectsBox(b2))
|
|
|
|
|
{
|
|
|
|
|
b1.intersect(b2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
b1.union(b2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let vec1 = new Vector3();
|
|
|
|
|
vec1[axis] = b1.getSize(new Vector3())[axis];
|
|
|
|
|
|
|
|
|
|
let vec2 = new Vector3();
|
|
|
|
|
vec2[axis] = dist - b2.getSize(new Vector3())[axis];
|
|
|
|
|
|
|
|
|
|
return new Box3Ext(b1.min.add(vec1), b1.max.add(vec2));
|
|
|
|
|
}
|
|
|
|
|
//分析多块板
|
|
|
|
|
private parseBoards(boards: Board[], uniSpaces: Box3Ext[], spliteSPs: Box3Ext[])
|
|
|
|
|
{
|
|
|
|
|
let boxMap: Map<Board, Box3Ext> = new Map();
|
|
|
|
|
|
|
|
|
|
for (let br of boards)
|
|
|
|
|
{
|
|
|
|
|
let b = br.Clone() as Board;
|
|
|
|
|
b.ApplyMatrix(new Matrix4().extractRotation(br.BoardOCSInv))
|
|
|
|
|
let box = b.BoundingBox;
|
|
|
|
|
boxMap.set(br, box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (boards[0].BoardType)
|
|
|
|
|
{
|
|
|
|
|
case BoardType.Layer:
|
|
|
|
|
this.sortAndMerge(boards, boxMap, "z");
|
|
|
|
|
break;
|
|
|
|
|
case BoardType.Vertical:
|
|
|
|
|
this.sortAndMerge(boards, boxMap, "x");
|
|
|
|
|
break;
|
|
|
|
|
case BoardType.Behind:
|
|
|
|
|
this.sortAndMerge(boards, boxMap, "y");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (boards.length >= 2)
|
|
|
|
|
{
|
|
|
|
|
let b1 = boards[0];
|
|
|
|
|
let box1 = boxMap.get(b1).clone();
|
|
|
|
|
let b2 = arrayLast(boards);
|
|
|
|
|
let box2 = boxMap.get(b2).clone();
|
|
|
|
|
|
|
|
|
|
let box = this.parseBox3(box1, box2, b1.BoardType)
|
|
|
|
|
if (!box.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
uniSpaces.push(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//排序归并板件
|
|
|
|
|
private sortAndMerge(boards: Board[], boxMap: Map<Board, Box3Ext>, type: string)
|
|
|
|
|
{
|
|
|
|
|
boards.sort((a, b) => boxMap.get(a).min[type] - boxMap.get(b).min[type]);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < boards.length; i++)
|
|
|
|
|
{
|
|
|
|
|
let b1 = boards[i];
|
|
|
|
|
let box1 = boxMap.get(b1);
|
|
|
|
|
for (let j = i + 1; j < boards.length; j++)
|
|
|
|
|
{
|
|
|
|
|
let b2 = boards[j];
|
|
|
|
|
let box2 = boxMap.get(b2);
|
|
|
|
|
if (equaln(box1.min[type], box2.min[type]))
|
|
|
|
|
{
|
|
|
|
|
let b = box1.clone();
|
|
|
|
|
box1.union(box2)
|
|
|
|
|
boards.splice(j, 1);
|
|
|
|
|
j--;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
i = j - 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class GeneralSpaceParse1 extends SpaceParse
|
|
|
|
|
{
|
|
|
|
|
private m_Spaces: Box3Ext[] = [];
|
|
|
|
|
get Spaces()
|
|
|
|
|
{
|
|
|
|
|
return this.m_Spaces;
|
|
|
|
|
}
|
|
|
|
|
SpaceParse()
|
|
|
|
|
{
|
|
|
|
|
super.SpaceParse();
|
|
|
|
|
let unionBoxes: Box3Ext[] = [];
|
|
|
|
|
let spliteBoxes: Box3Ext[] = [];
|
|
|
|
|
for (let key of this.boardMap.keys())
|
|
|
|
|
{
|
|
|
|
|
let boards = this.boardMap.get(key);
|
|
|
|
|
if (boards.length > 1)
|
|
|
|
|
{
|
|
|
|
|
// this.parseBoards(boards, unionBoxes, spliteBoxes);
|
|
|
|
|
this.parseBoards2(boards, unionBoxes, spliteBoxes);
|
|
|
|
|
}
|
|
|
|
|
else if (boards.length === 1)
|
|
|
|
|
{
|
|
|
|
|
let box = boards[0].BoundingBox as Box3Ext;
|
|
|
|
|
box.spliteType = boards[0].BoardType;
|
|
|
|
|
spliteBoxes.push(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.SpliteBoxs(this.MergeSpaces(unionBoxes), spliteBoxes);
|
|
|
|
|
// this.SpliteBoxs(this.MergeSpaces(unionBoxes), spliteBoxes);
|
|
|
|
|
this.SpliteBoxs2(unionBoxes, spliteBoxes);
|
|
|
|
|
}
|
|
|
|
|
private MergeSpaces(spaces: Box3Ext[])
|
|
|
|
|
{
|
|
|
|
@ -91,6 +291,31 @@ export class GeneralSpaceParse extends SpaceParse
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private SpliteBoxs2(boxes: Box3Ext[], spliteBoxes: Box3Ext[])
|
|
|
|
|
{
|
|
|
|
|
if (spliteBoxes.length === 0)
|
|
|
|
|
this.m_Spaces = boxes;
|
|
|
|
|
else
|
|
|
|
|
for (let i = 0; i < boxes.length; i++)
|
|
|
|
|
{
|
|
|
|
|
let box = boxes[i];
|
|
|
|
|
for (let j = 0; j < spliteBoxes.length; j++)
|
|
|
|
|
{
|
|
|
|
|
let bs = box.substract(spliteBoxes[j]);
|
|
|
|
|
if (bs.length > 1)
|
|
|
|
|
{
|
|
|
|
|
boxes.splice(i, 1, ...bs);
|
|
|
|
|
i -= (bs.length - 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (j === spliteBoxes.length - 1)
|
|
|
|
|
{
|
|
|
|
|
this.m_Spaces.push(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//分析2个盒子之间的空间
|
|
|
|
|
private parseBox3(b1: Box3Ext, b2: Box3Ext, boardType: BoardType)
|
|
|
|
@ -180,6 +405,81 @@ export class GeneralSpaceParse extends SpaceParse
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private parseBoards2(boards: Board[], uniSpaces: Box3Ext[], spliteSPs: Box3Ext[])
|
|
|
|
|
{
|
|
|
|
|
let boxMap: Map<Board, Box3Ext> = new Map();
|
|
|
|
|
|
|
|
|
|
for (let br of boards)
|
|
|
|
|
{
|
|
|
|
|
let box = br.BoundingBox as Box3Ext;
|
|
|
|
|
box.applyMatrix4(new Matrix4().extractRotation(br.BoardOCSInv));
|
|
|
|
|
boxMap.set(br, box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (boards[0].BoardType)
|
|
|
|
|
{
|
|
|
|
|
case BoardType.Layer:
|
|
|
|
|
this.sortAndMerge(boards, boxMap, "z");
|
|
|
|
|
break;
|
|
|
|
|
case BoardType.Vertical:
|
|
|
|
|
this.sortAndMerge(boards, boxMap, "x");
|
|
|
|
|
break;
|
|
|
|
|
case BoardType.Behind:
|
|
|
|
|
this.sortAndMerge(boards, boxMap, "y");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (boards.length === 1)
|
|
|
|
|
{
|
|
|
|
|
let box = boxMap.get(boards[0]);
|
|
|
|
|
box.spliteType = boards[0].BoardType;
|
|
|
|
|
spliteSPs.push(box);
|
|
|
|
|
}
|
|
|
|
|
if (uniSpaces.length === 0)
|
|
|
|
|
{
|
|
|
|
|
for (let i = 0; i < boards.length - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
let b1 = boards[i];
|
|
|
|
|
let box1 = boxMap.get(b1);
|
|
|
|
|
|
|
|
|
|
let b2 = boards[i + 1];
|
|
|
|
|
let box2 = boxMap.get(b2).clone();
|
|
|
|
|
let box = this.parseBox3(box1, box2, b1.BoardType)
|
|
|
|
|
if (!box.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
box.spliteType = b1.BoardType;
|
|
|
|
|
uniSpaces.push(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (let i = 0; i < boards.length - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
let b1 = boards[i];
|
|
|
|
|
let box1 = boxMap.get(b1);
|
|
|
|
|
let b2 = boards[i + 1];
|
|
|
|
|
let box2 = boxMap.get(b2).clone();
|
|
|
|
|
let box = this.parseBox3(box1.clone(), box2.clone(), b1.BoardType)
|
|
|
|
|
if (!box.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (uniSpaces.every(b => !b.intersectsBox(box)))
|
|
|
|
|
{
|
|
|
|
|
this.m_Spaces.push(box);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
box1.spliteType = b1.BoardType;
|
|
|
|
|
spliteSPs.push(box1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i === boards.length - 2)
|
|
|
|
|
{
|
|
|
|
|
box2.spliteType = b1.BoardType;
|
|
|
|
|
spliteSPs.push(box2)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//排序归并板件
|
|
|
|
|
private sortAndMerge(boards: Board[], boxMap: Map<Board, Box3Ext>, type: string)
|
|
|
|
@ -209,4 +509,7 @@ export class GeneralSpaceParse extends SpaceParse
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|