Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_snap_object.cc
| Show First 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | if (std::unique_ptr<SnapData_EditMesh> *sod_p = sctx->editmesh_caches.lookup_ptr(em)) { | ||||
| bool is_dirty = false; | bool is_dirty = false; | ||||
| /* Check if the geometry has changed. */ | /* Check if the geometry has changed. */ | ||||
| if (sod->treedata_editmesh.em != em) { | if (sod->treedata_editmesh.em != em) { | ||||
| is_dirty = true; | is_dirty = true; | ||||
| } | } | ||||
| else if (sod->mesh_runtime) { | else if (sod->mesh_runtime) { | ||||
| if (sod->mesh_runtime != snap_object_data_editmesh_runtime_get(ob_eval)) { | if (sod->mesh_runtime != snap_object_data_editmesh_runtime_get(ob_eval)) { | ||||
| if (G.moving) { | if (G.moving) { | ||||
| /* Hack to avoid updating while transforming. */ | /* WORKAROUND: avoid updating while transforming. */ | ||||
| BLI_assert(!sod->treedata_editmesh.cached && !sod->cached[0] && !sod->cached[1]); | BLI_assert(!sod->treedata_editmesh.cached && !sod->cached[0] && !sod->cached[1]); | ||||
| sod->mesh_runtime = snap_object_data_editmesh_runtime_get(ob_eval); | sod->mesh_runtime = snap_object_data_editmesh_runtime_get(ob_eval); | ||||
| } | } | ||||
| else { | else { | ||||
| is_dirty = true; | is_dirty = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (sod->treedata_editmesh.tree && sod->treedata_editmesh.cached && | else if (sod->treedata_editmesh.tree && sod->treedata_editmesh.cached && | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | if (treedata->tree == nullptr) { | ||||
| } | } | ||||
| else { | else { | ||||
| /* Only cache if BVH-tree is created without a mask. | /* Only cache if BVH-tree is created without a mask. | ||||
| * This helps keep a standardized BVH-tree in cache. */ | * This helps keep a standardized BVH-tree in cache. */ | ||||
| BKE_bvhtree_from_editmesh_get(treedata, | BKE_bvhtree_from_editmesh_get(treedata, | ||||
| em, | em, | ||||
| 4, | 4, | ||||
| BVHTREE_FROM_EM_LOOPTRI, | BVHTREE_FROM_EM_LOOPTRI, | ||||
| &sod->mesh_runtime->bvh_cache, | /* WORKAROUND: avoid updating while transforming. */ | ||||
| G.moving ? nullptr : &sod->mesh_runtime->bvh_cache, | |||||
| &sod->mesh_runtime->eval_mutex); | &sod->mesh_runtime->eval_mutex); | ||||
| } | } | ||||
| } | } | ||||
| if (treedata == nullptr || treedata->tree == nullptr) { | if (treedata->tree == nullptr) { | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| return treedata; | return treedata; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| ▲ Show 20 Lines • Show All 850 Lines • ▼ Show 20 Lines | static bool nearest_world_editmesh(SnapObjectContext *sctx, | ||||
| const float init_co[3], | const float init_co[3], | ||||
| const float curr_co[3], | const float curr_co[3], | ||||
| float *r_dist_sq, | float *r_dist_sq, | ||||
| float *r_loc, | float *r_loc, | ||||
| float *r_no, | float *r_no, | ||||
| int *r_index) | int *r_index) | ||||
| { | { | ||||
| BVHTreeFromEditMesh *treedata = snap_object_data_editmesh_treedata_get(sctx, ob_eval, em); | BVHTreeFromEditMesh *treedata = snap_object_data_editmesh_treedata_get(sctx, ob_eval, em); | ||||
| if (treedata == nullptr || treedata->tree == nullptr) { | if (treedata == nullptr) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return nearest_world_tree(sctx, | return nearest_world_tree(sctx, | ||||
| params, | params, | ||||
| treedata->tree, | treedata->tree, | ||||
| treedata->nearest_callback, | treedata->nearest_callback, | ||||
| treedata, | treedata, | ||||
| ▲ Show 20 Lines • Show All 1,485 Lines • ▼ Show 20 Lines | if (treedata.tree == nullptr) { | ||||
| bvhtree_from_editmesh_verts_ex(&treedata, em, verts_mask, verts_num_active, 0.0f, 2, 6); | bvhtree_from_editmesh_verts_ex(&treedata, em, verts_mask, verts_num_active, 0.0f, 2, 6); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_bvhtree_from_editmesh_get(&treedata, | BKE_bvhtree_from_editmesh_get(&treedata, | ||||
| em, | em, | ||||
| 2, | 2, | ||||
| BVHTREE_FROM_EM_VERTS, | BVHTREE_FROM_EM_VERTS, | ||||
| &sod->mesh_runtime->bvh_cache, | /* WORKAROUND: avoid updating while transforming. */ | ||||
| G.moving ? nullptr : &sod->mesh_runtime->bvh_cache, | |||||
| &sod->mesh_runtime->eval_mutex); | &sod->mesh_runtime->eval_mutex); | ||||
| } | } | ||||
| sod->bvhtree[0] = treedata.tree; | sod->bvhtree[0] = treedata.tree; | ||||
| sod->cached[0] = treedata.cached; | sod->cached[0] = treedata.cached; | ||||
| } | } | ||||
| } | } | ||||
| if (sctx->runtime.snap_to_flag & SCE_SNAP_MODE_EDGE) { | if (sctx->runtime.snap_to_flag & SCE_SNAP_MODE_EDGE) { | ||||
| Show All 12 Lines | if (treedata.tree == nullptr) { | ||||
| bvhtree_from_editmesh_edges_ex(&treedata, em, edges_mask, edges_num_active, 0.0f, 2, 6); | bvhtree_from_editmesh_edges_ex(&treedata, em, edges_mask, edges_num_active, 0.0f, 2, 6); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_bvhtree_from_editmesh_get(&treedata, | BKE_bvhtree_from_editmesh_get(&treedata, | ||||
| em, | em, | ||||
| 2, | 2, | ||||
| BVHTREE_FROM_EM_EDGES, | BVHTREE_FROM_EM_EDGES, | ||||
| &sod->mesh_runtime->bvh_cache, | /* WORKAROUND: avoid updating while transforming. */ | ||||
| G.moving ? nullptr : &sod->mesh_runtime->bvh_cache, | |||||
| &sod->mesh_runtime->eval_mutex); | &sod->mesh_runtime->eval_mutex); | ||||
| } | } | ||||
| sod->bvhtree[1] = treedata.tree; | sod->bvhtree[1] = treedata.tree; | ||||
| sod->cached[1] = treedata.cached; | sod->cached[1] = treedata.cached; | ||||
| } | } | ||||
| } | } | ||||
| Nearest2dUserData nearest2d; | Nearest2dUserData nearest2d; | ||||
| ▲ Show 20 Lines • Show All 252 Lines • ▼ Show 20 Lines | |||||
| void ED_transform_snap_object_context_set_editmesh_callbacks( | void ED_transform_snap_object_context_set_editmesh_callbacks( | ||||
| SnapObjectContext *sctx, | SnapObjectContext *sctx, | ||||
| bool (*test_vert_fn)(BMVert *, void *user_data), | bool (*test_vert_fn)(BMVert *, void *user_data), | ||||
| bool (*test_edge_fn)(BMEdge *, void *user_data), | bool (*test_edge_fn)(BMEdge *, void *user_data), | ||||
| bool (*test_face_fn)(BMFace *, void *user_data), | bool (*test_face_fn)(BMFace *, void *user_data), | ||||
| void *user_data) | void *user_data) | ||||
| { | { | ||||
| bool is_cache_dirty = false; | |||||
| if (sctx->callbacks.edit_mesh.test_vert_fn != test_vert_fn) { | |||||
| sctx->callbacks.edit_mesh.test_vert_fn = test_vert_fn; | sctx->callbacks.edit_mesh.test_vert_fn = test_vert_fn; | ||||
| is_cache_dirty = true; | |||||
| } | |||||
| if (sctx->callbacks.edit_mesh.test_edge_fn != test_edge_fn) { | |||||
| sctx->callbacks.edit_mesh.test_edge_fn = test_edge_fn; | sctx->callbacks.edit_mesh.test_edge_fn = test_edge_fn; | ||||
| is_cache_dirty = true; | |||||
| } | |||||
| if (sctx->callbacks.edit_mesh.test_face_fn != test_face_fn) { | |||||
| sctx->callbacks.edit_mesh.test_face_fn = test_face_fn; | sctx->callbacks.edit_mesh.test_face_fn = test_face_fn; | ||||
| is_cache_dirty = true; | |||||
| } | |||||
| if (sctx->callbacks.edit_mesh.user_data != user_data) { | |||||
| sctx->callbacks.edit_mesh.user_data = user_data; | sctx->callbacks.edit_mesh.user_data = user_data; | ||||
| is_cache_dirty = true; | |||||
| } | |||||
| if (is_cache_dirty) { | |||||
| sctx->editmesh_caches.clear(); | |||||
| } | |||||
| } | } | ||||
| bool ED_transform_snap_object_project_ray_ex(SnapObjectContext *sctx, | bool ED_transform_snap_object_project_ray_ex(SnapObjectContext *sctx, | ||||
| Depsgraph *depsgraph, | Depsgraph *depsgraph, | ||||
| const View3D *v3d, | const View3D *v3d, | ||||
| const SnapObjectParams *params, | const SnapObjectParams *params, | ||||
| const float ray_start[3], | const float ray_start[3], | ||||
| const float ray_normal[3], | const float ray_normal[3], | ||||
| ▲ Show 20 Lines • Show All 423 Lines • Show Last 20 Lines | |||||