MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / add_sun

Function add_sun

tools/cycles_reference/render.py:281–307  ·  view source on GitHub ↗

Add a Sun light aimed along the given direction (in Bloom Y-up). In Bloom, `setDirectionalLight` direction is the vector *toward* the light source. Blender's Sun shines along the light's local -Z axis. We orient the Sun so its -Z points in the opposite of dir_bloom (i.e. the directi

(name, dir_bloom, color, strength)

Source from the content-addressed store, hash-verified

279
280
281def add_sun(name, dir_bloom, color, strength):
282 """Add a Sun light aimed along the given direction (in Bloom Y-up).
283
284 In Bloom, `setDirectionalLight` direction is the vector *toward* the
285 light source. Blender's Sun shines along the light's local -Z axis.
286 We orient the Sun so its -Z points in the opposite of dir_bloom
287 (i.e. the direction the light travels).
288 """
289 light_data = bpy.data.lights.new(name=name, type='SUN')
290 light_data.color = color
291 light_data.energy = strength
292 light_data.angle = math.radians(0.53) # ~solar disc size; soft shadow
293
294 light_obj = bpy.data.objects.new(name=name, object_data=light_data)
295 bpy.context.collection.objects.link(light_obj)
296
297 # The direction the light *travels* is -dir_bloom
298 travel_bloom = (-dir_bloom[0], -dir_bloom[1], -dir_bloom[2])
299 travel_b = Vector(bloom_to_blender(travel_bloom)).normalized()
300
301 # Orient so local -Z aligns with travel_b.
302 # Track_quat returns a rotation mapping the chosen axis onto the vector.
303 # We want -Z to look along travel_b, which is equivalent to asking the
304 # quat that maps '-Z' onto travel_b.
305 rot = travel_b.to_track_quat('-Z', 'Y')
306 light_obj.rotation_mode = 'QUATERNION'
307 light_obj.rotation_quaternion = rot
308
309
310def setup_camera():

Callers 1

mainFunction · 0.85

Calls 2

bloom_to_blenderFunction · 0.85
newMethod · 0.45

Tested by

no test coverage detected