I’d like to save a UniversalCamera path to play it again later.
My idea is to sample all the necessary parameters at certain key points (either every X time or when I press a key) and then use animations later to animate the camera smoothly. This would let me save the points I want and should smooth out the animation, as well as give me a way to control the frame keys so I can make the animation longer or smaller, or edit them later easily. So is that a good approach?
And what exactly to I need to save to restore the camera later?
storeState()/restoreState() seem to be what I want, but they don’t export the data.
serialize() seems to export way too much stuff (though I could filter things) but there’s no
unserialize() method. Is there a simple way to save/restore only the camera visual settings like position/orientation/up/etc? If not and this is deemed useful I can send a PR.
I believe serialize creates a JSON file so unserialize with JSON.parse
If you call serialize on the camera it will create a serialization object containing the properties needed to re-create the camera, which can be done by calling the static function Camera.Parse. But it’s up to you to call JSON.Stringify and save it to a file and then later load the file and call JSON.Parse before passing the serialization object to Camera.Parse.
I think you could store just the position, rotation, target and timestamp thou (maybe more depending on what else is changing each frame, I think maybe that’s enough for recoding user-controlled camera animation thou)… For example you could do it at the end of each frame, after the they’ve been updated, using scene.registerAfterRender, and check if any of the values are different from the last frame in the array before pushing to an array of frames (or could use a minimum threshold to check if any of the values have changed enough to create and push a new frame). And if you want to condense the data a bit, asArray and copyFromFloats/FromArray could be useful to convert between a Vector3 object and an array of 3 floats, for example.
Or maybe it would be better to store higher level instructions to control the camera, corresponding to the user’s inputs? I’ve never tried to implement camera recording thou, not sure which approach would work best.