To help myself learn Panda, I’m adapting a random dungeon generator, creating the geometry and applying the materials and textures at runtime. I have it working nicely, up until the point where I try to apply separate textures to different areas of the dungeon.
In the attached images, you can see how the model looks without multiple textures and what happens when I apply more than one texture. When I add multiple textures, I lose all normal mapping, texture scaling, and lighting effects. My frame rate also drops significantly.
Some code snippets:
if usecolor:
ts = TextureStage("tex")
myDungeon.setTexScale(ts, 3, 3, 1)
ts = TextureStage("bump")
myDungeon.setTexScale(ts, 3, 3, 1)
myMaterial = Material()
myMaterial.setShininess(10.0) #Make this material shiny
myDungeon.setMaterial(myMaterial)
else:
tex = loader.loadTexture("models/dungeon/white_tile.jpg")
myDungeon.setTexture(tex)
myDungeon.setTexScale(TextureStage.getDefault(), 3, 3, 1)
tex = loader.loadTexture("models/dungeon/tile_bump2.jpg")
ts = TextureStage("bump")
ts.setMode(TextureStage.MNormal)
myDungeon.setTexScale(ts, 3, 3, 1)
myDungeon.setTexture(ts, tex)
myMaterial = Material()
myMaterial.setShininess(10.0) #Make this material shiny
myDungeon.setMaterial(myMaterial)
def colorNode(self):
for index in range(self.geomnode.getNumGeoms()):
if self.usecolor:
color = self.color_lookup[index]
name = self.colornames
tex = loader.loadTexture("models/dungeon/%s_tile.jpg" %(name))
else:
tex = loader.loadTexture("models/dungeon/white_tile.jpg")
texAttrib = TextureAttrib.make()
ts_tex = TextureStage("tex")
ts_tex.setMode(TextureStage.MDecal)
texAttrib = texAttrib.addOnStage(ts_tex, tex)
bump = loader.loadTexture("models/dungeon/tile_bump2.jpg")
ts_bump = TextureStage("bump")
ts_bump.setMode(TextureStage.MNormal)
texAttrib = texAttrib.addOnStage(ts_bump, bump)
newRenderState = self.geomnode.getGeomState(index).addAttrib(texAttrib)
self.geomnode.setGeomState(index, newRenderState)
self.geomnode.unify(self.geomnode.getNumGeoms(),1)
I’m evidently doing something wrong, in the texAttrib portion of the process. The trouble I’m having is that multiple textures need to be set on the geomNode level, but then I have to set materials and texture scaling on the nodePath level. Somewhere in the jump between these, I assume, I’m missing something. It’s a puzzle.
Can anyone offer any assistance with this?
I also have a question about octree implementation for the same project, but… one question at a time.