system_verlet library
TODO lot of test (unit, ...) TODO benchmark, profiling, optimisation
Functions
dynamic setCollideOfSegment(Entity e, collide) #
setCollideOfSegment(Entity e, collide) { (e.getComponent(Constraints.CT) as Constraints).l.forEach((c){ if (c is Constraint_Distance) c.segment.collide = collide; }); }
dynamic pinVector3(Vector3 v, Constraints cs) #
pinVector3(Vector3 v, Constraints cs) { cs.l.add(new Constraint_Pin(v)); }
dynamic pinParticle(Entity e, int index) #
pinParticle(Entity e, int index) { pinVector3( (e.getComponent(Particles.CT) as Particles).position3d[index], e.getComponent(Constraints.CT) ); }
Iterable<Component> makeCloth(Vector3 origin, Vector3 width, Vector3 height, int segments, int pinMod, double stiffness, ParticlesConstructor genP) #
Iterable<Component> makeCloth(Vector3 origin, Vector3 width, Vector3 height, int segments, int pinMod, double stiffness, ParticlesConstructor genP) { var xStride = width / segments.toDouble(); var yStride = height / segments.toDouble(); var diag = width - height; var diagl = diag.length; var xStiffness = stiffness * width.length / diagl; var yStiffness = stiffness * height.length / diagl; var ps = genP(segments * segments); var cs = new Constraints(); for (var y=0; y < segments; ++y) { var x0 = ps.position3d[y*segments + 0]; x0.setFrom(yStride).scale(y.toDouble()).add(origin); if (y > 0) cs.l.add(new Constraint_Distance.fromParticles(ps, y*segments + 0, (y-1)*segments, yStiffness)); for (var x = 1; x < segments; ++x) { // var px = origin.x + x*xStride - width/2 + xStride/2; // var py = origin.y + y*yStride - height/2 + yStride/2; var xi = ps.position3d[y*segments + x]; xi.setFrom(xStride).scale(x.toDouble()).add(x0); cs.l.add(new Constraint_Distance.fromParticles(ps, y*segments + x, y*segments+x-1, xStiffness)); if (y > 0) { cs.l.add(new Constraint_Distance.fromParticles(ps, y*segments + x, (y-1)*segments+x, yStiffness)); //cs.l.add(new Constraint_Distance.fromParticles(ps, y*segments + x, (y-1)*segments+x-1, stiffness)); } } } ps.copyPosition3dIntoPrevious(); for (var x=0; x< segments; ++x) { if ( x % pinMod == 0) pinVector3(ps.position3d[x], cs); } return [ps, cs]; }
Iterable<Component> makeParallelogram(Vector3 origin, Vector3 width, Vector3 height, double stiffness, ParticlesConstructor genP) #
Iterable<Component> makeParallelogram(Vector3 origin, Vector3 width, Vector3 height, double stiffness, ParticlesConstructor genP) { return makeLineSegments([origin, origin + width, origin + width + height, origin + height], stiffness, true, genP); }
Iterable<Component> makeLineSegments(List<Vector3> vertices, double stiffness, bool closed, ParticlesConstructor genP) #
Iterable<Component> makeLineSegments(List<Vector3> vertices, double stiffness, bool closed, ParticlesConstructor genP) { var ps = genP(vertices.length); for(int i = 0; i < ps.length; ++i) { ps.position3d[i].setFrom(vertices[i]); } ps.copyPosition3dIntoPrevious(); var cs = new Constraints(); for (var i = 1; i < ps.position3d.length; ++i) { cs.l.add(new Constraint_Distance.fromParticles(ps, i, i-1, stiffness)); } if (closed) { cs.l.add(new Constraint_Distance.fromParticles(ps, 0, ps.position3d.length - 1, stiffness)); } return [ps, cs]; }
Iterable<Component> makeTireXY(Vector3 origin, double radius, int segments, double spokeStiffness, double treadStiffness, ParticlesConstructor genP) #
Iterable<Component> makeTireXY(Vector3 origin, double radius, int segments, double spokeStiffness, double treadStiffness, ParticlesConstructor genP) { var stride = (2 * math.PI) / segments; // particles var ps = genP(segments + 1); for (var i=0; i < segments; ++i) { var theta = i * stride; var v = ps.position3d[i].setFrom(origin); v.x = v.x + math.cos(theta) * radius; v.y = v.y + math.sin(theta) * radius; } ps.position3d[segments].setFrom(origin); ps.copyPosition3dIntoPrevious(); // constraints var cs = new Constraints(); for (var i=0; i < segments; ++i) { cs.l.add(new Constraint_Distance.fromParticles(ps, i, (i + 1) % segments, treadStiffness)); cs.l.add(new Constraint_Distance.fromParticles(ps, i, segments, spokeStiffness)); cs.l.add(new Constraint_Distance.fromParticles(ps, i, (i + 5) % segments, treadStiffness)); } return [ps,cs]; }