Skip to content

Commit

Permalink
Blender 4.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vbousquet committed Mar 18, 2024
1 parent e5aa4fc commit 3c96971
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion addons/vpx_lightmapper/vlm_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ def append_structure(src_path, mode, hashed):
col = vlm_collections.get_collection(bake_col, obj.vlmSettings.bake_collections, create=False)

obj.data.validate()
obj.data.calc_normals_split() # compute loop normal (would be 0,0,0 otherwise)
if bpy.app.version < (4, 1, 0): # FIXME Remove for Blender 4.1
obj.data.calc_normals_split() # compute loop normal (would be 0,0,0 otherwise)
uv_layer_nested = obj.data.uv_layers.get("UVMap Nested")
if not uv_layer_nested:
logger.info(f'. Missing nested uv map for {obj.name}')
Expand Down
10 changes: 6 additions & 4 deletions addons/vpx_lightmapper/vlm_meshes_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def create_bake_meshes(op, context):
logger.info(f'. ERROR {obj_name} has an invalid modifier which was not applied')
dup.modifiers.clear()

# Remove custom normals since they will be lost during mesh optimization
if optimize_mesh:
# FIXME Remove for Blender 4.1
if bpy.app.version < (4, 1, 0) and optimize_mesh: # Remove custom normals since they will be lost during mesh optimization
dup.data.free_normals_split()
dup.data.use_auto_smooth = False # Don't use custom normals since we removed them
with context.temp_override(active_object=dup, selected_objects=[dup]):
Expand All @@ -225,7 +225,8 @@ def create_bake_meshes(op, context):

# Save normals
dup.data.validate()
dup.data.calc_normals_split() # compute loop normal (would 0,0,0 otherwise since we free them above)
if bpy.app.version < (4, 1, 0): # FIXME Remove for Blender 4.1
dup.data.calc_normals_split() # compute loop normal (would 0,0,0 otherwise since we free them above)

# Switch material to baked ones (needs to be done after applying modifiers which may create material slots)
for poly in dup.data.polygons:
Expand Down Expand Up @@ -461,7 +462,8 @@ def create_bake_meshes(op, context):
prev_nestmap = bpy.data.objects[obj_name].vlmSettings.bake_nestmap if bpy.data.objects.get(obj_name) else -1
bake_instance = bpy.data.objects.new(obj_name, bake_mesh.copy())
# Remove face shading (lightmap are not made to be shaded and the pruning process breaks the shading)
bake_instance.data.free_normals_split()
if bpy.app.version < (4, 1, 0): # FIXME Remove for Blender 4.1
bake_instance.data.free_normals_split()
bake_instance.data.use_auto_smooth = False # Don't use custom normals since we removed them
with context.temp_override(active_object=bake_instance, selected_objects=[bake_instance]):
bpy.ops.object.shade_flat()
Expand Down
2 changes: 2 additions & 0 deletions addons/vpx_lightmapper/vlm_nestmap_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def render_nestmaps(op, context):
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
# VPX only supports opaque HDR therefore we pack all non lightmaps as LDR (luckily base bake is usually LDR, and we don't really need this for lightmaps which are RGB only)
if not obj.vlmSettings.is_lightmap or obj.vlmSettings.bake_hdr_range <= 1.0:
if obj.vlmSettings.bake_hdr_range > 1.0:
logger.error('ERROR: Object {obj.name} is packed to an LDR nestmap while it has an HDR range of {obj.vlmSettings.bake_hdr_range}. Render will be wrongly clamped. You need to reduce bake lighting strength to avoid this.')
if has_normalmap:
to_nest_ldr_nm.append(obj)
else:
Expand Down

0 comments on commit 3c96971

Please sign in to comment.