Jump to content

How to access point variables in VEX operators?


Recommended Posts

Suppose you have a VEX SOP like Mountain SOP. How would you access point variables like $PT, etc?

I noticed it doesn't recognize them. So you can't even use the point expression. Are they not supported in VEX SOPs?

Why aren't point variables not allowed since it makes sense to have them in VEX SOPs that are point based?

Am I missing something? Sure you can dip into VOPs and do it there but that defeats the purpose of having a VEX SOP in the first place.

Thanks :)

Link to comment
Share on other sites

Sorry I meant doing something like this. Say in the Mountain SOP, specify the height as $PT or some other point attribute. Either via the $ sign or the point expression.

But I want to differ the value as a user, just like I can in the Point SOP.

I thought I could do the same in VEX SOPs since they also act like the Point SOP.

Link to comment
Share on other sites

Guest mantragora

I think he's specifically asking about the mountain SOP!

Yes, I know. Mountain SOP is just pure VEX. You can edit its VEX code. It's the same like you would made your own New Operator Type and put all that code inside it. You just get the same Mountain SOP. It is not operator like other compiled SOPs.

Link to comment
Share on other sites

No I meant for any VEX SOP. To be able to use values that varies per point. So for any numerical parameter, I want to be able to vary them using point attributes, or even just point numbers.

Due to the nature of VEX, all point variables/attributes and the point expressions could easily be added for support, right? Something all VEX SOPs could inherit.

For instance I have some VEX SOPs that are useful to me, but without this variation, I have to do the same effect in VOPs.

Link to comment
Share on other sites

You can also use a parameterVOP to get data from geometry. if the attribute exist it gets imported from the geometry if not it is pulled from the parameter.

for example if you want to drive the height of the mountain sop with a $ variable just put a attributeSOP in front of it createing that height attibute and drive it with $, but I'm quite sure rebuilding that expression in vex will result in much faster networks

Edited by sanostol
  • Like 1
Link to comment
Share on other sites

No I meant for any VEX SOP. To be able to use values that varies per point. So for any numerical parameter, I want to be able to vary them using point attributes, or even just point numbers.

Due to the nature of VEX, all point variables/attributes and the point expressions could easily be added for support, right? Something all VEX SOPs could inherit.

For instance I have some VEX SOPs that are useful to me, but without this variation, I have to do the same effect in VOPs.

I'm a bit confused, but all I know is that, if you do it through vex code, (which your vex SOPs are probably made that way) you should have access to point attribs, and if you're using a VOP SOP(which is pretty much a gui for vex code) you have point number already in your inputs, and you can import any other attribute with import attrib!

Link to comment
Share on other sites

Guest mantragora

No I meant for any VEX SOP. To be able to use values that varies per point. So for any numerical parameter, I want to be able to vary them using point attributes, or even just point numbers.

Due to the nature of VEX, all point variables/attributes and the point expressions could easily be added for support, right? Something all VEX SOPs could inherit.

For instance I have some VEX SOPs that are useful to me, but without this variation, I have to do the same effect in VOPs.

In that case just add importVOP or code to pull up attribute and do your operation with in in your code. To allow customization of this thru the UI just add string parameter, so user can pick attribute name, and menu, so user can choose type (float, int, etc.). Then use those parameters to drive import()/importVOP.

Link to comment
Share on other sites

@sanostol:

Thanks, that's a great trick. I knew if I could override parameters in VOPs but not outside them to affect VEX SOPs. That's pretty neat.

But yeah mine was basically being able to do this directly inside the parameter fields of a VEX SOP, without creating an attribute to override existing ones.

Here is the pic:

TEshJ.png

@ehsan:

I know I can import anything in code, but I want the code to not care about attributes. Something like this:

sop deform(float amount = 0)
{
    P[0] += amount;
}

But on the user level, you should be able to plug any value into amount, using attributes, etc.

@mantragora:

So you mean creating a string parameter for each parameter? Basically sort of replicating an AttribCreate SOP for every parameter?

Edited by magneto
Link to comment
Share on other sites

Thanks sanostol. So you mean using a parameter vop to import some values/attributes and then refer to that parameter in any parameter inside the VEX SOP (Mountain SOP in this case)?

If so, would this be preferred to using attribute create to override the VEX SOP parameters?

Link to comment
Share on other sites

mh, maybe I do not understand what you are aiming for. I just meant that that point expression just reads in the per point values of the attribute roughness. but if this attribute exists it gets used anyway

the mountsop looks for rough, by the way by hovering the mouseover the attribute houdini will tell you the internal name. that pointexpression just takes more time, I guess. what ever You can do in vop/vexland just do it as it is incredible fast

Edited by sanostol
Link to comment
Share on other sites

Yes that's what I meant. The override method works. I was just looking for a direct way of doing this. Like if you had an attribute used for something else, that you want to use for another parameter in a VEX SOP, then you will have to create another attribute with the same name as the parameter you want to override.

Being able to use point variables/attributes and the point expression directly inside the fields is more intuitive, as you do it pretty much everywhere in Houdini.

Link to comment
Share on other sites

Thanks mantragora, nice example :)

Although this allows you to import parameters, it would clutter the UI alot if you had this for each parameter alongside actual parameters.

Another nice thing if this was supported directly in VEX parameter fields is that you wouldn't care about the value type.

  • Downvote 1
Link to comment
Share on other sites

Guest mantragora

Thanks mantragora, nice example :)

Although this allows you to import parameters, it would clutter the UI alot if you had this for each parameter alongside actual parameters.

You can make your own UI and hide one that you don't need.

Another nice thing if this was supported directly in VEX parameter fields is that you wouldn't care about the value type.

So you send attribute called MAGIC. It's a float. Your code picks it up. Now you change your attribute and make it vector. And you want to use only Y to drive your code. How your code will figure this out if you don't tell it what type of attribute it is ?

VEX is not python. It's not interpreted/dynamic language. It's staticaly typed/compiled.

Theoretically you can solve this by using arrays. From Help:

3. int import(string attrib_name; float values[] &; int input; int pt_num) 

This form lets you import attributes containing arbitrary length arrays of floats, such as capture data.

So then you don't need type menu on your UI. You just take care of casting and other things in your code:

#pragma oplabel "Magic Example"
#pragma opname "magic_example"
#pragma opmininputs 1
#pragma opmaxinputs 1

#pragma label magicname "Magic Name"

sop magic_example(string magicname = "magic")
{
    float magicvalue[] = {0.0, 0.0, 0.0};

    import(magicname, magicvalue, 0);

    if(magicname == "magicfloat") 
        P += normalize(N) * set(0, magicvalue[0]/100, 0);

    if(magicname == "magicvector") 
        P *=  (vector)magicvalue/100;
}

But this is bigger clutter in your code than it needs to be.

On the other hand you got structs now. You got also functions. You can make your onw logic to solve those type of situations and than just #include needed functions to manage convertions and returning correct values from attributes.

Edited by mantragora
  • Like 1
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...