diff --git a/__test__/Board/Mirror.test.ts b/__test__/Board/Mirror.test.ts new file mode 100644 index 000000000..4f6db9bcb --- /dev/null +++ b/__test__/Board/Mirror.test.ts @@ -0,0 +1,16 @@ +import { Vector3 } from "three"; +import { CADFiler } from "../../src/api"; +import { MakeMirrorMtx } from "../../src/Common/Matrix4Utils"; +import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util"; + +test('板件镜像', () => +{ + let d = + { "file": [5, "Board", 8, 2, 106, false, 1, 2, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 3435.3422864514687, 444.811074718357, 21.352872036479766, 1], 107, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2671.3422864514687, 444.811074718357, 21.352872036479766, 1], 0, 3, 764, 500.00000000000006, 18, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [6.123233995736766e-17, -1, 0, 0, 1, 6.123233995736766e-17, 0, 0, 0, 0, 1, 0, 0, 764, 0, 1], 0, 2, 4, [0, 764], 0, [500, 764], 0, [500.00000000000006, 0], 0, [4.678150772742889e-14, 0], 0, true, 0, 3, 1, 1, 1, 0, 1, 112, 10, 0, "晨丰顶板", "未命名", "晨丰一字柜测试", "", "水曲柳(默认材质)", "", 0, 1, "**多种**", 2, 4, 2, 1, 4, 3, "2", "4", "3", "1", "", "", "", 4, "三合一", "铰链孔", "二合一", "不排", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, "Text", 8, 2, 231, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2980.073687006361, 1010.7348531969456, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2980.073687006361, 1010.7348531969456, 0, 1], 0, 1, "1铰链孔", 30, 0, "songti", 10, "Text", 8, 2, 236, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2497.0038493164498, 635.6980151294591, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2497.0038493164498, 635.6980151294591, 0, 1], 0, 1, "2三合一", 30, 0, "songti", 10, "Text", 8, 2, 237, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3047.2444639736723, 397.8015133702329, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3047.2444639736723, 397.8015133702329, 0, 1], 0, 1, "3不排", 30, 0, "songti", 10, "Text", 8, 2, 238, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3475.3182280215988, 681.1782287010747, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3475.3182280215988, 681.1782287010747, 0, 1], 0, 1, "4二合一", 30, 0, "songti", 10], "basePt": { "x": 2497.0038493164498, "y": 397.8015133702329, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3435.3422864514687, 444.811074718357, 21.352872036479766, 1] }; + let br = LoadBoardsFromFileData(d)[0]; + + br.ApplyMatrix(MakeMirrorMtx(new Vector3(0, 0, 1))); + let f = new CADFiler; + f.WriteObject(br); + expect(f).toMatchSnapshot(); +}); diff --git a/__test__/Board/__snapshots__/Mirror.test.ts.snap b/__test__/Board/__snapshots__/Mirror.test.ts.snap new file mode 100644 index 000000000..42ce933f1 --- /dev/null +++ b/__test__/Board/__snapshots__/Mirror.test.ts.snap @@ -0,0 +1,182 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`板件镜像 1`] = ` +CADFiler { + "_datas": Array [ + "Board", + 8, + 2, + 0, + false, + 0, + 2, + 0, + Array [ + 0, + 1, + 0, + 0, + -1, + 0, + 0, + 0, + 0, + 0, + -1, + 0, + 3435.3422864514687, + 444.811074718357, + -21.352872036479766, + 1, + ], + 0, + 0, + true, + Array [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + -1, + 0, + 2671.3422864514687, + 444.811074718357, + -21.352872036479766, + 1, + ], + 0, + 3, + 764, + 500.00000000000006, + 18, + true, + "Polyline", + 8, + 2, + 0, + false, + 0, + 7, + 0, + Array [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + ], + 0, + 0, + true, + Array [ + 6.123233995736766e-17, + -1, + 0, + 0, + 1, + 6.123233995736766e-17, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 764, + 0, + 1, + ], + 0, + 2, + 4, + Array [ + 0, + 764, + ], + 0, + Array [ + 500, + 764, + ], + 0, + Array [ + 500.00000000000006, + 0, + ], + 0, + Array [ + 4.678150772742889e-14, + 0, + ], + 0, + true, + 0, + 3, + 1, + 1, + 1, + 0, + 0, + 10, + 0, + "晨丰顶板", + "未命名", + "晨丰一字柜测试", + "", + "水曲柳(默认材质)", + "", + 0, + 1, + "**多种**", + 2, + 4, + 2, + 1, + 4, + 3, + "2", + "4", + "3", + "1", + "", + "", + "", + 4, + "三合一", + "铰链孔", + "二合一", + "不排", + true, + true, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + true, + 0, + 0, + ], + "readIndex": 0, +} +`; diff --git a/__test__/Utils/LoadEntity.util.ts b/__test__/Utils/LoadEntity.util.ts index 6c67043a5..1eff9eb58 100644 --- a/__test__/Utils/LoadEntity.util.ts +++ b/__test__/Utils/LoadEntity.util.ts @@ -11,6 +11,7 @@ import { RoomWallLine } from "../../src/DatabaseServices/Room/Entity/Wall/RoomWa import { TemplateStretchGripAction } from "../../src/DatabaseServices/Template/Action/TemplateStretchGripAction"; import { TemplateLeftRightBoardRecord } from "../../src/DatabaseServices/Template/ProgramTempate/TemplateLeftRightBoardRecord"; import { TemplateSizeBoard } from "../../src/DatabaseServices/Template/ProgramTempate/TemplateSizeBoard"; +import { Text } from "../../src/DatabaseServices/Text/Text"; Factory(Polyline); Factory(Region); @@ -21,6 +22,7 @@ TemplateSizeBoard; TemplateStretchGripAction; RoomWallLine; RoomWallArc; +Text; export function LoadEntityFromFileData(data: any) { diff --git a/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts b/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts index b900f15d4..fbc74c814 100644 --- a/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts +++ b/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts @@ -1,6 +1,6 @@ import { Matrix4, Vector2, Vector3 } from "three"; import { arrayLast, arrayRemoveDuplicateBySort, arraySortByNumber } from "../../Common/ArrayExt"; -import { GetMirrorMat } from "../../Common/Matrix4Utils"; +import { MakeMirrorMtx } from "../../Common/Matrix4Utils"; import { Board } from "../../DatabaseServices/Entity/Board"; import { Line } from "../../DatabaseServices/Entity/Line"; import { Polyline } from "../../DatabaseServices/Entity/Polyline"; @@ -44,19 +44,11 @@ export class DrawObliqueWineRackTool extends DrawWineRackTool const spaceHeight = size.z; const spaceWidth = size.x; const ptMid = new Vector3(0.5 * size.x, size.z / 2, 0); - let miMat: Matrix4; + let mirrorMtx: Matrix4; if (config.fullType === EFullType.ByWidth) - { - miMat = MoveMatrix(ptMid) - .multiply(GetMirrorMat(YAxis)) - .multiply(MoveMatrix(ptMid.clone().negate())); - } + mirrorMtx = MakeMirrorMtx(YAxis, ptMid); else - { - miMat = MoveMatrix(ptMid) - .multiply(GetMirrorMat(XAxis)) - .multiply(MoveMatrix(ptMid.clone().negate())); - } + mirrorMtx = MakeMirrorMtx(XAxis, ptMid); ptMid.set(0.5 * size.x, size.z / 2, 0); polar(ptMid, Math.PI * 0.75, -config.boardThick); @@ -90,7 +82,7 @@ export class DrawObliqueWineRackTool extends DrawWineRackTool for (let pl of [...pls1, ...pls2]) { let plClone = pl.Clone(); - plClone.ApplyMatrix(miMat); + plClone.ApplyMatrix(mirrorMtx); retPls.push(plClone); } this.DrawBoardFormPolyLine(retPls); diff --git a/src/Add-on/DrawWineRack/Polyline2Winerack.ts b/src/Add-on/DrawWineRack/Polyline2Winerack.ts index 84fba7b9c..d85b416f7 100644 --- a/src/Add-on/DrawWineRack/Polyline2Winerack.ts +++ b/src/Add-on/DrawWineRack/Polyline2Winerack.ts @@ -1,18 +1,18 @@ -import { Command } from "../../Editor/CommandMachine"; +import { toJS } from "mobx"; +import { Box3, Matrix4, Vector3 } from "three"; import { app } from "../../ApplicationServices/Application"; -import { PromptStatus } from "../../Editor/PromptResult"; +import { MergeCurvelist } from "../../Common/CurveUtils"; +import { SetMtxVector } from "../../Common/Matrix4Utils"; import { Polyline } from "../../DatabaseServices/Entity/Polyline"; -import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse"; +import { ProcessingGroupRecord } from "../../DatabaseServices/ProcessingGroup/ProcessingGroupRecord"; +import { Command } from "../../Editor/CommandMachine"; +import { PromptStatus } from "../../Editor/PromptResult"; import { Box3Ext } from "../../Geometry/Box"; -import { Vector3, Matrix4, Box3 } from "three"; +import { ISpaceParse } from "../../Geometry/SpaceParse/ISpaceParse"; import { Rect2Winerack } from "../../UI/Components/Board/Rect2Winerack"; -import { rect2WinerackStore } from "../../UI/Store/Rect2WinerackStore"; import { ModalState } from "../../UI/Components/Modal/ModalInterface"; -import { toJS } from "mobx"; +import { rect2WinerackStore } from "../../UI/Store/Rect2WinerackStore"; import { Rect2WinerackTool } from "./Rect2WinerackTool"; -import { matrixSetVector } from "../../Common/Matrix4Utils"; -import { MergeCurvelist } from "../../Common/CurveUtils"; -import { ProcessingGroupRecord } from "../../DatabaseServices/ProcessingGroup/ProcessingGroupRecord"; export class Polyline2Winerack implements Command { @@ -75,8 +75,8 @@ export class Polyline2Winerack implements Command let y = new Vector3().setFromMatrixColumn(mtx, 1); let z = new Vector3().setFromMatrixColumn(mtx, 2); - matrixSetVector(mtx, 1, z.negate()); - matrixSetVector(mtx, 2, y); + SetMtxVector(mtx, 1, z.negate()); + SetMtxVector(mtx, 2, y); [spaceBox.min.y, spaceBox.min.z] = [spaceBox.min.z, spaceBox.min.y]; [spaceBox.max.y, spaceBox.max.z] = [spaceBox.max.z, spaceBox.max.y]; diff --git a/src/Add-on/KJLImport.ts b/src/Add-on/KJLImport.ts index b9267ea04..4a0fe5be1 100644 --- a/src/Add-on/KJLImport.ts +++ b/src/Add-on/KJLImport.ts @@ -1,5 +1,5 @@ import { Intent } from "@blueprintjs/core"; -import { Euler, Matrix4, Vector2, Vector3 } from "three"; +import { Box3, Euler, Matrix4, Vector2, Vector3 } from "three"; import { app } from "../ApplicationServices/Application"; import { arrayLast } from "../Common/ArrayExt"; import { EBoardKeyList } from "../Common/BoardKeyList"; @@ -7,6 +7,7 @@ import { safeEval } from "../Common/eval"; import { FileSystem } from "../Common/FileSystem"; import { BuyZengZhiBao, MaterialUrls } from "../Common/HostUrl"; import { JigMoveEntity } from "../Common/JigMove"; +import { MakeMirrorMtx, NormalMatrix, RoundMatrix } from "../Common/Matrix4Utils"; import { PostJson, RequestStatus } from "../Common/Request"; import { inflate, MaterialIn } from "../Common/SerializeMaterial"; import { DuplicateRecordCloning } from "../Common/Status"; @@ -20,16 +21,16 @@ import { Polyline, PolylineProps } from "../DatabaseServices/Entity/Polyline"; import { Region } from "../DatabaseServices/Entity/Region"; import { HardwareCompositeEntity } from "../DatabaseServices/Hardware/HardwareCompositeEntity"; import { HardwareTopline } from "../DatabaseServices/Hardware/HardwareTopline"; +import { ObjectId } from "../DatabaseServices/ObjectId"; import { PhysicalMaterialRecord } from "../DatabaseServices/PhysicalMaterialRecord"; import { GetOnlineTemplate } from "../DatabaseServices/Template/TempateUtils"; import { TemplateRecord } from "../DatabaseServices/Template/TemplateRecord"; import { Command, CommandWrap } from "../Editor/CommandMachine"; import { userConfig } from "../Editor/UserConfig"; import { Vec2 } from "../Geometry/CheckIntersect"; -import { AsVector2, equaln, equalv2 } from "../Geometry/GeUtils"; +import { AsVector2, equaln, equalv2, ZAxis } from "../Geometry/GeUtils"; import { Vec3 } from "../Geometry/IVec3"; import { HandleRectBoardSealingData, ParagraphSealinglist } from "../GraphicsSystem/CalcEdgeSealing"; -import { HotCMD } from "../Hot/HotCommand"; import { ApplyGoodInfo } from "../UI/Components/Asset"; import { BoardModalType } from "../UI/Components/Board/BoardModalType"; import { AppConfirm } from "../UI/Components/Common/Confirm"; @@ -156,7 +157,6 @@ class FuzzPoint } } -@HotCMD export class Command_KJLImport implements Command { async exec() @@ -167,76 +167,100 @@ export class Command_KJLImport implements Command { let res = await AppConfirm.show({ message: "您还未购买该增值包,前往购买?" }); if (res) - { window.open(BuyZengZhiBao + EZengZhiBaoId.KJLIMport); - } return; } FileSystem.ChooseFile({ - filter: ".json", multiple: false, callback: (files) => + filter: ".json", multiple: false, callback: async (files) => { - CommandWrap(async () => + for (let i = 0; i < files.length; i++) { - let f = files.item(0); - let fstr = await FileSystem.ReadFileAsText(f); - if (!fstr) + let file = files.item(i); + let data = await file.text(); + try + { + let object = JSON.parse(data); + if (object.paramModel) + { + await ImportKJLData(object); + } + else + { + AppToaster.show({ + message: `${file.name}不是有效的酷家乐JSOn文件!`, + timeout: 5000, + intent: Intent.WARNING, + }); + } + } + catch (error) { AppToaster.show({ - message: "数据有误", - timeout: 3000, - intent: Intent.DANGER + message: `${file.name}导入失败!`, + timeout: 5000, + intent: Intent.WARNING, }); - return; } - let fileData = JSON.parse(fstr) as KJL_JsonFile; - let roomMap = ParseRoomNameMap(fileData.designData); - let cabMap = ParseCabNameMap(fileData.assemblyModels); - let materialMap = await ParseMaterialMap(); + } + } + }); + } +} - for (let m of fileData.paramModel) - { - let roomName = roomMap.get(m.roomId); - let gName = cabMap.get(m.id) ?? m.modelBrandGoodName; - await ParseModel(m, roomName, gName, materialMap); - } +export async function ImportKJLData(fileData: KJL_JsonFile) +{ + await CommandWrap(async () => + { + let roomMap = ParseRoomNameMap(fileData.designData); + let cabMap = ParseCabNameMap(fileData.assemblyModels); + let materialMap = await ParseMaterialMap(); - 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[]; + for (let m of fileData.paramModel) + { + let roomName = roomMap.get(m.roomId); + let gName = cabMap.get(m.id) ?? m.modelBrandGoodName; + await ParseModel(m, roomName, gName, materialMap); + } - if (ents.length === 0) - return true; + 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[]; - let ok = await JigMoveEntity(ents); + if (ents.length === 0) + return true; - if (ok) - { - if (brs.length !== 0) - { - app.Editor.Prompt("开始计算薄背板拉槽!"); - let bbrs: Board[] = []; - let allBrs: Board[] = []; - for (let br of brs) - { - if (br.IsKnife)//br.BoardType === BoardType.Behind - bbrs.push(br); - else - allBrs.push(br); - } - - CuttingBoardByBoard(allBrs, bbrs); - } + let box = new Box3; + for (let en of ents) + box.union(en.BoundingBox); - //直接调用五金挖孔 - await app._hardwareCuttingReactor.StartReactor(hws, new Set); - } + app.Editor.GetPointServices.snapServices.FilterEntitys = new Set(ents); + let ok = await JigMoveEntity(ents, box.isEmpty() ? undefined : box.min); + app.Editor.GetPointServices.snapServices.FilterEntitys = undefined; - return !ok; - }, "酷家乐导入"); + if (ok) + { + if (brs.length !== 0) + { + app.Editor.Prompt("开始计算薄背板拉槽!"); + let bbrs: Board[] = []; + let allBrs: Board[] = []; + for (let br of brs) + { + if (br.IsKnife)//br.BoardType === BoardType.Behind + bbrs.push(br); + else + allBrs.push(br); + } + + CuttingBoardByBoard(allBrs, bbrs); } - }); - } + + //直接调用五金挖孔 + await app._hardwareCuttingReactor.StartReactor(hws, new Set); + } + return !ok; + }, "酷家乐导入"); } function ParseRoomNameMap(d: KJL_DesignData): Map @@ -288,6 +312,7 @@ async function ParseModel(model: KJL_ParamModel, roomName: string, gName: string { let mtx = new Matrix4().makeRotationFromEuler(new Euler(model.rotate.x, model.rotate.y, model.rotate.z, "ZYX")) .setPosition(model.position.x, model.position.y, model.position.z); + RoundMatrix(mtx);//因为这个会产生奇怪的数值 例如1e-16 if (model.modelTypeId === KJL_ModelType.ParamModel) { @@ -433,6 +458,14 @@ async function ParseModel(model: KJL_ParamModel, roomName: string, gName: string br.BoardProcessOption.drillType = DrillType.Invail; } + if (model.textureAngle === 0) + br.BoardProcessOption[EBoardKeyList.Lines] = LinesType.Reverse; + else + br.BoardProcessOption[EBoardKeyList.Lines] = LinesType.Positive; + + //根据kjl数据设置大孔面 + br.BoardProcessOption[EBoardKeyList.BigHole] = drillData?.bigHole === 0 ? FaceDirection.Front : FaceDirection.Back; + let n = new Vector3().setFromMatrixColumn(mtx, 2).toArray(); for (let i = 0; i < n.length; i++) { @@ -440,19 +473,49 @@ async function ParseModel(model: KJL_ParamModel, roomName: string, gName: string { switch (i) { - case 0: - br.SetBoardType(BoardType.Vertical); - br.ColorIndex = 11; - break; - case 1: - br.SetBoardType(BoardType.Behind); - br.ColorIndex = 3; - br.BoardProcessOption[EBoardKeyList.BigHole] = FaceDirection.Back; - break; - case 2: - br.SetBoardType(BoardType.Layer); - br.ColorIndex = 2; - break; + case 0://立板 + { + br.SetBoardType(BoardType.Vertical); + br.ColorIndex = 11; + + let name = br.Name; + + //镜像 + br.objectId = new ObjectId;//因为我们还没有绘制,所以给个假id 避免没有更新实体信息(因为镜像变换有这个优化) + br.ApplyMatrix(MakeMirrorMtx(ZAxis, new Vector3(0, 0, br.Thickness * 0.5))); + br.objectId = undefined; + + let ms = br.BoardModeling; + for (let m of ms) + m.dir = 1 - m.dir; + br.BoardModeling = ms; + + br.BoardProcessOption.bigHoleDir = 1 - br.BoardProcessOption.bigHoleDir; + + br.Name = name;//防止被改掉 + + //对齐坐标系 + br.SetXAxis(new Vector3(0, 1, 0), true); + break; + } + case 1://背板 + { + br.SetBoardType(BoardType.Behind); + br.ColorIndex = 3; + + //对齐坐标系 + br.SetXAxis(new Vector3(0, -1, 0), true); + break; + } + case 2://层板 + { + br.SetBoardType(BoardType.Layer); + br.ColorIndex = 2; + + //对齐坐标系 + br.SetXAxis(new Vector3(0, 1, 0), true); + break; + } } break; } @@ -461,25 +524,19 @@ async function ParseModel(model: KJL_ParamModel, roomName: string, gName: string if (parentMatrix) mtx.premultiply(parentMatrix); br.ApplyMatrix(new Matrix4().setPosition(0, 0, bmodel.thickness * -0.5).premultiply(mtx)); + NormalMatrix(br.OCSNoClone);//标准化坐标系 + RoundMatrix(br.OCSNoClone); - if (br.BoardType === BoardType.Layer) - { - let p = br.Position; - if (p.z > 1500) - br.BoardProcessOption[EBoardKeyList.BigHole] = FaceDirection.Front; - else - br.BoardProcessOption[EBoardKeyList.BigHole] = FaceDirection.Back; - } - - //根据kjl数据设置大孔面 - br.BoardProcessOption[EBoardKeyList.BigHole] = drillData?.bigHole === 0 ? FaceDirection.Front : FaceDirection.Back; - - if (model.textureAngle === 0) - br.BoardProcessOption[EBoardKeyList.Lines] = LinesType.Reverse; - else - br.BoardProcessOption[EBoardKeyList.Lines] = LinesType.Positive; - - //纹路翻转 + // if (br.BoardType === BoardType.Layer) + // { + // let p = br.Position; + // if (p.z > 1500) + // br.BoardProcessOption[EBoardKeyList.BigHole] = FaceDirection.Front; + // else + // br.BoardProcessOption[EBoardKeyList.BigHole] = FaceDirection.Back; + // } + + //纹路自动翻转 if (br.BoardProcessOption.lines === LinesType.Positive) { if (br.Width > 1220) diff --git a/src/Add-on/Mirror.ts b/src/Add-on/Mirror.ts index a1d0de69c..55f4151ba 100644 --- a/src/Add-on/Mirror.ts +++ b/src/Add-on/Mirror.ts @@ -1,7 +1,7 @@ import { Intent } from "@blueprintjs/core"; import { Matrix4, Vector3 } from "three"; import { app } from "../ApplicationServices/Application"; -import { GetMirrorMat } from "../Common/Matrix4Utils"; +import { MakeMirrorMtx } from "../Common/Matrix4Utils"; import { UpdateDraw } from "../Common/Status"; import { Hole } from "../DatabaseServices/3DSolid/Hole"; import { SweepSolid } from "../DatabaseServices/3DSolid/SweepSolid"; @@ -16,7 +16,6 @@ import { EntityRef } from "../DatabaseServices/Entity/EntityRef"; import { Command } from "../Editor/CommandMachine"; import { JigUtils } from "../Editor/JigUtils"; import { PromptStatus } from "../Editor/PromptResult"; -import { MoveMatrix } from "../Geometry/GeUtils"; import { AppToaster } from "../UI/Components/Toaster"; import { UpdateEntityDrawTask } from "./UpdateEntityDrawTask"; @@ -78,10 +77,10 @@ export class MirrorCommand implements Command Msg: "选择镜像第二点", BasePoint: p1, AllowDrawRubberBand: true, - Callback: (v) => + Callback: (p2) => { JigUtils.Restore(); - this.MirrorEntitys(cloneEns, p1, v, nor); + this.MirrorEntitys(cloneEns, p1, p2, nor); } }); if (ptRes.Status === PromptStatus.Cancel) @@ -124,13 +123,13 @@ export class MirrorCommand implements Command this.UpdateTask = undefined; } UpdateTask: UpdateEntityDrawTask; - MirrorEntitys(ens: Entity[], p1: Vector3, v: Vector3, nor: Vector3) + MirrorEntitys(ens: Entity[], p1: Vector3, p2: Vector3, planeNormal: Vector3) { - let rot = new Matrix4().makeRotationAxis(nor, Math.PI / 2); - let vec = v.clone().sub(p1).applyMatrix4(rot).normalize(); - let newMat = GetMirrorMat(vec); + let rot = new Matrix4().makeRotationAxis(planeNormal, Math.PI / 2); + let vec = p2.clone().sub(p1).applyMatrix4(rot).normalize(); + let mirrorMtx = MakeMirrorMtx(vec, p1); - let mtx = MoveMatrix(p1).multiply(newMat).multiply(MoveMatrix(p1.clone().negate())); + let mtx = mirrorMtx; for (let en of ens) { diff --git a/src/Add-on/twoD2threeD/Command_Curve2VSBox.ts b/src/Add-on/twoD2threeD/Command_Curve2VSBox.ts index f69bae888..d989313ec 100644 --- a/src/Add-on/twoD2threeD/Command_Curve2VSBox.ts +++ b/src/Add-on/twoD2threeD/Command_Curve2VSBox.ts @@ -2,7 +2,7 @@ import { Box3, Matrix4, Vector3 } from "three"; import { app } from "../../ApplicationServices/Application"; import { arrayRemoveDuplicateBySort } from "../../Common/ArrayExt"; import { IsRect } from "../../Common/CurveUtils"; -import { matrixSetVector } from "../../Common/Matrix4Utils"; +import { SetMtxVector } from "../../Common/Matrix4Utils"; import { Status } from "../../Common/Status"; import { isNum } from "../../Common/Utils"; import { Curve } from "../../DatabaseServices/Entity/Curve"; @@ -45,8 +45,8 @@ export class Command_Curve2VSBox implements Command this.spaceOCS = group.ocs.clone(); let y = new Vector3().setFromMatrixColumn(this.spaceOCS, 1); let z = new Vector3().setFromMatrixColumn(this.spaceOCS, 2); - matrixSetVector(this.spaceOCS, 1, z.negate()); - matrixSetVector(this.spaceOCS, 2, y); + SetMtxVector(this.spaceOCS, 1, z.negate()); + SetMtxVector(this.spaceOCS, 2, y); ocsInv.getInverse(group.ocs); diff --git a/src/Add-on/twoD2threeD/Polyline2Board.ts b/src/Add-on/twoD2threeD/Polyline2Board.ts index eae5ef95e..6c9422630 100644 --- a/src/Add-on/twoD2threeD/Polyline2Board.ts +++ b/src/Add-on/twoD2threeD/Polyline2Board.ts @@ -4,7 +4,7 @@ import { arrayRemoveIf } from "../../Common/ArrayExt"; import { GetRectData } from "../../Common/CurveUtils"; import { safeEval } from "../../Common/eval"; import { Buy2To3 } from "../../Common/HostUrl"; -import { matrixSetVector } from "../../Common/Matrix4Utils"; +import { SetMtxVector } from "../../Common/Matrix4Utils"; import { DuplicateRecordCloning } from "../../Common/Status"; import { FixDigits } from "../../Common/Utils"; import { Board } from "../../DatabaseServices/Entity/Board"; @@ -142,7 +142,7 @@ export class Polyline2Board implements Command //希望根据当前的ucs进行绘制,避免坐标系没有对齐的问题 let ucs = app.Editor.UCSMatrix; //对齐到pl0点 - matrixSetVector(ucs, 3, pl0.Position); + SetMtxVector(ucs, 3, pl0.Position); let ucsinv = new Matrix4().getInverse(ucs); pls = pls.filter(pl => CurveInOCS(pl, ucs, ucsinv)); for (let pl of pls) @@ -183,8 +183,8 @@ export class Polyline2Board implements Command this.SpaceOCS = ucs.clone(); let y = new Vector3().setFromMatrixColumn(this.SpaceOCS, 1); let z = new Vector3().setFromMatrixColumn(this.SpaceOCS, 2); - matrixSetVector(this.SpaceOCS, 1, z.negate()); - matrixSetVector(this.SpaceOCS, 2, y); + SetMtxVector(this.SpaceOCS, 1, z.negate()); + SetMtxVector(this.SpaceOCS, 2, y); let allBoards: Board[] = []; let layerVerBoards: Board[] = this.DrawBoard(otherPls); diff --git a/src/ApplicationServices/Application.ts b/src/ApplicationServices/Application.ts index f2f96eae1..fa0b1f2a6 100644 --- a/src/ApplicationServices/Application.ts +++ b/src/ApplicationServices/Application.ts @@ -6,6 +6,7 @@ import { HardwareCuttingReactor } from '../Add-on/BoardCutting/HardwareCuttingRe import { DrillingReactor } from '../Add-on/DrawDrilling/DrillingReactor'; import { DwgDxfImport } from '../Add-on/DXFLoad'; import { AppendUserInfo } from '../Add-on/ExportData'; +import { ImportKJLData } from '../Add-on/KJLImport'; import { CommandNames } from '../Common/CommandNames'; import { IsDev } from '../Common/Deving'; import { MouseKey } from '../Common/KeyEnum'; @@ -41,6 +42,7 @@ import { SyncDataReactor } from '../Reactor/SyncDataReactor'; import { AppToaster } from '../UI/Components/Toaster'; import { ShowToasterClearSiteData } from '../UI/Components/ToasterClearSiteData/ToasterClearSiteData'; import { DownPanelStore } from '../UI/Store/DownPanelStore'; +import { TopPanelStore } from '../UI/Store/TopPanelStore'; import { HostApplicationServices } from './HostApplicationServices'; import { WebSocketClientServer } from './WebSocketClientServer'; @@ -330,6 +332,8 @@ export class ApplicationService document.addEventListener("drop", e => { + let cadfiles: File[] = []; + let jsonFiles: File[] = []; for (let i = 0; i < e.dataTransfer.files.length; i++) { let f = e.dataTransfer.files.item(i); @@ -337,18 +341,39 @@ export class ApplicationService if (ext === ".DXF" || ext === ".DWG") { e.preventDefault(); - break; + cadfiles.push(f); + } + else if (ext === "JSON") + { + e.preventDefault(); + jsonFiles.push(f); } } - CommandWrap(async () => + const exec = async () => { - for (let i = 0; i < e.dataTransfer.files.length; i++) + if (cadfiles.length > 0) + await CommandWrap(async () => + { + for (let f of cadfiles) + await DwgDxfImport(f); + }, "CAD图纸导入"); + + if (jsonFiles.length > 0) { - let f = e.dataTransfer.files.item(i); - await DwgDxfImport(f); + const tpStore = TopPanelStore.GetInstance(); + for (let f of jsonFiles) + { + let str = await f.text(); + let obj = JSON.parse(str); + if (obj.paramModel) + if (tpStore.canKJLImport) + await ImportKJLData(obj); + } } - }, "CAD图纸导入"); + }; + + exec(); }); } diff --git a/src/Common/BoardUtil.ts b/src/Common/BoardUtil.ts index 32be5e6df..c26132c89 100644 --- a/src/Common/BoardUtil.ts +++ b/src/Common/BoardUtil.ts @@ -1,8 +1,7 @@ import { Matrix4, Vector3 } from "three"; import { Entity } from "../DatabaseServices/Entity/Entity"; import { Box3Ext } from "../Geometry/Box"; -import { MoveMatrix } from "../Geometry/GeUtils"; -import { GetMirrorMat } from "./Matrix4Utils"; +import { MakeMirrorMtx } from "./Matrix4Utils"; /**分析不同柜体 */ export function ParseBoardList(borads: T[], ocsInv?: Matrix4): Map @@ -50,16 +49,14 @@ export function ParseBoardList(borads: T[], ocsInv?: Matrix4): return boardMap; } -export function MirrorEntitys(ens: Entity[], p1: Vector3, v: Vector3, nor: Vector3) +export function MirrorEntitys(ens: Entity[], p1: Vector3, p2: Vector3, nor: Vector3) { let rot = new Matrix4().makeRotationAxis(nor, Math.PI / 2); - let vec = v.clone().sub(p1).applyMatrix4(rot).normalize(); - let newMat = GetMirrorMat(vec); - - let mtx = MoveMatrix(p1).multiply(newMat).multiply(MoveMatrix(p1.clone().negate())); + let vec = p2.clone().sub(p1).applyMatrix4(rot).normalize(); + let mirrorMtx = MakeMirrorMtx(vec, p1); for (let en of ens) { - en.ApplyMatrix(mtx); + en.ApplyMatrix(mirrorMtx); } } diff --git a/src/Common/Matrix4Utils.ts b/src/Common/Matrix4Utils.ts index 7526e9ab0..8f90a0d39 100644 --- a/src/Common/Matrix4Utils.ts +++ b/src/Common/Matrix4Utils.ts @@ -4,16 +4,16 @@ import { equaln, isParallelTo } from '../Geometry/GeUtils'; /** * 设置矩阵的某列的向量 - * @param {Matrix4} mat 矩阵 + * @param {Matrix4} mtx 矩阵 * @param {number} col 列索引,0x 1y 2z 3org * @param {Vector3} v 向量或点 */ -export function matrixSetVector(mat: Matrix4, col: number, v: Vector3) +export function SetMtxVector(mtx: Matrix4, col: number, v: Vector3) { let index = col * 4; - mat.elements[index] = v.x; - mat.elements[index + 1] = v.y; - mat.elements[index + 2] = v.z; + mtx.elements[index] = v.x; + mtx.elements[index + 1] = v.y; + mtx.elements[index + 2] = v.z; } /** @@ -90,8 +90,7 @@ export function reviseMirrorMatrix(mtx: Matrix4, index = 1): Matrix4 else cs.ZAxis.negate(); - mtx.copy(cs.getMatrix4()); - return mtx; + return cs.getMatrix4(mtx); } let cacheVec: Vector3; @@ -108,17 +107,28 @@ export function Vector2ApplyMatrix4(mtx: Matrix4, vec: Vector2) vec.x = cacheVec.x; vec.y = cacheVec.y; } -export function GetMirrorMat(v: Vector3) + +export function MakeMirrorMtx(planeNormal: Vector3, pos?: Vector3) { - let mirrorMat = new Matrix4(); - let xAxis = new Vector3(1 - 2 * v.x ** 2, -2 * v.x * v.y, -2 * v.x * v.z); - let yAxis = new Vector3(-2 * v.x * v.y, 1 - 2 * v.y ** 2, -2 * v.y * v.z); - let zAxis = new Vector3(-2 * v.x * v.z, -2 * v.y * v.z, 1 - 2 * v.z ** 2); - mirrorMat.makeBasis(xAxis, yAxis, zAxis); - return mirrorMat; + let mirrorMtx = new Matrix4(); + let xAxis = new Vector3(1 - 2 * planeNormal.x ** 2, -2 * planeNormal.x * planeNormal.y, -2 * planeNormal.x * planeNormal.z); + let yAxis = new Vector3(-2 * planeNormal.x * planeNormal.y, 1 - 2 * planeNormal.y ** 2, -2 * planeNormal.y * planeNormal.z); + let zAxis = new Vector3(-2 * planeNormal.x * planeNormal.z, -2 * planeNormal.y * planeNormal.z, 1 - 2 * planeNormal.z ** 2); + mirrorMtx.makeBasis(xAxis, yAxis, zAxis); + + if (pos) + mirrorMtx.setPosition(pos.clone().applyMatrix4(mirrorMtx).sub(pos).negate()); + + return mirrorMtx; } -export function ApplyMatrix4IgnorePosition(vec: { x: number, y: number, z: number; }, m: Matrix4) +/** + * 对向量进行方向变换 (如果是pos 请使用pos.applyMatrix4) + * @param vec 向量 + * @param m 矩阵 + * @returns vec + */ +export function TransformVector(vec: T, m: Matrix4): T { let { x, y, z } = vec; let e = m.elements; @@ -164,7 +174,19 @@ export function NormalMatrix(mtx: Matrix4) return mtx; } +//四舍五入 +export function RoundMatrix(mtx: Matrix4, fuzz = 1e-6) +{ + let el = mtx.elements; + for (let i = 0; i < 16; i++) + { + let re = Math.round(el[i]); + if (equaln(re, el[i], fuzz)) + el[i] = re; + } + return mtx; +} export const tempMatrix1 = new Matrix4; -export const ZMirrorMatrix = GetMirrorMat(new Vector3(0, 0, 1)); +export const ZMirrorMatrix = MakeMirrorMtx(new Vector3(0, 0, 1)); diff --git a/src/DatabaseServices/Entity/Arc.ts b/src/DatabaseServices/Entity/Arc.ts index c41854e26..a709f9ca5 100644 --- a/src/DatabaseServices/Entity/Arc.ts +++ b/src/DatabaseServices/Entity/Arc.ts @@ -1,6 +1,6 @@ import { Box3, Matrix3, Matrix4, Vector2, Vector3 } from 'three'; import { getArcOrCirNearPts, getCircleCenter, GetTanPtsOnArcOrCircle } from '../../Common/CurveUtils'; -import { matrixSetVector, reviseMirrorMatrix } from '../../Common/Matrix4Utils'; +import { reviseMirrorMatrix, SetMtxVector } from '../../Common/Matrix4Utils'; import { Status } from '../../Common/Status'; import { ObjectSnapMode } from '../../Editor/ObjectSnapMode'; import { Box3Ext } from '../../Geometry/Box'; @@ -69,7 +69,7 @@ export class Arc extends Curve set Normal(v: Vector3) { this.WriteAllObjectRecord(); - matrixSetVector(this._Matrix, 2, v); + SetMtxVector(this._Matrix, 2, v); this.Update(); } diff --git a/src/DatabaseServices/Entity/Board.ts b/src/DatabaseServices/Entity/Board.ts index f027286c4..e3a3dab91 100644 --- a/src/DatabaseServices/Entity/Board.ts +++ b/src/DatabaseServices/Entity/Board.ts @@ -6,17 +6,17 @@ import { HostApplicationServices } from '../../ApplicationServices/HostApplicati import { arrayRemoveIf, arraySortByNumber, arraySum } from '../../Common/ArrayExt'; import { EBoardKeyList } from '../../Common/BoardKeyList'; import { ColorMaterial } from '../../Common/ColorPalette'; -import { ZMirrorMatrix } from '../../Common/Matrix4Utils'; +import { tempMatrix1, TransformVector, ZMirrorMatrix } from '../../Common/Matrix4Utils'; import { UpdateDraw } from '../../Common/Status'; import { ObjectSnapMode } from '../../Editor/ObjectSnapMode'; import { boardUVGenerator, boardUVGenerator2 } from '../../Geometry/BoardUVGenerator'; import { BufferGeometryUtils } from '../../Geometry/BufferGeometryUtils'; -import { equaln, XAxis, XAxisN, YAxis, YAxisN, ZAxis, ZeroVec } from '../../Geometry/GeUtils'; +import { equaln, equalv3, IdentityMtx4, XAxis, XAxisN, YAxis, YAxisN, ZAxis, ZeroVec } from '../../Geometry/GeUtils'; import { PointShapeUtils } from '../../Geometry/PointShapeUtils'; import { GetBoardHighSeal, GetBoardSealingCurves, HandleRectBoardSealingData } from '../../GraphicsSystem/CalcEdgeSealing'; import { RenderType } from '../../GraphicsSystem/RenderType'; import { VData2Curve, VKnifToolPath } from '../../GraphicsSystem/ToolPath/VKnifToolPath'; -import { BoardOpenDir, BoardProcessOption, BoardType, ComposingType, FaceDirection, LinesType } from '../../UI/Store/BoardInterface'; +import { BoardOpenDir, BoardProcessOption, BoardType, ComposingType, FaceDirection, IHighSealedItem, LinesType } from '../../UI/Store/BoardInterface'; import { CylinderHole } from '../3DSolid/CylinderHole'; import { ExtrudeHole } from '../3DSolid/ExtrudeHole'; import { AutoRecord } from '../AutoRecord'; @@ -413,7 +413,7 @@ export class Board extends ExtrudeSolid let models: IModeling[] = []; for (let g of this.grooves) { - let cu = g.ContourCurve.Clone().ApplyMatrix(this.OCSInv.multiply(g.OCS)); + let cu = g.ContourCurve.Clone().ApplyMatrix(this.OCSInv.multiply(g.OCSNoClone)); cu.Erase(false);//当内部造型超过100个时,不校验时,这个曲线就是erase的状态,所以设置这个状态,避免无法绘制出来 if (cu instanceof Circle)//这里保证这个圆是正常坐标系 I3BUSY#note_4525213 cu.OCS = new Matrix4().setPosition(cu.Position); @@ -422,7 +422,7 @@ export class Board extends ExtrudeSolid let holes: Contour[] = []; for (let subG of g.Grooves) { - let holeCu = subG.ContourCurve.Clone().ApplyMatrix(this.OCSInv.multiply(subG.OCS)); + let holeCu = subG.ContourCurve.Clone().ApplyMatrix(this.OCSInv.multiply(subG.OCSNoClone)); holes.push(Contour.CreateContour(holeCu, false)); } @@ -794,6 +794,51 @@ export class Board extends ExtrudeSolid return Board2Regions(this); } + /** + * 在不改变Normal和实体显示的情况下,修改X轴的指向 + * @param xAxis + */ + override SetXAxis(xAxis: Vector3, isKeepLines = false): this + { + let ocsInv = this.OCSInv; + let x = TransformVector(xAxis.clone(), ocsInv).setZ(0).normalize(); + if (equalv3(ZeroVec, x, 1e-5)) return this; + + this.WriteAllObjectRecord(); + + let highSeals: IHighSealedItem[]; + if (this.isRect) + highSeals = GetBoardHighSeal(this, GetBoardSealingCurves(this)); + + let a = Math.atan2(x.y, x.x); + + if (isKeepLines && this.BoardProcessOption.lines !== LinesType.CanReversal && (equaln(x.y, 1, 1e-5) || equaln(x.y, -1, 1e-5))) + this.BoardProcessOption.lines = 1 - this.BoardProcessOption.lines;//翻转纹路 1=>0 0=>1 + + x.transformDirection(this._Matrix); + let z = this.Normal; + let y = z.cross(x); + + this._Matrix.elements[0] = x.x; + this._Matrix.elements[1] = x.y; + this._Matrix.elements[2] = x.z; + + this._Matrix.elements[4] = y.x; + this._Matrix.elements[5] = y.y; + this._Matrix.elements[6] = y.z; + + this.ContourCurve.ApplyMatrix(tempMatrix1.makeRotationZ(-a));//复用了这个矩阵 + this.CheckContourCurve(); + if (this.contourCurve instanceof Polyline) + this.contourCurve.UpdateMatrixTo(IdentityMtx4); + + if (this.isRect) + HandleRectBoardSealingData(this, highSeals); + + this.Update(); + return this; + } + RotateBoard(rox: number, roy: number, roz: number) { this.WriteAllObjectRecord(); @@ -824,7 +869,10 @@ export class Board extends ExtrudeSolid protected ApplyMirrorMatrix(m: Matrix4) { if (!this.Id) + { + // super.ApplyMirrorMatrix(m); //这个变更导致镜像错误 因为实体没有正常的被更新. 所以需要注意的是,如果需要镜像变更,需要给实体一个id!!! return this; + } let cus = GetBoardSealingCurves(this); let highSeals = GetBoardHighSeal(this, cus); diff --git a/src/DatabaseServices/Entity/Extrude.ts b/src/DatabaseServices/Entity/Extrude.ts index ee3cf51dd..2d1dbac19 100644 --- a/src/DatabaseServices/Entity/Extrude.ts +++ b/src/DatabaseServices/Entity/Extrude.ts @@ -9,7 +9,7 @@ import { CSGIntersect } from '../../Common/CSGIntersect'; import { equalCurve, PolylineSpliteRect } from "../../Common/CurveUtils"; import { DisposeThreeObj, Object3DRemoveAll } from "../../Common/Dispose"; import { Log } from "../../Common/Log"; -import { matrixSetVector, reviseMirrorMatrix, Vector2ApplyMatrix4 } from "../../Common/Matrix4Utils"; +import { reviseMirrorMatrix, SetMtxVector, tempMatrix1, TransformVector, Vector2ApplyMatrix4 } from "../../Common/Matrix4Utils"; import { Status, UpdateDraw } from "../../Common/Status"; import { Geometry2CSG2 } from "../../csg/core/Geometry2CSG"; import { ObjectSnapMode } from "../../Editor/ObjectSnapMode"; @@ -83,7 +83,7 @@ export class ExtrudeSolid extends Entity __OriginalEnt__: this; /** * 拉伸形状 - * 出于优化考虑,可能未初始化 + * 出于优化考虑,可能未初始化,请注意调用this.ContourCurve * 形状位于WCS 0点位置,不随OCS变化而变化 */ protected contourCurve: ExtrudeContourCurve; @@ -221,7 +221,12 @@ export class ExtrudeSolid extends Entity super.ApplyMatrix(m); for (let g of this.grooves) + { + g._SpaceOCS.copy(this._SpaceOCS);//因为在镜像的时候 没有设置这个会导致错误 所以拷贝一下 + g.objectId = new ObjectId; g.ApplyMatrix(m); + g.objectId = undefined; + } //由于修改矩阵会导致矩阵错误 this.csg = undefined; @@ -250,20 +255,21 @@ export class ExtrudeSolid extends Entity } protected ApplyMirrorMatrix(m: Matrix4) { + this.WriteAllObjectRecord(); const curve = this.ContourCurve; if (curve instanceof Polyline && !equalv3(curve.Position, ZeroVec)) { let pts = curve.LineData; if (equalv2(pts[0].pt, arrayLast(pts).pt)) pts.pop(); - let ocs = curve.OCS; + let ocs = curve.OCSNoClone; for (let p of pts) { Vector2ApplyMatrix4(ocs, p.pt); } curve.OCS = IdentityMtx4; } - let nor = this.Normal.applyMatrix4(this.SpaceOCSInv.setPosition(new Vector3)); + let nor = this.Normal.applyMatrix4(this.SpaceOCSInv.setPosition(ZeroVec)); if (equaln(Math.abs(nor.z), 1)) { reviseMirrorMatrix(this._Matrix, 1); @@ -273,9 +279,7 @@ export class ExtrudeSolid extends Entity } else { - let ocs = curve.OCS; - reviseMirrorMatrix(ocs, 1); - curve.OCS = ocs; + reviseMirrorMatrix(curve.OCSNoClone, 1); } this.SetContourCurve(curve); @@ -294,9 +298,7 @@ export class ExtrudeSolid extends Entity } else { - let ocs = curve.OCS; - reviseMirrorMatrix(ocs, 0); - curve.OCS = ocs; + reviseMirrorMatrix(curve.OCSNoClone, 0); } this.SetContourCurve(curve); @@ -415,7 +417,7 @@ export class ExtrudeSolid extends Entity /** * 更新拉伸实体的轮廓 - * @param curve 曲线已经存在WCS坐标系 + * @param curve 曲线已经存在WCS坐标系0点 */ SetContourCurve(curve: ExtrudeContourCurve) { @@ -474,16 +476,15 @@ export class ExtrudeSolid extends Entity */ SetXAxis(xAxis: Vector3): this { - let m = this.OCSInv.setPosition(ZeroVec); - let x = xAxis.applyMatrix4(m).setZ(0).normalize(); - if (equalv3(ZeroVec, x)) return this; + let ocsInv = this.OCSInv; + let x = TransformVector(xAxis.clone(), ocsInv).setZ(0).normalize(); + if (equalv3(ZeroVec, x, 1e-5)) return this; this.WriteAllObjectRecord(); let a = Math.atan2(x.y, x.x); - m.copy(this._Matrix).setPosition(ZeroVec); - x.applyMatrix4(m); + x.transformDirection(this._Matrix); let z = this.Normal; let y = z.cross(x); @@ -495,11 +496,10 @@ export class ExtrudeSolid extends Entity this._Matrix.elements[5] = y.y; this._Matrix.elements[6] = y.z; - m.makeRotationZ(-a); - this.contourCurve.ApplyMatrix(m); + this.ContourCurve.ApplyMatrix(tempMatrix1.makeRotationZ(-a));//复用了这个矩阵 this.CheckContourCurve(); if (this.contourCurve instanceof Polyline) - this.contourCurve.UpdateMatrixTo(m.identity()); + this.contourCurve.UpdateMatrixTo(IdentityMtx4); this.Update(); return this; @@ -1106,10 +1106,10 @@ export class ExtrudeSolid extends Entity if (parType === 2) { let mtx = target._Matrix; - matrixSetVector(mtx, 2, n1); + SetMtxVector(mtx, 2, n1); let p = n1.setFromMatrixColumn(mtx, 3); p.add(n2.multiplyScalar(target.thickness)); - matrixSetVector(mtx, 3, p); + SetMtxVector(mtx, 3, p); } if (this.GrooveCheckPosition(target) !== Status.True) return []; diff --git a/src/DatabaseServices/Entity/Polyline.ts b/src/DatabaseServices/Entity/Polyline.ts index 1917be881..520f3f180 100644 --- a/src/DatabaseServices/Entity/Polyline.ts +++ b/src/DatabaseServices/Entity/Polyline.ts @@ -23,6 +23,7 @@ export interface PolylineProps pt: Vector2, bul: number; } + @Factory export class Polyline extends Curve { @@ -40,7 +41,7 @@ export class Polyline extends Curve if (equaln(p.z, 0)) { let dir = Math.sign(this.Area2); - let tm = matrixAlignCoordSys(this.OCS, m); + let tm = matrixAlignCoordSys(this.OCSNoClone, m); for (let p of this._LineData) { let p3 = AsVector3(p.pt); diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 734218fdd..9ce45c2d9 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -533,7 +533,7 @@ export function registerCommand() if (IsTest()) { commandMachine.RegisterCommand("box", new Command_TestBox()); - commandMachine.RegisterCommand("testInt", new TestIntersect()); + commandMachine.RegisterCommand("TestIntersect", new TestIntersect()); commandMachine.RegisterCommand("collison", new TestCollision()); } diff --git a/src/Editor/SnapServices.ts b/src/Editor/SnapServices.ts index 458e6a0c3..dcc0d59cc 100644 --- a/src/Editor/SnapServices.ts +++ b/src/Editor/SnapServices.ts @@ -72,6 +72,7 @@ export class SnapServices { Disabled: boolean = false;//禁用捕捉 FilterErase = true; + FilterEntitys: Set; SnapSize = 15;//捕捉框大小 AxisSnapMode = AxisSnapMode.Polar;//极轴捕捉模式 SnapPoint: Vector3;//捕捉到的点 @@ -252,6 +253,9 @@ export class SnapServices for (let obj of app.Viewer.VisibleObjects) { let ent = GetEntity(obj); + + if (this.FilterEntitys && this.FilterEntitys.has(ent)) continue; + if (ent instanceof Circle || ent instanceof Arc) { if (this.FilterErase) @@ -274,6 +278,8 @@ export class SnapServices filterErase: true, filterFunction: (obj, ent) => { + if (this.FilterEntitys && this.FilterEntitys.has(ent)) return false; + // if (cacheSet.has(ent)) return false; // 不要了,不然无法显示捕捉点 @@ -285,7 +291,7 @@ export class SnapServices // cacheSet.add(ent); // console.time(); - // //黑魔法,提高性能,否则如果是概念视觉央视下,还要选一遍网格体,亏死 + // //黑魔法,提高性能,否则如果是概念视觉样式下,还要选一遍网格体,亏死 // if (sel.CheckSelectTraverse(ent.GetDrawObjectFromRenderType(RenderType.Wireframe))) // selectEns.push(ent); // console.timeEnd(); @@ -675,7 +681,16 @@ export class SnapServices if (this.SnapModeEnable & ObjectSnapMode.Int) { let sel = new SelectPick(app.Viewer, nowVCS); - sel.Select(app.Viewer.VisibleObjects, { filterTypes: [Curve], filterErase: true }); + sel.Select(app.Viewer.VisibleObjects, { + filterTypes: [Curve], + filterErase: true, + filterFunction: (obj, ent?) => + { + if (this.FilterEntitys && this.FilterEntitys.has(ent)) return false; + + return true; + }, + }); let cus = sel.SelectEntityList as Curve[]; //轴线与实体的交点 diff --git a/src/Geometry/CoordinateSystem.ts b/src/Geometry/CoordinateSystem.ts index 71f2a0114..6f54224ad 100644 --- a/src/Geometry/CoordinateSystem.ts +++ b/src/Geometry/CoordinateSystem.ts @@ -28,9 +28,8 @@ export class CoordinateSystem return this; } - getMatrix4(): Matrix4 + getMatrix4(m = new Matrix4): Matrix4 { - let m = new Matrix4(); m.makeBasis(this.XAxis, this.YAxis, this.ZAxis); m.setPosition(this.Postion); return m; diff --git a/src/Geometry/DrillParse/BoardGetFace.ts b/src/Geometry/DrillParse/BoardGetFace.ts index c59d81d1a..f66d695c2 100644 --- a/src/Geometry/DrillParse/BoardGetFace.ts +++ b/src/Geometry/DrillParse/BoardGetFace.ts @@ -1,6 +1,6 @@ import { Matrix4, Vector3 } from "three"; import { MergeCurvelist } from "../../Common/CurveUtils"; -import { GetMirrorMat } from "../../Common/Matrix4Utils"; +import { MakeMirrorMtx } from "../../Common/Matrix4Utils"; import { Arc } from "../../DatabaseServices/Entity/Arc"; import { Board } from "../../DatabaseServices/Entity/Board"; import { Curve } from "../../DatabaseServices/Entity/Curve"; @@ -56,13 +56,13 @@ export class BoardGetFace if (opt.backDrill || isEdgeFace) { - let mat = GetMirrorMat(ZAxis).setPosition(new Vector3()); + let mtx = MakeMirrorMtx(ZAxis); this.Faces.push(new Face({ type: BoardFaceType.NoSide, localBoard: this.Board, isRect: this.Board.IsRect, region: reg ? reg.Clone() : undefined, - matrix4: new Matrix4().multiplyMatrices(ocs.clone(), mat), + matrix4: new Matrix4().multiplyMatrices(ocs, mtx), length: this.Board.Width, width: this.Board.Height })); @@ -166,7 +166,7 @@ export function GetSideFaceMtx(cu: Curve, inverseZ = false): Matrix4 if (inverseZ) z.negate(); let basePt: Vector3; - if ((equaln(x.x, 0) && x.y > 0) || x.x < 0) + if ((equaln(x.x, 0, 1e-5) && x.y > 0) || x.x < -1e-5) { x.negate(); basePt = cu.EndPoint; diff --git a/src/Geometry/SpaceParse/Point2SpaceParse.ts b/src/Geometry/SpaceParse/Point2SpaceParse.ts index d954565cc..90bfb120b 100644 --- a/src/Geometry/SpaceParse/Point2SpaceParse.ts +++ b/src/Geometry/SpaceParse/Point2SpaceParse.ts @@ -1,6 +1,6 @@ import { Matrix4, Vector3 } from "three"; import { app } from "../../ApplicationServices/Application"; -import { matrixSetVector } from "../../Common/Matrix4Utils"; +import { SetMtxVector } from "../../Common/Matrix4Utils"; import { GetEntity } from "../../Common/Utils"; import { Board } from "../../DatabaseServices/Entity/Board"; import { PointPick } from "../../Editor/PointPick"; @@ -44,8 +44,8 @@ export class Point2SpaceParse extends ISpaceParse let y = new Vector3().setFromMatrixColumn(this.SpaceOCS, 1); let z = new Vector3().setFromMatrixColumn(this.SpaceOCS, 2); - matrixSetVector(this.SpaceOCS, 1, z.negate()); - matrixSetVector(this.SpaceOCS, 2, y); + SetMtxVector(this.SpaceOCS, 1, z.negate()); + SetMtxVector(this.SpaceOCS, 2, y); [this.SpaceBox.min.y, this.SpaceBox.min.z] = [this.SpaceBox.min.z, this.SpaceBox.min.y]; [this.SpaceBox.max.y, this.SpaceBox.max.z] = [this.SpaceBox.max.z, this.SpaceBox.max.y]; diff --git a/src/Nest/Common/ClipperCpp.ts b/src/Nest/Common/ClipperCpp.ts index 4a3657633..b22db62fd 100644 --- a/src/Nest/Common/ClipperCpp.ts +++ b/src/Nest/Common/ClipperCpp.ts @@ -15,7 +15,7 @@ export function InitClipperCpp(): Promise { clipperCpp.lib = c; res(); - console.log("载入成功!"); + // console.log("载入成功!");//不再需要 }); }); } diff --git a/src/UI/Components/Board/BoardConfigModal.tsx b/src/UI/Components/Board/BoardConfigModal.tsx index 522a0f813..01d28f103 100644 --- a/src/UI/Components/Board/BoardConfigModal.tsx +++ b/src/UI/Components/Board/BoardConfigModal.tsx @@ -8,6 +8,7 @@ import { app } from "../../../ApplicationServices/Application"; import { CheckObjectType } from "../../../Common/CheckoutVaildValue"; import { ConverCircleToPolyline, curveLinkGroup } from "../../../Common/CurveUtils"; import { Log } from "../../../Common/Log"; +import { NormalMatrix } from "../../../Common/Matrix4Utils"; import { FixedNotZero, GetEntity } from "../../../Common/Utils"; import { Contour } from "../../../DatabaseServices/Contour"; import { Arc } from "../../../DatabaseServices/Entity/Arc"; @@ -234,9 +235,10 @@ export class BoardConfigModal extends React.Component{ if (isParallelTo(new Vector3().setFromMatrixColumn(ucsMtx, 2), br.Normal)) app.Editor.UCSMatrix = ucsMtx.setPosition(br.Position); else - app.Editor.UCSMatrix = new Matrix4().extractRotation(br.OCS); + app.Editor.UCSMatrix = new Matrix4().extractRotation(br.OCSNoClone); - let cu = JigUtils.Draw(br.ContourCurve.Clone().ApplyMatrix(br.OCS)); + let cu = JigUtils.Draw(br.ContourCurve.Clone().ApplyMatrix(br.OCSNoClone)); + NormalMatrix(cu.OCSNoClone);//酷家乐的矩阵异常导致的坐标系错误! LastExtractBoardContour.Contour = cu; cu.Erase(false); let moveCus = [cu]; @@ -264,12 +266,12 @@ export class BoardConfigModal extends React.Component{ store.modelingStore.ChangeModelingValue(color - 1, data); } - let cu = JigUtils.Draw(data.shape.Outline.Curve.Clone().Z0().ApplyMatrix(br.OCS)); + let cu = JigUtils.Draw(data.shape.Outline.Curve.Clone().Z0().ApplyMatrix(br.OCSNoClone)); cu.ColorIndex = color; moveCus.push(cu); for (let c of data.shape.Holes) { - cu = JigUtils.Draw(c.Curve.Clone().Z0().ApplyMatrix(br.OCS)); + cu = JigUtils.Draw(c.Curve.Clone().Z0().ApplyMatrix(br.OCSNoClone)); cu.ColorIndex = color; moveCus.push(cu); }