Render problems

I have created a class and rendering it directly in the class. But I can’t see the block being rendered.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import *



class dirt:
    
    def __init__(self, position):
        
        ModelPath="dirt_block.egg"
        
        self.model = loader.loadModel(ModelPath)
        self.model.setScale(1.0)
        self.model.setPos(position)
        self.model.reparentTo(render)



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

        sprite = dirt((0, 0, 0))
       


app = MyApp()
app.run()

Is there any problem in this code?

You just need move the camera back.

1 Like

Noting that, in the current state of the code, the default camera-controller is active.

Thus the camera can be moved using the mouse–but setting the position of the camera via code may not work.

In order to be able to set the camera’s position via code, call “disableMouse” on your ShowBase object (perhaps in the “__init__” function of your “MyApp” class). Like so:

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.disableMouse()

        sprite = dirt((0, 0, 0))