From the course: Grasshopper: Tips, Tricks, and Techniques

Unfolding from scratch, part 2

- [Narrator] I have my Exercise file open already. In the last video we started building out an unfolding tool that would take a poly-surface or mesh or just a set of points that represented an object and unfold them in a logical way based on the relationships between the faces. You can see here we're unfolding each of these faces but we have an example of one face, which needs multiple unfolds because the tree that connects this face back to the face that's staying flat, goes through face number three. This up here at the top is face number five, it's going through face number three so we need to apply the transformation to face number three, to face number five to get it to come all the way down to the origin. This is common unfolding and it's a really simple illustration of how every complex unfolding algorithm works where it builds a tree structure that links all of the faces within the shape back to whichever face is actually staying in its proper location, is at the plane that you're unfolding onto. So how do we do this? So we have, a rotation's happening right here and we have a list of transformations coming out. You can see in this Exercise file, I've added a couple things since the last video. First, a transformation index list and second, a twist that'll let us test out how this works if the geometry gets a little weird. So lets look at this transformation index. For each of these, there's just a single transformation. For face zero, we're just using transformation zero. For face one, we're using transformation one and only face five has multiple transformations. If this was more complex geometry, this transformation index list would be far more complicated. What we can do now, we'll go to sets, list item, we're going to plug in here and we're going to get the transformations and now we have our six transformation values. Actually we need to do one thing before we do this. Because these are now strings that have a comma in them, so we have multiple items per string, I need to go to sets, text, we need to break this text apart at that comma which will give us a data tree. This data tree, most of the branches will have one item but one of the branches, the branch for face number five will have two items. We can see that one item, then the first five branches and then on the sixth branch we have two items. Now we have two transformations for that last face. Now lets see what happens if I go to transform, transform geometry, and remember what I'm doing is I'm getting the transformations by index. I'll plug that in, I'm going to graph this so we can plug in, or before I do that I have to combine these so when we have multiple transformations I actually want to combine them into single transformations. I see I have an error, solution not set to an instance of an object. The reason is because I have a null value because one of the faces is not actually transforming at all. So there's my null, so how do we deal with this? This compound transformation component doesn't want to deal with a null so we don't want to pass the nulls in here either, basically what we want is a transformation that does nothing. We want this face to just sit here, it's not going to move. What we can do is replace this null value with a transformation, an identity transformation, meaning it's a transformation that does nothing it just preserves the identity of the object that it's operating on. So how do we create that? One easy way to do it is to go to transform, move and I'm going to set one vector, I'm going to set the vector to zero comma zero comma zero. This move component is not doing anything, it's not moving at all and here is the transformation that's coming out of it. So we're going to replace this null transformation with this transformation right here. If I go to sets, I want to first find that null component. So go to null item, this will give me a true value for null items and a false value for non-null items. Now I want to replace nulls, and actually I can simply skip this finding the null items and just replace them and now I have a list without any nulls. Now I have my rotations and then I have my move zero where I had the null value. I'm going to plug that in here, now I get one transformation for each item. That is a compound transformation and I'll plug that in here and I can actually flatten all of this so we get a cleaner list. I'm going to plug my faces in, now you see I'm unfolding the whole box all the way flat to the origin. It's a really simple logic. The key thing here is I have a poly surface with a list of faces, I'm looking at the index in the indices of each of those faces and it has a list of edges. I'm looking at the indices of each of those edges and then I'm building out lists of rotations. So an axis, a reference, and then this transformation indices that tells each face, okay here's how you unfold down to the origin. If I want to see this working with something that's a little more complicated, here I'm just twisting the original shape. You can see, it works the same so it's still just unfolding all of these things down based on that plane at the center at each of the faces. It doesn't care that the face is curvy or twisted which is another nice feature using this approach. Sometimes that's what you want, you don't want to unroll this thing completely flat. There is a limitation here, so if I were to replace this box with some other box that's generated another way. If I create a box by extruding cap it, so now I have a box but I created this box using a different sequence of steps. If I input this box, it's very likely that faces will not be in the same order. These indices listing the order of the faces and the order of the curves won't be the same in the logic breaks down. This process works great if you're creating the geometry programmatically and you know the order of the faces every single time. If you don't, then you need to actually figure out a way to build up that order in a logical way by checking the locations of faces against some reference point. That's the type of thing that a plug-in like Ivy does or it actually builds up that unfold tree for you using a bunch of different logical systems.

Contents