|
@ -15,12 +15,6 @@ class PhysicsEngine extends PhysicsBase { |
|
|
this.freezeCache = {}; |
|
|
this.freezeCache = {}; |
|
|
this.renderTimer = undefined; |
|
|
this.renderTimer = undefined; |
|
|
|
|
|
|
|
|
// parameters for the adaptive timestep
|
|
|
|
|
|
this.adaptiveTimestep = false; |
|
|
|
|
|
this.adaptiveTimestepEnabled = false; |
|
|
|
|
|
this.adaptiveCounter = 0; |
|
|
|
|
|
this.adaptiveInterval = 3; |
|
|
|
|
|
|
|
|
|
|
|
this.ready = false; // will be set to true if the stabilize
|
|
|
this.ready = false; // will be set to true if the stabilize
|
|
|
|
|
|
|
|
|
// default options
|
|
|
// default options
|
|
@ -106,7 +100,6 @@ class PhysicsEngine extends PhysicsBase { |
|
|
}); |
|
|
}); |
|
|
this.body.emitter.on('_positionUpdate', (properties) => this.positionUpdateHandler(properties)); |
|
|
this.body.emitter.on('_positionUpdate', (properties) => this.positionUpdateHandler(properties)); |
|
|
this.body.emitter.on('_physicsUpdate', (properties) => this.physicsUpdateHandler(properties)); |
|
|
this.body.emitter.on('_physicsUpdate', (properties) => this.physicsUpdateHandler(properties)); |
|
|
// For identifying which nodes to send to worker thread
|
|
|
|
|
|
this.body.emitter.on('dragStart', (properties) => { |
|
|
this.body.emitter.on('dragStart', (properties) => { |
|
|
this.draggingNodes = properties.nodes; |
|
|
this.draggingNodes = properties.nodes; |
|
|
}); |
|
|
}); |
|
@ -316,6 +309,7 @@ class PhysicsEngine extends PhysicsBase { |
|
|
startSimulation() { |
|
|
startSimulation() { |
|
|
if (this.physicsEnabled === true && this.options.enabled === true) { |
|
|
if (this.physicsEnabled === true && this.options.enabled === true) { |
|
|
this.stabilized = false; |
|
|
this.stabilized = false; |
|
|
|
|
|
this._updateWorkerStabilized(); |
|
|
|
|
|
|
|
|
// when visible, adaptivity is disabled.
|
|
|
// when visible, adaptivity is disabled.
|
|
|
this.adaptiveTimestep = false; |
|
|
this.adaptiveTimestep = false; |
|
@ -339,6 +333,8 @@ class PhysicsEngine extends PhysicsBase { |
|
|
*/ |
|
|
*/ |
|
|
stopSimulation(emit = true) { |
|
|
stopSimulation(emit = true) { |
|
|
this.stabilized = true; |
|
|
this.stabilized = true; |
|
|
|
|
|
this._updateWorkerStabilized(); |
|
|
|
|
|
|
|
|
if (emit === true) { |
|
|
if (emit === true) { |
|
|
this._emitStabilized(); |
|
|
this._emitStabilized(); |
|
|
} |
|
|
} |
|
@ -351,6 +347,14 @@ class PhysicsEngine extends PhysicsBase { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_updateWorkerStabilized() { |
|
|
|
|
|
if (this.physicsWorker) { |
|
|
|
|
|
this.physicsWorker.postMessage({ |
|
|
|
|
|
type: 'setStabilized', |
|
|
|
|
|
data: this.stabilized |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* The viewFunction inserts this step into each renderloop. It calls the physics tick and handles the cleanup at stabilized. |
|
|
* The viewFunction inserts this step into each renderloop. It calls the physics tick and handles the cleanup at stabilized. |
|
@ -555,6 +559,7 @@ class PhysicsEngine extends PhysicsBase { |
|
|
return totalVelocity; |
|
|
return totalVelocity; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO probably want to move freeze/restore to PhysicsBase and do in worker if running
|
|
|
/** |
|
|
/** |
|
|
* When initializing and stabilizing, we can freeze nodes with a predefined position. This greatly speeds up stabilization |
|
|
* When initializing and stabilizing, we can freeze nodes with a predefined position. This greatly speeds up stabilization |
|
|
* because only the supportnodes for the smoothCurves have to settle. |
|
|
* because only the supportnodes for the smoothCurves have to settle. |
|
@ -629,7 +634,7 @@ class PhysicsEngine extends PhysicsBase { |
|
|
|
|
|
|
|
|
if (this.physicsWorker) { |
|
|
if (this.physicsWorker) { |
|
|
this.physicsWorker.postMessage({ |
|
|
this.physicsWorker.postMessage({ |
|
|
type: 'stabilization', |
|
|
|
|
|
|
|
|
type: 'stabilize', |
|
|
data: { |
|
|
data: { |
|
|
targetIterations: iterations |
|
|
targetIterations: iterations |
|
|
} |
|
|
} |
|
|