From c5fc05c3c515b5188978dcfaf52f0c1df86d83e8 Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 24 Jul 2018 16:12:37 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=BA=AF=E5=87=80=E7=9A=84=E4=BA=8C?= =?UTF-8?q?=E7=BB=B4=E7=BB=98=E5=9B=BE=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GraphicsSystem/Viewer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GraphicsSystem/Viewer.ts b/src/GraphicsSystem/Viewer.ts index 185e71d03..b9adb3fce 100644 --- a/src/GraphicsSystem/Viewer.ts +++ b/src/GraphicsSystem/Viewer.ts @@ -99,9 +99,9 @@ export class Viewer this.m_Render.autoClear = true; //如果设置,那么它希望所有的纹理和颜色都是预乘的伽玛。默认值为false。 - this.m_Render.gammaInput = true; - this.m_Render.gammaOutput = true; - this.m_Render.shadowMap.enabled = true; + // this.m_Render.gammaInput = true; + // this.m_Render.gammaOutput = true; + // this.m_Render.shadowMap.enabled = true; this.m_Render.setPixelRatio(window.devicePixelRatio); //以下参数为三维渲染时需要开启的参数. From 3c1e121b2cc1ca8958398eba014ddaef7ce363be Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 24 Jul 2018 16:12:52 +0800 Subject: [PATCH 2/6] =?UTF-8?q?dll=E4=B8=8D=E5=9C=A8=E6=8F=90=E4=BE=9Bsour?= =?UTF-8?q?ce-map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dll.config.js | 2 +- webpack.config.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dll.config.js b/dll.config.js index b3e4232dd..a0f114617 100644 --- a/dll.config.js +++ b/dll.config.js @@ -27,7 +27,7 @@ module.exports = { }, resolve: { }, - devtool: "source-map", + // devtool: "source-map", plugins: [ new webpack.DllPlugin({ path: 'manifest.json', diff --git a/webpack.config.ts b/webpack.config.ts index c1ed54d91..500276ce9 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -135,7 +135,10 @@ const config: webpack.Configuration = { typeOfAsset: "css", includeSourcemap: false }, - { filepath: "./dist/dll.js" }, + { + filepath: "./dist/dll.js", + includeSourcemap: false + }, { filepath: "./node_modules/three/build/three.min.js", includeSourcemap: false }, { filepath: "./node_modules//three/examples/js/libs/inflate.min.js", From 306cd25033a228da3a88a6ce115c3c9cb043f9c8 Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 24 Jul 2018 16:29:18 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=A7=BB=E9=99=A4code=E5=91=BD=E4=BB=A4,?= =?UTF-8?q?=E6=9B=B4=E5=A5=BD=E7=9A=84=E4=BD=BF=E7=94=A8co?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/GenerateCode.ts | 31 ------------------------------- src/Editor/CommandRegister.ts | 17 +++++++---------- 2 files changed, 7 insertions(+), 41 deletions(-) delete mode 100644 src/Add-on/GenerateCode.ts diff --git a/src/Add-on/GenerateCode.ts b/src/Add-on/GenerateCode.ts deleted file mode 100644 index 5f34ba0c7..000000000 --- a/src/Add-on/GenerateCode.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { app } from '../ApplicationServices/Application'; -import { Command } from "../Editor/CommandMachine"; -import { PromptStatus } from "../Editor/PromptResult"; -import { CADFile } from '../DatabaseServices/CADFile'; -import { copyTextToClipboard } from '../Common/Utils'; - -/** - * 选择实体,生成构建代码. - * - * @export - * @class Command_GenerateCode - * @implements {Command} - */ -export class Command_GenerateCode implements Command -{ - async exec() - { - let ssRes = await app.m_Editor.GetSelection({ UseSelect: true }); - if (ssRes.Status != PromptStatus.OK) return; - - let file = new CADFile(); - - for (let en of ssRes.SelectSet.SelectEntityList) - { - file.WriteObject(en); - } - copyTextToClipboard(JSON.stringify(file.Data)); - - app.m_Editor.m_CommandStore.Prompt("成功拷贝到剪切板."); - } -} diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index fe714d0dd..2fa0cca78 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -1,12 +1,14 @@ import { DrawAxis } from '../Add-on/AddAxis'; import { Command_Array } from '../Add-on/Array'; import { IntersectionOperation, SubsractOperation, UnionOperation } from '../Add-on/BoolOperation'; +import { Command_Break } from '../Add-on/Break'; import { Command_ClosePt } from '../Add-on/closetest'; import { Command_Copy } from '../Add-on/Copy'; import { CopyClip } from '../Add-on/CopyClip'; import { Command_CopyPoint } from '../Add-on/CopyPoint'; import { CustomUcs } from '../Add-on/CostumUCS'; import { Union } from '../Add-on/CSGUnion'; +import { CMD_Divide } from '../Add-on/Divide'; import { DrawArc } from '../Add-on/DrawArc'; import { Command_DrawBoard } from '../Add-on/DrawBoard'; import { DrawAlignedDimension } from '../Add-on/DrawDim/DrawAlignedDimension'; @@ -16,6 +18,7 @@ import { DrawEllipse } from '../Add-on/DrawEllipse'; import { DrawFloor } from '../Add-on/DrawFloor'; import { DrawGripStretch } from '../Add-on/DrawGripStretch'; import { DrawCircle, DrawLine, DrawSphere, DrawTest, ZoomE } from '../Add-on/DrawLine'; +import { CMD_DrawPoint } from '../Add-on/DrawPoint'; import { DrawPolyline } from '../Add-on/DrawPolyline'; import { DrawRect } from '../Add-on/DrawRec'; import { DrawRegion } from '../Add-on/DrawRegion'; @@ -29,14 +32,14 @@ import { Command_Erase } from '../Add-on/Erase'; import { Command_Explode } from '../Add-on/Explode'; import { Command_Extend } from '../Add-on/Extends'; import { CommandFillet } from '../Add-on/Fillet'; -import { Command_GenerateCode } from '../Add-on/GenerateCode'; import { Command_INsTest } from '../Add-on/instest'; import { Command_Join } from '../Add-on/Join'; +import { Command_Length } from '../Add-on/Length'; import { Command_Lisp } from '../Add-on/Lisp'; import { Fbx } from '../Add-on/loadfbx'; import { LoadImg } from '../Add-on/LoadImg'; import { Command_Move } from '../Add-on/Move'; -import { Command_Offset, Command_TestOffset } from '../Add-on/Offset'; +import { Command_Offset } from '../Add-on/Offset'; import { OffsetX } from '../Add-on/OffsetX'; import { Open } from '../Add-on/Open'; import { PasteClip } from '../Add-on/PasteClip'; @@ -46,8 +49,10 @@ import { Command_PtInCu } from '../Add-on/ptincu'; import { Command_RevPl } from '../Add-on/RevPl'; import { Command_Rotate } from '../Add-on/Rotate'; import { Save } from '../Add-on/Save'; +import { Command_Scale } from '../Add-on/Scale'; import { Command_Ssget } from '../Add-on/ssget'; import { Stretch } from '../Add-on/Stretch'; +import { Sweep } from '../Add-on/Sweep'; import { Command_SwitchCamera } from '../Add-on/SwitchCamera'; import { Command_SwitchPass } from '../Add-on/SwitchPass'; // import { DrawFloor } from '../Add-on/DrawFloor'; @@ -64,12 +69,6 @@ import { Redo, Undo } from '../Add-on/Undo'; import { ViewToFront, ViewToRight, ViewToTop } from '../Add-on/ViewChange'; import { Command_DimTest } from '../DatabaseServices/Dimension/dimTest'; import { commandMachine } from './CommandMachine'; -import { Sweep } from '../Add-on/Sweep'; -import { Command_Scale } from '../Add-on/Scale'; -import { Command_Break } from '../Add-on/Break'; -import { Command_Length } from '../Add-on/Length'; -import { CMD_Divide } from '../Add-on/Divide'; -import { CMD_DrawPoint } from '../Add-on/DrawPoint'; export function registerCommand() { @@ -185,7 +184,6 @@ export function registerCommand() commandMachine.RegisterCommand("close", new Command_ClosePt()); //用于测试包围盒 commandMachine.RegisterCommand("box", new Command_TestBox()); - commandMachine.RegisterCommand("testoffset", new Command_TestOffset()); //测试标注 commandMachine.RegisterCommand("testdim", new Command_DimTest()); @@ -194,7 +192,6 @@ export function registerCommand() commandMachine.RegisterCommand("incu", new Command_PtInCu()); - commandMachine.RegisterCommand("code", new Command_GenerateCode()); commandMachine.RegisterCommand("outcur", new TestTargeOnCurve()); commandMachine.RegisterCommand("join", new Command_Join()); From 76d5aa098108238344657d7962cfe2d5eae13d92 Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 24 Jul 2018 17:44:58 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=AE=8C=E6=88=90Jig=E5=8A=9F=E8=83=BD,?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BD=BF=E7=94=A8=E5=8A=A8=E6=80=81=E6=8B=BD?= =?UTF-8?q?=E6=8B=96=E5=91=BD=E4=BB=A4=E7=9A=84=E5=AE=9E=E7=8E=B0,copy?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=9E=E7=BB=AD=E5=A4=8D=E5=88=B6.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/Copy.ts | 81 ++++++++++-------------- src/Add-on/DrawArc.ts | 15 ++--- src/Add-on/DrawLine.ts | 41 +++++------- src/Add-on/DrawPolyline.ts | 49 ++++++++------ src/Add-on/DrawRec.ts | 14 ++-- src/Add-on/Move.ts | 38 ++++------- src/Add-on/Offset.ts | 89 +++++++++++--------------- src/Add-on/Stretch.ts | 68 ++++++++------------ src/Common/ColorPalette.ts | 2 +- src/Common/Dispose.ts | 11 ++++ src/DatabaseServices/CADObject.ts | 25 ++++---- src/DatabaseServices/Curve.ts | 13 +++- src/DatabaseServices/Entity.ts | 38 ++++++----- src/DatabaseServices/Polyline.ts | 23 +++++-- src/Editor/CommandMachine.ts | 13 ++-- src/Editor/Jig.ts | 102 ++++++++++++++++++++++++++++++ src/Editor/SnapDragServices.ts | 42 +++--------- src/Editor/SnapServices.ts | 1 + src/GraphicsSystem/Viewer.ts | 1 + 19 files changed, 368 insertions(+), 298 deletions(-) create mode 100644 src/Common/Dispose.ts create mode 100644 src/Editor/Jig.ts diff --git a/src/Add-on/Copy.ts b/src/Add-on/Copy.ts index 046dd06f8..c92dd9d4b 100644 --- a/src/Add-on/Copy.ts +++ b/src/Add-on/Copy.ts @@ -1,66 +1,53 @@ import { app } from '../ApplicationServices/Application'; -import { Entity } from '../DatabaseServices/Entity'; import { Command } from '../Editor/CommandMachine'; +import { Jig } from '../Editor/Jig'; import { PromptStatus } from '../Editor/PromptResult'; -import { SelectSet } from '../Editor/SelectSet'; -import { CADFile } from '../DatabaseServices/CADFile'; -import { Curve } from 'three'; import { MoveMatrix } from '../Geometry/GeUtils'; -import { RenderType } from '../GraphicsSystem/Enum'; export class Command_Copy implements Command { - async exec(ss: SelectSet) + async exec() { - if (ss.SelectEntityList.length === 0) - { - let ssRes = await app.m_Editor.GetSelection({ Msg: "请选择需要拷贝的实体:" }); - if (ssRes.Status != PromptStatus.OK) - return; - - ss = ssRes.SelectSet; - } + let ssRes = await app.m_Editor.GetSelection({ Msg: "请选择需要拷贝的实体:", UseSelect: true }); + if (ssRes.Status != PromptStatus.OK) + return; let ptRes = await app.m_Editor.GetPoint({ Msg: "请选择复制基点:" }); - if (ptRes.Status != PromptStatus.OK) return; + if (ptRes.Status != PromptStatus.OK) + return; - let maps = new Map(); - for (let en of ss.SelectEntityList) - { - let newE = en.Clone() as Entity; - app.m_Database.ModelSpace.Append(newE); - let f = new CADFile(); - newE.WriteFile(f); - maps.set(f, newE); - } + app.m_Editor.m_SelectCtrl.Cancel(); - const UpdateEntity = (p) => - { - let m = MoveMatrix(p.clone().sub(ptRes.Value)) - for (let [f, e] of maps) - { - f.Reset(); - e.ReadFile(f); - e.ApplyMatrix(m); - } - app.m_Editor.UpdateScreen(); - } + let ptBase = ptRes.Value; + let ptLast = ptBase.clone(); - let ptRes2 = await app.m_Editor.GetPoint({ - Msg: "请选择复制终点:", - Callback: UpdateEntity, - BasePoint: ptRes.Value, - AllowDrawRubberBand: true - }); - if (ptRes2.Status != PromptStatus.OK) + let orgEns = ssRes.SelectSet.SelectEntityList; + let jigEns = orgEns.map(e => Jig.Draw(e)); + + while (true) { - for (let [, e] of maps) + let ptRes2 = await app.m_Editor.GetPoint({ + Msg: "请选择复制终点:", + Callback: (p) => + { + let moveM = MoveMatrix(p.clone().sub(ptLast)); + ptLast.copy(p); + jigEns.forEach(e => e.ApplyMatrix(moveM)); + }, + BasePoint: ptRes.Value, + AllowDrawRubberBand: true + }); + + if (ptRes2.Status === PromptStatus.OK) { - e.Erase(); - e.GoodBye(); + let moveM = MoveMatrix(ptRes2.Value.sub(ptBase)); + for (let e of orgEns) + app.m_Database.ModelSpace.Append(e.Clone().ApplyMatrix(moveM)); } + else + break; } - else - UpdateEntity(ptRes2.Value); + + Jig.End(); } } diff --git a/src/Add-on/DrawArc.ts b/src/Add-on/DrawArc.ts index a5a763d10..857a8c88b 100644 --- a/src/Add-on/DrawArc.ts +++ b/src/Add-on/DrawArc.ts @@ -1,6 +1,7 @@ import { app } from '../ApplicationServices/Application'; import { Arc } from '../DatabaseServices/Arc'; import { Command } from '../Editor/CommandMachine'; +import { Jig } from '../Editor/Jig'; import { PromptStatus } from '../Editor/PromptResult'; import { equalv3 } from '../Geometry/GeUtils'; @@ -20,13 +21,8 @@ export class DrawArc implements Command let arc = new Arc(); arc.ApplyMatrix(app.m_Editor.UCSMatrix); - app.m_Editor.AddNoSnapEntity(arc); - const updateArc = (p) => { - if (!arc.Id) - app.m_Database.ModelSpace.Append(arc); - if (!equalv3(p, pt2) && !equalv3(p, pt2)) { arc.FromThreePoint(pt1, pt2, p); @@ -34,14 +30,17 @@ export class DrawArc implements Command } } + Jig.Draw(arc); let ptRes3 = await app.m_Editor.GetPoint({ Msg: "请输入第三个点:", Callback: updateArc }); - if (ptRes3.Status != PromptStatus.OK) - arc.Erase(); - else + if (ptRes3.Status === PromptStatus.OK) + { updateArc(ptRes3.Value); + app.m_Database.ModelSpace.Append(arc); + } + Jig.End(); } } diff --git a/src/Add-on/DrawLine.ts b/src/Add-on/DrawLine.ts index b837c63c9..40f4fd969 100644 --- a/src/Add-on/DrawLine.ts +++ b/src/Add-on/DrawLine.ts @@ -7,6 +7,7 @@ import { Line } from '../DatabaseServices/Line'; import { Command } from '../Editor/CommandMachine'; import { PromptStatus } from '../Editor/PromptResult'; import { midPoint } from '../Geometry/GeUtils'; +import { Jig } from '../Editor/Jig'; export class DrawLine implements Command { @@ -180,32 +181,29 @@ export class DrawCircle implements Command cir.ApplyMatrix(app.m_Editor.UCSMatrix); cir.Center = val; - app.m_Database.ModelSpace.Append(cir); - - app.m_Editor.AddNoSnapEntity(cir); - + Jig.Draw(cir); let disRes = await app.m_Editor.GetDistance({ Msg: "指定圆的半径:", BasePoint: val, Callback: (v) => cir.Radius = v, }); if (disRes.Status === PromptStatus.OK) + { cir.Radius = disRes.Value; - else - cir.Erase(); + app.m_Database.ModelSpace.Append(cir); + } + Jig.Destroy(); } async DrawCicleUseTwoPoint() { - let ptRes1 = await app.m_Editor.GetPoint({ - Msg: "指定圆直径的第一个端点:", - }); + let ptRes1 = await app.m_Editor.GetPoint({ Msg: "指定圆直径的第一个端点:" }); if (ptRes1.Status != PromptStatus.OK) return; let cir = new Circle(); - app.m_Database.ModelSpace.Append(cir); - app.m_Editor.AddNoSnapEntity(cir); + + Jig.Draw(cir); let ptRes2 = await app.m_Editor.GetPoint({ Msg: "指定圆直径的第二个端点:", @@ -221,23 +219,19 @@ export class DrawCircle implements Command { cir.Radius = ptRes2.Value.distanceTo(ptRes1.Value) / 2; cir.Center = midPoint(ptRes2.Value, ptRes1.Value); + app.m_Database.ModelSpace.Append(cir); } - else - cir.Erase(); + Jig.Destroy(); } async DrawCicleUseThreePoint() { - let ptRes1 = await app.m_Editor.GetPoint({ - Msg: "指定圆上第一个点:" - }); + let ptRes1 = await app.m_Editor.GetPoint({ Msg: "指定圆上第一个点:" }); if (ptRes1.Status != PromptStatus.OK) return; let cir = new Circle(); let ar = new Arc(); - app.m_Database.ModelSpace.Append(cir); - let ptRes2 = await app.m_Editor.GetPoint({ Msg: "指定圆上第二个点:", BasePoint: ptRes1.Value, @@ -246,7 +240,8 @@ export class DrawCircle implements Command if (ptRes2.Status != PromptStatus.OK) return; - app.m_Editor.AddNoSnapEntity(cir); + Jig.Draw(cir); + let ptRes3 = await app.m_Editor.GetPoint({ Msg: "指定圆上第三个点:", BasePoint: ptRes2.Value, @@ -263,9 +258,10 @@ export class DrawCircle implements Command ar.FromThreePoint(ptRes1.Value, ptRes2.Value, ptRes3.Value); cir.Radius = ar.Radius; cir.Center = ar.Center; + app.m_Database.ModelSpace.Append(cir); } - else - cir.Erase(); + + Jig.Destroy(); } async DrawCicleUseCutoffPointAndRadious() { @@ -280,9 +276,6 @@ export class DrawCircle implements Command // let ptRes2 = await app.m_Editor.GetPoint({ // Msg: "指定对象与圆的第二个切点:", // }); - - - } } diff --git a/src/Add-on/DrawPolyline.ts b/src/Add-on/DrawPolyline.ts index b531e55cb..0e61b3225 100644 --- a/src/Add-on/DrawPolyline.ts +++ b/src/Add-on/DrawPolyline.ts @@ -1,11 +1,10 @@ -import { Matrix4, Vector3, Vector2 } from 'three'; +import { Vector2, Vector3 } from 'three'; import { app } from '../ApplicationServices/Application'; -import { Vec2DTo3D, Vec3DTo2D, getCirAngleByChordAndTangent } from '../Common/CurveUtils'; -import { Polyline, PolylineProps } from '../DatabaseServices/Polyline'; -import { Command } from '../Editor/CommandMachine'; -import { PromptStatus, PromptSsgetResult } from '../Editor/PromptResult'; -import { rotatePoint } from '../Geometry/GeUtils'; +import { getCirAngleByChordAndTangent, Vec2DTo3D, Vec3DTo2D } from '../Common/CurveUtils'; import { GetPointPrompt } from '../Common/InputState'; +import { Polyline } from '../DatabaseServices/Polyline'; +import { PromptStatus } from '../Editor/PromptResult'; +import { Jig } from '../Editor/Jig'; enum PolylineModel { @@ -23,10 +22,11 @@ export class DrawPolyline let pl = new Polyline(); pl.ApplyMatrix(app.m_Editor.UCSMatrix); app.m_Database.ModelSpace.Append(pl); - app.m_Editor.AddNoSnapEntity(pl); + + let plJig = Jig.Draw(pl); let Callback = (p: Vector3) => - this.UpdatePoint(pl, p); + this.UpdatePoint(plJig, p) let firstOps: GetPointPrompt = { Msg: "请输入第一个点:", Callback }; let keywords = [{ msg: "圆弧", key: "A" }, { msg: "直线", key: "L" }, { msg: "放弃", key: "U" }]; @@ -36,26 +36,31 @@ export class DrawPolyline while (true) { let ops: GetPointPrompt; - if (pl.NumberOfVertices === 0) + if (plJig.NumberOfVertices === 0) ops = firstOps; else { ops = nextOps; - ops.BasePoint = pl.EndPoint; - if (pl.NumberOfVertices >= 3 || (pl.NumberOfVertices === 2 && this.model === PolylineModel.Arc)) + ops.BasePoint = plJig.EndPoint; + if (plJig.NumberOfVertices >= 3 || (plJig.NumberOfVertices === 2 && this.model === PolylineModel.Arc)) nextOps.KeyWordList = keywords2; else nextOps.KeyWordList = keywords; } - pl.AddVertexAt(pl.NumberOfVertices, new Vector2()); + plJig.AddVertexAt(plJig.NumberOfVertices, new Vector2()); let p = await app.m_Editor.GetPoint(ops); if (p.Status === PromptStatus.OK) + { + this.UpdatePoint(plJig, p.Value); + + pl.AddVertexAt(pl.NumberOfVertices, new Vector2()); this.UpdatePoint(pl, p.Value); + } else if (p.Status === PromptStatus.Keyword) { - this.RemoveLastVertex(pl); + this.RemoveLastVertex(plJig); if (p.StringResult === "A") { this.model = PolylineModel.Arc; @@ -63,15 +68,16 @@ export class DrawPolyline else if (p.StringResult === "L") { this.model = PolylineModel.Line; - if (pl.NumberOfVertices > 0) - pl.SetBulgeAt(pl.NumberOfVertices - 1, 0); + if (plJig.NumberOfVertices > 0) + plJig.SetBulgeAt(plJig.NumberOfVertices - 1, 0); } else if (p.StringResult === "U") { + this.RemoveLastVertex(plJig); this.RemoveLastVertex(pl); - if (pl.NumberOfVertices > 0) + if (plJig.NumberOfVertices > 0) { - this.model = pl.GetBuilgeAt(pl.NumberOfVertices - 1) !== 0 ? + this.model = plJig.GetBuilgeAt(plJig.NumberOfVertices - 1) !== 0 ? PolylineModel.Arc : PolylineModel.Line; } } @@ -88,13 +94,14 @@ export class DrawPolyline } } else - { - this.RemoveLastVertex(pl); break; - } } + Jig.End(); if (pl.NumberOfVertices < 2) - pl.Erase(); + { + app.m_Database.ModelSpace.Remove(pl); + return true; + } } UpdatePoint(pl: Polyline, pt: Vector3) diff --git a/src/Add-on/DrawRec.ts b/src/Add-on/DrawRec.ts index c0ea20d4c..524e63872 100644 --- a/src/Add-on/DrawRec.ts +++ b/src/Add-on/DrawRec.ts @@ -5,6 +5,7 @@ import { Vec3DTo2D } from '../Common/CurveUtils'; import { Polyline } from '../DatabaseServices/Polyline'; import { Command } from '../Editor/CommandMachine'; import { PromptStatus } from '../Editor/PromptResult'; +import { Jig } from '../Editor/Jig'; export class DrawRect implements Command { async exec() @@ -14,15 +15,13 @@ export class DrawRect implements Command return; let p1: THREE.Vector3; - let p2: THREE.Vector3; p1 = ptRes.Value; let rec = new Polyline(); rec.CloseMark = true; rec.ApplyMatrix(app.m_Editor.UCSMatrix); - app.m_Database.ModelSpace.Append(rec); - app.m_Editor.AddNoSnapEntity(rec); + Jig.Draw(rec); let box = new Box3(); let updateRect = (p1, p2) => @@ -45,9 +44,12 @@ export class DrawRect implements Command Callback: (p) => updateRect(p, p1) }); - if (ptRes.Status == PromptStatus.OK) + if (ptRes.Status === PromptStatus.OK) + { updateRect(ptRes.Value, p1); - else - rec.Erase(); + app.m_Database.ModelSpace.Append(rec); + } + + Jig.End(); } } diff --git a/src/Add-on/Move.ts b/src/Add-on/Move.ts index b540e1543..4b482aff7 100644 --- a/src/Add-on/Move.ts +++ b/src/Add-on/Move.ts @@ -3,6 +3,7 @@ import { app } from '../ApplicationServices/Application'; import { Command } from '../Editor/CommandMachine'; import { PromptStatus } from '../Editor/PromptResult'; import { MoveMatrix } from '../Geometry/GeUtils'; +import { Jig } from '../Editor/Jig'; export class Command_Move implements Command { @@ -13,47 +14,32 @@ export class Command_Move implements Command let ptRes = await app.m_Editor.GetPoint({ Msg: "请点击移动基点:" }); if (ptRes.Status != PromptStatus.OK) - { return; } + return; let ens = ssRes.SelectSet.SelectEntityList; - let ptBase = ptRes.Value; + let ensClone = ens.map(e => Jig.Draw(e)); - let pt1 = ptBase; + let ptBase = ptRes.Value; + let ptLast = ptBase.clone(); ptRes = await app.m_Editor.GetPoint( { Msg: "请点击移动终点:", Callback: (p: THREE.Vector3) => { - let moveVec = p.clone().sub(pt1); - let moveMatrix = MoveMatrix(moveVec); - ens.forEach(e => - { - e.ApplyMatrix(moveMatrix); - }) - pt1 = p.clone(); + let moveMatrix = MoveMatrix(p.clone().sub(ptLast)); + ensClone.forEach(e => e.ApplyMatrix(moveMatrix)); + ptLast.copy(p); }, - BasePoint: pt1, + BasePoint: ptBase, AllowDrawRubberBand: true }); - //还原到原来的位置 - let moveV = ptBase.clone().sub(pt1); - let moveM = MoveMatrix(moveV); - - ens.forEach(e => - { - e.ApplyMatrix(moveM); - }) - + Jig.End(); if (ptRes.Status === PromptStatus.OK) { - moveV = ptRes.Value.clone().sub(ptBase); - moveM = MoveMatrix(moveV); - ens.forEach(e => - { - e.ApplyMatrix(moveM); - }) + let moveM = MoveMatrix(ptRes.Value.clone().sub(ptBase)); + ens.forEach(e => e.ApplyMatrix(moveM)); } } } diff --git a/src/Add-on/Offset.ts b/src/Add-on/Offset.ts index 6fb5fe304..8005f4660 100644 --- a/src/Add-on/Offset.ts +++ b/src/Add-on/Offset.ts @@ -3,86 +3,69 @@ import { GetPointAtCurveDir } from '../Common/CurveUtils'; import { Curve } from '../DatabaseServices/Curve'; import { Command } from '../Editor/CommandMachine'; import { PromptStatus } from '../Editor/PromptResult'; +import { Vector3 } from '../../node_modules/@types/three'; +import { Jig } from '../Editor/Jig'; export class Command_Offset implements Command { offsetDis: number = 1; async exec() { - let dis = await app.m_Editor.GetDistance({ + let disRes = await app.m_Editor.GetDistance({ Msg: "指定偏移距离:", KeyWordList: [{ msg: "通过", key: "T" }], Default: this.offsetDis }); - if (dis.Status != PromptStatus.OK) return; - this.offsetDis = dis.Value; + + let dyn = false; + if (disRes.Status === PromptStatus.Keyword && disRes.StringResult === "T") + dyn = true; + else if (disRes.Status != PromptStatus.OK) + return; + else + this.offsetDis = disRes.Value; while (true) { - let enRes = await app.m_Editor.GetEntity({ - Msg: "选择要偏移的对象:" - }); + let enRes = await app.m_Editor.GetEntity({ Msg: "选择要偏移的对象:" }); if (enRes.Status === PromptStatus.Cancel) break; else if (enRes.Status !== PromptStatus.OK) continue; - let pt = await app.m_Editor.GetPoint({ - Msg: "指定要偏移的那一侧的点" - }); - - let cu = enRes.Entity; + let cu = enRes.Entity as Curve; if (cu instanceof Curve) { - let dir = GetPointAtCurveDir(cu, pt.Value) ? 1 : -1 - let offCurs = cu.GetOffsetCurves(this.offsetDis * dir); - offCurs.forEach((offCur) => - { - app.m_Database.ModelSpace.Append(offCur); - }) - app.m_Viewer.m_bNeedUpdate = true; - } - } - } -} - - -export class Command_TestOffset implements Command -{ - async exec() - { - //禁用捕捉服务 - app.m_Editor.m_GetpointServices.snapServices.m_Disabled = true; - while (true) - { - let enRes = await app.m_Editor.GetEntity({ - Msg: "选择要偏移的对象:" - }); - if (enRes.Status != PromptStatus.OK) - { - //结束偏移后打开点捕捉 - app.m_Editor.m_GetpointServices.snapServices.m_Disabled = false; - break; - } - let cu = enRes.Entity as Curve; - - let lastpls: Curve[]; + let ptRes = await app.m_Editor.GetPoint({ + Msg: "指定要偏移的那一侧的点", + Callback: dyn ? (p: Vector3) => + { + Jig.Destroy(); + let dir = GetPointAtCurveDir(cu, p) ? 1 : -1 + cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir) + .forEach(c => Jig.Draw(c)); + } : undefined + }); - await app.m_Editor.GetPoint({ - Msg: "指定要偏移的那一侧的点", - Callback: (p) => + Jig.End(); + if (ptRes.Status === PromptStatus.OK) { - if (lastpls) lastpls.forEach(cu => cu.GoodBye()); - let dir = GetPointAtCurveDir(cu, p) ? 1 : -1 - lastpls = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir); - - lastpls.forEach((offCur) => + let p = ptRes.Value; + let dir = GetPointAtCurveDir(cu, p) ? 1 : -1; + let offCus: Curve[]; + if (dyn) + offCus = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir); + else + offCus = cu.GetOffsetCurves(this.offsetDis * dir); + offCus.forEach((offCur) => { app.m_Database.ModelSpace.Append(offCur); }) app.m_Viewer.m_bNeedUpdate = true; } - }); + else + return; + } } } } diff --git a/src/Add-on/Stretch.ts b/src/Add-on/Stretch.ts index 4b0149955..a3f2ce328 100644 --- a/src/Add-on/Stretch.ts +++ b/src/Add-on/Stretch.ts @@ -1,8 +1,8 @@ import * as THREE from 'three'; import { app } from '../ApplicationServices/Application'; -import { CADFile } from '../DatabaseServices/CADFile'; import { Entity } from '../DatabaseServices/Entity'; import { Command } from '../Editor/CommandMachine'; +import { Jig } from '../Editor/Jig'; import { PromptStatus } from '../Editor/PromptResult'; import { SelectBox } from '../Editor/SelectBox'; import { SelectPick } from '../Editor/SelectPick'; @@ -13,12 +13,11 @@ import { MoveMatrix } from '../Geometry/GeUtils'; interface StretchData { moveEntityList: Entity[];//被移动的图元(所有点都被选中) - stretchEntityMap: Map>; //被拉伸的图元,对照被拉伸的点索引. + stretchEntityMap: { Ent: Entity, Indexs: Array }[]; //被拉伸的图元,对照被拉伸的点索引. } export class Stretch implements Command { - m_CacheEntity: Map = new Map(); async exec() { let ssRes = await app.m_Editor.GetSelection({ UseSelect: true, Msg: "请选择拉伸对象:" }); @@ -28,43 +27,52 @@ export class Stretch implements Command let p1 = await app.m_Editor.GetPoint({ Msg: "指定基点:" });//, KeyWordList: [{ msg: "位移", key: "D" }] if (p1.Status != PromptStatus.OK) return; let data = this.parse(ss); - for (let [e] of data.stretchEntityMap) - app.m_Editor.AddNoSnapEntity(e); + let dataClone: StretchData = + { + moveEntityList: data.moveEntityList.map(e => Jig.Draw(e)), + stretchEntityMap: data.stretchEntityMap.map(v => + { + return { + Ent: Jig.Draw(v.Ent), + Indexs: v.Indexs + } + }) + } let lastP = p1.Value.clone(); let curP = lastP.clone(); let p2 = await app.m_Editor.GetPoint( { BasePoint: p1.Value, + AllowDrawRubberBand: true, Msg: "指定第二个点:",//或 <使用第一个点作为位移> Callback: (p) => { + Jig.Restore(); let v = p.clone().sub(lastP); - this.s(data, v); + this.s(dataClone, v); curP.copy(p); } }); if (p2.Status === PromptStatus.OK) this.s(data, p2.Value.sub(lastP)); - else - { - data.moveEntityList.forEach(e => this.RestoreEntity(e)); - data.stretchEntityMap.forEach((v, k) => this.RestoreEntity(k)); - } - - app.m_Editor.ClearSnapEntity(); - app.m_Editor.m_SelectCtrl.Cancel(); - if (p1.Status != PromptStatus.OK) return; - this.m_CacheEntity.clear(); + Jig.End(); } + /** + * 解析拉伸范围,得到哪些实体的哪些点被拉伸,或者哪些实体需要被移动. + * + * @param {SelectSet} ss + * @returns {StretchData} + * @memberof Stretch + */ parse(ss: SelectSet): StretchData { let data: StretchData = { - stretchEntityMap: new Map>(), + stretchEntityMap: [], moveEntityList: [] }; for (let set of ss.SelectSetList) @@ -89,8 +97,7 @@ export class Stretch implements Command let en = obj.userData; if (en && en instanceof Entity) { - this.CacheEntity(en); - data.stretchEntityMap.set(en, indexArr); + data.stretchEntityMap.push({ Ent: en, Indexs: indexArr }); let pts = en.GetStretchPoints(); for (let i = pts.length; i--;) { @@ -106,10 +113,6 @@ export class Stretch implements Command } } } - - for (let e of data.moveEntityList) - this.CacheEntity(e); - return data; } s(d: StretchData, vec: THREE.Vector3) @@ -117,26 +120,11 @@ export class Stretch implements Command let moveMat = MoveMatrix(vec); for (let e of d.moveEntityList) { - this.RestoreEntity(e); e.ApplyMatrix(moveMat); } - for (let [e, arr] of d.stretchEntityMap) + for (let { Ent, Indexs } of d.stretchEntityMap) { - this.RestoreEntity(e); - e.MoveStretchPoints(arr, vec); + Ent.MoveStretchPoints(Indexs, vec); } } - - CacheEntity(e: Entity) - { - let f = new CADFile(); - e.WriteFile(f); - this.m_CacheEntity.set(e, f); - } - RestoreEntity(e: Entity) - { - let f = this.m_CacheEntity.get(e); - f.Reset(); - e.ReadFile(f); - } } diff --git a/src/Common/ColorPalette.ts b/src/Common/ColorPalette.ts index dbfbd1fc5..f2f066203 100644 --- a/src/Common/ColorPalette.ts +++ b/src/Common/ColorPalette.ts @@ -14,7 +14,7 @@ const ColorPalette = [ // [255, 0, 0, 255], //----- 8 - More red Red // [255, 0, 0, 255], //----- 9 - More red Red [255, 255, 255, 255],//----- 7 - White - [255, 255, 255, 255],//----- 8 + [128, 128, 128, 255],//----- 8 [255, 255, 255, 255],//----- 9 [255, 0, 0, 255], //----- 10 [255, 127, 127, 255],//----- 11 diff --git a/src/Common/Dispose.ts b/src/Common/Dispose.ts new file mode 100644 index 000000000..99666f225 --- /dev/null +++ b/src/Common/Dispose.ts @@ -0,0 +1,11 @@ +import { Object3D } from "three"; + + +export function DisposeThreeObj(m: Object3D) +{ + //@ts-ignores + if (m.geometry) + //@ts-ignore + m.geometry.dispose(); + m.children.forEach(o => DisposeThreeObj(o)); +} diff --git a/src/DatabaseServices/CADObject.ts b/src/DatabaseServices/CADObject.ts index 5b668ebf4..4b3bc7dea 100644 --- a/src/DatabaseServices/CADObject.ts +++ b/src/DatabaseServices/CADObject.ts @@ -73,10 +73,11 @@ export abstract class CADObject { let ver = file.Read(); //write Id; - this.objectId = this.ReadObjectId(file); - if (this.objectId) + let id = this.ReadObjectId(file); + if (!this.objectId && id)//避免CopyFrom时错误的修改自身Id { - this.objectId.Object = this; + this.objectId = id; + id.Object = this; } this._isErase = file.Read(); } @@ -121,14 +122,16 @@ export abstract class CADObject newObject._db = undefined; return newObject; } - // //从一个实体拷贝数据,实体类型必须相同. - // CopyFrom(obj: CADObject) - // { - // this.WriteAllObjectRecord(); - // let f = new CADFile(); - // obj.WriteFile(f); - // this.ReadFile(f); - // } + //从一个实体拷贝数据,实体类型必须相同. + CopyFrom(obj: CADObject) + { + let id = this.objectId; + this.WriteAllObjectRecord(); + let f = new CADFile(); + obj.WriteFile(f); + this.ReadFile(f); + this.objectId = id; + } //-------------------------File End------------------------- diff --git a/src/DatabaseServices/Curve.ts b/src/DatabaseServices/Curve.ts index 925ea1374..96bbd1e07 100644 --- a/src/DatabaseServices/Curve.ts +++ b/src/DatabaseServices/Curve.ts @@ -1,12 +1,12 @@ import { Line, Object3D, Shape, Vector3 } from 'three'; import { arrayRemoveDuplicateBySort, arraySortByNumber } from '../Common/ArrayExt'; import { ColorMaterial } from '../Common/ColorPalette'; -import { equalv3, equaln } from '../Geometry/GeUtils'; +import { Status } from '../Common/Status'; +import { equaln, equalv3 } from '../Geometry/GeUtils'; import { RenderType } from '../GraphicsSystem/Enum'; import { IntersectOption } from '../GraphicsSystem/IntersectWith'; import { Factory } from './CADFactory'; import { Entity } from './Entity'; -import { Status } from '../Common/Status'; export enum ExtendType { @@ -161,4 +161,13 @@ export abstract class Curve extends Entity let m = en as Line; m.material = ColorMaterial.GetLineMaterial(this.m_Color); } + + UpdateJigMaterial() + { + for (let [type, en] of this.m_DrawEntity) + { + let l = en as Line; + l.material = ColorMaterial.GetLineMaterial(8); + } + } } diff --git a/src/DatabaseServices/Entity.ts b/src/DatabaseServices/Entity.ts index 68a0fc1f7..bc35368bd 100644 --- a/src/DatabaseServices/Entity.ts +++ b/src/DatabaseServices/Entity.ts @@ -7,6 +7,7 @@ import { Factory } from './CADFactory'; import { CADFile } from './CADFile'; import { CADObject } from './CADObject'; import { ObjectId } from './ObjectId'; +import { DisposeThreeObj } from '../Common/Dispose'; /** * Entity 是所有图元的基类,绘制的实体都集成该类. @@ -201,30 +202,33 @@ export class Entity extends CADObject } + /** + * 当实体需要被拽拖时,需要材质更新 + * + * @memberof Entity + */ + UpdateJigMaterial() + { + } + RestoreJigMaterial() + { + for (let [type, en] of this.m_DrawEntity) + this.UpdateDrawObjectMaterial(type, en); + } + UpdateVisible() { for (let [, en] of this.m_DrawEntity) - { en.visible = !this._isErase; - } } GoodBye() { for (let [, obj] of this.m_DrawEntity) { - - let geo = obj['Geometry'] - if (geo && geo instanceof THREE.Geometry) - { - geo.dispose(); - } + DisposeThreeObj(obj); if (obj.parent) - { obj.parent.remove(obj); - } - else - console.warn("重复加入数据库导致的错误!"); } } Erase(isErase: boolean = true) @@ -303,11 +307,11 @@ export class Entity extends CADObject this.Update(); } - // CopyFrom(obj: CADObject) - // { - // super.CopyFrom(obj); - // this.Update(); - // } + CopyFrom(obj: CADObject) + { + super.CopyFrom(obj); + this.Update(); + } //#endregion } diff --git a/src/DatabaseServices/Polyline.ts b/src/DatabaseServices/Polyline.ts index 433a2b4c8..a2083e585 100644 --- a/src/DatabaseServices/Polyline.ts +++ b/src/DatabaseServices/Polyline.ts @@ -156,6 +156,7 @@ export class Polyline extends Curve } set StartPoint(v: Vector3) { + this.WriteAllObjectRecord(); this.SetPointAt(0, Vec3DTo2D(v)); let bul = this.GetBuilgeAt(0) if (bul !== 0) @@ -175,7 +176,11 @@ export class Polyline extends Curve } set EndPoint(v: Vector3) { + this.WriteAllObjectRecord(); this.SetPointAt(this.EndParam, Vec3DTo2D(v)); + if (this.EndParam === 0) + return; + let bul = this.GetBuilgeAt(this.EndParam - 1) if (bul !== 0) { @@ -894,11 +899,21 @@ export class Polyline extends Curve } UpdateDrawObject(type: RenderType, en: Object3D) { - let plObj = en as THREE.Line; - let geo = new Geometry(); let shape = this.Shape; - geo.setFromPoints(shape.getPoints(50)); - updateGeometry(plObj, geo); + let pts = shape.getPoints(30); + let plObj = en as THREE.Line; + let geo = plObj.geometry as Geometry; + if (pts.length === geo.vertices.length) + { + geo.setFromPoints(pts); + geo.verticesNeedUpdate = true; + } + else + { + geo = new Geometry(); + geo.setFromPoints(shape.getPoints(50)); + updateGeometry(plObj, geo); + } } GetSnapPoints(): Array diff --git a/src/Editor/CommandMachine.ts b/src/Editor/CommandMachine.ts index 78eb69a46..1385ebc36 100644 --- a/src/Editor/CommandMachine.ts +++ b/src/Editor/CommandMachine.ts @@ -1,7 +1,7 @@ import { app } from '../ApplicationServices/Application'; export interface Command { - exec: Function; + exec: Function;//函数可以返回true,实现放弃命令的任何操作. } //命令状态机. @@ -26,20 +26,21 @@ export class CommandMachine app.m_Database.hm.StartCmd(cmdName); } app.m_Editor.m_SelectCtrl.RestState(); - let ss = app.m_Editor.m_SelectCtrl.SelectSet; //命令执行... this.m_CommandIng = true; app.m_Editor.m_CommandStore.isCmdIng = true; + + let abort: boolean = true; try { - await this.m_CommandList.get(cmdName).exec(ss); + abort = await this.m_CommandList.get(cmdName).exec(); } catch (error) { app.m_Editor.m_CommandStore.Prompt("抱歉,命令造成了错误,请联系开发人员."); console.error(error); } - this.CommandEnd(cmdName); + this.CommandEnd(cmdName, abort); } else { @@ -53,10 +54,12 @@ export class CommandMachine this.m_CommandList.set(cmdName, cmd); this.m_CommandNameList.add(cmdName); } - CommandEnd(cmdName: string) + CommandEnd(cmdName: string, abort: boolean = false) { this.m_CommandIng = false; app.m_Database.hm.EndCmd(); + if (abort) + app.m_Database.hm.Undo(); app.m_Editor.m_CommandStore.isCmdIng = false; app.m_Viewer.m_GripScene.UpdateAll(); app.m_Editor.ClearSnapEntity(); diff --git a/src/Editor/Jig.ts b/src/Editor/Jig.ts new file mode 100644 index 000000000..d1596a5a5 --- /dev/null +++ b/src/Editor/Jig.ts @@ -0,0 +1,102 @@ +import { app } from "../ApplicationServices/Application"; +import { Entity } from "../DatabaseServices/Entity"; +import { RenderType } from "../GraphicsSystem/Enum"; +import { CADFile } from "../DatabaseServices/CADFile"; + +/** + * 动态拽拖的静态类,控制动态拽拖的状态. + * + * # Example: + * //1.开始拽拖:-> + * //得到临时对象,如果en是已经存在的对象,那么将会被临时修改材质 + * let jigEnt = Jig.Draw(en); + * //2.拽拖中:-> ....拽拖代码.更新jigEnt,你可以临时调用Jig.Destroy(); + * //3.结束拽拖: + * Jig.End(); + * @export + * @class Jig + */ +export class Jig +{ + //临时图形,如果需要,将被销毁. + private static m_JigEnts: Entity[] = []; + //图纸数据缓存,用于还原 + private static m_EntityCacheData: { Ent: Entity, File: CADFile }[] = []; + private static m_OrgEntitys: Entity[] = []; + + static End() + { + this.Destroy(); + this.RestoreOriginEntity(); + } + + /** + * 还原源对象的材质 + * + * @static + * @memberof Jig + */ + static RestoreOriginEntity() + { + this.m_OrgEntitys.forEach(e => e.RestoreJigMaterial()); + this.m_EntityCacheData.length = 0; + } + + /** + * 将在视图中绘制该对象. + * 如果该对象已经存在图纸:那么将被拷贝,并且暂时暗显示,并且缓存原始数据,以便还原. + * @static + * @param {Entity} enOrg 源实体 + * @memberof Jig + */ + static Draw(enOrg: T): T + { + let enNew: T; + if (enOrg.Id) + { + enNew = enOrg.Clone(); + this.m_OrgEntitys.push(enOrg); + enOrg.UpdateJigMaterial(); + + let f = new CADFile(); + enNew.WriteFile(f); + this.m_EntityCacheData.push({ Ent: enNew, File: f }); + } + else + enNew = enOrg; + + this.m_JigEnts.push(enNew); + let obj = enNew.Draw(RenderType.Wireframe); + app.m_Viewer.Scene.add(obj); + return enNew; + } + + /** + * 还原拽拖的实体到初始化状态. + * @static + * @memberof Jig + */ + static Restore() + { + this.m_EntityCacheData.forEach((v) => + { + v.File.Reset(); + v.Ent.ReadFile(v.File); + }) + } + + /** + * 销毁临时对象,如果临时对象被加入到图纸,那么将不会被销毁. + * @static + * @memberof Jig + */ + static Destroy() + { + this.m_JigEnts.forEach(e => + { + if (!e.Id) + e.GoodBye(); + }); + this.m_JigEnts.length = 0; + } +} diff --git a/src/Editor/SnapDragServices.ts b/src/Editor/SnapDragServices.ts index 3e9b077c1..0490f7027 100644 --- a/src/Editor/SnapDragServices.ts +++ b/src/Editor/SnapDragServices.ts @@ -3,12 +3,12 @@ import { Vector3 } from 'three'; import { end } from 'xaop'; import { app } from '../ApplicationServices/Application'; import { MouseKey } from '../Common/KeyEnum'; -import { CADFile } from '../DatabaseServices/CADFile'; import { Entity } from '../DatabaseServices/Entity'; import { MoveMatrix } from '../Geometry/GeUtils'; import { InputState } from './../Common/InputState'; import { commandMachine } from './CommandMachine'; import { Editor, EditorService } from './Editor'; +import { Jig } from './Jig'; import { MouseControls } from './MouseControls'; import { PromptStatus } from './PromptResult'; @@ -69,38 +69,19 @@ export class SnapDragServices implements EditorService app.m_Viewer.WorldToScreen(ptV); if (ptV.distanceToSquared(this.mouseCtrl.m_CurMousePointVCS) < 100) - { arr.push(i); - } } if (arr.length > 0) - { snapIndexMap.push({ ent: en, indexArr: arr }); - app.m_Editor.AddNoSnapEntity(en); - } } } - app.m_Viewer.m_GripScene.visible = false; - - let restData = snapIndexMap.map(v => + let snapIndexMapClone = snapIndexMap.map(v => { - let f = new CADFile(); - v.ent.WriteFile(f); - return { Entity: v.ent, File: f }; - }) - - const Reset = () => - { - restData.forEach((v) => - { - v.File.Reset(); - v.Entity.ReadFile(v.File); - }) - } - - const DragTo = (p: Vector3) => + return { ent: Jig.Draw(v.ent), indexArr: v.indexArr }; + }); + const DragTo = (p: Vector3, snapIndexMap = snapIndexMapClone) => { - Reset(); + Jig.Restore(); for (let data of snapIndexMap) { let entDrawP = data.ent.GetSnapPoints()[data.indexArr[0]]; @@ -117,19 +98,14 @@ export class SnapDragServices implements EditorService }); if (ptRes.Status === PromptStatus.OK) - { - DragTo(ptRes.Value); - } - else - { - Reset(); - } + DragTo(ptRes.Value, snapIndexMap); + + Jig.End(); this.UpdateLastPoint(); this.UpdatePreLine(); commandMachine.CommandEnd("drag"); - app.m_Viewer.m_GripScene.visible = true; return true; } diff --git a/src/Editor/SnapServices.ts b/src/Editor/SnapServices.ts index 5284e0f93..2b9224a42 100644 --- a/src/Editor/SnapServices.ts +++ b/src/Editor/SnapServices.ts @@ -153,6 +153,7 @@ export class SnapServices { if (this.notSnapEntity.has(obj.userData)) continue; if (obj.userData.IsErase) continue; + if (!obj.userData.Id) continue; for (let p of obj.userData.GetSnapPoints()) { let pv = p.clone(); diff --git a/src/GraphicsSystem/Viewer.ts b/src/GraphicsSystem/Viewer.ts index b9adb3fce..a76a7cec6 100644 --- a/src/GraphicsSystem/Viewer.ts +++ b/src/GraphicsSystem/Viewer.ts @@ -97,6 +97,7 @@ export class Viewer canvasContainer.appendChild(this.m_Render.domElement); this.m_Render.autoClear = true; + this.m_Render.sortObjects = false; //如果设置,那么它希望所有的纹理和颜色都是预乘的伽玛。默认值为false。 // this.m_Render.gammaInput = true; From aa5c1831c5075fe4a3c7449e3c4bb0e7c8ef19a8 Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 24 Jul 2018 18:02:31 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/Copy.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Add-on/Copy.ts b/src/Add-on/Copy.ts index c92dd9d4b..af29b2f5c 100644 --- a/src/Add-on/Copy.ts +++ b/src/Add-on/Copy.ts @@ -16,8 +16,6 @@ export class Command_Copy implements Command if (ptRes.Status != PromptStatus.OK) return; - app.m_Editor.m_SelectCtrl.Cancel(); - let ptBase = ptRes.Value; let ptLast = ptBase.clone(); From 930eb64338af3e865cb0e76d031c3a94cf1424ad Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 25 Jul 2018 08:59:12 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=A4=9A=E6=AE=B5?= =?UTF-8?q?=E7=BA=BF=E6=94=AF=E6=8C=81=E7=A9=BA=E6=A0=BC=E9=80=80=E5=87=BA?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/DrawPolyline.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Add-on/DrawPolyline.ts b/src/Add-on/DrawPolyline.ts index 0e61b3225..eb686291b 100644 --- a/src/Add-on/DrawPolyline.ts +++ b/src/Add-on/DrawPolyline.ts @@ -28,10 +28,10 @@ export class DrawPolyline let Callback = (p: Vector3) => this.UpdatePoint(plJig, p) - let firstOps: GetPointPrompt = { Msg: "请输入第一个点:", Callback }; + let firstOps: GetPointPrompt = { Msg: "请输入第一个点:", Callback, AllowNone: true }; let keywords = [{ msg: "圆弧", key: "A" }, { msg: "直线", key: "L" }, { msg: "放弃", key: "U" }]; let keywords2 = keywords.concat([{ msg: "闭合", key: "C" }]); - let nextOps: GetPointPrompt = { Msg: "请点击下一个点或", Callback }; + let nextOps: GetPointPrompt = { Msg: "请点击下一个点或", Callback, AllowNone: true }; while (true) {