That's right people it's time to actually make a thing that does some stuff!
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:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// generate colour cube based on grid position
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int i, j, k, id = 0; // declare iteration variables
vector grid_size = chv("grid_size"); // reference node paramaeters and cast them as variables
vector grid_res = chv("grid_res"); //
vector iter_values = grid_size * grid_res + 1; // work out iteration stop condition values
for(i=0; i<iter_values[0]; i++){ // create 3 nested for loops to generate x,y,z position data.
for(j=0; j<iter_values[1]; j++){ // use seperate iterators for each loop to keep x,y,z values seperate
for(k=0; k<iter_values[2]; k++){
vector pos = set(i/grid_res[0], j/grid_res[1], k/grid_res[2]);
// use i,j,k iteration variables to set generate a position vector per iteration
addpoint(0, pos * chf("global_scale")); // add new point for each iteration
addpointattrib(0, "Cd", set(1,0,0)); // add colour attribute
setpointattrib(0, "Cd", id, pos / grid_size); // set colour attribute based on position
addprim(0, "sphere", id); // add prim for each point
matrix3 trans = ident(); // generate identity matrix
setprimintrinsic(0, "transform", id, trans * ch("prim_scale"));
// use setprimintrinsic to scale the prim
id += 1; // use id variable to count iterations
}
}
}
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!
Comentarios