Exemple #1
0
def stickyMod(surf, falloff=1):

    sm_dfrm, sm_hdl = cmds.softMod(surf)
    sm_shp = cmds.listRelatives(sm_hdl, c=1)[0]
    cmds.setAttr('{}.visibility'.format(sm_shp), 0)
    cmds.setAttr('{}.visibility'.format(sm_hdl), l=1, k=0)
    cmds.setAttr('{}.rp'.format(sm_hdl), 0, 0, 0)
    cmds.setAttr('{}.sp'.format(sm_hdl), 0, 0, 0)
    cmds.setAttr('{}.falloffAroundSelection'.format(sm_dfrm), 0)
    cmds.addAttr(sm_hdl, ln='envelope', at='float', dv=1, min=0, max=1, k=1)
    cmds.connectAttr('{}.envelope'.format(sm_hdl),
                     '{}.envelope'.format(sm_dfrm))
    cmds.addAttr(sm_hdl,
                 ln='falloffRadius',
                 at='float',
                 min=.001,
                 dv=falloff,
                 k=1)
    cmds.connectAttr('{}.falloffRadius'.format(sm_hdl),
                     '{}.falloffRadius'.format(sm_dfrm))
    cmds.setAttr('{}.displayHandle'.format(sm_hdl), 1)
    cmds.connectAttr('{}.worldMatrix'.format(surf),
                     '{}.geomMatrix[0]'.format(sm_dfrm))
    outGeo = cmds.listConnections('{}.input[0].inputGeometry'.format(sm_dfrm),
                                  plugs=1)[0]

    rslt = sm_dfrm, sm_hdl, outGeo
    return rslt
Exemple #2
0
    def create_plane_rig(self):
        nurb_name = "plane"

        cmds.group(n="{0}Rig_grp".format(nurb_name), em=True)
        plane_grp_dag = oopmaya.DAG_Node()

        cmds.group(n="{0}Controller_grp".format(nurb_name), em=True)
        controller_grp_dag = oopmaya.DAG_Node()

        cmds.nurbsPlane(n="{0}_nurb".format(nurb_name), p=[0, 0, 0], ax=[0, 1, 0], w=10, lr=1, d=3, u=4, v=1, ch=True)
        plane_nurb_dag = oopmaya.DAG_Node()

        soft_mod = cmds.softMod("{0}.cv[3][0:3]".format(plane_nurb_dag.name()))[0]
        soft_mod_handle_dag = oopmaya.DAG_Node()

        oopmaya.Maya_Controller(name="{0}Deformer_controller".format(nurb_name), shape="diamond_curve")
        controller_dag = oopmaya.DAG_Node()

        plane_nurb_dag.set_parent(plane_grp_dag)
        controller_grp_dag.set_parent(plane_grp_dag)
        controller_dag.set_parent(controller_grp_dag)
        soft_mod_handle_dag.set_parent(plane_nurb_dag)
        soft_mod_handle_dag.parent_constraint(controller_dag)

        controller_grp_dag.parent_constraint(plane_nurb_dag)
        controller_grp_dag.scale_constraint(plane_nurb_dag)

        soft_mod_handle_dag.hide()

        cmds.setAttr("{0}.relative".format(soft_mod), 1)
        cmds.setAttr("{0}.falloffAroundSelection".format(soft_mod), 0)

        cmds.select(plane_nurb_dag.name())
	def create_plane_rig( self ):
		nurb_name = 'plane'

		cmds.group( n = '{0}Rig_grp'.format( nurb_name ), em = True )
		plane_grp_dag = oopmaya.DAG_Node()

		cmds.group( n = '{0}Controller_grp'.format( nurb_name ), em = True )
		controller_grp_dag = oopmaya.DAG_Node()

		cmds.nurbsPlane( n = '{0}_nurb'.format( nurb_name ), p = [0, 0, 0], ax = [0, 1, 0], w = 10, lr = 1, d = 3, u = 4, v = 1, ch = True )
		plane_nurb_dag = oopmaya.DAG_Node()

		soft_mod = cmds.softMod( '{0}.cv[3][0:3]'.format( plane_nurb_dag.name() ) )[0]
		soft_mod_handle_dag = oopmaya.DAG_Node()

		oopmaya.Maya_Controller( name = '{0}Deformer_controller'.format( nurb_name ), shape = 'diamond_curve' )
		controller_dag = oopmaya.DAG_Node()

		plane_nurb_dag.set_parent( plane_grp_dag )
		controller_grp_dag.set_parent( plane_grp_dag )
		controller_dag.set_parent( controller_grp_dag )
		soft_mod_handle_dag.set_parent( plane_nurb_dag )
		soft_mod_handle_dag.parent_constraint( controller_dag )

		controller_grp_dag.parent_constraint( plane_nurb_dag )
		controller_grp_dag.scale_constraint( plane_nurb_dag )

		soft_mod_handle_dag.hide()

		cmds.setAttr( '{0}.relative'.format( soft_mod ), 1 )
		cmds.setAttr( '{0}.falloffAroundSelection'.format( soft_mod ), 0 )

		cmds.select( plane_nurb_dag.name() )
Exemple #4
0
def create(geo,prefix=''):
	'''
	'''
	# Check prefix
	if not prefix: prefix = geo
	
	# Create Deformer
	sMod = mc.softMod(geo,n=prefix+'_softMod')
	sModHandle = sMod[1]
	sMod = sMod[0]
	sModBase = mc.duplicate(sModHandle,po=True,n=prefix+'_softModBase')[0]
	
	# Get Handle pivot
	piv = mc.xform(sModHandle,q=True,ws=True,rp=True)
	
	# Initiate Control Builder
	ctrlBuilder = glTools.tools.controlBuilder.ControlBuilder()
	
	# Create Base control
	base_grp = mc.createNode('transform',n=prefix+'_softModBase_grp')
	base_ctrl = mc.createNode('transform',n=prefix+'_softModBase_ctrl',p=base_grp)
	base_ctrlShape = ctrlBuilder.controlShape(base_ctrl,'box',scale=2)
	
	# Create Offset control
	offset_grp = mc.createNode('transform',n=prefix+'_softModOffset_grp',p=base_ctrl)
	offset_ctrl = mc.createNode('transform',n=prefix+'_softModOffset_ctrl',p=offset_grp)
	offset_ctrlShape = ctrlBuilder.controlShape(offset_ctrl,'sphere',scale=0.25)
	
	# Create Falloff control
	falloff_grp = mc.createNode('transform',n=prefix+'_softModFalloff_grp',p=base_ctrl)
	falloff_ctrl = mc.createNode('transform',n=prefix+'_softModFalloff_ctrl',p=falloff_grp)
	falloff_ctrlShape = ctrlBuilder.controlShape(falloff_ctrl,'circle',scale=1)
	falloff_loc = mc.spaceLocator(n=prefix+'_softModFalloff_loc')[0]
	mc.parent(falloff_loc,falloff_ctrl)
	mc.addAttr(falloff_ctrl,ln='radius',min=0.001,dv=1,k=True)
	mc.setAttr(falloff_loc+'.v',0)
	
	# Move hierarchy into place
	mc.move(piv[0],piv[1],piv[2],base_grp,a=True)
	
	# Connect to deformer
	mc.connectAttr(falloff_loc+'.worldPosition[0]',sMod+'.falloffCenter',f=True)
	mc.connectAttr(falloff_ctrl+'.radius',sMod+'.falloffRadius',f=True)
	mc.connectAttr(sModBase+'.worldInverseMatrix[0]',sMod+'.bindPreMatrix',f=True)
	
	# Parent and constrain softMod elements
	mc.parentConstraint(offset_ctrl,sModHandle,mo=True)
	mc.scaleConstraint(offset_ctrl,sModHandle,mo=True)
	mc.parentConstraint(base_ctrl,sModBase,mo=True)
	mc.scaleConstraint(base_ctrl,sModBase,mo=True)
	mc.parent(sModHandle,sModBase)
	mc.parent(sModBase,base_grp)
	
	# Return result
	return sMod
Exemple #5
0
def creatSoftModCtrl(vtx):
        
    for i in vtx:
        a = str(type(i))
        if a == "<class 'pymel.core.general.MeshVertex'>":
            name = (str(i))
            ModifiedName = re.sub(r'[^\w]', '_', name)    
            print (ModifiedName)
        else:
            print('Wrong Selection, Only select verticies')
            break
        pos = pm.pointPosition(i)
        
        name = (str(i))
        ModifiedName = re.sub(r'[^\w]', '_', name)    
        ctl = pm.curve(n = ModifiedName +'_SoftMod_Handle_Ctrl' ,d=1, p=[(1, 1, 1),(1, 1, -1),(-1, 1, -1),(-1, 1, 1),(1, 1, 1),(1, -1, 1),(1, -1, -1),(1, 1, -1),(-1, 1, -1),(-1, -1, -1),(1, -1, -1),(-1, -1, -1),(-1, -1, 1),(-1, 1, 1),(-1, -1, 1),(1, -1, 1)], k=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
            
        pm.addAttr(ctl , ln = 'fallOff', at = 'double', dv = 20) 
        pm.setAttr(ctl.fallOff, k=1)
        pm.addAttr(ctl , ln = 'fallOffMode', at = 'enum', en = 'volume:surface') 
        pm.setAttr(ctl.fallOffMode, k=1)    
        pm.addAttr(ctl , ln = 'globalScale', at = 'double', dv = 1) 
        pm.setAttr(ctl.globalScale, k=1)   
        grp = pm.createNode('transform',n = ModifiedName + '_ctrl_grp' )
        loc = pm.spaceLocator(n = ModifiedName+'_SoftMod_Ctrl') 
        pm.select(cl=1)
        pm.parent(loc,grp)
        pm.parent(ctl,loc)
        grp.translate.set(pos)
        mesh = pm.listTransforms(i.split('.')[0])[0]
        pm.select(mesh)
        sfMod = cmds.softMod(wn = (str(mesh),str(mesh)))
        pm.select(cl=1)
        cmds.softMod(sfMod[0],e=1,wn = (str(ctl),str(ctl)))
        pm.setAttr(sfMod[0]+'.falloffAroundSelection',0)
        pm.connectAttr(loc.worldPosition[0],sfMod[0]+'.falloffCenter')
        mdl = pm.createNode('multDoubleLinear',n = ModifiedName+'_MDL')
        pm.connectAttr(ctl.fallOffMode,sfMod[0]+'.falloffMode')
        ctl.fallOff>>mdl.input1
        ctl.globalScale>>mdl.input2
        pm.connectAttr(mdl.output,sfMod[0]+'.falloffRadius')
        pm.connectAttr(loc.worldInverseMatrix[0],str(sfMod[0])+'.bindPreMatrix')
def create(geo, prefix=""):
    """
	"""
    # Check prefix
    if not prefix:
        prefix = geo

    # Create Deformer
    sMod = mc.softMod(geo, n=prefix + "_softMod")
    sModHandle = sMod[1]
    sMod = sMod[0]
    sModBase = mc.duplicate(sModHandle, po=True, n=prefix + "_softModBase")[0]

    # Get Handle pivot
    piv = mc.xform(sModHandle, q=True, ws=True, rp=True)

    # Create Base control
    base_grp = mc.createNode("transform", n=prefix + "_softModBase_grp")
    base_ctrl = mc.createNode("transform", n=prefix + "_softModBase_ctrl", p=base_grp)
    base_ctrlShape = glTools.tools.controlBuilder.controlShape(base_ctrl, "box", scale=2)

    # Create Offset control
    offset_grp = mc.createNode("transform", n=prefix + "_softModOffset_grp", p=base_ctrl)
    offset_ctrl = mc.createNode("transform", n=prefix + "_softModOffset_ctrl", p=offset_grp)
    offset_ctrlShape = glTools.tools.controlBuilder.controlShape(offset_ctrl, "sphere", scale=0.25)

    # Create Falloff control
    falloff_grp = mc.createNode("transform", n=prefix + "_softModFalloff_grp", p=base_ctrl)
    falloff_ctrl = mc.createNode("transform", n=prefix + "_softModFalloff_ctrl", p=falloff_grp)
    falloff_ctrlShape = glTools.tools.controlBuilder.controlShape(falloff_ctrl, "circle", scale=1)
    falloff_loc = mc.spaceLocator(n=prefix + "_softModFalloff_loc")[0]
    mc.parent(falloff_loc, falloff_ctrl)
    mc.addAttr(falloff_ctrl, ln="radius", min=0.001, dv=1, k=True)
    mc.setAttr(falloff_loc + ".v", 0)

    # Move hierarchy into place
    mc.move(piv[0], piv[1], piv[2], base_grp, a=True)

    # Connect to deformer
    mc.connectAttr(falloff_loc + ".worldPosition[0]", sMod + ".falloffCenter", f=True)
    mc.connectAttr(falloff_ctrl + ".radius", sMod + ".falloffRadius", f=True)
    mc.connectAttr(sModBase + ".worldInverseMatrix[0]", sMod + ".bindPreMatrix", f=True)

    # Parent and constrain softMod elements
    mc.parentConstraint(offset_ctrl, sModHandle, mo=True)
    mc.scaleConstraint(offset_ctrl, sModHandle, mo=True)
    mc.parentConstraint(base_ctrl, sModBase, mo=True)
    mc.scaleConstraint(base_ctrl, sModBase, mo=True)
    mc.parent(sModHandle, sModBase)
    mc.parent(sModBase, base_grp)

    # Return result
    return sMod
Exemple #7
0
def displacePointsInsideMeshSM(plane, mesh, height, fRadius):
	"""
	Same function as displacePointsInsideMesh, but use soft modification
	instead of soft selection

	:param plane: object to displace
	:param mesh: shape for select vertices to displace
	:param height: height of displacement
	:param fRadius: soft modification falloff radius
	:return: None
	"""
	cmd.selectMode(component=True)

	vtxNumber = len(cmd.getAttr(plane+'.vtx[:]'))
	for i in range(0, vtxNumber):
		v = plane+'.vtx[%d]' % i
		vPosition = cmd.xform(v, query=True, translation=True, worldSpace=True)
		if test_if_inside_mesh(mesh, vPosition):
			cmd.select(v, add=True)

	cmd.softMod(rel=True, fas=True, fr=fRadius, fm=False)
	cmd.move(height, y=True, r=True)
	cmd.selectMode(o=True)
Exemple #8
0
def softMod(*args, **kwargs):
    res = cmds.softMod(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
Exemple #9
0
import maya.cmds as cmds
import zTools.rig.zbw_rig as rig

pts = cmds.ls(sl=True, fl=True)
mesh = cmds.ls(*pts, o=True)[0]
# throw error if more than one is selected?
obj = cmds.listRelatives(mesh, p=True)[0]
initPos = rig.average_point_positions(pts)
cpom = rig.closest_point_on_mesh_position(initPos, obj)
crom = rig.closest_point_on_mesh_rotation(initPos, obj)

#create softmod
cmds.select(obj, r=True)
softList = cmds.softMod(relative=False,
                        falloffCenter=cpom,
                        falloffRadius=5.0,
                        n="testSM",
                        frontOfChain=True)
#create both controls
baseCtrl = rig.create_control("base", type="cube")
baseGrp = rig.group_freeze(baseCtrl)
moveCtrl = rig.create_control("move", type="sphere")
moveGrp = rig.group_freeze(moveCtrl)
cmds.parent(moveGrp, baseCtrl)

cmds.xform(baseGrp, ws=True, t=cpom)
cmds.xform(baseGrp, ws=True, ro=crom)

# do mult matrix

# also mult scale by falloff attr to get final falloff
Exemple #10
0
def create(geo, prefix=''):
    '''
	'''
    # Check prefix
    if not prefix: prefix = geo

    # Create Deformer
    sMod = mc.softMod(geo, n=prefix + '_softMod')
    sModHandle = sMod[1]
    sMod = sMod[0]
    sModBase = mc.duplicate(sModHandle, po=True, n=prefix + '_softModBase')[0]

    # Get Handle pivot
    piv = mc.xform(sModHandle, q=True, ws=True, rp=True)

    # Initiate Control Builder
    ctrlBuilder = glTools.tools.controlBuilder.ControlBuilder()

    # Create Base control
    base_grp = mc.createNode('transform', n=prefix + '_softModBase_grp')
    base_ctrl = mc.createNode('transform',
                              n=prefix + '_softModBase_ctrl',
                              p=base_grp)
    base_ctrlShape = ctrlBuilder.controlShape(base_ctrl, 'box', scale=2)

    # Create Offset control
    offset_grp = mc.createNode('transform',
                               n=prefix + '_softModOffset_grp',
                               p=base_ctrl)
    offset_ctrl = mc.createNode('transform',
                                n=prefix + '_softModOffset_ctrl',
                                p=offset_grp)
    offset_ctrlShape = ctrlBuilder.controlShape(offset_ctrl,
                                                'sphere',
                                                scale=0.25)

    # Create Falloff control
    falloff_grp = mc.createNode('transform',
                                n=prefix + '_softModFalloff_grp',
                                p=base_ctrl)
    falloff_ctrl = mc.createNode('transform',
                                 n=prefix + '_softModFalloff_ctrl',
                                 p=falloff_grp)
    falloff_ctrlShape = ctrlBuilder.controlShape(falloff_ctrl,
                                                 'circle',
                                                 scale=1)
    falloff_loc = mc.spaceLocator(n=prefix + '_softModFalloff_loc')[0]
    mc.parent(falloff_loc, falloff_ctrl)
    mc.addAttr(falloff_ctrl, ln='radius', min=0.001, dv=1, k=True)
    mc.setAttr(falloff_loc + '.v', 0)

    # Move hierarchy into place
    mc.move(piv[0], piv[1], piv[2], base_grp, a=True)

    # Connect to deformer
    mc.connectAttr(falloff_loc + '.worldPosition[0]',
                   sMod + '.falloffCenter',
                   f=True)
    mc.connectAttr(falloff_ctrl + '.radius', sMod + '.falloffRadius', f=True)
    mc.connectAttr(sModBase + '.worldInverseMatrix[0]',
                   sMod + '.bindPreMatrix',
                   f=True)

    # Parent and constrain softMod elements
    mc.parentConstraint(offset_ctrl, sModHandle, mo=True)
    mc.scaleConstraint(offset_ctrl, sModHandle, mo=True)
    mc.parentConstraint(base_ctrl, sModBase, mo=True)
    mc.scaleConstraint(base_ctrl, sModBase, mo=True)
    mc.parent(sModHandle, sModBase)
    mc.parent(sModBase, base_grp)

    # Return result
    return sMod
Exemple #11
0
def softmod_for_each(size=1):
    """Create a softMod deformer and controlers for every selected element"""

    # what's selected
    selection = mc.ls(sl=True)

    # for each selected node
    for node in selection:

        # get the name and the transforms
        node_name = node.split('|')[-1]
        pos = mc.xform(node, q=True, rp=True, ws=True)

        # def name of the new nodes
        ctrl_name = node_name + '_ctrl'
        # softmod names
        soft_name = node_name + '_softMod'
        soft_control = node_name + '_softMod_ctrl'
        mover_name = node_name + '_mover_ctrl'

        if mc.objExists(soft_name):
            softmod_list = [
                softmod for softmod in mc.ls(et='softMod')
                if soft_name in softmod
            ]

            number = str(len(softmod_list))
            soft_name = node_name + '_softMod_' + number
            soft_control = soft_name + '_ctrl'
            mover_name = node_name + '_mover' + number + '_ctrl'

        # calculate ctrl size
        #bbox
        bbox = mc.exactWorldBoundingBox(node, ignoreInvisible=True)
        bbox_size = [0, 0]
        bbox_size[0] = bbox[3] - bbox[0]
        bbox_size[1] = bbox[5] - bbox[2]
        bbox_size.sort()
        bbox_height = bbox[4] - bbox[1]

        ctrl_size = bbox_size[1] * 0.6

        if ctrl_size > 5.0:
            mover_size = 2.0
        else:
            mover_size = ctrl_size / 2.0

        # create ctrl and place it
        mc.circle(name=soft_control,
                  normal=(0, 1, 0),
                  sections=8,
                  radius=ctrl_size)
        #delete history
        mc.delete(soft_control, ch=True)
        orig_soft_ctrl = orig.orig([soft_control])

        mover = mlutilities.create_ctrl(ctrl_type='simple_orb',
                                        name=mover_name,
                                        size=mover_size)

        mc.spaceLocator(name=mover_name + 'loc', a=True, p=[0, 0, 0])
        mc.parent(mover_name + 'loc', soft_control)

        # create softMod
        mc.softMod(node, n=soft_name, wn=(mover_name, mover_name))

        # creates softMod hierarchy
        mc.parent(mover[1], soft_control)

        # create/set/connect Attributes
        #visibility
        mc.connectAttr(mover_name + 'locShape.worldPosition',
                       soft_name + '.falloffCenter')
        #size
        mc.addAttr(mover_name,
                   at='float',
                   k=True,
                   h=False,
                   ln='size',
                   dv=5,
                   min=0.001,
                   max=50)
        mc.connectAttr(mover_name + '.size', soft_name + '.falloffRadius')
        #set display in channel box
        #mover
        mc.setAttr(mover_name + '.visibility', k=False, cb=False)
        #softMod ctrl
        mc.setAttr(soft_control + '.scaleX', k=False, cb=False)
        mc.setAttr(soft_control + '.scaleY', k=False, cb=False)
        mc.setAttr(soft_control + '.scaleZ', k=False, cb=False)
        mc.setAttr(soft_control + '.visibility', k=False, cb=False)
        #locator
        mc.setAttr(mover_name + 'loc.visibility', 0)

        #color
        mlutilities.color([soft_control + 'Shape'], 'cyan')
        mlutilities.color([mover_name + 'Shape'], 'dark_pink')

        # bindPreMatrix
        mc.connectAttr(soft_control + '.worldInverseMatrix',
                       soft_name + '.bindPreMatrix')
        mc.connectAttr(node + '.worldMatrix[0]',
                       soft_name + '.geomMatrix[0]',
                       f=True)

        # ctrl placement
        mc.xform(orig_soft_ctrl,
                 t=[pos[0], pos[1] + (bbox_height / 2), pos[2]])
        #mc.xform(orig_soft_ctrl, ro=rot)

        # parent to existing hierarchy
        if mc.objExists(ctrl_name):
            mc.parent(orig_soft_ctrl, ctrl_name)
        elif mc.objExists('helper_ctrl'):
            mc.parent(orig_soft_ctrl, 'helper_ctrl')
        elif mc.objExists('walk_ctrl'):
            mc.parent(orig_soft_ctrl, 'walk_ctrl')
        else:
            pass

    mlutilities.rigset()
Exemple #12
0
def create_soft_mod_deformer(wave=False, *args):
    """
    creates and sets up the softmod deformer
    """
    bpf = cmds.intFieldGrp(widgets["bpFrameIFG"], q=True, v1=True)
    currentTime = cmds.currentTime(q=True)
    cmds.currentTime(bpf)

    check = cmds.checkBoxGrp(widgets["checkCBG"], q=True, v1=True)
    defName = cmds.textFieldGrp(widgets["smdTFG"], tx=True, q=True)
    scaleFactor = cmds.floatFieldGrp(widgets["scaleFFG"], q=True, v1=True)
    front = cmds.checkBoxGrp(widgets["frontCBG"], q=True, v1=True)
    auto = cmds.checkBoxGrp(widgets["autoscaleCBG"], q=True, v1=True)

    if (cmds.objExists(defName)):
        cmds.warning(
            "An object of this name, {0}, already exists! Choose a new name!".
            format(defName))
        return ()

# TODO - check that we've got only verts (or cv's?) selected - always do average?
    vertex = cmds.ls(sl=True, fl=True)
    if not vertex:
        cmds.warning("Must select at least one vertex")
        return ()

    # get objects - in no parent object (to parent rig to) then parent to the object itself
    obj = vertex[0].partition(".")[0]

    # TODO below is if we have a mesh . . . broaden to nurbs? or curve?
    if cmds.objectType(obj) == "mesh":
        obj = cmds.listRelatives(obj, p=True)[0]
    parentObject = cmds.textFieldButtonGrp(widgets["mainCtrlTFBG"],
                                           q=True,
                                           tx=True)
    if not parentObject:
        parentObject = obj

    vertPos = rig.average_point_positions(vertex)

    if check and (not front):
        deformer_check(obj)

    cmds.select(obj)
    softMod = defName
    softModAll = cmds.softMod(relative=False,
                              falloffCenter=vertPos,
                              falloffRadius=5.0,
                              n=softMod,
                              frontOfChain=front)
    cmds.rename(softModAll[0], softMod)
    softModXform = cmds.listConnections(softModAll[0], type="transform")[0]

    ctrlName = defName + "_zeroed_GRP"
    control = cmds.group(name=ctrlName, em=True)

    # TODO - make a little swatch to set the color of the control
    controlGrp = cmds.group(control,
                            n="{0}_static_GRP".format(
                                control.rpartition("_")[0]))
    cmds.xform(controlGrp, ws=True, t=vertPos)
    if wave:
        ctrlType = "arrow"
    else:
        ctrlType = "cube"
    topCtrl, topGrp = add_top_level_ctrl(control, ctrlType,
                                         cmds.listRelatives(obj, s=True)[0])

    # TODO figure out how to transpose the space for just the scale
    rig.connect_transforms(control, softModXform)

    cmds.addAttr(topCtrl, ln="__XTRA__", at="enum", k=True)
    cmds.setAttr("{0}.__XTRA__".format(topCtrl), l=True)
    cmds.addAttr(topCtrl,
                 ln="envelope",
                 at="float",
                 min=0,
                 max=1,
                 k=True,
                 dv=1)
    cmds.addAttr(topCtrl,
                 ln="falloff",
                 at="float",
                 min=0,
                 max=100,
                 k=True,
                 dv=5)
    cmds.addAttr(topCtrl,
                 ln="mode",
                 at="enum",
                 enumName="volume=0:surface=1",
                 k=True)

    # connect that attr to the softmod falloff radius
    cmds.connectAttr("{0}.envelope".format(topCtrl),
                     "{0}.envelope".format(softMod))
    cmds.connectAttr("{0}.falloff".format(topCtrl),
                     "{0}.falloffRadius".format(softMod))
    cmds.connectAttr("{0}.mode".format(topCtrl),
                     "{0}.falloffMode".format(softMod))
    cmds.setAttr("{0}.inheritsTransform".format(softModXform), 0)
    cmds.setAttr("{0}.visibility".format(softModXform), 0)

    if auto:
        calsz = rig.calibrate_size(obj, .15)
        if calsz:
            rig.scale_nurbs_control(topCtrl, calsz, calsz, calsz)
            cmds.setAttr("{0}.falloff".format(topCtrl), 2 * calsz)
        else:
            cmds.warning(
                "I had an issue getting the calibrated scale of {0}".format(
                    obj))
    rig.scale_nurbs_control(topCtrl, scaleFactor, scaleFactor, scaleFactor)

    defGroup = cmds.group(empty=True, n=(defName + "_deform_GRP"))
    cmds.xform(defGroup, ws=True, t=vertPos)
    cmds.parent(softModXform, controlGrp, defGroup)

    # TODO - use the name of the deformer instead. . .
    masterGrp = cmds.group(name="{0}_mstr_GRP".format(obj), em=True)
    cmds.parent(topGrp, defGroup, masterGrp)

    if wave:
        softWave(softMod, topCtrl, control)

    cmds.parent(masterGrp, parentObject)

    newName = rig.increment_name(defName)
    cmds.textFieldGrp(widgets["smdTFG"], tx=newName, e=True)

    cmds.select(topCtrl)
    cmds.currentTime(currentTime)

    return (softMod, control, obj, defGroup)
Exemple #13
0
def softModDeformerDo(*args):
    """creates and sets up the softmod deformer setup"""

    check = cmds.checkBoxGrp(widgets["checkCBG"], q=True, v1=True)
    increment = cmds.checkBoxGrp(widgets["incrCBG"], q=True, v1=True)
    toParent = cmds.checkBoxGrp(widgets["parentCBG"], q=True, v1=True)
    #get deformer name
    defName = cmds.textFieldGrp(widgets["smdTFG"], tx=True, q=True)
    scaleFactor = cmds.floatFieldGrp(widgets["scaleFFG"], q=True, v1=True)

    if not (cmds.objExists(defName)):
        # choose a vert (for example)
        vertsRaw = cmds.ls(sl=True, fl=True)

        if vertsRaw == []:
            cmds.warning("Must select at least one vertex")
        else:
            if (cmds.checkBoxGrp(widgets["firstVertCBG"], q=True, v1=True)):
                vertex = [vertsRaw[0]]
            else:
                vertex = vertsRaw

        obj = vertex[0].partition(".")[0]

        #get vert position then select the geo
        positions = []
        for vert in vertex:
            positions.append(cmds.pointPosition(vert))

        numVerts = len(positions)

        x,y,z = 0,0,0
        for i in range(numVerts):
            x += positions[i][0]
            y += positions[i][1]
            z += positions[i][2]

        vertPos = [(x/numVerts), (y/numVerts), (z/numVerts)]

        #check if there are other deformers on the obj
        if check:
            deformers = []
            deformers = getDeformers(obj)
            if deformers:
                cmds.confirmDialog( title='Deformer Alert!', message='Found some deformers on %s.\nYou may want to put the softmod\n early in the input list'%obj, button=['OK'], defaultButton='OK', cancelButton='OK', dismissString='OK' )

        cmds.select(obj)

        # create a soft mod at vert position (avg)
        softMod = defName
        softModOrig = cmds.softMod(relative=False, falloffCenter = vertPos, falloffRadius=5.0, n=softMod)[0]
        cmds.rename(softModOrig, softMod)
        softModXform = cmds.listConnections(softModOrig, type="transform")[0]


        # create a control at the position of the softmod
        control = defName + "_CTRL"
        cmds.curve(n=control, d=1, p=[[0.0, 1.0, 0.0], [-0.382683, 0.92388000000000003, 0.0], [-0.70710700000000004, 0.70710700000000004, 0.0], [-0.92388000000000003, 0.382683, 0.0], [-1.0, 0.0, 0.0], [-0.92388000000000003, -0.382683, 0.0], [-0.70710700000000004, -0.70710700000000004, 0.0], [-0.382683, -0.92388000000000003, 0.0], [0.0, -1.0, 0.0], [0.382683, -0.92388000000000003, 0.0], [0.70710700000000004, -0.70710700000000004, 0.0], [0.92388000000000003, -0.382683, 0.0], [1.0, 0.0, 0.0], [0.92388000000000003, 0.382683, 0.0], [0.70710700000000004, 0.70710700000000004, 0.0], [0.382683, 0.92388000000000003, 0.0], [0.0, 1.0, 0.0], [0.0, 0.92388000000000003, 0.382683], [0.0, 0.70710700000000004, 0.70710700000000004], [0.0, 0.382683, 0.92388000000000003], [0.0, 0.0, 1.0], [0.0, -0.382683, 0.92388000000000003], [0.0, -0.70710700000000004, 0.70710700000000004], [0.0, -0.92388000000000003, 0.382683], [0.0, -1.0, 0.0], [0.0, -0.92388000000000003, -0.382683], [0.0, -0.70710700000000004, -0.70710700000000004], [0.0, -0.382683, -0.92388000000000003], [0.0, 0.0, -1.0], [0.0, 0.382683, -0.92388000000000003], [0.0, 0.70710700000000004, -0.70710700000000004], [0.0, 0.92388000000000003, -0.382683], [0.0, 1.0, 0.0], [-0.382683, 0.92388000000000003, 0.0], [-0.70710700000000004, 0.70710700000000004, 0.0], [-0.92388000000000003, 0.382683, 0.0], [-1.0, 0.0, 0.0], [-0.92388000000000003, 0.0, 0.382683], [-0.70710700000000004, 0.0, 0.70710700000000004], [-0.382683, 0.0, 0.92388000000000003], [0.0, 0.0, 1.0], [0.382683, 0.0, 0.92388000000000003], [0.70710700000000004, 0.0, 0.70710700000000004], [0.92388000000000003, 0.0, 0.382683], [1.0, 0.0, 0.0], [0.92388000000000003, 0.0, -0.382683], [0.70710700000000004, 0.0, -0.70710700000000004], [0.382683, 0.0, -0.92388000000000003], [0.0, 0.0, -1.0], [-0.382683, 0.0, -0.92388000000000003], [-0.70710700000000004, 0.0, -0.70710700000000004], [-0.92388000000000003, 0.0, -0.382683], [-1.0, 0.0, 0.0]])

        cmds.select(cl=True)
    #TO-DO----------------pull this out into separate function?? Args would be object and color
        shapes = cmds.listRelatives(control, shapes=True)
        for shape in shapes:
            cmds.setAttr("%s.overrideEnabled"%shape, 1)
            cmds.setAttr("%s.overrideColor"%shape, 14)
        controlGrp = cmds.group(control, n="%s_GRP"%control)
        cmds.xform(controlGrp, ws=True, t=vertPos)

        # connect the pos, rot, scale of the control to the softModHandle
        cmds.connectAttr("%s.translate"%control, "%s.translate"%softModXform)
        cmds.connectAttr("%s.rotate"%control, "%s.rotate"%softModXform)
        cmds.connectAttr("%s.scale"%control, "%s.scale"%softModXform)

        cmds.addAttr(control, ln="__XTRA__", at="enum", k=True)
        cmds.setAttr("%s.__XTRA__"%control, l=True)

        # cmds.addAttr(control, ln="centerCtrlVis", at="bool", min=0, max=1, k=True, dv=0)
        cmds.addAttr(control, ln="envelope", at="float", min=0, max=1, k=True, dv=1)
        cmds.addAttr(control, ln="falloff", at="float", min=0, max=100, k=True, dv=5)
        # cmds.addAttr(control, ln="centerX", at="float", dv=0, k=True)
        # cmds.addAttr(control, ln="centerY", at="float", dv=0, k=True)
        # cmds.addAttr(control, ln="centerZ", at="float", dv=0, k=True)

        # connect that attr to the softmod falloff radius
        cmds.connectAttr("%s.envelope"%control, "%s.envelope"%softMod)
        cmds.connectAttr("%s.falloff"%control, "%s.falloffRadius"%softMod)

        # inherit transforms on softModHandle are "off"
        cmds.setAttr("%s.inheritsTransform"%softModXform, 0)

        # centerName = defName + "_center_CTRL"
        # #create secondary (area of influence) control here
        # centerCtrl = cmds.curve(n=centerName, d=1, p=[[-1.137096, -1.137096, 1.137096], [-1.137096, 1.137096, 1.137096], [1.137096, 1.137096, 1.137096], [1.137096, -1.137096, 1.137096], [-1.137096, -1.137096, 1.137096], [-1.137096, -1.137096, -1.137096], [-1.137096, 1.137096, -1.137096], [-1.137096, 1.137096, 1.137096], [1.137096, 1.137096, 1.137096], [1.137096, 1.137096, -1.137096], [1.137096, -1.137096, -1.137096], [1.137096, -1.137096, 1.137096], [1.137096, -1.137096, -1.137096], [-1.137096, -1.137096, -1.137096], [-1.137096, 1.137096, -1.137096], [1.137096, 1.137096, -1.137096]])

        # centerCtrlSh = cmds.listRelatives(centerCtrl, s=True)
        # for shape in centerCtrlSh:
        #     #turn on overrides
        #     cmds.setAttr("%s.overrideEnabled"%shape, 1)
        #     cmds.connectAttr("%s.centerCtrlVis"%control, "%s.overrideVisibility"%shape)
        #     cmds.setAttr("%s.overrideColor"%shape, 13)

        # centerGrp = cmds.group(centerCtrl, n="%s_GRP"%centerName)
        # #turn off scale and rotation for the center control
        # cmds.setAttr("%s.rotate"%centerCtrl, k=False, l=True)
        # cmds.setAttr("%s.scale"%centerCtrl, k=False, l=True)
        # cmds.setAttr("%s.visibility"%centerCtrl, k=False, l=True)

        # #move the group to the location
        # cmds.xform(centerGrp, ws=True, t=vertPos)

        # plusName = defName + "_plus"
        # plusNode = cmds.shadingNode("plusMinusAverage", asUtility=True, n=plusName)

        # cmds.connectAttr("%s.translate"%centerGrp, "%s.input3D[0]"%plusNode, f=True)
        # cmds.connectAttr("%s.translate"%centerCtrl, "%s.input3D[1]"%plusNode, f=True)
        # cmds.connectAttr("%s.output3D"%plusNode, "%s.falloffCenter"%softMod, f=True)

        #hide the softmod
        cmds.setAttr("%s.visibility"%softModXform, 0)

        #group the group and the softmod xform
        # defGroup = cmds.group(softModXform, controlGrp, n=(defName + "_deform_GRP"))
        defGroup = cmds.group(empty=True, n=(defName + "_deform_GRP"))
        cmds.xform(defGroup, ws=True, t=vertPos)
        cmds.parent(softModXform, controlGrp, defGroup)
        #parent the softmod under the centerCtrl
        # cmds.parent(defGroup, centerCtrl)

        #parent that group under the obj?
        if toParent:
            cmds.parent(defGroup, obj)

        # #connect group translate to plus node
        # plusName = defName + "_plus"
        # plusNode = cmds.shadingNode("plusMinusAverage", asUtility=True, n=plusName)
        # cmds.connectAttr("%s.translate"%defGroup, "%s.input3D[0]"%plusNode)

        # #connect to falloff center
        # cmds.connectAttr("%s.centerX"%control, "%s.input3D[1].input3Dx"%plusNode)
        # cmds.connectAttr("%s.centerY"%control, "%s.input3D[1].input3Dy"%plusNode)
        # cmds.connectAttr("%s.centerZ"%control, "%s.input3D[1].input3Dz"%plusNode)

        # cmds.connectAttr("%s.output3D"%plusNode, "%s.falloffCenter"%softMod)

        #scale the controls
        scaleCtrl([control], scaleFactor)

        #increment name
        if increment == 1:
            print "trying to rename"
            split = defName.rpartition("_")
            end = split[2]
            isInt = integerTest(end)

            if isInt:
                newNum = int(end) + 1
                newName = "%s%s%02d"%(split[0], split[1], newNum)
                cmds.textFieldGrp(widgets["smdTFG"], tx=newName, e=True)
            else:
                newName = "%s_01"%defName
                cmds.textFieldGrp(widgets["smdTFG"], tx=newName, e=True)

        #select the control to wrap up
        cmds.select(control)
    else:
        cmds.warning("An object of this name, %s, already exists! Choose a new name!"%defName)
Exemple #14
0
         for inMeshAttr in rivetData['inMeshAttrs']:
             cmds.connectAttr('{0}'.format(meshConnections[0]), inMeshAttr, f=1)
         locShapes = cmds.listRelatives(rivetData['loc'], type='locator')
         if locShapes:
             cmds.hide(locShapes)
     else:
         popcList = util.mesh.rivet.attachTransformsToMesh(transformList=[rivetGrp], geo=mesh)
         for popc in popcList:
             cmds.connectAttr('{0}'.format(meshConnections[0]), '{0}.target[0].targetMesh'.format(popc), f=1)
 else:
     # Query the position to place the softmod
     cmds.xform(softModCenterCtlGrp, t=softModPos, ws=1)
     
 # build soft mod
 softModData = cmds.softMod("{0}".format(mesh), falloffRadius=2, falloffMode=0,
     falloffBasedOnX=1, falloffBasedOnY=1, falloffBasedOnZ=1, falloffAroundSelection=0,
     falloffMasking=1, n=smdName)
     
 # Add attributes to the soft mod control, and connect those attributes
 cmds.addAttr(softModCtl, at='double', ln=envelopeAttr, k=1, dv=1, min=0, max=1)
 cmds.connectAttr(
     '{0}.{1}'.format(softModCtl, envelopeAttr),
     '{0}.{1}'.format(softModData[0], envelopeAttr), f=1)
 cmds.addAttr(softModCtl, at='double', ln=fallOffRadiusAttr, k=1, dv=1)
 cmds.connectAttr(
     '{0}.{1}'.format(softModCtl, fallOffRadiusAttr),
     '{0}.{1}'.format(softModData[0], fallOffRadiusAttr), f=1)
 cmds.addAttr(softModCtl, at='enum', ln=falloffModeAttr, k=1, en='Volume:Surface')
 cmds.connectAttr(
     '{0}.{1}'.format(softModCtl, falloffModeAttr),
     '{0}.{1}'.format(softModData[0], falloffModeAttr), f=1)