def create_nurbs(self): self.nurbs = pm.nurbsPlane(name='geo_' + self.ribbon_name, pivot=[0, 0, 0], axis=[0, 1, 0], width=1, lengthRatio=self.ribbon_segment, degree=3, ch=False)[0] self.nurbs.setRotation([0, 90, 0], space='world') pm.makeIdentity(self.nurbs, a=True, rotate=True) # rebuild nurbs to reduce CVs pm.rebuildSurface(self.nurbs, replaceOriginal=True, rebuildType=0, endKnots=1, keepRange=0, keepControlPoints=0, keepCorners=0, spansU=1, degreeU=1, spansV=self.ribbon_segment, degreeV=3, ch=False)
def build_plane(name=None, crv=None, spans=None, direction='u', width_axis=None, width=1, log=True): '''Given a valid curve, build nurbs plane Attributes: name -- Prefix name for plane. Str crv -- Curve to use as build guide. nt.Transform spans -- Spans for the plane. Int direction -- Build direction. 'u' or 'v' width_axis -- Plane width axis. 'x', 'y' or 'z' width -- Width of plane. Float ''' general.check_type(name, 'name', [str]) general.check_type(crv, 'crv', [pm.nt.Transform]) general.check_type(spans, 'spans', [int]) general.check_type(direction, 'direction', [str]) general.check_type(width_axis, 'width_axis', [str]) general.check_type(width, 'width', [float, int]) if direction not in ['u', 'v']: raise errors.InputError('direction', direction, "'u' or 'v'") if width_axis not in ['x', 'y', 'z']: raise errors.InputError('width_axis', width_axis, "'x', 'y' or 'z'") d1 = crv.duplicate() d2 = crv.duplicate() move_amt = [] if width_axis == 'x': move_amt = [width, 0, 0] elif width_axis == 'y': move_amt = [0, width, 0] elif width_axis == 'z': move_amt = [0, 0, width] if log: str_1 = 'move_amt: ', move_amt general.logging.debug(str_1) pm.move(move_amt[0], move_amt[1], move_amt[2], d1, r=1) pm.move(-move_amt[0], -move_amt[1], -move_amt[2], d2, r=1) p = pm.loft(d1, d2, n=name + '_plane', ch=0)[0] if direction == 'u': pm.rebuildSurface(p, dir=2, su=spans, sv=2) if direction == 'v': pm.rebuildSurface(p, dir=2, sv=spans, su=2) pm.delete(d1) pm.delete(d2) return p
def createRibbonSpine(*args): jointChainLen = int(jointChainLenField.getText()) nurbsPlnName = nameField.getText() + '_ribbonPlane' nurbsPln = pm.nurbsPlane(u = 1, v = jointChainLen, lr = jointChainLen, n = nurbsPlnName, ax = [0,0,1]) pm.rebuildSurface(nurbsPln, ch = 1, rpo = 1, end = 1, kr = 0, kc = 0, su =1, du = 1, sv = 5, dv = 3, tol = .01, dir = 0) pm.select(nurbsPln, r = True) mNurbsPln = pm.ls(selection = True)[0]
def build(self): # make the nurbs plane self.ribbonIkPlane = pm.nurbsPlane( axis = (0,0,1), degree = 3, #cubic constructionHistory = False, name = self.name +'_'+d.PLANE, patchesU = 1, patchesV = self.numSpans, lengthRatio = self.numSpans)[0] pm.rebuildSurface(self.ribbonIkPlane, degreeU=1, spansU=1, direction=0) u.makeNonRendering(self.ribbonIkPlane) pm.setAttr('%s.%s'% (self.ribbonIkPlane.name(),'visibility'), 0) pm.setAttr('%s.%s'% (self.ribbonIkPlane.name(), 'inheritsTransform'), 0) # move the pivots to the top of the plane self.ribbonIkPlane.setPivots((0,(self.numSpans/2.0),0)) # place and scale the plane in 3d space pm.delete(pm.pointConstraint(self.startLoc,self.ribbonIkPlane)) pm.delete(pm.orientConstraint(self.startLoc,self.ribbonIkPlane)) #pm.delete(pm.aimConstraint(self.endLoc,self.ribbonIkPlane, # aimVector=(0,-1,0))) #skip =('x','z'))) height = u.distance(self.startLoc, self.endLoc) scale = (height / self.numSpans) self.ribbonIkPlane.scaleBy((scale,scale,scale)) # create and attach follicles follicles = [] for i in range(1,(self.numJoints+1)): follicle = self.createFollicle( shape = self.ribbonIkPlane.getShape(), posV = (i-1.0)/float(self.numJoints-1.0), posU = 0.5, name = self.name + "_%s%02d" % (d.FOLLICLE,i)) pm.setAttr(follicle.visibility, False) follicles.append(follicle) self.follicleGrp = pm.group(follicles, name='%s_%s_grp' % \ (self.name,d.FOLLICLE)) pm.setAttr('%s.%s'% (self.follicleGrp,'inheritsTransform'),0) # create the bind joints for i,f in enumerate(follicles): self.bindJoints.append(u.placeJoint( position = u.getWsLocation(f), name = '%s%s%02d_%s'%(self.name, d.JOINT.title(), i+1, self.jointPostfix), parent = f)) # parent self.ribbonIkPlane.setParent(self.parent)
def point_base(self, *points, **kwargs): super(Loft, self).point_base(*points, **kwargs) delete_history = kwargs.pop('delete_history', True) self.path = self.curve_creator.point_base(*pm.ls(points), ep=True) self._create_profile(**kwargs) original_surf = pm.extrude(self.profile, self.path, fixedPath=True, useComponentPivot=1, useProfileNormal=True) swap_uv = pm.rebuildSurface(original_surf[0], keepControlPoints=True, rebuildType=0, keepRange=0) new_surface = pm.reverseSurface(swap_uv[0], direction=3) self.skin_surface = new_surface[0] self.name_convention.rename_name_in_format(self.skin_surface, name='extrude') cps = pm.createNode('closestPointOnSurface') measure_locator = self.locator_creator.point_base(points[0]) measure_locator.worldPosition >> cps.inPosition self.skin_surface.worldSpace[0] >> cps.inputSurface u_closer_value = cps.parameterU.get() pm.delete(measure_locator, cps) if u_closer_value > .5: new_surface = pm.reverseSurface(self.skin_surface, direction=0) self.skin_surface = new_surface[0] if delete_history: self.delete_history() return self.skin_surface
def createRbnSrf(self): startJntVec = om.MVector(self.start[0], self.start[1], self.start[2]) endJntVec = om.MVector(self.end[0], self.end[1], self.end[2]) diffVec = endJntVec - startJntVec # calculate the witdth of the surface as a fraction of the total joint chain length jntChainLength = diffVec.length() self.width = jntChainLength * self.widthMult crvPoints = [] for i in range(self.numCtrl): vec = startJntVec + diffVec * (i * 1.0 / (self.numCtrl - 1)) crvPoints.append([vec.x, vec.y, vec.z]) tmp = pm.curve(n=self.name + '_crv1', d=1, p=crvPoints) crv1 = pm.ls(tmp)[0] crv1.setPivots(self.start) crv2 = pm.duplicate(crv1)[0] self.offsetCrv(crv1, -1.0 * self.width / 2) self.offsetCrv(crv2, 1.0 * self.width / 2) tmpLoftSrf = pm.loft(crv1, crv2, ch=0, u=1, c=0, ar=1, d=3, ss=1, rn=0, po=0, rsn=1, n=self.name + "_tmp")[0] rebuiltLoftSrf = \ pm.rebuildSurface(ch=0, rpo=0, rt=0, end=1, kr=0, kcp=0, kc=0, su=0, du=3, sv=0, dv=1, fr=0, dir=2, n=self.name + "_srf")[0] rebuiltLoftSrf.setPivots(rebuiltLoftSrf.c.get()) self.rbnSrf = rebuiltLoftSrf pm.delete(self.rbnSrf, ch=1) pm.delete([crv1, crv2, tmpLoftSrf]) pm.parent(self.rbnSrf, self.mainGrp)
def create_guideSurface( IdName, listOfJnts ): loftCurves = [] for i in range(2): # duplicate and select hierarchy of joints listOfOffsetJnts = pm.duplicate( listOfJnts, name = 'b_' + IdName +'_offset1', parentOnly = True ) # offset each joint on it's own z-axis for jnt in listOfOffsetJnts: if i == 0: pm.move(jnt, (0,0,-0.5), relative = True, objectSpace = True, preserveChildPosition = True) if i == 1: pm.move(jnt, (0,0,0.5), relative = True, objectSpace = True, preserveChildPosition = True) # draw loftcurves loftCurvePoints = [] for each in listOfOffsetJnts: jntPosition = pm.xform(each, q = True, t = True, ws = True) loftCurvePoints.append(jntPosition) loftCurves.append( pm.curve( name = IdName + '_loftCurve' + str(i), degree = 1, point = loftCurvePoints ) ) pm.delete(listOfOffsetJnts) # loft guideSurface guideSurface = pm.loft( loftCurves[0], loftCurves[1], name = IdName + '_guide_surface', ar=True, rsn=True, d=3, ss=1, object=True, ch=False, polygon=0 ) guideSurface = pm.rebuildSurface( guideSurface ,ch=1, rpo=1, rt=0, end=1, kr=1, kcp=0, kc=0, su=0, du=3, sv=1, dv=3, tol=0.01, fr=0, dir=2 ) # cleanup pm.delete( loftCurves ) guideSurface[0].inheritsTransform.set(False) guideSurface[0].overrideEnabled.set(True) guideSurface[0].overrideDisplayType.set(1) # guideSurface[0].visibility.set(False) print('Successfully lofted guide surface. Continuing...') return guideSurface
def buildSrf(self): startJntVec = om.MVector(self.start[0], self.start[1], self.start[2]) endJntVec = om.MVector(self.end[0], self.end[1], self.end[2]) diffVec = endJntVec - startJntVec self.rbnLength = diffVec.length() crvPoints = [] for i in range(self.rbnSegments + 1): vec = startJntVec + diffVec * (i * 1.0 / self.rbnSegments) crvPoints.append([vec.x, vec.y, vec.z]) # pm.spaceLocator(p=[vec.x,vec.y,vec.z]) tmp = pm.curve(n=self.rbnName + '_crv1', d=1, p=crvPoints) crv1 = pm.ls(tmp)[0] crv1.setPivots(self.start) crv2 = pm.duplicate(crv1)[0] self.offsetCrv(crv1, -1.0 * self.rbnWidth / 2) self.offsetCrv(crv2, 1.0 * self.rbnWidth / 2) tmpLoftSrf = \ pm.loft(crv1, crv2, ch=0, u=1, c=0, ar=1, d=1, ss=1, rn=0, po=0, rsn=1, n=self.rbnName + "_lft_srf")[0] rebuiltLoftSrf = \ pm.rebuildSurface(ch=0, rpo=0, rt=0, end=1, kr=1, kcp=0, kc=0, su=0, du=3, sv=0, dv=1, fr=0, dir=2, n=self.rbnName + "_srf")[0] rebuiltLoftSrf.setPivots(rebuiltLoftSrf.c.get()) self.rbnSrf = rebuiltLoftSrf pm.delete(self.rbnSrf, ch=1) pm.delete([crv1, crv2, tmpLoftSrf]) pm.parent(self.rbnSrf, self.rbnTransformGrp)
def createSrf(self): #calculate the witdth of the surface as a fraction of the total joint chain length jntChainLength = 0 crvPoints = [] for i in range(1,self.numJnt): pos1 = self.ikJntList[i-1].getTranslation(space='world') crvPoints.append(pos1) pos2 = self.ikJntList[i].getTranslation(space='world') jntChainLength += (pos2 - pos1).length() if i == self.numJnt - 1: crvPoints.append(pos2) jntChainLength = math.ceil(jntChainLength ) self.width = jntChainLength * self.widthMult crv1 = pm.curve(n=self.name + '_crv1',d=1,p=crvPoints) pm.move(crv1,self.width / 2.0,0,0,r=1) pm.parent(crv1,self.mainGrp) crv2 = pm.curve(n=self.name + '_crv2',d=1,p=crvPoints) pm.move(crv2,self.width / -2.0,0,0,r=1) pm.parent(crv2,self.mainGrp) pm.select(cl=1) loftSrf = pm.loft(crv2,crv1,ch=1,u=1,c= 0,ar= 1,d=3,ss= 1,rn=0,po=0,rsn=1,n=self.name + "_srf")[0] rebuiltLoftSrf = pm.rebuildSurface(loftSrf,ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=self.numCtrl-1, du=3, sv=0, dv=3, tol=0, fr=0, dir=2 )[0] self.srf = loftSrf pm.parent(self.srf,self.mainGrp)
def createSrf(self): # calculate the witdth of the surface as a fraction of the total joint chain length jntChainLength = 0 crvPoints = [] for i in range(1, self.numJnt): pos1 = self.ikJntList[i - 1].getTranslation(space='world') crvPoints.append(pos1) pos2 = self.ikJntList[i].getTranslation(space='world') jntChainLength += (pos2 - pos1).length() if i == self.numJnt - 1: crvPoints.append(pos2) jntChainLength = math.ceil(jntChainLength) self.width = jntChainLength * self.widthMult crv1 = pm.curve(n=self.name + '_crv1', d=1, p=crvPoints) pm.move(crv1, self.width / 2.0, 0, 0, r=1) pm.parent(crv1, self.mainGrp) crv2 = pm.curve(n=self.name + '_crv2', d=1, p=crvPoints) pm.move(crv2, self.width / -2.0, 0, 0, r=1) pm.parent(crv2, self.mainGrp) pm.select(cl=1) loftSrf = pm.loft(crv2, crv1, ch=1, u=1, c=0, ar=1, d=3, ss=1, rn=0, po=0, rsn=1, n=self.name + "_srf")[0] rebuiltLoftSrf = \ pm.rebuildSurface(loftSrf, ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=self.numCtrl - 1, du=3, sv=0, dv=3, tol=0, fr=0, dir=2)[0] self.srf = loftSrf pm.parent(self.srf, self.mainGrp)
def bdBuildSrf(self,name): selected = pm.ls(sl=1) if selected: if len(selected) == 1: if selected[0].type() == 'joint': print 'start srf' self.startJnt = selected[0] children = self.startJnt.getChildren(type='joint') print children #need to implement a case with more joint chidren #build the one degree curves for lofting self.endJnt = children[0] startPos1,endPos1 = self.bdGetPos(-0.05) startPos2,endPos2 = self.bdGetPos( 0.05) pm.spaceLocator(p=startPos1) pm.spaceLocator(p=startPos2) pm.spaceLocator(p=endPos1) pm.spaceLocator(p=endPos2) dif1 = (endPos1 - startPos1) dif2 = (endPos2 - startPos2) crv1Points = [] crv2Points = [] for i in range(self.segmentsRbn): pos = dif1 * (i/(self.segmentsRbn*1.0)) + startPos1 crv1Points.append(pos ) pos = dif2 * (i/(self.segmentsRbn*1.0)) + startPos2 crv2Points.append(pos) crv1Points.append(endPos1) crv2Points.append(endPos2) print 'building curve' tmp = pm.curve(n=name + '_crv1',d=1,p=crv1Points) crv1 = pm.ls(tmp)[0] print crv1 #crv1.setScalePivot(startPos1) #crv1.setRotatePivot(startPos1) crv2 = pm.curve(n=name + '_crv2',d=1,p=crv2Points) #crv2.setScalePivot(startPos2) #crv2.setRotatePivot(startPos2) drvGrp = self.bdCreateDrvJnt(crv1,crv2) #loft the curves loftSrf = pm.loft(crv1,crv2,ch=1,u=1,c= 0,ar= 1,d=1,ss= 1,rn=0,po=0,rsn=1,n=name + "_lft_srf")[0] #loftSrf.setScalePivot(startPos2) #loftSrf.setRotatePivot(startPos2) rebuiltLoftSrf = pm.rebuildSurface(ch=1, rpo = 0, rt = 0, end = 1, kr=1, kcp=0,kc=0, su=0, du=3, sv=0, dv=1, fr=0, dir=2 , n=name + "_srf")[0] self.rbnSrf = rebuiltLoftSrf crvGrp = pm.group([crv1,crv2],name=name+'_crv_grp') crvGrp.centerPivots() srfGrp = pm.group([loftSrf,rebuiltLoftSrf],name=name+'_srf_grp') srfGrp.centerPivots() self.rbnGrp = pm.group([crvGrp,srfGrp],n=name+"_grp") pm.parent(drvGrp,self.rbnGrp)
def _create_ribbon(self): """Create the ribbon spine based on the guides.""" ribboncrv = pm.curve(p=[ctl.position() for ctl in self.guides.spine], n='%s_%sRibbon_CRV' % (self.side, self.name), d=3) ribboncrv.listRelatives(ad=True)[0].rename('%sShape' % ribboncrv) crva = pm.curve(d=1, p=[ctl.position() for ctl in self.guides.spine]) crvb = crva.duplicate()[0] crva.tx.set(-1) crvb.tx.set(1) nrbname = '%s_%sRibbon_NRB' % (self.side, self.name) loft = pm.loft(crva, crvb, n=nrbname, ch=False)[0] self.ribbon = pm.rebuildSurface(loft, su=0, sv=0, ch=False) pm.delete(crva, crvb)
def build_nurbs_between_points(xformA, xformB, ref_xform, spansUV=[1,4]): """ Build a simple nurbs surface between two points with a surface up third object Args: xformA (pm.nt.Transform): first point xformB (pm.nt.Transform): second point ref_xform (pm.nt.Transform): aim object Usage: Mesh.build_nurbs_between_points(pm.PyNode('locator1'),pm.PyNode('locator2'),pm.PyNode('locator3')) """ nurbs = pm.nurbsPlane(p=[0,0,0], ax=[0,1,0], w=1, lr=1, d=1, u=1, v=1, ch=0)[0] nurbs.scalePivot.set(0,0,0.5) nurbs.rotatePivot.set(0,0,0.5) pm.delete(pm.pointConstraint(xformA, nurbs, mo=False)) pm.delete(pm.aimConstraint(xformB, nurbs, worldUpType=1, aimVector=[0,0,-1], worldUpVector=[0,1,0], worldUpObject=ref_xform, mo=False)) cluster = pm.cluster(nurbs.getShape().cv[0:1][1]) pm.delete(pm.pointConstraint(xformB, cluster, mo=False)) pm.delete(nurbs, ch=True) u, v = spansUV pm.rebuildSurface(nurbs.getShape(), ch=False, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=u, du=3, sv=v, dv=3, tol=0, fr=0, dir=2) return nurbs
def createCtrls(self): ctrlList = [] # rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kc 0 -su 4 -du 3 -sv 1 -dv 3 -tol 0 -fr 0 -dir 2 "Tail_srf"; self.rbnSrf = \ pm.rebuildSurface(self.rbnSrf.name(), ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=(self.numCtrl - 1), du=3, sv=1, dv=3, tol=0, fr=0, dir=2)[0] pociNode = pm.shadingNode('pointOnCurveInfo', asUtility=1) pociNode.turnOnPercentage.set(1) pm.ls(self.ikCrv)[0].getShape().worldSpace[0] >> pociNode.inputCurve tempLoc = pm.spaceLocator() pociNode.position >> tempLoc.translate segmentLength = 1.0 / (self.numCtrl - 1) for i in range(self.numCtrl): pociNode.parameter.set(i * segmentLength) pos = tempLoc.getTranslation(space='world') ctrl = self.addCtrl(i) self.ctrlList.append(ctrl) ctrlMainGrp = self.getCtrlMainGrp(ctrl) ctrlMainGrp.setTranslation(pos) pm.parent(ctrlMainGrp, self.allCtrlGrp) pm.addAttr(ctrl, longName='extras', nn='------', attributeType='enum', en='Extras:', keyable=True) pm.setAttr(ctrl.name() + '.extras', lock=1) pm.addAttr(ctrl, longName='scaleRadius', attributeType='float', keyable=True, min=0.0001, defaultValue=0.3) pm.parent(self.allCtrlGrp, self.mainGrp)
def curve_base(self, *path, **kwargs): swap_uv = kwargs.pop('swap_uv', True) delete_history = kwargs.pop('delete_history', False) self.path = path[0] self._create_profile(**kwargs) print self.profile original_surf = pm.extrude(self.profile, self.path, fixedPath=True, useComponentPivot=1, useProfileNormal=True) if swap_uv: swap_uv_curve = pm.rebuildSurface(original_surf[0], keepControlPoints=True, rebuildType=0, keepRange=0) new_surface = pm.reverseSurface(swap_uv_curve[0], direction=3) self.skin_surface = new_surface[0] else: self.skin_surface = original_surf self.name_convention.rename_name_in_format(self.skin_surface, name='extrude') if delete_history: self.delete_history() return self.skin_surface
def createRbnSrf(self): startJntVec = om.MVector(self.start[0], self.start[1], self.start[2]) endJntVec = om.MVector(self.end[0], self.end[1], self.end[2]) diffVec = endJntVec - startJntVec # calculate the witdth of the surface as a fraction of the total joint chain length jntChainLength = diffVec.length() self.width = jntChainLength * self.widthMult crv1 = pm.duplicate(pm.ls(self.buildCrv)[0])[0] crv1.setPivots(self.start) crv2 = pm.duplicate(crv1)[0] self.offsetCrv(crv1, -0.3 * self.width) self.offsetCrv(crv2, 0.3 * self.width) loftSrf = pm.loft(crv1, crv2, ch=0, u=1, c=0, ar=1, d=1, ss=1, rn=0, po=0, rsn=1)[0] loftSrf = \ pm.rebuildSurface(ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=0, du=1, sv=0, dv=1, tol=0, fr=0, dir=2, n=self.name + "_srf")[0] pm.rename(loftSrf, self.name + "_srf") loftSrf.setPivots(loftSrf.c.get()) self.rbnSrf = loftSrf pm.delete(self.rbnSrf, ch=1) pm.delete([crv1, crv2]) pm.parent(self.rbnSrf, self.mainGrp)
def construction(self): self.folList = [] #create burbs plane ribbonGeo = pm.nurbsPlane(p = (0,0,0),ax = (0,1,0),w = self.Width,lr = self.Length, d = 3,u = self.UVal,v = self.segment,ch = 1,n = (self.side + '_' + self.RibbonName + '_Rbbn01_geo_01_')) #rebuild ribbon geo if self.VVal > self.UVal: pm.rebuildSurface(ribbonGeo[0],ch = 1,rpo = 1,rt = 0,end = 1,kr = 0,kcp = 0,kc = 0,su = self.UVal,du = 1,sv = self.VVal,dv = 3,tol = 0.000155,fr = 0,dir = 2) if self.UVal > self.VVal: pm.rebuildSurface(ribbonGeo[0],ch = 1,rpo = 1,rt = 0,end = 1,kr = 0,kcp = 0,kc = 0,su = self.UVal,du = 3,sv = self.VVal,dv = 1,tol = 0.000155,fr = 0,dir = 2) #clear history of ribbonGeometry pm.select(ribbonGeo[0],r = 1) pm.delete(ch = 1) #CREATE THE HAIR FOLLICLES self.folGrp = pm.group(em = 1,n = getUniqueName(self.side,self.RibbonName + 'Fol','grp')) for fol in range(self.segment): #createNodeName follicleTransName = getUniqueName(self.side,self.RibbonName,'fol') follicleShapeName = getUniqueName(self.side,self.RibbonName,'folShape') #createNode follicleShape = pm.createNode('follicle',n = follicleShapeName) follicleTrans = pm.listRelatives(follicleShape, parent=True)[0] follicleTrans = pm.rename(follicleTrans, follicleTransName) # connect the surface to the follicle if ribbonGeo[0].getShape().nodeType() == 'nurbsSurface': pm.connectAttr((ribbonGeo[0] + '.local'), (follicleShape + '.inputSurface')) #Connect the worldMatrix of the surface into the follicleShape pm.connectAttr((ribbonGeo[0] + '.worldMatrix[0]'), (follicleShape + '.inputWorldMatrix')) #Connect the follicleShape to it's transform pm.connectAttr((follicleShape + '.outRotate'), (follicleTrans + '.rotate')) pm.connectAttr((follicleShape + '.outTranslate'), (follicleTrans + '.translate')) #Set the uValue and vValue for the current follicle pm.setAttr((follicleShape + '.parameterU'), 0.5) pm.setAttr((follicleShape + '.parameterV'), float(1.0 / self.segment) * fol + (1.0 / (self.segment * 2))) #Lock the translate/rotate of the follicle pm.setAttr((follicleTrans + '.translate'), lock=True) pm.setAttr((follicleTrans + '.rotate'), lock=True) #parent self.folList.append(follicleTrans) follicleTrans.setParent(self.folGrp) #CREATE JOINTS SNAPPED AND PARENTED TO THE FOLLICLE--- for num,fol in enumerate(self.folList): jJoint = pm.joint(n = self.side + '_' + self.RibbonName + '_Rbbn0' + str(num) + '_jj',p = (0,0,0),rad = min(self.Width,self.Length) * .25) pm.parent(jJoint,fol) jJoint.translate.set(0,0,0) self.jj.append(jJoint) #CREATE SOME TEMPORARY CLUSTERS TO PLACE THE POS LOCATORS--- if self.UVal > self.VVal: vNo = self.UVal + 2 pm.select(self.side + '_' + self.RibbonName + '_Rbbn01_geo_01_.cv[' + str(vNo) + '][0:1]',r = 1) startCls = pm.cluster(n = 'spCltr') pm.select(self.side + '_' + self.RibbonName + '_Rbbn01_geo_01_.cv[0][0:1]',r = 1) endCls = pm.cluster(n = 'epCltr') if self.VVal > self.UVal: vNo = self.VVal + 2 pm.select(self.side + '_' + self.RibbonName + '_Rbbn01_geo_01_.cv[0:1][' + str(vNo) + ']',r = 1) startCls = pm.cluster(n = 'spCltr') pm.select(self.side + '_' + self.RibbonName + '_Rbbn01_geo_01_.cv[0:1][0]',r = 1) endCls = pm.cluster(n = 'epCltr') #CREATE SOME LOCATORS--- #CREATE START POINT LOCATORS AND PARENT THEM PROPERLY--- spLocPos = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnSp01_pos') spLocAim = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnSp01_aim') self.startUploc = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnSp01_up') #hide shape # spLocPos.getShape().v.set(0) # spLocAim.getShape().v.set(0) # spLocUp.getShape().v.set(0) self.startLoc = spLocPos pm.parent(spLocAim,spLocPos) pm.parent(self.startUploc,spLocPos) #CREATE MID POINT LOCATORS AND PARENT THEM PROPERLY--- mpLocPos = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnMp01_pos') self.mpLocAim = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnMp01_aim') mpLocUp = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnMp01_up') #hide shape # mpLocPos.getShape().v.set(0) # self.mpLocAim.getShape().v.set(0) # mpLocUp.getShape().v.set(0) self.midloc = mpLocPos pm.parent(self.mpLocAim,mpLocPos) pm.parent(mpLocUp,mpLocPos) #CREATE END POINT LOCATORS AND PARENT THEM PROPERLY--- epLocPos = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnEp01_pos') epLocAim = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnEp01_aim') self.epUploc = pm.spaceLocator(p = (0,0,0), n = self.side + '_' + self.RibbonName + '_RbbnEp01_up') #hide shape # epLocPos.getShape().v.set(0) # epLocAim.getShape().v.set(0) # self.epUploc.getShape().v.set(0) self.endLoc = epLocPos pm.parent(epLocAim,epLocPos) pm.parent(self.epUploc,epLocPos) #CONSTRAINT EACH LOCATORS PROPERLY--- pm.pointConstraint('spCltrHandle',spLocPos,o = (0,0,0),w = 1) pm.delete(self.side + '_' + self.RibbonName + '_RbbnSp01_pos_pointConstraint1') pm.pointConstraint('epCltrHandle',epLocPos,o = (0,0,0),w = 1) pm.delete(self.side + '_' + self.RibbonName + '_RbbnEp01_pos_pointConstraint1') pm.pointConstraint(spLocPos,epLocPos,mpLocPos,o = (0,0,0),w = 1) pm.pointConstraint(self.startUploc,self.epUploc,mpLocUp,o = (0,0,0),w = 1) #OFFSET THE POSITION OF THE UP LOCATOR--- pm.setAttr(self.startUploc.ty,min(self.Width,self.Length) * .5) pm.setAttr(self.epUploc.ty,min(self.Width,self.Length) * .5) #CREATE CTRL JOINTS pm.select(cl = 1) tx = tz = 0.0 if self.VVal > self.UVal: tz = self.Length * .2 if self.UVal > self.VVal: tx = self.Width * .2 ############# #transmit Jc joint info--- #FOR START POINT JOINT--- self.startJc = pm.joint(p = (0,0,0),rad = min(self.Width,self.Length) * .5,n = self.side + '_' + self.RibbonName + '_RbbnSp01_jc') pm.joint(p = (tx * .6,0,tz * .6),rad = min(self.Width,self.Length) * .5,n = self.side + '_' + self.RibbonName + '_RbbnSp02_jc') pm.joint(e = 1,zso = 1,oj = 'xyz',sao = 'yup',n = self.side + '_' + self.RibbonName + '_RbbnSp02_jc') #FOR MIDDLE POINT JOINT--- pm.select(cl = 1) self.midJc = pm.joint(p = (0,0,0),rad = min(self.Width,self.Length) * .5,n = self.side + '_' + self.RibbonName + '_RbbnMp01_jc') pm.joint(e = 1,zso = 1,oj = 'xyz',sao = 'yup',n = self.side + '_' + self.RibbonName + '_RbbnMp01_jc') #FOR END POINT JOINT--- pm.select(cl = 1) self.endJc = pm.joint(p = (0,0,0),rad = min(self.Width,self.Length) * .5,n = self.side + '_' + self.RibbonName + '_RbbnEp01_jc') pm.joint(p = (tx * -0.6,0,tz * -0.6),rad = min(self.Width,self.Length) * .5,n = self.side + '_' + self.RibbonName + '_RbbnEp02_jc') pm.joint(e = 1,zso = 1,oj = 'xyz',sao = 'yup',n = self.side + '_' + self.RibbonName + '_RbbnEp02_jc') #PARENT THE CONTROL JOINTS APPROPRIATLY--- pm.parent(self.side + '_' + self.RibbonName + "_RbbnSp01_jc",spLocAim,r = 1) pm.parent(self.side + '_' + self.RibbonName + "_RbbnMp01_jc",self.mpLocAim,r = 1) pm.parent(self.side + '_' + self.RibbonName + "_RbbnEp01_jc",epLocAim,r = 1) #APPLY THE AIM CONSTRINTS--- aTz = 0 if self.VVal > self.UVal: aTz = 1 aTx = 0 if self.UVal > self.VVal: aTx = 1 #FOR MIDDLE POINT--- pm.aimConstraint(self.side + '_' + self.RibbonName + "_RbbnSp01_pos",self.side + '_' + self.RibbonName + "_RbbnMp01_aim",o = (0,0,0),w = 1,aim = (aTx * -1,0,aTz * -1),u = (0,1,0),wut = 'object',wuo = self.side + '_' + self.RibbonName + '_RbbnMp01_up') #FOR START POINT--- pm.aimConstraint(self.side + '_' + self.RibbonName + "_RbbnMp01_jc",self.side + '_' + self.RibbonName + "_RbbnSp01_aim",o = (0,0,0),w = 1,aim = (aTx,0,aTz),u = (0,1,0),wut = 'object',wuo = self.side + '_' + self.RibbonName + '_RbbnSp01_up') #FOR END POINT--- pm.aimConstraint(self.side + '_' + self.RibbonName + "_RbbnMp01_jc",self.side + '_' + self.RibbonName + "_RbbnEp01_aim",o = (0,0,0),w = 1,aim = (aTx * -1,0,aTz * -1),u = (0,1,0),wut = 'object',wuo = self.side + '_' + self.RibbonName + '_RbbnEp01_up') #APPLY SKINCLUSTER--- pm.select(cl = 1) pm.skinCluster(self.side + '_' + self.RibbonName + "_RbbnSp01_jc",self.side + '_' + self.RibbonName + "_RbbnMp01_jc",self.side + '_' + self.RibbonName + "_RbbnEp01_jc",self.side + '_' + self.RibbonName + "_Rbbn01_geo_01_",tsb = 1,ih = 1,mi = 3,dr = 4,rui = 1) #CLEAN UP pm.delete(startCls) pm.delete(endCls) pm.rename(self.side + '_' + self.RibbonName + '_Rbbn01_geo_01_',self.side + '_' + self.RibbonName + '_Rbbn01_geo_01') #GROUP THEM ALL self.main = pm.group(self.folGrp,self.side + '_' + self.RibbonName + '_Rbbn01_geo_01',self.side + '_' + self.RibbonName + '_RbbnSp01_pos',self.side + '_' + self.RibbonName + '_RbbnMp01_pos',self.side + '_' + self.RibbonName + '_RbbnEp01_pos',n = self.side + '_' + self.RibbonName + "_Rbbn01_grp") pm.xform(os = 1,piv = (0,0,0)) if self.subMid == 1: self.__midCC()
def doRig(self): p1 = pm.xform(self.guide1, q=1, t=1) p2 = pm.xform(self.guide2, q=1, t=1) p3 = pm.xform(self.guide3, q=1, t=1) A = om.MVector(p1) B = om.MVector(p2) C = om.MVector(p3) AC = A - C nurbsLength = AC.length() # setup do nurbs plane e follicles nurbs = pm.nurbsPlane(w=nurbsLength / self.sections, lr=self.sections, v=self.sections)[0] nurbsShp = nurbs.getShape() pm.rebuildSurface(nurbs, ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, su=1, du=1, dv=3, tol=0.01, fr=0, dir=0) pm.xform(nurbs, t=p1, ws=True) guide2Up = pm.duplicate(self.guide2, n=self.guide2 + '_up')[0] pm.delete(pm.pointConstraint(self.guide1, self.guide3, guide2Up)) pm.xform(guide2Up, r=True, t=(self.direction[0], self.direction[1], self.direction[2])) pm.delete( pm.aimConstraint(self.guide3, nurbs, w=1, o=(0, 0, 0), aim=(0, 1, 0), u=(-1, 0, 0), wut='object', wuo=guide2Up)) pm.delete(guide2Up) pm.delete(pm.pointConstraint(self.guide1, self.guide3, nurbs)) grpFol = pm.group(em=1, n=self.name + 'Foll_grp') grpScale = pm.group(em=1, n=self.name + 'Scale_grp') vValue = 0 vSections = 1.0 / self.sections vOffset = vSections / 2 id = 0 # medindo o comprimento do nurbs para o squash stretch arcLengthShp = pm.createNode('arcLengthDimension') arcLength = arcLengthShp.getParent() nurbsShp.worldSpace[0] >> arcLengthShp.nurbsGeometry arcLengthShp.vParamValue.set(1) arcLengthShp.uParamValue.set(0) arcLenValue = arcLengthShp.arcLengthInV.get() autoManualList = [] factorList = [] on_offList = [] skinJntsList = [] for follicle in range(self.sections): id += 1 # criando nodes para o stretch squash normalizeTo0 = pm.createNode('plusMinusAverage', n=self.name + 'RbbnNormalize0' + ` id ` + '_pma') scaleAux = pm.createNode('multiplyDivide', n=self.name + 'RbbnScaleAux0' + ` id ` + '_md') factor = pm.createNode('multiplyDivide', n=self.name + 'RbbnFactor0' + ` id ` + '_md') on_off = pm.createNode('multiplyDivide', n=self.name + 'RbbnOnOff0' + ` id ` + '_md') autoManual = pm.createNode('plusMinusAverage', n=self.name + 'RbbnAutoManual0' + ` id ` + '_pma') autoReverse = pm.createNode('reverse', n=self.name + 'RbbnReverse0' + ` id ` + '_rev') # ajustando valores dos nodes de stretch squash normalizeTo0.operation.set(2) scaleAux.input2.set((arcLenValue, arcLenValue, arcLenValue)) # conectando os nodes de stretch squash arcLength.arcLengthInV >> normalizeTo0.input3D[0].input3Dx arcLength.arcLengthInV >> normalizeTo0.input3D[0].input3Dy arcLength.arcLengthInV >> normalizeTo0.input3D[0].input3Dz scaleAux.output >> normalizeTo0.input3D[1] grpScale.scale >> scaleAux.input1 normalizeTo0.output3D >> factor.input2 factor.output >> on_off.input1 on_off.output >> autoReverse.input autoReverse.output >> autoManual.input3D[0] # criando nodes do rbbn folShp = pm.createNode('follicle') fol = folShp.getParent() # escondendo os follicles if self.visibility == 0: folShp.visibility.set(0) jnt = pm.joint(radius=nurbsLength * 0.2) skinJntsList.append(jnt) # conectando e ajustando nodes do rbbn autoManual.output3Dx >> jnt.scaleX autoManual.output3Dz >> jnt.scaleZ nurbsShp.local >> folShp.inputSurface nurbsShp.worldMatrix[0] >> folShp.inputWorldMatrix folShp.outRotate >> fol.rotate folShp.outTranslate >> fol.translate folShp.parameterU.set(0.5) vValue += vSections folShp.parameterV.set(vValue - vOffset) pm.parent(fol, grpFol) pm.scaleConstraint(grpScale, fol, mo=1) # listas para loops posteriores on_offList.append(on_off) factorList.append(factor) autoManualList.append(autoManual) # fk setup FKSIZE = (nurbsLength / 2) / self.sections topPosLoc = pm.spaceLocator() topAimLoc = pm.spaceLocator() topAimLoc.setParent(topPosLoc) topToSkin = pm.joint( radius=nurbsLength * 0.2, p=(0, 0, 0), ) pm.joint( radius=nurbsLength * 0.15, p=(0, -FKSIZE, 0), ) topUpLoc = pm.spaceLocator() topUpLoc.setParent(topPosLoc) pm.move(FKSIZE * 3 * self.upVector[0], FKSIZE * 3 * self.upVector[1], FKSIZE * 3 * self.upVector[2], topUpLoc) pm.delete(pm.pointConstraint(self.guide3, topPosLoc)) # pm.delete(pm.parentConstraint(guide3,topPosLoc)) midPosLoc = pm.spaceLocator() midAimLoc = pm.spaceLocator() midAimLoc.setParent(midPosLoc) midOffLoc = pm.spaceLocator() midOffLoc.setParent(midAimLoc) midToSkin = pm.joint(radius=nurbsLength * 0.2, p=(0, 0, 0)) midUpLoc = pm.spaceLocator() midUpLoc.setParent(midPosLoc) pm.move(FKSIZE * 3 * self.upVector[0], FKSIZE * 3 * self.upVector[1], FKSIZE * 3 * self.upVector[2], midUpLoc) lwrPosLoc = pm.spaceLocator() lwrAimLoc = pm.spaceLocator() lwrAimLoc.setParent(lwrPosLoc) lwrToSkin = pm.joint(radius=nurbsLength * 0.2, p=(0, 0, 0)) pm.joint(radius=nurbsLength * 0.15, p=(0, FKSIZE, 0)) lwrUpLoc = pm.spaceLocator() lwrUpLoc.setParent(lwrPosLoc) pm.move(FKSIZE * 3 * self.upVector[0], FKSIZE * 3 * self.upVector[1], FKSIZE * 3 * self.upVector[2], lwrUpLoc) pm.delete(pm.pointConstraint(self.guide1, lwrPosLoc)) topPosLocShp = topPosLoc.getShape() midPosLocShp = midPosLoc.getShape() lwrPosLocShp = lwrPosLoc.getShape() topAimLocShp = topAimLoc.getShape() midAimLocShp = midAimLoc.getShape() lwrAimLocShp = lwrAimLoc.getShape() topUpLocShp = topUpLoc.getShape() midUpLocShp = midUpLoc.getShape() lwrUpLocShp = lwrUpLoc.getShape() midOffLocShp = midOffLoc.getShape() topPosLocShp.localScale.set( (nurbsLength * 0.2, nurbsLength * 0.2, nurbsLength * 0.2)) topAimLocShp.localScale.set( (nurbsLength * 0.2, nurbsLength * 0.2, nurbsLength * 0.2)) topUpLocShp.localScale.set( (nurbsLength * 0.05, nurbsLength * 0.05, nurbsLength * 0.05)) midPosLocShp.localScale.set( (nurbsLength * 0.2, nurbsLength * 0.2, nurbsLength * 0.2)) midAimLocShp.localScale.set( (nurbsLength * 0.2, nurbsLength * 0.2, nurbsLength * 0.2)) midUpLocShp.localScale.set( (nurbsLength * 0.05, nurbsLength * 0.05, nurbsLength * 0.05)) midOffLocShp.localScale.set( (nurbsLength * 0.2, nurbsLength * 0.2, nurbsLength * 0.2)) lwrPosLocShp.localScale.set( (nurbsLength * 0.2, nurbsLength * 0.2, nurbsLength * 0.2)) lwrAimLocShp.localScale.set( (nurbsLength * 0.2, nurbsLength * 0.2, nurbsLength * 0.2)) lwrUpLocShp.localScale.set( (nurbsLength * 0.05, nurbsLength * 0.05, nurbsLength * 0.05)) pm.parent(topPosLoc, midPosLoc, lwrPosLoc, grpScale) # criando constraints para os locators do rbbn pm.aimConstraint(midToSkin, topAimLoc, aim=(0, -1, 0), u=(1, 0, 0), wut='object', wuo=topUpLoc) pm.aimConstraint(midToSkin, lwrAimLoc, aim=(0, 1, 0), u=(1, 0, 0), wut='object', wuo=lwrUpLoc) pm.aimConstraint(topPosLoc, midAimLoc, aim=(0, 1, 0), u=(1, 0, 0), wut='object', wuo=midUpLoc) pm.pointConstraint(topPosLoc, lwrPosLoc, midPosLoc) pm.pointConstraint(topUpLoc, lwrUpLoc, midUpLoc) # skin setup skin = pm.skinCluster(topToSkin, midToSkin, lwrToSkin, nurbs, tsb=1) if self.sections == 3: pm.skinPercent(skin, nurbs + '.cv[0:1][5]', tv=(topToSkin, 1)) pm.skinPercent(skin, nurbs + '.cv[0:1][4]', tv=[(topToSkin, 0.6), (midToSkin, 0.4)]) pm.skinPercent(skin, nurbs + '.cv[0:1][3]', tv=[(topToSkin, 0.2), (midToSkin, 0.8)]) pm.skinPercent(skin, nurbs + '.cv[0:1][2]', tv=[(topToSkin, 0.2), (midToSkin, 0.8)]) pm.skinPercent(skin, nurbs + '.cv[0:1][1]', tv=[(topToSkin, 0.6), (midToSkin, 0.4)]) pm.skinPercent(skin, nurbs + '.cv[0:1][0]', tv=(topToSkin, 1)) elif self.sections == 5: pm.skinPercent(skin, nurbs + '.cv[0:1][7]', tv=(topToSkin, 1)) pm.skinPercent(skin, nurbs + '.cv[0:1][6]', tv=[(topToSkin, 0.80), (midToSkin, 0.2)]) pm.skinPercent(skin, nurbs + '.cv[0:1][5]', tv=[(topToSkin, 0.5), (midToSkin, 0.5)]) pm.skinPercent(skin, nurbs + '.cv[0:1][4]', tv=[(topToSkin, 0.25), (midToSkin, 0.75)]) pm.skinPercent(skin, nurbs + '.cv[0:1][3]', tv=[(lwrToSkin, 0.25), (midToSkin, 0.75)]) pm.skinPercent(skin, nurbs + '.cv[0:1][2]', tv=[(lwrToSkin, 0.5), (midToSkin, 0.5)]) pm.skinPercent(skin, nurbs + '.cv[0:1][1]', tv=[(lwrToSkin, 0.8), (midToSkin, 0.2)]) pm.skinPercent(skin, nurbs + '.cv[0:1][0]', tv=(lwrToSkin, 1)) elif self.sections == 7: pm.skinPercent(skin, nurbs + '.cv[0:1][9]', tv=(topToSkin, 1)) pm.skinPercent(skin, nurbs + '.cv[0:1][8]', tv=[(topToSkin, 0.85), (midToSkin, 0.15)]) pm.skinPercent(skin, nurbs + '.cv[0:1][7]', tv=[(topToSkin, 0.6), (midToSkin, 0.4)]) pm.skinPercent(skin, nurbs + '.cv[0:1][6]', tv=[(topToSkin, 0.35), (midToSkin, 0.65)]) pm.skinPercent(skin, nurbs + '.cv[0:1][5]', tv=[(topToSkin, 0.25), (midToSkin, 0.75)]) pm.skinPercent(skin, nurbs + '.cv[0:1][4]', tv=[(lwrToSkin, 0.25), (midToSkin, 0.75)]) pm.skinPercent(skin, nurbs + '.cv[0:1][3]', tv=[(lwrToSkin, 0.35), (midToSkin, 0.65)]) pm.skinPercent(skin, nurbs + '.cv[0:1][2]', tv=[(lwrToSkin, 0.6), (midToSkin, 0.4)]) pm.skinPercent(skin, nurbs + '.cv[0:1][1]', tv=[(lwrToSkin, 0.85), (midToSkin, 0.15)]) pm.skinPercent(skin, nurbs + '.cv[0:1][0]', tv=(lwrToSkin, 1)) else: print "!!!There's skinning support for 3,5 and 7 sections only!!!" # posicionando o controle do meio pm.delete(pm.pointConstraint(self.guide2, midOffLoc)) # criando controles if self.createCtrls == 0: topCircle = pm.circle(r=nurbsLength * .2, nr=(self.ctrlNormal[0], self.ctrlNormal[1], self.ctrlNormal[2])) topCtrlGrp = pm.group() topCtrlGrp.setParent(grpScale) pm.delete(pm.parentConstraint(self.guide3, topCtrlGrp, mo=0)) pm.parentConstraint(topCircle[0], topPosLoc) midCircle = pm.circle(r=nurbsLength * .2, nr=(self.ctrlNormal[0], self.ctrlNormal[1], self.ctrlNormal[2])) midCtrlGrp = pm.group() midCtrlGrp.setParent(midOffLoc) pm.delete(pm.parentConstraint(midToSkin, midCtrlGrp)) midJointZerado = self.zeroOut(midToSkin, returnGrpName=1)[0] pm.parent(midJointZerado, grpScale) pm.parentConstraint(midCircle[0], midJointZerado, mo=1) lwrCircle = pm.circle(r=nurbsLength * .2, nr=(self.ctrlNormal[0], self.ctrlNormal[1], self.ctrlNormal[2])) lwrCtrlGrp = pm.parent(pm.group(), grpScale) pm.delete(pm.parentConstraint(self.guide1, lwrCtrlGrp, mo=0)) pm.parentConstraint(lwrCircle[0], lwrPosLoc) else: midCircle = pm.circle(r=nurbsLength * .2, nr=(self.ctrlNormal[0], self.ctrlNormal[1], self.ctrlNormal[2])) midCtrlGrp = pm.parent(pm.group(), midOffLoc) pm.delete(pm.parentConstraint(midToSkin, midCtrlGrp)) midJointZerado = self.zeroOut(midToSkin, returnGrpName=1)[0] pm.parent(midJointZerado, grpScale) pm.parentConstraint(midCircle[0], midJointZerado, mo=1) id = 0 midCircle[0].addAttr('autoSS', k=1, dv=0.0, at='double', min=0, max=1) midCircleShp = midCircle[0].getShape() if self.createCtrls: midCircleShp.v.set(0) for autoManualAuxNodes in autoManualList: id += 1 # criando e ajustando nodes para stretch squash manualNormalize = pm.createNode( 'plusMinusAverage', n=self.name + 'RbbnManualNormalize0' + str(id) + '_pma') manualFactor = pm.createNode('multiplyDivide', n=self.name + 'RbbnManualFactor0' + str(id) + '_md') ratioScale = pm.createNode('multiplyDivide', n=self.name + 'RbbnRatioScale0' + str(id) + 'md') zRatio = pm.createNode('multiplyDivide', n=self.name + 'RbbnSsManualZratio' + str(id) + '_md') manualFactor.output >> autoManualAuxNodes.input3D[1] midCircle[0].scale >> manualNormalize.input3D[0] manualNormalize.output3D >> manualFactor.input2 manualNormalize.operation.set(2) manualNormalize.input3D[1].input3D.set((1, 1, 1)) ratioScale.operation.set(2) # adicionando atributos de squash midCircleShp.addAttr('manualFactorX0' + str(id), k=1, at='float', dv=1) midCircleShp.addAttr('manualRatioZ0' + str(id), k=1, at='float') midCircleShp.addAttr('autoFactorX0' + str(id), k=1, at='float') midCircleShp.addAttr('autoRatioZ0' + str(id), k=1, at='float') # conectando os atributos acima midCircleShp.attr('manualRatioZ0' + str(id)) >> zRatio.input1Z midCircleShp.attr('autoRatioZ0' + str(id)) >> zRatio.input1X midCircle[0].autoSS >> on_offList[id - 1].input2X # on_off midCircle[0].autoSS >> on_offList[id - 1].input2Z # on_off midCircleShp.attr('manualFactorX0' + str(id)) >> manualFactor.input1X midCircleShp.attr('manualFactorX0' + str(id)) >> zRatio.input2Z ratioScale.outputX >> zRatio.input2X zRatio.outputZ >> manualFactor.input1Z ratioScale.outputX >> factorList[id - 1].input1X # factor zRatio.outputX >> factorList[id - 1].input1Z # factor grpScale.scale >> ratioScale.input2 midCircleShp.attr('autoFactorX0' + str(id)) >> ratioScale.input1X # ajustando os atributos midCircleShp.attr('manualRatioZ0' + str(id)).set(1) midCircleShp.attr('autoRatioZ0' + str(id)).set(1) # ajustando valores iniciais para os factores de squash if self.sections == 3: midCircleShp.autoFactorX02.set(0.08) elif self.sections == 5: midCircleShp.autoFactorX01.set(0.02) midCircleShp.autoFactorX02.set(0.25) midCircleShp.autoFactorX03.set(0.22) midCircleShp.autoFactorX04.set(0.25) midCircleShp.autoFactorX05.set(0.02) elif self.sections == 7: midCircleShp.autoFactorX01.set(0) midCircleShp.autoFactorX02.set(0.11) midCircleShp.autoFactorX03.set(0.1) midCircleShp.autoFactorX04.set(0.16) midCircleShp.autoFactorX05.set(0.1) midCircleShp.autoFactorX06.set(0.11) midCircleShp.autoFactorX07.set(0) # toggles displays if self.visibility == 0: pm.toggle(nurbs, g=1, te=1) pm.toggle(arcLength, te=1) arcLength.visibility.set(0) topPosLoc.visibility.set(0) midPosLocShp = midPosLoc.getShape() midPosLocShp.visibility.set(0) midAimLocShp = midAimLoc.getShape() midAimLocShp.visibility.set(0) midOffLocShp = midOffLoc.getShape() midOffLocShp.visibility.set(0) lwrPosLoc.visibility.set(0) midUpLoc.visibility.set(0) grpScale.visibility.set(0) grpFol.visibility.set(0) # agrupando tudo finalRbbnGrp = pm.group(em=1, n=self.name + 'finalRbbn_grp') pm.parent(nurbs, grpFol, grpScale, arcLength, finalRbbnGrp)
def surfaceCreation(self, curve): bindJntChain = self.jointCreation(curve) loftCurves = [] i = -1 for x in range(2): jntPosList = [] chain = pm.duplicate(bindJntChain) chain[0].translateZ.set(i) i += 2 # Getting the children of the joint chains for k in chain: jntChildPos = k.getTranslation(space='world') jntPosList.append(jntChildPos) loftCurve = pm.curve(n='curve_' + str(x), degree=1, point=jntPosList) loftCurves.append(loftCurve) pm.delete(chain) surface = pm.loft(loftCurves[0], loftCurves[1], n='Ribbon_Surface', ar=True, reverseSurfaceNormals=False, degree=1, ss=1, object=True, ch=False, polygon=0) surface = pm.rebuildSurface(surface, ch=0, rpo=1, rt=0, end=1, kr=2, kcp=0, kc=0, su=0, du=3, sv=0, dv=3, tol=0.01, fr=0, dir=2 ) pm.delete(surface, ch=True) for j in loftCurves: pm.delete(j) # Unparenting joints and duplicate joints for skin bindJntList = [] skinJntList = [] for b in range(len(bindJntChain)): pm.parent(bindJntChain[b], w=True) bindJnt = pm.PyNode(bindJntChain[b]) bindJntList.append(bindJnt) #Here we add the method to nodelling if b == len(bindJntChain)-1: for l in range(len(bindJntChain)): name = bindJntChain[l].replace('Bind', 'Skin') skinJnt = pm.duplicate(bindJntChain[l], name=name) skinJntList.append(skinJnt) # Skinning the surface to the bind joint pm.skinCluster(surface, bindJntList, tsb=True, skinMethod=0, maximumInfluences=1, dropoffRate=10.0) # Creating all the nodes to for the skin Joints surfaceShape = surface[0].getShape() for r in range(len(skinJntList)): skinJnt = skinJntList[r] distance = (1.0 / (len(skinJntList)-1)) * r self.skinJntControl(skinJnt, surfaceShape, distance)
def build_plane(name=None, crv=None, spans=None, direction='u', width_axis=None, width=1, log=True): '''Given a valid curve, build nurbs plane Attributes: name -- Prefix name for plane. Str crv -- Curve to use as build guide. nt.Transform spans -- Spans for the plane. Int direction -- Build direction. 'u' or 'v' width_axis -- Plane width axis. 'x', 'y' or 'z' width -- Width of plane. Float ''' general.check_type(name, 'name', [str]) general.check_type(crv, 'crv', [pm.nt.Transform]) general.check_type(spans, 'spans', [int]) general.check_type(direction, 'direction', [str]) general.check_type(width_axis, 'width_axis', [str]) general.check_type(width, 'width', [float, int]) if direction not in ['u', 'v']: raise errors.InputError('direction', direction, "'u' or 'v'") if width_axis not in ['x', 'y', 'z']: raise errors.InputError('width_axis', width_axis, "'x', 'y' or 'z'") d1 = crv.duplicate() d2 = crv.duplicate() move_amt = [] if width_axis == 'x': move_amt = [width, 0, 0] elif width_axis == 'y': move_amt = [0, width, 0] elif width_axis == 'z': move_amt = [0, 0, width] if log: str_1 = 'move_amt: ', move_amt general.logging.debug(str_1) pm.move(move_amt[0], move_amt[1], move_amt[2], d1, r=1) pm.move(-move_amt[0], -move_amt[1], -move_amt[2], d2, r=1) p = pm.loft(d1, d2, n=name+'_plane', ch=0)[0] if direction == 'u': pm.rebuildSurface(p, dir=2, su=spans, sv=2) if direction == 'v': pm.rebuildSurface(p, dir=2, sv=spans, su=2) pm.delete(d1) pm.delete(d2) return p
def create_ribbons(self, side, components_type, selection, how_many_ctrls): if components_type != "face": if components_type == "edge": vertices_from_selection = pmc.polyListComponentConversion(selection, fromEdge=1, toVertex=1) vertices = pmc.ls(vertices_from_selection, flatten=1) vertices_from_first_edge = pmc.ls(pmc.polyListComponentConversion(selection[0], fromEdge=1, toVertex=1), flatten=1) edges_from_point = pmc.ls(pmc.polyListComponentConversion(vertices_from_first_edge[0], fromVertex=1, toEdge=1), flatten=1) vertices_from_edges = pmc.ls(pmc.polyListComponentConversion(edges_from_point, toVertex=1, fromEdge=1, border=1), flatten=1) next_vertex = [vertex for vertex in vertices_from_edges if vertex in vertices] if len(next_vertex) == 1: first_vertex = pmc.ls(vertices_from_first_edge[0])[0] else: first_vertex = pmc.ls(vertices_from_first_edge[1])[0] vertices.remove(first_vertex) vertices.insert(0, first_vertex) else: vertices = selection ordered_vertices = rig_lib.continuous_check_and_reorder_vertex_list(vertices, self.model.module_name) vertices_world_pos = [] skn_jnts = [] for i, vertex in enumerate(ordered_vertices): vertices_world_pos.append(pmc.xform(vertex, q=1, ws=1, translation=1)) pmc.select(cl=1) jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_{2}_SKN".format(self.model.module_name, side, i)) jnt.setAttr("translate", vertices_world_pos[i]) jnt.setAttr("radius", 0.1) skn_jnts.append(jnt) front_curve = pmc.curve(d=3, p=vertices_world_pos, n="{0}_{1}_nurbsSurface_guide_01".format(self.model.module_name, side)) back_curve = pmc.duplicate(front_curve, n="{0}_{1}_nurbsSurface_guide_02".format(self.model.module_name, side))[0] if self.model.loft_axis == "X": front_curve.setAttr("translateX", 0.1) back_curve.setAttr("translateX", -0.1) elif self.model.loft_axis == "Y": front_curve.setAttr("translateY", 0.1) back_curve.setAttr("translateY", -0.1) else: front_curve.setAttr("translateZ", 0.1) back_curve.setAttr("translateZ", -0.1) surface = pmc.loft(back_curve, front_curve, ar=1, ch=0, d=1, uniform=0, n="{0}_{1}_ribbons_NURBSSURFACE".format(self.model.module_name, side))[0] surface = pmc.rebuildSurface(surface, ch=0, du=1, dv=3, dir=2, kcp=1, kr=0, rt=0, rpo=1)[0] pmc.delete(front_curve) pmc.delete(back_curve) pmc.parent(surface, self.parts_grp) self.jnts_to_skin.append(skn_jnts) follicles = [] for i, jnt in enumerate(skn_jnts): follicle_shape = pmc.createNode("follicle", n="{0}_{1}_{2}_FOLShape".format(self.model.module_name, side, i)) follicle = follicle_shape.getParent() follicle.rename("{0}_{1}_{2}_FOL".format(self.model.module_name, side, i)) follicle_shape.outTranslate >> follicle.translate follicle_shape.outRotate >> follicle.rotate surface.getShape().local >> follicle_shape.inputSurface surface.getShape().worldMatrix[0] >> follicle_shape.inputWorldMatrix point_on_surface = pmc.createNode("closestPointOnSurface", n=str(jnt) + "CPS") surface.getShape().local >> point_on_surface.inputSurface point_on_surface.setAttr("inPosition", pmc.xform(jnt, q=1, ws=1, translation=1)) follicle_shape.setAttr("parameterU", point_on_surface.getAttr("parameterU")) follicle_shape.setAttr("parameterV", point_on_surface.getAttr("parameterV")) pmc.delete(point_on_surface) pmc.parent(jnt, follicle, r=0) follicles.append(follicle) pmc.parent(follicle, self.jnt_input_grp) pmc.select(cl=1) start_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_start_JNT".format(self.model.module_name, side)) start_jnt.setAttr("radius", 0.2) pmc.select(cl=1) end_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_end_JNT".format(self.model.module_name, side)) end_jnt.setAttr("radius", 0.2) pmc.select(cl=1) mid_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_mid_JNT".format(self.model.module_name, side)) mid_jnt.setAttr("radius", 0.2) pmc.select(cl=1) start_mid_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_start_mid_JNT".format(self.model.module_name, side)) start_mid_jnt.setAttr("radius", 0.2) pmc.select(cl=1) mid_end_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_mid_end_JNT".format(self.model.module_name, side)) mid_end_jnt.setAttr("radius", 0.2) ctrl_jnts_pos = pmc.createNode("pointOnSurfaceInfo", n="{0}_{1}_PSI".format(self.model.module_name, side)) surface.getShape().local >> ctrl_jnts_pos.inputSurface ctrl_jnts_pos.setAttr("parameterU", 0.5) ctrl_jnts_pos.setAttr("parameterV", 0.0) pmc.refresh() start_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) if how_many_ctrls == "7": ctrl_jnts_pos.setAttr("parameterV", 0.3) else: ctrl_jnts_pos.setAttr("parameterV", 0.25) pmc.refresh() start_mid_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrl_jnts_pos.setAttr("parameterV", 0.5) pmc.refresh() mid_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) if how_many_ctrls == "7": ctrl_jnts_pos.setAttr("parameterV", 0.7) else: ctrl_jnts_pos.setAttr("parameterV", 0.75) pmc.refresh() mid_end_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrl_jnts_pos.setAttr("parameterV", 1.0) pmc.refresh() end_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) if how_many_ctrls == "7": pmc.select(cl=1) start_quarter_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_start_quarter_JNT".format(self.model.module_name, side)) start_quarter_jnt.setAttr("radius", 0.2) pmc.select(cl=1) quarter_end_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_quarter_end_JNT".format(self.model.module_name, side)) quarter_end_jnt.setAttr("radius", 0.2) ctrl_jnts_pos.setAttr("parameterV", 0.15) pmc.refresh() start_quarter_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrl_jnts_pos.setAttr("parameterV", 0.85) pmc.refresh() quarter_end_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrls_jnt = [start_jnt, start_quarter_jnt, start_mid_jnt, mid_jnt, mid_end_jnt, quarter_end_jnt, end_jnt] else: ctrls_jnt = [start_jnt, start_mid_jnt, mid_jnt, mid_end_jnt, end_jnt] pmc.delete(ctrl_jnts_pos) ctrls = [] ctrls_fol = [] for jnt in ctrls_jnt: if side == "bot": jnt.setAttr("jointOrientX", 180) if jnt.getAttr("translateX") < -0.05: jnt.setAttr("jointOrientY", 180) follicle_shape = pmc.createNode("follicle", n=str(jnt).replace("_JNT", "_FOLShape")) follicle = follicle_shape.getParent() follicle.rename(str(jnt).replace("_JNT", "_FOL")) follicle_shape.outTranslate >> follicle.translate follicle_shape.outRotate >> follicle.rotate self.mesh_to_follow.getShape().outMesh >> follicle_shape.inputMesh self.mesh_to_follow.getShape().worldMatrix[0] >> follicle_shape.inputWorldMatrix point_on_mesh = pmc.createNode("closestPointOnMesh", n=str(jnt) + "CPM") self.mesh_to_follow.getShape().outMesh >> point_on_mesh.inMesh point_on_mesh.setAttr("inPosition", pmc.xform(jnt, q=1, ws=1, translation=1)) follicle_shape.setAttr("parameterU", point_on_mesh.getAttr("parameterU")) follicle_shape.setAttr("parameterV", point_on_mesh.getAttr("parameterV")) pmc.delete(point_on_mesh) ctrls_fol.append(follicle) pmc.select(clear=1) ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=0.5, d=3, s=8, n=str(jnt).replace("_JNT", "_ctrl_Shape"), ch=0)[0] ctrl = rig_lib.create_jnttype_ctrl(name=str(jnt).replace("_JNT", "_CTRL"), shape=ctrl_shape) pmc.select(clear=1) ctrl_ofs = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_OFS")) ctrl_ofs.setAttr("drawStyle", 2) ctrl_fix_r = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_rotate_FIX")) ctrl_fix_r.setAttr("drawStyle", 2) ctrl_fix_r.setAttr("rotateOrder", 5) ctrl_fix_t = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_translate_FIX")) ctrl_fix_t.setAttr("drawStyle", 2) pmc.parent(ctrl, ctrl_fix_t) pmc.parent(ctrl_ofs, follicle) ctrl_ofs.setAttr("translate", (0, 0, 0)) ctrl_ofs.setAttr("rotate", (0, 0, 0)) ctrl_ofs.setAttr("jointOrient", (0, 0, 0)) ctrl_ofs_orientation_loc = pmc.spaceLocator(p=(0, 0, 0), n="{0}_orientation_LOC".format(ctrl_ofs)) pmc.parent(ctrl_ofs_orientation_loc, jnt, r=1) pmc.parent(ctrl_ofs_orientation_loc, follicle, r=0) ctrl_ofs.setAttr("jointOrient", ctrl_ofs_orientation_loc.getAttr("rotate")) pmc.delete(ctrl_ofs_orientation_loc) invert_ctrl_translate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_translate_MDL") invert_ctrl_rotate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_rotate_MDL") ctrl.translate >> invert_ctrl_translate.input1 invert_ctrl_translate.setAttr("input2", (-1, -1, -1)) invert_ctrl_translate.output >> ctrl_fix_t.translate ctrl.rotate >> invert_ctrl_rotate.input1 invert_ctrl_rotate.setAttr("input2", (-1, -1, -1)) invert_ctrl_rotate.output >> ctrl_fix_r.rotate ctrl_cvs = ctrl.cv[:] for cv in ctrl_cvs: pmc.move(cv, 0.5, moveZ=1, ws=1, wd=1, r=1) pmc.move(cv, 0.1, moveY=1, ls=1, wd=1, r=1) jnt_ofs = pmc.duplicate(jnt, n=str(jnt).replace("_JNT", "_jnt_OFS"))[0] jnt_ofs.setAttr("drawStyle", 2) pmc.parent(jnt, jnt_ofs) ctrl.translate >> jnt.translate ctrl.rotate >> jnt.rotate ctrl.scale >> jnt.scale ctrls.append(ctrl) pmc.parent(jnt_ofs, self.parts_grp) pmc.parent(follicle, self.ctrl_input_grp) pmc.select(cl=1) pmc.skinCluster(ctrls_jnt, surface, bm=0, dr=4.0, mi=2, nw=1, sm=0, tsb=1, wd=0) return skn_jnts, surface, follicles, ctrls_jnt, ctrls_fol, ctrls else: pmc.error("faces aren't support yet")
for i in range(locator_num): new_locator = pm.duplicate(startlocator) movelen = steplen * (i + 1) pm.move(movelen,new_locator, x = True,r=True, os = True) pointlist.append(pm.xform(new_locator,t = True, ws = True, q = True)) #create curve #move curve along z axis curve1 = pm.curve(p = pointlist,d = 1.0) curve2 = pm.duplicate(curve1) pm.move(2, curve1, x = True, r = True, os = True) pm.move(-2, curve2, x = True, r = True, os = True) flexymesh_transform = pm.loft(curve1, curve2, ar = True, d = 3, name = 'flexymesh', po = 0, rsn = True)[0] #surface need to rebuild pm.rebuildSurface(flexymesh_transform, du = 3, dv = 1, su = total_joint, sv = 1) flexymesh = flexymesh_transform.getShape() foll_grp = pm.group(em = True, w = True, n = 'FollicleNode') #create follicles for i in range (5): foll_transform = pm.createNode('transform', ss= True, name = 'follicle' + str(i)) follicle = pm.createNode('follicle', name = 'follicleshape' + str(i), p = foll_transform) flexymesh.local.connect(follicle.inputSurface) flexymesh.worldMatrix[0].connect(follicle.inputWorldMatrix) follicle.outRotate.connect(follicle.getParent().rotate) follicle.outTranslate.connect(follicle.getParent().translate) follicle.parameterU.set(0.1 + i * 0.2) follicle.parameterV.set(0.5) follicle.getParent().t.lock() follicle.getParent().r.lock()
def rp_surface(): """..............................................................................................//""" ncj = int(pm.intField('NCJ', q=1, v=1)) # > control joints rn = float(pm.intField('NJ', q=1, v=1)) bz = int(pm.checkBoxGrp('CTJP', q=1, v1=1)) s = pm.ls(sl=1) rp_check(s) if pm.objExists(s[0] + "_surface"): rp_del() rp_cr() cj = pm.ls((s[0] + "_ctj_*"), typ="joint") x = 0.0 if pm.optionMenuGrp('AXES', q=1, v=1) == "x": x = float(1) y = 0.0 if pm.optionMenuGrp('AXES', q=1, v=1) == "y": y = float(1) z = 0.0 if pm.optionMenuGrp('AXES', q=1, v=1) == "z": z = float(1) su = pm.extrude(s[0], upn=0, dl=3, ch=bz, d=(x, y, z), n=(s[0] + "_surface"), et=0, rn=0, po=0) pm.pm.cmds.move(((-1) * (x / 2)), ((-1) * (y / 2)), ((-1) * (z / 2)), su[0]) pm.makeIdentity(su[0], a=1, t=1) sj = pm.ls((s[0] + "_tw_*"), typ="joint") # pivot move t = (pm.xform(cj[0], q=1, ws=1, t=1)) pm.setAttr((su[0] + ".rpx"), (t.x)) pm.setAttr((su[0] + ".rpy"), (t.y)) pm.setAttr((su[0] + ".rpz"), (t.z)) pm.setAttr((su[0] + ".spx"), (t.x)) pm.setAttr((su[0] + ".spy"), (t.y)) pm.setAttr((su[0] + ".spz"), (t.z)) # hairs hsys = str(pm.createNode("hairSystem", n=(s[0] + "_position"))) hsysg = pm.listRelatives(hsys, p=1) pm.rename(hsysg[0], (s[0] + "_surface_grp_")) pm.select(su[0], hsys) pm.mel.createHair((len(sj)), 1, 2, 0, 0, 1, 1, 1, 0, 2, 2, 1) pm.delete((s[0] + "_surface_grp_"), (s[0] + "_surface_grp_OutputCurves")) # joints sg = pm.listRelatives((s[0] + "_surface_grp_Follicles"), c=1) pm.delete(s[0] + "_tw_hl") for i in range(0, (len(sj))): pm.parent(sj[i], sg[i]) pm.makeIdentity(sj[i], a=1, r=1) pm.connectAttr((s[0] + "_rig.s"), (sg[i] + ".s"), f=1) pm.parent(su[0], (s[0] + "_sistem")) pm.parent((s[0] + "_surface_grp_Follicles"), (s[0] + "_sistem")) # conection scale joints if bz == 0: if pm.checkBoxGrp('CTJ', q=1, v1=1): for i in range(0, (len(cj))): pm.disconnectAttr((s[0] + "_" + str((i + 1)) + "_CT.change"), (cj[i] + ".sy")) pm.disconnectAttr((s[0] + "_" + str((i + 1)) + "_CT.change"), (cj[i] + ".sz")) pm.delete((s[0] + "_sx"), (s[0] + "_s")) sx = str(pm.createNode('multiplyDivide', n=(s[0] + "_pow"))) # pow scale pm.setAttr((sx + ".op"), 2) pm.connectAttr((s[0] + "_rig.s"), (sx + ".i2"), f=1) pm.setAttr((sx + ".i1x"), 1) pm.setAttr((sx + ".i1y"), 1) pm.setAttr((sx + ".i1z"), 1) pm.connectAttr((sx + ".o"), (s[0] + "_surface_grp_Follicles.s"), f=1) # > skin fol = pm.ls((s[0] + "_surfaceFollicle*"), typ="transform") for i in range(0, (len(fol))): pm.setAttr((fol[i] + ".it"), 0) if bz == 0: pm.rebuildSurface(su[0], dv=1, du=3, sv=0, su=rn) pm.intField('NJ', e=1, v=rn) pm.skinCluster(cj, su[0], mi=2, rui=1, dr=2.0, n=(s[0] + "_skin_surface")) pm.setAttr((su[0] + ".it"), 0) pm.setAttr((su[0] + ".tmp"), 1) # > end pm.select(s[0])
def buildRibbon(start, end, normal, numControls=3, name='Ribbon', groupName='', controlSpec={}): chain = util.getChain(start, end) controlChain = util.dupChain(start, end) if not name: name = 'Ribbon' container = util.parentGroup(chain[0]) container.setParent(lib.getNodes.mainGroup()) world = group(em=True) hide(world) world.setParent(container) #controlChain[0].setParent( container ) crv = curve(d=1, p=[(0, 0, 0)] * len(chain)) for i, j in enumerate(chain): xform(crv.cv[i], t=xform(j, q=True, ws=True, t=True), ws=True) dup = duplicate(crv)[0] # &&& Obviously need to calc the offset somehow, maybe I can use the mirror state? Maybe not, due to asymmetry #offset = dt.Vector(5, 0, 0) offset = normal crv.t.set(offset) dup.t.set(offset * -1) surfaceTrans = loft(crv, dup, uniform=True, polygon=0, sectionSpans=1, degree=3, autoReverse=True)[0] surfaceTrans.setParent(world) delete(crv, dup) rebuildSurface(surfaceTrans, rebuildType=0, replaceOriginal=True, spansU=1, spansV=(len(chain) - 1) * 2, dir=2, degreeV=3, degreeU=1) hide(surfaceTrans) surfaceShape = surfaceTrans.getShape() closest = createNode('closestPointOnSurface') surfaceShape.worldSpace >> closest.inputSurface vScalar = surfaceShape.minMaxRangeV.get()[1] #constraints = [] for jnt, hairJoint in zip(chain, controlChain): #jnt.setParent(world) follicle = createNode('follicle') hide(follicle) trans = follicle.getParent() #hairJoints.append(trans) trans.setParent(world) pos = jnt.getTranslation(space='world') closest.inPosition.set(pos) surfaceShape.local >> follicle.inputSurface u = closest.parameterU.get() # closestPointOnSurface returns val in relation to the maxV but the follicle needs it normalized. v = closest.parameterV.get() / vScalar follicle.parameterU.set(u) follicle.parameterV.set(v) follicle.outTranslate >> trans.translate follicle.outRotate >> trans.rotate trans.translate.lock() trans.rotate.lock() hairJoint.setParent(trans) constraints = util.constrainAtoB(chain, controlChain) temp = core.capi.asMObject(surfaceShape) nurbsObj = OpenMaya.MFnNurbsSurface(temp.object()) controls = [] controlJoints = [] for i in range(numControls): percent = i / float(numControls - 1) * vScalar p = pointOnSurface(surfaceShape, u=.5, v=percent, p=True) ctrl = controllerShape.build( name + '%i' % (i + 1), controlSpec['main'], type=controllerShape.ControlType.TRANSLATE) ctrl.t.set(p) j = joint(ctrl) hide(j) controlJoints.append(j) ctrl.setParent(container) # Aim the control at the next joint with it's up following the surface if i < numControls - 1: target = chain[i + 1] normal = nurbsObj.normal(0.5, percent) lib.anim.orientJoint(ctrl, target, upVector=dt.Vector(normal.x, normal.y, normal.z)) core.dagObj.zero(ctrl) controls.append(ctrl) # Orient the final control to the final joint core.dagObj.matchTo(controls[-1], chain[-1]) core.dagObj.zero(controls[-1]) skinCluster(surfaceShape, controlJoints, tsb=True) mainCtrl = nodeApi.RigController.convert(controls[0]) mainCtrl.container = container for i, ctrl in enumerate(controls[1:], 1): mainCtrl.subControl[str(i)] = ctrl return mainCtrl, constraints
def create_guideSurface(IdName, listOfJnts): loftCurves = [] for i in range(2): # duplicate and select hierarchy of joints listOfOffsetJnts = pm.duplicate(listOfJnts, name='b_' + IdName + '_offset1', parentOnly=True) # offset each joint on it's own z-axis for jnt in listOfOffsetJnts: if i == 0: pm.move(jnt, (0, 0, -0.5), relative=True, objectSpace=True, preserveChildPosition=True) if i == 1: pm.move(jnt, (0, 0, 0.5), relative=True, objectSpace=True, preserveChildPosition=True) # draw loftcurves loftCurvePoints = [] for each in listOfOffsetJnts: jntPosition = pm.xform(each, q=True, t=True, ws=True) loftCurvePoints.append(jntPosition) loftCurves.append( pm.curve(name=IdName + '_loftCurve' + str(i), degree=1, point=loftCurvePoints)) pm.delete(listOfOffsetJnts) # loft guideSurface guideSurface = pm.loft(loftCurves[0], loftCurves[1], name=IdName + '_guide_surface', ar=True, rsn=True, d=3, ss=1, object=True, ch=False, polygon=0) guideSurface = pm.rebuildSurface(guideSurface, ch=1, rpo=1, rt=0, end=1, kr=1, kcp=0, kc=0, su=0, du=3, sv=1, dv=3, tol=0.01, fr=0, dir=2) # cleanup pm.delete(loftCurves) guideSurface[0].inheritsTransform.set(False) guideSurface[0].overrideEnabled.set(True) guideSurface[0].overrideDisplayType.set(1) # guideSurface[0].visibility.set(False) print('Successfully lofted guide surface. Continuing...') return guideSurface
def __createNurbs__(self): # check if plugin decompose matrix is present pmc.loadPlugin('decomposeMatrix', quiet=True) # create groups folGrp = pmc.createNode('transform', name=self.name+'_fol_NXF', parent=self.grp, skipSelect=True) self.strucGrp = pmc.createNode('transform', name=self.name+'_struc_NXF', parent=self.grp, skipSelect=True) folGrp.inheritsTransform.set(0) self.strucGrp.inheritsTransform.set(0) # create plane plan = pmc.nurbsPlane(name=self.name+'_plane', axis=[0,1,0], width=self.length, lengthRatio=(1.0/self.length)/2.0, degree=3, patchesU=4, patchesV=1, constructionHistory=0, pivot=[self.length/2.0,0,0])[0] plan.inheritsTransform.set(0) plan.setParent(folGrp) pmc.rebuildSurface( plan, constructionHistory=False, replaceOriginal=True, rebuildType=0, endKnots=1, keepRange=0, keepControlPoints=0, keepCorners=0, spansV=1, degreeV=1, fitRebuild=0, direction=1 ) # create follicle + control + bones self.subCtrlGrp = [] self.subCtrl = [] self.bones2SK = [] for i in range(self.nbItem): fol = pmc.createNode('transform', name=self.name+'_fol'+str(i+1), parent=folGrp, skipSelect=True) folShape = pmc.createNode('follicle', name=self.name+'_fol'+str(i+1)+'Shape', parent=fol, skipSelect=True) # connections plan.worldMatrix[0] >> folShape.inputWorldMatrix plan.local >> folShape.inputSurface folShape.outRotate >> fol.rotate folShape.outTranslate >> fol.translate # u and v setting folShape.parameterV.set(0.5) folShape.parameterU.set((1.0/(self.nbItem-1.0))*i) folShape.visibility.set(False) clean.__lockHideTransform__(fol, channel=['t', 'r', 's', 'v']) # sub control self.subCtrlGrp.append( pmc.createNode('transform', name=self.name+'_sub'+str(i+1)+'_grp') ) self.subCtrl.append( shapesBiblio.rhombusX(name=self.name+'_sub'+str(i+1), color=self.colorTwo) ) # add attributs pmc.addAttr(self.subCtrl[i], longName='posU', attributeType='float', defaultValue=((1.0/(self.nbItem-1.0))*i) ) pmc.addAttr(self.subCtrl[i], longName='negU', attributeType='float', defaultValue=1-((1.0/(self.nbItem-1.0))*i) ) self.subCtrl[-1].setParent(self.subCtrlGrp[-1]) self.subCtrlGrp[-1].setParent(fol) self.subCtrlGrp[-1].setTranslation([0,0,0], space='object') xfm.__xfm__(self.subCtrlGrp[-1]) # bones self.bones2SK.append( bn.create2SK(self.name+'_sub'+str(i+1), self.subCtrl[-1]) ) # pickwalk arPickwalk.setPickWalk(self.subCtrl, type='UD') # create structure strucJnt = [] self.strucCtrl = {} for i in range(len(self.ctrlName)): strucTmp = [] if i == 1: # ctrl strucTmp.append( shapesBiblio.circleX(name=self.name+'_'+self.ctrlName[i], parent=self.strucGrp, color=self.colorOne) ) clean.__lockHideTransform__(strucTmp[-1], channel=['s']) strucJnt.append( pmc.createNode('joint', name=self.name+'_'+self.ctrlName[i]+'_RIGjnt', parent=strucTmp[-1], skipSelect=True) ) # aim strucTmp.append( pmc.createNode('transform', name=self.name+'_'+self.ctrlName[i]+'_pos', parent=self.strucGrp, skipSelect=True) ) # rot strucTmp.append( pmc.createNode('transform', name=self.name+'_'+self.ctrlName[i]+'_aim', parent=strucTmp[-1], skipSelect=True) ) strucTmp[0].setParent(strucTmp[-1]) # up strucTmp.append( pmc.createNode('transform', name=self.name+'_'+self.ctrlName[i]+'_up', parent=strucTmp[-2], skipSelect=True) ) strucTmp[-1].setTranslation([0,self.length/2.0,0], space='world') else: # ctrl strucTmp.append( shapesBiblio.circleX(name=self.name+'_'+self.ctrlName[i], parent=self.strucGrp, color=self.colorOne) ) clean.lockHideTransform(strucTmp[-1], channel=['rotateOrder']) # aim strucTmp.append( pmc.createNode('transform', name=self.name+'_'+self.ctrlName[i]+'_aim', parent=strucTmp[-1], skipSelect=True) ) strucJnt.append( pmc.createNode('joint', name=self.name+'_'+self.ctrlName[i]+'_RIGjnt', parent=strucTmp[-1], skipSelect=True) ) # scale strucTmp.append( pmc.createNode('transform', name=self.name+'_'+self.ctrlName[i]+'_scl', parent=strucTmp[-1], skipSelect=True) ) strucTmp.append( pmc.createNode('transform', name=self.name+'_'+self.ctrlName[i]+'_locScl', parent=strucTmp[-1], skipSelect=True) ) # local scale connection strucTmp[0].scale >> strucTmp[-1].scale # up strucTmp.append( pmc.createNode('transform', name=self.name+'_'+self.ctrlName[i]+'_up', parent=strucTmp[-4], skipSelect=True) ) strucTmp[-1].setTranslation([0,self.length/2.0,0], space='world') # put info into dico self.strucCtrl[self.ctrlName[i]] = strucTmp # place structure end self.strucCtrl[self.ctrlName[2]][0].setTranslation([self.length,0,0], space='world') # pickwalk arPickwalk.setPickWalk([self.strucCtrl[self.ctrlName[0]][0], self.strucCtrl[self.ctrlName[1]][0], self.strucCtrl[self.ctrlName[2]][0]], type='UD') arPickwalk.setPickWalk([self.strucCtrl[self.ctrlName[0]][0], self.subCtrl[0]], type='LR') arPickwalk.setPickWalk([self.strucCtrl[self.ctrlName[2]][0], self.subCtrl[-1]], type='LR') # create constrain group self.strucCtrlGrp = [] self.strucCtrlGrp.append( xfm.__xfm__(self.strucCtrl[self.ctrlName[0]][0], suffix='_cst_grp', lock=False) ) self.strucCtrlGrp.append( xfm.__xfm__(self.strucCtrl[self.ctrlName[1]][0], suffix='_cst_grp', lock=False) ) self.strucCtrlGrp.append( xfm.__xfm__(self.strucCtrl[self.ctrlName[2]][0], suffix='_cst_grp', lock=False) ) # constrain between structure tmp = [] tmp.append( pmc.pointConstraint(self.strucCtrl[self.ctrlName[0]][0], self.strucCtrl[self.ctrlName[2]][0], self.strucCtrl[self.ctrlName[1]][1], name=self.strucCtrl[self.ctrlName[1]][1]+'_ptCst', maintainOffset=False ) ) tmp.append( pmc.pointConstraint(self.strucCtrl[self.ctrlName[0]][4], self.strucCtrl[self.ctrlName[2]][4], self.strucCtrl[self.ctrlName[1]][3], name=self.strucCtrl[self.ctrlName[1]][3]+'_ptCst', maintainOffset=False ) ) tmp.append( pmc.aimConstraint(self.strucCtrl[self.ctrlName[2]][0], self.strucCtrl[self.ctrlName[0]][1], name=self.strucCtrl[self.ctrlName[0]][1]+'_aimCst', maintainOffset=False, worldUpType='object', worldUpObject=self.strucCtrl[self.ctrlName[0]][4], aimVector=[1,0,0], upVector=[0,1,0]) ) tmp.append( pmc.aimConstraint(self.strucCtrl[self.ctrlName[0]][0], self.strucCtrl[self.ctrlName[2]][1], name=self.strucCtrl[self.ctrlName[2]][1]+'_aimCst', maintainOffset=False, worldUpType='object', worldUpObject=self.strucCtrl[self.ctrlName[2]][4], aimVector=[-1,0,0], upVector=[0,1,0]) ) tmp.append( pmc.aimConstraint(self.strucCtrl[self.ctrlName[2]][0], self.strucCtrl[self.ctrlName[1]][2], name=self.strucCtrl[self.ctrlName[1]][2]+'_aimCst', maintainOffset=False, worldUpType='object', worldUpObject=self.strucCtrl[self.ctrlName[1]][3], aimVector=[1,0,0], upVector=[0,1,0]) ) clean.lockHideTransform(tmp, channelBox=True) # skinning nurbs plane skinNode = pmc.skinCluster( strucJnt[0], strucJnt[1], strucJnt[2], plan, name=plan.name()+'_skn', ignoreSelected=0, maximumInfluences=3, dropoffRate=12.0, normalizeWeights=1) weights = [] weights.extend([1, 0, 0]) weights.extend([1, 0, 0]) weights.extend([0.8, 0.2, 0]) weights.extend([0.8, 0.2, 0]) weights.extend([0.4, 0.6, 0]) weights.extend([0.4, 0.6, 0]) weights.extend([0, 1, 0]) weights.extend([0, 1, 0]) weights.extend([0, 0.6, 0.4]) weights.extend([0, 0.6, 0.4]) weights.extend([0, 0.2, 0.8]) weights.extend([0, 0.2, 0.8]) weights.extend([0, 0, 1]) weights.extend([0, 0, 1]) # set weights skinNode[0].setWeights(plan, [0,1,2], weights, normalize=True) # delete useless bindpose bindPose = strucJnt[0].bindPose.outputs()[0] pmc.delete(bindPose) # inverse scale for bones for i in range(len(self.ctrlName)): multMat = pmc.createNode('multMatrix', name=self.strucCtrl[self.ctrlName[i]][0]+'_invScl_multMat', skipSelect=True) decoMat = pmc.createNode('decomposeMatrix', name=self.strucCtrl[self.ctrlName[i]][0]+'_invScl_decoMat', skipSelect=True) self.strucGrp.inverseMatrix >> multMat.matrixIn[0] self.strucCtrl[self.ctrlName[i]][0].worldMatrix[0] >> multMat.matrixIn[1] multMat.matrixSum >> decoMat.inputMatrix decoMat.outputScale >> strucJnt[i].inverseScale # connect scale from controlors to sub decoMatS = pmc.createNode('decomposeMatrix', name=self.strucCtrl[self.ctrlName[0]][0]+'_decoMat', skipSelect=True) decoMatE = pmc.createNode('decomposeMatrix', name=self.strucCtrl[self.ctrlName[2]][0]+'_decoMat', skipSelect=True) self.strucCtrl[self.ctrlName[0]][3].worldMatrix[0] >> decoMatS.inputMatrix self.strucCtrl[self.ctrlName[2]][3].worldMatrix[0] >> decoMatE.inputMatrix # connect scale to sub control for i in range(1, self.nbItem-1): # create blend to progressively pass from the start to the end scale bld = pmc.createNode('blendColors', name=self.subCtrl[i].name()+str(i)+'_bld') decoMatS.outputScale >> bld.color1 decoMatE.outputScale >> bld.color2 # connect the sub control attribut neg U self.subCtrl[i].negU >> bld.blender # connect into the scale bld.output >> self.subCtrlGrp[i].scale # no point to create a blend node for the first and the last sub control decoMatS.outputScale >> self.subCtrlGrp[0].scale decoMatE.outputScale >> self.subCtrlGrp[-1].scale # hide and lock channels plan.visibility.set(False) clean.__lockHideTransform__(plan, channel=['t', 'r', 's', 'v']) clean.__lockHideTransform__(folGrp, channel=['t', 'r', 's', 'v']) for jnt in strucJnt: jnt.overrideEnabled.set(1) jnt.overrideColor.set(3) jnt.radius.set(0.5) jnt.visibility.set(False) clean.__lockHideTransform__(jnt, channel=['t', 'r', 's', 'v', 'radius']) # unselect pmc.select(clear=True) # return, in order # 0 the main group PyNode # 1 the main structure group this last can receive constrain to place the ribbon PyNode # 2 groups of each structure controls in order (start offset end) PyNode List # 3 structure controls in order (start offset end) PyNode List) # 4 groups wich can receive a scale information in order (start end) PyNode List # 5 position groups which give the default position in order (offset) PyNode # 6 groups of sub controls PyNode List # 7 sub controls PyNode List # 8 2SKjnt PyNode List return [self.grp, self.strucGrp, self.strucCtrlGrp, [self.strucCtrl[self.ctrlName[0]][0], self.strucCtrl[self.ctrlName[1]][0], self.strucCtrl[self.ctrlName[2]][0]], [self.strucCtrl[self.ctrlName[0]][2], self.strucCtrl[self.ctrlName[2]][2]], self.strucCtrl[self.ctrlName[1]][1], self.subCtrlGrp, self.subCtrl, self.bones2SK]
def uniform_rebuild(self, number_of_points): rebuild_surf = pm.rebuildSurface(self.skin_surface, rebuildType=0, spansV=number_of_points, keepRange=True) self.skin_surface = rebuild_surf[0]