[Bf-blender-cvs] [56a0a716492] functions: new simulations folder with some test code

Jacques Lucke noreply at git.blender.org
Thu Jun 6 11:21:41 CEST 2019


Commit: 56a0a7164926522cfd363b25ad4883ed24107d2e
Author: Jacques Lucke
Date:   Thu Jun 6 10:42:01 2019 +0200
Branches: functions
https://developer.blender.org/rB56a0a7164926522cfd363b25ad4883ed24107d2e

new simulations folder with some test code

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

M	source/blender/CMakeLists.txt
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/intern/MOD_nodeparticles.c
A	source/blender/simulations/CMakeLists.txt
A	source/blender/simulations/SIM_particles.h
A	source/blender/simulations/playground.cpp

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

diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index d0e951a8219..85de9f53f17 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -112,6 +112,7 @@ add_subdirectory(modifiers)
 add_subdirectory(gpencil_modifiers)
 add_subdirectory(shader_fx)
 add_subdirectory(functions)
+add_subdirectory(simulations)
 add_subdirectory(makesdna)
 add_subdirectory(makesrna)
 
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 9b0411b5aa8..e6d4664865c 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -27,6 +27,7 @@ set(INC
   ../bmesh
   ../depsgraph
   ../functions
+  ../simulations
   ../makesdna
   ../makesrna
   ../render/extern/include
@@ -116,6 +117,7 @@ set(LIB
   bf_blenkernel
   bf_blenlib
   bf_functions
+  bf_simulations
 )
 
 if(WITH_ALEMBIC)
diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index 6cc94f4be77..cd4992dfcaf 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -26,6 +26,8 @@
  *
  */
 
+#include "MEM_guardedalloc.h"
+
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
@@ -38,13 +40,25 @@
 
 #include "MOD_util.h"
 
+#include "SIM_particles.h"
+
 static Mesh *applyModifier(ModifierData *UNUSED(md),
                            const struct ModifierEvalContext *UNUSED(ctx),
                            Mesh *UNUSED(mesh))
 {
-  Mesh *mesh = BKE_mesh_new_nomain(1, 0, 0, 0, 0);
-  float point[] = {1, 2, 3};
-  copy_v3_v3(mesh->mvert[0].co, point);
+  ParticleSystemRef particle_system = NULL;
+  uint point_amount = SIM_particles_count(particle_system);
+  Mesh *mesh = BKE_mesh_new_nomain(point_amount, 0, 0, 0, 0);
+
+  float(*positions)[3] = MEM_malloc_arrayN(point_amount, sizeof(float[3]), __func__);
+  SIM_particles_get_positions(particle_system, positions);
+
+  for (uint i = 0; i < point_amount; i++) {
+    copy_v3_v3(mesh->mvert[i].co, positions[i]);
+  }
+
+  MEM_freeN(positions);
+
   return mesh;
 }
 
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
new file mode 100644
index 00000000000..78fbfcf9cd3
--- /dev/null
+++ b/source/blender/simulations/CMakeLists.txt
@@ -0,0 +1,23 @@
+set(INC
+  .
+  ../blenlib
+  ../makesdna
+  ../makesrna
+  ../blenkernel
+  ../depsgraph
+  ../../../intern/guardedalloc
+)
+
+set(INC_SYS
+)
+
+
+set(SRC
+   playground.cpp
+)
+
+set(LIB
+  bf_blenlib
+)
+
+blender_add_lib(bf_simulations "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/simulations/SIM_particles.h b/source/blender/simulations/SIM_particles.h
new file mode 100644
index 00000000000..82bb035b901
--- /dev/null
+++ b/source/blender/simulations/SIM_particles.h
@@ -0,0 +1,20 @@
+
+#ifndef __SIM_PARTICLES_C_H__
+#define __SIM_PARTICLES_C_H__
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct OpaqueParticleSystem *ParticleSystemRef;
+
+uint SIM_particles_count(ParticleSystemRef particle_system);
+void SIM_particles_get_positions(ParticleSystemRef particle_system, float (*dst)[3]);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SIM_PARTICLES_C_H__ */
diff --git a/source/blender/simulations/playground.cpp b/source/blender/simulations/playground.cpp
new file mode 100644
index 00000000000..aa785ca5269
--- /dev/null
+++ b/source/blender/simulations/playground.cpp
@@ -0,0 +1,31 @@
+#include "BLI_math.h"
+
+#include "SIM_particles.h"
+
+#define WRAPPERS(T1, T2) \
+  inline T1 unwrap(T2 value) \
+  { \
+    return (T1)value; \
+  } \
+  inline T2 wrap(T1 value) \
+  { \
+    return (T2)value; \
+  }
+
+WRAPPERS(void *, ParticleSystemRef);
+
+uint SIM_particles_count(ParticleSystemRef UNUSED(particle_system))
+{
+  return 5;
+}
+
+void SIM_particles_get_positions(ParticleSystemRef UNUSED(particle_system), float (*dst)[3])
+{
+  for (uint i = 0; i < 5; i++) {
+    float vec[3];
+    vec[0] = i;
+    vec[1] = i * 0.3f;
+    vec[2] = 1.0f;
+    copy_v3_v3(dst[i], vec);
+  }
+}



More information about the Bf-blender-cvs mailing list