Blender
V3.3
|
#include <Python.h>
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
#include "BLI_kdopbvh.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_polyfill_2d.h"
#include "BLI_utildefines.h"
#include "BKE_bvhutils.h"
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
#include "mathutils.h"
#include "mathutils_bvhtree.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "BKE_customdata.h"
#include "BKE_editmesh_bvh.h"
#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "DEG_depsgraph_query.h"
#include "bmesh.h"
#include "../bmesh/bmesh_py_types.h"
#include "BLI_strict_flags.h"
Go to the source code of this file.
Classes | |
struct | PyBVHTree |
struct | PyBVH_RangeData |
struct | PyBVHTree_OverlapData |
Macros | |
#define | PYBVH_MAX_DIST_STR "1.84467e+19" |
Documentation String (snippets) | |
#define | PYBVH_FIND_GENERIC_DISTANCE_DOC |
#define | PYBVH_FIND_GENERIC_RETURN_DOC |
#define | PYBVH_FIND_GENERIC_RETURN_LIST_DOC |
#define | PYBVH_FROM_GENERIC_EPSILON_DOC |
Functions | |
static void | py_bvhtree__tp_dealloc (PyBVHTree *self) |
Utility helper functions | |
static PyObject * | bvhtree_CreatePyObject (BVHTree *tree, float epsilon, float(*coords)[3], uint coords_len, uint(*tris)[3], uint tris_len, int *orig_index, float(*orig_normal)[3]) |
BVHTreeRayHit to Python utilities | |
static void | py_bvhtree_raycast_to_py_tuple (const BVHTreeRayHit *hit, PyObject *py_retval) |
static PyObject * | py_bvhtree_raycast_to_py (const BVHTreeRayHit *hit) |
static PyObject * | py_bvhtree_raycast_to_py_none (void) |
BVHTreeNearest to Python utilities | |
static void | py_bvhtree_nearest_to_py_tuple (const BVHTreeNearest *nearest, PyObject *py_retval) |
static PyObject * | py_bvhtree_nearest_to_py (const BVHTreeNearest *nearest) |
static PyObject * | py_bvhtree_nearest_to_py_none (void) |
Methods | |
static void | py_bvhtree_raycast_cb (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) |
static void | py_bvhtree_nearest_point_cb (void *userdata, int index, const float co[3], BVHTreeNearest *nearest) |
PyDoc_STRVAR (py_bvhtree_ray_cast_doc, ".. method:: ray_cast(origin, direction, distance=sys.float_info.max)\n" "\n" " Cast a ray onto the mesh.\n" "\n" " :arg origin: Start location of the ray in object space.\n" " :type origin: :class:`Vector`\n" " :arg direction: Direction of the ray in object space.\n" " :type direction: :class:`Vector`\n" PYBVH_FIND_GENERIC_DISTANCE_DOC PYBVH_FIND_GENERIC_RETURN_DOC) | |
static PyObject * | py_bvhtree_ray_cast (PyBVHTree *self, PyObject *args) |
PyDoc_STRVAR (py_bvhtree_find_nearest_doc, ".. method:: find_nearest(origin, distance=" PYBVH_MAX_DIST_STR ")\n" "\n" " Find the nearest element (typically face index) to a point.\n" "\n" " :arg co: Find nearest element to this point.\n" " :type co: :class:`Vector`\n" PYBVH_FIND_GENERIC_DISTANCE_DOC PYBVH_FIND_GENERIC_RETURN_DOC) | |
static PyObject * | py_bvhtree_find_nearest (PyBVHTree *self, PyObject *args) |
static void | py_bvhtree_nearest_point_range_cb (void *userdata, int index, const float co[3], float UNUSED(dist_sq_bvh)) |
PyDoc_STRVAR (py_bvhtree_find_nearest_range_doc, ".. method:: find_nearest_range(origin, distance=" PYBVH_MAX_DIST_STR ")\n" "\n" " Find the nearest elements (typically face index) to a point in the distance range.\n" "\n" " :arg co: Find nearest elements to this point.\n" " :type co: :class:`Vector`\n" PYBVH_FIND_GENERIC_DISTANCE_DOC PYBVH_FIND_GENERIC_RETURN_LIST_DOC) | |
static PyObject * | py_bvhtree_find_nearest_range (PyBVHTree *self, PyObject *args) |
BLI_INLINE uint | overlap_hash (const void *overlap_v) |
BLI_INLINE bool | overlap_cmp (const void *a_v, const void *b_v) |
static bool | py_bvhtree_overlap_cb (void *userdata, int index_a, int index_b, int UNUSED(thread)) |
PyDoc_STRVAR (py_bvhtree_overlap_doc, ".. method:: overlap(other_tree)\n" "\n" " Find overlapping indices between 2 trees.\n" "\n" " :arg other_tree: Other tree to perform overlap test on.\n" " :type other_tree: :class:`BVHTree`\n" " :return: Returns a list of unique index pairs," " the first index referencing this tree, the second referencing the **other_tree**.\n" " :rtype: :class:`list`\n") | |
static PyObject * | py_bvhtree_overlap (PyBVHTree *self, PyBVHTree *other) |
Class Methods | |
PyDoc_STRVAR (C_BVHTree_FromPolygons_doc, ".. classmethod:: FromPolygons(vertices, polygons, all_triangles=False, epsilon=0.0)\n" "\n" " BVH tree constructed geometry passed in as arguments.\n" "\n" " :arg vertices: float triplets each representing ``(x, y, z)``\n" " :type vertices: float triplet sequence\n" " :arg polygons: Sequence of polyugons, each containing indices to the vertices argument.\n" " :type polygons: Sequence of sequences containing ints\n" " :arg all_triangles: Use when all **polygons** are triangles for more efficient " "conversion.\n" " :type all_triangles: bool\n" PYBVH_FROM_GENERIC_EPSILON_DOC) | |
static PyObject * | C_BVHTree_FromPolygons (PyObject *UNUSED(cls), PyObject *args, PyObject *kwargs) |
PyDoc_STRVAR (C_BVHTree_FromBMesh_doc, ".. classmethod:: FromBMesh(bmesh, epsilon=0.0)\n" "\n" " BVH tree based on :class:`BMesh` data.\n" "\n" " :arg bmesh: BMesh data.\n" " :type bmesh: :class:`BMesh`\n" PYBVH_FROM_GENERIC_EPSILON_DOC) | |
static PyObject * | C_BVHTree_FromBMesh (PyObject *UNUSED(cls), PyObject *args, PyObject *kwargs) |
static Mesh * | bvh_get_mesh (const char *funcname, struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, const bool use_deform, const bool use_cage, bool *r_free_mesh) |
PyDoc_STRVAR (C_BVHTree_FromObject_doc, ".. classmethod:: FromObject(object, depsgraph, deform=True, render=False, " "cage=False, epsilon=0.0)\n" "\n" " BVH tree based on :class:`Object` data.\n" "\n" " :arg object: Object data.\n" " :type object: :class:`Object`\n" " :arg depsgraph: Depsgraph to use for evaluating the mesh.\n" " :type depsgraph: :class:`Depsgraph`\n" " :arg deform: Use mesh with deformations.\n" " :type deform: bool\n" " :arg cage: Use modifiers cage.\n" " :type cage: bool\n" PYBVH_FROM_GENERIC_EPSILON_DOC) | |
static PyObject * | C_BVHTree_FromObject (PyObject *UNUSED(cls), PyObject *args, PyObject *kwargs) |
Variables | |
static const float | max_dist_default = 1.844674352395373e+19f |
static const char | PY_BVH_TREE_TYPE_DEFAULT = 4 |
static const char | PY_BVH_AXIS_DEFAULT = 6 |
Module & Type definition | |
static PyMethodDef | py_bvhtree_methods [] |
PyTypeObject | PyBVHTree_Type |
static struct PyModuleDef | bvhtree_moduledef |
PyDoc_STRVAR (py_bvhtree_doc, "BVH tree structures for proximity searches and ray casts on geometry.") | |
PyMODINIT_FUNC | PyInit_mathutils_bvhtree (void) |
This file defines the 'mathutils.bvhtree' module, a general purpose module to access blenders bvhtree for mesh surface nearest-element search and ray casting.
Definition in file mathutils_bvhtree.c.
#define PYBVH_FIND_GENERIC_DISTANCE_DOC |
Definition at line 53 of file mathutils_bvhtree.c.
#define PYBVH_FIND_GENERIC_RETURN_DOC |
Definition at line 57 of file mathutils_bvhtree.c.
#define PYBVH_FIND_GENERIC_RETURN_LIST_DOC |
Definition at line 63 of file mathutils_bvhtree.c.
#define PYBVH_FROM_GENERIC_EPSILON_DOC |
Definition at line 68 of file mathutils_bvhtree.c.
#define PYBVH_MAX_DIST_STR "1.84467e+19" |
Definition at line 75 of file mathutils_bvhtree.c.
|
static |
Definition at line 1014 of file mathutils_bvhtree.c.
References CD_MASK_BAREMESH, DAG_EVAL_RENDER, DEG_get_evaluated_object(), DEG_get_mode(), depsgraph, mesh_create_eval_final(), mesh_create_eval_no_deform(), mesh_create_eval_no_deform_render(), mesh_get_eval_deform(), mesh_get_eval_final(), NULL, and scene.
Referenced by C_BVHTree_FromObject().
|
static |
Definition at line 101 of file mathutils_bvhtree.c.
References blender::robust_pred::epsilon, PyBVHTree_Type, result, and tree.
Referenced by C_BVHTree_FromBMesh(), C_BVHTree_FromObject(), and C_BVHTree_FromPolygons().
|
static |
Definition at line 923 of file mathutils_bvhtree.c.
References BLI_bvhtree_balance(), BLI_bvhtree_insert(), BLI_bvhtree_new(), bm, BPy_BMesh::bm, BM_elem_index_get, BM_elem_index_set, BM_FACE, BM_FACES_OF_MESH, BM_ITER_MESH_INDEX, BM_mesh_calc_tessellation(), BM_VERT, BM_VERTS_OF_MESH, BPy_BMesh_Type, bvhtree_CreatePyObject(), BMVert::co, copy_v3_v3(), BMesh::elem_index_dirty, blender::robust_pred::epsilon, float(), MEM_freeN, MEM_mallocN, BMFace::no, NULL, poly_to_tri_count(), PY_BVH_AXIS_DEFAULT, PY_BVH_TREE_TYPE_DEFAULT, BMesh::totface, BMesh::totloop, BMesh::totvert, tree, and v.
|
static |
Definition at line 1096 of file mathutils_bvhtree.c.
References BKE_id_free(), BKE_mesh_poly_normals_are_dirty(), BKE_mesh_poly_normals_ensure(), BKE_mesh_runtime_looptri_ensure(), BKE_mesh_runtime_looptri_len(), BLI_bvhtree_balance(), BLI_bvhtree_insert(), BLI_bvhtree_new(), bvh_get_mesh(), bvhtree_CreatePyObject(), copy_v3_v3(), DEG_get_evaluated_scene(), depsgraph, blender::robust_pred::epsilon, float(), MEM_dupallocN, MEM_mallocN, mesh, Mesh::mloop, Mesh::mvert, NULL, MLoopTri::poly, PY_BVH_AXIS_DEFAULT, PY_BVH_TREE_TYPE_DEFAULT, PyC_ParseBool(), PyC_RNA_AsPointer(), scene, Mesh::totvert, tree, MLoopTri::tri, and MLoop::v.
|
static |
Definition at line 641 of file mathutils_bvhtree.c.
References add_newell_cross_v3_v3v3(), axis_dominant_v3_to_m3_negate(), BLI_bvhtree_balance(), BLI_bvhtree_insert(), BLI_bvhtree_new(), BLI_memarena_alloc(), BLI_memarena_clear(), BLI_memarena_free(), BLI_memarena_new(), BLI_MEMARENA_STD_BUFSIZE, BLI_POLYFILL_ARENA_SIZE, BLI_polyfill_calc_arena(), bvhtree_CreatePyObject(), copy_v3_v3(), blender::robust_pred::epsilon, float(), len, mathutils_array_parse(), MEM_freeN, MEM_mallocN, mul_v2_m3v3(), next, normal, normal_tri_v3(), normalize_v3(), NULL, PY_BVH_AXIS_DEFAULT, PY_BVH_TREE_TYPE_DEFAULT, PyC_Long_AsU32(), PyC_ParseBool(), tree, UNLIKELY, and zero_v3().
BLI_INLINE bool overlap_cmp | ( | const void * | a_v, |
const void * | b_v | ||
) |
Definition at line 499 of file mathutils_bvhtree.c.
References Freestyle::a, and usdtokens::b().
Referenced by py_bvhtree_overlap().
BLI_INLINE uint overlap_hash | ( | const void * | overlap_v | ) |
Definition at line 492 of file mathutils_bvhtree.c.
References BVHTreeOverlap::indexA.
Referenced by py_bvhtree_overlap().
Definition at line 239 of file mathutils_bvhtree.c.
References BLI_bvhtree_free(), MEM_SAFE_FREE, and self.
|
static |
Definition at line 375 of file mathutils_bvhtree.c.
References BLI_bvhtree_find_nearest(), BVHTreeNearest::dist_sq, BVHTreeNearest::index, mathutils_array_parse(), max_dist_default, MU_ARRAY_ZERO, NULL, py_bvhtree_nearest_point_cb(), py_bvhtree_nearest_to_py(), py_bvhtree_nearest_to_py_none(), and self.
|
static |
Definition at line 458 of file mathutils_bvhtree.c.
References BLI_bvhtree_range_query(), data, mathutils_array_parse(), max_dist_default, MU_ARRAY_ZERO, NULL, py_bvhtree_nearest_point_range_cb(), ret, self, and square_f().
|
static |
Definition at line 290 of file mathutils_bvhtree.c.
Referenced by py_bvhtree_find_nearest().
|
static |
Definition at line 416 of file mathutils_bvhtree.c.
References closest_on_tri_to_point_v3(), BVHTreeNearest::co, copy_v3_v3(), data, BVHTreeNearest::dist_sq, PyBVH_RangeData::dist_sq, float(), BVHTreeNearest::index, len_squared_v3v3(), BVHTreeNearest::no, normal_tri_v3(), py_bvhtree_nearest_to_py(), self, and UNPACK3.
Referenced by py_bvhtree_find_nearest_range().
|
static |
Definition at line 201 of file mathutils_bvhtree.c.
References py_bvhtree_nearest_to_py_tuple().
Referenced by py_bvhtree_find_nearest(), and py_bvhtree_nearest_point_range_cb().
|
static |
Definition at line 210 of file mathutils_bvhtree.c.
References PyC_Tuple_Fill().
Referenced by py_bvhtree_find_nearest().
|
static |
Definition at line 189 of file mathutils_bvhtree.c.
References BLI_assert, BVHTreeNearest::co, BVHTreeNearest::dist_sq, BVHTreeNearest::index, BVHTreeNearest::no, NULL, PyTuple_SET_ITEMS, sqrtf, and Vector_CreatePyObject().
Referenced by py_bvhtree_nearest_to_py().
Definition at line 554 of file mathutils_bvhtree.c.
References BLI_bvhtree_overlap(), BLI_gset_add(), BLI_gset_free(), BLI_gset_new_ex(), data, PyBVHTree::epsilon, max_ff(), MEM_freeN, NULL, PyBVHTree::orig_index, overlap_cmp(), overlap_hash(), py_bvhtree_overlap_cb(), PyBVHTree_CheckExact, PyTuple_SET_ITEMS, ret, self, and PyBVHTree::tree.
|
static |
Definition at line 511 of file mathutils_bvhtree.c.
References PyBVHTree::coords, data, ELEM, isect_tri_tri_v3(), len_squared_v3v3(), PyBVHTree::tris, UNLIKELY, and UNPACK3.
Referenced by py_bvhtree_overlap().
|
static |
Definition at line 328 of file mathutils_bvhtree.c.
References BLI_bvhtree_ray_cast(), BVHTreeRayHit::dist, BVHTreeRayHit::index, mathutils_array_parse(), MU_ARRAY_ZERO, normalize_v3(), NULL, py_bvhtree_raycast_cb(), py_bvhtree_raycast_to_py(), py_bvhtree_raycast_to_py_none(), and self.
|
static |
Definition at line 258 of file mathutils_bvhtree.c.
Referenced by py_bvhtree_ray_cast().
|
static |
Definition at line 147 of file mathutils_bvhtree.c.
References py_bvhtree_raycast_to_py_tuple().
Referenced by py_bvhtree_ray_cast().
|
static |
Definition at line 156 of file mathutils_bvhtree.c.
References PyC_Tuple_Fill().
Referenced by py_bvhtree_ray_cast().
|
static |
Definition at line 135 of file mathutils_bvhtree.c.
References BLI_assert, BVHTreeRayHit::co, BVHTreeRayHit::dist, BVHTreeRayHit::index, BVHTreeRayHit::no, NULL, PyTuple_SET_ITEMS, and Vector_CreatePyObject().
Referenced by py_bvhtree_raycast_to_py().
PyDoc_STRVAR | ( | C_BVHTree_FromBMesh_doc | , |
".. classmethod:: FromBMesh(bmesh, epsilon=0.0)\n" "\n" " BVH tree based on :class:`BMesh` data.\n" "\n" " :arg bmesh: BMesh data.\n" " :type bmesh: :class:`BMesh`\n" | PYBVH_FROM_GENERIC_EPSILON_DOC | ||
) |
PyDoc_STRVAR | ( | C_BVHTree_FromObject_doc | , |
".. classmethod:: FromObject(object, depsgraph, deform=True, render=False, " "cage=False, epsilon=0.0)\n" "\n" " BVH tree based on :class:`Object` data.\n" "\n" " :arg object: Object data.\n" " :type object: :class:`Object`\n" " :arg depsgraph: Depsgraph to use for evaluating the mesh.\n" " :type depsgraph: :class:`Depsgraph`\n" " :arg deform: Use mesh with deformations.\n" " :type deform: bool\n" " :arg cage: Use modifiers cage.\n" " :type cage: bool\n" | PYBVH_FROM_GENERIC_EPSILON_DOC | ||
) |
PyDoc_STRVAR | ( | C_BVHTree_FromPolygons_doc | , |
".. classmethod:: FromPolygons(vertices, polygons, all_triangles=False, epsilon=0.0)\n" "\n" " BVH tree constructed geometry passed in as arguments.\n" "\n" " :arg vertices: float triplets each representing ``(x, y, z)``\n" " :type vertices: float triplet sequence\n" " :arg polygons: Sequence of | polyugons, | ||
each containing indices to the vertices argument.\n" " :type polygons:Sequence of sequences containing ints\n" " :arg all_triangles:Use when all **polygons **are triangles for more efficient " "conversion.\n" " :type all_triangles:bool\n" | PYBVH_FROM_GENERIC_EPSILON_DOC | ||
) |
PyDoc_STRVAR | ( | py_bvhtree_doc | , |
"BVH tree structures for proximity searches and ray casts on geometry." | |||
) |
PyDoc_STRVAR | ( | py_bvhtree_find_nearest_doc | , |
".. method:: find_nearest(origin, distance=" PYBVH_MAX_DIST_STR ")\n" "\n" " Find the nearest element (typically face index) to a point.\n" "\n" " :arg co: Find nearest element to this point.\n" " :type co: :class:`Vector`\n" PYBVH_FIND_GENERIC_DISTANCE_DOC | PYBVH_FIND_GENERIC_RETURN_DOC | ||
) |
PyDoc_STRVAR | ( | py_bvhtree_find_nearest_range_doc | , |
".. method:: find_nearest_range(origin, distance=" PYBVH_MAX_DIST_STR ")\n" "\n" " Find the nearest elements (typically face index) to a point in the distance range.\n" "\n" " :arg co: Find nearest elements to this point.\n" " :type co: :class:`Vector`\n" PYBVH_FIND_GENERIC_DISTANCE_DOC | PYBVH_FIND_GENERIC_RETURN_LIST_DOC | ||
) |
PyDoc_STRVAR | ( | py_bvhtree_overlap_doc | , |
".. method:: overlap(other_tree)\n" "\n" " Find overlapping indices between 2 trees.\n" "\n" " :arg other_tree: Other tree to perform overlap test on.\n" " :type other_tree: :class:`BVHTree`\n" " :return: Returns a list of unique index | pairs, | ||
" " the first index referencing this | tree, | ||
the second referencing the **other_tree **.\n" " :rtype::class:`list`\n" | |||
) |
PyDoc_STRVAR | ( | py_bvhtree_ray_cast_doc | , |
".. method:: ray_cast(origin, direction, distance=sys.float_info.max)\n" "\n" " Cast a ray onto the mesh.\n" "\n" " :arg origin: Start location of the ray in object space.\n" " :type origin: :class:`Vector`\n" " :arg direction: Direction of the ray in object space.\n" " :type direction: :class:`Vector`\n" PYBVH_FIND_GENERIC_DISTANCE_DOC | PYBVH_FIND_GENERIC_RETURN_DOC | ||
) |
PyMODINIT_FUNC PyInit_mathutils_bvhtree | ( | void | ) |
Definition at line 1303 of file mathutils_bvhtree.c.
References bvhtree_moduledef, NULL, and PyBVHTree_Type.
Referenced by PyInit_mathutils().
|
static |
Definition at line 1289 of file mathutils_bvhtree.c.
Referenced by PyInit_mathutils_bvhtree().
Definition at line 76 of file mathutils_bvhtree.c.
Referenced by py_bvhtree_find_nearest(), and py_bvhtree_find_nearest_range().
|
static |
Definition at line 79 of file mathutils_bvhtree.c.
Referenced by C_BVHTree_FromBMesh(), C_BVHTree_FromObject(), and C_BVHTree_FromPolygons().
|
static |
Definition at line 78 of file mathutils_bvhtree.c.
Referenced by C_BVHTree_FromBMesh(), C_BVHTree_FromObject(), and C_BVHTree_FromPolygons().
|
static |
Definition at line 1207 of file mathutils_bvhtree.c.
PyTypeObject PyBVHTree_Type |
Definition at line 1237 of file mathutils_bvhtree.c.
Referenced by bvhtree_CreatePyObject(), and PyInit_mathutils_bvhtree().