transfer glyph transforms on duplication
This commit is contained in:
parent
2ace31a246
commit
8f3d58aad0
2 changed files with 54 additions and 14 deletions
24
__init__.py
24
__init__.py
|
@ -284,17 +284,19 @@ class ABC3D_data(bpy.types.PropertyGroup):
|
|||
|
||||
def active_text_index_update(self, context):
|
||||
if self.active_text_index != -1:
|
||||
o = self.available_texts[self.active_text_index].text_object
|
||||
# active_text_index changed. so let's update the selection
|
||||
# check if it is already selected
|
||||
# or perhaps one of the glyphs
|
||||
if (
|
||||
not o.select_get()
|
||||
and not len([c for c in o.children if c.select_get()]) > 0
|
||||
):
|
||||
bpy.ops.object.select_all(action="DESELECT")
|
||||
o.select_set(True)
|
||||
bpy.context.view_layer.objects.active = o
|
||||
text_properties = butils.get_text_properties(self.active_text_index, context.scene)
|
||||
if text_properties is not None:
|
||||
o = text_properties.text_object
|
||||
# active_text_index changed. so let's update the selection
|
||||
# check if it is already selected
|
||||
# or perhaps one of the glyphs
|
||||
if (o is not None
|
||||
and not o.select_get()
|
||||
and not len([c for c in o.children if c.select_get()]) > 0
|
||||
):
|
||||
bpy.ops.object.select_all(action="DESELECT")
|
||||
o.select_set(True)
|
||||
context.view_layer.objects.active = o
|
||||
# else:
|
||||
# print("already selected")
|
||||
|
||||
|
|
44
butils.py
44
butils.py
|
@ -772,6 +772,15 @@ def prepare_text(font_name, face_name, text, allow_replacement=True):
|
|||
load_font_from_filepath(filepath, loadable, font_name, face_name)
|
||||
return True
|
||||
|
||||
def predict_actual_text(text_properties):
|
||||
availability = Font.test_availability(text_properties.font_name, text_properties.face_name, text_properties.text)
|
||||
AVAILABILITY = Font.test_availability(text_properties.font_name, text_properties.face_name, text_properties.text.swapcase())
|
||||
t_text = text_properties.text
|
||||
for c in availability["missing"]:
|
||||
t_text = t_text.replace(c, "")
|
||||
for c in AVAILABILITY["missing"]:
|
||||
t_text = t_text.replace(c, "")
|
||||
return t_text
|
||||
|
||||
def is_bezier(curve):
|
||||
if curve.type != "CURVE":
|
||||
|
@ -936,6 +945,25 @@ def get_text_properties(text_id, scene = None):
|
|||
return t
|
||||
return None
|
||||
|
||||
def duplicate(obj, data=True, actions=True, add_to_collection=True, collection=None, recursive=True):
|
||||
obj_copy = obj.copy()
|
||||
if add_to_collection:
|
||||
if collection:
|
||||
collection.objects.link(obj_copy)
|
||||
elif len(obj.users_collection) > 0:
|
||||
obj.users_collection[0].objects.link(obj_copy)
|
||||
if data and obj.data:
|
||||
obj_copy.data = obj.data.copy()
|
||||
if actions and obj.animation_data:
|
||||
obj_copy.animation_data.action = obj.animation_data.action.copy()
|
||||
if recursive and hasattr(obj, "children"):
|
||||
for child in obj.children:
|
||||
child_copy = duplicate(child)
|
||||
child_copy.parent_type = child.parent_type
|
||||
child_copy.parent = obj_copy
|
||||
# child_copy.matrix_parent_inverse = obj_copy.matrix_world.inverted()
|
||||
return obj_copy
|
||||
|
||||
def transfer_text_object_to_text_properties(text_object, text_properties, id_from_text_properties=True):
|
||||
print("TRANSFER:: BEGIN")
|
||||
print(f" {text_properties['text_id']=}")
|
||||
|
@ -957,9 +985,18 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
|
|||
print(f" {text_properties['offset']=}")
|
||||
|
||||
if len(text_object.children) == 0:
|
||||
print("could be duplicate?")
|
||||
print("ccccccccccccccccccccccccccccccccc ccccc ccccc c c c c ccould be duplicate?")
|
||||
if possible_brother_text_id != text_properties["text_id"] and possible_brother_text_id != "":
|
||||
pass
|
||||
possible_brother_properties = get_text_properties(possible_brother_text_id)
|
||||
possible_brother_object = possible_brother_properties.text_object
|
||||
if possible_brother_object is not None:
|
||||
for child in possible_brother_object.children:
|
||||
if is_glyph_object(child):
|
||||
child_copy = duplicate(child)
|
||||
child_copy.parent_type = child.parent_type
|
||||
child_copy.parent = text_object
|
||||
parent_to_curve(child_copy, text_object)
|
||||
# child_copy.matrix_parent_inverse = text_object.matrix_world.inverted()
|
||||
|
||||
found_reconstructable_glyphs = False
|
||||
glyph_objects_with_indices = []
|
||||
|
@ -1155,7 +1192,8 @@ def transfer_glyph_object_to_glyph_properties(glyph_object, glyph_properties):
|
|||
import inspect
|
||||
def would_regenerate(text_properties):
|
||||
print("REGENERATE?")
|
||||
if len(text_properties.actual_text) != len(text_properties.glyphs):
|
||||
predicted_text = predict_actual_text(text_properties)
|
||||
if text_properties.actual_text != predicted_text:
|
||||
print(inspect.currentframe().f_lineno)
|
||||
return True
|
||||
if len(text_properties.glyphs) == 0:
|
||||
|
|
Loading…
Add table
Reference in a new issue