Open Jasonwky opened 6 years ago
I can't even find out what LayaBox3D is. Is it a game engine? Is it a rendering library? A Unity addon? You probably won't find official examples with this. I've certainly never heard of it.
This is website:https://www.layabox.com/, a chinese game engin.
Looks very cool! Again there probably aren't many examples, but it should be doable if you know how to work with this layabox engine.
Cannon really is an independent system. If you look at the current examples, it usually goes something like:
You keep the first step. Initialize Cannon scene, add objects and step the world. All of that is really independent and you can copy all of that code. Just ignore anything three.js related, which again, shouldn't be difficult, as the two systems are pretty well separated.
As for synchronization, you now need to go through your layabox objects inside your layabox Update loop and say: layaBoxBody.position = cannonBody.position; layaBoxBody.rotation = cannonBody.rotation;
So the Cannon part really is the same everywhere. If you need help with layabox's object transformation or scene management, you'll need to look into layabox's documentation. Then just build a bridge between the two and you're done.
Might be a lot more difficult than I imagine it to be but I wish you good luck.
Also take a look at the demo (http://layaair.ldc.layabox.com/demo/?2d&Physics&Slingshot) that uses matter.js (2D physics). Integrating cannon.js for 3D physics should be similar. (Source on GitHub here: https://github.com/layabox/layaair/blob/master/samples/js/2d/samples/Physics_Slingshot.js)
Thank you,I'll try it.
I cannot find rotation in cannonBody,Can you tell me in which class I can find it?
Oh sorry, rotation is stored as a quaternion in a Body object. (a 4D vector, it prevents gimbal lock) http://schteppe.github.io/cannon.js/docs/classes/Body.html
Does layabox support quaternions? Might not if it's mainly a 2D engine. Converting quaternions can be tricky.
I want to use in LayaBox3D,Can officials give an example?