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:
authorTon Roosendaal <ton@blender.org>2004-09-24 00:52:51 +0400
committerTon Roosendaal <ton@blender.org>2004-09-24 00:52:51 +0400
commita2e918d831fb1c7fd4da8b2f56a24aad75479627 (patch)
tree57a415ba3773594b0fa045e5338acb983112c610 /source/blender/src/editmesh_lib.c
parent4b5203e29e5febafa731e2d70223bdb6fd27a783 (diff)
EditMesh refactory + undo recode
The changelog is very long... it's on the web too: http://www.blender3d.org/cms/Mesh_editing_rewrite.425.0.html EditMesh refactor notes (user) **** New selection modes When entering Edit Mode for a Mesh, you now have the choice for three selection modes. These are shown as icons in the 3D header (hotkey is being searched for!). - Vertex Select Select vertices as usual, fully compatible with how previous version work - Edge Select Vertices are not drawn anymore, and selections happen by default on the edges. It is a true edge select, meaning that you can select three out of four edges in a face, without automatic having the 4th edge selected. - Face Select Instead of vertices, now selection 'points' are drawn in the face centers. Selected faces also get a colored outline, like for edges. This also is true face select, for each face individual regardless selection status of its vertices or edges. While holding SHIFT, and press a selection mode, you can also combine the above choices. Now selection becomes mixed, and will behave as expected. For example; in Edge+Face select mode, selecting the 4 edges of a face will select the face too. The selection modes and optional drawing modes (like transparant faces, normals, or solid drawing) all work together. All of Blender's mesh editing tools now react to the correct selection mode as well. Most noticeable it's in: **** Extrude Extruding in Edge or Face Select mode allows much more precise control over what's extruded and what should be excluded. Try for example a checker pattern selection, and extrude it. New is the fixed translation when faces are extruded. This always follows the (averaged) face normal(s) of the old face(s), enabling much easier working in 3D views . A single 'G' (Grab) or 'R' (Rotate) or 'S' (Scale) will change transform modus as usual. **** Other things to note - Hiding edges/faces will also behave different based on Select Mode. - while editing, normals of faces are updated always now - Border select (BKEY) has 2 different rules for edges; when one edge is fully inside of the border, it will only select edges that are fully inside. Otherwise it selects each edge intersecting with the border. - in face mode, adding vertices, edges or a circle is invisible... - "Add monkey" now works as a normal primitive (rotated and on 3d cursor) - Mesh undo was fully recoded, hopefully solving issues now with Vertex Keys and Groups - Going in and out of editmode was fully recoded. Especially on larger models you'll notice substantial speed gain. **** Todo Add 'FaceSelect mode' functionality in EditMode, including zbuffered selection, display and editing of UV texture. EditMesh refactor notes (coder) **** Usage of flags in general The "->f" flags are reserved for the editmesh.c and editmesh_lib.c core functions. Actually only selection status is there now. The "->f1" and "->f2" flags are free to use. They're available in vertex/edge/face structs. Since they're free, check carefully when calling other functions that use these flags... for example extrude() or subdivide() use them. **** Selection flags EditVert: eve->f & SELECT EditEdge: eed->f & SELECT EditFace: efa->f & SELECT - Selection is only possible when not-hidden! - Selection flags are always up-to-date, BUT: if selection mode >= SELECT_EDGE vertex selection flags can be incorrect if selection mode == SELECT_FACE vertex/edge selection flags can be incorrect This because of shared vertices or edges. - use for selecting vertices: eve->f &= SELECT - use for selecting edges always: void EM_select_edge(eed, 1) // 1 = select, 0 = deselect - use for selecting faces always: void EM_select_face(efa, 1) // 1 = select, 0 = deselect - To set the 'f' flags in all of the data: void EM_set_flag_all(int flag); void EM_clear_flag_all(int flag); - the old faceselectedOR() and faceselectedAND() are still there, but only to be used for evaluating its vertices **** Code hints for handling selection If the selectmode is 'face'; vertex or edge selections need to be flushed upward. Same is true for 'edge' selection mode. This means that you'll have to keep track of all selections while coding... selecting the four vertices in a face doesn't automatically select the face anymore. However, by using the above calls, at least selections flush downward (to vertex level). You then can call: void EM_selectmode_flush(void); Which flushes selections back upward, based on the selectmode setting. This function does the following: - if selectmode 'vertex': select edges/faces based on its selected vertices - if selectmode 'edge': select faces based its selected edges This works fine in nice controlled situations. However, only changing the vertex selections then still doesn't select a face in face mode! If you really can't avoid only working with vertex selections, you can use this call: void EM_select_flush(void); Now selection is flushed upward regardless current selectmode. That can be destructive for special cases however, like checkerboard selected faces. So use this only when you know everything else was deselected (or deselect it). Example: adding primitives. **** Hide flags EditVert: eve->h EditEdge: eed->h EditFace: efa->h - all hide flags are always up-to-date - hidden vertices/edges/faces are always deselected. so when you operate on selection only, there's no need to check for hide flag. **** Unified undo for editmode New file: editmode_undo.h A pretty nice function pointer handler style undo. Just code three functions, and your undo will fly! The c file has a good reference. Also note that the old undo system has been replaced. It currently uses minimal dependencies on Meshes themselves (no abuse of going in/out editmode), and is restricted nicely to editmode functions. **** Going in/out editmode As speedup now all vertices/faces/edges are allocated in three big chunks. In vertices/faces/edges now tags are set to denote such data cannot be freed. ALso the hashtable (lookup) for edges uses no mallocs at all anymore, but is part of the EditEdge itself.
Diffstat (limited to 'source/blender/src/editmesh_lib.c')
-rw-r--r--source/blender/src/editmesh_lib.c697
1 files changed, 572 insertions, 125 deletions
diff --git a/source/blender/src/editmesh_lib.c b/source/blender/src/editmesh_lib.c
index a977130c385..263f860a7b2 100644
--- a/source/blender/src/editmesh_lib.c
+++ b/source/blender/src/editmesh_lib.c
@@ -53,6 +53,7 @@ editmesh_lib: generic (no UI, no menus) operations/evaluators for editmesh data
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
@@ -67,22 +68,89 @@ editmesh_lib: generic (no UI, no menus) operations/evaluators for editmesh data
#include "editmesh.h"
-/* ********************* */
+/* ********* Selection ************ */
+
+void EM_select_face(EditFace *efa, int sel)
+{
+ if(sel) {
+ efa->f |= SELECT;
+ efa->e1->f |= SELECT;
+ efa->e2->f |= SELECT;
+ efa->e3->f |= SELECT;
+ if(efa->e4) efa->e4->f |= SELECT;
+ efa->v1->f |= SELECT;
+ efa->v2->f |= SELECT;
+ efa->v3->f |= SELECT;
+ if(efa->v4) efa->v4->f |= SELECT;
+ }
+ else {
+ efa->f &= ~SELECT;
+ efa->e1->f &= ~SELECT;
+ efa->e2->f &= ~SELECT;
+ efa->e3->f &= ~SELECT;
+ if(efa->e4) efa->e4->f &= ~SELECT;
+ efa->v1->f &= ~SELECT;
+ efa->v2->f &= ~SELECT;
+ efa->v3->f &= ~SELECT;
+ if(efa->v4) efa->v4->f &= ~SELECT;
+ }
+}
-int editmesh_nfaces_selected(void)
+void EM_select_edge(EditEdge *eed, int sel)
+{
+ if(sel) {
+ eed->f |= SELECT;
+ eed->v1->f |= SELECT;
+ eed->v2->f |= SELECT;
+ }
+ else {
+ eed->f &= ~SELECT;
+ eed->v1->f &= ~SELECT;
+ eed->v2->f &= ~SELECT;
+ }
+}
+
+int faceselectedOR(EditFace *efa, int flag)
+{
+
+ if(efa->v1->f & flag) return 1;
+ if(efa->v2->f & flag) return 1;
+ if(efa->v3->f & flag) return 1;
+ if(efa->v4 && (efa->v4->f & 1)) return 1;
+ return 0;
+}
+
+// replace with (efa->f & SELECT)
+int faceselectedAND(EditFace *efa, int flag)
+{
+ if(efa->v1->f & flag) {
+ if(efa->v2->f & flag) {
+ if(efa->v3->f & flag) {
+ if(efa->v4) {
+ if(efa->v4->f & flag) return 1;
+ }
+ else return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+
+int EM_nfaces_selected(void)
{
EditMesh *em = G.editMesh;
EditFace *efa;
int count= 0;
for (efa= em->faces.first; efa; efa= efa->next)
- if (faceselectedAND(efa, SELECT))
+ if (efa->f & SELECT)
count++;
return count;
}
-int editmesh_nvertices_selected(void)
+int EM_nvertices_selected(void)
{
EditMesh *em = G.editMesh;
EditVert *eve;
@@ -95,22 +163,353 @@ int editmesh_nvertices_selected(void)
return count;
}
-/* ***************** */
+void EM_clear_flag_all(int flag)
+{
+ EditMesh *em = G.editMesh;
+ EditVert *eve;
+ EditEdge *eed;
+ EditFace *efa;
+
+ for (eve= em->verts.first; eve; eve= eve->next) eve->f &= ~flag;
+ for (eed= em->edges.first; eed; eed= eed->next) eed->f &= ~flag;
+ for (efa= em->faces.first; efa; efa= efa->next) efa->f &= ~flag;
+
+}
+
+void EM_set_flag_all(int flag)
+{
+ EditMesh *em = G.editMesh;
+ EditVert *eve;
+ EditEdge *eed;
+ EditFace *efa;
+
+ for (eve= em->verts.first; eve; eve= eve->next) eve->f |= flag;
+ for (eed= em->edges.first; eed; eed= eed->next) eed->f |= flag;
+ for (efa= em->faces.first; efa; efa= efa->next) efa->f |= flag;
+
+}
+
+/* flush to edges & faces */
+
+/* this based on coherent selected vertices, for example when adding new
+ objects. call clear_flag_all() before you select vertices to be sure it ends OK!
+
+*/
+
+void EM_select_flush(void)
+{
+ EditMesh *em = G.editMesh;
+ EditEdge *eed;
+ EditFace *efa;
+
+ for(eed= em->edges.first; eed; eed= eed->next) {
+ if(eed->v1->f & eed->v2->f & SELECT) eed->f |= SELECT;
+ }
+ for(efa= em->faces.first; efa; efa= efa->next) {
+ if(efa->v4) {
+ if(efa->v1->f & efa->v2->f & efa->v3->f & efa->v4->f & SELECT ) efa->f |= SELECT;
+ }
+ else {
+ if(efa->v1->f & efa->v2->f & efa->v3->f & SELECT ) efa->f |= SELECT;
+ }
+ }
+}
+
+/* flush to edges & faces */
+
+/* based on select mode it selects edges/faces
+ assumed is that verts/edges/faces were properly selected themselves
+ with the calls above
+*/
+
+void EM_selectmode_flush(void)
+{
+ EditMesh *em = G.editMesh;
+ EditEdge *eed;
+ EditFace *efa;
+
+ // flush to edges & faces
+ if(G.scene->selectmode & SCE_SELECT_VERTEX) {
+ for(eed= em->edges.first; eed; eed= eed->next) {
+ if(eed->v1->f & eed->v2->f & SELECT) eed->f |= SELECT;
+ else eed->f &= ~SELECT;
+ }
+ for(efa= em->faces.first; efa; efa= efa->next) {
+ if(efa->v4) {
+ if(efa->v1->f & efa->v2->f & efa->v3->f & efa->v4->f & SELECT) efa->f |= SELECT;
+ else efa->f &= ~SELECT;
+ }
+ else {
+ if(efa->v1->f & efa->v2->f & efa->v3->f & SELECT) efa->f |= SELECT;
+ else efa->f &= ~SELECT;
+ }
+ }
+ }
+ // flush to faces
+ else if(G.scene->selectmode & SCE_SELECT_EDGE) {
+ for(efa= em->faces.first; efa; efa= efa->next) {
+ if(efa->e4) {
+ if(efa->e1->f & efa->e2->f & efa->e3->f & efa->e4->f & SELECT) efa->f |= SELECT;
+ else efa->f &= ~SELECT;
+ }
+ else {
+ if(efa->e1->f & efa->e2->f & efa->e3->f & SELECT) efa->f |= SELECT;
+ else efa->f &= ~SELECT;
+ }
+ }
+ }
+
+ // make sure selected faces have selected edges too, for extrude (hack?)
+ else if(G.scene->selectmode & SCE_SELECT_FACE) {
+ for(efa= em->faces.first; efa; efa= efa->next) {
+ if(efa->f & SELECT) {
+ efa->e1->f |= SELECT;
+ efa->e2->f |= SELECT;
+ efa->e3->f |= SELECT;
+ if(efa->e4) efa->e4->f |= SELECT;
+ }
+ }
+ }
+}
+
+/* when switching select mode, makes sure selection is consistant for editing */
+/* also for paranoia checks to make sure edge or face mode works */
+void EM_selectmode_set(void)
+{
+ EditMesh *em = G.editMesh;
+ EditVert *eve;
+ EditEdge *eed;
+ EditFace *efa;
+
+ if(G.scene->selectmode & SCE_SELECT_VERTEX) {
+ /* vertices -> edges -> faces */
+ EM_select_flush();
+ }
+ else if(G.scene->selectmode & SCE_SELECT_EDGE) {
+ /* deselect vertices, and select again based on edge select */
+ for(eve= em->verts.first; eve; eve= eve->next) eve->f &= ~SELECT;
+ for(eed= em->edges.first; eed; eed= eed->next)
+ if(eed->f & SELECT) EM_select_edge(eed, 1);
+ /* selects faces based on edge status */
+ EM_selectmode_flush();
+ }
+ else if(G.scene->selectmode == SCE_SELECT_FACE) {
+ /* deselect eges, and select again based on face select */
+ for(eed= em->edges.first; eed; eed= eed->next) EM_select_edge(eed, 0);
+ for(efa= em->faces.first; efa; efa= efa->next)
+ if(efa->f & SELECT) EM_select_face(efa, 1);
+ }
+}
+
+
+/* ******** EXTRUDE ********* */
-short extrudeflag(short flag,short type)
+static void set_edge_directions(void)
{
- /* when type=1 old extrusion faces are removed (for spin etc) */
- /* all verts with (flag & 'flag'): extrude */
+ EditMesh *em= G.editMesh;
+ EditFace *efa= em->faces.first;
+
+ while(efa) {
+ // non selected face
+ if(efa->f== 0) {
+ if(efa->e1->f) {
+ if(efa->e1->v1 == efa->v1) efa->e1->dir= 0;
+ else efa->e1->dir= 1;
+ }
+ if(efa->e2->f) {
+ if(efa->e2->v1 == efa->v2) efa->e2->dir= 0;
+ else efa->e2->dir= 1;
+ }
+ if(efa->e3->f) {
+ if(efa->e3->v1 == efa->v3) efa->e3->dir= 0;
+ else efa->e3->dir= 1;
+ }
+ if(efa->e4 && efa->e4->f) {
+ if(efa->e4->v1 == efa->v4) efa->e4->dir= 0;
+ else efa->e4->dir= 1;
+ }
+ }
+ efa= efa->next;
+ }
+}
+
+static short extrudeflag_edge(short flag)
+{
+ /* all select edges/faces: extrude */
+ /* old select is cleared, in new ones it is set */
+ EditMesh *em = G.editMesh;
+ EditVert *eve, *nextve;
+ EditEdge *eed, *nexted;
+ EditFace *efa, *nextfa;
+ float nor[3]={0.0, 0.0, 0.0};
+ short del_old= 0;
+
+ if(G.obedit==0 || get_mesh(G.obedit)==0) return 0;
+
+ /* selected edges with 0 or 1 selected face become faces */
+ /* selected faces generate new faces */
+
+ /* if *one* selected face has edge with unselected face; remove old selected faces */
+
+ /* if selected edge is not used anymore; remove */
+ /* if selected vertex is not used anymore: remove */
+
+ /* select the new extrusion, deselect old */
+
+
+ /* step 1; init, count faces in edges */
+ recalc_editnormals();
+
+ for(eve= em->verts.first; eve; eve= eve->next) {
+ eve->vn= NULL;
+ eve->f1= 0;
+ }
+
+ for(eed= em->edges.first; eed; eed= eed->next) {
+ eed->f1= 0; // amount of selected faces
+ eed->f2= 0; // amount of unselected faces
+ if(eed->f & SELECT) {
+ eed->v1->f1= 1; // we call this 'selected vertex' now
+ eed->v2->f1= 1;
+ }
+ }
+ for(efa= em->faces.first; efa; efa= efa->next) {
+ if(efa->f & SELECT) {
+ efa->e1->f1++;
+ efa->e2->f1++;
+ efa->e3->f1++;
+ if(efa->e4) efa->e4->f1++;
+ }
+ else {
+ efa->e1->f2++;
+ efa->e2->f2++;
+ efa->e3->f2++;
+ if(efa->e4) efa->e4->f2++;
+ }
+ }
+
+ set_edge_directions();
+
+ /* step 2: make new faces from edges */
+ for(eed= em->edges.last; eed; eed= eed->prev) {
+ if(eed->f & SELECT) {
+ if(eed->f1<2) {
+ if(eed->v1->vn==NULL)
+ eed->v1->vn= addvertlist(eed->v1->co);
+ if(eed->v2->vn==NULL)
+ eed->v2->vn= addvertlist(eed->v2->co);
+
+ if(eed->dir==1) addfacelist(eed->v1, eed->v2, eed->v2->vn, eed->v1->vn, NULL);
+ else addfacelist(eed->v2, eed->v1, eed->v1->vn, eed->v2->vn, NULL);
+ }
+ }
+ }
+
+ /* step 3: make new faces from faces */
+ for(efa= em->faces.last; efa; efa= efa->prev) {
+ if(efa->f & SELECT) {
+ if(efa->v1->vn==NULL) efa->v1->vn= addvertlist(efa->v1->co);
+ if(efa->v2->vn==NULL) efa->v2->vn= addvertlist(efa->v2->co);
+ if(efa->v3->vn==NULL) efa->v3->vn= addvertlist(efa->v3->co);
+ if(efa->v4 && efa->v4->vn==NULL) efa->v4->vn= addvertlist(efa->v4->co);
+
+ if(efa->v4)
+ addfacelist(efa->v1->vn, efa->v2->vn, efa->v3->vn, efa->v4->vn, efa);
+ else
+ addfacelist(efa->v1->vn, efa->v2->vn, efa->v3->vn, NULL, efa);
+
+ /* if *one* selected face has edge with unselected face; remove old selected faces */
+ if(efa->e1->f2 || efa->e2->f2 || efa->e3->f2 || (efa->e4 && efa->e4->f2))
+ del_old= 1;
+
+ /* for transform */
+ VecAddf(nor, nor, efa->n);
+ }
+ }
+
+ if(del_old) {
+ /* step 4: remove old faces, if del_old */
+ efa= em->faces.first;
+ while(efa) {
+ nextfa= efa->next;
+ if(efa->f & SELECT) {
+ BLI_remlink(&em->faces, efa);
+ free_editface(efa);
+ }
+ efa= nextfa;
+ }
+
+ /* step 5: remove selected unused edges */
+ /* start tagging again */
+ for(eed= em->edges.first; eed; eed= eed->next) eed->f1=0;
+ for(efa= em->faces.first; efa; efa= efa->next) {
+ efa->e1->f1= 1;
+ efa->e2->f1= 1;
+ efa->e3->f1= 1;
+ if(efa->e4) efa->e4->f1= 1;
+ }
+ /* remove */
+ eed= em->edges.first;
+ while(eed) {
+ nexted= eed->next;
+ if(eed->f & SELECT) {
+ if(eed->f1==0) {
+ remedge(eed);
+ free_editedge(eed);
+ }
+ }
+ eed= nexted;
+ }
+
+ /* step 6: remove selected unused vertices */
+ for(eed= em->edges.first; eed; eed= eed->next)
+ eed->v1->f1= eed->v2->f1= 0;
+
+ eve= em->verts.first;
+ while(eve) {
+ nextve= eve->next;
+ if(eve->f1) {
+ // hack... but we need it for step 7, redoing selection
+ if(eve->vn) eve->vn->vn= eve->vn;
+
+ BLI_remlink(&em->verts, eve);
+ free_editvert(eve);
+ }
+ eve= nextve;
+ }
+ }
+
+ /* step 7: redo selection */
+ EM_clear_flag_all(SELECT);
+
+ Normalise(nor); // translation normal grab
+
+ for(eve= em->verts.first; eve; eve= eve->next) {
+ if(eve->vn) {
+ eve->vn->f |= SELECT;
+ VECCOPY(eve->vn->no, nor);
+ }
+ }
+
+ EM_select_flush();
+
+ return 1;
+}
+
+short extrudeflag_vert(short flag)
+{
+ /* all verts/edges/faces with (f & 'flag'): extrude */
/* from old verts, 'flag' is cleared, in new ones it is set */
EditMesh *em = G.editMesh;
EditVert *eve, *v1, *v2, *v3, *v4, *nextve;
EditEdge *eed, *e1, *e2, *e3, *e4, *nexted;
EditFace *efa, *efa2, *nextvl;
- short sel=0, deloud= 0, smooth= 0;
+ float nor[3]={0.0, 0.0, 0.0};
+ short sel=0, del_old= 0, smooth= 0;
if(G.obedit==0 || get_mesh(G.obedit)==0) return 0;
- /* clear vert flag f1, we use this to detext a loose selected vertice */
+ /* clear vert flag f1, we use this to detect a loose selected vertice */
eve= em->verts.first;
while(eve) {
if(eve->f & flag) eve->f1= 1;
@@ -121,11 +520,11 @@ short extrudeflag(short flag,short type)
eed= em->edges.first;
while(eed) {
if( (eed->v1->f & flag) && (eed->v2->f & flag) ) {
- eed->f= 1;
+ eed->f2= 1;
eed->v1->f1= 0;
eed->v2->f1= 0;
}
- else eed->f= 0;
+ else eed->f2= 0;
eed->f1= 1; /* this indicates it is an 'old' edge (in this routine we make new ones) */
@@ -136,7 +535,7 @@ short extrudeflag(short flag,short type)
efa= em->faces.first;
while(efa) {
- efa->f= 0;
+ efa->f1= 0;
if (efa->flag & ME_SMOOTH) {
if (faceselectedOR(efa, 1)) smooth= 1;
@@ -148,11 +547,12 @@ short extrudeflag(short flag,short type)
e3= efa->e3;
e4= efa->e4;
- if(e1->f < 3) e1->f++;
- if(e2->f < 3) e2->f++;
- if(e3->f < 3) e3->f++;
- if(e4 && e4->f < 3) e4->f++;
- efa->f= 1;
+ if(e1->f2 < 3) e1->f2++;
+ if(e2->f2 < 3) e2->f2++;
+ if(e3->f2 < 3) e3->f2++;
+ if(e4 && e4->f2 < 3) e4->f2++;
+
+ efa->f1= 1;
}
else if(faceselectedOR(efa, flag)) {
e1= efa->e1;
@@ -169,51 +569,28 @@ short extrudeflag(short flag,short type)
efa= efa->next;
}
- /* set direction of edges */
- efa= em->faces.first;
- while(efa) {
- if(efa->f== 0) {
- if(efa->e1->f==2) {
- if(efa->e1->v1 == efa->v1) efa->e1->dir= 0;
- else efa->e1->dir= 1;
- }
- if(efa->e2->f==2) {
- if(efa->e2->v1 == efa->v2) efa->e2->dir= 0;
- else efa->e2->dir= 1;
- }
- if(efa->e3->f==2) {
- if(efa->e3->v1 == efa->v3) efa->e3->dir= 0;
- else efa->e3->dir= 1;
- }
- if(efa->e4 && efa->e4->f==2) {
- if(efa->e4->v1 == efa->v4) efa->e4->dir= 0;
- else efa->e4->dir= 1;
- }
- }
- efa= efa->next;
- }
-
+ set_edge_directions();
/* the current state now is:
eve->f1==1: loose selected vertex
- eed->f==0 : edge is not selected, no extrude
- eed->f==1 : edge selected, is not part of a face, extrude
- eed->f==2 : edge selected, is part of 1 face, extrude
- eed->f==3 : edge selected, is part of more faces, no extrude
+ eed->f2==0 : edge is not selected, no extrude
+ eed->f2==1 : edge selected, is not part of a face, extrude
+ eed->f2==2 : edge selected, is part of 1 face, extrude
+ eed->f2==3 : edge selected, is part of more faces, no extrude
eed->f1==0: new edge
eed->f1==1: edge selected, is part of selected face, when eed->f==3: remove
- eed->f1==2: edge selected, is not part of a selected face
+ eed->f1==2: edge selected, part of a partially selected face
- efa->f==1 : duplicate this face
+ efa->f1==1 : duplicate this face
*/
/* copy all selected vertices, */
/* write pointer to new vert in old struct at eve->vn */
eve= em->verts.last;
while(eve) {
- eve->f&= ~128; /* clear, for later test for loose verts */
+ eve->f &= ~128; /* clear, for later test for loose verts */
if(eve->f & flag) {
sel= 1;
v1= addvertlist(0);
@@ -229,17 +606,24 @@ short extrudeflag(short flag,short type)
if(sel==0) return 0;
- /* all edges with eed->f==1 or eed->f==2 become faces */
- /* if deloud==1 then edges with eed->f>2 are removed */
+ /* all edges with eed->f2==1 or eed->f2==2 become faces */
+
+ /* if del_old==1 then extrude is in partial geometry, to keep it manifold.
+ verts with f1==0 and (eve->f & 128)==0) are removed
+ edges with eed->f2>2 are removed
+ faces with efa->f1 are removed
+ if del_old==0 the extrude creates a volume.
+ */
+
eed= em->edges.last;
while(eed) {
nexted= eed->prev;
- if( eed->f<3) {
- eed->v1->f|=128; /* = no loose vert! */
- eed->v2->f|=128;
+ if( eed->f2<3) {
+ eed->v1->f |= 128; /* = no loose vert! */
+ eed->v2->f |= 128;
}
- if( (eed->f==1 || eed->f==2) ) {
- if(eed->f1==2) deloud=1;
+ if( (eed->f2==1 || eed->f2==2) ) {
+ if(eed->f1==2) del_old= 1;
if(eed->dir==1) efa2= addfacelist(eed->v1, eed->v2, eed->v2->vn, eed->v1->vn, NULL);
else efa2= addfacelist(eed->v2, eed->v1, eed->v1->vn, eed->v2->vn, NULL);
@@ -257,22 +641,22 @@ short extrudeflag(short flag,short type)
eed= nexted;
}
- if(deloud) {
+ if(del_old) {
eed= em->edges.first;
while(eed) {
nexted= eed->next;
- if(eed->f==3 && eed->f1==1) {
+ if(eed->f2==3 && eed->f1==1) {
remedge(eed);
free_editedge(eed);
}
eed= nexted;
}
}
- /* duplicate faces, if necessart remove old ones */
+ /* duplicate faces, if necessary remove old ones */
efa= em->faces.first;
while(efa) {
nextvl= efa->next;
- if(efa->f & 1) {
+ if(efa->f1 & 1) {
v1= efa->v1->vn;
v2= efa->v2->vn;
@@ -281,7 +665,10 @@ short extrudeflag(short flag,short type)
efa2= addfacelist(v1, v2, v3, v4, efa);
- if(deloud) {
+ /* for transform */
+ VecAddf(nor, nor, efa->n);
+
+ if(del_old) {
BLI_remlink(&em->faces, efa);
free_editface(efa);
}
@@ -289,9 +676,12 @@ short extrudeflag(short flag,short type)
}
efa= nextvl;
}
+
+ Normalise(nor); // for grab
+
/* for all vertices with eve->vn!=0
if eve->f1==1: make edge
- if flag!=128 : if deloud==1: remove
+ if flag!=128 : if del_old==1: remove
*/
eve= em->verts.last;
while(eve) {
@@ -299,21 +689,35 @@ short extrudeflag(short flag,short type)
if(eve->vn) {
if(eve->f1==1) addedgelist(eve, eve->vn, NULL);
else if( (eve->f & 128)==0) {
- if(deloud) {
+ if(del_old) {
BLI_remlink(&em->verts,eve);
free_editvert(eve);
eve= NULL;
}
}
}
- if(eve) eve->f&= ~128;
-
+ if(eve) {
+ if(eve->f & flag) {
+ VECCOPY(eve->no, nor);
+ }
+ eve->f &= ~128;
+ }
eve= nextve;
}
return 1;
}
+/* generic extrude */
+short extrudeflag(short flag)
+{
+ if(G.scene->selectmode & SCE_SELECT_VERTEX)
+ return extrudeflag_vert(flag);
+ else
+ return extrudeflag_edge(flag);
+
+}
+
void rotateflag(short flag, float *cent, float rotmat[][3])
{
/* all verts with (flag & 'flag') rotate */
@@ -352,32 +756,92 @@ void translateflag(short flag, float *vec)
}
}
+void adduplicateflag(int flag)
+{
+ EditMesh *em = G.editMesh;
+ /* old selection has flag 128 set, and flag 'flag' cleared
+ new selection has flag 'flag' set */
+ EditVert *eve, *v1, *v2, *v3, *v4;
+ EditEdge *eed, *newed;
+ EditFace *efa, *newfa;
+
+ EM_clear_flag_all(128);
+ EM_selectmode_set(); // paranoia check, selection now is consistant
+
+ /* vertices first */
+ for(eve= em->verts.last; eve; eve= eve->prev) {
+
+ if(eve->f & flag) {
+ v1= addvertlist(eve->co);
+
+ v1->f= eve->f;
+ eve->f-= flag;
+ eve->f|= 128;
+
+ eve->vn= v1;
+
+ /* >>>>> FIXME: Copy deformation weight ? */
+ v1->totweight = eve->totweight;
+ if (eve->totweight){
+ v1->dw = MEM_mallocN (eve->totweight * sizeof(MDeformWeight), "deformWeight");
+ memcpy (v1->dw, eve->dw, eve->totweight * sizeof(MDeformWeight));
+ }
+ else
+ v1->dw=NULL;
+ }
+ }
+
+ /* copy edges */
+ for(eed= em->edges.last; eed; eed= eed->prev) {
+ if( eed->f & flag ) {
+ v1= eed->v1->vn;
+ v2= eed->v2->vn;
+ newed= addedgelist(v1, v2, eed);
+
+ newed->f= eed->f;
+ eed->f -= flag;
+ eed->f |= 128;
+ }
+ }
+
+ /* then dupicate faces */
+ for(efa= em->faces.last; efa; efa= efa->prev) {
+ if(efa->f & flag) {
+ v1= efa->v1->vn;
+ v2= efa->v2->vn;
+ v3= efa->v3->vn;
+ if(efa->v4) v4= efa->v4->vn; else v4= NULL;
+ newfa= addfacelist(v1, v2, v3, v4, efa);
+
+ newfa->f= efa->f;
+ efa->f -= flag;
+ efa->f |= 128;
+ }
+ }
+}
void delfaceflag(int flag)
{
EditMesh *em = G.editMesh;
/* delete all faces with 'flag', including edges and loose vertices */
- /* in vertices the 'flag' is cleared */
+ /* in remaining vertices/edges 'flag' is cleared */
EditVert *eve,*nextve;
EditEdge *eed, *nexted;
EditFace *efa,*nextvl;
- eed= em->edges.first;
- while(eed) {
- eed->f= 0;
- eed= eed->next;
- }
+ for(eed= em->edges.first; eed; eed= eed->next) eed->f2= 0;
+ /* delete faces */
efa= em->faces.first;
while(efa) {
nextvl= efa->next;
- if(faceselectedAND(efa, flag)) {
+ if(efa->f & flag) {
- efa->e1->f= 1;
- efa->e2->f= 1;
- efa->e3->f= 1;
+ efa->e1->f2= 1;
+ efa->e2->f2= 1;
+ efa->e3->f2= 1;
if(efa->e4) {
- efa->e4->f= 1;
+ efa->e4->f2= 1;
}
BLI_remlink(&em->faces, efa);
@@ -385,33 +849,34 @@ void delfaceflag(int flag)
}
efa= nextvl;
}
- /* all faces with 1, 2 (3) vertices selected: make sure we keep the edges */
- efa= em->faces.first;
- while(efa) {
- efa->e1->f= 0;
- efa->e2->f= 0;
- efa->e3->f= 0;
+
+ /* all remaining faces: make sure we keep the edges */
+ for(efa= em->faces.first; efa; efa= efa->next) {
+ efa->e1->f2= 0;
+ efa->e2->f2= 0;
+ efa->e3->f2= 0;
if(efa->e4) {
- efa->e4->f= 0;
+ efa->e4->f2= 0;
}
-
- efa= efa->next;
}
- /* test all edges for vertices with 'flag', and clear */
+ /* remove tagged edges, and clear remaining ones */
eed= em->edges.first;
while(eed) {
nexted= eed->next;
- if(eed->f==1) {
+
+ if(eed->f2==1) {
remedge(eed);
free_editedge(eed);
}
- else if( (eed->v1->f & flag) || (eed->v2->f & flag) ) {
- eed->v1->f&= ~flag;
- eed->v2->f&= ~flag;
+ else {
+ eed->f &= ~flag;
+ eed->v1->f &= ~flag;
+ eed->v2->f &= ~flag;
}
eed= nexted;
}
+
/* vertices with 'flag' now are the loose ones, and will be removed */
eve= em->verts.first;
while(eve) {
@@ -547,7 +1012,7 @@ void vertexnormals(int testflip)
/* vertex normal flip-flags for shade (render) */
efa= em->faces.first;
while(efa) {
- efa->f=0;
+ efa->puno=0;
if(testflip) {
f1= efa->v1->no;
@@ -556,21 +1021,21 @@ void vertexnormals(int testflip)
fac1= efa->n[0]*f1[0] + efa->n[1]*f1[1] + efa->n[2]*f1[2];
if(fac1<0.0) {
- efa->f = ME_FLIPV1;
+ efa->puno = ME_FLIPV1;
}
fac2= efa->n[0]*f2[0] + efa->n[1]*f2[1] + efa->n[2]*f2[2];
if(fac2<0.0) {
- efa->f += ME_FLIPV2;
+ efa->puno += ME_FLIPV2;
}
fac3= efa->n[0]*f3[0] + efa->n[1]*f3[1] + efa->n[2]*f3[2];
if(fac3<0.0) {
- efa->f += ME_FLIPV3;
+ efa->puno += ME_FLIPV3;
}
if(efa->v4) {
f4= efa->v4->no;
fac4= efa->n[0]*f4[0] + efa->n[1]*f4[1] + efa->n[2]*f4[2];
if(fac4<0.0) {
- efa->f += ME_FLIPV4;
+ efa->puno += ME_FLIPV4;
}
}
}
@@ -579,9 +1044,9 @@ void vertexnormals(int testflip)
yn= fabs(efa->n[1]);
zn= fabs(efa->n[2]);
- if(zn>xn && zn>yn) efa->f += ME_PROJXY;
- else if(yn>xn && yn>zn) efa->f += ME_PROJXZ;
- else efa->f += ME_PROJYZ;
+ if(zn>xn && zn>yn) efa->puno += ME_PROJXY;
+ else if(yn>xn && yn>zn) efa->puno += ME_PROJXZ;
+ else efa->puno += ME_PROJYZ;
efa= efa->next;
}
@@ -624,7 +1089,7 @@ void flip_editnormals(void)
}
}
-
+/* does face centers too */
void recalc_editnormals(void)
{
EditMesh *em = G.editMesh;
@@ -632,37 +1097,19 @@ void recalc_editnormals(void)
efa= em->faces.first;
while(efa) {
- if(efa->v4) CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n);
- else CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n);
+ if(efa->v4) {
+ CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n);
+ CalcCent4f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
+ }
+ else {
+ CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n);
+ CalcCent3f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co);
+ }
efa= efa->next;
}
}
-int faceselectedOR(EditFace *efa, int flag)
-{
-
- if(efa->v1->f & flag) return 1;
- if(efa->v2->f & flag) return 1;
- if(efa->v3->f & flag) return 1;
- if(efa->v4 && (efa->v4->f & 1)) return 1;
- return 0;
-}
-
-int faceselectedAND(EditFace *efa, int flag)
-{
- if(efa->v1->f & flag) {
- if(efa->v2->f & flag) {
- if(efa->v3->f & flag) {
- if(efa->v4) {
- if(efa->v4->f & flag) return 1;
- }
- else return 1;
- }
- }
- }
- return 0;
-}
int compareface(EditFace *vl1, EditFace *vl2)
{