mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
Alembic: remember default and active color attributes
Prior to version 3.5, when importing an Alembic file the default and active color attributes were set to the first color layer. Since then, as the default and active color attributes are stored as strings on the Mesh object, importing an Alembic file leaves those uninitialized. Note that this only worked prior to 3.5 as the indices for the active and default layers were initialized by default to zero. Remembering those default and active attributes is necessary after an import for e.g. being able to visualize the colors using viewport shading overlays. As Alembic does not have a concept of default or active color attribute, this writes the name of those attributes in the mesh user properties during export. During import, we lookup those properties and use them to set the default and active color layers. If the properties do not exist, we default to the first color layer. This adds a test for the new export and import of the default and active names, and updates old tests to check that the fallback to the first layer works. Pull Request: https://projects.blender.org/blender/blender/pulls/164075
This commit is contained in:
parent
c6447e69c6
commit
cc44ebbd24
7 changed files with 138 additions and 2 deletions
|
|
@ -220,6 +220,10 @@ class VertexColourImportTest(AbstractAlembicTest):
|
|||
self.assertAlmostEqualFloatArray(layer.data[98].color, (0.9019607, 0.4745098, 0.2666666, 1.0))
|
||||
self.assertAlmostEqualFloatArray(layer.data[99].color, (0.8941176, 0.4705882, 0.2627451, 1.0))
|
||||
|
||||
mesh = ob.data
|
||||
self.assertEqual(mesh.color_attributes.active_color_name, 'Cf')
|
||||
self.assertEqual(mesh.color_attributes.default_color_name, 'Cf')
|
||||
|
||||
def test_import_from_blender(self):
|
||||
# Blender saved per-vertex, and as RGBA.
|
||||
res = bpy.ops.wm.alembic_import(
|
||||
|
|
@ -235,6 +239,37 @@ class VertexColourImportTest(AbstractAlembicTest):
|
|||
self.assertAlmostEqualFloatArray(layer.data[98].color, (0.0941176, 0.1215686, 0.9137254, 1.0))
|
||||
self.assertAlmostEqualFloatArray(layer.data[99].color, (0.1294117, 0.3529411, 0.7529411, 1.0))
|
||||
|
||||
mesh = ob.data
|
||||
self.assertEqual(mesh.color_attributes.active_color_name, 'Cf')
|
||||
self.assertEqual(mesh.color_attributes.default_color_name, 'Cf')
|
||||
|
||||
|
||||
class VertexColourImportExportTest(AbstractAlembicTest):
|
||||
def setUp(self):
|
||||
self._tempdir = tempfile.TemporaryDirectory()
|
||||
self.tempdir = pathlib.Path(self._tempdir.name)
|
||||
|
||||
def test_export_import_default_active(self):
|
||||
"""Test export and import of the default and active color attribute names"""
|
||||
|
||||
abc_path = str(self.tempdir / "vertex-colours-default-active.abc")
|
||||
|
||||
# Export
|
||||
bpy.ops.wm.open_mainfile(filepath=str(args.testdir / "vertex-colours-default-active.blend"))
|
||||
self.assertIn('FINISHED', bpy.ops.wm.alembic_export(
|
||||
filepath=abc_path,
|
||||
vcolors=True
|
||||
))
|
||||
|
||||
# Import back
|
||||
res = bpy.ops.wm.alembic_import(filepath=abc_path, as_background_job=False)
|
||||
self.assertEqual({'FINISHED'}, res)
|
||||
|
||||
ob = bpy.context.active_object
|
||||
mesh = ob.data
|
||||
self.assertEqual(mesh.color_attributes.active_color_name, 'Active')
|
||||
self.assertEqual(mesh.color_attributes.default_color_name, 'Default')
|
||||
|
||||
|
||||
class CameraExportImportTest(unittest.TestCase):
|
||||
names = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue