Allow to load a urdf file in the testplugin.cpp, as first quick test, example pybullet script:

import pybullet as p
p.connect(p.GUI)
pluginUid = p.loadPlugin("E:/develop/bullet3/bin/pybullet_testplugin_vs2010_x64_debug.dll")
commandUid = 0
argument = "plane.urdf"
p.executePluginCommand(pluginUid,commandUid,argument)
p.unloadPlugin(pluginUid)
This commit is contained in:
erwincoumans
2017-09-23 09:25:00 -07:00
parent 37cfce99b2
commit 815a56c9bc
8 changed files with 50 additions and 13 deletions

View File

@@ -78,7 +78,7 @@ struct PhysicsClientSharedMemoryInternalData {
m_hasLastServerStatus(false), m_hasLastServerStatus(false),
m_sharedMemoryKey(SHARED_MEMORY_KEY), m_sharedMemoryKey(SHARED_MEMORY_KEY),
m_verboseOutput(false), m_verboseOutput(false),
m_timeOutInSeconds(5) m_timeOutInSeconds(30)
{} {}
void processServerStatus(); void processServerStatus();

View File

@@ -1516,8 +1516,8 @@ struct PhysicsServerCommandProcessorInternalData
b3HashMap<b3HashString, char*> m_profileEvents; b3HashMap<b3HashString, char*> m_profileEvents;
PhysicsServerCommandProcessorInternalData() PhysicsServerCommandProcessorInternalData(PhysicsCommandProcessorInterface* proc)
: :m_pluginManager(proc),
m_allowRealTimeSimulation(false), m_allowRealTimeSimulation(false),
m_commandLogger(0), m_commandLogger(0),
m_logPlayback(0), m_logPlayback(0),
@@ -1647,8 +1647,9 @@ void PhysicsServerCommandProcessor::setGuiHelper(struct GUIHelperInterface* guiH
PhysicsServerCommandProcessor::PhysicsServerCommandProcessor() PhysicsServerCommandProcessor::PhysicsServerCommandProcessor()
:m_data(0)
{ {
m_data = new PhysicsServerCommandProcessorInternalData(); m_data = new PhysicsServerCommandProcessorInternalData(this);
createEmptyDynamicsWorld(); createEmptyDynamicsWorld();

View File

@@ -4,6 +4,8 @@
#include "Bullet3Common/b3ResizablePool.h" #include "Bullet3Common/b3ResizablePool.h"
#include "plugins/b3PluginAPI.h" #include "plugins/b3PluginAPI.h"
#include "SharedMemoryPublic.h" #include "SharedMemoryPublic.h"
#include "PhysicsDirect.h"
#include "plugins/b3PluginContext.h"
#ifdef _WIN32 #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@@ -50,15 +52,19 @@ struct b3PluginManagerInternalData
{ {
b3ResizablePool<b3PluginHandle> m_plugins; b3ResizablePool<b3PluginHandle> m_plugins;
b3HashMap<b3HashString, b3PluginHandle> m_pluginMap; b3HashMap<b3HashString, b3PluginHandle> m_pluginMap;
PhysicsDirect* m_physicsDirect;
}; };
b3PluginManager::b3PluginManager() b3PluginManager::b3PluginManager(class PhysicsCommandProcessorInterface* physSdk)
{ {
m_data = new b3PluginManagerInternalData; m_data = new b3PluginManagerInternalData;
m_data->m_physicsDirect = new PhysicsDirect(physSdk,false);
} }
b3PluginManager::~b3PluginManager() b3PluginManager::~b3PluginManager()
{ {
delete m_data->m_physicsDirect;
m_data->m_pluginMap.clear(); m_data->m_pluginMap.clear();
m_data->m_plugins.exitHandles(); m_data->m_plugins.exitHandles();
delete m_data; delete m_data;
@@ -145,7 +151,10 @@ int b3PluginManager::executePluginCommand(int pluginUniqueId, const char* argume
b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId); b3PluginHandle* plugin = m_data->m_plugins.getHandle(pluginUniqueId);
if (plugin) if (plugin)
{ {
result = plugin->m_executeCommandFunc(arguments); b3PluginContext context;
context.m_arguments = arguments;
context.m_physClient = (b3PhysicsClientHandle) m_data->m_physicsDirect;
result = plugin->m_executeCommandFunc(&context);
} }
return result; return result;
} }

View File

@@ -7,7 +7,7 @@ class b3PluginManager
public: public:
b3PluginManager(); b3PluginManager(class PhysicsCommandProcessorInterface* physSdk);
virtual ~b3PluginManager(); virtual ~b3PluginManager();
int loadPlugin(const char* pluginPath); int loadPlugin(const char* pluginPath);

View File

@@ -28,7 +28,7 @@ extern "C" {
/* Plugin API */ /* Plugin API */
typedef B3_API_ENTRY int (B3_API_CALL * PFN_INIT)(); typedef B3_API_ENTRY int (B3_API_CALL * PFN_INIT)();
typedef B3_API_ENTRY void (B3_API_CALL * PFN_EXIT)(); typedef B3_API_ENTRY void (B3_API_CALL * PFN_EXIT)();
typedef B3_API_ENTRY int (B3_API_CALL * PFN_EXECUTE)(const char* arguments); typedef B3_API_ENTRY int (B3_API_CALL * PFN_EXECUTE)(struct b3PluginContext* context);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -0,0 +1,13 @@
#ifndef B3_PLUGIN_CONTEXT_H
#define B3_PLUGIN_CONTEXT_H
#include "../PhysicsClientC_API.h"
struct b3PluginContext
{
const char* m_arguments;
b3PhysicsClientHandle m_physClient;
};
#endif //B3_PLUGIN_CONTEXT_H

View File

@@ -1,7 +1,7 @@
#include "testplugin.h" #include "testplugin.h"
#include "../../SharedMemoryPublic.h" #include "../../SharedMemoryPublic.h"
#include "../b3PluginContext.h"
#include <stdio.h> #include <stdio.h>
B3_SHARED_API int initPlugin() B3_SHARED_API int initPlugin()
@@ -10,10 +10,24 @@ B3_SHARED_API int initPlugin()
return SHARED_MEMORY_MAGIC_NUMBER; return SHARED_MEMORY_MAGIC_NUMBER;
} }
B3_SHARED_API int executePluginCommand(const char* arguments) B3_SHARED_API int executePluginCommand(struct b3PluginContext* context)
{ {
printf("arguments:%s\n",arguments); printf("arguments:%s\n",context->m_arguments);
return 42;
b3SharedMemoryStatusHandle statusHandle;
int statusType = -1;
int bodyUniqueId = -1;
b3SharedMemoryCommandHandle command =
b3LoadUrdfCommandInit(context->m_physClient, context->m_arguments);
statusHandle = b3SubmitClientCommandAndWaitStatus(context->m_physClient, command);
statusType = b3GetStatusType(statusHandle);
if (statusType == CMD_URDF_LOADING_COMPLETED)
{
bodyUniqueId = b3GetStatusBodyIndex(statusHandle);
}
return bodyUniqueId;
} }

View File

@@ -10,7 +10,7 @@ extern "C"
B3_SHARED_API int initPlugin(); B3_SHARED_API int initPlugin();
B3_SHARED_API void exitPlugin(); B3_SHARED_API void exitPlugin();
B3_SHARED_API int executePluginCommand(const char* arguments); B3_SHARED_API int executePluginCommand(struct b3PluginContext* context);
#ifdef __cplusplus #ifdef __cplusplus
}; };