Commit 78d03799 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Use 16 colors in 3D model representations

parent 874df81c
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -1011,14 +1011,30 @@ def write_obj(scatterer, geometry, max_rad):
    out_dir = scatterer['out_file'].absolute().parent
    out_model_path = Path(str(geometry['out_file']) + ".obj")
    out_material_path = Path(str(geometry['out_file']) + ".mtl")
    # The following color scale is obtained from the normalized
    # RGB values of colors divided by 2.
    color_strings = [
        "0.5 0.5 0.5\n", # white
        "0.3 0.0 0.0\n", # red
        "0.0 0.0 0.3\n", # blue
        "0.0 0.3 0.0\n", # green
        "0.50 0.50 0.50\n", # white
        "0.30 0.00 0.00\n", # red
        "0.00 0.00 0.30\n", # blue
        "0.00 0.30 0.00\n", # green
        "0.35 0.35 0.00\n", # yellow
        "0.21 0.03 0.34\n", # purple
        "0.00 0.49 0.49\n", # cyan
        "0.27 0.16 0.08\n", # brown
        "0.19 0.21 0.09\n", # olive
        "0.50 0.00 0.50\n", # magenta
        "0.16 0.38 0.37\n", # turquoise
        "0.25 0.25 0.25\n", # gray
        "0.50 0.36 0.38\n", # pink
        "0.50 0.32 0.00\n", # orange
        "0.48 0.45 0.34\n", # vanilla
        "0.16 0.39 0.24\n", # emerald
    ]
    color_names = [
        "white", "red", "blue", "green"
        "white", "red", "blue", "green", "yellow", "purple", "cyan", "brown",
        "olive", "magenta", "turquoise", "gray", "pink", "orange", "vanilla",
        "emerald"
    ]
    mtl_file = open(str(out_material_path), "w")
    for mi in range(len(color_strings)):
@@ -1062,8 +1078,8 @@ def write_obj(scatterer, geometry, max_rad):
                str_line = tmp_model_file.readline()
            else:
                old_sph_type_index = sph_type_index
                color_index = sph_type_index % (len(color_names) - 1)
                str_line = "g grp{0:04d}\n".format(sph_type_index)
                color_index = 1 + (sph_type_index - 1) % (len(color_names) - 1)
                str_line = "g grp{0:04d}\n".format(sph_type_index - 1)
                out_model_file.write(str_line)
                str_line = tmp_model_file.readline()
                str_line = "usemtl {0:s}\n".format(color_names[color_index])