Alembic export: fixed exporting as "flat"

This exports all objects in world coordinates without parenting.
This commit is contained in:
Sybren A. Stüvel 2017-04-12 12:15:32 +02:00
parent de3c98d62b
commit 642728b339
5 changed files with 21 additions and 14 deletions

View File

@ -374,7 +374,9 @@ void AbcExporter::createTransformWritersFlat()
if (export_object(&m_settings, ob) && object_is_shape(ob)) {
std::string name = get_id_name(ob);
m_xforms[name] = new AbcTransformWriter(ob, m_writer->archive().getTop(), 0, m_trans_sampling_index, m_settings);
m_xforms[name] = new AbcTransformWriter(
ob, m_writer->archive().getTop(), NULL,
m_trans_sampling_index, m_settings);
}
base = base->next;

View File

@ -71,6 +71,9 @@ AbcTransformWriter::AbcTransformWriter(Object *ob,
m_xform = OXform(abc_parent, get_id_name(m_object), time_sampling);
m_schema = m_xform.getSchema();
/* Blender objects can't have a parent without inheriting the transform. */
m_inherits_xform = parent != NULL;
}
void AbcTransformWriter::do_write()
@ -86,20 +89,18 @@ void AbcTransformWriter::do_write()
}
float yup_mat[4][4];
create_transform_matrix(m_object, yup_mat);
create_transform_matrix(m_object, yup_mat,
m_inherits_xform ? ABC_MATRIX_LOCAL : ABC_MATRIX_WORLD);
/* Only apply rotation to root camera, parenting will propagate it. */
if (m_object->type == OB_CAMERA && !has_parent_camera(m_object)) {
if (m_object->type == OB_CAMERA && (!m_inherits_xform || !has_parent_camera(m_object))) {
float rot_mat[4][4];
axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
mul_m4_m4m4(yup_mat, yup_mat, rot_mat);
}
if (!m_object->parent) {
if (!m_object->parent || !m_inherits_xform) {
/* Only apply scaling to root objects, parenting will propagate it. */
/* TODO Sybren: when we're exporting as "flat", i.e. non-hierarchial,
* we should apply the scale even when the object has a parent
* Blender Object. */
float scale_mat[4][4];
scale_m4_fl(scale_mat, m_settings.global_scale);
scale_mat[3][3] = m_settings.global_scale; /* also scale translation */
@ -108,6 +109,7 @@ void AbcTransformWriter::do_write()
m_matrix = convert_matrix(yup_mat);
m_sample.setMatrix(m_matrix);
m_sample.setInheritsXforms(m_inherits_xform);
m_schema.set(m_sample);
}

View File

@ -38,6 +38,7 @@ class AbcTransformWriter : public AbcObjectWriter {
bool m_is_animated;
bool m_visible;
bool m_inherits_xform;
public:
AbcTransformWriter(Object *ob,

View File

@ -257,15 +257,12 @@ void convert_matrix(const Imath::M44d &xform, Object *ob, float r_mat[4][4])
/* Recompute transform matrix of object in new coordinate system
* (from Z-Up to Y-Up). */
void create_transform_matrix(Object *obj, float r_yup_mat[4][4])
void create_transform_matrix(Object *obj, float r_yup_mat[4][4], AbcMatrixMode mode)
{
float zup_mat[4][4];
/* get local matrix. */
/* TODO Sybren: when we're exporting as "flat", i.e. non-hierarchial,
* we should export the world matrix even when the object has a parent
* Blender Object. */
if (obj->parent) {
/* get local or world matrix. */
if (mode == ABC_MATRIX_LOCAL && obj->parent) {
/* Note that this produces another matrix than the local matrix, due to
* constraints and modifiers as well as the obj->parentinv matrix. */
invert_m4_m4(obj->parent->imat, obj->parent->obmat);

View File

@ -57,7 +57,12 @@ bool object_selected(Object *ob);
bool parent_selected(Object *ob);
Imath::M44d convert_matrix(float mat[4][4]);
void create_transform_matrix(Object *obj, float r_transform_mat[4][4]);
typedef enum {
ABC_MATRIX_WORLD = 1,
ABC_MATRIX_LOCAL = 2,
} AbcMatrixMode;
void create_transform_matrix(Object *obj, float r_transform_mat[4][4], AbcMatrixMode mode);
void split(const std::string &s, const char delim, std::vector<std::string> &tokens);