!808 优化:实体导入酷家乐

pull/808/MERGE
ZoeLeeFZ 5 years ago committed by ChenX
parent 24a2bb5226
commit 5f8c46301b

@ -1,16 +1,23 @@
import { Command } from "../../Editor/CommandMachine";
import { app } from "../../ApplicationServices/Application";
import { PromptStatus } from "../../Editor/PromptResult";
import { Board } from "../../DatabaseServices/Entity/Board";
import { EBoardKeyList } from "../../Common/BoardKeyList";
import { Board, BoardType } from "../../DatabaseServices/Entity/Board";
import { Line } from "../../DatabaseServices/Entity/Line";
import { Arc } from "../../DatabaseServices/Entity/Arc";
import { Vector3, MathUtils } from "three";
import { Vector3, MathUtils, Matrix4 } from "three";
import { getEulerAngle, equalv3 } from "../../Geometry/GeUtils";
import { Curve } from "../../DatabaseServices/Entity/Curve";
import { Circle } from "../../DatabaseServices/Entity/Circle";
import { ConverCircleToPolyline } from "../../Common/CurveUtils";
import { arrayLast } from "../../Common/ArrayExt";
import { KJLExportUrls, CURRENT_HOST } from "../../Common/HostUrl";
import { PostJson } from "../../Common/Request";
import { GetEntitysLogo } from "../../Common/SerializeMaterial";
import { AppToaster } from "../../UI/Components/Toaster";
import { Intent } from '@blueprintjs/core';
import { Box3Ext } from "../../Geometry/Box";
import { HotCMD } from './../../Hot/HotCommand';
import { LinesType } from "../../UI/Store/BoardInterface";
//ref:https://open.kujiale.com/open/apps/1/docs?doc_id=458
@ -79,7 +86,7 @@ enum EKjlCurveType
LineSeg = "lineSeg",
Arc = "arc"
}
@HotCMD
export class KjlExport implements Command
{
async exec()
@ -95,31 +102,61 @@ export class KjlExport implements Command
if (brs.length === 0) return;
const subModels: ISubModel[] = [];
for (let br of brs)
const getBasePt = (b: Board, ocsInv: Matrix4) =>
{
subModels.push(this.GetKJLSubModel(br));
}
let basePt: Vector3;
if (b.BoardType === BoardType.Layer)
basePt = new Vector3(b.Width, b.Height);
else if (b.BoardType === BoardType.Behind)
{
basePt = new Vector3();
}
else
basePt = new Vector3(b.Width);
return basePt.applyMatrix4(b.OCS).applyMatrix4(ocsInv);
};
const br = brs[0];
let spaceOcsInv = br.SpaceOCSInv;
let origin = getBasePt(br, spaceOcsInv);
const subModels: ISubModel[] = [];
for (let b of brs)
{
subModels.push(this.GetKJLSubModel(b, getBasePt(b, spaceOcsInv).sub(origin), spaceOcsInv));
}
const logo = await GetEntitysLogo(brs.map(e => e.Clone()), true);
//(br.BoardProcessOption[EBoardKeyList.CabinetName] || "未命名") +
const paramModel: IParamModel = {
id: "0",
name: br.BoardProcessOption[EBoardKeyList.CabinetName] || "未命名",
category: "GENERAL_FLOOR_CABINET",
id: "",
name: new Date().toLocaleString(),
category: "SEMI_TALL_CABINET_OF_CUPBOARD",
subModels,
previewImgUrl: "https://chenfeng.tech:7779/CAD/logos/8b/8b0d32f75b8b9bc98d09686d60800bbc.png"
previewImgUrl: CURRENT_HOST + "/" + logo
};
const kjlData: IKjlExportData = {
version: "v1beta",
paramModel
};
console.log('kjlData: ', JSON.stringify(kjlData));
// let data = await PostJson("https://openapi.kujiale.com/v2/editor/api/site/importmodel", kjlData);
// console.log(data);import { Circle } from './../../DatabaseServices/Entity/Circle';
let data = await PostJson(KJLExportUrls, kjlData);
if (data.errorMsg.length === 0)
{
AppToaster.show({
message: "模型已经导入酷家乐",
timeout: 3000,
intent: Intent.SUCCESS
});
}
else
{
AppToaster.show({
message: data.errorMsg.join("/n"),
timeout: 10000,
intent: Intent.DANGER
});
}
}
private GetPtNumberList(contour: Curve)
{
@ -160,27 +197,47 @@ export class KjlExport implements Command
}
return kjsCurves;
}
private GetKJLSubModel(br: Board): IExtrusionSubModel
private GetKJLSubModel(br: Board, vec: Vector3, spaceOcsinv: Matrix4): IExtrusionSubModel
{
let contour = br.ContourCurve;
let x = new Vector3().setFromMatrixColumn(br.OCS, 0);
let y = new Vector3().setFromMatrixColumn(br.OCS, 1);
let ro = getEulerAngle(x, y, br.Normal);
let diffMat = spaceOcsinv.clone().multiply(br.OCS);
let x = new Vector3().setFromMatrixColumn(diffMat, 0);
let y = new Vector3().setFromMatrixColumn(diffMat, 1);
let z = new Vector3().setFromMatrixColumn(diffMat, 2);
let ro = getEulerAngle(x, y, z);
let p: Vector3;
let roMat = new Matrix4().extractRotation(diffMat);
if (br.BoardType === BoardType.Layer)
{
p = new Vector3(-br.Width).applyMatrix4(roMat);
}
else if (br.BoardType === BoardType.Vertical)
{
p = new Vector3(-br.Width, br.Height).applyMatrix4(roMat);
}
else
{
p = new Vector3(0, br.Height).applyMatrix4(roMat);
}
p.add(vec);
const model: IExtrusionSubModel = {
instanceId: "",
instanceId: br.Id.Index.toString(),
name: br.Name,
// BT: br.IsChaiDan ? 1 : 0,
type: "extrusion",
thickness: br.Thickness,
translate: br.Position.toArray() as [number, number, number],
translate: p.toArray() as [number, number, number],//[0, 0, 0],
rotate: [MathUtils.degToRad(ro.roX), MathUtils.degToRad(ro.roY), MathUtils.degToRad(ro.roZ)],
profile: {
points: this.GetPtNumberList(contour),
curves: this.GetCurveList(contour),
},
texture: {
topId: "IU74E08GM2"
topId: "3FO4G7HR1AI4",
bottomId: "3FO4G7HR1AI4",
sideId: "3FO4G7HR1AI4",
angle: br.BoardProcessOption.lines === LinesType.Reverse ? Math.PI / 2 : 0
}
};

@ -109,3 +109,5 @@ export const ChangeZoneUrls = [
/**发布模块 */
export const PublishTemplateUrl = CURRENT_HOST + "/Goods-cadModuleDeploy?module_id=";
export const PublishMaterialUrl = CURRENT_HOST + "/Materials-setMaterials?material_id=";
export const KJLExportUrls = CURRENT_HOST + "/CAD-importModule";

@ -55,6 +55,9 @@ export async function Post(url: string, body?: BodyInit, isShowErrMsg = true): P
});
let result = await res.json();
let store = TopPanelStore.GetInstance() as TopPanelStore;
if (result.err_code === undefined)
return result;
switch (result.err_code)
{
case RequestStatus.OffLine:

@ -1,4 +1,4 @@
import { Matrix4, Vector2, Vector3, Box3, Scene } from "three";
import { Matrix4, Vector2, Vector3, Box3, Scene, Color } from "three";
import { app } from "../ApplicationServices/Application";
import { CADFiler } from "../DatabaseServices/CADFiler";
import { Database } from "../DatabaseServices/Database";
@ -14,6 +14,8 @@ import { AAType } from "../GraphicsSystem/Viewer";
import { DisposeThreeObj } from "./Dispose";
import { uploadLogo } from "./Request";
import { ExtrudeHole } from "../DatabaseServices/3DSolid/ExtrudeHole";
import { userConfig } from './../Editor/UserConfig';
import { RenderType } from "../GraphicsSystem/RenderType";
export function MaterialOut(material: PhysicalMaterialRecord): string
{
@ -195,11 +197,19 @@ export function ExtrudeDrillFileIn(data: any[])
return en;
}
export async function GetEntitysLogo(ens: Entity[])
export async function GetEntitysLogo(ens: Entity[], isConceptual = false)
{
//备份视图
let sceneBak = app.Viewer.Scene;
let renderTypeBak: RenderType;
let clearColorBak: Color;
if (isConceptual)
{
renderTypeBak == userConfig._renderType;
userConfig._renderType = RenderType.Conceptual;
clearColorBak = app.Viewer.Renderer.getClearColor().clone();
app.Viewer.Renderer.setClearColor(new Color());
}
let aabak = app.Viewer.AAType;
let f = new CADFiler();
app.Viewer.CameraCtrl.WriteFile(f);
@ -218,6 +228,12 @@ export async function GetEntitysLogo(ens: Entity[])
//还原视图
[app.Viewer.Scene, sceneBak] = [sceneBak, app.Viewer.Scene];
if (isConceptual)
{
userConfig._renderType = renderTypeBak;
app.Viewer.Renderer.setClearColor(clearColorBak);
}
app.Viewer._AAType = aabak;
f.Reset();
app.Viewer.CameraCtrl.ReadFile(f);

Loading…
Cancel
Save