Example #1
0
def build(type):
    global shapes, widmenu, rangename
    sce = bpy.data.scenes.active
    ob = sce.objects.active

    try:
        ob.getData(mesh=1).key
    except:
        Blender.Draw.PupMenu('Aborting%t|Object has no keys')
        return

    loc = Window.GetCursorPos()
    range = makeRange(sce, type, rangename.val)
    controller = makeController(sce, rangename.val)
    text = makeText(sce, rangename.val)

    range.restrictRender = True
    controller.restrictRender = True
    text.restrictRender = True

    range.setLocation(loc)
    controller.setLocation(loc)
    text.setLocation(loc)

    range.makeParent([controller], 1)
    range.makeParent([text], 0)

    sce.update()

    setupDrivers(ob, controller, widmenu.val)
Example #2
0
 def NewObject(flag):
 	global ob, me, sc
 	if flag == 1: DumpData()
 	DeselectAllObjects()
 	sc = Scene.GetCurrent()
 	cursorpos = Window.GetCursorPos()
 	ob = Object.New('Mesh', 'Cyl_')
 	me = NMesh.New('MyCylMesh')
 	ob.setLocation(cursorpos)
 	ob.link(me)
 	sc.link(ob)
Example #3
0
from Blender import Camera,Object,Scene,Constraint,Window,Draw,Mathutils

scn = Scene.GetCurrent()

convert = "TargetCam?%t|Convert Active Camera %x1|Create New Camera %x2"
result = Draw.PupMenu(convert)

if result == 1:
	camob = scn.objects.camera

else:
	cam = Camera.New('persp', 'TCam')
	camob = scn.objects.new(cam)
	scn.objects.camera = camob
	camob.setLocation(Window.GetCursorPos())

if camob:
	
	target = scn.objects.new('Empty', (camob.name + '.target'))
	matrix = camob.getMatrix()
	tvect = Mathutils.Vector([0,0,-10])
	targetv = tvect*matrix
	target.setLocation(targetv)
	
	cam = camob.data
	#cam.drawLimits = 1
	cam.drawSize = 2.0
	campos = Mathutils.Vector([camob.dloc[0],camob.dloc[1],camob.dloc[2]])
	dofdistv = campos-targetv
	dofdist = dofdistv.length
def main():

    scn = bpy.data.scenes.active
    ob = scn.objects.active
    if not ob or ob.type != 'Mesh':
        return

    is_editmode = Window.EditMode()
    if is_editmode:
        Window.EditMode(0)

    mousedown_wait()  # so the menu items clicking dosnt trigger the mouseclick

    Window.DrawProgressBar(0.0, '')
    Window.DrawProgressBar(0.1, '(1 of 3) Click on a face corner')

    # wait for a click
    mouse_buttons = Window.GetMouseButtons()
    while not mouse_buttons & LMB:
        sys.sleep(10)
        mouse_buttons = Window.GetMouseButtons()

        # Allow for RMB cancel
        if mouse_buttons & RMB:
            return

    while mouse_buttons & LMB:
        sys.sleep(10)
        mouse_buttons = Window.GetMouseButtons()

    Window.DrawProgressBar(0.2, '(2 of 3 ) Click confirms the U coords')

    mousedown_wait()

    obmat = ob.matrixWorld
    screen_x, screen_y = Window.GetMouseCoords()
    mouseInView, OriginA, DirectionA = mouseViewRay(screen_x, screen_y, obmat)

    if not mouseInView or not OriginA:
        return

    me = ob.getData(mesh=1)

    # Get the face under the mouse
    face_click, isect, side = BPyMesh.pickMeshRayFace(me, OriginA, DirectionA)
    if not face_click:
        return

    proj_z_component = face_click.no
    if not face_click:
        return

    # Find the face vertex thats closest to the mouse,
    # this vert will be used as the corner to map from.
    best_v = None
    best_length = 10000000
    vi1 = None
    for i, v in enumerate(face_click.v):
        l = (v.co - isect).length
        if l < best_length:
            best_v = v
            best_length = l
            vi1 = i

    # now get the 2 edges in the face that connect to v
    # we can work it out fairly easerly
    if len(face_click) == 4:
        if vi1 == 0: vi2, vi3 = 3, 1
        elif vi1 == 1: vi2, vi3 = 0, 2
        elif vi1 == 2: vi2, vi3 = 1, 3
        elif vi1 == 3: vi2, vi3 = 2, 0
    else:
        if vi1 == 0: vi2, vi3 = 2, 1
        elif vi1 == 1: vi2, vi3 = 0, 2
        elif vi1 == 2: vi2, vi3 = 1, 0

    face_corner_main = face_click.v[vi1].co
    face_corner_a = face_click.v[vi2].co
    face_corner_b = face_click.v[vi3].co

    line_a_len = (face_corner_a - face_corner_main).length
    line_b_len = (face_corner_b - face_corner_main).length

    orig_cursor = Window.GetCursorPos()
    Window.SetCursorPos(face_corner_main.x, face_corner_main.y,
                        face_corner_main.z)

    SHIFT = Window.Qual.SHIFT
    MODE = 0  # firstclick, 1, secondclick
    mouse_buttons = Window.GetMouseButtons()

    project_mat = Matrix([0, 0, 0], [0, 0, 0], [0, 0, 0])

    def get_face_coords(f):
        f_uv = f.uv
        return [(v.co - face_corner_main, f_uv[i]) for i, v in enumerate(f.v)]

    if me.faceUV == False:
        me.faceUV = True

    coords = [(co, uv) for f in me.faces if f.sel
              for co, uv in get_face_coords(f)]

    coords_orig = [uv.copy() for co, uv in coords]
    USE_MODIFIER = using_modifier(ob)

    while 1:
        if mouse_buttons & LMB:
            if MODE == 0:
                mousedown_wait()
                Window.DrawProgressBar(
                    0.8, '(3 of 3 ) Click confirms the V coords')
                MODE = 1  # second click

                # Se we cont continually set the length and get float error
                proj_y_component_orig = proj_y_component.copy()
            else:
                break

        elif mouse_buttons & RMB:
            # Restore old uvs
            for i, uv_orig in enumerate(coords_orig):
                coords[i][1][:] = uv_orig
            break

        mouse_buttons = Window.GetMouseButtons()
        screen_x, screen_y = Window.GetMouseCoords()
        mouseInView, OriginA, DirectionA = mouseViewRay(
            screen_x, screen_y, obmat)

        if not mouseInView:
            continue

        # Do a ray tri intersection, not clipped by the tri
        new_isect = Intersect(face_corner_main, face_corner_a, face_corner_b,
                              DirectionA, OriginA, False)
        new_isect_alt = new_isect + DirectionA * 0.0001

        # The distance from the mouse cursor ray vector to the edge
        line_isect_a_pair = LineIntersect(new_isect, new_isect_alt,
                                          face_corner_main, face_corner_a)
        line_isect_b_pair = LineIntersect(new_isect, new_isect_alt,
                                          face_corner_main, face_corner_b)

        # SHIFT to flip the axis.
        is_shift = Window.GetKeyQualifiers() & SHIFT

        if MODE == 0:
            line_dist_a = (line_isect_a_pair[0] - line_isect_a_pair[1]).length
            line_dist_b = (line_isect_b_pair[0] - line_isect_b_pair[1]).length

            if line_dist_a < line_dist_b:
                proj_x_component = face_corner_a - face_corner_main
                y_axis_length = line_b_len
                x_axis_length = (line_isect_a_pair[1] -
                                 face_corner_main).length
            else:
                proj_x_component = face_corner_b - face_corner_main
                y_axis_length = line_a_len
                x_axis_length = (line_isect_b_pair[1] -
                                 face_corner_main).length

            proj_y_component = proj_x_component.cross(proj_z_component)

            proj_y_component.length = 1 / y_axis_length
            proj_x_component.length = 1 / x_axis_length

            if is_shift: proj_x_component.negate()

        else:
            proj_y_component[:] = proj_y_component_orig
            if line_dist_a < line_dist_b:
                proj_y_component.length = 1 / (line_isect_a_pair[1] -
                                               new_isect).length
            else:
                proj_y_component.length = 1 / (line_isect_b_pair[1] -
                                               new_isect).length

            if is_shift: proj_y_component.negate()

        # Use the existing matrix to make a new 3x3 projecton matrix
        project_mat[0][:] = -proj_y_component
        project_mat[1][:] = -proj_x_component
        project_mat[2][:] = proj_z_component

        # Apply the projection matrix
        for proj_co, uv in coords:
            uv[:] = (project_mat * proj_co)[0:2]

        if USE_MODIFIER:
            me.update()

        Window.Redraw(Window.Types.VIEW3D)

    Window.SetCursorPos(*orig_cursor)
    if is_editmode:
        Window.EditMode(1)

    Window.RedrawAll()
Example #5
0
    pop_list=[]

    for i in items:
        path=i[3].split('/')[:-1]
        extend_pop_for(pop_list,path)
        if len(path):
            append_to_inner(pop_list,(i[3].split('/')[-1],items.index(i)))
        else:
            pop_list.append((i[3].split('/')[-1],items.index(i)))


    r = Draw.PupTreeMenu(pop_list)
    if r >= 0:
        print items[r]
        set_pref_key('xplane.tools','annotate.last_item',items[r])
        cur = Window.GetCursorPos()
        mm = TranslationMatrix(Vector([0,0,0])).resize4x4()
        #mm = TranslationMatrix(Vector(Window.GetCursorPos())).resize4x4()
        importer=OBJimport(items[r][1],mm)
        importer.verbose=1
        try:
            sel = Blender.Scene.GetCurrent().objects.selected
            old_objs = set(Blender.Scene.GetCurrent().objects)
            obj_list = importer.doimport()
            new_objs = set(Blender.Scene.GetCurrent().objects)
            wrapper=Blender.Object.New('Empty','OBJ%s' % items[r][0].split('/')[-1])
            Blender.Scene.GetCurrent().objects.link(wrapper)
            added = new_objs-old_objs
            wrapper.makeParent(list(added),1,0)
            if len(sel) == 1:
                sel[0].makeParent([wrapper],1,0)