优化:造型实体的线框和实体重合

pull/1999/MERGE
ChenX 2 years ago
parent 233fda1d63
commit 308d497751

@ -17,7 +17,7 @@ import { boardUVGenerator } from "../../Geometry/BoardUVGenerator";
import { Box3Ext } from "../../Geometry/Box";
import { BSPGroupParse } from '../../Geometry/BSPGroupParse';
import { BufferGeometryUtils } from "../../Geometry/BufferGeometryUtils";
import { FastExtrudeEdgeGeometry, FastWireframe } from "../../Geometry/CreateWireframe";
import { FastExtrudeEdgeGeometry, FastExtrudeEdgeGeometryOfShape, FastWireframe } from "../../Geometry/CreateWireframe";
import { EdgesGeometry } from "../../Geometry/EdgeGeometry";
import { ExtrudeGeometryBuilder } from "../../Geometry/ExtrudeMeshGeomBuilder/ExtrudeEdgeGeometry2";
import { AsVector2, equaln, equalv2, equalv3, IdentityMtx4, isIntersect, isParallelTo, isPerpendicularityTo, MoveMatrix, XAxis, YAxis, ZAxis, ZeroVec } from "../../Geometry/GeUtils";
@ -1864,7 +1864,7 @@ export class ExtrudeSolid extends Entity
let ocsInv = this.OCSInv;
let alMatrix4 = new Matrix4();
if (grooves.length < 1000)
if (grooves.length < MaxDrawGrooveCount)
for (let g of grooves)
{
alMatrix4.multiplyMatrices(ocsInv, g.OCSNoClone);
@ -1888,6 +1888,17 @@ export class ExtrudeSolid extends Entity
bgeo["IsMesh"] = true;
this._MeshGeometry = bgeo;
this.GenWorldUV(bgeo);
//edge geometry
if (grooves.length < MaxDrawGrooveCount)//这个代码保证线框和概念对齐
{
let coords = FastExtrudeEdgeGeometryOfShape(shape.Shape, 0, this.thickness, 12, true);
let edgeGeo = new BufferGeometry();
edgeGeo.setAttribute('position', new Float32BufferAttribute(coords, 3));
edgeGeo.applyMatrix4(contour.OCSNoClone);
this._EdgeGeometry = edgeGeo;
}
return bgeo;
}

@ -11,13 +11,11 @@ import { Polyline } from './Entity/Polyline';
export class Shape
{
private _Outline: Contour;
private _Holes: Contour[] = [];
private _Shape: TShape = new TShape();
constructor(out?: Contour, hols?: Contour[])
constructor(
private _Outline: Contour = new Contour,
private _Holes: Contour[] = []
)
{
this._Outline = out || new Contour();
hols && this._Holes.push(...hols);
}
get Outline()
@ -38,21 +36,37 @@ export class Shape
{
return this._Outline.BoundingBox;
}
set Outline(cus: Contour)
set Outline(con: Contour)
{
this._Outline = cus;
this.UpdateShape();
this._Outline = con;
}
set Holes(cus: Contour[])
set Holes(holes: Contour[])
{
this._Holes = cus;
this.UpdateShape();
this._Holes = holes;
}
get Shape()
get Shape(): TShape
{
this.UpdateShape();
return this._Shape;
let shape = this.Outline.Shape;
for (let h of this._Holes)
{
if (h.Curve instanceof Polyline)
h.Curve.UpdateOCSTo(this.Outline.Curve.OCS);
if (h.Curve instanceof Circle)
{
let sp = new Path();
let cen = h.Curve.Center.applyMatrix4(this.Outline.Curve.OCSInv);
sp.ellipse(cen.x, cen.y, h.Curve.Radius, h.Curve.Radius, 0, 2 * Math.PI, false, 0);
shape.holes.push(sp);
}
else
shape.holes.push(h.Shape);
}
return shape;
}
get Position()
{
return this._Outline.Curve.Position;
@ -523,25 +537,6 @@ export class Shape
}
return holes;
}
UpdateShape()
{
this._Shape = this.Outline.Shape;
for (let h of this._Holes)
{
if (h.Curve instanceof Polyline)
h.Curve.UpdateOCSTo(this.Outline.Curve.OCS);
if (h.Curve instanceof Circle)
{
let sp = new Path();
let cen = h.Curve.Center.applyMatrix4(this.Outline.Curve.OCSInv);
sp.ellipse(cen.x, cen.y, h.Curve.Radius, h.Curve.Radius, 0, 2 * Math.PI, false, 0);
this._Shape.holes.push(sp);
}
else
this._Shape.holes.push(h.Shape);
}
}
//读写文件
ReadFile(file: CADFiler)
{

@ -7,6 +7,7 @@ import { Board } from "../DatabaseServices/Entity/Board";
import { Curve } from "../DatabaseServices/Entity/Curve";
import { ExtrudeSolid } from "../DatabaseServices/Entity/Extrude";
import { Shape } from "../DatabaseServices/Shape";
import { Shape2 } from "../DatabaseServices/Shape2";
import { FaceDirection } from "../UI/Store/BoardInterface";
import { MatrixIsIdentityCS, MoveMatrix } from "./GeUtils";
@ -146,7 +147,31 @@ export function FastWireframe(br: ExtrudeSolid, color = 0, divCount = 6, optArc
return result;
}
export function FastExtrudeEdgeGeometryOfShape(shape: Shape2, z0: number, z1: number, divCount = 6, optArc = true, coords: number[] = [])
{
let ptss = [shape.getPoints(divCount, optArc)];
for (let hole of shape.holes)
ptss.push((hole as Shape2).getPoints(divCount, optArc));
for (let pts of ptss)
for (let i = 0; i < pts.length; i++)
{
let p = pts[i];
let nextp = pts[FixIndex(i + 1, pts)];
//底面
coords.push(p.x, p.y, z0, nextp.x, nextp.y, z0);
//顶面
coords.push(p.x, p.y, z1, nextp.x, nextp.y, z1);
if (p["_mask_"])//侧面
coords.push(p.x, p.y, z0, p.x, p.y, z1);
}
return coords;
}
let tempP = new Vector3;
//这个代码天生不和Mesh对齐,因为独立坐标系的原因,槽的坐标系可能和主题的坐标系不一致导致的
export function FastExtrudeEdgeGeometry(ext: ExtrudeSolid, color = 0, divCount = 6, optArc = true, coords: number[] = [], inv: Matrix4 = undefined)
{
color = color || ext.ColorIndex;

Loading…
Cancel
Save