mirror of https://gitee.com/cf-fz/WebCAD.git
parent
e259535c94
commit
541654f571
@ -0,0 +1,46 @@
|
||||
import { Box3, Group, Object3D } from 'three';
|
||||
import { STLExporter } from 'three/examples/jsm/exporters/STLExporter.js';
|
||||
import { ColladaExporter } from 'three/examples/jsm/exporters/ColladaExporter';
|
||||
import { app } from '../../ApplicationServices/Application';
|
||||
import { FileSystem } from '../../Common/FileSystem';
|
||||
import { Entity } from '../../DatabaseServices/Entity/Entity';
|
||||
import { PromptStatus } from '../../Editor/PromptResult';
|
||||
import { MoveMatrix } from '../../Geometry/GeUtils';
|
||||
import { RenderType } from '../../GraphicsSystem/RenderType';
|
||||
export class Command_ExportSTL
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let ssRes = await app.Editor.GetSelection({ Filter: { filterTypes: [Entity] } });
|
||||
if (ssRes.Status !== PromptStatus.OK) return;
|
||||
let ents = ssRes.SelectSet.SelectEntityList;
|
||||
let exporter = new STLExporter();
|
||||
let ocsInv = ents[0].SpaceOCSInv;
|
||||
let totalBox = new Box3();
|
||||
ents.reduce((box, en) =>
|
||||
{
|
||||
return box.union(en.GetBoundingBoxInMtx(ocsInv));
|
||||
}, totalBox);
|
||||
|
||||
let min = totalBox.min;
|
||||
let mtx = MoveMatrix(min.negate()).multiply(ocsInv);
|
||||
|
||||
let g = new Group();
|
||||
|
||||
for (let b of ents)
|
||||
{
|
||||
let o: Object3D;
|
||||
o = b.Clone().ApplyMatrix(mtx).GetDrawObjectFromRenderType(RenderType.Physical);
|
||||
g.add(o);
|
||||
}
|
||||
|
||||
g.scale.set(1e-3, 1e-3, 1e-3);
|
||||
g.updateMatrix();
|
||||
g.updateMatrixWorld();
|
||||
let result = exporter.parse(g, { binary: true });
|
||||
FileSystem.WriteFile("webcad.stl", result);
|
||||
// let exporter2 = new ColladaExporter();
|
||||
// let r2 = exporter2.parse(g, () => { }, {});
|
||||
// FileSystem.WriteFile("webcad.dae", r2.data);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue