AMEND ME!!!

This commit is contained in:
raccoon
2024-12-15 22:01:03 +05:00
parent b1690c7a57
commit 821a60251c
5 changed files with 213 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -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()

View File

@@ -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()

Binary file not shown.