[Bf-blender-cvs] [1180996832f] functions: add ability to select output mesh type in modifier settings

Jacques Lucke noreply at git.blender.org
Sat Jul 20 14:21:28 CEST 2019


Commit: 1180996832fce0081cfad48d98067feb1930bf99
Author: Jacques Lucke
Date:   Sat Jul 20 14:06:51 2019 +0200
Branches: functions
https://developer.blender.org/rB1180996832fce0081cfad48d98067feb1930bf99

add ability to select output mesh type in modifier settings

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

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 9605f0d1394..17292bdebe5 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1670,6 +1670,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
         layout.operator("object.bparticles_clear_cache", text="Clear Cache")
 
+        layout.prop(md, "output_type")
+
 
 class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
     bl_label = "Modifiers"
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 05279fe7772..e5c7fbafe42 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1984,12 +1984,17 @@ typedef struct BParticlesFrameCache {
   BParticlesTypeCache *particle_types;
 } BParticlesFrameCache;
 
+typedef enum eBParticlesOutputType {
+  MOD_BPARTICLES_OUTPUT_POINTS,
+  MOD_BPARTICLES_OUTPUT_TETRAHEDONS,
+} eBParticlesOutputType;
+
 typedef struct BParticlesModifierData {
   ModifierData modifier;
   struct bNodeTree *bparticles_tree;
+  unsigned int output_type;
 
   unsigned int num_cached_frames;
-  char _pad[4];
   BParticlesFrameCache *cached_frames;
 } BParticlesModifierData;
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 09c5c13af11..3b85d84f35d 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5982,6 +5982,26 @@ static void rna_def_modifier_bparticles(BlenderRNA *brna)
   RNA_def_property_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop, "BParticles Tree", "BParticles node tree");
   RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+
+  const static EnumPropertyItem output_types[] = {
+      {MOD_BPARTICLES_OUTPUT_POINTS,
+       "POINTS",
+       0,
+       "Points",
+       "Create a mesh containing only vertices"},
+      {MOD_BPARTICLES_OUTPUT_TETRAHEDONS,
+       "TETRAHEDONS",
+       0,
+       "Tetrahedons",
+       "Create a mesh that has a tetrahedon at every vertex position"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  prop = RNA_def_property(srna, "output_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, output_types);
+  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");
 }
 
 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 46d916ea255..739558a6b2f 100644
--- a/source/blender/modifiers/intern/MOD_bparticles.c
+++ b/source/blender/modifiers/intern/MOD_bparticles.c
@@ -83,22 +83,6 @@ static void free_modifier_runtime_data(BParticlesModifierData *bpmd)
   }
 }
 
-static Mesh *point_mesh_from_particle_state(BParticlesState particles_state)
-{
-  uint point_amount = BParticles_state_particle_count(particles_state);
-  Mesh *mesh = BKE_mesh_new_nomain(point_amount, 0, 0, 0, 0);
-
-  float(*positions)[3] = MEM_malloc_arrayN(point_amount, sizeof(float[3]), __func__);
-  BParticles_state_get_positions(particles_state, positions);
-
-  for (uint i = 0; i < point_amount; i++) {
-    copy_v3_v3(mesh->mvert[i].co, positions[i]);
-  }
-
-  MEM_freeN(positions);
-  return mesh;
-}
-
 static Mesh *applyModifier(ModifierData *md,
                            const struct ModifierEvalContext *ctx,
                            Mesh *UNUSED(mesh))
@@ -137,7 +121,12 @@ static Mesh *applyModifier(ModifierData *md,
     runtime->last_simulated_frame = current_frame;
   }
 
-  return BParticles_modifier_mesh_from_state(runtime->particles_state);
+  if (bpmd->output_type == MOD_BPARTICLES_OUTPUT_POINTS) {
+    return BParticles_modifier_point_mesh_from_state(runtime->particles_state);
+  }
+  else {
+    return BParticles_modifier_mesh_from_state(runtime->particles_state);
+  }
 }
 
 static void initData(ModifierData *UNUSED(md))
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 0ed70da4d65..ef844f73471 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -31,6 +31,7 @@ void BParticles_simulate_modifier(struct BParticlesModifierData *bpmd,
 uint BParticles_state_particle_count(BParticlesState particles_state);
 void BParticles_state_get_positions(BParticlesState particles_state, float (*dst)[3]);
 
+Mesh *BParticles_modifier_point_mesh_from_state(BParticlesState state);
 Mesh *BParticles_modifier_mesh_from_state(BParticlesState particles_state);
 void BParticles_modifier_free_cache(struct BParticlesModifierData *bpmd);
 struct Mesh *BParticles_modifier_mesh_from_cache(struct BParticlesFrameCache *cached_frame);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 4dcb603e654..c4a0e09db84 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -226,6 +226,26 @@ void BParticles_modifier_free_cache(BParticlesModifierData *bpmd)
   bpmd->num_cached_frames = 0;
 }
 
+Mesh *BParticles_modifier_point_mesh_from_state(BParticlesState state_c)
+{
+  SCOPED_TIMER(__func__);
+
+  ParticlesState &state = *unwrap(state_c);
+
+  SmallVector<float3> positions;
+  for (ParticlesContainer *container : state.particle_containers().values()) {
+    positions.extend(container->flatten_attribute_float3("Position"));
+  }
+
+  Mesh *mesh = BKE_mesh_new_nomain(positions.size(), 0, 0, 0, 0);
+
+  for (uint i = 0; i < mesh->totvert; i++) {
+    copy_v3_v3(mesh->mvert[i].co, positions[i]);
+  }
+
+  return mesh;
+}
+
 Mesh *BParticles_modifier_mesh_from_state(BParticlesState state_c)
 {
   SCOPED_TIMER(__func__);



More information about the Bf-blender-cvs mailing list