Skip to content

Instantly share code, notes, and snippets.

@metal3d

metal3d/sun_set.py

Last active Oct 14, 2020
Embed
What would you like to do?
Align Sky textyure with the sun lamp in Blender
import bpy
import mathutils
# Author: Patrice Ferlet <metal3d@gmail.com>
# License: GPL
# Works with Blender 2.80-2.90
# To use this script:
# - paste this script in a "text editor" *inside* blender
# - name it "sun_set.py"
# - select a sun lamp (or any directional lamp)
# - press ALT+p with you mouse over the script
# The sky texture is now aligned to the sun lamp
# selected lamp
sun_lamp = bpy.context.selected_objects[0]
# get rotation euler
sun_rot = mathutils.Euler(sun_lamp.rotation_euler, sun_lamp.rotation_mode)
vec_rot = mathutils.Vector((0.0, 0.0, 1.0))
vec_rot.rotate(sun_rot)
# apply to world sky texture
bpy.data.worlds['World'].node_tree.nodes['Sky Texture'].sun_direction = vec_rot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment