diff options
author | Matt Ebb <matt@mke3.net> | 2011-05-13 02:52:30 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2011-05-13 02:52:30 +0400 |
commit | b73fe01295636aea92bf3076874b5e3cbcba9057 (patch) | |
tree | 9e9d6688e346e5c3b1b09db6e02932cceb6eb8ed /source/blender | |
parent | 57c626d11c0b2d0ed7cce7e60c863477f87d8ebd (diff) |
* Enabled rna access to fluid sim velocity vectors
The main purpose for this is to allow rendering motion blurred blender fluids in external renderers (eg. http://vimeo.com/21870635 ).
Python code snippet for interpreting this data here: http://www.pasteall.org/21577 . Cleaned up some ugly hacks in this area too
* Also added read-only access to scene.subframe to RNA - setting current frame and subframe should still go via scene.frame_set()
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_object_fluidsim.h | 15 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_fluidsim.c | 37 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 5 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_fluidsim_util.c | 39 | ||||
-rw-r--r-- | source/blender/render/intern/source/convertblender.c | 12 |
6 files changed, 78 insertions, 34 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index afa571769ab..5543e842007 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3967,7 +3967,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) fluidmd->fss= newdataadr(fd, fluidmd->fss); fluidmd->fss->fmd= fluidmd; - fluidmd->fss->meshSurfNormals = NULL; + fluidmd->fss->meshVelocities = NULL; } else if (md->type==eModifierType_Smoke) { SmokeModifierData *smd = (SmokeModifierData*) md; @@ -9623,7 +9623,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) fluidmd->fss->lastgoodframe = INT_MAX; fluidmd->fss->flag = 0; - fluidmd->fss->meshSurfNormals = NULL; + fluidmd->fss->meshVelocities = NULL; } } } diff --git a/source/blender/makesdna/DNA_object_fluidsim.h b/source/blender/makesdna/DNA_object_fluidsim.h index e8360b99d69..6f4c16cb7f3 100644 --- a/source/blender/makesdna/DNA_object_fluidsim.h +++ b/source/blender/makesdna/DNA_object_fluidsim.h @@ -42,7 +42,10 @@ extern "C" { struct Mesh; struct Ipo; -struct MVert; + +typedef struct FluidVertexVelocity { + float vel[3]; +} FluidVertexVelocity; typedef struct FluidsimSettings { struct FluidsimModifierData *fmd; /* for fast RNA access */ @@ -82,8 +85,6 @@ typedef struct FluidsimSettings { /* store pointer to original mesh (for replacing the current one) */ struct Mesh *orgMesh; - /* pointer to the currently loaded fluidsim mesh */ - struct Mesh *meshSurface; /* a mesh to display the bounding box used for simulation */ struct Mesh *meshBB; @@ -122,8 +123,10 @@ typedef struct FluidsimSettings { /* testing vars */ float farFieldSize; - /* save fluidsurface normals in mvert.no, and surface vertex velocities (if available) in mvert.co */ - struct MVert *meshSurfNormals; + /* vertex velocities of simulated fluid mesh */ + struct FluidVertexVelocity *meshVelocities; + /* number of vertices in simulated fluid mesh */ + int totvert; /* Fluid control settings */ float cpsTimeStart; @@ -136,6 +139,8 @@ typedef struct FluidsimSettings { float velocityforceRadius; int lastgoodframe; + + int pad; } FluidsimSettings; diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c index acec2ca7a24..7c93ae4168b 100644 --- a/source/blender/makesrna/intern/rna_fluidsim.c +++ b/source/blender/makesrna/intern/rna_fluidsim.c @@ -195,6 +195,18 @@ static char *rna_FluidSettings_path(PointerRNA *ptr) return BLI_sprintfN("modifiers[\"%s\"].settings", md->name); } +static void rna_FluidMeshVertex_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + FluidsimSettings *fss = (FluidsimSettings*)ptr->data; + rna_iterator_array_begin(iter, fss->meshVelocities, sizeof(float)*3, fss->totvert, 0, NULL); +} + +static int rna_FluidMeshVertex_data_length(PointerRNA *ptr) +{ + FluidsimSettings *fss = (FluidsimSettings*)ptr->data; + return fss->totvert; +} + #else static void rna_def_fluidsim_slip(StructRNA *srna) @@ -219,6 +231,24 @@ static void rna_def_fluidsim_slip(StructRNA *srna) RNA_def_property_ui_text(prop, "Partial Slip Amount", "Amount of mixing between no- and free-slip, 0 is no slip and 1 is free slip"); } +static void rna_def_fluid_mesh_vertices(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "FluidMeshVertex", NULL); + RNA_def_struct_sdna(srna, "FluidVertexVelocity"); + RNA_def_struct_ui_text(srna, "Fluid Mesh Vertex", "Vertex of a simulated fluid mesh"); + RNA_def_struct_ui_icon(srna, ICON_VERTEXSEL); + + prop= RNA_def_property(srna, "velocity", PROP_FLOAT, PROP_VELOCITY); + RNA_def_property_array(prop, 3); + RNA_def_property_float_sdna(prop, NULL, "vel"); + RNA_def_property_ui_text(prop, "Velocity", ""); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); +} + + static void rna_def_fluidsim_domain(BlenderRNA *brna) { StructRNA *srna; @@ -367,6 +397,13 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_range(prop, 0.0, 10.0); RNA_def_property_ui_text(prop, "Generate Particles", "Amount of particles to generate (0=off, 1=normal, >1=more)"); + + /* simulated fluid mesh data */ + prop= RNA_def_property(srna, "fluid_mesh_vertices", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "FluidMeshVertex"); + RNA_def_property_ui_text(prop, "Fluid Mesh Vertices", "Vertices of the fluid mesh generated by simulation"); + RNA_def_property_collection_funcs(prop, "rna_FluidMeshVertex_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_FluidMeshVertex_data_length", 0, 0); + rna_def_fluid_mesh_vertices(brna); } static void rna_def_fluidsim_volume(StructRNA *srna) diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 8bbde89475a..de724cc2252 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -3226,6 +3226,11 @@ void RNA_def_scene(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); RNA_def_property_update(prop, NC_SCENE|ND_FRAME, "rna_Scene_frame_update"); + prop= RNA_def_property(srna, "frame_subframe", PROP_FLOAT, PROP_TIME); + RNA_def_property_float_sdna(prop, NULL, "r.subframe"); + RNA_def_property_ui_text(prop, "Current Sub-Frame", ""); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE|PROP_EDITABLE); + prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_int_sdna(prop, NULL, "r.sfra"); diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 02912e38204..61345427d1c 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -139,8 +139,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd) fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize); */ - // (ab)used to store velocities - fss->meshSurfNormals = NULL; + fss->meshVelocities = NULL; fss->lastgoodframe = -1; @@ -158,10 +157,10 @@ void fluidsim_free(FluidsimModifierData *fluidmd) #ifndef DISABLE_ELBEEM if(fluidmd) { - if(fluidmd->fss->meshSurfNormals) + if(fluidmd->fss->meshVelocities) { - MEM_freeN(fluidmd->fss->meshSurfNormals); - fluidmd->fss->meshSurfNormals = NULL; + MEM_freeN(fluidmd->fss->meshVelocities); + fluidmd->fss->meshVelocities = NULL; } MEM_freeN(fluidmd->fss); } @@ -394,12 +393,12 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * FluidsimSettings *fss = fluidmd->fss; int len = strlen(filename); int totvert = dm->getNumVerts(dm); - float *velarray = NULL; + FluidVertexVelocity *velarray = NULL; // mesh and vverts have to be valid from loading... - if(fss->meshSurfNormals) - MEM_freeN(fss->meshSurfNormals); + if(fss->meshVelocities) + MEM_freeN(fss->meshVelocities); if(len<7) { @@ -408,12 +407,10 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * if(fss->domainNovecgen>0) return; - // abusing pointer to hold an array of 3d-velocities - fss->meshSurfNormals = MEM_callocN(sizeof(float)*3*dm->getNumVerts(dm), "Fluidsim_velocities"); - // abusing pointer to hold an INT - fss->meshSurface = SET_INT_IN_POINTER(totvert); + fss->meshVelocities = MEM_callocN(sizeof(FluidVertexVelocity)*dm->getNumVerts(dm), "Fluidsim_velocities"); + fss->totvert = totvert; - velarray = (float *)fss->meshSurfNormals; + velarray = fss->meshVelocities; // .bobj.gz , correct filename // 87654321 @@ -424,16 +421,16 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * gzf = gzopen(filename, "rb"); if (!gzf) { - MEM_freeN(fss->meshSurfNormals); - fss->meshSurfNormals = NULL; + MEM_freeN(fss->meshVelocities); + fss->meshVelocities = NULL; return; } gzread(gzf, &wri, sizeof( wri )); if(wri != totvert) { - MEM_freeN(fss->meshSurfNormals); - fss->meshSurfNormals = NULL; + MEM_freeN(fss->meshVelocities); + fss->meshVelocities = NULL; return; } @@ -442,7 +439,7 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * for(j=0; j<3; j++) { gzread(gzf, &wrf, sizeof( wrf )); - velarray[3*i + j] = wrf; + velarray[i].vel[j] = wrf; } } @@ -531,10 +528,10 @@ static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData } else { - if(fss->meshSurfNormals) - MEM_freeN(fss->meshSurfNormals); + if(fss->meshVelocities) + MEM_freeN(fss->meshVelocities); - fss->meshSurfNormals = NULL; + fss->meshVelocities = NULL; } return dm; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 74ce7957dd7..c1c2fb60abd 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -5387,7 +5387,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * float imat[4][4]; FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsob, eModifierType_Fluidsim); FluidsimSettings *fss; - float *velarray = NULL; + FluidVertexVelocity *velarray = NULL; /* only one step needed */ if(step) return 1; @@ -5401,14 +5401,14 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * invert_m4_m4(imat, mat); /* set first vertex OK */ - if(!fss->meshSurfNormals) return 0; + if(!fss->meshVelocities) return 0; - if( obr->totvert != GET_INT_FROM_POINTER(fss->meshSurface) ) { + if( obr->totvert != fss->totvert) { //fprintf(stderr, "load_fluidsimspeedvectors - modified fluidsim mesh, not using speed vectors (%d,%d)...\n", obr->totvert, fsob->fluidsimSettings->meshSurface->totvert); // DEBUG return 0; } - velarray = (float *)fss->meshSurfNormals; + velarray = fss->meshVelocities; if(obi->flag & R_TRANSFORMED) mul_m4_m4m4(winmat, obi->mat, re->winmat); @@ -5420,7 +5420,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * so that also small drops/little water volumes return a velocity != 0. But I had no luck in fixing that function - DG */ for(a=0; a<obr->totvert; a++) { - for(j=0;j<3;j++) avgvel[j] += velarray[3*a + j]; + for(j=0;j<3;j++) avgvel[j] += velarray[a].vel[j]; } for(j=0;j<3;j++) avgvel[j] /= (float)(obr->totvert); @@ -5435,7 +5435,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * // get fluid velocity fsvec[3] = 0.; //fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.; fsvec[2] = 2.; // NT fixed test - for(j=0;j<3;j++) fsvec[j] = velarray[3*a + j]; + for(j=0;j<3;j++) fsvec[j] = velarray[a].vel[j]; /* (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)) |