Syntax in python for Opacity for 3D-Models and Lighting issue

I need a semi-transparent 3D sphere around another sphere. How do I do that?
Regarding the lighting issue, look at the two images One is unlit another is lit by a point light.


What is causing the issue? How do I correct it?
Here is the code I have written for it.

from panda3d.core import loadPrcFile
loadPrcFile("config/conf.prc")

from direct.showbase.ShowBase import ShowBase
# from panda3d.core import NodePath
from panda3d.core import PointLight, AmbientLight
from math import sin, cos


class MyGame(ShowBase):
    def __init__(self):
        super().__init__()

        self.cam.setPos(0, -500, 0)
        self.setBackgroundColor(0,0,0)

        self.chara = self.loader.loadModel("planet_models/Earth")
        self.chara.setScale(0.2)
        self.chara.setPos(0, 0, -2.5)
        self.chara.reparentTo(self.render)
        self.charaNode = self.chara.node()

        self.sphere_light = self.loader.loadModel("models/misc/sphere")
        self.sphere_light.setScale(0.2)
        self.sphere_light.setColor(1, 1, 1, 1)
        self.sphere_light.setPos(0, -600, 0)
        self.sphere_light.reparentTo(self.render)

        plight = PointLight("plight")
        plight.setColor((1, 1, 1, 1))
        self.plnp = self.sphere_light.attachNewNode(plight)
        # self.plightNodePath.setPos(2, 0, 0)
        plight.setAttenuation((1, 0, 0))
        self.chara.setLight(self.plnp)

        alight = AmbientLight("alight")
        alight.setColor((0.04, 0.04, 0.04, 1))
        alnp = self.render.attachNewNode(alight)
        self.chara.setLight(alnp)

        self.taskMgr.add(self.move_light, "move-light")

    def move_light(self, task):
        ft = globalClock.getFrameTime()
        self.sphere_light.setPos(cos(ft)*400, sin(ft)*400, 0)
        return task.cont

game = MyGame()
game.run()

with the prc file being

win-size 1280 720
window-title First Trial
show-frame-rate-meter true
show-scene-graph-analyzer-meter true

It should be possible to do this like so:

  • Load the first 3D sphere as normal
  • Load the second 3D sphere
    • If it’s not already so, scale it to be bigger than the first sphere
    • If it’s not already so, make it semi-transparent
      • One way to do this is to call “setAlphaScale” on it, passing in a value between 0 and 1
    • If called for, activate transparency for it
      • For standard transparency, this can be done by calling “setTransparent(True)” on it
  • If called for, place the two spheres so that they’re in the same location

I’m not entirely sure of what the issue is, as I don’t know what you’re expecting to see.

If the issue is the rectilinear markings in the second image, then I would imagine that those are being caused by some texture or other that’s being applied to the sphere–a glow-map, perhaps, or some such thing.

If that’s not the issue, could you elaborate, please?

Yup got the issue for the lighting issue, the texture had problems, i corrected the texture and got the problem resolved. Got the transparency working, thanks!!!

1 Like