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
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.)
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?
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.
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.
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.