|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|