|
|
|
@ -120,10 +120,10 @@ export default abstract class BaseInteraction { |
|
|
|
this.viewerDom = this.viewport.viewerDom |
|
|
|
this.canvas = this.viewport.renderer.domElement |
|
|
|
if (option.startPoint) { |
|
|
|
this.linkStartPointId = option.startPoint.userData?.entityId |
|
|
|
if (!this.linkStartPointId) { |
|
|
|
this.linkStartPointObject = this.viewport.entityManager.findObjectsById(this.linkStartPointId)?.[0] |
|
|
|
} |
|
|
|
this.linkStartPointId = option.startPoint |
|
|
|
} |
|
|
|
if (this.linkStartPointId) { |
|
|
|
this.linkStartPointObject = this.viewport.entityManager.findObjectsById(this.linkStartPointId)?.[0] |
|
|
|
} |
|
|
|
|
|
|
|
pdFn = this.mousedown.bind(this) |
|
|
|
@ -264,47 +264,76 @@ export default abstract class BaseInteraction { |
|
|
|
} |
|
|
|
this.lastClickTime = now |
|
|
|
|
|
|
|
const renderer = getRenderer(this.itemTypeName) |
|
|
|
const from = this.viewport.stateManager.findItemById(this.linkStartPointId) |
|
|
|
if (!from) { |
|
|
|
system.showErrorDialog(`Cannot find state item: ${this.linkStartPointId}`) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 如果正式的点命中到同类型的节点上,则不添加新的点,只牵线到该点
|
|
|
|
let catchPoint: ItemJson | null = this.viewport.stateManager.findItemByPosition(point, this.itemTypeName) |
|
|
|
|
|
|
|
const defaultScale = renderer.getDefaultScale() |
|
|
|
const defaultRotation = renderer.getDefaultRotation() |
|
|
|
|
|
|
|
// 添加正式点
|
|
|
|
const itemJson = { |
|
|
|
id: system.createUUID(), |
|
|
|
t: this.itemTypeName, |
|
|
|
v: true, |
|
|
|
tf: [ |
|
|
|
[point.x, point.y, point.z], |
|
|
|
[defaultRotation.x, defaultRotation.y, defaultRotation.z], |
|
|
|
[defaultScale.x, defaultScale.y, defaultScale.z] |
|
|
|
], |
|
|
|
dt: { |
|
|
|
in: [] as string[], |
|
|
|
out: [] as string[], |
|
|
|
center: [] as string[] |
|
|
|
if (catchPoint) { |
|
|
|
// 连线到目标点
|
|
|
|
if (this.linkStartPointId === catchPoint.id) { |
|
|
|
// 自己连接自己,忽略
|
|
|
|
system.msg('Cannot link to itself.') |
|
|
|
return |
|
|
|
} |
|
|
|
} as ItemJson |
|
|
|
// 关联2个点
|
|
|
|
|
|
|
|
// 关联2个点
|
|
|
|
const from = this.viewport.entityManager.findItemById(this.linkStartPointId) |
|
|
|
if (this.linkStartPointId && from) { |
|
|
|
itemJson.dt.center.push(this.linkStartPointId) |
|
|
|
from.dt.center.push(itemJson.id) |
|
|
|
} |
|
|
|
if (this.linkStartPointId && from) { |
|
|
|
catchPoint.dt.center.push(this.linkStartPointId) |
|
|
|
from.dt.center.push(catchPoint.id) |
|
|
|
} |
|
|
|
|
|
|
|
// 提交状态管理器
|
|
|
|
const stateManager = this.viewport.stateManager |
|
|
|
stateManager.beginStateUpdate({ createFromInteraction: true }) |
|
|
|
stateManager.vdata.items.push(itemJson) |
|
|
|
stateManager.endStateUpdate() |
|
|
|
// 提交状态管理器
|
|
|
|
const stateManager = this.viewport.stateManager |
|
|
|
stateManager.beginStateUpdate({ createFromInteraction: true }) |
|
|
|
catchPoint.dt.center.push(this.linkStartPointId) |
|
|
|
from.dt.center.push(catchPoint.id) |
|
|
|
stateManager.endStateUpdate() |
|
|
|
|
|
|
|
} else { |
|
|
|
const renderer = getRenderer(this.itemTypeName) |
|
|
|
|
|
|
|
const defaultScale = renderer.getDefaultScale() |
|
|
|
const defaultRotation = renderer.getDefaultRotation() |
|
|
|
|
|
|
|
// 添加正式点
|
|
|
|
catchPoint = { |
|
|
|
id: system.createUUID(), |
|
|
|
t: this.itemTypeName, |
|
|
|
v: true, |
|
|
|
tf: [ |
|
|
|
[point.x, point.y, point.z], |
|
|
|
[defaultRotation.x, defaultRotation.y, defaultRotation.z], |
|
|
|
[defaultScale.x, defaultScale.y, defaultScale.z] |
|
|
|
], |
|
|
|
dt: { |
|
|
|
in: [] as string[], |
|
|
|
out: [] as string[], |
|
|
|
center: [] as string[] |
|
|
|
} |
|
|
|
} as ItemJson |
|
|
|
|
|
|
|
|
|
|
|
// 提交状态管理器
|
|
|
|
const stateManager = this.viewport.stateManager |
|
|
|
stateManager.beginStateUpdate({ createFromInteraction: true }) |
|
|
|
// 关联2个点
|
|
|
|
stateManager.vdata.items.push(catchPoint) |
|
|
|
catchPoint.dt.center.push(this.linkStartPointId) |
|
|
|
from.dt.center.push(catchPoint.id) |
|
|
|
stateManager.endStateUpdate() |
|
|
|
} |
|
|
|
|
|
|
|
// 把点加入拖拽控制器
|
|
|
|
// this.viewport.dragControl.setDragObjects(marker, 'push')
|
|
|
|
|
|
|
|
// 更新起始点为新添加的点
|
|
|
|
this.linkStartPointId = itemJson.id |
|
|
|
this.linkStartPointObject = this.viewport.entityManager.findObjectsById(itemJson.id)?.[0] |
|
|
|
this.linkStartPointId = catchPoint.id |
|
|
|
this.linkStartPointObject = this.viewport.entityManager.findObjectsById(catchPoint.id)?.[0] |
|
|
|
|
|
|
|
// 删除临时点
|
|
|
|
this.tempPointMarker && this.viewport.scene.remove(this.tempPointMarker) |
|
|
|
|