def smoothBoundary(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'smoothBoundary') remote.shutdown() except: remote.shutdown()
def invertTool(): remote = mmRemote() try: remote.connect() selection_utility_command(remote, 'invert') remote.shutdown() except: remote.shutdown()
def contractByOneRing(): remote = mmRemote() try: remote.connect() selection_utility_command(remote, 'contractByOneRing') remote.shutdown() except: remote.shutdown()
def createFaceGroup(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'createFaceGroup') remote.shutdown() except: remote.shutdown()
def clearAllFaceGroup(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'clearFaceGroup') remote.shutdown() except: remote.shutdown()
def sculptingTools(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'volumeBrush') remote.shutdown() except: remote.shutdown()
def separate(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'separate') remote.shutdown() except: remote.shutdown()
def connector_join(): remote = mmRemote(); remote.connect(); # accept outstanding tools, if there are any mm.accept_tool(remote) [found,id1] = mm.find_object_by_name(remote,'socket') [found,id2] = mm.find_object_by_name(remote,"connector") mm.select_objects(remote,[id1,id2]) # combine part with socket mm.begin_tool(remote, "combine") # select-all and do join # [TODO] support select-boundary-loops in API mm.select_all(remote) mm.begin_tool(remote, "join") mm.accept_tool(remote) [foundconnector,id1] = mm.find_object_by_name(remote,'connector') ## we need to rename the connector back to socket if foundconnector: cmd = mmapi.StoredCommands() cmd.AppendSceneCommand_SetObjectName(id1,'socket') remote.runCommand(cmd) ## [RMS] this block will clean up holes, but requires ability to save & restore selection! ## [TODO] we can do this now, because we can read back facegroup after createFaceGroup... #if False: # # save selection # mm.begin_tool(remote, "createFaceGroup") # mm.clear_face_selection(remote) # # do repair pass, in case join created holes (happens!) # mm.begin_tool(remote, "inspector") # mm.tool_utility_command(remote, "repairAll") # # [TODO] restore selection ## expand selection a few times, then remesh #if True: # for x in range(0,8): # mm.selection_utility_command(remote, "expandByOneRing") # mm.begin_tool(remote, "remesh") # mm.accept_tool(remote) # mm.begin_tool(remote, "smooth") # mm.set_toolparam(remote, "scale", 500.0) # mm.accept_tool(remote) #mm.clear_face_selection(remote) remote.shutdown()
def expandToConnected(): remote = mmRemote() try: remote.connect() selection_utility_command(remote, 'expandToConnected') remote.shutdown() except: remote.shutdown()
def selectAll(): remote = mmRemote() try: remote.connect() select_all(remote) remote.shutdown() except: remote.shutdown()
def planeCut(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'planeCut') remote.shutdown() except: remote.shutdown()
def cancel(): remote = mmRemote() try: remote.connect() cancel_tool(remote) remote.shutdown() except: remote.shutdown()
def accept(): remote = mmRemote() try: remote.connect() accept_tool(remote) # save_mix(remote, path) remote.shutdown() except: remote.shutdown()
def discard(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'discard') remote.shutdown() except: remote.shutdown()
def alignZCam(view): remote = mmRemote() remote.connect() divisor = 1.0 height = 0.7 eye = vec3f() if view == 0: eye.x = -10.0 eye.y = height eye.z = 0 elif view == 1: eye.x = 0.0 eye.y = height eye.z = 10.0 elif view == 2: eye.x = 0 eye.y = height eye.z = -10.0 elif view == 3: eye.x = 10.0 eye.y = height eye.z = 0 elif view == 4: eye.x = 0.0 eye.y = 10.0 eye.z = 0 elif view == 5: eye.x = 0.0 eye.y = -10.0 eye.z = 0 else: eye.x = 0.0 eye.y = 10.0 eye.z = 0.0 target = vec3f() target.x = 0.0 up = vec3f() if view == 4 or view == 5: target.y = 0.0 up.x = 1.0 up.y = 0.0 up.z = 0.0 else: target.y = height up.x = 0.0 up.y = 1.0 up.z = 0.0 target.z = 0 camera_control_set_specific_view(remote, eye, target, up) remote.shutdown()
def deformSmooth(smooth_value): remote = mmRemote() try: remote.connect() begin_tool(remote, 'smooth') set_toolparam(remote, 'smooth', smooth_value) remote.shutdown() except: remote.shutdown()
def erect_fixture(): '''Returns tuple of app subprocess and remote connection.''' mm = subprocess.Popen([app_path]) # TODO: VERY BAD, but I have not yet found a reliable way to synchronize # the app. This function hangs if the app has been started but is not # yet ready to accept commands. time.sleep(5.0) remote = mmRemote() remote.connect() return mm, remote
def selectTool(size=1.3, symmetry=False): remote = mmRemote() try: remote.connect() begin_tool(remote, 'select') set_toolparam(remote, 'radiusWorld', size) set_toolparam(remote, 'symmetry', symmetry) remote.shutdown() except: remote.shutdown()
def alignTransform(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'transform') set_toolparam(remote, 'pivotFrameMode', 0) remote.shutdown() except: remote.shutdown()
def clearScene(): try: remote = mmRemote() remote.connect() allobjects = list_objects(remote) delete_objects(remote, allobjects) remote.shutdown() except: remote.shutdown()
def import_connector(do_accept,connectorName): # initialize connection remote = mmRemote(); remote.connect(); setConnectorPath(connectorName) # find center of current selection, and then shoot ray from below this point, straight upwards, and # hope that it hits outer shell centroid = mm.get_face_selection_centroid(remote) sel_ctr = centroid (bFound, selFrame) = mm.find_ray_hit(remote, mm.addv3(sel_ctr, (0,-10,0)), (0,1,0) ) # exit out of selection tool mm.clear_face_selection(remote) # import part we want to position at selection cwd = os.getcwd() socketPath = os.path.join(cwd,'socket',connectorName) new_objs = mm.append_objects_from_file(remote, socketPath); # rename part mm.set_object_name(remote, new_objs[0], ConnectorName() ) # select new part mm.select_objects(remote, new_objs) # get bbox of part, so that we can put origin at bottom of cylinder if desired (assume file authored that way) (min,max) = mm.get_selected_bounding_box(remote) partTop = ( (min[0]+max[0])/2, max[1], (min[2]+max[2])/2 ) partCenter = ( (min[0]+max[0])/2, (min[1]+max[1])/2, (min[2]+max[2])/2 ) partH = max[1]-min[1] # RMS HACK BECAUSE OF UNITS STUPID plane_cut_setback = partH * 0.5 # start transform tool mm.begin_tool(remote, "transform") cur_origin = mm.get_toolparam(remote, "origin") dy = 0.5*partH # [RMS] currently assuming that leg is oriented wrt axis, so we keep connector vertical # compute and apply rotation #rotation = mm.make_matrix_from_axes(selFrame.x, mm.negv3(selFrame.z), selFrame.y ) #mm.set_toolparam(remote, "rotation", rotation ) # translate origin of part to frame origin translate = mm.subv3( selFrame.origin, cur_origin ) # shift along frame Z to place bottom of part on surface (ie at frame origin) translate = mm.addv3( translate, mm.mulv3s( selFrame.z, dy ) ) mm.set_toolparam(remote, "translation", translate ) # accept xform if do_accept: mm.accept_tool(remote) remote.shutdown()
def import_connector(do_accept): # initialize connection remote = mmRemote(); remote.connect(); # find center of current selection, and then shoot ray from below this point, straight upwards, and # hope that it hits outer shell centroid = mm.get_face_selection_centroid(remote) sel_ctr = centroid (bFound, selFrame) = mm.find_ray_hit(remote, mm.addv3(sel_ctr, (0,-10,0)), (0,1,0) ) # exit out of selection tool mm.clear_face_selection(remote) # import part we want to position at selection cwd = os.getcwd() socketPath = os.path.join(cwd,'socket','socket.obj') new_objs = mm.append_objects_from_file(remote, socketPath); # rename part mm.set_object_name(remote, new_objs[0], ConnectorName() ) # select new part mm.select_objects(remote, new_objs) # get bbox of part, so that we can put origin at bottom of cylinder if desired (assume file authored that way) (min,max) = mm.get_selected_bounding_box(remote) partTop = ( (min[0]+max[0])/2, max[1], (min[2]+max[2])/2 ) partCenter = ( (min[0]+max[0])/2, (min[1]+max[1])/2, (min[2]+max[2])/2 ) partH = max[1]-min[1] # RMS HACK BECAUSE OF UNITS STUPID plane_cut_setback = partH * 0.5 # start transform tool mm.begin_tool(remote, "transform") cur_origin = mm.get_toolparam(remote, "origin") dy = 0.5*partH # [RMS] currently assuming that leg is oriented wrt axis, so we keep connector vertical # compute and apply rotation #rotation = mm.make_matrix_from_axes(selFrame.x, mm.negv3(selFrame.z), selFrame.y ) #mm.set_toolparam(remote, "rotation", rotation ) # translate origin of part to frame origin translate = mm.subv3( selFrame.origin, cur_origin ) # shift along frame Z to place bottom of part on surface (ie at frame origin) translate = mm.addv3( translate, mm.mulv3s( selFrame.z, dy ) ) mm.set_toolparam(remote, "translation", translate ) # accept xform if do_accept: mm.accept_tool(remote) remote.shutdown()
def softTransition(soft_value): remote = mmRemote() try: remote.connect() selection_utility_command(remote, 'optimizeBoundary') begin_tool(remote, 'offset') set_toolparam(remote, 'softenWorld', soft_value) remote.shutdown() except: remote.shutdown()
def remeshSpecial(): remote = mmRemote() try: remote.connect() begin_tool(remote, 'remesh') set_toolparam(remote, 'density', 0.5) set_toolparam(remote, 'smooth', 1.0) set_toolparam(remote, 'preserveGroups', True) accept_tool(remote) except: remote.shutdown()
def inspector(): remote = mmRemote() try: remote.connect() cancel_tool(remote) begin_tool(remote, 'inspector') tool_utility_command(remote, 'repairAll') accept_tool(remote) remote.shutdown() except: remote.shutdown()
def boolean(obj1, obj2): remote = mmRemote() try: remote.connect() [found1, id1] = find_object_by_name(remote, obj1) [found2, id2] = find_object_by_name(remote, obj2) if found1 and found2: select_objects(remote, [id1, id2]) begin_tool(remote, 'difference') remote.shutdown() except: remote.shutdown()
def saveFile(path, name=None): try: remote = mmRemote() remote.connect() if not name: name = 'Auto_Save.mix' fileName = str(os.path.join(path, name)) save_mix(remote, fileName) remote.shutdown() except: remote.shutdown()
def reOrientModel(path): tmpDirectory = os.path.join(path, 'tmp') fileName = str(os.path.join(tmpDirectory, 'tmp.obj')) xAvg, yAvg, zAvg, xRot, zRot, rotationVector = calculateEigenVectors(fileName, 0) ## make another 270 degree rotation about y axis angle = math.pi/2 #yRotation = np.matrix([[math.cos(angle), 0,-math.sin(angle)], [0, 1.0,0],[math.sin(angle), 0,math.cos(angle)]]) xRotation =np.matrix([[1, 0, 0], [0, m.cos(angle), -m.sin(angle)],[0, m.sin(angle), m.cos(angle)]]) zRotation =np.matrix([[math.cos(angle), -math.sin(angle), 0], [math.sin(angle), math.cos(angle), 0], [0, 0, 1]]) if xRot: rotationVector = np.dot(xRotation, rotationVector) elif zRot: rotationVector = np.dot(zRotation, rotationVector) rotation =[] a = rotationVector.item((0, 0)) b = rotationVector.item((0, 1)) c = rotationVector.item((0, 2)) d = rotationVector.item((1, 0)) e = rotationVector.item((1, 1)) f = rotationVector.item((1, 2)) g = rotationVector.item((2, 0)) h = rotationVector.item((2, 1)) i = rotationVector.item((2, 2)) remote = mmRemote() try: remote.connect() result = to_scene_xyz(remote, xAvg, yAvg, zAvg) xAvg = result[0] yAvg = result[1] zAvg = result[2] #translate from scene to world coordinates result2 = to_scene_xyz(remote, 0, 0, 0) xAvg = xAvg - result2[0] yAvg = yAvg - result2[1] zAvg = zAvg - result2[2] begin_tool(remote, 'transform') set_toolparam(remote, 'rotation', (a, b, c, d, e, f, g, h, i)) set_toolparam(remote, 'translation', (-xAvg, -yAvg, -zAvg)) remote.shutdown() except: remote.shutdown() finally: os.remove (fileName)
def offsetDistance(distance, connected=False): remote = mmRemote() try: remote.connect() selection_utility_command(remote, 'optimizeBoundary') begin_tool(remote, 'offset') set_toolparam(remote, 'offsetWorld', distance) if checked: set_toolparam(remote, 'connected', connected) remote.shutdown() except: remote.shutdown()
def exportStepModel(path, step_number): try: remote = mmRemote() remote.connect() name = 'Step ' + str(step_number) + '.mix' directory = os.path.join(path, 'Steps') if not os.path.exists(directory): os.makedirs(directory) fileName = str(os.path.join(directory, name)) save_mix(remote, fileName) remote.shutdown() except: remote.shutdown()
def exportTempModel(path): try: remote = mmRemote() remote.connect() name = 'tmp.obj' directory = os.path.join(path, 'tmp') if not os.path.exists(directory): os.makedirs(directory) fileName = str(os.path.join(directory, name)) save_current(remote, fileName) remote.shutdown() except: remote.shutdown()
def connector_join(): remote = mmRemote(); remote.connect(); # accept outstanding tools, if there are any mm.accept_tool(remote) [found,id1] = mm.find_object_by_name(remote,SocketName()) [found,id2] = mm.find_object_by_name(remote,ConnectorName()) mm.select_objects(remote,[id1,id2]) # combine part with socket mm.begin_tool(remote, "combine") # select-all and do join # [TODO] support select-boundary-loops in API mm.select_all(remote) mm.begin_tool(remote, "join") mm.accept_tool(remote) # [RMS] this block will clean up holes, but requires ability to save & restore selection! # [TODO] we can do this now, because we can read back facegroup after createFaceGroup... if False: # save selection mm.begin_tool(remote, "createFaceGroup") mm.clear_face_selection(remote) # do repair pass, in case join created holes (happens!) mm.begin_tool(remote, "inspector") mm.tool_utility_command(remote, "repairAll") # [TODO] restore selection # expand selection a few times, then remesh if True: for x in range(0,8): mm.selection_utility_command(remote, "expandByOneRing") mm.begin_tool(remote, "remesh") mm.accept_tool(remote) mm.begin_tool(remote, "smooth") mm.set_toolparam(remote, "scale", 500.0) mm.accept_tool(remote) mm.clear_face_selection(remote) remote.shutdown()