Skip to content

d954mas/defold-reactphysics3d

Repository files navigation

GitHub release (latest by date) GitHub Workflow Status

ReactPhysics3D for Defold

ReactPhysics3D lua bindings for the Defold Game Engine.

This project based on ReactPhysics3D

ReactPhysics3D is an open source C++ physics engine library that can be used in 3D simulations and games.

www.reactphysics3d.com

I tried to keep the lua api the same as the c++ api when possible.

If you like the extension you can support me on patreon. It will help me make more libraries for defold.

"Buy Me A Coffee"

Try the demo


WARNING

  1. This is c++ library. I add some function parameters checks but you can crash it in some cases.

  2. Call destroy. Or you will have memory leaks.

  3. rp3d.destroyPhysicsWorld will destroy and free all used memory by world objects. But for example shapes will not be free.

  4. Destroy shapes after destroy all objects that use shape or you will get crash.

--CRASH
rp3d.destroyBoxShape(self.shape)
self.world:destroyCollisionBody(self.body)

--GOOD
self.world:destroyCollisionBody(self.body)
rp3d.destroyBoxShape(self.shape)
  1. In most places used 0 index.

  2. You can crash physics engine in Hinge Chain test scene.

Assertion failed: length() > MACHINE_EPSILON, at: upload/reactphysics3d/src/reactphysics3d/mathematics/Vector3.cpp,48,getOneUnitOrthogonalVector)

Limits

1)Defold vector instead of rp3d::Vector

2)Defold quaternion instead of rp3d::Quat

3)no Transform userdata. Use table with vector3 and quaternion


Setup

Dependency

You can use the rp3d extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/d954mas/defold-reactphysics3d/archive/master.zip

Or point to the ZIP file of a specific release.

Emmylua

Make lua file with Emmylua annotations. Use it for autocomplete.

Emmylua header


How to use

1.ReactPhysics3D c++ manual

User manual and api for c++ library. Read it first

2.Lua API

3.Examples

Look at examples. You can download this repository and run them.

4.Tests

Every function have a test. You can use test as example.


Lua API

rp3d

AABB
BallAndSocketJoint
BallAndSocketJointInfo
BoxShape
CapsuleShape
Collider
CollisionBody
CollisionShape
ConcaveMeshShape
ConcaveShape
ConvexMeshShape
ConvexPolyhedronShape
ConvexShape
DebugRenderer
EventListener
FixedJoint
FixedJointInfo
HalfEdgeStructure
HeightFieldShape
HingeJoint
HingeJointInfo
Joint
JointInfo
Material
PhysicsCommon rp3d in lua
PhysicsWorld
PolyhedronMesh
Ray
RaycastCallback
RaycastInfo
RigidBody
SliderJoint
SliderJointInfo
SphereShape
Transform
TriangleMesh
TriangleVertexArray