use iteration to find geometry

master
pullusb 2023-12-07 18:15:11 +01:00
parent 52f92ea103
commit eadd3bb999
1 changed files with 33 additions and 34 deletions

View File

@ -131,7 +131,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
# (vlc, 'hide_viewport', vlc.name not in included_cols), # viewport viz
)
print(f'Preparation {time()-start:.4f}s')
# print(f'Preparation {time()-start:.4f}s')
with attr_set(store_list):
if settings.method == 'BONE':
@ -167,7 +167,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
point_co_world = world_co_3d[i]
object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
##
## Try condition (not needed)
# try:
# object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
# except Exception as e:
@ -179,40 +179,39 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
# print(e)
# return {'CANCELLED'}
## with one extra search
if not object_hit or object_hit not in col.all_objects[:]:
for square_co in search_square(point_co_world, factor=settings.search_range):
object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
if object_hit and object_hit in col.all_objects[:]:
hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
break
### with increasing search range
## with one simple extra search
# if not object_hit or object_hit not in col.all_objects[:]:
# found = False
# for iteration in range(1, 6):
# for square_co in search_square(point_co_world, factor=settings.search_range * iteration):
# object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
# if object_hit and object_hit in col.all_objects[:]:
# hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
# found = True
# # print(f'{si}:{i} iteration {iteration}') # Dbg
# context.scene.cursor.location = square_co
# break
# if found:
# for square_co in search_square(point_co_world, factor=settings.search_range):
# object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
# if object_hit and object_hit in col.all_objects[:]:
# hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
# break
# if not found:
# ## /!\ ERROR ! No surface found!
# # For debugging, select only problematic stroke (and point)
# for sid, s in enumerate(tgt_strokes):
# s.select = sid == si
# for ip, p in enumerate(stroke.points):
# p.select = ip == i
# self.report({'ERROR'}, f'Stroke {si} point {i} could not find underlying geometry')
# return {'CANCELLED'}
### with increasing search range
if not object_hit or object_hit not in col.all_objects[:]:
found = False
for iteration in range(1, 6):
for square_co in search_square(point_co_world, factor=settings.search_range * iteration):
object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
if object_hit and object_hit in col.all_objects[:]:
hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
found = True
# print(f'{si}:{i} iteration {iteration}') # Dbg
break
if found:
break
if not found:
## /!\ ERROR ! No surface found!
# For debugging, select only problematic stroke (and point)
for sid, s in enumerate(tgt_strokes):
s.select = sid == si
for ip, p in enumerate(stroke.points):
p.select = ip == i
self.report({'ERROR'}, f'Stroke {si} point {i} could not find underlying geometry')
return {'CANCELLED'}
stroke_data.append((stroke, point_co_world, object_hit, hit_location, tri, tri_indices))
@ -257,7 +256,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
# except Exception as e:
# print(f'\nCould not apply barycentric tranform {eval_ob.name}')
# print(e)
# bpy.context.scene.cursor.location = hit_location
# # bpy.context.scene.cursor.location = hit_location
# self.report({'ERROR'}, f'Stroke {si} point {i} could not find underlying geometry')
# return {'CANCELLED'}