1
$\begingroup$

I can find a lot of examples about tools for creating a sky using the User Interface (https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/sky.html), but the same cannot be said for the Python API. The only examples I found use the obsolete

bpy.context.scene.world.use_sky_paper

Which does not exist anymore. Does anyone know how this can be replicated from Python?

$\endgroup$
1
  • $\begingroup$ I think so… I messed with material nodes a bit, so it shouldn’t be to different for the world. Try bpy.data.worlds[0].node_tree.nodes… $\endgroup$ – TheLabCat May 19 at 1:52
2
$\begingroup$

Try this:

import bpy

sky_texture = bpy.context.scene.world.node_tree.nodes.new("ShaderNodeTexSky")
bg = bpy.context.scene.world.node_tree.nodes["Background"]
bpy.context.scene.world.node_tree.links.new(bg.inputs["Color"], sky_texture.outputs["Color"])

You can then tweak the options like this:

sky_texture.sky_type = 'HOSEK_WILKIE' # or 'PREETHAM'
sky_texture.turbidity = 2.0
sky_texture.ground_albedo = 0.4
sky_texture.sun_direction = mathutils.Vector((1.0, 0.0, 1.0))  # add `import mathutils` at the beginning of the script 
$\endgroup$
2
  • $\begingroup$ It works, thanks! $\endgroup$ – SIMONE BENATTI May 19 at 8:15
  • $\begingroup$ Glad I could help! $\endgroup$ – Dale Cieslak May 20 at 1:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.