mirror of https://gitee.com/cf-fz/WebCAD.git
!1554 优化:导出obj文件,使其可以导入3dmax
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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue