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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-09-28 18:28:45 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-09-28 18:28:45 +0400
commit8563115e8c18e1e2b5db5de21520a0c780c5b164 (patch)
treec3942457c05c86f48ec0d95e56734160527090e0
parent18e54b1ee85407d54e8f9d1942c323616cbe0beb (diff)
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.
-rw-r--r--source/blender/editors/include/ED_mesh.h22
-rw-r--r--source/blender/editors/mesh/mesh_data.c (renamed from source/blender/editors/mesh/mesh_layers.c)410
-rw-r--r--source/blender/makesrna/intern/rna_ID.c21
-rw-r--r--source/blender/makesrna/intern/rna_mesh_api.c263
4 files changed, 385 insertions, 331 deletions
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 634a3bc278b..fd88f9889ae 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -38,6 +38,7 @@ struct EditFace;
struct bContext;
struct wmOperator;
struct wmWindowManager;
+struct ReportList;
struct EditSelection;
struct ViewContext;
struct bDeformGroup;
@@ -49,6 +50,8 @@ struct MCol;
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_keymap_mesh(struct wmWindowManager *wm);
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_containsVert(struct EditFace *efa, struct EditVert *eve);
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 */
diff --git a/source/blender/editors/mesh/mesh_layers.c b/source/blender/editors/mesh/mesh_data.c
index a36c7a56b7c..4d2e5d357f1 100644
--- a/source/blender/editors/mesh/mesh_layers.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -26,12 +26,14 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#include <stdlib.h>
#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"
@@ -43,9 +45,13 @@
#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"
@@ -150,49 +156,142 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
}
}
-/*********************** UV texture operators ************************/
+int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
+{
+ EditMesh *em;
+ MCol *mcol;
+ int layernum;
-static int layers_poll(bContext *C)
+ 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)
{
- 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);
+ 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;
}
-static int uv_texture_add_exec(bContext *C, wmOperator *op)
+int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
{
- Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
- Mesh *me= ob->data;
EditMesh *em;
+ MCol *mcol;
int layernum;
if(me->edit_mesh) {
em= me->edit_mesh;
- layernum= CustomData_number_of_layers(&em->fdata, CD_MTFACE);
- if(layernum >= MAX_MTFACE)
- return OPERATOR_CANCELLED;
+ layernum= CustomData_number_of_layers(&em->fdata, CD_MCOL);
+ if(layernum >= MAX_MCOL)
+ return 0;
- EM_add_data_layer(em, &em->fdata, CD_MTFACE);
- CustomData_set_layer_active(&em->fdata, CD_MTFACE, layernum);
+ 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_MTFACE);
- if(layernum >= MAX_MTFACE)
- return OPERATOR_CANCELLED;
+ layernum= CustomData_number_of_layers(&me->fdata, CD_MCOL);
+ if(layernum >= MAX_MCOL)
+ return 0;
+
+ mcol= me->mcol;
- if(me->mtface)
- CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface);
+ if(me->mcol)
+ CustomData_add_layer(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface);
else
- CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface);
+ CustomData_add_layer(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface);
- CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum);
+ 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);
+ Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+ Mesh *me= ob->data;
+
+ if(!ED_mesh_uv_texture_add(C, scene, ob, me))
+ return OPERATOR_CANCELLED;
+
return OPERATOR_FINISHED;
}
@@ -215,20 +314,10 @@ static int uv_texture_remove_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Mesh *me= ob->data;
- CustomDataLayer *cdl;
- int index;
-
- index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
- cdl= (index == -1)? NULL: &me->fdata.layers[index];
- if(!cdl)
+ if(!ED_mesh_uv_texture_remove(C, ob, me))
return OPERATOR_CANCELLED;
- 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 OPERATOR_FINISHED;
}
@@ -254,41 +343,9 @@ static int vertex_color_add_exec(bContext *C, wmOperator *op)
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Mesh *me= ob->data;
- 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 OPERATOR_CANCELLED;
-
- 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 OPERATOR_CANCELLED;
-
- 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);
+ if(!ED_mesh_color_add(C, scene, ob, me))
+ return OPERATOR_CANCELLED;
return OPERATOR_FINISHED;
}
@@ -312,20 +369,10 @@ static int vertex_color_remove_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Mesh *me= ob->data;
- CustomDataLayer *cdl;
- int index;
- index= CustomData_get_active_layer_index(&me->fdata, CD_MCOL);
- cdl= (index == -1)? NULL: &me->fdata.layers[index];
-
- if(!cdl)
+ if(!ED_mesh_color_remove(C, ob, me))
return OPERATOR_CANCELLED;
- 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 OPERATOR_FINISHED;
}
@@ -409,3 +456,212 @@ void MESH_OT_sticky_remove(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+/************************** Add Geometry Layers *************************/
+
+static void mesh_calc_edges(Mesh *mesh)
+{
+ CustomData edata;
+ EdgeHashIterator *ehi;
+ MFace *mf = mesh->mface;
+ MEdge *med;
+ EdgeHash *eh = BLI_edgehash_new();
+ int i, *index, totedge, totface = mesh->totface;
+
+ for (i = 0; i < totface; i++, mf++) {
+ if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2))
+ BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL);
+ if (!BLI_edgehash_haskey(eh, mf->v2, mf->v3))
+ BLI_edgehash_insert(eh, mf->v2, mf->v3, NULL);
+
+ if (mf->v4) {
+ if (!BLI_edgehash_haskey(eh, mf->v3, mf->v4))
+ BLI_edgehash_insert(eh, mf->v3, mf->v4, NULL);
+ if (!BLI_edgehash_haskey(eh, mf->v4, mf->v1))
+ BLI_edgehash_insert(eh, mf->v4, mf->v1, NULL);
+ } else {
+ if (!BLI_edgehash_haskey(eh, mf->v3, mf->v1))
+ BLI_edgehash_insert(eh, mf->v3, mf->v1, NULL);
+ }
+ }
+
+ totedge = BLI_edgehash_size(eh);
+
+ /* write new edges into a temporary CustomData */
+ memset(&edata, 0, sizeof(edata));
+ CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge);
+
+ ehi = BLI_edgehashIterator_new(eh);
+ med = CustomData_get_layer(&edata, CD_MEDGE);
+ for(i = 0; !BLI_edgehashIterator_isDone(ehi);
+ BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
+ BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
+
+ med->flag = ME_EDGEDRAW|ME_EDGERENDER;
+ }
+ BLI_edgehashIterator_free(ehi);
+
+ /* free old CustomData and assign new one */
+ CustomData_free(&mesh->edata, mesh->totedge);
+ mesh->edata = edata;
+ mesh->totedge = totedge;
+
+ mesh->medge = CustomData_get_layer(&mesh->edata, CD_MEDGE);
+
+ BLI_edgehash_free(eh, NULL);
+}
+
+void ED_mesh_update(Mesh *mesh, bContext *C)
+{
+ if(mesh->totface && mesh->totedge == 0)
+ mesh_calc_edges(mesh);
+
+ mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL);
+
+ DAG_id_flush_update(&mesh->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, mesh);
+}
+
+static void mesh_add_verts(Mesh *mesh, int len)
+{
+ CustomData vdata;
+ MVert *mvert;
+ int i, totvert;
+
+ if(len == 0)
+ return;
+
+ totvert= mesh->totvert + len;
+ CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, totvert);
+ CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert);
+
+ if(!CustomData_has_layer(&vdata, CD_MVERT))
+ CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert);
+
+ CustomData_free(&mesh->vdata, mesh->totvert);
+ mesh->vdata= vdata;
+ mesh_update_customdata_pointers(mesh);
+
+ /* scan the input list and insert the new vertices */
+
+ mvert= &mesh->mvert[mesh->totvert];
+ for(i=0; i<len; i++, mvert++)
+ mvert->flag |= SELECT;
+
+ /* set final vertex list size */
+ mesh->totvert= totvert;
+}
+
+void ED_mesh_transform(Mesh *me, float *mat)
+{
+ int i;
+ MVert *mvert= me->mvert;
+
+ for(i= 0; i < me->totvert; i++, mvert++)
+ Mat4MulVecfl((float (*)[4])mat, mvert->co);
+
+ mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+}
+
+static void mesh_add_edges(Mesh *mesh, int len)
+{
+ CustomData edata;
+ MEdge *medge;
+ int i, totedge;
+
+ if(len == 0)
+ return;
+
+ totedge= mesh->totedge+len;
+
+ /* update customdata */
+ CustomData_copy(&mesh->edata, &edata, CD_MASK_MESH, CD_DEFAULT, totedge);
+ CustomData_copy_data(&mesh->edata, &edata, 0, 0, mesh->totedge);
+
+ if(!CustomData_has_layer(&edata, CD_MEDGE))
+ CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge);
+
+ CustomData_free(&mesh->edata, mesh->totedge);
+ mesh->edata= edata;
+ mesh_update_customdata_pointers(mesh);
+
+ /* set default flags */
+ medge= &mesh->medge[mesh->totedge];
+ for(i=0; i<len; i++, medge++)
+ medge->flag= ME_EDGEDRAW|ME_EDGERENDER|SELECT;
+
+ mesh->totedge= totedge;
+}
+
+static void mesh_add_faces(Mesh *mesh, int len)
+{
+ CustomData fdata;
+ MFace *mface;
+ int i, totface;
+
+ if(len == 0)
+ return;
+
+ totface= mesh->totface + len; /* new face count */
+
+ /* update customdata */
+ CustomData_copy(&mesh->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface);
+ CustomData_copy_data(&mesh->fdata, &fdata, 0, 0, mesh->totface);
+
+ if(!CustomData_has_layer(&fdata, CD_MFACE))
+ CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface);
+
+ CustomData_free(&mesh->fdata, mesh->totface);
+ mesh->fdata= fdata;
+ mesh_update_customdata_pointers(mesh);
+
+ /* set default flags */
+ mface= &mesh->mface[mesh->totface];
+ for(i=0; i<len; i++, mface++)
+ mface->flag= SELECT;
+
+ mesh->totface= totface;
+}
+
+void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't add geometry in edit mode.");
+ return;
+ }
+
+ if(verts)
+ mesh_add_verts(mesh, verts);
+ if(edges)
+ mesh_add_edges(mesh, edges);
+ if(faces)
+ mesh_add_faces(mesh, faces);
+}
+
+void ED_mesh_calc_normals(Mesh *me)
+{
+ mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+}
+
+void ED_mesh_material_add(Mesh *me, Material *ma)
+{
+ int i;
+ int totcol = me->totcol + 1;
+ Material **mat;
+
+ /* don't add if mesh already has it */
+ for(i = 0; i < me->totcol; i++)
+ if(me->mat[i] == ma)
+ return;
+
+ mat= MEM_callocN(sizeof(void*)*totcol, "newmatar");
+
+ if(me->totcol) memcpy(mat, me->mat, sizeof(void*) * me->totcol);
+ if(me->mat) MEM_freeN(me->mat);
+
+ me->mat = mat;
+ me->mat[me->totcol++] = ma;
+ ma->id.us++;
+
+ test_object_materials((ID*)me);
+}
+
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index f5c6063e892..8ab5a1442c7 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -178,6 +178,18 @@ StructRNA* rna_IDPropertyGroup_refine(PointerRNA *ptr)
return ptr->type;
}
+ID *rna_ID_copy(ID *id)
+{
+ ID *newid;
+
+ if(id_copy(id, &newid, 0)) {
+ if(newid) newid->us--;
+ return newid;
+ }
+
+ return NULL;
+}
+
#else
static void rna_def_ID_properties(BlenderRNA *brna)
@@ -243,7 +255,8 @@ static void rna_def_ID_properties(BlenderRNA *brna)
static void rna_def_ID(BlenderRNA *brna)
{
StructRNA *srna;
- PropertyRNA *prop;
+ FunctionRNA *func;
+ PropertyRNA *prop, *parm;
srna= RNA_def_struct(brna, "ID", NULL);
RNA_def_struct_ui_text(srna, "ID", "Base type for datablocks, defining a unique name, linking from other libraries and garbage collection.");
@@ -271,6 +284,12 @@ static void rna_def_ID(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "lib");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Library", "Library file the datablock is linked from.");
+
+ /* functions */
+ func= RNA_def_function(srna, "copy", "rna_ID_copy");
+ RNA_def_function_ui_description(func, "Create a copy of this datablock (not supported for all datablocks).");
+ parm= RNA_def_pointer(func, "id", "ID", "", "New copy of the ID.");
+ RNA_def_function_return(func, parm);
}
static void rna_def_library(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index 6e37014a771..3da0e1e6fd4 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -32,249 +32,15 @@
#include "RNA_define.h"
#include "RNA_types.h"
-#ifdef RNA_RUNTIME
-
-#include "DNA_mesh_types.h"
-#include "DNA_scene_types.h"
-
-#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_main.h"
-#include "BKE_mesh.h"
-#include "BKE_material.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_scene_types.h"
-
-#include "BLI_arithb.h"
-#include "BLI_edgehash.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "MEM_guardedalloc.h"
-
-static void rna_Mesh_calc_edges(Mesh *mesh)
-{
- CustomData edata;
- EdgeHashIterator *ehi;
- MFace *mf = mesh->mface;
- MEdge *med;
- EdgeHash *eh = BLI_edgehash_new();
- int i, *index, totedge, totface = mesh->totface;
-
- for (i = 0; i < totface; i++, mf++) {
- if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2))
- BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL);
- if (!BLI_edgehash_haskey(eh, mf->v2, mf->v3))
- BLI_edgehash_insert(eh, mf->v2, mf->v3, NULL);
-
- if (mf->v4) {
- if (!BLI_edgehash_haskey(eh, mf->v3, mf->v4))
- BLI_edgehash_insert(eh, mf->v3, mf->v4, NULL);
- if (!BLI_edgehash_haskey(eh, mf->v4, mf->v1))
- BLI_edgehash_insert(eh, mf->v4, mf->v1, NULL);
- } else {
- if (!BLI_edgehash_haskey(eh, mf->v3, mf->v1))
- BLI_edgehash_insert(eh, mf->v3, mf->v1, NULL);
- }
- }
-
- totedge = BLI_edgehash_size(eh);
-
- /* write new edges into a temporary CustomData */
- memset(&edata, 0, sizeof(edata));
- CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge);
-
- ehi = BLI_edgehashIterator_new(eh);
- med = CustomData_get_layer(&edata, CD_MEDGE);
- for(i = 0; !BLI_edgehashIterator_isDone(ehi);
- BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
- BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
-
- med->flag = ME_EDGEDRAW|ME_EDGERENDER;
- }
- BLI_edgehashIterator_free(ehi);
-
- /* free old CustomData and assign new one */
- CustomData_free(&mesh->edata, mesh->totedge);
- mesh->edata = edata;
- mesh->totedge = totedge;
-
- mesh->medge = CustomData_get_layer(&mesh->edata, CD_MEDGE);
-
- BLI_edgehash_free(eh, NULL);
-}
-
-static void rna_Mesh_update(Mesh *mesh, bContext *C)
-{
- if(mesh->totface && mesh->totedge == 0)
- rna_Mesh_calc_edges(mesh);
+#include "BLO_sys_types.h"
- mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL);
-
- DAG_id_flush_update(&mesh->id, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM|ND_DATA, mesh);
-}
-
-static void rna_Mesh_transform(Mesh *me, float *mat)
-{
-
- /* TODO: old API transform had recalc_normals option */
- int i;
- MVert *mvert= me->mvert;
-
- for(i= 0; i < me->totvert; i++, mvert++) {
- Mat4MulVecfl((float (*)[4])mat, mvert->co);
- }
-}
-
-static void rna_Mesh_add_verts(Mesh *mesh, int len)
-{
- CustomData vdata;
- MVert *mvert;
- int i, totvert;
-
- if(len == 0)
- return;
-
- totvert= mesh->totvert + len;
- CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, totvert);
- CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert);
-
- if(!CustomData_has_layer(&vdata, CD_MVERT))
- CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert);
-
- CustomData_free(&mesh->vdata, mesh->totvert);
- mesh->vdata= vdata;
- mesh_update_customdata_pointers(mesh);
-
- /* scan the input list and insert the new vertices */
-
- mvert= &mesh->mvert[mesh->totvert];
- for(i=0; i<len; i++, mvert++)
- mvert->flag |= SELECT;
-
- /* set final vertex list size */
- mesh->totvert= totvert;
-}
-
-Mesh *rna_Mesh_create_copy(Mesh *me)
-{
- Mesh *ret= copy_mesh(me);
- ret->id.us--;
-
- return ret;
-}
+#include "ED_mesh.h"
-static void rna_Mesh_add_edges(Mesh *mesh, int len)
-{
- CustomData edata;
- MEdge *medge;
- int i, totedge;
-
- if(len == 0)
- return;
-
- totedge= mesh->totedge+len;
-
- /* update customdata */
- CustomData_copy(&mesh->edata, &edata, CD_MASK_MESH, CD_DEFAULT, totedge);
- CustomData_copy_data(&mesh->edata, &edata, 0, 0, mesh->totedge);
-
- if(!CustomData_has_layer(&edata, CD_MEDGE))
- CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge);
-
- CustomData_free(&mesh->edata, mesh->totedge);
- mesh->edata= edata;
- mesh_update_customdata_pointers(mesh);
-
- /* set default flags */
- medge= &mesh->medge[mesh->totedge];
- for(i=0; i<len; i++, medge++)
- medge->flag= ME_EDGEDRAW|ME_EDGERENDER|SELECT;
-
- mesh->totedge= totedge;
-}
-
-static void rna_Mesh_add_faces(Mesh *mesh, int len)
-{
- CustomData fdata;
- MFace *mface;
- int i, totface;
-
- if(len == 0)
- return;
-
- totface= mesh->totface + len; /* new face count */
-
- /* update customdata */
- CustomData_copy(&mesh->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface);
- CustomData_copy_data(&mesh->fdata, &fdata, 0, 0, mesh->totface);
-
- if(!CustomData_has_layer(&fdata, CD_MFACE))
- CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface);
-
- CustomData_free(&mesh->fdata, mesh->totface);
- mesh->fdata= fdata;
- mesh_update_customdata_pointers(mesh);
-
- /* set default flags */
- mface= &mesh->mface[mesh->totface];
- for(i=0; i<len; i++, mface++)
- mface->flag= SELECT;
-
- mesh->totface= totface;
-}
-
-/*
-static void rna_Mesh_add_faces(Mesh *mesh)
-{
-}
-*/
-
-static void rna_Mesh_add_geometry(Mesh *mesh, int verts, int edges, int faces)
-{
- if(verts)
- rna_Mesh_add_verts(mesh, verts);
- if(edges)
- rna_Mesh_add_edges(mesh, edges);
- if(faces)
- rna_Mesh_add_faces(mesh, faces);
-}
-
-static void rna_Mesh_add_uv_texture(Mesh *me)
-{
- me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface);
-}
-
-static void rna_Mesh_calc_normals(Mesh *me)
-{
- mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
-}
+#ifdef RNA_RUNTIME
-static void rna_Mesh_add_material(Mesh *me, Material *ma)
+static void rna_Mesh_uv_texture_add(struct Mesh *me, struct bContext *C)
{
- int i;
- int totcol = me->totcol + 1;
- Material **mat;
-
- /* don't add if mesh already has it */
- for (i = 0; i < me->totcol; i++)
- if (me->mat[i] == ma)
- return;
-
- mat= MEM_callocN(sizeof(void*) * totcol, "newmatar");
-
- if (me->totcol) memcpy(mat, me->mat, sizeof(void*) * me->totcol);
- if (me->mat) MEM_freeN(me->mat);
-
- me->mat = mat;
- me->mat[me->totcol++] = ma;
- ma->id.us++;
-
- test_object_materials((ID*)me);
+ ED_mesh_uv_texture_add(C, NULL, NULL, me);
}
#else
@@ -284,12 +50,13 @@ void RNA_api_mesh(StructRNA *srna)
FunctionRNA *func;
PropertyRNA *parm;
- func= RNA_def_function(srna, "transform", "rna_Mesh_transform");
+ func= RNA_def_function(srna, "transform", "ED_mesh_transform");
RNA_def_function_ui_description(func, "Transform mesh vertices by a matrix.");
parm= RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix.", 0.0f, 0.0f);
RNA_def_property_flag(parm, PROP_REQUIRED);
- func= RNA_def_function(srna, "add_geometry", "rna_Mesh_add_geometry");
+ func= RNA_def_function(srna, "add_geometry", "ED_mesh_geometry_add");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
parm= RNA_def_int(func, "verts", 0, 0, INT_MAX, "Number", "Number of vertices to add.", 0, INT_MAX);
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_int(func, "edges", 0, 0, INT_MAX, "Number", "Number of edges to add.", 0, INT_MAX);
@@ -297,21 +64,17 @@ void RNA_api_mesh(StructRNA *srna)
parm= RNA_def_int(func, "faces", 0, 0, INT_MAX, "Number", "Number of faces to add.", 0, INT_MAX);
RNA_def_property_flag(parm, PROP_REQUIRED);
- func= RNA_def_function(srna, "create_copy", "rna_Mesh_create_copy");
- RNA_def_function_ui_description(func, "Create a copy of this Mesh datablock.");
- parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh, remove it if it is only used for export.");
- RNA_def_function_return(func, parm);
-
- func= RNA_def_function(srna, "add_uv_texture", "rna_Mesh_add_uv_texture");
+ func= RNA_def_function(srna, "add_uv_texture", "rna_Mesh_uv_texture_add");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Add a UV texture layer to Mesh.");
- func= RNA_def_function(srna, "calc_normals", "rna_Mesh_calc_normals");
+ func= RNA_def_function(srna, "calc_normals", "ED_mesh_calc_normals");
RNA_def_function_ui_description(func, "Calculate vertex normals.");
- func= RNA_def_function(srna, "update", "rna_Mesh_update");
+ func= RNA_def_function(srna, "update", "ED_mesh_update");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
- func= RNA_def_function(srna, "add_material", "rna_Mesh_add_material");
+ func= RNA_def_function(srna, "add_material", "ED_mesh_material_add");
RNA_def_function_ui_description(func, "Add a new material to Mesh.");
parm= RNA_def_pointer(func, "material", "Material", "", "Material to add.");
RNA_def_property_flag(parm, PROP_REQUIRED);