I am attempting to synchronize a mesh deformation with the current frame rate of the scene. The deformation I had in mind is pretty much the same as the Crumple Mesh Modifier on this page
I need a program that will cycle the deformation once in the same amount of time as it took to complete the current frame.
if the frame took .2s to complete than i need the deformation cycle to last for .2s if the frame took .5s to complete than i need it to last for .5s etc...
i don't have much experience with programing but it seems that the time.deltatime function would return an integer value which is just what I'm looking for, namely the frequency of the deformation. Except that function gives the time needed to complete the PREVIOUS frame not the current frame.
What i suspect needs to be done is to process the frame but delay it from being sent to the screen long enough for the deformation function to receive its needed frequency information, namely how long it took to complete the frame. Then they can perform their functions in tandem; the frame will display to the screen and the mesh will perform a single deformation cycle. Hopefully the delay would be minimal so as not to cause too much lag as the project this will be applied to is designed for small multiplayer applications.
The final effect should be similar to a stop motion animation in that every frame the object will have deformed once. Since the deformation is random it will look like "deformed snapshots" of the object layered on top of each other. I don't want to see the movement only the final image of the object, after deformation, displayed every frame.
This seems like it may be one of those theoretically "simple" problems that turn out to be quite complex in application.
Any help or suggestions on accomplishing this task would be much appreciated.
asked Jul 15 '10 at 01:51 AM
Just use time.deltatime no one is going to notice its the time for the last frame, unless your frames are varying wildly in the time they need, in which case you've got bigger problems than getting deformation to work.
Though at 200ms (0.2s) per frame the effect will still be very fast. I would have thought you'd want to make the delay in updates longer than that if you want to really see the effect.
However its hard to really know what you are trying to do, as you have a kind of paradox
If you haven't done the deformation then the frame cannot be complete, you need to render the frame to know how long it took, but by that point you can't perform the deformation for that frame because the frame is already complete. This is why you'll need to just use the previous deltatime. That is assuming of course this is really what you want to do.
You talk about wildly differing framerates such as 0.2 to 0.5 seconds, but if that was the case your game would be unplayable. It sounds more like you want to control the frequency of the update to the deform code, which really has nothing to do with the time it took to render the frame.
Presuming the mesh deform takes time as an argument (not got round to looking at that demo), then all it should need is to add a timer to control calling the function. You can set the timer to whatever value update you want.
So if Unity is running at 60 fps and you want the stop motion effect to happen every 0.5 seconds, then what will happen is that for 30 frames unity will render the current deformed mesh, then you deform the mesh by 0.5 second value and for the next 30 frames Unity renders the new deformation and so on.
In essence you are decoupling the call to deformation from the actual framerate Unity is running at.
answered Jul 15 '10 at 05:58 AM