Combining models into a bam file with LOD

I have a chunked world with a variable number of static models per chunk. When I click save or compile in my world editor I want to combine all the statics of a chunk into one bam file.

The problem comes in when I try to load the combined bam file into an LODNode, at which point some of the models just disappear as if they are not even part of the bam file.

I know that I can actually create an Actor() with an LODNode, add the models to the different LOD switches and then save the Actor as a bam file. Then I load the bam file into an Actor like this:

model=Actor()
Actor.loadModel(model,"bamfile.bam")

After loading it like this I get the same result as above where some of the models in the bam file just disappear.

If I load it like this:

model=loader.loadModel("bamfile.bam")

The bam works perfect, but how can I set the LOD Ins and Outs when I load it like this? Not even sure I can set them when loading into an Actor as above.

I’m not sure what you mean when you say “some of the models just disappear”. It rather sounds like the LODNode is doing what it’s supposed to do, which is making certain nodes invisible or visible depending on the distance to the camera (and the LODNode setup).

But to answer your question, the way to set up the switch distances on the LOD is to get a handle to the LODNode itself and call addSwitch() or setSwitch() on it for each child.

David

Yes, disappear is not the right word. I meant, they are just not there or missing, as if they were never even loaded. Can’t be sure what is wrong, but I’m definitely sure its not because of a bad LOD switch that they appear to be missing. The switch I used is Out=0 In=500 for the whole combined model. Why would only one model show up?

Anyway, I’ll try getting a handle to the LODNode and test the setSwitch() function.

Ok, this is my code. Here I have my combinedModel and combinedLODModel, both have a few models reparented to them.

actor=Actor()
lodnode=LODNode("lodnode")
actor.setLODNode(lodnode)
actor.addLOD("0", inDist=250, outDist=0)
combinedModel.reparentTo(actor.getLOD("0"))
actor.addLOD("1", inDist=500, outDist=250)
combinedLODModel.reparentTo(actor.getLOD("1"))

actor.writeBamFile(filename)

Then I load the bam as follows and try to get it’s LODNode:

model=Actor()
Actor.loadModel(model,filename)
model.reparentTo(render)
modelslodnode=model.getLODNode()

I get the following error:

Traceback (most recent call last):
  File "main.py", line 33, in <module>
    modelslodnode=model.getLODNode()
  File "C:\Panda3D-1.7.1\direct\actor\Actor.py", line 624, in getLODNode
    return self.__LODNode.node()
AttributeError: 'NoneType' object has no attribute 'node'

Oh, you probably don’t want to be using Actor.setLODNode(). That’s not designed to be written to a bam file and reloaded.

Instead, just create an LODNode outside of the Actor, and parent the Actor to it. When you reload the Actor from a bam file, do it again.

David

I did not realize that an LODNode does not need an Actor(). Works now, thanks.