コード例 #1
0
def build_castle_streetmap(p1, p2, options=Map()):
    width, null, depth = vg.dists(p1, p2)

    # Find a large central rectangle for the castle
    if width < 25 or depth < 25:
        castle_x = options.castle_x or width
        castle_z = options.castle_z or depth
    else:
        rand_x = max(25, math.ceil(width * .75))
        rand_z = max(25, math.ceil(depth * .75))
        castle_x = options.castle_x or min(width, np.random.randint(24, rand_x))
        castle_z = options.castle_z or min(depth, np.random.randint(24, rand_z))

    ninths = vg.ninths(p1, p2, castle_x, castle_z)
    partitions = []
    for ninth in ninths:
        if ninth.largest:
            partitions.append(ninth)
        else:
            w, null, d = vg.dists(ninth.p1, ninth.p2)
            if (w > 5) and (d > 5):
                subparts = vg.partition(ninth.p1, ninth.p2, min_x=options.min_x, min_z=options.min_z)
                partitions.extend(subparts)
            else:
                partitions.append(ninth)

    return partitions
コード例 #2
0
    def create_polys(self, options=Map()):
        polys = self.polys
        data_so_far = self.data()

        sides = data_so_far.sides or 4

        if options.outside:
            corners, lines = helpers.corners_from_bounds(options.p1, options.p2, sides, self.center, self.radius, options.width, options.depth)
            polys.append(MCShape(["garden"], corners, data_so_far.copy(corner_vectors=corners, lines=lines)))
            options.p1, options.p2 = vg.rectangle_inner(options.p1, options.p2, 1)

        # Build Walls
        corners, lines = helpers.corners_from_bounds(options.p1, options.p2, sides, self.center, self.radius, options.width, options.depth)
        for i, l in enumerate(lines):
            facing = "front" if i == 1 else "side"
            # TODO: Pass in point where front door is, determine facing from that
            p = MCShape(["standing rectangle", "wall"], l, data_so_far.copy(height=self.height, facing=facing))
            polys.append(p)

        # Build Roof and Foundation
        roof_vectors = [vg.up(v, self.height) for v in corners]
        polys.append(MCShape(["flat rectangle", "roof"], roof_vectors, data_so_far.copy(corner_vectors=roof_vectors)))
        polys.insert(0, MCShape(["flat rectangle", "foundation"], [vg.up(v, -1) for v in corners],
                                data_so_far.copy(corner_vectors=corners)))

        self.corner_vectors = corners
        self.polys = polys
コード例 #3
0
    def create_polys(self, options=Map()):
        polys = self.polys or []
        data_so_far = self.data()

        options.outside = False
        sides = options.sides = 4
        castle_wall_height = options.castle_wall_height or 9
        castle_inner_wall_height = options.castle_inner_wall_height or 18

        p1 = vg.up(options.p1, 1)
        p2 = vg.up(options.p2, 1)

        width, null, depth = vg.dists(p1, p2)
        print("Castle starting points and dimensions", p1, p2, ":", width, "x", depth)
        if (width > 22) and (depth > 22):
            # keep moat width between 4 and 10
            if (width > 26) and (depth > 26):
                moat_width = round(min((width + depth / 2) - 26, 10))
            else:
                moat_width = 4

            # Build Moat
            p1, p2 = vg.rectangle_inner(p1, p2, moat_width / 2)
            corners, lines = helpers.corners_from_bounds(vg.up(p1, -1), vg.up(p2, -1), sides, self.center, self.radius,
                                                         options.width, options.depth)
            p = MCShape(["moat"], corners, data_so_far.copy(height=self.height))
            polys.append(p)

            p1, p2 = vg.rectangle_inner(p1, p2, (moat_width / 2) - 2)

        width, null, depth = vg.dists(p1, p2)
        print("- Castle tower points", p1, p2, " and dimensions:", width, "x", depth)
        if (width > 17) and (depth > 17):

            p1, p2 = vg.rectangle_inner(p1, p2, 2)
            corners, lines = helpers.corners_from_bounds(p1, p2, sides, self.center, self.radius,
                                                         options.width, options.depth)

            for i, l in enumerate(lines):
                facing = "front" if i == 1 else "side"
                p = MCShape(["standing rectangle", "castle_outer_wall"], l, data_so_far.copy(height=castle_wall_height, thickness=3, facing=facing))
                polys.append(p)

            for i, c in enumerate(corners):
                p = MCShape(["standing line", "castle_wall_tower"], [c], data_so_far.copy(height=castle_wall_height, radius=3, facing=facing))
                polys.append(p)

            p1, p2 = vg.rectangle_inner(p1, p2, 4)

        options.p1 = p1
        options.p2 = p2

        self.polys = polys

        # Call the Building's create_poly class to build walls and roof
        super(self.__class__, self).create_polys(options)
コード例 #4
0
def corners_from_bounds(p1, p2, sides, center, radius, width, depth):
    corner_vectors = []
    lines = []
    for i in range(0, sides):
        v1 = vg.point_along_circle(center, radius, sides, i, Map(align_to_cells=True, width=width, depth=depth, p1=p1, p2=p2))
        v2 = vg.point_along_circle(center, radius, sides, i+1, Map(align_to_cells=True, width=width, depth=depth, p1=p1, p2=p2))
        corner_vectors.append(v1)
        lines.append((v1, v2))

    return corner_vectors, lines
コード例 #5
0
def prep(size=0, ground=True):
    if size > 0:
        corner1 = V3(mid_point.x - size, mid_point.y, mid_point.z - size)
        corner2 = V3(mid_point.x + size, mid_point.y, mid_point.z + size)
    else:
        corner1, corner2 = V3(-60, 0, 40), V3(120, 0, 200)

    debug("Bulldozing building zone...")
    if ground: create_block_filled_box(vg.up(corner1, -1), vg.up(corner2, -3), block.GRASS.id, data=None)
    create_block_filled_box(vg.up(corner1, 0), vg.up(corner2, 70), block.AIR.id, data=None)
    debug("...Finished bulldozing")
コード例 #6
0
    def __init__(self, zones, options=Map()):
        # TODO: Set width 1 or 2 of roads

        self.style = options.style or "blacktop"
        for z in zones:
            z.p1 = vg.up(z.p1, -1)
            z.p2 = vg.up(z.p2, -1)

        self.zones = zones
        self.options = options
        self.blocks, self.inner_blocks = vg.partitions_to_blocks(zones, options)
コード例 #7
0
    def __init__(self, zones, options=Map()):
        self.style = options.style
        self.buildings = []
        self.zones = []

        for part in zones:
            self.zones.append(part)
            p1 = vg.up(part.p1, 1)
            p2 = vg.up(part.p2, 1)
            p1, p2 = vg.rectangle_inner(p1, p2, 1)
            self.buildings.append(Building(False, Map(p1=p1, p2=p2)))
コード例 #8
0
    def __init__(self, kind, pos, options=Map()):
        self.kind = kind
        self.pos = pos
        self.facing = options.facing
        self.cardinality = options.cardinality
        self.blocks = []
        self.blocks_to_not_draw = []

        if kind == "door":
            if options.door_inside:
                door_pattern = "swne"
            else:
                door_pattern = "nesw"
            door_code = door_pattern.index(options.cardinality[-1:])
            self.blocks.append(
                Map(pos=pos, id=block.DOOR_WOOD.id, data=door_code))
            self.blocks.append(
                Map(pos=vg.up(pos), id=block.DOOR_WOOD.id, data=8))
            # self.blocks_to_not_draw.append(V3(pos.x, pos.y+1, pos.z))
        elif kind == "window":
            if options.window_style == "glass random":
                self.blocks.append(Map(pos=pos, id=block.GLASS_PANE.id,
                                       data=1))

            elif options.window_style == "open_slit_and_above" and options.windows not in [
                    "window_line", "window_line_double"
            ]:
                self.blocks.append(Map(pos=vg.up(pos), id=44, data=13))
                self.blocks.append(Map(pos=pos, id=44, data=5))
                around = vg.points_around([pos, vg.up(pos)])
                for b in around:
                    self.blocks.append(Map(pos=b, id=block.STONE.id))

            else:
                self.blocks.append(Map(pos=pos, id=block.GLASS_PANE.id,
                                       data=1))

        elif kind == "bed":
            self.blocks.append(Map(
                pos=pos,
                id=block.BED.id))  # TODO: Add 2 beds or 4 beds with spacing

        elif kind == "spacing":
            self.add_blocks(pos, block.AIR.id)
        elif kind == "flowers":
            self.add_blocks(pos, options.material)
        elif kind == "fence":
            self.add_blocks(pos, options.material)
        elif kind == "roof":
            for block_list in options.block_lists:
                self.add_blocks(block_list.blocks, block_list.material)
コード例 #9
0
def decorate_roof(obj, options=Map()):
    settings = options.options
    if not settings.roof:
        return obj

    material = Blocks.match(settings.roof_material)
    if material:
        obj.material = material

    if str.startswith(settings.roof, "pointy"):
        height = settings.roof_pointy_multiplier * options.radius
        pointy = V3(options.center.x,
                    options.center.y + options.height + height,
                    options.center.z)

        for i, vec in enumerate(options.corner_vectors):
            roof_line = vg.getLine(vec.x, vec.y + 1, vec.z, pointy.x,
                                   pointy.y + 1, pointy.z)
            obj.points_edges += roof_line

            if not settings.roof == "pointy_lines":
                next_roof_point = options.corner_vectors[(i + 1) % len(
                    options.corner_vectors)]

                # Triangle to pointy face
                triangle_face = [vec, pointy, next_roof_point]
                roof_face = vg.unique_points(
                    vg.getFace([V3(v.x, v.y + 1, v.z) for v in triangle_face]))
                obj.points = obj.points.union(roof_face)

    elif str.startswith(settings.roof, "triangular"):
        obj.decorations.append("roof_triangular")
    elif str.startswith(settings.roof, "battlement"):
        height = settings.roof_battlement_height or 1
        spacing = settings.roof_battlement_space or 2

        for i, vec in enumerate(options.corner_vectors):
            next_roof_point = options.corner_vectors[(i + 1) % len(
                options.corner_vectors)]
            # TODO: Add X,Z outward from center as option
            roof_line = vg.getLine(vec.x, vec.y + height, vec.z,
                                   next_roof_point.x,
                                   next_roof_point.y + height,
                                   next_roof_point.z)

            obj.points = obj.points.union(
                vg.points_spaced(roof_line, Map(every=spacing)))

    elif str.startswith(settings.roof, "shape"):
        obj.decorations.append("roof_floating_shape")
    return obj
コード例 #10
0
def test_shapes(line=True, buff=13, texture_base=89, texture_main="Glass", info=False):
    texture = Texture1D.Texture1D(Map(gradient=True, gradient_type="linear", onlyBlock=True, name_contains=texture_main,
                                      colors=Texture1D.COLOR_MAPS.Rainbow, axis="y"))

    def draw(func, position, radius=5, height=8, material=texture_base, info=False):
        points = func(V3(position.x, position.y, position.z), radius, .7, height=height)
        draw_point_list(points, material, options=Map(info=info))
        return points

    pos = my_tile_pos()

    higher = 8

    all_points = []
    if line is True:
        p1 = V3(pos.x + buff, pos.y, pos.z)
        p2 = V3(pos.x + (buff * 1.8), pos.y, pos.z)
        p3 = V3(pos.x + (buff * 3.3), pos.y, pos.z)
        p4 = V3(pos.x + (buff * 4.5), pos.y, pos.z)
        p5 = V3(pos.x + (buff * 5.7), pos.y, pos.z)
    else:
        p1 = V3(pos.x + buff, pos.y, pos.z)
        p2 = V3(pos.x, pos.y, pos.z)
        p3 = V3(pos.x, pos.y, pos.z - buff)
        p4 = V3(pos.x - buff, pos.y, pos.z)
        p5 = V3(pos.x, pos.y, pos.z + buff)

    all_points.extend(draw(vg.circle, p1, material=texture_base, info=info))
    all_points.extend(draw(vg.sphere, vg.up(p1, higher), radius=5, material=texture, info=info))

    all_points.extend(draw(vg.square, p2, material=texture_base, info=info))
    all_points.extend(draw(vg.box, vg.up(p2, higher), radius=4, material=texture, info=info))

    all_points.extend(draw(vg.circle, p3, material=texture_base, info=info))
    all_points.extend(draw(vg.cone, vg.up(p3, higher / 2), height=9, material=texture, info=info))

    all_points.extend(draw(vg.circle, p4, material=texture_base, info=info))
    all_points.extend(draw(vg.cylinder, vg.up(p4, higher / 2), material=texture, info=info))

    all_points.extend(draw(vg.square, p5, material=texture_base, info=info))
    all_points.extend(draw(vg.rectangular_pyramid, vg.up(p5, higher / 2), height=8, material=texture, info=info))

    class Temp:
        def __init__(self, points):
            self.points = points

        def clear(self):
            for p in self.points:
                create_block(p, block.AIR.id)

    return Temp(all_points)
コード例 #11
0
def build_basic_shape(obj, options):
    vertices = options.vertices

    # TODO: Add width for the wall - how to add end lines to that?

    options.p1 = p1 = vertices[0]
    options.p2 = p2 = vertices[1]

    obj.inside_vector = vg.inside_vector(p1=p1, center=options.center, p2=p2)
    obj.outside_vector = obj.inside_vector * -1

    h = options.height or 5
    if h > 1:
        obj.vertices = vertices_with_up = [p1, p2,
                                           vg.up(p2, h),
                                           vg.up(p1, h)]  # points straight up
        obj.height = options.height or (vg.highest(vertices_with_up) -
                                        vg.lowest(vertices_with_up) + 1)
        obj.points, obj.top_line, obj.bottom_line, obj.left_line, obj.right_line = vg.rectangular_face(
            p1, p2, h)
        obj.points_edges = obj.top_line + obj.bottom_line + obj.left_line + obj.right_line
    else:
        obj.vertices = [p1, p2]  # points straight up
        obj.height = h
        obj.points_edges = obj.points = obj.top_line = obj.bottom_line = vg.getLine(
            p1.x, p1.y, p1.z, p2.x, p2.y, p2.z)
        obj.left_line = obj.points[0]
        obj.right_line = obj.points[-1]

    obj.cardinality = vg.cardinality(p1, p2)
    return obj
コード例 #12
0
def scan(show_location=False):
    direction = my_rot()
    target = vg.up(my_pos())

    # print("Facing:", direction)
    if direction == 'w':
        x_range = [1]
        z_range = [-2, -1, 0, 1, 2]
    elif direction == 'e':
        x_range = [-1]
        z_range = [2, 1, 0, -1, -2]
    elif direction == 's':
        x_range = [-3, -2, -1, 0, 1]
        z_range = [0]
    else:
        # n
        x_range = [-2, -1, 0, 1, 2]
        z_range = [-2]

    blocks = []
    for y in [2, 1, 0, -1, -2]:
        text = ""
        for x in x_range:
            for z in z_range:
                new_point = target + V3(x, y, z)
                b = mc.getBlockWithData(new_point.x, new_point.y, new_point.z)

                name = Blocks.name_by_id(b.id, b.data)
                loc = str(new_point.x) + "," + str(new_point.y) + "," + str(
                    new_point.z) + " : " if show_location else ""
                line = "(" + loc + str(b.id) + "," + str(b.data) + ": " + name + ")  "

                text += line.ljust(28)
                blocks.append(b)
        print(text)
コード例 #13
0
def draw_point_list(points, material, data=None, options=Map()):
    # Remove empty blocks from list
    if options.blocks_to_not_draw:
        points = [i for i in points if i not in options.blocks_to_not_draw]

    # Find material if texture
    if type(material) == Texture1D.Texture1D:
        if material.options.gradient:
            bounds = vg.bounds(points)
            # Find low then high, calc difference, get color at dist, draw all at that height
            if material.axis == "y":
                bounds_lowest = bounds.lowest
                bounds_highest = bounds.highest
            elif material.axis == "x":
                bounds_lowest = bounds.x_low
                bounds_highest = bounds.x_high
            else:
                # if material.axis == "z":
                bounds_lowest = bounds.z_low
                bounds_highest = bounds.z_high

            # for each step along axis, draw the right color at that slice
            steps = bounds_highest - bounds_lowest + 1
            for slice_step in range(bounds_lowest, bounds_highest + 1):
                colored_points = []
                for point in points:
                    if (material.axis == "x" and point.x == slice_step) or \
                            (material.axis == "y" and point.y == slice_step) or \
                            (material.axis == "z" and point.z == slice_step):
                        colored_points.append(point)

                step = slice_step - bounds_lowest
                block_at_slice = material.block(Map(step=step, steps=steps))
                if options.info:
                    print("Material used:", step, steps, block_at_slice)

                draw_point_list(points=colored_points, material=block_at_slice["id"], data=block_at_slice["data"])
            return points

        else:
            # Texture but not gradient
            material = material.material

    # Regular material

    # Update the incrementer
    global BLOCK_DRAW_INCREMENTER
    BLOCK_DRAW_INCREMENTER = 0

    # Now that we know the block info from all options, Draw the Points
    for p in points:
        material_now, data_now = find_block_info(material, data=data, options=options)
        try:
            if not data_now:
                mc.setBlock(p.x, p.y, p.z, material_now)
            else:
                mc.setBlock(p.x, p.y, p.z, material_now, data_now)
        except TypeError:
            print("Error crating block", material_now)
コード例 #14
0
def build_basic_shape(obj, options):

    vertices = options.vertices

    # It's a non-y-rectangular-shaped polygon, so use a different getFace builder function
    obj.height = options.height or (vg.highest(vertices) - vg.lowest(vertices) + 1)
    obj.cardinality = options.cardinality
    obj.points = vg.unique_points(vg.getFace(obj.vertices))
    null, obj.top_line, obj.bottom_line, obj.left_line, obj.right_line = vg.poly_point_edges(obj.points)
    obj.points_edges = obj.top_line + obj.bottom_line + obj.left_line + obj.right_line

    if options.vertices[0].y > options.center.y:
        obj.material_clear = Blocks.AIR
    else:
        obj.material_clear = Blocks.GRASS

    return obj
コード例 #15
0
def decorate_roof_shape(obj, options=Map()):
    settings = options.options

    if settings.roof_shape_color_pattern == "RainbowGlass":
        material = Texture1D.COMMON_TEXTURES.RainbowGlass
    elif settings.roof_shape_color_pattern == "OldStoneWall":
        material = Texture1D.COMMON_TEXTURES.OldStoneWall
    elif settings.roof_shape_color_pattern == "WoodBlends":
        material = Texture1D.COMMON_TEXTURES.WoodBlends
    elif settings.roof_shape_color_pattern == "Glow":
        material = Texture1D.COMMON_TEXTURES.Glow
    else:
        material = Blocks.match(settings.roof_material)

    if not material:
        material = obj.material

    boundaries = vg.bounds(options.corner_vectors)

    min_radius = min(boundaries.x_radius, boundaries.z_radius)

    pos = boundaries.center
    if settings.roof_shape_object == "cylinder":
        func = vg.cylinder
        height = min_radius * (settings.roof_shape_height_multiplier or 1)
    elif settings.roof_shape_object == "cone":
        func = vg.cone
        height = min_radius * (settings.roof_shape_height_multiplier or 1)
    elif settings.roof_shape_object == "box":
        func = vg.box
        height = min_radius * (settings.roof_shape_height_multiplier or 1)
    else:  # sphere
        func = vg.oblate_sphere
        height = None
        if settings.roof_shape_floating:
            pos = vg.up(boundaries.center, min_radius)

    sides = func(pos, min_radius, tight=settings.roof_shape_tight, height=height,
                 options=Map(min_y_pct=.5, x_radius=boundaries.x_radius, z_radius=boundaries.z_radius))

    roof_lists = list()
    roof_lists.append(Map(blocks=sides, material=material))
    obj.features.append(Feature("roof", boundaries.center, Map(block_lists=roof_lists)))

    obj.points_edges = []
    return obj
コード例 #16
0
def spheredoze(player_pos=my_tile_pos(False), radius=40, ground=True):
    debug("Bulldozing " + str(radius) + "x around player...")
    debug(player_pos)

    all_points = vg.sphere(center=player_pos, radius=radius, filled=True)
    draw_point_list(points=all_points, material=block.AIR.id)

    debug("...Finished bulldozing")
コード例 #17
0
def decorate_castle_wall_tower(obj, options):
    height = options.options.roof_battlement_height or 1
    spacing = options.options.roof_battlement_space or 2

    # TODO: Add in battlements, wood roof, stairway, torches
    points = vg.cylinder(options.center, radius=3, height=obj.height or 10)
    obj.points.extend(points)

    return obj
コード例 #18
0
def decorate_roof_triangular(obj, options=Map()):
    settings = options.options

    material = Blocks.match(settings.roof_material)
    if material:
        obj.material = material

    p1, p2, radius, ends, sides = vg.best_points_for_triangular_roof(
        options.corner_vectors)
    chop_pct = settings.roof_triangular_chop_pct or 0

    radius += settings.roof_triangular_overhang

    height = radius
    if round(height) == int(height):
        height += 1

    if settings.roof_triangular_stairs or settings.roof_triangular_end_cap_in:
        # It's a more complex roof, build it as a Feature
        roof_lists = vg.prism_roof(
            p1,
            p2,
            height=height,
            radius=radius,
            chop_pct=chop_pct,
            sloped=settings.roof_triangular_sloped,
            material=obj.material,
            endpoint_out=settings.roof_triangular_end_cap_out)

        obj.features.append(Feature("roof", p1, Map(block_lists=roof_lists)))

    else:
        # Nothing fancy, color each block all the same type
        roof = vg.triangular_prism(p1,
                                   p2,
                                   height=height,
                                   radius=radius,
                                   chop_pct=chop_pct,
                                   sloped=settings.roof_triangular_sloped)
        obj.points.update(roof)

    obj.points_edges = []

    return obj
コード例 #19
0
def decorate_castle_outer_wall(obj, options):
    height = options.options.roof_battlement_height
    spacing = options.options.roof_battlement_space

    p1 = options.p1
    p2 = options.p2

    # TODO: Add in inner and outer, create walkway and arrow slits

    # TODO: Add X,Z outward from center as option
    roof_line = vg.getLine(p1.x, p1.y + height, p1.z, p2.x, p2.y + height, p2.z)
    obj.points.extend(vg.points_spaced(roof_line, Map(every=spacing)))

    mid_points = vg.middle_of_line(obj.bottom(), Map(center=True, max_width=2, point_per=10))
    for vec in mid_points:
        obj.features.append(
            Feature("door", vec, Map(cardinality=obj.cardinality, door_inside=options.options.door_inside)))

    return obj
コード例 #20
0
def build_basic_shape(obj, options):

    vertices = options.vertices
    if type(vertices) is not list:
        raise ValueError(
            "Expected list of points passed in, even though only 1st will be used"
        )

    # TODO: These are being built at center

    obj.center = options.center = p1 = vertices[0]
    obj.height = h = options.height or 8
    obj.points = []
    obj.points_edges = []  # TODO: Use bottom and top circles for edges?
    obj.vertices = [p1, p1, vg.up(p1, h), vg.up(p1, h)]  # points straight up

    obj.inside_vector = vg.inside_vector(p1=p1, center=options.center)
    obj.outside_vector = obj.inside_vector * -1

    return obj
コード例 #21
0
    def draw(self):
        for i, item in enumerate(self.blocks):
            if i == 0 and type(item.id) == Texture1D.Texture1D:
                item.id.reset_between_objects()

                if not item.id.options.bounds:
                    item.id.options.bounds = vg.bounds(self.blocks)

                # TODO: This won't reset Texture Gradients if there are multiple per Feature

            helpers.create_block(item.pos, item.id, item.data)
コード例 #22
0
def decorate_outside(obj, options=Map()):

    obj.points = []
    obj.points_edges = []
    obj.material_clear = Blocks.AIR

    border = flatten_list_of_lists(
        [vg.get_line_from_points(l[0], l[1]) for l in options.lines])

    if options.options.outside == "flowers":
        flowers_1 = []
        flowers_2 = []
        for i, b in enumerate(border):
            # TODO: Refactor to have multiple numbers of flowers

            if (i % 2) == 0:
                flowers_1.append(b)
            else:
                flowers_2.append(b)

        colors = Blocks.kind("Flower")
        np.random.shuffle(colors)

        obj.features.append(
            Feature("flowers", flowers_1, Map(material=colors[0])))
        obj.features.append(
            Feature("flowers", flowers_2, Map(material=colors[1])))

    elif options.options.outside == "trees":
        trees = []
        for i, b in enumerate(border):
            if (i % 3) == 0:
                trees.append(b)

        colors = Blocks.kind("Sapling")
        np.random.shuffle(colors)

        obj.features.append(Feature("flowers", trees, Map(material=colors[0])))

    elif options.options.outside == "grass":
        trees = []
        for i, b in enumerate(border):
            if (i % 3) == 0:
                trees.append(b)

        obj.features.append(
            Feature("flowers", trees, Map(material=Blocks.DOUBLETALLGRASS)))

    elif options.options.outside == "fence":
        fence_type = np.random.random_integers(188, 192)
        obj.features.append(Feature("fence", border, Map(material=fence_type)))

    return obj
コード例 #23
0
    def __init__(self, p1, p2, options=Map()):
        self.crop = options.crop or np.random.choice(
            ["cane", "wheat", "carrot", "potato", "cactus"])
        self.blocks = []

        rim, inner_rec = vg.rectangle(p1, p2)
        for block in rim + inner_rec:
            if not block in self.blocks and type(block) == V3:
                self.blocks.append(block)

        self.center = V3(round(abs(p2.x + p1.x) / 2), p1.y,
                         round(abs(p2.z + p1.z) / 2))
コード例 #24
0
def decorate_moat(obj, options=Map()):
    # TODO: FINISH
    moat_type = options.options.moat or "clear"
    radius = options.moat_width or 2
    height = -1 * abs(options.moat_depth or (radius + 2))
    obj.material_clear = Blocks.GRASS

    points = []
    for i, vec in enumerate(obj.vertices):
        next_vec = obj.vertices[(i + 1) % len(obj.vertices)]

        p1, p2 = vg.move_points_together(vec, next_vec, -radius)
        points.extend(vg.triangular_prism(p1, p2, height=height, radius=radius, sloped=True))

    obj.points = points
    obj.points_edges = []

    obj.material = Blocks.STILLWATER
    # if moat_type=="ice":

    return obj
コード例 #25
0
def test_polyhedron():
    # TODO: Revamp this
    import VoxelGraphics as vg

    pos = my_pos()
    points = vg.getFace([(pos.x, pos.y, pos.z), (pos.x + 20, pos.y + 20, pos.z), (pos.x + 20, pos.y + 20, pos.z + 20),
                         (pos.x, pos.y, pos.z + 20)])
    draw_point_list(points, block.GLASS.id)

    n = 20
    for t in range(0, n):
        (x1, z1) = (100 * math.cos(t * 2 * math.pi / n), 80 * math.sin(t * 2 * math.pi / n))
        for p in vg.traverse(V3(pos.x, pos.y - 1, pos.z), V3(pos.x + x1, pos.y - 1, pos.z + z1)):
            create_block(p, block.OBSIDIAN)

    n = 40
    vertices = []
    for t in range(0, n):
        (x1, z1) = (100 * math.cos(t * 2 * math.pi / n), 80 * math.sin(t * 2 * math.pi / n))
        vertices.append((pos.x + x1, pos.y, pos.z + z1))
    points = vg.getFace(vertices)
    draw_point_list(points, block.STAINED_GLASS_BLUE)
コード例 #26
0
def decorate_wall(obj, options):

    if options.options.windows == "window_line":
        spaced_points = vg.extrude(
            obj.bottom(), Map(spacing=V3(0, math.ceil(obj.height / 2), 0)))
        for vec in spaced_points:
            obj.features.append(Feature("window", vec,
                                        options=options.options))

    elif options.options.windows == "window_line_double":
        spaced_points = vg.extrude(
            obj.bottom(), Map(spacing=V3(0, math.ceil(obj.height / 2), 0)))
        spaced_points2 = vg.extrude(spaced_points, Map(spacing=V3(0, 1, 0)))
        for vec in spaced_points + spaced_points2:
            obj.features.append(Feature("window", vec,
                                        options=options.options))

    elif options.options.windows == "window_slits":
        spaced_points = vg.points_spaced(obj.bottom(), Map(every=5))
        spaced_points = vg.extrude(
            spaced_points, Map(spacing=V3(0, math.ceil(obj.height / 2), 0)))
        spaced_points2 = vg.extrude(spaced_points, Map(spacing=V3(0, 1, 0)))
        for vec in spaced_points + spaced_points2:
            obj.features.append(Feature("spacing", vec))

    else:
        spaced_points = vg.points_spaced(obj.bottom(), Map(every=3))
        spaced_points = vg.extrude(
            spaced_points, Map(spacing=V3(0, math.ceil(obj.height / 2), 0)))
        for vec in spaced_points:
            obj.features.append(Feature("window", vec,
                                        options=options.options))

    mid_points = vg.middle_of_line(obj.bottom(),
                                   Map(center=True, max_width=2, point_per=10))
    for vec in mid_points:
        obj.features.append(
            Feature(
                "door", vec,
                Map(cardinality=obj.cardinality,
                    door_inside=options.options.door_inside)))

    return obj
コード例 #27
0
def move_points_outwards(points,
                         distance_multiplier=0.8,
                         zone_data=Map(),
                         band=180):
    center_point = points[zone_data.center_id]
    zone_data.first = []
    zone_data.second = []
    zone_data.third = []
    zone_data.fourth = []

    for p2, point in enumerate(points):
        to_point = points[p2]

        dist = dist_points(center_point, to_point)
        angle = vg.angle_between(center_point[0], center_point[1], to_point[0],
                                 to_point[1])
        rad = math.radians(angle)
        band_name = None
        band_mult = 1

        if dist < band * .9:  # Green
            band_name = 'first'
            band_mult = .6
        elif dist < band * 1.35:  # Yellow
            band_name = 'second'
            band_mult = .7
        elif dist < band * 1.7:  # Brown
            band_name = 'third'
            band_mult = .8
        elif dist < band * 2.1:  # Black
            band_name = 'fourth'
            band_mult = .9

        if band_name:
            points[p2][0] = center_point[0] + (
                math.cos(rad) * distance_multiplier * band_mult * dist)
            points[p2][1] = center_point[1] + (
                math.sin(rad) * distance_multiplier * band_mult * dist)
            zone_data[band_name].append(p2)

    return points, zone_data
コード例 #28
0
def clear(size=0):
    if size > 0:
        corner1 = V3(mid_point.x - size, mid_point.y, mid_point.z - size)
        corner2 = V3(mid_point.x + size, mid_point.y, mid_point.z + size)
    else:
        corner1, corner2 = V3(-60, 0, 40), V3(120, 0, 200)

    debug("Removing Everything...(fly in 10 seconds)")
    create_block_filled_box(vg.up(corner1, -5), vg.up(corner2, 50), block.AIR.id, data=None)

    debug("...Adding Grass...")
    create_block_filled_box(vg.up(corner1, -1), vg.up(corner2, -1), block.GRASS.id, data=None)

    debug("...Stone underneath...")
    create_block_filled_box(vg.up(corner1, -2), vg.up(corner2, -5), block.STONE.id, data=None)
    debug("...Finished")
コード例 #29
0
    def __init__(self, pos=False, options=Map()):
        if not helpers.mc:
            helpers.mc = helpers.connect()

        self.seed = options.seed or vg.get_seed()
        vg.init_with_seed(self.seed)
        self.sides = options.sides or 4
        self.polys = []

        if options.p1 and options.p2:
            p1, p2 = vg.min_max_points(options.p1, options.p2)
            options.width = abs(p2.x - p1.x) - 2
            options.depth = abs(p2.z - p1.z) - 2
            options.radius = math.floor(min(options.width, options.depth) / 2)
            pos = V3(round((p1.x + p2.x) / 2), p1.y, round((p1.z + p2.z) / 2))
            if options.sides == 4:
                options.p1 = p1
                options.p2 = p2
        else:
            # If position isn't set, use the player position
            if pos is False:
                pos = helpers.my_tile_pos()

        # If "force_height" not passed in as an option, then pick height of the terrain at the x,z point
        # if not options.force_height:
        #     setattr(pos, "y", helpers.get_height(pos))

        self.options = options
        self.radius = options.radius or vg.rand_in_range(4, 10)
        self.options = choose_random_options(self.options)
        self.center = V3(pos.x, pos.y, pos.z)

        self.biome = "Plains"  # TODO: self.biome.title(options.biome or helpers.biome_at(pos))

        rand_max = min(max(math.ceil(self.radius * 2.5), 6), 40)  # keep buildings between 4-40 height
        self.height = options.height or vg.rand_in_range(4, rand_max)
        self.corner_vectors = []

        self.material = options.material or block.STONE.id
        self.material_edges = options.material_edges or block.IRON_BLOCK.id  # TODO: Change based on biome, have rand list

        self.name = options.name or self.biome + " house"

        # Create the walls and major polygons
        self.create_polys(options)
コード例 #30
0
def create_building_polys(polys, city_zones_in_walls, dist=3):
    all_buildings = []
    for z in city_zones_in_walls:
        zone = polys[z]
        center = vg.polygon_center(zone)
        poly_bounds = []
        for v_id, vertex in enumerate(zone):
            poly_bounds.append(move_point_towards(vertex, center, dist=dist))

        polygon_bounds = Polygon(poly_bounds)

        layout = np.random.choice(["edge"])
        if layout == "random":
            zone_buildings = create_building_polys_random(
                polygon_bounds, poly_bounds)
        elif layout == "edge":
            zone_buildings = create_building_polys_on_edges(
                polygon_bounds, poly_bounds)
        all_buildings.extend(zone_buildings)

        # all_buildings.insert(0, poly_bounds)

    return all_buildings