From 2c13e70d1a8227dfce948abbd550a615188e9d17 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Fri, 5 Oct 2018 19:24:44 -0700 Subject: [PATCH] make projective textures work in DIRECT+eglPlugin (see examples/pybullet/examples/projective_texture.py) --- .../ImportURDFDemo/UrdfRenderingInterface.h | 3 ++ .../PhysicsServerCommandProcessor.cpp | 28 +++++++++++++++++++ .../eglRendererVisualShapeConverter.cpp | 10 +++++++ .../eglRendererVisualShapeConverter.h | 3 ++ 4 files changed, 44 insertions(+) diff --git a/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h b/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h index 4e86a06bf..de2ddbe51 100644 --- a/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h +++ b/examples/Importers/ImportURDFDemo/UrdfRenderingInterface.h @@ -91,6 +91,9 @@ struct UrdfRenderingInterface ///register a texture using an in-memory pixel buffer of a given width and height virtual int registerTexture(unsigned char* texels, int width, int height) = 0; + + virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]) {} + virtual void setProjectiveTexture(bool useProjectiveTexture) {} }; #endif //LINK_VISUAL_SHAPES_CONVERTER_H diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index d3d37201d..c298a9975 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -3645,10 +3645,38 @@ bool PhysicsServerCommandProcessor::processRequestCameraImageCommand(const struc if (m_data->m_pluginManager.getRenderInterface()) { + if ((flags & ER_USE_PROJECTIVE_TEXTURE) != 0) + { + m_data->m_pluginManager.getRenderInterface()->setProjectiveTexture(true); + if ((clientCmd.m_updateFlags & REQUEST_PIXEL_ARGS_HAS_PROJECTIVE_TEXTURE_MATRICES) != 0) + { + for (int i = 0; i < 16; i++) + { + projTextureViewMat[i] = clientCmd.m_requestPixelDataArguments.m_projectiveTextureViewMatrix[i]; + projTextureProjMat[i] = clientCmd.m_requestPixelDataArguments.m_projectiveTextureProjectionMatrix[i]; + } + } + else // If no specified matrices for projective texture, then use the camera matrices. + { + for (int i = 0; i < 16; i++) + { + projTextureViewMat[i] = viewMat[i]; + projTextureProjMat[i] = projMat[i]; + } + } + m_data->m_pluginManager.getRenderInterface()->setProjectiveTextureMatrices(projTextureViewMat, projTextureProjMat); + } + else + { + m_data->m_pluginManager.getRenderInterface()->setProjectiveTexture(false); + } + + m_data->m_pluginManager.getRenderInterface()->copyCameraImageData(pixelRGBA, numRequestedPixels, depthBuffer, numRequestedPixels, segmentationMaskBuffer, numRequestedPixels, startPixelIndex, &width, &height, &numPixelsCopied); + m_data->m_pluginManager.getRenderInterface()->setProjectiveTexture(false); } m_data->m_guiHelper->debugDisplayCameraImageData(clientCmd.m_requestPixelDataArguments.m_viewMatrix, diff --git a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp index 243bf6c30..70548b301 100644 --- a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp @@ -984,6 +984,16 @@ void EGLRendererVisualShapeConverter::setWidthAndHeight(int width, int height) m_data->m_rgbColorBuffer = TGAImage(width, height, TGAImage::RGB); } +void EGLRendererVisualShapeConverter::setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]) +{ + m_data->m_instancingRenderer->setProjectiveTextureMatrices(viewMatrix,projectionMatrix); +} + +void EGLRendererVisualShapeConverter::setProjectiveTexture(bool useProjectiveTexture) +{ + m_data->m_instancingRenderer->setProjectiveTexture(useProjectiveTexture); +} + //copied from OpenGLGuiHelper.cpp void EGLRendererVisualShapeConverter::copyCameraImageDataGL( unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, diff --git a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h index 26d281058..d0aefb68a 100644 --- a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h +++ b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h @@ -51,6 +51,9 @@ struct EGLRendererVisualShapeConverter : public UrdfRenderingInterface virtual int loadTextureFile(const char* filename); virtual int registerTexture(unsigned char* texels, int width, int height); + virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]); + virtual void setProjectiveTexture(bool useProjectiveTexture); + virtual void syncTransform(int shapeUid, const class btTransform& worldTransform, const class btVector3& localScaling); };