mirror of https://gitee.com/cf-fz/WebCAD.git
parent
5c39e4b0a5
commit
0716cd3533
@ -0,0 +1,14 @@
|
|||||||
|
import { Region } from "../../src/DatabaseServices/Region";
|
||||||
|
import { LoadRegionsFromFileData } from "../Utils/LoadEntity.util";
|
||||||
|
import { BoolOpeartionType } from "../../src/GraphicsSystem/BoolOperateUtils";
|
||||||
|
|
||||||
|
test("#IRFL2面域消失", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[2, "Region", 2, 1, 102, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -284.847850497852, -347.14497813089565, 0, 1], 1, 1, 1, 1, 1, "Polyline", 2, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -284.847850497852, -347.14497813089565, 0, 1], 0, 2, 4, [258.7734554093699, 1.1368683772161603e-13], 0, [674.3301771838924, 5.684341886080802e-14], 0, [674.3301771838924, 1091.0460568668868], 0, [258.7734554093699, 1091.0460568668868], 0, true, 0, "Region", 2, 1, 103, false, 7, 0, [-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 389.4823496974607, -74.09892126400852, 0, 1], 1, 1, 1, 1, 1, "Polyline", 2, 1, 0, false, 7, 0, [-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 389.4823496974607, -74.09892126400852, 0, 1], 0, 2, 4, [0, 0], 0, [415.5567321777343, 0], 0, [415.5567321777343, 18], 0, [0, 18], 0, true, 0]
|
||||||
|
|
||||||
|
let regs: Region[] = LoadRegionsFromFileData(data);
|
||||||
|
expect(regs.length).toBe(2);
|
||||||
|
regs[0].BooleanOper(regs[1], BoolOpeartionType.Intersection);
|
||||||
|
expect(regs[0].ShapeManager.ShapeList.length).toBe(2);
|
||||||
|
});
|
File diff suppressed because one or more lines are too long
@ -1,102 +1,70 @@
|
|||||||
import { Matrix4, Vector3 } from "three";
|
|
||||||
import { app } from "../../ApplicationServices/Application";
|
import { app } from "../../ApplicationServices/Application";
|
||||||
import { FixedNotZero } from "../../Common/Utils";
|
import { FixedNotZero } from "../../Common/Utils";
|
||||||
import { Arc } from "../../DatabaseServices/Arc";
|
import { BoardType, Board } from "../../DatabaseServices/Board";
|
||||||
import { Board, BoardType } from "../../DatabaseServices/Board";
|
import { ExtureSolid } from "../../DatabaseServices/Extrude";
|
||||||
import { Circle } from "../../DatabaseServices/Circle";
|
|
||||||
import { Curve } from "../../DatabaseServices/Curve";
|
|
||||||
import { Line } from "../../DatabaseServices/Line";
|
|
||||||
import { Polyline } from "../../DatabaseServices/Polyline";
|
|
||||||
import { Command } from "../../Editor/CommandMachine";
|
import { Command } from "../../Editor/CommandMachine";
|
||||||
import { PromptStatus } from "../../Editor/PromptResult";
|
|
||||||
import { MoveMatrix } from "../../Geometry/GeUtils";
|
|
||||||
import { SpecialShapeBoardModal } from "../../UI/Components/Board/SpecialBoardModal";
|
import { SpecialShapeBoardModal } from "../../UI/Components/Board/SpecialBoardModal";
|
||||||
import { ModalPosition } from "../../UI/Components/Modal/ModalsManage";
|
import { ModalPosition } from "../../UI/Components/Modal/ModalsManage";
|
||||||
import { SpecialShapeStore } from "../../UI/Store/BoardStore";
|
import { SpecialShapeStore } from "../../UI/Store/BoardStore";
|
||||||
import { getCulistShape } from "./DrawSpecialShapeBoardTool";
|
import { ExtrudeApplyContour, SelectExtrudeContour } from "./DrawSpecialShapeBoardTool";
|
||||||
|
import { Matrix4 } from "three";
|
||||||
|
|
||||||
export class DrawSpecialShapedBoard implements Command
|
export class DrawSpecialShapedBoard implements Command
|
||||||
{
|
{
|
||||||
|
ext = new ExtureSolid();
|
||||||
async exec()
|
async exec()
|
||||||
{
|
{
|
||||||
let cuRes = await app.m_Editor.GetSelection({
|
let { contour } = await SelectExtrudeContour(false);
|
||||||
Msg: "选择对象",
|
|
||||||
Filter: { filterTypes: [Polyline, Line, Arc, Circle] }
|
|
||||||
})
|
|
||||||
if (cuRes.Status === PromptStatus.Cancel)
|
|
||||||
return;
|
|
||||||
let culist = cuRes.SelectSet.SelectEntityList as Curve[];
|
|
||||||
|
|
||||||
let shape = getCulistShape(culist, true);
|
if (contour)
|
||||||
if (shape)
|
|
||||||
{
|
{
|
||||||
shape = shape.Clone();
|
let applyMatrix4 = ExtrudeApplyContour(this.ext, contour);
|
||||||
const store = SpecialShapeStore.GetInstance();
|
let toCurve = new Matrix4().getInverse(applyMatrix4);
|
||||||
|
|
||||||
let cu = shape.Outline.Curve;
|
const store = SpecialShapeStore.GetInstance() as SpecialShapeStore;
|
||||||
let cuOcs = cu.OCS;
|
store.m_Option.height = parseFloat(FixedNotZero(this.ext.Height, 2));
|
||||||
|
store.m_Option.width = parseFloat(FixedNotZero(this.ext.Width, 2));
|
||||||
cu.ApplyMatrix(cu.OCSInv);
|
|
||||||
|
|
||||||
let box = cu.BoundingBox;
|
|
||||||
let size = box.getSize(new Vector3());
|
|
||||||
cu.ApplyMatrix(MoveMatrix(box.min.clone().negate()));
|
|
||||||
|
|
||||||
store.m_Option.height = parseFloat(FixedNotZero(size.x, 2));
|
|
||||||
store.m_Option.width = parseFloat(FixedNotZero(size.y, 2));
|
|
||||||
|
|
||||||
app.m_Editor.m_ModalManage.RenderModeless(SpecialShapeBoardModal, ModalPosition.Center, { store });
|
app.m_Editor.m_ModalManage.RenderModeless(SpecialShapeBoardModal, ModalPosition.Center, { store });
|
||||||
|
|
||||||
app.m_Editor.m_ModalManage.Callback = async () =>
|
app.m_Editor.m_ModalManage.Callback = async () =>
|
||||||
{
|
{
|
||||||
let thickness = store.m_Option.thickness;
|
let br = new Board();
|
||||||
let min = box.min.clone().setZ(-thickness);
|
br.BoardType = store.m_Option.type;
|
||||||
min.applyMatrix4(cuOcs);
|
br.ApplyMatrix(br.OCSInv);
|
||||||
|
br.Thickness = store.m_Option.thickness;
|
||||||
let length: number;
|
|
||||||
let width: number;
|
|
||||||
|
|
||||||
[length, width] = [size.y, size.x];
|
|
||||||
|
|
||||||
if (store.m_Option.type === BoardType.Layer)
|
if (store.m_Option.type === BoardType.Layer)
|
||||||
{
|
{
|
||||||
cu.ApplyMatrix(new Matrix4().makeRotationZ(-Math.PI / 2));
|
//基点修改
|
||||||
cu.ApplyMatrix(MoveMatrix(new Vector3(0, box.getSize(new Vector3()).x)));
|
toCurve.elements[12] += toCurve.elements[0] * this.ext.Width;
|
||||||
|
toCurve.elements[13] += toCurve.elements[1] * this.ext.Width;
|
||||||
[length, width] = [size.x, size.y];
|
toCurve.elements[14] += toCurve.elements[2] * this.ext.Width;
|
||||||
|
|
||||||
let xv = new Vector3();
|
//xy互换
|
||||||
let yv = new Vector3();
|
[
|
||||||
let zv = new Vector3();
|
toCurve.elements[0],
|
||||||
|
toCurve.elements[1],
|
||||||
cuOcs.extractBasis(xv, yv, zv);
|
toCurve.elements[2],
|
||||||
cuOcs.makeBasis(yv, xv.negate(), zv);
|
toCurve.elements[4],
|
||||||
|
toCurve.elements[5],
|
||||||
|
toCurve.elements[6]
|
||||||
|
]
|
||||||
|
=
|
||||||
|
[
|
||||||
|
toCurve.elements[4],
|
||||||
|
toCurve.elements[5],
|
||||||
|
toCurve.elements[6],
|
||||||
|
-toCurve.elements[0],
|
||||||
|
-toCurve.elements[1],
|
||||||
|
-toCurve.elements[2],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
br.ApplyMatrix(toCurve);
|
||||||
//创建板件
|
ExtrudeApplyContour(br, contour);
|
||||||
let br = Board.CreateBoard(length, width, thickness, store.m_Option.type);
|
|
||||||
br.Name = store.m_Option.name;
|
|
||||||
br.BoardProcessOption = store.m_BoardProcessOption;
|
|
||||||
|
|
||||||
br.ApplyMatrix(br.OCSInv);
|
|
||||||
br.ApplyMatrix(MoveMatrix(br.MinPoint.negate()));
|
|
||||||
cuOcs.setPosition(min);
|
|
||||||
br.ApplyMatrix(cuOcs);
|
|
||||||
|
|
||||||
//应用轮廓
|
|
||||||
br.Shape = shape;
|
|
||||||
|
|
||||||
br.Length = store.m_Option.height;
|
|
||||||
br.Width = store.m_Option.width;
|
|
||||||
|
|
||||||
app.m_Database.ModelSpace.Append(br);
|
app.m_Database.ModelSpace.Append(br);
|
||||||
|
|
||||||
culist.forEach(cu => cu.Erase());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
app.m_Editor.Prompt('选择对象无效')
|
app.m_Editor.Prompt('选择对象无效')
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,10 @@
|
|||||||
import { app } from "../../ApplicationServices/Application";
|
|
||||||
import { Board } from "../../DatabaseServices/Board";
|
|
||||||
import { PhysicalMaterialRecord } from "../../DatabaseServices/PhysicalMaterialRecord";
|
|
||||||
import { TextureTableRecord } from "../../DatabaseServices/Texture";
|
|
||||||
import { Command } from "../../Editor/CommandMachine";
|
|
||||||
import { HotCMD } from "../../Hot/HotCommand";
|
import { HotCMD } from "../../Hot/HotCommand";
|
||||||
|
import { Command } from "../../Editor/CommandMachine";
|
||||||
|
|
||||||
@HotCMD
|
@HotCMD
|
||||||
export class Test implements Command
|
export class Test implements Command
|
||||||
{
|
{
|
||||||
async exec()
|
async exec()
|
||||||
{
|
{
|
||||||
|
|
||||||
let texture = new TextureTableRecord();
|
|
||||||
|
|
||||||
texture.imageUrl = `https://cdn.jsdelivr.net/gh/FishOrBear/CDNResources/Default.jpg`;
|
|
||||||
texture.Name = app.m_Database.TextureTable.AllocateName();
|
|
||||||
await texture.Update();
|
|
||||||
app.m_Database.TextureTable.Add(texture);
|
|
||||||
let material = new PhysicalMaterialRecord();
|
|
||||||
material.map = texture.Id;
|
|
||||||
material.Update();
|
|
||||||
app.m_Database.MaterialTable.Add(material);
|
|
||||||
|
|
||||||
|
|
||||||
let br = new Board();
|
|
||||||
br.InitBoard(600, 1200, 18);
|
|
||||||
|
|
||||||
br.Material = material.Id;
|
|
||||||
|
|
||||||
app.m_Database.ModelSpace.Append(br);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,96 @@
|
|||||||
|
import { Vector3 } from "three";
|
||||||
|
import { ToFixed } from "../Common/Utils";
|
||||||
|
import ThreeBSP, { Polygon } from "./ThreeCSG";
|
||||||
|
interface Vec3
|
||||||
|
{
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解决 THREEBSP(CSG) 产生的结果没有办法得到分裂的个数.
|
||||||
|
* 本类分析了THREEBSP的组合情况.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* let topology = new BSPGroupParse(csg);
|
||||||
|
* topology.parse();
|
||||||
|
*/
|
||||||
|
export class BSPGroupParse
|
||||||
|
{
|
||||||
|
constructor(bsp?: ThreeBSP, public fractionDigits = 1)
|
||||||
|
{
|
||||||
|
if (bsp)
|
||||||
|
for (let poly of bsp.tree.allPolygons())
|
||||||
|
this.Add(poly);
|
||||||
|
}
|
||||||
|
Add(poly: Polygon)
|
||||||
|
{
|
||||||
|
let strs = poly.vertices.map(p => this.GenerateP(p));
|
||||||
|
let str0 = strs[0];
|
||||||
|
let s0 = this.Get(str0);
|
||||||
|
for (let i = 1; i < strs.length; i++)
|
||||||
|
{
|
||||||
|
let stri = strs[i];
|
||||||
|
s0.add(stri);
|
||||||
|
this.Get(stri).add(str0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回组合点
|
||||||
|
*/
|
||||||
|
Parse(): Vector3[][]
|
||||||
|
{
|
||||||
|
let set = new Set([...this.map.keys()]);
|
||||||
|
let res: Vector3[][] = [];
|
||||||
|
while (set.size > 0)
|
||||||
|
{
|
||||||
|
let fp = set[Symbol.iterator]().next().value;
|
||||||
|
set.delete(fp);
|
||||||
|
let cset = new Set();
|
||||||
|
cset.add(fp);
|
||||||
|
this.GetPts(fp, cset, set);
|
||||||
|
let pts = [...cset].map(str =>
|
||||||
|
{
|
||||||
|
let v3 = this.vecMap.get(str);
|
||||||
|
return new Vector3(v3.x, v3.y, v3.z);
|
||||||
|
});
|
||||||
|
res.push(pts);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
private map = new Map<string, Set<string>>();
|
||||||
|
private Get(vstr: string): Set<string>
|
||||||
|
{
|
||||||
|
if (!this.map.has(vstr))
|
||||||
|
{
|
||||||
|
let s = new Set();
|
||||||
|
this.map.set(vstr, s);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return this.map.get(vstr);
|
||||||
|
}
|
||||||
|
private GetPts(p: string, cset: Set<string>, oset: Set<string>)
|
||||||
|
{
|
||||||
|
let strs = this.map.get(p);
|
||||||
|
for (let str of strs)
|
||||||
|
{
|
||||||
|
if (!cset.has(str))
|
||||||
|
{
|
||||||
|
cset.add(str);
|
||||||
|
oset.delete(str);
|
||||||
|
this.GetPts(str, cset, oset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private vecMap = new Map();
|
||||||
|
private GenerateP(v: Vec3)
|
||||||
|
{
|
||||||
|
let str = [v.x, v.y, v.z].map(n => ToFixed(n, this.fractionDigits)).join(",");
|
||||||
|
this.vecMap.set(str, v);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue