Fix for [#27289] Hair: Render Option - Object does not point objects to end of "hair...
authorJanne Karhu <jhkarh@gmail.com>
Sun, 10 Jul 2011 17:30:31 +0000 (17:30 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Sun, 10 Jul 2011 17:30:31 +0000 (17:30 +0000)
* Objects are now always rotated in the directions of the hair paths
* Secondary fix: particle size wasn't updated for hair particles, so dupliobject size couldn't be change after the hair was edited

source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_system.c

index 5e615a28eb2407df1c398e602d06ebddcdf52a26..5995b895061c695197c31f707a0ac171625bb48a 100644 (file)
@@ -4372,58 +4372,45 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa
        Object *ob = sim->ob;
        ParticleSystem *psys = sim->psys;
        ParticleSystemModifierData *psmd = sim->psmd;
-       float loc[3], nor[3], vec[3], side[3], len, obrotmat[4][4], qmat[4][4];
-       float xvec[3] = {-1.0, 0.0, 0.0}, q[4], nmat[3][3];
+       float loc[3], nor[3], vec[3], side[3], len;
+       float xvec[3] = {-1.0, 0.0, 0.0}, nmat[3][3];
 
        sub_v3_v3v3(vec, (cache+cache->steps)->co, cache->co);
        len= normalize_v3(vec);
 
-       if(psys->part->rotmode) {
-               if(pa == NULL)
-                       pa= psys->particles+cpa->pa[0];
+       if(pa == NULL && psys->part->childflat != PART_CHILD_FACES)
+               pa = psys->particles + cpa->pa[0];
 
-               vec_to_quat( q,xvec, ob->trackflag, ob->upflag);
-               quat_to_mat4( obrotmat,q);
-               obrotmat[3][3]= 1.0f;
-
-               quat_to_mat4( qmat,pa->state.rot);
-               mul_m4_m4m4(mat, obrotmat, qmat);
-       }
-       else {
-               if(pa == NULL && psys->part->childflat != PART_CHILD_FACES)
-                       pa = psys->particles + cpa->pa[0];
-
-               if(pa)
-                       psys_particle_on_emitter(psmd,sim->psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc,nor,0,0,0,0);
-               else
-                       psys_particle_on_emitter(psmd,PART_FROM_FACE,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,loc,nor,0,0,0,0);
+       if(pa)
+               psys_particle_on_emitter(psmd,sim->psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc,nor,0,0,0,0);
+       else
+               psys_particle_on_emitter(psmd,PART_FROM_FACE,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,loc,nor,0,0,0,0);
                
-               copy_m3_m4(nmat, ob->imat);
-               transpose_m3(nmat);
-               mul_m3_v3(nmat, nor);
-
-               /* make sure that we get a proper side vector */
-               if(fabs(dot_v3v3(nor,vec))>0.999999) {
-                       if(fabs(dot_v3v3(nor,xvec))>0.999999) {
-                               nor[0] = 0.0f;
-                               nor[1] = 1.0f;
-                               nor[2] = 0.0f;
-                       }
-                       else {
-                               nor[0] = 1.0f;
-                               nor[1] = 0.0f;
-                               nor[2] = 0.0f;
-                       }
-               }
-               cross_v3_v3v3(side, nor, vec);
-               normalize_v3(side);
-               cross_v3_v3v3(nor, vec, side);
+       copy_m3_m4(nmat, ob->imat);
+       transpose_m3(nmat);
+       mul_m3_v3(nmat, nor);
 
-               unit_m4(mat);
-               VECCOPY(mat[0], vec);
-               VECCOPY(mat[1], side);
-               VECCOPY(mat[2], nor);
+       /* make sure that we get a proper side vector */
+       if(fabs(dot_v3v3(nor,vec))>0.999999) {
+               if(fabs(dot_v3v3(nor,xvec))>0.999999) {
+                       nor[0] = 0.0f;
+                       nor[1] = 1.0f;
+                       nor[2] = 0.0f;
+               }
+               else {
+                       nor[0] = 1.0f;
+                       nor[1] = 0.0f;
+                       nor[2] = 0.0f;
+               }
        }
+       cross_v3_v3v3(side, nor, vec);
+       normalize_v3(side);
+       cross_v3_v3v3(nor, vec, side);
+
+       unit_m4(mat);
+       VECCOPY(mat[0], vec);
+       VECCOPY(mat[1], side);
+       VECCOPY(mat[2], nor);
 
        *scale= len;
 }
index 50f397044880b798568f21e8ed64496a3c90962c..63a9c224971b344327d79cf315c55075dee7c5ff 100644 (file)
@@ -3510,11 +3510,15 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
 static void hair_step(ParticleSimulationData *sim, float cfra)
 {
        ParticleSystem *psys = sim->psys;
-/*     ParticleSettings *part = psys->part; */
+       ParticleSettings *part = psys->part;
        PARTICLE_P;
        float disp = (float)psys_get_current_display_percentage(psys)/100.0f;
 
        LOOP_PARTICLES {
+               pa->size = part->size;
+               if(part->randsize > 0.0f)
+                       pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1);
+
                if(PSYS_FRAND(p) > disp)
                        pa->flag |= PARS_NO_DISP;
                else