diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 7392dfbd7d3..eb556e31aba 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -169,15 +169,15 @@ void fluidsim_free(FluidsimModifierData *fluidmd) /* read .bobj.gz file into a fluidsimDerivedMesh struct */ DerivedMesh *fluidsim_read_obj(char *filename) { - int wri = 0,i,j; - float wrf; + int wri = 0,i; int gotBytes; gzFile gzf; int numverts = 0, numfaces = 0; DerivedMesh *dm = NULL; - MFace *mface; - MVert *mvert; - short *normals; + MFace *mf; + MVert *mv; + short *normals, *no_s; + float no[3]; // ------------------------------------------------ // get numverts + numfaces first @@ -193,20 +193,15 @@ DerivedMesh *fluidsim_read_obj(char *filename) numverts = wri; // skip verts - for(i=0; ico[j] = wrf; - } - } + for(i=0; ico, sizeof(float) * 3); // should be the same as numverts gotBytes = gzread(gzf, &wri, sizeof(wri)); @@ -269,10 +257,10 @@ DerivedMesh *fluidsim_read_obj(char *filename) } // read normals from file (but don't save them yet) - for(i=0; i0; i--, no_s += 3) { - gotBytes = gzread(gzf, &wrf, sizeof( wrf )); - normals[i] = (short)(wrf*32767.0f); + gotBytes = gzread(gzf, no, sizeof(float) * 3); + normal_float_to_short_v3(no_s, no); } /* read no. of triangles */ @@ -283,20 +271,17 @@ DerivedMesh *fluidsim_read_obj(char *filename) if(dm) dm->release(dm); gzclose( gzf ); + MEM_freeN(normals); return NULL; } // read triangles from file - mface = CDDM_get_faces(dm); - for(i=0; i0; i--, mf++) { - int face[4]; - MFace *mf = &mface[i]; + int face[3]; - 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; + gotBytes = gzread(gzf, face, sizeof(int) * 3); // check if 3rd vertex has index 0 (not allowed in blender) if(face[2]) @@ -311,7 +296,7 @@ DerivedMesh *fluidsim_read_obj(char *filename) mf->v2 = face[2]; mf->v3 = face[0]; } - mf->v4 = face[3]; + mf->v4 = 0; test_index_face(mf, NULL, 0, 3); }