From 198113b232a407a1fcd5282b998564f656df9680 Mon Sep 17 00:00:00 2001 From: Andrew Wiggin Date: Tue, 29 Nov 2011 13:11:14 +0000 Subject: [PATCH] subsurf-specific implementations of getVert/Edge/TessFaceData --- .../blender/blenkernel/intern/subsurf_ccg.c | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index c4eb129de26..de1818475ef 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -2446,6 +2446,12 @@ static void *ccgDM_get_vert_data_layer(DerivedMesh *dm, int type) int *origindex; int a, index, totnone, totorig; + /* Avoid re-creation if the layer exists already */ + origindex = DM_get_vert_data_layer(dm, CD_ORIGINDEX); + if (origindex) { + return origindex; + } + DM_add_vert_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL); origindex= DM_get_vert_data_layer(dm, CD_ORIGINDEX); @@ -2477,6 +2483,12 @@ static void *ccgDM_get_edge_data_layer(DerivedMesh *dm, int type) int a, i, index, totnone, totorig, totedge; int edgeSize= ccgSubSurf_getEdgeSize(ss); + /* Avoid re-creation if the layer exists already */ + origindex = DM_get_edge_data_layer(dm, CD_ORIGINDEX); + if (origindex) { + return origindex; + } + DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL); origindex= DM_get_edge_data_layer(dm, CD_ORIGINDEX); @@ -2512,6 +2524,12 @@ static void *ccgDM_get_tessface_data_layer(DerivedMesh *dm, int type) int a, i, index, totface; int gridFaces = ccgSubSurf_getGridSize(ss) - 1; + /* Avoid re-creation if the layer exists already */ + origindex = DM_get_tessface_data_layer(dm, CD_ORIGINDEX); + if (origindex) { + return origindex; + } + DM_add_tessface_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL); origindex= DM_get_tessface_data_layer(dm, CD_ORIGINDEX); @@ -2532,6 +2550,36 @@ static void *ccgDM_get_tessface_data_layer(DerivedMesh *dm, int type) return DM_get_tessface_data_layer(dm, type); } +static void *ccgDM_get_vert_data(DerivedMesh *dm, int index, int type) +{ + if (type == CD_ORIGINDEX) { + /* ensure creation of CD_ORIGINDEX layer */ + ccgDM_get_vert_data_layer(dm, type); + } + + return DM_get_vert_data(dm, index, type); +} + +static void *ccgDM_get_edge_data(DerivedMesh *dm, int index, int type) +{ + if (type == CD_ORIGINDEX) { + /* ensure creation of CD_ORIGINDEX layer */ + ccgDM_get_edge_data_layer(dm, type); + } + + return DM_get_edge_data(dm, index, type); +} + +static void *ccgDM_get_tessface_data(DerivedMesh *dm, int index, int type) +{ + if (type == CD_ORIGINDEX) { + /* ensure creation of CD_ORIGINDEX layer */ + ccgDM_get_tessface_data_layer(dm, type); + } + + return DM_get_tessface_data(dm, index, type); +} + static int ccgDM_getNumGrids(DerivedMesh *dm) { CCGDerivedMesh *cgdm= (CCGDerivedMesh*)dm; @@ -2829,6 +2877,10 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, ccgdm->dm.copyTessFaceArray = ccgDM_copyFinalFaceArray; ccgdm->dm.copyLoopArray = ccgDM_copyFinalLoopArray; ccgdm->dm.copyPolyArray = ccgDM_copyFinalPolyArray; + + ccgdm->dm.getVertData = ccgDM_get_vert_data; + ccgdm->dm.getEdgeData = ccgDM_get_edge_data; + ccgdm->dm.getTessFaceData = ccgDM_get_tessface_data; ccgdm->dm.getVertDataArray = ccgDM_get_vert_data_layer; ccgdm->dm.getEdgeDataArray = ccgDM_get_edge_data_layer; ccgdm->dm.getTessFaceDataArray = ccgDM_get_tessface_data_layer;