Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/alembic/intern/alembic_capi.cc
| Show First 20 Lines • Show All 780 Lines • ▼ Show 20 Lines | static ISampleSelector sample_selector_for_time(float time) | ||||
| return ISampleSelector(time, ISampleSelector::kFloorIndex); | return ISampleSelector(time, ISampleSelector::kFloorIndex); | ||||
| } | } | ||||
| Mesh *ABC_read_mesh(CacheReader *reader, | Mesh *ABC_read_mesh(CacheReader *reader, | ||||
| Object *ob, | Object *ob, | ||||
| Mesh *existing_mesh, | Mesh *existing_mesh, | ||||
| const float time, | const float time, | ||||
| const char **err_str, | const char **err_str, | ||||
| int read_flag) | const int read_flag, | ||||
| const char *velocity_name, | |||||
| const float velocity_scale) | |||||
| { | { | ||||
| AbcObjectReader *abc_reader = get_abc_reader(reader, ob, err_str); | AbcObjectReader *abc_reader = get_abc_reader(reader, ob, err_str); | ||||
| if (abc_reader == nullptr) { | if (abc_reader == nullptr) { | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| ISampleSelector sample_sel = sample_selector_for_time(time); | ISampleSelector sample_sel = sample_selector_for_time(time); | ||||
| return abc_reader->read_mesh(existing_mesh, sample_sel, read_flag, err_str); | return abc_reader->read_mesh( | ||||
| existing_mesh, sample_sel, read_flag, velocity_name, velocity_scale, err_str); | |||||
| } | } | ||||
| bool ABC_mesh_topology_changed( | bool ABC_mesh_topology_changed( | ||||
| CacheReader *reader, Object *ob, Mesh *existing_mesh, const float time, const char **err_str) | CacheReader *reader, Object *ob, Mesh *existing_mesh, const float time, const char **err_str) | ||||
| { | { | ||||
| AbcObjectReader *abc_reader = get_abc_reader(reader, ob, err_str); | AbcObjectReader *abc_reader = get_abc_reader(reader, ob, err_str); | ||||
| if (abc_reader == nullptr) { | if (abc_reader == nullptr) { | ||||
| return false; | return false; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if (abc_reader == nullptr) { | ||||
| /* This object is not supported */ | /* This object is not supported */ | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| abc_reader->object(object); | abc_reader->object(object); | ||||
| abc_reader->incref(); | abc_reader->incref(); | ||||
| return reinterpret_cast<CacheReader *>(abc_reader); | 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; | |||||
| } | |||||