I am trying to start with KangarooSolver.dll. Unery force need to be added. But it is not working.
Did I write it wrong?
//initialize the solver
var PS = new KangarooSolver.PhysicalSystem();
var Goals = new List();
//get the Mesh points and boundary status
Point3d[] Pts = M.Vertices.ToPoint3dArray();
bool[] Naked = M.GetNakedEdgePointStatus();
for (int i = 0; i < M.Vertices.Count; i++)
{
PS.AddParticle(Pts[i], 1); //add a particle for every mesh vertex
if (Naked[i] == true && i % 10 == 0)
{ Goals.Add(new KangarooSolver.Goals.Anchor(i, Pts[i], 10000)); }// fix the boundaries strongly in place
Vector3d vt = new Vector3d(0,0,-1);
if (Naked[i] == false)
{
Goals.Add(new KangarooSolver.Goals.Unary(Pts[i],vt));
}
}
for (int i = 0; i < M.TopologyEdges.Count; i++)
{
var Ends = M.TopologyEdges.GetTopologyVertices(i);
int Start = M.TopologyVertices.MeshVertexIndices(Ends.I)[0];
int End = M.TopologyVertices.MeshVertexIndices(Ends.J)[0];
Goals.Add(new KangarooSolver.Goals.Spring(Start, End, 0, 1)); //for each edge, a spring with rest length 0, and strength 1
//
}
int counter = 0;
double threshold = 1e-6;
do
{
//Step forward, using these goals, with multi-threading on, and stopping if the threshold is reached
PS.Step(Goals, true, threshold);
counter++;
} while (PS.GetvSum() > threshold && counter < 100);
//GetvSum returns the current kinetic energy
//always include a counter to prevent it getting stuck forever in case it cannot reach the given threshold
//replace the mesh vertices with the relaxed ones
M.Vertices.Clear();
M.Vertices.AddVertices(PS.GetPositions());
//Output the mesh, and how many iterations it took to converge
Mesh A = M;
//B = counter;
doc.Objects.AddMesh(A);