!745 正确的显示板件造型

pull/745/MERGE
ChenX 5 years ago
parent 99783c90e7
commit 89dc6da05e

@ -1,6 +1,7 @@
import { Line } from "three";
import { RenderType } from "../../src/GraphicsSystem/RenderType";
import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util";
import { ExtrudeGeometryBuilder } from "../../src/Geometry/ExtrudeEdgeGeometry2";
test('EdgeGeometry生成', () =>
{
@ -27,3 +28,17 @@ test('EdgeGeometry生成2', () =>
expect(line.geometry.attributes.position.count).toMatchSnapshot();
}
});
test('Geometry构建测试', () =>
{
let d = require("./edgebuilderData.json");
let brs = LoadBoardsFromFileData(d);
for (let br of brs)
{
let builder = new ExtrudeGeometryBuilder(br);
expect(builder.verticesArray.length).toMatchSnapshot();
expect(builder.edgeAndLidBuilder.verticesArray.length).toMatchSnapshot();
}
});

@ -2,8 +2,48 @@
exports[`EdgeGeometry生成 1`] = `114`;
exports[`EdgeGeometry生成 2`] = `858`;
exports[`EdgeGeometry生成 2`] = `360`;
exports[`EdgeGeometry生成 3`] = `60`;
exports[`EdgeGeometry生成2 1`] = `110`;
exports[`EdgeGeometry生成2 1`] = `80`;
exports[`Geometry构建测试 1`] = `540`;
exports[`Geometry构建测试 2`] = `408`;
exports[`Geometry构建测试 3`] = `378`;
exports[`Geometry构建测试 4`] = `288`;
exports[`Geometry构建测试 5`] = `1188`;
exports[`Geometry构建测试 6`] = `888`;
exports[`Geometry构建测试 7`] = `774`;
exports[`Geometry构建测试 8`] = `552`;
exports[`Geometry构建测试 9`] = `630`;
exports[`Geometry构建测试 10`] = `456`;
exports[`Geometry构建测试 11`] = `1548`;
exports[`Geometry构建测试 12`] = `1056`;
exports[`Geometry构建测试 13`] = `639`;
exports[`Geometry构建测试 14`] = `480`;
exports[`Geometry构建测试 15`] = `1998`;
exports[`Geometry构建测试 16`] = `1368`;
exports[`Geometry构建测试 17`] = `1908`;
exports[`Geometry构建测试 18`] = `1344`;
exports[`Geometry构建测试 19`] = `2232`;
exports[`Geometry构建测试 20`] = `1584`;

File diff suppressed because one or more lines are too long

@ -8,7 +8,7 @@ const config: webpack.Configuration = merge(
{
mode: "development",
output: { pathinfo: false },
devtool: "cheap-module-eval-source-map",
devtool: "eval-source-map",
//https://www.webpackjs.com/configuration/stats/
stats: {
assets: false,

@ -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);
// }
}
}

@ -1,15 +1,8 @@
import { BufferGeometry, Float32BufferAttribute, Matrix4, Mesh, Shape, ShapeUtils, Vector2 } from "three";
import { Command } from "../../Editor/CommandMachine";
import { HotCMD } from "../../Hot/HotCommand";
import { app } from "../../ApplicationServices/Application";
import { Contour } from "../../DatabaseServices/Contour";
import { Board } from "../../DatabaseServices/Entity/Board";
import { Circle } from "../../DatabaseServices/Entity/Circle";
import { Curve } from "../../DatabaseServices/Entity/Curve";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { Command } from "../../Editor/CommandMachine";
import { PromptStatus } from "../../Editor/PromptResult";
import { equaln } from "../../Geometry/GeUtils";
import { HotCMD } from "../../Hot/HotCommand";
import { TestDraw } from "../test/TestUtil";
@HotCMD
export class Test implements Command
@ -20,169 +13,6 @@ export class Test implements Command
if (enRes.Status !== PromptStatus.OK) return;
let br = enRes.Entity as Board;
let ocsInv = br.OCSInv;
let alMatrix4 = new Matrix4();
let frontHoles: Shape[] = [];
let backHoles: Shape[] = [];
let frontCurves: Curve[] = [];
let backCurves: Curve[] = [];
let frontHoleCurves: Curve[] = [];
let backHoleCurves: Curve[] = [];
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(ocsInv).z, 0))
back = true;
else
front = true;
}
alMatrix4.multiplyMatrices(ocsInv, g.OCSNoClone);
let gContour = g.ContourCurve.Clone();
gContour.ApplyMatrix(alMatrix4);
if (gContour instanceof Polyline)
gContour.UpdateMatrixTo(br.ContourCurve.OCS);
let sp: Shape;
if (gContour instanceof Circle)
{
sp = new Shape();
let cen = gContour.Center.applyMatrix4(ocsInv);
sp.ellipse(cen.x, cen.y, gContour.Radius, gContour.Radius, 0, 2 * Math.PI, false, 0);
}
else
sp = gContour.Shape;
gContour.Z0();
gContour.TempData = g.Thickness;
let holeCurves: Curve[] = [];
for (let gg of g.Grooves)
{
let c = gg.ContourCurve;
c.ApplyMatrix(alMatrix4).Z0();
c.TempData = g.Thickness;
holeCurves.push(c);
}
if (back)
{
backHoles.push(sp);
backCurves.push(gContour);
backHoleCurves.push(...holeCurves);
}
if (front)
{
frontHoles.push(sp);
frontCurves.push(gContour);
frontHoleCurves.push(...holeCurves);
}
}
let contourShape = br.ContourCurve.Shape;
let verticesArray: number[] = [];
//draw front
contourShape.holes = frontHoles;
DrawShapeFaces(contourShape, verticesArray, br);
//front 孤岛
let frontCurveContours = frontCurves.map(c => Contour.CreateContour([c]));
DrawIslandFaces(frontHoleCurves, frontCurveContours, verticesArray, br);
//draw back
contourShape.holes = backHoles;
DrawShapeFaces(contourShape, verticesArray, br, false);
let backCurveContours = backCurves.map(c => Contour.CreateContour([c]));
DrawIslandFaces(backHoleCurves, backCurveContours, verticesArray, br, false);
//绘制内部造型
//绘制边缘
//geo
let geo = new BufferGeometry();
geo.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
TestDraw(new Mesh(geo));
}
}
function DrawIslandFaces(HoleCurves: Curve[], CurveContours: Contour[], verticesArray: number[], br: Board, front = true)
{
for (let c of HoleCurves)
{
let contours = [Contour.CreateContour([c])];
for (let hole of CurveContours)
{
if (!equaln(c.TempData as number, hole.Curve.TempData as number))
{
let newcs: Contour[] = [];
for (let con of contours)
newcs.push(...con.SubstactBoolOperation(hole));
contours = newcs;
}
}
for (let con of contours)
{
DrawShapeFaces(con.Curve.Shape, verticesArray, br);
}
}
}
function DrawShapeFaces(contourShape: Shape, verticesArray: number[], br: Board, front = true)
{
let shapePoints = contourShape.extractPoints(6);
let vertices = shapePoints.shape;
let holes = shapePoints.holes;
let reverse = !ShapeUtils.isClockWise(vertices);
if (reverse)
{
vertices = vertices.reverse();
for (let h = 0, hl = holes.length; h < hl; h++)
{
let ahole = holes[h];
if (ShapeUtils.isClockWise(ahole))
holes[h] = ahole.reverse();
}
}
let faces = ShapeUtils.triangulateShape(vertices, holes);
for (let h of holes)
vertices.push(...h);
for (let f of faces)
{
if (front)
{
newFunction_1(vertices[f[0]]);
newFunction_1(vertices[f[1]]);
newFunction_1(vertices[f[2]]);
}
else
{
newFunction_1(vertices[f[0]]);
newFunction_1(vertices[f[2]]);
newFunction_1(vertices[f[1]]);
}
}
function newFunction_1(v: Vector2)
{
verticesArray.push(v.x);
verticesArray.push(v.y);
if (front)
verticesArray.push(br.Thickness);
else
verticesArray.push(0);
br.ApplyMatrix(br.OCSInv);
}
}

@ -88,12 +88,12 @@ export abstract class Curve extends Entity
/**
* 线.,线.
*
* @param {(number[] | number)} param
* @returns {Array<Curve>}
* @memberof Curve
*/
GetSplitCurves(param: number[] | number): Array<Curve> { return; }
//未完善
GetCurveAtParamRange(startParam: number, EndParam: number): Array<Curve> { return; }
GetSplitCurvesByPts(pt: Vector3[] | Vector3): Array<Curve>
{
let pts = Array.isArray(pt) ? pt : [pt];

@ -1,4 +1,4 @@
import { BoxGeometry, BufferGeometry, ExtrudeGeometry, ExtrudeGeometryOptions, Geometry, Line, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Vector3, Path } from "three";
import { BoxGeometry, BufferGeometry, ExtrudeGeometry, ExtrudeGeometryOptions, Geometry, Line, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Path, Vector3 } from "three";
import { arrayClone, arrayLast, arrayRemoveIf, arraySortByNumber, arraySum } from "../../Common/ArrayExt";
import { ColorMaterial } from "../../Common/ColorPalette";
import { equalCurve } from "../../Common/CurveUtils";
@ -6,7 +6,7 @@ import { DisposeThreeObj } from "../../Common/Dispose";
import { matrixSetVector, Vector2ApplyMatrix4 } from "../../Common/Matrix4Utils";
import { Status, UpdateDraw } from "../../Common/Status";
import { CSG } from "../../csg/core/CSG";
import { CSG2Geometry, Geometry2CSG } from "../../csg/core/Geometry2CSG";
import { Geometry2CSG } from "../../csg/core/Geometry2CSG";
import { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { boardUVGenerator } from "../../Geometry/BoardUVGenerator";
import { Box3Ext } from "../../Geometry/Box";
@ -14,6 +14,7 @@ import { BSPGroupParse } from "../../Geometry/BSPGroupParse";
import { FastWireframe } from "../../Geometry/CreateWireframe";
import { EdgesGeometry } from "../../Geometry/EdgeGeometry";
import { GenerateExtrudeEdgeGeometry } from "../../Geometry/ExtrudeEdgeGeometry";
import { ExtrudeGeometryBuilder } from "../../Geometry/ExtrudeEdgeGeometry2";
import { AsVector2, AsVector3, equaln, equalv2, equalv3, IdentityMtx4, isIntersect, isParallelTo, isPerpendicularityTo, MoveMatrix, XAxis, YAxis, ZAxis, ZeroVec } from "../../Geometry/GeUtils";
import { OBB } from "../../Geometry/OBB/obb";
import { ScaleUV } from "../../Geometry/UVUtils";
@ -1219,11 +1220,47 @@ export class ExtrudeSolid extends Entity
if (this._MeshGeometry)
return this._MeshGeometry;
this._MeshGeometry = this.GeneralMeshGeometry();
this.csg = undefined;
let grooves = this.Grooves;
if (grooves.every(g => equaln(g.thickness, this.thickness)))
{
let contour = this.ContourCurve;
let holes: Contour[] = [];
let ocsInv = this.OCSInv;
let alMatrix4 = new Matrix4();
for (let g of grooves)
{
alMatrix4.multiplyMatrices(ocsInv, g.OCSNoClone);
let gContour = g.ContourCurve.Clone();
gContour.ApplyMatrix(alMatrix4);
holes.push(Contour.CreateContour(gContour));
}
let shape = new Shape(Contour.CreateContour(contour), holes);
let extrudeSettings: ExtrudeGeometryOptions = {
steps: 1,
bevelEnabled: false,
depth: this.Thickness,
UVGenerator: this.UCGenerator,
};
let geo = new ExtrudeGeometry(shape.Shape, extrudeSettings);
geo.applyMatrix4(contour.OCSNoClone);
ScaleUV(geo);
return geo;
}
let builder = new ExtrudeGeometryBuilder(this);
this._MeshGeometry = builder.MeshGeometry;
this._EdgeGeometry = builder.EdgeGeometry;
return this._MeshGeometry;
}
private _EdgeGeometry: EdgesGeometry;
private _EdgeGeometry: EdgesGeometry | BufferGeometry;
private get EdgeGeometry()
{
if (this._EdgeGeometry)
@ -1256,55 +1293,9 @@ export class ExtrudeSolid extends Entity
}
return GenerateExtrudeEdgeGeometry(pts, this.thickness).applyMatrix4(this.contourCurve.OCSNoClone);
}
this._EdgeGeometry = new EdgesGeometry().FromCSG(this.CSG);
return this._EdgeGeometry;
}
private GeneralMeshGeometry()
{
this.csg = undefined;
let grooves = this.Grooves;
let gs: ExtrudeSolid[] = [];//不是全深槽
let contour = this.ContourCurve;
let holes: Contour[] = [];
let ocsInv = this.OCSInv;
let alMatrix4 = new Matrix4();
for (let g of grooves)
{
if (equaln(g.Thickness, this.Thickness))
{
alMatrix4.multiplyMatrices(ocsInv, g.OCSNoClone);
let gContour = g.ContourCurve.Clone();
gContour.ApplyMatrix(alMatrix4);
holes.push(Contour.CreateContour(gContour));
}
else if (g.Thickness > 0)
gs.push(g);
}
let shape = new Shape(Contour.CreateContour(contour), holes);
let extrudeSettings: ExtrudeGeometryOptions = {
steps: 1,
bevelEnabled: false,
depth: this.Thickness,
UVGenerator: this.UCGenerator,
};
let geo = new ExtrudeGeometry(shape.Shape, extrudeSettings);
geo.applyMatrix4(contour.OCSNoClone);
ScaleUV(geo);
if (gs.length === 0 || gs.length > MaxGrooveCount)
return geo;
this.csg = Geometry2CSG(geo);
for (let g of gs)
this.csg = this.csg.subtract(g.CSG.transform1(this.OCSInv.multiply(g.OCSNoClone)));
let bgeo = CSG2Geometry(this.csg);
return bgeo;
this.MeshGeometry;
return this._EdgeGeometry;
}
DeferUpdate()

@ -647,7 +647,7 @@ export class Polyline extends Curve
//添加点
for (let i = 0; i < pafloor; i++)
{
if (i == 0 && !equaln(buls[0], 0, 1e-8))
if (i === 0 && !equaln(buls[0], 0, 1e-8))
{
buls[0] = Math.tan((1 - prePa) * Math.atan(buls[0]));
}
@ -694,6 +694,70 @@ export class Polyline extends Curve
return pls;
}
//未完善
GetCurveAtParamRange(startParam: number, endParam: number): Array<Curve>
{
let sfloor = Math.floor(startParam + 0.5);
if (equaln(sfloor, startParam, 1e-8)) startParam = sfloor;
else sfloor = Math.floor(startParam);
let efloor = Math.floor(endParam + 0.5);
if (equaln(efloor, endParam, 1e-8)) endParam = efloor;
else efloor = Math.floor(efloor);
const GetCurve = (index: number) =>
{
let d = this._LineData[index];
let next = this._LineData[index + 1];
if (!equaln(d.bul, 0, 1e-8))
return new Arc().ParseFromBul(d.pt, next.pt, d.bul);
else
return new Line(AsVector3(d.pt), AsVector3(next.pt));
};
let lined: PolylineProps[] = [];
if (startParam === sfloor)
{
let d = this._LineData[sfloor];
lined.push({ pt: d.pt.clone(), bul: d.bul });
}
else
{
let d = this._LineData[sfloor];
let cu = GetCurve(sfloor);
let remParam = startParam - sfloor;
let p = cu.GetPointAtParam(remParam);
let bul = d.bul;
if (!equaln(bul, 0))
bul = Math.tan(Math.atan(bul) * (1 - remParam));
lined.push({ pt: AsVector2(p), bul: bul });
}
for (let i = sfloor + 1; i < efloor; i++)
{
let d = this._LineData[i];
lined.push({ pt: d.pt.clone(), bul: d.bul });
}
if (efloor !== endParam)
{
let d = this.LineData[efloor];
let remParam = endParam - efloor;
let cu = GetCurve(efloor);
let p = cu.GetPointAtParam(remParam);
let bul = d.bul;
if (!equaln(bul, 0))
{
arrayLast(lined).bul = Math.tan(Math.atan(bul) * remParam);
bul = Math.tan(Math.atan(bul) * (1 - remParam));
}
lined.push({ pt: AsVector2(p), bul });
}
let pl = new Polyline(lined);
pl.OCS = this.OCSNoClone;
return;
}
Extend(newParam: number)
{
if (this.CloseMark || this.ParamOnCurve(newParam)) return;

@ -18,7 +18,6 @@ import { ShapeManager } from '../ShapeManager';
@Factory
export class Region extends Entity
{
private _ShapeManager: ShapeManager = new ShapeManager();
static CreateFromCurves(cus: Curve[]): Region | undefined
{
let shapes = Contour.GetAllContour(cus).map(out => new Shape(out));
@ -32,6 +31,11 @@ export class Region extends Entity
}
}
constructor(private _ShapeManager: ShapeManager = new ShapeManager())
{
super();
}
//如果需要修改获取到的属性,需要Clone后进行操作,否则会对原实体进行破坏
get ShapeManager()
{

@ -109,6 +109,20 @@ export class ShapeManager
}
return true;
}
SubstactShape(target: Shape)
{
//减数形状
let tmpShapes: Shape[] = [];
//被减形状
for (let minuendShape of this._ShapeList)
{
let operatedShapes = minuendShape.SubstactBoolOperation(target);
tmpShapes.push(...operatedShapes);
}
//迭代this形状列表,每次赋予新的结果
this._ShapeList = tmpShapes;
return true;
}
/**
* region.ApplyMatrix,.

@ -159,6 +159,7 @@ import { Align } from './../Add-on/Align';
import { BuyMaterial } from './../Add-on/BuyMaterial';
import { Interfere } from './../Add-on/interfere';
import { Command_ShowProcessingGroupModal2 } from "../Add-on/ShowProcessingGroupModal";
import { Command_TestTape } from "../Add-on/test/TestTape";
export function registerCommand()
{
@ -438,6 +439,9 @@ export function registerCommand()
commandMachine.RegisterCommand("buymaterial", new BuyMaterial());
commandMachine.RegisterCommand("interfere", new Interfere());
commandMachine.RegisterCommand("testw", new Command_TestTape());
RegistCustomCommand();
}

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;
}
}

@ -172,6 +172,7 @@ export class OffsetPolyline
this._Polyline.OCS = IdentityMtx4;
this._SubCurves = this._Polyline.Explode().filter(c => c.Length > 1e-4);
this._Polyline.OCS = this._CacheOCS;
return this;
}
protected GeneralCirclesAndVertexs()

Loading…
Cancel
Save