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:
authorGeoffrey Bantle <hairbat@yahoo.com>2008-02-24 01:11:16 +0300
committerGeoffrey Bantle <hairbat@yahoo.com>2008-02-24 01:11:16 +0300
commite03ab146ae673ec296e97f3c146c048417833521 (patch)
tree24e5d7445c6ce151fb95f4252f23319165dacd23 /source/blender/src
parent40934ef6df34a70f2275f1208d9433830e9ccf8f (diff)
-> Bevel tools and Bmesh kernel
The following is a commit of Levi Schooley's bevel code and the bmesh library it depends on. The current editmode bevel has been replaced with a new per edge bevel function. Vertex beveling is also availible. To set weights for the modifier to use, use the ctrl-shift-e shortcut on either edges or vertices. Recursive beveling is turned of for the time being.
Diffstat (limited to 'source/blender/src')
-rw-r--r--source/blender/src/buttons_editing.c75
-rw-r--r--source/blender/src/drawobject.c38
-rw-r--r--source/blender/src/editmesh.c26
-rw-r--r--source/blender/src/editmesh_tools.c50
-rw-r--r--source/blender/src/header_view3d.c10
-rw-r--r--source/blender/src/space.c12
-rw-r--r--source/blender/src/transform.c206
7 files changed, 404 insertions, 13 deletions
diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c
index e35cc6a04a9..be6b872774e 100644
--- a/source/blender/src/buttons_editing.c
+++ b/source/blender/src/buttons_editing.c
@@ -96,6 +96,7 @@
#include "BKE_packedFile.h"
#include "BKE_particle.h"
#include "BKE_scene.h"
+#include "BKE_bmesh.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
@@ -1752,6 +1753,10 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
height = 86;
} else if (md->type==eModifierType_Mirror) {
height = 86;
+ } else if (md->type==eModifierType_Bevel) {
+ BevelModifierData *bmd = (BevelModifierData*) md;
+ height = 105; /* height = 124; */
+ if ((bmd->lim_flags & BME_BEVEL_ANGLE) || ((bmd->lim_flags & BME_BEVEL_WEIGHT) && !(bmd->flags & BME_BEVEL_VERT))) height += 19;
} else if (md->type==eModifierType_EdgeSplit) {
EdgeSplitModifierData *emd = (EdgeSplitModifierData*) md;
height = 48;
@@ -1895,7 +1900,62 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
"Ob: ", lx, (cy -= 19), buttonWidth, 19,
&mmd->mirror_ob,
"Object to use as mirror");
-
+ } else if (md->type==eModifierType_Bevel) {
+ BevelModifierData *bmd = (BevelModifierData*) md;
+ /*uiDefButS(block, ROW, B_MODIFIER_RECALC, "Distance",
+ lx, (cy -= 19), (buttonWidth/2), 19, &bmd->val_flags,
+ 11.0, 0, 0, 0,
+ "Interpret bevel value as a constant distance from each edge");
+ uiDefButS(block, ROW, B_MODIFIER_RECALC, "Radius",
+ (lx+buttonWidth/2), cy, (buttonWidth - buttonWidth/2), 19, &bmd->val_flags,
+ 11.0, BME_BEVEL_RADIUS, 0, 0,
+ "Interpret bevel value as a radius - smaller angles will be beveled more");*/
+ uiDefButF(block, NUM, B_MODIFIER_RECALC, "Dis",
+ lx, (cy -= 19), buttonWidth, 19, &bmd->value,
+ 0.0, 0.5, 5, 2,
+ "Bevel value/amount");
+ /*uiDefButI(block, NUM, B_MODIFIER_RECALC, "Recurs",
+ lx, (cy -= 19), buttonWidth, 19, &bmd->res,
+ 1, 4, 5, 2,
+ "Number of times to bevel");*/
+ uiDefButBitS(block, TOG, BME_BEVEL_VERT,
+ B_MODIFIER_RECALC, "Verts only",
+ lx, (cy -= 19), buttonWidth, 19,
+ &bmd->flags, 0, 0, 0, 0,
+ "Bevel only verts/corners; not edges");
+ uiDefBut(block, LABEL, 1, "Limit using:", lx, (cy-=19), buttonWidth,19, NULL, 0.0, 0.0, 0, 0, "");
+ uiDefButS(block, ROW, B_MODIFIER_RECALC, "None",
+ lx, (cy -= 19), (buttonWidth/3), 19, &bmd->lim_flags,
+ 12.0, 0, 0, 0,
+ "Bevel the entire mesh by a constant amount");
+ uiDefButS(block, ROW, B_MODIFIER_RECALC, "Angle",
+ (lx+buttonWidth/3), cy, (buttonWidth/3), 19, &bmd->lim_flags,
+ 12.0, BME_BEVEL_ANGLE, 0, 0,
+ "Only bevel edges with sharp enough angles between faces");
+ uiDefButS(block, ROW, B_MODIFIER_RECALC, "BevWeight",
+ lx+(2*buttonWidth/3), cy, buttonWidth-2*(buttonWidth/3), 19, &bmd->lim_flags,
+ 12.0, BME_BEVEL_WEIGHT, 0, 0,
+ "Use bevel weights to determine how much bevel is applied; apply them separately in vert/edge select mode");
+ if ((bmd->lim_flags & BME_BEVEL_WEIGHT) && !(bmd->flags & BME_BEVEL_VERT)) {
+ uiDefButS(block, ROW, B_MODIFIER_RECALC, "Min",
+ lx, (cy -= 19), (buttonWidth/3), 19, &bmd->e_flags,
+ 13.0, BME_BEVEL_EMIN, 0, 0,
+ "The sharpest edge's weight is used when weighting a vert");
+ uiDefButS(block, ROW, B_MODIFIER_RECALC, "Average",
+ (lx+buttonWidth/3), cy, (buttonWidth/3), 19, &bmd->e_flags,
+ 13.0, 0, 0, 0,
+ "The edge weights are averaged when weighting a vert");
+ uiDefButS(block, ROW, B_MODIFIER_RECALC, "Max",
+ (lx+2*(buttonWidth/3)), cy, buttonWidth-2*(buttonWidth/3), 19, &bmd->e_flags,
+ 13.0, BME_BEVEL_EMAX, 0, 0,
+ "The largest edge's wieght is used when weighting a vert");
+ }
+ else if (bmd->lim_flags & BME_BEVEL_ANGLE) {
+ uiDefButF(block, NUM, B_MODIFIER_RECALC, "Angle:",
+ lx, (cy -= 19), buttonWidth, 19, &bmd->bevel_angle,
+ 0.0, 180.0, 100, 2,
+ "Angle above which to bevel edges");
+ }
} else if (md->type==eModifierType_EdgeSplit) {
EdgeSplitModifierData *emd = (EdgeSplitModifierData*) md;
uiDefButBitI(block, TOG, MOD_EDGESPLIT_FROMANGLE,
@@ -4788,6 +4848,10 @@ void do_meshbuts(unsigned short event)
allqueue(REDRAWBUTSEDIT, 0);
allqueue(REDRAWVIEW3D, 0);
break;
+ //~ case B_DRAWBWEIGHTS:
+ //~ allqueue(REDRAWBUTSEDIT, 0);
+ //~ allqueue(REDRAWVIEW3D, 0);
+ //~ break;
case B_JOINTRIA:
join_triangles();
break;
@@ -4966,10 +5030,11 @@ static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
uiBlockBeginAlign(block);
uiDefButBitI(block, TOG, G_DRAWFACES, REDRAWVIEW3D_IMAGE, "Draw Faces", 955,88,150,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades in the 3d view and UV editor");
- uiDefButBitI(block, TOG, G_DRAWEDGES, REDRAWVIEW3D, "Draw Edges", 955,66,150,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
- uiDefButBitI(block, TOG, G_DRAWCREASES, REDRAWVIEW3D, "Draw Creases", 955,44,150,19, &G.f, 0, 0, 0, 0, "Displays creases created for subsurf weighting");
- uiDefButBitI(block, TOG, G_DRAWSEAMS, REDRAWVIEW3D, "Draw Seams", 955,22,150,19, &G.f, 0, 0, 0, 0, "Displays UV unwrapping seams");
- uiDefButBitI(block, TOG, G_DRAWSHARP, REDRAWVIEW3D, "Draw Sharp", 955,0,150,19, &G.f, 0, 0, 0, 0, "Displays sharp edges, used with the EdgeSplit modifier");
+ uiDefButBitI(block, TOG, G_DRAWEDGES, REDRAWVIEW3D, "Draw Edges", 955, 66,150,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
+ uiDefButBitI(block, TOG, G_DRAWCREASES, REDRAWVIEW3D, "Draw Creases", 955, 42,150,19, &G.f, 0, 0, 0, 0, "Displays creases created for subsurf weighting");
+ uiDefButBitI(block, TOG, G_DRAWBWEIGHTS, REDRAWVIEW3D, "Draw Bevel Weights", 955, 20,150,19, &G.f, 0, 0, 0, 0, "Displays weights created for the Bevel modifier");
+ uiDefButBitI(block, TOG, G_DRAWSEAMS, REDRAWVIEW3D, "Draw Seams", 955, -2,150,19, &G.f, 0, 0, 0, 0, "Displays UV unwrapping seams");
+ uiDefButBitI(block, TOG, G_DRAWSHARP, REDRAWVIEW3D, "Draw Sharp", 955, -24,150,19, &G.f, 0, 0, 0, 0, "Displays sharp edges, used with the EdgeSplit modifier");
uiBlockEndAlign(block);
/* Measurement drawing options */
diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c
index 6edb89a1049..6375af4d49e 100644
--- a/source/blender/src/drawobject.c
+++ b/source/blender/src/drawobject.c
@@ -1660,6 +1660,41 @@ static void draw_dm_creases(DerivedMesh *dm)
glLineWidth(1.0);
}
+static int draw_dm_bweights__setDrawOptions(void *userData, int index)
+{
+ EditEdge *eed = EM_get_edge_for_index(index);
+
+ if (eed->h==0 && eed->bweight!=0.0) {
+ BIF_ThemeColorBlend(TH_WIRE, TH_EDGE_SELECT, eed->bweight);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+static void draw_dm_bweights__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
+{
+ EditVert *eve = EM_get_vert_for_index(index);
+
+ if (eve->h==0 && eve->bweight!=0.0) {
+ BIF_ThemeColorBlend(TH_VERTEX, TH_VERTEX_SELECT, eve->bweight);
+ bglVertex3fv(co);
+ }
+}
+static void draw_dm_bweights(DerivedMesh *dm)
+{
+ if (G.scene->selectmode & SCE_SELECT_VERTEX) {
+ glPointSize(BIF_GetThemeValuef(TH_VERTEX_SIZE) + 2);
+ bglBegin(GL_POINTS);
+ dm->foreachMappedVert(dm, draw_dm_bweights__mapFunc, NULL);
+ bglEnd();
+ }
+ else {
+ glLineWidth(3.0);
+ dm->drawMappedEdges(dm, draw_dm_bweights__setDrawOptions, NULL);
+ glLineWidth(1.0);
+ }
+}
+
/* Second section of routines: Combine first sets to form fancy
* drawing routines (for example rendering twice to get overlays).
*
@@ -2139,6 +2174,9 @@ static void draw_em_fancy(Object *ob, EditMesh *em, DerivedMesh *cageDM, Derived
if(G.f & G_DRAWCREASES) {
draw_dm_creases(cageDM);
}
+ if(G.f & G_DRAWBWEIGHTS) {
+ draw_dm_bweights(cageDM);
+ }
draw_em_fancy_edges(cageDM, 0, eed_act);
}
diff --git a/source/blender/src/editmesh.c b/source/blender/src/editmesh.c
index de4bcda157f..acb4134a040 100644
--- a/source/blender/src/editmesh.c
+++ b/source/blender/src/editmesh.c
@@ -163,10 +163,13 @@ EditVert *addvertlist(float *vec, EditVert *example)
createVerseVert(eve);
#endif
- if(example)
+ if(example) {
CustomData_em_copy_data(&em->vdata, &em->vdata, example->data, &eve->data);
- else
+ eve->bweight = example->bweight;
+ }
+ else {
CustomData_em_set_default(&em->vdata, &eve->data);
+ }
return eve;
}
@@ -299,6 +302,7 @@ EditEdge *addedgelist(EditVert *v1, EditVert *v2, EditEdge *example)
rule is to do this with addedgelist call, before addfacelist */
if(example) {
eed->crease= example->crease;
+ eed->bweight= example->bweight;
eed->sharp = example->sharp;
eed->seam = example->seam;
eed->h |= (example->h & EM_FGON);
@@ -896,6 +900,8 @@ void make_editMesh()
eve->no[1]= mvert->no[1]/32767.0;
eve->no[2]= mvert->no[2]/32767.0;
+ eve->bweight= ((float)mvert->bweight)/255.0f;
+
/* lets overwrite the keyindex of the editvert
* with the order it used to be in before
* editmode
@@ -915,7 +921,8 @@ void make_editMesh()
eed= addedgelist(evlist[medge->v1], evlist[medge->v2], NULL);
/* eed can be zero when v1 and v2 are identical, dxf import does this... */
if(eed) {
- eed->crease= ((float)medge->crease)/255.0;
+ eed->crease= ((float)medge->crease)/255.0f;
+ eed->bweight= ((float)medge->bweight)/255.0f;
if(medge->flag & ME_SEAM) eed->seam= 1;
if(medge->flag & ME_SHARP) eed->sharp = 1;
@@ -1153,7 +1160,8 @@ void load_editMesh(void)
mvert->flag= 0;
if(eve->f1==1) mvert->flag |= ME_SPHERETEST;
mvert->flag |= (eve->f & SELECT);
- if (eve->h) mvert->flag |= ME_HIDE;
+ if (eve->h) mvert->flag |= ME_HIDE;
+ mvert->bweight= (char)(255.0*eve->bweight);
#ifdef WITH_VERSE
if(eve->vvert) {
@@ -1205,6 +1213,7 @@ void load_editMesh(void)
if(eed->h & 1) medge->flag |= ME_HIDE;
medge->crease= (char)(255.0*eed->crease);
+ medge->bweight= (char)(255.0*eed->bweight);
CustomData_from_em_block(&em->edata, &me->edata, eed->data, a);
eed->tmp.l = a++;
@@ -1926,6 +1935,7 @@ typedef struct EditVertC
float no[3];
float co[3];
unsigned char f, h;
+ short bweight;
int keyindex;
} EditVertC;
@@ -1933,7 +1943,7 @@ typedef struct EditEdgeC
{
int v1, v2;
unsigned char f, h, seam, sharp, pad;
- short crease, fgoni;
+ short crease, bweight, fgoni;
} EditEdgeC;
typedef struct EditFaceC
@@ -2034,6 +2044,7 @@ static void *editMesh_to_undoMesh(void)
evec->h= eve->h;
evec->keyindex= eve->keyindex;
eve->tmp.l = a; /*store index*/
+ evec->bweight= (short)(eve->bweight*255.0);
CustomData_from_em_block(&em->vdata, &um->vdata, eve->data, a);
}
@@ -2048,6 +2059,7 @@ static void *editMesh_to_undoMesh(void)
eedc->seam= eed->seam;
eedc->sharp= eed->sharp;
eedc->crease= (short)(eed->crease*255.0);
+ eedc->bweight= (short)(eed->bweight*255.0);
eedc->fgoni= eed->fgoni;
eed->tmp.l = a; /*store index*/
CustomData_from_em_block(&em->edata, &um->edata, eed->data, a);
@@ -2161,6 +2173,7 @@ static void undoMesh_to_editMesh(void *umv)
eve->f= evec->f;
eve->h= evec->h;
eve->keyindex= evec->keyindex;
+ eve->bweight= ((float)evec->bweight)/255.0f;
CustomData_to_em_block(&um->vdata, &em->vdata, a, &eve->data);
}
@@ -2174,7 +2187,8 @@ static void undoMesh_to_editMesh(void *umv)
eed->seam= eedc->seam;
eed->sharp= eedc->sharp;
eed->fgoni= eedc->fgoni;
- eed->crease= ((float)eedc->crease)/255.0;
+ eed->crease= ((float)eedc->crease)/255.0f;
+ eed->bweight= ((float)eedc->bweight)/255.0f;
CustomData_to_em_block(&um->edata, &em->edata, a, &eed->data);
}
diff --git a/source/blender/src/editmesh_tools.c b/source/blender/src/editmesh_tools.c
index 14b8fe39d45..a20327dcfac 100644
--- a/source/blender/src/editmesh_tools.c
+++ b/source/blender/src/editmesh_tools.c
@@ -73,6 +73,7 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include "BKE_mesh.h"
#include "BKE_object.h"
#include "BKE_utildefines.h"
+#include "BKE_bmesh.h"
#ifdef WITH_VERSE
#include "BKE_verse.h"
@@ -90,6 +91,7 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include "BIF_resources.h"
#include "BIF_toolbox.h"
#include "BIF_transform.h"
+#include "transform.h"
#ifdef WITH_VERSE
#include "BIF_verse.h"
@@ -3707,6 +3709,7 @@ static void edge_rotate(EditEdge *eed,int dir)
srchedge->dir = eed->dir;
srchedge->seam = eed->seam;
srchedge->crease = eed->crease;
+ srchedge->bweight = eed->bweight;
}
}
@@ -4476,7 +4479,52 @@ static void bevel_mesh_recurs(float bsize, short recurs, int allfaces)
}
}
-void bevel_menu()
+void bevel_menu() {
+ BME_Mesh *bm;
+ BME_TransData_Head *td;
+ TransInfo *t;
+ int options, res, gbm_free = 0;
+
+ t = BIF_GetTransInfo();
+ if (!G.editBMesh) {
+ G.editBMesh = MEM_callocN(sizeof(*(G.editBMesh)),"bevel_menu() G.editBMesh");
+ gbm_free = 1;
+ }
+
+ G.editBMesh->options = BME_BEVEL_RUNNING | BME_BEVEL_SELECT;
+ G.editBMesh->res = 1;
+
+ while(G.editBMesh->options & BME_BEVEL_RUNNING) {
+ options = G.editBMesh->options;
+ res = G.editBMesh->res;
+ bm = BME_make_mesh();
+ bm = BME_editmesh_to_bmesh(G.editMesh, bm);
+ BIF_undo_push("Pre-Bevel");
+ free_editMesh(G.editMesh);
+ BME_bevel(bm,0.1f,res,options,0,0,&td);
+ BME_bmesh_to_editmesh(bm, td);
+ G.editBMesh->bm = bm;
+ G.editBMesh->td = td;
+ initTransform(TFM_BEVEL,CTX_BMESH);
+ Transform();
+ BME_free_transdata(td);
+ BME_free_mesh(bm);
+ if (t->state != TRANS_CONFIRM) {
+ BIF_undo();
+ }
+ if (options == G.editBMesh->options) {
+ G.editBMesh->options &= ~BME_BEVEL_RUNNING;
+ }
+ }
+
+ if (gbm_free) {
+ MEM_freeN(G.editBMesh);
+ G.editBMesh = NULL;
+ }
+}
+
+
+void bevel_menu_old()
{
char Finished = 0, Canceled = 0, str[100], Recalc = 0;
short mval[2], oval[2], curval[2], event = 0, recurs = 1, nr;
diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c
index 34169b428cd..7f9a2d02d83 100644
--- a/source/blender/src/header_view3d.c
+++ b/source/blender/src/header_view3d.c
@@ -2688,7 +2688,7 @@ void do_view3d_edit_mesh_edgesmenu(void *arg, int event)
case 8: /* Clear Seam */
editmesh_mark_seam(1);
break;
- case 9: /* Cease SubSurf */
+ case 9: /* Crease SubSurf */
if(!multires_level1_test()) {
initTransform(TFM_CREASE, CTX_EDGE);
Transform();
@@ -2720,6 +2720,12 @@ void do_view3d_edit_mesh_edgesmenu(void *arg, int event)
BIF_undo_push("Clear Sharp");
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
break;
+ case 17: /* Adjust Bevel Weight */
+ if(!multires_level1_test()) {
+ initTransform(TFM_BWEIGHT, CTX_EDGE);
+ Transform();
+ }
+ break;
}
allqueue(REDRAWVIEW3D, 0);
}
@@ -2756,6 +2762,8 @@ static uiBlock *view3d_edit_mesh_edgesmenu(void *arg_unused)
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Mark Sharp|Ctrl E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear Sharp|Ctrl E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 16, "");
+ uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Adjust Bevel Weight|Ctrl Shift E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 17, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Crease SubSurf|Shift E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
diff --git a/source/blender/src/space.c b/source/blender/src/space.c
index 1994a2fcb7f..6dacf38c544 100644
--- a/source/blender/src/space.c
+++ b/source/blender/src/space.c
@@ -1896,6 +1896,18 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
extrude_armature(1);
}
}
+ else if (G.qual == (LR_CTRLKEY|LR_SHIFTKEY)) {
+ if (G.obedit && G.obedit->type==OB_MESH &&
+ !multires_level1_test()) {
+ if (G.scene->selectmode & SCE_SELECT_VERTEX) {
+ initTransform(TFM_BWEIGHT, CTX_NONE);
+ }
+ else {
+ initTransform(TFM_BWEIGHT, CTX_EDGE);
+ }
+ Transform();
+ }
+ }
break;
case FKEY:
if(G.obedit) {
diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c
index 87ca52dcfad..72d4c418b80 100644
--- a/source/blender/src/transform.c
+++ b/source/blender/src/transform.c
@@ -84,6 +84,7 @@
#include "BKE_utildefines.h"
#include "BKE_bad_level_calls.h"/* popmenu and error */
#include "BKE_particle.h"
+#include "BKE_bmesh.h"
#include "BSE_drawipo.h"
#include "BSE_editnla_types.h" /* for NLAWIDTH */
@@ -576,6 +577,10 @@ static char *transform_to_undostr(TransInfo *t)
return "Trackball";
case TFM_PUSHPULL:
return "Push/Pull";
+ case TFM_BEVEL:
+ return "Bevel";
+ case TFM_BWEIGHT:
+ return "Bevel Weight";
case TFM_CREASE:
return "Crease";
case TFM_BONESIZE:
@@ -1030,6 +1035,12 @@ void initTransform(int mode, int context) {
case TFM_MIRROR:
initMirror(&Trans);
break;
+ case TFM_BEVEL:
+ initBevel(&Trans);
+ break;
+ case TFM_BWEIGHT:
+ initBevelWeight(&Trans);
+ break;
}
}
@@ -3232,6 +3243,201 @@ int PushPull(TransInfo *t, short mval[2])
return 1;
}
+/* ************************** BEVEL **************************** */
+
+void initBevel(TransInfo *t)
+{
+ t->mode = TFM_BEVEL;
+ t->flag |= T_NO_CONSTRAINT;
+ t->transform = Bevel;
+ t->handleEvent = handleEventBevel;
+ if (G.editBMesh->imval[0] == 0 && G.editBMesh->imval[1] == 0) {
+ /* save the initial mouse co */
+ G.editBMesh->imval[0] = t->imval[0];
+ G.editBMesh->imval[1] = t->imval[1];
+ }
+ else {
+ /* restore the mouse co from a previous call to initTransform() */
+ t->imval[0] = G.editBMesh->imval[0];
+ t->imval[1] = G.editBMesh->imval[1];
+ }
+}
+
+int handleEventBevel(TransInfo *t, unsigned short event, short val)
+{
+ if (val) {
+ switch (event) {
+ case MIDDLEMOUSE:
+ G.editBMesh->options ^= BME_BEVEL_VERT;
+ t->state = TRANS_CANCEL;
+ return 1;
+ //case PADPLUSKEY:
+ // G.editBMesh->options ^= BME_BEVEL_RES;
+ // G.editBMesh->res += 1;
+ // if (G.editBMesh->res > 4) {
+ // G.editBMesh->res = 4;
+ // }
+ // t->state = TRANS_CANCEL;
+ // return 1;
+ //case PADMINUS:
+ // G.editBMesh->options ^= BME_BEVEL_RES;
+ // G.editBMesh->res -= 1;
+ // if (G.editBMesh->res < 0) {
+ // G.editBMesh->res = 0;
+ // }
+ // t->state = TRANS_CANCEL;
+ // return 1;
+ default:
+ return 0;
+ }
+ }
+ return 0;
+}
+
+int Bevel(TransInfo *t, short mval[2])
+{
+ float distance,d;
+ int i;
+ char str[128];
+ char *mode;
+ TransData *td = t->data;
+
+ mode = (G.editBMesh->options & BME_BEVEL_VERT) ? "verts only" : "normal";
+ distance = InputHorizontalAbsolute(t, mval)/4; /* 4 just seemed a nice value to me, nothing special */
+
+ applyNumInput(&t->num, &distance);
+
+ /* header print for NumInput */
+ if (hasNumInput(&t->num)) {
+ char c[20];
+
+ outputNumInput(&(t->num), c);
+
+ sprintf(str, "Bevel: %s", c);
+ }
+ else {
+ /* default header print */
+ sprintf(str, "Bevel - Dist: %.4f, Mode: %s (MMB to toggle))", distance, mode);
+ }
+
+ if (distance < 0) distance = -distance;
+ for(i = 0 ; i < t->total; i++, td++) {
+ if (td->axismtx[1][0] > 0 && distance > td->axismtx[1][0]) {
+ d = td->axismtx[1][0];
+ }
+ else {
+ d = distance;
+ }
+ VECADDFAC(td->loc,td->center,td->axismtx[0],(*td->val)*d);
+ }
+
+ recalcData(t);
+
+ headerprint(str);
+
+ viewRedrawForce(t);
+
+ return 1;
+}
+
+/* ************************** BEVEL WEIGHT *************************** */
+
+void initBevelWeight(TransInfo *t)
+{
+ t->mode = TFM_BWEIGHT;
+ t->transform = BevelWeight;
+
+ t->idx_max = 0;
+ t->num.idx_max = 0;
+ t->snap[0] = 0.0f;
+ t->snap[1] = 0.1f;
+ t->snap[2] = t->snap[1] * 0.1f;
+
+ t->flag |= T_NO_CONSTRAINT;
+
+ t->fac = (float)sqrt(
+ (
+ ((float)(t->center2d[1] - t->imval[1]))*((float)(t->center2d[1] - t->imval[1]))
+ +
+ ((float)(t->center2d[0] - t->imval[0]))*((float)(t->center2d[0] - t->imval[0]))
+ ) );
+
+ if(t->fac==0.0f) t->fac= 1.0f; // prevent Inf
+}
+
+int BevelWeight(TransInfo *t, short mval[2])
+{
+ TransData *td = t->data;
+ float weight;
+ int i;
+ char str[50];
+
+
+ if(t->flag & T_SHIFT_MOD) {
+ /* calculate ratio for shiftkey pos, and for total, and blend these for precision */
+ float dx= (float)(t->center2d[0] - t->shiftmval[0]);
+ float dy= (float)(t->center2d[1] - t->shiftmval[1]);
+ weight = (float)sqrt( dx*dx + dy*dy)/t->fac;
+
+ dx= (float)(t->center2d[0] - mval[0]);
+ dy= (float)(t->center2d[1] - mval[1]);
+ weight+= 0.1f*(float)(sqrt( dx*dx + dy*dy)/t->fac -weight);
+
+ }
+ else {
+ float dx= (float)(t->center2d[0] - mval[0]);
+ float dy= (float)(t->center2d[1] - mval[1]);
+ weight = (float)sqrt( dx*dx + dy*dy)/t->fac;
+ }
+
+ weight -= 1.0f;
+ if (weight > 1.0f) weight = 1.0f;
+
+ snapGrid(t, &weight);
+
+ applyNumInput(&t->num, &weight);
+
+ /* header print for NumInput */
+ if (hasNumInput(&t->num)) {
+ char c[20];
+
+ outputNumInput(&(t->num), c);
+
+ if (weight >= 0.0f)
+ sprintf(str, "Bevel Weight: +%s %s", c, t->proptext);
+ else
+ sprintf(str, "Bevel Weight: %s %s", c, t->proptext);
+ }
+ else {
+ /* default header print */
+ if (weight >= 0.0f)
+ sprintf(str, "Bevel Weight: +%.3f %s", weight, t->proptext);
+ else
+ sprintf(str, "Bevel Weight: %.3f %s", weight, t->proptext);
+ }
+
+ for(i = 0 ; i < t->total; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->val) {
+ *td->val = td->ival + weight * td->factor;
+ if (*td->val < 0.0f) *td->val = 0.0f;
+ if (*td->val > 1.0f) *td->val = 1.0f;
+ }
+ }
+
+ recalcData(t);
+
+ headerprint(str);
+
+ viewRedrawForce(t);
+
+ helpline (t, t->center);
+
+ return 1;
+}
+
/* ************************** CREASE *************************** */
void initCrease(TransInfo *t)