Skip to content

Commit ef8026f

Browse files
committed
Merge pull request #148 from valeriebernard/fnSceneShapeCreateChild
Added FnSceneShape createChild, extracted from expandOnce.
2 parents 8d348c6 + 8625c0b commit ef8026f

File tree

1 file changed

+52
-44
lines changed

1 file changed

+52
-44
lines changed

python/IECoreMaya/FnSceneShape.py

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,57 @@ def __queryIndexForPath( self, path ):
202202

203203
maya.cmds.setAttr( node+".queryPaths["+str(index)+"]", path, type="string" )
204204
return index
205+
206+
## create the given child for the scene shape
207+
# Returns a the function set for the child scene shape.
208+
def createChild( self, childName, sceneFile, sceneRoot, drawGeo = False, drawChildBounds = False, drawRootBound = True, drawTagsFilter = "" ) :
209+
210+
node = self.fullPathName()
211+
transform = maya.cmds.listRelatives( node, parent=True, f=True )[0]
212+
213+
if maya.cmds.objExists( transform+"|"+childName ):
214+
shape = maya.cmds.listRelatives( transform+"|"+childName, f=True, type="ieSceneShape" )
215+
if shape:
216+
fnChild = IECoreMaya.FnSceneShape( shape[0] )
217+
else:
218+
fnChild = IECoreMaya.FnSceneShape.createShape( transform+"|"+childName )
219+
else:
220+
fnChild = IECoreMaya.FnSceneShape.create( childName, transformParent = transform )
221+
222+
childNode = fnChild.fullPathName()
223+
childTransform = maya.cmds.listRelatives( childNode, parent=True, f=True )[0]
224+
maya.cmds.setAttr( childNode+".file", sceneFile, type="string" )
225+
sceneRootName = "/"+childName if sceneRoot == "/" else sceneRoot+"/"+childName
226+
maya.cmds.setAttr( childNode+".root", sceneRootName, type="string" )
227+
228+
index = self.__queryIndexForPath( "/"+childName )
229+
outTransform = node+".outTransform["+str(index)+"]"
230+
if not maya.cmds.isConnected( outTransform+".outTranslate", childTransform+".translate" ):
231+
maya.cmds.connectAttr( outTransform+".outTranslate", childTransform+".translate", f=True )
232+
if not maya.cmds.isConnected( outTransform+".outRotate", childTransform+".rotate" ):
233+
maya.cmds.connectAttr( outTransform+".outRotate", childTransform+".rotate", f=True )
234+
if not maya.cmds.isConnected( outTransform+".outScale", childTransform+".scale" ):
235+
maya.cmds.connectAttr( outTransform+".outScale", childTransform+".scale", f=True )
236+
237+
maya.cmds.setAttr( childNode+".drawGeometry", drawGeo )
238+
maya.cmds.setAttr( childNode+".drawChildBounds", drawChildBounds )
239+
maya.cmds.setAttr( childNode+".drawRootBound", drawRootBound )
240+
241+
if drawTagsFilter:
242+
parentTags = drawTagsFilter.split()
243+
childTags = fnChild.sceneInterface().readTags()
244+
commonTags = filter( lambda x: str(x) in childTags, parentTags )
245+
if not commonTags:
246+
# Hide that child since it doesn't match any filter
247+
maya.cmds.setAttr( childTransform+".visibility", 0 )
248+
else:
249+
maya.cmds.setAttr( childNode+".drawTagsFilter", " ".join(commonTags),type="string" )
250+
251+
# Connect child time to its parent so they're in sync
252+
if not maya.cmds.isConnected( node+".outTime", childNode+".time" ):
253+
maya.cmds.connectAttr( node+".outTime", childNode+".time", f=True )
254+
255+
return fnChild
205256

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

236-
timeConnection = maya.cmds.listConnections( node+".time", source = True, destination = False, plugs=True )
237-
238287
newSceneShapeFns = []
239288

240289
for i, child in enumerate( sceneChildren ):
241290

242-
if maya.cmds.objExists( transform+"|"+child ):
243-
shape = maya.cmds.listRelatives( transform+"|"+child, f=True, type="ieSceneShape" )
244-
if shape:
245-
fnChild = IECoreMaya.FnSceneShape( shape[0] )
246-
else:
247-
fnChild = IECoreMaya.FnSceneShape.createShape( transform+"|"+child )
248-
else:
249-
fnChild = IECoreMaya.FnSceneShape.create( child, transformParent = transform )
250-
251-
childNode = fnChild.fullPathName()
252-
childTransform = maya.cmds.listRelatives( childNode, parent=True, f=True )[0]
253-
maya.cmds.setAttr( childNode+".file", sceneFile, type="string" )
254-
sceneRootName = "/"+child if sceneRoot == "/" else sceneRoot+"/"+child
255-
maya.cmds.setAttr( childNode+".root", sceneRootName, type="string" )
256-
257-
index = self.__queryIndexForPath( "/"+child )
258-
outTransform = node+".outTransform["+str(index)+"]"
259-
if not maya.cmds.isConnected( outTransform+".outTranslate", childTransform+".translate" ):
260-
maya.cmds.connectAttr( outTransform+".outTranslate", childTransform+".translate", f=True )
261-
if not maya.cmds.isConnected( outTransform+".outRotate", childTransform+".rotate" ):
262-
maya.cmds.connectAttr( outTransform+".outRotate", childTransform+".rotate", f=True )
263-
if not maya.cmds.isConnected( outTransform+".outScale", childTransform+".scale" ):
264-
maya.cmds.connectAttr( outTransform+".outScale", childTransform+".scale", f=True )
265-
266-
maya.cmds.setAttr( childNode+".drawGeometry", drawGeo )
267-
maya.cmds.setAttr( childNode+".drawChildBounds", drawChildBounds )
268-
maya.cmds.setAttr( childNode+".drawRootBound", drawRootBound )
269-
270-
if drawTagsFilter:
271-
parentTags = drawTagsFilter.split()
272-
childTags = fnChild.sceneInterface().readTags()
273-
commonTags = filter( lambda x: str(x) in childTags, parentTags )
274-
if not commonTags:
275-
# Hide that child since it doesn't match any filter
276-
maya.cmds.setAttr( childTransform+".visibility", 0 )
277-
else:
278-
maya.cmds.setAttr( childNode+".drawTagsFilter", " ".join(commonTags),type="string" )
279-
280-
# Connect child time to its parent so they're in sync
281-
if not maya.cmds.isConnected( node+".outTime", childNode+".time" ):
282-
maya.cmds.connectAttr( node+".outTime", childNode+".time", f=True )
283-
291+
fnChild = self.createChild( child, sceneFile, sceneRoot, drawGeo, drawChildBounds, drawRootBound, drawTagsFilter )
284292
newSceneShapeFns.append( fnChild )
285293

286294
return newSceneShapeFns

0 commit comments

Comments
 (0)