Exemple #1
0
    def createCurve_circleFourArrows(self, name=""):
        """
        Creates a nurbs curve in the shape of a circle with four arrows
        
        Args:

        Returns:
        
        """
        startCurve1 = cmds.curve(d=3,
                                 p=[(-0.448148, 0, -0.137417),
                                    (-0.425577, 0, -0.210319),
                                    (-0.345762, 0, -0.345408),
                                    (-0.210765, 0, -0.425313),
                                    (-0.138183, 0, -0.447335)],
                                 k=[0, 0, 0, 1, 2, 2, 2])
        startCurve2 = cmds.curve(d=1,
                                 p=[(-0.138183, 0, -0.447335),
                                    (-0.138183, 0, -0.552734),
                                    (-0.276367, 0, -0.552734),
                                    (0, 0, -0.829101),
                                    (0.276367, 0, -0.552734),
                                    (0.138183, 0, -0.552734),
                                    (0.138183, 0, -0.447335)],
                                 k=[0, 1, 2, 3, 4, 5, 6])
        curve1 = cmds.attachCurve(startCurve1,
                                  startCurve2,
                                  replaceOriginal=0,
                                  kmk=1,
                                  ch=0)
        cmds.delete(startCurve1, startCurve2)
        curve2 = cmds.duplicate(curve1)
        cmds.rotate(0, 90, 0, curve1)
        curve3 = cmds.duplicate(curve1)
        cmds.rotate(0, 180, 0, curve3)
        curve4 = cmds.duplicate(curve1)
        cmds.rotate(0, 270, 0, curve4)
        attachCurve1 = cmds.attachCurve(curve1,
                                        curve2,
                                        replaceOriginal=0,
                                        kmk=1,
                                        ch=0)
        attachCurve2 = cmds.attachCurve(curve3,
                                        curve4,
                                        replaceOriginal=0,
                                        kmk=1,
                                        ch=0)
        cmds.delete(curve1, curve2, curve3, curve4)
        attachCurve2 = cmds.reverseCurve(attachCurve2[0], ch=0, rpo=1)
        newCurve = cmds.attachCurve(attachCurve1[0],
                                    attachCurve2[0],
                                    replaceOriginal=0,
                                    kmk=1,
                                    ch=0)
        cmds.delete(attachCurve1[0], attachCurve2[0])
        cmds.makeIdentity(newCurve, apply=1, t=1, r=1, s=1, n=0)
        ret = cmds.rename(newCurve, name)
        return ret
Exemple #2
0
def superCurveCutter():
    tolerance = 0.01
    killList = []
    curveDict = {}
    origCurves = cmd.ls(sl=True)

    mel.eval('cutCurvePreset(1,0,0.01,2,0,0,1,2,1)')
    for i in cmd.ls(sl=True, type='transform'):
        cmd.rename(i, 'cutCurve#')
    newCurves = cmd.ls(sl=True, type='transform')

    for one in newCurves:
        curveShape = cmd.listRelatives(one, type='nurbsCurve')[0]
        cvs = cmd.getAttr('%s.spans' % curveShape) + 2
        pos0 = cmds.pointPosition('%s.cv[0]' % curveShape, world=True)
        pos1 = cmds.pointPosition('%s.cv[%d]' % (curveShape, cvs), world=True)
        curveDict[one] = [pos0, pos1]

    for curve in curveDict.keys():
        compare = []
        for k, v in curveDict.items():
            if curve is k:
                continue
            compare.append(v)
        if isIsolated(curveDict[curve], compare) is True:
            killList.append(curve)

    keep = [x for x in newCurves if x not in killList]
    newShape = cmd.attachCurve(keep, ch=1, rpo=0, kmk=1, m=0, name='shape')
    cmd.delete(newCurves)
Exemple #3
0
def generateSpider(input_namespace, startTime, endTime):
    '''
	this function attaches all curves together, without replacing the orignal curves, using it as a motion path
	for an animated spider. the animated spider is imported, and a simple expression links the U value of the motion
	path to a rotation attribute on the spider rig, controlling its walk cycle. there is also a custom attribute on
	the controller that appears with the spider rig, controlling the length of its steps as it walks.
	'''
    filePath = cmds.internalVar(
        usd=True
    ) + 'SpiderGen/spider.ma'  #the file path at which the spider model should exist
    fileExists = cmds.file(filePath, q=True,
                           ex=True)  #queries whether the file exists

    if fileExists is True:
        #selects all of the spiralling curves and connects them, providing a 'path' for the spiders movement.
        cmds.select(str(input_namespace) + 'curve_spiral*')
        curves = cmds.ls(selection=True)
        path = cmds.attachCurve(curves,
                                n=str(input_namespace) + 'spiderpath',
                                rpo=False)
        cmds.rebuildCurve(path, rt=3)
        cmds.hide(path)
        cmds.file(filePath, i=True)

        #renames the spider and it's callable controllers so that they are using the current 'namespace'.
        cmds.rename('SPIDER_RIG', str(input_namespace) + 'SPIDER_RIG')
        cmds.rename('SCALE_HANDLE',
                    str(input_namespace) + 'CONTROLLER_ScaleMe')
        cmds.rename('CONTROLLER', str(input_namespace) + 'CONTROLLER')

        #selects the scale controller and the path and connects them to a path animation.
        cmds.select(str(input_namespace) + 'CONTROLLER_ScaleMe', path)
        cmds.pathAnimation(stu=startTime,
                           etu=endTime,
                           f=True,
                           fa='x',
                           ua='y',
                           name=str(input_namespace) + 'motionpath')

        #creates a command that links the controller rotation to the 'length' of the animation.
        command = str(input_namespace) + 'CONTROLLER.rotateX = ' + str(
            input_namespace) + 'motionpath_uValue.output * ' + str(
                (endTime - startTime) / 10)
        #creates an expression of that command which is used for moving the legs as the spider moves around the path.
        cmds.expression(name=str(input_namespace) + 'leg_movement',
                        alwaysEvaluate=True,
                        s=command)
    else:
        #an error window for if the file is not found
        cmds.confirmDialog(
            title='Error',
            message='Spider Model not found, please ensure it located at: ' +
            str(filePath),
            button=['OK'],
            cancelButton='OK')

    return fileExists  #so that the grouping functions know not to expect the spider model or motionpath
def generateSpider(input_namespace, startTime, endTime):
    '''
	this function attaches all curves together, without replacing the orignal curves, using it as a motion path
	for an animated spider. the animated spider is imported, and a simple expression links the U value of the motion
	path to a rotation attribute on the spider rig, controlling its walk cycle. there is also a custom attribute on
	the controller that appears with the spider rig, controlling the length of its steps as it walks.
	'''
    filePath = cmds.internalVar(usd=True) + 'SpiderGen/spider.ma'
    fileExists = cmds.file(filePath, q=True, ex=True)

    if fileExists is True:
        cmds.select(str(input_namespace) + 'curve_spiral*')
        curves = cmds.ls(selection=True)
        path = cmds.attachCurve(curves,
                                n=str(input_namespace) + 'spiderpath',
                                rpo=False)
        cmds.rebuildCurve(path, rt=3)
        cmds.hide(path)
        cmds.file(filePath, i=True)

        cmds.rename('SPIDER_RIG', str(input_namespace) + 'SPIDER_RIG')
        cmds.rename('SCALE_HANDLE',
                    str(input_namespace) + 'CONTROLLER_ScaleMe')
        cmds.rename('CONTROLLER', str(input_namespace) + 'CONTROLLER')

        cmds.select(str(input_namespace) + 'CONTROLLER_ScaleMe', path)
        cmds.pathAnimation(stu=startTime,
                           etu=endTime,
                           f=True,
                           fa='x',
                           ua='y',
                           name=str(input_namespace) + 'motionpath')

        command = str(input_namespace) + 'CONTROLLER.rotateX = ' + str(
            input_namespace) + 'motionpath_uValue.output * ' + str(
                (endTime - startTime) / 10)

        cmds.expression(name=str(input_namespace) + 'leg_movement',
                        alwaysEvaluate=True,
                        s=command)
    else:
        cmds.confirmDialog(
            title='Error',
            message='Spider Model not found, please ensure it located at: ' +
            str(filePath),
            button=['OK'],
            cancelButton='OK')

    return fileExists
def buildEdgeCurve():
	global sortedList
	global newEdgeCurve
	global spacerNode
	#Create a curve that fits the selected edges
	crvGarbageCollect = []
	for edgCrv in sortedList:
		curveAttach = mc.duplicateCurve(edgCrv, ch=True, rn=0, local=0, n=("edgeCurve"))
		crvGarbageCollect.append(curveAttach[0])
	newEdgeCurve = mc.attachCurve(crvGarbageCollect, ch=False, rpo=False, kmk = 1, m = 0, n= 'bigEdgeCurve', bb = 0.5, bki = 0, p=0.1)
	mc.rebuildCurve(newEdgeCurve, ch=False, rpo=True, rt=0, end=1, kr=0, kcp=0, kep=1, kt=0, s=400, d=1, tol=0.01)
	#Rebuild is mandatory otherwise the EP joints are too unevenly spaced, this helps to correct the problem. Uneven EP's result in poor placement of the locators for snapping.
	mc.delete(crvGarbageCollect) # A bit of tidyness
	bigCrvShp =  mc.ls(newEdgeCurve, s=True, dag=True)
	spacerNode = mc.shadingNode('pointOnCurveInfo',au=True,  n='spacerCurveInfo')
	mc.setAttr(spacerNode + '.turnOnPercentage', 1)
	mc.connectAttr(bigCrvShp[0] + '.worldSpace[0]', spacerNode + '.inputCurve')
Exemple #6
0
def createCurve(edgeList,
                rebuild=True,
                spans=4):
    """
    Create a fine curve from selection
    :param edgeList: list(str), flattened edge list to created new curve.
    :param rebuild: bool, whether rebuild the created line or not.
    :param spans: int, if rebuild the created line, spans of the rebuilded curve.
    :return: str, new curve.
    """
    # check the edge list
    for i in edgeList:
        if getComponentType(i) != 'e':
            cmds.error('Please select edges')
            return

    # create each line
    curves = []
    if edgeList and len(edgeList) >= 2:
        for crv in edgeList:
            curve = cmds.polyToCurve(crv, form=0, degree=1, ch=0)[0]
            curves.append(curve)

    else:
        cmds.error('Please select at least 2 lines!')
        return
    # attach each line and clean the trash lines
    outputCurve = []
    if curves:
        outputCurve = cmds.attachCurve(curves[:], ch=0, method=0, kmk=0)

    trashGrp = cmds.group(em=1)
    for i in xrange(len(outputCurve) - 1):
        cmds.parent(outputCurve[i+1], trashGrp)

    cmds.delete(trashGrp)

    # if needed, rebuild the attached line
    finalCurve = None

    if rebuild and spans:
        finalCurve = cmds.rebuildCurve(outputCurve[0], ch=0, degree=3, spans=spans, end=1, rebuildType=0)
    else:
        finalCurve = outputCurve[0]

    return finalCurve
Exemple #7
0
def curve_from_edge():
    '''
    creates a curve from the selected edges
    Need to select the edges individually in the order that makes up the curve for attach curve to work
    it's crude, but it does what I need it to do 
    
    This is dodgy and doesn't always work....need to re-write
    '''
    edges = cmds.ls(sl=True)
    curves = list()

    for edge in edges:
        crv = cmds.duplicateCurve(edge)
        curves.append(crv[0])

    new_curve = cmds.attachCurve(curves,
                                 ch=1,
                                 rpo=0,
                                 kmk=1,
                                 m=1,
                                 bb=0.5,
                                 bki=0,
                                 p=0.1)
    cmds.delete(curves)
    cmds.rebuildCurve(new_curve[0],
                      ch=1,
                      rpo=1,
                      rt=0,
                      end=1,
                      kr=0,
                      kcp=1,
                      kep=1,
                      kt=0,
                      s=4,
                      d=3,
                      tol=0.01)

    return new_curve
def createCircle1Arrowhead	():
	_controlled			=	cmds.ls		(	long	=	True,	selection	=	True	)
	_curveList			=	[]
	_control			=	cmds.circle (	normal	=	(	1,	0,	0	),	radius	=	2,	sweep	=	300,
											constructionHistory	=	False	)
	_curveList.append					(	_control[0]	)
	_control			=	cmds.circle	(	normal	=	(	1,	0,	0	),	radius	=	3,	sweep	=	300,
											constructionHistory =	False	)
	_curveList.append					(	_control[0]	)
	_control 			=	cmds.curve	(	degree	=	1,	point	=	[(0,3,0),(0,3.5,0),(0,2.5,-2),(0,1.5,0),(0,2,0)]	)
	_curveList.append					(	_control	)
	_control = cmds.curve				(	degree	=	1,	point	=	[(0,1.5,-2.598076),(0,1,-1.732051)]	)
	_curveList.append					(	_control )

	for	_k	in	_curveList:		cmds.select	(	_k,	add	=	True	)
	_control			=	cmds.attachCurve	()

	for	_k	in	_curveList:		cmds.select	(	_k,	add	=	True	)

	cmds.select		(	_control[0],	deselect	=	True	)
	cmds.delete		()
	cmds.select		(	_control[0]	)
	
	postProcessControl				(	_control[0],	'rotate',	_controlled	)
Exemple #9
0
def create_fibonacci_curve(camera, panel, iterations, points_per_section):
    """Creates a Fibonacci curve.

    Args:
        iterations (int): number of quarter circles in the created curve
        points_per_section (int): number of segment per quarter of circle

    Returns:
        str: curve maya node
    """
    old_sel = mc.ls(selection=True)
    fibonacci_grp = camera + '_fibonacci'
    # ratio = mc.camera(camera, aspectRatio=True, query=True)
    ratio = (1 + math.sqrt(5)) * 0.5

    all_curves = []

    fib_gen = gen_fib_points(ratio)

    # Create the quarter of circles
    for _ in range(iterations):
        start_point, center_point, end_point = next(fib_gen)
        radius = math.sqrt((start_point[0] - center_point[0])**2 +
                           (start_point[1] - center_point[1])**2)

        ctx = mc.createNode("makeTwoPointCircularArc")
        mc.setAttr(ctx + ".pt1",
                   start_point[0],
                   0,
                   start_point[1],
                   type='double3')
        mc.setAttr(ctx + ".pt2", end_point[0], 0, end_point[1], type='double3')
        mc.setAttr(ctx + ".directionVector", 0, 1, 0, type='double3')
        mc.setAttr(ctx + ".radius", radius)
        mc.setAttr(ctx + ".sections", points_per_section)

        curve = mc.createNode("nurbsCurve")
        all_curves.append(curve)
        mc.connectAttr(ctx + ".outputCurve", curve + ".create")

        mc.delete(curve, constructionHistory=True)

    # Attach all curves
    mc.attachCurve(all_curves,
                   constructionHistory=False,
                   replaceOriginal=True,
                   keepMultipleKnots=False,
                   method=0,
                   blendBias=0.5,
                   blendKnotInsertion=False,
                   parameter=0.1)
    mc.delete(mc.listRelatives(all_curves[1:], parent=True))
    fibonacci_crv = mc.rename(mc.listRelatives(all_curves[0], parent=True),
                              'fibonacci')

    matrix_cam = mc.xform(camera, worldSpace=True, matrix=True, query=True)
    mc.xform(fibonacci_grp, worldSpace=True, matrix=matrix_cam)
    mc.makeIdentity(fibonacci_grp, apply=True, t=1, r=0, s=1, n=0)

    # Test

    mc.parent(fibonacci_crv, fibonacci_grp)
    mc.setAttr(fibonacci_grp + '.rx', -90)
    mc.setAttr(fibonacci_crv + '.tx', -0.5)
    mc.setAttr(fibonacci_crv + '.tz', -0.5)

    create_camera_node(camera, fibonacci_crv)

    isolate_transform = []
    if mc.listRelatives(mc.ls(type='mesh'), path=True, parent=True):
        isolate_transform = mc.listRelatives(mc.ls(type='mesh'),
                                             path=True,
                                             parent=True)

    isolate_transform.append(fibonacci_grp)
    mc.select(isolate_transform)

    currentState = mc.isolateSelect(panel, query=True, state=True)
    if currentState == 1:
        mc.isolateSelect(panel, state=0)
        mc.isolateSelect(panel, removeSelected=True)
        mc.isolateSelect(panel, state=1)
        mc.isolateSelect(panel, addSelected=True)
        mc.select(old_sel, r=True)
    else:
        mc.isolateSelect(panel, state=1)
        mc.isolateSelect(panel, addSelected=True)
        mc.select(old_sel, r=True)
# #############################################################################
def createSphere ():
	_controlled			=	cmds.ls	(	long	=	True,	selection	=	True	)
	_curveList			=	[]
	# create arcs
	_arc				=	cmds.createNode		(	'makeTwoPointCircularArc'	)
	cmds.setAttr		(	_arc	+	'.pt1',	0,	3,	0	)
	cmds.setAttr		(	_arc	+	'.pt2',	-3,	0,	0	)
	cmds.setAttr		(	_arc	+	'.dv',	0,	0,	1	)
	cmds.setAttr		(	_arc	+	'.radius',	3	)
	_curve				=	cmds.createNode		(	'nurbsCurve'	)
	_curve				=	cmds.listRelatives	(	_curve,	parent	=	True	)
	_curveList.append	(	_curve	)
	cmds.connectAttr	(	_arc	+	'.oc',	_curve[0]	+	'.cr'	)
	#
	_arc				=	cmds.createNode	(	'makeTwoPointCircularArc'	)
	cmds.setAttr		(	_arc	+	'.pt1',	3,	0,	0	)
	cmds.setAttr		(	_arc	+	'.pt2', 0, 3, 0 )
	cmds.setAttr		(	_arc	+	'.dv', 0, 0, 1 )
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append 	(	_curve )
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', -3, 0, 0 )
	cmds.setAttr		(	_arc	+	'.pt2', 0, -3, 0 )
	cmds.setAttr		(	_arc	+	'.dv', 0, 0, 1 )
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve	)
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 0, -3, 0 )
	cmds.setAttr		(	_arc	+	'.pt2', 3, 0, 0 )
	cmds.setAttr		(	_arc	+	'.dv', 0, 0, 1 )
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve	)
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 0,3,0 )
	cmds.setAttr		(	_arc	+	'.pt2', 0,0,3 )
	cmds.setAttr		(	_arc	+	'.dv', 1,0,0 )
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve )
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 0,0,-3)
	cmds.setAttr		(	_arc	+	'.pt2', 0,3,0)
	cmds.setAttr		(	_arc	+	'.dv', 1,0,0 )
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve	)
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 0,-3,0)
	cmds.setAttr		(	_arc	+	'.pt2', 0,0,-3)
	cmds.setAttr		(	_arc	+	'.dv', 1,0,0)
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve	)
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 0,0,3)
	cmds.setAttr		(	_arc	+	'.pt2', 0,-3,0)
	cmds.setAttr		(	_arc	+	'.dv', 1,0,0)
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve	)
	cmds.connectAttr	( _arc + '.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 0,0,-3)
	cmds.setAttr		(	_arc	+	'.pt2', -3,0,0)
	cmds.setAttr		(	_arc	+	'.dv', 0,1,0)
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve	)
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 3,0,0)
	cmds.setAttr		(	_arc	+	'.pt2', 0,0,-3)
	cmds.setAttr		(	_arc	+	'.dv', 0,1,0)
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve )
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', 0,0,3)
	cmds.setAttr		(	_arc	+	'.pt2', 3,0,0)
	cmds.setAttr		(	_arc	+	'.dv', 0,1,0)
	cmds.setAttr		(	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve	)
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )
	#
	_arc				=	cmds.createNode	( 'makeTwoPointCircularArc' )
	cmds.setAttr		(	_arc	+	'.pt1', -3,0,0)
	cmds.setAttr		(	_arc	+	'.pt2', 0,0,3)
	cmds.setAttr		( 	_arc	+	'.dv', 0,1,0)
	cmds.setAttr		( 	_arc	+	'.radius', 3 )
	_curve				=	cmds.createNode	( 'nurbsCurve' )
	_curve				=	cmds.listRelatives	( _curve, parent = True )
	_curveList.append	(	_curve )
	cmds.connectAttr	(	_arc	+	'.oc', _curve[0] + '.cr' )

	cmds.select			(	clear	=	True	)
	for	_c	in	range	(	len	(	_curveList	)	-1	):
		cmds.select		(	_curveList[_c],	toggle	=	True	)

	cmds.delete			( 	constructionHistory	=	True	)
	cmds.attachCurve	(	constructionHistory	=	False,	replaceOriginal	=	True,	keepMultipleKnots	=	True,
							method	=	0,	blendKnotInsertion	=	False,	parameter	=	0.1	)
	cmds.delete			( 	constructionHistory	=	True	)
	cmds.select			(	_curveList[0],	_curveList[11],	replace	=	True	)

	cmds.delete			( 	constructionHistory	=	True	)
	cmds.attachCurve	(	constructionHistory	=	False,	replaceOriginal	=	True,	keepMultipleKnots	=	True,
							method	=	0,	blendBias	=	0.5,	blendKnotInsertion	=	False,	parameter	=	0.1	)
	cmds.delete			( 	constructionHistory	=	True	)
	cmds.select			(	_curveList[0],	replace	=	True	)
	
	_control			=	cmds.rename	(	_curveList[0],	'_rotation_control'	)

	for	_c	in	range	(	len	(	_curveList	)	-1	):
		cmds.select	(	_curveList[_c+1],	replace	=	True	)
		cmds.delete	()

	cmds.select			(	_control	)

	postProcessControl	(	_control,	'rotate',	_controlled	)
Exemple #12
0
def attachCurve(*args, **kwargs):
    res = cmds.attachCurve(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
Exemple #13
0

"""
    Build left hair section
"""

#Start with template curve
leftStrand = cmds.curve(p=[(-1,0,-0.125),(-0.9375,-0.0875,-0.1875),(-0.84375,-0.06375,-0.26),(-0.7578125,-0.0053125,-0.275),(-0.6875,0.0425,-0.26),(-0.625,0.06375,-0.234375),(-0.5625,0.0425,-0.1875),(-0.5,0,-0.125),(-0.4375,-0.0875221,-0.0625),(-0.375,-0.06375,-0.015625),(-0.3125,-0.0425,0),(-0.2421875,0.0053125,0),(-0.15625,0.06375,0),(-0.0625,0.0425,-0.0625),(0,0,-0.125),(0.0625,-0.08752214296547417,-0.1875),(0.15625,-0.06375,-0.26),(0.2421875,-0.0053125,-0.275),(0.3125,0.0425,-0.26),(0.375,0.06375,-0.234375),(0.4375,0.0425,-0.1875),(0.5,0,-0.125),(0.5625,-0.0875221,-0.0625),(0.625,-0.06375,-0.015625),(0.6875,-0.0425,0),(0.7578125,0.0053125,0),(0.84375,0.06375,0),(0.9375,0.0425,-0.0625),(1,0,-0.125)], k=[0,0,0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12,12], name='leftStrand')
lsTemplate = cmds.duplicate('leftStrand', name='lsTemplate')

#Append length if necessary
cutbottom = 12 #Curve point at which to detach curve
for i in xrange(0, append):
    toAppend = cmds.duplicate('lsTemplate', name='leftStrand2')
    cmds.move(2*(i+1),0,0,'leftStrand2', relative=True)
    cmds.attachCurve('leftStrand', 'leftStrand2')
    cmds.delete('leftStrand2')
    cutbottom = 12*(i+2) - 6*(i+1)

#Cut bottom of curve
cmds.detachCurve('leftStrand.u['+str(cutbottom)+']', k=(1,0), replaceOriginal=True)
cmds.delete('leftStranddetachedCurve2')

#Position strand upright, set color to red
cmds.rotate(0, 0, -90, leftStrand)
cmds.move(-0.0072805614748225056, 0.62530322953737649, 0.12630761389650735, leftStrand, relative=True)
cmds.setAttr(leftStrand+'.overrideEnabled', 1)
cmds.setAttr(leftStrand+'.overrideColor', 4)

#Duplicate curves concentrically around template
r = radius
Exemple #14
0
	def _create(self):
	    mi_base = self.mi_baseCurve
	    mi_target = self.mi_targetCurve
	    
	    self.l_baseCvPos = []
	    self.d_base = self.getCurveMirrorData(mi_base)
	    
	    if not mi_target:#if no target, mirror self
		if not self.d_base['b_oneSided']:
		    if self.d_base['b_even']:
			log.info("%s Even mirror"%self._str_reportStart)			
			l_cvPos = self.d_base['l_cvPos']
			l_cvs = self.d_base['l_cvs']			
			int_split = int(len(l_cvPos)/2)
			log.info(int_split)
			l_splitDriven = l_cvs[int_split:]
			l_splitDriver = l_cvs[:int_split]
			l_splitDriverPos = l_cvPos[:int_split]			
			l_splitDriverPos.reverse()
			log.info("%s l_splitDriven: %s"%(self._str_reportStart,l_splitDriven))
			log.info("%s l_splitDriver: %s"%(self._str_reportStart,l_splitDriver))			
			for i,cv in enumerate(l_splitDriven):
			    pos = l_splitDriverPos[i]
			    mc.move(-pos[0],pos[1],pos[2], cv, ws=True)
			return True
		    else:
			log.info("%s nonEven mirror"%self._str_reportStart)			
			l_cvPos = self.d_base['l_cvPos']
			l_cvs = self.d_base['l_cvs']			
			int_split = int(len(l_cvPos)/2)
			l_cvPos.pop(int_split)
			l_cvs.pop(int_split)
			l_splitDriven = l_cvs[int_split:]
			l_splitDriver = l_cvs[:int_split]
			l_splitDriverPos = l_cvPos[:int_split]			
			l_splitDriverPos.reverse()
			log.info("%s l_splitDriven: %s"%(self._str_reportStart,l_splitDriven))
			log.info("%s l_splitDriver: %s"%(self._str_reportStart,l_splitDriver))			
			for i,cv in enumerate(l_splitDriven):
			    pos = l_splitDriverPos[i]
			    mc.move(-pos[0],pos[1],pos[2], cv, ws=True)
			return True		
		else:#it's one sided
		    log.info("%s Build other side. New crv"%self._str_reportStart)
		    l_epPos = self.d_base['l_epPos']
		    l_otherSide = copy.copy(l_epPos)
		    l_otherSide.reverse()
		    for i,pos in enumerate(l_otherSide):
			l_otherSide[i] = [-pos[0],pos[1],pos[2]]
			
		    #l_newCurvePos = l_epPos + l_otherSide
		    l_newCurvePos = l_otherSide
		    l_newCurvePos = lists.returnListNoDuplicates(l_newCurvePos)
		    
		    self.mi_created = cgmMeta.cgmObject( mc.curve(d=2,p=l_newCurvePos,os = True) )
		    self.mi_created.rename( mi_base.p_nameBase + '_mirrored')
		    
		    #
		    if self.d_base['b_startInThreshold'] or self.d_base['b_endInThreshold']:
			#In this case we need to combine and rebuild the curve
			try:
			    str_attachedCurves  = mc.attachCurve([self.mi_created.mNode,self.mi_baseCurve.mNode],
			                                         blendBias = self.d_kws['blendBias'])
			except Exception,error:raise StandardError,"Attach curve | %s"%error
			#mc.delete(self.mi_created.mNode)#delete the old one
			#self.mi_created = cgmMeta.cgmObject(str_attachedCurves[0])
			#int_spans = (len(l_epPos)*1.5)
			int_spans = len(l_epPos)+1			
			try:
			    mc.rebuildCurve (self.mi_created.mNode, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=1, kt=0, s=int_spans, d=3, tol=0.001)
			except Exception,error:raise StandardError,"Rebuild curve | %s"%error
			try:
			    mc.reverseCurve (self.mi_created.mNode, rpo=1)
			except Exception,error:raise StandardError,"Reverse curve | %s"%error			
		    self.mi_created.rename( mi_base.p_nameBase + '_mirrored')
		    return self.mi_created.p_nameShort
		    
		#See if we need to make new curve to have stuff to mirror
	    else:#if we have a target
		self.d_target = self.getCurveMirrorData(mi_target)
		l_cvsBase = self.d_base['l_cvs']			
		l_cvsTarget = self.d_target['l_cvs']
		if len(l_cvsBase) != len(l_cvsTarget):
		    raise NotImplementedError,"Haven't added ability to do curves of differing cv lengths yet"
		for i,pos in enumerate(self.d_base['l_cvPos']):
		    mc.move(-pos[0],pos[1],pos[2], l_cvsTarget[i], ws=True)
		    
		return True