Cleanup: use const for mesh functions
This commit is contained in:
parent
0875cb07cc
commit
f3d5af4172
|
@ -71,11 +71,11 @@ struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
|
|||
|
||||
int poly_find_loop_from_vert(
|
||||
const struct MPoly *poly,
|
||||
const struct MLoop *loopstart,
|
||||
unsigned vert);
|
||||
const struct MLoop *loopstart, unsigned vert);
|
||||
int poly_get_adj_loops_from_vert(
|
||||
unsigned r_adj[2], const struct MPoly *poly,
|
||||
const struct MLoop *mloop, unsigned vert);
|
||||
const struct MPoly *poly,
|
||||
const struct MLoop *mloop, unsigned int vert,
|
||||
unsigned int r_adj[2]);
|
||||
|
||||
int BKE_mesh_edge_other_vert(const struct MEdge *e, int v);
|
||||
|
||||
|
@ -96,12 +96,16 @@ int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex,
|
|||
struct Mesh *BKE_mesh_from_object(struct Object *ob);
|
||||
void BKE_mesh_assign_object(struct Object *ob, struct Mesh *me);
|
||||
void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me);
|
||||
int BKE_mesh_nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert,
|
||||
struct MEdge **alledge, int *totedge, struct MLoop **allloop, struct MPoly **allpoly,
|
||||
int *totloop, int *totpoly);
|
||||
int BKE_mesh_nurbs_displist_to_mdata(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert,
|
||||
struct MEdge **alledge, int *_totedge, struct MLoop **allloop, struct MPoly **allpoly,
|
||||
struct MLoopUV **alluv, int *_totloop, int *_totpoly);
|
||||
int BKE_mesh_nurbs_to_mdata(
|
||||
struct Object *ob, struct MVert **r_allvert, int *r_totvert,
|
||||
struct MEdge **r_alledge, int *r_totedge, struct MLoop **r_allloop, struct MPoly **r_allpoly,
|
||||
int *r_totloop, int *r_totpoly);
|
||||
int BKE_mesh_nurbs_displist_to_mdata(
|
||||
struct Object *ob, const struct ListBase *dispbase,
|
||||
struct MVert **r_allvert, int *r_totvert,
|
||||
struct MEdge **r_alledge, int *r_totedge,
|
||||
struct MLoop **r_allloop, struct MPoly **r_allpoly,
|
||||
struct MLoopUV **r_alluv, int *r_totloop, int *r_totpoly);
|
||||
void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase, const bool use_orco_uv);
|
||||
void BKE_mesh_from_nurbs(struct Object *ob);
|
||||
void BKE_mesh_to_curve_nurblist(struct DerivedMesh *dm, struct ListBase *nurblist, const int edge_users_test);
|
||||
|
@ -131,7 +135,7 @@ struct Mesh *BKE_mesh_new_from_object(struct Main *bmain, struct Scene *sce, str
|
|||
|
||||
/* vertex level transformations & checks (no derived mesh) */
|
||||
|
||||
bool BKE_mesh_minmax(struct Mesh *me, float r_min[3], float r_max[3]);
|
||||
bool BKE_mesh_minmax(const struct Mesh *me, float r_min[3], float r_max[3]);
|
||||
void BKE_mesh_transform(struct Mesh *me, float mat[4][4], bool do_keys);
|
||||
void BKE_mesh_translate(struct Mesh *me, const float offset[3], const bool do_keys);
|
||||
|
||||
|
@ -156,26 +160,28 @@ void BKE_mesh_mselect_active_set(struct Mesh *me, int index, int type);
|
|||
|
||||
void BKE_mesh_calc_normals_mapping(
|
||||
struct MVert *mverts, int numVerts,
|
||||
struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3]);
|
||||
const struct MLoop *mloop, const struct MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
const struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3]);
|
||||
void BKE_mesh_calc_normals_mapping_ex(
|
||||
struct MVert *mverts, int numVerts,
|
||||
struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3],
|
||||
const struct MLoop *mloop, const struct MPoly *mpolys,
|
||||
int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
const struct MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3],
|
||||
const bool only_face_normals);
|
||||
void BKE_mesh_calc_normals_poly(
|
||||
struct MVert *mverts, int numVerts,
|
||||
struct MLoop *mloop, struct MPoly *mpolys,
|
||||
const struct MLoop *mloop, const struct MPoly *mpolys,
|
||||
int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
const bool only_face_normals);
|
||||
void BKE_mesh_calc_normals(struct Mesh *me);
|
||||
void BKE_mesh_calc_normals_tessface(
|
||||
struct MVert *mverts, int numVerts,
|
||||
struct MFace *mfaces, int numFaces,
|
||||
const struct MFace *mfaces, int numFaces,
|
||||
float (*r_faceNors)[3]);
|
||||
void BKE_mesh_loop_tangents_ex(
|
||||
struct MVert *mverts, const int numVerts, struct MLoop *mloops, float (*r_looptangent)[4], float (*loopnors)[3],
|
||||
struct MLoopUV *loopuv, const int numLoops, struct MPoly *mpolys, const int numPolys,
|
||||
const struct MVert *mverts, const int numVerts, const struct MLoop *mloops,
|
||||
float (*r_looptangent)[4], float (*loopnors)[3], const struct MLoopUV *loopuv,
|
||||
const int numLoops, const struct MPoly *mpolys, const int numPolys,
|
||||
struct ReportList *reports);
|
||||
void BKE_mesh_loop_tangents(
|
||||
struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
|
||||
|
@ -213,38 +219,39 @@ void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float
|
|||
|
||||
bool BKE_mesh_has_custom_loop_normals(struct Mesh *me);
|
||||
|
||||
void BKE_mesh_normals_loop_split(struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
|
||||
void BKE_mesh_normals_loop_split(
|
||||
const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
|
||||
struct MLoop *mloops, float (*r_loopnors)[3], const int numLoops,
|
||||
struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
|
||||
const bool use_split_normals, float split_angle,
|
||||
MLoopNorSpaceArray *r_lnors_spacearr, short (*clnors_data)[2], int *r_loop_to_poly);
|
||||
|
||||
void BKE_mesh_normals_loop_custom_set(
|
||||
struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
|
||||
const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
|
||||
struct MLoop *mloops, float (*custom_loopnors)[3], const int numLoops,
|
||||
struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
|
||||
short (*r_clnors_data)[2]);
|
||||
void BKE_mesh_normals_loop_custom_from_vertices_set(
|
||||
struct MVert *mverts, float (*custom_vertnors)[3], const int numVerts,
|
||||
const struct MVert *mverts, float (*custom_vertnors)[3], const int numVerts,
|
||||
struct MEdge *medges, const int numEdges, struct MLoop *mloops, const int numLoops,
|
||||
struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
|
||||
short (*r_clnors_data)[2]);
|
||||
|
||||
void BKE_mesh_calc_poly_normal(
|
||||
struct MPoly *mpoly, struct MLoop *loopstart,
|
||||
struct MVert *mvarray, float no[3]);
|
||||
const struct MPoly *mpoly, const struct MLoop *loopstart,
|
||||
const struct MVert *mvarray, float r_no[3]);
|
||||
void BKE_mesh_calc_poly_normal_coords(
|
||||
struct MPoly *mpoly, struct MLoop *loopstart,
|
||||
const float (*vertex_coords)[3], float no[3]);
|
||||
const struct MPoly *mpoly, const struct MLoop *loopstart,
|
||||
const float (*vertex_coords)[3], float r_no[3]);
|
||||
void BKE_mesh_calc_poly_center(
|
||||
struct MPoly *mpoly, struct MLoop *loopstart,
|
||||
struct MVert *mvarray, float cent[3]);
|
||||
const struct MPoly *mpoly, const struct MLoop *loopstart,
|
||||
const struct MVert *mvarray, float r_cent[3]);
|
||||
float BKE_mesh_calc_poly_area(
|
||||
struct MPoly *mpoly, struct MLoop *loopstart,
|
||||
struct MVert *mvarray);
|
||||
const struct MPoly *mpoly, const struct MLoop *loopstart,
|
||||
const struct MVert *mvarray);
|
||||
void BKE_mesh_calc_poly_angles(
|
||||
struct MPoly *mpoly, struct MLoop *loopstart,
|
||||
struct MVert *mvarray, float angles[]);
|
||||
const struct MPoly *mpoly, const struct MLoop *loopstart,
|
||||
const struct MVert *mvarray, float angles[]);
|
||||
|
||||
void BKE_mesh_poly_edgehash_insert(
|
||||
struct EdgeHash *ehash,
|
||||
|
@ -254,13 +261,14 @@ void BKE_mesh_poly_edgebitmap_insert(
|
|||
const struct MPoly *mp, const struct MLoop *mloop);
|
||||
|
||||
|
||||
bool BKE_mesh_center_median(struct Mesh *me, float cent[3]);
|
||||
bool BKE_mesh_center_bounds(struct Mesh *me, float cent[3]);
|
||||
bool BKE_mesh_center_centroid(struct Mesh *me, float cent[3]);
|
||||
bool BKE_mesh_center_median(const struct Mesh *me, float r_cent[3]);
|
||||
bool BKE_mesh_center_bounds(const struct Mesh *me, float r_cent[3]);
|
||||
bool BKE_mesh_center_centroid(const struct Mesh *me, float r_cent[3]);
|
||||
|
||||
void BKE_mesh_calc_volume(struct MVert *mverts, int numVerts,
|
||||
struct MFace *mfaces, int numFaces,
|
||||
float *r_vol, float *r_com);
|
||||
void BKE_mesh_calc_volume(
|
||||
const struct MVert *mverts, const int numVerts,
|
||||
const struct MFace *mfaces, const int numFaces,
|
||||
float *r_vol, float *r_com);
|
||||
|
||||
/* tessface */
|
||||
void BKE_mesh_loops_to_mface_corners(
|
||||
|
|
|
@ -59,8 +59,9 @@ typedef void (*BKE_pbvh_HitOccludedCallback)(PBVHNode *node, void *data, float *
|
|||
/* Building */
|
||||
|
||||
PBVH *BKE_pbvh_new(void);
|
||||
void BKE_pbvh_build_mesh(PBVH *bvh, struct MFace *faces, struct MVert *verts,
|
||||
int totface, int totvert, struct CustomData *vdata);
|
||||
void BKE_pbvh_build_mesh(
|
||||
PBVH *bvh, const struct MFace *faces, struct MVert *verts,
|
||||
int totface, int totvert, struct CustomData *vdata);
|
||||
void BKE_pbvh_build_grids(PBVH *bvh, struct CCGElem **grid_elems,
|
||||
int totgrid,
|
||||
struct CCGKey *key, void **gridfaces, struct DMFlagMat *flagmats,
|
||||
|
|
|
@ -1175,9 +1175,10 @@ static void make_edges_mdata_extend(MEdge **r_alledge, int *r_totedge,
|
|||
|
||||
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
|
||||
/* return non-zero on error */
|
||||
int BKE_mesh_nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
|
||||
MEdge **alledge, int *totedge, MLoop **allloop, MPoly **allpoly,
|
||||
int *totloop, int *totpoly)
|
||||
int BKE_mesh_nurbs_to_mdata(
|
||||
Object *ob, MVert **r_allvert, int *r_totvert,
|
||||
MEdge **r_alledge, int *r_totedge, MLoop **r_allloop, MPoly **r_allpoly,
|
||||
int *r_totloop, int *r_totpoly)
|
||||
{
|
||||
ListBase disp = {NULL, NULL};
|
||||
|
||||
|
@ -1185,11 +1186,12 @@ int BKE_mesh_nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
|
|||
disp = ob->curve_cache->disp;
|
||||
}
|
||||
|
||||
return BKE_mesh_nurbs_displist_to_mdata(ob, &disp,
|
||||
allvert, totvert,
|
||||
alledge, totedge,
|
||||
allloop, allpoly, NULL,
|
||||
totloop, totpoly);
|
||||
return BKE_mesh_nurbs_displist_to_mdata(
|
||||
ob, &disp,
|
||||
r_allvert, r_totvert,
|
||||
r_alledge, r_totedge,
|
||||
r_allloop, r_allpoly, NULL,
|
||||
r_totloop, r_totpoly);
|
||||
}
|
||||
|
||||
/* BMESH: this doesn't calculate all edges from polygons,
|
||||
|
@ -1197,12 +1199,13 @@ int BKE_mesh_nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
|
|||
|
||||
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
|
||||
/* use specified dispbase */
|
||||
int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase,
|
||||
MVert **allvert, int *_totvert,
|
||||
MEdge **alledge, int *_totedge,
|
||||
MLoop **allloop, MPoly **allpoly,
|
||||
MLoopUV **alluv,
|
||||
int *_totloop, int *_totpoly)
|
||||
int BKE_mesh_nurbs_displist_to_mdata(
|
||||
Object *ob, const ListBase *dispbase,
|
||||
MVert **r_allvert, int *r_totvert,
|
||||
MEdge **r_alledge, int *r_totedge,
|
||||
MLoop **r_allloop, MPoly **r_allpoly,
|
||||
MLoopUV **r_alluv,
|
||||
int *r_totloop, int *r_totpoly)
|
||||
{
|
||||
Curve *cu = ob->data;
|
||||
DispList *dl;
|
||||
|
@ -1253,13 +1256,13 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase,
|
|||
return -1;
|
||||
}
|
||||
|
||||
*allvert = mvert = MEM_callocN(sizeof(MVert) * totvert, "nurbs_init mvert");
|
||||
*alledge = medge = MEM_callocN(sizeof(MEdge) * totedge, "nurbs_init medge");
|
||||
*allloop = mloop = MEM_callocN(sizeof(MLoop) * totvlak * 4, "nurbs_init mloop"); // totloop
|
||||
*allpoly = mpoly = MEM_callocN(sizeof(MPoly) * totvlak, "nurbs_init mloop");
|
||||
*r_allvert = mvert = MEM_callocN(sizeof(MVert) * totvert, "nurbs_init mvert");
|
||||
*r_alledge = medge = MEM_callocN(sizeof(MEdge) * totedge, "nurbs_init medge");
|
||||
*r_allloop = mloop = MEM_callocN(sizeof(MLoop) * totvlak * 4, "nurbs_init mloop"); // totloop
|
||||
*r_allpoly = mpoly = MEM_callocN(sizeof(MPoly) * totvlak, "nurbs_init mloop");
|
||||
|
||||
if (alluv)
|
||||
*alluv = mloopuv = MEM_callocN(sizeof(MLoopUV) * totvlak * 4, "nurbs_init mloopuv");
|
||||
if (r_alluv)
|
||||
*r_alluv = mloopuv = MEM_callocN(sizeof(MLoopUV) * totvlak * 4, "nurbs_init mloopuv");
|
||||
|
||||
/* verts and faces */
|
||||
vertcount = 0;
|
||||
|
@ -1332,7 +1335,7 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase,
|
|||
mloop[0].v = startvert + index[0];
|
||||
mloop[1].v = startvert + index[2];
|
||||
mloop[2].v = startvert + index[1];
|
||||
mpoly->loopstart = (int)(mloop - (*allloop));
|
||||
mpoly->loopstart = (int)(mloop - (*r_allloop));
|
||||
mpoly->totloop = 3;
|
||||
mpoly->mat_nr = dl->col;
|
||||
|
||||
|
@ -1390,7 +1393,7 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase,
|
|||
mloop[1].v = p3;
|
||||
mloop[2].v = p4;
|
||||
mloop[3].v = p2;
|
||||
mpoly->loopstart = (int)(mloop - (*allloop));
|
||||
mpoly->loopstart = (int)(mloop - (*r_allloop));
|
||||
mpoly->totloop = 4;
|
||||
mpoly->mat_nr = dl->col;
|
||||
|
||||
|
@ -1440,14 +1443,14 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase,
|
|||
}
|
||||
|
||||
if (totvlak) {
|
||||
make_edges_mdata_extend(alledge, &totedge,
|
||||
*allpoly, *allloop, totvlak);
|
||||
make_edges_mdata_extend(r_alledge, &totedge,
|
||||
*r_allpoly, *r_allloop, totvlak);
|
||||
}
|
||||
|
||||
*_totpoly = totvlak;
|
||||
*_totloop = totloop;
|
||||
*_totedge = totedge;
|
||||
*_totvert = totvert;
|
||||
*r_totpoly = totvlak;
|
||||
*r_totloop = totloop;
|
||||
*r_totedge = totedge;
|
||||
*r_totvert = totvert;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1871,8 +1874,9 @@ int poly_find_loop_from_vert(
|
|||
* vertex is not in \a poly
|
||||
*/
|
||||
int poly_get_adj_loops_from_vert(
|
||||
unsigned r_adj[2], const MPoly *poly,
|
||||
const MLoop *mloop, unsigned vert)
|
||||
const MPoly *poly,
|
||||
const MLoop *mloop, unsigned int vert,
|
||||
unsigned int r_adj[2])
|
||||
{
|
||||
int corner = poly_find_loop_from_vert(poly,
|
||||
&mloop[poly->loopstart],
|
||||
|
@ -1906,7 +1910,7 @@ int BKE_mesh_edge_other_vert(const MEdge *e, int v)
|
|||
}
|
||||
|
||||
/* basic vertex data functions */
|
||||
bool BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3])
|
||||
bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3])
|
||||
{
|
||||
int i = me->totvert;
|
||||
MVert *mvert;
|
||||
|
|
|
@ -89,26 +89,28 @@ static void mesh_calc_normals_vert_fallback(MVert *mverts, int numVerts)
|
|||
/* Calculate vertex and face normals, face normals are returned in *r_faceNors if non-NULL
|
||||
* and vertex normals are stored in actual mverts.
|
||||
*/
|
||||
void BKE_mesh_calc_normals_mapping(MVert *mverts, int numVerts,
|
||||
MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3])
|
||||
void BKE_mesh_calc_normals_mapping(
|
||||
MVert *mverts, int numVerts,
|
||||
const MLoop *mloop, const MPoly *mpolys, int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
const MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3])
|
||||
{
|
||||
BKE_mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys,
|
||||
numLoops, numPolys, r_polyNors, mfaces, numFaces,
|
||||
origIndexFace, r_faceNors, false);
|
||||
BKE_mesh_calc_normals_mapping_ex(
|
||||
mverts, numVerts, mloop, mpolys,
|
||||
numLoops, numPolys, r_polyNors, mfaces, numFaces,
|
||||
origIndexFace, r_faceNors, false);
|
||||
}
|
||||
/* extended version of 'BKE_mesh_calc_normals_poly' with option not to calc vertex normals */
|
||||
void BKE_mesh_calc_normals_mapping_ex(
|
||||
MVert *mverts, int numVerts,
|
||||
MLoop *mloop, MPoly *mpolys,
|
||||
const MLoop *mloop, const MPoly *mpolys,
|
||||
int numLoops, int numPolys, float (*r_polyNors)[3],
|
||||
MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3],
|
||||
const MFace *mfaces, int numFaces, const int *origIndexFace, float (*r_faceNors)[3],
|
||||
const bool only_face_normals)
|
||||
{
|
||||
float (*pnors)[3] = r_polyNors, (*fnors)[3] = r_faceNors;
|
||||
int i;
|
||||
MFace *mf;
|
||||
MPoly *mp;
|
||||
const MFace *mf;
|
||||
const MPoly *mp;
|
||||
|
||||
if (numPolys == 0) {
|
||||
if (only_face_normals == false) {
|
||||
|
@ -164,8 +166,10 @@ void BKE_mesh_calc_normals_mapping_ex(
|
|||
|
||||
}
|
||||
|
||||
static void mesh_calc_normals_poly_accum(MPoly *mp, MLoop *ml,
|
||||
MVert *mvert, float polyno[3], float (*tnorms)[3])
|
||||
static void mesh_calc_normals_poly_accum(
|
||||
const MPoly *mp, const MLoop *ml,
|
||||
const MVert *mvert,
|
||||
float r_polyno[3], float (*r_tnorms)[3])
|
||||
{
|
||||
const int nverts = mp->totloop;
|
||||
float (*edgevecbuf)[3] = BLI_array_alloca(edgevecbuf, (size_t)nverts);
|
||||
|
@ -178,11 +182,11 @@ static void mesh_calc_normals_poly_accum(MPoly *mp, MLoop *ml,
|
|||
const float *v_prev = mvert[ml[i_prev].v].co;
|
||||
const float *v_curr;
|
||||
|
||||
zero_v3(polyno);
|
||||
zero_v3(r_polyno);
|
||||
/* Newell's Method */
|
||||
for (i = 0; i < nverts; i++) {
|
||||
v_curr = mvert[ml[i].v].co;
|
||||
add_newell_cross_v3_v3v3(polyno, v_prev, v_curr);
|
||||
add_newell_cross_v3_v3v3(r_polyno, v_prev, v_curr);
|
||||
|
||||
/* Unrelated to normalize, calculate edge-vector */
|
||||
sub_v3_v3v3(edgevecbuf[i_prev], v_prev, v_curr);
|
||||
|
@ -191,8 +195,8 @@ static void mesh_calc_normals_poly_accum(MPoly *mp, MLoop *ml,
|
|||
|
||||
v_prev = v_curr;
|
||||
}
|
||||
if (UNLIKELY(normalize_v3(polyno) == 0.0f)) {
|
||||
polyno[2] = 1.0f; /* other axis set to 0.0 */
|
||||
if (UNLIKELY(normalize_v3(r_polyno) == 0.0f)) {
|
||||
r_polyno[2] = 1.0f; /* other axis set to 0.0 */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,21 +213,23 @@ static void mesh_calc_normals_poly_accum(MPoly *mp, MLoop *ml,
|
|||
const float fac = saacos(-dot_v3v3(cur_edge, prev_edge));
|
||||
|
||||
/* accumulate */
|
||||
madd_v3_v3fl(tnorms[ml[i].v], polyno, fac);
|
||||
madd_v3_v3fl(r_tnorms[ml[i].v], r_polyno, fac);
|
||||
prev_edge = cur_edge;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_normals_poly(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
|
||||
int UNUSED(numLoops), int numPolys, float (*r_polynors)[3],
|
||||
const bool only_face_normals)
|
||||
void BKE_mesh_calc_normals_poly(
|
||||
MVert *mverts, int numVerts,
|
||||
const MLoop *mloop, const MPoly *mpolys,
|
||||
int UNUSED(numLoops), int numPolys, float (*r_polynors)[3],
|
||||
const bool only_face_normals)
|
||||
{
|
||||
float (*pnors)[3] = r_polynors;
|
||||
float (*tnorms)[3];
|
||||
int i;
|
||||
MPoly *mp;
|
||||
const MPoly *mp;
|
||||
|
||||
if (only_face_normals) {
|
||||
BLI_assert((pnors != NULL) || (numPolys == 0));
|
||||
|
@ -280,14 +286,17 @@ void BKE_mesh_calc_normals(Mesh *mesh)
|
|||
#endif
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*r_faceNors)[3])
|
||||
void BKE_mesh_calc_normals_tessface(
|
||||
MVert *mverts, int numVerts,
|
||||
const MFace *mfaces, int numFaces,
|
||||
float (*r_faceNors)[3])
|
||||
{
|
||||
float (*tnorms)[3] = MEM_callocN(sizeof(*tnorms) * (size_t)numVerts, "tnorms");
|
||||
float (*fnors)[3] = (r_faceNors) ? r_faceNors : MEM_callocN(sizeof(*fnors) * (size_t)numFaces, "meshnormals");
|
||||
int i;
|
||||
|
||||
for (i = 0; i < numFaces; i++) {
|
||||
MFace *mf = &mfaces[i];
|
||||
const MFace *mf = &mfaces[i];
|
||||
float *f_no = fnors[i];
|
||||
float *n4 = (mf->v4) ? tnorms[mf->v4] : NULL;
|
||||
const float *c4 = (mf->v4) ? mverts[mf->v4].co : NULL;
|
||||
|
@ -1061,7 +1070,7 @@ static void loop_split_generator(TaskPool *UNUSED(pool), void *taskdata, int UNU
|
|||
* Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry (splitting edges).
|
||||
*/
|
||||
void BKE_mesh_normals_loop_split(
|
||||
MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
|
||||
const MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
|
||||
MLoop *mloops, float (*r_loopnors)[3], const int numLoops,
|
||||
MPoly *mpolys, const float (*polynors)[3], const int numPolys,
|
||||
const bool use_split_normals, float split_angle,
|
||||
|
@ -1287,7 +1296,7 @@ void BKE_mesh_normals_loop_split(
|
|||
* (this allows to set whole vert's normals at once, useful in some cases).
|
||||
*/
|
||||
static void mesh_normals_loop_custom_set(
|
||||
MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
|
||||
const MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
|
||||
MLoop *mloops, float (*custom_loopnors)[3], const int numLoops,
|
||||
MPoly *mpolys, const float (*polynors)[3], const int numPolys,
|
||||
short (*r_clnors_data)[2], const bool use_vertices)
|
||||
|
@ -1453,7 +1462,7 @@ static void mesh_normals_loop_custom_set(
|
|||
}
|
||||
|
||||
void BKE_mesh_normals_loop_custom_set(
|
||||
MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
|
||||
const MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
|
||||
MLoop *mloops, float (*custom_loopnors)[3], const int numLoops,
|
||||
MPoly *mpolys, const float (*polynors)[3], const int numPolys,
|
||||
short (*r_clnors_data)[2])
|
||||
|
@ -1463,7 +1472,7 @@ void BKE_mesh_normals_loop_custom_set(
|
|||
}
|
||||
|
||||
void BKE_mesh_normals_loop_custom_from_vertices_set(
|
||||
MVert *mverts, float (*custom_vertnors)[3], const int numVerts,
|
||||
const MVert *mverts, float (*custom_vertnors)[3], const int numVerts,
|
||||
MEdge *medges, const int numEdges, MLoop *mloops, const int numLoops,
|
||||
MPoly *mpolys, const float (*polynors)[3], const int numPolys,
|
||||
short (*r_clnors_data)[2])
|
||||
|
@ -1486,10 +1495,10 @@ void BKE_mesh_normals_loop_custom_from_vertices_set(
|
|||
|
||||
/* User data. */
|
||||
typedef struct {
|
||||
MPoly *mpolys; /* faces */
|
||||
MLoop *mloops; /* faces's vertices */
|
||||
MVert *mverts; /* vertices */
|
||||
MLoopUV *luvs; /* texture coordinates */
|
||||
const MPoly *mpolys; /* faces */
|
||||
const MLoop *mloops; /* faces's vertices */
|
||||
const MVert *mverts; /* vertices */
|
||||
const MLoopUV *luvs; /* texture coordinates */
|
||||
float (*lnors)[3]; /* loops' normals */
|
||||
float (*tangents)[4]; /* output tangents */
|
||||
int num_polys; /* number of polygons */
|
||||
|
@ -1542,15 +1551,17 @@ static void set_tspace(const SMikkTSpaceContext *pContext, const float fv_tangen
|
|||
* split normals can be used to recreate the full tangent space.
|
||||
* Note: * The mesh should be made of only tris and quads!
|
||||
*/
|
||||
void BKE_mesh_loop_tangents_ex(MVert *mverts, const int UNUSED(numVerts), MLoop *mloops,
|
||||
float (*r_looptangent)[4], float (*loopnors)[3], MLoopUV *loopuvs,
|
||||
const int UNUSED(numLoops), MPoly *mpolys, const int numPolys, ReportList *reports)
|
||||
void BKE_mesh_loop_tangents_ex(
|
||||
const MVert *mverts, const int UNUSED(numVerts), const MLoop *mloops,
|
||||
float (*r_looptangent)[4], float (*loopnors)[3], const MLoopUV *loopuvs,
|
||||
const int UNUSED(numLoops), const MPoly *mpolys, const int numPolys,
|
||||
ReportList *reports)
|
||||
{
|
||||
BKEMeshToTangent mesh_to_tangent = {NULL};
|
||||
SMikkTSpaceContext s_context = {NULL};
|
||||
SMikkTSpaceInterface s_interface = {NULL};
|
||||
|
||||
MPoly *mp;
|
||||
const MPoly *mp;
|
||||
int mp_index;
|
||||
|
||||
/* First check we do have a tris/quads only mesh. */
|
||||
|
@ -1587,8 +1598,9 @@ void BKE_mesh_loop_tangents_ex(MVert *mverts, const int UNUSED(numVerts), MLoop
|
|||
|
||||
/**
|
||||
* Wrapper around BKE_mesh_loop_tangents_ex, which takes care of most boiling code.
|
||||
* Note: * There must be a valid loop's CD_NORMALS available.
|
||||
* * The mesh should be made of only tris and quads!
|
||||
* \note
|
||||
* - There must be a valid loop's CD_NORMALS available.
|
||||
* - The mesh should be made of only tris and quads!
|
||||
*/
|
||||
void BKE_mesh_loop_tangents(Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], ReportList *reports)
|
||||
{
|
||||
|
@ -1633,8 +1645,9 @@ void BKE_mesh_loop_tangents(Mesh *mesh, const char *uvmap, float (*r_looptangent
|
|||
* computing newell normal.
|
||||
*
|
||||
*/
|
||||
static void mesh_calc_ngon_normal(MPoly *mpoly, MLoop *loopstart,
|
||||
MVert *mvert, float normal[3])
|
||||
static void mesh_calc_ngon_normal(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const MVert *mvert, float normal[3])
|
||||
{
|
||||
const int nverts = mpoly->totloop;
|
||||
const float *v_prev = mvert[loopstart[nverts - 1].v].co;
|
||||
|
@ -1655,21 +1668,22 @@ static void mesh_calc_ngon_normal(MPoly *mpoly, MLoop *loopstart,
|
|||
}
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_poly_normal(MPoly *mpoly, MLoop *loopstart,
|
||||
MVert *mvarray, float no[3])
|
||||
void BKE_mesh_calc_poly_normal(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const MVert *mvarray, float r_no[3])
|
||||
{
|
||||
if (mpoly->totloop > 4) {
|
||||
mesh_calc_ngon_normal(mpoly, loopstart, mvarray, no);
|
||||
mesh_calc_ngon_normal(mpoly, loopstart, mvarray, r_no);
|
||||
}
|
||||
else if (mpoly->totloop == 3) {
|
||||
normal_tri_v3(no,
|
||||
normal_tri_v3(r_no,
|
||||
mvarray[loopstart[0].v].co,
|
||||
mvarray[loopstart[1].v].co,
|
||||
mvarray[loopstart[2].v].co
|
||||
);
|
||||
}
|
||||
else if (mpoly->totloop == 4) {
|
||||
normal_quad_v3(no,
|
||||
normal_quad_v3(r_no,
|
||||
mvarray[loopstart[0].v].co,
|
||||
mvarray[loopstart[1].v].co,
|
||||
mvarray[loopstart[2].v].co,
|
||||
|
@ -1677,49 +1691,51 @@ void BKE_mesh_calc_poly_normal(MPoly *mpoly, MLoop *loopstart,
|
|||
);
|
||||
}
|
||||
else { /* horrible, two sided face! */
|
||||
no[0] = 0.0;
|
||||
no[1] = 0.0;
|
||||
no[2] = 1.0;
|
||||
r_no[0] = 0.0;
|
||||
r_no[1] = 0.0;
|
||||
r_no[2] = 1.0;
|
||||
}
|
||||
}
|
||||
/* duplicate of function above _but_ takes coords rather then mverts */
|
||||
static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart,
|
||||
const float (*vertex_coords)[3], float normal[3])
|
||||
static void mesh_calc_ngon_normal_coords(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const float (*vertex_coords)[3], float r_normal[3])
|
||||
{
|
||||
const int nverts = mpoly->totloop;
|
||||
const float *v_prev = vertex_coords[loopstart[nverts - 1].v];
|
||||
const float *v_curr;
|
||||
int i;
|
||||
|
||||
zero_v3(normal);
|
||||
zero_v3(r_normal);
|
||||
|
||||
/* Newell's Method */
|
||||
for (i = 0; i < nverts; i++) {
|
||||
v_curr = vertex_coords[loopstart[i].v];
|
||||
add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
|
||||
add_newell_cross_v3_v3v3(r_normal, v_prev, v_curr);
|
||||
v_prev = v_curr;
|
||||
}
|
||||
|
||||
if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
|
||||
normal[2] = 1.0f; /* other axis set to 0.0 */
|
||||
if (UNLIKELY(normalize_v3(r_normal) == 0.0f)) {
|
||||
r_normal[2] = 1.0f; /* other axis set to 0.0 */
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart,
|
||||
const float (*vertex_coords)[3], float no[3])
|
||||
void BKE_mesh_calc_poly_normal_coords(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const float (*vertex_coords)[3], float r_no[3])
|
||||
{
|
||||
if (mpoly->totloop > 4) {
|
||||
mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, no);
|
||||
mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, r_no);
|
||||
}
|
||||
else if (mpoly->totloop == 3) {
|
||||
normal_tri_v3(no,
|
||||
normal_tri_v3(r_no,
|
||||
vertex_coords[loopstart[0].v],
|
||||
vertex_coords[loopstart[1].v],
|
||||
vertex_coords[loopstart[2].v]
|
||||
);
|
||||
}
|
||||
else if (mpoly->totloop == 4) {
|
||||
normal_quad_v3(no,
|
||||
normal_quad_v3(r_no,
|
||||
vertex_coords[loopstart[0].v],
|
||||
vertex_coords[loopstart[1].v],
|
||||
vertex_coords[loopstart[2].v],
|
||||
|
@ -1727,14 +1743,15 @@ void BKE_mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart,
|
|||
);
|
||||
}
|
||||
else { /* horrible, two sided face! */
|
||||
no[0] = 0.0;
|
||||
no[1] = 0.0;
|
||||
no[2] = 1.0;
|
||||
r_no[0] = 0.0;
|
||||
r_no[1] = 0.0;
|
||||
r_no[2] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_calc_ngon_center(MPoly *mpoly, MLoop *loopstart,
|
||||
MVert *mvert, float cent[3])
|
||||
static void mesh_calc_ngon_center(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const MVert *mvert, float cent[3])
|
||||
{
|
||||
const float w = 1.0f / (float)mpoly->totloop;
|
||||
int i;
|
||||
|
@ -1746,18 +1763,19 @@ static void mesh_calc_ngon_center(MPoly *mpoly, MLoop *loopstart,
|
|||
}
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_poly_center(MPoly *mpoly, MLoop *loopstart,
|
||||
MVert *mvarray, float cent[3])
|
||||
void BKE_mesh_calc_poly_center(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const MVert *mvarray, float r_cent[3])
|
||||
{
|
||||
if (mpoly->totloop == 3) {
|
||||
cent_tri_v3(cent,
|
||||
cent_tri_v3(r_cent,
|
||||
mvarray[loopstart[0].v].co,
|
||||
mvarray[loopstart[1].v].co,
|
||||
mvarray[loopstart[2].v].co
|
||||
);
|
||||
}
|
||||
else if (mpoly->totloop == 4) {
|
||||
cent_quad_v3(cent,
|
||||
cent_quad_v3(r_cent,
|
||||
mvarray[loopstart[0].v].co,
|
||||
mvarray[loopstart[1].v].co,
|
||||
mvarray[loopstart[2].v].co,
|
||||
|
@ -1765,13 +1783,14 @@ void BKE_mesh_calc_poly_center(MPoly *mpoly, MLoop *loopstart,
|
|||
);
|
||||
}
|
||||
else {
|
||||
mesh_calc_ngon_center(mpoly, loopstart, mvarray, cent);
|
||||
mesh_calc_ngon_center(mpoly, loopstart, mvarray, r_cent);
|
||||
}
|
||||
}
|
||||
|
||||
/* note, passing polynormal is only a speedup so we can skip calculating it */
|
||||
float BKE_mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart,
|
||||
MVert *mvarray)
|
||||
float BKE_mesh_calc_poly_area(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const MVert *mvarray)
|
||||
{
|
||||
if (mpoly->totloop == 3) {
|
||||
return area_tri_v3(mvarray[loopstart[0].v].co,
|
||||
|
@ -1781,7 +1800,7 @@ float BKE_mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart,
|
|||
}
|
||||
else {
|
||||
int i;
|
||||
MLoop *l_iter = loopstart;
|
||||
const MLoop *l_iter = loopstart;
|
||||
float area;
|
||||
float (*vertexcos)[3] = BLI_array_alloca(vertexcos, (size_t)mpoly->totloop);
|
||||
|
||||
|
@ -1798,7 +1817,9 @@ float BKE_mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart,
|
|||
}
|
||||
|
||||
/* note, results won't be correct if polygon is non-planar */
|
||||
static float mesh_calc_poly_planar_area_centroid(MPoly *mpoly, MLoop *loopstart, MVert *mvarray, float cent[3])
|
||||
static float mesh_calc_poly_planar_area_centroid(
|
||||
const MPoly *mpoly, const MLoop *loopstart, const MVert *mvarray,
|
||||
float r_cent[3])
|
||||
{
|
||||
int i;
|
||||
float tri_area;
|
||||
|
@ -1808,7 +1829,7 @@ static float mesh_calc_poly_planar_area_centroid(MPoly *mpoly, MLoop *loopstart,
|
|||
BKE_mesh_calc_poly_normal(mpoly, loopstart, mvarray, normal);
|
||||
copy_v3_v3(v1, mvarray[loopstart[0].v].co);
|
||||
copy_v3_v3(v2, mvarray[loopstart[1].v].co);
|
||||
zero_v3(cent);
|
||||
zero_v3(r_cent);
|
||||
|
||||
for (i = 2; i < mpoly->totloop; i++) {
|
||||
copy_v3_v3(v3, mvarray[loopstart[i].v].co);
|
||||
|
@ -1817,12 +1838,12 @@ static float mesh_calc_poly_planar_area_centroid(MPoly *mpoly, MLoop *loopstart,
|
|||
total_area += tri_area;
|
||||
|
||||
cent_tri_v3(tri_cent, v1, v2, v3);
|
||||
madd_v3_v3fl(cent, tri_cent, tri_area);
|
||||
madd_v3_v3fl(r_cent, tri_cent, tri_area);
|
||||
|
||||
copy_v3_v3(v2, v3);
|
||||
}
|
||||
|
||||
mul_v3_fl(cent, 1.0f / total_area);
|
||||
mul_v3_fl(r_cent, 1.0f / total_area);
|
||||
|
||||
return total_area;
|
||||
}
|
||||
|
@ -1850,8 +1871,9 @@ void BKE_mesh_calc_poly_angles(MPoly *mpoly, MLoop *loopstart,
|
|||
|
||||
#else /* equivalent the function above but avoid multiple subtractions + normalize */
|
||||
|
||||
void BKE_mesh_calc_poly_angles(MPoly *mpoly, MLoop *loopstart,
|
||||
MVert *mvarray, float angles[])
|
||||
void BKE_mesh_calc_poly_angles(
|
||||
const MPoly *mpoly, const MLoop *loopstart,
|
||||
const MVert *mvarray, float angles[])
|
||||
{
|
||||
float nor_prev[3];
|
||||
float nor_next[3];
|
||||
|
@ -1912,35 +1934,35 @@ void BKE_mesh_poly_edgebitmap_insert(unsigned int *edge_bitmap, const MPoly *mp,
|
|||
/** \name Mesh Center Calculation
|
||||
* \{ */
|
||||
|
||||
bool BKE_mesh_center_median(Mesh *me, float cent[3])
|
||||
bool BKE_mesh_center_median(const Mesh *me, float r_cent[3])
|
||||
{
|
||||
int i = me->totvert;
|
||||
MVert *mvert;
|
||||
zero_v3(cent);
|
||||
const MVert *mvert;
|
||||
zero_v3(r_cent);
|
||||
for (mvert = me->mvert; i--; mvert++) {
|
||||
add_v3_v3(cent, mvert->co);
|
||||
add_v3_v3(r_cent, mvert->co);
|
||||
}
|
||||
/* otherwise we get NAN for 0 verts */
|
||||
if (me->totvert) {
|
||||
mul_v3_fl(cent, 1.0f / (float)me->totvert);
|
||||
mul_v3_fl(r_cent, 1.0f / (float)me->totvert);
|
||||
}
|
||||
|
||||
return (me->totvert != 0);
|
||||
}
|
||||
|
||||
bool BKE_mesh_center_bounds(Mesh *me, float cent[3])
|
||||
bool BKE_mesh_center_bounds(const Mesh *me, float r_cent[3])
|
||||
{
|
||||
float min[3], max[3];
|
||||
INIT_MINMAX(min, max);
|
||||
if (BKE_mesh_minmax(me, min, max)) {
|
||||
mid_v3_v3v3(cent, min, max);
|
||||
mid_v3_v3v3(r_cent, min, max);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BKE_mesh_center_centroid(Mesh *me, float cent[3])
|
||||
bool BKE_mesh_center_centroid(const Mesh *me, float r_cent[3])
|
||||
{
|
||||
int i = me->totpoly;
|
||||
MPoly *mpoly;
|
||||
|
@ -1948,23 +1970,23 @@ bool BKE_mesh_center_centroid(Mesh *me, float cent[3])
|
|||
float total_area = 0.0f;
|
||||
float poly_cent[3];
|
||||
|
||||
zero_v3(cent);
|
||||
zero_v3(r_cent);
|
||||
|
||||
/* calculate a weighted average of polygon centroids */
|
||||
for (mpoly = me->mpoly; i--; mpoly++) {
|
||||
poly_area = mesh_calc_poly_planar_area_centroid(mpoly, me->mloop + mpoly->loopstart, me->mvert, poly_cent);
|
||||
|
||||
madd_v3_v3fl(cent, poly_cent, poly_area);
|
||||
madd_v3_v3fl(r_cent, poly_cent, poly_area);
|
||||
total_area += poly_area;
|
||||
}
|
||||
/* otherwise we get NAN for 0 polys */
|
||||
if (me->totpoly) {
|
||||
mul_v3_fl(cent, 1.0f / total_area);
|
||||
mul_v3_fl(r_cent, 1.0f / total_area);
|
||||
}
|
||||
|
||||
/* zero area faces cause this, fallback to median */
|
||||
if (UNLIKELY(!is_finite_v3(cent))) {
|
||||
return BKE_mesh_center_median(me, cent);
|
||||
if (UNLIKELY(!is_finite_v3(r_cent))) {
|
||||
return BKE_mesh_center_median(me, r_cent);
|
||||
}
|
||||
|
||||
return (me->totpoly != 0);
|
||||
|
@ -1977,52 +1999,54 @@ bool BKE_mesh_center_centroid(Mesh *me, float cent[3])
|
|||
/** \name Mesh Volume Calculation
|
||||
* \{ */
|
||||
|
||||
static bool mesh_calc_center_centroid_ex(MVert *mverts, int UNUSED(numVerts),
|
||||
MFace *mfaces, int numFaces,
|
||||
float center[3])
|
||||
static bool mesh_calc_center_centroid_ex(
|
||||
const MVert *mverts, int UNUSED(numVerts),
|
||||
const MFace *mfaces, int numFaces,
|
||||
float r_center[3])
|
||||
{
|
||||
float totweight;
|
||||
int f;
|
||||
|
||||
zero_v3(center);
|
||||
zero_v3(r_center);
|
||||
|
||||
if (numFaces == 0)
|
||||
return false;
|
||||
|
||||
totweight = 0.0f;
|
||||
for (f = 0; f < numFaces; ++f) {
|
||||
MFace *face = &mfaces[f];
|
||||
MVert *v1 = &mverts[face->v1];
|
||||
MVert *v2 = &mverts[face->v2];
|
||||
MVert *v3 = &mverts[face->v3];
|
||||
MVert *v4 = &mverts[face->v4];
|
||||
const MFace *face = &mfaces[f];
|
||||
const MVert *v1 = &mverts[face->v1];
|
||||
const MVert *v2 = &mverts[face->v2];
|
||||
const MVert *v3 = &mverts[face->v3];
|
||||
const MVert *v4 = &mverts[face->v4];
|
||||
float area;
|
||||
|
||||
area = area_tri_v3(v1->co, v2->co, v3->co);
|
||||
madd_v3_v3fl(center, v1->co, area);
|
||||
madd_v3_v3fl(center, v2->co, area);
|
||||
madd_v3_v3fl(center, v3->co, area);
|
||||
madd_v3_v3fl(r_center, v1->co, area);
|
||||
madd_v3_v3fl(r_center, v2->co, area);
|
||||
madd_v3_v3fl(r_center, v3->co, area);
|
||||
totweight += area;
|
||||
|
||||
if (face->v4) {
|
||||
area = area_tri_v3(v3->co, v4->co, v1->co);
|
||||
madd_v3_v3fl(center, v3->co, area);
|
||||
madd_v3_v3fl(center, v4->co, area);
|
||||
madd_v3_v3fl(center, v1->co, area);
|
||||
madd_v3_v3fl(r_center, v3->co, area);
|
||||
madd_v3_v3fl(r_center, v4->co, area);
|
||||
madd_v3_v3fl(r_center, v1->co, area);
|
||||
totweight += area;
|
||||
}
|
||||
}
|
||||
if (totweight == 0.0f)
|
||||
return false;
|
||||
|
||||
mul_v3_fl(center, 1.0f / (3.0f * totweight));
|
||||
mul_v3_fl(r_center, 1.0f / (3.0f * totweight));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_volume(MVert *mverts, int numVerts,
|
||||
MFace *mfaces, int numFaces,
|
||||
float *r_vol, float *r_com)
|
||||
void BKE_mesh_calc_volume(
|
||||
const MVert *mverts, const int numVerts,
|
||||
const MFace *mfaces, const int numFaces,
|
||||
float *r_vol, float *r_com)
|
||||
{
|
||||
float center[3];
|
||||
float totvol;
|
||||
|
@ -2039,11 +2063,11 @@ void BKE_mesh_calc_volume(MVert *mverts, int numVerts,
|
|||
|
||||
totvol = 0.0f;
|
||||
for (f = 0; f < numFaces; ++f) {
|
||||
MFace *face = &mfaces[f];
|
||||
MVert *v1 = &mverts[face->v1];
|
||||
MVert *v2 = &mverts[face->v2];
|
||||
MVert *v3 = &mverts[face->v3];
|
||||
MVert *v4 = &mverts[face->v4];
|
||||
const MFace *face = &mfaces[f];
|
||||
const MVert *v1 = &mverts[face->v1];
|
||||
const MVert *v2 = &mverts[face->v2];
|
||||
const MVert *v3 = &mverts[face->v3];
|
||||
const MVert *v4 = &mverts[face->v4];
|
||||
float vol;
|
||||
|
||||
vol = volume_tetrahedron_signed_v3(center, v1->co, v2->co, v3->co);
|
||||
|
|
|
@ -291,7 +291,7 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
|
|||
"bvh node face vert indices");
|
||||
|
||||
for (i = 0; i < totface; ++i) {
|
||||
MFace *f = bvh->faces + node->prim_indices[i];
|
||||
const MFace *f = &bvh->faces[node->prim_indices[i]];
|
||||
int sides = f->v4 ? 4 : 3;
|
||||
|
||||
for (j = 0; j < sides; ++j) {
|
||||
|
@ -321,7 +321,7 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
|
|||
}
|
||||
|
||||
for (i = 0; i < totface; ++i) {
|
||||
MFace *f = bvh->faces + node->prim_indices[i];
|
||||
const MFace *f = &bvh->faces[node->prim_indices[i]];
|
||||
int sides = f->v4 ? 4 : 3;
|
||||
|
||||
for (j = 0; j < sides; ++j) {
|
||||
|
@ -528,7 +528,9 @@ static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim)
|
|||
}
|
||||
|
||||
/* Do a full rebuild with on Mesh data structure */
|
||||
void BKE_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int totvert, struct CustomData *vdata)
|
||||
void BKE_pbvh_build_mesh(
|
||||
PBVH *bvh, const MFace *faces, MVert *verts,
|
||||
int totface, int totvert, struct CustomData *vdata)
|
||||
{
|
||||
BBC *prim_bbc = NULL;
|
||||
BB cb;
|
||||
|
@ -548,7 +550,7 @@ void BKE_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int
|
|||
prim_bbc = MEM_mallocN(sizeof(BBC) * totface, "prim_bbc");
|
||||
|
||||
for (i = 0; i < totface; ++i) {
|
||||
MFace *f = faces + i;
|
||||
const MFace *f = &faces[i];
|
||||
const int sides = f->v4 ? 4 : 3;
|
||||
BBC *bbc = prim_bbc + i;
|
||||
|
||||
|
@ -649,9 +651,10 @@ void BKE_pbvh_free(PBVH *bvh)
|
|||
if (bvh->verts) {
|
||||
/* if pbvh was deformed, new memory was allocated for verts/faces -- free it */
|
||||
|
||||
MEM_freeN(bvh->verts);
|
||||
if (bvh->faces)
|
||||
MEM_freeN(bvh->faces);
|
||||
MEM_freeN((void *)bvh->verts);
|
||||
if (bvh->faces) {
|
||||
MEM_freeN((void *)bvh->faces);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -975,9 +978,9 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes,
|
|||
totface = node->totprim;
|
||||
|
||||
for (i = 0; i < totface; ++i) {
|
||||
MFace *f = bvh->faces + faces[i];
|
||||
const MFace *f = &bvh->faces[faces[i]];
|
||||
float fn[3];
|
||||
unsigned int *fv = &f->v1;
|
||||
const unsigned int *fv = &f->v1;
|
||||
int sides = (f->v4) ? 4 : 3;
|
||||
|
||||
if (f->v4)
|
||||
|
|
|
@ -133,7 +133,7 @@ struct PBVH {
|
|||
|
||||
/* Mesh data */
|
||||
MVert *verts;
|
||||
MFace *faces;
|
||||
const MFace *faces;
|
||||
CustomData *vdata;
|
||||
|
||||
/* Grid Data */
|
||||
|
|
|
@ -1561,7 +1561,7 @@ static void neighbor_average(SculptSession *ss, float avg[3], unsigned vert)
|
|||
const MPoly *p = &ss->mpoly[vert_map->indices[i]];
|
||||
unsigned f_adj_v[2];
|
||||
|
||||
if (poly_get_adj_loops_from_vert(f_adj_v, p, ss->mloop, vert) != -1) {
|
||||
if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) {
|
||||
int j;
|
||||
for (j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) {
|
||||
if (vert_map->count != 2 || ss->pmap[f_adj_v[j]].count <= 2) {
|
||||
|
@ -1596,7 +1596,7 @@ static float neighbor_average_mask(SculptSession *ss, unsigned vert)
|
|||
const MPoly *p = &ss->mpoly[ss->pmap[vert].indices[i]];
|
||||
unsigned f_adj_v[2];
|
||||
|
||||
if (poly_get_adj_loops_from_vert(f_adj_v, p, ss->mloop, vert) != -1) {
|
||||
if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) {
|
||||
int j;
|
||||
for (j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) {
|
||||
avg += vmask[f_adj_v[j]];
|
||||
|
|
Loading…
Reference in New Issue