Blender V5.3
effect.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cmath>
11#include <cstdarg>
12#include <cstddef>
13#include <cstdlib>
14
15#include "MEM_guardedalloc.h"
16
17#include "DNA_curve_types.h"
18#include "DNA_layer_types.h"
19#include "DNA_listBase.h"
20#include "DNA_mesh_types.h"
22#include "DNA_object_types.h"
23#include "DNA_particle_types.h"
24#include "DNA_scene_types.h"
25#include "DNA_texture_types.h"
26
27#include "BLI_ghash.hh"
28#include "BLI_listbase.hh"
29#include "BLI_math_base_safe.hh"
30#include "BLI_math_geom_c.hh"
31#include "BLI_math_matrix_c.hh"
33#include "BLI_math_vector_c.hh"
34#include "BLI_noise_c.hh"
35#include "BLI_rand_c.hh"
36#include "BLI_string.hh"
37#include "BLI_time.hh"
38#include "BLI_utildefines.hh"
39
40#include "BKE_anim_path.h" /* needed for where_on_path */
41#include "BKE_bvh.hh"
42#include "BKE_bvhutils.hh"
43#include "BKE_collection.hh"
44#include "BKE_collision.h"
45#include "BKE_curve.hh"
46#include "BKE_displist.h"
47#include "BKE_effect.h"
48#include "BKE_fluid.h"
49#include "BKE_global.hh"
50#include "BKE_modifier.hh"
51#include "BKE_object.hh"
52#include "BKE_object_types.hh"
53#include "BKE_particle.h"
54
55#include "DEG_depsgraph.hh"
58
59#include "RE_texture.h"
60
61namespace blender {
62
64{
65 EffectorWeights *weights = MEM_new<EffectorWeights>("EffectorWeights");
66 for (int i = 0; i < NUM_PFIELD_TYPES; i++) {
67 weights->weight[i] = 1.0f;
68 }
69
70 weights->global_gravity = 1.0f;
71
72 weights->group = collection;
73
74 return weights;
75}
77{
78 PartDeflect *pd;
79
80 pd = MEM_new<PartDeflect>("PartDeflect");
81
82 pd->forcefield = type;
83 pd->pdef_sbdamp = 0.1f;
84 pd->pdef_sbift = 0.2f;
85 pd->pdef_sboft = 0.02f;
86 pd->pdef_cfrict = 5.0f;
87 pd->seed = (uint(ceil(BLI_time_now_seconds())) + 1) % 128;
88 pd->f_strength = 1.0f;
89 pd->f_damp = 1.0f;
90
91 /* set sensible defaults based on type */
92 switch (type) {
93 case PFIELD_VORTEX:
95 break;
96 case PFIELD_WIND:
98 pd->f_flow = 1.0f; /* realistic wind behavior */
99 pd->f_wind_factor = 1.0f; /* only act perpendicularly to a surface */
100 break;
101 case PFIELD_TEXTURE:
102 pd->f_size = 1.0f;
103 break;
104 case PFIELD_FLUIDFLOW:
105 pd->f_flow = 1.0f;
106 break;
107 default:
108 break;
109 }
111
112 return pd;
113}
114
115/************************ PARTICLES ***************************/
116
118{
119 if (pd_src == nullptr) {
120 return nullptr;
121 }
122 PartDeflect *pd_dst = MEM_dupalloc(pd_src);
123 return pd_dst;
124}
125
127{
128 if (!pd) {
129 return;
130 }
131 MEM_delete(pd);
132}
133
134/******************** EFFECTOR RELATIONS ***********************/
135
136static void precalculate_effector(Depsgraph *depsgraph, EffectorCache *eff)
137{
138 float ctime = DEG_get_ctime(depsgraph);
139 uint cfra = uint(ctime >= 0 ? ctime : -ctime);
140
141 eff->rng = BLI_rng_new(eff->pd->seed + cfra);
142
143 if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type == OB_CURVES_LEGACY) {
144 Curve *cu = id_cast<Curve *>(eff->ob->data);
145 if (cu->flag & CU_PATH) {
146 if (eff->ob->runtime->curve_cache == nullptr ||
147 eff->ob->runtime->curve_cache->anim_path_accum_length == nullptr)
148 {
149 BKE_displist_make_curveTypes(depsgraph, eff->scene, eff->ob, false);
150 }
151
154 eff->ob, 0.0, eff->guide_loc, eff->guide_dir, nullptr, &eff->guide_radius, nullptr);
155 mul_m4_v3(eff->ob->object_to_world().ptr(), eff->guide_loc);
156 mul_mat3_m4_v3(eff->ob->object_to_world().ptr(), eff->guide_dir);
157 }
158 }
159 }
160 else if (eff->pd->shape == PFIELD_SHAPE_SURFACE) {
161 eff->surmd = reinterpret_cast<SurfaceModifierData *>(
163 if (eff->ob->type == OB_CURVES_LEGACY) {
164 eff->flag |= PE_USE_NORMAL_DATA;
165 }
166 }
167 else if (eff->psys) {
168 psys_update_particle_tree(eff->psys, ctime);
169 }
170}
171
172static void add_effector_relation(ListBaseT<EffectorRelation> *relations,
173 Object *ob,
174 ParticleSystem *psys,
175 PartDeflect *pd)
176{
177 EffectorRelation *relation = MEM_new_zeroed<EffectorRelation>("EffectorRelation");
178 relation->ob = ob;
179 relation->psys = psys;
180 relation->pd = pd;
181
182 BLI_addtail(relations, relation);
183}
184
185static void add_effector_evaluation(ListBaseT<EffectorCache> **effectors,
186 Depsgraph *depsgraph,
187 Scene *scene,
188 Object *ob,
189 ParticleSystem *psys,
190 PartDeflect *pd)
191{
192 if (*effectors == nullptr) {
193 *effectors = MEM_new_zeroed<ListBaseT<EffectorCache>>("effector effectors");
194 }
195
196 EffectorCache *eff = MEM_new_zeroed<EffectorCache>("EffectorCache");
197 eff->depsgraph = depsgraph;
198 eff->scene = scene;
199 eff->ob = ob;
200 eff->psys = psys;
201 eff->pd = pd;
202 eff->frame = -1;
203 BLI_addtail(*effectors, eff);
204
205 precalculate_effector(depsgraph, eff);
206}
207
208ListBaseT<EffectorRelation> *BKE_effector_relations_create(Depsgraph *depsgraph,
209 const Scene *scene,
210 ViewLayer *view_layer,
211 Collection *collection)
212{
214 *DEG_get_bmain(depsgraph), scene, view_layer, collection);
215 const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
216 const int base_flag = (for_render) ? BASE_ENABLED_RENDER : BASE_ENABLED_VIEWPORT;
217
218 ListBaseT<EffectorRelation> *relations = MEM_new_zeroed<ListBaseT<EffectorRelation>>(
219 "effector relations");
220
221 for (; base; base = base->next) {
222 if (!(base->flag & base_flag)) {
223 continue;
224 }
225
226 Object *ob = base->object;
227
228 if (ob->pd && ob->pd->forcefield) {
229 add_effector_relation(relations, ob, nullptr, ob->pd);
230 }
231
232 for (ParticleSystem &psys : ob->particlesystem) {
233 ParticleSettings *part = psys.part;
234
235 if (psys_check_enabled(ob, &psys, for_render)) {
236 if (part->pd && part->pd->forcefield) {
237 add_effector_relation(relations, ob, &psys, part->pd);
238 }
239 if (part->pd2 && part->pd2->forcefield) {
240 add_effector_relation(relations, ob, &psys, part->pd2);
241 }
242 }
243 }
244 }
245
246 return relations;
247}
248
249void BKE_effector_relations_free(ListBaseT<EffectorRelation> *lb)
250{
251 if (lb) {
252 lb->free_no_destruct();
253 MEM_delete(lb);
254 }
255}
256
257/* Check that the force field isn't disabled via its flags. */
258static bool is_effector_enabled(PartDeflect *pd, bool use_rotation)
259{
260 switch (pd->forcefield) {
261 case PFIELD_BOID:
262 case PFIELD_GUIDE:
263 return true;
264
265 case PFIELD_TEXTURE:
266 return (pd->flag & PFIELD_DO_LOCATION) != 0 && pd->tex != nullptr;
267
268 default:
269 if (use_rotation) {
270 return (pd->flag & (PFIELD_DO_LOCATION | PFIELD_DO_ROTATION)) != 0;
271 }
272 else {
273 return (pd->flag & PFIELD_DO_LOCATION) != 0;
274 }
275 }
276}
277
278/* Check that the force field won't have zero effect due to strength settings. */
280{
281 if (pd->f_strength != 0.0f) {
282 return true;
283 }
284
285 if (pd->forcefield == PFIELD_TEXTURE) {
286 return false;
287 }
288
289 if (pd->f_noise > 0.0f || pd->f_flow != 0.0f) {
290 return true;
291 }
292
293 switch (pd->forcefield) {
294 case PFIELD_BOID:
295 case PFIELD_GUIDE:
296 return true;
297
298 case PFIELD_VORTEX:
299 return pd->shape != PFIELD_SHAPE_POINT;
300
301 case PFIELD_DRAG:
302 return pd->f_damp != 0.0f;
303
304 default:
305 return false;
306 }
307}
308
309/* Check if the force field will affect its user. */
310static bool is_effector_relevant(PartDeflect *pd, EffectorWeights *weights, bool use_rotation)
311{
312 return (weights->weight[pd->forcefield] != 0.0f) && is_effector_enabled(pd, use_rotation) &&
314}
315
316ListBaseT<EffectorCache> *BKE_effectors_create(Depsgraph *depsgraph,
317 Object *ob_src,
318 ParticleSystem *psys_src,
319 EffectorWeights *weights,
320 bool use_rotation)
321{
322 Scene *scene = DEG_get_evaluated_scene(depsgraph);
323 ListBaseT<EffectorRelation> *relations = DEG_get_effector_relations(depsgraph, weights->group);
324 ListBaseT<EffectorCache> *effectors = nullptr;
325
326 if (!relations) {
327 return nullptr;
328 }
329
330 for (EffectorRelation &relation : *relations) {
331 /* Get evaluated object. */
332 Object *ob = DEG_get_evaluated(depsgraph, relation.ob);
333
334 if (relation.psys) {
335 /* Get evaluated particle system. */
336 ParticleSystem *psys = static_cast<ParticleSystem *>(BLI_findstring(
337 &ob->particlesystem, relation.psys->name, offsetof(ParticleSystem, name)));
338 ParticleSettings *part = psys->part;
339
340 if (psys == psys_src && (part->flag & PART_SELF_EFFECT) == 0) {
341 continue;
342 }
343
344 PartDeflect *pd = (relation.pd == relation.psys->part->pd) ? part->pd : part->pd2;
345
346 if (!is_effector_relevant(pd, weights, use_rotation)) {
347 continue;
348 }
349
350 add_effector_evaluation(&effectors, depsgraph, scene, ob, psys, pd);
351 }
352 else {
353 /* Object effector. */
354 if (ob == ob_src) {
355 continue;
356 }
357 if (!is_effector_relevant(ob->pd, weights, use_rotation)) {
358 continue;
359 }
360 if (ob->pd->shape == PFIELD_SHAPE_POINTS && BKE_object_get_evaluated_mesh(ob) == nullptr) {
361 continue;
362 }
363
364 add_effector_evaluation(&effectors, depsgraph, scene, ob, nullptr, ob->pd);
365 }
366 }
367
368 return effectors;
369}
370
371void BKE_effectors_free(ListBaseT<EffectorCache> *lb)
372{
373 if (lb) {
374 for (EffectorCache &eff : *lb) {
375 if (eff.rng) {
376 BLI_rng_free(eff.rng);
377 }
378 if (eff.guide_data) {
379 MEM_delete(eff.guide_data);
380 }
381 }
382
383 lb->free_no_destruct();
384 MEM_delete(lb);
385 }
386}
387
389 ParticleData *pa,
391 EffectedPoint *point)
392{
393 ParticleSettings *part = sim->psys->part;
394 point->loc = state->co;
395 point->vel = state->vel;
396 point->index = pa - sim->psys->particles;
397 point->size = pa->size;
398 point->charge = 0.0f;
399
400 if (part->pd && part->pd->forcefield == PFIELD_CHARGE) {
401 point->charge += part->pd->f_strength;
402 }
403
404 if (part->pd2 && part->pd2->forcefield == PFIELD_CHARGE) {
405 point->charge += part->pd2->f_strength;
406 }
407
408 point->vel_to_sec = 1.0f;
409 point->vel_to_frame = psys_get_timestep(sim);
410
411 point->flag = 0;
412
413 if (sim->psys->part->flag & PART_ROT_DYN) {
414 point->ave = state->ave;
415 point->rot = state->rot;
416 }
417 else {
418 point->ave = point->rot = nullptr;
419 }
420
421 point->psys = sim->psys;
422}
423
424void pd_point_from_loc(Scene *scene, float *loc, float *vel, int index, EffectedPoint *point)
425{
426 point->loc = loc;
427 point->vel = vel;
428 point->index = index;
429 point->size = 0.0f;
430
431 point->vel_to_sec = float(scene->r.frs_sec);
432 point->vel_to_frame = 1.0f;
433
434 point->flag = 0;
435
436 point->ave = point->rot = nullptr;
437 point->psys = nullptr;
438}
439void pd_point_from_soft(Scene *scene, float *loc, float *vel, int index, EffectedPoint *point)
440{
441 point->loc = loc;
442 point->vel = vel;
443 point->index = index;
444 point->size = 0.0f;
445
446 point->vel_to_sec = float(scene->r.frs_sec);
447 point->vel_to_frame = 1.0f;
448
449 point->flag = PE_WIND_AS_SPEED;
450
451 point->ave = point->rot = nullptr;
452
453 point->psys = nullptr;
454}
455/************************************************/
456/* Effectors */
457/************************************************/
458
459// triangle - ray callback function
460static void eff_tri_ray_hit(void * /*user_data*/,
461 int /*index*/,
462 const BVHTreeRay * /*ray*/,
463 BVHTreeRayHit *hit)
464{
465 /* whenever we hit a bounding box, we don't check further */
466 hit->dist = -1;
467 hit->index = 1;
468}
469
473static float eff_calc_visibility(ListBaseT<ColliderCache> *colliders,
474 EffectorCache *eff,
475 EffectorData *efd,
476 EffectedPoint *point)
477{
478 const int raycast_flag = BVH_RAYCAST_DEFAULT & ~BVH_RAYCAST_WATERTIGHT;
479 ListBaseT<ColliderCache> *colls = colliders;
480 float norm[3], len = 0.0;
481 float visibility = 1.0, absorption = 0.0;
482
483 if (!(eff->pd->flag & PFIELD_VISIBILITY)) {
484 return visibility;
485 }
486 if (!colls) {
487 colls = BKE_collider_cache_create(eff->depsgraph, eff->ob, nullptr);
488 }
489 if (!colls) {
490 return visibility;
491 }
492
495
496 /* check all collision objects */
497 for (ColliderCache &col : *colls) {
498 CollisionModifierData *collmd = col.collmd;
499
500 if (col.ob == eff->ob) {
501 continue;
502 }
503 if (collmd->bvhtree) {
504 BVHTreeRayHit hit;
505
506 hit.index = -1;
507 hit.dist = len + FLT_EPSILON;
508
509 /* check if the way is blocked */
511 point->loc,
512 norm,
513 0.0f,
514 &hit,
516 nullptr,
517 raycast_flag) != -1)
518 {
519 absorption = col.ob->pd->absorption;
520
521 /* visibility is only between 0 and 1, calculated from 1-absorption */
522 visibility *= std::clamp(1.0f - absorption, 0.0f, 1.0f);
523
524 if (visibility <= 0.0f) {
525 break;
526 }
527 }
528 }
529 }
530
531 if (!colliders) {
533 }
534
535 return visibility;
536}
537
538/* Noise function for wind e.g. */
539static float wind_func(RNG *rng, float strength)
540{
541 int random = (BLI_rng_get_int(rng) + 1) % 128; /* max 2357 */
542 float force = BLI_rng_get_float(rng) + 1.0f;
543 float ret;
544 float sign = 0;
545
546 /* Dividing by 2 is not giving equal sign distribution. */
547 sign = (float(random) > 64.0f) ? 1.0f : -1.0f;
548
549 ret = sign * (float(random) / force) * strength / 128.0f;
550
551 return ret;
552}
553
554/* maxdist: zero effect from this distance outwards (if usemax) */
555/* mindist: full effect up to this distance (if usemin) */
556/* power: falloff with formula 1/r^power */
557static float falloff_func(
558 float fac, int usemin, float mindist, int usemax, float maxdist, float power)
559{
560 /* first quick checks */
561 if (usemax && fac > maxdist) {
562 return 0.0f;
563 }
564
565 if (usemin && fac < mindist) {
566 return 1.0f;
567 }
568
569 if (!usemin) {
570 mindist = 0.0;
571 }
572
573 return pow(double(1.0f + fac - mindist), double(-power));
574}
575
576static float falloff_func_dist(PartDeflect *pd, float fac)
577{
578 return falloff_func(fac,
579 pd->flag & PFIELD_USEMIN,
580 pd->mindist,
581 pd->flag & PFIELD_USEMAX,
582 pd->maxdist,
583 pd->f_power);
584}
585
586static float falloff_func_rad(PartDeflect *pd, float fac)
587{
588 return falloff_func(fac,
589 pd->flag & PFIELD_USEMINR,
590 pd->minrad,
591 pd->flag & PFIELD_USEMAXR,
592 pd->maxrad,
593 pd->f_power_r);
594}
595
597 EffectorData *efd,
598 EffectedPoint * /*point*/,
599 EffectorWeights *weights)
600{
601 float temp[3];
602 float falloff = weights ? weights->weight[0] * weights->weight[eff->pd->forcefield] : 1.0f;
603 float fac, r_fac;
604
605 fac = dot_v3v3(efd->nor, efd->vec_to_point2);
606
607 if (eff->pd->zdir == PFIELD_Z_POS && fac < 0.0f) {
608 falloff = 0.0f;
609 }
610 else if (eff->pd->zdir == PFIELD_Z_NEG && fac > 0.0f) {
611 falloff = 0.0f;
612 }
613 else {
614 switch (eff->pd->falloff) {
616 falloff *= falloff_func_dist(eff->pd, efd->distance);
617 break;
618
619 case PFIELD_FALL_TUBE:
620 falloff *= falloff_func_dist(eff->pd, fabsf(fac));
621 if (falloff == 0.0f) {
622 break;
623 }
624
625 madd_v3_v3v3fl(temp, efd->vec_to_point2, efd->nor, -fac);
626 r_fac = len_v3(temp);
627 falloff *= falloff_func_rad(eff->pd, r_fac);
628 break;
629 case PFIELD_FALL_CONE:
630 falloff *= falloff_func_dist(eff->pd, fabsf(fac));
631 if (falloff == 0.0f) {
632 break;
633 }
634
635 r_fac = RAD2DEGF(safe_acosf(fac / len_v3(efd->vec_to_point2)));
636 falloff *= falloff_func_rad(eff->pd, r_fac);
637
638 break;
639 }
640 }
641
642 return falloff;
643}
644
646 const float co[3],
647 float surface_co[3],
648 float surface_nor[3],
649 float surface_vel[3])
650{
651 if (surmd == nullptr || surmd->runtime.bvhtree == nullptr) {
652 return false;
653 }
654 const std::optional<bke::bvh::ClosestPointResult> nearest =
655 surmd->runtime.bvhtree->closest_point(float3(co));
656 if (!nearest) {
657 return false;
658 }
659
660 copy_v3_v3(surface_co, nearest->position);
661
662 const Mesh &mesh = *surmd->runtime.mesh;
663 const Span<float3> positions = mesh.vert_positions();
664 const float (*velocities)[3] = surmd->runtime.vert_velocities;
665
666 if (mesh.faces_num > 0) {
667 const int3 &tri = mesh.corner_tris()[nearest->index];
668 const Span<int> corner_verts = mesh.corner_verts();
669 const int verts[3] = {corner_verts[tri[0]], corner_verts[tri[1]], corner_verts[tri[2]]};
670
671 if (surface_nor) {
672 normal_tri_v3(surface_nor, positions[verts[0]], positions[verts[1]], positions[verts[2]]);
673 }
674 if (surface_vel) {
675 copy_v3_v3(surface_vel, velocities[verts[0]]);
676 add_v3_v3(surface_vel, velocities[verts[1]]);
677 add_v3_v3(surface_vel, velocities[verts[2]]);
678 mul_v3_fl(surface_vel, (1.0f / 3.0f));
679 }
680 }
681 else {
682 /* The tree contains the mesh edges. Match old behavior which returned the edge direction. */
683 const int2 edge = mesh.edges()[nearest->index];
684
685 if (surface_nor) {
686 sub_v3_v3v3(surface_nor, positions[edge[0]], positions[edge[1]]);
687 normalize_v3(surface_nor);
688 }
689 if (surface_vel) {
690 copy_v3_v3(surface_vel, velocities[edge[0]]);
691 add_v3_v3(surface_vel, velocities[edge[1]]);
692 mul_v3_fl(surface_vel, 0.5f);
693 }
694 }
695 return true;
696}
698 EffectorData *efd,
699 EffectedPoint *point,
700 int real_velocity)
701{
702 float cfra = DEG_get_ctime(eff->depsgraph);
703 bool ret = false;
704
705 /* In case surface object is in Edit mode when loading the .blend,
706 * surface modifier is never executed and bvhtree never built, see #48415. */
707 if (eff->pd && eff->pd->shape == PFIELD_SHAPE_SURFACE && eff->surmd &&
708 eff->surmd->runtime.bvhtree)
709 {
710 /* closest point in the object surface is an effector */
711 float vec[3];
712
713 /* using velocity corrected location allows for easier sliding over effector surface */
714 copy_v3_v3(vec, point->vel);
715 mul_v3_fl(vec, point->vel_to_frame);
716 add_v3_v3(vec, point->loc);
717
719 eff->surmd, vec, efd->loc, efd->nor, real_velocity ? efd->vel : nullptr);
720
721 efd->size = 0.0f;
722 }
723 else if (eff->pd && eff->pd->shape == PFIELD_SHAPE_POINTS) {
724 /* TODO: hair and points object support */
725 const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(eff->ob);
726 if (mesh_eval != nullptr) {
727 const Span<float3> positions = mesh_eval->vert_positions();
728 const Span<float3> vert_normals = mesh_eval->vert_normals();
729 copy_v3_v3(efd->loc, positions[*efd->index]);
730 copy_v3_v3(efd->nor, vert_normals[*efd->index]);
731
732 mul_m4_v3(eff->ob->object_to_world().ptr(), efd->loc);
733 mul_mat3_m4_v3(eff->ob->object_to_world().ptr(), efd->nor);
734
735 normalize_v3(efd->nor);
736
737 efd->size = 0.0f;
738
739 ret = true;
740 }
741 }
742 else if (eff->psys) {
743 ParticleData *pa = eff->psys->particles + *efd->index;
745
746 /* exclude the particle itself for self effecting particles */
747 if (eff->psys == point->psys && *efd->index == point->index) {
748 /* pass */
749 }
750 else {
751 ParticleSimulationData sim = {nullptr};
752 sim.depsgraph = eff->depsgraph;
753 sim.scene = eff->scene;
754 sim.ob = eff->ob;
755 sim.psys = eff->psys;
756
757 /* TODO: time from actual previous calculated frame (step might not be 1) */
758 state.time = cfra - 1.0f;
759 ret = psys_get_particle_state(&sim, *efd->index, &state, false);
760
761 /* TODO */
762 // if (eff->pd->forcefiled == PFIELD_HARMONIC && ret==0) {
763 // if (pa->dietime < eff->psys->cfra)
764 // eff->flag |= PE_VELOCITY_TO_IMPULSE;
765 //}
766
767 copy_v3_v3(efd->loc, state.co);
768
769 /* rather than use the velocity use rotated x-axis (defaults to velocity) */
770 efd->nor[0] = 1.0f;
771 efd->nor[1] = efd->nor[2] = 0.0f;
772 mul_qt_v3(state.rot, efd->nor);
773
774 if (real_velocity) {
775 copy_v3_v3(efd->vel, state.vel);
776 }
777 efd->size = pa->size;
778 }
779 }
780 else {
781 /* use center of object for distance calculus */
782 const Object *ob = eff->ob;
783
784 /* Use z-axis as normal. */
785 normalize_v3_v3(efd->nor, ob->object_to_world().ptr()[2]);
786
787 if (eff->pd && ELEM(eff->pd->shape, PFIELD_SHAPE_PLANE, PFIELD_SHAPE_LINE)) {
788 float temp[3], translate[3];
789 sub_v3_v3v3(temp, point->loc, ob->object_to_world().location());
790 project_v3_v3v3(translate, temp, efd->nor);
791
792 /* for vortex the shape chooses between old / new force */
793 if (eff->pd->forcefield == PFIELD_VORTEX || eff->pd->shape == PFIELD_SHAPE_LINE) {
794 add_v3_v3v3(efd->loc, ob->object_to_world().location(), translate);
795 }
796 else { /* Normally `efd->loc` is closest point on effector XY-plane. */
797 sub_v3_v3v3(efd->loc, point->loc, translate);
798 }
799 }
800 else {
801 copy_v3_v3(efd->loc, ob->object_to_world().location());
802 }
803
804 zero_v3(efd->vel);
805 efd->size = 0.0f;
806
807 ret = true;
808 }
809
810 if (ret) {
811 sub_v3_v3v3(efd->vec_to_point, point->loc, efd->loc);
812 efd->distance = len_v3(efd->vec_to_point);
813
814 /* Rest length for harmonic effector,
815 * will have to see later if this could be extended to other effectors. */
816 if (eff->pd && eff->pd->forcefield == PFIELD_HARMONIC && eff->pd->f_size) {
817 mul_v3_fl(efd->vec_to_point, (efd->distance - eff->pd->f_size) / efd->distance);
818 }
819
820 if (eff->flag & PE_USE_NORMAL_DATA) {
822 copy_v3_v3(efd->nor2, efd->nor);
823 }
824 else {
825 /* for some effectors we need the object center every time */
826 sub_v3_v3v3(efd->vec_to_point2, point->loc, eff->ob->object_to_world().location());
827 normalize_v3_v3(efd->nor2, eff->ob->object_to_world().ptr()[2]);
828 }
829 }
830
831 return ret;
832}
834 EffectorCache *eff, EffectorData *efd, EffectedPoint *point, int *tot, int *p, int *step)
835{
836 *p = 0;
837 efd->index = p;
838
839 if (eff->pd->shape == PFIELD_SHAPE_POINTS) {
840 /* TODO: hair and points object support */
841 const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(eff->ob);
842 *tot = mesh_eval != nullptr ? mesh_eval->verts_num : 1;
843
844 if (*tot && eff->pd->forcefield == PFIELD_HARMONIC && point->index >= 0) {
845 *p = point->index % *tot;
846 *tot = *p + 1;
847 }
848 }
849 else if (eff->psys) {
850 *tot = eff->psys->totpart;
851
852 if (eff->pd->forcefield == PFIELD_CHARGE) {
853 /* Only the charge of the effected particle is used for
854 * interaction, not fall-offs. If the fall-offs aren't the
855 * same this will be nonphysical, but for animation this
856 * could be the wanted behavior. If you want physical
857 * correctness the fall-off should be spherical 2.0 anyways.
858 */
859 efd->charge = eff->pd->f_strength;
860 }
861 else if (eff->pd->forcefield == PFIELD_HARMONIC &&
862 (eff->pd->flag & PFIELD_MULTIPLE_SPRINGS) == 0)
863 {
864 /* every particle is mapped to only one harmonic effector particle */
865 *p = point->index % eff->psys->totpart;
866 *tot = *p + 1;
867 }
868
869 if (eff->psys->part->effector_amount) {
870 int totpart = eff->psys->totpart;
871 int amount = eff->psys->part->effector_amount;
872
873 *step = (totpart > amount) ? int(ceil(float(totpart) / float(amount))) : 1;
874 }
875 }
876 else {
877 *tot = 1;
878 }
879}
881 EffectorData *efd,
882 EffectedPoint *point,
883 float *total_force)
884{
885 TexResult result[4];
886 float tex_co[3], strength, force[3];
887 float nabla = eff->pd->tex_nabla;
888 int hasrgb;
889 short mode = eff->pd->tex_mode;
890
891 if (!eff->pd->tex) {
892 return;
893 }
894
895 strength = eff->pd->f_strength * efd->falloff;
896
897 copy_v3_v3(tex_co, point->loc);
898
899 if (eff->pd->flag & PFIELD_TEX_OBJECT) {
900 mul_m4_v3(eff->ob->world_to_object().ptr(), tex_co);
901
902 if (eff->pd->flag & PFIELD_TEX_2D) {
903 tex_co[2] = 0.0f;
904 }
905 }
906 else if (eff->pd->flag & PFIELD_TEX_2D) {
907 float fac = -dot_v3v3(tex_co, efd->nor);
908 madd_v3_v3fl(tex_co, efd->nor, fac);
909 }
910
911 hasrgb = multitex_ext(eff->pd->tex, tex_co, result, 0, nullptr, true, false);
912
913 if (hasrgb && mode == PFIELD_TEX_RGB) {
914 force[0] = (0.5f - result->trgba[0]) * strength;
915 force[1] = (0.5f - result->trgba[1]) * strength;
916 force[2] = (0.5f - result->trgba[2]) * strength;
917 }
918 else if (nabla != 0) {
919 strength /= nabla;
920
921 tex_co[0] += nabla;
922 multitex_ext(eff->pd->tex, tex_co, result + 1, 0, nullptr, true, false);
923
924 tex_co[0] -= nabla;
925 tex_co[1] += nabla;
926 multitex_ext(eff->pd->tex, tex_co, result + 2, 0, nullptr, true, false);
927
928 tex_co[1] -= nabla;
929 tex_co[2] += nabla;
930 multitex_ext(eff->pd->tex, tex_co, result + 3, 0, nullptr, true, false);
931
932 if (mode == PFIELD_TEX_GRAD || !hasrgb) { /* if we don't have rgb fall back to grad */
933 /* generate intensity if texture only has rgb value */
934 if (hasrgb & TEX_RGB) {
935 for (int i = 0; i < 4; i++) {
936 result[i].tin = (1.0f / 3.0f) *
937 (result[i].trgba[0] + result[i].trgba[1] + result[i].trgba[2]);
938 }
939 }
940 force[0] = (result[0].tin - result[1].tin) * strength;
941 force[1] = (result[0].tin - result[2].tin) * strength;
942 force[2] = (result[0].tin - result[3].tin) * strength;
943 }
944 else { /*PFIELD_TEX_CURL*/
945 float dbdy, dgdz, drdz, dbdx, dgdx, drdy;
946
947 dbdy = result[2].trgba[2] - result[0].trgba[2];
948 dgdz = result[3].trgba[1] - result[0].trgba[1];
949 drdz = result[3].trgba[0] - result[0].trgba[0];
950 dbdx = result[1].trgba[2] - result[0].trgba[2];
951 dgdx = result[1].trgba[1] - result[0].trgba[1];
952 drdy = result[2].trgba[0] - result[0].trgba[0];
953
954 force[0] = (dbdy - dgdz) * strength;
955 force[1] = (drdz - dbdx) * strength;
956 force[2] = (dgdx - drdy) * strength;
957 }
958 }
959 else {
960 zero_v3(force);
961 }
962
963 if (eff->pd->flag & PFIELD_TEX_2D) {
964 float fac = -dot_v3v3(force, efd->nor);
965 madd_v3_v3fl(force, efd->nor, fac);
966 }
967
968 if (eff->pd->flag & PFIELD_DO_LOCATION) {
969 add_v3_v3(total_force, force);
970 }
971}
973 EffectorData *efd,
974 EffectedPoint *point,
975 float *total_force)
976{
977 PartDeflect *pd = eff->pd;
978 RNG *rng = eff->rng;
979 float force[3] = {0, 0, 0};
980 float temp[3];
981 float fac;
982 float strength = pd->f_strength;
983 float damp = pd->f_damp;
984 float noise_factor = pd->f_noise;
985 float flow_falloff = efd->falloff;
986
987 if (noise_factor > 0.0f) {
988 strength += wind_func(rng, noise_factor);
989
991 damp += wind_func(rng, noise_factor);
992 }
993 }
994
995 copy_v3_v3(force, efd->vec_to_point);
996
997 switch (pd->forcefield) {
998 case PFIELD_WIND:
999 copy_v3_v3(force, efd->nor);
1000 mul_v3_fl(force, strength * efd->falloff);
1001 break;
1002 case PFIELD_FORCE:
1003 normalize_v3(force);
1004 if (pd->flag & PFIELD_GRAVITATION) { /* Option: Multiply by 1/distance^2 */
1005 if (efd->distance < FLT_EPSILON) {
1006 strength = 0.0f;
1007 }
1008 else {
1009 strength *= powf(efd->distance, -2.0f);
1010 }
1011 }
1012 mul_v3_fl(force, strength * efd->falloff);
1013 break;
1014 case PFIELD_VORTEX:
1015 /* old vortex force */
1016 if (pd->shape == PFIELD_SHAPE_POINT) {
1017 cross_v3_v3v3(force, efd->nor, efd->vec_to_point);
1018 normalize_v3(force);
1019 mul_v3_fl(force, strength * efd->distance * efd->falloff);
1020 }
1021 else {
1022 /* new vortex force */
1023 cross_v3_v3v3(temp, efd->nor2, efd->vec_to_point2);
1024 mul_v3_fl(temp, strength * efd->falloff);
1025
1026 cross_v3_v3v3(force, efd->nor2, temp);
1027 mul_v3_fl(force, strength * efd->falloff);
1028
1029 madd_v3_v3fl(temp, point->vel, -point->vel_to_sec);
1030 add_v3_v3(force, temp);
1031 }
1032 break;
1033 case PFIELD_MAGNET:
1035 /* magnetic field of a moving charge */
1036 cross_v3_v3v3(temp, efd->nor, efd->vec_to_point);
1037 }
1038 else {
1039 copy_v3_v3(temp, efd->nor);
1040 }
1041
1042 normalize_v3(temp);
1043 mul_v3_fl(temp, strength * efd->falloff);
1044 cross_v3_v3v3(force, point->vel, temp);
1045 mul_v3_fl(force, point->vel_to_sec);
1046 break;
1047 case PFIELD_HARMONIC:
1048 mul_v3_fl(force, -strength * efd->falloff);
1049 copy_v3_v3(temp, point->vel);
1050 mul_v3_fl(temp, -damp * 2.0f * sqrtf(fabsf(strength)) * point->vel_to_sec);
1051 add_v3_v3(force, temp);
1052 break;
1053 case PFIELD_CHARGE:
1054 mul_v3_fl(force, point->charge * strength * efd->falloff);
1055 break;
1056 case PFIELD_LENNARDJ:
1057 fac = pow((efd->size + point->size) / efd->distance, 6.0);
1058
1059 fac = -fac * (1.0f - fac) / efd->distance;
1060
1061 /* limit the repulsive term drastically to avoid huge forces */
1062 fac = ((fac > 2.0f) ? 2.0f : fac);
1063
1064 mul_v3_fl(force, strength * fac);
1065 break;
1066 case PFIELD_BOID:
1067 /* Boid field is handled completely in boids code. */
1068 return;
1069 case PFIELD_TURBULENCE:
1070 if (pd->flag & PFIELD_GLOBAL_CO) {
1071 copy_v3_v3(temp, point->loc);
1072 }
1073 else {
1074 add_v3_v3v3(temp, efd->vec_to_point2, efd->nor2);
1075 }
1076 force[0] = -1.0f + 2.0f * BLI_noise_generic_turbulence(
1077 pd->f_size, temp[0], temp[1], temp[2], 2, false, 2);
1078 force[1] = -1.0f + 2.0f * BLI_noise_generic_turbulence(
1079 pd->f_size, temp[1], temp[2], temp[0], 2, false, 2);
1080 force[2] = -1.0f + 2.0f * BLI_noise_generic_turbulence(
1081 pd->f_size, temp[2], temp[0], temp[1], 2, false, 2);
1082 mul_v3_fl(force, strength * efd->falloff);
1083 break;
1084 case PFIELD_DRAG:
1085 copy_v3_v3(force, point->vel);
1086 fac = normalize_v3(force) * point->vel_to_sec;
1087
1088 strength = std::min(strength, 2.0f);
1089 damp = std::min(damp, 2.0f);
1090
1091 mul_v3_fl(force, -efd->falloff * fac * (strength * fac + damp));
1092 break;
1093 case PFIELD_FLUIDFLOW:
1094 zero_v3(force);
1095 flow_falloff = 0;
1096#ifdef WITH_FLUID
1097 if (pd->f_source) {
1098 const float density = BKE_fluid_get_velocity_at(pd->f_source, point->loc, force);
1099 if (density >= 0.0f) {
1100 float influence = strength * efd->falloff;
1101 if (pd->flag & PFIELD_SMOKE_DENSITY) {
1102 influence *= density;
1103 }
1104 mul_v3_fl(force, influence);
1105 flow_falloff = influence;
1106 }
1107 }
1108#endif
1109 break;
1110 default:
1111 break;
1112 }
1113
1114 if (pd->flag & PFIELD_DO_LOCATION) {
1115 madd_v3_v3fl(total_force, force, 1.0f / point->vel_to_sec);
1116
1117 if (!ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG) && pd->f_flow != 0.0f) {
1118 madd_v3_v3fl(total_force, point->vel, -pd->f_flow * flow_falloff);
1119 }
1120 }
1121
1122 if (pd->flag & PFIELD_DO_ROTATION && point->ave && point->rot) {
1123 float xvec[3] = {1.0f, 0.0f, 0.0f};
1124 float dave[3];
1125 mul_qt_v3(point->rot, xvec);
1126 cross_v3_v3v3(dave, xvec, force);
1127 if (pd->f_flow != 0.0f) {
1128 madd_v3_v3fl(dave, point->ave, -pd->f_flow * efd->falloff);
1129 }
1130 add_v3_v3(point->ave, dave);
1131 }
1132}
1133
1134void BKE_effectors_apply(ListBaseT<EffectorCache> *effectors,
1135 ListBaseT<ColliderCache> *colliders,
1136 EffectorWeights *weights,
1137 EffectedPoint *point,
1138 float *force,
1139 float *wind_force,
1140 float *impulse)
1141{
1142 /* WARNING(@ideasman42): historic comment?
1143 * Many of these parameters don't exist!
1144 *
1145 * `scene` = scene where it runs in, for time and stuff.
1146 * `lb` = listbase with objects that take part in effecting.
1147 * `opco` = global coord, as input.
1148 * `force` = accumulator for force.
1149 * `wind_force` = accumulator for force only acting perpendicular to a surface.
1150 * `speed` = actual current speed which can be altered.
1151 * `cur_time` = "external" time in frames, is constant for static particles.
1152 * `loc_time` = "local" time in frames, range <0-1> for the lifetime of particle.
1153 * `par_layer` = layer the caller is in.
1154 * `flags` = only used for soft-body wind now.
1155 * `guide` = old speed of particle.
1156 */
1157
1158 /*
1159 * Modifies the force on a particle according to its
1160 * relation with the effector object
1161 * Different kind of effectors include:
1162 * - Force-fields: Gravity-like attractor
1163 * (force power is related to the inverse of distance to the power of a falloff value)
1164 * - Vortex fields: swirling effectors
1165 * (particles rotate around Z-axis of the object. otherwise, same relation as)
1166 * (Force-fields, but this is not done through a force/acceleration)
1167 * - Guide: particles on a path
1168 * (particles are guided along a curve bezier or old nurbs)
1169 * (is independent of other effectors)
1170 */
1171 EffectorData efd;
1172 int p = 0, tot = 1, step = 1;
1173
1174 /* Cycle through collected objects, get total of (1/(gravity_strength * dist^gravity_power)) */
1175 /* Check for min distance here? (yes would be cool to add that, ton) */
1176
1177 if (effectors) {
1178 for (EffectorCache &eff : *effectors) {
1179 /* object effectors were fully checked to be OK to evaluate! */
1180
1181 get_effector_tot(&eff, &efd, point, &tot, &p, &step);
1182
1183 for (; p < tot; p += step) {
1184 if (get_effector_data(&eff, &efd, point, 0)) {
1185 efd.falloff = effector_falloff(&eff, &efd, point, weights);
1186
1187 if (efd.falloff > 0.0f) {
1188 efd.falloff *= eff_calc_visibility(colliders, &eff, &efd, point);
1189 }
1190 if (efd.falloff > 0.0f) {
1191 float out_force[3] = {0, 0, 0};
1192
1193 if (eff.pd->forcefield == PFIELD_TEXTURE) {
1194 do_texture_effector(&eff, &efd, point, out_force);
1195 }
1196 else {
1197 do_physical_effector(&eff, &efd, point, out_force);
1198
1199 /* for softbody backward compatibility */
1200 if (point->flag & PE_WIND_AS_SPEED && impulse) {
1201 sub_v3_v3v3(impulse, impulse, out_force);
1202 }
1203 }
1204
1205 if (wind_force) {
1206 madd_v3_v3fl(force, out_force, 1.0f - eff.pd->f_wind_factor);
1207 madd_v3_v3fl(wind_force, out_force, eff.pd->f_wind_factor);
1208 }
1209 else {
1210 add_v3_v3(force, out_force);
1211 }
1212 }
1213 }
1214 else if (eff.flag & PE_VELOCITY_TO_IMPULSE && impulse) {
1215 /* special case for harmonic effector */
1216 add_v3_v3v3(impulse, impulse, efd.vel);
1217 }
1218 }
1219 }
1220 }
1221}
1222
1223/* ======== Simulation Debugging ======== */
1224
1226
1228{
1229 return BLI_ghashutil_uinthash(uint(i));
1230}
1231
1233{
1234#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
1235
1236 uint a, b, c;
1237
1238 a = b = c = 0xdeadbeef + (2 << 2) + 13;
1239 a += kx;
1240 b += ky;
1241
1242 c ^= b;
1243 c -= rot(b, 14);
1244 a ^= c;
1245 a -= rot(c, 11);
1246 b ^= a;
1247 b -= rot(a, 25);
1248 c ^= b;
1249 c -= rot(b, 16);
1250 a ^= c;
1251 a -= rot(c, 4);
1252 b ^= a;
1253 b -= rot(a, 14);
1254 c ^= b;
1255 c -= rot(b, 24);
1256
1257 return c;
1258
1259#undef rot
1260}
1261
1262static uint debug_element_hash(const void *key)
1263{
1264 const SimDebugElement *elem = static_cast<const SimDebugElement *>(key);
1265 return elem->hash;
1266}
1267
1268static bool debug_element_compare(const void *a, const void *b)
1269{
1270 const SimDebugElement *elem1 = static_cast<const SimDebugElement *>(a);
1271 const SimDebugElement *elem2 = static_cast<const SimDebugElement *>(b);
1272
1273 if (elem1->hash == elem2->hash) {
1274 return false;
1275 }
1276 return true;
1277}
1278
1279static void debug_element_free(void *val)
1280{
1281 SimDebugElement *elem = static_cast<SimDebugElement *>(val);
1282 MEM_delete(elem);
1283}
1284
1286{
1287 if (enable) {
1288 if (!_sim_debug_data) {
1291 debug_element_hash, debug_element_compare, "sim debug element hash");
1292 }
1293 }
1294 else {
1296 }
1297}
1298
1300{
1301 return _sim_debug_data != nullptr;
1302}
1303
1305{
1306 if (_sim_debug_data) {
1307 if (_sim_debug_data->gh) {
1309 }
1310 MEM_delete(_sim_debug_data);
1311 }
1312}
1313
1314static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
1315{
1316 SimDebugElement *old_elem = static_cast<SimDebugElement *>(
1317 BLI_ghash_lookup(debug_data->gh, elem));
1318 if (old_elem) {
1319 *old_elem = *elem;
1320 MEM_delete(elem);
1321 }
1322 else {
1323 BLI_ghash_insert(debug_data->gh, elem, elem);
1324 }
1325}
1326
1328 const float v1[3],
1329 const float v2[3],
1330 const char *str,
1331 float r,
1332 float g,
1333 float b,
1334 const char *category,
1335 uint hash)
1336{
1337 uint category_hash = BLI_ghashutil_strhash_p(category);
1338 SimDebugElement *elem;
1339
1340 if (!_sim_debug_data) {
1341 if (G.debug & G_DEBUG_SIMDATA) {
1343 }
1344 else {
1345 return;
1346 }
1347 }
1348
1349 elem = MEM_new_zeroed<SimDebugElement>("sim debug data element");
1350 elem->type = type;
1351 elem->category_hash = category_hash;
1352 elem->hash = hash;
1353 elem->color[0] = r;
1354 elem->color[1] = g;
1355 elem->color[2] = b;
1356 if (v1) {
1357 copy_v3_v3(elem->v1, v1);
1358 }
1359 else {
1360 zero_v3(elem->v1);
1361 }
1362 if (v2) {
1363 copy_v3_v3(elem->v2, v2);
1364 }
1365 else {
1366 zero_v3(elem->v2);
1367 }
1368 if (str) {
1369 STRNCPY(elem->str, str);
1370 }
1371 else {
1372 elem->str[0] = '\0';
1373 }
1374
1376}
1377
1379{
1380 SimDebugElement dummy;
1381 if (!_sim_debug_data) {
1382 return;
1383 }
1384 dummy.hash = hash;
1386}
1387
1389{
1390 if (!_sim_debug_data) {
1391 return;
1392 }
1393 if (_sim_debug_data->gh) {
1395 }
1396}
1397
1398void BKE_sim_debug_data_clear_category(const char *category)
1399{
1400 int category_hash = int(BLI_ghashutil_strhash_p(category));
1401
1402 if (!_sim_debug_data) {
1403 return;
1404 }
1405
1406 if (_sim_debug_data->gh) {
1407 GHashIterator iter;
1409 while (!BLI_ghashIterator_done(&iter)) {
1410 const SimDebugElement *elem = static_cast<const SimDebugElement *>(
1412
1413 /* Removing invalidates the current iterator, so step before removing. */
1415
1416 if (elem->category_hash == category_hash) {
1418 }
1419 }
1420 }
1421}
1422
1423} // namespace blender
display list (or rather multi purpose list) stuff.
#define PE_VELOCITY_TO_IMPULSE
Definition BKE_effect.h:175
#define PE_USE_NORMAL_DATA
Definition BKE_effect.h:172
#define PE_WIND_AS_SPEED
Definition BKE_effect.h:171
General operations, lookup, etc. for blender objects.
#define BVH_RAYCAST_DEFAULT
#define RAD2DEGF(_rad)
Random number functions.
Platform independent time functions.
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define ELEM(...)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition btVector3.h:263
std::optional< ClosestPointResult > closest_point(const float3 &point, float radius=std::numeric_limits< float >::max()) const
Definition bvh.cc:709
#define powf(x, y)
#define offsetof(t, d)
#define rot(x, k)
#define str(s)
#define FLT_EPSILON
#define pow
constexpr T sign(T) RET
#define ceil
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float4x4 translate(float4x4 mat, float3 translation)
const int state
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline float2 power(const float2 v, const float e)
BMesh Iterators.
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE void negate_v3_v3(float r[3], const float a[3])
struct PartDeflect * BKE_partdeflect_new(ePFieldType type)
Definition effect.cc:76
unsigned int BLI_ghashutil_uinthash(unsigned int key)
float BLI_noise_generic_turbulence(float noisesize, float x, float y, float z, int oct, bool hard, int noisebasis)
Definition noise_c.cc:1212
char * STRNCPY(char(&dst)[N], const char *src)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void BKE_collider_cache_free(ListBaseT< ColliderCache > **colliders)
void BKE_sim_debug_data_set_enabled(bool enable)
Definition effect.cc:1285
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
int multitex_ext(Tex *tex, const float texvec[3], TexResult *texres, const short thread, ImagePool *pool, bool scene_color_manage, const bool skip_load_image)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:735
@ BASE_ENABLED_VIEWPORT
bool BKE_where_on_path(const struct Object *ob, float ctime, float r_vec[4], float r_dir[3], float r_quat[4], float *r_radius, float *r_weight)
static void precalculate_effector(Depsgraph *depsgraph, EffectorCache *eff)
Definition effect.cc:136
int BLI_bvhtree_ray_cast_ex(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata, int flag)
MINLINE float safe_acosf(float a)
void pd_point_from_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, struct EffectedPoint *point)
Definition effect.cc:388
void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str, float r, float g, float b, const char *category, unsigned int hash)
Definition effect.cc:1327
struct PartDeflect * BKE_partdeflect_copy(const struct PartDeflect *pd_src)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void BKE_effectors_apply(ListBaseT< EffectorCache > *effectors, ListBaseT< ColliderCache > *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
Definition effect.cc:1134
static uint debug_element_hash(const void *key)
Definition effect.cc:1262
unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky)
Definition effect.cc:1232
static void eff_tri_ray_hit(void *, int, const BVHTreeRay *, BVHTreeRayHit *hit)
Definition effect.cc:460
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:45
float psys_get_timestep(struct ParticleSimulationData *sim)
Definition particle.cc:4518
struct RNG * BLI_rng_new(unsigned int seed)
Definition rand.cc:41
MINLINE void mul_v3_fl(float r[3], float f)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:711
float effector_falloff(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, struct EffectorWeights *weights)
Definition effect.cc:596
@ G_DEBUG_SIMDATA
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
Global G
Definition blender.cc:57
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.hh:301
void mul_qt_v3(const float q[4], float r[3])
float BKE_fluid_get_velocity_at(struct Object *ob, float position[3], float velocity[3])
void mul_m4_v3(const float M[4][4], float r[3])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
static bool is_effector_enabled(PartDeflect *pd, bool use_rotation)
Definition effect.cc:258
void BLI_ghashIterator_step(GHashIterator *ghi)
Definition BLI_ghash.cc:917
VecBase< int32_t, 2 > int2
void BKE_sim_debug_data_clear()
Definition effect.cc:1388
bool psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, bool always)
Definition particle.cc:4930
VecBase< int32_t, 3 > int3
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
ListBaseT< ColliderCache > * BKE_collider_cache_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection)
Main * DEG_get_bmain(const Depsgraph *graph)
void BKE_sim_debug_data_remove_element(unsigned int hash)
Definition effect.cc:1378
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
static void add_effector_relation(ListBaseT< EffectorRelation > *relations, Object *ob, ParticleSystem *psys, PartDeflect *pd)
Definition effect.cc:172
void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:861
ListBaseT< EffectorRelation > * DEG_get_effector_relations(const Depsgraph *depsgraph, Collection *collection)
bool get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, int real_velocity)
Definition effect.cc:697
SimDebugData * _sim_debug_data
Definition effect.cc:1225
Base * BKE_collection_or_layer_objects(const Main &bmain, const Scene *scene, ViewLayer *view_layer, Collection *collection)
static float falloff_func_dist(PartDeflect *pd, float fac)
Definition effect.cc:576
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
Definition rand.cc:55
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
static void get_effector_tot(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, int *tot, int *p, int *step)
Definition effect.cc:833
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition BLI_ghash.cc:901
MINLINE void zero_v3(float r[3])
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
Definition particle.cc:739
@ BVH_RAYCAST_WATERTIGHT
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition rand.cc:90
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
void BKE_partdeflect_free(struct PartDeflect *pd)
Definition effect.cc:126
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void int BLI_rng_get_int(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition rand.cc:75
static bool debug_element_compare(const void *a, const void *b)
Definition effect.cc:1268
MINLINE float normalize_v3(float n[3])
unsigned int BKE_sim_debug_data_hash(int i)
Definition effect.cc:1227
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void pd_point_from_loc(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
Definition effect.cc:424
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static float wind_func(RNG *rng, float strength)
Definition effect.cc:539
void psys_update_particle_tree(struct ParticleSystem *psys, float cfra)
static float falloff_func_rad(PartDeflect *pd, float fac)
Definition effect.cc:586
void BKE_effector_relations_free(ListBaseT< EffectorRelation > *lb)
Definition effect.cc:249
static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, float *total_force)
Definition effect.cc:880
static void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, float *total_force)
Definition effect.cc:972
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:792
ListBaseT< EffectorCache > * BKE_effectors_create(struct Depsgraph *depsgraph, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool use_rotation)
Definition effect.cc:316
ListBaseT< EffectorRelation > * BKE_effector_relations_create(struct Depsgraph *depsgraph, const struct Scene *scene, struct ViewLayer *view_layer, struct Collection *collection)
bool BKE_sim_debug_data_get_enabled()
Definition effect.cc:1299
void pd_point_from_soft(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
Definition effect.cc:439
unsigned int BLI_ghashutil_strhash_p(const void *ptr)
double BLI_time_now_seconds()
Definition time.cc:30
static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
Definition effect.cc:1314
static bool is_effector_nonzero_strength(PartDeflect *pd)
Definition effect.cc:279
bool closest_point_on_surface(struct SurfaceModifierData *surmd, const float co[3], float surface_co[3], float surface_nor[3], float surface_vel[3])
Definition effect.cc:645
static void add_effector_evaluation(ListBaseT< EffectorCache > **effectors, Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd)
Definition effect.cc:185
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:690
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
VecBase< float, 3 > float3
void BKE_sim_debug_data_clear_category(const char *category)
Definition effect.cc:1398
static float eff_calc_visibility(ListBaseT< ColliderCache > *colliders, EffectorCache *eff, EffectorData *efd, EffectedPoint *point)
Definition effect.cc:473
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
Definition effect.cc:63
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float DEG_get_ctime(const Depsgraph *graph)
BLI_INLINE bool BLI_ghashIterator_done(const GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.hh:309
static bool is_effector_relevant(PartDeflect *pd, EffectorWeights *weights, bool use_rotation)
Definition effect.cc:310
void BKE_effectors_free(ListBaseT< EffectorCache > *lb)
Definition effect.cc:371
static void debug_element_free(void *val)
Definition effect.cc:1279
static float falloff_func(float fac, int usemin, float mindist, int usemax, float maxdist, float power)
Definition effect.cc:557
void BKE_sim_debug_data_free()
Definition effect.cc:1304
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Definition object.cc:4436
#define hash
Definition noise_c.cc:156
#define fabsf
#define sqrtf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
closure color absorption() BUILTIN
struct Object * object
struct Base * next
const float * anim_path_accum_length
Definition BKE_curve.hh:53
struct ParticleSystem * psys
Definition BKE_effect.h:44
struct Object * ob
Definition BKE_effect.h:76
struct Scene * scene
Definition BKE_effect.h:75
struct SurfaceModifierData * surmd
Definition BKE_effect.h:78
struct PartDeflect * pd
Definition BKE_effect.h:80
struct Depsgraph * depsgraph
Definition BKE_effect.h:74
struct ParticleSystem * psys
Definition BKE_effect.h:77
struct PartDeflect * pd
Definition BKE_effect.h:98
struct ParticleSystem * psys
Definition BKE_effect.h:97
struct PartDeflect * pd
bke::ObjectRuntime * runtime
ListBaseT< struct ParticleSystem > particlesystem
struct ParticleSystem * psys
struct RenderData r
struct GHash * gh
Definition BKE_effect.h:224
unsigned int category_hash
Definition BKE_effect.h:205
SurfaceModifierData_Runtime runtime