def sitePlacement(length: float, width: float, height: float, rotation: float,
                  area: float):
    site = makeSite()
    building = makeBuilding(site, length, width, height, rotation, area)
    area = 0
    floors = 0
    for space in building:
        area += space.area
        floors += 1
    model = glTF()
    colorBlue = model.add_material(0.0, 0.631, 0.945, 0.9, 1.0, "Blue")
    colorGreen = model.add_material(0.486, 0.733, 0.0, 0.9, 0.0, "Green")
    colorOrange = model.add_material(0.964, 0.325, 0.078, 0.9, 1.0, "Orange")
    colorYellow = model.add_material(1.0, 0.733, 0.0, 0.9, 1.0, "Yellow")
    spaceMesh = site.mesh_graphic
    model.add_triangle_mesh(spaceMesh.vertices, spaceMesh.normals,
                            spaceMesh.indices, colorGreen)
    for space in building:
        spaceMesh = space.mesh_graphic
        colorIndex = random.randint(0, 2)
        if colorIndex == 0: color = colorBlue
        if colorIndex == 1: color = colorOrange
        if colorIndex == 2: color = colorYellow
        model.add_triangle_mesh(spaceMesh.vertices, spaceMesh.normals,
                                spaceMesh.indices, color)
    return {
        "model": model.save_base64(),
        'computed': {
            'floors': floors,
            'area': area
        }
    }
Exemple #2
0
def create_box(length, width, height):
    vertices = []
    normals = []
    indices = []

    # Create a model to hold the geometry.
    model = glTF()

    # Create a material to use in the model.
    model.add_material(0.0, 0.0, 1.0, 0.9, 1.0, "Blue")

    # bottom
    b1 = [0, 0, 0]
    b2 = [width, 0, 0]
    b3 = [width, length, 0]
    b4 = [0, length, 0]

    t1 = [0, 0, height]
    t2 = [width, 0, height]
    t3 = [width, length, height]
    t4 = [0, length, height]

    index = create_square_face(vertices, normals, indices, 0, b4, b3, b2, b1)
    index = create_square_face(vertices, normals, indices, index, t1, t2, t3, t4)
    index = create_square_face(vertices, normals, indices, index, b1, b2, t2, t1)
    index = create_square_face(vertices, normals, indices, index, b2, b3, t3, t2)
    index = create_square_face(vertices, normals, indices, index, b3, b4, t4, t3)
    index = create_square_face(vertices, normals, indices, index, b4, b1, t1, t4)

    node_name = model.add_triangle_mesh(vertices, normals, indices, 0)

    return (node_name, model)
from hypar import glTF
from random import randint, uniform
from typing import List

from aecSpace.aecPoint import aecPoint
from aecSpace.aecShaper import aecShaper
from aecSpace.aecSpace import aecSpace
from aecSpace.aecSpaceGroup import aecSpaceGroup
from aecSpace.aecSpacer import aecSpacer

spacer = aecSpacer()
shaper = aecShaper()

model = glTF()
colorAqua = model.add_material(0.3, 0.72, 0.392, 1.0, 0.8, "Aqua")
colorBlue = model.add_material(0.0, 0.631, 0.945, 1.0, 0.8, "Blue")
colorBrown = model.add_material(0.5, 0.2, 0.0, 1.0, 0.5, "Brown")
colorGray = model.add_material(0.5, 0.5, 0.5, 1.0, 0.8, "Gray")
colorGranite = model.add_material(0.25, 0.25, 0.25, 1.0, 0.8, "Granite")
colorGreen = model.add_material(0.486, 0.733, 0.0, 1.0, 0.8, "Green")
colorOrange = model.add_material(0.964, 0.325, 0.078, 1.0, 0.8, "Orange")
colorPurple = model.add_material(0.75, 0.07, 1.0, 1.0, 0.8, "Purple")
colorSand = model.add_material(1.0, 0.843, 0.376, 1.0, 0.8, "Sand") 
colorSilver = model.add_material(0.75, 0.75, 0.75, 1.0, 1.0, "Silver")
colorWhite = model.add_material(1.0, 1.0, 1.0, 1.0, 0.8, "White")
colorYellow = model.add_material(1.0, 0.733, 0.0, 1.0, 0.8, "Yellow")

def getColor(color: int = 0):
    if color == 0: return colorAqua
    if color == 1: return colorBlue
    if color == 2: return colorBrown
Exemple #4
0
def makeTowerDucts(stories: int = 5, mostRooms: int = 4, routing = 0, useColor=0):
    model = glTF()
    spaces = MakeSpaceTower.makeSpaceTower(stories, mostRooms)

    alpha = 0.2
    reflect = 0.1
    colorAqua = model.add_material(0.302, 0.722, 0.392, alpha, reflect, "Aqua")
    colorBlue = model.add_material(0.0, 0.631, 0.945, alpha, reflect, "Blue")
    colorCyan = model.add_material(0.275, 0.941, 0.941, alpha, reflect, "Cyan")
    colorGranite = model.add_material(0.235, 0.235, 0.235, alpha, reflect, "Gray")
    colorGray = model.add_material(0.5, 0.5, 0.5, 1.0, 0.2, "Gray")
    colorGreen = model.add_material(0.486, 0.733, 0.0, alpha, reflect, "Green")
    colorOrange = model.add_material(0.964, 0.325, 0.078, alpha, reflect, "Orange")
    colorSand = model.add_material(1.0, 0.843, 0.376, alpha, reflect, "Sand") 
    colorTeal = model.add_material(0.0, 0.502, 0.502, alpha, reflect, "Teal")  
    colorYellow = model.add_material(1.0, 0.733, 0.0, alpha, reflect, "Yellow")

    loads = space_cfm_calc.Space_CFM_Calc(spaces)
    ductSpecs = pathing.minSpanningPath.GetDuctPathFromBldg(loads)
    mini = min([x["cfm"] for x in ductSpecs])
    maxi = max([x["cfm"] for x in ductSpecs])
    numcolors = 12
    hmColors = []

    xCoord = 13000
    yCoord = 74000
    point = aecPoint(xCoord, yCoord, 0)
    shaper = aecShaper()
    stack = aecSpace()
    stack.boundary = shaper.makeBox(point, 4000, 3000)
    stack.color = aecColor.gray
    stack.level = 8500
    stack.height = ((stories - 2) * 3500) + 8000
    spaces += [stack]
    
    xCoord = 10000
    yCoord = 65000
    point = aecPoint(xCoord, yCoord, 0)
    mech = aecSpace()
    mech.boundary = shaper.makeBox(point, 10000, 15000)
    mech.color = aecColor.gray
    mech.level = ((stories - 1) * 3500) + 11000
    mech.height = 4000
    spaces += [mech]    
    
    for space in spaces:
        spaceMesh = space.mesh_graphic
        if space.color.color == aecColor.aqua: color = colorAqua
        if space.color.color == aecColor.blue: color = colorBlue
        if space.color.color == aecColor.cyan: color = colorCyan
        if space.color.color == aecColor.gray: color = colorGray 
        if space.color.color == aecColor.granite: color = colorGranite
        if space.color.color == aecColor.green: color = colorGreen
        if space.color.color == aecColor.orange: color = colorOrange
        if space.color.color == aecColor.sand: color = colorSand
        if space.color.color == aecColor.teal: color = colorTeal
        if space.color.color == aecColor.yellow: color = colorYellow
        model.add_triangle_mesh(spaceMesh.vertices, spaceMesh.normals, spaceMesh.indices, color)   

    for i in range(numcolors):
        dI = i * (maxi-mini)/numcolors
        r,g,b = heatmap.convert_to_rgb(mini, maxi, dI)
        hmColors.append(model.add_material(r/255,g/255,b/255,1.0,1.0,"HM"+str(i)))
    for ductSpec in ductSpecs:
        start = aecPoint(ductSpec['start'][0], ductSpec['start'][1], ductSpec['start'][2])
        end = aecPoint(ductSpec['end'][0], ductSpec['end'][1], ductSpec['end'][2])
        chosenColor = math.floor(12-ductSpec['cfm'] / (maxi-mini) * 12 )
        duct = MakeDuct.makeDuct(start, end, ductSpec['width'], ductSpec['height'])
        ductMesh = duct.mesh_graphic
        if useColor == 1:
            model.add_triangle_mesh(ductMesh.vertices, ductMesh.normals, ductMesh.indices, hmColors[ chosenColor-1])   
        else:
            model.add_triangle_mesh(ductMesh.vertices, ductMesh.normals, ductMesh.indices, colorGray)   

#   return {"model": model.save_base64()}   
    model.save_glb('model.glb')
Exemple #5
0
def makeTowerShell(xSize: float = 60,
                   ySize: float = 60,
                   levels: int = 10,
                   floorType: int = 1):
    def randomFloor(point, xSize, ySize):
        try:
            floor = aecSpace()
            shaper = aecShaper()
            if floorType == 1:
                floor.boundary = shaper.makeBox(point, xSize, ySize)
                floor.rotate(uniform(0, 360))
                x = 0
                boundaries = uniform(1, 5)
                tempFloor = aecSpace()
                while x < boundaries:
                    tempFloor.boundary = shaper.makeBox(origin=point,
                                                        xSize=uniform(65, 100),
                                                        ySize=uniform(65, 100))
                    tempFloor.rotate(uniform(0, 360))
                    floor.add(tempFloor.points_floor)
                    x += 1
            if floorType == 2:
                floor.boundary = shaper.makeCylinder(aecPoint(
                    point.x + (xSize * 0.5), point.y + (ySize * 0.5)),
                                                     radius=(xSize * 0.5))
            if floorType > 2 and floorType < 9:
                floor.boundary = shaper.makePolygon(aecPoint(
                    point.x + (xSize * 0.5), point.y + (ySize * 0.5)),
                                                    radius=(xSize * 0.5),
                                                    sides=floorType)
            if floorType == 9:
                floor.boundary = shaper.makeCross(point,
                                                  xSize=xSize,
                                                  ySize=ySize)
            if floorType == 10:
                floor.boundary = shaper.makeH(point, xSize=xSize, ySize=ySize)
            if floorType == 11:
                floor.boundary = shaper.makeU(point, xSize=xSize, ySize=ySize)
            floor.height = 15
            return floor
        except:
            return False

    spacer = aecSpacer()
    floor = randomFloor(aecPoint(0, 0, 0), xSize, ySize)
    floors = [floor] + spacer.stack(floor, levels - 1)
    if uniform(1, 3) == 1:
        plinth = aecSpace()
        plinthLevels = randint(1, 3)
        plinthHeight = 15 * plinthLevels
        plinth.wrap(floor.points_floor)
        plinth.height = plinthHeight
        plinth.scale(1.25, 1.25, 1)
        floors = floors[plinthLevels:]
        floors = [plinth] + floors
    colors = [aecColor.blue, aecColor.green, aecColor.white]
    tower = aecSpaceGroup()
    tower.spaces = floors
    tower.setColor(colors[randint(0, 2)])
    if levels >= 10:
        index = 10
        while index < levels:
            tower.scale(0.8, 0.8, 1, index=index)
            index += 1
    if levels >= 30:
        index = 30
        while index < levels:
            tower.scale(0.8, 0.8, 1, index=index)
            index += 1

    model = glTF()
    colorBlue = model.add_material(0.0, 0.631, 0.945, 0.5, 0.8, "Blue")
    colorWhite = model.add_material(1.0, 1.0, 1.0, 0.5, 0.8, "White")
    colorIndex = randint(0, 1)
    if colorIndex == 0: color = colorBlue
    if colorIndex == 1: color = colorWhite
    area = 0
    for space in floors:
        area += space.area
        spaceMesh = space.mesh_graphic
        model.add_triangle_mesh(spaceMesh.vertices, spaceMesh.normals,
                                spaceMesh.indices, color)
    return {
        "model": model.save_base64(),
        'computed': {
            'floors': levels,
            'area': area
        }
    }
def makeTower(bldgWidth: float = 20,
              bldgDepth: float = 20,
              floorHeight: float = 3,
              bldgLevels: int = 10,
              plinthScale: float = 1.1):
    """
    Constructs a series of tower space distibution examples from a 
    combination of fixed and randomly set values and floor divisions.
    """
    spacer = aecSpacer()
    shaper = aecShaper()

    def full(point, xWidth, yDepth, zHeight, level):
        floor = aecSpace()
        floor.boundary = shaper.makeBox(point, xWidth, yDepth)
        floor.height = zHeight
        floor.level = level
        setColors([floor])
        return [floor]

    def halfDepth(point, xWidth, yDepth, zHeight, level):
        depth = yDepth * 0.5
        half1 = aecSpace()
        half1.boundary = shaper.makeBox(point, xWidth, depth)
        half1.height = zHeight
        half1.level = level
        halfSpaces = [half1] + spacer.row(half1, xAxis=False)
        setColors(halfSpaces)
        return halfSpaces

    def halfWidth(point, xWidth, yDepth, zHeight, level):
        width = xWidth * 0.5
        half1 = aecSpace()
        half1.boundary = shaper.makeBox(point, width, yDepth)
        half1.height = zHeight
        half1.level = level
        halfSpaces = [half1] + spacer.row(half1)
        setColors(halfSpaces)
        return halfSpaces

    def quarterDepth(point, xWidth, yDepth, zHeight, level):
        if randint(0, 1) == 0:
            depth = yDepth * 0.25
            scale = 3
        else:
            depth = yDepth * 0.75
            scale = 0.333333333
        half1 = aecSpace()
        half1.boundary = shaper.makeBox(point, xWidth, depth)
        half1.height = zHeight
        half1.level = level
        halfSpaces = [half1] + spacer.row(half1, xAxis=False)
        halfSpaces[1].scale(1, scale, 1, halfSpaces[1].points_floor[0])
        setColors(halfSpaces)
        return halfSpaces

    def quarterWidth(point, xWidth, yDepth, zHeight, level):
        if randint(0, 1) == 0:
            width = xWidth * 0.25
            scale = 3
        else:
            width = xWidth * 0.75
            scale = 0.333333333
        half1 = aecSpace()
        half1.boundary = shaper.makeBox(point, width, yDepth)
        half1.height = zHeight
        half1.level = level
        halfSpaces = [half1] + spacer.row(half1)
        halfSpaces[1].scale(scale, 1, 1, halfSpaces[1].points_floor[0])
        setColors(halfSpaces)
        return halfSpaces

    def setColors(halfSpaces):
        colors = [
            aecColor.blue, aecColor.orange, aecColor.purple, aecColor.yellow
        ]
        colorPick = randint(0, 3)
        halfSpaces[0].color = colors[colorPick]
        if len(halfSpaces) == 1: return
        colors.reverse()
        halfSpaces[1].color = colors[colorPick]

    def makeFloor(point, xWidth, yDepth, zHeight, level):
        floorType = randint(0, 4)
        if floorType == 0:
            floorSpaces = full(point, xWidth, yDepth, zHeight, level)
        if floorType == 1:
            floorSpaces = halfDepth(point, xWidth, yDepth, zHeight, level)
        if floorType == 2:
            floorSpaces = halfWidth(point, xWidth, yDepth, zHeight, level)
        if floorType == 3:
            floorSpaces = quarterDepth(point, xWidth, yDepth, zHeight, level)
        if floorType == 4:
            floorSpaces = quarterWidth(point, xWidth, yDepth, zHeight, level)
        return floorSpaces

    def makeCore(point, xWidth, yDepth, zHeight):
        xCoord = (point.x - 5) + (xWidth * 0.5)
        yCoord = (point.y + (yDepth * (randint(0, 9) * 0.1)))
        point = aecPoint(xCoord, yCoord, point.z)
        core = aecSpace()
        core.boundary = shaper.makeBox(point, 10, 20)
        core.height = zHeight
        core.color = aecColor.gray
        return core

    plinth = aecSpace()
    point = aecPoint()
    plinth.boundary = shaper.makeBox(point, bldgWidth, bldgDepth)
    plinth.scale(plinthScale, plinthScale, 2, plinth.centroid_floor)
    plinth.height = (floorHeight * 2)
    plinth.color = aecColor.green
    core = makeCore(point, bldgWidth, bldgDepth,
                    floorHeight * (bldgLevels + 3))
    level = (floorHeight * 2)
    x = 0
    floors = []
    while x < bldgLevels:
        floors = floors + makeFloor(point, bldgWidth, bldgDepth, floorHeight,
                                    level)
        level += floorHeight
        x += 1
    model = glTF()
    colorBlue = model.add_material(0.0, 0.631, 0.945, 0.9, 0.8, "Blue")
    colorGray = model.add_material(0.5, 0.5, 0.5, 0.9, 0.8, "Gray")
    colorGreen = model.add_material(0.486, 0.733, 0.0, 0.9, 0.8, "Green")
    colorOrange = model.add_material(0.964, 0.325, 0.078, 0.9, 0.8, "Orange")
    colorPurple = model.add_material(0.75, 0.07, 1.0, 0.9, 0.8, "Purple")
    colorYellow = model.add_material(1.0, 0.733, 0.0, 0.9, 0.8, "Yellow")
    mesh = core.mesh_graphic
    model.add_triangle_mesh(mesh.vertices, mesh.normals, mesh.indices,
                            colorGray)
    mesh = plinth.mesh_graphic
    model.add_triangle_mesh(mesh.vertices, mesh.normals, mesh.indices,
                            colorGreen)
    area = 0
    levels = 0
    for space in floors:
        area += space.area
        levels += 1
        spaceMesh = space.mesh_graphic
        colorIndex = randint(0, 3)
        if colorIndex == 0: color = colorBlue
        if colorIndex == 1: color = colorOrange
        if colorIndex == 2: color = colorPurple
        if colorIndex == 3: color = colorYellow
        model.add_triangle_mesh(spaceMesh.vertices, spaceMesh.normals,
                                spaceMesh.indices, color)
    return {
        "model": model.save_base64(),
        'computed': {
            'floors': levels,
            'area': area
        }
    }