Kangaroo2 Custom GoalObject logic

Hi,

I’m trying to make a custom goal that duplicates a mesh then makes it move a certain distance (why? to understand the K2/c#/rhino mesh logic) and I’m having trouble with the K2/c#/rhino logic. My understanding w the code below is that it creates 5 new meshes, adds them to a list, then calls the first mesh, then with each vertex, changes the position.

It doesn’t display any errors when I run it but I don’t see anything happening. I’m also wondering how I can access those new meshes via baking because it does not output anything.

    public override void Calculate(List<KangarooSolver.Particle> p)
    {

      var MeshList = new List<Mesh>();

      for(int i = 0;i < 5;i++)
      {
        MeshList.Add(mesh_to_dup);
      }
      
      
      for(int j = 0;j < 5;j++)
      {
        Mesh dupmesh = MeshList[j];
        for (int i = 0; i < dupmesh.Vertices.Count; i++)
        {
          var vertex = dupmesh.Vertices[i];
          var move = new Vector3d(1e-6, 1e-6, 0.0);
          dupmesh.Vertices.SetVertex(i, vertex.X + move.X, vertex.Y + move.Y, vertex.Z + move.Z);
        }
      }

Hi @SalvadorIII

The Calculate method in a custom Goal is there to set the vectors in the Move array (note the case sensitivity). For each particle that Goal acts on, these vectors tell it where to go.
It is only by setting those Move vectors that the Goal has any effect on the simulation. The Move vectors from all the Goals are combined by the solver at each iteration.

Your script looks more like something to use on its own, not inside a Kangaroo Goal.

Hi Daniel,

Thanks for the reply! Yes, it does seem like it can be done outside Kangaroo though my long term plan would be to combine it with other K2 goals like collision.

Aside from ‘Move’, are there any other words that need attention to?

How are PPos and List<KangarooSolver.Particle> p related? Are they just equal to each other?

            for (int i = 0; i < mPoints.Length; i++)
            {
                PPos[i] = mPoints[i];
                Weighting[i] = K;
            }

PPos is the initial locations of the points a Goal acts on. It is only used once, in the initialisation (where coincident points are combined into single particles and indexed with PIndex) and is not updated as the simulation iterates.

The list of KangarooSolver.Particle instead gives the particles as they are at the current iteration. A Goal needs access to this so that it can update its Move vectors based on the new positions.

Thanks Daniel,

Very helpful info! I’m out of questions for now :slight_smile: