Esempio n. 1
0
def patio_chair(width=0.45, length=0.45, seat_height=0.40):
    seat_thick = 0.05
    seat = ddd.rect([0, 0, width, length], name="Chair seat").recenter().extrude(seat_thick)
    seat = ddd.uv.map_cubic(seat)
    seat = seat.translate([0, 0, seat_height - seat_thick])

    stool = ddd.group3([seat], name="Chair stool")

    leg_thick = 0.05
    leg_padding = leg_thick
    for c in [(1, 1), (-1, 1), (-1, -1), (1, -1)]:
        leg = ddd.point([c[0] * (width / 2 - leg_padding), c[1] * (length / 2 - leg_padding)]).buffer(leg_thick / 2).extrude(seat_height - seat_thick)
        leg = ddd.uv.map_cylindrical(leg)
        stool.append(leg)

    stool = stool.material(ddd.mats.steel)
    stool = ddd.collision.aabox_from_aabb(stool)

    back_height = 0.3
    back = ddd.rect([width, seat_thick], name="Chair Back").recenter().extrude(back_height)
    back = back.material(ddd.mats.steel)
    back = ddd.uv.map_cubic(back)
    back = back.translate([0, length / 2 - seat_thick, seat_height])
    back = ddd.collision.aabox_from_aabb(back)

    chair = ddd.group3([stool, back], name="Chair")
    chair.extra['ddd:mass'] = 2.5

    chair = ddd.meshops.batch_by_material(chair).clean(remove_degenerate=False)

    return chair
Esempio n. 2
0
def basketball_hoop():
    """
    """

    ring_r = 0.45 / 2
    ring = ddd.disc(
        r=ring_r,
        name="Basketball hoop ring").outline().buffer(0.015).extrude(-0.03)
    ring = ring.material(ddd.mats.steel)
    #ring = ddd.uv.map_cubic(ring)

    board_w = 1.80
    board_h = 1.20
    board_ring_h = 0.30
    board_shape = ddd.rect(
        [board_w, board_h],
        name="Basketball hoop board").recenter().extrude(-0.05)
    board_shape = board_shape.material(ddd.mats.plastic_transparent)
    #board_shape = ddd.uv.map_cubic(board_shape)
    board_shape = board_shape.rotate(ddd.ROT_FLOOR_TO_FRONT)
    board_shape = board_shape.translate(
        [0, ring_r + 0.15, board_h / 2 - board_ring_h])

    board = ddd.group3([ring, board_shape], name="Basketball hoop")
    board = board.translate([0, 0, 3.05])

    pole = curvedpost(3.25, arm_length=1.5,
                      corner_radius=0.4).rotate(ddd.ROT_TOP_CCW)
    pole = pole.material(ddd.mats.metal_paint_red)
    pole.prop_set('uv', None, True)
    pole = pole.translate([0, ring_r + 0.15 + 0.05 + 1.5, 0])

    hoop = ddd.group3([pole, board], name="Basketball hoop with pole")

    return hoop
Esempio n. 3
0
    def generate_way_3d_railway(self, way_2d):
        '''
        '''
        # TODO: Elevation shall be applied for ways in a common way: Way generation if special could be handled by ddd:area:type ?

        rail_height = 0.20

        result = ddd.group3()

        for way_2d in way_2d.individualize().flatten().children:

            way_2d_interior = way_2d.buffer(-0.3)  # .individualize()
            if (len(way_2d_interior.individualize().children) > 1):
                way_3d = way_2d.triangulate()
            else:
                way_3d = way_2d.extrude_step(
                    way_2d_interior,
                    rail_height,
                    base=False,
                    cap=False,
                    method=ddd.EXTRUSION_METHOD_SUBTRACT)

            way_3d = way_3d.material(ddd.mats.dirt)
            way_3d = ddd.uv.map_cubic(way_3d)
            way_3d.extra['ddd:shadows'] = False
            way_3d.extra['ddd:collider'] = True

            pathline = way_2d_interior.extra['way_1d'].copy()
            way_2d_interior = uvmapping.map_2d_path(way_2d_interior,
                                                    pathline,
                                                    line_x_offset=0.5,
                                                    line_x_width=0.5,
                                                    line_d_scale=0.25)
            railroad_3d = way_2d_interior.triangulate().translate(
                [0, 0, rail_height]).material(ddd.mats.railway)
            railroad_3d.extra['ddd:collider'] = True
            railroad_3d.extra['ddd:shadows'] = False
            try:
                uvmapping.map_3d_from_2d(railroad_3d, way_2d_interior)
            except Exception as e:
                logger.error("Could not map railway UV coordinates: %s", e)
                railroad_3d.extra['uv'] = None

            railroad_group = ddd.group3([way_3d, railroad_3d])
            if int(ddd.data.get('ddd:area:subdivide', 0)) > 0:
                railroad_group = ddd.meshops.subdivide_to_grid(
                    railroad_group, float(ddd.data.get('ddd:area:subdivide')))

            result.append(railroad_group)

        # Apply elevation
        result = self.osm.areas3.generate_area_3d_apply_elevation(
            way_2d, result)

        return result
Esempio n. 4
0
def osm_model_init(root, osm):
    """
    Initializes the 3D output node tree structure.
    """

    root.append(ddd.group3(name="Items3"))
    #root.append(ddd.group3(name="Ways3"))
    #root.append(ddd.group3(name="Areas3"))
    #root.append(ddd.group3(name="Buildings3"))
    #root.append(ddd.group3(name="Items3"))
    root.append(ddd.group3(name="Other3"))
Esempio n. 5
0
    def generate_area_3d_pitch(self, area_2d):

        if area_2d.geom is None or area_2d.geom.is_empty:
            return None

        area_2d_orig = area_2d.extra.get('ddd:crop:original')  #, area_2d)

        #logger.debug("Pitch: %s", area_2d)
        area_3d = self.generate_area_3d_gen(area_2d)

        # TODO: pass size then adapt to position and orientation, easier to construct and reuse
        # TODO: get area uncropped (create a cropping utility that stores the original area)

        sport_full = area_2d.extra.get('ddd:sport', None)
        sport = sport_full.split(";")[0]  # Get first value if multivalued

        lines = None
        if sport == 'tennis':
            lines = sports.field_lines_area(area_2d_orig,
                                            sports.tennis_field_lines,
                                            padding=2.5)
        elif sport == 'basketball':
            lines = sports.field_lines_area(area_2d_orig,
                                            sports.basketball_field_lines,
                                            padding=1)
        elif sport == 'gymnastics':
            #lines = sports.field_lines_area(area_2d_orig, sports.basketball_field_lines, padding=2.0)
            lines = ddd.group3()
        elif sport in ('handball'):
            lines = sports.field_lines_area(area_2d_orig,
                                            sports.handball_field_lines,
                                            padding=1)
        elif sport in ('soccer', 'futsal'):
            lines = sports.field_lines_area(area_2d_orig,
                                            sports.football_field_lines,
                                            padding=1)
        else:
            # No sport assigned
            lines = ddd.group3()

        if lines:
            lines = terrain.terrain_geotiff_elevation_apply(
                lines, self.osm.ddd_proj)  #.translate([0, 0, 0.01])
            height = area_2d.extra.get('ddd:height', 0.0)
            lines = lines.translate([0, 0, height])

            area_3d = ddd.group3([area_3d, lines])
        else:
            logger.debug("No pitch lines generated.")

        return area_3d
Esempio n. 6
0
def childrens_playground_swingset(length=2.2, num=2, height=2.1, width=1.6):
    """
    """
    frame_thick = 0.06
    path = ddd.point([-width / 2, 0], name="Swing path").line_to([-width*2/6, height - width*2/6])
    path = path.arc_to([width*2/6, height - width *2/6], [0, height - width*2/6], ccw=False)
    path = path.line_to([width / 2, 0])

    side_mat = random.choice([ddd.mats.metal_paint_red, ddd.mats.metal_paint_green, ddd.mats.metal_paint_yellow])
    frameside = path.buffer(frame_thick / 2).material(side_mat)
    frameside = frameside.extrude(frame_thick, center=True).rotate(ddd.ROT_FLOOR_TO_FRONT).rotate(ddd.ROT_TOP_CCW)
    frameside = frameside.material(ddd.mats.steel)
    frameside = ddd.uv.map_cubic(frameside)

    frameside1 = frameside.translate([-length/2, 0, 0])
    frameside2 = frameside.translate([length/2, 0, 0])

    topbar = ddd.point([(-length + frame_thick) / 2, 0], name="Swing top bar").line_to([(length - frame_thick) / 2, 0])
    topbar = topbar.buffer(frame_thick / 2).extrude(frame_thick, center=True).translate([0, 0, height - frame_thick / 4])
    topbar = topbar.material(ddd.mats.steel)
    topbar = ddd.uv.map_cubic(topbar)

    swingset = ddd.group3([frameside1, frameside2, topbar], name="Playground swingset")

    for i in range(num):
        posx = -length / 2 + (i + 0.5) * (length / (num))
        swing = childrens_playground_swing(height=height - 0.4)
        swing = swing.translate([posx, 0, height])
        swingset.append(swing)

    item = swingset
    item = ddd.meshops.batch_by_material(item).clean(remove_degenerate=False)

    return item
Esempio n. 7
0
def osm_model_generate_areas(osm, root, pipeline, obj):

    area_3d = osm.areas3.generate_area_3d(obj)

    if not '_areas_areas_new' in pipeline.data:
        pipeline.data['_areas_areas_new'] = ddd.group3(name="Areas")
    pipeline.data['_areas_areas_new'].append(area_3d)
Esempio n. 8
0
def reed(height=None, leaves=None):

    if leaves is None:
        leaves = random.randint(4, 7)
    if height is None:
        height = random.uniform(1.3, 1.9)

    reed = ddd.group3(name="Reed")
    for i in range(leaves):
        lh = height + random.uniform(-0.4, 0.4)
        lb = 0.02 * lh
        item = ddd.polygon([[-lb, 0.0], [lb, 0.0], [0, lh]],
                           name="Reed leaf").triangulate(
                               twosided=True).material(ddd.mats.treetop)
        item = item.rotate(ddd.ROT_FLOOR_TO_FRONT)
        item = ddd.group([item, item.rotate(ddd.ROT_TOP_CW)], name="Reed leaf")
        item = ddd.uv.map_cubic(item, scale=(0.2, 2.0))
        item = item.rotate([0, 0, random.uniform(0, math.pi)])
        item = item.rotate([random.uniform(0.1, 0.3), 0, 0])
        torsion_advance = math.pi / 4
        item = item.rotate([0, 0, torsion_advance])
        rt = 0.15
        item = item.translate(
            [random.uniform(-rt, rt),
             random.uniform(-rt, rt), 0])
        reed.append(item)

    reed = ddd.align.polar(reed, 0.1, rotate=True)

    reed = reed.combine()
    return reed
Esempio n. 9
0
def tree_default(height=3.5, r=0.40, fork_iters=2, fork_height_ratio=0.35):

    height = height * (1 + fork_height_ratio)

    def trunk_callback(height):
        section = ddd.regularpolygon(sides=5, r=r).extrude(height)
        section = section.smooth(math.pi * 0.45)
        section = ddd.uv.map_cylindrical(section, scale=(2, 2), split=False)
        section = section.material(ddd.mats.bark)
        return section
    def leaves_callback(height):
        tt = treetop(r=0.5 + 0.4 * height, subdivisions=0).material(ddd.mats.treetop)
        return tt

    obj = recursivetree(height=height, r=r, leaves_callback=leaves_callback, trunk_callback=trunk_callback,
                        fork_iters=fork_iters, fork_height_ratio=fork_height_ratio)

    # Booleans and grouping (cut trunk?, merge all)
    '''
    objs = [p for p in ptrunk.recurse_objects() if p.mesh]
    while len(objs) > 1:
        newo = objs[0].union(objs[1])
        newo.mesh.merge_vertices()
        objs = objs[2:] + [newo]
    obj = objs[0]
    obj = obj.material(mat_leaves)
    '''

    obj.name = "Tree Default"

    objtrunk = obj.select(func=lambda o: o.mat == ddd.mats.bark).combine()
    objleaves = obj.select(func=lambda o: o.mat == ddd.mats.treetop).combine()
    obj = ddd.group3([objtrunk, objleaves], name="Tree Default")

    return obj
Esempio n. 10
0
    def all(self,
            size=20.0,
            plane_xy=True,
            grid_yz=True,
            grid_xz=True,
            grid_space=2.0,
            center=None,
            around_center=False):

        objs = ddd.group3(name="Helper grid")

        if plane_xy:
            objs.append(self.plane_xy(size))
        if grid_yz:
            objs.append(self.grid_yz(size, grid_space))
        if grid_xz:
            objs.append(self.grid_xz(size, grid_space))

        if center is None:
            center = [0, 0, 0]

        objs = objs.translate([-center[0], -center[1], -center[2]])

        if around_center:
            objs = objs.translate([-size / 2, -size / 2, 0])

        return objs
Esempio n. 11
0
def materials_list(root):

    mats = ddd.group3(name="Materials")
    root.append(mats)

    # Avoid exporting the same material twice
    added_names = []

    for key in sorted(dir(ddd.mats)):
        mat = getattr(ddd.mats, key)
        if isinstance(mat, DDDMaterial):
            if mat.name not in added_names:
                '''
                # This was a test, but these materials need not be converted to linear color space
                if mat.texture:
                    albedo_image = DDDMaterial.load_texture_cached(mat.texture)
                    albedo_array = np.array(albedo_image)
                    albedo_array_linear = convert_to_linear(albedo_array[:,:,:3])
                    if albedo_array.shape[2] == 4:
                        albedo_array_linear_rgba = np.empty((albedo_array.shape[0], albedo_array.shape[1], 4))
                        albedo_array_linear_rgba[:,:,:3] = albedo_array_linear[:,:,:]
                        albedo_array_linear_rgba[:,:,3] = albedo_array[:,:,3]
                    image_linear = Image.fromarray(np.uint8(albedo_array_linear), "RGBA" if albedo_array_linear.shape[2] == 4 else "RGB")
                    DDDMaterial._texture_cache[mat.texture] = image_linear
                '''

                marker = ddd.marker(name=mat.name)
                marker = marker.material(mat)
                mats.append(marker)
                added_names.append(mat.name)
Esempio n. 12
0
def pipeline_start(pipeline, root):

    items = ddd.group3()

    item = industrial.crane_vertical()
    items.append(item)

    item = landscape.powertower()
    items.append(item)

    item = landscape.lighthouse()
    items.append(item)
    #item.show()

    # TODO: Move generate_item_3d_historic_archaeological_site site generation to sketchy (?)
    '''
    item = osmitems.ItemsOSMBuilder(None).generate_item_3d_historic_archaeological_site(ddd.point())
    items.append(item)
    item.show()
    '''

    item = landscape.comm_tower()
    items.append(item)

    items = ddd.align.grid(items, 10.0)
    items.append(ddd.helper.all())
    items.show()

    pipeline.root = items
Esempio n. 13
0
def osm_model_generate_ways(osm, root, pipeline, obj):

    obj.extra['ddd:area:elevation'] = 'path'
    way_3d = osm.areas3.generate_area_3d(obj)

    if not '_ways_areas_new' in pipeline.data:
        pipeline.data['_ways_areas_new'] = ddd.group3(name="Ways")
    pipeline.data['_ways_areas_new'].append(way_3d)
Esempio n. 14
0
def osm_structured_ways_2d_generate_roadlines(root, osm, pipeline, logger):
    """
    Roadlines are incorporated here, but other augmented properties (traffic lights, lamp posts, traffic signs...)
    are added during augmentation.
    """
    logger.info("Generating roadlines.")
    root.append(ddd.group2(name="Roadlines2"))
    # TODO: This shall be moved to s60, in 3D, and separated from 2D roadline generation
    pipeline.data["Roadlines3"] = ddd.group3(name="Roadlines3")
Esempio n. 15
0
def pipeline_start(pipeline, root):
    """
    Draws several catenary cables.
    """

    ddd.mats.traffic_signs = ddd.material(name="TrafficSigns", color="#ffffff", #color="#e01010",
                                      texture_path=ddd.DATA_DIR  + "/materials/traffic-signs-es/traffic_signs_es_0.png",
                                      atlas_path=ddd.DATA_DIR  + "/materials/traffic-signs-es/traffic_signs_es_0.plist",
                                      extra={'ddd:texture:resize': 2048})


    items = ddd.group3()

    # Cube with logo
    fig = ddd.box()
    fig = fig.material(ddd.mats.logo)
    fig = ddd.uv.map_cubic(fig)
    items.append(fig)

    # Sphere with logo
    fig = ddd.sphere()
    fig = fig.material(ddd.mats.logo)
    #fig = fig.merge_vertices()
    #fig = fig.smooth(math.pi*2)
    fig = ddd.uv.map_spherical(fig)
    fig = fig.translate([0, 0, 2])
    items.append(fig)

    # Cube
    fig = ddd.box()
    fig = fig.material(ddd.mats.traffic_signs)
    fig = ddd.uv.map_cubic(fig)
    #fig.show()
    #items.append(fig)

    fig = TextureAtlasUtils().create_sprite_rect(ddd.mats.traffic_signs)
    #fig.show()
    #items.append(fig)

    fig = TextureAtlasUtils().create_sprite_from_atlas(ddd.mats.traffic_signs, "ES_P6.png")
    #fig.show()
    #items.append(fig)


    '''
    ddd.mats.roadmarks = ddd.material(name="Roadmarks", color='#e8e8e8',
                                 texture_path=ddd.DATA_DIR + "/materials/road-marks-es/TexturesCom_Atlas_RoadMarkings2_White_1K_albedo_with_alpha.png",
                                 atlas_path=ddd.DATA_DIR  + "/materials/road-marks-es/RoadMarkings2.plist")

    fig = TextureAtlasUtils().create_sprite_from_atlas(ddd.mats.roadmarks, "give_way")
    fig.show()
    '''

    items = ddd.align.grid(items, width=4)
    items.append(ddd.helper.all(size=40.0, center=[5, 5, 0]).twosided())

    root.append(items)
Esempio n. 16
0
def pipeline_logo(pipeline, root):
    """
    """

    logo = ddd.group3()

    thick = 0.125
    margin = 0.4

    line_out = ddd.line([
        (1.0, 0.0, 0.4),
        (1.0, 0.0, 0.0),
        (0.0, 0.0, 0.0),
        (0.0, 1.0, 0.0),
        (0.0, 1.0, 1.0),
        (1.0, 1.0, 1.0),
        (1.0, 0.0, 1.0),
        (1.0, 0.0, 0.6),
    ])

    base = ddd.rect([thick, thick], name="Logo exterior").recenter()

    item = base.extrude_along(line_out)
    item = item.material(ddd.mats.steel)
    #item = item.rotate([0, 0, 0.2])
    item = ddd.uv.map_cubic(
        item
    )  # FIXME: One of the corner vertices are not being split (but they are if slightly rotated)
    logo.append(item)

    line_in = ddd.line([
        (1.0 - margin, 1.0 - margin - 0.1, 1),
        (1.0 - margin, 1.0 - margin, 1),
        (0.0, 1.0 - margin, 1),
        (0.0, 0.0, 1),
        (1.0 - margin, 0.0, 1),
        (1.0 - margin, 0.0, margin),
        (0.0, 0.0, margin),
        (0.0, 1.0 - margin, margin),
        (0.0, 1.0 - margin, 1.0 - margin),
        (0.0, 1.0 - margin - 0.1, 1.0 - margin),
    ])

    item = base.extrude_along(line_in)
    item = item.material(ddd.mats.green)
    item = ddd.uv.map_cubic(item)
    logo.append(item)

    #logo = logo.scale([2, 2, 2])

    logo.show()

    root.append(logo)

    root.append(ddd.helper.all(center=[10, 10, 1]))
Esempio n. 17
0
def materials_list(root, osm):

    mats = ddd.group3(name="Materials")
    root.append(mats)

    for key in dir(ddd.mats):
        mat = getattr(ddd.mats, key)
        if isinstance(mat, DDDMaterial):
            marker = ddd.marker(name=mat.name)
            marker = marker.material(mat)
            mats.append(marker)
Esempio n. 18
0
def rooms_test_show(root, pipeline):

    root.dump()
    items = ddd.group([root.find("/Rooms"), root.find("/Items")])
    nitems = ddd.group3()

    items = items.flatten()
    for item in items.children:
        item = item.extrude(20.0 + item.get('ddd:z_index', 0))
        item = item.translate([0, 0, -item.get('ddd:z_index', 0)])
        nitems.append(item)
Esempio n. 19
0
 def grid_xz(self, size=10.0, grid_space=1.0):
     gw = 0.05
     grid = ddd.group3(name="Helper grid XZ")
     for i in range(int(size / grid_space) + 1):
         line1 = ddd.box([i * grid_space, 0, 0, i * grid_space + gw, 0 + gw, size])
         grid.append(line1)
     for j in range(int(size / grid_space) + 1):
         line2 = ddd.box([0, 0, j * grid_space, size, 0 + gw, j * grid_space + gw])
         grid.append(line2)
     grid = grid.combine()
     return grid
Esempio n. 20
0
def tree_fir(height=20, r=0.2):
    """
    (Abeto) They are large trees, reaching heights of 10–80 m (33–262 ft) tall with trunk diameters
    of 0.5–4 m (1 ft 8 in–13 ft 1 in) when mature.
    """
    top_r = (height / 4) * random.uniform(0.9, 1.1)
    top_base_h = height / 10

    section = ddd.regularpolygon(sides=5, r=r).extrude_step(ddd.regularpolygon(sides=5, r=r*0.1), height)
    section = ddd.uv.map_cylindrical(section)
    section = section.material(ddd.mats.bark)

    #pol = ddd.regularpolygon(sides=9, r=1)
    #layer = pol.extrude_step(pol.scale(0.5), -0.4, base=False, cap=False)
    #layer = layer.extrude_step(ddd.point(), -0.2, cap=False)
    #layer = layer.material(ddd.mats.treetop).twosided().translate([0, 0, 0.6])
    layer = ddd.sphere(subdivisions=1).scale([1, 1, 0.5])
    #layer = ddd.uv.map_spherical(layer)
    layer = layer.vertex_func(lambda x, y, z, i: [x, y, z + ((x*x + y*y) * 0.7)])
    layer = layer.material(ddd.mats.treetop)

    numlayers = 8
    leaves = ddd.group3(name="Fir leaves group")
    for i in range(numlayers):
        lh = top_base_h + ((height - top_base_h) / (numlayers - 1)) * i
        lobj = layer.copy(name="Fir leaves %d" % i)
        lscale = top_r * (1 / numlayers) * (numlayers - i)
        lobj = layer.scale([lscale, lscale, lscale]).translate([0, 0, lh])
        #lobj = ddd.uv.map_cubic(lobj)
        leaves.append(lobj)

    leaves = leaves.combine()
    leaves  = leaves.merge_vertices()
    #leaves  = leaves.smooth(math.pi*2)
    leaves  = ddd.uv.map_spherical(leaves, scale=[4, 8], split=False)

    obj = ddd.group3([section.combine(), leaves], name="Fir")
    #obj.show()
    return obj
Esempio n. 21
0
    def generate_buildings_3d(self, buildings_2d):
        logger.info("Generating 3D buildings (%d)", len(buildings_2d.children))

        buildings_3d = ddd.group3(name="Buildings")
        for building_2d in buildings_2d.children:
            if building_2d.extra.get('ddd:building:parent', None) in (None, building_2d):
                logger.debug("Generating building: %s", building_2d)
                building_3d = self.generate_building_3d_generic(building_2d)
                if building_3d and len(list(building_3d.vertex_iterator())) > 0:
                    self.generate_building_3d_amenities(building_3d)
                    building_3d = self.generate_building_3d_elevation(building_3d)
                    buildings_3d.append(building_3d)
        return buildings_3d
Esempio n. 22
0
def window_with_border(width=1.6,
                       height=1.2,
                       border_depth=0.05,
                       border_thick=0.1):  #, shelf_thick=None):
    interior = window_interior(width=width - border_thick * 2,
                               height=height - border_thick * 2).translate(
                                   [0, 0, border_thick])
    border = window_border_flat(width=width,
                                height=height,
                                border_depth=border_depth,
                                border_thick=border_thick)
    obj = ddd.group3([interior, border], "Window")
    return obj
Esempio n. 23
0
def pipeline_start(pipeline, root):
    """
    """

    items = ddd.group3()

    heights = (3.0, 5.0, 10.0, 15.0)

    for h in heights:
        item = plants.reed(height=h)
        items.append(item)

    for h in heights:
        item = plants.tree_default(height=h)
        items.append(item)

    for h in heights:
        item = plants.tree_palm(height=h)
        items.append(item)

    for h in heights:
        item = plants.tree_fir(height=h)
        items.append(item)

    items_org = items.copy()

    # Original
    items = items_org.copy()
    items = ddd.align.grid(items)
    items.append(ddd.helper.all())
    items.show()

    # Simplify using convex hull
    items = ddd.meshops.reduce(items_org)
    items = ddd.align.grid(items)
    items.append(ddd.helper.all())
    items.show()

    # Simplify using bounds
    items = ddd.meshops.reduce_bounds(items_org)
    items = ddd.align.grid(items)
    items.append(ddd.helper.all())
    items.show()

    # Simplify using quadric decimation
    items = ddd.meshops.reduce_quadric_decimation(items_org, target_ratio=0.25)
    items = ddd.align.grid(items)
    items.append(ddd.helper.all())
    items.show()

    root.append(items)
Esempio n. 24
0
def tree_palm(height=14, r=0.30):
    """
    Arecaceae. Currently 181 genera with around 2,600 species are known.

    Different species of palm trees attain different heights. The Queen Palm, for instance,
    can reach 20 m in height, while the Majesty Palm grows to a maximum height of 12m and
    the Black Trunk Palm can reach a towering height of 28 m.

    The palms can reach a height of over 25 m, with trunks between 9 cm and 16 cm in diameter.
    The palms generally grow with 4–9 stems per clump, but up to 25 stems is possible.
    """

    def trunk_callback(height):
        section = ddd.regularpolygon(sides=5, r=r).extrude_step(ddd.regularpolygon(sides=5, r=r*0.8), height * 0.15)
        section = section.extrude_step(ddd.regularpolygon(sides=5, r=r*0.8).translate([random.uniform(-0.4, 0.4), random.uniform(-0.4, 0.4)]), height * 0.35)
        section = section.extrude_step(ddd.regularpolygon(sides=5, r=r*0.7).translate([random.uniform(-0.3, 0.3), random.uniform(-0.3, 0.3)]), height * 0.5)
        section = section.smooth(math.pi * 0.45)
        section = ddd.uv.map_cylindrical(section, split=False)
        section = section.material(ddd.mats.bark)
        return section

    def leaves_callback(sheight):
        golden = (1 + 5 ** 0.5) / 2
        leaf = ddd.group3(name="Leaf group")

        tt = palm_leaf(length=0.5 + height / 5, fallfactor=1.45).material(ddd.mats.treetop)
        tt = ddd.align.matrix_polar(tt, 5)
        leaf.append(tt)
        tt = palm_leaf(length=1.1 + height / 5, fallfactor=1.2).rotate([0, -math.pi * 0.1, math.pi * 2 * (golden)]).material(ddd.mats.treetop)
        tt = ddd.align.matrix_polar(tt, 3)
        leaf.append(tt)
        tt = palm_leaf(length=0.5 + height / 6, fallfactor=1).rotate([0, -math.pi * 0.3, math.pi * 2 * (golden * 2)]).material(ddd.mats.treetop)
        tt = ddd.align.matrix_polar(tt, 2)
        leaf.append(tt)

        return leaf

    obj = recursivetree(height=height, r=r, fork_iters=1, fork_angle=10.0, fork_height_ratio=1.0,
                        trunk_callback=trunk_callback, leaves_callback=leaves_callback)
    obj.name = "Tree Palm"

    objtrunk = obj.select(func=lambda o: o.mat == ddd.mats.bark).combine()
    objleaves = obj.select(func=lambda o: o.mat == ddd.mats.treetop).combine()
    objleaves = ddd.uv.map_cubic(objleaves)
    #objleaves.mesh.merge_vertices()
    obj = ddd.group3([objtrunk, objleaves], name="Tree Palm")

    #obj.show()
    return obj
Esempio n. 25
0
    def leaves_callback(sheight):
        golden = (1 + 5 ** 0.5) / 2
        leaf = ddd.group3(name="Leaf group")

        tt = palm_leaf(length=0.5 + height / 5, fallfactor=1.45).material(ddd.mats.treetop)
        tt = ddd.align.matrix_polar(tt, 5)
        leaf.append(tt)
        tt = palm_leaf(length=1.1 + height / 5, fallfactor=1.2).rotate([0, -math.pi * 0.1, math.pi * 2 * (golden)]).material(ddd.mats.treetop)
        tt = ddd.align.matrix_polar(tt, 3)
        leaf.append(tt)
        tt = palm_leaf(length=0.5 + height / 6, fallfactor=1).rotate([0, -math.pi * 0.3, math.pi * 2 * (golden * 2)]).material(ddd.mats.treetop)
        tt = ddd.align.matrix_polar(tt, 2)
        leaf.append(tt)

        return leaf
Esempio n. 26
0
def generate_scenario_run(root):
    """
    Create a circular platform for articles.
    Hill size according to importance
    """
    elements = root.find("/Elements2")
    num_items = elements.count()
    logger.info("Num elements: %s", num_items)
    distance = (num_items * 10) / (2 * math.pi)
    #result = ddd.align.polar(elements, d=distance)
    result = ddd.align.grid(elements)
    elements.replace(result)

    elements3 = ddd.group3(name="Elements3")
    root.append(elements3)
Esempio n. 27
0
def pipeline_test_line_substring(pipeline, root, logger):
    """
    Tests geometric operations.
    """

    items = ddd.group3()

    # Test substrings
    obj = ddd.line([(0, 0), (4, 0)])
    obj2 = obj.line_substring(1.0, -1.0)

    result = ddd.group([
        obj.buffer(0.1, cap_style=ddd.CAP_FLAT),
        obj2.buffer(0.1, cap_style=ddd.CAP_FLAT).material(ddd.MAT_HIGHLIGHT)
    ])
    result.show()
Esempio n. 28
0
def iconitem(path, size=(1, 1), depth=0.2, bisel=None):

    item = ddd.load(path)
    item = ddd.align.anchor(item, ddd.ANCHOR_BOTTOM_CENTER)
    item = ddd.geomops.resize(item, size)

    result = ddd.group3(name="Icon Item")

    #print(piece3)
    #print(piece3.is_empty())
    #sys.exit(1)

    for piece in item.union().individualize(always=True).flatten().children:
        piece3 = None
        #piece = piece.clean(0)

        if bisel:
            piece_smaller = piece.buffer(-bisel)
            try:
                piece3 = piece_smaller.extrude_step(
                    piece, bisel, method=ddd.EXTRUSION_METHOD_SUBTRACT)
                piece3 = piece3.extrude_step(
                    piece,
                    depth - bisel * 2,
                    method=ddd.EXTRUSION_METHOD_SUBTRACT)
                piece3 = piece3.extrude_step(
                    piece_smaller, bisel, method=ddd.EXTRUSION_METHOD_SUBTRACT)
            except:
                piece3 = None

        if not piece3 or piece3.is_empty(
        ) or piece3.extra['_extrusion_steps'] < 3:
            try:
                piece3 = piece.extrude(depth)
            except:
                logger.warn("Could not create iconitem for: %s", path)
                return None

        result.append(piece3)

    result = result.rotate(ddd.ROT_FLOOR_TO_FRONT)
    result = result.combine()
    result = ddd.uv.map_cubic(result)

    result.name = "Icon Item"

    return result
Esempio n. 29
0
def osm_model_generate_structures(osm, root, pipeline, logger):
    """

    TODO: Generate structures as a whole, without dealing with individual types, using metadata.
    """

    structures = ddd.group3(name="Structures3")

    #sidewalks_3d = objsidewalks_2d.extrude(0.3).translate([0, 0, -5]).material(ddd.mats.sidewalk)
    walls = root.find("/Structures2/Walls")
    if walls:
        walls_3d = walls.extrude(5.5).translate([0, 0,
                                                 -6]).material(ddd.mats.cement)
        walls_3d = terrain.terrain_geotiff_elevation_apply(
            walls_3d, osm.ddd_proj)
        if int(ddd.data.get('ddd:area:subdivide', 0)) > 0:
            walls_3d = ddd.meshops.subdivide_to_grid(
                walls_3d, float(ddd.data.get('ddd:area:subdivide')))
        walls_3d = ddd.uv.map_cubic(walls_3d)
        structures.append(walls_3d)

    ceilings = root.find("/Structures2/Ceilings")
    if ceilings:
        ceilings_3d = ceilings.extrude(0.5).translate([0, 0, -1.0]).material(
            ddd.mats.cement)
        ceilings_3d = terrain.terrain_geotiff_elevation_apply(
            ceilings_3d, osm.ddd_proj)
        if int(ddd.data.get('ddd:area:subdivide', 0)) > 0:
            ceilings_3d = ddd.meshops.subdivide_to_grid(
                ceilings_3d, float(ddd.data.get('ddd:area:subdivide')))
        ceilings_3d = ddd.uv.map_cubic(ceilings_3d)
        structures.append(ceilings_3d)

    #sidewalks_3d = terrain.terrain_geotiff_elevation_apply(sidewalks_3d, self.osm.ddd_proj)
    #sidewalks_3d = ddd.uv.map_cubic(sidewalks_3d)
    #floors_3d = floors_2d.extrude(-0.3).translate([0, 0, -5]).material(ddd.mats.sidewalk)
    #floors_3d = floors_2d.triangulate().translate([0, 0, -5]).material(ddd.mats.sidewalk)
    #floors_3d = terrain.terrain_geotiff_elevation_apply(floors_3d, osm.ddd_proj)

    #subway = ddd.group([sidewalks_3d, walls_3d, floors_3d, ceilings_3d], empty=3).translate([0, 0, -0.2])
    #self.osm.other_3d.children.append(subway)

    root.append(structures)
Esempio n. 30
0
def tennis_net(width, net_height_center=0.914, net_height_post=1.07):
    """
    Tennis net, on XY along the Y axis (since playground fields are seen x: length, y: width).
    """
    post1 = urban.post(net_height_post + 0.15).translate(
        [0, -width * 0.5, 0]).material(ddd.mats.steel)
    post2 = urban.post(net_height_post + 0.15).translate(
        [0, +width * 0.5, 0]).material(ddd.mats.steel)

    net = ddd.polygon(
        [[-width * 0.5, 0], [width * 0.5, 0], [width * 0.5, net_height_post],
         [0, net_height_center], [-width * 0.5, net_height_post]],
        name="Tennis net")
    net = net.triangulate(twosided=True).material(ddd.mats.fence)
    net = net.rotate(ddd.ROT_FLOOR_TO_FRONT).rotate(ddd.ROT_TOP_CCW)
    net = ddd.uv.map_cubic(net)

    item = ddd.group3([post1, post2, net])
    return item