Alembic: constraint for transform animation is using world matrix again

In rB7c5a44c71f13 I changed the way transform matrices are loaded from
Alembic. Instead of having the Alembic importer convert matrices from
local (in the Alembic file) to World (to pass to the constraint handling
the animation of transforms), I set the constraint space to
`CONSTRAINT_SPACE_LOCAL`.

This worked thanks to rB7728bfd4c45c. However, that commit was reverted,
which meant that for parentless objects `CONSTRAINT_SPACE_LOCAL` no
longer means "local space".

The situation is resolved by setting the constraint to world space
again, and computing the world matrix in the Alembic importer.
This commit is contained in:
Sybren A. Stüvel 2020-03-09 18:22:49 +01:00
parent e672cf11c3
commit b080de79db
4 changed files with 34 additions and 6 deletions

View File

@ -5314,9 +5314,6 @@ static bConstraint *add_new_constraint(Object *ob,
}
break;
}
case CONSTRAINT_TYPE_TRANSFORM_CACHE:
con->ownspace = CONSTRAINT_SPACE_LOCAL;
break;
}
return con;

View File

@ -4802,5 +4802,14 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
/* Alembic Transform Cache changed from local to world space. */
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
LISTBASE_FOREACH (bConstraint *, con, &ob->constraints) {
if (con->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
con->ownspace = CONSTRAINT_SPACE_WORLD;
}
}
}
}
}

View File

@ -110,7 +110,10 @@ AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
void ABC_free_handle(AbcArchiveHandle *handle);
void ABC_get_transform(struct CacheReader *reader, float r_mat[4][4], float time, float scale);
void ABC_get_transform(struct CacheReader *reader,
float r_mat_world[4][4],
float time,
float scale);
/* Either modifies current_mesh in-place or constructs a new mesh. */
struct Mesh *ABC_read_mesh(struct CacheReader *reader,

View File

@ -53,6 +53,7 @@ extern "C" {
#include "BKE_global.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "DEG_depsgraph.h"
@ -931,7 +932,7 @@ bool ABC_import(bContext *C,
/* ************************************************************************** */
void ABC_get_transform(CacheReader *reader, float r_mat[4][4], float time, float scale)
void ABC_get_transform(CacheReader *reader, float r_mat_world[4][4], float time, float scale)
{
if (!reader) {
return;
@ -940,7 +941,25 @@ void ABC_get_transform(CacheReader *reader, float r_mat[4][4], float time, float
AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
bool is_constant = false;
abc_reader->read_matrix(r_mat, time, scale, is_constant);
/* Convert from the local matrix we obtain from Alembic to world coordinates
* for Blender. This conversion is done here rather than by Blender due to
* work around the non-standard interpretation of CONSTRAINT_SPACE_LOCAL in
* BKE_constraint_mat_convertspace(). */
Object *object = abc_reader->object();
if (object->parent == nullptr) {
/* No parent, so local space is the same as world space. */
abc_reader->read_matrix(r_mat_world, time, scale, is_constant);
return;
}
float mat_parent[4][4];
BKE_object_get_parent_matrix(object, object->parent, mat_parent);
float mat_local[4][4];
abc_reader->read_matrix(mat_local, time, scale, is_constant);
mul_m4_m4m4(r_mat_world, mat_parent, object->parentinv);
mul_m4_m4m4(r_mat_world, r_mat_world, mat_local);
}
/* ************************************************************************** */