diff options
Diffstat (limited to 'source/blender/alembic')
-rw-r--r-- | source/blender/alembic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_exporter.cc | 85 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_exporter.h | 9 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_mesh.cc | 7 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_object.cc | 1 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_util.cc | 36 | ||||
-rw-r--r-- | source/blender/alembic/intern/abc_util.h | 4 | ||||
-rw-r--r-- | source/blender/alembic/intern/alembic_capi.cc | 48 |
8 files changed, 106 insertions, 85 deletions
diff --git a/source/blender/alembic/CMakeLists.txt b/source/blender/alembic/CMakeLists.txt index a6e0be6a7f3..aa12b726d6b 100644 --- a/source/blender/alembic/CMakeLists.txt +++ b/source/blender/alembic/CMakeLists.txt @@ -29,6 +29,7 @@ set(INC ../blenlib ../blenloader ../bmesh + ../depsgraph ../editors/include ../makesdna ../makesrna diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc index 3f359990980..e3dd2b968be 100644 --- a/source/blender/alembic/intern/abc_exporter.cc +++ b/source/blender/alembic/intern/abc_exporter.cc @@ -132,32 +132,32 @@ static bool object_type_is_exportable(Object *ob) * 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 in question. + * @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. */ -static bool export_object(const ExportSettings * const settings, Object *ob, +static bool export_object(const ExportSettings * const settings, const Base * const ob_base, bool is_duplicated) { 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 && !parent_selected(ob)) { + if (settings->selected_only && !object_selected(ob_base)) { return false; } - - if (settings->visible_layers_only && !(settings->scene->lay & ob->lay)) { + // FIXME Sybren: handle these cleanly (maybe just remove code), now using active scene layer instead. + if (settings->visible_layers_only && (ob_base->flag & BASE_VISIBLED) == 0) { return false; } } - if (settings->renderable_only && (ob->restrictflag & OB_RESTRICT_RENDER)) { - return false; - } + // if (settings->renderable_only && (ob->restrictflag & OB_RESTRICT_RENDER)) { + // return false; + // } return true; } @@ -354,32 +354,32 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled) 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_MBALL: - 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; } } -void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent) +void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent) { + Object *ob = ob_base->object; + /* If an object isn't exported itself, its duplilist shouldn't be * exported either. */ - if (!export_object(&m_settings, ob, dupliObParent != NULL)) { + if (!export_object(&m_settings, ob_base, dupliObParent != NULL)) { return; } @@ -390,6 +390,9 @@ void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Object *ob, Obje ListBase *lb = object_duplilist(eval_ctx, m_scene, ob); if (lb) { + Base fake_base = *ob_base; // copy flags (like selection state) from the real object. + fake_base.next = fake_base.prev = NULL; + DupliObject *link = static_cast<DupliObject *>(lb->first); Object *dupli_ob = NULL; Object *dupli_parent = NULL; @@ -404,7 +407,8 @@ void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Object *ob, Obje dupli_ob = link->ob; dupli_parent = (dupli_ob->parent) ? dupli_ob->parent : ob; - exploreTransform(eval_ctx, dupli_ob, dupli_parent, ob); + fake_base.object = dupli_ob; + exploreTransform(eval_ctx, &fake_base, dupli_parent, ob); } } } @@ -483,29 +487,28 @@ AbcTransformWriter * AbcExporter::createTransformWriter(Object *ob, Object *pare void AbcExporter::createShapeWriters(EvaluationContext *eval_ctx) { - Base *base = static_cast<Base *>(m_scene->base.first); - - while (base) { - Object *ob = base->object; - exploreObject(eval_ctx, ob, NULL); - - base = base->next; + for (Base *base = static_cast<Base *>(m_settings.sl->object_bases.first); base; base = base->next) { + exploreObject(eval_ctx, base, NULL); } } -void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Object *ob, Object *dupliObParent) +void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent) { /* If an object isn't exported itself, its duplilist shouldn't be * exported either. */ - if (!export_object(&m_settings, ob, dupliObParent != NULL)) { + if (!export_object(&m_settings, ob_base, dupliObParent != NULL)) { return; } - createShapeWriter(ob, dupliObParent); + createShapeWriter(ob_base, dupliObParent); + Object *ob = ob_base->object; ListBase *lb = object_duplilist(eval_ctx, m_scene, ob); if (lb) { + Base fake_base = *ob_base; // copy flags (like selection state) from the real object. + fake_base.next = fake_base.prev = NULL; + DupliObject *link = static_cast<DupliObject *>(lb->first); for (; link; link = link->next) { @@ -513,9 +516,9 @@ void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Object *ob, Object if (m_settings.renderable_only && link->no_draw) { continue; } - if (link->type == OB_DUPLIGROUP) { - exploreObject(eval_ctx, link->ob, ob); + fake_base.object = link->ob; + exploreObject(eval_ctx, &fake_base, ob); } } } @@ -546,8 +549,10 @@ void AbcExporter::createParticleSystemsWriters(Object *ob, AbcTransformWriter *x } } -void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent) +void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent) { + Object *ob = ob_base->object; + if (!object_type_is_exportable(ob)) { return; } @@ -632,5 +637,5 @@ void AbcExporter::setCurrentFrame(Main *bmain, double t) { m_scene->r.cfra = static_cast<int>(t); m_scene->r.subframe = static_cast<float>(t) - m_scene->r.cfra; - BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, m_scene, m_scene->lay); + BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, m_scene); } diff --git a/source/blender/alembic/intern/abc_exporter.h b/source/blender/alembic/intern/abc_exporter.h index f763922a73b..15158a9ef51 100644 --- a/source/blender/alembic/intern/abc_exporter.h +++ b/source/blender/alembic/intern/abc_exporter.h @@ -38,11 +38,14 @@ struct EvaluationContext; struct Main; struct Object; struct Scene; +struct SceneLayer; +struct Base; struct ExportSettings { ExportSettings(); Scene *scene; + SceneLayer *sl; // Scene layer to export; all its objects will be exported, unless selected_only=true SimpleLogger logger; bool selected_only; @@ -114,10 +117,10 @@ private: void createTransformWritersHierarchy(EvaluationContext *eval_ctx); AbcTransformWriter * createTransformWriter(Object *ob, Object *parent, Object *dupliObParent); - void exploreTransform(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent = NULL); - void exploreObject(EvaluationContext *eval_ctx, Object *ob, Object *dupliObParent); + void exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent); + void exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent); void createShapeWriters(EvaluationContext *eval_ctx); - void createShapeWriter(Object *ob, Object *dupliObParent); + void createShapeWriter(Base *ob_base, Object *dupliObParent); void createParticleSystemsWriters(Object *ob, AbcTransformWriter *xform); AbcTransformWriter *getXForm(const std::string &name); diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc index 9a4ca6f99a8..bc62db5702c 100644 --- a/source/blender/alembic/intern/abc_mesh.cc +++ b/source/blender/alembic/intern/abc_mesh.cc @@ -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" @@ -918,12 +917,6 @@ static void *add_customdata_cb(void *user_data, const char *name, int data_type) numloops = dm->getNumLoops(dm); cd_ptr = CustomData_add_layer_named(loopdata, cd_data_type, CD_DEFAULT, NULL, numloops, name); - if (cd_data_type == CD_MLOOPUV) { - CustomData_add_layer_named(dm->getPolyDataLayout(dm), - CD_MTEXPOLY, CD_DEFAULT, - NULL, numloops, name); - } - return cd_ptr; } diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc index 04f6da48711..8b169988096 100644 --- a/source/blender/alembic/intern/abc_object.cc +++ b/source/blender/alembic/intern/abc_object.cc @@ -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" diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc index 26eb7620fb1..8601dff54ed 100644 --- a/source/blender/alembic/intern/abc_util.cc +++ b/source/blender/alembic/intern/abc_util.cc @@ -35,6 +35,7 @@ extern "C" { #include "DNA_object_types.h" +#include "DNA_layer_types.h" #include "BLI_math.h" @@ -60,6 +61,15 @@ std::string get_id_name(const ID * const id) return name; } +/** + * @brief get_object_dag_path_name returns the name under which the object + * will be exported in the Alembic file. It is of the form + * "[../grandparent/]parent/object" if dupli_parent is NULL, or + * "dupli_parent/[../grandparent/]parent/object" otherwise. + * @param ob + * @param dupli_parent + * @return + */ std::string get_object_dag_path_name(const Object * const ob, Object *dupli_parent) { std::string name = get_id_name(ob); @@ -78,31 +88,9 @@ std::string get_object_dag_path_name(const Object * const ob, Object *dupli_pare return name; } -bool object_selected(Object *ob) -{ - return ob->flag & SELECT; -} - -bool parent_selected(Object *ob) +bool object_selected(const Base * const ob_base) { - if (object_selected(ob)) { - return true; - } - - bool do_export = false; - - Object *parent = ob->parent; - - while (parent != NULL) { - if (object_selected(parent)) { - do_export = true; - break; - } - - parent = parent->parent; - } - - return do_export; + return ob_base->flag & SELECT; } Imath::M44d convert_matrix(float mat[4][4]) diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h index 74d0faf97d3..4c6bd7d5412 100644 --- a/source/blender/alembic/intern/abc_util.h +++ b/source/blender/alembic/intern/abc_util.h @@ -48,13 +48,13 @@ struct ImportSettings; struct ID; struct Object; +struct Base; std::string get_id_name(const ID * const id); std::string get_id_name(const Object * const ob); std::string get_object_dag_path_name(const Object * const ob, Object *dupli_parent); -bool object_selected(Object *ob); -bool parent_selected(Object *ob); +bool object_selected(const Base * const ob_base); Imath::M44d convert_matrix(float mat[4][4]); diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc index be454050098..54b49330355 100644 --- a/source/blender/alembic/intern/alembic_capi.cc +++ b/source/blender/alembic/intern/alembic_capi.cc @@ -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 @@ -269,8 +272,7 @@ static void export_startjob(void *customdata, short *stop, short *do_update, flo 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; @@ -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_samples_xform = params->frame_samples_xform; job->settings.frame_samples_shape = params->frame_samples_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; @@ -345,8 +358,13 @@ bool ABC_export( 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; @@ -606,6 +624,7 @@ enum { struct ImportJobData { Main *bmain; Scene *scene; + SceneLayer *scene_layer; char filename[1024]; ImportSettings settings; @@ -807,20 +826,32 @@ static void import_endjob(void *user_data) 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_get_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) { @@ -863,6 +894,7 @@ bool ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence 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); |