Skip to content

Commit

Permalink
Closes #595! However, in working on this bug it was discovered that t…
Browse files Browse the repository at this point in the history
…he regions feature is quite possibly broken, and that we don't have test coverage for it! Also discovered is that Aircraft export types have been previously unable to work with regions. Bug reports made.
  • Loading branch information
tngreene committed Nov 4, 2020
1 parent d04dabf commit b1b9adc
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 111 deletions.
2 changes: 1 addition & 1 deletion io_xplane2blender/xplane_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 = 94
CURRENT_DATA_MODEL_VERSION = 95

# 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
4 changes: 4 additions & 0 deletions io_xplane2blender/xplane_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,7 @@ def _get_all_manipulators():
LOGGER_LEVEL_SUCCESS,
LOGGER_LEVEL_WARN,
)

PANEL_COCKPIT = "cockpit"
PANEL_COCKPIT_LIT_ONLY = "cockpit_lit_only"
PANEL_COCKPIT_REGION = "cockpit_region"
19 changes: 15 additions & 4 deletions io_xplane2blender/xplane_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,13 @@ class XPlaneLayer(bpy.types.PropertyGroup):
or they'll reload the file and the problem will be (hopefully solved)
"""
def update_cockpit_regions(self, context)->None:
# Avoids the need for operators to increase and decrease the size of self.cockpit_region
while len(self.cockpit_region) < xplane_constants.MAX_COCKPIT_REGIONS:
self.cockpit_region.add()
return None

def update_lods(self, context):
# Avoids the need for operators to increase and decrease the size of self.lods
#MAX_LODS also counts "None", so we have to subtract by 1
while len(self.lod) < xplane_constants.MAX_LODS - 1:
self.lod.add()
Expand All @@ -1021,10 +1023,15 @@ def update_lods(self, context):
default = False
)

cockpit_lit_only: bpy.props.BoolProperty(
name="Emissive Panel Texture Only",
description="Only emissive panel texture will be dynamic. Great for computer displays",
default = False
cockpit_panel_mode: bpy.props.EnumProperty(
name="Panel Texture Mode",
description="Panel Texture Mode, affects all Materials using Panel",
items=[
(PANEL_COCKPIT, "Default", "Full Panel Texture: Albedo, Lit, and Normal"),
(PANEL_COCKPIT_LIT_ONLY, "Emissive Panel Texture Only", "Only emissive panel texture will be dynamic. Great for computer displays"),
(PANEL_COCKPIT_REGION, "Regions", "Uses regions of panel texture")
],
default=PANEL_COCKPIT,
)

expanded: bpy.props.BoolProperty(
Expand Down Expand Up @@ -1163,6 +1170,8 @@ def update_lods(self, context):
default = ""
)

# BAD NAME ALERT!
# regions (plural) is the enum, region (singular) is the collection
cockpit_regions: bpy.props.EnumProperty(
name = "Cockpit Regions",
description = "Number of Cockpit regions to use",
Expand All @@ -1183,6 +1192,8 @@ def update_lods(self, context):
description = "Cockpit Region"
)

# BAD NAME ALERT!
# lods (plural) is the enum, lod (singular) is the collection
lods: bpy.props.EnumProperty(
name = "Levels of Detail",
description = "Levels of detail",
Expand Down
11 changes: 2 additions & 9 deletions io_xplane2blender/xplane_types/xplane_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def __init__(self, xplaneFile: "XPlaneFile", obj_version: int) -> None:
self.attributes.add(XPlaneAttribute("COCKPIT_REGION", None))
self.attributes.add(XPlaneAttribute("DEBUG", None))
self.attributes.add(XPlaneAttribute("GLOBAL_cockpit_lit", None))
self.attributes.add(XPlaneAttribute("ATTR_cockpit_lit_only", None))
self.attributes.add(XPlaneAttribute("GLOBAL_tint", None))
self.attributes.add(XPlaneAttribute("REQUIRE_WET", None))
self.attributes.add(XPlaneAttribute("REQUIRE_DRY", None))
Expand Down Expand Up @@ -324,7 +323,7 @@ def _init(self):
)

# set cockpit regions
if isCockpit:
if isAircraft or isCockpit:
num_regions = int(self.xplaneFile.options.cockpit_regions)

if num_regions > 0:
Expand Down Expand Up @@ -481,15 +480,9 @@ def _init(self):
mat.attributes["ATTR_no_shadow"].setValue(None)

# cockpit_lit
if isCockpit:
if isAircraft or isCockpit:
if self.xplaneFile.options.cockpit_lit or xplane_version >= 1100:
self.attributes["GLOBAL_cockpit_lit"].setValue(True)
if (
self.xplaneFile.options.cockpit_lit_only
and xplane_version >= 1110
and self.xplaneFile.options.cockpit_regions == "0"
):
self.attributes["ATTR_cockpit_lit_only"].setValue(True)

if len(self.export_path_dirs):
self.attributes["EXPORT"].value = [
Expand Down
31 changes: 24 additions & 7 deletions io_xplane2blender/xplane_types/xplane_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def __init__(self, xplaneObject: xplane_object.XPlaneObject):

self.cockpitAttributes = XPlaneAttributes()
self.cockpitAttributes.add(XPlaneAttribute("ATTR_cockpit", None, 2000))
self.cockpitAttributes.add(XPlaneAttribute("ATTR_no_cockpit", True, 2000))
self.cockpitAttributes.add(XPlaneAttribute("ATTR_cockpit_lit_only", None, 2000))
self.cockpitAttributes.add(XPlaneAttribute("ATTR_cockpit_region", None, 2000))
self.cockpitAttributes.add(XPlaneAttribute("ATTR_no_cockpit", True, 2000))

self.conditions = []

Expand Down Expand Up @@ -206,13 +207,29 @@ def collectCustomAttributes(self, mat: bpy.types.Material) -> None:

def collectCockpitAttributes(self, mat: bpy.types.Material) -> None:
if mat.xplane.panel:
self.cockpitAttributes["ATTR_cockpit"].setValue(True)
self.cockpitAttributes["ATTR_no_cockpit"].setValue(None)
xplaneFile = self.xplaneObject.xplaneBone.xplaneFile
xplane_version = int(bpy.context.scene.xplane.version)
cockpit_panel_mode = xplaneFile.options.cockpit_panel_mode
cockpit_region = int(mat.xplane.cockpit_region)
if cockpit_region > 0:
self.cockpitAttributes["ATTR_cockpit_region"].setValue(
cockpit_region - 1
)

self.cockpitAttributes["ATTR_no_cockpit"].setValue(None)
if xplane_version >= 1110:
if cockpit_panel_mode == PANEL_COCKPIT:
self.cockpitAttributes["ATTR_cockpit"].setValue(True)
elif cockpit_panel_mode == PANEL_COCKPIT_LIT_ONLY:
self.cockpitAttributes["ATTR_cockpit_lit_only"].setValue(True)
elif cockpit_panel_mode == PANEL_COCKPIT_REGION and cockpit_region:
self.cockpitAttributes["ATTR_cockpit_region"].setValue(
cockpit_region - 1
)
elif xplane_version < 1110:
# TODO: I believe this is wrong!
# This prints out ATTR_cockpit then region no matter
self.cockpitAttributes["ATTR_cockpit"].setValue(True)
if cockpit_region:
self.cockpitAttributes["ATTR_cockpit_region"].setValue(
cockpit_region - 1
)

def collectLightLevelAttributes(self, mat: bpy.types.Material) -> None:
if mat.xplane.lightLevel:
Expand Down
74 changes: 34 additions & 40 deletions io_xplane2blender/xplane_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,6 @@ def layer_layout(

global_mat_box = layout.box()
global_mat_box.label(text="Global Material Options")
if version >= 1110:
if (
layer_props.export_type == EXPORT_TYPE_COCKPIT
and layer_props.cockpit_regions == "0"
):
global_mat_box.row().prop(layer_props, "cockpit_lit_only")
if version >= 1100:
global_mat_box.row().prop(layer_props, "blend_glass")
global_mat_box.row().prop(layer_props, "normal_metalness")
Expand All @@ -428,42 +422,42 @@ def layer_layout(
row.prop(layer_props, "tint_emissive", text="Emissive", slider=True)

# cockpit regions
if layer_props.export_type == EXPORT_TYPE_COCKPIT:
if layer_props.export_type in {EXPORT_TYPE_AIRCRAFT, EXPORT_TYPE_COCKPIT}:
cockpit_box = layout.box()
cockpit_box.label(text="Cockpits")
cockpit_box.prop(layer_props, "cockpit_regions", text="Regions")
num_regions = int(layer_props.cockpit_regions)

if num_regions > 0:
for i in range(0, num_regions):
# get cockpit region or create it if not present
if len(layer_props.cockpit_region) > i:
cockpit_region = layer_props.cockpit_region[i]

if cockpit_region.expanded:
expandIcon = "TRIA_DOWN"
else:
expandIcon = "TRIA_RIGHT"

region_box = cockpit_box.box()
region_box.prop(
cockpit_region,
"expanded",
text="Cockpit region %i" % (i + 1),
expand=True,
emboss=False,
icon=expandIcon,
)
cockpit_box.label(text="Cockpit Panel Options")
if version >= 1110:
cockpit_box.row().prop(layer_props, "cockpit_panel_mode")

if layer_props.cockpit_panel_mode == PANEL_COCKPIT:
pass
elif (
version >= 1110 and layer_props.cockpit_panel_mode == PANEL_COCKPIT_LIT_ONLY
):
pass
elif layer_props.cockpit_panel_mode == PANEL_COCKPIT_REGION or version < 1110:
cockpit_box.prop(layer_props, "cockpit_regions", text="Regions")
for i, cockpit_region in enumerate(
layer_props.cockpit_region[: int(layer_props.cockpit_regions)]
):
region_box = cockpit_box.box()
region_box.prop(
cockpit_region,
"expanded",
text="Cockpit region %i" % (i + 1),
expand=True,
emboss=False,
icon=("TRIA_DOWN" if cockpit_region.expanded else "TRIA_RIGHT"),
)

if cockpit_region.expanded:
region_box.prop(cockpit_region, "left")
region_box.prop(cockpit_region, "top")
region_split = region_box.split(factor=0.5)
region_split.prop(cockpit_region, "width")
region_split.label(text="= %d" % (2 ** cockpit_region.width))
region_split = region_box.split(factor=0.5)
region_split.prop(cockpit_region, "height")
region_split.label(text="= %d" % (2 ** cockpit_region.height))
if cockpit_region.expanded:
region_box.prop(cockpit_region, "left")
region_box.prop(cockpit_region, "top")
region_split = region_box.split(factor=0.5)
region_split.prop(cockpit_region, "width")
region_split.label(text="= %d" % (2 ** cockpit_region.width))
region_split = region_box.split(factor=0.5)
region_split.prop(cockpit_region, "height")
region_split.label(text="= %d" % (2 ** cockpit_region.height))

# v1010
if version < 1100:
Expand Down
Binary file modified tests/features/cockpit_lit_only.test.blend
Binary file not shown.
33 changes: 22 additions & 11 deletions tests/features/cockpit_lit_only.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,33 @@ class TestCockpitLitOnly(XPlaneTestCase):
def test_Scene_1100(self) -> None:
bpy.context.window.scene = bpy.data.scenes["Scene_1100"]

out = self.exportExportableRoot("05_cockpit_lit_only_no_export_wrong_version")
self.assertNotIn("ATTR_cockpit_lit_only", out)
filename = "test_05_cockpit_lit_only_no_export_wrong_version"
self.assertExportableRootExportEqualsFixture(
filename[5:],
os.path.join(__dirname__, "fixtures", f"{filename}.obj"),
{"ATTR_cockpit_lit_only"},
filename,
)

def test_Scene_1110(self) -> None:
bpy.context.window.scene = bpy.data.scenes["Scene_1110"]

out = self.exportExportableRoot("01_cockpit_lit_only_exported")
self.assertIn("ATTR_cockpit_lit_only", out)
for root in [
c
for c in bpy.context.scene.collection.children
if not c.name.startswith("01")
out = self.exportExportableRoot("test_02_cockpit_lit_only_wrong_type_error"[5:])
# Scenery cannot have panel
self.assertLoggerErrors(1)

for filename in [
"test_01_cockpit_lit_only_exported",
"test_03_cockpit_lit_only_no_export_regions",
"test_04_cockpit_lit_no_export_panel_mode_default",
]:
with self.subTest(f"Exporting {root.name}", root=root):
out = self.exportExportableRoot(root)
self.assertNotIn("ATTR_cockpit_lit_only", out)
with self.subTest(f"Testing fixture {filename}", filename=filename):
self.assertExportableRootExportEqualsFixture(
filename[5:],
os.path.join(__dirname__, "fixtures", f"{filename}.obj"),
{"ATTR_cockpit_lit_only"},
filename,
)

def test_Scene_default_version(self) -> None:
bpy.context.window.scene = bpy.data.scenes["Scene_default_version"]
Expand Down
62 changes: 62 additions & 0 deletions tests/features/fixtures/test_01_cockpit_lit_only_exported.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
I
800
OBJ

GLOBAL_cockpit_lit
POINT_COUNTS 36 0 0 36

VT -1 1 1 0 1 -0 0.625 0.25 # 0
VT -1 1 -1 0 1 -0 0.625 0 # 1
VT 1 1 -1 0 1 -0 0.375 0 # 2
VT 1 1 1 0 1 0 0.375 0.25 # 3
VT -1 1 1 0 1 0 0.625 0.25 # 4
VT 1 1 -1 0 1 0 0.375 0 # 5
VT -1 1 1 0 0 1 0.625 0.5 # 6
VT 1 1 1 0 0 1 0.625 0.25 # 7
VT 1 -1 1 0 0 1 0.375 0.25 # 8
VT -1 -1 1 0 0 1 0.375 0.5 # 9
VT -1 1 1 0 0 1 0.625 0.5 # 10
VT 1 -1 1 0 0 1 0.375 0.25 # 11
VT -1 1 -1 -1 -0 0 0.625 0.75 # 12
VT -1 1 1 -1 -0 0 0.625 0.5 # 13
VT -1 -1 1 -1 -0 0 0.375 0.5 # 14
VT -1 -1 -1 -1 0 0 0.375 0.75 # 15
VT -1 1 -1 -1 0 0 0.625 0.75 # 16
VT -1 -1 1 -1 0 0 0.375 0.5 # 17
VT 1 -1 1 0 -1 -0 0.625 1 # 18
VT 1 -1 -1 0 -1 -0 0.625 0.75 # 19
VT -1 -1 -1 0 -1 -0 0.375 0.75 # 20
VT -1 -1 1 0 -1 -0 0.375 1 # 21
VT 1 -1 1 0 -1 -0 0.625 1 # 22
VT -1 -1 -1 0 -1 -0 0.375 0.75 # 23
VT 1 1 1 1 0 0 0.375 0.75 # 24
VT 1 1 -1 1 0 0 0.375 0.5 # 25
VT 1 -1 -1 1 0 0 0.125 0.5 # 26
VT 1 -1 1 1 0 0 0.125 0.75 # 27
VT 1 1 1 1 0 0 0.375 0.75 # 28
VT 1 -1 -1 1 0 0 0.125 0.5 # 29
VT 1 1 -1 0 0 -1 0.875 0.75 # 30
VT -1 1 -1 0 0 -1 0.875 0.5 # 31
VT -1 -1 -1 0 0 -1 0.625 0.5 # 32
VT 1 -1 -1 0 -0 -1 0.625 0.75 # 33
VT 1 1 -1 0 -0 -1 0.875 0.75 # 34
VT -1 -1 -1 0 -0 -1 0.625 0.5 # 35

IDX10 0 1 2 3 4 5 6 7 8 9
IDX10 10 11 12 13 14 15 16 17 18 19
IDX10 20 21 22 23 24 25 26 27 28 29
IDX 30
IDX 31
IDX 32
IDX 33
IDX 34
IDX 35

# 0 ROOT
# 1 Mesh: Cube
# MESH: Cube weight: 2
# MATERIAL: MaterialPartOfPanel
ATTR_cockpit_lit_only
TRIS 0 36

# Build with Blender 2.80 (sub 75) (build b'f6cb5f54494e'). Exported with XPlane2Blender 4.1.0-dev.0+94.NO_BUILD_NUMBR
Loading

0 comments on commit b1b9adc

Please sign in to comment.