def test_value_update(): v = View('__') v.position = (0, 0, 10) v.direction = (0, 1, 0) v.up_vector = (0, 0, 1) v.type = 'l' v.h_size = 240 v.v_size = 300 v.shift = -10 v.lift = -25 v.fore_clip = 30 v.aft_clip = 50 assert v.position == (0, 0, 10) assert v.direction == (0, 1, 0) assert v.up_vector == (0, 0, 1) assert v.type == 'l' assert v.h_size == 240 assert v.v_size == 300 assert v.shift == -10 assert v.lift == -25 assert v.fore_clip == 30 assert v.aft_clip == 50 assert v.to_radiance() == '-vtl -vp 0.0 0.0 10.0 -vd 0.0 1.0 0.0' \ ' -vu 0.0 0.0 1.0 -vh 240.0 -vv 300.0 -vs -10.0 -vl -25.0 ' \ '-vo 30.0 -va 50.0'
def test_from_grid_vth(): v = View('test_vth') v.position = (0, 0, 0) v.direction = (0, 1, 0) v.up_vector = (0, 0, 1) v.type = 'h' v.h_size = 180 v.v_size = 180 grid = v.grid(x_div_count=2, y_div_count=5) from_grid = View.from_grid(grid) assert v.to_radiance() == from_grid.to_radiance()
def test_from_grid_unf(): v = View('test_vta') v.position = (3, 7, 1.8) v.direction = (0, 1, 0) v.up_vector = (0, 0, 1) v.type = 'a' v.h_size = 360 v.v_size = 360 grid = [ './tests/assets/view/view_0000.unf', './tests/assets/view/view_0001.unf', './tests/assets/view/view_0002.unf', './tests/assets/view/view_0003.unf', './tests/assets/view/view_0004.unf' ] from_grid = View.from_grid(grid) assert v.to_radiance() == from_grid.to_radiance()
def test_grid_dimension(): v = View('test_vtv') v.position = (0, 0, 0) v.direction = (0, 1, 0) v.up_vector = (0, 0, 1) v.type = 'v' v.h_size = 60 v.v_size = 60 grid = v.grid(x_div_count=1, y_div_count=1) from_grid = View.from_grid(grid) assert v.to_radiance() == from_grid.to_radiance() grid = v.grid(x_div_count=2, y_div_count=4) from_grid = View.from_grid(grid) assert v.to_radiance() == from_grid.to_radiance() grid = v.grid(x_div_count=1, y_div_count=10) from_grid = View.from_grid(grid) assert v.to_radiance() == from_grid.to_radiance() grid = v.grid(x_div_count=10, y_div_count=100) from_grid = View.from_grid(grid) assert v.to_radiance() == from_grid.to_radiance()
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