mirror of https://gitee.com/cf-fz/WebCAD.git
!743 快速构造拉伸实体网格
parent
cad71af247
commit
65efa29eff
@ -1,9 +1,9 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EdgeGeometry生成 1`] = `432`;
|
||||
exports[`EdgeGeometry生成 1`] = `114`;
|
||||
|
||||
exports[`EdgeGeometry生成 2`] = `858`;
|
||||
|
||||
exports[`EdgeGeometry生成 3`] = `146`;
|
||||
exports[`EdgeGeometry生成 3`] = `60`;
|
||||
|
||||
exports[`EdgeGeometry生成2 1`] = `110`;
|
||||
|
@ -1,26 +1,188 @@
|
||||
import { BufferGeometry, Float32BufferAttribute, Matrix4, Mesh, Shape, ShapeUtils, Vector2 } from "three";
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { TemplateVisualSpace } from "../../DatabaseServices/Template/ProgramTempate/TemplateVisualSpace";
|
||||
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 { TemplateSplitType } from "../../DatabaseServices/Template/TemplateType";
|
||||
import { SelectTempate } from "../../DatabaseServices/Template/TemplateTest";
|
||||
import { Entity } from "../../DatabaseServices/Entity/Entity";
|
||||
import { TestDraw } from "../test/TestUtil";
|
||||
|
||||
@HotCMD
|
||||
export class Test implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let enRes = await app.Editor.GetEntity({ Filter: { filterTypes: [Board] } });
|
||||
if (enRes.Status !== PromptStatus.OK) return;
|
||||
let br = enRes.Entity as Board;
|
||||
|
||||
let t = await SelectTempate();
|
||||
if (!t) return;
|
||||
let ocsInv = br.OCSInv;
|
||||
let alMatrix4 = new Matrix4();
|
||||
|
||||
let frontHoles: Shape[] = [];
|
||||
let backHoles: Shape[] = [];
|
||||
|
||||
let objs = t.Objects.map(t => t.Object).filter(o => o !== undefined && !o.IsErase) as Entity[];
|
||||
let frontCurves: Curve[] = [];
|
||||
let backCurves: Curve[] = [];
|
||||
|
||||
for (let o of objs)
|
||||
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++)
|
||||
{
|
||||
o.ApplyMatrix(o.SpaceOCSInv);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue