From bb0a5a4a2ce96acb5c0c9b8c811ba34322cfbeec Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Sat, 31 May 2025 19:57:11 +0200 Subject: [PATCH] add testing scripts --- testing_scripts/bezier_distance.py | 25 +++++++ testing_scripts/unload_glyphs.py | 115 +++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 testing_scripts/bezier_distance.py create mode 100644 testing_scripts/unload_glyphs.py diff --git a/testing_scripts/bezier_distance.py b/testing_scripts/bezier_distance.py new file mode 100644 index 0000000..5557a6b --- /dev/null +++ b/testing_scripts/bezier_distance.py @@ -0,0 +1,25 @@ +import bpy +from mathutils import * +from math import * +import abc3d.butils + +v = 0 +goal = 5.0 +step = 0.1 +speed = 1.0 + +C = bpy.context +obj = C.scene.objects['Cube'] +curve = C.scene.objects['BézierCurve'] + +m = curve.matrix + +def fun(distance): + obj.location = m @ abc3d.butils.calc_point_on_bezier_curve(curve, + distance, + output_tangent=True) + print(f"executed {distance}") + +while v < goal: + bpy.app.timers.register(lambda: fun(v), first_interval=(v * speed)) + v += step diff --git a/testing_scripts/unload_glyphs.py b/testing_scripts/unload_glyphs.py new file mode 100644 index 0000000..3802a58 --- /dev/null +++ b/testing_scripts/unload_glyphs.py @@ -0,0 +1,115 @@ +import bpy + +import abc3d +from abc3d import butils +from abc3d.common import Font + + +def get_text_properties_by_mom(mom): + scene = bpy.context.scene + abc3d_data = scene.abc3d_data + + for text_properties in abc3d_data.available_texts: + if mom == text_properties.text_object: + return text_properties + return None + + +def isolate_objects(objects): + for area in bpy.context.window.screen.areas: + if area.type == "VIEW_3D": + with bpy.context.temp_override( + selected_objects=list(objects), + area=area, + refgion=[region for region in area.regions if region.type == "WINDOW"][ + 0 + ], + screen=bpy.context.window.screen, + ): + # bpy.ops.view3d.view_selected() + bpy.ops.view3d.localview(frame_selected=True) + break + + +def main(): + # create a curve + bpy.ops.curve.primitive_bezier_curve_add( + radius=1, + enter_editmode=False, + align="WORLD", + location=(0, 0, 0), + scale=(1, 1, 1), + ) + # new curve is active object + mom = bpy.context.active_object + + # make sure + print(f"MOM: {mom.name}") + + fonts = Font.get_loaded_fonts_and_faces() + if len(fonts) == 0: + print("no fonts! what?") + return + + font_name = fonts[0][0] + face_name = fonts[0][1] + font = f"{font_name} {face_name}" + + isolate_objects([mom]) + + bpy.ops.abc3d.placetext( + font_name=font_name, + face_name=face_name, + font=font, + text="SOMETHING SOMETHING BROKEN ARMS", + letter_spacing=0, + font_size=1, + offset=0, + translation=(0, 0, 0), + orientation=(1.5708, 0, 0), + ) + + def change_text(font_name="", face_name="", text=""): + print(f"change_text to '{text}'") + text_properties = get_text_properties_by_mom(mom) + if font_name != "": + text_properties["font_name"] = font_name + if face_name != "": + text_properties["face_name"] = face_name + if text != "": + text_properties.text = text + else: + text_properties.text = text_properties.text + return None + + def unload(glyph_id): + print(f"unload glyph '{glyph_id}'") + butils.unload_unused_glyph(font_name, face_name, glyph_id) + return None + + def unload_all(): + print(f"unload glyph all unused glyphs") + butils.unload_unused_glyphs() + return None + + bpy.app.timers.register(lambda: change_text(text="SOMETHING"), first_interval=0) + bpy.app.timers.register(lambda: change_text(text="LOLSS"), first_interval=2) + bpy.app.timers.register(lambda: change_text(text="LOLAA"), first_interval=3) + bpy.app.timers.register(lambda: change_text(text="WHAT"), first_interval=4) + bpy.app.timers.register(lambda: change_text(text="LOL"), first_interval=5) + + bpy.app.timers.register(lambda: unload("A"), first_interval=10) + bpy.app.timers.register(lambda: unload_all(), first_interval=12) + + bpy.app.timers.register(lambda: change_text(text="LOLM"), first_interval=16) + bpy.app.timers.register(lambda: change_text(text="ZHE END"), first_interval=20) + + bpy.app.timers.register( + lambda: change_text(font_name="NM_Origin", face_name="Tender"), + first_interval=30, + ) + + bpy.app.timers.register(lambda: unload_all(), first_interval=42) + + +main()