All Kangaroo Pages - Grasshopper2024-03-29T15:10:07Zhttps://www.grasshopper3d.com/group/kangaroo/page/page/list?sort=mostRecent&feed=yes&xn_auth=noKangaroo2 - scripting custom iteration - examplestag:www.grasshopper3d.com,2016-09-20:2985220:Page:16026802016-09-20T16:08:06.911ZDaniel Pikerhttps://www.grasshopper3d.com/profile/DanielPiker
<p>I'm going to post here some examples of writing simple C# scripts which use the Kangaroo library for custom iterative behaviour. While I have posted a number of examples of custom goals before, so far I've not shown much about such custom looping.</p>
<p>This can be useful because it allows you to make changes in topology (such as which goals act on which particles, or the number of particles in the simulation), which would be difficult or impossible using only the standard…</p>
<p>I'm going to post here some examples of writing simple C# scripts which use the Kangaroo library for custom iterative behaviour. While I have posted a number of examples of custom goals before, so far I've not shown much about such custom looping.</p>
<p>This can be useful because it allows you to make changes in topology (such as which goals act on which particles, or the number of particles in the simulation), which would be difficult or impossible using only the standard components.</p>
<p>Please let me know if you have any questions about these files, or requests for other types of examples.</p>
<p></p>
<p>For all of these scripting examples, the first time you open them you will need to set the location of the <strong>KangarooSolver.dll</strong> on your system.</p>
<p>I think the easiest way to do this is to use <em><strong>File>Special Folders>Components Folder</strong></em> to navigate to your libraries folder, and copy the path. Then right click the script component on the canvas, and <em><strong>Manage Assemblies</strong></em>. Select and delete the KangarooSolver reference which is there, then choose <em><strong>Add</strong></em>, paste the path you copied earlier, and select your local copy of <em><strong>KangarooSolver.dll</strong></em></p>
<p><em><strong><br></strong></em> After you have done this once, it should be easier with future files, as the dll will then show up in the <em><strong>recent assemblies</strong></em> tab, and you can simply drag it over.</p>
<p><em><strong><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653176081?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653176081?profile=RESIZE_1024x1024" width="750" class="align-full"></a><br></strong></em></p>
<p>Example 1: <a href="http://storage.ning.com/topology/rest/1.0/file/get/2653176138?profile=original" target="_self">AddingPoints.gh</a></p>
<p>Starting with something simple - this takes a collection of points, pulls them to a mesh, with collisions between them, and adds a new point at each iteration. Note that here the PhysicalSystem object is actually being created anew at each iteration, with the point locations the only thing preserved between iterations.</p>
<p></p>
<p>Example 2: <a href="http://storage.ning.com/topology/rest/1.0/file/get/2653176192?profile=original" target="_self">GrowingLine.gh</a></p>
<p>This is an updated version of a file I previously posted <a href="http://www.grasshopper3d.com/forum/topics/new-scripting-examples?groupUrl=kangaroo" target="_blank">here</a>. I've cleaned it up a bit to hopefully make it easier to follow. Unlike the first example, this actually maintains the physical simulation from one iteration to the next. It includes a custom goal for the collisions, as the one in the current compiled component did not have a constructor allowing you to assign the Indexing directly. </p>
<p></p> Kangaroo2 additional examplestag:www.grasshopper3d.com,2015-03-20:2985220:Page:12467622015-03-20T17:53:32.827ZDaniel Pikerhttps://www.grasshopper3d.com/profile/DanielPiker
<p>The download of the new version from Food4Rhino comes with several example files, but I will be posting additional ones here.</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653174129?profile=original" target="_self">LinesCollideExample.gh</a></p>
<p>Collision between line segments</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653174244?profile=original" target="_self">Raisin.gh</a></p>
<p>An example of volume driven buckling, as…</p>
<p>The download of the new version from Food4Rhino comes with several example files, but I will be posting additional ones here.</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653174129?profile=original" target="_self">LinesCollideExample.gh</a></p>
<p>Collision between line segments</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653174244?profile=original" target="_self">Raisin.gh</a></p>
<p>An example of volume driven buckling, as shown <a href="http://www.grasshopper3d.com/photo/raisin" target="_blank">here</a></p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653174316?profile=original" target="_self">Voronoi_relaxK2.gh</a></p>
<p>Simple tensile relaxation of a Voronoi mesh, in response to <a href="http://www.grasshopper3d.com/video/voronoi-3d-relaxation-kangaroo" target="_blank">this</a></p>
<p></p>
<p><strong><em>07/04/15 all files below updated for version 2.01</em></strong></p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653174345?profile=original" target="_self">sculpt_example.gh</a></p>
<p>This is the file shown in this video:</p>
<p><a href="http://www.grasshopper3d.com/video/bowlsculpt" target="_blank">http://www.grasshopper3d.com/video/bowlsculpt</a></p>
<p>It demonstrates the use of plastic anchors for sculpting</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653174508?profile=original" target="_self">PlanarQuads.gh</a></p>
<p>The file shown in this video:</p>
<p><a href="http://www.grasshopper3d.com/video/kangaroo2-planar-quad-mesh-editing" target="_blank">http://www.grasshopper3d.com/video/kangaroo2-planar-quad-mesh-editing</a></p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653175744?profile=original" target="_self">TensileRelaxScript.gh</a></p>
<p>Another scripting example, showing automatic relaxation of a mesh with fixed boundaries.</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653175862?profile=original" target="_self">Volume_and_SolidPtCollide.gh</a></p>
<p>Showing volume preservation and collision between points and solids</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653175931?profile=original" target="_self">CirclePackOnSurface.gh</a></p>
<p>Packing circles on a surface</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653175981?profile=original" target="_self">PlanarHex.gh</a></p>
<p>Planar hexagonal panels on a surface, as shown <a href="http://www.grasshopper3d.com/photo/planar-hex?" target="_blank">here</a></p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653176087?profile=original" target="_self">TangentIncircles.gh</a></p>
<p>Create a mesh where incircles between adjacent triangles are tangent. This can be used to generate a compact circle packing. See publications <a href="http://Mathias%20H%C3%B6binger" target="_blank">here</a> for more info on the use of such meshes.<span><br/></span></p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653176126?profile=original" target="_self">StepByStep.gh</a></p>
<p>A simple script using the library to apply some goals and iterate only when a button is pushed.</p> Example filestag:www.grasshopper3d.com,2011-07-02:2985220:Page:3093112011-07-02T16:33:12.156ZDaniel Pikerhttps://www.grasshopper3d.com/profile/DanielPiker
<p><em><strong>edit 29/04/14</strong></em> <strong>-</strong> Here is a new collection of more than 80 example files, organized by category:</p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653175802?profile=original" target="_self">KangarooExamples.zip</a></p>
<p>This zip is the most up to date collection of examples at the moment, and collects together a wide variety of definitions made for various workshops and in response to forum questions. Thanks to all workshop…</p>
<p><em><strong>edit 29/04/14</strong></em> <strong>-</strong> Here is a new collection of more than 80 example files, organized by category:</p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653175802?profile=original" target="_self">KangarooExamples.zip</a></p>
<p>This zip is the most up to date collection of examples at the moment, and collects together a wide variety of definitions made for various workshops and in response to forum questions. Thanks to all workshop attendees and forum members for your valuable input.</p>
<p>It is possible I've missed a few useful ones. If there is something else you'd like to see included please let me know</p>
<p></p>
<p>The examples below are mostly older, but I will leave them here for now until I am certain all the same topics are adequately covered in the 'official' collection above.</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653175932?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653175932?profile=original" width="376" class="align-full"></a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653176132?profile=original" target="_self">orbit_trails.ghx</a></p>
<p>Showing how the <strong>trail</strong><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653176198?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653176198?profile=original" width="24" class="align-left"></a> component can be used to trace the motion of moving particles</p>
<p> </p>
<p> </p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653176329?profile=original"><img class="align-full" width="376" src="http://storage.ning.com/topology/rest/1.0/file/get/2653176329?profile=RESIZE_480x480"></a><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653176503?profile=original">wind_example.3dm</a></p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653176677?profile=original">wind_example.ghx</a></p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653176761?profile=original"><img class="align-left" width="24" src="http://storage.ning.com/topology/rest/1.0/file/get/2653176761?profile=original"></a>The <strong>wind</strong> component acts on sets of 3 points (typically each the vertices of each face of a triangulated mesh). It applies a force to each vertex, proportional to its area multiplied by the projection of the wind velocity vector onto the triangle normal.</p>
<p> </p>
<p> </p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653176912?profile=original"><img class="align-full" width="376" src="http://storage.ning.com/topology/rest/1.0/file/get/2653176912?profile=RESIZE_480x480"></a></p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653177043?profile=original">curvepull_example.ghx</a></p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653177208?profile=original"><img class="align-left" width="24" src="http://storage.ning.com/topology/rest/1.0/file/get/2653177208?profile=RESIZE_180x180"></a></p>
<p><strong>CurvePull</strong> - Pulls particles onto a curve. This can be either a hard or soft constraint. Useful for fixing the boundary curves of tensile surfaces, yet allowing the nodes to slide along that boundary.</p>
<p> </p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653177303?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653177303?profile=RESIZE_480x480" width="376" class="align-full"></a><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653177666?profile=original" target="_self">Vortex_example1.ghx</a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653177631?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653177631?profile=RESIZE_480x480" width="376" class="align-full"></a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653177871?profile=original" target="_self">vortex_example2.ghx</a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653177938?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653177938?profile=RESIZE_180x180" width="24" class="align-left"></a>The <strong>Vortex</strong> component rotates one particle about an axis defined by 2 points.</p>
<p> </p>
<p> </p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653178015?profile=original"><img class="align-full" width="376" src="http://storage.ning.com/topology/rest/1.0/file/get/2653178015?profile=RESIZE_480x480"></a><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653178129?profile=original">align_demo1.ghx</a></p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653178435?profile=original">align_demo_sphere.ghx</a></p>
<p><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653178448?profile=original" width="24" class="align-left"><strong>Align</strong> Pulls two line segments towards being parallel.</p>
<p> </p>
<p> </p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653178616?profile=original" target="_self">planarize_demo1.ghx</a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653178640?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653178640?profile=original" width="24" class="align-left"></a><strong>Planarize</strong> takes 4 points and pulls them towards being coplanar<a href="http://storage.ning.com/topology/rest/1.0/file/get/2653178651?profile=original" target="_self"></a></p>
<p> </p>
<p><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653178651?profile=original" class="align-left" width="24"></p>
<p><strong>Planarity</strong> measures how planar a quad defined by 4 points is (it returns the shortest distance between the two diagonals).</p>
<p> </p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653178923?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653178923?profile=RESIZE_480x480" width="376" class="align-full"></a><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653179082?profile=original" target="_self">equalize_demo1.ghx</a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653178980?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653178980?profile=original" width="24" class="align-left"></a><strong>Equalize</strong> adjusts a set of lines towards having equal length (it finds their average length, then treats each line as a spring with this as the rest the length). This demo shows how it can be used to make a quadrilateral circular (the 4 vertices lie on a common circle). Meshes made up of circular quads have a constant distance vertex-vertex offset mesh. (see <a href="http://www.dmg.tuwien.ac.at/pottmann/2008/pw_focal_07/pw_focal_07.html">http://www.dmg.tuwien.ac.at/pottmann/2008/pw_focal_07/pw_focal_07.html</a>)</p>
<p> </p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653178985?profile=original"><img class="align-full" width="376" src="http://storage.ning.com/topology/rest/1.0/file/get/2653178985?profile=RESIZE_480x480"></a><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653179140?profile=original">laplacian_demo1.ghx</a></p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653179307?profile=original"><img class="align-left" width="24" src="http://storage.ning.com/topology/rest/1.0/file/get/2653179307?profile=original"></a></p>
<p><strong>Laplacian</strong> acts on a central vertex, and its ring of neighbouring vertices. It finds the average position of the neighbours, and moves the central vertex towards this point. It also divides the same force up between the number of neighbours, reverses it and applies it to each of them. When applied to each vertex/set of surrounding neighbours of a mesh, this smooths it.</p>
<p> </p>
<p> </p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653179278?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653179278?profile=RESIZE_480x480" width="376" class="align-full"></a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653179465?profile=original" target="_self">shear_demo1.ghx</a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653179507?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653179507?profile=original" width="24" class="align-left"></a></p>
<p><strong>Shear</strong> pulls a particle towards the plane normal to a given line (or to a given height above that plane). It could be useful for example if you wanted to restrict some of the vertices of a mesh to match a plane for glazing lines, or in self-organizing particle systems if you want them to form surfaces not just clusters.</p>
<p> </p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653179612?profile=original"><img class="align-full" width="376" src="http://storage.ning.com/topology/rest/1.0/file/get/2653179612?profile=RESIZE_480x480"></a><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653179656?profile=original">Combined_mesh_optimization_demo.3dm</a></p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653179878?profile=original">Combined_mesh_optimization_demo.ghx</a></p>
<p>(also requires <a target="_blank" href="http://www.giuliopiacentino.com/weaverbird/">WeaverBird</a>)</p>
<p>This demo shows how several forces can be combined to optimize different properties of a mesh. Sliders control the relative strengths of the Laplacian smoothing and Planarization forces.</p>
<p>A shear component keeps the base vertices on the ground plane but allows them to move around on it (Using the shear component here is quicker than constraining to a mesh).</p>
<p>The colours display how planar each quad of the mesh is.</p>
<p>It can sometimes be effective to use high smoothing/low planarization values to begin with and get a nice smooth form, then lower the smoothing and raise the planarization for the fine adjustments to get it within manufacturing tolerances.</p>
<p> </p>
<p> </p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180057?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653180057?profile=RESIZE_480x480" width="376" class="align-full"></a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180141?profile=original" target="_self">equilateralize_demo1.3dm</a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180320?profile=original" target="_self">equilateralize_demo1.ghx</a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180433?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653180433?profile=RESIZE_180x180" width="24" class="align-left"></a></p>
<p><strong>Equilateralization</strong> - This shows how equalization of mesh triangle edge lengths can be combined with smoothing to create a pseudo-physical material that reacts to manipulation of the anchor points</p>
<p> </p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/2653180519?profile=original"><img class="align-full" width="376" src="http://storage.ning.com/topology/rest/1.0/file/get/2653180519?profile=original"></a><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180591?profile=original" target="_self">shell_and_plate_example_updated.gh</a></p>
<p>This shows how the Hinge force can be used to keep the angle between faces of a mesh at a particular angle.</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180724?profile=original" target="_self"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2653180724?profile=RESIZE_480x480" width="400" class="align-full"></a></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180805?profile=original" target="_self">Origami_example.gh</a></p>
<p>This takes a flat mesh, and a choice of which lines will be valley folds, and which ones mountain folds, and folds it into 3d. (Inspired by Tomohiro Tachi's rigid origami simulator)</p>
<p></p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180936?profile=original" target="_self">drape_example.gh</a></p>
<p>Shows how to use solids (Breps or Meshes) as collision volumes and drape a simple fabric over them</p>
<p> </p>
<p>You can also download an earlier collection of example files here:</p>
<p><a target="_blank" href="http://dl.dropbox.com/u/26034251/SimpleKangarooExamples.zip">http://dl.dropbox.com/u/26034251/SimpleKangarooExamples.zip</a></p>
<p>(some of these may need slight changes and updating - I'll be trying to go through these over the next few days and make sure they are all compatible with the latest version. Also - many of them also require the WeaverBird plugin)</p>
<p> </p>
<p>There is also a collection of links to further example files and helpful discussions here:</p>
<p><a href="http://smartgeometry.org/index.php?option=com_community&view=groups&task=viewdiscussion&groupid=2&topicid=11&Itemid=0"></a><a href="http://smartgeometry.org/index.php?option=com_community&view=groups&task=viewdiscussion&groupid=2&topicid=11&Itemid=0">http://smartgeometry.org/index.php?option=com_community&view=groups&task=viewdiscussion&groupid=2&topicid=11&Itemid=0</a></p>
<p></p>
<p>update: here's another example for the vortex force:</p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/2653180979?profile=original" target="_self">swirl_mesh.gh</a> </p>
<p></p>
<p><span style="color: #808080;" class="font-size-1">more example files to follow soon...</span></p>
<div><span style="color: #0000ee;"><br></span></div>
<div><span style="color: #0000ee;"><br></span></div>