示例#1
0
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()
示例#2
0
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()
示例#3
0
print "scene bbox min: ", fMin
print "scene bbox max: ", fMax

# convert to world-space (ie current units)
fMinW = mm.to_world(r, fMin)
fMaxW = mm.to_world(r, fMax)
print "world bbox min: ", fMinW
print "world bbox max: ", fMaxW
print "one world unit in scene dimensions: ", mm.to_scene(r, 1.0)
print "\n"

# construct a ray from far-away-pt through center of bbox, along +Z axis
center = lerpv3(fMin, fMax, 0.5)
diag = subv3(fMax, fMin)
ray_dir = (0.0,0.0,1.0)
ray_origin = subv3(center, mulv3s(ray_dir, 25.0*max(diag)))

# hit-test ray against object
(bHit, hitFrame) = mm.find_ray_hit(r, ray_origin, ray_dir)
print "hit: ", bHit, " world pos: ", hitFrame.origin;

# find nearest point on sfc to (-2,0,0)
(bFound, nearFrame) = mm.find_nearest(r, (-2,0,0) )
print "found: ", bFound, " world pos: ", mm.toW(r, nearFrame.origin);

#done!
r.shutdown()