autoremove text_objects and newline

This commit is contained in:
jrkb 2024-07-02 12:22:24 +02:00
parent 62e6c63a61
commit 8bcb252087
2 changed files with 46 additions and 73 deletions

View file

@ -167,6 +167,7 @@ class FONT3D_glyph_properties(bpy.types.PropertyGroup):
class FONT3D_text_properties(bpy.types.PropertyGroup):
def update_callback(self, context):
butils.set_text_on_curve(self)
text_index: bpy.props.IntProperty()
font_name: bpy.props.StringProperty()
font_face: bpy.props.StringProperty()
text_object: bpy.props.PointerProperty(type=bpy.types.Object)
@ -245,6 +246,14 @@ class FONT3D_PT_panel(bpy.types.Panel):
for i, t in enumerate(font3d_data.available_texts):
if type(t.text_object) == type(None):
remove_list.append(i)
continue
remove_me = True
for c in t.text_object.children:
if len(c.users_collection) > 0 and (c.get('linked_textobject')) != type(None) and c.get('linked_textobject') == t.text_index:
remove_me = False
if remove_me:
remove_list.append(i)
for i in remove_list:
font3d_data.available_texts.remove(i)
@ -414,82 +423,14 @@ class FONT3D_OT_TestFont(bpy.types.Operator):
font_name = "NM_Origin"
font_face = "Tender"
# text_text_object = bpy.data.objects.new(f"{selected.name}_text", None)
# text_text_object.empty_display_type = 'PLAIN_AXES'
# selected.users_collection[0].objects.link(text_text_object)
distribution_type = 'DEFAULT'
bpy.ops.object.select_all(action='DESELECT')
t = font3d_data.available_texts.add()
offset = mathutils.Vector((0.0, 0.0, 0.0))
advance = 0
for i, c in enumerate(scene.font3d.test_text):
glyph_id = c
glyph = Font.get_glyph(font_name, font_face, glyph_id)
if glyph == None:
self.report({'ERROR'}, f"Glyph not found for {font_name} {font_face} {glyph_id}")
continue
ob = bpy.data.objects.new(f"{glyph_id}", glyph.data)
distribution_type = 'CALCULATE'
if selected.type == "CURVE" and distribution_type == 'FOLLOW_PATH':
distribution_type = "FOLLOW_PATH"
curve_length = butils.get_curve_length(selected)
ob.constraints.new(type='FOLLOW_PATH')
ob.constraints["Follow Path"].target = selected
ob.constraints["Follow Path"].use_fixed_location = True
ob.constraints["Follow Path"].offset_factor = advance / curve_length
ob.constraints["Follow Path"].use_curve_follow = True
ob.constraints["Follow Path"].forward_axis = "FORWARD_X"
ob.constraints["Follow Path"].up_axis = "UP_Y"
# butils.ShowMessageBox("WHAT","INFO","I don't really know what you mean, lsaidry")
elif selected.type == "CURVE" and distribution_type == 'CALCULATE':
location, tangent = butils.calc_point_on_bezier_curve(selected, advance, True)
ob.location = selected.matrix_world @ location
mask = [0]
input_rotations = [mathutils.Vector((0.0, 0.0, 0.0))]
vectors = [tangent]
factors = [1.0]
local_main_axis = mathutils.Vector((1.0, 0.0, 0.0))
motor = butils.align_rotations_auto_pivot(mask,
input_rotations,
vectors,
factors,
local_main_axis)
ob.rotation_quaternion = (selected.matrix_world @ motor[0]).to_quaternion()
print("what")
else:
offset.x = advance
ob.location = selected.location + offset
scalor = 0.001
glyph_advance = (-1 * glyph.bound_box[0][0] + glyph.bound_box[4][0]) * scalor
ob.scale = (scalor, scalor, scalor)
selected.users_collection[0].objects.link(ob)
advance = advance + glyph_advance
tc = t.glyphs.add()
tc.glyph_id = c
tc.glyph_object = ob
tc.letter_spacing = 0
ob.select_set(True)
selected.select_set(True)
bpy.context.view_layer.objects.active = selected
bpy.ops.object.parent_set(type='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
text_index = 0
for i, tt in enumerate(font3d_data.available_texts):
while text_index == tt.text_index:
text_index = text_index + 1
t.text_index = text_index
t.font_name = font_name
t.font_face = font_face