本文整理汇总了Python中maya.cmds.spaceLocator函数的典型用法代码示例。如果您正苦于以下问题:Python spaceLocator函数的具体用法?Python spaceLocator怎么用?Python spaceLocator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spaceLocator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MakePointOnSurfaceNd
def MakePointOnSurfaceNd(surface):
mc.select ("mesh_*MouthLip")
lx_mesh = mc.ls(sl=1)
mc.select ("snd_mouthLip*")
lx_sndJnt = mc.ls(sl=True )
lx_node ,lx_locGrp=[],[]
for lx_i in lx_sndJnt :
lx_temp=mc.xform(lx_i,q=1,ws =1,t=1)
lx_locN= "loc_"+lx_i
mc.spaceLocator(n=lx_locN,a=1,p=(lx_temp[0],lx_temp[1],lx_temp[2]))
lx_locGrp.append(lx_locN)
lx_null = 'grp_'+lx_i+'02'
mc.group(n=lx_null,em =1)
mc.toggle (lx_null,la=1)
mc.parent (lx_null ,('grp_'+lx_i+'01'))
mc.parent (('grp_'+lx_i+'03'),lx_null)
nd=mc.pointOnSurface(lx_mesh,ch=True )
#lx_node.insert(1,nd);
ndName = "pntNd_"+lx_i
mc.rename(nd,ndName )
mc.connectAttr ((ndName +".position"),('grp_'+lx_i+'02.translate'))
mc.setAttr (('grp_'+lx_i+'01.translate'),0,0,0,type ="double3")
mc.setAttr (('grp_'+lx_i+'03.translate'),0,0,0,type="double3")
mc.xform (('grp_'+lx_i+'01'),cp=True)
mc.select(cl=1)
mc.select(lx_locGrp )
mc.group (n="grp_locMouthLip01")
示例2: pointOnCurveLocCV
def pointOnCurveLocCV(name,curve):
if not cmds.nodeType(curve) == 'shape':
curve = cmds.listRelatives(curve, type = 'shape')[0]
mobject = GenAPI.getMObject(curve)
iterCVs = om.MItCurveCV(mobject)
while not iterCVs.isDone():
index = iterCVs.index()
nameIndex = index + 1
moPath = cmds.createNode('motionPath')
moPath = cmds.createNode('motionPath',n = '%s_0%i_MotionPath'%(name,nameIndex))
cmds.connectAttr('%s.worldSpace[0]'%curve,'%s.geometryPath'%moPath)
locator = cmds.spaceLocator(n = '%s_0%i_MP_Loc'%(name,nameIndex))
cmds.addAttr(locator[0],ln = "Offset" ,at = 'double')
cmds.setAttr('%s.Offset'%locator[0], e = True, keyable = True)
upLocator = cmds.spaceLocator(n = '%s_0%i_MP_Up_Loc'%(name,nameIndex))
cmds.connectAttr('%s.allCoordinates'%moPath,'%s.translate'%locator[0])
cmds.connectAttr('%s.rotate'%moPath,'%s.rotate'%locator[0])
cmds.connectAttr('%s.rotateOrder'%moPath, '%s.rotateOrder'%locator[0])
uValue = MeasuringTool.curveCVtoU(curve,index)
cmds.setAttr('%s.uValue'%moPath, uValue)
cmds.setAttr('%s.worldUpType'%moPath, 2)
cmds.setAttr ('%s.frontAxis'%moPath,0)
cmds.setAttr ('%s.upAxis'%moPath,2)
offsetMD = cmds.createNode('multiplyDivide', n = '%s_0%i_Offset_MD'%(locator[0],nameIndex))
cmds.connectAttr('%s.Offset'%locator[0],'%s.input1X'%offsetMD)
cmds.setAttr('%s.input2X'%offsetMD, 0.1)
offsetPMA = cmds.createNode('plusMinusAverage', n = '%s_0%i_Offset_PMA'%(locator[0],nameIndex))
cmds.connectAttr('%s.outputX'%offsetMD,'%s.input1D[0]'%offsetPMA )
cmds.setAttr('%s.input1D[1]'%offsetPMA,uValue)
cmds.connectAttr('%s.output1D'%offsetPMA, '%s.uValue'%moPath)
locPos = cmds.xform(locator[0], q = True, ws = True, translation = True)
locOrient = cmds.xform(locator[0], q = True, ws = True, rotation = True)
cmds.setAttr ('%s.worldUpVectorX'%moPath,0)
cmds.setAttr ('%s.worldUpVectorY'%moPath,0)
cmds.setAttr ('%s.worldUpVectorZ'%moPath,1)
cmds.connectAttr('%s.worldMatrix[0]'%upLocator[0], '%s.worldUpMatrix'%moPath)
nullGroup = cmds.group(empty = True, n = '%s_Group'%upLocator[0])
cmds.move(locPos[0], locPos[1],locPos[2],nullGroup)
cmds.rotate(locOrient[0],locOrient[1],locOrient[2], nullGroup)
cmds.parent(upLocator[0], nullGroup,r = True)
cmds.move(0,0,10,upLocator[0], a = True, os = True)
cmds.group(locator[0],nullGroup,n = '%s_0%i_MP_Loc_Group'%(name,nameIndex))
iterCVs.next()
示例3: rotateOrderReference
def rotateOrderReference(self, rotorder, *args):
if rotorder == 0:
# 既に存在するかチェック
if cmds.objExists("locatorXYZ"):
print ("locatorXYZ exists already.")
else:
cmds.spaceLocator(p=(0, 0, 0), n="locatorXYZ")
cmds.select("locatorXYZ")
cmds.setAttr("locatorXYZ.rotateOrder", 0)
if rotorder == 2:
# 既に存在するかチェック
if cmds.objExists("locatorXYZ"):
print ("locatorZXY exists already.")
else:
cmds.spaceLocator(p=(0, 0, 0), n="locatorZXY")
cmds.select("locatorZXY")
cmds.setAttr("locatorZXY.rotateOrder", 2)
else:
print ("Info: RotateOrder Input Parameter Error <Sync Unity Transform> ")
示例4: aimRig
def aimRig(self,name):
#query start location and orient
startPosition = MeasuringTool.getPointLocation(self.objectStart)
startOrient = MeasuringTool.getWorldEulerRotation(self.objectStart)
#create locators
aimLoc = cmds.spaceLocator(n = '%s_Aim_AimVector_Loc'%(name))
upLoc = cmds.spaceLocator(n = '%s_Aim_UpVector_Loc'%(name))
tgt = cmds.spaceLocator(n = '%s_Aim_Target_Loc'%(name))
#create hierarchy
posNull = cmds.group(aimLoc[0],upLoc[0],tgt[0],n = '%s_Aim_Pos_Null'%(name))
cmds.move(startPosition[0],startPosition[1],startPosition[2],posNull)
cmds.rotate(startOrient[0],startOrient[1],startOrient[2],posNull)
#find vector length
distance = self.getPointDistanceBetween()
length = MeasuringTool.getVectorLength([distance[0],distance[1],distance[2]])
#move and apply constraints to target
cmds.move(length,0,0,tgt, a = True, os = True)
cmds.move(0,0,10,upLoc[0],os = True)
cmds.parentConstraint(self.objectStart,posNull)
cmds.pointConstraint(self.objectEnd,tgt[0])
cmds.aimConstraint(tgt,aimLoc, aimVector = (1,0,0), upVector = (0,0,1), worldUpType = "object", worldUpObject = upLoc[0])
示例5: setup_dof
def setup_dof(target, camera, f_stop):
cmds.setAttr(camera + ".depthOfField", 1)
# create a locator parented to the camera
cam_matrix = cmds.xform(camera, q=True, m=True, ws=True)
cam_locator = cmds.spaceLocator()
cmds.xform(cam_locator, m=cam_matrix, ws=True)
cmds.select(cam_locator, camera, r=True)
cmds.parent()
# create a locator parented to the target
target_matrix = cmds.xform(target, q=True, m=True, ws=True)
target_locator = cmds.spaceLocator()
cmds.xform(target_locator, m=target_matrix, ws=True)
cmds.select(target_locator, target, r=True)
cmds.parent()
distance_node = cmds.distanceDimension(cam_locator, target_locator)
cmds.connectAttr(distance_node + ".distance", camera + ".focusDistance")
f_stop_multiplier = 1.0
while f_stop < 1.0:
f_stop *= 2.0
f_stop_multiplier /= 2.0
cmds.setAttr(camera + ".fStop", f_stop)
cmds.setAttr(camera + ".focusRegionScale", f_stop_multiplier)
示例6: bdGetComMain
def bdGetComMain():
locators = cmds.ls('locator*')
if locators:
cmds.delete(locators)
mDagObject = om.MDagPath()
mSelList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(mSelList)
centerMass = om.MPoint(0,0,0)
mSelList.getDagPath(0,mDagObject)
print centerMass.x, centerMass.y, centerMass.z
if mSelList.length():
if mDagObject.hasFn(om.MFn.kMesh):
mFnMesh = om.MFnMesh(mDagObject)
for i in range(mFnMesh.numVertices()):
mVertPos = om.MPoint()
mFnMesh.getPoint(i,mVertPos,om.MSpace.kWorld)
print i
print mVertPos.x, mVertPos.y,mVertPos.z
centerMass += om.MVector(mVertPos)
print centerMass.x, centerMass.y,centerMass.z
cmds.spaceLocator(p=[mVertPos.x,mVertPos.y,mVertPos.z])
print mFnMesh.numVertices()
centerMass = centerMass / (mFnMesh.numVertices())
cmds.spaceLocator(p=[centerMass.x,centerMass.y,centerMass.z])
示例7: createPathLocators
def createPathLocators(*argv):
oPathLoc = cmds.spaceLocator(n='pathLocator')
oStopLoc = cmds.spaceLocator(n='stopLocator')
oPathLocGrp = cmds.group(oPathLoc,n='pathLocatorGrp')
cmds.group(oStopLoc,n='stopLocatorGrp')
cmds.pathAnimation( oPathLocGrp, stu=0, etu=1000, fa='x', ua='y', bank=True, fm = True,c='pathCurve' )
cmds.parentConstraint(oPathLoc,oStopLoc,cmds.ls('*:Master_Anim')[0])
示例8: setupSw
def setupSw(self):
for joint in self._joints:
name = joint.replace(nameLib.prefixNames.jointSuffix, "") + nameLib.prefixNames.locator
# create locators
worldLocator = mc.spaceLocator(name="world_" + name)
localLocator = mc.spaceLocator(name="local_" + name)
# group for locators
rootGroup = utils.makeGroup.MakeGroup(name=name + nameLib.prefixNames.offsetGroup)
mc.parent(worldLocator, rootGroup.groupName)
mc.parent(localLocator, rootGroup.groupName)
# snap locators to posittion
mc.delete(mc.parentConstraint(joint, rootGroup.groupName))
# put them into root group
mc.parent(rootGroup.groupName, self._parent)
# orient constrain from global control
mc.orientConstraint(nameLib.prefixNames.globalControl + nameLib.prefixNames.controlSuffix, worldLocator, maintainOffset=True)
# constraint from parent
parent = mc.listRelatives(joint, parent=True)[0].replace(nameLib.prefixNames.jointSuffix, "")
parentControl = nameLib.prefixNames.fkPrefix + parent + nameLib.prefixNames.controlSuffix
mc.parentConstraint(parentControl, rootGroup.groupName, maintainOffset=True)
# create constraint for cotroller's driven group
drivenGroup = nameLib.prefixNames.fkPrefix + name.replace(nameLib.prefixNames.locator, "") + nameLib.prefixNames.controlSuffix + nameLib.prefixNames.drivenGroup
localWorldConstraint = mc.parentConstraint(worldLocator, drivenGroup)
localWorldConstraint = mc.parentConstraint(localLocator, drivenGroup)
# create connections from controller
weightList = [worldLocator[0] + "W0", localLocator[0] + "W1"]
self.connectSW(localWorldConstraint[0], parentControl, weightList)
示例9: set_knee_IK
def set_knee_IK():
# メッセージ
cmds.inViewMessage(amg="<hl>「指のコントローラー設置」</hl>を押してください。", pos="midCenter", fade=True, fit=1, fst=4000, fts=20)
# 座標取得
positionR = cmds.xform("Knee_R", q=True, ws=True, t=True)
locatorNameR = "Knee_R_Locator"
# ロケーター設置
cmds.spaceLocator(p=(positionR[0], positionR[1], positionR[2] + 3.8), n=locatorNameR)
knee_ik_add("Hip_R", "Ankle_R", "Knee_R_Effector", positionR, locatorNameR)
# 座標取得
positionL = cmds.xform("Knee_L", q=True, ws=True, t=True)
locatorNameL = "Knee_L_Locator"
# ロケーター設置
cmds.spaceLocator(p=(positionL[0], positionL[1], positionL[2] + 3.8), n=locatorNameL)
knee_ik_add("Hip_L", "Ankle_L", "Knee_L_Effector", positionL, locatorNameL)
# つま先のIK実行
toe_ik_add("Ankle_R", "MiddleToe2_R", "Ankle_R_Effector")
toe_ik_add("Ankle_L", "MiddleToe2_L", "Ankle_L_Effector")
# 足のコントローラー、 座標取得
toePositionR = cmds.xform("MiddleToe1_R", q=True, ws=True, t=True)
toePositionL = cmds.xform("MiddleToe1_L", q=True, ws=True, t=True)
foot_controller("foot_R_controller", toePositionR[0])
foot_controller("foot_L_controller", toePositionL[0])
# コントローラー内にエフェクター移動
cmds.parent("Ankle_L_Effector", "foot_L_controller")
cmds.parent("Knee_L_Effector", "foot_L_controller")
cmds.parent("Ankle_R_Effector", "foot_R_controller")
cmds.parent("Knee_R_Effector", "foot_R_controller")
# 親子関係移動
cmds.parent("Knee_R_Locator", "Knee_L_Locator", "foot_R_controller", "foot_L_controller", "main_controller")
示例10: setUp
def setUp(self):
cmds.file(newFile=True,f=True)
self.sphere = cmds.polySphere()
self.loc1 = cmds.spaceLocator()[0]
self.loc2 = cmds.spaceLocator()[0]
self.joint = cmds.joint()
示例11: createPoleVector
def createPoleVector(self, prefix=None, distanceScale=2, verbose=False):
print 'Building pole vector...'
if prefix is None:
prefix = self.prefix
# Create Joint Vectors
shoulderIkPos = cmds.xform(self.shoulder, q=True, ws=True, t=True)
shoulderIkVec = OpenMaya.MVector(shoulderIkPos[0], shoulderIkPos[1], shoulderIkPos[2])
elbowIkPos = cmds.xform(self.elbow, q=True, ws=True, t=True)
elbowIkVec = OpenMaya.MVector(elbowIkPos[0], elbowIkPos[1], elbowIkPos[2])
wristIkPos = cmds.xform(self.wrist, q=True, ws=True, t=True)
wristIkVec = OpenMaya.MVector(wristIkPos[0], wristIkPos[1], wristIkPos[2])
# Transpose vectors to correct pole vector translation point
bisectorVec = (shoulderIkVec * 0.5) + (wristIkVec * 0.5)
transposedVec = (elbowIkVec * distanceScale) - (bisectorVec * distanceScale)
ikChainPoleVec = bisectorVec + transposedVec
# Create a pole vector
poleVecCon = self.utils.createBoxControl('%selbowPV' % self.prefix, 0.125)
poleVecPos = [ikChainPoleVec.x, ikChainPoleVec.y, ikChainPoleVec.z]
cmds.xform(poleVecCon, t=poleVecPos)
self.utils.orientSnap(self.elbow, poleVecCon)
# Visualize Vectors and End Points
if verbose:
for vector, letter in zip([bisectorVec, transposedVec, ikChainPoleVec,
shoulderIkVec, elbowIkVec, wristIkVec],
['bisectorVec', 'transposedVec', 'ikChainPoleVec',
'shoulderIk', 'elbowIk', 'wristIk']):
cmds.spaceLocator(n='%sVecLoc' % letter, p=[vector.x, vector.y, vector.z])
cmds.curve(n='%sVecCurve' % letter, degree=1, p=[(0, 0, 0), (vector.x, vector.y, vector.z)])
return poleVecCon
示例12: createDistanceNode
def createDistanceNode(**kwargs):
startTransform = kwargs.get('start')
endTransform = kwargs.get('end')
name = kwargs.get('name')
startPos = cmds.xform(startTransform,q = True,ws = True, translation = True)
endPos = cmds.xform(endTransform,q = True,ws = True, translation = True)
group = cmds.group(empty = True, name = '%s_Locator_Group'%name)
startGroup = cmds.group(empty = True, name = '%s_Start_Locator_Group'%name)
endGroup = cmds.group(empty = True, name = '%s_End_Locator_Group'%name)
cmds.parent(startGroup,group)
cmds.parent(endGroup,group)
startLocator = cmds.spaceLocator(name = '%s_Start_Locator'%name)[0]
endLocator = cmds.spaceLocator(name = '%s_End_Locator'%name)[0]
cmds.parent(startLocator,startGroup)
cmds.parent(endLocator,endGroup)
cmds.move(startPos[0],startPos[1],startPos[2],startLocator,ws = True)
cmds.move(endPos[0],endPos[1],endPos[2],endLocator,ws = True)
lengthNode = cmds.createNode('kLengthNode',name = '%s_Length'%name)
cmds.connectAttr('%s.worldMatrix[0]'%startLocator, '%s.startWorldMatrix'%lengthNode)
cmds.connectAttr('%s.parentInverseMatrix[0]'%startLocator, '%s.startParentInverseMatrix'%lengthNode)
cmds.connectAttr('%s.worldMatrix[0]'%endLocator, '%s.endWorldMatrix'%lengthNode)
cmds.connectAttr('%s.parentInverseMatrix[0]'%endLocator, '%s.endParentInverseMatrix'%lengthNode)
return lengthNode
示例13: _plotter_avrg
def _plotter_avrg(self):
'''plots a locator to a vertice or face per keyframe in a timeline'''
selObj=cmds.ls(sl=1, fl=1)
if len(selObj)>0:
pass
else:
print "Select 1 object"
return
getTopRange=cmds.playbackOptions(q=1, max=1)+1#get framerange of scene to set keys in iteration
getLowRange=cmds.playbackOptions(q=1, min=1)-1#get framerange of scene to set keys in iteration
edgeBucket=[]
getRange=arange(getLowRange,getTopRange, 1 )
getloc=cmds.spaceLocator(n=selObj[0]+"cnstr_lctr")
cmds.normalConstraint(selObj[0], getloc[0])
placeloc=cmds.spaceLocator(n=selObj[0]+"lctr")
for each in getRange:
cmds.currentTime(each)
transform=cmds.xform(selObj, q=1, ws=1, t=1)
posBucketx=self.array_median_find(transform[0::3])
posBuckety=self.array_median_find(transform[1::3])
posBucketz=self.array_median_find(transform[2::3])
cmds.xform(getloc[0], ws=1, t=(posBucketx, posBuckety, posBucketz))
cmds.SetKeyTranslate(getloc[0])
cmds.xform(placeloc[0], ws=1, t=(posBucketx, posBuckety, posBucketz))
cmds.SetKeyTranslate(placeloc[0])
rotate=cmds.xform(getloc[0], q=True, ws=1, ro=True)
cmds.xform(placeloc[0], ws=1, ro=rotate)
cmds.SetKeyRotate(placeloc[0])
cmds.currentTime(each)
示例14: _buildOffsetCloud
def _buildOffsetCloud(self,nodes,rootReference=None,raw=False):
'''
Build a point cloud up for each node in nodes
@param nodes: list of objects to be in the cloud
@param rootReference: the node used for the initial pibot location
@param raw: build the cloud but DON'T snap the nodes into place - an optimisation for the PoseLoad sequence
'''
self.posePointCloudNodes=[]
self.posePointRoot=cmds.ls(cmds.spaceLocator(name='posePointCloud'),l=True)[0]
ppcShape=cmds.listRelatives(self.posePointRoot,type='shape')[0]
cmds.setAttr( "%s.localScaleZ" % ppcShape, 30)
cmds.setAttr( "%s.localScaleX" % ppcShape, 30)
cmds.setAttr( "%s.localScaleY" % ppcShape, 30)
if self.mayaUpAxis=='y':
cmds.setAttr('%s.rotateOrder' % self.posePointRoot, 2)
if rootReference:# and not mesh:
r9Anim.AnimFunctions.snap([rootReference,self.posePointRoot])
for node in nodes:
pnt=cmds.spaceLocator(name='pp_%s' % r9Core.nodeNameStrip(node))[0]
if not raw:
r9Anim.AnimFunctions.snap([node,pnt])
cmds.parent(pnt,self.posePointRoot)
self.posePointCloudNodes.append((pnt,node))
return self.posePointCloudNodes
示例15: createCurveFromMesh
def createCurveFromMesh( meshName, centerIndices, startIndex, endIndices, numSample=20 ):
bb = om.MBoundingBox()
for i in centerIndices:
point = om.MPoint( *cmds.xform( meshName+'.vtx[%d]' % i, q=1, ws=1, t=1 ) )
bb.expand( point )
centerPoint = bb.center()
bb = om.MBoundingBox()
for i in endIndices:
point = om.MPoint( *cmds.xform( meshName+'.vtx[%d]' % i, q=1, ws=1, t=1 ) )
bb.expand( point )
endPoint = bb.center()
startPoint = om.MPoint( *cmds.xform( meshName+'.vtx[%d]' % startIndex, q=1, ws=1, t=1 ) )
aimVector = om.MVector( endPoint ) - om.MVector( startPoint )
eachPoints = []
multRate = 1.0/( numSample-1 )
for i in range( numSample ):
eachPoint = aimVector * (multRate*i) + om.MVector( centerPoint )
eachPoints.append( om.MPoint( eachPoint ) )
fnMesh = getMFnMesh( meshName )
mtx = fnMesh.dagPath().inclusiveMatrix()
mtxInv = mtx.inverse()
intersector = om.MMeshIntersector()
intersector.create( fnMesh.object() )
pointOnMesh = om.MPointOnMesh()
for point in eachPoints:
intersector.getClosestPoint( point*mtxInv, pointOnMesh )
closePoint = om.MPoint( pointOnMesh.getPoint() )*mtx
cmds.spaceLocator( p=[closePoint.x, closePoint.y, closePoint.z] )