[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21283] branches/blender2.5/blender/source /blender: RNA

Brecht Van Lommel brecht at blender.org
Wed Jul 1 14:19:02 CEST 2009


Revision: 21283
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21283
Author:   blendix
Date:     2009-07-01 14:19:00 +0200 (Wed, 01 Jul 2009)

Log Message:
-----------
RNA

* Mesh.add_geometry, Mesh.update and make indices editable. This
  is without checking if they are valid still, no time now to
  implement this.
* Also fix warnings in rna_ui.c, and a bug in CDDM_calc_edges.

Example code:

co = [0.0, 0.0, 0.0] + [1.0, 0.0, 0.0] + [0.0, 1.0, 0.0] + [1.0, 1.0, 0.0]
faces = [0, 1, 2, 0] + [1, 3, 2, 0]

mesh.add_geometry(4, 0, 2)

mesh.verts.foreach_set("co", co)
mesh.faces.foreach_set("verts", faces)

mesh.update()

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh_api.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_ui.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-01 11:27:43 UTC (rev 21282)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-01 12:19:00 UTC (rev 21283)
@@ -1220,7 +1220,7 @@
 	BLI_edgehashIterator_free(ehi);
 
 	/* free old CustomData and assign new one */
-	CustomData_free(&dm->edgeData, dm->numVertData);
+	CustomData_free(&dm->edgeData, dm->numEdgeData);
 	dm->edgeData = edgeData;
 	dm->numEdgeData = numEdges;
 

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c	2009-07-01 11:27:43 UTC (rev 21282)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c	2009-07-01 12:19:00 UTC (rev 21283)
@@ -716,8 +716,8 @@
 	prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED);
 	RNA_def_property_int_sdna(prop, NULL, "v1");
 	RNA_def_property_array(prop, 2);
-	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
+	// XXX allows creating invalid meshes
 
 	prop= RNA_def_property(srna, "crease", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_funcs(prop, "rna_MEdge_crease_get", "rna_MEdge_crease_set", NULL);
@@ -758,8 +758,8 @@
 	prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED);
 	RNA_def_property_int_sdna(prop, NULL, "v1");
 	RNA_def_property_array(prop, 4);
-	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
+	// XXX allows creating invalid meshes
 
 	prop= RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
 	RNA_def_property_int_sdna(prop, NULL, "mat_nr");
@@ -1104,7 +1104,6 @@
 	RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert");
 	RNA_def_property_struct_type(prop, "MeshVertex");
 	RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh.");
-	// XXX RNA_def_property_collection_funcs(prop, "rna_Mesh_verts_begin", 0, 0, 0, 0, 0, 0, "add_verts", "remove_verts");
 
 	prop= RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "medge", "totedge");

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh_api.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh_api.c	2009-07-01 11:27:43 UTC (rev 21282)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh_api.c	2009-07-01 12:19:00 UTC (rev 21283)
@@ -34,74 +34,207 @@
 
 #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 "DNA_mesh_types.h"
-#include "DNA_scene_types.h"
+#include "BLI_edgehash.h"
 
-/*
-void rna_Mesh_copy(Mesh *me, Mesh *from)
+#include "WM_api.h"
+#include "WM_types.h"
+
+static void rna_Mesh_calc_edges(Mesh *mesh)
 {
-	copy_mesh_data(me, from);
+	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 rna_Mesh_copy_applied(Mesh *me, Scene *sce, Object *ob)
+static void rna_Mesh_update(Mesh *mesh, bContext *C)
 {
-	DerivedMesh *dm= mesh_create_derived_view(sce, ob, CD_MASK_MESH);
-	DM_to_mesh(dm, me);
-	dm->release(dm);
+	Main *bmain= CTX_data_main(C);
+	Object *ob;
+
+	if(mesh->totface && mesh->totedge == 0)
+		rna_Mesh_calc_edges(mesh);
+
+	mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL);
+
+	for(ob=bmain->object.first; ob; ob=ob->id.next) {
+		if(ob->data == mesh) {
+			ob->recalc |= OB_RECALC_DATA;
+			WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob);
+		}
+	}
 }
-*/
 
-void rna_Mesh_transform(Mesh *me, float **mat)
+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;
 }
 
-#if 0
-/* extern struct EditVert *addvertlist(EditMesh *em, float *vec, struct EditVert *example); */
+static void rna_Mesh_add_edges(Mesh *mesh, int len)
+{
+	CustomData edata;
+	MEdge *medge;
+	int i, totedge;
 
-static void rna_Mesh_verts_add(PointerRNA *ptr, PointerRNA *ptr_item)
+	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)
 {
-	//Mesh *me= (Mesh*)ptr->data;
+	CustomData fdata;
+	MFace *mface;
+	int i, totface;
 
-	/*
-	// XXX if item is not MVert we fail silently
-	if (item->type == RNA_MeshVertex)
+	if(len == 0)
 		return;
 
-	// XXX this must be slow...
-	EditMesh *em= BKE_mesh_get_editmesh(me);
+	totface= mesh->totface + len;	/* new face count */
 
-	MVert *v = (MVert*)ptr_item->ptr->data;
-	addvertlist(em, v->co, NULL);
+	/* update customdata */
+	CustomData_copy(&mesh->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface);
+	CustomData_copy_data(&mesh->fdata, &fdata, 0, 0, mesh->totface);
 
-	BKE_mesh_end_editmesh(me, em);
-	*/
+	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;
 }
-#endif
 
+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);
+}
+
 #else
 
 void RNA_api_mesh(StructRNA *srna)
 {
-	/*FunctionRNA *func;
-	PropertyRNA *prop;*/
+	FunctionRNA *func;
+	PropertyRNA *parm;
 
-	/*
-	func= RNA_def_function(srna, "copy", "rna_Mesh_copy");
-	RNA_def_function_ui_description(func, "Copy mesh data.");
-	prop= RNA_def_pointer(func, "src", "Mesh", "", "A mesh to copy data from.");
-	RNA_def_property_flag(prop, PROP_REQUIRED);*/
+	func= RNA_def_function(srna, "add_geometry", "rna_Mesh_add_geometry");
+	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);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	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, "add_geom", "rna_Mesh_add_geom");
-	RNA_def_function_ui_description(func, "Add geometry data to mesh.");
-	prop= RNA_def_collection(func, "verts", "?", "", "Vertices.");
-	RNA_def_property_flag(prop, PROP_REQUIRED);
-	prop= RNA_def_collection(func, "faces", "?", "", "Faces.");
-	RNA_def_property_flag(prop, PROP_REQUIRED);
-	*/
+	func= RNA_def_function(srna, "update", "rna_Mesh_update");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
 }
 
 #endif

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_ui.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_ui.c	2009-07-01 11:27:43 UTC (rev 21282)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_ui.c	2009-07-01 12:19:00 UTC (rev 21283)
@@ -416,12 +416,12 @@
 
 static void rna_UILayout_active_set(struct PointerRNA *ptr, int value)
 {
-	return uiLayoutSetActive(ptr->data, value);
+	uiLayoutSetActive(ptr->data, value);
 }
 
 static void rna_UILayout_op_context_set(struct PointerRNA *ptr, int value)
 {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list