Added ViewPortWidget.

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

@ -23,6 +23,7 @@ SET(OVQT_PLUGIN_MATERIAL_EDITOR_HDR
shader_editor.h
shader_widget.h
prop_browser_ctrl.h
viewport_widget.h
)
SET(OVQT_PLUGIN_MATERIAL_EDITOR_UIS

@ -20,6 +20,7 @@
#include "shader_widget.h"
#include "render_passes.h"
#include "nel3d_interface.h"
#include "viewport_widget.h"
#include "../core/icore.h"
#include "../core/core_constants.h"
@ -42,6 +43,8 @@ namespace MaterialEditor
m_ui.setupUi(this);
nl3dIface = new CNel3DInterface();
viewPort = new ViewPortWidget();
viewPort->setNel3DInterface( nl3dIface );
shaderWidget = new ShaderWidget();
shaderWidget->setNel3DInterface( nl3dIface );
materialSplitter = new MaterialSplitter();
@ -56,6 +59,8 @@ namespace MaterialEditor
createDockWidgets();
setupConnections();
setCentralWidget( viewPort );
QTimer::singleShot( 1, this, SLOT( onStartup() ) );
}
@ -65,6 +70,8 @@ namespace MaterialEditor
shaderWidget = NULL;
delete passesWidget;
passesWidget = NULL;
delete viewPort;
viewPort = NULL;
delete nl3dIface;
nl3dIface = NULL;
}
@ -78,7 +85,19 @@ namespace MaterialEditor
tr( "Shape files ( *.shape )" )
);
if( fn.isEmpty() )
return;
std::string fname = fn.toUtf8().data();
bool ok = nl3dIface->loadShape( fname );
if( !ok )
{
QMessageBox::critical(
this,
tr( "Error loading shape file" ),
tr( "There was an error while loading the shape file." )
);
}
}
void MaterialEditorWindow::onNewMaterialClicked()
@ -154,6 +173,12 @@ namespace MaterialEditor
{
nl3dIface->loadShaders();
shaderWidget->load();
viewPort->init();
}
void MaterialEditorWindow::onClearSceneClicked()
{
nl3dIface->clearScene();
}
void MaterialEditorWindow::createMenus()
@ -181,6 +206,13 @@ namespace MaterialEditor
mm->addAction( a );
}
mm = m->addMenu( tr( "Scene" ) );
{
a = new QAction( tr( "Clear scene" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onClearSceneClicked() ) );
mm->addAction( a );
}
a = new QAction( tr( "Shaders" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onShadersClicked() ) );
m->addAction( a );

@ -26,6 +26,7 @@ namespace MaterialEditor
class RenderPassesWidget;
class CNel3DInterface;
class MaterialSplitter;
class ViewPortWidget;
class MaterialEditorWindow: public QMainWindow
{
@ -43,6 +44,7 @@ private Q_SLOTS:
void onShadersClicked();
void onPassesClicked();
void onStartup();
void onClearSceneClicked();
private:
void createMenus();
@ -54,6 +56,7 @@ private:
ShaderWidget *shaderWidget;
RenderPassesWidget *passesWidget;
MaterialSplitter *materialSplitter;
ViewPortWidget *viewPort;
Ui::MaterialEditorWindow m_ui;
};

@ -20,6 +20,9 @@
#include "nel/3d/shader_program.h"
#include "nel/3d/shader_loader.h"
#include "nel/3d/shader_saver.h"
#include "nel/3d/driver_user.h"
#include "nel/3d/scene_user.h"
#include "nel/3d/u_camera.h"
#include "nel/misc/i_xml.h"
#include "nel/misc/o_xml.h"
#include "nel/misc/file.h"
@ -196,13 +199,15 @@ namespace MaterialEditor
{
mat = new NL3D::CDynMaterial();
shaderManager = new NL3D::CShaderManager();
driver = NULL;
scene = NULL;
}
CNel3DInterface::~CNel3DInterface()
{
delete shaderManager;
shaderManager = NULL;
killViewPort();
}
bool CNel3DInterface::loadMaterial( const char *fname )
@ -332,5 +337,40 @@ namespace MaterialEditor
{
NLMISC::CFile::deleteFile( "./shaders/" + name + ".nlshdr" );
}
void CNel3DInterface::initViewPort( unsigned long wnd, unsigned long w, unsigned long h )
{
driver = NL3D::UDriver::createDriver( 0, false, 0 );
nlassert( driver != NULL );
driver->setDisplay( (nlWindow)wnd, NL3D::UDriver::CMode( w, h, 32 ) );
scene = driver->createScene( true );
}
void CNel3DInterface::killViewPort()
{
driver->deleteScene( scene );
delete driver;
driver = NULL;
}
void CNel3DInterface::resizeViewPort( unsigned long w, unsigned long h )
{
if( scene != NULL )
{
scene->getCam().setPerspective( 90.0f, w / (float)h, 0.1f, 1000.0f );
}
}
bool CNel3DInterface::loadShape( const std::string &fileName )
{
return true;
}
void CNel3DInterface::clearScene()
{
}
}

@ -26,6 +26,8 @@ namespace NL3D
class CDynMaterial;
struct SRenderPass;
class CShaderManager;
class UDriver;
class UScene;
}
namespace MaterialEditor
@ -141,9 +143,20 @@ namespace MaterialEditor
void saveShader( const std::string &name );
void deleteShader( const std::string &name );
void initViewPort( unsigned long wnd, unsigned long w, unsigned long h );
void killViewPort();
void resizeViewPort( unsigned long w, unsigned long h );
NL3D::UDriver* getDriver(){ return driver; }
bool loadShape( const std::string &fileName );
void clearScene();
private:
NL3D::CDynMaterial *mat;
NL3D::CShaderManager *shaderManager;
NL3D::UDriver *driver;
NL3D::UScene *scene;
};
}

@ -0,0 +1,127 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "viewport_widget.h"
#include <QResizeEvent>
#include "nel3d_interface.h"
#include "nel/3d/driver.h"
#include "nel/3d/driver_user.h"
#ifdef NL_OS_WINDOWS
#include <Windows.h>
#endif
namespace MaterialEditor
{
ViewPortWidget::ViewPortWidget( QWidget *parent ) :
QWidget( parent )
{
nl3dIface = NULL;
setAttribute( Qt::WA_PaintOnScreen, true );
}
ViewPortWidget::~ViewPortWidget()
{
}
void ViewPortWidget::init()
{
nl3dIface->initViewPort( (unsigned long)winId(), width(), height() );
}
void ViewPortWidget::resizeEvent( QResizeEvent *evnt )
{
uint32 w = evnt->size().width();
uint32 h = evnt->size().height();
nl3dIface->resizeViewPort( w, h );
QWidget::resizeEvent( evnt );
}
#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;
}
#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() )
{
NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver();
if( driver != NULL )
{
cocoaProc proc = ( cocoaProc )driver->getWindowProc();
proc( driver, event );
}
}
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() )
{
NL3D::IDriver *driver = dynamic_cast< NL3D::CDriverUser* >( udriver )->getDriver();
if( driver != NULL )
{
x11Proc proc = ( x11Proc )driver->getWindowProc();
proc( driver, event );
}
}
return false;
}
#endif
}

@ -0,0 +1,60 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef VIEWPORT_WIDGET_H
#define VIEWPORT_WIDGET_H
#include <QWidget>
#include "nel/misc/types_nl.h"
#include "nel/misc/event_emitter.h"
namespace MaterialEditor
{
class CNel3DInterface;
class ViewPortWidget : public QWidget
{
Q_OBJECT
public:
ViewPortWidget( QWidget *parent = NULL );
~ViewPortWidget();
void setNel3DInterface( CNel3DInterface *iface ){ nl3dIface = iface; }
void init();
void resizeEvent( QResizeEvent *evnt );
QPaintEngine* paintEngine() const{ return NULL; }
protected:
#if defined ( NL_OS_WINDOWS )
bool winEvent( MSG *message, long *result );
#elif defined( NL_OS_MAC )
bool macEvent( EventHandlerCallRef caller, EventRef event ) ;
#elif defined( NL_OS_UNIX )
bool x11Event( XEvent *event );
#endif
private:
CNel3DInterface *nl3dIface;
};
}
#endif
Loading…
Cancel
Save