Skip to content

Commit 446bf28

Browse files
committed
Merge branch 'develop' into 312-light-spill-custom
# Conflicts: # io_xplane2blender/xplane_config.py # io_xplane2blender/xplane_constants.py # io_xplane2blender/xplane_props.py # io_xplane2blender/xplane_ui.py
1 parent 1e59e5e commit 446bf28

72 files changed

Lines changed: 7465 additions & 976 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

io_xplane2blender/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"name": "Export: X-Plane (.obj)",
2626
"description": "Export X-Plane objects/planes (.obj format)",
2727
"author": "Ted Greene, Ben Supnik",
28-
"version": (4, 0, 0),
28+
"version": (4, 1, 0),
2929
"blender": (2, 80, 0),
3030
"location": "File > Import/Export > X-Plane",
3131
"warning": "",

io_xplane2blender/tests/__init__.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
from io_xplane2blender.tests import animation_file_mappings, test_creation_helpers
1515
from io_xplane2blender.xplane_config import getDebug, setDebug
1616
from io_xplane2blender.xplane_helpers import XPlaneLogger, logger
17-
from io_xplane2blender.xplane_types import xplane_bone, xplane_file, xplane_primitive
17+
from io_xplane2blender.xplane_types import (
18+
xplane_attribute,
19+
xplane_bone,
20+
xplane_file,
21+
xplane_primitive,
22+
)
1823

1924
FLOAT_TOLERANCE = 0.0001
2025

2126
__dirname__ = os.path.dirname(__file__)
22-
TMP_DIR = os.path.realpath(os.path.join(__dirname__, "../../tests/tmp"))
2327

2428
FilterLinesCallback = Callable[[List[Union[float, str]]], bool]
2529

@@ -189,10 +193,10 @@ def assertFloatVectorsEqual(
189193
for a_comp, b_comp in zip(a, b):
190194
self.assertFloatsEqual(a_comp, b_comp, tolerance)
191195

192-
def parseFileToLines(self, data: str) -> List[Union[float, str]]:
196+
def parseFileToLines(self, data: str) -> List[Tuple[Union[float, str]]]:
193197
"""
194-
Turns a string of \n seperated lines into a List[Union[float,str]]
195-
without comments or 0 length strings. All numeric parts are converted
198+
Turns a string of \n seperated lines into a list of lines
199+
without comments or 0 length strings with all numeric parts are converted
196200
"""
197201
lines = [] # type: List[Union[float,str]]
198202

@@ -208,7 +212,7 @@ def tryToFloat(part: str) -> Union[float, str]:
208212
line = line.strip()
209213
if line:
210214
if line.startswith("800"):
211-
lines.append(line.split())
215+
lines.append(tuple(line.split()))
212216
else:
213217
lines.append(tuple(map(tryToFloat, line.split())))
214218

@@ -414,7 +418,7 @@ def assertLayerExportEqualsFixture(
414418
- layer_number starts at 0, as it used to access the scene.layers collection
415419
"""
416420
# if not ('-q' in sys.argv or '--quiet' in sys.argv):
417-
# print("Comparing: '%s', '%s'" % (tmpFilename, fixturePath))
421+
# print("Comparing: '%s', '%s'" % (tmpFilename, fixturePath))
418422

419423
out = self.exportExportableRoot(
420424
bpy.data.collections[f"Layer {layer_number + 1}"], tmpFilename
@@ -446,34 +450,35 @@ def assertExportableRootExportEqualsFixture(
446450
# asserts that an attributes object equals a dict
447451
def assertAttributesEqualDict(
448452
self,
449-
attrs: List[str],
453+
attrs: List[Union[str, xplane_attribute.XPlaneAttribute]],
450454
d: Dict[str, Any],
451455
floatTolerance: float = FLOAT_TOLERANCE,
452456
):
453-
self.assertEquals(len(d), len(attrs), "Attribute lists have different length")
457+
self.assertEquals(
458+
len(d),
459+
len(attrs),
460+
f"Attribute lists {list(d.keys())}, {list(attrs.keys())} have different length",
461+
)
454462

455463
for name in attrs:
456464
attr = attrs[name]
457465
value = attr.getValue()
458466
expectedValue = d[name]
459467

460-
if isinstance(expectedValue, list) or isinstance(expectedValue, tuple):
461-
self.assertTrue(
462-
isinstance(value, list) or isinstance(value, tuple),
463-
'Attribute value for "%s" is no list or tuple but: %s'
464-
% (name, str(value)),
468+
if isinstance(expectedValue, (list, tuple)):
469+
self.assertIsInstance(
470+
value,
471+
(list, tuple),
472+
msg='Attribute value for "%s" is no list or tuple but: %s',
465473
)
466474
self.assertEquals(
467475
len(expectedValue),
468476
len(value),
469477
'Attribute values for "%s" have different length' % name,
470478
)
471479

472-
for i in range(0, len(expectedValue)):
473-
v = value[i]
474-
expectedV = expectedValue[i]
475-
476-
if isinstance(expectedV, float) or isinstance(expectedV, int):
480+
for i, (v, expectedV) in enumerate(zip(value, expectedValue)):
481+
if isinstance(expectedV, (float, int)):
477482
self.assertFloatsEqual(expectedV, v, floatTolerance)
478483
else:
479484
self.assertEquals(
@@ -564,7 +569,7 @@ def exportExportableRoot(
564569
xplane_file._all_keyframe_infos.clear()
565570

566571
if dest:
567-
with open(os.path.join(TMP_DIR, dest + ".obj"), "w") as tmp_file:
572+
with open(os.path.join(get_tmp_folder(), dest + ".obj"), "w") as tmp_file:
568573
tmp_file.write(out)
569574

570575
return out
@@ -640,18 +645,22 @@ def filterLine(line):
640645

641646
def get_source_folder() -> pathlib.Path:
642647
"""Returns the full path to the addon folder"""
643-
return os.path.dirname(pathlib.Path("..", __file__))
648+
return pathlib.Path(__file__).parent
644649

645650

646651
def get_project_folder() -> pathlib.Path:
647652
"""Returns the full path to the project folder"""
648-
return os.path.dirname(pathlib.Path("..", "..", __file__))
653+
return pathlib.Path(__file__).parent.parent.parent
649654

650655

651656
def get_tests_folder() -> pathlib.Path:
652657
return pathlib.Path(get_project_folder(), "tests")
653658

654659

660+
def get_tmp_folder() -> pathlib.Path:
661+
return os.path.realpath(os.path.join(__dirname__, "../../tests/tmp"))
662+
663+
655664
def make_fixture_path(dirname, filename, sub_dir=""):
656665
return os.path.join(dirname, "fixtures", sub_dir, filename + ".obj")
657666

io_xplane2blender/xplane_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
CURRENT_ADDON_VERSION: Tuple[int, int, int] = bl_info["version"]
1111

1212
# The current build type, must be a member of XPlane2BlenderVersion.BUILD_TYPE
13-
CURRENT_BUILD_TYPE = xplane_constants.BUILD_TYPE_DEV
13+
CURRENT_BUILD_TYPE = xplane_constants.BUILD_TYPE_BETA
1414

1515
# The current build type version, must be > 0
1616
# if not BUILD_TYPE_DEV or BULD_TYPE_LEGACY
17-
CURRENT_BUILD_TYPE_VERSION = 0
17+
CURRENT_BUILD_TYPE_VERSION = 1
1818

1919
# The current data model version, incrementing every time xplane_constants, xplane_props, or xplane_updater
2020
# changes. Builds earlier than 3.4.0-beta.5 have and a version of 0.
2121
# When merging, take the higher data model version of the two branches and add one
22-
CURRENT_DATA_MODEL_VERSION = 90
22+
CURRENT_DATA_MODEL_VERSION = 101
2323

2424
# The build number, hardcoded by the build script when there is one, otherwise it is xplane_constants.BUILD_NUMBER_NONE
2525
CURRENT_BUILD_NUMBER = xplane_constants.BUILD_NUMBER_NONE

io_xplane2blender/xplane_constants.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ def _get_resources_folder() -> str:
9191
CONDITION_GLOBAL_SHADOWS = "GLOBAL_SHADOWS"
9292
CONDITION_VERSION10 = "VERSION10"
9393

94+
COCKPIT_FEATURE_NONE = "none"
95+
# See panel modes as well
96+
COCKPIT_FEATURE_PANEL = "panel"
97+
COCKPIT_FEATURE_DEVICE = "device"
98+
99+
DEVICE_GNS430_1 = "GNS430_1"
100+
DEVICE_GNS430_2 = "GNS430_2"
101+
DEVICE_GNS530_1 = "GNS530_1"
102+
DEVICE_GNS530_2 = "GNS530_2"
103+
DEVICE_CDU739_1 = "CDU739_1"
104+
DEVICE_CDU739_2 = "CDU739_2"
105+
DEVICE_G1000_PFD1 = "G1000_PFD1"
106+
DEVICE_G1000_MFD = "G1000_MFD"
107+
DEVICE_G1000_PFD2 = "G1000_PFD2"
108+
94109
MANIP_DRAG_XY = "drag_xy"
95110
MANIP_DRAG_AXIS = "drag_axis"
96111
MANIP_COMMAND = "command"
@@ -226,6 +241,7 @@ def _get_all_manipulators():
226241
LIGHT_PARAM = "param"
227242
LIGHT_AUTOMATIC = "automatic"
228243
LIGHT_SPILL_CUSTOM = "light_spill_custom"
244+
LIGHT_NON_EXPORTING = "nonexporting"
229245

230246
LIGHTS_OLD_TYPES = {
231247
LIGHT_DEFAULT,
@@ -248,3 +264,7 @@ def _get_all_manipulators():
248264
LOGGER_LEVEL_SUCCESS,
249265
LOGGER_LEVEL_WARN,
250266
)
267+
268+
PANEL_COCKPIT = "cockpit"
269+
PANEL_COCKPIT_LIT_ONLY = "cockpit_lit_only"
270+
PANEL_COCKPIT_REGION = "cockpit_region"

io_xplane2blender/xplane_helpers.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import mathutils
1010

1111
import io_xplane2blender
12-
from io_xplane2blender import xplane_config, xplane_constants
12+
from io_xplane2blender import xplane_config, xplane_constants, xplane_props
1313
from io_xplane2blender.xplane_constants import PRECISION_OBJ_FLOAT
1414

1515
"""
@@ -63,6 +63,20 @@ def resolveBlenderPath(path: str) -> str:
6363
return path
6464

6565

66+
def effective_normal_metalness(xp_file: "xplane_file.XPlaneFile") -> bool:
67+
return (
68+
int(bpy.context.scene.xplane.version) >= 1100
69+
and xp_file.options.normal_metalness
70+
)
71+
72+
73+
def effective_normal_metalness_draped(xp_file: "xplane_file.XPlaneFile") -> bool:
74+
return (
75+
int(bpy.context.scene.xplane.version) >= 1100
76+
and xp_file.options.normal_metalness_draped
77+
)
78+
79+
6680
def get_plugin_resources_folder() -> str:
6781
return os.path.join(os.path.dirname(__file__), "resources")
6882

@@ -195,11 +209,11 @@ def vec_x_to_b(v) -> mathutils.Vector:
195209
class VerStruct:
196210
def __init__(
197211
self,
198-
addon_version: Tuple[int, int, int] = None,
199-
build_type: str = None,
200-
build_type_version: int = None,
201-
data_model_version: int = None,
202-
build_number=None,
212+
addon_version: Optional[Tuple[int, int, int]] = None,
213+
build_type: Optional[str] = None,
214+
build_type_version: Optional[int] = None,
215+
data_model_version: Optional[int] = None,
216+
build_number: Optional[str] = None,
203217
):
204218
# fmt: off
205219
self.addon_version = tuple(addon_version) if addon_version is not None else (0,0,0)
@@ -279,7 +293,7 @@ def __str__(self):
279293
# according to our spec
280294
#
281295
# Returns True or False
282-
def is_valid(self):
296+
def is_valid(self) -> bool:
283297
types_correct = (
284298
isinstance(self.addon_version, tuple)
285299
and len(self.addon_version) == 3
@@ -354,13 +368,17 @@ def is_valid(self):
354368
return True
355369
else:
356370
print("build_type %s was not found in BUILD_TYPES" % self.build_type)
371+
return False
357372
else:
358373
print("addon_version %s is invalid" % str(self.addon_version))
359374
return False
360375

361376
@staticmethod
362-
def add_to_version_history(version_to_add):
363-
history = bpy.context.scene.xplane.xplane2blender_ver_history
377+
def add_to_version_history(
378+
scene: bpy.types.Scene,
379+
version_to_add: Union["VerStruct", "xplane_props.XPlane2BlenderVersion"],
380+
):
381+
history = scene.xplane.xplane2blender_ver_history
364382

365383
if len(history) == 0 or history[-1].name != repr(version_to_add):
366384
new_hist_entry = history.add()
@@ -396,6 +414,18 @@ def current():
396414
xplane_config.CURRENT_BUILD_NUMBER,
397415
)
398416

417+
@staticmethod
418+
def from_version_entry(
419+
version_entry: "xplane_props.XPlane2BlenderVersion",
420+
) -> "VerStruct":
421+
return VerStruct(
422+
version_entry.addon_version,
423+
version_entry.build_type,
424+
version_entry.build_type_version,
425+
version_entry.data_model_version,
426+
version_entry.build_number,
427+
)
428+
399429
@staticmethod
400430
def make_new_build_number():
401431
# Use the UNIX Timestamp in UTC

0 commit comments

Comments
 (0)