Jump to content

Is there a way to concatenate parameter tokens in VOPs?


Recommended Posts

I have a few parameters in one of my VOPs, and I want to combine their tokens like this:

$parameter1 + $parameter2 + $parameter3

where it could be:

Deform + Surface + Fast =

DeformSurfaceFast

I know I can do this with a single parameter where I can call it as a function, but I am wondering if it's possible to do with multiple parameters to form a function name that exists?

Thanks :)

Link to comment
Share on other sites

Guest mantragora

So basically you want to change concatenated tokens into function name just like you can in C# with reflection and dynamic method invocation ? In that case, you can't.

You still seems to think about VEX like if it was dynamic language. It's not. Stick with thinking about everything in it in like if it was "0-1". For dynamic things you have Python. If you need more than python can give you, you can use inlineCPP in it. If it's still not what you are looking for, you got HDK. End of story.

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

Guest mantragora

Anyway, if you are looking for simple concatination - not dynamic method invocation , for example - your menus returns strings as tokens, you can just concatinate them like any string with

string text = $menu1 + $menu2 + $menu3;

This will give you "DeformSurfaceFast" and then you can compare this string with if{}else{}whatever{} to call your function based on this.

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

Yes that's what I wanted. I thought it might allow that because just using the variable name actually allows you to call a function using its string token. So thought perhaps it would also allow combining them.

Otherwise, I will have to code a large if else statements and call a different function based on the menu choices.

Link to comment
Share on other sites

Guest mantragora

Dynamic method invocation is slow. VEX is made to be fast. It was thought as a shading language. You don't have dynamic calls in any other shading languages too. They must throw data from one end to other as fast as they can. All this sugar code is nice, but it is always slow.

  • Like 1
Link to comment
Share on other sites

I also wonder if having if statements before the function call would be slow for VEX?

I don't mean inside the function itself but before it's decided which function to call.

Say you have 2 parameters, each have 3 options, so have 9 functions. If inside the VOP you have:

if ($option1 == 0 && $option2 == 0)
    function00();
...
if ($option1 == 2 && $option2 == 2)
    function22();

I wonder if this code is called for each point or only once? I assume only once because options don't change for each iteration.

But actual if statements inside VEX is something I avoid.

Edited by magneto
Link to comment
Share on other sites

Guest mantragora

As long as you don't force for each point yourself, it will call it once for all points. That's what SIMD is for.

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

  • 1 month later...

as far as I know functions (as well as all code in VEX) are run once per each point, not once per all points

in VEX (SIMD) they can run parallel, but still per each point, therefore you can have different result for each point

I never had performance problems with if statements within VEX, on the other hand they can speed up a lot, because it can decide for each point what to compute and what not, so I would not fear to use them

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