|
@ -117,7 +117,13 @@ class PhysicsEngine { |
|
|
}); |
|
|
}); |
|
|
// For identifying which nodes to send to worker thread
|
|
|
// For identifying which nodes to send to worker thread
|
|
|
this.body.emitter.on('dragStart', (properties) => {this.draggingNodes = properties.nodes;}); |
|
|
this.body.emitter.on('dragStart', (properties) => {this.draggingNodes = properties.nodes;}); |
|
|
this.body.emitter.on('dragEnd', () => {this.draggingNodes = [];}); |
|
|
|
|
|
|
|
|
this.body.emitter.on('dragEnd', () => { |
|
|
|
|
|
// need one last update to handle the case where a drag happens
|
|
|
|
|
|
// and the user holds the node clicked at the final position
|
|
|
|
|
|
// for a time prior to releasing
|
|
|
|
|
|
this.updateWorkerPositions(); |
|
|
|
|
|
this.draggingNodes = []; |
|
|
|
|
|
}); |
|
|
this.body.emitter.on('destroy', () => { |
|
|
this.body.emitter.on('destroy', () => { |
|
|
if (this.physicsWorker) { |
|
|
if (this.physicsWorker) { |
|
|
this.physicsWorker.terminate(); |
|
|
this.physicsWorker.terminate(); |
|
@ -244,8 +250,7 @@ class PhysicsEngine { |
|
|
case 'positions': |
|
|
case 'positions': |
|
|
this.stabilized = msg.data.stabilized; |
|
|
this.stabilized = msg.data.stabilized; |
|
|
var positions = msg.data.positions; |
|
|
var positions = msg.data.positions; |
|
|
// console.log('received positions', positions);
|
|
|
|
|
|
for (let i = 0; i < this.draggingNodes; i++) { |
|
|
|
|
|
|
|
|
for (let i = 0; i < this.draggingNodes.length; i++) { |
|
|
delete positions[this.draggingNodes[i]]; |
|
|
delete positions[this.draggingNodes[i]]; |
|
|
} |
|
|
} |
|
|
let nodeIds = Object.keys(positions); |
|
|
let nodeIds = Object.keys(positions); |
|
@ -290,20 +295,7 @@ class PhysicsEngine { |
|
|
*/ |
|
|
*/ |
|
|
startSimulation() { |
|
|
startSimulation() { |
|
|
if (this.physicsEnabled === true && this.options.enabled === true) { |
|
|
if (this.physicsEnabled === true && this.options.enabled === true) { |
|
|
if (this.physicsWorker) { |
|
|
|
|
|
for(let i = 0; i < this.draggingNodes.length; i++) { |
|
|
|
|
|
let nodeId = this.draggingNodes[i]; |
|
|
|
|
|
let node = this.body.nodes[nodeId]; |
|
|
|
|
|
this.physicsWorker.postMessage({ |
|
|
|
|
|
type: 'update', |
|
|
|
|
|
data: { |
|
|
|
|
|
id: nodeId, |
|
|
|
|
|
x: node.x, |
|
|
|
|
|
y: node.y |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.updateWorkerPositions(); |
|
|
this.stabilized = false; |
|
|
this.stabilized = false; |
|
|
|
|
|
|
|
|
// when visible, adaptivity is disabled.
|
|
|
// when visible, adaptivity is disabled.
|
|
@ -577,6 +569,22 @@ class PhysicsEngine { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updateWorkerPositions() { |
|
|
|
|
|
if (this.physicsWorker) { |
|
|
|
|
|
for(let i = 0; i < this.draggingNodes.length; i++) { |
|
|
|
|
|
let nodeId = this.draggingNodes[i]; |
|
|
|
|
|
let node = this.body.nodes[nodeId]; |
|
|
|
|
|
this.physicsWorker.postMessage({ |
|
|
|
|
|
type: 'update', |
|
|
|
|
|
data: { |
|
|
|
|
|
id: nodeId, |
|
|
|
|
|
x: node.x, |
|
|
|
|
|
y: node.y |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Revert the simulation one step. This is done so after stabilization, every new start of the simulation will also say stabilized. |
|
|
* Revert the simulation one step. This is done so after stabilization, every new start of the simulation will also say stabilized. |
|
|