Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/modules/bpy_types.py25
-rw-r--r--source/blender/editors/include/ED_mesh.h2
-rw-r--r--source/blender/editors/mesh/mesh_data.c109
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c25
4 files changed, 133 insertions, 28 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 101416f4943..e80c913a865 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -330,7 +330,8 @@ class Mesh(bpy_types.ID):
"""
self.vertices.add(len(vertices))
self.edges.add(len(edges))
- self.faces.add(len(faces))
+ self.loops.add(sum((len(f) for f in faces)))
+ self.polygons.add(len(faces))
vertices_flat = [f for v in vertices for f in v]
self.vertices.foreach_set("co", vertices_flat)
@@ -340,19 +341,15 @@ class Mesh(bpy_types.ID):
self.edges.foreach_set("vertices", edges_flat)
del edges_flat
- def treat_face(f):
- if len(f) == 3:
- if f[2] == 0:
- return f[2], f[0], f[1], 0
- else:
- return f[0], f[1], f[2], 0
- elif f[2] == 0 or f[3] == 0:
- return f[2], f[3], f[0], f[1]
- return f
-
- faces_flat = [v for f in faces for v in treat_face(f)]
- self.faces.foreach_set("vertices_raw", faces_flat)
- del faces_flat
+ # this is different in bmesh
+ loop_index = 0
+ for i, p in enumerate(self.polygons):
+ f = faces[i]
+ loop_len = len(f)
+ p.loop_start = loop_index
+ p.loop_total = loop_len
+ p.vertices = f
+ loop_index += loop_len
@property
def edge_keys(self):
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 2e11711637a..d889e4cb272 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -280,8 +280,10 @@ struct BMFace *EDBM_findnearestface(struct ViewContext *vc, int *dist);
/* mesh_data.c */
// void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces);
+void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int count);
void ED_mesh_faces_add(struct Mesh *mesh, struct ReportList *reports, int count);
void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_loops_add(struct Mesh *mesh, struct ReportList *reports, int count);
void ED_mesh_vertices_add(struct Mesh *mesh, struct ReportList *reports, int count);
void ED_mesh_transform(struct Mesh *me, float *mat);
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index a88b678b365..3327654e6b3 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -75,7 +75,6 @@
#include "mesh_intern.h"
#define GET_CD_DATA(me, data) (me->edit_btmesh ? &me->edit_btmesh->bm->data : &me->data)
-
static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer)
{
Mesh *me = ob->data;
@@ -99,6 +98,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
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. */
@@ -129,10 +129,12 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
break;
}
}
+
/* set index */
CustomData_set_layer_active(data, type, actindex);
}
+
if (rndlayerdata != layerdata) {
/* find index */
@@ -143,10 +145,12 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
break;
}
}
+
/* set index */
CustomData_set_layer_render(data, type, rndindex);
}
+
if (clonelayerdata != layerdata) {
/* find index */
@@ -157,10 +161,12 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
break;
}
}
+
/* set index */
CustomData_set_layer_clone(data, type, cloneindex);
}
+
if (stencillayerdata != layerdata) {
/* find index */
@@ -171,6 +177,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
break;
}
}
+
/* set index */
CustomData_set_layer_stencil(data, type, stencilindex);
@@ -241,6 +248,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
CustomData_set_layer_active(&me->ldata, CD_MLOOPUV, layernum);
}
+
mesh_update_customdata_pointers(me);
}
@@ -290,13 +298,11 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes
BM_add_data_layer(em->bm, &em->bm->pdata, CD_MLOOPCOL);
CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPCOL, layernum);
-
if(layernum) /* copy data from active vertex color layer */
copy_editface_active_customdata(em, CD_MCOL, layernum);
if(active_set || layernum==0)
CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPCOL, layernum);
-
}
else {
layernum= CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
@@ -366,6 +372,7 @@ void MESH_OT_uv_texture_add(wmOperatorType *ot)
ot->name= "Add UV Texture";
ot->description= "Add UV texture layer";
ot->idname= "MESH_OT_uv_texture_add";
+
/* api callbacks */
ot->poll= layers_poll;
@@ -385,16 +392,19 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
Object *obedit;
int exitmode= 0;
char name[32];
+
/* Check context */
if(base==NULL || base->object->type!=OB_MESH) {
BKE_report(op->reports, RPT_ERROR, "Not an Object or Mesh");
return OPERATOR_CANCELLED;
}
+
/* check input variables */
if(RNA_property_is_set(op->ptr, "filepath")) {
char path[FILE_MAX];
+
RNA_string_get(op->ptr, "filepath", path);
ima= BKE_add_image_file(path);
@@ -403,11 +413,13 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
RNA_string_get(op->ptr, "name", name);
ima= (Image *)find_id("IM", name);
}
+
if(!ima) {
BKE_report(op->reports, RPT_ERROR, "Not an Image.");
return OPERATOR_CANCELLED;
}
+
/* put mesh in editmode */
@@ -417,9 +429,9 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
EDBM_MakeEditBMesh(scene->toolsettings, scene, obedit);
exitmode= 1;
}
-
if(me->edit_btmesh==NULL)
return OPERATOR_CANCELLED;
+
ED_uvedit_assign_image(scene, obedit, ima, NULL);
@@ -433,8 +445,10 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
/* dummie drop support; ensure view shows a result :) */
if(v3d)
v3d->flag2 |= V3D_SOLID_TEX;
+
WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
return OPERATOR_FINISHED;
}
@@ -445,13 +459,16 @@ void MESH_OT_drop_named_image(wmOperatorType *ot)
ot->name= "Assign Image to UV Texture";
ot->description= "Assigns Image to active UV layer, or creates a UV layer";
ot->idname= "MESH_OT_drop_named_image";
+
/* api callbacks */
ot->poll= layers_poll;
ot->invoke= drop_named_image_invoke;
+
/* flags */
ot->flag= OPTYPE_UNDO;
+
/* properties */
RNA_def_string(ot->srna, "name", "Image", 24, "Name", "Image name to assign.");
@@ -475,6 +492,7 @@ void MESH_OT_uv_texture_remove(wmOperatorType *ot)
ot->name= "Remove UV Texture";
ot->description= "Remove UV texture layer";
ot->idname= "MESH_OT_uv_texture_remove";
+
/* api callbacks */
ot->poll= layers_poll;
@@ -504,6 +522,7 @@ void MESH_OT_vertex_color_add(wmOperatorType *ot)
ot->name= "Add Vertex Color";
ot->description= "Add vertex color layer";
ot->idname= "MESH_OT_vertex_color_add";
+
/* api callbacks */
ot->poll= layers_poll;
@@ -530,6 +549,7 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot)
ot->name= "Remove Vertex Color";
ot->description= "Remove vertex color layer";
ot->idname= "MESH_OT_vertex_color_remove";
+
/* api callbacks */
ot->exec= vertex_color_remove_exec;
@@ -565,6 +585,7 @@ void MESH_OT_sticky_add(wmOperatorType *ot)
ot->name= "Add Sticky";
ot->description= "Add sticky UV texture layer";
ot->idname= "MESH_OT_sticky_add";
+
/* api callbacks */
ot->poll= layers_poll;
@@ -597,6 +618,7 @@ void MESH_OT_sticky_remove(wmOperatorType *ot)
ot->name= "Remove Sticky";
ot->description= "Remove sticky UV texture layer";
ot->idname= "MESH_OT_sticky_remove";
+
/* api callbacks */
ot->poll= layers_poll;
@@ -693,6 +715,8 @@ static void mesh_add_edges(Mesh *mesh, int len)
mesh->totedge= totedge;
}
+
+
static void mesh_add_faces(Mesh *mesh, int len)
{
CustomData fdata;
@@ -723,6 +747,61 @@ static void mesh_add_faces(Mesh *mesh, int len)
mesh->totface= totface;
}
+static void mesh_add_loops(Mesh *mesh, int len)
+{
+ CustomData ldata;
+ MLoop *mloop;
+ int i, totloop;
+
+ if(len == 0)
+ return;
+
+ totloop= mesh->totloop + len; /* new face count */
+
+ /* update customdata */
+ CustomData_copy(&mesh->ldata, &ldata, CD_MASK_MESH, CD_DEFAULT, totloop);
+ CustomData_copy_data(&mesh->ldata, &ldata, 0, 0, mesh->totloop);
+
+ if(!CustomData_has_layer(&ldata, CD_MLOOP))
+ CustomData_add_layer(&ldata, CD_MLOOP, CD_CALLOC, NULL, totloop);
+
+ CustomData_free(&mesh->ldata, mesh->totloop);
+ mesh->ldata= ldata;
+ mesh_update_customdata_pointers(mesh);
+
+ mesh->totloop= totloop;
+}
+
+static void mesh_add_polys(Mesh *mesh, int len)
+{
+ CustomData pdata;
+ MPoly *mpoly;
+ int i, totpoly;
+
+ if(len == 0)
+ return;
+
+ totpoly= mesh->totpoly + len; /* new face count */
+
+ /* update customdata */
+ CustomData_copy(&mesh->pdata, &pdata, CD_MASK_MESH, CD_DEFAULT, totpoly);
+ CustomData_copy_data(&mesh->pdata, &pdata, 0, 0, mesh->totpoly);
+
+ if(!CustomData_has_layer(&pdata, CD_MPOLY))
+ CustomData_add_layer(&pdata, CD_MPOLY, CD_CALLOC, NULL, totpoly);
+
+ CustomData_free(&mesh->pdata, mesh->totpoly);
+ mesh->pdata= pdata;
+ mesh_update_customdata_pointers(mesh);
+
+ /* set default flags */
+ mpoly= &mesh->mpoly[mesh->totpoly];
+ for(i=0; i<len; i++, mpoly++)
+ mpoly->flag= ME_FACE_SEL;
+
+ mesh->totpoly= totpoly;
+}
+
/*
void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces)
{
@@ -746,6 +825,7 @@ void ED_mesh_faces_add(Mesh *mesh, ReportList *reports, int count)
BKE_report(reports, RPT_ERROR, "Can't add faces in edit mode.");
return;
}
+
mesh_add_faces(mesh, count);
}
@@ -759,6 +839,7 @@ void ED_mesh_edges_add(Mesh *mesh, ReportList *reports, int count)
mesh_add_edges(mesh, count);
}
+
void ED_mesh_vertices_add(Mesh *mesh, ReportList *reports, int count)
{
if(mesh->edit_btmesh) {
@@ -769,6 +850,26 @@ void ED_mesh_vertices_add(Mesh *mesh, ReportList *reports, int count)
mesh_add_verts(mesh, count);
}
+void ED_mesh_loops_add(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_btmesh) {
+ BKE_report(reports, RPT_ERROR, "Can't add loops in edit mode.");
+ return;
+ }
+
+ mesh_add_loops(mesh, count);
+}
+
+void ED_mesh_polys_add(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_btmesh) {
+ BKE_report(reports, RPT_ERROR, "Can't add polys in edit mode.");
+ return;
+ }
+
+ mesh_add_polys(mesh, count);
+}
+
void ED_mesh_calc_normals(Mesh *mesh)
{
mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 00440626ce3..7d6fcd1d006 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1345,6 +1345,15 @@ static void rna_def_mpolygon(BlenderRNA *brna)
RNA_def_property_int_funcs(prop, "rna_MeshPoly_vertices_get", "rna_MeshPoly_vertices_set", NULL);
RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
+ /* these are both very low level access */
+ prop= RNA_def_property(srna, "loop_start", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "loopstart");
+ RNA_def_property_ui_text(prop, "Loop Start", "");
+ /* also low level */
+ prop= RNA_def_property(srna, "loop_total", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "totloop");
+ RNA_def_property_ui_text(prop, "Loop Total", "");
+
prop= RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "mat_nr");
RNA_def_property_ui_text(prop, "Material Index", "");
@@ -1785,12 +1794,10 @@ static void rna_def_mesh_loops(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
-#if 0 // BMESH_TODO
PropertyRNA *prop;
FunctionRNA *func;
- PropertyRNA *parm;
-#endif
+// PropertyRNA *parm;
RNA_def_property_srna(cprop, "MeshLoops");
srna= RNA_def_struct(brna, "MeshLoops", NULL);
@@ -1801,11 +1808,11 @@ static void rna_def_mesh_loops(BlenderRNA *brna, PropertyRNA *cprop)
prop= RNA_def_property(srna, "active", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "act_face");
RNA_def_property_ui_text(prop, "Active Polygon", "The active polygon for this mesh");
+#endif
- func= RNA_def_function(srna, "add", "ED_mesh_polys_add");
+ func= RNA_def_function(srna, "add", "ED_mesh_loops_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
- parm= RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of polygons to add.", 0, INT_MAX);
-#endif
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of loops to add.", 0, INT_MAX);
}
/* mesh.polygons */
@@ -1813,12 +1820,10 @@ static void rna_def_mesh_polygons(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
-#if 0 // BMESH_TODO
- PropertyRNA *prop;
+// PropertyRNA *prop;
FunctionRNA *func;
PropertyRNA *parm;
-#endif
RNA_def_property_srna(cprop, "MeshPolygons");
srna= RNA_def_struct(brna, "MeshPolygons", NULL);
@@ -1829,11 +1834,11 @@ static void rna_def_mesh_polygons(BlenderRNA *brna, PropertyRNA *cprop)
prop= RNA_def_property(srna, "active", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "act_face");
RNA_def_property_ui_text(prop, "Active Polygon", "The active polygon for this mesh");
+#endif
func= RNA_def_function(srna, "add", "ED_mesh_polys_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
parm= RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of polygons to add.", 0, INT_MAX);
-#endif
}