Blender 2.5 Python Camera Driver?

Hi All,

I am trying to create a python solution for my asteroid LOD probelm.

I want to make a python driver for the camera, have the python code review all asteroids in the scene and then sort them into 3 or 4 lists based upon distance from camera. Each asteroid in the list will have it’s subsurf render detail value set higher or lower based upon the proximity to the camera. So all asteroids in list #1 get their render detail value set to 1 and so on. This needs to be evaluated every frame, because the camera is moving through the asteroid field.

I am not new to python or Blender, but I’m not sure how to really do this in 2.5?

Is this a good approach to solving this problem?
Is there another way to achieve my goal?

Ok, I have inserted a keyframe on the camera.
I have added a modifier with a type of Python to the Camera X Location channel.
My first goal is to try and implement a simple print out of all objects in the scene.


obs = bpy.data.objects
for o in obs:
    print(o)

But where do I put my code? The modifier panel has no box for pasting code? I have tried pasting the code into a text document and hoping it would show up as a pickable item in the modifier, but that does not work either.

not quite shure if this helps, because
i would put such a script into the scripting-section
and enable it for every frame-change.


#for blender-2.5-alpha
import bpy
camera = bpy.context.scene.objects["Camera"] #thats the camera?
for i in bpy.context.scene.objects:
    if i.type == "MESH": #only use meshes
        print (i.name, (camera.location-i.location).length) #decide for distance?
        for m in i.modifiers:
            if m.name == "Subsurf":
                print(m.name, m.render_levels)
                m.render_levels = 1 #change render_level from default 2 to 1

only question is … where is the entry for global scripting in blender-2.5-alpha,
did not find it … at once.

Wow, thanks for the code! That is very close to what I intended.

Now just to find a place to put it. I just assumed the Python modifier is the replacement for the frame change event. It obviously get’s updated every frame to relay data to the fcurve system. But maybe something else is in the works…

I think it would be useful having this for the camera, but could you not also use the z-buffer and for 4 groups, split them on the shades of greyscale?

I guess I am trying to find a way to reduce the poly count I am supplying to the renderer. As I sit here waiting for occlusion preprocessing, again, I feel this would be the best place to tackle the bottle neck because it is a single threaded process. Any z-buffer solution would happen after the render had taken place. I’m not sure how the z-buffer solution would speed up the render time?