|
28 | 28 |
|
29 | 29 | from math import degrees, radians
|
30 | 30 |
|
| 31 | +columm_rot = 14.65 |
| 32 | +column_elements = 26 |
| 33 | +row_rot = 12.5 |
| 34 | +row_elements = 8 |
| 35 | + |
31 | 36 | def interpolate_color(color_a, color_b, steps):
|
32 | 37 | color_list = []
|
33 | 38 | rdelta, gdelta, bdelta = (color_b[0]-color_a[0])/steps, (color_b[1]-color_a[1])/steps, (color_b[2]-color_a[2])/steps
|
34 |
| - r1 = color_a[0] |
35 |
| - g1 = color_a[1] |
36 |
| - b1 = color_a[2] |
| 39 | + r1, g1, b1 = color_a[0], color_a[1], color_a[2] |
37 | 40 | color_list.append(color_a)
|
38 | 41 | for step in range(steps):
|
39 | 42 | r1 += rdelta
|
40 | 43 | g1 += gdelta
|
41 | 44 | b1 += bdelta
|
42 | 45 | color_list.append((r1, g1, b1))
|
| 46 | + |
43 | 47 | color_list.append(color_b)
|
| 48 | + |
44 | 49 | return color_list
|
45 | 50 |
|
46 |
| -def generate_hemisphere(zenith_color, horizon_color, strength): |
| 51 | +def get_center_point(rotation, is_x_axis): |
| 52 | + light_spacing = row_rot |
| 53 | + if is_x_axis: |
| 54 | + light_spacing = columm_rot |
| 55 | + |
| 56 | + sun_id = round(rotation / light_spacing) |
| 57 | + |
| 58 | + return sun_id |
| 59 | + |
| 60 | +def get_percentages(rotation, is_x_axis, color_loops): |
| 61 | + |
| 62 | + light_spacing = row_rot |
| 63 | + max_elements = row_elements |
| 64 | + if is_x_axis: |
| 65 | + light_spacing = columm_rot |
| 66 | + max_elements = column_elements |
| 67 | + |
| 68 | + percentage_list = [] |
| 69 | + postitive_space_list = [] |
| 70 | + negative_space_list = [] |
| 71 | + sun_id = round(rotation / light_spacing) |
| 72 | + postive_space = max_elements - sun_id + 1 |
| 73 | + |
| 74 | + if color_loops: |
| 75 | + halved_elements = round(max_elements / 2) |
| 76 | + for idx in range(halved_elements): |
| 77 | + percentage = 1 / halved_elements |
| 78 | + if idx > 0: |
| 79 | + percentage = percentage * (idx + 1) |
| 80 | + |
| 81 | + if idx == halved_elements - 1: |
| 82 | + percentage = 1.0 |
| 83 | + |
| 84 | + negative_space_list.append(percentage) |
| 85 | + postitive_space_list.append(percentage) |
| 86 | + |
| 87 | + postitive_space_list.reverse() |
| 88 | + |
| 89 | + starting_point_list = [] |
| 90 | + if sun_id > halved_elements: |
| 91 | + |
| 92 | + starting_point_list_reversed = [] |
| 93 | + for idx in range(sun_id - halved_elements): |
| 94 | + starting_point_list_reversed.append(negative_space_list[idx]) |
| 95 | + |
| 96 | + starting_point_list_reversed.reverse() |
| 97 | + starting_point_list = starting_point_list_reversed |
| 98 | + |
| 99 | + for idx in range(sun_id - halved_elements): |
| 100 | + starting_point_list.append(negative_space_list[idx]) |
| 101 | + |
| 102 | + middle_point_list_reversed = [] |
| 103 | + for idx in range(max_elements - sun_id): |
| 104 | + middle_point_list_reversed.append(postitive_space_list[idx]) |
| 105 | + |
| 106 | + middle_point_list_reversed.reverse() |
| 107 | + starting_point_list = starting_point_list + middle_point_list_reversed |
| 108 | + |
| 109 | + for idx in range(max_elements - sun_id): |
| 110 | + starting_point_list.append(postitive_space_list[idx]) |
| 111 | + |
| 112 | + else: |
| 113 | + for idx in range(sun_id): |
| 114 | + starting_point_list.append(negative_space_list[(idx + 1 ) * -1]) |
| 115 | + |
| 116 | + starting_point_list.reverse() |
| 117 | + |
| 118 | + for idx in range(halved_elements): |
| 119 | + starting_point_list.append(postitive_space_list[idx]) |
| 120 | + |
| 121 | + for idx in range(max_elements - (halved_elements + sun_id)): |
| 122 | + starting_point_list.append(negative_space_list[idx]) |
| 123 | + |
| 124 | + percentage_list = starting_point_list |
| 125 | + |
| 126 | + else: |
| 127 | + for idx in range(sun_id): |
| 128 | + percentage = 1 / sun_id |
| 129 | + if idx > 0: |
| 130 | + percentage = percentage * (idx + 1) |
| 131 | + |
| 132 | + if idx == sun_id - 1: |
| 133 | + percentage = 1.0 |
| 134 | + |
| 135 | + negative_space_list.append(percentage) |
| 136 | + |
| 137 | + for idx in range(postive_space): |
| 138 | + percentage = 1 / postive_space |
| 139 | + if idx > 0: |
| 140 | + percentage = percentage * (idx + 1) |
| 141 | + |
| 142 | + if not percentage == 1.0: |
| 143 | + postitive_space_list.append(percentage) |
| 144 | + |
| 145 | + postitive_space_list.reverse() |
| 146 | + percentage_list = negative_space_list + postitive_space_list |
| 147 | + |
| 148 | + return percentage_list |
| 149 | + |
| 150 | +def darken_color(color, light_x_idx, light_y_idx, percentage_list_y, percentage_list_x): |
| 151 | + percentage_y = percentage_list_y[light_y_idx] |
| 152 | + percentage_x = percentage_list_x[light_x_idx] |
| 153 | + color_r, color_g, color_b = (color[0], color[1], color[2]) |
| 154 | + color_r_y, color_g_y, color_b_y = (color_r * percentage_y), (color_g * percentage_y), (color_b * percentage_y) |
| 155 | + color_r_xy, color_g_xy, color_b_xy = ((color_r_y * percentage_x), (color_g_y * percentage_x), (color_b_y * percentage_x)) |
| 156 | + return (color_r_xy, color_g_xy, color_b_xy) |
| 157 | + |
| 158 | +def generate_hemisphere(zenith_color, horizon_color, strength, sun_yaw, sun_pitch): |
| 159 | + percentage_list_y = get_percentages(sun_yaw, False, False) |
| 160 | + percentage_list_x = get_percentages(sun_pitch, True, True) |
| 161 | + |
| 162 | + sun_row_id = get_center_point(sun_yaw, False) |
| 163 | + sun_column_id = get_center_point(sun_pitch, True) |
| 164 | + |
47 | 165 | color_list = interpolate_color(zenith_color, horizon_color, 6)
|
48 |
| - object_list = [] |
49 |
| - for light_row in range(26): |
50 |
| - for light in range(8): |
51 |
| - rot_tuple = (radians(90 + (12.5 * light)), 0, radians(18 * light_row)) |
52 |
| - name = 'skylight_%s' % (light + (8 * light_row)) |
| 166 | + |
| 167 | + for light_column in range(column_elements): |
| 168 | + for light_row in range(row_elements): |
| 169 | + rot_tuple = (radians(90 + (row_rot * light_row)), 0, radians(columm_rot * light_column)) |
| 170 | + name = 'skylight_%s' % (light_row + (8 * light_column)) |
| 171 | + |
53 | 172 | light_data = bpy.data.lights.new(name, "SUN")
|
54 | 173 | object_mesh = bpy.data.objects.new(name, light_data)
|
55 | 174 | bpy.context.collection.objects.link(object_mesh)
|
56 |
| - object_mesh.data.color = color_list[light] |
57 |
| - object_mesh.data.energy = strength |
| 175 | + |
58 | 176 | object_mesh.rotation_euler = rot_tuple
|
| 177 | + if light_column == sun_column_id and light_row == sun_row_id: |
| 178 | + print("%s is the sun point. Beat the shit out of him!!!" % name) |
| 179 | + object_mesh.data.energy = 0.000047 |
| 180 | + object_mesh.data.color = (1.0, 1.0, 1.0) |
| 181 | + |
| 182 | + else: |
| 183 | + object_mesh.data.energy = strength |
| 184 | + object_mesh.data.color = darken_color(color_list[light_row], light_column, light_row, percentage_list_y, percentage_list_x) |
59 | 185 |
|
60 | 186 | return {'FINISHED'}
|
61 | 187 |
|
|
0 commit comments