forked from bartvdbraak/blender
rename normal calc functions.
comparing bmesh to trunk, mesh_calc_normals() in bmesh is a much more comprehensive function, calculating mpoly,mface normals, where trunk only calculated vertex normals. renamed: * mesh_calc_normals() --> mesh_calc_normals_mapping_ex * mesh_calc_tessface_normals --> mesh_calc_normals_tessface() - only calculates normals from tessface * added mesh_calc_normals() - only calculates normals from poltys this way we can have mesh_calc_normals() remain fast for parts of the code which only need vertex normals to be updated. only refactor, no func changes- didnt replace mesh_calc_normals_mapping_ex() with mesh_calc_normals() anywhere yet.
This commit is contained in:
parent
2c9f08302c
commit
2b2c1007f6
@ -123,7 +123,7 @@ void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert);
|
||||
void mesh_delete_material_index(struct Mesh *me, short index);
|
||||
void mesh_set_smooth_flag(struct Object *meshOb, int enableSmooth);
|
||||
void convert_mfaces_to_mpolys(struct Mesh *mesh);
|
||||
void mesh_calc_tessface_normals(struct MVert *mverts, int numVerts,struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
|
||||
void mesh_calc_normals_tessface(struct MVert *mverts, int numVerts,struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
|
||||
|
||||
/*used for unit testing; compares two meshes, checking only
|
||||
differences we care about. should be usable with leaf's
|
||||
@ -143,14 +143,20 @@ void mesh_strip_loose_edges(struct Mesh *me);
|
||||
/* Calculate vertex and face normals, face normals are returned in *faceNors_r if non-NULL
|
||||
* and vertex normals are stored in actual mverts.
|
||||
*/
|
||||
void mesh_calc_normals(struct MVert *mverts, int numVerts, struct MLoop *mloop,
|
||||
struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
|
||||
struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]);
|
||||
void mesh_calc_normals_mapping(
|
||||
struct MVert *mverts, int numVerts,
|
||||
struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
|
||||
struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]);
|
||||
/* extended version of 'mesh_calc_normals' with option not to calc vertex normals */
|
||||
void mesh_calc_normals_ex(struct MVert *mverts, int numVerts, struct MLoop *mloop,
|
||||
struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
|
||||
struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
|
||||
const short only_face_normals);
|
||||
void mesh_calc_normals_mapping_ex(
|
||||
struct MVert *mverts, int numVerts, struct MLoop *mloop,
|
||||
struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
|
||||
struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
|
||||
const short only_face_normals);
|
||||
|
||||
void mesh_calc_normals(
|
||||
struct MVert *mverts, int numVerts, struct MLoop *mloop,
|
||||
struct MPoly *mpolys, int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3]);
|
||||
|
||||
/* Return a newly MEM_malloc'd array of all the mesh vertex locations
|
||||
* (_numVerts_r_ may be NULL) */
|
||||
|
@ -2258,7 +2258,7 @@ void CDDM_calc_normals(DerivedMesh *dm)
|
||||
face_nors = MEM_mallocN(sizeof(float)*3*dm->numTessFaceData, "face_nors");
|
||||
|
||||
/* calculate face normals */
|
||||
mesh_calc_normals_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
|
||||
mesh_calc_normals_mapping_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
|
||||
dm->numLoopData, dm->numPolyData, NULL, cddm->mface, dm->numTessFaceData,
|
||||
CustomData_get_layer(&dm->faceData, CD_POLYINDEX), face_nors,
|
||||
only_face_normals);
|
||||
|
@ -1392,7 +1392,7 @@ void nurbs_to_mesh(Object *ob)
|
||||
me->mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop);
|
||||
me->mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly);
|
||||
|
||||
mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
} else {
|
||||
me= add_mesh("Mesh");
|
||||
DM_to_mesh(dm, me, ob);
|
||||
@ -1663,24 +1663,25 @@ void mesh_set_smooth_flag(Object *meshOb, int enableSmooth)
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
|
||||
int numLoops, int numPolys, float (*polyNors_r)[3], MFace *mfaces, int numFaces,
|
||||
int *origIndexFace, float (*faceNors_r)[3])
|
||||
void mesh_calc_normals_mapping(MVert *mverts, int numVerts,
|
||||
MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
|
||||
MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3])
|
||||
{
|
||||
mesh_calc_normals_ex(mverts, numVerts, mloop, mpolys,
|
||||
numLoops, numPolys, polyNors_r, mfaces, numFaces,
|
||||
origIndexFace, faceNors_r, TRUE);
|
||||
mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys,
|
||||
numLoops, numPolys, polyNors_r, mfaces, numFaces,
|
||||
origIndexFace, faceNors_r, TRUE);
|
||||
}
|
||||
void mesh_calc_normals_ex(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
|
||||
int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3], MFace *mfaces, int numFaces,
|
||||
int *origIndexFace, float (*faceNors_r)[3],
|
||||
const short only_face_normals)
|
||||
|
||||
void mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts,
|
||||
MLoop *mloop, MPoly *mpolys,
|
||||
int numLoops, int numPolys, float (*polyNors_r)[3],
|
||||
MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
|
||||
const short only_face_normals)
|
||||
{
|
||||
float (*pnors)[3] = polyNors_r, (*fnors)[3] = faceNors_r;
|
||||
int i, j;
|
||||
int i;
|
||||
MFace *mf;
|
||||
MPoly *mp;
|
||||
MLoop *ml;
|
||||
|
||||
if (numPolys == 0) {
|
||||
return;
|
||||
@ -1699,51 +1700,7 @@ void mesh_calc_normals_ex(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpol
|
||||
if (only_face_normals == FALSE) {
|
||||
/* vertex normals are optional, they require some extra calculations,
|
||||
* so make them optional */
|
||||
|
||||
float (*tnorms)[3], (*edgevecbuf)[3]= NULL;
|
||||
float **vertcos = NULL, **vertnos = NULL;
|
||||
BLI_array_declare(vertcos);
|
||||
BLI_array_declare(vertnos);
|
||||
BLI_array_declare(edgevecbuf);
|
||||
|
||||
/*first go through and calculate normals for all the polys*/
|
||||
tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c");
|
||||
|
||||
mp = mpolys;
|
||||
for (i=0; i<numPolys; i++, mp++) {
|
||||
mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
|
||||
ml = mloop + mp->loopstart;
|
||||
|
||||
BLI_array_empty(vertcos);
|
||||
BLI_array_empty(vertnos);
|
||||
for (j=0; j<mp->totloop; j++) {
|
||||
int vindex = ml[j].v;
|
||||
BLI_array_append(vertcos, mverts[vindex].co);
|
||||
BLI_array_append(vertnos, tnorms[vindex]);
|
||||
}
|
||||
|
||||
BLI_array_empty(edgevecbuf);
|
||||
BLI_array_growitems(edgevecbuf, mp->totloop);
|
||||
|
||||
accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop);
|
||||
}
|
||||
|
||||
BLI_array_free(vertcos);
|
||||
BLI_array_free(vertnos);
|
||||
BLI_array_free(edgevecbuf);
|
||||
|
||||
/* following Mesh convention; we use vertex coordinate itself for normal in this case */
|
||||
for(i=0; i<numVerts; i++) {
|
||||
MVert *mv= &mverts[i];
|
||||
float *no= tnorms[i];
|
||||
|
||||
if(normalize_v3(no) == 0.0f)
|
||||
normalize_v3_v3(no, mv->co);
|
||||
|
||||
normal_float_to_short_v3(mv->no, no);
|
||||
}
|
||||
|
||||
MEM_freeN(tnorms);
|
||||
mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, polyNors_r);
|
||||
}
|
||||
else {
|
||||
/* only calc poly normals */
|
||||
@ -1776,7 +1733,66 @@ void mesh_calc_normals_ex(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpol
|
||||
|
||||
}
|
||||
|
||||
void mesh_calc_tessface_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
|
||||
void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
|
||||
int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3])
|
||||
{
|
||||
float (*pnors)[3] = polyNors_r;
|
||||
|
||||
float (*tnorms)[3], (*edgevecbuf)[3]= NULL;
|
||||
float **vertcos = NULL, **vertnos = NULL;
|
||||
BLI_array_declare(vertcos);
|
||||
BLI_array_declare(vertnos);
|
||||
BLI_array_declare(edgevecbuf);
|
||||
|
||||
int i, j;
|
||||
MPoly *mp;
|
||||
MLoop *ml;
|
||||
|
||||
if (!pnors) pnors = MEM_callocN(sizeof(float) * 3 * numPolys, "poly_nors mesh.c");
|
||||
|
||||
/*first go through and calculate normals for all the polys*/
|
||||
tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c");
|
||||
|
||||
mp = mpolys;
|
||||
for (i=0; i<numPolys; i++, mp++) {
|
||||
mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
|
||||
ml = mloop + mp->loopstart;
|
||||
|
||||
BLI_array_empty(vertcos);
|
||||
BLI_array_empty(vertnos);
|
||||
for (j=0; j<mp->totloop; j++) {
|
||||
int vindex = ml[j].v;
|
||||
BLI_array_append(vertcos, mverts[vindex].co);
|
||||
BLI_array_append(vertnos, tnorms[vindex]);
|
||||
}
|
||||
|
||||
BLI_array_empty(edgevecbuf);
|
||||
BLI_array_growitems(edgevecbuf, mp->totloop);
|
||||
|
||||
accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop);
|
||||
}
|
||||
|
||||
BLI_array_free(vertcos);
|
||||
BLI_array_free(vertnos);
|
||||
BLI_array_free(edgevecbuf);
|
||||
|
||||
/* following Mesh convention; we use vertex coordinate itself for normal in this case */
|
||||
for(i=0; i<numVerts; i++) {
|
||||
MVert *mv= &mverts[i];
|
||||
float *no= tnorms[i];
|
||||
|
||||
if(normalize_v3(no) == 0.0f)
|
||||
normalize_v3_v3(no, mv->co);
|
||||
|
||||
normal_float_to_short_v3(mv->no, no);
|
||||
}
|
||||
|
||||
MEM_freeN(tnorms);
|
||||
|
||||
if (pnors != polyNors_r) MEM_freeN(pnors);
|
||||
}
|
||||
|
||||
void mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
|
||||
{
|
||||
float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms");
|
||||
float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals");
|
||||
@ -2602,15 +2618,15 @@ static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart,
|
||||
const float (*vertex_coords)[3], float normal[3])
|
||||
{
|
||||
|
||||
float *v1, *v2, *v3;
|
||||
const float *v1, *v2, *v3;
|
||||
double u[3], v[3], w[3];
|
||||
double n[3] = {0.0, 0.0, 0.0}, l;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < mpoly->totloop; i++){
|
||||
v1 = vertex_coords + loopstart[i].v;
|
||||
v2 = vertex_coords + loopstart[(i+1)%mpoly->totloop].v;
|
||||
v3 = vertex_coords + loopstart[(i+2)%mpoly->totloop].v;
|
||||
v1 = (const float *)(vertex_coords + loopstart[i].v);
|
||||
v2 = (const float *)(vertex_coords + loopstart[(i+1)%mpoly->totloop].v);
|
||||
v3 = (const float *)(vertex_coords + loopstart[(i+2)%mpoly->totloop].v);
|
||||
|
||||
VECCOPY(u, v1);
|
||||
VECCOPY(v, v2);
|
||||
|
@ -1585,7 +1585,7 @@ void BLI_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3])
|
||||
}
|
||||
|
||||
/* coordinates are new -- normals should also be updated */
|
||||
mesh_calc_tessface_normals(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL);
|
||||
mesh_calc_normals_tessface(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL);
|
||||
|
||||
for (a= 0; a < pbvh->totnode; ++a)
|
||||
BLI_pbvh_node_mark_update(&pbvh->nodes[a]);
|
||||
|
@ -12327,7 +12327,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
||||
Mesh *me;
|
||||
|
||||
for(me= main->mesh.first; me; me= me->id.next)
|
||||
mesh_calc_tessface_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
|
||||
mesh_calc_normals_tessface(me->mvert, me->totvert, me->mface, me->totface, NULL);
|
||||
}
|
||||
|
||||
if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)){
|
||||
|
@ -959,7 +959,7 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry* geom)
|
||||
|
||||
make_edges(me, 0);
|
||||
|
||||
mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges)
|
||||
contain the normal of the poly the face was tesselated from. */
|
||||
face_nors = CustomData_add_layer(&mesh->fdata, CD_NORMAL, CD_CALLOC, NULL, mesh->totface);
|
||||
|
||||
mesh_calc_normals(
|
||||
mesh_calc_normals_mapping(
|
||||
mesh->mvert,
|
||||
mesh->totvert,
|
||||
mesh->mloop,
|
||||
@ -829,7 +829,7 @@ void ED_mesh_transform(Mesh *mesh, float *mat)
|
||||
for(i= 0; i < mesh->totvert; i++, mvert++)
|
||||
mul_m4_v3((float (*)[4])mat, mvert->co);
|
||||
|
||||
mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
static void mesh_add_edges(Mesh *mesh, int len)
|
||||
@ -1015,5 +1015,5 @@ void ED_mesh_polys_add(Mesh *mesh, ReportList *reports, int count)
|
||||
|
||||
void ED_mesh_calc_normals(Mesh *mesh)
|
||||
{
|
||||
mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
|
||||
}
|
||||
|
||||
/* update normals */
|
||||
mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
}
|
||||
else if (ob->type==OB_ARMATURE) {
|
||||
ED_armature_apply_transform(ob, mat);
|
||||
|
@ -2299,7 +2299,7 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3])
|
||||
for (a= 0; a < me->totvert; a++, mvert++)
|
||||
copy_v3_v3(mvert->co, vertCos[a]);
|
||||
|
||||
mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
/* apply new coords on active key block */
|
||||
@ -2532,7 +2532,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob)
|
||||
/* Modifiers could depend on mesh normals, so we should update them/
|
||||
Note, then if sculpting happens on locked key, normals should be re-calculated
|
||||
after applying coords from keyblock on base mesh */
|
||||
mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
} else if (ss->kb)
|
||||
sculpt_update_keyblock(ob);
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
|
||||
|
||||
if(ss->modifiers_active) {
|
||||
Mesh *mesh= ob->data;
|
||||
mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
|
||||
|
||||
free_sculptsession_deformMats(ss);
|
||||
tag_update|= 1;
|
||||
|
Loading…
Reference in New Issue
Block a user