修复:DXF导入因为块缩放导致的图纸错误

pull/1881/MERGE
ChenX 2 years ago
parent bcd0384499
commit c648614f25

@ -296,8 +296,8 @@ export function Conver2WebCADEntity(en: IEntity, doc: IDxf, ents: Entity[]): voi
mtx.multiply(new Matrix4().makeRotationZ(MathUtils.DEG2RAD * blkRef.rotation));
let scaleMtx: Matrix4;
if (blkRef.xScale)
scaleMtx = new Matrix4().makeScale(blkRef.xScale, blkRef.yScale, blkRef.zScale);
if (blkRef.xScale || blkRef.yScale || blkRef.zScale) //值可能为undefined
scaleMtx = new Matrix4().makeScale(blkRef.xScale ?? 1, blkRef.yScale ?? blkRef.xScale ?? 1, blkRef.zScale ?? blkRef.xScale ?? 1);
let blk = doc.blocks[blkRef.name];
if (blk)

@ -1,8 +1,10 @@
import { Intent } from "@blueprintjs/core";
import { Vector3 } from "three";
import { arrayLast } from "../Common/ArrayExt";
import { Draw } from "../Common/Draw";
import { FileSystem } from "../Common/FileSystem";
import { CommandWrap } from "../Editor/CommandMachine";
import { GetBox } from "../Geometry/GeUtils";
import { AppToaster } from "../UI/Components/Toaster";
import { Dxf2Entitys } from "./ACAD/DxfEntityConvert";
import { Dwg2Dxf } from "./DwgLoader/DwgLoader";
@ -31,25 +33,23 @@ export class Command_DWGDXFImport
export async function DwgDxfImport(f: File)
{
let ext = arrayLast(f.name.split(".")).toUpperCase();
let dxfStr: string;
if (ext === "DXF")
dxfStr = await FileSystem.ReadFileAsText(f);
else if (ext === "DWG")
dxfStr = await Dwg2Dxf(f);
let size = new Vector3;
for (let e of Dxf2Entitys(dxfStr))
{
let str = await FileSystem.ReadFileAsText(f);
//校验实体有效性 避免出现nan的情况
let obj = e.DrawObject;
GetBox(obj).getSize(size);
if (isNaN(size.x) || isNaN(size.y) || isNaN(size.z))
continue;
for (let e of Dxf2Entitys(str))
Draw(e);
AppToaster.show({
message: `成功导入${f.name}`,
intent: Intent.SUCCESS,
timeout: 3000,
});
return true;
}
else if (ext === "DWG")
{
let dxfStr = await Dwg2Dxf(f);
for (let e of Dxf2Entitys(dxfStr))
Draw(e);
AppToaster.show({
message: `成功导入${f.name}`,
@ -58,4 +58,3 @@ export async function DwgDxfImport(f: File)
});
return true;
}
}

Loading…
Cancel
Save