Skip to content

Commit

Permalink
focus tool now uses generictool to allow user placement in network view
Browse files Browse the repository at this point in the history
  • Loading branch information
simonreeves committed Jan 16, 2023
1 parent 4fcdd09 commit 636ea49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
32 changes: 27 additions & 5 deletions scripts/python/bee/focus_null.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
import hou
import stateutils
import toolutils

def main(kwargs):
"""
Creates a null to use as a focus gizmo for the selected camera(s)
"""

# store reference to selected node
selected_nodes = hou.selectedNodes()

def main():
nodes = hou.selectedNodes()
# Init to record if a camera was selected at all
any_camera_selected = False

for node in nodes:
# get network editor pane
pane = stateutils.activePane(kwargs)

if not isinstance(pane, hou.NetworkEditor):
hou.ui.setStatusMessage('Only works in network editor', severity=hou.severityType.Error)
return False

for node in selected_nodes:
if node.type().name() != 'cam':
continue

# A camera was found!
any_camera_selected = True

# create null
focus_null = node.parent().createNode('null', node.name() + '_focus')
# create null
# toolutils not soptoolutils, because it's not a SOP
focus_null = toolutils.genericTool(kwargs, 'null')
focus_null.setName(node.name() + '_focus', True)

# add focus distance expression
expression = "vlength(vtorigin('.', '{}'))".format(node.relativePathTo(focus_null))
node.parm('focus').setExpression(expression)

# Lock rotation
focus_null.parmTuple('r').lock(True)

# set focus null visual properties
focus_null.parm('shadedmode').set(1)
focus_null.parm('controltype').set(2)
Expand Down
2 changes: 1 addition & 1 deletion toolbar/bee.shelf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bee.list_materials.main()]]></script>
</toolMenuContext>
<toolSubmenu>Bee</toolSubmenu>
<script scriptType="python"><![CDATA[import bee.focus_null
bee.focus_null.main()]]></script>
bee.focus_null.main(kwargs)]]></script>
<keywordList>
<keyword>camera add focus null bee</keyword>
</keywordList>
Expand Down

0 comments on commit 636ea49

Please sign in to comment.