Search code examples
python-3.xpanda3d

Python Panda3D weird cube render


I am trying to render a simple red-colored cube in Panda3D, but instead of a 3D cube, I encounter a red rectangle in my window: Red Rectangle. Obviously, this might seem correct because of the way how perspective lenses work... but whenever I try to change the camera's position using self.camera.setPos() or change my cube's position using self.cube.setPos() then that rectangle doesn't change anything. And trying to rescale the cube using self.cube.setScale() then it completely disappears, even if I put self.cube.setScale(0,99999, 1, 1).

I can't seem to find anything about this issue.

Here is my code by the way:

import ctypes
from panda3d.core import SceneGraphAnalyzerMeter
from panda3d.core import loadPrcFileData
from panda3d.core import PerspectiveLens
from direct.showbase.ShowBase import ShowBase

def screen_resolution():
    u32 = ctypes.windll.user32
    screen_width = u32.GetSystemMetrics(0)
    screen_height = u32.GetSystemMetrics(1)
    string_result = str(screen_width) + " " + str(screen_height)
    return string_result


loadPrcFileData("", "load-display pandagl")
loadPrcFileData("", "window-title Wild Space Residents")
#loadPrcFileData("", "win-size " + screen_resolution() + "x24")
loadPrcFileData("", "color-bits 24")
#loadPrcFileData("", "fullscreen 1")
#loadPrcFileData("", "framebuffer-hardware 1")


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

        self.lens = PerspectiveLens()
        self.lens.setAspectRatio(1920 / 1080)
        self.lens.setFov(120)
        self.lens.setNear(1)
        self.lens.setFar(50)

        self.cam.node().setLens(self.lens)
        self.camera.setPos(10, -10, 0)

        self.cube = self.loader.loadModel("\\models\\cube\\Cube.glb")
        self.cube.reparentTo(self.render)

        self.cube.setScale(1, 1, 1)
        self.cube.setPos(0, 0, 0)
        self.cube.setHpr(0, 0, 0)
        self.cube.setColor(1, 0, 0, 1)

        # self.scene_graph()

    def scene_graph(self):
        self.setFrameRateMeter(False)
        self.messenger.toggleVerbose()
        self.render.analyze()


app = WSR()
app.run()

And my specs are:

  • CPU: AMD Ryzen 5 2600 Six-Core Processor.
  • GPU: Nvidia GTX 1660ti (6 cores).
  • RAM: 16gb.
  • 1920x1080 resolution (in case the resolution is a problem in Panda3D).

By the way:
My cube model file ("/models/cube/Cube.glb") has been exported from Blender. Maybe that has something to do with it?

I've also tried to change the render types from OpenGL in Panda3D's Config file and various other values. I've also tested this script on multiple other PCs.

My goal as for now is to have a spinning red cube.

I've tried to change the UV-mapping in Blender, then exporting and replacing the old model files multiple times.

I've tried to change self.camera.setPos(), self.camera.setH() (and other rotation commands), and the camera PerspectiveLens() field of view.

I've also tried to change the cube's color using self.cube.setColor(1, 0, 0, 1).

Switching from PyCharm to Spyder and even running the Python-file through the command-prompt.

(None of the above worked!)

I am wanting to have a 3D cube, instead of a non-configurable rectangle.


Solution

  • Solved!

    I just had to update my GPU drivers, which were apparently very outdated. Still weird that that's the reason why it didn't work..