Skip to content

Commit

Permalink
Closes #595, with unit test, code, and all that fun!
Browse files Browse the repository at this point in the history
  • Loading branch information
tngreene committed Oct 27, 2020
1 parent acdecee commit 9bc8ac7
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 8 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 = 92
CURRENT_DATA_MODEL_VERSION = 93

# 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
8 changes: 6 additions & 2 deletions io_xplane2blender/xplane_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,6 @@ class XPlaneLOD(bpy.types.PropertyGroup):
def __str__(self)->str:
return f"({self.near}, {self.far})"

#TODO: Maybe we should change all this "X-Plane Layer" stuff
# to XPLaneOBJSettings or something
class XPlaneLayer(bpy.types.PropertyGroup):
"""
Defines settings for an OBJ file. Is was formerly tied to
Expand Down Expand Up @@ -1023,6 +1021,12 @@ 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
)

expanded: bpy.props.BoolProperty(
name = "Expanded",
description = "Toggles the layer settings visibility",
Expand Down
14 changes: 10 additions & 4 deletions io_xplane2blender/xplane_types/xplane_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ 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 @@ -480,10 +481,15 @@ def _init(self):
mat.attributes["ATTR_no_shadow"].setValue(None)

# cockpit_lit
if isCockpit and (
self.xplaneFile.options.cockpit_lit == True or xplane_version >= 1100
):
self.attributes["GLOBAL_cockpit_lit"].setValue(True)
if 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
8 changes: 7 additions & 1 deletion io_xplane2blender/xplane_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ 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 @@ -422,7 +428,7 @@ def layer_layout(
row.prop(layer_props, "tint_emissive", text="Emissive", slider=True)

# cockpit regions
if layer_props.export_type == "cockpit":
if layer_props.export_type == EXPORT_TYPE_COCKPIT:
cockpit_box = layout.box()
cockpit_box.label(text="Cockpits")
cockpit_box.prop(layer_props, "cockpit_regions", text="Regions")
Expand Down
Binary file added tests/features/cockpit_lit_only.test.blend
Binary file not shown.
47 changes: 47 additions & 0 deletions tests/features/cockpit_lit_only.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import inspect
import os
import sys
from typing import Tuple

import bpy

from io_xplane2blender import xplane_config
from io_xplane2blender.tests import *
from io_xplane2blender.tests import test_creation_helpers

__dirname__ = os.path.dirname(__file__)


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)

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")
]:
with self.subTest(f"Exporting {root.name}", root=root):
out = self.exportExportableRoot(root)
self.assertNotIn("ATTR_cockpit_lit_only", out)

def test_Scene_default_version(self) -> None:
bpy.context.window.scene = bpy.data.scenes["Scene_default_version"]
filename = "test_06_cockpit_lit_only_exported"
self.assertExportableRootExportEqualsFixture(
filename[5:],
os.path.join(__dirname__, "fixtures", f"{filename}.obj"),
{"ATTR_cockpit_lit_only"},
filename,
)


runTestCases([TestCockpitLitOnly])
59 changes: 59 additions & 0 deletions tests/features/fixtures/test_06_cockpit_lit_only_exported.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
I
800
OBJ

GLOBAL_cockpit_lit
ATTR_cockpit_lit_only
POINT_COUNTS 36 0 0 36

VT -1 1 1 0 1 -0 0.625 0.25
VT -1 1 -1 0 1 -0 0.625 0
VT 1 1 -1 0 1 -0 0.375 0
VT 1 1 1 0 1 0 0.375 0.25
VT -1 1 1 0 1 0 0.625 0.25
VT 1 1 -1 0 1 0 0.375 0
VT -1 1 1 0 0 1 0.625 0.5
VT 1 1 1 0 0 1 0.625 0.25
VT 1 -1 1 0 0 1 0.375 0.25
VT -1 -1 1 0 0 1 0.375 0.5
VT -1 1 1 0 0 1 0.625 0.5
VT 1 -1 1 0 0 1 0.375 0.25
VT -1 1 -1 -1 -0 0 0.625 0.75
VT -1 1 1 -1 -0 0 0.625 0.5
VT -1 -1 1 -1 -0 0 0.375 0.5
VT -1 -1 -1 -1 0 0 0.375 0.75
VT -1 1 -1 -1 0 0 0.625 0.75
VT -1 -1 1 -1 0 0 0.375 0.5
VT 1 -1 1 0 -1 -0 0.625 1
VT 1 -1 -1 0 -1 -0 0.625 0.75
VT -1 -1 -1 0 -1 -0 0.375 0.75
VT -1 -1 1 0 -1 -0 0.375 1
VT 1 -1 1 0 -1 -0 0.625 1
VT -1 -1 -1 0 -1 -0 0.375 0.75
VT 1 1 1 1 0 0 0.375 0.75
VT 1 1 -1 1 0 0 0.375 0.5
VT 1 -1 -1 1 0 0 0.125 0.5
VT 1 -1 1 1 0 0 0.125 0.75
VT 1 1 1 1 0 0 0.375 0.75
VT 1 -1 -1 1 0 0 0.125 0.5
VT 1 1 -1 0 0 -1 0.875 0.75
VT -1 1 -1 0 0 -1 0.875 0.5
VT -1 -1 -1 0 0 -1 0.625 0.5
VT 1 -1 -1 0 -0 -1 0.625 0.75
VT 1 1 -1 0 -0 -1 0.875 0.75
VT -1 -1 -1 0 -0 -1 0.625 0.5

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

ATTR_shiny_rat 0.5
TRIS 0 36

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

0 comments on commit 9bc8ac7

Please sign in to comment.