2017-02-24 23:34:11 +00:00
|
|
|
#include "b3RobotSimulatorClientAPI.h"
|
|
|
|
|
2017-05-13 18:15:20 +00:00
|
|
|
#include "../SharedMemory/PhysicsClientC_API.h"
|
2018-06-05 01:41:41 +00:00
|
|
|
#include "../SharedMemory/b3RobotSimulatorClientAPI_InternalData.h"
|
2017-02-24 23:34:11 +00:00
|
|
|
#ifdef BT_ENABLE_ENET
|
2017-05-13 18:15:20 +00:00
|
|
|
#include "../SharedMemory/PhysicsClientUDP_C_API.h"
|
2017-03-16 00:09:17 +00:00
|
|
|
#endif //PHYSICS_UDP
|
2017-02-24 23:34:11 +00:00
|
|
|
|
|
|
|
#ifdef BT_ENABLE_CLSOCKET
|
2017-05-13 18:15:20 +00:00
|
|
|
#include "../SharedMemory/PhysicsClientTCP_C_API.h"
|
2017-03-16 00:09:17 +00:00
|
|
|
#endif //PHYSICS_TCP
|
2017-02-24 23:34:11 +00:00
|
|
|
|
2017-05-13 18:15:20 +00:00
|
|
|
#include "../SharedMemory/PhysicsDirectC_API.h"
|
2017-02-24 23:34:11 +00:00
|
|
|
|
2017-05-13 18:15:20 +00:00
|
|
|
#include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h"
|
2017-02-24 23:34:11 +00:00
|
|
|
|
2017-05-13 18:15:20 +00:00
|
|
|
#include "../SharedMemory/SharedMemoryPublic.h"
|
2017-02-24 23:34:11 +00:00
|
|
|
#include "Bullet3Common/b3Logging.h"
|
|
|
|
|
2018-09-04 06:13:15 +00:00
|
|
|
#ifdef BT_ENABLE_GRPC
|
|
|
|
#include "../SharedMemory/PhysicsClientGRPC_C_API.h"
|
|
|
|
#endif
|
2017-02-24 23:34:11 +00:00
|
|
|
|
|
|
|
b3RobotSimulatorClientAPI::b3RobotSimulatorClientAPI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:09:17 +00:00
|
|
|
b3RobotSimulatorClientAPI::~b3RobotSimulatorClientAPI()
|
2017-02-24 23:34:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-13 18:15:20 +00:00
|
|
|
void b3RobotSimulatorClientAPI::renderScene()
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_data->m_guiHelper)
|
|
|
|
{
|
|
|
|
b3InProcessRenderSceneInternal(m_data->m_physicsClientHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-13 20:37:49 +00:00
|
|
|
void b3RobotSimulatorClientAPI::debugDraw(int debugDrawMode)
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_data->m_guiHelper)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3InProcessDebugDrawInternal(m_data->m_physicsClientHandle, debugDrawMode);
|
2017-05-13 20:37:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI::mouseMoveCallback(float x, float y)
|
2017-05-13 20:37:49 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_data->m_guiHelper)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return b3InProcessMouseMoveCallback(m_data->m_physicsClientHandle, x, y) != 0;
|
2017-05-13 20:37:49 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI::mouseButtonCallback(int button, int state, float x, float y)
|
2017-05-13 20:37:49 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_data->m_guiHelper)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return b3InProcessMouseButtonCallback(m_data->m_physicsClientHandle, button, state, x, y) != 0;
|
2017-05-13 20:37:49 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-24 23:34:11 +00:00
|
|
|
bool b3RobotSimulatorClientAPI::connect(int mode, const std::string& hostName, int portOrKey)
|
|
|
|
{
|
|
|
|
if (m_data->m_physicsClientHandle)
|
|
|
|
{
|
2017-03-16 00:09:17 +00:00
|
|
|
b3Warning("Already connected, disconnect first.");
|
2017-02-24 23:34:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3PhysicsClientHandle sm = 0;
|
|
|
|
|
|
|
|
int udpPort = 1234;
|
|
|
|
int tcpPort = 6667;
|
|
|
|
int key = SHARED_MEMORY_KEY;
|
|
|
|
|
2017-03-16 00:09:17 +00:00
|
|
|
switch (mode)
|
2017-02-24 23:34:11 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_EXISTING_EXAMPLE_BROWSER:
|
2017-05-13 18:15:20 +00:00
|
|
|
{
|
|
|
|
sm = b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(m_data->m_guiHelper);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_GUI:
|
2017-02-24 23:34:11 +00:00
|
|
|
{
|
2017-03-16 00:09:17 +00:00
|
|
|
int argc = 0;
|
|
|
|
char* argv[1] = {0};
|
|
|
|
#ifdef __APPLE__
|
2017-08-16 19:33:25 +00:00
|
|
|
sm = b3CreateInProcessPhysicsServerAndConnectMainThread(argc, argv);
|
2017-03-16 00:09:17 +00:00
|
|
|
#else
|
2017-08-16 19:33:25 +00:00
|
|
|
sm = b3CreateInProcessPhysicsServerAndConnect(argc, argv);
|
2017-08-15 16:34:44 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_GUI_SERVER:
|
2017-08-15 16:34:44 +00:00
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
char* argv[1] = {0};
|
|
|
|
#ifdef __APPLE__
|
2017-08-16 19:33:25 +00:00
|
|
|
sm = b3CreateInProcessPhysicsServerAndConnectMainThread(argc, argv);
|
2017-08-15 16:34:44 +00:00
|
|
|
#else
|
2017-08-16 19:33:25 +00:00
|
|
|
sm = b3CreateInProcessPhysicsServerAndConnect(argc, argv);
|
2017-03-16 00:09:17 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2017-02-24 23:34:11 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_DIRECT:
|
2017-03-16 00:09:17 +00:00
|
|
|
{
|
|
|
|
sm = b3ConnectPhysicsDirect();
|
|
|
|
break;
|
2017-02-24 23:34:11 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_SHARED_MEMORY:
|
2017-03-16 00:09:17 +00:00
|
|
|
{
|
|
|
|
if (portOrKey >= 0)
|
2017-02-24 23:34:11 +00:00
|
|
|
{
|
|
|
|
key = portOrKey;
|
|
|
|
}
|
2017-05-13 20:58:05 +00:00
|
|
|
sm = b3ConnectSharedMemory(key);
|
2017-03-16 00:09:17 +00:00
|
|
|
break;
|
2017-02-24 23:34:11 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_UDP:
|
2017-03-16 00:09:17 +00:00
|
|
|
{
|
|
|
|
if (portOrKey >= 0)
|
2017-02-24 23:34:11 +00:00
|
|
|
{
|
|
|
|
udpPort = portOrKey;
|
|
|
|
}
|
2017-03-16 00:09:17 +00:00
|
|
|
#ifdef BT_ENABLE_ENET
|
2017-02-24 23:34:11 +00:00
|
|
|
|
|
|
|
sm = b3ConnectPhysicsUDP(hostName.c_str(), udpPort);
|
2017-03-16 00:09:17 +00:00
|
|
|
#else
|
|
|
|
b3Warning("UDP is not enabled in this build");
|
|
|
|
#endif //BT_ENABLE_ENET
|
2017-02-24 23:34:11 +00:00
|
|
|
|
|
|
|
break;
|
2017-03-16 00:09:17 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_TCP:
|
2017-02-24 23:34:11 +00:00
|
|
|
{
|
2017-03-16 00:09:17 +00:00
|
|
|
if (portOrKey >= 0)
|
2017-02-24 23:34:11 +00:00
|
|
|
{
|
|
|
|
tcpPort = portOrKey;
|
|
|
|
}
|
2017-03-16 00:09:17 +00:00
|
|
|
#ifdef BT_ENABLE_CLSOCKET
|
|
|
|
|
2017-02-24 23:34:11 +00:00
|
|
|
sm = b3ConnectPhysicsTCP(hostName.c_str(), tcpPort);
|
2017-03-16 00:09:17 +00:00
|
|
|
#else
|
2017-02-24 23:34:11 +00:00
|
|
|
b3Warning("TCP is not enabled in this pybullet build");
|
2017-03-16 00:09:17 +00:00
|
|
|
#endif //BT_ENABLE_CLSOCKET
|
2017-02-24 23:34:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case eCONNECT_GRPC:
|
|
|
|
{
|
2018-09-04 06:13:15 +00:00
|
|
|
#ifdef BT_ENABLE_GRPC
|
2018-09-23 21:17:31 +00:00
|
|
|
sm = b3ConnectPhysicsGRPC(hostName.c_str(), tcpPort);
|
2018-09-04 06:13:15 +00:00
|
|
|
#else
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Warning("GRPC is not enabled in this pybullet build");
|
2018-09-04 06:13:15 +00:00
|
|
|
#endif
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2017-03-16 00:09:17 +00:00
|
|
|
{
|
|
|
|
b3Warning("connectPhysicsServer unexpected argument");
|
2017-02-24 23:34:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-16 00:09:17 +00:00
|
|
|
if (sm)
|
|
|
|
{
|
|
|
|
m_data->m_physicsClientHandle = sm;
|
|
|
|
if (!b3CanSubmitCommand(m_data->m_physicsClientHandle))
|
|
|
|
{
|
|
|
|
disconnect();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-02-24 23:34:11 +00:00
|
|
|
}
|