Alembic export: fixed exporting as "flat"
This exports all objects in world coordinates without parenting.
This commit is contained in:
@@ -374,7 +374,9 @@ void AbcExporter::createTransformWritersFlat()
|
|||||||
|
|
||||||
if (export_object(&m_settings, ob) && object_is_shape(ob)) {
|
if (export_object(&m_settings, ob) && object_is_shape(ob)) {
|
||||||
std::string name = get_id_name(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;
|
base = base->next;
|
||||||
|
@@ -71,6 +71,9 @@ AbcTransformWriter::AbcTransformWriter(Object *ob,
|
|||||||
|
|
||||||
m_xform = OXform(abc_parent, get_id_name(m_object), time_sampling);
|
m_xform = OXform(abc_parent, get_id_name(m_object), time_sampling);
|
||||||
m_schema = m_xform.getSchema();
|
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()
|
void AbcTransformWriter::do_write()
|
||||||
@@ -86,20 +89,18 @@ void AbcTransformWriter::do_write()
|
|||||||
}
|
}
|
||||||
|
|
||||||
float yup_mat[4][4];
|
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. */
|
/* 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];
|
float rot_mat[4][4];
|
||||||
axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
|
axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
|
||||||
mul_m4_m4m4(yup_mat, yup_mat, rot_mat);
|
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. */
|
/* 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];
|
float scale_mat[4][4];
|
||||||
scale_m4_fl(scale_mat, m_settings.global_scale);
|
scale_m4_fl(scale_mat, m_settings.global_scale);
|
||||||
scale_mat[3][3] = m_settings.global_scale; /* also scale translation */
|
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_matrix = convert_matrix(yup_mat);
|
||||||
m_sample.setMatrix(m_matrix);
|
m_sample.setMatrix(m_matrix);
|
||||||
|
m_sample.setInheritsXforms(m_inherits_xform);
|
||||||
m_schema.set(m_sample);
|
m_schema.set(m_sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@ class AbcTransformWriter : public AbcObjectWriter {
|
|||||||
|
|
||||||
bool m_is_animated;
|
bool m_is_animated;
|
||||||
bool m_visible;
|
bool m_visible;
|
||||||
|
bool m_inherits_xform;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AbcTransformWriter(Object *ob,
|
AbcTransformWriter(Object *ob,
|
||||||
|
@@ -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
|
/* Recompute transform matrix of object in new coordinate system
|
||||||
* (from Z-Up to Y-Up). */
|
* (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];
|
float zup_mat[4][4];
|
||||||
|
|
||||||
/* get local matrix. */
|
/* get local or world matrix. */
|
||||||
/* TODO Sybren: when we're exporting as "flat", i.e. non-hierarchial,
|
if (mode == ABC_MATRIX_LOCAL && obj->parent) {
|
||||||
* we should export the world matrix even when the object has a parent
|
|
||||||
* Blender Object. */
|
|
||||||
if (obj->parent) {
|
|
||||||
/* Note that this produces another matrix than the local matrix, due to
|
/* Note that this produces another matrix than the local matrix, due to
|
||||||
* constraints and modifiers as well as the obj->parentinv matrix. */
|
* constraints and modifiers as well as the obj->parentinv matrix. */
|
||||||
invert_m4_m4(obj->parent->imat, obj->parent->obmat);
|
invert_m4_m4(obj->parent->imat, obj->parent->obmat);
|
||||||
|
@@ -57,7 +57,12 @@ bool object_selected(Object *ob);
|
|||||||
bool parent_selected(Object *ob);
|
bool parent_selected(Object *ob);
|
||||||
|
|
||||||
Imath::M44d convert_matrix(float mat[4][4]);
|
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);
|
void split(const std::string &s, const char delim, std::vector<std::string> &tokens);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user