[Bf-blender-cvs] [b8a84a0402d] soc-2019-fast-io: [Fast import/export] Refactoring, fixed ASCII STL export and other bugs
Hugo Sales
noreply at git.blender.org
Sat Jun 8 10:49:09 CEST 2019
Commit: b8a84a0402dae320668b1db13cf8fc3aa827e209
Author: Hugo Sales
Date: Thu Jun 6 21:39:15 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rBb8a84a0402dae320668b1db13cf8fc3aa827e209
[Fast import/export] Refactoring, fixed ASCII STL export and other bugs
===================================================================
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
M source/blender/editors/io/io_obj.c
M source/blender/editors/io/io_stl.c
===================================================================
diff --git a/source/blender/editors/io/intern/common.cpp b/source/blender/editors/io/intern/common.cpp
index 570694f3e4a..fe7ce15712f 100644
--- a/source/blender/editors/io/intern/common.cpp
+++ b/source/blender/editors/io/intern/common.cpp
@@ -8,6 +8,7 @@ extern "C" {
#include "DNA_object_types.h"
#include "DNA_modifier_types.h"
+#include "BKE_modifier.h"
#include "BKE_modifier.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
@@ -70,44 +71,41 @@ namespace common {
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.
- * 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) {
- // 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) */
-
- /* 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; */
+ case OB_LAMP:
+ case OB_EMPTY:
+ case OB_CAMERA:
+ return false;
default:
- printf("Export for this object type is not defined %s\n", ob->id.name);
+ // TODO someone Print in debug only
+ fprintf(stderr, "Export for this object type is not yet defined %s\n", ob->id.name);
+ return false;
+ }
+ }
+
+ // Whether the object should be exported
+ bool should_export_object(const ExportSettings * const settings, const Object * const ob) {
+ if (!object_type_is_exportable(ob))
+ return false;
+ // If the object is a dupli, it's export satus depends on the parent
+ if (!(ob->flag & BASE_FROM_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 && (ob->flag & BASE_SELECTED) != 0) ||
+ // FIXME Sybren: handle these cleanly (maybe just remove code),
+ // now using active scene layer instead.
+ (settings->visible_only && (ob->flag & BASE_VISIBLE) != 0) ||
+ (settings->renderable_only && (ob->flag & BASE_ENABLED_RENDER) != 0);
+ } else if (!(ob->parent != NULL && ob->parent->transflag & OB_DUPLI))
+ return should_export_object(settings, ob->parent);
+ else {
+ BLI_assert(!"should_export_object");
return false;
}
}
diff --git a/source/blender/editors/io/intern/common.hpp b/source/blender/editors/io/intern/common.hpp
index 99d22e8d86e..a74eb4a8368 100644
--- a/source/blender/editors/io/intern/common.hpp
+++ b/source/blender/editors/io/intern/common.hpp
@@ -63,10 +63,10 @@ namespace common {
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);
+ bool should_export_object(const ExportSettings * const settings, 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,
@@ -97,7 +97,7 @@ namespace common {
template<typename SourceT, typename Tag = std::random_access_iterator_tag>
struct pointer_iterator :
public boost::iterator_facade<pointer_iterator<SourceT, Tag>, SourceT &, Tag> {
- pointer_iterator() = default;
+ pointer_iterator() : first(nullptr) {}
pointer_iterator(const pointer_iterator<SourceT, Tag> &) = default;
pointer_iterator(pointer_iterator<SourceT, Tag> &&) = default;
explicit pointer_iterator(SourceT *p) : it(p), first(p), size(0) {}
@@ -166,7 +166,7 @@ namespace common {
typename Tag = std::bidirectional_iterator_tag>
struct list_iterator : public boost::iterator_adaptor<list_iterator<SourceT, ResT, Tag>,
pointer_iterator<SourceT, Tag>, ResT, Tag, ResT> {
- list_iterator() : list_iterator::iterator_adaptor_() {}
+ list_iterator() : list_iterator::iterator_adaptor_(), first(nullptr) {}
list_iterator(const pointer_iterator<SourceT, Tag> &other)
: list_iterator::iterator_adaptor_(other), first(other.first) {}
explicit list_iterator(SourceT *first)
@@ -203,19 +203,6 @@ namespace common {
const Mesh * const mesh;
};
- // Iterator over the UVs of a mesh (as `const std::array<float, 2>`)
- struct uv_iter : public dereference_iterator<MLoopUV, const std::array<float, 2>, uv_iter> {
- explicit uv_iter(const Mesh * const m)
- : dereference_iterator(m->mloopuv, m->totloop, this) {}
- uv_iter(const dereference_iterator_ &di)
- : dereference_iterator(di, this) {}
- uv_iter(dereference_iterator_ &&di)
- : dereference_iterator(di, this) {}
- inline const std::array<float, 2> dereference(const pointer_iterator<MLoopUV> &b) {
- return {b->uv[0], b->uv[1]};
- }
- };
-
// Iterator over all the edges of a mesh
struct edge_iter : pointer_iterator<MEdge> {
edge_iter(const Mesh * const m) : pointer_iterator(m->medge, m->totedge) {}
@@ -247,18 +234,47 @@ namespace common {
// Iterator over all the objects in a `ViewLayer`
// TODO someone G.is_break
struct object_iter : dereference_iterator<Base, Object *, object_iter, list_iterator<Base>> {
- explicit object_iter(const ViewLayer * const vl)
+ object_iter(const ViewLayer * const vl)
: dereference_iterator((Base *) vl->object_bases.first, this) {}
+ object_iter(Base *b)
+ : dereference_iterator(b, this) {}
inline static Object * dereference(const list_iterator<Base> &b) { return b->object; }
};
+ struct exportable_object_iter
+ : public boost::iterator_adaptor<exportable_object_iter, object_iter> {
+ explicit exportable_object_iter(const ExportSettings * const settings)
+ : exportable_object_iter::iterator_adaptor_(settings->view_layer),
+ settings(settings) {}
+ exportable_object_iter(const ExportSettings * const settings, Base *base)
+ : exportable_object_iter::iterator_adaptor_(base),
+ settings(settings) {}
+ friend class boost::iterator_core_access;
+ exportable_object_iter begin() const { return { settings, (Base *) settings->view_layer->
+ object_bases.first}; }
+ exportable_object_iter end() const { return { settings, (Base *) nullptr}; }
+ void increment() {
+ do {
+ ++this->base_reference();
+ } while (this->base() != this->base().end() &&
+ !should_export_object(settings, *this->base()));
+ }
+ void decrement() {
+ do {
+ --this->base_reference();
+ } while (this->base() != this->base().begin() &&
+ !should_export_object(settings, *this->base()));
+ }
+ const ExportSettings * const settings;
+ };
+
// Iterator over the modifiers of an `Object`
struct modifier_iter : list_iterator<ModifierData> {
explicit modifier_iter(const Object * const ob)
: list_iterator((ModifierData *) ob->modifiers.first) {}
};
- // Iterator over the `MLoop` if a `MPoly` of a mesh
+ // Iterator over the `MLoop` of a `MPoly` of a mesh
struct loop_of_poly_iter : pointer_iterator<MLoop> {
explicit loop_of_poly_iter(const Mesh * const mesh, const poly_iter &poly)
: pointer_iterator(mesh->mloop + poly->loopstart, poly->totloop - 1) {}
@@ -268,6 +284,19 @@ namespace common {
loop_of_poly_iter(pointer_iterator &&p) : pointer_iterator(std::move(p)) {}
};
+ // Iterator over the UVs of a mesh (as `const std::array<float, 2>`)
+ struct uv_iter : public dereference_iterator<MLoopUV, const std::array<float, 2>, uv_iter> {
+ explicit uv_iter(const Mesh * const m)
+ : dereference_iterator(m->mloopuv, m->totloop, this) {}
+ uv_iter(const dereference_iterator_ &di)
+ : dereference_iterator(di, this) {}
+ uv_iter(dereference_iterator_ &&di)
+ : dereference_iterator(di, this) {}
+ inline const std::array<float, 2> dereference(const pointer_iterator<MLoopUV> &b) {
+ return {b->uv[0], b->uv[1]};
+ }
+ };
+
// Iterator over the normals of mesh
// This is a more complex one, because there are three possible sources for the normals of a mesh:
// - Custom normals
diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj.cpp
index c0f2cc2f278..65a2d8dde7d 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -232,9 +232,9 @@ namespace {
dedup_pair_t<uv_key_t> &uv_mapping_pair, dedup_pair_t<no_key_t> &no_mapping_pair) {
// TODO someone Should it be evaluated first? Is this expensive? Breaks mesh_create_eval_final
// Object *eob = DEG_get_evaluated_object(settings->depsgraph, base->object);
- if (!common::should_export_object(settings, ob) ||
- !common::object_type_is_exportable(ob))
- return false;
+ // if (!common::should_export_object(settings, ob) ||
+ // !common::object_type_is_exportable(ob))
+ // return false;
struct Mesh *mesh = nullptr;
bool needs_free = false;
@@ -252,8 +252,9 @@ namespace {
return true;
default:
// TODO someone Probably abort, it shouldn't be possible to get here
- std::cerr << "OBJ Export for this Object Type not implemented"
- << ob->id.name << '\
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list