Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pbvh.c
| Context not available. | |||||
| const MVert *vert = bvh->verts; | const MVert *vert = bvh->verts; | ||||
| const MLoop *mloop = bvh->mloop; | const MLoop *mloop = bvh->mloop; | ||||
| const int *faces = node->prim_indices; | const int *faces = node->prim_indices; | ||||
| int totface = node->totprim; | int i, totface = node->totprim; | ||||
| bool hit = false; | bool hit = false; | ||||
| float nearest_vertex_co[3] = {0.0f}; | float min_depth = FLT_MAX; | ||||
| float location[3] = {0.0f}; | |||||
| float nearest_vertex_co[3]; | |||||
| copy_v3_fl(nearest_vertex_co, 0.0f); | |||||
| for (int i = 0; i < totface; i++) { | for (i = 0; i < totface; i++) { | ||||
| const MLoopTri *lt = &bvh->looptri[faces[i]]; | const MLoopTri *lt = &bvh->looptri[faces[i]]; | ||||
| const int *face_verts = node->face_vert_indices[i]; | const int *face_verts = node->face_vert_indices[i]; | ||||
| Context not available. | |||||
| continue; | continue; | ||||
| } | } | ||||
| const float *co[3]; | |||||
| if (origco) { | if (origco) { | ||||
| /* intersect with backuped original coordinates */ | /* intersect with backuped original coordinates */ | ||||
| co[0] = origco[face_verts[0]]; | hit |= ray_face_intersection_tri(ray_start, | ||||
| co[1] = origco[face_verts[1]]; | isect_precalc, | ||||
| co[2] = origco[face_verts[2]]; | origco[face_verts[0]], | ||||
| origco[face_verts[1]], | |||||
| origco[face_verts[2]], | |||||
| depth); | |||||
| } | } | ||||
| else { | else { | ||||
| /* intersect with current coordinates */ | /* intersect with current coordinates */ | ||||
| co[0] = vert[mloop[lt->tri[0]].v].co; | hit |= ray_face_intersection_tri(ray_start, | ||||
| co[1] = vert[mloop[lt->tri[1]].v].co; | isect_precalc, | ||||
| co[2] = vert[mloop[lt->tri[2]].v].co; | vert[mloop[lt->tri[0]].v].co, | ||||
| } | vert[mloop[lt->tri[1]].v].co, | ||||
| vert[mloop[lt->tri[2]].v].co, | |||||
| if (ray_face_intersection_tri(ray_start, isect_precalc, co[0], co[1], co[2], depth)) { | depth); | ||||
| hit = true; | |||||
| if (hit && *depth < min_depth) { | |||||
| if (r_face_normal) { | min_depth = *depth; | ||||
| normal_tri_v3(r_face_normal, co[0], co[1], co[2]); | normal_tri_v3(r_face_normal, | ||||
| } | vert[mloop[lt->tri[0]].v].co, | ||||
| vert[mloop[lt->tri[1]].v].co, | |||||
| if (r_active_vertex_index) { | vert[mloop[lt->tri[2]].v].co); | ||||
| float location[3] = {0.0f}; | |||||
| madd_v3_v3v3fl(location, ray_start, ray_normal, *depth); | madd_v3_v3v3fl(location, ray_start, ray_normal, *depth); | ||||
| for (int j = 0; j < 3; j++) { | for (int j = 0; j < 3; j++) { | ||||
| if (len_squared_v3v3(location, co[j]) < len_squared_v3v3(location, nearest_vertex_co)) { | if (len_squared_v3v3(location, vert[mloop[lt->tri[j]].v].co) < | ||||
| copy_v3_v3(nearest_vertex_co, co[j]); | len_squared_v3v3(location, nearest_vertex_co)) { | ||||
| copy_v3_v3(nearest_vertex_co, vert[mloop[lt->tri[j]].v].co); | |||||
| *r_active_vertex_index = mloop[lt->tri[j]].v; | *r_active_vertex_index = mloop[lt->tri[j]].v; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| PBVHNode *node, | PBVHNode *node, | ||||
| float (*origco)[3], | float (*origco)[3], | ||||
| const float ray_start[3], | const float ray_start[3], | ||||
| const float ray_normal[3], | |||||
| struct IsectRayPrecalc *isect_precalc, | struct IsectRayPrecalc *isect_precalc, | ||||
| float *depth, | float *depth) | ||||
| int *r_active_vertex_index, | |||||
| float *r_face_normal) | |||||
| { | { | ||||
| const int totgrid = node->totprim; | const int totgrid = node->totprim; | ||||
| const int gridsize = bvh->gridkey.grid_size; | const int gridsize = bvh->gridkey.grid_size; | ||||
| bool hit = false; | bool hit = false; | ||||
| float nearest_vertex_co[3] = {0.0}; | |||||
| const CCGKey *gridkey = &bvh->gridkey; | |||||
| for (int i = 0; i < totgrid; i++) { | for (int i = 0; i < totgrid; i++) { | ||||
| const int grid_index = node->prim_indices[i]; | CCGElem *grid = bvh->grids[node->prim_indices[i]]; | ||||
| CCGElem *grid = bvh->grids[grid_index]; | |||||
| BLI_bitmap *gh; | BLI_bitmap *gh; | ||||
| if (!grid) { | if (!grid) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| gh = bvh->grid_hidden[grid_index]; | gh = bvh->grid_hidden[node->prim_indices[i]]; | ||||
| for (int y = 0; y < gridsize - 1; y++) { | for (int y = 0; y < gridsize - 1; y++) { | ||||
| for (int x = 0; x < gridsize - 1; x++) { | for (int x = 0; x < gridsize - 1; x++) { | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| const float *co[4]; | |||||
| if (origco) { | if (origco) { | ||||
| co[0] = origco[y * gridsize + x]; | hit |= ray_face_intersection_quad(ray_start, | ||||
| co[1] = origco[y * gridsize + x + 1]; | isect_precalc, | ||||
| co[2] = origco[(y + 1) * gridsize + x + 1]; | origco[y * gridsize + x], | ||||
| co[3] = origco[(y + 1) * gridsize + x]; | origco[y * gridsize + x + 1], | ||||
| origco[(y + 1) * gridsize + x + 1], | |||||
| origco[(y + 1) * gridsize + x], | |||||
| depth); | |||||
| } | } | ||||
| else { | else { | ||||
| co[0] = CCG_grid_elem_co(gridkey, grid, x, y); | hit |= ray_face_intersection_quad(ray_start, | ||||
| co[1] = CCG_grid_elem_co(gridkey, grid, x + 1, y); | isect_precalc, | ||||
| co[2] = CCG_grid_elem_co(gridkey, grid, x + 1, y + 1); | CCG_grid_elem_co(&bvh->gridkey, grid, x, y), | ||||
| co[3] = CCG_grid_elem_co(gridkey, grid, x, y + 1); | CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y), | ||||
| } | CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y + 1), | ||||
| CCG_grid_elem_co(&bvh->gridkey, grid, x, y + 1), | |||||
| if (ray_face_intersection_quad( | depth); | ||||
| ray_start, isect_precalc, co[0], co[1], co[2], co[3], depth)) { | |||||
| hit = true; | |||||
| if (r_face_normal) { | |||||
| normal_quad_v3(r_face_normal, co[0], co[1], co[2], co[3]); | |||||
| } | |||||
| if (r_active_vertex_index) { | |||||
| float location[3] = {0.0}; | |||||
| madd_v3_v3v3fl(location, ray_start, ray_normal, *depth); | |||||
| for (int j = 0; j < 4; j++) { | |||||
| if (len_squared_v3v3(location, co[j]) < | |||||
| len_squared_v3v3(location, nearest_vertex_co)) { | |||||
| copy_v3_v3(nearest_vertex_co, co[j]); | |||||
| *r_active_vertex_index = gridkey->grid_area * grid_index + y * gridkey->grid_size + | |||||
| x; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| face_normal); | face_normal); | ||||
| break; | break; | ||||
| case PBVH_GRIDS: | case PBVH_GRIDS: | ||||
| hit |= pbvh_grids_node_raycast(bvh, | hit |= pbvh_grids_node_raycast(bvh, node, origco, ray_start, isect_precalc, depth); | ||||
| node, | |||||
| origco, | |||||
| ray_start, | |||||
| ray_normal, | |||||
| isect_precalc, | |||||
| depth, | |||||
| active_vertex_index, | |||||
| face_normal); | |||||
| break; | break; | ||||
| case PBVH_BMESH: | case PBVH_BMESH: | ||||
| BM_mesh_elem_index_ensure(bvh->bm, BM_VERT); | BM_mesh_elem_index_ensure(bvh->bm, BM_VERT); | ||||
| Context not available. | |||||