[Bf-blender-cvs] [58997f47af0] functions: initial passive modifier mode

Jacques Lucke noreply at git.blender.org
Thu Sep 5 19:12:09 CEST 2019


Commit: 58997f47af0f447b80cc1e0e55ae970384f1bd9a
Author: Jacques Lucke
Date:   Thu Sep 5 18:30:36 2019 +0200
Branches: functions
https://developer.blender.org/rB58997f47af0f447b80cc1e0e55ae970384f1bd9a

initial passive modifier mode

This allows creating separate meshes for the different particle types.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_bparticles.c
M	source/blender/simulations/BParticles.h
M	source/blender/simulations/bparticles/c_wrapper.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 8ee964883f6..aaa5d872f3d 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1662,15 +1662,20 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         props.modifier_name = md.name
 
     def BPARTICLES(self, layout, ob, md):
-        row = layout.row(align=True)
-        row.prop(md, "bparticles_tree")
-        props = row.operator("bp.new_bparticles_tree", text="", icon="ADD")
-        props.object_name = ob.name
-        props.modifier_name = md.name
+        layout.prop(md, "mode")
+        if md.mode == 'SIMULATOR':
+            row = layout.row(align=True)
+            row.prop(md, "bparticles_tree")
+            props = row.operator("bp.new_bparticles_tree", text="", icon="ADD")
+            props.object_name = ob.name
+            props.modifier_name = md.name
 
-        layout.operator("object.bparticles_clear_cache", text="Clear Cache")
+            layout.operator("object.bparticles_clear_cache", text="Clear Cache")
 
-        layout.prop(md, "output_type")
+            layout.prop(md, "output_type")
+        elif md.mode == 'PASSIVE':
+            layout.prop(md, "source_object")
+            layout.prop(md, "source_particle_type")
 
 
 class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
@@ -1814,7 +1819,7 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
 
         col.label(text="Material:")
         row = col.row(align=True)
-        
+
         row.prop_search(md, "material", gpd, "materials", text="", icon='SHADING_TEXTURE')
         row.prop(md, "invert_materials", text="", icon='ARROW_LEFTRIGHT')
         row = layout.row(align=True)
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 44de62b1298..36a80b51926 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1985,15 +1985,30 @@ typedef struct BParticlesFrameCache {
 typedef enum eBParticlesOutputType {
   MOD_BPARTICLES_OUTPUT_POINTS,
   MOD_BPARTICLES_OUTPUT_TETRAHEDONS,
+  MOD_BPARTICLES_OUTPUT_NONE,
 } eBParticlesOutputType;
 
+typedef enum eBParticlesModifierMode {
+  MOD_BPARTICLES_MODE_SIMULATOR,
+  MOD_BPARTICLES_MODE_PASSIVE,
+} eBParticlesModifierMode;
+
 typedef struct BParticlesModifierData {
   ModifierData modifier;
-  struct bNodeTree *bparticles_tree;
+  unsigned int mode;
+
+  /* Simulator Settings */
   unsigned int output_type;
+  struct bNodeTree *bparticles_tree;
 
   unsigned int num_cached_frames;
+  char _pad[4];
   BParticlesFrameCache *cached_frames;
+
+  /* Passive Settings */
+  struct Object *source_object;
+  char source_particle_type[64];
+
 } BParticlesModifierData;
 
 #endif /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 9ec169e10f5..63b01af8b62 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -6053,6 +6053,28 @@ static void rna_def_modifier_bparticles(BlenderRNA *brna)
   RNA_def_struct_sdna(srna, "BParticlesModifierData");
   RNA_def_struct_ui_icon(srna, ICON_NONE);
 
+  const static EnumPropertyItem mode_types[] = {
+      {MOD_BPARTICLES_MODE_SIMULATOR,
+       "SIMULATOR",
+       0,
+       "Simulator",
+       "Use this modifier as main simulator"},
+      {MOD_BPARTICLES_MODE_PASSIVE,
+       "PASSIVE",
+       0,
+       "Passive",
+       "This modifiers only copies particle data from another object"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, mode_types);
+  RNA_def_property_ui_text(
+      prop, "Mode", "Use the modifier as active simulator or only copy data from other modifier");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+  /* Simulator Mode */
+
   prop = RNA_def_property(srna, "bparticles_tree", PROP_POINTER, PROP_NONE);
   RNA_def_property_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop, "BParticles Tree", "BParticles node tree");
@@ -6069,6 +6091,7 @@ static void rna_def_modifier_bparticles(BlenderRNA *brna)
        0,
        "Tetrahedons",
        "Create a mesh that has a tetrahedon at every vertex position"},
+      {MOD_BPARTICLES_OUTPUT_NONE, "NONE", 0, "None", "Create no output mesh"},
       {0, NULL, 0, NULL, NULL},
   };
 
@@ -6077,6 +6100,18 @@ static void rna_def_modifier_bparticles(BlenderRNA *brna)
   RNA_def_property_ui_text(
       prop, "Output Type", "Method for creating the output mesh from the particle data");
   RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+  /* Passive Mode */
+
+  prop = RNA_def_property(srna, "source_object", PROP_POINTER, PROP_NONE);
+  RNA_def_property_flag(prop, PROP_EDITABLE);
+  RNA_def_property_ui_text(prop, "Source Object", "Object to copy a particle type from");
+  RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+
+  prop = RNA_def_property(srna, "source_particle_type", PROP_STRING, PROP_NONE);
+  RNA_def_property_ui_text(
+      prop, "Particle Type", "Name of the particle type that should be copied");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_bparticles.c b/source/blender/modifiers/intern/MOD_bparticles.c
index a360f3e59b8..003cf4220d3 100644
--- a/source/blender/modifiers/intern/MOD_bparticles.c
+++ b/source/blender/modifiers/intern/MOD_bparticles.c
@@ -80,12 +80,12 @@ static void free_modifier_runtime_data(BParticlesModifierData *bpmd)
   }
 }
 
-static Mesh *applyModifier(ModifierData *md,
-                           const struct ModifierEvalContext *ctx,
-                           Mesh *UNUSED(mesh))
+static Mesh *apply_modifier__simulator(BParticlesModifierData *bpmd,
+                                       const struct ModifierEvalContext *ctx,
+                                       Mesh *UNUSED(mesh))
 {
-  BParticlesModifierData *bpmd = (BParticlesModifierData *)md;
-  BParticlesModifierData *bpmd_orig = (BParticlesModifierData *)modifier_get_original(md);
+  BParticlesModifierData *bpmd_orig = (BParticlesModifierData *)modifier_get_original(
+      &bpmd->modifier);
 
   Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
   float current_frame = BKE_scene_frame_get(scene);
@@ -117,9 +117,47 @@ static Mesh *applyModifier(ModifierData *md,
   if (bpmd->output_type == MOD_BPARTICLES_OUTPUT_POINTS) {
     return BParticles_modifier_point_mesh_from_state(runtime->simulation_state);
   }
-  else {
+  else if (bpmd->output_type == MOD_BPARTICLES_OUTPUT_TETRAHEDONS) {
     return BParticles_modifier_mesh_from_state(runtime->simulation_state);
   }
+  else {
+    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+  }
+}
+
+static Mesh *apply_modifier__passive(BParticlesModifierData *bpmd,
+                                     const struct ModifierEvalContext *UNUSED(ctx),
+                                     Mesh *UNUSED(mesh))
+{
+  if (bpmd->source_object == NULL) {
+    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+  }
+  BParticlesModifierData *source_bpmd = (BParticlesModifierData *)modifiers_findByType(
+      bpmd->source_object, eModifierType_BParticles);
+  if (source_bpmd == NULL) {
+    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+  }
+  RuntimeData *source_runtime_data = get_runtime_struct(source_bpmd);
+  if (source_runtime_data == NULL) {
+    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+  }
+  if (source_runtime_data->simulation_state == NULL) {
+    return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
+  }
+
+  return BParticles_modifier_extract_mesh(source_runtime_data->simulation_state,
+                                          bpmd->source_particle_type);
+}
+
+static Mesh *applyModifier(ModifierData *md, const struct ModifierEvalContext *ctx, Mesh *mesh)
+{
+  BParticlesModifierData *bpmd = (BParticlesModifierData *)md;
+  if (bpmd->mode == MOD_BPARTICLES_MODE_SIMULATOR) {
+    return apply_modifier__simulator(bpmd, ctx, mesh);
+  }
+  else {
+    return apply_modifier__passive(bpmd, ctx, mesh);
+  }
 }
 
 static void initData(ModifierData *UNUSED(md))
@@ -156,16 +194,19 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
   return true;
 }
 
-static void updateDepsgraph(ModifierData *UNUSED(md),
-                            const ModifierUpdateDepsgraphContext *UNUSED(ctx))
+static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
 {
+  BParticlesModifierData *bpmd = (BParticlesModifierData *)md;
+  if (bpmd->source_object) {
+    DEG_add_object_relation(
+        ctx->node, bpmd->source_object, DEG_OB_COMP_GEOMETRY, "Passive BParticles Modifier");
+  }
 }
 
-static void foreachObjectLink(ModifierData *UNUSED(md),
-                              Object *UNUSED(ob),
-                              ObjectWalkFunc UNUSED(walk),
-                              void *UNUSED(userData))
+static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
 {
+  BParticlesModifierData *bpmd = (BParticlesModifierData *)md;
+  walk(userData, ob, &bpmd->source_object, IDWALK_CB_NOP);
 }
 
 static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 159caa410e1..a5047dca712 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -25,6 +25,8 @@ void BParticles_simulate_modifier(struct BParticlesModifierData *bpmd,
 
 Mesh *BParticles_modifier_point_mesh_from_state(BParticlesSimulationState simulation_state);
 Mesh *BParticles_modifier_mesh_from_state(BParticlesSimulationState simulation_state);
+Mesh *BParticles_modifier_extract_mesh(BParticlesSimulationState simulation_state,
+                                       const char *particle_type);
 
 void BParticles_modifier_free_cache(struct BParticlesModifierData *bpmd);
 struct Mesh *BParticles_m

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list