Light does not render on script

by czr   Last Updated August 13, 2019 19:15 PM

I am trying to develop a script that will render a lot of views from objects and output bounding boxes coordinates for those objects. I am a complete beginner in Blender and 3D in general, until now I came up with the following script:

import bpy
import sys
import os
import math
from mathutils import Vector
import mathutils

def get_center(o):
    local_bbox_center = 0.125 * sum((Vector(b) for b in o.bound_box), Vector())
    global_bbox_center = o.matrix_world @ local_bbox_center

    return global_bbox_center

def clear():
    # Select objects by type
    for o in bpy.context.scene.objects:
    # Call the operator

def update_camera(camera, focus_point=mathutils.Vector((0.0, 0.0, 0.0)), distance=10.0):
    Focus the camera to a focus point and place the camera at a specific distance from that
    focus point. The camera stays in a direct line with the focus point.

    :param camera: the camera object
    :type camera: bpy.types.object
    :param focus_point: the point to focus on (default=``mathutils.Vector((0.0, 0.0, 0.0))``)
    :type focus_point: mathutils.Vector
    :param distance: the distance to keep to the focus point (default=``10.0``)
    :type distance: float
    looking_direction = camera.location - focus_point
    rot_quat = looking_direction.to_track_quat('Z', 'Y')

    camera.rotation_euler = rot_quat.to_euler()
    camera.location = camera.location + rot_quat @ mathutils.Vector((0.0, 0.0, distance))


scene = bpy.context.scene

#load and position mesh
filepath = '/path/to/file.STL'
obj = bpy.context.object
bpy.context.scene.cursor.location = get_center(obj)
#bpy.context.scene.tool_settings.transform_pivot_point= 'CURSOR'
obj.rotation_euler = (math.pi/2, 0, 0)

# Create and position lamp
lamp_data ="Lamp", type='POINT') = 100
lamp_object ="Lamp", object_data=lamp_data) = lamp_object
lamp_object.location = (0, 0, 30)

cam ="Camera")
cam_ob ="Camera", cam) = cam_ob

cam_ob.location=(70, 0, 0)
update_camera(cam_ob, Vector((0, 0, 0)))

scene.render.resolution_x = 800
scene.render.resolution_y = 600
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.image_settings.file_format='JPEG'['Scene'].render.filepath = '/path/to/image.jpg'

It loads the mesh, positions it on the center and places a light source above the object. The problem is that the light is not showing up on the rendered output, it is too dark, changing energy parameter on the lamp_data makes no difference. What might be wrong?

Related Questions

Updated April 03, 2015 21:23 PM

Updated April 22, 2015 21:06 PM

Updated May 04, 2015 00:06 AM

Updated June 16, 2016 08:06 AM

Updated July 05, 2016 08:06 AM