Created
June 3, 2021 16:43
-
-
Save esnosy/21616f2100ccdea736904d5e5e2a919e to your computer and use it in GitHub Desktop.
How to efficiently ray cast static meshes Blender Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from mathutils.bvhtree import BVHTree | |
C = bpy.context | |
# Build BVH once | |
bvh = BVHTree.FromObject(C.object, C.evaluated_depsgraph_get()) | |
for i in range(999999): | |
# Slower, this possibly builds BVH everytime | |
# C.object.ray_cast((0, 0, 0), (0, 0, -1)) | |
# Faster | |
bvh.ray_cast((0, 0, 0), (0, 0, -1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment