calculate instead of follow_path
This commit is contained in:
parent
d081d1d42d
commit
62e6c63a61
3 changed files with 82 additions and 16 deletions
42
butils.py
42
butils.py
|
@ -30,14 +30,14 @@ def get_parent_collection_names(collection, parent_names):
|
|||
|
||||
# Ensure it's a curve object
|
||||
# TODO: no raising, please
|
||||
def get_curve_length(curve_obj, num_samples = 100):
|
||||
def get_curve_length(curve_obj, resolution = -1):
|
||||
total_length = 0
|
||||
|
||||
curve = curve_obj.data
|
||||
|
||||
# Loop through all splines in the curve
|
||||
for spline in curve.splines:
|
||||
total_length = total_length + spline.calc_length()
|
||||
total_length = total_length + spline.calc_length(resolution=resolution)
|
||||
|
||||
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_axis = (old_rotation @ local_main_axis).normalized()
|
||||
new_axis = vector
|
||||
# rotation_axis = (-(old_axis) + new_axis).normalized()
|
||||
rotation_axis = old_axis.cross(new_axis).normalized()
|
||||
rotation_axis = (-(old_axis) + new_axis).normalized()
|
||||
# rotation_axis = old_axis.cross(new_axis).normalized()
|
||||
|
||||
if rotation_axis.length < 1e-6:
|
||||
# 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:
|
||||
distance_on_bezier = (distance - iterated_distance)
|
||||
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],
|
||||
beziers[i][1],
|
||||
d)
|
||||
|
@ -386,13 +386,31 @@ def set_text_on_curve(text_properties):
|
|||
|
||||
ob = bpy.data.objects.new(f"{glyph_id}", glyph.data)
|
||||
|
||||
ob.constraints.new(type='FOLLOW_PATH')
|
||||
ob.constraints["Follow Path"].target = mom
|
||||
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"
|
||||
distribution_type = 'CALCULATE'
|
||||
if distribution_type == 'FOLLOW_PATH':
|
||||
ob.constraints.new(type='FOLLOW_PATH')
|
||||
ob.constraints["Follow Path"].target = mom
|
||||
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"
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue