def run(self): if not self.outputpath: print("Error missing output path") # build a mesh based on the trajectory drawed by the wipers for dummySet in self.dummySets: point1 = rt.getnodebyname(dummySet[0]) point2 = rt.getnodebyname(dummySet[1]) if point1 and point2: wMesh = self.buildWiperMesh(point1, point2) if self.wiperMesh == rt.undefined: self.wiperMesh = wMesh else: rt.polyop.attach(self.wiperMesh, wMesh) else: print("Error: with wiper points names") # bake the previously built mesh vertex color data into the secondary uv set of the glass if self.wiperMesh: rt.convertToMesh(self.theGlass) self.wiperMesh.name = WIPERMESH_NAME dirName = os.path.dirname(self.outputpath) basename = os.path.basename(self.outputpath) info = os.path.splitext(basename) textureName = info[0] noPaddingTexPath = os.path.join( dirName, textureName + "_noPadding_RG" + info[1]) paddingTextPath = os.path.join( dirName, textureName + "_padding_B" + info[1]) self.projectVertexColor(self.theGlass, self.wiperMesh, paddingTextPath, 64) self.projectVertexColor(self.theGlass, self.wiperMesh, noPaddingTexPath, 0) rt.maxOps.CollapseNode(self.wiperMesh, False) rt.delete(self.wiperMesh)
def zdepthchannel(): '''Access the Z-Depth Channel''' prev_renderer = rt.renderers.current rt.renderers.current = rt.Default_Scanline_Renderer() voxelbox = re.compile("^VoxelBox") for tbd in filter(lambda o: voxelbox.match(o.name), list(rt.objects)): rt.delete(tbd) zdepth_name = rt.Name("zdepth") rbmp = rt.render(outputsize=rt.Point2(32, 32), channels=[zdepth_name], vfb=False) z_d = rt.getChannelAsMask(rbmp, zdepth_name) rt.progressStart("Rendering Voxels...") for y in range(1, rbmp.height): print("y =", y) if not rt.progressupdate(100.0 * y / rbmp.height): break pixel_line = rt.getPixels(rbmp, rt.Point2(0, y - 1), rbmp.width) z_line = rt.getPixels(z_d, rt.Point2(0, y - 1), rbmp.width) for x in range(1, rbmp.width): print("x =", x, z_line[x].value) box = rt.box(width=10, length=10, height=(z_line[x].value / 2)) box.pos = rt.Point3(x * 10, -y * 10, 0) box.wirecolor = pixel_line[x] box.name = rt.uniqueName("VoxelBox") rt.progressEnd() rt.renderers.current = prev_renderer
def remove_nodes(max_nodes): """ Deletes given max nodes :param max_nodes: list<MaxPlus.INode> """ max_nodes = python.force_list(max_nodes) for obj in max_nodes: rt.delete(obj)
def runEmptyNodeCleaner(): sceneNodes = [] sceneNodes = node.getAllNodes() NodesToRemove = [] for sn in sceneNodes: cl = rt.classOf(sn) if cl == rt.Editable_Poly or cl == rt.Editable_Mesh: NF = sn.numfaces if NF <= 0: NodesToRemove.append(sn) for NTR in NodesToRemove: print("{0} was deleted because it was not containing any geometry". format(NTR)) rt.delete(NTR)
def mirrorNode(node, mirrorAxis): original_parent = node.GetParent() if MAXVERSION() < MAX2017: temp_mesh = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere) temp_parent = MaxPlus.Factory.CreateNode(temp_mesh) else: temp_parent = rt.sphere() node.SetParent(temp_parent) rtNode = rt.getNodeByName(temp_parent.GetName()) p = rt.Point3(1, 1, 1) if mirrorAxis == "X": p = rt.Point3(-1, 1, 1) elif mirrorAxis == "Y": p = rt.Point3(1, -1, 1) elif mirrorAxis == "Z": p = rt.Point3(1, 1, -1) else: print("Error axis do not match") rt.scale(rtNode, p) node.SetParent(original_parent) MaxPlus.INode.Delete(temp_parent) if MAXVERSION() < MAX2017 else rt.delete( temp_parent)
def remove_nodes_by_ids(nodes_ids): """ Removes objects with the given ids :param nodes_ids: list<int> """ nodes_ids = python.force_list(nodes_ids) loop_ids = nodes_ids[:] scene_objects = list(rt.objects)[:] with pymxs.undo(True): for obj in scene_objects: if not loop_ids: return if obj.handle in loop_ids: loop_ids.remove(obj.handle) rt.delete(obj)
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 startTransfer(self): mxs.execute("max create mode") with pymxs.undo(True): for i in self.skinMeshes: skinSource = mxs.skinUtils.ExtractSkinData(i[0]) skinSource = mxs.getNodeByName("SkinData_{}".format(i[0].name)) count = mxs.skinOps.GetNumberBones(i[1]) newBones = [] for item in range(count): # print(item +1, i[0].name, mxs.skinOps.GetBoneNode(i[1], item + 1)) try: newBones.append(self.dict[mxs.skinOps.GetBoneNode( i[1], item + 1)]) except: pass oldSkin = i[1] oldSkin.enabled = False skinMod = mxs.Skin() skinMod.name = "Transfered Skin" mxs.addModifier(i[0], skinMod, before=i[2] - 1) for bone in newBones: mxs.skinOps.addbone(skinMod, bone, 0) mxs.select(i[0]) mxs.selectmore(skinSource) mxs.skinUtils.ImportSkinDataNoDialog(True, False, False, False, False, 1.0, 0) mxs.delete(skinSource) mxs.clearSelection() mxs.execute("max modify mode")
def projectVertexColor(self, nodeToBake, nodeToProject, outputPath, padding): """ Project the vertex color of a given node to a given surface and bake the result in the given path Parameters ---------- nodeToBake : INode the node used to bake the texture nodeToProject : INode the node used to project the vertex color outputPath : str the path of the baked texture """ rt.disableSceneRedraw() rt.select(nodeToBake) snap = rt.snapshot(nodeToBake, name=nodeToBake.name + "_new") snap.material = rt.standard(showInViewport=False, name="GlassMat") nodeToProject.material = rt.standard(diffuseMap=rt.Vertex_Color(), showInViewport=False, name="WiperMat") # --Clear all render elements snap.iNodeBakeProperties.removeAllBakeElements() # --Preparing the Bake Elements: be1 = rt.diffusemap() # --instance of the bake element class be1.outputSzX = be1.outputSzY = 1024 # --set the size of the baked map --specifythe full file path, name and type: be1.fileType = outputPath be1.fileName = rt.filenameFromPath(be1.fileType) be1.filterOn = True # --enable filtering be1.shadowsOn = False # --disable shadows be1.lightingOn = False # --disable lighting be1.enabled = True # --enable baking snap.iNodeBakeProperties.nDilations = padding # --expand the texturea bit snap.iNodeBakeProperties.addBakeElement(be1) # --add first element snap.iNodeBakeProperties.bakeEnabled = True # --enabling baking snap.iNodeBakeProperties.bakeChannel = 2 # --channel to bake snap.INodeBakeProjProperties.bakeEnabled = True # --enabling baking snap.INodeBakeProjProperties.bakeChannel = 2 # --channel to bake snap.INodeBakeProjProperties.subObjBakeChannel = 2 snap.INodeBakeProjProperties.enabled = True #enable projection baking # add a projection modifier and set it as the projection source projection = rt.Projection() rt.addModifier(snap, projection) projection.addObjectNode(nodeToProject) projection.resetCage() snap.INodeBakeProjProperties.projectionMod = projection snap.INodeBakeProjProperties.rayMissColor = rt.Point3(0, 0, 0) #select the object enter modify mode, offset the cage and bake the texture at the given path rt.select( snap ) # --we are baking the selection, so we select the object --Call the rendererto bake both elements: rt.execute("max modify mode") projection.pushCage(0.1) rt.render(rendertype=rt.Name("bakeSelected"), vfb=False, progressBar=True, outputSize=rt.Point2(1024, 1024)) print("baked image in {0}".format(be1.fileType)) rt.delete(snap) rt.enableSceneRedraw() rt.CompleteRedraw()
def execute(): # Define the target object my_target = mxs.selection[0] # Reset the pivot my_target.pivot = my_target.center # Define the grid object my_grid = mxs.grid() # Define the vector vector = my_target.transform.position - mxs.inverse( mxs.viewport.getTM()).position # Define the length of the target distance = (mxs.length(my_target.min - my_target.max) / 2) # Normalize + UP vector (Z) X = mxs.normalize(vector) Z = mxs.point3(0, 0, 1) Y = mxs.normalize(mxs.cross(Z, X)) Z = mxs.normalize(mxs.cross(X, Y)) # Define a new transform based on vector my_transform = mxs.matrix3(Z, Y, X, my_target.transform.position) # Edit the position of the transform new_position = my_transform.position - (X * distance) my_transform = mxs.matrix3(Z, Y, X, new_position) # Assign the transform to the grid my_grid.transform = my_transform # Activate the grid mxs.activegrid = my_grid # Define spline method def setMode(name): name.curveType = 1 try: # Set iso view mxs.execute("max vpt iso user") # Define user draw curves curves = mxs.startObjectCreation(mxs.FreehandSpline, returnNewNodes=True, newNodeCallback=setMode) # Define modifiers noise_mod = mxs.Noisemodifier() quad_mod = mxs.Quadify_Mesh() extrude_mod = mxs.Extrude() # Change the parameters extrude_mod.amount = distance * 2 quad_mod.quadsize = 2 noise_mod.scale = 10 noise_mod.fractal = True noise_mod.strength = mxs.point3(2, 10, 2) # Add the modifiers mxs.addmodifier(curves, extrude_mod) mxs.addmodifier(curves, quad_mod) mxs.addmodifier(curves, noise_mod) # Define cutter splines mxs.ProCutter.CreateCutter(curves, 1, True, True, False, True, True) # Define stock object mxs.ProCutter.AddStocks(curves[0], my_target, 1, 1) # Set perspective view mxs.execute("max vpt persp user") # Deactivate and delete the grid mxs.activegrid = None mxs.delete(my_grid) except: # Set perspective view mxs.execute("max vpt persp user") # Deactivate and delete the grid mxs.activegrid = None mxs.delete(my_grid) print("cancled")
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