def run(self): """ This method is where your nimble script should be implemented. Prior to Nimble calling this method the class receives the arguments passed through Nimble needed by the your method implementation. """ # Retrieve the arguments passed by Nimble using the fetch method, which includes a default # value to assign if the argument was not specified in the Nimble call sphereCount = self.fetch('count', 6) ringRadius = self.fetch('radius', 10) yOffset = self.fetch('y', 0) # Create the spheres using Maya commands imported through Nimble, which allows this script # to be run flexibly both inside and outside of Maya sphereNames = [] for i in range(sphereCount): result = cmds.sphere() sphereNames.append(result[0]) # Position the sphere in the ring cmds.move( ringRadius*math.cos(2.0*math.pi*i/sphereCount), 0, ringRadius*math.sin(2.0*math.pi*i/sphereCount), result[0]) # Place the spheres within a group node to represent the ring and move the group up the # y-axis by the value specified by the script arguments ringGroupNode = cmds.group(*sphereNames, name='sphereRing1') cmds.move(0, yOffset, 0, ringGroupNode) # Set the results of the script with the put command for returning to the Nimble calling # environment self.put('ringName', ringGroupNode) self.put('sphereNames', sphereNames)
def _handleExampleButton(self): """ makes the bubble """ x = 0 y = 0 z = 0 sx = 0.1 # original scale size x sy = 0.1 # original scale size y sz = 0.1 # original scale size z so = 0.1 # scale original for exp growth form maxY = 30 # highest bound maxX = 5 # max horizon bound maxZ = 5 # max horzon bound keyStep = 3 # 3 * 10 = 30 fps totalTime = 10 # number of seconds of animation maxKey = totalTime * keyStep * 10 # max num of keys for the time minHdev = -2.0 # max movement between horizon space maxHdev = 2.0 # max movement beteen horiz space scaleRate = 0.2 # for growth of bubble exponentially as a decimal time = 0 # amount of time since bubble creation bubbleToTop = 1 # seconds for life of bubble # Create Material # Start bubble_mat bubbleShader = mayaShader('bubble_mat', (0.0, 0.8, 1.0), (0.9, 0.9, 0.9), (0.8, 0.8, 0.8), 'blinn') bubbleShader.create() #end bubble_mat # Create Spehere nurb, the [0] selects first node of object r = 1 yUp = (0, 1, 0) # start creation at y-up p = (0, 0, 0) # object pivot point d = 3 # degree bNum = 1 # bNum is the bubble number c = cmds.sphere(p=p, ax=yUp, ssw=0, esw=360, r=r, d=d, ut=0, tol=0.01, s=8, nsp=4, ch=1, n='bubble' + str(bNum))[0] cmds.select(c) # Assign bubble_mat cmds.hyperShade(a="bubble_mat") for i in xrange(1, maxKey, keyStep): cmds.currentTime(i) cmds.setKeyframe(v=y, at='translateY') cmds.setKeyframe(v=x, at='translateX') cmds.setKeyframe(v=z, at='translateZ') x = x + uniform(minHdev, maxHdev) z = z + uniform(minHdev, maxHdev) y = y + (keyStep / bubbleToTop) if x >= maxX: x = maxX if z >= maxZ: z = maxZ sx = so * ((1 + scaleRate)**time) sz = so * ((1 + scaleRate)**time) sy = so * ((1 + scaleRate)**time) cmds.setKeyframe(v=sy, at='scaleY') cmds.setKeyframe(v=sx, at='scaleX') cmds.setKeyframe(v=sz, at='scaleZ') time = time + 1 if y > maxY: break # terminate movement which can explode bubble later response = nimble.createRemoteResponse(globals()) response.put('name', c)
To use the Maya Python commands the import statement at the beginning of your script looks like: from maya import cmds and then you can call commands, such as: cmds.move(1, 0, 0, 'someNode') which moves the 'someNode' by 1 unit in the x direction. To use the nimble commands module all you need to do is replace the maya commands import with the nimble commands import: from nimble import cmds after which you call commands in the exact same fashion: cmds.move(1, 0, 0, 'someNode') """ from __future__ import print_function, absolute_import, unicode_literals, division from nimble import cmds # Create a sphere sphereName, sphereShape = cmds.sphere() # Move the created sphere to x=10 cmds.move(10, 0, 0, sphereName)
def _handleExampleButton(self): """ This callback creates a polygonal container and fills it with bubbles. """ sx = 0.1 # original scale size x sy = 0.1 # original scale size y sz = 0.1 # original scale size z so = 0.1 # scale original for exp growth form maxY = 10 # highest bound maxX = 5 # max horizon bound maxZ = 5 # max horzon bound # Create container material containerShader = mayaShader('container_mat', (0.6, 0.6, 0.6), (0.9, 0.9, 0.9), (0.8, 0.8, 0.8), 'blinn') containerShader.create() # Create Container cHeight = 12 c = cmds.polyCylinder(r=11, h=cHeight, sx=40, sy=10, sz=0, ax=(0, 1, 0), rcp=0, cuv=3, ch=1, n='container1')[0] cmds.select(c) cmds.setAttr("container1.translateY", cHeight / 2 - 0.5) # create another mesh smaller cHeight = 12 c = cmds.polyCylinder(r=10.5, h=cHeight, sx=40, sy=10, sz=0, ax=(0, 1, 0), rcp=0, cuv=3, ch=1, n='container2')[0] cmds.select(c) cmds.setAttr("container2.translateY", cHeight / 2) # Boolean difference for making container cmds.polyCBoolOp('container1', 'container2', op=2, n='container') # Assign container_mat cmds.hyperShade(a="container_mat") keyStep = 3 # 3 * 10 = 30 fps totalTime = 10 # number of seconds of animation maxKey = totalTime * keyStep * 10 # max num of keys for the time minHdev = -2.0 # max movement between horizon space maxHdev = 2.0 # max movement beteen horiz space numBubbles = 50 # make 20 bubbles scaleRate = 0.2 # for growth of bubble exponentially as a decimal bubbleToTop = 1 # seconds for life of bubble # Create Material # Start bubble_mat bubbleShader = mayaShader('bubble_mat', (0.0, 0.8, 1.0), (0.9, 0.9, 0.9), (0.8, 0.8, 0.8), 'blinn') bubbleShader.create() #end bubble_mat for i in xrange(0, numBubbles): x = 0 y = 0 z = 0 time = 0 # amount of time since bubble creation # Create Spehere nurb, the [0] selects first node of object randX = uniform(-maxX, maxX) randZ = uniform(-maxZ, maxZ) r = 1 yUp = (0, 1, 0) # start creation at y-up p = (randX, 0, randZ) # object pivot point d = 3 # degree bNum = 1 # bNum is the bubble number c = cmds.sphere(p=p, ax=yUp, ssw=0, esw=360, r=r, d=d, ut=0, tol=0.01, s=8, nsp=4, ch=1, n='bubble' + str(bNum))[0] cmds.select(c) # Assign bubble_mat cmds.hyperShade(a="bubble_mat") randFrameStart = randint(1, maxKey) # Start randomly in time for j in xrange(randFrameStart, maxKey, keyStep): cmds.currentTime(j) cmds.setKeyframe(v=y, at='translateY') cmds.setKeyframe(v=x, at='translateX') cmds.setKeyframe(v=z, at='translateZ') x = x + uniform(minHdev, maxHdev) z = z + uniform(minHdev, maxHdev) y = y + (keyStep / bubbleToTop) print(y) if x >= maxX: x = maxX if z >= maxZ: z = maxZ sx = so * ((1 + scaleRate)**time) sz = so * ((1 + scaleRate)**time) sy = so * ((1 + scaleRate)**time) cmds.setKeyframe(v=sy, at='scaleY') cmds.setKeyframe(v=sx, at='scaleX') cmds.setKeyframe(v=sz, at='scaleZ') time = time + 1 if y > maxY: break # terminate movement which can explode bubble later response = nimble.createRemoteResponse(globals()) response.put('name', c)