def createConnectorCurve(xforms, parent=None, name=None): xforms = pm.ls(xforms) if (len(xforms) < 2) or not all( isinstance(xform, pm.nodetypes.Transform) for xform in xforms): raise ValueError( 'createConnectorCurve requires at least 2 transforms.') name = name or '{}_connector'.format(xforms[0].name()) crv = pm.curve(name=name, ep=[xform.getTranslation(ws=True) for xform in xforms], d=1) crv.overrideEnabled.set(True) crv.overrideDisplayType.set(1) crv.setParent(parent) for i, xform in enumerate(xforms): loc = pm.pointCurveConstraint(crv.ep[i])[0] loc = pm.ls(loc)[0] pm.rename(loc, '{}_loc1'.format(xform.name())) pm.xform(loc, cp=True) pm.parentConstraint(xform, loc) loc.setParent(parent) loc.visibility.set(False) pm.select(None) return crv
def create(self): pointA = self.startObj pointB = self.endObj position = (0,0,0) # 커브 생성 crv = pm.curve( d=1, p=[ position, position ], k=[0,1] ) self.curve = crv.getShape() # obj에 커브 쉐입을 종속 시킴 : 커브를 선택해도 오브젝트를 선택한 효과를 줌. pm.parent( self.curve, pointA, r=True, s=True) pm.delete( crv ) # target에 locator를 종속 시킴 self.locator = pm.pointCurveConstraint( self.curve+'.ep[1]', ch=True)[0] self.locator = pm.PyNode(self.locator) pm.pointConstraint( pointB, self.locator ) # 로케이서 속성 조정 self.locator.getShape().localPosition.set(0,0,0) #이 로케이터는 보이지 않음 self.locator.getShape().v.set(False) #이 로케이터는 보이지 않음 self.locator.v.set(False) #이 로케이터는 보이지 않음 self.locator.setParent(pointA) self.locator.rename( pointB+'_CONNLOC' ) # 커브쉐입에 어트리뷰트 추가 self.curve.addAttr( 'curveConnectedTo', at='message' ) self.curve.addAttr( 'curveConnectedLOC', at='message' ) # 어트리뷰트 연결 pointB.message >> self.curve.curveConnectedTo self.locator.message >> self.curve.curveConnectedLOC
def rigCurveConnect( *objs, **kwargs ): ''' update : 2015-04-15 ''' if objs: pm.select(objs) sel = pm.selected( type='transform') if not sel: raise obj = sel[0] # 삭제 delete = kwargs.get('delete', False) if delete: for crvShp in obj.getShapes(): if crvShp.hasAttr('curveConnectedLOC'): try: pm.delete( crvShp, crvShp.curveConnectedLOC.inputs() ) except: pass return True # 타겟 가져옴. target = sel[1] name = kwargs.get('name') or kwargs.get('n', target+'_CONNCRV' ) position = kwargs.get('position') or kwargs.get('p', (0,0,0) ) # 커브 생성 crvTrans = pm.curve( n=name, d=1, p=[ position, position ], k=[0,1] ) crvShape = crvTrans.getShape() # obj에 커브 쉐입을 종속 시킴 : 커브를 선택해도 오브젝트를 선택한 효과를 줌. pm.parent( crvShape, obj, r=True, s=True) pm.delete( crvTrans ) # target에 locator를 종속 시킴 loc = pm.pointCurveConstraint( crvShape+'.ep[1]', ch=True)[0] loc = pm.PyNode(loc) pm.pointConstraint( target, loc ) # 로케이서 속성 조정 loc.getShape().localPosition.set(0,0,0) loc.getShape().v.set(False) loc.v.set(False) loc.setParent(obj) loc.rename( target+'_CONNLOC' ) # 커브쉐입에 어트리뷰트 추가 crvShape.addAttr( 'curveConnectedTo', at='message' ) crvShape.addAttr( 'curveConnectedLOC', at='message' ) # 어트리뷰트 연결 target.message >> crvShape.curveConnectedTo loc. message >> crvShape.curveConnectedLOC return loc
def rigCurveConnect(*objs, **kwargs): ''' update : 2015-04-15 update : 2016-11-03 ''' if objs: pm.select(objs) sel = pm.selected(type='transform') if not sel: raise obj = sel[0] # # 삭제 # delete = kwargs.get('delete', False) if delete: deleteList = [] for crvShp in obj.getShapes(): if crvShp.hasAttr('curveConnectedLOC'): deleteList = [ crvShp, crvShp.curveConnectedLOC.inputs(), crvShp.history(type='nurbsCurve')[-1] ] if deleteList: pm.delete(deleteList) print deleteList return # # 생성 # # 타겟 가져옴. target = sel[1] position = kwargs.get('position') or kwargs.get('p', (0, 0, 0)) # 커브 생성 crvTrans = pm.curve(d=1, p=[position, position], k=[0, 1]) crvShape = crvTrans.getShape() # obj에 커브 쉐입을 종속 시킴 : 커브를 선택해도 오브젝트를 선택한 효과를 줌. pm.parent(crvShape, obj, r=True, s=True) pm.delete(crvTrans) crvShape.rename(obj + 'Shape') # target에 locator를 종속 시킴 loc, leastSquaresModifier = pm.pointCurveConstraint(crvShape + '.ep[1]', ch=True) loc = pm.PyNode(loc) leastSquaresModifier = pm.PyNode(leastSquaresModifier) const = pm.pointConstraint(target, loc) # 로케이서 속성 조정 loc.getShape().localPosition.set(0, 0, 0) loc.getShape().v.set(False) loc.v.set(False) loc.setParent(obj) loc.rename(target + '_locator#') const.rename(target + '_pointConst#') # 커브쉐입에 어트리뷰트 추가 (깔끔 삭제용) crvShape.addAttr('curveConnectedTo', at='message') crvShape.addAttr('curveConnectedLOC', at='message') crvShape.addAttr('curveConnectedOrgShape', at='message') # 어트리뷰트 연결 target.message >> crvShape.curveConnectedTo loc.message >> crvShape.curveConnectedLOC # 선택 pm.select(obj) return loc