MeshShop

Youll be implementing your remaining assignments and extra point projects inside MeshShop, a framework that we provide to you. There are a couple main reason for the framework. 

  1. So that we can hopefully get the useful bits of everyones project to compile together. We need a central framework or this would be hopeless.

  2. So that you can have a little experience working on larger project for which you cant have control over every piece (the usual situation outside of class). T

There will be some very simple code in place which allows you to load a mesh from a file, render it on the screen, and change its orientation. All of the interesting functionality will be written by either prior students, you, or future students.

The framework has a basic Mesh datatype which contains the data for the loaded mesh(es). You can write feature plugins. A plugin might draw the mesh to the screen, or load a mesh, or allow you to select a region, or deform a mesh. Think of the plugins to PhotoShop. 

 

All of the core functionality that we provide you will also be implemented as feature plugins so you can see examples of what to do. Well be providing roughly the following: Load Mesh From File, Very Simple Drawing On Screen, Simple Mesh Manipulator, and Very Simple Mesh Filter.

 

 

Callback functions:

Each plugin will implement some subset of the following functions. These are callback functions similar to the kind you used with GLUT. In fact MeshShop uses GLUT underneath.

You probably wont use all of these. For example, if you want to make a painterly rendering option, and you dont want any options, you might only implement a display() function which draws each mesh on the screen. If you want to make a sophisticated manipulator which allows the user to drag the mouse and change the mesh viewing direction, you might implement mouse() and nothing else. Someone who wants to remove noise in the mesh might only implement filter(). However most people will probably implement a few of s that go with the mesh structure. Instead plugins can dynamically create "properties" of any type they want. You should think of these properties as fields in a structure or class, just dynamically extendable. 

 

So that plugins can communicate with each other there has to be a list of standard properties. It would be a disaster if the mesh loading plugin thought that mesh vertices should be called "MeshVert" and the display plugin thought they were called "Vertex". 

 

Properties have types. They are always a list of elements implemented as an STL vector. They could be double, long, double3, long3, etc... Its worth noting that double3 means that each "element" is 3 doubles packed together, such as X,Y,Z or R,G,B. The property itself would be a vector of many XYZ triples.

 

 

The most basic things we need to render a mesh are triangles and vertices:

We also need the normal direction to render with lighting. These could be attached to either faces or vertices. As should be apparent, the display plugin cant _assume_ that the property is initialized or set unless it did so itself. In this case, probably only one or the other is defined, but possibly both.

A name is not strictly needed for rendering, but quickly become useful:

Transformations of matrices are needed. Since our properties are 1D vectors, well pack the 4x4 transform into a double[16] in the same order that OpenGL does.

Additional properties used by some meshes:

This brings us to another point. Some properties are not associated with a particular mesh but rather with the whole scene. The current position of the camera is an example of that. It would be nice to store the 4x4 matrix (16 doubles) which represent the camera view.

Thus we have a special mesh named "Sceot;SceneProperties". Recall that the name is stored in the "name" property.:

Its helpful to have a notion of which vertices are selected.

Purely as a matter of efficiency, some plugins want to cache information and only recalculate if someone changed things.

If you find you need a new property go ahead and just make it up. If you want to get it into this list of "standard" properties, then talk to me and well get it approved and added.

Very Simple Example:

This example can be found in .../meshshop/plugins/filter/grow/grow.cpp.

The base code and definitions can be found in .../meshshop/base/plugin.h

First lets look at how we declare a new plugin. We simply subclass it from the base plugin class. Further we declare the two types of callbacks we will use in this case. Just the startup() callback to initialize some things, and the changed() callback to let us modify a mesh whenever this plugin is chosen.

class PluginGrow : public Plugin_Base {
  void startup();
  void changed(MeshVec&);
};

Now lets look at how we might implement this. We need to register the plugin auto-magically (just copy this line, dont worry about it).

We need to implement the changed callback. Note that we get passed a list of the currently active meshes in the form of an STL vector. We can get properties of individual meshes using the GetDouble3Property() function. You have to know the type of the property you want to fetch so that you can call the right function.

 

Finally we need to declare what kind of plugin this is in the startup() function.

PluginGrow autoInitPluginGrow; // Auto-magically includes your plugin at compile time.

void PluginGrow::changed(MeshVec& meshList)
{

// Loop over meshes for (int m"0; m<meshList.size(); m++) {
// Get the vertex list for this mesh Double3Vec &v " (meshList)[m].GetDouble3Property("vertex_pos"); // Loop over all vertices and double their position for(int i"0;i<v.size();i++) { v[i].a " 2 * v[i].a; v[i].b " 2 * v[i].b; v[i].c " 2 * v[i].c; } } } void PluginGrow::startup() { // The name that goes in a menu somewhere name""grow"; // We want to be in the filter menu type"PT_FILTER; }

Example of Display Plugin in psuedocode:

    SetMatrixMode to GL_MODELVIEW
    LoadIdentity
    Get "camera" property of "SceneProperties" mesh
    Multiply "camera" onto matrix stack
    Loop over all meshes {
        Push
        Get "transform" property of this mesh
        Multiply "transform" onto stack
        Draw this mesh
        Pop
        }