[Bf-blender-cvs] [e8a0fca50b2] cycles_procedural_api: alembic, use min/max time sampling time to derive the frame index
Kévin Dietrich
noreply at git.blender.org
Wed Sep 9 01:08:22 CEST 2020
Commit: e8a0fca50b2d4ff17407660fd10d0abb69361920
Author: Kévin Dietrich
Date: Tue Sep 8 06:03:06 2020 +0200
Branches: cycles_procedural_api
https://developer.blender.org/rBe8a0fca50b2d4ff17407660fd10d0abb69361920
alembic, use min/max time sampling time to derive the frame index
===================================================================
M intern/cycles/render/alembic.cpp
M intern/cycles/render/alembic.h
===================================================================
diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp
index 1760c15fa69..b9ffad803b8 100644
--- a/intern/cycles/render/alembic.cpp
+++ b/intern/cycles/render/alembic.cpp
@@ -133,6 +133,11 @@ AlembicObject::~AlembicObject()
{
}
+int AlembicObject::frame_index(float frame, float frame_rate)
+{
+ return static_cast<int>(frame - (static_cast<float>(min_time) * frame_rate));
+}
+
NODE_DEFINE(AlembicProcedural)
{
NodeType *type = NodeType::add("alembic", create);
@@ -236,6 +241,17 @@ void AlembicProcedural::set_current_frame(ccl::Scene *scene, float frame_)
static void load_all_data(AlembicObject *abc_object, IPolyMeshSchema &schema)
{
+ const auto &time_sampling = schema.getTimeSampling();
+
+ if (!schema.isConstant()) {
+ auto num_samples = schema.getNumSamples();
+
+ if (num_samples > 0) {
+ abc_object->min_time = time_sampling->getSampleTime(0);
+ abc_object->max_time = time_sampling->getSampleTime(num_samples - 1);
+ }
+ }
+
// TODO : store other properties and have a better structure to store these arrays
for (size_t i = 0; i < schema.getNumSamples(); ++i) {
abc_object->frame_data.emplace_back();
@@ -328,11 +344,7 @@ void AlembicProcedural::read_mesh(Scene *scene,
load_all_data(abc_object, schema);
}
- int frame_index = static_cast<int>(frame);
- if (frame_time >= abc_object->frame_data.size()) {
- frame_index = abc_object->frame_data.size() - 1;
- }
-
+ int frame_index = abc_object->frame_index(frame, frame_rate);
auto &data = abc_object->frame_data[frame_index];
// TODO : arrays are emptied when passed to the sockets, so we need to reload the data
diff --git a/intern/cycles/render/alembic.h b/intern/cycles/render/alembic.h
index 014738cb03c..3b3126f50a4 100644
--- a/intern/cycles/render/alembic.h
+++ b/intern/cycles/render/alembic.h
@@ -48,6 +48,8 @@ class AlembicObject : public Node {
// runtime data
bool data_loaded = false;
+ chrono_t min_time = 0.0;
+ chrono_t max_time = 0.0;
// TODO : this is only for Meshes at the moment
// TODO : handle attributes as well
@@ -57,8 +59,9 @@ class AlembicObject : public Node {
array<int3> triangles{};
};
- // TODO : find a way to store the time, for now we presume that frame 0 == index 0
vector<DataCache> frame_data;
+
+ int frame_index(float frame, float frame_rate);
};
class AlembicProcedural : public Procedural {
More information about the Bf-blender-cvs
mailing list