Jump to content

How to work with variables in Houdini


Pancho

Recommended Posts

Coming from SI I'm used to set variables in ICE by set data > self.variable = value

 

Depending on the context I create the variable in it's either per point, per polygon, etc. or per object.

 

In case I need to access variables in Houdini inside a geometry from different nodes (per object in SI), how do I set this up? I know that I can acces values from a node by using ch("../node/entryField"). IS this the way to go or would I use something else do have it floating around in the geometry?

 

In my case I want something like a panel in which I can set up all values needed inside the geometry node, e.g. width, height, subdivisions of the object which gets created inside the node.

 

Which node would I use for this and which kind of referencing is best for this task?

 

Thanks for some input!

Tom

Link to comment
Share on other sites

In Houdini, self is a context and variable is an attribute. 

 

I would us an Attribute Wrangle to write VEX code to access attributes. By providing a path to the API calls you can effectively reach outside of your current context and fetch data from all over the network across context boundaries. You can add parameters/channels to the Attribute Wrangle as well. This way that node becomes your 'panel'. If you start setting up relative pathing to access channels on other nodes your panel can not be moved out of that context without addressing/breaking the references you have established.

 

For instance you can pull in the scatter count from a scatter node from any context with this code.

string scatter_path = "op:/obj/geo_target/scatter1";                                            // Path to our scatter database of attributes.
int scatter_count = npoints(scatter_path);                                                      // Number of points in the scatter.

npoints is one of the API calls I mention above.

 

Other functions:

http://www.sidefx.com/docs/houdini15.0/expressions/_index

Edited by Atom
Link to comment
Share on other sites

Not sure if I totally get you.

 

E.g., I need this width parameter for the geometry. I want a "central" node in which I can write the value (attribute wrangle?). Then this value is needed in a transform node (x-offset) and an attribute vop (import with bind?).

 

Looking at the attribute wrangle node I typed in

 

float width = 0.25 (run over set to "detail (only once)

 

In the transformation or a box node I type into a field

 

@width or $WIDTH

 

Neither works. I'm able to do quite a lot of stuff in H already, but some concepts still didn't get through to me yet.

 

In SI I use set data > self.blablabla

 

and get data > self blablabla

 

That's the way I'm thinking after years of ICE.

 

But in H it seems to be different. You propose to use the attWrangle as the get or set node? From the code it looks like it is a get node, but I need the value in an entry field of the node as described above. So I still need some info.

 

Thanks so far!

Link to comment
Share on other sites

Ive attached a file which is the simplest version of what you describe. 

 

Dive inside the Box1 node. In there is a box node and a null node. Ive changed the name of the null to CTRL and colored it red.

 

I added 3 extra parameters to the null node called width, height and depth. You can add these by clicking the gear icon at the top right of the parameter pane.

 

I then reference these parameters in the box1 node with a ch expression which points to that data on the CTRL node. The expression looks like this for width ch("../CTRL/width)

 

There's many ways to do this. Pulling data from different parts of a network, and between contexts is one of the trickier things in Houdini when starting out.

 

Is this what you are asking? Or did you want something more complex?

using_null_parms.hip

Link to comment
Share on other sites

This syntax creates a variable that is local in scope and can not be referenced outside the wrangle.

float width = 0.25;

This syntax will create an attribute on the current geometry within the context that the wrangle is running over (i.e. point, primitive, detail etc...)

f@width = 0.25;

You can just add parameters, which are not attributes, to a NULL and then reference them via ch("../my_watever"). But in some cases you can't write to them from VEX, they are read-only but animatable.

Edited by Atom
Link to comment
Share on other sites

Thanks to you both. Will take a closer look tomorrow.

 

Just in general, from what I'm feeling, I'd like to have a box floating around. The box is named width. Inside this box is a value. 0.25.

 

So, now everybody who want to know what inside this box can look inside of it and can get this value. I don't care if this is a particle, point, polygon, primitive, vop, ..... who wants to do this. This value, in my eyes, doesn't have a context. It's just a floating point scalar value.

 

Now, there's the reality of H and it's hard to tell if you are new to something how it is actually done.

 

Guessing from Richards post I need to know that this value is inside a box (or null or other node). So everytime I want to know this value I need to look inside the box, reference it by name. I thought that this value could be floating around in the ether and I just need to call "width" and the echo will be "0.25". The value would be penetrating all regions inside of Houdini, like a global variable. Not sure if this is a good way  in terms of programming, but it sounds comfortable.

 

Where I'm struggling currently is to grasp the concept of data exchange inside of H and how to do it practically. I'll try out both tips as soon as my work horse is powered on and let you know how far I'm getting. Thanks so much so far!

Link to comment
Share on other sites

I don't think you can make a variable global like you want.

 

Its not too bad though, I like having my `global` variables stored in as parameters on a node as you end up with a big controller node at the end of a project from where you can set everything. It ends up with you being very organised as your network gets bigger.

 

You can make the NULL node at obj level also, and just reference from there. Thats handy for parameters you want to use alot, like a global random seed for example. The paths end up getting pretty long though.

Link to comment
Share on other sites

Just go to Edit->Aliases/Variables->Variables tab

Enter the name of your variable, enter the value, say name foo value 0.25

And in any context you should be able to access that variable on a global level as a $FOO. it will always return 0.25.

Its an ok thing to do however you usually want to make your assets or setups know about these variables from the parent node containing the setup, rather than the Global Alias/Variable.

Its going to be very difficult keeping track of all of those global constants you have and you dont have an easy enough access for a typical user to change the value.

Link to comment
Share on other sites

Just go to Edit->Aliases/Variables->Variables tab

Enter the name of your variable, enter the value, say name foo value 0.25

And in any context you should be able to access that variable on a global level as a $FOO. it will always return 0.25.

Its an ok thing to do however you usually want to make your assets or setups know about these variables from the parent node containing the setup, rather than the Global Alias/Variable.

Its going to be very difficult keeping track of all of those global constants you have and you dont have an easy enough access for a typical user to change the value.

 

I would say that this technique is best used for things like project wide texture paths or variables relevant to your system, and not project specific data like the width/height of a box or the pscalevalue of a point set. 

Edited by LukeLetellier
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...