The model turns to black in Panda3d. I set the light and use Simplepbr

My classmate created the model and I am a noob in blender.
(I have struggled with this problem for a period time, :sob:)
about the model:
material properties:
- Surface principled BSDF ;
- Base Color RGB ;
- Emission Black ;
Export:
gltf 2.0 embedded;
I select the “Selected Objects” and “Custom Properties”
I can see the model clearly in win10’s 3D software.
about the code:

from math import pi, sin, cos
from direct.showbase import DirectObject
from pandac.PandaModules import *
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
import simplepbr
import gltf

class MyApp(ShowBase):
    def __init__(self):
        # ShowBase.__init__(self)
        super().__init__()
        simplepbr.init()
        # Load the environment model.
        self.render.set_shader_auto()#!

        self.scene = self.loader.loadModel("models/environment")
        # Reparent the model to render.
        self.scene.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.scene.setScale(0.25, 0.25, 0.25)
        self.scene.setPos(-8, 42, 0)
        #loaing the chair into panda3d
        chair = loader.loadModel("c4.gltf")
        chair.reparentTo(render)
        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
        #light_test
        # Create Ambient Light
        ambientLight = AmbientLight('ambientLight')
        ambientLight.setColor((0.1, 0.1, 0.1, 1))
        ambientLightNP = render.attachNewNode(ambientLight)
        render.setLight(ambientLightNP)

        # Directional light 01
        directionalLight = DirectionalLight('directionalLight')
        directionalLight.setColor((0.8, 0.2, 0.2, 1))
        directionalLightNP = render.attachNewNode(directionalLight)
        # This light is facing backwards, towards the camera.
        directionalLightNP.setHpr(180, -20, 0)
        render.setLight(directionalLightNP)

        # Directional light 02
        directionalLight = DirectionalLight('directionalLight')
        directionalLight.setColor((0.2, 0.2, 0.8, 1))
        directionalLightNP = render.attachNewNode(directionalLight)
        # This light is facing forwards, away from the camera.
        directionalLightNP.setHpr(0, -20, 0)
        render.setLight(directionalLightNP)
        # Give chair some light
        ambient = AmbientLight('ambient')
        ambient.setColor((0.5, 1, 0.5, 1))
        ambientNP = chair.attachNewNode(ambient)
        
    # Define a procedure to move the camera.
    def spinCameraTask(self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        self.camera.setPos(20 * sin(angleRadians), -20 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)
        return Task.cont

![x|690x258](upload://sAEQdr2yvk13QXBLV1n0dfWNIWl.jpeg) 
app = MyApp()
app.run()
        

Thank you so much !
:smiley: :smiley: :smiley:

Hi,

I got your codes work.

First of all, you need to put a line to your codes, so that the loader could handle the gltf correctly:

gltf.patch_loader(self.loader)

Secondly, you have to disable the self.render.set_shader_auto(). This is the default Panda3D shader, and it may override the simplepbr.

Finally, I highly recommend you to only use ambient light to test your model. After confirming the model works, you could try other light settings.

This is the full codes, you just need to replace my model to your chair, since I do not have your model. Please be noticed that I am not able to get the panda’s models/environment work compatibly with the simplepbr at this moment, so I modified it on Blender 2.8 and re-exported to a gltf file. In this example, I only use embeded gltf without any other settings. The full package was attached too.

from math import pi, sin, cos
from panda3d.core import *
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
import simplepbr
import gltf

class MyApp(ShowBase):
    def __init__(self):
        # ShowBase.__init__(self)
        super().__init__()
        simplepbr.init()
        gltf.patch_loader(self.loader)
        # Load the environment model.
        # self.render.set_shader_auto()#!

        self.scene = self.loader.loadModel("environment.gltf")
        # Reparent the model to render.
        self.scene.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.scene.setScale(0.25, 0.25, 0.25)
        self.scene.setPos(-8, 42, 0)
        #loaing the chair into panda3d
        chair = loader.loadModel("archery-target.gltf")
        chair.reparentTo(render)
        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
        #light_test
        # Create Ambient Light
        ambientLight = AmbientLight('ambientLight')
        ambientLight.setColor((0.3, 0.3, 0.3, 1))
        ambientLightNP = render.attachNewNode(ambientLight)
        render.setLight(ambientLightNP)

    # Define a procedure to move the camera.
    def spinCameraTask(self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        self.camera.setPos(20 * sin(angleRadians), -20 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)
        return Task.cont

app = MyApp()
app.run()

This is the screenshot:

This is the full package:
miting.zip (2.6 MB)

If you need any helps, please let me know.

1 Like

Thank uuuuuuuuuuuuuuu soooo much!!!
IT WORKS!!!
My chair can also be loaded corretly!
Thanks a ton!
( •̀ ω •́ )