2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Esteban Tovagliari, Cedric Paille, Kevin Dietrich
20 * ***** END GPL LICENSE BLOCK *****
23 #include "../ABC_alembic.h"
24 #include <boost/foreach.hpp>
26 #include <Alembic/AbcMaterial/IMaterial.h>
28 #include "abc_archive.h"
29 #include "abc_camera.h"
30 #include "abc_curves.h"
33 #include "abc_nurbs.h"
34 #include "abc_points.h"
35 #include "abc_transform.h"
39 #include "MEM_guardedalloc.h"
41 #include "DNA_cachefile_types.h"
42 #include "DNA_curve_types.h"
43 #include "DNA_modifier_types.h"
44 #include "DNA_object_types.h"
45 #include "DNA_scene_types.h"
47 #include "BKE_cachefile.h"
48 #include "BKE_cdderivedmesh.h"
49 #include "BKE_context.h"
50 #include "BKE_curve.h"
51 #include "BKE_depsgraph.h"
52 #include "BKE_global.h"
53 #include "BKE_library.h"
55 #include "BKE_scene.h"
57 /* SpaceType struct has a member called 'new' which obviously conflicts with C++
58 * so temporarily redefining the new keyword to make it compile. */
59 #define new extern_new
60 #include "BKE_screen.h"
63 #include "BLI_fileops.h"
64 #include "BLI_ghash.h"
65 #include "BLI_listbase.h"
67 #include "BLI_path_util.h"
68 #include "BLI_string.h"
74 using Alembic::Abc::Int32ArraySamplePtr;
75 using Alembic::Abc::ObjectHeader;
77 using Alembic::AbcGeom::MetaData;
78 using Alembic::AbcGeom::P3fArraySamplePtr;
79 using Alembic::AbcGeom::kWrapExisting;
81 using Alembic::AbcGeom::ICamera;
82 using Alembic::AbcGeom::ICurves;
83 using Alembic::AbcGeom::ICurvesSchema;
84 using Alembic::AbcGeom::IFaceSet;
85 using Alembic::AbcGeom::ILight;
86 using Alembic::AbcGeom::INuPatch;
87 using Alembic::AbcGeom::IObject;
88 using Alembic::AbcGeom::IPoints;
89 using Alembic::AbcGeom::IPointsSchema;
90 using Alembic::AbcGeom::IPolyMesh;
91 using Alembic::AbcGeom::IPolyMeshSchema;
92 using Alembic::AbcGeom::ISampleSelector;
93 using Alembic::AbcGeom::ISubD;
94 using Alembic::AbcGeom::IV2fGeomParam;
95 using Alembic::AbcGeom::IXform;
96 using Alembic::AbcGeom::IXformSchema;
97 using Alembic::AbcGeom::N3fArraySamplePtr;
98 using Alembic::AbcGeom::XformSample;
99 using Alembic::AbcGeom::ICompoundProperty;
100 using Alembic::AbcGeom::IN3fArrayProperty;
101 using Alembic::AbcGeom::IN3fGeomParam;
102 using Alembic::AbcGeom::V3fArraySamplePtr;
104 using Alembic::AbcMaterial::IMaterial;
106 struct AbcArchiveHandle {
110 ABC_INLINE ArchiveReader *archive_from_handle(AbcArchiveHandle *handle)
112 return reinterpret_cast<ArchiveReader *>(handle);
115 ABC_INLINE AbcArchiveHandle *handle_from_archive(ArchiveReader *archive)
117 return reinterpret_cast<AbcArchiveHandle *>(archive);
122 /* NOTE: this function is similar to visit_objects below, need to keep them in
124 static bool gather_objects_paths(const IObject &object, ListBase *object_paths)
126 if (!object.valid()) {
131 size_t children_claiming_this_object = 0;
132 size_t num_children = object.getNumChildren();
134 for (size_t i = 0; i < num_children; ++i) {
135 bool child_claims_this_object = gather_objects_paths(object.getChild(i), object_paths);
136 children_claiming_this_object += child_claims_this_object ? 1 : 0;
139 const MetaData &md = object.getMetaData();
140 bool get_path = false;
141 bool parent_is_part_of_this_object = false;
143 if (!object.getParent()) {
144 /* The root itself is not an object we should import. */
146 else if (IXform::matches(md)) {
147 if (has_property(object.getProperties(), "locator")) {
151 get_path = children_claiming_this_object == 0;
154 /* Transforms are never "data" for their parent. */
155 parent_is_part_of_this_object = false;
158 /* These types are "data" for their parent. */
160 IPolyMesh::matches(md) ||
161 ISubD::matches(md) ||
163 INuPatch::matches(md) ||
165 ICamera::matches(md) ||
166 IPoints::matches(md) ||
167 ICurves::matches(md);
168 parent_is_part_of_this_object = get_path;
172 void *abc_path_void = MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath");
173 AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(abc_path_void);
175 BLI_strncpy(abc_path->path, object.getFullName().c_str(), PATH_MAX);
176 BLI_addtail(object_paths, abc_path);
179 return parent_is_part_of_this_object;
182 AbcArchiveHandle *ABC_create_handle(const char *filename, ListBase *object_paths)
184 ArchiveReader *archive = new ArchiveReader(filename);
186 if (!archive->valid()) {
192 gather_objects_paths(archive->getTop(), object_paths);
195 return handle_from_archive(archive);
198 void ABC_free_handle(AbcArchiveHandle *handle)
200 delete archive_from_handle(handle);
203 int ABC_get_version()
205 return ALEMBIC_LIBRARY_VERSION;
208 static void find_iobject(const IObject &object, IObject &ret,
209 const std::string &path)
211 if (!object.valid()) {
215 std::vector<std::string> tokens;
216 split(path, '/', tokens);
218 IObject tmp = object;
220 std::vector<std::string>::iterator iter;
221 for (iter = tokens.begin(); iter != tokens.end(); ++iter) {
222 IObject child = tmp.getChild(*iter);
229 struct ExportJobData {
234 ExportSettings settings;
243 static void export_startjob(void *customdata, short *stop, short *do_update, float *progress)
245 ExportJobData *data = static_cast<ExportJobData *>(customdata);
248 data->do_update = do_update;
249 data->progress = progress;
251 /* XXX annoying hack: needed to prevent data corruption when changing
252 * scene frame in separate threads
254 G.is_rendering = true;
255 BKE_spacedata_draw_locks(true);
260 Scene *scene = data->scene;
261 AbcExporter exporter(scene, data->filename, data->settings);
263 const int orig_frame = CFRA;
265 data->was_canceled = false;
266 exporter(data->bmain, *data->progress, data->was_canceled);
268 if (CFRA != orig_frame) {
271 BKE_scene_update_for_newframe(data->bmain->eval_ctx, data->bmain,
275 catch (const std::exception &e) {
276 ABC_LOG(data->settings.logger) << "Abc Export error: " << e.what() << '\n';
279 ABC_LOG(data->settings.logger) << "Abc Export: unknown error...\n";
283 static void export_endjob(void *customdata)
285 ExportJobData *data = static_cast<ExportJobData *>(customdata);
287 if (data->was_canceled && BLI_exists(data->filename)) {
288 BLI_delete(data->filename, false, false);
291 if (!data->settings.logger.empty()) {
292 std::cerr << data->settings.logger;
293 WM_report(RPT_ERROR, "Errors occured during the export, look in the console to know more...");
296 G.is_rendering = false;
297 BKE_spacedata_draw_locks(false);
303 const char *filepath,
304 const struct AlembicExportParams *params)
306 ExportJobData *job = static_cast<ExportJobData *>(MEM_mallocN(sizeof(ExportJobData), "ExportJobData"));
308 job->bmain = CTX_data_main(C);
309 BLI_strncpy(job->filename, filepath, 1024);
311 /* Alright, alright, alright....
313 * ExportJobData contains an ExportSettings containing a SimpleLogger.
315 * Since ExportJobData is a C-style struct dynamically allocated with
316 * MEM_mallocN (see above), its construtor is never called, therefore the
317 * ExportSettings constructor is not called which implies that the
318 * SimpleLogger one is not called either. SimpleLogger in turn does not call
319 * the constructor of its data members which ultimately means that its
320 * std::ostringstream member has a NULL pointer. To be able to properly use
321 * the stream's operator<<, the pointer needs to be set, therefore we have
322 * to properly construct everything. And this is done using the placement
323 * new operator as here below. It seems hackish, but I'm too lazy to
324 * do bigger refactor and maybe there is a better way which does not involve
325 * hardcore refactoring. */
326 new (&job->settings) ExportSettings();
327 job->settings.scene = job->scene;
328 job->settings.frame_start = params->frame_start;
329 job->settings.frame_end = params->frame_end;
330 job->settings.frame_step_xform = params->frame_step_xform;
331 job->settings.frame_step_shape = params->frame_step_shape;
332 job->settings.shutter_open = params->shutter_open;
333 job->settings.shutter_close = params->shutter_close;
334 job->settings.selected_only = params->selected_only;
335 job->settings.export_face_sets = params->face_sets;
336 job->settings.export_normals = params->normals;
337 job->settings.export_uvs = params->uvs;
338 job->settings.export_vcols = params->vcolors;
339 job->settings.export_hair = params->export_hair;
340 job->settings.export_particles = params->export_particles;
341 job->settings.apply_subdiv = params->apply_subdiv;
342 job->settings.flatten_hierarchy = params->flatten_hierarchy;
343 job->settings.visible_layers_only = params->visible_layers_only;
344 job->settings.renderable_only = params->renderable_only;
345 job->settings.use_subdiv_schema = params->use_subdiv_schema;
346 job->settings.export_ogawa = (params->compression_type == ABC_ARCHIVE_OGAWA);
347 job->settings.pack_uv = params->packuv;
348 job->settings.global_scale = params->global_scale;
349 job->settings.triangulate = params->triangulate;
350 job->settings.quad_method = params->quad_method;
351 job->settings.ngon_method = params->ngon_method;
353 if (job->settings.frame_start > job->settings.frame_end) {
354 std::swap(job->settings.frame_start, job->settings.frame_end);
357 wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
362 WM_JOB_TYPE_ALEMBIC);
365 WM_jobs_customdata_set(wm_job, job, MEM_freeN);
366 WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_FRAME, NC_SCENE | ND_FRAME);
367 WM_jobs_callbacks(wm_job, export_startjob, NULL, NULL, export_endjob);
369 WM_jobs_start(CTX_wm_manager(C), wm_job);
372 /* ********************** Import file ********************** */
375 * Generates an AbcObjectReader for this Alembic object and its children.
377 * \param object The Alembic IObject to visit.
378 * \param readers The created AbcObjectReader * will be appended to this vector.
379 * \param settings Import settings, not used directly but passed to the
380 * AbcObjectReader subclass constructors.
381 * \param r_assign_as_parent Return parameter, contains a list of reader
382 * pointers, whose parent pointer should still be set.
383 * This is filled when this call to visit_object() didn't create
384 * a reader that should be the parent.
385 * \return A pair of boolean and reader pointer. The boolean indicates whether
386 * this IObject claims its parent as part of the same object
387 * (for example an IPolyMesh object would claim its parent, as the mesh
388 * is interpreted as the object's data, and the parent IXform as its
389 * Blender object). The pointer is the AbcObjectReader that represents
390 * the IObject parameter.
392 * NOTE: this function is similar to gather_object_paths above, need to keep
394 static std::pair<bool, AbcObjectReader *> visit_object(
395 const IObject &object,
396 AbcObjectReader::ptr_vector &readers,
397 ImportSettings &settings,
398 AbcObjectReader::ptr_vector &r_assign_as_parent)
400 const std::string & full_name = object.getFullName();
402 if (!object.valid()) {
405 << ": object is invalid, skipping it and all its children.\n";
406 return std::make_pair(false, static_cast<AbcObjectReader *>(NULL));
409 /* The interpretation of data by the children determine the role of this
410 * object. This is especially important for Xform objects, as they can be
411 * either part of a Blender object or a Blender object (Empty) themselves.
413 size_t children_claiming_this_object = 0;
414 size_t num_children = object.getNumChildren();
415 AbcObjectReader::ptr_vector claiming_child_readers;
416 AbcObjectReader::ptr_vector nonclaiming_child_readers;
417 AbcObjectReader::ptr_vector assign_as_parent;
418 for (size_t i = 0; i < num_children; ++i) {
419 const IObject ichild = object.getChild(i);
421 /* TODO: When we only support C++11, use std::tie() instead. */
422 std::pair<bool, AbcObjectReader *> child_result;
423 child_result = visit_object(ichild, readers, settings, assign_as_parent);
425 bool child_claims_this_object = child_result.first;
426 AbcObjectReader *child_reader = child_result.second;
428 if (child_reader == NULL) {
429 BLI_assert(!child_claims_this_object);
432 if (child_claims_this_object) {
433 claiming_child_readers.push_back(child_reader);
435 nonclaiming_child_readers.push_back(child_reader);
439 children_claiming_this_object += child_claims_this_object ? 1 : 0;
441 BLI_assert(children_claiming_this_object == claiming_child_readers.size());
443 AbcObjectReader *reader = NULL;
444 const MetaData &md = object.getMetaData();
445 bool parent_is_part_of_this_object = false;
447 if (!object.getParent()) {
448 /* The root itself is not an object we should import. */
450 else if (IXform::matches(md)) {
453 /* An xform can either be a Blender Object (if it contains a mesh, for
454 * example), but it can also be an Empty. Its correct translation to
455 * Blender's data model depends on its children. */
457 /* Check whether or not this object is a Maya locator, which is
458 * similar to empties used as parent object in Blender. */
459 if (has_property(object.getProperties(), "locator")) {
463 create_empty = claiming_child_readers.empty();
467 reader = new AbcEmptyReader(object, settings);
470 else if (IPolyMesh::matches(md)) {
471 reader = new AbcMeshReader(object, settings);
472 parent_is_part_of_this_object = true;
474 else if (ISubD::matches(md)) {
475 reader = new AbcSubDReader(object, settings);
476 parent_is_part_of_this_object = true;
478 else if (INuPatch::matches(md)) {
480 /* TODO(kevin): importing cyclic NURBS from other software crashes
481 * at the moment. This is due to the fact that NURBS in other
482 * software have duplicated points which causes buffer overflows in
483 * Blender. Need to figure out exactly how these points are
484 * duplicated, in all cases (cyclic U, cyclic V, and cyclic UV).
485 * Until this is fixed, disabling NURBS reading. */
486 reader = new AbcNurbsReader(object, settings);
487 parent_is_part_of_this_object = true;
490 else if (ICamera::matches(md)) {
491 reader = new AbcCameraReader(object, settings);
492 parent_is_part_of_this_object = true;
494 else if (IPoints::matches(md)) {
495 reader = new AbcPointsReader(object, settings);
496 parent_is_part_of_this_object = true;
498 else if (IMaterial::matches(md)) {
501 else if (ILight::matches(md)) {
504 else if (IFaceSet::matches(md)) {
505 /* Pass, those are handled in the mesh reader. */
507 else if (ICurves::matches(md)) {
508 reader = new AbcCurveReader(object, settings);
509 parent_is_part_of_this_object = true;
512 std::cerr << "Alembic object " << full_name
513 << " is of unsupported schema type '"
514 << object.getMetaData().get("schemaObjTitle") << "'"
519 /* We have created a reader, which should imply that this object is
520 * not claimed as part of any child Alembic object. */
521 BLI_assert(claiming_child_readers.empty());
523 readers.push_back(reader);
526 AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(
527 MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath"));
528 BLI_strncpy(abc_path->path, full_name.c_str(), PATH_MAX);
529 BLI_addtail(&settings.cache_file->object_paths, abc_path);
531 /* We can now assign this reader as parent for our children. */
532 if (nonclaiming_child_readers.size() + assign_as_parent.size() > 0) {
533 /* TODO: When we only support C++11, use for (a: b) instead. */
534 BOOST_FOREACH(AbcObjectReader *child_reader, nonclaiming_child_readers) {
535 child_reader->parent_reader = reader;
537 BOOST_FOREACH(AbcObjectReader *child_reader, assign_as_parent) {
538 child_reader->parent_reader = reader;
542 else if (object.getParent()) {
543 if (claiming_child_readers.size() > 0) {
544 /* The first claiming child will serve just fine as parent to
545 * our non-claiming children. Since all claiming children share
546 * the same XForm, it doesn't really matter which one we pick. */
547 AbcObjectReader *claiming_child = claiming_child_readers[0];
548 BOOST_FOREACH(AbcObjectReader *child_reader, nonclaiming_child_readers) {
549 child_reader->parent_reader = claiming_child;
551 BOOST_FOREACH(AbcObjectReader *child_reader, assign_as_parent) {
552 child_reader->parent_reader = claiming_child;
554 /* Claiming children should have our parent set as their parent. */
555 BOOST_FOREACH(AbcObjectReader *child_reader, claiming_child_readers) {
556 r_assign_as_parent.push_back(child_reader);
560 /* This object isn't claimed by any child, and didn't produce
561 * a reader. Odd situation, could be the top Alembic object, or
562 * an unsupported Alembic schema. Delegate to our parent. */
563 BOOST_FOREACH(AbcObjectReader *child_reader, claiming_child_readers) {
564 r_assign_as_parent.push_back(child_reader);
566 BOOST_FOREACH(AbcObjectReader *child_reader, nonclaiming_child_readers) {
567 r_assign_as_parent.push_back(child_reader);
569 BOOST_FOREACH(AbcObjectReader *child_reader, assign_as_parent) {
570 r_assign_as_parent.push_back(child_reader);
575 return std::make_pair(parent_is_part_of_this_object, reader);
583 struct ImportJobData {
588 ImportSettings settings;
590 std::vector<AbcObjectReader *> readers;
600 ABC_INLINE bool is_mesh_and_strands(const IObject &object)
602 bool has_mesh = false;
603 bool has_curve = false;
605 for (int i = 0; i < object.getNumChildren(); ++i) {
606 const IObject &child = object.getChild(i);
608 if (!child.valid()) {
612 const MetaData &md = child.getMetaData();
614 if (IPolyMesh::matches(md)) {
617 else if (ISubD::matches(md)) {
620 else if (ICurves::matches(md)) {
623 else if (IPoints::matches(md)) {
628 return has_mesh && has_curve;
631 static void import_startjob(void *user_data, short *stop, short *do_update, float *progress)
633 SCOPE_TIMER("Alembic import, objects reading and creation");
635 ImportJobData *data = static_cast<ImportJobData *>(user_data);
638 data->do_update = do_update;
639 data->progress = progress;
641 ArchiveReader *archive = new ArchiveReader(data->filename);
643 if (!archive->valid()) {
645 data->error_code = ABC_ARCHIVE_FAIL;
649 CacheFile *cache_file = static_cast<CacheFile *>(BKE_cachefile_add(data->bmain, BLI_path_basename(data->filename)));
651 /* Decrement the ID ref-count because it is going to be incremented for each
652 * modifier and constraint that it will be attached to, so since currently
653 * it is not used by anyone, its use count will off by one. */
654 id_us_min(&cache_file->id);
656 cache_file->is_sequence = data->settings.is_sequence;
657 cache_file->scale = data->settings.scale;
658 cache_file->handle = handle_from_archive(archive);
659 BLI_strncpy(cache_file->filepath, data->filename, 1024);
661 data->settings.cache_file = cache_file;
663 *data->do_update = true;
664 *data->progress = 0.05f;
666 /* Parse Alembic Archive. */
667 AbcObjectReader::ptr_vector assign_as_parent;
668 visit_object(archive->getTop(), data->readers, data->settings, assign_as_parent);
670 /* There shouldn't be any orphans. */
671 BLI_assert(assign_as_parent.size() == 0);
674 data->was_cancelled = true;
678 *data->do_update = true;
679 *data->progress = 0.1f;
681 /* Create objects and set scene frame range. */
683 const float size = static_cast<float>(data->readers.size());
686 chrono_t min_time = std::numeric_limits<chrono_t>::max();
687 chrono_t max_time = std::numeric_limits<chrono_t>::min();
689 std::vector<AbcObjectReader *>::iterator iter;
690 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
691 AbcObjectReader *reader = *iter;
693 if (reader->valid()) {
694 reader->readObjectData(data->bmain, 0.0f);
696 min_time = std::min(min_time, reader->minTime());
697 max_time = std::max(max_time, reader->maxTime());
700 std::cerr << "Object " << reader->name() << " in Alembic file "
701 << data->filename << " is invalid.\n";
704 *data->progress = 0.1f + 0.3f * (++i / size);
705 *data->do_update = true;
708 data->was_cancelled = true;
713 if (data->settings.set_frame_range) {
714 Scene *scene = data->scene;
716 if (data->settings.is_sequence) {
717 SFRA = data->settings.offset;
718 EFRA = SFRA + (data->settings.sequence_len - 1);
721 else if (min_time < max_time) {
722 SFRA = static_cast<int>(round(min_time * FPS));
723 EFRA = static_cast<int>(round(max_time * FPS));
728 /* Setup parenthood. */
729 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
730 const AbcObjectReader *reader = *iter;
731 const AbcObjectReader *parent_reader = reader->parent_reader;
732 Object *ob = reader->object();
734 if (parent_reader == NULL) {
738 ob->parent = parent_reader->object();
742 /* Setup transformations and constraints. */
744 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
745 AbcObjectReader *reader = *iter;
746 reader->setupObjectTransform(0.0f);
748 *data->progress = 0.7f + 0.3f * (++i / size);
749 *data->do_update = true;
752 data->was_cancelled = true;
758 static void import_endjob(void *user_data)
760 SCOPE_TIMER("Alembic import, cleanup");
762 ImportJobData *data = static_cast<ImportJobData *>(user_data);
764 std::vector<AbcObjectReader *>::iterator iter;
766 /* Delete objects on cancelation. */
767 if (data->was_cancelled) {
768 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
769 Object *ob = (*iter)->object();
771 /* It's possible that cancellation occured between the creation of
772 * the reader and the creation of the Blender object. */
773 if (ob == NULL) continue;
775 BKE_libblock_free_us(data->bmain, ob);
779 /* Add object to scene. */
780 BKE_scene_base_deselect_all(data->scene);
782 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
783 Object *ob = (*iter)->object();
784 ob->lay = data->scene->lay;
786 BKE_scene_base_add(data->scene, ob);
788 DAG_id_tag_update_ex(data->bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
791 DAG_relations_tag_update(data->bmain);
794 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
795 AbcObjectReader *reader = *iter;
798 if (reader->refcount() == 0) {
803 switch (data->error_code) {
807 case ABC_ARCHIVE_FAIL:
808 WM_report(RPT_ERROR, "Could not open Alembic archive for reading! See console for detail.");
812 WM_main_add_notifier(NC_SCENE | ND_FRAME, data->scene);
815 static void import_freejob(void *user_data)
817 ImportJobData *data = static_cast<ImportJobData *>(user_data);
821 void ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence, bool set_frame_range, int sequence_len, int offset, bool validate_meshes)
823 /* Using new here since MEM_* funcs do not call ctor to properly initialize
825 ImportJobData *job = new ImportJobData();
826 job->bmain = CTX_data_main(C);
827 job->scene = CTX_data_scene(C);
828 BLI_strncpy(job->filename, filepath, 1024);
830 job->settings.scale = scale;
831 job->settings.is_sequence = is_sequence;
832 job->settings.set_frame_range = set_frame_range;
833 job->settings.sequence_len = sequence_len;
834 job->settings.offset = offset;
835 job->settings.validate_meshes = validate_meshes;
836 job->error_code = ABC_NO_ERROR;
837 job->was_cancelled = false;
841 wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
846 WM_JOB_TYPE_ALEMBIC);
849 WM_jobs_customdata_set(wm_job, job, import_freejob);
850 WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_FRAME, NC_SCENE | ND_FRAME);
851 WM_jobs_callbacks(wm_job, import_startjob, NULL, NULL, import_endjob);
853 WM_jobs_start(CTX_wm_manager(C), wm_job);
856 /* ************************************************************************** */
858 void ABC_get_transform(CacheReader *reader, float r_mat[4][4], float time, float scale)
864 AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
866 bool is_constant = false;
867 abc_reader->read_matrix(r_mat, time, scale, is_constant);
870 /* ************************************************************************** */
872 DerivedMesh *ABC_read_mesh(CacheReader *reader,
876 const char **err_str,
879 AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
880 IObject iobject = abc_reader->iobject();
882 if (!iobject.valid()) {
883 *err_str = "Invalid object: verify object path";
887 const ObjectHeader &header = iobject.getHeader();
889 if (IPolyMesh::matches(header)) {
890 if (ob->type != OB_MESH) {
891 *err_str = "Object type mismatch: object path points to a mesh!";
895 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
897 else if (ISubD::matches(header)) {
898 if (ob->type != OB_MESH) {
899 *err_str = "Object type mismatch: object path points to a subdivision mesh!";
903 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
905 else if (IPoints::matches(header)) {
906 if (ob->type != OB_MESH) {
907 *err_str = "Object type mismatch: object path points to a point cloud (requires a mesh object)!";
911 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
913 else if (ICurves::matches(header)) {
914 if (ob->type != OB_CURVE) {
915 *err_str = "Object type mismatch: object path points to a curve!";
919 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
922 *err_str = "Unsupported object type: verify object path"; // or poke developer
926 /* ************************************************************************** */
928 void CacheReader_free(CacheReader *reader)
930 AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
931 abc_reader->decref();
933 if (abc_reader->refcount() == 0) {
938 CacheReader *CacheReader_open_alembic_object(AbcArchiveHandle *handle, CacheReader *reader, Object *object, const char *object_path)
940 if (object_path[0] == '\0') {
944 ArchiveReader *archive = archive_from_handle(handle);
946 if (!archive || !archive->valid()) {
951 find_iobject(archive->getTop(), iobject, object_path);
954 CacheReader_free(reader);
957 ImportSettings settings;
958 AbcObjectReader *abc_reader = create_reader(iobject, settings);
959 abc_reader->object(object);
960 abc_reader->incref();
962 return reinterpret_cast<CacheReader *>(abc_reader);