Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. Here are the key points I understand from your request:
  2.  
  3. Write a Blender Python script
  4. The script should render the current frame as a normal map
  5. The normal map should be normalized to look like a typical normal map
  6. You provided an example image of what a normal map should look like
  7. To render the current frame in Blender as a normalized normal map, you can use a script like this:
  8.  
  9. import bpy
  10.  
  11. Set the render engine to Cycles
  12. bpy.context.scene.render.engine = 'CYCLES'
  13.  
  14. Create a new image to bake to
  15. image_name = "Normal_Map"
  16. image = bpy.data.images.new(image_name, width=1024, height=1024)
  17.  
  18. Create a new material and assign it to the active object
  19. mat = bpy.data.materials.new(name="Bake_Mat")
  20. bpy.context.active_object.data.materials.append(mat)
  21.  
  22. Enable use of baked normal map
  23. mat.use_nodes = True
  24. nodes = mat.node_tree.nodes
  25. texture_node = nodes.new("ShaderNodeTexImage")
  26. texture_node.image = image
  27. texture_node.select = True
  28. nodes.active = texture_node
  29.  
  30. Set bake settings
  31. bpy.context.scene.render.bake.use_selected_to_active = False
  32. bpy.context.scene.render.bake.use_cage = False
  33. bpy.context.scene.render.bake.cage_extrusion = 0.1
  34. bpy.context.scene.render.bake.type = 'NORMAL'
  35. bpy.context.scene.render.bake.normal_space = 'TANGENT'
  36. bpy.context.scene.render.bake.normal_r = 'POS_X'
  37. bpy.context.scene.render.bake.normal_g = 'POS_Y'
  38. bpy.context.scene.render.bake.normal_b = 'POS_Z'
  39.  
  40. Bake normal map
  41. bpy.ops.object.bake(type='NORMAL')
  42.  
  43. Save the normal map image
  44. image.filepath_raw = "//normal_map.png"
  45. image.file_format = 'PNG'
  46. image.save()
  47.  
  48. This will bake a tangent space normal map of the current frame, normalized with the typical blue as the Z direction. It will save the normal map as "normal_map.png" in the same directory as your Blender file.
  49.  
  50. Let me know if you have any other questions! I'd be happy to explain or modify the script further.
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement