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