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.
This commit is contained in:
2009-10-12 19:34:58 +00:00
parent 0696cf23e5
commit b5f820cd87
5 changed files with 43 additions and 3 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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)

View File

@@ -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");

View File

@@ -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}
};