Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
d7333adb
Commit
d7333adb
authored
2 years ago
by
Damien Picard
Browse files
Options
Downloads
Patches
Plain Diff
Sun Position: cleanup
parent
f5ea6e39
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sun_position/draw.py
+16
-21
16 additions, 21 deletions
sun_position/draw.py
sun_position/sun_calc.py
+26
-44
26 additions, 44 deletions
sun_position/sun_calc.py
with
42 additions
and
65 deletions
sun_position/draw.py
+
16
−
21
View file @
d7333adb
...
@@ -52,11 +52,11 @@ else:
...
@@ -52,11 +52,11 @@ else:
shader
=
gpu
.
types
.
GPUShader
(
vertex_shader
,
fragment_shader
)
shader
=
gpu
.
types
.
GPUShader
(
vertex_shader
,
fragment_shader
)
def
draw_north_callback
():
def
draw_north_callback
():
# ------------------------------------------------------------------
"""
#
Set up the compass needle using the current north offset angle
Set up the compass needle using the current north offset angle
#
less 90 degrees. This forces the unit circle to begin at the
less 90 degrees. This forces the unit circle to begin at the
#
12 O'clock instead of 3 O'clock position.
12 O
'
clock instead of 3 O
'
clock position.
# ------------------------------------------------------------------
"""
sun_props
=
bpy
.
context
.
scene
.
sun_pos_properties
sun_props
=
bpy
.
context
.
scene
.
sun_pos_properties
color
=
(
0.2
,
0.6
,
1.0
,
0.7
)
color
=
(
0.2
,
0.6
,
1.0
,
0.7
)
...
@@ -64,30 +64,25 @@ else:
...
@@ -64,30 +64,25 @@ else:
angle
=
-
(
sun_props
.
north_offset
-
math
.
pi
/
2
)
angle
=
-
(
sun_props
.
north_offset
-
math
.
pi
/
2
)
x
=
math
.
cos
(
angle
)
*
radius
x
=
math
.
cos
(
angle
)
*
radius
y
=
math
.
sin
(
angle
)
*
radius
y
=
math
.
sin
(
angle
)
*
radius
coords
=
Vector
((
x
,
y
,
0
)),
Vector
((
0
,
0
,
0
))
coords
=
Vector
((
x
,
y
,
0
)),
Vector
((
0
,
0
,
0
))
# Start & end of needle
batch
=
batch_for_shader
(
shader
,
'
LINE_STRIP
'
,
{
"
position
"
:
coords
})
batch
=
batch_for_shader
(
shader
,
'
LINE_STRIP
'
,
{
"
position
"
:
coords
},
)
shader
.
bind
()
matrix
=
bpy
.
context
.
region_data
.
perspective_matrix
matrix
=
bpy
.
context
.
region_data
.
perspective_matrix
shader
.
uniform_float
(
"
u_ViewProjectionMatrix
"
,
matrix
)
shader
.
uniform_float
(
"
u_ViewProjectionMatrix
"
,
matrix
)
shader
.
uniform_float
(
"
u_Resolution
"
,
(
bpy
.
context
.
region
.
width
,
bpy
.
context
.
region
.
height
))
shader
.
uniform_float
(
"
u_Resolution
"
,
(
bpy
.
context
.
region
.
width
,
bpy
.
context
.
region
.
height
))
shader
.
uniform_float
(
"
u_Color
"
,
color
)
shader
.
uniform_float
(
"
u_Color
"
,
color
)
gpu
.
state
.
line_width_set
(
2.0
)
gpu
.
state
.
line_width_set
(
2.0
)
batch
.
draw
(
shader
)
batch
.
draw
(
shader
)
_handle
=
None
_north_handle
=
None
def
north_update
(
self
,
context
):
def
north_update
(
self
,
context
):
global
_handle
global
_north
_handle
if
self
.
show_north
and
_handle
is
None
:
if
self
.
show_north
and
_north
_handle
is
None
:
_handle
=
bpy
.
types
.
SpaceView3D
.
draw_handler_add
(
draw_north_callback
,
(),
'
WINDOW
'
,
'
POST_VIEW
'
)
_north
_handle
=
bpy
.
types
.
SpaceView3D
.
draw_handler_add
(
draw_north_callback
,
(),
'
WINDOW
'
,
'
POST_VIEW
'
)
elif
_handle
is
not
None
:
elif
_north
_handle
is
not
None
:
bpy
.
types
.
SpaceView3D
.
draw_handler_remove
(
_handle
,
'
WINDOW
'
)
bpy
.
types
.
SpaceView3D
.
draw_handler_remove
(
_
north_
handle
,
'
WINDOW
'
)
_handle
=
None
_north
_handle
=
None
context
.
area
.
tag_redraw
()
context
.
area
.
tag_redraw
()
This diff is collapsed.
Click to expand it.
sun_position/sun_calc.py
+
26
−
44
View file @
d7333adb
...
@@ -9,14 +9,10 @@ import datetime
...
@@ -9,14 +9,10 @@ import datetime
from
.geo
import
parse_position
from
.geo
import
parse_position
############################################################################
#
# SunClass is used for storing intermediate sun calculations.
#
############################################################################
class
SunClass
:
class
SunClass
:
"""
SunClass is used for storing intermediate sun calculations.
"""
class
TazEl
:
class
TazEl
:
time
=
0.0
time
=
0.0
azimuth
=
0.0
azimuth
=
0.0
...
@@ -81,16 +77,11 @@ def sun_handler(scene):
...
@@ -81,16 +77,11 @@ def sun_handler(scene):
move_sun
(
bpy
.
context
)
move_sun
(
bpy
.
context
)
############################################################################
#
# move_sun() will cycle through all the selected objects
# and call set_sun_position and set_sun_rotations
# to place them in the sky.
#
############################################################################
def
move_sun
(
context
):
def
move_sun
(
context
):
"""
Cycle through all the selected objects and call set_sun_position and
set_sun_rotations to place them in the sky
"""
addon_prefs
=
context
.
preferences
.
addons
[
__package__
].
preferences
addon_prefs
=
context
.
preferences
.
addons
[
__package__
].
preferences
sun_props
=
context
.
scene
.
sun_pos_properties
sun_props
=
context
.
scene
.
sun_pos_properties
...
@@ -265,29 +256,23 @@ def format_lat_long(lat_long, is_latitude):
...
@@ -265,29 +256,23 @@ def format_lat_long(lat_long, is_latitude):
return
hh
+
"
°
"
+
mm
+
"'
"
+
ss
+
'"'
+
coord_tag
return
hh
+
"
°
"
+
mm
+
"'
"
+
ss
+
'"'
+
coord_tag
############################################################################
#
# Calculate the actual position of the sun based on input parameters.
#
# The sun positioning algorithms below are based on the National Oceanic
# and Atmospheric Administration's (NOAA) Solar Position Calculator
# which rely on calculations of Jean Meeus' book "Astronomical Algorithms."
# Use of NOAA data and products are in the public domain and may be used
# freely by the public as outlined in their policies at
# www.nws.noaa.gov/disclaimer.php
#
# The calculations of this script can be verified with those of NOAA's
# using the Azimuth and Solar Elevation displayed in the SunPos_Panel.
# NOAA's web site is:
# http://www.esrl.noaa.gov/gmd/grad/solcalc
############################################################################
def
get_sun_position
(
local_time
,
latitude
,
longitude
,
north_offset
,
def
get_sun_position
(
local_time
,
latitude
,
longitude
,
north_offset
,
utc_zone
,
month
,
day
,
year
,
distance
):
utc_zone
,
month
,
day
,
year
,
distance
):
"""
Calculate the actual position of the sun based on input parameters.
The sun positioning algorithms below are based on the National Oceanic
and Atmospheric Administration
'
s (NOAA) Solar Position Calculator
which rely on calculations of Jean Meeus
'
book
"
Astronomical Algorithms.
"
Use of NOAA data and products are in the public domain and may be used
freely by the public as outlined in their policies at
www.nws.noaa.gov/disclaimer.php
The calculations of this script can be verified with those of NOAA
'
s
using the Azimuth and Solar Elevation displayed in the SunPos_Panel.
NOAA
'
s web site is:
http://www.esrl.noaa.gov/gmd/grad/solcalc
"""
addon_prefs
=
bpy
.
context
.
preferences
.
addons
[
__package__
].
preferences
addon_prefs
=
bpy
.
context
.
preferences
.
addons
[
__package__
].
preferences
sun_props
=
bpy
.
context
.
scene
.
sun_pos_properties
sun_props
=
bpy
.
context
.
scene
.
sun_pos_properties
...
@@ -381,9 +366,7 @@ def set_sun_position(obj, distance):
...
@@ -381,9 +366,7 @@ def set_sun_position(obj, distance):
locY
=
math
.
sin
(
sun
.
theta
)
*
math
.
cos
(
sun
.
phi
)
*
distance
locY
=
math
.
sin
(
sun
.
theta
)
*
math
.
cos
(
sun
.
phi
)
*
distance
locZ
=
math
.
cos
(
sun
.
theta
)
*
distance
locZ
=
math
.
cos
(
sun
.
theta
)
*
distance
#----------------------------------------------
# Update selected object in viewport
# Update selected object in viewport
#----------------------------------------------
obj
.
location
=
locX
,
locY
,
locZ
obj
.
location
=
locX
,
locY
,
locZ
...
@@ -475,13 +458,12 @@ def calc_sunrise_sunset(rise):
...
@@ -475,13 +458,12 @@ def calc_sunrise_sunset(rise):
sun
.
sunset
.
azimuth
=
sun
.
azimuth
sun
.
sunset
.
azimuth
=
sun
.
azimuth
sun
.
sunset
.
elevation
=
sun
.
elevation
sun
.
sunset
.
elevation
=
sun
.
elevation
##########################################################################
## Get the elapsed julian time since 1/1/2000 12:00 gmt
## Y2k epoch (1/1/2000 12:00 gmt) is Julian day 2451545.0
##########################################################################
def
julian_time_from_y2k
(
utc_time
,
year
,
month
,
day
):
def
julian_time_from_y2k
(
utc_time
,
year
,
month
,
day
):
"""
Get the elapsed julian time since 1/1/2000 12:00 gmt
Y2k epoch (1/1/2000 12:00 gmt) is Julian day 2451545.0
"""
century
=
36525.0
# Days in Julian Century
century
=
36525.0
# Days in Julian Century
epoch
=
2451545.0
# Julian Day for 1/1/2000 12:00 gmt
epoch
=
2451545.0
# Julian Day for 1/1/2000 12:00 gmt
jd
=
get_julian_day
(
year
,
month
,
day
)
jd
=
get_julian_day
(
year
,
month
,
day
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment