Skip to content

Commit

Permalink
More Lua bindings for 3D physics
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardodoria committed Nov 28, 2023
1 parent d40d69d commit 889cfb5
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
30 changes: 30 additions & 0 deletions engine/core/script/binding/ECSClassesLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ void LuaBinding::registerECSClasses(lua_State *L){
.addProperty("preSolve2D", [] (PhysicsSystem* self, lua_State* L) { return &self->preSolve2D; }, [] (PhysicsSystem* self, lua_State* L) { self->preSolve2D = L; })
.addProperty("postSolve2D", [] (PhysicsSystem* self, lua_State* L) { return &self->postSolve2D; }, [] (PhysicsSystem* self, lua_State* L) { self->postSolve2D = L; })
.addProperty("shouldCollide2D", [] (PhysicsSystem* self, lua_State* L) { return &self->shouldCollide2D; }, [] (PhysicsSystem* self, lua_State* L) { self->shouldCollide2D = L; })

.addFunction("createBody2D", &PhysicsSystem::createBody2D)
.addFunction("removeBody2D", &PhysicsSystem::removeBody2D)

.addFunction("createRectShape2D", &PhysicsSystem::createRectShape2D)
.addFunction("createCenteredRectShape2D", &PhysicsSystem::createCenteredRectShape2D)
.addFunction("createPolygonShape2D", &PhysicsSystem::createPolygonShape2D)
Expand All @@ -126,10 +128,25 @@ void LuaBinding::registerECSClasses(lua_State *L){
.addFunction("createLoopChainShape2D", &PhysicsSystem::createLoopChainShape2D)
.addFunction("createChainShape2D", &PhysicsSystem::createChainShape2D)
.addFunction("removeAllShapes2D", &PhysicsSystem::removeAllShapes2D)

.addFunction("createBody3D", &PhysicsSystem::createBody3D)
.addFunction("removeBody3D", &PhysicsSystem::removeBody3D)
.addFunction("createBoxShape3D", &PhysicsSystem::createBoxShape3D)
.addFunction("createSphereShape3D", &PhysicsSystem::createSphereShape3D)
.addFunction("createCapsuleShape3D", &PhysicsSystem::createCapsuleShape3D)
.addFunction("createTaperedCapsuleShape3D", &PhysicsSystem::createTaperedCapsuleShape3D)
.addFunction("createCylinderShape3D", &PhysicsSystem::createCylinderShape3D)
.addFunction("createConvexHullShape3D", &PhysicsSystem::createConvexHullShape3D)
.addFunction("createMeshShape3D",
luabridge::overload<Entity , std::vector<Vector3>, std::vector<uint16_t>>(&PhysicsSystem::createMeshShape3D),
luabridge::overload<Entity, MeshComponent&>(&PhysicsSystem::createMeshShape3D))
.addFunction("createHeightFieldShape3D", &PhysicsSystem::createHeightFieldShape3D)

.addFunction("loadBody2D", &PhysicsSystem::loadBody2D)
.addFunction("destroyBody2D", &PhysicsSystem::destroyBody2D)
.addFunction("loadShape2D", &PhysicsSystem::loadShape2D)
.addFunction("destroyShape2D", &PhysicsSystem::destroyShape2D)

.addFunction("loadDistanceJoint2D", &PhysicsSystem::loadDistanceJoint2D)
.addFunction("loadRevoluteJoint2D", &PhysicsSystem::loadRevoluteJoint2D)
.addFunction("loadPrismaticJoint2D", &PhysicsSystem::loadPrismaticJoint2D)
Expand All @@ -142,6 +159,19 @@ void LuaBinding::registerECSClasses(lua_State *L){
.addFunction("loadMotorJoint2D", &PhysicsSystem::loadMotorJoint2D)
.addFunction("loadRopeJoint2D", &PhysicsSystem::loadRopeJoint2D)
.addFunction("destroyJoint2D", &PhysicsSystem::destroyJoint2D)

.addFunction("loadFixedJoint3D", &PhysicsSystem::loadFixedJoint3D)
.addFunction("loadDistanceJoint3D", &PhysicsSystem::loadDistanceJoint3D)
.addFunction("loadPointJoint3D", &PhysicsSystem::loadPointJoint3D)
.addFunction("loadHingeJoint3D", &PhysicsSystem::loadHingeJoint3D)
.addFunction("loadConeJoint3D", &PhysicsSystem::loadConeJoint3D)
.addFunction("loadPrismaticJoint3D", &PhysicsSystem::loadPrismaticJoint3D)
.addFunction("loadSwingTwistJoint3D", &PhysicsSystem::loadSwingTwistJoint3D)
.addFunction("loadSixDOFJoint3D", &PhysicsSystem::loadSixDOFJoint3D)
.addFunction("loadPathJoint3D", &PhysicsSystem::loadPathJoint3D)
.addFunction("loadGearJoint3D", &PhysicsSystem::loadGearJoint3D)
.addFunction("loadRackAndPinionJoint3D", &PhysicsSystem::loadRackAndPinionJoint3D)
.addFunction("loadPulleyJoint3D", &PhysicsSystem::loadPulleyJoint3D)
.endClass();

luabridge::getGlobalNamespace(L)
Expand Down
63 changes: 63 additions & 0 deletions engine/core/script/binding/ObjectClassesLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include "ContactImpulse2D.h"
#include "Manifold2D.h"
#include "WorldManifold2D.h"
#include "Body3D.h"
#include "Joint3D.h"
#include "Contact3D.h"
#include "CollideShapeResult3D.h"

using namespace Supernova;

Expand Down Expand Up @@ -98,6 +102,22 @@ void LuaBinding::registerObjectClasses(lua_State *L){
.addProperty("ROPE", Joint2DType::ROPE)
.endNamespace();

luabridge::getGlobalNamespace(L)
.beginNamespace("Joint3DType")
.addProperty("FIXED", Joint3DType::FIXED)
.addProperty("DISTANCE", Joint3DType::DISTANCE)
.addProperty("POINT", Joint3DType::POINT)
.addProperty("HINGE", Joint3DType::HINGE)
.addProperty("CONE", Joint3DType::CONE)
.addProperty("PRISMATIC", Joint3DType::PRISMATIC)
.addProperty("SWINGTWIST", Joint3DType::SWINGTWIST)
.addProperty("SIXDOF", Joint3DType::SIXDOF)
.addProperty("PATH", Joint3DType::PATH)
.addProperty("GEAR", Joint3DType::GEAR)
.addProperty("RACKANDPINON", Joint3DType::RACKANDPINON)
.addProperty("PULLEY", Joint3DType::PULLEY)
.endNamespace();

luabridge::getGlobalNamespace(L)
.beginNamespace("Manifold2DType")
.addProperty("CIRCLES", Manifold2DType::CIRCLES)
Expand Down Expand Up @@ -656,6 +676,7 @@ void LuaBinding::registerObjectClasses(lua_State *L){

luabridge::getGlobalNamespace(L)
.beginClass<Joint2D>("Joint2D")
.addConstructor <void (Scene*), void (Scene*, Entity)> ()
.addFunction("setDistanceJoint", &Joint2D::setDistanceJoint)
.addFunction("setRevoluteJoint", &Joint2D::setRevoluteJoint)
.addFunction("setPrismaticJoint", &Joint2D::setPrismaticJoint)
Expand Down Expand Up @@ -758,5 +779,47 @@ void LuaBinding::registerObjectClasses(lua_State *L){
.addFunction("getCenterOfMassPosition", &Body3D::getCenterOfMassPosition)
.endClass();

luabridge::getGlobalNamespace(L)
.beginClass<Joint3D>("Joint3D")
.addConstructor <void (Scene*), void (Scene*, Entity)> ()
.addFunction("setFixedJoint", &Joint3D::setFixedJoint)
.addFunction("setDistanceJoint", &Joint3D::setDistanceJoint)
.addFunction("setPointJoint", &Joint3D::setPointJoint)
.addFunction("setHingeJoint", &Joint3D::setHingeJoint)
.addFunction("setConeJoint", &Joint3D::setConeJoint)
.addFunction("setPrismaticJoint", &Joint3D::setPrismaticJoint)
.addFunction("setSwingTwistJoint", &Joint3D::setSwingTwistJoint)
.addFunction("setSixDOFJoint", &Joint3D::setSixDOFJoint)
.addFunction("setPathJoint", &Joint3D::setPathJoint)
.addFunction("setGearJoint", &Joint3D::setGearJoint)
.addFunction("setRackAndPinionJoint", &Joint3D::setRackAndPinionJoint)
.addFunction("setPulleyJoint", &Joint3D::setPulleyJoint)
.addFunction("getType", &Joint3D::getType)
.endClass();

luabridge::getGlobalNamespace(L)
.beginClass<Contact3D>("Contact2D")
.addFunction("getBaseOffset", &Contact3D::getBaseOffset)
.addFunction("getWorldSpaceNormal", &Contact3D::getWorldSpaceNormal)
.addFunction("getPenetrationDepth", &Contact3D::getPenetrationDepth)
.addFunction("getSubShapeID1", &Contact3D::getSubShapeID1)
.addFunction("getSubShapeID12", &Contact3D::getSubShapeID12)
.addFunction("getRelativeContactPointsOnA", &Contact3D::getRelativeContactPointsOnA)
.addFunction("getRelativeContactPointsOnB", &Contact3D::getRelativeContactPointsOnB)
.addProperty("combinedFriction", &Contact3D::getCombinedFriction, &Contact3D::setCombinedFriction)
.addProperty("combinedRestitution", &Contact3D::getCombinedRestitution, &Contact3D::setCombinedRestitution)
.addProperty("sensor", &Contact3D::isSensor, &Contact3D::setIsSensor)
.endClass();

luabridge::getGlobalNamespace(L)
.beginClass<CollideShapeResult3D>("CollideShapeResult3D")
.addFunction("getContactPointOnA", &CollideShapeResult3D::getContactPointOnA)
.addFunction("getContactPointOnB", &CollideShapeResult3D::getContactPointOnB)
.addFunction("getPenetrationAxis", &CollideShapeResult3D::getPenetrationAxis)
.addFunction("getSubShapeID1", &CollideShapeResult3D::getSubShapeID1)
.addFunction("getSubShapeID2", &CollideShapeResult3D::getSubShapeID2)
.addFunction("getBodyID2", &CollideShapeResult3D::getBodyID2)
.endClass();

#endif //DISABLE_LUA_BINDINGS
}

0 comments on commit 889cfb5

Please sign in to comment.