[Bf-blender-cvs] [566eafd50b5] soc-2019-fast-io: [Fast import/export] Working MVP for obj exporter

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


Commit: 566eafd50b50a9324860417022ad08be3f3e0672
Author: Hugo Sales
Date:   Fri Mar 22 12:50:28 2019 +0000
Branches: soc-2019-fast-io
https://developer.blender.org/rB566eafd50b50a9324860417022ad08be3f3e0672

[Fast import/export] Working MVP for obj exporter

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

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

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

diff --git a/source/blender/editors/io/intern/common.c b/source/blender/editors/io/intern/common.c
deleted file mode 100644
index 7a135adc3a9..00000000000
--- a/source/blender/editors/io/intern/common.c
+++ /dev/null
@@ -1,130 +0,0 @@
-#include "BLI_listbase.h"
-#include "BLI_math_matrix.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_layer_types.h"
-#include "DNA_object_types.h"
-#include "DNA_modifier_types.h"
-
-#include "BKE_modifier.h"
-#include "BKE_mesh.h"
-#include "BKE_mesh_runtime.h"
-
-#include "bmesh.h"
-#include "bmesh_tools.h"
-
-#include "../io_common.h"
-#include "common.h"
-
-
-static bool common_object_is_smoke_sim(Object *ob) {
-	ModifierData *md = modifiers_findByType(ob, eModifierType_Smoke);
-	if (md) {
-		SmokeModifierData *smd = (SmokeModifierData *) md;
-		return (smd->type == MOD_SMOKE_TYPE_DOMAIN);
-	}
-	return false;
-}
-
-/**
- * Returns whether this object should be exported into the Alembic file.
- *
- * \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,
- * and assumes that the dupli-object itself (e.g. the group-instantiating empty) is exported.
- */
-bool common_should_export_object(const ExportSettings * const settings, const Base * const ob_base,
-                             bool is_duplicated) {
-	/* From alembic */
-	if (!is_duplicated) {
-		/* These two tests only make sense when the object isn't being instanced
-		 * into the scene. When it is, its exportability is determined by
-		 * its dupli-object and the DupliObject::no_draw property. */
-		if (settings->selected_only && (ob_base->flag & BASE_SELECTED) != 0) {
-			return false;
-		}
-		// FIXME Sybren: handle these cleanly (maybe just remove code), now using active scene layer instead.
-		if (settings->visible_only && (ob_base->flag & BASE_VISIBLE) == 0) {
-			return false;
-		}
-
-		if (settings->renderable_only && (ob_base->flag & BASE_ENABLED_RENDER)) {
-			return false;
-		}
-	}
-
-	return true;
-}
-
-
-bool common_object_type_is_exportable(Object *ob) {
-	switch (ob->type) {
-	case OB_MESH:
-		return !common_object_is_smoke_sim(ob);
-	case OB_EMPTY:
-	case OB_CURVE:
-	case OB_SURF:
-	case OB_CAMERA:
-		return true;
-	default:
-		return false;
-	}
-}
-
-bool get_final_mesh(ExportSettings *settings, Scene *escene, Object *eob, Mesh *mesh) {
-	/* From abc_mesh.cc */
-
-	/* Temporarily disable subdivs if we shouldn't apply them */
-	if (!settings->apply_subdiv)
-		for (ModifierData *md = 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);
-	// TODO someone Unsure if necessary
-	// scale_mat[3][3] = m_settings.global_scale;  /* also scale translation */
-	mul_m4_m4m4(eob->obmat, eob->obmat, scale_mat);
-	// yup_mat[3][3] /= m_settings.global_scale;  /* normalise the homogeneous component */
-
-	if (determinant_m4(eob->obmat) < 0.0)
-		;               /* TODO someone flip normals */
-
-	/* Object *eob = DEG_get_evaluated_object(settings->depsgraph, ob); */
-	mesh = mesh_get_eval_final(settings->depsgraph, escene, eob, CD_MASK_MESH);
-
-	if (!settings->apply_subdiv)
-		for (ModifierData *md = eob->modifiers.first; md; md = md->next)
-			if (md->type == eModifierType_Subsurf)
-				md->mode &= ~eModifierMode_DisableTemporary;
-
-	if (settings->triangulate) {
-		struct BMeshCreateParams bmcp = {false};
-		struct BMeshFromMeshParams bmfmp = {true, false, false, 0};
-		BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, &bmcp, &bmfmp);
-
-		BM_mesh_triangulate(bm, settings->quad_method, settings->ngon_method,
-		                    false /* tag_only */, NULL, NULL, NULL);
-
-		Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, 0);
-		BM_mesh_free(bm);
-
-		// TODO someone Does it need to be freed?
-		// It seems from abc_mesh that the result of mesh_get_eval_final
-		// doesn't need to be freed
-		/* if (*needs_free) { */
-		/* 	BKE_id_free(NULL, mesh); */
-		/* } */
-
-		mesh = result;
-		return true;
-	}
-
-	// TODO someone Does it need to be freed?
-	// It seems from abc_mesh that the result of mesh_get_eval_final doesn't need to be freed
-	return false;
-}
diff --git a/source/blender/editors/io/intern/common.cpp b/source/blender/editors/io/intern/common.cpp
new file mode 100644
index 00000000000..4bb8cc2d17d
--- /dev/null
+++ b/source/blender/editors/io/intern/common.cpp
@@ -0,0 +1,323 @@
+extern "C" {
+#include "BLI_listbase.h"
+#include "BLI_math_matrix.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_layer_types.h"
+#include "DNA_object_types.h"
+#include "DNA_modifier_types.h"
+
+#include "BKE_modifier.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
+
+#include "bmesh.h"
+#include "bmesh_tools.h"
+
+#include "../io_common.h"
+
+#include <stdio.h>
+}
+
+#include "common.hpp"
+
+// Anonymous namespace for internal functions
+namespace {
+	void name_compat(std::string& ob_name, std::string& mesh_name) {
+		if(ob_name.compare(mesh_name) != 0) {
+			ob_name += "_" + mesh_name;
+		}
+		size_t start_pos;
+		while((start_pos = ob_name.find(" ")) != std::string::npos)
+			ob_name.replace(start_pos, 1, "_");
+	}
+}
+
+namespace common {
+
+	static bool object_is_smoke_sim(const Object * const ob) {
+		ModifierData *md = modifiers_findByType((Object *) ob, eModifierType_Smoke);
+		if (md) {
+			SmokeModifierData *smd = (SmokeModifierData *) md;
+			return (smd->type == MOD_SMOKE_TYPE_DOMAIN);
+		}
+		return false;
+	}
+
+	/**
+	 * Returns whether this object should be exported into the Alembic file.
+	 *
+	 * \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,
+	 * 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 (!(eob->flag & BASE_FROM_DUPLI)) {
+			/* !(eob->parent != NULL && eob->parent->transflag & OB_DUPLI) */
+
+			/* These tests only make sense when the object isn't being instanced
+			 * into the scene. When it is, its exportability is determined by
+			 * its dupli-object and the DupliObject::no_draw property. */
+			return  (settings->selected_only && (eob->flag & BASE_SELECTED) != 0) ||
+				// FIXME Sybren: handle these cleanly (maybe just remove code),
+				// now using active scene layer instead.
+				(settings->visible_only && (eob->flag & BASE_VISIBLE) != 0) ||
+				(settings->renderable_only && (eob->flag & BASE_ENABLED_RENDER) != 0);
+		}
+
+		return should_export_object(settings, eob->parent);
+	}
+
+
+	bool object_type_is_exportable(const Object * const ob) {
+		switch (ob->type) {
+		case OB_MESH:
+			return !object_is_smoke_sim(ob);
+			/* case OB_EMPTY: */
+			/* case OB_CURVE: */
+			/* case OB_SURF: */
+			/* case OB_CAMERA: */
+			/* return false; */
+		default:
+			printf("Export for this object type not defined %s\n", ob->id.name);
+			return false;
+		}
+	}
+
+	bool get_final_mesh(const ExportSettings * const settings, const Scene * const escene,
+	                    const Object *eob, Mesh **mesh /* out */) {
+		/* 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;
+
+		float scale_mat[4][4];
+		scale_m4_fl(scale_mat, settings->global_scale);
+		// 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);
+		// yup_mat[3][3] /= m_settings.global_scale;  /* normalise the homogeneous component */
+
+		if (determinant_m4(eob->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);
+
+		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->triangulate) {
+			struct BMeshCreateParams bmcp = {false};
+			struct BMeshFromMeshParams bmfmp = {true, false, false, 0};
+			BMesh *bm = BKE_mesh_to_bmesh_ex(*mesh, &bmcp, &bmfmp);
+
+			BM_mesh_triangulate(bm, settings->quad_method, settings->ngon_method,
+			                    false /* tag_only */, NULL, NULL, NULL);
+
+			Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, 0);
+			BM_mesh_free(bm);
+
+			*mesh = result;
+			/* Needs to free? */
+			return true;
+		}
+
+		/* Needs to free? */
+		return false;
+	}
+
+	std::string&& get_object_name(const Object *eob, const Mesh *mesh) {
+		std::string name{eob->id.name + 2};
+		std::string mesh_name{mesh->id.name + 2};
+		name_compat(name /* modifies */, mesh_name);
+		return std::move(name);
+	}
+
+        	// template<typename func>
+	void for_each_vertex(const Mesh *mesh, void (*f)(int, const MVert)) {
+		// 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_uv(Mesh *mesh, void (*f)(int, const std::array<float, 2>)) {
+		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]});
+		}
+	}
+
+	// template<ty

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list