From 66fb3c128404ba4eb3f0b63b879dc0f23c938732 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 8 Jul 2013 02:58:06 +0200 Subject: [PATCH] Shapes can now be loaded and rendered to ViewPortWidget. --HG-- branch : gsoc2013-dfighter --- .../material_editor_window.cpp | 3 + .../material_editor/nel3d_interface.cpp | 34 ++++++ .../plugins/material_editor/nel3d_interface.h | 1 + .../material_editor/viewport_widget.cpp | 114 +++++++++++------- .../plugins/material_editor/viewport_widget.h | 8 ++ 5 files changed, 116 insertions(+), 44 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp index 673ac1134..c9f344f5b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp @@ -98,6 +98,8 @@ namespace MaterialEditor tr( "There was an error while loading the shape file." ) ); } + + viewPort->startTimedUpdates( 20 ); } void MaterialEditorWindow::onNewMaterialClicked() @@ -179,6 +181,7 @@ namespace MaterialEditor void MaterialEditorWindow::onClearSceneClicked() { nl3dIface->clearScene(); + viewPort->stopTimedUpdates(); } void MaterialEditorWindow::createMenus() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index 95d7d1f7a..13a0e9b9a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -23,6 +23,7 @@ #include "nel/3d/driver_user.h" #include "nel/3d/scene_user.h" #include "nel/3d/u_camera.h" +#include "nel/3d/u_instance.h" #include "nel/misc/i_xml.h" #include "nel/misc/o_xml.h" #include "nel/misc/file.h" @@ -31,6 +32,8 @@ namespace MaterialEditor { + NL3D::UInstance currentShape; + const char *SMatProp::idToString[] = { "Color", @@ -366,11 +369,42 @@ namespace MaterialEditor bool CNel3DInterface::loadShape( const std::string &fileName ) { + NLMISC::CPath::addSearchPath( NLMISC::CFile::getPath( fileName ), false, false ); + NL3D::UInstance instance = scene->createInstance( fileName ); + if( instance.empty() ) + return false; + + clearScene(); + currentShape = instance; + return true; } void CNel3DInterface::clearScene() { + if( scene != NULL ) + { + if( currentShape.empty() ) + return; + scene->deleteInstance( currentShape ); + currentShape = NL3D::UInstance(); + } + + if( driver == NULL ) + return; + + driver->clearBuffers(); + driver->swapBuffers(); + } + + void CNel3DInterface::renderScene() + { + if( scene != NULL ) + { + driver->clearBuffers(); + scene->render(); + driver->swapBuffers(); + } } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h index 04c7c0cb6..2aaa7d689 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h @@ -150,6 +150,7 @@ namespace MaterialEditor bool loadShape( const std::string &fileName ); void clearScene(); + void renderScene(); private: NL3D::CDynMaterial *mat; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp index 7e4211131..799e57e40 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.cpp @@ -32,6 +32,7 @@ namespace MaterialEditor QWidget( parent ) { nl3dIface = NULL; + timerId = 0; setAttribute( Qt::WA_PaintOnScreen, true ); } @@ -55,73 +56,98 @@ namespace MaterialEditor QWidget::resizeEvent( evnt ); } + void ViewPortWidget::startTimedUpdates( int interval ) + { + if( interval == 0 ) + return; -#if defined( NL_OS_WINDOWS ) + timerId = startTimer( interval ); + } -typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); + void ViewPortWidget::stopTimedUpdates() + { + killTimer( timerId ); + timerId = 0; + } -bool ViewPortWidget::winEvent( MSG *message, long *result ) -{ - NL3D::UDriver *udriver = nl3dIface->getDriver(); - if( ( udriver != NULL ) && udriver->isActive() ) + void ViewPortWidget::timerEvent( QTimerEvent *evnt ) { - NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver(); - if( driver != NULL ) - { - winProc proc = (winProc)driver->getWindowProc(); + int id = evnt->timerId(); + if( id == timerId ) + update(); + } - return proc( driver, message->hwnd, message->message, message->wParam, message->lParam ); +#if defined( NL_OS_WINDOWS ) + + typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); + + bool ViewPortWidget::winEvent( MSG *message, long *result ) + { + NL3D::UDriver *udriver = nl3dIface->getDriver(); + if( ( udriver != NULL ) && udriver->isActive() ) + { + NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver(); + if( driver != NULL ) + { + winProc proc = (winProc)driver->getWindowProc(); + return proc( driver, message->hwnd, message->message, message->wParam, message->lParam ); + } } + + return false; } - return false; -} - #elif defined( NL_OS_MAC ) -typedef bool ( *cocoaProc )( NL3D::IDriver *, const void *e ); - -bool ViewPortWidget::macEvent( EventHandlerCallRef caller, EventRef event ) -{ - if(caller) - nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt"); - - NL3D::UDriver *udriver = nl3dIface->getDriver(); - if( ( udriver != NULL ) && udriver->isActive() ) + typedef bool ( *cocoaProc )( NL3D::IDriver *, const void *e ); + + bool ViewPortWidget::macEvent( EventHandlerCallRef caller, EventRef event ) { - NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver(); - if( driver != NULL ) + if( caller ) + nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt"); + + NL3D::UDriver *udriver = nl3dIface->getDriver(); + if( ( udriver != NULL ) && udriver->isActive() ) { - cocoaProc proc = ( cocoaProc )driver->getWindowProc(); - proc( driver, event ); + NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver(); + if( driver != NULL ) + { + cocoaProc proc = ( cocoaProc )driver->getWindowProc(); + proc( driver, event ); + } } + + return false; } - return false; -} - #elif defined( NL_OS_UNIX ) - -typedef bool ( *x11Proc )( NL3D::IDriver *drv, XEvent *e ); - -bool ViewPortWidget::x11Event( XEvent *event ) -{ - - NL3D::UDriver *udriver = nl3dIface->getDriver(); - if( ( udriver != NULL ) && udriver->isActive() ) + + typedef bool ( *x11Proc )( NL3D::IDriver *drv, XEvent *e ); + + bool ViewPortWidget::x11Event( XEvent *event ) { - NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver(); - if( driver != NULL ) + NL3D::UDriver *udriver = nl3dIface->getDriver(); + + if( ( udriver != NULL ) && udriver->isActive() ) { - x11Proc proc = ( x11Proc )driver->getWindowProc(); - proc( driver, event ); + NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver(); + if( driver != NULL ) + { + x11Proc proc = ( x11Proc )driver->getWindowProc(); + proc( driver, event ); + } + } + return false; } - return false; -} #endif + void ViewPortWidget::update() + { + nl3dIface->renderScene(); + } + } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h index 154052bae..081cad53a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/viewport_widget.h @@ -39,8 +39,13 @@ namespace MaterialEditor QPaintEngine* paintEngine() const{ return NULL; } + void startTimedUpdates( int interval ); + void stopTimedUpdates(); + protected: + void timerEvent( QTimerEvent *evnt ); + #if defined ( NL_OS_WINDOWS ) bool winEvent( MSG *message, long *result ); #elif defined( NL_OS_MAC ) @@ -50,7 +55,10 @@ namespace MaterialEditor #endif private: + void update(); + CNel3DInterface *nl3dIface; + int timerId; }; }