calculate instead of follow_path

This commit is contained in:
themancalledjakob 2024-07-01 14:39:07 +02:00
parent d081d1d42d
commit 62e6c63a61
3 changed files with 82 additions and 16 deletions

View file

@ -435,7 +435,9 @@ class FONT3D_OT_TestFont(bpy.types.Operator):
ob = bpy.data.objects.new(f"{glyph_id}", glyph.data) ob = bpy.data.objects.new(f"{glyph_id}", glyph.data)
if selected.type == "CURVE": distribution_type = 'CALCULATE'
if selected.type == "CURVE" and distribution_type == 'FOLLOW_PATH':
distribution_type = "FOLLOW_PATH" distribution_type = "FOLLOW_PATH"
curve_length = butils.get_curve_length(selected) curve_length = butils.get_curve_length(selected)
@ -446,9 +448,25 @@ class FONT3D_OT_TestFont(bpy.types.Operator):
ob.constraints["Follow Path"].use_curve_follow = True ob.constraints["Follow Path"].use_curve_follow = True
ob.constraints["Follow Path"].forward_axis = "FORWARD_X" ob.constraints["Follow Path"].forward_axis = "FORWARD_X"
ob.constraints["Follow Path"].up_axis = "UP_Y" ob.constraints["Follow Path"].up_axis = "UP_Y"
# samplecurve = nodes.new(type="GeometryNodeSampleCurve")
# butils.ShowMessageBox("WHAT","INFO","I don't really know what you mean, lsaidry") # 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: else:
offset.x = advance offset.x = advance
ob.location = selected.location + offset ob.location = selected.location + offset
@ -553,7 +571,7 @@ class FONT3D_OT_SaveFontToFile(bpy.types.Operator):
# get save data # get save data
selected_font = font3d_data.available_fonts[font3d_data.active_font_index] selected_font = font3d_data.available_fonts[font3d_data.active_font_index]
print(selected_font.font_name) # print(selected_font.font_name)
self.report({'INFO'}, f"{bl_info['name']}: {selected_font.font_name}") self.report({'INFO'}, f"{bl_info['name']}: {selected_font.font_name}")
preferences = getPreferences(context) preferences = getPreferences(context)
print(f"assets folder: {preferences.assets_dir}") print(f"assets folder: {preferences.assets_dir}")
@ -673,6 +691,35 @@ class FONT3D_OT_CreateFontFromObjects(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
scene = context.scene
font3d = scene.font3d
font3d_data = scene.font3d_data
obj = context.active_object
row = layout.row()
row.label(text="Hello world!", icon='WORLD_DATA')
row = layout.row()
row.label(text="Active object is: " + obj.name)
row = layout.row()
row.prop(obj, "location")
row = layout.row()
row.operator("mesh.primitive_cube_add")
classes = ( classes = (
FONT3D_addonPreferences, FONT3D_addonPreferences,
FONT3D_OT_Font3D, FONT3D_OT_Font3D,
@ -691,6 +738,7 @@ classes = (
FONT3D_OT_ToggleFont3DCollection, FONT3D_OT_ToggleFont3DCollection,
FONT3D_OT_SaveFontToFile, FONT3D_OT_SaveFontToFile,
FONT3D_OT_CreateFontFromObjects, FONT3D_OT_CreateFontFromObjects,
HelloWorldPanel,
) )
def register(): def register():

View file

@ -30,14 +30,14 @@ def get_parent_collection_names(collection, parent_names):
# Ensure it's a curve object # Ensure it's a curve object
# TODO: no raising, please # TODO: no raising, please
def get_curve_length(curve_obj, num_samples = 100): def get_curve_length(curve_obj, resolution = -1):
total_length = 0 total_length = 0
curve = curve_obj.data curve = curve_obj.data
# Loop through all splines in the curve # Loop through all splines in the curve
for spline in curve.splines: for spline in curve.splines:
total_length = total_length + spline.calc_length() total_length = total_length + spline.calc_length(resolution=resolution)
return total_length return total_length
@ -74,8 +74,8 @@ def align_rotations_auto_pivot(mask, input_rotations, vectors, factors, local_ma
old_rotation = input_rotation.to_matrix() old_rotation = input_rotation.to_matrix()
old_axis = (old_rotation @ local_main_axis).normalized() old_axis = (old_rotation @ local_main_axis).normalized()
new_axis = vector new_axis = vector
# rotation_axis = (-(old_axis) + new_axis).normalized() rotation_axis = (-(old_axis) + new_axis).normalized()
rotation_axis = old_axis.cross(new_axis).normalized() # rotation_axis = old_axis.cross(new_axis).normalized()
if rotation_axis.length < 1e-6: if rotation_axis.length < 1e-6:
# Vectors are linearly dependent, fallback to another axis # Vectors are linearly dependent, fallback to another axis
@ -163,7 +163,7 @@ def calc_point_on_bezier_spline(bezier_spline_obj,
if iterated_distance + lengths[i] > distance: if iterated_distance + lengths[i] > distance:
distance_on_bezier = (distance - iterated_distance) distance_on_bezier = (distance - iterated_distance)
d = distance_on_bezier / lengths[i] d = distance_on_bezier / lengths[i]
print(f"i: {i}, d: {d}, distance_on_bezier: {distance_on_bezier}, distance: {distance}") # print(f"i: {i}, d: {d}, distance_on_bezier: {distance_on_bezier}, distance: {distance}")
location = calc_point_on_bezier(beziers[i][0], location = calc_point_on_bezier(beziers[i][0],
beziers[i][1], beziers[i][1],
d) d)
@ -386,13 +386,31 @@ def set_text_on_curve(text_properties):
ob = bpy.data.objects.new(f"{glyph_id}", glyph.data) ob = bpy.data.objects.new(f"{glyph_id}", glyph.data)
ob.constraints.new(type='FOLLOW_PATH') distribution_type = 'CALCULATE'
ob.constraints["Follow Path"].target = mom if distribution_type == 'FOLLOW_PATH':
ob.constraints["Follow Path"].use_fixed_location = True ob.constraints.new(type='FOLLOW_PATH')
ob.constraints["Follow Path"].offset_factor = advance / curve_length ob.constraints["Follow Path"].target = mom
ob.constraints["Follow Path"].use_curve_follow = True ob.constraints["Follow Path"].use_fixed_location = True
ob.constraints["Follow Path"].forward_axis = "FORWARD_X" ob.constraints["Follow Path"].offset_factor = advance / curve_length
ob.constraints["Follow Path"].up_axis = "UP_Y" ob.constraints["Follow Path"].use_curve_follow = True
ob.constraints["Follow Path"].forward_axis = "FORWARD_X"
ob.constraints["Follow Path"].up_axis = "UP_Y"
elif distribution_type == 'CALCULATE':
location, tangent = calc_point_on_bezier_curve(mom, advance, True)
ob.location = mom.matrix_world @ location
mask = [0]
input_rotations = [mathutils.Vector((radians(90.0), 0.0, 0.0))]
vectors = [tangent]
factors = [1.0]
local_main_axis = mathutils.Vector((1.0, 0.0, 0.0))
motor = align_rotations_auto_pivot(mask,
input_rotations,
vectors,
factors,
local_main_axis)
if ob.rotation_mode != 'QUATERNION':
ob.rotation_mode = 'QUATERNION'
ob.rotation_quaternion = (mom.matrix_world @ motor[0]).to_quaternion()
scalor = 0.001 scalor = 0.001

View file

@ -97,7 +97,7 @@ def get_glyph(font_name, face_name, glyph_id):
:return: returns the glyph object, or ``None`` if it does not exist :return: returns the glyph object, or ``None`` if it does not exist
:rtype: `Object` :rtype: `Object`
""" """
print(fonts) # print(fonts)
if not fonts.keys().__contains__(font_name): if not fonts.keys().__contains__(font_name):
print(f"FONT3D::get_glyph: font name({font_name}) not found") print(f"FONT3D::get_glyph: font name({font_name}) not found")
print(fonts.keys()) print(fonts.keys())