Saturday, April 1, 2017

Houville :: nice up vectors

This is for arranging your geo for nice behaviour with the copy sop. If you want to distibute geo, like trees or whatever, and control orientation but still respect the angle to the surface this is for you.


You'll need some way to connect the target points with the surface prim they relate to. Scatter has the sourceprim option which is cool, but if you want to manually do it you'll need a pre-pass. Here's an example using the 'stick a point in the middle of the face' technique. This should run over prims.
int newPtNum = addpoint(0,@P);
addpointattrib(0,"sourceprim", 0);
setpointattrib(0,"sourceprim", newPtNum, @primnum, 'set');
removeprim(0,@primnum,1);


Now lets get the surface geo ready. Here we will sneakily say normals run along the U direction and Up is what would typically be considered a normal. This makes sure our orientation makes sense.

Run this over points, assuming point source is in OpInput1, and reference geo for orientation is OpInput2.
vector center = primuv(s@OpInput2, 'P', i@sourceprim, {0.5,0.5,0.0});
vector dPdu = primuv(s@OpInput2, 'P', i@sourceprim, {0.51,0.5,0.0});
vector dPdv = primuv(s@OpInput2, 'P', i@sourceprim, {0.5,0.51,0.0});

vector u = normalize(dPdu - center);
vector v = normalize(dPdv - center);

v@up = normalize(cross(u,v));
v@N = u;

//matrix rotation shiz!
vector rot[];
rot[0] = u;
rot[1] = v@up;
rot[2] = v;
matrix3 mtx[] = unserialize(serialize(rot));
rotate(mtx[0], radians(chf('heading')), v@up);
rot = unserialize(serialize(mtx));
v@N = rot[0];
v@up = rot[1];



** for another post - passing colour information through points to be picked up by "Point Instance Procedural" as material overrides:
string r = sprintf("%d", @Cd.x);
string g = sprintf("%d", @Cd.y);
string b = sprintf("%d", @Cd.z);


s@shop_materialpath = chs('../theInstancesShaderPath');
s@material_override = "{'basecolorr':" + r + ",'basecolorg':" + g + ",'basecolorb':" + b + ",}";



Soooooo.. some of that was overkill. Here are a few ways to optimise that.

You can for example dispense with the serialise/unserialise phase by seting to the matrix directly. Also you can use quarternion to directly pull rotation information out of the matrix. Bear in mind Houdini understands '@orient' as a vector4 aka p@orient.
## direct casting and assignment of a matrix, rotation, extraction as a quaternion.
matrix3 rot = set(u,v@up,v)
rotate(rot, radians(chf('heading')), v@up);
p@orient = quaternion(rot)


And finally, you don't have to derive a @up if you have a normal. Have the points (scattered or otherwise) pick up their normals from the source they are based on. addpointattrib(0,"N",{0,0,0}); setpointattrib(0,"N",newPtNum,@N,"set");

Saturday, March 25, 2017

Python: copy paste buffer

Seems like PyQt4 is the ideal way to go:

Two styles:
##how to get something into the clipboard / copy/paste buffer
from PyQt4 import QtGui
QtGui.QApplication.clipboard().setText(textString)

##and to get it back out
text = QtGui.QApplication.clipboard().text()

##but it will be a QString so you'll probably want to 
textString = str(text)


In some cases PyQt4 seems to be crippled, so you can also use Tkinter, which seems to work well for extracting from clipboard. Haven't had luck putting stuff in though:
import Tkinter
root = Tkinter.Tk()
root.withdraw() # Hide the main window (optional)
rawClip = root.clipboard_get()

Saturday, March 11, 2017

Nukia - smarter switch

Use in text node to find what Switch1 Reads are looking at. [lindex [split [file tail [value [value Switch1.input[expr int([value Switch1.which])].name].file]] -] 0] or lol.. [lindex [split [file tail [value [value [value this.input0.name].input[expr int([value [value this.input0.name].which])].name].file]] -] 0] This is also useful. Root dir: [file dirname [knob [topnode].file] ] File name: [file tail [knob [topnode].file] ] File extension: [file extension [knob [topnode].file] ]

Friday, March 10, 2017

Houville :: rop presets

nodePath = ropnet.createNode('ifd',node_name).path()
hscript = "oppresetloadfile %s %s" % (nodePath, "niceRopLayout.preset")
hou.hscript(hscript)

Friday, March 3, 2017

Houville :: put points in the centre of prims

Points in centre of prim, and delete points:
addpoint(0, @P);
removeprim(0, @primnum, 1);

Sunday, February 19, 2017

Houville :: copying nodes from one part of network to another

Yup, this might come in handy too:
hou.copyNodesTo(hou.node('/obj/mySubnet').glob('*'),hou.node('/obj'))


Houville :: adding params to a obj

Another one I keep forgetting... Here's how to add params to a node in houdini.
n = hou.node('/obj/geo1')
n.addSpareParmTuple(hou.IntParmTemplate('intParm','',1, default_value=(10,),min = 0, max = 20))
n.addSpareParmTuple(hou.FloatParmTemplate('floatParm','',1, default_value=(10,),min = 0, max = 20))


#define some multi line code.  Like a python script
code = """print 'some stuff'
print 'more stuffs'
print 'an\\\\' ting'"""

# is hidden is good for hiding code away
n.addSpareParmTuple(hou.StringParmTemplate('stringParm','',1,default_value=(code,), is_hidden=0))
n.addSpareParmTuple(hou.ButtonParmTemplate('Button','', join_with_next=0, script_callback='exec(hou.parm("stringParm").evalAsString())', script_callback_language=hou.scriptLanguage.Python))

And when you want to delete some parms, remember to get rid of the tuple.  You can access that easily like this:
n.removeSpareParmTuple(n.parm('stringParm').tuple())

And finally, if you don't want to add params one by one you can make a Parameter Template Group to then add as a lump later.
ptg = n.parmTemplateGroup()
ptg.append(hou.IntParmTemplate('intParm','',1, default_value=(10,),min = 0, max = 20))
n.setParmTemplateGroup(ptg)

Not quite sure yet why this is better, but I'll probably find out one day.