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.apply_subdiv = params->apply_subdiv;
340 job->settings.flatten_hierarchy = params->flatten_hierarchy;
341 job->settings.visible_layers_only = params->visible_layers_only;
342 job->settings.renderable_only = params->renderable_only;
343 job->settings.use_subdiv_schema = params->use_subdiv_schema;
344 job->settings.export_ogawa = (params->compression_type == ABC_ARCHIVE_OGAWA);
345 job->settings.pack_uv = params->packuv;
346 job->settings.global_scale = params->global_scale;
347 job->settings.triangulate = params->triangulate;
348 job->settings.quad_method = params->quad_method;
349 job->settings.ngon_method = params->ngon_method;
351 if (job->settings.frame_start > job->settings.frame_end) {
352 std::swap(job->settings.frame_start, job->settings.frame_end);
355 wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
360 WM_JOB_TYPE_ALEMBIC);
363 WM_jobs_customdata_set(wm_job, job, MEM_freeN);
364 WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_FRAME, NC_SCENE | ND_FRAME);
365 WM_jobs_callbacks(wm_job, export_startjob, NULL, NULL, export_endjob);
367 WM_jobs_start(CTX_wm_manager(C), wm_job);
370 /* ********************** Import file ********************** */
373 * Generates an AbcObjectReader for this Alembic object and its children.
375 * \param object The Alembic IObject to visit.
376 * \param readers The created AbcObjectReader * will be appended to this vector.
377 * \param settings Import settings, not used directly but passed to the
378 * AbcObjectReader subclass constructors.
379 * \param r_assign_as_parent Return parameter, contains a list of reader
380 * pointers, whose parent pointer should still be set.
381 * This is filled when this call to visit_object() didn't create
382 * a reader that should be the parent.
383 * \return A pair of boolean and reader pointer. The boolean indicates whether
384 * this IObject claims its parent as part of the same object
385 * (for example an IPolyMesh object would claim its parent, as the mesh
386 * is interpreted as the object's data, and the parent IXform as its
387 * Blender object). The pointer is the AbcObjectReader that represents
388 * the IObject parameter.
390 * NOTE: this function is similar to gather_object_paths above, need to keep
392 static std::pair<bool, AbcObjectReader *> visit_object(
393 const IObject &object,
394 AbcObjectReader::ptr_vector &readers,
395 ImportSettings &settings,
396 AbcObjectReader::ptr_vector &r_assign_as_parent)
398 const std::string & full_name = object.getFullName();
400 if (!object.valid()) {
403 << ": object is invalid, skipping it and all its children.\n";
404 return std::make_pair(false, static_cast<AbcObjectReader *>(NULL));
407 /* The interpretation of data by the children determine the role of this
408 * object. This is especially important for Xform objects, as they can be
409 * either part of a Blender object or a Blender object (Empty) themselves.
411 size_t children_claiming_this_object = 0;
412 size_t num_children = object.getNumChildren();
413 AbcObjectReader::ptr_vector claiming_child_readers;
414 AbcObjectReader::ptr_vector nonclaiming_child_readers;
415 AbcObjectReader::ptr_vector assign_as_parent;
416 for (size_t i = 0; i < num_children; ++i) {
417 const IObject ichild = object.getChild(i);
419 /* TODO: When we only support C++11, use std::tie() instead. */
420 std::pair<bool, AbcObjectReader *> child_result;
421 child_result = visit_object(ichild, readers, settings, assign_as_parent);
423 bool child_claims_this_object = child_result.first;
424 AbcObjectReader *child_reader = child_result.second;
426 if (child_reader == NULL) {
427 BLI_assert(!child_claims_this_object);
430 if (child_claims_this_object) {
431 claiming_child_readers.push_back(child_reader);
433 nonclaiming_child_readers.push_back(child_reader);
437 children_claiming_this_object += child_claims_this_object ? 1 : 0;
439 BLI_assert(children_claiming_this_object == claiming_child_readers.size());
441 AbcObjectReader *reader = NULL;
442 const MetaData &md = object.getMetaData();
443 bool parent_is_part_of_this_object = false;
445 if (!object.getParent()) {
446 /* The root itself is not an object we should import. */
448 else if (IXform::matches(md)) {
451 /* An xform can either be a Blender Object (if it contains a mesh, for
452 * example), but it can also be an Empty. Its correct translation to
453 * Blender's data model depends on its children. */
455 /* Check whether or not this object is a Maya locator, which is
456 * similar to empties used as parent object in Blender. */
457 if (has_property(object.getProperties(), "locator")) {
461 create_empty = claiming_child_readers.empty();
465 reader = new AbcEmptyReader(object, settings);
468 else if (IPolyMesh::matches(md)) {
469 reader = new AbcMeshReader(object, settings);
470 parent_is_part_of_this_object = true;
472 else if (ISubD::matches(md)) {
473 reader = new AbcSubDReader(object, settings);
474 parent_is_part_of_this_object = true;
476 else if (INuPatch::matches(md)) {
478 /* TODO(kevin): importing cyclic NURBS from other software crashes
479 * at the moment. This is due to the fact that NURBS in other
480 * software have duplicated points which causes buffer overflows in
481 * Blender. Need to figure out exactly how these points are
482 * duplicated, in all cases (cyclic U, cyclic V, and cyclic UV).
483 * Until this is fixed, disabling NURBS reading. */
484 reader = new AbcNurbsReader(object, settings);
485 parent_is_part_of_this_object = true;
488 else if (ICamera::matches(md)) {
489 reader = new AbcCameraReader(object, settings);
490 parent_is_part_of_this_object = true;
492 else if (IPoints::matches(md)) {
493 reader = new AbcPointsReader(object, settings);
494 parent_is_part_of_this_object = true;
496 else if (IMaterial::matches(md)) {
499 else if (ILight::matches(md)) {
502 else if (IFaceSet::matches(md)) {
503 /* Pass, those are handled in the mesh reader. */
505 else if (ICurves::matches(md)) {
506 reader = new AbcCurveReader(object, settings);
507 parent_is_part_of_this_object = true;
510 std::cerr << "Alembic object " << full_name
511 << " is of unsupported schema type '"
512 << object.getMetaData().get("schemaObjTitle") << "'"
517 /* We have created a reader, which should imply that this object is
518 * not claimed as part of any child Alembic object. */
519 BLI_assert(claiming_child_readers.empty());
521 readers.push_back(reader);
524 AlembicObjectPath *abc_path = static_cast<AlembicObjectPath *>(
525 MEM_callocN(sizeof(AlembicObjectPath), "AlembicObjectPath"));
526 BLI_strncpy(abc_path->path, full_name.c_str(), PATH_MAX);
527 BLI_addtail(&settings.cache_file->object_paths, abc_path);
529 /* We can now assign this reader as parent for our children. */
530 if (nonclaiming_child_readers.size() + assign_as_parent.size() > 0) {
531 /* TODO: When we only support C++11, use for (a: b) instead. */
532 BOOST_FOREACH(AbcObjectReader *child_reader, nonclaiming_child_readers) {
533 child_reader->parent_reader = reader;
535 BOOST_FOREACH(AbcObjectReader *child_reader, assign_as_parent) {
536 child_reader->parent_reader = reader;
540 else if (object.getParent()) {
541 if (claiming_child_readers.size() > 0) {
542 /* The first claiming child will serve just fine as parent to
543 * our non-claiming children. Since all claiming children share
544 * the same XForm, it doesn't really matter which one we pick. */
545 AbcObjectReader *claiming_child = claiming_child_readers[0];
546 BOOST_FOREACH(AbcObjectReader *child_reader, nonclaiming_child_readers) {
547 child_reader->parent_reader = claiming_child;
549 BOOST_FOREACH(AbcObjectReader *child_reader, assign_as_parent) {
550 child_reader->parent_reader = claiming_child;
552 /* Claiming children should have our parent set as their parent. */
553 BOOST_FOREACH(AbcObjectReader *child_reader, claiming_child_readers) {
554 r_assign_as_parent.push_back(child_reader);
558 /* This object isn't claimed by any child, and didn't produce
559 * a reader. Odd situation, could be the top Alembic object, or
560 * an unsupported Alembic schema. Delegate to our parent. */
561 BOOST_FOREACH(AbcObjectReader *child_reader, claiming_child_readers) {
562 r_assign_as_parent.push_back(child_reader);
564 BOOST_FOREACH(AbcObjectReader *child_reader, nonclaiming_child_readers) {
565 r_assign_as_parent.push_back(child_reader);
567 BOOST_FOREACH(AbcObjectReader *child_reader, assign_as_parent) {
568 r_assign_as_parent.push_back(child_reader);
573 return std::make_pair(parent_is_part_of_this_object, reader);
581 struct ImportJobData {
586 ImportSettings settings;
588 std::vector<AbcObjectReader *> readers;
598 ABC_INLINE bool is_mesh_and_strands(const IObject &object)
600 bool has_mesh = false;
601 bool has_curve = false;
603 for (int i = 0; i < object.getNumChildren(); ++i) {
604 const IObject &child = object.getChild(i);
606 if (!child.valid()) {
610 const MetaData &md = child.getMetaData();
612 if (IPolyMesh::matches(md)) {
615 else if (ISubD::matches(md)) {
618 else if (ICurves::matches(md)) {
621 else if (IPoints::matches(md)) {
626 return has_mesh && has_curve;
629 static void import_startjob(void *user_data, short *stop, short *do_update, float *progress)
631 SCOPE_TIMER("Alembic import, objects reading and creation");
633 ImportJobData *data = static_cast<ImportJobData *>(user_data);
636 data->do_update = do_update;
637 data->progress = progress;
639 ArchiveReader *archive = new ArchiveReader(data->filename);
641 if (!archive->valid()) {
643 data->error_code = ABC_ARCHIVE_FAIL;
647 CacheFile *cache_file = static_cast<CacheFile *>(BKE_cachefile_add(data->bmain, BLI_path_basename(data->filename)));
649 /* Decrement the ID ref-count because it is going to be incremented for each
650 * modifier and constraint that it will be attached to, so since currently
651 * it is not used by anyone, its use count will off by one. */
652 id_us_min(&cache_file->id);
654 cache_file->is_sequence = data->settings.is_sequence;
655 cache_file->scale = data->settings.scale;
656 cache_file->handle = handle_from_archive(archive);
657 BLI_strncpy(cache_file->filepath, data->filename, 1024);
659 data->settings.cache_file = cache_file;
661 *data->do_update = true;
662 *data->progress = 0.05f;
664 /* Parse Alembic Archive. */
665 AbcObjectReader::ptr_vector assign_as_parent;
666 visit_object(archive->getTop(), data->readers, data->settings, assign_as_parent);
668 /* There shouldn't be any orphans. */
669 BLI_assert(assign_as_parent.size() == 0);
672 data->was_cancelled = true;
676 *data->do_update = true;
677 *data->progress = 0.1f;
679 /* Create objects and set scene frame range. */
681 const float size = static_cast<float>(data->readers.size());
684 chrono_t min_time = std::numeric_limits<chrono_t>::max();
685 chrono_t max_time = std::numeric_limits<chrono_t>::min();
687 std::vector<AbcObjectReader *>::iterator iter;
688 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
689 AbcObjectReader *reader = *iter;
691 if (reader->valid()) {
692 reader->readObjectData(data->bmain, 0.0f);
694 min_time = std::min(min_time, reader->minTime());
695 max_time = std::max(max_time, reader->maxTime());
698 std::cerr << "Object " << reader->name() << " in Alembic file "
699 << data->filename << " is invalid.\n";
702 *data->progress = 0.1f + 0.3f * (++i / size);
703 *data->do_update = true;
706 data->was_cancelled = true;
711 if (data->settings.set_frame_range) {
712 Scene *scene = data->scene;
714 if (data->settings.is_sequence) {
715 SFRA = data->settings.offset;
716 EFRA = SFRA + (data->settings.sequence_len - 1);
719 else if (min_time < max_time) {
720 SFRA = static_cast<int>(round(min_time * FPS));
721 EFRA = static_cast<int>(round(max_time * FPS));
726 /* Setup parenthood. */
727 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
728 const AbcObjectReader *reader = *iter;
729 const AbcObjectReader *parent_reader = reader->parent_reader;
730 Object *ob = reader->object();
732 if (parent_reader == NULL) {
736 ob->parent = parent_reader->object();
740 /* Setup transformations and constraints. */
742 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
743 AbcObjectReader *reader = *iter;
744 reader->setupObjectTransform(0.0f);
746 *data->progress = 0.7f + 0.3f * (++i / size);
747 *data->do_update = true;
750 data->was_cancelled = true;
756 static void import_endjob(void *user_data)
758 SCOPE_TIMER("Alembic import, cleanup");
760 ImportJobData *data = static_cast<ImportJobData *>(user_data);
762 std::vector<AbcObjectReader *>::iterator iter;
764 /* Delete objects on cancelation. */
765 if (data->was_cancelled) {
766 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
767 Object *ob = (*iter)->object();
769 /* It's possible that cancellation occured between the creation of
770 * the reader and the creation of the Blender object. */
771 if (ob == NULL) continue;
773 BKE_libblock_free_us(data->bmain, ob);
777 /* Add object to scene. */
778 BKE_scene_base_deselect_all(data->scene);
780 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
781 Object *ob = (*iter)->object();
782 ob->lay = data->scene->lay;
784 BKE_scene_base_add(data->scene, ob);
786 DAG_id_tag_update_ex(data->bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
789 DAG_relations_tag_update(data->bmain);
792 for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
793 AbcObjectReader *reader = *iter;
796 if (reader->refcount() == 0) {
801 switch (data->error_code) {
805 case ABC_ARCHIVE_FAIL:
806 WM_report(RPT_ERROR, "Could not open Alembic archive for reading! See console for detail.");
810 WM_main_add_notifier(NC_SCENE | ND_FRAME, data->scene);
813 static void import_freejob(void *user_data)
815 ImportJobData *data = static_cast<ImportJobData *>(user_data);
819 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)
821 /* Using new here since MEM_* funcs do not call ctor to properly initialize
823 ImportJobData *job = new ImportJobData();
824 job->bmain = CTX_data_main(C);
825 job->scene = CTX_data_scene(C);
826 BLI_strncpy(job->filename, filepath, 1024);
828 job->settings.scale = scale;
829 job->settings.is_sequence = is_sequence;
830 job->settings.set_frame_range = set_frame_range;
831 job->settings.sequence_len = sequence_len;
832 job->settings.offset = offset;
833 job->settings.validate_meshes = validate_meshes;
834 job->error_code = ABC_NO_ERROR;
835 job->was_cancelled = false;
839 wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
844 WM_JOB_TYPE_ALEMBIC);
847 WM_jobs_customdata_set(wm_job, job, import_freejob);
848 WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_FRAME, NC_SCENE | ND_FRAME);
849 WM_jobs_callbacks(wm_job, import_startjob, NULL, NULL, import_endjob);
851 WM_jobs_start(CTX_wm_manager(C), wm_job);
854 /* ************************************************************************** */
856 void ABC_get_transform(CacheReader *reader, float r_mat[4][4], float time, float scale)
862 AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
864 bool is_constant = false;
865 abc_reader->read_matrix(r_mat, time, scale, is_constant);
868 /* ************************************************************************** */
870 DerivedMesh *ABC_read_mesh(CacheReader *reader,
874 const char **err_str,
877 AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
878 IObject iobject = abc_reader->iobject();
880 if (!iobject.valid()) {
881 *err_str = "Invalid object: verify object path";
885 const ObjectHeader &header = iobject.getHeader();
887 if (IPolyMesh::matches(header)) {
888 if (ob->type != OB_MESH) {
889 *err_str = "Object type mismatch: object path points to a mesh!";
893 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
895 else if (ISubD::matches(header)) {
896 if (ob->type != OB_MESH) {
897 *err_str = "Object type mismatch: object path points to a subdivision mesh!";
901 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
903 else if (IPoints::matches(header)) {
904 if (ob->type != OB_MESH) {
905 *err_str = "Object type mismatch: object path points to a point cloud (requires a mesh object)!";
909 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
911 else if (ICurves::matches(header)) {
912 if (ob->type != OB_CURVE) {
913 *err_str = "Object type mismatch: object path points to a curve!";
917 return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
920 *err_str = "Unsupported object type: verify object path"; // or poke developer
924 /* ************************************************************************** */
926 void CacheReader_free(CacheReader *reader)
928 AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
929 abc_reader->decref();
931 if (abc_reader->refcount() == 0) {
936 CacheReader *CacheReader_open_alembic_object(AbcArchiveHandle *handle, CacheReader *reader, Object *object, const char *object_path)
938 if (object_path[0] == '\0') {
942 ArchiveReader *archive = archive_from_handle(handle);
944 if (!archive || !archive->valid()) {
949 find_iobject(archive->getTop(), iobject, object_path);
952 CacheReader_free(reader);
955 ImportSettings settings;
956 AbcObjectReader *abc_reader = create_reader(iobject, settings);
957 abc_reader->object(object);
958 abc_reader->incref();
960 return reinterpret_cast<CacheReader *>(abc_reader);