[Bf-blender-cvs] [7fdb4158304] cycles_procedural_api: alembic, avoid clearing the mesh, reload deleted data from previous playback

Kévin Dietrich noreply at git.blender.org
Wed Sep 9 01:08:22 CEST 2020


Commit: 7fdb4158304d55513907f7987468735e41e066cc
Author: Kévin Dietrich
Date:   Tue Sep 8 05:42:13 2020 +0200
Branches: cycles_procedural_api
https://developer.blender.org/rB7fdb4158304d55513907f7987468735e41e066cc

alembic, avoid clearing the mesh, reload deleted data from previous
playback

===================================================================

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 e00055d1d62..1760c15fa69 100644
--- a/intern/cycles/render/alembic.cpp
+++ b/intern/cycles/render/alembic.cpp
@@ -328,28 +328,49 @@ void AlembicProcedural::read_mesh(Scene *scene,
     load_all_data(abc_object, schema);
   }
 
-  mesh->clear();
-  mesh->set_used_shaders(used_shaders);
-  mesh->set_use_motion_blur(use_motion_blur);
-  mesh->tag_update(scene, true);
-
   int frame_index = static_cast<int>(frame);
   if (frame_time >= abc_object->frame_data.size()) {
     frame_index = abc_object->frame_data.size() - 1;
   }
 
   auto &data = abc_object->frame_data[frame_index];
-  // TODO : animations like fluids will have different data or different frames
-  auto &triangle_data = abc_object->frame_data[0].triangles;
 
-  mesh->reserve_mesh(data.vertices.size(), triangle_data.size());
+  // TODO : arrays are emptied when passed to the sockets, so we need to reload the data
+  // perhaps we should just have a way to set the pointer
+  if (data.dirty) {
+    abc_object->frame_data.clear();
+    load_all_data(abc_object, schema);
+    data = abc_object->frame_data[frame_index];
+  }
+
+  data.dirty = true;
+  // TODO : animations like fluids will have different data on different frames
+  auto &triangle_data = abc_object->frame_data[0].triangles;
 
-  mesh->verts = data.vertices;
+  mesh->set_verts(data.vertices);
 
-  for (int i = 0; i < triangle_data.size(); ++i) {
-    int3 tri = triangle_data[i];
+  {
     // TODO : shader association
-    mesh->add_triangle(tri.x, tri.y, tri.z, 0, 1);
+    array<int> triangles;
+    array<bool> smooth;
+    array<int> shader;
+
+    triangles.reserve(triangle_data.size() * 3);
+    smooth.reserve(triangle_data.size());
+    shader.reserve(triangle_data.size());
+
+    for (int i = 0; i < triangle_data.size(); ++i) {
+      int3 tri = triangle_data[i];
+      triangles.push_back_reserved(tri.x);
+      triangles.push_back_reserved(tri.y);
+      triangles.push_back_reserved(tri.z);
+      shader.push_back_reserved(0);
+      smooth.push_back_reserved(1);
+    }
+
+    mesh->set_triangles(triangles);
+    mesh->set_smooth(smooth);
+    mesh->set_shader(shader);
   }
 
   IPolyMeshSchema::Sample samp = schema.getValue(ISampleSelector(frame_time));
@@ -366,6 +387,12 @@ void AlembicProcedural::read_mesh(Scene *scene,
     memcpy(
         attr->data_float3(), mesh->get_verts().data(), sizeof(float3) * mesh->get_verts().size());
   }
+
+  if (mesh->is_modified()) {
+    // TODO : check for modification of subdivision data (is a separate object in Alembic)
+    bool need_rebuild = mesh->triangles_is_modified();
+    mesh->tag_update(scene, need_rebuild);
+  }
 }
 
 void AlembicProcedural::read_curves(Scene *scene,
diff --git a/intern/cycles/render/alembic.h b/intern/cycles/render/alembic.h
index a0fdfab2a36..014738cb03c 100644
--- a/intern/cycles/render/alembic.h
+++ b/intern/cycles/render/alembic.h
@@ -52,6 +52,7 @@ class AlembicObject : public Node {
   // TODO : this is only for Meshes at the moment
   // TODO : handle attributes as well
   struct DataCache {
+      bool dirty = false;
       array<float3> vertices{};
       array<int3> triangles{};
   };



More information about the Bf-blender-cvs mailing list