Papervision LOD – SimpleLevelOfDetail


lodspheres2.png

There was some talk of being able to do to handle LOD (Level of Detail) in Papervision. While this is a far cry from a true LOD filter, I whipped it together hoping it might help someone out. The idea is this: YOU pass in the models you want to swap between. This allows you to control the geometry you want to keep, and more importantly, it is really easy to use. So implementing it is simple: pass an array of objects you want to use - from most complex to most simple. The SimpleLevelOfDetail object will add/remove them when it is the appropriate distance from the camera. And that is pretty much it. Specify the minDepth and maxDepth you want the swapping to occur between. Alternatively, you can specify an array of distances you want to use for selecting LoD. The index in the distance array that the objects screenZ is greater than will be the index of model that is used. All you need to do then is pass your SimpleLevelOfDetail object to your scene - and it will handle the rest!

The next step is the real LevelOfDetail object/filter. This will dynamically join faces for you - but I imagine it will have alot more problems. So, for simple LoD that you can have some good control of - check it out. It is now in the repository in GreatWhite under objects.special.SimpleLevelOfDetail.

I've whipped together a quick demo of the SLOD here. You can click and drag to rotate your view, and use the WSAD keys to move around. I've included the source below.

Here is a quick snippet showing how to use the class:

Actionscript:
  1. var objects:Array = new Array();
  2. var bMat:BitmapFileMaterial = new BitmapFileMaterial("texture.jpg");
  3. var distances:Array = null;
  4.  
  5. //UNCOMMENT TO USE A DISTANCE BASED ARRAY TO CONTROL RANGES
  6. //distances = [1000, 1500, 1600, 3000];
  7.  
  8. for(var i:Number=8;i<16;i++){
  9. objects.unshift(new Sphere(bMat, 100, i, i-1));
  10.  
  11. }
  12.  
  13. var simple:SimpleLevelOfDetail = new SimpleLevelOfDetail(objects, 100, 3000, distances);
  14.  
  15. scene.addChild(simple);

You can see we just push more and more complex spheres onto the front of the objects array - using the same material for each. Then, we create our SimpleLevelOfDetail object, passing in the objects, min, and max depths to use for selecting models. Finally we add our SimpleLevelOfDetail object to the scene - and we are done! If you choose to use the distances array, your results will be something like this:

When your model is less than 1500, it will use objects[0], if it is between 1500-1600, it will use objects[1], between 1600-3000 will use objects[2], over 3000 will use objects[3], etc. Pretty straightforward.

enjoy.

Get the source here


12 Comments, Comment or Ping

  1. Now that is a great idea. That will be perfect for a couple projects I’ve been unable to do because of the sheer amount of faces they require. Thanks!

    June 11th, 2008

  2. this sound AWESOME to my ears! :D
    this feature really ease large 3D architectures\sites\worlds development!

    thanks a lot andy :)

    June 12th, 2008

  3. very cool! thanx again andy!

    June 12th, 2008

  4. David

    Perfect.. been looking for that, and I gather i could use a particle as the last LOD detail level aswell? (really far away objects is a simle billboard in essence?) Or is that outside of this implementation?

    Will check it out anyways.

    June 12th, 2008

  5. David

    Hm, did you ponder anything related to LOD-”patience”/and “fade” between LOD-states? What I mean is in your example (and in other cases aswell, specifically when dealing with orbits), objects tend to travel in and out of lod depth several times in a small timeframe, and it would be sooo good to be able to tell a lod-state how fast it switches LOD states, in your example that value would be 0, but in some cases it would be very nice to delay that until the object has kept itself within the threshold for several milliseconds/frames? Or would that be a resource hog of epic proportions? :D .

    Anyways, if you wanna discuss it, please mail me.

    June 12th, 2008

  6. well, the next step i’m planning on taking is smoothing the geometry between stages: that is, the SLOD will have its own geometry that is interpolated between stages so things look a little more natural. I put this out now so that people would be able to have the basic LOD ability, and maybe even come up with a nice smoothing option for me :)

    June 12th, 2008

  7. David

    Then I’ll look into that once I need it in the game ;) . Consider it looked at atleast.

    June 23rd, 2008

  8. im doin my FYP on a GIS based on 3D and vector based maps.
    i found ur PAPERVISION link very healpful.Thank you very much..
    this article was the best coz i was having problems with dynamically loading objects into the view.

    hope u publish more articles on “measuring distance between objects”
    cheerssssssssss!

    July 12th, 2008

  9. cheers mate,

    I haven’t looked into the source to check but to answer MULT1 question an implementation of geom.Points would help for positioning, I am not sure if they have a z axis but the handling methods are useful.

    October 22nd, 2009

Reply to “Papervision LOD – SimpleLevelOfDetail”