Skip to content

Commit

Permalink
improve dragcontrol
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyangXYZ committed Dec 23, 2023
1 parent 5407ad3 commit 921055a
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/hooks/useDrawTopology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function useDrawTopology(dom: HTMLElement) {
return sprite
}

let drawnNodes: {[name:string]:any} = {}
let drawnNodes: { [name: string]: any } = {}
const drawNodes = () => {
switch (Network.Type) {
case NetworkType.TSCH:
Expand Down Expand Up @@ -596,21 +596,6 @@ export function useDrawTopology(dom: HTMLElement) {
b.mesh.scale.set(scale, scale, scale)
}

// show dragbox helper
if (SignalEditTopology.value) {
for (const node of Object.values(drawnNodes)) {
node.modelGroup.position.copy(node.dragBox.position)
node.dragBoxHelper.update()
if (node.label != undefined) {
node.label.position.set(
node.dragBox.position.x,
node.label.position.y,
node.dragBox.position.z
)
}
}
}

requestAnimationFrame(animate)
TWEEN.update()
controls.update()
Expand Down Expand Up @@ -651,6 +636,7 @@ export function useDrawTopology(dom: HTMLElement) {
dragControls.deactivate()
}
for (const node of Object.values(drawnNodes)) {
node.dragBox.visible = !node.dragBoxHelper.visible
node.dragBoxHelper.visible = !node.dragBoxHelper.visible
}
})
Expand Down Expand Up @@ -714,8 +700,10 @@ export function useDrawTopology(dom: HTMLElement) {
controls.enabled = true
})
dragControls.addEventListener('drag', function (event) {
// snap to ground
event.object.position.y = 0
if (event.object.userData.type == 'TSCH') {

if (NODE_TYPE[event.object.userData.type] != undefined) {
Network.Nodes.value[event.object.userData.node_id].pos = [
event.object.position.x,
event.object.position.z
Expand All @@ -729,10 +717,23 @@ export function useDrawTopology(dom: HTMLElement) {
clearPacket(pkt.uid)
drawUnicastPacket(pkt)
}
if (relatedBeaconPacket!=undefined) {
if (relatedBeaconPacket != undefined) {
clearPacket(relatedBeaconPacket.uid)
drawBeaconPacket(relatedBeaconPacket)
}
}

// update dragbox and model
for (const node of Object.values(drawnNodes)) {
node.modelGroup.position.copy(node.dragBox.position)
node.dragBoxHelper.update()
if (node.label != undefined) {
node.label.position.set(
node.dragBox.position.x,
node.label.position.y,
node.dragBox.position.z
)
}
}
})
}

0 comments on commit 921055a

Please sign in to comment.