preliminary font size and translation

This commit is contained in:
themancalledjakob 2024-08-05 12:59:07 +02:00
parent 8a63014d58
commit 7e55f9e9bf
2 changed files with 35 additions and 12 deletions

View file

@ -178,6 +178,18 @@ class FONT3D_text_properties(bpy.types.PropertyGroup):
default=(1.5707963267948966, 0.0, 0.0), # 90 degrees in radians default=(1.5707963267948966, 0.0, 0.0), # 90 degrees in radians
subtype='EULER', subtype='EULER',
) )
translation: bpy.props.FloatVectorProperty(
update=update_callback,
name="Translation",
default=(0.0, 0.0, 0.0),
subtype='TRANSLATION',
)
font_size: bpy.props.FloatProperty(
update=update_callback,
name="Font Size",
default=1.0,
subtype='NONE',
)
distribution_type: bpy.props.StringProperty() distribution_type: bpy.props.StringProperty()
glyphs: bpy.props.CollectionProperty(type=FONT3D_glyph_properties) glyphs: bpy.props.CollectionProperty(type=FONT3D_glyph_properties)
@ -442,6 +454,8 @@ class FONT3D_PT_TextPropertiesPanel(bpy.types.Panel):
layout.label(text=f"Mom: {props.text_object.name}") layout.label(text=f"Mom: {props.text_object.name}")
layout.row().prop(props, "text") layout.row().prop(props, "text")
layout.row().prop(props, "letter_spacing") layout.row().prop(props, "letter_spacing")
layout.row().prop(props, "font_size")
layout.column().prop(props, "translation")
layout.column().prop(props, "orientation") layout.column().prop(props, "orientation")
class FONT3D_OT_LoadFont(bpy.types.Operator): class FONT3D_OT_LoadFont(bpy.types.Operator):
@ -740,27 +754,36 @@ class FONT3D_PT_RightPropertiesPanel(bpy.types.Panel):
obj = context.active_object obj = context.active_object
def is_text(): def is_it_text():
return type(next((t for t in context.scene.font3d_data.available_texts if t.text_object == context.active_object), None)) != type(None) return type(next((t for t in context.scene.font3d_data.available_texts if t.text_object == context.active_object), None)) != type(None)
def is_glyph(): def is_it_glyph():
return type(next((t for t in context.scene.font3d_data.available_texts if t.text_object == context.active_object.parent), None)) != type(None) return type(next((t for t in context.scene.font3d_data.available_texts if t.text_object == context.active_object.parent), None)) != type(None)
textobject = obj if is_text() else obj.parent if is_glyph() else obj is_text = is_it_text()
is_glyph = is_it_glyph()
textobject = obj if is_text else obj.parent if is_glyph else obj
available_text = font3d_data.available_texts[font3d_data.active_text_index] available_text = font3d_data.available_texts[font3d_data.active_text_index]
row = layout.row() # row = layout.row()
row.label(text="Hello world!", icon='WORLD_DATA') # row.label(text="Hello world!", icon='WORLD_DATA')
# row = layout.row()
row = layout.row() # row.label(text="Active object is: " + obj.name)
row.label(text="Active object is: " + obj.name) # row = layout.row()
row = layout.row() # row.label(text="text object is: " + textobject.name)
row.label(text="text object is: " + textobject.name)
row = layout.row() row = layout.row()
row.label(text=f"active text index is: {font3d_data.active_text_index}") row.label(text=f"active text index is: {font3d_data.active_text_index}")
layout.row().label(text="Text Properties:")
layout.row().prop(available_text, "text") layout.row().prop(available_text, "text")
layout.row().prop(available_text, "letter_spacing") layout.row().prop(available_text, "letter_spacing")
layout.row().prop(available_text, "font_size")
layout.column().prop(available_text, "translation")
layout.column().prop(available_text, "orientation") layout.column().prop(available_text, "orientation")
if is_glyph:
layout.row().label(text="Glyph Properties:")
classes = ( classes = (
FONT3D_addonPreferences, FONT3D_addonPreferences,

View file

@ -576,7 +576,7 @@ def set_text_on_curve(text_properties):
ob.constraints["Follow Path"].up_axis = "UP_Y" ob.constraints["Follow Path"].up_axis = "UP_Y"
elif distribution_type == 'CALCULATE': elif distribution_type == 'CALCULATE':
location, tangent = calc_point_on_bezier_curve(mom, advance, True) location, tangent = calc_point_on_bezier_curve(mom, advance, True)
ob.location = mom.matrix_world @ location ob.location = mom.matrix_world @ (location + text_properties.translation)
mask = [0] mask = [0]
input_rotations = [mathutils.Vector((0.0, 0.0, 0.0))] input_rotations = [mathutils.Vector((0.0, 0.0, 0.0))]
vectors = [tangent] vectors = [tangent]
@ -593,7 +593,7 @@ def set_text_on_curve(text_properties):
q.rotate(text_properties.orientation) q.rotate(text_properties.orientation)
ob.rotation_quaternion = (mom.matrix_world @ motor[0] @ q.to_matrix().to_4x4()).to_quaternion() ob.rotation_quaternion = (mom.matrix_world @ motor[0] @ q.to_matrix().to_4x4()).to_quaternion()
scalor = 0.001 scalor = 0.001 * text_properties.font_size
glyph_advance = (-1 * glyph.bound_box[0][0] + glyph.bound_box[4][0]) * scalor + text_properties.letter_spacing glyph_advance = (-1 * glyph.bound_box[0][0] + glyph.bound_box[4][0]) * scalor + text_properties.letter_spacing