Generic Level of Detail in Blender?

Hi,
I know that this should be in dev-forums but I’d like to try my luck here first.

The problem is that I need some generic way of handling level of detail in Blender. I don’t mean automatic poly count reducer like Decimator-modifier but ability set by hand several meshes for same object with view distance information.

I need that for exporting external real-time engine (OpenSceneGraph). Now I have to that by editing OSG-files and that is not that fun… or fast

Does any one know way to do this? Any hints are wellcome!

If this was implemented internally in Blender, I think that would also benefit echo-plugin and current game-engine.

Any thoughts?

There is a patch " LOD functionality in decimate modifier " here

Thanks, but I can not use decimator because I’ll make different version by hand. Decimators fails with architecture since they are often designed for organic models.

But thas is very interesting, maybe he could make a lod modifier also :slight_smile:

Perhaps poly reduce could do it with some clever scripting, http://wiki.blender.org/index.php/Release_Notes/Notes242/Scripts#Poly_Reduce_.28Mesh.29 . That preserves UVs at least.

Automatic poly reduce just seem to do horrible things to my buildings :slight_smile:
http://www.opendimension.org/blender_en/images/polyreduce2.jpg

In my case there are quite fine detailed buildings which you can enter and have a look. When moving away (for example do following):

  • replace windows with textured, transparent plane
  • stop rendering inner parts of the house
  • and finally, replace whole building with one mesh that is baked from high-poly model.
  • and very far use impostors

So I need a way to set those limits inside Blender so I can export them.

EDIT. So the problem is not making those LOD-meshes but MARKING them as LOD-levels.

One solution would be to bind LOD models to empties. So each empty would represent a collection of building LODs. Empty would be a parent and a container of the collection of building LOD levels. Then develop a naming scheme so that you know which LOD level is which (empty (parent): hotel, lowest LOD: hotel_0, middle LOD: hotel_1, high_LOD: hotel_2 or something like this would work).

After this you need to hack the OSG exporter (http://projects.blender.org/projects/osgexport/) to support this scheme.

That sounds good! It is the best option for now.

Anyway, that LOD-modifier would be a cool thing :wink:
I wish I had time to dive in Blender sources but currently that is not possible.

After this you need to hack the OSG exporter (http://projects.blender.org/projects/osgexport/) to support this scheme.
That’s exactly what I’m going to do :slight_smile:

BlenderPeople uses Empties with dupligroups pointing to various level-of-detail models, and a script to swap them out depending on camera distance.

Thanks for info, I’ll have a look.

There’s a ton of stuff in BP, so I’ve snipped and cleaned the relevant function for you…


import math

def setLoDforselected():
    selected=Blender.Object.GetSelected()
    if (selected is not None):
        #find if a camera object is included in the list
        camOb=None
        for object in selected:
            if (object.getType()=='Camera'):
                camOb=object
        if (camOb):
            camMat=camOb.getMatrix()
            camLoc=camMat.translationPart()
            for object in selected:
                if (object<>camOb):
                    obMat=object.getMatrix()
                    obLoc=obMat.translationPart()
                    distance=math.sqrt(((obLoc[0]-camLoc[0])**2)+((obLoc[1]-camLoc[1])**2)+((obLoc[2]-camLoc[2])**2))

                    # Your code for selecting the proper dupligroup based on distance goes here
                    # place name of new group in the variable nameofnewgroup
                    # nameofnewgroup=groupnames[index] or something like that

                    obGroup=object.DupGroup
                    newGroup=Blender.Group.Get(nameofnewgroup)
                    if (newGroup):
                        object.DupGroup=newGroup
                                    
        else:
            return "No Camera object in selection."

To use this, you select a camera object and your Empty placeholders that have a dupligroup assigned. You also need to have your other meshes each in their own group so you can re-assign your empty to point to them. If you know anything about python scripting in Blender, this code should be pretty straightforward.

If not, I unfortunately don’t have time to fix it up/make it turn-key, etc. Also, this is just a function definition, so you’d need to add some kind of call, or remove the function def portion.

jms was working on LOD. I don’t know how current this is or whether it works in the GE:

http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_LOD_en.htm

%<

Thank you! Although I don’t need camera info because I only need a solution how to export information about lod-levels and models related to them. But thanks anyway!

@Fligh: Thanks, but as I said earlier scripts are not suitable for my purposes. See my previous post.

The point of my script snippet is how you do the kind of thing you’re talking about. You create an Empty as your base object. You then create your different models of varying Level of Detail. Make each model (or collection of model and armature, etc.) into a Group. Then, you enable Dupligroups on the Empty, pointing it toward each of the different LoD Group stand-ins you created.

That’s how you do it in Blender.

You could also try re-assigning the Mesh datablock of an object to point to varying library meshes, but you lose a number of mesh effects that are held at the object level by doing that.

Empty+Dupligroups is the way to go. My script snippet was nothing more than an automatic way to manage those different groups.

Sorry, I didn’t notice that dupligroups part. Now I see what you meant. Thanks for clarification!