Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 52 additions & 44 deletions python/IECoreMaya/FnSceneShape.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,57 @@ def __queryIndexForPath( self, path ):

maya.cmds.setAttr( node+".queryPaths["+str(index)+"]", path, type="string" )
return index

## create the given child for the scene shape
# Returns a the function set for the child scene shape.
def createChild( self, childName, sceneFile, sceneRoot, drawGeo = False, drawChildBounds = False, drawRootBound = True, drawTagsFilter = "" ) :

node = self.fullPathName()
transform = maya.cmds.listRelatives( node, parent=True, f=True )[0]

if maya.cmds.objExists( transform+"|"+childName ):
shape = maya.cmds.listRelatives( transform+"|"+childName, f=True, type="ieSceneShape" )
if shape:
fnChild = IECoreMaya.FnSceneShape( shape[0] )
else:
fnChild = IECoreMaya.FnSceneShape.createShape( transform+"|"+childName )
else:
fnChild = IECoreMaya.FnSceneShape.create( childName, transformParent = transform )

childNode = fnChild.fullPathName()
childTransform = maya.cmds.listRelatives( childNode, parent=True, f=True )[0]
maya.cmds.setAttr( childNode+".file", sceneFile, type="string" )
sceneRootName = "/"+childName if sceneRoot == "/" else sceneRoot+"/"+childName
maya.cmds.setAttr( childNode+".root", sceneRootName, type="string" )

index = self.__queryIndexForPath( "/"+childName )
outTransform = node+".outTransform["+str(index)+"]"
if not maya.cmds.isConnected( outTransform+".outTranslate", childTransform+".translate" ):
maya.cmds.connectAttr( outTransform+".outTranslate", childTransform+".translate", f=True )
if not maya.cmds.isConnected( outTransform+".outRotate", childTransform+".rotate" ):
maya.cmds.connectAttr( outTransform+".outRotate", childTransform+".rotate", f=True )
if not maya.cmds.isConnected( outTransform+".outScale", childTransform+".scale" ):
maya.cmds.connectAttr( outTransform+".outScale", childTransform+".scale", f=True )

maya.cmds.setAttr( childNode+".drawGeometry", drawGeo )
maya.cmds.setAttr( childNode+".drawChildBounds", drawChildBounds )
maya.cmds.setAttr( childNode+".drawRootBound", drawRootBound )

if drawTagsFilter:
parentTags = drawTagsFilter.split()
childTags = fnChild.sceneInterface().readTags()
commonTags = filter( lambda x: str(x) in childTags, parentTags )
if not commonTags:
# Hide that child since it doesn't match any filter
maya.cmds.setAttr( childTransform+".visibility", 0 )
else:
maya.cmds.setAttr( childNode+".drawTagsFilter", " ".join(commonTags),type="string" )

# Connect child time to its parent so they're in sync
if not maya.cmds.isConnected( node+".outTime", childNode+".time" ):
maya.cmds.connectAttr( node+".outTime", childNode+".time", f=True )

return fnChild

## Expands the scene shape one level down if possible.
# Returns a list of function sets for the child scene shapes.
Expand Down Expand Up @@ -233,54 +284,11 @@ def expandOnce( self ) :
drawRootBound = maya.cmds.getAttr( node+".drawRootBound" )
drawTagsFilter = maya.cmds.getAttr( node+".drawTagsFilter" )

timeConnection = maya.cmds.listConnections( node+".time", source = True, destination = False, plugs=True )

newSceneShapeFns = []

for i, child in enumerate( sceneChildren ):

if maya.cmds.objExists( transform+"|"+child ):
shape = maya.cmds.listRelatives( transform+"|"+child, f=True, type="ieSceneShape" )
if shape:
fnChild = IECoreMaya.FnSceneShape( shape[0] )
else:
fnChild = IECoreMaya.FnSceneShape.createShape( transform+"|"+child )
else:
fnChild = IECoreMaya.FnSceneShape.create( child, transformParent = transform )

childNode = fnChild.fullPathName()
childTransform = maya.cmds.listRelatives( childNode, parent=True, f=True )[0]
maya.cmds.setAttr( childNode+".file", sceneFile, type="string" )
sceneRootName = "/"+child if sceneRoot == "/" else sceneRoot+"/"+child
maya.cmds.setAttr( childNode+".root", sceneRootName, type="string" )

index = self.__queryIndexForPath( "/"+child )
outTransform = node+".outTransform["+str(index)+"]"
if not maya.cmds.isConnected( outTransform+".outTranslate", childTransform+".translate" ):
maya.cmds.connectAttr( outTransform+".outTranslate", childTransform+".translate", f=True )
if not maya.cmds.isConnected( outTransform+".outRotate", childTransform+".rotate" ):
maya.cmds.connectAttr( outTransform+".outRotate", childTransform+".rotate", f=True )
if not maya.cmds.isConnected( outTransform+".outScale", childTransform+".scale" ):
maya.cmds.connectAttr( outTransform+".outScale", childTransform+".scale", f=True )

maya.cmds.setAttr( childNode+".drawGeometry", drawGeo )
maya.cmds.setAttr( childNode+".drawChildBounds", drawChildBounds )
maya.cmds.setAttr( childNode+".drawRootBound", drawRootBound )

if drawTagsFilter:
parentTags = drawTagsFilter.split()
childTags = fnChild.sceneInterface().readTags()
commonTags = filter( lambda x: str(x) in childTags, parentTags )
if not commonTags:
# Hide that child since it doesn't match any filter
maya.cmds.setAttr( childTransform+".visibility", 0 )
else:
maya.cmds.setAttr( childNode+".drawTagsFilter", " ".join(commonTags),type="string" )

# Connect child time to its parent so they're in sync
if not maya.cmds.isConnected( node+".outTime", childNode+".time" ):
maya.cmds.connectAttr( node+".outTime", childNode+".time", f=True )

fnChild = self.createChild( child, sceneFile, sceneRoot, drawGeo, drawChildBounds, drawRootBound, drawTagsFilter )
newSceneShapeFns.append( fnChild )

return newSceneShapeFns
Expand Down