• Matt Norris

Introduction to VEX part 4 (time to write a flipping wrangle!!!)

Updated: Feb 25, 2020

That's right people it's time to actually make a thing that does some stuff!

download the .hip file here

I want to keep it simple for this first example, so I'm going to make a colour visualisation cube.

To be honest this doesn't really have much practical use, it's more about putting into practice some of the techniques mentioned in the previous post, so it will include:

-iterations (for loops)

-channel referencing

-creating geometry

-creating and setting geometry level attributes.

So without any further ado here's the code (screen grab so you can see the formatting)

And here's the code in a copy paste friendly format, including comments:

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  2. // generate colour cube based on grid position

  3. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  4. int i, j, k, id = 0; // declare iteration variables

  5. vector grid_size = chv("grid_size"); // reference node paramaeters and cast them as variables

  6. vector grid_res = chv("grid_res"); //

  7. vector iter_values = grid_size * grid_res + 1; // work out iteration stop condition values

  8. for(i=0; i<iter_values[0]; i++){ // create 3 nested for loops to generate x,y,z position data.

  9. for(j=0; j<iter_values[1]; j++){ // use seperate iterators for each loop to keep x,y,z values seperate

  10. for(k=0; k<iter_values[2]; k++){

  11. vector pos = set(i/grid_res[0], j/grid_res[1], k/grid_res[2]);

  12. // use i,j,k iteration variables to set generate a position vector per iteration

  13. addpoint(0, pos * chf("global_scale")); // add new point for each iteration

  14. addpointattrib(0, "Cd", set(1,0,0)); // add colour attribute

  15. setpointattrib(0, "Cd", id, pos / grid_size); // set colour attribute based on position

  16. addprim(0, "sphere", id); // add prim for each point

  17. matrix3 trans = ident(); // generate identity matrix

  18. setprimintrinsic(0, "transform", id, trans * ch("prim_scale"));

  19. // use setprimintrinsic to scale the prim

  20. id += 1; // use id variable to count iterations

  21. }

  22. }

  23. }

That's basically it, although a few points to mention, I'm creating this as a fully stand alone node, so it doesn't require any inputs. I'm running over the detail, which makes a lot of sense as I have no points or prims coming in to loop through.

And finally I'm actually referencing parameters directly in my code without having to manually open the parameter interface editor. This makes it very quick to build in simple parameters to your wrangle nodes directly from the "snippet" window, however you have to make sure to hit the "create spare parameters" button on the right hand side of the snippet otherwise every variable that is referencing an un-built parameter will get set to zero.

Alright, we made it! thanks again for checking out my blog, it's still very early days but I hope to keep adding to this regularly, please feel free to comment, I'm open to all questions, suggestions and requests (within reason and legality).

And remember, don't get mad, get vexed!

download the .hip file here

94 views0 comments

Recent Posts

See All