Revision: 23531 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23531 Author: blendix Date: 2009-09-28 16:28:45 +0200 (Mon, 28 Sep 2009)
Log Message: ----------- RNA * Move mesh API functions to mesh_data.c, would like to keep RNA layer fairly thin, any non-trivial functions shoud be in their modules. * Replace mesh.create_copy by generic id.copy. * Fix #19250: Mesh.add_geometry() in editmode fails silently, now gives an error. Modified Paths: -------------- trunk/blender/source/blender/editors/include/ED_mesh.h trunk/blender/source/blender/makesrna/intern/rna_ID.c trunk/blender/source/blender/makesrna/intern/rna_mesh_api.c Added Paths: ----------- trunk/blender/source/blender/editors/mesh/mesh_data.c Removed Paths: ------------- trunk/blender/source/blender/editors/mesh/mesh_layers.c Modified: trunk/blender/source/blender/editors/include/ED_mesh.h =================================================================== --- trunk/blender/source/blender/editors/include/ED_mesh.h 2009-09-28 13:05:03 UTC (rev 23530) +++ trunk/blender/source/blender/editors/include/ED_mesh.h 2009-09-28 14:28:45 UTC (rev 23531) @@ -38,6 +38,7 @@ struct bContext; struct wmOperator; struct wmWindowManager; +struct ReportList; struct EditSelection; struct ViewContext; struct bDeformGroup; @@ -49,6 +50,8 @@ struct UvVertMap; struct UvMapVert; struct CustomData; +struct Material; +struct Object; #define EM_FGON_DRAW 1 // face flag #define EM_FGON 2 // edge and face flag both @@ -89,9 +92,9 @@ void ED_spacetypes_init(void); void ED_keymap_mesh(struct wmWindowManager *wm); -void make_editMesh(struct Scene *scene, Object *ob); -void load_editMesh(struct Scene *scene, Object *ob); -void remake_editMesh(struct Scene *scene, Object *ob); +void make_editMesh(struct Scene *scene, struct Object *ob); +void load_editMesh(struct Scene *scene, struct Object *ob); +void remake_editMesh(struct Scene *scene, struct Object *ob); void free_editMesh(struct EditMesh *em); void recalc_editnormals(struct EditMesh *em); @@ -184,5 +187,18 @@ int editface_containsEdge(struct EditFace *efa, struct EditEdge *eed); short sharesFace(struct EditMesh *em, struct EditEdge *e1, struct EditEdge *e2); +/* mesh_data.c */ + +void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces); +void ED_mesh_transform(struct Mesh *me, float *mat); +void ED_mesh_calc_normals(struct Mesh *me); +void ED_mesh_material_add(struct Mesh *me, struct Material *ma); +void ED_mesh_update(struct Mesh *mesh, struct bContext *C); + +int ED_mesh_uv_texture_add(struct bContext *C, struct Scene *scene, struct Object *ob, struct Mesh *me); +int ED_mesh_uv_texture_remove(struct bContext *C, struct Object *ob, struct Mesh *me); +int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob, struct Mesh *me); +int ED_mesh_color_remove(struct bContext *C, struct Object *ob, struct Mesh *me); + #endif /* ED_MESH_H */ Copied: trunk/blender/source/blender/editors/mesh/mesh_data.c (from rev 23529, trunk/blender/source/blender/editors/mesh/mesh_layers.c) =================================================================== --- trunk/blender/source/blender/editors/mesh/mesh_data.c (rev 0) +++ trunk/blender/source/blender/editors/mesh/mesh_data.c 2009-09-28 14:28:45 UTC (rev 23531) @@ -0,0 +1,667 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <math.h> +#include <stdlib.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_customdata_types.h" +#include "DNA_material_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_windowmanager_types.h" + +#include "BKE_context.h" +#include "BKE_customdata.h" +#include "BKE_depsgraph.h" +#include "BKE_displist.h" +#include "BKE_global.h" +#include "BKE_material.h" +#include "BKE_mesh.h" +#include "BKE_report.h" + +#include "BLI_arithb.h" +#include "BLI_editVert.h" +#include "BLI_edgehash.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_mesh.h" +#include "ED_object.h" +#include "ED_view3d.h" + +#include "mesh_intern.h" + +static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer) +{ + Mesh *me = ob->data; + CustomData *data= (me->edit_mesh)? &me->edit_mesh->fdata: &me->fdata; + void *actlayerdata, *rndlayerdata, *clonelayerdata, *masklayerdata, *layerdata=layer->data; + int type= layer->type; + int index= CustomData_get_layer_index(data, type); + int i, actindex, rndindex, cloneindex, maskindex; + + /* 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, + (to detect if we're deleting the active layer or not), then use the active + layer data pointer to find where the active layer has ended up. + + this is necassary because the deletion functions only support deleting the active + layer. */ + actlayerdata = data->layers[CustomData_get_active_layer_index(data, type)].data; + rndlayerdata = data->layers[CustomData_get_render_layer_index(data, type)].data; + clonelayerdata = data->layers[CustomData_get_clone_layer_index(data, type)].data; + masklayerdata = data->layers[CustomData_get_mask_layer_index(data, type)].data; + CustomData_set_layer_active(data, type, layer - &data->layers[index]); + + if(me->edit_mesh) { + EM_free_data_layer(me->edit_mesh, data, type); + } + else { + CustomData_free_layer_active(data, type, me->totface); + mesh_update_customdata_pointers(me); + } + + if(!CustomData_has_layer(data, type) && (type == CD_MCOL && (ob->mode & OB_MODE_VERTEX_PAINT))) + ED_object_toggle_modes(C, OB_MODE_VERTEX_PAINT); + + /* reconstruct active layer */ + if (actlayerdata != layerdata) { + /* find index */ + actindex = CustomData_get_layer_index(data, type); + for (i=actindex; i<data->totlayer; i++) { + if (data->layers[i].data == actlayerdata) { + actindex = i - actindex; + break; + } + } + + /* set index */ + CustomData_set_layer_active(data, type, actindex); + } + + if (rndlayerdata != layerdata) { + /* find index */ + rndindex = CustomData_get_layer_index(data, type); + for (i=rndindex; i<data->totlayer; i++) { + if (data->layers[i].data == rndlayerdata) { + rndindex = i - rndindex; + break; + } + } + + /* set index */ + CustomData_set_layer_render(data, type, rndindex); + } + + if (clonelayerdata != layerdata) { + /* find index */ + cloneindex = CustomData_get_layer_index(data, type); + for (i=cloneindex; i<data->totlayer; i++) { + if (data->layers[i].data == clonelayerdata) { + cloneindex = i - cloneindex; + break; + } + } + + /* set index */ + CustomData_set_layer_clone(data, type, cloneindex); + } + + if (masklayerdata != layerdata) { + /* find index */ + maskindex = CustomData_get_layer_index(data, type); + for (i=maskindex; i<data->totlayer; i++) { + if (data->layers[i].data == masklayerdata) { + maskindex = i - maskindex; + break; + } + } + + /* set index */ + CustomData_set_layer_mask(data, type, maskindex); + } +} + +int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me) +{ + EditMesh *em; + MCol *mcol; + int layernum; + + if(me->edit_mesh) { + em= me->edit_mesh; + + layernum= CustomData_number_of_layers(&em->fdata, CD_MCOL); + if(layernum >= MAX_MCOL) + return 0; + + EM_add_data_layer(em, &em->fdata, CD_MCOL); + CustomData_set_layer_active(&em->fdata, CD_MCOL, layernum); + } + else { + layernum= CustomData_number_of_layers(&me->fdata, CD_MCOL); + if(layernum >= MAX_MCOL) + return 0; + + mcol= me->mcol; + + if(me->mcol) + CustomData_add_layer(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface); + else + CustomData_add_layer(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface); + + CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum); + mesh_update_customdata_pointers(me); + + if(!mcol && ob) + shadeMeshMCol(scene, ob, me); + } + + DAG_id_flush_update(&me->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + + return 1; +} + +int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me) +{ + CustomDataLayer *cdl; + int index; + + index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + cdl= (index == -1)? NULL: &me->fdata.layers[index]; + + if(!cdl) + return 0; + + delete_customdata_layer(C, ob, cdl); + DAG_id_flush_update(&me->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + + return 1; +} + +int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me) +{ + EditMesh *em; + MCol *mcol; + int layernum; + + if(me->edit_mesh) { + em= me->edit_mesh; + + layernum= CustomData_number_of_layers(&em->fdata, CD_MCOL); + if(layernum >= MAX_MCOL) + return 0; + + EM_add_data_layer(em, &em->fdata, CD_MCOL); + CustomData_set_layer_active(&em->fdata, CD_MCOL, layernum); + } + else { + layernum= CustomData_number_of_layers(&me->fdata, CD_MCOL); + if(layernum >= MAX_MCOL) + return 0; + + mcol= me->mcol; + + if(me->mcol) + CustomData_add_layer(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface); + else + CustomData_add_layer(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface); + + CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum); + mesh_update_customdata_pointers(me); + + if(!mcol) + shadeMeshMCol(scene, ob, me); + } + + DAG_id_flush_update(&me->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + + return 1; +} + +int ED_mesh_color_remove(bContext *C, Object *ob, Mesh *me) +{ + CustomDataLayer *cdl; + int index; + + index= CustomData_get_active_layer_index(&me->fdata, CD_MCOL); + cdl= (index == -1)? NULL: &me->fdata.layers[index]; + + if(!cdl) + return 0; + + delete_customdata_layer(C, ob, cdl); + DAG_id_flush_update(&me->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); + + return 1; +} + +/*********************** UV texture operators ************************/ + +static int layers_poll(bContext *C) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + ID *data= (ob)? ob->data: NULL; + return (ob && !ob->id.lib && ob->type==OB_MESH && data && !data->lib); +} + +static int uv_texture_add_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs