From 821a60251ceeb852123f98814f5265ab14781908 Mon Sep 17 00:00:00 2001 From: raccoon Date: Sun, 15 Dec 2024 22:01:03 +0500 Subject: [PATCH] AMEND ME!!! --- Assets/avatar-example/mesh/blend~/axes.png | 3 + .../mesh/blend~/example_2.79.blend | 3 + .../mesh/blend~/ui_bone_size.py | 91 ++++++++++++++ Assets/avatar-example/mesh/blend~/ui_grid.py | 113 ++++++++++++++++++ Assets/avatar-example/mesh/fbx/scene/room.fbx | 3 + 5 files changed, 213 insertions(+) create mode 100644 Assets/avatar-example/mesh/blend~/axes.png create mode 100644 Assets/avatar-example/mesh/blend~/example_2.79.blend create mode 100644 Assets/avatar-example/mesh/blend~/ui_bone_size.py create mode 100644 Assets/avatar-example/mesh/blend~/ui_grid.py create mode 100644 Assets/avatar-example/mesh/fbx/scene/room.fbx diff --git a/Assets/avatar-example/mesh/blend~/axes.png b/Assets/avatar-example/mesh/blend~/axes.png new file mode 100644 index 0000000..24d4e13 --- /dev/null +++ b/Assets/avatar-example/mesh/blend~/axes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd41e9148296d7f37de24d4ed9aaeb24752407802e128139883f4293ac1e7c1b +size 944 diff --git a/Assets/avatar-example/mesh/blend~/example_2.79.blend b/Assets/avatar-example/mesh/blend~/example_2.79.blend new file mode 100644 index 0000000..dfb80d8 --- /dev/null +++ b/Assets/avatar-example/mesh/blend~/example_2.79.blend @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c797285f8c1bdb5c4c910d4cc52d59aa59e8b26b3fa7cabdce4ae9a5e00d73a +size 684176 diff --git a/Assets/avatar-example/mesh/blend~/ui_bone_size.py b/Assets/avatar-example/mesh/blend~/ui_bone_size.py new file mode 100644 index 0000000..2234dad --- /dev/null +++ b/Assets/avatar-example/mesh/blend~/ui_bone_size.py @@ -0,0 +1,91 @@ +import bpy +from bpy.props import FloatProperty +from bpy.types import Context, Operator, Panel + + +class ArmEditOperator: + @classmethod + def poll(cls, context: Context): + return ( + context.active_object + and context.active_object.type == 'ARMATURE' + and context.active_bone + and context.mode == 'EDIT_ARMATURE' + ) + + +class ARMATURE_OT_ReadBoneLength(ArmEditOperator, Operator): + """Make length property equal to actual bone length""" + bl_idname = "armature.read_bone_length" + bl_label = "Read Bone Length" + bl_options = {'UNDO'} + + def execute(self, context): + context.active_bone.bbone_y = context.active_bone.length + return {'FINISHED'} + + +class ARMATURE_OT_MakeBoneSquare(ArmEditOperator, Operator): + """Make bone's width and depth equal to it's length""" + bl_idname = "armature.make_bone_square" + bl_label = "Make Bone Square" + bl_options = {'UNDO'} + + def execute(self, context): + context.active_bone.bbone_x = context.active_bone.bbone_z = context.active_bone.length * 0.5 + return {'FINISHED'} + + +class VIEW3D_PT_bone_size(Panel): + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_label = "Bone Size" + bl_options = {'DEFAULT_CLOSED'} + + @classmethod + def poll(cls, context: Context): + scene = context.space_data + ob = context.active_object + return scene and ob and ob.type == 'ARMATURE' and ob.mode == 'EDIT' + + def draw(self, context: Context): + layout = self.layout + + col = layout.column() + col.prop(context.active_bone, "bbone_x", text="Bone Width") + col.prop(context.active_bone, "bbone_z", text="Bone Depth") + sub = col.row(align=True) + sub.operator(ARMATURE_OT_ReadBoneLength.bl_idname, icon="COPYDOWN", text="") + sub.prop(context.active_bone, "bbone_y", text="Bone Length") + col.operator(ARMATURE_OT_MakeBoneSquare.bl_idname, icon="MESH_PLANE") + + +def update_length(self, context) -> None: + context.active_bone.length = self.bbone_y + + +def register(): + bpy.types.EditBone.bbone_y = FloatProperty( + name="B-Bone Display Y Length", + description="B-Bone Y size", + default=1.0, + min=0.0, + soft_min=0.001, + step=10, + precision=3, + options={'HIDDEN'}, + update=update_length, + ) + bpy.utils.register_class(ARMATURE_OT_ReadBoneLength) + bpy.utils.register_class(ARMATURE_OT_MakeBoneSquare) + bpy.utils.register_class(VIEW3D_PT_bone_size) + + +def unregister(): + bpy.utils.unregister_class(VIEW3D_PT_bone_size) + bpy.utils.unregister_class(ARMATURE_OT_MakeBoneSquare) + bpy.utils.unregister_class(ARMATURE_OT_ReadBoneLength) + del bpy.types.EditBone.bbone_y + + +register() diff --git a/Assets/avatar-example/mesh/blend~/ui_grid.py b/Assets/avatar-example/mesh/blend~/ui_grid.py new file mode 100644 index 0000000..edc620b --- /dev/null +++ b/Assets/avatar-example/mesh/blend~/ui_grid.py @@ -0,0 +1,113 @@ +import math + +import bpy +from bpy.props import EnumProperty, IntProperty + +HU_TO_METERS_RATIO = 0.025 # 1hu = 2.5cm +GRID_SUBDIVISIONS = 8 + + +class VIEW3D_OT_ResetGrid(bpy.types.Operator): + """Reset grid settings to defaults""" + bl_idname = "screen.reset_grid" + bl_label = "Reset Grid" + bl_options = {'UNDO'} + + def execute(self, context): + context.space_data.grid_lines = 16 + context.space_data.grid_scale = 1.0 + context.space_data.grid_subdivisions = 8 + return {'FINISHED'} + + +class VIEW3D_PT_grid_level(bpy.types.Panel): + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_label = "Grid Level" + + def draw(self, context): + layout = self.layout + + row = layout.row() + row.prop(context.scene, "grid_type", expand=True) + + col = layout.column() + if context.scene.grid_type == 'HAMMER': + col.prop(context.scene, "grid_hu") + + grid_size = pow(2, context.scene.grid_hu) + + split = col.split(align=True) + col_l = split.column() + col_l.alignment = 'RIGHT' + col_l.label("Hammer Units:") + col_l.label("Meters:") + col_r = split.column() + col_r.label("%i hu" % grid_size) + col_r.label("%.3f m" % (grid_size * HU_TO_METERS_RATIO)) + + elif context.scene.grid_type == 'POWEROF2': + col.prop(context.scene, "grid_po2") + + layout.operator(VIEW3D_OT_ResetGrid.bl_idname) + + +def update_grid_hu(self, context) -> None: + grid_size = pow(2, self.grid_hu) + context.space_data.grid_lines = max(3, math.ceil(1024 / grid_size)) + context.space_data.grid_scale = grid_size * HU_TO_METERS_RATIO + context.space_data.grid_subdivisions = GRID_SUBDIVISIONS + + +def update_grid_po2(self, context) -> None: + context.space_data.grid_lines = max(3, pow(2, self.grid_po2 + 5)) + context.space_data.grid_scale = 1 / pow(2, self.grid_po2) + context.space_data.grid_subdivisions = GRID_SUBDIVISIONS + + +def update_type(self, context) -> None: + if self.grid_type == 'HAMMER': + update_grid_hu(self, context) + elif self.grid_type == 'POWEROF2': + update_grid_po2(self, context) + + +def register(): + bpy.types.Scene.grid_type = EnumProperty( + items=( + ('HAMMER', "Hammer Units", "Main basic settings"), + ('POWEROF2', "Power Of 2", "Armature-related settings"), + ), + name="Grid type", + description="", + update=update_type, + ) + bpy.types.Scene.grid_hu = IntProperty( + name="Grid level", + description="Hammer Units grid level", + min=0, + max=9, + default=4, + update=update_grid_hu, + ) + bpy.types.Scene.grid_po2 = IntProperty( + name="Grid divisions", + description="Grid divisions in power of 2", + min=-4, + max=4, + default=0, + update=update_grid_po2, + ) + bpy.utils.register_class(VIEW3D_OT_ResetGrid) + bpy.utils.register_class(VIEW3D_PT_grid_level) + + +def unregister(): + bpy.utils.unregister_class(VIEW3D_PT_grid_level) + bpy.utils.register_class(VIEW3D_OT_ResetGrid) + del bpy.types.Scene.grid_po2 + del bpy.types.Scene.grid_hu + del bpy.types.Scene.grid_type + + +register() diff --git a/Assets/avatar-example/mesh/fbx/scene/room.fbx b/Assets/avatar-example/mesh/fbx/scene/room.fbx new file mode 100644 index 0000000..7fdd036 --- /dev/null +++ b/Assets/avatar-example/mesh/fbx/scene/room.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1e94f1f2369afc2c9c9c82a5ffad6cc34a9f65a1b6e470ad5955463adbb16cb +size 117130