simplify placement
This commit is contained in:
parent
409e06bd44
commit
4d0c42adb3
3 changed files with 78 additions and 40 deletions
103
__init__.py
103
__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(
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in a new issue