Posts Tagged ‘papervision’

Papervision3D real-time level of detail ( LOD )

July 24th, 2010

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 )



Here, uv coords and normal’s prevervation ( described further ) was used to preserve spherical shape of the sphere
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:

Zipped qemlive:

Demo source ( not too clean, but the hell ? )

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_NORMALS – 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.

Tags: , , , ,
Posted in flash experiments | Comments (0)

Papervision3D 3D Fonts

May 25th, 2009

I wrote today a little class which converts font outlines to TriangleMesh3D objects:

Click on the image, you will se a demo. I wasn’t tweaking my code too much, so there are several bugs in this 3D fonts class. Major bug is, that glyphs like “i” or “%” aren’t rendered properly. And it doesn’t work with all typefaces, hence this demo is based on only one typeface ( helvetica bold italic ).

And don’t exaggerate with typing your own phrases in the input textbox – I wasn’t optimizing my code, so CPU usage can be high.

Tags: , , , , ,
Posted in flash experiments | Comments (0)

Very “efficient” DAE parser in papervision 3d

January 22nd, 2009

I’m currently workin on some bigger project, and I needed to load DAE file. It’s known, that papervision3d has DAE parser – so I used it. But when I tried to load a little bigger file ( only 400KB model ), flash thrown 15 seconds timeout exception. The exception was thrown during unpack process. “Wow, flash is so slow, that it can’t unpack 400KB zip in 15 seconds? This sucks” I thought. But later I looked deeper into DAE parser’s code. DAE parser uses KMZ parser, to unpack DAE’s content ( like textures and models ), and then parses XML ( or rather KMZ unpacks and then uses DAE to read model… ). I followed the code ( just like Dexter does ), and studied KMZ parser’s code. And it appears, that KMZ’s parser code, isn’t the most efficient code I’ve ever seen.

Just look @ it:

After loading the zip file, it calls “parse” function, which calls “getColladaFromZip”. getColladaFromZip unopacks the zip file:

private function getColladaFromZip( zipFile : ZipFile ) : ByteArray  {
	for(var i:int = 0; i < zipFile.entries.length; i++) {
	    var entry:ZipEntry = zipFile.entries[i];

	    // extract the entry's data from the zip
	    var data:ByteArray = zipFile.getInput(entry);

		if(".dae") != -1) {
			return data;
	return null;

It unpacks entire file, just to get the “dae” file, and then returns. More – it extracts content ( function “getInput” ) , and then checks if unpacked content is “dae” file, despite the fact, that to check it, we don’t need to unpack anything to check it.

It gets worse later – it unpacks entire file to check how many textures we have in the zip:

private function numTexturesInZip( zipFile : ZipFile ) : uint {
	var count : uint = 0;
	for(var i:int = 0; i < zipFile.entries.length; i++) {
	    var entry:ZipEntry = zipFile.entries[i];

	    // extract the entry's data from the zip
	    var data:ByteArray = zipFile.getInput(entry);

	    if(".png") != -1 ||".jpg") != -1) {
	return count;

Ok, and at the end, in the “parse” function, every file in archive is extracted again, only for purpose of loading textures from this archive.

Reassuming, if you have 1 meg model and several 200 KB textures, KMZ parser extracts geometry 3 times – second time, to count number of textures (?!?) and third, to load textures. Every texture is extrated 3 times too – first time – to ensure that the texture isn’t a model, second – to count it, and finally third time – to load texture. I think that somebody pasted the code of loading zip file from some tutorial and repasted it 3 times :)

I would paste here my code of better KMZ parser, but it’s too integrated with my project, so you’ll have to wait ; p

And I wrote this post, to enlight you people, that when you are using pv3d’s KMZ parser to load zipped DAE, it isn’t the best parser to use.

Tags: , , , , , ,
Posted in flash experiments | Comments (9)

3D Physics papervision photo gallery

November 17th, 2008

This is the 3D photo gallery which uses WoW Engine 3D physics to simmulate movement of thumbnails. I believe I could do some precaching or modify WoW to make it a little faster. But up to now nobody complained:) Some issues with interaction and feel are to be fixed.

I’ve updated my old flash portfolio ( ) to display properly in Firefox under Mac OS

[ update: minor update to photo gallery: bigger titles, less dynamic movement of photos, blurring, and several other enhancements. I will be updating this gallery till it gains satisfying level of “usability”  ]

[ update2: blah, i forgot to give a link to the gallery :d now it’s fixed. Click on the image to see the gallery. This is my gallery with different images: ]

Tags: , , , ,
Posted in flash experiments | Comments (6)

Rotating rings with shadows and reflections and a pv3d primitive

September 10th, 2008

I have made this two simulations of rotating rings. First one, is a bit more interactive – you can change position of the camera by dragging mouse cursor. Second one is fully prebuffered, thus you can only click on stage, and watch how the rings are rotating.

Shadows and reflections were made using Andy Zupko’s classes ( ). They were also tweaked to look like projected on convex surface.

First demo is a cpu killer, despite some modifications, and prebuffered shadows ( after prebuffering, shadows are animated on the floor plane ). On 1Ghz it will probably have something around 10fps. I could lower the details, but this demo is all about details:)

Second demo is also a cpu killer, but only during the prebuffering phase. It has some details smoothed, and features two animations, chosen randomly after clicking on stage.

To make this demo, I needed genereric model of a ring with proper texture mapping – so i modified cylinder primitive from Papervision3D. To make a new Ring:

new Ring( material , radius , height, subradius , segmentsW , segmentsH , topFace , bottomFace )

material – its for example new ColorMaterial( 0 )

radius – radius of a ring, including wall thickness

subradius – thickness of ring’s wall

segmentsW – more segmentsW, your ring will look less angular

segmentsH – segments horizontally.

topFace , bottomFace – if you dont include topFace and bottomFace, your ring will look like two extruded circles.

You can download this class here to make your own rings ( of course you need Papervision3D too )

ps. I had to disable comments because spambots seems to like this post. Gosh, I hate this lamers who call themselves programmers and writes shit like this…

Tags: , , , , ,
Posted in flash experiments | Comments (5)