diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-04-13 14:18:51 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-04-13 14:19:00 +0400 |
commit | 18e4224142261cd8a1086c5872efb406b82f8330 (patch) | |
tree | a1a9f7680ab45158ec2c2755f76a966532cad8b8 /source/blender/blenkernel/intern/cdderivedmesh.c | |
parent | a872d0b414f406a7d53ce77f7b43e7a831a68fa7 (diff) |
Split Normals I (1/5): basis for split normals (nearly nothing user-visible here):
* Add a new calcLoopNormals function to DerivedMesh struct, and implement it for CDDM and CCGDM (subsurf).
EditDerivedBMesh (edit mode DM) only gets a dummy one in this commit.
* Add a tessellated version of CD_LOOPNORMAL layer (CD_TESSLOOPNORMAL), with relevant code to handle it
(tessellation, rna access, etc.).
* Change auto_smooth options of Mesh (angle now in radian internaly, and toggle is now used to enable/disable
split normals in DM creation process). Note BI render code is not touched here, hence its behavior regarding
this option is now incoherent, will be addressed in a separate commit.
Reviewers: campbellbarton
CC: brecht
Differential Revision: https://developer.blender.org/D365
Diffstat (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 0c58b7e66e7..9af6220e4b2 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1738,6 +1738,7 @@ static CDDerivedMesh *cdDM_create(const char *desc) dm->getTessFaceDataArray = DM_get_tessface_data_layer; dm->calcNormals = CDDM_calc_normals; + dm->calcLoopNormals = CDDM_calc_loop_normals; dm->recalcTessellation = CDDM_recalc_tessellation; dm->getVertCos = cdDM_getVertCos; @@ -2289,8 +2290,7 @@ void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const bool only_face_normals) CustomData_free_layers(&dm->faceData, CD_NORMAL, dm->numTessFaceData); } - - face_nors = MEM_mallocN(sizeof(float) * 3 * dm->numTessFaceData, "face_nors"); + face_nors = MEM_mallocN(sizeof(*face_nors) * dm->numTessFaceData, "face_nors"); /* calculate face normals */ BKE_mesh_calc_normals_mapping_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm), @@ -2298,8 +2298,7 @@ void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const bool only_face_normals) CustomData_get_layer(&dm->faceData, CD_ORIGINDEX), face_nors, only_face_normals); - CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_ASSIGN, - face_nors, dm->numTessFaceData); + CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_ASSIGN, face_nors, dm->numTessFaceData); cddm->dm.dirty &= ~DM_DIRTY_NORMALS; } @@ -2353,6 +2352,48 @@ void CDDM_calc_normals(DerivedMesh *dm) #endif +void CDDM_calc_loop_normals(DerivedMesh *dm, const float split_angle) +{ + MVert *mverts = dm->getVertArray(dm); + MEdge *medges = dm->getEdgeArray(dm); + MLoop *mloops = dm->getLoopArray(dm); + MPoly *mpolys = dm->getPolyArray(dm); + + CustomData *ldata, *pdata; + + float (*lnors)[3]; + float (*pnors)[3]; + + const int numVerts = dm->getNumVerts(dm); + const int numEdges = dm->getNumEdges(dm); + const int numLoops = dm->getNumLoops(dm); + const int numPolys = dm->getNumPolys(dm); + + ldata = dm->getLoopDataLayout(dm); + if (CustomData_has_layer(ldata, CD_NORMAL)) { + lnors = CustomData_get_layer(ldata, CD_NORMAL); + } + else { + lnors = CustomData_add_layer(ldata, CD_NORMAL, CD_CALLOC, NULL, numLoops); + } + + /* Compute poly (always needed) and vert normals. */ + /* Note we can't use DM_ensure_normals, since it won't keep computed poly nors... */ + pdata = dm->getPolyDataLayout(dm); + pnors = CustomData_get_layer(pdata, CD_NORMAL); + if (!pnors) { + pnors = CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, numPolys); + } + BKE_mesh_calc_normals_poly(mverts, numVerts, mloops, mpolys, numLoops, numPolys, pnors, + (dm->dirty & DM_DIRTY_NORMALS) ? false : true); + + dm->dirty &= ~DM_DIRTY_NORMALS; + + BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops, + mpolys, pnors, numPolys, split_angle); +} + + void CDDM_calc_normals_tessface(DerivedMesh *dm) { CDDerivedMesh *cddm = (CDDerivedMesh *)dm; |