Last active
December 12, 2019 00:59
-
-
Save duartevictorino/b1968f8324f4ac498e42033184437e95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import toolutils | |
outputitem = None | |
inputindex = -1 | |
inputitem = None | |
outputindex = -1 | |
num_args = 1 | |
h_extra_args = '' | |
pane = toolutils.activePane(kwargs) | |
if not isinstance(pane, hou.NetworkEditor): | |
pane = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor) | |
if pane is None: | |
hou.ui.displayMessage( | |
'Cannot create node: cannot find any network pane') | |
sys.exit(0) | |
else: # We're creating this tool from the TAB menu inside a network editor | |
pane_node = pane.pwd() | |
if kwargs.has_key("outputnodename") and kwargs.has_key("inputindex"): | |
outputitem = pane_node.item(kwargs["outputnodename"]) | |
inputindex = kwargs["inputindex"] | |
h_extra_args += 'set arg4 = "' + kwargs["outputnodename"] + '"\n' | |
h_extra_args += 'set arg5 = "' + str(inputindex) + '"\n' | |
num_args = 6 | |
if kwargs.has_key("inputnodename") and kwargs.has_key("outputindex"): | |
inputitem = pane_node.item(kwargs["inputnodename"]) | |
outputindex = kwargs["outputindex"] | |
h_extra_args += 'set arg6 = "' + kwargs["inputnodename"] + '"\n' | |
h_extra_args += 'set arg9 = "' + str(outputindex) + '"\n' | |
num_args = 9 | |
if kwargs.has_key("autoplace"): | |
autoplace = kwargs["autoplace"] | |
else: | |
autoplace = False | |
# If shift-clicked we want to auto append to the current | |
# node | |
if kwargs.has_key("shiftclick") and kwargs["shiftclick"]: | |
if inputitem is None: | |
inputitem = pane.currentNode() | |
outputindex = 0 | |
if kwargs.has_key("nodepositionx") and kwargs.has_key("nodepositiony"): | |
try: | |
pos = [ float( kwargs["nodepositionx"] ), | |
float( kwargs["nodepositiony"] )] | |
except: | |
pos = None | |
else: | |
pos = None | |
if not autoplace and not pane.listMode(): | |
if pos is not None: | |
pass | |
elif outputitem is None: | |
pos = pane.selectPosition(inputitem, outputindex, None, -1) | |
else: | |
pos = pane.selectPosition(inputitem, outputindex, | |
outputitem, inputindex) | |
if pos is not None: | |
if kwargs.has_key("node_bbox"): | |
size = kwargs["node_bbox"] | |
pos[0] -= size[0] / 2 | |
pos[1] -= size[1] / 2 | |
else: | |
pos[0] -= 0.573625 | |
pos[1] -= 0.220625 | |
h_extra_args += 'set arg2 = "' + str(pos[0]) + '"\n' | |
h_extra_args += 'set arg3 = "' + str(pos[1]) + '"\n' | |
h_extra_args += 'set argc = "' + str(num_args) + '"\n' | |
pane_node = pane.pwd() | |
child_type = pane_node.childTypeCategory().nodeTypes() | |
if not child_type.has_key('subnet'): | |
hou.ui.displayMessage( | |
'Cannot create node: incompatible pane network type') | |
sys.exit(0) | |
# First clear the node selection | |
pane_node.setSelected(False, True) | |
h_path = pane_node.path() | |
h_preamble = 'set arg1 = "' + h_path + '"\n' | |
h_cmd = r''' | |
if ($argc < 2 || "$arg2" == "") then | |
set arg2 = 0 | |
endif | |
if ($argc < 3 || "$arg3" == "") then | |
set arg3 = 0 | |
endif | |
# Automatically generated script | |
# $arg1 - the path to add this node | |
# $arg2 - x position of the tile | |
# $arg3 - y position of the tile | |
# $arg4 - input node to wire to | |
# $arg5 - which input to wire to | |
# $arg6 - output node to wire to | |
# $arg7 - the type of this node | |
# $arg8 - the node is an indirect input | |
# $arg9 - index of output from $arg6 | |
\set noalias = 1 | |
set saved_path = `execute("oppwf")` | |
opcf $arg1 | |
# Node $_obj_geo1_dvVelocityGenerator (Sop/subnet) | |
set _obj_geo1_dvVelocityGenerator = `run("opadd -e -n -v subnet dvVelocityGenerator")` | |
oplocate -x `$arg2 + 0` -y `$arg3 + 0` $_obj_geo1_dvVelocityGenerator | |
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off $_obj_geo1_dvVelocityGenerator | |
opexprlanguage -s hscript $_obj_geo1_dvVelocityGenerator | |
opcf $_obj_geo1_dvVelocityGenerator | |
# Node $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 (Sop/attribwrangle) | |
set _obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 = `run("opadd -e -n -v attribwrangle dvVelocityGenerator9")` | |
oplocate -x `$arg2 + 0` -y `$arg3 + 5.2176` $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opspareds ' group { name "folder2" label "Velocity Generator Parms" parm { name "noise_viz" label "Noise Visualization" type toggle default { "0" } } parm { name "use_input2" label "Use Input2 for Direction" type toggle default { "0" } range { 0 10 } } parm { name "center_offset" label "Direction / Center Offset" type vector size 3 default { "0" "2.5" "0" } disablewhen "{ use_input2 == 1 }" range { -5 5 } } parm { name "rand_min" label "Rand Min" type float default { "0" } range { 0 1 } } parm { name "rand_max" label "Rand Max" type float default { "1" } range { 0 1 } } parm { name "noise_frequency" label "Noise Frequency" type float default { "1" } range { 0 1 } } parm { name "in_noise_min_val" label "In Noise Min Val" type float default { "0.25" } range { 0 1 } } parm { name "in_noise_max_val" label "In Noise Max Val" type float default { "0.75" } range { 0 1 } } parm { name "out_noise_min_val" label "Out Noise Min Val" type float default { "0.25" } range { 0 1 } } parm { name "out_noise_max_val" label "Out Noise Max Val" type float default { "0.75" } range { 0 1 } } parm { name "power" label "Power" type float default { "2" } range { 0 1 } } parm { name "velocity_multiplier" label "Velocity Multiplier" type float default { "100" } range { 0 1 } } parm { name "noise_offset" label "Noise Offset" type vector size 3 default { "0" "0" "0" } range { 0 1 } } parm { name "custom_rotation" label "Custom Rotation" type vector size 3 default { "0" "0" "0" } range { 0 1 } } } group { name "folder2_1" label "Code" parm { name "group" baseparm label "Group" export none bindselector points "Modify Points" "Select the points to affect and press Enter to complete." 0 1 0xffffffff 0 grouptype 0 } parm { name "grouptype" baseparm label "Group Type" export none } parm { name "class" baseparm label "Run Over" export none } parm { name "vex_numcount" baseparm label "Number Count" export none } parm { name "vex_threadjobsize" baseparm label "Thread Job Size" export none } parm { name "snippet" baseparm label "VEXpression" export all } parm { name "exportlist" baseparm label "Attributes to Create" export none } parm { name "vex_strict" baseparm label "Enforce Prototypes" export none } } group { name "folder2_2" label "Bindings" parm { name "autobind" baseparm label "Autobind by Name" export none } multiparm { name "bindings" label "Number of Bindings" baseparm default 0 parmtag { "autoscope" "0000000000000000" } parmtag { "multistartoffset" "1" } parm { name "bindname#" baseparm label "Attribute Name" export none } parm { name "bindparm#" baseparm label "VEX Parameter" export none } } parm { name "groupautobind" baseparm label "Autobind Groups by Name" export none } multiparm { name "groupbindings" label "Group Bindings" baseparm default 0 parmtag { "autoscope" "0000000000000000" } parmtag { "multistartoffset" "1" } parm { name "bindgroupname#" baseparm label "Group Name" export none } parm { name "bindgroupparm#" baseparm label "VEX Parameter" export none } } parm { name "vex_cwdpath" baseparm label "Evaluation Node Path" export none } parm { name "vex_outputmask" baseparm label "Export Parameters" export none } parm { name "vex_updatenmls" baseparm label "Update Normals If Displaced" export none } parm { name "vex_matchattrib" baseparm label "Attribute to Match" export none } parm { name "vex_inplace" baseparm label "Compute Results In Place" export none } parm { name "vex_selectiongroup" baseparm label "Output Selection Group" export none } } ' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opparm $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 bindings ( 0 ) groupbindings ( 0 ) | |
opparm $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 snippet ( '//VELOCITY GENERATOR\n//=======================================================\n//INPUT 1 - OBJECT TO EMIT FROM\n//INPUT 2 - SINGLE POINT THAT PROVIDES THE VELOCITY DIRECTION (i.e. emitting object -> pack -> add -> transform)\n//=======================================================\n//INIT VALUES\nvector p1;\nfloat r1 = rand(@ptnum * 123.321);\nvector center = getbbox_center(0);\nvector center_offset = chv("center_offset");\nint use_input2 = chi("use_input2");\n\n\nif (use_input2){\n p1 = point(1,"P",0);\n}\nelse {\n p1 = center - center_offset;\n}\n\n//NOISE\nfloat val = noise((@P + chv("noise_offset")) * chf("noise_frequency"));\nval = fit(val,chf("in_noise_min_val"),chf("in_noise_max_val"),chf("out_noise_min_val"),chf("out_noise_max_val"));\nval = pow(val,chf("power"));\n\n//VISUALIZE NOISE\nif(ch("noise_viz")==1)\n @Cd = set(val,val,val);\nelse if(ch("noise_viz")==0)\n @Cd = @Cd;\n\n//DIRECTION\nv@direction = normalize(@P - p1);\n\n//SPEED\nfloat speed = fit01(r1,ch("rand_min"),ch("rand_max"));\n\n//SET VELOCITY\n//Always have: vector * float \nv@v = v@direction * speed;\nv@v *= val;\n\n//ROTATE EMITTER\n//vector center = getbbox_center(0);\nvector trans = 0;\nvector scale = 1;\nvector rot = chv("custom_rotation");\nvector pivot = center;\nmatrix m = maketransform(0,0,trans,rot,scale,center);\n4@mxform = m;\n\n@P *= m;\n\n//VELOCITY MULTIPLIER\n@v *= chf("velocity_multiplier");\n\n//ROTATE VELOCITIES\nv@v *= matrix3 (m);\n\n//=======================================================' ) center_offset ( 0 5 0 ) rand_min ( 0.82399999999999995 ) noise_frequency ( 0.5 ) in_noise_min_val ( 0.35199999999999998 ) in_noise_max_val ( 0.78800000000000003 ) out_noise_min_val ( 0.41399999999999998 ) out_noise_max_val ( 0.95899999999999996 ) power ( 4 ) custom_rotation ( 0 0 -25 ) | |
opcomment -c 'Created from Gallery Entry: dvVelocityGenerator\n\nVelocity Generator' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opcolor -c 0.80000001192092896 0.016000000759959221 0.016000000759959221 $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opset -d on -r on -h off -f off -y off -t off -l off -s off -u off -F off -c on -e on -b off $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opexprlanguage -s hscript $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opuserdata -n '___Version___' -v '' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opuserdata -n '___toolcount___' -v '1' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opuserdata -n '___toolid___' -v 'subnet' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opuserdata -n 'nodeshape' -v 'trapezoid_down' $_obj_geo1_dvVelocityGenerator_dvVelocityGenerator9 | |
opcf .. | |
opcf $_obj_geo1_dvVelocityGenerator | |
opcf .. | |
opset -p on $_obj_geo1_dvVelocityGenerator | |
opcf $arg1 | |
opcf $_obj_geo1_dvVelocityGenerator | |
opcf .. | |
set oidx = 0 | |
if ($argc >= 9 && "$arg9" != "") then | |
set oidx = $arg9 | |
endif | |
if ($argc >= 5 && "$arg4" != "") then | |
set output = $_obj_geo1_dvVelocityGenerator | |
opwire -n $output -$arg5 $arg4 | |
endif | |
if ($argc >= 6 && "$arg6" != "") then | |
set input = $_obj_geo1_dvVelocityGenerator | |
if ($arg8) then | |
opwire -n -i $arg6 -0 $input | |
else | |
opwire -n -o $oidx $arg6 -0 $input | |
endif | |
endif | |
opcf $saved_path | |
''' | |
hou.hscript(h_preamble + h_extra_args + h_cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment