Fix T103354: Author extents on UsdGeomMesh #104676

Merged
Sybren A. Stüvel merged 6 commits from wave/blender_wave_Apple:contribs/T103354_author_extents into main 2023-02-14 12:12:05 +01:00
2 changed files with 101 additions and 0 deletions
Showing only changes of commit a60f0ec2c8 - Show all commits

View File

@ -910,6 +910,12 @@ if(WITH_ALEMBIC)
endif()
if(WITH_USD)
add_blender_test(
usd_export_test
--python ${CMAKE_CURRENT_LIST_DIR}/bl_usd_export_test.py
--
--testdir "${TEST_SRC_DIR}/usd"
)
add_blender_test(
usd_import_test
--python ${CMAKE_CURRENT_LIST_DIR}/bl_usd_import_test.py

View File

@ -0,0 +1,95 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import enum
import pathlib
import pprint
import sys
import tempfile
import unittest
from pxr import UsdUtils
import bpy
args = None
class Result(str, enum.Enum):
finished = "FINISHED"
cancelled = "CANCELLED"
wave marked this conversation as resolved

I don't think this class is necessary. Comparison with {'FINISHED'} etc. is common enough in Blender unit tests that trying to abstract away from it will make it harder for people who know the Blender API to figure out what's going on.

I don't think this `class` is necessary. Comparison with `{'FINISHED'}` etc. is common enough in Blender unit tests that trying to abstract away from it will make it harder for people who know the Blender API to figure out what's going on.
class AbstractUSDTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._tempdir = tempfile.TemporaryDirectory()
cls.testdir = args.testdir
cls.tempdir = pathlib.Path(cls._tempdir.name)
return cls
def setUp(self):
self.assertTrue(
self.testdir.exists(), "Test dir {0} should exist".format(self.testdir)
)
def tearDown(self):
self._tempdir.cleanup()
class USDExportTest(AbstractUSDTest):
def test_export_usdchecker(self):
"""Test exporting a scene and verifying it passes the usdchecker test suite"""
bpy.ops.wm.open_mainfile(
filepath=str(self.testdir / "usd_materials_export.blend")
)
export_path = self.tempdir / "usdchecker.usda"
res = bpy.ops.wm.usd_export(
filepath=str(export_path),
export_materials=True,
evaluation_mode="RENDER",
)
self.assertEqual({Result.finished}, res, f"Unable to export to {export_path}")
checker = UsdUtils.ComplianceChecker(
arkit=False,
skipARKitRootLayerCheck=False,
rootPackageOnly=False,
skipVariants=False,
verbose=False,
)
checker.CheckCompliance(str(export_path))
collection = {}
to_skip = ("MissingReferenceChecker",)
for rule in checker._rules:
wave marked this conversation as resolved

collection is not the most descriptive name. failed_checks would be better.

`collection` is not the most descriptive name. `failed_checks` would be better.
name = rule.__class__.__name__
if name in to_skip:
wave marked this conversation as resolved

Why is this rule skipped? Might be worth a comment.

Why is this rule skipped? Might be worth a comment.
continue
issues = rule.GetFailedChecks() + rule.GetWarnings() + rule.GetErrors()
if not issues:
continue
collection[name] = issues
self.assertFalse(collection, pprint.pformat(collection))
def main():
global args
import argparse
if "--" in sys.argv:
argv = [sys.argv[0]] + sys.argv[sys.argv.index("--") + 1 :]
else:
argv = sys.argv
parser = argparse.ArgumentParser()
parser.add_argument("--testdir", required=True, type=pathlib.Path)
args, remaining = parser.parse_known_args(argv)
unittest.main(argv=remaining)
if __name__ == "__main__":
main()