Alembic: use object-oriented approach in ABC_read_mesh()
This is easier to extend than the if/else if/else chain that was in place, and allows for somewhat more granular error messages.
This commit is contained in:
parent
2e67a20045
commit
aa88796a6c
|
@ -117,6 +117,23 @@ bool AbcCameraReader::valid() const
|
|||
return m_schema.valid();
|
||||
}
|
||||
|
||||
bool AbcCameraReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const
|
||||
{
|
||||
if (!Alembic::AbcGeom::ICamera::matches(alembic_header)) {
|
||||
*err_str = "Object type mismatch, Alembic object path pointed to Camera when importing, but not any more.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ob->type != OB_CAMERA) {
|
||||
*err_str = "Object type mismatch, Alembic object path points to Camera.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbcCameraReader::readObjectData(Main *bmain, const ISampleSelector &sample_sel)
|
||||
{
|
||||
Camera *bcam = static_cast<Camera *>(BKE_camera_add(bmain, m_data_name.c_str()));
|
||||
|
|
|
@ -54,6 +54,9 @@ public:
|
|||
AbcCameraReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
|
||||
|
||||
bool valid() const;
|
||||
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const;
|
||||
|
||||
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
|
||||
};
|
||||
|
|
|
@ -211,6 +211,23 @@ bool AbcCurveReader::valid() const
|
|||
return m_curves_schema.valid();
|
||||
}
|
||||
|
||||
bool AbcCurveReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const
|
||||
{
|
||||
if (!Alembic::AbcGeom::ICurves::matches(alembic_header)) {
|
||||
*err_str = "Object type mismatch, Alembic object path pointed to Curves when importing, but not any more.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ob->type != OB_EMPTY) {
|
||||
*err_str = "Object type mismatch, Alembic object path points to Curves.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbcCurveReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
|
||||
{
|
||||
Curve *cu = BKE_curve_add(bmain, m_data_name.c_str(), OB_CURVE);
|
||||
|
|
|
@ -54,6 +54,9 @@ public:
|
|||
AbcCurveReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
|
||||
|
||||
bool valid() const;
|
||||
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const;
|
||||
|
||||
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
|
||||
DerivedMesh *read_derivedmesh(DerivedMesh *dm,
|
||||
|
|
|
@ -1048,6 +1048,23 @@ void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec
|
|||
}
|
||||
}
|
||||
|
||||
bool AbcMeshReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const
|
||||
{
|
||||
if (!Alembic::AbcGeom::IPolyMesh::matches(alembic_header)) {
|
||||
*err_str = "Object type mismatch, Alembic object path pointed to PolyMesh when importing, but not any more.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ob->type != OB_MESH) {
|
||||
*err_str = "Object type mismatch, Alembic object path points to PolyMesh.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm,
|
||||
const ISampleSelector &sample_sel,
|
||||
int read_flag,
|
||||
|
@ -1239,6 +1256,23 @@ bool AbcSubDReader::valid() const
|
|||
return m_schema.valid();
|
||||
}
|
||||
|
||||
bool AbcSubDReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const
|
||||
{
|
||||
if (!Alembic::AbcGeom::ISubD::matches(alembic_header)) {
|
||||
*err_str = "Object type mismatch, Alembic object path pointed to SubD when importing, but not any more.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ob->type != OB_MESH) {
|
||||
*err_str = "Object type mismatch, Alembic object path points to SubD.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
|
||||
{
|
||||
Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
|
||||
|
|
|
@ -99,7 +99,9 @@ public:
|
|||
AbcMeshReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
|
||||
|
||||
bool valid() const;
|
||||
|
||||
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const;
|
||||
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
|
||||
|
||||
DerivedMesh *read_derivedmesh(DerivedMesh *dm,
|
||||
|
@ -123,7 +125,9 @@ public:
|
|||
AbcSubDReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
|
||||
|
||||
bool valid() const;
|
||||
|
||||
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const;
|
||||
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
|
||||
DerivedMesh *read_derivedmesh(DerivedMesh *dm,
|
||||
const Alembic::Abc::ISampleSelector &sample_sel,
|
||||
|
|
|
@ -169,6 +169,9 @@ public:
|
|||
const std::string & data_name() const { return m_data_name; }
|
||||
|
||||
virtual bool valid() const = 0;
|
||||
virtual bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const = 0;
|
||||
|
||||
virtual void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) = 0;
|
||||
|
||||
|
|
|
@ -151,6 +151,23 @@ bool AbcPointsReader::valid() const
|
|||
return m_schema.valid();
|
||||
}
|
||||
|
||||
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_EMPTY) {
|
||||
*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());
|
||||
|
|
|
@ -58,6 +58,9 @@ public:
|
|||
AbcPointsReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
|
||||
|
||||
bool valid() const;
|
||||
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const;
|
||||
|
||||
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
|
||||
|
||||
|
|
|
@ -154,6 +154,23 @@ bool AbcEmptyReader::valid() const
|
|||
return m_schema.valid();
|
||||
}
|
||||
|
||||
bool AbcEmptyReader::accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const
|
||||
{
|
||||
if (!Alembic::AbcGeom::IXform::matches(alembic_header)) {
|
||||
*err_str = "Object type mismatch, Alembic object path pointed to XForm when importing, but not any more.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ob->type != OB_EMPTY) {
|
||||
*err_str = "Object type mismatch, Alembic object path points to XForm.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbcEmptyReader::readObjectData(Main *bmain, const ISampleSelector &UNUSED(sample_sel))
|
||||
{
|
||||
m_object = BKE_object_add_only_object(bmain, OB_EMPTY,
|
||||
|
|
|
@ -68,6 +68,9 @@ public:
|
|||
AbcEmptyReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
|
||||
|
||||
bool valid() const;
|
||||
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
|
||||
const Object *const ob,
|
||||
const char **err_str) const;
|
||||
|
||||
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
|
||||
};
|
||||
|
|
|
@ -939,43 +939,13 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader,
|
|||
}
|
||||
|
||||
const ObjectHeader &header = iobject.getHeader();
|
||||
if (!abc_reader->accepts_object_type(header, ob, err_str)) {
|
||||
/* err_str is set by acceptsObjectType() */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ISampleSelector sample_sel(time);
|
||||
|
||||
if (IPolyMesh::matches(header)) {
|
||||
if (ob->type != OB_MESH) {
|
||||
*err_str = "Object type mismatch: object path points to a mesh!";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
|
||||
}
|
||||
else if (ISubD::matches(header)) {
|
||||
if (ob->type != OB_MESH) {
|
||||
*err_str = "Object type mismatch: object path points to a subdivision mesh!";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
|
||||
}
|
||||
else if (IPoints::matches(header)) {
|
||||
if (ob->type != OB_MESH) {
|
||||
*err_str = "Object type mismatch: object path points to a point cloud (requires a mesh object)!";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
|
||||
}
|
||||
else if (ICurves::matches(header)) {
|
||||
if (ob->type != OB_CURVE) {
|
||||
*err_str = "Object type mismatch: object path points to a curve!";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
|
||||
}
|
||||
|
||||
*err_str = "Unsupported object type: verify object path"; // or poke developer
|
||||
return NULL;
|
||||
return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
|
Loading…
Reference in New Issue