0
$\begingroup$

I am having trouble rendering camera motion and lighting. In the example below, my scene contains a sphere and a plate, and some light. But while rendering, the light does not seem to lit the plate. And I can't seem to move the Euler angles of the camera. I must be doing something wrong there, but I can't see what. I'd appreciate your help. I am using Blender 2.79.

import bpy,math
scene = bpy.context.scene
# A sphere
bpy.ops.mesh.primitive_uv_sphere_add(location = (2,-100,2),size=20.5)  
bpy.ops.object.shade_smooth()  
ball = bpy.context.object
mat1 = bpy.data.materials.new("mat_ball")
mat1.diffuse_color = (1,0,0)
ball.data.materials.append(mat1)

# A plate
bpy.ops.mesh.primitive_cube_add(location = (0, 0, 100))
bpy.ops.transform.resize(value=(200, 20, 100))
cube = bpy.context.object
mat2 = bpy.data.materials.new("mat_plate")
mat2.diffuse_color = (0,1,0)
cube.data.materials.append(mat2)

# if I remove this, I do not even see the ball in the rendering
scene.render.resolution_x = 1200
scene.render.resolution_y = 800

# camera
cam1 = bpy.data.cameras.new("Camera 1")
cam1.clip_end = 10000
cam_obj1 = bpy.data.objects.new("Camera 1", cam1)
cam_obj1.location = (0.0, -500.0, 2.0)
cam_obj1.rotation_euler = (math.radians(90),math.radians(0),0.0)
scene.objects.link(cam_obj1)
# If I add this, the default camera is used for rendering, why?
#bpy.data.scenes['Scene'].camera = cam1_obj1

# light
light_data = bpy.data.lamps.new(name="mylight-data",type='SUN')
light_object=bpy.data.objects.new(name="mylight",
       object_data=light_data)
light_object.location = (0, -500, 500)
scene.objects.link(light_object)

angle=90

scene.frame_start = 0
scene.frame_end = 10

bpy.context.scene.camera = bpy.data.objects['Camera 1']
for frame in range(0,10):
    bpy.context.scene.frame_set(frame)
    #cam_obj1.location.z+=1
    # IF I ONLY CHANGE THE EULER ANGLES, 
    # THE CAMERA DOES NOT SEEM TO MOVE BETWEEN THE FRAMES
    cam_obj1.rotation_euler =               
             (math.radians(angle),math.radians(angle),0.0)
    angle-=2

    for ob in scene.objects:
      ob.keyframe_insert(data_path="location", index=-1)

bpy.ops.screen.frame_jump(end=False)
$\endgroup$
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.