diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-12-21 16:47:27 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-12-21 16:47:27 +0300 |
commit | 47bc3d1208c48903f53728d17d3acbb1ccbd06cb (patch) | |
tree | eca808294b88940590b8dc7e9693acc20ef2048f /source/blender/blenkernel | |
parent | edccdf934018264002c034906e8a287d12b7ead7 (diff) |
Added names to UV and vertex color layers, and display them as a list.
Added support for multiple UVs in the render engine. This also involved
changing the way faces are stored, to allow data to be added optionally
per 256 faces, same as the existing system for vertices.
A UV layer can be specified in the Map Input panel and the Geometry node
by name. Leaving this field blank will default to the active UV layer.
Also added sharing of face selection and hiding between UV layers, and at
the same time improved syncing with editmode selection and hiding.
Still to do:
- Multi UV support for fastshade.
- Multires and NMesh preservation of multiple UV sets.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_customdata.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 96 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 44 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node_shaders.c | 22 |
5 files changed, 131 insertions, 37 deletions
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 3f133adc68a..b20e60c9442 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -166,6 +166,7 @@ void *CustomData_em_get(const struct CustomData *data, void *block, int type); void *CustomData_get_layer(const struct CustomData *data, int type); void *CustomData_get_layer_n(const struct CustomData *data, int type, int n); +int CustomData_get_layer_index(const struct CustomData *data, int type); int CustomData_get_active_layer_index(const struct CustomData *data, int type); /* copies the data from source to the data element at index in the first @@ -206,4 +207,7 @@ int CustomData_sizeof(int type); /* get the name of a layer type */ const char *CustomData_layertype_name(int type); +/* make sure the name of layer at index is unique */ +void CustomData_set_layer_unique_name(struct CustomData *data, int index); + #endif diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 586c6db972b..2567595171c 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -34,6 +34,7 @@ #include "BKE_customdata.h" +#include "BLI_blenlib.h" #include "BLI_linklist.h" #include "DNA_customdata_types.h" @@ -52,6 +53,7 @@ typedef struct LayerTypeInfo { int size; /* the memory size of one element of this layer's data */ char *structname; /* name of the struct used, for file writing */ int structnum; /* number of structs per element, for file writing */ + char *defaultname; /* default layer name */ /* a function to copy count elements of this layer's data * (deep copy if appropriate) @@ -351,22 +353,22 @@ static void layerDefault_mcol(void *data, int count) } const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { - {sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL}, - {sizeof(MSticky), "MSticky", 1, NULL, NULL, layerInterp_msticky, NULL, + {sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(MSticky), "MSticky", 1, NULL, NULL, NULL, layerInterp_msticky, NULL, NULL}, - {sizeof(MDeformVert), "MDeformVert", 1, layerCopy_mdeformvert, + {sizeof(MDeformVert), "MDeformVert", 1, NULL, layerCopy_mdeformvert, layerFree_mdeformvert, layerInterp_mdeformvert, NULL, NULL}, - {sizeof(MEdge), "MEdge", 1, NULL, NULL, NULL, NULL, NULL}, - {sizeof(MFace), "MFace", 1, NULL, NULL, NULL, NULL, NULL}, - {sizeof(MTFace), "MTFace", 1, layerCopy_tface, NULL, + {sizeof(MEdge), "MEdge", 1, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(MFace), "MFace", 1, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(MTFace), "MTFace", 1, "UVTex", layerCopy_tface, NULL, layerInterp_tface, layerSwap_tface, layerDefault_tface}, /* 4 MCol structs per face */ - {sizeof(MCol)*4, "MCol", 4, NULL, NULL, layerInterp_mcol, + {sizeof(MCol)*4, "MCol", 4, "Col", NULL, NULL, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol}, - {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL}, + {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 3 floats per normal vector */ - {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL}, - {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL}, + {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, }; const char *LAYERTYPENAMES[CD_NUMTYPES] = { @@ -403,7 +405,7 @@ static const char *layerType_getName(int type) static void customData_update_offsets(CustomData *data); static CustomDataLayer *customData_add_layer__internal(CustomData *data, - int type, int alloctype, void *layerdata, int totelem); + int type, int alloctype, void *layerdata, int totelem, const char *name); void CustomData_merge(const struct CustomData *source, struct CustomData *dest, CustomDataMask mask, int alloctype, int totelem) @@ -432,10 +434,10 @@ void CustomData_merge(const struct CustomData *source, struct CustomData *dest, if((alloctype == CD_ASSIGN) && (layer->flag & CD_FLAG_NOFREE)) newlayer = customData_add_layer__internal(dest, type, CD_REFERENCE, - layer->data, totelem); + layer->data, totelem, layer->name); else newlayer = customData_add_layer__internal(dest, type, alloctype, - layer->data, totelem); + layer->data, totelem, layer->name); if(newlayer) newlayer->active = lastactive; @@ -493,7 +495,7 @@ static void customData_update_offsets(CustomData *data) data->totsize = offset; } -static int CustomData_get_layer_index(const struct CustomData *data, int type) +int CustomData_get_layer_index(const CustomData *data, int type) { int i; @@ -550,7 +552,7 @@ static int customData_resize(CustomData *data, int amount) } static CustomDataLayer *customData_add_layer__internal(CustomData *data, - int type, int alloctype, void *layerdata, int totelem) + int type, int alloctype, void *layerdata, int totelem, const char *name) { const LayerTypeInfo *typeInfo= layerType_getInfo(type); int size = typeInfo->size * totelem, flag = 0, index = data->totlayer; @@ -586,6 +588,8 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, } } + data->totlayer++; + /* keep layers ordered by type */ for( ; index > 0 && data->layers[index - 1].type > type; --index) data->layers[index] = data->layers[index - 1]; @@ -594,13 +598,18 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, data->layers[index].flag = flag; data->layers[index].data = newlayerdata; + if(name) { + strcpy(data->layers[index].name, name); + CustomData_set_layer_unique_name(data, index); + } + else + data->layers[index].name[0] = '\0'; + if(index > 0 && data->layers[index-1].type == type) data->layers[index].active = data->layers[index-1].active; else data->layers[index].active = 0; - data->totlayer++; - customData_update_offsets(data); return &data->layers[index]; @@ -610,9 +619,10 @@ void *CustomData_add_layer(CustomData *data, int type, int alloctype, void *layerdata, int totelem) { CustomDataLayer *layer; + const LayerTypeInfo *typeInfo= layerType_getInfo(type); layer = customData_add_layer__internal(data, type, alloctype, layerdata, - totelem); + totelem, typeInfo->defaultname); if(layer) return layer->data; @@ -1195,3 +1205,53 @@ const char *CustomData_layertype_name(int type) { return layerType_getName(type); } + +void CustomData_set_layer_unique_name(CustomData *data, int index) +{ + char tempname[64]; + int number, i, type; + char *dot, *name; + CustomDataLayer *layer, *nlayer= &data->layers[index]; + const LayerTypeInfo *typeInfo= layerType_getInfo(nlayer->type); + + if (!typeInfo->defaultname) + return; + + type = nlayer->type; + name = nlayer->name; + + if (name[0] == '\0') + BLI_strncpy(nlayer->name, typeInfo->defaultname, sizeof(nlayer->name)); + + /* see if there is a duplicate */ + for(i=0; i<data->totlayer; i++) { + layer = &data->layers[i]; + + if(i!=index && layer->type==type && strcmp(layer->name, name)==0) + break; + } + + if(i == data->totlayer) + return; + + /* strip off the suffix */ + dot = strchr(nlayer->name, '.'); + if(dot) *dot=0; + + for(number=1; number <=999; number++) { + sprintf(tempname, "%s.%03d", nlayer->name, number); + + for(i=0; i<data->totlayer; i++) { + layer = &data->layers[i]; + + if(i!=index && layer->type==type && strcmp(layer->name, tempname)==0) + break; + } + + if(i == data->totlayer) { + BLI_strncpy(nlayer->name, tempname, sizeof(nlayer->name)); + return; + } + } +} + diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 62c8d53d15a..0e69607d1bb 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -282,7 +282,6 @@ void count_displist(ListBase *lb, int *totvert, int *totface) static ShadeInput shi; static void init_fastshade_shadeinput(void) { - memset(&shi, 0, sizeof(ShadeInput)); shi.lay= G.scene->lay; shi.view[2]= -1.0f; @@ -311,15 +310,19 @@ void fastshade_free_render(void) } } -static void fastshade(float *co, float *nor, float *orco, float *uv, Material *ma, char *col1, char *col2, char *vertcol) +static void fastshade(float *co, float *nor, float *orco, float *uv, char *uvname, Material *ma, char *col1, char *col2, char *vertcol, char *colname) { ShadeResult shr; int a; if(vertcol) { - shi.vcol[0]= ((float)vertcol[3])/255.0f; - shi.vcol[1]= ((float)vertcol[2])/255.0f; - shi.vcol[2]= ((float)vertcol[1])/255.0f; + shi.col[0].col[0]= ((float)vertcol[3])/255.0f; + shi.col[0].col[1]= ((float)vertcol[2])/255.0f; + shi.col[0].col[2]= ((float)vertcol[1])/255.0f; + shi.col[0].name= colname; + shi.totcol= 1; + + VECCOPY(shi.vcol, shi.col[0].col); } VECCOPY(shi.co, co); @@ -343,12 +346,15 @@ static void fastshade(float *co, float *nor, float *orco, float *uv, Material *m } if(ma->texco & TEXCO_UV) { if(uv) { - shi.uv[0]= 2.0f*uv[0]-1.0f; - shi.uv[1]= 2.0f*uv[1]-1.0f; + shi.uv[0].uv[0]= 2.0f*uv[0]-1.0f; + shi.uv[0].uv[1]= 2.0f*uv[1]-1.0f; + shi.uv[0].uv[2]= 1.0f; } else { - VECCOPY(shi.uv, shi.lo); + VECCOPY(shi.uv[0].uv, shi.lo); } + shi.uv[0].name = uvname; + shi.totuv= 1; } if(ma->texco & TEXCO_OBJECT) { VECCOPY(shi.co, shi.lo); @@ -449,7 +455,8 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un MTFace *mtface; unsigned int *col1, *col2; float *orco, *vnors, *nors, imat[3][3], mat[4][4], vec[3]; - int a, i, need_orco, totface, totvert; + int a, i, need_orco, totface, totvert, layerindex; + char *uvname= "", *colname= ""; CustomDataMask dataMask = CD_MASK_BAREMESH | CD_MASK_MCOL | CD_MASK_MTFACE | CD_MASK_NORMAL; @@ -470,6 +477,15 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un totvert = dm->getNumVerts(dm); totface = dm->getNumFaces(dm); + if (mcol) { + layerindex= CustomData_get_active_layer_index(&dm->faceData, CD_MCOL); + colname= dm->faceData.layers[layerindex].name; + } + if (mtface) { + layerindex= CustomData_get_active_layer_index(&dm->faceData, CD_MTFACE); + uvname= dm->faceData.layers[layerindex].name; + } + if (onlyForMesh) { col1 = *col1_r; col2 = NULL; @@ -546,7 +562,7 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un vec[0]+= 0.001*vn[0]; vec[1]+= 0.001*vn[1]; vec[2]+= 0.001*vn[2]; - fastshade(vec, vn, orco?&orco[vidx[j]*3]:mv->co, uv, ma, col1, col2, mcol); + fastshade(vec, vn, orco?&orco[vidx[j]*3]:mv->co, uv, uvname, ma, col1, col2, mcol, colname); } } MEM_freeN(vnors); @@ -566,7 +582,7 @@ void shadeMeshMCol(Object *ob, Mesh *me) Render *re= fastshade_get_render(); mesh_create_shadedColors(re, ob, 1, (unsigned int **)&me->mcol, NULL); - + /* swap bytes */ for(cp= (char *)me->mcol, a= 4*me->totface; a>0; a--, cp+=4) { SWAP(char, cp[0], cp[3]); @@ -646,7 +662,7 @@ void shadeDispList(Base *base) VECCOPY(vec, fp); Mat4MulVecfl(mat, vec); - fastshade(vec, n1, fp, NULL, ma, (char *)col1, NULL, NULL); + fastshade(vec, n1, fp, NULL, "", ma, (char *)col1, NULL, NULL, ""); fp+= 3; col1++; } @@ -667,7 +683,7 @@ void shadeDispList(Base *base) n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2]; Normalise(n1); - fastshade(vec, n1, fp, NULL, ma, (char *)col1, NULL, NULL); + fastshade(vec, n1, fp, NULL, "", ma, (char *)col1, NULL, NULL, ""); fp+= 3; nor+= 3; col1++; } @@ -705,7 +721,7 @@ void shadeDispList(Base *base) n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2]; Normalise(n1); - fastshade(vec, n1, fp, NULL, ma, (char *)col1, NULL, NULL); + fastshade(vec, n1, fp, NULL, "", ma, (char *)col1, NULL, NULL, ""); fp+= 3; col1++; nor+= 3; } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index d10ff6c6d33..59dcccc1f8d 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -785,6 +785,8 @@ bNode *nodeAddNodeType(bNodeTree *ntree, int type, bNodeTree *ngroup) node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); else if(type==SH_NODE_CURVE_RGB) node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); + else if(type==SH_NODE_GEOMETRY) + node->storage= MEM_callocN(sizeof(NodeGeometry), "NodeGeometry"); } else if(ntree->type==NTREE_COMPOSIT) { if(type==CMP_NODE_VALTORGB) diff --git a/source/blender/blenkernel/intern/node_shaders.c b/source/blender/blenkernel/intern/node_shaders.c index dbdca2edcb6..f332873de49 100644 --- a/source/blender/blenkernel/intern/node_shaders.c +++ b/source/blender/blenkernel/intern/node_shaders.c @@ -188,13 +188,25 @@ static void node_shader_exec_geom(void *data, bNode *node, bNodeStack **in, bNod { if(data) { ShadeInput *shi= ((ShaderCallData *)data)->shi; + ShadeInputUV *suv= &shi->uv[0]; + NodeGeometry *ngeo= (NodeGeometry*)node->storage; + int i; + + if(ngeo->uvname[0]) { + for(i = 0; i < shi->totuv; i++) { + if(strcmp(shi->uv[i].name, ngeo->uvname)==0) { + suv= &shi->uv[i]; + break; + } + } + } /* out: global, local, view, orco, uv, normal */ VECCOPY(out[GEOM_OUT_GLOB]->vec, shi->gl); VECCOPY(out[GEOM_OUT_LOCAL]->vec, shi->co); VECCOPY(out[GEOM_OUT_VIEW]->vec, shi->view); VECCOPY(out[GEOM_OUT_ORCO]->vec, shi->lo); - VECCOPY(out[GEOM_OUT_UV]->vec, shi->uv); + VECCOPY(out[GEOM_OUT_UV]->vec, suv->uv); VECCOPY(out[GEOM_OUT_NORMAL]->vec, shi->vno); if(shi->osatex) { @@ -206,7 +218,7 @@ static void node_shader_exec_geom(void *data, bNode *node, bNodeStack **in, bNod out[GEOM_OUT_VIEW]->datatype= NS_OSA_VALUES; out[GEOM_OUT_ORCO]->data= shi->dxlo; out[GEOM_OUT_ORCO]->datatype= NS_OSA_VECTORS; - out[GEOM_OUT_UV]->data= shi->dxuv; + out[GEOM_OUT_UV]->data= suv->dxuv; out[GEOM_OUT_UV]->datatype= NS_OSA_VECTORS; out[GEOM_OUT_NORMAL]->data= shi->dxno; out[GEOM_OUT_NORMAL]->datatype= NS_OSA_VECTORS; @@ -218,11 +230,11 @@ static void node_shader_exec_geom(void *data, bNode *node, bNodeStack **in, bNod static bNodeType sh_node_geom= { /* type code */ SH_NODE_GEOMETRY, /* name */ "Geometry", - /* width+range */ 90, 40, 100, - /* class+opts */ NODE_CLASS_INPUT, 0, + /* width+range */ 120, 80, 160, + /* class+opts */ NODE_CLASS_INPUT, NODE_OPTIONS, /* input sock */ NULL, /* output sock */ sh_node_geom_out, - /* storage */ "", + /* storage */ "NodeGeometry", /* execfunc */ node_shader_exec_geom }; |