Beispiel #1
0
    def saveScreenshot(self, name, directory):
        """
        Saves screenshot out to disk
        Args:
            name: Name of the screenshot
            directory: Directory to save into
        """
        # get camera, current position and focus object
        cameraName = cmds.lookThru(q=True)
        prevPosition = cmds.getAttr("{0}.translate".format(cameraName))
        objName = cmds.ls(sl=True, l=True)
        if objName:
            objName = objName[0]
        else:
            cmds.error("No object has been selected")

        # frame camera to object
        cmds.viewFit()  # 'f' on keyboard
        distance = lib.distanceBetween(cameraName, objName)
        frameDistance = distance * 0.5
        cmds.dolly(cameraName, d=-frameDistance)

        # take screenshot
        screenshotDir = mnpr_system.renderFrame(os.path.join(directory, name),
                                                100, 100, 1, ".jpg")

        # bring camera back to normal
        lib.setAttr(cameraName, "translate", prevPosition)
        return screenshotDir
Beispiel #2
0
    def testImportDisplayColor(self):
        """Tests that the import of the USD preview surface containing a connected displayColor
        primvar reader shader node is imported with vertex colours for textured display"""
        cmds.file(force=True, new=True)
        mayaUtils.loadPlugin("mayaUsdPlugin")

        # Turn on textured display and focus in on the subject
        panel = mayaUtils.activeModelPanel()
        cmds.modelEditor(panel, e=1, displayTextures=1)
        cmds.dolly("persp", abs=True, d=3.2)

        # Import the USD file
        testFile = testUtils.getTestScene("UsdPreviewSurface",
                                          "DisplayColorCube.usda")
        options = [
            "shadingMode=[[useRegistry,UsdPreviewSurface]]", "primPath=/",
            "preferredMaterial=none"
        ]
        cmds.file(testFile,
                  i=True,
                  type="USD Import",
                  ignoreVersion=True,
                  ra=True,
                  mergeNamespacesOnClash=False,
                  namespace="Test",
                  pr=True,
                  importTimeRange="combine",
                  options=";".join(options))

        # Snapshot and assert similarity
        self.assertSnapshotClose('DisplayColorCube.png')
Beispiel #3
0
def run(max_iteration, size, c):
    """
	Generates a visualization of the Julia set by printing cubes in space in Maya
	Parameters:
		max_Iteration - maximum number of cubes to print 
		size - the size of our printing canvas
		c - constant complex variable of the formula z = z*z + c, which affects the result
	"""
    # Initialize scene
    cmds.file(new=True, force=True)
    cmds.lookThru('top')
    cmds.grid(toggle=False)

    # Setup window for progress bar
    window = cmds.window()
    cmds.columnLayout()
    progressControl = cmds.progressBar(maxValue=size**2, width=300)
    cmds.showWindow(window)

    # Create shades of grey to paint cubes with based on depth
    for i in range(max_iteration + 1):
        shader = cmds.shadingNode("blinn",
                                  asShader=True,
                                  name="shader" + str(i))
        attr = shader + ".color"
        cmds.setAttr(attr, i / float(max_iteration), i / float(max_iteration),
                     i / float(max_iteration))

    # Specify real and imaginary range of image
    re_min, re_max = -2.0, 2.0
    im_min, im_max = -2.0, 2.0
    scX = (abs(re_min) + abs(re_max)) / size
    scZ = (abs(im_min) + abs(im_max)) / size

    # Generate evenly spaced values over real and imaginary ranges
    real_range = numpy.arange(re_min, re_max, (re_max - re_min) / size)
    imag_range = numpy.arange(im_max, im_min, (im_min - im_max) / size)

    # Run through the grid of our canvas size (size X size)
    for im in imag_range:
        for re in real_range:
            # Initialize z (according to complex plane) and number of iterations
            z = complex(re, im)
            iteration = 0

            # While z is within our space boundaries and we have not exceeded our maximum iteration:
            while abs(z) < 10 and iteration < max_iteration:
                z = z * z + c
                iteration += 1

            # Draw appropriate cube in space
            cmds.polyCube(n="cube" + str(im) + str(re))
            cmds.move(im, 0, re)
            cmds.scale(scX, 0.1, scZ)
            cmds.hyperShade(assign="shader" + str(iteration))

            # Update progress bar and viewport
            cmds.progressBar(progressControl, edit=True, step=1)
            cmds.viewFit('top', all=True)
            cmds.dolly('top', os=1.5)
            cmds.refresh()

    # Update progress bar and viewport
    cmds.progressBar(progressControl, edit=True, step=1)
    cmds.refresh()
    cmds.toggleWindowVisibility(window)
def run(max_iteration, size, c):
    """
	Generates a visualization of the Mandelbrot set by printing cubes in space in Maya
	Parameters:
		max_Iteration - maximum number of cubes to print 
		size - the size of our printing canvas
		c - complex variable of the formula z = z*z + c, which affects the result
	"""
    # Initialize scene
    cmds.file(new=True, force=True)
    cmds.lookThru('top')
    cmds.grid(toggle=False)

    # Setup window for progress bar
    window = cmds.window()
    cmds.columnLayout()
    progressControl = cmds.progressBar(maxValue=size**2, width=300)
    cmds.showWindow(window)

    # Create shades of grey to paint cubes with based on depth
    for i in range(max_iteration + 1):
        shader = cmds.shadingNode("blinn",
                                  asShader=True,
                                  name="shader" + str(i))
        attr = shader + ".color"
        cmds.setAttr(attr, i / float(max_iteration), i / float(max_iteration),
                     i / float(max_iteration))

    # Set center of complex plane
    x_center = c.real
    y_center = c.imag
    # Run through the grid of our canvas size (size X size)
    for i in range(size):
        for j in range(size):
            # Re-evaluate c according to current 'pixel' to be drawn
            c = complex(x_center + 4.0 * float(i - size / 2) / size,
                        y_center + 4.0 * float(j - size / 2) / size)

            # Initialize z and number of iterations
            z = 0 + 0j
            iteration = 0

            # While z is within our space boundaries and we have not exceeded our maximum iteration:
            while (abs(z) <= 2.0 and iteration < max_iteration):
                z = z**2 + c  # Re-evaluate z, based on formula z = z*z + c
                iteration += 1

            # Draw appropriate cube in space
            cmds.polyCube(n="cube" + str(i) + str(j))
            cmds.move(i, 0, j)
            cmds.hyperShade(assign="shader" + str(iteration))

            # Update progress bar and viewport
            cmds.progressBar(progressControl, edit=True, step=1)
            cmds.viewFit('top', all=True)
            cmds.dolly('top', os=1.5)
            cmds.refresh()
    # Update progress bar and viewport
    cmds.progressBar(progressControl, edit=True, step=1)
    cmds.refresh()
    cmds.toggleWindowVisibility(window)
def run(max_Iteration, size):
	"""
	Generates a visualization of the Barnsley Fern by printing spheres in space in Maya
	Parameters:
		max_Iteration - maximum number of cubes to print 
		size - the size of our printing canvas
	"""
	# Initialize scene
	cmds.file(new = True, force = True)
	cmds.lookThru( 'top' )
	cmds.grid(toggle=False)
	
	# Setup window for progress bar
	window = cmds.window()
	cmds.columnLayout()
	progressControl = cmds.progressBar(maxValue=max_Iteration, width=300)
	cmds.showWindow(window)
	
	# Create shader to paint spheres with
	shader=cmds.shadingNode("blinn",asShader=True, name = "shader" + str(1))
	attr = shader + ".color"
	cmds.setAttr (attr, 1,1,1)
	
	# Setup matrix A containing appropriate affine transformations
	A=[]
	mat=[[0.0,0.0,0.0,0.16,0.0,0.0,0.01],
		[0.85,0.04,-0.04,0.85,0.0,1.6,0.85],
		[0.2,-0.26,0.23,0.22,0.0,1.6,0.07],
		[-0.15,0.28,0.26,0.24,0.0,0.44,0.07]]
	# Set starting point (x,y) = (0,0)
	x=0.0
	y=0.0
	
	# Draw max_Iteration number of spheres
	for iteration in range(max_Iteration):
		# Select random transformation to compute
		p=random.random()
		if p <= mat[0][6]:
			i=0
		elif p <= mat[0][6] + mat[1][6]:
			i=1
		elif p <= mat[0][6] + mat[1][6] + mat[2][6]:
			i=2
		else:
			i=3
		# Compute above transformation:
		x0 = x * mat[i][0] + y * mat[i][1] + mat[i][4]
		y  = x * mat[i][2] + y * mat[i][3] + mat[i][5]
		x = x0
		
		# Draw corresponding sphere in space
		cmds.polySphere(n="sp"+str(iteration))
		cmds.move(size*x,0,-size*y)
		cmds.scale(0.5,0.5,0.5)  
		cmds.hyperShade(assign="shader"+str(1))
		
		# Update progress bar and viewport
		cmds.progressBar(progressControl, edit=True, step=1)
		cmds.viewFit( 'top', all=True )
		cmds.dolly( 'top', os=1.5 )
		cmds.refresh()
		
	# Update progress bar and viewport
	cmds.progressBar(progressControl, edit=True, step=1)
	cmds.refresh()
	cmds.toggleWindowVisibility(window)
Beispiel #6
0
    cmds.setKeyframe( bubble, attribute='scaleX', value=size+0.02*time,  t=time )
    cmds.setKeyframe( bubble, attribute='scaleY', value=size+0.02*time,  t=time )
    cmds.setKeyframe( bubble, attribute='scaleZ', value=size+0.02*time,  t=time )
        #mc.setKeyframe( bubble, attribute='translateZ', value=pz, t=f )

#cmds.rename(obj[1], "bubbleCamShape")


# Save the current position of the persp camera.
homeName = cmds.cameraView(camera='persp')

# Add this view to the persp bookmark menu.
cmds.cameraView( homeName, e=True, camera='bubbleCam', ab=True )

# Change the persp camera position.
cmds.dolly( 'bubbleCam', distance=-30 )

# Create another bookmark for the zoomed position.
cmds.cameraView( camera='bubbleCam', name='zoom', ab=True )

# Restore original camera position.
cmds.cameraView( homeName, e=True, camera='bubbleCam', sc=True )

# Save the current 2D pan/zoom attributes of the persp camera
panZoomBookmark = cmds.cameraView( camera='bubbleCam', ab=True, typ=1 )

# Enable 2D pan/zoom
cmds.setAttr( 'bubbleCamShape.panZoomEnabled', True )

# Pan right
cmds.panZoom( 'bubbleCam', r=0.6 )
def run(max_Iteration, size):
    """
	Generates a visualization of a region of the Apollonean Gasket by printing spheres in space in Maya
	Parameters:
		max_Iteration - maximum number of cubes to print 
		size - the size of our printing canvas
	"""
    # Initialize scene
    cmds.file(new=True, force=True)
    cmds.lookThru('top')
    cmds.grid(toggle=False)

    # Setup window for progress bar
    window = cmds.window()
    cmds.columnLayout()
    progressControl = cmds.progressBar(maxValue=max_Iteration, width=300)
    cmds.showWindow(window)

    # Initialize fractal variables
    s = math.sqrt(3.0)

    def f(z):
        return 3.0 / (1.0 + s - z) - (1.0 + s) / (2.0 + s)

    ifs = [
        "f(z)", "f(z) * complex(-1.0, s) / 2.0",
        "f(z) * complex(-1.0, -s) / 2.0"
    ]
    xa = -0.6
    xb = 0.9
    ya = -0.75
    yb = 0.75
    z = complex(0.0, 0.0)

    # Create shader to paint spheres with
    shader = cmds.shadingNode("blinn", asShader=True, name="shader" + str(1))
    attr = shader + ".color"
    cmds.setAttr(attr, 1, 1, 1)

    # Draw max_Iteration number of spheres
    for i in range(max_Iteration):
        # Compute z and kx, ky
        z = eval(ifs[random.randint(0, 2)])
        kx = int((z.real - xa) / (xb - xa) * (size - 1))
        ky = int((z.imag - ya) / (yb - ya) * (size - 1))
        # Update progress bar
        cmds.progressBar(progressControl, edit=True, step=1)
        # If kx and kz are within our drawing canvas draw sphere:
        if kx >= 0 and kx < size and ky >= 0 and ky < size:
            cmds.polySphere(n="sp" + str(i))
            cmds.move(kx, 0, ky)
            cmds.scale(0.5, 0.5, 0.5)
            cmds.hyperShade(assign="shader" + str(1))

            # Update viewport
            cmds.viewFit('top', all=True)
            cmds.dolly('top', os=1.5)
            cmds.refresh()

    # Update progress bar and viewport
    cmds.progressBar(progressControl, edit=True, step=1)
    cmds.refresh()
    cmds.toggleWindowVisibility(window)
Beispiel #8
0
def run(max_Iteration, size):
    """
	Generates a visualization of the Sierpinski triangle by printing cubes in space in Maya
	Parameters:
		max_Iteration - maximum number of cubes to print 
		size - the size of our printing canvas
	"""
    # Initialize scene
    cmds.file(new=True, force=True)
    cmds.lookThru('top')
    cmds.grid(toggle=False)

    # Setup window for progress bar
    window = cmds.window()
    cmds.columnLayout()
    progressControl = cmds.progressBar(maxValue=max_Iteration, width=300)
    cmds.showWindow(window)

    # Create shader to paint spheres with
    shader = cmds.shadingNode("blinn", asShader=True, name="shader" + str(1))
    attr = shader + ".color"
    cmds.setAttr(attr, 1, 1, 1)

    # Calculates the midpoint of point1 and point2 and returns result
    def midpoint(point1, point2):
        return [(point1[0] + point2[0]) / 2, (point1[1] + point2[1]) / 2]

    # Set starting point for Sierpinski algorithm
    curr_point = [0, 0]

    # Define an equilateral triangle in space
    v1 = [0, 0]
    v2 = [1, 0]
    v3 = [.5, np.sqrt(3) / 2]

    # Draw max_Iteration number of spheres
    for i in range(max_Iteration):
        val = randint(0, 2)  # Select random vertex of our equilateral triangle
        # Calculate midpoint of above vertex and our current point:
        if val == 0:
            curr_point = midpoint(curr_point, v1)
        if val == 1:
            curr_point = midpoint(curr_point, v2)
        if val == 2:
            curr_point = midpoint(curr_point, v3)

        # Draw corresponding sphere in space
        cmds.polySphere(n="sp" + str(i))
        cmds.move(size * curr_point[0], 0, size * curr_point[1])
        cmds.scale(0.5, 0.5, 0.5)
        cmds.hyperShade(assign="shader" + str(1))

        # Update progress bar and viewport
        cmds.progressBar(progressControl, edit=True, step=1)
        cmds.viewFit('top', all=True)
        cmds.dolly('top', os=1.5)
        cmds.refresh()
    # Update progress bar and viewport
    cmds.progressBar(progressControl, edit=True, step=1)
    cmds.refresh()
    cmds.toggleWindowVisibility(window)