!2526 新增嘉居导入对接材质,新增复制材质ID

pull/2543/head
黄诗津 9 months ago committed by ChenX
parent 9c21e542ae
commit 932f39c643

@ -1,14 +1,19 @@
import { Box3, Matrix4, Vector3 } from "three";
import { app } from "../../../ApplicationServices/Application";
import { arrayRemoveIf } from "../../../Common/ArrayExt";
import { EBoardKeyList } from "../../../Common/BoardKeyList";
import { FS } from "../../../Common/FileSystem";
import { MaterialUrls } from "../../../Common/HostUrl";
import { JigMoveEntity } from "../../../Common/JigMove";
import { Log, LogType } from "../../../Common/Log";
import { MakeMirrorMtx, NormalMatrix } from "../../../Common/Matrix4Utils";
import { PostJson, RequestStatus } from "../../../Common/Request";
import { MaterialIn } from "../../../Common/SerializeMaterial";
import { DuplicateRecordCloning } from "../../../Common/Status";
import { Intent, ToasterShowEntityMsg } from "../../../Common/Toaster";
import { FixDigits } from "../../../Common/Utils";
import { safeEval } from "../../../Common/eval";
import { inflateBase64 } from "../../../Common/inflate";
import { Contour } from "../../../DatabaseServices/Contour";
import { Database } from "../../../DatabaseServices/Database";
import { Arc } from "../../../DatabaseServices/Entity/Arc";
@ -19,7 +24,9 @@ import { Line } from "../../../DatabaseServices/Entity/Line";
import { Polyline } from "../../../DatabaseServices/Entity/Polyline";
import { HardwareCompositeEntity } from "../../../DatabaseServices/Hardware/HardwareCompositeEntity";
import { ObjectId } from "../../../DatabaseServices/ObjectId";
import { PhysicalMaterialRecord } from "../../../DatabaseServices/PhysicalMaterialRecord";
import { Shape } from "../../../DatabaseServices/Shape";
import { TemplateParamType } from "../../../DatabaseServices/Template/Param/TemplateParamType";
import { GetOnlineTemplate } from "../../../DatabaseServices/Template/TempateUtils";
import { TemplateRecord } from "../../../DatabaseServices/Template/TemplateRecord";
import { Command, CommandWrap } from "../../../Editor/CommandMachine";
@ -200,25 +207,32 @@ class JiaJuParse
let template_out = await GetOnlineTemplate(paramTable.ID);
if (template_out)
{
template_out = template_out.Root;
template = app.Database.WblockCloneObejcts([template_out], app.Database.TemplateTable, new Map(), DuplicateRecordCloning.Ignore)[0] as TemplateRecord;
template_out.LParam.expr = paramTable.W;
template_out.WParam.expr = paramTable.D;
template_out.HParam.expr = paramTable.H;
template = template.Root;
template.LParam.expr = paramTable.W;
template.WParam.expr = paramTable.D;
template.HParam.expr = paramTable.H;
for (let paramName in paramTable)
{
if (paramName.startsWith("MK_"))
{
let param = template_out.GetParam(paramName);
let param = template.GetParam(paramName);
if (param)
param.expr = paramTable[paramName];
else
Log(`AB库应用参数失败,参数:${paramName}`, LogType.Error);
{
if (param.type === TemplateParamType.Material)
param.MaterialValue = await LoadMaterial(paramTable[paramName]);
else if (param.type === TemplateParamType.Float)
param.expr = paramTable[paramName];
else
Log(`AB库应用参数失败,参数:${paramName}`, LogType.Error);
}
}
}
let ens = template_out.AllEntitys as Entity[];
let ens = template.AllEntitys as Entity[];
for (const en of ens)
{
if (en instanceof Board)
@ -279,7 +293,7 @@ class JiaJuParse
let openType = parseInt(paramTable.OPEN_TYPE);
let openDoorString = GetHardwareOpenDir(openType);
for (let e of template_out.AllEntitys)
for (let e of template.AllEntitys)
{
if (e instanceof Board)
e.OpenDir = openType;
@ -291,14 +305,14 @@ class JiaJuParse
}
}
await template_out.UpdateTemplateTree();
await template.UpdateTemplateTree();
// 删除材质变量 避免重复进入(在酷家乐导入后删除这个是可以接受的!)(或者不删除也是可以接受的, 但是要把材质Value设置为空);
arrayRemoveIf(template.Params, p => p.type === TemplateParamType.Material);
let mtx = new Matrix4().fromArray(product.Coordinate.split(",").map(parseFloat));
for (let ent of template_out.AllEntitys)
for (let ent of template.AllEntitys)
ent.ApplyMatrix(mtx);
template = this.curDb.WblockCloneObejcts([template_out], this.curDb.TemplateTable, new Map(), DuplicateRecordCloning.Ignore)[0] as TemplateRecord;
}
}
@ -594,3 +608,41 @@ function JiajuPath2Polyline(path: JiaJu.Path)
return polyline;
}
async function LoadMaterial(fetchMaterialId: string): Promise<PhysicalMaterialRecord>
{
let mtl: PhysicalMaterialRecord;
let data = await PostJson(MaterialUrls.detail, { material_id: fetchMaterialId });
if (data.err_code !== RequestStatus.Ok)
{
AppToaster.show({
message: `错误:无法从远程获取到材质数据!id:${fetchMaterialId}`,
timeout: 5000,
intent: Intent.DANGER,
}, "no_mtl_data");
return;
}
try
{
let jsonData = JSON.parse(inflateBase64(data.materials.file));
let mtlOut = MaterialIn(jsonData) as PhysicalMaterialRecord;
mtl = app.Database.WblockCloneObejcts(
[mtlOut],
app.Database.MaterialTable,
new Map(),
DuplicateRecordCloning.Ignore
)[0] as PhysicalMaterialRecord;
return mtl;
}
catch (error)
{
AppToaster.show({
message: `加载材质失败! id:${fetchMaterialId}`,
timeout: 5000,
intent: Intent.WARNING,
});
}
}

@ -6,5 +6,6 @@ export class Test implements Command
{
async exec()
{
}
}

@ -6,12 +6,12 @@ import { Curve, Vector3 } from 'three';
import { app } from '../../../ApplicationServices/Application';
import { CommandNames } from '../../../Common/CommandNames';
import { MaterialUrls, PublishMaterialUrl } from '../../../Common/HostUrl';
import { inflateBase64 } from "../../../Common/inflate";
import { IsMeshMaterialEntity } from '../../../Common/IsMeshMaterialEntity';
import { PostJson, RequestStatus } from '../../../Common/Request';
import { MaterialIn, MaterialInAndAppendAppData } from '../../../Common/SerializeMaterial';
import { DuplicateRecordCloning } from '../../../Common/Status';
import { GetEntity, getFileSize } from '../../../Common/Utils';
import { GetEntity, copyTextToClipboard, getFileSize } from '../../../Common/Utils';
import { inflateBase64 } from "../../../Common/inflate";
import { Hole } from '../../../DatabaseServices/3DSolid/Hole';
import { Board } from '../../../DatabaseServices/Entity/Board';
import { PhysicalMaterialRecord } from '../../../DatabaseServices/PhysicalMaterialRecord';
@ -381,6 +381,11 @@ export class MaterialList extends React.Component<IImgListProps, {}> {
text="发布"
onClick={() => this.publishTemplate(data.material_id)}
/>
<MenuItem
icon="duplicate"
text="复制ID"
onClick={() => this.copyid(data.material_id)}
/>
{
!this.props.isRightToolbar &&
<MenuItem
@ -403,6 +408,16 @@ export class MaterialList extends React.Component<IImgListProps, {}> {
e.stopPropagation();
e.preventDefault();
};
//复制ID
private copyid = (material_id: string) =>
{
copyTextToClipboard(material_id);
AppToaster.show({
message: "ID复制成功",
intent: Intent.SUCCESS
});
};
private publishTemplate = (id: string) =>
{
window.open(PublishMaterialUrl + id);

Loading…
Cancel
Save