diff --git a/src/Add-on/DrawLine.ts b/src/Add-on/DrawLine.ts index 7a23039dd..6eb8ebcb1 100644 --- a/src/Add-on/DrawLine.ts +++ b/src/Add-on/DrawLine.ts @@ -25,7 +25,7 @@ export class DrawLine implements Command while (true) { app.m_Editor.m_CommandStore.Prompt("请输入点2:"); - ptRes = await app.m_Editor.GetPoint({ BasePoint: p1 }); + ptRes = await app.m_Editor.GetPoint({ BasePoint: p1, AllowDrawRubberBand: true }); if (ptRes.Status != PromptStatus.OK) { return; diff --git a/src/ApplicationServices/Application.ts b/src/ApplicationServices/Application.ts index e0215b97f..b16fccfac 100644 --- a/src/ApplicationServices/Application.ts +++ b/src/ApplicationServices/Application.ts @@ -8,7 +8,6 @@ import { DatGUI } from '../Editor/DebugDatUi'; import { Editor } from '../Editor/Editor'; import { SelectSetBase } from '../Editor/SelectSet'; import { SnapDrag } from '../Editor/SnapDrag'; -import { CursorViewer } from '../GraphicsSystem/CursorViewer'; import { SnapServices } from '../GraphicsSystem/SnapServices'; import { Viewer } from '../GraphicsSystem/Viewer'; import { layoutOnsizeEvent } from '../UI/Layout/LayoutOnSizeEventManage'; @@ -28,7 +27,6 @@ export class ApplicationService gui: DatGUI; m_Database: Database; m_Viewer: Viewer; - m_CursorViewer: CursorViewer; m_Editor: Editor; constructor() { @@ -41,12 +39,9 @@ export class ApplicationService //渲染器 this.m_Viewer = new Viewer(container); - this.m_CursorViewer = new CursorViewer(container); - // layoutOnsizeEvent.register("Webgl", () => { this.m_Viewer.onSize(); - this.m_CursorViewer.onSize(); }) this.m_Viewer.renderDatabase(this.m_Database); @@ -58,11 +53,6 @@ export class ApplicationService this.m_Editor = new Editor(this); - xaop.end(this.m_Editor.m_MouseCtrl, this.m_Editor.m_MouseCtrl.onMouseMove, () => - { - this.m_CursorViewer.SerCursorPostion(this.m_Editor.m_MouseCtrl.m_CurMousePointVCS); - }) - let regGripEvent = () => { let selectSet = this.m_Editor.m_SelectCtrl.SelectSet; diff --git a/src/Common/InputState.ts b/src/Common/InputState.ts index 095201cac..1a88a68a1 100644 --- a/src/Common/InputState.ts +++ b/src/Common/InputState.ts @@ -12,4 +12,5 @@ export interface GetPointPrompt Msg?: string BasePoint?: Vector3 Callback?: (pt: THREE.Vector3) => void + AllowDrawRubberBand?: Boolean; } \ No newline at end of file diff --git a/src/Editor/Editor.ts b/src/Editor/Editor.ts index 435dce203..247f7e8bd 100644 --- a/src/Editor/Editor.ts +++ b/src/Editor/Editor.ts @@ -33,12 +33,17 @@ export class Editor this.m_KeyCtrl = new KeyBoardControls(); this.m_SelectCtrl = new SelectControls(app.m_Viewer, this) this.m_CommandStore = new CommandStore(this); + + xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () => + { + app.m_Viewer.m_PreViewer.SerCursorPostion(this.m_MouseCtrl.m_CurMousePointVCS); + }) } GetPoint(prompt?: GetPointPrompt): Promise { prompt = prompt ? prompt : {}; - this.m_App.m_CursorViewer.ToGetpoint(); + this.m_App.m_Viewer.m_PreViewer.ToGetpoint(); this.m_InputState = InputState.GetPoint; let retValue = new PromptPointResult(); @@ -50,25 +55,36 @@ export class Editor return new Promise((resolve, reject) => { //如果有基点,那么绘制直线 - if (prompt.BasePoint) + if (prompt.BasePoint && prompt.AllowDrawRubberBand) { - let line = new Line(prompt.BasePoint, prompt.BasePoint); - - this.m_App.m_Database.appendEntity(line); + let preView = this.m_App.m_Viewer.m_PreViewer; - let drawObj = line.Draw(RenderType.Wireframe); + let startP = prompt.BasePoint.clone(); + this.m_App.m_Viewer.WorldToScreen(startP); + preView.ScreenPointToViewerPoint(startP); - this.noSnapList.add(drawObj); + let line = preView.DrawLine(startP, startP, preView.m_DashMaterial); + let geo = line.geometry as THREE.Geometry; + geo.computeLineDistances(); + preView.Scene.add(line); removeCalls.push( () => { - this.m_App.m_Database.removeEntityId(line.objectId); + preView.Scene.remove(line); }, xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () => { - let p = this.GetNowPoint(prompt.BasePoint); - line.setEndPoint(p); + let endP = this.GetNowPoint(prompt.BasePoint); + this.m_App.m_Viewer.WorldToScreen(endP); + preView.ScreenPointToViewerPoint(endP); + + geo.vertices[1] = endP; + geo.computeLineDistances(); + geo.lineDistancesNeedUpdate = true; + geo.verticesNeedUpdate = true; + + preView.render(); this.UpdateScreen(); }) ); @@ -117,7 +133,7 @@ export class Editor //返回 let _return = () => { - this.m_App.m_CursorViewer.ToSelect(); + this.m_App.m_Viewer.m_PreViewer.ToSelect(); this.m_InputState = InputState.None; this.noSnapList.clear(); @@ -145,9 +161,9 @@ export class Editor */ private GetNowPoint(basePoint?: THREE.Vector3): THREE.Vector3 { - if (this.m_App.m_CursorViewer.m_LastSnapPoint) + if (this.m_App.m_Viewer.m_PreViewer.m_LastSnapPoint) { - let retP = app.m_CursorViewer.ptWcs; + let retP = app.m_Viewer.m_PreViewer.ptWcs; app.m_Viewer.ScreenToWorld(retP); return retP; } @@ -203,14 +219,14 @@ export class Editor if (ptC.distanceToSquared(this.m_MouseCtrl.m_CurMousePointVCS) < 100) { - app.m_CursorViewer.m_LastSnapPoint = ptC; + app.m_Viewer.m_PreViewer.m_LastSnapPoint = ptC; - app.m_CursorViewer.m_LastEntity = obj; - app.m_CursorViewer.m_LastIndex = i; + app.m_Viewer.m_PreViewer.m_LastEntity = obj; + app.m_Viewer.m_PreViewer.m_LastIndex = i; - app.m_CursorViewer.SerCursorPostion(ptC); + app.m_Viewer.m_PreViewer.SerCursorPostion(ptC); - app.m_CursorViewer.render(); + app.m_Viewer.m_PreViewer.render(); return; } } diff --git a/src/Editor/SelectControls.ts b/src/Editor/SelectControls.ts index 0161db443..31a856c32 100644 --- a/src/Editor/SelectControls.ts +++ b/src/Editor/SelectControls.ts @@ -105,10 +105,10 @@ export class SelectControls if (ptC.distanceToSquared(mouseCtrl.m_CurMousePointVCS) < 100) { - app.m_CursorViewer.m_LastSnapPoint = ptC; + app.m_Viewer.m_PreViewer.m_LastSnapPoint = ptC; - app.m_CursorViewer.m_LastEntity = pts.userData; - app.m_CursorViewer.m_LastIndex = i; + app.m_Viewer.m_PreViewer.m_LastEntity = pts.userData; + app.m_Viewer.m_PreViewer.m_LastIndex = i; return; } @@ -133,14 +133,14 @@ export class SelectControls app.m_Editor.m_CommandStore.Prompt("拽拖开始:"); - let en = app.m_CursorViewer.m_LastEntity as THREE.Mesh; + let en = app.m_Viewer.m_PreViewer.m_LastEntity as THREE.Mesh; app.m_Editor.noSnapList.add(en); let geo = en.geometry as THREE.Geometry; - let movePoint = geo.vertices[app.m_CursorViewer.m_LastIndex]; + let movePoint = geo.vertices[app.m_Viewer.m_PreViewer.m_LastIndex]; - let lastP = app.m_CursorViewer.m_LastSnapPoint.clone(); + let lastP = app.m_Viewer.m_PreViewer.m_LastSnapPoint.clone(); app.m_Viewer.ScreenToWorld(lastP); let pt = await app.m_Editor.GetPoint({ Msg: "指定下一个点:", @@ -169,7 +169,7 @@ export class SelectControls { if (e.button === MouseKey.Left) { - if (app.m_Viewer.m_GripScene.children.length > 0 && app.m_CursorViewer.m_LastSnapPoint && app.m_Editor.m_InputState == 0 && !this.m_SelectIng) + if (app.m_Viewer.m_GripScene.children.length > 0 && app.m_Viewer.m_PreViewer.m_LastSnapPoint && app.m_Editor.m_InputState == 0 && !this.m_SelectIng) { this.GridDrag(); return; @@ -201,14 +201,14 @@ export class SelectControls this.m_SelectIng = !this.m_SelectIng; if (this.m_SelectIng) { - app.m_CursorViewer.ToGetpoint(); + app.m_Viewer.m_PreViewer.ToGetpoint(); this.m_SelectCss.SetStart(pt.x, pt.y) this.m_SelectCss.SetEnd(pt.x, pt.y) this.m_SelectCss.Show(); } else { - app.m_CursorViewer.ToSelect(); + app.m_Viewer.m_PreViewer.ToSelect(); let selectBox = new SelectBox(this.m_Viewer, this.m_SelectCss.start, this.m_SelectCss.end); selectBox.m_SelectType = this.m_SelectCss.end.x > this.m_SelectCss.start.x ? SelectType.W : SelectType.C; @@ -247,13 +247,13 @@ export class SelectControls } cancel() { - app.m_CursorViewer.ToSelect(); + app.m_Viewer.m_PreViewer.ToSelect(); this.m_SelectSet = new SelectSet(); this.m_SelectCss.Hide(); this.m_SelectIng = false; - app.m_CursorViewer.ShowCursor(); + app.m_Viewer.m_PreViewer.ShowCursor(); this.removeSnap(); } diff --git a/src/GraphicsSystem/CursorViewer.ts b/src/GraphicsSystem/PreViewer.ts similarity index 94% rename from src/GraphicsSystem/CursorViewer.ts rename to src/GraphicsSystem/PreViewer.ts index f17e6de77..3390e6b8a 100644 --- a/src/GraphicsSystem/CursorViewer.ts +++ b/src/GraphicsSystem/PreViewer.ts @@ -2,7 +2,7 @@ import * as THREE from 'three'; import { CameraControl } from './CameraControl'; -export class CursorViewer +export class PreViewer { //渲染器 private m_Render: THREE.WebGLRenderer; @@ -13,6 +13,12 @@ export class CursorViewer //线材质 private m_LineMaterial: THREE.LineBasicMaterial = new THREE.LineBasicMaterial({ color: 0xffffff }); private m_SnapMaterial: THREE.LineBasicMaterial = new THREE.LineBasicMaterial({ color: 0x008B00 }); + m_DashMaterial = new THREE.LineDashedMaterial({ + color: 0x008B00, + dashSize: 30, + gapSize: 15, + }); + //光标对象 private m_CursorObject: THREE.Group; private m_SnapObject: THREE.Group; @@ -39,7 +45,6 @@ export class CursorViewer this.Scene.add(this.m_SnapObject); this.InitCursor(8, 1800); - this.onSize(); } get Scene() { return this.m_Scene; } @@ -150,7 +155,7 @@ export class CursorViewer } } - DrawLine(p1: THREE.Vector3, p2: THREE.Vector3, material?: THREE.LineBasicMaterial): THREE.Line + DrawLine(p1: THREE.Vector3, p2: THREE.Vector3, material?: THREE.LineBasicMaterial | THREE.LineDashedMaterial): THREE.Line { material = material ? material : this.m_LineMaterial; let geometry = new THREE.Geometry(); @@ -196,18 +201,10 @@ export class CursorViewer p.y = this.m_Height * 0.5 - p.y; } - onSize() + onSize(width: number, height: number) { - this.m_Width = this.m_DomEl.scrollWidth; - this.m_Height = this.m_DomEl.scrollHeight; - if (this.m_Width % 2 == 1) - { - this.m_Width -= 1; - } - if (this.m_Height % 2 == 1) - { - this.m_Height -= 1; - } + this.m_Width = width; + this.m_Height = height; this.m_Camera.SetSize(this.m_Width, this.m_Height); this.m_Camera.ViewHeight = this.m_Height; diff --git a/src/GraphicsSystem/Viewer.ts b/src/GraphicsSystem/Viewer.ts index e1ff0f21d..06d060402 100644 --- a/src/GraphicsSystem/Viewer.ts +++ b/src/GraphicsSystem/Viewer.ts @@ -8,6 +8,7 @@ import { PlaneExt } from '../Geometry/Plane'; import { CameraControl } from './CameraControl'; import { RenderType } from './Enum'; import { GripScene } from './GripScene'; +import { PreViewer } from './PreViewer'; //导入其他js模块 require("three-CopyShader"); @@ -31,6 +32,8 @@ export class Viewer //渲染器//暂时只用这个类型 m_Render: THREE.WebGLRenderer; + //前置渲染 + m_PreViewer: PreViewer; m_bUsePass = true; m_RenderPass: THREE.RenderPass; @@ -51,6 +54,7 @@ export class Viewer this.m_DomEl = canvasContainer; this.m_GripScene = new GripScene(this.m_Scene); + this.m_PreViewer = new PreViewer(canvasContainer); this.initRender(canvasContainer); this.StartRender(); @@ -124,6 +128,7 @@ export class Viewer if (this._Height % 2 == 1) this._Height -= 1; + this.m_PreViewer.onSize(this._Width, this._Height); this.m_Render.setSize(this.Width, this.Height); this.m_Composer.setSize(this.Width, this.Height); this.m_Camera.SetSize(this.Width, this.Height); diff --git a/webpack.config.js b/webpack.config.js index 8d0cff874..ae63fd055 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -103,7 +103,7 @@ module.exports = { devServer: { contentBase: path.join(__dirname, "dist"), port: 7777, - hot: true + hot: false }, plugins: [ new HtmlWebPackPlugin(