2015-07-14 22:30:17 +00:00
2016-07-11 07:26:40 +00:00
//todo(erwincoumans): re-use the upcoming b3RobotSimAPI here
2015-07-14 22:30:17 +00:00
# include "PhysicsServerExample.h"
2017-05-31 02:54:55 +00:00
2017-06-13 17:53:24 +00:00
# include "../CommonInterfaces/Common2dCanvasInterface.h"
2015-11-23 04:50:32 +00:00
# include "PhysicsServerSharedMemory.h"
2016-10-09 01:40:09 +00:00
# include "Bullet3Common/b3CommandLineArgs.h"
2015-07-14 22:30:17 +00:00
# include "SharedMemoryCommon.h"
2016-07-18 06:50:11 +00:00
# include "Bullet3Common/b3Matrix3x3.h"
2016-07-08 02:24:44 +00:00
# include "../Utils/b3Clock.h"
# include "../MultiThreading/b3ThreadSupportInterface.h"
2016-12-27 03:40:09 +00:00
# include "SharedMemoryPublic.h"
2017-10-25 15:15:01 +00:00
//#define BT_ENABLE_VR
2016-10-14 22:06:09 +00:00
# ifdef BT_ENABLE_VR
# include "../RenderingExamples/TinyVRGui.h"
# endif //BT_ENABLE_VR
# include "../CommonInterfaces/CommonParameterInterface.h"
2017-10-25 15:15:01 +00:00
# include "../Importers/ImportURDFDemo/urdfStringSplit.h"
2016-09-09 18:28:38 +00:00
2016-10-04 15:53:59 +00:00
//@todo(erwincoumans) those globals are hacks for a VR demo, move this to Python/pybullet!
2017-05-15 18:39:39 +00:00
bool gEnablePicking = true ;
bool gEnableTeleporting = true ;
2017-05-16 19:19:03 +00:00
bool gEnableRendering = true ;
2017-09-02 18:35:54 +00:00
bool gActivedVRRealTimeSimulation = false ;
2017-05-16 19:19:03 +00:00
bool gEnableSyncPhysicsRendering = true ;
bool gEnableUpdateDebugDrawLines = true ;
2017-11-18 21:21:20 +00:00
static int gCamVisualizerWidth = 228 ;
static int gCamVisualizerHeight = 192 ;
2017-01-06 01:41:58 +00:00
2017-06-17 20:29:14 +00:00
static bool gEnableDefaultKeyboardShortcuts = true ;
static bool gEnableDefaultMousePicking = true ;
2017-05-31 02:54:55 +00:00
2017-10-25 15:15:01 +00:00
2017-01-06 01:41:58 +00:00
2017-05-31 02:54:55 +00:00
2016-12-03 01:44:00 +00:00
btScalar gVRTeleportRotZ = 0 ;
2017-01-06 01:41:58 +00:00
2016-10-23 14:14:50 +00:00
extern int gInternalSimFlags ;
2016-11-30 01:08:47 +00:00
extern bool gResetSimulation ;
2016-11-17 00:12:59 +00:00
int gGraspingController = - 1 ;
2016-09-22 15:50:28 +00:00
extern btScalar simTimeScalingFactor ;
2016-12-27 03:40:09 +00:00
bool gBatchUserDebugLines = true ;
2017-05-31 02:54:55 +00:00
2016-09-09 21:30:37 +00:00
2016-12-03 01:44:00 +00:00
const char * startFileNameVR = " 0_VRDemoSettings.txt " ;
2016-11-17 00:12:59 +00:00
# include <vector>
2016-12-03 01:44:00 +00:00
static void loadCurrentSettingsVR ( b3CommandLineArgs & args )
{
2017-01-16 06:26:11 +00:00
//int currentEntry = 0;
2016-12-03 01:44:00 +00:00
FILE * f = fopen ( startFileNameVR , " r " ) ;
if ( f )
{
char oneline [ 1024 ] ;
char * argv [ ] = { 0 , & oneline [ 0 ] } ;
2017-01-16 06:26:11 +00:00
2016-12-03 01:44:00 +00:00
while ( fgets ( oneline , 1024 , f ) ! = NULL )
{
char * pos ;
if ( ( pos = strchr ( oneline , ' \n ' ) ) ! = NULL )
* pos = ' \0 ' ;
args . addArgs ( 2 , argv ) ;
}
fclose ( f ) ;
}
2017-01-16 06:26:11 +00:00
2016-12-03 01:44:00 +00:00
} ;
2017-01-16 06:26:11 +00:00
//remember the settings (you don't want to re-tune again and again...)
2017-05-31 02:54:55 +00:00
static void saveCurrentSettingsVR ( const btVector3 & VRTeleportPos1 )
2017-01-16 06:26:11 +00:00
{
FILE * f = fopen ( startFileNameVR , " w " ) ;
if ( f )
{
2017-05-31 02:54:55 +00:00
fprintf ( f , " --camPosX= %f \n " , VRTeleportPos1 [ 0 ] ) ;
fprintf ( f , " --camPosY= %f \n " , VRTeleportPos1 [ 1 ] ) ;
fprintf ( f , " --camPosZ= %f \n " , VRTeleportPos1 [ 2 ] ) ;
2017-01-16 06:26:11 +00:00
fprintf ( f , " --camRotZ= %f \n " , gVRTeleportRotZ ) ;
fclose ( f ) ;
}
} ;
2016-09-08 22:15:58 +00:00
bool gDebugRenderToggle = false ;
2016-07-08 02:24:44 +00:00
void MotionThreadFunc ( void * userPtr , void * lsMemory ) ;
void * MotionlsMemoryFunc ( ) ;
2018-05-02 21:32:43 +00:00
void MotionlsMemoryReleaseFunc ( void * ptr ) ;
2016-07-08 02:24:44 +00:00
# define MAX_MOTION_NUM_THREADS 1
enum
{
numCubesX = 20 ,
numCubesY = 20
} ;
enum TestExampleBrowserCommunicationEnums
{
eRequestTerminateMotion = 13 ,
eMotionIsUnInitialized ,
eMotionIsInitialized ,
eMotionInitializationFailed ,
eMotionHasTerminated
} ;
enum MultiThreadedGUIHelperCommunicationEnums
{
eGUIHelperIdle = 13 ,
eGUIHelperRegisterTexture ,
eGUIHelperRegisterGraphicsShape ,
eGUIHelperRegisterGraphicsInstance ,
eGUIHelperCreateCollisionShapeGraphicsObject ,
eGUIHelperCreateCollisionObjectGraphicsObject ,
2016-09-22 15:50:28 +00:00
eGUIHelperCreateRigidBodyGraphicsObject ,
2016-07-08 02:24:44 +00:00
eGUIHelperRemoveAllGraphicsInstances ,
2016-08-08 21:23:44 +00:00
eGUIHelperCopyCameraImageData ,
2017-06-13 17:53:24 +00:00
eGUIHelperDisplayCameraImageData ,
2016-11-12 02:07:42 +00:00
eGUIHelperAutogenerateGraphicsObjects ,
2016-11-20 23:38:42 +00:00
eGUIUserDebugAddText ,
eGUIUserDebugAddLine ,
2017-01-17 23:42:32 +00:00
eGUIUserDebugAddParameter ,
2016-11-20 23:38:42 +00:00
eGUIUserDebugRemoveItem ,
eGUIUserDebugRemoveAllItems ,
2017-03-16 16:13:33 +00:00
eGUIDumpFramesToVideo ,
2017-05-04 00:05:05 +00:00
eGUIHelperRemoveGraphicsInstance ,
2017-05-13 16:18:36 +00:00
eGUIHelperChangeGraphicsInstanceRGBAColor ,
2017-06-01 19:32:44 +00:00
eGUIHelperChangeGraphicsInstanceSpecularColor ,
2017-05-16 19:19:03 +00:00
eGUIHelperSetVisualizerFlag ,
2017-06-30 20:35:07 +00:00
eGUIHelperChangeGraphicsInstanceTextureId ,
eGUIHelperGetShapeIndexFromInstance ,
2017-07-01 02:11:43 +00:00
eGUIHelperChangeTexture ,
2018-02-22 07:22:16 +00:00
eGUIHelperRemoveTexture ,
2016-07-08 02:24:44 +00:00
} ;
2017-03-16 16:13:33 +00:00
2016-07-08 02:24:44 +00:00
# include <stdio.h>
//#include "BulletMultiThreaded/PlatformDefinitions.h"
# ifndef _WIN32
# include "../MultiThreading/b3PosixThreadSupport.h"
b3ThreadSupportInterface * createMotionThreadSupport ( int numThreads )
{
b3PosixThreadSupport : : ThreadConstructionInfo constructionInfo ( " MotionThreads " ,
MotionThreadFunc ,
MotionlsMemoryFunc ,
2018-05-02 21:32:43 +00:00
MotionlsMemoryReleaseFunc ,
2016-07-08 02:24:44 +00:00
numThreads ) ;
b3ThreadSupportInterface * threadSupport = new b3PosixThreadSupport ( constructionInfo ) ;
return threadSupport ;
}
# elif defined( _WIN32)
# include "../MultiThreading/b3Win32ThreadSupport.h"
b3ThreadSupportInterface * createMotionThreadSupport ( int numThreads )
{
2018-05-02 21:32:43 +00:00
b3Win32ThreadSupport : : Win32ThreadConstructionInfo threadConstructionInfo ( " MotionThreads " , MotionThreadFunc , MotionlsMemoryFunc , MotionlsMemoryReleaseFunc , numThreads ) ;
2016-07-08 02:24:44 +00:00
b3Win32ThreadSupport * threadSupport = new b3Win32ThreadSupport ( threadConstructionInfo ) ;
return threadSupport ;
}
# endif
2016-11-17 00:12:59 +00:00
enum MyMouseCommandType
{
MyMouseMove = 1 ,
MyMouseButtonDown ,
MyMouseButtonUp
2016-07-08 02:24:44 +00:00
2016-11-17 00:12:59 +00:00
} ;
struct MyMouseCommand
{
btVector3 m_rayFrom ;
btVector3 m_rayTo ;
int m_type ;
} ;
2016-07-08 02:24:44 +00:00
struct MotionArgs
{
MotionArgs ( )
2017-05-18 15:31:40 +00:00
:
m_debugDrawFlags ( 0 ) ,
m_physicsServerPtr ( 0 )
2016-07-08 02:24:44 +00:00
{
2016-09-08 22:15:58 +00:00
for ( int i = 0 ; i < MAX_VR_CONTROLLERS ; i + + )
{
2016-12-27 03:40:09 +00:00
m_vrControllerEvents [ i ] . m_numButtonEvents = 0 ;
m_vrControllerEvents [ i ] . m_numMoveEvents = 0 ;
for ( int b = 0 ; b < MAX_VR_BUTTONS ; b + + )
{
m_vrControllerEvents [ i ] . m_buttons [ b ] = 0 ;
}
2018-05-15 20:24:28 +00:00
m_vrControllerPos [ i ] . setValue ( 0 , 0 , 0 ) ;
m_vrControllerOrn [ i ] . setValue ( 0 , 0 , 0 , 1 ) ;
2016-09-08 22:15:58 +00:00
m_isVrControllerPicking [ i ] = false ;
m_isVrControllerDragging [ i ] = false ;
m_isVrControllerReleasing [ i ] = false ;
m_isVrControllerTeleporting [ i ] = false ;
}
2016-07-08 02:24:44 +00:00
}
b3CriticalSection * m_cs ;
2016-12-29 05:51:54 +00:00
b3CriticalSection * m_cs2 ;
b3CriticalSection * m_cs3 ;
b3CriticalSection * m_csGUI ;
2017-05-16 19:19:03 +00:00
int m_debugDrawFlags ;
2016-11-17 00:12:59 +00:00
btAlignedObjectArray < MyMouseCommand > m_mouseCommands ;
2016-12-27 03:40:09 +00:00
b3VRControllerEvent m_vrControllerEvents [ MAX_VR_CONTROLLERS ] ;
b3VRControllerEvent m_sendVrControllerEvents [ MAX_VR_CONTROLLERS ] ;
2017-03-02 20:33:22 +00:00
btAlignedObjectArray < b3KeyboardEvent > m_keyboardEvents ;
btAlignedObjectArray < b3KeyboardEvent > m_sendKeyEvents ;
2017-06-17 20:29:14 +00:00
btAlignedObjectArray < b3MouseEvent > m_allMouseEvents ;
btAlignedObjectArray < b3MouseEvent > m_sendMouseEvents ;
2016-07-08 02:24:44 +00:00
PhysicsServerSharedMemory * m_physicsServerPtr ;
b3AlignedObjectArray < b3Vector3 > m_positions ;
2016-07-18 06:50:11 +00:00
2016-09-08 22:15:58 +00:00
btVector3 m_vrControllerPos [ MAX_VR_CONTROLLERS ] ;
btQuaternion m_vrControllerOrn [ MAX_VR_CONTROLLERS ] ;
bool m_isVrControllerPicking [ MAX_VR_CONTROLLERS ] ;
bool m_isVrControllerDragging [ MAX_VR_CONTROLLERS ] ;
bool m_isVrControllerReleasing [ MAX_VR_CONTROLLERS ] ;
bool m_isVrControllerTeleporting [ MAX_VR_CONTROLLERS ] ;
2016-07-18 06:50:11 +00:00
2016-07-08 02:24:44 +00:00
} ;
struct MotionThreadLocalStorage
{
int threadId ;
} ;
2017-01-08 20:49:04 +00:00
2016-09-08 22:15:58 +00:00
float clampedDeltaTime = 0.2 ;
2016-07-08 02:24:44 +00:00
2017-01-08 20:49:04 +00:00
2016-07-08 02:24:44 +00:00
void MotionThreadFunc ( void * userPtr , void * lsMemory )
{
2016-07-09 22:09:09 +00:00
printf ( " MotionThreadFunc thread started \n " ) ;
2017-01-16 06:26:11 +00:00
//MotionThreadLocalStorage* localStorage = (MotionThreadLocalStorage*) lsMemory;
2016-07-08 02:24:44 +00:00
MotionArgs * args = ( MotionArgs * ) userPtr ;
2017-01-16 06:26:11 +00:00
//int workLeft = true;
2016-07-08 02:24:44 +00:00
b3Clock clock ;
clock . reset ( ) ;
2017-03-01 21:48:57 +00:00
b3Clock sleepClock ;
2016-07-08 02:24:44 +00:00
bool init = true ;
if ( init )
{
2018-05-16 15:32:21 +00:00
unsigned int cachedSharedParam = eMotionIsInitialized ;
2016-07-08 02:24:44 +00:00
args - > m_cs - > lock ( ) ;
args - > m_cs - > setSharedParam ( 0 , eMotionIsInitialized ) ;
args - > m_cs - > unlock ( ) ;
2016-07-18 06:50:11 +00:00
2016-09-08 22:15:58 +00:00
double deltaTimeInSeconds = 0 ;
2017-03-01 21:48:57 +00:00
int numCmdSinceSleep1ms = 0 ;
2017-03-24 00:30:59 +00:00
unsigned long long int prevTime = clock . getTimeMicroseconds ( ) ;
2018-05-16 15:32:21 +00:00
2016-07-08 02:24:44 +00:00
do
{
{
2017-01-08 20:49:04 +00:00
b3Clock : : usleep ( 0 ) ;
}
2017-03-01 21:48:57 +00:00
{
2017-03-26 20:06:46 +00:00
2017-05-31 02:54:55 +00:00
2017-03-26 20:06:46 +00:00
if ( sleepClock . getTimeMilliseconds ( ) > 1 )
2017-03-04 20:59:21 +00:00
{
sleepClock . reset ( ) ;
2017-03-26 20:06:46 +00:00
numCmdSinceSleep1ms = 0 ;
2017-03-04 20:59:21 +00:00
}
2017-03-04 23:30:57 +00:00
}
2017-03-24 00:30:59 +00:00
unsigned long long int curTime = clock . getTimeMicroseconds ( ) ;
unsigned long long int dtMicro = curTime - prevTime ;
prevTime = curTime ;
# if 1
double dt = double ( dtMicro ) / 1000000. ;
# else
2017-01-08 20:49:04 +00:00
double dt = double ( clock . getTimeMicroseconds ( ) ) / 1000000. ;
2017-01-30 04:59:47 +00:00
clock . reset ( ) ;
2017-03-24 00:30:59 +00:00
# endif
2017-01-08 20:49:04 +00:00
deltaTimeInSeconds + = dt ;
2016-07-18 06:50:11 +00:00
{
2017-03-26 20:06:46 +00:00
2016-07-18 06:50:11 +00:00
//process special controller commands, such as
//VR controller button press/release and controller motion
2016-09-08 22:15:58 +00:00
for ( int c = 0 ; c < MAX_VR_CONTROLLERS ; c + + )
2016-07-18 06:50:11 +00:00
{
2016-09-08 22:15:58 +00:00
btVector3 from = args - > m_vrControllerPos [ c ] ;
btMatrix3x3 mat ( args - > m_vrControllerOrn [ c ] ) ;
btScalar pickDistance = 1000. ;
2016-11-17 00:12:59 +00:00
btVector3 to = from + mat . getColumn ( 0 ) * pickDistance ;
// btVector3 toY = from+mat.getColumn(1)*pickDistance;
// btVector3 toZ = from+mat.getColumn(2)*pickDistance;
2016-09-08 22:15:58 +00:00
if ( args - > m_isVrControllerTeleporting [ c ] )
{
args - > m_isVrControllerTeleporting [ c ] = false ;
2016-11-17 00:12:59 +00:00
args - > m_physicsServerPtr - > pickBody ( from , to ) ;
2016-09-08 22:15:58 +00:00
args - > m_physicsServerPtr - > removePickingConstraint ( ) ;
}
2016-11-30 01:08:47 +00:00
// if (!gEnableKukaControl)
2016-09-08 22:15:58 +00:00
{
2016-10-04 15:53:59 +00:00
if ( args - > m_isVrControllerPicking [ c ] )
{
args - > m_isVrControllerPicking [ c ] = false ;
args - > m_isVrControllerDragging [ c ] = true ;
2016-11-17 00:12:59 +00:00
args - > m_physicsServerPtr - > pickBody ( from , to ) ;
2016-10-04 15:53:59 +00:00
//printf("PICK!\n");
}
2016-09-08 22:15:58 +00:00
}
if ( args - > m_isVrControllerDragging [ c ] )
{
2016-11-17 00:12:59 +00:00
args - > m_physicsServerPtr - > movePickedBody ( from , to ) ;
2016-09-08 22:15:58 +00:00
// printf(".");
}
if ( args - > m_isVrControllerReleasing [ c ] )
{
args - > m_isVrControllerDragging [ c ] = false ;
args - > m_isVrControllerReleasing [ c ] = false ;
args - > m_physicsServerPtr - > removePickingConstraint ( ) ;
//printf("Release pick\n");
}
2016-07-18 06:50:11 +00:00
}
//don't simulate over a huge timestep if we had some interruption (debugger breakpoint etc)
2016-09-08 22:15:58 +00:00
if ( deltaTimeInSeconds > clampedDeltaTime )
{
deltaTimeInSeconds = clampedDeltaTime ;
2016-12-23 23:20:04 +00:00
//b3Warning("Clamp deltaTime from %f to %f",deltaTimeInSeconds, clampedDeltaTime);
2016-09-08 22:15:58 +00:00
}
2016-12-29 05:51:54 +00:00
2016-12-27 03:40:09 +00:00
2016-12-29 05:51:54 +00:00
args - > m_csGUI - > lock ( ) ;
2016-12-27 03:40:09 +00:00
int numSendVrControllers = 0 ;
for ( int i = 0 ; i < MAX_VR_CONTROLLERS ; i + + )
{
if ( args - > m_vrControllerEvents [ i ] . m_numButtonEvents + args - > m_vrControllerEvents [ i ] . m_numMoveEvents )
{
args - > m_sendVrControllerEvents [ numSendVrControllers + + ] =
args - > m_vrControllerEvents [ i ] ;
if ( args - > m_vrControllerEvents [ i ] . m_numButtonEvents )
{
for ( int b = 0 ; b < MAX_VR_BUTTONS ; b + + )
{
args - > m_vrControllerEvents [ i ] . m_buttons [ b ] & = eButtonIsDown ;
}
}
args - > m_vrControllerEvents [ i ] . m_numMoveEvents = 0 ;
args - > m_vrControllerEvents [ i ] . m_numButtonEvents = 0 ;
}
}
2017-03-02 20:33:22 +00:00
args - > m_sendKeyEvents . resize ( args - > m_keyboardEvents . size ( ) ) ;
for ( int i = 0 ; i < args - > m_keyboardEvents . size ( ) ; i + + )
{
args - > m_sendKeyEvents [ i ] = args - > m_keyboardEvents [ i ] ;
if ( args - > m_keyboardEvents [ i ] . m_keyState & eButtonReleased )
{
args - > m_keyboardEvents [ i ] . m_keyState = 0 ;
} else
{
args - > m_keyboardEvents [ i ] . m_keyState & = ~ eButtonTriggered ;
}
}
//remove the 'released' events
for ( int i = args - > m_keyboardEvents . size ( ) - 1 ; i > = 0 ; i - - )
{
if ( args - > m_keyboardEvents [ i ] . m_keyState = = 0 )
{
args - > m_keyboardEvents . removeAtIndex ( i ) ;
}
}
b3KeyboardEvent * keyEvents = args - > m_sendKeyEvents . size ( ) ? & args - > m_sendKeyEvents [ 0 ] : 0 ;
2016-12-29 05:51:54 +00:00
args - > m_csGUI - > unlock ( ) ;
2017-06-17 20:29:14 +00:00
args - > m_csGUI - > lock ( ) ;
if ( gEnableDefaultMousePicking )
{
for ( int i = 0 ; i < args - > m_mouseCommands . size ( ) ; i + + )
{
switch ( args - > m_mouseCommands [ i ] . m_type )
{
case MyMouseMove :
{
args - > m_physicsServerPtr - > movePickedBody ( args - > m_mouseCommands [ i ] . m_rayFrom , args - > m_mouseCommands [ i ] . m_rayTo ) ;
break ;
} ;
case MyMouseButtonDown :
{
args - > m_physicsServerPtr - > pickBody ( args - > m_mouseCommands [ i ] . m_rayFrom , args - > m_mouseCommands [ i ] . m_rayTo ) ;
break ;
}
case MyMouseButtonUp :
{
args - > m_physicsServerPtr - > removePickingConstraint ( ) ;
break ;
}
default :
{
}
}
}
}
args - > m_sendMouseEvents . resize ( args - > m_allMouseEvents . size ( ) ) ;
for ( int i = 0 ; i < args - > m_allMouseEvents . size ( ) ; i + + )
{
args - > m_sendMouseEvents [ i ] = args - > m_allMouseEvents [ i ] ;
}
b3MouseEvent * mouseEvents = args - > m_sendMouseEvents . size ( ) ? & args - > m_sendMouseEvents [ 0 ] : 0 ;
args - > m_allMouseEvents . clear ( ) ;
args - > m_mouseCommands . clear ( ) ;
args - > m_csGUI - > unlock ( ) ;
2016-12-29 05:51:54 +00:00
{
2017-06-17 20:29:14 +00:00
args - > m_physicsServerPtr - > stepSimulationRealTime ( deltaTimeInSeconds , args - > m_sendVrControllerEvents , numSendVrControllers , keyEvents , args - > m_sendKeyEvents . size ( ) , mouseEvents , args - > m_sendMouseEvents . size ( ) ) ;
2016-12-29 05:51:54 +00:00
}
2017-05-16 19:19:03 +00:00
{
if ( gEnableUpdateDebugDrawLines )
{
args - > m_csGUI - > lock ( ) ;
args - > m_physicsServerPtr - > physicsDebugDraw ( args - > m_debugDrawFlags ) ;
gEnableUpdateDebugDrawLines = false ;
args - > m_csGUI - > unlock ( ) ;
}
}
2016-09-08 22:15:58 +00:00
deltaTimeInSeconds = 0 ;
2016-07-08 02:24:44 +00:00
}
2017-06-17 20:29:14 +00:00
2016-11-17 00:12:59 +00:00
2016-12-29 05:51:54 +00:00
{
args - > m_physicsServerPtr - > processClientCommands ( ) ;
2017-03-01 21:48:57 +00:00
numCmdSinceSleep1ms + + ;
2016-12-29 05:51:54 +00:00
}
2016-07-08 02:24:44 +00:00
2018-05-16 15:32:21 +00:00
args - > m_cs - > lock ( ) ;
cachedSharedParam = args - > m_cs - > getSharedParam ( 0 ) ;
args - > m_cs - > unlock ( ) ;
} while ( cachedSharedParam ! = eRequestTerminateMotion ) ;
2016-07-08 02:24:44 +00:00
} else
{
args - > m_cs - > lock ( ) ;
args - > m_cs - > setSharedParam ( 0 , eMotionInitializationFailed ) ;
args - > m_cs - > unlock ( ) ;
}
2017-03-16 16:13:33 +00:00
args - > m_physicsServerPtr - > disconnectSharedMemory ( true ) ;
2016-07-08 02:24:44 +00:00
//do nothing
}
void * MotionlsMemoryFunc ( )
{
//don't create local store memory, just return 0
return new MotionThreadLocalStorage ;
}
2018-05-02 21:32:43 +00:00
void MotionlsMemoryReleaseFunc ( void * ptr )
{
MotionThreadLocalStorage * p = ( MotionThreadLocalStorage * ) ptr ;
delete p ;
}
2016-07-08 02:24:44 +00:00
2016-11-14 15:39:34 +00:00
struct UserDebugDrawLine
{
double m_debugLineFromXYZ [ 3 ] ;
double m_debugLineToXYZ [ 3 ] ;
double m_debugLineColorRGB [ 3 ] ;
double m_lineWidth ;
double m_lifeTime ;
int m_itemUniqueId ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
int m_trackingVisualShapeIndex ;
2018-06-22 23:47:20 +00:00
int m_replaceItemUid ;
2016-11-14 15:39:34 +00:00
} ;
2017-01-17 23:42:32 +00:00
struct UserDebugParameter
{
char m_text [ 1024 ] ;
double m_rangeMin ;
double m_rangeMax ;
2017-01-18 01:38:30 +00:00
btScalar m_value ;
2017-01-17 23:42:32 +00:00
int m_itemUniqueId ;
} ;
2016-11-14 15:39:34 +00:00
struct UserDebugText
{
char m_text [ 1024 ] ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
double m_textPositionXYZ1 [ 3 ] ;
2016-11-14 15:39:34 +00:00
double m_textColorRGB [ 3 ] ;
double textSize ;
double m_lifeTime ;
int m_itemUniqueId ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
double m_textOrientation [ 4 ] ;
int m_trackingVisualShapeIndex ;
int m_optionFlags ;
2016-11-14 15:39:34 +00:00
} ;
2017-05-16 19:19:03 +00:00
struct LineSegment
{
btVector3 m_from ;
btVector3 m_to ;
} ;
struct ColorWidth
{
btVector3FloatData m_color ;
int width ;
int getHash ( ) const
{
unsigned char r = ( unsigned char ) m_color . m_floats [ 0 ] * 255 ;
unsigned char g = ( unsigned char ) m_color . m_floats [ 1 ] * 255 ;
unsigned char b = ( unsigned char ) m_color . m_floats [ 2 ] * 255 ;
unsigned char w = width ;
return r + ( 256 * g ) + ( 256 * 256 * b ) + ( 256 * 256 * 256 * w ) ;
}
bool equals ( const ColorWidth & other ) const
{
bool same = ( ( width = = other . width ) & & ( m_color . m_floats [ 0 ] = = other . m_color . m_floats [ 0 ] ) & &
( m_color . m_floats [ 1 ] = = other . m_color . m_floats [ 1 ] ) & &
( m_color . m_floats [ 2 ] = = other . m_color . m_floats [ 2 ] ) ) ;
return same ;
}
} ;
ATTRIBUTE_ALIGNED16 ( class ) MultithreadedDebugDrawer : public btIDebugDraw
{
print better error warning, in case the physics client/server version mismatch.
fix in b3HashString
remove many unused dependencies from kuka_grasp_block_playback.py (time,math, datetime ,numpy,pylab ,sys, os, fnmatch,argparse were not used!)
move block_grasp_log.bin from Bullet3/data to Bullet3/examples/pybullet/examples/data folder.
PhysicsServerCommandProcessor, derive from CommandProcessorInterface to prepare for different back-end implementation
2017-05-29 00:05:18 +00:00
struct GUIHelperInterface * m_guiHelper ;
2017-05-16 19:19:03 +00:00
int m_debugMode ;
btAlignedObjectArray < btAlignedObjectArray < unsigned int > > m_sortedIndices ;
btAlignedObjectArray < btAlignedObjectArray < btVector3FloatData > > m_sortedLines ;
btHashMap < ColorWidth , int > m_hashedLines ;
public :
void drawDebugDrawerLines ( )
{
if ( m_hashedLines . size ( ) )
{
for ( int i = 0 ; i < m_hashedLines . size ( ) ; i + + )
{
ColorWidth cw = m_hashedLines . getKeyAtIndex ( i ) ;
int index = * m_hashedLines . getAtIndex ( i ) ;
int stride = sizeof ( btVector3FloatData ) ;
const float * positions = & m_sortedLines [ index ] [ 0 ] . m_floats [ 0 ] ;
int numPoints = m_sortedLines [ index ] . size ( ) ;
const unsigned int * indices = & m_sortedIndices [ index ] [ 0 ] ;
int numIndices = m_sortedIndices [ index ] . size ( ) ;
m_guiHelper - > getRenderInterface ( ) - > drawLines ( positions , cw . m_color . m_floats , numPoints , stride , indices , numIndices , cw . width ) ;
}
}
}
MultithreadedDebugDrawer ( GUIHelperInterface * guiHelper )
: m_guiHelper ( guiHelper ) ,
m_debugMode ( 0 )
{
}
virtual ~ MultithreadedDebugDrawer ( )
{
}
virtual void drawLine ( const btVector3 & from , const btVector3 & to , const btVector3 & color )
{
{
ColorWidth cw ;
color . serializeFloat ( cw . m_color ) ;
cw . width = 1 ;
int index = - 1 ;
int * indexPtr = m_hashedLines . find ( cw ) ;
if ( indexPtr )
{
index = * indexPtr ;
} else
{
index = m_sortedLines . size ( ) ;
m_sortedLines . expand ( ) ;
m_sortedIndices . expand ( ) ;
m_hashedLines . insert ( cw , index ) ;
}
btAssert ( index > = 0 ) ;
if ( index > = 0 )
{
btVector3FloatData from1 , toX1 ;
m_sortedIndices [ index ] . push_back ( m_sortedLines [ index ] . size ( ) ) ;
from . serializeFloat ( from1 ) ;
m_sortedLines [ index ] . push_back ( from1 ) ;
m_sortedIndices [ index ] . push_back ( m_sortedLines [ index ] . size ( ) ) ;
to . serializeFloat ( toX1 ) ;
m_sortedLines [ index ] . push_back ( toX1 ) ;
}
}
}
virtual void drawContactPoint ( const btVector3 & PointOnB , const btVector3 & normalOnB , btScalar distance , int lifeTime , const btVector3 & color )
{
drawLine ( PointOnB , PointOnB + normalOnB * distance , color ) ;
btVector3 ncolor ( 0 , 0 , 0 ) ;
drawLine ( PointOnB , PointOnB + normalOnB * 0.01 , ncolor ) ;
}
virtual void reportErrorWarning ( const char * warningString )
{
}
virtual void draw3dText ( const btVector3 & location , const char * textString )
{
}
virtual void setDebugMode ( int debugMode )
{
m_debugMode = debugMode ;
}
virtual int getDebugMode ( ) const
{
return m_debugMode ;
}
virtual void clearLines ( )
{
m_hashedLines . clear ( ) ;
m_sortedIndices . clear ( ) ;
m_sortedLines . clear ( ) ;
}
virtual void flushLines ( )
{
}
} ;
2016-11-14 15:39:34 +00:00
2016-07-08 02:24:44 +00:00
class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface
{
2017-01-16 06:26:11 +00:00
// CommonGraphicsApp* m_app;
2016-07-08 02:24:44 +00:00
b3CriticalSection * m_cs ;
2016-12-29 05:51:54 +00:00
b3CriticalSection * m_cs2 ;
b3CriticalSection * m_cs3 ;
b3CriticalSection * m_csGUI ;
2017-05-16 19:19:03 +00:00
2016-11-14 15:39:34 +00:00
2016-07-08 02:24:44 +00:00
public :
2017-02-22 01:36:54 +00:00
2017-05-16 19:19:03 +00:00
MultithreadedDebugDrawer * m_debugDraw ;
void drawDebugDrawerLines ( )
{
if ( m_debugDraw )
{
m_debugDraw - > drawDebugDrawerLines ( ) ;
}
}
2016-07-08 02:24:44 +00:00
GUIHelperInterface * m_childGuiHelper ;
2016-11-14 15:39:34 +00:00
int m_uidGenerator ;
2016-07-08 02:24:44 +00:00
const unsigned char * m_texels ;
int m_textureWidth ;
int m_textureHeight ;
int m_shapeIndex ;
const float * m_position ;
const float * m_quaternion ;
const float * m_color ;
const float * m_scaling ;
const float * m_vertices ;
int m_numvertices ;
const int * m_indices ;
int m_numIndices ;
int m_primitiveType ;
int m_textureId ;
int m_instanceId ;
2018-05-07 22:57:36 +00:00
bool m_skipGraphicsUpdate ;
2016-12-29 05:51:54 +00:00
void mainThreadRelease ( )
{
BT_PROFILE ( " mainThreadRelease " ) ;
getCriticalSection ( ) - > setSharedParam ( 1 , eGUIHelperIdle ) ;
getCriticalSection3 ( ) - > lock ( ) ;
getCriticalSection2 ( ) - > unlock ( ) ;
getCriticalSection ( ) - > lock ( ) ;
getCriticalSection2 ( ) - > lock ( ) ;
getCriticalSection ( ) - > unlock ( ) ;
getCriticalSection3 ( ) - > unlock ( ) ;
}
void workerThreadWait ( )
{
2018-05-07 22:57:36 +00:00
BT_PROFILE ( " workerThreadWait " ) ;
if ( m_skipGraphicsUpdate )
{
getCriticalSection ( ) - > setSharedParam ( 1 , eGUIHelperIdle ) ;
m_cs - > unlock ( ) ;
return ;
}
2016-12-29 05:51:54 +00:00
m_cs2 - > lock ( ) ;
m_cs - > unlock ( ) ;
m_cs2 - > unlock ( ) ;
m_cs3 - > lock ( ) ;
m_cs3 - > unlock ( ) ;
while ( m_cs - > getSharedParam ( 1 ) ! = eGUIHelperIdle )
{
2017-02-16 22:19:09 +00:00
b3Clock : : usleep ( 0 ) ;
2016-12-29 05:51:54 +00:00
}
}
2016-07-08 02:24:44 +00:00
2018-05-07 22:57:36 +00:00
MultiThreadedOpenGLGuiHelper ( CommonGraphicsApp * app , GUIHelperInterface * guiHelper , int skipGraphicsUpdate )
2017-01-16 06:26:11 +00:00
:
//m_app(app),
m_cs ( 0 ) ,
2016-12-29 05:51:54 +00:00
m_cs2 ( 0 ) ,
m_cs3 ( 0 ) ,
m_csGUI ( 0 ) ,
2017-05-16 19:19:03 +00:00
m_debugDraw ( 0 ) ,
2016-11-14 15:39:34 +00:00
m_uidGenerator ( 0 ) ,
2016-07-08 02:24:44 +00:00
m_texels ( 0 ) ,
2018-05-07 22:57:36 +00:00
m_shapeIndex ( - 1 ) ,
m_textureId ( - 1 ) ,
m_instanceId ( - 1 ) ,
m_skipGraphicsUpdate ( skipGraphicsUpdate )
2016-07-08 02:24:44 +00:00
{
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
m_childGuiHelper = guiHelper ;
2016-07-08 02:24:44 +00:00
}
virtual ~ MultiThreadedOpenGLGuiHelper ( )
{
2017-01-10 22:57:16 +00:00
//delete m_childGuiHelper;
2017-06-08 02:00:44 +00:00
if ( m_debugDraw )
{
delete m_debugDraw ;
m_debugDraw = 0 ;
}
2018-05-02 19:24:31 +00:00
for ( int i = 0 ; i < m_userDebugParams . size ( ) ; i + + )
{
delete m_userDebugParams [ i ] ;
}
m_userDebugParams . clear ( ) ;
2016-07-08 02:24:44 +00:00
}
void setCriticalSection ( b3CriticalSection * cs )
{
m_cs = cs ;
}
b3CriticalSection * getCriticalSection ( )
{
return m_cs ;
}
2016-12-29 05:51:54 +00:00
void setCriticalSection2 ( b3CriticalSection * cs )
{
m_cs2 = cs ;
}
b3CriticalSection * getCriticalSection2 ( )
{
return m_cs2 ;
}
void setCriticalSection3 ( b3CriticalSection * cs )
{
m_cs3 = cs ;
}
void setCriticalSectionGUI ( b3CriticalSection * cs )
{
m_csGUI = cs ;
}
b3CriticalSection * getCriticalSection3 ( )
{
return m_cs3 ;
}
2016-09-22 15:50:28 +00:00
btRigidBody * m_body ;
btVector3 m_color3 ;
virtual void createRigidBodyGraphicsObject ( btRigidBody * body , const btVector3 & color )
{
m_body = body ;
m_color3 = color ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperCreateRigidBodyGraphicsObject ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-09-22 15:50:28 +00:00
}
2016-07-08 02:24:44 +00:00
btCollisionObject * m_obj ;
btVector3 m_color2 ;
virtual void createCollisionObjectGraphicsObject ( btCollisionObject * obj , const btVector3 & color )
{
m_obj = obj ;
m_color2 = color ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperCreateCollisionObjectGraphicsObject ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
}
btCollisionShape * m_colShape ;
virtual void createCollisionShapeGraphicsObject ( btCollisionShape * collisionShape )
{
m_colShape = collisionShape ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperCreateCollisionShapeGraphicsObject ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
}
virtual void syncPhysicsToGraphics ( const btDiscreteDynamicsWorld * rbWorld )
{
//this check is to prevent a crash, in case we removed all graphics instances, but there are still physics objects.
//the check will be obsolete, once we have a better/safer way of synchronizing physics->graphics transforms
2016-12-29 05:51:54 +00:00
if ( m_childGuiHelper - > getRenderInterface ( ) & & m_childGuiHelper - > getRenderInterface ( ) - > getTotalNumInstances ( ) > 0 )
2016-07-08 02:24:44 +00:00
{
m_childGuiHelper - > syncPhysicsToGraphics ( rbWorld ) ;
}
}
virtual void render ( const btDiscreteDynamicsWorld * rbWorld )
{
m_childGuiHelper - > render ( 0 ) ;
}
2016-09-08 22:15:58 +00:00
virtual void createPhysicsDebugDrawer ( btDiscreteDynamicsWorld * rbWorld )
{
2017-05-16 19:19:03 +00:00
btAssert ( rbWorld ) ;
if ( m_debugDraw )
{
delete m_debugDraw ;
m_debugDraw = 0 ;
}
m_debugDraw = new MultithreadedDebugDrawer ( this ) ;
rbWorld - > setDebugDrawer ( m_debugDraw ) ;
//m_childGuiHelper->createPhysicsDebugDrawer(rbWorld);
2016-09-08 22:15:58 +00:00
}
2016-07-08 02:24:44 +00:00
2018-02-22 07:22:16 +00:00
int m_removeTextureUid ;
virtual void removeTexture ( int textureUid )
{
m_removeTextureUid = textureUid ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperRemoveTexture ) ;
workerThreadWait ( ) ;
}
2016-07-08 02:24:44 +00:00
virtual int registerTexture ( const unsigned char * texels , int width , int height )
{
m_texels = texels ;
m_textureWidth = width ;
m_textureHeight = height ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperRegisterTexture ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
return m_textureId ;
}
virtual int registerGraphicsShape ( const float * vertices , int numvertices , const int * indices , int numIndices , int primitiveType , int textureId )
{
m_vertices = vertices ;
m_numvertices = numvertices ;
m_indices = indices ;
m_numIndices = numIndices ;
m_primitiveType = primitiveType ;
m_textureId = textureId ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperRegisterGraphicsShape ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
return m_shapeIndex ;
}
2017-05-16 19:19:03 +00:00
int m_visualizerFlag ;
int m_visualizerEnable ;
void setVisualizerFlag ( int flag , int enable )
{
m_visualizerFlag = flag ;
m_visualizerEnable = enable ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperSetVisualizerFlag ) ;
workerThreadWait ( ) ;
}
void setVisualizerFlagCallback ( VisualizerFlagCallback callback )
{
m_childGuiHelper - > setVisualizerFlagCallback ( callback ) ;
}
2016-07-08 02:24:44 +00:00
virtual int registerGraphicsInstance ( int shapeIndex , const float * position , const float * quaternion , const float * color , const float * scaling )
{
m_shapeIndex = shapeIndex ;
m_position = position ;
m_quaternion = quaternion ;
m_color = color ;
m_scaling = scaling ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperRegisterGraphicsInstance ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
return m_instanceId ;
}
virtual void removeAllGraphicsInstances ( )
{
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperRemoveAllGraphicsInstances ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
}
2017-05-04 00:05:05 +00:00
int m_graphicsInstanceRemove ;
virtual void removeGraphicsInstance ( int graphicsUid )
{
m_graphicsInstanceRemove = graphicsUid ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperRemoveGraphicsInstance ) ;
workerThreadWait ( ) ;
}
2017-06-30 20:35:07 +00:00
int m_getShapeIndex_instance ;
int getShapeIndex_shapeIndex ;
virtual int getShapeIndexFromInstance ( int instance )
{
m_getShapeIndex_instance = instance ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperGetShapeIndexFromInstance ) ;
2018-05-07 22:57:36 +00:00
getShapeIndex_shapeIndex = - 1 ;
2017-06-30 20:35:07 +00:00
workerThreadWait ( ) ;
return getShapeIndex_shapeIndex ;
}
int m_graphicsInstanceChangeTextureId ;
int m_graphicsInstanceChangeTextureShapeIndex ;
virtual void replaceTexture ( int shapeIndex , int textureUid )
{
m_graphicsInstanceChangeTextureShapeIndex = shapeIndex ;
m_graphicsInstanceChangeTextureId = textureUid ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperChangeGraphicsInstanceTextureId ) ;
workerThreadWait ( ) ;
}
2017-05-04 00:05:05 +00:00
2017-07-01 02:11:43 +00:00
int m_changeTextureUniqueId ;
const unsigned char * m_changeTextureRgbTexels ;
int m_changeTextureWidth ;
int m_changeTextureHeight ;
virtual void changeTexture ( int textureUniqueId , const unsigned char * rgbTexels , int width , int height )
{
m_changeTextureUniqueId = textureUniqueId ;
m_changeTextureRgbTexels = rgbTexels ;
m_changeTextureWidth = width ;
m_changeTextureHeight = height ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperChangeTexture ) ;
workerThreadWait ( ) ;
}
2017-05-13 16:18:36 +00:00
double m_rgbaColor [ 4 ] ;
int m_graphicsInstanceChangeColor ;
virtual void changeRGBAColor ( int instanceUid , const double rgbaColor [ 4 ] )
{
m_graphicsInstanceChangeColor = instanceUid ;
m_rgbaColor [ 0 ] = rgbaColor [ 0 ] ;
m_rgbaColor [ 1 ] = rgbaColor [ 1 ] ;
m_rgbaColor [ 2 ] = rgbaColor [ 2 ] ;
m_rgbaColor [ 3 ] = rgbaColor [ 3 ] ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperChangeGraphicsInstanceRGBAColor ) ;
workerThreadWait ( ) ;
}
2017-06-01 19:32:44 +00:00
double m_specularColor [ 3 ] ;
int m_graphicsInstanceChangeSpecular ;
virtual void changeSpecularColor ( int instanceUid , const double specularColor [ 3 ] )
{
m_graphicsInstanceChangeSpecular = instanceUid ;
m_specularColor [ 0 ] = specularColor [ 0 ] ;
m_specularColor [ 1 ] = specularColor [ 1 ] ;
m_specularColor [ 2 ] = specularColor [ 2 ] ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperChangeGraphicsInstanceSpecularColor ) ;
workerThreadWait ( ) ;
}
2016-07-08 02:24:44 +00:00
virtual Common2dCanvasInterface * get2dCanvasInterface ( )
{
2017-06-13 17:53:24 +00:00
return m_childGuiHelper - > get2dCanvasInterface ( ) ;
2016-07-08 02:24:44 +00:00
}
virtual CommonParameterInterface * getParameterInterface ( )
{
return 0 ;
}
virtual CommonRenderInterface * getRenderInterface ( )
{
2016-11-17 00:12:59 +00:00
return m_childGuiHelper - > getRenderInterface ( ) ;
2016-07-08 02:24:44 +00:00
}
virtual CommonGraphicsApp * getAppInterface ( )
{
2016-07-09 22:09:09 +00:00
return m_childGuiHelper - > getAppInterface ( ) ;
2016-07-08 02:24:44 +00:00
}
virtual void setUpAxis ( int axis )
{
m_childGuiHelper - > setUpAxis ( axis ) ;
}
2017-06-01 22:30:37 +00:00
virtual void resetCamera ( float camDist , float yaw , float pitch , float camPosX , float camPosY , float camPosZ )
2016-07-08 02:24:44 +00:00
{
2017-06-01 22:30:37 +00:00
m_childGuiHelper - > resetCamera ( camDist , yaw , pitch , camPosX , camPosY , camPosZ ) ;
2016-07-08 02:24:44 +00:00
}
2017-06-03 01:24:51 +00:00
virtual bool getCameraInfo ( int * width , int * height , float viewMatrix [ 16 ] , float projectionMatrix [ 16 ] , float camUp [ 3 ] , float camForward [ 3 ] , float hor [ 3 ] , float vert [ 3 ] , float * yaw , float * pitch , float * camDist , float camTarget [ 3 ] ) const
2017-04-10 18:03:41 +00:00
{
2017-06-03 01:24:51 +00:00
return m_childGuiHelper - > getCameraInfo ( width , height , viewMatrix , projectionMatrix , camUp , camForward , hor , vert , yaw , pitch , camDist , camTarget ) ;
2017-04-10 18:03:41 +00:00
}
2016-08-08 21:23:44 +00:00
float m_viewMatrix [ 16 ] ;
float m_projectionMatrix [ 16 ] ;
unsigned char * m_pixelsRGBA ;
int m_rgbaBufferSizeInPixels ;
float * m_depthBuffer ;
int m_depthBufferSizeInPixels ;
2016-08-11 21:55:30 +00:00
int * m_segmentationMaskBuffer ;
int m_segmentationMaskBufferSizeInPixels ;
2016-08-08 21:23:44 +00:00
int m_startPixelIndex ;
int m_destinationWidth ;
int m_destinationHeight ;
int * m_numPixelsCopied ;
2016-08-11 21:55:30 +00:00
virtual void copyCameraImageData ( const float viewMatrix [ 16 ] , const float projectionMatrix [ 16 ] ,
unsigned char * pixelsRGBA , int rgbaBufferSizeInPixels ,
float * depthBuffer , int depthBufferSizeInPixels ,
int * segmentationMaskBuffer , int segmentationMaskBufferSizeInPixels ,
int startPixelIndex , int destinationWidth ,
int destinationHeight , int * numPixelsCopied )
2016-07-08 02:24:44 +00:00
{
2016-08-08 21:23:44 +00:00
m_cs - > lock ( ) ;
for ( int i = 0 ; i < 16 ; i + + )
{
m_viewMatrix [ i ] = viewMatrix [ i ] ;
m_projectionMatrix [ i ] = projectionMatrix [ i ] ;
}
m_pixelsRGBA = pixelsRGBA ;
m_rgbaBufferSizeInPixels = rgbaBufferSizeInPixels ;
m_depthBuffer = depthBuffer ;
m_depthBufferSizeInPixels = depthBufferSizeInPixels ;
2016-08-11 21:55:30 +00:00
m_segmentationMaskBuffer = segmentationMaskBuffer ;
m_segmentationMaskBufferSizeInPixels = segmentationMaskBufferSizeInPixels ;
2016-08-08 21:23:44 +00:00
m_startPixelIndex = startPixelIndex ;
m_destinationWidth = destinationWidth ;
m_destinationHeight = destinationHeight ;
m_numPixelsCopied = numPixelsCopied ;
m_cs - > setSharedParam ( 1 , eGUIHelperCopyCameraImageData ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
}
2016-08-08 21:23:44 +00:00
2017-06-13 17:53:24 +00:00
virtual void debugDisplayCameraImageData ( const float viewMatrix [ 16 ] , const float projectionMatrix [ 16 ] ,
unsigned char * pixelsRGBA , int rgbaBufferSizeInPixels ,
float * depthBuffer , int depthBufferSizeInPixels ,
int * segmentationMaskBuffer , int segmentationMaskBufferSizeInPixels ,
int startPixelIndex , int destinationWidth , int destinationHeight , int * numPixelsCopied )
{
m_cs - > lock ( ) ;
for ( int i = 0 ; i < 16 ; i + + )
{
m_viewMatrix [ i ] = viewMatrix [ i ] ;
m_projectionMatrix [ i ] = projectionMatrix [ i ] ;
}
m_pixelsRGBA = pixelsRGBA ;
m_rgbaBufferSizeInPixels = rgbaBufferSizeInPixels ;
m_depthBuffer = depthBuffer ;
m_depthBufferSizeInPixels = depthBufferSizeInPixels ;
m_segmentationMaskBuffer = segmentationMaskBuffer ;
m_segmentationMaskBufferSizeInPixels = segmentationMaskBufferSizeInPixels ;
m_startPixelIndex = startPixelIndex ;
m_destinationWidth = destinationWidth ;
m_destinationHeight = destinationHeight ;
m_numPixelsCopied = numPixelsCopied ;
m_cs - > setSharedParam ( 1 , eGUIHelperDisplayCameraImageData ) ;
workerThreadWait ( ) ;
}
2018-03-19 01:45:54 +00:00
virtual void setProjectiveTextureMatrices ( const float viewMatrix [ 16 ] , const float projectionMatrix [ 16 ] )
{
2018-05-20 02:20:06 +00:00
if ( m_childGuiHelper - > getAppInterface ( ) & & m_childGuiHelper - > getAppInterface ( ) - > m_renderer )
{
m_childGuiHelper - > getAppInterface ( ) - > m_renderer - > setProjectiveTextureMatrices ( viewMatrix , projectionMatrix ) ;
}
2018-03-19 01:45:54 +00:00
}
2018-03-21 04:28:47 +00:00
virtual void setProjectiveTexture ( bool useProjectiveTexture )
{
2018-05-20 02:20:06 +00:00
if ( m_childGuiHelper - > getAppInterface ( ) & & m_childGuiHelper - > getAppInterface ( ) - > m_renderer )
{
m_childGuiHelper - > getAppInterface ( ) - > m_renderer - > setProjectiveTexture ( useProjectiveTexture ) ;
}
2018-03-21 04:28:47 +00:00
}
2016-07-08 02:24:44 +00:00
2016-11-12 02:07:42 +00:00
btDiscreteDynamicsWorld * m_dynamicsWorld ;
2016-07-08 02:24:44 +00:00
virtual void autogenerateGraphicsObjects ( btDiscreteDynamicsWorld * rbWorld )
{
2016-11-12 02:07:42 +00:00
m_dynamicsWorld = rbWorld ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIHelperAutogenerateGraphicsObjects ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-07-08 02:24:44 +00:00
}
virtual void drawText3D ( const char * txt , float posX , float posZY , float posZ , float size )
{
}
2016-11-14 15:39:34 +00:00
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
virtual void drawText3D ( const char * txt , float position [ 3 ] , float orientation [ 4 ] , float color [ 4 ] , float size , int optionFlag )
{
}
2016-11-14 15:39:34 +00:00
btAlignedObjectArray < UserDebugText > m_userDebugText ;
UserDebugText m_tmpText ;
2017-10-10 05:40:53 +00:00
int m_resultUserDebugTextUid ;
2017-10-25 15:15:01 +00:00
virtual int addUserDebugText3D ( const char * txt , const double positionXYZ [ 3 ] , const double orientation [ 4 ] , const double textColorRGB [ 3 ] , double size , double lifeTime , int trackingVisualShapeIndex , int optionFlags , int replaceItemUid )
2016-11-14 15:39:34 +00:00
{
2017-10-25 15:15:01 +00:00
if ( replaceItemUid > = 0 )
{
m_tmpText . m_itemUniqueId = replaceItemUid ;
} else
{
m_tmpText . m_itemUniqueId = m_uidGenerator + + ;
}
2016-11-14 15:39:34 +00:00
m_tmpText . m_lifeTime = lifeTime ;
m_tmpText . textSize = size ;
2017-01-16 06:26:11 +00:00
//int len = strlen(txt);
2016-11-14 15:39:34 +00:00
strcpy ( m_tmpText . m_text , txt ) ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
m_tmpText . m_textPositionXYZ1 [ 0 ] = positionXYZ [ 0 ] ;
m_tmpText . m_textPositionXYZ1 [ 1 ] = positionXYZ [ 1 ] ;
m_tmpText . m_textPositionXYZ1 [ 2 ] = positionXYZ [ 2 ] ;
m_tmpText . m_textOrientation [ 0 ] = orientation [ 0 ] ;
m_tmpText . m_textOrientation [ 1 ] = orientation [ 1 ] ;
m_tmpText . m_textOrientation [ 2 ] = orientation [ 2 ] ;
m_tmpText . m_textOrientation [ 3 ] = orientation [ 3 ] ;
2016-11-14 15:39:34 +00:00
m_tmpText . m_textColorRGB [ 0 ] = textColorRGB [ 0 ] ;
m_tmpText . m_textColorRGB [ 1 ] = textColorRGB [ 1 ] ;
m_tmpText . m_textColorRGB [ 2 ] = textColorRGB [ 2 ] ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
m_tmpText . m_trackingVisualShapeIndex = trackingVisualShapeIndex ;
m_tmpText . m_optionFlags = optionFlags ;
m_tmpText . m_textOrientation [ 0 ] = orientation [ 0 ] ;
m_tmpText . m_textOrientation [ 1 ] = orientation [ 1 ] ;
m_tmpText . m_textOrientation [ 2 ] = orientation [ 2 ] ;
m_tmpText . m_textOrientation [ 3 ] = orientation [ 3 ] ;
2016-11-14 15:39:34 +00:00
m_cs - > lock ( ) ;
2016-11-20 23:38:42 +00:00
m_cs - > setSharedParam ( 1 , eGUIUserDebugAddText ) ;
2018-05-07 22:57:36 +00:00
m_resultUserDebugTextUid = - 1 ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-11-14 15:39:34 +00:00
2017-10-10 05:40:53 +00:00
return m_resultUserDebugTextUid ;
2016-11-14 15:39:34 +00:00
}
2017-01-17 23:42:32 +00:00
btAlignedObjectArray < UserDebugParameter * > m_userDebugParams ;
UserDebugParameter m_tmpParam ;
virtual int readUserDebugParameter ( int itemUniqueId , double * value )
{
for ( int i = 0 ; i < m_userDebugParams . size ( ) ; i + + )
{
if ( m_userDebugParams [ i ] - > m_itemUniqueId = = itemUniqueId )
{
* value = m_userDebugParams [ i ] - > m_value ;
return 1 ;
}
}
return 0 ;
}
2017-10-10 05:40:53 +00:00
int m_userDebugParamUid ;
2017-01-17 23:42:32 +00:00
virtual int addUserDebugParameter ( const char * txt , double rangeMin , double rangeMax , double startValue )
{
strcpy ( m_tmpParam . m_text , txt ) ;
m_tmpParam . m_rangeMin = rangeMin ;
m_tmpParam . m_rangeMax = rangeMax ;
m_tmpParam . m_value = startValue ;
m_tmpParam . m_itemUniqueId = m_uidGenerator + + ;
m_cs - > lock ( ) ;
m_cs - > setSharedParam ( 1 , eGUIUserDebugAddParameter ) ;
2018-05-07 22:57:36 +00:00
m_userDebugParamUid = - 1 ;
2017-01-17 23:42:32 +00:00
workerThreadWait ( ) ;
2017-10-10 05:40:53 +00:00
return m_userDebugParamUid ;
2017-01-17 23:42:32 +00:00
}
2016-11-14 15:39:34 +00:00
btAlignedObjectArray < UserDebugDrawLine > m_userDebugLines ;
2016-11-20 23:38:42 +00:00
UserDebugDrawLine m_tmpLine ;
2017-10-10 05:40:53 +00:00
int m_resultDebugLineUid ;
2018-06-22 23:47:20 +00:00
virtual int addUserDebugLine ( const double debugLineFromXYZ [ 3 ] , const double debugLineToXYZ [ 3 ] , const double debugLineColorRGB [ 3 ] , double lineWidth , double lifeTime , int trackingVisualShapeIndex , int replaceItemUid )
2016-11-14 15:39:34 +00:00
{
2016-11-20 23:38:42 +00:00
m_tmpLine . m_lifeTime = lifeTime ;
m_tmpLine . m_lineWidth = lineWidth ;
2018-06-22 23:47:20 +00:00
m_tmpLine . m_itemUniqueId = replaceItemUid < 0 ? m_uidGenerator + + : replaceItemUid ;
2016-11-20 23:38:42 +00:00
m_tmpLine . m_debugLineFromXYZ [ 0 ] = debugLineFromXYZ [ 0 ] ;
m_tmpLine . m_debugLineFromXYZ [ 1 ] = debugLineFromXYZ [ 1 ] ;
m_tmpLine . m_debugLineFromXYZ [ 2 ] = debugLineFromXYZ [ 2 ] ;
m_tmpLine . m_debugLineToXYZ [ 0 ] = debugLineToXYZ [ 0 ] ;
m_tmpLine . m_debugLineToXYZ [ 1 ] = debugLineToXYZ [ 1 ] ;
m_tmpLine . m_debugLineToXYZ [ 2 ] = debugLineToXYZ [ 2 ] ;
2016-11-14 15:39:34 +00:00
2016-11-20 23:38:42 +00:00
m_tmpLine . m_debugLineColorRGB [ 0 ] = debugLineColorRGB [ 0 ] ;
m_tmpLine . m_debugLineColorRGB [ 1 ] = debugLineColorRGB [ 1 ] ;
m_tmpLine . m_debugLineColorRGB [ 2 ] = debugLineColorRGB [ 2 ] ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
m_tmpLine . m_trackingVisualShapeIndex = trackingVisualShapeIndex ;
2018-06-22 23:47:20 +00:00
m_tmpLine . m_replaceItemUid = replaceItemUid ;
2016-11-14 15:39:34 +00:00
m_cs - > lock ( ) ;
2016-11-20 23:38:42 +00:00
m_cs - > setSharedParam ( 1 , eGUIUserDebugAddLine ) ;
2018-05-07 22:57:36 +00:00
m_resultDebugLineUid = - 1 ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2017-10-10 05:40:53 +00:00
return m_resultDebugLineUid ;
2016-11-14 15:39:34 +00:00
}
int m_removeDebugItemUid ;
virtual void removeUserDebugItem ( int debugItemUniqueId )
{
m_removeDebugItemUid = debugItemUniqueId ;
m_cs - > lock ( ) ;
2016-11-20 23:38:42 +00:00
m_cs - > setSharedParam ( 1 , eGUIUserDebugRemoveItem ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-11-20 01:13:56 +00:00
2016-11-14 15:39:34 +00:00
}
virtual void removeAllUserDebugItems ( )
{
m_cs - > lock ( ) ;
2016-11-20 23:38:42 +00:00
m_cs - > setSharedParam ( 1 , eGUIUserDebugRemoveAllItems ) ;
2016-12-29 05:51:54 +00:00
workerThreadWait ( ) ;
2016-11-14 15:39:34 +00:00
}
2017-05-15 18:39:39 +00:00
2017-03-16 16:13:33 +00:00
const char * m_mp4FileName ;
virtual void dumpFramesToVideo ( const char * mp4FileName )
{
m_cs - > lock ( ) ;
m_mp4FileName = mp4FileName ;
m_cs - > setSharedParam ( 1 , eGUIDumpFramesToVideo ) ;
workerThreadWait ( ) ;
m_mp4FileName = 0 ;
}
2016-07-08 02:24:44 +00:00
} ;
2015-07-14 22:30:17 +00:00
class PhysicsServerExample : public SharedMemoryCommon
{
PhysicsServerSharedMemory m_physicsServer ;
2016-07-08 02:24:44 +00:00
b3ThreadSupportInterface * m_threadSupport ;
MotionArgs m_args [ MAX_MOTION_NUM_THREADS ] ;
MultiThreadedOpenGLGuiHelper * m_multiThreadedHelper ;
2015-08-06 18:59:31 +00:00
bool m_wantsShutdown ;
2017-05-31 02:54:55 +00:00
2015-08-06 18:59:31 +00:00
bool m_isConnected ;
2015-09-03 21:18:22 +00:00
btClock m_clock ;
2015-11-01 20:48:15 +00:00
bool m_replay ;
2017-06-13 17:53:24 +00:00
struct Common2dCanvasInterface * m_canvas ;
int m_canvasRGBIndex ;
int m_canvasDepthIndex ;
int m_canvasSegMaskIndex ;
2017-01-16 06:26:11 +00:00
// int m_options;
2016-07-18 06:50:11 +00:00
2016-10-14 22:06:09 +00:00
# ifdef BT_ENABLE_VR
TinyVRGui * m_tinyVrGui ;
# endif
2015-07-14 22:30:17 +00:00
public :
2016-05-18 23:21:40 +00:00
2017-05-31 02:54:55 +00:00
PhysicsServerExample ( MultiThreadedOpenGLGuiHelper * helper , CommandProcessorCreationInterface * commandProcessorCreator , SharedMemoryInterface * sharedMem = 0 , int options = 0 ) ;
2016-05-18 23:21:40 +00:00
2015-07-14 22:30:17 +00:00
virtual ~ PhysicsServerExample ( ) ;
2016-05-18 23:21:40 +00:00
2015-07-14 22:30:17 +00:00
virtual void initPhysics ( ) ;
2016-05-18 23:21:40 +00:00
2015-07-14 22:30:17 +00:00
virtual void stepSimulation ( float deltaTime ) ;
2016-05-18 23:21:40 +00:00
2017-02-16 22:19:09 +00:00
virtual void updateGraphics ( ) ;
2015-10-29 18:25:50 +00:00
void enableCommandLogging ( )
{
m_physicsServer . enableCommandLogging ( true , " BulletPhysicsCommandLog.bin " ) ;
}
2015-10-30 17:30:48 +00:00
void replayFromLogFile ( )
{
2015-11-01 20:48:15 +00:00
m_replay = true ;
2015-10-30 17:30:48 +00:00
m_physicsServer . replayFromLogFile ( " BulletPhysicsCommandLog.bin " ) ;
}
2016-05-18 23:21:40 +00:00
2015-07-14 22:30:17 +00:00
virtual void resetCamera ( )
{
float dist = 5 ;
2017-06-01 22:30:37 +00:00
float pitch = - 35 ;
float yaw = 50 ;
2015-07-14 22:30:17 +00:00
float targetPos [ 3 ] = { 0 , 0 , 0 } ; //-3,2.8,-2.5};
2017-06-01 22:30:37 +00:00
m_guiHelper - > resetCamera ( dist , yaw , pitch , targetPos [ 0 ] , targetPos [ 1 ] , targetPos [ 2 ] ) ;
2015-07-14 22:30:17 +00:00
}
2016-05-18 23:21:40 +00:00
2015-07-14 22:30:17 +00:00
virtual bool wantsTermination ( ) ;
2015-08-06 18:59:31 +00:00
virtual bool isConnected ( ) ;
2015-08-07 07:13:26 +00:00
virtual void renderScene ( ) ;
2016-11-20 01:13:56 +00:00
void drawUserDebugLines ( ) ;
2016-07-08 02:24:44 +00:00
virtual void exitPhysics ( ) ;
2015-08-07 07:13:26 +00:00
virtual void physicsDebugDraw ( int debugFlags ) ;
2016-05-18 23:21:40 +00:00
2015-09-04 18:28:08 +00:00
btVector3 getRayTo ( int x , int y ) ;
2016-05-18 23:21:40 +00:00
2017-10-06 22:34:25 +00:00
virtual void vrControllerButtonCallback ( int controllerId , int button , int state , float pos [ 4 ] , float orn [ 4 ] ) ;
virtual void vrControllerMoveCallback ( int controllerId , float pos [ 4 ] , float orn [ 4 ] , float analogAxis , float auxAnalogAxes [ 10 ] ) ;
2017-04-08 05:53:36 +00:00
virtual void vrHMDMoveCallback ( int controllerId , float pos [ 4 ] , float orientation [ 4 ] ) ;
virtual void vrGenericTrackerMoveCallback ( int controllerId , float pos [ 4 ] , float orientation [ 4 ] ) ;
2016-07-18 06:50:11 +00:00
2015-09-04 18:28:08 +00:00
virtual bool mouseMoveCallback ( float x , float y )
{
2015-11-01 20:48:15 +00:00
if ( m_replay )
return false ;
2016-11-17 00:12:59 +00:00
CommonRenderInterface * renderer = m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) ; // m_guiHelper->getRenderInterface();
2015-09-04 18:28:08 +00:00
if ( ! renderer )
{
return false ;
}
2017-06-17 20:29:14 +00:00
b3MouseEvent event ;
event . m_buttonState = 0 ;
event . m_buttonIndex = - 1 ;
event . m_mousePosX = x ;
event . m_mousePosY = y ;
event . m_eventType = MOUSE_MOVE_EVENT ;
m_args [ 0 ] . m_csGUI - > lock ( ) ;
m_args [ 0 ] . m_allMouseEvents . push_back ( event ) ;
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2015-09-04 18:28:08 +00:00
btVector3 rayTo = getRayTo ( int ( x ) , int ( y ) ) ;
btVector3 rayFrom ;
renderer - > getActiveCamera ( ) - > getCameraPosition ( rayFrom ) ;
2016-11-17 00:12:59 +00:00
MyMouseCommand cmd ;
cmd . m_rayFrom = rayFrom ;
cmd . m_rayTo = rayTo ;
cmd . m_type = MyMouseMove ;
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > lock ( ) ;
2016-11-17 00:12:59 +00:00
m_args [ 0 ] . m_mouseCommands . push_back ( cmd ) ;
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2015-09-04 18:28:08 +00:00
return false ;
} ;
virtual bool mouseButtonCallback ( int button , int state , float x , float y )
{
2015-11-01 20:48:15 +00:00
if ( m_replay )
return false ;
2015-09-04 18:28:08 +00:00
CommonRenderInterface * renderer = m_guiHelper - > getRenderInterface ( ) ;
2016-05-18 23:21:40 +00:00
2015-09-04 18:28:08 +00:00
if ( ! renderer )
{
return false ;
}
2016-05-18 23:21:40 +00:00
2015-09-04 18:28:08 +00:00
CommonWindowInterface * window = m_guiHelper - > getAppInterface ( ) - > m_window ;
2017-06-17 20:29:14 +00:00
b3MouseEvent event ;
event . m_buttonIndex = button ;
event . m_mousePosX = x ;
event . m_mousePosY = y ;
event . m_eventType = MOUSE_BUTTON_EVENT ;
if ( state )
{
event . m_buttonState = eButtonIsDown + eButtonTriggered ;
} else
{
event . m_buttonState = eButtonReleased ;
}
m_args [ 0 ] . m_csGUI - > lock ( ) ;
m_args [ 0 ] . m_allMouseEvents . push_back ( event ) ;
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2016-05-18 23:21:40 +00:00
2015-09-04 18:28:08 +00:00
if ( state = = 1 )
{
if ( button = = 0 & & ( ! window - > isModifierKeyPressed ( B3G_ALT ) & & ! window - > isModifierKeyPressed ( B3G_CONTROL ) ) )
{
btVector3 camPos ;
renderer - > getActiveCamera ( ) - > getCameraPosition ( camPos ) ;
btVector3 rayFrom = camPos ;
btVector3 rayTo = getRayTo ( int ( x ) , int ( y ) ) ;
2016-11-17 00:12:59 +00:00
MyMouseCommand cmd ;
cmd . m_rayFrom = rayFrom ;
cmd . m_rayTo = rayTo ;
cmd . m_type = MyMouseButtonDown ;
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > lock ( ) ;
2016-11-17 00:12:59 +00:00
m_args [ 0 ] . m_mouseCommands . push_back ( cmd ) ;
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2015-09-04 18:28:08 +00:00
}
} else
{
if ( button = = 0 )
{
2016-11-17 00:12:59 +00:00
//m_physicsServer.removePickingConstraint();
MyMouseCommand cmd ;
cmd . m_rayFrom . setValue ( 0 , 0 , 0 ) ;
cmd . m_rayTo . setValue ( 0 , 0 , 0 ) ;
cmd . m_type = MyMouseButtonUp ;
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > lock ( ) ;
2016-11-17 00:12:59 +00:00
m_args [ 0 ] . m_mouseCommands . push_back ( cmd ) ;
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2015-09-04 18:28:08 +00:00
//remove p2p
}
}
//printf("button=%d, state=%d\n",button,state);
return false ;
}
2017-01-26 03:17:57 +00:00
virtual bool keyboardCallback ( int key , int state ) {
2017-03-02 20:33:22 +00:00
//printf("key=%d, state=%d\n", key,state);
{
int keyIndex = - 1 ;
//is already there?
for ( int i = 0 ; i < m_args [ 0 ] . m_keyboardEvents . size ( ) ; i + + )
{
if ( m_args [ 0 ] . m_keyboardEvents [ i ] . m_keyCode = = key )
{
keyIndex = i ;
break ;
}
}
if ( state )
{
b3KeyboardEvent ev ;
ev . m_keyCode = key ;
ev . m_keyState = eButtonIsDown + eButtonTriggered ;
m_args [ 0 ] . m_csGUI - > lock ( ) ;
if ( keyIndex > = 0 )
{
if ( 0 = = ( m_args [ 0 ] . m_keyboardEvents [ keyIndex ] . m_keyState & eButtonIsDown ) )
{
m_args [ 0 ] . m_keyboardEvents [ keyIndex ] = ev ;
}
} else
{
m_args [ 0 ] . m_keyboardEvents . push_back ( ev ) ;
}
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
} else
{
m_args [ 0 ] . m_csGUI - > lock ( ) ;
b3KeyboardEvent ev ;
ev . m_keyCode = key ;
ev . m_keyState = eButtonReleased ;
if ( keyIndex > = 0 )
{
m_args [ 0 ] . m_keyboardEvents [ keyIndex ] = ev ;
} else
{
m_args [ 0 ] . m_keyboardEvents . push_back ( ev ) ;
}
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
}
}
/*printf("m_args[0].m_keyboardEvents.size()=%d\n", m_args[0].m_keyboardEvents.size());
for ( int i = 0 ; i < m_args [ 0 ] . m_keyboardEvents . size ( ) ; i + + )
{
printf ( " key[%d]=%d state = %d \n " , i , m_args [ 0 ] . m_keyboardEvents [ i ] . m_keyCode , m_args [ 0 ] . m_keyboardEvents [ i ] . m_keyState ) ;
}
*/
2017-05-04 17:51:42 +00:00
double shift = 0.1 ;
CommonWindowInterface * window = m_guiHelper - > getAppInterface ( ) - > m_window ;
if ( window - > isModifierKeyPressed ( B3G_SHIFT ) )
shift = 0.01 ;
2017-05-31 02:54:55 +00:00
btVector3 VRTeleportPos = this - > m_physicsServer . getVRTeleportPosition ( ) ;
2017-06-17 20:29:14 +00:00
if ( gEnableDefaultKeyboardShortcuts )
2017-01-26 03:17:57 +00:00
{
2017-06-17 20:29:14 +00:00
if ( key = = ' w ' & & state )
{
VRTeleportPos [ 0 ] + = shift ;
m_physicsServer . setVRTeleportPosition ( VRTeleportPos ) ;
saveCurrentSettingsVR ( VRTeleportPos ) ;
}
if ( key = = ' s ' & & state )
{
VRTeleportPos [ 0 ] - = shift ;
m_physicsServer . setVRTeleportPosition ( VRTeleportPos ) ;
saveCurrentSettingsVR ( VRTeleportPos ) ;
}
if ( key = = ' a ' & & state )
{
VRTeleportPos [ 1 ] - = shift ;
m_physicsServer . setVRTeleportPosition ( VRTeleportPos ) ;
saveCurrentSettingsVR ( VRTeleportPos ) ;
}
if ( key = = ' d ' & & state )
{
VRTeleportPos [ 1 ] + = shift ;
m_physicsServer . setVRTeleportPosition ( VRTeleportPos ) ;
saveCurrentSettingsVR ( VRTeleportPos ) ;
}
if ( key = = ' q ' & & state )
{
VRTeleportPos [ 2 ] + = shift ;
m_physicsServer . setVRTeleportPosition ( VRTeleportPos ) ;
saveCurrentSettingsVR ( VRTeleportPos ) ;
}
if ( key = = ' e ' & & state )
{
VRTeleportPos [ 2 ] - = shift ;
m_physicsServer . setVRTeleportPosition ( VRTeleportPos ) ;
saveCurrentSettingsVR ( VRTeleportPos ) ;
}
if ( key = = ' z ' & & state )
{
gVRTeleportRotZ + = shift ;
btQuaternion VRTeleportOrn = btQuaternion ( btVector3 ( 0 , 0 , 1 ) , gVRTeleportRotZ ) ;
m_physicsServer . setVRTeleportOrientation ( VRTeleportOrn ) ;
saveCurrentSettingsVR ( VRTeleportPos ) ;
}
2017-01-26 03:17:57 +00:00
}
2017-05-31 02:54:55 +00:00
2017-01-26 03:17:57 +00:00
return false ;
}
2015-08-07 07:13:26 +00:00
virtual void setSharedMemoryKey ( int key )
{
m_physicsServer . setSharedMemoryKey ( key ) ;
}
2016-10-09 01:40:09 +00:00
virtual void processCommandLineArgs ( int argc , char * argv [ ] )
{
b3CommandLineArgs args ( argc , argv ) ;
2016-12-03 01:44:00 +00:00
loadCurrentSettingsVR ( args ) ;
2016-12-29 05:51:54 +00:00
int shmemKey ;
if ( args . GetCmdLineArgument ( " sharedMemoryKey " , shmemKey ) )
{
setSharedMemoryKey ( shmemKey ) ;
}
2017-05-31 02:54:55 +00:00
btVector3 vrTeleportPos = m_physicsServer . getVRTeleportPosition ( ) ;
if ( args . GetCmdLineArgument ( " camPosX " , vrTeleportPos [ 0 ] ) )
2016-11-17 00:12:59 +00:00
{
2017-05-31 02:54:55 +00:00
printf ( " camPosX=%f \n " , vrTeleportPos [ 0 ] ) ;
2016-11-17 00:12:59 +00:00
}
2017-05-31 02:54:55 +00:00
if ( args . GetCmdLineArgument ( " camPosY " , vrTeleportPos [ 1 ] ) )
2016-11-17 00:12:59 +00:00
{
2017-05-31 02:54:55 +00:00
printf ( " camPosY=%f \n " , vrTeleportPos [ 1 ] ) ;
2016-11-17 00:12:59 +00:00
}
2017-05-31 02:54:55 +00:00
if ( args . GetCmdLineArgument ( " camPosZ " , vrTeleportPos [ 2 ] ) )
2016-11-17 00:12:59 +00:00
{
2017-05-31 02:54:55 +00:00
printf ( " camPosZ=%f \n " , vrTeleportPos [ 2 ] ) ;
2016-11-17 00:12:59 +00:00
}
2017-05-31 02:54:55 +00:00
m_physicsServer . setVRTeleportPosition ( vrTeleportPos ) ;
2016-11-17 00:12:59 +00:00
float camRotZ = 0.f ;
if ( args . GetCmdLineArgument ( " camRotZ " , camRotZ ) )
{
printf ( " camRotZ = %f \n " , camRotZ ) ;
btQuaternion ornZ ( btVector3 ( 0 , 0 , 1 ) , camRotZ ) ;
2017-05-31 02:54:55 +00:00
m_physicsServer . setVRTeleportOrientation ( ornZ ) ;
2016-11-17 00:12:59 +00:00
}
2016-10-09 01:40:09 +00:00
2017-02-22 17:33:30 +00:00
if ( args . CheckCmdLineFlag ( " realtimesimulation " ) )
{
//gEnableRealTimeSimVR = true;
m_physicsServer . enableRealTimeSimulation ( true ) ;
}
2017-06-17 20:29:14 +00:00
if ( args . CheckCmdLineFlag ( " disableDefaultKeyboardShortcuts " ) )
{
gEnableDefaultKeyboardShortcuts = false ;
}
if ( args . CheckCmdLineFlag ( " enableDefaultKeyboardShortcuts " ) )
{
gEnableDefaultKeyboardShortcuts = true ;
}
if ( args . CheckCmdLineFlag ( " disableDefaultMousePicking " ) )
{
gEnableDefaultMousePicking = false ;
}
if ( args . CheckCmdLineFlag ( " enableDefaultMousePicking " ) )
{
gEnableDefaultMousePicking = true ;
}
2016-10-23 14:14:50 +00:00
}
2015-08-06 18:59:31 +00:00
2015-07-14 22:30:17 +00:00
} ;
2016-11-17 00:12:59 +00:00
2017-05-31 02:54:55 +00:00
PhysicsServerExample : : PhysicsServerExample ( MultiThreadedOpenGLGuiHelper * helper , CommandProcessorCreationInterface * commandProcessorCreator , SharedMemoryInterface * sharedMem , int options )
2015-07-14 22:30:17 +00:00
: SharedMemoryCommon ( helper ) ,
2017-05-31 02:54:55 +00:00
m_physicsServer ( commandProcessorCreator , sharedMem , 0 ) ,
2015-08-06 18:59:31 +00:00
m_wantsShutdown ( false ) ,
2015-11-01 20:48:15 +00:00
m_isConnected ( false ) ,
2017-06-13 17:53:24 +00:00
m_replay ( false ) ,
m_canvas ( 0 ) ,
m_canvasRGBIndex ( - 1 ) ,
m_canvasDepthIndex ( - 1 ) ,
m_canvasSegMaskIndex ( - 1 )
2017-01-16 06:26:11 +00:00
//m_options(options)
2016-10-14 22:06:09 +00:00
# ifdef BT_ENABLE_VR
, m_tinyVrGui ( 0 )
# endif
2015-07-14 22:30:17 +00:00
{
2016-11-17 00:12:59 +00:00
2016-07-08 02:24:44 +00:00
m_multiThreadedHelper = helper ;
2016-12-23 23:20:04 +00:00
// b3Printf("Started PhysicsServer\n");
2015-07-14 22:30:17 +00:00
}
PhysicsServerExample : : ~ PhysicsServerExample ( )
{
2017-06-13 17:53:24 +00:00
if ( m_canvas )
{
if ( m_canvasRGBIndex > = 0 )
m_canvas - > destroyCanvas ( m_canvasRGBIndex ) ;
if ( m_canvasDepthIndex > = 0 )
m_canvas - > destroyCanvas ( m_canvasDepthIndex ) ;
if ( m_canvasSegMaskIndex > = 0 )
m_canvas - > destroyCanvas ( m_canvasSegMaskIndex ) ;
}
2017-05-31 02:54:55 +00:00
2016-10-14 22:06:09 +00:00
# ifdef BT_ENABLE_VR
delete m_tinyVrGui ;
# endif
2017-01-10 22:57:16 +00:00
2015-07-14 22:30:17 +00:00
bool deInitializeSharedMemory = true ;
m_physicsServer . disconnectSharedMemory ( deInitializeSharedMemory ) ;
2015-08-06 18:59:31 +00:00
m_isConnected = false ;
2017-01-10 22:57:16 +00:00
delete m_multiThreadedHelper ;
2015-08-06 18:59:31 +00:00
}
bool PhysicsServerExample : : isConnected ( )
{
return m_isConnected ;
2015-07-14 22:30:17 +00:00
}
void PhysicsServerExample : : initPhysics ( )
{
///for this testing we use Z-axis up
int upAxis = 2 ;
m_guiHelper - > setUpAxis ( upAxis ) ;
2016-05-18 23:21:40 +00:00
2016-07-08 02:24:44 +00:00
m_threadSupport = createMotionThreadSupport ( MAX_MOTION_NUM_THREADS ) ;
2018-05-15 20:24:28 +00:00
m_isConnected = m_physicsServer . connectSharedMemory ( m_guiHelper ) ;
2018-05-16 15:32:21 +00:00
2016-07-08 02:24:44 +00:00
for ( int i = 0 ; i < m_threadSupport - > getNumTasks ( ) ; i + + )
{
MotionThreadLocalStorage * storage = ( MotionThreadLocalStorage * ) m_threadSupport - > getThreadLocalMemory ( i ) ;
b3Assert ( storage ) ;
storage - > threadId = i ;
//storage->m_sharedMem = data->m_sharedMem;
}
2016-05-18 23:21:40 +00:00
2016-07-08 02:24:44 +00:00
for ( int w = 0 ; w < MAX_MOTION_NUM_THREADS ; w + + )
{
m_args [ w ] . m_cs = m_threadSupport - > createCriticalSection ( ) ;
2016-12-29 05:51:54 +00:00
m_args [ w ] . m_cs2 = m_threadSupport - > createCriticalSection ( ) ;
m_args [ w ] . m_cs3 = m_threadSupport - > createCriticalSection ( ) ;
m_args [ w ] . m_csGUI = m_threadSupport - > createCriticalSection ( ) ;
2018-05-15 20:24:28 +00:00
m_args [ w ] . m_cs - > lock ( ) ;
2016-07-08 02:24:44 +00:00
m_args [ w ] . m_cs - > setSharedParam ( 0 , eMotionIsUnInitialized ) ;
2018-05-15 20:24:28 +00:00
m_args [ w ] . m_cs - > unlock ( ) ;
2016-07-08 02:24:44 +00:00
int numMoving = 0 ;
m_args [ w ] . m_positions . resize ( numMoving ) ;
m_args [ w ] . m_physicsServerPtr = & m_physicsServer ;
2017-01-16 06:26:11 +00:00
//int index = 0;
2016-07-08 02:24:44 +00:00
m_threadSupport - > runTask ( B3_THREAD_SCHEDULE_TASK , ( void * ) & this - > m_args [ w ] , w ) ;
2018-05-15 20:24:28 +00:00
bool isUninitialized = true ;
2016-08-13 19:21:18 +00:00
2018-05-15 20:24:28 +00:00
while ( isUninitialized )
2016-07-08 02:24:44 +00:00
{
2018-05-15 20:24:28 +00:00
m_args [ w ] . m_cs - > lock ( ) ;
isUninitialized = ( m_args [ w ] . m_cs - > getSharedParam ( 0 ) = = eMotionIsUnInitialized ) ;
m_args [ w ] . m_cs - > unlock ( ) ;
# ifdef _WIN32
2016-08-13 19:21:18 +00:00
b3Clock : : usleep ( 1000 ) ;
2018-05-15 20:24:28 +00:00
# endif
2016-07-08 02:24:44 +00:00
}
}
m_args [ 0 ] . m_cs - > setSharedParam ( 1 , eGUIHelperIdle ) ;
m_multiThreadedHelper - > setCriticalSection ( m_args [ 0 ] . m_cs ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > setCriticalSection2 ( m_args [ 0 ] . m_cs2 ) ;
m_multiThreadedHelper - > setCriticalSection3 ( m_args [ 0 ] . m_cs3 ) ;
m_multiThreadedHelper - > setCriticalSectionGUI ( m_args [ 0 ] . m_csGUI ) ;
m_args [ 0 ] . m_cs2 - > lock ( ) ;
2017-06-13 17:53:24 +00:00
{
m_canvas = m_guiHelper - > get2dCanvasInterface ( ) ;
if ( m_canvas )
{
2017-11-18 21:21:20 +00:00
m_canvasRGBIndex = m_canvas - > createCanvas ( " Synthetic Camera RGB data " , gCamVisualizerWidth , gCamVisualizerHeight , 8 , 55 ) ;
m_canvasDepthIndex = m_canvas - > createCanvas ( " Synthetic Camera Depth data " , gCamVisualizerWidth , gCamVisualizerHeight , 8 , 75 + gCamVisualizerHeight ) ;
m_canvasSegMaskIndex = m_canvas - > createCanvas ( " Synthetic Camera Segmentation Mask " , gCamVisualizerWidth , gCamVisualizerHeight , 8 , 95 + gCamVisualizerHeight * 2 ) ;
2017-06-13 17:53:24 +00:00
for ( int i = 0 ; i < gCamVisualizerWidth ; i + + )
{
for ( int j = 0 ; j < gCamVisualizerHeight ; j + + )
{
unsigned char red = 255 ;
unsigned char green = 255 ;
unsigned char blue = 255 ;
unsigned char alpha = 255 ;
if ( i = = j )
{
red = 0 ;
green = 0 ;
blue = 0 ;
}
m_canvas - > setPixel ( m_canvasRGBIndex , i , j , red , green , blue , alpha ) ;
2017-06-13 21:07:58 +00:00
if ( m_canvasSegMaskIndex > = 0 )
m_canvas - > setPixel ( m_canvasDepthIndex , i , j , red , green , blue , alpha ) ;
if ( m_canvasSegMaskIndex > = 0 )
m_canvas - > setPixel ( m_canvasSegMaskIndex , i , j , red , green , blue , alpha ) ;
2017-06-13 17:53:24 +00:00
}
}
m_canvas - > refreshImageData ( m_canvasRGBIndex ) ;
2017-06-13 21:07:58 +00:00
if ( m_canvasDepthIndex > = 0 )
m_canvas - > refreshImageData ( m_canvasDepthIndex ) ;
if ( m_canvasSegMaskIndex > = 0 )
m_canvas - > refreshImageData ( m_canvasSegMaskIndex ) ;
2017-06-13 17:53:24 +00:00
}
}
2015-07-14 22:30:17 +00:00
}
2016-07-08 02:24:44 +00:00
void PhysicsServerExample : : exitPhysics ( )
{
for ( int i = 0 ; i < MAX_MOTION_NUM_THREADS ; i + + )
{
2017-10-10 18:10:42 +00:00
m_args [ i ] . m_cs2 - > unlock ( ) ;
2016-07-08 02:24:44 +00:00
m_args [ i ] . m_cs - > lock ( ) ;
m_args [ i ] . m_cs - > setSharedParam ( 0 , eRequestTerminateMotion ) ;
m_args [ i ] . m_cs - > unlock ( ) ;
}
int numActiveThreads = MAX_MOTION_NUM_THREADS ;
while ( numActiveThreads )
{
int arg0 , arg1 ;
if ( m_threadSupport - > isTaskCompleted ( & arg0 , & arg1 , 0 ) )
{
numActiveThreads - - ;
printf ( " numActiveThreads = %d \n " , numActiveThreads ) ;
} else
{
2017-10-10 18:10:42 +00:00
b3Clock : : usleep ( 0 ) ;
2016-07-08 02:24:44 +00:00
}
2017-01-12 16:06:40 +00:00
//we need to call 'stepSimulation' to make sure that
//other threads get out of blocking state (workerThreadWait)
stepSimulation ( 0 ) ;
2016-07-08 02:24:44 +00:00
} ;
printf ( " stopping threads \n " ) ;
2017-01-10 22:57:16 +00:00
m_threadSupport - > deleteCriticalSection ( m_args [ 0 ] . m_cs ) ;
m_threadSupport - > deleteCriticalSection ( m_args [ 0 ] . m_cs2 ) ;
m_threadSupport - > deleteCriticalSection ( m_args [ 0 ] . m_cs3 ) ;
m_threadSupport - > deleteCriticalSection ( m_args [ 0 ] . m_csGUI ) ;
2016-07-08 02:24:44 +00:00
delete m_threadSupport ;
m_threadSupport = 0 ;
2016-07-09 22:09:09 +00:00
//m_physicsServer.resetDynamicsWorld();
2016-07-08 02:24:44 +00:00
}
2015-07-14 22:30:17 +00:00
bool PhysicsServerExample : : wantsTermination ( )
{
return m_wantsShutdown ;
}
2017-02-16 22:19:09 +00:00
void PhysicsServerExample : : updateGraphics ( )
2015-07-14 22:30:17 +00:00
{
2016-07-08 02:24:44 +00:00
//check if any graphics related tasks are requested
switch ( m_multiThreadedHelper - > getCriticalSection ( ) - > getSharedParam ( 1 ) )
{
case eGUIHelperCreateCollisionShapeGraphicsObject :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperCreateCollisionShapeGraphicsObject " ) ;
2016-07-08 02:24:44 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > createCollisionShapeGraphicsObject ( m_multiThreadedHelper - > m_colShape ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-07-08 02:24:44 +00:00
break ;
}
case eGUIHelperCreateCollisionObjectGraphicsObject :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperCreateCollisionObjectGraphicsObject " ) ;
2016-07-08 02:24:44 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > createCollisionObjectGraphicsObject ( m_multiThreadedHelper - > m_obj ,
m_multiThreadedHelper - > m_color2 ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-07-08 02:24:44 +00:00
break ;
}
2016-09-22 15:50:28 +00:00
case eGUIHelperCreateRigidBodyGraphicsObject :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperCreateRigidBodyGraphicsObject " ) ;
2016-09-22 15:50:28 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > createRigidBodyGraphicsObject ( m_multiThreadedHelper - > m_body , m_multiThreadedHelper - > m_color3 ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-09-22 15:50:28 +00:00
break ;
}
2016-07-08 02:24:44 +00:00
case eGUIHelperRegisterTexture :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperRegisterTexture " ) ;
2016-07-08 02:24:44 +00:00
m_multiThreadedHelper - > m_textureId = m_multiThreadedHelper - > m_childGuiHelper - > registerTexture ( m_multiThreadedHelper - > m_texels ,
m_multiThreadedHelper - > m_textureWidth , m_multiThreadedHelper - > m_textureHeight ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-07-08 02:24:44 +00:00
break ;
}
2018-02-22 07:22:16 +00:00
case eGUIHelperRemoveTexture :
{
B3_PROFILE ( " eGUIHelperRemoveTexture " ) ;
m_multiThreadedHelper - > m_childGuiHelper - > removeTexture ( m_multiThreadedHelper - > m_removeTextureUid ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2016-07-08 02:24:44 +00:00
case eGUIHelperRegisterGraphicsShape :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperRegisterGraphicsShape " ) ;
2016-07-08 02:24:44 +00:00
m_multiThreadedHelper - > m_shapeIndex = m_multiThreadedHelper - > m_childGuiHelper - > registerGraphicsShape (
m_multiThreadedHelper - > m_vertices ,
m_multiThreadedHelper - > m_numvertices ,
m_multiThreadedHelper - > m_indices ,
m_multiThreadedHelper - > m_numIndices ,
m_multiThreadedHelper - > m_primitiveType ,
m_multiThreadedHelper - > m_textureId ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-07-08 02:24:44 +00:00
break ;
}
2017-05-16 19:19:03 +00:00
case eGUIHelperSetVisualizerFlag :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperSetVisualizerFlag " ) ;
2017-05-16 19:19:03 +00:00
int flag = m_multiThreadedHelper - > m_visualizerFlag ;
int enable = m_multiThreadedHelper - > m_visualizerEnable ;
2017-11-17 21:33:27 +00:00
if ( flag = = COV_ENABLE_RGB_BUFFER_PREVIEW )
{
if ( enable )
{
if ( m_canvasRGBIndex < 0 )
{
2017-11-18 21:21:20 +00:00
m_canvasRGBIndex = m_canvas - > createCanvas ( " Synthetic Camera RGB data " , gCamVisualizerWidth , gCamVisualizerHeight , 8 , 55 ) ;
2017-11-17 21:33:27 +00:00
}
} else
{
if ( m_canvasRGBIndex > = 0 )
{
m_canvas - > destroyCanvas ( m_canvasRGBIndex ) ;
m_canvasRGBIndex = - 1 ;
}
}
}
if ( flag = = COV_ENABLE_DEPTH_BUFFER_PREVIEW )
{
if ( enable )
{
if ( m_canvasDepthIndex < 0 )
{
2017-11-18 21:21:20 +00:00
m_canvasDepthIndex = m_canvas - > createCanvas ( " Synthetic Camera Depth data " , gCamVisualizerWidth , gCamVisualizerHeight , 8 , 75 + gCamVisualizerHeight ) ;
2017-11-17 21:33:27 +00:00
}
} else
{
if ( m_canvasDepthIndex > = 0 )
{
m_canvas - > destroyCanvas ( m_canvasDepthIndex ) ;
m_canvasDepthIndex = - 1 ;
}
}
}
if ( flag = = COV_ENABLE_SEGMENTATION_MARK_PREVIEW )
{
if ( enable )
{
if ( m_canvasSegMaskIndex < 0 )
{
2017-11-18 21:21:20 +00:00
m_canvasSegMaskIndex = m_canvas - > createCanvas ( " Synthetic Camera Segmentation Mask " , gCamVisualizerWidth , gCamVisualizerHeight , 8 , 95 + gCamVisualizerHeight * 2 ) ;
2017-11-17 21:33:27 +00:00
}
} else
{
if ( m_canvasSegMaskIndex > = 0 )
{
m_canvas - > destroyCanvas ( m_canvasSegMaskIndex ) ;
m_canvasSegMaskIndex = - 1 ;
}
}
}
2017-05-16 19:19:03 +00:00
if ( flag = = COV_ENABLE_VR_TELEPORTING )
{
print better error warning, in case the physics client/server version mismatch.
fix in b3HashString
remove many unused dependencies from kuka_grasp_block_playback.py (time,math, datetime ,numpy,pylab ,sys, os, fnmatch,argparse were not used!)
move block_grasp_log.bin from Bullet3/data to Bullet3/examples/pybullet/examples/data folder.
PhysicsServerCommandProcessor, derive from CommandProcessorInterface to prepare for different back-end implementation
2017-05-29 00:05:18 +00:00
gEnableTeleporting = ( enable ! = 0 ) ;
2017-05-16 19:19:03 +00:00
}
if ( flag = = COV_ENABLE_VR_PICKING )
{
print better error warning, in case the physics client/server version mismatch.
fix in b3HashString
remove many unused dependencies from kuka_grasp_block_playback.py (time,math, datetime ,numpy,pylab ,sys, os, fnmatch,argparse were not used!)
move block_grasp_log.bin from Bullet3/data to Bullet3/examples/pybullet/examples/data folder.
PhysicsServerCommandProcessor, derive from CommandProcessorInterface to prepare for different back-end implementation
2017-05-29 00:05:18 +00:00
gEnablePicking = ( enable ! = 0 ) ;
2017-05-16 19:19:03 +00:00
}
if ( flag = = COV_ENABLE_SYNC_RENDERING_INTERNAL )
{
print better error warning, in case the physics client/server version mismatch.
fix in b3HashString
remove many unused dependencies from kuka_grasp_block_playback.py (time,math, datetime ,numpy,pylab ,sys, os, fnmatch,argparse were not used!)
move block_grasp_log.bin from Bullet3/data to Bullet3/examples/pybullet/examples/data folder.
PhysicsServerCommandProcessor, derive from CommandProcessorInterface to prepare for different back-end implementation
2017-05-29 00:05:18 +00:00
gEnableSyncPhysicsRendering = ( enable ! = 0 ) ;
2017-05-16 19:19:03 +00:00
}
if ( flag = = COV_ENABLE_RENDERING )
{
print better error warning, in case the physics client/server version mismatch.
fix in b3HashString
remove many unused dependencies from kuka_grasp_block_playback.py (time,math, datetime ,numpy,pylab ,sys, os, fnmatch,argparse were not used!)
move block_grasp_log.bin from Bullet3/data to Bullet3/examples/pybullet/examples/data folder.
PhysicsServerCommandProcessor, derive from CommandProcessorInterface to prepare for different back-end implementation
2017-05-29 00:05:18 +00:00
gEnableRendering = ( enable ! = 0 ) ;
2017-05-16 19:19:03 +00:00
}
2017-06-17 20:29:14 +00:00
if ( flag = = COV_ENABLE_KEYBOARD_SHORTCUTS )
{
gEnableDefaultKeyboardShortcuts = ( enable ! = 0 ) ;
}
if ( flag = = COV_ENABLE_MOUSE_PICKING )
{
gEnableDefaultMousePicking = ( enable ! = 0 ) ;
}
2017-05-16 19:19:03 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > setVisualizerFlag ( m_multiThreadedHelper - > m_visualizerFlag , m_multiThreadedHelper - > m_visualizerEnable ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2016-07-08 02:24:44 +00:00
case eGUIHelperRegisterGraphicsInstance :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperRegisterGraphicsInstance " ) ;
2016-07-08 02:24:44 +00:00
m_multiThreadedHelper - > m_instanceId = m_multiThreadedHelper - > m_childGuiHelper - > registerGraphicsInstance (
m_multiThreadedHelper - > m_shapeIndex ,
m_multiThreadedHelper - > m_position ,
m_multiThreadedHelper - > m_quaternion ,
m_multiThreadedHelper - > m_color ,
m_multiThreadedHelper - > m_scaling ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-07-08 02:24:44 +00:00
break ;
}
case eGUIHelperRemoveAllGraphicsInstances :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperRemoveAllGraphicsInstances " ) ;
2017-05-30 04:55:58 +00:00
# ifdef BT_ENABLE_VR
if ( m_tinyVrGui )
{
delete m_tinyVrGui ;
m_tinyVrGui = 0 ;
}
# endif //BT_ENABLE_VR
2016-07-08 02:24:44 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > removeAllGraphicsInstances ( ) ;
2016-12-29 05:51:54 +00:00
if ( m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) )
{
2017-01-16 16:23:49 +00:00
int numRenderInstances ;
numRenderInstances = m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) - > getTotalNumInstances ( ) ;
2016-12-29 05:51:54 +00:00
b3Assert ( numRenderInstances = = 0 ) ;
}
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-07-09 22:09:09 +00:00
2016-07-08 02:24:44 +00:00
break ;
}
2017-05-04 00:05:05 +00:00
case eGUIHelperRemoveGraphicsInstance :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperRemoveGraphicsInstance " ) ;
2017-05-04 00:05:05 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > removeGraphicsInstance ( m_multiThreadedHelper - > m_graphicsInstanceRemove ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2017-05-13 16:18:36 +00:00
2017-06-30 20:35:07 +00:00
case eGUIHelperGetShapeIndexFromInstance :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperGetShapeIndexFromInstance " ) ;
2017-06-30 20:35:07 +00:00
m_multiThreadedHelper - > getShapeIndex_shapeIndex = m_multiThreadedHelper - > m_childGuiHelper - > getShapeIndexFromInstance ( m_multiThreadedHelper - > m_getShapeIndex_instance ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
case eGUIHelperChangeGraphicsInstanceTextureId :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperChangeGraphicsInstanceTextureId " ) ;
2017-06-30 20:35:07 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > replaceTexture (
m_multiThreadedHelper - > m_graphicsInstanceChangeTextureShapeIndex ,
m_multiThreadedHelper - > m_graphicsInstanceChangeTextureId ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2017-07-01 02:11:43 +00:00
case eGUIHelperChangeTexture :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperChangeTexture " ) ;
2017-07-01 02:11:43 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > changeTexture (
m_multiThreadedHelper - > m_changeTextureUniqueId ,
m_multiThreadedHelper - > m_changeTextureRgbTexels ,
m_multiThreadedHelper - > m_changeTextureWidth ,
m_multiThreadedHelper - > m_changeTextureHeight ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2017-06-30 20:35:07 +00:00
2017-05-13 16:18:36 +00:00
case eGUIHelperChangeGraphicsInstanceRGBAColor :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperChangeGraphicsInstanceRGBAColor " ) ;
2017-05-13 16:18:36 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > changeRGBAColor ( m_multiThreadedHelper - > m_graphicsInstanceChangeColor , m_multiThreadedHelper - > m_rgbaColor ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2017-06-01 19:32:44 +00:00
case eGUIHelperChangeGraphicsInstanceSpecularColor :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperChangeGraphicsInstanceSpecularColor " ) ;
2017-06-01 19:32:44 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > changeSpecularColor ( m_multiThreadedHelper - > m_graphicsInstanceChangeSpecular , m_multiThreadedHelper - > m_specularColor ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2017-06-13 17:53:24 +00:00
case eGUIHelperDisplayCameraImageData :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperDisplayCameraImageData " ) ;
2017-06-13 17:53:24 +00:00
if ( m_canvas )
{
int numBytesPerPixel = 4 ;
int startRGBIndex = m_multiThreadedHelper - > m_startPixelIndex * numBytesPerPixel ;
int endRGBIndex = startRGBIndex + ( * m_multiThreadedHelper - > m_numPixelsCopied * numBytesPerPixel ) ;
int startDepthIndex = m_multiThreadedHelper - > m_startPixelIndex ;
int endDepthIndex = startDepthIndex + ( * m_multiThreadedHelper - > m_numPixelsCopied ) ;
int startSegIndex = m_multiThreadedHelper - > m_startPixelIndex ;
int endSegIndex = startSegIndex + ( * m_multiThreadedHelper - > m_numPixelsCopied ) ;
2017-05-04 00:05:05 +00:00
2017-11-18 23:18:46 +00:00
//btScalar frustumZNear = m_multiThreadedHelper->m_projectionMatrix[14]/(m_multiThreadedHelper->m_projectionMatrix[10]-1);
//btScalar frustumZFar = m_multiThreadedHelper->m_projectionMatrix[14]/(m_multiThreadedHelper->m_projectionMatrix[10]+1);
2017-06-13 17:53:24 +00:00
for ( int i = 0 ; i < gCamVisualizerWidth ; i + + )
{
for ( int j = 0 ; j < gCamVisualizerHeight ; j + + )
{
int xIndex = int ( float ( i ) * ( float ( m_multiThreadedHelper - > m_destinationWidth ) / float ( gCamVisualizerWidth ) ) ) ;
int yIndex = int ( float ( j ) * ( float ( m_multiThreadedHelper - > m_destinationHeight ) / float ( gCamVisualizerHeight ) ) ) ;
2017-06-13 23:04:50 +00:00
btClamp ( xIndex , 0 , m_multiThreadedHelper - > m_destinationWidth ) ;
btClamp ( yIndex , 0 , m_multiThreadedHelper - > m_destinationHeight ) ;
2017-06-13 17:53:24 +00:00
int bytesPerPixel = 4 ; //RGBA
if ( m_canvasRGBIndex > = 0 )
{
int rgbPixelIndex = ( xIndex + yIndex * m_multiThreadedHelper - > m_destinationWidth ) * bytesPerPixel ;
if ( rgbPixelIndex > = startRGBIndex & & rgbPixelIndex < endRGBIndex )
{
m_canvas - > setPixel ( m_canvasRGBIndex , i , j ,
m_multiThreadedHelper - > m_pixelsRGBA [ rgbPixelIndex - startRGBIndex ] ,
m_multiThreadedHelper - > m_pixelsRGBA [ rgbPixelIndex + 1 - startRGBIndex ] ,
m_multiThreadedHelper - > m_pixelsRGBA [ rgbPixelIndex + 2 - startRGBIndex ] ,
255 ) ; //alpha set to 255
}
}
if ( m_canvasDepthIndex > = 0 & & 0 ! = m_multiThreadedHelper - > m_depthBuffer )
{
int depthPixelIndex = ( xIndex + yIndex * m_multiThreadedHelper - > m_destinationWidth ) ;
if ( depthPixelIndex > = startDepthIndex & & depthPixelIndex < endDepthIndex )
{
float depthValue = m_multiThreadedHelper - > m_depthBuffer [ depthPixelIndex - startDepthIndex ] ;
//todo: rescale the depthValue to [0..255]
if ( depthValue > - 1e20 )
{
int rgb = 0 ;
2017-11-18 23:18:46 +00:00
btScalar frustumZNear = 0.1 ;
btScalar frustumZFar = 30 ;
btScalar minDepthValue = frustumZNear ; //todo: compute more reasonably min/max depth range
btScalar maxDepthValue = frustumZFar ;
float depth = depthValue ;
2017-11-19 01:20:21 +00:00
btScalar linearDepth = 255. * ( 2.0 * frustumZNear ) / ( frustumZFar + frustumZNear - depth * ( frustumZFar - frustumZNear ) ) ;
2017-11-18 23:18:46 +00:00
btClamp ( linearDepth , btScalar ( 0 ) , btScalar ( 255 ) ) ;
rgb = linearDepth ;
2017-06-13 17:53:24 +00:00
m_canvas - > setPixel ( m_canvasDepthIndex , i , j ,
rgb ,
rgb ,
255 , 255 ) ; //alpha set to 255
} else
{
m_canvas - > setPixel ( m_canvasDepthIndex , i , j ,
0 ,
0 ,
0 , 255 ) ; //alpha set to 255
}
}
}
if ( m_canvasSegMaskIndex > = 0 & & ( 0 ! = m_multiThreadedHelper - > m_segmentationMaskBuffer ) )
{
int segmentationMaskPixelIndex = ( xIndex + yIndex * m_multiThreadedHelper - > m_destinationWidth ) ;
if ( segmentationMaskPixelIndex > = startSegIndex & & segmentationMaskPixelIndex < endSegIndex )
{
int segmentationMask = m_multiThreadedHelper - > m_segmentationMaskBuffer [ segmentationMaskPixelIndex - startSegIndex ] ;
btVector4 palette [ 4 ] = { btVector4 ( 32 , 255 , 32 , 255 ) ,
btVector4 ( 32 , 32 , 255 , 255 ) ,
btVector4 ( 255 , 255 , 32 , 255 ) ,
btVector4 ( 32 , 255 , 255 , 255 ) } ;
if ( segmentationMask > = 0 )
{
2017-12-28 20:37:07 +00:00
int obIndex = segmentationMask & ( ( 1 < < 24 ) - 1 ) ;
2017-12-28 18:18:35 +00:00
int linkIndex = ( segmentationMask > > 24 ) - 1 ;
btVector4 rgb = palette [ ( obIndex + linkIndex ) & 3 ] ;
2017-06-13 17:53:24 +00:00
m_canvas - > setPixel ( m_canvasSegMaskIndex , i , j ,
rgb . x ( ) ,
rgb . y ( ) ,
rgb . z ( ) , 255 ) ; //alpha set to 255
} else
{
m_canvas - > setPixel ( m_canvasSegMaskIndex , i , j ,
0 ,
0 ,
0 , 255 ) ; //alpha set to 255
}
}
}
}
}
if ( m_canvasRGBIndex > = 0 )
m_canvas - > refreshImageData ( m_canvasRGBIndex ) ;
if ( m_canvasDepthIndex > = 0 )
m_canvas - > refreshImageData ( m_canvasDepthIndex ) ;
if ( m_canvasSegMaskIndex > = 0 )
m_canvas - > refreshImageData ( m_canvasSegMaskIndex ) ;
}
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2016-08-08 21:23:44 +00:00
case eGUIHelperCopyCameraImageData :
{
2018-03-09 17:56:03 +00:00
B3_PROFILE ( " eGUIHelperCopyCameraImageData " ) ;
if ( m_multiThreadedHelper - > m_startPixelIndex = = 0 )
{
m_physicsServer . syncPhysicsToGraphics ( ) ;
}
2017-10-06 20:46:24 +00:00
2016-08-08 21:23:44 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > copyCameraImageData ( m_multiThreadedHelper - > m_viewMatrix ,
2017-01-16 16:23:49 +00:00
m_multiThreadedHelper - > m_projectionMatrix ,
m_multiThreadedHelper - > m_pixelsRGBA ,
m_multiThreadedHelper - > m_rgbaBufferSizeInPixels ,
m_multiThreadedHelper - > m_depthBuffer ,
m_multiThreadedHelper - > m_depthBufferSizeInPixels ,
m_multiThreadedHelper - > m_segmentationMaskBuffer ,
m_multiThreadedHelper - > m_segmentationMaskBufferSizeInPixels ,
m_multiThreadedHelper - > m_startPixelIndex ,
m_multiThreadedHelper - > m_destinationWidth ,
m_multiThreadedHelper - > m_destinationHeight ,
m_multiThreadedHelper - > m_numPixelsCopied ) ;
2017-06-13 17:53:24 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-08-08 21:23:44 +00:00
break ;
}
2016-11-12 02:07:42 +00:00
case eGUIHelperAutogenerateGraphicsObjects :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIHelperAutogenerateGraphicsObjects " ) ;
2016-11-12 02:07:42 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > autogenerateGraphicsObjects ( m_multiThreadedHelper - > m_dynamicsWorld ) ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-11-12 02:07:42 +00:00
break ;
}
2016-11-14 15:39:34 +00:00
2016-11-20 23:38:42 +00:00
case eGUIUserDebugAddText :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIUserDebugAddText " ) ;
2017-10-25 15:15:01 +00:00
bool replaced = false ;
for ( int i = 0 ; i < m_multiThreadedHelper - > m_userDebugText . size ( ) ; i + + )
{
if ( m_multiThreadedHelper - > m_userDebugText [ i ] . m_itemUniqueId = = m_multiThreadedHelper - > m_tmpText . m_itemUniqueId )
{
m_multiThreadedHelper - > m_userDebugText [ i ] = m_multiThreadedHelper - > m_tmpText ;
m_multiThreadedHelper - > m_resultUserDebugTextUid = m_multiThreadedHelper - > m_tmpText . m_itemUniqueId ;
replaced = true ;
}
}
2017-10-06 20:46:24 +00:00
2017-10-25 15:15:01 +00:00
if ( ! replaced )
{
m_multiThreadedHelper - > m_userDebugText . push_back ( m_multiThreadedHelper - > m_tmpText ) ;
m_multiThreadedHelper - > m_resultUserDebugTextUid = m_multiThreadedHelper - > m_userDebugText [ m_multiThreadedHelper - > m_userDebugText . size ( ) - 1 ] . m_itemUniqueId ;
}
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2017-10-25 15:15:01 +00:00
2016-11-20 23:38:42 +00:00
break ;
}
2017-01-17 23:42:32 +00:00
case eGUIUserDebugAddParameter :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIUserDebugAddParameter " ) ;
2017-01-17 23:42:32 +00:00
UserDebugParameter * param = new UserDebugParameter ( m_multiThreadedHelper - > m_tmpParam ) ;
m_multiThreadedHelper - > m_userDebugParams . push_back ( param ) ;
{
SliderParams slider ( param - > m_text , & param - > m_value ) ;
slider . m_minVal = param - > m_rangeMin ;
slider . m_maxVal = param - > m_rangeMax ;
if ( m_multiThreadedHelper - > m_childGuiHelper - > getParameterInterface ( ) )
m_multiThreadedHelper - > m_childGuiHelper - > getParameterInterface ( ) - > registerSliderFloatParameter ( slider ) ;
}
2017-10-10 05:40:53 +00:00
m_multiThreadedHelper - > m_userDebugParamUid = ( * m_multiThreadedHelper - > m_userDebugParams [ m_multiThreadedHelper - > m_userDebugParams . size ( ) - 1 ] ) . m_itemUniqueId ;
2017-01-17 23:42:32 +00:00
//also add actual menu
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2016-11-20 23:38:42 +00:00
case eGUIUserDebugAddLine :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIUserDebugAddLine " ) ;
2018-06-22 23:47:20 +00:00
if ( m_multiThreadedHelper - > m_tmpLine . m_replaceItemUid > = 0 )
{
for ( int i = 0 ; i < m_multiThreadedHelper - > m_userDebugLines . size ( ) ; i + + )
{
if ( m_multiThreadedHelper - > m_userDebugLines [ i ] . m_itemUniqueId = = m_multiThreadedHelper - > m_tmpLine . m_replaceItemUid )
{
m_multiThreadedHelper - > m_userDebugLines [ i ] = m_multiThreadedHelper - > m_tmpLine ;
m_multiThreadedHelper - > m_resultDebugLineUid = m_multiThreadedHelper - > m_tmpLine . m_replaceItemUid ;
}
}
} else
{
m_multiThreadedHelper - > m_userDebugLines . push_back ( m_multiThreadedHelper - > m_tmpLine ) ;
m_multiThreadedHelper - > m_resultDebugLineUid = m_multiThreadedHelper - > m_userDebugLines [ m_multiThreadedHelper - > m_userDebugLines . size ( ) - 1 ] . m_itemUniqueId ;
}
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2018-06-22 23:47:20 +00:00
break ;
2016-11-20 23:38:42 +00:00
}
case eGUIUserDebugRemoveItem :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIUserDebugRemoveItem " ) ;
2016-11-20 23:38:42 +00:00
for ( int i = 0 ; i < m_multiThreadedHelper - > m_userDebugLines . size ( ) ; i + + )
{
if ( m_multiThreadedHelper - > m_userDebugLines [ i ] . m_itemUniqueId = = m_multiThreadedHelper - > m_removeDebugItemUid )
{
m_multiThreadedHelper - > m_userDebugLines . swap ( i , m_multiThreadedHelper - > m_userDebugLines . size ( ) - 1 ) ;
m_multiThreadedHelper - > m_userDebugLines . pop_back ( ) ;
break ;
}
}
for ( int i = 0 ; i < m_multiThreadedHelper - > m_userDebugText . size ( ) ; i + + )
{
if ( m_multiThreadedHelper - > m_userDebugText [ i ] . m_itemUniqueId = = m_multiThreadedHelper - > m_removeDebugItemUid )
{
m_multiThreadedHelper - > m_userDebugText . swap ( i , m_multiThreadedHelper - > m_userDebugText . size ( ) - 1 ) ;
m_multiThreadedHelper - > m_userDebugText . pop_back ( ) ;
break ;
}
}
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-11-20 23:38:42 +00:00
break ;
}
case eGUIUserDebugRemoveAllItems :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIUserDebugRemoveAllItems " ) ;
2016-11-20 23:38:42 +00:00
m_multiThreadedHelper - > m_userDebugLines . clear ( ) ;
m_multiThreadedHelper - > m_userDebugText . clear ( ) ;
m_multiThreadedHelper - > m_uidGenerator = 0 ;
2016-12-29 05:51:54 +00:00
m_multiThreadedHelper - > mainThreadRelease ( ) ;
2016-11-20 23:38:42 +00:00
break ;
}
2017-03-16 16:13:33 +00:00
case eGUIDumpFramesToVideo :
{
2017-10-06 20:46:24 +00:00
B3_PROFILE ( " eGUIDumpFramesToVideo " ) ;
2017-03-16 16:13:33 +00:00
m_multiThreadedHelper - > m_childGuiHelper - > dumpFramesToVideo ( m_multiThreadedHelper - > m_mp4FileName ) ;
m_multiThreadedHelper - > mainThreadRelease ( ) ;
break ;
}
2016-07-08 02:24:44 +00:00
case eGUIHelperIdle :
2016-11-14 15:39:34 +00:00
{
break ;
}
2016-07-08 02:24:44 +00:00
default :
{
2016-11-14 15:39:34 +00:00
btAssert ( 0 ) ;
2016-07-08 02:24:44 +00:00
}
}
2017-02-16 22:19:09 +00:00
}
void PhysicsServerExample : : stepSimulation ( float deltaTime )
{
BT_PROFILE ( " PhysicsServerExample::stepSimulation " ) ;
//this->m_physicsServer.processClientCommands();
for ( int i = m_multiThreadedHelper - > m_userDebugLines . size ( ) - 1 ; i > = 0 ; i - - )
{
if ( m_multiThreadedHelper - > m_userDebugLines [ i ] . m_lifeTime )
{
m_multiThreadedHelper - > m_userDebugLines [ i ] . m_lifeTime - = deltaTime ;
if ( m_multiThreadedHelper - > m_userDebugLines [ i ] . m_lifeTime < = 0 )
{
m_multiThreadedHelper - > m_userDebugLines . swap ( i , m_multiThreadedHelper - > m_userDebugLines . size ( ) - 1 ) ;
m_multiThreadedHelper - > m_userDebugLines . pop_back ( ) ;
}
}
}
for ( int i = m_multiThreadedHelper - > m_userDebugText . size ( ) - 1 ; i > = 0 ; i - - )
{
if ( m_multiThreadedHelper - > m_userDebugText [ i ] . m_lifeTime )
{
m_multiThreadedHelper - > m_userDebugText [ i ] . m_lifeTime - = deltaTime ;
if ( m_multiThreadedHelper - > m_userDebugText [ i ] . m_lifeTime < = 0 )
{
m_multiThreadedHelper - > m_userDebugText . swap ( i , m_multiThreadedHelper - > m_userDebugText . size ( ) - 1 ) ;
m_multiThreadedHelper - > m_userDebugText . pop_back ( ) ;
}
}
}
updateGraphics ( ) ;
2016-07-08 02:24:44 +00:00
2017-01-06 02:30:01 +00:00
2016-07-08 02:24:44 +00:00
{
if ( m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) )
{
m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) - > writeTransforms ( ) ;
}
}
2015-07-14 22:30:17 +00:00
}
2016-09-08 22:15:58 +00:00
static float vrOffset [ 16 ] = { 1 , 0 , 0 , 0 ,
0 , 1 , 0 , 0 ,
0 , 0 , 1 , 0 ,
0 , 0 , 0 , 0 } ;
2016-07-09 22:09:09 +00:00
2016-09-09 18:28:38 +00:00
extern int gDroppedSimulationSteps ;
extern int gNumSteps ;
extern double gDtInSec ;
extern double gSubStep ;
2017-01-06 01:41:58 +00:00
extern btTransform gVRTrackingObjectTr ;
2016-11-17 00:12:59 +00:00
2016-11-20 01:13:56 +00:00
void PhysicsServerExample : : drawUserDebugLines ( )
{
2017-01-16 06:26:11 +00:00
//static char line0[1024];
//static char line1[1024];
2016-11-20 01:13:56 +00:00
//draw all user-debug-lines
//add array of lines
2016-09-09 18:28:38 +00:00
2016-11-20 01:13:56 +00:00
//draw all user- 'text3d' messages
if ( m_multiThreadedHelper )
{
2016-11-20 23:38:42 +00:00
2016-12-27 03:40:09 +00:00
//if gBatchUserDebugLines is true, batch lines based on color+width, to reduce line draw calls
btAlignedObjectArray < btAlignedObjectArray < unsigned int > > sortedIndices ;
btAlignedObjectArray < btAlignedObjectArray < btVector3FloatData > > sortedLines ;
btHashMap < ColorWidth , int > hashedLines ;
2016-11-20 01:13:56 +00:00
for ( int i = 0 ; i < m_multiThreadedHelper - > m_userDebugLines . size ( ) ; i + + )
{
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
2016-11-20 01:13:56 +00:00
btVector3 from ;
from . setValue ( m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineFromXYZ [ 0 ] ,
m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineFromXYZ [ 1 ] ,
m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineFromXYZ [ 2 ] ) ;
btVector3 toX ;
toX . setValue ( m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineToXYZ [ 0 ] ,
m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineToXYZ [ 1 ] ,
m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineToXYZ [ 2 ] ) ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
int graphicsIndex = m_multiThreadedHelper - > m_userDebugLines [ i ] . m_trackingVisualShapeIndex ;
if ( graphicsIndex > = 0 )
{
CommonRenderInterface * renderer = m_guiHelper - > getRenderInterface ( ) ;
if ( renderer )
{
float parentPos [ 3 ] ;
float parentOrn [ 4 ] ;
if ( renderer - > readSingleInstanceTransformToCPU ( parentPos , parentOrn , graphicsIndex ) )
{
btTransform parentTrans ;
parentTrans . setOrigin ( btVector3 ( parentPos [ 0 ] , parentPos [ 1 ] , parentPos [ 2 ] ) ) ;
parentTrans . setRotation ( btQuaternion ( parentOrn [ 0 ] , parentOrn [ 1 ] , parentOrn [ 2 ] , parentOrn [ 3 ] ) ) ;
from = parentTrans * from ;
toX = parentTrans * toX ;
}
}
}
2016-11-20 01:13:56 +00:00
btVector3 color ;
color . setValue ( m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineColorRGB [ 0 ] ,
m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineColorRGB [ 1 ] ,
m_multiThreadedHelper - > m_userDebugLines [ i ] . m_debugLineColorRGB [ 2 ] ) ;
2016-12-27 03:40:09 +00:00
ColorWidth cw ;
color . serializeFloat ( cw . m_color ) ;
cw . width = m_multiThreadedHelper - > m_userDebugLines [ i ] . m_lineWidth ;
int index = - 1 ;
if ( gBatchUserDebugLines )
{
int * indexPtr = hashedLines . find ( cw ) ;
if ( indexPtr )
{
index = * indexPtr ;
} else
{
index = sortedLines . size ( ) ;
sortedLines . expand ( ) ;
sortedIndices . expand ( ) ;
hashedLines . insert ( cw , index ) ;
}
btAssert ( index > = 0 ) ;
if ( index > = 0 )
{
btVector3FloatData from1 , toX1 ;
sortedIndices [ index ] . push_back ( sortedLines [ index ] . size ( ) ) ;
from . serializeFloat ( from1 ) ;
sortedLines [ index ] . push_back ( from1 ) ;
sortedIndices [ index ] . push_back ( sortedLines [ index ] . size ( ) ) ;
toX . serializeFloat ( toX1 ) ;
sortedLines [ index ] . push_back ( toX1 ) ;
}
}
else
{
m_guiHelper - > getAppInterface ( ) - > m_renderer - > drawLine ( from , toX , color , m_multiThreadedHelper - > m_userDebugLines [ i ] . m_lineWidth ) ;
}
}
2016-11-20 01:13:56 +00:00
2016-12-27 03:40:09 +00:00
if ( gBatchUserDebugLines )
{
for ( int i = 0 ; i < hashedLines . size ( ) ; i + + )
{
ColorWidth cw = hashedLines . getKeyAtIndex ( i ) ;
int index = * hashedLines . getAtIndex ( i ) ;
int stride = sizeof ( btVector3FloatData ) ;
const float * positions = & sortedLines [ index ] [ 0 ] . m_floats [ 0 ] ;
int numPoints = sortedLines [ index ] . size ( ) ;
const unsigned int * indices = & sortedIndices [ index ] [ 0 ] ;
int numIndices = sortedIndices [ index ] . size ( ) ;
m_guiHelper - > getAppInterface ( ) - > m_renderer - > drawLines ( positions , cw . m_color . m_floats , numPoints , stride , indices , numIndices , cw . width ) ;
}
2016-11-20 01:13:56 +00:00
}
for ( int i = 0 ; i < m_multiThreadedHelper - > m_userDebugText . size ( ) ; i + + )
{
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
2017-10-11 05:11:32 +00:00
//int optionFlag = 0;//CommonGraphicsApp::eDrawText3D_OrtogonalFaceCamera|CommonGraphicsApp::eDrawText3D_TrueType;
//int optionFlag = CommonGraphicsApp::eDrawText3D_TrueType;
float orientation [ 4 ] = { 0 , 0 , 0 , 1 } ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
//int optionFlag = CommonGraphicsApp::eDrawText3D_OrtogonalFaceCamera;
int optionFlag = 0 ;
2017-10-11 05:11:32 +00:00
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
if ( m_multiThreadedHelper - > m_userDebugText [ i ] . m_optionFlags & CommonGraphicsApp : : eDrawText3D_OrtogonalFaceCamera )
2017-10-11 05:11:32 +00:00
{
optionFlag | = CommonGraphicsApp : : eDrawText3D_OrtogonalFaceCamera ;
} else
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
{
2018-01-15 19:59:00 +00:00
orientation [ 0 ] = ( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textOrientation [ 0 ] ;
orientation [ 1 ] = ( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textOrientation [ 1 ] ;
orientation [ 2 ] = ( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textOrientation [ 2 ] ;
orientation [ 3 ] = ( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textOrientation [ 3 ] ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
optionFlag | = CommonGraphicsApp : : eDrawText3D_TrueType ;
2017-10-11 05:11:32 +00:00
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
}
2017-10-11 05:11:32 +00:00
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
float colorRGBA [ 4 ] = {
2018-01-04 03:17:28 +00:00
( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textColorRGB [ 0 ] ,
( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textColorRGB [ 1 ] ,
( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textColorRGB [ 2 ] ,
( float ) 1. } ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
2018-01-04 03:17:28 +00:00
float pos [ 3 ] = { ( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textPositionXYZ1 [ 0 ] ,
( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textPositionXYZ1 [ 1 ] ,
( float ) m_multiThreadedHelper - > m_userDebugText [ i ] . m_textPositionXYZ1 [ 2 ] } ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
int graphicsIndex = m_multiThreadedHelper - > m_userDebugText [ i ] . m_trackingVisualShapeIndex ;
if ( graphicsIndex > = 0 )
{
CommonRenderInterface * renderer = m_guiHelper - > getRenderInterface ( ) ;
if ( renderer )
{
float parentPos [ 3 ] ;
float parentOrn [ 4 ] ;
if ( renderer - > readSingleInstanceTransformToCPU ( parentPos , parentOrn , graphicsIndex ) )
{
btTransform parentTrans ;
parentTrans . setOrigin ( btVector3 ( parentPos [ 0 ] , parentPos [ 1 ] , parentPos [ 2 ] ) ) ;
parentTrans . setRotation ( btQuaternion ( parentOrn [ 0 ] , parentOrn [ 1 ] , parentOrn [ 2 ] , parentOrn [ 3 ] ) ) ;
btTransform childTr ;
childTr . setOrigin ( btVector3 ( pos [ 0 ] , pos [ 1 ] , pos [ 2 ] ) ) ;
childTr . setRotation ( btQuaternion ( orientation [ 0 ] , orientation [ 1 ] , orientation [ 2 ] , orientation [ 3 ] ) ) ;
btTransform siteTr = parentTrans * childTr ;
pos [ 0 ] = siteTr . getOrigin ( ) [ 0 ] ;
pos [ 1 ] = siteTr . getOrigin ( ) [ 1 ] ;
pos [ 2 ] = siteTr . getOrigin ( ) [ 2 ] ;
btQuaternion siteOrn = siteTr . getRotation ( ) ;
orientation [ 0 ] = siteOrn [ 0 ] ;
orientation [ 1 ] = siteOrn [ 1 ] ;
orientation [ 2 ] = siteOrn [ 2 ] ;
orientation [ 3 ] = siteOrn [ 3 ] ;
}
}
}
2017-10-25 15:15:01 +00:00
{
btAlignedObjectArray < std : : string > pieces ;
btAlignedObjectArray < std : : string > separators ;
separators . push_back ( " \n " ) ;
urdfStringSplit ( pieces , m_multiThreadedHelper - > m_userDebugText [ i ] . m_text , separators ) ;
double sz = m_multiThreadedHelper - > m_userDebugText [ i ] . textSize ;
btTransform tr ;
tr . setIdentity ( ) ;
tr . setOrigin ( btVector3 ( pos [ 0 ] , pos [ 1 ] , pos [ 2 ] ) ) ;
tr . setRotation ( btQuaternion ( orientation [ 0 ] , orientation [ 1 ] , orientation [ 2 ] , orientation [ 3 ] ) ) ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
2017-10-25 15:15:01 +00:00
//float newpos[3]={pos[0]-float(t)*sz,pos[1],pos[2]};
for ( int t = 0 ; t < pieces . size ( ) ; t + + )
{
btTransform offset ;
offset . setIdentity ( ) ;
offset . setOrigin ( btVector3 ( 0 , - float ( t ) * sz , 0 ) ) ;
btTransform result = tr * offset ;
2018-01-04 03:17:28 +00:00
float newpos [ 3 ] = { ( float ) result . getOrigin ( ) [ 0 ] ,
( float ) result . getOrigin ( ) [ 1 ] ,
( float ) result . getOrigin ( ) [ 2 ] } ;
2017-10-25 15:15:01 +00:00
m_guiHelper - > getAppInterface ( ) - > drawText3D ( pieces [ t ] . c_str ( ) ,
newpos , orientation , colorRGBA ,
sz , optionFlag ) ;
}
}
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
/*m_guiHelper->getAppInterface()->drawText3D(m_multiThreadedHelper->m_userDebugText[i].m_text,
2016-11-20 01:13:56 +00:00
m_multiThreadedHelper - > m_userDebugText [ i ] . m_textPositionXYZ [ 0 ] ,
m_multiThreadedHelper - > m_userDebugText [ i ] . m_textPositionXYZ [ 1 ] ,
m_multiThreadedHelper - > m_userDebugText [ i ] . m_textPositionXYZ [ 2 ] ,
m_multiThreadedHelper - > m_userDebugText [ i ] . textSize ) ;
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
*/
2016-11-20 01:13:56 +00:00
}
}
}
2016-09-09 18:28:38 +00:00
2015-08-07 07:13:26 +00:00
void PhysicsServerExample : : renderScene ( )
{
2017-01-06 01:41:58 +00:00
btTransform vrTrans ;
2016-11-17 00:12:59 +00:00
2017-01-06 01:41:58 +00:00
2016-11-17 00:12:59 +00:00
2016-09-19 14:02:43 +00:00
B3_PROFILE ( " PhysicsServerExample::RenderScene " ) ;
2016-11-10 05:01:04 +00:00
2017-05-31 02:54:55 +00:00
if ( m_physicsServer . isRealTimeSimulationEnabled ( ) )
2016-10-14 22:06:09 +00:00
{
static int frameCount = 0 ;
2017-05-30 04:55:58 +00:00
static btScalar prevTime = m_clock . getTimeSeconds ( ) ;
2016-10-14 22:06:09 +00:00
frameCount + + ;
2017-05-30 04:55:58 +00:00
static char line0 [ 1024 ] = { 0 } ;
static char line1 [ 1024 ] = { 0 } ;
2017-01-16 06:26:11 +00:00
#if 0
2016-10-14 22:06:09 +00:00
static btScalar worseFps = 1000000 ;
int numFrames = 200 ;
static int count = 0 ;
count + + ;
2017-05-30 04:55:58 +00:00
2016-10-14 22:06:09 +00:00
if ( 0 = = ( count & 1 ) )
{
btScalar curTime = m_clock . getTimeSeconds ( ) ;
btScalar fps = 1. / ( curTime - prevTime ) ;
prevTime = curTime ;
if ( fps < worseFps )
{
worseFps = fps ;
}
if ( count > numFrames )
{
count = 0 ;
sprintf ( line0 , " fps:%f frame:%d " , worseFps , frameCount / 2 ) ;
sprintf ( line1 , " drop:%d tscale:%f dt:%f, substep %f) " , gDroppedSimulationSteps , simTimeScalingFactor , gDtInSec , gSubStep ) ;
gDroppedSimulationSteps = 0 ;
worseFps = 1000000 ;
}
}
2016-11-20 01:13:56 +00:00
# endif
2016-10-14 22:06:09 +00:00
# ifdef BT_ENABLE_VR
2016-10-23 14:14:50 +00:00
if ( ( gInternalSimFlags & 2 ) & & m_tinyVrGui = = 0 )
2016-10-14 22:06:09 +00:00
{
ComboBoxParams comboParams ;
comboParams . m_comboboxId = 0 ;
comboParams . m_numItems = 0 ;
comboParams . m_startItem = 0 ;
comboParams . m_callback = 0 ; //MyComboBoxCallback;
comboParams . m_userPointer = 0 ; //this;
m_tinyVrGui = new TinyVRGui ( comboParams , this - > m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) ) ;
m_tinyVrGui - > init ( ) ;
}
if ( m_tinyVrGui )
{
2016-09-19 14:02:43 +00:00
2016-10-14 22:06:09 +00:00
b3Transform tr ; tr . setIdentity ( ) ;
2017-05-31 02:54:55 +00:00
btVector3 VRController2Pos = m_physicsServer . getVRTeleportPosition ( ) ;
btQuaternion VRController2Orn = m_physicsServer . getVRTeleportOrientation ( ) ;
tr . setOrigin ( b3MakeVector3 ( VRController2Pos [ 0 ] , VRController2Pos [ 1 ] , VRController2Pos [ 2 ] ) ) ;
tr . setRotation ( b3Quaternion ( VRController2Orn [ 0 ] , VRController2Orn [ 1 ] , VRController2Orn [ 2 ] , VRController2Orn [ 3 ] ) ) ;
2016-10-14 22:06:09 +00:00
tr = tr * b3Transform ( b3Quaternion ( 0 , 0 , - SIMD_HALF_PI ) , b3MakeVector3 ( 0 , 0 , 0 ) ) ;
b3Scalar dt = 0.01 ;
m_tinyVrGui - > clearTextArea ( ) ;
m_tinyVrGui - > grapicalPrintf ( line0 , 0 , 0 , 0 , 0 , 0 , 255 ) ;
m_tinyVrGui - > grapicalPrintf ( line1 , 0 , 16 , 255 , 255 , 255 , 255 ) ;
m_tinyVrGui - > tick ( dt , tr ) ;
}
# endif //BT_ENABLE_VR
}
2015-08-07 07:13:26 +00:00
///debug rendering
2016-07-08 02:24:44 +00:00
//m_args[0].m_cs->lock();
2016-09-15 23:57:00 +00:00
//gVRTeleportPos[0] += 0.01;
2016-11-17 00:12:59 +00:00
btTransform tr2a , tr2 ;
tr2a . setIdentity ( ) ;
tr2 . setIdentity ( ) ;
2017-05-31 02:54:55 +00:00
tr2 . setOrigin ( m_physicsServer . getVRTeleportPosition ( ) ) ;
tr2a . setRotation ( m_physicsServer . getVRTeleportOrientation ( ) ) ;
2016-11-17 00:12:59 +00:00
btTransform trTotal = tr2 * tr2a ;
btTransform trInv = trTotal . inverse ( ) ;
btMatrix3x3 vrOffsetRot ;
vrOffsetRot . setRotation ( trInv . getRotation ( ) ) ;
for ( int i = 0 ; i < 3 ; i + + )
{
for ( int j = 0 ; j < 3 ; j + + )
{
vrOffset [ i + 4 * j ] = vrOffsetRot [ i ] [ j ] ;
}
}
vrOffset [ 12 ] = trInv . getOrigin ( ) [ 0 ] ;
vrOffset [ 13 ] = trInv . getOrigin ( ) [ 1 ] ;
vrOffset [ 14 ] = trInv . getOrigin ( ) [ 2 ] ;
2016-09-08 22:15:58 +00:00
2016-12-29 05:51:54 +00:00
if ( m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) )
{
m_multiThreadedHelper - > m_childGuiHelper - > getRenderInterface ( ) - >
2016-09-08 22:15:58 +00:00
getActiveCamera ( ) - > setVRCameraOffsetTransform ( vrOffset ) ;
2016-12-29 05:51:54 +00:00
}
2017-05-16 19:19:03 +00:00
if ( gEnableRendering )
{
int renderFlags = 0 ;
if ( ! gEnableSyncPhysicsRendering )
{
renderFlags | = 1 ; //COV_DISABLE_SYNC_RENDERING;
}
m_physicsServer . renderScene ( renderFlags ) ;
}
2016-07-18 06:50:11 +00:00
2017-05-15 18:39:39 +00:00
if ( gEnablePicking )
2016-07-18 06:50:11 +00:00
{
2017-05-15 18:39:39 +00:00
for ( int i = 0 ; i < MAX_VR_CONTROLLERS ; i + + )
2016-09-08 22:15:58 +00:00
{
2017-05-15 18:39:39 +00:00
if ( m_args [ 0 ] . m_isVrControllerPicking [ i ] | | m_args [ 0 ] . m_isVrControllerDragging [ i ] )
{
btVector3 from = m_args [ 0 ] . m_vrControllerPos [ i ] ;
btMatrix3x3 mat ( m_args [ 0 ] . m_vrControllerOrn [ i ] ) ;
2016-07-18 06:50:11 +00:00
2017-05-15 18:39:39 +00:00
btVector3 toX = from + mat . getColumn ( 0 ) ;
btVector3 toY = from + mat . getColumn ( 1 ) ;
btVector3 toZ = from + mat . getColumn ( 2 ) ;
2016-07-18 06:50:11 +00:00
2017-05-15 18:39:39 +00:00
int width = 2 ;
2016-07-18 06:50:11 +00:00
2017-05-15 18:39:39 +00:00
btVector4 color ;
color = btVector4 ( 1 , 0 , 0 , 1 ) ;
m_guiHelper - > getAppInterface ( ) - > m_renderer - > drawLine ( from , toX , color , width ) ;
color = btVector4 ( 0 , 1 , 0 , 1 ) ;
m_guiHelper - > getAppInterface ( ) - > m_renderer - > drawLine ( from , toY , color , width ) ;
color = btVector4 ( 0 , 0 , 1 , 1 ) ;
m_guiHelper - > getAppInterface ( ) - > m_renderer - > drawLine ( from , toZ , color , width ) ;
2016-07-18 06:50:11 +00:00
2017-05-15 18:39:39 +00:00
}
2016-09-08 22:15:58 +00:00
}
2016-07-18 06:50:11 +00:00
}
2016-07-09 22:09:09 +00:00
if ( m_guiHelper - > getAppInterface ( ) - > m_renderer - > getActiveCamera ( ) - > isVRCamera ( ) )
{
2017-09-02 18:35:54 +00:00
if ( ! m_physicsServer . isRealTimeSimulationEnabled ( ) & & ! gActivedVRRealTimeSimulation )
2016-12-11 17:28:36 +00:00
{
2017-09-02 18:35:54 +00:00
//only activate real-time simulation once (for backward compatibility)
gActivedVRRealTimeSimulation = true ;
2016-12-11 17:28:36 +00:00
m_physicsServer . enableRealTimeSimulation ( 1 ) ;
}
2016-09-22 15:50:28 +00:00
}
2017-10-11 05:11:32 +00:00
drawUserDebugLines ( ) ;
2016-09-22 15:50:28 +00:00
2016-07-09 22:09:09 +00:00
2016-07-08 02:24:44 +00:00
//m_args[0].m_cs->unlock();
2015-08-07 07:13:26 +00:00
}
void PhysicsServerExample : : physicsDebugDraw ( int debugDrawFlags )
{
Improve debug text/line rendering, can be use to draw frames and text in local coordinate of an object / link.
example:
kuka = p.loadURDF("kuka_iiwa/model.urdf")
p.getNumJoints(kuka)
pybullet.addUserDebugLine([0,0,0],[0,0,0.1],[0,0,1],trackObjectUniqueId=2,trackLinkIndex=6)
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],trackObjectUniqueId=2,trackLinkIndex=6)
Also allow to render text using a given orientation (instead of pointing to the camera), example:
pybullet.addUserDebugText("tip", [0,0,0.1],textColorRGB=[1,0,0],textOrientation=[0,0,0,1], trackObjectUniqueId=2,trackLinkIndex=6)
Add drawTexturedTriangleMesh, for drawing 3d text.
Expose readSingleInstanceTransformToCPU, to extract position/orientation from graphics index.
updateTexture: allow to not flip texels around up axis
2017-05-24 05:05:26 +00:00
if ( gEnableSyncPhysicsRendering )
{
m_physicsServer . syncPhysicsToGraphics ( ) ;
}
2016-11-20 01:13:56 +00:00
drawUserDebugLines ( ) ;
2017-05-16 19:19:03 +00:00
if ( gEnableRendering )
{
///debug rendering
//m_physicsServer.physicsDebugDraw(debugDrawFlags);
m_args [ 0 ] . m_csGUI - > lock ( ) ;
//draw stuff and flush?
this - > m_multiThreadedHelper - > m_debugDraw - > drawDebugDrawerLines ( ) ;
m_args [ 0 ] . m_debugDrawFlags = debugDrawFlags ;
gEnableUpdateDebugDrawLines = true ;
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2015-08-07 07:13:26 +00:00
2017-05-16 19:19:03 +00:00
}
2015-08-07 07:13:26 +00:00
}
2015-07-14 22:30:17 +00:00
2015-09-04 18:28:08 +00:00
btVector3 PhysicsServerExample : : getRayTo ( int x , int y )
{
CommonRenderInterface * renderer = m_guiHelper - > getRenderInterface ( ) ;
2016-05-18 23:21:40 +00:00
2015-09-04 18:28:08 +00:00
if ( ! renderer )
{
btAssert ( 0 ) ;
return btVector3 ( 0 , 0 , 0 ) ;
}
2017-10-08 18:34:42 +00:00
2015-09-04 18:28:08 +00:00
float top = 1.f ;
float bottom = - 1.f ;
float nearPlane = 1.f ;
float tanFov = ( top - bottom ) * 0.5f / nearPlane ;
float fov = btScalar ( 2.0 ) * btAtan ( tanFov ) ;
btVector3 camPos , camTarget ;
renderer - > getActiveCamera ( ) - > getCameraPosition ( camPos ) ;
renderer - > getActiveCamera ( ) - > getCameraTargetPosition ( camTarget ) ;
2016-09-08 22:15:58 +00:00
2015-09-04 18:28:08 +00:00
btVector3 rayFrom = camPos ;
btVector3 rayForward = ( camTarget - camPos ) ;
rayForward . normalize ( ) ;
float farPlane = 10000.f ;
rayForward * = farPlane ;
btVector3 rightOffset ;
btVector3 cameraUp = btVector3 ( 0 , 0 , 0 ) ;
cameraUp [ m_guiHelper - > getAppInterface ( ) - > getUpAxis ( ) ] = 1 ;
btVector3 vertical = cameraUp ;
btVector3 hor ;
hor = rayForward . cross ( vertical ) ;
hor . normalize ( ) ;
vertical = hor . cross ( rayForward ) ;
vertical . normalize ( ) ;
float tanfov = tanf ( 0.5f * fov ) ;
hor * = 2.f * farPlane * tanfov ;
vertical * = 2.f * farPlane * tanfov ;
btScalar aspect ;
float width = float ( renderer - > getScreenWidth ( ) ) ;
float height = float ( renderer - > getScreenHeight ( ) ) ;
aspect = width / height ;
hor * = aspect ;
btVector3 rayToCenter = rayFrom + rayForward ;
btVector3 dHor = hor * 1.f / width ;
btVector3 dVert = vertical * 1.f / height ;
btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical ;
rayTo + = btScalar ( x ) * dHor ;
rayTo - = btScalar ( y ) * dVert ;
return rayTo ;
}
2015-07-14 22:30:17 +00:00
2015-10-29 18:25:50 +00:00
2016-09-08 22:15:58 +00:00
2016-07-18 06:50:11 +00:00
void PhysicsServerExample : : vrControllerButtonCallback ( int controllerId , int button , int state , float pos [ 4 ] , float orn [ 4 ] )
{
2016-09-08 22:15:58 +00:00
//printf("controllerId %d, button=%d\n",controllerId, button);
2016-09-09 18:28:38 +00:00
if ( controllerId < 0 | | controllerId > = MAX_VR_CONTROLLERS )
2016-09-08 22:15:58 +00:00
return ;
2016-09-15 23:57:00 +00:00
if ( gGraspingController < 0 )
2016-12-03 01:44:00 +00:00
{
2016-09-15 23:57:00 +00:00
gGraspingController = controllerId ;
2016-12-03 01:44:00 +00:00
}
2016-12-27 03:40:09 +00:00
btTransform trLocal ;
trLocal . setIdentity ( ) ;
trLocal . setRotation ( btQuaternion ( btVector3 ( 0 , 0 , 1 ) , SIMD_HALF_PI ) * btQuaternion ( btVector3 ( 0 , 1 , 0 ) , SIMD_HALF_PI ) ) ;
btTransform trOrg ;
trOrg . setIdentity ( ) ;
trOrg . setOrigin ( btVector3 ( pos [ 0 ] , pos [ 1 ] , pos [ 2 ] ) ) ;
trOrg . setRotation ( btQuaternion ( orn [ 0 ] , orn [ 1 ] , orn [ 2 ] , orn [ 3 ] ) ) ;
btTransform tr2a ;
tr2a . setIdentity ( ) ;
btTransform tr2 ;
tr2 . setIdentity ( ) ;
2017-05-31 02:54:55 +00:00
tr2 . setOrigin ( m_physicsServer . getVRTeleportPosition ( ) ) ;
tr2a . setRotation ( m_physicsServer . getVRTeleportOrientation ( ) ) ;
2016-12-27 03:40:09 +00:00
btTransform trTotal = tr2 * tr2a * trOrg * trLocal ;
2016-09-12 18:10:20 +00:00
if ( controllerId ! = gGraspingController )
2016-09-08 22:15:58 +00:00
{
2016-09-12 18:10:20 +00:00
if ( button = = 1 & & state = = 0 )
{
2017-05-31 02:54:55 +00:00
2016-09-12 18:10:20 +00:00
}
2016-09-22 15:50:28 +00:00
} else
{
if ( button = = 1 )
{
if ( state = = 1 )
{
gDebugRenderToggle = 1 ;
} else
{
gDebugRenderToggle = 0 ;
2016-11-30 01:08:47 +00:00
#if 0 //it confuses people, make it into a debug option in a VR GUI?
2016-09-22 15:50:28 +00:00
if ( simTimeScalingFactor = = 0 )
{
simTimeScalingFactor = 1 ;
2016-09-24 18:25:05 +00:00
} else
2016-09-22 15:50:28 +00:00
{
2016-09-24 18:25:05 +00:00
if ( simTimeScalingFactor = = 1 )
{
simTimeScalingFactor = 0.25 ;
}
else
{
simTimeScalingFactor = 0 ;
}
2016-09-22 15:50:28 +00:00
}
2016-11-30 01:08:47 +00:00
# endif
2016-09-22 15:50:28 +00:00
}
} else
{
}
2016-09-08 22:15:58 +00:00
}
2016-11-17 00:12:59 +00:00
2016-09-08 22:15:58 +00:00
if ( button = = 32 & & state = = 0 )
{
2016-11-17 00:12:59 +00:00
if ( controllerId = = gGraspingController )
{
}
else
{
2016-11-30 01:08:47 +00:00
// gEnableKukaControl = !gEnableKukaControl;
2016-11-17 00:12:59 +00:00
}
2016-09-08 22:15:58 +00:00
}
2016-09-09 21:30:37 +00:00
2017-05-15 18:39:39 +00:00
if ( button = = 1 & & gEnableTeleporting )
2016-09-08 22:15:58 +00:00
{
m_args [ 0 ] . m_isVrControllerTeleporting [ controllerId ] = true ;
}
2016-09-12 18:10:20 +00:00
if ( controllerId = = gGraspingController & & ( button = = 33 ) )
2016-09-08 22:15:58 +00:00
{
2017-05-31 02:54:55 +00:00
2016-09-08 22:15:58 +00:00
}
2016-09-09 21:30:37 +00:00
else
2016-09-08 22:15:58 +00:00
{
2016-09-09 21:30:37 +00:00
2017-05-15 18:39:39 +00:00
if ( button = = 33 & & gEnablePicking )
2016-09-09 21:30:37 +00:00
{
m_args [ 0 ] . m_isVrControllerPicking [ controllerId ] = ( state ! = 0 ) ;
m_args [ 0 ] . m_isVrControllerReleasing [ controllerId ] = ( state = = 0 ) ;
}
2016-11-17 00:12:59 +00:00
2016-09-09 21:30:37 +00:00
if ( ( button = = 33 ) | | ( button = = 1 ) )
{
2016-11-17 00:12:59 +00:00
// m_args[0].m_vrControllerPos[controllerId].setValue(pos[0] + gVRTeleportPos[0], pos[1] + gVRTeleportPos[1], pos[2] + gVRTeleportPos[2]);
// m_args[0].m_vrControllerOrn[controllerId].setValue(orn[0], orn[1], orn[2], orn[3]);
m_args [ 0 ] . m_vrControllerPos [ controllerId ] = trTotal . getOrigin ( ) ;
m_args [ 0 ] . m_vrControllerOrn [ controllerId ] = trTotal . getRotation ( ) ;
2016-09-09 21:30:37 +00:00
}
2016-11-17 00:12:59 +00:00
2016-09-08 22:15:58 +00:00
}
2016-12-27 03:40:09 +00:00
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > lock ( ) ;
2016-12-27 03:40:09 +00:00
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_controllerId = controllerId ;
2017-04-08 05:53:36 +00:00
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_deviceType = VR_DEVICE_CONTROLLER ;
2016-12-27 03:40:09 +00:00
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 0 ] = trTotal . getOrigin ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 1 ] = trTotal . getOrigin ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 2 ] = trTotal . getOrigin ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 0 ] = trTotal . getRotation ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 1 ] = trTotal . getRotation ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 2 ] = trTotal . getRotation ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 3 ] = trTotal . getRotation ( ) [ 3 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_numButtonEvents + + ;
if ( state )
{
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_buttons [ button ] | = eButtonIsDown + eButtonTriggered ;
} else
{
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_buttons [ button ] | = eButtonReleased ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_buttons [ button ] & = ~ eButtonIsDown ;
}
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2016-07-18 06:50:11 +00:00
}
2016-09-15 23:57:00 +00:00
2017-10-05 19:59:58 +00:00
void PhysicsServerExample : : vrControllerMoveCallback ( int controllerId , float pos [ 4 ] , float orn [ 4 ] , float analogAxis , float auxAnalogAxes [ 10 ] )
2016-07-18 06:50:11 +00:00
{
2016-09-08 22:15:58 +00:00
2017-04-08 05:53:36 +00:00
if ( controllerId < 0 | | controllerId > = MAX_VR_CONTROLLERS )
2016-09-09 18:28:38 +00:00
{
printf ( " Controller Id exceeds max: %d > %d " , controllerId , MAX_VR_CONTROLLERS ) ;
return ;
}
2016-11-17 00:12:59 +00:00
btTransform trLocal ;
trLocal . setIdentity ( ) ;
trLocal . setRotation ( btQuaternion ( btVector3 ( 0 , 0 , 1 ) , SIMD_HALF_PI ) * btQuaternion ( btVector3 ( 0 , 1 , 0 ) , SIMD_HALF_PI ) ) ;
btTransform trOrg ;
trOrg . setIdentity ( ) ;
trOrg . setOrigin ( btVector3 ( pos [ 0 ] , pos [ 1 ] , pos [ 2 ] ) ) ;
trOrg . setRotation ( btQuaternion ( orn [ 0 ] , orn [ 1 ] , orn [ 2 ] , orn [ 3 ] ) ) ;
btTransform tr2a ;
tr2a . setIdentity ( ) ;
btTransform tr2 ;
tr2 . setIdentity ( ) ;
2017-05-31 02:54:55 +00:00
tr2 . setOrigin ( m_physicsServer . getVRTeleportPosition ( ) ) ;
tr2a . setRotation ( m_physicsServer . getVRTeleportOrientation ( ) ) ;
2016-11-17 00:12:59 +00:00
btTransform trTotal = tr2 * tr2a * trOrg * trLocal ;
2016-09-12 18:10:20 +00:00
if ( controllerId = = gGraspingController )
2016-09-09 21:30:37 +00:00
{
2016-11-17 00:12:59 +00:00
2016-09-09 21:30:37 +00:00
}
else
{
2016-11-17 00:12:59 +00:00
m_args [ 0 ] . m_vrControllerPos [ controllerId ] = trTotal . getOrigin ( ) ;
m_args [ 0 ] . m_vrControllerOrn [ controllerId ] = trTotal . getRotation ( ) ;
2016-09-09 21:30:37 +00:00
}
2016-09-08 22:15:58 +00:00
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > lock ( ) ;
2016-12-27 03:40:09 +00:00
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_controllerId = controllerId ;
2017-04-08 05:53:36 +00:00
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_deviceType = VR_DEVICE_CONTROLLER ;
2016-12-27 03:40:09 +00:00
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 0 ] = trTotal . getOrigin ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 1 ] = trTotal . getOrigin ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 2 ] = trTotal . getOrigin ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 0 ] = trTotal . getRotation ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 1 ] = trTotal . getRotation ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 2 ] = trTotal . getRotation ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 3 ] = trTotal . getRotation ( ) [ 3 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_numMoveEvents + + ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_analogAxis = analogAxis ;
2017-10-05 19:59:58 +00:00
for ( int i = 0 ; i < 10 ; i + + )
{
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_auxAnalogAxis [ i ] = auxAnalogAxes [ i ] ;
}
2016-12-29 05:51:54 +00:00
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
2016-12-27 03:40:09 +00:00
2016-07-18 06:50:11 +00:00
}
2017-04-08 05:53:36 +00:00
void PhysicsServerExample : : vrHMDMoveCallback ( int controllerId , float pos [ 4 ] , float orn [ 4 ] )
{
if ( controllerId < 0 | | controllerId > = MAX_VR_CONTROLLERS )
{
printf ( " Controller Id exceeds max: %d > %d " , controllerId , MAX_VR_CONTROLLERS ) ;
return ;
}
//we may need to add some trLocal transform, to align the camera to our preferences
btTransform trLocal ;
trLocal . setIdentity ( ) ;
// trLocal.setRotation(btQuaternion(btVector3(0, 0, 1), SIMD_HALF_PI)*btQuaternion(btVector3(0, 1, 0), SIMD_HALF_PI));
btTransform trOrg ;
trOrg . setIdentity ( ) ;
trOrg . setOrigin ( btVector3 ( pos [ 0 ] , pos [ 1 ] , pos [ 2 ] ) ) ;
trOrg . setRotation ( btQuaternion ( orn [ 0 ] , orn [ 1 ] , orn [ 2 ] , orn [ 3 ] ) ) ;
btTransform tr2a ;
tr2a . setIdentity ( ) ;
btTransform tr2 ;
tr2 . setIdentity ( ) ;
2017-05-31 02:54:55 +00:00
tr2 . setOrigin ( m_physicsServer . getVRTeleportPosition ( ) ) ;
tr2a . setRotation ( m_physicsServer . getVRTeleportOrientation ( ) ) ;
2017-04-08 05:53:36 +00:00
btTransform trTotal = tr2 * tr2a * trOrg * trLocal ;
m_args [ 0 ] . m_csGUI - > lock ( ) ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_controllerId = controllerId ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_deviceType = VR_DEVICE_HMD ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 0 ] = trTotal . getOrigin ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 1 ] = trTotal . getOrigin ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 2 ] = trTotal . getOrigin ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 0 ] = trTotal . getRotation ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 1 ] = trTotal . getRotation ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 2 ] = trTotal . getRotation ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 3 ] = trTotal . getRotation ( ) [ 3 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_numMoveEvents + + ;
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
}
void PhysicsServerExample : : vrGenericTrackerMoveCallback ( int controllerId , float pos [ 4 ] , float orn [ 4 ] )
{
if ( controllerId < 0 | | controllerId > = MAX_VR_CONTROLLERS )
{
printf ( " Controller Id exceeds max: %d > %d " , controllerId , MAX_VR_CONTROLLERS ) ;
return ;
}
//we may need to add some trLocal transform, to align the camera to our preferences
btTransform trLocal ;
trLocal . setIdentity ( ) ;
trLocal . setRotation ( btQuaternion ( btVector3 ( 0 , 0 , 1 ) , SIMD_HALF_PI ) * btQuaternion ( btVector3 ( 0 , 1 , 0 ) , SIMD_HALF_PI ) ) ;
btTransform trOrg ;
trOrg . setIdentity ( ) ;
trOrg . setOrigin ( btVector3 ( pos [ 0 ] , pos [ 1 ] , pos [ 2 ] ) ) ;
trOrg . setRotation ( btQuaternion ( orn [ 0 ] , orn [ 1 ] , orn [ 2 ] , orn [ 3 ] ) ) ;
btTransform tr2a ;
tr2a . setIdentity ( ) ;
btTransform tr2 ;
tr2 . setIdentity ( ) ;
2017-05-31 02:54:55 +00:00
tr2 . setOrigin ( m_physicsServer . getVRTeleportPosition ( ) ) ;
tr2a . setRotation ( m_physicsServer . getVRTeleportOrientation ( ) ) ;
2017-04-08 05:53:36 +00:00
btTransform trTotal = tr2 * tr2a * trOrg * trLocal ;
m_args [ 0 ] . m_csGUI - > lock ( ) ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_controllerId = controllerId ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_deviceType = VR_DEVICE_GENERIC_TRACKER ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 0 ] = trTotal . getOrigin ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 1 ] = trTotal . getOrigin ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_pos [ 2 ] = trTotal . getOrigin ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 0 ] = trTotal . getRotation ( ) [ 0 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 1 ] = trTotal . getRotation ( ) [ 1 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 2 ] = trTotal . getRotation ( ) [ 2 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_orn [ 3 ] = trTotal . getRotation ( ) [ 3 ] ;
m_args [ 0 ] . m_vrControllerEvents [ controllerId ] . m_numMoveEvents + + ;
m_args [ 0 ] . m_csGUI - > unlock ( ) ;
}
2017-05-31 02:54:55 +00:00
extern int gSharedMemoryKey ;
class CommonExampleInterface * PhysicsServerCreateFuncInternal ( struct CommonExampleOptions & options )
{
2018-05-07 22:57:36 +00:00
MultiThreadedOpenGLGuiHelper * guiHelperWrapper = new MultiThreadedOpenGLGuiHelper ( options . m_guiHelper - > getAppInterface ( ) , options . m_guiHelper , options . m_skipGraphicsUpdate ) ;
2017-05-31 02:54:55 +00:00
PhysicsServerExample * example = new PhysicsServerExample ( guiHelperWrapper ,
options . m_commandProcessorCreation ,
options . m_sharedMem ,
options . m_option ) ;
if ( gSharedMemoryKey > = 0 )
{
example - > setSharedMemoryKey ( gSharedMemoryKey ) ;
}
if ( options . m_option & PHYSICS_SERVER_ENABLE_COMMAND_LOGGING )
{
example - > enableCommandLogging ( ) ;
}
if ( options . m_option & PHYSICS_SERVER_REPLAY_FROM_COMMAND_LOG )
{
example - > replayFromLogFile ( ) ;
}
return example ;
}