Shapes can now be loaded and rendered to ViewPortWidget.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 8408ddd552
commit 66fb3c1284

@ -98,6 +98,8 @@ namespace MaterialEditor
tr( "There was an error while loading the shape file." ) tr( "There was an error while loading the shape file." )
); );
} }
viewPort->startTimedUpdates( 20 );
} }
void MaterialEditorWindow::onNewMaterialClicked() void MaterialEditorWindow::onNewMaterialClicked()
@ -179,6 +181,7 @@ namespace MaterialEditor
void MaterialEditorWindow::onClearSceneClicked() void MaterialEditorWindow::onClearSceneClicked()
{ {
nl3dIface->clearScene(); nl3dIface->clearScene();
viewPort->stopTimedUpdates();
} }
void MaterialEditorWindow::createMenus() void MaterialEditorWindow::createMenus()

@ -23,6 +23,7 @@
#include "nel/3d/driver_user.h" #include "nel/3d/driver_user.h"
#include "nel/3d/scene_user.h" #include "nel/3d/scene_user.h"
#include "nel/3d/u_camera.h" #include "nel/3d/u_camera.h"
#include "nel/3d/u_instance.h"
#include "nel/misc/i_xml.h" #include "nel/misc/i_xml.h"
#include "nel/misc/o_xml.h" #include "nel/misc/o_xml.h"
#include "nel/misc/file.h" #include "nel/misc/file.h"
@ -31,6 +32,8 @@
namespace MaterialEditor namespace MaterialEditor
{ {
NL3D::UInstance currentShape;
const char *SMatProp::idToString[] = const char *SMatProp::idToString[] =
{ {
"Color", "Color",
@ -366,11 +369,42 @@ namespace MaterialEditor
bool CNel3DInterface::loadShape( const std::string &fileName ) 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; return true;
} }
void CNel3DInterface::clearScene() 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();
}
} }
} }

@ -150,6 +150,7 @@ namespace MaterialEditor
bool loadShape( const std::string &fileName ); bool loadShape( const std::string &fileName );
void clearScene(); void clearScene();
void renderScene();
private: private:
NL3D::CDynMaterial *mat; NL3D::CDynMaterial *mat;

@ -32,6 +32,7 @@ namespace MaterialEditor
QWidget( parent ) QWidget( parent )
{ {
nl3dIface = NULL; nl3dIface = NULL;
timerId = 0;
setAttribute( Qt::WA_PaintOnScreen, true ); setAttribute( Qt::WA_PaintOnScreen, true );
} }
@ -55,13 +56,33 @@ namespace MaterialEditor
QWidget::resizeEvent( evnt ); QWidget::resizeEvent( evnt );
} }
void ViewPortWidget::startTimedUpdates( int interval )
{
if( interval == 0 )
return;
timerId = startTimer( interval );
}
void ViewPortWidget::stopTimedUpdates()
{
killTimer( timerId );
timerId = 0;
}
void ViewPortWidget::timerEvent( QTimerEvent *evnt )
{
int id = evnt->timerId();
if( id == timerId )
update();
}
#if defined( NL_OS_WINDOWS ) #if defined( NL_OS_WINDOWS )
typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); typedef bool ( *winProc )( NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
bool ViewPortWidget::winEvent( MSG *message, long *result ) bool ViewPortWidget::winEvent( MSG *message, long *result )
{ {
NL3D::UDriver *udriver = nl3dIface->getDriver(); NL3D::UDriver *udriver = nl3dIface->getDriver();
if( ( udriver != NULL ) && udriver->isActive() ) if( ( udriver != NULL ) && udriver->isActive() )
{ {
@ -69,21 +90,20 @@ bool ViewPortWidget::winEvent( MSG *message, long *result )
if( driver != NULL ) if( driver != NULL )
{ {
winProc proc = (winProc)driver->getWindowProc(); winProc proc = (winProc)driver->getWindowProc();
return proc( driver, message->hwnd, message->message, message->wParam, message->lParam ); return proc( driver, message->hwnd, message->message, message->wParam, message->lParam );
} }
} }
return false; return false;
} }
#elif defined( NL_OS_MAC ) #elif defined( NL_OS_MAC )
typedef bool ( *cocoaProc )( NL3D::IDriver *, const void *e ); typedef bool ( *cocoaProc )( NL3D::IDriver *, const void *e );
bool ViewPortWidget::macEvent( EventHandlerCallRef caller, EventRef event ) bool ViewPortWidget::macEvent( EventHandlerCallRef caller, EventRef event )
{ {
if(caller) if( caller )
nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt"); nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt");
NL3D::UDriver *udriver = nl3dIface->getDriver(); NL3D::UDriver *udriver = nl3dIface->getDriver();
@ -98,16 +118,16 @@ bool ViewPortWidget::macEvent( EventHandlerCallRef caller, EventRef event )
} }
return false; return false;
} }
#elif defined( NL_OS_UNIX ) #elif defined( NL_OS_UNIX )
typedef bool ( *x11Proc )( NL3D::IDriver *drv, XEvent *e ); typedef bool ( *x11Proc )( NL3D::IDriver *drv, XEvent *e );
bool ViewPortWidget::x11Event( XEvent *event )
{
bool ViewPortWidget::x11Event( XEvent *event )
{
NL3D::UDriver *udriver = nl3dIface->getDriver(); NL3D::UDriver *udriver = nl3dIface->getDriver();
if( ( udriver != NULL ) && udriver->isActive() ) if( ( udriver != NULL ) && udriver->isActive() )
{ {
NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver(); NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver();
@ -116,12 +136,18 @@ bool ViewPortWidget::x11Event( XEvent *event )
x11Proc proc = ( x11Proc )driver->getWindowProc(); x11Proc proc = ( x11Proc )driver->getWindowProc();
proc( driver, event ); proc( driver, event );
} }
}
}
return false; return false;
} }
#endif #endif
void ViewPortWidget::update()
{
nl3dIface->renderScene();
}
} }

@ -39,8 +39,13 @@ namespace MaterialEditor
QPaintEngine* paintEngine() const{ return NULL; } QPaintEngine* paintEngine() const{ return NULL; }
void startTimedUpdates( int interval );
void stopTimedUpdates();
protected: protected:
void timerEvent( QTimerEvent *evnt );
#if defined ( NL_OS_WINDOWS ) #if defined ( NL_OS_WINDOWS )
bool winEvent( MSG *message, long *result ); bool winEvent( MSG *message, long *result );
#elif defined( NL_OS_MAC ) #elif defined( NL_OS_MAC )
@ -50,7 +55,10 @@ namespace MaterialEditor
#endif #endif
private: private:
void update();
CNel3DInterface *nl3dIface; CNel3DInterface *nl3dIface;
int timerId;
}; };
} }

Loading…
Cancel
Save