Exemple #1
0
	def test_computeCenter( self ):
		starttime = time.time()

		# GET AVERAGE POSITION
		pos = api.MVector()
		nodecache = list()			# for the previous wrapped nodes

		for node in it.iterDagNodes( api.MFn.kTransform, asNode = True ):
			pos += node.getTranslation( api.MSpace.kWorld )
			nodecache.append( node )
		# END for each node

		nodecount = len( nodecache )
		pos /= float( nodecount )
		elapsed = time.time() - starttime

		print >> sys.stderr, "Average position of %i nodes is: <%f,%f,%f> in %f s" % ( nodecount, pos.x,pos.y,pos.z, elapsed )


		# NOW SET ALL NODES TO THE GIVEN VALUE
		starttime = time.time()

		for node in nodecache:
			node.setTranslation( pos, api.MSpace.kWorld )
		# END for each node

		elapsed = time.time() - starttime
		print >> sys.stderr, "Set %i nodes to average position in %f s ( %f / s )" % ( nodecount, elapsed, nodecount / elapsed )
		
		# set back to zero - this time we have the method cached, but not the mfnfunc
		starttime = time.time()
		null = api.MVector()
		for node in nodecache:
			node.setTranslation( null, api.MSpace.kWorld )
		# END for each node
		
		new_elapsed = time.time() - starttime
		print >> sys.stderr, "Set the same %i nodes back to null in %f s ( %f / s ) ( cached functions speedup = %f %%)" % ( nodecount, new_elapsed, nodecount / new_elapsed, (elapsed / new_elapsed)*100 )
		
		
		starttime = time.time()
		null = api.MVector()
		for node in nodecache:
			node._api_setTranslation( pos, api.MSpace.kWorld )
		# END for each node
		api_new_elapsed = time.time() - starttime
		print >> sys.stderr, "Set the same %i nodes back to average in %f s ( %f / s ) ( new api functions speedup = %f %%)" % ( nodecount, api_new_elapsed, nodecount / api_new_elapsed, (elapsed / api_new_elapsed)*100 )
		
		
		starttime = time.time()
		null = api.MVector()
		for node in nodecache:
			node._api_setTranslation( null, api.MSpace.kWorld )
		# END for each node
		api_new_elapsed = time.time() - starttime
		print >> sys.stderr, "Set the same %i nodes back to null in %f s ( %f / s ) ( cached api functions speedup = %f %%)" % ( nodecount, api_new_elapsed, nodecount / api_new_elapsed, (elapsed / api_new_elapsed)*100 )
Exemple #2
0
	def test_randomizeScene( self ):
		starttime = time.time()
		nodecount = 0
		vec = api.MVector()
		for i, node in enumerate( it.iterDagNodes( api.MFn.kTransform, asNode = True ) ):
			vec.x = i*3
			vec.y = i*3+1
			vec.z = i*3+2
			node.setTranslation( vec, api.MSpace.kWorld )
			nodecount += 1
		# END for each object
		elapsed = time.time() - starttime
		print >> sys.stderr, "Randomized %i node translations in %f s ( %f / s )" % ( nodecount, elapsed, nodecount / elapsed )
Exemple #3
0
    def test_dagwalking( self ):

        # numnodes = [ 2500, 25000, 100000 ]
        numnodes = [ 2500 ]
        for nodecount in numnodes:
            benchfile = get_maya_file( "large_scene_%i.mb" % nodecount )
            mrvmaya.Scene.open( benchfile, force = 1 )

            # DIRECT ITERATOR USE
            st = time.time( )
            iterObj = api.MItDag( )
            nc = 0
            while not iterObj.isDone( ):
                dPath = api.MDagPath( )
                iterObj.getPath( dPath )
                iterObj.next()
                nc += 1
            # END for each dagpath
            elapsed = time.time() - st
            print >>sys.stderr, "Walked %i nodes directly in %f s ( %f / s )" % ( nc, elapsed, nc / elapsed )

            
            for dagPath in range(2):
                for traversalmode in range(2):
                    for asNode in range(2):
                        # DAGPATHS NO NODE CONVERSION
                        st = time.time( )
                        nc = 0
                        for dagpath in it.iterDagNodes( dagpath = dagPath, depth=traversalmode, asNode = asNode ):
                            nc += 1
                        elapsed = time.time() - st
                        print >>sys.stderr, "iterDagNode: Walked %i dag nodes (dagPath=%i, depth-first=%i, asNode=%i) in %f s ( %f / s )" % ( nc, dagPath, traversalmode, asNode, elapsed, nc / elapsed )
                    # END for each asNode value
                # END for each traversal
            # END for each dagpath mode
            
            # FROM LS
            st = time.time( )
            sellist = nt.toSelectionListFromNames( cmds.ls( type="dagNode" ) )
            nsl = len(sellist)
            for node in it.iterSelectionList( sellist, handlePlugs = False, asNode = False ):
                pass
            elapsed = time.time() - st
            print >>sys.stderr, "Listed %i nodes with ls in %f s ( %f / s )" % ( nsl, elapsed, nsl / elapsed )

            cmds.select( cmds.ls( type="dagNode" ) )
            st = time.time( )
            sellist = api.MSelectionList()
            api.MGlobal.getActiveSelectionList( sellist )
            nsl = len(sellist)
            
            # selection list testing
            for asNode in range(2):
                for handlePlugs in range(2):
                    for handleComponents in range(2):
                        st = time.time( )
                        for item in it.iterSelectionList( sellist, handlePlugs=handlePlugs, 
                                                            asNode=asNode, handleComponents=handleComponents ):
                            pass
                        # END for each item
                        elapsed = time.time() - st
                        print >>sys.stderr, "iterSelList: Listed %i nodes from active selection (asNode=%i, handlePlugs=%i, handleComponents=%i) in %f s ( %f / s )" % ( nsl, asNode, handlePlugs, handleComponents, elapsed, nsl / elapsed )
                    # END for handle components
                # END for handle plugs 
            # END for asNode
                
            # dg walking
            for asNode in range(2):
                nc = 0
                st = time.time( )
                for node in it.iterDgNodes(asNode=asNode):
                    nc += 1
                # END for each node
                elapsed = time.time() - st
                print >>sys.stderr, "iterDgNodes: Walked %i nodes (asNode=%i) in %f s ( %f / s )" % ( nc, asNode, elapsed, nc / elapsed )
            # END for each node
            
            # iterate namespaces
            for namespace in chain((ns.RootNamespace, ), ns.RootNamespace.childrenDeep()):
                self._iterate_namespace(namespace)
Exemple #4
0
	def test_dagwalking( self ):

		# numnodes = [ 2500, 25000, 100000 ]
		numnodes = [ 2500 ]
		for nodecount in numnodes:
			benchfile = get_maya_file( "large_scene_%i.mb" % nodecount )
			mrvmaya.Scene.open( benchfile, force = 1 )

			# DIRECT ITERATOR USE
			st = time.time( )
			iterObj = api.MItDag( )
			nc = 0
			while not iterObj.isDone( ):
				dPath = api.MDagPath( )
				iterObj.getPath( dPath )
				iterObj.next()
				nc += 1
			# END for each dagpath
			elapsed = time.time() - st
			print >>sys.stderr, "Walked %i nodes directly in %f s ( %f / s )" % ( nc, elapsed, nc / elapsed )

			
			for dagPath in range(2):
				for traversalmode in range(2):
					for asNode in range(2):
						# DAGPATHS NO NODE CONVERSION
						st = time.time( )
						nc = 0
						for dagpath in it.iterDagNodes( dagpath = dagPath, depth=traversalmode, asNode = asNode ):
							nc += 1
						elapsed = time.time() - st
						print >>sys.stderr, "iterDagNode: Walked %i dag nodes (dagPath=%i, depth-first=%i, asNode=%i) in %f s ( %f / s )" % ( nc, dagPath, traversalmode, asNode, elapsed, nc / elapsed )
					# END for each asNode value
				# END for each traversal
			# END for each dagpath mode
			
			# FROM LS
			st = time.time( )
			sellist = nt.toSelectionListFromNames( cmds.ls( type="dagNode" ) )
			nsl = len(sellist)
			for node in it.iterSelectionList( sellist, handlePlugs = False, asNode = False ):
				pass
			elapsed = time.time() - st
			print >>sys.stderr, "Listed %i nodes with ls in %f s ( %f / s )" % ( nsl, elapsed, nsl / elapsed )

			cmds.select( cmds.ls( type="dagNode" ) )
			st = time.time( )
			sellist = api.MSelectionList()
			api.MGlobal.getActiveSelectionList( sellist )
			nsl = len(sellist)
			
			# selection list testing
			for asNode in range(2):
				for handlePlugs in range(2):
					for handleComponents in range(2):
						st = time.time( )
						for item in it.iterSelectionList( sellist, handlePlugs=handlePlugs, 
															asNode=asNode, handleComponents=handleComponents ):
							pass
						# END for each item
						elapsed = time.time() - st
						print >>sys.stderr, "iterSelList: Listed %i nodes from active selection (asNode=%i, handlePlugs=%i, handleComponents=%i) in %f s ( %f / s )" % ( nsl, asNode, handlePlugs, handleComponents, elapsed, nsl / elapsed )
					# END for handle components
				# END for handle plugs 
			# END for asNode
				
			# dg walking
			for asNode in range(2):
				nc = 0
				st = time.time( )
				for node in it.iterDgNodes(asNode=asNode):
					nc += 1
				# END for each node
				elapsed = time.time() - st
				print >>sys.stderr, "iterDgNodes: Walked %i nodes (asNode=%i) in %f s ( %f / s )" % ( nc, asNode, elapsed, nc / elapsed )
			# END for each node
			
			# iterate namespaces
			for namespace in chain((ns.RootNamespace, ), ns.RootNamespace.childrenDeep()):
				self._iterate_namespace(namespace)