I’ve changed my old quadrics decimation library to make it run in real-time.
Previous quadrics were intended to work with big meshes ( that is over 5000 faces, meshes with such number of faces slows pv3d down very much, and they can’t be used on the web ) and task of decimating such mesh involved converting to my mesh format ( instead of papervision’s TriangleMesh ), decimating and then converting back to TriangleMesh. This type of workflow excluded the possibility of real-time LOD ( for games for example ) because to make LOD work in real time in papervision, we must extend TriangleMesh class and refine geometry that is currently displayed on screen.
New library, “qemlive” depends on HEMesh ( the name comes from Half-Edge mesh because it uses half-edges for adjacency lookup ) class that extends Papervision’s TriangleMesh class and during decimation, HEMesh refines TriangleMesh’es GeometryObject3D. It also remembers everything that was changed during decimation, to effectively revert decimation and come back to the original form of a mesh. To speed-up the decimation process, edge collapses don’t compute new vertex positions, best vertex is chosen among face’s vertices.
Now, the examples ( notice the speed-up in fps )
CYLINDER
CUBE
SPHERE
Here, uv coords and normal’s prevervation ( described further ) was used to preserve spherical shape of the sphere
X-WING
For an x-wing, click HERE
When decimating xwing, uv and normal preservation was used, to preserve two “antennas” in the front of the xwing. The texture mapping breaks down a bit while decimating, this is because there are many discontinuities in xwing’s texture.
All models use almost the same decimation settings, only interpolation method was changed. There are many other settings that changes algorithm’s behaviour? but yah, too lazy to document it. Nobody likes to make a documentation I suppose ; )
The library isn’t public-ready because the code is without documentation and with some debug variables ( as always :p ) but I’ve decided to show the source code, it’s available on googlecode:
http://code.google.com/p/bartekz/source/browse
Zipped qemlive:
http://code.google.com/p/bartekz/downloads/list
Demo source ( not too clean, but the hell ? )
http://dl.dropbox.com/u/1268089/QEMLive.as
To instantiate HEMesh, just do this:
var model:HEMesh = new HEMesh( null , null, null , TeleQEM.INTERPOLATE_UV_AND_NORMALS );
model.init( new Sphere( new WireframeMaterial(), 100 , 20 , 20 ) );
See the null’s at the beginning of the constructor? This is one of the reason’s that this library isn’t “public-ready” :p
The fourth parameter controls the way the mesh is decimated ( there are million of other parameters that you can figure out yourself in TeleQEM class ). The possible values are:
TeleQEM.INTERPOLATE_NOTHING
– look only at geometry when decimating
TeleQEM.INTERPOLATE_UV
– look at uv coordinates during decimation – algorithm tries to preserve correct uv mapping
TeleQEM.INTERPOLATE_UV_AND_NORMAL
S – look at face normals during decimation as well as uv coordinates – algorithm tries to preserve correct shape of a geometry
We can listen for mesh creation completion:
model.addEventListener( Event.COMPLETE , initComplete );
private function initComplete( e:Event ):void{
do some stuff?
}
To decimate triangles:
model.newqem( model.numFaces*PERCENT_OF_FACES_WE_WANT_TO_LEAVE );
We can set up a listener to listen for decimation completion:
model.addEventListener( TeleQEM.COMPLETE_DECIMATION , decimationCompleted );
private function decimationCompleted( e:Event ):void{
do some stuff?
}
ps. This LOD can be optimized by changing as3’s arrays into vectors. My old decimation algorithm has been made for flash player 9, but the science moves forward … ;) So maybe this will be fixed in the future.
ps2. During “undecimation”, geometry is “forgotten” to free up some memory. If it weren’t, the second decimation could use this fogotten information to decimate the model faster. I think I will make this as an option in HEMesh class in the next update of qemlive – to reuse the decimaton info.