Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pbvh.c
| Show First 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | |||||
| static int map_insert_vert( | static int map_insert_vert( | ||||
| PBVH *pbvh, GHash *map, unsigned int *face_verts, unsigned int *uniq_verts, int vertex) | PBVH *pbvh, GHash *map, unsigned int *face_verts, unsigned int *uniq_verts, int vertex) | ||||
| { | { | ||||
| void *key, **value_p; | void *key, **value_p; | ||||
| key = POINTER_FROM_INT(vertex); | key = POINTER_FROM_INT(vertex); | ||||
| if (!BLI_ghash_ensure_p(map, key, &value_p)) { | if (!BLI_ghash_ensure_p(map, key, &value_p)) { | ||||
| int value_i; | int value_i; | ||||
| if (BLI_BITMAP_TEST(pbvh->vert_bitmap, vertex) == 0) { | if (!pbvh->vert_bitmap[vertex]) { | ||||
| BLI_BITMAP_ENABLE(pbvh->vert_bitmap, vertex); | pbvh->vert_bitmap[vertex] = true; | ||||
| value_i = *uniq_verts; | value_i = *uniq_verts; | ||||
| (*uniq_verts)++; | (*uniq_verts)++; | ||||
| } | } | ||||
| else { | else { | ||||
| value_i = ~(*face_verts); | value_i = ~(*face_verts); | ||||
| (*face_verts)++; | (*face_verts)++; | ||||
| } | } | ||||
| *value_p = POINTER_FROM_INT(value_i); | *value_p = POINTER_FROM_INT(value_i); | ||||
| ▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | void BKE_pbvh_build_mesh(PBVH *pbvh, | ||||
| pbvh->mesh = mesh; | pbvh->mesh = mesh; | ||||
| pbvh->type = PBVH_FACES; | pbvh->type = PBVH_FACES; | ||||
| pbvh->mpoly = mpoly; | pbvh->mpoly = mpoly; | ||||
| pbvh->mloop = mloop; | pbvh->mloop = mloop; | ||||
| pbvh->looptri = looptri; | pbvh->looptri = looptri; | ||||
| pbvh->verts = verts; | pbvh->verts = verts; | ||||
| BKE_mesh_vertex_normals_ensure(mesh); | BKE_mesh_vertex_normals_ensure(mesh); | ||||
| pbvh->vert_normals = BKE_mesh_vertex_normals_for_write(mesh); | pbvh->vert_normals = BKE_mesh_vertex_normals_for_write(mesh); | ||||
| pbvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap"); | pbvh->vert_bitmap = MEM_calloc_arrayN(totvert, sizeof(bool), "bvh->vert_bitmap"); | ||||
| pbvh->totvert = totvert; | pbvh->totvert = totvert; | ||||
| pbvh->leaf_limit = LEAF_LIMIT; | pbvh->leaf_limit = LEAF_LIMIT; | ||||
| pbvh->vdata = vdata; | pbvh->vdata = vdata; | ||||
| pbvh->ldata = ldata; | pbvh->ldata = ldata; | ||||
| pbvh->pdata = pdata; | pbvh->pdata = pdata; | ||||
| pbvh->face_sets_color_seed = mesh->face_sets_color_seed; | pbvh->face_sets_color_seed = mesh->face_sets_color_seed; | ||||
| pbvh->face_sets_color_default = mesh->face_sets_color_default; | pbvh->face_sets_color_default = mesh->face_sets_color_default; | ||||
| Show All 21 Lines | void BKE_pbvh_build_mesh(PBVH *pbvh, | ||||
| if (looptri_num) { | if (looptri_num) { | ||||
| pbvh_build(pbvh, &cb, prim_bbc, looptri_num); | pbvh_build(pbvh, &cb, prim_bbc, looptri_num); | ||||
| } | } | ||||
| MEM_freeN(prim_bbc); | MEM_freeN(prim_bbc); | ||||
| /* Clear the bitmap so it can be used as an update tag later on. */ | /* Clear the bitmap so it can be used as an update tag later on. */ | ||||
| BLI_bitmap_set_all(pbvh->vert_bitmap, false, totvert); | memset(pbvh->vert_bitmap, 0, sizeof(bool) * totvert); | ||||
| BKE_pbvh_update_active_vcol(pbvh, mesh); | BKE_pbvh_update_active_vcol(pbvh, mesh); | ||||
| } | } | ||||
| void BKE_pbvh_build_grids(PBVH *pbvh, | void BKE_pbvh_build_grids(PBVH *pbvh, | ||||
| CCGElem **grids, | CCGElem **grids, | ||||
| int totgrid, | int totgrid, | ||||
| CCGKey *key, | CCGKey *key, | ||||
| ▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | static void pbvh_update_normals_clear_task_cb(void *__restrict userdata, | ||||
| PBVHNode *node = data->nodes[n]; | PBVHNode *node = data->nodes[n]; | ||||
| float(*vnors)[3] = data->vnors; | float(*vnors)[3] = data->vnors; | ||||
| if (node->flag & PBVH_UpdateNormals) { | if (node->flag & PBVH_UpdateNormals) { | ||||
| const int *verts = node->vert_indices; | const int *verts = node->vert_indices; | ||||
| const int totvert = node->uniq_verts; | const int totvert = node->uniq_verts; | ||||
| for (int i = 0; i < totvert; i++) { | for (int i = 0; i < totvert; i++) { | ||||
| const int v = verts[i]; | const int v = verts[i]; | ||||
| if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { | if (pbvh->vert_bitmap[v]) { | ||||
| zero_v3(vnors[v]); | zero_v3(vnors[v]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, | static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| Show All 26 Lines | for (int i = 0; i < totface; i++) { | ||||
| const MPoly *mp = &pbvh->mpoly[lt->poly]; | const MPoly *mp = &pbvh->mpoly[lt->poly]; | ||||
| BKE_mesh_calc_poly_normal(mp, &pbvh->mloop[mp->loopstart], pbvh->verts, fn); | BKE_mesh_calc_poly_normal(mp, &pbvh->mloop[mp->loopstart], pbvh->verts, fn); | ||||
| mpoly_prev = lt->poly; | mpoly_prev = lt->poly; | ||||
| } | } | ||||
| for (int j = sides; j--;) { | for (int j = sides; j--;) { | ||||
| const int v = vtri[j]; | const int v = vtri[j]; | ||||
| if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { | if (pbvh->vert_bitmap[v]) { | ||||
| /* NOTE: This avoids `lock, add_v3_v3, unlock` | /* NOTE: This avoids `lock, add_v3_v3, unlock` | ||||
| * and is five to ten times quicker than a spin-lock. | * and is five to ten times quicker than a spin-lock. | ||||
| * Not exact equivalent though, since atomicity is only ensured for one component | * Not exact equivalent though, since atomicity is only ensured for one component | ||||
| * of the vector at a time, but here it shall not make any sensible difference. */ | * of the vector at a time, but here it shall not make any sensible difference. */ | ||||
| for (int k = 3; k--;) { | for (int k = 3; k--;) { | ||||
| atomic_add_and_fetch_fl(&vnors[v][k], fn[k]); | atomic_add_and_fetch_fl(&vnors[v][k], fn[k]); | ||||
| } | } | ||||
| } | } | ||||
| Show All 15 Lines | if (node->flag & PBVH_UpdateNormals) { | ||||
| const int *verts = node->vert_indices; | const int *verts = node->vert_indices; | ||||
| const int totvert = node->uniq_verts; | const int totvert = node->uniq_verts; | ||||
| for (int i = 0; i < totvert; i++) { | for (int i = 0; i < totvert; i++) { | ||||
| const int v = verts[i]; | const int v = verts[i]; | ||||
| /* No atomics necessary because we are iterating over uniq_verts only, | /* No atomics necessary because we are iterating over uniq_verts only, | ||||
| * so we know only this thread will handle this vertex. */ | * so we know only this thread will handle this vertex. */ | ||||
| if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { | if (pbvh->vert_bitmap[v]) { | ||||
| normalize_v3(vnors[v]); | normalize_v3(vnors[v]); | ||||
| BLI_BITMAP_DISABLE(pbvh->vert_bitmap, v); | pbvh->vert_bitmap[v] = false; | ||||
| } | } | ||||
| } | } | ||||
| node->flag &= ~PBVH_UpdateNormals; | node->flag &= ~PBVH_UpdateNormals; | ||||
| } | } | ||||
| } | } | ||||
| static void pbvh_faces_update_normals(PBVH *pbvh, PBVHNode **nodes, int totnode) | static void pbvh_faces_update_normals(PBVH *pbvh, PBVHNode **nodes, int totnode) | ||||
| ▲ Show 20 Lines • Show All 764 Lines • ▼ Show 20 Lines | |||||
| bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node) | bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node) | ||||
| { | { | ||||
| return (node->flag & PBVH_Leaf) && (node->flag & PBVH_FullyUnmasked); | return (node->flag & PBVH_Leaf) && (node->flag & PBVH_FullyUnmasked); | ||||
| } | } | ||||
| void BKE_pbvh_vert_mark_update(PBVH *pbvh, int index) | void BKE_pbvh_vert_mark_update(PBVH *pbvh, int index) | ||||
| { | { | ||||
| BLI_assert(pbvh->type == PBVH_FACES); | BLI_assert(pbvh->type == PBVH_FACES); | ||||
| BLI_BITMAP_ENABLE(pbvh->vert_bitmap, index); | pbvh->vert_bitmap[index] = true; | ||||
| } | } | ||||
| void BKE_pbvh_node_get_loops(PBVH *pbvh, | void BKE_pbvh_node_get_loops(PBVH *pbvh, | ||||
| PBVHNode *node, | PBVHNode *node, | ||||
| const int **r_loop_indices, | const int **r_loop_indices, | ||||
| const MLoop **r_loops) | const MLoop **r_loops) | ||||
| { | { | ||||
| BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES); | BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES); | ||||
| ▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BLI_assert(pbvh->type == PBVH_FACES); | BLI_assert(pbvh->type == PBVH_FACES); | ||||
| const int *verts = node->vert_indices; | const int *verts = node->vert_indices; | ||||
| const int totvert = node->uniq_verts + node->face_verts; | const int totvert = node->uniq_verts + node->face_verts; | ||||
| for (int i = 0; i < totvert; i++) { | for (int i = 0; i < totvert; i++) { | ||||
| const int v = verts[i]; | const int v = verts[i]; | ||||
| if (BLI_BITMAP_TEST(pbvh->vert_bitmap, v)) { | if (pbvh->vert_bitmap[v]) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /********************************* Ray-cast ***********************************/ | /********************************* Ray-cast ***********************************/ | ||||
| ▲ Show 20 Lines • Show All 992 Lines • Show Last 20 Lines | |||||