[Bf-blender-cvs] [288fab94058] new-object-types: Objects: modifier stack integration for hair, point clouds and volumes

Brecht Van Lommel noreply at git.blender.org
Sat Feb 1 16:04:05 CET 2020


Commit: 288fab940582519b9848209027d9996dfee10a2d
Author: Brecht Van Lommel
Date:   Sat Feb 1 15:13:15 2020 +0100
Branches: new-object-types
https://developer.blender.org/rB288fab940582519b9848209027d9996dfee10a2d

Objects: modifier stack integration for hair, point clouds and volumes

This is more a prototype for testing, it's not clear yet if we want to use
the existing modifier stack or immediately go to nodes.

Currently working are a few deform modifiers for hair and points clouds.
The infrastructure for constructive modifiers is there as well, just none
are implemented.

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

M	source/blender/blenkernel/BKE_modifier.h
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/displist.c
M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/mesh_convert.c
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/blenkernel/intern/multires.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/pointcloud.c
M	source/blender/blenkernel/intern/volume.cc
M	source/blender/editors/object/object_modifier.c
M	source/blender/modifiers/intern/MOD_armature.c
M	source/blender/modifiers/intern/MOD_array.c
M	source/blender/modifiers/intern/MOD_bevel.c
M	source/blender/modifiers/intern/MOD_boolean.c
M	source/blender/modifiers/intern/MOD_build.c
M	source/blender/modifiers/intern/MOD_cast.c
M	source/blender/modifiers/intern/MOD_cloth.c
M	source/blender/modifiers/intern/MOD_collision.c
M	source/blender/modifiers/intern/MOD_correctivesmooth.c
M	source/blender/modifiers/intern/MOD_curve.c
M	source/blender/modifiers/intern/MOD_datatransfer.c
M	source/blender/modifiers/intern/MOD_decimate.c
M	source/blender/modifiers/intern/MOD_displace.c
M	source/blender/modifiers/intern/MOD_dynamicpaint.c
M	source/blender/modifiers/intern/MOD_edgesplit.c
M	source/blender/modifiers/intern/MOD_explode.c
M	source/blender/modifiers/intern/MOD_fluid.c
M	source/blender/modifiers/intern/MOD_hook.c
M	source/blender/modifiers/intern/MOD_laplaciandeform.c
M	source/blender/modifiers/intern/MOD_laplaciansmooth.c
M	source/blender/modifiers/intern/MOD_lattice.c
M	source/blender/modifiers/intern/MOD_mask.c
M	source/blender/modifiers/intern/MOD_meshcache.c
M	source/blender/modifiers/intern/MOD_meshdeform.c
M	source/blender/modifiers/intern/MOD_meshsequencecache.c
M	source/blender/modifiers/intern/MOD_mirror.c
M	source/blender/modifiers/intern/MOD_multires.c
M	source/blender/modifiers/intern/MOD_none.c
M	source/blender/modifiers/intern/MOD_normal_edit.c
M	source/blender/modifiers/intern/MOD_ocean.c
M	source/blender/modifiers/intern/MOD_particleinstance.c
M	source/blender/modifiers/intern/MOD_particlesystem.c
M	source/blender/modifiers/intern/MOD_remesh.c
M	source/blender/modifiers/intern/MOD_screw.c
M	source/blender/modifiers/intern/MOD_shapekey.c
M	source/blender/modifiers/intern/MOD_shrinkwrap.c
M	source/blender/modifiers/intern/MOD_simpledeform.c
M	source/blender/modifiers/intern/MOD_skin.c
M	source/blender/modifiers/intern/MOD_smooth.c
M	source/blender/modifiers/intern/MOD_softbody.c
M	source/blender/modifiers/intern/MOD_solidify.c
M	source/blender/modifiers/intern/MOD_solidify_extrude.c
M	source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
M	source/blender/modifiers/intern/MOD_solidify_util.h
M	source/blender/modifiers/intern/MOD_subsurf.c
M	source/blender/modifiers/intern/MOD_surface.c
M	source/blender/modifiers/intern/MOD_surfacedeform.c
M	source/blender/modifiers/intern/MOD_triangulate.c
M	source/blender/modifiers/intern/MOD_uvproject.c
M	source/blender/modifiers/intern/MOD_uvwarp.c
M	source/blender/modifiers/intern/MOD_warp.c
M	source/blender/modifiers/intern/MOD_wave.c
M	source/blender/modifiers/intern/MOD_weighted_normal.c
M	source/blender/modifiers/intern/MOD_weightvgedit.c
M	source/blender/modifiers/intern/MOD_weightvgmix.c
M	source/blender/modifiers/intern/MOD_weightvgproximity.c
M	source/blender/modifiers/intern/MOD_weld.c
M	source/blender/modifiers/intern/MOD_wireframe.c

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

diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index 1e549849989..b84dda0ba66 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -100,7 +100,7 @@ typedef enum {
 
   /* For modifiers that use CD_PREVIEW_MCOL for preview. */
   eModifierTypeFlag_UsesPreview = (1 << 9),
-  eModifierTypeFlag_AcceptsLattice = (1 << 10),
+  eModifierTypeFlag_AcceptsVertexCosOnly = (1 << 10),
 } ModifierTypeFlag;
 
 /* IMPORTANT! Keep ObjectWalkFunc and IDWalkFunc signatures compatible. */
@@ -206,18 +206,28 @@ typedef struct ModifierTypeInfo {
 
   /********************* Non-deform modifier functions *********************/
 
-  /* For non-deform types: apply the modifier and return a mesh object.
+  /* For non-deform types: apply the modifier and return a mesh datablock.
    *
-   * The mesh argument should always be non-NULL; the modifier
-   * should read the object data from the mesh object instead of the
-   * actual object data.
+   * The mesh argument should always be non-NULL; the modifier should use the
+   * passed in mesh datablock rather than object->data, as it contains the mesh
+   * with modifier applied up to this point.
    *
-   * The modifier may reuse the mesh argument (i.e. return it in
-   * modified form), but must not release it.
+   * The modifier may modify and return the mesh argument, but must not free it
+   * and must ensure any referenced data layers are converted to non-referenced
+   * before modification.
    */
-  struct Mesh *(*applyModifier)(struct ModifierData *md,
-                                const struct ModifierEvalContext *ctx,
-                                struct Mesh *mesh);
+  struct Mesh *(*modifyMesh)(struct ModifierData *md,
+                             const struct ModifierEvalContext *ctx,
+                             struct Mesh *mesh);
+  struct Hair *(*modifyHair)(struct ModifierData *md,
+                             const struct ModifierEvalContext *ctx,
+                             struct Hair *hair);
+  struct PointCloud *(*modifyPointCloud)(struct ModifierData *md,
+                                         const struct ModifierEvalContext *ctx,
+                                         struct PointCloud *pointcloud);
+  struct Volume *(*modifyVolume)(struct ModifierData *md,
+                                 const struct ModifierEvalContext *ctx,
+                                 struct Volume *volume);
 
   /********************* Optional functions *********************/
 
@@ -445,9 +455,9 @@ struct ModifierData *modifier_get_evaluated(struct Depsgraph *depsgraph,
 
 /* wrappers for modifier callbacks that ensure valid normals */
 
-struct Mesh *modwrap_applyModifier(ModifierData *md,
-                                   const struct ModifierEvalContext *ctx,
-                                   struct Mesh *me);
+struct Mesh *modwrap_modifyMesh(ModifierData *md,
+                                const struct ModifierEvalContext *ctx,
+                                struct Mesh *me);
 
 void modwrap_deformVerts(ModifierData *md,
                          const struct ModifierEvalContext *ctx,
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index d432dc17e52..7256f705df6 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1184,7 +1184,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
         }
       }
 
-      Mesh *mesh_next = modwrap_applyModifier(md, &mectx, mesh_final);
+      Mesh *mesh_next = modwrap_modifyMesh(md, &mectx, mesh_final);
       ASSERT_IS_VALID_MESH(mesh_next);
 
       if (mesh_next) {
@@ -1220,7 +1220,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
         CustomData_MeshMasks_update(&temp_cddata_masks, &nextmask);
         mesh_set_only_copy(mesh_orco, &temp_cddata_masks);
 
-        mesh_next = modwrap_applyModifier(md, &mectx_orco, mesh_orco);
+        mesh_next = modwrap_modifyMesh(md, &mectx_orco, mesh_orco);
         ASSERT_IS_VALID_MESH(mesh_next);
 
         if (mesh_next) {
@@ -1246,7 +1246,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
         nextmask.pmask |= CD_MASK_ORIGINDEX;
         mesh_set_only_copy(mesh_orco_cloth, &nextmask);
 
-        mesh_next = modwrap_applyModifier(md, &mectx_orco, mesh_orco_cloth);
+        mesh_next = modwrap_modifyMesh(md, &mectx_orco, mesh_orco_cloth);
         ASSERT_IS_VALID_MESH(mesh_next);
 
         if (mesh_next) {
@@ -1603,7 +1603,7 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
         mask.pmask |= CD_MASK_ORIGINDEX;
         mesh_set_only_copy(mesh_orco, &mask);
 
-        Mesh *mesh_next = modwrap_applyModifier(md, &mectx_orco, mesh_orco);
+        Mesh *mesh_next = modwrap_modifyMesh(md, &mectx_orco, mesh_orco);
         ASSERT_IS_VALID_MESH(mesh_next);
 
         if (mesh_next) {
@@ -1634,7 +1634,7 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
         }
       }
 
-      Mesh *mesh_next = modwrap_applyModifier(md, &mectx, mesh_final);
+      Mesh *mesh_next = modwrap_modifyMesh(md, &mectx, mesh_final);
       ASSERT_IS_VALID_MESH(mesh_next);
 
       if (mesh_next) {
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 73b7e024b2f..756ed4d7b3c 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -1094,7 +1094,7 @@ static void curve_calc_modifiers_post(Depsgraph *depsgraph,
       if (need_normal) {
         BKE_mesh_ensure_normals(modified);
       }
-      mesh_applied = mti->applyModifier(md, &mectx_apply, modified);
+      mesh_applied = mti->modifyMesh(md, &mectx_apply, modified);
 
       if (mesh_applied) {
         /* Modifier returned a new derived mesh */
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index c32523c7680..48979ab1a57 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -41,6 +41,7 @@
 #include "BKE_library_query.h"
 #include "BKE_library_remap.h"
 #include "BKE_main.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 
 #include "DEG_depsgraph_query.h"
@@ -228,17 +229,75 @@ Hair *BKE_hair_copy_for_eval(Hair *hair_src, bool reference)
   return result;
 }
 
-void BKE_hair_data_update(struct Depsgraph *UNUSED(depsgraph),
-                          struct Scene *UNUSED(scene),
-                          Object *object)
+static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
+                                     struct Scene *scene,
+                                     Object *object,
+                                     Hair *hair_input)
+{
+  Hair *hair = hair_input;
+
+  /* Modifier evaluation modes. */
+  const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
+  const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime;
+  ModifierApplyFlag appflag = use_render ? MOD_APPLY_RENDER : MOD_APPLY_USECACHE;
+  const ModifierEvalContext mectx = {depsgraph, object, appflag};
+
+  /* Get effective list of modifiers to execute. Some effects like shape keys
+   * are added as virtual modifiers before the user created modifiers. */
+  VirtualModifierData virtualModifierData;
+  ModifierData *md = modifiers_getVirtualModifierList(object, &virtualModifierData);
+
+  /* Evaluate modifiers. */
+  for (; md; md = md->next) {
+    const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+    if (!modifier_isEnabled(scene, md, required_mode)) {
+      continue;
+    }
+
+    if ((mti->type == eModifierTypeType_OnlyDeform) &&
+        (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) {
+      /* Ensure we are not modifying the input. */
+      if (hair == hair_input) {
+        hair = BKE_hair_copy_for_eval(hair, true);
+      }
+
+      /* Ensure we are not overwriting referenced data. */
+      CustomData_duplicate_referenced_layer(&hair->pdata, CD_LOCATION, hair->totpoint);
+      BKE_hair_update_customdata_pointers(hair);
+
+      /* Created deformed coordinates array on demand. */
+      mti->deformVerts(md, &mectx, NULL, hair->co, hair->totpoint);
+    }
+    else if (mti->modifyHair) {
+      /* Ensure we are not modifying the input. */
+      if (hair == hair_input) {
+        hair = BKE_hair_copy_for_eval(hair, true);
+      }
+
+      Hair *hair_next = mti->modifyHair(md, &mectx, hair);
+
+      if (hair_next && hair_next != hair) {
+        /* If the modifier returned a new hair, release the old one. */
+        if (hair != hair_input) {
+          BKE_id_free(NULL, hair);
+        }
+        hair = hair_next;
+      }
+    }
+  }
+
+  return hair;
+}
+
+void BKE_hair_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object)
 {
   /* Free any evaluated data and restore original data. */
   BKE_object_free_derived_caches(object);
 
-  /* Modifier evaluation goes here, using BKE_hair_new_for_eval or
-   * BKE_hair_copy_for_eval to create a new Hair. */
+  /* Evaluate modifiers. */
   Hair *hair = object->data;
-  Hair *hair_eval = hair;
+  Hair *hair_eval = hair_evaluate_modifiers(depsgraph, scene, object, hair);
 
   /* Assign evaluated object. */
   const bool is_owned = (hair != hair_eval);
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 72b531c446a..50170c5ba01 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -1111,7 +1111,7 @@ void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Objec
   for (; md; md = md->next) {
     const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
-    if (!(mti->flags & eModifierTypeFlag_AcceptsLattice)) {
+    if (!(mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) {
       continue;
     }
     if (!(md->mode & eModifierMode_Realtime)) {
diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c
index e07d6bf796a..c01e13eea42 100644
--- a/source/blender/

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list