[Bf-blender-cvs] [d92863a] alembic_basic_io: Fix some hierarchical issues.
Kévin Dietrich
noreply at git.blender.org
Mon Jul 4 18:22:48 CEST 2016
Commit: d92863a77153ecf6138ac42e3856cb975fd19301
Author: Kévin Dietrich
Date: Mon Jul 4 08:25:22 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rBd92863a77153ecf6138ac42e3856cb975fd19301
Fix some hierarchical issues.
This fixes the rare issue found in some Maya and Unity files, where an
object would still be scaled even though it has a parent which was
already scaled.
===================================================================
M source/blender/alembic/intern/abc_object.cc
M source/blender/alembic/intern/abc_util.cc
M source/blender/alembic/intern/abc_util.h
===================================================================
diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index ac80e08..ad275ba 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -131,7 +131,13 @@ AbcObjectReader::AbcObjectReader(const IObject &object, ImportSettings &settings
std::vector<std::string> parts;
split(m_name, '/', parts);
- m_object_name = m_data_name = parts[parts.size() - 1];
+ if (parts.size() >= 2) {
+ m_object_name = parts[parts.size() - 2];
+ m_data_name = parts[parts.size() - 1];
+ }
+ else {
+ m_object_name = m_data_name = parts[parts.size() - 1];
+ }
}
AbcObjectReader::~AbcObjectReader()
@@ -150,13 +156,34 @@ Object *AbcObjectReader::object() const
void AbcObjectReader::readObjectMatrix(const float time)
{
IXform ixform;
+ bool has_alembic_parent = false;
+ /* Check that we have an empty object (locator, bone head/tail...). */
if (IXform::matches(m_iobject.getMetaData())) {
ixform = IXform(m_iobject, Alembic::AbcGeom::kWrapExisting);
+
+ /* See comment below. */
+ has_alembic_parent = m_iobject.getParent().getParent().valid();
}
+ /* Check that we have an object with actual data. */
else if (IXform::matches(m_iobject.getParent().getMetaData())) {
ixform = IXform(m_iobject.getParent(), Alembic::AbcGeom::kWrapExisting);
+
+ /* This is a bit hackish, but we need to make sure that extra
+ * transformations added to the matrix (rotation/scale) are only applied
+ * to root objects. The way objects and their hierarchy are created will
+ * need to be revisited at some point but for now this seems to do the
+ * trick.
+ *
+ * Explanation of the trick:
+ * The first getParent() will return this object's transformation matrix.
+ * The second getParent() will get the parent of the transform, but this
+ * might be the archive root ('/') which is valid, so we go passed it to
+ * make sure that there is no parent.
+ */
+ has_alembic_parent = m_iobject.getParent().getParent().getParent().valid();
}
+ /* Should not happen. */
else {
return;
}
@@ -171,7 +198,7 @@ void AbcObjectReader::readObjectMatrix(const float time)
Alembic::AbcGeom::XformSample xs;
schema.get(xs, sample_sel);
- create_input_transform(sample_sel, ixform, m_object, m_object->obmat, m_settings->scale);
+ create_input_transform(sample_sel, ixform, m_object, m_object->obmat, m_settings->scale, has_alembic_parent);
invert_m4_m4(m_object->imat, m_object->obmat);
diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc
index a9e11f9..89969dd 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -204,7 +204,7 @@ void create_transform_matrix(float r_mat[4][4])
void create_input_transform(const Alembic::AbcGeom::ISampleSelector &sample_sel,
const Alembic::AbcGeom::IXform &ixform, Object *ob,
- float r_mat[4][4], float scale)
+ float r_mat[4][4], float scale, bool has_alembic_parent)
{
const Alembic::AbcGeom::IXformSchema &ixform_schema = ixform.getSchema();
@@ -230,7 +230,8 @@ void create_input_transform(const Alembic::AbcGeom::ISampleSelector &sample_sel,
if (ob->parent) {
mul_m4_m4m4(r_mat, ob->parent->obmat, r_mat);
}
- else {
+ /* TODO(kevin) */
+ else if (!has_alembic_parent) {
/* Only apply scaling to root objects, parenting will propagate it. */
float scale_mat[4][4];
scale_m4_fl(scale_mat, scale);
diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h
index 4cc91b5..b2ab046 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -52,7 +52,7 @@ bool begins_with(const TContainer &input, const TContainer &match)
void create_input_transform(const Alembic::AbcGeom::ISampleSelector &sample_sel,
const Alembic::AbcGeom::IXform &ixform, Object *ob,
- float r_mat[4][4], float scale);
+ float r_mat[4][4], float scale, bool has_alembic_parent = false);
template <typename Schema>
void get_min_max_time(const Schema &schema, chrono_t &min, chrono_t &max)
More information about the Bf-blender-cvs
mailing list