|
|
@ -384,6 +384,7 @@ class PhysicsEngine { |
|
|
|
} |
|
|
|
|
|
|
|
if (this.stabilized === false) { |
|
|
|
this.updateWorkerFixed(); |
|
|
|
// adaptivity means the timestep adapts to the situation, only applicable for stabilization
|
|
|
|
if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) { |
|
|
|
// this is the factor for increasing the timestep on success.
|
|
|
@ -464,15 +465,21 @@ class PhysicsEngine { |
|
|
|
let nodes = this.body.nodes; |
|
|
|
let edges = this.body.edges; |
|
|
|
|
|
|
|
this.physicsBody.forces = {}; |
|
|
|
this.physicsBody.physicsNodeIndices = []; |
|
|
|
this.physicsBody.physicsEdgeIndices = []; |
|
|
|
|
|
|
|
if (this.physicsWorker) { |
|
|
|
var physicsWorkerNodes = {}; |
|
|
|
this.physicsWorkerNodes = {}; |
|
|
|
var physicsWorkerEdges = {}; |
|
|
|
|
|
|
|
for (let nodeId in nodes) { |
|
|
|
if (nodes.hasOwnProperty(nodeId)) { |
|
|
|
let node = nodes[nodeId]; |
|
|
|
if (node.options.physics === true) { |
|
|
|
physicsWorkerNodes[nodeId] = { |
|
|
|
// for updating fixed later
|
|
|
|
this.physicsBody.physicsNodeIndices.push(nodeId); |
|
|
|
this.physicsWorkerNodes[nodeId] = { |
|
|
|
id: node.id, |
|
|
|
x: node.x, |
|
|
|
y: node.y, |
|
|
@ -522,15 +529,11 @@ class PhysicsEngine { |
|
|
|
this.physicsWorker.postMessage({ |
|
|
|
type: 'physicsObjects', |
|
|
|
data: { |
|
|
|
nodes: physicsWorkerNodes, |
|
|
|
nodes: this.physicsWorkerNodes, |
|
|
|
edges: physicsWorkerEdges |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this.physicsBody.forces = {}; |
|
|
|
this.physicsBody.physicsNodeIndices = []; |
|
|
|
this.physicsBody.physicsEdgeIndices = []; |
|
|
|
|
|
|
|
// get node indices for physics
|
|
|
|
for (let nodeId in nodes) { |
|
|
|
if (nodes.hasOwnProperty(nodeId)) { |
|
|
@ -571,11 +574,11 @@ class PhysicsEngine { |
|
|
|
|
|
|
|
updateWorkerPositions() { |
|
|
|
if (this.physicsWorker) { |
|
|
|
for(let i = 0; i < this.draggingNodes.length; i++) { |
|
|
|
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', |
|
|
|
type: 'updatePositions', |
|
|
|
data: { |
|
|
|
id: nodeId, |
|
|
|
x: node.x, |
|
|
@ -586,6 +589,35 @@ class PhysicsEngine { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
updateWorkerFixed() { |
|
|
|
if (this.physicsWorker) { |
|
|
|
for (let i = 0; i < this.physicsBody.physicsNodeIndices.length; i++) { |
|
|
|
let nodeId = this.physicsBody.physicsNodeIndices[i]; |
|
|
|
let physicsNode = this.physicsWorkerNodes[nodeId]; |
|
|
|
let node = this.body.nodes[nodeId]; |
|
|
|
if (physicsNode.options.fixed.x !== node.options.fixed.x || |
|
|
|
physicsNode.options.fixed.y !== node.options.fixed.y) |
|
|
|
{ |
|
|
|
let fixed = { |
|
|
|
x: node.options.fixed.x, |
|
|
|
y: node.options.fixed.y |
|
|
|
}; |
|
|
|
physicsNode.options.fixed.x = fixed.x; |
|
|
|
physicsNode.options.fixed.y = fixed.y; |
|
|
|
this.physicsWorker.postMessage({ |
|
|
|
type: 'updateFixed', |
|
|
|
data: { |
|
|
|
id: nodeId, |
|
|
|
x: node.x, |
|
|
|
y: node.y, |
|
|
|
fixed: fixed |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Revert the simulation one step. This is done so after stabilization, every new start of the simulation will also say stabilized. |
|
|
|
*/ |
|
|
|