Skip to content

Add sun positioning algorithm. #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 83 additions & 10 deletions properties/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import bpy

from ..utils import util

from datetime import datetime
from ..translators.world import update_sun_pos

class AppleseedSSSSetsProps(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(name="SSS Set Name",
Expand All @@ -46,21 +47,93 @@ class AppleseedSSSSets(bpy.types.PropertyGroup):


class AppleseedSkySettings(bpy.types.PropertyGroup):
env_type: bpy.props.EnumProperty(name="Environment Type",
items=[("constant", "Constant", "Use constant color for sky", "", 1),
env_type: bpy.props.EnumProperty(name="Environment Type",
items=[("constant", "Constant", "Use constant color for sky", "", 1),
("gradient", "Gradient", "Use sky color gradient", "", 2),
("latlong_map", "HDRI Environment", "Use HDRI map texture", "", 3),
("mirrorball_map", "Mirror Ball", "Use mirror ball texture", "", 4),
("none", "None", "", "", 7),
("sunsky", "Physical Sky", "", "", 5),
("constant_hemisphere", "Per-Hemisphere Constant", "Use constant color per hemisphere", "", 6)],
description="Select environment type",
default="none")

sun_model: bpy.props.EnumProperty(name="Sky Model",
items=[('hosek', "Hosek-Wilkie", "Hosek-Wilkie physical sun/sky model")],
description="Physical sun/sky model",
default='hosek')
description="Select environment type",
default="none")

sun_model: bpy.props.EnumProperty(name="Sky Model",
items=[('hosek', "Hosek-Wilkie", "Hosek-Wilkie physical sun/sky model")],
description="Physical sun/sky model",
default='hosek')

sun_pos_sys: bpy.props.EnumProperty(name="Sun Positioning System",
items=[("analytical", "Analytical", "Set value of Elevation and Azimuth directly"),
("Sun Positioner", "Time and Location", "Calcule Elevation and Azimuth using Date, time and location")],
description="Sun Positioning System",
default="analytical",
update=update_sun_pos)

hour: bpy.props.IntProperty(name="hour",
min=0,
max=24,
default=12,
update=update_sun_pos)

minute: bpy.props.IntProperty(name="minute",
min=0,
max=59,
default=0,
update=update_sun_pos)

second: bpy.props.IntProperty(name="second",
min=0,
max=59,
default=0,
update=update_sun_pos)

month: bpy.props.IntProperty(name="Month",
min=1,
max=12,
default=datetime.today().month,
update=update_sun_pos)

day: bpy.props.IntProperty(name="Day",
min=1,
max=31,
default=datetime.today().day,
update=update_sun_pos)

year: bpy.props.IntProperty(name="Year",
min=-2000,
max=4000,
default=datetime.today().year,
update=update_sun_pos)

timezone: bpy.props.IntProperty(name="timezone",
min= -18,
max= 18,
default=0,
update=update_sun_pos)


north: bpy.props.FloatProperty(name="North",
description="Rotate the North direction",
soft_min=-180,
soft_max=180,
step= 5.0,
default=0.0,
unit="ROTATION")

latitude: bpy.props.FloatProperty(name="Latitude",
min=-90,
max=90,
step=5.0,
default=0.0,
update=update_sun_pos)

longitude: bpy.props.FloatProperty(name="Longitude",
min=-180,
max=180,
step=5.0,
default=0.0,
update=update_sun_pos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the above parameters I would add in some kind of appleseed prefix, such as 'as_' in order to avoid potential conflict with another addon. Such things have happened in the past.


sun_theta: bpy.props.FloatProperty(name="sun_theta",
description="Sun polar (vertical) angle in degrees",
Expand Down
18 changes: 17 additions & 1 deletion translators/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

logger = get_logger()


class WorldTranslator(Translator):
"""
This class translates a Blender world block into an appleseed environment
Expand Down Expand Up @@ -231,3 +230,20 @@ def __create_params(self):

return params

def update_sun_pos(self, context):
as_world = context.world.appleseed_sky
params = dict()
params = {'hour': as_world.hour,
'minute': as_world.minute,
'second': as_world.second,
'month': as_world.month,
'day': as_world.day,
'year' : as_world.day,
'timezone' : as_world.timezone,
'north' : as_world.north,
'latitude': as_world.latitude,
'longitude': as_world.longitude}
sun_positioner = asr.SunPositioner(params)
sun_positioner.compute_sun_position()
context.world.appleseed_sky.sun_theta = sun_positioner.get_zenith()
context.world.appleseed_sky.sun_phi = sun_positioner.get_azimuth()
25 changes: 23 additions & 2 deletions ui/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,35 @@ def draw(self, context):

if asr_sky_props.env_type == "sunsky":
layout.prop(asr_sky_props, "sun_model", text="Sky Model")
layout.prop(asr_sky_props, "sun_theta", text="Sun Theta Angle")
layout.prop(asr_sky_props, "sun_phi", text="Sun Phi Angle")
layout.prop(asr_sky_props, "turbidity", text="Turbidity")
layout.prop(asr_sky_props, "turbidity_multiplier", text="Turbidity Multiplier")
layout.prop(asr_sky_props, "luminance_multiplier", text="Luminance Multiplier")
layout.prop(asr_sky_props, "luminance_gamma", text="Luminance Gamma")
layout.prop(asr_sky_props, "saturation_multiplier", text="Saturation Multiplier")
layout.prop(asr_sky_props, "horizon_shift", text="Horizon Shift")
layout.prop(asr_sky_props, "sun_pos_sys", text="Sun Positioning System", expand=True)

if asr_sky_props.sun_pos_sys == "analytical":
layout.prop(asr_sky_props, "sun_theta", text="Sun Theta Angle")
layout.prop(asr_sky_props, "sun_phi", text="Sun Phi Angle")
else:
#flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
col = layout.column(align=True)
col.prop(asr_sky_props, "hour", text="Hour")
col.prop(asr_sky_props, "minute", text="Minute")
col.prop(asr_sky_props, "second", text="Second")
col.prop(asr_sky_props, "timezone", text="Timezone")

col = layout.column(align=True)
col.prop(asr_sky_props, "month", text="Month")
col.prop(asr_sky_props, "day", text="Day")
col.prop(asr_sky_props, "year", text="Year")

layout.prop(asr_sky_props, "north", text="North")

col = layout.column(align=True)
col.prop(asr_sky_props, "latitude", text="Latitude")
col.prop(asr_sky_props, "longitude", text="Longitude")

if asr_sky_props.sun_model == "hosek_environment_edf":
layout.prop(asr_sky_props, "ground_albedo", text="Ground Albedo")
Expand Down