refactor(tools): one FBX export preset instead of six copies
The bpy.ops.export_scene.fbx argument block was duplicated in six scripts (hero, block frontage, north buildings, site, scale test, MPFB character) and all six carried mesh_smooth_type="OFF", which drops smoothing groups and made every Unreal import warn and every round part faceted. Tools/fbx_export_preset.py now owns the presets: - preset_kwargs(preset, selection, **overrides) is bpy-free and unit-tested; - export_static()/export_character() are thin wrappers that import bpy lazily; - ue_metric_v1 and ue_character_v1 keep the recorded scale contract (FBX_SCALE_NONE, apply_unit_scale, -Y forward / Z up) and use FACE smoothing. Callers switched: hero_facade_build, export_block_frontage, export_north_buildings, scale_test_export, mpfb_character_export, Art/blender/site/export_site_fbx. Verified by re-exporting every asset through the preset and re-importing all of them: 0 smoothing warnings on site, frontage and north buildings; packaging and -qaselftest all PASS (walk, transect 0 holes, wall probe 0/35, facade probe 0/9). 49 tool tests pass (9 new for the preset contract).
This commit is contained in:
1 parent
160e9144f9
commit
286d9f6479
49 files changed
+283
-158
No files matched your search
@@ -0,0 +1,70 @@
|
||||
"""Tests for Tools/fbx_export_preset.py.
|
||||
|
||||
The preset module keeps its argument set in plain dicts and builds it in
|
||||
`preset_kwargs()`, so the export contract can be checked without starting
|
||||
Blender. Only `export_static`/`export_character` import `bpy`.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
sys.path.insert(0, os.path.join(ROOT, "Tools"))
|
||||
|
||||
import fbx_export_preset as preset # noqa: E402
|
||||
|
||||
|
||||
class MetricPresetTest(unittest.TestCase):
|
||||
def test_scale_and_axis_contract(self):
|
||||
# These three are the project's recorded conversion contract: metres ->
|
||||
# centimetres by a factor of exactly 100, east +X, north -Y, up +Z.
|
||||
kwargs = preset.preset_kwargs()
|
||||
self.assertTrue(kwargs["apply_unit_scale"])
|
||||
self.assertEqual(kwargs["apply_scale_options"], "FBX_SCALE_NONE")
|
||||
self.assertEqual(kwargs["axis_forward"], "-Y")
|
||||
self.assertEqual(kwargs["axis_up"], "Z")
|
||||
|
||||
def test_smoothing_groups_are_exported(self):
|
||||
# "OFF" (the pre-refactor value) drops smoothing groups and every Unreal
|
||||
# import warns about it, with round parts faceted.
|
||||
self.assertEqual(preset.preset_kwargs()["mesh_smooth_type"], "FACE")
|
||||
|
||||
def test_selection_flag(self):
|
||||
self.assertFalse(preset.preset_kwargs()["use_selection"])
|
||||
self.assertTrue(preset.preset_kwargs(selection=True)["use_selection"])
|
||||
|
||||
def test_object_types_are_meshes_only(self):
|
||||
self.assertEqual(preset.preset_kwargs()["object_types"], {"MESH"})
|
||||
|
||||
|
||||
class CharacterPresetTest(unittest.TestCase):
|
||||
def test_character_exports_armature_and_mesh(self):
|
||||
kwargs = preset.preset_kwargs("ue_character_v1")
|
||||
self.assertEqual(kwargs["object_types"], {"ARMATURE", "MESH"})
|
||||
self.assertFalse(kwargs["add_leaf_bones"])
|
||||
self.assertEqual(kwargs["path_mode"], "COPY")
|
||||
self.assertFalse(kwargs["embed_textures"])
|
||||
|
||||
def test_character_keeps_the_scale_contract(self):
|
||||
kwargs = preset.preset_kwargs("ue_character_v1")
|
||||
self.assertEqual(kwargs["apply_scale_options"], "FBX_SCALE_NONE")
|
||||
self.assertEqual(kwargs["mesh_smooth_type"], "FACE")
|
||||
|
||||
|
||||
class OverrideTest(unittest.TestCase):
|
||||
def test_overrides_win(self):
|
||||
kwargs = preset.preset_kwargs(mesh_smooth_type="OFF")
|
||||
self.assertEqual(kwargs["mesh_smooth_type"], "OFF")
|
||||
|
||||
def test_unknown_preset_raises(self):
|
||||
with self.assertRaises(KeyError):
|
||||
preset.preset_kwargs("ue_imperial_v9")
|
||||
|
||||
def test_filepath_must_not_be_an_override(self):
|
||||
with self.assertRaises(ValueError):
|
||||
preset.preset_kwargs(filepath="/tmp/x.fbx")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user