[Bf-blender-cvs] [da244d5abef] cycles_procedural_api: add support for reading curve radiuses from the archive

Kévin Dietrich noreply at git.blender.org
Sun Dec 6 06:26:28 CET 2020


Commit: da244d5abef6c2897bec2f43aff41a120641be09
Author: Kévin Dietrich
Date:   Thu Dec 3 13:13:07 2020 +0100
Branches: cycles_procedural_api
https://developer.blender.org/rBda244d5abef6c2897bec2f43aff41a120641be09

add support for reading curve radiuses from the archive

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

M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/render/alembic.cpp
M	intern/cycles/render/alembic.h
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/io/io_alembic.c
M	source/blender/io/alembic/ABC_alembic.h
M	source/blender/io/alembic/intern/abc_reader_curves.cc
M	source/blender/io/alembic/intern/abc_reader_object.h
M	source/blender/io/alembic/intern/alembic_capi.cc
M	source/blender/makesdna/DNA_cachefile_types.h
M	source/blender/makesrna/intern/rna_cachefile.c

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

diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index bb1e5107176..814250207b4 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -508,6 +508,7 @@ void BlenderSync::sync_procedural(BL::Object &b_ob,
 
   p->set_frame(static_cast<float>(frame_current));
   p->set_frame_rate(b_scene.render().fps() / b_scene.render().fps_base());
+  p->set_default_curves_radius(cache_file.default_curves_radius());
 
   auto absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
 
diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp
index 5c2b627912b..947bcce9e53 100644
--- a/intern/cycles/render/alembic.cpp
+++ b/intern/cycles/render/alembic.cpp
@@ -571,28 +571,40 @@ void AlembicObject::load_all_data(IPolyMeshSchema &schema, Progress &progress)
   data_loaded = true;
 }
 
-void AlembicObject::load_all_data(const ICurvesSchema &schema, Progress &progress)
+void AlembicObject::load_all_data(const ICurvesSchema &schema, Progress &progress, float default_radius)
 {
   cached_data.clear();
 
-  cached_data.curve_keys.set_time_sampling(*schema.getTimeSampling());
-  cached_data.curve_radius.set_time_sampling(*schema.getTimeSampling());
-  cached_data.curve_first_key.set_time_sampling(*schema.getTimeSampling());
-  cached_data.curve_shader.set_time_sampling(*schema.getTimeSampling());
+  const TimeSamplingPtr time_sampling = schema.getTimeSampling();
+  cached_data.curve_keys.set_time_sampling(*time_sampling);
+  cached_data.curve_radius.set_time_sampling(*time_sampling);
+  cached_data.curve_first_key.set_time_sampling(*time_sampling);
+  cached_data.curve_shader.set_time_sampling(*time_sampling);
 
   for (size_t i = 0; i < schema.getNumSamples(); ++i) {
     if (progress.get_cancel()) {
       return;
     }
 
-    const ISampleSelector iss = ISampleSelector(static_cast<index_t>(i));
+    const ISampleSelector iss = ISampleSelector(index_t(i));
     const ICurvesSchema::Sample sample = schema.getValue(iss);
 
-    const double time = schema.getTimeSampling()->getSampleTime(static_cast<index_t>(i));
+    const double time = time_sampling->getSampleTime(index_t(i));
 
     const Int32ArraySamplePtr curves_num_vertices = sample.getCurvesNumVertices();
     const P3fArraySamplePtr position = sample.getPositions();
 
+    const IFloatGeomParam widths_param = schema.getWidthsParam();
+    FloatArraySamplePtr radiuses;
+
+    if (widths_param.valid()) {
+      IFloatGeomParam::Sample wsample = widths_param.getExpandedValue(iss);
+      radiuses = wsample.getVals();
+    }
+
+    const bool do_radius = (radiuses != nullptr) && (radiuses->size() > 1);
+    float radius = (radiuses && radiuses->size() == 1) ? (*radiuses)[0] : default_radius;
+
     array<float3> curve_keys;
     array<float> curve_radius;
     array<int> curve_first_key;
@@ -610,7 +622,12 @@ void AlembicObject::load_all_data(const ICurvesSchema &schema, Progress &progres
       for (int j = 0; j < num_vertices; j++) {
         const V3f &f = position->get()[offset + j];
         curve_keys.push_back_reserved(make_float3_from_yup(f));
-        curve_radius.push_back_reserved(0.01f);
+
+        if (do_radius) {
+          radius = (*radiuses)[offset + j];
+        }
+
+        curve_radius.push_back_reserved(radius);
       }
 
       curve_first_key.push_back_reserved(offset);
@@ -844,6 +861,7 @@ NODE_DEFINE(AlembicProcedural)
   SOCKET_STRING(filepath, "Filename", ustring());
   SOCKET_FLOAT(frame, "Frame", 1.0f);
   SOCKET_FLOAT(frame_rate, "Frame Rate", 24.0f);
+  SOCKET_FLOAT(default_curves_radius, "Default Curve Radius", 0.01f);
 
   SOCKET_NODE_ARRAY(objects, "Objects", &AlembicObject::node_type);
 
@@ -854,6 +872,7 @@ AlembicProcedural::AlembicProcedural() : Procedural(node_type)
 {
   frame = 1.0f;
   frame_rate = 24.0f;
+  default_curves_radius = 0.01f;
 }
 
 AlembicProcedural::~AlembicProcedural()
@@ -1082,9 +1101,9 @@ void AlembicProcedural::read_curves(Scene *scene,
     hair = static_cast<Hair *>(abc_object->get_object()->get_geometry());
   }
 
-  if (!abc_object->has_data_loaded()) {
+  if (!abc_object->has_data_loaded() || default_curves_radius_is_modified()) {
     ICurvesSchema schema = curves.getSchema();
-    abc_object->load_all_data(schema, progress);
+    abc_object->load_all_data(schema, progress, default_curves_radius);
   }
 
   CachedData &cached_data = abc_object->get_cached_data();
diff --git a/intern/cycles/render/alembic.h b/intern/cycles/render/alembic.h
index 7c972cf70d3..4787962d6b8 100644
--- a/intern/cycles/render/alembic.h
+++ b/intern/cycles/render/alembic.h
@@ -206,7 +206,7 @@ class AlembicObject : public Node {
   Object *get_object();
 
   void load_all_data(Alembic::AbcGeom::IPolyMeshSchema &schema, Progress &progress);
-  void load_all_data(const Alembic::AbcGeom::ICurvesSchema &schema, Progress &progress);
+  void load_all_data(const Alembic::AbcGeom::ICurvesSchema &schema, Progress &progress, float default_radius);
 
   bool has_data_loaded() const;
 
@@ -253,6 +253,7 @@ class AlembicProcedural : public Procedural {
   NODE_SOCKET_API(float, frame)
   NODE_SOCKET_API(float, frame_rate)
   NODE_SOCKET_API_ARRAY(array<Node *>, objects)
+  NODE_SOCKET_API(float, default_curves_radius)
 
   void add_object(AlembicObject *object);
 
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index d6c31809a2e..e541efef535 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -63,6 +63,7 @@ static void cache_file_init_data(ID *id)
 
   BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(cache_file, id));
 
+  cache_file->default_curves_radius = 0.01f;
   cache_file->scale = 1.0f;
   cache_file->velocity_unit = CACHEFILE_VELOCITY_UNIT_SECOND;
   BLI_strncpy(cache_file->velocity_name, ".velocities", sizeof(cache_file->velocity_name));
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 43ead511cfe..c1b47eea2b7 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -7229,6 +7229,8 @@ void uiTemplateCacheFile(uiLayout *layout,
   uiItemR(layout, &fileptr, "velocity_name", 0, NULL, ICON_NONE);
   uiItemR(layout, &fileptr, "velocity_unit", 0, NULL, ICON_NONE);
 
+  uiItemR(layout, &fileptr, "default_curves_radius", 0, NULL, ICON_NONE);
+
   /* TODO: unused for now, so no need to expose. */
 #if 0
   row = uiLayoutRow(layout, false);
diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index de7f123a168..78a5434b697 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -595,6 +595,8 @@ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
   uiItemR(col, imfptr, "is_sequence", 0, NULL, ICON_NONE);
   uiItemR(col, imfptr, "validate_meshes", 0, NULL, ICON_NONE);
   uiItemR(col, imfptr, "force_modifier", 0, NULL, ICON_NONE);
+
+  uiItemR(box, imfptr, "default_curves_radius", 0, NULL, ICON_NONE);
 }
 
 static void wm_alembic_import_draw(bContext *UNUSED(C), wmOperator *op)
@@ -630,6 +632,7 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
   const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
   const bool force_modifier = RNA_boolean_get(op->ptr, "force_modifier");
   const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job");
+  const float default_curves_radius = RNA_float_get(op->ptr, "default_curves_radius");
 
   int offset = 0;
   int sequence_len = 1;
@@ -657,6 +660,7 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
                        offset,
                        validate_meshes,
                        force_modifier,
+                       default_curves_radius,
                        as_background_job);
 
   return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
@@ -718,6 +722,17 @@ void WM_OT_alembic_import(wmOperatorType *ot)
                   "Is Sequence",
                   "Set to true if the cache is split into separate files");
 
+  RNA_def_float(
+      ot->srna,
+      "default_curves_radius",
+      0.01f,
+      0.0001f,
+      1000.0f,
+      "Curves Radius",
+      "Value to use for defining the curves width when the curves do not have a property for it",
+      0.0001f,
+      1000.0f);
+
   RNA_def_boolean(
       ot->srna,
       "as_background_job",
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h
index 9504d2b99a6..b72cc5064d4 100644
--- a/source/blender/io/alembic/ABC_alembic.h
+++ b/source/blender/io/alembic/ABC_alembic.h
@@ -96,6 +96,7 @@ bool ABC_import(struct bContext *C,
                 int offset,
                 bool validate_meshes,
                 bool force_modifier,
+                float default_curves_radius,
                 bool as_background_job);
 
 AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
diff --git a/source/blender/io/alembic/intern/abc_reader_curves.cc b/source/blender/io/alembic/intern/abc_reader_curves.cc
index 4af7632721e..753d6f064e9 100644
--- a/source/blender/io/alembic/intern/abc_reader_curves.cc
+++ b/source/blender/io/alembic/intern/abc_reader_curves.cc
@@ -222,7 +222,7 @@ void AbcCurveReader::read_curve_sample(Curve *cu,
     float weight = 1.0f;
 
     const bool do_radius = (radiuses != nullptr) && (radiuses->size() > 1);
-    float radius = (radiuses && radiuses->size() == 1) ? (*radiuses)[0] : 1.0f;
+    float radius = (radiuses && radiuses->size() == 1) ? (*radiuses)[0] : m_settings->default_curves_radius;
 
     nu->type = CU_NURBS;
 
diff --git a/source/blender/io/alembic/intern/abc_reader_object.h b/source/blender/io/alembic/intern/abc_reader_object.h
index ff11f75348b..be33b11d414 100644
--- a/source/blender/io/alembic/intern/abc_reader_object.h
+++ b/source/blender/io/alembic/intern/abc_reader_object.h
@@ -53,6 +53,8 @@ struct ImportSettings {
   bool validate_meshes;
   bool force_modifier;
 
+  float default_curves_radius;
+
   CacheFile *

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list