def add_top_level_ctrl(origCtrl, type, geo, *args):
"""
creates a new ctrl, orients it to the geo and parent constrains the orig ctrl rig under itself
:param origCtrl: the control we're working from
:param type: the ctrl type of shape see zbw_rig.createControl for options
:param geo: the geo to orient to
:param args:
:return: topCtrl (the new ctrl), grp (the top ctrl grp freeze grp)
"""
# THIS IS THE XTRA CTRL LAYER, THIS ORIENTS CTRL AND CONNECTS ORIG CTRL TO THE NEW CTRL
origCtrlPos = cmds.xform(origCtrl, q=True, ws=True, rp=True)
topCtrl = rig.createControl(name="{0}_moveCtrl".format(origCtrl.rpartition("_")[0]), type=type, axis="z",
color="yellow")
grp = rig.groupFreeze(topCtrl)
cmds.xform(grp, ws=True, t=origCtrlPos)
nc = cmds.normalConstraint(geo, grp, worldUpType="vector", upVector=(0, 1, 0))
cmds.delete(nc)
pc = cmds.parentConstraint(topCtrl, origCtrl, mo=True)
sc = cmds.scaleConstraint(topCtrl, origCtrl, mo=True)
return(topCtrl, grp)
python类xform()的实例源码
def make_position_planar(*args):
sel = cmds.ls(sl=True, type='joint')
if len(sel) <= 3:
raise RuntimeError('Select 3 joints to make a plane and then additional joints to move onto that plane.')
a, b, c = [get_position(sel[i]) for i in range(3)]
ab = (b - a).normal()
ac = (c - a).normal()
normal = (ab ^ ac).normal()
joints = sel[3:]
for joint in joints:
children = _unparent_children(joint)
p = get_position(joint)
pa = a - p
dot = pa*normal
p = p + (normal*dot)
cmds.xform(joint, ws=True, t=(p.x, p.y, p.z))
_reparent_children(joint, children)
if sel:
cmds.select(sel)
def __init__(self, controls=None, **kwargs):
"""Constructor
:param controls: A list of dictionaries describing the contorls nodes that need to be created.
See cmt.rig.control.dump.
{
'name': node,
'cvs': cmds.getAttr('{0}.cv[*]'.format(node)),
'degree': cmds.getAttr('{0}.degree'.format(node)),
'form': cmds.getAttr('{0}.form'.format(node)),
'xform': cmds.xform(node, q=True, matrix=True),
'knots': get_knots(node),
'pivot': cmds.xform(node, q=True, rp=True),
'overrideEnabled': cmds.getAttr('{0}.overrideEnabled'.format(node)),
'overrideRGBColors': cmds.getAttr('{0}.overrideRGBColors'.format(node)),
'overrideColorRGB': cmds.getAttr('{0}.overrideColorRGB'.format(node))[0],
'overrideColor': cmds.getAttr('{0}.overrideColor'.format(node)),
}
"""
super(Component, self).__init__(**kwargs)
self.controls = controls or []
self.control_list = fields.ListField(name='controls',
value=[control['name'] for control in self.controls],
help_text='Controls that will be created.',
parent=self)
def create_bounding_box(self, meshName="bounding_GEO"):
"""
Create the bounding box mesh.
:param meshName(string): Name of created mesh.
Raises:
None
Returns:
(string) Cube Transform
"""
obbCube = cmds.polyCube(constructionHistory=False, name="obb_GEO")[0]
for ind, pnt in enumerate(self.boundPoints):
cmds.xform("%s.vtx[%s]" % (obbCube, ind),
translation=[pnt.x, pnt.y, pnt.z])
return obbCube
def getLocalValues(obj, *args):
"""use the matrix(xform) to get world space vals, convert to trans and rots"""
# get values
# add as key in dict
obj_values = []
obj_wRot = cmds.xform(obj, q=True, ws=True, ro=True)
obj_wTrans = cmds.xform(obj, q=True, ws=True, t=True)
for tval in obj_wTrans:
obj_values.append(tval)
for rval in obj_wRot:
obj_values.append(rval)
return obj_values
# return (tx, ty, tz, rx, ry, rz)
# @zbw_undoable.undoable
def huddleExec(*args):
"""
from first selection, moves the next selected objects closer or farther from first selection based on slider values (as a percentage)
"""
factor = cmds.floatSliderGrp(widgets["slider"], q=True, v=True)
sel = cmds.ls(sl=True, type="transform")
center = sel[0]
objs = sel[1:]
centerPos = cmds.xform(center, q=True, ws=True, rp=True)
centerVec = om.MVector(centerPos[0], centerPos[1], centerPos[2])
for obj in objs:
objPos = cmds.xform(obj, ws=True, q=True, rp=True)
objVec = om.MVector(objPos[0], objPos[1], objPos[2])
diffVec = objVec-centerVec
scaledVec = diffVec * factor
newVec = scaledVec + centerVec
cmds.xform(obj, ws=True, t=(newVec[0], newVec[1], newVec[2]))
def insertGroupAbove(obj, *args):
par = cmds.listRelatives(obj, p=True)
grp = cmds.group(em=True, n="{}_Grp".format(obj))
pos = cmds.xform(obj, q=True, ws=True, rp=True)
rot = cmds.xform(obj, q=True, ws=True, ro=True)
cmds.xform(grp, ws=True, t=pos)
cmds.xform(grp, ws=True, ro=rot)
cmds.parent(obj, grp)
if par:
cmds.parent(grp, par[0])
return (grp)
def scale_the_objects(scaleVal, *args):
"""
does the scaling bits
"""
sel = cmds.ls(sl=True, type="transform")
if sel:
for obj in sel:
if (rig.isType(obj, "nurbsSurface")) or (rig.isType(obj, "nurbsCurve")):
piv = cmds.xform(obj, q=True, ws=True, rp=True)
cvs = cmds.select((obj + ".cv[*]"))
cmds.scale(scaleVal, scaleVal, scaleVal, cvs, pivot=piv)
elif rig.isType(obj, "mesh"):
piv = cmds.xform(obj, q=True, ws=True, rp=True)
vs = cmds.select((obj + ".vtx[*]"))
cmds.scale(scaleVal, scaleVal, scaleVal, vs, pivot=piv)
else:
cmds.warning("{0} isn't a nurbs or poly object, so it was skipped".format(obj))
# clear and reselect all
if sel:
cmds.select(cl=True)
cmds.select(sel)
return (True)
return (False)
def move_pivot(end, *args):
"""
Args:
end (int): parameter value (0 or 1 from buttons) the point on curve will return, start or end
*args:
"""
check = False
sel = cmds.ls(sl=True, exactType = "transform")
if sel:
for x in sel:
check = rig.isType(x, "nurbsCurve")
if check:
# get curve info
pos = cmds.pointOnCurve(x, parameter = end, position = True)
cmds.xform(x, ws=True, piv=pos)
else:
cmds.warning("{0} is not a nurbsCurve object. Skipping!".format(x))
def insertGroupAbove(*args):
sel = cmds.ls(sl=True)
for obj in sel:
par = cmds.listRelatives(obj, p=True)
grp = cmds.group(em=True, n="{}_Grp".format(obj))
# grp = nameCheck(grp)
pos = cmds.xform(obj, q=True, ws=True, rp=True)
rot = cmds.xform(obj, q=True, ws=True, ro=True)
cmds.xform(grp, ws=True, t=pos)
cmds.xform(grp, ws=True, ro=rot)
cmds.parent(obj, grp)
if par:
cmds.parent(grp, par[0])
def addGroupBelow(*args):
############----------fix lots of stuff here, but basic idea works
sel = cmds.ls(sl=True)
for obj in sel:
pos = cmds.xform(obj, ws=True, q=True, rp=True)
rot = cmds.xform(obj, ws=True, q=True, ro=True)
children = cmds.listRelatives(obj, children=True)
grp = cmds.group(em=True, name=obj.replace("Auto", "Manual"))
cmds.xform(grp, ws=True, t=pos)
cmds.xform(grp, ws=True, ro=rot)
cmds.parent(grp, obj)
for child in children:
cmds.parent(child, grp)
def insertGroupAbove(obj, *args):
par = cmds.listRelatives(obj, p=True)
grp = cmds.group(em=True, n="{}_Grp".format(obj))
# grp = nameCheck(grp)
pos = cmds.xform(obj, q=True, ws=True, rp=True)
rot = cmds.xform(obj, q=True, ws=True, ro=True)
cmds.xform(grp, ws=True, t=pos)
cmds.xform(grp, ws=True, ro=rot)
cmds.parent(obj, grp)
if par:
cmds.parent(grp, par[0])
return(grp)
def create_orient_manipulator(joint, material):
joint_scale = cmds.jointDisplayScale(query=True)
joint_radius = cmds.getAttr('{0}.radius'.format(joint))
radius = joint_scale * joint_radius
children = cmds.listRelatives(joint, children=True, path=True)
if children:
p1 = cmds.xform(joint, q=True, ws=True, t=True)
p1 = OpenMaya.MPoint(*p1)
p2 = cmds.xform(children[0], q=True, ws=True, t=True)
p2 = OpenMaya.MPoint(*p2)
radius = p1.distanceTo(p2)
arrow_cvs = [[-1, 0, 0], [-1, 2, 0], [-2, 2, 0], [0, 4, 0], [2, 2, 0], [1, 2, 0], [1, 0, 0], [-1, 0, 0]]
arrow_cvs = [[x[0]*radius, x[1]*radius, x[2]*radius] for x in arrow_cvs]
shape = cmds.curve(name='{0}_zForward'.format(joint), degree=1, point=arrow_cvs)
# shape = cmds.sphere(n='{0}_zForward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0]
# cmds.setAttr('{0}.sz'.format(shape), 0)
# cmds.select(shape)
# cmds.hyperShade(assign=material)
group = cmds.createNode('transform', name='{0}_grp'.format(shape))
cmds.parent(shape, group)
cmds.makeIdentity(shape, apply=True)
cmds.addAttr(shape, longName=MESSAGE_ATTRIBUTE, attributeType='message')
cmds.connectAttr('{0}.message'.format(joint), '{0}.{1}'.format(shape, MESSAGE_ATTRIBUTE))
for attr in ['tx', 'ty', 'tz', 'ry', 'rz', 'v']:
cmds.setAttr('{0}.{1}'.format(shape, attr), lock=True, keyable=False)
return group, shape
def get_position(node):
p = cmds.xform(node, q=True, ws=True, t=True)
return OpenMaya.MPoint(p)
def create_arrow(jointName):
curve = cmds.curve(name='%s_ForwardDirection' % jointName, degree=1, point=[(-1, 0, 0), (-1, 2, 0), (-2, 2, 0), (0, 4, 0), (2, 2, 0), (1, 2, 0), (1, 0, 0), (-1, 0, 0)])
group = cmds.group()
cmds.xform(objectSpace=True, pivots=(0, 0, 0))
jointScale = cmds.jointDisplayScale(query=True)
jointRadius = cmds.getAttr('%s.radius' % jointName)
jointScale *= jointRadius
cmds.xform(scale=(jointScale, jointScale, jointScale))
return group
def rotate_components(rx, ry, rz, nodes=None):
"""Rotate the given nodes' components the given number of degrees about each axis.
:param rx: Degrees around x.
:param ry: Degrees around y.
:param rz: Degrees around z.
:param nodes: Optional list of curves.
"""
if nodes is None:
nodes = cmds.ls(sl=True) or []
for node in nodes:
pivot = cmds.xform(node, q=True, rp=True, ws=True)
cmds.rotate(rx, ry, rz, '{0}.cv[*]'.format(node), r=True, p=pivot, os=True, fo=True)
def dump(curves=None, stack=False):
"""Get a data dictionary representing all the given curves.
:param curves: Optional list of curves.
:return: A json serializable list of dictionaries containing the data required to recreate the curves.
"""
if curves is None:
curves = cmds.ls(sl=True) or []
data = []
for node in curves:
shape = shortcuts.get_shape(node)
if cmds.nodeType(shape) == 'nurbsCurve':
control = {
'name': node,
'cvs': cmds.getAttr('{0}.cv[*]'.format(node)),
'degree': cmds.getAttr('{0}.degree'.format(node)),
'form': cmds.getAttr('{0}.form'.format(node)),
'xform': cmds.xform(node, q=True, ws=True, matrix=True),
'knots': get_knots(node),
'pivot': cmds.xform(node, q=True, rp=True),
'overrideEnabled': cmds.getAttr('{0}.overrideEnabled'.format(node)),
'overrideRGBColors': cmds.getAttr('{0}.overrideRGBColors'.format(node)),
'overrideColorRGB': cmds.getAttr('{0}.overrideColorRGB'.format(node))[0],
'overrideColor': cmds.getAttr('{0}.overrideColor'.format(node)),
}
if stack:
control['stack'] = get_stack_count(node)
control['parent'] = get_stack_parent(node)
data.append(control)
if curves:
cmds.select(curves)
return data
def BT_Setup(set = None):
if not set:
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
if not transforms:
return False
if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
else:
return False
btNode = cmds.createNode("BlendTransforms")
cmds.setAttr(set +'.Blend_Node', btNode, type = "string")
for i in range(0, len(transforms)):
baseMatrix = cmds.xform(transforms[i], q = True, m = True)
baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
baseRotOffset = [0.0, 0.0, 0.0]
if cmds.objectType(transforms[i], isType = 'joint'):
baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]
btAttr = 'transforms[' +str(i) +'].baseMatrix'
btScaleAttr = 'transforms[' +str(i) +'].baseScale'
btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'
BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
return True
def BT_Setup(set = None):
if not set:
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
if not transforms:
return False
if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
else:
return False
btNode = cmds.createNode("BlendTransforms")
cmds.setAttr(set +'.Blend_Node', btNode, type = "string")
for i in range(0, len(transforms)):
baseMatrix = cmds.xform(transforms[i], q = True, m = True)
baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
baseRotOffset = [0.0, 0.0, 0.0]
if cmds.objectType(transforms[i], isType = 'joint'):
baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]
btAttr = 'transforms[' +str(i) +'].baseMatrix'
btScaleAttr = 'transforms[' +str(i) +'].baseScale'
btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'
BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
return True
def BT_Setup(set = None):
if not set:
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
if not transforms:
return False
if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
else:
return False
btNode = cmds.createNode("BlendTransforms")
cmds.setAttr(set +'.Blend_Node', btNode, type = "string")
for i in range(0, len(transforms)):
baseMatrix = cmds.xform(transforms[i], q = True, m = True)
baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
baseRotOffset = [0.0, 0.0, 0.0]
if cmds.objectType(transforms[i], isType = 'joint'):
baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]
btAttr = 'transforms[' +str(i) +'].baseMatrix'
btScaleAttr = 'transforms[' +str(i) +'].baseScale'
btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'
BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
return True
def BT_Setup(set = None):
if not set:
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
if not transforms:
return False
if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
else:
return False
btNode = cmds.createNode("BlendTransforms")
cmds.setAttr(set +'.Blend_Node', btNode, type = "string")
for i in range(0, len(transforms)):
baseMatrix = cmds.xform(transforms[i], q = True, m = True)
baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
baseRotOffset = [0.0, 0.0, 0.0]
if cmds.objectType(transforms[i], isType = 'joint'):
baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]
btAttr = 'transforms[' +str(i) +'].baseMatrix'
btScaleAttr = 'transforms[' +str(i) +'].baseScale'
btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'
BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
return True
def align_to_curve(xforms, curve):
curve_fn = to_curve_fn(curve)
num_xforms = len(xforms)
param_step = curve_fn.numSpans / float(num_xforms - 1)
for i, xform in enumerate(xforms):
param = i * param_step
normal = curve_fn.normal(param, om.MSpace.kWorld)
tangent = -curve_fn.tangent(param, om.MSpace.kWorld)
position = curve_fn.getPointAtParam(param, om.MSpace.kWorld)
matrix = build_matrix(normal, tangent, position)
cmds.xform(xform, ws=True, matrix=matrix)
def new_strand(hair_system=None):
if not hair_system:
selection = cmds.ls(sl=True, dag=True, leaf=True, type='hairSystem')
if selection:
hair_system = selection[0]
start = om.MVector(0, 0, 0)
end = om.MVector(0, 0, 24)
start_loc = cmds.spaceLocator(name='strand_start#')[0]
end_loc = cmds.spaceLocator(name='strand_end#')[0]
cmds.xform(end_loc, ws=True, translation=end)
tta = cmds.createNode('transformsToArrays')
cmds.connectAttr(start_loc + '.worldMatrix', tta + '.inTransforms[0].inMatrix')
cmds.connectAttr(end_loc + '.worldMatrix', tta + '.inTransforms[1].inMatrix')
pcc = cmds.createNode('pointCloudToCurve')
cmds.connectAttr(tta + '.outPositionPP', pcc + '.inArray')
expand_grp = cmds.group([start_loc, end_loc], name='strand_expand_grp#')
curve, curve_shape = curve_between(start, end, name='strand_curve#')
cmds.connectAttr(pcc + '.outCurve', curve_shape + '.create')
root_grp = cmds.group(empty=True, name='strand_grp#')
cmds.parent([expand_grp, curve], root_grp)
follicle_nodes, out_curve_nodes = add_curve_to_system(curve_shape, hair_system)
follicle_shape = follicle_nodes[1]
cmds.setAttr(follicle_shape + '.pointLock', 3)
cmds.setAttr(follicle_shape + '.sampleDensity', 24)
def dm2skin_getVertexPositionsOverRange(mesh, startFrame=0, endFrame=1):
"""Gets a list of lists of vertex positions for the given mesh. One list for
each frame between startFrame and endFrame."""
numVerts = cmds.polyEvaluate(mesh, v=True)
resultList = []
for i in range(startFrame, endFrame + 1):
tempList = []
cmds.currentTime(i)
for j in range(0, numVerts):
tempPos = cmds.xform(mesh + '.vtx[' + str(j) + ']', q=True, ws=True, t=True)
tempList.append(np.array([tempPos[0], tempPos[1], tempPos[2]]))
resultList.append(tempList)
return resultList
def dm2skin_getVertexLocationList(mesh, frame=0):
"""Gets a list of vertex locations on the given frame."""
numVerts = cmds.polyEvaluate(mesh, v=True)
resultList = []
cmds.currentTime(frame)
for v in range(0, numVerts):
pos = cmds.xform(mesh + '.vtx[' + str(v) + ']', q=True, ws=True, t=True)
resultList.append(np.array([pos[0], pos[1], pos[2], 1.0]))
return resultList
def dm2skin_getNeighbouringJoints(joint, vertexString=None, cluster=None, influences=3):
"""This gets a list of nearby joints in the skin cluster to joint up to
the number of influences. These will be the ones we use in our minimization
later"""
if not cmds.objExists(joint):
return False
if influences < 3:
return False
if not cluster:
return False
clusterJoints = cmds.skinCluster(cluster, q=True, inf=True)
pos1 = cmds.xform(vertexString, q=True, ws=True, t=True)
parentJoint = cmds.listRelatives(joint, parent=True)
subtract = 1
# add the main joint
resultList = [joint]
# i've found it works best to always include the parent
if parentJoint and parentJoint in clusterJoints:
resultList.insert(0, parentJoint[0])
subtract = 2
# for the rest of the available influences get a list of nearby joints in space
measureList = []
for measureJnt in clusterJoints:
if measureJnt not in resultList:
jntPos2 = cmds.xform(measureJnt, q=True, ws=True, t=True)
#this just gets the length of the vector between the two joints
dist = math.sqrt(reduce(lambda x, y: x + y, [math.pow(jntPos2[i] - pos1[i], 2) for i in range(len(pos1))]))
measureList.append((measureJnt, dist))
# sort the list in ascending order so we get the closest joints first
measureList.sort(key=lambda dist: dist[1])
ascendingList = [entry[0] for entry in measureList[0:influences - subtract]]
return resultList + ascendingList
def zbw_FK2IKSnap(*args):
"""
select FK wrist joint(or control), fk elbow joint (or ctrl), FK shoulder joint (or ctrl), IK wrist ctl and IK pole vector in that order
"""
sel = cmds.ls(sl=True)
fkEndC = cmds.listConnections((sel[0]+".fkEndCtrl"))
fkMidC = cmds.listConnections((sel[0]+".fkMidCtrl"))
fkTopC = cmds.listConnections((sel[0]+".fkTopCtrl"))
ikTopJ = cmds.listConnections((sel[0]+".ikTopJnt"))
ikMidJ = cmds.listConnections((sel[0]+".ikMidJnt"))
ikEndJ = cmds.listConnections((sel[0]+".ikEndJnt"))
#get FK wrist joint position & rot
ikEndPos = cmds.xform(ikEndJ, q=True, ws=True, t=True)
iep = om.MVector(ikEndPos[0], ikEndPos[1], ikEndPos[2])
ikEndRot = cmds.xform(ikEndJ, q=True, ro=True)
ier = om.MVector(ikEndRot[0], ikEndRot[1], ikEndRot[2])
#get FK shoulder position & rot
ikTopPos = cmds.xform(ikTopJ, q=True, ws=True, t=True)
itp = om.MVector(ikTopPos[0], ikTopPos[1], ikTopPos[2])
ikTopRot = cmds.xform(ikTopJ, q=True, ro=True)
itr = om.MVector(ikTopRot[0], ikTopRot[1], ikTopRot[2])
#get midJnt pos & rot
ikMidPos = cmds.xform(ikMidJ, q=True, ws=True, t=True)
imp = om.MVector(ikMidPos[0], ikMidPos[1], ikMidPos[2])
ikMidRot = cmds.xform(ikMidJ, q=True, ro=True)
imr = om.MVector(ikMidRot[0], ikMidRot[1], ikMidRot[2])
#rotate joints to rotations
cmds.xform(fkEndC, ro=(ier.x, ier.y, ier.z))
cmds.xform(fkMidC, ro=(imr.x, imr.y, imr.z))
cmds.xform(fkTopC, ro=(itr.x, itr.y, itr.z))
#snap FK ctrl to positions
#-------try:except this part . . . Will only work if the channels aren't locked . . .
cmds.move(iep.x, iep.y, iep.z, fkEndC, ws=True)
cmds.move(imp.x, imp.y, imp.z, fkMidC, ws=True)
cmds.move(iep.x, iep.y, iep.z, fkEndC, ws=True)
def createJointFromObj(objs = [], *args):
"""
creates a joint at obj location/orientation. Can be arg[list] or selection
:param objs: a list of objects to operate on
:param args:
:return:
"""
if not objs:
objs = cmds.ls(sl=True, type="transform")
if objs:
for obj in objs:
pos = cmds.xform(obj, q=True, ws=True, rp=True)
rot = cmds.xform(obj, q=True, ws=True, ro=True)
jnt = cmds.joint(name="{0}_JNT".format(obj))
grp = cmds.group(jnt, n="{0}_JNT_GRP".format(obj))
if cmds.listRelatives(grp, p=True):
cmds.parent(grp, w=True)
cmds.xform(grp, ws=True, t=pos)
cmds.xform(grp, ws=True, ro=rot)
else:
cmds.warning("You need to select object(s)")
def get_center_point(objs):
positions = []
for obj in objs:
positions.append(cmds.xform(obj, ws=True, q=True, rp=True))
center = [sum(y)/len(y) for y in zip(*positions)]
return(center)
def switchMatchSpace(index, *args):
#get the obj and attr
obj = cmds.textFieldGrp(widgets["objTFG"], q=True, tx=True)
#print("switchMatch obj val :%s"%obj)
attr = "%s.follow"%obj
#get the space value that was selected? why?
#get the existing ws xform values of obj
ws1Pos = cmds.xform(obj, q=True, ws=True, t=True)
ws1Rot = cmds.xform(obj, q=True, ws=True, ro=True)
#(maybe also key it a frame before at previous value?)
#set and key the switch
cmds.setAttr("%s.follow"%obj, index)
#-------------setKey here?
#set the old ws xform of obj
ws2Pos = cmds.xform(obj, ws=True, t=ws1Pos)
ws2Rot = cmds.xform(obj, ws=True, ro=ws1Rot)
print("changed space of %s to index %s"%(obj,index))
#set and key the space
pass