2.5
Fix for Spin & Screw Mesh edit operators. - now center and axis are RNA properties for operator - axis is drawn as Normal button in properties buttons. Fun toy!
This commit is contained in:
@@ -806,7 +806,8 @@ void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect)
|
||||
glEnable(GL_LIGHT7);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
VECCOPY(dir, (float *)but->poin);
|
||||
ui_get_but_vectorf(but, dir);
|
||||
|
||||
dir[3]= 0.0f; /* glLight needs 4 args, 0.0 is sun */
|
||||
glLightfv(GL_LIGHT7, GL_POSITION, dir);
|
||||
glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn);
|
||||
@@ -817,7 +818,12 @@ void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect)
|
||||
/* transform to button */
|
||||
glPushMatrix();
|
||||
glTranslatef(rect->xmin + 0.5f*(rect->xmax-rect->xmin), rect->ymin+ 0.5f*(rect->ymax-rect->ymin), 0.0f);
|
||||
|
||||
if( rect->xmax-rect->xmin < rect->ymax-rect->ymin)
|
||||
size= (rect->xmax-rect->xmin)/200.f;
|
||||
else
|
||||
size= (rect->ymax-rect->ymin)/200.f;
|
||||
|
||||
glScalef(size, size, size);
|
||||
|
||||
if(displist==0) {
|
||||
|
||||
@@ -366,7 +366,12 @@ void uiDefAutoButsRNA_single(const bContext *C, uiLayout *layout, PointerRNA *pt
|
||||
name= (char*)RNA_property_ui_name(prop);
|
||||
col= uiLayoutColumn(layout, 1);
|
||||
uiItemL(col, name, 0);
|
||||
uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0, 0, 0);
|
||||
|
||||
/* temp hack to show normal button for spin/screw */
|
||||
if(strcmp(name, "Axis")==0) {
|
||||
uiDefButR(uiLayoutGetBlock(layout), BUT_NORMAL, 0, name, 0, 0, 100, 100, ptr, "axis", -1, 0, 0, -1, -1, NULL);
|
||||
}
|
||||
else uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
RNA_property_collection_end(&iter);
|
||||
|
||||
@@ -846,26 +846,25 @@ void MESH_OT_extrude_repeat(wmOperatorType *ot)
|
||||
|
||||
/* ************************** spin operator ******************** */
|
||||
|
||||
static int spin_mesh(bContext *C, float *dvec, int steps, float degr, int dupli )
|
||||
|
||||
static int spin_mesh(bContext *C, wmOperator *op, float *dvec, int steps, float degr, int dupli )
|
||||
{
|
||||
Object *obedit= CTX_data_edit_object(C);
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
|
||||
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
||||
EditVert *eve,*nextve;
|
||||
float nor[3]= {0.0f, 0.0f, 0.0f};
|
||||
float *curs, si, n[3], q[4], cmat[3][3], imat[3][3], tmat[3][3];
|
||||
float si, n[3], q[4], cmat[3][3], imat[3][3], tmat[3][3];
|
||||
float cent[3], bmat[3][3];
|
||||
float phi;
|
||||
short a, ok= 1;
|
||||
|
||||
RNA_float_get_array(op->ptr, "center", cent);
|
||||
|
||||
/* imat and center and size */
|
||||
Mat3CpyMat4(bmat, obedit->obmat);
|
||||
Mat3Inv(imat,bmat);
|
||||
|
||||
curs= give_cursor(scene, v3d);
|
||||
VECCOPY(cent, curs);
|
||||
cent[0]-= obedit->obmat[3][0];
|
||||
cent[1]-= obedit->obmat[3][1];
|
||||
cent[2]-= obedit->obmat[3][2];
|
||||
@@ -875,15 +874,7 @@ static int spin_mesh(bContext *C, float *dvec, int steps, float degr, int dupli
|
||||
phi/= steps;
|
||||
if(scene->toolsettings->editbutflag & B_CLOCKWISE) phi= -phi;
|
||||
|
||||
if(dvec) {
|
||||
n[0]= rv3d->viewinv[1][0];
|
||||
n[1]= rv3d->viewinv[1][1];
|
||||
n[2]= rv3d->viewinv[1][2];
|
||||
} else {
|
||||
n[0]= rv3d->viewinv[2][0];
|
||||
n[1]= rv3d->viewinv[2][1];
|
||||
n[2]= rv3d->viewinv[2][2];
|
||||
}
|
||||
RNA_float_get_array(op->ptr, "axis", n);
|
||||
Normalize(n);
|
||||
|
||||
q[0]= (float)cos(phi);
|
||||
@@ -945,7 +936,7 @@ static int spin_mesh_exec(bContext *C, wmOperator *op)
|
||||
|
||||
WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
|
||||
|
||||
ok= spin_mesh(C, NULL, RNA_int_get(op->ptr,"steps"), RNA_float_get(op->ptr,"degrees"), RNA_boolean_get(op->ptr,"dupli"));
|
||||
ok= spin_mesh(C, op, NULL, RNA_int_get(op->ptr,"steps"), RNA_float_get(op->ptr,"degrees"), RNA_boolean_get(op->ptr,"dupli"));
|
||||
if(ok==0) {
|
||||
BKE_report(op->reports, RPT_ERROR, "No valid vertices are selected");
|
||||
return OPERATOR_CANCELLED;
|
||||
@@ -953,6 +944,19 @@ static int spin_mesh_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
/* get center and axis, in global coords */
|
||||
static int spin_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
||||
|
||||
RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
|
||||
RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]);
|
||||
|
||||
return spin_mesh_exec(C, op);
|
||||
}
|
||||
|
||||
void MESH_OT_spin(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
@@ -960,16 +964,21 @@ void MESH_OT_spin(wmOperatorType *ot)
|
||||
ot->idname= "MESH_OT_spin";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke= spin_mesh_invoke;
|
||||
ot->exec= spin_mesh_exec;
|
||||
ot->poll= ED_operator_editmesh;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
|
||||
/*props */
|
||||
/* props */
|
||||
RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX);
|
||||
RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates");
|
||||
RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f);
|
||||
|
||||
RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
|
||||
RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
|
||||
|
||||
}
|
||||
|
||||
static int screw_mesh_exec(bContext *C, wmOperator *op)
|
||||
@@ -1028,7 +1037,7 @@ static int screw_mesh_exec(bContext *C, wmOperator *op)
|
||||
dvec[2]= -dvec[2];
|
||||
}
|
||||
|
||||
if(spin_mesh(C, dvec, turns*steps, 360.0f*turns, 0)) {
|
||||
if(spin_mesh(C, op, dvec, turns*steps, 360.0f*turns, 0)) {
|
||||
WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
|
||||
BKE_mesh_end_editmesh(obedit->data, em);
|
||||
return OPERATOR_FINISHED;
|
||||
@@ -1042,6 +1051,19 @@ static int screw_mesh_exec(bContext *C, wmOperator *op)
|
||||
BKE_mesh_end_editmesh(obedit->data, em);
|
||||
}
|
||||
|
||||
/* get center and axis, in global coords */
|
||||
static int screw_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
||||
|
||||
RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
|
||||
RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]);
|
||||
|
||||
return screw_mesh_exec(C, op);
|
||||
}
|
||||
|
||||
void MESH_OT_screw(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
@@ -1049,6 +1071,7 @@ void MESH_OT_screw(wmOperatorType *ot)
|
||||
ot->idname= "MESH_OT_screw";
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke= screw_mesh_invoke;
|
||||
ot->exec= screw_mesh_exec;
|
||||
ot->poll= ED_operator_editmesh;
|
||||
|
||||
@@ -1058,6 +1081,9 @@ void MESH_OT_screw(wmOperatorType *ot)
|
||||
/*props */
|
||||
RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256);
|
||||
RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256);
|
||||
|
||||
RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
|
||||
RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
|
||||
}
|
||||
|
||||
static void erase_edges(EditMesh *em, ListBase *l)
|
||||
|
||||
Reference in New Issue
Block a user