31-10-2019, 08:33 AM
(This post was last modified: 31-10-2019, 08:45 AM by josemendez.)
(31-10-2019, 06:51 AM)lophochroa Wrote: I'm just getting started with Obi. I am overall impressed with its performance, but there is one big thing I can't figure out: Is it possible to pre-compute and cache a simulation? By this I mean a way to calculate particles in advance and replay them on demand.
This would be useful when results are not needed in real time, such as for pre-rendered sequences, film production, and realtime gaming when the simulation is not affected by any interactive components. This is my primary use case.
If Obi does not support this directly, is there another way to achieve it in Unity? Perhaps a way to export the resulting mesh?
Thanks in advance for your help!
Hi there!
Thought of simulating in any offline simulator, then using Alembic to import the results? This is probably the industry standard approach for cinematics and similar content, no need to reinvent the wheel:
https://docs.unity3d.com/Packages/com.un...orial.html
There is/was a built-in caching system in Obi, but I'm not exactly proud of it. It is not documented at all, not actively maintained, and since it is implemented in pure C#, it is oftentimes as slow as or slower than performing the simulation (which is written in C++/assembly), which completely defeats its purpose.
Basically what it does is capture simulation "frames" at a fixed interval, and store them in an asset. These frames contain a Vector3 position for each particle. For playing them back, simulation is bypassed and particle positions are driven by frame interpolation instead.
If you want to give it a try (though I don't even know if it will work at this point, probably not):
- Add a ObiParticleBaker component to your solver. This is in charge of recording an playing back particle caches.
- Right click in the project window->Create->Obi->ObiParticleCache. This is the asset that stores the cached simulation, kinda like a video tape. The baker will write/read particle position to/from it.
- Enable "bake on Awake" in the ObiParticleBaker, and start the game.
- Simulation will be performed, and the baker will record it in the cache.
- Exit the game at any time.
- Enable "play on Awake".
- Enter the game again. Simulation should be driven by the cache.
If it does not work, it should be relatively easy to fix. I'm currently working full-time in Obi 5.0 and life away from the keyboard is non-existent for me, but if you really need it I can take a look. However as I said, not much of an advantage due to playback performance.