diff options
author | Daniel Genrich <daniel.genrich@gmx.net> | 2012-11-23 09:00:07 +0400 |
---|---|---|
committer | Daniel Genrich <daniel.genrich@gmx.net> | 2012-11-23 09:00:07 +0400 |
commit | ef67ddeba9c9f1f99129da3a4a7eb6b535a542e5 (patch) | |
tree | 1eb091638eb19e38ab15a77efb518ca47b66f5fa | |
parent | 7189a9db514e2ba8f79ed3cf5bc6d00ea6ff4b8c (diff) |
Bugfix [#29186] Object contribute to fluid sim animation start earlier than keyframe
Also fix:
- Fluid simulation was always lagging 1 frame behind: E.g. the 250th frame in blender showed 249th frame of the fluid simulation.
Change:
- Animated enabled/disabled property only gets counted as "on" if value >= 1
Note that this bugfix should solve many problems with timings of animated fluid sim properties.
-rw-r--r-- | intern/elbeem/intern/ntl_geometryobject.cpp | 2 | ||||
-rw-r--r-- | intern/elbeem/intern/ntl_world.cpp | 11 | ||||
-rw-r--r-- | intern/elbeem/intern/ntl_world.h | 3 | ||||
-rw-r--r-- | source/blender/editors/physics/physics_fluid.c | 8 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_fluidsim_util.c | 6 |
5 files changed, 24 insertions, 6 deletions
diff --git a/intern/elbeem/intern/ntl_geometryobject.cpp b/intern/elbeem/intern/ntl_geometryobject.cpp index 4f640253f0f..1e08cb96a95 100644 --- a/intern/elbeem/intern/ntl_geometryobject.cpp +++ b/intern/elbeem/intern/ntl_geometryobject.cpp @@ -787,7 +787,7 @@ ntlVec3Gfx ntlGeometryObject::getTranslation(double t) { } /*! get active flag time t*/ float ntlGeometryObject::getGeoActive(double t) { - float act = mcGeoActive.get(t); // if <= 0.0 -> off + float act = (mcGeoActive.get(t) >= 1.) ? 1.0 : 0.0; return act; } diff --git a/intern/elbeem/intern/ntl_world.cpp b/intern/elbeem/intern/ntl_world.cpp index 0b36f724985..dcc81dbe5cb 100644 --- a/intern/elbeem/intern/ntl_world.cpp +++ b/intern/elbeem/intern/ntl_world.cpp @@ -143,6 +143,7 @@ void ntlWorld::initDefaults() mFirstSim = 1; mSingleStepDebug = false; mFrameCnt = 0; + mSimFrameCnt = 0; mpOpenGLRenderer = NULL; /* create scene storage */ @@ -406,7 +407,6 @@ int ntlWorld::advanceSims(int framenum) } for(size_t i=0;i<mpSims->size();i++) { (*mpSims)[i]->setFrameNum(framenum); } - double targetTime = mSimulationTime + (*mpSims)[mFirstSim]->getFrameTime(framenum); // time stopped? nothing else to do... if( (*mpSims)[mFirstSim]->getFrameTime(framenum) <= 0.0 ){ @@ -416,6 +416,13 @@ int ntlWorld::advanceSims(int framenum) (*mpSims)[mFirstSim]->checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0); } + // Prevent bug [#29186] Object contribute to fluid sim animation start earlier than keyframe + // Was: double targetTime = mSimulationTime + (*mpSims)[mFirstSim]->getFrameTime(framenum); - DG + double totalTime = 0.0, targetTime = 0.0; + for(size_t i = 0; i < mSimFrameCnt; i++) + totalTime += (*mpSims)[mFirstSim]->getFrameTime(framenum); + targetTime = totalTime + (*mpSims)[mFirstSim]->getFrameTime(framenum); + int gstate = 0; myTime_t advsstart = getTime(); @@ -461,6 +468,8 @@ int ntlWorld::advanceSims(int framenum) sim->prepareVisualization(); } + mSimFrameCnt++; + return 0; } diff --git a/intern/elbeem/intern/ntl_world.h b/intern/elbeem/intern/ntl_world.h index 3c5958477d4..c207904cf75 100644 --- a/intern/elbeem/intern/ntl_world.h +++ b/intern/elbeem/intern/ntl_world.h @@ -115,6 +115,9 @@ class ntlWorld /*! count no. of frame for viz render */ int mFrameCnt; + + /*! count no. of frame for correct sim time */ + int mSimFrameCnt; }; diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index 7cd153d9564..5304c64c2a9 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -446,7 +446,7 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid for (fobj=fobjects->first; fobj; fobj=fobj->next) { Object *ob = fobj->object; FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim); - float active= (float)(fluidmd->fss->flag & OB_FLUIDSIM_ACTIVE); + float active= (float) ((fluidmd->fss->flag & OB_FLUIDSIM_ACTIVE) > 0 ? 1 : 0); float rot_d[3] = {0.f, 0.f, 0.f}, old_rot[3] = {0.f, 0.f, 0.f}; if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) @@ -467,6 +467,8 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid set_channel(fobj->Scale, timeAtFrame, ob->size, i, CHANNEL_VEC); set_channel(fobj->Active, timeAtFrame, &active, i, CHANNEL_FLOAT); set_channel(fobj->InitialVelocity, timeAtFrame, &fluidmd->fss->iniVelx, i, CHANNEL_VEC); + + // printf("Active: %f, Frame: %f\n", active, timeAtFrame); if (fluidmd->fss->type == OB_FLUIDSIM_CONTROL) { set_channel(fobj->AttractforceStrength, timeAtFrame, &fluidmd->fss->attractforceStrength, i, CHANNEL_FLOAT); @@ -962,8 +964,8 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor /* ******** prepare output file paths ******** */ outStringsChanged = fluid_init_filepaths(fsDomain, targetDir, targetFile, debugStrBuffer); - channels->length = scene->r.efra; - channels->aniFrameTime = (double)(domainSettings->animEnd - domainSettings->animStart) / (double)noFrames; + channels->length = scene->r.efra; // DG TODO: why using endframe and not "noFrames" here? .. because "noFrames" is buggy too? (not using sfra) + channels->aniFrameTime = (double)((double)domainSettings->animEnd - (double)domainSettings->animStart) / (double)noFrames; /* ******** initialize and allocate animation channels ******** */ fluid_init_all_channels(C, fsDomain, domainSettings, channels, fobjects); diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 47523286229..13d409dc941 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -426,7 +426,11 @@ static DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams) { int displaymode = 0; - int curFrame = framenr - 1 /*scene->r.sfra*/; /* start with 0 at start frame */ + + int curFrame = framenr /* - 1 */ /*scene->r.sfra*/; /* start with 0 at start frame */ + /* why start with 0 as start frame?? Animations + time are frozen for frame 0 anyway. (See physics_fluid.c for that. - DG */ + /* If we start with frame 0, we need to remap all animation channels, too, because they will all be 1 frame late if using frame-1! - DG */ + char targetFile[FILE_MAX]; FluidsimSettings *fss = fluidmd->fss; DerivedMesh *dm = NULL; |