[Bf-blender-cvs] [8cf1e0c865d] soc-2019-fast-io: [Fast import/export] Initial support for materials and STL

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


Commit: 8cf1e0c865dd4ccd20e16961ca0740028ac3d58f
Author: Hugo Sales
Date:   Fri May 17 10:16:57 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rB8cf1e0c865dd4ccd20e16961ca0740028ac3d58f

[Fast import/export] Initial support for materials and STL

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

M	source/blender/editors/io/CMakeLists.txt
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/obj.h
A	source/blender/editors/io/intern/stl.cpp
A	source/blender/editors/io/intern/stl.h
M	source/blender/editors/io/io_common.c
M	source/blender/editors/io/io_common.h
M	source/blender/editors/io/io_obj.h
M	source/blender/editors/io/io_ops.c
A	source/blender/editors/io/io_stl.c
A	source/blender/editors/io/io_stl.h

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

diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index 7ecec0eb040..c5f29d7f09f 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -42,6 +42,7 @@ set(SRC
   io_ops.c
   io_common.c
   io_obj.c
+  io_stl.c
 
   io_alembic.h
   io_cache.h
@@ -49,11 +50,14 @@ set(SRC
   io_ops.h
   io_common.h
   io_obj.h
+  io_stl.h
 
   intern/obj.cpp
   intern/obj.h
   intern/common.cpp
   intern/common.hpp
+  intern/stl.cpp
+  intern/stl.h
 )
 
 set(LIB
diff --git a/source/blender/editors/io/intern/common.cpp b/source/blender/editors/io/intern/common.cpp
index 65cadcdef83..ddb9e10dc62 100644
--- a/source/blender/editors/io/intern/common.cpp
+++ b/source/blender/editors/io/intern/common.cpp
@@ -24,7 +24,7 @@ extern "C" {
 
 // Anonymous namespace for internal functions
 namespace {
-	void name_compat(std::string& ob_name, std::string& mesh_name) {
+	void name_compat(std::string& ob_name, const std::string& mesh_name) {
 		if(ob_name.compare(mesh_name) != 0) {
 			ob_name += "_" + mesh_name;
 		}
@@ -36,7 +36,7 @@ namespace {
 
 namespace common {
 
-	static bool object_is_smoke_sim(const Object * const ob) {
+	bool object_is_smoke_sim(const Object * const ob) {
 		ModifierData *md = modifiers_findByType((Object *) ob, eModifierType_Smoke);
 		if (md) {
 			SmokeModifierData *smd = (SmokeModifierData *) md;
@@ -50,16 +50,11 @@ namespace common {
 	 *
 	 * \param settings: export settings, used for options like 'selected only'.
 	 * \param ob: the object's base in question.
-	 * \param is_duplicated: Normally false; true when the object is instanced
-	 * into the scene by a dupli-object (e.g. part of a dupligroup).
-	 * This ignores selection and layer visibility,
+	 * This ignores layer visibility,
 	 * and assumes that the dupli-object itself (e.g. the group-instantiating empty) is exported.
 	 */
 	bool should_export_object(const ExportSettings * const settings, const Object * const eob) {
-
-		/* From alembic */
-
-		// TODO someone Currently ignoring all dupli objects; unsure if expected behavior
+		// If the object is a dupli, it's export satus depends on the parent
 		if (!(eob->flag & BASE_FROM_DUPLI)) {
 			/* !(eob->parent != NULL && eob->parent->transflag & OB_DUPLI) */
 
@@ -97,10 +92,11 @@ namespace common {
 		/* From abc_mesh.cc */
 
 		/* Temporarily disable subdivs if we shouldn't apply them */
-		if (!settings->apply_subdiv)
-			for (ModifierData *md = (ModifierData *) eob->modifiers.first; md; md = md->next)
-				if (md->type == eModifierType_Subsurf)
-					md->mode |= eModifierMode_DisableTemporary;
+		if (!settings->apply_modifiers)
+			for (ModifierData *md = (ModifierData *) eob->modifiers.first;
+			     md; md = md->next)
+				// if (md->type == eModifierType_Subsurf)
+				md->mode |= eModifierMode_DisableTemporary;
 
 		float scale_mat[4][4];
 		scale_m4_fl(scale_mat, settings->global_scale);
@@ -113,12 +109,21 @@ namespace common {
 			;               /* 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);
-
-		if (!settings->apply_subdiv)
-			for (ModifierData *md = (ModifierData *) eob->modifiers.first; md; md = md->next)
-				if (md->type == eModifierType_Subsurf)
-					md->mode &= ~eModifierMode_DisableTemporary;
+		//*mesh = mesh_get_eval_final(settings->depsgraph, (Scene *) escene,
+		//                            (Object *)eob, &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);
+		else
+			*mesh = mesh_create_eval_final_view(settings->depsgraph, (Scene *) escene,
+			                               (Object *) eob, &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;
 
 		if (settings->triangulate) {
 			struct BMeshCreateParams bmcp = {false};
@@ -135,12 +140,11 @@ namespace common {
 			/* Needs to free? */
 			return true;
 		}
-
 		/* Needs to free? */
 		return false;
 	}
 
-	std::string get_object_name(const Object *eob, const Mesh *mesh) {
+	std::string get_object_name(const Object * const eob, const Mesh * const mesh) {
 		std::string name{eob->id.name + 2};
 		std::string mesh_name{mesh->id.name + 2};
 		name_compat(name /* modifies */, mesh_name);
diff --git a/source/blender/editors/io/intern/common.hpp b/source/blender/editors/io/intern/common.hpp
index 8020d8a2e4c..dce867cc24f 100644
--- a/source/blender/editors/io/intern/common.hpp
+++ b/source/blender/editors/io/intern/common.hpp
@@ -42,18 +42,24 @@ namespace common {
 	bool get_final_mesh(const ExportSettings * const settings, const Scene * const escene,
 	                    const Object *eob, Mesh **mesh);
 
-	std::string get_object_name(const Object *eob, const Mesh *mesh);
+	std::string get_object_name(const Object * const eob, const Mesh * const mesh);
 
 	template<typename func>
-	void for_each_vertex(const Mesh *mesh, func f) {
+	void for_each_vertex(const Mesh * const mesh, func f) {
 		// TODO someone Should this use iterators? Unsure if those are only for BMesh
 		for (int i = 0, e = mesh->totvert; i < e; ++i)
 			f(i, mesh->mvert[i]);
 	}
 
+	template<typename func>
+	void for_each_edge(const Mesh * const mesh, func f) {
+		for (int i = 0, e = mesh->totedge; i < e; ++i)
+			f(i, mesh->medge[i]);
+	}
+
 	struct for_each_uv_t {
 		template<typename func>
-		void operator()(Mesh *mesh, func f) {
+		void operator()(const Mesh * const mesh, func f) {
 			for (int i = 0, e = mesh->totloop; i < e; ++i) {
 				const float (&uv)[2] = mesh->mloopuv[i].uv;
 				f(i, std::array<float, 2>{uv[0], uv[1]});
@@ -62,13 +68,13 @@ namespace common {
 	};
 
 	template<typename func>
-	void for_each_uv(Mesh *mesh, func f) {
+	void for_each_uv(const Mesh * const mesh, func f) {
 		for_each_uv_t{}(mesh, f);
 	}
 
 	struct for_each_normal_t {
 		template<typename func>
-		void operator()(Mesh *mesh, func f) {
+		void operator()(const Mesh * const mesh, func f) {
 			const float (*loop_no)[3] = static_cast<float(*)[3]>
 				(CustomData_get_layer(&mesh->ldata,
 				                      CD_NORMAL));
@@ -112,12 +118,12 @@ namespace common {
 	};
 
 	template<typename func>
-	void for_each_normal(Mesh *mesh, func f) {
+	void for_each_normal(const Mesh * const mesh, func f) {
 		for_each_normal_t{}(mesh, f);
 	}
 
 	template<typename key_t>
-	using set_t = std::set<key_t, bool (*)(key_t, key_t)>;
+	using set_t = std::set<key_t, bool (*)(const key_t &, const key_t &)>;
 
 	template<typename key_t>
 	using set_mapping_t = std::vector<typename set_t<key_t>::iterator>;
@@ -128,37 +134,9 @@ namespace common {
 	using uv_key_t = std::pair<std::array<float, 2>, ulong>;
 	using no_key_t = std::pair<std::array<float, 3>, ulong>;
 
-	// template<typename func>
-	// void for_each_deduplicated_uv(Mesh *mesh, ulong &total, dedup_pair_t<uv_key_t>& p, func f);
-
-	// template<typename func>
-	// void for_each_deduplicated_normal(Mesh *mesh, ulong &total, dedup_pair_t<no_key_t>& p, func f);
-
-	// template <class F>
-	// struct lambda_traits : lambda_traits<decltype(&F::operator())> {};
-
-	// template <typename F, typename R, typename... Args>
-	// struct lambda_traits<R(F::*)(Args...)> : lambda_traits<R(F::*)(Args...) const> {};
-
-	// template <class F, class R, class... Args>
-	// struct lambda_traits<R(F::*)(Args...) const> {
-	// 	using pointer = typename std::add_pointer<R(Args...)>::type;
-
-	// 	static pointer stateful_lambda_to_pointer(F&& f) {
-	// 		static F fn = std::forward<F>(f);
-	// 		return [](Args... args) {
-	// 			       return fn(std::forward<Args>(args)...);
-	// 		       };
-	// 	}
-	// };
-
-	// template <class F>
-	// inline typename lambda_traits<F>::pointer stateful_lambda_to_pointer(F&& f) {
-	// 	return lambda_traits<F>::stateful_lambda_to_pointer(std::forward<F>(f));
-	// }
-
+	// TODO someone Benchmark the performance wth iterators and normal deduplication
 	template<typename for_each_t, typename dedup_set_mapping_t, typename on_insert_t>
-	void deduplicate(ulong &total, ulong reserve, Mesh *mesh,
+	void deduplicate(ulong &total, ulong reserve, const Mesh * const mesh,
 	                 dedup_set_mapping_t &p,
 	                 for_each_t for_each,
 	                 on_insert_t on_insert) {
@@ -181,15 +159,16 @@ namespace common {
 		               });
 	}
 
-	// Again, C++14/17 would be really useful here...
+	// Again, C++14/17 would be really useful here...rmal
 	template<typename key_t>
 	dedup_pair_t<key_t> make_deduplicate_set() {
-		auto cmp = [](key_t lhs, key_t rhs) -> bool { return lhs.first < rhs.first; };
+		auto cmp = [](const key_t &lhs, const key_t &rhs) -> bool
+		           { return lhs.first < rhs.first; };
 		return {set_t<key_t>{cmp} /* set */, {} /* set_mapping */};
 	}
 
 	template<typename func>
-	void for_each_deduplicated_uv(Mesh *mesh, ulong &total,
+	void for_each_deduplicated_uv(const Mesh *mesh, ulong &total,
 	                              dedup_pair_t<uv_key_t>& p, func f) {
 		deduplicate(/* modifies  */ total,
 		            /* reserve   */ total + mesh->totloop,
@@ -200,11 +179,10 @@ namespace common {
 	}
 
 	template<typename func>
-	void for_each_deduplicated_normal(Mesh *mesh, ulong &total,
+	void for_each_deduplicated_normal(const Mesh *mesh, ulong &total,
 	                                  dedup_pair_t<no_key_t>& p, func f) {
 		deduplicate(/* modifies  */ total,
-		            /* Assume 4 verts per face, doesn't break anything if not true */
-		            total + mesh->totpoly * 4, // TODO someone There's probably a better way to do this
+		            total + mesh->totvert,
 		            mesh,
 		            /* modifies  */ p,
 		            /* for_each  */ for_each_normal_t{},
@@ -223,4 +201,4 @@ namespace common {
 	}
 }
 
-#endif // __io_intern_common__
+#endif // __io_intern_common_
diff --git a/sourc

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list