Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pbvh.c
| Show First 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | |||||
| // BB_reset(&node->vb); | // BB_reset(&node->vb); | ||||
| //} | //} | ||||
| // | // | ||||
| //void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]) | //void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]) | ||||
| //{ | //{ | ||||
| // BB_expand(&node->vb, co); | // BB_expand(&node->vb, co); | ||||
| //} | //} | ||||
| static int face_materials_match(const MFace *f1, const MFace *f2) | static int face_materials_match(const MPoly *f1, const MPoly *f2) | ||||
| { | { | ||||
| return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) && | return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) && | ||||
| (f1->mat_nr == f2->mat_nr)); | (f1->mat_nr == f2->mat_nr)); | ||||
| } | } | ||||
| static int grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2) | static int grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2) | ||||
| { | { | ||||
| return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) && | return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) && | ||||
| Show All 16 Lines | for (;; ) { | ||||
| SWAP(int, prim_indices[i], prim_indices[j]); | SWAP(int, prim_indices[i], prim_indices[j]); | ||||
| i++; | i++; | ||||
| } | } | ||||
| } | } | ||||
| /* Returns the index of the first element on the right of the partition */ | /* Returns the index of the first element on the right of the partition */ | ||||
| static int partition_indices_material(PBVH *bvh, int lo, int hi) | static int partition_indices_material(PBVH *bvh, int lo, int hi) | ||||
| { | { | ||||
| const MFace *faces = bvh->faces; | const MPoly *mpoly = bvh->mpoly; | ||||
| const MLoopTri *looptri = bvh->looptri; | |||||
| const DMFlagMat *flagmats = bvh->grid_flag_mats; | const DMFlagMat *flagmats = bvh->grid_flag_mats; | ||||
| const int *indices = bvh->prim_indices; | const int *indices = bvh->prim_indices; | ||||
| const void *first; | const void *first; | ||||
| int i = lo, j = hi; | int i = lo, j = hi; | ||||
| if (bvh->faces) | if (bvh->looptri) | ||||
| first = &faces[bvh->prim_indices[lo]]; | first = &looptri[bvh->prim_indices[lo]]; | ||||
| else | else | ||||
| first = &flagmats[bvh->prim_indices[lo]]; | first = &flagmats[bvh->prim_indices[lo]]; | ||||
| for (;; ) { | for (;; ) { | ||||
| if (bvh->faces) { | if (bvh->looptri) { | ||||
| for (; face_materials_match(first, &faces[indices[i]]); i++) ; | for (; face_materials_match(first, &mpoly[looptri[indices[i]].poly]); i++) ; | ||||
| for (; !face_materials_match(first, &faces[indices[j]]); j--) ; | for (; !face_materials_match(first, &mpoly[looptri[indices[j]].poly]); j--) ; | ||||
psy-fi: We may be able to use polys here? (no big deal though, this is cached I think) | |||||
Not Done Inline ActionsThat can work if bvh->prim_indices are polys. campbellbarton: That can work if `bvh->prim_indices` are polys. | |||||
| } | } | ||||
| else { | else { | ||||
| for (; grid_materials_match(first, &flagmats[indices[i]]); i++) ; | for (; grid_materials_match(first, &flagmats[indices[i]]); i++) ; | ||||
| for (; !grid_materials_match(first, &flagmats[indices[j]]); j--) ; | for (; !grid_materials_match(first, &flagmats[indices[j]]); j--) ; | ||||
| } | } | ||||
| if (!(i < j)) | if (!(i < j)) | ||||
| return i; | return i; | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) | ||||
| map = BLI_ghash_int_new_ex("build_mesh_leaf_node gh", 2 * totface); | map = BLI_ghash_int_new_ex("build_mesh_leaf_node gh", 2 * totface); | ||||
| face_vert_indices = MEM_callocN(sizeof(int[4]) * totface, | face_vert_indices = MEM_callocN(sizeof(int[4]) * totface, | ||||
| "bvh node face vert indices"); | "bvh node face vert indices"); | ||||
| node->face_vert_indices = (const int (*)[4])face_vert_indices; | node->face_vert_indices = (const int (*)[4])face_vert_indices; | ||||
| for (i = 0; i < totface; ++i) { | for (i = 0; i < totface; ++i) { | ||||
| const MFace *f = &bvh->faces[node->prim_indices[i]]; | const MLoopTri *lt = &bvh->looptri[node->prim_indices[i]]; | ||||
| int sides = f->v4 ? 4 : 3; | int sides = 3; | ||||
Not Done Inline ActionsNot sure if storing triangles is the best option for sculpting. psy-fi: Not sure if storing triangles is the best option for sculpting.
For intersection it is… | |||||
Not Done Inline Actionsagree, just sculpt stores tri's per node, not polys... which makes sense for actual sculpting part. but as you say - not here. campbellbarton: agree, just sculpt stores tri's per node, not polys... which makes sense for actual sculpting… | |||||
| for (j = 0; j < sides; ++j) { | for (j = 0; j < sides; ++j) { | ||||
| face_vert_indices[i][j] = | face_vert_indices[i][j] = | ||||
| map_insert_vert(bvh, map, &node->face_verts, | map_insert_vert(bvh, map, &node->face_verts, | ||||
| &node->uniq_verts, (&f->v1)[j]); | &node->uniq_verts, bvh->mloop[lt->tri[j]].v); | ||||
| } | } | ||||
| if (!paint_is_face_hidden(f, bvh->verts)) | if (!paint_is_face_hidden(lt, bvh->verts, bvh->mloop)) { | ||||
| has_visible = true; | has_visible = true; | ||||
| } | } | ||||
| } | |||||
| vert_indices = MEM_callocN(sizeof(int) * | vert_indices = MEM_callocN(sizeof(int) * | ||||
| (node->uniq_verts + node->face_verts), | (node->uniq_verts + node->face_verts), | ||||
| "bvh node vert indices"); | "bvh node vert indices"); | ||||
| node->vert_indices = vert_indices; | node->vert_indices = vert_indices; | ||||
| /* Build the vertex list, unique verts first */ | /* Build the vertex list, unique verts first */ | ||||
| GHASH_ITER (gh_iter, map) { | GHASH_ITER (gh_iter, map) { | ||||
| void *value = BLI_ghashIterator_getValue(&gh_iter); | void *value = BLI_ghashIterator_getValue(&gh_iter); | ||||
| int ndx = GET_INT_FROM_POINTER(value); | int ndx = GET_INT_FROM_POINTER(value); | ||||
| if (ndx < 0) | if (ndx < 0) | ||||
| ndx = -ndx + node->uniq_verts - 1; | ndx = -ndx + node->uniq_verts - 1; | ||||
| vert_indices[ndx] = | vert_indices[ndx] = | ||||
| GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(&gh_iter)); | GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(&gh_iter)); | ||||
| } | } | ||||
| for (i = 0; i < totface; ++i) { | for (i = 0; i < totface; ++i) { | ||||
| const MFace *f = &bvh->faces[node->prim_indices[i]]; | int sides = 3; | ||||
| int sides = f->v4 ? 4 : 3; | |||||
| for (j = 0; j < sides; ++j) { | for (j = 0; j < sides; ++j) { | ||||
| if (face_vert_indices[i][j] < 0) | if (face_vert_indices[i][j] < 0) | ||||
| face_vert_indices[i][j] = | face_vert_indices[i][j] = | ||||
| -face_vert_indices[i][j] + | -face_vert_indices[i][j] + | ||||
| node->uniq_verts - 1; | node->uniq_verts - 1; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc, | ||||
| bvh->nodes[node_index].flag |= PBVH_Leaf; | bvh->nodes[node_index].flag |= PBVH_Leaf; | ||||
| bvh->nodes[node_index].prim_indices = bvh->prim_indices + offset; | bvh->nodes[node_index].prim_indices = bvh->prim_indices + offset; | ||||
| bvh->nodes[node_index].totprim = count; | bvh->nodes[node_index].totprim = count; | ||||
| /* Still need vb for searches */ | /* Still need vb for searches */ | ||||
| update_vb(bvh, &bvh->nodes[node_index], prim_bbc, offset, count); | update_vb(bvh, &bvh->nodes[node_index], prim_bbc, offset, count); | ||||
| if (bvh->faces) | if (bvh->looptri) | ||||
| build_mesh_leaf_node(bvh, bvh->nodes + node_index); | build_mesh_leaf_node(bvh, bvh->nodes + node_index); | ||||
| else { | else { | ||||
| build_grid_leaf_node(bvh, bvh->nodes + node_index); | build_grid_leaf_node(bvh, bvh->nodes + node_index); | ||||
| } | } | ||||
| } | } | ||||
| /* Return zero if all primitives in the node can be drawn with the | /* Return zero if all primitives in the node can be drawn with the | ||||
| * same material (including flat/smooth shading), non-zero otherwise */ | * same material (including flat/smooth shading), non-zero otherwise */ | ||||
| static int leaf_needs_material_split(PBVH *bvh, int offset, int count) | static int leaf_needs_material_split(PBVH *bvh, int offset, int count) | ||||
| { | { | ||||
| int i, prim; | int i; | ||||
| if (count <= 1) | if (count <= 1) | ||||
| return 0; | return 0; | ||||
| if (bvh->faces) { | if (bvh->looptri) { | ||||
| const MFace *first = &bvh->faces[bvh->prim_indices[offset]]; | const MLoopTri *first = &bvh->looptri[bvh->prim_indices[offset]]; | ||||
| const MPoly *mp = &bvh->mpoly[first->poly]; | |||||
| for (i = offset + count - 1; i > offset; --i) { | for (i = offset + count - 1; i > offset; --i) { | ||||
| prim = bvh->prim_indices[i]; | int prim = bvh->prim_indices[i]; | ||||
| if (!face_materials_match(first, &bvh->faces[prim])) | const MPoly *mp_other = &bvh->mpoly[bvh->looptri[prim].poly]; | ||||
| if (!face_materials_match(mp, mp_other)) { | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| const DMFlagMat *first = &bvh->grid_flag_mats[bvh->prim_indices[offset]]; | const DMFlagMat *first = &bvh->grid_flag_mats[bvh->prim_indices[offset]]; | ||||
| for (i = offset + count - 1; i > offset; --i) { | for (i = offset + count - 1; i > offset; --i) { | ||||
| prim = bvh->prim_indices[i]; | int prim = bvh->prim_indices[i]; | ||||
| if (!grid_materials_match(first, &bvh->grid_flag_mats[prim])) | if (!grid_materials_match(first, &bvh->grid_flag_mats[prim])) | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim) | ||||
| } | } | ||||
| bvh->totnode = 1; | bvh->totnode = 1; | ||||
| build_sub(bvh, 0, cb, prim_bbc, 0, totprim); | build_sub(bvh, 0, cb, prim_bbc, 0, totprim); | ||||
| } | } | ||||
| /* Do a full rebuild with on Mesh data structure */ | /* Do a full rebuild with on Mesh data structure */ | ||||
| void BKE_pbvh_build_mesh( | void BKE_pbvh_build_mesh( | ||||
| PBVH *bvh, const MFace *faces, MVert *verts, | PBVH *bvh, const MPoly *mpoly, const MLoop *mloop, MVert *verts, | ||||
| int totface, int totvert, struct CustomData *vdata) | int totvert, struct CustomData *vdata, | ||||
| const MLoopTri *looptri, int looptri_num) | |||||
| { | { | ||||
| BBC *prim_bbc = NULL; | BBC *prim_bbc = NULL; | ||||
| BB cb; | BB cb; | ||||
| int i, j; | int i, j; | ||||
| bvh->type = PBVH_FACES; | bvh->type = PBVH_FACES; | ||||
| bvh->faces = faces; | bvh->mpoly = mpoly; | ||||
| bvh->mloop = mloop; | |||||
| bvh->looptri = looptri; | |||||
| bvh->verts = verts; | bvh->verts = verts; | ||||
| bvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap"); | bvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap"); | ||||
| bvh->totvert = totvert; | bvh->totvert = totvert; | ||||
| bvh->leaf_limit = LEAF_LIMIT; | bvh->leaf_limit = LEAF_LIMIT; | ||||
| bvh->vdata = vdata; | bvh->vdata = vdata; | ||||
| BB_reset(&cb); | BB_reset(&cb); | ||||
| /* For each face, store the AABB and the AABB centroid */ | /* For each face, store the AABB and the AABB centroid */ | ||||
| prim_bbc = MEM_mallocN(sizeof(BBC) * totface, "prim_bbc"); | prim_bbc = MEM_mallocN(sizeof(BBC) * looptri_num, "prim_bbc"); | ||||
| for (i = 0; i < totface; ++i) { | for (i = 0; i < looptri_num; ++i) { | ||||
| const MFace *f = &faces[i]; | const MLoopTri *lt = &looptri[i]; | ||||
| const int sides = f->v4 ? 4 : 3; | const int sides = 3; | ||||
| BBC *bbc = prim_bbc + i; | BBC *bbc = prim_bbc + i; | ||||
| BB_reset((BB *)bbc); | BB_reset((BB *)bbc); | ||||
| for (j = 0; j < sides; ++j) | for (j = 0; j < sides; ++j) | ||||
| BB_expand((BB *)bbc, verts[(&f->v1)[j]].co); | BB_expand((BB *)bbc, verts[bvh->mloop[lt->tri[j]].v].co); | ||||
| BBC_update_centroid(bbc); | BBC_update_centroid(bbc); | ||||
| BB_expand(&cb, bbc->bcentroid); | BB_expand(&cb, bbc->bcentroid); | ||||
| } | } | ||||
| if (totface) | if (looptri_num) | ||||
| pbvh_build(bvh, &cb, prim_bbc, totface); | pbvh_build(bvh, &cb, prim_bbc, looptri_num); | ||||
| MEM_freeN(prim_bbc); | MEM_freeN(prim_bbc); | ||||
| MEM_freeN(bvh->vert_bitmap); | MEM_freeN(bvh->vert_bitmap); | ||||
| } | } | ||||
| /* Do a full rebuild with on Grids data structure */ | /* Do a full rebuild with on Grids data structure */ | ||||
| void BKE_pbvh_build_grids(PBVH *bvh, CCGElem **grids, | void BKE_pbvh_build_grids(PBVH *bvh, CCGElem **grids, | ||||
| int totgrid, CCGKey *key, void **gridfaces, DMFlagMat *flagmats, BLI_bitmap **grid_hidden) | int totgrid, CCGKey *key, void **gridfaces, DMFlagMat *flagmats, BLI_bitmap **grid_hidden) | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | for (i = 0; i < bvh->totnode; ++i) { | ||||
| } | } | ||||
| } | } | ||||
| if (bvh->deformed) { | if (bvh->deformed) { | ||||
| if (bvh->verts) { | if (bvh->verts) { | ||||
| /* if pbvh was deformed, new memory was allocated for verts/faces -- free it */ | /* if pbvh was deformed, new memory was allocated for verts/faces -- free it */ | ||||
| MEM_freeN((void *)bvh->verts); | MEM_freeN((void *)bvh->verts); | ||||
| if (bvh->faces) { | |||||
| MEM_freeN((void *)bvh->faces); | |||||
| } | } | ||||
| } | } | ||||
| if (bvh->looptri) { | |||||
| MEM_freeN((void *)bvh->looptri); | |||||
| } | } | ||||
| if (bvh->nodes) | if (bvh->nodes) | ||||
| MEM_freeN(bvh->nodes); | MEM_freeN(bvh->nodes); | ||||
| if (bvh->prim_indices) | if (bvh->prim_indices) | ||||
| MEM_freeN(bvh->prim_indices); | MEM_freeN(bvh->prim_indices); | ||||
| ▲ Show 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | for (n = 0; n < totnode; n++) { | ||||
| if ((node->flag & PBVH_UpdateNormals)) { | if ((node->flag & PBVH_UpdateNormals)) { | ||||
| int i, j, totface, *faces; | int i, j, totface, *faces; | ||||
| faces = node->prim_indices; | faces = node->prim_indices; | ||||
| totface = node->totprim; | totface = node->totprim; | ||||
| for (i = 0; i < totface; ++i) { | for (i = 0; i < totface; ++i) { | ||||
| const MFace *f = &bvh->faces[faces[i]]; | const MLoopTri *lt = &bvh->looptri[faces[i]]; | ||||
| const unsigned int vtri[3] = { | |||||
| bvh->mloop[lt->tri[0]].v, | |||||
| bvh->mloop[lt->tri[1]].v, | |||||
| bvh->mloop[lt->tri[2]].v, | |||||
| }; | |||||
| float fn[3]; | float fn[3]; | ||||
| const unsigned int *fv = &f->v1; | int sides = 3; | ||||
| int sides = (f->v4) ? 4 : 3; | |||||
| if (f->v4) | normal_tri_v3( | ||||
| normal_quad_v3(fn, bvh->verts[f->v1].co, bvh->verts[f->v2].co, | fn, | ||||
| bvh->verts[f->v3].co, bvh->verts[f->v4].co); | bvh->verts[vtri[0]].co, | ||||
| else | bvh->verts[vtri[1]].co, | ||||
| normal_tri_v3(fn, bvh->verts[f->v1].co, bvh->verts[f->v2].co, | bvh->verts[vtri[2]].co); | ||||
| bvh->verts[f->v3].co); | |||||
| for (j = 0; j < sides; ++j) { | for (j = 0; j < sides; ++j) { | ||||
| int v = fv[j]; | int v = vtri[j]; | ||||
| if (bvh->verts[v].flag & ME_VERT_PBVH_UPDATE) { | if (bvh->verts[v].flag & ME_VERT_PBVH_UPDATE) { | ||||
| /* this seems like it could be very slow but profile | /* this seems like it could be very slow but profile | ||||
| * does not show this, so just leave it for now? */ | * does not show this, so just leave it for now? */ | ||||
| #pragma omp atomic | #pragma omp atomic | ||||
| vnor[v][0] += fn[0]; | vnor[v][0] += fn[0]; | ||||
| #pragma omp atomic | #pragma omp atomic | ||||
| vnor[v][1] += fn[1]; | vnor[v][1] += fn[1]; | ||||
| #pragma omp atomic | #pragma omp atomic | ||||
| vnor[v][2] += fn[2]; | vnor[v][2] += fn[2]; | ||||
| } | } | ||||
| } | } | ||||
| if (face_nors) | if (face_nors) { | ||||
| copy_v3_v3(face_nors[faces[i]], fn); | copy_v3_v3(face_nors[lt->poly], fn); | ||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #pragma omp parallel for private(n) schedule(static) if (totnode > PBVH_OMP_LIMIT) | #pragma omp parallel for private(n) schedule(static) if (totnode > PBVH_OMP_LIMIT) | ||||
| for (n = 0; n < totnode; n++) { | for (n = 0; n < totnode; n++) { | ||||
| PBVHNode *node = nodes[n]; | PBVHNode *node = nodes[n]; | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | if (node->flag & PBVH_RebuildDrawBuffers) { | ||||
| GPU_build_grid_pbvh_buffers(node->prim_indices, | GPU_build_grid_pbvh_buffers(node->prim_indices, | ||||
| node->totprim, | node->totprim, | ||||
| bvh->grid_hidden, | bvh->grid_hidden, | ||||
| bvh->gridkey.grid_size); | bvh->gridkey.grid_size); | ||||
| break; | break; | ||||
| case PBVH_FACES: | case PBVH_FACES: | ||||
| node->draw_buffers = | node->draw_buffers = | ||||
| GPU_build_mesh_pbvh_buffers(node->face_vert_indices, | GPU_build_mesh_pbvh_buffers(node->face_vert_indices, | ||||
| bvh->faces, bvh->verts, | bvh->mpoly, bvh->mloop, bvh->looptri, | ||||
| bvh->verts, | |||||
| node->prim_indices, | node->prim_indices, | ||||
| node->totprim); | node->totprim); | ||||
| break; | break; | ||||
| case PBVH_BMESH: | case PBVH_BMESH: | ||||
| node->draw_buffers = | node->draw_buffers = | ||||
| GPU_build_bmesh_pbvh_buffers(bvh->flags & | GPU_build_bmesh_pbvh_buffers(bvh->flags & | ||||
| PBVH_DYNTOPO_SMOOTH_SHADING); | PBVH_DYNTOPO_SMOOTH_SHADING); | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 405 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static bool pbvh_faces_node_raycast(PBVH *bvh, const PBVHNode *node, | static bool pbvh_faces_node_raycast(PBVH *bvh, const PBVHNode *node, | ||||
| float (*origco)[3], | float (*origco)[3], | ||||
| const float ray_start[3], | const float ray_start[3], | ||||
| const float ray_normal[3], float *dist) | const float ray_normal[3], float *dist) | ||||
| { | { | ||||
| const MVert *vert = bvh->verts; | const MVert *vert = bvh->verts; | ||||
| const MLoop *mloop = bvh->mloop; | |||||
| const int *faces = node->prim_indices; | const int *faces = node->prim_indices; | ||||
| int i, totface = node->totprim; | int i, totface = node->totprim; | ||||
| bool hit = false; | bool hit = false; | ||||
| for (i = 0; i < totface; ++i) { | for (i = 0; i < totface; ++i) { | ||||
| const MFace *f = bvh->faces + 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]; | ||||
| if (paint_is_face_hidden(f, vert)) | if (paint_is_face_hidden(lt, vert, mloop)) | ||||
| continue; | continue; | ||||
| if (origco) { | if (origco) { | ||||
| /* intersect with backuped original coordinates */ | /* intersect with backuped original coordinates */ | ||||
| hit |= ray_face_intersection(ray_start, ray_normal, | hit |= ray_face_intersection(ray_start, ray_normal, | ||||
| origco[face_verts[0]], | origco[face_verts[0]], | ||||
| origco[face_verts[1]], | origco[face_verts[1]], | ||||
| origco[face_verts[2]], | origco[face_verts[2]], | ||||
| f->v4 ? origco[face_verts[3]] : NULL, | NULL, | ||||
| dist); | dist); | ||||
| } | } | ||||
| else { | else { | ||||
| /* intersect with current coordinates */ | /* intersect with current coordinates */ | ||||
| hit |= ray_face_intersection(ray_start, ray_normal, | hit |= ray_face_intersection(ray_start, ray_normal, | ||||
| vert[f->v1].co, | vert[mloop[lt->tri[0]].v].co, | ||||
Not Done Inline ActionsProbably change to ray_triangle_intersection now? psy-fi: Probably change to ray_triangle_intersection now? | |||||
Not Done Inline ActionsWe could, I checked this and there are other tris in sculpt code being passed to this function, so which defines epsilon & compares dist.. so could be good to wrap stilll. campbellbarton: We could, I checked this and there are other tris in sculpt code being passed to this function… | |||||
| vert[f->v2].co, | vert[mloop[lt->tri[1]].v].co, | ||||
| vert[f->v3].co, | vert[mloop[lt->tri[2]].v].co, | ||||
| f->v4 ? vert[f->v4].co : NULL, | NULL, | ||||
| dist); | dist); | ||||
| } | } | ||||
| } | } | ||||
| return hit; | return hit; | ||||
| } | } | ||||
| static bool pbvh_grids_node_raycast( | static bool pbvh_grids_node_raycast( | ||||
| ▲ Show 20 Lines • Show All 316 Lines • ▼ Show 20 Lines | void BKE_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3]) | ||||
| int a; | int a; | ||||
| if (!pbvh->deformed) { | if (!pbvh->deformed) { | ||||
| if (pbvh->verts) { | if (pbvh->verts) { | ||||
| /* if pbvh is not already deformed, verts/faces points to the */ | /* if pbvh is not already deformed, verts/faces points to the */ | ||||
| /* original data and applying new coords to this arrays would lead to */ | /* original data and applying new coords to this arrays would lead to */ | ||||
| /* unneeded deformation -- duplicate verts/faces to avoid this */ | /* unneeded deformation -- duplicate verts/faces to avoid this */ | ||||
| pbvh->verts = MEM_dupallocN(pbvh->verts); | pbvh->verts = MEM_dupallocN(pbvh->verts); | ||||
| pbvh->faces = MEM_dupallocN(pbvh->faces); | pbvh->looptri = MEM_dupallocN(pbvh->looptri); | ||||
| pbvh->deformed = 1; | pbvh->deformed = 1; | ||||
| } | } | ||||
| } | } | ||||
| if (pbvh->verts) { | if (pbvh->verts) { | ||||
| MVert *mvert = pbvh->verts; | MVert *mvert = pbvh->verts; | ||||
| /* copy new verts coords */ | /* copy new verts coords */ | ||||
| for (a = 0; a < pbvh->totvert; ++a, ++mvert) { | for (a = 0; a < pbvh->totvert; ++a, ++mvert) { | ||||
| copy_v3_v3(mvert->co, vertCos[a]); | copy_v3_v3(mvert->co, vertCos[a]); | ||||
| mvert->flag |= ME_VERT_PBVH_UPDATE; | mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| /* coordinates are new -- normals should also be updated */ | /* coordinates are new -- normals should also be updated */ | ||||
| BKE_mesh_calc_normals_tessface(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL); | BKE_mesh_calc_normals_looptri( | ||||
| pbvh->verts, pbvh->totvert, | |||||
| pbvh->mloop, | |||||
| pbvh->looptri, pbvh->totprim, | |||||
| NULL); | |||||
| for (a = 0; a < pbvh->totnode; ++a) | for (a = 0; a < pbvh->totnode; ++a) | ||||
| BKE_pbvh_node_mark_update(&pbvh->nodes[a]); | BKE_pbvh_node_mark_update(&pbvh->nodes[a]); | ||||
| BKE_pbvh_update(pbvh, PBVH_UpdateBB, NULL); | BKE_pbvh_update(pbvh, PBVH_UpdateBB, NULL); | ||||
| BKE_pbvh_update(pbvh, PBVH_UpdateOriginalBB, NULL); | BKE_pbvh_update(pbvh, PBVH_UpdateOriginalBB, NULL); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 145 Lines • Show Last 20 Lines | |||||
We may be able to use polys here? (no big deal though, this is cached I think)