命令:ExportSTL

pull/1031/head
ChenX 4 years ago
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);
}
}

@ -178,6 +178,7 @@ import { Command_Conver2Polyline } from "../Add-on/Conver2Polyline";
import { Command_Curve2VSBox } from "../Add-on/twoD2threeD/Command_Curve2VSBox";
import { Command_ToggleUI } from "../Add-on/ToggleUI";
import { Command_ExportObj2 } from "../Geometry/ExportObj2";
import { Command_ExportSTL } from "../Add-on/Exports/ExportSTL";
export function registerCommand()
{
@ -486,6 +487,7 @@ export function registerCommand()
commandMachine.RegisterCommand("clearrelevance", new DeleteRelevance());
commandMachine.RegisterCommand("exportobj", new Command_ExportObj());
commandMachine.RegisterCommand("exportobj2", new Command_ExportObj2());
commandMachine.RegisterCommand("ExportSTL", new Command_ExportSTL());
commandMachine.RegisterCommand("updateboardinfos", new UpdateBoardInfos());

Loading…
Cancel
Save