algorithmic modeling for Rhino
the new K2 planarize constraint is hard coded to take only (quad) meshes as an input. I am trying to planarize polygons similar to the K0.9 component that took a list of vertices instead.
I had a look at the code on Github and it looks like there is code to deal with ngons, but I haven't been able to get it to work in a C# custom goal.
I used this workflow:
1) Select a K2 constraint and setup a simple demo patch in GH
2) Create a C# component
3) Go to Github and copy paste the source code containing the entire 'public class NameOfConstraint' inside the curly brackets
4) Copy paste the code into the C# component into the section titled // <Custom additional code>
5) Right-click on the C# component and select 'Manage Assemblies...'
6) In the dialog add the Kangaroo.solver from you GH libs
7) Recreate the C# component inputs based on the original K2 constraint paying attention to Access and Type hints
8) Add a line of code into the C# component in the main 'private void' section creating a new instance of the main Class with the component input variables.
A = new FunctionName(x, y);
9) Replace any occurrencies of Particles with KangarooSolver.Particle
Good point - as you saw, the code for planarizing ngons is in there, but with the component taking a (non ngon) mesh there isn't currently a way to use it without scripting. I'll change this for the next release, either to take lists of vertices, or perhaps to take a Plankton mesh.
However, using an existing goal in a scripted component is much simpler than what you describe, and there is no need to copy-paste all the code. You can simply access it via KangarooSolver.Goals
Attached is an example of this.
Also, in case anyone isn't aware of the handy shortcut, when typing the arguments to a constructor like this, you can press Ctrl+Shift+Space to bring up the required inputs, and cycle through the options using the arrow keys.
What you did with copy-pasting the goal code from github would be the right approach for if you wanted to actually modify the actual calculation method of the goal somehow though.
I think your specific example here just happens to be already divided in a way that results in planar panels without needing any optimization!
Is it always necessarily possible to planarize a collection of polygons in this manner? I am using this script in an attempt to planarize the faces of a mesh dual. I'm still unsure if I need to adjust my inputs/weights to kangaroo in some way, or if there is simply no way to planarize my geometry.
I am trying to planarize polygons with your C# "Custom panalize", but the pannel is red and i get an eror:
1. Error (CS1705): Assembly 'KangarooSolver, Version=220.127.116.11, Culture=neutral, PublicKeyToken=null' uses 'RhinoCommon, Version=5.1.30000.13, Culture=neutral, PublicKeyToken=552281e97c755530' which has a higher version than referenced assembly 'RhinoCommon, Version=5.1.30000.4, Culture=neutral, PublicKeyToken=552281e97c755530'
what does it mean?
Which version of Rhino are you running? You might need to update to a current service release
Thanks, Daniel. You make this look super easy - as always.