Panda 1.7.0 Manual "Dynamic Cube Maps" crashes pyt

Panda3D-1.7.0 and python 2.6.6 on fully patched XP SP2 32 bit
The code below, based on the example on the Manual page “Dynamic Cube Maps” crashes Python. It used to work with Panda3D-1.5.4.
The line
buffer = base.win.makeCubeMap(‘env’, 64, rig)
causes the crash.
Brian

from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import NodePath

class MyApp(ShowBase):
def init(self):
ShowBase.init(self)
scene = self.loader.loadModel(“models/environment”)
scene.reparentTo(render)
scene.setZ(-2)
teapot = loader.loadModel("./models/teapot.egg")
teapot.reparentTo(render)
rig = NodePath(‘rig’)
buffer = base.win.makeCubeMap(‘env’, 64, rig)
rig.reparentTo(teapot)
teapot.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldCubeMap)
teapot.setTexture(buffer.getTexture())
zoom = teapot.posInterval(5, VBase3(20, 0, 0), startPos=VBase3(-20, 0, 0))
zoom.loop()
app = MyApp()
app.run()

Sounds like a bug in the GraphicsWindow class.

Try the snapshot build. Someone may have fixed it.

If not, then check the bug tracker and someone will fix it in the next release.

I’ve tried snapshot
Panda3D-2010.11.09-22.exe
But there were no samples and my previously working Panda3D programs caused python crashes.
I’ve logged Bug 671900.
Brian

The command window after the crash contains:
:display(error): Window wouldn’t open; abandoning window.
d
:display:wgldisplay(error): Could not share texture contexts between wglGraphicsStateGuardians.
Brian

I recently upgraded my Panda setup on XP to Panda3D-1.7.2 which includes Python 2.6.5 but the ‘Teapot on TV’ sample still Crashes Python.
Below is the error dump file if anyone’s into those things…
Brian

<?xml version="1.0" encoding="UTF-16"?>

What happens if you edit your Config.prc file and add the lines:

prefer-parasite-buffer 1
force-parasite-buffer 1

Also, have you tried it with the buildbot release, instead of the 1.7.2 release?

David

Many thanks.
Adding
prefer-parasite-buffer 1
force-parasite-buffer 1
to my Config.prc fixed both Teapot on TV and the reflection logic in my own game world.
What does it do and why isn’t it in the default config?
Brian

It enables a different way to generate offscreen buffers that is more likely to work when you have a buggy graphics driver. So there might be an incompatibility with your graphics driver.

It would also be interesting to be to know whether this is solved in the buildbot release, because we have made some changes since 1.7.2 to the way offscreen buffers are opened, and perhaps the new way will work better with your particular graphics driver.

David

Maybe you can help with anther reflections problem?
The simple app below is based on the code in the manual and works fine for the teapot model, but when I use a cube, cylinder or sphere exported from Blender using Chicken, the reflection looks too big and as if the rig cameras are pointing the wrong way; is it something to do with normals in the model?
Brian

from math import pi, sin, cos
import sys
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.interval.IntervalGlobal import Sequence
from pandac.PandaModules import *
import direct.directbase.DirectStart
class MyApp(ShowBase):
def init(self):
ShowBase.init(self)
self.environ = self.loader.loadModel(“models/environment”)
self.environ.reparentTo(self.render)
self.environ.setScale(0.25, 0.25, 0.25)
self.environ.setPos(-8, 42, 0)
self.taskMgr.add(self.spinCameraTask, “SpinCameraTask”)
self.accept(“escape”, sys.exit) #Esc to exit
#reflector = loader.loadModel(’./models/cylinder.egg’) ;reflector.setScale(.5,.5,.5)
reflector = loader.loadModel(’./models/teapot.egg’) #works well
#reflector = loader.loadModel(’./models/sphere1.egg’);reflector.setScale(.2,.2,.2)
reflector.reparentTo(render)
rig = NodePath(‘rig’)
buffer = base.win.makeCubeMap(‘env’, 64, rig)
lens = rig.find(’**/+Camera’).node().getLens()
lens.setNearFar(1, 100)
rig.reparentTo(reflector)
reflector.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldCubeMap)
reflector.setTexture(buffer.getTexture())
zoom = reflector.posInterval(5, VBase3(20, 0, 0), startPos=VBase3(-20, 0, 5)) #Z=0 for teapot, 5 for sphere
zoom.loop()
# Define a procedure to pan the camera.
def spinCameraTask(self, task):
angleDegrees = task.time * 6.0
angleRadians = angleDegrees * (pi / 180.0)
self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
self.camera.setHpr(angleDegrees, 0, 0)
return Task.cont
app = MyApp()
app.run()

I don’t know; I don’t have Blender, and I don’t have the models you refer to. There could certainly be a problem with the normals, though. Do the models look sensible when you view them in pview with the “l” option to enable lighting? That’s an easy way to check the normals.

Also, you might try reflector.flattenLight(), to apply the scale you specify onto the vertices.

David

Oh, and for the record, you shouldn’t both inherit from ShowBase and also import DirectStart. Use only one or the other.

David

Thanks for those:

  1. I took out import direct.directbase.DirectStart
  2. All the models look fine in pview l light
  3. Tried adding
    reflector.flattenLight()
    after
    reflector.setTexture(buffer.getTexture())
    it didn’t seem to make any difference.
    What determines how big the rendered camera rig images are on the reflector mesh?
    Could I use
    reflector.setTexScale(TextureStage, uScale, vScale)
    to make the image smaller? But then, why do I not need to with teapot??
    Brian

A reflection map is different from a regular texture map. It doesn’t really make sense to scale the texture with setTexScale(). The UV’s are computed based on the surface normals and the vertices, to reflect exactly what the reflection map contains, so that if you have a broad, flat surface, it should show exactly the contents of the reflection map itself. A spherical surface would correspondingly make the reflection appear smaller.

I don’t know what you mean when you say the reflection “looks too big”. Can you paste one of your models somewhere where I can try it too?

David

I don’t think it’s my models as I’ve noticed reflections in the flat base of the teapot also look wrong; I added an actor to my code with:

an_actor=loader.loadModel(’./models/Elise.egg’) an_actor.reparentTo(render);an_actor.setScale(.5,.5,.5);an_actor.setY(an_actor.getY()+4)

then tipped the teapot with

reflector.setHpr(0,90,0)

so the teapot’s flat base faces the actor and the reflection doesn’t look right.
I could upload a screen shot from my test game showing the effect more clearly if I could work out how to upload images to the forum!
Brian

Well, you might have to upload a picture to show me what you mean. You can’t upload to this forum, but you can use any of a number of free image hosting sites.

David

I’ve now added a link to the screen-shot on the web.
Brian

Here’s the screen-shot:
picasaweb.google.com/brian.horton111/Panda
Brian

Oh, I think this is the way it’s supposed to look. Remember, a cube map is not the same thing as a physically-correct reflection; instead, it’s the extrapolation of the view from a single point, spread across the entire surface of the object. Thus, the reflection is only technically correct at exactly one point, which is the eyepoint of your cubemap camera. Everywhere else it isn’t correct.

It’s generally close enough you wouldn’t notice, though, unless you scale the object up really big and put something smaller right up against it, like you’re doing here. :wink:

For a mirrored reflection, like the surface of a water, there are other approaches. Try searching the forums.

David

OK, I’ll see how others have tackled it.
As an alternative, I tried rendering a movie of sea onto a card (using the Panda sneeze sample) but the movie renders in 4 quarters as if it’s offset by half the card size in each dimension; I tried using offsets like:
card.setTexOffset(TextureStage.getDefault(), 1000, 1)
but it didn’t seem to make any visible difference; any thoughts?
Brian

Probably you want to change the texture scale instead of the texture offset. Or you can choose the UV’s properly when you create the card in the first place–generally, you want your UV’s to range from 0 to 1 to map the texture.

If you have a video texture that’s not a power of 2, there will be black space around the video–you can avoid this by putting “textures-power-2 none” in your Config.prc file, or you can use card.setTexScale(ts, tex.getTexScale()) to scale the UV’s so that the black space is not on the card.

David