.obj model completely black when auto shadow set on

Screenshot_20230416_195902


Description

I have loaded an .obj model exported from Tinkercad but when I turn on auto shadowing the object is completely black. The rest of the scene is rendered as usual and the .obj model even casts shadows on its surroundings. When auto shadowing is turned off, the model keeps its material colors and seems to be partially translucent to point light; however, all the colors are entirely flat so it looks more as a silhouette rather than a 3d object.

The very same model is rendered correctly in g3dviewer, but blender fails to load it whatsoever. There is no error message anyways.

Steps to Reproduce

#!/usr/bin/python3

-- coding: utf-8 --

from direct.showbase.ShowBase import ShowBase
#import direct.directbase.DirectStart
#from panda3d.core import Material
from panda3d.core import *
from direct.filter.CommonFilters import CommonFilters

class MyApp(ShowBase):

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

    # Load the environment model.
    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)
    
    #muj model
    self.skorapka = self.loader.load_model("Biplane.egg")
    #self.skorapka.reparentTo(render)
    
    
    self.myMaterial = Material()
    self.myMaterial.setShininess(5.0) #Make this material shiny
    self.myMaterial.setAmbient((0, 0, 1, 1)) #Make this material blue

    #myNode = loader.loadModel("panda") #Load the model to apply the material to
    #myNode.setMaterial(self.myMaterial) #Apply the material to this nodePath
    
    
    #muj model
    self.skorapka2 = self.loader.load_model("models/tinker.obj")
    #self.skorapka2.setDepthOffset(1)
    #self.skorapka2.setShaderAuto()
    #self.skorapka2.setMaterial(self.myMaterial) #Apply the material to this nodePath
    #self.skorapka2.setColor(1, 0, 1, 1)
    #self.skorapka2.setTwoSided(True)
    self.skorapka2.reparentTo(render)
    
    # Find all materials
    self.mats = self.skorapka2.findAllMaterials()
    print(self.mats)
    
    
    # Create Ambient Light
    self.ambientLight = AmbientLight('ambientLight')
    self.ambientLight.setColor((0.5, 0.5, 0.5, 1))
    self.ambientLightNP = render.attachNewNode(self.ambientLight)
    self.render.setLight(self.ambientLightNP)
    
    #svetlo
    self.plight = PointLight('plight')
    self.plight.setColor((1, 1, 1, 1))
    self.plight.attenuation = (1, 0, 0)
    self.plight.setShadowCaster(True, 512, 512)
    self.plnp = render.attachNewNode(self.plight)
    self.plnp.setPos(0, 0, 22.5)
    self.render.setLight(self.plnp)
    #render.setLight(self.plnp)
    
    # Use a 512x512 resolution shadow map
    #self.plight.setShadowCaster(True)
    # Enable the shader generator for the receiving nodes
    #self.render.setShaderAuto()
    
    
    # Directional light 02
    self.directionalLight = DirectionalLight('directionalLight')
    self.directionalLight.setColor((1, 1, 1, 1))
    self.directionalLightNP = render.attachNewNode(self.directionalLight)
    # This light is facing forwards, away from the camera.
    self.directionalLightNP.setHpr(0, -10, 0)
    #render.setLight(self.directionalLightNP)
    
    self.filters = CommonFilters(base.win, base.cam)
    self.filters.setCartoonInk(separation=1, color=(0, 0, 0, 1))
    
    #self.render.ls()

app = MyApp()
app.run()

Environment

  • Operating system: debian 10
  • System architecture: ?
  • Panda3D version: 1.10.9
  • Installation method: (eg. pip, wheel, SDK, built from source) pip in venv
  • Python version (if using Python): 3.7
  • Compiler (if using C++):

The problem may be that in this model, either the normals of the polygons for lighting are set incorrectly, or they are completely absent.

Welcome to the community!

It’s hard to say what’s wrong without more information. Can you share the model?