Vertex Force and Closeness Constraint
This example demonstrates a dynamic cloth simulation using vertex force, edge strain constraint, and closeness constraints. First we create a grid mesh and initialize the solver from it. Then we add closeness constraints to pin the corners of the mesh in place. Next we add edge strain constraints to make the mesh more regular. Finally we add vertex force to make the mesh more dynamic. We run the solver for 100 iterations and update the mesh vertices in real-time. The simulation is interactive and can be stopped at any time.
from compas.datastructures import Mesh
from compas_viewer import Viewer
from compas_shapeop.meshsolver import MeshSolver
mesh = Mesh.from_meshgrid(10, 8, 10, 8)
mesh.translate([-5, -5, 0])
s = MeshSolver(mesh)
s.fix_vertices(vertices=mesh.vertices_where({"vertex_degree": 2}))
s.constrain_edge_lengths()
s.add_gravity()
s.solve(1000)
viewer = Viewer()
viewer.scene.add(s.mesh)
viewer.show()