Skip to content

Commit

Permalink
Closes #553! Turns out the only thing we really wanted here was the c…
Browse files Browse the repository at this point in the history
…alculated values for WIDTH. The rest was redundant. Also some changes to the default names and precision in xplane_props
  • Loading branch information
tngreene committed Jun 19, 2020
1 parent 2a10b43 commit bac7edb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion io_xplane2blender/xplane_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# The current data model version, incrementing every time xplane_constants, xplane_props, or xplane_updater
# changes. Builds earlier than 3.4.0-beta.5 have and a version of 0.
# When merging, take the higher data model version of the two branches and add one
CURRENT_DATA_MODEL_VERSION = 85
CURRENT_DATA_MODEL_VERSION = 86

# The build number, hardcoded by the build script when there is one, otherwise it is xplane_constants.BUILD_NUMBER_NONE
CURRENT_BUILD_NUMBER = xplane_constants.BUILD_NUMBER_NONE
Expand Down
11 changes: 6 additions & 5 deletions io_xplane2blender/xplane_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,29 +1706,30 @@ class XPlaneLightSettings(bpy.types.PropertyGroup):
)

param_freq: bpy.props.FloatProperty(
name = "Frequency",
name = "Flash Frequency",
description = "The number of light flashes per second",
min = 0.0,
)

param_index: bpy.props.IntProperty(
name = "Index",
name = "Dataref Index",
description = "Index in light's associated array dataref",
min = 0,
max = 127
)

param_phase: bpy.props.FloatProperty(
name = "Phase",
name = "Phase Offset",
description = "Phase offset in seconds of light (so it can make flashing lights that don't flash at the same time)",
min = 0.0,
)

param_size: bpy.props.FloatProperty(
name = 'Size',
name = "Size",
description = "Spill size uses meters; billboard size uses arbitrary scales - bigger is brighter",
default = 1.0,
min = LIGHT_PARAM_SIZE_MIN
min = LIGHT_PARAM_SIZE_MIN,
precision = 3
)

rgb_override_values: bpy.props.FloatVectorProperty(
Expand Down
16 changes: 8 additions & 8 deletions io_xplane2blender/xplane_types/xplane_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ def width_param_new_value()->float:
if light_data.type == "POINT":
return 1
elif "BILLBOARD" in parsed_light.best_overload().overload_type:
return XPlaneLight._WIDTH_for_billboard(light_data.spot_size)
return XPlaneLight.WIDTH_for_billboard(light_data.spot_size)
elif "SPILL" in parsed_light.best_overload().overload_type:
# cos(half the cone angle)
return XPlaneLight._WIDTH_for_spill(light_data.spot_size)
return XPlaneLight.WIDTH_for_spill(light_data.spot_size)

def new_dxyz_vec_x()->Vector:
"""
Expand All @@ -232,7 +232,7 @@ def new_dxyz_vec_x()->Vector:
return Vector((0, 0, 0))
elif "BILLBOARD" in parsed_light.best_overload().overload_type:
# Works for DIR_MAG as well, but we'll probably never have a case for that
scale = 1 - XPlaneLight._WIDTH_for_billboard(light_data.spot_size)
scale = 1 - XPlaneLight.WIDTH_for_billboard(light_data.spot_size)
dir_vec_b_norm = self.get_light_direction_b()
scaled_vec_b = dir_vec_b_norm * scale
return vec_b_to_x(scaled_vec_b)
Expand Down Expand Up @@ -261,7 +261,7 @@ def convert_table(param:str)->float:
}

if light_data.type == "SPOT":
table["DIR_MAG"] = XPlaneLight._DIR_MAG_for_billboard(light_data.spot_size)
table["DIR_MAG"] = XPlaneLight.DIR_MAG_for_billboard(light_data.spot_size)
elif light_data.type == "POINT":
table["DIR_MAG"] = 0
return table[param]
Expand Down Expand Up @@ -490,15 +490,15 @@ def get_light_direction_b(self)->Vector:
return dir_vec_b_norm

@staticmethod
def _DIR_MAG_for_billboard(spot_size:float):
return 1 - XPlaneLight._WIDTH_for_billboard(spot_size)
def DIR_MAG_for_billboard(spot_size:float):
return 1 - XPlaneLight.WIDTH_for_billboard(spot_size)

@staticmethod
def _WIDTH_for_billboard(spot_size:float):
def WIDTH_for_billboard(spot_size:float):
assert spot_size != 0, "spot_size is 0, divide by zero error will occur"
angle_from_center = spot_size / 2
return math.cos(angle_from_center)/(math.cos(angle_from_center)-1)

@staticmethod
def _WIDTH_for_spill(spot_size:float):
def WIDTH_for_spill(spot_size:float):
return math.cos(spot_size * .5)
79 changes: 39 additions & 40 deletions io_xplane2blender/xplane_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,46 +572,45 @@ def draw_automatic_ui():
if param in parsed_light.light_param_def:
layout.row().prop(light_data.xplane, prop_name)

debug_box = layout.box()
debug_box.label(text="Debug Box")
debug_box.row().label(text=f"{len(parsed_light.light_param_def)} {' '.join(parsed_light.light_param_def)}")
debug_box.row().label(text=f"{parsed_light.overloads[0]['DREF'] if 'DREF' in parsed_light.overloads[0] else ''}")
if light_data.xplane.params:
debug_box.row().label(text=f"Former Params: '{light_data.xplane.params}'")
rgb_row = debug_box.row()
for param in parsed_light.light_param_def:
if param in {"R","G","B"}:
rgb_row.label(text=f"{param}: {round(light_data.color['RGB'.index(param)], 3)}")
if param == "A":
rgb_row.label(text=f"{param}: 1")
if param == "SIZE":
debug_box.row().label(text=f"{param}: {round(light_data.xplane.size)}m")
#--- WIDTH -----------------------------------------------
if param == "WIDTH" or param == "DIR_MAG":
if is_omni or light_data.type == "POINT":
debug_box.row().label(
text=f"{param}: Omni"
)
elif is_omni and not omni_conclusively_known:
assert False, "is_omni can't be True and not conclusively known"
elif not is_omni and omni_conclusively_known and light_data.type == "SPOT":
# We can only get this by being a non-special case Spot Light
debug_box.row().label(
text=f"{param}: {round(math.cos(light_data.spot_size * .5), 5)}"
)
elif not is_omni and not omni_conclusively_known and light_data.type == "SPOT":
# Directional billboard
debug_box.row().label(
text=f"{param}: Directional, final 'WIDTH' calculated during export"
)
#TODO: actually, if we don't have a SW callback, we can answer this for all billboards
#---------------------------------------------------------
if param == "INDEX":
debug_box.row().label(text=f"{param}: {light_data.xplane.param_index}")
if param == "FREQ":
debug_box.row().label(text=f"{param}: {light_data.xplane.param_freq}")
if param == "PHASE":
debug_box.row().label(text=f"{param}: {light_data.xplane.param_phase}")
has_width = "WIDTH" in parsed_light.light_param_def
has_dir_mag = "DIR_MAG" in parsed_light.light_param_def
if has_width or has_dir_mag:
debug_box = layout.box()
debug_box.label(text="Calculated Values")
#debug_box = layout.box()
#debug_box.row().label(text=f"{len(parsed_light.light_param_def)} {' '.join(parsed_light.light_param_def)}")
#debug_box.row().label(text=f"{parsed_light.overloads[0]['DREF'] if 'DREF' in parsed_light.overloads[0] else ''}")
#if light_data.xplane.params:
#debug_box.row().label(text=f"Former Params: '{light_data.xplane.params}'")
#if {"R","G","B"} <= set(parsed_light.light_param_def):
#debug_box.row().label(text=f"R, G, B: {', '.join(map(lambda c: str(round(c, 3)), light_data.color))}")

#def try_param(prop:str, param:str, text:str, n=5)->None:
#if param in parsed_light.light_param_def:
#debug_box.row().label(text=f"{text}: {round(light_data.xplane.get(prop), n)}")

#try_param("param_size", "Size", 3)
#--- WIDTH -----------------------------------------------
if has_width or has_dir_mag:
# Covers DIR_MAG case as well,
# though, ideally we'd stick with only using is_omni
if light_data.type == "POINT":
WIDTH_val = "Omni"
elif is_omni and not omni_conclusively_known:
assert False, "is_omni can't be True and not conclusively known"
elif not is_omni:
if has_width:
if "BILLBOARD" in parsed_light.best_overload().overload_type:
WIDTH_val = round(xplane_types.XPlaneLight.WIDTH_for_billboard(light_data.spot_size), 5)
elif "SPILL" in parsed_light.best_overload().overload_type:
WIDTH_val = round(xplane_types.XPlaneLight.WIDTH_for_spill(light_data.spot_size), 5)
elif has_dir_mag:
WIDTH_val = round(xplane_types.XPlaneLight.DIR_MAG_for_billboard(light_data.spot_size), 5)
debug_box.row().label(text=f"Width: {WIDTH_val}")
#---------------------------------------------------------
#try_param("param_index", "INDEX", "Dataref Index", n=0)
#try_param("param_freq", "FREQ", "Freq")
#try_param("param_phase", "PHASE", "Phase")
draw_automatic_ui()
elif light_data.xplane.type == LIGHT_NAMED:
layout.row().prop(light_data.xplane, "name")
Expand Down

0 comments on commit bac7edb

Please sign in to comment.