diff --git a/src/Add-on/Room/DrawRectWall.ts b/src/Add-on/Room/DrawRectWall.ts index 971c15a05..1e9592308 100644 --- a/src/Add-on/Room/DrawRectWall.ts +++ b/src/Add-on/Room/DrawRectWall.ts @@ -22,7 +22,7 @@ export class Command_DrawRectWall implements Command _DrawDirMode: WallDirMode = WallDirMode.Inside; async exec() { - if (! await FixDrawWallDir()) return; + if (!await FixDrawWallDir()) return; this._parse = undefined; diff --git a/src/Add-on/Room/DrawWall.ts b/src/Add-on/Room/DrawWall.ts index 5c8f47214..9b8bdd7df 100644 --- a/src/Add-on/Room/DrawWall.ts +++ b/src/Add-on/Room/DrawWall.ts @@ -333,7 +333,7 @@ export class Command_DrawWallInside implements Command WallThickness = 240; async exec() { - if (! await FixDrawWallDir()) return; + if (!await FixDrawWallDir()) return; this.model = WallMode.Line; diff --git a/src/Add-on/Room/FixDrawWallDir.ts b/src/Add-on/Room/FixDrawWallDir.ts index e9cbd9cab..78eaaaac7 100644 --- a/src/Add-on/Room/FixDrawWallDir.ts +++ b/src/Add-on/Room/FixDrawWallDir.ts @@ -1,10 +1,15 @@ import { Intent } from "@blueprintjs/core"; import { Vector3 } from "three"; import { app } from "../../ApplicationServices/Application"; +import { DefaultParamMap, SetMaterialParams } from "../../DatabaseServices/IMaterialDefaultParam"; +import { PhysicalMaterialRecord } from "../../DatabaseServices/PhysicalMaterialRecord"; import { equalv3, isPerpendicularityTo, ZAxis, ZAxisN } from "../../Geometry/GeUtils"; import { AppToaster } from "../../UI/Components/Toaster"; +import ResourceStore from "../../UI/Components/ToolBar/ResourceLibrary/RsourceStore"; import { ViewChange } from "../ViewChange"; + +//同时自动创建默认的墙体和地面材质 export async function FixDrawWallDir(): Promise { if (app.Viewer.isLayout) @@ -51,5 +56,46 @@ export async function FixDrawWallDir(): Promise app.Editor.SetUCSLookAt(new Vector3(0, 0, -1)); } + + if (!app.Database.MaterialTable.CurFloorMtl) + { + let mtl = await ResourceStore.GetInstance().PraseMaterial("/瓷砖/Inst_瓷砖_79"); + app.Database.MaterialTable.CurFloorMtl = mtl.Id; + + AppToaster.show({ + message: "成功创建地板默认材质(可以在右侧材质面板,右键设置其他的地板默认材质!)", + timeout: 5000, + intent: Intent.SUCCESS, + }); + } + + if (!app.Database.MaterialTable.CurWallMtl) + { + for (let [, mtl] of app.Database.MaterialTable.Materials) + { + if (mtl.type === "乳胶漆") + { + app.Database.MaterialTable.CurWallMtl = mtl.Id; + break; + } + } + + if (!app.Database.MaterialTable.CurWallMtl) + { + let mtl = new PhysicalMaterialRecord; + SetMaterialParams(mtl, DefaultParamMap.乳胶漆); + mtl.Name = "乳胶漆"; + app.Database.MaterialTable.Add(mtl); + + app.Database.MaterialTable.CurWallMtl = mtl.Id; + + AppToaster.show({ + message: "成功创建墙面默认材质(可以在右侧材质面板,右键设置其他的地板默认材质!)", + timeout: 5000, + intent: Intent.SUCCESS, + }); + } + } + return true; } diff --git a/src/DatabaseServices/BlockTableRecord.ts b/src/DatabaseServices/BlockTableRecord.ts index fcabae09d..1aee62bd7 100644 --- a/src/DatabaseServices/BlockTableRecord.ts +++ b/src/DatabaseServices/BlockTableRecord.ts @@ -6,6 +6,9 @@ import { Database } from './Database'; import { Dimension } from './Dimension/Dimension'; import { Entity } from './Entity/Entity'; import { ObjectCollection } from './ObjectCollection'; +import { RoomFlatFloor } from './Room/Entity/Flat/RoomFlatFloor'; +import { RoomFlatTop } from './Room/Entity/Flat/RoomFlatTop'; +import { RoomWallBase } from './Room/Entity/Wall/RoomWallBase'; import { SymbolTableRecord } from './SymbolTableRecord'; @Factory @@ -37,8 +40,23 @@ export class BlockTableRecord extends SymbolTableRecord Append(entity: Entity, isCheckObjectCleanly = true) { if (this._db) - if (entity instanceof Dimension && !entity.DimStyle) - entity.DimStyle = this._db.DimStyleTable.Current;//设置默认的标注样式 + { + if (entity instanceof Dimension) + { + if (!entity.DimStyle) + entity.DimStyle = this._db.DimStyleTable.Current;//设置默认的标注样式 + } + else if (entity instanceof RoomWallBase || entity instanceof RoomFlatTop) + { + if (!entity.Material) + entity.Material = this._db.MaterialTable.CurWallMtl; + } + else if (entity instanceof RoomFlatFloor) + { + if (!entity.Material) + entity.Material = this._db.MaterialTable.CurFloorMtl; + } + } this.EntityCol.Append(entity, isCheckObjectCleanly); entity.Owner = this.objectId; diff --git a/src/DatabaseServices/MaterialTable.ts b/src/DatabaseServices/MaterialTable.ts index 5da6cdb7c..fa61654f1 100644 --- a/src/DatabaseServices/MaterialTable.ts +++ b/src/DatabaseServices/MaterialTable.ts @@ -1,8 +1,30 @@ -import { SymbolTable } from "./SymbolTable"; +import { CADFiler } from "./CADFiler"; +import { ObjectId } from "./ObjectId"; import { PhysicalMaterialRecord } from "./PhysicalMaterialRecord"; +import { SymbolTable } from "./SymbolTable"; export class MaterialTable extends SymbolTable { + protected _CurFloorMtl: ObjectId;//默认地板材质 + protected _CurWallMtl: ObjectId;//默认墙体材质 + + get CurFloorMtl() { return this._CurFloorMtl; } + get CurWallMtl() { return this._CurWallMtl; } + + + set CurFloorMtl(id) + { + if (id === this._CurFloorMtl) return; + this.WriteAllObjectRecord(); + this._CurFloorMtl = id; + } + + set CurWallMtl(id) + { + if (id === this._CurWallMtl) return; + this.WriteAllObjectRecord(); + this._CurWallMtl = id; + } get Materials() { @@ -28,4 +50,27 @@ export class MaterialTable extends SymbolTable { return super.AllocateName(name); } + + //#region -------------------------File------------------------- + //对象从文件中读取数据,初始化自身 + override ReadFile(file: CADFiler) + { + super.ReadFile(file); + + if (this._FileVer > 2) + { + this._CurFloorMtl = file.ReadObjectId(); + this._CurWallMtl = file.ReadObjectId(); + } + } + + //对象将自身数据写入到文件. + override WriteFile(file: CADFiler) + { + super.WriteFile(file); + + file.WriteObjectId(this._CurFloorMtl); + file.WriteObjectId(this._CurWallMtl); + } + //#endregion } diff --git a/src/DatabaseServices/SymbolTable.ts b/src/DatabaseServices/SymbolTable.ts index a512a2d82..549d59523 100644 --- a/src/DatabaseServices/SymbolTable.ts +++ b/src/DatabaseServices/SymbolTable.ts @@ -85,11 +85,13 @@ export class SymbolTable extends CADObject return true; } + protected _FileVer = 0; //#region -------------------------File------------------------- ReadFile(file: CADFiler) { super.ReadFile(file); let ver = file.Read(); + this._FileVer = ver; let count = file.Read(); this.Symbols.clear(); for (let i = 0; i < count; i++) @@ -104,7 +106,7 @@ export class SymbolTable extends CADObject WriteFile(file: CADFiler) { super.WriteFile(file); - file.Write(2); + file.Write(3); file.Write(this.Symbols.size); for (let [key, record] of this.Symbols) { diff --git a/src/UI/Components/ToolBar/ResourceLibrary/Resource_ResourceList.tsx b/src/UI/Components/ToolBar/ResourceLibrary/Resource_ResourceList.tsx index cd4af1868..d2f14fd9f 100644 --- a/src/UI/Components/ToolBar/ResourceLibrary/Resource_ResourceList.tsx +++ b/src/UI/Components/ToolBar/ResourceLibrary/Resource_ResourceList.tsx @@ -460,7 +460,7 @@ export class ResourceItem extends Component<{ module: ModuleData; }, {}> if (!module_detail) return; CommandWrap(async () => { - let material = await this.resourceStore.PraseMaterial(module_detail); + let material = await this.resourceStore.PraseMaterial(module_detail.path); let count = 0; let brCount = 0; for (let en of app.Editor.SelectCtrl.SelectSet.SelectEntityList) diff --git a/src/UI/Components/ToolBar/ResourceLibrary/RsourceStore.ts b/src/UI/Components/ToolBar/ResourceLibrary/RsourceStore.ts index 6ec8c3ac4..2f9d2c74f 100644 --- a/src/UI/Components/ToolBar/ResourceLibrary/RsourceStore.ts +++ b/src/UI/Components/ToolBar/ResourceLibrary/RsourceStore.ts @@ -32,7 +32,7 @@ import { DynamicInputManage } from "../../../DynamicPrompt/DynamicInputManage"; import { PromptBlock } from "../../../DynamicPrompt/PromptBlock"; import { InsertTemplateByBasePoint } from "../../Template/InsertTemplateByBasePoint"; import { AppToaster } from "../../Toaster"; -import { Folder, ModuleData, ModuleDetail, ModuleSource, ResourceBrands, ResourceClass, ResourceParams, ResType } from "./ResourceInterfaces"; +import { Folder, ModuleData, ModuleSource, ResourceBrands, ResourceClass, ResourceParams, ResType } from "./ResourceInterfaces"; import { ResourcePanelType } from "./ResourcePanel"; import { getClassList, getModuleDetail, getModuleList, GetUserCollectDir, GetUserCollection } from "./ResourcesData"; @@ -136,7 +136,7 @@ export default class ResourceStore { if (module_detail.type === ResType.Mtl) { - let mtl = await this.PraseMaterial(module_detail); + let mtl = await this.PraseMaterial(module_detail.path); for (let o of selectObj) { let en = GetEntity(o); @@ -322,13 +322,13 @@ export default class ResourceStore }, module_detail.type === ResType.Mtl ? CommandNames.ApplyMtl : "绘制模型"); }; - PraseMaterial = async (module_detail: ModuleDetail) => + PraseMaterial = async (mtlPath: string) => { - let name = ParseUrlName(module_detail.path); + let name = ParseUrlName(mtlPath); let mtl = app.Database.MaterialTable.GetAt(name); if (!mtl) { - let url = "/Data/MAT_INST基础材质库" + module_detail.path; + let url = "/Data/MAT_INST基础材质库" + mtlPath; let dataString = await (await fetch(GenerateCdnUrl(`/Paks/paks_cooked/ue_resource/Content${encodeURI(url)}.json`))).text(); let data = JSON.parse(dataString); @@ -340,7 +340,7 @@ export default class ResourceStore mtl.transparent = false; mtl.opacity = 1; mtl.bumpScale = 0.0005; - mtl.ref = module_detail.path; + mtl.ref = mtlPath; let color = new Color; let texturePath = data.baseColor_texturePath as string; diff --git a/src/UI/Components/ToolBar/ResourceLibrary/UserCollect.tsx b/src/UI/Components/ToolBar/ResourceLibrary/UserCollect.tsx index f9c008f94..372f9a5ab 100644 --- a/src/UI/Components/ToolBar/ResourceLibrary/UserCollect.tsx +++ b/src/UI/Components/ToolBar/ResourceLibrary/UserCollect.tsx @@ -117,7 +117,7 @@ export default class UserCollect extends Component<{}, {}> if (!module_detail) return; CommandWrap(async () => { - let material = await this.resourceStore.PraseMaterial(module_detail); + let material = await this.resourceStore.PraseMaterial(module_detail.path); let count = 0; let brCount = 0; for (let en of app.Editor.SelectCtrl.SelectSet.SelectEntityList)