Thanks to @dchichkov for some of the fixes in the eglRendererPlugin!

Rename tinyRenderer -> eglRenderer in the eglRendererPlugin.
Allow to run the eglRendererPlugin to run on Windows (not in EGL mode but Win32OpenGLWindow mode)

Here is a script I tested on Windows:
~~~~~~~~~~~~
mport pybullet as p
import time

p.connect(p.DIRECT)
plugin = p.loadPlugin("e:/develop/bullet3/bin/pybullet_eglRendererPlugin_vs2010_x64_debug.dll","_eglRendererPlugin")
print("plugin=",plugin)
p.setGravity(0,0,-10)
p.loadURDF("plane.urdf",[0,0,-1])
p.loadURDF("r2d2.urdf")
pixelWidth = 320
pixelHeight = 220
while (1):
	p.stepSimulation()
	viewMatrix = [1.0, 0.0, -0.0, 0.0, -0.0, 0.1736481785774231, -0.9848078489303589, 0.0, 0.0, 0.9848078489303589, 0.1736481785774231, 0.0, -0.0, -5.960464477539063e-08, -4.0, 1.0]
	projectionMatrix  = [1.0825318098068237, 0.0, 0.0, 0.0, 0.0, 1.732050895690918, 0.0, 0.0, 0.0, 0.0, -1.0002000331878662, -1.0, 0.0, 0.0, -0.020002000033855438, 0.0]

	#img_arr = p.getCameraImage(pixelWidth, pixelHeight, viewMatrix,projectionMatrix, shadow=1,lightDirection=[1,1,1])#,renderer=pybullet.ER_BULLET_HARDWARE_OPENGL)
	img_arr = p.getCameraImage(pixelWidth, pixelHeight, shadow=1,lightDirection=[1,1,1])#,renderer=pybullet.ER_BULLET_HARDWARE_OPENGL)
	#print("img_arr=",img_arr)
	time.sleep(1)
~~~~~~~~~~~~~
This commit is contained in:
erwincoumans
2018-09-09 13:37:49 -07:00
parent dc7feb9027
commit adb5c049c7
10 changed files with 159 additions and 184 deletions

View File

@@ -30,11 +30,12 @@
#ifdef BT_USE_EGL
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "OpenGLInclude.h"
@@ -213,7 +214,7 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
exit(EXIT_FAILURE);
}
if (!gladLoadGL(eglGetProcAddress)) {
if (!gladLoadGL((GLADloadfunc) eglGetProcAddress)) {
fprintf(stderr, "failed to load GL with glad.\n");
exit(EXIT_FAILURE);
}
@@ -228,8 +229,8 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) {
const GLubyte* sl = glGetString(GL_SHADING_LANGUAGE_VERSION);
printf("GL_SHADING_LANGUAGE_VERSION=%s\n", sl);
int i = pthread_getconcurrency();
printf("pthread_getconcurrency()=%d\n", i);
//int i = pthread_getconcurrency();
//printf("pthread_getconcurrency()=%d\n", i);
}
void EGLOpenGLWindow::closeWindow() {

View File

@@ -1,85 +0,0 @@
import os
import sys
import time
import subprocess
import pybullet as p
from pdb import set_trace
import matplotlib.pyplot as plt
import numpy as np
#subprocess.call(["hardening-check", p.__file__])
p.connect(p.DIRECT)
logId = p.startStateLogging(p.STATE_LOGGING_PROFILE_TIMINGS, "debugTimings")
plugin = True
if plugin:
plugin_fn = '/home/argusm/lang/bullet3/build/lib.linux-x86_64-3.5/eglRenderer.cpython-35m-x86_64-linux-gnu.so'
plugin = p.loadPlugin(plugin_fn,"_tinyRendererPlugin")
if plugin < 0:
print("\nPlugin Failed to load!\n")
sys.exit()
print("plugin =",plugin)
path = '/home/argusm/lang/bullet3/examples/pybullet/gym/pybullet_data/duck_vhacd.urdf'
p.loadURDF(path,globalScaling=12)
#path = '/home/argusm/lang/gym-grasping/gym_grasping/robots/models/kuka_iiwa/kuka_weiss_bolt.sdf'
#p.loadSDF(path)
start = time.time()
camTargetPos = [0,0,0]
upAxisIndex = 2
nearPlane = 0.01
farPlane = 100
camDistance = 2
pixelWidth = 128
pixelHeight = 128
fov = 60
plot = False
anim = True
if plot:
plt.ion()
if anim:
import matplotlib.animation as manimation
FFMpegWriter = manimation.writers['ffmpeg']
metadata = dict(title='Movie Test', artist='Matplotlib',
comment='Movie support!')
writer = FFMpegWriter(fps=15, metadata=metadata)
if plot or anim:
fig = plt.figure()
img = np.random.rand(pixelWidth,pixelHeight)
image = plt.imshow(img,interpolation='none',animated=True,label="blah")
ax = plt.gca()
ax.set_axis_off()
ax.set_aspect('equal')
plt.subplots_adjust(wspace=0, hspace=0, left=0, bottom=0, right=1, top=1)
try:
iter = range(0,360,10)
with writer.saving(fig, "debug.mp4", len(iter)):
for i,yaw in enumerate(iter):
viewMatrix = p.computeViewMatrixFromYawPitchRoll(camTargetPos, camDistance, 0, yaw-90, 0, upAxisIndex)
aspect = pixelWidth / pixelHeight;
projectionMatrix = p.computeProjectionMatrixFOV(fov, aspect, nearPlane, farPlane);
hight, width, img_arr, deept_arr, obj_arr = p.getCameraImage(pixelWidth,pixelHeight,viewMatrix,projectionMatrix)
if plot:
image.set_data(img_arr)#np_img_arr)
ax.plot([0])
#plt.draw()
#plt.show()
plt.pause(0.01)
if anim:
image.set_data(img_arr)#np_img_arr)
ax.plot([0])
writer.grab_frame()
if i % 100 == 0 and i > 0:
print("FPS",100/(time.time()-start))
start = time.time()
finally:
p.stopStateLogging(logId)

View File

@@ -1,15 +1,7 @@
//tinyRenderer plugin
//eglRenderer plugin
/*
import pybullet as p
p.connect(p.GUI)
plugin = p.loadPlugin("e:/develop/bullet3/bin/pybullet_tinyRendererPlugin_vs2010_x64_debug.dll","_tinyRendererPlugin")
print("plugin=",plugin)
p.loadURDF("r2d2.urdf")
while (1):
p.getCameraImage(320,200)
*/
//see Bullet/examples/pybullet/examples/eglRendererTest.py
#include "eglRendererPlugin.h"
#include "eglRendererVisualShapeConverter.h"
@@ -20,43 +12,43 @@ while (1):
struct MyRendererPluginClass
struct EGLRendererPluginClass
{
TinyRendererVisualShapeConverter m_renderer;
MyRendererPluginClass()
EGLRendererVisualShapeConverter m_renderer;
EGLRendererPluginClass()
{
}
virtual ~MyRendererPluginClass()
virtual ~EGLRendererPluginClass()
{
}
};
B3_SHARED_API int initPlugin_tinyRendererPlugin(struct b3PluginContext* context)
B3_SHARED_API int initPlugin_eglRendererPlugin(struct b3PluginContext* context)
{
MyRendererPluginClass* obj = new MyRendererPluginClass();
EGLRendererPluginClass* obj = new EGLRendererPluginClass();
context->m_userPointer = obj;
return SHARED_MEMORY_MAGIC_NUMBER;
}
B3_SHARED_API int executePluginCommand_tinyRendererPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments)
B3_SHARED_API int executePluginCommand_eglRendererPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments)
{
return -1;
}
B3_SHARED_API void exitPlugin_tinyRendererPlugin(struct b3PluginContext* context)
B3_SHARED_API void exitPlugin_eglRendererPlugin(struct b3PluginContext* context)
{
MyRendererPluginClass* obj = (MyRendererPluginClass*) context->m_userPointer;
EGLRendererPluginClass* obj = (EGLRendererPluginClass*) context->m_userPointer;
delete obj;
context->m_userPointer = 0;
}
//all the APIs below are optional
B3_SHARED_API struct UrdfRenderingInterface* getRenderInterface_tinyRendererPlugin(struct b3PluginContext* context)
B3_SHARED_API struct UrdfRenderingInterface* getRenderInterface_eglRendererPlugin(struct b3PluginContext* context)
{
MyRendererPluginClass* obj = (MyRendererPluginClass*) context->m_userPointer;
EGLRendererPluginClass* obj = (EGLRendererPluginClass*) context->m_userPointer;
return &obj->m_renderer;
}

View File

@@ -1,5 +1,5 @@
#ifndef TINY_RENDERER_PLUGIN_H
#define TINY_RENDERER_PLUGIN_H
#ifndef EGL_RENDERER_PLUGIN_H
#define EGL_RENDERER_PLUGIN_H
#include "../b3PluginAPI.h"
@@ -9,12 +9,12 @@ extern "C"
#endif
//initPlugin, exitPlugin and executePluginCommand are required, otherwise plugin won't load
B3_SHARED_API int initPlugin_tinyRendererPlugin(struct b3PluginContext* context);
B3_SHARED_API void exitPlugin_tinyRendererPlugin(struct b3PluginContext* context);
B3_SHARED_API int executePluginCommand_tinyRendererPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments);
B3_SHARED_API int initPlugin_eglRendererPlugin(struct b3PluginContext* context);
B3_SHARED_API void exitPlugin_eglRendererPlugin(struct b3PluginContext* context);
B3_SHARED_API int executePluginCommand_eglRendererPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments);
//all the APIs below are optional
B3_SHARED_API struct UrdfRenderingInterface* getRenderInterface_tinyRendererPlugin(struct b3PluginContext* context);
B3_SHARED_API struct UrdfRenderingInterface* getRenderInterface_eglRendererPlugin(struct b3PluginContext* context);
@@ -22,4 +22,4 @@ B3_SHARED_API struct UrdfRenderingInterface* getRenderInterface_tinyRendererPlug
};
#endif
#endif//#define TEST_PLUGIN_H
#endif//#define EGL_RENDERER_PLUGIN_H

View File

@@ -38,9 +38,16 @@ subject to the following restrictions:
#include "stb_image/stb_image.h"
#include "../OpenGLWindow/EGLOpenGLWindow.h"
#include "../OpenGLWindow/GLInstancingRenderer.h"
#include "../OpenGLWindow/GLRenderToTexture.h"
#ifdef _WIN32
#include "OpenGLWindow/Win32OpenGLWindow.h"
typedef Win32OpenGLWindow DefaultOpenGLWindow;
#else
#include "OpenGLWindow/EGLOpenGLWindow.h"
typedef EGLOpenGLWindow DefaultOpenGLWindow;
#endif
#include "OpenGLWindow/GLInstancingRenderer.h"
#include "OpenGLWindow/GLRenderToTexture.h"
static void printGLString(const char *name, GLenum s) {
const char *v = (const char *) glGetString(s);
@@ -62,6 +69,7 @@ struct TinyRendererObjectArray
btAlignedObjectArray< TinyRenderObjectData*> m_renderObjects;
int m_objectUniqueId;
int m_linkIndex;
int m_graphicsInstanceId;
btTransform m_worldTransform;
btVector3 m_localScaling;
@@ -69,13 +77,14 @@ struct TinyRendererObjectArray
{
m_worldTransform.setIdentity();
m_localScaling.setValue(1,1,1);
m_graphicsInstanceId = -1;
}
};
#define START_WIDTH 640
#define START_HEIGHT 480
struct TinyRendererVisualShapeConverterInternalData
struct EGLRendererVisualShapeConverterInternalData
{
class CommonWindowInterface* m_window;
class GLInstancingRenderer* m_instancingRenderer;
@@ -111,7 +120,7 @@ struct TinyRendererVisualShapeConverterInternalData
SimpleCamera m_camera;
TinyRendererVisualShapeConverterInternalData()
EGLRendererVisualShapeConverterInternalData()
:m_upAxis(2),
m_swWidth(START_WIDTH),
m_swHeight(START_HEIGHT),
@@ -137,7 +146,7 @@ struct TinyRendererVisualShapeConverterInternalData
// OpenGL window
bool allowRetina=true;
m_window = new EGLOpenGLWindow();
m_window = new DefaultOpenGLWindow();
m_window->setAllowRetina(allowRetina);
b3gWindowConstructionInfo ci;
ci.m_title = "Title";
@@ -177,9 +186,9 @@ struct TinyRendererVisualShapeConverterInternalData
TinyRendererVisualShapeConverter::TinyRendererVisualShapeConverter()
EGLRendererVisualShapeConverter::EGLRendererVisualShapeConverter()
{
m_data = new TinyRendererVisualShapeConverterInternalData();
m_data = new EGLRendererVisualShapeConverterInternalData();
float dist = 1.5;
float pitch = -10;
@@ -190,53 +199,53 @@ TinyRendererVisualShapeConverter::TinyRendererVisualShapeConverter()
}
TinyRendererVisualShapeConverter::~TinyRendererVisualShapeConverter()
EGLRendererVisualShapeConverter::~EGLRendererVisualShapeConverter()
{
resetAll();
delete m_data;
}
void TinyRendererVisualShapeConverter::setLightDirection(float x, float y, float z)
void EGLRendererVisualShapeConverter::setLightDirection(float x, float y, float z)
{
m_data->m_lightDirection.setValue(x, y, z);
m_data->m_hasLightDirection = true;
}
void TinyRendererVisualShapeConverter::setLightColor(float x, float y, float z)
void EGLRendererVisualShapeConverter::setLightColor(float x, float y, float z)
{
m_data->m_lightColor.setValue(x, y, z);
m_data->m_hasLightColor = true;
}
void TinyRendererVisualShapeConverter::setLightDistance(float dist)
void EGLRendererVisualShapeConverter::setLightDistance(float dist)
{
m_data->m_lightDistance = dist;
m_data->m_hasLightDistance = true;
}
void TinyRendererVisualShapeConverter::setShadow(bool hasShadow)
void EGLRendererVisualShapeConverter::setShadow(bool hasShadow)
{
m_data->m_hasShadow = hasShadow;
}
void TinyRendererVisualShapeConverter::setFlags(int flags)
void EGLRendererVisualShapeConverter::setFlags(int flags)
{
m_data->m_flags = flags;
}
void TinyRendererVisualShapeConverter::setLightAmbientCoeff(float ambientCoeff)
void EGLRendererVisualShapeConverter::setLightAmbientCoeff(float ambientCoeff)
{
m_data->m_lightAmbientCoeff = ambientCoeff;
m_data->m_hasLightAmbientCoeff = true;
}
void TinyRendererVisualShapeConverter::setLightDiffuseCoeff(float diffuseCoeff)
void EGLRendererVisualShapeConverter::setLightDiffuseCoeff(float diffuseCoeff)
{
m_data->m_lightDiffuseCoeff = diffuseCoeff;
m_data->m_hasLightDiffuseCoeff = true;
}
void TinyRendererVisualShapeConverter::setLightSpecularCoeff(float specularCoeff)
void EGLRendererVisualShapeConverter::setLightSpecularCoeff(float specularCoeff)
{
m_data->m_lightSpecularCoeff = specularCoeff;
m_data->m_hasLightSpecularCoeff = true;
@@ -609,7 +618,7 @@ static btVector4 sColors[4] =
// If you are getting segfaults in this function it may be ecause you are
// compliling the plugin with differently from pybullet, try complining the
// plugin with distutils too.
void TinyRendererVisualShapeConverter::convertVisualShapes(
void EGLRendererVisualShapeConverter::convertVisualShapes(
int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame,
const UrdfLink* linkPtr, const UrdfModel* model,
int collisionObjectUniqueId, int bodyUniqueId)
@@ -739,14 +748,17 @@ void TinyRendererVisualShapeConverter::convertVisualShapes(
unsigned char* textureImage1=0;
int textureWidth=0;
int textureHeight=0;
bool isCached = false;
bool isCached = false;
int textureIndex = -1;
if (textures.size())
{
textureImage1 = textures[0].textureData1;
textureWidth = textures[0].m_width;
textureHeight = textures[0].m_height;
isCached = textures[0].m_isCached;
}
textureIndex = m_data->m_instancingRenderer->registerTexture(textureImage1, textureWidth, textureHeight);
}
{
B3_PROFILE("registerMeshShape");
@@ -760,10 +772,11 @@ void TinyRendererVisualShapeConverter::convertVisualShapes(
B3_PROFILE("m_instancingRenderer register");
// register mesh to m_instancingRenderer too.
int textureIndex = m_data->m_instancingRenderer->registerTexture(textureImage1, textureWidth, textureHeight);
int shapeIndex = m_data->m_instancingRenderer->registerShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size(),textureIndex);
int shapeIndex = m_data->m_instancingRenderer->registerShape(&vertices[0].xyzw[0], vertices.size(), &indices[0], indices.size(),B3_GL_TRIANGLES, textureIndex);
btVector3 scaling(1,1,1);
m_data->m_instancingRenderer->registerGraphicsInstance(shapeIndex, &visualShape.m_localVisualFrame[0], &visualShape.m_localVisualFrame[3], &visualShape.m_rgbaColor[0],scaling);
visuals->m_graphicsInstanceId = m_data->m_instancingRenderer->registerGraphicsInstance(shapeIndex, &visualShape.m_localVisualFrame[0], &visualShape.m_localVisualFrame[3], &visualShape.m_rgbaColor[0],scaling);
m_data->m_instancingRenderer->writeTransforms();
}
}
@@ -778,7 +791,7 @@ void TinyRendererVisualShapeConverter::convertVisualShapes(
}
}
int TinyRendererVisualShapeConverter::getNumVisualShapes(int bodyUniqueId)
int EGLRendererVisualShapeConverter::getNumVisualShapes(int bodyUniqueId)
{
int start = -1;
//find first one, then count how many
@@ -810,7 +823,7 @@ int TinyRendererVisualShapeConverter::getNumVisualShapes(int bodyUniqueId)
return count;
}
int TinyRendererVisualShapeConverter::getVisualShapesData(int bodyUniqueId, int shapeIndex, struct b3VisualShapeData* shapeData)
int EGLRendererVisualShapeConverter::getVisualShapesData(int bodyUniqueId, int shapeIndex, struct b3VisualShapeData* shapeData)
{
int start = -1;
//find first one, then count how many
@@ -837,7 +850,7 @@ int TinyRendererVisualShapeConverter::getVisualShapesData(int bodyUniqueId, int
void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int linkIndex, int shapeIndex, const double rgbaColor[4])
void EGLRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int linkIndex, int shapeIndex, const double rgbaColor[4])
{
//int start = -1;
for (int i = 0; i < m_data->m_visualShapes.size(); i++)
@@ -874,7 +887,7 @@ void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int lin
void TinyRendererVisualShapeConverter::setUpAxis(int axis)
void EGLRendererVisualShapeConverter::setUpAxis(int axis)
{
m_data->m_upAxis = axis;
m_data->m_camera.setCameraUpAxis(axis);
@@ -882,7 +895,7 @@ void TinyRendererVisualShapeConverter::setUpAxis(int axis)
m_data->m_instancingRenderer->updateCamera();
}
void TinyRendererVisualShapeConverter::resetCamera(float camDist, float yaw, float pitch, float camPosX,float camPosY, float camPosZ)
void EGLRendererVisualShapeConverter::resetCamera(float camDist, float yaw, float pitch, float camPosX,float camPosY, float camPosZ)
{
m_data->m_camera.setCameraDistance(camDist);
m_data->m_camera.setCameraPitch(pitch);
@@ -892,7 +905,7 @@ void TinyRendererVisualShapeConverter::resetCamera(float camDist, float yaw, flo
m_data->m_camera.update();
}
void TinyRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
void EGLRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
{
float farPlane = m_data->m_camera.getCameraFrustumFar();
for(int y=0;y<m_data->m_swHeight;++y)
@@ -908,7 +921,7 @@ void TinyRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
}
void TinyRendererVisualShapeConverter::render()
void EGLRendererVisualShapeConverter::render()
{
/*
ATTRIBUTE_ALIGNED16(float viewMat[16]);
@@ -920,13 +933,23 @@ void TinyRendererVisualShapeConverter::render()
cout<<viewMat[4*2 + 0]<<" "<<viewMat[4*2+1]<<" "<<viewMat[4*2+2]<<" "<<viewMat[4*2+3] << endl;
cout<<viewMat[4*3 + 0]<<" "<<viewMat[4*3+1]<<" "<<viewMat[4*3+2]<<" "<<viewMat[4*3+3] << endl;
*/
B3_PROFILE("m_instancingRenderer render");
m_data->m_instancingRenderer->setActiveCamera(&m_data->m_camera);
m_data->m_instancingRenderer->updateCamera();
m_data->m_instancingRenderer->writeTransforms();
if (m_data->m_hasLightDirection)
{
m_data->m_instancingRenderer->setLightPosition(m_data->m_lightDirection);
}
m_data->m_instancingRenderer->setActiveCamera(&m_data->m_camera);
m_data->m_instancingRenderer->updateCamera(m_data->m_upAxis);
m_data->m_instancingRenderer->renderScene();
m_data->m_window->endRendering();
m_data->m_window->startRendering();
}
void TinyRendererVisualShapeConverter::render(const float viewMat[16], const float projMat[16])
void EGLRendererVisualShapeConverter::render(const float viewMat[16], const float projMat[16])
{
// This code is very similar to that of
// PhysicsServerCommandProcessor::processRequestCameraImageCommand
@@ -934,10 +957,10 @@ void TinyRendererVisualShapeConverter::render(const float viewMat[16], const flo
// Tiny allows rendering with viewMat, projMat explicitly, but
// GLInstancingRender calls m_activeCamera, so set this.
m_data->m_camera.setVRCamera(viewMat,projMat);
m_data->m_instancingRenderer->setActiveCamera(&m_data->m_camera);
m_data->m_instancingRenderer->updateCamera();
m_data->m_instancingRenderer->renderScene();
m_data->m_camera.setVRCamera(viewMat,projMat);
render();
//cout<<viewMat[4*0 + 0]<<" "<<viewMat[4*0+1]<<" "<<viewMat[4*0+2]<<" "<<viewMat[4*0+3] << endl;
//cout<<viewMat[4*1 + 0]<<" "<<viewMat[4*1+1]<<" "<<viewMat[4*1+2]<<" "<<viewMat[4*1+3] << endl;
@@ -945,14 +968,14 @@ void TinyRendererVisualShapeConverter::render(const float viewMat[16], const flo
//cout<<viewMat[4*3 + 0]<<" "<<viewMat[4*3+1]<<" "<<viewMat[4*3+2]<<" "<<viewMat[4*3+3] << endl;
}
void TinyRendererVisualShapeConverter::getWidthAndHeight(int& width, int& height)
void EGLRendererVisualShapeConverter::getWidthAndHeight(int& width, int& height)
{
width = m_data->m_swWidth;
height = m_data->m_swHeight;
}
void TinyRendererVisualShapeConverter::setWidthAndHeight(int width, int height)
void EGLRendererVisualShapeConverter::setWidthAndHeight(int width, int height)
{
m_data->m_swWidth = width;
m_data->m_swHeight = height;
@@ -966,7 +989,7 @@ void TinyRendererVisualShapeConverter::setWidthAndHeight(int width, int height)
}
//copied from OpenGLGuiHelper.cpp
void TinyRendererVisualShapeConverter::copyCameraImageDataGL(
void EGLRendererVisualShapeConverter::copyCameraImageDataGL(
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
float* depthBuffer, int depthBufferSizeInPixels,
int* segmentationMaskBuffer, int segmentationMaskSizeInPixels,
@@ -1079,7 +1102,7 @@ void TinyRendererVisualShapeConverter::copyCameraImageDataGL(
}
}
void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
void EGLRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
float* depthBuffer, int depthBufferSizeInPixels,
int* segmentationMaskBuffer, int segmentationMaskSizeInPixels,
int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied)
@@ -1091,7 +1114,7 @@ void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixels
startPixelIndex, widthPtr, heightPtr, numPixelsCopied);
}
void TinyRendererVisualShapeConverter::removeVisualShape(int collisionObjectUniqueId)
void EGLRendererVisualShapeConverter::removeVisualShape(int collisionObjectUniqueId)
{
TinyRendererObjectArray** ptrptr = m_data->m_swRenderInstances[collisionObjectUniqueId];
if (ptrptr && *ptrptr)
@@ -1110,7 +1133,7 @@ void TinyRendererVisualShapeConverter::removeVisualShape(int collisionObjectUniq
}
void TinyRendererVisualShapeConverter::resetAll()
void EGLRendererVisualShapeConverter::resetAll()
{
for (int i=0;i<m_data->m_swRenderInstances.size();i++)
{
@@ -1142,7 +1165,7 @@ void TinyRendererVisualShapeConverter::resetAll()
}
void TinyRendererVisualShapeConverter::changeShapeTexture(int objectUniqueId, int jointIndex, int shapeIndex, int textureUniqueId)
void EGLRendererVisualShapeConverter::changeShapeTexture(int objectUniqueId, int jointIndex, int shapeIndex, int textureUniqueId)
{
btAssert(textureUniqueId < m_data->m_textures.size());
if (textureUniqueId >= 0 && textureUniqueId < m_data->m_textures.size())
@@ -1170,7 +1193,7 @@ void TinyRendererVisualShapeConverter::changeShapeTexture(int objectUniqueId, in
}
}
int TinyRendererVisualShapeConverter::registerTexture(unsigned char* texels, int width, int height)
int EGLRendererVisualShapeConverter::registerTexture(unsigned char* texels, int width, int height)
{
MyTexture2 texData;
texData.m_width = width;
@@ -1181,7 +1204,7 @@ int TinyRendererVisualShapeConverter::registerTexture(unsigned char* texels, int
return m_data->m_textures.size()-1;
}
int TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
int EGLRendererVisualShapeConverter::loadTextureFile(const char* filename)
{
B3_PROFILE("loadTextureFile");
int width,height,n;
@@ -1194,7 +1217,7 @@ int TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
return -1;
}
void TinyRendererVisualShapeConverter::syncTransform(int collisionObjectUniqueId, const btTransform& worldTransform, const btVector3& localScaling)
void EGLRendererVisualShapeConverter::syncTransform(int collisionObjectUniqueId, const btTransform& worldTransform, const btVector3& localScaling)
{
TinyRendererObjectArray** renderObjPtr = m_data->m_swRenderInstances[collisionObjectUniqueId];
if (renderObjPtr)
@@ -1202,5 +1225,11 @@ void TinyRendererVisualShapeConverter::syncTransform(int collisionObjectUniqueId
TinyRendererObjectArray* renderObj = *renderObjPtr;
renderObj->m_worldTransform = worldTransform;
renderObj->m_localScaling = localScaling;
if (renderObj->m_graphicsInstanceId>=0)
{
btVector3 pos = worldTransform.getOrigin();
btQuaternion orn = worldTransform.getRotation();
m_data->m_instancingRenderer->writeSingleInstanceTransformToCPU(pos, orn, renderObj->m_graphicsInstanceId);
}
}
}

View File

@@ -3,15 +3,14 @@
#include "../../../Importers/ImportURDFDemo/UrdfRenderingInterface.h"
struct TinyRendererVisualShapeConverter : public UrdfRenderingInterface
struct EGLRendererVisualShapeConverter : public UrdfRenderingInterface
{
int frame = 0;
struct TinyRendererVisualShapeConverterInternalData* m_data;
struct EGLRendererVisualShapeConverterInternalData* m_data;
TinyRendererVisualShapeConverter();
EGLRendererVisualShapeConverter();
virtual ~TinyRendererVisualShapeConverter();
virtual ~EGLRendererVisualShapeConverter();
virtual void convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, int shapeUid, int objectIndex);

View File

@@ -3,25 +3,36 @@
project ("pybullet_eglRendererPlugin")
language "C++"
kind "SharedLib"
initEGL()
includedirs {".","../../../../src", "../../../../examples",
"../../../ThirdPartyLibs"}
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"}
"../../../ThirdPartyLibs", ""../../examples/ThirdPartyLibs/glad"}
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER", "STB_AGAIN"}
hasCL = findOpenCL("clew")
links{"BulletCollision", "Bullet3Common", "LinearMath"}
initOpenGL()
if os.is("Windows") then
files {"../../../OpenGLWindow/Win32OpenGLWindow.cpp",
"../../../OpenGLWindow/Win32GLWindow.cpp",}
end
if os.is("MacOSX") then
-- targetextension {"so"}
links{"Cocoa.framework","Python"}
links{"Cocoa.framework"}
end
if os.is("Linux") then
files {"../../../ThirdPartyLibs/glad/glx.c",}
end
files {
"eglRendererPlugin.cpp",
"eglRendererPlugin.h",
"TinyRendererVisualShapeConverter.cpp",
"TinyRendererVisualShapeConverter.h",
"eglRendererVisualShapeConverter.cpp",
"eglRendererVisualShapeConverter.h",
"../../../Importers/ImportColladaDemo/LoadMeshFromCollada.cpp",
"../../../Importers/ImportColladaDemo/LoadMeshFromCollada.h",
"../../../Importers/ImportMeshUtility/b3ImportMeshUtility.cpp",
@@ -35,14 +46,22 @@ project ("pybullet_eglRendererPlugin")
"../../../TinyRenderer/our_gl.cpp",
"../../../TinyRenderer/tgaimage.cpp",
"../../../TinyRenderer/TinyRenderer.cpp",
"../../../ThirdPartyLibs/Wavefront/egl_obj_loader.cpp",
"../../../ThirdPartyLibs/Wavefront/egl_obj_loader.h",
"../../../ThirdPartyLibs/glad/gl.c",
"../../../ThirdPartyLibs/glad/egl.c",
"../../../ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp",
"../../../ThirdPartyLibs/Wavefront/tiny_obj_loader.h",
"../../../ThirdPartyLibs/stb_image/stb_image.cpp",
"../../../ThirdPartyLibs/stb_image/stb_image.h",
"../../../ThirdPartyLibs/eglxml2/eglxml2.cpp",
"../../../ThirdPartyLibs/eglxml2/eglxml2.h",
"../../../ThirdPartyLibs/tinyxml2/tinyxml2.cpp",
"../../../ThirdPartyLibs/tinyxml2/tinyxml2.h",
"../../../OpenGLWindow/SimpleCamera.cpp",
"../../../OpenGLWindow/SimpleCamera.h",
"../../../OpenGLWindow/GLInstancingRenderer.cpp",
"../../../OpenGLWindow/GLInstancingRenderer.h",
"../../../OpenGLWindow/LoadShader.cpp",
"../../../OpenGLWindow/LoadShader.h",
"../../../OpenGLWindow/GLRenderToTexture.cpp",
"../../../OpenGLWindow/GLRenderToTexture.h",
"../../../Utils/b3Clock.cpp",
"../../../Utils/b3Clock.h",
"../../../Utils/b3ResourcePath.cpp",

View File

@@ -474,6 +474,10 @@ include "plugins/tinyRendererPlugin"
include "plugins/pdControlPlugin"
include "plugins/collisionFilterPlugin"
if _OPTIONS["enable_egl"] then
include "plugins/eglPlugin"
end
if _OPTIONS["enable_grpc"] then
include "grpc"
include "plugins/grpcPlugin"