generated from stilobique/BlenderTemplate
Automatized the thumbnail generation, and adding easily all lights
This commit is contained in:
@@ -13,7 +13,27 @@ class ConfigLighting(bpy.types.Operator):
|
|||||||
self.clear_light_on_scene()
|
self.clear_light_on_scene()
|
||||||
|
|
||||||
r = self.get_blend_resources_file()
|
r = self.get_blend_resources_file()
|
||||||
print(f'[Pipeline] Get file resource {r}')
|
|
||||||
|
world = bpy.data.worlds.get('WorldIconRendering')
|
||||||
|
if not world:
|
||||||
|
with bpy.data.libraries.load(r, link=True) as (data_from, data_to):
|
||||||
|
data_to.worlds = data_from.worlds
|
||||||
|
|
||||||
|
world = bpy.data.worlds.get('WorldIconRendering')
|
||||||
|
|
||||||
|
context.scene.world = world
|
||||||
|
|
||||||
|
if not bpy.data.collections.get('Lighting'):
|
||||||
|
print(f'[Pipeline] Need to import the lighting collection')
|
||||||
|
with bpy.data.libraries.load(r, link=False) as (data_from, data_to):
|
||||||
|
for collection in data_from.collections:
|
||||||
|
print(f'[Pipeline] Collection can be import "{collection}"')
|
||||||
|
if 'Lighting' in collection:
|
||||||
|
print(f'[Pipeline] Append {collection}.')
|
||||||
|
data_to.collections.append(collection)
|
||||||
|
|
||||||
|
print('[Pipeline] Link lighting collection with the scene collection')
|
||||||
|
bpy.data.collections['Scene'].children.link(bpy.data.collections.get('Lighting'))
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@@ -21,23 +41,15 @@ class ConfigLighting(bpy.types.Operator):
|
|||||||
def get_blend_resources_file():
|
def get_blend_resources_file():
|
||||||
"""Get the blend file shared with the addon"""
|
"""Get the blend file shared with the addon"""
|
||||||
addon_folder = Path(bpy.utils.user_resource('SCRIPTS'))
|
addon_folder = Path(bpy.utils.user_resource('SCRIPTS'))
|
||||||
print(f'[Pipeline] Get addon folder "{addon_folder}"')
|
addon_name = __name__.split(".")[0]
|
||||||
addon_name = str(bpy.context.preferences.addons[__name__.split(".")[0]])
|
|
||||||
print(f'[Pipeline] The addon name "{addon_name}"')
|
|
||||||
|
|
||||||
return addon_folder.joinpath("addons", addon_name, "resources").as_posix()
|
return addon_folder.joinpath("addons", addon_name, "resources", "Lighting.blend").as_posix()
|
||||||
|
|
||||||
def get_world(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_light_collection(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def clear_light_on_scene(self):
|
def clear_light_on_scene(self):
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
|
|
||||||
for ob in bpy.data.objects:
|
for ob in bpy.data.objects:
|
||||||
if ob.type == 'LIGHT' and self.find_collection(ob):
|
if ob.type == 'LIGHT' and not self.find_collection(ob):
|
||||||
ob.select_set(True)
|
ob.select_set(True)
|
||||||
bpy.ops.object.delete()
|
bpy.ops.object.delete()
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ class ConfigRendering(bpy.types.Operator):
|
|||||||
self.set_rendering_panel()
|
self.set_rendering_panel()
|
||||||
self.set_output_file()
|
self.set_output_file()
|
||||||
|
|
||||||
|
bpy.ops.render.render(write_still=True, use_viewport=True)
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def set_rendering_panel(self):
|
def set_rendering_panel(self):
|
||||||
@@ -33,8 +35,10 @@ class ConfigRendering(bpy.types.Operator):
|
|||||||
def set_output_file(self):
|
def set_output_file(self):
|
||||||
self.scene.render.resolution_x = self.scene.render.resolution_y = 512
|
self.scene.render.resolution_x = self.scene.render.resolution_y = 512
|
||||||
self.scene.render.image_settings.file_format = 'TARGA'
|
self.scene.render.image_settings.file_format = 'TARGA'
|
||||||
|
self.scene.render.image_settings.color_mode = 'RGBA'
|
||||||
self.scene.render.filepath = self.filename_export.as_posix()
|
self.scene.render.filepath = self.filename_export.as_posix()
|
||||||
|
|
||||||
def set_camera_used(self):
|
def set_camera_used(self):
|
||||||
"""Find the best camera position"""
|
"""Find the best camera position"""
|
||||||
|
# TODO
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user