/// <summary> /// /// </summary> /// <param name="args"></param> public static void Start() { var random = new Random(0); var box = new Interval3d(new Vec3d(0.0), new Vec3d(10.0)); // create a interval between the (0,0,0) and (10,10,10) // create particles var particles = new Particle[] { new Particle(random.NextVec3d(box)), new Particle(random.NextVec3d(box)), new Particle(random.NextVec3d(box)), new Particle(random.NextVec3d(box)) }; // create constraints var constraints = new IConstraint[] { new PlanarQuad(0, 1, 2, 3) }; // create solver var solver = new ConstraintSolver(); // wait for keypress to start the solver Console.WriteLine("Press return to start the solver."); Console.ReadLine(); // step the solver until converged while (!solver.IsConverged) { solver.Step(particles, constraints); Console.WriteLine($" step {solver.StepCount}"); } Console.WriteLine("\nSolver converged! Press return to exit."); Console.ReadLine(); }
/// <summary> /// /// </summary> public static void Start() { // import halfedge mesh var mesh = HeMesh3d.Factory.CreateFromOBJ(Paths.Resources + _fileIn); // create particles var bodies = mesh.Vertices.Select(v => new Body(v.Position)).ToArray(); // create constraints var constraints = mesh.Faces.Where(f => !f.IsDegree3) .Select(f => new Coplanar(f.Vertices.Select(v => v.Index))) .ToArray(); // create solver var solver = new ConstraintSolver(); solver.Settings.LinearDamping = 0.1; // wait for keypress to start the solver Console.WriteLine("Press return to start the solver."); Console.ReadLine(); // step the solver until converged while (!solver.IsConverged) { solver.Step(bodies, constraints, true); Console.WriteLine($" step {solver.StepCount}"); } Console.WriteLine("\nSolver converged! Press return to exit."); // update mesh vertices mesh.Vertices.Action(v => v.Position = bodies[v].Position.Current); // mesh elements (vertices, halfedges, faces) are implicitly converted to their index // compute vertex normals & write to file mesh.Vertices.Action(v => v.Normal = v.GetNormal(), true); Interop.Meshes.WriteToObj(mesh, Paths.Resources + _fileOut); Console.ReadLine(); }
/// <summary> /// /// </summary> public static void Start() { // import halfedge mesh var mesh = HeMesh3d.Factory.CreateFromOBJ(Paths.Resources + _fileIn); // create particles var particles = mesh.Vertices.Select(v => new Particle(v.Position)).ToArray(); // create constraints var constraints = mesh.Faces.Where(f => !f.IsDegree3) .Select(f => new PlanarNgon(f.Vertices.Select(v => v.Index))) .ToArray(); // create solver var solver = new ConstraintSolver(); // wait for keypress to start the solver Console.WriteLine("Press return to start the solver."); Console.ReadLine(); // step the solver until converged while (!solver.IsConverged) { solver.Step(particles, constraints, true); Console.WriteLine($" step {solver.StepCount}"); } Console.WriteLine("\nSolver converged! Press return to exit."); // update mesh vertices mesh.Vertices.Action(v => v.Position = particles[v.Index].Position); // mesh.Vertices.Action(v => v.Position = particles[v].Position); // mesh elements (vertices, halfedges, faces) are converted to their indices implicitly so this also works // compute vertex normals & write to file mesh.GetVertexNormals(v => v.Position, (v, n) => v.Normal = n, true); mesh.WriteToOBJ(Paths.Resources + _fileOut); Console.ReadLine(); }