开发:异形优化支持板外下刀

pull/2474/head
ChenX 11 months ago
parent b559dd39cf
commit 927e329fa9

@ -1,12 +1,12 @@
import { Command } from "../Editor/CommandMachine";
import { app } from "../ApplicationServices/Application";
import { PromptStatus } from "../Editor/PromptResult";
import { ShowLinesToaster } from "../UI/Components/Toaster";
import { Intent } from "@blueprintjs/core";
import { Log } from "../Common/Log";
import { angle } from "../Geometry/GeUtils";
import { MathUtils } from "three";
import { app } from "../ApplicationServices/Application";
import { Log } from "../Common/Log";
import { FixedNotZero } from "../Common/Utils";
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
import { angle } from "../Geometry/GeUtils";
import { ShowLinesToaster } from "../UI/Components/Toaster";
export class Command_Dist implements Command
@ -31,18 +31,18 @@ export class Command_Dist implements Command
let p2 = ptRes.Point;
let dist = FixedNotZero(p1.distanceTo(p2), 2);
let x = FixedNotZero(Math.abs(p2.x - p1.x), 2);
let y = FixedNotZero(Math.abs(p2.y - p1.y), 2);
let z = FixedNotZero(Math.abs(p2.z - p1.z), 2);
let dist = FixedNotZero(p1.distanceTo(p2), 4);
let x = FixedNotZero(Math.abs(p2.x - p1.x), 4);
let y = FixedNotZero(Math.abs(p2.y - p1.y), 4);
let z = FixedNotZero(Math.abs(p2.z - p1.z), 4);
let vec = p2.sub(p1);
let ang = FixedNotZero(MathUtils.radToDeg(angle(vec)), 2);
let ang2 = FixedNotZero(MathUtils.radToDeg(Math.asin(vec.z / vec.length())), 2);
let ang = FixedNotZero(MathUtils.radToDeg(angle(vec)), 4);
let ang2 = FixedNotZero(MathUtils.radToDeg(Math.asin(vec.z / vec.length())), 4);
ShowLinesToaster([
`距离=${dist}`, `XY平面倾角=${ang}°`, `XY平面夹角=${ang2}°`, `X方向距离=${x}`, `Y方向距离=${y}`, `Z方向距离=${z}`
`距离=${dist} 向量(${x},${y},${z})`, `XY平面倾角=${ang}°`, `XY平面夹角=${ang2}°`, `X方向距离=${x}`, `Y方向距离=${y}`, `Z方向距离=${z}`
], { timeout: 20 * 1e3, intent: Intent.SUCCESS }, "dist");
Log(`距离=${dist},XY平面倾角=${ang}°,XY平面夹角=${ang2}°,X方向距离=${x},Y方向距离=${y},Z方向距离=${z}`);
}

@ -27,8 +27,11 @@ export class CurveWrap
Points: Point[];
_OrgCurve: Polyline | Circle;
constructor(public Curve: Polyline | Circle, public KnifRadius = 3, public IsOutside: boolean = true)
{
this._OrgCurve = Curve;
this.BoundingBox = Curve.BoundingBox;
if (Curve instanceof Polyline)

@ -1,10 +1,13 @@
import { Draw } from "../../Common/Draw";
import { Log, LogType } from "../../Common/Log";
import { Circle } from "../../DatabaseServices/Entity/Circle";
import { Curve } from "../../DatabaseServices/Entity/Curve";
import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { AsVector3 } from "../../Geometry/GeUtils";
import { Part } from "../Core/Part";
import { Path } from "../Core/Path";
import { CurveWrap } from "./CurveWrap";
import { Path2Polyline } from "./Path2Polyline";
/**
* 线.
@ -44,7 +47,7 @@ export function Curves2Parts(curves: (Polyline | Circle)[], binPath: Path, KnifR
try
{
let part = new Part();
let curves: Curve[] = [w.Curve];
let curves: Curve[] = [w._OrgCurve];
let path = new Path(w.GetOutsidePoints());
for (let h of w.Holes)
{
@ -56,7 +59,33 @@ export function Curves2Parts(curves: (Polyline | Circle)[], binPath: Path, KnifR
curves.push(h.Curve);
}
}
part.Init(path, binPath, 12);
let c1 = Path2Polyline(path.Points);
c1.Move(AsVector3(path.OrigionMinPoint));
c1.ColorIndex = 1;
Draw(c1);
curves.push(c1);
let knife = w.Curve.GetOffsetCurves(5)[0] as Polyline;
let knifPath = new Path(new CurveWrap(knife, 3, true).GetOutsidePoints());
// knife.ColorIndex = 1;
// Draw(knife);
// curves.push(knife);
if (i % 2 === 0)
{
knifPath = undefined;
}
else
{
let c2 = Path2Polyline(knifPath.Points);
c2.Move(AsVector3(knifPath.OrigionMinPoint));
c2.ColorIndex = 2;
Draw(c2);
curves.push(c2);
}
part.Init2(path, binPath, [Math.PI / 2], knifPath);
part.UserData = curves;
parts.push(part);
}

@ -11,7 +11,7 @@ import { equaln } from "../Common/Util";
import { Vector2 } from "../Common/Vector2";
import { NestCache } from "./NestCache";
import { Part, PartGroup } from "./Part";
import { Path, PathTranslate } from "./Path";
import { Path, PathTranslate, PathTranslate_Self } from "./Path";
import { PlaceType } from "./PlaceType";
/**
@ -252,14 +252,36 @@ export class Container
let nfps: SubjectInput[] = [];
for (let placedPart of this.PlacedParts)
{
let nfp = placedPart.State.Contour.GetOutsideNFP(part.State.Contour);
let nfp = placedPart.State.OutContour.GetOutsideNFP(part.State.Contour);
if (!nfp) return;
for (let n of nfp)
{
let nnfp = PathTranslate(n, placedPart.PlacePosition);
if (placedPart.State.KnifeContour)
PathTranslate_Self(nnfp, -placedPart.State.KnifeOffset.x * 1e4, -placedPart.State.KnifeOffset.y * 1e4);
nfps.push({ data: nnfp, closed: true });
}
}
if (part.State.KnifeContour)
{
for (let placedPart of this.PlacedParts)
{
let nfp = placedPart.State.Contour.GetOutsideNFP(part.State.KnifeContour);
if (!nfp) return;
for (let n of nfp)
{
let nnfp = PathTranslate(n, placedPart.PlacePosition);
PathTranslate_Self(nnfp, part.State.KnifeOffset.x * 1e4, part.State.KnifeOffset.y * 1e4);
nfps.push({ data: nnfp, closed: true });
}
}
}
//合并nfp
let combinedNfp = clipperCpp.lib.clipToPaths({
subjectInputs: nfps,

@ -66,7 +66,7 @@ export class Part<T = any, Matrix = any>
}
//初始化零件的各个状态,按360度旋转个数
Init(path: Path, bin: Path, rotateCount = 4): this
Init(path: Path, bin: Path, rotateCount = 4, path_knife?: Path): this
{
let rotations: number[] = [];
let a = 2 * Math.PI / rotateCount;
@ -74,12 +74,12 @@ export class Part<T = any, Matrix = any>
{
rotations.push(a * i);
}
this.Init2(path, bin, rotations);
this.Init2(path, bin, rotations, path_knife);
return this;
}
//初始化零件的各个状态,按旋转角度表
Init2(path: Path, bin: Path, rotations: number[] = []): this
Init2(path: Path, bin: Path, rotations: number[] = [], path_knife?: Path): this
{
let path_OMP = path.OrigionMinPoint;
let path_0 = PathGeneratorSingle.Allocate(path);
@ -95,6 +95,12 @@ export class Part<T = any, Matrix = any>
partState.Contour = path_0;
partState.OrigionMinPoint = path_OMP;
partState.MinPoint = path_OMP;
if (path_knife)
{
partState.KnifeContour = PathGeneratorSingle.Allocate(path_knife);
partState.KnifeOffset = path_OMP.clone().sub(path_knife.OrigionMinPoint);
}
}
else
{
@ -113,6 +119,24 @@ export class Part<T = any, Matrix = any>
//计算正确的最小点
let tempPath = new Path(path.OrigionPoints, ro);
partState.MinPoint = tempPath.OrigionMinPoint;
if (path_knife)
{
let kpath_r = new Path(path_knife.Points, ro);
partState.KnifeContour = PathGeneratorSingle.Allocate(kpath_r);
partState.KnifeOffset = path_r.OrigionMinPoint.clone().sub(kpath_r.OrigionMinPoint);
let c = Math.cos(ro);
let s = Math.sin(ro);
let x = path_OMP.x - path_knife.OrigionMinPoint.x;
let y = path_OMP.y - path_knife.OrigionMinPoint.y;
let x1 = x * c - y * s;
let y1 = x * s + y * c;
partState.KnifeOffset.x += x1;
partState.KnifeOffset.y += y1;
}
}
//记录已有Path
pathSet.add(partState.Contour);
@ -121,6 +145,8 @@ export class Part<T = any, Matrix = any>
{
this.RotatedStates.push(partState);
PathGeneratorSingle.RegisterId(partState.Contour);
if (partState.KnifeContour)
PathGeneratorSingle.RegisterId(partState.KnifeContour);
}
}

@ -15,9 +15,18 @@ export class PartState
MinPoint: Point;//这个状态下的最小点 通常是网洞相对于上级的位置
Contour: Path;//轮廓
//刀路轮廓(比原始轮廓大一点)
KnifeContour: Path;
KnifeOffset: Point;//原始轮廓的左下角相对于刀轮廓左下角的偏移值,kf0+p = org0
IsMirror: boolean = false;
MirrorOriginMinPoint: Point;
get OutContour()
{
return this.KnifeContour ?? this.Contour;
}
Mirror(): PartState
{
if (this.Contour.IsRect) return;
@ -47,6 +56,11 @@ export class PartState
if (!this.Contour)
console.error("无法得到PartState的轮廓!");
let knifeId = file.Read() as number;
this.KnifeContour = PathGeneratorSingle.paths[knifeId];
if (this.KnifeContour)
this.KnifeOffset = file.Read();
}
WriteFile(file: NestFiler)
{
@ -54,6 +68,10 @@ export class PartState
file.Write(this.OrigionMinPoint);
file.Write(this.MinPoint);
file.Write(this.Contour.Id);
file.Write(this.KnifeContour?.Id ?? -1);
if (this.KnifeContour)
file.Write(this.KnifeOffset);
}
//#endregion
}

@ -159,7 +159,7 @@ export function Place(inv: Individual, parts: Part[], binPath: Path)
for (let cu of partOld.UserData)
{
cu.ColorIndex = j;
// cu.ColorIndex = j;
ApplyMatrix(cu, partOld.PlaceCS);
}
}

Loading…
Cancel
Save