[Bf-blender-cvs] [39cddacb85f] soc-2019-fast-io: [Fast import/export] Bug fixing and adding support for orientation changes

Hugo Sales noreply at git.blender.org
Wed May 22 13:40:14 CEST 2019


Commit: 39cddacb85fa2601b341bab16c0436bd707c8c56
Author: Hugo Sales
Date:   Tue May 21 15:07:32 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rB39cddacb85fa2601b341bab16c0436bd707c8c56

[Fast import/export] Bug fixing and adding support for orientation changes

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

M	source/blender/editors/io/intern/common.cpp
M	source/blender/editors/io/intern/common.hpp
M	source/blender/editors/io/intern/obj.cpp
M	source/blender/editors/io/intern/stl.cpp
M	source/blender/editors/io/io_common.c
M	source/blender/editors/io/io_common.h

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

diff --git a/source/blender/editors/io/intern/common.cpp b/source/blender/editors/io/intern/common.cpp
index ddb9e10dc62..a72dcfbee63 100644
--- a/source/blender/editors/io/intern/common.cpp
+++ b/source/blender/editors/io/intern/common.cpp
@@ -20,11 +20,13 @@ extern "C" {
 #include <stdio.h>
 }
 
+#include <iostream>
+
 #include "common.hpp"
 
 // Anonymous namespace for internal functions
 namespace {
-	void name_compat(std::string& ob_name, const std::string& mesh_name) {
+	inline void name_compat(std::string& ob_name, const std::string& mesh_name) {
 		if(ob_name.compare(mesh_name) != 0) {
 			ob_name += "_" + mesh_name;
 		}
@@ -32,6 +34,28 @@ namespace {
 		while((start_pos = ob_name.find(" ")) != std::string::npos)
 			ob_name.replace(start_pos, 1, "_");
 	}
+
+	inline void change_single_axis_orientation(float (&mat)[4][4],
+	                                     int axis_from, int axis_to) {
+		bool negate = false;
+		switch (axis_to) {
+		case AXIS_X: // Fallthrough
+		case AXIS_Y: // Fallthrough
+		case AXIS_Z:
+			break; // Just swap
+		case AXIS_NEG_X: // Fallthrough
+		case AXIS_NEG_Y: // Fallthrough
+		case AXIS_NEG_Z:
+			axis_to -= AXIS_NEG_X; // Transform the enum into an index
+			negate = true;         // Swap and negate
+			break;
+		}
+		for (size_t i = 0; i < 4; ++i) {
+			float t = mat[i][axis_to];
+			mat[i][axis_to] = (negate ? -1 : 1) * mat[i][axis_from];
+			mat[i][axis_from] = t;
+		}
+	}
 }
 
 namespace common {
@@ -82,48 +106,56 @@ namespace common {
 			/* case OB_CAMERA: */
 			/* return false; */
 		default:
-			printf("Export for this object type not defined %s\n", ob->id.name);
+			printf("Export for this object type is not defined %s\n", ob->id.name);
 			return false;
 		}
 	}
 
+	void change_orientation(float (&mat)[4][4], int forward, int up) {
+		change_single_axis_orientation(mat, AXIS_X, forward);
+		change_single_axis_orientation(mat, AXIS_Z, up);
+	}
+
 	bool get_final_mesh(const ExportSettings * const settings, const Scene * const escene,
-	                    const Object *eob, Mesh **mesh /* out */) {
-		/* From abc_mesh.cc */
+	                    const Object *ob, Mesh **mesh /* out */) {
+		/* Based on abc_mesh.cc */
 
-		/* Temporarily disable subdivs if we shouldn't apply them */
+		/* Temporarily disable modifiers if we shouldn't apply them */
 		if (!settings->apply_modifiers)
-			for (ModifierData *md = (ModifierData *) eob->modifiers.first;
-			     md; md = md->next)
-				// if (md->type == eModifierType_Subsurf)
-				md->mode |= eModifierMode_DisableTemporary;
+			for_each_modifier(ob, [](ModifierData *md){
+				                      md->mode |= eModifierMode_DisableTemporary;
+			                      });
 
 		float scale_mat[4][4];
 		scale_m4_fl(scale_mat, settings->global_scale);
+
+		change_orientation(scale_mat, settings->axis_forward, settings->axis_up);
+
 		// TODO someone Unsure if necessary
 		// scale_mat[3][3] = m_settings.global_scale;  /* also scale translation */
-		mul_m4_m4m4((float (*)[4]) eob->obmat, eob->obmat, scale_mat);
+
+		// TODO someone Doesn't seem to do anyhing. Is it necessary to update the object somehow?
+		mul_m4_m4m4((float (*)[4]) ob->obmat, ob->obmat, scale_mat);
 		// yup_mat[3][3] /= m_settings.global_scale;  /* normalise the homogeneous component */
 
-		if (determinant_m4(eob->obmat) < 0.0)
+		if (determinant_m4(ob->obmat) < 0.0)
 			;               /* TODO someone flip normals */
 
-		/* Object *eob = DEG_get_evaluated_object(settings->depsgraph, ob); */
-		//*mesh = mesh_get_eval_final(settings->depsgraph, (Scene *) escene,
-		//                            (Object *)eob, &CD_MASK_MESH);
+		/* Object *ob = DEG_get_evaluated_object(settings->depsgraph, ob); */
+		// *mesh = mesh_get_eval_final(settings->depsgraph, (Scene *) escene,
+		//                             (Object *) ob, &CD_MASK_MESH);
 
 		if (settings->render_modifiers) // vv Depends on depsgraph type
 			*mesh = mesh_create_eval_final_render(settings->depsgraph, (Scene *) escene,
-			                                 (Object *) eob, &CD_MASK_MESH);
+			                                      (Object *) ob, &CD_MASK_MESH);
 		else
 			*mesh = mesh_create_eval_final_view(settings->depsgraph, (Scene *) escene,
-			                               (Object *) eob, &CD_MASK_MESH);
+			                                    (Object *) ob, &CD_MASK_MESH);
 
 		if (!settings->apply_modifiers)
-			for (ModifierData *md = (ModifierData *) eob->modifiers.first;
-			     md; md = md->next)
-				// if (md->type == eModifierType_Subsurf)
-				md->mode &= ~eModifierMode_DisableTemporary;
+			for_each_modifier(ob, [](ModifierData *md){
+				                      md->mode &= ~eModifierMode_DisableTemporary;
+			                      });
 
 		if (settings->triangulate) {
 			struct BMeshCreateParams bmcp = {false};
@@ -150,4 +182,27 @@ namespace common {
 		name_compat(name /* modifies */, mesh_name);
 		return name;
 	}
+
+	void export_start(bContext *UNUSED(C), const ExportSettings * const settings) {
+		/* From alembic_capi.cc
+		 * XXX annoying hack: needed to prevent data corruption when changing
+		 * scene frame in separate threads
+		 */
+		G.is_rendering = true; // TODO someone Should use BKE_main_lock(bmain);?
+		BKE_spacedata_draw_locks(true);
+		DEG_graph_build_from_view_layer(settings->depsgraph,
+		                                settings->main,
+		                                settings->scene,
+		                                settings->view_layer);
+		BKE_scene_graph_update_tagged(settings->depsgraph, settings->main);
+	}
+
+	bool export_end(bContext *UNUSED(C), ExportSettings * const settings) {
+		G.is_rendering = false;
+		BKE_spacedata_draw_locks(false);
+		DEG_graph_free(settings->depsgraph);
+		MEM_freeN(settings);
+		return true;
+	}
+
 }
diff --git a/source/blender/editors/io/intern/common.hpp b/source/blender/editors/io/intern/common.hpp
index dce867cc24f..4bf73339516 100644
--- a/source/blender/editors/io/intern/common.hpp
+++ b/source/blender/editors/io/intern/common.hpp
@@ -8,20 +8,38 @@
 
 extern "C" {
 
+#include "BKE_global.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_runtime.h"
 #include "BKE_modifier.h"
+#include "BKE_library.h"
+#include "BKE_customdata.h"
+#include "BKE_scene.h"
+
+#include "MEM_guardedalloc.h"
+
+/* SpaceType struct has a member called 'new' which obviously conflicts with C++
+ * so temporarily redefining the new keyword to make it compile. */
+#define new extern_new
+#include "BKE_screen.h"
+#undef new
+
 #include "BLI_listbase.h"
 #include "BLI_math_matrix.h"
 #include "BLI_math_vector.h"
+
 #include "bmesh.h"
 #include "bmesh_tools.h"
+
 #include "DNA_layer_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
 #include "../io_common.h"
 
 }
@@ -34,16 +52,38 @@ extern "C" {
 namespace common {
 	using ulong = unsigned long;
 
-	bool should_export_object(const ExportSettings * const settings, const Object * const eob);
+	bool object_is_smoke_sim(const Object * const ob);
 
+	bool should_export_object(const ExportSettings * const settings, const Object * const eob);
 
 	bool object_type_is_exportable(const Object * const ob);
 
+	void change_orientation(float (&mat)[4][4], int forward, int up);
+
 	bool get_final_mesh(const ExportSettings * const settings, const Scene * const escene,
 	                    const Object *eob, Mesh **mesh);
 
 	std::string get_object_name(const Object * const eob, const Mesh * const mesh);
 
+	void export_start(bContext *C, const ExportSettings * const settings);
+	bool export_end(bContext *C, ExportSettings * const settings);
+
+	template<typename func>
+	void for_each_modifier(const Object * const ob, func f) {
+		for (ModifierData *md = (ModifierData *) ob->modifiers.first;
+		     md; md = md->next)
+			f(md);
+	}
+
+	template<typename func>
+	void for_each_base(ViewLayer * const view_layer, func f) {
+		for (Base *base = static_cast<Base *>(view_layer->object_bases.first);
+		     base; base = base->next)
+			if (!G.is_break)
+				f(base);
+		G.is_break = false;
+	}
+
 	template<typename func>
 	void for_each_vertex(const Mesh * const mesh, func f) {
 		// TODO someone Should this use iterators? Unsure if those are only for BMesh
@@ -57,6 +97,7 @@ namespace common {
 			f(i, mesh->medge[i]);
 	}
 
+	// Meeded for the templated call operator, for deduping
 	struct for_each_uv_t {
 		template<typename func>
 		void operator()(const Mesh * const mesh, func f) {
diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj.cpp
index 2cacd8a98df..66d8e616171 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -8,12 +8,6 @@ extern "C" {
 #include "BKE_library.h"
 #include "BKE_customdata.h"
 
-/* SpaceType struct has a member called 'new' which obviously conflicts with C++
- * so temporarily redefining the new keyword to make it compile. */
-#define new extern_new
-#include "BKE_screen.h"
-#undef new
-
 #include "DNA_ID.h"
 #include "DNA_material_types.h"
 #include "DNA_meshdata_types.h"
@@ -22,10 +16,6 @@ extern "C" {
 #include "DNA_space_types.h"
 
 #include "DEG_depsgraph.h"
-#include "DEG_depsgraph_build.h"
-#include "DEG_depsgraph_query.h"
-
-#include "MEM_guardedalloc.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -35,7 +25,6 @@ extern "C" {
 #include "BLT_translation.h"
 
 #include "ED_object.h"
-
 #include "bmesh.h"
 #include "bmesh_tools.h"
 
@@ -48,6 +37,7 @@ extern "C" {
 #include <fstream>
 #include <iomanip>
 #include <iostream>
+#include <map>
 #include <set>
 #include <unordered_map>
 #include <vector>
@@ -57,7 +47,8 @@ extern "C" {
 /*
   TODO someone: () not done, -- done, # maybe add, ? unsure
   presets
-  axis remap
+  axis remap -- doesn't work. Does it need to update, somehow?
+  	DEG_id_tag_update(&mesh->id, 0); obedit->id.recalc & ID_RECALC_ALL
   --selection only
   animation - partly
   --apply modifiers
@@ -68,31 +59,55 @@ extern "C" {
   --normals
   --uvs
   materials
+  material groups
+  path mode -- python repr
   --triangulate
   nurbs
   polygroups?
   --o

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list