~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/effect.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 *  \ingroup bke
30
30
 */
31
31
 
32
 
 
33
32
#include <stddef.h>
34
33
 
35
34
#include <math.h>
55
54
 
56
55
#include "BLI_math.h"
57
56
#include "BLI_blenlib.h"
 
57
#include "BLI_noise.h"
58
58
#include "BLI_jitter.h"
59
59
#include "BLI_rand.h"
60
60
#include "BLI_utildefines.h"
85
85
#include "BKE_object.h"
86
86
#include "BKE_particle.h"
87
87
#include "BKE_scene.h"
 
88
#include "BKE_smoke.h"
88
89
 
89
90
 
90
91
#include "RE_render_ext.h"
98
99
#include <string.h>
99
100
#endif // WITH_MOD_FLUID
100
101
 
101
 
//XXX #include "BIF_screen.h"
102
 
 
103
102
EffectorWeights *BKE_add_effector_weights(Group *group)
104
103
{
105
104
        EffectorWeights *weights = MEM_callocN(sizeof(EffectorWeights), "EffectorWeights");
129
128
        pd->f_damp = 1.0f;
130
129
 
131
130
        /* set sensible defaults based on type */
132
 
        switch(type) {
 
131
        switch (type) {
133
132
                case PFIELD_VORTEX:
134
133
                        pd->shape = PFIELD_SHAPE_PLANE;
135
134
                        break;
140
139
                case PFIELD_TEXTURE:
141
140
                        pd->f_size = 1.0f;
142
141
                        break;
 
142
                case PFIELD_SMOKEFLOW:
 
143
                        pd->f_flow = 1.0f;
 
144
                        break;
143
145
        }
144
146
        pd->flag = PFIELD_DO_LOCATION|PFIELD_DO_ROTATION;
145
147
 
164
166
                pd->tex->id.us--;
165
167
 
166
168
        if (pd->rng)
167
 
                rng_free(pd->rng);
 
169
                BLI_rng_free(pd->rng);
168
170
 
169
171
        MEM_freeN(pd);
170
172
}
173
175
{
174
176
        unsigned int cfra = (unsigned int)(eff->scene->r.cfra >= 0 ? eff->scene->r.cfra : -eff->scene->r.cfra);
175
177
        if (!eff->pd->rng)
176
 
                eff->pd->rng = rng_new(eff->pd->seed + cfra);
 
178
                eff->pd->rng = BLI_rng_new(eff->pd->seed + cfra);
177
179
        else
178
 
                rng_srandom(eff->pd->rng, eff->pd->seed + cfra);
 
180
                BLI_rng_srandom(eff->pd->rng, eff->pd->seed + cfra);
179
181
 
180
182
        if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type==OB_CURVE) {
181
183
                Curve *cu= eff->ob->data;
182
184
                if (cu->flag & CU_PATH) {
183
185
                        if (cu->path==NULL || cu->path->data==NULL)
184
 
                                makeDispListCurveTypes(eff->scene, eff->ob, 0);
 
186
                                BKE_displist_make_curveTypes(eff->scene, eff->ob, 0);
185
187
 
186
188
                        if (cu->path && cu->path->data) {
187
189
                                where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius, NULL);
202
204
        if (eff->ob) {
203
205
                float old_vel[3];
204
206
 
205
 
                where_is_object_time(eff->scene, eff->ob, cfra - 1.0f);
206
 
                copy_v3_v3(old_vel, eff->ob->obmat[3]); 
207
 
                where_is_object_time(eff->scene, eff->ob, cfra);
 
207
                BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra - 1.0f);
 
208
                copy_v3_v3(old_vel, eff->ob->obmat[3]);
 
209
                BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra);
208
210
                sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel);
209
211
        }
210
212
}
393
395
// triangle - ray callback function
394
396
static void eff_tri_ray_hit(void *UNUSED(userData), int UNUSED(index), const BVHTreeRay *UNUSED(ray), BVHTreeRayHit *hit)
395
397
{       
396
 
        // whenever we hit a bounding box, we don't check further
 
398
        /* whenever we hit a bounding box, we don't check further */
397
399
        hit->dist = -1;
398
400
        hit->index = 1;
399
401
}
418
420
        negate_v3_v3(norm, efd->vec_to_point);
419
421
        len = normalize_v3(norm);
420
422
        
421
 
        // check all collision objects
422
 
        for (col = colls->first; col; col = col->next)
423
 
        {
 
423
        /* check all collision objects */
 
424
        for (col = colls->first; col; col = col->next) {
424
425
                CollisionModifierData *collmd = col->collmd;
425
426
 
426
427
                if (col->ob == eff->ob)
427
428
                        continue;
428
 
                
 
429
 
429
430
                if (collmd->bvhtree) {
430
431
                        BVHTreeRayHit hit;
431
 
                        
 
432
 
432
433
                        hit.index = -1;
433
434
                        hit.dist = len + FLT_EPSILON;
434
 
                        
435
 
                        // check if the way is blocked
 
435
 
 
436
                        /* check if the way is blocked */
436
437
                        if (BLI_bvhtree_ray_cast(collmd->bvhtree, point->loc, norm, 0.0f, &hit, eff_tri_ray_hit, NULL)>=0) {
437
438
                                absorption= col->ob->pd->absorption;
438
439
 
439
 
                                // visibility is only between 0 and 1, calculated from 1-absorption
 
440
                                /* visibility is only between 0 and 1, calculated from 1-absorption */
440
441
                                visibility *= CLAMPIS(1.0f-absorption, 0.0f, 1.0f);
441
442
                                
442
443
                                if (visibility <= 0.0f)
454
455
// noise function for wind e.g.
455
456
static float wind_func(struct RNG *rng, float strength)
456
457
{
457
 
        int random = (rng_getInt(rng)+1) % 128; // max 2357
458
 
        float force = rng_getFloat(rng) + 1.0f;
 
458
        int random = (BLI_rng_get_int(rng)+1) % 128; // max 2357
 
459
        float force = BLI_rng_get_float(rng) + 1.0f;
459
460
        float ret;
460
461
        float sign = 0;
461
462
        
506
507
                falloff=0.0f;
507
508
        else if (eff->pd->zdir == PFIELD_Z_NEG && fac > 0.0f)
508
509
                falloff=0.0f;
509
 
        else switch(eff->pd->falloff) {
 
510
        else {
 
511
                switch (eff->pd->falloff) {
510
512
                case PFIELD_FALL_SPHERE:
511
513
                        falloff*= falloff_func_dist(eff->pd, efd->distance);
512
514
                        break;
529
531
                        falloff*= falloff_func_rad(eff->pd, r_fac);
530
532
 
531
533
                        break;
 
534
                }
532
535
        }
533
536
 
534
537
        return falloff;
559
562
                        if (mface->v4)
560
563
                                add_v3_v3(surface_vel, surmd->v[mface->v4].co);
561
564
 
562
 
                        mul_v3_fl(surface_vel, mface->v4 ? 0.25f : 0.333f);
 
565
                        mul_v3_fl(surface_vel, mface->v4 ? 0.25f : (1.0f / 3.0f));
563
566
                }
564
567
                return 1;
565
568
        }
715
718
                
716
719
                if (eff->pd->forcefield == PFIELD_CHARGE) {
717
720
                        /* Only the charge of the effected particle is used for 
718
 
                         * interaction, not fall-offs. If the fall-offs aren't the      
719
 
                         * same this will be unphysical, but for animation this         
 
721
                         * interaction, not fall-offs. If the fall-offs aren't the
 
722
                         * same this will be unphysical, but for animation this
720
723
                         * could be the wanted behavior. If you want physical
721
724
                         * correctness the fall-off should be spherical 2.0 anyways.
722
725
                         */
755
758
 
756
759
        strength= eff->pd->f_strength * efd->falloff;
757
760
 
758
 
        copy_v3_v3(tex_co,point->loc);
 
761
        copy_v3_v3(tex_co, point->loc);
759
762
 
760
763
        if (eff->pd->flag & PFIELD_TEX_2D) {
761
764
                float fac=-dot_v3v3(tex_co, efd->nor);
766
769
                mul_m4_v3(eff->ob->imat, tex_co);
767
770
        }
768
771
 
769
 
        hasrgb = multitex_ext(eff->pd->tex, tex_co, NULL,NULL, 0, result);
 
772
        hasrgb = multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result, NULL);
770
773
 
771
774
        if (hasrgb && mode==PFIELD_TEX_RGB) {
772
775
                force[0] = (0.5f - result->tr) * strength;
777
780
                strength/=nabla;
778
781
 
779
782
                tex_co[0] += nabla;
780
 
                multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+1);
 
783
                multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+1, NULL);
781
784
 
782
785
                tex_co[0] -= nabla;
783
786
                tex_co[1] += nabla;
784
 
                multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+2);
 
787
                multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+2, NULL);
785
788
 
786
789
                tex_co[1] -= nabla;
787
790
                tex_co[2] += nabla;
788
 
                multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+3);
 
791
                multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+3, NULL);
789
792
 
790
793
                if (mode == PFIELD_TEX_GRAD || !hasrgb) { /* if we don't have rgb fall back to grad */
 
794
                        /* generate intensity if texture only has rgb value */
 
795
                        if (hasrgb & TEX_RGB) {
 
796
                                int i;
 
797
                                for (i=0; i<4; i++)
 
798
                                        result[i].tin = (1.0f / 3.0f) * (result[i].tr + result[i].tg + result[i].tb);
 
799
                        }
791
800
                        force[0] = (result[0].tin - result[1].tin) * strength;
792
801
                        force[1] = (result[0].tin - result[2].tin) * strength;
793
802
                        force[2] = (result[0].tin - result[3].tin) * strength;
819
828
{
820
829
        PartDeflect *pd = eff->pd;
821
830
        RNG *rng = pd->rng;
822
 
        float force[3]={0,0,0};
 
831
        float force[3] = {0, 0, 0};
823
832
        float temp[3];
824
833
        float fac;
825
834
        float strength = pd->f_strength;
835
844
 
836
845
        copy_v3_v3(force, efd->vec_to_point);
837
846
 
838
 
        switch(pd->forcefield) {
 
847
        switch (pd->forcefield) {
839
848
                case PFIELD_WIND:
840
849
                        copy_v3_v3(force, efd->nor);
841
850
                        mul_v3_fl(force, strength * efd->falloff);
904
913
                        else {
905
914
                                add_v3_v3v3(temp, efd->vec_to_point2, efd->nor2);
906
915
                        }
907
 
                        force[0] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[0], temp[1], temp[2], 2,0,2);
908
 
                        force[1] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[1], temp[2], temp[0], 2,0,2);
909
 
                        force[2] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[2], temp[0], temp[1], 2,0,2);
 
916
                        force[0] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[0], temp[1], temp[2], 2, 0, 2);
 
917
                        force[1] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[1], temp[2], temp[0], 2, 0, 2);
 
918
                        force[2] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[2], temp[0], temp[1], 2, 0, 2);
910
919
                        mul_v3_fl(force, strength * efd->falloff);
911
920
                        break;
912
921
                case PFIELD_DRAG:
918
927
 
919
928
                        mul_v3_fl(force, -efd->falloff * fac * (strength * fac + damp));
920
929
                        break;
 
930
                case PFIELD_SMOKEFLOW:
 
931
                        zero_v3(force);
 
932
                        if (pd->f_source) {
 
933
                                float density;
 
934
                                if ((density = smoke_get_velocity_at(pd->f_source, point->loc, force)) >= 0.0f) {
 
935
                                        float influence = strength * efd->falloff;
 
936
                                        if (pd->flag & PFIELD_SMOKE_DENSITY)
 
937
                                                influence *= density;
 
938
                                        mul_v3_fl(force, influence);
 
939
                                        /* apply flow */
 
940
                                        madd_v3_v3fl(total_force, point->vel, -pd->f_flow * influence);
 
941
                                }
 
942
                        }
 
943
                        break;
 
944
 
921
945
        }
922
946
 
923
947
        if (pd->flag & PFIELD_DO_LOCATION) {
924
948
                madd_v3_v3fl(total_force, force, 1.0f/point->vel_to_sec);
925
949
 
926
 
                if (ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG)==0 && pd->f_flow != 0.0f) {
 
950
                if (ELEM3(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG, PFIELD_SMOKEFLOW)==0 && pd->f_flow != 0.0f) {
927
951
                        madd_v3_v3fl(total_force, point->vel, -pd->f_flow * efd->falloff);
928
952
                }
929
953
        }
930
954
 
 
955
        if (point->ave)
 
956
                zero_v3(point->ave);
931
957
        if (pd->flag & PFIELD_DO_ROTATION && point->ave && point->rot) {
932
958
                float xvec[3] = {1.0f, 0.0f, 0.0f};
933
959
                float dave[3];
987
1013
                                if (efd.falloff > 0.0f)
988
1014
                                        efd.falloff *= eff_calc_visibility(colliders, eff, &efd, point);
989
1015
 
990
 
                                if (efd.falloff <= 0.0f)
991
 
                                        ;       /* don't do anything */
992
 
                                else if (eff->pd->forcefield == PFIELD_TEXTURE)
 
1016
                                if (efd.falloff <= 0.0f) {
 
1017
                                        /* don't do anything */
 
1018
                                }
 
1019
                                else if (eff->pd->forcefield == PFIELD_TEXTURE) {
993
1020
                                        do_texture_effector(eff, &efd, point, force);
 
1021
                                }
994
1022
                                else {
995
 
                                        float temp1[3]={0,0,0}, temp2[3];
 
1023
                                        float temp1[3] = {0, 0, 0}, temp2[3];
996
1024
                                        copy_v3_v3(temp1, force);
997
1025
 
998
1026
                                        do_physical_effector(eff, &efd, point, force);
999
1027
                                        
1000
 
                                        // for softbody backward compatibility
 
1028
                                        /* for softbody backward compatibility */
1001
1029
                                        if (point->flag & PE_WIND_AS_SPEED && impulse) {
1002
1030
                                                sub_v3_v3v3(temp2, force, temp1);
1003
1031
                                                sub_v3_v3v3(impulse, impulse, temp2);