svn merge -r 15800:15973 https://svn.blender.org/svnroot/bf-blender/trunk/blender
authorDaniel Genrich <daniel.genrich@gmx.net>
Tue, 5 Aug 2008 16:12:40 +0000 (16:12 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Tue, 5 Aug 2008 16:12:40 +0000 (16:12 +0000)
1  2 
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/render/intern/source/convertblender.c
source/blender/src/buttons_editing.c
source/blender/src/buttons_object.c
source/blender/src/editipo.c
source/blender/src/header_ipo.c

index 2ec8199979841d06fbeb8bd869626a3f3b66eab4,67cf89d5ee26de6b964e499eedfd6975b05a9e83..3772c2d06aec9b6903da4a6486bc475cd8d2f65c
@@@ -2814,4 -2845,703 +2815,124 @@@ int editmesh_get_first_deform_matrices(
        return numleft;
  }
  
+ void DM_add_tangent_layer(DerivedMesh *dm)
+ {
+       /* mesh vars */
+       MTFace *mtface, *tf;
+       MFace *mface, *mf;
+       MVert *mvert, *v1, *v2, *v3, *v4;
+       MemArena *arena= NULL;
+       VertexTangent **vtangents= NULL;
+       float (*orco)[3]= NULL, (*tangent)[3];
+       float *uv1, *uv2, *uv3, *uv4, *vtang;
+       float fno[3], tang[3], uv[4][2];
+       int i, j, len, mf_vi[4], totvert, totface;
+       if(CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1)
+               return;
+       /* check we have all the needed layers */
+       totvert= dm->getNumVerts(dm);
+       totface= dm->getNumFaces(dm);
+       mvert= dm->getVertArray(dm);
+       mface= dm->getFaceArray(dm);
+       mtface= dm->getFaceDataArray(dm, CD_MTFACE);
+       if(!mtface) {
+               orco= dm->getVertDataArray(dm, CD_ORCO);
+               if(!orco)
+                       return;
+       }
+       
+       /* create tangent layer */
+       DM_add_face_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
+       tangent= DM_get_face_data_layer(dm, CD_TANGENT);
+       
+       /* allocate some space */
+       arena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
+       BLI_memarena_use_calloc(arena);
+       vtangents= MEM_callocN(sizeof(VertexTangent*)*totvert, "VertexTangent");
+       
+       /* sum tangents at connected vertices */
+       for(i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++) {
+               v1= &mvert[mf->v1];
+               v2= &mvert[mf->v2];
+               v3= &mvert[mf->v3];
+               if (mf->v4) {
+                       v4= &mvert[mf->v4];
+                       CalcNormFloat4(v4->co, v3->co, v2->co, v1->co, fno);
+               }
+               else {
+                       v4= NULL;
+                       CalcNormFloat(v3->co, v2->co, v1->co, fno);
+               }
+               
+               if(mtface) {
+                       uv1= tf->uv[0];
+                       uv2= tf->uv[1];
+                       uv3= tf->uv[2];
+                       uv4= tf->uv[3];
+               }
+               else {
+                       uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3];
+                       spheremap(orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2], &uv[0][0], &uv[0][1]);
+                       spheremap(orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2], &uv[1][0], &uv[1][1]);
+                       spheremap(orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2], &uv[2][0], &uv[2][1]);
+                       if(v4)
+                               spheremap(orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2], &uv[3][0], &uv[3][1]);
+               }
+               
+               tangent_from_uv(uv1, uv2, uv3, v1->co, v2->co, v3->co, fno, tang);
+               sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1);
+               sum_or_add_vertex_tangent(arena, &vtangents[mf->v2], tang, uv2);
+               sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3);
+               
+               if(mf->v4) {
+                       v4= &mvert[mf->v4];
+                       
+                       tangent_from_uv(uv1, uv3, uv4, v1->co, v3->co, v4->co, fno, tang);
+                       sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1);
+                       sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3);
+                       sum_or_add_vertex_tangent(arena, &vtangents[mf->v4], tang, uv4);
+               }
+       }
+       
+       /* write tangent to layer */
+       for(i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++, tangent+=4) {
+               len= (mf->v4)? 4 : 3; 
+               
+               if(mtface) {
+                       uv1= tf->uv[0];
+                       uv2= tf->uv[1];
+                       uv3= tf->uv[2];
+                       uv4= tf->uv[3];
+               }
+               else {
+                       uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3];
+                       spheremap(orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2], &uv[0][0], &uv[0][1]);
+                       spheremap(orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2], &uv[1][0], &uv[1][1]);
+                       spheremap(orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2], &uv[2][0], &uv[2][1]);
+                       if(len==4)
+                               spheremap(orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2], &uv[3][0], &uv[3][1]);
+               }
+               
+               mf_vi[0]= mf->v1;
+               mf_vi[1]= mf->v2;
+               mf_vi[2]= mf->v3;
+               mf_vi[3]= mf->v4;
+               
+               for(j=0; j<len; j++) {
+                       vtang= find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]);
+                       VECCOPY(tangent[j], vtang);
+                       Normalize(tangent[j]);
+               }
+       }
+       
+       BLI_memarena_free(arena);
+       MEM_freeN(vtangents);
+ }
  
 -/* ************************* fluidsim bobj file handling **************************** */
 -
 -#ifndef DISABLE_ELBEEM
 -
 -#ifdef WIN32
 -#ifndef snprintf
 -#define snprintf _snprintf
 -#endif
 -#endif
 -
 -/* write .bobj.gz file for a mesh object */
 -void writeBobjgz(char *filename, struct Object *ob, int useGlobalCoords, int append, float time) 
 -{
 -      char debugStrBuffer[256];
 -      int wri,i,j,totvert,totface;
 -      float wrf;
 -      gzFile gzf;
 -      DerivedMesh *dm;
 -      float vec[3];
 -      float rotmat[3][3];
 -      MVert *mvert;
 -      MFace *mface;
 -      //if(append)return; // DEBUG
 -
 -      if(!ob->data || (ob->type!=OB_MESH)) {
 -              snprintf(debugStrBuffer,256,"Writing GZ_BOBJ Invalid object %s ...\n", ob->id.name); 
 -              elbeemDebugOut(debugStrBuffer);
 -              return;
 -      }
 -      if((ob->size[0]<0.0) || (ob->size[0]<0.0) || (ob->size[0]<0.0) ) {
 -              snprintf(debugStrBuffer,256,"\nfluidSim::writeBobjgz:: Warning object %s has negative scaling - check triangle ordering...?\n\n", ob->id.name); 
 -              elbeemDebugOut(debugStrBuffer);
 -      }
 -
 -      snprintf(debugStrBuffer,256,"Writing GZ_BOBJ '%s' ... ",filename); elbeemDebugOut(debugStrBuffer); 
 -      if(append) gzf = gzopen(filename, "a+b9");
 -      else       gzf = gzopen(filename, "wb9");
 -      if (!gzf) {
 -              snprintf(debugStrBuffer,256,"writeBobjgz::error - Unable to open file for writing '%s'\n", filename);
 -              elbeemDebugOut(debugStrBuffer);
 -              return;
 -      }
 -
 -      dm = mesh_create_derived_render(ob, CD_MASK_BAREMESH);
 -      //dm = mesh_create_derived_no_deform(ob,NULL);
 -
 -      mvert = dm->getVertArray(dm);
 -      mface = dm->getFaceArray(dm);
 -      totvert = dm->getNumVerts(dm);
 -      totface = dm->getNumFaces(dm);
 -
 -      // write time value for appended anim mesh
 -      if(append) {
 -              gzwrite(gzf, &time, sizeof(time));
 -      }
 -
 -      // continue with verts/norms
 -      if(sizeof(wri)!=4) { snprintf(debugStrBuffer,256,"Writing GZ_BOBJ, Invalid int size %d...\n", wri); elbeemDebugOut(debugStrBuffer); return; } // paranoia check
 -      wri = dm->getNumVerts(dm);
 -      mvert = dm->getVertArray(dm);
 -      gzwrite(gzf, &wri, sizeof(wri));
 -      for(i=0; i<wri;i++) {
 -              VECCOPY(vec, mvert[i].co);
 -              if(useGlobalCoords) { Mat4MulVecfl(ob->obmat, vec); }
 -              for(j=0; j<3; j++) {
 -                      wrf = vec[j]; 
 -                      gzwrite(gzf, &wrf, sizeof( wrf )); 
 -              }
 -      }
 -
 -      // should be the same as Vertices.size
 -      wri = totvert;
 -      gzwrite(gzf, &wri, sizeof(wri));
 -      EulToMat3(ob->rot, rotmat);
 -      for(i=0; i<wri;i++) {
 -              VECCOPY(vec, mvert[i].no);
 -              Normalize(vec);
 -              if(useGlobalCoords) { Mat3MulVecfl(rotmat, vec); }
 -              for(j=0; j<3; j++) {
 -                      wrf = vec[j];
 -                      gzwrite(gzf, &wrf, sizeof( wrf )); 
 -              }
 -      }
 -
 -      // append only writes verts&norms 
 -      if(!append) {
 -              //float side1[3],side2[3],norm1[3],norm2[3];
 -              //float inpf;
 -      
 -              // compute no. of triangles 
 -              wri = 0;
 -              for(i=0; i<totface; i++) {
 -                      wri++;
 -                      if(mface[i].v4) { wri++; }
 -              }
 -              gzwrite(gzf, &wri, sizeof(wri));
 -              for(i=0; i<totface; i++) {
 -
 -                      int face[4];
 -                      face[0] = mface[i].v1;
 -                      face[1] = mface[i].v2;
 -                      face[2] = mface[i].v3;
 -                      face[3] = mface[i].v4;
 -                      //snprintf(debugStrBuffer,256,"F %s %d = %d,%d,%d,%d \n",ob->id.name, i, face[0],face[1],face[2],face[3] ); elbeemDebugOut(debugStrBuffer);
 -                      //VecSubf(side1, mvert[face[1]].co,mvert[face[0]].co);
 -                      //VecSubf(side2, mvert[face[2]].co,mvert[face[0]].co);
 -                      //Crossf(norm1,side1,side2);
 -                      gzwrite(gzf, &(face[0]), sizeof( face[0] )); 
 -                      gzwrite(gzf, &(face[1]), sizeof( face[1] )); 
 -                      gzwrite(gzf, &(face[2]), sizeof( face[2] )); 
 -                      if(face[3]) { 
 -                              //VecSubf(side1, mvert[face[2]].co,mvert[face[0]].co);
 -                              //VecSubf(side2, mvert[face[3]].co,mvert[face[0]].co);
 -                              //Crossf(norm2,side1,side2);
 -                              //inpf = Inpf(norm1,norm2);
 -                              //if(inpf>0.) {
 -                              gzwrite(gzf, &(face[0]), sizeof( face[0] )); 
 -                              gzwrite(gzf, &(face[2]), sizeof( face[2] )); 
 -                              gzwrite(gzf, &(face[3]), sizeof( face[3] )); 
 -                              //} else {
 -                                      //gzwrite(gzf, &(face[0]), sizeof( face[0] )); 
 -                                      //gzwrite(gzf, &(face[3]), sizeof( face[3] )); 
 -                                      //gzwrite(gzf, &(face[2]), sizeof( face[2] )); 
 -                              //}
 -                      } // quad
 -              }
 -      }
 -
 -      snprintf(debugStrBuffer,256,"Done. #Vertices: %d, #Triangles: %d\n", totvert, totface ); 
 -      elbeemDebugOut(debugStrBuffer);
 -      
 -      gzclose( gzf );
 -      dm->release(dm);
 -}
 -
 -void initElbeemMesh(struct Object *ob, 
 -              int *numVertices, float **vertices, 
 -              int *numTriangles, int **triangles,
 -              int useGlobalCoords) 
 -{
 -      DerivedMesh *dm = NULL;
 -      MVert *mvert;
 -      MFace *mface;
 -      int countTris=0, i, totvert, totface;
 -      float *verts;
 -      int *tris;
 -
 -      dm = mesh_create_derived_render(ob, CD_MASK_BAREMESH);
 -      //dm = mesh_create_derived_no_deform(ob,NULL);
 -
 -      mvert = dm->getVertArray(dm);
 -      mface = dm->getFaceArray(dm);
 -      totvert = dm->getNumVerts(dm);
 -      totface = dm->getNumFaces(dm);
 -
 -      *numVertices = totvert;
 -      verts = MEM_callocN( totvert*3*sizeof(float), "elbeemmesh_vertices");
 -      for(i=0; i<totvert; i++) {
 -              VECCOPY( &verts[i*3], mvert[i].co);
 -              if(useGlobalCoords) { Mat4MulVecfl(ob->obmat, &verts[i*3]); }
 -      }
 -      *vertices = verts;
 -
 -      for(i=0; i<totface; i++) {
 -              countTris++;
 -              if(mface[i].v4) { countTris++; }
 -      }
 -      *numTriangles = countTris;
 -      tris = MEM_callocN( countTris*3*sizeof(int), "elbeemmesh_triangles");
 -      countTris = 0;
 -      for(i=0; i<totface; i++) {
 -              int face[4];
 -              face[0] = mface[i].v1;
 -              face[1] = mface[i].v2;
 -              face[2] = mface[i].v3;
 -              face[3] = mface[i].v4;
 -
 -              tris[countTris*3+0] = face[0]; 
 -              tris[countTris*3+1] = face[1]; 
 -              tris[countTris*3+2] = face[2]; 
 -              countTris++;
 -              if(face[3]) { 
 -                      tris[countTris*3+0] = face[0]; 
 -                      tris[countTris*3+1] = face[2]; 
 -                      tris[countTris*3+2] = face[3]; 
 -                      countTris++;
 -              }
 -      }
 -      *triangles = tris;
 -
 -      dm->release(dm);
 -}
 -
 -/* read .bobj.gz file into a fluidsimDerivedMesh struct */
 -Mesh* readBobjgz(char *filename, Mesh *orgmesh, float* bbstart, float *bbsize) //, fluidsimDerivedMesh *fsdm)
 -{
 -      int wri,i,j;
 -      char debugStrBuffer[256];
 -      float wrf;
 -      Mesh *newmesh; 
 -      const int debugBobjRead = 1;
 -      // init data from old mesh (materials,flags)
 -      MFace *origMFace = &((MFace*) orgmesh->mface)[0];
 -      int mat_nr = -1;
 -      int flag = -1;
 -      MFace *fsface = NULL;
 -      int gotBytes;
 -      gzFile gzf;
 -
 -      if(!orgmesh) return NULL;
 -      if(!origMFace) return NULL;
 -      mat_nr = origMFace->mat_nr;
 -      flag = origMFace->flag;
 -
 -      // similar to copy_mesh
 -      newmesh = MEM_dupallocN(orgmesh);
 -      newmesh->mat= orgmesh->mat;
 -
 -      newmesh->mvert= NULL;
 -      newmesh->medge= NULL;
 -      newmesh->mface= NULL;
 -      newmesh->mtface= NULL;
 -
 -      newmesh->dvert = NULL;
 -
 -      newmesh->mcol= NULL;
 -      newmesh->msticky= NULL;
 -      newmesh->texcomesh= NULL;
 -      memset(&newmesh->vdata, 0, sizeof(newmesh->vdata));
 -      memset(&newmesh->edata, 0, sizeof(newmesh->edata));
 -      memset(&newmesh->fdata, 0, sizeof(newmesh->fdata));
 -
 -      newmesh->key= NULL;
 -      newmesh->totface = 0;
 -      newmesh->totvert = 0;
 -      newmesh->totedge = 0;
 -      newmesh->medge = NULL;
 -
 -
 -      snprintf(debugStrBuffer,256,"Reading '%s' GZ_BOBJ... ",filename); elbeemDebugOut(debugStrBuffer); 
 -      gzf = gzopen(filename, "rb");
 -      // gzf = fopen(filename, "rb");
 -      // debug: fread(b,c,1,a) = gzread(a,b,c)
 -      if (!gzf) {
 -              //snprintf(debugStrBuffer,256,"readBobjgz::error - Unable to open file for reading '%s'\n", filename); // DEBUG
 -              MEM_freeN(newmesh);
 -              return NULL;
 -      }
 -
 -      //if(sizeof(wri)!=4) { snprintf(debugStrBuffer,256,"Reading GZ_BOBJ, Invalid int size %d...\n", wri); return NULL; } // paranoia check
 -      gotBytes = gzread(gzf, &wri, sizeof(wri));
 -      newmesh->totvert = wri;
 -      newmesh->mvert = CustomData_add_layer(&newmesh->vdata, CD_MVERT, CD_CALLOC, NULL, newmesh->totvert);
 -      if(debugBobjRead){ snprintf(debugStrBuffer,256,"#vertices %d ", newmesh->totvert); elbeemDebugOut(debugStrBuffer); } //DEBUG
 -      for(i=0; i<newmesh->totvert;i++) {
 -              //if(debugBobjRead) snprintf(debugStrBuffer,256,"V %d = ",i);
 -              for(j=0; j<3; j++) {
 -                      gotBytes = gzread(gzf, &wrf, sizeof( wrf )); 
 -                      newmesh->mvert[i].co[j] = wrf;
 -                      //if(debugBobjRead) snprintf(debugStrBuffer,256,"%25.20f ", wrf);
 -              }
 -              //if(debugBobjRead) snprintf(debugStrBuffer,256,"\n");
 -      }
 -
 -      // should be the same as Vertices.size
 -      gotBytes = gzread(gzf, &wri, sizeof(wri));
 -      if(wri != newmesh->totvert) {
 -              // complain #vertices has to be equal to #normals, reset&abort
 -              CustomData_free_layer_active(&newmesh->vdata, CD_MVERT, newmesh->totvert);
 -              MEM_freeN(newmesh);
 -              snprintf(debugStrBuffer,256,"Reading GZ_BOBJ, #normals=%d, #vertices=%d, aborting...\n", wri,newmesh->totvert );
 -              return NULL;
 -      }
 -      for(i=0; i<newmesh->totvert;i++) {
 -              for(j=0; j<3; j++) {
 -                      gotBytes = gzread(gzf, &wrf, sizeof( wrf )); 
 -                      newmesh->mvert[i].no[j] = (short)(wrf*32767.0f);
 -                      //newmesh->mvert[i].no[j] = 0.5; // DEBUG tst
 -              }
 -      //fprintf(stderr,"  DEBDPCN nm%d, %d = %d,%d,%d \n",
 -                      //(int)(newmesh->mvert), i, newmesh->mvert[i].no[0], newmesh->mvert[i].no[1], newmesh->mvert[i].no[2]);
 -      }
 -      //fprintf(stderr,"  DPCN 0 = %d,%d,%d \n", newmesh->mvert[0].no[0], newmesh->mvert[0].no[1], newmesh->mvert[0].no[2]);
 -
 -      
 -      /* compute no. of triangles */
 -      gotBytes = gzread(gzf, &wri, sizeof(wri));
 -      newmesh->totface = wri;
 -      newmesh->mface = CustomData_add_layer(&newmesh->fdata, CD_MFACE, CD_CALLOC, NULL, newmesh->totface);
 -      if(debugBobjRead){ snprintf(debugStrBuffer,256,"#faces %d ", newmesh->totface); elbeemDebugOut(debugStrBuffer); } //DEBUG
 -      fsface = newmesh->mface;
 -      for(i=0; i<newmesh->totface; i++) {
 -              int face[4];
 -
 -              gotBytes = gzread(gzf, &(face[0]), sizeof( face[0] )); 
 -              gotBytes = gzread(gzf, &(face[1]), sizeof( face[1] )); 
 -              gotBytes = gzread(gzf, &(face[2]), sizeof( face[2] )); 
 -              face[3] = 0;
 -
 -              fsface[i].v1 = face[0];
 -              fsface[i].v2 = face[1];
 -              fsface[i].v3 = face[2];
 -              fsface[i].v4 = face[3];
 -      }
 -
 -      // correct triangles with v3==0 for blender, cycle verts
 -      for(i=0; i<newmesh->totface; i++) {
 -              if(!fsface[i].v3) {
 -                      int temp = fsface[i].v1;
 -                      fsface[i].v1 = fsface[i].v2;
 -                      fsface[i].v2 = fsface[i].v3;
 -                      fsface[i].v3 = temp;
 -              }
 -      }
 -      
 -      gzclose( gzf );
 -      for(i=0;i<newmesh->totface;i++) { 
 -              fsface[i].mat_nr = mat_nr;
 -              fsface[i].flag = flag;
 -              fsface[i].edcode = ME_V1V2 | ME_V2V3 | ME_V3V1;
 -              //snprintf(debugStrBuffer,256,"%d : %d,%d,%d\n", i,fsface[i].mat_nr, fsface[i].flag, fsface[i].edcode );
 -      }
 -
 -      snprintf(debugStrBuffer,256," (%d,%d) done\n", newmesh->totvert,newmesh->totface); elbeemDebugOut(debugStrBuffer); //DEBUG
 -      return newmesh;
 -}
 -
 -/* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */
 -void readVelgz(char *filename, Object *srcob)
 -{
 -      char debugStrBuffer[256];
 -      int wri, i, j;
 -      float wrf;
 -      gzFile gzf;
 -      MVert *vverts = srcob->fluidsimSettings->meshSurfNormals;
 -      int len = strlen(filename);
 -      Mesh *mesh = srcob->data;
 -      // mesh and vverts have to be valid from loading...
 -
 -      // clean up in any case
 -      for(i=0; i<mesh->totvert;i++) { 
 -              for(j=0; j<3; j++) {
 -                      vverts[i].co[j] = 0.; 
 -              } 
 -      } 
 -      if(srcob->fluidsimSettings->domainNovecgen>0) return;
 -
 -      if(len<7) { 
 -              //printf("readVelgz Eror: invalid filename '%s'\n",filename); // DEBUG
 -              return; 
 -      }
 -
 -      // .bobj.gz , correct filename
 -      // 87654321
 -      filename[len-6] = 'v';
 -      filename[len-5] = 'e';
 -      filename[len-4] = 'l';
 -
 -      snprintf(debugStrBuffer,256,"Reading '%s' GZ_VEL... ",filename); elbeemDebugOut(debugStrBuffer); 
 -      gzf = gzopen(filename, "rb");
 -      if (!gzf) { 
 -              //printf("readVelgz Eror: unable to open file '%s'\n",filename); // DEBUG
 -              return; 
 -      }
 -
 -      gzread(gzf, &wri, sizeof( wri ));
 -      if(wri != mesh->totvert) {
 -              //printf("readVelgz Eror: invalid no. of velocities %d vs. %d aborting.\n" ,wri ,mesh->totvert ); // DEBUG
 -              return; 
 -      }
 -
 -      for(i=0; i<mesh->totvert;i++) {
 -              for(j=0; j<3; j++) {
 -                      gzread(gzf, &wrf, sizeof( wrf )); 
 -                      vverts[i].co[j] = wrf;
 -              }
 -              //if(i<20) fprintf(stderr, "GZ_VELload %d = %f,%f,%f  \n",i,vverts[i].co[0],vverts[i].co[1],vverts[i].co[2]); // DEBUG
 -      }
 -
 -      gzclose(gzf);
 -}
 -
 -
 -/* ***************************** fluidsim derived mesh ***************************** */
 -
 -/* check which file to load, and replace old mesh of the object with it */
 -/* this replacement is undone at the end of mesh_calc_modifiers */
 -void loadFluidsimMesh(Object *srcob, int useRenderParams)
 -{
 -      Mesh *mesh = NULL;
 -      float *bbStart = NULL, *bbSize = NULL;
 -      float lastBB[3];
 -      int displaymode = 0;
 -      int curFrame = G.scene->r.cfra - 1 /*G.scene->r.sfra*/; /* start with 0 at start frame */
 -      char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR];
 -      char debugStrBuffer[256];
 -      //snprintf(debugStrBuffer,256,"loadFluidsimMesh call (obid '%s', rp %d)\n", srcob->id.name, useRenderParams); // debug
 -
 -      if((!srcob)||(!srcob->fluidsimSettings)) {
 -              snprintf(debugStrBuffer,256,"DEBUG - Invalid loadFluidsimMesh call, rp %d, dm %d)\n", useRenderParams, displaymode); // debug
 -              elbeemDebugOut(debugStrBuffer); // debug
 -              return;
 -      }
 -      // make sure the original mesh data pointer is stored
 -      if(!srcob->fluidsimSettings->orgMesh) {
 -              srcob->fluidsimSettings->orgMesh = srcob->data;
 -      }
 -
 -      // free old mesh, if there is one (todo, check if it's still valid?)
 -      if(srcob->fluidsimSettings->meshSurface) {
 -              Mesh *freeFsMesh = srcob->fluidsimSettings->meshSurface;
 -
 -              // similar to free_mesh(...) , but no things like unlink...
 -              CustomData_free(&freeFsMesh->vdata, freeFsMesh->totvert);
 -              CustomData_free(&freeFsMesh->edata, freeFsMesh->totedge);
 -              CustomData_free(&freeFsMesh->fdata, freeFsMesh->totface);
 -              MEM_freeN(freeFsMesh);
 -              
 -              if(srcob->data == srcob->fluidsimSettings->meshSurface)
 -               srcob->data = srcob->fluidsimSettings->orgMesh;
 -              srcob->fluidsimSettings->meshSurface = NULL;
 -
 -              if(srcob->fluidsimSettings->meshSurfNormals) MEM_freeN(srcob->fluidsimSettings->meshSurfNormals);
 -              srcob->fluidsimSettings->meshSurfNormals = NULL;
 -      } 
 -
 -      // init bounding box
 -      bbStart = srcob->fluidsimSettings->bbStart; 
 -      bbSize = srcob->fluidsimSettings->bbSize;
 -      lastBB[0] = bbSize[0];  // TEST
 -      lastBB[1] = bbSize[1]; 
 -      lastBB[2] = bbSize[2];
 -      fluidsimGetAxisAlignedBB(srcob->fluidsimSettings->orgMesh, srcob->obmat, bbStart, bbSize, &srcob->fluidsimSettings->meshBB);
 -      // check free fsmesh... TODO
 -      
 -      if(!useRenderParams) {
 -              displaymode = srcob->fluidsimSettings->guiDisplayMode;
 -      } else {
 -              displaymode = srcob->fluidsimSettings->renderDisplayMode;
 -      }
 -      
 -      snprintf(debugStrBuffer,256,"loadFluidsimMesh call (obid '%s', rp %d, dm %d), curFra=%d, sFra=%d #=%d \n", 
 -                      srcob->id.name, useRenderParams, displaymode, G.scene->r.cfra, G.scene->r.sfra, curFrame ); // debug
 -      elbeemDebugOut(debugStrBuffer); // debug
 -
 -      strncpy(targetDir, srcob->fluidsimSettings->surfdataPath, FILE_MAXDIR);
 -      // use preview or final mesh?
 -      if(displaymode==1) {
 -              // just display original object
 -              srcob->data = srcob->fluidsimSettings->orgMesh;
 -              return;
 -      } else if(displaymode==2) {
 -              strcat(targetDir,"fluidsurface_preview_####");
 -      } else { // 3
 -              strcat(targetDir,"fluidsurface_final_####");
 -      }
 -      BLI_convertstringcode(targetDir, G.sce);
 -      BLI_convertstringframe(targetDir, curFrame); // fixed #frame-no 
 -      
 -      strcpy(targetFile,targetDir);
 -      strcat(targetFile, ".bobj.gz");
 -
 -      snprintf(debugStrBuffer,256,"loadFluidsimMesh call (obid '%s', rp %d, dm %d) '%s' \n", srcob->id.name, useRenderParams, displaymode, targetFile);  // debug
 -      elbeemDebugOut(debugStrBuffer); // debug
 -
 -      if(displaymode!=2) { // dont add bounding box for final
 -              mesh = readBobjgz(targetFile, srcob->fluidsimSettings->orgMesh ,NULL,NULL);
 -      } else {
 -              mesh = readBobjgz(targetFile, srcob->fluidsimSettings->orgMesh, bbSize,bbSize );
 -      }
 -      if(!mesh) {
 -              // switch, abort background rendering when fluidsim mesh is missing
 -              const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp
 -              if(G.background==1) {
 -                      if(getenv(strEnvName2)) {
 -                              int elevel = atoi(getenv(strEnvName2));
 -                              if(elevel>0) {
 -                                      printf("Env. var %s set, fluid sim mesh '%s' not found, aborting render...\n",strEnvName2, targetFile);
 -                                      exit(1);
 -                              }
 -                      }
 -              }
 -              
 -              // display org. object upon failure
 -              srcob->data = srcob->fluidsimSettings->orgMesh;
 -              return;
 -      }
 -
 -      if((mesh)&&(mesh->totvert>0)) {
 -              make_edges(mesh, 0);    // 0 = make all edges draw
 -      }
 -      srcob->fluidsimSettings->meshSurface = mesh;
 -      srcob->data = mesh;
 -      srcob->fluidsimSettings->meshSurfNormals = MEM_dupallocN(mesh->mvert);
 -
 -      // load vertex velocities, if they exist...
 -      // TODO? use generate flag as loading flag as well?
 -      // warning, needs original .bobj.gz mesh loading filename
 -      if(displaymode==3) {
 -              readVelgz(targetFile, srcob);
 -      } else {
 -              // no data for preview, only clear...
 -              int i,j;
 -              for(i=0; i<mesh->totvert;i++) { for(j=0; j<3; j++) { srcob->fluidsimSettings->meshSurfNormals[i].co[j] = 0.; }} 
 -      }
 -
 -      //fprintf(stderr,"LOADFLM DEBXHCH fs=%d 3:%d,%d,%d \n", (int)mesh, ((Mesh *)(srcob->fluidsimSettings->meshSurface))->mvert[3].no[0], ((Mesh *)(srcob->fluidsimSettings->meshSurface))->mvert[3].no[1], ((Mesh *)(srcob->fluidsimSettings->meshSurface))->mvert[3].no[2]);
 -      return;
 -}
 -
 -/* helper function */
 -/* init axis aligned BB for mesh object */
 -void fluidsimGetAxisAlignedBB(struct Mesh *mesh, float obmat[][4],
 -               /*RET*/ float start[3], /*RET*/ float size[3], /*RET*/ struct Mesh **bbmesh )
 -{
 -      float bbsx=0.0, bbsy=0.0, bbsz=0.0;
 -      float bbex=1.0, bbey=1.0, bbez=1.0;
 -      int i;
 -      float vec[3];
 -
 -      VECCOPY(vec, mesh->mvert[0].co); 
 -      Mat4MulVecfl(obmat, vec);
 -      bbsx = vec[0]; bbsy = vec[1]; bbsz = vec[2];
 -      bbex = vec[0]; bbey = vec[1]; bbez = vec[2];
 -
 -      for(i=1; i<mesh->totvert;i++) {
 -              VECCOPY(vec, mesh->mvert[i].co);
 -              Mat4MulVecfl(obmat, vec);
 -
 -              if(vec[0] < bbsx){ bbsx= vec[0]; }
 -              if(vec[1] < bbsy){ bbsy= vec[1]; }
 -              if(vec[2] < bbsz){ bbsz= vec[2]; }
 -              if(vec[0] > bbex){ bbex= vec[0]; }
 -              if(vec[1] > bbey){ bbey= vec[1]; }
 -              if(vec[2] > bbez){ bbez= vec[2]; }
 -      }
 -
 -      // return values...
 -      if(start) {
 -              start[0] = bbsx;
 -              start[1] = bbsy;
 -              start[2] = bbsz;
 -      } 
 -      if(size) {
 -              size[0] = bbex-bbsx;
 -              size[1] = bbey-bbsy;
 -              size[2] = bbez-bbsz;
 -      }
 -
 -      // init bounding box mesh?
 -      if(bbmesh) {
 -              int i,j;
 -              Mesh *newmesh = NULL;
 -              if(!(*bbmesh)) { newmesh = MEM_callocN(sizeof(Mesh), "fluidsimGetAxisAlignedBB_meshbb"); }
 -              else {           newmesh = *bbmesh; }
 -
 -              newmesh->totvert = 8;
 -              if(!newmesh->mvert)
 -                      newmesh->mvert = CustomData_add_layer(&newmesh->vdata, CD_MVERT, CD_CALLOC, NULL, newmesh->totvert);
 -              for(i=0; i<8; i++) {
 -                      for(j=0; j<3; j++) newmesh->mvert[i].co[j] = start[j]; 
 -              }
 -
 -              newmesh->totface = 6;
 -              if(!newmesh->mface)
 -                      newmesh->mface = CustomData_add_layer(&newmesh->fdata, CD_MFACE, CD_CALLOC, NULL, newmesh->totface);
 -
 -              *bbmesh = newmesh;
 -      }
 -}
 -
 -#else // DISABLE_ELBEEM
 -
 -/* dummy for mesh_calc_modifiers */
 -void loadFluidsimMesh(Object *srcob, int useRenderParams) {
 -}
 -
 -#endif // DISABLE_ELBEEM
 -
index 82269357b24069464fffd59e1ea4edc69e073233,ad19cde3c9ba963ad5700bd4cdb848b396056286..55106420cc66a3b49d9d8697dcb5069ca1699b73
@@@ -7729,29 -7774,14 +7773,36 @@@ static void do_versions(FileData *fd, L
                        la->sun_intensity = 1.0;
                }
        }
 +      
 +      // convert fluids to modifier
 +      if(main->versionfile <= 246 && main->subversionfile < 1)
 +      {
 +              Object *ob;
 +              
 +              for(ob = main->object.first; ob; ob= ob->id.next) {
 +                      if(ob->fluidsimSettings)
 +                      {
 +                              FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifier_new(eModifierType_Fluidsim);
 +                              BLI_addhead(&ob->modifiers, (ModifierData *)fluidmd);
 +                              
 +                              MEM_freeN(fluidmd->fss);
 +                              fluidmd->fss = MEM_dupallocN(ob->fluidsimSettings);
 +                              fluidmd->fss->ipo = newlibadr_us(fd, ob->id.lib, ob->fluidsimSettings->ipo);
 +                              MEM_freeN(ob->fluidsimSettings);
 +                              
 +                              fluidmd->fss->lastgoodframe = INT_MAX;
 +                      }
 +              }
 +      }
 +      
  
+       if(main->versionfile <= 246 && main->subversionfile < 1){
+               Mesh *me;
+               for(me=main->mesh.first; me; me= me->id.next)
+                       alphasort_version_246(fd, lib, me);
+       }
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
  
Simple merge
Simple merge
index 6f532e5d3d28f6e6745aa85adac0b72d66284995,63c301658f2232e9c85db24a5a40b48f7d20434b..b9ca228d737cb01784e1d5c96bfaf702bc8c25d1
@@@ -83,8 -82,8 +83,9 @@@
  #include "BKE_group.h"
  #include "BKE_ipo.h"
  #include "BKE_key.h"
+ #include "BKE_main.h"
  #include "BKE_material.h"
 +#include "BKE_modifier.h"
  #include "BKE_particle.h"
  #include "BKE_texture.h"
  #include "BKE_utildefines.h"
Simple merge