diff --git a/package.json b/package.json index a66255d..aa40bd7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "material-editor", "private": true, - "version": "1.0.19", + "version": "1.0.20", "type": "module", "scripts": { "dev": "vite", diff --git a/src/common/MaterialSerializer.ts b/src/common/MaterialSerializer.ts index 59e3044..9ab6577 100644 --- a/src/common/MaterialSerializer.ts +++ b/src/common/MaterialSerializer.ts @@ -1,4 +1,4 @@ -import { CADFiler, CADObject, Database, DuplicateRecordCloning, Factory, LayerNode, ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api"; +import { CADFactory, CADFiler, CADObject, Database, DuplicateRecordCloning, Factory, LayerNode, ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api"; // TODO: Danger: 注意入侵性代码 // 疑似是WebCAD中的漏洞,当传入new Database()时, @@ -14,26 +14,22 @@ Database.prototype.AllocationObjectId = function (this: Database, object: CADObj this.idMap.set(object.Id.Index, object.Id); } -export function MaterialOut(material: PhysicalMaterialRecord): string -{ - try { - let db = new Database(); - db.WblockCloneObejcts( - [material], - db.MaterialTable, - new Map(), - DuplicateRecordCloning.Ignore - ); - let json = JSON.stringify(db.FileWrite().Data); - // // TODO: Danger: 因为WebCAD依赖库中的部分类的构造函数名异常,所以在生成JSON时需要对类名进行替换 - json = json.replace(LayerNode.name, "LayerNode") - .replace(TextureTableRecord.name, "TextureTableRecord") - .replace(PhysicalMaterialRecord.name, "PhysicalMaterialRecord"); - return json; - } catch (error) { - console.error("error in MaterialOut:", error, material); - throw error; - } +export function MaterialOut(material: PhysicalMaterialRecord): string { + let db = new Database(); + db.WblockCloneObejcts( + [material], + db.MaterialTable, + new Map(), + DuplicateRecordCloning.Ignore + ); + let json = JSON.stringify(db.FileWrite().Data); + // // TODO: Danger: 因为WebCAD依赖库中的部分类的构造函数名异常,所以在生成JSON时需要对类名进行替换 + json = json.replace(LayerNode.name, "LayerNode") + .replace(TextureTableRecord.name, "TextureTableRecord") + .replace(PhysicalMaterialRecord.name, "PhysicalMaterialRecord"); + console.debug("DEBUG CAD Object Name", CADFactory['factory'].objectNameMap); + console.debug("CURRENT PROTOTYPE NAME\n", "LAYERNODE:", LayerNode.name, "TEXTURETABLERECORD:", TextureTableRecord.name, "PHYSICALMATERIALRECORD:", PhysicalMaterialRecord.name); + return json; } export function MaterialIn(fileData: Object[]): PhysicalMaterialRecord