mirror of https://gitee.com/cf-fz/WebCAD.git
!744 干涉检查
parent
13ce190406
commit
9e5f7a5855
@ -0,0 +1,132 @@
|
||||
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { Mesh, Vector3 } from 'three';
|
||||
import { app } from '../ApplicationServices/Application';
|
||||
import { DisposeThreeObj } from '../Common/Dispose';
|
||||
import { CylinderHole } from '../DatabaseServices/3DSolid/CylinderHole';
|
||||
import { Entity } from '../DatabaseServices/Entity/Entity';
|
||||
import { ExtrudeSolid } from '../DatabaseServices/Entity/Extrude';
|
||||
import { PromptStatus } from '../Editor/PromptResult';
|
||||
import { userConfig } from '../Editor/UserConfig';
|
||||
import { RenderType } from '../GraphicsSystem/RenderType';
|
||||
import { InterfereModal } from '../UI/Components/Modal/InterfereModal';
|
||||
import { ModalPosition } from '../UI/Components/Modal/ModalsManage';
|
||||
import { ColorMaterial } from './../Common/ColorPalette';
|
||||
import { CSG } from './../csg/core/CSG';
|
||||
import { CSG2Geometry, Geometry2CSG } from './../csg/core/Geometry2CSG';
|
||||
import { FastDrillingMeshGeometry } from './../DatabaseServices/3DSolid/CylinderHole';
|
||||
import { ExtrudeHole } from './../DatabaseServices/3DSolid/ExtrudeHole';
|
||||
import { SweepSolid } from './../DatabaseServices/3DSolid/SweepSolid';
|
||||
import { Command } from './../Editor/CommandMachine';
|
||||
import { AppToaster } from './../UI/Components/Toaster';
|
||||
|
||||
//| CylinderHole | ExtrudeHole
|
||||
export type Solid3D = ExtrudeSolid | SweepSolid | ExtrudeHole;
|
||||
|
||||
export class Interfere implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
const Filter = {
|
||||
filterTypes: [ExtrudeHole, ExtrudeSolid, SweepSolid]
|
||||
};
|
||||
|
||||
let enRes = await app.Editor.GetSelection({
|
||||
Msg: "选择检查干涉的对象",
|
||||
Filter
|
||||
});
|
||||
|
||||
if (enRes.Status === PromptStatus.Cancel) return;
|
||||
|
||||
let ens = enRes.SelectSet.SelectEntityList as Solid3D[];
|
||||
let set1 = new Set();
|
||||
let objMap: Map<Mesh, [Solid3D, Solid3D]> = new Map();
|
||||
const csgCache: WeakMap<Entity, CSG> = new WeakMap();
|
||||
|
||||
for (let i = 0; i < ens.length; i++)
|
||||
{
|
||||
let e1 = ens[i];
|
||||
|
||||
let c1: CSG;
|
||||
if (csgCache.has(e1))
|
||||
c1 = csgCache.get(e1);
|
||||
else
|
||||
c1 = this.GetCSG(e1);
|
||||
|
||||
let obb1 = e1.OBB;
|
||||
|
||||
for (let j = i + 1; j < ens.length; j++)
|
||||
{
|
||||
let e2 = ens[j];
|
||||
if (!obb1.intersectsOBB(e2.OBB))
|
||||
continue;
|
||||
|
||||
let c2: CSG;
|
||||
if (csgCache.has(e2))
|
||||
c2 = csgCache.get(e2);
|
||||
else
|
||||
{
|
||||
c2 = this.GetCSG(e2);
|
||||
csgCache.set(e2, c2);
|
||||
}
|
||||
|
||||
if (!c2)
|
||||
console.error("实体CSG出错");
|
||||
|
||||
let c = c1.intersect(c2.transform1(e1.OCSInv.multiply(e2.OCS)));
|
||||
|
||||
if (c.polygons.length > 0)
|
||||
{
|
||||
set1.add(e1);
|
||||
set1.add(e2);
|
||||
let g = CSG2Geometry(c).applyMatrix4(e1.OCS);
|
||||
g.computeBoundingBox();
|
||||
if (g.boundingBox.getSize(new Vector3).toArray().every(n => n > 1 - 1e-3))
|
||||
{
|
||||
let m = new Mesh(g, ColorMaterial.GetBasicMaterial(1).clone());
|
||||
objMap.set(m, [e1, e2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (objMap.size === 0)
|
||||
{
|
||||
AppToaster.show({
|
||||
message: "未找到干涉对象",
|
||||
timeout: 2000,
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
for (let [o,] of objMap)
|
||||
{
|
||||
app.Viewer.Scene.add(o);
|
||||
}
|
||||
let oldType = userConfig.RenderType;
|
||||
userConfig.RenderType = RenderType.Wireframe;
|
||||
|
||||
app.Editor.ModalManage.RenderModeless(InterfereModal, ModalPosition.Center, { count: set1.size, data: objMap });
|
||||
|
||||
await app.Editor.ModalManage.Wait();
|
||||
|
||||
for (let [o,] of objMap)
|
||||
{
|
||||
DisposeThreeObj(o);
|
||||
app.Viewer.Scene.remove(o);
|
||||
}
|
||||
|
||||
userConfig.RenderType = oldType;
|
||||
}
|
||||
private GetCSG(en: Solid3D)
|
||||
{
|
||||
if (en instanceof ExtrudeSolid)
|
||||
{
|
||||
return en.CSG;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Geometry2CSG(en.MeshGeometry);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue