Created
November 13, 2022 14:15
-
-
Save medicationforall/1fd7237efba4d81854a7f002bc1922b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cadquery as cq | |
import math | |
from cqterrain import Building, stone, window | |
from cadqueryhelper import series, grid | |
def grill_custom(length=20, width=4, height=40, columns=4, rows=2, grill_width=1, grill_height=1): | |
# Make a flat plane | |
pane = cq.Workplane("XY").box(length, grill_height, height) | |
t_width = length / columns | |
t_height = height / rows | |
# Make the window cutout | |
tile = cq.Workplane("XY").box(t_width, grill_height, t_height).rotate((1,0,0),(0,0,0),90) | |
# Repeat the cutout | |
tiles = grid.make_grid(tile, [t_width+grill_width, t_height+grill_width], rows=columns, columns=rows).rotate((1,0,0),(0,0,0),-90) | |
# Remove the window cutouts leaving the frame | |
combine = pane.cut(tiles) | |
return combine | |
def lattice_custom(length=20, width=4, height=40, tile_size=4, lattice_width=1, lattice_height=1, lattice_angle=45): | |
# Determine longest distance between points | |
hyp = math.hypot(length, height) | |
columns= math.floor(hyp / (tile_size+lattice_width)) | |
rows= math.floor(hyp / (tile_size+lattice_width)) | |
# Make a flat plane | |
pane = cq.Workplane("XY").box(length, lattice_height, height) | |
#make the cutout tile | |
tile = cq.Workplane("XY").box(tile_size, lattice_height, tile_size).rotate((1,0,0),(0,0,0),90) | |
tiles = grid.make_grid(tile, [tile_size+lattice_width, tile_size+lattice_width], rows=columns, columns=rows).rotate((1,0,0),(0,0,0),-90).rotate((0,1,0),(0,0,0),lattice_angle) | |
combine = pane.cut(tiles) | |
return combine | |
def lattice_windows(wall, length, width, height, count, padding): | |
# Create the cut out the holes where the windows will be placed. | |
window_cutout = cq.Workplane().box(length, width, height) | |
window_cut_series = series(window_cutout, count, length_offset = padding) | |
# create the window frame, and lattice. | |
i_window = window.frame(length, width+3, height) | |
lattice = lattice_custom(length=length, width=4, height=height, tile_size=10, lattice_height=2) | |
i_window.add(lattice) | |
# Create the window set | |
window_series = series(i_window, count, length_offset = padding) | |
# remove the cutout and add the windows | |
w = wall.cut(window_cut_series) | |
w = w.add(window_series) | |
return w | |
def casement_windows(wall, length, width, height, count, padding): | |
# Create the cut out the holes where the windows will be placed. | |
window_cutout = cq.Workplane().box(length, width, height) | |
window_cut_series = series(window_cutout, count, length_offset = padding) | |
# create the window frame, and grill. | |
i_window = window.frame(length, width+3, height) | |
grill = grill_custom(length=length, width=4, height=height, rows=4, columns=3, grill_width=2, grill_height=3) | |
i_window.add(grill) | |
# Create the window set | |
window_series = series(i_window, count, length_offset = padding) | |
# Remove the cutout and add the windows | |
w = wall.cut(window_cut_series) | |
w = w.add(window_series) | |
return w | |
def add_stones(wall, length, height, wall_width, rotate=0, seed="test4"): | |
# static boxes to act as stone | |
tile = cq.Workplane("XY").box(10,10,2) | |
tile2 = cq.Workplane("XY").box(8,8,2) | |
tile3 = cq.Workplane("XY").box(6,12,2) | |
tile4 = cq.Workplane("XY").cylinder(6,4) | |
# create an array of the stones and chamfer / fillet to add interest to the shapes. | |
stone_list = [tile.chamfer(0.8), tile2.fillet(.5), tile3.chamfer(0.5), tile4] | |
# This is the pattern generator | |
stones = stone.make_stones(stone_list, [12,12,2], columns = 14, rows = 3, seed=seed).rotate((0,1,0),(0,0,0), 90).rotate((0,0,1),(0,0,0), 90) | |
# Align the pattern and surround with a frame | |
stones = stones.translate((0,-2,-1*(height/2)+(24))).rotate((0,0,1),(0,0,0), rotate) | |
frame = window.frame(length, 2, 48).translate((0,-1*((1)+(wall_width/2)),-1*(height/2)+(24))).rotate((0,0,1),(0,0,0), rotate) | |
# Add the detailing to the room wall | |
return wall.add(stones).add(frame) | |
def make_arch_door(wall, length, width, height, floor_height): | |
# find the bottom of the wall to align to. | |
bottom = wall.faces("-Z").val() | |
#create the initial shape | |
cutout = (cq.Workplane(bottom.Center()) | |
.box(length, width, height) | |
.translate((0,0,(height/2)+floor_height)) | |
) | |
# round off the top | |
cutout = cutout.faces("Z").edges("Y").fillet((length/2)-.5) | |
#remove the arch from the wall | |
w = wall.cut(cutout) | |
return w | |
bp = Building(length=175, width=175, height=350, stories=2) | |
bp.room['build_walls']= [False,True,True,True] | |
bp.room['window_walls'] = [False, True, False, False] | |
bp.room['door_walls'] = [False, False, True, True] | |
bp.room['make_custom_door'] = make_arch_door | |
bp.door['length'] = 80 | |
bp.door['height'] = 100 | |
bp.make() | |
first_floor = bp.floors[0] | |
first_floor.window_count=5 | |
first_floor.window['height'] = 45 | |
first_floor.window['length'] = 28 | |
first_floor.make_custom_windows = lattice_windows | |
first_floor.make() | |
second_floor = bp.floors[1] | |
second_floor.window_count=3 | |
second_floor.window['height'] = 65 | |
second_floor.window['length'] = 48 | |
second_floor.make_custom_windows = casement_windows | |
second_floor.make() | |
st_front_wall = bp.floors[0].walls[1] | |
stone_wall = add_stones(st_front_wall, 175, bp.floors[0].height, bp.floors[0].wall_width) | |
bp.floors[0].walls[1] = stone_wall | |
st_front_wall = bp.floors[1].walls[1] | |
stone_wall = add_stones(st_front_wall, 175, bp.floors[1].height, bp.floors[1].wall_width, seed="demo") | |
bp.floors[1].walls[1] = stone_wall | |
build = bp.build() | |
show_object(build) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment