Alembic: using Base* instead of Object* to get selection

I also added some remarks & TODOs to indicate work in progress.
This commit is contained in:
Sybren A. Stüvel 2017-02-09 14:42:08 +01:00
parent 48a6aa3499
commit ae6e9401ab
Notes: blender-bot 2023-02-14 02:22:07 +01:00
Referenced by commit 834e87af7b, Alembic: remove non-functional "Renderable Objects" only option
5 changed files with 77 additions and 54 deletions

View File

@ -123,19 +123,19 @@ static bool object_is_shape(Object *ob)
}
}
static bool export_object(const ExportSettings * const settings, Object *ob)
static bool export_object(const ExportSettings * const settings, const Base * const ob_base)
{
if (settings->selected_only && !object_selected(ob)) {
if (settings->selected_only && !object_selected(ob_base)) {
return false;
}
// 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->visible_layers_only && !(settings->scene->lay & ob->lay)) {
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;
}
@ -341,12 +341,10 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled)
void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx)
{
BaseLegacy *base = static_cast<BaseLegacy *>(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;
if (export_object(&m_settings, ob)) {
if (export_object(&m_settings, base)) {
switch(ob->type) {
case OB_LAMP:
case OB_LATTICE:
@ -356,53 +354,49 @@ void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx)
break;
default:
exploreTransform(eval_ctx, ob, ob->parent, NULL);
exploreTransform(eval_ctx, base, ob->parent, NULL);
}
}
base = base->next;
}
}
void AbcExporter::createTransformWritersFlat()
{
BaseLegacy *base = static_cast<BaseLegacy *>(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;
if (export_object(&m_settings, ob) && object_is_shape(ob)) {
if (!export_object(&m_settings, base)) {
std::string name = get_id_name(ob);
m_xforms[name] = new AbcTransformWriter(ob, m_writer->archive().getTop(), 0, m_trans_sampling_index, m_settings);
}
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 (export_object(&m_settings, ob) && object_is_shape(ob)) {
if (export_object(&m_settings, ob_base) && object_is_shape(ob)) {
createTransformWriter(ob, parent, dupliObParent);
}
ListBase *lb = object_duplilist(eval_ctx, m_scene, ob);
if (lb) {
DupliObject *link = static_cast<DupliObject *>(lb->first);
Object *dupli_ob = NULL;
Object *dupli_parent = NULL;
while (link) {
Base fake_base = *ob_base; // copy flags (like selection state) from the real object.
fake_base.next = fake_base.prev = NULL;
for (DupliObject *link = static_cast<DupliObject *>(lb->first); link; link = link->next) {
Object *dupli_ob = NULL;
Object *dupli_parent = NULL;
if (link->type == OB_DUPLIGROUP) {
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);
}
link = link->next;
}
}
@ -460,44 +454,42 @@ void AbcExporter::createTransformWriter(Object *ob, Object *parent, Object *dupl
void AbcExporter::createShapeWriters(EvaluationContext *eval_ctx)
{
BaseLegacy *base = static_cast<BaseLegacy *>(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)
{
Object *ob = ob_base->object;
ListBase *lb = object_duplilist(eval_ctx, m_scene, ob);
createShapeWriter(ob, dupliObParent);
createShapeWriter(ob_base, dupliObParent);
if (lb) {
DupliObject *dupliob = static_cast<DupliObject *>(lb->first);
Base fake_base = *ob_base; // copy flags (like selection state) from the real object.
fake_base.next = fake_base.prev = NULL;
while (dupliob) {
for (DupliObject *dupliob = static_cast<DupliObject *>(lb->first); dupliob; dupliob = dupliob->next) {
if (dupliob->type == OB_DUPLIGROUP) {
exploreObject(eval_ctx, dupliob->ob, ob);
fake_base.object = dupliob->ob;
exploreObject(eval_ctx, &fake_base, ob);
}
dupliob = dupliob->next;
}
}
free_object_duplilist(lb);
}
void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent)
{
Object *ob = ob_base->object;
if (!object_is_shape(ob)) {
return;
}
if (!export_object(&m_settings, ob)) {
if (!export_object(&m_settings, ob_base)) {
return;
}

View File

@ -36,11 +36,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
bool selected_only;
bool visible_layers_only;
@ -105,10 +108,10 @@ private:
void createTransformWritersHierarchy(EvaluationContext *eval_ctx);
void createTransformWritersFlat();
void 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);
AbcTransformWriter *getXForm(const std::string &name);

View File

@ -35,6 +35,7 @@
extern "C" {
#include "DNA_object_types.h"
#include "DNA_layer_types.h"
#include "BLI_math.h"
}
@ -58,6 +59,16 @@ std::string get_id_name(ID *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(Object *ob, Object *dupli_parent)
{
std::string name = get_id_name(ob);
@ -76,9 +87,9 @@ std::string get_object_dag_path_name(Object *ob, Object *dupli_parent)
return name;
}
bool object_selected(Object *ob)
bool object_selected(const Base * const ob_base)
{
return ob->flag & SELECT;
return ob_base->flag & SELECT;
}
Imath::M44d convert_matrix(float mat[4][4])

View File

@ -43,12 +43,13 @@ struct ImportSettings;
struct ID;
struct Object;
struct Base;
std::string get_id_name(ID *id);
std::string get_id_name(Object *ob);
std::string get_object_dag_path_name(Object *ob, Object *dupli_parent);
bool object_selected(Object *ob);
bool object_selected(const Base * const ob_base);
Imath::M44d convert_matrix(float mat[4][4]);
void create_transform_matrix(float r_mat[4][4]);

View File

@ -332,21 +332,37 @@ void ABC_export(
BLI_strncpy(job->filename, filepath, 1024);
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_vcols = params->vcolors;
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;