コード例 #1
0
    def generate(self, config):
        if config.type == 'square':
            leg = draw.makeBox(config.leg_thickness,
                               config.leg_thickness,
                               config.leg_height)

        elif config.type == 'cylinder':
            origin = (config.leg_thickness/2,config.leg_thickness/2,0)
            leg = draw.makeCylinder(config.leg_thickness/2,
                                    config.leg_height, origin)

        elif config.type == 'triangular':
            leg = draw.makePolygon([(config.leg_thickness,0,0),(0,config.leg_thickness,0),(0,0,0)])
            leg = leg.extrude((0,0,config.leg_height))

        self.add_geoms(leg)
コード例 #2
0
    def generate(self, config):
        if config.type == 'square':
            leg = draw.makeBox(config.leg_thickness,
                               config.leg_thickness,
                               config.leg_height)

        elif config.type == 'cylinder':
            origin = (config.leg_thickness/2,config.leg_thickness/2,0)
            leg = draw.makeCylinder(config.leg_thickness/2,
                                    config.leg_height, origin)

        elif config.type == 'triangular':
            leg = draw.makePolygon([(config.leg_thickness,0,0),(0,config.leg_thickness,0),(0,0,0)])
            leg = leg.extrude((0,0,config.leg_height))


        x = self.picker.pick((1.0))
        wood_id = self.get_material('grass', M(texture='bark.jpg'))
        leg.set_material(wood_id, texture_coords=[(0.0, 0.0), (x, 0.0), (x, x), (0.0, x)])
        self.add_geoms(leg)
コード例 #3
0
    def skyapt_plan(self, sector_length, sector_width, road_gap, plan):

        chooser = lambda min, max: self.picker.pick((min,max))

        if plan == 'sky':
            height_width_ratio = 8.
            build_height = self.picker.pick((100,300))
            build_width = build_height/height_width_ratio
            build_length = self.picker.pick((build_width, build_width*2))
        else:
            build_length = self.picker.pick((50,70))
            build_width = self.picker.pick((50,70))
            build_height = chooser(1,2)

        build_length = int(round(build_length))
        build_width = int(round(build_width))
        x = sector_length - build_length
        y = sector_width - build_width
        x = int(round(x))
        y = int(round(y))

        if x <= 5 or y <= 5:
            return None, None
        
        x = chooser(5, x)
        y = chooser(5, y)

        build_origin = (x, y, 0)
        sky_apt = None
        if plan == 'sky':
            self.subgen('building', build_origin, build_length, build_width, height=build_height)
            sky_apt = build_origin
        else:

            a,b,c = build_origin
            base = draw.makePolygon([build_origin,(a+build_length,b,0),
                                    (a+build_length,b+build_width,0),
                                    (a,b+build_width,0),build_origin])
            sky_apt = base.extrude((0,0,3))
            self.add_geom(sky_apt)

        build_start = (x, y)
        build_end = (x+build_length, y+build_width)
        build_rect = geometry.AxisAligned2DRectangle(build_start, build_end)
        sector_rect = geometry.AxisAligned2DRectangle((0,0), (sector_length, sector_width))
        common, layouts = geometry.split_overlapping_rectangles(sector_rect, build_rect)
        for layout in layouts:
            (x1, y1), (x2, y2) = layout.point1, layout.point2
            layout_length = abs(x2 - x1) - road_gap
            layout_width = abs(y2 - y1) - road_gap
            dummy, sub_layouts = self.skyapt_plan(layout_length,
                                                  layout_width, road_gap, plan)
            if not sub_layouts:
                origin = (layout.min_x(), layout.min_y(), 0)
                if plan == 'sky':
                    plot_gap = 5
                    height_width_ratio = 8.
                    building_range = self.picker.random()
                    if building_range <= 0.4:
                        building_height = self.picker.pick((15,75))
                        height_range = (15,75)
                    else:
                        building_height = self.picker.pick((3,15))
                        height_range = (3,15)
                    plot_width = building_height/height_width_ratio
                    if plot_width < 5:
                        plot_width = 5
                    plot_length = (plot_width,plot_width*2)
                else:
                    plot_gap = 8
                    height_width_ratio = 6.
                    building_height = self.picker.pick((3,50))
                    height_range = (3,50)
                    plot_width = building_height/height_width_ratio
                    if plot_width < 5:
                        plot_width = 5
                    plot_length = (plot_width,plot_width*3)
                self.subgen('celllayout', origin, layout_length,
                            layout_width, [plot_length], plot_width, road_gap,
                            [height_range], plot_gap)

        return sky_apt, layouts
コード例 #4
0
    def generate(self, config):
        # x is on horizontal,  y is on depthwards, z is on upwards
        '''
        z    y
        |   *
        |  *
        | *
        - - - x

        all units are in metres
        '''

        # in short
        '''
        pnt is where the object has to be created
        dir is in which directiong it has to be created

        draw.makeBox(length, width, height, pnt=(0,0,0), dir=(0,0,1))
        draw.makeSphere(radius, pnt=(0,0,0), dir=(0,0,1), angle1=0.5*PI, angle2=0.5*PI, angle3=2*PI)
        draw.makeCylinder(radius, height, pnt=(0,0,0), dir=(0,0,1), angle=2*PI)
        draw.makePlane(length,width, pnt=(0,0,0), dir=(0,0,1))
        draw.makePolygon([]) -- Make a polygon of a list of points
        '''

        C = config

        if C.box:
            box = draw.makeBox(1, 1, 1)
            self.add_geom(box) # adding box to the scene

            pnt = (2, 2, 2)
            o_box = draw.makeBox(1, 1, 1, pnt)
            self.add_geom(o_box) # adding another box at different point in scene

        if C.sphere:
            sphere = draw.makeSphere(2)
            self.add_geom(sphere)

            pnt = (2, 2, 2)
            o_sphere = draw.makeSphere(2, pnt)
            self.add_geom(o_sphere)

        if C.cylinder:
            cylinder = draw.makeCylinder(1, 1)
            self.add_geom(cylinder)

            pnt = (2, 2, 2)
            o_cylinder = draw.makeCylinder(1, 1, pnt)
            self.add_geom(o_cylinder)

        if C.plane:
            plane = draw.makePlane(1, 1)
            self.add_geom(plane)

            pnt = (2, 2, 2)
            o_plane = draw.makePlane(1, 1, pnt)
            self.add_geom(o_plane)

        if C.polygon:
            polygon = draw.makePolygon([(0, 0, 0),
                                        (1, 0, 0),
                                        (1, 0, 1),
                                        (0, 0, 1),
                                        (0, 0, 0)]) # this returns a wire connecting points

            face = draw.Face(polygon) # filling up the wire with mass, u can also do other things with the wire

            self.add_geom(face)