コード例 #1
0
ファイル: pattern.py プロジェクト: Tob1112/blendercam
def getPathPattern4axis(operation):
    o = operation
    t = time.time()
    progress("building path pattern")
    minx, miny, minz, maxx, maxy, maxz = o.min.x, o.min.y, o.min.z, o.max.x, o.max.y, o.max.z
    pathchunks = []
    zlevel = 1  # minz#this should do layers...

    # set axes for various options, Z option is obvious nonsense now.
    if o.rotary_axis_1 == "X":
        a1 = 0
        a2 = 1
        a3 = 2
    if o.rotary_axis_1 == "Y":
        a1 = 1
        a2 = 0
        a3 = 2
    if o.rotary_axis_1 == "Z":
        a1 = 2
        a2 = 0
        a3 = 1

    o.max.z = o.maxz
    # set radius for all types of operation
    m1 = max(abs(o.min[a2]), abs(o.max[a2]))
    m2 = max(abs(o.min[a3]), abs(o.max[a3]))

    radius = max(
        o.max.z, 0.0001
    )  # math.sqrt(m1*m1+m2*m2)+operation.cutter_diameter*2#max radius estimation, but the minimum is object
    radiusend = o.min.z

    mradius = max(radius, radiusend)
    circlesteps = (mradius * pi * 2) / o.dist_along_paths
    circlesteps = max(4, circlesteps)
    anglestep = 2 * pi / circlesteps
    # generalized rotation
    e = Euler((0, 0, 0))
    e[a1] = anglestep

    # generalized length of the operation
    maxl = o.max[a1]
    minl = o.min[a1]
    steps = (maxl - minl) / o.dist_between_paths

    # set starting positions for cutter e.t.c.
    cutterstart = Vector((0, 0, 0))
    cutterend = Vector((0, 0, 0))  # end point for casting

    if o.strategy4axis == "PARALLELR":

        for a in range(0, floor(steps) + 1):
            chunk = camPathChunk([])

            cutterstart[a1] = o.min[a1] + a * o.dist_between_paths
            cutterend[a1] = cutterstart[a1]

            cutterstart[a2] = 0  # radius
            cutterend[a2] = 0  # radiusend

            cutterstart[a3] = radius
            cutterend[a3] = radiusend

            for b in range(0, floor(circlesteps) + 1):
                # print(cutterstart,cutterend)
                chunk.startpoints.append(cutterstart.to_tuple())
                chunk.endpoints.append(cutterend.to_tuple())
                rot = [0, 0, 0]
                rot[a1] = a * 2 * pi + b * anglestep

                chunk.rotations.append(rot)
                cutterstart.rotate(e)
                cutterend.rotate(e)

            chunk.depth = radiusend - radius
            # last point = first
            chunk.startpoints.append(chunk.startpoints[0])
            chunk.endpoints.append(chunk.endpoints[0])
            chunk.rotations.append(chunk.rotations[0])

            pathchunks.append(chunk)

    if o.strategy4axis == "PARALLEL":

        reverse = False

        for b in range(0, floor(circlesteps) + 1):
            chunk = camPathChunk([])
            cutterstart[a2] = 0
            cutterstart[a3] = radius

            cutterend[a2] = 0
            cutterend[a3] = radiusend

            e[a1] = anglestep * b

            cutterstart.rotate(e)
            cutterend.rotate(e)

            for a in range(0, floor(steps) + 1):
                cutterstart[a1] = o.min[a1] + a * o.dist_between_paths
                cutterend[a1] = cutterstart[a1]
                chunk.startpoints.append(cutterstart.to_tuple())
                chunk.endpoints.append(cutterend.to_tuple())
                rot = [0, 0, 0]
                rot[a1] = b * anglestep
                chunk.rotations.append(rot)

            chunk.depth = radiusend - radius
            # last point = first

            pathchunks.append(chunk)

            if (
                (reverse and o.movement_type == "MEANDER")
                or (o.movement_type == "CONVENTIONAL" and o.spindle_rotation_direction == "CW")
                or (o.movement_type == "CLIMB" and o.spindle_rotation_direction == "CCW")
            ):
                chunk.reverse()

            reverse = not reverse

    if o.strategy4axis == "HELIX":
        print("helix")

        a1step = o.dist_between_paths / circlesteps

        chunk = camPathChunk([])  # only one chunk, init here

        for a in range(0, floor(steps) + 1):

            cutterstart[a1] = o.min[a1] + a * o.dist_between_paths
            cutterend[a1] = cutterstart[a1]
            cutterstart[a2] = 0
            cutterstart[a3] = radius
            cutterend[a3] = radiusend

            for b in range(0, floor(circlesteps) + 1):
                # print(cutterstart,cutterend)
                cutterstart[a1] += a1step
                cutterend[a1] += a1step
                chunk.startpoints.append(cutterstart.to_tuple())
                chunk.endpoints.append(cutterend.to_tuple())

                rot = [0, 0, 0]
                rot[a1] = a * 2 * pi + b * anglestep
                chunk.rotations.append(rot)

                cutterstart.rotate(e)
                cutterend.rotate(e)

            chunk.depth = radiusend - radius
            # last point = first

        pathchunks.append(chunk)
        # print(chunk.startpoints)
        # print(pathchunks)
        # sprint(len(pathchunks))
        # print(o.strategy4axis)
    return pathchunks
コード例 #2
0
ファイル: pattern.py プロジェクト: viewsat/blendercam
def getPathPattern4axis(operation):
    o = operation
    t = time.time()
    progress('building path pattern')
    minx, miny, minz, maxx, maxy, maxz = o.min.x, o.min.y, o.min.z, o.max.x, o.max.y, o.max.z
    pathchunks = []
    zlevel = 1  #minz#this should do layers...

    #set axes for various options, Z option is obvious nonsense now.
    if o.rotary_axis_1 == 'X':
        a1 = 0
        a2 = 1
        a3 = 2
    if o.rotary_axis_1 == 'Y':
        a1 = 1
        a2 = 0
        a3 = 2
    if o.rotary_axis_1 == 'Z':
        a1 = 2
        a2 = 0
        a3 = 1

    o.max.z = o.maxz
    #set radius for all types of operation
    m1 = max(abs(o.min[a2]), abs(o.max[a2]))
    m2 = max(abs(o.min[a3]), abs(o.max[a3]))

    radius = max(
        o.max.z, 0.0001
    )  #math.sqrt(m1*m1+m2*m2)+operation.cutter_diameter*2#max radius estimation, but the minimum is object
    radiusend = o.min.z

    mradius = max(radius, radiusend)
    circlesteps = (mradius * pi * 2) / o.dist_along_paths
    circlesteps = max(4, circlesteps)
    anglestep = 2 * pi / circlesteps
    #generalized rotation
    e = Euler((0, 0, 0))
    e[a1] = anglestep

    #generalized length of the operation
    maxl = o.max[a1]
    minl = o.min[a1]
    steps = (maxl - minl) / o.dist_between_paths

    #set starting positions for cutter e.t.c.
    cutterstart = Vector((0, 0, 0))
    cutterend = Vector((0, 0, 0))  #end point for casting

    if o.strategy4axis == 'PARALLELR':

        for a in range(0, floor(steps) + 1):
            chunk = camPathChunk([])

            cutterstart[a1] = o.min[a1] + a * o.dist_between_paths
            cutterend[a1] = cutterstart[a1]

            cutterstart[a2] = 0  #radius
            cutterend[a2] = 0  #radiusend

            cutterstart[a3] = radius
            cutterend[a3] = radiusend

            for b in range(0, floor(circlesteps) + 1):
                #print(cutterstart,cutterend)
                chunk.startpoints.append(cutterstart.to_tuple())
                chunk.endpoints.append(cutterend.to_tuple())
                rot = [0, 0, 0]
                rot[a1] = a * 2 * pi + b * anglestep

                chunk.rotations.append(rot)
                cutterstart.rotate(e)
                cutterend.rotate(e)

            chunk.depth = radiusend - radius
            #last point = first
            chunk.startpoints.append(chunk.startpoints[0])
            chunk.endpoints.append(chunk.endpoints[0])
            chunk.rotations.append(chunk.rotations[0])

            pathchunks.append(chunk)

    if o.strategy4axis == 'PARALLEL':
        circlesteps = (mradius * pi * 2) / o.dist_between_paths
        steps = (maxl - minl) / o.dist_along_paths

        anglestep = 2 * pi / circlesteps
        #generalized rotation
        e = Euler((0, 0, 0))
        e[a1] = anglestep

        reverse = False

        for b in range(0, floor(circlesteps) + 1):
            chunk = camPathChunk([])
            cutterstart[a2] = 0
            cutterstart[a3] = radius

            cutterend[a2] = 0
            cutterend[a3] = radiusend

            e[a1] = anglestep * b

            cutterstart.rotate(e)
            cutterend.rotate(e)

            for a in range(0, floor(steps) + 1):
                cutterstart[a1] = o.min[a1] + a * o.dist_along_paths
                cutterend[a1] = cutterstart[a1]
                chunk.startpoints.append(cutterstart.to_tuple())
                chunk.endpoints.append(cutterend.to_tuple())
                rot = [0, 0, 0]
                rot[a1] = b * anglestep
                chunk.rotations.append(rot)

            chunk.depth = radiusend - radius
            #last point = first

            pathchunks.append(chunk)

            if (reverse and o.movement_type == 'MEANDER') or (
                    o.movement_type == 'CONVENTIONAL'
                    and o.spindle_rotation_direction
                    == 'CW') or (o.movement_type == 'CLIMB'
                                 and o.spindle_rotation_direction == 'CCW'):
                chunk.reverse()

            reverse = not reverse

    if o.strategy4axis == 'HELIX':
        print('helix')

        a1step = o.dist_between_paths / circlesteps

        chunk = camPathChunk([])  #only one chunk, init here

        for a in range(0, floor(steps) + 1):

            cutterstart[a1] = o.min[a1] + a * o.dist_between_paths
            cutterend[a1] = cutterstart[a1]
            cutterstart[a2] = 0
            cutterstart[a3] = radius
            cutterend[a3] = radiusend

            for b in range(0, floor(circlesteps) + 1):
                #print(cutterstart,cutterend)
                cutterstart[a1] += a1step
                cutterend[a1] += a1step
                chunk.startpoints.append(cutterstart.to_tuple())
                chunk.endpoints.append(cutterend.to_tuple())

                rot = [0, 0, 0]
                rot[a1] = a * 2 * pi + b * anglestep
                chunk.rotations.append(rot)

                cutterstart.rotate(e)
                cutterend.rotate(e)

            chunk.depth = radiusend - radius
            #last point = first

        pathchunks.append(chunk)
    #print(chunk.startpoints)
    #print(pathchunks)
    #sprint(len(pathchunks))
    #print(o.strategy4axis)
    return pathchunks