[Bf-blender-cvs] [f3e4464ef7c] temp-lineart-contained: LineArt: PointCache for caching chains (code path only)

YimingWu noreply at git.blender.org
Wed Apr 7 17:03:41 CEST 2021


Commit: f3e4464ef7c0fa65da8dc7b798227c29ce09d51a
Author: YimingWu
Date:   Wed Apr 7 23:01:11 2021 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rBf3e4464ef7c0fa65da8dc7b798227c29ce09d51a

LineArt: PointCache for caching chains (code path only)

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

M	source/blender/blenkernel/BKE_pointcache.h
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
M	source/blender/makesdna/DNA_pointcache_types.h
M	source/blender/makesdna/DNA_scene_types.h

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

diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 170eb4ba662..978287a55a5 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -63,6 +63,7 @@ extern "C" {
 #define PTCACHE_TYPE_DYNAMICPAINT 5
 #define PTCACHE_TYPE_RIGIDBODY 6
 #define PTCACHE_TYPE_SIM_PARTICLES 7
+#define PTCACHE_TYPE_LINEART 8
 
 /* high bits reserved for flags that need to be stored in file */
 #define PTCACHE_TYPEFLAG_COMPRESS (1 << 16)
@@ -285,6 +286,7 @@ void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid,
                                       struct Object *ob,
                                       struct DynamicPaintSurface *surface);
 void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
+void BKE_ptcache_id_from_lineart(PTCacheID *pid, struct Scene *scene, void *lineart_renderbuffer);
 
 PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache);
 void BKE_ptcache_ids_from_object(struct ListBase *lb,
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 17434ee8023..c1b05002c2d 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -127,6 +127,7 @@ static int ptcache_data_size[] = {
     sizeof(float),        /* BPHYS_DATA_SIZE */
     sizeof(float[3]),     /* BPHYS_DATA_TIMES */
     sizeof(BoidData),     /* case BPHYS_DATA_BOIDS */
+    sizeof(void *),       /* BPHYS_DATA_LINEART */
 };
 
 static int ptcache_extra_datasize[] = {
@@ -872,6 +873,29 @@ static void ptcache_rigidbody_error(const struct ID *UNUSED(owner_id),
   /* ignored for now */
 }
 
+/* Line Art functions */
+static int ptcache_lineart_write(int index, void *la_rb, void **data, int UNUSED(cfra))
+{
+  /* data is output */
+  return 1;
+}
+static void ptcache_lineart_read(
+    int index, void *la_rb, void **data, float UNUSED(cfra), const float *old_data)
+{
+}
+static int ptcache_lineart_totpoint(void *la_rb, int UNUSED(cfra))
+{
+  /* The cache is one whole block, so we always return 1. */
+  return 1;
+}
+
+static void ptcache_lineart_error(const struct ID *UNUSED(owner_id),
+                                  void *UNUSED(la_v),
+                                  const char *UNUSED(message))
+{
+  /* ignored for now */
+}
+
 /* Creating ID's */
 void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
 {
@@ -1104,6 +1128,45 @@ void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, Object *ob, RigidBodyWorld *r
   pid->file_type = PTCACHE_FILE_PTCACHE;
 }
 
+void BKE_ptcache_id_from_lineart(PTCacheID *pid, Scene *scene, void *lineart_renderbuffer)
+{
+
+  memset(pid, 0, sizeof(PTCacheID));
+
+  pid->owner_id = scene;
+  pid->calldata = lineart_renderbuffer;
+  pid->type = PTCACHE_TYPE_RIGIDBODY;
+  pid->cache = scene->grease_pencil_settings.lineart_cache;
+  pid->cache_ptr = &scene->grease_pencil_settings.lineart_cache;
+  pid->ptcaches = &scene->grease_pencil_settings.lineart_caches;
+
+  pid->totpoint = pid->totwrite = ptcache_lineart_totpoint;
+  pid->error = ptcache_rigidbody_error;
+
+  pid->write_point = ptcache_lineart_write;  // ptcache_rigidbody_write;
+  pid->read_point = ptcache_lineart_read;    // ptcache_rigidbody_read;
+  pid->interpolate_point = NULL;
+
+  pid->write_stream = NULL;
+  pid->read_stream = NULL;
+
+  pid->write_extra_data = NULL;
+  pid->read_extra_data = NULL;
+  pid->interpolate_extra_data = NULL;
+
+  pid->write_header = NULL;  // ptcache_basic_header_write;
+  pid->read_header = NULL;   // ptcache_basic_header_read;
+
+  pid->data_types = (1 << BPHYS_DATA_LINEART);
+  pid->info_types = 0;
+
+  pid->stack_index = 0;
+
+  pid->default_step = 1;
+  pid->max_step = 1;
+  pid->file_type = PTCACHE_FILE_PTCACHE;
+}
+
 /**
  * \param ob: Optional, may be NULL.
  * \param scene: Optional may be NULL.
@@ -1250,6 +1313,13 @@ static bool foreach_object_ptcache(
       return false;
     }
   }
+  /* Line art. */
+  if (scene != NULL && (scene->grease_pencil_settings.lineart_cache != NULL)) {
+    BKE_ptcache_id_from_lineart(&pid, scene, NULL);
+    if (!callback(&pid, callback_user_data)) {
+      return false;
+    }
+  }
   return true;
 }
 
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index d1cf2fea48f..0f9a55fabd1 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -3861,6 +3861,16 @@ bool MOD_lineart_compute_feature_lines(Depsgraph *depsgraph, LineartGpencilModif
     lineart_count_and_print_render_buffer_memory(rb);
   }
 
+  Scene *use_scene = scene->id.orig_id ? (Scene *)scene->id.orig_id : scene;
+  if (!use_scene->grease_pencil_settings.lineart_cache) {
+    use_scene->grease_pencil_settings.lineart_cache = BKE_ptcache_add(
+        &use_scene->grease_pencil_settings.lineart_caches);
+  }
+  PTCacheID pid;
+  BKE_ptcache_id_from_lineart(&pid, use_scene, rb);
+  BKE_ptcache_id_time(&pid, use_scene, use_scene->r.cfra, NULL, NULL, NULL);
+  BKE_ptcache_write(&pid, use_scene->r.cfra);
+
   return true;
 }
 
diff --git a/source/blender/makesdna/DNA_pointcache_types.h b/source/blender/makesdna/DNA_pointcache_types.h
index de2fa3f10fe..66ab0bc2610 100644
--- a/source/blender/makesdna/DNA_pointcache_types.h
+++ b/source/blender/makesdna/DNA_pointcache_types.h
@@ -45,8 +45,9 @@ extern "C" {
 #define BPHYS_DATA_SIZE 5
 #define BPHYS_DATA_TIMES 6
 #define BPHYS_DATA_BOIDS 7
+#define BPHYS_DATA_LINEART 8
 
-#define BPHYS_TOT_DATA 8
+#define BPHYS_TOT_DATA 9
 
 #define BPHYS_EXTRA_FLUID_SPRINGS 1
 #define BPHYS_EXTRA_CLOTH_ACCELERATION 2
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index c7f7e610a1a..bdd3fa7ad25 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1658,9 +1658,13 @@ typedef struct SceneEEVEE {
   float light_threshold;
 } SceneEEVEE;
 
+struct PointCache;
+
 typedef struct SceneGpencil {
   float smaa_threshold;
   char _pad[4];
+  struct PointCache *lineart_cache;
+  struct ListBase lineart_caches;
 } SceneGpencil;
 
 /* *************************************************************** */



More information about the Bf-blender-cvs mailing list