diff options
Diffstat (limited to 'source/blender/io/alembic/intern')
5 files changed, 144 insertions, 10 deletions
diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.cc b/source/blender/io/alembic/intern/abc_axis_conversion.cc index cebab1f2e41..396c8fdb28b 100644 --- a/source/blender/io/alembic/intern/abc_axis_conversion.cc +++ b/source/blender/io/alembic/intern/abc_axis_conversion.cc @@ -170,4 +170,4 @@ void create_transform_matrix(Object *obj, } // namespace alembic } // namespace io -} // namespace blender
\ No newline at end of file +} // namespace blender diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.h b/source/blender/io/alembic/intern/abc_axis_conversion.h index 9a19e9116be..645d9fc783b 100644 --- a/source/blender/io/alembic/intern/abc_axis_conversion.h +++ b/source/blender/io/alembic/intern/abc_axis_conversion.h @@ -100,4 +100,4 @@ void create_transform_matrix(Object *obj, } // namespace alembic } // namespace io -} // namespace blender
\ No newline at end of file +} // namespace blender diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 756dde3783c..98130eb28cd 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -104,7 +104,7 @@ static void assign_materials(Main *bmain, for (; it != mat_index_map.end(); ++it) { std::string mat_name = it->first; - mat_iter = mat_map.find(mat_name.c_str()); + mat_iter = mat_map.find(mat_name); Material *assigned_mat; diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 39b9cd4c161..06b0c07f4c5 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -236,7 +236,7 @@ Alembic::AbcGeom::IXform AbcObjectReader::xform() * parent Alembic object should contain the transform. */ IObject abc_parent = m_iobject.getParent(); - /* The archive's top object can be recognised by not having a parent. */ + /* The archive's top object can be recognized by not having a parent. */ if (abc_parent.getParent() && IXform::matches(abc_parent.getMetaData())) { try { return IXform(abc_parent, Alembic::AbcGeom::kWrapExisting); diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc index 7cde2d4fe73..eba7f64db02 100644 --- a/source/blender/io/alembic/intern/alembic_capi.cc +++ b/source/blender/io/alembic/intern/alembic_capi.cc @@ -22,6 +22,7 @@ #include <Alembic/AbcMaterial/IMaterial.h> +#include "abc_axis_conversion.h" #include "abc_reader_archive.h" #include "abc_reader_camera.h" #include "abc_reader_curves.h" @@ -47,18 +48,13 @@ #include "BKE_lib_id.h" #include "BKE_object.h" #include "BKE_scene.h" +#include "BKE_screen.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" #include "ED_undo.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 -#include "BKE_screen.h" -#undef new - #include "BLI_compiler_compat.h" #include "BLI_fileops.h" #include "BLI_ghash.h" @@ -70,7 +66,10 @@ #include "WM_api.h" #include "WM_types.h" +using Alembic::Abc::IV3fArrayProperty; using Alembic::Abc::ObjectHeader; +using Alembic::Abc::PropertyHeader; +using Alembic::Abc::V3fArraySamplePtr; using Alembic::AbcGeom::ICamera; using Alembic::AbcGeom::ICurves; using Alembic::AbcGeom::IFaceSet; @@ -79,9 +78,11 @@ using Alembic::AbcGeom::INuPatch; using Alembic::AbcGeom::IObject; using Alembic::AbcGeom::IPoints; using Alembic::AbcGeom::IPolyMesh; +using Alembic::AbcGeom::IPolyMeshSchema; using Alembic::AbcGeom::ISampleSelector; using Alembic::AbcGeom::ISubD; using Alembic::AbcGeom::IXform; +using Alembic::AbcGeom::kWrapExisting; using Alembic::AbcGeom::MetaData; using Alembic::AbcMaterial::IMaterial; @@ -859,3 +860,136 @@ CacheReader *CacheReader_open_alembic_object(AbcArchiveHandle *handle, return reinterpret_cast<CacheReader *>(abc_reader); } + +/* ************************************************************************** */ + +static const PropertyHeader *get_property_header(const IPolyMeshSchema &schema, const char *name) +{ + const PropertyHeader *prop_header = schema.getPropertyHeader(name); + + if (prop_header) { + return prop_header; + } + + ICompoundProperty prop = schema.getArbGeomParams(); + + if (!has_property(prop, name)) { + return nullptr; + } + + return prop.getPropertyHeader(name); +} + +bool ABC_has_vec3_array_property_named(struct CacheReader *reader, const char *name) +{ + AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader); + + if (!abc_reader) { + return false; + } + + IObject iobject = abc_reader->iobject(); + + if (!iobject.valid()) { + return false; + } + + const ObjectHeader &header = iobject.getHeader(); + + if (!IPolyMesh::matches(header)) { + return false; + } + + IPolyMesh mesh(iobject, kWrapExisting); + IPolyMeshSchema schema = mesh.getSchema(); + + const PropertyHeader *prop_header = get_property_header(schema, name); + + if (!prop_header) { + return false; + } + + return IV3fArrayProperty::matches(prop_header->getMetaData()); +} + +static V3fArraySamplePtr get_velocity_prop(const IPolyMeshSchema &schema, + const ISampleSelector &iss, + const std::string &name) +{ + const PropertyHeader *prop_header = schema.getPropertyHeader(name); + + if (prop_header) { + const IV3fArrayProperty &velocity_prop = IV3fArrayProperty(schema, name, 0); + return velocity_prop.getValue(iss); + } + + ICompoundProperty prop = schema.getArbGeomParams(); + + if (!has_property(prop, name)) { + return V3fArraySamplePtr(); + } + + const IV3fArrayProperty &velocity_prop = IV3fArrayProperty(prop, name, 0); + + if (velocity_prop) { + return velocity_prop.getValue(iss); + } + + return V3fArraySamplePtr(); +} + +int ABC_read_velocity_cache(CacheReader *reader, + const char *velocity_name, + const float time, + float velocity_scale, + int num_vertices, + float *r_vertex_velocities) +{ + AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader); + + if (!abc_reader) { + return -1; + } + + IObject iobject = abc_reader->iobject(); + + if (!iobject.valid()) { + return -1; + } + + const ObjectHeader &header = iobject.getHeader(); + + if (!IPolyMesh::matches(header)) { + return -1; + } + + IPolyMesh mesh(iobject, kWrapExisting); + IPolyMeshSchema schema = mesh.getSchema(); + ISampleSelector sample_sel(time); + const IPolyMeshSchema::Sample sample = schema.getValue(sample_sel); + + V3fArraySamplePtr velocities = get_velocity_prop(schema, sample_sel, velocity_name); + + if (!velocities) { + return -1; + } + + float vel[3]; + + int num_velocity_vectors = static_cast<int>(velocities->size()); + + if (num_velocity_vectors != num_vertices) { + return -1; + } + + for (size_t i = 0; i < velocities->size(); ++i) { + const Imath::V3f &vel_in = (*velocities)[i]; + copy_zup_from_yup(vel, vel_in.getValue()); + + mul_v3_fl(vel, velocity_scale); + + copy_v3_v3(r_vertex_velocities + i * 3, vel); + } + + return num_vertices; +} |