Merge branch 'master' into blender2.8
authorSybren A. Stüvel <sybren@stuvel.eu>
Fri, 28 Apr 2017 13:52:07 +0000 (15:52 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Fri, 28 Apr 2017 13:52:07 +0000 (15:52 +0200)
1  2 
source/blender/alembic/intern/abc_mesh.cc
source/blender/alembic/intern/abc_object.cc
source/blender/alembic/intern/alembic_capi.cc
source/creator/creator_args.c
tests/python/CMakeLists.txt

index a0b175dbcdc97d2bff7478501e469c47a3a4b1a9,32795e70e9237fbfb0f6c00acd4d94da455b0b59..15a72cf4453abc94cb6ce549f0b143144b8509f6
@@@ -38,6 -38,7 +38,6 @@@ extern "C" 
  #include "BLI_string.h"
  
  #include "BKE_cdderivedmesh.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_main.h"
  #include "BKE_material.h"
  #include "BKE_mesh.h"
@@@ -1020,17 -1021,15 +1020,15 @@@ bool AbcMeshReader::valid() cons
        return m_schema.valid();
  }
  
- void AbcMeshReader::readObjectData(Main *bmain, float time)
+ void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
  {
        Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
  
        m_object = BKE_object_add_only_object(bmain, OB_MESH, m_object_name.c_str());
        m_object->data = mesh;
  
-       const ISampleSelector sample_sel(time);
        DerivedMesh *dm = CDDM_from_mesh(mesh);
-       DerivedMesh *ndm = this->read_derivedmesh(dm, time, MOD_MESHSEQ_READ_ALL, NULL);
+       DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, MOD_MESHSEQ_READ_ALL, NULL);
  
        if (ndm != dm) {
                dm->release(dm);
        }
  }
  
- DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str)
+ bool AbcMeshReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
+                                         const Object *const ob,
+                                         const char **err_str) const
+ {
+       if (!Alembic::AbcGeom::IPolyMesh::matches(alembic_header)) {
+               *err_str = "Object type mismatch, Alembic object path pointed to PolyMesh when importing, but not any more.";
+               return false;
+       }
+       if (ob->type != OB_MESH) {
+               *err_str = "Object type mismatch, Alembic object path points to PolyMesh.";
+               return false;
+       }
+       return true;
+ }
+ DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm,
+                                              const ISampleSelector &sample_sel,
+                                              int read_flag,
+                                              const char **err_str)
  {
-       ISampleSelector sample_sel(time);
        const IPolyMeshSchema::Sample sample = m_schema.getValue(sample_sel);
  
        const P3fArraySamplePtr &positions = sample.getPositions();
        }
  
        CDStreamConfig config = get_config(new_dm ? new_dm : dm);
-       config.time = time;
+       config.time = sample_sel.getRequestedTime();
  
        bool do_normals = false;
        read_mesh_sample(&settings, m_schema, sample_sel, config, do_normals);
@@@ -1238,7 -1256,24 +1255,24 @@@ bool AbcSubDReader::valid() cons
        return m_schema.valid();
  }
  
- void AbcSubDReader::readObjectData(Main *bmain, float time)
+ bool AbcSubDReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
+                                         const Object *const ob,
+                                         const char **err_str) const
+ {
+       if (!Alembic::AbcGeom::ISubD::matches(alembic_header)) {
+               *err_str = "Object type mismatch, Alembic object path pointed to SubD when importing, but not any more.";
+               return false;
+       }
+       if (ob->type != OB_MESH) {
+               *err_str = "Object type mismatch, Alembic object path points to SubD.";
+               return false;
+       }
+       return true;
+ }
+ void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
  {
        Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
  
        m_object->data = mesh;
  
        DerivedMesh *dm = CDDM_from_mesh(mesh);
-       DerivedMesh *ndm = this->read_derivedmesh(dm, time, MOD_MESHSEQ_READ_ALL, NULL);
+       DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, MOD_MESHSEQ_READ_ALL, NULL);
  
        if (ndm != dm) {
                dm->release(dm);
  
        DM_to_mesh(ndm, mesh, m_object, CD_MASK_MESH, true);
  
-       const ISampleSelector sample_sel(time);
        const ISubDSchema::Sample sample = m_schema.getValue(sample_sel);
        Int32ArraySamplePtr indices = sample.getCreaseIndices();
        Alembic::Abc::FloatArraySamplePtr sharpnesses = sample.getCreaseSharpnesses();
        }
  }
  
- DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str)
+ DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm,
+                                              const ISampleSelector &sample_sel,
+                                              int read_flag,
+                                              const char **err_str)
  {
-       ISampleSelector sample_sel(time);
        const ISubDSchema::Sample sample = m_schema.getValue(sample_sel);
  
        const P3fArraySamplePtr &positions = sample.getPositions();
  
        /* Only read point data when streaming meshes, unless we need to create new ones. */
        CDStreamConfig config = get_config(new_dm ? new_dm : dm);
-       config.time = time;
+       config.time = sample_sel.getRequestedTime();
        read_subd_sample(&settings, m_schema, sample_sel, config);
  
        if (new_dm) {
index 28a4d1850148654623742e1d4a4d534d2c7fff6a,04f6da4871160c82c5e71c48e105850765fcd725..8b169988096617e51c28fa12b300ad54afb4917d
@@@ -32,6 -32,7 +32,6 @@@ extern "C" 
  #include "DNA_space_types.h"  /* for FILE_MAX */
  
  #include "BKE_constraint.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_idprop.h"
  #include "BKE_library.h"
  #include "BKE_modifier.h"
@@@ -215,9 -216,9 +215,9 @@@ Imath::M44d get_matrix(const IXformSche
  }
  
  DerivedMesh *AbcObjectReader::read_derivedmesh(DerivedMesh *dm,
-                                                        const float UNUSED(time),
-                                                        int UNUSED(read_flag),
-                                                        const char **UNUSED(err_str))
+                                                const Alembic::Abc::ISampleSelector &UNUSED(sample_sel),
+                                                int UNUSED(read_flag),
+                                                const char **UNUSED(err_str))
  {
        return dm;
  }
index 61b18c7112fec47cdaea395d102eb29903b2d952,528647991335034f061347e2a80aa98dfbdf0f7f..ac195ffc95571f1549f502495379c0f1f779f073
@@@ -48,15 -48,12 +48,15 @@@ extern "C" 
  #include "BKE_cdderivedmesh.h"
  #include "BKE_context.h"
  #include "BKE_curve.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_global.h"
 +#include "BKE_layer.h"
  #include "BKE_library.h"
  #include "BKE_main.h"
  #include "BKE_scene.h"
  
 +#include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_build.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
@@@ -272,7 -269,8 +272,7 @@@ static void export_startjob(void *custo
                if (CFRA != orig_frame) {
                        CFRA = orig_frame;
  
 -                      BKE_scene_update_for_newframe(data->bmain->eval_ctx, data->bmain,
 -                                                    scene, scene->lay);
 +                      BKE_scene_update_for_newframe(data->bmain->eval_ctx, data->bmain, scene);
                }
  
                data->export_ok = !data->was_canceled;
@@@ -332,24 -330,13 +332,24 @@@ bool ABC_export
         * hardcore refactoring. */
        new (&job->settings) ExportSettings();
        job->settings.scene = job->scene;
 +
 +      /* Sybren: for now we only export the active scene layer.
 +       * Later in the 2.8 development process this may be replaced by using
 +       * a specific collection for Alembic I/O, which can then be toggled
 +       * between "real" objects and cached Alembic files. */
 +      job->settings.sl = CTX_data_scene_layer(C);
 +
        job->settings.frame_start = params->frame_start;
        job->settings.frame_end = params->frame_end;
        job->settings.frame_step_xform = params->frame_step_xform;
        job->settings.frame_step_shape = params->frame_step_shape;
        job->settings.shutter_open = params->shutter_open;
        job->settings.shutter_close = params->shutter_close;
 +
 +      /* Sybren: For now this is ignored, until we can get selection
 +       * detection working through Base pointers (instead of ob->flags). */
        job->settings.selected_only = params->selected_only;
 +
        job->settings.export_face_sets = params->face_sets;
        job->settings.export_normals = params->normals;
        job->settings.export_uvs = params->uvs;
        job->settings.export_particles = params->export_particles;
        job->settings.apply_subdiv = params->apply_subdiv;
        job->settings.flatten_hierarchy = params->flatten_hierarchy;
 +
 +      /* Sybren: visible_layer & renderable only is ignored for now,
 +       * to be replaced with collections later in the 2.8 dev process
 +       * (also see note above). */
        job->settings.visible_layers_only = params->visible_layers_only;
        job->settings.renderable_only = params->renderable_only;
 +
        job->settings.use_subdiv_schema = params->use_subdiv_schema;
        job->settings.export_ogawa = (params->compression_type == ABC_ARCHIVE_OGAWA);
        job->settings.pack_uv = params->packuv;
@@@ -623,7 -605,6 +623,7 @@@ enum 
  struct ImportJobData {
        Main *bmain;
        Scene *scene;
 +      SceneLayer *scene_layer;
  
        char filename[1024];
        ImportSettings settings;
@@@ -732,12 -713,13 +732,13 @@@ static void import_startjob(void *user_
        chrono_t min_time = std::numeric_limits<chrono_t>::max();
        chrono_t max_time = std::numeric_limits<chrono_t>::min();
  
+       ISampleSelector sample_sel(0.0f);
        std::vector<AbcObjectReader *>::iterator iter;
        for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
                AbcObjectReader *reader = *iter;
  
                if (reader->valid()) {
-                       reader->readObjectData(data->bmain, 0.0f);
+                       reader->readObjectData(data->bmain, sample_sel);
  
                        min_time = std::min(min_time, reader->minTime());
                        max_time = std::max(max_time, reader->maxTime());
@@@ -824,32 -806,20 +825,32 @@@ static void import_endjob(void *user_da
        else {
                /* Add object to scene. */
                Base *base;
 +              LayerCollection *lc;
 +              SceneLayer *sl = data->scene_layer;
  
 -              BKE_scene_base_deselect_all(data->scene);
 +              BKE_scene_layer_base_deselect_all(sl);
 +
 +              lc = BKE_layer_collection_active(sl);
 +              if (lc == NULL) {
 +                      BLI_assert(BLI_listbase_count_ex(&sl->layer_collections, 1) == 0);
 +                      /* when there is no collection linked to this SceneLayer, create one */
 +                      SceneCollection *sc = BKE_collection_add(data->scene, NULL, NULL);
 +                      lc = BKE_collection_link(sl, sc);
 +              }
  
                for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
                        Object *ob = (*iter)->object();
                        ob->lay = data->scene->lay;
  
 -                      base = BKE_scene_base_add(data->scene, ob);
 -                      BKE_scene_base_select(data->scene, base);
 +                      BKE_collection_object_add(data->scene, lc->scene_collection, ob);
 +
 +                      base = BKE_scene_layer_base_find(sl, ob);
 +                      BKE_scene_layer_base_select(sl, base);
  
 -                      DAG_id_tag_update_ex(data->bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
 +                      DEG_id_tag_update_ex(data->bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
                }
  
 -              DAG_relations_tag_update(data->bmain);
 +              DEG_relations_tag_update(data->bmain);
        }
  
        for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
@@@ -892,7 -862,6 +893,7 @@@ bool ABC_import(bContext *C, const cha
        ImportJobData *job = new ImportJobData();
        job->bmain = CTX_data_main(C);
        job->scene = CTX_data_scene(C);
 +      job->scene_layer = CTX_data_scene_layer(C);
        job->import_ok = false;
        BLI_strncpy(job->filename, filepath, 1024);
  
@@@ -970,42 -939,13 +971,13 @@@ DerivedMesh *ABC_read_mesh(CacheReader 
        }
  
        const ObjectHeader &header = iobject.getHeader();
-       if (IPolyMesh::matches(header)) {
-               if (ob->type != OB_MESH) {
-                       *err_str = "Object type mismatch: object path points to a mesh!";
-                       return NULL;
-               }
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
-       }
-       else if (ISubD::matches(header)) {
-               if (ob->type != OB_MESH) {
-                       *err_str = "Object type mismatch: object path points to a subdivision mesh!";
-                       return NULL;
-               }
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
-       }
-       else if (IPoints::matches(header)) {
-               if (ob->type != OB_MESH) {
-                       *err_str = "Object type mismatch: object path points to a point cloud (requires a mesh object)!";
-                       return NULL;
-               }
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
-       }
-       else if (ICurves::matches(header)) {
-               if (ob->type != OB_CURVE) {
-                       *err_str = "Object type mismatch: object path points to a curve!";
-                       return NULL;
-               }
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
+       if (!abc_reader->accepts_object_type(header, ob, err_str)) {
+               /* err_str is set by acceptsObjectType() */
+               return NULL;
        }
  
-       *err_str = "Unsupported object type: verify object path"; // or poke developer
-       return NULL;
+       ISampleSelector sample_sel(time);
+       return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
  }
  
  /* ************************************************************************** */
index d7406588952f13d3e6fc42cb48194a080b30b1e6,658a0b2db080f5f90fe1e98f7d6b5cddfe2bb647..3850846b0b94db4c4163d5f923c361ccc9eaa1a1
@@@ -55,6 -55,8 +55,6 @@@
  #include "BKE_sound.h"
  #include "BKE_image.h"
  
 -#include "DEG_depsgraph.h"
 -
  #ifdef WITH_FFMPEG
  #include "IMB_imbuf.h"
  #endif
@@@ -585,6 -587,7 +585,6 @@@ static int arg_handle_print_help(int UN
  
        printf("\n");
        printf("Experimental Features:\n");
 -      BLI_argsPrintArgDoc(ba, "--enable-new-depsgraph");
        BLI_argsPrintArgDoc(ba, "--enable-new-basic-shader-glsl");
  
        /* Other options _must_ be last (anything not handled will show here) */
@@@ -1160,7 -1163,6 +1160,6 @@@ static const char arg_handle_threads_se
  "<threads>\n"
  "\tUse amount of <threads> for rendering and other operations\n"
  "\t[1-" STRINGIFY(BLENDER_MAX_THREADS) "], 0 for systems processor count."
- "(This must be the first argument)"
  ;
  static int arg_handle_threads_set(int argc, const char **argv, void *UNUSED(data))
  {
        }
  }
  
 -static const char arg_handle_depsgraph_use_new_doc[] =
 -"\n\tUse new dependency graph"
 -;
 -static int arg_handle_depsgraph_use_new(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
 -{
 -      printf("Using new dependency graph.\n");
 -      DEG_depsgraph_switch_to_new();
 -      return 0;
 -}
 -
 -static const char arg_handle_basic_shader_glsl_use_new_doc[] =
 -"\n\tUse new GLSL basic shader"
 -;
 -static int arg_handle_basic_shader_glsl_use_new(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
 -{
 -      printf("Using new GLSL basic shader.\n");
 -      GPU_basic_shader_use_glsl_set(true);
 -      return 0;
 -}
 -
  static const char arg_handle_verbosity_set_doc[] =
  "<verbose>\n"
  "\tSet logging verbosity level."
@@@ -1820,6 -1842,9 +1819,6 @@@ void main_args_setup(bContext *C, bArg
        BLI_argsAdd(ba, 1, NULL, "--debug-gpumem",
                    CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_MEM);
  
 -      BLI_argsAdd(ba, 1, NULL, "--enable-new-depsgraph", CB(arg_handle_depsgraph_use_new), NULL);
 -      BLI_argsAdd(ba, 1, NULL, "--enable-new-basic-shader-glsl", CB(arg_handle_basic_shader_glsl_use_new), NULL);
 -
        BLI_argsAdd(ba, 1, NULL, "--verbose", CB(arg_handle_verbosity_set), NULL);
  
        BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL);
index 9042b804be907877a1dc5318c767c6f3a25ce0f6,1ee5ce8b88a45ddee14bab207c7360ad6b199c99..5240a4144c9b56125bc87d240f0f6abe52d511b8
@@@ -462,7 -462,7 +462,7 @@@ if(WITH_ALEMBIC
                        COMMAND
                                "$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>"
                                ${CMAKE_CURRENT_LIST_DIR}/alembic_tests.py
-                       --blender "${TEST_BLENDER_EXE_BARE}"
+                       --blender "$<TARGET_FILE:blender>"
                        --testdir "${TEST_SRC_DIR}/alembic"
                        --alembic-root "${ALEMBIC_ROOT_DIR}"
                )
                )
        endif()
  endif()
 +
 +add_subdirectory(render_layer)