重构清理板件空间分析的代码

pull/113/head
ChenX 6 years ago
parent cae8e31bcb
commit fd6b13dec7

@ -0,0 +1,14 @@
import { Box3Ext } from "../../src/Geometry/Box"
import { Vector3 } from "three";
test('盒子相减', () =>
{
let b = new Box3Ext(new Vector3(), new Vector3(100, 100, 100));
let b2 = new Box3Ext(new Vector3(200, 0, 0), new Vector3(205, 10, 300));
let bs = b.substract(b2, 0);
expect(bs.length).toBe(0);
});

@ -8,7 +8,7 @@ import { GenerateRaycaster } from '../../Editor/PointPick';
import { PromptStatus } from '../../Editor/PromptResult'; import { PromptStatus } from '../../Editor/PromptResult';
import { Box3Ext } from '../../Geometry/Box'; import { Box3Ext } from '../../Geometry/Box';
import { equaln } from '../../Geometry/GeUtils'; import { equaln } from '../../Geometry/GeUtils';
import { GeneralSpaceParse, GeneralSpaceParse2 } from '../../Geometry/SpaceParse/GeneralSpaceParse'; import { GeneralSpaceParse } from '../../Geometry/SpaceParse/GeneralSpaceParse';
import { PointPickSpaceParse } from '../../Geometry/SpaceParse/PointPickSpaceParse'; import { PointPickSpaceParse } from '../../Geometry/SpaceParse/PointPickSpaceParse';
import { BoardModal, BoardModalType } from '../../UI/Components/Board/BoardModal'; import { BoardModal, BoardModalType } from '../../UI/Components/Board/BoardModal';
import { ModalPosition } from '../../UI/Components/Modal/ModalsManage'; import { ModalPosition } from '../../UI/Components/Modal/ModalsManage';
@ -192,32 +192,32 @@ export abstract class DrawBoardTool implements Command
let boardCus = exSsRes.SelectSet.SelectEntityList.filter(en => let boardCus = exSsRes.SelectSet.SelectEntityList.filter(en =>
en instanceof Board) as Board[]; en instanceof Board) as Board[];
if (boardCus.length > 0) // if (boardCus.length > 0)
{ // {
let spaceParse = new GeneralSpaceParse2(boardCus); // let spaceParse = new GeneralSpaceParse2(boardCus);
spaceParse.SpaceParse(); // spaceParse.SpaceParse();
if (spaceParse.Spaces.length === 0) // if (spaceParse.Spaces.length === 0)
{ // {
app.m_Editor.Prompt("生成板件失败"); // app.m_Editor.Prompt("生成板件失败");
return; // return;
} // }
let ro = new Matrix4().extractRotation(spaceParse.SpaceOCS); // let ro = new Matrix4().extractRotation(spaceParse.SpaceOCS);
let spaces = spaceParse.Spaces; // let spaces = spaceParse.Spaces;
for (let box of spaces) // for (let box of spaces)
{ // {
this.buildBoard(box, ro, // this.buildBoard(box, ro,
{ // {
boardConfig: this.store.m_BoardOption, // boardConfig: this.store.m_BoardOption,
boardProcess: this.store.m_BoardProcessOption // boardProcess: this.store.m_BoardProcessOption
}); // });
} // }
} // }
else // else
{ // {
app.m_Editor.Prompt("请选择板件") // app.m_Editor.Prompt("请选择板件")
} // }
} }
async selectBox(spaces: Box3Ext[]) async selectBox(spaces: Box3Ext[])

@ -81,7 +81,7 @@ export function arraySortByNumber<T>(arr: Array<T>): Array<T>
* @param {(e1, e2) => boolean} [checkFuction] * @param {(e1, e2) => boolean} [checkFuction]
* @returns {Array<T>} * @returns {Array<T>}
*/ */
export function arrayRemoveDuplicateBySort<T>(arr: Array<T>, checkFuction: (e1, e2) => boolean = checkEqual): Array<T> export function arrayRemoveDuplicateBySort<T>(arr: Array<T>, checkFuction: (e1: T, e2: T) => boolean = checkEqual): Array<T>
{ {
if (arr.length < 2) return arr; if (arr.length < 2) return arr;
let j = 1; let j = 1;
@ -92,6 +92,34 @@ export function arrayRemoveDuplicateBySort<T>(arr: Array<T>, checkFuction: (e1,
return arr; return arr;
} }
/**
*
* @param {(e1, e2) => boolean} [checkFuction]
* @returns {Array<T>}
*/
export function arrayRemoveDuplicateBySort2<T>(arr: Array<T>, checkFuction: (e1: T, e2: T) => boolean = checkEqual): Array<T>
{
if (arr.length < 2) return arr;
let pre = arr[0],
newArr = [pre],
now: T;
for (let i = 1, len = arr.length; i < len; i++)
{
now = arr[i];
if (!checkEqual(now, pre))
{
newArr.push(now);
pre = now;
}
}
if (pre !== now) newArr.push(now);
return newArr;
}
//原地更新数组,注意这个函数并不会比map快. //原地更新数组,注意这个函数并不会比map快.
export function arrayMap<T>(arr: Array<T>, mapFunc: (v: T) => T): Array<T> export function arrayMap<T>(arr: Array<T>, mapFunc: (v: T) => T): Array<T>
{ {

@ -20,6 +20,20 @@ export enum BoardType
Behind = 2 //背板 Behind = 2 //背板
} }
//转换板件类型成为空间类型. 0x 1y 2z
export function ConverBoardTypeToSpaceType(type: BoardType): number
{
switch (type)
{
case BoardType.Layer:
return 2;
case BoardType.Vertical:
return 0;
case BoardType.Behind:
return 1;
}
}
/** /**
* *
* *

@ -1,6 +1,14 @@
import { Vector3, Box3 } from 'three'; import { Vector3, Box3 } from 'three';
import { BoardType } from '../DatabaseServices/Board';
import { equaln } from './GeUtils'; /**
*
*/
export enum SplitType
{
X = 0,
Y = 1,
Z = 2,
}
/** /**
* Box3,, * Box3,,
@ -11,47 +19,40 @@ import { equaln } from './GeUtils';
*/ */
export class Box3Ext extends Box3 export class Box3Ext extends Box3
{ {
//FIXME: 这个类型不应该出现在这里,非必要属性
//切割类型
spliteType: BoardType;
get Volume() get Volume()
{ {
let size = this.getSize(new Vector3()); let size = this.getSize(new Vector3());
return size.x * size.y * size.z; return size.x * size.y * size.z;
} }
substract(b: Box3Ext)
//每个轴的大小必须大于最小的size
isSolid(minSize = 1)
{
return this.getSize(new Vector3()).toArray().every(x => x > minSize);
}
substract(b: Box3Ext, spaceType: SplitType)
{ {
let boxes: Box3Ext[] = []; let interBox = this.clone().intersect(b) as this;
if (this.intersectsBox(b)) if (interBox.isEmpty() || !interBox.isSolid())
{ return [this];
let box1 = this.clone();
box1.intersect(b);
let max = box1.max;
let min = box1.min;
switch (b.spliteType) let b1Max = this.max.clone().setComponent(spaceType, interBox.min.getComponent(spaceType));
{ let b2Min = this.min.clone().setComponent(spaceType, interBox.max.getComponent(spaceType));
case BoardType.Vertical:
boxes = [ return [
new Box3Ext(min.clone().setX(this.min.x), max.clone().setX(min.x)), new Box3Ext(this.min, b1Max),
new Box3Ext(min.clone().setX(max.x), max.clone().setX(this.max.x)) new Box3Ext(b2Min, this.max)
]; ].filter(b => b.isSolid());
break; }
case BoardType.Behind: clampSpace(b2: Box3Ext, splitType: SplitType)
boxes = [ {
new Box3Ext(min.clone().setY(this.min.y), max.clone().setY(min.y)), let interBox = this.clone();
new Box3Ext(min.clone().setY(max.y), max.clone().setY(this.max.y)) interBox.min.max(b2.min);
]; interBox.max.min(b2.max);
break; interBox.min.setComponent(splitType, Math.min(this.max.getComponent(splitType), b2.max.getComponent(splitType)));
case BoardType.Layer: interBox.max.setComponent(splitType, Math.max(this.min.getComponent(splitType), b2.min.getComponent(splitType)));
boxes = [ return interBox;
new Box3Ext(min.clone().setZ(max.z), max.clone().setZ(this.max.z)),
new Box3Ext(min.clone().setZ(this.min.z), max.clone().setZ(min.z))
];
break;
}
}
return boxes.filter(b => !b.isEmpty() && !equaln(b.Volume, 0, 1e-6))
} }
intersectsBox(b: Box3) intersectsBox(b: Box3)
{ {

@ -1,8 +1,8 @@
import { Matrix4, Vector3 } from "three"; import { Vector3 } from "three";
import { arrayLast } from "../../Common/ArrayExt"; import { arrayLast, arrayRemoveDuplicateBySort2 } from "../../Common/ArrayExt";
import { Board, BoardType } from "../../DatabaseServices/Board"; import { Board, ConverBoardTypeToSpaceType } from "../../DatabaseServices/Board";
import { Box3Ext } from "../Box"; import { Box3Ext, SplitType } from "../Box";
import { equaln, MoveMatrix } from "../GeUtils"; import { equaln } from "../GeUtils";
import { SpaceParse } from "./SpaceParse"; import { SpaceParse } from "./SpaceParse";
/** /**
@ -24,436 +24,304 @@ export class GeneralSpaceParse extends SpaceParse
async SpaceParse() async SpaceParse()
{ {
await super.SpaceParse(); await super.SpaceParse();
let unionBoxes: Box3Ext[] = []; let unionBoxCol: Box3Ext[] = [];
let spliteBoxes: Box3Ext[] = []; let spliteBoxs = new Map<SplitType, Box3Ext>();
for (let key of this.boardMap.keys()) for (let [boardType, boards] of this.boardMap)
{ {
let boards = this.boardMap.get(key); let splitType: SplitType = ConverBoardTypeToSpaceType(boardType);
if (boards.length > 1) let boardBoxCol = this.ParseBoardBoxOfSortAndCombin(boards, splitType);
{
this.parseBoards(boards, unionBoxes);
}
else if (boards.length === 1)
{
let box = boards[0].GetBoardBoxInMat(this.SpaceOCSInv);
box.spliteType = boards[0].BoardType;
spliteBoxes.push(box);
}
}
if (unionBoxes.length > 0) if (boardBoxCol.length > 1)
{
let spaces = this.MergeSpaces(unionBoxes) as Box3Ext;
spaces && this.SpliteBoxs(spaces, spliteBoxes);
}
else if (spliteBoxes.length > 0)
{
let box = new Box3Ext()
spliteBoxes.reduce((b1, b2) => <Box3Ext>b1.union(<Box3Ext>b2), box);
this.SpliteBoxs(box, spliteBoxes);
}
}
/**
*
* 3
* @param spaces
* @returns
*/
private MergeSpaces(spaces: Box3Ext[])
{
if (spaces.length === 0) return undefined;
let b1 = spaces.shift();
let isInt = false;
for (let box of spaces)
{
if (b1.intersectsBox(box))
{ {
isInt = true; let clampBox = boardBoxCol[0].clampSpace(arrayLast(boardBoxCol), splitType);
b1.intersect(box); if (clampBox.isSolid())
unionBoxCol.push(clampBox);
} }
} else if (boardBoxCol.length === 1)
if (!isInt && spaces.length === 2)
{
b1 = spaces[0];
let b2 = spaces[1];
if (b1.intersectsBox(b2))
{ {
return b1.intersect(b2); spliteBoxs.set(splitType, boardBoxCol[0]);
} }
return undefined;
} }
return b1; let allSpaceBox: Box3Ext;
} if (unionBoxCol.length === 0)
/**
*
*/
private SpliteBoxs(box: Box3Ext, spliteBoxes: Box3Ext[])
{
if (spliteBoxes.length === 0)
this.m_Spaces = [box];
else
{ {
let boxes = [box]; allSpaceBox = new Box3Ext();
for (let i = 0; i < boxes.length; i++) spliteBoxs.forEach((box) => { allSpaceBox.union(box) });
{
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--;
if (i === boxes.length - 1 && j === spliteBoxes.length - 1)
{
this.m_Spaces.push(...bs);
}
break;
}
else if (j === spliteBoxes.length - 1)
{
this.m_Spaces.push(box);
}
}
}
}
}
/**
*2
* @param {Box3Ext} b1
* @param {Box3Ext} b2
* @param {BoardType} boardType
* @returns
*/
private parseBox3(b1: Box3Ext, b2: Box3Ext, boardType: BoardType)
{
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 else
{ {
b1.union(b2); allSpaceBox = unionBoxCol[0];
for (let i = 1, len = unionBoxCol.length; i < len; i++)
allSpaceBox.intersect(unionBoxCol[i]);
} }
let vec1 = new Vector3(); this.SpliteBoxs(allSpaceBox, spliteBoxs);
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));
} }
/**
*,
*2,22
* @private
* @param {Board[]} boards
* @param {Box3Ext[]} uniSpaces
* @memberof GeneralSpaceParse
*/
private parseBoards(boards: Board[], uniSpaces: Box3Ext[])
{
let boxMap: Map<Board, Box3Ext> = new Map();
for (let br of boards)
{
let box = br.GetBoardBoxInMat(this.SpaceOCSInv);
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) //解析板件的盒子,已经排序并且归并.
{ private ParseBoardBoxOfSortAndCombin(boardCol: Board[], splitType: SplitType)
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]); let boxCol = boardCol.map(b => { return b.GetBoardBoxInMat(this.SpaceOCSInv) });
for (let i = 0; i < boards.length; i++) //根据分割类型排序
boxCol.sort((b1, b2) =>
{ {
let b1 = boards[i]; return b1.min.getComponent(splitType) - b2.min.getComponent(splitType);
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;
}
}
}
}
}
//归并盒子
/** let boxComCol: Box3Ext[] = arrayRemoveDuplicateBySort2(boxCol,
* (b1, b2) =>
*
* @export
* @class GeneralSpaceParse2
* @extends {SpaceParse}
*/
export class GeneralSpaceParse2 extends SpaceParse
{
get Spaces()
{
return this.m_Spaces;
}
async 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);
}
else if (boards.length === 1)
{
let box = boards[0].BoundingBox as Box3Ext;
box.spliteType = boards[0].BoardType;
spliteBoxes.push(box);
}
}
this.SpliteBoxs(unionBoxes, spliteBoxes);
}
private SpliteBoxs(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]; if (
for (let j = 0; j < spliteBoxes.length; j++) //对齐
equaln(
b1.min.getComponent(splitType),
b2.min.getComponent(splitType),
)
&&
//厚度相等
equaln(
b1.getSize(new Vector3()).getComponent(splitType),
b2.getSize(new Vector3()).getComponent(splitType)
)
)
{ {
let bs = box.substract(spliteBoxes[j]); b1.union(b2);
if (bs.length > 1) return true;
{
boxes.splice(i, 1, ...bs);
i -= (bs.length - 1);
break;
}
else if (j === spliteBoxes.length - 1)
{
this.m_Spaces.push(box);
}
} }
return false;
} }
);
return boxComCol;
} }
//分析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 SpliteBoxs(box: Box3Ext, spliteBoxes: Map<SplitType, Box3Ext>)
}
//分析多块板
private parseBoards(boards: Board[], uniSpaces: Box3Ext[], spliteSPs: Box3Ext[])
{ {
let boxMap: Map<Board, Box3Ext> = new Map(); if (spliteBoxes.size === 0)
this.m_Spaces = [box];
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())
{
uniSpaces.push(box);
}
}
}
else else
{ {
for (let i = 0; i < boards.length - 1; i++) let orgBoxs = [box];
for (let [splitType, spBox] of spliteBoxes)
{ {
let b1 = boards[i]; let remBoxs: Box3Ext[] = [];
let box1 = boxMap.get(b1); for (let b of orgBoxs)
let b2 = boards[i + 1]; remBoxs.push(...b.substract(spBox, splitType));
let box2 = boxMap.get(b2).clone(); orgBoxs = remBoxs;
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;
}
spliteSPs.push(box1)
}
if (i === boards.length - 2)
{
spliteSPs.push(box2)
}
}
}
}
//排序归并板件
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;
}
} }
this.m_Spaces = orgBoxs;
} }
} }
} }
// /**
// *用于分析出全部空间
// * 待完善优化,暂留
// * @export
// * @class GeneralSpaceParse2
// * @extends {SpaceParse}
// */
// export class GeneralSpaceParse2 extends SpaceParse
// {
// get Spaces()
// {
// return this.m_Spaces;
// }
// async 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);
// }
// else if (boards.length === 1)
// {
// let box = boards[0].BoundingBox as Box3Ext;
// spliteBoxes.push(box);
// }
// }
// this.SpliteBoxs(unionBoxes, spliteBoxes);
// }
// private SpliteBoxs(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)
// {
// 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 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())
// {
// 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;
// }
// spliteSPs.push(box1)
// }
// if (i === boards.length - 2)
// {
// spliteSPs.push(box2)
// }
// }
// }
// }
// //排序归并板件
// 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;
// }
// }
// }
// }
// }

@ -79,14 +79,11 @@ export function PointPickSpaceParse(ptVcs: Vector3, view: Viewer, objectCol: Obj
if (selectBoardCol.includes(br)) if (selectBoardCol.includes(br))
return false; return false;
//根据Orbit的规则,应该是如下过滤. //根据Orbit的规则,如果按X轴选择,则不选择层板
if (i % 2 === 0) if (i % 2 === 0 && br.BoardType === BoardType.Layer)
{ return false;
if (br.BoardType === BoardType.Vertical)
return true; return true;
}
else if (br.BoardType === BoardType.Layer)
return true;
} }
return false; return false;
} }

@ -59,13 +59,9 @@ export class SpaceParse
{ {
let tmpList = this.boardMap.get(b.BoardType); let tmpList = this.boardMap.get(b.BoardType);
if (!tmpList) if (!tmpList)
{
this.boardMap.set(b.BoardType, [b]) this.boardMap.set(b.BoardType, [b])
}
else else
{
tmpList.push(b); tmpList.push(b);
}
} }
} }
} }

Loading…
Cancel
Save