Browse Source

- improved performance

kamadaKawai
Alex de Mulder 9 years ago
parent
commit
93f1480af3
2 changed files with 18 additions and 11 deletions
  1. +9
    -5
      dist/vis.js
  2. +9
    -6
      lib/network/modules/PhysicsEngine.js

+ 9
- 5
dist/vis.js View File

@ -33019,6 +33019,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.previousStates = {};
this.referenceState = {};
this.adaptiveTimestep = true;
this.adaptiveTimestepEnabled = false;
this.adaptiveCounter = 0;
this.adaptiveInterval = 2;
this.freezeCache = {};
@ -33297,11 +33298,11 @@ return /******/ (function(modules) { // webpackBootstrap
value: function physicsTick() {
if (this.stabilized === false) {
// adaptivity means the timestep adapts to the situation, only applicable for stabilization
if (this.adaptiveTimestep === true) {
if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) {
this.adaptiveCounter += 1;
var factor = 1.2;
if (this.adaptiveCounter % this.adaptiveInterval === 0) {
// we leave the timestep stable for "interval" iterations.
//console.log(this.timestep)
// first the big step and revert. Revert saves the reference state.
this.timestep = 2 * this.timestep;
this.calculateForces();
@ -33319,18 +33320,18 @@ return /******/ (function(modules) { // webpackBootstrap
// we compare the two steps. if it is acceptable we double the step.
if (this.compare() === true) {
this.timestep = 1.1 * this.timestep;
this.timestep = factor * this.timestep;
} else {
// if not, we half the step to a minimum of the options timestep.
// if the half the timestep is smaller than the options step, we do not reset the counter
// we assume that the options timestep is stable enough.
if (0.9 * this.timestep < this.options.timestep) {
if (this.timestep / factor < this.options.timestep) {
this.timestep = this.options.timestep;
} else {
// if the timestep was larger than 2 times the option one we check the adaptivity again to ensure
// that large instabilities do not form.
this.adaptiveCounter = -1; // check again next iteration
this.timestep = 0.9 * this.timestep;
this.timestep = Math.max(this.options.timestep, this.timestep / factor);
}
}
} else {
@ -33478,6 +33479,7 @@ return /******/ (function(modules) { // webpackBootstrap
var nodeIndices = this.physicsBody.physicsNodeIndices;
var maxVelocity = this.options.maxVelocity ? this.options.maxVelocity : 1e9;
var maxNodeVelocity = 0;
var velocityAdaptiveThreshold = 5;
for (var i = 0; i < nodeIndices.length; i++) {
var nodeId = nodeIndices[i];
@ -33487,6 +33489,8 @@ return /******/ (function(modules) { // webpackBootstrap
nodesPresent = true;
}
this.adaptiveTimestepEnabled = maxNodeVelocity < velocityAdaptiveThreshold;
this.stabilized = maxNodeVelocity <= this.options.minVelocity;
}

+ 9
- 6
lib/network/modules/PhysicsEngine.js View File

@ -21,6 +21,7 @@ class PhysicsEngine {
this.previousStates = {};
this.referenceState = {};
this.adaptiveTimestep = true;
this.adaptiveTimestepEnabled = false;
this.adaptiveCounter = 0;
this.adaptiveInterval = 2;
this.freezeCache = {};
@ -279,10 +280,10 @@ class PhysicsEngine {
physicsTick() {
if (this.stabilized === false) {
// adaptivity means the timestep adapts to the situation, only applicable for stabilization
if (this.adaptiveTimestep === true) {
if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) {
this.adaptiveCounter += 1;
let factor = 1.2;
if (this.adaptiveCounter % this.adaptiveInterval === 0) { // we leave the timestep stable for "interval" iterations.
//console.log(this.timestep)
// first the big step and revert. Revert saves the reference state.
this.timestep = 2 * this.timestep;
this.calculateForces();
@ -300,20 +301,20 @@ class PhysicsEngine {
// we compare the two steps. if it is acceptable we double the step.
if (this.compare() === true) {
this.timestep = 1.1 * this.timestep;
this.timestep = factor * this.timestep;
}
else {
// if not, we half the step to a minimum of the options timestep.
// if the half the timestep is smaller than the options step, we do not reset the counter
// we assume that the options timestep is stable enough.
if (0.9 * this.timestep < this.options.timestep) {
if (this.timestep/factor < this.options.timestep) {
this.timestep = this.options.timestep;
}
else {
// if the timestep was larger than 2 times the option one we check the adaptivity again to ensure
// that large instabilities do not form.
this.adaptiveCounter = -1; // check again next iteration
this.timestep = 0.9 * this.timestep;
this.timestep = Math.max(this.options.timestep, this.timestep/factor);
}
}
}
@ -456,7 +457,7 @@ class PhysicsEngine {
var nodeIndices = this.physicsBody.physicsNodeIndices;
var maxVelocity = this.options.maxVelocity ? this.options.maxVelocity : 1e9;
var maxNodeVelocity = 0;
var velocityAdaptiveThreshold = 5;
for (let i = 0; i < nodeIndices.length; i++) {
let nodeId = nodeIndices[i];
@ -466,6 +467,8 @@ class PhysicsEngine {
nodesPresent = true;
}
this.adaptiveTimestepEnabled = maxNodeVelocity < velocityAdaptiveThreshold;
this.stabilized = maxNodeVelocity <= this.options.minVelocity;
}

Loading…
Cancel
Save