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 main(): """Create a cylinder and add a bend modifier to it.""" cyl = rt.cylinder() cyl.radius = 10 cyl.height = 30 bend = rt.Bend() bend.bendAngle = 45 rt.addModifier(cyl, bend)
def create(): for mod in rt.modifier.classes: try: created = mod() print(created) box = create_box() rt.addModifier(box, created) yield box except RuntimeError: pass
def _uvSnaps(self, assetName): originalSelection = rt.execute("selection as array") validShapes = rt.execute( "for o in selection where superClassOf o == geometryClass collect o" ) if len(validShapes) > 10: msg = "There are %s objects for UV snapshots.\nAre you sure you want to include snapshots to the Asset?" % ( len(validShapes)) state = rt.queryBox(msg, title='Too many objects for UV Snapshot') if state: pass else: return assetDirectory = os.path.join(self.directory, assetName) UVdir = os.path.join(assetDirectory, "UV_snaps") if not os.path.isdir(os.path.normpath(UVdir)): os.makedirs(os.path.normpath(UVdir)) rt.execute("max modify mode") for i in validShapes: objName = i.name UVpath = os.path.join(UVdir, '%s_uv.jpg' % objName) rt.select(i) defUnwrapMod = rt.Unwrap_UVW() rt.addModifier(i, defUnwrapMod) defUnwrapMod.setMapChannel = 1 defUnwrapMod.renderuv_fillmode = 0 defUnwrapMod.renderuv_seamColor = rt.Name("green") defUnwrapMod.renderuv_showframebuffer = False defUnwrapMod.renderuv_force2sided = False defUnwrapMod.renderuv_fillColor = rt.Name("black") defUnwrapMod.renderuv_showoverlap = False defUnwrapMod.renderuv_overlapColor = rt.Name("red") defUnwrapMod.renderuv_edgeColor = rt.Name("white") defUnwrapMod.renderuv_visibleedges = True defUnwrapMod.renderuv_invisibleedges = False defUnwrapMod.renderuv_seamedges = False defUnwrapMod.renderUV(UVpath) rt.deleteModifier(i, defUnwrapMod) rt.select(originalSelection)
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 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 move_node(node_name, amount=None, move_vertices=False, use_local_axis=True): """ Moves given node :param node_name: :param amount: :param move_vertices: :param use_local_axis: :return: """ node_to_move = node_utils.get_pymxs_node(node_name) if not node_to_move: return amount = amount or [0, 0, 0] if rt.classOf(amount) != rt.Point3: amount = rt.Point3(*amount) if move_vertices: xform_mod = rt.xform() rt.addModifier(node_to_move, xform_mod) rt.setProperty(xform_mod.gizmo, 'position', amount) rt.CollapseStack(node_to_move) else: if use_local_axis: coordsys = getattr(rt, '%coordsys_context') local_coordsys = rt.Name('local') prev_coordsys = coordsys(local_coordsys, None) # store current coordsys rt.move(node_to_move, amount) # this is done in local axis coordsys(prev_coordsys, None) # restore previous coordsys else: rt.move(node_to_move, amount)
def convertToMesh(self): if not self.useAlpha_chb.isChecked() and not self.isValidTexture( self.texturePath): self.info_lbl = "Specified texture is missing or not found" return subdivideMod = rt.subdivide() volSel = rt.Vol__Select() for o in rt.selection: texturePath = self.texturePath if self.useAlpha_chb.isChecked(): mat = o.material if rt.classOf(mat) == rt.FlightSim: texturePath = mat.BaseColorTex elif rt.classOf(mat) == rt.Standardmaterial: texturePath = mat.opacityMap.filename else: self.info_lbl = "Currently only FlightSim material are supported" continue if not os.path.isabs(texturePath): texturePath = os.path.join( rt.pathConfig.getCurrentProjectFolder(), texturePath) if not self.isValidTexture(texturePath): continue p = rt.convertToPoly(o) rt.addModifier(o, subdivideMod) subdivideMod.size = 0.001 rt.convertTo(o, rt.editable_poly) #hack adding the modifier only one time do not work for first object in iteration WTF? rt.addModifier(o, subdivideMod) subdivideMod.size = 0.001 rt.convertTo(o, rt.editable_poly) rt.addModifier(p, volSel) volSel.level = 1 volSel.invert = True bitmap = rt.Bitmaptexture(filename=texturePath) volSel.texture = bitmap volSel.method = 0 volSel.volume = 4 p = rt.convertToPoly(o) rt.subObjectLevel = 1 p.delete(pymxs.runtime.Name("Vertex")) rt.convertTo(o, rt.editable_poly)
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 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 buildWiperMesh(self, p1, p2): """ Build the wiper mesh Parameters ---------- p1 : Point3 the world position of the first dummy placed on the exterior part of the wiper p2 : Point3 the world position of the second dummy placed on the exterior part of the wiper """ animationLength = self.animInEndFrame - self.animInStartFrame + 1 projectMeshVertices = [] projectMeshFaces = [] vColors = [rt.Point3(0, 0, 0) for i in range(animationLength * 2)] vert_count = 0 if rt.DEBUG_MODE: print( "------------------------------------------------------------------" ) #fill projectMeshVertices with the exterior points of the wiper for each frame f = self.animInStartFrame while f <= self.animInEndFrame: with at(f): projectMeshVertices.append(p1.transform.position) projectMeshVertices.append(p2.transform.position) f += 1 # fill the vertexColors array during animation IN vIndex = 0 f = self.animInStartFrame while f <= self.animInEndFrame: with at(f): self.setColorByFrame(f, vColors[vIndex]) self.setColorByFrame(f, vColors[vIndex + 1]) f += 1 vIndex += 2 # fill the vertexColors array during animation OUT vIndex = 0 f = self.animOutEndFrame while f >= self.animOutStartFrame: with at(f): self.setColorByFrame(f, vColors[vIndex]) self.setColorByFrame(f, vColors[vIndex + 1]) f -= 1 vIndex += 2 axis = rt.Point3(1, 0, 0) result = rt.dot(p2.transform.position, axis) for i in range(1, len(projectMeshVertices) - 1): #build the triangle with the righ orientation if i % 2 != 0: projectMeshFaces.append( rt.Point3(vert_count + 3, vert_count + 2, vert_count + 1)) else: projectMeshFaces.append( rt.Point3(vert_count + 2, vert_count + 3, vert_count + 1)) vert_count += 1 #build the mesh with an array of vertex and triangles projectionMesh = rt.mesh(vertices=rt.Array(*(projectMeshVertices)), faces=rt.Array(*(projectMeshFaces))) rt.defaultVCFaces(projectionMesh) #set the vertex color for each vertex for i in range(len(projectMeshVertices)): rt.setVertColor(projectionMesh, i + 1, vColors[i]) if result > 0: rt.select(projectionMesh) rt.execute("max modify mode") normalModifier = rt.NormalModifier() rt.addModifier(projectionMesh, rt.NormalModifier()) normal = rt.Name("Normal") projectionMesh.modifiers[normal].flip = True rt.maxOps.CollapseNode(projectionMesh, False) #quadrify rt.select(projectionMesh) rt.convertToPoly(projectionMesh) rt.execute("max modify mode") rt.PolyToolsModeling.Quadrify(True, False) edge = rt.Name("EDGE") edgeNumber = projectionMesh.EditablePoly.getNumEdges() edgeList = [1] if result < 0 else [2] edgeSelection = rt.BitArray(*(edgeList)) rt.subObjectLevel = 2 projectionMesh.EditablePoly.SetSelection(edge, edgeSelection) projectionMesh.EditablePoly.SelectEdgeRing() projectionMesh.connectEdgeSegments = 3 rt.execute('macros.run "Ribbon - Modeling" "ConnectEdges"') return projectionMesh