From fc24231e61ce88e25b9895ff21f97addff1e43b1 Mon Sep 17 00:00:00 2001 From: jsyoo Date: Fri, 16 Sep 2022 18:18:18 +0900 Subject: [PATCH] feat: build up for basic function --- __init__.py | 44 +++++++++++++++ pose-thumbnail-exporter.code-workspace | 8 +++ ptx_op.py | 74 ++++++++++++++++++++++++++ ptx_pnl.py | 37 +++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 __init__.py create mode 100644 pose-thumbnail-exporter.code-workspace create mode 100644 ptx_op.py create mode 100644 ptx_pnl.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..c0d7cc6 --- /dev/null +++ b/__init__.py @@ -0,0 +1,44 @@ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +bl_info = { + "name" : "pose-thumbnail-exporter", + "author" : "eatdesignlove", + "description" : "add-on for pose's thumbnail exporting", + "blender" : (3, 2, 2), + "version" : (0, 0, 1), + "warning" : "", + "category" : "Animation" +} + +import bpy + +from . ptx_op import PTX_OT_Export_All_Pose_Op, PTX_OT_Change_Posemode_OP +from . ptx_pnl import PTX_PT_Panel + +classes = (PTX_OT_Change_Posemode_OP, PTX_OT_Export_All_Pose_Op, PTX_PT_Panel) + +def register(): + for c in classes: + bpy.utils.register_class(c) + + bpy.types.Scene.directory = bpy.props.StringProperty(subtype='DIR_PATH') + +def unregister(): + for c in classes: + bpy.utils.unregister_class(c) + + del(bpy.types.Scene.directory) + +if __name__ == "__main__": + register() \ No newline at end of file diff --git a/pose-thumbnail-exporter.code-workspace b/pose-thumbnail-exporter.code-workspace new file mode 100644 index 0000000..d6c7df5 --- /dev/null +++ b/pose-thumbnail-exporter.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } +], + "settings": {} +} diff --git a/ptx_op.py b/ptx_op.py new file mode 100644 index 0000000..c6183f9 --- /dev/null +++ b/ptx_op.py @@ -0,0 +1,74 @@ +import bpy +import os +from bpy.types import ( + Operator, +) + +class PTX_OT_Change_Posemode_OP(Operator): + bl_idname = "object.change_posemode" + bl_label = "Change posemode" + bl_description = "Change current mode to posemode" + + @classmethod + def poll(cls, context): + current_mode = bpy.context.object.mode + if current_mode == "POSE": + return False + return True + + def execute(self, context): + bpy.ops.object.mode_set(mode='POSE') + return {'FINISHED'} + + +class PTX_OT_Export_All_Pose_Op(Operator): + bl_idname = "object.export_all_pose" + bl_label = "Export All Pose thumbnail" + bl_description = "Export all Pose thumbnail" + + @classmethod + def poll(cls, context): + current_mode = bpy.context.object.mode + if current_mode == "POSE": + return True + return False + + def execute(self, context): + # armature 오브젝트 찾기 + for obj in bpy.data.objects: + target = obj.find_armature() + if target is not None: + armatureObj = target + # skybox 렌더 제외 + if obj.name == "skybox": + obj.hide_render=True + + # 포즈 개수 배열 + actionsLength = len(bpy.data.actions) + + armatureObj.animation_data_create() + + # 렌더 세팅 설정하기 + bpy.context.scene.frame_start = 0 + bpy.context.scene.frame_end = actionsLength + bpy.context.scene.render.engine = 'BLENDER_WORKBENCH' + bpy.context.scene.render.resolution_x = 768 + bpy.context.scene.render.resolution_y = 768 + + filename = bpy.path.basename(bpy.data.filepath) + print(filename) + print(bpy.context.scene.directory, ':::bpy.types.Scene.directory:::') + + for idx in range(actionsLength): + # 키프레임 이동 + bpy.context.scene.frame_set(idx) + action = bpy.data.actions[idx] + + # 포즈 적용 + armatureObj.animation_data.action = action + + bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1) + bpy.context.scene.render.filepath = os.path.join(bpy.context.scene.directory, ('pose_thumb_%d.jpg' % idx)) + bpy.ops.render.render(write_still = True) + + return {'FINISHED'} \ No newline at end of file diff --git a/ptx_pnl.py b/ptx_pnl.py new file mode 100644 index 0000000..f75654e --- /dev/null +++ b/ptx_pnl.py @@ -0,0 +1,37 @@ +import bpy +from bpy.types import Panel + +from .lib.easybpy import * + +class PTX_PT_Panel(Panel): + bl_space_type = "VIEW_3D" #패널이 보여지는 화면모드 + bl_region_type = "UI" + bl_label = "Pose thumbnail exporter" #패널 상단 라벨 + bl_category = "pose.tools" #사이드바 패널명 + + @classmethod + def poll(cls, context): + return bool( + context.mode in {'OBJECT','EDIT_MESH', 'EDIT_ARMATURE','POSE'} + and get_scene().clone_props.files_loaded + ) + + def draw(self, context): + layout = self.layout + + if context.mode == 'POSE': + row = layout.row().label(text="Output Path") + self.layout.prop(context.scene, "directory") + + row = layout.row() + row.scale_y = 1.5 + row.operator("object.export_all_pose", text ="Export Pose Thumnails") + + else: + row = layout.row() + row.scale_y = 1.5 + row.operator( + "object.change_posemode", + text="Switch to Pose Mode", + depress=True, icon='POSE_HLT' + )