I try to get the are_inside
function working from:
https://blender.stackexchange.com/a/80781/21443
No matter what I try, I just get new errors. My scene is as follows:
I don't want to rely on edit mode for selections for the script.
The closest I got is:
import bpy
from mathutils import *
from mathutils.bvhtree import BVHTree
import bmesh
def are_inside(points, bm):
"""
input:
points
- a list of vectors (can also be tuples/lists)
bm
- a manifold bmesh with verts and (edge/faces) for which the
normals are calculated already. (add bm.normal_update() otherwise)
returns:
a list
- a mask lists with True if the point is inside the bmesh, False otherwise
"""
rpoints = []
addp = rpoints.append
bvh = BVHTree.FromBMesh(bm, epsilon=0.0001)
# return points on polygons
for point in points:
fco, normal, _, _ = bvh.find_nearest(point)
p2 = fco - Vector(point)
v = p2.dot(normal)
addp(not v < 0.0) # addp(v >= 0.0) ?
return rpoints
def test():
print("test")
mesh_points = bpy.data.objects['Grid'].to_mesh()
bm_points = bmesh.new()
bm_points.from_mesh(mesh_points)
points = bm_points.verts
mesh = bpy.data.objects['Suzanne'].to_mesh()
bm = bmesh.new()
bm.from_mesh(mesh)
inside = are_inside(points, bm)
test()
How can I get this working?