[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20780] branches/bmesh/blender/source: ( NOTE: DO NOT TEST)

Joseph Eagar joeedh at gmail.com
Wed Jun 10 12:06:25 CEST 2009


Revision: 20780
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20780
Author:   joeedh
Date:     2009-06-10 12:06:25 +0200 (Wed, 10 Jun 2009)

Log Message:
-----------
(NOTE: DO NOT TEST)

Start of planned DerivedMesh refactoring.  The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather 
then the primary ones, which are now stored in mpolys).

short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles).  mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.

I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh.  Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).

I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.

I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/BKE_DerivedMesh.h
    branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h
    branches/bmesh/blender/source/blender/blenkernel/BKE_multires.h
    branches/bmesh/blender/source/blender/blenkernel/intern/BME_conversions.c
    branches/bmesh/blender/source/blender/blenkernel/intern/CCGSubSurf.c
    branches/bmesh/blender/source/blender/blenkernel/intern/CCGSubSurf.h
    branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/anim.c
    branches/bmesh/blender/source/blender/blenkernel/intern/booleanops.c
    branches/bmesh/blender/source/blender/blenkernel/intern/bvhutils.c
    branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/cloth.c
    branches/bmesh/blender/source/blender/blenkernel/intern/displist.c
    branches/bmesh/blender/source/blender/blenkernel/intern/editderivedbmesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/exotic.c
    branches/bmesh/blender/source/blender/blenkernel/intern/fluidsim.c
    branches/bmesh/blender/source/blender/blenkernel/intern/modifier.c
    branches/bmesh/blender/source/blender/blenkernel/intern/multires.c
    branches/bmesh/blender/source/blender/blenkernel/intern/particle.c
    branches/bmesh/blender/source/blender/blenkernel/intern/particle_system.c
    branches/bmesh/blender/source/blender/blenkernel/intern/softbody.c
    branches/bmesh/blender/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c
    branches/bmesh/blender/source/blender/editors/armature/meshlaplacian.c
    branches/bmesh/blender/source/blender/editors/mesh/editmesh_tools.c
    branches/bmesh/blender/source/blender/editors/physics/editparticle.c
    branches/bmesh/blender/source/blender/editors/sculpt_paint/paint_image.c
    branches/bmesh/blender/source/blender/editors/sculpt_paint/paint_utils.c
    branches/bmesh/blender/source/blender/editors/sculpt_paint/sculpt.c
    branches/bmesh/blender/source/blender/editors/space_view3d/drawobject.c
    branches/bmesh/blender/source/blender/editors/transform/transform_snap.c
    branches/bmesh/blender/source/blender/render/intern/source/convertblender.c
    branches/bmesh/blender/source/blender/render/intern/source/strand.c
    branches/bmesh/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_DerivedMesh.h	2009-06-10 09:56:22 UTC (rev 20779)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_DerivedMesh.h	2009-06-10 10:06:25 UTC (rev 20780)
@@ -43,6 +43,8 @@
  */
 
 #include "DNA_customdata_types.h"
+#include "DNA_meshdata_types.h"
+
 #include "BKE_customdata.h"
 #include "BKE_bvhutils.h"
 
@@ -65,32 +67,75 @@
 #define SUB_ELEMS_EDGE 2
 #define SUB_ELEMS_FACE 4
 
+/*
+note: all mface interfaces now officially operate on tesselated data.
+*/
+
+/*DM Iterators.  For now, first implement face iterators.
+  These are read-only, at least for now.*/
+
+typedef struct DMLoopIter {
+	void (*step)(void *self);
+	int done;
+
+	int index, vindex, eindex;
+	MVert v; /*copy of the associated vert's data*/	
+
+	/*note: if layer is -1, then the active layer is retrieved.
+	  loop refers to per-face-vertex data.*/
+	void *(*getLoopCDData)(void *self, int type, int layer);
+	void *(*getVertCDData)(void *self, int type, int layer);
+} DMLoopIter;
+
+typedef struct DMFaceIter {
+	void (*step)(void *self);
+	void (*free)(void *self);
+	int done;
+
+	int index;
+	int len;
+	int mat_nr;
+	int flags;
+
+	/*note: you may only use one
+	  loop iterator at a time.*/
+	DMLoopIter *(*getLoopsIter)(void *self);
+
+	/*if layer is -1, returns active layer*/
+	void *(*getCDData)(void *self, int type, int layer);
+} DMFaceIter;
+
 typedef struct DerivedMesh DerivedMesh;
 struct DerivedMesh {
 	/* Private DerivedMesh data, only for internal DerivedMesh use */
-	CustomData vertData, edgeData, faceData;
-	int numVertData, numEdgeData, numFaceData;
+	CustomData vertData, edgeData, faceData, loopData, polyData;
+	int numVertData, numEdgeData, numFaceData, numLoopData, numPolyData;
 	int needsFree; /* checked on ->release, is set to 0 for cached results */
 	int deformedOnly; /* set by modifier stack if only deformed from original */
 	BVHCache bvhCache;
 
 	/* Misc. Queries */
+	
+	/*face iterator.  initializes iter.*/
+	DMFaceIter *(*newFaceIter)(DerivedMesh *dm);
 
+	/*recalculates mesh tesselation*/
+	void (*recalcTesselation)(DerivedMesh *dm);
+
 	/* Also called in Editmode */
 	int (*getNumVerts)(DerivedMesh *dm);
-	/* Also called in Editmode */
-	int (*getNumFaces)(DerivedMesh *dm);
-
 	int (*getNumEdges)(DerivedMesh *dm);
+	int (*getNumTessFaces)(DerivedMesh *dm);
+	int (*getNumFaces) (DerivedMesh *dm);
 
-	/* copy a single vert/edge/face from the derived mesh into
+	/* copy a single vert/edge/tesselated face from the derived mesh into
 	 * *{vert/edge/face}_r. note that the current implementation
 	 * of this function can be quite slow, iterating over all
 	 * elements (editmesh)
 	 */
 	void (*getVert)(DerivedMesh *dm, int index, struct MVert *vert_r);
 	void (*getEdge)(DerivedMesh *dm, int index, struct MEdge *edge_r);
-	void (*getFace)(DerivedMesh *dm, int index, struct MFace *face_r);
+	void (*getTessFace)(DerivedMesh *dm, int index, struct MFace *face_r);
 
 	/* return a pointer to the entire array of verts/edges/face from the
 	 * derived mesh. if such an array does not exist yet, it will be created,
@@ -99,21 +144,21 @@
 	 */
 	struct MVert *(*getVertArray)(DerivedMesh *dm);
 	struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
-	struct MFace *(*getFaceArray)(DerivedMesh *dm);
+	struct MFace *(*getTessFaceArray)(DerivedMesh *dm);
 
 	/* copy all verts/edges/faces from the derived mesh into
 	 * *{vert/edge/face}_r (must point to a buffer large enough)
 	 */
 	void (*copyVertArray)(DerivedMesh *dm, struct MVert *vert_r);
 	void (*copyEdgeArray)(DerivedMesh *dm, struct MEdge *edge_r);
-	void (*copyFaceArray)(DerivedMesh *dm, struct MFace *face_r);
+	void (*copyTessFaceArray)(DerivedMesh *dm, struct MFace *face_r);
 
 	/* return a copy of all verts/edges/faces from the derived mesh
 	 * it is the caller's responsibility to free the returned pointer
 	 */
 	struct MVert *(*dupVertArray)(DerivedMesh *dm);
 	struct MEdge *(*dupEdgeArray)(DerivedMesh *dm);
-	struct MFace *(*dupFaceArray)(DerivedMesh *dm);
+	struct MFace *(*dupTessFaceArray)(DerivedMesh *dm);
 
 	/* return a pointer to a single element of vert/edge/face custom data
 	 * from the derived mesh (this gives a pointer to the actual data, not
@@ -121,7 +166,7 @@
 	 */
 	void *(*getVertData)(DerivedMesh *dm, int index, int type);
 	void *(*getEdgeData)(DerivedMesh *dm, int index, int type);
-	void *(*getFaceData)(DerivedMesh *dm, int index, int type);
+	void *(*getTessFaceData)(DerivedMesh *dm, int index, int type);
 
 	/* return a pointer to the entire array of vert/edge/face custom data
 	 * from the derived mesh (this gives a pointer to the actual data, not
@@ -129,7 +174,7 @@
 	 */
 	void *(*getVertDataArray)(DerivedMesh *dm, int type);
 	void *(*getEdgeDataArray)(DerivedMesh *dm, int type);
-	void *(*getFaceDataArray)(DerivedMesh *dm, int type);
+	void *(*getTessFaceDataArray)(DerivedMesh *dm, int type);
 
 	/* Iterate over each mapped vertex in the derived mesh, calling the
 	 * given function with the original vert and the mapped vert's new
@@ -300,13 +345,15 @@
  * of vertices, edges and faces (doesn't allocate memory for them, just
  * sets up the custom data layers)
  */
-void DM_init(DerivedMesh *dm, int numVerts, int numEdges, int numFaces);
+void DM_init(DerivedMesh *dm, int numVerts, int numEdges, int numFaces,
+	     int numLoops, int numPolys);
 
 /* utility function to initialise a DerivedMesh for the desired number
  * of vertices, edges and faces, with a layer setup copied from source
  */
 void DM_from_template(DerivedMesh *dm, DerivedMesh *source,
-                      int numVerts, int numEdges, int numFaces);
+                      int numVerts, int numEdges, int numFaces,
+		      int numLoops, int numPolys);
 
 /* utility function to release a DerivedMesh's layers
  * returns 1 if DerivedMesh has to be released by the backend, 0 otherwise
@@ -369,6 +416,10 @@
                        int source_index, int dest_index, int count);
 void DM_copy_edge_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                        int source_index, int dest_index, int count);
+void DM_copy_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                       int source_index, int dest_index, int count);
+void DM_copy_loop_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                       int source_index, int dest_index, int count);
 void DM_copy_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                        int source_index, int dest_index, int count);
 
@@ -378,8 +429,13 @@
  */
 void DM_free_vert_data(struct DerivedMesh *dm, int index, int count);
 void DM_free_edge_data(struct DerivedMesh *dm, int index, int count);
+void DM_free_tessface_data(struct DerivedMesh *dm, int index, int count);
+void DM_free_loop_data(struct DerivedMesh *dm, int index, int count);
 void DM_free_face_data(struct DerivedMesh *dm, int index, int count);
 
+/*sets up mpolys for a DM based on face iterators in source*/
+void DM_DupPolys(DerivedMesh *source, DerivedMesh *target);
+
 /* interpolates vertex data from the vertices indexed by src_indices in the
  * source mesh using the given weights and stores the result in the vertex
  * indexed by dest_index in the dest mesh
@@ -409,13 +465,21 @@
  * vert_weights[i] multiplied by weights[i].
  */
 typedef float FaceVertWeight[SUB_ELEMS_FACE][SUB_ELEMS_FACE];
-void DM_interp_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+void DM_interp_tessface_data(struct DerivedMesh *source, struct DerivedMesh *dest,
                          int *src_indices,
                          float *weights, FaceVertWeight *vert_weights,
                          int count, int dest_index);
 
-void DM_swap_face_data(struct DerivedMesh *dm, int index, int *corner_indices);
+void DM_swap_tessface_data(struct DerivedMesh *dm, int index, int *corner_indices);
 
+void DM_interp_loop_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index);
+
+void DM_interp_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
+                         int *src_indices,
+                         float *weights, int count, int dest_index);
+
 /* Temporary? A function to give a colorband to derivedmesh for vertexcolor ranges */
 void vDM_ColorBand_store(struct ColorBand *coba);
 

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h	2009-06-10 09:56:22 UTC (rev 20779)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h	2009-06-10 10:06:25 UTC (rev 20780)
@@ -44,7 +44,8 @@
 struct Object;
 
 /* creates a new CDDerivedMesh */
-struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces);
+struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces,
+                             int numLoops, int numPolys);
 
 /* creates a CDDerivedMesh from the given Mesh, this will reference the
    original data in Mesh, but it is safe to apply vertex coordinates or
@@ -68,8 +69,14 @@
  * elements are initialised to all zeros
  */
 struct DerivedMesh *CDDM_from_template(struct DerivedMesh *source,
-                                  int numVerts, int numEdges, int numFaces);
+                                  int numVerts, int numEdges, int numFaces,
+                                  int numLoops, int numPolys);
 
+/*converts mfaces to mpolys.  note things may break if there are not valid
+ *medges surrounding each mface.
+ */
+void CDDM_tessfaces_to_faces(struct DerivedMesh *dm);
+
 /* applies vertex coordinates or normals to a CDDerivedMesh. if the MVert
  * layer is a referenced layer, it will be duplicate to not overwrite the
  * original
@@ -99,7 +106,9 @@
  */
 struct MVert *CDDM_get_vert(struct DerivedMesh *dm, int index);
 struct MEdge *CDDM_get_edge(struct DerivedMesh *dm, int index);
-struct MFace *CDDM_get_face(struct DerivedMesh *dm, int index);
+struct MFace *CDDM_get_tessface(struct DerivedMesh *dm, int index);
+struct MLoop *CDDM_get_loop(struct DerivedMesh *dm, int index);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list