!1971 功能:酷家乐导入支持顶线五金

pull/1986/MERGE
黄诗津 2 years ago committed by ChenX
parent d0c2dbb9c7
commit bd6b93aaa7

@ -31,7 +31,7 @@ import { EZengZhiBaoId, userConfigStore } from "../../../UI/Store/UserConfigStor
import { CuttingBoardByBoard } from "../../BoardCutting/CuttingUtils2";
import { KJL_DrillData, KJL_JsonFile, KJL_ModelType, KJL_Parameter, KJL_ParamModel, KJL_ParamModel_Board, KJL_ParamModel_Hardware } from "./KJLInterface";
import { KJLMaterialLoader } from "./KJLMaterialLoader";
import { ParseBCBZ, ParseBT, ParseCabNameMap, ParseDrilling, ParseEdgeBanding, ParseEdges, ParseKMFX, ParsePathOutlineAndHole, ParseRoomNameMap } from "./KJLParse";
import { ParseBCBZ, ParseBT, ParseCabNameMap, ParseDrilling, ParseEdgeBanding, ParseEdges, ParseKMFX, ParsePathOutlineAndHole, ParseRoomNameMap, ParseTopline } from "./KJLParse";
import { ApplyMaterial, CreateHardware } from "./KJLUtils";
@ -100,25 +100,40 @@ export async function ImportKJLData(fileData: KJL_JsonFile)
let mtlLoader = new KJLMaterialLoader;
await mtlLoader.LoadKJLConfigMaterials(config);
let toplines: HardwareTopline[] = [];
for (let m of fileData.paramModel)
{
let roomName = roomNameMap.get(m.roomId);
let gName = cabNameMap.get(m.id) ?? m.modelBrandGoodName;
await ParseModel(m, roomName, gName, mtlLoader, config);
await ParseModel(m, roomName, gName, mtlLoader, config, toplines);
}
let ents = app.CommandReactor._createObejcts.filter(obj => obj instanceof Entity) as Entity[];
let brs = ents.filter(en => en instanceof Board) as Board[];
let hws = ents.filter(en => en instanceof HardwareCompositeEntity).filter(hw => (hw as HardwareCompositeEntity).HardwareOption.isHole) as HardwareCompositeEntity[];
if (ents.length === 0)
if (ents.length === 0 && toplines.length === 0)
return true;
let box = new Box3;
for (let en of ents)
box.union(en.BoundingBox);
//合理的设置顶线的位置
let topLineStartP = box.isEmpty() ? new Vector3 : box.min.clone().setY(box.max.y + 1000);
for (let i = 0; i < toplines.length; i++)
{
let tl = toplines[i];
tl.Position = topLineStartP;
topLineStartP.x += 50;
app.Database.ModelSpace.Append(tl);
ents.push(tl);
}
app.Editor.GetPointServices.snapServices.FilterEntitys = new Set(ents);
let ok = await JigMoveEntity(ents, box.isEmpty() ? undefined : box.min);
app.Editor.GetPointServices.snapServices.FilterEntitys = undefined;
@ -168,6 +183,7 @@ async function ParseModel(model: KJL_ParamModel,
gName: string,
mtlLoader: KJLMaterialLoader,
config: { [key: string]: KJLImportConfigOption; },
outToplines: HardwareTopline[],
parentMatrix?: Matrix4,
edgeBandingAll?: number[],
drillData?: KJL_DrillData): Promise<Board | TemplateRecord | HardwareCompositeEntity>
@ -181,6 +197,22 @@ async function ParseModel(model: KJL_ParamModel,
if (parentMatrix)
mtx.premultiply(parentMatrix);
if (model.profileSegments)
{
let toplines = await ParseTopline(model, mtlLoader);
if (toplines)
{
for (const topline of toplines)
{
if (parentMatrix)
mtx.premultiply(parentMatrix);
outToplines.push(topline);
}
return;//顶线是单独的模块,数据在第一层,不需要解析子模块
}
}
let boardType = ParseBT(model.parameters) ?? ParseBT(model.ignoreParameters) ?? ParseBT(model.constParameters);
if (boardType === 4)
{
@ -475,7 +507,7 @@ async function ParseModel(model: KJL_ParamModel,
if (holeFaceData) drillData.bigHole = holeFaceData.bigHole;
let boardType = ParseBT(model.parameters) ?? ParseBT(model.ignoreParameters) ?? ParseBT(model.constParameters);
let obj = await ParseModel(m, roomName, gName, mtlLoader, config, mtx, edgeBandings, drillData);
let obj = await ParseModel(m, roomName, gName, mtlLoader, config, outToplines, mtx, edgeBandings, drillData);
if (obj)
{
if (obj instanceof Board)

@ -24,6 +24,7 @@ export interface KJL_ParamModel
roomId: string;
modelBrandGoodName: string;
parameters: KJL_Parameter[];
profileSegments?: KJL_Topline[];
ignoreParameters: KJL_Parameter[];
constParameters: KJL_Parameter[];
boxSize: Vec3;
@ -49,6 +50,15 @@ export enum KJL_LineType
Arc = 1,
}
export interface KJL_Topline
{
lengthWithAllowance: number;
startCornerCutDegree: number;
startCornerCutTyp: number;
endCornerCutDegree: number;
endCornerCutType: number;
}
export interface KJL_Path
{
resultPoints: Vec2[];

@ -1,11 +1,14 @@
import { Vec2, Vector2 } from "three";
import { Polyline, PolylineProps } from "../../../api";
import { arrayLast, ArrayRemoveDupSavePre } from "../../../Common/ArrayExt";
import { safeEval } from "../../../Common/eval";
import { FixIndex, ToFixed } from "../../../Common/Utils";
import { Polyline, PolylineProps } from "../../../DatabaseServices/Entity/Polyline";
import { HardwareTopline } from "../../../DatabaseServices/Hardware/HardwareTopline";
import { AsVector2, equalv2 } from "../../../Geometry/GeUtils";
import { BoardOpenDir } from "../../../UI/Store/BoardInterface";
import { KJL_AssemblyModel, KJL_DesignData, KJL_DrillData, KJL_LineType, KJL_Parameter, KJL_ParamModel, KJL_Path } from "./KJLInterface";
import { KJL_AssemblyModel, KJL_DesignData, KJL_DrillData, KJL_LineType, KJL_Parameter, KJL_ParamModel, KJL_Path, KJL_Topline } from "./KJLInterface";
import { KJLMaterialLoader } from "./KJLMaterialLoader";
import { ApplyMaterial } from "./KJLUtils";
//返回id->房名映射
@ -80,6 +83,26 @@ export function ParseEdgeBanding(model: KJL_ParamModel): number[] | undefined
return edgeBandings;
}
export async function ParseTopline(model: KJL_ParamModel, mtlLoader: KJLMaterialLoader)
{
let profileSegments: KJL_Topline[] = model.profileSegments;
let toplines: HardwareTopline[] = [];
let shape = new Polyline().Rectangle(10, 10);
for (const p of profileSegments)
{
let path = new Polyline([{ pt: new Vector2(0, 0), bul: 0 }, { pt: new Vector2(0, p.lengthWithAllowance), bul: 0 }]);
let topline = new HardwareTopline(shape, path);
topline.HardwareOption.name = model.modelName ?? "";
topline.HardwareOption.comments =
`左切类型:${p.startCornerCutTyp === 0 ? "平切" : p.startCornerCutTyp === 1 ? "阳角" : "阴角"}${p.startCornerCutDegree}°;
:${p.endCornerCutType === 0 ? "平切" : p.endCornerCutType === 1 ? "阳角" : "阴角"}${p.endCornerCutDegree}°;`;
let mtl = await mtlLoader.LoadMaterialFromName(model.textureName);
if (mtl) ApplyMaterial(topline, mtl);
toplines.push(topline);
}
return toplines;
}
export function ParseBT(params: KJL_Parameter[]): number
{
if (!params) return 0;

@ -1,8 +1,6 @@
import { EBoardKeyList } from "../../../Common/BoardKeyList";
import { SweepSolid } from "../../../DatabaseServices/3DSolid/SweepSolid";
import { CompositeEntity } from "../../../DatabaseServices/Entity/CompositeEntity";
import { IsMeshMaterialEntity } from "../../../Common/IsMeshMaterialEntity";
import { Entity } from "../../../DatabaseServices/Entity/Entity";
import { Region } from "../../../DatabaseServices/Entity/Region";
import { HardwareCompositeEntity } from "../../../DatabaseServices/Hardware/HardwareCompositeEntity";
import { PhysicalMaterialRecord } from "../../../DatabaseServices/PhysicalMaterialRecord";
import { Board } from "../../../ueapi";
@ -48,10 +46,10 @@ export function CreateHardware(hmodel: KJL_ParamModel_Hardware, roomName: string
return hw;
}
export function ApplyMaterial(br: Entity, mtl: PhysicalMaterialRecord)
export function ApplyMaterial(ent: Entity, mtl: PhysicalMaterialRecord)
{
if (br instanceof Board || br instanceof Region || br instanceof CompositeEntity || br instanceof SweepSolid)
br.Material = mtl.Id;
if (br instanceof Board)
ApplyGoodInfo(br, mtl);
if (IsMeshMaterialEntity(ent))
ent.Material = mtl.Id;
if (ent instanceof Board)
ApplyGoodInfo(ent, mtl);
}

@ -3,6 +3,7 @@ import { Board } from "../DatabaseServices/Entity/Board";
import { CompositeEntity } from "../DatabaseServices/Entity/CompositeEntity";
import { Entity } from "../DatabaseServices/Entity/Entity";
import { Region } from "../DatabaseServices/Entity/Region";
import { HardwareTopline } from "../DatabaseServices/Hardware/HardwareTopline";
import { RoomFlatBase } from "../DatabaseServices/Room/Entity/Flat/RoomFlatBase";
import { RoomHoleBase } from "../DatabaseServices/Room/Entity/Wall/Hole/RoomHoleBase";
import { RoomWallBase } from "../DatabaseServices/Room/Entity/Wall/RoomWallBase";
@ -10,7 +11,7 @@ import { RoomWallBase } from "../DatabaseServices/Room/Entity/Wall/RoomWallBase"
export function IsMeshMaterialEntity(en: Entity)
{
return (en instanceof Board || en instanceof Region || en instanceof CompositeEntity || en instanceof SweepSolid
return (en instanceof Board || en instanceof Region || en instanceof CompositeEntity || en instanceof SweepSolid || HardwareTopline
|| en instanceof RoomWallBase || en instanceof RoomFlatBase
|| en instanceof RoomHoleBase);
}

Loading…
Cancel
Save