diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2017-05-23 18:35:45 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2017-05-23 18:35:45 +0300 |
commit | 99c6601a1ffe744ef8592de5da5920156a1097a6 (patch) | |
tree | 2dd91884fb1bc12144f4d585c4591db354725134 /tests/python/bl_alembic_import_test.py | |
parent | 3db15ae23a542f60926baea24f838c8510371743 (diff) | |
parent | 7b25ffb618dd7509d425f7a5891c64d4a3668743 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'tests/python/bl_alembic_import_test.py')
-rw-r--r-- | tests/python/bl_alembic_import_test.py | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/python/bl_alembic_import_test.py b/tests/python/bl_alembic_import_test.py index 854a5846361..1322a883b72 100644 --- a/tests/python/bl_alembic_import_test.py +++ b/tests/python/bl_alembic_import_test.py @@ -31,7 +31,7 @@ import bpy args = None -class SimpleImportTest(unittest.TestCase): +class AbstractAlembicTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.testdir = args.testdir @@ -43,6 +43,18 @@ class SimpleImportTest(unittest.TestCase): # Make sure we always start with a known-empty file. bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "empty.blend")) + def assertAlmostEqualFloatArray(self, actual, expect, places=6, delta=None): + """Asserts that the arrays of floats are almost equal.""" + + self.assertEqual(len(actual), len(expect), + 'Actual array has %d items, expected %d' % (len(actual), len(expect))) + + for idx, (act, exp) in enumerate(zip(actual, expect)): + self.assertAlmostEqual(act, exp, places=places, delta=delta, + msg='%f != %f at index %d' % (act, exp, idx)) + + +class SimpleImportTest(AbstractAlembicTest): def test_import_cube_hierarchy(self): res = bpy.ops.wm.alembic_import( filepath=str(self.testdir / "cubes-hierarchy.abc"), @@ -158,6 +170,38 @@ class SimpleImportTest(unittest.TestCase): self.assertEqual('CubeShape', bpy.data.objects['Cube'].data.name) +class VertexColourImportTest(AbstractAlembicTest): + def test_import_from_houdini(self): + # Houdini saved "face-varying", and as RGB. + res = bpy.ops.wm.alembic_import( + filepath=str(self.testdir / "vertex-colours-houdini.abc"), + as_background_job=False) + self.assertEqual({'FINISHED'}, res) + + ob = bpy.context.active_object + layer = ob.data.vertex_colors['Cf'] # MeshLoopColorLayer + + # Test some known-good values. + self.assertAlmostEqualFloatArray(layer.data[0].color, (0, 0, 0)) + self.assertAlmostEqualFloatArray(layer.data[98].color, (0.9019607, 0.4745098, 0.2666666)) + self.assertAlmostEqualFloatArray(layer.data[99].color, (0.8941176, 0.4705882, 0.2627451)) + + def test_import_from_blender(self): + # Blender saved per-vertex, and as RGBA. + res = bpy.ops.wm.alembic_import( + filepath=str(self.testdir / "vertex-colours-blender.abc"), + as_background_job=False) + self.assertEqual({'FINISHED'}, res) + + ob = bpy.context.active_object + layer = ob.data.vertex_colors['Cf'] # MeshLoopColorLayer + + # Test some known-good values. + self.assertAlmostEqualFloatArray(layer.data[0].color, (1.0, 0.0156862, 0.3607843)) + self.assertAlmostEqualFloatArray(layer.data[98].color, (0.0941176, 0.1215686, 0.9137254)) + self.assertAlmostEqualFloatArray(layer.data[99].color, (0.1294117, 0.3529411, 0.7529411)) + + def main(): global args import argparse |