diff --git a/src/Add-on/ACAD/DxfEntityConvert.ts b/src/Add-on/ACAD/DxfEntityConvert.ts index c9d269d27..f0e980dd9 100644 --- a/src/Add-on/ACAD/DxfEntityConvert.ts +++ b/src/Add-on/ACAD/DxfEntityConvert.ts @@ -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) diff --git a/src/Add-on/DXFLoad.ts b/src/Add-on/DXFLoad.ts index 6229fcfdc..cb73f46df 100644 --- a/src/Add-on/DXFLoad.ts +++ b/src/Add-on/DXFLoad.ts @@ -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,31 +33,28 @@ export class Command_DWGDXFImport export async function DwgDxfImport(f: File) { let ext = arrayLast(f.name.split(".")).toUpperCase(); + let dxfStr: string; if (ext === "DXF") - { - let str = await FileSystem.ReadFileAsText(f); - - for (let e of Dxf2Entitys(str)) - Draw(e); - - AppToaster.show({ - message: `成功导入${f.name}`, - intent: Intent.SUCCESS, - timeout: 3000, - }); - return true; - } + dxfStr = await FileSystem.ReadFileAsText(f); else if (ext === "DWG") + dxfStr = await Dwg2Dxf(f); + + let size = new Vector3; + for (let e of Dxf2Entitys(dxfStr)) { - let dxfStr = await Dwg2Dxf(f); - for (let e of Dxf2Entitys(dxfStr)) - Draw(e); + //校验实体有效性 避免出现nan的情况 + let obj = e.DrawObject; + GetBox(obj).getSize(size); + if (isNaN(size.x) || isNaN(size.y) || isNaN(size.z)) + continue; - AppToaster.show({ - message: `成功导入${f.name}`, - intent: Intent.SUCCESS, - timeout: 3000, - }); - return true; + Draw(e); } + + AppToaster.show({ + message: `成功导入${f.name}`, + intent: Intent.SUCCESS, + timeout: 3000, + }); + return true; }