mirror of https://gitee.com/cf-fz/WebCAD.git
!745 正确的显示板件造型
parent
99783c90e7
commit
89dc6da05e
File diff suppressed because one or more lines are too long
@ -0,0 +1,122 @@
|
|||||||
|
import { Vector3 } from "three";
|
||||||
|
import { TestDraw } from "./TestUtil";
|
||||||
|
import { app } from "../../ApplicationServices/Application";
|
||||||
|
import { Board } from "../../DatabaseServices/Entity/Board";
|
||||||
|
import { PromptStatus } from "../../Editor/PromptResult";
|
||||||
|
import { HotCMD } from "../../Hot/HotCommand";
|
||||||
|
import { MoveMatrix } from "../../Geometry/GeUtils";
|
||||||
|
import { ExtrudeGeometryBuilder } from "../../Geometry/ExtrudeEdgeGeometry2";
|
||||||
|
@HotCMD
|
||||||
|
export class Command_TestTape
|
||||||
|
{
|
||||||
|
async exec()
|
||||||
|
{
|
||||||
|
let enRes = await app.Editor.GetEntity({ Filter: { filterTypes: [Board] } });
|
||||||
|
if (enRes.Status !== PromptStatus.OK)
|
||||||
|
return;
|
||||||
|
let br = enRes.Entity as Board;
|
||||||
|
let geo = new ExtrudeGeometryBuilder(br);
|
||||||
|
return;
|
||||||
|
let k = 0;
|
||||||
|
let i = 1;
|
||||||
|
let testOut = true;
|
||||||
|
for (let s of geo.shapes)
|
||||||
|
{
|
||||||
|
if (testOut)
|
||||||
|
{
|
||||||
|
let m = MoveMatrix(new Vector3(0, k * 20));
|
||||||
|
for (let t of s.contour.Tape)
|
||||||
|
{
|
||||||
|
t.Curve.ApplyMatrix(m);
|
||||||
|
TestDraw(t.Curve, s.depth);
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (let w of s.holes)
|
||||||
|
{
|
||||||
|
let m = MoveMatrix(new Vector3(0, k * 20));
|
||||||
|
for (let t of w.Tape)
|
||||||
|
{
|
||||||
|
t.Curve.ApplyMatrix(m);
|
||||||
|
TestDraw(t.Curve, w.depth);
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// let gs = br.Grooves;
|
||||||
|
// let brOcsInv = br.OCSInv;
|
||||||
|
// let alm = new Matrix4;
|
||||||
|
// let ws = gs.map(g =>
|
||||||
|
// {
|
||||||
|
// alm.multiplyMatrices(brOcsInv, g.OCSNoClone);
|
||||||
|
// let type: DepthType;
|
||||||
|
// if (equaln(g.Thickness, br.Thickness))
|
||||||
|
// type = DepthType.All;
|
||||||
|
// else if (equaln(g.Position.applyMatrix4(brOcsInv).z, 0))
|
||||||
|
// type = DepthType.Back;
|
||||||
|
// else
|
||||||
|
// type = DepthType.Front;
|
||||||
|
// //槽轮廓
|
||||||
|
// let gContour = g.ContourCurve.Clone();
|
||||||
|
// gContour.ApplyMatrix(alm);
|
||||||
|
// gContour.Z0();
|
||||||
|
// let holes: ExtureContourCurve[] = [];
|
||||||
|
// //孤岛
|
||||||
|
// for (let gg of g.Grooves)
|
||||||
|
// {
|
||||||
|
// let c = gg.ContourCurve.Clone();
|
||||||
|
// alm.multiplyMatrices(brOcsInv, gg.OCSNoClone);
|
||||||
|
// c.ApplyMatrix(alm).Z0();
|
||||||
|
// holes.push(c);
|
||||||
|
// }
|
||||||
|
// let s = new ExtrudeWallShape(gContour, holes, type, g.Thickness, br.Thickness);
|
||||||
|
// return s;
|
||||||
|
// });
|
||||||
|
// let brS = new ExtrudeWallShape(br.ContourCurve.Clone(), [], DepthType.All, br.Thickness, br.Thickness);
|
||||||
|
// brS.contour.wallType = WallType.Outer;
|
||||||
|
// let k = 0;
|
||||||
|
// for (let i = 0; i < ws.length; i++)
|
||||||
|
// {
|
||||||
|
// let w1 = ws[i];
|
||||||
|
// brS.Clip(w1, false);
|
||||||
|
// for (let j = i + 1; j < ws.length; j++)
|
||||||
|
// {
|
||||||
|
// let w2 = ws[j];
|
||||||
|
// w1.Clip(w2);
|
||||||
|
// }
|
||||||
|
// for (let c of [w1.contour, ...w1.holes])
|
||||||
|
// {
|
||||||
|
// let m = MoveMatrix(new Vector3(0, k * 20));
|
||||||
|
// k++;
|
||||||
|
// for (let tape of c.Tape)
|
||||||
|
// {
|
||||||
|
// let en = tape.Curve.Clone();
|
||||||
|
// en.ApplyMatrix(m);
|
||||||
|
// TestDraw(en, w1.depth);
|
||||||
|
// }
|
||||||
|
// let mesh = c.ToMesh();
|
||||||
|
// mesh.applyMatrix4(br.OCS);
|
||||||
|
// mesh.updateMatrixWorld(true);
|
||||||
|
// TestDraw(mesh, w1.depth);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// for (let c of [brS.contour])
|
||||||
|
// {
|
||||||
|
// let m = MoveMatrix(new Vector3(0, k * 20));
|
||||||
|
// k++;
|
||||||
|
// for (let tape of c.Tape)
|
||||||
|
// {
|
||||||
|
// let en = tape.Curve.Clone();
|
||||||
|
// en.ApplyMatrix(m);
|
||||||
|
// TestDraw(en, br.Thickness);
|
||||||
|
// }
|
||||||
|
// let mesh = c.ToMesh();
|
||||||
|
// mesh.applyMatrix4(br.OCS);
|
||||||
|
// mesh.updateMatrixWorld(true);
|
||||||
|
// TestDraw(mesh, br.Thickness);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,200 @@
|
|||||||
|
import { Matrix4, Shape as TShape } from "three";
|
||||||
|
import { Contour } from "../DatabaseServices/Contour";
|
||||||
|
import { Circle } from "../DatabaseServices/Entity/Circle";
|
||||||
|
import { Curve } from "../DatabaseServices/Entity/Curve";
|
||||||
|
import { ExtrudeSolid, ExtureContourCurve } from "../DatabaseServices/Entity/Extrude";
|
||||||
|
import { Polyline } from "../DatabaseServices/Entity/Polyline";
|
||||||
|
import { equaln } from "./GeUtils";
|
||||||
|
|
||||||
|
/*
|
||||||
|
1.绘制正反面
|
||||||
|
|
||||||
|
2.绘制槽的面
|
||||||
|
|
||||||
|
3.绘制侧面
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
export class GenMeshGeom
|
||||||
|
{
|
||||||
|
brOcsInv: Matrix4;
|
||||||
|
alMatrix4: Matrix4 = new Matrix4;
|
||||||
|
|
||||||
|
//网洞
|
||||||
|
frontHoleCurves: ExtureContourCurve[] = [];
|
||||||
|
backHoleCurves: ExtureContourCurve[] = [];
|
||||||
|
|
||||||
|
//孤岛
|
||||||
|
frontIslandCurves: ExtureContourCurve[] = [];
|
||||||
|
backIslandCurves: ExtureContourCurve[] = [];
|
||||||
|
|
||||||
|
constructor(private br: ExtrudeSolid)
|
||||||
|
{
|
||||||
|
this.brOcsInv = br.OCSInv;
|
||||||
|
|
||||||
|
this.InitHoles(br);
|
||||||
|
|
||||||
|
//合并网洞
|
||||||
|
let frontCurveContours = this.frontHoleCurves.map(c => Contour.CreateContour(c as Polyline));
|
||||||
|
let backCurveContours = this.backHoleCurves.map(c => Contour.CreateContour(c as Polyline));
|
||||||
|
let frontHoleContours: Contour[] = [];
|
||||||
|
for (let i = 0; i < frontCurveContours.length; i++)
|
||||||
|
{
|
||||||
|
let c1 = frontCurveContours[i];
|
||||||
|
if (isNaN(c1.Curve.TempData)) continue;//已使用
|
||||||
|
for (let j = i + 1; j < frontCurveContours.length; j++)
|
||||||
|
{
|
||||||
|
let c2 = frontCurveContours[j];
|
||||||
|
if (isNaN(c2.Curve.TempData)) continue;
|
||||||
|
if (!c1.BoundingBox.intersectsBox(c2.BoundingBox)) continue;
|
||||||
|
if (equaln(c1.Curve.TempData, c2.Curve.TempData)) continue;//同深度的网洞不需要求交
|
||||||
|
|
||||||
|
let cs = c1.UnionBoolOperation(c2);
|
||||||
|
if (cs.length === 1)
|
||||||
|
{
|
||||||
|
c1 = cs[0];
|
||||||
|
c2.Curve.TempData = NaN;//已使用
|
||||||
|
c1.Curve.TempData = NaN;//和同类相残
|
||||||
|
j = i;//从下一个开始
|
||||||
|
}
|
||||||
|
}
|
||||||
|
frontHoleContours.push(c1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let contourShape = br.ContourCurve.Shape;
|
||||||
|
let verticesArray: number[] = [];
|
||||||
|
|
||||||
|
//draw front
|
||||||
|
contourShape.holes = frontHoleContours.map(c =>
|
||||||
|
{
|
||||||
|
let gContour = c.Curve;
|
||||||
|
if (gContour instanceof Polyline)
|
||||||
|
gContour.UpdateMatrixTo(br.ContourCurve.OCS);
|
||||||
|
|
||||||
|
let sp: TShape;
|
||||||
|
if (gContour instanceof Circle)
|
||||||
|
{
|
||||||
|
sp = new TShape();
|
||||||
|
let cen = gContour.Center.applyMatrix4(this.brOcsInv);
|
||||||
|
sp.ellipse(cen.x, cen.y, gContour.Radius, gContour.Radius, 0, 2 * Math.PI, false, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sp = gContour.Shape;
|
||||||
|
|
||||||
|
return sp;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private InitHoles(br: ExtrudeSolid)
|
||||||
|
{
|
||||||
|
for (let g of br.Grooves)
|
||||||
|
{
|
||||||
|
//判断槽正反面
|
||||||
|
let back = false;
|
||||||
|
let front = false;
|
||||||
|
if (equaln(g.Thickness, br.Thickness))
|
||||||
|
{
|
||||||
|
back = true;
|
||||||
|
front = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (equaln(g.Position.applyMatrix4(this.brOcsInv).z, 0))
|
||||||
|
back = true;
|
||||||
|
else
|
||||||
|
front = true;
|
||||||
|
}
|
||||||
|
this.alMatrix4.multiplyMatrices(this.brOcsInv, g.OCSNoClone);
|
||||||
|
//槽轮廓
|
||||||
|
let gContour = g.ContourCurve.Clone();
|
||||||
|
gContour.ApplyMatrix(this.alMatrix4);
|
||||||
|
gContour.Z0();
|
||||||
|
gContour.TempData = g.Thickness;
|
||||||
|
if (back)
|
||||||
|
this.backHoleCurves.push(gContour);
|
||||||
|
if (front)
|
||||||
|
this.frontHoleCurves.push(gContour);
|
||||||
|
//孤岛
|
||||||
|
for (let gg of g.Grooves)
|
||||||
|
{
|
||||||
|
let c = gg.ContourCurve.Clone();
|
||||||
|
this.alMatrix4.multiplyMatrices(this.brOcsInv, gg.OCSNoClone);
|
||||||
|
c.ApplyMatrix(this.alMatrix4).Z0();
|
||||||
|
c.TempData = g.Thickness;
|
||||||
|
if (back)
|
||||||
|
this.backIslandCurves.push(c);
|
||||||
|
if (front)
|
||||||
|
this.frontIslandCurves.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ContourFace
|
||||||
|
{
|
||||||
|
Front = 1,
|
||||||
|
Back = 2,
|
||||||
|
All = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OperatorData
|
||||||
|
{
|
||||||
|
//外部
|
||||||
|
outer: Curve[];
|
||||||
|
//被包含
|
||||||
|
beContainer: Curve[];
|
||||||
|
//共线
|
||||||
|
collineation: Curve[];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 轮廓曲线
|
||||||
|
*
|
||||||
|
* 板件轮廓与所有非全深槽的外轮廓进行计算
|
||||||
|
*/
|
||||||
|
class ContourCurveWrap
|
||||||
|
{
|
||||||
|
static Thickness: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param curve
|
||||||
|
* @param face 正面,反面,全深
|
||||||
|
* @param depth
|
||||||
|
* @param [isOuter=false] 外面(孤岛和板件轮廓)
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
public curve: ExtureContourCurve,
|
||||||
|
public face: ContourFace,
|
||||||
|
public depth: number,
|
||||||
|
public isOuter = false,
|
||||||
|
// public isBrContour = false,
|
||||||
|
public contour = Contour.CreateContour(curve)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 和轮廓进行求交,记录轮廓的关系
|
||||||
|
*
|
||||||
|
* 轮廓间关系:分离,包含,共线
|
||||||
|
*
|
||||||
|
* 分离:分离部分都需要绘制面
|
||||||
|
* 包含:共同方向的部分不绘制
|
||||||
|
* 共线:共同方向的包含只绘制一次,相反方向的面则取消绘制
|
||||||
|
*/
|
||||||
|
Operator(c: ContourCurveWrap)
|
||||||
|
{
|
||||||
|
if (c.face === this.face //面相同
|
||||||
|
&& equaln(this.depth, c.depth) && this.isOuter === c.isOuter)//深度相同
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((c.face & this.face) === 0 //没有全深槽
|
||||||
|
&& c.face !== this.face //面相反
|
||||||
|
&& this.depth + c.depth < ContourCurveWrap.Thickness)//不可能相交
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue