diff options
author | Alexander Romanov <a.romanov@blend4web.com> | 2017-04-13 13:02:39 +0300 |
---|---|---|
committer | Alexander Romanov <a.romanov@blend4web.com> | 2017-04-13 13:02:39 +0300 |
commit | 6f268ac55d834ca9ba098b321dc101fbba93d773 (patch) | |
tree | 6a18624d0c7940af708c69103322fdcaaf5126fc /source/blender/alembic | |
parent | 0a62e971b2413dee218f43e8ba01b14c3a005b7f (diff) | |
parent | f5bc8ad4ce87165fc0648f1cd8c0ae1fb5f07281 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/alembic')
-rw-r--r-- | source/blender/alembic/intern/abc_exporter.cc | 4 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_mesh.cc | 38 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_transform.cc | 14 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_transform.h | 1 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_util.cc | 9 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_util.h | 7 |
6 files changed, 46 insertions, 27 deletions
diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc index 61ad76b409c..1b218b98f21 100644 --- a/source/blender/alembic/intern/abc_exporter.cc +++ b/source/blender/alembic/intern/abc_exporter.cc @@ -370,7 +370,9 @@ void AbcExporter::createTransformWritersFlat() if (!export_object(&m_settings, base)) { 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); } } } diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc index 63c69cae8cd..a0b175dbcdc 100644 --- a/source/blender/alembic/intern/abc_mesh.cc +++ b/source/blender/alembic/intern/abc_mesh.cc @@ -896,19 +896,31 @@ static void *add_customdata_cb(void *user_data, const char *name, int data_type) { DerivedMesh *dm = static_cast<DerivedMesh *>(user_data); CustomDataType cd_data_type = static_cast<CustomDataType>(data_type); - void *cd_ptr = NULL; - - if (ELEM(cd_data_type, CD_MLOOPUV, CD_MLOOPCOL)) { - cd_ptr = CustomData_get_layer_named(dm->getLoopDataLayout(dm), cd_data_type, name); - - if (cd_ptr == NULL) { - cd_ptr = CustomData_add_layer_named(dm->getLoopDataLayout(dm), - cd_data_type, - CD_DEFAULT, - NULL, - dm->getNumLoops(dm), - name); - } + void *cd_ptr; + CustomData *loopdata; + int numloops; + + /* unsupported custom data type -- don't do anything. */ + if (!ELEM(cd_data_type, CD_MLOOPUV, CD_MLOOPCOL)) { + return NULL; + } + + loopdata = dm->getLoopDataLayout(dm); + cd_ptr = CustomData_get_layer_named(loopdata, cd_data_type, name); + if (cd_ptr != NULL) { + /* layer already exists, so just return it. */ + return cd_ptr; + } + + /* create a new layer, taking care to construct the hopefully-soon-to-be-removed + * CD_MTEXPOLY layer too, with the same name. */ + numloops = dm->getNumLoops(dm); + cd_ptr = CustomData_add_layer_named(loopdata, cd_data_type, CD_DEFAULT, + NULL, numloops, name); + if (cd_data_type == CD_MLOOPUV) { + CustomData_add_layer_named(dm->getPolyDataLayout(dm), + CD_MTEXPOLY, CD_DEFAULT, + NULL, numloops, name); } return cd_ptr; diff --git a/source/blender/alembic/intern/abc_transform.cc b/source/blender/alembic/intern/abc_transform.cc index cad1eae4764..2e626edeb8b 100644 --- a/source/blender/alembic/intern/abc_transform.cc +++ b/source/blender/alembic/intern/abc_transform.cc @@ -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); } diff --git a/source/blender/alembic/intern/abc_transform.h b/source/blender/alembic/intern/abc_transform.h index b55fa12dadf..714adc299c1 100644 --- a/source/blender/alembic/intern/abc_transform.h +++ b/source/blender/alembic/intern/abc_transform.h @@ -38,6 +38,7 @@ class AbcTransformWriter : public AbcObjectWriter { bool m_is_animated; bool m_visible; + bool m_inherits_xform; public: AbcTransformWriter(Object *ob, diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc index b99be718c18..4b2541c23c4 100644 --- a/source/blender/alembic/intern/abc_util.cc +++ b/source/blender/alembic/intern/abc_util.cc @@ -245,15 +245,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); diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h index 7217d5d5cef..9fdcf5e701b 100644 --- a/source/blender/alembic/intern/abc_util.h +++ b/source/blender/alembic/intern/abc_util.h @@ -57,7 +57,12 @@ std::string get_object_dag_path_name(const Object * const ob, Object *dupli_pare bool object_selected(const Base * const ob_base); 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); |