Jump to content

Understanding VEX command in docs


Arthur Spooner

Recommended Posts

I'm going though some VEX function commands to understand, and I'm having a little difficulty understanding for example addprim. What I have thus far,

 

v@gm = addprim();

 

The docs state int, is this a hard and fast rule if the docs state an integer I shouldn't be making a vector variable, rather a integer variable ? 

 

 

Adds a primitive to the geometry.

 
  • int addprim(int geohandle, string type)

Creates a primitive in the geometry specified by geohandle. The returned value is a primitive number that can be used with the setprimattrib to change the value of the primitive, but is not the final primitive number of the primitive.

Types can be:

poly: Closed polygon.

polyline: Open polygon.

 

 

Another command is neighbors, which returns an array of the point numbers of the neighbors of a point. Once again the docs state, integer with an empty array followed by int input, int ptnum, what must I enter for those values ? Must I select a point on the mesh ?

 

Link to comment
Share on other sites

That must be a typo, it should be int like you wrote:

i@gm = addprim(...) 
You could use a vector as all the components of the vector wuold be set to the same value when using: v@gm = addprim(...) but it would just get messy unless you need it for som especial case.

 

This is how you declare an array attribute:

i[]@mypoints = neighbours(0, @ptnum);
If you want to declare a variable, go like this:

int mypoints[] = neighbours(0, @ptnum);
The example code in the docs: http://www.sidefx.com/docs/houdini15.0/vex/functions/neighbours is not correct:

To work it needs to look something like this:

int input = 0; //Just passing in some values for testing. 0 is the first input of the Wrangle node.
int ptnum = 20; //Just passing in some values for testing

int myarray[] = neighbours(input, ptnum);
int i, n;
int result[];
n = neighbourcount(input, ptnum);
resize(result, n);
for (i = 0; i < n; i++) {
    result[i] = neighbour(input, ptnum, i);
}

i[]@test = myarray; // Set Geo Spreadsheet to Detail to see the members of the array
 

Put down a Grid and an Attribute Wrangle set to Detail to test. Change "ptnum" to set a different point.

Hope this answers your questions.

 

Cheers

Bonsak

Edited by bonsak
Link to comment
Share on other sites

That must be a typo, it should be int like you wrote:

i@gm = addprim(...) 
You could use a vector as all the components of the vector wuold be set to the same value when using: v@gm = addprim(...) but it would just get messy unless you need it for som especial case.

 

This is how you declare an array attribute:

i[]@mypoints = neighbours(0, @ptnum);
If you want to declare a variable, go like this:

int mypoints[] = neighbours(0, @ptnum);
The example code in the docs: http://www.sidefx.com/docs/houdini15.0/vex/functions/neighbours is not correct:

To work it needs to look something like this:

int input = 0; //Just passing in some values for testing. 0 is the first input of the Wrangle node.
int ptnum = 20; //Just passing in some values for testing

int myarray[] = neighbours(input, ptnum);
int i, n;
int result[];
n = neighbourcount(input, ptnum);
resize(result, n);
for (i = 0; i < n; i++) {
    result[i] = neighbour(input, ptnum, i);
}

i[]@test = myarray; // Set Geo Spreadsheet to Detail to see the members of the array
 

Put down a Grid and an Attribute Wrangle set to Detail to test. Change "ptnum" to set a different point.

Hope this answers your questions.

 

Cheers

Bonsak

 

 

 

 

 

 

That must be a typo, it should be int like you wrote:

i@gm = addprim(...) 

 

 

How do I use addprim ? The docs state it createa a primitive in the geometry specified by geohandle ?

 

This is how you declare an array attribute:

i[]@mypoints = neighbours(0, @ptnum);

 

 

The above code is starting from the first point then giving each point an id followed by storing that in an array called @mypoints ?

Edited by Arthur Spooner
Link to comment
Share on other sites

How do I use addprim ? The docs state it createa a primitive in the geometry specified by geohandle ?

Very basic example would be like this:

int prim = addprim(geoself(), "poly");

int pt1 = addpoint(geoself(), {0,0,0});
int pt2 = addpoint(geoself(), {0,0,1});
int pt3 = addpoint(geoself(), {1,0,1});
int pt4 = addpoint(geoself(), {1,0,0});

int vt1 = addvertex(geoself(), prim, pt1); // Actually no need to set the int like this, just old habbit. 
int vt2 = addvertex(geoself(), prim, pt2); 
int vt3 = addvertex(geoself(), prim, pt3);
addvertex(geoself(), prim, pt4); // This works as well

Put down a null inside a Geo and then attach a Attribute Wrangle set to Detail to see how it works. 

 

The above code is starting from the first point then giving each point an id followed by storing that in an array called @mypoints ?

No it's returning the neighbouring points around the point you supply in @ptnum from the geo from input 1.

 

-b

Edited by bonsak
Link to comment
Share on other sites

I created a torus, connected a null, followed by a point wrangler, inserted the code, got a plane, sounds correct ?

 

How do I know what to make a int, v etc in Houdini ?

 

Breaking this line of code down; int prim = addprim(geoself(), "poly");

 

How did you know to make prim a integer ? I'm reading over and over in the docs for Prim & addPrim & Geoself and I'm not understanding, arghhh. :angry:

Link to comment
Share on other sites

I created a torus, connected a null, followed by a point wrangler, inserted the code, got a plane, sounds correct ?

 

How do I know what to make a int, v etc in Houdini ?

 

Breaking this line of code down; int prim = addprim(geoself(), "poly");

 

How did you know to make prim a integer ? I'm reading over and over in the docs for Prim & addPrim & Geoself and I'm not understanding, arghhh. :angry:

Adding the null is only for when you want to start creating geometry from scratch. Attribute Wrangle needs an input of some sort to not error out.

 

 

 

What is cd used for the example; prim ?

I don't understand.

 

The string "poly" that we're passing to addprim() is only describing the type of poly you want to make: "poly" (closed) or "polyline" (open)

 

-b

Link to comment
Share on other sites

Adding the null is only for when you want to start creating geometry from scratch. Attribute Wrangle needs an input of some sort to not error out.

 

I don't understand.

 

The string "poly" that we're passing to addprim() is only describing the type of poly you want to make: "poly" (closed) or "polyline" (open)

 

-b

 

What is the attribute Cd ? That is what I should've asked !

Link to comment
Share on other sites

You don't add attributes to geoself(). geoself is just a function that returns a handle to the geometry being processed.

If you want to set attributes to geometry for example, try a Point Wrangle for instance. To set the color of the points you go:

@Cd = {1,0,0}; 

-b

Link to comment
Share on other sites

You don't add attributes to geoself(). geoself is just a function that returns a handle to the geometry being processed.

If you want to set attributes to geometry for example, try a Point Wrangle for instance. To set the color of the points you go:

@Cd = {1,0,0}; 

-b

 

The geometry, whether it be a sphere, or cube etc should've turned red ? 

Link to comment
Share on other sites

 

and if you're in the detail mode, you can set a point attribute like this:

setpointattrib(geoself(), "Cd", ptNum, {1,0,0})

 

You mean detail mode in Geo Spreadsheet ? :unsure:

 

What is meant by "it returns a handle" to the geometry being processed, sorry it's the terms ! :)

int prim = addprim(geoself(), "poly");

int pt1 = addpoint(geoself(), {0,0,0});
int pt2 = addpoint(geoself(), {0,0,1});
int pt3 = addpoint(geoself(), {1,0,1});
int pt4 = addpoint(geoself(), {1,0,0});

int prim is not a variable, rather the command which must be used.  

 

One imports the attribute value from geometry, in this case, it is importing an empty geohandle, then points are being creating, to create a closed polygon ?

 

0,0,0 > no points

0,0,1 > point at world z ?

1,0,1 > point at world, x & z ?

1,0,0 > point at world, x ?

Link to comment
Share on other sites

that's normal, you gotta provide it with a point number ;)

 

something like that

int npts = npoints(0);
for(int i = 0; i<npts;i++){
    setpointattrib(geoself(), "Cd", i, {1,0,0})
}

but I would recommend to do as much as possible in point/prim/vertex mode instead of in the detail mode as that last one isn't multithreaded.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...