BKE_effect.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  19. * All rights reserved.
  20. *
  21. * The Original Code is: all of this file.
  22. *
  23. * Contributor(s): none yet.
  24. *
  25. * ***** END GPL LICENSE BLOCK *****
  26. */
  27. #ifndef __BKE_EFFECT_H__
  28. #define __BKE_EFFECT_H__
  29. /** \file BKE_effect.h
  30. * \ingroup bke
  31. * \since March 2001
  32. * \author nzc
  33. */
  34. #include "DNA_modifier_types.h"
  35. #include "BLI_utildefines.h"
  36. struct Object;
  37. struct Scene;
  38. struct ListBase;
  39. struct Group;
  40. struct ParticleSimulationData;
  41. struct ParticleData;
  42. struct ParticleKey;
  43. struct EffectorWeights *BKE_add_effector_weights(struct Group *group);
  44. struct PartDeflect *object_add_collision_fields(int type);
  45. /* Input to effector code */
  46. typedef struct EffectedPoint {
  47. float *loc;
  48. float *vel;
  49. float *ave; /* angular velocity for particles with dynamic rotation */
  50. float *rot; /* rotation quaternion for particles with dynamic rotation */
  51. float vel_to_frame;
  52. float vel_to_sec;
  53. /* only for particles */
  54. float size, charge;
  55. unsigned int flag;
  56. int index;
  57. struct ParticleSystem *psys; /* particle system the point belongs to */
  58. } EffectedPoint;
  59. typedef struct GuideEffectorData {
  60. float vec_to_point[3];
  61. float strength;
  62. } GuideEffectorData;
  63. typedef struct EffectorData {
  64. /* Effector point */
  65. float loc[3];
  66. float nor[3];
  67. float vel[3];
  68. float vec_to_point[3];
  69. float distance, falloff;
  70. /* only for effector particles */
  71. float size, charge;
  72. /* only for vortex effector with surface falloff */
  73. float nor2[3], vec_to_point2[3];
  74. int *index; /* point index */
  75. } EffectorData;
  76. /* used for calculating the effector force */
  77. typedef struct EffectorCache {
  78. struct EffectorCache *next, *prev;
  79. struct Scene *scene;
  80. struct Object *ob;
  81. struct ParticleSystem *psys;
  82. struct SurfaceModifierData *surmd;
  83. struct PartDeflect *pd;
  84. /* precalculated for guides */
  85. struct GuideEffectorData *guide_data;
  86. float guide_loc[4], guide_dir[3], guide_radius;
  87. float velocity[3];
  88. float frame;
  89. int flag;
  90. } EffectorCache;
  91. void free_partdeflect(struct PartDeflect *pd);
  92. struct ListBase *pdInitEffectors(struct Scene *scene, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool for_simulation);
  93. void pdEndEffectors(struct ListBase **effectors);
  94. void pdPrecalculateEffectors(struct ListBase *effectors);
  95. void pdDoEffectors(struct ListBase *effectors, struct ListBase *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *impulse);
  96. void pd_point_from_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, struct EffectedPoint *point);
  97. void pd_point_from_loc(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point);
  98. void pd_point_from_soft(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point);
  99. /* needed for boids */
  100. float effector_falloff(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, struct EffectorWeights *weights);
  101. int closest_point_on_surface(SurfaceModifierData *surmd, const float co[3], float surface_co[3], float surface_nor[3], float surface_vel[3]);
  102. int get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, int real_velocity);
  103. /* required for particle_system.c */
  104. //void do_physical_effector(struct EffectorData *eff, struct EffectorPoint *point, float *total_force);
  105. //float effector_falloff(struct EffectorData *eff, struct EffectorPoint *point, struct EffectorWeights *weights);
  106. /* EffectedPoint->flag */
  107. #define PE_WIND_AS_SPEED 1
  108. #define PE_DYNAMIC_ROTATION 2
  109. #define PE_USE_NORMAL_DATA 4
  110. /* EffectorData->flag */
  111. #define PE_VELOCITY_TO_IMPULSE 1
  112. /* ======== Simulation Debugging ======== */
  113. #define SIM_DEBUG_HASH_BASE 5381
  114. unsigned int BKE_sim_debug_data_hash(int i);
  115. unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky);
  116. /* _VA_SIM_DEBUG_HASH#(i, ...): combined hash value of multiple integers */
  117. /* internal helpers*/
  118. #define _VA_SIM_DEBUG_HASH1(a) \
  119. (BKE_sim_debug_data_hash(a))
  120. #define _VA_SIM_DEBUG_HASH2(a, b) \
  121. (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH1(b)))
  122. #define _VA_SIM_DEBUG_HASH3(a, b, c) \
  123. (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH2(b, c)))
  124. #define _VA_SIM_DEBUG_HASH4(a, b, c, d) \
  125. (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH3(b, c, d)))
  126. #define _VA_SIM_DEBUG_HASH5(a, b, c, d, e) \
  127. (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH4(b, c, d, e)))
  128. #define _VA_SIM_DEBUG_HASH6(a, b, c, d, e, f) \
  129. (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH5(b, c, d, e, f)))
  130. #define _VA_SIM_DEBUG_HASH7(a, b, c, d, e, f, g) \
  131. (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH6(b, c, d, e, f, g)))
  132. #define _VA_SIM_DEBUG_HASH8(a, b, c, d, e, f, g, h) \
  133. (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH7(b, c, d, e, f, g, h)))
  134. #define SIM_DEBUG_HASH(...) VA_NARGS_CALL_OVERLOAD(_VA_SIM_DEBUG_HASH, __VA_ARGS__)
  135. typedef struct SimDebugElement {
  136. unsigned int category_hash;
  137. unsigned int hash;
  138. int type;
  139. float color[3];
  140. float v1[3], v2[3];
  141. char str[64];
  142. } SimDebugElement;
  143. typedef enum eSimDebugElement_Type {
  144. SIM_DEBUG_ELEM_DOT,
  145. SIM_DEBUG_ELEM_CIRCLE,
  146. SIM_DEBUG_ELEM_LINE,
  147. SIM_DEBUG_ELEM_VECTOR,
  148. SIM_DEBUG_ELEM_STRING,
  149. } eSimDebugElement_Type;
  150. typedef struct SimDebugData {
  151. struct GHash *gh;
  152. } SimDebugData;
  153. extern SimDebugData *_sim_debug_data;
  154. void BKE_sim_debug_data_set_enabled(bool enable);
  155. bool BKE_sim_debug_data_get_enabled(void);
  156. void BKE_sim_debug_data_free(void);
  157. void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str,
  158. float r, float g, float b, const char *category, unsigned int hash);
  159. void BKE_sim_debug_data_remove_element(unsigned int hash);
  160. #define BKE_sim_debug_data_add_dot(p, r, g, b, category, ...) { \
  161. const float v2[3] = { 0.0f, 0.0f, 0.0f }; \
  162. BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_DOT, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
  163. }
  164. #define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category, ...) { \
  165. const float v2[3] = { radius, 0.0f, 0.0f }; \
  166. BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_CIRCLE, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
  167. }
  168. #define BKE_sim_debug_data_add_line(p1, p2, r, g, b, category, ...) { \
  169. BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_LINE, p1, p2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
  170. }
  171. #define BKE_sim_debug_data_add_vector(p, d, r, g, b, category, ...) { \
  172. BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_VECTOR, p, d, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
  173. }
  174. #define BKE_sim_debug_data_add_string(p, str, r, g, b, category, ...) { \
  175. BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_STRING, p, NULL, str, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
  176. }
  177. #define BKE_sim_debug_data_remove(...) \
  178. BKE_sim_debug_data_remove_element(SIM_DEBUG_HASH(__VA_ARGS__))
  179. void BKE_sim_debug_data_clear(void);
  180. void BKE_sim_debug_data_clear_category(const char *category);
  181. #endif