Changeset View
Changeset View
Standalone View
Standalone View
source/blender/alembic/intern/abc_exporter.cc
| Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | AbcExporter::AbcExporter(Scene *scene, const char *filename, ExportSettings &settings) | ||||
| , m_trans_sampling_index(0) | , m_trans_sampling_index(0) | ||||
| , m_shape_sampling_index(0) | , m_shape_sampling_index(0) | ||||
| , m_scene(scene) | , m_scene(scene) | ||||
| , m_writer(NULL) | , m_writer(NULL) | ||||
| {} | {} | ||||
| AbcExporter::~AbcExporter() | AbcExporter::~AbcExporter() | ||||
| { | { | ||||
| std::map<std::string, AbcTransformWriter*>::iterator it, e; | /* Free xforms map */ | ||||
| for (it = m_xforms.begin(), e = m_xforms.end(); it != e; ++it) { | m_xforms_type::iterator it_x, e_x; | ||||
| delete it->second; | for (it_x = m_xforms.begin(), e_x = m_xforms.end(); it_x != e_x; ++it_x) { | ||||
| delete it_x->second; | |||||
| } | } | ||||
| /* Free shapes vector */ | |||||
| for (int i = 0, e = m_shapes.size(); i != e; ++i) { | for (int i = 0, e = m_shapes.size(); i != e; ++i) { | ||||
| delete m_shapes[i]; | delete m_shapes[i]; | ||||
| } | } | ||||
dfelinto: In this case there is no need to change the loop logic. | |||||
| delete m_writer; | delete m_writer; | ||||
| } | } | ||||
| void AbcExporter::getShutterSamples(double step, bool time_relative, | void AbcExporter::getShutterSamples(double step, bool time_relative, | ||||
| std::vector<double> &samples) | std::vector<double> &samples) | ||||
| { | { | ||||
| samples.clear(); | samples.clear(); | ||||
| ▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | if (shape_frames.count(frame) != 0) { | ||||
| m_shapes[i]->write(); | m_shapes[i]->write(); | ||||
| } | } | ||||
| } | } | ||||
| if (xform_frames.count(frame) == 0) { | if (xform_frames.count(frame) == 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| std::map<std::string, AbcTransformWriter *>::iterator xit, xe; | m_xforms_type::iterator xit, xe; | ||||
| for (xit = m_xforms.begin(), xe = m_xforms.end(); xit != xe; ++xit) { | for (xit = m_xforms.begin(), xe = m_xforms.end(); xit != xe; ++xit) { | ||||
| xit->second->write(); | xit->second->write(); | ||||
| } | } | ||||
| /* Save the archive 's bounding box. */ | /* Save the archive 's bounding box. */ | ||||
| Imath::Box3d bounds; | Imath::Box3d bounds; | ||||
| for (xit = m_xforms.begin(), xe = m_xforms.end(); xit != xe; ++xit) { | for (xit = m_xforms.begin(), xe = m_xforms.end(); xit != xe; ++xit) { | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | while (link) { | ||||
| link = link->next; | link = link->next; | ||||
| } | } | ||||
| } | } | ||||
| free_object_duplilist(lb); | free_object_duplilist(lb); | ||||
| } | } | ||||
| void AbcExporter::createTransformWriter(Object *ob, Object *parent, Object *dupliObParent) | AbcTransformWriter * AbcExporter::createTransformWriter(Object *ob, Object *parent, Object *dupliObParent) | ||||
| { | { | ||||
| const std::string name = get_object_dag_path_name(ob, dupliObParent); | const std::string name = get_object_dag_path_name(ob, dupliObParent); | ||||
| /* An object should not be its own parent, or we'll get infinite loops. */ | /* An object should not be its own parent, or we'll get infinite loops. */ | ||||
| BLI_assert(ob != parent); | BLI_assert(ob != parent); | ||||
| BLI_assert(ob != dupliObParent); | BLI_assert(ob != dupliObParent); | ||||
| /* check if we have already created a transform writer for this object */ | /* check if we have already created a transform writer for this object */ | ||||
| if (getXForm(name) != NULL){ | AbcTransformWriter *my_writer = getXForm(name); | ||||
| std::cerr << "xform " << name << " already exists\n"; | if (my_writer != NULL){ | ||||
| return; | return my_writer; | ||||
| } | } | ||||
| AbcTransformWriter *parent_xform = NULL; | AbcTransformWriter *parent_writer = NULL; | ||||
| Alembic::Abc::OObject alembic_parent; | |||||
| if (parent) { | if (parent) { | ||||
| const std::string parentname = get_object_dag_path_name(parent, dupliObParent); | /* Since there are so many different ways to find parents (as evident | ||||
| parent_xform = getXForm(parentname); | * in the number of conditions below), we can't really look up the | ||||
| * parent by name. We'll just call createTransformWriter(), which will | |||||
| if (!parent_xform) { | * return the parent's AbcTransformWriter pointer. */ | ||||
| if (parent->parent) { | if (parent->parent) { | ||||
| createTransformWriter(parent, parent->parent, dupliObParent); | parent_writer = createTransformWriter(parent, parent->parent, dupliObParent); | ||||
| } | } | ||||
| else if (parent == dupliObParent) { | else if (parent == dupliObParent) { | ||||
| if (dupliObParent->parent == NULL) { | if (dupliObParent->parent == NULL) { | ||||
| createTransformWriter(parent, NULL, NULL); | parent_writer = createTransformWriter(parent, NULL, NULL); | ||||
| } | } | ||||
| else { | else { | ||||
| createTransformWriter(parent, dupliObParent->parent, dupliObParent->parent); | parent_writer = createTransformWriter(parent, dupliObParent->parent, dupliObParent->parent); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| createTransformWriter(parent, dupliObParent, dupliObParent); | parent_writer = createTransformWriter(parent, dupliObParent, dupliObParent); | ||||
| } | |||||
| parent_xform = getXForm(parentname); | |||||
| } | |||||
| } | } | ||||
| if (parent_xform) { | BLI_assert(parent_writer); | ||||
| m_xforms[name] = new AbcTransformWriter(ob, parent_xform->alembicXform(), parent_xform, m_trans_sampling_index, m_settings); | alembic_parent = parent_writer->alembicXform(); | ||||
Done Inline ActionsI would suggest bring this inside the '''if (parent)''' body. dfelinto: I would suggest bring this inside the '''if (parent)''' body. | |||||
| m_xforms[name]->setParent(parent); | |||||
| } | } | ||||
| else { | else { | ||||
| m_xforms[name] = new AbcTransformWriter(ob, m_writer->archive().getTop(), NULL, m_trans_sampling_index, m_settings); | /* Parentless objects still have the "top object" as parent | ||||
| * in Alembic. */ | |||||
| alembic_parent = m_writer->archive().getTop(); | |||||
| } | } | ||||
| my_writer = new AbcTransformWriter(ob, alembic_parent, parent_writer, | |||||
| m_trans_sampling_index, m_settings); | |||||
| m_xforms[name] = my_writer; | |||||
| return my_writer; | |||||
| } | } | ||||
| void AbcExporter::createShapeWriters(EvaluationContext *eval_ctx) | void AbcExporter::createShapeWriters(EvaluationContext *eval_ctx) | ||||
| { | { | ||||
| Base *base = static_cast<Base *>(m_scene->base.first); | Base *base = static_cast<Base *>(m_scene->base.first); | ||||
| while (base) { | while (base) { | ||||
| Object *ob = base->object; | Object *ob = base->object; | ||||
| ▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines | |||||
In this case there is no need to change the loop logic.