From 17d39e3db289ba4cd535c8f2558501420c65ee99 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 12 May 2017 16:26:07 +0100 Subject: [PATCH 1/7] From Don Burns, add use of Xinerama to ensure full screen goes across all screens. --- src/osgViewer/CMakeLists.txt | 16 +++++ src/osgViewer/GraphicsWindowX11.cpp | 102 ++++++++++++++++++++++++---- 2 files changed, 106 insertions(+), 12 deletions(-) diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index f2283947b..3a13934f4 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -173,14 +173,23 @@ ELSE() # X11 for everybody else INCLUDE(FindPkgConfig OPTIONAL) IF(PKG_CONFIG_FOUND) + PKG_CHECK_MODULES(XRANDR xrandr) IF(XRANDR_FOUND) OPTION(OSGVIEWER_USE_XRANDR "Set to ON to enable Xrandr support for GraphicsWindowX11." ON) ELSE() SET(OSGVIEWER_USE_XRANDR OFF) ENDIF() + + PKG_CHECK_MODULES(XINERAMA xinerama) + IF(XINERAMA_FOUND) + SET(OSGVIEWER_USE_XINERAMA ON) + ELSE() + SET(OSGVIEWER_USE_XINERAMA OFF) + ENDIF() ELSE() SET(OSGVIEWER_USE_XRANDR OFF) + SET(OSGVIEWER_USE_XINERAMA OFF) ENDIF() SET(TARGET_H_NO_MODULE_INSTALL @@ -205,6 +214,13 @@ ELSE() ENDIF() ENDIF() + IF(OSGVIEWER_USE_XINERAMA) + ADD_DEFINITIONS(-DOSGVIEWER_USE_XINERAMA) + SET(LIB_PRIVATE_HEADERS ${LIB_PRIVATE_HEADERS} ${XINERAMA_INCLUDE_DIRS} ) + SET(LIB_EXTRA_LIBS -lXinerama ${LIB_EXTRA_LIBS}) + ENDIF() + + # X11 on Apple requires X11 library plus OpenGL linking hack on Leopard IF(APPLE) # hack for finding the iphone opengl es lib IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR) diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index a3d4552ca..02729a8dd 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -38,6 +38,10 @@ #include #endif +#ifdef OSGVIEWER_USE_XINERAMA +#include +#endif + #include using namespace osgViewer; @@ -382,23 +386,95 @@ bool GraphicsWindowX11::checkAndSendEventFullScreenIfNeeded(Display* display, in Atom netWMStateAtom = XInternAtom(display, "_NET_WM_STATE", True); Atom netWMStateFullscreenAtom = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", True); + OSG_NOTICE<<"GraphicsWindowX11::checkAndSendEventFullScreenIfNeeded()"< maxx ) + { + span[RightMost] = xi[i].screen_number; + maxx = xi[i].x_org; + } + + if( xi[i].y_org < miny ) + { + span[TopMost] = xi[i].screen_number; + miny = xi[i].y_org; + } + + if( xi[i].y_org > maxy ) + { + span[BottomMost] = xi[i].screen_number; + maxy = xi[i].y_org; + } + } + XFree(xi); + + Atom fullmons = XInternAtom(display, "_NET_WM_FULLSCREEN_MONITORS", True); + if( fullmons != None ) + { + XEvent xev; + xev.type = ClientMessage; + xev.xclient.window = _window; + xev.xclient.message_type = fullmons; + xev.xclient.format = 32; + xev.xclient.data.l[0] = span[TopMost]; + xev.xclient.data.l[1] = span[BottomMost]; + xev.xclient.data.l[2] = span[LeftMost]; + xev.xclient.data.l[3] = span[RightMost]; + xev.xclient.data.l[4] = 0; + + XSendEvent( display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); + } + } +#endif return true; } + return false; } @@ -1328,6 +1404,7 @@ bool GraphicsWindowX11::checkEvents() bool isModifier = keyMapGetKey(modMap, key); if (!isModifier) forceKey(key, eventTime, false); } + needNewWindowSize = true; // release modifier keys for (unsigned int key = 8; key < 256; key++) @@ -1367,6 +1444,7 @@ bool GraphicsWindowX11::checkEvents() bool isPressed = keyMapGetKey(keyMap, key); if (!isPressed) forceKey(key, eventTime, false); } + needNewWindowSize = true; // press/release modifier keys for (unsigned int key = 8; key < 256; key++) From 0d128c3a1affd6606215d0590e902eda195f4b30 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 7 Aug 2017 16:32:44 +0100 Subject: [PATCH 2/7] Added link to ABI tracker --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 37f0ceb1f..d890bddbc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![Build Status](https://travis-ci.org/openscenegraph/OpenSceneGraph.svg?branch=master)](https://travis-ci.org/openscenegraph/OpenSceneGraph) [![Coverity Status](https://scan.coverity.com/projects/9159/badge.svg)](https://scan.coverity.com/projects/openscenegraph-openscenegraph) [![Documentation](https://codedocs.xyz/openscenegraph/OpenSceneGraph.svg)](https://codedocs.xyz/openscenegraph/OpenSceneGraph/) +[ABI Tracker](https://abi-laboratory.pro/tracker/timeline/openscenegraph/ "ABI Tracker") # Introduction From 9d1234e866e92f4ded339999520a5b9f28bb084d Mon Sep 17 00:00:00 2001 From: Anna Sokol Date: Tue, 8 Aug 2017 13:35:35 +0100 Subject: [PATCH 3/7] In the attached GraphicsWindowWin32.cpp file, I changed order of the "else-if" for the TOUCHEVENTF_UP and TOUCHEVENTF_MOVE, I made it less intrusive then changing them into "if" events. I tested this on Windows 7 64-bit with a touch screen and a Windows 10 64-bit tablet. Separately in the same file, I also needed to address the fact that the close button would not react on touch so I added to the top of the "handleNativeWindowingEvent" close button handling in case of touch events. Again this was tested on the same 2 devices. --- src/osgViewer/GraphicsWindowWin32.cpp | 53 ++++++++++++++++++++------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index ab3e8af45..05ed74b71 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -2556,12 +2556,37 @@ void GraphicsWindowWin32::transformMouseXY( float& x, float& y ) LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - if ((GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) return TRUE; - //!@todo adapt windows event time to osgGA event queue time for better resolution double eventTime = getEventQueue()->getTime(); _timeOfLastCheckEvents = eventTime; + if ((GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) + { + switch(uMsg) + { + ///////////////// + case WM_SYSCOMMAND: + ///////////////// + { + UINT cmd = LOWORD(wParam); + if (cmd == SC_CLOSE) + getEventQueue()->closeWindow(eventTime); + break; + } + ///////////////// + case WM_NCLBUTTONUP: + ///////////////// + { + UINT cmd = LOWORD(wParam); + if (cmd == HTCLOSE) + getEventQueue()->closeWindow(eventTime); + break; + } + default: break; + } + return TRUE; + } + switch(uMsg) { // Wojtek Lewandowski 2010-09-28: @@ -2904,14 +2929,6 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W osg_event->addTouchPoint( ti[i].dwID, osgGA::GUIEventAdapter::TOUCH_BEGAN, pt.x, pt.y); } } - else if(ti[i].dwFlags & TOUCHEVENTF_MOVE) - { - if (!osg_event) { - osg_event = getEventQueue()->touchMoved( ti[i].dwID, osgGA::GUIEventAdapter::TOUCH_MOVED, pt.x, pt.y); - } else { - osg_event->addTouchPoint( ti[i].dwID, osgGA::GUIEventAdapter::TOUCH_MOVED, pt.x, pt.y); - } - } else if(ti[i].dwFlags & TOUCHEVENTF_UP) { // No double tap detection with RAW TOUCH Events, sorry. @@ -2921,6 +2938,14 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W osg_event->addTouchPoint( ti[i].dwID, osgGA::GUIEventAdapter::TOUCH_ENDED, pt.x, pt.y); } } + else if(ti[i].dwFlags & TOUCHEVENTF_MOVE) + { + if (!osg_event) { + osg_event = getEventQueue()->touchMoved( ti[i].dwID, osgGA::GUIEventAdapter::TOUCH_MOVED, pt.x, pt.y); + } else { + osg_event->addTouchPoint( ti[i].dwID, osgGA::GUIEventAdapter::TOUCH_MOVED, pt.x, pt.y); + } + } } } if (closeTouchInputHandleFunc) @@ -2934,7 +2959,7 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W /* TOUCH inputs for Win8 and later */ /************************************************************************/ // Note by Riccardo Corsi, 2017-03-16 - // Currently only handle the PEN input which is not handled nicely by the + // Currently only handle the PEN input which is not handled nicely by the // WM_TOUCH framework. // At the moment the PEN is mapped to the mouse, emulating LEFT button click. // WM_POINTER* messages could entirely replace the WM_TOUCH framework, @@ -2946,7 +2971,7 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W case WM_POINTERDOWN: ///// { - UINT32 pointerId = GET_POINTERID_WPARAM(wParam); + UINT32 pointerId = GET_POINTERID_WPARAM(wParam); POINTER_INPUT_TYPE pointerType = PT_POINTER; // check pointer type @@ -2960,13 +2985,13 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); ScreenToClient(hwnd, &pt); - + getEventQueue()->mouseButtonPress(pt.x, pt.y, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON); } // call default implementation to fallback on WM_TOUCH else { - if (_ownsWindow) + if (_ownsWindow) return ::DefWindowProc(hwnd, uMsg, wParam, lParam); } } From b46ccd0aa5e588e4c079a273eaf006ecfe1b91d6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 9 Aug 2017 08:58:25 +0100 Subject: [PATCH 4/7] Disabled the building of deprecated serializations in convertity_scan --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c6025ab4a..687c7c43d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ matrix: name: "openscenegraph/OpenSceneGraph" description: "OpenSceneGraph build" notification_email: robert@openscenegraph.com - build_command_prepend: "cmake -DCMAKE_BUILD_TYPE=Release ." + build_command_prepend: "cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_OSG_DEPRECATED_SERIALIZERS=OFF ." build_command: "make -j 3" branch_pattern: coverity_scan apt: From c18be2fc41c6b8fae161e1ca17436361e7c3f6f4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 23 May 2017 16:33:16 +0100 Subject: [PATCH 5/7] Replaced local FindZLIB.cmake usage with CMake's own FindZLIB.cmake, and ZLIB_LIBRARY to ZLIB_LIBRARIES --- CMakeModules/FindZLIB.cmake | 58 ----------------------------- src/osgDB/CMakeLists.txt | 2 +- src/osgPlugins/curl/CMakeLists.txt | 2 +- src/osgPlugins/dicom/CMakeLists.txt | 2 +- src/osgPlugins/exr/CMakeLists.txt | 2 +- src/osgPlugins/gz/CMakeLists.txt | 2 +- src/osgPlugins/ive/CMakeLists.txt | 2 +- src/osgPlugins/png/CMakeLists.txt | 2 +- src/osgPlugins/vnc/CMakeLists.txt | 2 +- src/osgPlugins/vrml/CMakeLists.txt | 2 +- 10 files changed, 9 insertions(+), 67 deletions(-) delete mode 100644 CMakeModules/FindZLIB.cmake diff --git a/CMakeModules/FindZLIB.cmake b/CMakeModules/FindZLIB.cmake deleted file mode 100644 index 3583ba302..000000000 --- a/CMakeModules/FindZLIB.cmake +++ /dev/null @@ -1,58 +0,0 @@ -# Locate zlib -# This module defines -# ZLIB_LIBRARY -# ZLIB_FOUND, if false, do not try to link to zlib -# ZLIB_INCLUDE_DIR, where to find the headers -# -# $ZLIB_DIR is an environment variable that would -# correspond to the ./configure --prefix=$ZLIB_DIR -# used in building zlib. -# -# Created by Ulrich Hertlein. - -# prefer FindZLIB from cmake distribution -if(EXISTS ${CMAKE_ROOT}/Modules/FindZLIB.cmake) - include(${CMAKE_ROOT}/Modules/FindZLIB.cmake) - - if(ZLIB_FOUND) - return() - endif() -endif() - - -FIND_PATH(ZLIB_INCLUDE_DIR zlib.h - $ENV{ZLIB_DIR}/include - $ENV{ZLIB_DIR} - ~/Library/Frameworks - /Library/Frameworks - /usr/local/include - /usr/include - /sw/include # Fink - /opt/local/include # DarwinPorts - /opt/csw/include # Blastwave - /opt/include - /usr/freeware/include -) - -FIND_LIBRARY(ZLIB_LIBRARY - NAMES z libz zlib - PATHS - $ENV{ZLIB_DIR}/lib - $ENV{ZLIB_DIR} - ~/Library/Frameworks - /Library/Frameworks - /usr/local/lib - /usr/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - /usr/freeware/lib64 -) - -SET(ZLIB_FOUND "NO") -IF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR) - SET(ZLIB_FOUND "YES") -ENDIF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR) - - diff --git a/src/osgDB/CMakeLists.txt b/src/osgDB/CMakeLists.txt index 1d0f614d0..070a9cec6 100644 --- a/src/osgDB/CMakeLists.txt +++ b/src/osgDB/CMakeLists.txt @@ -162,7 +162,7 @@ ENDIF() IF( ZLIB_FOUND ) ADD_DEFINITIONS( -DUSE_ZLIB ) INCLUDE_DIRECTORIES( ${ZLIB_INCLUDE_DIR} ) - SET(COMPRESSION_LIBRARIES ZLIB_LIBRARY) + SET(COMPRESSION_LIBRARIES ZLIB_LIBRARIES) ENDIF() ################################################################################ diff --git a/src/osgPlugins/curl/CMakeLists.txt b/src/osgPlugins/curl/CMakeLists.txt index f20ea6284..667631f07 100644 --- a/src/osgPlugins/curl/CMakeLists.txt +++ b/src/osgPlugins/curl/CMakeLists.txt @@ -24,7 +24,7 @@ SET(TARGET_H IF(ZLIB_FOUND) SET(TARGET_LIBRARIES_VARS CURL_LIBRARY - ZLIB_LIBRARY) + ZLIB_LIBRARIES) ELSE() SET(TARGET_LIBRARIES_VARS CURL_LIBRARY) diff --git a/src/osgPlugins/dicom/CMakeLists.txt b/src/osgPlugins/dicom/CMakeLists.txt index 5932fa1aa..37f621a79 100644 --- a/src/osgPlugins/dicom/CMakeLists.txt +++ b/src/osgPlugins/dicom/CMakeLists.txt @@ -5,7 +5,7 @@ IF (DCMTK_FOUND) SET(TARGET_SRC ReaderWriterDICOM.cpp ) - LINK_LIBRARIES(${DCMTK_LIBRARIES} ${ZLIB_LIBRARY}) + LINK_LIBRARIES(${DCMTK_LIBRARIES} ${ZLIB_LIBRARIES}) ADD_DEFINITIONS(-DUSE_DCMTK) diff --git a/src/osgPlugins/exr/CMakeLists.txt b/src/osgPlugins/exr/CMakeLists.txt index 43894ff48..56ef8e0e4 100644 --- a/src/osgPlugins/exr/CMakeLists.txt +++ b/src/osgPlugins/exr/CMakeLists.txt @@ -2,7 +2,7 @@ INCLUDE_DIRECTORIES( ${OPENEXR_INCLUDE_DIR}/OpenEXR ) SET(TARGET_SRC ReaderWriterEXR.cpp ) -SET(TARGET_LIBRARIES_VARS ${OPENEXR_LIBRARIES_VARS} ZLIB_LIBRARY) +SET(TARGET_LIBRARIES_VARS ${OPENEXR_LIBRARIES_VARS} ZLIB_LIBRARIES) IF(CMAKE_COMPILER_IS_GNUCXX) # Remove -Wshadow flag as it barfs on ffmoeg headers diff --git a/src/osgPlugins/gz/CMakeLists.txt b/src/osgPlugins/gz/CMakeLists.txt index 86acc1c6d..9d5e758c4 100644 --- a/src/osgPlugins/gz/CMakeLists.txt +++ b/src/osgPlugins/gz/CMakeLists.txt @@ -4,7 +4,7 @@ SET(TARGET_SRC ReaderWriterGZ.cpp ) -SET(TARGET_LIBRARIES_VARS ZLIB_LIBRARY ) +SET(TARGET_LIBRARIES_VARS ZLIB_LIBRARIES ) #### end var setup ### diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 311103a6e..784a79c7e 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -269,7 +269,7 @@ SET(TARGET_H SET(TARGET_ADDED_LIBRARIES osgSim osgFX osgText osgTerrain osgVolume) IF(ZLIB_FOUND) - SET(TARGET_LIBRARIES_VARS ZLIB_LIBRARY) + SET(TARGET_LIBRARIES_VARS ZLIB_LIBRARIES) ENDIF() #### end var setup ### diff --git a/src/osgPlugins/png/CMakeLists.txt b/src/osgPlugins/png/CMakeLists.txt index b090fb7ab..33df903d2 100644 --- a/src/osgPlugins/png/CMakeLists.txt +++ b/src/osgPlugins/png/CMakeLists.txt @@ -5,7 +5,7 @@ IF(OSG_CPP_EXCEPTIONS_AVAILABLE) ENDIF() SET(TARGET_SRC ReaderWriterPNG.cpp ) -SET(TARGET_LIBRARIES_VARS PNG_LIBRARY ZLIB_LIBRARY ) +SET(TARGET_LIBRARIES_VARS PNG_LIBRARY ZLIB_LIBRARIES ) #### end var setup ### diff --git a/src/osgPlugins/vnc/CMakeLists.txt b/src/osgPlugins/vnc/CMakeLists.txt index af0b1210c..9a54b2bf2 100644 --- a/src/osgPlugins/vnc/CMakeLists.txt +++ b/src/osgPlugins/vnc/CMakeLists.txt @@ -4,7 +4,7 @@ INCLUDE_DIRECTORIES(${LIBVNCSERVER_INCLUDE_DIR}) SET(TARGET_EXTERNAL_LIBRARIES ${LIBVNCCLIENT_LIBRARY} - ${ZLIB_LIBRARY} + ${ZLIB_LIBRARIES} ${JPEG_LIBRARY} ) SET(TARGET_ADDED_LIBRARIES osgWidget ) diff --git a/src/osgPlugins/vrml/CMakeLists.txt b/src/osgPlugins/vrml/CMakeLists.txt index 867e0dfff..cacff5a31 100644 --- a/src/osgPlugins/vrml/CMakeLists.txt +++ b/src/osgPlugins/vrml/CMakeLists.txt @@ -25,7 +25,7 @@ IF (WIN32) OPENVRML_LIBRARY JPEG_LIBRARY PNG_LIBRARY - ZLIB_LIBRARY) + ZLIB_LIBRARIES) SET(TARGET_EXTERNAL_LIBRARIES Ws2_32.lib) ELSE() From f186f6b2d4f11fff14f4247d1d492e24a14e71ce Mon Sep 17 00:00:00 2001 From: Uwe Woessner Date: Tue, 15 Aug 2017 15:42:22 +0100 Subject: [PATCH 6/7] Extension to the PLY plugin to read files with textures. --- src/osgPlugins/ply/vertexData.cpp | 119 +++++++++++++++++++++++++----- src/osgPlugins/ply/vertexData.h | 4 +- 2 files changed, 103 insertions(+), 20 deletions(-) diff --git a/src/osgPlugins/ply/vertexData.cpp b/src/osgPlugins/ply/vertexData.cpp index 81a279a55..00ce08758 100644 --- a/src/osgPlugins/ply/vertexData.cpp +++ b/src/osgPlugins/ply/vertexData.cpp @@ -18,6 +18,10 @@ #include #include #include +#include +#include +#include +#include using namespace std; using namespace ply; @@ -35,6 +39,7 @@ VertexData::VertexData() _diffuse = NULL; _ambient = NULL; _specular = NULL; + _texcoord = NULL; } @@ -66,6 +71,8 @@ void VertexData::readVertices( PlyFile* file, const int nVertices, unsigned char specular_blue; float specular_coeff; float specular_power; + float texture_u; + float texture_v; } vertex; PlyProperty vertexProps[] = @@ -74,8 +81,8 @@ void VertexData::readVertices( PlyFile* file, const int nVertices, { "y", PLY_FLOAT, PLY_FLOAT, offsetof( _Vertex, y ), 0, 0, 0, 0 }, { "z", PLY_FLOAT, PLY_FLOAT, offsetof( _Vertex, z ), 0, 0, 0, 0 }, { "nx", PLY_FLOAT, PLY_FLOAT, offsetof( _Vertex, nx ), 0, 0, 0, 0 }, - { "ny", PLY_FLOAT, PLY_FLOAT, offsetof( _Vertex, ny ), 0, 0, 0, 0 }, - { "nz", PLY_FLOAT, PLY_FLOAT, offsetof( _Vertex, nz ), 0, 0, 0, 0 }, + { "ny", PLY_FLOAT, PLY_FLOAT, offsetof(_Vertex, ny), 0, 0, 0, 0 }, + { "nz", PLY_FLOAT, PLY_FLOAT, offsetof(_Vertex, nz), 0, 0, 0, 0 }, { "red", PLY_UCHAR, PLY_UCHAR, offsetof( _Vertex, red ), 0, 0, 0, 0 }, { "green", PLY_UCHAR, PLY_UCHAR, offsetof( _Vertex, green ), 0, 0, 0, 0 }, { "blue", PLY_UCHAR, PLY_UCHAR, offsetof( _Vertex, blue ), 0, 0, 0, 0 }, @@ -91,6 +98,8 @@ void VertexData::readVertices( PlyFile* file, const int nVertices, { "specular_blue", PLY_UCHAR, PLY_UCHAR, offsetof( _Vertex, specular_blue ), 0, 0, 0, 0 }, { "specular_coeff", PLY_FLOAT, PLY_FLOAT, offsetof( _Vertex, specular_coeff ), 0, 0, 0, 0 }, { "specular_power", PLY_FLOAT, PLY_FLOAT, offsetof( _Vertex, specular_power ), 0, 0, 0, 0 }, + { "texture_u", PLY_FLOAT, PLY_FLOAT, offsetof(_Vertex, texture_u), 0, 0, 0, 0 }, + { "texture_v", PLY_FLOAT, PLY_FLOAT, offsetof(_Vertex, texture_v), 0, 0, 0, 0 }, }; // use all 6 properties when reading colors, only the first 3 otherwise @@ -120,6 +129,10 @@ void VertexData::readVertices( PlyFile* file, const int nVertices, for( int i = 16; i < 21; ++i ) ply_get_property( file, "vertex", &vertexProps[i] ); + if (fields & TEXCOORD) + for (int i = 21; i < 23; ++i) + ply_get_property(file, "vertex", &vertexProps[i]); + // check whether array is valid otherwise allocate the space if(!_vertices.valid()) _vertices = new osg::Vec3Array; @@ -154,6 +167,11 @@ void VertexData::readVertices( PlyFile* file, const int nVertices, if(!_specular.valid()) _specular = new osg::Vec4Array; } + if (fields & TEXCOORD) + { + if (!_texcoord.valid()) + _texcoord = new osg::Vec2Array; + } // read in the vertices for( int i = 0; i < nVertices; ++i ) @@ -186,6 +204,8 @@ void VertexData::readVertices( PlyFile* file, const int nVertices, _specular->push_back( osg::Vec4( (unsigned int) vertex.specular_red / 255.0, (unsigned int) vertex.specular_green / 255.0 , (unsigned int) vertex.specular_blue / 255.0, 1.0 ) ); + if (fields & TEXCOORD) + _texcoord->push_back(osg::Vec2(vertex.texture_u,vertex.texture_v)); } } @@ -291,13 +311,47 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor MESHINFO << filename << ": " << nPlyElems << " elements, file type = " << fileType << ", version = " << version << endl; #endif - + char *textureFile = NULL; for( int i = 0; i < nComments; i++ ) { if( equal_strings( comments[i], "modified by flipply" ) ) { _invertFaces = true; } + if (strncmp(comments[i], "TextureFile",11)==0) + { + textureFile = comments[i]+12; + char * path = new char[strlen(const_cast(filename)) + 1 + strlen(comments[i])]; + if (textureFile[0] == '\\' || textureFile[0] == '/' || textureFile[1] == ':') + { + // texture filename is absolute + strcpy(path, textureFile); + } + else + { + // texture filename is relative + // add directory of ply file + strcpy(path, const_cast(filename)); + char *pp = path + strlen(path); + while (pp >= path) + { + if (*pp == '\\' || *pp == '/') + { + pp++; + *pp = '\0'; + break; + } + pp--; + } + if (pp == path - 1) + { + pp++; + *pp = '\0'; + } + strcat(path, textureFile); + } + textureFile = path; + } } for( int i = 0; i < nPlyElems; ++i ) @@ -330,10 +384,10 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor // if the string is vertex means vertex data is started if( equal_strings( elemNames[i], "vertex" ) ) { - int fields = NONE; + int fields = NONE; // determine if the file stores vertex colors for( int j = 0; j < nProps; ++j ) - { + { // if the string have the red means color info is there if( equal_strings( props[j]->name, "x" ) ) fields |= XYZ; @@ -347,15 +401,19 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor fields |= AMBIENT; if( equal_strings( props[j]->name, "diffuse_red" ) ) fields |= DIFFUSE; - if( equal_strings( props[j]->name, "specular_red" ) ) + if (equal_strings(props[j]->name, "specular_red")) fields |= SPECULAR; - } + if (equal_strings(props[j]->name, "texture_u")) + fields |= TEXCOORD; + if (equal_strings(props[j]->name, "texture_v")) + fields |= TEXCOORD; + } if( ignoreColors ) - { - fields &= ~(XYZ | NORMALS); - MESHINFO << "Colors in PLY file ignored per request." << endl; - } + { + fields &= ~(XYZ | NORMALS); + MESHINFO << "Colors in PLY file ignored per request." << endl; + } try { // Read vertices and store in a std::vector array @@ -363,7 +421,7 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor // Check whether all vertices are loaded or not MESHASSERT( _vertices->size() == static_cast< size_t >( nElems ) ); - // Check if all the optional elements were read or not + // Check if all the optional elements were read or not if( fields & NORMALS ) { MESHASSERT( _normals->size() == static_cast< size_t >( nElems ) ); @@ -380,9 +438,13 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor { MESHASSERT( _diffuse->size() == static_cast< size_t >( nElems ) ); } - if( fields & SPECULAR ) + if (fields & SPECULAR) { - MESHASSERT( _specular->size() == static_cast< size_t >( nElems ) ); + MESHASSERT(_specular->size() == static_cast< size_t >(nElems)); + } + if (fields & TEXCOORD) + { + MESHASSERT(_texcoord->size() == static_cast< size_t >(nElems)); } result = true; @@ -462,9 +524,9 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor geom->addPrimitiveSet(new osg::DrawArrays(GL_POINTS, 0, _vertices->size())); - // Apply the colours to the model; at the moment this is a - // kludge because we only use one kind and apply them all the - // same way. Also, the priority order is completely arbitrary + // Apply the colours to the model; at the moment this is a + // kludge because we only use one kind and apply them all the + // same way. Also, the priority order is completely arbitrary if(_colors.valid()) { @@ -478,10 +540,14 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor { geom->setColorArray(_diffuse.get(), osg::Array::BIND_PER_VERTEX ); } - else if(_specular.valid()) + else if(_specular.valid()) { geom->setColorArray(_specular.get(), osg::Array::BIND_PER_VERTEX ); } + else if (_texcoord.valid()) + { + geom->setTexCoordArray(0, _texcoord); + } // If the model has normals, add them to the geometry if(_normals.valid()) @@ -497,11 +563,26 @@ osg::Node* VertexData::readPlyFile( const char* filename, const bool ignoreColor // set flage true to activate the vertex buffer object of drawable geom->setUseVertexBufferObjects(true); + osg::Image *image = NULL; + if (textureFile && (image = osgDB::readImageFile(textureFile)) != NULL) + { + osg::Texture2D *texture = new osg::Texture2D; + texture->setImage(image); + texture->setResizeNonPowerOfTwoHint(false); + + osg::TexEnv *texenv = new osg::TexEnv; + texenv->setMode(osg::TexEnv::REPLACE); + + osg::StateSet *stateset = geom->getOrCreateStateSet(); + stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); + stateset->setTextureAttribute(0, texenv); + delete[] textureFile; + } osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); return geode; - } + } return NULL; } diff --git a/src/osgPlugins/ply/vertexData.h b/src/osgPlugins/ply/vertexData.h index dec0a663a..e2cd3a646 100644 --- a/src/osgPlugins/ply/vertexData.h +++ b/src/osgPlugins/ply/vertexData.h @@ -55,7 +55,8 @@ namespace ply AMBIENT = 8, DIFFUSE = 16, SPECULAR = 32, - RGBA = 64 + RGBA = 64, + TEXCOORD = 128 }; // Function which reads all the vertices and colors if color info is @@ -75,6 +76,7 @@ namespace ply osg::ref_ptr _ambient; osg::ref_ptr _diffuse; osg::ref_ptr _specular; + osg::ref_ptr _texcoord; // Normals in osg format osg::ref_ptr _normals; From 7b2dbc603c006f1add8ec4a2cadd366c45f778c1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 15 Aug 2017 16:35:23 +0100 Subject: [PATCH 7/7] Fixed warning --- examples/osgtext3D/osgtext3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/osgtext3D/osgtext3D.cpp b/examples/osgtext3D/osgtext3D.cpp index 7495064e4..64c2c086b 100644 --- a/examples/osgtext3D/osgtext3D.cpp +++ b/examples/osgtext3D/osgtext3D.cpp @@ -43,7 +43,7 @@ public: { } - virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) + virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&) { if (ea.getEventType() == osgGA::GUIEventAdapter::KEYUP) {