|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Cloth Simulation using a relaxed constrains solver
|
|
|
+ * Cloth Simulation using a relaxed constraints solver
|
|
|
*/
|
|
|
|
|
|
// Suggested Readings
|
|
@@ -82,7 +82,7 @@ Particle.prototype.addForce = function( force ) {
|
|
|
};
|
|
|
|
|
|
|
|
|
-// Performs verlet integration
|
|
|
+// Performs Verlet integration
|
|
|
|
|
|
Particle.prototype.integrate = function( timesq ) {
|
|
|
|
|
@@ -101,7 +101,7 @@ Particle.prototype.integrate = function( timesq ) {
|
|
|
|
|
|
var diff = new THREE.Vector3();
|
|
|
|
|
|
-function satisifyConstrains( p1, p2, distance ) {
|
|
|
+function satisifyConstraints( p1, p2, distance ) {
|
|
|
|
|
|
diff.subVectors( p2.position, p1.position );
|
|
|
var currentDist = diff.length();
|
|
@@ -122,7 +122,7 @@ function Cloth( w, h ) {
|
|
|
this.h = h;
|
|
|
|
|
|
var particles = [];
|
|
|
- var constrains = [];
|
|
|
+ var constraints = [];
|
|
|
|
|
|
var u, v;
|
|
|
|
|
@@ -145,13 +145,13 @@ function Cloth( w, h ) {
|
|
|
|
|
|
for ( u = 0; u < w; u ++ ) {
|
|
|
|
|
|
- constrains.push( [
|
|
|
+ constraints.push( [
|
|
|
particles[ index( u, v ) ],
|
|
|
particles[ index( u, v + 1 ) ],
|
|
|
restDistance
|
|
|
] );
|
|
|
|
|
|
- constrains.push( [
|
|
|
+ constraints.push( [
|
|
|
particles[ index( u, v ) ],
|
|
|
particles[ index( u + 1, v ) ],
|
|
|
restDistance
|
|
@@ -163,7 +163,7 @@ function Cloth( w, h ) {
|
|
|
|
|
|
for ( u = w, v = 0; v < h; v ++ ) {
|
|
|
|
|
|
- constrains.push( [
|
|
|
+ constraints.push( [
|
|
|
particles[ index( u, v ) ],
|
|
|
particles[ index( u, v + 1 ) ],
|
|
|
restDistance
|
|
@@ -174,7 +174,7 @@ function Cloth( w, h ) {
|
|
|
|
|
|
for ( v = h, u = 0; u < w; u ++ ) {
|
|
|
|
|
|
- constrains.push( [
|
|
|
+ constraints.push( [
|
|
|
particles[ index( u, v ) ],
|
|
|
particles[ index( u + 1, v ) ],
|
|
|
restDistance
|
|
@@ -183,8 +183,8 @@ function Cloth( w, h ) {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // While many system uses shear and bend springs,
|
|
|
- // the relax constrains model seem to be just fine
|
|
|
+ // While many systems use shear and bend springs,
|
|
|
+ // the relaxed constraints model seems to be just fine
|
|
|
// using structural springs.
|
|
|
// Shear
|
|
|
// var diagonalDist = Math.sqrt(restDistance * restDistance * 2);
|
|
@@ -193,13 +193,13 @@ function Cloth( w, h ) {
|
|
|
// for (v=0;v<h;v++) {
|
|
|
// for (u=0;u<w;u++) {
|
|
|
|
|
|
- // constrains.push([
|
|
|
+ // constraints.push([
|
|
|
// particles[index(u, v)],
|
|
|
// particles[index(u+1, v+1)],
|
|
|
// diagonalDist
|
|
|
// ]);
|
|
|
|
|
|
- // constrains.push([
|
|
|
+ // constraints.push([
|
|
|
// particles[index(u+1, v)],
|
|
|
// particles[index(u, v+1)],
|
|
|
// diagonalDist
|
|
@@ -210,7 +210,7 @@ function Cloth( w, h ) {
|
|
|
|
|
|
|
|
|
this.particles = particles;
|
|
|
- this.constrains = constrains;
|
|
|
+ this.constraints = constraints;
|
|
|
|
|
|
function index( u, v ) {
|
|
|
|
|
@@ -231,7 +231,7 @@ function simulate( time ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var i, il, particles, particle, pt, constrains, constrain;
|
|
|
+ var i, il, particles, particle, pt, constraints, constraint;
|
|
|
|
|
|
// Aerodynamics forces
|
|
|
|
|
@@ -264,19 +264,19 @@ function simulate( time ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Start Constrains
|
|
|
+ // Start Constraints
|
|
|
|
|
|
- constrains = cloth.constrains;
|
|
|
- il = constrains.length;
|
|
|
+ constraints = cloth.constraints;
|
|
|
+ il = constraints.length;
|
|
|
|
|
|
for ( i = 0; i < il; i ++ ) {
|
|
|
|
|
|
- constrain = constrains[ i ];
|
|
|
- satisifyConstrains( constrain[ 0 ], constrain[ 1 ], constrain[ 2 ] );
|
|
|
+ constraint = constraints[ i ];
|
|
|
+ satisifyConstraints( constraint[ 0 ], constraint[ 1 ], constraint[ 2 ] );
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Ball Constrains
|
|
|
+ // Ball Constraints
|
|
|
|
|
|
ballPosition.z = - Math.sin( Date.now() / 600 ) * 90 ; //+ 40;
|
|
|
ballPosition.x = Math.cos( Date.now() / 400 ) * 70;
|
|
@@ -301,7 +301,7 @@ function simulate( time ) {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // Floor Constains
|
|
|
+ // Floor Constraints
|
|
|
|
|
|
for ( particles = cloth.particles, i = 0, il = particles.length; i < il; i ++ ) {
|
|
|
|
|
@@ -315,7 +315,7 @@ function simulate( time ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // Pin Constrains
|
|
|
+ // Pin Constraints
|
|
|
|
|
|
for ( i = 0, il = pins.length; i < il; i ++ ) {
|
|
|
|