import maya.cmds as cmds import MASH.api as mapi reload(mapi) import maya.mel as mel import flux.core as fx def runPreset(): cmds.select(clear=True) # # Drop Window # # Add labels for each step of the smart preset steps = [ 'Step 1: Drag in your stuff:', 'Step 2: Drag in a pile starting shape (like a cone):' ] # List the accepted node types for each step acceptableNodeTypes = [ ['mesh'], ['mesh'] ] # create the drop window fx.DropWindow.getDrop(steps, callback=lambda data: smartPreset.send(data), title='MASH - Pile of Stuff', accepts=acceptableNodeTypes) node = yield # split the dragged nodes into a list and only use the first object nodes = node.split('\n') # get the largest bbox dimension, this will be the voxel size longestSide = 0 for obj in nodes: bbox = cmds.exactWorldBoundingBox(obj) tmpX = bbox[3] - bbox[0] if tmpX > longestSide: longestSide = tmpX tmpY = bbox[4] - bbox[1] if tmpY > longestSide: longestSide = tmpY tmpZ = bbox[5] - bbox[2] if tmpZ > longestSide: longestSide = tmpZ longestSide *= .8 # create a new MASH network mashNetwork = mapi.Network() mashNetwork.createNetwork(name = "MASH_Pile", geometry="Instancer") # get the second step drop node = yield # split the dragged nodes into a list and only use the first object node = node.split('\n')[0] # put the ground undreneath the pile object groundBBox = cmds.exactWorldBoundingBox(node) groundPosition = groundBBox[1] # set up the MASH network mashNetwork.meshDistribute(node, 6) cmds.setAttr(mashNetwork.distribute + '.voxelDensity', longestSide) cmds.setAttr(mashNetwork.distribute + '.voxelMode', 3) # fill inside with voxels # random rotations randomNode = mashNetwork.addNode("MASH_Random") cmds.setAttr(randomNode.name + '.positionX', 0) cmds.setAttr(randomNode.name + '.positionY', 0) cmds.setAttr(randomNode.name + '.positionZ', 0) cmds.setAttr(randomNode.name + '.rotationX', 360) cmds.setAttr(randomNode.name + '.rotationY', 360) cmds.setAttr(randomNode.name + '.rotationZ', 360) # add dynamice dynamicsNode = mashNetwork.addNode("MASH_Dynamics") cmds.setAttr(dynamicsNode.name + '.collisionShape', 4) # force convex hull for fast computation cmds.setAttr(dynamicsNode.name + '.friction', 1) cmds.setAttr(dynamicsNode.name + '.rollingFriction', 1) cmds.setAttr(dynamicsNode.name + '.bounce', 0) cmds.setAttr(dynamicsNode.name + '.mass', 10) solver = cmds.listConnections(dynamicsNode.name+(".enable"))[0] or [] cmds.setAttr(solver + '.groundPlanePositionY', groundPosition) # hide the rock pile shape object cmds.hide(node) yield # run the preset smartPreset = runPreset() smartPreset.next()