!220 修复排钻部分bug

Merge pull request !220 from ZoeLeeFZ/fixpz2
pull/220/MERGE
ChenX 6 years ago
parent bc7a347500
commit ec59f861ee

@ -209,6 +209,14 @@ export class DrawDrillingTool extends Singleton
for (let dist of this.m_MoveDistList)
{
if (this.drillEnts.length === 3)
{
let pos = this.drillEnts[2].Position
.applyMatrix4(MoveMatrix(new Vector3(dist)))
.applyMatrix4(this.m_Face.OCS);
if (this.CheckModelingCollision(pos))
continue;
}
//新的排钻列表
let newDrillEnts: ObjectId[] = []
for (let d of this.drillEnts)
@ -224,6 +232,27 @@ export class DrawDrillingTool extends Singleton
this.ParseDrillList(newDrillentList);
}
//排钻避开造型
private CheckModelingCollision(pos: Vector3)
{
let br = this.m_Face.m_LocalBoard;
let modelings = br.BoardModeling;
pos.applyMatrix4(br.OCSInv);
for (let m of modelings)
{
if (m.thickness === br.Thickness)
{
//TODO:暂先处理挖空的造型
let cu = m.shape.Outline.Curve;
pos.setZ(cu.Position.z);
if (cu.PtInCurve(pos))
{
return true;
}
}
}
return false;
}
// 分析当前排钻
private ParseDrillList(drills: ObjectId[][])
{
@ -240,9 +269,10 @@ export class DrawDrillingTool extends Singleton
let refDrillList: ObjectId[][] = [];
//加入本地的板件排钻测试通孔
for (let [, v] of locaBoard.DrillList)
for (let [id, v] of locaBoard.DrillList)
{
refDrillList.push(...v);
if (id)
refDrillList.push(...v);
}
if (refDrillList.length > 0)

@ -5,6 +5,15 @@ import { JigUtils } from "../Editor/JigUtils";
import { PromptStatus } from "../Editor/PromptResult";
import { MoveMatrix } from "../Geometry/GeUtils";
export function GetMirrorMat(v: Vector3)
{
let mirrorMat = new Matrix4();
let xAxis = new Vector3(1 - 2 * v.x ** 2, -2 * v.x * v.y, -2 * v.x * v.z);
let yAxis = new Vector3(-2 * v.x * v.y, 1 - 2 * v.y ** 2, -2 * v.y * v.z);
let zAxis = new Vector3(-2 * v.x * v.z, -2 * v.y * v.z, 1 - 2 * v.z ** 2);
mirrorMat.makeBasis(xAxis, yAxis, zAxis);
return mirrorMat;
}
export class MirrorCommand implements Command
{
async exec()
@ -33,7 +42,7 @@ export class MirrorCommand implements Command
JigUtils.Restore();
let rot = new Matrix4().makeRotationAxis(p1.clone().cross(v).normalize(), Math.PI / 2);
let vec = v.clone().sub(p1).applyMatrix4(rot).normalize();
let newMat = this.GetMirrorMat(vec);
let newMat = GetMirrorMat(vec);
cloneEns.forEach(en =>
{
en.ApplyMatrix(MoveMatrix(p1.clone().negate()))
@ -57,13 +66,4 @@ export class MirrorCommand implements Command
ens.forEach(en => en.Erase());
cloneEns.forEach(en => app.m_Database.ModelSpace.Append(en));
}
GetMirrorMat(v: Vector3)
{
let mirrorMat = new Matrix4();
let xAxis = new Vector3(1 - 2 * v.x ** 2, -2 * v.x * v.y, -2 * v.x * v.z);
let yAxis = new Vector3(-2 * v.x * v.y, 1 - 2 * v.y ** 2, -2 * v.y * v.z);
let zAxis = new Vector3(-2 * v.x * v.z, -2 * v.y * v.z, 1 - 2 * v.z ** 2);
mirrorMat.makeBasis(xAxis, yAxis, zAxis);
return mirrorMat;
}
}

@ -42,7 +42,7 @@ export function matrixAlignCoordSys(matrixFrom: Matrix4, matrixTo: Matrix4): Mat
* @param {Matrix4} matrixTo
* @returns {boolean} 2
*/
export function matrixIsCoplane(matrixFrom: Matrix4, matrixTo: Matrix4): boolean
export function matrixIsCoplane(matrixFrom: Matrix4, matrixTo: Matrix4, fuzz = 1e-5): boolean
{
let nor1 = new Vector3().setFromMatrixColumn(matrixFrom, 2);
let nor2 = new Vector3().setFromMatrixColumn(matrixTo, 2);
@ -56,7 +56,7 @@ export function matrixIsCoplane(matrixFrom: Matrix4, matrixTo: Matrix4): boolean
//变换到自身对象坐标系.
pt.applyMatrix4(new Matrix4().getInverse(matrixFrom));
return equaln(pt.z, 0);
return equaln(pt.z, 0, fuzz);
}
//构造缩放矩阵

@ -385,7 +385,7 @@ export class Board extends Entity
{
let refArea = this.m_Length * this.m_Width;
let cuArea = this.m_Shape.Outline.Area;
return !equaln(refArea, cuArea);
return !equaln(refArea, cuArea, 1);
}
get Name()
{

@ -1,4 +1,5 @@
import { Matrix4, Vector3 } from "three";
import { GetMirrorMat } from "../../Add-on/Mirror";
import { arrayLast } from "../../Common/ArrayExt";
import { matrixIsCoplane } from "../../Common/Matrix4Utils";
import { Board } from "../../DatabaseServices/Board";
@ -50,9 +51,9 @@ export class BoardGetFace
let size = box.getSize(new Vector3());
let reg: Region;
let isRect = this.IsRect(curve);
if (isRect)
reg = Region.CreateFromCurves([this.m_Board.Shape.Outline.Curve]);
let isRect = !this.m_Board.IsSpecialShape;
if (!isRect)
reg = Region.CreateFromCurves([curve]);
let thickness = this.m_Board.Thickness;
let ocs = this.m_Board.OCS;
@ -62,20 +63,19 @@ export class BoardGetFace
region: reg,
isRect,
localBoard: this.m_Board,
IsPositiveFace: true,
isPositiveFace: true,
matrix4: ocs.clone(),
length: size.x,
width: size.y
}));
let mat = new Matrix4().makeBasis(new Vector3(-1), new Vector3(0, -1), new Vector3(0, 0, -1))
.setPosition(new Vector3(this.m_Board.Width, this.m_Board.Length, -thickness));
let mat = GetMirrorMat(cZAxis).setPosition(new Vector3(0, 0, -thickness));
this.m_Faces.push(new Face({
type: BoardFaceType.NoSide,
localBoard: this.m_Board,
isRect,
region: reg ? reg.Clone() : undefined,
IsPositiveFace: false,
isPositiveFace: false,
matrix4: new Matrix4().multiplyMatrices(ocs.clone(), mat),
length: size.x,
width: size.y
@ -104,7 +104,7 @@ export class BoardGetFace
this.m_Faces.push(new Face({
type: BoardFaceType.Side,
localBoard: this.m_Board,
IsPositiveFace: derv.x + derv.y + derv.z > 0,
isPositiveFace: derv.x + derv.y + derv.z > 0,
matrix4: new Matrix4().multiplyMatrices(this.m_Board.OCS.clone(), mat),
length: len,
width: this.m_Board.Thickness
@ -129,9 +129,12 @@ export class BoardGetFace
if (f1.type === BoardFaceType.NoSide || !bInsEqual)
continue;
//不共面
if (!matrixIsCoplane(f1.OCS, f2.OCS))
if (!matrixIsCoplane(f1.OCS, f2.OCS, 1e-4))
continue;
let nor1 = new Vector3().setFromMatrixColumn(f1.OCS, 2);
let nor2 = new Vector3().setFromMatrixColumn(f2.OCS, 2);
if (equalv3(nor1, nor2, 1e-6))
continue;
let interFace = f1.Intersect(f2);
if (interFace)
collisionFaces.push(interFace);

@ -4,7 +4,7 @@ import { Line } from "../../DatabaseServices/Line";
import { Region } from "../../DatabaseServices/Region";
import { BoolOpeartionType } from "../../GraphicsSystem/BoolOperateUtils";
import { Box3Ext } from "../Box";
import { equaln, cXAxis } from "../GeUtils";
import { cXAxis, equaln } from "../GeUtils";
import { BoardFaceType } from "./BoardGetFace";
export interface BoardFaceParams
@ -13,7 +13,7 @@ export interface BoardFaceParams
length: number;
width: number;
localBoard: Board;
IsPositiveFace: boolean;
isPositiveFace: boolean;
matrix4: Matrix4;
region?: Region;
isRect?: boolean;
@ -30,18 +30,19 @@ export class Face
isEqualType: boolean = false;
OCS: Matrix4 = new Matrix4();
m_IsRect: boolean = true;
constructor(opt?: BoardFaceParams)
constructor(parameters?: BoardFaceParams)
{
if (opt)
if (parameters)
{
this.type = opt.type;
this.m_Region = opt.region;
this.m_LocalBoard = opt.localBoard;
this.IsPositiveFace = opt.IsPositiveFace;
opt.matrix4 && this.OCS.copy(opt.matrix4);
this.m_Length = opt.length;
this.m_Width = opt.width;
this.m_IsRect = opt.isRect ? opt.isRect : true;
this.type = parameters.type;
this.m_Region = parameters.region;
this.m_LocalBoard = parameters.localBoard;
this.IsPositiveFace = parameters.isPositiveFace;
parameters.matrix4 && this.OCS.copy(parameters.matrix4);
this.m_Length = parameters.length;
this.m_Width = parameters.width;
if (parameters.isRect !== undefined)
this.m_IsRect = parameters.isRect;
}
}
get IsRect()
@ -94,7 +95,7 @@ export class Face
if (!noSideFace.IsRect || !canUseBoxCalc)
{
let sideReg = sideFace.Region;
isSuccess = sideReg.BooleanOper(noSideFace.m_Region.ApplyMatrix(diffMat), BoolOpeartionType.Intersection);
isSuccess = sideReg.BooleanOper(noSideFace.Region.Clone().ApplyMatrix(diffMat), BoolOpeartionType.Intersection);
retBox = sideReg.BoundingBox as Box3Ext;
size = retBox.getSize(new Vector3());
}

Loading…
Cancel
Save