示例#1
0
def make_sphere(name="Nisse", create_uvs=1, radius=3):
    """
    Example function that will make a sphere name Nisse

    :return:
    """
    pm.polySphere(name=name, createUVs=create_uvs, radius=radius)
    return "I made a sphere"
示例#2
0
def make_sphere(name="Nisse"):
    """
    Example function that will make a sphere name Nisse

    :return:
    """
    pm.polySphere(name=name)
    return "I made a sphere"
示例#3
0
def test():
    facs = utils.FACS()
    print facs.getAttrs(attrNum=False,
                        attrGrp=False,
                        attrName=True,
                        splitAttrName=False,
                        splitPart=False,
                        auNum=False,
                        auName=False)

    pm.polySphere()
示例#4
0
    def create_sphere_display_control_base(self, control, radius):
        new_sphere_transform, new_sphere_creator = pm.polySphere()
        self.display_spheres.append([new_sphere_transform, new_sphere_creator])
        pfx = pm.createNode('pfxToon')
        transform_pfx = pm.ls('pfxToon1')[0]
        new_sphere_transform.setParent(self.rig_system.kinematics)
        self.name_conv.rename_name_in_format(transform_pfx, name='display')
        self.name_conv.rename_name_in_format(pfx, name='displaypfx')
        self.name_conv.rename_name_in_format(new_sphere_transform,
                                             name='displaySphere')
        self.name_conv.rename_name_in_format(new_sphere_creator,
                                             name='displaySphereCreation')

        new_sphere_transform.outMesh >> pfx.inputSurface[0].surface
        new_sphere_transform.worldMatrix >> pfx.inputSurface[0].inputWorldMatrix
        pfx.displayPercent.set(100)
        pfx.screenspaceWidth.set(True)
        pfx.distanceScaling.set(1)
        pfx.minPixelWidth.set(1)
        pfx.maxPixelWidth.set(10)
        pfx.profileColor.set(0.5, 0.0, 0.0)
        len(pm.getAttr(pfx.inputSurface, mi=True))
        pfx.overrideEnabled.set(True)
        pfx.overrideDisplayType.set(2)
        pm.addAttr(control, ln='radius', at='float', k=True, hnv=True, min=0)
        pm.addAttr(control, ln='influenceDisplay', at='bool', k=True)
        control.radius >> new_sphere_creator.radius
        control.radius.set(radius)
        control.influenceDisplay.set(True)
        control.influenceDisplay >> transform_pfx.visibility
        pm.parentConstraint(control, new_sphere_transform)
示例#5
0
def sphere_generator(source_sphrs, source_verts, gen_bones, settings):
    spheres = []
    for i in range(len(source_sphrs)):
        sphere = source_sphrs[i]
        core_vert = source_verts[sphere.vertex]
        coords = [core_vert.x, core_vert.y, core_vert.z]

        poly_transform, poly_sphere = pm.polySphere(
            name="Sphere" + str(i),
            r=sphere.size * WORLD_SCALE,
            sx=settings.sphere_resolution,
            sy=settings.sphere_resolution)
        poly_transform.translate.set(coords)
        poly_transform.rotate.set([90, 0, 0])
        poly_shape = poly_transform.getShape()

        if settings.use_palette:
            sg = "paletteSG" + str(sphere.colour)
            pm.sets(sg, edit=True, forceElement=poly_transform)

        pm.polySoftEdge(a=180)
        if settings.use_rigging:
            pm.skinCluster(gen_bones[core_vert.bone], poly_shape, tsb=True)

        spheres.append(poly_shape)
    return spheres
示例#6
0
    def addSkinnedShape(self):

        testNode    = self.createNode()
        testShapes  = testNode.getShapes()

        otherNode   = pm.polySphere()[0]
        otherShapes = otherNode.getShapes()
        oldShape    = otherNode.getShape()

        oldShape.addAttr('SomeSpecialTestMarkerAttr', attributeType = controls.Attribute.Type.BOOL)

        newObject = self.testingClass(testNode)

        newObject.addSkinnedShape([oldShape.faces])

        other = find('Other node\'s shapes changed').using(otherNode.getShapes())
        verify(other).collection.isEqualTo(otherShapes)

        difference = list(set(testShapes) ^ set(testNode.getShapes()))

        actual = find('Incorrect shape count after addition').using(difference)
        verify(actual).collection.size(1)

        newShape = difference[0]

        actual = find('Old shape was not duplicated').using(newShape)
        verify(actual).isNotEqualTo(oldShape)

        actual = find('New shape was not a duplicate').using(newShape.hasAttr('SomeSpecialTestMarkerAttr'))
        verify(actual).isTrue()
示例#7
0
    def setUp(self):
        self.temp = tempfile.mkdtemp(prefix='referencesTest')
        print "created temp dir: %s" % self.temp

        # Refs:
        #  sphere.ma
        #    (no refs)
        #  cube.ma
        #    :sphere => sphere.ma
        #  cone.ma
        #    :cubeInCone => cube.ma
        #      :cubeInCone:sphere => sphere.ma
        #  master.ma
        #    :sphere1 => sphere.ma
        #    :sphere2 => sphere.ma
        #    :cube1 => cube.ma
        #      :cube1:sphere => sphere.ma
        #    :cone1 => cone.ma
        #      :cone1:cubeInCone => cube.ma
        #        :cone1:cubeInCone:sphere => sphere.ma

        # create sphere file
        print "sphere file"
        #        cmds.file(new=1, f=1)
        pm.newFile(f=1)
        sphere = pm.polySphere()
        # We will use this to test failed ref edits...
        pm.addAttr(sphere, ln='zombieAttr')
        self.sphereFile = pm.saveAs(os.path.join(self.temp, 'sphere.ma'), f=1)

        # create cube file
        print "cube file"
        pm.newFile(f=1)
        pm.polyCube()
        pm.createReference(self.sphereFile, namespace='sphere')
        pm.PyNode('sphere:pSphere1').attr('translateX').set(2)
        self.cubeFile = pm.saveAs(os.path.join(self.temp, 'cube.ma'), f=1)

        # create cone file
        print "cone file"
        pm.newFile(f=1)
        pm.polyCone()
        pm.createReference(self.cubeFile, namespace='cubeInCone')
        pm.PyNode('cubeInCone:pCube1').attr('translateZ').set(2)
        pm.PyNode('cubeInCone:sphere:pSphere1').attr('translateZ').set(2)
        self.coneFile = pm.saveAs(os.path.join(self.temp, 'cone.ma'), f=1)

        print "master file"
        pm.newFile(f=1)
        self.sphereRef1 = pm.createReference(self.sphereFile,
                                             namespace='sphere1')
        pm.PyNode('sphere1:pSphere1').attr('translateY').set(2)
        self.sphereRef2 = pm.createReference(self.sphereFile,
                                             namespace='sphere2')
        pm.PyNode('sphere2:pSphere1').attr('translateY').set(4)
        self.cubeRef1 = pm.createReference(self.cubeFile, namespace='cube1')
        pm.PyNode('cube1:sphere:pSphere1').attr('translateY').set(6)
        pm.PyNode('cube1:pCube1').attr('translateY').set(6)
        self.coneRef1 = pm.createReference(self.coneFile, namespace='cone1')
        self.masterFile = pm.saveAs(os.path.join(self.temp, 'master.ma'), f=1)
示例#8
0
文件: hdr.py 项目: heylenz/mtoatools
def create_background_sphere(name):
    '''Create a sphere aligned to aiSkyDomeLight shape'''

    xform, _ =  pmc.polySphere(radius=995)
    shape = xform.getShape()
    xform.rename('HDR_Reflector')

    # align sphere to aiSkyDomeLight
    xform.rotateY.set(71.5)
    uv_count = pmc.polyEvaluate(shape, uv=True)
    pmc.polyFlipUV(
        '{}.map[0:{}]'.format(str(shape), uv_count),
        flipType=0,
        local=True
    )
    pmc.delete(xform, ch=True)
    pmc.makeIdentity(xform, apply=True)

    # set defaults
    shape.doubleSided.set(False)
    shape.castsShadows.set(False)
    shape.receiveShadows.set(False)
    shape.opposite.set(True)
    shape.aiSelfShadows.set(0)
    shape.aiOpaque.set(0)
    shape.aiVisibleInDiffuse.set(0)
    shape.aiVisibleInGlossy.set(0)

    return xform, shape
    def __init__(self, array):

        if isinstance(array, pm.datatypes.BoundingBox):
            self.boundingbox = array
        else:
            _spheres = [pm.polySphere(r=0.01)[0] for x in xrange(6)]
            for sphere, points, axe in zip(_spheres, array, 'xyzxyz'):
                sphere.setAttr('t{}'.format(axe), points)
            pm.select(_spheres, r=1)
            _lattrice = pm.lattice(pm.selected(),
                                   divisions=(2, 2, 2),
                                   ldv=(2, 2, 2),
                                   objectCentered=True)
            self.boundingbox = (_lattrice[-1]).getBoundingBox()
            pm.delete(_lattrice)
            pm.delete(_spheres)

        self.getAllPos()
        self.all_locs = []
        self.axisDic = {
            'all': 'all',
            'x': 0,
            'y': 1,
            'z': 2,
        }
示例#10
0
def makeLantern():
	#clear workspace
	cmds.select(all=True)
	cmds.delete()
	
	#get values from sliders
	ridges = cmds.intSliderGrp(ridgesSlider, q=True, value=True)
	deform = cmds.intSliderGrp(deformSlider, q=True, value=True)
	bend = cmds.intSliderGrp(bendSlider, q=True, value=True)
	bendNum = bend/100.0+1.0
	flatten = float(cmds.intSliderGrp(flattenSlider, q=True, value=True))

	
	lantern = pm.polySphere(n='lantern', sx=10, r=1, sy=ridges)
	rings = pm.polySelect( lantern, er=1)
	pm.select(lantern, cl=True)
	toggle = True
	for i in rings:
	    if toggle:
	        pm.polySelect( lantern, el=i)
	        pm.scale(pm.selected(), [bendNum,bendNum,bendNum], xz=True)
	    toggle = not toggle
	pm.select(lantern)
	pm.displaySmoothness(divisionsU=3, divisionsV=3, pointsWire=16, pointsShaded=4, polygonObject=3)
	wave = pm.nonLinear(type='wave', amplitude=0.03)
	pm.setAttr(wave[0]+'.wavelength', deform/100+0.1)
	pm.rotate(wave, 0, 0, '45deg')
	pm.select(all=True)
	pm.scale(lantern, [1,1-(flatten/100),1], xyz=True)
	pm.delete(ch=True)
    def addEyeMesh(self, name, parent, position=None):
        """Add a loc object to the guide.

        This mehod can initialize the object or draw it.
        Loc object is a simple null to define a position or a tranformation in
        the guide.

        Args:
            name (str): Local name of the element.
            parent (dagNode): The parent of the element.
            position (vector): The default position of the element.

        Returns:
            dagNode: The locator object.

        """
        if name not in self.tra.keys():
            self.tra[name] = transform.getTransformFromPos(position)

        eyeMesh = pm.polySphere(name=self.getName(name),
                                subdivisionsX=30,
                                subdivisionsY=45,
                                radius=0.5)[0]
        eyeMesh.setTransformation(self.tra[name])
        pm.parent(eyeMesh, parent)

        eyeMesh.setTranslation

        return eyeMesh
示例#12
0
 def make_circler_nodes(self):
     spherexform = pmc.polySphere()[0]
     spherexform.translate.set([44, 55, 66])
     circler = self.createNode('circler')
     pmc.PyNode('time1').outTime.connect(circler.input)
     circler.outSine.connect(spherexform.translateX)
     circler.outCosine.connect(spherexform.translateY)
     return spherexform, circler
 def make_circler_nodes(self):
     spherexform = pmc.polySphere()[0]
     spherexform.translate.set([44, 55, 66])
     circler = self.createNode('circler')
     pmc.PyNode('time1').outTime.connect(circler.input)
     circler.outSine.connect(spherexform.translateX)
     circler.outCosine.connect(spherexform.translateY)
     return spherexform, circler
示例#14
0
    def setUp(self):
        self.temp = tempfile.mkdtemp(prefix='referencesTest')
        print "created temp dir: %s" % self.temp

        # Refs:
        #  sphere.ma
        #    (no refs)
        #  cube.ma
        #    :sphere => sphere.ma
        #  cone.ma
        #    :cubeInCone => cube.ma
        #      :cubeInCone:sphere => sphere.ma
        #  master.ma
        #    :sphere1 => sphere.ma
        #    :sphere2 => sphere.ma
        #    :cube1 => cube.ma
        #      :cube1:sphere => sphere.ma
        #    :cone1 => cone.ma
        #      :cone1:cubeInCone => cube.ma
        #        :cone1:cubeInCone:sphere => sphere.ma

        # create sphere file
        print "sphere file"
#        cmds.file(new=1, f=1)
        pm.newFile(f=1)
        sphere = pm.polySphere()
        # We will use this to test failed ref edits...
        pm.addAttr(sphere, ln='zombieAttr')
        self.sphereFile = pm.saveAs( os.path.join( self.temp, 'sphere.ma' ), f=1 )

        # create cube file
        print "cube file"
        pm.newFile(f=1)
        pm.polyCube()
        pm.createReference( self.sphereFile, namespace='sphere' )
        pm.PyNode('sphere:pSphere1').attr('translateX').set(2)
        self.cubeFile = pm.saveAs( os.path.join( self.temp, 'cube.ma' ), f=1 )

        # create cone file
        print "cone file"
        pm.newFile(f=1)
        pm.polyCone()
        pm.createReference( self.cubeFile, namespace='cubeInCone' )
        pm.PyNode('cubeInCone:pCube1').attr('translateZ').set(2)
        pm.PyNode('cubeInCone:sphere:pSphere1').attr('translateZ').set(2)
        self.coneFile = pm.saveAs( os.path.join( self.temp, 'cone.ma' ), f=1 )

        print "master file"
        pm.newFile(f=1)
        self.sphereRef1 = pm.createReference( self.sphereFile, namespace='sphere1' )
        pm.PyNode('sphere1:pSphere1').attr('translateY').set(2)
        self.sphereRef2 = pm.createReference( self.sphereFile, namespace='sphere2' )
        pm.PyNode('sphere2:pSphere1').attr('translateY').set(4)
        self.cubeRef1 = pm.createReference( self.cubeFile, namespace='cube1' )
        pm.PyNode('cube1:sphere:pSphere1').attr('translateY').set(6)
        pm.PyNode('cube1:pCube1').attr('translateY').set(6)
        self.coneRef1 = pm.createReference( self.coneFile, namespace='cone1' )
        self.masterFile = pm.saveAs(os.path.join(self.temp, 'master.ma'), f=1)
示例#15
0
 def sphereHull(self):
     sel = pm.ls(sl=True, fl=True)
     bb, cnt, transform = self._get_bounds(sel)
     hull = pm.polySphere(radius=max(bb.width(), bb.height(), bb.depth()) / 2, sx=8, sy=8,
                          n='UCX_{0}_01'.format(transform))
     hull[0].setTranslation(cnt)
     sg = pm.PyNode('initialShadingGroup')
     sg.remove(hull[0].getShape())
     hull[0].setParent(transform)
def randPrims(numPrims, maxSize, minX, maxX, minY, maxY, minZ, maxZ, minSize=0.1): 
	prims = []
	
	for m in range(numPrims):
	# roll a random whole number between 0 to 4:
		p = random.randrange(0,5)
		if p == 0:
	# roll a random number between 0 and max sizes for all parameters
			radiusSphere = random.uniform(minSize, maxSize)
			x = random.uniform(minX, maxX)
			y = random.uniform(minY, maxY)
			z = random.uniform(minZ, maxZ)
			# store the object in a variable temporarily so it's easier to append it to the list
			n = pm.polySphere(r=radiusSphere)[0]
			pm.move(n, x, y, z)
			prims.append(n) 
		# create elif statements in case we roll 1, 2, 3 or 4
		elif p == 1:
			volCube = random.uniform(minSize, maxSize)
			x = random.uniform(minX, maxX)
			y = random.uniform(minY, maxY)
			z = random.uniform(minZ, maxZ)
			n = pm.polyCube(w=volCube, h=volCube, d=volCube)[0]
			pm.move(n, x, y, z)
			prims.append(n)
		elif p == 2:
			radiusCyl = random.uniform(minSize, maxSize)
			heightCyl = random.uniform(minSize, maxSize)
			x = random.uniform(minX, maxX)
			y = random.uniform(minY, maxY)
			z = random.uniform(minZ, maxZ)
			n = pm.polyCylinder(h=heightCyl, r=radiusCyl)[0]
			pm.move(n, x, y, z)
			prims.append(n)
		elif p == 3:
			radiusCone = random.uniform(minSize, maxSize)
			heightCone = random.uniform(minSize, maxSize)
			x = random.uniform(minX, maxX)
			y = random.uniform(minY, maxY)
			z = random.uniform(minZ, maxZ)
			n = pm.polyCone(h=heightCone, r=radiusCone)[0]
			pm.move(n, x, y, z)
			prims.append(n)
		elif p == 4:
			widthPlane = random.uniform(minSize, maxSize)
			heightPlane = random.uniform(minSize, maxSize)
			x = random.uniform(minX, maxX)
			y = random.uniform(minY, maxY)
			z = random.uniform(minZ, maxZ)
			n = pm.polyPlane(h=heightPlane, w=widthPlane)[0]
			pm.move(n, x, y, z)
			prims.append(n)
			
	return prims
示例#17
0
 def sphereHull(self):
     sel = pm.ls(sl=True, fl=True)
     bb, cnt, transform = self._get_bounds(sel)
     hull = pm.polySphere(radius=max(bb.width(), bb.height(), bb.depth()) /
                          2,
                          sx=8,
                          sy=8,
                          n='UCX_{0}_01'.format(transform))
     hull[0].setTranslation(cnt)
     sg = pm.PyNode('initialShadingGroup')
     sg.remove(hull[0].getShape())
     hull[0].setParent(transform)
示例#18
0
    def createParentCubeSphere():
        # | による親子付け

        #トランスフォームノードとシェイプノードのリストが返ってくるため、[0]で一つ目の要素のみ受け取っています
        myCube = pm.polyCube()[0]
        #同じく
        mySphere = pm.polySphere()[0]
        #親子付け
        myCube | mySphere

        #階層化されているか確認
        print '階層化の確認', mySphere.name(long=True)
示例#19
0
    def rig(self, component_node, control, bake_controls=False, default_space=None, use_global_queue=False, **kwargs):
        # Create the dynamic pendulum to be used as the Aim space for the overdriver
        self.network = self.create_meta_network(component_node)
        #self.zero_character(self.network['character'], use_global_queue)

        aim_up_group_name = "{0}pre_dynamics_{1}_grp".format(self.namespace, self.prefix)
        pre_dynamic_group = pm.group(empty=True, name=aim_up_group_name)
        pre_dynamic_group.setParent(self.network['addon'].group)
        pm.parentConstraint(self.character_world, pre_dynamic_group, mo=False)

        cur_namespace = pm.namespaceInfo(cur=True)
        pm.namespace(set=":")
        time_range = (pm.playbackOptions(q=True, min=True), pm.playbackOptions(q=True, max=True))

        object_space = pm.polySphere(r=8, sx=20, sy=20, ax=[0,1,0], cuv=2, ch=1, n="pendulum")[0]
        object_space.setParent(pre_dynamic_group)

        ws_pos = pm.xform(control, q=True, ws=True, t=True)
        pm.xform(object_space, ws=True, t=ws_pos)

        rigid_body = pm.rigidBody(object_space, b=0, dp=5)
        rigid_body_nail = pm.PyNode(pm.constrain(rigid_body, nail=True))
        rigid_body_nail.setParent(pre_dynamic_group)
        rigid_point_constraint = pm.pointConstraint(control, rigid_body_nail, mo=False)

        pm.select(None)
        gravity_field = pm.gravity(m=980)
        gravity_field.setParent(pre_dynamic_group)
        pm.connectDynamic(object_space, f=gravity_field)

        self.reset_pendulum(object_space)

        if not super(Pendulum, self).rig(component_node, control, [object_space], bake_controls=bake_controls, default_space=default_space, use_global_queue=use_global_queue, **kwargs):
            return False
        
        driver_control = self.network['controls'].get_first_connection()

        driver_control.addAttr("damping", type='double', hidden=False, keyable=True)
        driver_control.damping.set(rigid_body.damping.get())
        driver_control.damping >> rigid_body.damping

        driver_control.addAttr("bounciness", type='double', hidden=False, keyable=True)
        driver_control.bounciness.set(rigid_body.bounciness.get())
        driver_control.bounciness >> rigid_body.bounciness

        driver_control.addAttr("gravity", type='double', hidden=False, keyable=True)
        driver_control.gravity.set(gravity_field.magnitude.get())
        driver_control.gravity >> gravity_field.magnitude

        self.reset_pendulum(object_space)
示例#20
0
文件: scene.py 项目: cescocm/lookdev
def create_lightchecker(name):
    '''
    Creates a poly mesh to use as lightchecker.
    Args:
        name(String): Name of the object
    Returns:
        lightchecker
    '''
    lightchecker = pm.polySphere(name='{0}:{1}_geo'.format(NAMESPACE, name),
                                 radius=7,
                                 subdivisionsX=60,
                                 subdivisionsY=40,
                                 constructionHistory=False)[0]
    return lightchecker
示例#21
0
    def ctrlRadiusFromJoint(self, jnt, useSphere=True):
        childJnt = jnt.getChildren()

        if len(childJnt) > 0:
            radius = util.get_distance(jnt, childJnt[0])

            if useSphere:
                sphere = pm.polySphere(r=radius, sx=20, sy=20, ch=False)[0]
                radius = util.getPlanarRadiusBBOXFromTransform(sphere, radiusFactor=3)['3D']
                pm.delete(sphere)

        else:
            return 1

        return radius
示例#22
0
def shaderTest(shader, attribute, objA=None, minV=0.0, maxV=1.0, step=0.1):
    """ Setup Balls to Render """
    if objA == None:
        objA = pm.polySphere()[0]
    copies = maxV / step
    objList = duplicateArray(objA=objA, noCopies=copies, direction="+x")
    attrV = minV
    for i, _obj in enumerate(objList, 1):
        print i, _obj, attribute, attrV
        shd, grp = createShader(shader, "%s_SHD" % str(_obj))
        assignShaderToObject(_obj, grp)
        if isinstance(shd.getAttr(attribute), float):
            shd.setAttr(attribute, attrV)
        elif isinstance(shd.getAttr(attribute), tuple):  # Color Support
            shd.setAttr(attribute, [attrV, attrV, attrV])
        attrV += step
    def AddSphere(self,*args):
	    #create sphere
	    #----------------------------------
	    collisionSphereTrans = pm.polySphere(sx = 8,sy = 8, n = 'collisionSphere0', r = 2, ch = 0)[0]
	    collisionSphereShape = collisionSphereTrans.getShape()
	    collisionSphereTrans.translate.set(0,1,0)
	    pm.select(cl = True)

	    #connect sphere as collision object
	    #----------------------------------
	    clothSolver = self.GlobalVars["clothSolver"]
	    clothSolver.collisionConstraint[self.NumOfCol].collisionConstraintActive.set(1)
	    clothSolver.collisionConstraint[self.NumOfCol].collisionConstraintType.set(0)
	    collisionSphereShape.outMesh >> clothSolver.collisionConstraint[self.NumOfCol].collisionConstraintGeo
	    collisionSphereShape.parentMatrix >> clothSolver.collisionConstraint[self.NumOfCol].collisionConstraintGeoMatrix
	    self.NumOfCol = self.NumOfCol + 1
	    pm.select(cl = True)
示例#24
0
 def setUp(self):
     new_obs = []
     collumn = 5
     row = 6
     for i in range(collumn):
         new_ob = pm.polySphere()[0]
         if new_obs:
             new_ob.setParent(new_obs[-1])
         new_obs.append(new_ob)
     new_obs = [new_obs[0]]
     for i in range(row):
         dup_ob = pm.duplicate(
             new_obs[-1],
             name = new_obs[-1].name()+'_i',
             rc=True)
         new_obs.append(dup_ob)
     self.selected = pm.selected()
示例#25
0
def createVertSphere():
	'''
	create a poly sphere that will be used to determine 
	what verts should be influenced.
	'''
	sel = pm.selected()
	
	for s in sel:
		print pm.objectType(s)
		if pm.objectType(s) == 'joint':
			userPos = pm.xform(s, q = True, t = True, ws = True)
		elif pm.objectType(s) == 'mesh':
			userPos = pm.pointPosition(s, w = True)
		
		vSphere = pm.polySphere(n = '{0}_vtxSphere'.format(s), ch = False)
		pm.move(userPos[0],userPos[1],userPos[2], vSphere)
		
		return vSphere
示例#26
0
    def duplicateTransformHierarchyRec(origNode, parentToNode, geoProxy=False):
        origChildren = origNode.getChildren(type='transform')

        if len(origChildren) == 0: return 'Finished'

        for origChild in origChildren:
            origShape = origChild.getShape()
            if origShape is not None:  # shape
                if geoProxy is not False:
                    print 'duplicating mesh'
                    proxySphere = pm.polySphere(name='temp', sx=4, sy=6)[0]
                    pm.matchTransform(proxySphere, origChild)
                    pm.parent(proxySphere, parentToNode)
                    proxySphere.rename(origChild)
            else:
                dup = origChild.duplicate(n='temp', po=1)[0]
                pm.parent(dup, parentToNode)
                dup.rename(origChild)
                duplicateTransformHierarchyRec(origChild, dup, geoProxy)
示例#27
0
    def setUp(self):
        self.temp = os.path.join(tempfile.gettempdir(), "referencesTest")
        if not os.path.isdir(self.temp):
            os.makedirs(self.temp)
        print "created temp dir: %s" % self.temp

        # Refs:
        #  sphere.ma
        #    (no refs)

        #  master.ma
        #    :sphere1 => sphere.ma
        #    :sphere2 => sphere.ma

        # create sphere file
        print "sphere file"
        #        cmds.file(new=1, f=1)
        pm.newFile(f=1)
        sphere = pm.polySphere()[0]

        pm.addAttr(sphere, ln="zombieAttr1")
        pm.addAttr(sphere, ln="zombieAttr2")
        cmds.setAttr("%s.v" % sphere, lock=1)
        cmds.setAttr("%s.zombieAttr1" % sphere, lock=1)

        self.sphereFile = pm.saveAs(os.path.join(self.temp, "sphere.ma"), f=1)

        print "master file"
        pm.newFile(f=1)
        self.sphereRef1 = pm.createReference(self.sphereFile, namespace="sphere1")
        self.sphereRef2 = pm.createReference(self.sphereFile, namespace="sphere2")
        self.sphere1 = pm.PyNode("sphere1:pSphere1")
        self.sphere2 = pm.PyNode("sphere2:pSphere1")
        self.sphere1.attr("translateY").set(2)
        self.sphere2.attr("translateY").set(4)

        self.cube = pm.polyCube()[0]
        pm.addAttr(self.cube, ln="zombieAttr1")
        pm.addAttr(self.cube, ln="zombieAttr2")
        cmds.setAttr("%s.v" % self.cube, lock=1)
        cmds.setAttr("%s.zombieAttr1" % self.cube, lock=1)

        self.masterFile = pm.saveAs(os.path.join(self.temp, "master.ma"), f=1)
示例#28
0
    def setUp(self):
        print "getting temp dir"
        self.temp = os.path.join(tempfile.gettempdir(), 'referencesTest')
        if not os.path.isdir(self.temp):
            os.makedirs(self.temp)
        
        # create sphere file
        print "sphere file"
#        cmds.file(new=1, f=1)
        pm.newFile(f=1)
        sphere = pm.polySphere()
        # We will use this to test failed ref edits...
        pm.addAttr(sphere, ln='zombieAttr')
        self.sphereFile = pm.saveAs( os.path.join( self.temp, 'sphere.ma' ), f=1 )
        
        # create cube file
        print "cube file"
        pm.newFile(f=1)
        pm.polyCube()
        pm.createReference( self.sphereFile, namespace='sphere' )
        pm.PyNode('sphere:pSphere1').attr('translateX').set(2)
        self.cubeFile = pm.saveAs( os.path.join( self.temp, 'cube.ma' ), f=1 )
        
        # create cone file
        print "cone file"
        pm.newFile(f=1)
        pm.polyCone()
        pm.createReference( self.cubeFile, namespace='cubeInCone' )
        pm.PyNode('cubeInCone:pCube1').attr('translateZ').set(2)
        pm.PyNode('cubeInCone:sphere:pSphere1').attr('translateZ').set(2)
        self.coneFile = pm.saveAs( os.path.join( self.temp, 'cone.ma' ), f=1 )
        
        print "master file"
        pm.newFile(f=1)
        self.sphereRef1 = pm.createReference( self.sphereFile, namespace='sphere1' )
        pm.PyNode('sphere1:pSphere1').attr('translateY').set(2)
        self.sphereRef2 = pm.createReference( self.sphereFile, namespace='sphere2' )
        pm.PyNode('sphere2:pSphere1').attr('translateY').set(4)
        self.cubeRef1 = pm.createReference( self.cubeFile, namespace='cube1' )
        pm.PyNode('cube1:sphere:pSphere1').attr('translateY').set(6)
        pm.PyNode('cube1:pCube1').attr('translateY').set(6)
        self.coneRef1 = pm.createReference( self.coneFile, namespace='cone1' )
示例#29
0
    def setUp(self):
        print "getting temp dir"
        self.temp = os.path.join(tempfile.gettempdir(), 'referencesTest')
        if not os.path.isdir(self.temp):
            os.makedirs(self.temp)
        
        # create sphere file
        print "sphere file"
#        cmds.file(new=1, f=1)
        pm.newFile(f=1)
        sphere = pm.polySphere()
        # We will use this to test failed ref edits...
        pm.addAttr(sphere, ln='zombieAttr')
        self.sphereFile = pm.saveAs( os.path.join( self.temp, 'sphere.ma' ), f=1 )
        
        # create cube file
        print "cube file"
        pm.newFile(f=1)
        pm.polyCube()
        pm.createReference( self.sphereFile, namespace='sphere' )
        pm.PyNode('sphere:pSphere1').attr('translateX').set(2)
        self.cubeFile = pm.saveAs( os.path.join( self.temp, 'cube.ma' ), f=1 )
        
        # create cone file
        print "cone file"
        pm.newFile(f=1)
        pm.polyCone()
        pm.createReference( self.cubeFile, namespace='cubeInCone' )
        pm.PyNode('cubeInCone:pCube1').attr('translateZ').set(2)
        pm.PyNode('cubeInCone:sphere:pSphere1').attr('translateZ').set(2)
        self.coneFile = pm.saveAs( os.path.join( self.temp, 'cone.ma' ), f=1 )
        
        print "master file"
        pm.newFile(f=1)
        self.sphereRef1 = pm.createReference( self.sphereFile, namespace='sphere1' )
        pm.PyNode('sphere1:pSphere1').attr('translateY').set(2)
        self.sphereRef2 = pm.createReference( self.sphereFile, namespace='sphere2' )
        pm.PyNode('sphere2:pSphere1').attr('translateY').set(4)
        self.cubeRef1 = pm.createReference( self.cubeFile, namespace='cube1' )
        pm.PyNode('cube1:sphere:pSphere1').attr('translateY').set(6)
        pm.PyNode('cube1:pCube1').attr('translateY').set(6)
        self.coneRef1 = pm.createReference( self.coneFile, namespace='cone1' )
示例#30
0
    def flexiplane_mid_ctrl(self, name=None):
        """
        Create Mid Control
        :param name:
        :return:
        """
        if not name:
            name = '_mid_ctrl'

        mid_ctrl = pm.polySphere(n=name,
                                 r=0.3,
                                 sx=8,
                                 sy=8,
                                 ax=(0.0, 1.0, 0.0),
                                 ch=False)[0]
        # cc_shp = cc.getShape()
        # cc_shp.overrideEnabled.set(1)
        # cc_shp.overrideColor.set(color)
        self.create_surfaceshader(mid_ctrl, color=(1.0, 1.0, 0.0))

        return mid_ctrl
示例#31
0
def create_shapes(*args):
    print('This will create shapes')
    num = slider1.getValue()
    print('Number of shapes to be created:', num)

    i = 0
    while i < num:
        value = float(i) / num
        angle = random.randint(0, 359)
        radius = random.uniform(0.5, 2)
        height = random.uniform(0.5, 1)
        x, y, z = pm.pointOnCurve('curve1', pr=value, turnOnPercentage=True)

        x1 = random.uniform(x - 3, x + 3)
        y1 = random.uniform(y - 3, y + 3)
        z1 = random.uniform(z - 3, z + 3)

        shape = options.getValueArray4()
        j = random.randint(0, 3)
        if shape[j] == True:
            if j == 0:
                figure = pm.polyTorus(r=radius, sr=0.25)
                pm.move(x1, y1, z1, figure)
                i += 1
            elif j == 1:
                figure = pm.polyCone(sx=1, sy=1.5, sz=0.5, r=radius, h=height)
                pm.move(x1, y1, z1, figure)
                i += 1
            elif j == 2:
                figure = pm.polySphere(r=radius)
                pm.move(x1, y1, z1, figure)
                i += 1
            elif j == 3:
                figure = pm.polyCylinder(r=radius, h=height)
                pm.move(x1, y1, z1, figure)
                i += 1
            pm.select(figure)
            pm.rotate(angle, 0, 0, r=True)
            pm.select(clear=True)
示例#32
0
def createPointParent(ob, name="PointParent#", shapeReplace=False, r=1):
    '''Create a Parent of selected'''
    obOldParent = ob.getParent()
    obNewParent = pm.polySphere(name=name,
                                subdivisionsAxis=6,
                                subdivisionsHeight=4,
                                radius=r / 3)
    for a in [('castsShadows', 0), ('receiveShadows', 0), ('smoothShading', 0),
              ('primaryVisibility', 0), ('visibleInReflections', 0),
              ('visibleInRefractions', 0), ('overrideEnabled', 1),
              ('overrideShading', 0), ('overrideTexturing', 0),
              ('overrideRGBColors', 1), ('overrideColorRGB', (1, 0, 0))]:
        obNewParent[0].getShape().attr(a[0]).set(a[1])
    if not shapeReplace:
        pm.xform(obNewParent[0], ws=1, t=pm.xform(ob, q=1, ws=1, t=1))
        pm.xform(obNewParent[0], ws=1, ro=pm.xform(ob, q=1, ws=1, ro=1))
        #pm.color(obNewParent[0],rgb=(1,0,0))
        #obNewParent.setAttr("translate",obPos)
        if obOldParent:
            pm.parent(obNewParent[0], obOldParent)
        pm.parent(ob, obNewParent[0])
    else:
        pm.parent(obNewParent[0].listsRelatives(shapes=1)[0], ob, r=1, s=1)
        pm.delete(obNewParent)
示例#33
0
# 基本的な使い方

## ライブラリ読み込み
~~~
import maya.cmds as cmds
~~~

## 球体を作成
~~~
import pymel.core as pm

# 球体を作成
pm.polySphere(r=10,n='testsphere')
~~~
pm.select(cl = True)
clothSolver.positionConstraint[3].positionConstraintVertexIndex.set(10)
positionConstraintLocatorIndex10Shape.worldPosition >> clothSolver.positionConstraint[3].positionConstraintCoordinate
pm.select(cl = True)
clothSolver.positionConstraint[4].positionConstraintVertexIndex.set(60)
positionConstraintLocatorIndex60Shape.worldPosition >> clothSolver.positionConstraint[4].positionConstraintCoordinate
pm.select(cl = True)

#set clothSolver active attr
#----------------------------------
clothSolver.positionConstraint[0].positionConstraintActive.set(1)
clothSolver.positionConstraint[1].positionConstraintActive.set(1)

#create sphere
#----------------------------------
collisionSphereTrans = pm.polySphere(sx = 8,sy = 8, n = 'collisionSphere0', r = 2, ch = 0)[0]
collisionSphereShape = collisionSphereTrans.getShape()
collisionSphereTrans.translate.set(0,1,0)
pm.select(cl = True)

#connect sphere as collision object
#----------------------------------
clothSolver.collisionConstraint[0].collisionConstraintActive.set(1)
clothSolver.collisionConstraint[0].collisionConstraintType.set(0)
collisionSphereShape.outMesh >> clothSolver.collisionConstraint[0].collisionConstraintGeo
collisionSphereShape.parentMatrix >> clothSolver.collisionConstraint[0].collisionConstraintGeoMatrix
pm.select(cl = True)

#create cube
#----------------------------------
collisionCubeTrans = pm.polyCube(sx = 1,sy = 1, sz = 1, d = 4, w = 4, h = 4, n = 'collisionCube1', ch = 0)[0]
示例#35
0
    def build_rbf(self):
        try:
            pm.loadPlugin('jsRadial.mll')
        except:
            pm.error('ERROR: jsRadial.mll not loaded.')

        pm.undoInfo(openChunk=True)
        rbf = pm.createNode('jsRadPose')

        # Notify if RBF is made with no connections
        if len(self.pose) == 0 and len(self.targets) == 0:
            print "RBF node made with no connections"

        # Only create one sigma blinn material
        if self.sigma_chk.isChecked():
            self.sigma_shader = pm.shadingNode("lambert",
                                               asShader=True,
                                               name="sigmaLmbt")
            pm.setAttr(self.sigma_shader.color.colorR, 0.0)
            pm.setAttr(self.sigma_shader.color.colorG, 0.5)
            pm.setAttr(self.sigma_shader.color.colorB, 1.0)
            pm.setAttr(self.sigma_shader.transparency, (0.95, 0.95, 0.95))
            self.sigma_sg = pm.sets(renderable=1,
                                    noSurfaceShader=1,
                                    empty=1,
                                    n="sigmaLmbt_SG")
            pm.connectAttr(self.sigma_shader.outColor,
                           self.sigma_sg.surfaceShader)
            self.falloff_group = pm.group(empty=1, n="GRP_rbf_falloff")

        # Connect pose attrs
        if len(self.pose) == 1:
            # Connect pose matrix
            if self.matrix_chk.isChecked() == True:
                if self.world_rad.isChecked() == True:
                    pm.connectAttr(self.pose[0][0].worldMatrix[0],
                                   rbf.poseMatrix)
                else:
                    pm.connectAttr(self.pose[0][0].parentMatrix[0],
                                   rbf.poseMatrix)

            # Connect pose color
            if self.rgb_chk.isChecked() == True or self.alpha_chk.isChecked(
            ) == True:
                shape = pm.listRelatives(self.pose[0], shapes=1)[0]
                shader_grp = pm.listConnections(shape, type='shadingEngine')
                shader = pm.listConnections(shader_grp[0], d=0, s=1)[0]
                if self.rgb_chk.isChecked():
                    try:
                        pm.connectAttr(shader.color, rbf.poseColor)
                    except:
                        try:
                            pm.connectAttr(shader.outColor, rbf.poseColor)
                        except:
                            pass
                if self.alpha_chk.isChecked():
                    try:
                        pm.connectAttr(shader.transparency,
                                       rbf.poseTransparency)
                    except:
                        try:
                            pm.connectAttr(shader.outTransparency,
                                           rbf.poseTransparency)
                        except:
                            pass

            # Build pose rotate locators
            locX = pm.spaceLocator(n=self.pose[0][0] + '_rotLocX')
            locY = pm.spaceLocator(n=self.pose[0][0] + '_rotLocY')
            locZ = pm.spaceLocator(n=self.pose[0][0] + '_rotLocZ')

            pm.parent(locX, locY, locZ, self.pose[0])

            pm.setAttr(locX.translate, (0, 0, 0))
            pm.setAttr(locY.translate, (0, 0, 0))
            pm.setAttr(locZ.translate, (0, 0, 0))

            mult = pm.createNode('multiplyDivide',
                                 n='MULTinv_' + self.pose[0][0])
            pm.setAttr(mult.operation, 2)
            pm.setAttr(mult.input1X, 1)
            pm.setAttr(mult.input1Y, 1)
            pm.setAttr(mult.input1Z, 1)

            pm.connectAttr(self.pose[0][0].scale, mult.input2)

            pm.connectAttr(mult.output, locX.scale)
            pm.connectAttr(mult.output, locY.scale)
            pm.connectAttr(mult.output, locZ.scale)

            mult_neg = pm.createNode('multiplyDivide',
                                     n='MULTneg_' + self.pose[0][0])
            pm.setAttr(mult_neg.operation, 1)
            pm.setAttr(mult_neg.input1X, -1)
            pm.setAttr(mult_neg.input1Y, -1)
            pm.setAttr(mult_neg.input1Z, -1)

            pm.connectAttr(rbf.rotateLocatorOffset, locX.tx)
            pm.connectAttr(rbf.rotateLocatorOffset, locY.ty)
            pm.connectAttr(rbf.rotateLocatorOffset, locZ.tz)

            pm.connectAttr(rbf.rotateLocatorOffset, mult_neg.input2X)
            pm.connectAttr(rbf.rotateLocatorOffset, mult_neg.input2Y)
            pm.connectAttr(rbf.rotateLocatorOffset, mult_neg.input2Z)

            pm.connectAttr(mult_neg.outputX, locX.scalePivotX)
            pm.connectAttr(mult_neg.outputY, locY.scalePivotY)
            pm.connectAttr(mult_neg.outputZ, locZ.scalePivotZ)

            pm.connectAttr(locX.worldMatrix[0], rbf.poseRotateLocX)
            pm.connectAttr(locY.worldMatrix[0], rbf.poseRotateLocY)
            pm.connectAttr(locZ.worldMatrix[0], rbf.poseRotateLocZ)

            pm.connectAttr(rbf.rotateLocatorsVisible, locX.visibility)
            pm.connectAttr(rbf.rotateLocatorsVisible, locY.visibility)
            pm.connectAttr(rbf.rotateLocatorsVisible, locZ.visibility)

            pm.setAttr(locX.overrideEnabled, 1)
            pm.setAttr(locY.overrideEnabled, 1)
            pm.setAttr(locZ.overrideEnabled, 1)
            pm.setAttr(locX.overrideColor, 12)
            pm.setAttr(locY.overrideColor, 23)
            pm.setAttr(locZ.overrideColor, 29)

        # Check target list for pose and duplicates
        if len(self.pose) == 1:
            single_set = set(self.targets)
            self.targets = list(single_set)
            if self.pose[0][0] in self.targets:
                print "Pose " + self.pose[0][
                    0] + " was removed from target list but kept as input pose."
                self.targets.remove(self.pose[0][0])

        # Connect target attrs
        for i in range(0, len(self.targets)):
            # Connect target matrix
            if self.matrix_chk.isChecked() == True:
                if self.world_rad.isChecked() == True:
                    pm.connectAttr(self.targets[i].worldMatrix[0],
                                   rbf.target[i].targetMatrix)
                else:
                    pm.connectAttr(self.targets[i].parentMatrix[0],
                                   rbf.target[i].targetMatrix)

            # Connect target rbga
            if self.rgb_chk.isChecked() == True or self.alpha_chk.isChecked(
            ) == True:
                shape = pm.listRelatives(self.targets[i], shapes=1)[0]
                shader_grp = pm.listConnections(shape, type='shadingEngine')
                shader = pm.listConnections(shader_grp[0], d=0, s=1)[0]
                if self.rgb_chk.isChecked() == True:
                    try:
                        pm.connectAttr(shader.color, rbf.target[i].targetColor)
                    except:
                        try:
                            pm.connectAttr(shader.outColor,
                                           rbf.target[i].targetColor)
                        except:
                            pass
                if self.alpha_chk.isChecked() == True:
                    try:
                        pm.connectAttr(shader.transparency,
                                       rbf.target[i].targetTransparency)
                    except:
                        try:
                            pm.connectAttr(shader.outTransparency,
                                           rbf.target[i].targetTransparency)
                        except:
                            pass

            # Build target rotate locators
            locX = pm.spaceLocator(n=self.targets[i] + '_rotLocX')
            locY = pm.spaceLocator(n=self.targets[i] + '_rotLocY')
            locZ = pm.spaceLocator(n=self.targets[i] + '_rotLocZ')

            pm.parent(locX, locY, locZ, self.targets[i])

            pm.setAttr(locX.translate, (0, 0, 0))
            pm.setAttr(locY.translate, (0, 0, 0))
            pm.setAttr(locZ.translate, (0, 0, 0))

            mult = pm.createNode('multiplyDivide',
                                 n='MULTinv_' + self.targets[i])
            pm.setAttr(mult.operation, 2)
            pm.setAttr(mult.input1X, 1)
            pm.setAttr(mult.input1Y, 1)
            pm.setAttr(mult.input1Z, 1)

            pm.connectAttr(self.targets[i].scale, mult.input2)

            pm.connectAttr(mult.output, locX.scale)
            pm.connectAttr(mult.output, locY.scale)
            pm.connectAttr(mult.output, locZ.scale)

            mult_neg = pm.createNode('multiplyDivide',
                                     n='MULTneg_' + self.targets[i])
            pm.setAttr(mult_neg.operation, 1)
            pm.setAttr(mult_neg.input1X, -1)
            pm.setAttr(mult_neg.input1Y, -1)
            pm.setAttr(mult_neg.input1Z, -1)

            pm.connectAttr(rbf.rotateLocatorOffset, locX.tx)
            pm.connectAttr(rbf.rotateLocatorOffset, locY.ty)
            pm.connectAttr(rbf.rotateLocatorOffset, locZ.tz)

            pm.connectAttr(rbf.rotateLocatorOffset, mult_neg.input2X)
            pm.connectAttr(rbf.rotateLocatorOffset, mult_neg.input2Y)
            pm.connectAttr(rbf.rotateLocatorOffset, mult_neg.input2Z)

            pm.connectAttr(mult_neg.outputX, locX.scalePivotX)
            pm.connectAttr(mult_neg.outputY, locY.scalePivotY)
            pm.connectAttr(mult_neg.outputZ, locZ.scalePivotZ)

            pm.connectAttr(locX.worldMatrix[0], rbf.target[i].rotateLocX)
            pm.connectAttr(locY.worldMatrix[0], rbf.target[i].rotateLocY)
            pm.connectAttr(locZ.worldMatrix[0], rbf.target[i].rotateLocZ)

            pm.connectAttr(rbf.rotateLocatorsVisible, locX.visibility)
            pm.connectAttr(rbf.rotateLocatorsVisible, locY.visibility)
            pm.connectAttr(rbf.rotateLocatorsVisible, locZ.visibility)

            pm.setAttr(locX.overrideEnabled, 1)
            pm.setAttr(locY.overrideEnabled, 1)
            pm.setAttr(locZ.overrideEnabled, 1)
            pm.setAttr(locX.overrideColor, 12)
            pm.setAttr(locY.overrideColor, 23)
            pm.setAttr(locZ.overrideColor, 29)

            # Build target alias attrs on RBF node
            if self.alias_chk.isChecked():
                alias = self.targets[i]
                if '|' in alias:
                    alias = alias.replace('|', '_')
                pm.aliasAttr(alias, rbf.target[i])
                outAlias = alias + 'Out'
                sigmaAlias = alias + 'Falloff'
                pm.aliasAttr(outAlias, rbf.outputInterpolate[i])
                pm.aliasAttr(sigmaAlias, rbf.outputSigma[i])
                pm.getAttr(rbf.outputInterpolate[i])
                pm.getAttr(rbf.outputSigma[i])

            # Build falloff spheres
            if self.sigma_chk.isChecked():
                bb = pm.xform(self.targets[i], q=1, bb=1)
                scale = bb[3] - bb[0]
                ### hard coding sphere radius from trial and error
                sphere = pm.polySphere(r=5.0,
                                       sx=20,
                                       sy=20,
                                       ax=(0, 1, 0),
                                       ch=0,
                                       n=str(self.targets[i]) + '_falloff')
                sphereShp = pm.listRelatives(sphere, s=1)
                pcon = pm.parentConstraint(self.targets[i], sphere, mo=0)
                pm.sets(self.sigma_sg, e=1, forceElement=sphereShp)

                mult = pm.createNode('multiplyDivide',
                                     n='MULT_' + self.targets[i] + '_falloff')
                pm.setAttr(mult.input1X, 0.5)
                pm.setAttr(mult.operation, 2)
                pm.connectAttr(rbf.outputSigma[i], mult.input2X)

                pm.connectAttr(mult.outputX, sphere[0].scaleX)
                pm.connectAttr(mult.outputX, sphere[0].scaleY)
                pm.connectAttr(mult.outputX, sphere[0].scaleZ)

                pm.parent(sphere, self.falloff_group)

        pm.undoInfo(closeChunk=True)
        self.close()
示例#36
0
def renderBuddy(ren, arg=1):

####: REN
# 1 : mentalRay
# 2 : V-ray

####: ARGS
# 1 : create
# 2 : delete

    if arg is 1:
        
        # cleanup check
        if pm.objExists('LGT_REF_OBJ') | pm.objExists('diff_18SG') | pm.objExists('diff_18'):
            pm.delete('diff_80', 'diff_18', 'refl_100', 'refl_75', 'diff_18SG', 'diff_80SG', 'refl_01SG', 'refl_02SG', 'LGT_REF_OBJ')
        
        # create four spheres & a plane
        tmp1 = pm.polySphere(r = 1, n = "fBall_D1", ch = 0)
        diff01 = tmp1[0]
        tmp1 = pm.polySphere(r = 1, n = "fBall_D2", ch = 0)
        diff02 = tmp1[0]
        tmp1 = pm.polySphere(r = 1, n = "fBall_R1", ch = 0)
        refl01 = tmp1[0]
        tmp1 = pm.polySphere(r = 1, n = "fBall_R2", ch = 0)
        refl02 = tmp1[0]
        tmp1 = pm.polyPlane (n = "fGround", ch = 1)
        grid01 = tmp1[0]
        objs = [diff01, diff02, refl01, refl02, grid01]
        
        #shds = [shd_diff_80, shd_diff_18, shd_refl_01, shd_refl_02]
        #shgs = [shg_diff_80, shg_diff_18, shg_refl_01, shg_refl_02]
        
        # group them
        grp = pm.group(diff01, diff02, refl01, refl02, grid01, n = "LGT_REF_OBJ")
        grp.translateY.set(10)
        
        # move them around
        offset = 4.5
        
        for o in objs:
            o.translateX.set(offset)
            offset = offset -3
            
        grid01.scaleX.set(50)
        grid01.scaleZ.set(50)
        grid01.translateX.set(0)
        grid01.translateY.set(-10)
        
        # create shaders
        # 80% diffuse goes to mesh diff01
        shg_diff_80 = pm.sets(n = "diff_80SG", renderable = 1, empty = 1)
        shd_diff_80 = pm.shadingNode('lambert', asShader = 1, n = "diff_80")
        shd_diff_80.diffuse.set(0.8)
        shd_diff_80.color.set(1, 1, 1)
        pm.surfaceShaderList(shd_diff_80, add = shg_diff_80)
        pm.sets(shg_diff_80, e = 1, forceElement = diff01)
        
        # 18% diffuse goes to mesh diff02
        shg_diff_18 = pm.sets(n = "diff_18SG", renderable = 1, empty = 1)
        shd_diff_18 = pm.shadingNode('lambert', asShader = 1, n = "diff_18")
        shd_diff_18.diffuse.set(0.18)
        shd_diff_18.color.set(1, 1, 1)
        pm.surfaceShaderList(shd_diff_18, add = shg_diff_18)
        pm.sets(shg_diff_18, e = 1, forceElement = diff02)
        
        
        ### REFLECTION SPHERES DEPEND ON DIFFERENT SHADERS FOR MENTALRAY / VRAY ###
        
        if ren is 1:
        
            # (MENTALRAY) 100% glossy mia goes to mesh refl01
            shg_refl_01 = pm.sets(n = "refl_01SG", renderable = 1, empty = 1)
            shd_refl_01 = pm.shadingNode('mia_material_x_passes', asShader = 1, n = "refl_100")
            shd_refl_01.diffuse_weight.set(0)
            shd_refl_01.reflectivity.set(1)
            pm.disconnectAttr('lambert1.outColor', shg_refl_01.surfaceShader)
            pm.connectAttr(shd_refl_01.message, shg_refl_01.miMaterialShader)
            pm.sets(shg_refl_01, e = 1, forceElement = refl01)
            
            # (MENTALRAY) 75% glossy mia goes to mesh refl02
            shg_refl_02 = pm.sets(n = "refl_02SG", renderable = 1, empty = 1)
            shd_refl_02 = pm.shadingNode('mia_material_x_passes', asShader = 1, n = "refl_75")
            shd_refl_02.diffuse_weight.set(0)
            shd_refl_02.reflectivity.set(1)
            shd_refl_02.refl_gloss.set(0.75)
            pm.disconnectAttr('lambert1.outColor', shg_refl_02.surfaceShader)
            pm.connectAttr(shd_refl_02.message, shg_refl_02.miMaterialShader)
            pm.sets(shg_refl_02, e = 1, forceElement = refl02)
        
        if ren is 2:
            
            # (VRAY) 100% glossy vraymtl goes to mesh refl01
            shg_refl_01 = pm.sets(n = "refl_01SG", renderable = 1, empty = 1)
            shd_refl_01 = pm.shadingNode('VRayMtl', asShader = 1, n = "refl_100")
            shd_refl_01.diffuseColorAmount.set(0)
            shd_refl_01.reflectionColor.set(1,1,1)
            pm.surfaceShaderList(shd_refl_01, add = shg_refl_01)
            pm.sets(shg_refl_01, e = 1, forceElement = refl01)
            
            # (VRAY) 75% glossy vraymtl goes to mesh refl02
            shg_refl_02 = pm.sets(n = "refl_02SG", renderable = 1, empty = 1)
            shd_refl_02 = pm.shadingNode('VRayMtl', asShader = 1, n = "refl_75")
            shd_refl_02.diffuseColorAmount.set(0)
            shd_refl_02.reflectionColor.set(1,1,1)
            pm.surfaceShaderList(shd_refl_02, add = shg_refl_02)
            pm.sets(shg_refl_02, e = 1, forceElement = refl02)


    if arg is 2:
        pm.delete('diff_80', 'diff_18', 'refl_100', 'refl_75', 'diff_18SG', 'diff_80SG', 'refl_01SG', 'refl_02SG', 'LGT_REF_OBJ')
示例#37
0
import pymel.core as pm

s = pm.polySphere()[0] # second in list is the history node, if construction history is on
c = pm.polyCube()[0]

print c, s
c.setTranslation( [0,2,0] )
s.setTranslation( [1,-2,0] )

g = pm.group( s, c, n='newGroup' )

print "The children of %s are %s" % (g, g.getChildren())
#print g.getChildren()[0].getShape()
print "difference =", c.translate.get() - s.translate.get()  # basic vector operation

s2 = s.duplicate()[0]

# move the new sphere relatively along the z axis
s2.setTranslation([0,0,-2], relative=1)

# cycle through and move some verts.
# we're moving each verts a relative amount based on its vertex number
num = s2.numVertices()
for i, vert in enumerate(s2.verts):
	pm.move( vert, [ i / float(num), 0, 0 ], r=1)


# save the current scene scene
currScene = pm.saveAs( 'pymel_test_main.ma')

# the parent property gives the parent directory of the current scene.
示例#38
0
文件: mesh.py 项目: HadibOo/Forms
import pymel.core as pm
import forms.util.mesh as meshUtil

reload ( meshUtil )


sphere = pm.polySphere( subdivisionsAxis = 8, subdivisionsX = 8, subdivisionsY = 8, subdivisionsHeight = 8, radius = 10 )

mesh1 = pm.duplicate( sphere[ 0 ] )
mesh2 = pm.duplicate( sphere[ 0 ] )
mesh1[ 0 ].setAttr( 'translateZ', -20 )
mesh2[ 0 ].setAttr( 'translateZ', 20 )

meshUtil.polyWire( mesh1, depth = 0.9, extrudeMode = 0 )
meshUtil.polyWire( mesh2, depth = 0.9, extrudeMode = 1 )

print mesh1
print mesh2

# Result: [nt.Transform(u'pSphere2')]
# Result: [nt.Transform(u'pSphere3')]

mesh1 = pm.duplicate( sphere[ 0 ] )
mesh2 = pm.duplicate( sphere[ 0 ] )
mesh3 = pm.duplicate( sphere[ 0 ] )

mesh1[ 0 ].setTranslation( [ -20, 0, -10 ] )
mesh2[ 0 ].setTranslation( [ -20, 0, 10 ] )
mesh3[ 0 ].setTranslation( [ -20, 0, 0 ] )

meshUtil.combineClean( pm.group( mesh1, mesh2, mesh3 ), 'combineCleanResult' )
示例#39
0
    def setup(self):

        for i in range(0, self.total_verts):
            self.vertices.append([0, 0, 0, ''])
            self.vertices_last.append([0, 0, 0, ''])
            self.v_forces.append([0, 0, 0])
            self.vertices.append([0, 0, 0])

        # Calculate initial vertices
        counter = 0
        for i in range(0, self.sim_u):
            for j in range(0, self.sim_v):
                self.vertices[counter] = [
                    ((float(i) / (float(self.sim_u) - 1.0)) * 2.0 - 1.0) *
                    self.VERTEX_SIZE_HALF, self.VERTEX_SIZE + 1,
                    ((float(j) / (float(self.sim_v) - 1.0)) *
                     self.VERTEX_SIZE), ''
                ]
                self.vertices_last[counter] = self.vertices[counter]
                counter = counter + 1

        # Fill in triangle indices
        for i in range(0, self.num_y):
            for j in range(0, self.num_x):
                i_0 = i * (self.num_x + 1) + j
                i_1 = i_0 + 1
                i_2 = i_0 + (self.num_x + 1)
                i_3 = i_2 + 1

                if (j + i) % 2:
                    self.v_indices.append(i_0)
                    self.v_indices.append(i_2)
                    self.v_indices.append(i_1)

                    self.v_indices.append(i_1)
                    self.v_indices.append(i_2)
                    self.v_indices.append(i_3)
                else:
                    self.v_indices.append(i_0)
                    self.v_indices.append(i_2)
                    self.v_indices.append(i_3)

                    self.v_indices.append(i_0)
                    self.v_indices.append(i_3)
                    self.v_indices.append(i_1)

        # Add structural springs
        # Horizontal
        for i in range(0, self.sim_v):
            for j in range(0, self.sim_u - 1):
                self.add_spring((i * self.sim_u) + j, (i * self.sim_u) + j + 1,
                                self.KS_STRUCTURAL, self.KD_STRUCTURAL,
                                self.STRUCTURAL_SPRING_TYPE)

        # Vertical
        for i in range(0, self.sim_u):
            for j in range(0, self.sim_v - 1):
                self.add_spring((j * self.sim_u) + i,
                                ((j + 1) * self.sim_u) + i, self.KS_STRUCTURAL,
                                self.KD_STRUCTURAL,
                                self.STRUCTURAL_SPRING_TYPE)

        # Add shear springs
        for i in range(0, self.sim_v - 1):
            for j in range(0, self.sim_u - 1):
                self.add_spring((i * self.sim_u) + j,
                                ((i + 1) * self.sim_u) + j + 1, self.KS_SHEAR,
                                self.KD_SHEAR, self.SHEAR_SPRING_TYPE)
                self.add_spring(((i + 1) * self.sim_u) + j,
                                (i * self.sim_u) + j + 1, self.KS_SHEAR,
                                self.KD_SHEAR, self.SHEAR_SPRING_TYPE)

        # Add bend strings
        for i in range(0, self.sim_v):
            for j in range(0, self.sim_u - 2):
                self.add_spring((i * self.sim_u) + j, (i * self.sim_u) + j + 2,
                                self.KS_BEND, self.KD_BEND,
                                self.BEND_SPRING_TYPE)
            self.add_spring((i * self.sim_u) + (self.sim_u - 3),
                            (i * self.sim_u) + (self.sim_u - 1), self.KS_BEND,
                            self.KD_BEND, self.BEND_SPRING_TYPE)

        for i in range(0, self.sim_u):
            for j in range(0, self.sim_v - 2):
                self.add_spring((j * self.sim_u) + i,
                                ((j + 2) * self.sim_u) + i, self.KS_BEND,
                                self.KD_BEND, self.BEND_SPRING_TYPE)
            self.add_spring(((self.sim_v - 3) * self.sim_u) + i,
                            ((self.sim_v - 1) * self.sim_u) + i, self.KS_BEND,
                            self.KD_BEND, self.BEND_SPRING_TYPE)

        # Add spheres at initial vertex positions, put reference name in last field
        for i in range(0, len(self.v_indices), 3):
            p_1 = self.vertices[self.v_indices[i]]
            p_2 = self.vertices[self.v_indices[i + 1]]
            p_3 = self.vertices[self.v_indices[i + 2]]

            sphere = pm.polySphere(sx=4, sy=4, r=0.1)
            pm.move(p_1[0], p_1[1], p_1[2], sphere[0], ws=True)
            self.vertices[self.v_indices[i]][3] = sphere[0]

            sphere = pm.polySphere(sx=4, sy=4, r=0.1)
            pm.move(p_2[0], p_2[1], p_2[2], sphere[0], ws=True)
            self.vertices[self.v_indices[i + 1]][3] = sphere[0]

            sphere = pm.polySphere(sx=4, sy=4, r=0.1)
            pm.move(p_3[0], p_3[1], p_3[2], sphere[0], ws=True)
            self.vertices[self.v_indices[i + 2]][3] = sphere[0]
示例#40
0
# -*- coding: Shift_Jis -*-
import pymel.core as pm
import os

# 新規シーンファイルをつくる
pm.newFile()

# ポリゴンの球をつくる
pm.polySphere()

# シーンファイルを保存するファイルパスを指定する
pm.renameFile(os.getcwd() + '\\hello.ma')

# シーンファイルを保存する
pm.saveFile()
示例#41
0
 def setUp(self):
     cmds.file(new=1, f=1)
     self.sphere = pm.polySphere()[0]
     self.cube = pm.polyCube()[0]
     self.cone = pm.polyCone()[0]
示例#42
0
            print e
    pmc.polyColorPerVertex(selection, rgb=colour, cdo=True)
    paint.last = selection
paint.last = None

def erase(mesh):
    """ Clear / Prepare colour on mesh """
    pmc.polyColorPerVertex(mesh.vtx, rgb=BASE_COLOUR)
    mesh.displayColors.set(0)

if __name__ == '__main__':
    # Testing
    import time, threading, random
    from maya.utils import executeInMainThreadWithResult as ex
    pmc.system.newFile(force=True)
    xform, shape = pmc.polySphere() # Create a cylinder and joints
    vert_num = xform.numVertices() - 1
    erase(xform)
    def flip():
        def random_colour():
            try:
                col = [random.random() for a in range(3)]
                rng = sorted([int(random.random() * vert_num)  for a in range(2)])
                sel = xform.vtx[slice(*rng)]
                paint(sel, col)
                return True
            except pmc.MayaNodeError:
                pass
        while True:
            if not ex(random_colour): break
            time.sleep(1)
示例#43
0
 def __AddTestNodes(self):
     cube = pCore.polyCube()[0]
     sphere = pCore.polySphere()[0]
     null = pCore.spaceLocator()
     metaNode = eMetaData.MetaData()
     self.TestNodes.extend([cube, sphere, null, metaNode.MetaNode])
示例#44
0
# Create and set custom vertex colors on a polygon object
# We create a poly sphere, then add two new colorsets,
# (1) with the "shared" vertex normal
# (2) with the face normal set on all face-vertices

import pymel.core as pm     # PyMel commands

object = pm.polySphere(name='myPolySphere')

poly = pm.PyNode(object[0]).getShape()

try:
    pm.nodetypes.Mesh(poly)
    print ">> mesh:", poly.name()

except TypeError:
    print "Not a mesh"

allColorSets = poly.getColorSetNames()
print ">> color sets, before:", allColorSets

# (1) set color from shared normal at each polygon vertex

colorSet = 'mySharedNormal'

print ">> create color set:", colorSet

# create new empty custom color set
if not colorSet in allColorSets:
    poly.createColorSet(colorSetName=colorSet)
            pmc.select(sel, r=True)
    def add(s, m): s.nodes[0].add(m)
    def discard(s, m):
        for sel in s.nodes:
            if m in sel: sel.remove(m)
    def __len__(s): return sum(len(a) for a in s.nodes)
    def __iter__(s):
        for node in s.nodes:
            for mesh in node:
                yield mesh
    def __contains__(s, m): return m in set(b for a in s.nodes for b in a)
    def __repr__(s): return "Collection :: [%s]" % ",".join(repr(a) for a in s)

if __name__ == '__main__':
    # Testing
    import random
    def rand_pos(): return [random.random() * 10 - 5 for a in range(3)]
    pmc.system.newFile(force=True)
    objs = [pmc.polySphere()[0] for a in range(5)]
    for o in objs: pmc.xform(o, t=rand_pos())
    name = "OutOfControlRig"

    set1 = pmc.sets(objs[:2], n="some:thing:%s" % name)

    container = Meshes("OutOfControlRig")
    print "contains".center(20, "-")
    print container
    print "added".center(20, "-")
    for o in objs: container.add(o)
    print container
示例#46
0
	#load new scene without saving
	pm.mel.eval('file -f -new;')
	
	#if plugin is loaded unload and reload it, else reload
	if(pm.pluginInfo( 'rbRoll.py', query=True, loaded=True )):
		pm.unloadPlugin( 'rbRoll.py' )
		pm.loadPlugin( 'rbRoll.py' )
		
	else: pm.loadPlugin( 'rbRoll.py' )

except:
	print('Error Reloading Plugin')

try:
	#Create Sphere
	sphereTrans = pm.polySphere(ch = False, r = 1)[0]
	pm.select(cl = True)
	sphereShape = sphereTrans.getShape()
	pm.select(cl = True)
	
	#Create root_j and root_j_grp
	root_j = pm.joint(a = True, p = (0.0,0.0,0.0), n = 'root_j')
	pm.select(cl = True)
	root_j_grp = pm.group(root_j, n = 'root_j_grp')
	pm.select(cl = True)
	
	#create root_j_manip
	root_j_manip = pm.circle(r = 1.3, nr = (0.0,1.0,0.0), n = 'root_j_manip', ch = False)[0]
	pm.select(cl = True)
	root_j_manip_grp = pm.group(root_j_manip, n = 'root_j_manip_grp')
	pm.select(cl = True)