|
|
|
@ -1,6 +1,8 @@ |
|
|
|
import * as THREE from 'three' |
|
|
|
import Toolbox from '@/model/itemType/Toolbox.ts' |
|
|
|
import type ItemTypeLine from '@/model/itemType/ItemTypeLine.ts' |
|
|
|
import { findObject3DById } from '@/model/ModelUtils.ts' |
|
|
|
import EventBus from '@/runtime/EventBus' |
|
|
|
|
|
|
|
/** |
|
|
|
* 线条工具箱 |
|
|
|
@ -22,6 +24,9 @@ export default class ToolboxLine extends Toolbox { |
|
|
|
afterMoveTemplateLine(line: THREE.Mesh, startPoint: THREE.Object3D, endPoint: THREE.Object3D) { |
|
|
|
} |
|
|
|
|
|
|
|
afterDeleteLine(line: THREE.Object3D, point: THREE.Object3D, relationPointIds: string[]) { |
|
|
|
} |
|
|
|
|
|
|
|
stop() { |
|
|
|
super.stop() |
|
|
|
|
|
|
|
@ -35,6 +40,57 @@ export default class ToolboxLine extends Toolbox { |
|
|
|
this.itemType.createLine(this.viewport, this.viewport.scene, this.startPoint, point) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除点 |
|
|
|
*/ |
|
|
|
deletePoint(point: THREE.Object3D) { |
|
|
|
const relationPointIds = [] |
|
|
|
|
|
|
|
const deletedPoints = _.remove(this.itemType.pointArray, (p) => p.uuid === point.uuid) |
|
|
|
if (!deletedPoints || deletedPoints.length !== 1) { |
|
|
|
console.warn('没有找到要删除的点:', point.uuid) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if (this.viewport.state.selectedObject === point) { |
|
|
|
// 如果当前选中的对象是要删除的点,则清除选中状态
|
|
|
|
this.viewport.state.selectedObject = undefined |
|
|
|
EventBus.$emit('objectChanged', { |
|
|
|
viewport: this, |
|
|
|
object: null |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// 找出与这个点相关的其他点
|
|
|
|
this.itemType.pointArray.forEach(p => { |
|
|
|
if (p.userData.center) { |
|
|
|
relationPointIds.push(..._.filter(p.userData.center, i => i === point.uuid)) |
|
|
|
_.remove(p.userData.center, i => i === point.uuid) |
|
|
|
|
|
|
|
relationPointIds.push(..._.filter(p.userData.in, i => i === point.uuid)) |
|
|
|
_.remove(p.userData.in, i => i === point.uuid) |
|
|
|
|
|
|
|
relationPointIds.push(..._.filter(p.userData.out, i => i === point.uuid)) |
|
|
|
_.remove(p.userData.out, i => i === point.uuid) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
// 找出与点相关的所有线
|
|
|
|
_.forEach(point.userData.lines, (line) => { |
|
|
|
const lineObject = findObject3DById(this.viewport.scene, line) |
|
|
|
this.removeFromScene(lineObject) |
|
|
|
this.afterDeleteLine(lineObject, point, relationPointIds) |
|
|
|
}) |
|
|
|
|
|
|
|
// 从场景中删除点
|
|
|
|
this.removeFromScene(point) |
|
|
|
|
|
|
|
// 如果是起始点,则清除起始点
|
|
|
|
if (this.startPoint === point) { |
|
|
|
this.startPoint = undefined |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
mousemove(e: MouseEvent): THREE.Vector3 | undefined { |
|
|
|
const point = super.mousemove(e) |
|
|
|
if (!point) { |
|
|
|
|