Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/DerivedMesh.c')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c611
1 files changed, 375 insertions, 236 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 4c683b2b2c8..074ea741f3a 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -51,6 +51,8 @@
#include "BLI_utildefines.h"
#include "BLI_linklist.h"
+#include "BLF_translation.h"
+
#include "BKE_cdderivedmesh.h"
#include "BKE_displist.h"
#include "BKE_key.h"
@@ -65,6 +67,7 @@
#include "BKE_tessmesh.h"
#include "BKE_bvhutils.h"
#include "BKE_deform.h"
+#include "BKE_global.h" /* For debug flag, DM_update_tessface_data() func. */
#ifdef WITH_GAMEENGINE
#include "BKE_navmesh_conversion.h"
@@ -80,8 +83,6 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
#include "GPU_extensions.h"
#include "GPU_material.h"
-extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
-
static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob);
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
@@ -121,8 +122,17 @@ static MFace *dm_getTessFaceArray(DerivedMesh *dm)
MFace *mface = CustomData_get_layer(&dm->faceData, CD_MFACE);
if (!mface) {
- mface = CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL,
- dm->getNumTessFaces(dm));
+ int numTessFaces = dm->getNumTessFaces(dm);
+
+ if (!numTessFaces) {
+ /* Do not add layer if there's no elements in it, this leads to issues later when
+ * this layer is needed with non-zero size, but currently CD stuff does not check
+ * for requested layer size on creation and just returns layer which was previously
+ * added (sergey) */
+ return NULL;
+ }
+
+ mface = CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numTessFaces);
CustomData_set_layer_flag(&dm->faceData, CD_MFACE, CD_FLAG_TEMPORARY);
dm->copyTessFaceArray(dm, mface);
}
@@ -163,7 +173,7 @@ static MVert *dm_dupVertArray(DerivedMesh *dm)
MVert *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumVerts(dm),
"dm_dupVertArray tmp");
- if(tmp) dm->copyVertArray(dm, tmp);
+ if (tmp) dm->copyVertArray(dm, tmp);
return tmp;
}
@@ -173,7 +183,7 @@ static MEdge *dm_dupEdgeArray(DerivedMesh *dm)
MEdge *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumEdges(dm),
"dm_dupEdgeArray tmp");
- if(tmp) dm->copyEdgeArray(dm, tmp);
+ if (tmp) dm->copyEdgeArray(dm, tmp);
return tmp;
}
@@ -183,7 +193,7 @@ static MFace *dm_dupFaceArray(DerivedMesh *dm)
MFace *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumTessFaces(dm),
"dm_dupFaceArray tmp");
- if(tmp) dm->copyTessFaceArray(dm, tmp);
+ if (tmp) dm->copyTessFaceArray(dm, tmp);
return tmp;
}
@@ -193,7 +203,7 @@ static MLoop *dm_dupLoopArray(DerivedMesh *dm)
MLoop *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumLoops(dm),
"dm_dupLoopArray tmp");
- if(tmp) dm->copyLoopArray(dm, tmp);
+ if (tmp) dm->copyLoopArray(dm, tmp);
return tmp;
}
@@ -203,7 +213,7 @@ static MPoly *dm_dupPolyArray(DerivedMesh *dm)
MPoly *tmp = MEM_callocN(sizeof(*tmp) * dm->getNumPolys(dm),
"dm_dupPolyArray tmp");
- if(tmp) dm->copyPolyArray(dm, tmp);
+ if (tmp) dm->copyPolyArray(dm, tmp);
return tmp;
}
@@ -277,6 +287,7 @@ void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges,
dm->needsFree = 1;
dm->auto_bump_scale = -1.0f;
+ dm->dirty = 0;
}
void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type,
@@ -304,6 +315,7 @@ void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type
DM_init_funcs(dm);
dm->needsFree = 1;
+ dm->dirty = 0;
}
int DM_release(DerivedMesh *dm)
@@ -372,6 +384,73 @@ void DM_ensure_tessface(DerivedMesh *dm)
}
}
+/* Update tessface CD data from loop/poly ones. Needed when not retessellating after modstack evaluation. */
+/* NOTE: Assumes dm has valid tessellated data! */
+void DM_update_tessface_data(DerivedMesh *dm)
+{
+ MFace *mf = dm->getTessFaceArray(dm);
+ MPoly *mp = dm->getPolyArray(dm);
+ MLoop *ml = dm->getLoopArray(dm);
+
+ CustomData *fdata = dm->getTessFaceDataLayout(dm);
+ CustomData *pdata = dm->getPolyDataLayout(dm);
+ CustomData *ldata = dm->getLoopDataLayout(dm);
+
+ const int numTex = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
+ const int numCol = CustomData_number_of_layers(ldata, CD_MLOOPCOL);
+ const int hasPCol = CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL);
+ const int hasOrigSpace = CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP);
+
+ int *polyindex = CustomData_get_layer(fdata, CD_POLYINDEX);
+
+ int mf_idx,
+ totface = dm->getNumTessFaces(dm),
+ ml_idx[4];
+
+ /* Should never occure, but better abort than segfault! */
+ if (!polyindex)
+ return;
+
+ CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
+
+ for (mf_idx = 0; mf_idx < totface; mf_idx++, mf++) {
+ const int mf_len = mf->v4 ? 4 : 3;
+ int i, not_done;
+
+ /* Find out loop indices. */
+ /* XXX Is there a better way to do this? */
+ /* NOTE: This assumes tessface are valid and in sync with loop/poly… Else, most likely, segfault! */
+ for (i = mp[polyindex[mf_idx]].loopstart, not_done = mf_len; not_done; i++) {
+ MLoop *tml = &ml[i];
+ if (tml->v == mf->v1) {
+ ml_idx[0] = i;
+ not_done--;
+ }
+ else if (tml->v == mf->v2) {
+ ml_idx[1] = i;
+ not_done--;
+ }
+ else if (tml->v == mf->v3) {
+ ml_idx[2] = i;
+ not_done--;
+ }
+ else if (mf_len == 4 && tml->v == mf->v4) {
+ ml_idx[3] = i;
+ not_done--;
+ }
+ }
+ mesh_loops_to_mface_corners(fdata, ldata, pdata,
+ ml_idx, mf_idx, polyindex[mf_idx],
+ mf_len,
+ numTex, numCol, hasPCol, hasOrigSpace);
+ }
+
+ if (G.f & G_DEBUG)
+ printf("Updated tessellated customdata of dm %p\n", dm);
+
+ dm->dirty &= ~DM_DIRTY_TESS_CDLAYERS;
+}
+
void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
{
/* dm might depend on me, so we need to do everything with a local copy */
@@ -422,11 +501,11 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
/* not all DerivedMeshes store their verts/edges/faces in CustomData, so
* we set them here in case they are missing */
- if(!CustomData_has_layer(&tmp.vdata, CD_MVERT))
+ if (!CustomData_has_layer(&tmp.vdata, CD_MVERT))
CustomData_add_layer(&tmp.vdata, CD_MVERT, CD_ASSIGN, dm->dupVertArray(dm), totvert);
- if(!CustomData_has_layer(&tmp.edata, CD_MEDGE))
+ if (!CustomData_has_layer(&tmp.edata, CD_MEDGE))
CustomData_add_layer(&tmp.edata, CD_MEDGE, CD_ASSIGN, dm->dupEdgeArray(dm), totedge);
- if(!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
+ if (!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
tmp.mloop = dm->dupLoopArray(dm);
tmp.mpoly = dm->dupPolyArray(dm);
@@ -436,14 +515,14 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
/* object had got displacement layer, should copy this layer to save sculpted data */
/* NOTE: maybe some other layers should be copied? nazgul */
- if(CustomData_has_layer(&me->ldata, CD_MDISPS)) {
+ if (CustomData_has_layer(&me->ldata, CD_MDISPS)) {
if (totloop == me->totloop) {
MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
CustomData_add_layer(&tmp.ldata, CD_MDISPS, CD_DUPLICATE, mdisps, totloop);
}
}
- /* yes, must be before _and_ after tesselate */
+ /* yes, must be before _and_ after tessellate */
mesh_update_customdata_pointers(&tmp, TRUE);
BKE_mesh_tessface_calc(&tmp);
@@ -457,9 +536,9 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
/* ok, this should now use new CD shapekey data,
* which shouuld be fed through the modifier
* stack*/
- if(tmp.totvert != me->totvert && !did_shapekeys && me->key) {
+ if (tmp.totvert != me->totvert && !did_shapekeys && me->key) {
printf("YEEK! this should be recoded! Shape key loss!!!\n");
- if(tmp.key) tmp.key->id.us--;
+ if (tmp.key) tmp.key->id.us--;
tmp.key = NULL;
}
@@ -472,16 +551,16 @@ void DM_to_meshkey(DerivedMesh *dm, Mesh *me, KeyBlock *kb)
float *fp;
MVert *mvert;
- if(totvert==0 || me->totvert==0 || me->totvert!=totvert) return;
+ if (totvert==0 || me->totvert==0 || me->totvert!=totvert) return;
- if(kb->data) MEM_freeN(kb->data);
+ if (kb->data) MEM_freeN(kb->data);
kb->data= MEM_callocN(me->key->elemsize*me->totvert, "kb->data");
kb->totelem= totvert;
fp= kb->data;
mvert=dm->getVertDataArray(dm, CD_MVERT);
- for(a=0; a<kb->totelem; a++, fp+=3, mvert++) {
+ for (a=0; a<kb->totelem; a++, fp+=3, mvert++) {
copy_v3_v3(fp, mvert->co);
}
}
@@ -535,7 +614,7 @@ void *DM_get_tessface_data(DerivedMesh *dm, int index, int type)
void *DM_get_vert_data_layer(DerivedMesh *dm, int type)
{
- if(type == CD_MVERT)
+ if (type == CD_MVERT)
return dm->getVertArray(dm);
return CustomData_get_layer(&dm->vertData, type);
@@ -543,7 +622,7 @@ void *DM_get_vert_data_layer(DerivedMesh *dm, int type)
void *DM_get_edge_data_layer(DerivedMesh *dm, int type)
{
- if(type == CD_MEDGE)
+ if (type == CD_MEDGE)
return dm->getEdgeArray(dm);
return CustomData_get_layer(&dm->edgeData, type);
@@ -694,7 +773,7 @@ DerivedMesh *mesh_create_derived(Mesh *me, Object *ob, float (*vertCos)[3])
{
DerivedMesh *dm = CDDM_from_mesh(me, ob);
- if(!dm)
+ if (!dm)
return NULL;
if (vertCos)
@@ -735,7 +814,8 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob,
add_shapekey_layers(dm, me, ob);
MEM_freeN(deformedVerts);
- } else {
+ }
+ else {
DerivedMesh *tdm = mesh_create_derived(me, ob, NULL);
if (build_shapekey_layers)
@@ -743,7 +823,7 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob,
dm = mti->applyModifier(md, ob, tdm, 0, 0);
- if(tdm != dm) tdm->release(tdm);
+ if (tdm != dm) tdm->release(tdm);
}
return dm;
@@ -776,23 +856,23 @@ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free
{
*free= 0;
- if(layer == CD_ORCO) {
+ if (layer == CD_ORCO) {
/* get original coordinates */
*free= 1;
- if(em)
+ if (em)
return (float(*)[3])get_editbmesh_orco_verts(em);
else
return (float(*)[3])get_mesh_orco_verts(ob);
}
- else if(layer == CD_CLOTH_ORCO) {
+ else if (layer == CD_CLOTH_ORCO) {
/* apply shape key for cloth, this should really be solved
* by a more flexible customdata system, but not simple */
- if(!em) {
+ if (!em) {
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
KeyBlock *kb= key_get_keyblock(ob_get_key(ob), clmd->sim_parms->shapekey_rest);
- if(kb->data)
+ if (kb->data)
return kb->data;
}
@@ -808,14 +888,14 @@ static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int lay
float (*orco)[3];
int free;
- if(em) dm= CDDM_from_BMEditMesh(em, me, FALSE, FALSE);
+ if (em) dm= CDDM_from_BMEditMesh(em, me, FALSE, FALSE);
else dm= CDDM_from_mesh(me, ob);
orco= get_orco_coords_dm(ob, em, layer, &free);
- if(orco) {
+ if (orco) {
CDDM_apply_vert_coords(dm, orco);
- if(free) MEM_freeN(orco);
+ if (free) MEM_freeN(orco);
}
CDDM_calc_normals(dm);
@@ -831,11 +911,11 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm,
totvert= dm->getNumVerts(dm);
- if(orcodm) {
+ if (orcodm) {
orco= MEM_callocN(sizeof(float)*3*totvert, "dm orco");
free= 1;
- if(orcodm->getNumVerts(orcodm) == totvert)
+ if (orcodm->getNumVerts(orcodm) == totvert)
orcodm->getVertCos(orcodm, orco);
else
dm->getVertCos(dm, orco);
@@ -843,17 +923,17 @@ static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm,
else
orco= get_orco_coords_dm(ob, em, layer, &free);
- if(orco) {
- if(layer == CD_ORCO)
+ if (orco) {
+ if (layer == CD_ORCO)
transform_mesh_orco_verts(ob->data, orco, totvert, 0);
- if(!(layerorco = DM_get_vert_data_layer(dm, layer))) {
+ if (!(layerorco = DM_get_vert_data_layer(dm, layer))) {
DM_add_vert_layer(dm, layer, CD_CALLOC, NULL);
layerorco = DM_get_vert_data_layer(dm, layer);
}
memcpy(layerorco, orco, sizeof(float)*3*totvert);
- if(free) MEM_freeN(orco);
+ if (free) MEM_freeN(orco);
}
}
@@ -908,13 +988,19 @@ static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const flo
{
float colf[4];
- if(coba) do_colorband(coba, input, colf);
- else weight_to_rgb(colf, input);
+ if (coba) {
+ do_colorband(coba, input, colf);
+ }
+ else {
+ weight_to_rgb(colf, input);
+ }
- r_col[3] = (unsigned char)(colf[0] * 255.0f);
- r_col[2] = (unsigned char)(colf[1] * 255.0f);
- r_col[1] = (unsigned char)(colf[2] * 255.0f);
- r_col[0] = 255;
+ /* don't use rgb_float_to_uchar() here because
+ * the resulting float doesn't need 0-1 clamp check */
+ r_col[0] = (unsigned char)(colf[0] * 255.0f);
+ r_col[1] = (unsigned char)(colf[1] * 255.0f);
+ r_col[2] = (unsigned char)(colf[2] * 255.0f);
+ r_col[3] = 255;
}
@@ -1039,30 +1125,34 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
unsigned char *wtcol_v;
#if 0 /* See coment below. */
- unsigned char *wtcol_f = dm->getTessFaceDataArray(dm, CD_WEIGHT_MCOL);
+ unsigned char *wtcol_f = dm->getTessFaceDataArray(dm, CD_PREVIEW_MCOL);
#endif
- unsigned char(*wtcol_l)[4] = CustomData_get_layer(dm->getLoopDataLayout(dm), CD_WEIGHT_MLOOPCOL);
+ unsigned char(*wtcol_l)[4] = CustomData_get_layer(dm->getLoopDataLayout(dm), CD_PREVIEW_MLOOPCOL);
#if 0 /* See coment below. */
MFace *mf = dm->getTessFaceArray(dm);
#endif
MLoop *mloop = dm->getLoopArray(dm), *ml;
MPoly *mp = dm->getPolyArray(dm);
+#if 0
int numFaces = dm->getNumTessFaces(dm);
+#endif
int numVerts = dm->getNumVerts(dm);
int totloop;
int i, j;
#if 0 /* See comment below */
- /* If no CD_WEIGHT_MCOL existed yet, add a new one! */
+ /* If no CD_PREVIEW_MCOL existed yet, add a new one! */
if (!wtcol_f)
- wtcol_f = CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numFaces);
+ wtcol_f = CustomData_add_layer(&dm->faceData, CD_PREVIEW_MCOL, CD_CALLOC, NULL, numFaces);
if (wtcol_f) {
unsigned char *wtcol_f_step = wtcol_f;
# else
- /* XXX We have to create a CD_WEIGHT_MCOL, else it might sigsev (after a SubSurf mod, eg)... */
- if(!dm->getTessFaceDataArray(dm, CD_WEIGHT_MCOL))
- CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numFaces);
+#if 0
+ /* XXX We have to create a CD_PREVIEW_MCOL, else it might sigsev (after a SubSurf mod, eg)... */
+ if (!dm->getTessFaceDataArray(dm, CD_PREVIEW_MCOL))
+ CustomData_add_layer(&dm->faceData, CD_PREVIEW_MCOL, CD_CALLOC, NULL, numFaces);
+#endif
{
#endif
@@ -1072,17 +1162,17 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
float *w = weights;
/* If indices is not NULL, it means we do not have weights for all vertices,
* so we must create them (and set them to zero)... */
- if(indices) {
+ if (indices) {
w = MEM_callocN(sizeof(float)*numVerts, "Temp weight array DM_update_weight_mcol");
i = num;
- while(i--)
+ while (i--)
w[indices[i]] = weights[i];
}
/* Convert float weights to colors. */
wtcol_v = calc_colors_from_weights_array(numVerts, w);
- if(indices)
+ if (indices)
MEM_freeN(w);
}
@@ -1119,7 +1209,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
}
#endif
/*now add to loops, so the data can be passed through the modifier stack*/
- /* If no CD_WEIGHT_MLOOPCOL existed yet, we have to add a new one! */
+ /* If no CD_PREVIEW_MLOOPCOL existed yet, we have to add a new one! */
if (!wtcol_l) {
BLI_array_declare(wtcol_l);
totloop = 0;
@@ -1132,7 +1222,7 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
(char *)&wtcol_v[4 * ml->v]);
}
}
- CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_ASSIGN, wtcol_l, totloop);
+ CustomData_add_layer(&dm->loopData, CD_PREVIEW_MLOOPCOL, CD_ASSIGN, wtcol_l, totloop);
}
else {
totloop = 0;
@@ -1147,6 +1237,8 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
}
MEM_freeN(wtcol_v);
}
+
+ dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
}
@@ -1186,7 +1278,8 @@ static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape
for (j=0; j<dm->numVertData; j++, kbcos++, mvert++) {
copy_v3_v3(*kbcos, mvert->co);
}
- } else {
+ }
+ else {
for (j=0; j<kb->totelem; j++, cos++, kbcos++) {
copy_v3_v3(*kbcos, *cos);
}
@@ -1259,7 +1352,8 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
Mesh *me = ob->data;
ModifierData *firstmd, *md, *previewmd = NULL;
LinkNode *datamasks, *curr;
- CustomDataMask mask, nextmask, append_mask = 0;
+ /* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
+ CustomDataMask mask, nextmask, append_mask = CD_MASK_POLYINDEX;
float (*deformedVerts)[3] = NULL;
DerivedMesh *dm=NULL, *orcodm, *clothorcodm, *finaldm;
int numVerts = me->totvert;
@@ -1278,20 +1372,20 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
const int do_final_wmcol = (scene->toolsettings->weights_preview == WP_WPREVIEW_FINAL) && do_wmcol;
#endif
const int do_final_wmcol = FALSE;
- int do_init_wmcol = ((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT) && !do_final_wmcol);
+ int do_init_wmcol = ((dataMask & CD_MASK_PREVIEW_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT) && !do_final_wmcol);
/* XXX Same as above... For now, only weights preview in WPaint mode. */
const int do_mod_wmcol = do_init_wmcol;
- if(mmd && !mmd->sculptlvl)
+ if (mmd && !mmd->sculptlvl)
has_multires = 0;
- if(!skipVirtualArmature) {
+ if (!skipVirtualArmature) {
firstmd = modifiers_getVirtualModifierList(ob);
}
else {
/* game engine exception */
firstmd = ob->modifiers.first;
- if(firstmd && firstmd->type == eModifierType_Armature)
+ if (firstmd && firstmd->type == eModifierType_Armature)
firstmd = firstmd->next;
}
@@ -1299,13 +1393,13 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
modifiers_clearErrors(ob);
- if(useRenderParams) required_mode = eModifierMode_Render;
+ if (useRenderParams) required_mode = eModifierMode_Render;
else required_mode = eModifierMode_Realtime;
datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode);
curr = datamasks;
- if(do_mod_wmcol || do_mod_mcol) {
+ if (do_mod_wmcol || do_mod_mcol) {
/* Find the last active modifier generating a preview, or NULL if none. */
/* XXX Currently, DPaint modifier just ignores this.
* Needs a stupid hack...
@@ -1313,33 +1407,34 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
previewmd = modifiers_getLastPreview(scene, md, required_mode);
}
- if(deform_r) *deform_r = NULL;
+ if (deform_r) *deform_r = NULL;
*final_r = NULL;
- if(useDeform) {
- if(inputVertexCos)
+ if (useDeform) {
+ if (inputVertexCos)
deformedVerts = inputVertexCos;
/* Apply all leading deforming modifiers */
- for(;md; md = md->next, curr = curr->next) {
+ for (;md; md = md->next, curr = curr->next) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
md->scene= scene;
- if(!modifier_isEnabled(scene, md, required_mode)) continue;
- if(useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue;
+ if (!modifier_isEnabled(scene, md, required_mode)) continue;
+ if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue;
- if(mti->type == eModifierTypeType_OnlyDeform) {
- if(!deformedVerts)
+ if (mti->type == eModifierTypeType_OnlyDeform) {
+ if (!deformedVerts)
deformedVerts = mesh_getVertexCos(me, &numVerts);
mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, useRenderParams, useDeform);
- } else {
+ }
+ else {
break;
}
/* grab modifiers until index i */
- if((index >= 0) && (modifiers_indexInObject(ob, md) >= index))
+ if ((index >= 0) && (modifiers_indexInObject(ob, md) >= index))
break;
}
@@ -1353,14 +1448,15 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
if (build_shapekey_layers)
add_shapekey_layers(dm, me, ob);
- if(deformedVerts) {
+ if (deformedVerts) {
CDDM_apply_vert_coords(*deform_r, deformedVerts);
CDDM_calc_normals(*deform_r);
}
}
- } else {
+ }
+ else {
/* default behavior for meshes */
- if(inputVertexCos)
+ if (inputVertexCos)
deformedVerts = inputVertexCos;
else
deformedVerts = mesh_getVertexCos(me, &numVerts);
@@ -1374,41 +1470,41 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
orcodm = NULL;
clothorcodm = NULL;
- for(;md; md = md->next, curr = curr->next) {
+ for (;md; md = md->next, curr = curr->next) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
md->scene= scene;
- if(!modifier_isEnabled(scene, md, required_mode)) continue;
- if(mti->type == eModifierTypeType_OnlyDeform && !useDeform) continue;
- if((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
- modifier_setError(md, "Modifier requires original data, bad stack position.");
+ if (!modifier_isEnabled(scene, md, required_mode)) continue;
+ if (mti->type == eModifierTypeType_OnlyDeform && !useDeform) continue;
+ if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
+ modifier_setError(md, "%s", TIP_("Modifier requires original data, bad stack position."));
continue;
}
- if(sculpt_mode && (!has_multires || multires_applied)) {
+ if (sculpt_mode && (!has_multires || multires_applied)) {
int unsupported= 0;
- if(scene->toolsettings->sculpt->flags & SCULPT_ONLY_DEFORM)
+ if (scene->toolsettings->sculpt->flags & SCULPT_ONLY_DEFORM)
unsupported|= mti->type != eModifierTypeType_OnlyDeform;
unsupported|= md->type == eModifierType_Multires && ((MultiresModifierData*)md)->sculptlvl==0;
unsupported|= multires_applied;
- if(unsupported) {
- modifier_setError(md, "Not supported in sculpt mode.");
+ if (unsupported) {
+ modifier_setError(md, "%s", TIP_("Not supported in sculpt mode."));
continue;
}
}
- if(needMapping && !modifier_supportsMapping(md)) continue;
- if(useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue;
+ if (needMapping && !modifier_supportsMapping(md)) continue;
+ if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) continue;
/* add an orco layer if needed by this modifier */
- if(mti->requiredDataMask)
+ if (mti->requiredDataMask)
mask = mti->requiredDataMask(ob, md);
else
mask = 0;
- if(dm && (mask & CD_MASK_ORCO))
+ if (dm && (mask & CD_MASK_ORCO))
add_orco_dm(ob, NULL, dm, orcodm, CD_ORCO);
/* How to apply modifier depends on (a) what we already have as
@@ -1416,10 +1512,10 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
* deformed vertices) and (b) what type the modifier is.
*/
- if(mti->type == eModifierTypeType_OnlyDeform) {
+ if (mti->type == eModifierTypeType_OnlyDeform) {
/* No existing verts to deform, need to build them. */
- if(!deformedVerts) {
- if(dm) {
+ if (!deformedVerts) {
+ if (dm) {
/* Deforming a derived mesh, read the vertex locations
* out of the mesh and deform them. Once done with this
* run of deformers verts will be written back.
@@ -1428,34 +1524,36 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
deformedVerts =
MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv");
dm->getVertCos(dm, deformedVerts);
- } else {
+ }
+ else {
deformedVerts = mesh_getVertexCos(me, &numVerts);
}
}
/* if this is not the last modifier in the stack then recalculate the normals
* to avoid giving bogus normals to the next modifier see: [#23673] */
- if(isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
+ if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
/* XXX, this covers bug #23673, but we may need normal calc for other types */
- if(dm && dm->type == DM_TYPE_CDDM) {
+ if (dm && dm->type == DM_TYPE_CDDM) {
CDDM_apply_vert_coords(dm, deformedVerts);
CDDM_calc_normals(dm);
}
}
mti->deformVerts(md, ob, dm, deformedVerts, numVerts, useRenderParams, useDeform);
- } else {
+ }
+ else {
DerivedMesh *ndm;
/* determine which data layers are needed by following modifiers */
- if(curr->next)
+ if (curr->next)
nextmask= (CustomDataMask)GET_INT_FROM_POINTER(curr->next->link);
else
nextmask= dataMask;
/* apply vertex coordinates or build a DerivedMesh as necessary */
- if(dm) {
- if(deformedVerts) {
+ if (dm) {
+ if (deformedVerts) {
DerivedMesh *tdm = CDDM_copy(dm);
dm->release(dm);
dm = tdm;
@@ -1463,18 +1561,19 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
CDDM_apply_vert_coords(dm, deformedVerts);
CDDM_calc_normals(dm);
}
- } else {
+ }
+ else {
dm = CDDM_from_mesh(me, ob);
if (build_shapekey_layers)
add_shapekey_layers(dm, me, ob);
- if(deformedVerts) {
+ if (deformedVerts) {
CDDM_apply_vert_coords(dm, deformedVerts);
CDDM_calc_normals(dm);
}
- if(do_init_wmcol)
+ if (do_init_wmcol)
DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
/* Constructive modifiers need to have an origindex
@@ -1484,7 +1583,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
* requests it, this way Mirror, Solidify etc will keep ORIGINDEX
* data by using generic DM_copy_vert_data() functions.
*/
- if(needMapping || (nextmask & CD_MASK_ORIGINDEX)) {
+ if (needMapping || (nextmask & CD_MASK_ORIGINDEX)) {
/* calc */
DM_add_vert_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
@@ -1505,12 +1604,12 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
DM_set_only_copy(dm, mask | (needMapping ? CD_MASK_ORIGINDEX : 0));
/* add cloth rest shape key if need */
- if(mask & CD_MASK_CLOTH_ORCO)
+ if (mask & CD_MASK_CLOTH_ORCO)
add_orco_dm(ob, NULL, dm, clothorcodm, CD_CLOTH_ORCO);
/* add an origspace layer if needed */
- if(((CustomDataMask)GET_INT_FROM_POINTER(curr->link)) & CD_MASK_ORIGSPACE_MLOOP) {
- if(!CustomData_has_layer(&dm->loopData, CD_ORIGSPACE_MLOOP)) {
+ if (((CustomDataMask)GET_INT_FROM_POINTER(curr->link)) & CD_MASK_ORIGSPACE_MLOOP) {
+ if (!CustomData_has_layer(&dm->loopData, CD_ORIGSPACE_MLOOP)) {
DM_add_loop_layer(dm, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL);
DM_init_origspace(dm);
}
@@ -1518,14 +1617,14 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
ndm = mti->applyModifier(md, ob, dm, useRenderParams, useCache);
- if(ndm) {
+ if (ndm) {
/* if the modifier returned a new dm, release the old one */
- if(dm && dm != ndm) dm->release(dm);
+ if (dm && dm != ndm) dm->release(dm);
dm = ndm;
- if(deformedVerts) {
- if(deformedVerts != inputVertexCos)
+ if (deformedVerts) {
+ if (deformedVerts != inputVertexCos)
MEM_freeN(deformedVerts);
deformedVerts = NULL;
@@ -1533,33 +1632,33 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
}
/* create an orco derivedmesh in parallel */
- if(nextmask & CD_MASK_ORCO) {
- if(!orcodm)
+ if (nextmask & CD_MASK_ORCO) {
+ if (!orcodm)
orcodm= create_orco_dm(ob, me, NULL, CD_ORCO);
nextmask &= ~CD_MASK_ORCO;
DM_set_only_copy(orcodm, nextmask | CD_MASK_ORIGINDEX);
ndm = mti->applyModifier(md, ob, orcodm, useRenderParams, 0);
- if(ndm) {
+ if (ndm) {
/* if the modifier returned a new dm, release the old one */
- if(orcodm && orcodm != ndm) orcodm->release(orcodm);
+ if (orcodm && orcodm != ndm) orcodm->release(orcodm);
orcodm = ndm;
}
}
/* create cloth orco derivedmesh in parallel */
- if(nextmask & CD_MASK_CLOTH_ORCO) {
- if(!clothorcodm)
+ if (nextmask & CD_MASK_CLOTH_ORCO) {
+ if (!clothorcodm)
clothorcodm= create_orco_dm(ob, me, NULL, CD_CLOTH_ORCO);
nextmask &= ~CD_MASK_CLOTH_ORCO;
DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX);
ndm = mti->applyModifier(md, ob, clothorcodm, useRenderParams, 0);
- if(ndm) {
+ if (ndm) {
/* if the modifier returned a new dm, release the old one */
- if(clothorcodm && clothorcodm != ndm) clothorcodm->release(clothorcodm);
+ if (clothorcodm && clothorcodm != ndm) clothorcodm->release(clothorcodm);
clothorcodm = ndm;
}
}
@@ -1567,32 +1666,32 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
/* in case of dynamic paint, make sure preview mask remains for following modifiers */
/* XXX Temp and hackish solution! */
if (md->type == eModifierType_DynamicPaint)
- append_mask |= CD_MASK_WEIGHT_MCOL;
+ append_mask |= CD_MASK_PREVIEW_MLOOPCOL;
/* In case of active preview modifier, make sure preview mask remains for following modifiers. */
else if ((md == previewmd) && (do_mod_wmcol)) {
DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
- append_mask |= CD_MASK_WEIGHT_MCOL;
+ append_mask |= CD_MASK_PREVIEW_MLOOPCOL;
}
}
isPrevDeform= (mti->type == eModifierTypeType_OnlyDeform);
/* grab modifiers until index i */
- if((index >= 0) && (modifiers_indexInObject(ob, md) >= index))
+ if ((index >= 0) && (modifiers_indexInObject(ob, md) >= index))
break;
- if(sculpt_mode && md->type == eModifierType_Multires)
+ if (sculpt_mode && md->type == eModifierType_Multires)
multires_applied = 1;
}
- for(md=firstmd; md; md=md->next)
+ for (md=firstmd; md; md=md->next)
modifier_freeTemporaryData(md);
/* Yay, we are done. If we have a DerivedMesh and deformed vertices
* need to apply these back onto the DerivedMesh. If we have no
* DerivedMesh then we need to build one.
*/
- if(dm && deformedVerts) {
+ if (dm && deformedVerts) {
finaldm = CDDM_copy(dm);
dm->release(dm);
@@ -1601,47 +1700,49 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
CDDM_calc_normals(finaldm);
#if 0 /* For later nice mod preview! */
- /* In case we need modified weights in CD_WEIGHT_MCOL, we have to re-compute it. */
- if(do_final_wmcol)
+ /* In case we need modified weights in CD_PREVIEW_MCOL, we have to re-compute it. */
+ if (do_final_wmcol)
DM_update_weight_mcol(ob, finaldm, draw_flag, NULL, 0, NULL);
#endif
- } else if(dm) {
+ }
+ else if (dm) {
finaldm = dm;
#if 0 /* For later nice mod preview! */
- /* In case we need modified weights in CD_WEIGHT_MCOL, we have to re-compute it. */
- if(do_final_wmcol)
+ /* In case we need modified weights in CD_PREVIEW_MCOL, we have to re-compute it. */
+ if (do_final_wmcol)
DM_update_weight_mcol(ob, finaldm, draw_flag, NULL, 0, NULL);
#endif
- } else {
+ }
+ else {
int recalc_normals= 0;
finaldm = CDDM_from_mesh(me, ob);
- if(build_shapekey_layers) {
+ if (build_shapekey_layers) {
add_shapekey_layers(finaldm, me, ob);
recalc_normals= 1;
}
- if(deformedVerts) {
+ if (deformedVerts) {
CDDM_apply_vert_coords(finaldm, deformedVerts);
recalc_normals= 1;
}
- if(recalc_normals) {
+ if (recalc_normals) {
CDDM_calc_normals(finaldm);
}
/* In this case, we should never have weight-modifying modifiers in stack... */
- if(do_init_wmcol)
+ if (do_init_wmcol)
DM_update_weight_mcol(ob, finaldm, draw_flag, NULL, 0, NULL);
}
/* add an orco layer if needed */
- if(dataMask & CD_MASK_ORCO) {
+ if (dataMask & CD_MASK_ORCO) {
add_orco_dm(ob, NULL, finaldm, orcodm, CD_ORCO);
- if(deform_r && *deform_r)
+ if (deform_r && *deform_r)
add_orco_dm(ob, NULL, *deform_r, NULL, CD_ORCO);
}
@@ -1659,7 +1760,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
{
/* calculating normals can re-calculate tessfaces in some cases */
+#if 0
int num_tessface = finaldm->getNumTessFaces(finaldm);
+#endif
/* --------------------------------------------------------------------- */
/* First calculate the polygon and vertex normals, re-tessellation
* copies these into the tessface's normal layer */
@@ -1678,23 +1781,46 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
* redundant in cases where the render mode doesn't use these inputs, but
* ideally eventually tessellation would happen on-demand, and this is one
* of the primary places it would be needed. */
- if (num_tessface == 0 && finaldm->getNumTessFaces(finaldm) == 0) {
+#if 0
+ if (num_tessface == 0 && finaldm->getNumTessFaces(finaldm) == 0)
+#else
+ if (finaldm->getNumTessFaces(finaldm) == 0) /* || !CustomData_has_layer(&finaldm->faceData, CD_POLYINDEX)) */
+#endif
+ {
finaldm->recalcTessellation(finaldm);
}
+ /* Even if tessellation is not needed, some modifiers migh have modified CD layers
+ * (like mloopcol or mloopuv), hence we have to update those. */
+ else if (finaldm->dirty & DM_DIRTY_TESS_CDLAYERS) {
+ /* A tessellation already exists, it should always have a CD_POLYINDEX. */
+ BLI_assert(CustomData_has_layer(&finaldm->faceData, CD_POLYINDEX));
+ DM_update_tessface_data(finaldm);
+ }
/* Need to watch this, it can cause issues, see bug [#29338] */
/* take care with this block, we really need testing frameworks */
/* --------------------------------------------------------------------- */
- }
+ /* without this, drawing ngon tri's faces will show ugly tessellated face
+ * normals and will also have to calculate normals on the fly, try avoid
+ * this where possible since calculating polygon normals isn't fast,
+ * note that this isn't a problem for subsurf (only quads) or editmode
+ * which deals with drawing differently.
+ *
+ * Never calc vertex normals because other code ensures these are up to date.
+ */
+ if ((finaldm->type == DM_TYPE_CDDM) && (CustomData_has_layer(&finaldm->faceData, CD_NORMAL) == FALSE)) {
+ CDDM_calc_normals_mapping_ex(finaldm, TRUE);
+ }
+ }
*final_r = finaldm;
- if(orcodm)
+ if (orcodm)
orcodm->release(orcodm);
- if(clothorcodm)
+ if (clothorcodm)
clothorcodm->release(clothorcodm);
- if(deformedVerts && deformedVerts != inputVertexCos)
+ if (deformedVerts && deformedVerts != inputVertexCos)
MEM_freeN(deformedVerts);
BLI_linklist_free(datamasks, NULL);
@@ -1722,9 +1848,9 @@ int editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *d
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
- if(!modifier_isEnabled(scene, md, required_mode)) return 0;
- if((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
- modifier_setError(md, "Modifier requires original data, bad stack position.");
+ if (!modifier_isEnabled(scene, md, required_mode)) return 0;
+ if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
+ modifier_setError(md, "%s", TIP_("Modifier requires original data, bad stack position."));
return 0;
}
@@ -1745,7 +1871,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
modifiers_clearErrors(ob);
- if(cage_r && cageIndex == -1) {
+ if (cage_r && cageIndex == -1) {
*cage_r = getEditDerivedBMesh(em, ob, NULL);
}
@@ -1755,18 +1881,18 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode);
curr = datamasks;
- for(i = 0; md; i++, md = md->next, curr = curr->next) {
+ for (i = 0; md; i++, md = md->next, curr = curr->next) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
md->scene= scene;
- if(!editbmesh_modifier_is_enabled(scene, md, dm))
+ if (!editbmesh_modifier_is_enabled(scene, md, dm))
continue;
/* add an orco layer if needed by this modifier */
- if(dm && mti->requiredDataMask) {
+ if (dm && mti->requiredDataMask) {
mask = mti->requiredDataMask(ob, md);
- if(mask & CD_MASK_ORCO)
+ if (mask & CD_MASK_ORCO)
add_orco_dm(ob, em, dm, orcodm, CD_ORCO);
}
@@ -1775,10 +1901,10 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
* deformed vertices) and (b) what type the modifier is.
*/
- if(mti->type == eModifierTypeType_OnlyDeform) {
+ if (mti->type == eModifierTypeType_OnlyDeform) {
/* No existing verts to deform, need to build them. */
- if(!deformedVerts) {
- if(dm) {
+ if (!deformedVerts) {
+ if (dm) {
/* Deforming a derived mesh, read the vertex locations
* out of the mesh and deform them. Once done with this
* run of deformers verts will be written back.
@@ -1787,7 +1913,8 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
deformedVerts =
MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv");
dm->getVertCos(dm, deformedVerts);
- } else {
+ }
+ else {
deformedVerts = editbmesh_get_vertex_cos(em, &numVerts);
}
}
@@ -1795,28 +1922,31 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
if (mti->deformVertsEM)
mti->deformVertsEM(md, ob, em, dm, deformedVerts, numVerts);
else mti->deformVerts(md, ob, dm, deformedVerts, numVerts, 0, 0);
- } else {
+ }
+ else {
DerivedMesh *ndm;
/* apply vertex coordinates or build a DerivedMesh as necessary */
- if(dm) {
- if(deformedVerts) {
+ if (dm) {
+ if (deformedVerts) {
DerivedMesh *tdm = CDDM_copy(dm);
- if(!(cage_r && dm == *cage_r)) dm->release(dm);
+ if (!(cage_r && dm == *cage_r)) dm->release(dm);
dm = tdm;
CDDM_apply_vert_coords(dm, deformedVerts);
CDDM_calc_normals(dm);
- } else if(cage_r && dm == *cage_r) {
+ }
+ else if (cage_r && dm == *cage_r) {
/* dm may be changed by this modifier, so we need to copy it
*/
dm = CDDM_copy(dm);
}
- } else {
+ }
+ else {
dm = CDDM_from_BMEditMesh(em, ob->data, FALSE, FALSE);
- if(deformedVerts) {
+ if (deformedVerts) {
CDDM_apply_vert_coords(dm, deformedVerts);
CDDM_calc_normals(dm);
}
@@ -1824,8 +1954,8 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
/* create an orco derivedmesh in parallel */
mask= (CustomDataMask)GET_INT_FROM_POINTER(curr->link);
- if(mask & CD_MASK_ORCO) {
- if(!orcodm)
+ if (mask & CD_MASK_ORCO) {
+ if (!orcodm)
orcodm= create_orco_dm(ob, ob->data, em, CD_ORCO);
mask &= ~CD_MASK_ORCO;
@@ -1836,9 +1966,9 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
else
ndm = mti->applyModifier(md, ob, orcodm, 0, 0);
- if(ndm) {
+ if (ndm) {
/* if the modifier returned a new dm, release the old one */
- if(orcodm && orcodm != ndm) orcodm->release(orcodm);
+ if (orcodm && orcodm != ndm) orcodm->release(orcodm);
orcodm = ndm;
}
}
@@ -1848,8 +1978,8 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
DM_set_only_copy(dm, mask | CD_MASK_ORIGINDEX);
- if(mask & CD_MASK_ORIGSPACE_MLOOP) {
- if(!CustomData_has_layer(&dm->loopData, CD_ORIGSPACE_MLOOP)) {
+ if (mask & CD_MASK_ORIGSPACE_MLOOP) {
+ if (!CustomData_has_layer(&dm->loopData, CD_ORIGSPACE_MLOOP)) {
DM_add_loop_layer(dm, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL);
DM_init_origspace(dm);
}
@@ -1861,7 +1991,7 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
ndm = mti->applyModifier(md, ob, dm, 0, 0);
if (ndm) {
- if(dm && dm != ndm)
+ if (dm && dm != ndm)
dm->release(dm);
dm = ndm;
@@ -1873,13 +2003,15 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
}
}
- if(cage_r && i == cageIndex) {
- if(dm && deformedVerts) {
+ if (cage_r && i == cageIndex) {
+ if (dm && deformedVerts) {
*cage_r = CDDM_copy(dm);
CDDM_apply_vert_coords(*cage_r, deformedVerts);
- } else if(dm) {
+ }
+ else if (dm) {
*cage_r = dm;
- } else {
+ }
+ else {
*cage_r =
getEditDerivedBMesh(em, ob,
deformedVerts ? MEM_dupallocN(deformedVerts) : NULL);
@@ -1893,10 +2025,10 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
* to apply these back onto the DerivedMesh. If we have no DerivedMesh
* then we need to build one.
*/
- if(dm && deformedVerts) {
+ if (dm && deformedVerts) {
*final_r = CDDM_copy(dm);
- if(!(cage_r && dm == *cage_r)) dm->release(dm);
+ if (!(cage_r && dm == *cage_r)) dm->release(dm);
CDDM_apply_vert_coords(*final_r, deformedVerts);
CDDM_calc_normals(*final_r); /* was CDDM_calc_normals_mapping - campbell */
@@ -1918,8 +2050,8 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
/* --- */
/* BMESH_ONLY, ensure tessface's used for drawing,
- * but dont recalculate if the last modifier in the stack gives us tessfaces
- * check if the derived meshes are DM_TYPE_EDITBMESH before calling, this isnt essential
+ * but don't recalculate if the last modifier in the stack gives us tessfaces
+ * check if the derived meshes are DM_TYPE_EDITBMESH before calling, this isn't essential
* but quiets annoying error messages since tessfaces wont be created. */
if ((*final_r)->type != DM_TYPE_EDITBMESH) {
DM_ensure_tessface(*final_r);
@@ -1934,13 +2066,13 @@ static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, D
/* --- */
/* add an orco layer if needed */
- if(dataMask & CD_MASK_ORCO)
+ if (dataMask & CD_MASK_ORCO)
add_orco_dm(ob, em, *final_r, orcodm, CD_ORCO);
- if(orcodm)
+ if (orcodm)
orcodm->release(orcodm);
- if(deformedVerts)
+ if (deformedVerts)
MEM_freeN(deformedVerts);
}
@@ -1971,7 +2103,7 @@ static void clear_mesh_caches(Object *ob)
ob->derivedDeform= NULL;
}
- if(ob->sculpt) {
+ if (ob->sculpt) {
object_sculpt_modifiers_changed(ob);
}
}
@@ -1995,6 +2127,12 @@ static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask,
ob->derivedFinal->needsFree = 0;
ob->derivedDeform->needsFree = 0;
ob->lastDataMask = dataMask;
+
+ if ((ob->mode & OB_MODE_SCULPT) && ob->sculpt) {
+ /* create PBVH immediately (would be created on the fly too,
+ but this avoids waiting on first stroke) */
+ ob->sculpt->pbvh= ob->derivedFinal->getPBVH(ob, ob->derivedFinal);
+ }
}
static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
@@ -2027,7 +2165,8 @@ void makeDerivedMesh(Scene *scene, Object *ob, BMEditMesh *em,
{
if (em) {
editbmesh_build_data(scene, ob, em, dataMask);
- } else {
+ }
+ else {
mesh_build_data(scene, ob, dataMask, build_shapekey_layers);
}
}
@@ -2039,7 +2178,7 @@ DerivedMesh *mesh_get_derived_final(Scene *scene, Object *ob, CustomDataMask dat
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
- if(!ob->derivedFinal || (dataMask & ob->lastDataMask) != dataMask)
+ if (!ob->derivedFinal || (dataMask & ob->lastDataMask) != dataMask)
mesh_build_data(scene, ob, dataMask, 0);
return ob->derivedFinal;
@@ -2050,7 +2189,7 @@ DerivedMesh *mesh_get_derived_deform(Scene *scene, Object *ob, CustomDataMask da
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
- if(!ob->derivedDeform || (dataMask & ob->lastDataMask) != dataMask)
+ if (!ob->derivedDeform || (dataMask & ob->lastDataMask) != dataMask)
mesh_build_data(scene, ob, dataMask, 0);
return ob->derivedDeform;
@@ -2132,7 +2271,7 @@ DerivedMesh *editbmesh_get_derived_cage_and_final(Scene *scene, Object *obedit,
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
- if(!em->derivedCage ||
+ if (!em->derivedCage ||
(em->lastDataMask & dataMask) != dataMask)
editbmesh_build_data(scene, obedit, em, dataMask);
@@ -2145,7 +2284,7 @@ DerivedMesh *editbmesh_get_derived_cage(Scene *scene, Object *obedit, BMEditMesh
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
- if(!em->derivedCage ||
+ if (!em->derivedCage ||
(em->lastDataMask & dataMask) != dataMask)
editbmesh_build_data(scene, obedit, em, dataMask);
@@ -2167,11 +2306,11 @@ static void make_vertexcosnos__mapFunc(void *userData, int index, float *co, flo
vec+= 6*index;
/* check if we've been here before (normal should not be 0) */
- if(vec[3] || vec[4] || vec[5]) return;
+ if (vec[3] || vec[4] || vec[5]) return;
copy_v3_v3(vec, co);
vec+= 3;
- if(no_f) {
+ if (no_f) {
copy_v3_v3(vec, no_f);
}
else {
@@ -2191,20 +2330,20 @@ float *mesh_get_mapped_verts_nors(Scene *scene, Object *ob)
float *vertexcosnos;
/* lets prevent crashing... */
- if(ob->type!=OB_MESH || me->totvert==0)
+ if (ob->type!=OB_MESH || me->totvert==0)
return NULL;
dm= mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH|CD_MASK_ORIGINDEX);
vertexcosnos= MEM_callocN(6*sizeof(float)*me->totvert, "vertexcosnos map");
- if(dm->foreachMappedVert) {
+ if (dm->foreachMappedVert) {
dm->foreachMappedVert(dm, make_vertexcosnos__mapFunc, vertexcosnos);
}
else {
float *fp= vertexcosnos;
int a;
- for(a=0; a< me->totvert; a++, fp+=6) {
+ for (a=0; a< me->totvert; a++, fp+=6) {
dm->getVertCo(dm, a, fp);
dm->getVertNo(dm, a, fp+3);
}
@@ -2256,7 +2395,7 @@ static void GetTextureCoordinate(const SMikkTSpaceContext * pContext, float fUV[
//assert(vert_index>=0 && vert_index<4);
SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
- if(pMesh->mtface!=NULL) {
+ if (pMesh->mtface!=NULL) {
float * uv = pMesh->mtface[face_num].uv[vert_index];
fUV[0]=uv[0]; fUV[1]=uv[1];
}
@@ -2272,8 +2411,8 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const
SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
const int smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH);
- if(!smoothnormal) { // flat
- if(pMesh->precomputedFaceNormals) {
+ if (!smoothnormal) { // flat
+ if (pMesh->precomputedFaceNormals) {
copy_v3_v3(fNorm, &pMesh->precomputedFaceNormals[3*face_num]);
}
else {
@@ -2282,7 +2421,7 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const
float *p1= pMesh->mvert[mf->v2].co;
float *p2= pMesh->mvert[mf->v3].co;
- if(mf->v4) {
+ if (mf->v4) {
float *p3 = pMesh->mvert[mf->v4].co;
normal_quad_v3(fNorm, p0, p1, p2, p3);
}
@@ -2320,7 +2459,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
int i, j, len, mf_vi[4], totvert, totface, iCalcNewMethod;
float *nors;
- if(CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1)
+ if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1)
return;
nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
@@ -2333,9 +2472,9 @@ void DM_add_tangent_layer(DerivedMesh *dm)
mface= dm->getTessFaceArray(dm);
mtface= dm->getTessFaceDataArray(dm, CD_MTFACE);
- if(!mtface) {
+ if (!mtface) {
orco= dm->getVertDataArray(dm, CD_ORCO);
- if(!orco)
+ if (!orco)
return;
}
@@ -2350,7 +2489,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
// new computation method
iCalcNewMethod = 1;
- if(iCalcNewMethod != 0) {
+ if (iCalcNewMethod != 0) {
SGLSLMeshToTangent mesh2tangent= {0};
SMikkTSpaceContext sContext= {0};
SMikkTSpaceInterface sInterface= {0};
@@ -2376,9 +2515,9 @@ void DM_add_tangent_layer(DerivedMesh *dm)
iCalcNewMethod = genTangSpaceDefault(&sContext);
}
- if(!iCalcNewMethod) {
+ if (!iCalcNewMethod) {
/* sum tangents at connected vertices */
- for(i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++) {
+ for (i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++) {
v1= &mvert[mf->v1];
v2= &mvert[mf->v2];
v3= &mvert[mf->v3];
@@ -2392,7 +2531,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
normal_tri_v3( fno,v3->co, v2->co, v1->co);
}
- if(mtface) {
+ if (mtface) {
uv1= tf->uv[0];
uv2= tf->uv[1];
uv3= tf->uv[2];
@@ -2403,7 +2542,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
map_to_sphere( &uv[0][0], &uv[0][1],orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]);
map_to_sphere( &uv[1][0], &uv[1][1],orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]);
map_to_sphere( &uv[2][0], &uv[2][1],orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]);
- if(v4)
+ if (v4)
map_to_sphere( &uv[3][0], &uv[3][1],orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]);
}
@@ -2412,7 +2551,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
sum_or_add_vertex_tangent(arena, &vtangents[mf->v2], tang, uv2);
sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3);
- if(mf->v4) {
+ if (mf->v4) {
v4= &mvert[mf->v4];
tangent_from_uv(uv1, uv3, uv4, v1->co, v3->co, v4->co, fno, tang);
@@ -2423,14 +2562,14 @@ void DM_add_tangent_layer(DerivedMesh *dm)
}
/* write tangent to layer */
- for(i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++, tangent+=4) {
+ for (i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++, tangent+=4) {
len= (mf->v4)? 4 : 3;
- if(mtface == NULL) {
+ if (mtface == NULL) {
map_to_sphere( &uv[0][0], &uv[0][1],orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]);
map_to_sphere( &uv[1][0], &uv[1][1],orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]);
map_to_sphere( &uv[2][0], &uv[2][1],orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]);
- if(len==4)
+ if (len==4)
map_to_sphere( &uv[3][0], &uv[3][1],orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]);
}
@@ -2439,7 +2578,7 @@ void DM_add_tangent_layer(DerivedMesh *dm)
mf_vi[2]= mf->v3;
mf_vi[3]= mf->v4;
- for(j=0; j<len; j++) {
+ for (j=0; j<len; j++) {
vtang= find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]);
normalize_v3_v3(tangent[j], vtang);
((float *) tangent[j])[3]=1.0f;
@@ -2460,7 +2599,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm)
MFace * mface = dm->getTessFaceArray(dm);
MTFace * mtface = dm->getTessFaceDataArray(dm, CD_MTFACE);
- if(mtface) {
+ if (mtface) {
double dsum = 0.0;
int nr_accumulated = 0;
int f;
@@ -2480,7 +2619,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm)
// discard degenerate faces
is_degenerate = 0;
- if( equals_v3v3(verts[0], verts[1]) || equals_v3v3(verts[0], verts[2]) || equals_v3v3(verts[1], verts[2]) ||
+ if ( equals_v3v3(verts[0], verts[1]) || equals_v3v3(verts[0], verts[2]) || equals_v3v3(verts[1], verts[2]) ||
equals_v2v2(tex_coords[0], tex_coords[1]) || equals_v2v2(tex_coords[0], tex_coords[2]) || equals_v2v2(tex_coords[1], tex_coords[2]) )
{
is_degenerate = 1;
@@ -2509,7 +2648,7 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm)
if (i == 0 ) {
is_signed = (signed_area < 0.0f) ? 1 : 0;
}
- else if((is_signed != 0) != (signed_area < 0.0f)) {
+ else if ((is_signed != 0) != (signed_area < 0.0f)) {
is_degenerate = 1;
}
@@ -2534,10 +2673,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm)
sub_v3_v3v3(vtmp, verts[3], verts[1]);
pos_len_diag1 = dot_v3v3(vtmp, vtmp);
- if(pos_len_diag1<pos_len_diag0) {
+ if (pos_len_diag1<pos_len_diag0) {
offs=1; // alter split
}
- else if(pos_len_diag0==pos_len_diag1) { /* do UV check instead */
+ else if (pos_len_diag0==pos_len_diag1) { /* do UV check instead */
float tex_len_diag0, tex_len_diag1;
sub_v2_v2v2(vtmp, tex_coords[2], tex_coords[0]);
@@ -2610,25 +2749,25 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
fdata = tfdata = dm->getTessFaceDataLayout(dm);
/* calc auto bump scale if necessary */
- if(dm->auto_bump_scale<=0.0f)
+ if (dm->auto_bump_scale<=0.0f)
DM_calc_auto_bump_scale(dm);
/* add a tangent layer if necessary */
- for(b = 0; b < gattribs->totlayer; b++)
- if(gattribs->layer[b].type == CD_TANGENT)
- if(CustomData_get_layer_index(fdata, CD_TANGENT) == -1)
+ for (b = 0; b < gattribs->totlayer; b++)
+ if (gattribs->layer[b].type == CD_TANGENT)
+ if (CustomData_get_layer_index(fdata, CD_TANGENT) == -1)
DM_add_tangent_layer(dm);
- for(b = 0; b < gattribs->totlayer; b++) {
- if(gattribs->layer[b].type == CD_MTFACE) {
+ for (b = 0; b < gattribs->totlayer; b++) {
+ if (gattribs->layer[b].type == CD_MTFACE) {
/* uv coordinates */
- if(gattribs->layer[b].name[0])
+ if (gattribs->layer[b].name[0])
layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE,
gattribs->layer[b].name);
else
layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE);
- if(layer != -1) {
+ if (layer != -1) {
a = attribs->tottface++;
attribs->tface[a].array = tfdata->layers[layer].data;
@@ -2642,7 +2781,7 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
int player;
CustomData *pdata = dm->getPolyDataLayout(dm);
- if(gattribs->layer[b].name[0])
+ if (gattribs->layer[b].name[0])
player = CustomData_get_named_layer_index(pdata, CD_MTEXPOLY,
gattribs->layer[b].name);
else
@@ -2660,15 +2799,15 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
}
#endif
}
- else if(gattribs->layer[b].type == CD_MCOL) {
+ else if (gattribs->layer[b].type == CD_MCOL) {
/* vertex colors */
- if(gattribs->layer[b].name[0])
+ if (gattribs->layer[b].name[0])
layer = CustomData_get_named_layer_index(tfdata, CD_MCOL,
gattribs->layer[b].name);
else
layer = CustomData_get_active_layer_index(tfdata, CD_MCOL);
- if(layer != -1) {
+ if (layer != -1) {
a = attribs->totmcol++;
attribs->mcol[a].array = tfdata->layers[layer].data;
@@ -2676,11 +2815,11 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
attribs->mcol[a].glIndex = gattribs->layer[b].glindex;
}
}
- else if(gattribs->layer[b].type == CD_TANGENT) {
+ else if (gattribs->layer[b].type == CD_TANGENT) {
/* tangents */
layer = CustomData_get_layer_index(fdata, CD_TANGENT);
- if(layer != -1) {
+ if (layer != -1) {
attribs->tottang = 1;
attribs->tang.array = fdata->layers[layer].data;
@@ -2688,11 +2827,11 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
attribs->tang.glIndex = gattribs->layer[b].glindex;
}
}
- else if(gattribs->layer[b].type == CD_ORCO) {
+ else if (gattribs->layer[b].type == CD_ORCO) {
/* original coordinates */
layer = CustomData_get_layer_index(vdata, CD_ORCO);
- if(layer != -1) {
+ if (layer != -1) {
attribs->totorco = 1;
attribs->orco.array = vdata->layers[layer].data;
@@ -2713,7 +2852,7 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm)
dm->getMinMax(dm, min, max);
- if(!ob->bb)
+ if (!ob->bb)
ob->bb= MEM_callocN(sizeof(BoundBox), "DM-BoundBox");
boundbox_set_from_min_max(ob->bb, min, max);
@@ -2731,12 +2870,12 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm)
*/
-BM_INLINE int navmesh_bit(int a, int b)
+BLI_INLINE int navmesh_bit(int a, int b)
{
return (a & (1 << b)) >> b;
}
-BM_INLINE void navmesh_intToCol(int i, float col[3])
+BLI_INLINE void navmesh_intToCol(int i, float col[3])
{
int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1;
int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1;
@@ -2767,11 +2906,11 @@ static void navmesh_drawColored(DerivedMesh *dm)
#endif
glDisable(GL_LIGHTING);
- /* if(GPU_buffer_legacy(dm) ) */ { /* TODO - VBO draw code, not high priority - campbell */
+ /* if (GPU_buffer_legacy(dm) ) */ { /* TODO - VBO draw code, not high priority - campbell */
DEBUG_VBO( "Using legacy code. drawNavMeshColored\n" );
//glShadeModel(GL_SMOOTH);
glBegin(glmode = GL_QUADS);
- for(a = 0; a < dm->numTessFaceData; a++, mface++) {
+ for (a = 0; a < dm->numTessFaceData; a++, mface++) {
int new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES;
int pi = polygonIdx[a];
if (pi <= 0) {
@@ -2781,7 +2920,7 @@ static void navmesh_drawColored(DerivedMesh *dm)
navmesh_intToCol(pi, col);
}
- if(new_glmode != glmode) {
+ if (new_glmode != glmode) {
glEnd();
glBegin(glmode = new_glmode);
}
@@ -2789,7 +2928,7 @@ static void navmesh_drawColored(DerivedMesh *dm)
glVertex3fv(mvert[mface->v1].co);
glVertex3fv(mvert[mface->v2].co);
glVertex3fv(mvert[mface->v3].co);
- if(mface->v4) {
+ if (mface->v4) {
glVertex3fv(mvert[mface->v4].co);
}
}
@@ -3003,7 +3142,7 @@ char *DM_debug_info(DerivedMesh *dm)
void DM_debug_print(DerivedMesh *dm)
{
char *str = DM_debug_info(dm);
- printf("%s", str);
+ puts(str);
fflush(stdout);
MEM_freeN(str);
}