def sqGenerateCurves(self, *args): self.edgeList = cmds.ls(selection=True, flatten=True) if not self.edgeList == None and not self.edgeList == [] and not self.edgeList == "": self.baseCurve = cmds.polyToCurve(name="baseCurve", form=2, degree=1)[0] cmds.select(self.baseCurve+".ep[*]") cmds.insertKnotCurve(cmds.ls(selection=True, flatten=True), constructionHistory=True, curveOnSurface=True, numberOfKnots=1, addKnots=False, insertBetween=True, replaceOriginal=True) pointListA, pointListB, sideA, sideB = self.sqGetPointLists() toDeleteList = [] p = 2 for k in range((sideA+2), (sideB-1)): if p%2 == 0: toDeleteList.append(self.baseCurve+".cv["+str(k)+"]") toDeleteList.append(self.baseCurve+".cv["+str(k+len(pointListA)-1)+"]") p = p+1 q = 2 m = sideA-2 if m >= 0: while m >= 0: if not m == sideA and not m == sideB: if q%2 == 0: toDeleteList.append(self.baseCurve+".cv["+str(m)+"]") m = m-1 q = q+1 cmds.delete(toDeleteList) cmds.insertKnotCurve([self.baseCurve+".u["+str(len(pointListA)-1)+"]", self.baseCurve+".ep["+str(len(pointListA)-1)+"]"], constructionHistory=True, curveOnSurface=True, numberOfKnots=1, addKnots=False, insertBetween=True, replaceOriginal=True) pointListA, pointListB, sideA, sideB = self.sqGetPointLists() posListA, posListB = [], [] for i in range(0, len(pointListA)-1): posListA.append(cmds.xform(pointListA[i], query=True, worldSpace=True, translation=True)) posListB.append(cmds.xform(pointListB[i], query=True, worldSpace=True, translation=True)) self.mainCurveA = cmds.curve(name="StickyLips_Main_A_Crv", degree=1, point=posListA) self.mainCurveB = cmds.curve(name="StickyLips_Main_B_Crv", degree=1, point=posListB) cmds.rename(cmds.listRelatives(self.mainCurveA, children=True, shapes=True)[0], self.mainCurveA+"Shape") cmds.rename(cmds.listRelatives(self.mainCurveB, children=True, shapes=True)[0], self.mainCurveB+"Shape") cmds.select(self.mainCurveA+".cv[*]") self.curveLenght = len(cmds.ls(selection=True, flatten=True)) cmds.select(clear=True) self.sqCheckCurveDirection(self.mainCurveA) self.sqCheckCurveDirection(self.mainCurveB) self.baseCurveA = cmds.duplicate(self.mainCurveA, name=self.mainCurveA.replace("_Main_", "_Base_"))[0] self.baseCurveB = cmds.duplicate(self.mainCurveB, name=self.mainCurveB.replace("_Main_", "_Base_"))[0] cmds.delete(self.baseCurve) self.maxIter = len(posListA) cmds.group(self.mainCurveA, self.mainCurveB, self.baseCurveA, self.baseCurveB, name="StickyLips_StaticData_Grp") else: mel.eval("warning \"Please, select an closed edgeLoop.\";")
def straightenVerts(edgeList, falloff=0.01, influence=1.0, snapToOriginal=False, keepEdgeSpacing=False, deleteHistory=False): """ Straighten specified polygon vertices. @param influence: @param keepEdgeSpacing: @param edgeList: List of polygon edges to straighten. @type edgeList: list @param falloff: Falloff distance around selected vertices. @type falloff: float @param snapToOriginal: Snap vertices back to closest point on original mesh. @type snapToOriginal: bool @param deleteHistory: Delete construction history. @type deleteHistory: bool """ # Get Edge List edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or [] if not edgeList: raise Exception( 'Invalid or empty edge list! Unable to straighten vertices...') # Build Edge Curve from Vertices edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves( edgeList, keepHistory=False) straightCrvList = [] for edgeCrv in edgeCrvList: # Build Straight Curve straightCrv = cmds.rebuildCurve(edgeCrv, ch=False, rpo=False, rt=0, end=1, kr=False, kcp=False, kep=True, kt=False, s=1, d=1, tol=0)[0] # Rebuild Straight Curve dist = [] total = 0.0 params = [] pts = glTools.utils.base.getMPointArray(edgeCrv) max = cmds.getAttr(straightCrv + '.maxValue') if keepEdgeSpacing: for i in range(pts.length() - 1): d = (pts[i] - pts[i + 1]).length() dist.append(d) total += d for i in range(len(dist)): d = dist[i] / total * max if i: d += params[-1] params.append(d) else: params = glTools.utils.mathUtils.distributeValue( pts.length(), rangeEnd=max)[1:-1] params = [straightCrv + '.u[' + str(i) + ']' for i in params] cmds.insertKnotCurve(params, ch=False, numberOfKnots=1, add=True, ib=False, rpo=True) # Snap To Mesh mesh = cmds.ls(edgeList, o=True)[0] if snapToOriginal: pts = glTools.utils.component.getComponentStrList(straightCrv) glTools.utils.mesh.snapPtsToMesh(mesh, pts) # Append List straightCrvList.append(straightCrv) # ================= # - Deform Points - # ================= # Build Wire Deformer wire = glTools.utils.wire.createMulti(mesh, edgeCrvList, dropoffDist=falloff, prefix=mesh.split(':')[-1]) cmds.setAttr(wire[0] + '.rotation', 0) # Blend to Straight Curve for i in range(len(edgeCrvList)): blendShape = glTools.utils.blendShape.create( baseGeo=edgeCrvList[i], targetGeo=[straightCrvList[i]]) cmds.setAttr(blendShape + '.' + straightCrvList[i], influence) # ================== # - Delete History - # ================== if deleteHistory: wireBaseList = glTools.utils.wire.getWireBase(wire[0]) cmds.delete(mesh, ch=True) for edgeCrv in edgeCrvList: if cmds.objExists(edgeCrv): cmds.delete(edgeCrv) for straightCrv in straightCrvList: if cmds.objExists(straightCrv): cmds.delete(straightCrv) for wireBase in wireBaseList: if cmds.objExists(wireBase): cmds.delete(wireBase) # ================= # - Return Result - # ================= if edgeList: cmds.hilite(mesh) cmds.select(edgeList) return edgeList
def straightenVerts(edgeList, falloff=0.01, influence=1.0, snapToOriginal=False, keepEdgeSpacing=False, deleteHistory=False): """ Straighten specified polygon vertices. @param influence: @param keepEdgeSpacing: @param edgeList: List of polygon edges to straighten. @type edgeList: list @param falloff: Falloff distance around selected vertices. @type falloff: float @param snapToOriginal: Snap vertices back to closest point on original mesh. @type snapToOriginal: bool @param deleteHistory: Delete construction history. @type deleteHistory: bool """ # Get Edge List edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or [] if not edgeList: raise Exception('Invalid or empty edge list! Unable to straighten vertices...') # Build Edge Curve from Vertices edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves(edgeList, keepHistory=False) straightCrvList = [] for edgeCrv in edgeCrvList: # Build Straight Curve straightCrv = cmds.rebuildCurve(edgeCrv, ch=False, rpo=False, rt=0, end=1, kr=False, kcp=False, kep=True, kt=False, s=1, d=1, tol=0)[0] # Rebuild Straight Curve dist = [] total = 0.0 params = [] pts = glTools.utils.base.getMPointArray(edgeCrv) max = cmds.getAttr(straightCrv + '.maxValue') if keepEdgeSpacing: for i in range(pts.length() - 1): d = (pts[i] - pts[i + 1]).length() dist.append(d) total += d for i in range(len(dist)): d = dist[i] / total * max if i: d += params[-1] params.append(d) else: params = glTools.utils.mathUtils.distributeValue(pts.length(), rangeEnd=max)[1:-1] params = [straightCrv + '.u[' + str(i) + ']' for i in params] cmds.insertKnotCurve(params, ch=False, numberOfKnots=1, add=True, ib=False, rpo=True) # Snap To Mesh mesh = cmds.ls(edgeList, o=True)[0] if snapToOriginal: pts = glTools.utils.component.getComponentStrList(straightCrv) glTools.utils.mesh.snapPtsToMesh(mesh, pts) # Append List straightCrvList.append(straightCrv) # ================= # - Deform Points - # ================= # Build Wire Deformer wire = glTools.utils.wire.createMulti(mesh, edgeCrvList, dropoffDist=falloff, prefix=mesh.split(':')[-1]) cmds.setAttr(wire[0] + '.rotation', 0) # Blend to Straight Curve for i in range(len(edgeCrvList)): blendShape = glTools.utils.blendShape.create(baseGeo=edgeCrvList[i], targetGeo=[straightCrvList[i]]) cmds.setAttr(blendShape + '.' + straightCrvList[i], influence) # ================== # - Delete History - # ================== if deleteHistory: wireBaseList = glTools.utils.wire.getWireBase(wire[0]) cmds.delete(mesh, ch=True) for edgeCrv in edgeCrvList: if cmds.objExists(edgeCrv): cmds.delete(edgeCrv) for straightCrv in straightCrvList: if cmds.objExists(straightCrv): cmds.delete(straightCrv) for wireBase in wireBaseList: if cmds.objExists(wireBase): cmds.delete(wireBase) # ================= # - Return Result - # ================= if edgeList: cmds.hilite(mesh) cmds.select(edgeList) return edgeList
def insertKnotCurve(*args, **kwargs): res = cmds.insertKnotCurve(*args, **kwargs) if not kwargs.get('query', kwargs.get('q', False)): res = _factories.maybeConvert(res, _general.PyNode) return res
def makeShape(self): if self.shape.lower() == 'square': ctrl = cmds.circle(r=1, s=4, ut=0, d=1, ch=0, sw=360, tol=0.01, n=self.ctrlName) cmds.xform(ctrl, ro=[0, 0, 45], t=self.pos) elif self.shape.lower() == 'diamond': ctrl = cmds.circle(r=1, s=4, ut=0, d=1, ch=0, sw=360, tol=0.01, n=self.ctrlName) cmds.xform(ctrl, t=self.pos) elif self.shape.lower() == 'plus': ctrl = cmds.circle(r=0.3, s=12, ut=0, d=1, ch=0, sw=360, tol=0.01, n=self.ctrlName) cmds.xform(ctrl, ro=[0, 0, 15], t=self.pos) cvs = [ '%s.cv[1]' % ctrl[0], '%s.cv[10]' % ctrl[0], '%s.cv[7]' % ctrl[0], '%s.cv[4]' % ctrl[0] ] cmds.scale( 0.361464, 0.361464, 0.361464, cvs, r=True, ) elif self.shape.lower() == 'star': ctrl = cmds.circle(r=0.3, s=8, ut=0, d=0, ch=0, sw=360, tol=0.01, n=self.ctrlName) cmds.xform(ctrl, t=self.pos) #shape star cvs = [ '%s.cv[0]' % ctrl[0], '%s.cv[2]' % ctrl[0], '%s.cv[4]' % ctrl[0], '%s.cv[6]' % ctrl[0] ] cmds.scale( 0.0876642, 0.0876642, 0.0876642, cvs, r=True, ) elif self.shape.lower() == 'cross': ctrl = cmds.nurbsSquare(c=[0, 0, 0], nr=[0, 1, 0], sl1=1, sl2=1, sps=1, d=3, ch=0, n=self.ctrlName) children = cmds.listRelatives(ctrl[0], c=True, pa=True) #move curves into place cmds.xform(children[0], t=[0, 0, -0.5]) cmds.xform(children[1], t=[0.5, 0, 0]) cmds.xform(children[2], t=[0, 0, 0.5], ro=[0, 0, 90]) #parent childrens shapes to top transform cmds.makeIdentity(ctrl, apply=True, t=1, r=1, s=1) cmds.parent(cmds.listRelatives(children[0], s=True, pa=True), cmds.listRelatives(children[1], s=True, pa=True), cmds.listRelatives(children[2], s=True, pa=True), ctrl[0], add=True, s=True) #clean up original transforms cmds.delete(children) #set position cmds.xform(ctrl, t=self.pos) elif self.shape.lower() == 'arch': ctrl = cmds.circle(r=1, s=4, ut=0, d=3, ch=0, sw=180, tol=0.01, n=self.ctrlName) cmds.xform(ctrl, ro=[0, 0, -90], t=self.pos) elif self.shape.lower() == 'pin': ctrl = cmds.circle(r=0.3, s=8, ut=0, d=3, ch=0, sw=359, tol=0.01, n=self.ctrlName) cmds.insertKnotCurve('%s.u[7.9]' % ctrl[0], ch=0, cos=True, nk=1, add=1, ib=0, rpo=1) cmds.xform('%s.cv[0:10]' % ctrl[0], t=[0, -2, 0], r=True) cmds.xform('%s.cv[11]' % ctrl[0], t=[0, -0.3, 0], r=True) cmds.xform(ctrl, ro=[0, 0, 180], s=[0.5, 0.5, 0.5], t=self.pos) elif self.shape.lower() == 'arrow': ctrl = cmds.curve(d=1, p=[(-0.5, 1, 0), (-0.5, 0, 0), (-1, 0, 0), (0, -1, 0), (1, 0, 0), (0.5, 0, 0.0), (0.5, 1, 0), (-0.5, 1, 0)], n=self.ctrlName) #ctrl = cmds.curve(d=1,p=[(-0.5,0,-1),(-0.5,0,0),(-1,0,0),(0,0,1),(1,0,0),(0.5,0,0.0),(0.5,0,-1),(-0.5,0,-1)],n=self.ctrlName) cmds.xform(ctrl, t=self.pos) ctrl = [ctrl] else: ctrl = cmds.circle(r=1, s=8, ut=0, d=0, ch=0, sw=360, tol=0.01, n=self.ctrlName) cmds.xform(ctrl, t=self.pos) return ctrl
def makeCord(): cordWeight = cmds.floatSliderButtonGrp('cordWeightGrp', q = True, v=True) randomWeightValue = cmds.floatSliderGrp('cordWeightRandomizeGrp', q=True, v=True) randomAttachValue = cmds.floatSliderGrp('cordWeightPointRandomization', q=True, v=True) curSel = cmds.ls(sl = 1, fl = 1) global recoverySel recoverySel = cmds.ls(sl = 1, fl = 1) curRange = range(len(cmds.ls(sl = 1, fl = 1))) ptList = [] curveCode = "" for item in curRange: print item randomAttachPointX = rand.uniform(-randomAttachValue, randomAttachValue) randomAttachPointY = rand.uniform(-randomAttachValue, randomAttachValue) randomAttachPointZ = rand.uniform(-randomAttachValue, randomAttachValue) exec("cmds.select('" + str(curSel[item]) + "', r = 1)") exec("pt_" + str(curRange[item]) + " = cmds.xform(q = 1, ws = 1, t = 1)") print "pt_" + str(curRange[item]) exec("print pt_" + str(curRange[item])) # exec("ptList.append(pt_" + str(curRange[item]) + ")") exec("tmp = " + "pt_" + str(curRange[item])) tmp = [(tmp[0] + randomAttachPointX), (tmp[1] + randomAttachPointY), (tmp[2] + randomAttachPointZ)] ptList.append(tmp) print ptList curveCode += "cmds.curve(d = 1, n = 'telephoneLine', p = (" for item in curRange: if (item != (1 - len(curRange))): curveCode += str(ptList[item]) + ", " else: curveCode += str(ptList[item]) curveCode += "))" exec(curveCode) #------ asd = .5 curSel2 = cmds.ls(sl = 1, fl = 1) while(asd < (len(curRange) - 1)): cmds.select(curSel2[0], r = 1) cmds.insertKnotCurve(p = (asd), nk=1, rpo = 1) #cmds.select(curSel2[0], r = 1) #cmds.insertKnotCurve(p = (asd + .495), nk=1, rpo = 1) #cmds.select(curSel2[0], r = 1) #cmds.insertKnotCurve(p = (asd + .505), nk=1, rpo = 1) asd += 1 asd = .5 counter = 1 while(asd < (len(curRange) - 1)): generatedRandomValue = rand.uniform(randomWeightValue*-1,randomWeightValue) # print generatedRandomValue exec("pt_before = cmds.xform('" + str(curSel2[0]) + ".cv[" + str(counter - 1) + "]', q = 1, t = 1)") exec("pt_after = cmds.xform('" + str(curSel2[0]) + ".cv[" + str(counter + 1) + "]', q = 1, t = 1)") distance = math.sqrt((pt_before[0]-pt_after[0])**2 + (pt_before[1]-pt_after[1])**2 + (pt_before[2]-pt_after[2])**2) exec("cmds.select('" + str(curSel2[0]) + ".cv[" + str(counter) + "]')") cmds.xform(r = 1, os = 1, t = [0,(distance * ((cordWeight + generatedRandomValue) * -1.00)),0]) cmds.xform asd += 1 counter += 2 asd = .5 cmds.select(curSel2[0], r = 1) while(asd < (len(curRange) - 1)): cmds.select(curSel2[0], r = 1) cmds.insertKnotCurve(p = (asd + .495), nk=1, rpo = 1) cmds.select(curSel2[0], r = 1) cmds.insertKnotCurve(p = (asd + .505), nk=1, rpo = 1) asd += 1 cmds.select(curSel2[0], r = 1) cmds.rebuildCurve(ch=1, rpo=1, rt=0, end=1, kr=1, kcp=1, kep=0, kt=0, s=4, d=3, tol=0.01) if(len(recoverySel) < 1): cmds.button('backUp',e = 1, en = 0) else: cmds.button('backUp',e = 1, en = 1)
def makeCord(): cordWeight = cmds.floatSliderButtonGrp('cordWeightGrp', q=True, v=True) randomWeightValue = cmds.floatSliderGrp('cordWeightRandomizeGrp', q=True, v=True) randomAttachValue = cmds.floatSliderGrp('cordWeightPointRandomization', q=True, v=True) curSel = cmds.ls(sl=1, fl=1) global recoverySel recoverySel = cmds.ls(sl=1, fl=1) curRange = range(len(cmds.ls(sl=1, fl=1))) ptList = [] curveCode = "" for item in curRange: print item randomAttachPointX = rand.uniform(-randomAttachValue, randomAttachValue) randomAttachPointY = rand.uniform(-randomAttachValue, randomAttachValue) randomAttachPointZ = rand.uniform(-randomAttachValue, randomAttachValue) exec("cmds.select('" + str(curSel[item]) + "', r = 1)") exec("pt_" + str(curRange[item]) + " = cmds.xform(q = 1, ws = 1, t = 1)") print "pt_" + str(curRange[item]) exec("print pt_" + str(curRange[item])) # exec("ptList.append(pt_" + str(curRange[item]) + ")") exec("tmp = " + "pt_" + str(curRange[item])) tmp = [(tmp[0] + randomAttachPointX), (tmp[1] + randomAttachPointY), (tmp[2] + randomAttachPointZ)] ptList.append(tmp) print ptList curveCode += "cmds.curve(d = 1, n = 'telephoneLine', p = (" for item in curRange: if (item != (1 - len(curRange))): curveCode += str(ptList[item]) + ", " else: curveCode += str(ptList[item]) curveCode += "))" exec(curveCode) #------ asd = .5 curSel2 = cmds.ls(sl=1, fl=1) while (asd < (len(curRange) - 1)): cmds.select(curSel2[0], r=1) cmds.insertKnotCurve(p=(asd), nk=1, rpo=1) #cmds.select(curSel2[0], r = 1) #cmds.insertKnotCurve(p = (asd + .495), nk=1, rpo = 1) #cmds.select(curSel2[0], r = 1) #cmds.insertKnotCurve(p = (asd + .505), nk=1, rpo = 1) asd += 1 asd = .5 counter = 1 while (asd < (len(curRange) - 1)): generatedRandomValue = rand.uniform(randomWeightValue * -1, randomWeightValue) # print generatedRandomValue exec("pt_before = cmds.xform('" + str(curSel2[0]) + ".cv[" + str(counter - 1) + "]', q = 1, t = 1)") exec("pt_after = cmds.xform('" + str(curSel2[0]) + ".cv[" + str(counter + 1) + "]', q = 1, t = 1)") distance = math.sqrt((pt_before[0] - pt_after[0])**2 + (pt_before[1] - pt_after[1])**2 + (pt_before[2] - pt_after[2])**2) exec("cmds.select('" + str(curSel2[0]) + ".cv[" + str(counter) + "]')") cmds.xform(r=1, os=1, t=[ 0, (distance * ((cordWeight + generatedRandomValue) * -1.00)), 0 ]) cmds.xform asd += 1 counter += 2 asd = .5 cmds.select(curSel2[0], r=1) while (asd < (len(curRange) - 1)): cmds.select(curSel2[0], r=1) cmds.insertKnotCurve(p=(asd + .495), nk=1, rpo=1) cmds.select(curSel2[0], r=1) cmds.insertKnotCurve(p=(asd + .505), nk=1, rpo=1) asd += 1 cmds.select(curSel2[0], r=1) cmds.rebuildCurve(ch=1, rpo=1, rt=0, end=1, kr=1, kcp=1, kep=0, kt=0, s=4, d=3, tol=0.01) if (len(recoverySel) < 1): cmds.button('backUp', e=1, en=0) else: cmds.button('backUp', e=1, en=1)
def sqGenerateCurves(self, *args): self.edgeList = cmds.ls(selection=True, flatten=True) if not self.edgeList == None and not self.edgeList == [] and not self.edgeList == "": self.baseCurve = cmds.polyToCurve(name="baseCurve", form=2, degree=1)[0] cmds.select(self.baseCurve + ".ep[*]") cmds.insertKnotCurve(cmds.ls(selection=True, flatten=True), constructionHistory=True, curveOnSurface=True, numberOfKnots=1, addKnots=False, insertBetween=True, replaceOriginal=True) pointListA, pointListB, sideA, sideB = self.sqGetPointLists() toDeleteList = [] p = 2 for k in range((sideA + 2), (sideB - 1)): if p % 2 == 0: toDeleteList.append(self.baseCurve + ".cv[" + str(k) + "]") toDeleteList.append(self.baseCurve + ".cv[" + str(k + len(pointListA) - 1) + "]") p = p + 1 q = 2 m = sideA - 2 if m >= 0: while m >= 0: if not m == sideA and not m == sideB: if q % 2 == 0: toDeleteList.append(self.baseCurve + ".cv[" + str(m) + "]") m = m - 1 q = q + 1 cmds.delete(toDeleteList) cmds.insertKnotCurve([ self.baseCurve + ".u[" + str(len(pointListA) - 1) + "]", self.baseCurve + ".ep[" + str(len(pointListA) - 1) + "]" ], constructionHistory=True, curveOnSurface=True, numberOfKnots=1, addKnots=False, insertBetween=True, replaceOriginal=True) pointListA, pointListB, sideA, sideB = self.sqGetPointLists() posListA, posListB = [], [] for i in range(0, len(pointListA) - 1): posListA.append( cmds.xform(pointListA[i], query=True, worldSpace=True, translation=True)) posListB.append( cmds.xform(pointListB[i], query=True, worldSpace=True, translation=True)) self.mainCurveA = cmds.curve(name="StickyLips_Main_A_Crv", degree=1, point=posListA) self.mainCurveB = cmds.curve(name="StickyLips_Main_B_Crv", degree=1, point=posListB) cmds.rename( cmds.listRelatives(self.mainCurveA, children=True, shapes=True)[0], self.mainCurveA + "Shape") cmds.rename( cmds.listRelatives(self.mainCurveB, children=True, shapes=True)[0], self.mainCurveB + "Shape") cmds.select(self.mainCurveA + ".cv[*]") self.curveLenght = len(cmds.ls(selection=True, flatten=True)) cmds.select(clear=True) self.sqCheckCurveDirection(self.mainCurveA) self.sqCheckCurveDirection(self.mainCurveB) self.baseCurveA = cmds.duplicate(self.mainCurveA, name=self.mainCurveA.replace( "_Main_", "_Base_"))[0] self.baseCurveB = cmds.duplicate(self.mainCurveB, name=self.mainCurveB.replace( "_Main_", "_Base_"))[0] cmds.delete(self.baseCurve) self.maxIter = len(posListA) cmds.group(self.mainCurveA, self.mainCurveB, self.baseCurveA, self.baseCurveB, name="StickyLips_StaticData_Grp") else: mel.eval("warning \"Please, select an closed edgeLoop.\";")