Recast required in vex ?

   2949   9   2
User Avatar
Member
766 posts
Joined: April 2014
Offline
How can I recast a vector to a float as in this; or must I declare it as a variable then as I want use ch() to control the float time ?

@Cd = {0,0,0};
ch("ctrl",@Cd = {0,0,0};
【T】【C】【S】
User Avatar
Member
8539 posts
Joined: July 2007
Offline
while it's better to not use Cd for float values, since you can visualize any attrib in the viewport as color anyway
assuming that your color is greyscale you can use any channel you want

float value = ch("ctrl",v@Cd.x);
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
766 posts
Joined: April 2014
Offline
tamte
while it's better to not use Cd for float values, since you can visualize any attrib in the viewport as color anyway
assuming that your color is greyscale you can use any channel you want

float value = ch("ctrl",v@Cd.x);

And if it's not gray-scale ?

float value = ch("ctrl",v@Cd={});

?
【T】【C】【S】
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
Moin, Christopher,

I think your question is ambiguous - you ask about “recasting a vector to a float”, but if you want to “cast” a vector with 3 components to a float with, obviously, only one component, it is unclear which component you want to extract.
One possible interpretation of your question could be “I want to get the luminance value of a RGB color that is stored as a vector” - and for that there are various solutions, depending on color space and whitepoint.

The example you gave:
Christopher_R
@Cd = {0,0,0};
ch("ctrl",@Cd = {0,0,0};

… doesn't work in VEX: You seem to be trying to set a parameter from VEX, which - unfortunately - Houdini does not support (it's not clear what you actually want to do, since the closing “)” bracket is missing).

If you want to extract a single channel from a vector, you can access it through .x/.y/.z. I think that is what Thomas meant: If the color is grayscale, it only has one channel (the x-channel), then “casting” is simply done by accessing that single channel's x-value, which is a float (or could be an integer). If the color has more than one channel, you need to define *how* you want to “recast”, because there is no such thing as “recast a 3 component value to a 1 component value” (think of imaginary numbers, which consist of two components).

Marc
Edited by malbrecht - Feb. 13, 2017 10:32:40
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
User Avatar
Member
8539 posts
Joined: July 2007
Offline
Christopher_R
And if it's not gray-scale ?
Then it's up to you what conversion you use to get float
You can use luminance of the color for example

float value = ch("ctrl", luminance(v@Cd));
Edited by tamte - Feb. 13, 2017 11:47:48
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
8539 posts
Joined: July 2007
Offline
I guess you have to explain it better,
what do you exactly want to do? The code just makes it confusing as it doesn't really make sense

EDIT: please don't remove posts
Edited by tamte - Feb. 14, 2017 11:09:44
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
I agree with Thomas, the code snippet you posted makes it way harder to grasp what you want to do. Maybe a screenshot of your desired result, with some scribbling, would help. Or if you can write your code in any other programming language (JS, Java, C, C++, Python, Perl, PHP, Basic, Fortran, Pascal, Logo - we figure it out, just let it make sense, as Thomas puts it).

*If* you should mean “how can I adjust the color by three separate floating point sliders”, then you could do something like this:

v@Cd.r=chf("path-to-r"); v@Cd.g=chf("path-to-g"); v@Cd.b=chf("path-to-b");

Marc
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
User Avatar
Member
766 posts
Joined: April 2014
Offline
I solved it, I had to put a lerp() within a ch() function in a condition
【T】【C】【S】
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
Cool - but what has “lerp” to do with “casting a vector to a float”?

(confused)

Marc
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
User Avatar
Member
766 posts
Joined: April 2014
Offline
malbrecht
Cool - but what has “lerp” to do with “casting a vector to a float”?

(confused)

Marc

Nothing, I was confusing with a VOP node at the time, sorry
【T】【C】【S】
  • Quick Links