I want to use the default camera, so I detach it first
for l in render.findAllMatches(’**/+LightNode’).asList():
remove spot light ?
for l in render.findAllMatches(’**/+LightLensNode’).asList():
restore the camera
If I repeatedly reload the scene and cleanup using the above code, for several times, the screen slowing down very much.
What is missing from the above code ?
Secondly, if I have made a light to cast on something, I want to remove the light completely, what should I write ?
alight = AmbientLight(‘alight’)
alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
alnp = render.attachNewNode(alight)
#clean up code correct?
# delete alight explicitly, or not required ?
alight = None
First, setLightOff() is not the same thing as clearLight(). setLightOff() adds an attribute that specifically disables use of a particular light; if you call it repeatedly on a node, you will be adding many attributes to that node. You should use clearLight() instead, which removes the attribute.
But you don’t need to do all that work in your first code sample at all. If you are removing the entire scene graph, just remove it:
Your second code sample looks fine. It is not necessary to call “del alight” before assigning alight = None. This is a common mistake made by newcomers to Python. In general, it doesn’t make sense to del a variable before you assign it to something else in Python; “del alight” does not actually delete anything other than the binding of the variable “alight”.
The light is not removed until you call clearLight() and also remove the light node itself. It doesn’t matter which order you do this in.
If you simply remove the light node and don’t call clearLight(), the light attribute remains, and so the light still affects the scene graph. If you create a bunch of lights and never call clearLight(), they will accumulate, and all of them will be illuminating the scene together.
If you simply call clearLight() and don’t remove the light node, the light node itself remains in the scene graph, even though it’s no longer illuminating anything. If you create a bunch of lights and never remove them, they will accumulate and you’ll have a bunch of useless nodes in your scene graph.