def testTags( self ) : self.writeTagSCC( file=SceneShapeTest.__testFile ) maya.cmds.file( new=True, f=True ) node = maya.cmds.createNode( 'ieSceneShape' ) fn = IECoreMaya.FnSceneShape( node ) transform = str(maya.cmds.listRelatives( node, parent=True )[0]) maya.cmds.setAttr( node+'.file', SceneShapeTest.__testFile, type='string' ) scene = IECoreMaya.MayaScene().child( transform ) self.assertEqual( sorted([ str(x) for x in scene.readTags( IECore.SceneInterface.TagFilter.EveryTag ) ]), [ "ObjectType:MeshPrimitive", "a", "b", "c" ] ) self.assertEqual( sorted([ str(x) for x in scene.readTags() ]), [] ) for tag in scene.readTags(IECore.SceneInterface.TagFilter.EveryTag) : self.assertTrue( scene.hasTag( tag, IECore.SceneInterface.TagFilter.EveryTag ) ) self.assertFalse( scene.hasTag( "fakeTag", IECore.SceneInterface.TagFilter.EveryTag ) ) # double expanding because the first level has all the same tags childFn = fn.expandOnce()[0].expandOnce()[0] scene = childFn.sceneInterface() self.assertEqual( set([ str(x) for x in scene.readTags( IECore.SceneInterface.TagFilter.DescendantTag|IECore.SceneInterface.TagFilter.LocalTag ) ]), set([ "ObjectType:MeshPrimitive", "b", "c" ]) ) self.assertEqual( sorted([ str(x) for x in scene.readTags() ]), [ "ObjectType:MeshPrimitive", "b" ] ) for tag in scene.readTags(IECore.SceneInterface.TagFilter.EveryTag) : self.assertTrue( scene.hasTag( tag, IECore.SceneInterface.TagFilter.EveryTag ) ) self.assertFalse( scene.hasTag( "fakeTag", IECore.SceneInterface.TagFilter.EveryTag ) ) childFn = childFn.expandOnce()[0] scene = childFn.sceneInterface() self.assertEqual( sorted([ str(x) for x in scene.readTags( IECore.SceneInterface.TagFilter.DescendantTag|IECore.SceneInterface.TagFilter.LocalTag ) ]), [ "ObjectType:MeshPrimitive", "c" ] ) self.assertEqual( sorted([ str(x) for x in scene.readTags() ]), [ "ObjectType:MeshPrimitive", "c" ] ) for tag in scene.readTags(IECore.SceneInterface.TagFilter.EveryTag) : self.assertTrue( scene.hasTag( tag, IECore.SceneInterface.TagFilter.EveryTag ) ) self.assertFalse( scene.hasTag( "fakeTag", IECore.SceneInterface.TagFilter.EveryTag ) )
def testSceneInterface(self): maya.cmds.file(new=True, f=True) node = maya.cmds.createNode("ieSceneShape") maya.cmds.setAttr(node + '.file', FnSceneShapeTest.__testFile, type='string') fn = IECoreMaya.FnSceneShape(node) # Check scene for a wrong path maya.cmds.setAttr(node + '.root', 'blabla', type='string') scene = fn.sceneInterface() self.assertEqual(scene, None) maya.cmds.setAttr(node + '.root', '/', type='string') scene = fn.sceneInterface() self.assertTrue(isinstance(scene, IECore.SceneCache)) self.assertEqual(scene.childNames(), ['1']) self.assertFalse(scene.hasObject()) maya.cmds.setAttr(node + '.root', '/1', type='string') scene = fn.sceneInterface() self.assertTrue(isinstance(scene, IECore.SceneCache)) self.assertEqual(scene.childNames(), ['child']) self.assertTrue(scene.hasObject())
def __invalidSceneShapes( sceneShapes ): invalid = [] for sceneShape in sceneShapes: fn = IECoreMaya.FnSceneShape( sceneShape ) if fn.sceneInterface() is None: invalid.append( sceneShape ) return invalid
def __printComponents( sceneShape, *unused ) : fnS = IECoreMaya.FnSceneShape( sceneShape ) names = fnS.componentNames() names.sort() print "\n" print " ".join( names ) , print "\n"
def testSceneShapeCustomReaders( self ): # make sure we are at time 0 maya.cmds.currentTime( "0sec" ) scene = IECoreMaya.LiveScene() envShape = str( IECoreMaya.FnSceneShape.create( "ieScene1" ).fullPathName() ) envNode = 'ieScene1' envScene = scene.child( envNode ) self.assertFalse( envScene.hasAttribute( IECoreScene.LinkedScene.linkAttribute ) ) maya.cmds.setAttr( envShape+'.file', 'test/IECore/data/sccFiles/environment.lscc',type='string' ) self.assertTrue( envScene.hasAttribute( IECoreScene.LinkedScene.linkAttribute ) ) spheresShape = str( IECoreMaya.FnSceneShape.create( "ieScene2" ).fullPathName() ) spheresNode = 'ieScene2' maya.cmds.setAttr( spheresShape+'.file', 'test/IECore/data/sccFiles/animatedSpheres.scc',type='string' ) self.assertEqual( set( scene.childNames() ).intersection([ envNode, spheresNode ]) , set( [ envNode, spheresNode ] ) ) self.assertTrue( IECoreScene.LinkedScene.linkAttribute in envScene.attributeNames() ) self.assertEqual( envScene.readAttribute( IECoreScene.LinkedScene.linkAttribute, 0 ), IECore.CompoundData( { "fileName":IECore.StringData('test/IECore/data/sccFiles/environment.lscc'), "root":IECore.InternedStringVectorData() } ) ) self.assertFalse( envScene.hasObject() ) spheresScene = scene.child( spheresNode ) self.assertTrue( spheresScene.hasAttribute( IECoreScene.LinkedScene.linkAttribute ) ) self.assertEqual( spheresScene.readAttribute( IECoreScene.LinkedScene.linkAttribute, 0 ), IECore.CompoundData( { "fileName":IECore.StringData('test/IECore/data/sccFiles/animatedSpheres.scc'), "root":IECore.InternedStringVectorData() } ) ) self.assertFalse( spheresScene.hasObject() ) # expand the scene fnSpheres = IECoreMaya.FnSceneShape( spheresShape ) fnSpheres.expandAll() self.assertFalse( spheresScene.hasAttribute( IECoreScene.LinkedScene.linkAttribute ) ) leafScene = spheresScene.child("A").child("a") self.assertTrue( leafScene.hasAttribute( IECoreScene.LinkedScene.linkAttribute ) ) # When expanding, we connect the child time attributes to their scene shape parent time attribute to propagate time remapping. When checking for time remapping, the scene shape # currently only checks the direct connection, so we have here time in the link attributes. Will have to look out for performance issues. self.assertEqual( leafScene.readAttribute( IECoreScene.LinkedScene.linkAttribute, 0 ), IECore.CompoundData( { "fileName":IECore.StringData('test/IECore/data/sccFiles/animatedSpheres.scc'), "root":IECore.InternedStringVectorData([ 'A', 'a' ]), 'time':IECore.DoubleData( 0 ) } ) ) self.assertFalse( leafScene.hasObject() ) # expand scene to meshes fnSpheres.convertAllToGeometry() self.assertFalse( leafScene.hasAttribute( IECoreScene.LinkedScene.linkAttribute ) ) self.assertTrue( leafScene.hasObject() ) self.assertTrue( isinstance( leafScene.readObject(0), IECoreScene.MeshPrimitive) ) # test time remapped scene readers... spheresShape = str( maya.cmds.createNode( 'ieSceneShape' ) ) maya.cmds.setAttr( spheresShape+'.file', 'test/IECore/data/sccFiles/animatedSpheres.scc',type='string' ) maya.cmds.setAttr( spheresShape+'.time', 24.0*10 ) spheresScene = scene.child( 'ieScene3' ) self.assertTrue( spheresScene.hasAttribute( IECoreScene.LinkedScene.linkAttribute ) ) self.assertEqual( spheresScene.readAttribute( IECoreScene.LinkedScene.linkAttribute, 0 ), IECore.CompoundData( { "fileName":IECore.StringData('test/IECore/data/sccFiles/animatedSpheres.scc'), "root":IECore.InternedStringVectorData(), "time":IECore.DoubleData(10.0) } ) )
def __expandOnce( sceneShapes, *unused ) : toSelect = [] for sceneShape in sceneShapes: fnS = IECoreMaya.FnSceneShape( sceneShape ) new = fnS.expandOnce() toSelect.extend( map( lambda x: x.fullPathName(), new ) ) if toSelect: maya.cmds.select( toSelect, replace=True )
def __printSelectedComponents( sceneShape, *unused ) : fnS = IECoreMaya.FnSceneShape( sceneShape ) selectedNames = fnS.selectedComponentNames() if selectedNames: selectedNames = list( selectedNames ) selectedNames.sort() print "\n" print " ".join( selectedNames ) , print "\n"
def __createLocatorAtPoints( sceneShape, childPlugSuffixes, *unused ) : fnSc = IECoreMaya.FnSceneShape( sceneShape ) selectedNames = fnSc.selectedComponentNames() locators = [] for name in selectedNames : locators.extend( fnSc.createLocatorAtPoints( name, childPlugSuffixes ) ) maya.cmds.select( locators, replace=True )
def __createLocatorWithTransform( sceneShape, *unused ) : fnSc = IECoreMaya.FnSceneShape( sceneShape ) selectedNames = fnSc.selectedComponentNames() locators = [] for name in selectedNames : locators.append( fnSc.createLocatorAtTransform( name ) ) maya.cmds.select( locators, replace=True )
def _expandAll( sceneShapes, tagName=None, *unused) : toSelect = [] for sceneShape in sceneShapes: fnS = IECoreMaya.FnSceneShape( sceneShape ) newFn = fnS.expandAll( preserveNamespace=True, tagName=tagName ) toSelect.extend( map( lambda x: x.fullPathName(), newFn ) ) if toSelect: maya.cmds.select( toSelect, replace=True )
def testLinkedLiveSceneTags(self): self.writeTagSCC(file=SceneShapeTest.__testFile) maya.cmds.file(new=True, f=True) node = maya.cmds.createNode('ieSceneShape') fn = IECoreMaya.FnSceneShape(node) transform = str(maya.cmds.listRelatives(node, parent=True)[0]) maya.cmds.setAttr(node + '.file', SceneShapeTest.__testFile, type='string') scene = IECoreScene.LinkedScene( IECoreMaya.LiveScene()).child(transform) self.assertEqual( sorted([ str(x) for x in scene.readTags( IECoreScene.SceneInterface.TagFilter.EveryTag) ]), ["ObjectType:MeshPrimitive", "a", "b", "c", "top"]) self.assertEqual(sorted([str(x) for x in scene.readTags()]), ["top"]) for tag in scene.readTags( IECoreScene.SceneInterface.TagFilter.EveryTag): self.assertTrue( scene.hasTag(tag, IECoreScene.SceneInterface.TagFilter.EveryTag)) self.assertFalse( scene.hasTag("fakeTag", IECoreScene.SceneInterface.TagFilter.EveryTag)) # expand once: child1Fn = fn.expandOnce()[0] child1 = scene.child("sceneShape_1") self.assertEqual(sorted([str(x) for x in scene.readTags()]), ["top"]) self.assertEqual(sorted([str(x) for x in child1.readTags()]), ["ObjectType:MeshPrimitive", "a"]) child2Fn = child1Fn.expandOnce()[0] child2 = child1.child("sceneShape_2") self.assertEqual(sorted([str(x) for x in scene.readTags()]), ["top"]) self.assertEqual(sorted([str(x) for x in child1.readTags()]), ["ObjectType:MeshPrimitive", "a"]) self.assertEqual(sorted([str(x) for x in child2.readTags()]), ["ObjectType:MeshPrimitive", "b"]) child3Fn = child2Fn.expandOnce()[0] child3 = child2.child("sceneShape_3") self.assertEqual(sorted([str(x) for x in scene.readTags()]), ["top"]) self.assertEqual(sorted([str(x) for x in child1.readTags()]), ["ObjectType:MeshPrimitive", "a"]) self.assertEqual(sorted([str(x) for x in child2.readTags()]), ["ObjectType:MeshPrimitive", "b"]) self.assertEqual(sorted([str(x) for x in child3.readTags()]), ["ObjectType:MeshPrimitive", "c"])
def __expandToSelected(sceneShape, *unused): fnScS = IECoreMaya.FnSceneShape(sceneShape) sceneShape = fnScS.fullPathName() selectedNames = fnScS.selectedComponentNames() if not selectedNames: return if "/" in selectedNames: selectedNames.remove("/") # Go back to object mode parent = maya.cmds.listRelatives(sceneShape, parent=True, fullPath=True)[0] maya.cmds.hilite(parent, unHilite=True) maya.cmds.selectMode(object=True) if selectedNames == []: return toSelect = [] for selected in selectedNames: transformName = parent transformNames = [transformName] for item in selected.split("/")[1:-1]: transformName = transformName + "|" + item if not transformName in transformNames: transformNames.append(transformName) for transform in transformNames: shape = maya.cmds.listRelatives(transform, fullPath=True, type="ieSceneShape")[0] fnS = IECoreMaya.FnSceneShape(shape) fnS.expandOnce() toSelect.append(transformNames[-1]) if toSelect: maya.cmds.select(toSelect, replace=True)
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
def testQuery( self ): maya.cmds.file( new=True, f=True ) def createSceneFile(): scene = IECoreScene.SceneCache( FnSceneShapeTest.__testFile, IECore.IndexedIO.OpenMode.Write ) sc = scene.createChild( str(1) ) curves = IECoreScene.CurvesPrimitive.createBox(imath.Box3f(imath.V3f(0),imath.V3f(1))) # 6 curves. sc.writeObject( curves, 0.0 ) matrix = imath.M44d().translate( imath.V3d( 0, 0, 0 ) ) sc.writeTransform( IECore.M44dData( matrix ), 0.0 ) createSceneFile() node = maya.cmds.createNode( "ieSceneShape" ) maya.cmds.setAttr( node+'.file', FnSceneShapeTest.__testFile,type='string' ) maya.cmds.setAttr( node+'.root', '/',type='string' ) fn = IECoreMaya.FnSceneShape( node ) self.assertEqual( maya.cmds.getAttr(fn.fullPathName()+".outObjects[0]", type=True), None ) self.assertEqual( maya.cmds.getAttr(fn.fullPathName()+".outObjects[1]", type=True), None ) maya.cmds.setAttr( fn.fullPathName()+".queryPaths[0]" , "/1", type="string") maya.cmds.setAttr( fn.fullPathName()+".queryPaths[1]" , "/1", type="string") maya.cmds.setAttr( fn.fullPathName()+".queryConvertParameters[0]", "-index 0", type="string" ) # Set it to output 0 th box curve. maya.cmds.setAttr( fn.fullPathName()+".queryConvertParameters[1]", "-index 1", type="string" ) # Set it to output 1 th box curve. self.assertEqual( maya.cmds.getAttr(fn.fullPathName()+".outObjects[0]", type=True), "nurbsCurve" ) self.assertEqual( maya.cmds.getAttr(fn.fullPathName()+".outObjects[1]", type=True), "nurbsCurve" ) curveShape0 = maya.cmds.createNode( "nurbsCurve" ) curveShape1 = maya.cmds.createNode( "nurbsCurve" ) maya.cmds.connectAttr( fn.fullPathName()+ ".outObjects[0]", curveShape0 + '.create' ) maya.cmds.connectAttr( fn.fullPathName()+ ".outObjects[1]", curveShape1 + '.create' ) self.assertNotEqual( maya.cmds.pointPosition(curveShape0 + '.cv[0]' ), maya.cmds.pointPosition(curveShape1 + '.cv[0]' ) ) maya.cmds.setAttr( fn.fullPathName()+".queryConvertParameters[1]", "-index 0", type="string" ) self.assertEqual( maya.cmds.pointPosition(curveShape0 + '.cv[0]' ), maya.cmds.pointPosition(curveShape1 + '.cv[0]' ) )
def __createChild(self, childName, sceneFile, sceneRoot, drawGeo=False, drawChildBounds=False, drawRootBound=True, drawTagsFilter="", namespace=""): if namespace: namespace += ":" dag = maya.OpenMaya.MDagPath() self.getPath(dag) dag.pop() parentPath = dag.fullPathName() childPath = parentPath + "|" + namespace + childName try: childDag = IECoreMaya.dagPathFromString(childPath) childExists = True except RuntimeError: childExists = False if childExists: shape = maya.cmds.listRelatives(childPath, f=True, type="ieSceneShape") if shape: fnChild = IECoreMaya.FnSceneShape(shape[0]) else: fnChild = IECoreMaya.FnSceneShape.createShape(childPath) else: fnChild = IECoreMaya.FnSceneShape.create( childName, transformParent=parentPath) fnChild.findPlug("file").setString(sceneFile) sceneRootName = "/" + childName if sceneRoot == "/" else sceneRoot + "/" + childName fnChild.findPlug("root").setString(sceneRootName) fnChildTransform = maya.OpenMaya.MFnDagNode(fnChild.parent(0)) index = self.__queryIndexForPath("/" + childName) outTransform = self.findPlug("outTransform").elementByLogicalIndex( index) dgMod = maya.OpenMaya.MDGModifier() childTranslate = fnChildTransform.findPlug("translate") if childTranslate.isConnected(): connections = maya.OpenMaya.MPlugArray() childTranslate.connectedTo(connections, True, False) dgMod.disconnect(connections[0], childTranslate) dgMod.connect(outTransform.child(self.attribute("outTranslate")), childTranslate) childRotate = fnChildTransform.findPlug("rotate") if childRotate.isConnected(): connections = maya.OpenMaya.MPlugArray() childRotate.connectedTo(connections, True, False) dgMod.disconnect(connections[0], childRotate) dgMod.connect(outTransform.child(self.attribute("outRotate")), childRotate) childScale = fnChildTransform.findPlug("scale") if childScale.isConnected(): connections = maya.OpenMaya.MPlugArray() childScale.connectedTo(connections, True, False) dgMod.disconnect(connections[0], childScale) dgMod.connect(outTransform.child(self.attribute("outScale")), childScale) childTime = fnChild.findPlug("time") if childTime.isConnected(): connections = maya.OpenMaya.MPlugArray() childTime.connectedTo(connections, True, False) dgMod.disconnect(connections[0], childTime) dgMod.connect(self.findPlug("outTime"), childTime) dgMod.doIt() fnChild.findPlug("drawGeometry").setBool(drawGeo) fnChild.findPlug("drawChildBounds").setBool(drawChildBounds) fnChild.findPlug("drawRootBound").setBool(drawRootBound) if drawTagsFilter: parentTags = drawTagsFilter.split() childTags = fnChild.sceneInterface().readTags( IECoreScene.SceneInterface.EveryTag) commonTags = filter(lambda x: str(x) in childTags, parentTags) if not commonTags: # Hide that child since it doesn't match any filter fnChildTransform.findPlug("visibility").setBool(False) else: fnChild.findPlug("drawTagsFilter").setString( " ".join(commonTags)) return fnChild
def __createChild(self, childName, sceneFile, sceneRoot, drawGeo=False, drawChildBounds=False, drawRootBound=True, drawTagsFilter="", namespace=""): if namespace: namespace += ":" if not sceneRoot.endswith('/'): sceneRoot += '/' # Construct the child sceneShapes's path dag = maya.OpenMaya.MDagPath() self.getPath(dag) dag.pop() parentPath = dag.fullPathName() childPath = parentPath + "|" + namespace + childName # Create (or retrieve) the child sceneShape if maya.cmds.objExists(childPath): shape = maya.cmds.listRelatives(childPath, fullPath=True, type="ieSceneShape") if shape: fnChild = IECoreMaya.FnSceneShape(shape[0]) else: fnChild = IECoreMaya.FnSceneShape.createShape(childPath) else: fnChild = IECoreMaya.FnSceneShape.create( childName, transformParent=parentPath) fnChildTransform = maya.OpenMaya.MFnDagNode(fnChild.parent(0)) # Set the child's sceneShapes plugs dgMod = maya.OpenMaya.MDGModifier() dgMod.newPlugValueString(fnChild.findPlug("file"), sceneFile) dgMod.newPlugValueString(fnChild.findPlug("root"), sceneRoot + childName) dgMod.newPlugValueBool(fnChild.findPlug("drawGeometry"), drawGeo) dgMod.newPlugValueBool(fnChild.findPlug("drawChildBounds"), drawChildBounds) dgMod.newPlugValueBool(fnChild.findPlug("drawRootBound"), drawRootBound) dgMod.doIt() # Set visible if I have any of the draw flags in my hierarchy, otherwise set hidden if drawTagsFilter: childTags = fnChild.sceneInterface().readTags( IECoreScene.SceneInterface.EveryTag) commonTags = filter(lambda x: str(x) in childTags, drawTagsFilter.split()) if not commonTags: dgMod.newPlugValueBool(fnChildTransform.findPlug("visibility"), False) else: dgMod.newPlugValueString(fnChild.findPlug("drawTagsFilter"), " ".join(commonTags)) dgMod.newPlugValueBool(fnChildTransform.findPlug("visibility"), True) # Drive the child's transforms through the parent sceneShapes plugs index = self.__queryIndexForPath("/" + childName) outTransform = self.findPlug("outTransform").elementByLogicalIndex( index) childTranslate = fnChildTransform.findPlug("translate") FnSceneShape.__disconnectPlug(dgMod, childTranslate) dgMod.connect(outTransform.child(self.attribute("outTranslate")), childTranslate) childRotate = fnChildTransform.findPlug("rotate") FnSceneShape.__disconnectPlug(dgMod, childRotate) dgMod.connect(outTransform.child(self.attribute("outRotate")), childRotate) childScale = fnChildTransform.findPlug("scale") FnSceneShape.__disconnectPlug(dgMod, childScale) dgMod.connect(outTransform.child(self.attribute("outScale")), childScale) childTime = fnChild.findPlug("time") FnSceneShape.__disconnectPlug(dgMod, childTime) dgMod.connect(self.findPlug("outTime"), childTime) dgMod.doIt() return fnChild
def expandOnce(self): node = self.fullPathName() transform = maya.cmds.listRelatives(node, parent=True, f=True)[0] scene = self.sceneInterface() if not scene: return [] sceneChildren = scene.childNames() if sceneChildren == []: # No children to expand to return [] sceneFile = maya.cmds.getAttr(node + ".file") sceneRoot = maya.cmds.getAttr(node + ".root") maya.cmds.setAttr(node + ".querySpace", 1) maya.cmds.setAttr(node + ".objectOnly", l=False) maya.cmds.setAttr(node + ".objectOnly", 1) maya.cmds.setAttr(node + ".objectOnly", l=True) drawGeo = maya.cmds.getAttr(node + ".drawGeometry") drawChildBounds = maya.cmds.getAttr(node + ".drawChildBounds") 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) newSceneShapeFns.append(fnChild) return newSceneShapeFns
def _dagMenu( menu, sceneShape ) : sceneShapes = __selectedSceneShapes() if not sceneShapes: return fnScS = [] for target in sceneShapes: fnScS.append( IECoreMaya.FnSceneShape( target ) ) maya.cmds.setParent( menu, menu=True ) invalidSceneShapes = __invalidSceneShapes( sceneShapes ) if invalidSceneShapes: maya.cmds.menuItem( label = "Invalid Inputs for selected SceneShapes!", radialPosition = "N", ) # Component mode elif fnScS[0].selectedComponentNames(): maya.cmds.menuItem( label = "Object", radialPosition = "N", command = IECore.curry( __objectCallback, sceneShapes[0] ), ) maya.cmds.menuItem( label = "Print Component Names", radialPosition = "NW", command = IECore.curry( __printComponents, sceneShapes[0] ) ) maya.cmds.menuItem( label = "Print Selected Component Names", radialPosition = "NE", command = IECore.curry( __printSelectedComponents, sceneShapes[0] ) ) maya.cmds.menuItem( label = "Expand...", radialPosition = "SE", subMenu = True ) maya.cmds.menuItem( label = "Expand to Selected Components", radialPosition = "S", command = IECore.curry( __expandToSelected, sceneShapes[0] ) ) maya.cmds.setParent( "..", menu=True ) maya.cmds.menuItem( label = "Create Locator", radialPosition = "SW", subMenu = True, ) maya.cmds.menuItem( label = "At Bound Min", radialPosition = "N", command = IECore.curry( __createLocatorAtPoints, sceneShapes[0], [ "Min" ] ), ) maya.cmds.menuItem( label = "At Bound Max", radialPosition = "NE", command = IECore.curry( __createLocatorAtPoints, sceneShapes[0], [ "Max" ] ), ) maya.cmds.menuItem( label = "At Bound Min And Max", radialPosition = "E", command = IECore.curry( __createLocatorAtPoints, sceneShapes[0], [ "Min", "Max" ] ), ) maya.cmds.menuItem( label = "At Bound Centre", radialPosition = "SE", command = IECore.curry( __createLocatorAtPoints, sceneShapes[0], [ "Center" ] ), ) maya.cmds.menuItem( label = "At Transform Origin", radialPosition = "S", command = IECore.curry( __createLocatorWithTransform, sceneShapes[0] ), ) maya.cmds.setParent( "..", menu=True ) # Object mode else: if len( sceneShapes ) == 1: if maya.cmds.getAttr( sceneShapes[0]+".drawGeometry" ) or maya.cmds.getAttr( sceneShapes[0]+".drawChildBounds" ): maya.cmds.menuItem( label = "Component", radialPosition = "N", command = IECore.curry( __componentCallback, sceneShapes[0] ) ) maya.cmds.menuItem( label = "Preview...", radialPosition = "NW", subMenu = True ) maya.cmds.menuItem( label = "All Geometry On", radialPosition = "E", command = IECore.curry( __setChildrenPreviewAttributes, sceneShapes, "drawGeometry", True ) ) maya.cmds.menuItem( label = "All Child Bounds On", radialPosition = "SE", command = IECore.curry( __setChildrenPreviewAttributes, sceneShapes, "drawChildBounds", True ) ) maya.cmds.menuItem( label = "All Root Bound On", radialPosition = "NE", command = IECore.curry( __setChildrenPreviewAttributes, sceneShapes, "drawRootBound", True ) ) maya.cmds.menuItem( label = "All Geometry Off", radialPosition = "W", command = IECore.curry( __setChildrenPreviewAttributes, sceneShapes, "drawGeometry", False ) ) maya.cmds.menuItem( label = "All Child Bounds Off", radialPosition = "SW", command = IECore.curry( __setChildrenPreviewAttributes, sceneShapes, "drawChildBounds", False ) ) maya.cmds.menuItem( label = "All Root Bound Off", radialPosition = "NW", command = IECore.curry( __setChildrenPreviewAttributes, sceneShapes, "drawRootBound", False ) ) maya.cmds.setParent( "..", menu=True ) commonTags = None for fn in fnScS: scene = fn.sceneInterface() tmpTags = scene.readTags(IECore.SceneInterface.EveryTag) if commonTags is None: commonTags = set( tmpTags ) else: commonTags.intersection_update( set(tmpTags) ) tagTree = dict() if not commonTags is None: tags = list(commonTags) for tag in tags : tag = str(tag) parts = tag.split(":") leftOverTag = tag[len(parts[0])+1:] if not parts[0] in tagTree : tagTree[parts[0]] = [ leftOverTag ] else : tagTree[parts[0]].append( leftOverTag ) if tagTree : maya.cmds.menuItem( label = "Tags filter...", radialPosition = "S", subMenu = True ) maya.cmds.menuItem( label = "Display All", command = IECore.curry( __setTagsFilterPreviewAttributes, sceneShapes, "" ) ) tags = tagTree.keys() tags.sort() for tag in tags : subtags = tagTree[tag] subtags.sort() if "" in subtags: maya.cmds.menuItem( label = tag, command = IECore.curry( __setTagsFilterPreviewAttributes, sceneShapes, tag ) ) subtags.remove("") if subtags: maya.cmds.menuItem( label = tag, subMenu = True ) for tagSuffix in subtags : maya.cmds.menuItem( label = tagSuffix, command = IECore.curry( __setTagsFilterPreviewAttributes, sceneShapes, tag + ":" + tagSuffix ) ) maya.cmds.setParent( "..", menu=True ) maya.cmds.setParent( "..", menu=True ) maya.cmds.menuItem( label = "Expand...", radialPosition = "SE", subMenu = True ) maya.cmds.menuItem( label = "Recursive Expand As Geometry", radialPosition = "W", command = IECore.curry( __expandAsGeometry, sceneShapes ) ) if any( map(lambda x: x.canBeExpanded(), fnScS) ): maya.cmds.menuItem( label = "Expand One Level", radialPosition = "E", command = IECore.curry( __expandOnce, sceneShapes ) ) maya.cmds.menuItem( label = "Recursive Expand", radialPosition = "N", command = IECore.curry( __expandAll, sceneShapes ) ) if len( sceneShapes ) == 1: if fnScS[0].selectedComponentNames() : maya.cmds.menuItem( label = "Expand to Selected Components", radialPosition = "S", command = IECore.curry( __expandToSelected, sceneShapes[0] ) ) maya.cmds.setParent( "..", menu=True ) parentSceneShape = __parentSceneShape( sceneShapes ) if any( map(lambda x: x.canBeCollapsed(), fnScS) ) or ( parentSceneShape and IECoreMaya.FnSceneShape( parentSceneShape ).canBeCollapsed() ): maya.cmds.menuItem( label = "Collapse...", radialPosition = "SW", subMenu = True ) if parentSceneShape and IECoreMaya.FnSceneShape( parentSceneShape ).canBeCollapsed(): parentName = maya.cmds.listRelatives( parentSceneShape, p=True )[0] maya.cmds.menuItem( label = "Collapse to Parent: "+parentName, radialPosition = "N", command = IECore.curry( __collapseChildren, [parentSceneShape] ) ) if any( map(lambda x: x.canBeCollapsed(), fnScS) ): maya.cmds.menuItem( label = "Collapse Children", radialPosition = "W", command = IECore.curry( __collapseChildren, sceneShapes ) ) maya.cmds.setParent( "..", menu=True ) for c in __dagMenuCallbacks : c( menu, sceneShape )
def _expandAsGeometry( sceneShapes, tagName=None, *unused) : for sceneShape in sceneShapes: fnS = IECoreMaya.FnSceneShape( sceneShape ) fnS.convertAllToGeometry( True, tagName )
def _menuDefinition( callbackShape ) : sceneShapes = __selectedSceneShapes() if not sceneShapes : return mainDef = IECore.MenuDefinition() fnShapes = [ IECoreMaya.FnSceneShape( shape ) for shape in sceneShapes ] # INVALID SHAPES invalidSceneShapes = __invalidSceneShapes( sceneShapes ) if invalidSceneShapes : mainDef.append( "/Invalid Inputs for selected SceneShapes!", { "blindData" : { "maya" : { "radialPosition" : "N" } } } ) return mainDef # COMPONENT MODE if fnShapes[ 0 ].selectedComponentNames() : mainDef.append( "/Object", { "blindData" : { "maya" : { "radialPosition" : "N" } }, "command" : functools.partial( __objectCallback, sceneShapes[ 0 ] ) } ) mainDef.append( "/Print Component Names", { "blindData" : { "maya" : { "radialPosition" : "NW" } }, "command" : functools.partial( __printComponents, sceneShapes[ 0 ] ) } ) mainDef.append( "/Print Selected Component Names", { "blindData" : { "maya" : { "radialPosition" : "NE" } }, "command" : functools.partial( __printSelectedComponents, sceneShapes[ 0 ] ) } ) # EXPAND expandDef = IECore.MenuDefinition( [ ("/Expand to Selected Components", { "blindData" : { "maya" : { "radialPosition" : "S" } }, "command" : functools.partial( __expandToSelected, sceneShapes[ 0 ] ) }), ] ) mainDef.append( "/Expand...", { "blindData" : { "maya" : { "radialPosition" : "SE" } }, "subMenu" : expandDef } ) locatorDef = IECore.MenuDefinition( [ ("/At Bound Min", { "blindData" : { "maya" : { "radialPosition" : "N" } }, "command" : functools.partial( __createLocatorAtPoints, sceneShapes[ 0 ], [ "Min" ] ) }), ("/At Bound Max", { "blindData" : { "maya" : { "radialPosition" : "NE" } }, "command" : functools.partial( __createLocatorAtPoints, sceneShapes[ 0 ], [ "Max" ] ) }), ("/At Bound Min And Max", { "blindData" : { "maya" : { "radialPosition" : "E" } }, "command" : functools.partial( __createLocatorAtPoints, sceneShapes[ 0 ], [ "Min", "Max" ] ) }), ("/At Bound Centre", { "blindData" : { "maya" : { "radialPosition" : "SE" } }, "command" : functools.partial( __createLocatorAtPoints, sceneShapes[ 0 ], [ "Center" ] ) }), ("/At Transform Origin", { "blindData" : { "maya" : { "radialPosition" : "S" } }, "command" : functools.partial( __createLocatorWithTransform, sceneShapes[ 0 ] ) }), ] ) mainDef.append( "/Create Locator", { "blindData" : { "maya" : { "radialPosition" : "SW" } }, "subMenu" : locatorDef } ) # OBJECT MODE else : # PREVIEW if len( sceneShapes ) == 1 and (maya.cmds.getAttr( sceneShapes[ 0 ] + ".drawGeometry" ) or maya.cmds.getAttr( sceneShapes[ 0 ] + ".drawChildBounds" )) : mainDef.append( "/Component", { "blindData" : { "maya" : { "radialPosition" : "N" } }, "command" : functools.partial( __componentCallback, sceneShapes[ 0 ] ) } ) previewDef = IECore.MenuDefinition( [ ("/All Geometry On", { "blindData" : { "maya" : { "radialPosition" : "E" } }, "command" : functools.partial( __setChildrenPreviewAttributes, sceneShapes, "drawGeometry", True ) }), ("/All Child Bounds On", { "blindData" : { "maya" : { "radialPosition" : "SE" } }, "command" : functools.partial( __setChildrenPreviewAttributes, sceneShapes, "drawChildBounds", True ) }), ("/All Root Bound On", { "blindData" : { "maya" : { "radialPosition" : "NE" } }, "command" : functools.partial( __setChildrenPreviewAttributes, sceneShapes, "drawRootBound", True ) }), ("/All Geometry Off", { "blindData" : { "maya" : { "radialPosition" : "W" } }, "command" : functools.partial( __setChildrenPreviewAttributes, sceneShapes, "drawGeometry", False ) }), ("/All Child Bounds Off", { "blindData" : { "maya" : { "radialPosition" : "SW" } }, "command" : functools.partial( __setChildrenPreviewAttributes, sceneShapes, "drawChildBounds", False ) }), ("/All Root Bound Off", { "blindData" : { "maya" : { "radialPosition" : "NE" } }, "command" : functools.partial( __setChildrenPreviewAttributes, sceneShapes, "drawRootBound", False ) }) ] ) mainDef.append( "/Preview...", { "blindData" : { "maya" : { "radialPosition" : "NW" } }, "subMenu" : previewDef } ) # get all tags that are shared between all shapes commonTags = None for fn in fnShapes : scene = fn.sceneInterface() tmpTags = scene.readTags( IECoreScene.SceneInterface.EveryTag ) if commonTags is None : commonTags = set( tmpTags ) else : commonTags.intersection_update( set( tmpTags ) ) tagTree = dict() if commonTags : for tag in commonTags : tag = str( tag ) namespace, _, subTagsString = tag.partition( ':' ) subTags = set( subTagsString.split( ':' ) ) if not namespace in tagTree : tagTree[ namespace ] = subTags else : tagTree[ namespace ].update( subTags ) # EXPAND expandDef = IECore.MenuDefinition( [ ("/Recursive Expand As Geometry", { "blindData" : { "maya" : { "radialPosition" : "W" } }, "command" : functools.partial( _expandAsGeometry, sceneShapes)})] ) mainDef.append( "/Expand...", { "blindData" : { "maya" : { "radialPosition" : "SE" } }, "subMenu" : expandDef } ) if any( map( lambda x : x.canBeExpanded(), fnShapes ) ) : expandDef.append( "/Expand One Level", { "blindData" : { "maya" : { "radialPosition" : "S" } }, "command" : functools.partial( __expandOnce, sceneShapes ) } ) expandDef.append( "/Recursive Expand", { "blindData" : { "maya" : { "radialPosition" : "E" } }, "command" : functools.partial( _expandAll, sceneShapes)}) if len( sceneShapes ) == 1 and fnShapes[ 0 ].selectedComponentNames() : expandDef.append( "/Expand to Selected Components", { "blindData" : { "maya" : { "radialPosition" : "S" } }, "command" : functools.partial( __expandToSelected, sceneShapes[ 0 ] ) } ) if tagTree : tags = tagTree.keys() tags.sort() def addTagSubMenuItems( menuDef, command ) : import copy copiedTagTree = copy.deepcopy( tagTree ) for tag in tags : subtags = list( copiedTagTree[ tag ] ) subtags.sort() for subtag in subtags : if subtag == '' : label = "/{}".format( tag ) expandTag = tag else : label = "/{}/{}".format( tag, subtag ) expandTag = "{}:{}".format( tag, subtag ) menuDef.append( label, { "command" : functools.partial( command, sceneShapes, expandTag ) } ) filterDef = IECore.MenuDefinition( [ ("/Display All", { "command" : functools.partial( _setTagsFilterPreviewAttributes, sceneShapes, "")}) ] ) expandTagDef = IECore.MenuDefinition() expandTagGeoDef = IECore.MenuDefinition() mainDef.append( "/Tags filter...", { "blindData" : { "maya" : { "radialPosition" : "S" } }, "subMenu" : filterDef } ) addTagSubMenuItems( filterDef, _setTagsFilterPreviewAttributes) addTagSubMenuItems( expandTagDef, _expandAll) addTagSubMenuItems( expandTagGeoDef, _expandAsGeometry) expandDef.append( "/Expand by Tag...", { "blindData" : { "maya" : { "radialPosition" : "SE" } }, "subMenu" : expandTagDef } ) expandDef.append( "/Expand by Tag as Geo...", { "blindData" : { "maya" : { "radialPosition" : "SW" } }, "subMenu" : expandTagGeoDef } ) parentSceneShape = __parentSceneShape( sceneShapes ) # COLLAPSE if any( map( lambda x : x.canBeCollapsed(), fnShapes ) ) or (parentSceneShape and IECoreMaya.FnSceneShape( parentSceneShape ).canBeCollapsed()) : collapseDef = IECore.MenuDefinition() if parentSceneShape and IECoreMaya.FnSceneShape( parentSceneShape ).canBeCollapsed() : parentName = maya.cmds.listRelatives( parentSceneShape, p = True )[ 0 ] collapseDef.append( "/Collapse to Parent: {}".format( parentName ), { "blindData" : { "maya" : { "radialPosition" : "N" } }, "command" : functools.partial( __collapseChildren, [ parentSceneShape ] ) } ) if any( map( lambda x : x.canBeCollapsed(), fnShapes ) ) : collapseDef.append( "/Collapse Children", { "blindData" : { "maya" : { "radialPosition" : "W" } }, "command" : functools.partial( __collapseChildren, sceneShapes ) } ) mainDef.append( "/Collapse...", { "blindData" : { "maya" : { "radialPosition" : "SW" } }, "subMenu" : collapseDef } ) return mainDef
def __collapseChildren( sceneShapes, *unused ) : for sceneShape in sceneShapes: fnS = IECoreMaya.FnSceneShape( sceneShape ) fnS.collapse()
def __expandAsGeometry( sceneShapes, *unused ) : for sceneShape in sceneShapes: fnS = IECoreMaya.FnSceneShape( sceneShape ) fnS.convertAllToGeometry()