Panda3D egg file from X format from Blender not showing

Hi,
I created a model in Blender and saved it as X file format. Then I used x2egg to convert it into an egg file. When I see the model, it is visible in pview. But it isn’t when I use this code and run.

from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.scene = self.loader.loadModel("Objects/Path_to_my_model")
        self.scene.reparentTo(self.render)
app = MyApp()
app.run()

This works when I put the ‘models/environment’(Already available Panda3D model). This means the code works, the model is visible in pview.

It probably isn’t visible from where the default camera is positioned. I believe it defaults to (0, 0, 0) and facing down the positive Y-axis. Try adding something like this:

self.camera.set_pos((0, -5, 5)) # might need to be an actual vector type
self.camera.look_at((0, 0, 0)) # again, might need to be an actual vector type

Thanks, I tried it already. But still the same thing.

Do you get any errors when you attempt to load it?

If you don’t get any errors, and you print the “tight bounds” of the model, what values do you get?

That is, what is the output of the following:

from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.scene = self.loader.loadModel("Objects/Path_to_my_model")
        self.scene.reparentTo(self.render)
        bounds = self.scene.getTightBounds()
        print (bounds)
app = MyApp()
app.run()

X models are supported without conversion, but it is worth noting that the animation was broken.

@Thaumaturge I ran that code and got this output :

Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
:display:windisplay(warning): SetForegroundWindow() failed!
(LPoint3f(-1, -0.1, -1), LPoint3f(1, 0.1, 1))

Hmm… It’s quite small on the y-axis, but I wouldn’t expect that to be a problem. I would really expect that if you were to move the camera to (0, -4, 0) you should see it.

Hum. Could you post a screenshot of what it looks like in PView, please? And when you view it successfully in PView, does it appear in view immediately, or do you have to use any of PView’s controls to bring it into view? (Like pressing “c” to centre it.)

And when you view it successfully in PView, does it appear in view immediately, or do you have to use any of PView’s controls to bring it into view? (Like pressing “c” to centre it.)

This is what happens at the beginning. When I press C, it is zoomed. To where I’d like.

Hmm. Very strange, then.

Would you be willing to share the egg file and/or blend file (or another that shows the same issue, if preferable), so that I can take a look at it more-directly?

Yes, I would have already, but it says, ‘Sorry, new users cannot send attachments.’

You can simply load it to the format .X have you tried?

from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.scene = self.loader.loadModel("Path_to_my_model.X")
        self.scene.reparentTo(self.render)
app = MyApp()
app.run()

Perhaps upload it to DropBox or similar service, then.

The starting position of the camera in PView does not seem to be (0., 0., 0.), so you can’t rely on this to give you the same view as in your own project at startup.

Just to make sure that the camera position is not the issue, try to set it through code once again, but be sure to call self.disable_mouse(), or your camera control code will have no effect.

1 Like

Uploaded it to Google [Egg File]
egg file:Link To Egg

from direct.showbase.ShowBase import ShowBase

class Test(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        sample = loader.loadModel("Board")
        sample.set_pos((0, 5, 0))
        sample.reparentTo(render)

demo = Test()
demo.run()

I was just about to post, too! Trying it out on my end, I can see the board well enough–as long as I move either it or the camera. Serega’s post above gives an example of how to make it visible; conversely, you could move the camera.

Note that if you use Moguri’s camera-placement code, above, you won’t see the board–likely because the z-position given there is too high. If you instead set the camera’s position to (0, -5, 0) you should see it.

from direct.showbase.ShowBase import ShowBase

class Test(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        sample = loader.loadModel("Board")
        sample.reparentTo(render)
        
        camera.set_pos((0, -5, 5))
        camera.look_at((0, 0, 0))
        
        self.disable_mouse()

demo = Test()
demo.run()

As for converting, you don’t need to convert it. Panda does this automatically, just load in .X format. Exceptions are only animated models, but this used to work. I hope this will be fixed.

The above can be simplified a bit in this case, to the following:

from direct.showbase.ShowBase import ShowBase

class Test(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        sample = loader.loadModel("Board")
        sample.reparentTo(render)
        
        self.cam.setY(-5)
        
        self.disable_mouse()

demo = Test()
demo.run()

(I also seemed to get away without disabling the mouse, but it’s probably safer to keep it.)