From 4cbe244e8a4e31c98b2aac8777fcfda05ddc46b9 Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Sat, 30 Nov 2019 20:48:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E6=B5=8B=E9=87=8F=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/editor/tools/DistanceTool.js | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/ShadowEditor.Web/src/editor/tools/DistanceTool.js b/ShadowEditor.Web/src/editor/tools/DistanceTool.js index 5e09c59c..68d05f23 100644 --- a/ShadowEditor.Web/src/editor/tools/DistanceTool.js +++ b/ShadowEditor.Web/src/editor/tools/DistanceTool.js @@ -9,16 +9,23 @@ class DistanceTool extends BaseTool { this.running = false; this.onMouseDown = this.onMouseDown.bind(this); - this.onMouseUp = this.onMouseUp.bind(this); this.onDblClick = this.onDblClick.bind(this); this.onGpuPick = this.onGpuPick.bind(this); } start() { + if (!this.init) { + this.init = true; + this.positions = []; + this.lines = []; + this.world = new THREE.Vector3(); + } + + this.positions.length = 0; + app.require('line').then(() => { app.on(`mousedown.${this.id}`, this.onMouseDown); - app.on(`mouseup.${this.id}`, this.onMouseUp); app.on(`gpuPick.${this.id}`, this.onGpuPick); app.on(`dblclick.${this.id}`, this.onDblClick); }); @@ -26,27 +33,40 @@ class DistanceTool extends BaseTool { stop() { app.on(`mousedown.${this.id}`, null); - app.on(`mouseup.${this.id}`, null); app.on(`gpuPick.${this.id}`, null); app.on(`dblclick.${this.id}`, null); - } - onMouseDown(event) { - if (!this.running) { - this.running = true; + delete this.line; + + while (this.lines.length) { + let line = this.lines[0]; + app.editor.sceneHelpers.remove(line); } + this.lines.length = 0; } - onMouseUp(event) { - + onMouseDown() { + if (!this.line) { + let geometry = new THREE.LineGeometry(); + let material = new THREE.LineMaterial({ color: Math.random() * 0xffffff }); + this.line = new THREE.Line2(geometry, material); + this.lines.push(this.line); + app.editor.sceneHelpers.add(this.line); + } + this.positions.push(this.world.x, this.world.y, this.world.z); + this.line.geometry.setPositions(this.positions); } onGpuPick(obj) { - + if (!obj.point) { + return; + } + this.world.copy(obj.point); } - onDblClick(event) { - + onDblClick() { + this.call(`end`, this); + delete this.line; } }