1 # SPDX-License-Identifier: GPL-2.0-or-later
4 from bpy
.types
import AddonPreferences
, PropertyGroup
5 from bpy
.props
import (StringProperty
, EnumProperty
, IntProperty
,
6 FloatProperty
, BoolProperty
, PointerProperty
)
7 from bpy
.app
.translations
import pgettext_iface
as iface_
10 from .sun_calc
import format_lat_long
, parse_position
, sun
, update_time
, move_sun
11 from .draw
import north_update
, surface_update
, analemmas_update
14 from datetime
import datetime
15 TODAY
= datetime
.today()
17 ############################################################################
18 # Sun panel properties
19 ############################################################################
24 def lat_long_update(self
, context
):
27 sun_update(self
, context
)
30 def get_coordinates(self
):
32 return format_lat_long(self
.latitude
, self
.longitude
)
33 return iface_("ERROR: Could not parse coordinates")
36 def set_coordinates(self
, value
):
37 parsed_co
= parse_position(value
)
40 if parsed_co
is not None and len(parsed_co
) == 2:
41 latitude
, longitude
= parsed_co
42 self
.latitude
, self
.longitude
= latitude
, longitude
46 sun_update(self
, bpy
.context
)
49 def sun_update(self
, context
):
50 sun_props
= context
.scene
.sun_pos_properties
55 if sun_props
.show_surface
:
56 surface_update(self
, context
)
57 if sun_props
.show_analemmas
:
58 analemmas_update(self
, context
)
59 if sun_props
.show_north
:
60 north_update(self
, context
)
63 class SunPosProperties(PropertyGroup
):
64 usage_mode
: EnumProperty(
66 description
="Operate in normal mode or environment texture mode",
68 ('NORMAL', "Normal", ""),
69 ('HDR', "Sun + HDR texture", ""),
74 use_daylight_savings
: BoolProperty(
75 name
="Daylight Savings",
76 description
="Daylight savings time adds 1 hour to standard time",
80 use_refraction
: BoolProperty(
81 name
="Use Refraction",
82 description
="Show the apparent Sun position due to atmospheric refraction",
86 show_north
: BoolProperty(
88 description
="Draw a line pointing to the north",
92 north_offset
: FloatProperty(
94 description
="Rotate the scene to choose the North direction",
96 soft_min
=-pi
, soft_max
=pi
, step
=10.0, default
=0.0,
99 show_surface
: BoolProperty(
101 description
="Draw the surface that the Sun occupies in the sky",
103 update
=surface_update
)
105 show_analemmas
: BoolProperty(
106 name
="Show Analemmas",
107 description
="Draw Sun analemmas. These help visualize the motion of the Sun in the sky during the year, for each hour of the day",
109 update
=analemmas_update
)
111 coordinates
: StringProperty(
113 description
="Enter coordinates from an online map",
116 options
={'SKIP_SAVE'})
118 latitude
: FloatProperty(
120 description
="Latitude: (+) Northern (-) Southern",
121 soft_min
=-90.0, soft_max
=90.0,
124 update
=lat_long_update
)
126 longitude
: FloatProperty(
128 description
="Longitude: (-) West of Greenwich (+) East of Greenwich",
129 soft_min
=-180.0, soft_max
=180.0,
132 update
=lat_long_update
)
134 sunrise_time
: FloatProperty(
136 description
="Time at which the Sun rises",
137 soft_min
=0.0, soft_max
=24.0,
139 get
=lambda _
: sun
.sunrise
)
141 sunset_time
: FloatProperty(
143 description
="Time at which the Sun sets",
144 soft_min
=0.0, soft_max
=24.0,
146 get
=lambda _
: sun
.sunset
)
148 sun_azimuth
: FloatProperty(
150 description
="Rotation angle of the Sun from the direction of the north",
151 soft_min
=-pi
, soft_max
=pi
,
153 get
=lambda _
: sun
.azimuth
)
155 sun_elevation
: FloatProperty(
156 name
="Sun Elevation",
157 description
="Elevation angle of the Sun",
158 soft_min
=-pi
/2, soft_max
=pi
/2,
160 get
=lambda _
: sun
.elevation
)
164 min=1, max=12, default
=TODAY
.month
,
169 min=1, max=31, default
=TODAY
.day
,
174 min=1, max=4000, default
=TODAY
.year
,
177 use_day_of_year
: BoolProperty(
178 description
="Use a single value for the day of year",
179 name
="Use day of year",
183 day_of_year
: IntProperty(
185 min=1, max=366, default
=1,
188 UTC_zone
: FloatProperty(
190 description
="Difference from Greenwich, England, in hours",
192 min=-14.0, max=13, step
=50, default
=0.0,
197 description
="Time of the day",
199 soft_min
=0.0, soft_max
=23.9999, step
=1.0, default
=12.0,
202 sun_distance
: FloatProperty(
204 description
="Distance to the Sun from the origin",
206 min=0.0, soft_max
=3000.0, step
=10.0, default
=50.0,
209 sun_object
: PointerProperty(
211 type=bpy
.types
.Object
,
212 description
="Sun object to use in the scene",
213 poll
=lambda self
, obj
: obj
.type == 'LIGHT',
216 object_collection
: PointerProperty(
218 type=bpy
.types
.Collection
,
219 description
="Collection of objects used to visualize the motion of the Sun",
222 object_collection_type
: EnumProperty(
224 description
="Type of Sun motion to visualize.",
226 ('ANALEMMA', "Analemma", "Trajectory of the Sun in the sky during the year, for a given time of the day"),
227 ('DIURNAL', "Diurnal", "Trajectory of the Sun in the sky during a single day"),
232 sky_texture
: StringProperty(
235 description
="Name of the sky texture to use",
238 hdr_texture
: StringProperty(
239 default
="Environment Texture",
240 name
="Environment Texture",
241 description
="Name of the environment texture to use. World nodes must be enabled "
242 "and the color set to an environment Texture",
245 hdr_azimuth
: FloatProperty(
247 description
="Rotation angle of the Sun and environment texture",
250 default
=0.0, precision
=3,
253 hdr_elevation
: FloatProperty(
255 description
="Elevation angle of the Sun",
258 default
=0.0, precision
=3,
261 bind_to_sun
: BoolProperty(
262 name
="Bind Texture to Sun",
263 description
="If enabled, the environment texture moves with the Sun",
267 time_spread
: FloatProperty(
269 description
="Time period around which to spread object collection",
271 soft_min
=1.0, soft_max
=24.0, step
=1.0, default
=23.0,
274 ############################################################################
275 # Preference panel properties
276 ############################################################################
279 class SunPosAddonPreferences(AddonPreferences
):
280 bl_idname
= __package__
282 show_time_place
: BoolProperty(
283 name
="Time and Place Presets",
284 description
="Show time and place presets",
287 show_overlays
: BoolProperty(
288 name
="Show Overlays",
289 description
="Display overlays in the viewport: the direction of the north, analemmas and the Sun surface",
293 show_refraction
: BoolProperty(
295 description
="Show Sun Refraction choice",
298 show_az_el
: BoolProperty(
299 name
="Azimuth and Elevation Info",
300 description
="Show azimuth and solar elevation info",
303 show_daylight_savings
: BoolProperty(
304 name
="Daylight Savings",
305 description
="Show daylight savings time choice",
308 show_rise_set
: BoolProperty(
309 name
="Sunrise and Sunset Info",
310 description
="Show sunrise and sunset labels",
313 def draw(self
, context
):
319 col
.label(text
="Show options or labels:")
320 flow
= col
.grid_flow(columns
=0, even_columns
=True, even_rows
=False, align
=False)
321 flow
.prop(self
, "show_time_place")
322 flow
.prop(self
, "show_refraction")
323 flow
.prop(self
, "show_overlays")
324 flow
.prop(self
, "show_az_el")
325 flow
.prop(self
, "show_daylight_savings")
326 flow
.prop(self
, "show_rise_set")