From 4d0c42adb36041bf930c90b4136d0652c44f599f Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Wed, 14 Aug 2024 16:15:25 +0200 Subject: [PATCH] simplify placement --- __init__.py | 103 +++++++++++++++++++++++++++++++++---------------- butils.py | 8 +--- common/Font.py | 7 ++++ 3 files changed, 78 insertions(+), 40 deletions(-) diff --git a/__init__.py b/__init__.py index b696df8..a4242e3 100644 --- a/__init__.py +++ b/__init__.py @@ -211,7 +211,7 @@ class ABC3D_text_properties(bpy.types.PropertyGroup): ) ignore_orientation: bpy.props.BoolProperty( update=update_callback, - name="Ignore Orientation", + name="Ignore Curve Orientation", default=False, ) distribution_type: bpy.props.StringProperty() @@ -334,12 +334,6 @@ class ABC3D_PT_TextPlacement(bpy.types.Panel): abc3d = scene.abc3d abc3d_data = scene.abc3d_data - layout.label(text="Set Properties Objects") - layout.row().prop(abc3d, "text") - layout.row().prop(abc3d, "letter_spacing") - layout.row().prop(abc3d, "font_size") - layout.column().prop(abc3d, "translation") - layout.column().prop(abc3d, "orientation") placerow = layout.row() placerow.enabled = self.can_place placerow.operator(f"{__name__}.placetext", text='Place Text') @@ -626,36 +620,79 @@ class ABC3D_OT_PlaceText(bpy.types.Operator): bl_label = "Place Text" bl_options = {'REGISTER', 'UNDO'} - # t.font_name = font_name - # t.face_name = face_name - # t.text_object = selected - # t.text = scene.abc3d.text - # t.letter_spacing = scene.abc3d.letter_spacing - # t.font_size = scene.abc3d.font_size - # t.translation = scene.abc3d.translation - # t.orientation = scene.abc3d.orientation - # t.distribution_type = distribution_type + def font_items_callback(self, context): + items = [] + fonts = Font.get_loaded_fonts_and_faces() + for f in fonts: + items.append((f"{f[0]} {f[1]}", f"{f[0]} {f[1]}", "")) + return items - # def invoke(self, context, event): - # wm = context.window_manager - # return wm.invoke_props_dialog(self) + def font_update_callback(self, context): + font_name, face_name = self.font.split(" ") + self.font_name = font_name + self.face_name = face_name + + font_name: bpy.props.StringProperty( + options={'HIDDEN'} + ) + face_name: bpy.props.StringProperty( + options={'HIDDEN'} + ) + font: bpy.props.EnumProperty(items=font_items_callback, + update=font_update_callback + ) + text: bpy.props.StringProperty( + name="Text", + description="The text.", + default="HELLO", + maxlen=1024, + ) + # target_object: bpy.props.PointerProperty( + # name="The Target Object", + # description="The target, which will be populated by character children of text.", + # type=bpy.types.Object, + # ) + letter_spacing: bpy.props.FloatProperty( + name="Letter Spacing", + description="Letter Spacing", + default=0.0, + ) + font_size: bpy.props.FloatProperty( + name="Font Size", + default=1.0, + subtype='NONE', + ) + translation: bpy.props.FloatVectorProperty( + name="Translation", + default=(0.0, 0.0, 0.0), + subtype='TRANSLATION', + ) + orientation: bpy.props.FloatVectorProperty( + name="Orientation", + default=(1.5707963267948966, 0.0, 0.0), # 90 degrees in radians + subtype='EULER', + ) + + def invoke(self, context, event): + wm = context.window_manager + return wm.invoke_props_dialog(self) def execute(self, context): global shared scene = bpy.context.scene - selected = bpy.context.view_layer.objects.active - abc3d = scene.abc3d abc3d_data = scene.abc3d_data - if abc3d.target_object: - selected = abc3d.target_object + selected = bpy.context.view_layer.objects.active + + # if abc3d.target_object: + # selected = abc3d.target_object if selected: - font = abc3d_data.available_fonts[abc3d_data.active_font_index] - font_name = font.font_name - face_name = font.face_name + # font = abc3d_data.available_fonts[abc3d_data.active_font_index] + # font_name = font.font_name + # face_name = font.face_name distribution_type = 'DEFAULT' @@ -666,14 +703,14 @@ class ABC3D_OT_PlaceText(bpy.types.Operator): t = abc3d_data.available_texts.add() t.text_id = text_id - t.font_name = font_name - t.face_name = face_name + t.font_name = self.font_name + t.face_name = self.face_name t.text_object = selected - t.text = scene.abc3d.text - t.letter_spacing = scene.abc3d.letter_spacing - t.font_size = scene.abc3d.font_size - t.translation = scene.abc3d.translation - t.orientation = scene.abc3d.orientation + t.text = self.text + t.letter_spacing = self.letter_spacing + t.font_size = self.font_size + t.translation = self.translation + t.orientation = self.orientation t.distribution_type = distribution_type else: butils.ShowMessageBox( diff --git a/butils.py b/butils.py index 945ca3a..213e30a 100644 --- a/butils.py +++ b/butils.py @@ -383,18 +383,12 @@ def load_font_from_filepath(filepath): return False abc3d_data = bpy.context.scene.abc3d_data - for f in bpy.context.scene.abc3d_data.available_fonts.values(): - print(f"inside available font: {f.font_name} {f.face_name}") allObjectsBefore = [] for ob in bpy.data.objects: allObjectsBefore.append(ob.name) bpy.ops.import_scene.gltf(filepath=filepath) - print(f"after import available fonts:") - for f in bpy.context.scene.abc3d_data.available_fonts.values(): - print(f"after import available font: {f.font_name} {f.face_name}") - fontcollection = bpy.data.collections.get("ABC3D") if fontcollection is None: fontcollection = bpy.data.collections.new("ABC3D") @@ -710,7 +704,7 @@ def set_text_on_curve(text_properties): # otherwise letters will be closer together the curvier the bezier is # this could be done more efficiently, but whatever curve_compensation = 0 - if text_properties.compensate_curvature: + if text_properties.compensate_curvature and glyph_advance > 0: previous_location = calc_point_on_bezier_curve(mom, advance, False) new_location = calc_point_on_bezier_curve(mom, advance + glyph_advance, False) while (previous_location - new_location).length > glyph_advance: diff --git a/common/Font.py b/common/Font.py index b835424..b8a595e 100644 --- a/common/Font.py +++ b/common/Font.py @@ -171,5 +171,12 @@ def get_glyph(font_name, face_name, glyph_id, alternate=0): def get_loaded_fonts(): return fonts.keys() +def get_loaded_fonts_and_faces(): + out = [] + for f in fonts.keys(): + for ff in fonts[f].faces.keys(): + out.append([f,ff]) + return out + # holds all fonts fonts = {}