[Bf-blender-cvs] [31b8b2a] alembic_basic_io: Revert changes done to the transform matrix read/write and axis conversion code to the state of the original patch.

Kévin Dietrich noreply at git.blender.org
Thu May 26 17:29:54 CEST 2016


Commit: 31b8b2aae2c8cf2e9b62b8991b04c4d2e06a22cb
Author: Kévin Dietrich
Date:   Thu May 26 14:38:45 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB31b8b2aae2c8cf2e9b62b8991b04c4d2e06a22cb

Revert changes done to the transform matrix read/write and axis
conversion code to the state of the original patch.

The rewrite wasn't ideal, and prone to bugs. The idea was to not
hardcode Y-up <-> Z-up conversions but rather let the user choose the
axis during the export/import process, but since the other DCCs commonly
found in VFX pipeline all use a Y-up system, hardcoding everything
should be fine for the time being. This will probably be revisited in
the future if need be.

===================================================================

M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/abc_hair.cc
M	source/blender/alembic/intern/abc_mesh.cc
M	source/blender/alembic/intern/abc_nurbs.cc
M	source/blender/alembic/intern/abc_object.cc
M	source/blender/alembic/intern/abc_transform.cc
M	source/blender/alembic/intern/abc_util.cc
M	source/blender/alembic/intern/abc_util.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/editors/io/io_alembic.c
M	source/blender/makesrna/intern/rna_scene_api.c

===================================================================

diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index db43c87..3fb2320 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -51,9 +51,9 @@ int ABC_export(struct Scene *scene, struct bContext *C, const char *filename,
                int vislayers, int renderable,
                int facesets, int matindices,
                int geogroups, int compression,
-               bool packuv, int to_forward, int to_up, float scale);
+               bool packuv, float scale);
 
-void ABC_import(struct bContext *C, const char *filename, int from_forward, int from_up, float scale);
+void ABC_import(struct bContext *C, const char *filename, float scale);
 
 void ABC_get_vertex_cache(const char *filepath, float time, void *verts, int max_verts, const char *sub_obj, int is_mvert);
 
diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc
index 69da382..b830b7c 100644
--- a/source/blender/alembic/intern/abc_hair.cc
+++ b/source/blender/alembic/intern/abc_hair.cc
@@ -159,11 +159,8 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm,
 
 					psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL, NULL);
 
-					if (m_settings.do_convert_axis) {
-						mul_m3_v3(m_settings.convert_matrix, tmpnor);
-					}
-
-					norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[1], tmpnor[2]));
+					/* Convert Z-up to Y-up. */
+					norm_values.push_back(Imath::V3f(tmpnor[0], -tmpnor[2], tmpnor[1]));
 				}
 			}
 			else {
@@ -214,11 +211,8 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm,
 			copy_v3_v3(vert, path->co);
 			mul_m4_v3(inv_mat, vert);
 
-			if (m_settings.do_convert_axis) {
-				mul_m3_v3(m_settings.convert_matrix, vert);
-			}
-
-			verts.push_back(Imath::V3f(vert[0], vert[1], vert[2]));
+			/* Convert Z-up to Y-up. */
+			verts.push_back(Imath::V3f(vert[0], vert[2], -vert[1]));
 
 			++path;
 		}
@@ -266,11 +260,8 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm,
 
 				psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL, NULL);
 
-				if (m_settings.do_convert_axis) {
-					mul_m3_v3(m_settings.convert_matrix, tmpnor);
-				}
-
-				norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[1], tmpnor[2]));
+				/* Convert Z-up to Y-up. */
+				norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[2], -tmpnor[1]));
 			}
 		}
 
@@ -282,11 +273,8 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm,
 			copy_v3_v3(vert, path->co);
 			mul_m4_v3(inv_mat, vert);
 
-			if (m_settings.do_convert_axis) {
-				mul_m3_v3(m_settings.convert_matrix, vert);
-			}
-
-			verts.push_back(Imath::V3f(vert[0], vert[1], vert[2]));
+			/* Convert Z-up to Y-up. */
+			verts.push_back(Imath::V3f(vert[0], vert[2], -vert[1]));
 
 			++path;
 		}
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index 85bad65..7c7b561 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -452,23 +452,11 @@ void AbcMeshWriter::getPoints(DerivedMesh *dm, std::vector<float> &points)
 
 	MVert *verts = dm->getVertArray(dm);
 
-	if (m_settings.do_convert_axis) {
-		float vert[3];
-
-		for (int i = 0, e = dm->getNumVerts(dm); i < e; ++i) {
-			copy_v3_v3(vert, verts[i].co);
-			mul_m3_v3(m_settings.convert_matrix, vert);
-			points.push_back(vert[0]);
-			points.push_back(vert[1]);
-			points.push_back(vert[2]);
-		}
-	}
-	else {
-		for (int i = 0, e = dm->getNumVerts(dm); i < e; ++i) {
-			points.push_back(verts[i].co[0]);
-			points.push_back(verts[i].co[1]);
-			points.push_back(verts[i].co[2]);
-		}
+	for (int i = 0, e = dm->getNumVerts(dm); i < e; ++i) {
+		/* Convert Z-up to Y-up. */
+		points.push_back(verts[i].co[0]);
+		points.push_back(verts[i].co[2]);
+		points.push_back(-verts[i].co[1]);
 	}
 
 	calcBounds(points);
@@ -907,27 +895,16 @@ void AbcMeshWriter::getVelocities(DerivedMesh *dm, std::vector<float> &vels)
 
 	if (fss->meshVelocities) {
 		float *meshVels = reinterpret_cast<float *>(fss->meshVelocities);
+		float vel[3];
 
-		if (m_settings.do_convert_axis) {
-			float vel[3];
-
-			for (int i = 0; i < totverts; ++i) {
-				copy_v3_v3(vel, meshVels);
-				mul_m3_v3(m_settings.convert_matrix, vel);
+		for (int i = 0; i < totverts; ++i) {
+			copy_v3_v3(vel, meshVels);
 
-				vels.push_back(vels[0]);
-				vels.push_back(vels[1]);
-				vels.push_back(vels[2]);
-				meshVels += 3;
-			}
-		}
-		else {
-			{
-				vels.push_back(meshVels[0]);
-				vels.push_back(meshVels[1]);
-				vels.push_back(meshVels[2]);
-				meshVels += 3;
-			}
+			/* Convert Z-up to Y-up. */
+			vels.push_back(vels[0]);
+			vels.push_back(vels[2]);
+			vels.push_back(-vels[1]);
+			meshVels += 3;
 		}
 	}
 	else {
@@ -1180,8 +1157,8 @@ void AbcMeshReader::readObjectData(Main *bmain, Scene *scene, float time)
 	MeshCacheModifierData *mcmd = reinterpret_cast<MeshCacheModifierData *>(md);
 	mcmd->type = MOD_MESHCACHE_TYPE_ABC;
 	mcmd->time_mode = MOD_MESHCACHE_TIME_SECONDS;
-	mcmd->forward_axis = m_settings->from_forward;
-	mcmd->up_axis = m_settings->from_up;
+	mcmd->forward_axis = OB_POSZ;
+	mcmd->up_axis = OB_NEGY;
 
 	BLI_strncpy(mcmd->filepath, m_iobject.getArchive().getName().c_str(), 1024);
 	BLI_strncpy(mcmd->sub_object, m_iobject.getFullName().c_str(), 1024);
@@ -1198,19 +1175,12 @@ void AbcMeshReader::readVertexDataSample(Mesh *mesh, const P3fArraySamplePtr &po
 		MVert &mvert = mesh->mvert[j];
 		Imath::V3f pos_in = (*positions)[i];
 
+		/* Convert Y-up to Z-up. */
 		mvert.co[0] = pos_in[0];
-		mvert.co[1] = pos_in[1];
-		mvert.co[2] = pos_in[2];
-
+		mvert.co[1] = -pos_in[2];
+		mvert.co[2] = pos_in[1];
 		mvert.bweight = 0;
 	}
-
-	if (m_settings->do_convert_mat) {
-		for (int i = 0, j = vertex_start; i < vertex_count; ++i, ++j) {
-			MVert &mvert = mesh->mvert[j];
-			mul_m4_v3(m_settings->conversion_mat, mvert.co);
-		}
-	}
 }
 
 void AbcMeshReader::readPolyDataSample(Mesh *mesh,
diff --git a/source/blender/alembic/intern/abc_nurbs.cc b/source/blender/alembic/intern/abc_nurbs.cc
index 7760ba5..fd97f4f 100644
--- a/source/blender/alembic/intern/abc_nurbs.cc
+++ b/source/blender/alembic/intern/abc_nurbs.cc
@@ -103,8 +103,7 @@ static void recompute_pnts_cyclic(const BPoint *bps,
                                   const int num_u, const int num_v,
                                   const int add_u, const int add_v,
                                   std::vector<Imath::V3f> &pos,
-                                  std::vector<float> &posWeight,
-                                  bool rotate, float rot_mat[3][3])
+                                  std::vector<float> &posWeight)
 {
 	const int new_u = num_u;/* + add_u; */
 	const int new_v = num_v;/* + add_v; */
@@ -115,31 +114,23 @@ static void recompute_pnts_cyclic(const BPoint *bps,
 
 	std::vector< std::vector<Imath::Vec4<float> > > pnts;
 	pnts.resize(new_u);
+
 	for (int u = 0; u < new_u; ++u) {
 		pnts[u].resize(new_v);
 
-		if (rotate) {
-			for (int v = 0; v < new_v; ++v) {
-				const BPoint& bp = bps[u + (v * new_u)];
-				float vert[3];
-				copy_v3_v3(vert, bp.vec);
-				mul_m3_v3(rot_mat, vert);
-
-				pnts[u][v] = Imath::Vec4<float>(vert[0], vert[1], vert[2], bp.vec[3]);
-			}
-		}
-		else {
-			for (int v = 0; v < new_v; ++v) {
-				const BPoint& bp = bps[u + (v * new_u)];
-				pnts[u][v] = Imath::Vec4<float>(bp.vec[0], bp.vec[1], bp.vec[2], bp.vec[3]);
-			}
+		for (int v = 0; v < new_v; ++v) {
+			const BPoint& bp = bps[u + (v * new_u)];
+			pnts[u][v] = Imath::Vec4<float>(bp.vec[0], bp.vec[1], bp.vec[2], bp.vec[3]);
 		}
 	}
 
 	for (int u = 0; u < new_u; ++u) {
 		for (int v = 0; v < new_v; ++v) {
-			Imath::Vec4<float>& pnt = pnts[u][v];
-			pos.push_back(Imath::V3f(pnt.x, pnt.y, pnt.z));
+			const Imath::Vec4<float> &pnt = pnts[u][v];
+
+			/* Convert Z-up to Y-up. */
+			pos.push_back(Imath::V3f(pnt.x, pnt.z, -pnt.y));
+
 			posWeight.push_back(pnt.z);
 		}
 	}
@@ -193,8 +184,7 @@ void AbcNurbsWriter::do_write()
 		std::vector<Imath::V3f> sampPos;
 		std::vector<float> sampPosWeights;
 		recompute_pnts_cyclic(nu->bp, nu->pntsu, nu->pntsv, add_u, add_v,
-		                      sampPos, sampPosWeights,
-		                      m_settings.do_convert_axis, m_settings.convert_matrix);
+		                      sampPos, sampPosWeights);
 
 		nuSamp.setPositions(sampPos);
 		nuSamp.setPositionWeights(sampPosWeights);
@@ -281,14 +271,11 @@ void AbcNurbsReader::readObjectData(Main *bmain, Scene *scene, float time)
 				posw_in = (*positionsW)[i];
 			}
 
+			/* Convert Y-up to Z-up. */
 			nu->bp[i].vec[0] = pos_in[0];
-			nu->bp[i].vec[1] = pos_in[1];
-			nu->bp[i].vec[2] = pos_in[2];
+			nu->bp[i].vec[1] = -pos_in[2];
+			nu->bp[i].vec[2] = pos_in[1];
 			nu->bp[i].vec[3] = posw_in;
-
-			if (m_settings->do_convert_mat) {
-				mul_m4_v3(m_settings->conversion_mat, nu->bp[i].vec);
-			}
 		}
 
 		for (size_t i = 0; i < numKnotsU; i++) {
diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index fca0580..714a233 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -350,26 +350,33 @@ void AbcObjectReader::readObjectMatrix(const float time)
 		Alembic::AbcGeom::XformSample xs;
 		schema.get(xs, xform_sample);
 
-		float loc[3];
-		for (int i = 0; i < 3; ++i) {
-			loc[i] = xs.getTranslation()[i];
-			m_object->size[i] = xs.getScale()[i];
+		Alembic::Abc::M44d xfrom = xs.getMatrix();
+
+		for (int i = 0; i < 4; ++i) {
+            for (int j = 0; j < 4; j++) {
+                m_object->obmat[i][j] = xfrom[i][j];
+            }
+        }
+
+		if (m_object->type == OB_CAMERA) {
+			float cam_to_yup[4][4];
+			unit_m4(cam_to_yup);
+			rotate_m4(cam_to_yup, 'X', M_PI_2);
+			mul_m4_m4m4(m_object->obmat, m_object->obmat, cam_to_yup);
 		}
 
-		m_object->rot[0] = xs.getXRotation() * M_PI / 180;
-		m_object->rot[1] = xs.getYRotation() * M_PI / 180;
-		m_object->rot[2] = xs.getZRotation() * M_PI / 180;
+		create_transform_matrix(m_object);
 
-		if (m_settings->do_convert_mat) {
-			mul_v3_m4v3(m_object->loc, m_settings->conversion_mat, loc

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list