def get_vertex_info(remote, objectid, vertexid): """returns tuple of 3-tuples of vertex info""" cmd1 = mmapi.StoredCommands() key1 = cmd1.AppendSceneCommand_GetVertexInfo(objectid, vertexid) remote.runCommand(cmd1) p = mmapi.vec3f() n = mmapi.vec3f() c = mmapi.vec3f() cmd1.GetSceneCommandResult_GetVertexInfo(key1, p, n, c) return ( (p.x,p.y,p.z), (n.x,n.y,n.z), (c.x,c.y,c.z) )
def append_pattern_segment(remote, p1, p2, scale1, scale2, is_scene = True): """Run a Tool utility command, with optional argument (see ::AppendToolUtilityCommand in StoredCommands.h)""" if ( is_scene == False ): p1 = to_scene(remote, p1) p2 = to_scene(remote, p2) cmd = mmapi.StoredCommands() op1 = mmapi.vec3f() op1.x = p1[0]; op1.y = p1[1]; op1.z = p1[2]; op2 = mmapi.vec3f() op2.x = p2[0]; op2.y = p2[1]; op2.z = p2[2]; cmd.AppendToolUtilityCommand( "addSegment", op1,op2, scale1,scale2 ) remote.runCommand(cmd)
def find_ray_hit(remote, ray_origin, ray_direction): cmd = mmapi.StoredCommands() o = mmapi.vec3f() o.x = ray_origin[0]; o.y = ray_origin[1]; o.z = ray_origin[2] d = mmapi.vec3f() d.x = ray_direction[0]; d.y = ray_direction[1]; d.z = ray_direction[2] key = cmd.AppendQueryCommand_FindRayIntersection(o,d) remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindRayIntersection(key, frame) hitFrame = mmFrame() hitFrame.setFromMM(frame) return (bOK, hitFrame)
def find_ray_hit(remote, ray_origin, ray_direction): """Find the intersection of a ray (specified by 3-tuples for origin and direction) and the 3D surface. Returns a tuple (bOK, hitFrame), where bOK is a boolean indicating if a hit was found, and hitFrame is an mmFrame at the hit point, with Z axis oriented to the surface normal""" cmd = mmapi.StoredCommands() o = mmapi.vec3f() o.x = ray_origin[0]; o.y = ray_origin[1]; o.z = ray_origin[2] d = mmapi.vec3f() d.x = ray_direction[0]; d.y = ray_direction[1]; d.z = ray_direction[2] key = cmd.AppendQueryCommand_FindRayIntersection(o,d) remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindRayIntersection(key, frame) hitFrame = mmFrame() hitFrame.set_frame3f(frame) return (bOK, hitFrame)
def find_ray_hit(remote, ray_origin, ray_direction): """Find the intersection of a ray (specified by 3-tuples for origin and direction) and the 3D surface. Returns a tuple (bOK, hitFrame), where bOK is a boolean indicating if a hit was found, and hitFrame is an mmFrame at the hit point, with Z axis oriented to the surface normal""" cmd = mmapi.StoredCommands() o = mmapi.vec3f() o.x = ray_origin[0]; o.y = ray_origin[1]; o.z = ray_origin[2] d = mmapi.vec3f() d.x = ray_direction[0]; d.y = ray_direction[1]; d.z = ray_direction[2] key = cmd.AppendQueryCommand_FindRayIntersection(o,d) remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindRayIntersection(key, frame) hitFrame = mmFrame() hitFrame.setFromMM(frame) return (bOK, hitFrame)
def find_ray_hit(remote, ray_origin, ray_direction): cmd = mmapi.StoredCommands() o = mmapi.vec3f() o.x = ray_origin[0] o.y = ray_origin[1] o.z = ray_origin[2] d = mmapi.vec3f() d.x = ray_direction[0] d.y = ray_direction[1] d.z = ray_direction[2] key = cmd.AppendQueryCommand_FindRayIntersection(o, d) remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindRayIntersection(key, frame) hitFrame = mmFrame() hitFrame.setFromMM(frame) return (bOK, hitFrame)
def set_vertex_color(remote, objectid, vertexid, col): cmd1 = mmapi.StoredCommands() p = mmapi.vec3f() p.x = col[0] p.y = col[1] p.z = col[2] key1 = cmd1.AppendSceneCommand_SetVertexColor(objectid, vertexid, p) remote.runCommand(cmd1)
def set_vertex_position(remote, objectid, vertexid, pos): cmd1 = mmapi.StoredCommands() p = mmapi.vec3f() p.x = pos[0] p.y = pos[1] p.z = pos[2] key1 = cmd1.AppendSceneCommand_SetVertexPosition(objectid, vertexid, p) remote.runCommand(cmd1)
def find_nearest(remote, position): cmd = mmapi.StoredCommands() v = mmapi.vec3f() key = cmd.AppendQueryCommand_FindNearestPoint(position[0], position[1], position[2]); remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindNearestPoint(key, frame) hitFrame = mmFrame() hitFrame.setFromMM(frame) return (bOK, hitFrame)
def find_nearest(remote, position): """Find the nearest point on the 3D surface to the input 3-tuple. Returns a tuple (bOK, hitFrame), where bOK is a boolean indicating if a nereast point was found, and hitFrame is an mmFrame at the hit point, with Z axis oriented to the surface normal""" cmd = mmapi.StoredCommands() v = mmapi.vec3f() key = cmd.AppendQueryCommand_FindNearestPoint(position[0], position[1], position[2]); remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindNearestPoint(key, frame) hitFrame = mmFrame() hitFrame.setFromMM(frame) return (bOK, hitFrame)
def find_nearest(remote, position): """Find the nearest point on the 3D surface to the input 3-tuple. Returns a tuple (bOK, hitFrame), where bOK is a boolean indicating if a nereast point was found, and hitFrame is an mmFrame at the hit point, with Z axis oriented to the surface normal""" cmd = mmapi.StoredCommands() v = mmapi.vec3f() key = cmd.AppendQueryCommand_FindNearestPoint(position[0], position[1], position[2]); remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindNearestPoint(key, frame) hitFrame = mmFrame() hitFrame.set_frame3f(frame) return (bOK, hitFrame)
def find_nearest(remote, position): cmd = mmapi.StoredCommands() v = mmapi.vec3f() key = cmd.AppendQueryCommand_FindNearestPoint(position[0], position[1], position[2]) remote.runCommand(cmd) frame = mmapi.frame3f() bOK = cmd.GetQueryResult_FindNearestPoint(key, frame) hitFrame = mmFrame() hitFrame.setFromMM(frame) return (bOK, hitFrame)
def tool_utility_command(remote, command_name, arg = -99): """Run a Tool utility command, with optional argument (see ::AppendToolUtilityCommand in StoredCommands.h)""" cmd = mmapi.StoredCommands() if ( isinstance(arg, int) and arg == -99 ): cmd.AppendToolUtilityCommand( command_name ) elif ( isinstance(arg, tuple) and len(arg) == 3 ): v = mmapi.vec3f() v.x = arg[0]; v.y = arg[1]; v.z = arg[2]; cmd.AppendToolUtilityCommand( command_name, v ) else: cmd.AppendToolUtilityCommand( command_name, arg ) remote.runCommand(cmd)
def tool_utility_command(remote, command_name, arg=-99): """Run a Tool utility command, with optional argument (see ::AppendToolUtilityCommand in StoredCommands.h)""" cmd = mmapi.StoredCommands() if (isinstance(arg, int) and arg == -99): cmd.AppendToolUtilityCommand(command_name) elif (isinstance(arg, tuple) and len(arg) == 3): v = mmapi.vec3f() v.x = arg[0] v.y = arg[1] v.z = arg[2] cmd.AppendToolUtilityCommand(command_name, v) else: cmd.AppendToolUtilityCommand(command_name, arg) remote.runCommand(cmd)
def to_vec3f(vec): p = mmapi.vec3f() p.x = vec[0] p.y = vec[1] p.z = vec[2] return p
cmd = mmapi.StoredCommands() key = cmd.AppendSceneCommand_AppendMeshFile(pathObject) remote.runCommand(cmd) #id cylender cmd = mmapi.StoredCommands() cmd_key = cmd.AppendSceneCommand_FindObjectByName("cylender.stl") remote.runCommand(cmd) result_val = mmapi.any_result() bFound = cmd.GetSceneCommandResult_FindObjectByName( cmd_key, result_val) print(result_val.i) supportId = result_val.i break v = mmapi.vec3f() v.x = x v.y = y v.z = z cmd.AppendBeginToolCommand("transform") cmd.AppendToolParameterCommand("dimensions", v) cmd.AppendCompleteToolCommand("accept") remote.runCommand(cmd) # align the shape in the center # construct commands to run cmd = mmapi.StoredCommands() cmd.AppendBeginToolCommand("align") cmd.AppendCompleteToolCommand("accept") # execute commands