def setSelectedObjVertexColor(): rt.execute('max modify mode') s = list(rt.selection) if s != None and len(s) > 0: for nod in s: if HasEditPolyn(nod): rt.Select(nod) rt.subobjectLevel = 1 rt.actionMan.executeAction( 0 ,"40021") nod.SetVertexColor(rt.color( 255, 255, 255), rt.name('VertexColor')) nod.SetVertexColor(rt.color( 255, 255, 255), rt.name('Illumination')) nod.SetVertexColor(rt.color(255,0,0), rt.name('Alpha')) rt.subobjectLevel = 0 print("Obj {0} Finished".format(nod)) else: print("OBJ {0} is not an Editable Poly, tool cannot perform vertex modifications".format(nod))
def create_gizmo_control(name, init_pos=None, radius=10, color=None): """ Creates a gizmo control :param name: str :param init_pos: :param radius: :param color: :return: """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow circle_a = create_circle_control(name=name, radius=radius, color=color, init_pos=pos, axis='x') circle_b = create_circle_control(name=name, radius=radius, color=color, init_pos=pos, axis='y') circle_c = create_circle_control(name=name, radius=radius, color=color, init_pos=pos, axis='z') gizmo_ctrl = add_shape(circle_a, circle_b) gizmo_ctrl = add_shape(gizmo_ctrl, circle_c) return gizmo_ctrl
def create_circle_control(name, init_pos=None, radius=10, color=None, axis='z'): """ Creates a circle control :param name: str :param init_pos: list(float, float, float) or None :param radius: float :param color: list(float, float, float) or rt.Point3 :param axis: str """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow rt.setCommandPanelTaskMode(rt.Name('modify')) ctrl_name = rt.uniquename(name) base_circle = rt.circle(name=ctrl_name, radius=radius, steps=6, pos=pos) if str(axis).lower() == 'x': xform_mod = rt.xform() rt.addModifier(base_circle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, 90, 0)) elif str(axis).lower() == 'y': xform_mod = rt.xform() rt.addModifier(base_circle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(90, 0, 0)) base_circle.wirecolor = color rt.convertTo(base_circle, rt.SplineShape) return base_circle
def create_expose_transform( pos=None, size=1.0, is_center_marker=True, is_axis_tripod=False, is_cross=False, is_box=False, color=None): """ Creates a new expose transform node in the scene :param pos: :param size: :param is_center_marker: :param is_axis_tripod: :param is_cross: :param is_box: :param color: :return: """ pos = pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.green expose_transform = rt.ExposeTM( pos=pos, size=size, centermarker=is_center_marker, axistripod=is_axis_tripod, cross=is_cross, box=is_box) expose_transform.wirecolor = color return expose_transform
def create_box_control(name, init_pos=None, length=10, width=10, height=10, color=None): """ Creates a box control :param name: str :param init_pos: :param length: :param width: :param height: :param color: :return: """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow rt.setCommandPanelTaskMode(rt.Name('modify')) base_box = rt.Box( lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height, mapcoords=True, pos=pos, isSelected=True) rt.select(base_box) rt.convertTo(base_box, rt.PolyMeshObject) rt.subobjectLevel = 2 edge_bitarray = rt.BitArray() edge_indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] edge_bitarray.count = len(edge_indices) for i, index in enumerate(edge_indices): edge_bitarray[i] = index base_box.EditablePoly.SetSelection(rt.Name('Edge'), edge_bitarray) ctrl_name = rt.uniquename(name) base_box.EditablePoly.createShape(ctrl_name, False, base_box) rt.subobjectLevel = 0 rt.delete(base_box) box_ctrl = rt.getNodeByName(ctrl_name) rt.convertTo(box_ctrl, rt.SplineShape) box_ctrl.wirecolor = color rt.CenterPivot(box_ctrl) transform.reset_xform_and_collapse(box_ctrl, freeze=True) return box_ctrl
def create_circle_with_triangle_control(name, init_pos=None, radius=10, corner_radius=0, color=None, axis='z'): """ Creates a circle with a triangle inside control :param name: str :param init_pos: :param radius: :param corner_radius: :param color: :param axis: :return: """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow circle_ctrl = create_circle_control(name, init_pos=pos, radius=radius, color=color, axis=axis) triangle_ctrl = rt.Ngon( radius=radius, cornerRadius=corner_radius, nsides=3, circular=False, scribe=1, pos=pos, isSelected=True) xform_mod = rt.xform() rt.addModifier(triangle_ctrl, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, 0, -90)) if str(axis).lower() == 'x': xform_mod = rt.xform() rt.addModifier(triangle_ctrl, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, -90, 0)) elif str(axis).lower() == 'y': xform_mod = rt.xform() rt.addModifier(triangle_ctrl, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(-90, 0, 0)) final_ctrl = add_shape(circle_ctrl, triangle_ctrl) return final_ctrl
def create_rectangle_control(name, init_pos=None, length=10.0, width=10.0, corner_radius=0.0, color=None, axis='z'): """ Creates a rectangle control :param name: str :param init_pos: :param length: :param width: :param corner_radius: :param color: :param axis: :return: """ pos = init_pos or [0, 0, 0] if rt.classOf(pos) != rt.Point3: pos = rt.Point3(*pos) if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.yellow rt.setCommandPanelTaskMode(rt.Name('modify')) ctrl_name = rt.uniquename(name) base_rectangle = rt.rectangle(name=ctrl_name, length=length, width=width, cornerRadius=corner_radius, pos=pos) base_rectangle.wirecolor = color if str(axis).lower() == 'x': xform_mod = rt.xform() rt.addModifier(base_rectangle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(0, 90, 0)) elif str(axis).lower() == 'y': xform_mod = rt.xform() rt.addModifier(base_rectangle, xform_mod) rt.setProperty(xform_mod.gizmo, 'rotation', rt.eulerAngles(90, 0, 0)) rt.convertTo(base_rectangle, rt.SplineShape) return base_rectangle
def createThumbnail(self, useCursorPosition=False, dbPath=None, versionInt=None): """ Creates the thumbnail file. :param databaseDir: (String) If defined, this folder will be used to store the created database. :param version: (integer) if defined this version number will be used instead currently open scene version. :return: (String) Relative path of the thumbnail file """ projectPath = self.projectDir if useCursorPosition: versionInt = self.currentVersionIndex dbPath = self.currentDatabasePath else: if not dbPath or not versionInt: logger.warning(( "Both dbPath and version must be defined if useCursorPosition=False" )) versionStr = "v%s" % (str(versionInt).zfill(3)) dbDir, shotNameWithExt = os.path.split(dbPath) shotName = os.path.splitext(shotNameWithExt)[0] thumbPath = "{0}_{1}_thumb.jpg".format(os.path.join(dbDir, shotName), versionStr) relThumbPath = os.path.relpath(thumbPath, projectPath) ## Software specific section # rt = pymxs.runtime oWidth = 221 oHeight = 124 grab = rt.gw.getViewportDib() ratio = float(grab.width) / float(grab.height) if ratio <= 1.782: new_width = oHeight * ratio new_height = oHeight else: new_width = oWidth new_height = oWidth / ratio resizeFrame = rt.bitmap(new_width, new_height, color=rt.color(0, 0, 0)) rt.copy(grab, resizeFrame) thumbFrame = rt.bitmap(oWidth, oHeight, color=rt.color(0, 0, 0)) xOffset = (oWidth - resizeFrame.width) / 2 yOffset = (oHeight - resizeFrame.height) / 2 rt.pasteBitmap(resizeFrame, thumbFrame, rt.point2(0, 0), rt.point2(xOffset, yOffset)) # rt.display(thumbFrame) thumbFrame.filename = thumbPath rt.save(thumbFrame) rt.close(thumbFrame) # img = rt.gw.getViewportDib() # img.fileName = thumbPath # rt.save(img) # rt.close(img) return relThumbPath
def changeRenderSettings(dictState, settings, ipr=False): #globals reMgr = cmds.maxOps.getCurRenderElementMgr() #Full if settings == 'full': for i in configData['RenderSettingsHightDefault']: dictState[i] = configData['RenderSettingsHightDefault'][i] #Mid elif settings == 'mid': for i in configData['RenderSettingsMidDefault']: dictState[i] = configData['RenderSettingsMidDefault'][i] #Draft elif settings == 'draft': for i in configData['RenderSettingsDraftDefault']: dictState[i] = configData['RenderSettingsDraftDefault'][i] #Default elif settings == 'default': return #Vfb vRay.output_on = dictState['vfb'] #Dof vRay.dof_on = dictState['dof'] #MotionBlur vRay.moblur_on = dictState['mob'] #Displace vRay.options_displacement = dictState['disp'] #renderElements reMgr.SetElementsActive(dictState['renderElem']) #Atmosphere cmds.rendAtmosphere = dictState['atmo'] print('##ATMO : ' + str(dictState['atmo'])) cmds.rendAtmosphere = dictState['atmo'] #Override vRay.options_overrideMtl_on = dictState['override'] BaseMat = cmds.vRayMtl() BaseMat.name = "OVERRIDE_MAT" vRay.options_overrideMtl_mtl = BaseMat #Isolate if dictState['isolate'] == True: vRay.imageSampler_renderMask_type = 2 else: vRay.imageSampler_renderMask_type = dictState['isolate'] #Probalistic vRay.options_probabilisticLights = dictState['probabilisticLights'] vRay.options_probabilisticLightsCount = dictState['probabilisticCount'] #Filter Maps vRay.options_filterMaps = dictState['filterMaps'] #Image Sampler vRay.imageSampler_type = dictState['imageSampler'] #Min Shading Rate vRay.imageSampler_shadingRate = dictState['minShadingRate'] #Subdivs vRay.twoLevel_baseSubdivs = dictState['minSubdiv'] vRay.twoLevel_fineSubdivs = dictState['maxSubdiv'] #Buckets vRay.twoLevel_bucket_width = dictState['BucketWidth'] vRay.twoLevel_bucket_height = dictState['BucketWidth'] #NoiseThreshold vRay.twoLevel_threshold = dictState['noiseThreshold'] #Clamp vRay.colorMapping_clampOutput = dictState['clampOutut'] vRay.colorMapping_clampLevel = dictState['clampLevel'] #LightCache vRay.lightcache_subdivs = dictState['LightCacheSubdivs'] #IPR vRay.ipr_progressiveMode = ipr #Debug Shading Mode if dictState['debug']: reMgr.SetElementsActive(True) normalPass = cmds.VRayNormals(elementname="[rtt]_Normals") normalPass.elementname = "[rtt]_Normals" #Uv uvTex = cmds.VraySamplerInfoTex() uvTex.name = "[rtt]_Uvs" uvTex.type = 4 uvPass = cmds.VRayExtraTex(elementname="[rtt]_Uvs") uvPass.texture = uvTex uvPass.elementname = "[rtt]_Uvs" #Occ aoTex = cmds.VrayDirt() aoTex.name = "[rtt]_AO" aoTex.unoccluded_color = cmds.color(232, 232, 232) aoPass = cmds.VRayExtraTex(elementname="[rtt]_Occ") aoPass.texture = aoTex aoPass.elmentname = "[rtt]_Occ" #Add Passes reMgr.AddRenderElement(normalPass) reMgr.AddRenderElement(uvPass) reMgr.AddRenderElement(aoPass) # Render overide light material + texture vRay.options_overrideMtl_on = True customTexMat = cmds.vRayLightMtl() customTexMat.name = "OVERRIDE_TEX" vRay.options_overrideMtl_mtl = customTexMat #End of functin Update in scene dialog cmds.renderSceneDialog.commit() cmds.renderSceneDialog.update()
def _createThumbnail(self, assetName, selectionOnly=True, viewFit=True): # ssResolution = 1000 thumbPath = os.path.join(self.directory, assetName, "%s_thumb.jpg" % assetName) SSpath = os.path.join(self.directory, assetName, "%s_s.jpg" % assetName) WFpath = os.path.join(self.directory, assetName, "%s_w.jpg" % assetName) if selectionOnly: rt.IsolateSelection.EnterIsolateSelectionMode() rt.redrawViews() # selection = rt.execute("selection as array") selection = self._getSelection(asMaxArray=True) rt.clearSelection() originalState = rt.viewport.GetRenderLevel() oWidth = 1600 oHeight = 1600 rt.viewport.SetRenderLevel(rt.Name("smoothhighlights")) rt.redrawViews() grabShaded = rt.gw.getViewportDib() rt.viewport.SetRenderLevel(rt.Name("wireframe")) rt.redrawViews() grabWire = rt.gw.getViewportDib() # rt.redrawViews() ratio = float(grabShaded.width) / float(grabShaded.height) if ratio < 1.0: new_width = oHeight * ratio new_height = oHeight elif ratio > 1.0: new_width = oWidth new_height = oWidth / ratio else: new_width = oWidth new_height = oWidth resizeFrameShaded = rt.bitmap(new_width, new_height, color=rt.color(0, 0, 0)) rt.copy(grabShaded, resizeFrameShaded) resizeFrameWire = rt.bitmap(new_width, new_height, color=rt.color(0, 0, 0)) rt.copy(grabWire, resizeFrameWire) ssFrame = rt.bitmap(oWidth, oHeight, color=rt.color(0, 0, 0)) wfFrame = rt.bitmap(oWidth, oHeight, color=rt.color(0, 0, 0)) xOffset = (oWidth - resizeFrameShaded.width) / 2 yOffset = (oHeight - resizeFrameShaded.height) / 2 rt.pasteBitmap(resizeFrameShaded, ssFrame, rt.point2(0, 0), rt.point2(xOffset, yOffset)) rt.pasteBitmap(resizeFrameWire, wfFrame, rt.point2(0, 0), rt.point2(xOffset, yOffset)) # rt.display(ssFrame) # rt.display(wfFrame) thumbFrame = rt.bitmap(200, 200, color=rt.color(0, 0, 0)) rt.copy(ssFrame, thumbFrame) rt.display(thumbFrame) thumbFrame.filename = thumbPath rt.save(thumbFrame) rt.close(thumbFrame) ssFrame.filename = SSpath rt.save(ssFrame) rt.close(ssFrame) wfFrame.filename = WFpath rt.save(wfFrame) rt.close(wfFrame) # switch to original view rt.viewport.SetRenderLevel(originalState) rt.IsolateSelection.ExitIsolateSelectionMode() rt.redrawViews() return thumbPath, SSpath, WFpath
def create_end_bone(parent_bone, name='newBone', snap_to=None, match_to=None, parent=None, **kwargs): """ Creates and end bone :param parent_bone: :param snap_to: :param match_to: :param name: :param parent: :return: """ length = kwargs.pop('length', 10) width = kwargs.pop('width', 10) height = kwargs.pop('height', 5) color = kwargs.pop('color', [7, 7, 11]) main_axis = kwargs.pop('main_axis', 'z') extrude = kwargs.pop('extrude', True) freeze = kwargs.pop('freeze', False) parent_bone = node_utils.get_pymxs_node(parent_bone) snap_to = node_utils.get_pymxs_node(snap_to) match_to = node_utils.get_pymxs_node(match_to) parent = node_utils.get_pymxs_node(parent) if not parent_bone or not node_utils.node_exists(parent_bone.name): logger.error('Bone could not be created!') return False if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.color(7, 7, 11) bone_name = rt.uniquename(name) bone_box = rt.box(name=bone_name, lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height, mapcoords=True, isSelected=True) bone_box.wirecolor = color bone_box.boneEnable = True bone_box.boneAxis = rt.Name(main_axis.lower()) xform_utils.match_transforms(bone_box, parent_bone) rt.SetCommandPanelTaskMode(rt.Name('modify')) rt.convertTo(bone_box, rt.PolyMeshObject) rt.subobjectLevel = 1 vertex_bitarray = rt.BitArray() vertex_indices = [1, 2, 3, 4] vertex_bitarray.count = len(vertex_indices) for i, index in enumerate(vertex_indices): vertex_bitarray[i] = index bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), vertex_bitarray) bone_box.EditablePoly.collapse(rt.Name('Vertex')) bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), rt.BitArray()) if extrude: rt.subobjectLevel = 4 vertex_bitarray = rt.BitArray() vertex_indices = [1] vertex_bitarray.count = len(vertex_indices) for i, index in enumerate(vertex_indices): vertex_bitarray[i] = index bone_box.EditablePoly.SetSelection(rt.Name('Face'), vertex_bitarray) bone_box.EditablePoly.extrudeFaces(height) bone_box.EditablePoly.SetSelection(rt.Name('Vertex'), rt.BitArray()) rt.subobjectLevel = 0 if snap_to: xform_utils.match_position(bone_box, snap_to) if match_to: xform_utils.match_transforms(bone_box, match_to) if parent: bone_box.parent = parent if freeze: xform_utils.freeze_transform(bone_box) return bone_box
def create_bone(root_node, name='new_bone', target_node=None, parent=None, **kwargs): length = kwargs.pop('length', 10) width = kwargs.pop('width', 10) height = kwargs.pop('height', 10) color = kwargs.pop('color', [7, 7, 11]) main_axis = kwargs.pop('main_axis', 'z') flip_main_axis = kwargs.pop('flip_main_axis', False) main_rot_axis = kwargs.pop('main_rot_axis', 'y') flip_main_rot_axis = kwargs.pop('flip_main_rot_axis', False) freeze = kwargs.pop('freeze', False) root_node = node_utils.get_pymxs_node(root_node) target_node = node_utils.get_pymxs_node(target_node) parent = node_utils.get_pymxs_node(parent) if not root_node or not node_utils.node_exists(root_node.name): logger.error('Bone could not be created!') return False if color and rt.classOf(color) != rt.color: color = rt.color(*color) if not color: color = rt.color(7, 7, 11) bone_name = rt.uniquename(name) bone_box = rt.box(name=bone_name, lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height, mapcoords=True, isSelected=True) bone_box.wirecolor = color bone_box.boneEnable = True bone_box.boneAxis = rt.Name(main_axis.lower()) main_axis_index = 0 main_rot_index = 0 if main_axis.lower() == 'y': main_axis_index = 1 elif main_axis.lower() == 'z': main_axis_index = 2 if main_rot_axis.lower() == 'y': main_rot_index = 1 elif main_rot_axis.lower() == 'z': main_rot_index = 2 xform_utils.match_transforms(bone_box, root_node) if target_node and node_utils.node_exists(target_node.name): temp_helper = rt.Point(pos=rt.Point3(0, 0, 0)) xform_utils.match_position(temp_helper, bone_box) look_at_controller = rt.LookAt_Constraint() rt.setPropertyController(temp_helper.controller, 'Rotation', look_at_controller) look_at_controller.appendTarget(target_node, 1) look_at_controller.target_axis = main_axis_index look_at_controller.upnode_axis = 1 look_at_controller.StoUP_axis = main_rot_index look_at_controller.target_axisFlip = flip_main_axis look_at_controller.StoUP_axisFlip = flip_main_rot_axis xform_utils.match_transforms(bone_box, temp_helper) rt.delete(temp_helper) bone_box.height = rt.distance(root_node, target_node) if parent: bone_box.parent = parent if freeze: xform_utils.freeze_transform(bone_box) return bone_box