Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Created May 12, 2023 14:22
Show Gist options
  • Save SuddenDevelopment/d5d0595e22c7ec37f0a8c81aec5b23d0 to your computer and use it in GitHub Desktop.
Save SuddenDevelopment/d5d0595e22c7ec37f0a8c81aec5b23d0 to your computer and use it in GitHub Desktop.
In Blender Python test for a clear path between 2 points
def isClearPath(vert1, vert2, depsgraph):
# Test if there are any obstructions from vert 1 to vert 2 until it reaches obj2
# test for given clearance around the ray traced path with 6 parallel line a given distance of clearnace away from original path t test fo
# isClear = isClearPath(vert1, vert2, depsgraph)
# Calculate the direction vector from vert1 to vert2
direction_vector = vert2 - vert1
# Normalize the direction vector
direction = direction_vector.normalized()
# Calculate the distance between vert1 and vert2, subtracting the offset
distance = direction_vector.length
# Apply the offset to avoid self-intersection with vert1
start_point = vert1 + direction
result, location, normal, index, object, matrix = custom_ray_cast(bpy.context.scene, depsgraph, start_point, direction, 0.1, 5, distance=distance)
#result, location, normal, index, object, matrix = bpy.context.scene.ray_cast(depsgraph, start_point, direction, distance=distance)
# If any of the rays hit an object other than obj2, return False
if location != vert2:
return False
# If all rays hit obj2 or didn't hit any objects, return True
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment