Merge pull request #1874 from erwincoumans/master
more egl plugin fixes, create stb_image_write.cpp (instead of magic defines in various source files)
This commit is contained in:
@@ -344,7 +344,7 @@ SET(BulletExampleBrowser_SRCS
|
||||
|
||||
../ThirdPartyLibs/stb_image/stb_image.cpp
|
||||
../ThirdPartyLibs/stb_image/stb_image.h
|
||||
|
||||
../ThirdPartyLibs/stb_image/stb_image_write.cpp
|
||||
../ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp
|
||||
|
||||
../ThirdPartyLibs/tinyxml2/tinyxml2.cpp
|
||||
|
||||
@@ -182,7 +182,7 @@ project "App_BulletExampleBrowser"
|
||||
"../MultiBody/MultiBodyConstraintFeedback.cpp",
|
||||
"../MultiBody/InvertedPendulumPDControl.cpp",
|
||||
"../RigidBody/RigidBodySoftContact.cpp",
|
||||
"../ThirdPartyLibs/stb_image/*",
|
||||
"../ThirdPartyLibs/stb_image/stb_image.cpp",
|
||||
"../ThirdPartyLibs/Wavefront/tiny_obj_loader.*",
|
||||
"../ThirdPartyLibs/BussIK/*",
|
||||
"../GyroscopicDemo/GyroscopicSetup.cpp",
|
||||
|
||||
@@ -51,6 +51,7 @@ IF(BUILD_EGL)
|
||||
SET(OpenGLWindow_SRCS ${OpenGLWindow_SRCS} ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/glad/egl.c)
|
||||
ENDIF(BUILD_EGL)
|
||||
|
||||
SET(OpenGLWindow_SRCS ${OpenGLWindow_SRCS} ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/stb_image/stb_image_write.cpp)
|
||||
|
||||
|
||||
ADD_LIBRARY(OpenGLWindow ${OpenGLWindow_SRCS} ${OpenGLWindow_HDRS})
|
||||
|
||||
@@ -80,6 +80,7 @@ float shadowMapWorldSize=10;
|
||||
#include "Shaders/linesVS.h"
|
||||
|
||||
#include "GLRenderToTexture.h"
|
||||
#include "stb_image/stb_image_write.h"
|
||||
|
||||
|
||||
|
||||
@@ -1542,10 +1543,6 @@ void GLInstancingRenderer::updateCamera(int upAxis)
|
||||
|
||||
|
||||
|
||||
#ifdef STB_AGAIN // first defn in examples/OpenGLWindow/opengl_fontstashcallbacks.cpp
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#endif //STB_AGAIN
|
||||
#include "stb_image/stb_image_write.h"
|
||||
void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName, int numComponents)
|
||||
{
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image/stb_image_write.h"
|
||||
|
||||
|
||||
|
||||
@@ -25,9 +25,12 @@
|
||||
"*.h",
|
||||
"OpenGLWindow/*.c",
|
||||
"OpenGLWindow/*.h",
|
||||
"OpenGLWindow/GL/*.h"
|
||||
"OpenGLWindow/GL/*.h",
|
||||
"../ThirdPartyLibs/stb_image/stb_image_write.cpp",
|
||||
}
|
||||
|
||||
|
||||
|
||||
if not os.is("Windows") then
|
||||
excludes {
|
||||
"Win32OpenGLWindow.cpp",
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
#define B3_DYNLIB_IMPORT GetProcAddress
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
typedef void* B3_DYNLIB_HANDLE;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define B3_DYNLIB_OPEN(path) dlopen(path, RTLD_NOW | RTLD_GLOBAL)
|
||||
#else
|
||||
#ifdef B3_USE_DLMOPEN
|
||||
#define B3_DYNLIB_OPEN(path) dlmopen(LM_ID_NEWLM, path, RTLD_LAZY)
|
||||
#else
|
||||
#define B3_DYNLIB_OPEN(path) dlopen(path, RTLD_NOW | RTLD_GLOBAL)
|
||||
#endif
|
||||
#define B3_DYNLIB_CLOSE dlclose
|
||||
#define B3_DYNLIB_IMPORT dlsym
|
||||
@@ -40,16 +40,16 @@ struct b3Plugin
|
||||
PFN_INIT m_initFunc;
|
||||
PFN_EXIT m_exitFunc;
|
||||
PFN_EXECUTE m_executeCommandFunc;
|
||||
|
||||
|
||||
PFN_TICK m_preTickFunc;
|
||||
PFN_TICK m_postTickFunc;
|
||||
PFN_TICK m_processNotificationsFunc;
|
||||
PFN_TICK m_processClientCommandsFunc;
|
||||
|
||||
PFN_GET_RENDER_INTERFACE m_getRendererFunc;
|
||||
|
||||
|
||||
void* m_userPointer;
|
||||
|
||||
|
||||
b3Plugin()
|
||||
:m_pluginHandle(0),
|
||||
m_ownsPluginHandle(false),
|
||||
@@ -332,7 +332,7 @@ void b3PluginManager::tickPlugins(double timeStep, b3PluginManagerTickMode tickM
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
PFN_TICK tick = 0;
|
||||
switch (tickMode)
|
||||
{
|
||||
@@ -355,7 +355,7 @@ void b3PluginManager::tickPlugins(double timeStep, b3PluginManagerTickMode tickM
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (tick)
|
||||
{
|
||||
b3PluginContext context = { 0 };
|
||||
@@ -437,7 +437,7 @@ int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT
|
||||
{
|
||||
|
||||
b3Plugin orgPlugin;
|
||||
|
||||
|
||||
int pluginUniqueId = m_data->m_plugins.allocHandle();
|
||||
b3PluginHandle* pluginHandle = m_data->m_plugins.getHandle(pluginUniqueId);
|
||||
pluginHandle->m_pluginHandle = 0;
|
||||
@@ -453,7 +453,7 @@ int b3PluginManager::registerStaticLinkedPlugin(const char* pluginPath, PFN_INIT
|
||||
pluginHandle->m_pluginHandle = 0;
|
||||
pluginHandle->m_pluginPath = pluginPath;
|
||||
pluginHandle->m_userPointer = 0;
|
||||
|
||||
|
||||
|
||||
if (pluginHandle->m_processNotificationsFunc)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,9 @@ del pybullet.grpc.pb.h
|
||||
..\..\..\ThirdPartyLibs\grpc\lib\win32\protoc --proto_path=. --cpp_out=. pybullet.proto
|
||||
..\..\..\ThirdPartyLibs\grpc\lib\win32\protoc.exe --plugin=protoc-gen-grpc="..\..\..\ThirdPartyLibs\grpc\lib\win32\grpc_cpp_plugin.exe" --grpc_out=. pybullet.proto
|
||||
|
||||
rename pybullet.grpc.pb.cc pybullet.grpc.pb.cpp
|
||||
rename pybullet.pb.cc pybullet.pb.cpp
|
||||
|
||||
del pybullet_pb2.py
|
||||
del pybullet_pb2_grpc.py
|
||||
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
rm ../pybullet.pb.cpp
|
||||
rm ../pybullet.pb.h
|
||||
rm ../pybullet.grpc.pb.cpp
|
||||
rm ../pybullet.grpc.pb.h
|
||||
rm pybullet.pb.cpp
|
||||
rm pybullet.pb.h
|
||||
rm pybullet.grpc.pb.cpp
|
||||
rm pybullet.grpc.pb.h
|
||||
|
||||
protoc --proto_path=. --cpp_out=. pybullet.proto
|
||||
protoc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` --grpc_out=. pybullet.proto
|
||||
mv pybullet.grpc.pb.cc ../pybullet.grpc.pb.cpp
|
||||
mv pybullet.grpc.pb.h ../pybullet.grpc.pb.h
|
||||
mv pybullet.pb.cc ../pybullet.pb.cpp
|
||||
mv pybullet.pb.h ../pybullet.pb.h
|
||||
mv pybullet.grpc.pb.cc pybullet.grpc.pb.cpp
|
||||
mv pybullet.pb.cc pybullet.pb.cpp
|
||||
|
||||
rm ../pybullet_pb2.py
|
||||
rm ../pybullet_pb2_grpc.py
|
||||
rm pybullet_pb2.py
|
||||
rm pybullet_pb2_grpc.py
|
||||
|
||||
protoc --proto_path=. --python_out=. pybullet.proto
|
||||
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. pybullet.proto
|
||||
mv pybullet_pb2.py ../pybullet_pb2.py
|
||||
mv pybullet_pb2_grpc.py ../pybullet_pb2_grpc.py
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
|
||||
#ifdef EGL_ADD_PYTHON_INIT
|
||||
#if defined(__APPLE__) && (!defined(B3_NO_PYTHON_FRAMEWORK))
|
||||
#include <Python/Python.h>
|
||||
#else
|
||||
#include <Python.h>
|
||||
#endif
|
||||
#endif //EGL_ADD_PYTHON_INIT
|
||||
|
||||
//eglRenderer plugin
|
||||
|
||||
//see Bullet/examples/pybullet/examples/eglRendererTest.py
|
||||
@@ -52,3 +60,17 @@ B3_SHARED_API struct UrdfRenderingInterface* getRenderInterface_eglRendererPlugi
|
||||
return &obj->m_renderer;
|
||||
}
|
||||
|
||||
|
||||
#ifdef EGL_ADD_PYTHON_INIT
|
||||
PyMODINIT_FUNC
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyInit_eglRenderer(void)
|
||||
#else
|
||||
initeglRenderer(void)
|
||||
#endif
|
||||
{
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //EGL_ADD_PYTHON_INIT
|
||||
|
||||
@@ -795,7 +795,7 @@ void EGLRendererVisualShapeConverter::convertVisualShapes(
|
||||
// register mesh to m_instancingRenderer too.
|
||||
|
||||
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);
|
||||
double scaling[3]={1,1,1};
|
||||
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();
|
||||
|
||||
@@ -6,7 +6,7 @@ project ("pybullet_eglRendererPlugin")
|
||||
initEGL()
|
||||
|
||||
includedirs {".","../../../../src", "../../../../examples",
|
||||
"../../../ThirdPartyLibs", "../../examples/ThirdPartyLibs/glad"}
|
||||
"../../../ThirdPartyLibs", "../../../ThirdPartyLibs/glad"}
|
||||
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER", "STB_AGAIN"}
|
||||
hasCL = findOpenCL("clew")
|
||||
|
||||
@@ -25,7 +25,8 @@ project ("pybullet_eglRendererPlugin")
|
||||
end
|
||||
|
||||
if os.is("Linux") then
|
||||
files {"../../../ThirdPartyLibs/glad/glx.c",}
|
||||
files {"../../../OpenGLWindow/EGLOpenGLWindow.cpp"}
|
||||
|
||||
end
|
||||
|
||||
files {
|
||||
|
||||
@@ -98,7 +98,8 @@ myfiles =
|
||||
"../ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp",
|
||||
"../ThirdPartyLibs/tinyxml2/tinyxml2.cpp",
|
||||
"../Importers/ImportMeshUtility/b3ImportMeshUtility.cpp",
|
||||
"../ThirdPartyLibs/stb_image/stb_image.cpp",
|
||||
"../ThirdPartyLibs/stb_image/stb_image.cpp",
|
||||
"../ThirdPartyLibs/stb_image/stb_image_write.cpp",
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,25 +14,10 @@
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#ifdef GLEW_STATIC
|
||||
#include "glad/gl.h"
|
||||
#else
|
||||
#ifdef NO_GLEW
|
||||
#define GL_GLEXT_LEGACY
|
||||
#include "third_party/GL/gl/include/GL/gl.h"
|
||||
#include "third_party/GL/gl/include/GL/glext.h"
|
||||
#else
|
||||
#endif//__APPLE__
|
||||
|
||||
#ifdef BT_NO_GLAD
|
||||
#include <GL/glew.h>
|
||||
#else
|
||||
#include "glad/glad.h"
|
||||
#endif
|
||||
|
||||
#endif //NO_GLEW
|
||||
#endif //GLEW_STATIC
|
||||
#endif//(__APPLE__)
|
||||
#endif
|
||||
#endif //B3_USE_GLFW
|
||||
|
||||
#include "FontData.h"
|
||||
|
||||
|
||||
2
examples/ThirdPartyLibs/stb_image/stb_image_write.cpp
Normal file
2
examples/ThirdPartyLibs/stb_image/stb_image_write.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
@@ -73,6 +73,7 @@ SET(pybullet_SRCS
|
||||
../../examples/ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp
|
||||
../../examples/ThirdPartyLibs/Wavefront/tiny_obj_loader.h
|
||||
../../examples/ThirdPartyLibs/stb_image/stb_image.cpp
|
||||
../../examples/ThirdPartyLibs/stb_image/stb_image_write.cpp
|
||||
../../examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp
|
||||
../../examples/Importers/ImportObjDemo/LoadMeshFromObj.cpp
|
||||
../../examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp
|
||||
|
||||
47
examples/pybullet/examples/eglRenderTest.py
Normal file
47
examples/pybullet/examples/eglRenderTest.py
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
import pybullet as p
|
||||
import time
|
||||
import pkgutil
|
||||
egl = pkgutil.get_loader('eglRenderer')
|
||||
|
||||
p.connect(p.DIRECT)
|
||||
|
||||
plugin = p.loadPlugin(egl.get_filename(), "_eglRendererPlugin")
|
||||
print("plugin=",plugin)
|
||||
|
||||
p.configureDebugVisualizer(p.COV_ENABLE_RENDERING, 0)
|
||||
p.configureDebugVisualizer(p.COV_ENABLE_GUI, 0)
|
||||
|
||||
p.setGravity(0,0,-10)
|
||||
p.loadURDF("plane.urdf",[0,0,-1])
|
||||
p.loadURDF("r2d2.urdf")
|
||||
|
||||
pixelWidth = 320
|
||||
pixelHeight = 220
|
||||
camTargetPos = [0,0,0]
|
||||
camDistance = 4
|
||||
pitch = -10.0
|
||||
roll=0
|
||||
upAxisIndex = 2
|
||||
|
||||
|
||||
while (p.isConnected()):
|
||||
for yaw in range (0,360,10) :
|
||||
start = time.time()
|
||||
p.stepSimulation()
|
||||
stop = time.time()
|
||||
print ("stepSimulation %f" % (stop - start))
|
||||
|
||||
#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]
|
||||
viewMatrix = p.computeViewMatrixFromYawPitchRoll(camTargetPos, camDistance, yaw, pitch, roll, upAxisIndex)
|
||||
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]
|
||||
|
||||
start = time.time()
|
||||
img_arr = p.getCameraImage(pixelWidth, pixelHeight, viewMatrix=viewMatrix, projectionMatrix=projectionMatrix, shadow=1,lightDirection=[1,1,1])
|
||||
stop = time.time()
|
||||
print ("renderImage %f" % (stop - start))
|
||||
#time.sleep(.1)
|
||||
#print("img_arr=",img_arr)
|
||||
|
||||
|
||||
p.unloadPlugin(plugin)
|
||||
@@ -9,7 +9,7 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import pybullet
|
||||
import time
|
||||
|
||||
import pkgutil
|
||||
|
||||
plt.ion()
|
||||
|
||||
@@ -20,7 +20,9 @@ ax = plt.gca()
|
||||
|
||||
pybullet.connect(pybullet.DIRECT)
|
||||
|
||||
pybullet.loadPlugin("eglRendererPlugin")
|
||||
egl = pkgutil.get_loader('eglRenderer')
|
||||
|
||||
pybullet.loadPlugin(egl.get_filename(), "_eglRendererPlugin")
|
||||
pybullet.loadURDF("plane.urdf",[0,0,-1])
|
||||
pybullet.loadURDF("r2d2.urdf")
|
||||
|
||||
@@ -64,14 +66,14 @@ while (1):
|
||||
#note that sending the data to matplotlib is really slow
|
||||
|
||||
#reshape is not needed
|
||||
#np_img_arr = np.reshape(rgb, (h, w, 4))
|
||||
#np_img_arr = np_img_arr*(1./255.)
|
||||
np_img_arr = np.reshape(rgb, (h, w, 4))
|
||||
np_img_arr = np_img_arr*(1./255.)
|
||||
|
||||
#show
|
||||
#plt.imshow(np_img_arr,interpolation='none',extent=(0,1600,0,1200))
|
||||
#image = plt.imshow(np_img_arr,interpolation='none',animated=True,label="blah")
|
||||
|
||||
image.set_data(rgb)#np_img_arr)
|
||||
image.set_data(np_img_arr)
|
||||
ax.plot([0])
|
||||
#plt.draw()
|
||||
#plt.show()
|
||||
|
||||
@@ -153,6 +153,7 @@ if not _OPTIONS["no-enet"] then
|
||||
"../../examples/ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp",
|
||||
"../../examples/ThirdPartyLibs/Wavefront/tiny_obj_loader.h",
|
||||
"../../examples/ThirdPartyLibs/stb_image/stb_image.cpp",
|
||||
"../../examples/ThirdPartyLibs/stb_image/stb_image_write.cpp",
|
||||
"../../examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp",
|
||||
"../../examples/Importers/ImportObjDemo/LoadMeshFromObj.cpp",
|
||||
"../../examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user