Pre-made Bam Files and Texture Projection[SOLVED]

I’ve gotten in the habit of pre-packing models with multiple textures into bam files so that I don’t have to load the model and apply all of its textures in the actual game code. When I later try to project a texture onto a model I’ve done this with, all of the textures get replaced.

I’m assuming this is because the bam file doesn’t preserve the different texture stages, at least not in a way I would expect.

Here’s a simple of my bam writing process. I make a small application that handles this process, separate from the game.

myModel = loader.loadModel("MyModel")

myTex1 = loader.loadTexture("MyTexture1")
myTex2 = loader.loadTexture("MyTexture2")

modTS = TextureStage("ModTS")
modTS.setMode(TextureStage.MModulate)

glossTS = TextureStage("GlossTS")
glossTS.setMode(TextureStage.MGloss)

myModel.setTexture(modTS, myTex1)
myModel.setTexture(glossTS, myTex2)

myModel.writeBamFile("MyModel.bam")

Is there anyway to make this process, or a process like it, preserve the texture stages so that I can project a texture onto this model later on, or do I just need to put the texturing code into the game for the specific models I want to project on?

The problem is that the TextureStage pointers get written to the bam file, then when you load the bam file again, it creates new TextureStage objects (which are no longer the same TextureStage objects you wrote out originally).

One easy thing you can do is simply use model.findTextureStage() after you have loaded the model, to find all of the new TextureStage pointers it created, and use those going forward, instead of the pointers you had originally.

But sometimes you really do want to keep the same TextureStage pointers (for instance, maybe you need multiple models to share the same pointers, or maybe there’s some other reason you want the loaded bam file to use the same TextureStage pointers you had around before). There’s a solution for this too: the TextureStagePool. To use it, you need to first set its mode to either MName or MUnique, with TextureStagePool.setMode(mode). Then when you create your TextureStages, and before you use them, use:

ts = TextureStagePool.getStage(ts)

to feed your new TextureStage to the TextureStagePool.

Now when you load a bam file, it will also feed the TextureStages it reads through the TextureStagePool, which will return the same pointers you got from the getStage() call, above. This will ensure that your TextureStage objects are shared across different models.

David

That’s good and useful information, but it turns out the problem was just a silly oversight on my part. I just hade to change the wrap modes and texture mode of the texture I was applying. Naturally it will look like a new texture is replacing an old one if you have it set to modulate instead of decal.