Jump to content
vtrvtr

VEX vs Python?

Recommended Posts

Hello.

I have a couple questions. Sorry if this isn't the correct section.
 

I'm learning Houdini and although I have some experience with C, I have much more experience with Python, so I figured I would use Python instead of VEX for most things. So question one is:
 

Is that feasible? From what I could gather you can write everything using the python library, but I'm not sure if this is correct. Is there something that python wouldn't be able or wouldn't be a smart way to do?

The second question is: what would be the recommended way to translate VEX expressions to python? Pretty much all tutorials I ever saw used VEX/hscript, so I usually have to translate, which I don't mind in the slightest,
but sometimes is hard to find what are exactly the equivalents.

For example, right now I'm trying to copy one attribute to a newly created one using a wrangler, which in VEX goes simply as

f@new_p = @old_p

But I'm not sure how would it go with python
 

Thanks

Edited by vtrvtr

Share this post


Link to post
Share on other sites
28 minutes ago, vtrvtr said:

I'm learning Houdini and although I have some experience with C, I have much more experience with Python, so I figured I would use Python instead of VEX for most things. So question one is:

Is that feasible? (...)

It is not. 

95% of cases when you want to process geometry, it is a job for VEX. Changing attributes' values, adding points, prims, manipulating vectors, etc. VEX is very well shaped to process heavy data,  forcing Python for doing this is ultimately waste of time. Using Python for a job will require learning Python->Houdini interaction anyway, which is pretty much the same as learning VEX from scratch - it is really very simple language. 

Both Python and VEX have their own place in Houdini, you can't escape from neither of them :) .

 

  • Like 2

Share this post


Link to post
Share on other sites
6 minutes ago, symek said:

It is not. 

95% of cases when you want to process geometry, it is a job for VEX. Changing attributes' values, adding points, prims, manipulating vectors, etc. VEX is very well shaped to process heavy data,  forcing Python for doing this is ultimately waste of time. Using Python for a job will require learning Python->Houdini interaction anyway, which is pretty much the same as learning VEX from scratch - it is really very simple language. 

Both Python and VEX have their own place in Houdini, you can't escape from neither of them :) .

 

Alright, thanks

So I thought they were interchangeable, but clearly they are not. So my next question would be: what would python in Houdini be recommended for then?

Share this post


Link to post
Share on other sites
10 minutes ago, vtrvtr said:

what would python in Houdini be recommended for then?

Tons of things but something that it is brilliant at doing is just manipulating Houdini in general. And by that i mean just simple nodes.

 

If you are into rigging, being proficient in python would be a useful. You could work out a nice control system by hand... then use python to automate the process. This would be different than a digital asset because you can use python to edit/control the current set of nodes in your scene. 

 

Just think of python as a high level control of Houdini, batch type jobs, nodes etc. Vex is efficient low level control dealing with geometry/attribute etc. 

  • Like 4

Share this post


Link to post
Share on other sites

Scene's elements manipulation, rendering orchestration, interacting geometry, image, channel data with numerical modules, like numpy, scipy, etc, adhoc import/export of data. Anything that VEX is not capable of, or hard to achieve in. VEX works in the sandbox of a single geometry object (with importing read-only data from 3 other geometry source). If you, say, import big, complicated FBX file, and want to postprocess it get clean up mess, Python is your man. Computing PCA? Use Numpy.

 

Python is also great for developing plugins which will be rewritten in C++ at the end. But VEX also applies here.  

  • Like 1

Share this post


Link to post
Share on other sites

Add C++ and OpenCL to the mix too, as you have Wrangle SOPs for these so you have no excuse :P

 

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, vtrvtr said:

For example, right now I'm trying to copy one attribute to a newly created one using a wrangler, which in VEX goes simply as


f@new_p = @old_p

But I'm not sure how would it go with python

Rough equivalent is:

x.setAttribValue('new_p', x.attribValue('old_p'))

But Houdini has not Python Wrangle, so, there is no real equivalent. You need to run cycle yourself and create attribute manually:

geo = hou.pwd().geometry()
new_p = geo.addAttrib(hou.attribType.Point, 'new_p', 0.0)
old_p = geo.findPointAttrib('old_p')

for point in geo.points():
    val = point.attribValue(old_p)
    point.setAttribValue(new_p, val)

Or do it this way:

geo = hou.pwd().geometry()
new_p = geo.addAttrib(hou.attribType.Point, 'new_p', 0.0)

values = geo.pointFloatAttribValues('old_p')
geo.setPointFloatAttribValues('new_p', values)

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×