From a5bd6b2d558645b0f070a626b6a8566e37749e30 Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 3 May 2017 21:10:14 +0100 Subject: [PATCH] change constraint solve order --- src/constraint/Constraint.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/constraint/Constraint.js b/src/constraint/Constraint.js index 68d75ae..61de118 100644 --- a/src/constraint/Constraint.js +++ b/src/constraint/Constraint.js @@ -103,9 +103,27 @@ var Common = require('../core/Common'); * @param {number} timeScale */ Constraint.solveAll = function(constraints, timeScale) { - for (var i = 0; i < constraints.length; i++) { + // Solve fixed constraints first. + for (var i = 0; i < constraints.length; i += 1) { + var constraint = constraints[i], + fixedA = !constraint.bodyA || (constraint.bodyA && constraint.bodyA.isStatic), + fixedB = !constraint.bodyB || (constraint.bodyB && constraint.bodyB.isStatic); + + if (fixedA || fixedB) { + Constraint.solve(constraints[i], timeScale); + } + } + + // Solve free constraints last. + for (i = 0; i < constraints.length; i += 1) { + constraint = constraints[i]; + fixedA = !constraint.bodyA || (constraint.bodyA && constraint.bodyA.isStatic); + fixedB = !constraint.bodyB || (constraint.bodyB && constraint.bodyB.isStatic); + + if (!fixedA && !fixedB) { Constraint.solve(constraints[i], timeScale); } + } }; /**