=bmesh= fix bug with uvlayers

This commit is contained in:
Joseph Eagar 2011-02-23 08:12:27 +00:00
parent 1c0cf60377
commit c128a8c12a
8 changed files with 79 additions and 47 deletions

@ -926,6 +926,28 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void
cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, userData);
}
#define PASSVERT(index, vert) { \
if(attribs.totorco) \
glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]); \
for(b = 0; b < attribs.tottface; b++) { \
MTFace *tf = &attribs.tface[b].array[a]; \
glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]); \
} \
for(b = 0; b < attribs.totmcol; b++) { \
MCol *cp = &attribs.mcol[b].array[a*4 + vert]; \
GLubyte col[4]; \
col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; \
glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col); \
} \
if(attribs.tottang) { \
float *tang = attribs.tang.array[a*4 + vert]; \
glVertexAttrib3fvARB(attribs.tang.glIndex, tang); \
} \
if(smoothnormal) \
glNormal3sv(mvert[index].no); \
glVertex3fv(mvert[index].co); \
}
static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs), int (*setDrawOptions)(void *userData, int index), void *userData)
{
CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@ -1012,28 +1034,6 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
}
}
#define PASSVERT(index, vert) { \
if(attribs.totorco) \
glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]); \
for(b = 0; b < attribs.tottface; b++) { \
MTFace *tf = &attribs.tface[b].array[a]; \
glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]); \
} \
for(b = 0; b < attribs.totmcol; b++) { \
MCol *cp = &attribs.mcol[b].array[a*4 + vert]; \
GLubyte col[4]; \
col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a; \
glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col); \
} \
if(attribs.tottang) { \
float *tang = attribs.tang.array[a*4 + vert]; \
glVertexAttrib3fvARB(attribs.tang.glIndex, tang); \
} \
if(smoothnormal) \
glNormal3sv(mvert[index].no); \
glVertex3fv(mvert[index].co); \
}
PASSVERT(mface->v1, 0);
PASSVERT(mface->v2, 1);
PASSVERT(mface->v3, 2);

@ -127,9 +127,10 @@ void tag_out_edges(BMesh *bm, EdgeTag *etags, BMOperator *op)
BMLoop *l, *startl;
BMEdge *e;
BMVert *v;
int i;
while (1) {
int i, ok;
ok=0;
while (ok++ < 100000) {
BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {
if (!BMO_TestFlag(bm, e, EDGE_SEAM))
continue;

@ -798,7 +798,7 @@ int EDBM_texFaceCheck(BMEditMesh *em)
{
/* some of these checks could be a touch overkill */
return em && em->bm->totface && CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY) &&
CustomData_has_layer(&em->bm->ldata, CD_MLOOPCOL);
CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV);
}
int EDBM_vertColorCheck(BMEditMesh *em)

@ -1582,12 +1582,17 @@ static int knifetool_invoke (bContext *C, wmOperator *op, wmEvent *evt)
static int knifetool_modal (bContext *C, wmOperator *op, wmEvent *event)
{
Object *obedit;
knifetool_opdata *kcd= op->customdata;
if (!C) {
return OPERATOR_FINISHED;
}
obedit = CTX_data_edit_object(C);
if (!obedit || obedit->type != OB_MESH || ((Mesh*)obedit->data)->edit_btmesh != kcd->em)
return OPERATOR_FINISHED;
view3d_operator_needs_opengl(C);
switch (event->type) {

@ -67,19 +67,26 @@
#include "mesh_intern.h"
#define GET_CD_DATA(me, data) (me->edit_btmesh ? &me->edit_btmesh->bm->data : &me->data)
static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer)
{
Mesh *me = ob->data;
CustomData *data= (me->edit_btmesh)? &me->edit_btmesh->bm->pdata: &me->pdata;
CustomData *data;
void *actlayerdata, *rndlayerdata, *clonelayerdata, *stencillayerdata, *layerdata=layer->data;
int type= layer->type;
int index= CustomData_get_layer_index(data, type);
int i, actindex, rndindex, cloneindex, stencilindex, tot = me->totpoly;
int index;
int i, actindex, rndindex, cloneindex, stencilindex, tot;
if (layer->type == CD_MLOOPCOL) {
if (layer->type == CD_MLOOPCOL || layer->type == CD_MLOOPUV) {
data = (me->edit_btmesh)? &me->edit_btmesh->bm->ldata: &me->ldata;
tot = me->totloop;
} else {
data = (me->edit_btmesh)? &me->edit_btmesh->bm->pdata: &me->pdata;
tot = me->totpoly;
}
index = CustomData_get_layer_index(data, type);
/* ok, deleting a non-active layer needs to preserve the active layer indices.
to do this, we store a pointer to the .data member of both layer and the active layer,
@ -179,20 +186,31 @@ int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me, cons
CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
if(active_set || layernum==0)
CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
BM_add_data_layer(em->bm, &em->bm->ldata, CD_MLOOPUV);
CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum);
if(active_set || layernum==0)
CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum);
}
else {
layernum= CustomData_number_of_layers(&me->pdata, MAX_MTFACE);
layernum= CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
if(layernum >= MAX_MTFACE)
return 0;
if(me->mtface)
if(me->mtpoly) {
CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DUPLICATE, me->mtpoly, me->totpoly, name);
else
CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DUPLICATE, me->mloopuv, me->totloop, name);
} else {
CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, name);
if(active_set || layernum==0)
CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, name);
}
if(active_set || layernum==0) {
CustomData_set_layer_active(&me->pdata, CD_MTEXPOLY, layernum);
CustomData_set_layer_active(&me->ldata, CD_MLOOPUV, layernum);
}
mesh_update_customdata_pointers(me);
}
@ -204,16 +222,22 @@ int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me, cons
int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me)
{
CustomDataLayer *cdl;
CustomData *pdata = GET_CD_DATA(me, pdata), *ldata = GET_CD_DATA(me, ldata);
CustomDataLayer *cdlp, *cdlu;
int index;
index= CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
cdl= (index == -1)? NULL: &me->pdata.layers[index];
index= CustomData_get_active_layer_index(pdata, CD_MTEXPOLY);
cdlp= (index == -1)? NULL: &pdata->layers[index];
if(!cdl)
index= CustomData_get_active_layer_index(ldata, CD_MLOOPUV);
cdlu= (index == -1)? NULL: &ldata->layers[index];
if (!cdlp || !cdlu)
return 0;
delete_customdata_layer(C, ob, cdl);
delete_customdata_layer(C, ob, cdlp);
delete_customdata_layer(C, ob, cdlu);
DAG_id_flush_update(&me->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
@ -274,8 +298,8 @@ int ED_mesh_color_remove(bContext *C, Object *ob, Mesh *me)
CustomDataLayer *cdl;
int index;
index= CustomData_get_active_layer_index(&me->pdata, CD_MLOOPCOL);
cdl= (index == -1)? NULL: &me->pdata.layers[index];
index= CustomData_get_active_layer_index(&me->ldata, CD_MLOOPCOL);
cdl= (index == -1)? NULL: &me->ldata.layers[index];
if(!cdl)
return 0;
@ -554,6 +578,7 @@ void MESH_OT_sticky_remove(wmOperatorType *ot)
static void mesh_calc_edges(Mesh *mesh, int update)
{
#if 0
CustomData edata;
EdgeHashIterator *ehi;
MFace *mf = mesh->mface;
@ -617,6 +642,7 @@ static void mesh_calc_edges(Mesh *mesh, int update)
mesh->medge = CustomData_get_layer(&mesh->edata, CD_MEDGE);
BLI_edgehash_free(eh, NULL);
#endif
}
void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges)

@ -173,13 +173,13 @@ static void draw_image_grid(ARegion *ar, float zoomx, float zoomy)
if(gridsize<=0.0f) return;
if(gridsize<1.0f) {
while(gridsize<1.0f) {
while(gridsize<1.0f && gridsize<1000000.0f ) {
gridsize*= 4.0;
gridstep*= 4.0;
}
}
else {
while(gridsize>=4.0f) {
while(gridsize>=4.0f && gridsize<1000000.0f) {
gridsize/= 4.0;
gridstep/= 4.0;
}

@ -85,7 +85,7 @@ static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit)
return 1;
}
if(em && em->bm->totface) {// && !CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY)) {
if(em && em->bm->totface && !CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY)) {
BM_add_data_layer(em->bm, &em->bm->pdata, CD_MTEXPOLY);
BM_add_data_layer(em->bm, &em->bm->ldata, CD_MLOOPUV);
}

@ -38,7 +38,7 @@ static bNodeSocketType sh_node_output_in[]= {
static void node_shader_exec_output(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
if(data) {
if(data && in[0] && in[1]) {
ShadeInput *shi= ((ShaderCallData *)data)->shi;
float col[4];