Skip to content

Instantly share code, notes, and snippets.

@MarkC-b3d
Created September 22, 2017 13:37
Show Gist options
  • Save MarkC-b3d/b7f58eb2b0a20c93bc21ad28e4bc2bcc to your computer and use it in GitHub Desktop.
Save MarkC-b3d/b7f58eb2b0a20c93bc21ad28e4bc2bcc to your computer and use it in GitHub Desktop.
An addon for a more streamlined normal baking procedure in blender.
bl_info = {
"name": "Easy Normals",
"author": "Mark C <BlendedMarks>",
"version": (0,1),
"blender": (2, 79, 0),
"location": "View3D >Spacebar Menu",
"description": "Prepares the Blender environment for easily baking normals",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Object"}
import bpy
class MakeNormal(bpy.types.Operator):
"""Easy Normals""" # blender will use this as a tooltip for menu items and buttons.
bl_idname = "object.make_normals" # unique identifier for buttons and menu items to reference.
bl_label = "Easy normals "# display name in the interface.
bl_options = {'REGISTER', 'UNDO'} # enable undo for the operator.
def execute(self, context): # execute() is called by blender when running the operator.
bpy.ops.object.editmode_toggle() #on
bpy.ops.uv.smart_project()
bpy.ops.object.editmode_toggle() #off
##Assign Material
ob = bpy.context.active_object
# Get material
mat = bpy.data.materials.get("Material")
if mat is None:
# create material
mat = bpy.data.materials.new(name="NormalBakedMaterial")
# Assign it to object
if ob.data.materials:
# assign to 1st material slot
ob.data.materials[0] = mat
else:
# no slots
ob.data.materials.append(mat)
#Get the image
image = bpy.data.images.new(name="BakedNormals", width=1024, height=1024)
bpy.context.scene.cycles.bake_type = 'NORMAL'
bpy.context.area.type = 'NODE_EDITOR'
bpy.context.space_data.tree_type = 'ShaderNodeTree'
bpy.context.object.active_material.use_nodes = True
return {'FINISHED'}
def register():
bpy.utils.register_class(MakeNormal)
def unregister():
bpy.utils.unregister_class(MakeNormal)
# This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment