[Bf-blender-cvs] [44d9f3a] alembic_basic_io: Import: add UI params to setup forward and up axises.

Kévin Dietrich noreply at git.blender.org
Tue Mar 29 10:02:25 CEST 2016


Commit: 44d9f3a73bbaeb08a4aa9f8b485595e8e1410ff2
Author: Kévin Dietrich
Date:   Tue Mar 29 09:33:34 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB44d9f3a73bbaeb08a4aa9f8b485595e8e1410ff2

Import: add UI params to setup forward and up axises.

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

M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/editors/io/io_alembic.c

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

diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index fae02cd..02b2880 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -54,7 +54,7 @@ int ABC_export(struct Scene *sce, const char *filename,
 				int geogroups, bool ogawa,
 				bool packuv);
 
-void ABC_import(struct bContext *C, const char *filename);
+void ABC_import(struct bContext *C, const char *filename, int from_forward, int from_up);
 
 void ABC_get_vertex_cache(const char *filepath, float time, void *key, void *verts, int max_verts, const char *sub_obj, int is_mvert);
 
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 45c6e34..dced1be 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -614,7 +614,11 @@ static void visitObjectMatrix(IObject iObj, std::string abc_subobject, float tim
 	}
 }
 
-static void getIObjectAsMesh(std::pair<IPolyMeshSchema, IObject> schema, const ISampleSelector &sample_sel, Mesh *blender_mesh, void *key, bool assign_mat)
+#include "BLI_math.h"
+
+static void getIObjectAsMesh(std::pair<IPolyMeshSchema, IObject> schema,
+                             const ISampleSelector &sample_sel, Mesh *blender_mesh,
+                             void *key, bool assign_mat, int from_forward, int from_up)
 {
 	size_t idx_pos  = blender_mesh->totpoly;
 	size_t vtx_pos  = blender_mesh->totvert;
@@ -653,20 +657,33 @@ static void getIObjectAsMesh(std::pair<IPolyMeshSchema, IObject> schema, const I
 		uvsamp_vals = uvsamp.getVals();
 	}
 
+	float mat[3][3];
+	bool use_mat = false;
+
+	if (mat3_from_axis_conversion(from_forward, from_up, 1, 2, mat)) {
+		use_mat = true;
+	}
+
 	int j = vtx_pos;
 	for (int i = 0; i < vertex_count; ++i, ++j) {
 		MVert &mvert = blender_mesh->mvert[j];
-
 		V3f pos_in = (*positions)[i];
 
-		// swap from Y-Up to Z-Up
 		mvert.co[0] = pos_in[0];
-		mvert.co[1] = -pos_in[2];
-		mvert.co[2] = pos_in[1];
+		mvert.co[1] = pos_in[1];
+		mvert.co[2] = pos_in[2];
 
 		mvert.bweight = 0;
 	}
 
+	if (use_mat) {
+		j = vtx_pos;
+		for (int i = 0; i < vertex_count; ++i, ++j) {
+			MVert &mvert = blender_mesh->mvert[j];
+			mul_m3_v3(mat, mvert.co);
+		}
+	}
+
 	j = idx_pos;
 	int loopcount = loop_pos;
 	for (int i = 0; i < num_poly; ++i, ++j) {
@@ -858,7 +875,8 @@ static void ABC_destroy_key(void *key)
 	}
 }
 
-static Mesh *ABC_get_mesh(const char *filepath, float time, void *key, int assign_mats, const char *sub_obj, bool *p_only)
+static Mesh *ABC_get_mesh(const char *filepath, float time, void *key, int assign_mats,
+                          const char *sub_obj, bool *p_only, int from_forward, int from_up)
 {
 	Mesh *mesh = NULL;
 	std::string file_path = filepath;
@@ -924,7 +942,7 @@ static Mesh *ABC_get_mesh(const char *filepath, float time, void *key, int assig
 			vtx_count = updatePoints(*it, sample_sel, mesh->mvert, vtx_count);
 		}
 		else {
-			getIObjectAsMesh(*it, sample_sel, mesh, key, assign_mats);
+			getIObjectAsMesh(*it, sample_sel, mesh, key, assign_mats, from_forward, from_up);
 		}
 	}
 
@@ -1310,7 +1328,9 @@ static Object *create_hierarchy(bContext *C, const std::string &/*filename*/, co
 }
 #endif
 
-static void import_object(bContext *C, const std::string &filename, const std::string &sub_object, int object_type, Object *parent)
+static void import_object(bContext *C, const std::string &filename,
+                          const std::string &sub_object, int object_type,
+                          Object *parent, int from_forward, int from_up)
 {
 	std::vector<std::string> parts;
 	split(sub_object, "/", parts);
@@ -1327,7 +1347,7 @@ static void import_object(bContext *C, const std::string &filename, const std::s
 			bool p_only = false;
 
 			ABC_mutex_lock();
-			Mesh *mesh = ABC_get_mesh(filename.c_str(), 0.0f, NULL, apply_materials, sub_object.c_str(), &p_only);
+			Mesh *mesh = ABC_get_mesh(filename.c_str(), 0.0f, NULL, apply_materials, sub_object.c_str(), &p_only, from_forward, from_up);
 			ABC_mutex_unlock();
 
 			if (!mesh) {
@@ -1394,7 +1414,8 @@ static void import_object(bContext *C, const std::string &filename, const std::s
 	DAG_id_tag_update(&ob->id, OB_RECALC_OB);
 }
 
-static void import_objects(bContext *C, const std::string &filename, int object_type)
+static void import_objects(bContext *C, const std::string &filename,
+                           int object_type, int from_forward, int from_up)
 {
 	/* get objects strings */
 	IArchive *archive = abc_manager->getArchive(filename);
@@ -1425,13 +1446,13 @@ static void import_objects(bContext *C, const std::string &filename, int object_
 		              parts.end());
 
 		Object *parent = NULL; // create_hierarchy(C, filename, parts);
-		import_object(C, filename, *iter, object_type, parent);
+		import_object(C, filename, *iter, object_type, parent, from_forward, from_up);
 	}
 }
 
-void ABC_import(bContext *C, const char *filename)
+void ABC_import(bContext *C, const char *filename, int from_forward, int from_up)
 {
-	import_objects(C, filename, OBJECT_TYPE_MESH);
-	import_objects(C, filename, OBJECT_TYPE_NURBS);
-	import_objects(C, filename, OBJECT_TYPE_CAMERA);
+	import_objects(C, filename, OBJECT_TYPE_MESH, from_forward, from_up);
+	import_objects(C, filename, OBJECT_TYPE_NURBS, from_forward, from_up);
+	import_objects(C, filename, OBJECT_TYPE_CAMERA, from_forward, from_up);
 }
diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index 93323a9c..fb6a6a0 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -41,6 +41,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -169,7 +170,10 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
 	char filename[FILE_MAX];
 	RNA_string_get(op->ptr, "filepath", filename);
 
-	ABC_import(C, filename);
+	const int from_forward = RNA_enum_get(op->ptr, "from_forward");
+	const int from_up = RNA_enum_get(op->ptr, "from_up");
+
+	ABC_import(C, filename, from_forward, from_up);
 
 	/* restore cursor */
 	copy_v3_v3(scene->cursor, cursor_location);
@@ -188,4 +192,7 @@ void WM_OT_alembic_import(wmOperatorType *ot)
 
 	WM_operator_properties_filesel(ot, 0, FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH,
 	                               FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
+
+	RNA_def_enum(ot->srna, "from_forward", rna_enum_object_axis_items, 0, "Forward Axis", "");
+	RNA_def_enum(ot->srna, "from_up", rna_enum_object_axis_items, 0, "Up Axis", "");
 }




More information about the Bf-blender-cvs mailing list