Beispiel #1
0
def sv_main(verts=[], num_verts=20, new_divisions=20):
    '''
    verts is expecting 4 (unique) 3d coordinates
    '''

    in_sockets = [['v', 'verts', verts], ['s', 'num_verts', num_verts],
                  ['s', 'new_divisions', new_divisions]]

    out_sockets = [['v', 'Vecs', []], ['s', 'Edges', []],
                   ['v', 'Vecs ctrl', []], ['s', 'Edges ctrl', []],
                   ['v', 'Vecs norm', []], ['s', 'Edges norm', []]]

    if not verts:
        return in_sockets, out_sockets

    # defend against div by zero
    new_divisions = max(new_divisions, 1)

    # while developing, it can be useful to uncomment this
    if 'get_length' in globals():
        import imp
        imp.reload(spline_utils)
        from spline_utils import get_length, get_verts_n_edges

    f = list(map(Vector, verts[0]))
    knot1, ctrl_1, ctrl_2, knot2 = f
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, num_verts)
    farc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, 870)

    tlen, lengths = get_length(farc_verts)
    # print(tlen)
    segment_width = tlen / new_divisions
    print('new div length = ', segment_width)
    k = get_verts_n_edges(farc_verts, lengths, segment_width)

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n + 1) for n in range(len(arc_verts) - 1)]

    norm_verts = [v[:] for v in k]
    norm_edges = [(n, n + 1) for n in range(len(k) - 1)]

    controls = verts[0]
    control_edges = [[(0, 1), (2, 3)]]

    out_sockets[0][2] = [arc_verts]
    out_sockets[1][2] = [arc_edges]

    out_sockets[2][2] = [controls]
    out_sockets[3][2] = control_edges

    out_sockets[4][2] = [norm_verts]
    out_sockets[5][2] = [norm_edges]

    return in_sockets, out_sockets
Beispiel #2
0
def sv_main(verts=[], num_verts=20):

    in_sockets = [['v', 'verts', verts], ['s', 'divisions', num_verts]]

    out_sockets = [['v', 'Vecs', []], ['s', 'Edges', []],
                   ['v', 'Vecs ctrl', []], ['s', 'Edges ctrl', []]]

    if not verts:
        return in_sockets, out_sockets

    f = list(map(Vector, verts[0]))
    knot1, ctrl_1, ctrl_2, knot2 = f
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, num_verts)

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n + 1) for n in range(len(arc_verts) - 1)]

    controls = verts[0]
    control_edges = [[(0, 1), (2, 3)]]

    out_sockets[0][2] = [arc_verts]
    out_sockets[1][2] = [arc_edges]

    out_sockets[2][2] = controls
    out_sockets[3][2] = control_edges

    return in_sockets, out_sockets
def get_arc_from_state(points, guide_verts, context):

    NUM_VERTS = context.scene.NumVerts
    MODE_SIGN = context.scene.FilletSign
    mode = context.scene.FilletMode

    # get control points and knots.
    h_control = guide_verts[0]
    knot1, knot2 = points[0], points[1]

    # draw fillet ( 2 modes )        
    if mode == 'KAPPA':
        kappa_ctrl_1 = knot1.lerp(h_control, context.scene.CurveHandle1)
        kappa_ctrl_2 = knot2.lerp(h_control, context.scene.CurveHandle2)
        arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2, NUM_VERTS)

    if mode == 'TRIG':
        if MODE_SIGN == 'POS':
            arc_centre = guide_verts[1]
            arc_verts = get_correct_verts(arc_centre, knot1, knot2, context)
        if MODE_SIGN == 'NEG':
            arc_centre = guide_verts[0]
            arc_verts = get_correct_verts(arc_centre, knot2, knot1, context)

    return arc_verts                                        
Beispiel #4
0
def get_arc_from_state(points, guide_verts, context):

    NUM_VERTS = context.scene.NumVerts
    MODE_SIGN = context.scene.FilletSign
    mode = context.scene.FilletMode

    # get control points and knots.
    h_control = guide_verts[0]
    knot1, knot2 = points[0], points[1]

    # draw fillet ( 2 modes )
    if mode == 'KAPPA':
        kappa_ctrl_1 = knot1.lerp(h_control, context.scene.CurveHandle1)
        kappa_ctrl_2 = knot2.lerp(h_control, context.scene.CurveHandle2)
        arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2,
                            NUM_VERTS)

    if mode == 'TRIG':
        if MODE_SIGN == 'POS':
            arc_centre = guide_verts[1]
            arc_verts = get_correct_verts(arc_centre, knot1, knot2, context)
        if MODE_SIGN == 'NEG':
            arc_centre = guide_verts[0]
            arc_verts = get_correct_verts(arc_centre, knot2, knot1, context)

    return arc_verts
def sv_main(verts=[], num_verts=20):

    in_sockets = [
        ['v', 'verts', verts],
        ['s', 'divisions', num_verts]]

    out_sockets = [ 
        ['v', 'Vecs', []], 
        ['s', 'Edges', []],
        ['v', 'Vecs ctrl', []], 
        ['s', 'Edges ctrl', []]
    ]

    if not verts:
        return in_sockets, out_sockets

    f = list(map(Vector, verts[0]))
    knot1, ctrl_1, ctrl_2, knot2 = f
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, num_verts)

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n+1) for n in range(len(arc_verts)-1)]

    controls = verts[0]
    control_edges = [[(0,1),(2,3)]]
    
    out_sockets[0][2] = [arc_verts]
    out_sockets[1][2] = [arc_edges]

    out_sockets[2][2] = controls
    out_sockets[3][2] = control_edges


    return in_sockets, out_sockets
Beispiel #6
0
def generate_bezier(verts=None, num_verts=20):
    knot1, ctrl_1, ctrl_2, knot2 = [Vector(v) for v in verts]
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, max(3, num_verts))

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n + 1) for n in range(len(arc_verts) - 1)]
    return arc_verts, arc_edges
Beispiel #7
0
def generate_bezier(verts=None, num_verts=20):
    knot1, ctrl_1, ctrl_2, knot2 = [Vector(v) for v in verts]
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, max(3, num_verts))

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n+1) for n in range(len(arc_verts)-1)]
    return arc_verts, arc_edges
def draw_callback_px(self, context):

    objlist = context.selected_objects
    names_of_empties = [i.name for i in objlist]

    region = context.region
    rv3d = context.space_data.region_3d
    points, guide_verts = init_functions(self, context)

    NUM_VERTS = context.scene.NumVerts
    mode = context.scene.FilletMode
    # draw bevel
    draw_polyline_from_coordinates(context, points, "GL_LINE_STIPPLE")

    # draw symmetry line
    draw_polyline_from_coordinates(context, guide_verts, "GL_LINE_STIPPLE")

    # get control points and knots.
    h_control = guide_verts[0]
    radial_centre = guide_verts[1]
    knot1, knot2 = points[0], points[1]

    kappa_ctrl_1 = knot1.lerp(h_control, KAPPA)
    kappa_ctrl_2 = knot2.lerp(h_control, KAPPA)
    arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2, NUM_VERTS)

    # draw fillet ( 3 modes )

    if mode == 'TRIG_LAZY':
        arc_verts = resposition_arc_points(arc_verts, radial_centre)

    if mode == 'KAPPA':
        print("using vanilla kappa, this mode produces a poor approximation")

    if mode == 'TRIG':
        arc_centre = radial_centre
        arc_start = knot1
        arc_end = knot2
        arc_verts = get_correct_verts(arc_centre, arc_start, arc_end,
                                      NUM_VERTS, context)
        # get_correct_verts(arc_centre, arc_start, arc_end, NUM_VERTS, context)

    draw_polyline_from_coordinates(context, arc_verts, "GL_BLEND")

    gl_col1 = 1.0, 0.2, 0.2, 1.0  # vertex arc color
    gl_col2 = 0.5, 0.7, 0.4, 1.0  # radial center color

    if DRAW_POINTS:
        draw_points(context, arc_verts, 4.2, gl_col1)
        draw_points(context, [radial_centre], 5.2, gl_col2)

    # draw bottom left, above object name the number of vertices in the fillet
    location = 65, 30
    draw_text(context, location, NUM_VERTS)

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    return
def draw_callback_px(self, context):
    
    objlist = context.selected_objects
    names_of_empties = [i.name for i in objlist]

    region = context.region
    rv3d = context.space_data.region_3d
    points, guide_verts = init_functions(self, context)
    
    NUM_VERTS = context.scene.NumVerts
    # draw bevel
    draw_polyline_from_coordinates(context, points, "GL_LINE_STIPPLE")
    
    # draw symmetry line
    draw_polyline_from_coordinates(context, guide_verts, "GL_LINE_STIPPLE")
    
    # get control points and knots.
    h_control = guide_verts[0]
    radial_centre = guide_verts[1]
    knot1, knot2 = points[0], points[1]

    kappa_ctrl_1 = knot1.lerp(h_control, KAPPA)
    kappa_ctrl_2 = knot2.lerp(h_control, KAPPA)
    arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2, NUM_VERTS)

    # draw fillet ( 3 modes )        

    if mode == 'TRIG_LAZY':
        arc_verts = resposition_arc_points(arc_verts, radial_centre)
    
    if mode == 'KAPPA':
        print("using vanilla kappa, this mode produces a poor approximation")
    
    if mode == 'TRIG':
        arc_centre = radial_centre        
        arc_start = knot1
        arc_end = knot2
        arc_verts = get_correct_verts(arc_centre, 
                        arc_start, 
                        arc_end, 
                        NUM_VERTS, 
                        context)
        # get_correct_verts(arc_centre, arc_start, arc_end, NUM_VERTS, context)
        
    draw_polyline_from_coordinates(context, arc_verts, "GL_BLEND")
    
    gl_col1 = 1.0, 0.2, 0.2, 1.0  # vertex arc color
    gl_col2 = 0.5, 0.7, 0.4, 1.0  # radial center color
    
    if DRAW_POINTS:
        draw_points(context, arc_verts, 4.2, gl_col1)    
        draw_points(context, [radial_centre], 5.2, gl_col2)
        
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    return
Beispiel #10
0
def generate_bezier(verts=[], num_verts=20):

    f = list(map(Vector, verts))
    knot1, ctrl_1, ctrl_2, knot2 = f
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, max(3, num_verts))

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n + 1) for n in range(len(arc_verts) - 1)]
    return arc_verts, arc_edges
Beispiel #11
0
def generate_bezier(verts=[], num_verts=20):

    f = list(map(Vector, verts))
    knot1, ctrl_1, ctrl_2, knot2 = f
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, max(3, num_verts))

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n+1) for n in range(len(arc_verts)-1)]
    return arc_verts, arc_edges
def draw_callback_px(self, context):
    
    region = context.region
    rv3d = context.space_data.region_3d
    points, guide_verts = init_functions(self, context)
    
    NUM_VERTS = context.scene.NumVerts
    mode = context.scene.FilletMode

    # draw bevel
    draw_polyline_from_coordinates(context, points, "GL_LINE_STIPPLE")
    
    # draw symmetry line
    draw_polyline_from_coordinates(context, guide_verts, "GL_LINE_STIPPLE")
    
    # get control points and knots.
    h_control = guide_verts[0]
    radial_centre = guide_verts[1]
    knot1, knot2 = points[0], points[1]

    # draw fillet ( 2 modes )        
    if mode == 'KAPPA':
        kappa_ctrl_1 = knot1.lerp(h_control, context.scene.CurveHandle1)
        kappa_ctrl_2 = knot2.lerp(h_control, context.scene.CurveHandle2)
        arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2, NUM_VERTS)

    if mode == 'TRIG':
        arc_centre = radial_centre        
        arc_start = knot1
        arc_end = knot2
        arc_verts = get_correct_verts(arc_centre, 
                        arc_start, 
                        arc_end, 
                        NUM_VERTS, 
                        context)
        
    draw_polyline_from_coordinates(context, arc_verts, "GL_BLEND")
   
    if DRAW_POINTS:
        draw_points(context, arc_verts, 4.2, gl_col1)    
        draw_points(context, [radial_centre], 5.2, gl_col2)
    
    # draw bottom left, above object name the number of vertices in the fillet
    draw_text(context, (65, 30), NUM_VERTS)
        
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    return
def draw_callback_px(self, context):

    objlist = context.selected_objects
    names_of_empties = [i.name for i in objlist]

    region = context.region
    rv3d = context.space_data.region_3d
    points, guide_verts = init_functions(self, context)

    # draw bevel
    draw_polyline_from_coordinates(context, points, "GL_LINE_STIPPLE")

    # draw symmetry line
    draw_polyline_from_coordinates(context, guide_verts, "GL_LINE_STIPPLE")

    # get control points and knots.
    h_control = guide_verts[0]
    knot1, knot2 = points[0], points[1]
    kappa_ctrl_1 = knot1.lerp(h_control, KAPPA)
    kappa_ctrl_2 = knot2.lerp(h_control, KAPPA)
    arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2, NUM_VERTS)

    # draw fillet ( 2 modes )
    radial_centre = guide_verts[1]
    if mode == 'TRIG':
        arc_verts = resposition_arc_points(arc_verts, radial_centre)
    if mode == 'KAPPA':
        print("using vanilla kappa, this mode produces a poor approximation")
        pass

    draw_polyline_from_coordinates(context, arc_verts, "GL_BLEND")

    gl_col1 = 1.0, 0.2, 0.2, 1.0  # vertex arc color
    gl_col2 = 0.5, 0.7, 0.4, 1.0  # radial center color

    if DRAW_POINTS == True:
        draw_points(context, arc_verts, 4.2, gl_col1)
        draw_points(context, [radial_centre], 5.2, gl_col2)

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    return
Beispiel #14
0
def spline_points(points, weights, index, params):
    """ 
        b  .
       .        .
      .              .
     .                    c
    a

    """
    cyclic = params.loop
    divs = params.num_points
    a, b, c = points

    if len(weights) == 2:
        w1, w2 = weights
    else:
        w2 = weights[0]

    # return early if no weight, then user wants no smooth/fillet
    if -0.0001 < w2 < 0.0001:
        return [b]

    weight_to_use_1 = 1 - w2
    weight_to_use_2 = 1 - w2

    if params.mode == 'absolute':
        len_ab = (Vector(a) - Vector(b)).length
        len_cb = (Vector(c) - Vector(b)).length
        weight_to_use_1 = w2 / len_ab
        weight_to_use_2 = w2 / len_cb
        p1 = Vector(b).lerp(Vector(a), weight_to_use_1)[:]
        p2 = Vector(b).lerp(Vector(c), weight_to_use_2)[:]
    elif params.mode == 'relative':
        p1 = Vector(a).lerp(Vector(b), weight_to_use_1)[:]
        p2 = Vector(c).lerp(Vector(b), weight_to_use_2)[:]
    elif params.mode == 'arc':
        pts = find_projected_arc_center(c, a, b, radius=w2)
        if not pts:
            return [b]
        return three_point_arc(pts=pts, num_verts=divs, make_edges=False)[0]

    return [v[:] for v in bezlerp(p1, b, b, p2, divs)]
Beispiel #15
0
    def add_bezier(self, controls, width, color, samples=20, resampled=False):
        # knot1, ctrl_1, ctrl_2, knot2 = controls

        N = samples
        bezier_points = bezlerp(*controls, samples)
        offsets = get_all_offsets(controls, bezier_points, samples, width)
        verts = [(b.to_2d() + offset)[:]
                 for b, offset in zip(bezier_points, offsets)]
        verts.extend([(b.to_2d() - offset)[:]
                      for b, offset in zip(bezier_points, offsets)])

        indices = []
        add_indices = indices.extend
        _ = [
            add_indices([[i, i + 1, N + i], [i + N, i + N + 1, i + 1]])
            for i in range(N - 1)
        ]
        self.add_data(new_vectors=verts,
                      new_colors=[color for _ in range(len(verts))],
                      new_indices=indices)
from mathutils import Vector, Euler

Verts = []
Edges = []


def mid(A, B):
    return (A[0] + B[0]) / 2, (A[1] + B[1]) / 2, (A[2] + B[2]) / 2


for quad in quads:
    if len(quad) == 4:
        sverts, sedges = [], []
        for s in range(4):

            knot1 = mid(quad[s % 4], quad[(s + 1) % 4])
            ctrl_1 = mid(knot1, quad[(s + 1) % 4])
            knot2 = mid(quad[(s + 1) % 4], quad[(s + 2) % 4])
            ctrl_2 = mid(knot2, quad[(s + 1) % 4])

            arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, max(3, points))
            sverts.extend([v[:] for v in arc_verts[:-1]])

        arc_edges = [(n, n + 1) for n in range(len(sverts) - 1)]
        arc_edges.append([len(sverts) - 1, 0])
        Edges.append([arc_edges])
        Verts.append([sverts])

verts = [Verts]
edges = [Edges]
def generate_geometry_already(self, context):

    radius_rate = bpy.context.scene.MyMove
    if radius_rate == 0.0:
        # why?
        report_string = "pick values above 0.000"
        self.report({'INFO'}, report_string)

        return

    NUM_VERTS = context.scene.NumVerts
    mode = context.scene.FilletMode
    points, guide_verts = init_functions(self, context)

    # get control points and knots.
    h_control = guide_verts[0]
    radial_centre = guide_verts[1]
    knot1, knot2 = points[0], points[1]

    # draw fillet ( 2 modes )
    if mode == 'KAPPA':
        kappa_ctrl_1 = knot1.lerp(h_control, context.scene.CurveHandle1)
        kappa_ctrl_2 = knot2.lerp(h_control, context.scene.CurveHandle2)
        arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2,
                            NUM_VERTS)

    if mode == 'TRIG':
        arc_centre = radial_centre
        arc_start = knot1
        arc_end = knot2
        arc_verts = get_correct_verts(arc_centre, arc_start, arc_end,
                                      NUM_VERTS, context)

    bpy.ops.object.mode_set(mode='OBJECT')
    obj = context.object
    removable_vert = find_index_of_selected_vertex(obj)
    idx1, idx2 = return_connected_from_object(obj)

    # make vertices
    obj.data.vertices.add(NUM_VERTS)
    vertex_counter = NUM_VERTS
    for vert in range(len(arc_verts)):
        obj.data.vertices[-vertex_counter].co = arc_verts[vert]
        vertex_counter -= 1

    # build edges, find a prettier way to do this. it's ridiculous.
    NUM_EDGES = (NUM_VERTS - 1)
    obj.data.edges.add(NUM_EDGES)

    # must count current verts first
    current_vert_count = len(bpy.context.object.data.vertices)
    edge_counter = -NUM_EDGES
    vertex_ID = current_vert_count - NUM_VERTS
    for edge in range(NUM_VERTS - 1):
        a = vertex_ID
        b = vertex_ID + 1
        obj.data.edges[edge_counter].vertices = [a, b]
        print(str(edge_counter) + "[", a, ",", b, "]")

        edge_counter += 1
        vertex_ID += 1

    # connect first and last new edge with the 2 existing 'found indices'
    obj.data.edges.add(2)
    last_new_vert = current_vert_count - 1
    first_new_vert = current_vert_count - NUM_VERTS
    obj.data.edges[-2].vertices = [idx1, first_new_vert]
    obj.data.edges[-1].vertices = [idx2, last_new_vert]

    # then delete 'active' vert YAY!
    # do that here. ugly code here.

    obj.data.update()
    bpy.ops.object.mode_set(mode='EDIT')

    # unselect all.
    bpy.ops.mesh.select_all(action='TOGGLE')

    # return to object mode to perform vertex selection
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.context.active_object.data.vertices[removable_vert].select = True

    # back into edit mode, delete the very first vertex again.
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.delete()

    # because i am lazy, this cleans up the doubles generated by a fillet
    # size that is equal to one of the edge lengths. i should be shot for this.
    if radius_rate == 1.0:
        bpy.ops.mesh.select_all(action='TOGGLE')
        bpy.ops.mesh.remove_doubles()
        bpy.ops.mesh.select_all(action='TOGGLE')

    return
def generate_geometry_already(self, context):
    
    
    radius_rate = bpy.context.scene.MyMove
    if radius_rate == 0.0:
        # why?
        report_string = "pick values above 0.000"
        self.report({'INFO'}, report_string)

        return
    
    NUM_VERTS = context.scene.NumVerts
    mode = context.scene.FilletMode
    points, guide_verts = init_functions(self, context)
        
    # get control points and knots.
    h_control = guide_verts[0]
    radial_centre = guide_verts[1]
    knot1, knot2 = points[0], points[1]

    # draw fillet ( 2 modes )        
    if mode == 'KAPPA':
        kappa_ctrl_1 = knot1.lerp(h_control, context.scene.CurveHandle1)
        kappa_ctrl_2 = knot2.lerp(h_control, context.scene.CurveHandle2)
        arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2, NUM_VERTS)

    if mode == 'TRIG':
        arc_centre = radial_centre        
        arc_start = knot1
        arc_end = knot2
        arc_verts = get_correct_verts(arc_centre, arc_start, arc_end, 
                                        NUM_VERTS, context)
    
    bpy.ops.object.mode_set(mode='OBJECT')
    obj = context.object
    removable_vert = find_index_of_selected_vertex(obj)
    idx1, idx2 = return_connected_from_object(obj)

    # make vertices
    obj.data.vertices.add(NUM_VERTS)
    vertex_counter = NUM_VERTS
    for vert in range(len(arc_verts)):
        obj.data.vertices[-vertex_counter].co = arc_verts[vert]        
        vertex_counter -= 1
    
    
    # build edges, find a prettier way to do this. it's ridiculous.
    NUM_EDGES = (NUM_VERTS - 1)
    obj.data.edges.add(NUM_EDGES)

    # must count current verts first
    current_vert_count = len(bpy.context.object.data.vertices)
    edge_counter = -NUM_EDGES
    vertex_ID = current_vert_count - NUM_VERTS
    for edge in range(NUM_VERTS-1):
        a = vertex_ID
        b = vertex_ID+1
        obj.data.edges[edge_counter].vertices = [a, b]
        print(str(edge_counter)+"[", a, ",", b, "]")

        edge_counter += 1
        vertex_ID += 1
    
    # connect first and last new edge with the 2 existing 'found indices'
    obj.data.edges.add(2)
    last_new_vert = current_vert_count-1
    first_new_vert = current_vert_count-NUM_VERTS
    obj.data.edges[-2].vertices = [idx1, first_new_vert]
    obj.data.edges[-1].vertices = [idx2, last_new_vert]
    
    # then delete 'active' vert YAY!
    # do that here. ugly code here.

    obj.data.update()
    bpy.ops.object.mode_set(mode='EDIT')

    # unselect all.
    bpy.ops.mesh.select_all(action='TOGGLE')
    
    # return to object mode to perform vertex selection
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.context.active_object.data.vertices[removable_vert].select = True

    # back into edit mode, delete the very first vertex again.
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.delete()  
    
    # because i am lazy, this cleans up the doubles generated by a fillet
    # size that is equal to one of the edge lengths. i should be shot for this.
    if radius_rate == 1.0:
        bpy.ops.mesh.select_all(action='TOGGLE')
        bpy.ops.mesh.remove_doubles()
        bpy.ops.mesh.select_all(action='TOGGLE')
        
    return
def generate_geometry_already(self, context):
    
    
    radius_rate = bpy.context.scene.MyMove
    if radius_rate == 0.0 or radius_rate == 1.0:
        # why?
        report_string = "pick values between, and exluding, 0.0 and 1.0"
        self.report({'INFO'}, report_string)

        return
    
    NUM_VERTS = context.scene.NumVerts
    mode = context.scene.FilletMode
    points, guide_verts = init_functions(self, context)
        
    # get control points and knots.
    h_control = guide_verts[0]
    radial_centre = guide_verts[1]
    knot1, knot2 = points[0], points[1]

    # draw fillet ( 2 modes )        
    if mode == 'KAPPA':
        kappa_ctrl_1 = knot1.lerp(h_control, context.scene.CurveHandle1)
        kappa_ctrl_2 = knot2.lerp(h_control, context.scene.CurveHandle2)
        arc_verts = bezlerp(knot1, kappa_ctrl_1, kappa_ctrl_2, knot2, NUM_VERTS)

    if mode == 'TRIG':
        arc_centre = radial_centre        
        arc_start = knot1
        arc_end = knot2
        arc_verts = get_correct_verts(arc_centre, arc_start, arc_end, 
                                        NUM_VERTS, context)
    
    bpy.ops.object.mode_set(mode='OBJECT')
    obj = context.object

    # make vertices
    obj.data.vertices.add(NUM_VERTS)
    vertex_counter = NUM_VERTS
    for vert in range(len(arc_verts)):
        obj.data.vertices[-vertex_counter].co = arc_verts[vert]        
        vertex_counter -= 1
    
    
    # build edges, find a prettier way to do this. it's ridiculous.
    NUM_EDGES = (NUM_VERTS - 1)
    obj.data.edges.add(NUM_EDGES)

    # must count current verts first
    current_vert_count = len(bpy.context.object.data.vertices)
    edge_counter = -NUM_EDGES
    vertex_ID = current_vert_count - NUM_VERTS
    for edge in range(NUM_VERTS-1):
        a = vertex_ID
        b = vertex_ID+1
        obj.data.edges[edge_counter].vertices = [a, b]
        print(str(edge_counter)+"[", a, ",", b, "]")

        edge_counter += 1
        vertex_ID += 1
    
    # TODO
    # add two more edges
    # connect 
    # - found_index[0] with last_vertex
    # - found_index[1] with last_vertex - num_verts (-1?)
    
    # then delete 'active' vert (should still be selected! ) YAY!
    
    obj.data.update()

    print("generate_geometry_already(self, context) " )
    
    bpy.ops.object.mode_set(mode='EDIT')
    # return arc_verts
    return
Beispiel #20
0
from mathutils import Vector, Euler

Verts = []
Edges = []


def mid(A, B):
    return (A[0] + B[0]) / 2, (A[1] + B[1]) / 2, (A[2] + B[2]) / 2


for quad in quads:
    if len(quad) == 4:
        sverts, sedges = [], []
        for s in range(4):

            knot1 = mid(quad[s % 4], quad[(s + 1) % 4])
            ctrl_1 = mid(knot1, quad[(s + 1) % 4])
            knot2 = mid(quad[(s + 1) % 4], quad[(s + 2) % 4])
            ctrl_2 = mid(knot2, quad[(s + 1) % 4])

            arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, max(3, points))
            sverts.extend([v[:] for v in arc_verts[:-1]])

        arc_edges = [(n, n + 1) for n in range(len(sverts) - 1)]
        arc_edges.append([len(sverts) - 1, 0])
        Edges.append([arc_edges])
        Verts.append([sverts])

verts = [Verts]
edges = [Edges]
def sv_main(verts=[], num_verts=20, new_divisions=20):
    '''
    verts is expecting 4 (unique) 3d coordinates
    '''

    in_sockets = [
        ['v', 'verts', verts],
        ['s', 'num_verts', num_verts],
        ['s', 'new_divisions', new_divisions]]

    out_sockets = [ 
        ['v', 'Vecs', []], 
        ['s', 'Edges', []],
        ['v', 'Vecs ctrl', []], 
        ['s', 'Edges ctrl', []],
        ['v', 'Vecs norm', []],
        ['s', 'Edges norm', []]
    ]

    if not verts:
        return in_sockets, out_sockets

    # defend against div by zero
    new_divisions = max(new_divisions, 1)
    
    # while developing, it can be useful to uncomment this 
    if 'get_length' in globals():
        import imp
        imp.reload(spline_utils)
        from spline_utils import get_length, get_verts_n_edges


    f = list(map(Vector, verts[0]))
    knot1, ctrl_1, ctrl_2, knot2 = f
    arc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, num_verts)
    farc_verts = bezlerp(knot1, ctrl_1, ctrl_2, knot2, 870)

    tlen, lengths = get_length(farc_verts)
    # print(tlen)
    segment_width = tlen/new_divisions
    print('new div length = ', segment_width)
    k = get_verts_n_edges(farc_verts, lengths, segment_width)

    arc_verts = [v[:] for v in arc_verts]
    arc_edges = [(n, n+1) for n in range(len(arc_verts)-1)]
    
    norm_verts = [v[:] for v in k]
    norm_edges = [(n, n+1) for n in range(len(k)-1)]
    

    controls = verts[0]
    control_edges = [[(0,1),(2,3)]]
    
    out_sockets[0][2] = [arc_verts]
    out_sockets[1][2] = [arc_edges]

    out_sockets[2][2] = [controls]
    out_sockets[3][2] = control_edges

    out_sockets[4][2] = [norm_verts]
    out_sockets[5][2] = [norm_edges]


    return in_sockets, out_sockets