Пример #1
2
def lcObj_exportObjs(*args, **kwargs):
  ''' Export .obj files from selected geometry, either as one combined file or as individual files per object.  Will recognize and convert poly smooth preview to geometry for export '''
  global prefix
  path = pm.textField(prefix+'_textField_export_path', query=True, text=True)
  objPrefix = pm.textField(prefix+'_textField_prefix', query=True, text=True)
  if objPrefix:
    objPrefix+='_'

  if path:

    sel = pm.ls(sl=True)

    if sel:
      sel = geometry.filterForGeometry(sel)
      print sel

      #undo is the easiest way to work on geometry temporarily
      pm.undoInfo(openChunk=True)

      if pm.checkBox(prefix+'_checkBox_use_smooth', query=True, v=True):
        for obj in sel:
          pm.select(obj)
          #find the objects currently displayed as smooth and create converted poly copies
          if pm.displaySmoothness(q=True, polygonObject=True)[0] == 3:
            pm.mel.performSmoothMeshPreviewToPolygon()

      if pm.checkBox(prefix+'_checkBox_export_indi', query=True, v=True):
        #export objects individually
        for obj in sel:
          pm.select(obj)
          name = str(obj)
          exportString = path+'/'+objPrefix+name+'.obj'
          pm.exportSelected(exportString, force=True, options='groups=1;ptgroups=1;materials=0;smoothing=1;normals=1', type='OBJexport', pr=True, es=True)

      else:
        #export as one object
        pm.select(sel)
        name = ''
        while name == '':
          dialog = pm.promptDialog(title='OBJ Name', message='Enter Name:', button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel')
          if dialog == 'OK':
            name = pm.promptDialog(query=True, text=True)
            if name:
              exportString = path+'/'+objPrefix+name+'.obj'
              pm.exportSelected(exportString, force=True, options='groups=1;ptgroups=1;materials=0;smoothing=1;normals=1', type='OBJexport', pr=True, es=True)
            else:
              pm.warning("You didn't type a name for your obj")
          if dialog == 'Cancel':
            break

      pm.undoInfo(closeChunk=True)
      pm.undo()
      pm.select(clear=True)

  else:
    pm.warning('Did you specify a path?')
Пример #2
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)
Пример #3
0
    def initialStructure(self, stepDict):
        # setting objects
        self.geo_root = pm.PyNode("geo_root")

        # set the preview smooth division to 0
        ts = self.geo_root.getChildren(allDescendents=True)
        pm.displaySmoothness(ts, polygonObject=0)

        self.facial_local_setups = pm.createNode(
            "transform",
            name="facial_local_setup",
            p=stepDict["mgearRun"].setupWS)

        # reparent geo root
        pm.parent(self.geo_root, stepDict["mgearRun"].model)
Пример #4
0
def lcObj_exportObjs(*args, **kwargs):
    ''' Export .obj files from selected geometry, either as one combined file or as individual files per object.  Will recognize and convert poly smooth preview to geometry for export '''
    global lct_cfg
    global prefix
    global defaultPath

    path = pm.textField(prefix+'_textField_export_path', query=True, text=True)
    objPrefix = pm.textField(prefix+'_textField_prefix', query=True, text=True)
    if objPrefix:
        objPrefix+='_'

    if path and path != defaultPath:

        sel = pm.ls(sl=True)

        if sel:
            sel = lcGeometry.Geometry.filterForGeometry(sel)
            #undo is the easiest way to work on geometry temporarily
            pm.undoInfo(openChunk=True)

            if sel:

                if pm.checkBox(prefix+'_checkBox_use_smooth', query=True, v=True):
                    for obj in sel:
                        pm.select(obj)
                        #find the objects currently displayed as smooth and create converted poly copies
                        if pm.displaySmoothness(q=True, polygonObject=True)[0] == 3:
                            pm.mel.performSmoothMeshPreviewToPolygon()

                if pm.checkBox(prefix+'_checkBox_export_indi', query=True, v=True):
                    #export objects individually
                    for obj in sel:
                        pm.select(obj)
                        nameSplit = str(obj).split('|')
                        if len(nameSplit) > 1:
                            name = nameSplit[-1]
                        else:
                            name = nameSplit[0]
                        exportString = os.path.normpath(os.path.join(path,str(objPrefix+name+'.obj')))
                        try:
                            pm.exportSelected(exportString, force=True, options='groups=1;ptgroups=1;materials=0;smoothing=1;normals=1', type='OBJexport', pr=True, es=True)
                            lcUtility.Utility.lc_print('Exporting: {0}'.format(exportString))
                        except:
                            lcUtility.Utility.lc_print_exception('Failed to export: {0}'.format(exportString))
                    #undo export individually
                    pm.undoInfo(closeChunk=True)
                    pm.undo()

                else:
                    #export as one object
                    pm.select(sel)
                    name = ''
                    while name == '':
                        dialog = pm.promptDialog(title='OBJ Name', message='Enter Name:', button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel')
                        if dialog == 'OK':
                            name = pm.promptDialog(query=True, text=True)
                            if name:
                                exportString = os.path.normpath(os.path.join(path,str(objPrefix+name+'.obj')))
                                try:
                                    pm.exportSelected(exportString, force=True, options='groups=1;ptgroups=1;materials=0;smoothing=1;normals=1', type='OBJexport', pr=True, es=True)
                                    pm.undoInfo(closeChunk=True)
                                    pm.undo()
                                    lcUtility.Utility.lc_print('Exporting: {0}'.format(exportString))
                                except:
                                    pm.undoInfo(closeChunk=True)
                                    pm.undo()
                                    lcUtility.Utility.lc_print('Failed to export: {0}'.format(exportString), mode='warning')
                            else:
                                pm.undoInfo(closeChunk=True)
                                pm.undo()
                                lcUtility.Utility.lc_print("You didn't type a name for your obj", mode='warning')
                        if dialog == 'Cancel':
                            pm.undoInfo(closeChunk=True)
                            pm.undo()
                            break

                pm.select(sel)

            else:
                lcUtility.Utility.lc_print('Select a mesh first', mode='warning')
        else:
            lcUtility.Utility.lc_print('Select a mesh first', mode='warning')
    else:
        lcUtility.Utility.lc_print('Did you set a path?', mode='warning')
Пример #5
0
def lcObj_exportObjs(*args, **kwargs):
    ''' Export .obj files from selected geometry, either as one combined file or as individual files per object.  Will recognize and convert poly smooth preview to geometry for export '''
    global prefix
    path = pm.textField(prefix + '_textField_export_path',
                        query=True,
                        text=True)
    objPrefix = pm.textField(prefix + '_textField_prefix',
                             query=True,
                             text=True)
    if objPrefix:
        objPrefix += '_'

    if path:

        sel = pm.ls(sl=True)

        if sel:
            sel = geometry.filterForGeometry(sel)
            print sel

            #undo is the easiest way to work on geometry temporarily
            pm.undoInfo(openChunk=True)

            if pm.checkBox(prefix + '_checkBox_use_smooth', query=True,
                           v=True):
                for obj in sel:
                    pm.select(obj)
                    #find the objects currently displayed as smooth and create converted poly copies
                    if pm.displaySmoothness(q=True,
                                            polygonObject=True)[0] == 3:
                        pm.mel.performSmoothMeshPreviewToPolygon()

            if pm.checkBox(prefix + '_checkBox_export_indi',
                           query=True,
                           v=True):
                #export objects individually
                for obj in sel:
                    pm.select(obj)
                    name = str(obj)
                    exportString = path + '/' + objPrefix + name + '.obj'
                    pm.exportSelected(
                        exportString,
                        force=True,
                        options=
                        'groups=1;ptgroups=1;materials=0;smoothing=1;normals=1',
                        type='OBJexport',
                        pr=True,
                        es=True)

            else:
                #export as one object
                pm.select(sel)
                name = ''
                while name == '':
                    dialog = pm.promptDialog(title='OBJ Name',
                                             message='Enter Name:',
                                             button=['OK', 'Cancel'],
                                             defaultButton='OK',
                                             cancelButton='Cancel',
                                             dismissString='Cancel')
                    if dialog == 'OK':
                        name = pm.promptDialog(query=True, text=True)
                        if name:
                            exportString = path + '/' + objPrefix + name + '.obj'
                            pm.exportSelected(
                                exportString,
                                force=True,
                                options=
                                'groups=1;ptgroups=1;materials=0;smoothing=1;normals=1',
                                type='OBJexport',
                                pr=True,
                                es=True)
                        else:
                            pm.warning("You didn't type a name for your obj")
                    if dialog == 'Cancel':
                        break

            pm.undoInfo(closeChunk=True)
            pm.undo()
            pm.select(clear=True)

    else:
        pm.warning('Did you specify a path?')
Пример #6
0
def unsmooth_all():
    logger.debug("Unsmooth")
    all_geo = pmc.ls(type='mesh')
    pmc.displaySmoothness(all_geo, du=0, dv=0, pw=4, ps=1, po=1)
    return True
def tglSmoothDisp():
	cur_smoothness = pm.displaySmoothness(q=1,polygonObject=1)
	if cur_smoothness[0]>1:
		pm.mel.eval("setDisplaySmoothness 1;")
	else:
		pm.mel.eval("setDisplaySmoothness 3;")
Пример #8
0
def createHairMesh(profilesList,
                   name="hairMesh#",
                   cSet="hairCrease",
                   mat="",
                   lengthDivs=7,
                   widthDivs=4):
    '''create a Hair Tube with auto crease and material from list of Curve Profiles'''
    print profilesList
    if not profilesList or all(
        [type(o.getShape()) != pm.nodetypes.NurbsCurve for o in profilesList]):
        print "no Profiles"
        return
    pm.select(profilesList)
    pm.nurbsToPolygonsPref(pt=1, un=4, vn=7, f=2, ut=2, vt=2)
    HairMesh = pm.loft(n=name,
                       po=1,
                       ch=1,
                       u=1,
                       c=0,
                       ar=1,
                       d=3,
                       ss=1,
                       rn=0,
                       rsn=True)
    ###
    #lock all Transform
    lockTransform(HairMesh[0])
    #custom Attribute add
    HairMesh[0].addAttr('lengthDivisions', min=1, at='long', dv=lengthDivs)
    HairMesh[0].addAttr('widthDivisions', min=4, at='long', dv=widthDivs)
    HairMesh[0].setAttr('lengthDivisions', e=1, k=1)
    HairMesh[0].setAttr('widthDivisions', e=1, k=1)
    HairTess = pm.listConnections(HairMesh)[-1]
    HairMesh[0].connectAttr('widthDivisions', HairTess + ".uNumber")
    HairMesh[0].connectAttr('lengthDivisions', HairTess + ".vNumber")
    HairMeshShape = HairMesh[0].getShape()
    ###
    #set Crease
    pm.select(HairMeshShape.e[0, 2], r=1)
    pm.runtime.SelectEdgeLoopSp()
    sideEdges = pm.selected()
    if bool(pm.ls(cSet, type=pm.nodetypes.CreaseSet)):
        hsSet = pm.ls(cSet, type=pm.nodetypes.CreaseSet)[0]
    else:
        hsSet = pm.nodetypes.CreaseSet(name=cSet)
        hsSet.setAttr('creaseLevel', 2.0)
    for e in sideEdges:
        pm.sets(hsSet, forceElement=e)
    #assign Texture
    HairUV = HairMeshShape.map
    pm.polyEditUV(HairUV, pu=0.5, pv=0.5, su=0.3, sv=1)
    pm.polyEditUV(HairUV, u=rand.uniform(-0.1, 0.1))
    ###
    #Add Vray OpenSubdiv
    pm.select(HairMesh[0], r=1)
    addVrayOpenSubdivAttr()
    ###
    #set Smoothness
    pm.displaySmoothness(po=3)
    ###
    #set Material
    if bool(pm.ls(mat, type=pm.nodetypes.ShadingEngine)):
        pm.sets(pm.ls(mat)[0], forceElement=HairMesh[0])
    return HairMesh
Пример #9
0
    def build_phase_1(self):
        self.side_prefix = str(self.ui.cb_side_prefix.currentText())
        self.up_down_prefix = str(self.ui.cb_up_down_prefix.currentText())

        self.joint_radius = float(self.ui.spin_joint_size.value())

        if self.center_eye_position is None:
            self.show_warning(
                "Make sure you've set an object that's the center of the eye!")
            return

        if len(self.lid_vertices) == 0:
            self.show_warning(
                "Make sure you've set the points for the eyelid!")
            return

        if self.head_joint is None:
            self.show_warning("Make sure you've set the head joint!")
            return

        if self.head_skin is None:
            self.show_warning("Make sure you've set the head mesh!")
            return

        if pm.objExists("%s_%s_lid_aim_locator_group" %
                        (self.side_prefix, self.up_down_prefix)):
            self.show_warning(
                "Check your side and up/down prefix, this already exists in the scene!"
            )
            return

        # create the joint and locator groups
        pm.select(None)
        lid_aim_locator_group = pm.PyNode(
            pm.group(name="%s_%s_lid_aim_locator_group" %
                     (self.side_prefix, self.up_down_prefix)))
        pm.select(None)

        lid_aim_locator_group.setTranslation(self.center_eye_position,
                                             worldSpace=True)
        pm.makeIdentity(lid_aim_locator_group, translate=True)

        # make a list we can append the positions of every vertex to, this list is used to build the high res curve
        vertex_position_list = []

        # make a list to add the aim locators to, so we can iterate over this list when we need to connect the locators to the high res curve
        aim_locator_list = []

        # build the locators and joints at the position of every vertex
        index = 1
        for vertex in self.lid_vertices:
            vertex_position = pm.xform(vertex,
                                       query=True,
                                       worldSpace=True,
                                       translation=True)
            vertex_position_list.append(vertex_position)

            skin_joint = pm.joint(
                name="%s_%s_eyelid_skin_joint_%02d" %
                (self.side_prefix, self.up_down_prefix, index),
                position=vertex_position,
                radius=self.joint_radius)
            pm.select(None)
            center_joint = pm.joint(
                name="%s_%s_eyelid_center_joint_%02d" %
                (self.side_prefix, self.up_down_prefix, index),
                position=self.center_eye_position,
                radius=self.joint_radius)

            pm.parent(skin_joint, center_joint)
            self.add_joint_to_skin(skin_joint, self.head_skin)
            pm.joint(center_joint,
                     edit=True,
                     orientJoint="xyz",
                     secondaryAxisOrient="yup",
                     children=True,
                     zeroScaleOrient=True)

            pm.parent(center_joint, self.head_joint)
            pm.select(None)

            aim_locator = pm.spaceLocator(
                absolute=True,
                name="%s_%s_eyelid_aim_locator_%02d" %
                (self.side_prefix, self.up_down_prefix, index))
            aim_locator.translate.set(vertex_position)
            aim_locator.centerPivots()
            aim_locator_shape = pm.listRelatives(shapes=True)[0]
            aim_locator_shape.localScaleX.set(self.joint_radius)
            aim_locator_shape.localScaleY.set(self.joint_radius)
            aim_locator_shape.localScaleZ.set(self.joint_radius)

            aim_locator_list.append(aim_locator)
            pm.parent(aim_locator, lid_aim_locator_group)

            pm.aimConstraint(aim_locator,
                             center_joint,
                             maintainOffset=True,
                             weight=1,
                             aimVector=(1, 0, 0),
                             upVector=(0, 1, 0),
                             worldUpType="scene")

            index += 1

        # build the high res curve
        eyelid_high_res_curve = pm.curve(
            name="%s_%s_eyelid_high_res_curve" %
            (self.side_prefix, self.up_down_prefix),
            point=vertex_position_list,
            degree=1)
        self.add_attribute(
            eyelid_high_res_curve, "eyelidCurve",
            "%s_%s_high" % (self.side_prefix, self.up_down_prefix))
        eyelid_high_res_curve_shape = pm.listRelatives(eyelid_high_res_curve,
                                                       shapes=True)[0]
        self.set_shape_node_color(eyelid_high_res_curve_shape, (1, 1, 0))
        eyelid_high_res_curve.centerPivots()

        # build the low res curve
        eyelid_low_res_curve = pm.duplicate(
            eyelid_high_res_curve,
            name="%s_%s_eyelid_low_res_curve" %
            (self.side_prefix, self.up_down_prefix))[0]
        pm.displaySmoothness(eyelid_low_res_curve,
                             divisionsU=3,
                             divisionsV=3,
                             pointsWire=16)
        pm.rebuildCurve(eyelid_low_res_curve,
                        degree=3,
                        endKnots=True,
                        spans=2,
                        keepRange=1,
                        replaceOriginal=True,
                        rebuildType=0)
        eyelid_low_res_curve.eyelidCurve.set(
            "%s_%s_low" % (self.side_prefix, self.up_down_prefix))

        eyelid_low_res_curve_shape = pm.listRelatives(eyelid_low_res_curve,
                                                      shapes=True)[0]
        self.set_shape_node_color(eyelid_low_res_curve_shape, (0, 0, 1))
        eyelid_low_res_curve.centerPivots()

        # parent the curves in their group
        if not pm.objExists(
                "%s_eyelid_deformer_curve_group" % self.side_prefix):
            eyelid_deformer_curve_group = pm.group(
                eyelid_high_res_curve,
                eyelid_low_res_curve,
                name="%s_eyelid_deformer_curve_group" % self.side_prefix)
        else:
            eyelid_deformer_curve_group = pm.PyNode(
                "%s_eyelid_deformer_curve_group" % self.side_prefix)
            pm.parent(eyelid_high_res_curve, eyelid_deformer_curve_group)
            pm.parent(eyelid_low_res_curve, eyelid_deformer_curve_group)

        # connect the locators to the high res curve
        for locator in aim_locator_list:
            npoc = pm.createNode("nearestPointOnCurve", name="npoc")
            position = locator.getTranslation(space="world")
            eyelid_high_res_curve_shape.worldSpace >> npoc.inputCurve
            npoc.inPosition.set(position)

            u = npoc.parameter.get()

            pci_node = pm.createNode("pointOnCurveInfo",
                                     name=locator.name().replace(
                                         "locator", "PCI"))
            eyelid_high_res_curve_shape.worldSpace >> pci_node.inputCurve
            pci_node.parameter.set(u)
            pci_node.position >> locator.translate

            pm.delete(npoc)

        if not pm.objExists("DO_NOT_TOUCH"):
            pm.select(None)
            self.do_not_touch_group = pm.PyNode(pm.group(name="DO_NOT_TOUCH"))
        else:
            self.do_not_touch_group = pm.PyNode("DO_NOT_TOUCH")

        pm.parent(eyelid_deformer_curve_group, self.do_not_touch_group)
        pm.parent(lid_aim_locator_group, self.do_not_touch_group)

        self.do_not_touch_group.visibility.set(False)
        #eyelid_deformer_curve_group.visibility.set(False)

        self.show_success_message("Phase 1 built successfully!")
        return "success"
Пример #10
0
def reset_display_smoothness():
    for top in pm.ls(assemblies=True, type='transform'):
        try:
            pm.displaySmoothness(top, polygonObject=0)
        except:
            pass