forked from nortikin/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chek_PointInObject.py
41 lines (29 loc) · 1.02 KB
/
chek_PointInObject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
# Author: Alexander Nedovizin
# A simple check on the entry point (Empty) into the object (Suzanne)
import bpy
import mathutils
print('\n\n***** start *****')
obj = bpy.context.scene.objects['Suzanne']
point = bpy.context.scene.objects['Empty'].location
mesh = obj.data
size = len(mesh.vertices)
kd = mathutils.kdtree.KDTree(size)
for i, p in enumerate(mesh.polygons):
kd.insert(obj.matrix_local * p.center, i)
kd.balance()
flag = True
# Далее находим ближайшие 10 точек в модели и проверим их на нормали
for (co, index, dist) in kd.find_n(point, 10):
p_no = mesh.polygons[index].normal
pt_a = p_no + co
cross_pt = mathutils.geometry.intersect_line_plane(pt_a, point, co, p_no)
if cross_pt:
pose_pt = mathutils.geometry.intersect_point_line(cross_pt, pt_a, point)
if pose_pt[1]>1 or pose_pt[1]<0:
flag = False
break
if flag:
print('is_boundary')
else:
print('not is_boundary')