>>> pane = hou.ui.curDesktop().paneTabOfType(hou.paneTabType.SceneViewer)
<hou.SceneViewer panetab1>
>>> settings = pane.curViewport().settings()
<hou.GeometryViewportSettings>
None
cam1
0.40000000596
>>> settings.setViewMaskOpacity(1)
>>> mycam = hou.node("/obj/cam1")
cam1
>>> settings.setCamera(mycam)
>>> def_cam = cam = viewport.defaultCamera()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'viewport' is not defined
>>> defcam = settings.defaultCamera()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'GeometryViewportSettings' object has no attribute 'defaultCamera'
>>> print pane.curViewport()
<hou.GeometryViewport persp1 of type Perspective>
import hou
from PySide2 import QtCore, QtUiTools, QtWidgets
 
class classname(QtWidgets.QWidget):
    def __init__(self):
        super(classname,self).__init__()        
        self.ui = QtUiTools.QUiLoader().load(ui_path, parentWidget=self)
        self.setParent(hou.ui.mainQtWindow(), QtCore.Qt.Window)
 
win = classname()
win.show()
  • python 2715 / pip 9.0.3

[python houdini] create output(s) from node

Working in Houdini, we need NULL node all the time. It doesn’t consume memory and make the network become organized. Another advantage of Null is when we name it in UPPERCASE it will show in the first row of operator chooser list such as Object Merge node.

Creating Null is already easy in Houdini, just press “TAB” and choose “Null”. But let’s make it easier and more functional to meet some scenario.

Below are two scenarios:

In Scenario 01, it’s quite straight-forward:

  • If you select one node, the python script will create one null node with its original name and prefix is “OUT_”. Then connect to the first input.
  • If you select many nodes, the python script will create null nodes and name them according to their original nodes.

In Scenario 02, it’s more complicated:

  • If you select more-than-one node, it won’t work because we want from one single node branches out many nodes.
  • So, if you select one node and let say you want 3 OUT null nodes (1 is for density, 2 is for velocity, 3 is for hi-poly), you can input the amount number of OUT node (in this case is 3) then you can give each one OUT node a distinct name.

Here’s the video about the code and how it works in Houdini

Here’s the code:

Hope this make your houdini workflow faster.

Enjoy your weekend!

[vex] Sobol sequence

We already turn Halton sequence into vex. How about Sobol sequence? First thing first, what is Sobol sequence?

Sobol sequences are an example of quasi-random low-discrepancy sequences. They were first introduced by the Russian mathematician Ilya M. Sobol in 1967.

Ilya M. Sobol (image from Wikipedia)

In numerical analysis, the quasi-random method is a method for numerical integration and solving some other problems using low-discrepancy sequences. Another name of quasi-random is Quasi-Monte Carlo (QMC) that we usually see in rendering adaptive sampling method.

If you want to know more, there’s a detail explanation about these sequences at this link: https://math.stackexchange.com/questions/888490/understanding-sobol-sequences

How to make Sobol in vex?

It’s great to know we don’t need to code it out. It’s already there thanks to SideFX guys. We have a function called random_sobol (yeah! awesome).

random_sobol function offers a lot of ways for input and output (float, vector, vector4). For now, I go with a simple vector to scatter created points.

Same as the way we did with Halton Sequence, create an Attribule Wrangle and do the code like this:

vector zero = {0,0,0};
vector pos;
vector randS;
for (int i = 0; i < chi(“totalnum”); i++){
randS = random_sobol(zero+i,1);
pos = set(randS.x *
2,randS.y,1e-07i);
addpoint(0,pos);
}

And that’s it! For each point we create, the wrangle will push it in Sobol sequence method.

snapshot of sobol sequence by vex

[vex] Halton Sequence

Today i saw a post on Houdini Artist Group asking about halton sequence in vex. So I think it’s good to give it a try since wikipedia has good information about the algorithm.

What is Halton Sequence?

A Halton sequence is a sequence of points within a unit n-cube which have low discrepancy (that is, they appear to be randomish but cover the domain uniformly), while being deterministic, fast to compute, and easy to understand and implement. They generalize the 1-dimensional Van der Corput sequences.

The Halton sequence is constructed according to a deterministic method that uses coprime numbers as its bases. As a simple example, let’s take one dimension of the Halton sequence to be based on 2 and the other on 3. To generate the sequence for 2, we start by dividing the interval (0,1) in half, then in fourths, eighths, etc., which generates ​12, ​14, ​34, ​18, ​58, ​38, ​78, ​116, ​916,…

Halton Sequence pseudocode

Halton Sequence in Vex

Alright! Above is some knowledge about Halton Sequence from Wikipedia. It’s quite complicated to me honestly. But we have pseudocode and our task is turning it into vex, see how it looks in Houdini.

  • Create an attribute wrangle and set it run in detail mode.
  • Write the vex code like the image below
  • Randomize the color (Cd)
  • Copy a circle to the points created by Halton Sequence wrangle.
halton sequence vex code
halton sequence node network