Creating Geometry With VEX

comments 41
Featured Video Play Icon

Did you ever wonder how to create polygons and polylines through code in Houdini. It’s a straigtforward concept. But you have to know some things about the way Houdini organizes and stores geometry in memory. In this tutorial Manuel will walk you through the process of creating geometry with VEX in a wrangle. After some theory he’ll show you how to generate a closed polygon. Then you’ll learn how to connect neighbouring points with polylines to create a “plexus” style effect.

The basic sequence of geo creation is the following:

  • Create the points with addpoint()
  • Create an empty primitive to later store the connectivity information
  • Add as many vertices as you like with addvertex() to the primitive
  • Update the point references, these vertices are storing

Update from Vimeo by Zybrand Jacobs:

Great tutorials guys! Its probably worth adding that you are creating 2 overlapping primitives between near points. Depending on the situation you can optimize the geometry even more by using a >= point number rather than the ==. That should half the primitives but still look the same.

Share on FacebookTweet about this on TwitterPin on PinterestEmail this to someoneShare on LinkedInShare on Google+


  1. Hello, thank you very much for your lessons!
    Could you tell us in your lessons about render in Houdini?

  2. Thanks, really useful!
    Is there a way to animate that building up? Not just edges poping, but really drawing the connections?

    • Manuel says

      Of course. In Houdini there’s always a way. A simple hint could be to try the carve SOP on the generated geo. But before doing so you have to get rid of the duplicate connections this setup generates. This is a little more complicated. Stuff for another tutorial…

  3. Nick says

    Absolutely stunning.
    I would be very intersted in seeing how you rendered this.

    • Manuel says

      Thank you. I created geometry in Houdini with the polywire node and exported to C4D/Octane for rendering. As neither C4D, nor Octane support per point colors or Cd I used a trick. I mapped the uvs of the geo to the range 0 to 1 in x and used this value to drive an Octane gradient for the colors. Worked quite well.

      • Ewan says

        I tried creating a digital asset but when I try and open it in C4D I don’t see anything. Any advice?

        • Ewan says

          I managed to get it to show up only after putting it through a wireframe node which makes the viewport very laggy so if there is a more efficient way of doing it I would love to know! Thanks for the tutorial, sorry if this question is obvious as I am new to Houdini.

        • Manuel says

          The houdini engine in C4D does not support spines aka polylines.

  4. Bruno says

    Thank you so much ! I am a beginner in Houdini and those tutorials are really usefull.

    Cheers from Brazil.

  5. Oscar says

    Thank you very much
    Hoidini does not load my files .stl and .obj someone knows for that?

  6. Christian M. Enger says

    After completely reacreating this step by step, with several input models, The point wrangle node is not generating any lines. No errors, but no result.
    Using Houdini Apprentice non-commercial 15.5.48

  7. pbd says

    To kill the original scattered points use:

    if(pnt >= @ptnum){..}

    I’d be interested in the setup that remove duplicate connections though, any hint?

    • Manuel says

      A general solution to remove duplicate lines (although it can be achieved easier in this particular setup by using a >= comparison) is to sort the points of every prim by their index and write this to a string attribute. Then use findattribval() to get the duplicates and remove them with removeprim(). You can get inspiration regarding the technique by inspecting the contents of the connectadjacentpices HDA.

  8. Jelle says

    Thank you kindly, i learn so much from you guys.
    I think the code can make a small optimization by moving the
    “int line = addprim(0,”polyline”);” outside of the foreach loop (just below the nearpts array declaration).

    I tested it and it works, i think its not needed to create this line over and over again. Then again i could be horribly wrong and missing something, please let me know if i am.

    All the best!


  9. Lauren says

    Thanks! I finished this in a cafe today. I found your explanation of the code easy to understand. I’ll have to review a lot in order to retain it. Looking forward to trying another one of your tutorials tomorrow.

  10. Gregor says

    Thank you for this great tutorial,
    I started houdini 1 month ago and at first, i have to say, it twisted my mind 🙂
    your tutorials are great ressources for a beginner like me.
    but i have a newbie question about it :
    how to render polylines with ramp’s colors with mantra ?

    • Manuel says

      Put a color (Cd) on the points in SOPs and import it to your shader using a bind node. Then you can use it as diffuse color. The shader will happily interpolate between the point colors and give you a gradient.

  11. Moritz says

    Tank you for your tutorials guys.

    Do you have an Idea how I can Create polys instead of a line with the same affect ( nearpoints) my mesh looks really messed up if i change from ‘polyline’ to ‘poly’ and I have no Idea why

    • Manuel says

      It’s not straightforward to do so. To form a polygon you need at least 3 points. Of course you can gather 3 points (e.g. by using the second closest point) and create a polygon from them, but if this gives something useful is not necessarily the case.

  12. Bella says

    it crashes after line

    int prim = addprim(0, “poly”);

    immediately in version 16

    • Manuel says

      it should read int prim = addprim(0, “polyline”); You are not gathering enough info to create a polygon.

  13. Marcus says

    Thanks for the tutorial. Very informative.
    I’ve tried it step by step but for some reason the lines do not show up on the bottom AttributeWrangle. The points simply remain as they are. Here’s the code:

    float searchrad = ch(“searchrad”);

    int nearpnts[] = nearpoints(0, @P, searchrad);
    int line = addprim(0, “polyline”);

    foreach(int pnt; nearpnts){
    if (pnt != @ptnum){


      • Marcus says

        Hello Manuel. Thank you very much for your quick reply.
        When you mean to create the point to store in pnt, that is the information going from the scatter node into the first input of the wrangleNode, correct?
        It is placed in the nearpnts[] array and then the foreach loop iterates through each point.

        I’ve repeated it a few times with both pointwrangle and attribwrangle (I believe they’re the same node), and used the very first example you set, and unfortunately still nothing:

        int nearpnts[] = nearpoints(0, @P, 0.01);
        foreach(int pnt; nearpnts){
        int line = addprim(0, “polyline”);

        I’m using H16.0.633
        Thank you.

        • Manuel says

          Hard to tell what’s wrong. Can you send me your scene file?

        • BlackPineapple says

          Try increasing the search radius so that the points get added to the nearpnts[] array. If you are using a large model a small radius won’t connect any points.

  14. BoredEngineer says

    This tutorial is gone from the list under “tutorials” section. Can access it only by direct link.

    • Manuel says

      Strange. I can access it from the “Tutorials” section.

  15. Jorge Medina says

    Hi Manuel!
    First, thanks for the tutorial.
    I was playing around with this exercise but I would like to go a little bit further and would like to scatter the points over an animated surface.
    I was changing some attributes values in the scatter node but didn’t find the way to keep the position of the points over the surface.
    I am using an alembic file but could not find the way to avoid randomisation during the animation that makes several point give a flickering effect.

    You could have a look to my first try using your tutorial:
    and the second one trying to stabilising the scatter points.

  16. Georgi Hristov says

    Might not be the most recent vid but I really liked the tutorial and I think that you explained everything just right. As a point (pun intended) of reference I am not an intermediate user but i do understand a bit of vex.

  17. Patrick Krebs says

    Thank you this is an amazing tutorial.
    If I might ask a question. Using this technique in an animation has the points and lines calculate per turn.
    How would you freeze the calculation so it isn’t dynamically generating the lines per frame?

    Thank you!

  18. dave says

    Thanks for the tutorial.

    In order to understand visualize better the variables, Is there some way to visualize them?

    (for example the nearpnts [])

    Thanks again

  19. Hello, Manuel,
    Thank you for this great tutorial, it’s a very good start. I hope to improve my skills with VEX in the future.
    Best regards,

  20. Thommas says

    Thank you for your great tutorials!
    Its posted a while ago, but the effect is timeless, so i have a question and hope you read it 🙂
    Is it possible to get the color of the UV texture map from the model to the geometry?
    I never touched houdini but i would buy a license just for that…
    Kind regards

    • Moritz says

      Hi Thommas,

      yes, that’s rather straightforward actually:
      – Transfer your UV coordinates to your points before building the connecting lines
      – Use anattribfrommap to read your texture’s color values onto the points
      that should be it 🙂

      Cheers, Mo

  21. Chaz Sutherland says

    Fantastic as usual. Entagma is easily my favorite Houdini resource. So good that anyone making a tutorial (on any subject) should study how it’s done here. Both of you are easy to understand, concise and thorough, and so friggin’ inspiring.

    On to my question tho:

    With a polyextrude to create divisions inside a font face, the aim is to take the points of each extruded division and make a unique line of each (if there’s a better way, plzzzz do tell). Then assign prim IDs to each line so I can weave from one prim line to the next (i.e. embroidery similar to your weave tut).
    I’m stuck on getting these initial lines made.
    The method shown here is based on distance so I’m getting gaps and unwanted bridging. My guess is to connect the points via point order… then of course how to avoid the end of one division/line jumping to the next division as it continues the ordering.
    Any suggestions?

Leave a Reply

Your email address will not be published. Required fields are marked *