Skip to content

Commit

Permalink
Fixes to AtlasGroups, postpacking and encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Naxela committed Sep 29, 2020
1 parent 07af777 commit 5f0c67a
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 110 deletions.
18 changes: 13 additions & 5 deletions __init__.py
Expand Up @@ -22,7 +22,7 @@
'name': 'The Lightmapper',
'description': 'The Lightmapper is a lightmapping utility addon for Blender, made specifically for making lightmaps for game engines.',
'author': 'Alexander Kleemann @ Naxela',
'version': (0, 4, 2, 7),
'version': (0, 4, 2, 8),
'blender': (2, 90, 0),
'location': 'View3D',
'category': '3D View'
Expand Down Expand Up @@ -113,8 +113,16 @@ def unregister():
0.4.2.3 - Fix infinite OpenCV installation on Linux
- 15.09.2020
0.4.2.4 Reimplement RGBD encoding
0.4.2.5 Add decoder options for RGBM, RGBD and LogLuv
0.4.2.6 Begin network rendering server
0.4.2.7 Begin network rendering client
0.4.2.4 - Reimplement RGBD encoding
0.4.2.5 - Add decoder options for RGBM, RGBD and LogLuv
0.4.2.6 - Begin network rendering server
0.4.2.7 - Begin network rendering client
- 29.09.2020
0.4.2.9 - Fix Xatlas bug
0.4.3.0 - Begin AtlasGroup postpacking
0.4.3.1 - Improve AtlasGroup postpacking (Rectmap packing)
0.4.3.2 - Improve AtlasGroup postpacking
0.4.3.3 - Add UV manipulation for AtlasGroup postpacking
0.4.3.4 - Fix for encoding with AtlasGroup
'''
76 changes: 0 additions & 76 deletions addon/network/server - Copy.py

This file was deleted.

7 changes: 6 additions & 1 deletion addon/operators/tlm.py
Expand Up @@ -191,7 +191,7 @@ class TLM_AtlasListNewItem(bpy.types.Operator):
# Add a new item to the list
bl_idname = "tlm_atlaslist.new_item"
bl_label = "Add a new item"
bl_description = ""
bl_description = "Create a new AtlasGroup"

def execute(self, context):
scene = context.scene
Expand All @@ -206,6 +206,7 @@ class TLM_PostAtlasListNewItem(bpy.types.Operator):
# Add a new item to the list
bl_idname = "tlm_postatlaslist.new_item"
bl_label = "Add a new item"
bl_description = "Create a new AtlasGroup"
bl_description = ""

def execute(self, context):
Expand All @@ -221,6 +222,7 @@ class TLM_AtlastListDeleteItem(bpy.types.Operator):
# Delete the selected item from the list
bl_idname = "tlm_atlaslist.delete_item"
bl_label = "Deletes an item"
bl_description = "Delete an AtlasGroup"

@classmethod
def poll(self, context):
Expand Down Expand Up @@ -252,6 +254,7 @@ class TLM_PostAtlastListDeleteItem(bpy.types.Operator):
# Delete the selected item from the list
bl_idname = "tlm_postatlaslist.delete_item"
bl_label = "Deletes an item"
bl_description = "Delete an AtlasGroup"

@classmethod
def poll(self, context):
Expand Down Expand Up @@ -283,6 +286,7 @@ class TLM_AtlasListMoveItem(bpy.types.Operator):
# Move an item in the list
bl_idname = "tlm_atlaslist.move_item"
bl_label = "Move an item in the list"
bl_description = "Move an item in the list"
direction: bpy.props.EnumProperty(
items=(
('UP', 'Up', ""),
Expand Down Expand Up @@ -324,6 +328,7 @@ class TLM_PostAtlasListMoveItem(bpy.types.Operator):
# Move an item in the list
bl_idname = "tlm_postatlaslist.move_item"
bl_label = "Move an item in the list"
bl_description = "Move an item in the list"
direction: bpy.props.EnumProperty(
items=(
('UP', 'Up', ""),
Expand Down
21 changes: 15 additions & 6 deletions addon/panels/scene.py
@@ -1,4 +1,4 @@
import bpy, importlib
import bpy, importlib, math
from bpy.props import *
from bpy.types import Menu, Panel
from .. utility import icon
Expand Down Expand Up @@ -71,8 +71,8 @@ def draw(self, context):
if sceneProperties.tlm_override_bg_color:
row = layout.row(align=True)
row.prop(sceneProperties, "tlm_override_color")
#row = layout.row(align=True)
#row.prop(sceneProperties, "tlm_reset_uv")
row = layout.row(align=True)
row.prop(sceneProperties, "tlm_reset_uv")

row = layout.row(align=True)
row.label(text="Cycles Settings")
Expand Down Expand Up @@ -438,19 +438,28 @@ def draw(self, context):

if postatlasListItem >= 0 and len(postatlasList) > 0:
item = postatlasList[postatlasListItem]
#layout.prop_search(item, "obj", bpy.data, "objects", text="Object")
#layout.prop(item, "res_x")
layout.prop(item, "tlm_atlas_lightmap_unwrap_mode")
layout.prop(item, "tlm_atlas_lightmap_resolution")
layout.prop(item, "tlm_atlas_unwrap_margin")

#Below list object counter
amount = 0
utilized = 0
atlasUsedArea = 0
atlasSize = item.tlm_atlas_lightmap_resolution

for obj in bpy.data.objects:
if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use:
if obj.TLM_ObjectProperties.tlm_mesh_lightmap_unwrap_mode == "AtlasGroupB":
if obj.TLM_ObjectProperties.tlm_postatlas_pointer == item.name:
amount = amount + 1

atlasUsedArea += int(obj.TLM_ObjectProperties.tlm_mesh_lightmap_resolution) ** 2

layout.label(text="Objects: " + str(amount))

utilized = atlasUsedArea / (int(atlasSize) ** 2)
layout.label(text="Utilized: " + str(utilized * 100) + "%")

layout.label(text="Objects: " + str(amount))
if (utilized * 100) > 100:
layout.label(text="Warning! Overflow not yet supported")
4 changes: 1 addition & 3 deletions addon/preferences/addon_preferences.py
Expand Up @@ -8,8 +8,6 @@ class TLM_AddonPreferences(AddonPreferences):

bl_idname = "thelightmapper"

addon_keys = bpy.context.preferences.addons.keys()

def draw(self, context):

layout = self.layout
Expand All @@ -33,7 +31,7 @@ def draw(self, context):
box = layout.box()
row = box.row()
row.label(text="Blender Xatlas")
if "blender_xatlas" in self.addon_keys:
if "blender_xatlas" in bpy.context.preferences.addons.keys():
row.label(text="Blender Xatlas installed and available")
else:
row.label(text="Blender Xatlas not installed", icon_value=2)
Expand Down
54 changes: 49 additions & 5 deletions addon/utility/build.py
Expand Up @@ -61,6 +61,12 @@ def prepare_build(self=0, background_mode=False):
self.report({'INFO'}, "Error:Filtering - OpenCV not installed")
return{'FINISHED'}

#TODO DO some resolution change
#if checkAtlasSize():
# print("Error: AtlasGroup overflow")
# self.report({'INFO'}, "Error: AtlasGroup overflow - Too many objects")
# return{'FINISHED'}

setMode()

dirpath = os.path.join(os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir)
Expand All @@ -70,8 +76,8 @@ def prepare_build(self=0, background_mode=False):
#Naming check
naming_check()

if sceneProperties.tlm_reset_uv:
for obj in bpy.context.selected_objects:
if sceneProperties.tlm_reset_uv or sceneProperties.tlm_atlas_mode == "Postpack":
for obj in bpy.data.objects:
if obj.type == "MESH":
uv_layers = obj.data.uv_layers

Expand Down Expand Up @@ -545,12 +551,12 @@ def manage_build(background_pass=False):
else:
supersampling_scale = 1

pack.postpack()

for image in bpy.data.images:
if image.users < 1:
bpy.data.images.remove(image)

pack.postpack()

if scene.TLM_SceneProperties.tlm_headless:

filepath = bpy.data.filepath
Expand Down Expand Up @@ -762,4 +768,42 @@ def sec_to_hours(seconds):
def setMode():
bpy.ops.object.mode_set(mode='OBJECT')

#TODO Make some checks that returns to previous selection
#TODO Make some checks that returns to previous selection

def checkAtlasSize():

overflow = False

scene = bpy.context.scene

if scene.TLM_EngineProperties.tlm_setting_supersample == "2x":
supersampling_scale = 2
elif scene.TLM_EngineProperties.tlm_setting_supersample == "4x":
supersampling_scale = 4
else:
supersampling_scale = 1

for atlas in bpy.context.scene.TLM_PostAtlasList:

atlas_resolution = int(int(atlas.tlm_atlas_lightmap_resolution) / int(scene.TLM_EngineProperties.tlm_resolution_scale) * int(supersampling_scale))

utilized = 0
atlasUsedArea = 0

for obj in bpy.data.objects:
if obj.TLM_ObjectProperties.tlm_mesh_lightmap_use:
if obj.TLM_ObjectProperties.tlm_mesh_lightmap_unwrap_mode == "AtlasGroupB":
if obj.TLM_ObjectProperties.tlm_postatlas_pointer == atlas.name:

atlasUsedArea += int(obj.TLM_ObjectProperties.tlm_mesh_lightmap_resolution) ** 2

utilized = atlasUsedArea / (int(atlas_resolution) ** 2)
if (utilized * 100) > 100:
overflow = True
print("Overflow for: " + str(atlas.name))

if overflow == True:
return True
else:
return False

2 changes: 2 additions & 0 deletions addon/utility/filtering/opencv.py
Expand Up @@ -54,6 +54,8 @@ def init(lightmap_dir, denoise):
override = bpy.data.objects[obj_name].TLM_ObjectProperties.tlm_mesh_filter_override
elif obj_name in scene.TLM_AtlasList:
override = False
else:
override = False

if override:

Expand Down

0 comments on commit 5f0c67a

Please sign in to comment.