import json
def drawOutline( outline, vex_func_name ):
vexcode = "void {}() {}\n".format(vex_func_name,'{')
vexcode += ' int pr,pt;\n'
vexcode += ' pr = addprim(0,"poly");\n'
for p in outline:
vt = " set( {}, {}, 0 )".format(*p)
vexcode += " pt = addpoint(0,{});\n".format(vt)
vexcode += " addvertex(0,pr,pt);\n"
vexcode += "}\n"
vexcode += "{}();\n\n".format(vex_func_name)
return vexcode
import math
def drawLine( line, vex_func_name ):
vexcode = "addattrib(0,\"point\",\"tangent\",{0,0,0});\n"
vexcode += "void {}() {}\n".format(vex_func_name,'{')
vexcode += ' int pr,pt;\n'
vexcode += ' pr = addprim(0,"polyline");\n'
for p in line:
x,y,theta = p
theta = hou.hmath.degToRad(theta)
vt = " set( {}, {}, 0 )".format(x,y)
vexcode += " pt = addpoint(0,{});\n".format(vt)
vexcode += " setattrib(0,\"point\",\"tangent\",pt,-1, set( {},{},0 ) );\n".format(math.cos(theta),math.sin(theta))
vexcode += " addvertex(0,pr,pt);\n"
vexcode += "}\n"
vexcode += "{}();\n\n".format(vex_func_name)
return vexcode
shapecode = hou.pwd().inputs()[0].parm('shape_json').eval()
shape = json.loads( shapecode )
outline = shape['outline']
code = drawOutline( outline, "outline" )
flags = shape['flags']
flagcode = ''
for flag in flags.keys():
flagoutline = flags[flag]['outline']
funcname = 'flag_{}'.format(flag)
flagcode += drawOutline( flagoutline, funcname )
code += flagcode
code += drawLine(shape['inputs'],'inputs')
code += drawLine(shape['outputs'],'outputs')
return code