diff options
author | Ben Batt <benbatt@gmail.com> | 2007-01-29 18:10:55 +0300 |
---|---|---|
committer | Ben Batt <benbatt@gmail.com> | 2007-01-29 18:10:55 +0300 |
commit | 2a47217cba4123da38d47278a5f52c38080e926e (patch) | |
tree | 0127a1a0fd21fefacddee4a72e8f722759dd6255 /source/blender/blenkernel | |
parent | 2d361fca0d0ee4ec085459286e75257f6c2f8c9c (diff) |
= Updating the UVProject modifier to handle multiple UV layers =
* Removed the "Add UVs" option from the UVProject modifier
* Added a UV layer menu to the UVProject modifier
* Refactored the Displace modifier UV layer menu code to allow the UVProject
modifier to share it
* Added two CustomData functions to facilitate getting layers by name
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 | 29 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 70 |
3 files changed, 68 insertions, 35 deletions
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index b0fe1ebde5d..ecefb6dde47 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -113,6 +113,8 @@ int CustomData_number_of_layers(const struct CustomData *data, int type); /* duplicate data of a layer with flag NOFREE, and remove that flag. * returns the layer data */ void *CustomData_duplicate_referenced_layer(struct CustomData *data, int type); +void *CustomData_duplicate_referenced_layer_named(struct CustomData *data, + int type, char *name); /* set the CD_FLAG_NOCOPY flag in custom data layers where the mask is * zero for the layer type, so only layer types specified by the mask @@ -176,6 +178,8 @@ void *CustomData_em_get_n(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); +void *CustomData_get_layer_named(const struct CustomData *data, int type, + char *name); int CustomData_get_layer_index(const struct CustomData *data, int type); int CustomData_get_named_layer_index(const struct CustomData *data, int type, char *name); diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index e8964ddeaf9..033c1b26471 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -741,6 +741,26 @@ void *CustomData_duplicate_referenced_layer(struct CustomData *data, int type) return layer->data; } +void *CustomData_duplicate_referenced_layer_named(struct CustomData *data, + int type, char *name) +{ + CustomDataLayer *layer; + int layer_index; + + /* get the layer index of the desired layer */ + layer_index = CustomData_get_named_layer_index(data, type, name); + if(layer_index < 0) return NULL; + + layer = &data->layers[layer_index]; + + if (layer->flag & CD_FLAG_NOFREE) { + layer->data = MEM_dupallocN(layer->data); + layer->flag &= ~CD_FLAG_NOFREE; + } + + return layer->data; +} + void CustomData_free_temporary(CustomData *data, int totelem) { CustomDataLayer *layer; @@ -953,6 +973,15 @@ void *CustomData_get_layer_n(const CustomData *data, int type, int n) return data->layers[layer_index+n].data; } +void *CustomData_get_layer_named(const struct CustomData *data, int type, + char *name) +{ + int layer_index = CustomData_get_named_layer_index(data, type, name); + if(layer_index < 0) return NULL; + + return data->layers[layer_index].data; +} + void *CustomData_set_layer(const CustomData *data, int type, void *ptr) { /* get the layer index of the first layer of type */ diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 7eb3a141513..4894a238634 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -2279,6 +2279,23 @@ static void displaceModifier_updateDepgraph( } } +static void validate_layer_name(const CustomData *data, int type, char *name) +{ + int index = -1; + + /* if a layer name was given, try to find that layer */ + if(name[0]) + index = CustomData_get_named_layer_index(data, CD_MTFACE, name); + + if(index < 0) { + /* either no layer was specified, or the layer we want has been + * deleted, so assign the active layer to name + */ + index = CustomData_get_active_layer_index(data, CD_MTFACE); + strcpy(name, data->layers[index].name); + } +} + static void get_texture_coords(DisplaceModifierData *dmd, Object *ob, DerivedMesh *dm, float (*co)[3], float (*texco)[3], @@ -2301,27 +2318,14 @@ static void get_texture_coords(DisplaceModifierData *dmd, Object *ob, MFace *mf; char *done = MEM_callocN(sizeof(*done) * numVerts, "get_texture_coords done"); - MTFace *tf = NULL; - int numFaces = dm->getNumFaces(dm), itf; - - if (dmd->uvlayer_name[0]) { - itf = CustomData_get_named_layer_index(&dm->faceData, CD_MTFACE, dmd->uvlayer_name); - if (itf != -1) - tf = dm->faceData.layers[itf].data; - else { - /*looks like the layer we want has been deleted, so assign the - first layer to dmd.*/ - itf = CustomData_get_active_layer_index(&dm->faceData, CD_MTFACE); - tf = dm->faceData.layers[itf].data; - strcpy(dmd->uvlayer_name, dm->faceData.layers[itf].name); - } - } else { - /* no uv layer specified, use the active one */ - itf = CustomData_get_active_layer_index(&dm->faceData, CD_MTFACE); - tf = dm->faceData.layers[itf].data; - strcpy(dmd->uvlayer_name, dm->faceData.layers[itf].name); - } - + int numFaces = dm->getNumFaces(dm); + MTFace *tf; + + validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name); + + tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, + dmd->uvlayer_name); + /* verts are given the UV from the first face that uses them */ for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) { if(!done[mf->v1]) { @@ -2531,7 +2535,7 @@ static void uvprojectModifier_initData(ModifierData *md) for(i = 0; i < MOD_UVPROJECT_MAXPROJECTORS; ++i) umd->projectors[i] = NULL; umd->image = NULL; - umd->flags = MOD_UVPROJECT_ADDUVS; + umd->flags = 0; umd->num_projectors = 1; umd->aspectx = umd->aspecty = 1.0f; } @@ -2624,22 +2628,18 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, if(umd->projectors[i]) projectors[num_projectors++].ob = umd->projectors[i]; - tface = dm->getFaceDataArray(dm, CD_MTFACE); - if(num_projectors == 0) return dm; - if(!tface) { - if(!(umd->flags & MOD_UVPROJECT_ADDUVS)) return dm; + /* make sure there are UV layers available */ + if(!dm->getFaceDataArray(dm, CD_MTFACE)) return dm; - DM_add_face_layer(dm, CD_MTFACE, CD_CALLOC, NULL); - tface = dm->getFaceDataArray(dm, CD_MTFACE); - new_tfaces = 1; - } - else { - /* make sure we are not modifying the original layer */ - CustomData_duplicate_referenced_layer(&dm->faceData, CD_MTFACE); - tface = dm->getFaceDataArray(dm, CD_MTFACE); - } + /* make sure we're using an existing layer */ + validate_layer_name(&dm->faceData, CD_MTFACE, umd->uvlayer_name); + + /* make sure we are not modifying the original UV layer */ + tface = CustomData_duplicate_referenced_layer_named(&dm->faceData, + CD_MTFACE, + umd->uvlayer_name); numVerts = dm->getNumVerts(dm); |