svn merge -r 16222:16320 https://svn.blender.org/svnroot/bf-blender/trunk/blender
authorDaniel Genrich <daniel.genrich@gmx.net>
Sun, 31 Aug 2008 21:00:20 +0000 (21:00 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sun, 31 Aug 2008 21:00:20 +0000 (21:00 +0000)
1  2 
source/blender/blenkernel/intern/ipo.c
source/blender/blenkernel/intern/particle_system.c
source/blender/render/intern/source/convertblender.c

index 4ba4f6b02f92b4e139d3260934d561be088131ea,1a6c8f51d9c20d1872264a266ca1816a27c5b683..800775eb2b3ce4db0f3c997bc89b1884b81b94ef
@@@ -175,9 -175,7 +175,9 @@@ int fluidsim_ar[FLUIDSIM_TOTIPO]= 
        FLUIDSIM_VISC, FLUIDSIM_TIME,
        FLUIDSIM_GRAV_X , FLUIDSIM_GRAV_Y , FLUIDSIM_GRAV_Z ,
        FLUIDSIM_VEL_X  , FLUIDSIM_VEL_Y  , FLUIDSIM_VEL_Z  ,
 -      FLUIDSIM_ACTIVE 
 +      FLUIDSIM_ACTIVE,
 +      FLUIDSIM_ATTR_FORCE_STR, FLUIDSIM_ATTR_FORCE_RADIUS,
 +      FLUIDSIM_VEL_FORCE_STR, FLUIDSIM_VEL_FORCE_RADIUS,
  };
  
  int part_ar[PART_TOTIPO]= {
@@@ -1674,6 -1672,8 +1674,8 @@@ void set_icu_vars(IpoCurve *icu
                                icu->ymax= 5.0; break;
                        case MA_ADD:
                                icu->ymax= 1.0; break;
+                       case MA_EMIT:
+                               icu->ymax= 2.0; break;
                        default:
                                icu->ymax= 1.0; break;
                        }
index 98bf817381904401d7fdff4e752c2c55a47405bc,92c2f27bc3171d69f3fc7f50e4ec12dd01e7dfc5..4ec9f7a95de13177dc324ec58a9aec9e33db7ae9
@@@ -2301,7 -2301,15 +2301,15 @@@ static void add_to_effectors(ListBase *
                        }
                }
                else if(pd->forcefield)
+               {
                        type |= PSYS_EC_EFFECTOR;
+                       
+                       if(pd->forcefield == PFIELD_WIND)
+                       {
+                               pd->rng = rng_new(1);
+                               rng_srandom(pd->rng, (unsigned int)(ceil(PIL_check_seconds_timer()))); // use better seed
+                       }
+               }
        }
        
        if(pd && pd->deflect)
@@@ -2413,6 -2421,9 +2421,9 @@@ void psys_end_effectors(ParticleSystem 
  
                        if(ec->tree)
                                BLI_kdtree_free(ec->tree);
+                       
+                       if(ec->ob->pd && (ec->ob->pd->forcefield == PFIELD_WIND))
+                               rng_free(ec->ob->pd->rng);
                }
  
                BLI_freelistN(lb);
@@@ -4386,7 -4397,7 +4397,7 @@@ void psys_changed_type(ParticleSystem *
  }
  
  static void particles_fluid_step(Object *ob, ParticleSystem *psys, int cfra)
 -{
 +{     
        if(psys->particles){
                MEM_freeN(psys->particles);
                psys->particles = 0;
  
        /* fluid sim particle import handling, actual loading of particles from file */
        #ifndef DISABLE_ELBEEM
 -      if( (1) && (ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) &&  // broken, disabled for now!
 -              (ob->fluidsimSettings)) { 
 -              ParticleSettings *part = psys->part;
 -              ParticleData *pa=0;
 -              char *suffix  = "fluidsurface_particles_####";
 -              char *suffix2 = ".gz";
 -              char filename[256];
 -              char debugStrBuffer[256];
 -              int  curFrame = G.scene->r.cfra -1; // warning - sync with derived mesh fsmesh loading
 -              int  p, j, numFileParts, totpart;
 -              int readMask, activeParts = 0, fileParts = 0;
 -              gzFile gzf;
 -
 -              if(ob==G.obedit) // off...
 -                      return;
 -
 -              // ok, start loading
 -              strcpy(filename, ob->fluidsimSettings->surfdataPath);
 -              strcat(filename, suffix);
 -              BLI_convertstringcode(filename, G.sce);
 -              BLI_convertstringframe(filename, curFrame); // fixed #frame-no 
 -              strcat(filename, suffix2);
 -
 -              gzf = gzopen(filename, "rb");
 -              if (!gzf) {
 -                      snprintf(debugStrBuffer,256,"readFsPartData::error - Unable to open file for reading '%s' \n", filename); 
 -                      //elbeemDebugOut(debugStrBuffer);
 -                      return;
 -              }
 -
 -              gzread(gzf, &totpart, sizeof(totpart));
 -              numFileParts = totpart;
 -              totpart = (G.rendering)?totpart:(part->disp*totpart)/100;
 +      {
 +              FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
                
 -              part->totpart= totpart;
 -              part->sta=part->end = 1.0f;
 -              part->lifetime = G.scene->r.efra + 1;
 -
 -              /* initialize particles */
 -              realloc_particles(ob, psys, part->totpart);
 -              initialize_all_particles(ob, psys, 0);
 -
 -              // set up reading mask
 -              readMask = ob->fluidsimSettings->typeFlags;
 -              
 -              for(p=0, pa=psys->particles; p<totpart; p++, pa++) {
 -                      int ptype=0;
 -
 -                      gzread(gzf, &ptype, sizeof( ptype )); 
 -                      if(ptype&readMask) {
 -                              activeParts++;
 -
 -                              gzread(gzf, &(pa->size), sizeof( float )); 
 -
 -                              pa->size /= 10.0f;
 -
 -                              for(j=0; j<3; j++) {
 -                                      float wrf;
 -                                      gzread(gzf, &wrf, sizeof( wrf )); 
 -                                      pa->state.co[j] = wrf;
 -                                      //fprintf(stderr,"Rj%d ",j);
 -                              }
 -                              for(j=0; j<3; j++) {
 -                                      float wrf;
 -                                      gzread(gzf, &wrf, sizeof( wrf )); 
 -                                      pa->state.vel[j] = wrf;
 -                              }
 -
 -                              pa->state.ave[0] = pa->state.ave[1] = pa->state.ave[2] = 0.0f;
 -                              pa->state.rot[0] = 1.0;
 -                              pa->state.rot[1] = pa->state.rot[2] = pa->state.rot[3] = 0.0;
 -
 -                              pa->alive = PARS_ALIVE;
 -                              //if(a<25) fprintf(stderr,"FSPARTICLE debug set %s , a%d = %f,%f,%f , life=%f \n", filename, a, pa->co[0],pa->co[1],pa->co[2], pa->lifetime );
 -                      } else {
 -                              // skip...
 -                              for(j=0; j<2*3+1; j++) {
 -                                      float wrf; gzread(gzf, &wrf, sizeof( wrf )); 
 +              if( fluidmd && fluidmd->fss) { 
 +                      FluidsimSettings *fss= fluidmd->fss;
 +                      ParticleSettings *part = psys->part;
 +                      ParticleData *pa=0;
 +                      char *suffix  = "fluidsurface_particles_####";
 +                      char *suffix2 = ".gz";
 +                      char filename[256];
 +                      char debugStrBuffer[256];
 +                      int  curFrame = G.scene->r.cfra -1; // warning - sync with derived mesh fsmesh loading
 +                      int  p, j, numFileParts, totpart;
 +                      int readMask, activeParts = 0, fileParts = 0;
 +                      gzFile gzf;
 +      
 +                      if(ob==G.obedit) // off...
 +                              return;
 +      
 +                      // ok, start loading
 +                      strcpy(filename, fss->surfdataPath);
 +                      strcat(filename, suffix);
 +                      BLI_convertstringcode(filename, G.sce);
 +                      BLI_convertstringframe(filename, curFrame); // fixed #frame-no 
 +                      strcat(filename, suffix2);
 +      
 +                      gzf = gzopen(filename, "rb");
 +                      if (!gzf) {
 +                              snprintf(debugStrBuffer,256,"readFsPartData::error - Unable to open file for reading '%s' \n", filename); 
 +                              //elbeemDebugOut(debugStrBuffer);
 +                              return;
 +                      }
 +      
 +                      gzread(gzf, &totpart, sizeof(totpart));
 +                      numFileParts = totpart;
 +                      totpart = (G.rendering)?totpart:(part->disp*totpart)/100;
 +                      
 +                      part->totpart= totpart;
 +                      part->sta=part->end = 1.0f;
 +                      part->lifetime = G.scene->r.efra + 1;
 +      
 +                      /* initialize particles */
 +                      realloc_particles(ob, psys, part->totpart);
 +                      initialize_all_particles(ob, psys, 0);
 +      
 +                      // set up reading mask
 +                      readMask = fss->typeFlags;
 +                      
 +                      for(p=0, pa=psys->particles; p<totpart; p++, pa++) {
 +                              int ptype=0;
 +      
 +                              gzread(gzf, &ptype, sizeof( ptype )); 
 +                              if(ptype&readMask) {
 +                                      activeParts++;
 +      
 +                                      gzread(gzf, &(pa->size), sizeof( float )); 
 +      
 +                                      pa->size /= 10.0f;
 +      
 +                                      for(j=0; j<3; j++) {
 +                                              float wrf;
 +                                              gzread(gzf, &wrf, sizeof( wrf )); 
 +                                              pa->state.co[j] = wrf;
 +                                              //fprintf(stderr,"Rj%d ",j);
 +                                      }
 +                                      for(j=0; j<3; j++) {
 +                                              float wrf;
 +                                              gzread(gzf, &wrf, sizeof( wrf )); 
 +                                              pa->state.vel[j] = wrf;
 +                                      }
 +      
 +                                      pa->state.ave[0] = pa->state.ave[1] = pa->state.ave[2] = 0.0f;
 +                                      pa->state.rot[0] = 1.0;
 +                                      pa->state.rot[1] = pa->state.rot[2] = pa->state.rot[3] = 0.0;
 +      
 +                                      pa->alive = PARS_ALIVE;
 +                                      //if(a<25) fprintf(stderr,"FSPARTICLE debug set %s , a%d = %f,%f,%f , life=%f \n", filename, a, pa->co[0],pa->co[1],pa->co[2], pa->lifetime );
 +                              } else {
 +                                      // skip...
 +                                      for(j=0; j<2*3+1; j++) {
 +                                              float wrf; gzread(gzf, &wrf, sizeof( wrf )); 
 +                                      }
                                }
 +                              fileParts++;
                        }
 -                      fileParts++;
 -              }
 -              gzclose( gzf );
 -
 -              totpart = psys->totpart = activeParts;
 -              snprintf(debugStrBuffer,256,"readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d  \n", psys->totpart,activeParts,fileParts,readMask);
 -              elbeemDebugOut(debugStrBuffer);
 -      } // fluid sim particles done
 +                      gzclose( gzf );
 +      
 +                      totpart = psys->totpart = activeParts;
 +                      snprintf(debugStrBuffer,256,"readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d  \n", psys->totpart,activeParts,fileParts,readMask);
 +                      elbeemDebugOut(debugStrBuffer);
 +              } // fluid sim particles done
 +      }
        #endif // DISABLE_ELBEEM
  }
  
index 551006ffcc3bfec2acff33e072ac89a474d37bc4,8626fb0f9d07ab3a49db8b3f0c299973abdd2524..0cf962052a36b19291d28d40ebb859b1d59c34cd
@@@ -674,6 -674,94 +674,6 @@@ static void calc_vertexnormals(Render *
                MEM_freeN(vtangents);
  }
  
 -// NT same as calc_vertexnormals, but dont modify the existing vertex normals
 -// only recalculate other render data. If this is at some point used for other things than fluidsim,
 -// this could be made on option for the normal calc_vertexnormals
 -static void calc_fluidsimnormals(Render *re, ObjectRen *obr, int do_nmap_tangent)
 -{
 -      int a;
 -
 -      /* dont clear vertex normals here */
 -      // OFF for(a=0; a<obr->totvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); ver->n[0]=ver->n[1]=ver->n[2]= 0.0; }
 -      /* calculate cos of angles and point-masses, use as weight factor to add face normal to vertex */
 -      for(a=0; a<obr->totvlak; a++) {
 -              VlakRen *vlr= RE_findOrAddVlak(obr, a);
 -              if(vlr->flag & ME_SMOOTH) {
 -                      VertRen *v1= vlr->v1;
 -                      VertRen *v2= vlr->v2;
 -                      VertRen *v3= vlr->v3;
 -                      VertRen *v4= vlr->v4;
 -                      float n1[3], n2[3], n3[3], n4[3];
 -                      float fac1, fac2, fac3, fac4=0.0f;
 -
 -                      if(re->flag & R_GLOB_NOPUNOFLIP)
 -                              vlr->flag |= R_NOPUNOFLIP;
 -                      
 -                      VecSubf(n1, v2->co, v1->co);
 -                      Normalize(n1);
 -                      VecSubf(n2, v3->co, v2->co);
 -                      Normalize(n2);
 -                      if(v4==NULL) {
 -                              VecSubf(n3, v1->co, v3->co);
 -                              Normalize(n3);
 -                              fac1= saacos(-n1[0]*n3[0]-n1[1]*n3[1]-n1[2]*n3[2]);
 -                              fac2= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
 -                              fac3= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
 -                      }
 -                      else {
 -                              VecSubf(n3, v4->co, v3->co);
 -                              Normalize(n3);
 -                              VecSubf(n4, v1->co, v4->co);
 -                              Normalize(n4);
 -
 -                              fac1= saacos(-n4[0]*n1[0]-n4[1]*n1[1]-n4[2]*n1[2]);
 -                              fac2= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
 -                              fac3= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
 -                              fac4= saacos(-n3[0]*n4[0]-n3[1]*n4[1]-n3[2]*n4[2]);
 -
 -                              if(!(vlr->flag & R_NOPUNOFLIP)) {
 -                                      if( check_vnormal(vlr->n, v4->n) ) fac4= -fac4;
 -                              }
 -                      }
 -
 -                      //if(do_nmap_tangent)
 -                      //      calc_tangent_vector(obr, vlr, fac1, fac2, fac3, fac4);
 -              }
 -              if(do_nmap_tangent) {
 -                      /* tangents still need to be calculated for flat faces too */
 -                      /* weighting removed, they are not vertexnormals */
 -                      //calc_tangent_vector(obr, vlr);
 -              }
 -      }
 -
 -      /* do solid faces */
 -      for(a=0; a<obr->totvlak; a++) {
 -              VlakRen *vlr= RE_findOrAddVlak(obr, a);
 -              if((vlr->flag & ME_SMOOTH)==0) {
 -                      float *f1= vlr->v1->n;
 -                      if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
 -                      f1= vlr->v2->n;
 -                      if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
 -                      f1= vlr->v3->n;
 -                      if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
 -                      if(vlr->v4) {
 -                              f1= vlr->v4->n;
 -                              if(f1[0]==0.0 && f1[1]==0.0 && f1[2]==0.0) VECCOPY(f1, vlr->n);
 -                      }                       
 -              }
 -      }
 -      
 -      /* normalize vertex normals */
 -      for(a=0; a<obr->totvert; a++) {
 -              VertRen *ver= RE_findOrAddVert(obr, a);
 -              Normalize(ver->n);
 -              if(do_nmap_tangent) {
 -                      float *tav= RE_vertren_get_tangent(obr, ver, 0);
 -                      if(tav) Normalize(tav);
 -              }
 -      }
 -}
 -
  /* ------------------------------------------------------------------------- */
  /* Autosmoothing:                                                            */
  /* ------------------------------------------------------------------------- */
@@@ -1477,7 -1565,7 +1477,7 @@@ static int render_new_particle_system(R
        float hasize, pa_size, pa_time, r_tilt, cfra=bsystem_time(ob,(float)CFRA,0.0);
        float adapt_angle=0.0, adapt_pix=0.0, random, simplify[2];
        int i, a, k, max_k=0, totpart, totuv=0, totcol=0, override_uv=-1, dosimplify = 0, dosurfacecache = 0;
-       int path_possible=0, keys_possible=0, baked_keys=0, totchild=psys->totchild;
+       int path_possible=0, keys_possible=0, baked_keys=0, totchild=0;
        int seed, path_nbr=0, path=0, orco1=0, adapt=0, uv[3]={0,0,0}, num;
        int totface, *origindex = 0;
        char **uv_name=0;
  /* 1. check that everything is ok & updated */
        if(psys==NULL)
                return 0;
+       
+       totchild=psys->totchild;
  
        part=psys->part;
        pars=psys->particles;
@@@ -3091,6 -3181,12 +3093,6 @@@ static void init_render_mesh(Render *re
                }
        }
  
 -      if((ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) &&
 -               (ob->fluidsimSettings->type & OB_FLUIDSIM_DOMAIN)&&
 -         (ob->fluidsimSettings->meshSurface) ) {
 -              useFluidmeshNormals = 1;
 -      }
 -
        mvert= dm->getVertArray(dm);
        totvert= dm->getNumVerts(dm);
  
                        if(do_autosmooth==0)    /* autosmooth on original unrotated data to prevent differences between frames */
                                MTC_Mat4MulVecfl(mat, ver->co);
    
 -                      if(useFluidmeshNormals) {
 -                              /* normals are inverted in render */
 -                              xn = -mvert->no[0]/ 32767.0;
 -                              yn = -mvert->no[1]/ 32767.0;
 -                              zn = -mvert->no[2]/ 32767.0;
 -                              /* transfor to cam  space */
 -                              ver->n[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn;
 -                              ver->n[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn;
 -                              ver->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn;
 -                      } // useFluidmeshNormals
 -
                        if(orco) {
                                ver->orco= orco;
                                orco+=3;
                        autosmooth(re, obr, mat, me->smoothresh);
                }
  
 -              if(useFluidmeshNormals) {
 -                      // do not recalculate, only init render data
 -                      calc_fluidsimnormals(re, obr, need_tangent||need_nmap_tangent);
 -              } else {
 -                      calc_vertexnormals(re, obr, need_tangent, need_nmap_tangent);
 -              }
 +              calc_vertexnormals(re, obr, need_tangent, need_nmap_tangent);
  
                if(need_stress)
                        calc_edge_stress(re, obr, me);
@@@ -5171,7 -5283,7 +5173,7 @@@ static int load_fluidsimspeedvectors(Re
                //fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.; fsvec[2] = 2.; // NT fixed test
                for(j=0;j<3;j++) fsvec[j] = vverts[a].co[j];
                
 -              /* (bad) HACK insert average velocity if none is there (see previous comment */
 +              /* (bad) HACK insert average velocity if none is there (see previous comment) */
                if((fsvec[0] == 0.0) && (fsvec[1] == 0.0) && (fsvec[2] == 0.0))
                {
                        fsvec[0] = avgvel[0];
@@@ -5315,7 -5427,6 +5317,7 @@@ void RE_Database_FromScene_Vectors(Rend
                        oldobi= table->first;
                        for(obi= re->instancetable.first; obi && oldobi; obi= obi->next) {
                                int ok= 1;
 +                              FluidsimModifierData *fluidmd;
  
                                if(!(obi->obr->flag & R_NEED_VECTORS))
                                        continue;
                                }
  
                                // NT check for fluidsim special treatment
 -                              if((obi->ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) && (obi->ob->fluidsimSettings->type & OB_FLUIDSIM_DOMAIN)) {
 +                              fluidmd = (FluidsimModifierData *)modifiers_findByType(obi->ob, eModifierType_Fluidsim);
 +                              if(fluidmd && fluidmd->fss && (fluidmd->fss->type & OB_FLUIDSIM_DOMAIN)) {
                                        // use preloaded per vertex simulation data , only does calculation for step=1
                                        // NOTE/FIXME - velocities and meshes loaded unnecessarily often during the database_fromscene_vectors calls...
                                        load_fluidsimspeedvectors(re, obi, oldobi->vectors, step);