Begin bake tool
This commit is contained in:
parent
5626003ead
commit
5811569234
78
blender/arm/props_bake.py
Normal file
78
blender/arm/props_bake.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
import os
|
||||
import shutil
|
||||
import arm.assets as assets
|
||||
import arm.utils
|
||||
import bpy
|
||||
import stat
|
||||
from bpy.types import Menu, Panel, UIList
|
||||
from bpy.props import *
|
||||
|
||||
class ArmBakeListItem(bpy.types.PropertyGroup):
|
||||
object_name = bpy.props.StringProperty(
|
||||
name="Name",
|
||||
description="A name for this item",
|
||||
default="")
|
||||
|
||||
class ArmBakeList(bpy.types.UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
# We could write some code to decide which icon to use here...
|
||||
custom_icon = 'OBJECT_DATAMODE'
|
||||
|
||||
# Make sure your code supports all 3 layout types
|
||||
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
||||
row = layout.row()
|
||||
row.prop(item, "object_name", text="", emboss=False, icon=custom_icon)
|
||||
|
||||
elif self.layout_type in {'GRID'}:
|
||||
layout.alignment = 'CENTER'
|
||||
layout.label("", icon = custom_icon)
|
||||
|
||||
class ArmBakeListNewItem(bpy.types.Operator):
|
||||
# Add a new item to the list
|
||||
bl_idname = "arm_bakelist.new_item"
|
||||
bl_label = "Add a new item"
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
scn.arm_bakelist.add()
|
||||
scn.arm_bakelist_index = len(scn.arm_bakelist) - 1
|
||||
return{'FINISHED'}
|
||||
|
||||
|
||||
class ArmBakeListDeleteItem(bpy.types.Operator):
|
||||
# Delete the selected item from the list
|
||||
bl_idname = "arm_bakelist.delete_item"
|
||||
bl_label = "Deletes an item"
|
||||
|
||||
@classmethod
|
||||
def poll(self, context):
|
||||
""" Enable if there's something in the list """
|
||||
scn = context.scene
|
||||
return len(scn.arm_bakelist) > 0
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
list = scn.arm_bakelist
|
||||
index = scn.arm_bakelist_index
|
||||
|
||||
list.remove(index)
|
||||
|
||||
if index > 0:
|
||||
index = index - 1
|
||||
|
||||
scn.arm_bakelist_index = index
|
||||
return{'FINISHED'}
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(ArmBakeListItem)
|
||||
bpy.utils.register_class(ArmBakeList)
|
||||
bpy.utils.register_class(ArmBakeListNewItem)
|
||||
bpy.utils.register_class(ArmBakeListDeleteItem)
|
||||
bpy.types.Scene.arm_bakelist = bpy.props.CollectionProperty(type=ArmBakeListItem)
|
||||
bpy.types.Scene.arm_bakelist_index = bpy.props.IntProperty(name="Index for my_list", default=0)
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_class(ArmBakeListItem)
|
||||
bpy.utils.unregister_class(ArmBakeList)
|
||||
bpy.utils.unregister_class(ArmBakeListNewItem)
|
||||
bpy.utils.unregister_class(ArmBakeListDeleteItem)
|
|
@ -1139,6 +1139,72 @@ class ArmRenderPropsPanel(bpy.types.Panel):
|
|||
layout.prop(wrd, 'arm_lens_texture')
|
||||
layout.prop(wrd, 'arm_lut_texture')
|
||||
|
||||
class ArmBakePanel(bpy.types.Panel):
|
||||
bl_label = "Armory Bake"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "render"
|
||||
bl_options = {'DEFAULT_CLOSED'}
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
rows = 2
|
||||
scn = context.scene
|
||||
if len(scn.arm_bakelist) > 1:
|
||||
rows = 4
|
||||
row = layout.row()
|
||||
row.template_list("ArmBakeList", "The_List", scn, "arm_bakelist", scn, "arm_bakelist_index", rows=rows)
|
||||
col = row.column(align=True)
|
||||
col.operator("arm_bakelist.new_item", icon='ZOOMIN', text="")
|
||||
col.operator("arm_bakelist.delete_item", icon='ZOOMOUT', text="")
|
||||
|
||||
if scn.arm_bakelist_index >= 0 and len(scn.arm_bakelist) > 0:
|
||||
item = scn.arm_bakelist[scn.arm_bakelist_index]
|
||||
layout.prop_search(item, "object_name", scn, "objects", "Object")
|
||||
|
||||
layout.operator("arm.bake_textures", icon="RENDER_STILL")
|
||||
|
||||
class ArmBakeButton(bpy.types.Operator):
|
||||
'''Bake textures for listed objects'''
|
||||
bl_idname = 'arm.bake_textures'
|
||||
bl_label = 'Bake'
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
if len(scn.arm_bakelist) == 0:
|
||||
return{'FINISHED'}
|
||||
# Images for baking
|
||||
for o in scn.arm_bakelist:
|
||||
ob = scn.objects[o.object_name]
|
||||
for slot in ob.material_slots:
|
||||
mat = slot.material
|
||||
img_name = "bake_" + mat.name
|
||||
# Get image
|
||||
if img_name in bpy.data.images:
|
||||
img = bpy.data.images[img_name]
|
||||
else:
|
||||
img = bpy.data.images.new("bake_" + mat.name, 2048, 2048)
|
||||
# Set image node
|
||||
mat.use_nodes = True
|
||||
nodes = mat.node_tree.nodes
|
||||
if 'Baked Image' in nodes:
|
||||
img_node = nodes['Baked Image']
|
||||
else:
|
||||
img_node = nodes.new('ShaderNodeTexImage')
|
||||
img_node.name = 'Baked Image'
|
||||
img_node.location = (100, 100)
|
||||
img_node.image = img
|
||||
img_node.select = True
|
||||
nodes.active = img_node
|
||||
# Bake
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
for o in scn.arm_bakelist:
|
||||
scn.objects[o.object_name].select = True
|
||||
scn.objects.active = scn.objects[scn.arm_bakelist[0].object_name]
|
||||
bpy.ops.object.bake(type='COMBINED')
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
return{'FINISHED'}
|
||||
|
||||
class ArmGenLodButton(bpy.types.Operator):
|
||||
'''Automatically generate LoD levels'''
|
||||
bl_idname = 'arm.generate_lod'
|
||||
|
@ -1400,6 +1466,7 @@ def register():
|
|||
bpy.utils.register_class(ArmoryProjectPanel)
|
||||
bpy.utils.register_class(ArmRenderPathPanel)
|
||||
bpy.utils.register_class(ArmRenderPropsPanel)
|
||||
bpy.utils.register_class(ArmBakePanel)
|
||||
# bpy.utils.register_class(ArmVirtualInputPanel)
|
||||
bpy.utils.register_class(ArmoryPlayButton)
|
||||
bpy.utils.register_class(ArmoryPlayInViewportButton)
|
||||
|
@ -1418,6 +1485,7 @@ def register():
|
|||
bpy.utils.register_class(ArmoryRenderAnimButton)
|
||||
bpy.utils.register_class(ArmoryGenerateNavmeshButton)
|
||||
bpy.utils.register_class(ArmNavigationPanel)
|
||||
bpy.utils.register_class(ArmBakeButton)
|
||||
bpy.utils.register_class(ArmGenLodButton)
|
||||
bpy.utils.register_class(ArmLodPanel)
|
||||
bpy.utils.register_class(ArmTilesheetPanel)
|
||||
|
@ -1452,6 +1520,7 @@ def unregister():
|
|||
bpy.utils.unregister_class(ArmoryProjectPanel)
|
||||
bpy.utils.unregister_class(ArmRenderPathPanel)
|
||||
bpy.utils.unregister_class(ArmRenderPropsPanel)
|
||||
bpy.utils.unregister_class(ArmBakePanel)
|
||||
# bpy.utils.unregister_class(ArmVirtualInputPanel)
|
||||
bpy.utils.unregister_class(ArmoryPlayButton)
|
||||
bpy.utils.unregister_class(ArmoryPlayInViewportButton)
|
||||
|
@ -1470,6 +1539,7 @@ def unregister():
|
|||
bpy.utils.unregister_class(ArmoryRenderAnimButton)
|
||||
bpy.utils.unregister_class(ArmoryGenerateNavmeshButton)
|
||||
bpy.utils.unregister_class(ArmNavigationPanel)
|
||||
bpy.utils.unregister_class(ArmBakeButton)
|
||||
bpy.utils.unregister_class(ArmGenLodButton)
|
||||
bpy.utils.unregister_class(ArmLodPanel)
|
||||
bpy.utils.unregister_class(ArmTilesheetPanel)
|
||||
|
|
|
@ -5,6 +5,7 @@ import arm.props_traits
|
|||
import arm.props_lod
|
||||
import arm.props_tilesheet
|
||||
import arm.props_exporter
|
||||
import arm.props_bake
|
||||
import arm.props_renderpath
|
||||
import arm.props
|
||||
import arm.props_ui
|
||||
|
@ -25,6 +26,7 @@ def register():
|
|||
arm.props_lod.register()
|
||||
arm.props_tilesheet.register()
|
||||
arm.props_exporter.register()
|
||||
arm.props_bake.register()
|
||||
arm.props_renderpath.register()
|
||||
arm.props.register()
|
||||
arm.props_ui.register()
|
||||
|
@ -48,5 +50,6 @@ def unregister():
|
|||
arm.props_lod.unregister()
|
||||
arm.props_tilesheet.unregister()
|
||||
arm.props_exporter.unregister()
|
||||
arm.props_bake.unregister()
|
||||
arm.props_renderpath.unregister()
|
||||
arm.space_armory.unregister()
|
||||
|
|
Loading…
Reference in a new issue