!1652 新增:右侧我的材质添加应用到选中实体的功能

pull/1651/MERGE
黄诗津 3 years ago committed by ChenX
parent fc6eccede4
commit 9010eba914

@ -2,13 +2,15 @@ import { Button, Card, Classes, ContextMenu, Intent, Menu, MenuItem } from '@blu
import { IObservableValue } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { Vector3 } from 'three';
import { Curve, Vector3 } from 'three';
import { app } from '../../../ApplicationServices/Application';
import { CommandNames } from '../../../Common/CommandNames';
import { MaterialUrls, PublishMaterialUrl } from '../../../Common/HostUrl';
import { PostJson, RequestStatus } from '../../../Common/Request';
import { inflate, MaterialIn, MaterialInAndAppendAppData } from '../../../Common/SerializeMaterial';
import { DuplicateRecordCloning } from '../../../Common/Status';
import { GetEntity, getFileSize } from '../../../Common/Utils';
import { Hole } from '../../../DatabaseServices/3DSolid/Hole';
import { Board } from '../../../DatabaseServices/Entity/Board';
import { CompositeEntity } from '../../../DatabaseServices/Entity/CompositeEntity';
import { Region } from '../../../DatabaseServices/Entity/Region';
@ -16,6 +18,7 @@ import { PhysicalMaterialRecord } from '../../../DatabaseServices/PhysicalMateri
import { CommandWrap } from '../../../Editor/CommandMachine';
import { PointPick } from '../../../Editor/PointPick';
import { userConfig } from '../../../Editor/UserConfig';
import { VisualSpaceBox } from '../../../Editor/VisualSpaceBox';
import { appUi } from '../../Layout/ApplicationLayout';
import { ApplyGoodInfo } from '../Asset';
import { DataList } from '../Common/Datalist';
@ -168,18 +171,7 @@ export class MaterialList extends React.Component<IImgListProps, {}> {
if (json)
{
let mtl = MaterialIn(JSON.parse(json)) as PhysicalMaterialRecord;
mtl.Name = data.name;
app.Database.WblockCloneObejcts(
[mtl],
app.Database.MaterialTable,
new Map(),
DuplicateRecordCloning.Ignore
)[0] as PhysicalMaterialRecord;
this.readyMtl = null;
AppToaster.show({
message: "材质已应用到图纸",
timeout: 1000
});
this.handleApplyOnce(mtl, data.name);
}
}
else
@ -187,6 +179,21 @@ export class MaterialList extends React.Component<IImgListProps, {}> {
this.handleOpen();
}
};
private handleApplyOnce = (mtl: PhysicalMaterialRecord, name: string) =>
{
mtl.Name = name;
app.Database.WblockCloneObejcts(
[mtl],
app.Database.MaterialTable,
new Map(),
DuplicateRecordCloning.Ignore
)[0] as PhysicalMaterialRecord;
this.readyMtl = null;
AppToaster.show({
message: "材质已应用到图纸",
timeout: 1000
});
};
private renameMtl = async () =>
{
let json = await this.handleGetMtlJson(this.readyMtl);
@ -226,6 +233,42 @@ export class MaterialList extends React.Component<IImgListProps, {}> {
this.handleClose();
}, "覆盖材质图纸");
};
private applyEntity = () =>
{
CommandWrap(async () =>
{
let json = await this.handleGetMtlJson(this.readyMtl);
//得到选择的实体.
let material = MaterialIn(JSON.parse(json)) as PhysicalMaterialRecord;
this.handleApplyOnce(material, this.readyMtl.name);
let count = 0;
let brCount = 0;
for (let en of app.Editor.SelectCtrl.SelectSet.SelectEntityList)
{
if (en instanceof Curve) continue;
if (en instanceof VisualSpaceBox) continue;
if (en instanceof Text) continue;
if (en instanceof Hole) continue;
en.Material = material.Id;
if (en instanceof Board)
{
if (userConfig.isModifyMaterial)
ApplyGoodInfo(en, material);
brCount++;
}
count++;
}
AppToaster.show({
message: `成功修改${count}个实体的材质,其中有${brCount}个板! (如果您想选下一组进行应用材质,记得先按ESC取消当前选中哦!) (建议切换到真实实体来查看更改结果!)`,
timeout: 10000,
intent: Intent.SUCCESS,
});
app.Viewer.UpdateRender();
}, CommandNames.ApplyMtl);
};
componentDidMount()
{
document.addEventListener("drop", this.handleApply);
@ -313,6 +356,11 @@ export class MaterialList extends React.Component<IImgListProps, {}> {
text="应用"
onClick={() => this.applyMtl(data)}
/>
<MenuItem
icon="folder-new"
text="应用到选中实体"
onClick={() => this.applyEntity()}
/>
<MenuItem
icon="folder-new"
text="发布"

Loading…
Cancel
Save