def buildNurbsRibbon(self):
		if self.guideSpline:
			guideDeg = cmds.getAttr(self.guideSpline + '.degree' )
			guideSpan = cmds.getAttr(self.guideSpline + '.spans' )
			oneCurvePoints = []
			otherCurvePoints = []
			for i in xrange(guideDeg + guideSpan):
				cvPos = cmds.pointPosition(self.guideSpline + '.cv[' + str(i) + "]", w=True )
				newPara = cmds.closestPointOnCurve(self.guideSpline, ip=cvPos, paramU=True)  #Find the parameter Value
				newParaVal = cmds.getAttr(newPara + ".paramU")
				cmds.delete(newPara)
				infoNode = cmds.pointOnCurve(self.guideSpline, ch=True, pr=newParaVal)  #Now find the Position and tangent!
				posy = (cmds.getAttr(infoNode + ".position"))[0]  # returns the position
				posy = MVector(posy[0],posy[1],posy[2])
				normy = (cmds.getAttr(infoNode + ".tangent"))[0]
				normy = MVector(normy[0],normy[1],normy[2]) #Use MVector from maya.openMaya
				normy = normy.normal()
				vertVect = MVector(0,1,0)
				sideMove = normy^vertVect #This is the notation for a cross product. Pretty cool. Should be a normal movement
				sideMove = sideMove.normal() * 0.5
				sideMovePos = posy + sideMove 
				otherSideMovePos = posy - sideMove
				oneCurvePoints.append([sideMovePos[0],sideMovePos[1],sideMovePos[2]])
				otherCurvePoints.append([otherSideMovePos[0],otherSideMovePos[1],otherSideMovePos[2]])

			oneSideCurve = cmds.curve(editPoint = oneCurvePoints, degree=3)
			OtherSideCurve = cmds.curve(editPoint = otherCurvePoints, degree=3)
			self.tempConstructionParts.append(oneSideCurve)
			self.tempConstructionParts.append(OtherSideCurve)
			#Now we loft the surface between the two Curves!
			nameStart = nameBase(self.totalMarkerList[0].getName(), self.searchString, "loc", "nbs")
			nameStart += "ribbonSurface"
			self.guideNurbsRibbon = cmds.loft(oneSideCurve, OtherSideCurve, name = nameStart, constructionHistory = True, uniform = True, close = False, autoReverse = True, degree = 3, sectionSpans = 1, range = False, polygon = 0, reverseSurfaceNormals = True)
			self.guideNurbsRibbon = self.guideNurbsRibbon[0]
			self.ribbonParts.append(self.guideNurbsRibbon)
Esempio n. 2
0
    def buildNurbsRibbon(self):
        if self.guideSpline:
            guideDeg = cmds.getAttr(self.guideSpline + '.degree')
            guideSpan = cmds.getAttr(self.guideSpline + '.spans')
            oneCurvePoints = []
            otherCurvePoints = []
            for i in xrange(guideDeg + guideSpan):
                cvPos = cmds.pointPosition(self.guideSpline + '.cv[' + str(i) +
                                           "]",
                                           w=True)
                newPara = cmds.closestPointOnCurve(
                    self.guideSpline, ip=cvPos,
                    paramU=True)  #Find the parameter Value
                newParaVal = cmds.getAttr(newPara + ".paramU")
                cmds.delete(newPara)
                infoNode = cmds.pointOnCurve(
                    self.guideSpline, ch=True,
                    pr=newParaVal)  #Now find the Position and tangent!
                posy = (cmds.getAttr(infoNode +
                                     ".position"))[0]  # returns the position
                posy = MVector(posy[0], posy[1], posy[2])
                normy = (cmds.getAttr(infoNode + ".tangent"))[0]
                normy = MVector(normy[0], normy[1],
                                normy[2])  #Use MVector from maya.openMaya
                normy = normy.normal()
                vertVect = MVector(0, 1, 0)
                sideMove = normy ^ vertVect  #This is the notation for a cross product. Pretty cool. Should be a normal movement
                sideMove = sideMove.normal() * 0.5
                sideMovePos = posy + sideMove
                otherSideMovePos = posy - sideMove
                oneCurvePoints.append(
                    [sideMovePos[0], sideMovePos[1], sideMovePos[2]])
                otherCurvePoints.append([
                    otherSideMovePos[0], otherSideMovePos[1],
                    otherSideMovePos[2]
                ])

            oneSideCurve = cmds.curve(editPoint=oneCurvePoints, degree=3)
            OtherSideCurve = cmds.curve(editPoint=otherCurvePoints, degree=3)
            self.tempConstructionParts.append(oneSideCurve)
            self.tempConstructionParts.append(OtherSideCurve)
            #Now we loft the surface between the two Curves!
            nameStart = nameBase(self.totalMarkerList[0].getName(),
                                 self.searchString, "loc", "nbs")
            nameStart += "ribbonSurface"
            self.guideNurbsRibbon = cmds.loft(oneSideCurve,
                                              OtherSideCurve,
                                              name=nameStart,
                                              constructionHistory=True,
                                              uniform=True,
                                              close=False,
                                              autoReverse=True,
                                              degree=3,
                                              sectionSpans=1,
                                              range=False,
                                              polygon=0,
                                              reverseSurfaceNormals=True)
            self.guideNurbsRibbon = self.guideNurbsRibbon[0]
            self.ribbonParts.append(self.guideNurbsRibbon)
Esempio n. 3
0
def averageNormals(normalLs, normalise):
    """Return the average vector of a list of MVectors
	If normalise is true, return the normalised vector (length 1)
	"""

    sumX = sumY = sumZ = 0
    count = len(normalLs)
    for normal in normalLs:
        sumX += normal.x
        sumY += normal.y
        sumZ += normal.z
    avg = MVector(sumX / count, sumY / count, sumZ / count)

    if normalise:
        avg = avg.normal()

    return avg