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