From b5f820cd874a7b3ca1de81103b99969429adfd6c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 12 Oct 2009 19:34:58 +0000 Subject: added rna api MVert,MFace & MEdge index properties eg. for v in me.verts: print(v.index) added calc_edges as an option eg. mesh.update(calc_edges=True) This is needed when adding faces to an existing mesh which create new edges. --- source/blender/editors/include/ED_mesh.h | 2 +- source/blender/editors/mesh/mesh_data.c | 4 +-- source/blender/makesrna/intern/rna_mesh.c | 36 +++++++++++++++++++++++++++ source/blender/makesrna/intern/rna_mesh_api.c | 1 + source/blender/python/intern/bpy_interface.c | 3 +++ 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 3bceeb9340e..144d29a4405 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -195,7 +195,7 @@ void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int ver 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); +void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges); 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); diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 43e1dd417a6..6ed2ca08c9c 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -504,9 +504,9 @@ static void mesh_calc_edges(Mesh *mesh) BLI_edgehash_free(eh, NULL); } -void ED_mesh_update(Mesh *mesh, bContext *C) +void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges) { - if(mesh->totface && mesh->totedge == 0) + if(calc_edges || (mesh->totface && mesh->totedge == 0)) mesh_calc_edges(mesh); mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL); diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 84a1940de9d..8b67ccecc3d 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -732,6 +732,27 @@ static void rna_MeshFace_verts_set(PointerRNA *ptr, const int *values) memcpy(&face->v1, values, (face->v4 ? 4 : 3) * sizeof(int)); } +static int rna_MeshVertex_index_get(PointerRNA *ptr) +{ + Mesh *me= (Mesh*)ptr->id.data; + MVert *vert= (MVert*)ptr->data; + return (int)(vert - me->mvert); +} + +static int rna_MeshEdge_index_get(PointerRNA *ptr) +{ + Mesh *me= (Mesh*)ptr->id.data; + MEdge *edge= (MEdge*)ptr->data; + return (int)(edge - me->medge); +} + +static int rna_MeshFace_index_get(PointerRNA *ptr) +{ + Mesh *me= (Mesh*)ptr->id.data; + MFace *face= (MFace*)ptr->data; + return (int)(face - me->mface); +} + /* path construction */ static char *rna_VertexGroupElement_path(PointerRNA *ptr) @@ -905,6 +926,11 @@ static void rna_def_mvert(BlenderRNA *brna) RNA_def_property_collection_funcs(prop, "rna_MeshVertex_groups_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0, 0); RNA_def_property_struct_type(prop, "VertexGroupElement"); RNA_def_property_ui_text(prop, "Groups", "Weights for the vertex groups this vertex is member of."); + + prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_int_funcs(prop, "rna_MeshVertex_index_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Index", "Index number of the vertex."); } static void rna_def_medge(BlenderRNA *brna) @@ -963,6 +989,11 @@ static void rna_def_medge(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_FGON); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Fgon", "Fgon edge"); + + prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_int_funcs(prop, "rna_MeshEdge_index_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Index", "Index number of the vertex."); } static void rna_def_mface(BlenderRNA *brna) @@ -1017,6 +1048,11 @@ static void rna_def_mface(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_float_funcs(prop, "rna_MeshFace_normal_get", NULL, NULL); RNA_def_property_ui_text(prop, "face normal", "local space unit length normal vector for this face"); + + prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_int_funcs(prop, "rna_MeshFace_index_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Index", "Index number of the vertex."); } static void rna_def_mtface(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index 3da0e1e6fd4..52ff98f66f0 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -72,6 +72,7 @@ void RNA_api_mesh(StructRNA *srna) RNA_def_function_ui_description(func, "Calculate vertex normals."); func= RNA_def_function(srna, "update", "ED_mesh_update"); + RNA_def_boolean(func, "calc_edges", 0, "Calculate Edges", "Force recalculation of edges."); RNA_def_function_flag(func, FUNC_USE_CONTEXT); func= RNA_def_function(srna, "add_material", "ED_mesh_material_add"); diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index d0829acd6cc..9e76c1d03aa 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -241,6 +241,9 @@ static PyObject *CreateGlobalDictionary( bContext *C ) {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""}, {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""}, {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {"EnumProperty", (PyCFunction)BPy_EnumProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {"PointerProperty", (PyCFunction)BPy_PointerProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {"CollectionProperty", (PyCFunction)BPy_CollectionProperty, METH_VARARGS|METH_KEYWORDS, ""}, {NULL, NULL, 0, NULL} }; -- cgit v1.2.3