Kangaroo

THIS FORUM IS NO LONGER ACTIVE. PLEASE POST ANY NEW QUESTIONS OR DISCUSSION ON:

https://discourse.mcneel.com/c/grasshopper/kangaroo

The discussions here are preserved for reference, but new questions posted here are likely to go unanswered.

Kangaroo is a Live Physics engine for interactive simulation, optimization and form-finding directly within Grasshopper.

Goal source code examples

Over the last year it has been great to see an increasing number of people start to script their own custom goals for Kangaroo2.

To help with this I have just open sourced most of the code for the actual goals that are included as components in the Kangaroo2 plugin.

Hopefully seeing how the existing ones work will be useful to some of you as a starting point for customizing or extending them. It may also be useful when trying to understand how certain goals behave to be able to look inside.

You can find the repository here:

https://github.com/Dan-Piker/K2Goals

Please do ask here any questions you may have about how these work.

The commenting is currently fairly minimal, but I'll try and improve that.

You may notice that some of these goals  inherit from a class called GoalObject, while some of the older ones directly implement an interface called IGoal.

GoalObject is a helper class which saves you from having to implement all the methods in the IGoal interface, and it is recommended to use GoalObject when creating your own.

  • up

    Daniel Piker

    To add to this - a few general guidelines when setting out to create your own goals:

    -Remember, a Goal is something that given the current positions of a set of points, calculates where it wants to move those points to.

    -The PIndex array is an array of integers, one for each point this goal acts on, giving its index in the particle list.

    -The move vectors on your set of points should usually sum to zero (for instance the two move vectors acting on each end of a spring are always equal and opposite). This is because otherwise you could introduce unbalanced forces causing the particles to fly off into space. An exception to this is if you are pulling points towards some fixed geometry, such as a target mesh. In this case it is as though the fixed geometry has infinite mass, and thus whatever the reaction force on it, it will not be moved, so we do not need to calculate this reaction.

    1
    • up

      Jens Pedersen

      Hi Daniel, 

      I have just tried to look through some old components I made and I am getting this error:

      1. Solution exception:Unable to cast object of type 'ModInflate' to type 'KangarooSolver.IGoal'.

      Any solutions? or have you swapped from GoalObject to IGoal?

      All the best 

      Jens

      3
      • up

        Ludovic Regnault

        Hi,

        I was trying to get inspired by the Plastic Length Goal to developp another goal, but I don't manage to use the Plastic Length script properly.

        There are no error messages but the plastic deformation does not work when the endpoint is pulled. It seems that the loop

        if (Stretch > Limit)
        { RestLength += Stretch - Limit; } ...

        is not actualizing the RestLength.

        Does anyone knows how this could be fixed ?

        Thanks

        4