{"id":46,"date":"2010-09-26T10:15:30","date_gmt":"2010-09-26T09:15:30","guid":{"rendered":"http:\/\/www.joesfer.com\/?p=46"},"modified":"2015-05-15T20:19:18","modified_gmt":"2015-05-15T19:19:18","slug":"growing-organic-structures","status":"publish","type":"post","link":"https:\/\/www.joesfer.com\/?p=46","title":{"rendered":"Growing organic structures"},"content":{"rendered":"<p><a href=\"http:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/bunny.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-49\" title=\"Image converted using ifftoany\" src=\"http:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/bunny.jpg\" alt=\"\" width=\"500\" height=\"500\" srcset=\"https:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/bunny.jpg 500w, https:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/bunny-150x150.jpg 150w, https:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/bunny-300x300.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>This project arose from a conversation with my friend <a title=\"Gino Dammers\" href=\"http:\/\/uk.linkedin.com\/in\/ginodammers\" target=\"_blank\">Gino<\/a>, who is currently working on Medical Visualization, about the difficulty for an artist to create growing structures such as veins -let alone animate them- and how to make them look organic, and therefore irregular and adapted to the surrounding they grow upon.<\/p>\n<h2>The Problem<\/h2>\n<p>I decided to tackle the problem, and the first approach that came to my mind were <a title=\"L-Systems\" href=\"http:\/\/en.wikipedia.org\/wiki\/L-system\" target=\"_blank\">L-Systems<\/a>, which have proven useful for modelling vegetation. There are two restrictions, however, which discouraged me from taking this approach:<\/p>\n<ol>\n<li>We should be able to bind the growing of the structures to a surface, and therefore the growth needs to be <strong><em>context<\/em> <em>aware<\/em><\/strong>.<\/li>\n<li>We need to be able to <strong>direct the growth<\/strong> by specifying the areas the structure is allowed to occupy.<\/li>\n<\/ol>\n<p>Doing some research I ended up taking the approach described in the paper <a title=\"paper\" href=\"http:\/\/algorithmicbotany.org\/papers\/colonization.egwnp2007.html\" target=\"_blank\">Modeling trees with a space colonization algorithm<\/a>, listed in <a title=\"algorithmic botany\" href=\"http:\/\/algorithmicbotany.org\/papers\/\" target=\"_blank\">Algorithmic Botany<\/a>, which perfectly suits the aforementioned requirements.<\/p>\n<h2>Space Colonization Algorithm<\/h2>\n<div id=\"attachment_48\" style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"..\/wp-content\/uploads\/2010\/09\/SCA.png\"><img aria-describedby=\"caption-attachment-48\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-48 \" title=\"SCA\" src=\"..\/wp-content\/uploads\/2010\/09\/SCA-300x189.png\" alt=\"\" width=\"300\" height=\"189\" srcset=\"https:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/SCA-300x189.png 300w, https:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/SCA.png 677w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-48\" class=\"wp-caption-text\">Space Colonization Algorithm<\/p><\/div>\n<p>The idea for the <strong>Space Colonization Algorithm<\/strong> is brilliantly simple: instead of generating the nodes that build our structure by using a set of rules (e.g. a grammar), we begin by producing a set of <strong>attractor points<\/strong> by sampling a domain -the surface of an object in our case-. Then we provide one or several<strong> start locations<\/strong>, and we iteratively start adding nodes by looking for the set of<strong> nearest <em>active <\/em>attractors<\/strong>, and growing towards them. When a new node is added, it <strong>kills all the attractor points<\/strong> which fall within a specified range, preventing other branches to fill in the same space, and directing the growth forward.<\/p>\n<h2>Implementation in Maya<\/h2>\n<p>Given the stages of the SCA algorithm, the natural solution felt to devise them as a set of separate DAG nodes which will be linked together. This allows Maya to cache the result of each individual stage and <strong>update the graph efficiently<\/strong> when a given parameter is tweaked without requiring the whole solution to be re-evaluated.<\/p>\n<p><a href=\"http:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/nodes.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-47\" title=\"nodes\" src=\"http:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/nodes.png\" alt=\"\" width=\"500\" height=\"142\" srcset=\"https:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/nodes.png 500w, https:\/\/www.joesfer.com\/wp-content\/uploads\/2010\/09\/nodes-300x85.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<ul>\n<li><strong>The Sampler node<\/strong>: takes a mesh as the input and produces a number of attractor points by sampling it. The more points we generate, the better the growing structure will fit upon the surface, but that will also tend to generate denser heavier structures.<\/li>\n<li><strong>The Grower node<\/strong>: implements the SCA algorithm. It is fed with the set of attractor points, which are stored in a <a title=\"kd-tree\" href=\"http:\/\/en.wikipedia.org\/wiki\/Kd-tree\" target=\"_blank\">kd-tree<\/a> for efficient <a title=\"nearest neighbor\" href=\"http:\/\/en.wikipedia.org\/wiki\/Nearest_neighbor_search\" target=\"_blank\">nearest neighbor<\/a> queries. An <strong>input locator <\/strong>provides the start position for the growth, and the exposed parameters of the algorithm control how the attractors are consumed to produce the resulting structure:\n<ul>\n<li><strong><em>Search Radius<\/em><\/strong>: specifies what&#8217;s the maximum distance an attractor point can influence over a node. It is given in % of the mesh bounding box extents. A high value will link distant areas, allowing the structure to &#8220;jump&#8221; between them.<\/li>\n<li><strong><em>Kill Radius<\/em><\/strong>: The range within an attractor point will be killed if it is near a grower node. Large kill radius result in smoother branches, whereas lower values will generate curlier shapes.<\/li>\n<li><strong><em>Grow Distance<\/em><\/strong>: the distance between nodes, the lower the value, the denser the resulting geometry.<\/li>\n<li><strong><em>Max Neighbors<\/em><\/strong>: for the nearest neighbor searches &#8211; controls how many attractor points affect a given node at a time. Large values will smooth out the branches, and a low number of neighbors on the other hand will produce <em>noisier <\/em>more organic lines (up to a limit).<\/li>\n<\/ul>\n<\/li>\n<li><strong>The Trimmer node<\/strong>: provides a Percent Length parameter which can be used to animate the growth of the structure generated.<\/li>\n<li><strong>The GrowerShape node<\/strong>: takes the (trimmed) result of the SCA and generates a polygonal mesh. It exposes a <em>Tube Sections<\/em>, and <em>Thickness <\/em>parameters, which control the smoothness and size of the branches.<\/li>\n<\/ul>\n<p>The node hierarchy can be easily built with the provided command <strong>&#8220;grow<\/strong>&#8221; -\u00c2\u00a0 Just select a mesh and an optional a locator node, and type <em>grow<\/em> on the MEL console.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/15292473\" width=\"640\" height=\"424\" frameborder=\"0\" title=\"Maya Grower\" webkitallowfullscreen mozallowfullscreen allowfullscreen><\/iframe><\/p>\n<h3>Directing the growth<\/h3>\n<p>The sampler node allows restricting which faces are used to generate the attractor points. To do so, it uses a <strong>vertex color set<\/strong> associated with the input mesh: the lightness of the vertex colors is used to determine the probability for each face to be sampled, hence, black faces will be excluded from sampling. See the example video below.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/15274926\" width=\"640\" height=\"256\" frameborder=\"0\" title=\"guiding growth\" webkitallowfullscreen mozallowfullscreen allowfullscreen><\/iframe><\/p>\n<h2>Download<\/h2>\n<p>If you feel like trying it out, I have compiled a version of the plugin for Maya 2011 32 and 64-bit. You can find it <a title=\"Plugin\" href=\"http:\/\/www.joesfer.com\/wp-content\/uploads\/programming\/Maya\/grower\/grower.zip\" target=\"_blank\">here<\/a>.<\/p>\n<p><strong>Edit<\/strong>: I&#8217;ve also added new precompiled binaries for <a href=\"https:\/\/github.com\/joesfer\/Grower\/tree\/master\/precompiled\/maya2015_x64\" target=\"_blank\">Maya 2015 64 bit <\/a>(Windows).<\/p>\n<p>Also, the source code is hosted under <a title=\"github\" href=\"https:\/\/github.com\/joesfer\/Grower\">github<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>About procedural organic-looking grown structures, which  must be controllable and confined to user-defined space. <a class=\"more-link\" href=\"https:\/\/www.joesfer.com\/?p=46\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":49,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[20,21,54,19,22],"_links":{"self":[{"href":"https:\/\/www.joesfer.com\/index.php?rest_route=\/wp\/v2\/posts\/46"}],"collection":[{"href":"https:\/\/www.joesfer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joesfer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joesfer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joesfer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=46"}],"version-history":[{"count":0,"href":"https:\/\/www.joesfer.com\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.joesfer.com\/index.php?rest_route=\/wp\/v2\/media\/49"}],"wp:attachment":[{"href":"https:\/\/www.joesfer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joesfer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joesfer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}