Saturday 11 March 2017

Create Arrays Containing the Vertices for Each Primitive

I got a question about how you could create an array out of four points for each primitive in one of the comments so I thought that I make a quick example.

So in this scene I'm reading every vertex for each primitive, put them in an array, move the box,  read them back and then add a point at the original position. It looks like this.


Make sure that your Attribute VOPS are running over primitives.


Inside the first VOP I'm using a For Loop and the numvtx (which is the number of verticies that the current primitive has) to drive how many time it will loop. I'm then using an Import Vertex Attribute with the current element index to pick up the position of the vertices. Lastly I'm appending them to an array. As we've selected that we are running over Primitives this will create an array for each Primitive.



To read it back is very easy. Just make sure that you are running over Primitives here as well. After that you can just use an for each node to step through your arrays. 




Hope that you will find this useful, The project file can be downloaded from here: Project File


5 comments:

  1. Wow, Thank's alot !
    I might have some question with the ReadBack. I'm not sure yet, maybe I should practice more before asking. I think the vertex get me confused.
    With your setup, as we're working with vertex, in the ReadBack it's adding 4points per vertex.

    I'm trying to refilter the result with a Get element and setting its index (at for example index 0)and Bind-Export it.
    I'd like to use these positions to place other objects.

    I'm attaching the scene, it might be easier to understand.
    https://drive.google.com/open?id=0B1QqhXD7Y15qZ1lHclBNOGtibjQ

    ReplyDelete
    Replies
    1. Hmm, I don't really understand what you are trying to do. In your scene the bind export will only export the last vertex position in each array as it will overwrite it on every iteration. In my example I'm adding three times the points as every point is shared by three vertices. In most 3d software a vertex and a point is the same thing, but Houdini they are "containers" that are specific for that primitive. So every vertex is numbered 1-4 in the box, but with different primitive numbers so prim 1 has a vertex 1 and prim 2 also has a vertex number 1 but that will be containing a different point position.

      If you just want to attach objects to the point positions, why don't you just use a copy SOP?

      Delete
  2. I'm sorry, I'm sorry.
    It's not that I have something particular in mind. I'm just trying to bring some of the ICE arrays node into Houdini.
    I wasn't even able to wire a correct loop to collect a proper array of point per primitive !
    And you did it for me ! Now I have something to chew :)
    The weird part was dealing in Primitive mode with Vertices.
    I think I have got it now.
    Sending you this just for fun :

    https://drive.google.com/open?id=0B1QqhXD7Y15qSDUyTjNva0xrZVk

    Do you know a way to reorder the vertex order the same way the Sort SOP Does ?
    Using the Primitive SOP, but it's limited to "shift"

    ReplyDelete
    Replies
    1. Ah, right! Pretty cool scene :) The vertices themselves can't be reordered as they are just containers 0,1,2 etc and only refer to the pointnumber, but you can do your own sorting logic and use Set Primitive Vertex to put the positions where you want them. Maybe there is an easier way, but that is the only way that I know of.

      Delete
  3. Yes, I saw Set Primitive Vertex, but I wasn't able to use it properly. Need to find an example somewhere.
    A big thank you for opening my eyes on the Array setup !

    ReplyDelete