[Bf-blender-cvs] [2bcf091ba9b] functions: control simulation with some properties

Jacques Lucke noreply at git.blender.org
Fri Jun 7 17:18:47 CEST 2019


Commit: 2bcf091ba9bca6eae7eb7218691a275ec76225e2
Author: Jacques Lucke
Date:   Fri Jun 7 15:13:11 2019 +0200
Branches: functions
https://developer.blender.org/rB2bcf091ba9bca6eae7eb7218691a275ec76225e2

control simulation with some properties

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

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_nodeparticles.c
M	source/blender/simulations/BParticles.h
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/playground_solver.cpp
M	source/blender/simulations/bparticles/playground_solver.hpp

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 2d64e41826a..b25ab0290d5 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1664,7 +1664,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         props.modifier_name = md.name
 
     def NODE_PARTICLES(self, layout, ob, md):
-        layout.label(text="Hello World")
+        layout.prop(md, "control1")
+        layout.prop(md, "control2")
 
 
 class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index bd6faebaf59..41c6dece51e 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1966,6 +1966,7 @@ typedef struct FunctionPointsModifierData {
 
 typedef struct NodeParticlesModifierData {
   ModifierData modifier;
+  float control1, control2;
 } NodeParticlesModifierData;
 
 #endif /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 7af6b83898d..b930ee915e1 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5976,11 +5976,18 @@ static void rna_def_modifier_function_points(BlenderRNA *brna)
 static void rna_def_modifier_node_particles(BlenderRNA *brna)
 {
   StructRNA *srna;
+  PropertyRNA *prop;
 
   srna = RNA_def_struct(brna, "NodeParticlesModifier", "Modifier");
   RNA_def_struct_ui_text(srna, "Node Particles Modifier", "");
   RNA_def_struct_sdna(srna, "NodeParticlesModifierData");
   RNA_def_struct_ui_icon(srna, ICON_NONE);
+
+  prop = RNA_def_float(srna, "control1", 0.0, -FLT_MAX, FLT_MAX, "Control 1", "", -10, 10);
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+  prop = RNA_def_float(srna, "control2", 0.0, -FLT_MAX, FLT_MAX, "Control 2", "", -10, 10);
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index ccab31bb496..058a9a77a7a 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -68,7 +68,7 @@ static void ensure_runtime_data(NodeParticlesModifierData *npmd)
   }
 
   RuntimeData *runtime = MEM_callocN(sizeof(RuntimeData), __func__);
-  runtime->description = BParticles_playground_description();
+  runtime->description = BParticles_playground_description(npmd->control1, npmd->control2);
   runtime->solver = BParticles_solver_build(runtime->description);
   runtime->state = BParticles_state_init(runtime->solver);
   runtime->last_simulated_frame = 0.0f;
@@ -104,7 +104,8 @@ static Mesh *applyModifier(ModifierData *md,
   float current_frame = BKE_scene_frame_get(scene);
 
   if (current_frame != runtime->last_simulated_frame) {
-    BParticlesDescription new_description = BParticles_playground_description();
+    BParticlesDescription new_description = BParticles_playground_description(npmd->control1,
+                                                                              npmd->control2);
     BParticlesSolver new_solver = BParticles_solver_build(new_description);
 
     if (current_frame == runtime->last_simulated_frame + 1) {
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 43a75da55f3..07bced86d11 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -12,7 +12,7 @@ typedef struct OpaqueBParticlesDescription *BParticlesDescription;
 typedef struct OpaqueBParticlesSolver *BParticlesSolver;
 typedef struct OpaqueBParticlesState *BParticlesState;
 
-BParticlesDescription BParticles_playground_description(void);
+BParticlesDescription BParticles_playground_description(float control1, float control2);
 void BParticles_description_free(BParticlesDescription description);
 
 BParticlesSolver BParticles_solver_build(BParticlesDescription description);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 496f6e3f4d3..0a567e200b5 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -21,18 +21,21 @@ WRAPPERS(BParticles::Description *, BParticlesDescription);
 WRAPPERS(BParticles::Solver *, BParticlesSolver);
 WRAPPERS(BParticles::WrappedState *, BParticlesState);
 
-BParticlesDescription BParticles_playground_description()
+BParticlesDescription BParticles_playground_description(float control1, float UNUSED(control2))
 {
-  return wrap(new Description());
+  Description *description = new Description();
+  description->m_gravity = control1;
+  return wrap(description);
 }
 void BParticles_description_free(BParticlesDescription description_c)
 {
   delete unwrap(description_c);
 }
 
-BParticlesSolver BParticles_solver_build(BParticlesDescription UNUSED(description_c))
+BParticlesSolver BParticles_solver_build(BParticlesDescription description_c)
 {
-  return wrap(BParticles::new_playground_solver());
+  Description *description = unwrap(description_c);
+  return wrap(BParticles::new_playground_solver(description));
 }
 void BParticles_solver_free(BParticlesSolver solver_c)
 {
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 9da6b52bd87..87f9fe854ee 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -13,6 +13,8 @@ class StateBase;
 class Description {
  public:
   virtual ~Description();
+
+  float m_gravity = 0.0f;
 };
 
 class Solver {
diff --git a/source/blender/simulations/bparticles/playground_solver.cpp b/source/blender/simulations/bparticles/playground_solver.cpp
index 80ff7c506d7..d9432d22113 100644
--- a/source/blender/simulations/bparticles/playground_solver.cpp
+++ b/source/blender/simulations/bparticles/playground_solver.cpp
@@ -17,8 +17,10 @@ class SimpleSolver : public Solver {
     SmallVector<Vector> velocities;
   };
 
+  Description *m_description;
+
  public:
-  SimpleSolver()
+  SimpleSolver(Description *description) : m_description(description)
   {
   }
 
@@ -40,7 +42,7 @@ class SimpleSolver : public Solver {
     }
 
     for (Vector &velocity : state.velocities) {
-      velocity.z -= 0.001f;
+      velocity.z -= m_description->m_gravity / 100.0f;
     }
 
     state.positions.append({(float)(rand() % 100) / 100.0f, 0, 1});
@@ -60,9 +62,9 @@ class SimpleSolver : public Solver {
   }
 };
 
-Solver *new_playground_solver()
+Solver *new_playground_solver(Description *description)
 {
-  return new SimpleSolver();
+  return new SimpleSolver(description);
 }
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/playground_solver.hpp b/source/blender/simulations/bparticles/playground_solver.hpp
index 21575ba3136..c0495054cba 100644
--- a/source/blender/simulations/bparticles/playground_solver.hpp
+++ b/source/blender/simulations/bparticles/playground_solver.hpp
@@ -3,5 +3,5 @@
 #include "core.hpp"
 
 namespace BParticles {
-Solver *new_playground_solver();
+Solver *new_playground_solver(Description *description);
 }



More information about the Bf-blender-cvs mailing list