|
|
|
@ -9,6 +9,9 @@ import { Vector3 } from 'three' |
|
|
|
|
|
|
|
let pdFn, pmFn, puFn, kdFn |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于在 threejs 中创建一系列的 object_for_measure 点,并标记他的距离 |
|
|
|
*/ |
|
|
|
export default class RulerTool implements ITool { |
|
|
|
static OBJ_NAME = 'object_for_measure' |
|
|
|
static LABEL_NAME = 'label_for_measure' |
|
|
|
@ -79,12 +82,6 @@ export default class RulerTool implements ITool { |
|
|
|
// 当次绘制点
|
|
|
|
this.pointArray = [] |
|
|
|
|
|
|
|
// 测量距离、面积和角度需要折线
|
|
|
|
this.polyline = this.createLine() |
|
|
|
this.group.add(this.polyline) |
|
|
|
|
|
|
|
this.viewport.viewerDom.style.cursor = 'crosshair' |
|
|
|
|
|
|
|
system.msg('进入鼠标测距模式') |
|
|
|
} |
|
|
|
|
|
|
|
@ -116,7 +113,6 @@ export default class RulerTool implements ITool { |
|
|
|
this.mouseMoved = false |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 鼠标移动,创建对应的临时点与线
|
|
|
|
mousemove = (e: MouseEvent) => { |
|
|
|
if (this.isCompleted) return |
|
|
|
@ -189,12 +185,11 @@ export default class RulerTool implements ITool { |
|
|
|
|
|
|
|
// 双击触发两次点击事件,我们需要避免这里的第二次点击
|
|
|
|
const now = Date.now() |
|
|
|
if (this.lastClickTime && (now - this.lastClickTime < 100)) return |
|
|
|
if (this.lastClickTime && (now - this.lastClickTime < 10)) return |
|
|
|
|
|
|
|
this.lastClickTime = now |
|
|
|
|
|
|
|
this.pointArray.push(point) |
|
|
|
console.log('pointArray', this.pointArray) |
|
|
|
|
|
|
|
const count = this.pointArray.length |
|
|
|
const marker = this.createPointMarker(point) |
|
|
|
@ -216,6 +211,7 @@ export default class RulerTool implements ITool { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// this.redrawComplete()
|
|
|
|
// this.viewport.dispatchSignal('sceneGraphChanged')
|
|
|
|
} |
|
|
|
|
|
|
|
@ -285,6 +281,7 @@ export default class RulerTool implements ITool { |
|
|
|
addOrUpdateTempLabel(label: string, position: THREE.Vector3) { |
|
|
|
if (!this.tempLabel) { |
|
|
|
this.tempLabel = this.createLabel(label) |
|
|
|
console.log('addOrUpdateTempLabel', label, position) |
|
|
|
this.viewport.scene.add(this.tempLabel) |
|
|
|
} |
|
|
|
this.tempLabel.position.set(position.x, position.y, position.z) |
|
|
|
@ -315,4 +312,48 @@ export default class RulerTool implements ITool { |
|
|
|
} |
|
|
|
return obj |
|
|
|
} |
|
|
|
|
|
|
|
// 重绘完成
|
|
|
|
redrawComplete() { |
|
|
|
if (!this.tempPointMarker) return |
|
|
|
|
|
|
|
const point = this.tempPointMarker.userData.point |
|
|
|
this.pointArray[this.tempPointMarker.userData.pointIndex] = point |
|
|
|
const count = this.pointArray.length |
|
|
|
|
|
|
|
if (this.polyline) { |
|
|
|
this.polyline.geometry.setFromPoints(this.pointArray) |
|
|
|
// 如果是距离测量,则清除group中已有的label,再重新创建
|
|
|
|
if (this.viewport.state.cursorMode === 'Ruler' && count > 1) { |
|
|
|
this.clearCurrentLabel() |
|
|
|
// 绘制label
|
|
|
|
for (let i = 0; i < count - 1; i++) { |
|
|
|
const p0 = this.pointArray[i] |
|
|
|
const p1 = this.pointArray[i + 1] |
|
|
|
if (!p0 || !p1) continue |
|
|
|
const dist = p0.distanceTo(p1) |
|
|
|
const label = `${numberToString(dist)} ${getUnitString(this.viewport.state.cursorMode)}` |
|
|
|
const position = new THREE.Vector3((p0.x + p1.x) / 2, (p0.y + p1.y) / 2, (p0.z + p1.z) / 2) |
|
|
|
const labelObj = this.createLabel(label) |
|
|
|
labelObj.position.set(position.x, position.y, position.z) |
|
|
|
labelObj.element.innerHTML = label |
|
|
|
this.group.add(labelObj) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// this.destory()
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 清除当前group label |
|
|
|
*/ |
|
|
|
clearCurrentLabel() { |
|
|
|
for (let i = this.group.children.length - 1; i >= 0; i--) { |
|
|
|
const c = this.group.children[i] |
|
|
|
if (c.userData.type === 'label') { |
|
|
|
this.group.remove(c) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |