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,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 { Command } from "../../Editor/CommandMachine";
|
||||
|
||||
@HotCMD
|
||||
export class Test implements Command
|
||||
{
|
||||
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