diff options
Diffstat (limited to 'source/blender/alembic/intern/abc_points.cc')
-rw-r--r-- | source/blender/alembic/intern/abc_points.cc | 242 |
1 files changed, 123 insertions, 119 deletions
diff --git a/source/blender/alembic/intern/abc_points.cc b/source/blender/alembic/intern/abc_points.cc index bc8c1e2debb..d691087ca21 100644 --- a/source/blender/alembic/intern/abc_points.cc +++ b/source/blender/alembic/intern/abc_points.cc @@ -45,8 +45,8 @@ extern "C" { using Alembic::AbcGeom::kVertexScope; using Alembic::AbcGeom::kWrapExisting; -using Alembic::AbcGeom::P3fArraySamplePtr; using Alembic::AbcGeom::N3fArraySamplePtr; +using Alembic::AbcGeom::P3fArraySamplePtr; using Alembic::AbcGeom::ICompoundProperty; using Alembic::AbcGeom::IN3fArrayProperty; @@ -66,75 +66,75 @@ AbcPointsWriter::AbcPointsWriter(Object *ob, ParticleSystem *psys) : AbcObjectWriter(ob, time_sampling, settings, parent) { - m_psys = psys; + m_psys = psys; - OPoints points(parent->alembicXform(), psys->name, m_time_sampling); - m_schema = points.getSchema(); + OPoints points(parent->alembicXform(), psys->name, m_time_sampling); + m_schema = points.getSchema(); } void AbcPointsWriter::do_write() { - if (!m_psys) { - return; - } + if (!m_psys) { + return; + } - std::vector<Imath::V3f> points; - std::vector<Imath::V3f> velocities; - std::vector<float> widths; - std::vector<uint64_t> ids; + std::vector<Imath::V3f> points; + std::vector<Imath::V3f> velocities; + std::vector<float> widths; + std::vector<uint64_t> ids; - ParticleKey state; + ParticleKey state; - ParticleSimulationData sim; - sim.depsgraph = m_settings.depsgraph; - sim.scene = m_settings.scene; - sim.ob = m_object; - sim.psys = m_psys; + ParticleSimulationData sim; + sim.depsgraph = m_settings.depsgraph; + sim.scene = m_settings.scene; + sim.ob = m_object; + sim.psys = m_psys; - m_psys->lattice_deform_data = psys_create_lattice_deform_data(&sim); + m_psys->lattice_deform_data = psys_create_lattice_deform_data(&sim); - uint64_t index = 0; - for (int p = 0; p < m_psys->totpart; p++) { - float pos[3], vel[3]; + uint64_t index = 0; + for (int p = 0; p < m_psys->totpart; p++) { + float pos[3], vel[3]; - if (m_psys->particles[p].flag & (PARS_NO_DISP | PARS_UNEXIST)) { - continue; - } + if (m_psys->particles[p].flag & (PARS_NO_DISP | PARS_UNEXIST)) { + continue; + } - state.time = DEG_get_ctime(m_settings.depsgraph); + state.time = DEG_get_ctime(m_settings.depsgraph); - if (psys_get_particle_state(&sim, p, &state, 0) == 0) { - continue; - } + if (psys_get_particle_state(&sim, p, &state, 0) == 0) { + continue; + } - /* location */ - mul_v3_m4v3(pos, m_object->imat, state.co); + /* location */ + mul_v3_m4v3(pos, m_object->imat, state.co); - /* velocity */ - sub_v3_v3v3(vel, state.co, m_psys->particles[p].prev_state.co); + /* velocity */ + sub_v3_v3v3(vel, state.co, m_psys->particles[p].prev_state.co); - /* Convert Z-up to Y-up. */ - points.push_back(Imath::V3f(pos[0], pos[2], -pos[1])); - velocities.push_back(Imath::V3f(vel[0], vel[2], -vel[1])); - widths.push_back(m_psys->particles[p].size); - ids.push_back(index++); - } + /* Convert Z-up to Y-up. */ + points.push_back(Imath::V3f(pos[0], pos[2], -pos[1])); + velocities.push_back(Imath::V3f(vel[0], vel[2], -vel[1])); + widths.push_back(m_psys->particles[p].size); + ids.push_back(index++); + } - if (m_psys->lattice_deform_data) { - end_latt_deform(m_psys->lattice_deform_data); - m_psys->lattice_deform_data = NULL; - } + if (m_psys->lattice_deform_data) { + end_latt_deform(m_psys->lattice_deform_data); + m_psys->lattice_deform_data = NULL; + } - Alembic::Abc::P3fArraySample psample(points); - Alembic::Abc::UInt64ArraySample idsample(ids); - Alembic::Abc::V3fArraySample vsample(velocities); - Alembic::Abc::FloatArraySample wsample_array(widths); - Alembic::AbcGeom::OFloatGeomParam::Sample wsample(wsample_array, kVertexScope); + Alembic::Abc::P3fArraySample psample(points); + Alembic::Abc::UInt64ArraySample idsample(ids); + Alembic::Abc::V3fArraySample vsample(velocities); + Alembic::Abc::FloatArraySample wsample_array(widths); + Alembic::AbcGeom::OFloatGeomParam::Sample wsample(wsample_array, kVertexScope); - m_sample = OPointsSchema::Sample(psample, idsample, vsample, wsample); - m_sample.setSelfBounds(bounds()); + m_sample = OPointsSchema::Sample(psample, idsample, vsample, wsample); + m_sample.setSelfBounds(bounds()); - m_schema.set(m_sample); + m_schema.set(m_sample); } /* ************************************************************************** */ @@ -142,75 +142,79 @@ void AbcPointsWriter::do_write() AbcPointsReader::AbcPointsReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) { - IPoints ipoints(m_iobject, kWrapExisting); - m_schema = ipoints.getSchema(); - get_min_max_time(m_iobject, m_schema, m_min_time, m_max_time); + IPoints ipoints(m_iobject, kWrapExisting); + m_schema = ipoints.getSchema(); + get_min_max_time(m_iobject, m_schema, m_min_time, m_max_time); } bool AbcPointsReader::valid() const { - return m_schema.valid(); + return m_schema.valid(); } -bool AbcPointsReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, - const Object *const ob, - const char **err_str) const +bool AbcPointsReader::accepts_object_type( + const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, + const Object *const ob, + const char **err_str) const { - if (!Alembic::AbcGeom::IPoints::matches(alembic_header)) { - *err_str = "Object type mismatch, Alembic object path pointed to Points when importing, but not any more."; - return false; - } - - if (ob->type != OB_MESH) { - *err_str = "Object type mismatch, Alembic object path points to Points."; - return false; - } - - return true; + if (!Alembic::AbcGeom::IPoints::matches(alembic_header)) { + *err_str = + "Object type mismatch, Alembic object path pointed to Points when importing, but not any " + "more."; + return false; + } + + if (ob->type != OB_MESH) { + *err_str = "Object type mismatch, Alembic object path points to Points."; + return false; + } + + return true; } void AbcPointsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) { - Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str()); - Mesh *read_mesh = this->read_mesh(mesh, sample_sel, 0, NULL); + Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str()); + Mesh *read_mesh = this->read_mesh(mesh, sample_sel, 0, NULL); - if (read_mesh != mesh) { - BKE_mesh_nomain_to_mesh(read_mesh, mesh, m_object, &CD_MASK_MESH, true); - } + if (read_mesh != mesh) { + BKE_mesh_nomain_to_mesh(read_mesh, mesh, m_object, &CD_MASK_MESH, true); + } - if (m_settings->validate_meshes) { - BKE_mesh_validate(mesh, false, false); - } + if (m_settings->validate_meshes) { + BKE_mesh_validate(mesh, false, false); + } - m_object = BKE_object_add_only_object(bmain, OB_MESH, m_object_name.c_str()); - m_object->data = mesh; + m_object = BKE_object_add_only_object(bmain, OB_MESH, m_object_name.c_str()); + m_object->data = mesh; - if (has_animations(m_schema, m_settings)) { - addCacheModifier(); - } + if (has_animations(m_schema, m_settings)) { + addCacheModifier(); + } } void read_points_sample(const IPointsSchema &schema, const ISampleSelector &selector, CDStreamConfig &config) { - Alembic::AbcGeom::IPointsSchema::Sample sample = schema.getValue(selector); + Alembic::AbcGeom::IPointsSchema::Sample sample = schema.getValue(selector); - const P3fArraySamplePtr &positions = sample.getPositions(); + const P3fArraySamplePtr &positions = sample.getPositions(); - ICompoundProperty prop = schema.getArbGeomParams(); - N3fArraySamplePtr vnormals; + ICompoundProperty prop = schema.getArbGeomParams(); + N3fArraySamplePtr vnormals; - if (has_property(prop, "N")) { - const Alembic::Util::uint32_t itime = static_cast<Alembic::Util::uint32_t>(selector.getRequestedTime()); - const IN3fArrayProperty &normals_prop = IN3fArrayProperty(prop, "N", itime); + if (has_property(prop, "N")) { + const Alembic::Util::uint32_t itime = static_cast<Alembic::Util::uint32_t>( + selector.getRequestedTime()); + const IN3fArrayProperty &normals_prop = IN3fArrayProperty(prop, "N", itime); - if (normals_prop) { - vnormals = normals_prop.getValue(selector); - } - } + if (normals_prop) { + vnormals = normals_prop.getValue(selector); + } + } - read_mverts(config.mvert, positions, vnormals); + read_mverts(config.mvert, positions, vnormals); } struct Mesh *AbcPointsReader::read_mesh(struct Mesh *existing_mesh, @@ -218,30 +222,30 @@ struct Mesh *AbcPointsReader::read_mesh(struct Mesh *existing_mesh, int /*read_flag*/, const char **err_str) { - IPointsSchema::Sample sample; - try { - sample = m_schema.getValue(sample_sel); - } - catch(Alembic::Util::Exception &ex) { - *err_str = "Error reading points sample; more detail on the console"; - printf("Alembic: error reading points sample for '%s/%s' at time %f: %s\n", - m_iobject.getFullName().c_str(), - m_schema.getName().c_str(), - sample_sel.getRequestedTime(), - ex.what()); - return existing_mesh; - } - - const P3fArraySamplePtr &positions = sample.getPositions(); - - Mesh *new_mesh = NULL; - - if (existing_mesh->totvert != positions->size()) { - new_mesh = BKE_mesh_new_nomain(positions->size(), 0, 0, 0, 0); - } - - CDStreamConfig config = get_config(new_mesh ? new_mesh : existing_mesh); - read_points_sample(m_schema, sample_sel, config); - - return new_mesh ? new_mesh : existing_mesh; + IPointsSchema::Sample sample; + try { + sample = m_schema.getValue(sample_sel); + } + catch (Alembic::Util::Exception &ex) { + *err_str = "Error reading points sample; more detail on the console"; + printf("Alembic: error reading points sample for '%s/%s' at time %f: %s\n", + m_iobject.getFullName().c_str(), + m_schema.getName().c_str(), + sample_sel.getRequestedTime(), + ex.what()); + return existing_mesh; + } + + const P3fArraySamplePtr &positions = sample.getPositions(); + + Mesh *new_mesh = NULL; + + if (existing_mesh->totvert != positions->size()) { + new_mesh = BKE_mesh_new_nomain(positions->size(), 0, 0, 0, 0); + } + + CDStreamConfig config = get_config(new_mesh ? new_mesh : existing_mesh); + read_points_sample(m_schema, sample_sel, config); + + return new_mesh ? new_mesh : existing_mesh; } |