Calculated Attributes Values via Attribute Wrangle

   2213   4   1
User Avatar
Member
5 posts
Joined: June 2022
Offline
I'm trying to affect the pscaleattribute by assigning a calculated value of @ptnum / @numptand can't understand why it won't work. I have tried several approaches, some of which work and some of which do not. I don't know why they don't all work.

What Works

Setup:
Line SOP set to pointstype.

The Points feed into an attribute createSOP, where I add an attribute named xand assign the value as @ptnum / @numpt.

Then, I create an Attribute WrangleSOP and add the following VEX:

@pscale = @x

Works fine -- pscaleis set as expected.

What Doesn't Work

If I use the same points and only the Attribute Wrangle SOP, and enter the following VEX:

@pscale = @ptnum / @numpt;

The pscalevalue is assigned 0.0 every time, for every point.

What strikes me as even stranger is that I can do something like:

@c = @ptnum;
@d = @numpt;

And see that the cand dattributes get added with non-zero values.

The attached file has both setups preceding a copy to points node.
Edited by alphazwest - July 10, 2022 16:41:32

Attachments:
attribute_transfers.hiplc (86.1 KB)

User Avatar
Member
1853 posts
Joined: May 2006
Online
Most programming languages if asked to divide an integer by an integer, will return an integer. That's what's happening here when you run @ptnum/@numpt.

To fix this, you need to convert the first number (or both numbers) to floats. Vex will define new attributes as floats if you don't specify a type, that's what happening when you type @c = @ptnum.

To do this without using 'burner' attributes, use a cast:

@pscale = float(@ptnum)/@numpt;

For completeness, you can get similar results without vex either with a uvtexture sop in points mode and the method of 'arc length spline', or with a resample sop with 'curve u attribute' enabled.
Edited by mestela - July 10, 2022 16:52:40
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
5 posts
Joined: June 2022
Offline
I guess I'm so used to linters and compilers holding my hand too much!

Thanks for the help, works like a charm now.

As an aside, it seems Houdini expects all attributes to be of type float-- is that correct?

e.g. if I set @c = 1I notice it shows as 1.0in the spreadsheet.
User Avatar
Member
1853 posts
Joined: May 2006
Online
It assumes for float, yes, except for a handful of known predefined special attributes like Cd, name, uv, orient etc
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
9380 posts
Joined: July 2007
Offline
Chances are that you want to do ptnum / (numpt - 1) to get values in full 0-1 range, in which case you can force float evaluation of the whole equation by typing 1 as float 1.0:
@pscale = @ptnum / (@numpt - 1.0);

alphazwest
As an aside, it seems Houdini expects all attributes to be of type float-- is that correct?

e.g. if I set @c = 1I notice it shows as 1.0 in the spreadsheet.
You can tell Houdini you want to create integer attribute by i prefix
i@c = 1;
Edited by tamte - July 11, 2022 00:48:05
Tomas Slancik
CG Supervisor
Framestore, NY
  • Quick Links