2023-08-15 16:20:26 +02:00
|
|
|
# SPDX-FileCopyrightText: 2017-2022 Blender Authors
|
2023-06-15 05:09:04 +02:00
|
|
|
#
|
2022-02-10 23:07:11 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2017-04-19 17:27:40 +02:00
|
|
|
|
|
|
|
"""
|
2020-02-14 15:14:46 +01:00
|
|
|
./blender.bin --background -noaudio --factory-startup --python tests/python/bl_alembic_io_test.py -- --testdir /path/to/lib/tests/alembic
|
2017-04-19 17:27:40 +02:00
|
|
|
"""
|
|
|
|
|
2020-02-14 15:21:19 +01:00
|
|
|
import math
|
2017-04-19 17:27:40 +02:00
|
|
|
import pathlib
|
|
|
|
import sys
|
2020-02-14 15:21:19 +01:00
|
|
|
import tempfile
|
2017-04-19 17:27:40 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
args = None
|
|
|
|
|
|
|
|
|
2017-05-23 17:27:09 +02:00
|
|
|
class AbstractAlembicTest(unittest.TestCase):
|
2017-04-19 17:27:40 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
cls.testdir = args.testdir
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.assertTrue(self.testdir.exists(),
|
|
|
|
'Test dir %s should exist' % self.testdir)
|
|
|
|
|
|
|
|
# Make sure we always start with a known-empty file.
|
|
|
|
bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "empty.blend"))
|
|
|
|
|
2017-05-23 17:27:09 +02:00
|
|
|
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):
|
2017-04-19 17:27:40 +02:00
|
|
|
def test_import_cube_hierarchy(self):
|
|
|
|
res = bpy.ops.wm.alembic_import(
|
|
|
|
filepath=str(self.testdir / "cubes-hierarchy.abc"),
|
|
|
|
as_background_job=False)
|
|
|
|
self.assertEqual({'FINISHED'}, res)
|
|
|
|
|
2018-06-08 17:14:44 +02:00
|
|
|
# The objects should be linked to scene.collection in Blender 2.8,
|
2017-04-19 17:27:40 +02:00
|
|
|
# and to scene in Blender 2.7x.
|
2018-06-08 17:14:44 +02:00
|
|
|
objects = bpy.context.scene.collection.objects
|
2017-04-19 17:27:40 +02:00
|
|
|
self.assertEqual(13, len(objects))
|
|
|
|
|
|
|
|
# Test the hierarchy.
|
|
|
|
self.assertIsNone(objects['Cube'].parent)
|
|
|
|
self.assertEqual(objects['Cube'], objects['Cube_001'].parent)
|
|
|
|
self.assertEqual(objects['Cube'], objects['Cube_002'].parent)
|
|
|
|
self.assertEqual(objects['Cube'], objects['Cube_003'].parent)
|
|
|
|
self.assertEqual(objects['Cube_003'], objects['Cube_004'].parent)
|
|
|
|
self.assertEqual(objects['Cube_003'], objects['Cube_005'].parent)
|
|
|
|
self.assertEqual(objects['Cube_003'], objects['Cube_006'].parent)
|
|
|
|
|
2017-07-11 16:16:56 +02:00
|
|
|
def test_inherit_or_not(self):
|
|
|
|
res = bpy.ops.wm.alembic_import(
|
|
|
|
filepath=str(self.testdir / "T52022-inheritance.abc"),
|
|
|
|
as_background_job=False)
|
|
|
|
self.assertEqual({'FINISHED'}, res)
|
|
|
|
|
2018-06-08 17:14:44 +02:00
|
|
|
# The objects should be linked to scene.collection in Blender 2.8,
|
2017-07-11 16:16:56 +02:00
|
|
|
# and to scene in Blender 2.7x.
|
2018-06-08 17:14:44 +02:00
|
|
|
objects = bpy.context.scene.collection.objects
|
2017-07-11 16:16:56 +02:00
|
|
|
|
|
|
|
# ABC parent is top-level object, which translates to nothing in Blender
|
|
|
|
self.assertIsNone(objects['locator1'].parent)
|
|
|
|
|
|
|
|
# ABC parent is locator1, but locator2 has "inherits Xforms" = false, which
|
|
|
|
# translates to "no parent" in Blender.
|
|
|
|
self.assertIsNone(objects['locator2'].parent)
|
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
|
2017-07-11 16:16:56 +02:00
|
|
|
# Shouldn't have inherited the ABC parent's transform.
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
loc2 = depsgraph.id_eval_get(objects['locator2'])
|
2017-07-11 16:16:56 +02:00
|
|
|
x, y, z = objects['locator2'].matrix_world.to_translation()
|
|
|
|
self.assertAlmostEqual(0, x)
|
|
|
|
self.assertAlmostEqual(0, y)
|
|
|
|
self.assertAlmostEqual(2, z)
|
|
|
|
|
|
|
|
# ABC parent is inherited and translates to normal parent in Blender.
|
|
|
|
self.assertEqual(objects['locator2'], objects['locatorShape2'].parent)
|
|
|
|
|
|
|
|
# Should have inherited its ABC parent's transform.
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
locshp2 = depsgraph.id_eval_get(objects['locatorShape2'])
|
2018-06-12 15:39:54 +02:00
|
|
|
x, y, z = locshp2.matrix_world.to_translation()
|
2017-07-11 16:16:56 +02:00
|
|
|
self.assertAlmostEqual(0, x)
|
|
|
|
self.assertAlmostEqual(0, y)
|
|
|
|
self.assertAlmostEqual(2, z)
|
|
|
|
|
2017-04-21 15:58:14 +02:00
|
|
|
def test_select_after_import(self):
|
2017-04-20 12:01:31 +02:00
|
|
|
# Add a sphere, so that there is something in the scene, selected, and active,
|
|
|
|
# before we do the Alembic import.
|
|
|
|
bpy.ops.mesh.primitive_uv_sphere_add()
|
|
|
|
sphere = bpy.context.active_object
|
|
|
|
self.assertEqual('Sphere', sphere.name)
|
|
|
|
self.assertEqual([sphere], bpy.context.selected_objects)
|
|
|
|
|
|
|
|
bpy.ops.wm.alembic_import(
|
|
|
|
filepath=str(self.testdir / "cubes-hierarchy.abc"),
|
|
|
|
as_background_job=False)
|
|
|
|
|
|
|
|
# The active object is probably the first one that was imported, but this
|
2023-08-25 00:56:58 +02:00
|
|
|
# behavior is not defined. At least it should be one of the cubes, and
|
2017-04-20 12:01:31 +02:00
|
|
|
# not the sphere.
|
|
|
|
self.assertNotEqual(sphere, bpy.context.active_object)
|
|
|
|
self.assertTrue('Cube' in bpy.context.active_object.name)
|
|
|
|
|
|
|
|
# All cubes should be selected, but the sphere shouldn't be.
|
|
|
|
for ob in bpy.data.objects:
|
2017-04-20 12:50:20 +02:00
|
|
|
self.assertEqual('Cube' in ob.name, ob.select_get())
|
2017-04-20 12:01:31 +02:00
|
|
|
|
2017-04-25 18:03:54 +02:00
|
|
|
def test_change_path_constraint(self):
|
2017-04-21 14:11:13 +02:00
|
|
|
fname = 'cube-rotating1.abc'
|
|
|
|
abc = self.testdir / fname
|
|
|
|
relpath = bpy.path.relpath(str(abc))
|
|
|
|
|
|
|
|
res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False)
|
|
|
|
self.assertEqual({'FINISHED'}, res)
|
|
|
|
cube = bpy.context.active_object
|
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
|
2017-04-21 14:11:13 +02:00
|
|
|
# Check that the file loaded ok.
|
|
|
|
bpy.context.scene.frame_set(10)
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
cube = depsgraph.id_eval_get(cube)
|
2017-04-21 14:11:13 +02:00
|
|
|
x, y, z = cube.matrix_world.to_euler('XYZ')
|
|
|
|
self.assertAlmostEqual(x, 0)
|
|
|
|
self.assertAlmostEqual(y, 0)
|
|
|
|
self.assertAlmostEqual(z, math.pi / 2, places=5)
|
|
|
|
|
|
|
|
# Change path from absolute to relative. This should not break the animation.
|
|
|
|
bpy.context.scene.frame_set(1)
|
|
|
|
bpy.data.cache_files[fname].filepath = relpath
|
|
|
|
bpy.context.scene.frame_set(10)
|
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
cube = depsgraph.id_eval_get(cube)
|
2017-04-21 14:11:13 +02:00
|
|
|
x, y, z = cube.matrix_world.to_euler('XYZ')
|
|
|
|
self.assertAlmostEqual(x, 0)
|
|
|
|
self.assertAlmostEqual(y, 0)
|
|
|
|
self.assertAlmostEqual(z, math.pi / 2, places=5)
|
|
|
|
|
|
|
|
# Replace the Alembic file; this should apply new animation.
|
|
|
|
bpy.data.cache_files[fname].filepath = relpath.replace('1.abc', '2.abc')
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
depsgraph.update()
|
2017-04-21 14:11:13 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
cube = depsgraph.id_eval_get(cube)
|
2017-04-21 14:11:13 +02:00
|
|
|
x, y, z = cube.matrix_world.to_euler('XYZ')
|
|
|
|
self.assertAlmostEqual(x, math.pi / 2, places=5)
|
|
|
|
self.assertAlmostEqual(y, 0)
|
|
|
|
self.assertAlmostEqual(z, 0)
|
|
|
|
|
2017-04-25 18:03:54 +02:00
|
|
|
def test_change_path_modifier(self):
|
|
|
|
fname = 'animated-mesh.abc'
|
|
|
|
abc = self.testdir / fname
|
|
|
|
relpath = bpy.path.relpath(str(abc))
|
|
|
|
|
|
|
|
res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False)
|
|
|
|
self.assertEqual({'FINISHED'}, res)
|
2017-08-09 13:59:27 +02:00
|
|
|
plane = bpy.context.active_object
|
2017-04-25 18:03:54 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
|
2017-04-25 18:03:54 +02:00
|
|
|
# Check that the file loaded ok.
|
|
|
|
bpy.context.scene.frame_set(6)
|
2017-08-09 15:06:50 +02:00
|
|
|
scene = bpy.context.scene
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
plane_eval = plane.evaluated_get(depsgraph)
|
|
|
|
mesh = plane_eval.to_mesh()
|
2017-08-09 13:59:27 +02:00
|
|
|
self.assertAlmostEqual(-1, mesh.vertices[0].co.x)
|
|
|
|
self.assertAlmostEqual(-1, mesh.vertices[0].co.y)
|
|
|
|
self.assertAlmostEqual(0.5905638933181763, mesh.vertices[0].co.z)
|
2019-05-16 13:49:21 +02:00
|
|
|
plane_eval.to_mesh_clear()
|
2017-04-25 18:03:54 +02:00
|
|
|
|
|
|
|
# Change path from absolute to relative. This should not break the animation.
|
2017-08-09 15:06:50 +02:00
|
|
|
scene.frame_set(1)
|
2017-04-25 18:03:54 +02:00
|
|
|
bpy.data.cache_files[fname].filepath = relpath
|
2017-08-09 15:06:50 +02:00
|
|
|
scene.frame_set(6)
|
2017-04-25 18:03:54 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
plane_eval = plane.evaluated_get(depsgraph)
|
|
|
|
mesh = plane_eval.to_mesh()
|
2017-08-09 13:59:27 +02:00
|
|
|
self.assertAlmostEqual(1, mesh.vertices[3].co.x)
|
|
|
|
self.assertAlmostEqual(1, mesh.vertices[3].co.y)
|
|
|
|
self.assertAlmostEqual(0.5905638933181763, mesh.vertices[3].co.z)
|
2019-05-16 13:49:21 +02:00
|
|
|
plane_eval.to_mesh_clear()
|
2017-04-25 18:03:54 +02:00
|
|
|
|
2017-04-25 12:05:55 +02:00
|
|
|
def test_import_long_names(self):
|
|
|
|
# This file contains very long names. The longest name is 4047 chars.
|
|
|
|
bpy.ops.wm.alembic_import(
|
|
|
|
filepath=str(self.testdir / "long-names.abc"),
|
|
|
|
as_background_job=False)
|
|
|
|
|
|
|
|
self.assertIn('Cube', bpy.data.objects)
|
|
|
|
self.assertEqual('CubeShape', bpy.data.objects['Cube'].data.name)
|
|
|
|
|
2017-04-19 17:27:40 +02:00
|
|
|
|
2017-05-23 17:27:09 +02:00
|
|
|
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.
|
2017-10-17 10:59:02 +02:00
|
|
|
self.assertAlmostEqualFloatArray(layer.data[0].color, (0, 0, 0, 1.0))
|
|
|
|
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))
|
2017-05-23 17:27:09 +02:00
|
|
|
|
|
|
|
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.
|
2017-10-17 10:59:02 +02:00
|
|
|
self.assertAlmostEqualFloatArray(layer.data[0].color, (1.0, 0.0156862, 0.3607843, 1.0))
|
|
|
|
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))
|
2017-05-23 17:27:09 +02:00
|
|
|
|
|
|
|
|
2020-02-14 15:21:19 +01:00
|
|
|
class CameraExportImportTest(unittest.TestCase):
|
|
|
|
names = [
|
|
|
|
'CAM_Unit_Transform',
|
|
|
|
'CAM_Look_+Y',
|
|
|
|
'CAM_Static_Child_Left',
|
|
|
|
'CAM_Static_Child_Right',
|
|
|
|
'Static_Child',
|
|
|
|
'CAM_Animated',
|
|
|
|
'CAM_Animated_Child_Left',
|
|
|
|
'CAM_Animated_Child_Right',
|
|
|
|
'Animated_Child',
|
|
|
|
]
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self._tempdir = tempfile.TemporaryDirectory()
|
|
|
|
self.tempdir = pathlib.Path(self._tempdir.name)
|
|
|
|
|
|
|
|
def tearDown(self):
|
2020-02-17 10:44:24 +01:00
|
|
|
# Unload the current blend file to release the imported Alembic file.
|
|
|
|
# This is necessary on Windows in order to be able to delete the
|
|
|
|
# temporary ABC file.
|
2023-07-25 13:14:50 +02:00
|
|
|
bpy.ops.wm.read_homefile(use_empty=True, use_factory_startup=True)
|
2020-02-14 15:21:19 +01:00
|
|
|
self._tempdir.cleanup()
|
|
|
|
|
|
|
|
def test_export_hierarchy(self):
|
|
|
|
self.do_export_import_test(flatten=False)
|
|
|
|
|
|
|
|
# Double-check that the export was hierarchical.
|
|
|
|
objects = bpy.context.scene.collection.objects
|
|
|
|
for name in self.names:
|
|
|
|
if 'Child' in name:
|
|
|
|
self.assertIsNotNone(objects[name].parent)
|
|
|
|
else:
|
|
|
|
self.assertIsNone(objects[name].parent)
|
|
|
|
|
|
|
|
def test_export_flattened(self):
|
|
|
|
self.do_export_import_test(flatten=True)
|
|
|
|
|
|
|
|
# Double-check that the export was flat.
|
|
|
|
objects = bpy.context.scene.collection.objects
|
|
|
|
for name in self.names:
|
|
|
|
self.assertIsNone(objects[name].parent)
|
|
|
|
|
|
|
|
def do_export_import_test(self, *, flatten: bool):
|
|
|
|
bpy.ops.wm.open_mainfile(filepath=str(args.testdir / "camera_transforms.blend"))
|
|
|
|
|
|
|
|
abc_path = self.tempdir / "camera_transforms.abc"
|
|
|
|
self.assertIn('FINISHED', bpy.ops.wm.alembic_export(
|
|
|
|
filepath=str(abc_path),
|
|
|
|
flatten=flatten,
|
|
|
|
))
|
|
|
|
|
|
|
|
# Re-import what we just exported into an empty file.
|
|
|
|
bpy.ops.wm.open_mainfile(filepath=str(args.testdir / "empty.blend"))
|
|
|
|
self.assertIn('FINISHED', bpy.ops.wm.alembic_import(filepath=str(abc_path)))
|
|
|
|
|
|
|
|
# Test that the import was ok.
|
|
|
|
bpy.context.scene.frame_set(1)
|
|
|
|
self.loc_rot_scale('CAM_Unit_Transform', (0, 0, 0), (0, 0, 0))
|
|
|
|
|
|
|
|
self.loc_rot_scale('CAM_Look_+Y', (2, 0, 0), (90, 0, 0))
|
|
|
|
self.loc_rot_scale('CAM_Static_Child_Left', (2 - 0.15, 0, 0), (90, 0, 0))
|
|
|
|
self.loc_rot_scale('CAM_Static_Child_Right', (2 + 0.15, 0, 0), (90, 0, 0))
|
|
|
|
self.loc_rot_scale('Static_Child', (2, 0, 1), (90, 0, 0))
|
|
|
|
|
|
|
|
self.loc_rot_scale('CAM_Animated', (4, 0, 0), (90, 0, 0))
|
|
|
|
self.loc_rot_scale('CAM_Animated_Child_Left', (4 - 0.15, 0, 0), (90, 0, 0))
|
|
|
|
self.loc_rot_scale('CAM_Animated_Child_Right', (4 + 0.15, 0, 0), (90, 0, 0))
|
|
|
|
self.loc_rot_scale('Animated_Child', (4, 0, 1), (90, 0, 0))
|
|
|
|
|
|
|
|
bpy.context.scene.frame_set(10)
|
|
|
|
|
|
|
|
self.loc_rot_scale('CAM_Animated', (4, 1, 2), (90, 0, 25))
|
|
|
|
self.loc_rot_scale('CAM_Animated_Child_Left', (3.864053, 0.936607, 2), (90, 0, 25))
|
|
|
|
self.loc_rot_scale('CAM_Animated_Child_Right', (4.135946, 1.063392, 2), (90, 0, 25))
|
|
|
|
self.loc_rot_scale('Animated_Child', (4, 1, 3), (90, -45, 25))
|
|
|
|
|
|
|
|
def loc_rot_scale(self, name: str, expect_loc, expect_rot_deg):
|
|
|
|
"""Assert world loc/rot/scale is OK."""
|
|
|
|
|
|
|
|
objects = bpy.context.scene.collection.objects
|
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
ob_eval = objects[name].evaluated_get(depsgraph)
|
|
|
|
|
|
|
|
actual_loc = ob_eval.matrix_world.to_translation()
|
|
|
|
actual_rot = ob_eval.matrix_world.to_euler('XYZ')
|
|
|
|
actual_scale = ob_eval.matrix_world.to_scale()
|
|
|
|
|
2020-02-17 10:44:24 +01:00
|
|
|
# Precision of the 'almost equal' comparisons.
|
|
|
|
delta_loc = delta_scale = 1e-6
|
|
|
|
delta_rot = math.degrees(1e-6)
|
2020-02-14 15:21:19 +01:00
|
|
|
|
2020-02-17 10:44:24 +01:00
|
|
|
self.assertAlmostEqual(expect_loc[0], actual_loc.x, delta=delta_loc)
|
|
|
|
self.assertAlmostEqual(expect_loc[1], actual_loc.y, delta=delta_loc)
|
|
|
|
self.assertAlmostEqual(expect_loc[2], actual_loc.z, delta=delta_loc)
|
|
|
|
|
|
|
|
self.assertAlmostEqual(expect_rot_deg[0], math.degrees(actual_rot.x), delta=delta_rot)
|
|
|
|
self.assertAlmostEqual(expect_rot_deg[1], math.degrees(actual_rot.y), delta=delta_rot)
|
|
|
|
self.assertAlmostEqual(expect_rot_deg[2], math.degrees(actual_rot.z), delta=delta_rot)
|
2020-02-14 15:21:19 +01:00
|
|
|
|
|
|
|
# This test doesn't use scale.
|
2020-02-17 10:44:24 +01:00
|
|
|
self.assertAlmostEqual(1, actual_scale.x, delta=delta_scale)
|
|
|
|
self.assertAlmostEqual(1, actual_scale.y, delta=delta_scale)
|
|
|
|
self.assertAlmostEqual(1, actual_scale.z, delta=delta_scale)
|
2020-02-14 15:21:19 +01:00
|
|
|
|
|
|
|
|
Alembic: add support for reading override layers
Override layers are a standard feature of Alembic, where archives can override
data from other archives, provided that the hierarchies match.
This is useful for modifying a UV map, updating an animation, or even creating
some sort of LOD system where low resolution meshes are swapped by high resolution
versions.
It is possible to add UV maps and vertex colors using this system, however, they
will only appear in the spreadsheet editor when viewing evaluated data, as the UV
map and Vertex color UI only show data present on the original mesh.
Implementation wise, this adds a `CacheFileLayer` data structure to the `CacheFile`
DNA, as well as some operators and UI to present and manage the layers. For both
the Alembic importer and the Cycles procedural, the main change is creating an
archive from a list of filepaths, instead of a single one.
After importing the base file through the regular import operator, layers can be added
to or removed from the `CacheFile` via the UI list under the `Override Layers` panel
located in the Mesh Sequence Cache modifier. Layers can also be moved around or
hidden.
See differential page for tests files and demos.
Reviewed by: brecht, sybren
Differential Revision: https://developer.blender.org/D13603
2022-01-17 14:50:47 +01:00
|
|
|
class OverrideLayersTest(AbstractAlembicTest):
|
|
|
|
def test_import_layer(self):
|
|
|
|
fname = 'cube-base-file.abc'
|
|
|
|
fname_layer = 'cube-hi-res.abc'
|
|
|
|
abc = self.testdir / fname
|
|
|
|
abc_layer = self.testdir / fname_layer
|
|
|
|
|
|
|
|
# We need a cache reader to ensure that the data will be updated after adding a layer.
|
|
|
|
res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False, always_add_cache_reader=True)
|
|
|
|
self.assertEqual({'FINISHED'}, res)
|
|
|
|
|
|
|
|
# Check that the file loaded ok.
|
|
|
|
cube = bpy.context.active_object
|
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
scene = bpy.context.scene
|
|
|
|
cube_eval = cube.evaluated_get(depsgraph)
|
|
|
|
mesh = cube_eval.to_mesh()
|
|
|
|
|
|
|
|
# The base file should be a default cube.
|
|
|
|
self.assertEqual(len(mesh.vertices), 8)
|
|
|
|
self.assertEqual(len(mesh.edges), 12)
|
|
|
|
self.assertEqual(len(mesh.polygons), 6)
|
|
|
|
|
|
|
|
# Add a layer.
|
|
|
|
cache_file = bpy.data.cache_files[fname]
|
|
|
|
self.assertEqual(len(cache_file.layers), 0)
|
|
|
|
|
|
|
|
layer = cache_file.layers.new(filepath=str(abc_layer))
|
|
|
|
self.assertEqual(len(cache_file.layers), 1)
|
|
|
|
self.assertIsNotNone(layer)
|
|
|
|
|
|
|
|
# The layer added a higher res version of the mesh.
|
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
cube_eval = cube.evaluated_get(depsgraph)
|
|
|
|
mesh = cube_eval.to_mesh()
|
|
|
|
self.assertEqual(len(mesh.vertices), 26)
|
|
|
|
self.assertEqual(len(mesh.edges), 48)
|
|
|
|
self.assertEqual(len(mesh.polygons), 24)
|
|
|
|
|
|
|
|
# Remove the layer.
|
|
|
|
cache_file.layers.remove(layer)
|
|
|
|
self.assertEqual(len(cache_file.layers), 0)
|
|
|
|
|
|
|
|
# We should have reverted to the default cube.
|
|
|
|
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
|
|
cube_eval = cube.evaluated_get(depsgraph)
|
|
|
|
mesh = cube_eval.to_mesh()
|
|
|
|
self.assertEqual(len(mesh.vertices), 8)
|
|
|
|
self.assertEqual(len(mesh.edges), 12)
|
|
|
|
self.assertEqual(len(mesh.polygons), 6)
|
|
|
|
|
|
|
|
|
2017-04-19 17:27:40 +02:00
|
|
|
def main():
|
|
|
|
global args
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
if '--' in sys.argv:
|
2017-06-12 05:35:00 +02:00
|
|
|
argv = [sys.argv[0]] + sys.argv[sys.argv.index('--') + 1:]
|
2017-04-19 17:27:40 +02:00
|
|
|
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__":
|
2020-04-27 17:43:47 +02:00
|
|
|
main()
|