Creating Geometry with VEX

   8826   7   0
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Hi,

I was going through the tutorial by Manuel C. Merkle on Creating Geometry with VEX.

I hope someone might be able to shed light on working with VEX in the way I wish to utilize it.

In doing the tutorial I realized it was getting close to showing how to do something I've been wanting to work on.

In one of the first examples he creates a simple primitive from “coded” points.

What I've been wanting to is something similar with the exception of mixing part coded points ( user defined ) combined with existing geometry points.

Below is the code that has been slightly modified ( the 2 point functions replacing the two addpoint functions that is in the video:

int newpoint0 = addpoint( 0, { 10, 8, 0 });
int newpoint1 = addpoint( 0, { 14, 8, 0 });
int newpoint2 = point( 0, "P", 9);
int newpoint3 = point( 0, "P", 5);
int prim0 = addprim(0, "poly" );
int vertex0 = addvertex( 0, prim0, newpoint0 ); 
int vertex1 = addvertex( 0, prim0, newpoint1 ); 
int vertex2 = addvertex( 0, prim0, newpoint2 ); 
int vertex3 = addvertex( 0, prim0, newpoint3 );

However, this code does not work completely.

I don't get errors in the code but only the addpoint functions work as expected.

The “point numbers” references( 9 on one line and the 5 on the next ) don't work as expected ( they don't correspond to the point numbers from the group node. )

Also, since the example in the help files shows the function returning a vector I tried the following thinking there are 3 values being x,y and z and trying to get the x value. But this doesn't work either.

vector pre_newpoint2 = point( 0, "P", 9);
vector pre_newpoint3 = point( 0, "P", 5);
int newpoint2 = pre_newpoint2[0];
int newpoint3 = pre_newpoint3[0];

I've also tried the getattribute function as well with similar undesired results. ( I'm wanting to make a copy of those points from the original geometry so that I make a second geometry object where some of the points of that second geometry still follow/correspond to the original geometry points, but that is another topic. I mention this because there seems to be a getattr function as well.

Any help on this is much appreciated.
Edited by BabaJ - July 24, 2016 08:34:26

Attachments:
test vex point sharing.hiplc (281.1 KB)

User Avatar
Member
2536 posts
Joined: June 2008
Offline
I am not exactly sure what you are trying to accomplish but here are a couple of pointers. Notice that your VEX code is running over points. When creating geometry you really want to run over Detail (run once). If you examine the point count before and after the VEX code you will see you start off with around 121 points but end up with over 300. This is because the VEX code is running the same process for every point.

You can filter by group but sometimes it is clearer to simply fetch from another input socket of the node. @OpInput does just that. But why fetch the point attribute at all? We know that addvertex requires an index, not a coordinate. So you can use the 9 and 5 directly in the add vertex function. Also the order in which you add the vertex is important and should be in a clockwise pattern to avoid creating faces that cross over one another.

Attachments:
Untitled-1.jpg (148.5 KB)
ap_test_vex_point_sharing.hiplc (270.5 KB)

Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Hi Enivob,

Thanks very much for that reply…I got the next step of what I wanted to do by incorporating elements of what you said.

The file I'm including has the working code that can be run and gives an idea of what I am working towards.

I was able to calculate the middle point of the indexes and use that instead of having to specify the specific point number. This now will be handy if I want to change the number of points. This way I will be able to keep the middle point or whatever other script I run that determines which points to use.

The next step I am trying to do is take that point reference and do some math on it for a new plotted location ( in reference to it's original location and as a new point…some possible applications could be using trigonmetric functions for example).

I think my inexperience with VEX code is preventing me from dealing with the vector information of these points in order to manipulate and change them.

In the file I've commented out the version of code that does not work but as the next step want to work towards.

I'll just paste that here too:


int size = npoints(@OpInput1);
int my_center = size/2;

vector new_location = point(@OpInput1, "P", my_center);
my_location[0] += 5;

// Add new points.
int newpoint0 = addpoint( 0, { 40, 25, 0 } );
int newpoint1 = addpoint( 0, new_location );


// Add new primitive.
int prim0 = addprim(0, "poly" );

// Connect the points.
int vertex2 = addvertex( 0, prim0, my_center );
int vertex0 = addvertex( 0, prim0, newpoint0 );
int vertex1 = addvertex( 0, prim0, newpoint1 );
int vertex3 = addvertex( 0, prim0, 0 );

I have been going through the different tutorials and help files to try and gleen how to do it, but so far I haven't had any luck in coming across the info that appears to me to be the answer.

So any help is much appreciated.
Edited by BabaJ - July 24, 2016 15:28:02

Attachments:
test vex point sharing v2.hiplc (298.2 KB)

User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Going through cgwiki on HoudiniVex I came across this example that I thought I would try:

Attributes vs variables

The examples given above all use the @ syntax to get and set attributes on points. If you have more than a few wrangles, or if you don't need those attributes outside the wrangle, the geometry spreadsheet starts getting very messy, and all that extra point data takes up memory, especially if you have complex scenes.

Instead, you can create variables that only exist within the wrangle. The syntax is similar to other c-style languages; define the type with a full word, and don't use a prefix on the variable:

float foo;
vector bar = {0,0,0};
matrix m;

foo = 8;
bar.x += foo;

base on that example I replaced the following of my code:

vector new_location = point(@OpInput1, "P", my_center);
my_location[0] += 5;

with code that follows the example, with:

vector new_location = point(@OpInput1, "P", my_center);
float my_var;
my_var = 5;
my_location.x += my_var;

But I get an error message from Houdini. It doesn't seem to like that I am using “.x” to try and access that part of the vector. ( Error message in part “…Invalid subscript for type: void.x…”

So I'm guessing the point function isn't really returning a vector? or maybe it's a different kind of vector?

Maybe I should be using a different function or do an additional step on the variable “my_location” before accessing the x, y, or z component?






User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
This is really odd but it works now.

I re-read the cgwiki article. And it says not to use a prefix on the variable.

As soon as I changed my variable name of “my_location” to “location” the code now works.

I guess underscores in VEX changes things when it comes to variables?
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Ok…changed my variable back to the original name ( including the underscore ).

And it works too.

I think sometimes when you get an error message it can be a little stubborn in getting reset even if your code is correct.

I've noticed that already in other cases by having to do things like disconnect and reconnect my nodes to get it working again after the code is corrected.

Normally clicking on the node itself or a blank spot on the network window is enough, but not always.
User Avatar
Member
2536 posts
Joined: June 2008
Offline
Well it was reporting void.x because my_location, as a variable, does not exist. You my have intended to reference new_location.x instead?
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Guilty!…becoming so myopic when trying to figure stuff out…can't see the obvious in front of me.

Thanks for point that out
  • Quick Links