예제 #1
0
def twistedCurves() :
import pymel.core as pm
import sys
import random
import math

if not 'Z:/ve/home/ArakawaT/maya/python' in sys.path :
    sys.path.append('Z:/ve/home/ArakawaT/maya/python')

import mayawrap as mw

pm.select(hi=True)
obj = pm.selected(type='mesh')[0]

curvenum = 5.0
curvespan = 30.0
dumax = 5
circlemin = 0.02
circlemax = 0.1

extrude = True

print(obj.name())
print(obj.numFaces())

curves = []
for i in range(curvenum) :
    print('curve %d/%d' % (i+1,curvenum))
    dv = 1.0/curvespan
    u = random.uniform(0.0,1.0)
    cpoints = []
    for i in range(curvespan+1) :
        u = math.fmod(u+random.uniform(0, (dumax/curvespan)*2.0),1)
        #print(u,i*dv)
        faceiter = obj.faces
        for f in faceiter :
            try :
                p = f.getPointAtUV((u, i*dv), space='world')
                #print(p)
                cpoints.append(p)
                break
            except :
                pass
    curve = pm.curve(p=cpoints, d=3)
    curves.append(curve)
    if extrude :
        circle = pm.circle()[0]
        randscale = random.uniform(circlemin, circlemax)
        pm.xform(circle, scale=(randscale,randscale,randscale))
        pm.xform(circle, translation=cpoints[0])
        pm.extrude(circle, curve, ch=True, rn=False, po=0, et=2, ucp=0, fpt=True, upn=True, rotation=0, scale=1, rsp=True)
    print(cpoints)
pm.select(curves)
예제 #2
0
def makeOpenSurf(crv, mesh, name):
    """New method for making the surface for OPEN curves
    make profile curve with 1/4 length of path curve
    extrude profile along path with tube method"""

    crv.cv[0].getPosition()
    pos = crv.cv[0].getPosition()
    # get vector for profile curve for extrusion along path
    norm = mesh.getClosestNormal(pos, "world")[0]
    tan = crv.tangent(0)
    profVec = norm.cross(tan)
    profVec.normalize()
    profVec *= (crv.length() / 8.0)

    profCrv = pmc.curve(d=3,
                        p=(-profVec, -(profVec / 3), (profVec / 3), profVec))
    # for extrude's "component pivot" mode
    profCrv.setTranslation(pos, ws=True)
    surf = pmc.extrude(profCrv,
                       crv,
                       extrudeType=2,
                       fixedPath=True,
                       n=name,
                       rsp=1,
                       useProfileNormal=True,
                       useComponentPivot=1,
                       ch=0)[0]
    pmc.delete(profCrv)

    return surf
예제 #3
0
def strokePath(node, radius=.1):
    """
    Create a nurbs surface from a curve control
    """
    curveNodes = separateShapes(node)
    for curveNode in curveNodes:
        shape = curveNode.listRelatives(type='nurbsCurve')[0]
        t = pm.pointOnCurve(shape, p=0, nt=1)
        pos = pm.pointOnCurve(shape, p=0)
        cir = pm.circle(r=radius)[0]
        pm.xform(cir, t=pos, ws=1)

        #align the circule along the curve
        l = pm.spaceLocator()
        pm.xform(l, t=[pos[0]+t[0], pos[1]+t[1], pos[2]+t[2]], ws=1)
        pm.delete(pm.aimConstraint(l, cir, aimVector=[0,0,1]))
        pm.delete(l)

        newxf = pm.extrude(cir, curveNode, rn=False, po=0, et=2, ucp=1,
                            fpt=1, upn=1, scale=1, rsp=1, ch=1)[0]
        pm.delete(cir)
        pm.delete(curveNode.listRelatives(type='nurbsCurve'))
        parentShape(curveNode, newxf)
    if len(curveNodes) > 1:
        for i in range(1, len(curveNodes)):
            parentShape(curveNodes[0], curveNodes[i])
    return curveNodes[0]
예제 #4
0
    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
예제 #5
0
def controlShapeAdaptive(controlList, geoList, ctrlSmooth=6, scaleConstant=1.5, rebuildCV=32):
    adaptiveShapeBuildGrp = pm.group(n='daptiveShapeBuild_GRP', em=True)
    geoList = pm.ls(geoList)
    dupliGeo = pm.duplicate(geoList)
    geoCombined = pm.polyUnite(dupliGeo, ch=False, name='tmpAdaptiveRef_GEO')[0]
    pm.parent(geoCombined, adaptiveShapeBuildGrp)

    ctrlList = pm.ls(controlList)
    for ctrl in ctrlList:
        ctrlShapeBuildGrp = pm.group(n=ctrl.name() + '_GRP', em=True, p=adaptiveShapeBuildGrp)

        dupliCtrl = pm.duplicate(ctrl, n='tmpCtrl')[0]
        pm.delete(pm.ls(dupliCtrl, dagObjects=True, exactType='transform')[1:])
        pm.rebuildCurve(dupliCtrl, ch=False, s=rebuildCV)
        pm.parent(dupliCtrl, ctrlShapeBuildGrp)

        # extrusion
        extrudeCircle = pm.circle(r=0.1, ch=0)[0]
        pm.parent(extrudeCircle, ctrlShapeBuildGrp)
        motionPathNode = \
            pm.ls(pm.pathAnimation(extrudeCircle, curve=dupliCtrl, fractionMode=True, follow=True, followAxis='z',
                                   upAxis='y', worldUpType='vector', worldUpVector=[0, 1, 0], inverseUp=False,
                                   inverseFront=False, bank=False))[0]

        pm.disconnectAttr(extrudeCircle.tx)
        pm.disconnectAttr(extrudeCircle.ty)
        pm.disconnectAttr(extrudeCircle.tz)
        pm.disconnectAttr(extrudeCircle.rx)
        pm.disconnectAttr(extrudeCircle.ry)
        pm.disconnectAttr(extrudeCircle.rz)
        pm.disconnectAttr(motionPathNode.u)
        pm.delete(motionPathNode)

        extrudedSurface = \
            pm.extrude(extrudeCircle, dupliCtrl, ch=False, rn=False, po=0, et=2, ucp=0, fpt=1, upn=0, rotation=0,
                       scale=1,
                       rsp=1)[0]
        pm.parent(extrudedSurface, ctrlShapeBuildGrp)
        nurbsToPoly = pm.nurbsToPoly(extrudedSurface, ch=False, polygonType=1, chr=0.9)
        pm.parent(nurbsToPoly, ctrlShapeBuildGrp)

        # add deformer
        wrapNode = deform.wrapDeformer(dupliCtrl, nurbsToPoly)
        shrinkWrapNode = deform.shrinkWrapDeformer(nurbsToPoly, geoCombined)

        shrinkWrapNode.projection.set(4)
        shrinkWrapNode.targetSmoothLevel.set(ctrlSmooth)

        # delete history
        common.deleteHistory(nurbsToPoly)
        common.deleteHistory(dupliCtrl)
        pm.scale(dupliCtrl.cv[:], [scaleConstant, scaleConstant, scaleConstant])

        copyShape(dupliCtrl, ctrl)

    pm.delete(adaptiveShapeBuildGrp)
예제 #6
0
    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 setup_extrudes(curve_transforms, **kwargs):
    """ Sets up all attributes to control objects given curve transforms and a control
    Args:
        control (pm.nt.Transform): transform to control objects
        curve_transforms [pm.nt.Transform]: list of transforms with nurbsCurve shapes
    Returns {type:pm.nt.Transform}: a dictionary of types of objects that were created
    """
    prefix = kwargs.get('prefix',"")
    control = kwargs.get('control')
    radius = kwargs.get('%sradius'%prefix, 1)
    sensitive = kwargs.get('sensitive', True)
    robust = kwargs.get('robust', True)
    nodes = {}
    # Create all attributes and control attrs
    for crv_xform in curve_transforms:
        # Check for pre-existing attr entry, otherwise it's been done already
        if not pm.objExists('%s%s.%s'%(prefix, control.name(), crv_xform.name())):
            # Create the circle and align it to curve with a tangent constraint
            circle = pm.circle()
            
            cv0_pos = crv_xform.getShape().cv[0].getPosition(space='world')
            pm.xform(circle, a=True, t=cv0_pos, ws=True)
            tc = pm.tangentConstraint(crv_xform,circle)
            tc.aimVectorX.set(0)
            
            # Create the extrude
            extrude = pm.extrude(circle[0], crv_xform,
                                 ch=True, rn=True,
                                 po=1, et=2, ucp=1,
                                 fpt=1, upn=1,
                                 rotation=0, scale=1, rsp=1)
            if kwargs.get('quaded'):
                try:
                    tessellate = extrude[1].listConnections(type='nurbsTessellate')[0]
                    tessellate.polygonType.set(1)
                    tessellate.attr('format').set(3)
                except ValueError:
                    print 'Couldn\'t set the tessellate, sorry!'
            
            # Now we can store the sub curve profile options
            path_subCurve = extrude[1].path.listConnections()[0]
            profile_subCurve = extrude[1].profile.listConnections()[0]
            
            # Setup the main control with some default attributes
            # Set up a display attr if robust
            if robust:
                control.addAttr('%s%s' % (prefix, crv_xform.name()), at='enum', k=True)
                control.attr('%s%s' % (prefix, crv_xform.name())).lock()
            
            # Otherwise we want only radius to display
            attrs = [['%s%s_radius', circle[1].radius, 1],
                     ['%s%s_profile_min', profile_subCurve.min, 0],
                     ['%s%s_profile_max', profile_subCurve.max, 1],
                     ['%s%s_path_min', path_subCurve.min, 0],
                     ['%s%s_path_max', path_subCurve.max, 1],
                     ['%s%s_flip_normals', tc.aimVectorZ, kwargs.get('flipped')-1]]
                
            for attr, destination, val in attrs:
                attr = attr % (prefix, crv_xform.name())
                control.addAttr(attr, at='double', dv=val, k=True)
                control.attr(attr).connect(destination)
                if 'radius' not in attr and not robust:
                    control.attr(attr).setKeyable(0)
                # initialize the radius with the value from kwargs
                if 'radius' in attr:
                    control.attr(attr).set(radius) 
                    
            # Insert multiplier to global radius attr
            insert_modifier(control.global_radius,
                            circle[1].radius,
                            type='addDoubleLinear')
            result = [path_subCurve, profile_subCurve, extrude[0], extrude[1], circle[0]]
            for node in result:
                try:
                    nodetype = pm.objectType(node.getShape())
                except:
                    nodetype = pm.objectType(node)
                nodes.setdefault(nodetype, [])
                nodes[nodetype].append(node)
        else:
            print 'object %s is already connected numbnuts'%(crv_xform.name())

    return nodes
예제 #8
0
import pymel.core as pm

sel=pm.ls(sl=True)
circle = ''
if pm.objExists('rope_CIRCLE'):
	circle = pm.PyNode('rope_CIRCLE')
else:
	circle = pm.circle(n='rope_CIRCLE')

for obj in sel:
	if obj.getShape().type() == 'nurbsCurve':		
		extrusion = pm.extrude(circle[0], obj, ch=True, rn=False, po=0, et=2, ucp=1, fpt=1, upn= 1, rotation=0, scale=1, rsp=1, n='%s_%s_GEO'%(obj.name(), circle[0].name()))
	else:
		pm.warning('Skipping object %s because it is not a curve'%obj)
import pymel.core as pm

selection = pm.selected()[1:]
nurbsCircle = pm.selected()[0]

for curve in selection:
    if not curve.getShape().nodeType() == 'nurbsCurve':
        pm.error('nodeType is not supported. Name:' + curve.name())
    pm.extrude(nurbsCircle,
               curve,
               fixedPath=True,
               useComponentPivot=1,
               useProfileNormal=True)
예제 #10
0
def setup_extrudes(control, curve_transforms):
    """ Sets up all attributes to control objects given curve transforms and a control
    Args:
        control (pm.nt.Transform): transform to control objects
        curve_transforms [pm.nt.Transform]: list of transforms with nurbsCurve shapes
    Returns {type:pm.nt.Transform}: a dictionary of types of objects that were created
    """
    nodes = {}
    # Create all attributes and control attrs
    for crv_xform in curve_transforms:
        # Check for pre-existing attr entry, otherwise it's been done already
        if not pm.objExists('%s.%s'%(control.name(), crv_xform.name())):
            print crv_xform
            # Create the circle and align it to curve with a tangent constraint
            circle = pm.circle()
            
            cv0_pos = crv_xform.getShape().cv[0].getPosition(space='world')
            pm.xform(circle, a=True, t=cv0_pos, ws=True)
            tc = pm.tangentConstraint(crv_xform,circle)
            tc.aimVectorX.set(0)
            
            # Create the extrude
            extrude = pm.extrude(circle[0], crv_xform,
                                 ch=True, rn=True,
                                 po=1, et=2, ucp=1,
                                 fpt=1, upn=1,
                                 rotation=0, scale=1, rsp=1)
            
            # Now we can store the sub curve profile options
            path_subCurve = extrude[1].path.listConnections()[0]
            profile_subCurve = extrude[1].profile.listConnections()[0]
            
            # Setup the main control with some default attributes
            control.addAttr(crv_xform.name(), at='enum', k=True)
            control.attr(crv_xform.name()).lock()
            
            attrs = [['%s_radius', circle[1].radius, 1],
                     ['%s_profile_min', profile_subCurve.min, 0],
                     ['%s_profile_max', profile_subCurve.max, 1],
                     ['%s_path_min', path_subCurve.min, 0],
                     ['%s_path_max', path_subCurve.max, 1],
                     ['%s_flip_normals', tc.aimVectorZ, -1]]
            
            for attr, destination, val in attrs:
                attr = attr%crv_xform.name()
                control.addAttr(attr, at='double', dv=val, k=True)
                control.attr(attr).connect(destination)
            
            # Insert multiplier to global radius attr
            insert_modifier(control.global_radius,
                            circle[1].radius,
                            type='addDoubleLinear')
            result = [path_subCurve, profile_subCurve, extrude[0], extrude[1], circle[0]]
            for node in result:
                try:
                    nodetype = pm.objectType(node.getShape())
                except:
                    nodetype = pm.objectType(node)
                nodes.setdefault(nodetype, [])
                nodes[nodetype].append(node)
        else:
            print 'object %s is already connected numbnuts'%(crv_xform.name())

    return nodes
예제 #11
0
파일: rope.py 프로젝트: dayelov/DevPyLib
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])