[Bf-blender-cvs] [cd7e41fcdcd] cycles_procedural_api: Revert "remove alembic code"

Kévin Dietrich noreply at git.blender.org
Sat Sep 26 19:25:53 CEST 2020


Commit: cd7e41fcdcd5b850d4ee238c449ced1e5c85041a
Author: Kévin Dietrich
Date:   Sat Sep 26 19:25:40 2020 +0200
Branches: cycles_procedural_api
https://developer.blender.org/rBcd7e41fcdcd5b850d4ee238c449ced1e5c85041a

Revert "remove alembic code"

This reverts commit cae7e63fca81f9fd1bd9110a879b1e1309ae2d4c.

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

M	intern/cycles/blender/CMakeLists.txt
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/blender/blender_sync.h
M	intern/cycles/render/CMakeLists.txt
A	intern/cycles/render/alembic.cpp
A	intern/cycles/render/alembic.h
A	intern/cycles/render/procedural.cpp
A	intern/cycles/render/procedural.h
M	intern/cycles/render/scene.cpp
M	intern/cycles/render/scene.h

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

diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt
index 0d805dc8683..7d1b695434e 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
 )
 
 set(INC_SYS
+  ${ALEMBIC_INCLUDE_DIRS}
   ${PYTHON_INCLUDE_DIRS}
   ${GLEW_INCLUDE_DIR}
 )
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index ddc4f5be0bc..03997e3386f 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -29,6 +29,8 @@
 #include "blender/blender_sync.h"
 #include "blender/blender_util.h"
 
+#include "render/alembic.h"
+
 #include "util/util_foreach.h"
 #include "util/util_hash.h"
 #include "util/util_logging.h"
@@ -320,6 +322,78 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph,
 
 /* Object Loop */
 
+static BL::MeshSequenceCacheModifier object_alembic_cache_find(BL::Object b_ob)
+{
+  if (b_ob.modifiers.length() > 0) {
+    BL::Modifier b_mod = b_ob.modifiers[b_ob.modifiers.length() - 1];
+
+    if (b_mod.type() == BL::Modifier::type_MESH_SEQUENCE_CACHE) {
+      return BL::MeshSequenceCacheModifier(b_mod);
+    }
+  }
+
+  return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+}
+
+void BlenderSync::sync_procedural(BL::Object &b_ob,
+                                  BL::MeshSequenceCacheModifier &b_mesh_cache,
+                                  int frame_current,
+                                  float motion_time)
+{
+  bool motion = motion_time != 0.0f;
+
+  if (motion) {
+    return;
+  }
+
+  ObjectKey key(b_ob.parent(), NULL, b_ob, false);
+
+  AlembicProcedural *p = static_cast<AlembicProcedural *>(procedural_map.find(key));
+
+  if (!p) {
+    p = scene->create_node<AlembicProcedural>();
+    procedural_map.add(key, p);
+  }
+  else {
+    procedural_map.used(p);
+  }
+
+  p->set_frame(static_cast<float>(frame_current));
+  if (p->frame_is_modified()) {
+    scene->procedural_manager->need_update = true;
+  }
+
+  auto absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
+
+  p->set_filepath(ustring(absolute_path));
+
+  /* if the filepath was not modified, then we have already created the objects */
+  if (!p->filepath_is_modified()) {
+    return;
+  }
+
+  Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
+                                                                      scene->default_surface;
+  /* Find shader indices. */
+  array<Node *> used_shaders;
+
+  BL::Object::material_slots_iterator slot;
+  for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
+    BL::ID b_material(slot->material());
+    find_shader(b_material, used_shaders, default_shader);
+  }
+
+  if (used_shaders.size() == 0) {
+    used_shaders.push_back_slow(default_shader);
+  }
+
+  AlembicObject *abc_object = scene->create_node<AlembicObject>();
+  abc_object->set_path(ustring(b_mesh_cache.object_path()));
+  abc_object->set_used_shaders(used_shaders);
+
+  p->objects.push_back_slow(abc_object);
+}
+
 void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
                                BL::SpaceView3D &b_v3d,
                                float motion_time)
@@ -332,6 +406,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
     light_map.pre_sync();
     geometry_map.pre_sync();
     object_map.pre_sync();
+    procedural_map.pre_sync();
     particle_system_map.pre_sync();
     motion_times.clear();
   }
@@ -367,14 +442,21 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
 
     /* Object itself. */
     if (b_instance.show_self()) {
-      sync_object(b_depsgraph,
-                  b_view_layer,
-                  b_instance,
-                  motion_time,
-                  false,
-                  show_lights,
-                  culling,
-                  &use_portal);
+      BL::MeshSequenceCacheModifier b_mesh_cache = object_alembic_cache_find(b_ob);
+
+      if (b_mesh_cache) {
+        sync_procedural(b_ob, b_mesh_cache, b_depsgraph.scene().frame_current(), motion_time);
+      }
+      else {
+        sync_object(b_depsgraph,
+                    b_view_layer,
+                    b_instance,
+                    motion_time,
+                    false,
+                    show_lights,
+                    culling,
+                    &use_portal);
+      }
     }
 
     /* Particle hair as separate object. */
@@ -402,6 +484,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
     geometry_map.post_sync(scene);
     object_map.post_sync(scene);
     particle_system_map.post_sync(scene);
+    procedural_map.post_sync(scene);
   }
 
   if (motion)
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index d33a7f709ed..28ef5d7fb13 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -24,6 +24,7 @@
 #include "render/mesh.h"
 #include "render/nodes.h"
 #include "render/object.h"
+#include "render/procedural.h"
 #include "render/scene.h"
 #include "render/shader.h"
 
@@ -58,6 +59,8 @@ BlenderSync::BlenderSync(BL::RenderEngine &b_engine,
       b_scene(b_scene),
       shader_map(),
       object_map(),
+      procedural_map(),
+      geometry_map(),
       light_map(),
       particle_system_map(),
       world_map(NULL),
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index d710bfea0d5..cdb02ed837c 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -147,6 +147,11 @@ class BlenderSync {
                       BlenderObjectCulling &culling,
                       bool *use_portal);
 
+  void sync_procedural(BL::Object &b_ob,
+                       BL::MeshSequenceCacheModifier &b_mesh_cache,
+                       int frame_current,
+                       float motion_time);
+
   /* Volume */
   void sync_volume(BL::Object &b_ob, Volume *volume, array<Node *> &used_shaders);
 
@@ -218,6 +223,7 @@ class BlenderSync {
 
   id_map<void *, Shader> shader_map;
   id_map<ObjectKey, Object> object_map;
+  id_map<ObjectKey, Procedural> procedural_map;
   id_map<GeometryKey, Geometry> geometry_map;
   id_map<ObjectKey, Light> light_map;
   id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
diff --git a/intern/cycles/render/CMakeLists.txt b/intern/cycles/render/CMakeLists.txt
index 43e66aa4e5b..33d486a34e2 100644
--- a/intern/cycles/render/CMakeLists.txt
+++ b/intern/cycles/render/CMakeLists.txt
@@ -19,10 +19,12 @@ set(INC
 )
 
 set(INC_SYS
+  ${ALEMBIC_INCLUDE_DIR}
   ${GLEW_INCLUDE_DIR}
 )
 
 set(SRC
+  alembic.cpp
   attribute.cpp
   background.cpp
   bake.cpp
@@ -48,6 +50,7 @@ set(SRC
   mesh_displace.cpp
   mesh_subdivision.cpp
   nodes.cpp
+  procedural.cpp
   object.cpp
   osl.cpp
   particles.cpp
@@ -64,6 +67,7 @@ set(SRC
 )
 
 set(SRC_HEADERS
+  alembic.h
   attribute.h
   bake.h
   background.h
@@ -90,6 +94,7 @@ set(SRC_HEADERS
   object.h
   osl.h
   particles.h
+  procedural.h
   curves.h
   scene.h
   session.h
diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp
new file mode 100644
index 00000000000..70e0053cdd8
--- /dev/null
+++ b/intern/cycles/render/alembic.cpp
@@ -0,0 +1,512 @@
+/*
+ * Copyright 2011-2018 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "alembic.h"
+
+#include <algorithm>
+#include <fnmatch.h>
+#include <iterator>
+#include <set>
+#include <sstream>
+#include <stack>
+#include <stdio.h>
+#include <vector>
+
+#include "render/camera.h"
+#include "render/curves.h"
+#include "render/mesh.h"
+#include "render/object.h"
+#include "render/scene.h"
+#include "render/shader.h"
+
+#include "util/util_foreach.h"
+#include "util/util_transform.h"
+#include "util/util_vector.h"
+
+CCL_NAMESPACE_BEGIN
+
+static float3 make_float3_from_yup(Imath::Vec3<float> const &v)
+{
+  return make_float3(v.x, -v.z, v.y);
+}
+
+static M44d convert_yup_zup(M44d const &mtx)
+{
+  Imath::Vec3<double> scale, shear, rot, trans;
+  extractSHRT(mtx, scale, shear, rot, trans);
+  M44d rotmat, scalemat, transmat;
+  rotmat.setEulerAngles(Imath::Vec3<double>(rot.x, -rot.z, rot.y));
+  scalemat.setScale(Imath::Vec3<double>(scale.x, scale.z, scale.y));
+  transmat.setTranslation(Imath::Vec3<double>(trans.x, -trans.z, trans.y));
+  return scalemat * rotmat * transmat;
+}
+
+static Transform make_transform(const Abc::M44d &a)
+{
+  auto m = convert_yup_zup(a);
+  Transform trans;
+  for (int j = 0; j < 3; j++) {
+    for (int i = 0; i < 4; i++) {
+      trans[j][i] = static_cast<float>(m[i][j]);
+    }
+  }
+  return trans;
+}
+
+/* TODO: any attribute lookup should probably go through the AttributeRequests
+ */
+static void read_uvs(const IV2fGeomParam &uvs,
+                     Geometry *node,
+                     const int *face_counts,
+                     const int num_faces)
+{
+  if (uvs.valid()) {
+    switch (uvs.getScope()) {
+      case kVaryingScope:
+      case kVertexScope: {
+        IV2fGeomParam::Sample uvsample = uvs.getExpandedValue();
+        break;
+      }
+      case kFacevaryingScope: {
+        IV2fGeomParam::Sample uvsample = uvs.getIndexedValue();
+
+        ustring name = ustring("UVMap");
+        Attribute *attr = node->attributes.add(ATTR_STD_UV, name);
+        float2 *fdata = attr->data_float2();
+
+        /* loop over the triangles */
+        int index_offset = 0;
+        const unsigned int *uvIndices = uvsample.getIndices()->get();
+        const Imath::Vec2<float> *uvValues = uvsample.getVals()->get();
+
+        for (size_t i = 0; i < num_fa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list