功能:绘制户型的时候设置墙体和地面的默认材质

pull/2051/head
ChenX 2 years ago
parent 0e6e2a63f0
commit d336b58087

@ -22,7 +22,7 @@ export class Command_DrawRectWall implements Command
_DrawDirMode: WallDirMode = WallDirMode.Inside; _DrawDirMode: WallDirMode = WallDirMode.Inside;
async exec() async exec()
{ {
if (! await FixDrawWallDir()) return; if (!await FixDrawWallDir()) return;
this._parse = undefined; this._parse = undefined;

@ -333,7 +333,7 @@ export class Command_DrawWallInside implements Command
WallThickness = 240; WallThickness = 240;
async exec() async exec()
{ {
if (! await FixDrawWallDir()) return; if (!await FixDrawWallDir()) return;
this.model = WallMode.Line; this.model = WallMode.Line;

@ -1,10 +1,15 @@
import { Intent } from "@blueprintjs/core"; import { Intent } from "@blueprintjs/core";
import { Vector3 } from "three"; import { Vector3 } from "three";
import { app } from "../../ApplicationServices/Application"; 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 { equalv3, isPerpendicularityTo, ZAxis, ZAxisN } from "../../Geometry/GeUtils";
import { AppToaster } from "../../UI/Components/Toaster"; import { AppToaster } from "../../UI/Components/Toaster";
import ResourceStore from "../../UI/Components/ToolBar/ResourceLibrary/RsourceStore";
import { ViewChange } from "../ViewChange"; import { ViewChange } from "../ViewChange";
//同时自动创建默认的墙体和地面材质
export async function FixDrawWallDir(): Promise<boolean> export async function FixDrawWallDir(): Promise<boolean>
{ {
if (app.Viewer.isLayout) if (app.Viewer.isLayout)
@ -51,5 +56,46 @@ export async function FixDrawWallDir(): Promise<boolean>
app.Editor.SetUCSLookAt(new Vector3(0, 0, -1)); 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; return true;
} }

@ -6,6 +6,9 @@ import { Database } from './Database';
import { Dimension } from './Dimension/Dimension'; import { Dimension } from './Dimension/Dimension';
import { Entity } from './Entity/Entity'; import { Entity } from './Entity/Entity';
import { ObjectCollection } from './ObjectCollection'; 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'; import { SymbolTableRecord } from './SymbolTableRecord';
@Factory @Factory
@ -37,8 +40,23 @@ export class BlockTableRecord extends SymbolTableRecord
Append(entity: Entity, isCheckObjectCleanly = true) Append(entity: Entity, isCheckObjectCleanly = true)
{ {
if (this._db) if (this._db)
if (entity instanceof Dimension && !entity.DimStyle) {
if (entity instanceof Dimension)
{
if (!entity.DimStyle)
entity.DimStyle = this._db.DimStyleTable.Current;//设置默认的标注样式 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); this.EntityCol.Append(entity, isCheckObjectCleanly);
entity.Owner = this.objectId; entity.Owner = this.objectId;

@ -1,8 +1,30 @@
import { SymbolTable } from "./SymbolTable"; import { CADFiler } from "./CADFiler";
import { ObjectId } from "./ObjectId";
import { PhysicalMaterialRecord } from "./PhysicalMaterialRecord"; import { PhysicalMaterialRecord } from "./PhysicalMaterialRecord";
import { SymbolTable } from "./SymbolTable";
export class MaterialTable extends 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() get Materials()
{ {
@ -28,4 +50,27 @@ export class MaterialTable extends SymbolTable
{ {
return super.AllocateName(name); 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
} }

@ -85,11 +85,13 @@ export class SymbolTable extends CADObject
return true; return true;
} }
protected _FileVer = 0;
//#region -------------------------File------------------------- //#region -------------------------File-------------------------
ReadFile(file: CADFiler) ReadFile(file: CADFiler)
{ {
super.ReadFile(file); super.ReadFile(file);
let ver = file.Read(); let ver = file.Read();
this._FileVer = ver;
let count = file.Read(); let count = file.Read();
this.Symbols.clear(); this.Symbols.clear();
for (let i = 0; i < count; i++) for (let i = 0; i < count; i++)
@ -104,7 +106,7 @@ export class SymbolTable extends CADObject
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
{ {
super.WriteFile(file); super.WriteFile(file);
file.Write(2); file.Write(3);
file.Write(this.Symbols.size); file.Write(this.Symbols.size);
for (let [key, record] of this.Symbols) for (let [key, record] of this.Symbols)
{ {

@ -460,7 +460,7 @@ export class ResourceItem extends Component<{ module: ModuleData; }, {}>
if (!module_detail) return; if (!module_detail) return;
CommandWrap(async () => CommandWrap(async () =>
{ {
let material = await this.resourceStore.PraseMaterial(module_detail); let material = await this.resourceStore.PraseMaterial(module_detail.path);
let count = 0; let count = 0;
let brCount = 0; let brCount = 0;
for (let en of app.Editor.SelectCtrl.SelectSet.SelectEntityList) for (let en of app.Editor.SelectCtrl.SelectSet.SelectEntityList)

@ -32,7 +32,7 @@ import { DynamicInputManage } from "../../../DynamicPrompt/DynamicInputManage";
import { PromptBlock } from "../../../DynamicPrompt/PromptBlock"; import { PromptBlock } from "../../../DynamicPrompt/PromptBlock";
import { InsertTemplateByBasePoint } from "../../Template/InsertTemplateByBasePoint"; import { InsertTemplateByBasePoint } from "../../Template/InsertTemplateByBasePoint";
import { AppToaster } from "../../Toaster"; 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 { ResourcePanelType } from "./ResourcePanel";
import { getClassList, getModuleDetail, getModuleList, GetUserCollectDir, GetUserCollection } from "./ResourcesData"; import { getClassList, getModuleDetail, getModuleList, GetUserCollectDir, GetUserCollection } from "./ResourcesData";
@ -136,7 +136,7 @@ export default class ResourceStore
{ {
if (module_detail.type === ResType.Mtl) 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) for (let o of selectObj)
{ {
let en = GetEntity(o); let en = GetEntity(o);
@ -322,13 +322,13 @@ export default class ResourceStore
}, module_detail.type === ResType.Mtl ? CommandNames.ApplyMtl : "绘制模型"); }, 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); let mtl = app.Database.MaterialTable.GetAt(name);
if (!mtl) 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 dataString = await (await fetch(GenerateCdnUrl(`/Paks/paks_cooked/ue_resource/Content${encodeURI(url)}.json`))).text();
let data = JSON.parse(dataString); let data = JSON.parse(dataString);
@ -340,7 +340,7 @@ export default class ResourceStore
mtl.transparent = false; mtl.transparent = false;
mtl.opacity = 1; mtl.opacity = 1;
mtl.bumpScale = 0.0005; mtl.bumpScale = 0.0005;
mtl.ref = module_detail.path; mtl.ref = mtlPath;
let color = new Color; let color = new Color;
let texturePath = data.baseColor_texturePath as string; let texturePath = data.baseColor_texturePath as string;

@ -117,7 +117,7 @@ export default class UserCollect extends Component<{}, {}>
if (!module_detail) return; if (!module_detail) return;
CommandWrap(async () => CommandWrap(async () =>
{ {
let material = await this.resourceStore.PraseMaterial(module_detail); let material = await this.resourceStore.PraseMaterial(module_detail.path);
let count = 0; let count = 0;
let brCount = 0; let brCount = 0;
for (let en of app.Editor.SelectCtrl.SelectSet.SelectEntityList) for (let en of app.Editor.SelectCtrl.SelectSet.SelectEntityList)

Loading…
Cancel
Save