[Bf-blender-cvs] [688444698b7] soc-2019-fast-io: [Fast import/export] Expanded the common library to include support for applying modifiers and triangulating
Hugo Sales
noreply at git.blender.org
Wed May 22 13:40:05 CEST 2019
Commit: 688444698b74ba239434966db0d676d2729600b1
Author: Hugo Sales
Date: Sun Mar 3 17:36:21 2019 +0000
Branches: soc-2019-fast-io
https://developer.blender.org/rB688444698b74ba239434966db0d676d2729600b1
[Fast import/export] Expanded the common library to include support for applying modifiers and triangulating
Includes some minor refactoring
===================================================================
M source/blender/editors/io/intern/common.c
M source/blender/editors/io/intern/common.h
M source/blender/editors/io/intern/obj.cpp
M source/blender/editors/io/intern/obj.h
M source/blender/editors/io/io_common.c
M source/blender/editors/io/io_common.h
M source/blender/editors/io/io_obj.c
M source/blender/makesdna/DNA_space_types.h
===================================================================
diff --git a/source/blender/editors/io/intern/common.c b/source/blender/editors/io/intern/common.c
index cf95600844f..7a135adc3a9 100644
--- a/source/blender/editors/io/intern/common.c
+++ b/source/blender/editors/io/intern/common.c
@@ -1,15 +1,32 @@
#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.
*
@@ -20,8 +37,9 @@
* This ignores selection and layer visibility,
* and assumes that the dupli-object itself (e.g. the group-instantiating empty) is exported.
*/
-bool common_export_object_p(const ExportSettings * const settings, const Base * const ob_base,
+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
@@ -43,7 +61,7 @@ bool common_export_object_p(const ExportSettings * const settings, const Base *
}
-bool common_object_type_is_exportable(Scene *scene, Object *ob) {
+bool common_object_type_is_exportable(Object *ob) {
switch (ob->type) {
case OB_MESH:
return !common_object_is_smoke_sim(ob);
@@ -57,11 +75,56 @@ bool common_object_type_is_exportable(Scene *scene, Object *ob) {
}
}
-static bool common_object_is_smoke_sim(Object *ob) {
- ModifierData *md = modifiers_findByType(ob, eModifierType_Smoke);
- if (md) {
- SmokeModifierData *smd = md;
- return (smd->type == MOD_SMOKE_TYPE_DOMAIN);
+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.h b/source/blender/editors/io/intern/common.h
index 8a456eaca0b..6cc7546a59e 100644
--- a/source/blender/editors/io/intern/common.h
+++ b/source/blender/editors/io/intern/common.h
@@ -7,11 +7,10 @@
#include "../io_common.h"
-bool common_export_object_p(const ExportSettings * const settings, const Base * const ob_base,
- bool is_duplicated);
+bool common_should_export_object(const ExportSettings * const settings, const Base * const ob_base,
+ bool is_duplicated);
-bool common_object_type_is_exportable(Scene *scene, Object *ob);
+bool common_object_type_is_exportable(Object *ob);
-
-static bool common_object_is_smoke_sim(Object *ob);
+bool get_final_mesh(ExportSettings *settings, Scene *escene, Object *eob, Mesh *mesh);
diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj.cpp
index 608144f02d3..353beb8d2ee 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -1,8 +1,11 @@
extern "C" {
+#include "BKE_mesh_runtime.h"
#include "BKE_global.h"
#include "BKE_context.h"
#include "BKE_scene.h"
+#include "BKE_library.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
@@ -10,6 +13,10 @@ extern "C" {
#undef new
#include "DNA_space_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_ID.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
@@ -20,10 +27,77 @@ extern "C" {
#include "WM_api.h"
#include "WM_types.h"
+#include "BLI_math.h"
+
+#include "BLT_translation.h"
+
+#include "ED_object.h"
+
+#include "bmesh.h"
+#include "bmesh_tools.h"
+
#include "obj.h"
#include "../io_common.h"
#include "common.h"
+}
+
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+
+
+
+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 = ob_name.find(" ");
+ while(start_pos != std::string::npos)
+ ob_name.replace(start_pos, 1, "_");
+ }
+
+ bool OBJ_export_mesh(bContext *UNUSED(C), ExportSettings *settings, std::fstream& fs,
+ Object *eob, Mesh *mesh) {
+
+ std::cout << "Foo\n";
+
+ if (mesh->totvert == 0)
+ return true;
+
+ if (settings->export_objects_as_objects || settings->export_objects_as_groups) {
+ std::string name{eob->id.name};
+ std::string mesh_name{mesh->id.name};
+ name_compat(name, mesh_name);
+ if (settings->export_objects_as_objects)
+ fs << "o " << name << '\n';
+ else
+ fs << "g " << name << '\n';
+ }
+
+ // TODO someone Should this use iterators? Unsure if those are only for BMesh
+ for (int i = 0, e = mesh->totvert; i < e; ++i)
+ fs << "v "
+ << mesh->mvert[i].co[0]
+ << mesh->mvert[i].co[1]
+ << mesh->mvert[i].co[2]
+ << '\n';
+
+ if (settings->export_uvs) {
+ // TODO someone Is T47010 still relevant?
+ for (int i = 0, e = mesh->totloop; i < e; ++i)
+ fs << "vt "
+ << mesh->mloopuv[i].uv[0]
+ << mesh->mloopuv[i].uv[1]
+ << '\n';
+
+ }
+
+ return true;
+ }
+
+
}
bool OBJ_export(bContext *C, ExportSettings *settings) {
@@ -40,21 +114,64 @@ bool OBJ_export_start(bContext *C, ExportSettings *settings) {
G.is_rendering = true;
BKE_spacedata_draw_locks(true);
+
DEG_graph_build_from_view_layer(settings->depsgraph,
- CTX_data_main(C),
+ settings->main,
settings->scene,
settings->view_layer);
- BKE_scene_graph_update_tagged(settings->depsgraph, CTX_data_main(C));
-
- for (Base *base = static_cast<Base *>(settings->view_layer->object_bases.first); base; base = base->next) {
- Object *ob = base->object;
- if (common_export_object_p(settings, base, false)) {
- Object *eob = DEG_get_evaluated_object(settings->depsgraph, ob);
- if (common_object_type_is_exportable(settings->scene, eob)) {
- // createTransformWriter(ob, parent, dupliObParent);
+ BKE_scene_graph_update_tagged(settings->depsgraph, settings->main);
+
+ std::fstream fs;
+ fs.open(settings->filepath, std::ios::out);
+ fs << std::fixed << std::setprecision(6);
+ fs << "# Blender v2.8\n# www.blender.org\n"; // TODO someone add proper version
+ // TODO someone add material export
+
+ Scene *scene = DEG_get_evaluated_scene(settings->depsgraph);
+
+ for (float frame = settings->frame_start; frame != settings->frame_end + 1.0; frame += 1.0) {
+ BKE_scene_frame_set(scene, frame);
+ BKE_scene_graph_update_for_newframe(settings->depsgraph, settings->main);
+
+ for (Base *base = static_cast<Base *>(settings->view_layer->object_bases.first);
+ base; base = base->next) {
+ if (!G.is_break) {
+ // Object *ob = base->object;
+ Object *eob = DEG_get_evaluated_object(settings->depsgraph,
+ base->object); // Is this expensive?
+ if (!common_should_export_object(settings, base,
+ // TODO someone Currently ignoring
+ // all dupli objects;
+ // unsure if expected behavior
+ eob->parent != NULL &&
+ eob->parent->transflag & OB_DUPLI)
+
+ || !common_object_type_is_exportable(eob))
+ continue;
+
+
+ struct Mesh *mesh = nullptr;
+ bool needs_free = false;
+
+ std::cout << "BAR\n";
+
+ switch (eob->type) {
+ case OB_MESH:
+ needs_free = get_final_mesh(settings, scene,
+ eob, mesh /* OUT */);
+ if (!OBJ_export_mesh(C, settings, fs, eob,
+ mesh))
+ return false;
+
+ BKE_id_f
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list