Jump to content

Understanding VEX command in docs


Arthur Spooner

Recommended Posts

If you want to use setattrib you need to use addattrib first if the attribute is not present on the geo.

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

Faster to do like this:

int npts = npoints(0);
i@debug = npts;
for( int i = 0; i<npts; i++ ){
    @Cd = {1,0,0};
}

-b

Link to comment
Share on other sites

Where can I find in the Houdini docs what the definition of npoints and npts is ?

 

I still don't understand geoself() & geoself handle ?  :unsure:

int npts = npoints(0);
i@debug = npts;
for( int i = 0; i<npts; i++ ){
@Cd = {1,0,0};
}

Should the above code do something to a plane, torus or sphere ? Or is it strictly debugging, if it's strictly debugging, is there an debugging window in Houdini ? :)

Link to comment
Share on other sites

based on your questions, I would highly recommend you to spend some time reading a little about coding, getting an introduction to it.

you can read one here

http://codingintro.com/chapter/en/1/introduction

 

npts is just a random name I have chosen to use as a variable that will contain the results of the npoints() function.

regarding geoself(), it points your function toward the geometry of the current node you're in.

 

regarding your code, it would just set the Cd detail attribute npts times if you are in Detail mode. if you would run that in a point mode, the only part of your code you would need to set your Cd point attribute is

@Cd = {1,0,0};

It's great you start to learn vex, but once again, spend time to understand the basics of programming, it will save you a lot of time. vex is using a similar syntax to any C language.

Link to comment
Share on other sites

I searched the VEX functions dictionary, if I didn't find it in the VEX index dictionary, I should have known it was a variable, but I decided for clarification to ask :)

 

regarding geoself(), it points your function toward the geometry of the current node you're in.

 

 

In other words it points a function to the parent element; whatever the geometry is as the parent of the pointWrangler ?

 

regarding your code, it would just set the Cd detail attribute npts times if you are in Detail mode. if you would run that in a point mode, the only part of your code you would need to set your Cd point attribute is

 

 

When running the code in detail mode on a torus in pointWrangler, should I expect to see something in the viewport ?

Link to comment
Share on other sites

if you run your, no

with mine, if you already have a Cd attribute on your input geo, then it will turn red.

the setpointattrib works only on existing attributes.

if the Cd attribute is missing, you can add this at the top of your code

addpointattrib(geoself(), "Cd", {1,1,1});

the {1,1,1} represents the default value for the attribute you just added to your points.

it also defines the attribute type: float, int. vector etc...

Link to comment
Share on other sites

your code:

int npts = npoints(0);
i@debug = npts;
for( int i = 0; i<npts; i++ ){
@Cd = {1,0,0};
}

you will not see anything different in the viewport

 

with my code example:

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

If the Cd attribute doesn't exist on your geometry before the wrangle sop, you won't see anything in the viewport. If it exist (like if you have a Color sop before the wrangle) it will change the points color to red

 

If you don't have the Cd attribute and want to add in your wrangle, your code should look like this:

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

Link to comment
Share on other sites

Returns the number of points in the input specified, or 0 if there is no input connected.

 

 

How do you specify an input for the npoints function ?

 

How do you have a color SOP before the wrangler ? 

 

I still don't understand what is geohandler, reading what specific VEX functions can do, as helped me understand what is posted.   :unsure:

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...