Skip to content

Commit

Permalink
Redesign bakemap / lightmap merging
Browse files Browse the repository at this point in the history
  • Loading branch information
vbousquet committed Aug 20, 2023
1 parent cf7e1d6 commit 1ce2c4d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
34 changes: 22 additions & 12 deletions addons/vpx_lightmapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,23 @@ class VLM_Scene_props(PropertyGroup):
class VLM_Collection_props(PropertyGroup):
bake_mode: EnumProperty(
items=[
('group', 'Group', 'Bake all objects to a single mesh', '', 0),
('split', 'Split', 'Bake each object to a splitted mesh', '', 1),
('group', 'Group', 'Merge all objects to a single mesh', '', 0),
('split', 'Split', 'Bake each object to its own mesh', '', 1),
],
name='Bake Mode',
description='Bake mode for the selected collection',
name='Merge Mode',
description='Define how objects in the bake collection are processed (individually or merged together).',
default='group'
)
is_opaque: BoolProperty(name="Opaque", description="Wether this collection only contains opaque objects which do not require blending.", default = True)
is_opaque: BoolProperty(name="Opaque", description="Wether this collection only contains opaque objects which do not require blending", default = True)
merge_lightmaps: BoolProperty(name="Merge Lightmaps", description="Merge lightmaps from this bake collection with lightmaps produced by others", default = True)
refraction_probe: StringProperty(name="Refraction Probe", description="Identifier of the refraction probe to be used on export", default = '')
reflection_probe: StringProperty(name="Reflection Probe", description="Identifier of the reflection probe to be used on export", default = '')
depth_bias: IntProperty(name="Depth Bias", description="Depth Bias applied to the layer when exported to VPX. Set to 0 for playfield, Negative for layer above playfield, positive for layers under playfield.", default = 0)
light_mode: EnumProperty(
items=[
('solid', 'Solid', 'Base solid bake', '', 0),
('group', 'Group', 'Bake all lights as a single lightmap group', '', 1),
('split', 'Split', 'Bake each light as a separate lightmap', '', 2)
('solid', 'Solid', 'Base lighting scenario on which others are applied', '', 0),
('group', 'Group', 'Bake all lights in this collection as a single lighting scenario', '', 1),
('split', 'Split', 'Bake each light as a separate lighting scenario', '', 2)
],
name='Light Mode',
description='Light mode for the selected collection',
Expand Down Expand Up @@ -262,8 +263,7 @@ class VLM_Object_props(PropertyGroup):
bake_height: IntProperty(name="Bake height:", description="Height of bake texture", default = 256, min = 2, max=8192)
no_mesh_optimization: BoolProperty(name="No Optimization", description="Disable mesh optimization (for example to preserve normals or unwrapped UV)", default = False)
# Both bake object and bake result
#movable_script: StringProperty(name="Sync", description="VBS script for movable/mod scynchronization", default = '')
is_movable: BoolProperty(name="No Merge", description="Part for which the bake/light meshes may only be merged with parts linked to the same VPX object", default = False)
is_movable: BoolProperty(name="Use as pivot", description="Use this part origin as the origin of the produced mesh", default = False)
use_obj_pos: BoolProperty(name="Use Obj Pos", description="Use ObjRot instead of Rot when exporting", default = False)
# Bake result properties (for object inside the bake result collection)
bake_lighting: StringProperty(name="Lighting", description="Lighting scenario", default="")
Expand Down Expand Up @@ -848,6 +848,9 @@ def draw(self, context):
layout.prop(col.vlmSettings, 'depth_bias', expand=True)
layout.prop(col.vlmSettings, 'is_opaque', expand=True)
sub = layout.column()
sub.enabled = col.vlmSettings.is_opaque
sub.prop(col.vlmSettings, 'merge_lightmaps', expand=True)
sub = layout.column()
sub.enabled = not col.vlmSettings.is_opaque
sub.prop(col.vlmSettings, 'refraction_probe', expand=True)
layout.prop(col.vlmSettings, 'reflection_probe', expand=True)
Expand Down Expand Up @@ -1023,9 +1026,16 @@ def draw(self, context):
layout.prop(context.active_object.vlmSettings, 'hide_from_others', text='Hide from others')
layout.prop(context.active_object.vlmSettings, 'bake_mask', text='Mask')
layout.separator()
layout.prop(context.active_object.vlmSettings, 'is_movable')
no_merge = False
for col in bake_col.children:
if context.active_object.name in col.all_objects:
no_merge = not (col.vlmSettings.is_opaque and col.vlmSettings.merge_lightmaps)
break
col = layout.column()
col.enabled = no_merge
col.prop(context.active_object.vlmSettings, 'is_movable')
col = layout.column()
col.enabled = context.active_object.vlmSettings.is_movable
col.enabled = context.active_object.vlmSettings.is_movable and no_merge
col.prop(context.active_object.vlmSettings, 'use_obj_pos')
layout.separator()
layout.prop(context.active_object.vlmSettings, 'use_bake', toggle=1, text='Unwrapped Bake' if context.active_object.vlmSettings.use_bake else 'Camera Render')
Expand Down
1 change: 0 additions & 1 deletion addons/vpx_lightmapper/vlm_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ def append_structure(src_path, mode, hashed):
is_lightmap = obj.vlmSettings.bake_type == 'lightmap'
is_active = obj.vlmSettings.bake_type == 'active'
is_static = obj.vlmSettings.bake_type == 'static'
is_movable = obj.vlmSettings.bake_sync_trans != ''
has_normalmap = next((mat for mat in obj.data.materials if mat.get('VLM.HasNormalMap') == True and mat['VLM.IsLightmap'] == False), None) is not None
depth_bias = None
reflection_probe = None
Expand Down
19 changes: 10 additions & 9 deletions addons/vpx_lightmapper/vlm_meshes_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ def create_bake_meshes(op, context):
to_bake.append((obj_name, bake_col, [obj_name], obj_name, not bake_col.vlmSettings.is_opaque))
else:
sync_obj = None
sync_transform = None
for obj_name in object_names:
obj = bpy.data.objects[obj_name]
if obj.vlmSettings.is_movable:
if sync_obj and sync_transform != obj.matrix_world:
logger.info(f'. ERROR: Bake collection {bake_col.name} bakes to a group multiple objects are marked as movable with different transforms. Only check the one you want to define the origin of the group.')
sync_obj = obj_name
sync_transform = obj.matrix_world
if not (bake_col.vlmSettings.is_opaque and bake_col.vlmSettings.merge_lightmaps):
sync_transform = None
for obj_name in object_names:
obj = bpy.data.objects[obj_name]
if obj.vlmSettings.is_movable:
if sync_obj and sync_transform != obj.matrix_world:
logger.info(f'. ERROR: Bake collection {bake_col.name} bakes to a group multiple objects are marked as movable with different transforms. Only check the one you want to define the origin of the group.')
sync_obj = obj_name
sync_transform = obj.matrix_world
to_bake.append((bake_col.name, bake_col, object_names, sync_obj, not bake_col.vlmSettings.is_opaque))

# Create all solid bake meshes
Expand Down Expand Up @@ -438,7 +439,7 @@ def create_bake_meshes(op, context):
merged_bake_meshes = []
opaque_bake_mesh = None
for bake_col, bake_name, bake_mesh, sync_obj in bake_meshes:
if bake_col.vlmSettings.is_opaque and sync_obj is None:
if bake_col.vlmSettings.is_opaque and bake_col.vlmSettings.merge_lightmaps:
if opaque_bake_mesh:
merged_bake_meshes.remove(opaque_bake_mesh)
ex_bake_col, ex_bake_name, ex_bake_mesh, ex_sync_obj = opaque_bake_mesh
Expand Down

0 comments on commit 1ce2c4d

Please sign in to comment.