schteppe / cannon.js

A lightweight 3D physics engine written in JavaScript.
http://schteppe.github.com/cannon.js
MIT License
4.63k stars 700 forks source link

Serializing the entire World #460

Open zakaton opened 3 years ago

zakaton commented 3 years ago

I'm working on a replicated multi-user A-FRAME demo using cannon.js for the physics and Croquet for networking, where each user runs an independent CANNON.World.

It works at first when everyone starts with a new CANNON.World and replicates timestepping, but when we serialize the world using cannon.serialize.js we found out it just serializes the bodies (not including stuff like velocity and inertia). We were hoping it would serialize EVERYTHING (including gravity, time, and all the other stuff) so it would replicate an exact copy of the world.

Is there a quick way to do this or will I need to go through the world's properties and manually serialize all the stuff myself?

marcofugaro commented 3 years ago

As it says here

These methods are not complete but works for simple cases.

That code works for bodies only I guess, you would have to write the rest of the code if you want other properties in the json. It shouldn't be that hard.