예제 #1
0
def test_metal():
    mt = Metal('test_metal')
    assert mt.r_reflectance == 0
    assert mt.g_reflectance == 0
    assert mt.b_reflectance == 0
    assert mt.specularity == 0.9
    assert mt.roughness == 0
    assert mt.to_radiance(
        minimal=True) == 'void metal test_metal 0 0 5 0.0 0.0 0.0 0.9 0.0'
예제 #2
0
def test_assign_values():
    mt = Metal('test_metal', 0.6, 0.7, 0.8, 0, 0)
    assert mt.r_reflectance == 0.6
    assert mt.g_reflectance == 0.7
    assert mt.b_reflectance == 0.8
    assert mt.specularity == 0
    assert mt.roughness == 0
    assert mt.to_radiance(
        minimal=True) == 'void metal test_metal 0 0 5 0.6 0.7 0.8 0.0 0.0'
예제 #3
0
def test_material_lockability():
    """Test the lockability of Metal."""
    mt = Metal('test_metal', 0.6, 0.7, 0.8, 0, 0)
    mt.r_reflectance = 0.5
    mt.lock()
    with pytest.raises(AttributeError):
        mt.r_reflectance = 0.7
    mt.unlock()
    mt.r_reflectance = 0.7
예제 #4
0
def test_material_equivalency():
    """Test the equality of a material to another."""
    mt_1 = Metal('test_metal', 0.6, 0.7, 0.8, 0, 0)
    mt_2 = mt_1.duplicate()
    mt_3 = Metal('test_metal2', 0.8, 0.7, 0.8, 0, 0)

    assert mt_1 is mt_1
    assert mt_1 is not mt_2
    assert mt_1 == mt_2
    assert isinstance(mt_2, Metal)
    assert mt_1 != mt_3
    collection = [mt_1, mt_2, mt_3]
    assert len(set(collection)) == 2
예제 #5
0
def test_from_dict_w_modifier():
    glass_mod = {
        "identifier": "test_glass_mod",
        "type": "Glass",
        "r_transmissivity": 0.4,
        "g_transmissivity": 0.5,
        "b_transmissivity": 0.6,
        "refraction_index": None,
        "modifier": None,
        "dependencies": []
    }

    plastic_dict = {
        "identifier": "test_metal",
        "type": "Metal",
        "r_reflectance": 0.1,
        "g_reflectance": 0.2,
        "b_reflectance": 0.3,
        "specularity": 0.01,
        "roughness": 0.02,
        "modifier": glass_mod,
        "dependencies": []
    }

    gg = Metal.from_dict(plastic_dict)
    assert gg.to_radiance(minimal=True, include_modifier=False) == \
        'test_glass_mod metal test_metal 0 0 5 0.1 0.2 0.3 0.01 0.02'
    assert gg.modifier.to_radiance(minimal=True) == \
        'void glass test_glass_mod 0 0 3 0.4 0.5 0.6'
예제 #6
0
def test_update_values():
    mt = Metal('test_metal', 0.6, 0.7, 0.8, 0.1, 0.02)
    mt.r_reflectance = 0.5
    mt.g_reflectance = 0.4
    mt.b_reflectance = 0.3
    mt.specularity = 0.1
    mt.roughness = 0.02
    assert mt.r_reflectance == 0.5
    assert mt.g_reflectance == 0.4
    assert mt.b_reflectance == 0.3
    assert mt.specularity == 0.1
    assert mt.roughness == 0.02
    assert mt.to_radiance(minimal=True) == \
        'void metal test_metal 0 0 5 0.5 0.4 0.3 0.1 0.02'
예제 #7
0
def test_from_string():
    plastic_str = """void metal plastic_alt_mat
        0
        0
        5
            0.91 0.92 0.93
            0.3 0.4
            
    """
    mt = Metal.from_string(plastic_str)
    assert mt.identifier == 'plastic_alt_mat'
    assert mt.r_reflectance == 0.91
    assert mt.g_reflectance == 0.92
    assert mt.b_reflectance == 0.93
    assert mt.to_radiance(minimal=True) == ' '.join(plastic_str.split())
ghenv.Component.NickName = 'MetalMod3'
ghenv.Component.Message = '1.1.0'
ghenv.Component.Category = 'HB-Radiance'
ghenv.Component.SubCategory = '1 :: Modifiers'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_rad_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import the honeybee-radiance dependencies
    from honeybee_radiance.modifier.material import Metal
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # set the default modifier properties
    _spec_ = 0.9 if _spec_ is None else _spec_
    _rough_ = 0.0 if _rough_ is None else _rough_

    # create the modifier
    modifier = Metal(clean_and_id_rad_string(_name), _r_ref, _g_ref, _b_ref,
                     _spec_, _rough_)
    modifier.display_name = _name
예제 #9
0
def test_from_single_value():
    mt = Metal.from_single_reflectance('mt_test', 0.6)
    assert mt.r_reflectance == 0.6
    assert mt.g_reflectance == 0.6
    assert mt.b_reflectance == 0.6
예제 #10
0
def main():
    argc = len(sys.argv)
    if argc < 2:
        print("Error: .rad file not specified, usage: python3 genParallelViews.py <file.rad>")
        return -1
    
    filePath = sys.argv[1]
    if not filePath.endswith(".rad"):
        print("Error: .rad file not specified, usage: python3 genParallelViews.py <file.rad>")
        return -1

    print("Scene up direction: [{0}, {1}, {2}]".format(SCENE_UP[0], SCENE_UP[1], SCENE_UP[2]))

    # Read in the RAD file
    stringObjects = reader.parse_from_file(filePath)
    polygons = []
    materials = []
    currentModifier = None
    for stringObject in stringObjects:
        if not "polygon" in stringObject:
            validMaterial = False
            for material in VALID_MATERIALS:
                if material in stringObject:
                    validMaterial = True
                    break
            
            # This is a bit hacky right now. We get an exception if we try and parse a non-material or non-polygon
            if not validMaterial:
                print("Error: Can't parse '{0}' from RAD file. If this is a material try manually adding it to the script, else ignore.".format(stringObject))
                continue

        primitiveDict = reader.string_to_dict(stringObject)
        if primitiveDict["type"] == "polygon":
            primitiveDict["modifier"] = None
            polygon = Polygon.from_primitive_dict(primitiveDict)
            polygon.modifier = currentModifier
            polygons.append(polygon)
        elif primitiveDict["type"] == "plastic":
            plastic = Plastic.from_primitive_dict(primitiveDict)
            currentModifier = plastic
            materials.append(plastic)
        elif primitiveDict["type"] == "metal":
            metal = Metal.from_primitive_dict(primitiveDict)
            currentModifier = metal
            materials.append(metal)
        elif primitiveDict["type"] == "glass":
            glass = Glass.from_primitive_dict(primitiveDict)
            currentModifier = glass
            materials.append(glass)
        else:
            print("Error: Unable to assign material from '{0}'.".format(stringObject))

    # Loop through all the polygons read in from the RAD file and classify them as triangles or quads
    triangles = []
    quads = []
    for polygon in polygons:
        if len(polygon.vertices) == 3:
            triangles.append(polygon)
        elif len(polygon.vertices) == 4:
            quads.append(polygon)

    # Loop through all the triangles read in from the RAD file and attempt to form quads from them
    trianglesMissed = []
    i = 0
    while True:
        if i >= len(triangles) - 1:
            break

        triangleA = triangles[i]
        triangleB = triangles[i+1]
        if formsQuad(triangleA, triangleB):
            quad = formQuad(triangleA, triangleB)
            quads.append(quad)
            i += 2
        else:
            trianglesMissed.append(triangleA)
            i += 1

    if len(trianglesMissed) != 0:    
        print("The following triangles from the RAD file couldn't be formed into quads: ", end="")
        for triangle in trianglesMissed:
            print("{0}".format(triangle.identifier), end=" ")
        print()
    
    # Loop through all the quads and generate a Radiance parallel projection view for it
    viewDict = {}
    for quad in quads:
        # type 'l' defines this view as a parallel projection
        view = View(quad.identifier, type='l')
         
        # Get the dimensions of the quad. 
        # One of these should be approximately 0.0 because a quad is two dimensional
        dimensions = [0, 0, 0]
        for i in range(3):
            dimensions[i] = getDimensionLength(quad, i)
        
        # Set the view's horizontal and vertical size based on the dimensions of the quad
        # The projection will contain the entire quad
        horizontalSet = False
        verticalSet = False
        for i in range(3):
            if dimensions[i] > SIGMA:
                if not horizontalSet:
                    view.h_size = dimensions[i]
                    horizontalSet = True
                else:
                    view.v_size = dimensions[i]
                    verticalSet = True
                    break
        
        if not horizontalSet or not verticalSet:
            print("Error: " + view.identifier + " vh and/or vv not set")
            continue

        # Set view direction
        normal = getQuadNormal(quad)
        if len(normal) == 0:
            print("Error: " + view.identifier + " vn not set")
            continue

        direction = (-normal[0], -normal[1], -normal[2])
        view.direction = direction

        # Set view position
        position = getViewPosition(quad, dimensions, normal)
        view.position = position

        # Set view up
        view.up_vector = SCENE_UP
        if listsSame(SCENE_UP, direction) or listsSame(SCENE_UP, normal):
            if not listsSame(SCENE_UP, [0.0, 0.0, 1.0]):
                view.up_vector = [0.0, 0.0, 1.0]
            elif not listsSame(SCENE_UP, [0.0, 1.0, 0.0]):
                view.up_vector = [0.0, 1.0, 0.0]
            else:
                view.up_vector = [1.0, 0.0, 0.0]

        viewDict[quad.identifier] = view

    print("\n-----Radiance Parallel Views-----")
    for view in viewDict.values():
        print("view=" + view.identifier + " " + view.to_radiance())
    print("----------\n\nTotal view count: {0}, Total quad count: {1}".format(len(viewDict.values()), len(quads)))

    writeOBJFile(BASE_FILE_NAME, quads, viewDict)
    writeMTLFile(BASE_FILE_NAME, quads)

    return 0
예제 #11
0
ghenv.Component.Category = 'HB-Radiance'
ghenv.Component.SubCategory = '1 :: Modifiers'
ghenv.Component.AdditionalHelpFromDocStrings = '2'

try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_rad_string, clean_rad_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import the honeybee-radiance dependencies
    from honeybee_radiance.modifier.material import Metal
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # set the default modifier properties
    _spec_ = 0.9 if _spec_ is None else _spec_
    _rough_ = 0.0 if _rough_ is None else _rough_
    name = clean_and_id_rad_string('MetalMaterial') if _name_ is None else \
        clean_rad_string(_name_)

    # create the modifier
    modifier = Metal.from_single_reflectance(name, _reflect, _spec_, _rough_)
    if _name_ is not None:
        modifier.display_name = _name_
예제 #12
0
def modifier_metal(directory):
    metal = Metal.from_single_reflectance('sheet_metal_0.5', 0.5, 0.95)
    dest_file = os.path.join(directory, 'modifier_metal.json')
    with open(dest_file, 'w') as fp:
        json.dump(metal.to_dict(), fp, indent=4)
예제 #13
0
ghenv.Component.Category = 'HB-Radiance'
ghenv.Component.SubCategory = '1 :: Modifiers'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_rad_string, clean_rad_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import the honeybee-radiance dependencies
    from honeybee_radiance.modifier.material import Metal
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # set the default modifier properties
    _spec_ = 0.9 if _spec_ is None else _spec_
    _rough_ = 0.0 if _rough_ is None else _rough_
    name = clean_and_id_rad_string('MetalMaterial') if _name_ is None else \
        clean_rad_string(_name_)

    # create the modifier
    modifier = Metal(name, _r_ref, _g_ref, _b_ref, _spec_, _rough_)
    if _name_ is not None:
        modifier.display_name = _name_
ghenv.Component.Message = '1.1.0'
ghenv.Component.Category = 'HB-Radiance'
ghenv.Component.SubCategory = '1 :: Modifiers'
ghenv.Component.AdditionalHelpFromDocStrings = '2'

try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_rad_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:  # import the honeybee-radiance dependencies
    from honeybee_radiance.modifier.material import Metal
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
    # set the default modifier properties
    _spec_ = 0.9 if _spec_ is None else _spec_
    _rough_ = 0.0 if _rough_ is None else _rough_

    # create the modifier
    modifier = Metal.from_single_reflectance(
        clean_and_id_rad_string(_name), _reflect, _spec_, _rough_)
    modifier.display_name = _name