Merge branch 'master' into blender2.8
authorSybren A. StÃ\83¼vel <sybren@stuvel.eu>
Sun, 29 Oct 2017 14:27:44 +0000 (15:27 +0100)
committerSybren A. Stüvel <sybren@stuvel.eu>
Sun, 29 Oct 2017 14:38:55 +0000 (15:38 +0100)
# Conflicts:
# source/blender/alembic/intern/abc_exporter.cc
# source/blender/alembic/intern/abc_exporter.h
# source/blender/alembic/intern/alembic_capi.cc
# tests/gtests/alembic/abc_export_test.cc

1  2 
source/blender/alembic/CMakeLists.txt
source/blender/alembic/intern/abc_exporter.cc
source/blender/alembic/intern/abc_exporter.h
source/blender/alembic/intern/abc_mball.cc
source/blender/alembic/intern/abc_mball.h
source/blender/alembic/intern/abc_mesh.cc
source/blender/alembic/intern/abc_mesh.h
source/blender/alembic/intern/alembic_capi.cc
tests/gtests/alembic/CMakeLists.txt
tests/gtests/alembic/abc_export_test.cc

Simple merge
index df2bc52aa2c42f4f5e13861308b95b170a126e7f,946b89213e6e616f69b14ffaa136bac18ba7c2b5..5635e3a94203df20c0e5acba2a4834d6b101adee
@@@ -163,8 -168,9 +168,9 @@@ static bool export_object(const ExportS
  
  /* ************************************************************************** */
  
- AbcExporter::AbcExporter(EvaluationContext *eval_ctx, Scene *scene, const char *filename, ExportSettings &settings)
-     : m_settings(settings)
 -AbcExporter::AbcExporter(Main *bmain, Scene *scene, const char *filename, ExportSettings &settings)
++AbcExporter::AbcExporter(Main *bmain, EvaluationContext *eval_ctx, Scene *scene, const char *filename, ExportSettings &settings)
+     : m_bmain(bmain)
+     , m_settings(settings)
      , m_filename(filename)
      , m_trans_sampling_index(0)
      , m_shape_sampling_index(0)
@@@ -354,22 -359,22 +360,20 @@@ void AbcExporter::operator()(Main *bmai
  
  void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx)
  {
 -      Base *base = static_cast<Base *>(m_scene->base.first);
 -
 -      while (base) {
 +      for (Base *base = static_cast<Base *>(m_settings.sl->object_bases.first); base; base = base->next) {
                Object *ob = base->object;
  
 -              switch (ob->type) {
 -                      case OB_LAMP:
 -                      case OB_LATTICE:
 -                      case OB_SPEAKER:
 -                              /* We do not export transforms for objects of these classes. */
 -                              break;
 -                      default:
 -                              exploreTransform(eval_ctx, ob, ob->parent);
 +              if (export_object(&m_settings, base, false)) {
 +                      switch (ob->type) {
 +                              case OB_LAMP:
 +                              case OB_LATTICE:
-                               case OB_MBALL:
 +                              case OB_SPEAKER:
 +                                      /* We do not export transforms for objects of these classes. */
 +                                      break;
 +                              default:
 +                                      exploreTransform(eval_ctx, base, ob->parent, NULL);
 +                      }
                }
 -
 -              base = base->next;
        }
  }
  
@@@ -383,8 -386,8 +387,8 @@@ void AbcExporter::exploreTransform(Eval
                return;
        }
  
-       if (object_type_is_exportable(ob)) {
+       if (object_type_is_exportable(m_scene, ob)) {
 -              createTransformWriter(ob, parent, dupliObParent);
 +              createTransformWriter(eval_ctx, ob, parent, dupliObParent);
        }
  
        ListBase *lb = object_duplilist(eval_ctx, m_scene, ob);
@@@ -549,11 -549,9 +553,11 @@@ void AbcExporter::createParticleSystems
        }
  }
  
 -void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
 +void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent)
  {
-       if (!object_type_is_exportable(ob)) {
 +      Object *ob = ob_base->object;
 +
+       if (!object_type_is_exportable(m_scene, ob)) {
                return;
        }
  
  
                        break;
                }
 -                                             m_bmain, m_scene, ob, xform,
+               case OB_MBALL:
+               {
+                       MetaBall *mball = static_cast<MetaBall *>(ob->data);
+                       if (!mball) {
+                               return;
+                       }
+                       m_shapes.push_back(new AbcMBallWriter(
++                                             m_bmain, m_eval_ctx, m_scene, ob, xform,
+                                              m_shape_sampling_index, m_settings));
+                       break;
+               }
        }
  }
  
index 9c5fb69234c323f30deb791302b3dcda6aa84300,280682b28964bdfc003ca67d6f286e60ade41341..7e32178bc208a205796cf37ba12434f8773b43bd
@@@ -102,7 -99,7 +103,7 @@@ class AbcExporter 
        std::vector<AbcObjectWriter *> m_shapes;
  
  public:
-       AbcExporter(EvaluationContext *eval_ctx, Scene *scene, const char *filename, ExportSettings &settings);
 -      AbcExporter(Main *bmain, Scene *scene, const char *filename, ExportSettings &settings);
++      AbcExporter(Main *bmain, EvaluationContext *eval_ctx, Scene *scene, const char *filename, ExportSettings &settings);
        ~AbcExporter();
  
        void operator()(Main *bmain, float &progress, bool &was_canceled);
index 0000000000000000000000000000000000000000,56bb609ace0437db6931fab38b03598171f2dd48..31cc6d1fe3eabeeef1b36dbd0c8e09bb0e0d0ef0
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,122 +1,122 @@@
 -#include "BKE_depsgraph.h"
+ /*
+  * ***** BEGIN GPL LICENSE BLOCK *****
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software Foundation,
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  *
+  * Contributor(s): Sybren A. Stüvel
+  *
+  * ***** END GPL LICENSE BLOCK *****
+  */
+ #include "abc_mball.h"
+ #include "abc_mesh.h"
+ #include "abc_transform.h"
+ extern "C" {
+ #include "DNA_meta_types.h"
+ #include "DNA_mesh_types.h"
+ #include "DNA_object_types.h"
+ #include "BKE_curve.h"
 -    : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ #include "BKE_displist.h"
+ #include "BKE_main.h"
+ #include "BKE_mball.h"
+ #include "BKE_mesh.h"
+ #include "BKE_object.h"
+ #include "DEG_depsgraph.h"
+ #include "MEM_guardedalloc.h"
+ }
+ AbcMBallWriter::AbcMBallWriter(
+         Main *bmain,
++        EvaluationContext *eval_ctx,
+         Scene *scene,
+         Object *ob,
+         AbcTransformWriter *parent,
+         uint32_t time_sampling,
+         ExportSettings &settings)
 -      m_mesh_writer = new AbcMeshWriter(scene, m_mesh_ob, parent,
++    : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent)
+     , m_bmain(bmain)
+ {
+       m_is_animated = isAnimated();
+       m_mesh_ob = BKE_object_copy(bmain, ob);
+       m_mesh_ob->curve_cache = (CurveCache*)MEM_callocN(
+                                    sizeof(CurveCache),
+                                    "CurveCache for AbcMBallWriter");
++      m_mesh_writer = new AbcMeshWriter(eval_ctx, scene, m_mesh_ob, parent,
+                                         time_sampling, settings);
+       m_mesh_writer->setIsAnimated(m_is_animated);
+ }
+ AbcMBallWriter::~AbcMBallWriter()
+ {
+       delete m_mesh_writer;
+       BKE_object_free(m_mesh_ob);
+ }
+ bool AbcMBallWriter::isAnimated() const
+ {
+       MetaBall *mb = static_cast<MetaBall *>(m_object->data);
+       if (mb->adt != NULL) return true;
+       /* Any movement of any object in the parent chain
+        * could cause the mball to deform. */
+       for (Object *ob = m_object; ob != NULL; ob = ob->parent) {
+               if (ob->adt != NULL) return true;
+       }
+       return false;
+ }
+ void AbcMBallWriter::do_write()
+ {
+       /* We have already stored a sample for this object. */
+       if (!m_first_frame && !m_is_animated)
+               return;
+       Mesh *tmpmesh = BKE_mesh_add(m_bmain, ((ID *)m_object->data)->name + 2);
+       BLI_assert(tmpmesh != NULL);
+       m_mesh_ob->data = tmpmesh;
+       /* BKE_mesh_add gives us a user count we don't need */
+       id_us_min(&tmpmesh->id);
+       ListBase disp = {NULL, NULL};
+       /* TODO(sergey): This is gonna to work for until EvaluationContext
+        *               only contains for_render flag. As soon as CoW is
+        *               implemented, this is to be rethinked.
+        */
+       EvaluationContext eval_ctx;
+       DEG_evaluation_context_init(&eval_ctx, DAG_EVAL_RENDER);
+       BKE_displist_make_mball_forRender(&eval_ctx, m_scene, m_object, &disp);
+       BKE_mesh_from_metaball(&disp, tmpmesh);
+       BKE_displist_free(&disp);
+       BKE_mesh_texspace_copy_from_object(tmpmesh, m_mesh_ob);
+       m_mesh_writer->write();
+       BKE_id_free(m_bmain, tmpmesh);
+       m_mesh_ob->data = NULL;
+ }
+ bool AbcMBallWriter::isBasisBall(Scene *scene, Object *ob)
+ {
+       Object *basis_ob = BKE_mball_basis_find(scene, ob);
+       return ob == basis_ob;
+ }
index 0000000000000000000000000000000000000000,46b61151216fcdbd20d9e06e6d97af9fe673ebcd..4fdc1d7b88286950e081b5931f21355403f5613e
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,61 +1,62 @@@
+ /*
+  * ***** BEGIN GPL LICENSE BLOCK *****
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software Foundation,
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  *
+  * Contributor(s): Sybren A. Stüvel
+  *
+  * ***** END GPL LICENSE BLOCK *****
+  */
+ #ifndef __ABC_MBALL_H__
+ #define __ABC_MBALL_H__
+ #include "abc_object.h"
+ struct AbcMeshWriter;
+ struct Main;
+ struct MetaBall;
+ struct Object;
+ /* AbcMBallWriter converts the metaballs to meshes at every frame,
+  * and defers to a wrapped AbcMeshWriter to perform the writing
+  * to the Alembic file. Only the basis balls are exported, as this
+  * results in the entire shape as one mesh. */
+ class AbcMBallWriter : public AbcObjectWriter {
+       AbcMeshWriter *m_mesh_writer;
+       Object *m_mesh_ob;
+       bool m_is_animated;
+       Main *m_bmain;
+ public:
+       AbcMBallWriter(
+               Main *bmain,
++              EvaluationContext *eval_ctx,
+               Scene *scene,
+               Object *ob,
+               AbcTransformWriter *parent,
+               uint32_t time_sampling,
+               ExportSettings &settings);
+       ~AbcMBallWriter();
+       static bool isBasisBall(Scene *scene, Object *ob);
+ private:
+       virtual void do_write();
+       bool isAnimated() const;
+ };
+ #endif  /* __ABC_MBALL_H__ */
index e7c7213cecb68bdbd7f03200fe3a764ce8958922,0d2316ce7d9f8adca4a30694da184cb798b9b8d6..730a574e6497dc23efdc318011b7694556208fcb
@@@ -263,7 -259,7 +263,7 @@@ static void export_startjob(void *custo
  
        try {
                Scene *scene = data->scene;
-               AbcExporter exporter(&data->eval_ctx, scene, data->filename, data->settings);
 -              AbcExporter exporter(data->bmain, scene, data->filename, data->settings);
++              AbcExporter exporter(data->bmain, &data->eval_ctx, scene, data->filename, data->settings);
  
                const int orig_frame = CFRA;
  
index 924e7bbb1b6e8746ae89e58faeda89ed8b3194e5,1511024ee51049c32e2fa04e8b5768c5c6cf2b9f..3e794898ebe4726380ccda685ae6803ec0c77ef2
@@@ -25,9 -25,9 +25,10 @@@ set(IN
        .
        ..
        ../../../source/blender/blenlib
+       ../../../source/blender/blenkernel
        ../../../source/blender/alembic
        ../../../source/blender/makesdna
 +      ../../../source/blender/depsgraph
        ${ALEMBIC_INCLUDE_DIRS}
        ${BOOST_INCLUDE_DIR}
        ${HDF5_INCLUDE_DIRS}
index 41ea32950ebfd2216aca236c2d4d28aaa02ac144,a2761513d06fdb6e71491e7ec5fe41264177b611..78622dcf8a04332cd0d84699c81bbb1ef91734bb
@@@ -10,16 -11,11 +11,16 @@@ extern "C" 
  #include "DNA_scene_types.h"
  }
  
 +#include "DEG_depsgraph.h"
 +
  class TestableAbcExporter : public AbcExporter {
  public:
-       TestableAbcExporter(Scene *scene, const char *filename, ExportSettings &settings)
-           : AbcExporter(&eval_ctx, scene, filename, settings)
+       TestableAbcExporter(Main *bmain, Scene *scene, const char *filename, ExportSettings &settings)
 -          : AbcExporter(bmain, scene, filename, settings)
 -      {}
++          : AbcExporter(bmain, &eval_ctx, scene, filename, settings)
 +      {
 +              /* TODO(sergey): Pass scene layer somehow? */
 +              DEG_evaluation_context_init(&eval_ctx, DAG_EVAL_VIEWPORT);
 +      }
  
        void getShutterSamples(unsigned int nr_of_samples,
                               bool time_relative,
@@@ -42,6 -37,6 +43,7 @@@ protected
        ExportSettings settings;
        Scene scene;
        TestableAbcExporter *exporter;
++      EvaluationContext eval_ctx;
  
        virtual void SetUp()
        {