!1554 优化:导出obj文件,使其可以导入3dmax

pull/1554/MERGE
ChenX 3 years ago
parent f88867bc64
commit 66eca6ab05

@ -1,17 +0,0 @@
import { Command } from './../Editor/CommandMachine';
import { app } from './../ApplicationServices/Application';
import { PromptStatus } from '../Editor/PromptResult';
import { ExportObj } from '../Geometry/ExportObj';
export class Command_ExportObj implements Command
{
async exec()
{
let brRes = await app.Editor.GetSelection({ UseSelect: true });
if (brRes.Status === PromptStatus.Cancel) return;
let ens = brRes.SelectSet.SelectEntityList;
ExportObj(ens);
}
}

@ -0,0 +1,62 @@
import { Box3, Group, Object3D, Vector3 } from 'three';
import { OBJExporter } from "three/examples/jsm/exporters/OBJExporter";
import { app } from '../../ApplicationServices/Application';
import { FileSystem } from '../../Common/FileSystem';
import { Hole } from '../../DatabaseServices/3DSolid/Hole';
import { Dimension } from '../../DatabaseServices/Dimension/Dimension';
import { Curve } from '../../DatabaseServices/Entity/Curve';
import { Entity } from '../../DatabaseServices/Entity/Entity';
import { Text } from '../../DatabaseServices/Text/Text';
import { PromptStatus } from '../../Editor/PromptResult';
import { VisualSpaceBox } from '../../Editor/VisualSpaceBox';
import { MoveMatrix } from '../../Geometry/GeUtils';
import { RenderType } from '../../GraphicsSystem/RenderType';
export async function ExportObj(ens: Entity[])
{
let ocsInv = ens[0].SpaceOCSInv;
let totalBox = new Box3();
ens.reduce((box, en) => box.union(en.GetBoundingBoxInMtx(ocsInv)), totalBox);
let min = totalBox.getCenter(new Vector3);
min.z = totalBox.min.z;
let mtx = MoveMatrix(min.negate()).multiply(ocsInv);
let g = new Group();
for (let b of ens)
{
let o: Object3D;
o = b.Clone().ApplyMatrix(mtx).GetDrawObjectFromRenderType(RenderType.Physical);
g.add(o);
}
g.scale.set(0.1, 0.1, 0.1);
g.updateMatrix();
g.updateMatrixWorld();
var exporter = new OBJExporter();
var result = exporter.parse(g);
FileSystem.WriteFile(`webcad.obj`, result);
}
export class Command_ExportObj
{
async exec()
{
let ssRes = await app.Editor.GetSelection({
Msg: "请选择要导出ObJ的实体(导出单位为厘米):",
UseSelect: true, Filter: {
filterFunction: (obj, ent) =>
{
if (ent instanceof Dimension || ent instanceof Curve || ent instanceof VisualSpaceBox || ent instanceof Hole || ent instanceof Text)
return false;
return true;
}
}
});
if (ssRes.Status !== PromptStatus.OK) return;
ExportObj(ssRes.SelectSet.SelectEntityList);
}
}

@ -0,0 +1,68 @@
import { Box3, Group, Object3D } from 'three';
import { app } from '../../ApplicationServices/Application';
import { FileSystem } from '../../Common/FileSystem';
import { Log } from '../../Common/Log';
import { Hole } from '../../DatabaseServices/3DSolid/Hole';
import { Dimension } from '../../DatabaseServices/Dimension/Dimension';
import { Curve } from '../../DatabaseServices/Entity/Curve';
import { Entity } from '../../DatabaseServices/Entity/Entity';
import { Text } from '../../DatabaseServices/Text/Text';
import { Command } from '../../Editor/CommandMachine';
import { PromptStatus } from '../../Editor/PromptResult';
import { VisualSpaceBox } from '../../Editor/VisualSpaceBox';
import { MoveMatrix } from '../../Geometry/GeUtils';
import { OBJExporter } from '../../Geometry/OBJExporter';
import { RenderType } from '../../GraphicsSystem/RenderType';
export class Command_ExportObjAndMtl implements Command
{
async exec()
{
Log("本命令导出的单位为米(如果需要厘米为单位,并且不需要材质的,可以使用ExportObj2命令!)");
let ssRes = await app.Editor.GetSelection({
Msg: "请选择要导出ObJ的实体(导出单位为米):",
UseSelect: true, Filter: {
filterFunction: (obj, ent) =>
{
if (ent instanceof Dimension || ent instanceof Curve || ent instanceof VisualSpaceBox || ent instanceof Hole || ent instanceof Text)
return false;
return true;
}
}
});
if (ssRes.Status !== PromptStatus.OK) return;
ExportObj(ssRes.SelectSet.SelectEntityList);
}
}
export async function ExportObj(brs: Entity[])
{
let ocsInv = brs[0].SpaceOCSInv;
let totalBox = new Box3();
brs.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 brs)
{
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();
var exporter = new OBJExporter();
var result = exporter.parse(g);
FileSystem.WriteFile(`file.obj`, result.obj);
FileSystem.WriteFile(`file.mtl`, result.mtl);
}

@ -183,6 +183,7 @@ export enum CommandNames
ClearRef = "CLEARRELEVANCE",
Clear2DModeling = "CLEAR2DMODELING",
ExportObj = "EXPORTOBJ",
ExportobjMtl = "EXPORTOBJMTL",
ExportObj2 = "EXPORTOBJ2",
ExportSTL = "EXPORTSTL",
UpdateBoardInfos = "UPDATEBOARDINFOS",

@ -357,13 +357,19 @@ export class ExtrudeHole extends Hole
{
return new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(this.ColorIndex));
}
else if (renderType === RenderType.Conceptual || renderType === RenderType.Physical || renderType === RenderType.Physical2)
else if (renderType === RenderType.Conceptual || renderType === RenderType.Physical2)
{
return new Object3D().add(
new Mesh(this.MeshGeometry, ColorMaterial.GetConceptualMaterial(this.ColorIndex)),
new LineSegments(this.EdgeGeometry, ColorMaterial.GetLineMaterial(7))
);
}
else if (renderType === RenderType.Physical)
{
return new Object3D().add(
new Mesh(this.MeshGeometry, ColorMaterial.GetConceptualMaterial(this.ColorIndex))
);
}
else if (renderType === RenderType.Jig)
{
return new Object3D().add(...FastWireframe2(this));

@ -32,7 +32,6 @@ import { CombinatAttributeBrush } from "../Add-on/CombinatAttributeBrush";
import { FeedingCommand } from "../Add-on/CommandFeeding";
import { Command_CombineEntity } from "../Add-on/Command_CombineEntity";
import { Command_CommandPanel } from "../Add-on/Command_CommandPanel";
import { Command_ExportObj } from "../Add-on/Command_ExportObj";
import { Command_Options } from "../Add-on/Command_Option";
import { Command_Purge } from "../Add-on/Command_Purge";
import { Command_SetBRXAxis } from "../Add-on/Command_SetBRXAxis";
@ -143,6 +142,8 @@ import { LookOverBoardInfos } from "../Add-on/LookOverBoardInfos/LookOverBoardIn
import { MirrorCommand } from "../Add-on/Mirror";
import { Command_Move } from "../Add-on/Move";
import { Command_M0, Command_PackageMove } from "../Add-on/MoveToWCS0";
import { Command_ExportObj } from "../Add-on/Obj/Command_ExportObj";
import { Command_ExportObjAndMtl } from "../Add-on/Obj/Command_ExportObjMtl";
import { Command_DynOffset, Command_DynOffsetToolPath, Command_Offset } from "../Add-on/Offset";
import { OffsetX } from "../Add-on/OffsetX";
import { Open } from "../Add-on/Open";
@ -215,7 +216,6 @@ import { Command_ZoomObject, ZoomE } from "../Add-on/ZoomE";
import { CommandNames } from "../Common/CommandNames";
import { IsTest } from "../Common/Deving";
import { CommandServer, UpgradeData } from '../DatabaseServices/CommandServer';
import { Command_ExportObj2 } from "../Geometry/ExportObj2";
import { RenderType } from "../GraphicsSystem/RenderType";
import { Command_TestContainer } from "../Nest/Test/TestContainer";
import { Command_TestDrawYHData } from "../Nest/Test/TestDrawYHData";
@ -604,8 +604,8 @@ export function registerCommand()
commandMachine.RegisterCommand(CommandNames.SetSmoothEdge, new SetSmoothEdge());
commandMachine.RegisterCommand(CommandNames.ClearRef, new DeleteRelevance());
commandMachine.RegisterCommand(CommandNames.Clear2DModeling, new Command_ClearBoard2DModeling());
commandMachine.RegisterCommand("exportobj", new Command_ExportObj());
commandMachine.RegisterCommand("exportobj2", new Command_ExportObj2());
commandMachine.RegisterCommand(CommandNames.ExportobjMtl, new Command_ExportObjAndMtl());
commandMachine.RegisterCommand(CommandNames.ExportObj, new Command_ExportObj());
commandMachine.RegisterCommand("ExportSTL", new Command_ExportSTL());
commandMachine.RegisterCommand(CommandNames.UpdateBoardInfos, new UpdateBoardInfos());

@ -1,72 +0,0 @@
import { Group, Box3, Object3D } from 'three';
import { FileSystem } from './../Common/FileSystem';
import { Entity } from './../DatabaseServices/Entity/Entity';
import { OBJExporter } from './OBJExporter';
import { userConfig } from './../Editor/UserConfig';
import { RenderType } from '../GraphicsSystem/RenderType';
import { MoveMatrix } from './GeUtils';
import { AppToaster } from '../UI/Components/Toaster';
import * as React from 'react';
export async function ExportObj(brs: Entity[])
{
let ocsInv = brs[0].SpaceOCSInv;
let totalBox = new Box3();
brs.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 brs)
{
let o: Object3D;
if (userConfig.RenderType === RenderType.Physical)
{
o = b.Clone().ApplyMatrix(mtx).GetDrawObjectFromRenderType(RenderType.Physical);
}
else
{
o = b.Clone().ApplyMatrix(mtx).GetDrawObjectFromRenderType(RenderType.Conceptual);
}
g.add(o);
}
g.scale.set(1e-3, 1e-3, 1e-3);
g.updateMatrix();
g.updateMatrixWorld();
var exporter = new OBJExporter();
var result = exporter.parse(g);
FileSystem.WriteFile(`file.obj`, result.obj);
FileSystem.WriteFile(`file.mtl`, result.mtl);
//生成地址二维码
// await uploadObj(result);
}
async function uploadObj(result)
{
let blob = new Blob([result.obj], { type: "octet/stream" });
let formData = new FormData();
formData.append("files", blob);
let res = await fetch("http://www.dodream.wang:3333/upload", {
method: "POST",
mode: "cors",
credentials: "include",
body: formData,
});
let data = await res.json();
if (data.code === 200)
{
AppToaster.show({
message: React.createElement('img', { src: data.data.code }),
timeout: 0
});
}
}

@ -1,49 +0,0 @@
import { Box3, Group, Object3D, Vector3 } from 'three';
import { OBJExporter } from "three/examples/jsm/exporters/OBJExporter";
import { app } from '../ApplicationServices/Application';
import { FileSystem } from '../Common/FileSystem';
import { Entity } from '../DatabaseServices/Entity/Entity';
import { PromptStatus } from '../Editor/PromptResult';
import { RenderType } from '../GraphicsSystem/RenderType';
import { MoveMatrix } from './GeUtils';
export async function ExportObj(brs: Entity[])
{
let ocsInv = brs[0].SpaceOCSInv;
let totalBox = new Box3();
brs.reduce((box, en) => box.union(en.GetBoundingBoxInMtx(ocsInv)), totalBox);
let min = totalBox.getCenter(new Vector3);
min.z = totalBox.min.z;
let mtx = MoveMatrix(min.negate()).multiply(ocsInv);
let g = new Group();
for (let b of brs)
{
let o: Object3D;
o = b.Clone().ApplyMatrix(mtx).GetDrawObjectFromRenderType(RenderType.Physical);
g.add(o);
}
g.scale.set(0.1, 0.1, 0.1);
g.updateMatrix();
g.updateMatrixWorld();
var exporter = new OBJExporter();
var result = exporter.parse(g);
FileSystem.WriteFile(`webcad.obj`, result);
}
export class Command_ExportObj2
{
async exec()
{
let brRes = await app.Editor.GetSelection({ UseSelect: true });
if (brRes.Status === PromptStatus.Cancel) return;
let ens = brRes.SelectSet.SelectEntityList;
ExportObj(ens);
}
}

@ -1,6 +1,6 @@
import { IconEnum } from "../../IconEnum";
import { CommandNames } from "../../../Common/CommandNames";
import { HotkeyList } from "../../../Common/HotKeyList";
import { IconEnum } from "../../IconEnum";
/**
*
* ,,
@ -2035,6 +2035,24 @@ export const CommandList: ICommand[] = [
chName: "解除编组",
chDes: "解除编组",
},
{
typeId: "file",
link: `#`,
defaultCustom: CommandNames.ExportobjMtl,
command: CommandNames.ExportobjMtl,
type: "文件",
chName: "导出obj文件",
chDes: "导出obj文件(包括材质),单位:米",
},
{
typeId: "file",
link: `#`,
defaultCustom: CommandNames.ExportObj,
command: CommandNames.ExportObj,
type: "文件",
chName: "导出obj文件",
chDes: "导出obj文件(单位:厘米)",
},
//模板
{

Loading…
Cancel
Save