Skip to content

Commit

Permalink
Merge pull request #92 from masqu3rad3/91-blender-increment-version-bug
Browse files Browse the repository at this point in the history
hotfix - blender thumbnail creation issue which causes errors on new …
  • Loading branch information
masqu3rad3 authored Apr 13, 2024
2 parents 912fd9a + 3830cc1 commit fc28a29
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tik_manager4/dcc/blender/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def get_current_frame():
def generate_thumbnail(self, file_path, width, height):
"""Generate a thumbnail for the scene."""

bpy.context.scene.render.image_settings.file_format = 'JPEG'
# get the extension from the file path
extension = Path(file_path).suffix
extension_map = {".jpg": 'JPEG', ".png": 'PNG'}

bpy.context.scene.render.image_settings.file_format = extension_map.get(extension, 'JPEG')
bpy.context.scene.render.filepath = file_path
bpy.context.scene.render.resolution_x = width * 10
bpy.context.scene.render.resolution_y = height * 10
Expand All @@ -84,7 +88,11 @@ def generate_thumbnail(self, file_path, width, height):
# Render the single frame
# bpy.ops.render.render(write_still=True)
context = utils.get_override_context()
with bpy.context.temp_override(**context):
try:
with bpy.context.temp_override(**context):
bpy.ops.render.opengl(write_still=True)
except TypeError:
# the override context is not working in the newer versions of blender
bpy.ops.render.opengl(write_still=True)

# we saved the image 10 times bigger than the desired size, so we need to resize it
Expand Down

0 comments on commit fc28a29

Please sign in to comment.