Plugin interface
Interface for all viewer plugins
Plugin Class Reference

#include <plugin.h>

Public Member Functions

 Plugin ()
 
virtual ~Plugin ()
 
virtual void onPluginLoad ()
 
virtual void onObjectAdd ()
 
virtual void onSceneClear ()
 
virtual void preFrame ()
 
virtual void postFrame ()
 
virtual void keyPressEvent (QKeyEvent *)
 
virtual void keyReleaseEvent (QKeyEvent *)
 
virtual void mouseMoveEvent (QMouseEvent *)
 
virtual void mousePressEvent (QMouseEvent *)
 
virtual void mouseReleaseEvent (QMouseEvent *)
 
virtual void wheelEvent (QWheelEvent *)
 
virtual bool paintGL ()
 
virtual bool drawScene ()
 
virtual bool drawObject (int)
 
Scene * scene ()
 
Camera * camera ()
 
PlugindrawPlugin ()
 
GLWidget * glwidget ()
 
void setWidget (GLWidget *glwidget)
 
void setDrawPlugin (Plugin *drawPlugin)
 
void setArgs (const string &str)
 
string args () const
 

Detailed Description

/class Plugin /brief The Plugin class is the base class for all plugins.

All plugins you will have to implement must derive from this class.

All methods have a default implementation (do nothing), so each plugin can override only those methods needed to provide the intended functionality.

An Effect Plugin might override preFrame() and postFrame() methods to modify the OpenGL state before and after the scene is rendered (for example, to load shaders or to enable alphablending) and to draw additional content (for example, the frame rate).

A Draw Plugin might override the drawScene() method, which is in charge of drawing all the objects forming the scene by issuing OpenGL rendering commands.

An Action Plugin might override user input methods such as keyPressEvent(), mouseMoveEvent() to allow for some interaction: camera control, object selection...

A Render Plugin should override paintGL(). The main purpose is to implement techniques requiring multiple rendering passes, for example, shadow mapping.

Constructor & Destructor Documentation

Plugin::Plugin ( )
inline

Constructs a basic plugin.

virtual Plugin::~Plugin ( )
inlinevirtual

Destroys the plugin.

Member Function Documentation

Camera* Plugin::camera ( )
inline

Returns a pointer to the Camera.

virtual bool Plugin::drawObject ( int  )
inlinevirtual

Draws the i-th object in the scene

Plugin* Plugin::drawPlugin ( )
inline

Returns a pointer to a plugin implementing drawScene(). If no such a plugin has been loaded, returns null.

virtual bool Plugin::drawScene ( )
inlinevirtual

This method is intended to be involked by any plugin willing to draw the scene. For example, a plugin overriding paintGL(). If you override drawScene(), you must always return true so that the application knows the scene has been drawn successfully. The GLWidget class keeps track of the plugin overriding this method. Using legacy code, a minimal implementation could be:

bool MyPluginExample::drawScene()
{
for (unsigned int i=0; i<scene()->objects().size(); ++i)
{
const Object& obj = scene()->objects()[i];
for (unsigned int c=0; c<obj.faces().size(); c++)
{
const Face& face = obj.faces()[c];
glBegin(GL_POLYGON);
glNormal3f(face.normal().x(), face.normal().y(), face.normal().z());
for(int v=0; v<face.numVertices(); v++)
{
const Point& p = obj.vertices()[face.vertexIndex(v)].coord();
glVertex3f(p.x(), p.y(), p.z());
}
glEnd();
}
}
return true;
}
GLWidget* Plugin::glwidget ( )
inline

Returns a pointer to the GLWidget.

virtual void Plugin::keyPressEvent ( QKeyEvent *  )
inlinevirtual

See the QOpenGLWidget reference.

virtual void Plugin::keyReleaseEvent ( QKeyEvent *  )
inlinevirtual

See the QOpenGLWidget reference.

virtual void Plugin::mouseMoveEvent ( QMouseEvent *  )
inlinevirtual

See the QOpenGLWidget reference.

virtual void Plugin::mousePressEvent ( QMouseEvent *  )
inlinevirtual

See the QOpenGLWidget reference.

virtual void Plugin::mouseReleaseEvent ( QMouseEvent *  )
inlinevirtual

See the QOpenGLWidget reference.

virtual void Plugin::onObjectAdd ( )
inlinevirtual

This method is called everytime a new object is added to the scene. This allows your plugin to execute some code everytime the scene has changed.

virtual void Plugin::onPluginLoad ( )
inlinevirtual

This method is called right after the plugin has been loaded by the application. A valid OpenGL context allways exists when this method is invoked. This method usually has code for initializing the plugin: compile shaders, load textures, setup timers... The scene might contain some objects but it could also be empty.

virtual void Plugin::onSceneClear ( )
inlinevirtual

This method is called everytime the scene is cleared (all objects are removed). This allows your plugin to execute some code everytime the scene has been cleared.

virtual bool Plugin::paintGL ( )
inlinevirtual

This method is invoked by GLWidget::paintGL(). It is responsible of painting everything whenever the widget needs to be painted. A minimal implementation should call glClear and then invoke the drawScene() method of the current Draw Plugin :

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
return true;

If you override paintGL(), you must always return true so that the application knows it has been repainted successfully.

virtual void Plugin::postFrame ( )
inlinevirtual

This method is called in GLWidget::paintGL() after drawing the scene. This allows your plugin to execute some code to be executed right after the scene is rendered. A typical use would be to unbind a shader, or drawing additional primitives (for example, the frame rate or a wireframe box around the selected object).

virtual void Plugin::preFrame ( )
inlinevirtual

This method is called in GLWidget::paintGL() before drawing the scene. This allows your plugin to execute some code to be executed right before the scene is rendered. A typical use would be to bind a shader affecting the whole scene. Notice that glClear() is likely to be called after all preFrame() methods have been executed, so you should not draw anything here. For drawing additional primitives override the postFrame() method instead.

Scene* Plugin::scene ( )
inline

Returns a pointer to the Scene.

virtual void Plugin::wheelEvent ( QWheelEvent *  )
inlinevirtual

See the QOpenGLWidget reference.