When I use an .egg file without the material (rook.egg) and set the material in the code then the color flickers when I rotate the view (hold middle mouse and drag). The .egg file that has the material set in the .egg file (rook_white.egg) there is no flickering when I rotate the camera by dragging middle mouse button. Any ideas on why? I’m trying to avoid explicitly defining the material in the .egg model file.
In both cases the material gets set but I guess whatever is in the .egg file trumpts that. Anyway any thoughts on the cause of the flickering?
from direct.showbase.ShowBase import ShowBase
from panda3d.core import AmbientLight, DirectionalLight, LightAttrib
from panda3d.core import Vec4
from panda3d.core import Vec3
from panda3d.core import ShadeModelAttrib
from panda3d.core import Material
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
#listModels = ["bishop_white.egg", "king_white.egg", "queen_white.egg", "knight_white.egg", "pawn_white.egg", "rook.egg", "rook_white.egg"]
listModels = ["rook.egg", "rook_white.egg"]
offsetX = -15.0
matRed = Material()
matRed.setDiffuse((1.0, 0.0, 0.0, 1.0))
for modname in listModels:
self.loadPiece(modname, Vec3(offsetX, 0, 0), matRed)
offsetX = offsetX + 20.0
# Directional light 01
self.directionalLight = DirectionalLight('directionalLight')
self.directionalLight.setColor(Vec4(1, 1, 1, 1))
self.directionalLightNP = render.attachNewNode(self.directionalLight)
# This light is facing backwards, towards the camera.
self.directionalLightNP.setHpr(180, -20, 0)
render.setLight(self.directionalLightNP)
self.cam.setPos(0, -200, 0)
self.cam.lookAt(0.0, 20.0, 0.0)
def loadPiece(self, modelname, position, mat):
print 'load', modelname
self.modelpiece = loader.loadModel(modelname)
self.modelpiece.setMaterial(mat)
self.modelpiece.reparentTo(render)
self.modelpiece.setScale(1.0)
self.modelpiece.setPos(position)
app = MyApp()
app.run()
Both .egg files are attached. You should be able run by doing…
ppython cviewer.py
in the CLI
rook_white.egg (1.05 MB)rook.egg (1.01 MB)