Alembic: Construct ISampleSelector once and pass along
authorSybren A. Stüvel <sybren@stuvel.eu>
Fri, 21 Apr 2017 09:04:47 +0000 (11:04 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Fri, 21 Apr 2017 12:11:49 +0000 (14:11 +0200)
No longer passing time as float and constructing ISampleSelectors all
over the place. Instead, just construct an ISampleSelector once and
pass it along.

15 files changed:
source/blender/alembic/intern/abc_camera.cc
source/blender/alembic/intern/abc_camera.h
source/blender/alembic/intern/abc_curves.cc
source/blender/alembic/intern/abc_curves.h
source/blender/alembic/intern/abc_mesh.cc
source/blender/alembic/intern/abc_mesh.h
source/blender/alembic/intern/abc_nurbs.cc
source/blender/alembic/intern/abc_nurbs.h
source/blender/alembic/intern/abc_object.cc
source/blender/alembic/intern/abc_object.h
source/blender/alembic/intern/abc_points.cc
source/blender/alembic/intern/abc_points.h
source/blender/alembic/intern/abc_transform.cc
source/blender/alembic/intern/abc_transform.h
source/blender/alembic/intern/alembic_capi.cc

index 4f70b2a972c2b0dd585c2793e682b53cae659f66..33344f6c9c53bef9d6be3cfac24327d44d54399d 100644 (file)
@@ -117,11 +117,10 @@ bool AbcCameraReader::valid() const
        return m_schema.valid();
 }
 
-void AbcCameraReader::readObjectData(Main *bmain, float time)
+void AbcCameraReader::readObjectData(Main *bmain, const ISampleSelector &sample_sel)
 {
        Camera *bcam = static_cast<Camera *>(BKE_camera_add(bmain, m_data_name.c_str()));
 
-       ISampleSelector sample_sel(time);
        CameraSample cam_sample;
        m_schema.get(cam_sample, sample_sel);
 
index fafb4d3eb39439b0a1698b8406e5f3005959bd7f..0201dd9d6e1fe34bc3b3d8bff22565a1823a0e0f 100644 (file)
@@ -55,7 +55,7 @@ public:
 
        bool valid() const;
 
-       void readObjectData(Main *bmain, float time);
+       void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
 };
 
-#endif  /* __ABC_CAMERA_H__ */
\ No newline at end of file
+#endif  /* __ABC_CAMERA_H__ */
index bf485c7ef61f85889174bdaebc8bb9fe83e236c9..d85d8df4d774e5efcbe4c6f1d49c007c6239e7cf 100644 (file)
@@ -211,7 +211,7 @@ bool AbcCurveReader::valid() const
        return m_curves_schema.valid();
 }
 
-void AbcCurveReader::readObjectData(Main *bmain, float time)
+void AbcCurveReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
 {
        Curve *cu = BKE_curve_add(bmain, m_data_name.c_str(), OB_CURVE);
 
@@ -219,8 +219,6 @@ void AbcCurveReader::readObjectData(Main *bmain, float time)
        cu->actvert = CU_ACT_NONE;
        cu->resolu = 1;
 
-       const ISampleSelector sample_sel(time);
-
        ICompoundProperty user_props = m_curves_schema.getUserProperties();
        if (user_props) {
                const PropertyHeader *header = user_props.getPropertyHeader(ABC_CURVE_RESOLUTION_U_PROPNAME);
@@ -389,9 +387,11 @@ void read_curve_sample(Curve *cu, const ICurvesSchema &schema, const ISampleSele
  * object directly and create a new DerivedMesh from that. Also we might need to
  * create new or delete existing NURBS in the curve.
  */
-DerivedMesh *AbcCurveReader::read_derivedmesh(DerivedMesh * /*dm*/, const float time, int /*read_flag*/, const char ** /*err_str*/)
+DerivedMesh *AbcCurveReader::read_derivedmesh(DerivedMesh * /*dm*/,
+                                              const ISampleSelector &sample_sel,
+                                              int /*read_flag*/,
+                                              const char ** /*err_str*/)
 {
-       ISampleSelector sample_sel(time);
        const ICurvesSchema::Sample sample = m_curves_schema.getValue(sample_sel);
 
        const P3fArraySamplePtr &positions = sample.getPositions();
index 71b0d20582045f0df1baeb51b5bf5dfcf74c5c39..1ad6d0bf2781452c0cd32379cb7f15fec087b577 100644 (file)
@@ -55,8 +55,11 @@ public:
 
        bool valid() const;
 
-       void readObjectData(Main *bmain, float time);
-       DerivedMesh *read_derivedmesh(DerivedMesh *, const float time, int read_flag, const char **err_str);
+       void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
+       DerivedMesh *read_derivedmesh(DerivedMesh *dm,
+                                     const Alembic::Abc::ISampleSelector &sample_sel,
+                                     int read_flag,
+                                     const char **err_str);
 };
 
 /* ************************************************************************** */
index 79b891dbcd4ed7a4c2a7e8c72d55b8a9108dd382..39186ec55dc980074cdcca61657c9ce31da7da29 100644 (file)
@@ -1021,17 +1021,15 @@ bool AbcMeshReader::valid() const
        return m_schema.valid();
 }
 
-void AbcMeshReader::readObjectData(Main *bmain, float time)
+void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
 {
        Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
 
        m_object = BKE_object_add_only_object(bmain, OB_MESH, m_object_name.c_str());
        m_object->data = mesh;
 
-       const ISampleSelector sample_sel(time);
-
        DerivedMesh *dm = CDDM_from_mesh(mesh);
-       DerivedMesh *ndm = this->read_derivedmesh(dm, time, MOD_MESHSEQ_READ_ALL, NULL);
+       DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, MOD_MESHSEQ_READ_ALL, NULL);
 
        if (ndm != dm) {
                dm->release(dm);
@@ -1050,9 +1048,11 @@ void AbcMeshReader::readObjectData(Main *bmain, float time)
        }
 }
 
-DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str)
+DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm,
+                                             const ISampleSelector &sample_sel,
+                                             int read_flag,
+                                             const char **err_str)
 {
-       ISampleSelector sample_sel(time);
        const IPolyMeshSchema::Sample sample = m_schema.getValue(sample_sel);
 
        const P3fArraySamplePtr &positions = sample.getPositions();
@@ -1092,7 +1092,7 @@ DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm, const float time,
        }
 
        CDStreamConfig config = get_config(new_dm ? new_dm : dm);
-       config.time = time;
+       config.time = sample_sel.getRequestedTime();
 
        bool do_normals = false;
        read_mesh_sample(&settings, m_schema, sample_sel, config, do_normals);
@@ -1239,7 +1239,7 @@ bool AbcSubDReader::valid() const
        return m_schema.valid();
 }
 
-void AbcSubDReader::readObjectData(Main *bmain, float time)
+void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
 {
        Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
 
@@ -1247,7 +1247,7 @@ void AbcSubDReader::readObjectData(Main *bmain, float time)
        m_object->data = mesh;
 
        DerivedMesh *dm = CDDM_from_mesh(mesh);
-       DerivedMesh *ndm = this->read_derivedmesh(dm, time, MOD_MESHSEQ_READ_ALL, NULL);
+       DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, MOD_MESHSEQ_READ_ALL, NULL);
 
        if (ndm != dm) {
                dm->release(dm);
@@ -1255,7 +1255,6 @@ void AbcSubDReader::readObjectData(Main *bmain, float time)
 
        DM_to_mesh(ndm, mesh, m_object, CD_MASK_MESH, true);
 
-       const ISampleSelector sample_sel(time);
        const ISubDSchema::Sample sample = m_schema.getValue(sample_sel);
        Int32ArraySamplePtr indices = sample.getCreaseIndices();
        Alembic::Abc::FloatArraySamplePtr sharpnesses = sample.getCreaseSharpnesses();
@@ -1286,9 +1285,11 @@ void AbcSubDReader::readObjectData(Main *bmain, float time)
        }
 }
 
-DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str)
+DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm,
+                                             const ISampleSelector &sample_sel,
+                                             int read_flag,
+                                             const char **err_str)
 {
-       ISampleSelector sample_sel(time);
        const ISubDSchema::Sample sample = m_schema.getValue(sample_sel);
 
        const P3fArraySamplePtr &positions = sample.getPositions();
@@ -1328,7 +1329,7 @@ DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm, const float time,
 
        /* Only read point data when streaming meshes, unless we need to create new ones. */
        CDStreamConfig config = get_config(new_dm ? new_dm : dm);
-       config.time = time;
+       config.time = sample_sel.getRequestedTime();
        read_subd_sample(&settings, m_schema, sample_sel, config);
 
        if (new_dm) {
index 64a3109232cc3245ea2ecab3054d545aec09006c..1b67c80cc72a475632eacb84ceeeaefbb561e9b4 100644 (file)
@@ -100,9 +100,12 @@ public:
 
        bool valid() const;
 
-       void readObjectData(Main *bmain, float time);
+       void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
 
-       DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str);
+       DerivedMesh *read_derivedmesh(DerivedMesh *dm,
+                                     const Alembic::Abc::ISampleSelector &sample_sel,
+                                     int read_flag,
+                                     const char **err_str);
 
 private:
        void readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start,
@@ -121,8 +124,11 @@ public:
 
        bool valid() const;
 
-       void readObjectData(Main *bmain, float time);
-       DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str);
+       void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
+       DerivedMesh *read_derivedmesh(DerivedMesh *dm,
+                                     const Alembic::Abc::ISampleSelector &sample_sel,
+                                     int read_flag,
+                                     const char **err_str);
 };
 
 /* ************************************************************************** */
index d0b9561f67987b3bb2041914f73f882636c3984b..eaef06fd6d11022a6ba358dab7a5d77c83b47e9f 100644 (file)
@@ -239,7 +239,7 @@ static bool set_knots(const FloatArraySamplePtr &knots, float *&nu_knots)
        return true;
 }
 
-void AbcNurbsReader::readObjectData(Main *bmain, float time)
+void AbcNurbsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
 {
        Curve *cu = static_cast<Curve *>(BKE_curve_add(bmain, "abc_curve", OB_SURF));
        cu->actvert = CU_ACT_NONE;
@@ -253,7 +253,6 @@ void AbcNurbsReader::readObjectData(Main *bmain, float time)
                nu->resolu = cu->resolu;
                nu->resolv = cu->resolv;
 
-               const ISampleSelector sample_sel(time);
                const INuPatchSchema &schema = it->first;
                const INuPatchSchema::Sample smp = schema.getValue(sample_sel);
 
index 1b2e7a8391fb828bdc91e7ec8dc959d38702bf1b..abe460a89882027a415851740dc0dda68aedaca6 100644 (file)
@@ -54,7 +54,7 @@ public:
 
        bool valid() const;
 
-       void readObjectData(Main *bmain, float time);
+       void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
 
 private:
        void getNurbsPatches(const Alembic::Abc::IObject &obj);
index c8716d55218498869cdf5737f25a300b5e0c9b44..4c3c060be28841267282f290376e4c0e6dafb1d1 100644 (file)
@@ -160,6 +160,15 @@ void AbcObjectReader::object(Object *ob)
        m_object = ob;
 }
 
+DerivedMesh *AbcObjectReader::read_derivedmesh(DerivedMesh *dm,
+                                               const Alembic::Abc::ISampleSelector &UNUSED(sample_sel),
+                                               int UNUSED(read_flag),
+                                               const char **UNUSED(err_str))
+{
+       return dm;
+}
+
+
 static Imath::M44d blend_matrices(const Imath::M44d &m0, const Imath::M44d &m1, const float weight)
 {
        float mat0[4][4], mat1[4][4], ret[4][4];
index d5344533b55a9741ccc5c30ed8d94eefcac90f96..a9dbaa89c97b5da4e32fcf6339b023cfa7fe5c99 100644 (file)
@@ -170,15 +170,12 @@ public:
 
        virtual bool valid() const = 0;
 
-       virtual void readObjectData(Main *bmain, float time) = 0;
-
-       virtual DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str)
-       {
-               (void)time;
-               (void)read_flag;
-               (void)err_str;
-               return dm;
-       }
+       virtual void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) = 0;
+
+       DerivedMesh *read_derivedmesh(DerivedMesh *dm,
+                                     const Alembic::Abc::ISampleSelector &sample_sel,
+                                     int read_flag,
+                                     const char **err_str);
 
        /** Reads the object matrix and sets up an object transform if animated. */
        void setupObjectTransform(const float time);
index fc84759b1d9b931133b79952e534f77197de7f20..d5ecf16b79382c5f6cfd947071f41d5d82ce806a 100644 (file)
@@ -151,12 +151,12 @@ bool AbcPointsReader::valid() const
        return m_schema.valid();
 }
 
-void AbcPointsReader::readObjectData(Main *bmain, float time)
+void AbcPointsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
 {
        Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
 
        DerivedMesh *dm = CDDM_from_mesh(mesh);
-       DerivedMesh *ndm = this->read_derivedmesh(dm, time, 0, NULL);
+       DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, 0, NULL);
 
        if (ndm != dm) {
                dm->release(dm);
@@ -178,8 +178,7 @@ void AbcPointsReader::readObjectData(Main *bmain, float time)
 
 void read_points_sample(const IPointsSchema &schema,
                         const ISampleSelector &selector,
-                        CDStreamConfig &config,
-                        float time)
+                        CDStreamConfig &config)
 {
        Alembic::AbcGeom::IPointsSchema::Sample sample = schema.getValue(selector);
 
@@ -189,7 +188,7 @@ void read_points_sample(const IPointsSchema &schema,
        N3fArraySamplePtr vnormals;
 
        if (has_property(prop, "N")) {
-               const Alembic::Util::uint32_t itime = static_cast<Alembic::Util::uint32_t>(time);
+               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) {
@@ -200,9 +199,11 @@ void read_points_sample(const IPointsSchema &schema,
        read_mverts(config.mvert, positions, vnormals);
 }
 
-DerivedMesh *AbcPointsReader::read_derivedmesh(DerivedMesh *dm, const float time, int /*read_flag*/, const char ** /*err_str*/)
+DerivedMesh *AbcPointsReader::read_derivedmesh(DerivedMesh *dm,
+                                               const ISampleSelector &sample_sel,
+                                               int /*read_flag*/,
+                                               const char ** /*err_str*/)
 {
-       ISampleSelector sample_sel(time);
        const IPointsSchema::Sample sample = m_schema.getValue(sample_sel);
 
        const P3fArraySamplePtr &positions = sample.getPositions();
@@ -214,7 +215,7 @@ DerivedMesh *AbcPointsReader::read_derivedmesh(DerivedMesh *dm, const float time
        }
 
        CDStreamConfig config = get_config(new_dm ? new_dm : dm);
-       read_points_sample(m_schema, sample_sel, config, time);
+       read_points_sample(m_schema, sample_sel, config);
 
        return new_dm ? new_dm : dm;
 }
index cb68dbca4d5023a4666e46f24d235b5825857328..1f74351d30297bc5cbdecf8ac0475807b14f2af3 100644 (file)
@@ -59,14 +59,16 @@ public:
 
        bool valid() const;
 
-       void readObjectData(Main *bmain, float time);
+       void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
 
-       DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str);
+       DerivedMesh *read_derivedmesh(DerivedMesh *dm,
+                                     const Alembic::Abc::ISampleSelector &sample_sel,
+                                     int read_flag,
+                                     const char **err_str);
 };
 
 void read_points_sample(const Alembic::AbcGeom::IPointsSchema &schema,
                         const Alembic::AbcGeom::ISampleSelector &selector,
-                        CDStreamConfig &config,
-                        float time);
+                        CDStreamConfig &config);
 
 #endif  /* __ABC_POINTS_H__ */
index 6e218cac4295521ed8055d6ecaf680faf1ab3a8e..c48be361877ec3c6db36c27364b5e51aac041495 100644 (file)
@@ -36,6 +36,7 @@ extern "C" {
 
 using Alembic::AbcGeom::OObject;
 using Alembic::AbcGeom::OXform;
+using Alembic::Abc::ISampleSelector;
 
 /* ************************************************************************** */
 
@@ -153,7 +154,7 @@ bool AbcEmptyReader::valid() const
        return m_schema.valid();
 }
 
-void AbcEmptyReader::readObjectData(Main *bmain, float /*time*/)
+void AbcEmptyReader::readObjectData(Main *bmain, const ISampleSelector &UNUSED(sample_sel))
 {
        m_object = BKE_object_add_only_object(bmain, OB_EMPTY,
                                              m_object_name.c_str());
index 59388e155dc4f3d45aaf59063b36f25269e91205..f2e2edf8010c930f4d37aa11ac4f207526faf039 100644 (file)
@@ -69,7 +69,7 @@ public:
 
        bool valid() const;
 
-       void readObjectData(Main *bmain, float time);
+       void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
 };
 
 #endif  /* __ABC_TRANSFORM_H__ */
index e44f66b7e56460eaa568ec87c821e6f751e72f5e..52a87d7c165fb72406a97cddea49cc140bb7a4c4 100644 (file)
@@ -704,12 +704,13 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
        chrono_t min_time = std::numeric_limits<chrono_t>::max();
        chrono_t max_time = std::numeric_limits<chrono_t>::min();
 
+       ISampleSelector sample_sel(0.0f);
        std::vector<AbcObjectReader *>::iterator iter;
        for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
                AbcObjectReader *reader = *iter;
 
                if (reader->valid()) {
-                       reader->readObjectData(data->bmain, 0.0f);
+                       reader->readObjectData(data->bmain, sample_sel);
 
                        min_time = std::min(min_time, reader->minTime());
                        max_time = std::max(max_time, reader->maxTime());
@@ -922,6 +923,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader,
        }
 
        const ObjectHeader &header = iobject.getHeader();
+       ISampleSelector sample_sel(time);
 
        if (IPolyMesh::matches(header)) {
                if (ob->type != OB_MESH) {
@@ -929,7 +931,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader,
                        return NULL;
                }
 
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
+               return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
        }
        else if (ISubD::matches(header)) {
                if (ob->type != OB_MESH) {
@@ -937,7 +939,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader,
                        return NULL;
                }
 
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
+               return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
        }
        else if (IPoints::matches(header)) {
                if (ob->type != OB_MESH) {
@@ -945,7 +947,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader,
                        return NULL;
                }
 
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
+               return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
        }
        else if (ICurves::matches(header)) {
                if (ob->type != OB_CURVE) {
@@ -953,7 +955,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader,
                        return NULL;
                }
 
-               return abc_reader->read_derivedmesh(dm, time, read_flag, err_str);
+               return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str);
        }
 
        *err_str = "Unsupported object type: verify object path"; // or poke developer