Jump to content

VEX vs Python?


vtrvtr

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
Link to comment
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
Link to comment
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?

Link to comment
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
Link to comment
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
Link to comment
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 2
  • Thanks 1
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...