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
)
8 from .sun_calc
import format_lat_long
, parse_coordinates
, sun
, update_time
, move_sun
9 from .draw
import north_update
, surface_update
, analemmas_update
12 from datetime
import datetime
13 TODAY
= datetime
.today()
15 ############################################################################
16 # Sun panel properties
17 ############################################################################
19 def sun_update(self
, context
):
20 sun_props
= context
.scene
.sun_pos_properties
25 if sun_props
.show_surface
:
26 surface_update(self
, context
)
27 if sun_props
.show_analemmas
:
28 analemmas_update(self
, context
)
29 if sun_props
.show_north
:
30 north_update(self
, context
)
33 class SunPosProperties(PropertyGroup
):
34 usage_mode
: EnumProperty(
36 description
="Operate in normal mode or environment texture mode",
38 ('NORMAL', "Normal", ""),
39 ('HDR', "Sun + HDR texture", ""),
44 use_daylight_savings
: BoolProperty(
45 name
="Daylight Savings",
46 description
="Daylight savings time adds 1 hour to standard time",
50 use_refraction
: BoolProperty(
51 name
="Use Refraction",
52 description
="Show the apparent Sun position due to atmospheric refraction",
56 show_north
: BoolProperty(
58 description
="Draw a line pointing to the north",
62 north_offset
: FloatProperty(
64 description
="Rotate the scene to choose the North direction",
66 soft_min
=-pi
, soft_max
=pi
, step
=10.0, default
=0.0,
69 show_surface
: BoolProperty(
71 description
="Draw the surface that the Sun occupies in the sky",
73 update
=surface_update
)
75 show_analemmas
: BoolProperty(
76 name
="Show Analemmas",
77 description
="Draw Sun analemmas. These help visualize the motion of the Sun in the sky during the year, for each hour of the day",
79 update
=analemmas_update
)
81 latitude
: FloatProperty(
83 description
="Latitude: (+) Northern (-) Southern",
84 soft_min
=-90.0, soft_max
=90.0,
89 longitude
: FloatProperty(
91 description
="Longitude: (-) West of Greenwich (+) East of Greenwich",
92 soft_min
=-180.0, soft_max
=180.0,
97 sunrise_time
: FloatProperty(
99 description
="Time at which the Sun rises",
100 soft_min
=0.0, soft_max
=24.0,
102 get
=lambda _
: sun
.sunrise
)
104 sunset_time
: FloatProperty(
106 description
="Time at which the Sun sets",
107 soft_min
=0.0, soft_max
=24.0,
109 get
=lambda _
: sun
.sunset
)
111 sun_azimuth
: FloatProperty(
113 description
="Rotation angle of the Sun from the direction of the north",
114 soft_min
=-pi
, soft_max
=pi
,
116 get
=lambda _
: sun
.azimuth
)
118 sun_elevation
: FloatProperty(
119 name
="Sun Elevation",
120 description
="Elevation angle of the Sun",
121 soft_min
=-pi
/2, soft_max
=pi
/2,
123 get
=lambda _
: sun
.elevation
)
125 co_parser
: StringProperty(
126 name
="Enter Coordinates",
127 description
="Enter coordinates from an online map",
128 update
=parse_coordinates
)
132 min=1, max=12, default
=TODAY
.month
,
137 min=1, max=31, default
=TODAY
.day
,
142 min=1, max=4000, default
=TODAY
.year
,
145 use_day_of_year
: BoolProperty(
146 description
="Use a single value for the day of year",
147 name
="Use day of year",
151 day_of_year
: IntProperty(
153 min=1, max=366, default
=1,
156 UTC_zone
: FloatProperty(
158 description
="Difference from Greenwich, England, in hours",
160 min=-14.0, max=13, step
=50, default
=0.0,
165 description
="Time of the day",
167 soft_min
=0.0, soft_max
=23.9999, step
=1.0, default
=12.0,
170 sun_distance
: FloatProperty(
172 description
="Distance to the Sun from the origin",
174 min=0.0, soft_max
=3000.0, step
=10.0, default
=50.0,
177 sun_object
: PointerProperty(
179 type=bpy
.types
.Object
,
180 description
="Sun object to use in the scene",
181 poll
=lambda self
, obj
: obj
.type == 'LIGHT',
184 object_collection
: PointerProperty(
186 type=bpy
.types
.Collection
,
187 description
="Collection of objects used to visualize the motion of the Sun",
190 object_collection_type
: EnumProperty(
192 description
="Type of Sun motion to visualize.",
194 ('ANALEMMA', "Analemma", "Trajectory of the Sun in the sky during the year, for a given time of the day"),
195 ('DIURNAL', "Diurnal", "Trajectory of the Sun in the sky during a single day"),
200 sky_texture
: StringProperty(
203 description
="Name of the sky texture to use",
206 hdr_texture
: StringProperty(
207 default
="Environment Texture",
208 name
="Environment Texture",
209 description
="Name of the environment texture to use. World nodes must be enabled "
210 "and the color set to an environment Texture",
213 hdr_azimuth
: FloatProperty(
215 description
="Rotation angle of the Sun and environment texture",
218 default
=0.0, precision
=3,
221 hdr_elevation
: FloatProperty(
223 description
="Elevation angle of the Sun",
226 default
=0.0, precision
=3,
229 bind_to_sun
: BoolProperty(
230 name
="Bind Texture to Sun",
231 description
="If enabled, the environment texture moves with the Sun",
235 time_spread
: FloatProperty(
237 description
="Time period around which to spread object collection",
239 soft_min
=1.0, soft_max
=24.0, step
=1.0, default
=23.0,
242 ############################################################################
243 # Preference panel properties
244 ############################################################################
247 class SunPosAddonPreferences(AddonPreferences
):
248 bl_idname
= __package__
250 show_time_place
: BoolProperty(
251 name
="Time and Place Presets",
252 description
="Show time and place presets",
255 show_dms
: BoolProperty(
257 description
="Show degrees, minutes, seconds labels for the latitude and longitude",
260 show_overlays
: BoolProperty(
261 name
="Show Overlays",
262 description
="Display overlays in the viewport: the direction of the north, analemmas and the Sun surface",
266 show_refraction
: BoolProperty(
268 description
="Show Sun Refraction choice",
272 show_az_el
: BoolProperty(
273 name
="Azimuth and Elevation Info",
274 description
="Show azimuth and solar elevation info",
277 show_daylight_savings
: BoolProperty(
278 name
="Daylight Savings",
279 description
="Show daylight savings time choice",
283 show_rise_set
: BoolProperty(
284 name
="Sunrise and Sunset Info",
285 description
="Show sunrise and sunset labels",
288 def draw(self
, context
):
294 col
.label(text
="Show options or labels:")
295 flow
= col
.grid_flow(columns
=0, even_columns
=True, even_rows
=False, align
=False)
296 flow
.prop(self
, "show_time_place")
297 flow
.prop(self
, "show_dms")
298 flow
.prop(self
, "show_refraction")
299 flow
.prop(self
, "show_overlays")
300 flow
.prop(self
, "show_az_el")
301 flow
.prop(self
, "show_daylight_savings")
302 flow
.prop(self
, "show_rise_set")