From 707220b150d57ce89dae8c0413b5d5f1fc580dd2 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 14 Jun 2010 02:03:01 +0000 Subject: gpencil simplified filtering, unbiased smoothing, and pen eraser that works --- source/blender/editors/gpencil/gpencil_paint.c | 89 ++++++++++++++------------ 1 file changed, 49 insertions(+), 40 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index e06722c1af1..544d87333d8 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -184,25 +184,22 @@ static void gp_get_3d_reference (tGPsdata *p, float *vec) /* check if the current mouse position is suitable for adding a new point */ static short gp_stroke_filtermval (tGPsdata *p, int mval[2], int pmval[2]) { - int dx= abs(mval[0] - pmval[0]); - int dy= abs(mval[1] - pmval[1]); - /* if buffer is empty, just let this go through (i.e. so that dots will work) */ if (p->gpd->sbuffer_size == 0) return 1; + else { + /* check if the distance since the last point is significant enough + no need for abs() or sqrt(), and don't bother checking Manhattan distance (ok?) */ + + int dx= mval[0] - pmval[0]; + int dy= mval[1] - pmval[1]; - /* check if mouse moved at least certain distance on both axes (best case) */ - else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) - return 1; - - /* check if the distance since the last point is significant enough */ - // future optimisation: sqrt here may be too slow? - else if (sqrt(dx*dx + dy*dy) > MIN_EUCLIDEAN_PX) - return 1; - - /* mouse 'didn't move' */ - else - return 0; + if ((dx*dx + dy*dy) > (MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX)) + return 1; + } + + /* pencil 'didn't move' if we make it this far */ + return 0; } /* convert screen-coordinates to buffer-coordinates */ @@ -349,30 +346,44 @@ static short gp_stroke_addpoint (tGPsdata *p, int mval[2], float pressure) /* smooth a stroke (in buffer) before storing it */ static void gp_stroke_smooth (tGPsdata *p) { - bGPdata *gpd= p->gpd; - int i=0, cmx=gpd->sbuffer_size; - /* only smooth if smoothing is enabled, and we're not doing a straight line */ if (!(U.gp_settings & GP_PAINT_DOSMOOTH) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)) return; - - /* don't try if less than 2 points in buffer */ - if ((cmx <= 2) || (gpd->sbuffer == NULL)) - return; - - /* apply weighting-average (note doing this along path sequentially does introduce slight error) */ - for (i=0; i < gpd->sbuffer_size; i++) { - tGPspoint *pc= (((tGPspoint *)gpd->sbuffer) + i); - tGPspoint *pb= (i-1 > 0)?(pc-1):(pc); - tGPspoint *pa= (i-2 > 0)?(pc-2):(pb); - tGPspoint *pd= (i+1 < cmx)?(pc+1):(pc); - tGPspoint *pe= (i+2 < cmx)?(pc+2):(pd); + else { + bGPdata *gpd= p->gpd; + int num_points=gpd->sbuffer_size; - pc->x= (short)(0.1*pa->x + 0.2*pb->x + 0.4*pc->x + 0.2*pd->x + 0.1*pe->x); - pc->y= (short)(0.1*pa->y + 0.2*pb->y + 0.4*pc->y + 0.2*pd->y + 0.1*pe->y); + /* don't try if less than 5 points in buffer */ + if ((num_points <= 5) || (gpd->sbuffer == NULL)) + return; + else { + /* apply weighting-average (avoiding errors from sequential processing) */ + + tGPspoint *begin = (tGPspoint*)gpd->sbuffer + 2; + tGPspoint *end = (tGPspoint*)gpd->sbuffer + num_points - 2; + + tGPspoint orig_a = *(begin - 2); + tGPspoint orig_b = *(begin - 1); + + tGPspoint *c = begin; + tGPspoint *d = begin + 1; + tGPspoint *e = begin + 2; + + + for (; c < end; ++c, ++d, ++e) { + tGPspoint orig_c = *c; + + c->x= (short)(0.1*orig_a.x + 0.2*orig_b.x + 0.4*orig_c.x + 0.2*d->x + 0.1*e->x); + c->y= (short)(0.1*orig_a.y + 0.2*orig_b.y + 0.4*orig_c.y + 0.2*d->y + 0.1*e->y); + + orig_a = orig_b; + orig_b = orig_c; + } + } } } + /* simplify a stroke (in buffer) before storing it * - applies a reverse Chaikin filter * - code adapted from etch-a-ton branch (editarmature_sketch.c) @@ -385,12 +396,12 @@ static void gp_stroke_simplify (tGPsdata *p) short flag= gpd->sbuffer_sflag; short i, j; - /* only simplify if simlification is enabled, and we're not doing a straight line */ + /* only simplify if simplification is enabled, and we're not doing a straight line */ if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)) return; /* don't simplify if less than 4 points in buffer */ - if ((num_points <= 2) || (old_points == NULL)) + if ((num_points < 4) || (old_points == NULL)) return; /* clear buffer (but don't free mem yet) so that we can write to it @@ -1283,8 +1294,10 @@ static void gpencil_draw_apply_event (bContext *C, wmOperator *op, wmEvent *even tablet= (wmtab->Active != EVT_TABLET_NONE); p->pressure= wmtab->Pressure; - //if (wmtab->Active == EVT_TABLET_ERASER) + if (wmtab->Active == EVT_TABLET_ERASER) // TODO... this should get caught by the keymaps which call drawing in the first place + // .. but until that's possible, duct tape the eraser function back on + p->paintmode = GP_PAINTMODE_ERASER; } else p->pressure= 1.0f; @@ -1515,8 +1528,6 @@ static EnumPropertyItem prop_gpencil_drawmodes[] = { void GPENCIL_OT_draw (wmOperatorType *ot) { - PropertyRNA *prop; - /* identifiers */ ot->name= "Grease Pencil Draw"; ot->idname= "GPENCIL_OT_draw"; @@ -1533,8 +1544,6 @@ void GPENCIL_OT_draw (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; /* settings for drawing */ - prop= RNA_def_enum(ot->srna, "mode", prop_gpencil_drawmodes, 0, "Mode", "Way to intepret mouse movements."); - RNA_def_property_flag(prop, PROP_HIDDEN); - + RNA_def_enum(ot->srna, "mode", prop_gpencil_drawmodes, 0, "Mode", "Way to intepret mouse movements."); RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", ""); } -- cgit v1.2.3 From f399481251a4d375a494517925c64b3b3c6db7e8 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 7 Aug 2010 10:57:15 +0000 Subject: SpaceNav turntable and fit in 3D view. Tablet data rides with cursor/button events (incomplete! Mac-only for now). Grease pencil works better with pen. --- source/blender/blenlib/intern/math_rotation.c | 6 +- source/blender/editors/gpencil/gpencil_paint.c | 14 +- source/blender/editors/space_view3d/view3d_edit.c | 565 ++++++--------------- .../blender/editors/space_view3d/view3d_intern.h | 4 +- source/blender/editors/space_view3d/view3d_ops.c | 8 +- source/blender/makesdna/DNA_view3d_types.h | 16 +- source/blender/windowmanager/WM_types.h | 14 + .../blender/windowmanager/intern/wm_event_system.c | 512 +++++++++++-------- source/blender/windowmanager/intern/wm_window.c | 3 - source/blender/windowmanager/wm.h | 1 - source/blender/windowmanager/wm_event_types.h | 59 ++- 11 files changed, 539 insertions(+), 663 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 6b5bf7743ef..ad6ce5c4448 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -132,7 +132,6 @@ void mul_fac_qt_fl(float *q, float fac) q[1]*= si; q[2]*= si; q[3]*= si; - } void quat_to_mat3(float m[][3], float *q) @@ -308,7 +307,6 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3]) mul_qt_qtqt(q, q1, q2); } - void normalize_qt(float *q) { float len; @@ -585,7 +583,7 @@ void axis_angle_to_quat(float q[4], float axis[3], float angle) } /* Quaternions to Axis Angle */ -void quat_to_axis_angle(float axis[3], float *angle,float q[4]) +void quat_to_axis_angle(float axis[3], float *angle, float q[4]) { float ha, si; @@ -687,7 +685,7 @@ void mat4_to_axis_angle(float axis[3], float *angle,float mat[4][4]) } /****************************** Vector/Rotation ******************************/ -/* TODO: the following calls should probably be depreceated sometime */ +/* TODO: the following calls should probably be deprecated sometime */ /* 3x3 matrix to axis angle */ void mat3_to_vec_rot(float axis[3], float *angle,float mat[3][3]) diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 7656295fd61..68ae37a0a56 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1233,6 +1233,8 @@ static int gpencil_draw_cancel (bContext *C, wmOperator *op) /* create a new stroke point at the point indicated by the painting context */ static void gpencil_draw_apply (bContext *C, wmOperator *op, tGPsdata *p) { + printf("< pressure = %.2f\n", p->pressure); + /* handle drawing/erasing -> test for erasing first */ if (p->paintmode == GP_PAINTMODE_ERASER) { /* do 'live' erasing now */ @@ -1245,6 +1247,7 @@ static void gpencil_draw_apply (bContext *C, wmOperator *op, tGPsdata *p) } /* only add current point to buffer if mouse moved (even though we got an event, it might be just noise) */ else if (gp_stroke_filtermval(p, p->mval, p->mvalo)) { + /* try to add point */ short ok= gp_stroke_addpoint(p, p->mval, p->pressure); @@ -1293,11 +1296,18 @@ static void gpencil_draw_apply_event (bContext *C, wmOperator *op, wmEvent *even wmTabletData *wmtab= event->customdata; tablet= (wmtab->Active != EVT_TABLET_NONE); - p->pressure= wmtab->Pressure; - if (wmtab->Active == EVT_TABLET_ERASER) + + + if (wmtab->Active == EVT_TABLET_ERASER) { // TODO... this should get caught by the keymaps which call drawing in the first place // .. but until that's possible, duct tape the eraser function back on p->paintmode = GP_PAINTMODE_ERASER; + p->pressure = wmtab->Pressure; + } + else { + /* 20% to 200% of normal mouse-based strength */ + p->pressure = 1.8 * wmtab->Pressure + 0.2; + } } else p->pressure= 1.0f; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index bce4a7e8f58..981b45c7396 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -313,7 +313,7 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event) QUATCOPY(vod->oldquat, rv3d->viewquat); vod->origx= vod->oldx= event->x; vod->origy= vod->oldy= event->y; - vod->origkey= event->type; /* the key that triggered the operator. */ + vod->origkey= event->type; /* the key that triggered the operator. */ vod->use_dyn_ofs= (U.uiflag & USER_ORBIT_SELECTION) ? 1:0; if (vod->use_dyn_ofs) { @@ -351,7 +351,7 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event) sub_v3_v3v3(my_pivot, rv3d->ofs, upvec); negate_v3(my_pivot); /* ofs is flipped */ - /* find a new ofs value that is allong the view axis (rather then the mouse location) */ + /* find a new ofs value that is along the view axis (rather then the mouse location) */ closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin); vod->dist0 = rv3d->dist = len_v3v3(my_pivot, dvec); @@ -498,7 +498,6 @@ void viewrotate_modal_keymap(wmKeyConfig *keyconf) /* assign map to operators */ WM_modalkeymap_assign(keymap, "VIEW3D_OT_rotate"); - } static void viewrotate_apply(ViewOpsData *vod, int x, int y) @@ -602,7 +601,6 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) int i; float viewmat[3][3]; - quat_to_mat3( viewmat,rv3d->viewquat); for (i = 0 ; i < 39; i++){ @@ -759,7 +757,6 @@ static int view3d_rotate_poll(bContext *C) void VIEW3D_OT_rotate(wmOperatorType *ot) { - /* identifiers */ ot->name= "Rotate view"; ot->description = "Rotate the view"; @@ -774,6 +771,169 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER; } +// returns angular velocity (0..1), fills axis of rotation +// (shouldn't live in this file!) +float ndof_to_angle_axis(const float ndof[3], float axis[3]) + { + const float x = ndof[0]; + const float y = ndof[1]; + const float z = ndof[2]; + + float angular_velocity = sqrtf(x*x + y*y + z*z); + + float scale = 1.f / angular_velocity; + + // normalize + axis[0] = scale * x; + axis[1] = scale * y; + axis[2] = scale * z; + + return angular_velocity; + } + +static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + float dt = ndof->dt; + + RegionView3D* rv3d = CTX_wm_region_view3d(C); + + if (dt > 0.25f) + /* this is probably the first event for this motion, so set dt to something reasonable */ + dt = 0.0125f; + + /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ + float phi, q1[4]; + float m[3][3]; + float m_inv[3][3]; + float xvec[3] = {1,0,0}; + + const float sensitivity = 0.035; + + /* Get the 3x3 matrix and its inverse from the quaternion */ + quat_to_mat3(m,rv3d->viewquat); + invert_m3_m3(m_inv,m); + + /* Determine the direction of the x vector (for rotating up and down) */ + /* This can likely be computed directly from the quaternion. */ + mul_m3_v3(m_inv,xvec); + + /* Perform the up/down rotation */ + phi = sensitivity * -ndof->rx; + q1[0] = cos(phi); + mul_v3_v3fl(q1+1, xvec, sin(phi)); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + + /* Perform the orbital rotation */ + phi = sensitivity * ndof->rz; + q1[0] = cos(phi); + q1[1] = q1[2] = 0.0; + q1[3] = sin(phi); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + + ED_region_tag_redraw(CTX_wm_region(C)); + return OPERATOR_FINISHED; + } + +static int viewndof_invoke_1st_try(bContext *C, wmOperator *op, wmEvent *event) +{ + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + float dt = ndof->dt; + + RegionView3D *rv3d= CTX_wm_region_view3d(C); + + if (dt > 0.25f) + /* this is probably the first event for this motion, so set dt to something reasonable */ + dt = 0.0125f; + + /* very simple for now, move viewpoint along world axes */ + rv3d->ofs[0] += dt * ndof->tx; + rv3d->ofs[1] += dt * ndof->ty; + rv3d->ofs[2] += dt * ndof->tz; + +// request_depth_update(CTX_wm_region_view3d(C)); /* need this? */ + ED_region_tag_redraw(CTX_wm_region(C)); + + return OPERATOR_FINISHED; +} + +static int viewndof_invoke_2nd_try(bContext *C, wmOperator *op, wmEvent *event) +{ + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + float dt = ndof->dt; + + RegionView3D* rv3d = CTX_wm_region_view3d(C); + + if (dt > 0.25f) + /* this is probably the first event for this motion, so set dt to something reasonable */ + dt = 0.0125f; + + float axis[3]; + float angle = ndof_to_angle_axis(&(ndof->rx), axis); + + float eyeball_q[4];// = {0.f}; + +// float* eyeball_v = eyeball_q + 1; + + axis_angle_to_quat(eyeball_q, axis, angle); + + float eye_conj[4]; + copy_qt_qt(eye_conj, eyeball_q); + conjugate_qt(eye_conj); + +// float mat[3][3]; +// quat_to_mat3(mat, rv3d->viewquat); +/* + eyeball_v[0] = dt * ndof->tx; + eyeball_v[1] = dt * ndof->ty; + eyeball_v[2] = dt * ndof->tz; +*/ +// mul_m3_v3(mat, eyeball_vector); +// mul_qt_v3(rv3d->viewquat, eyeball_vector); + + // doesn't this transform v? + // v' = (q)(v)(~q) + + float view_q[4]; + copy_qt_qt(view_q, rv3d->viewquat); + +// float q_conj[4]; +// copy_qt_qt(q_conj, q); +// conjugate_qt(q_conj); + + mul_qt_qtqt(view_q, eyeball_q, view_q); + mul_qt_qtqt(view_q, view_q, eye_conj); + +// mul_qt_qtqt(eyeball_q, q, eyeball_q); +// mul_qt_qtqt(eyeball_q, eyeball_q, q_conj); + +// add_v3_v3(rv3d->ofs, eyeball_v); + + copy_qt_qt(rv3d->viewquat, view_q); + + ED_region_tag_redraw(CTX_wm_region(C)); + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_ndof(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Navigate view"; + ot->description = "Navigate the view using a 3D mouse."; + ot->idname = "VIEW3D_OT_ndof"; + + /* api callbacks */ + ot->invoke = viewndof_invoke; + ot->poll = ED_operator_view3d_active; + + /* flags */ + ot->flag = 0; +} + /* ************************ viewmove ******************************** */ @@ -839,7 +999,6 @@ static void viewmove_apply(ViewOpsData *vod, int x, int y) static int viewmove_modal(bContext *C, wmOperator *op, wmEvent *event) { - ViewOpsData *vod= op->customdata; short event_code= VIEW_PASS; @@ -2650,397 +2809,3 @@ int view_autodist_depth(struct ARegion *ar, short *mval, int margin, float *dept return (*depth==FLT_MAX) ? 0:1; return 0; } - -/* ********************* NDOF ************************ */ -/* note: this code is confusing and unclear... (ton) */ -/* **************************************************** */ - -// ndof scaling will be moved to user setting. -// In the mean time this is just a place holder. - -// Note: scaling in the plugin and ghostwinlay.c -// should be removed. With driver default setting, -// each axis returns approx. +-200 max deflection. - -// The values I selected are based on the older -// polling i/f. With event i/f, the sensistivity -// can be increased for improved response from -// small deflections of the device input. - - -// lukep notes : i disagree on the range. -// the normal 3Dconnection driver give +/-400 -// on defaut range in other applications -// and up to +/- 1000 if set to maximum -// because i remove the scaling by delta, -// which was a bad idea as it depend of the system -// speed and os, i changed the scaling values, but -// those are still not ok - - -float ndof_axis_scale[6] = { - +0.01, // Tx - +0.01, // Tz - +0.01, // Ty - +0.0015, // Rx - +0.0015, // Rz - +0.0015 // Ry -}; - -void filterNDOFvalues(float *sbval) -{ - int i=0; - float max = 0.0; - - for (i =0; i<6;i++) - if (fabs(sbval[i]) > max) - max = fabs(sbval[i]); - for (i =0; i<6;i++) - if (fabs(sbval[i]) != max ) - sbval[i]=0.0; -} - -// statics for controlling rv3d->dist corrections. -// viewmoveNDOF zeros and adjusts rv3d->ofs. -// viewmove restores based on dz_flag state. - -int dz_flag = 0; -float m_dist; - -void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode) -{ - RegionView3D *rv3d= ar->regiondata; - int i; - float phi; - float dval[7]; - // static fval[6] for low pass filter; device input vector is dval[6] - static float fval[6]; - float tvec[3],rvec[3]; - float q1[4]; - float mat[3][3]; - float upvec[3]; - - - /*---------------------------------------------------- - * sometimes this routine is called from headerbuttons - * viewmove needs to refresh the screen - */ -// XXX areawinset(ar->win); - - - // fetch the current state of the ndof device -// XXX getndof(dval); - - if (v3d->ndoffilter) - filterNDOFvalues(fval); - - // Scale input values - -// if(dval[6] == 0) return; // guard against divide by zero - - for(i=0;i<6;i++) { - - // user scaling - dval[i] = dval[i] * ndof_axis_scale[i]; - } - - - // low pass filter with zero crossing reset - - for(i=0;i<6;i++) { - if((dval[i] * fval[i]) >= 0) - dval[i] = (fval[i] * 15 + dval[i]) / 16; - else - fval[i] = 0; - } - - - // force perspective mode. This is a hack and is - // incomplete. It doesn't actually effect the view - // until the first draw and doesn't update the menu - // to reflect persp mode. - - rv3d->persp = RV3D_PERSP; - - - // Correct the distance jump if rv3d->dist != 0 - - // This is due to a side effect of the original - // mouse view rotation code. The rotation point is - // set a distance in front of the viewport to - // make rotating with the mouse look better. - // The distance effect is written at a low level - // in the view management instead of the mouse - // view function. This means that all other view - // movement devices must subtract this from their - // view transformations. - - if(rv3d->dist != 0.0) { - dz_flag = 1; - m_dist = rv3d->dist; - upvec[0] = upvec[1] = 0; - upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, upvec); - sub_v3_v3(rv3d->ofs, upvec); - rv3d->dist = 0.0; - } - - - // Apply rotation - // Rotations feel relatively faster than translations only in fly mode, so - // we have no choice but to fix that here (not in the plugins) - rvec[0] = -0.5 * dval[3]; - rvec[1] = -0.5 * dval[4]; - rvec[2] = -0.5 * dval[5]; - - // rotate device x and y by view z - - copy_m3_m4(mat, rv3d->viewinv); - mat[2][2] = 0.0f; - mul_m3_v3(mat, rvec); - - // rotate the view - - phi = normalize_v3(rvec); - if(phi != 0) { - axis_angle_to_quat(q1,rvec,phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - } - - - // Apply translation - - tvec[0] = dval[0]; - tvec[1] = dval[1]; - tvec[2] = -dval[2]; - - // the next three lines rotate the x and y translation coordinates - // by the current z axis angle - - copy_m3_m4(mat, rv3d->viewinv); - mat[2][2] = 0.0f; - mul_m3_v3(mat, tvec); - - // translate the view - - sub_v3_v3(rv3d->ofs, tvec); - - - /*---------------------------------------------------- - * refresh the screen XXX - */ - - // update render preview window - -// XXX BIF_view3d_previewrender_signal(ar, PR_DBASE|PR_DISPRECT); -} - -void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) -{ - RegionView3D *rv3d= ar->regiondata; - float fval[7]; - float dvec[3]; - float sbadjust = 1.0f; - float len; - short use_sel = 0; - Object *ob = OBACT; - float m[3][3]; - float m_inv[3][3]; - float xvec[3] = {1,0,0}; - float yvec[3] = {0,-1,0}; - float zvec[3] = {0,0,1}; - float phi; - float q1[4]; - float obofs[3]; - float reverse; - //float diff[4]; - float d, curareaX, curareaY; - float mat[3][3]; - float upvec[3]; - - /* Sensitivity will control how fast the view rotates. The value was - * obtained experimentally by tweaking until the author didn't get dizzy watching. - * Perhaps this should be a configurable user parameter. - */ - float psens = 0.005f * (float) U.ndof_pan; /* pan sensitivity */ - float rsens = 0.005f * (float) U.ndof_rotate; /* rotate sensitivity */ - float zsens = 0.3f; /* zoom sensitivity */ - - const float minZoom = -30.0f; - const float maxZoom = 300.0f; - - //reset view type - rv3d->view = 0; -//printf("passing here \n"); -// - if (scene->obedit==NULL && ob && !(ob->mode & OB_MODE_POSE)) { - use_sel = 1; - } - - if((dz_flag)||rv3d->dist==0) { - dz_flag = 0; - rv3d->dist = m_dist; - upvec[0] = upvec[1] = 0; - upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, upvec); - add_v3_v3(rv3d->ofs, upvec); - } - - /*---------------------------------------------------- - * sometimes this routine is called from headerbuttons - * viewmove needs to refresh the screen - */ -// XXX areawinset(curarea->win); - - /*---------------------------------------------------- - * record how much time has passed. clamp at 10 Hz - * pretend the previous frame occurred at the clamped time - */ -// now = PIL_check_seconds_timer(); - // frametime = (now - prevTime); - // if (frametime > 0.1f){ /* if more than 1/10s */ - // frametime = 1.0f/60.0; /* clamp at 1/60s so no jumps when starting to move */ -// } -// prevTime = now; - // sbadjust *= 60 * frametime; /* normalize ndof device adjustments to 100Hz for framerate independence */ - - /* fetch the current state of the ndof device & enforce dominant mode if selected */ -// XXX getndof(fval); - if (v3d->ndoffilter) - filterNDOFvalues(fval); - - - // put scaling back here, was previously in ghostwinlay - fval[0] = fval[0] * (1.0f/600.0f); - fval[1] = fval[1] * (1.0f/600.0f); - fval[2] = fval[2] * (1.0f/1100.0f); - fval[3] = fval[3] * 0.00005f; - fval[4] =-fval[4] * 0.00005f; - fval[5] = fval[5] * 0.00005f; - fval[6] = fval[6] / 1000000.0f; - - // scale more if not in perspective mode - if (rv3d->persp == RV3D_ORTHO) { - fval[0] = fval[0] * 0.05f; - fval[1] = fval[1] * 0.05f; - fval[2] = fval[2] * 0.05f; - fval[3] = fval[3] * 0.9f; - fval[4] = fval[4] * 0.9f; - fval[5] = fval[5] * 0.9f; - zsens *= 8; - } - - /* set object offset */ - if (ob) { - obofs[0] = -ob->obmat[3][0]; - obofs[1] = -ob->obmat[3][1]; - obofs[2] = -ob->obmat[3][2]; - } - else { - VECCOPY(obofs, rv3d->ofs); - } - - /* calc an adjustment based on distance from camera - disabled per patch 14402 */ - d = 1.0f; - -/* if (ob) { - sub_v3_v3v3(diff, obofs, rv3d->ofs); - d = len_v3(diff); - } -*/ - - reverse = (rv3d->persmat[2][1] < 0.0f) ? -1.0f : 1.0f; - - /*---------------------------------------------------- - * ndof device pan - */ - psens *= 1.0f + d; - curareaX = sbadjust * psens * fval[0]; - curareaY = sbadjust * psens * fval[1]; - dvec[0] = curareaX * rv3d->persinv[0][0] + curareaY * rv3d->persinv[1][0]; - dvec[1] = curareaX * rv3d->persinv[0][1] + curareaY * rv3d->persinv[1][1]; - dvec[2] = curareaX * rv3d->persinv[0][2] + curareaY * rv3d->persinv[1][2]; - add_v3_v3(rv3d->ofs, dvec); - - /*---------------------------------------------------- - * ndof device dolly - */ - len = zsens * sbadjust * fval[2]; - - if (rv3d->persp==RV3D_CAMOB) { - if(rv3d->persp==RV3D_CAMOB) { /* This is stupid, please fix - TODO */ - rv3d->camzoom+= 10.0f * -len; - } - if (rv3d->camzoom < minZoom) rv3d->camzoom = minZoom; - else if (rv3d->camzoom > maxZoom) rv3d->camzoom = maxZoom; - } - else if ((rv3d->dist> 0.001*v3d->grid) && (rv3d->dist<10.0*v3d->far)) { - rv3d->dist*=(1.0 + len); - } - - - /*---------------------------------------------------- - * ndof device turntable - * derived from the turntable code in viewmove - */ - - /* Get the 3x3 matrix and its inverse from the quaternion */ - quat_to_mat3( m,rv3d->viewquat); - invert_m3_m3(m_inv,m); - - /* Determine the direction of the x vector (for rotating up and down) */ - /* This can likely be compuated directly from the quaternion. */ - mul_m3_v3(m_inv,xvec); - mul_m3_v3(m_inv,yvec); - mul_m3_v3(m_inv,zvec); - - /* Perform the up/down rotation */ - phi = sbadjust * rsens * /*0.5f * */ fval[3]; /* spin vertically half as fast as horizontally */ - q1[0] = cos(phi); - mul_v3_v3fl(q1+1, xvec, sin(phi)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - - if (use_sel) { - conjugate_qt(q1); /* conj == inv for unit quat */ - sub_v3_v3(rv3d->ofs, obofs); - mul_qt_v3(q1, rv3d->ofs); - add_v3_v3(rv3d->ofs, obofs); - } - - /* Perform the orbital rotation */ - /* Perform the orbital rotation - If the seen Up axis is parallel to the zoom axis, rotation should be - achieved with a pure Roll motion (no Spin) on the device. When you start - to tilt, moving from Top to Side view, Spinning will increasingly become - more relevant while the Roll component will decrease. When a full - Side view is reached, rotations around the world's Up axis are achieved - with a pure Spin-only motion. In other words the control of the spinning - around the world's Up axis should move from the device's Spin axis to the - device's Roll axis depending on the orientation of the world's Up axis - relative to the screen. */ - //phi = sbadjust * rsens * reverse * fval[4]; /* spin the knob, y axis */ - phi = sbadjust * rsens * (yvec[2] * fval[4] + zvec[2] * fval[5]); - q1[0] = cos(phi); - q1[1] = q1[2] = 0.0; - q1[3] = sin(phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - - if (use_sel) { - conjugate_qt(q1); - sub_v3_v3(rv3d->ofs, obofs); - mul_qt_v3(q1, rv3d->ofs); - add_v3_v3(rv3d->ofs, obofs); - } - - /*---------------------------------------------------- - * refresh the screen - */ -// XXX scrarea_do_windraw(curarea); -} - - - - diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 846300ff9a6..ca75eb81724 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -71,6 +71,7 @@ void view3d_keymap(struct wmKeyConfig *keyconf); void VIEW3D_OT_zoom(struct wmOperatorType *ot); void VIEW3D_OT_move(struct wmOperatorType *ot); void VIEW3D_OT_rotate(struct wmOperatorType *ot); +void VIEW3D_OT_ndof(struct wmOperatorType *ot); void VIEW3D_OT_view_all(struct wmOperatorType *ot); void VIEW3D_OT_viewnumpad(struct wmOperatorType *ot); void VIEW3D_OT_view_selected(struct wmOperatorType *ot); @@ -98,8 +99,6 @@ void draw_motion_path_instance(Scene *scene, View3D *v3d, struct ARegion *ar, struct bAnimVizSettings *avs, struct bMotionPath *mpath); void draw_motion_paths_cleanup(Scene *scene, View3D *v3d, struct ARegion *ar); - - /* drawobject.c */ void draw_object(Scene *scene, struct ARegion *ar, View3D *v3d, Base *base, int flag); int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt); @@ -192,4 +191,3 @@ void draw_volume(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, st #endif /* ED_VIEW3D_INTERN_H */ - diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 22fab5887ee..dced49494ca 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -28,6 +28,7 @@ #include #include +#include // [mce] debug, remove when finished #include "MEM_guardedalloc.h" @@ -61,6 +62,7 @@ void view3d_operatortypes(void) WM_operatortype_append(VIEW3D_OT_rotate); WM_operatortype_append(VIEW3D_OT_move); WM_operatortype_append(VIEW3D_OT_zoom); + WM_operatortype_append(VIEW3D_OT_ndof); WM_operatortype_append(VIEW3D_OT_view_all); WM_operatortype_append(VIEW3D_OT_viewnumpad); WM_operatortype_append(VIEW3D_OT_view_orbit); @@ -155,12 +157,17 @@ void view3d_keymap(wmKeyConfig *keyconf) RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0)->ptr, "center", 0); /* only without camera view */ RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1); + /* 3D mouse */ + WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON1, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_ndof", NDOF_MOTION, 0, 0, 0); + /* numpad view hotkeys*/ RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA); RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT); RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD2, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPDOWN); RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT); RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD4, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPLEFT); + WM_keymap_add_item(keymap, "VIEW3D_OT_view_persportho", PAD5, KM_PRESS, 0, 0); RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD6, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPRIGHT); @@ -300,4 +307,3 @@ void view3d_keymap(wmKeyConfig *keyconf) viewmove_modal_keymap(keyconf); viewzoom_modal_keymap(keyconf); } - diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index c5516a3bff5..23934f665c5 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -47,10 +47,10 @@ struct wmTimer; /* This is needed to not let VC choke on near and far... old * proprietary MS extensions... */ #ifdef WIN32 -#undef near -#undef far -#define near clipsta -#define far clipend + #undef near + #undef far + #define near clipsta + #define far clipend #endif #include "DNA_listBase.h" @@ -137,12 +137,12 @@ typedef struct View3D { float blockscale; short blockhandler[8]; - float viewquat[4], dist, pad1; /* XXX depricated */ + float viewquat[4], dist, pad1; /* XXX deprecated */ int lay_used; /* used while drawing */ - short persp; /* XXX depricated */ - short view; /* XXX depricated */ + short persp; /* XXX deprecated */ + short view; /* XXX deprecated */ struct Object *camera, *ob_centre; @@ -298,5 +298,3 @@ typedef struct View3D { #define V3D_BGPIC_EXPANDED 2 #endif - - diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index c84a5e64889..e6e75bf793c 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -346,6 +346,7 @@ typedef struct wmEvent { } wmEvent; /* ************** custom wmEvent data ************** */ + typedef struct wmTabletData { int Active; /* 0=EVT_TABLET_NONE, 1=EVT_TABLET_STYLUS, 2=EVT_TABLET_ERASER */ float Pressure; /* range 0.0 (not touching) to 1.0 (full pressure) */ @@ -371,6 +372,19 @@ typedef struct wmTimer { int sleep; /* internal, put timers to sleep when needed */ } wmTimer; +typedef struct { + /* awfully similar to GHOST_TEventNDOFMotionData... */ + + /* Each component normally ranges from -1 to +1, but can exceed that. */ + + float tx, ty, tz; /* translation: -x left, +y forward, -z up */ + float rx, ry, rz; /* rotation: + axis = (rx,ry,rz).normalized + amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg] */ + + float dt; // time since previous NDOF Motion event (or zero if this is the first) +} wmNDOFMotionData; + typedef struct wmOperatorType { struct wmOperatorType *next, *prev; diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 63dcda3c12e..030ce7fa888 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -29,6 +29,7 @@ #include #include #include +#include // [mce] debug, remove when finished #include "DNA_listBase.h" #include "DNA_screen_types.h" @@ -99,7 +100,7 @@ void wm_event_free(wmEvent *event) void wm_event_free_all(wmWindow *win) { wmEvent *event; - + while((event= win->queue.first)) { BLI_remlink(&win->queue, event); wm_event_free(event); @@ -115,7 +116,7 @@ static int wm_test_duplicate_notifier(wmWindowManager *wm, unsigned int type, vo for(note=wm->queue.first; note; note=note->next) if((note->category|note->data|note->subtype|note->action) == type && note->reference == reference) return 1; - + return 0; } @@ -123,20 +124,20 @@ static int wm_test_duplicate_notifier(wmWindowManager *wm, unsigned int type, vo void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference) { wmNotifier *note= MEM_callocN(sizeof(wmNotifier), "notifier"); - + note->wm= CTX_wm_manager(C); BLI_addtail(¬e->wm->queue, note); - + note->window= CTX_wm_window(C); - + if(CTX_wm_region(C)) note->swinid= CTX_wm_region(C)->swinid; - + note->category= type & NOTE_CATEGORY; note->data= type & NOTE_DATA; note->subtype= type & NOTE_SUBTYPE; note->action= type & NOTE_ACTION; - + note->reference= reference; } @@ -147,15 +148,15 @@ void WM_main_add_notifier(unsigned int type, void *reference) if(wm && !wm_test_duplicate_notifier(wm, type, reference)) { wmNotifier *note= MEM_callocN(sizeof(wmNotifier), "notifier"); - + note->wm= wm; BLI_addtail(¬e->wm->queue, note); - + note->category= type & NOTE_CATEGORY; note->data= type & NOTE_DATA; note->subtype= type & NOTE_SUBTYPE; note->action= type & NOTE_ACTION; - + note->reference= reference; } } @@ -177,13 +178,13 @@ void wm_event_do_notifiers(bContext *C) if(wm==NULL) return; - + /* cache & catch WM level notifiers, such as frame change, scene/screen set */ for(win= wm->windows.first; win; win= win->next) { int do_anim= 0; - + CTX_wm_window_set(C, win); - + for(note= wm->queue.first; note; note= next) { next= note->next; @@ -219,13 +220,12 @@ void wm_event_do_notifiers(bContext *C) } else if(note->data==ND_FRAME) do_anim= 1; - + if(note->action == NA_REMOVED) { ED_screen_delete_scene(C, note->reference); // XXX hrms, think this over! if(G.f & G_DEBUG) printf("scene delete %p\n", note->reference); } - } } if(ELEM5(note->category, NC_SCENE, NC_OBJECT, NC_GEOM, NC_SCENE, NC_WM)) { @@ -245,13 +245,13 @@ void wm_event_do_notifiers(bContext *C) } } } - + /* the notifiers are sent without context, to keep it clean */ while( (note=wm_notifier_next(wm)) ) { wmWindow *win; - + for(win= wm->windows.first; win; win= win->next) { - + /* filter out notifiers */ if(note->category==NC_SCREEN && note->reference && note->reference!=win->screen); else if(note->category==NC_SCENE && note->reference && note->reference!=win->screen->scene); @@ -268,7 +268,7 @@ void wm_event_do_notifiers(bContext *C) for(ar=win->screen->regionbase.first; ar; ar= ar->next) { ED_region_do_listen(ar, note); } - + for(sa= win->screen->areabase.first; sa; sa= sa->next) { ED_area_do_listen(sa, note); for(ar=sa->regionbase.first; ar; ar= ar->next) { @@ -277,14 +277,14 @@ void wm_event_do_notifiers(bContext *C) } } } - + MEM_freeN(note); } - + /* cached: editor refresh callbacks now, they get context */ for(win= wm->windows.first; win; win= win->next) { ScrArea *sa; - + CTX_wm_window_set(C, win); for(sa= win->screen->areabase.first; sa; sa= sa->next) { if(sa->do_refresh) { @@ -292,7 +292,7 @@ void wm_event_do_notifiers(bContext *C) ED_area_do_refresh(C, sa); } } - + /* XXX make lock in future, or separated derivedmesh users in scene */ if(!G.rendering) /* depsgraph & animation: update tagged datablocks */ @@ -310,7 +310,7 @@ static int wm_handler_ui_call(bContext *C, wmEventHandler *handler, wmEvent *eve ARegion *region= CTX_wm_region(C); ARegion *menu= CTX_wm_menu(C); int retval; - + /* we set context to where ui handler came from */ if(handler->ui_area) CTX_wm_area_set(C, handler->ui_area); if(handler->ui_region) CTX_wm_region_set(C, handler->ui_region); @@ -362,14 +362,14 @@ static void wm_handler_ui_cancel(bContext *C) int WM_operator_poll(bContext *C, wmOperatorType *ot) { wmOperatorTypeMacro *otmacro; - + for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) { wmOperatorType *ot= WM_operatortype_find(otmacro->idname, 0); if(0==WM_operator_poll(C, ot)) return 0; } - + /* python needs operator type, so we added exception for it */ if(ot->pyop_poll) return ot->pyop_poll(C, ot); @@ -391,7 +391,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int pop wmWindowManager *wm = CTX_wm_manager(C); ReportList *reports = CTX_wm_reports(C); char *buf; - + if(popup) if(op->reports->list.first) uiPupMenuReports(C, op->reports); @@ -399,7 +399,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int pop if(retval & OPERATOR_FINISHED) { if(G.f & G_DEBUG) wm_operator_print(op); /* todo - this print may double up, might want to check more flags then the FINISHED */ - + if (op->type->flag & OPTYPE_REGISTER) { /* Report the python string representation of the operator */ buf = WM_operator_pystring(C, op->type, op->ptr, 1); @@ -410,16 +410,16 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int pop if (op->reports->list.first) { ReportTimerInfo *rti; - + /* add reports to the global list, otherwise they are not seen */ addlisttolist(&CTX_wm_reports(C)->list, &op->reports->list); - + /* After adding reports to the global list, reset the report timer. */ WM_event_remove_timer(wm, NULL, reports->reporttimer); - + /* Records time since last report was added */ reports->reporttimer= WM_event_add_timer(wm, CTX_wm_window(C), TIMER, 0.02); - + rti = MEM_callocN(sizeof(ReportTimerInfo), "ReportTimerInfo"); reports->reporttimer->customdata = rti; } @@ -457,13 +457,13 @@ static int wm_operator_exec(bContext *C, wmOperator *op, int repeat) { wmWindowManager *wm= CTX_wm_manager(C); int retval= OPERATOR_CANCELLED; - + if(op==NULL || op->type==NULL) return retval; - + if(0==WM_operator_poll(C, op->type)) return retval; - + if(op->type->exec) { if(op->type->flag & OPTYPE_UNDO) wm->op_undo_depth++; @@ -473,17 +473,16 @@ static int wm_operator_exec(bContext *C, wmOperator *op, int repeat) if(op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) wm->op_undo_depth--; } - + if (retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED) && repeat == 0) wm_operator_reports(C, op, retval, 0); - + if(retval & OPERATOR_FINISHED) wm_operator_finished(C, op, repeat); else if(repeat==0) WM_operator_free(op); - + return retval | OPERATOR_HANDLED; - } /* for running operators with frozen context (modal handlers, menus) */ @@ -501,11 +500,11 @@ int WM_operator_repeat(bContext *C, wmOperator *op) static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, PointerRNA *properties, ReportList *reports) { wmOperator *op= MEM_callocN(sizeof(wmOperator), ot->idname); /* XXX operatortype names are static still. for debug */ - + /* XXX adding new operator could be function, only happens here now */ op->type= ot; BLI_strncpy(op->idname, ot->idname, OP_MAX_TYPENAME); - + /* initialize properties, either copy or create */ op->ptr= MEM_callocN(sizeof(PointerRNA), "wmOperatorPtrRNA"); if(properties && properties->data) { @@ -525,20 +524,19 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P op->reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList"); BKE_reports_init(op->reports, RPT_STORE|RPT_FREE); } - + /* recursive filling of operator macro list */ if(ot->macro.first) { static wmOperator *motherop= NULL; wmOperatorTypeMacro *otmacro; int root = 0; - + /* ensure all ops are in execution order in 1 list */ if(motherop==NULL) { motherop = op; root = 1; } - /* if properties exist, it will contain everything needed */ if (properties) { otmacro= ot->macro.first; @@ -573,11 +571,11 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P opm->opm= motherop; /* pointer to mom, for modal() */ } } - + if (root) motherop= NULL; } - + WM_operator_properties_sanitize(op->ptr, 0); return op; @@ -600,10 +598,10 @@ int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerR if(WM_operator_poll(C, ot)) { wmOperator *op= wm_operator_create(wm, ot, properties, reports); /* if reports==NULL, theyll be initialized */ - + if((G.f & G_DEBUG) && event && event->type!=MOUSEMOVE) printf("handle evt %d win %d op %s\n", event?event->type:0, CTX_wm_screen(C)->subwinactive, ot->idname); - + if(op->type->invoke && event) { wm_region_mouse_co(C, event); @@ -626,14 +624,13 @@ int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerR } else printf("invalid operator call %s\n", ot->idname); /* debug, important to leave a while, should never happen */ - + /* Note, if the report is given as an argument then assume the caller will deal with displaying them * currently python only uses this */ if (!(retval & OPERATOR_HANDLED) && retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED)) /* only show the report if the report list was not given in the function */ wm_operator_reports(C, op, retval, (reports==NULL)); - - + if(retval & OPERATOR_HANDLED) ; /* do nothing, wm_operator_exec() has been called somewhere */ else if(retval & OPERATOR_FINISHED) { @@ -708,7 +705,7 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex } switch(context) { - + case WM_OP_EXEC_REGION_WIN: case WM_OP_INVOKE_REGION_WIN: case WM_OP_EXEC_REGION_CHANNELS: @@ -727,36 +724,36 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex case WM_OP_EXEC_REGION_CHANNELS: case WM_OP_INVOKE_REGION_CHANNELS: type = RGN_TYPE_CHANNELS; - + case WM_OP_EXEC_REGION_PREVIEW: case WM_OP_INVOKE_REGION_PREVIEW: type = RGN_TYPE_PREVIEW; break; - + case WM_OP_EXEC_REGION_WIN: case WM_OP_INVOKE_REGION_WIN: default: type = RGN_TYPE_WINDOW; break; } - + if(!(ar && ar->regiontype == type) && area) { ARegion *ar1= BKE_area_find_region_type(area, type); if(ar1) CTX_wm_region_set(C, ar1); } - + retval= wm_operator_invoke(C, ot, event, properties, reports); - + /* set region back */ CTX_wm_region_set(C, ar); - + return retval; } case WM_OP_EXEC_AREA: case WM_OP_INVOKE_AREA: { - /* remove region from context */ + /* remove region from context */ ARegion *ar= CTX_wm_region(C); CTX_wm_region_set(C, NULL); @@ -785,7 +782,7 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex return wm_operator_invoke(C, ot, event, properties, reports); } } - + return 0; } @@ -828,13 +825,13 @@ int WM_operator_call_py(bContext *C, wmOperatorType *ot, int context, PointerRNA #endif retval= wm_operator_call_internal(C, ot, context, properties, reports); - + /* keep the reports around if needed later */ if (retval & OPERATOR_RUNNING_MODAL || ot->flag & OPTYPE_REGISTER) { reports->flag |= RPT_FREE; } - + return retval; } @@ -851,13 +848,13 @@ void wm_event_free_handler(wmEventHandler *handler) static void wm_handler_op_context(bContext *C, wmEventHandler *handler) { bScreen *screen= CTX_wm_screen(C); - + if(screen && handler->op) { if(handler->op_area==NULL) CTX_wm_area_set(C, NULL); else { ScrArea *sa; - + for(sa= screen->areabase.first; sa; sa= sa->next) if(sa==handler->op_area) break; @@ -886,16 +883,16 @@ void WM_event_remove_handlers(bContext *C, ListBase *handlers) { wmEventHandler *handler; wmWindowManager *wm= CTX_wm_manager(C); - + /* C is zero on freeing database, modal handlers then already were freed */ while((handler=handlers->first)) { BLI_remlink(handlers, handler); - + if(handler->op) { if(handler->op->type->cancel) { ScrArea *area= CTX_wm_area(C); ARegion *region= CTX_wm_region(C); - + wm_handler_op_context(C, handler); if(handler->op->type->flag & OPTYPE_UNDO) @@ -917,7 +914,7 @@ void WM_event_remove_handlers(bContext *C, ListBase *handlers) ScrArea *area= CTX_wm_area(C); ARegion *region= CTX_wm_region(C); ARegion *menu= CTX_wm_menu(C); - + if(handler->ui_area) CTX_wm_area_set(C, handler->ui_area); if(handler->ui_region) CTX_wm_region_set(C, handler->ui_region); if(handler->ui_menu) CTX_wm_menu_set(C, handler->ui_menu); @@ -942,45 +939,45 @@ int WM_userdef_event_map(int kmitype) return LEFTMOUSE; else return RIGHTMOUSE; - + case ACTIONMOUSE: if(U.flag & USER_LMOUSESELECT) return RIGHTMOUSE; else return LEFTMOUSE; - + case WHEELOUTMOUSE: if(U.uiflag & USER_WHEELZOOMDIR) return WHEELUPMOUSE; else return WHEELDOWNMOUSE; - + case WHEELINMOUSE: if(U.uiflag & USER_WHEELZOOMDIR) return WHEELDOWNMOUSE; else return WHEELUPMOUSE; - + case EVT_TWEAK_A: if(U.flag & USER_LMOUSESELECT) return EVT_TWEAK_R; else return EVT_TWEAK_L; - + case EVT_TWEAK_S: if(U.flag & USER_LMOUSESELECT) return EVT_TWEAK_L; else return EVT_TWEAK_R; } - + return kmitype; } static void wm_eventemulation(wmEvent *event) { static int mmb_emulated = 0; /* this should be in a data structure somwhere */ - + /* middlemouse emulation */ if(U.flag & USER_TWOBUTTONMOUSE) { if(event->type == LEFTMOUSE && (event->alt || mmb_emulated == KM_PRESS)) { @@ -1032,10 +1029,10 @@ static int wm_eventmatch(wmEvent *winevent, wmKeyMapItem *kmi) if(ISTEXTINPUT(winevent->type) && winevent->ascii) return 1; if(kmitype!=KM_ANY) if(winevent->type!=kmitype) return 0; - + if(kmi->val!=KM_ANY) if(winevent->val!=kmi->val) return 0; - + /* modifiers also check bits, so it allows modifier order */ if(kmi->shift!=KM_ANY) if(winevent->shift != kmi->shift && !(winevent->shift & kmi->shift)) return 0; @@ -1045,16 +1042,16 @@ static int wm_eventmatch(wmEvent *winevent, wmKeyMapItem *kmi) if(winevent->alt != kmi->alt && !(winevent->alt & kmi->alt)) return 0; if(kmi->oskey!=KM_ANY) if(winevent->oskey != kmi->oskey && !(winevent->oskey & kmi->oskey)) return 0; - + if(kmi->keymodifier) if(winevent->keymodifier!=kmi->keymodifier) return 0; - + /* key modifiers always check when event has it */ /* otherwise regular keypresses with keymodifier still work */ if(winevent->keymodifier) if(ISTEXTINPUT(winevent->type)) if(winevent->keymodifier!=kmi->keymodifier) return 0; - + return 1; } @@ -1077,7 +1074,6 @@ static void wm_event_modalkeymap(const bContext *C, wmOperator *op, wmEvent *eve for(kmi= keymap->items.first; kmi; kmi= kmi->next) { if(wm_eventmatch(event, kmi)) { - event->type= EVT_MODAL_MAP; event->val= kmi->propvalue; } @@ -1089,7 +1085,7 @@ static void wm_event_modalkeymap(const bContext *C, wmOperator *op, wmEvent *eve static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHandler *handler, wmEvent *event, PointerRNA *properties) { int retval= OPERATOR_PASS_THROUGH; - + /* derived, modal or blocking operator */ if(handler->op) { wmOperator *op= handler->op; @@ -1100,11 +1096,11 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand wmWindowManager *wm= CTX_wm_manager(C); ScrArea *area= CTX_wm_area(C); ARegion *region= CTX_wm_region(C); - + wm_handler_op_context(C, handler); wm_region_mouse_co(C, event); wm_event_modalkeymap(C, op, event); - + if(ot->flag & OPTYPE_UNDO) wm->op_undo_depth++; @@ -1122,11 +1118,11 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand /* this special cases is for areas and regions that get removed */ CTX_wm_area_set(C, NULL); CTX_wm_region_set(C, NULL); - } + } if(retval & (OPERATOR_CANCELLED|OPERATOR_FINISHED)) wm_operator_reports(C, op, retval, 0); - + if(retval & OPERATOR_FINISHED) { wm_operator_finished(C, op, 0); handler->op= NULL; @@ -1135,18 +1131,17 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand WM_operator_free(op); handler->op= NULL; } - + /* remove modal handler, operator itself should have been cancelled and freed */ if(retval & (OPERATOR_CANCELLED|OPERATOR_FINISHED)) { WM_cursor_ungrab(CTX_wm_window(C)); BLI_remlink(handlers, handler); wm_event_free_handler(handler); - + /* prevent silly errors from operator users */ //retval &= ~OPERATOR_PASS_THROUGH; } - } else printf("wm_handler_operator_call error\n"); @@ -1178,18 +1173,18 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa wmWindowManager *wm= CTX_wm_manager(C); SpaceFile *sfile; int action= WM_HANDLER_CONTINUE; - + if(event->type != EVT_FILESELECT) return action; if(handler->op != (wmOperator *)event->customdata) return action; - + switch(event->val) { case EVT_FILESELECT_OPEN: case EVT_FILESELECT_FULL_OPEN: - { + { ScrArea *sa; - + /* sa can be null when window A is active, but mouse is over window B */ /* in this case, open file select in original window A */ if (handler->op_area == NULL) { @@ -1197,37 +1192,37 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa sa = (ScrArea *)screen->areabase.first; } else sa = handler->op_area; - + if(event->val==EVT_FILESELECT_OPEN) ED_area_newspace(C, sa, SPACE_FILE); else ED_screen_full_newspace(C, sa, SPACE_FILE); /* sets context */ - + /* settings for filebrowser, sfile is not operator owner but sends events */ sa = CTX_wm_area(C); sfile= (SpaceFile*)sa->spacedata.first; sfile->op= handler->op; ED_fileselect_set_params(sfile); - + action= WM_HANDLER_BREAK; } break; - + case EVT_FILESELECT_EXEC: case EVT_FILESELECT_CANCEL: { /* XXX validate area and region? */ bScreen *screen= CTX_wm_screen(C); - + if(screen != handler->filescreen) ED_screen_full_prevspace(C, CTX_wm_area(C)); else ED_area_prevspace(C, CTX_wm_area(C)); - + /* remlink now, for load file case */ BLI_remlink(handlers, handler); - + wm_handler_op_context(C, handler); /* needed for uiPupMenuReports */ @@ -1253,11 +1248,11 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa if(handler->op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) wm->op_undo_depth--; - + if (retval & OPERATOR_FINISHED) if(G.f & G_DEBUG) wm_operator_print(handler->op); - + if(wm->op_undo_depth == 0) if(handler->op->type->flag & OPTYPE_UNDO) ED_undo_push_op(C, handler->op); @@ -1299,14 +1294,14 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa } CTX_wm_area_set(C, NULL); - + wm_event_free_handler(handler); - + action= WM_HANDLER_BREAK; } break; } - + return action; } @@ -1358,7 +1353,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) if(handler_boundbox_test(handler, event)) { /* in advance to avoid access to freed event on window close */ always_pass= wm_event_always_pass(event); - + /* modal+blocking handler */ if(handler->flag & WM_HANDLER_BLOCKING) action |= WM_HANDLER_BREAK; @@ -1366,13 +1361,13 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) if(handler->keymap) { wmKeyMap *keymap= WM_keymap_active(wm, handler->keymap); wmKeyMapItem *kmi; - + if(!keymap->poll || keymap->poll(C)) { for(kmi= keymap->items.first; kmi; kmi= kmi->next) { if(wm_eventmatch(event, kmi)) { - + event->keymap_idname= kmi->idname; /* weak, but allows interactive callback to not use rawkey */ - + action |= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr); if(action & WM_HANDLER_BREAK) /* not always_pass here, it denotes removed handler */ break; @@ -1398,7 +1393,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) for(drag= lb->first; drag; drag= drag->next) { if(drop->poll(C, drag, event)) { drop->copy(drag, drop); - + wm_operator_invoke(C, drop->ot, event, drop->ptr, NULL); action |= WM_HANDLER_BREAK; } @@ -1419,7 +1414,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) break; } } - + /* fileread case */ if(CTX_wm_window(C)==NULL) return action; @@ -1443,7 +1438,6 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) action |= wm_handlers_do(C, event, handlers); } - /* revert value if not handled */ if (wm_action_not_handled(action)) { event->val = KM_RELEASE; @@ -1473,7 +1467,7 @@ static ScrArea *area_event_inside(bContext *C, int x, int y) { bScreen *screen= CTX_wm_screen(C); ScrArea *sa; - + if(screen) for(sa= screen->areabase.first; sa; sa= sa->next) if(BLI_in_rcti(&sa->totrct, x, y)) @@ -1486,7 +1480,7 @@ static ARegion *region_event_inside(bContext *C, int x, int y) bScreen *screen= CTX_wm_screen(C); ScrArea *area= CTX_wm_area(C); ARegion *ar; - + if(screen && area) for(ar= area->regionbase.first; ar; ar= ar->next) if(BLI_in_rcti(&ar->winrct, x, y)) @@ -1512,21 +1506,21 @@ static void wm_paintcursor_tag(bContext *C, wmPaintCursor *pc, ARegion *ar) static void wm_paintcursor_test(bContext *C, wmEvent *event) { wmWindowManager *wm= CTX_wm_manager(C); - + if(wm->paintcursors.first) { ARegion *ar= CTX_wm_region(C); if(ar) wm_paintcursor_tag(C, wm->paintcursors.first, ar); - + /* if previous position was not in current region, we have to set a temp new context */ if(ar==NULL || !BLI_in_rcti(&ar->winrct, event->prevx, event->prevy)) { ScrArea *sa= CTX_wm_area(C); - + CTX_wm_area_set(C, area_event_inside(C, event->prevx, event->prevy)); CTX_wm_region_set(C, region_event_inside(C, event->prevx, event->prevy)); wm_paintcursor_tag(C, wm->paintcursors.first, CTX_wm_region(C)); - + CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); } @@ -1536,7 +1530,7 @@ static void wm_paintcursor_test(bContext *C, wmEvent *event) static void wm_event_drag_test(wmWindowManager *wm, wmWindow *win, wmEvent *event) { if(wm->drags.first==NULL) return; - + if(event->type==MOUSEMOVE) win->screen->do_draw_drag= 1; else if(event->type==ESCKEY) { @@ -1545,24 +1539,24 @@ static void wm_event_drag_test(wmWindowManager *wm, wmWindow *win, wmEvent *even } else if(event->type==LEFTMOUSE && event->val==KM_RELEASE) { event->type= EVT_DROP; - + /* create customdata, first free existing */ if(event->customdata) { if(event->customdatafree) MEM_freeN(event->customdata); } - + event->custom= EVT_DATA_LISTBASE; event->customdata= &wm->drags; event->customdatafree= 1; - + /* clear drop icon */ win->screen->do_draw_drag= 1; - + /* restore cursor (disabled, see wm_dragdrop.c) */ // WM_cursor_restore(win); } - + /* overlap fails otherwise */ if(win->screen->do_draw_drag) if(win->drawmethod == USER_DRAW_OVERLAP) @@ -1579,24 +1573,24 @@ void wm_event_do_handlers(bContext *C) for(win= wm->windows.first; win; win= win->next) { wmEvent *event; - + if( win->screen==NULL ) wm_event_free_all(win); else { Scene* scene = win->screen->scene; - + if(scene) { int playing = sound_scene_playing(win->screen->scene); - + if(playing != -1) { CTX_wm_window_set(C, win); CTX_wm_screen_set(C, win->screen); CTX_data_scene_set(C, scene); - + if(((playing == 1) && (!win->screen->animtimer)) || ((playing == 0) && (win->screen->animtimer))){ ED_screen_animation_play(C, -1, 1); } - + if(playing == 0) { int ncfra = sound_sync_scene(scene) * FPS + 0.5; if(ncfra != scene->r.cfra) { @@ -1605,41 +1599,41 @@ void wm_event_do_handlers(bContext *C) WM_event_add_notifier(C, NC_WINDOW, NULL); } } - + CTX_data_scene_set(C, NULL); CTX_wm_screen_set(C, NULL); CTX_wm_window_set(C, NULL); } } } - + while( (event= win->queue.first) ) { int action = WM_HANDLER_CONTINUE; if((G.f & G_DEBUG) && event && !ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) printf("pass on evt %d val %d\n", event->type, event->val); - + wm_eventemulation(event); CTX_wm_window_set(C, win); - + /* we let modal handlers get active area/region, also wm_paintcursor_test needs it */ CTX_wm_area_set(C, area_event_inside(C, event->x, event->y)); CTX_wm_region_set(C, region_event_inside(C, event->x, event->y)); - + /* MVC demands to not draw in event handlers... but we need to leave it for ogl selecting etc */ wm_window_make_drawable(C, win); - + /* first we do priority handlers, modal + some limited keymaps */ action |= wm_handlers_do(C, event, &win->modalhandlers); - + /* fileread case */ if(CTX_wm_window(C)==NULL) return; - + /* check dragging, creates new event or frees, adds draw tag */ wm_event_drag_test(wm, win, event); - + /* builtin tweak, if action is break it removes tweak */ wm_tweakevent_test(C, event, action); @@ -1647,7 +1641,7 @@ void wm_event_do_handlers(bContext *C) ScrArea *sa; ARegion *ar; int doit= 0; - + /* XXX to solve, here screen handlers? */ if(event->type==MOUSEMOVE) { /* state variables in screen, cursors */ @@ -1664,18 +1658,18 @@ void wm_event_do_handlers(bContext *C) for(ar=sa->regionbase.first; ar; ar= ar->next) { if(wm_event_inside_i(event, &ar->winrct)) { CTX_wm_region_set(C, ar); - + /* does polls for drop regions and checks uibuts */ /* need to be here to make sure region context is true */ if(ELEM(event->type, MOUSEMOVE, EVT_DROP)) { wm_region_mouse_co(C, event); wm_drags_check_ops(C, event); } - + action |= wm_handlers_do(C, event, &ar->handlers); - + doit |= (BLI_in_rcti(&ar->winrct, event->x, event->y)); - + if(action & WM_HANDLER_BREAK) break; } @@ -1692,7 +1686,7 @@ void wm_event_do_handlers(bContext *C) /* NOTE: do not escape on WM_HANDLER_BREAK, mousemove needs handled for previous area */ } } - + if((action & WM_HANDLER_BREAK) == 0) { /* also some non-modal handlers need active area/region */ CTX_wm_area_set(C, area_event_inside(C, event->x, event->y)); @@ -1712,7 +1706,7 @@ void wm_event_do_handlers(bContext *C) win->eventstate->prevy= event->y; } } - + /* store last event for this window */ /* mousemove and timer events don't overwrite last type */ if (event->type != MOUSEMOVE && !ISTIMER(event->type)) { @@ -1747,9 +1741,9 @@ void wm_event_do_handlers(bContext *C) /* unlink and free here, blender-quit then frees all */ BLI_remlink(&win->queue, event); wm_event_free(event); - + } - + /* only add mousemove when queue was read entirely */ if(win->addmousemove && win->eventstate) { wmEvent event= *(win->eventstate); @@ -1759,7 +1753,7 @@ void wm_event_do_handlers(bContext *C) wm_event_add(win, &event); win->addmousemove= 0; } - + CTX_wm_window_set(C, NULL); } } @@ -1770,10 +1764,10 @@ void WM_event_fileselect_event(bContext *C, void *ophandle, int eventval) { /* add to all windows! */ wmWindow *win; - + for(win= CTX_wm_manager(C)->windows.first; win; win= win->next) { wmEvent event= *win->eventstate; - + event.type= EVT_FILESELECT; event.val= eventval; event.customdata= ophandle; // only as void pointer type check @@ -1795,15 +1789,15 @@ void WM_event_add_fileselect(bContext *C, wmOperator *op) wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "fileselect handler"); wmWindow *win= CTX_wm_window(C); int full= 1; // XXX preset? - + handler->type= WM_HANDLER_FILESELECT; handler->op= op; handler->op_area= CTX_wm_area(C); handler->op_region= CTX_wm_region(C); handler->filescreen= CTX_wm_screen(C); - + BLI_addhead(&win->modalhandlers, handler); - + WM_event_fileselect_event(C, op, full?EVT_FILESELECT_FULL_OPEN:EVT_FILESELECT_OPEN); } @@ -1817,7 +1811,7 @@ wmEventHandler *WM_event_add_modal_handler(bContext *C, wmOperator *op) { wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event modal handler"); wmWindow *win= CTX_wm_window(C); - + /* operator was part of macro */ if(op->opm) { /* give the mother macro to the handler */ @@ -1827,10 +1821,10 @@ wmEventHandler *WM_event_add_modal_handler(bContext *C, wmOperator *op) } else handler->op= op; - + handler->op_area= CTX_wm_area(C); /* means frozen screen context for modal handlers! */ handler->op_region= CTX_wm_region(C); - + BLI_addhead(&win->modalhandlers, handler); return handler; @@ -1849,7 +1843,7 @@ wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap for(handler= handlers->first; handler; handler= handler->next) if(handler->keymap==keymap) return handler; - + handler= MEM_callocN(sizeof(wmEventHandler), "event keymap handler"); BLI_addtail(handlers, handler); handler->keymap= keymap; @@ -1861,20 +1855,20 @@ wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap wmEventHandler *WM_event_add_keymap_handler_priority(ListBase *handlers, wmKeyMap *keymap, int priority) { wmEventHandler *handler; - + WM_event_remove_keymap_handler(handlers, keymap); - + handler= MEM_callocN(sizeof(wmEventHandler), "event keymap handler"); BLI_addhead(handlers, handler); handler->keymap= keymap; - + return handler; } wmEventHandler *WM_event_add_keymap_handler_bb(ListBase *handlers, wmKeyMap *keymap, rcti *bblocal, rcti *bbwin) { wmEventHandler *handler= WM_event_add_keymap_handler(handlers, keymap); - + if(handler) { handler->bblocal= bblocal; handler->bbwin= bbwin; @@ -1885,7 +1879,7 @@ wmEventHandler *WM_event_add_keymap_handler_bb(ListBase *handlers, wmKeyMap *key void WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap) { wmEventHandler *handler; - + for(handler= handlers->first; handler; handler= handler->next) { if(handler->keymap==keymap) { BLI_remlink(handlers, handler); @@ -1904,16 +1898,16 @@ wmEventHandler *WM_event_add_ui_handler(const bContext *C, ListBase *handlers, w handler->ui_area= (C)? CTX_wm_area(C): NULL; handler->ui_region= (C)? CTX_wm_region(C): NULL; handler->ui_menu= (C)? CTX_wm_menu(C): NULL; - + BLI_addhead(handlers, handler); - + return handler; } void WM_event_remove_ui_handler(ListBase *handlers, wmUIHandlerFunc func, wmUIHandlerRemoveFunc remove, void *userdata) { wmEventHandler *handler; - + for(handler= handlers->first; handler; handler= handler->next) { if(handler->ui_handle == func && handler->ui_remove == remove && handler->ui_userdata == userdata) { BLI_remlink(handlers, handler); @@ -1931,13 +1925,13 @@ wmEventHandler *WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropb for(handler= handlers->first; handler; handler= handler->next) if(handler->dropboxes==dropboxes) return handler; - + handler= MEM_callocN(sizeof(wmEventHandler), "dropbox handler"); - + /* dropbox stored static, no free or copy */ handler->dropboxes= dropboxes; BLI_addhead(handlers, handler); - + return handler; } @@ -1966,7 +1960,7 @@ void WM_event_remove_handler(ListBase *handlers, wmEventHandler *handler) void WM_event_add_mousemove(bContext *C) { wmWindow *window= CTX_wm_window(C); - + window->addmousemove= 1; } @@ -1976,7 +1970,7 @@ int WM_modal_tweak_exit(wmEvent *evt, int tweak_event) /* user preset or keymap? dunno... */ // XXX WTH is this? int tweak_modal= (U.flag & USER_RELEASECONFIRM)==0; - + switch(tweak_event) { case EVT_TWEAK_L: case EVT_TWEAK_M: @@ -2010,7 +2004,7 @@ static int convert_key(GHOST_TKey key) case GHOST_kKeyLinefeed: return LINEFEEDKEY; case GHOST_kKeyClear: return 0; case GHOST_kKeyEnter: return RETKEY; - + case GHOST_kKeyEsc: return ESCKEY; case GHOST_kKeySpace: return SPACEKEY; case GHOST_kKeyQuote: return QUOTEKEY; @@ -2018,15 +2012,15 @@ static int convert_key(GHOST_TKey key) case GHOST_kKeyMinus: return MINUSKEY; case GHOST_kKeyPeriod: return PERIODKEY; case GHOST_kKeySlash: return SLASHKEY; - + case GHOST_kKeySemicolon: return SEMICOLONKEY; case GHOST_kKeyEqual: return EQUALKEY; - + case GHOST_kKeyLeftBracket: return LEFTBRACKETKEY; case GHOST_kKeyRightBracket: return RIGHTBRACKETKEY; case GHOST_kKeyBackslash: return BACKSLASHKEY; case GHOST_kKeyAccentGrave: return ACCENTGRAVEKEY; - + case GHOST_kKeyLeftShift: return LEFTSHIFTKEY; case GHOST_kKeyRightShift: return RIGHTSHIFTKEY; case GHOST_kKeyLeftControl: return LEFTCTRLKEY; @@ -2034,93 +2028,135 @@ static int convert_key(GHOST_TKey key) case GHOST_kKeyCommand: return COMMANDKEY; case GHOST_kKeyLeftAlt: return LEFTALTKEY; case GHOST_kKeyRightAlt: return RIGHTALTKEY; - + case GHOST_kKeyCapsLock: return CAPSLOCKKEY; case GHOST_kKeyNumLock: return 0; case GHOST_kKeyScrollLock: return 0; - + case GHOST_kKeyLeftArrow: return LEFTARROWKEY; case GHOST_kKeyRightArrow: return RIGHTARROWKEY; case GHOST_kKeyUpArrow: return UPARROWKEY; case GHOST_kKeyDownArrow: return DOWNARROWKEY; - + case GHOST_kKeyPrintScreen: return 0; case GHOST_kKeyPause: return PAUSEKEY; - + case GHOST_kKeyInsert: return INSERTKEY; case GHOST_kKeyDelete: return DELKEY; case GHOST_kKeyHome: return HOMEKEY; case GHOST_kKeyEnd: return ENDKEY; case GHOST_kKeyUpPage: return PAGEUPKEY; case GHOST_kKeyDownPage: return PAGEDOWNKEY; - + case GHOST_kKeyNumpadPeriod: return PADPERIOD; case GHOST_kKeyNumpadEnter: return PADENTER; case GHOST_kKeyNumpadPlus: return PADPLUSKEY; case GHOST_kKeyNumpadMinus: return PADMINUS; case GHOST_kKeyNumpadAsterisk: return PADASTERKEY; case GHOST_kKeyNumpadSlash: return PADSLASHKEY; - + case GHOST_kKeyGrLess: return GRLESSKEY; - + default: return UNKNOWNKEY; /* GHOST_kKeyUnknown */ } } } +#if 0 /* adds customdata to event */ static void update_tablet_data(wmWindow *win, wmEvent *event) { const GHOST_TabletData *td= GHOST_GetTabletData(win->ghostwin); - + /* if there's tablet data from an active tablet device then add it */ if ((td != NULL) && td->Active != GHOST_kTabletModeNone) { struct wmTabletData *wmtab= MEM_mallocN(sizeof(wmTabletData), "customdata tablet"); - + wmtab->Active = (int)td->Active; wmtab->Pressure = td->Pressure; wmtab->Xtilt = td->Xtilt; wmtab->Ytilt = td->Ytilt; - + event->custom= EVT_DATA_TABLET; event->customdata= wmtab; event->customdatafree= 1; } } +#endif + +/* adds customdata to event */ +static void attach_tablet_data(wmEvent* event, const GHOST_TabletData* ghost) +{ + if (ghost->Active != GHOST_kTabletModeNone) + { + wmTabletData* data = MEM_mallocN(sizeof(wmTabletData), "customdata tablet"); + + data->Active = ghost->Active; + data->Pressure = ghost->Pressure; + data->Xtilt = ghost->Xtilt; + data->Ytilt = ghost->Ytilt; + + event->custom = EVT_DATA_TABLET; + event->customdata = data; + event->customdatafree = 1; + + printf("+ pressure = %.2f tilt = %.2f %2f\n", data->Pressure, data->Xtilt, data->Ytilt); + } +} + +/* adds customdata to event */ +static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* ghost) +{ + wmNDOFMotionData* data = MEM_mallocN(sizeof(wmNDOFMotionData), "customdata NDOF"); + + data->tx = ghost->tx; + data->ty = ghost->ty; + data->tz = ghost->tz; + + data->rx = ghost->rx; + data->ry = ghost->ry; + data->rz = ghost->rz; + + data->dt = ghost->dt; + + event->custom = EVT_DATA_NDOF_MOTION; + event->customdata = data; + event->customdatafree = 1; +} /* imperfect but probably usable... draw/enable drags to other windows */ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *win, wmEvent *evt) { short mx= evt->x, my= evt->y; - + if(wm->windows.first== wm->windows.last) return NULL; - + /* top window bar... */ if(mx<0 || my<0 || mx>win->sizex || my>win->sizey+30) { wmWindow *owin; wmEventHandler *handler; - + /* let's skip windows having modal handlers now */ /* potential XXX ugly... I wouldn't have added a modalhandlers list (introduced in rev 23331, ton) */ for(handler= win->modalhandlers.first; handler; handler= handler->next) if(handler->ui_handle || handler->op) return NULL; - + /* to desktop space */ mx+= win->posx; my+= win->posy; - + /* check other windows to see if it has mouse inside */ for(owin= wm->windows.first; owin; owin= owin->next) { - + if(owin!=win) { if(mx-owin->posx >= 0 && my-owin->posy >= 0 && mx-owin->posx <= owin->sizex && my-owin->posy <= owin->sizey) { evt->x= mx-owin->posx; evt->y= my-owin->posy; - + return owin; } } @@ -2130,34 +2166,34 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi } /* windows store own event queues, no bContext here */ -/* time is in 1000s of seconds, from ghost */ +/* time is in 1000s of seconds (or milliseconds?), from ghost */ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int time, void *customdata) { wmWindow *owin; wmEvent event, *evt= win->eventstate; - + /* initialize and copy state (only mouse x y and modifiers) */ event= *evt; - + switch (type) { /* mouse move */ case GHOST_kEventCursorMove: { if(win->active) { GHOST_TEventCursorData *cd= customdata; wmEvent *lastevent= win->queue.last; - + #if defined(__APPLE__) && defined(GHOST_COCOA) //Cocoa already uses coordinates with y=0 at bottom, and returns inwindow coordinates on mouse moved event evt->x= cd->x; evt->y= cd->y; #else int cx, cy; - + GHOST_ScreenToClient(win->ghostwin, cd->x, cd->y, &cx, &cy); evt->x= cx; evt->y= (win->sizey-1) - cy; #endif - + event.x= evt->x; event.y= evt->y; @@ -2169,23 +2205,23 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t if(lastevent && lastevent->type == MOUSEMOVE) lastevent->type = INBETWEEN_MOUSEMOVE; - update_tablet_data(win, &event); + attach_tablet_data(&event, &(cd->tablet)); + // update_tablet_data(win, &event); wm_event_add(win, &event); - + /* also add to other window if event is there, this makes overdraws disappear nicely */ /* it remaps mousecoord to other window in event */ owin= wm_event_cursor_other_windows(wm, win, &event); if(owin) { wmEvent oevent= *(owin->eventstate); - + oevent.x=owin->eventstate->x= event.x; oevent.y=owin->eventstate->y= event.y; oevent.type= MOUSEMOVE; - - update_tablet_data(owin, &oevent); + + // update_tablet_data(owin, &oevent); wm_event_add(owin, &oevent); } - } break; } @@ -2218,8 +2254,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t // Use prevx/prevy so we can calculate the delta later event.prevx= event.x - pd->deltaX; event.prevy= event.y - pd->deltaY; - - update_tablet_data(win, &event); + + // [mce] tablet never sends trackpad events. + // update_tablet_data(win, &event); wm_event_add(win, &event); break; } @@ -2239,25 +2276,27 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t event.type= BUTTON5MOUSE; else event.type= MIDDLEMOUSE; - + /* add to other window if event is there (not to both!) */ owin= wm_event_cursor_other_windows(wm, win, &event); if(owin) { wmEvent oevent= *(owin->eventstate); - + oevent.x= event.x; oevent.y= event.y; oevent.type= event.type; oevent.val= event.val; - - update_tablet_data(owin, &oevent); + + attach_tablet_data(&oevent, &(bd->tablet)); + // update_tablet_data(owin, &oevent); wm_event_add(owin, &oevent); } else { - update_tablet_data(win, &event); + attach_tablet_data(&event, &(bd->tablet)); + // update_tablet_data(win, &event); wm_event_add(win, &event); } - + break; } /* keyboard */ @@ -2267,11 +2306,11 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t event.type= convert_key(kd->key); event.ascii= kd->ascii; event.val= (type==GHOST_kEventKeyDown)?KM_PRESS:KM_RELEASE; - + /* exclude arrow keys, esc, etc from text input */ if(type==GHOST_kEventKeyUp || (event.ascii<32 && event.ascii>0)) event.ascii= '\0'; - + /* modifiers */ if (event.type==LEFTSHIFTKEY || event.type==RIGHTSHIFTKEY) { event.shift= evt->shift= (event.val==KM_PRESS); @@ -2306,29 +2345,30 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t key we don't want the key modifier */ if(event.keymodifier == event.type) event.keymodifier= 0; - + /* if test_break set, it catches this. XXX Keep global for now? */ if(event.type==ESCKEY) G.afbreek= 1; - + wm_event_add(win, &event); - + break; } - + case GHOST_kEventWheel: { GHOST_TEventWheelData* wheelData = customdata; - + if (wheelData->z > 0) event.type= WHEELUPMOUSE; else event.type= WHEELDOWNMOUSE; - + event.val= KM_PRESS; wm_event_add(win, &event); - + break; } + case GHOST_kEventTimer: { event.type= TIMER; event.custom= EVT_DATA_TIMER; @@ -2338,6 +2378,36 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t break; } + case GHOST_kEventNDOFMotion: { + event.type = NDOF_MOTION; + attach_ndof_data(&event, customdata); + wm_event_add(win, &event); + + break; + } + + case GHOST_kEventNDOFButton: { + GHOST_TEventNDOFButtonData* e = customdata; + + event.type = NDOF_BUTTON_NONE + e->button; + + switch (e->action) { + case GHOST_kPress: + event.val = KM_PRESS; + break; + case GHOST_kRelease: + event.val = KM_RELEASE; + break; + } + + event.custom = 0; + event.customdata = NULL; + + wm_event_add(win, &event); + + break; + } + case GHOST_kEventUnknown: case GHOST_kNumEventTypes: break; @@ -2347,8 +2417,6 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t wm_event_add(win, &event); break; - } - } } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index e4bb5b797d3..d9dad900632 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -796,8 +796,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private) } } - - break; } @@ -805,7 +803,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private) wm_event_add_ghostevent(wm, win, type, time, data); break; } - } return 1; } diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index 7228a6dcd93..bbf9ed9af6a 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -83,4 +83,3 @@ extern int circle_select_size; #endif #endif /* WM_H */ - diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index 6cb3971bd21..9db84bf7795 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -36,42 +36,66 @@ #define WM_EVENT_TYPES_H /* customdata type */ -#define EVT_DATA_TABLET 1 -#define EVT_DATA_GESTURE 2 -#define EVT_DATA_TIMER 3 -#define EVT_DATA_LISTBASE 4 +#define EVT_DATA_TABLET 1 +#define EVT_DATA_GESTURE 2 +#define EVT_DATA_TIMER 3 +#define EVT_DATA_LISTBASE 4 +#define EVT_DATA_NDOF_MOTION 5 /* tablet active, matches GHOST_TTabletMode */ +/* [mce] also matches my own TabletTool.type */ #define EVT_TABLET_NONE 0 #define EVT_TABLET_STYLUS 1 #define EVT_TABLET_ERASER 2 -#define MOUSEX 0x004 -#define MOUSEY 0x005 +/* [mce] what are these for? */ +#define MOUSEX 0x004 +#define MOUSEY 0x005 /* MOUSE : 0x00x */ -#define LEFTMOUSE 0x001 -#define MIDDLEMOUSE 0x002 -#define RIGHTMOUSE 0x003 -#define MOUSEMOVE 0x004 +#define LEFTMOUSE 0x001 +#define MIDDLEMOUSE 0x002 +#define RIGHTMOUSE 0x003 +#define MOUSEMOVE 0x004 /* only use if you want user option switch possible */ #define ACTIONMOUSE 0x005 #define SELECTMOUSE 0x006 /* Extra mouse buttons */ -#define BUTTON4MOUSE 0x007 +#define BUTTON4MOUSE 0x007 #define BUTTON5MOUSE 0x008 /* Extra trackpad gestures */ #define MOUSEPAN 0x00e #define MOUSEZOOM 0x00f #define MOUSEROTATE 0x010 /* defaults from ghost */ -#define WHEELUPMOUSE 0x00a +#define WHEELUPMOUSE 0x00a #define WHEELDOWNMOUSE 0x00b /* mapped with userdef */ #define WHEELINMOUSE 0x00c #define WHEELOUTMOUSE 0x00d #define INBETWEEN_MOUSEMOVE 0x011 +/* NDOF (from SpaceNavigator & friends) */ +#define NDOF_MOTION 0x12 +enum { + NDOF_BUTTON_NONE = NDOF_MOTION, /* never sent, used during translation */ + NDOF_BUTTON1, + NDOF_BUTTON2/*, + NDOF_BUTTON3, + NDOF_BUTTON4, + NDOF_BUTTON5, + NDOF_BUTTON6, + NDOF_BUTTON7, + NDOF_BUTTON8, + NDOF_BUTTON9, + NDOF_BUTTON10, + NDOF_BUTTON11, + NDOF_BUTTON12, + NDOF_BUTTON13, + NDOF_BUTTON14, + NDOF_BUTTON15, + NDOF_BUTTON16*/ + }; /* SYSTEM : 0x01xx */ #define INPUTCHANGE 0x0103 /* input connected or disconnected */ @@ -126,9 +150,9 @@ #define CAPSLOCKKEY 211 #define LEFTCTRLKEY 212 -#define LEFTALTKEY 213 -#define RIGHTALTKEY 214 -#define RIGHTCTRLKEY 215 +#define LEFTALTKEY 213 +#define RIGHTALTKEY 214 +#define RIGHTCTRLKEY 215 #define RIGHTSHIFTKEY 216 #define LEFTSHIFTKEY 217 @@ -169,8 +193,8 @@ #define PADPERIOD 199 -#define PADSLASHKEY 161 -#define PADASTERKEY 160 +#define PADSLASHKEY 161 +#define PADASTERKEY 160 #define PADMINUS 162 #define PADENTER 163 @@ -299,4 +323,3 @@ #endif /* WM_EVENT_TYPES_H */ - -- cgit v1.2.3 From 4bf887d4d3592e955144388305ae801040a57701 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 10 Aug 2010 09:51:22 +0000 Subject: SpaceNav works in 3D view on Windows. Cleaned up related WIP code. --- source/blender/editors/space_view3d/view3d_edit.c | 3 ++- source/blender/windowmanager/intern/wm_event_system.c | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 8dd901d9e54..874a2f778f5 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -27,7 +27,6 @@ */ #include -#include #include #include @@ -879,6 +878,7 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } +#if 0 static int viewndof_invoke_1st_try(bContext *C, wmOperator *op, wmEvent *event) { wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; @@ -961,6 +961,7 @@ static int viewndof_invoke_2nd_try(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } +#endif void VIEW3D_OT_ndof(struct wmOperatorType *ot) { diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index e281e65539e..bce1cc22f7f 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -29,7 +29,6 @@ #include #include #include -#include // [mce] debug, remove when finished #include "DNA_listBase.h" #include "DNA_screen_types.h" -- cgit v1.2.3 From 91e2a5517190b532a78515956391d2e699ae88b8 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 14 Aug 2010 21:01:09 +0000 Subject: continued Win32 tablet hackery --- .../blender/windowmanager/intern/wm_event_system.c | 35 ++++------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index bce1cc22f7f..6a2102633c3 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1977,7 +1977,7 @@ int WM_modal_tweak_exit(wmEvent *evt, int tweak_event) if(evt->val==tweak_modal) return 1; default: - /* this case is when modal callcback didnt get started with a tweak */ + /* this case is when modal callback didnt get started with a tweak */ if(evt->val) return 1; } @@ -2062,28 +2062,6 @@ static int convert_key(GHOST_TKey key) } } -#if 0 -/* adds customdata to event */ -static void update_tablet_data(wmWindow *win, wmEvent *event) -{ - const GHOST_TabletData *td= GHOST_GetTabletData(win->ghostwin); - - /* if there's tablet data from an active tablet device then add it */ - if ((td != NULL) && td->Active != GHOST_kTabletModeNone) { - struct wmTabletData *wmtab= MEM_mallocN(sizeof(wmTabletData), "customdata tablet"); - - wmtab->Active = (int)td->Active; - wmtab->Pressure = td->Pressure; - wmtab->Xtilt = td->Xtilt; - wmtab->Ytilt = td->Ytilt; - - event->custom= EVT_DATA_TABLET; - event->customdata= wmtab; - event->customdatafree= 1; - } -} -#endif - /* adds customdata to event */ static void attach_tablet_data(wmEvent* event, const GHOST_TabletData* ghost) { @@ -2100,7 +2078,7 @@ static void attach_tablet_data(wmEvent* event, const GHOST_TabletData* ghost) event->customdata = data; event->customdatafree = 1; - printf("+ pressure = %.2f tilt = %.2f %2f\n", data->Pressure, data->Xtilt, data->Ytilt); + // printf("+ pressure = %.2f tilt = %.2f %.2f\n", data->Pressure, data->Xtilt, data->Ytilt); } } @@ -2165,7 +2143,7 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi } /* windows store own event queues, no bContext here */ -/* time is in 1000s of seconds (or milliseconds?), from ghost */ +/* time is in milliseconds, from ghost */ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int time, void *customdata) { wmWindow *owin; @@ -2205,7 +2183,6 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t lastevent->type = INBETWEEN_MOUSEMOVE; attach_tablet_data(&event, &(cd->tablet)); - // update_tablet_data(win, &event); wm_event_add(win, &event); /* also add to other window if event is there, this makes overdraws disappear nicely */ @@ -2218,7 +2195,6 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t oevent.y=owin->eventstate->y= event.y; oevent.type= MOUSEMOVE; - // update_tablet_data(owin, &oevent); wm_event_add(owin, &oevent); } } @@ -2263,7 +2239,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t case GHOST_kEventButtonDown: case GHOST_kEventButtonUp: { GHOST_TEventButtonData *bd= customdata; - event.val= (type==GHOST_kEventButtonDown) ? KM_PRESS:KM_RELEASE; /* Note!, this starts as 0/1 but later is converted to KM_PRESS/KM_RELEASE by tweak */ + event.val= (type==GHOST_kEventButtonDown) ? KM_PRESS:KM_RELEASE; + /* Note!, this starts as 0/1 but later is converted to KM_PRESS/KM_RELEASE by tweak */ if (bd->button == GHOST_kButtonMaskLeft) event.type= LEFTMOUSE; @@ -2287,12 +2264,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int t oevent.val= event.val; attach_tablet_data(&oevent, &(bd->tablet)); - // update_tablet_data(owin, &oevent); wm_event_add(owin, &oevent); } else { attach_tablet_data(&event, &(bd->tablet)); - // update_tablet_data(win, &event); wm_event_add(win, &event); } -- cgit v1.2.3 From 162795cffec42cbd3c426c62b7eae2992b93a7cb Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Fri, 21 Jan 2011 09:59:58 +0000 Subject: applied SpaceNav patch from Tom Acunzo --- source/blender/editors/space_view3d/view3d_edit.c | 85 +++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 874a2f778f5..2c00d2dcba4 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -833,6 +833,7 @@ float ndof_to_angle_axis(const float ndof[3], float axis[3]) return angular_velocity; } +#if 0 // my version static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) { wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; @@ -877,6 +878,90 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; } +#endif + +// Tom's version +static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + float phi, q1[4]; + float m[3][3]; + float m_inv[3][3]; + float xvec[3] = {1,0,0}; + float yvec[3] = {0,1,0}; + float vec[3]; + float mat[3][3]; + const float rotaSensitivity = 0.007; + const float tranSensitivity = 0.120; + + ARegion *ar= CTX_wm_region(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + View3D *v3d = CTX_wm_view3d(C); + + float dt = ndof->dt; + + if (dt > 0.25f) { + /* this is probably the first event for this motion, so set dt to something reasonable */ + dt = 0.0125f; + } + + /* Get the 3x3 matrix and its inverse from the quaternion */ + quat_to_mat3(m,rv3d->viewquat); + invert_m3_m3(m_inv,m); + + /* Determine the direction of the x vector (for rotating up and down) */ + /* This can likely be computed directly from the quaternion. */ + mul_m3_v3(m_inv,xvec); + + //if(rv3d->persp=!= RV3D_PERSP) //Camera control not supported yet + /* Lock fixed views out of using rotation controls */ + if(rv3d->view!=RV3D_VIEW_FRONT && rv3d->view!=RV3D_VIEW_BACK) + if(rv3d->view!=RV3D_VIEW_TOP && rv3d->view!=RV3D_VIEW_BOTTOM) + if(rv3d->view!=RV3D_VIEW_RIGHT && rv3d->view!=RV3D_VIEW_LEFT) { + // Perform the up/down rotation + phi = (rotaSensitivity+dt) * -ndof->rx; + q1[0] = cos(phi); + mul_v3_v3fl(q1+1, xvec, sin(phi)); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + + // Perform the left/right rotation + mul_m3_v3(m_inv,yvec); + phi = (rotaSensitivity+dt) * ndof->ry; + q1[0] = cos(phi); + mul_v3_v3fl(q1+1, yvec, sin(phi)); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + + // Perform the orbital rotation + phi = (rotaSensitivity+dt) * ndof->rz; + q1[0] = cos(phi); + q1[1] = q1[2] = 0.0; + q1[3] = sin(phi); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + } + + // Perform Pan translation + vec[0]= (tranSensitivity+dt) * ndof->tx; + vec[1]= (tranSensitivity+dt) * ndof->tz; + //vec[2]= 0.0f;//tranSensitivity * ndof->ty; + //window_to_3d_delta(ar, vec, -ndof->tx, -ndof->tz); // experimented a little instead of above + copy_m3_m4(mat, rv3d->viewinv); + mat[2][2] = 0.0f; + mul_m3_v3(mat, vec); + // translate the view + add_v3_v3(rv3d->ofs, vec); + + // Perform Zoom translation + if (ndof->ty!=0.0f){ // TODO - need to add limits to prevent flipping past gridlines + rv3d->dist += (tranSensitivity+dt)* ndof->ty; + // printf("dist %5.3f view %d grid %f\n",rv3d->dist,rv3d->view,v3d->grid); + } + + //printf("Trans tx:%5.2f ty:%5.2f tz:%5.2f \n",ndof->tx, ndof->ty, ndof->tz); + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; +} #if 0 static int viewndof_invoke_1st_try(bContext *C, wmOperator *op, wmEvent *event) -- cgit v1.2.3 From 7b124242e7a2f5138f245af6af506081b83e5103 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 11 Jun 2011 00:25:48 +0000 Subject: SpaceNav works on Linux --- source/blender/editors/space_view3d/view3d_edit.c | 8 ++++---- source/blender/windowmanager/intern/wm_event_system.c | 6 +++++- source/blender/windowmanager/intern/wm_window.c | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 315c8b39f44..76d595c275b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -958,10 +958,6 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) RegionView3D* rv3d = CTX_wm_region_view3d(C); - if (dt > 0.25f) - /* this is probably the first event for this motion, so set dt to something reasonable */ - dt = 0.0125f; - /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ float phi, q1[4]; float m[3][3]; @@ -970,6 +966,10 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) const float sensitivity = 0.035; + if (dt > 0.25f) + /* this is probably the first event for this motion, so set dt to something reasonable */ + dt = 0.0125f; + /* Get the 3x3 matrix and its inverse from the quaternion */ quat_to_mat3(m,rv3d->viewquat); invert_m3_m3(m_inv,m); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 96071bc442b..56805aa3d3f 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2375,7 +2375,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U { wmWindow *owin; wmEvent event, *evt= win->eventstate; - + + printf("ghost (%d) --> wm\n", type); + /* initialize and copy state (only mouse x y and modifiers) */ event= *evt; @@ -2579,6 +2581,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } case GHOST_kEventNDOFMotion: { + puts("ndof motion in wm"); event.type = NDOF_MOTION; attach_ndof_data(&event, customdata); wm_event_add(win, &event); @@ -2588,6 +2591,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U case GHOST_kEventNDOFButton: { GHOST_TEventNDOFButtonData* e = customdata; + puts("ndof button in wm"); event.type = NDOF_BUTTON_NONE + e->button; diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 9ee39132521..7524174c345 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -621,12 +621,12 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private) if (!ghostwin) { // XXX - should be checked, why are we getting an event here, and // what is it? - + puts(" event has no window"); return 1; } else if (!GHOST_ValidWindow(g_system, ghostwin)) { // XXX - should be checked, why are we getting an event here, and // what is it? - + puts(" event has invalid window"); return 1; } else { win= GHOST_GetWindowUserData(ghostwin); -- cgit v1.2.3 From 6aa77771443391c827268ef0eac7a5e4382a3e44 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Wed, 15 Jun 2011 02:40:25 +0000 Subject: removed temporary debug logging --- source/blender/windowmanager/intern/wm_event_system.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 56805aa3d3f..b41eebc5298 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2376,8 +2376,6 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U wmWindow *owin; wmEvent event, *evt= win->eventstate; - printf("ghost (%d) --> wm\n", type); - /* initialize and copy state (only mouse x y and modifiers) */ event= *evt; @@ -2581,7 +2579,6 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } case GHOST_kEventNDOFMotion: { - puts("ndof motion in wm"); event.type = NDOF_MOTION; attach_ndof_data(&event, customdata); wm_event_add(win, &event); @@ -2591,7 +2588,6 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U case GHOST_kEventNDOFButton: { GHOST_TEventNDOFButtonData* e = customdata; - puts("ndof button in wm"); event.type = NDOF_BUTTON_NONE + e->button; -- cgit v1.2.3 From 18b5dac5cad91abf4787d7fd7a06029a02b6609d Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 16 Jun 2011 19:45:38 +0000 Subject: Standard views (front, top, etc.) work from buttons on SpaceExplorer and SpacePilotPro. Linux can now determine which NDOF device is plugged in. --- source/blender/editors/space_view3d/view3d_ops.c | 8 +++- source/blender/windowmanager/wm_event_types.h | 58 ++++++++++++++++-------- 2 files changed, 47 insertions(+), 19 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 3e99c6992d1..2dd560a6408 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -163,8 +163,14 @@ void view3d_keymap(wmKeyConfig *keyconf) RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1); /* 3D mouse */ - WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON1, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_ndof", NDOF_MOTION, 0, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BACK, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BACK); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_LEFT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_LEFT); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BOTTOM, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BOTTOM); /* numpad view hotkeys*/ RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA); diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index 748f5018e1a..ed500ccd5c5 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -79,25 +79,47 @@ #define INBETWEEN_MOUSEMOVE 17 /* NDOF (from SpaceNavigator & friends) */ -#define NDOF_MOTION 0x12 +#define NDOF_MOTION 0x12 // keep in sync with GHOST_NDOFManager.h enum { - NDOF_BUTTON_NONE = NDOF_MOTION, /* never sent, used internally */ - NDOF_BUTTON1, - NDOF_BUTTON2/*, the following buttons will be supported soon... - NDOF_BUTTON3, and possibly get meaningful names - NDOF_BUTTON4, - NDOF_BUTTON5, - NDOF_BUTTON6, - NDOF_BUTTON7, - NDOF_BUTTON8, - NDOF_BUTTON9, - NDOF_BUTTON10, - NDOF_BUTTON11, - NDOF_BUTTON12, - NDOF_BUTTON13, - NDOF_BUTTON14, - NDOF_BUTTON15, - NDOF_BUTTON16*/ + // used internally, never sent + NDOF_BUTTON_NONE = NDOF_MOTION, + // these two are available from any 3Dconnexion device + NDOF_BUTTON_MENU, + NDOF_BUTTON_FIT, + // standard views + NDOF_BUTTON_TOP, + NDOF_BUTTON_BOTTOM, + NDOF_BUTTON_LEFT, + NDOF_BUTTON_RIGHT, + NDOF_BUTTON_FRONT, + NDOF_BUTTON_BACK, + // more views + NDOF_BUTTON_ISO1, + NDOF_BUTTON_ISO2, + // 90 degree rotations + NDOF_BUTTON_ROLL_CW, + NDOF_BUTTON_ROLL_CCW, + NDOF_BUTTON_SPIN_CW, + NDOF_BUTTON_SPIN_CCW, + NDOF_BUTTON_TILT_CW, + NDOF_BUTTON_TILT_CCW, + // device control + NDOF_BUTTON_ROTATE, + NDOF_BUTTON_PANZOOM, + NDOF_BUTTON_DOMINANT, + NDOF_BUTTON_PLUS, + NDOF_BUTTON_MINUS, + // general-purpose buttons + NDOF_BUTTON_1, + NDOF_BUTTON_2, + NDOF_BUTTON_3, + NDOF_BUTTON_4, + NDOF_BUTTON_5, + NDOF_BUTTON_6, + NDOF_BUTTON_7, + NDOF_BUTTON_8, + NDOF_BUTTON_9, + NDOF_BUTTON_10, }; -- cgit v1.2.3 From e46e2d9d5400729da2980cc5b1f2e24df9207c5a Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 18 Jun 2011 20:30:09 +0000 Subject: resolved collision among WM event types, ndof no longer encroaches on keyboard turf --- source/blender/windowmanager/wm_event_types.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index ed500ccd5c5..210dd902b99 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -78,8 +78,13 @@ #define WHEELOUTMOUSE 13 #define INBETWEEN_MOUSEMOVE 17 -/* NDOF (from SpaceNavigator & friends) */ -#define NDOF_MOTION 0x12 // keep in sync with GHOST_NDOFManager.h + +/* NDOF (from SpaceNavigator & friends) + These should be kept in sync with GHOST_NDOFManager.h + Ordering matters, exact values do not. */ + +#define NDOF_MOTION 400 + enum { // used internally, never sent NDOF_BUTTON_NONE = NDOF_MOTION, -- cgit v1.2.3 From 015b0ea00afc4f12be5fc830152930cd9bbb6dac Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 20 Jun 2011 01:54:49 +0000 Subject: small fix to turntable mode, first attempt at trackball code, ndof now respects view locking and updates 'User Persp' etc. --- source/blender/editors/space_view3d/view3d_edit.c | 110 +++++++++++++++------- 1 file changed, 78 insertions(+), 32 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 76d595c275b..d1be99ce7ee 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -954,46 +954,92 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) { wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - float dt = ndof->dt; - - RegionView3D* rv3d = CTX_wm_region_view3d(C); - - /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ - float phi, q1[4]; - float m[3][3]; - float m_inv[3][3]; - float xvec[3] = {1,0,0}; - - const float sensitivity = 0.035; + float sensitivity = 1.f; /* ooh, magic number! + const float sensitivity = 0.035; /* ooh, magic number! + there will be several of these as interactions get tuned */ + float dt = ndof->dt; if (dt > 0.25f) /* this is probably the first event for this motion, so set dt to something reasonable */ + /* TODO: replace such guesswork with a flag or field from the NDOF manager */ dt = 0.0125f; - /* Get the 3x3 matrix and its inverse from the quaternion */ - quat_to_mat3(m,rv3d->viewquat); - invert_m3_m3(m_inv,m); - - /* Determine the direction of the x vector (for rotating up and down) */ - /* This can likely be computed directly from the quaternion. */ - mul_m3_v3(m_inv,xvec); - - /* Perform the up/down rotation */ - phi = sensitivity * -ndof->rx; - q1[0] = cos(phi); - mul_v3_v3fl(q1+1, xvec, sin(phi)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + RegionView3D* rv3d = CTX_wm_region_view3d(C); - /* Perform the orbital rotation */ - phi = sensitivity * ndof->rz; - q1[0] = cos(phi); - q1[1] = q1[2] = 0.0; - q1[3] = sin(phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + int /* bool */ has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); + if (has_rotation) + rv3d->view = RV3D_VIEW_USER; + + if (has_rotation) { + if (U.flag & USER_TRACKBALL) { + /* TODO: write trackball code! */ + + float axis[3] = {ndof->rx, ndof->ry, ndof->rz}; + float angle = sensitivity * dt * ndof_to_angle_axis(axis, axis); + float rotation[4], rotationconj[4]; + float view[4], viewconj[4]; + + // convert to quaternion + axis_angle_to_quat(rotation, axis, angle); + + // extract rotation component of viewquat + copy_qt_qt(view, rv3d->viewquat); + invert_qt(view); + normalize_qt(view); + copy_qt_qt(viewconj, view); + conjugate_qt(viewconj); + + // transform device rotation into view's frame of reference + // rotation(view) = view * rotation(world) * viewconj + mul_qt_qtqt(rotation, rotation, viewconj); + mul_qt_qtqt(rotation, view, rotation); + + // apply rotation to obtain new viewpoint +// copy_qt_qt(rotationconj, rotation); +// conjugate_qt(rotationconj); +// mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotationconj); +// mul_qt_qtqt(rv3d->viewquat, rotation, rv3d->viewquat); + mul_qt_qtqt(rv3d->viewquat, rotation, rv3d->viewquat); + + // this is *close* to trackball behavior + // rotation axis needs to remain fixed relative to viewpoint, not world coordinates + + ED_region_tag_redraw(CTX_wm_region(C)); + + } else { + /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ + float phi, q1[4]; + float m[3][3]; + float m_inv[3][3]; + float xvec[3] = {1,0,0}; + + /* Get the 3x3 matrix and its inverse from the quaternion */ + quat_to_mat3(m,rv3d->viewquat); + invert_m3_m3(m_inv,m); + + /* Determine the direction of the x vector (for rotating up and down) */ + /* This can likely be computed directly from the quaternion. */ + mul_m3_v3(m_inv,xvec); + + /* Perform the up/down rotation */ + phi = sensitivity * dt * ndof->rx; + q1[0] = cos(phi); + mul_v3_v3fl(q1+1, xvec, sin(phi)); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + + /* Perform the orbital rotation */ + phi = sensitivity * dt * ndof->rz; + q1[0] = cos(phi); + q1[1] = q1[2] = 0.0; + q1[3] = sin(phi); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + + ED_region_tag_redraw(CTX_wm_region(C)); + } + } - ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; - } +} // Tom's version #if 0 -- cgit v1.2.3 From 0faeffb8a57493b6ccebc87decfed54c51152af0 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Mon, 20 Jun 2011 13:04:11 +0000 Subject: Compile fix. Note that var introduction must happen at start of code block. --- source/blender/editors/space_view3d/view3d_edit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index d1be99ce7ee..d506c4a5636 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -952,11 +952,13 @@ float ndof_to_angle_axis(const float ndof[3], float axis[3]) // Mike's version static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) { + RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; float sensitivity = 1.f; /* ooh, magic number! const float sensitivity = 0.035; /* ooh, magic number! there will be several of these as interactions get tuned */ + int /* bool */ has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); float dt = ndof->dt; if (dt > 0.25f) @@ -964,9 +966,7 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) /* TODO: replace such guesswork with a flag or field from the NDOF manager */ dt = 0.0125f; - RegionView3D* rv3d = CTX_wm_region_view3d(C); - int /* bool */ has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); if (has_rotation) rv3d->view = RV3D_VIEW_USER; -- cgit v1.2.3 From 4030f82aadec55add812043a355b4bd11210c10c Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 20 Jun 2011 21:34:23 +0000 Subject: ndof trackball works... somehow --- source/blender/editors/space_view3d/view3d_edit.c | 75 +++++++++++++---------- 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index d506c4a5636..048742fa392 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -949,6 +949,25 @@ float ndof_to_angle_axis(const float ndof[3], float axis[3]) return angular_velocity; } +void ndof_to_quat(wmNDOFMotionData* ndof, float q[4]) + { + const float x = ndof->rx; + const float y = ndof->ry; + const float z = ndof->rz; + + float angular_velocity = sqrtf(x*x + y*y + z*z); + float angle = ndof->dt * angular_velocity; + + // combined scaling factor -- normalize axis while converting to quaternion + float scale = sin(0.5f * angle) / angular_velocity; + + // convert axis-angle to quaternion + q[0] = cos(0.5f * angle); + q[1] = scale * x; + q[2] = scale * y; + q[3] = scale * z; + } + // Mike's version static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) { @@ -964,7 +983,7 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) if (dt > 0.25f) /* this is probably the first event for this motion, so set dt to something reasonable */ /* TODO: replace such guesswork with a flag or field from the NDOF manager */ - dt = 0.0125f; + ndof->dt = dt = 0.0125f; if (has_rotation) @@ -972,37 +991,29 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) if (has_rotation) { if (U.flag & USER_TRACKBALL) { - /* TODO: write trackball code! */ - - float axis[3] = {ndof->rx, ndof->ry, ndof->rz}; - float angle = sensitivity * dt * ndof_to_angle_axis(axis, axis); - float rotation[4], rotationconj[4]; - float view[4], viewconj[4]; - - // convert to quaternion - axis_angle_to_quat(rotation, axis, angle); - - // extract rotation component of viewquat - copy_qt_qt(view, rv3d->viewquat); - invert_qt(view); - normalize_qt(view); - copy_qt_qt(viewconj, view); - conjugate_qt(viewconj); - - // transform device rotation into view's frame of reference - // rotation(view) = view * rotation(world) * viewconj - mul_qt_qtqt(rotation, rotation, viewconj); - mul_qt_qtqt(rotation, view, rotation); - - // apply rotation to obtain new viewpoint -// copy_qt_qt(rotationconj, rotation); -// conjugate_qt(rotationconj); -// mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotationconj); -// mul_qt_qtqt(rv3d->viewquat, rotation, rv3d->viewquat); - mul_qt_qtqt(rv3d->viewquat, rotation, rv3d->viewquat); - - // this is *close* to trackball behavior - // rotation axis needs to remain fixed relative to viewpoint, not world coordinates + + float rot[4]; + float view_inv[4], view_inv_conj[4]; + + ndof_to_quat(ndof, rot); + + // swap y and z -- not sure why, but it works + { + float temp = -rot[2]; // also invert device y + rot[2] = rot[3]; + rot[3] = temp; + } + + invert_qt_qt(view_inv, rv3d->viewquat); + copy_qt_qt(view_inv_conj, view_inv); + conjugate_qt(view_inv_conj); + + // transform rotation from view to world coordinates + mul_qt_qtqt(rot, view_inv, rot); + mul_qt_qtqt(rot, rot, view_inv_conj); + + // apply rotation + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); ED_region_tag_redraw(CTX_wm_region(C)); -- cgit v1.2.3 From 651df035f790b6e82dec074972aad52d616b2d47 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 25 Jun 2011 18:50:03 +0000 Subject: baby steps toward an NDOF popup menu --- source/blender/windowmanager/intern/wm_operators.c | 47 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 1b7333024e7..e36849e103c 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1374,6 +1374,48 @@ static void WM_OT_search_menu(wmOperatorType *ot) ot->poll= wm_search_menu_poll; } +// BEGIN ndof menu -- experimental! + +static int wm_ndof_menu_poll(bContext *C) +{ + if(CTX_wm_window(C)==NULL) + return 0; + + // if menu is already pulled up, another button press should dismiss it + // not sure if that behavior should go here or elsewhere... + + puts("ndof: menu poll"); + return 1; +} + +static int wm_ndof_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) +{ + puts("ndof: menu exec"); + return OPERATOR_FINISHED; +} + +static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +{ + puts("ndof: menu invoke"); + + uiPupMenuNotice(C, "Hello!"); + + return OPERATOR_CANCELLED; +} + +static void WM_OT_ndof_menu(wmOperatorType *ot) +{ + puts("ndof: registering menu operator"); + ot->name= "NDOF Menu"; + ot->idname= "WM_OT_ndof_menu"; + + ot->invoke= wm_ndof_menu_invoke; + ot->exec= wm_ndof_menu_exec; + ot->poll= wm_ndof_menu_poll; +} + +// END ndof menu + static int wm_call_menu_exec(bContext *C, wmOperator *op) { char idname[BKE_ST_MAXNAME]; @@ -3403,6 +3445,7 @@ void wm_operatortype_init(void) WM_operatortype_append(WM_OT_debug_menu); WM_operatortype_append(WM_OT_splash); WM_operatortype_append(WM_OT_search_menu); + WM_operatortype_append(WM_OT_ndof_menu); WM_operatortype_append(WM_OT_call_menu); WM_operatortype_append(WM_OT_radial_control); #if defined(WIN32) @@ -3623,7 +3666,9 @@ void wm_window_keymap(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0); WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0); WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); - + + WM_keymap_add_item(keymap, "WM_OT_ndof_menu", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); + /* Space switching */ -- cgit v1.2.3 From e61063f04296d4af023718485ba0ac52b7a42a5a Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 25 Jun 2011 18:51:29 +0000 Subject: NDOF pan/zoom/fit working in image/uv editor --- source/blender/editors/space_image/image_intern.h | 1 + source/blender/editors/space_image/image_ops.c | 54 +++++++++++++++++++++++ source/blender/editors/space_image/space_image.c | 4 ++ 3 files changed, 59 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index e9e77ddf430..399157da85c 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -73,6 +73,7 @@ void IMAGE_OT_view_zoom(struct wmOperatorType *ot); void IMAGE_OT_view_zoom_in(struct wmOperatorType *ot); void IMAGE_OT_view_zoom_out(struct wmOperatorType *ot); void IMAGE_OT_view_zoom_ratio(struct wmOperatorType *ot); +void IMAGE_OT_view_ndof(struct wmOperatorType *ot); void IMAGE_OT_new(struct wmOperatorType *ot); void IMAGE_OT_open(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 10b8cb238aa..fc7b84e21ae 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -437,6 +437,60 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) "Factor", "Zoom factor, values higher than 1.0 zoom in, lower values zoom out.", -FLT_MAX, FLT_MAX); } +/********************** NDOF operator *********************/ + +/* Combined pan/zoom from a 3D mouse device. + * Y zooms, XZ pans + * "view" (not "paper") control -- user moves the viewpoint, not the image being viewed + * that explains the negative signs in the code below + */ + +static int view_ndof_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + SpaceImage *sima= CTX_wm_space_image(C); + ARegion *ar= CTX_wm_region(C); + + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + float dt = ndof->dt > 0.25f ? 0.0125f : ndof->dt; + /* this is probably the first event for this motion, so set dt to something reasonable + * TODO: replace such guesswork with a flag or field from the NDOF manager + */ + + /* tune these until it feels right */ + const float zoom_sensitivity = 0.5f; + const float pan_sensitivity = 300.f; + + float pan_x = pan_sensitivity * dt * -ndof->tx / sima->zoom; + float pan_y = pan_sensitivity * dt * -ndof->tz / sima->zoom; + + /* "mouse zoom" factor = 1 + (dx + dy) / 300 + * what about "ndof zoom" factor? should behave like this: + * at rest -> factor = 1 + * move forward -> factor > 1 + * move backward -> factor < 1 + */ + float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->ty; + + sima_zoom_set_factor(sima, ar, zoom_factor); + sima->xof += pan_x; + sima->yof += pan_y; + + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; +} + +void IMAGE_OT_view_ndof(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "NDOF Pan/Zoom"; + ot->idname= "IMAGE_OT_view_ndof"; + + /* api callbacks */ + ot->invoke= view_ndof_invoke; +} + /********************** view all operator *********************/ /* Updates the fields of the View2D member of the SpaceImage struct. diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 2e9544f5d20..afab4ede229 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -469,6 +469,7 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_view_zoom_in); WM_operatortype_append(IMAGE_OT_view_zoom_out); WM_operatortype_append(IMAGE_OT_view_zoom_ratio); + WM_operatortype_append(IMAGE_OT_view_ndof); WM_operatortype_append(IMAGE_OT_new); WM_operatortype_append(IMAGE_OT_open); @@ -518,6 +519,9 @@ static void image_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MOUSEPAN, 0, 0, 0); + WM_keymap_add_item(keymap, "IMAGE_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); // or view selected? + WM_keymap_add_item(keymap, "IMAGE_OT_view_ndof", NDOF_MOTION, 0, 0, 0); + WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0); -- cgit v1.2.3 From b8e8f8064dd14a0031cbef50d89c13c868c910cd Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 25 Jun 2011 18:53:06 +0000 Subject: NDOF zoom for orbit modes (trackball/turntable) in 3D view --- source/blender/editors/space_view3d/view3d_edit.c | 100 +++++++--------------- 1 file changed, 32 insertions(+), 68 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 048742fa392..bd44378c9aa 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -949,6 +949,15 @@ float ndof_to_angle_axis(const float ndof[3], float axis[3]) return angular_velocity; } +float ndof_to_angular_velocity(wmNDOFMotionData* ndof, float axis[3]) + { + const float x = ndof->rx; + const float y = ndof->ry; + const float z = ndof->rz; + + return sqrtf(x*x + y*y + z*z); + } + void ndof_to_quat(wmNDOFMotionData* ndof, float q[4]) { const float x = ndof->rx; @@ -974,10 +983,12 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - float sensitivity = 1.f; /* ooh, magic number! - const float sensitivity = 0.035; /* ooh, magic number! - there will be several of these as interactions get tuned */ - int /* bool */ has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); + // tune these until everything feels right + float rot_sensitivity = 1.f; + float zoom_sensitivity = 1.f; + + // rather have bool, but... + int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); float dt = ndof->dt; if (dt > 0.25f) @@ -986,16 +997,29 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) ndof->dt = dt = 0.0125f; - if (has_rotation) - rv3d->view = RV3D_VIEW_USER; + if (ndof->ty) { + // Zoom! + // velocity should be proportional to the linear velocity attained by rotational motion of same strength + // [got that?] + // proportional to s = r * theta + + float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->ty; + rv3d->dist += zoom_distance; + + ED_region_tag_redraw(CTX_wm_region(C)); + } if (has_rotation) { + + rv3d->view = RV3D_VIEW_USER; + if (U.flag & USER_TRACKBALL) { float rot[4]; float view_inv[4], view_inv_conj[4]; ndof_to_quat(ndof, rot); + // scale by rot_sensitivity? // swap y and z -- not sure why, but it works { @@ -1033,13 +1057,13 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) mul_m3_v3(m_inv,xvec); /* Perform the up/down rotation */ - phi = sensitivity * dt * ndof->rx; + phi = rot_sensitivity * dt * ndof->rx; q1[0] = cos(phi); mul_v3_v3fl(q1+1, xvec, sin(phi)); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); /* Perform the orbital rotation */ - phi = sensitivity * dt * ndof->rz; + phi = rot_sensitivity * dt * ndof->rz; q1[0] = cos(phi); q1[1] = q1[2] = 0.0; q1[3] = sin(phi); @@ -1160,66 +1184,6 @@ static int viewndof_invoke_1st_try(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } - -static int viewndof_invoke_2nd_try(bContext *C, wmOperator *op, wmEvent *event) -{ - wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - - float dt = ndof->dt; - - RegionView3D* rv3d = CTX_wm_region_view3d(C); - - if (dt > 0.25f) - /* this is probably the first event for this motion, so set dt to something reasonable */ - dt = 0.0125f; - - float axis[3]; - float angle = ndof_to_angle_axis(&(ndof->rx), axis); - - float eyeball_q[4];// = {0.f}; - -// float* eyeball_v = eyeball_q + 1; - - axis_angle_to_quat(eyeball_q, axis, angle); - - float eye_conj[4]; - copy_qt_qt(eye_conj, eyeball_q); - conjugate_qt(eye_conj); - -// float mat[3][3]; -// quat_to_mat3(mat, rv3d->viewquat); -/* - eyeball_v[0] = dt * ndof->tx; - eyeball_v[1] = dt * ndof->ty; - eyeball_v[2] = dt * ndof->tz; -*/ -// mul_m3_v3(mat, eyeball_vector); -// mul_qt_v3(rv3d->viewquat, eyeball_vector); - - // doesn't this transform v? - // v' = (q)(v)(~q) - - float view_q[4]; - copy_qt_qt(view_q, rv3d->viewquat); - -// float q_conj[4]; -// copy_qt_qt(q_conj, q); -// conjugate_qt(q_conj); - - mul_qt_qtqt(view_q, eyeball_q, view_q); - mul_qt_qtqt(view_q, view_q, eye_conj); - -// mul_qt_qtqt(eyeball_q, q, eyeball_q); -// mul_qt_qtqt(eyeball_q, eyeball_q, q_conj); - -// add_v3_v3(rv3d->ofs, eyeball_v); - - copy_qt_qt(rv3d->viewquat, view_q); - - ED_region_tag_redraw(CTX_wm_region(C)); - - return OPERATOR_FINISHED; -} #endif void VIEW3D_OT_ndof(struct wmOperatorType *ot) -- cgit v1.2.3 From edd5980436cdfe9ca7a7a2a75b6dff2129b72275 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 27 Jun 2011 20:12:10 +0000 Subject: now using blender view coordinates for ndof input -- core and Linux in place --- source/blender/editors/space_image/image_ops.c | 8 +-- source/blender/editors/space_view3d/view3d_edit.c | 68 ++++++----------------- 2 files changed, 20 insertions(+), 56 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index fc7b84e21ae..77fb129e278 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -440,7 +440,7 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) /********************** NDOF operator *********************/ /* Combined pan/zoom from a 3D mouse device. - * Y zooms, XZ pans + * Z zooms, XY pans * "view" (not "paper") control -- user moves the viewpoint, not the image being viewed * that explains the negative signs in the code below */ @@ -461,8 +461,8 @@ static int view_ndof_invoke(bContext *C, wmOperator *op, wmEvent *event) const float zoom_sensitivity = 0.5f; const float pan_sensitivity = 300.f; - float pan_x = pan_sensitivity * dt * -ndof->tx / sima->zoom; - float pan_y = pan_sensitivity * dt * -ndof->tz / sima->zoom; + float pan_x = pan_sensitivity * dt * ndof->tx / sima->zoom; + float pan_y = pan_sensitivity * dt * ndof->ty / sima->zoom; /* "mouse zoom" factor = 1 + (dx + dy) / 300 * what about "ndof zoom" factor? should behave like this: @@ -470,7 +470,7 @@ static int view_ndof_invoke(bContext *C, wmOperator *op, wmEvent *event) * move forward -> factor > 1 * move backward -> factor < 1 */ - float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->ty; + float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->tz; sima_zoom_set_factor(sima, ar, zoom_factor); sima->xof += pan_x; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index bd44378c9aa..0e82581e411 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1003,10 +1003,10 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) // [got that?] // proportional to s = r * theta - float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->ty; + float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; rv3d->dist += zoom_distance; - ED_region_tag_redraw(CTX_wm_region(C)); + ED_region_tag_redraw(CTX_wm_region(C)); } if (has_rotation) { @@ -1020,13 +1020,7 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) ndof_to_quat(ndof, rot); // scale by rot_sensitivity? - - // swap y and z -- not sure why, but it works - { - float temp = -rot[2]; // also invert device y - rot[2] = rot[3]; - rot[3] = temp; - } + // mul_qt_fl(rot, rot_sensitivity); invert_qt_qt(view_inv, rv3d->viewquat); copy_qt_qt(view_inv_conj, view_inv); @@ -1043,31 +1037,26 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) } else { /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ - float phi, q1[4]; - float m[3][3]; - float m_inv[3][3]; + float angle, rot[4]; float xvec[3] = {1,0,0}; - /* Get the 3x3 matrix and its inverse from the quaternion */ - quat_to_mat3(m,rv3d->viewquat); - invert_m3_m3(m_inv,m); - /* Determine the direction of the x vector (for rotating up and down) */ - /* This can likely be computed directly from the quaternion. */ - mul_m3_v3(m_inv,xvec); + float view_inv[4]/*, view_inv_conj[4]*/; + invert_qt_qt(view_inv, rv3d->viewquat); + mul_qt_v3(view_inv, xvec); /* Perform the up/down rotation */ - phi = rot_sensitivity * dt * ndof->rx; - q1[0] = cos(phi); - mul_v3_v3fl(q1+1, xvec, sin(phi)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + angle = rot_sensitivity * dt * ndof->rx; + rot[0] = cos(angle); + mul_v3_v3fl(rot+1, xvec, sin(angle)); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); /* Perform the orbital rotation */ - phi = rot_sensitivity * dt * ndof->rz; - q1[0] = cos(phi); - q1[1] = q1[2] = 0.0; - q1[3] = sin(phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); + angle = rot_sensitivity * dt * ndof->ry; + rot[0] = cos(angle); + rot[1] = rot[2] = 0.0; + rot[3] = sin(angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); ED_region_tag_redraw(CTX_wm_region(C)); } @@ -1161,31 +1150,6 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) } #endif -#if 0 -static int viewndof_invoke_1st_try(bContext *C, wmOperator *op, wmEvent *event) -{ - wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - - float dt = ndof->dt; - - RegionView3D *rv3d= CTX_wm_region_view3d(C); - - if (dt > 0.25f) - /* this is probably the first event for this motion, so set dt to something reasonable */ - dt = 0.0125f; - - /* very simple for now, move viewpoint along world axes */ - rv3d->ofs[0] += dt * ndof->tx; - rv3d->ofs[1] += dt * ndof->ty; - rv3d->ofs[2] += dt * ndof->tz; - -// request_depth_update(CTX_wm_region_view3d(C)); /* need this? */ - ED_region_tag_redraw(CTX_wm_region(C)); - - return OPERATOR_FINISHED; -} -#endif - void VIEW3D_OT_ndof(struct wmOperatorType *ot) { /* identifiers */ -- cgit v1.2.3 From 798f59fe6810a77ce0903f3dd5650d5777a5e5ba Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 27 Jun 2011 20:44:23 +0000 Subject: Mac ndof using blender view coordinates + small but important typo fixed --- source/blender/editors/space_view3d/view3d_edit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 0e82581e411..15c3d9da84f 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -997,11 +997,11 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) ndof->dt = dt = 0.0125f; - if (ndof->ty) { + if (ndof->tz) { // Zoom! // velocity should be proportional to the linear velocity attained by rotational motion of same strength // [got that?] - // proportional to s = r * theta + // proportional to arclength = radius * angle float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; rv3d->dist += zoom_distance; -- cgit v1.2.3 From 4178b662ccb99240ad8528577f040dc00c3c78dd Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 28 Jun 2011 15:59:46 +0000 Subject: enabled pan/zoom in rotation-locked 3D views + small cleanup --- source/blender/editors/space_view3d/view3d_edit.c | 31 +++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 15c3d9da84f..b334ed91df6 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -931,7 +931,7 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) // returns angular velocity (0..1), fills axis of rotation // (shouldn't live in this file!) -float ndof_to_angle_axis(const float ndof[3], float axis[3]) +static float ndof_to_angle_axis(const float ndof[3], float axis[3]) { const float x = ndof[0]; const float y = ndof[1]; @@ -949,7 +949,7 @@ float ndof_to_angle_axis(const float ndof[3], float axis[3]) return angular_velocity; } -float ndof_to_angular_velocity(wmNDOFMotionData* ndof, float axis[3]) +static float ndof_to_angular_velocity(wmNDOFMotionData* ndof) { const float x = ndof->rx; const float y = ndof->ry; @@ -958,7 +958,7 @@ float ndof_to_angular_velocity(wmNDOFMotionData* ndof, float axis[3]) return sqrtf(x*x + y*y + z*z); } -void ndof_to_quat(wmNDOFMotionData* ndof, float q[4]) +static void ndof_to_quat(wmNDOFMotionData* ndof, float q[4]) { const float x = ndof->rx; const float y = ndof->ry; @@ -984,8 +984,9 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; // tune these until everything feels right - float rot_sensitivity = 1.f; - float zoom_sensitivity = 1.f; + const float rot_sensitivity = 1.f; + const float zoom_sensitivity = 1.f; + const float pan_sensitivity = 1.f; // rather have bool, but... int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); @@ -1005,8 +1006,20 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; rv3d->dist += zoom_distance; + } + + if (rv3d->viewlock == RV3D_LOCKED) { + /* rotation not allowed -- explore panning options instead */ + float view_inv[4]; + float pan_vec[3] = {ndof->tx, ndof->ty, 0}; + mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); + + /* transform motion from view to world coordinates */ + invert_qt_qt(view_inv, rv3d->viewquat); + mul_qt_v3(view_inv, pan_vec); - ED_region_tag_redraw(CTX_wm_region(C)); + /* move center of view opposite of hand motion (camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, pan_vec); } if (has_rotation) { @@ -1033,8 +1046,6 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) // apply rotation mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); - ED_region_tag_redraw(CTX_wm_region(C)); - } else { /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ float angle, rot[4]; @@ -1057,11 +1068,11 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) rot[1] = rot[2] = 0.0; rot[3] = sin(angle); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); - - ED_region_tag_redraw(CTX_wm_region(C)); } } + ED_region_tag_redraw(CTX_wm_region(C)); + return OPERATOR_FINISHED; } -- cgit v1.2.3 From 20de4f27b6be5b4494e1338fe737cf2df42a283e Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Fri, 1 Jul 2011 01:00:20 +0000 Subject: ndof popup menu (experimental (mostly harmless)) --- source/blender/windowmanager/intern/wm_operators.c | 99 ++++++++++++++++++++-- 1 file changed, 94 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index e36849e103c..7d6a50043b5 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1376,6 +1376,61 @@ static void WM_OT_search_menu(wmOperatorType *ot) // BEGIN ndof menu -- experimental! +static uiBlock* wm_block_ndof_menu_1st(bContext* C, ARegion* ar, void* UNUSED(arg_op)) +{ + uiBlock* block; + uiBut* but; + + block = uiBeginBlock(C, ar, "ndof_popup_menu", UI_EMBOSS); + uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT); +// uiBlockSetDirection(block, UI_DOWN); +// uiBlockBeginAlign(block); + + // uiItemBooleanO(block->curlayout, "enable pan/zoom", ICON_NDOF_TRANS, "toggle_ndof_pan_zoom_enabled", "ndof_pan_zoom_enabled", 1); + // uiBlock is used as an opaque type in this file, so can't use members... + + int foo = 333; + uiDefButI(block, TOG, 0, "foo", 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, &foo, 0.f, 1.f, 0.1f, 0.9f, "15%"); + // uiDefBut(block, TOG, 0, "enable pan/zoom", 0, 0, 10, 10, NULL, 0.f, 1.f, 0.f, 1.f, "don't talk to strangers"); + +// uiBlockEndAlign(block); +// uiBoundsBlock(block, 6); + uiEndBlock(C, block); + + return block; +} + +static uiBlock *wm_block_ndof_menu(bContext *C, ARegion *ar, void *UNUSED(arg_op)) +{ + static char search[256]= ""; + wmEvent event; + wmWindow *win= CTX_wm_window(C); + uiBlock *block; + uiBut *but; + + block= uiBeginBlock(C, ar, "ndof_popup", UI_EMBOSS); +// uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT); + uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_POPUP|UI_BLOCK_MOVEMOUSE_QUIT); + + but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, 0, 0, ""); + uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL); + + /* fake button, it holds space for search items */ + uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 9*UI_UNIT_X, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL); + + uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */ + uiEndBlock(C, block); + + event= *(win->eventstate); /* XXX huh huh? make api call */ + event.type= EVT_BUT_OPEN; + event.val= KM_PRESS; + event.customdata= but; + event.customdatafree= FALSE; + wm_event_add(win, &event); + + return block; +} + static int wm_ndof_menu_poll(bContext *C) { if(CTX_wm_window(C)==NULL) @@ -1396,11 +1451,45 @@ static int wm_ndof_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { - puts("ndof: menu invoke"); + printf("ndof: menu invoked in "); - uiPupMenuNotice(C, "Hello!"); + switch (CTX_wm_area(C)->spacetype) // diff spaces can have diff 3d mouse options + { + case SPACE_VIEW3D: + puts("3D area"); + break; + case SPACE_IMAGE: + puts("image area"); + break; + default: + puts("some iNDOFferent area"); + } + +// uiPupMenuNotice(C, "Hello!"); // <-- this works +// uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck! +// ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works + + uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN); + uiLayout* layout = uiPupMenuLayout(pup); + + //uiBlock* block = uiLayoutGetBlock(layout); + //int foo = 1; + //uiDefButI(block, TOG, 0, "foo", 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, &foo, 0.f, 1.f, 0.1f, 0.9f, "15%"); - return OPERATOR_CANCELLED; + uiItemS(layout); // separator + + uiItemBooleanO(layout, "enable pan/zoom", ICON_NDOF_TRANS, "ndof_toggle_pan_zoom_enabled", "ndof_pan_zoom_enabled", 1); + uiItemBooleanO(layout, "enable rotation", ICON_NDOF_TURN, "ndof_toggle_rotation_enabled", "ndof_rotation_enabled", 1); + uiItemFloatO(layout, "sensitivity", 0, "ndof_adjust_sensitivity", "ndof_sensitivity", 1.f); + uiItemV(layout,"sensitivity",ICON_NDOF_TRANS, 1); + + uiItemS(layout); + uiItemL(layout, "3D navigation mode", ICON_NDOF_FLY); + uiItemL(layout, "...", 0); + + uiPupMenuEnd(C,pup); + + return OPERATOR_CANCELLED; // <-- correct? } static void WM_OT_ndof_menu(wmOperatorType *ot) @@ -1410,8 +1499,8 @@ static void WM_OT_ndof_menu(wmOperatorType *ot) ot->idname= "WM_OT_ndof_menu"; ot->invoke= wm_ndof_menu_invoke; - ot->exec= wm_ndof_menu_exec; - ot->poll= wm_ndof_menu_poll; +// ot->exec= wm_ndof_menu_exec; +// ot->poll= wm_ndof_menu_poll; } // END ndof menu -- cgit v1.2.3 From 893bf5f81a2a7b7306461cd3c9b5c00b1796bb2d Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Fri, 1 Jul 2011 03:44:03 +0000 Subject: verbose ndof event trace for a tester --- source/blender/editors/space_view3d/view3d_edit.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index b334ed91df6..42a41be05e0 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -997,6 +997,11 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) /* TODO: replace such guesswork with a flag or field from the NDOF manager */ ndof->dt = dt = 0.0125f; + #define DEBUG_NDOF_MOTION + #ifdef DEBUG_NDOF_MOTION + printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n", + ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt); + #endif if (ndof->tz) { // Zoom! -- cgit v1.2.3 From 14c72f379cea8be411e649f08fd5ac9f8943e56d Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Fri, 1 Jul 2011 21:51:44 +0000 Subject: implemented ndof 'dead zone' around home position, fixed X11 active window determination, removed old X11 ndof code --- source/blender/windowmanager/intern/wm_operators.c | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 7d6a50043b5..6fb6a8dcf1f 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1376,6 +1376,7 @@ static void WM_OT_search_menu(wmOperatorType *ot) // BEGIN ndof menu -- experimental! +#if 0 static uiBlock* wm_block_ndof_menu_1st(bContext* C, ARegion* ar, void* UNUSED(arg_op)) { uiBlock* block; @@ -1448,9 +1449,17 @@ static int wm_ndof_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) puts("ndof: menu exec"); return OPERATOR_FINISHED; } +#endif static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { +// uiPupMenuNotice(C, "Hello!"); // <-- this works +// uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck! +// ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works + + uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN); + uiLayout* layout = uiPupMenuLayout(pup); + printf("ndof: menu invoked in "); switch (CTX_wm_area(C)->spacetype) // diff spaces can have diff 3d mouse options @@ -1465,12 +1474,6 @@ static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even puts("some iNDOFferent area"); } -// uiPupMenuNotice(C, "Hello!"); // <-- this works -// uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck! -// ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works - - uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN); - uiLayout* layout = uiPupMenuLayout(pup); //uiBlock* block = uiLayoutGetBlock(layout); //int foo = 1; @@ -1495,12 +1498,11 @@ static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even static void WM_OT_ndof_menu(wmOperatorType *ot) { puts("ndof: registering menu operator"); - ot->name= "NDOF Menu"; - ot->idname= "WM_OT_ndof_menu"; + + ot->name = "NDOF Menu"; + ot->idname = "WM_OT_ndof_menu"; - ot->invoke= wm_ndof_menu_invoke; -// ot->exec= wm_ndof_menu_exec; -// ot->poll= wm_ndof_menu_poll; + ot->invoke = wm_ndof_menu_invoke; } // END ndof menu -- cgit v1.2.3 From e3c89a127de7cabb32d89ff696d6d840ff23b123 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Wed, 6 Jul 2011 17:10:38 +0000 Subject: refitted old ndof fly code for 2.5, removed crusty old code --- source/blender/editors/space_view3d/view3d_edit.c | 641 ++++++---------------- 1 file changed, 174 insertions(+), 467 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 42a41be05e0..5a0c233edfa 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -929,6 +929,7 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER; } +#if 0 // NDOF utility functions // returns angular velocity (0..1), fills axis of rotation // (shouldn't live in this file!) static float ndof_to_angle_axis(const float ndof[3], float axis[3]) @@ -957,6 +958,7 @@ static float ndof_to_angular_velocity(wmNDOFMotionData* ndof) return sqrtf(x*x + y*y + z*z); } +#endif static void ndof_to_quat(wmNDOFMotionData* ndof, float q[4]) { @@ -977,8 +979,11 @@ static void ndof_to_quat(wmNDOFMotionData* ndof, float q[4]) q[3] = scale * z; } -// Mike's version -static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) +// Mike's original version: +// -- "orbit" navigation (trackball/turntable) +// -- zooming +// -- panning in rotationally-locked views +static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) { RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; @@ -1023,7 +1028,7 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) invert_qt_qt(view_inv, rv3d->viewquat); mul_qt_v3(view_inv, pan_vec); - /* move center of view opposite of hand motion (camera mode, not object mode) */ + /* move center of view opposite of hand motion (this is camera mode, not object mode) */ sub_v3_v3(rv3d->ofs, pan_vec); } @@ -1057,7 +1062,7 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) float xvec[3] = {1,0,0}; /* Determine the direction of the x vector (for rotating up and down) */ - float view_inv[4]/*, view_inv_conj[4]*/; + float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); mul_qt_v3(view_inv, xvec); @@ -1081,90 +1086,183 @@ static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } -// Tom's version -#if 0 -static int viewndof_invoke(bContext *C, wmOperator *op, wmEvent *event) +#if 0 // not ready +static int ndof_fly_invoke(bContext *C, wmOperator *op, wmEvent *event) { + RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - - float phi, q1[4]; - float m[3][3]; - float m_inv[3][3]; - float xvec[3] = {1,0,0}; - float yvec[3] = {0,1,0}; - float vec[3]; - float mat[3][3]; - const float rotaSensitivity = 0.007; - const float tranSensitivity = 0.120; - - ARegion *ar= CTX_wm_region(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - View3D *v3d = CTX_wm_view3d(C); - + + const int shouldRotate = 0, shouldMove = 1; + float dt = ndof->dt; - - if (dt > 0.25f) { + if (dt > 0.25f) /* this is probably the first event for this motion, so set dt to something reasonable */ - dt = 0.0125f; + /* TODO: replace such guesswork with a flag or field from the NDOF manager */ + ndof->dt = dt = 0.0125f; + + if (shouldRotate) + { + const float turn_sensitivity = 1.f; + + float rot[4]; + ndof_to_quat(ndof, rot); + + rv3d->view = RV3D_VIEW_USER; + } + + if (shouldMove) + { + const float forward_sensitivity = 1.f; + const float vertical_sensitivity = 1.f; + const float lateral_sensitivity = 1.f; + + float trans[3] = { + lateral_sensitivity * dt * ndof->tx, + vertical_sensitivity * dt * ndof->ty, + forward_sensitivity * rv3d->dist * dt * ndof->tz + }; + } + + ED_region_tag_redraw(CTX_wm_region(C)); + + return OPERATOR_FINISHED; +} +#endif + +// BEGIN old fly code +// derived from blender 2.4 + +static void getndof(wmNDOFMotionData* indof, float* outdof) +{ + // Rotations feel relatively faster than translations only in fly mode, so + // we have no choice but to fix that here (not in the plugins) + const float turn_sensitivity = 0.8f; + + const float forward_sensitivity = 2.5f; + const float vertical_sensitivity = 1.6f; + const float lateral_sensitivity = 2.5f; + + const float dt = (indof->dt < 0.25f) ? indof->dt : 0.0125f; + // this is probably the first event for this motion, so set dt to something reasonable + // TODO: replace such guesswork with a flag or field from the NDOF manager + + outdof[0] = lateral_sensitivity * dt * indof->tx; + outdof[1] = vertical_sensitivity * dt * indof->ty; + outdof[2] = forward_sensitivity * dt * indof->tz; + + outdof[3] = turn_sensitivity * dt * indof->rx; + outdof[4] = turn_sensitivity * dt * indof->ry; + outdof[5] = turn_sensitivity * dt * indof->rz; +} + +// statics for controlling rv3d->dist corrections. +// viewmoveNDOF zeros and adjusts rv3d->ofs. +// viewmove restores based on dz_flag state. + +static int dz_flag = 0; +static float m_dist; + +static void mouse_rotation_workaround_push(RegionView3D* rv3d) +{ + // This is due to a side effect of the original + // mouse view rotation code. The rotation point is + // set a distance in front of the viewport to + // make rotating with the mouse look better. + // The distance effect is written at a low level + // in the view management instead of the mouse + // view function. This means that all other view + // movement devices must subtract this from their + // view transformations. + + float mat[3][3]; + float upvec[3]; + + if(rv3d->dist != 0.0) { + dz_flag = 1; + m_dist = rv3d->dist; + upvec[0] = upvec[1] = 0; + upvec[2] = rv3d->dist; + copy_m3_m4(mat, rv3d->viewinv); + mul_m3_v3(mat, upvec); + sub_v3_v3(rv3d->ofs, upvec); + rv3d->dist = 0.0; } - /* Get the 3x3 matrix and its inverse from the quaternion */ - quat_to_mat3(m,rv3d->viewquat); - invert_m3_m3(m_inv,m); - - /* Determine the direction of the x vector (for rotating up and down) */ - /* This can likely be computed directly from the quaternion. */ - mul_m3_v3(m_inv,xvec); - - //if(rv3d->persp=!= RV3D_PERSP) //Camera control not supported yet - /* Lock fixed views out of using rotation controls */ - if(rv3d->view!=RV3D_VIEW_FRONT && rv3d->view!=RV3D_VIEW_BACK) - if(rv3d->view!=RV3D_VIEW_TOP && rv3d->view!=RV3D_VIEW_BOTTOM) - if(rv3d->view!=RV3D_VIEW_RIGHT && rv3d->view!=RV3D_VIEW_LEFT) { - // Perform the up/down rotation - phi = (rotaSensitivity+dt) * -ndof->rx; - q1[0] = cos(phi); - mul_v3_v3fl(q1+1, xvec, sin(phi)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - - // Perform the left/right rotation - mul_m3_v3(m_inv,yvec); - phi = (rotaSensitivity+dt) * ndof->ry; - q1[0] = cos(phi); - mul_v3_v3fl(q1+1, yvec, sin(phi)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - - // Perform the orbital rotation - phi = (rotaSensitivity+dt) * ndof->rz; - q1[0] = cos(phi); - q1[1] = q1[2] = 0.0; - q1[3] = sin(phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - } + // this is still needed in version 2.5 [mce] + // warning! current viewmove does not look at dz_flag or m_dist + // don't expect 2D mouse to work properly right after using 3D mouse +} + +static void mouse_rotation_workaround_pop(RegionView3D* rv3d) +{ + if (dz_flag) { + dz_flag = 0; + rv3d->dist = m_dist; + } +} + +static int ndof_oldfly_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + RegionView3D* rv3d = CTX_wm_region_view3d(C); + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + float phi; + float dval[6]; + float tvec[3], rvec[3]; + float q1[4]; + float mat[3][3]; + + // fetch the current state of the ndof device + getndof(ndof, dval); - // Perform Pan translation - vec[0]= (tranSensitivity+dt) * ndof->tx; - vec[1]= (tranSensitivity+dt) * ndof->tz; - //vec[2]= 0.0f;//tranSensitivity * ndof->ty; - //window_to_3d_delta(ar, vec, -ndof->tx, -ndof->tz); // experimented a little instead of above + // force perspective mode. This is a hack and is + // incomplete. It doesn't actually affect the view + // until the first draw and doesn't update the menu + // to reflect persp mode. + rv3d->persp = RV3D_PERSP; + + // Correct the distance jump if rv3d->dist != 0 + mouse_rotation_workaround_push(rv3d); + + // Apply rotation + rvec[0] = dval[3]; + rvec[1] = dval[4]; + rvec[2] = dval[5]; + + // rotate device x and y by view z copy_m3_m4(mat, rv3d->viewinv); mat[2][2] = 0.0f; - mul_m3_v3(mat, vec); - // translate the view - add_v3_v3(rv3d->ofs, vec); + mul_m3_v3(mat, rvec); - // Perform Zoom translation - if (ndof->ty!=0.0f){ // TODO - need to add limits to prevent flipping past gridlines - rv3d->dist += (tranSensitivity+dt)* ndof->ty; - // printf("dist %5.3f view %d grid %f\n",rv3d->dist,rv3d->view,v3d->grid); + // rotate the view + phi = normalize_v3(rvec); + if(phi != 0) { + axis_angle_to_quat(q1,rvec,phi); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); } - //printf("Trans tx:%5.2f ty:%5.2f tz:%5.2f \n",ndof->tx, ndof->ty, ndof->tz); - ED_region_tag_redraw(ar); - + // Apply translation + tvec[0] = dval[0]; + tvec[1] = dval[1]; + tvec[2] = dval[2]; + + // the next three lines rotate the x and y translation coordinates + // by the current z axis angle + copy_m3_m4(mat, rv3d->viewinv); + mat[2][2] = 0.0f; + mul_m3_v3(mat, tvec); + + // translate the view + sub_v3_v3(rv3d->ofs, tvec); + + mouse_rotation_workaround_pop(rv3d); + + // back to 2.5 land! + ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; } -#endif + +// END old fly code void VIEW3D_OT_ndof(struct wmOperatorType *ot) { @@ -1174,7 +1272,8 @@ void VIEW3D_OT_ndof(struct wmOperatorType *ot) ot->idname = "VIEW3D_OT_ndof"; /* api callbacks */ - ot->invoke = viewndof_invoke; + ot->invoke = ndof_oldfly_invoke; +// ot->invoke = ndof_orbit_invoke; ot->poll = ED_operator_view3d_active; /* flags */ @@ -3448,398 +3547,6 @@ int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], cons return (*depth==FLT_MAX) ? 0:1; } -/* ********************* NDOF ************************ */ -/* note: this code is confusing and unclear... (ton) */ -/* **************************************************** */ - -// ndof scaling will be moved to user setting. -// In the mean time this is just a place holder. - -// Note: scaling in the plugin and ghostwinlay.c -// should be removed. With driver default setting, -// each axis returns approx. +-200 max deflection. - -// The values I selected are based on the older -// polling i/f. With event i/f, the sensistivity -// can be increased for improved response from -// small deflections of the device input. - - -// lukep notes : i disagree on the range. -// the normal 3Dconnection driver give +/-400 -// on defaut range in other applications -// and up to +/- 1000 if set to maximum -// because i remove the scaling by delta, -// which was a bad idea as it depend of the system -// speed and os, i changed the scaling values, but -// those are still not ok - -#if 0 -static float ndof_axis_scale[6] = { - +0.01, // Tx - +0.01, // Tz - +0.01, // Ty - +0.0015, // Rx - +0.0015, // Rz - +0.0015 // Ry -}; - -static void filterNDOFvalues(float *sbval) -{ - int i=0; - float max = 0.0; - - for (i =0; i<6;i++) - if (fabs(sbval[i]) > max) - max = fabs(sbval[i]); - for (i =0; i<6;i++) - if (fabs(sbval[i]) != max ) - sbval[i]=0.0; -} - -// statics for controlling rv3d->dist corrections. -// viewmoveNDOF zeros and adjusts rv3d->ofs. -// viewmove restores based on dz_flag state. - -int dz_flag = 0; -float m_dist; - -void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int UNUSED(mode)) -{ - RegionView3D *rv3d= ar->regiondata; - int i; - float phi; - float dval[7]; - // static fval[6] for low pass filter; device input vector is dval[6] - static float fval[6]; - float tvec[3],rvec[3]; - float q1[4]; - float mat[3][3]; - float upvec[3]; - - - /*---------------------------------------------------- - * sometimes this routine is called from headerbuttons - * viewmove needs to refresh the screen - */ -// XXX areawinset(ar->win); - - - // fetch the current state of the ndof device -// XXX getndof(dval); - - if (v3d->ndoffilter) - filterNDOFvalues(fval); - - // Scale input values - -// if(dval[6] == 0) return; // guard against divide by zero - - for(i=0;i<6;i++) { - - // user scaling - dval[i] = dval[i] * ndof_axis_scale[i]; - } - - - // low pass filter with zero crossing reset - - for(i=0;i<6;i++) { - if((dval[i] * fval[i]) >= 0) - dval[i] = (fval[i] * 15 + dval[i]) / 16; - else - fval[i] = 0; - } - - - // force perspective mode. This is a hack and is - // incomplete. It doesn't actually effect the view - // until the first draw and doesn't update the menu - // to reflect persp mode. - - rv3d->persp = RV3D_PERSP; - - - // Correct the distance jump if rv3d->dist != 0 - - // This is due to a side effect of the original - // mouse view rotation code. The rotation point is - // set a distance in front of the viewport to - // make rotating with the mouse look better. - // The distance effect is written at a low level - // in the view management instead of the mouse - // view function. This means that all other view - // movement devices must subtract this from their - // view transformations. - - if(rv3d->dist != 0.0) { - dz_flag = 1; - m_dist = rv3d->dist; - upvec[0] = upvec[1] = 0; - upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, upvec); - sub_v3_v3(rv3d->ofs, upvec); - rv3d->dist = 0.0; - } - - - // Apply rotation - // Rotations feel relatively faster than translations only in fly mode, so - // we have no choice but to fix that here (not in the plugins) - rvec[0] = -0.5 * dval[3]; - rvec[1] = -0.5 * dval[4]; - rvec[2] = -0.5 * dval[5]; - - // rotate device x and y by view z - - copy_m3_m4(mat, rv3d->viewinv); - mat[2][2] = 0.0f; - mul_m3_v3(mat, rvec); - - // rotate the view - - phi = normalize_v3(rvec); - if(phi != 0) { - axis_angle_to_quat(q1,rvec,phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - } - - - // Apply translation - - tvec[0] = dval[0]; - tvec[1] = dval[1]; - tvec[2] = -dval[2]; - - // the next three lines rotate the x and y translation coordinates - // by the current z axis angle - - copy_m3_m4(mat, rv3d->viewinv); - mat[2][2] = 0.0f; - mul_m3_v3(mat, tvec); - - // translate the view - - sub_v3_v3(rv3d->ofs, tvec); - - - /*---------------------------------------------------- - * refresh the screen XXX - */ - - // update render preview window - -// XXX BIF_view3d_previewrender_signal(ar, PR_DBASE|PR_DISPRECT); -} - -void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int UNUSED(mode)) -{ - RegionView3D *rv3d= ar->regiondata; - float fval[7]; - float dvec[3]; - float sbadjust = 1.0f; - float len; - short use_sel = 0; - Object *ob = OBACT; - float m[3][3]; - float m_inv[3][3]; - float xvec[3] = {1,0,0}; - float yvec[3] = {0,-1,0}; - float zvec[3] = {0,0,1}; - float phi; - float q1[4]; - float obofs[3]; - float reverse; - //float diff[4]; - float d, curareaX, curareaY; - float mat[3][3]; - float upvec[3]; - - /* Sensitivity will control how fast the view rotates. The value was - * obtained experimentally by tweaking until the author didn't get dizzy watching. - * Perhaps this should be a configurable user parameter. - */ - float psens = 0.005f * (float) U.ndof_pan; /* pan sensitivity */ - float rsens = 0.005f * (float) U.ndof_rotate; /* rotate sensitivity */ - float zsens = 0.3f; /* zoom sensitivity */ - - const float minZoom = -30.0f; - const float maxZoom = 300.0f; - - //reset view type - rv3d->view = 0; -//printf("passing here \n"); -// - if (scene->obedit==NULL && ob && !(ob->mode & OB_MODE_POSE)) { - use_sel = 1; - } - - if((dz_flag)||rv3d->dist==0) { - dz_flag = 0; - rv3d->dist = m_dist; - upvec[0] = upvec[1] = 0; - upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, upvec); - add_v3_v3(rv3d->ofs, upvec); - } - - /*---------------------------------------------------- - * sometimes this routine is called from headerbuttons - * viewmove needs to refresh the screen - */ -// XXX areawinset(curarea->win); - - /*---------------------------------------------------- - * record how much time has passed. clamp at 10 Hz - * pretend the previous frame occurred at the clamped time - */ -// now = PIL_check_seconds_timer(); - // frametime = (now - prevTime); - // if (frametime > 0.1f){ /* if more than 1/10s */ - // frametime = 1.0f/60.0; /* clamp at 1/60s so no jumps when starting to move */ -// } -// prevTime = now; - // sbadjust *= 60 * frametime; /* normalize ndof device adjustments to 100Hz for framerate independence */ - - /* fetch the current state of the ndof device & enforce dominant mode if selected */ -// XXX getndof(fval); - if (v3d->ndoffilter) - filterNDOFvalues(fval); - - - // put scaling back here, was previously in ghostwinlay - fval[0] = fval[0] * (1.0f/600.0f); - fval[1] = fval[1] * (1.0f/600.0f); - fval[2] = fval[2] * (1.0f/1100.0f); - fval[3] = fval[3] * 0.00005f; - fval[4] =-fval[4] * 0.00005f; - fval[5] = fval[5] * 0.00005f; - fval[6] = fval[6] / 1000000.0f; - - // scale more if not in perspective mode - if (rv3d->persp == RV3D_ORTHO) { - fval[0] = fval[0] * 0.05f; - fval[1] = fval[1] * 0.05f; - fval[2] = fval[2] * 0.05f; - fval[3] = fval[3] * 0.9f; - fval[4] = fval[4] * 0.9f; - fval[5] = fval[5] * 0.9f; - zsens *= 8; - } - - /* set object offset */ - if (ob) { - obofs[0] = -ob->obmat[3][0]; - obofs[1] = -ob->obmat[3][1]; - obofs[2] = -ob->obmat[3][2]; - } - else { - copy_v3_v3(obofs, rv3d->ofs); - } - - /* calc an adjustment based on distance from camera - disabled per patch 14402 */ - d = 1.0f; - -/* if (ob) { - sub_v3_v3v3(diff, obofs, rv3d->ofs); - d = len_v3(diff); - } -*/ - - reverse = (rv3d->persmat[2][1] < 0.0f) ? -1.0f : 1.0f; - - /*---------------------------------------------------- - * ndof device pan - */ - psens *= 1.0f + d; - curareaX = sbadjust * psens * fval[0]; - curareaY = sbadjust * psens * fval[1]; - dvec[0] = curareaX * rv3d->persinv[0][0] + curareaY * rv3d->persinv[1][0]; - dvec[1] = curareaX * rv3d->persinv[0][1] + curareaY * rv3d->persinv[1][1]; - dvec[2] = curareaX * rv3d->persinv[0][2] + curareaY * rv3d->persinv[1][2]; - add_v3_v3(rv3d->ofs, dvec); - - /*---------------------------------------------------- - * ndof device dolly - */ - len = zsens * sbadjust * fval[2]; - - if (rv3d->persp==RV3D_CAMOB) { - if(rv3d->persp==RV3D_CAMOB) { /* This is stupid, please fix - TODO */ - rv3d->camzoom+= 10.0f * -len; - } - if (rv3d->camzoom < minZoom) rv3d->camzoom = minZoom; - else if (rv3d->camzoom > maxZoom) rv3d->camzoom = maxZoom; - } - else if ((rv3d->dist> 0.001*v3d->grid) && (rv3d->dist<10.0*v3d->far)) { - rv3d->dist*=(1.0 + len); - } - - - /*---------------------------------------------------- - * ndof device turntable - * derived from the turntable code in viewmove - */ - - /* Get the 3x3 matrix and its inverse from the quaternion */ - quat_to_mat3( m,rv3d->viewquat); - invert_m3_m3(m_inv,m); - - /* Determine the direction of the x vector (for rotating up and down) */ - /* This can likely be compuated directly from the quaternion. */ - mul_m3_v3(m_inv,xvec); - mul_m3_v3(m_inv,yvec); - mul_m3_v3(m_inv,zvec); - - /* Perform the up/down rotation */ - phi = sbadjust * rsens * /*0.5f * */ fval[3]; /* spin vertically half as fast as horizontally */ - q1[0] = cos(phi); - mul_v3_v3fl(q1+1, xvec, sin(phi)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - - if (use_sel) { - conjugate_qt(q1); /* conj == inv for unit quat */ - sub_v3_v3(rv3d->ofs, obofs); - mul_qt_v3(q1, rv3d->ofs); - add_v3_v3(rv3d->ofs, obofs); - } - - /* Perform the orbital rotation */ - /* Perform the orbital rotation - If the seen Up axis is parallel to the zoom axis, rotation should be - achieved with a pure Roll motion (no Spin) on the device. When you start - to tilt, moving from Top to Side view, Spinning will increasingly become - more relevant while the Roll component will decrease. When a full - Side view is reached, rotations around the world's Up axis are achieved - with a pure Spin-only motion. In other words the control of the spinning - around the world's Up axis should move from the device's Spin axis to the - device's Roll axis depending on the orientation of the world's Up axis - relative to the screen. */ - //phi = sbadjust * rsens * reverse * fval[4]; /* spin the knob, y axis */ - phi = sbadjust * rsens * (yvec[2] * fval[4] + zvec[2] * fval[5]); - q1[0] = cos(phi); - q1[1] = q1[2] = 0.0; - q1[3] = sin(phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - - if (use_sel) { - conjugate_qt(q1); - sub_v3_v3(rv3d->ofs, obofs); - mul_qt_v3(q1, rv3d->ofs); - add_v3_v3(rv3d->ofs, obofs); - } - - /*---------------------------------------------------- - * refresh the screen - */ -// XXX scrarea_do_windraw(curarea); -} -#endif // if 0, unused NDof code - - /* Gets the view trasnformation from a camera * currently dosnt take camzoom into account * -- cgit v1.2.3 From 50ef78cdb8d9d746785bb03a296666dd15123e90 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Wed, 6 Jul 2011 18:50:59 +0000 Subject: various fixes to enable MSVC build, removed crusty old Win32 ndof code --- source/blender/editors/space_view3d/view3d_edit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 5a0c233edfa..2d8c14b29f3 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1002,7 +1002,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) /* TODO: replace such guesswork with a flag or field from the NDOF manager */ ndof->dt = dt = 0.0125f; - #define DEBUG_NDOF_MOTION + //#define DEBUG_NDOF_MOTION #ifdef DEBUG_NDOF_MOTION printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n", ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt); -- cgit v1.2.3 From b2eb2a00f104ae4d201ab58f83623e36ba45aef8 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 14 Jul 2011 03:27:33 +0000 Subject: introduce variables for ndof settings --- source/blender/makesdna/DNA_userdef_types.h | 18 ++++++++++++++++-- source/blender/makesrna/intern/rna_userdef.c | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 50e66f91028..78bc1c73ec9 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -365,7 +365,7 @@ typedef struct UserDef { short recent_files; /* maximum number of recently used files to remember */ short smooth_viewtx; /* miliseconds to spend spinning the view */ short glreslimit; - short ndof_pan, ndof_rotate; +/* short ndof_pan, ndof_rotate; */ short curssize; short color_picker_type; short ipo_new; /* interpolation mode for newly added F-Curves */ @@ -375,7 +375,10 @@ typedef struct UserDef { short scrcastwait; /* milliseconds between screencast snapshots */ short widget_unit; /* defaults to 20 for 72 DPI setting */ - short pad[3]; + short pad[1]; + + float ndof_sensitivity; /* overall sensitivity of 3D mouse */ + int ndof_flag; /* flags for 3D mouse */ char versemaster[160]; char verseuser[160]; @@ -578,6 +581,17 @@ extern UserDef U; /* from blenkernel blender.c */ #define TH_OLDSKOOL 3 #define TH_SHADED 4 +/* ndof_flag (3D mouse options) */ +#define NDOF_SHOW_GUIDE (1 << 0) +#define NDOF_FLY_HELICOPTER (1 << 1) +#define NDOF_LOCK_HORIZON (1 << 2) +/* the following might not need to be saved between sessions, + but they do need to live somewhere accessible... +#define NDOF_SHOULD_PAN (1 << 3) +#define NDOF_SHOULD_ZOOM (1 << 4) +#define NDOF_SHOULD_ROTATE (1 << 5) +*/ + #ifdef __cplusplus } #endif diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index b67805c97b9..86b88718ba8 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2705,7 +2705,9 @@ static void rna_def_userdef_input(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "dragthreshold"); RNA_def_property_range(prop, 3, 40); RNA_def_property_ui_text(prop, "Drag Threshold", "Amount of pixels you have to drag before dragging UI items happens"); - + + /* 3D mouse settings */ +/* prop= RNA_def_property(srna, "ndof_pan_speed", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "ndof_pan"); RNA_def_property_range(prop, 0, 200); @@ -2715,7 +2717,24 @@ static void rna_def_userdef_input(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "ndof_rotate"); RNA_def_property_range(prop, 0, 200); RNA_def_property_ui_text(prop, "NDof Rotation Speed", "The overall rotation speed of an NDOF device, as percent of standard"); - +*/ + prop= RNA_def_property(srna, "ndof_sensitivity", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.25f, 4.0f); + RNA_def_property_ui_text(prop, "3D Mouse Sensitivity", "Baseline sensitivity of the 3D Mouse"); + + prop= RNA_def_property(srna, "ndof_show_guide", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_SHOW_GUIDE); + RNA_def_property_ui_text(prop, "Show 3D Mouse Guide", "Visualize the center and axis of rotation (or projected position in fly mode)"); + + prop= RNA_def_property(srna, "ndof_lock_horizon", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_LOCK_HORIZON); + RNA_def_property_ui_text(prop, "Lock Horizon", "Keep horizon level while flying with 3D Mouse"); + + prop= RNA_def_property(srna, "ndof_fly_helicopter", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_FLY_HELICOPTER); + RNA_def_property_ui_text(prop, "Helicopter Fly Mode", ""); + + prop= RNA_def_property(srna, "mouse_double_click_time", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "dbl_click_time"); RNA_def_property_range(prop, 1, 1000); -- cgit v1.2.3 From 44d2e6eb109889f49fb9935d05ef201127d15805 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 14 Jul 2011 03:28:31 +0000 Subject: disable old ndof fly (new stuff en route from another machine) --- source/blender/editors/space_view3d/view3d_edit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 2d8c14b29f3..fc84944da02 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1127,7 +1127,6 @@ static int ndof_fly_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } -#endif // BEGIN old fly code // derived from blender 2.4 @@ -1263,6 +1262,7 @@ static int ndof_oldfly_invoke(bContext *C, wmOperator *op, wmEvent *event) } // END old fly code +#endif void VIEW3D_OT_ndof(struct wmOperatorType *ot) { @@ -1272,8 +1272,8 @@ void VIEW3D_OT_ndof(struct wmOperatorType *ot) ot->idname = "VIEW3D_OT_ndof"; /* api callbacks */ - ot->invoke = ndof_oldfly_invoke; -// ot->invoke = ndof_orbit_invoke; +// ot->invoke = ndof_oldfly_invoke; + ot->invoke = ndof_orbit_invoke; ot->poll = ED_operator_view3d_active; /* flags */ -- cgit v1.2.3 From cc1ba4569ccdb77a9371140def316caecac71da5 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 14 Jul 2011 21:20:45 +0000 Subject: more consistent and modal-friendly ndof events, fly mode v1 --- source/blender/editors/space_view3d/view3d_edit.c | 182 +++++++++++++-------- source/blender/editors/space_view3d/view3d_fly.c | 149 +++++++++++++++-- .../blender/editors/space_view3d/view3d_intern.h | 3 + source/blender/windowmanager/WM_types.h | 27 +-- .../blender/windowmanager/intern/wm_event_system.c | 2 + 5 files changed, 263 insertions(+), 100 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index fc84944da02..bfbff8a4906 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -929,10 +929,30 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER; } -#if 0 // NDOF utility functions +// NDOF utility functions +// (should these functions live in this file?) +float ndof_to_angle_axis(struct wmNDOFMotionData* ndof, float axis[3]) + { + const float x = ndof->rx; + const float y = ndof->ry; + const float z = ndof->rz; + + float angular_velocity = sqrtf(x*x + y*y + z*z); + float angle = ndof->dt * angular_velocity; + + float scale = 1.f / angular_velocity; + + // normalize + axis[0] = scale * x; + axis[1] = scale * y; + axis[2] = scale * z; + + return angle; + } + +#if 0 // unused utility functions // returns angular velocity (0..1), fills axis of rotation -// (shouldn't live in this file!) -static float ndof_to_angle_axis(const float ndof[3], float axis[3]) +float ndof_to_angle_axis(const float ndof[3], float axis[3]) { const float x = ndof[0]; const float y = ndof[1]; @@ -960,7 +980,7 @@ static float ndof_to_angular_velocity(wmNDOFMotionData* ndof) } #endif -static void ndof_to_quat(wmNDOFMotionData* ndof, float q[4]) +void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]) { const float x = ndof->rx; const float y = ndof->ry; @@ -988,6 +1008,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + const float dt = ndof->dt; + // tune these until everything feels right const float rot_sensitivity = 1.f; const float zoom_sensitivity = 1.f; @@ -996,12 +1018,6 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) // rather have bool, but... int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); - float dt = ndof->dt; - if (dt > 0.25f) - /* this is probably the first event for this motion, so set dt to something reasonable */ - /* TODO: replace such guesswork with a flag or field from the NDOF manager */ - ndof->dt = dt = 0.0125f; - //#define DEBUG_NDOF_MOTION #ifdef DEBUG_NDOF_MOTION printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n", @@ -1086,41 +1102,109 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } -#if 0 // not ready +#if 0 +// statics for controlling rv3d->dist corrections. +// viewmoveNDOF zeros and adjusts rv3d->ofs. +// viewmove restores based on dz_flag state. + +static int dz_flag = 0; +static float m_dist; + +static void mouse_rotation_workaround_push(RegionView3D* rv3d) +{ + // This is due to a side effect of the original + // mouse view rotation code. The rotation point is + // set a distance in front of the viewport to + // make rotating with the mouse look better. + // The distance effect is written at a low level + // in the view management instead of the mouse + // view function. This means that all other view + // movement devices must subtract this from their + // view transformations. + + float mat[3][3]; + float upvec[3]; + + if(rv3d->dist != 0.0) { + dz_flag = 1; + m_dist = rv3d->dist; + upvec[0] = upvec[1] = 0; + upvec[2] = rv3d->dist; + copy_m3_m4(mat, rv3d->viewinv); + mul_m3_v3(mat, upvec); + sub_v3_v3(rv3d->ofs, upvec); + rv3d->dist = 0.0; + } + + // this is still needed in version 2.5 [mce] + // warning! current viewmove does not look at dz_flag or m_dist + // don't expect 2D mouse to work properly right after using 3D mouse +} + +static void mouse_rotation_workaround_pop(RegionView3D* rv3d) +{ + if (dz_flag) { + dz_flag = 0; + rv3d->dist = m_dist; + } +} + static int ndof_fly_invoke(bContext *C, wmOperator *op, wmEvent *event) { RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - const int shouldRotate = 0, shouldMove = 1; + const int shouldRotate = 1, shouldTranslate = 0; + + const float dt = ndof->dt; - float dt = ndof->dt; - if (dt > 0.25f) - /* this is probably the first event for this motion, so set dt to something reasonable */ - /* TODO: replace such guesswork with a flag or field from the NDOF manager */ - ndof->dt = dt = 0.0125f; + float view_inv[4]; + invert_qt_qt(view_inv, rv3d->viewquat); if (shouldRotate) { const float turn_sensitivity = 1.f; float rot[4]; + float view_inv_conj[4]; + mouse_rotation_workaround_push(rv3d); + ndof_to_quat(ndof, rot); + copy_qt_qt(view_inv_conj, view_inv); + conjugate_qt(view_inv_conj); + + // transform rotation from view to world coordinates + mul_qt_qtqt(rot, view_inv, rot); + mul_qt_qtqt(rot, rot, view_inv_conj); + + // apply rotation to view offset (focal point) + mul_qt_v3(rot, rv3d->ofs); +// mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + rv3d->view = RV3D_VIEW_USER; } - if (shouldMove) + if (shouldTranslate) { const float forward_sensitivity = 1.f; const float vertical_sensitivity = 1.f; const float lateral_sensitivity = 1.f; - + float trans[3] = { - lateral_sensitivity * dt * ndof->tx, - vertical_sensitivity * dt * ndof->ty, - forward_sensitivity * rv3d->dist * dt * ndof->tz + lateral_sensitivity * ndof->tx, + vertical_sensitivity * ndof->ty, + forward_sensitivity * ndof->tz }; + +// mul_v3_fl(trans, rv3d->dist * dt); + mul_v3_fl(trans, dt); + + /* transform motion from view to world coordinates */ + mul_qt_v3(view_inv, trans); + + /* move center of view opposite of hand motion (this is camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, trans); } ED_region_tag_redraw(CTX_wm_region(C)); @@ -1141,9 +1225,7 @@ static void getndof(wmNDOFMotionData* indof, float* outdof) const float vertical_sensitivity = 1.6f; const float lateral_sensitivity = 2.5f; - const float dt = (indof->dt < 0.25f) ? indof->dt : 0.0125f; - // this is probably the first event for this motion, so set dt to something reasonable - // TODO: replace such guesswork with a flag or field from the NDOF manager + const float dt = indof->dt; outdof[0] = lateral_sensitivity * dt * indof->tx; outdof[1] = vertical_sensitivity * dt * indof->ty; @@ -1154,51 +1236,6 @@ static void getndof(wmNDOFMotionData* indof, float* outdof) outdof[5] = turn_sensitivity * dt * indof->rz; } -// statics for controlling rv3d->dist corrections. -// viewmoveNDOF zeros and adjusts rv3d->ofs. -// viewmove restores based on dz_flag state. - -static int dz_flag = 0; -static float m_dist; - -static void mouse_rotation_workaround_push(RegionView3D* rv3d) -{ - // This is due to a side effect of the original - // mouse view rotation code. The rotation point is - // set a distance in front of the viewport to - // make rotating with the mouse look better. - // The distance effect is written at a low level - // in the view management instead of the mouse - // view function. This means that all other view - // movement devices must subtract this from their - // view transformations. - - float mat[3][3]; - float upvec[3]; - - if(rv3d->dist != 0.0) { - dz_flag = 1; - m_dist = rv3d->dist; - upvec[0] = upvec[1] = 0; - upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, upvec); - sub_v3_v3(rv3d->ofs, upvec); - rv3d->dist = 0.0; - } - - // this is still needed in version 2.5 [mce] - // warning! current viewmove does not look at dz_flag or m_dist - // don't expect 2D mouse to work properly right after using 3D mouse -} - -static void mouse_rotation_workaround_pop(RegionView3D* rv3d) -{ - if (dz_flag) { - dz_flag = 0; - rv3d->dist = m_dist; - } -} static int ndof_oldfly_invoke(bContext *C, wmOperator *op, wmEvent *event) { @@ -1254,7 +1291,7 @@ static int ndof_oldfly_invoke(bContext *C, wmOperator *op, wmEvent *event) // translate the view sub_v3_v3(rv3d->ofs, tvec); - mouse_rotation_workaround_pop(rv3d); +// mouse_rotation_workaround_pop(rv3d); // back to 2.5 land! ED_region_tag_redraw(CTX_wm_region(C)); @@ -1272,8 +1309,9 @@ void VIEW3D_OT_ndof(struct wmOperatorType *ot) ot->idname = "VIEW3D_OT_ndof"; /* api callbacks */ -// ot->invoke = ndof_oldfly_invoke; ot->invoke = ndof_orbit_invoke; +// ot->invoke = ndof_fly_invoke; +// ot->invoke = ndof_oldfly_invoke; ot->poll = ED_operator_view3d_active; /* flags */ diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index ed1ed5b3881..00adfa13e28 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -158,7 +158,9 @@ typedef struct FlyInfo { short state; short use_precision; short redraw; - int mval[2]; + + int mval[2]; /* latest 2D mouse values */ + wmNDOFMotionData* ndof; /* latest 3D mouse values */ /* fly state state */ float speed; /* the speed the view is moving per redraw */ @@ -257,6 +259,8 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->ar = CTX_wm_region(C); fly->scene= CTX_data_scene(C); + puts("\n-- fly begin --"); + if(fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->id.lib) { BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library"); return FALSE; @@ -282,12 +286,14 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->zlock_momentum=0.0f; fly->grid= 1.0f; fly->use_precision= 0; + fly->redraw= 1; fly->dvec_prev[0]= fly->dvec_prev[1]= fly->dvec_prev[2]= 0.0f; fly->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); VECCOPY2D(fly->mval, event->mval) + fly->ndof = NULL; fly->time_lastdraw= fly->time_lastwheel= PIL_check_seconds_timer(); @@ -329,8 +335,17 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even /* perspective or ortho */ if (fly->rv3d->persp==RV3D_ORTHO) fly->rv3d->persp= RV3D_PERSP; /*if ortho projection, make perspective */ + copy_qt_qt(fly->rot_backup, fly->rv3d->viewquat); copy_v3_v3(fly->ofs_backup, fly->rv3d->ofs); + + /* the dist defines a vector that is infront of the offset + to rotate the view about. + this is no good for fly mode because we + want to rotate about the viewers center. + but to correct the dist removal we must + alter offset so the view doesn't jump. */ + fly->rv3d->dist= 0.0f; upvec[2]= fly->dist_backup; /*x and y are 0*/ @@ -338,7 +353,6 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even sub_v3_v3(fly->rv3d->ofs, upvec); /*Done with correcting for the dist*/ } - /* center the mouse, probably the UI mafia are against this but without its quite annoying */ WM_cursor_warp(CTX_wm_window(C), fly->ar->winrct.xmin + fly->ar->winx/2, fly->ar->winrct.ymin + fly->ar->winy/2); @@ -356,6 +370,8 @@ static int flyEnd(bContext *C, FlyInfo *fly) if(fly->state == FLY_RUNNING) return OPERATOR_RUNNING_MODAL; + puts("\n-- fly end --"); + WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), fly->timer); ED_region_draw_cb_exit(fly->ar->type, fly->draw_handle_pixel); @@ -401,6 +417,9 @@ static int flyEnd(bContext *C, FlyInfo *fly) if(fly->obtfm) MEM_freeN(fly->obtfm); + if(fly->ndof) + MEM_freeN(fly->ndof); + if(fly->state == FLY_CONFIRM) { MEM_freeN(fly); return OPERATOR_FINISHED; @@ -412,12 +431,46 @@ static int flyEnd(bContext *C, FlyInfo *fly) static void flyEvent(FlyInfo *fly, wmEvent *event) { - if (event->type == TIMER && event->customdata == fly->timer) { - fly->redraw = 1; - } - else if (event->type == MOUSEMOVE) { + if (event->type == MOUSEMOVE) { VECCOPY2D(fly->mval, event->mval); - } /* handle modal keymap first */ + } + else if (event->type == NDOF_MOTION) { + // do these automagically get delivered? yes. + // puts("ndof motion detected in fly mode!"); + // static const char* tag_name = "3D mouse position"; + + wmNDOFMotionData* incoming_ndof = (wmNDOFMotionData*) event->customdata; + switch (incoming_ndof->progress) + { + case P_STARTING: + // start keeping track of 3D mouse position + puts("start keeping track of 3D mouse position"); + // fall through... + case P_IN_PROGRESS: + // update 3D mouse position + putchar('.'); fflush(stdout); + if (fly->ndof == NULL) + // fly->ndof = MEM_mallocN(sizeof(wmNDOFMotionData), tag_name); + fly->ndof = MEM_dupallocN(incoming_ndof); + // fly->ndof = malloc(sizeof(wmNDOFMotionData)); + else + memcpy(fly->ndof, incoming_ndof, sizeof(wmNDOFMotionData)); + break; + case P_FINISHING: + // stop keeping track of 3D mouse position + puts("stop keeping track of 3D mouse position"); + if (fly->ndof) + { + MEM_freeN(fly->ndof); + // free(fly->ndof); + fly->ndof = NULL; + } + break; + default: + ; // should always be one of the above 3 + } + } + /* handle modal keymap first */ else if (event->type == EVT_MODAL_MAP) { switch (event->val) { case FLY_MODAL_CANCEL: @@ -528,7 +581,6 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) case FLY_MODAL_PRECISION_DISABLE: fly->use_precision= FALSE; break; - } } } @@ -567,16 +619,12 @@ static int flyApply(bContext *C, FlyInfo *fly) unsigned char apply_rotation= 1; /* if the user presses shift they can look about without movinf the direction there looking*/ + static unsigned int iteration = 1; + printf("fly timer %d\n", iteration++); + if(fly->root_parent) ED_view3d_to_m4(prev_view_mat, fly->rv3d->ofs, fly->rv3d->viewquat, fly->rv3d->dist); - /* the dist defines a vector that is infront of the offset - to rotate the view about. - this is no good for fly mode because we - want to rotate about the viewers center. - but to correct the dist removal we must - alter offset so the view doesn't jump. */ - xmargin= ar->winx/20.0f; ymargin= ar->winy/20.0f; @@ -622,6 +670,8 @@ static int flyApply(bContext *C, FlyInfo *fly) float time_redraw; float time_redraw_clamped; + fly->redraw= 1; + time_current= PIL_check_seconds_timer(); time_redraw= (float)(time_current - fly->time_lastdraw); time_redraw_clamped= MIN2(0.05f, time_redraw); /* clamt the redraw time to avoid jitter in roll correction */ @@ -854,11 +904,69 @@ static int flyApply(bContext *C, FlyInfo *fly) copy_v3_v3(fly->dvec_prev, dvec); } -/* moved to flyEnd() */ - return OPERATOR_FINISHED; } +static int flyApply_ndof(bContext *C, FlyInfo *fly) +{ + // shorthand for oft-used variables + wmNDOFMotionData* ndof = fly->ndof; + const float dt = ndof->dt; + RegionView3D* rv3d = fly->rv3d; + + const int shouldRotate = 1, shouldTranslate = 1; + + float view_inv[4]; + invert_qt_qt(view_inv, rv3d->viewquat); + + if (shouldRotate) + { + const float turn_sensitivity = 1.f; + + float rotation[4]; + float axis[3]; + float angle = turn_sensitivity * ndof_to_angle_axis(ndof, axis); + + // transform rotation axis from view to world coordinates + mul_qt_v3(view_inv, axis); + + // apply rotation to view + axis_angle_to_quat(rotation, axis, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + + rv3d->view = RV3D_VIEW_USER; + + fly->redraw = 1; + } + + if (shouldTranslate) + { + const float forward_sensitivity = 1.f; + const float vertical_sensitivity = 0.4f; + const float lateral_sensitivity = 0.6f; + + float speed = 10.f; // blender units per second + // ^^ this is ok for default cube scene, but should scale with.. something + + float trans[3] = { + lateral_sensitivity * ndof->tx, + vertical_sensitivity * ndof->ty, + forward_sensitivity * ndof->tz + }; + + mul_v3_fl(trans, speed * dt); + + // transform motion from view to world coordinates + mul_qt_v3(view_inv, trans); + + // move center of view opposite of hand motion (this is camera mode, not object mode) + sub_v3_v3(rv3d->ofs, trans); + + fly->redraw = 1; + } + + return OPERATOR_FINISHED; +} static int fly_invoke(bContext *C, wmOperator *op, wmEvent *event) @@ -908,7 +1016,12 @@ static int fly_modal(bContext *C, wmOperator *op, wmEvent *event) flyEvent(fly, event); - if(event->type==TIMER && event->customdata == fly->timer) + if (fly->ndof) // 3D mouse overrules [2D mouse + timer] + { + if (event->type==NDOF_MOTION) + flyApply_ndof(C, fly); + } + else if (event->type==TIMER && event->customdata == fly->timer) flyApply(C, fly); do_draw |= fly->redraw; diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 1a148481031..3658a481bdf 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -51,6 +51,7 @@ struct ARegionType; struct bPoseChannel; struct bAnimVizSettings; struct bMotionPath; +struct wmNDOFMotionData; #define BL_NEAR_CLIP 0.001 @@ -92,6 +93,8 @@ void VIEW3D_OT_zoom_border(struct wmOperatorType *ot); void VIEW3D_OT_drawtype(struct wmOperatorType *ot); void view3d_boxview_copy(ScrArea *sa, ARegion *ar); +void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]); +float ndof_to_angle_axis(struct wmNDOFMotionData* ndof, float axis[3]); /* view3d_fly.c */ void view3d_keymap(struct wmKeyConfig *keyconf); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 26c394a2ad3..7476410ec19 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -377,17 +377,24 @@ typedef struct wmTabletData { float Ytilt; /* as above */ } wmTabletData; -typedef struct { +typedef enum { // motion progress, for modal handlers + P_NOT_STARTED, + P_STARTING, // <-- + P_IN_PROGRESS, // <-- only these are sent for NDOF motion + P_FINISHING, // <-- + P_FINISHED + } wmProgress; + +typedef struct wmNDOFMotionData { /* awfully similar to GHOST_TEventNDOFMotionData... */ - - /* Each component normally ranges from -1 to +1, but can exceed that. */ - - float tx, ty, tz; /* translation: -x left, +y forward, -z up */ - float rx, ry, rz; /* rotation: - axis = (rx,ry,rz).normalized - amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg] */ - - float dt; // time since previous NDOF Motion event (or zero if this is the first) + // Each component normally ranges from -1 to +1, but can exceed that. + // These use blender standard view coordinates, with positive rotations being CCW about the axis. + float tx, ty, tz; // translation + float rx, ry, rz; // rotation: + // axis = (rx,ry,rz).normalized + // amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg] + float dt; // time since previous NDOF Motion event + wmProgress progress; // is this the first event, the last, or one of many in between? } wmNDOFMotionData; typedef struct wmTimer { diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index b41eebc5298..c2df53c9e91 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2324,6 +2324,8 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g data->dt = ghost->dt; + data->progress = (wmProgress) ghost->progress; + event->custom = EVT_DATA_NDOF_MOTION; event->customdata = data; event->customdatafree = 1; -- cgit v1.2.3 From b0c8abf04e6af902827913e09c245efa690ce5c4 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 14 Jul 2011 22:01:09 +0000 Subject: removed unused ndof code --- source/blender/editors/space_view3d/view3d_edit.c | 234 +--------------------- 1 file changed, 1 insertion(+), 233 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index bfbff8a4906..0c07df9fd01 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -950,36 +950,6 @@ float ndof_to_angle_axis(struct wmNDOFMotionData* ndof, float axis[3]) return angle; } -#if 0 // unused utility functions -// returns angular velocity (0..1), fills axis of rotation -float ndof_to_angle_axis(const float ndof[3], float axis[3]) - { - const float x = ndof[0]; - const float y = ndof[1]; - const float z = ndof[2]; - - float angular_velocity = sqrtf(x*x + y*y + z*z); - - float scale = 1.f / angular_velocity; - - // normalize - axis[0] = scale * x; - axis[1] = scale * y; - axis[2] = scale * z; - - return angular_velocity; - } - -static float ndof_to_angular_velocity(wmNDOFMotionData* ndof) - { - const float x = ndof->rx; - const float y = ndof->ry; - const float z = ndof->rz; - - return sqrtf(x*x + y*y + z*z); - } -#endif - void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]) { const float x = ndof->rx; @@ -999,11 +969,10 @@ void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]) q[3] = scale * z; } -// Mike's original version: +static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) // -- "orbit" navigation (trackball/turntable) // -- zooming // -- panning in rotationally-locked views -static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) { RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; @@ -1102,205 +1071,6 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } -#if 0 -// statics for controlling rv3d->dist corrections. -// viewmoveNDOF zeros and adjusts rv3d->ofs. -// viewmove restores based on dz_flag state. - -static int dz_flag = 0; -static float m_dist; - -static void mouse_rotation_workaround_push(RegionView3D* rv3d) -{ - // This is due to a side effect of the original - // mouse view rotation code. The rotation point is - // set a distance in front of the viewport to - // make rotating with the mouse look better. - // The distance effect is written at a low level - // in the view management instead of the mouse - // view function. This means that all other view - // movement devices must subtract this from their - // view transformations. - - float mat[3][3]; - float upvec[3]; - - if(rv3d->dist != 0.0) { - dz_flag = 1; - m_dist = rv3d->dist; - upvec[0] = upvec[1] = 0; - upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - mul_m3_v3(mat, upvec); - sub_v3_v3(rv3d->ofs, upvec); - rv3d->dist = 0.0; - } - - // this is still needed in version 2.5 [mce] - // warning! current viewmove does not look at dz_flag or m_dist - // don't expect 2D mouse to work properly right after using 3D mouse -} - -static void mouse_rotation_workaround_pop(RegionView3D* rv3d) -{ - if (dz_flag) { - dz_flag = 0; - rv3d->dist = m_dist; - } -} - -static int ndof_fly_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - RegionView3D* rv3d = CTX_wm_region_view3d(C); - wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - - const int shouldRotate = 1, shouldTranslate = 0; - - const float dt = ndof->dt; - - float view_inv[4]; - invert_qt_qt(view_inv, rv3d->viewquat); - - if (shouldRotate) - { - const float turn_sensitivity = 1.f; - - float rot[4]; - float view_inv_conj[4]; - mouse_rotation_workaround_push(rv3d); - - ndof_to_quat(ndof, rot); - - copy_qt_qt(view_inv_conj, view_inv); - conjugate_qt(view_inv_conj); - - // transform rotation from view to world coordinates - mul_qt_qtqt(rot, view_inv, rot); - mul_qt_qtqt(rot, rot, view_inv_conj); - - // apply rotation to view offset (focal point) - mul_qt_v3(rot, rv3d->ofs); -// mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); - - rv3d->view = RV3D_VIEW_USER; - } - - if (shouldTranslate) - { - const float forward_sensitivity = 1.f; - const float vertical_sensitivity = 1.f; - const float lateral_sensitivity = 1.f; - - float trans[3] = { - lateral_sensitivity * ndof->tx, - vertical_sensitivity * ndof->ty, - forward_sensitivity * ndof->tz - }; - -// mul_v3_fl(trans, rv3d->dist * dt); - mul_v3_fl(trans, dt); - - /* transform motion from view to world coordinates */ - mul_qt_v3(view_inv, trans); - - /* move center of view opposite of hand motion (this is camera mode, not object mode) */ - sub_v3_v3(rv3d->ofs, trans); - } - - ED_region_tag_redraw(CTX_wm_region(C)); - - return OPERATOR_FINISHED; -} - -// BEGIN old fly code -// derived from blender 2.4 - -static void getndof(wmNDOFMotionData* indof, float* outdof) -{ - // Rotations feel relatively faster than translations only in fly mode, so - // we have no choice but to fix that here (not in the plugins) - const float turn_sensitivity = 0.8f; - - const float forward_sensitivity = 2.5f; - const float vertical_sensitivity = 1.6f; - const float lateral_sensitivity = 2.5f; - - const float dt = indof->dt; - - outdof[0] = lateral_sensitivity * dt * indof->tx; - outdof[1] = vertical_sensitivity * dt * indof->ty; - outdof[2] = forward_sensitivity * dt * indof->tz; - - outdof[3] = turn_sensitivity * dt * indof->rx; - outdof[4] = turn_sensitivity * dt * indof->ry; - outdof[5] = turn_sensitivity * dt * indof->rz; -} - - -static int ndof_oldfly_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - RegionView3D* rv3d = CTX_wm_region_view3d(C); - wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - - float phi; - float dval[6]; - float tvec[3], rvec[3]; - float q1[4]; - float mat[3][3]; - - // fetch the current state of the ndof device - getndof(ndof, dval); - - // force perspective mode. This is a hack and is - // incomplete. It doesn't actually affect the view - // until the first draw and doesn't update the menu - // to reflect persp mode. - rv3d->persp = RV3D_PERSP; - - // Correct the distance jump if rv3d->dist != 0 - mouse_rotation_workaround_push(rv3d); - - // Apply rotation - rvec[0] = dval[3]; - rvec[1] = dval[4]; - rvec[2] = dval[5]; - - // rotate device x and y by view z - copy_m3_m4(mat, rv3d->viewinv); - mat[2][2] = 0.0f; - mul_m3_v3(mat, rvec); - - // rotate the view - phi = normalize_v3(rvec); - if(phi != 0) { - axis_angle_to_quat(q1,rvec,phi); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); - } - - // Apply translation - tvec[0] = dval[0]; - tvec[1] = dval[1]; - tvec[2] = dval[2]; - - // the next three lines rotate the x and y translation coordinates - // by the current z axis angle - copy_m3_m4(mat, rv3d->viewinv); - mat[2][2] = 0.0f; - mul_m3_v3(mat, tvec); - - // translate the view - sub_v3_v3(rv3d->ofs, tvec); - -// mouse_rotation_workaround_pop(rv3d); - - // back to 2.5 land! - ED_region_tag_redraw(CTX_wm_region(C)); - return OPERATOR_FINISHED; -} - -// END old fly code -#endif - void VIEW3D_OT_ndof(struct wmOperatorType *ot) { /* identifiers */ @@ -1310,8 +1080,6 @@ void VIEW3D_OT_ndof(struct wmOperatorType *ot) /* api callbacks */ ot->invoke = ndof_orbit_invoke; -// ot->invoke = ndof_fly_invoke; -// ot->invoke = ndof_oldfly_invoke; ot->poll = ED_operator_view3d_active; /* flags */ -- cgit v1.2.3 From 3ad978ea8ec425e000fd1d79944b47b037f2f3f6 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 18 Jul 2011 22:37:48 +0000 Subject: switched off ndof fly logging (receiving end) --- source/blender/editors/space_view3d/view3d_fly.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 00adfa13e28..ec17aa9586f 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -29,6 +29,8 @@ /* defines VIEW3D_OT_fly modal operator */ +// #define NDOF_FLY_DEBUG + #include "DNA_anim_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -259,7 +261,9 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->ar = CTX_wm_region(C); fly->scene= CTX_data_scene(C); + #ifdef NDOF_FLY_DEBUG puts("\n-- fly begin --"); + #endif if(fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->id.lib) { BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library"); @@ -370,7 +374,9 @@ static int flyEnd(bContext *C, FlyInfo *fly) if(fly->state == FLY_RUNNING) return OPERATOR_RUNNING_MODAL; + #ifdef NDOF_FLY_DEBUG puts("\n-- fly end --"); + #endif WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), fly->timer); @@ -444,11 +450,15 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) { case P_STARTING: // start keeping track of 3D mouse position + #ifdef NDOF_FLY_DEBUG puts("start keeping track of 3D mouse position"); + #endif // fall through... case P_IN_PROGRESS: // update 3D mouse position + #ifdef NDOF_FLY_DEBUG putchar('.'); fflush(stdout); + #endif if (fly->ndof == NULL) // fly->ndof = MEM_mallocN(sizeof(wmNDOFMotionData), tag_name); fly->ndof = MEM_dupallocN(incoming_ndof); @@ -458,7 +468,9 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) break; case P_FINISHING: // stop keeping track of 3D mouse position + #ifdef NDOF_FLY_DEBUG puts("stop keeping track of 3D mouse position"); + #endif if (fly->ndof) { MEM_freeN(fly->ndof); @@ -619,8 +631,10 @@ static int flyApply(bContext *C, FlyInfo *fly) unsigned char apply_rotation= 1; /* if the user presses shift they can look about without movinf the direction there looking*/ + #ifdef NDOF_FLY_DEBUG static unsigned int iteration = 1; printf("fly timer %d\n", iteration++); + #endif if(fly->root_parent) ED_view3d_to_m4(prev_view_mat, fly->rv3d->ofs, fly->rv3d->viewquat, fly->rv3d->dist); -- cgit v1.2.3 From 7f74abeaca38d0c1634a8d0532bb38877a1f730e Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 19 Jul 2011 04:12:49 +0000 Subject: translated ndof menu from C to Python, enabled helicopter fly mode --- source/blender/editors/space_view3d/view3d_fly.c | 9 +++ source/blender/windowmanager/intern/wm_operators.c | 64 +++++++--------------- 2 files changed, 28 insertions(+), 45 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index ec17aa9586f..8269d0e7cd3 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -973,6 +973,15 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // transform motion from view to world coordinates mul_qt_v3(view_inv, trans); + // int fly_mode = TRUE; + int fly_mode = U.ndof_flag & NDOF_FLY_HELICOPTER; + // could also use RNA to get a simple boolean value + + if (fly_mode) + { + trans[2] = speed * dt * vertical_sensitivity * ndof->ty; + } + // move center of view opposite of hand motion (this is camera mode, not object mode) sub_v3_v3(rv3d->ofs, trans); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 6fb6a8dcf1f..7e93c2d5f46 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1401,37 +1401,6 @@ static uiBlock* wm_block_ndof_menu_1st(bContext* C, ARegion* ar, void* UNUSED(ar return block; } -static uiBlock *wm_block_ndof_menu(bContext *C, ARegion *ar, void *UNUSED(arg_op)) -{ - static char search[256]= ""; - wmEvent event; - wmWindow *win= CTX_wm_window(C); - uiBlock *block; - uiBut *but; - - block= uiBeginBlock(C, ar, "ndof_popup", UI_EMBOSS); -// uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT); - uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_POPUP|UI_BLOCK_MOVEMOUSE_QUIT); - - but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, 0, 0, ""); - uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL); - - /* fake button, it holds space for search items */ - uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 9*UI_UNIT_X, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL); - - uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */ - uiEndBlock(C, block); - - event= *(win->eventstate); /* XXX huh huh? make api call */ - event.type= EVT_BUT_OPEN; - event.val= KM_PRESS; - event.customdata= but; - event.customdatafree= FALSE; - wm_event_add(win, &event); - - return block; -} - static int wm_ndof_menu_poll(bContext *C) { if(CTX_wm_window(C)==NULL) @@ -1453,6 +1422,11 @@ static int wm_ndof_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { + uiPupMenuInvoke(C,"VIEW3D_MT_ndof_settings"); + + return OPERATOR_CANCELLED; // <-- correct? + +/* // uiPupMenuNotice(C, "Hello!"); // <-- this works // uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck! // ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works @@ -1460,12 +1434,25 @@ static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN); uiLayout* layout = uiPupMenuLayout(pup); + uiItemS(layout); // separator + uiItemFloatO(layout, "sensitivity", 0, 0, "ndof_sensitivity", 1.f); + // do I have to look specifically in "UserPreferences" for ndof_sensitivity property? + + // trial & error -- ok, mostly error +// uiItemBooleanO(layout, "enable pan/zoom", ICON_NDOF_TRANS, "ndof_toggle_pan_zoom_enabled", "ndof_pan_zoom_enabled", 1); +// uiItemBooleanO(layout, "enable rotation", ICON_NDOF_TURN, "ndof_toggle_rotation_enabled", "ndof_rotation_enabled", 1); +// uiItemV(layout,"sensitivity",ICON_NDOF_TRANS, 1); + printf("ndof: menu invoked in "); switch (CTX_wm_area(C)->spacetype) // diff spaces can have diff 3d mouse options { case SPACE_VIEW3D: puts("3D area"); + uiItemS(layout); + uiItemL(layout, "3D navigation mode", 0); + uiItemBooleanO(layout, "helicopter", ICON_NDOF_FLY, 0, "ndof_fly_helicopter", 1); + uiItemBooleanO(layout, "lock horizon", ICON_NDOF_DOM, 0, "ndof_lock_horizon", 1); break; case SPACE_IMAGE: puts("image area"); @@ -1474,25 +1461,12 @@ static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even puts("some iNDOFferent area"); } - //uiBlock* block = uiLayoutGetBlock(layout); //int foo = 1; //uiDefButI(block, TOG, 0, "foo", 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, &foo, 0.f, 1.f, 0.1f, 0.9f, "15%"); - - uiItemS(layout); // separator - - uiItemBooleanO(layout, "enable pan/zoom", ICON_NDOF_TRANS, "ndof_toggle_pan_zoom_enabled", "ndof_pan_zoom_enabled", 1); - uiItemBooleanO(layout, "enable rotation", ICON_NDOF_TURN, "ndof_toggle_rotation_enabled", "ndof_rotation_enabled", 1); - uiItemFloatO(layout, "sensitivity", 0, "ndof_adjust_sensitivity", "ndof_sensitivity", 1.f); - uiItemV(layout,"sensitivity",ICON_NDOF_TRANS, 1); - - uiItemS(layout); - uiItemL(layout, "3D navigation mode", ICON_NDOF_FLY); - uiItemL(layout, "...", 0); uiPupMenuEnd(C,pup); - - return OPERATOR_CANCELLED; // <-- correct? +*/ } static void WM_OT_ndof_menu(wmOperatorType *ot) -- cgit v1.2.3 From c89379e7e15aeb50a7d7106218821a17e5a7dac9 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 19 Jul 2011 22:40:22 +0000 Subject: ndof fly: better sharing of control between 2D and 3D mouse, compile fix for MSVC, lock horizon implemented --- source/blender/editors/space_view3d/view3d_fly.c | 77 ++++++++++++++++-------- 1 file changed, 52 insertions(+), 25 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 8269d0e7cd3..6955aefcb9e 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -477,6 +477,8 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) // free(fly->ndof); fly->ndof = NULL; } + /* update the time else the view will jump when 2D mouse/timer resume */ + fly->time_lastdraw= PIL_check_seconds_timer(); break; default: ; // should always be one of the above 3 @@ -933,26 +935,6 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); - if (shouldRotate) - { - const float turn_sensitivity = 1.f; - - float rotation[4]; - float axis[3]; - float angle = turn_sensitivity * ndof_to_angle_axis(ndof, axis); - - // transform rotation axis from view to world coordinates - mul_qt_v3(view_inv, axis); - - // apply rotation to view - axis_angle_to_quat(rotation, axis, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); - - rv3d->view = RV3D_VIEW_USER; - - fly->redraw = 1; - } - if (shouldTranslate) { const float forward_sensitivity = 1.f; @@ -973,12 +955,10 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // transform motion from view to world coordinates mul_qt_v3(view_inv, trans); - // int fly_mode = TRUE; - int fly_mode = U.ndof_flag & NDOF_FLY_HELICOPTER; - // could also use RNA to get a simple boolean value - - if (fly_mode) + if (U.ndof_flag & NDOF_FLY_HELICOPTER) + // could also use RNA to get a simple boolean value { + // replace world z component with device y (yes it makes sense) trans[2] = speed * dt * vertical_sensitivity * ndof->ty; } @@ -988,6 +968,53 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) fly->redraw = 1; } + if (shouldRotate) + { + const float turn_sensitivity = 1.f; + + float rotation[4]; + float axis[3]; + float angle = turn_sensitivity * ndof_to_angle_axis(ndof, axis); + + // transform rotation axis from view to world coordinates + mul_qt_v3(view_inv, axis); + + // apply rotation to view + axis_angle_to_quat(rotation, axis, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + + if (U.ndof_flag & NDOF_LOCK_HORIZON) + // force an upright viewpoint + // TODO: make this less... sudden + { + float view_horizon[3] = {1, 0, 0}; // view +x + float view_direction[3] = {0, 0, -1}; // view -z (into screen) + + // find new inverse since viewquat has changed + invert_qt_qt(view_inv, rv3d->viewquat); + + // transform view vectors to world coordinates + mul_qt_v3(view_inv, view_horizon); + mul_qt_v3(view_inv, view_direction); + + // find difference between view & world horizons + // true horizon lives in world xy plane, so look only at difference in z + angle = -asinf(view_horizon[2]); + + #ifdef NDOF_FLY_DEBUG + printf("lock horizon: adjusting %.1f degrees\n\n", RAD2DEG(angle)); + #endif + + // rotate view so view horizon = world horizon + axis_angle_to_quat(rotation, view_direction, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + } + + rv3d->view = RV3D_VIEW_USER; + + fly->redraw = 1; + } + return OPERATOR_FINISHED; } -- cgit v1.2.3 From 1cce0dd505b72b1e1b2188c9f72fa73d73e6ec4d Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Thu, 21 Jul 2011 20:57:23 +0000 Subject: Prepare for NDOF event handling all the way to keymaps (and keymap editor). --- source/blender/windowmanager/wm_event_types.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index 210dd902b99..579f20ca605 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -125,6 +125,7 @@ enum { NDOF_BUTTON_8, NDOF_BUTTON_9, NDOF_BUTTON_10, + NDOF_LAST }; @@ -290,8 +291,11 @@ enum { /* test whether the event is tweak event */ #define ISTWEAK(event) (event >= EVT_TWEAK_L && event <= EVT_GESTURE) + /* test whether the event is a NDOF event */ +#define ISNDOF(event) (event >= NDOF_MOTION && event < NDOF_LAST) + /* test whether event type is acceptable as hotkey, excluding modifiers */ -#define ISHOTKEY(event) ((ISKEYBOARD(event) || ISMOUSE(event)) && event!=ESCKEY && !(event>=LEFTCTRLKEY && event<=LEFTSHIFTKEY) && !(event>=UNKNOWNKEY && event<=GRLESSKEY)) +#define ISHOTKEY(event) ((ISKEYBOARD(event) || ISMOUSE(event) || ISNDOF(event)) && event!=ESCKEY && !(event>=LEFTCTRLKEY && event<=LEFTSHIFTKEY) && !(event>=UNKNOWNKEY && event<=GRLESSKEY)) /* **************** BLENDER GESTURE EVENTS (0x5000) **************** */ -- cgit v1.2.3 From 2258afc1be78a2cd629f0efb8e5d69acc4c58d2c Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Thu, 21 Jul 2011 21:40:00 +0000 Subject: Handle NDOF events on RNA side for windowmanager. --- source/blender/makesrna/intern/rna_wm.c | 88 ++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 7ea4701dec3..31e1d73c8de 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -106,6 +106,46 @@ EnumPropertyItem event_timer_type_items[]= { {TIMER2, "TIMER2", 0, "Timer 2", ""}, {0, NULL, 0, NULL, NULL}}; +EnumPropertyItem event_ndof_type_items[]= { + /* buttons on all 3dconnexion devices */ + {NDOF_BUTTON_MENU, "NDOF_BUTTON_MENU", 0, "Menu", ""}, + {NDOF_BUTTON_FIT, "NDOF_BUTTON_FIT", 0, "Fit", ""}, + /* view buttons */ + {NDOF_BUTTON_TOP, "NDOF_BUTTON_TOP", 0, "Top", ""}, + {NDOF_BUTTON_BOTTOM, "NDOF_BUTTON_BOTTOM", 0, "Bottom", ""}, + {NDOF_BUTTON_LEFT, "NDOF_BUTTON_LEFT", 0, "Left", ""}, + {NDOF_BUTTON_RIGHT, "NDOF_BUTTON_RIGHT", 0, "Right", ""}, + {NDOF_BUTTON_FRONT, "NDOF_BUTTON_FRONT", 0, "Front", ""}, + {NDOF_BUTTON_BACK, "NDOF_BUTTON_BACK", 0, "Back", ""}, + /* more views */ + {NDOF_BUTTON_ISO1, "NDOF_BUTTON_ISO1", 0, "ISO 1", ""}, + {NDOF_BUTTON_ISO2, "NDOF_BUTTON_ISO2", 0, "ISO 2", ""}, + /* 90 degree rotations */ + {NDOF_BUTTON_ROLL_CW, "NDOF_BUTTON_ROLL_CW", 0, "Roll CW", ""}, + {NDOF_BUTTON_ROLL_CCW, "NDOF_BUTTON_ROLL_CCW", 0, "Roll CCW", ""}, + {NDOF_BUTTON_SPIN_CW, "NDOF_BUTTON_SPIN_CW", 0, "Spin CW", ""}, + {NDOF_BUTTON_SPIN_CCW, "NDOF_BUTTON_SPIN_CCW", 0, "Spin CCW", ""}, + {NDOF_BUTTON_TILT_CW, "NDOF_BUTTON_TILT_CW", 0, "Tilt CW", ""}, + {NDOF_BUTTON_TILT_CCW, "NDOF_BUTTON_TILT_CCW", 0, "Tilt CCW", ""}, + /* device control */ + {NDOF_BUTTON_ROTATE, "NDOF_BUTTON_ROTATE", 0, "Rotate", ""}, + {NDOF_BUTTON_PANZOOM, "NDOF_BUTTON_PANZOOM", 0, "Pan/Zoom", ""}, + {NDOF_BUTTON_DOMINANT, "NDOF_BUTTON_DOMINANT", 0, "Dominant", ""}, + {NDOF_BUTTON_PLUS, "NDOF_BUTTON_PLUS", 0, "Plus", ""}, + {NDOF_BUTTON_MINUS, "NDOF_BUTTON_MINUS", 0, "Minus", ""}, + /* general-purpose buttons */ + {NDOF_BUTTON_1, "NDOF_BUTTON_1", 0, "Button 1", ""}, + {NDOF_BUTTON_2, "NDOF_BUTTON_2", 0, "Button 2", ""}, + {NDOF_BUTTON_3, "NDOF_BUTTON_3", 0, "Button 3", ""}, + {NDOF_BUTTON_4, "NDOF_BUTTON_4", 0, "Button 4", ""}, + {NDOF_BUTTON_5, "NDOF_BUTTON_5", 0, "Button 5", ""}, + {NDOF_BUTTON_6, "NDOF_BUTTON_6", 0, "Button 6", ""}, + {NDOF_BUTTON_7, "NDOF_BUTTON_7", 0, "Button 7", ""}, + {NDOF_BUTTON_8, "NDOF_BUTTON_8", 0, "Button 8", ""}, + {NDOF_BUTTON_9, "NDOF_BUTTON_9", 0, "Button 9", ""}, + {NDOF_BUTTON_10, "NDOF_BUTTON_10", 0, "Button 10", ""}, + {0, NULL, 0, NULL, NULL}}; + /* not returned: CAPSLOCKKEY, UNKNOWNKEY */ EnumPropertyItem event_type_items[] = { @@ -256,6 +296,44 @@ EnumPropertyItem event_type_items[] = { {TIMER0, "TIMER0", 0, "Timer 0", ""}, {TIMER1, "TIMER1", 0, "Timer 1", ""}, {TIMER2, "TIMER2", 0, "Timer 2", ""}, + {0, "", 0, NULL, NULL}, + /* buttons on all 3dconnexion devices */ + {NDOF_BUTTON_MENU, "NDOF_BUTTON_MENU", 0, "Menu", ""}, + {NDOF_BUTTON_FIT, "NDOF_BUTTON_FIT", 0, "Fit", ""}, + /* view buttons */ + {NDOF_BUTTON_TOP, "NDOF_BUTTON_TOP", 0, "Top", ""}, + {NDOF_BUTTON_BOTTOM, "NDOF_BUTTON_BOTTOM", 0, "Bottom", ""}, + {NDOF_BUTTON_LEFT, "NDOF_BUTTON_LEFT", 0, "Left", ""}, + {NDOF_BUTTON_RIGHT, "NDOF_BUTTON_RIGHT", 0, "Right", ""}, + {NDOF_BUTTON_FRONT, "NDOF_BUTTON_FRONT", 0, "Front", ""}, + {NDOF_BUTTON_BACK, "NDOF_BUTTON_BACK", 0, "Back", ""}, + /* more views */ + {NDOF_BUTTON_ISO1, "NDOF_BUTTON_ISO1", 0, "ISO 1", ""}, + {NDOF_BUTTON_ISO2, "NDOF_BUTTON_ISO2", 0, "ISO 2", ""}, + /* 90 degree rotations */ + {NDOF_BUTTON_ROLL_CW, "NDOF_BUTTON_ROLL_CW", 0, "Roll CW", ""}, + {NDOF_BUTTON_ROLL_CCW, "NDOF_BUTTON_ROLL_CCW", 0, "Roll CCW", ""}, + {NDOF_BUTTON_SPIN_CW, "NDOF_BUTTON_SPIN_CW", 0, "Spin CW", ""}, + {NDOF_BUTTON_SPIN_CCW, "NDOF_BUTTON_SPIN_CCW", 0, "Spin CCW", ""}, + {NDOF_BUTTON_TILT_CW, "NDOF_BUTTON_TILT_CW", 0, "Tilt CW", ""}, + {NDOF_BUTTON_TILT_CCW, "NDOF_BUTTON_TILT_CCW", 0, "Tilt CCW", ""}, + /* device control */ + {NDOF_BUTTON_ROTATE, "NDOF_BUTTON_ROTATE", 0, "Rotate", ""}, + {NDOF_BUTTON_PANZOOM, "NDOF_BUTTON_PANZOOM", 0, "Pan/Zoom", ""}, + {NDOF_BUTTON_DOMINANT, "NDOF_BUTTON_DOMINANT", 0, "Dominant", ""}, + {NDOF_BUTTON_PLUS, "NDOF_BUTTON_PLUS", 0, "Plus", ""}, + {NDOF_BUTTON_MINUS, "NDOF_BUTTON_MINUS", 0, "Minus", ""}, + /* general-purpose buttons */ + {NDOF_BUTTON_1, "NDOF_BUTTON_1", 0, "Button 1", ""}, + {NDOF_BUTTON_2, "NDOF_BUTTON_2", 0, "Button 2", ""}, + {NDOF_BUTTON_3, "NDOF_BUTTON_3", 0, "Button 3", ""}, + {NDOF_BUTTON_4, "NDOF_BUTTON_4", 0, "Button 4", ""}, + {NDOF_BUTTON_5, "NDOF_BUTTON_5", 0, "Button 5", ""}, + {NDOF_BUTTON_6, "NDOF_BUTTON_6", 0, "Button 6", ""}, + {NDOF_BUTTON_7, "NDOF_BUTTON_7", 0, "Button 7", ""}, + {NDOF_BUTTON_8, "NDOF_BUTTON_8", 0, "Button 8", ""}, + {NDOF_BUTTON_9, "NDOF_BUTTON_9", 0, "Button 9", ""}, + {NDOF_BUTTON_10, "NDOF_BUTTON_10", 0, "Button 10", ""}, {0, NULL, 0, NULL, NULL}}; EnumPropertyItem keymap_propvalue_items[] = { @@ -303,6 +381,7 @@ EnumPropertyItem wm_report_items[] = { #define KMI_TYPE_TWEAK 2 #define KMI_TYPE_TEXTINPUT 3 #define KMI_TYPE_TIMER 4 +#define KMI_TYPE_NDOF 5 #ifdef RNA_RUNTIME @@ -433,6 +512,7 @@ static int rna_wmKeyMapItem_map_type_get(PointerRNA *ptr) if(ISKEYBOARD(kmi->type)) return KMI_TYPE_KEYBOARD; if(ISTWEAK(kmi->type)) return KMI_TYPE_TWEAK; if(ISMOUSE(kmi->type)) return KMI_TYPE_MOUSE; + if(ISNDOF(kmi->type)) return KMI_TYPE_NDOF; if(kmi->type == KM_TEXTINPUT) return KMI_TYPE_TEXTINPUT; return KMI_TYPE_KEYBOARD; } @@ -464,6 +544,10 @@ static void rna_wmKeyMapItem_map_type_set(PointerRNA *ptr, int value) kmi->type= TIMER; kmi->val= KM_NOTHING; break; + case KMI_TYPE_NDOF: + kmi->type = NDOF_BUTTON_MENU; + kmi->val = KM_NOTHING; + break; } } } @@ -475,6 +559,7 @@ static EnumPropertyItem *rna_KeyMapItem_type_itemf(bContext *UNUSED(C), PointerR if(map_type == KMI_TYPE_MOUSE) return event_mouse_type_items; if(map_type == KMI_TYPE_TWEAK) return event_tweak_type_items; if(map_type == KMI_TYPE_TIMER) return event_timer_type_items; + if(map_type == KMI_TYPE_NDOF) return event_ndof_type_items; else return event_type_items; } @@ -482,7 +567,7 @@ static EnumPropertyItem *rna_KeyMapItem_value_itemf(bContext *UNUSED(C), Pointer { int map_type= rna_wmKeyMapItem_map_type_get(ptr); - if(map_type == KMI_TYPE_MOUSE || map_type == KMI_TYPE_KEYBOARD) return event_keymouse_value_items; + if(map_type == KMI_TYPE_MOUSE || map_type == KMI_TYPE_KEYBOARD || map_type == KMI_TYPE_NDOF) return event_keymouse_value_items; if(map_type == KMI_TYPE_TWEAK) return event_tweak_value_items; else return event_value_items; } @@ -1653,6 +1738,7 @@ static void rna_def_keyconfig(BlenderRNA *brna) {KMI_TYPE_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""}, {KMI_TYPE_TWEAK, "TWEAK", 0, "Tweak", ""}, {KMI_TYPE_MOUSE, "MOUSE", 0, "Mouse", ""}, + {KMI_TYPE_NDOF, "NDOF", 0, "NDOF", ""}, {KMI_TYPE_TEXTINPUT, "TEXTINPUT", 0, "Text Input", ""}, {KMI_TYPE_TIMER, "TIMER", 0, "Timer", ""}, {0, NULL, 0, NULL, NULL}}; -- cgit v1.2.3 From 407a2a8439f61922139a3c5d1607818234924fe1 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 21 Jul 2011 21:40:04 +0000 Subject: tweaked ephemeral ndof data types --- source/blender/editors/space_view3d/view3d_fly.c | 18 +++++++++++++----- source/blender/makesdna/DNA_userdef_types.h | 5 ++--- source/blender/makesdna/DNA_view3d_types.h | 7 +++---- source/blender/makesrna/intern/rna_userdef.c | 16 +++------------- 4 files changed, 21 insertions(+), 25 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 6955aefcb9e..1122438da96 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -929,8 +929,15 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) wmNDOFMotionData* ndof = fly->ndof; const float dt = ndof->dt; RegionView3D* rv3d = fly->rv3d; + const int flag = U.ndof_flag; - const int shouldRotate = 1, shouldTranslate = 1; + const int shouldRotate = TRUE, + shouldTranslate = TRUE; + + // const int shouldRotate = flag & NDOF_SHOULD_ROTATE, + // shouldTranslate = flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM); + // might also be something in FlyInfo that restricts motion + // if so, change these ^^ float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); @@ -955,7 +962,7 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // transform motion from view to world coordinates mul_qt_v3(view_inv, trans); - if (U.ndof_flag & NDOF_FLY_HELICOPTER) + if (flag & NDOF_FLY_HELICOPTER) // could also use RNA to get a simple boolean value { // replace world z component with device y (yes it makes sense) @@ -981,9 +988,9 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // apply rotation to view axis_angle_to_quat(rotation, axis, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); - if (U.ndof_flag & NDOF_LOCK_HORIZON) + if (flag & NDOF_LOCK_HORIZON) // force an upright viewpoint // TODO: make this less... sudden { @@ -992,6 +999,7 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // find new inverse since viewquat has changed invert_qt_qt(view_inv, rv3d->viewquat); + // could apply reverse rotation to existing view_inv to save a few cycles // transform view vectors to world coordinates mul_qt_v3(view_inv, view_horizon); @@ -1007,7 +1015,7 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // rotate view so view horizon = world horizon axis_angle_to_quat(rotation, view_direction, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); } rv3d->view = RV3D_VIEW_USER; diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index a94c10a7aa0..6fbdb9842d6 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -365,7 +365,6 @@ typedef struct UserDef { short recent_files; /* maximum number of recently used files to remember */ short smooth_viewtx; /* miliseconds to spend spinning the view */ short glreslimit; -/* short ndof_pan, ndof_rotate; */ short curssize; short color_picker_type; short ipo_new; /* interpolation mode for newly added F-Curves */ @@ -586,11 +585,11 @@ extern UserDef U; /* from blenkernel blender.c */ #define NDOF_FLY_HELICOPTER (1 << 1) #define NDOF_LOCK_HORIZON (1 << 2) /* the following might not need to be saved between sessions, - but they do need to live somewhere accessible... + but they do need to live somewhere accessible... */ #define NDOF_SHOULD_PAN (1 << 3) #define NDOF_SHOULD_ZOOM (1 << 4) #define NDOF_SHOULD_ROTATE (1 << 5) -*/ + #ifdef __cplusplus } diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 7379493003d..27ffc6d856b 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -190,11 +190,10 @@ typedef struct View3D { /* drawflags, denoting state */ short zbuf, transp, xray; - char ndofmode; /* mode of transform for 6DOF devices -1 not found, 0 normal, 1 fly, 2 ob transform */ - char ndoffilter; /* filter for 6DOF devices 0 normal, 1 dominant */ - + char pad3[2]; + void *properties_storage; /* Nkey panel stores stuff here (runtime only!) */ - + /* XXX depricated? */ struct bGPdata *gpd; /* Grease-Pencil Data (annotation layers) */ diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 664cb7732f9..50b5e99804c 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2739,24 +2739,14 @@ static void rna_def_userdef_input(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Drag Threshold", "Amount of pixels you have to drag before dragging UI items happens"); /* 3D mouse settings */ -/* - prop= RNA_def_property(srna, "ndof_pan_speed", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "ndof_pan"); - RNA_def_property_range(prop, 0, 200); - RNA_def_property_ui_text(prop, "NDof Pan Speed", "The overall panning speed of an NDOF device, as percent of standard"); - - prop= RNA_def_property(srna, "ndof_rotate_speed", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "ndof_rotate"); - RNA_def_property_range(prop, 0, 200); - RNA_def_property_ui_text(prop, "NDof Rotation Speed", "The overall rotation speed of an NDOF device, as percent of standard"); -*/ prop= RNA_def_property(srna, "ndof_sensitivity", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.25f, 4.0f); - RNA_def_property_ui_text(prop, "3D Mouse Sensitivity", "Baseline sensitivity of the 3D Mouse"); + RNA_def_property_ui_text(prop, "Sensitivity", "Overall sensitivity of the 3D Mouse"); prop= RNA_def_property(srna, "ndof_show_guide", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_SHOW_GUIDE); - RNA_def_property_ui_text(prop, "Show 3D Mouse Guide", "Visualize the center and axis of rotation (or projected position in fly mode)"); + RNA_def_property_ui_text(prop, "Show Navigation Guide", "Display the center and axis during rotation"); + /* TODO: update description when fly-mode visuals are in place ("projected position in fly mode")*/ prop= RNA_def_property(srna, "ndof_lock_horizon", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_LOCK_HORIZON); -- cgit v1.2.3 From b9f3ff5435d78b4538b417849edf60238fa54e34 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 23 Jul 2011 21:55:52 +0000 Subject: removed ancient ndof global, removed my own attempt at a C popup menu (the Python one works) --- source/blender/blenkernel/BKE_global.h | 5 -- source/blender/windowmanager/intern/wm_init_exit.c | 2 - source/blender/windowmanager/intern/wm_operators.c | 98 +--------------------- 3 files changed, 3 insertions(+), 102 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index d21b0428d76..17876c6ec9d 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -92,9 +92,6 @@ typedef struct Global { /* save the allowed windowstate of blender when using -W or -w */ int windowstate; - - /* ndof device found ? */ - int ndofdevice; } Global; /* **************** GLOBAL ********************* */ @@ -174,5 +171,3 @@ extern Global G; #endif #endif - - diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index ed28696ef69..7dd865984b3 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -182,8 +182,6 @@ void WM_init(bContext *C, int argc, const char **argv) ED_preview_init_dbase(); - G.ndofdevice = -1; /* XXX bad initializer, needs set otherwise buttons show! */ - WM_read_history(); /* allow a path of "", this is what happens when making a new file */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 32d2adffb01..44e42966c77 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1411,113 +1411,22 @@ static void WM_OT_search_menu(wmOperatorType *ot) ot->poll= wm_search_menu_poll; } -// BEGIN ndof menu -- experimental! - -#if 0 -static uiBlock* wm_block_ndof_menu_1st(bContext* C, ARegion* ar, void* UNUSED(arg_op)) -{ - uiBlock* block; - uiBut* but; - - block = uiBeginBlock(C, ar, "ndof_popup_menu", UI_EMBOSS); - uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT); -// uiBlockSetDirection(block, UI_DOWN); -// uiBlockBeginAlign(block); - - // uiItemBooleanO(block->curlayout, "enable pan/zoom", ICON_NDOF_TRANS, "toggle_ndof_pan_zoom_enabled", "ndof_pan_zoom_enabled", 1); - // uiBlock is used as an opaque type in this file, so can't use members... - - int foo = 333; - uiDefButI(block, TOG, 0, "foo", 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, &foo, 0.f, 1.f, 0.1f, 0.9f, "15%"); - // uiDefBut(block, TOG, 0, "enable pan/zoom", 0, 0, 10, 10, NULL, 0.f, 1.f, 0.f, 1.f, "don't talk to strangers"); - -// uiBlockEndAlign(block); -// uiBoundsBlock(block, 6); - uiEndBlock(C, block); - - return block; -} - -static int wm_ndof_menu_poll(bContext *C) -{ - if(CTX_wm_window(C)==NULL) - return 0; - - // if menu is already pulled up, another button press should dismiss it - // not sure if that behavior should go here or elsewhere... - - puts("ndof: menu poll"); - return 1; -} - -static int wm_ndof_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) -{ - puts("ndof: menu exec"); - return OPERATOR_FINISHED; -} -#endif - static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { uiPupMenuInvoke(C,"VIEW3D_MT_ndof_settings"); + return OPERATOR_FINISHED; // <-- correct? return OPERATOR_CANCELLED; // <-- correct? - -/* -// uiPupMenuNotice(C, "Hello!"); // <-- this works -// uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck! -// ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works - - uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN); - uiLayout* layout = uiPupMenuLayout(pup); - - uiItemS(layout); // separator - uiItemFloatO(layout, "sensitivity", 0, 0, "ndof_sensitivity", 1.f); - // do I have to look specifically in "UserPreferences" for ndof_sensitivity property? - - // trial & error -- ok, mostly error -// uiItemBooleanO(layout, "enable pan/zoom", ICON_NDOF_TRANS, "ndof_toggle_pan_zoom_enabled", "ndof_pan_zoom_enabled", 1); -// uiItemBooleanO(layout, "enable rotation", ICON_NDOF_TURN, "ndof_toggle_rotation_enabled", "ndof_rotation_enabled", 1); -// uiItemV(layout,"sensitivity",ICON_NDOF_TRANS, 1); - - printf("ndof: menu invoked in "); - - switch (CTX_wm_area(C)->spacetype) // diff spaces can have diff 3d mouse options - { - case SPACE_VIEW3D: - puts("3D area"); - uiItemS(layout); - uiItemL(layout, "3D navigation mode", 0); - uiItemBooleanO(layout, "helicopter", ICON_NDOF_FLY, 0, "ndof_fly_helicopter", 1); - uiItemBooleanO(layout, "lock horizon", ICON_NDOF_DOM, 0, "ndof_lock_horizon", 1); - break; - case SPACE_IMAGE: - puts("image area"); - break; - default: - puts("some iNDOFferent area"); - } - - //uiBlock* block = uiLayoutGetBlock(layout); - //int foo = 1; - //uiDefButI(block, TOG, 0, "foo", 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, &foo, 0.f, 1.f, 0.1f, 0.9f, "15%"); - - uiPupMenuEnd(C,pup); -*/ } static void WM_OT_ndof_menu(wmOperatorType *ot) { - puts("ndof: registering menu operator"); - ot->name = "NDOF Menu"; ot->idname = "WM_OT_ndof_menu"; ot->invoke = wm_ndof_menu_invoke; } -// END ndof menu - static int wm_call_menu_exec(bContext *C, wmOperator *op) { char idname[BKE_ST_MAXNAME]; @@ -3782,13 +3691,12 @@ void wm_window_keymap(wmKeyConfig *keyconf) /* debug/testing */ WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0); WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0); - WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); + /* menus that can be accessed anywhere in blender */ + WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "WM_OT_ndof_menu", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); /* Space switching */ - - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */ RNA_string_set(kmi->ptr, "data_path", "area.type"); RNA_string_set(kmi->ptr, "value", "LOGIC_EDITOR"); -- cgit v1.2.3 From ed232c756d25f5fe16370c7eba332f2d78cd128e Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 24 Jul 2011 00:40:39 +0000 Subject: ndof overall sensitivity is now live --- source/blender/windowmanager/intern/wm_event_system.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 26d72906ece..ad8df1ef0bb 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2314,13 +2314,15 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g { wmNDOFMotionData* data = MEM_mallocN(sizeof(wmNDOFMotionData), "customdata NDOF"); - data->tx = ghost->tx; - data->ty = ghost->ty; - data->tz = ghost->tz; + const float s = U.ndof_sensitivity; - data->rx = ghost->rx; - data->ry = ghost->ry; - data->rz = ghost->rz; + data->tx = s * ghost->tx; + data->ty = s * ghost->ty; + data->tz = s * ghost->tz; + + data->rx = s * ghost->rx; + data->ry = s * ghost->ry; + data->rz = s * ghost->rz; data->dt = ghost->dt; -- cgit v1.2.3 From 1ca4f1ba1c48b9afa46c85ce9010829a26194632 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 24 Jul 2011 08:02:42 +0000 Subject: sculpt/paint while using 3D mouse --- source/blender/editors/gpencil/gpencil_paint.c | 12 ++++++++++++ source/blender/editors/sculpt_paint/paint_stroke.c | 3 +++ 2 files changed, 15 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index f4da734473d..28a54b20277 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1617,6 +1617,18 @@ static int gpencil_draw_modal (bContext *C, wmOperator *op, wmEvent *event) tGPsdata *p= op->customdata; int estate = OPERATOR_PASS_THROUGH; /* default exit state - not handled, so let others have a share of the pie */ + // if (event->type == NDOF_MOTION) + // return OPERATOR_PASS_THROUGH; + // ------------------------------- + // [mce] Not quite what I was looking + // for, but a good start! GP continues to + // draw on the screen while the 3D mouse + // moves the viewpoint. Problem is that + // the stroke is converted to 3D only after + // it is finished. This approach should work + // better in tools that immediately apply + // in 3D space. + //printf("\tGP - handle modal event...\n"); /* exit painting mode (and/or end current stroke) */ diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 7ddf5dff000..bddb30a4262 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -832,6 +832,9 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) float mouse[2]; int first= 0; + if (event->type == NDOF_MOTION) + return OPERATOR_PASS_THROUGH; + if(!stroke->stroke_started) { stroke->last_mouse_position[0] = event->x; stroke->last_mouse_position[1] = event->y; -- cgit v1.2.3 From c4bda1370c9528e2035c1d91df126dd4ea789d69 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Sun, 24 Jul 2011 08:37:43 +0000 Subject: Add mapping for front/right/top aligned to selected object. --- source/blender/editors/space_view3d/view3d_ops.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 2dd560a6408..963e7aeeb95 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -221,6 +221,17 @@ void view3d_keymap(wmKeyConfig *keyconf) RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BOTTOM); RNA_boolean_set(kmi->ptr, "align_active", TRUE); + /* 3D mouse align */ + kmi= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, KM_SHIFT, 0); + RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_FRONT); + RNA_boolean_set(kmi->ptr, "align_active", TRUE); + kmi= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, KM_SHIFT, 0); + RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_RIGHT); + RNA_boolean_set(kmi->ptr, "align_active", TRUE); + kmi= WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, KM_SHIFT, 0); + RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_TOP); + RNA_boolean_set(kmi->ptr, "align_active", TRUE); + WM_keymap_add_item(keymap, "VIEW3D_OT_localview", PADSLASHKEY, KM_PRESS, 0, 0); /* layers, shift + alt are properties set in invoke() */ -- cgit v1.2.3 From 6149526aac7a10034ce369147c8c7962f8ed4e35 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Sun, 24 Jul 2011 08:50:09 +0000 Subject: Default for ndof_sensitivity to 1.0 in case 0.0 is found on start. --- source/blender/editors/interface/resources.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 3f825762d74..276e1b3dc61 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1583,6 +1583,9 @@ void init_userdef_do_versions(void) if (U.anisotropic_filter <= 0) U.anisotropic_filter = 1; + if (U.ndof_sensitivity == 0.0) + U.ndof_sensitivity = 1.0f; + /* funny name, but it is GE stuff, moves userdef stuff to engine */ // XXX space_set_commmandline_options(); /* this timer uses U */ -- cgit v1.2.3 From abf658d36785e3fb0fe458ba7ee9b22987a9c036 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 25 Jul 2011 00:00:53 +0000 Subject: removed old ndof transform stuff, added experimental ndof nav during transform (might disable for release) --- source/blender/editors/transform/transform.c | 127 +---------------------- source/blender/editors/transform/transform_ops.c | 6 ++ 2 files changed, 11 insertions(+), 122 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index d3a30991aa6..81aade5ca64 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1006,9 +1006,11 @@ int transformEvent(TransInfo *t, wmEvent *event) else view_editmove(event->type); t->redraw= 1; break; -// case NDOFMOTION: -// viewmoveNDOF(1); - // break; +#if 0 + case NDOF_MOTION: + // should have been caught by tranform_modal + return OPERATOR_PASS_THROUGH; +#endif default: handled = 0; break; @@ -1017,43 +1019,6 @@ int transformEvent(TransInfo *t, wmEvent *event) // Numerical input events t->redraw |= handleNumInput(&(t->num), event); - // NDof input events - switch(handleNDofInput(&(t->ndof), event)) - { - case NDOF_CONFIRM: - if ((t->options & CTX_NDOF) == 0) - { - /* Confirm on normal transform only */ - t->state = TRANS_CONFIRM; - } - break; - case NDOF_CANCEL: - if (t->options & CTX_NDOF) - { - /* Cancel on pure NDOF transform */ - t->state = TRANS_CANCEL; - } - else - { - /* Otherwise, just redraw, NDof input was cancelled */ - t->redraw |= TREDRAW_HARD; - } - break; - case NDOF_NOMOVE: - if (t->options & CTX_NDOF) - { - /* Confirm on pure NDOF transform */ - t->state = TRANS_CONFIRM; - } - break; - case NDOF_REFRESH: - t->redraw |= TREDRAW_HARD; - break; - default: - handled = 0; - break; - } - // Snapping events t->redraw |= handleSnapping(t, event); @@ -2886,10 +2851,6 @@ void initRotation(TransInfo *t) setInputPostFct(&t->mouse, postInputRotation); initMouseInputMode(t, &t->mouse, INPUT_ANGLE); - t->ndof.axis = 16; - /* Scale down and flip input for rotation */ - t->ndof.factor[0] = -0.2f; - t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -3161,8 +3122,6 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; - applyNDofInput(&t->ndof, &final); - snapGrid(t, &final); if ((t->con.mode & CON_APPLY) && t->con.applyRot) { @@ -3216,11 +3175,6 @@ void initTrackball(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL); - t->ndof.axis = 40; - /* Scale down input for rotation */ - t->ndof.factor[0] = 0.2f; - t->ndof.factor[1] = 0.2f; - t->idx_max = 1; t->num.idx_max = 1; t->snap[0] = 0.0f; @@ -3276,8 +3230,6 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2])) phi[0] = t->values[0]; phi[1] = t->values[1]; - applyNDofInput(&t->ndof, phi); - snapGrid(t, phi); if (hasNumInput(&t->num)) { @@ -3331,8 +3283,6 @@ void initTranslation(TransInfo *t) t->num.flag = 0; t->num.idx_max = t->idx_max; - t->ndof.axis = (t->flag & T_2D_EDIT)? 1|2: 1|2|4; - if(t->spacetype == SPACE_VIEW3D) { RegionView3D *rv3d = t->ar->regiondata; @@ -3507,7 +3457,6 @@ int Translation(TransInfo *t, const int UNUSED(mval[2])) headerTranslation(t, pvec, str); } else { - applyNDofInput(&t->ndof, t->values); snapGrid(t, t->values); applyNumInput(&t->num, t->values); if (hasNumInput(&t->num)) { @@ -3616,10 +3565,6 @@ void initTilt(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_ANGLE); - t->ndof.axis = 16; - /* Scale down and flip input for rotation */ - t->ndof.factor[0] = -0.2f; - t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -3643,8 +3588,6 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; - applyNDofInput(&t->ndof, &final); - snapGrid(t, &final); if (hasNumInput(&t->num)) { @@ -3759,10 +3702,6 @@ void initPushPull(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE); - t->ndof.axis = 4; - /* Flip direction */ - t->ndof.factor[0] = -1.0f; - t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -3783,8 +3722,6 @@ int PushPull(TransInfo *t, const int UNUSED(mval[2])) distance = t->values[0]; - applyNDofInput(&t->ndof, &distance); - snapGrid(t, &distance); applyNumInput(&t->num, &distance); @@ -5309,8 +5246,6 @@ void initSeqSlide(TransInfo *t) t->num.flag = 0; t->num.idx_max = t->idx_max; - t->ndof.axis = 1|2; - t->snap[0] = 0.0f; t->snap[1] = floor(t->scene->r.frs_sec / t->scene->r.frs_sec_base); t->snap[2] = 10.0f; @@ -5365,7 +5300,6 @@ int SeqSlide(TransInfo *t, const int UNUSED(mval[2])) VECCOPY(t->values, tvec); } else { - applyNDofInput(&t->ndof, t->values); snapGrid(t, t->values); applyNumInput(&t->num, t->values); } @@ -5925,54 +5859,3 @@ void BIF_TransformSetUndo(char *UNUSED(str)) // TRANSFORM_FIX_ME //Trans.undostr= str; } - - -#if 0 // TRANSFORM_FIX_ME -static void NDofTransform(void) -{ - float fval[7]; - float maxval = 50.0f; // also serves as threshold - int axis = -1; - int mode = 0; - int i; - - getndof(fval); - - for(i = 0; i < 6; i++) - { - float val = fabs(fval[i]); - if (val > maxval) - { - axis = i; - maxval = val; - } - } - - switch(axis) - { - case -1: - /* No proper axis found */ - break; - case 0: - case 1: - case 2: - mode = TFM_TRANSLATION; - break; - case 4: - mode = TFM_ROTATION; - break; - case 3: - case 5: - mode = TFM_TRACKBALL; - break; - default: - printf("ndof: what we are doing here ?"); - } - - if (mode != 0) - { - initTransform(mode, CTX_NDOF); - Transform(); - } -} -#endif diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 7bdf6c909d9..0b0b22fb689 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -360,6 +360,12 @@ static int transform_modal(bContext *C, wmOperator *op, wmEvent *event) TransInfo *t = op->customdata; + if (event->type == NDOF_MOTION) + { + // puts("transform_modal: passing through NDOF_MOTION"); + return OPERATOR_PASS_THROUGH; + } + /* XXX insert keys are called here, and require context */ t->context= C; exit_code = transformEvent(t, event); -- cgit v1.2.3 From 73417bfbb564a2e5b1b203e436994ea8b7f3c535 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 25 Jul 2011 00:03:07 +0000 Subject: spoof MOUSEMOVE after NDOF_MOTION event, added comments --- source/blender/editors/sculpt_paint/paint_stroke.c | 4 ++++ source/blender/windowmanager/intern/wm_event_system.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index bddb30a4262..09873566d4a 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -832,6 +832,10 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) float mouse[2]; int first= 0; + // let NDOF motion pass through to the 3D view so we can paint and rotate simultaneously! + // this isn't perfect... even when an extra MOUSEMOVE is spoofed, the stroke discards it + // since the 2D deltas are zero -- code in this file needs to be updated to use the + // post-NDOF_MOTION MOUSEMOVE if (event->type == NDOF_MOTION) return OPERATOR_PASS_THROUGH; diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index ad8df1ef0bb..322cd3b5642 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1815,7 +1815,10 @@ void wm_event_do_handlers(bContext *C) /* for regions having custom cursors */ wm_paintcursor_test(C, event); } - + else if (event->type==NDOF_MOTION) { + win->addmousemove = TRUE; + } + for(sa= win->screen->areabase.first; sa; sa= sa->next) { if(wm_event_inside_i(event, &sa->totrct)) { CTX_wm_area_set(C, sa); @@ -1879,7 +1882,10 @@ void wm_event_do_handlers(bContext *C) if(doit && win->screen && win->screen->subwinactive != win->screen->mainwin) { win->eventstate->prevx= event->x; win->eventstate->prevy= event->y; + //printf("win->eventstate->prev = %d %d\n", event->x, event->y); } + else + ;//printf("not setting prev to %d %d\n", event->x, event->y); } /* store last event for this window */ @@ -1922,6 +1928,7 @@ void wm_event_do_handlers(bContext *C) /* only add mousemove when queue was read entirely */ if(win->addmousemove && win->eventstate) { wmEvent tevent= *(win->eventstate); + //printf("adding MOUSEMOVE %d %d\n", tevent.x, tevent.y); tevent.type= MOUSEMOVE; tevent.prevx= tevent.x; tevent.prevy= tevent.y; @@ -2408,6 +2415,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U update_tablet_data(win, &event); wm_event_add(win, &event); + + //printf("sending MOUSEMOVE %d %d\n", event.x, event.y); /* also add to other window if event is there, this makes overdraws disappear nicely */ /* it remaps mousecoord to other window in event */ @@ -2586,6 +2595,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U attach_ndof_data(&event, customdata); wm_event_add(win, &event); + //printf("sending NDOF_MOTION, prev = %d %d\n", event.x, event.y); + break; } -- cgit v1.2.3 From e31fef1d94c38f4701f12d7f264fe145446f08b6 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 25 Jul 2011 00:10:42 +0000 Subject: set default values for all other ndof flags --- source/blender/editors/interface/resources.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 276e1b3dc61..5f405a5f51e 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1583,8 +1583,11 @@ void init_userdef_do_versions(void) if (U.anisotropic_filter <= 0) U.anisotropic_filter = 1; - if (U.ndof_sensitivity == 0.0) + if (U.ndof_sensitivity == 0.0f) { U.ndof_sensitivity = 1.0f; + U.ndof_flag = NDOF_SHOW_GUIDE | NDOF_LOCK_HORIZON | + NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE; + } /* funny name, but it is GE stuff, moves userdef stuff to engine */ // XXX space_set_commmandline_options(); -- cgit v1.2.3 From c692351fdfe96ec396af9f9c1dfc92ae4e8ee5c6 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 25 Jul 2011 00:20:45 +0000 Subject: added option to invert axes for orbiting (part 1 of 2) --- source/blender/editors/space_view3d/view3d_edit.c | 14 ++++++++++++-- source/blender/makesdna/DNA_userdef_types.h | 11 +++++++++++ source/blender/makesrna/intern/rna_userdef.c | 6 +++++- 3 files changed, 28 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 0c07df9fd01..aabacadf3db 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1019,6 +1019,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) if (has_rotation) { + const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; + rv3d->view = RV3D_VIEW_USER; if (U.flag & USER_TRACKBALL) { @@ -1027,8 +1029,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) float view_inv[4], view_inv_conj[4]; ndof_to_quat(ndof, rot); - // scale by rot_sensitivity? - // mul_qt_fl(rot, rot_sensitivity); + // mul_qt_fl(rot, rot_sensitivity * (invert ? -1.f : 1.f)); + // ^^ no apparent effect invert_qt_qt(view_inv, rv3d->viewquat); copy_qt_qt(view_inv_conj, view_inv); @@ -1038,6 +1040,10 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) mul_qt_qtqt(rot, view_inv, rot); mul_qt_qtqt(rot, rot, view_inv_conj); + // if (invert) + // invert_qt(rot); + // ^^ argh!! this does something crazy + // apply rotation mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); @@ -1053,12 +1059,16 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) /* Perform the up/down rotation */ angle = rot_sensitivity * dt * ndof->rx; + if (invert) + angle = -angle; rot[0] = cos(angle); mul_v3_v3fl(rot+1, xvec, sin(angle)); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); /* Perform the orbital rotation */ angle = rot_sensitivity * dt * ndof->ry; + if (invert) + angle = -angle; rot[0] = cos(angle); rot[1] = rot[2] = 0.0; rot[3] = sin(angle); diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 6fbdb9842d6..12f8cd656a0 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -589,6 +589,17 @@ extern UserDef U; /* from blenkernel blender.c */ #define NDOF_SHOULD_PAN (1 << 3) #define NDOF_SHOULD_ZOOM (1 << 4) #define NDOF_SHOULD_ROTATE (1 << 5) +/* orbit navigation modes + only two options, so it's sort of a hyrbrid bool/enum + if ((U.ndof_flag & NDOF_ORBIT_MODE) == NDOF_OM_OBJECT)... */ +/* +#define NDOF_ORBIT_MODE (1 << 6) +#define NDOF_OM_TARGETCAMERA 0 +#define NDOF_OM_OBJECT NDOF_ORBIT_MODE +*/ +/* actually... users probably don't care about what the mode + is called, just that it feels right */ +#define NDOF_ORBIT_INVERT_AXES (1 << 6) #ifdef __cplusplus diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 50b5e99804c..7a9193571fd 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2748,13 +2748,17 @@ static void rna_def_userdef_input(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Show Navigation Guide", "Display the center and axis during rotation"); /* TODO: update description when fly-mode visuals are in place ("projected position in fly mode")*/ + prop= RNA_def_property(srna, "ndof_orbit_invert_axes", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_ORBIT_INVERT_AXES); + RNA_def_property_ui_text(prop, "Invert Axes", "Toggle between moving the viewpoint or moving the scene being viewed"); + prop= RNA_def_property(srna, "ndof_lock_horizon", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_LOCK_HORIZON); RNA_def_property_ui_text(prop, "Lock Horizon", "Keep horizon level while flying with 3D Mouse"); prop= RNA_def_property(srna, "ndof_fly_helicopter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_FLY_HELICOPTER); - RNA_def_property_ui_text(prop, "Helicopter Fly Mode", ""); + RNA_def_property_ui_text(prop, "Helicopter Mode", "Device up/down directly controls your Z position"); prop= RNA_def_property(srna, "mouse_double_click_time", PROP_INT, PROP_NONE); -- cgit v1.2.3 From 4b8233423bea092d5af4affe14290095dbd701ef Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Mon, 25 Jul 2011 03:13:15 +0000 Subject: invert axes option affects trackball navigation --- source/blender/editors/space_view3d/view3d_edit.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index aabacadf3db..0aceb3bc1ca 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1029,9 +1029,12 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) float view_inv[4], view_inv_conj[4]; ndof_to_quat(ndof, rot); - // mul_qt_fl(rot, rot_sensitivity * (invert ? -1.f : 1.f)); + // mul_qt_fl(rot, rot_sensitivity); // ^^ no apparent effect + if (invert) + invert_qt(rot); + invert_qt_qt(view_inv, rv3d->viewquat); copy_qt_qt(view_inv_conj, view_inv); conjugate_qt(view_inv_conj); @@ -1040,10 +1043,6 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) mul_qt_qtqt(rot, view_inv, rot); mul_qt_qtqt(rot, rot, view_inv_conj); - // if (invert) - // invert_qt(rot); - // ^^ argh!! this does something crazy - // apply rotation mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); -- cgit v1.2.3 From 72f70874bb3477a0861735d612e0c15c931ff7e5 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 26 Jul 2011 02:35:46 +0000 Subject: experimental onscreen rotation guide --- source/blender/editors/space_view3d/view3d_draw.c | 59 +++++++ source/blender/editors/space_view3d/view3d_edit.c | 206 ++++++++++++---------- source/blender/editors/space_view3d/view3d_fly.c | 2 + source/blender/makesdna/DNA_view3d_types.h | 6 +- 4 files changed, 181 insertions(+), 92 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index d2ff6eef097..f1909bb4049 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -675,6 +675,60 @@ static void draw_view_axis(RegionView3D *rv3d) glDisable(GL_BLEND); } +/* draw center and axis of rotation for ongoing 3D mouse navigation */ +static void draw_rotation_guide(RegionView3D *rv3d) +{ + float o[3]; // center of rotation + float end[3]; // endpoints for drawing + + float color[4] = {1,1,0,1}; // bright yellow so it stands out during development + + negate_v3_v3(o, rv3d->ofs); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glShadeModel(GL_SMOOTH); + glPointSize(5); + glEnable(GL_POINT_SMOOTH); + + if (rv3d->rot_angle != 0.f) { + float scaled_axis[3]; + mul_v3_v3fl(scaled_axis, rv3d->rot_axis, 3.f); + + glBegin(GL_LINE_STRIP); + color[3] = 0; // more transparent toward the ends + glColor4fv(color); + add_v3_v3v3(end, o, scaled_axis); + glVertex3fv(end); + + color[3] = 0.2f + rv3d->rot_angle; // more opaque toward the center + glColor4fv(color); + glVertex3fv(o); + + color[3] = 0; + glColor4fv(color); + sub_v3_v3v3(end, o, scaled_axis); + glVertex3fv(end); + glEnd(); + + color[3] = 1; // solid dot + } + else + color[3] = 0.5; // see-through dot + + glColor4fv(color); + glBegin(GL_POINTS); + glVertex3fv(o); + glEnd(); + + // find screen coordinates for rotation center, then draw pretty icon + // mul_m4_v3(rv3d->persinv, rot_center); + // UI_icon_draw(rot_center[0], rot_center[1], ICON_NDOF_TURN); + // ^^ just playing around, does not work + + glDisable(GL_BLEND); + glDisable(GL_POINT_SMOOTH); +} static void draw_view_icon(RegionView3D *rv3d) { @@ -2618,6 +2672,11 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) BDR_drawSketch(C); } +#if 0 // not yet... + if (U.ndof_flag & NDOF_SHOW_GUIDE) + draw_rotation_guide(rv3d); +#endif + ED_region_pixelspace(ar); // retopo_paint_view_update(v3d); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 0aceb3bc1ca..75e20ad565e 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -977,101 +977,125 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) RegionView3D* rv3d = CTX_wm_region_view3d(C); wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - const float dt = ndof->dt; + rv3d->rot_angle = 0.f; // off by default, until changed later this function - // tune these until everything feels right - const float rot_sensitivity = 1.f; - const float zoom_sensitivity = 1.f; - const float pan_sensitivity = 1.f; - - // rather have bool, but... - int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); - - //#define DEBUG_NDOF_MOTION - #ifdef DEBUG_NDOF_MOTION - printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n", - ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt); - #endif - - if (ndof->tz) { - // Zoom! - // velocity should be proportional to the linear velocity attained by rotational motion of same strength - // [got that?] - // proportional to arclength = radius * angle - - float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; - rv3d->dist += zoom_distance; - } - - if (rv3d->viewlock == RV3D_LOCKED) { - /* rotation not allowed -- explore panning options instead */ + if (ndof->progress != P_FINISHING) { + const float dt = ndof->dt; + + // tune these until everything feels right + const float rot_sensitivity = 1.f; + const float zoom_sensitivity = 1.f; + const float pan_sensitivity = 1.f; + + // rather have bool, but... + int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); + float view_inv[4]; - float pan_vec[3] = {ndof->tx, ndof->ty, 0}; - mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); - - /* transform motion from view to world coordinates */ invert_qt_qt(view_inv, rv3d->viewquat); - mul_qt_v3(view_inv, pan_vec); - - /* move center of view opposite of hand motion (this is camera mode, not object mode) */ - sub_v3_v3(rv3d->ofs, pan_vec); - } - - if (has_rotation) { - - const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; - - rv3d->view = RV3D_VIEW_USER; - - if (U.flag & USER_TRACKBALL) { - - float rot[4]; - float view_inv[4], view_inv_conj[4]; - - ndof_to_quat(ndof, rot); - // mul_qt_fl(rot, rot_sensitivity); - // ^^ no apparent effect - - if (invert) - invert_qt(rot); - - invert_qt_qt(view_inv, rv3d->viewquat); - copy_qt_qt(view_inv_conj, view_inv); - conjugate_qt(view_inv_conj); - - // transform rotation from view to world coordinates - mul_qt_qtqt(rot, view_inv, rot); - mul_qt_qtqt(rot, rot, view_inv_conj); - - // apply rotation - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); - - } else { - /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ - float angle, rot[4]; - float xvec[3] = {1,0,0}; - - /* Determine the direction of the x vector (for rotating up and down) */ - float view_inv[4]; + + //#define DEBUG_NDOF_MOTION + #ifdef DEBUG_NDOF_MOTION + printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n", + ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt); + #endif + + if (ndof->tz) { + // Zoom! + // velocity should be proportional to the linear velocity attained by rotational motion of same strength + // [got that?] + // proportional to arclength = radius * angle + + float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; + rv3d->dist += zoom_distance; + } + + if (rv3d->viewlock == RV3D_LOCKED) { + /* rotation not allowed -- explore panning options instead */ + float pan_vec[3] = {ndof->tx, ndof->ty, 0}; + mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); + + /* transform motion from view to world coordinates */ invert_qt_qt(view_inv, rv3d->viewquat); - mul_qt_v3(view_inv, xvec); - - /* Perform the up/down rotation */ - angle = rot_sensitivity * dt * ndof->rx; - if (invert) - angle = -angle; - rot[0] = cos(angle); - mul_v3_v3fl(rot+1, xvec, sin(angle)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); - - /* Perform the orbital rotation */ - angle = rot_sensitivity * dt * ndof->ry; - if (invert) - angle = -angle; - rot[0] = cos(angle); - rot[1] = rot[2] = 0.0; - rot[3] = sin(angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + mul_qt_v3(view_inv, pan_vec); + + /* move center of view opposite of hand motion (this is camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, pan_vec); + } + + if (has_rotation) { + + const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; + + rv3d->view = RV3D_VIEW_USER; + + if (U.flag & USER_TRACKBALL) { + float rot[4]; + #if 0 // -------------------------- Mike's nifty original version + float view_inv_conj[4]; + + ndof_to_quat(ndof, rot); + // mul_qt_fl(rot, rot_sensitivity); + // ^^ no apparent effect + + if (invert) + invert_qt(rot); + + copy_qt_qt(view_inv_conj, view_inv); + conjugate_qt(view_inv_conj); + + // transform rotation from view to world coordinates + mul_qt_qtqt(rot, view_inv, rot); + mul_qt_qtqt(rot, rot, view_inv_conj); + #else // ---------------------------------------- Mike's revised version + float axis[3]; + float angle = rot_sensitivity * ndof_to_angle_axis(ndof, axis); + + if (invert) + angle = -angle; + + // update the onscreen doo-dad + rv3d->rot_angle = angle; + copy_v3_v3(rv3d->rot_axis, axis); + + // transform rotation axis from view to world coordinates + mul_qt_v3(view_inv, axis); + + axis_angle_to_quat(rot, axis, angle); + #endif // -------------------------------------------- + // apply rotation + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + } else { + /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ + float angle, rot[4]; + float xvec[3] = {1,0,0}; + + /* Determine the direction of the x vector (for rotating up and down) */ + mul_qt_v3(view_inv, xvec); + + /* Perform the up/down rotation */ + angle = rot_sensitivity * dt * ndof->rx; + if (invert) + angle = -angle; + rot[0] = cos(angle); + mul_v3_v3fl(rot+1, xvec, sin(angle)); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + + /* Perform the orbital rotation */ + angle = rot_sensitivity * dt * ndof->ry; + if (invert) + angle = -angle; + + // update the onscreen doo-dad + rv3d->rot_angle = angle; + rv3d->rot_axis[0] = 0; + rv3d->rot_axis[1] = 0; + rv3d->rot_axis[2] = 1; + + rot[0] = cos(angle); + rot[1] = rot[2] = 0.0; + rot[3] = sin(angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + } } } diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 1122438da96..c7ebc296896 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -942,6 +942,8 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); + rv3d->rot_angle = 0; // disable onscreen rotation doo-dad + if (shouldTranslate) { const float forward_sensitivity = 1.f; diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 27ffc6d856b..89b8bad2806 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -130,7 +130,11 @@ typedef struct RegionView3D { float twangle[3]; - float padf; + /* active rotation from NDOF or elsewhere */ + float rot_angle; + float rot_axis[3]; + + char pad2[4]; } RegionView3D; -- cgit v1.2.3 From 37aa6a5e3d5d5fdd8e9ec0779cdfa831a084b01f Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 26 Jul 2011 16:17:00 +0000 Subject: onscreen ndof rotation guide (center + axis) --- source/blender/editors/space_view3d/view3d_draw.c | 16 ++++++++++++---- source/blender/editors/space_view3d/view3d_edit.c | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index f1909bb4049..2b863bf794c 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -690,10 +690,13 @@ static void draw_rotation_guide(RegionView3D *rv3d) glShadeModel(GL_SMOOTH); glPointSize(5); glEnable(GL_POINT_SMOOTH); + glDepthMask(0); // don't overwrite zbuf if (rv3d->rot_angle != 0.f) { + // -- draw rotation axis -- float scaled_axis[3]; - mul_v3_v3fl(scaled_axis, rv3d->rot_axis, 3.f); + const float scale = rv3d->dist; + mul_v3_v3fl(scaled_axis, rv3d->rot_axis, scale); glBegin(GL_LINE_STRIP); color[3] = 0; // more transparent toward the ends @@ -701,7 +704,10 @@ static void draw_rotation_guide(RegionView3D *rv3d) add_v3_v3v3(end, o, scaled_axis); glVertex3fv(end); - color[3] = 0.2f + rv3d->rot_angle; // more opaque toward the center + // color[3] = 0.2f + fabsf(rv3d->rot_angle); // modulate opacity with angle + // ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 + + color[3] = 0.5f; // more opaque toward the center glColor4fv(color); glVertex3fv(o); @@ -716,6 +722,7 @@ static void draw_rotation_guide(RegionView3D *rv3d) else color[3] = 0.5; // see-through dot + // -- draw rotation center -- glColor4fv(color); glBegin(GL_POINTS); glVertex3fv(o); @@ -728,6 +735,7 @@ static void draw_rotation_guide(RegionView3D *rv3d) glDisable(GL_BLEND); glDisable(GL_POINT_SMOOTH); + glDepthMask(1); } static void draw_view_icon(RegionView3D *rv3d) @@ -2672,10 +2680,10 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) BDR_drawSketch(C); } -#if 0 // not yet... +//#if 0 // not yet... if (U.ndof_flag & NDOF_SHOW_GUIDE) draw_rotation_guide(rv3d); -#endif +//#endif ED_region_pixelspace(ar); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 75e20ad565e..999120a0987 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1053,13 +1053,13 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) if (invert) angle = -angle; + // transform rotation axis from view to world coordinates + mul_qt_v3(view_inv, axis); + // update the onscreen doo-dad rv3d->rot_angle = angle; copy_v3_v3(rv3d->rot_axis, axis); - // transform rotation axis from view to world coordinates - mul_qt_v3(view_inv, axis); - axis_angle_to_quat(rot, axis, angle); #endif // -------------------------------------------- // apply rotation -- cgit v1.2.3 From f54068719f8f1965ffd3584f9f8ad53b3c7f9602 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 26 Jul 2011 22:43:07 +0000 Subject: shift-motion to pan with 3D mouse --- source/blender/editors/space_view3d/view3d_edit.c | 81 ++++++++++++++++++++-- .../blender/editors/space_view3d/view3d_intern.h | 3 +- source/blender/editors/space_view3d/view3d_ops.c | 6 +- 3 files changed, 83 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 999120a0987..b343718d39b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1104,12 +1104,12 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_FINISHED; } -void VIEW3D_OT_ndof(struct wmOperatorType *ot) +void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot) { /* identifiers */ - ot->name = "Navigate view"; - ot->description = "Navigate the view using a 3D mouse."; - ot->idname = "VIEW3D_OT_ndof"; + ot->name = "NDOF Orbit View"; + ot->description = "Explore every angle of an object using the 3D mouse."; + ot->idname = "VIEW3D_OT_ndof_orbit"; /* api callbacks */ ot->invoke = ndof_orbit_invoke; @@ -1119,6 +1119,79 @@ void VIEW3D_OT_ndof(struct wmOperatorType *ot) ot->flag = 0; } +static int ndof_pan_invoke(bContext *C, wmOperator *op, wmEvent *event) +// -- "pan" navigation +// -- zoom or dolly? +{ + RegionView3D* rv3d = CTX_wm_region_view3d(C); + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + + rv3d->rot_angle = 0.f; // we're panning here! so erase any leftover rotation from other operators + + if (ndof->progress != P_FINISHING) { + const float dt = ndof->dt; + float view_inv[4]; +#if 0 // ------------------------------------------- zoom with Z + // tune these until everything feels right + const float zoom_sensitivity = 1.f; + const float pan_sensitivity = 1.f; + + float pan_vec[3] = { + ndof->tx, ndof->ty, 0 + }; + + // "zoom in" or "translate"? depends on zoom mode in user settings? + if (ndof->tz) { + float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; + rv3d->dist += zoom_distance; + } + + mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); +#else // ------------------------------------------------------- dolly with Z + float speed = 10.f; // blender units per second + // ^^ this is ok for default cube scene, but should scale with.. something + + // tune these until everything feels right + const float forward_sensitivity = 1.f; + const float vertical_sensitivity = 0.4f; + const float lateral_sensitivity = 0.6f; + + float pan_vec[3] = { + lateral_sensitivity * ndof->tx, + vertical_sensitivity * ndof->ty, + forward_sensitivity * ndof->tz + }; + + mul_v3_fl(pan_vec, speed * dt); +#endif + /* transform motion from view to world coordinates */ + invert_qt_qt(view_inv, rv3d->viewquat); + mul_qt_v3(view_inv, pan_vec); + + /* move center of view opposite of hand motion (this is camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, pan_vec); + } + + ED_region_tag_redraw(CTX_wm_region(C)); + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "NDOF Pan View"; + ot->description = "Position your viewpoint with the 3D mouse."; + ot->idname = "VIEW3D_OT_ndof_pan"; + + /* api callbacks */ + ot->invoke = ndof_pan_invoke; + ot->poll = ED_operator_view3d_active; + + /* flags */ + ot->flag = 0; +} + /* ************************ viewmove ******************************** */ diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 28e0e48f220..c4207b0ce25 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -73,7 +73,8 @@ void VIEW3D_OT_dolly(struct wmOperatorType *ot); void VIEW3D_OT_zoom_camera_1_to_1(struct wmOperatorType *ot); void VIEW3D_OT_move(struct wmOperatorType *ot); void VIEW3D_OT_rotate(struct wmOperatorType *ot); -void VIEW3D_OT_ndof(struct wmOperatorType *ot); +void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot); +void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot); void VIEW3D_OT_view_all(struct wmOperatorType *ot); void VIEW3D_OT_viewnumpad(struct wmOperatorType *ot); void VIEW3D_OT_view_selected(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 963e7aeeb95..e47cb1db753 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -64,7 +64,8 @@ void view3d_operatortypes(void) WM_operatortype_append(VIEW3D_OT_zoom); WM_operatortype_append(VIEW3D_OT_zoom_camera_1_to_1); WM_operatortype_append(VIEW3D_OT_dolly); - WM_operatortype_append(VIEW3D_OT_ndof); + WM_operatortype_append(VIEW3D_OT_ndof_orbit); + WM_operatortype_append(VIEW3D_OT_ndof_pan); WM_operatortype_append(VIEW3D_OT_view_all); WM_operatortype_append(VIEW3D_OT_viewnumpad); WM_operatortype_append(VIEW3D_OT_view_orbit); @@ -163,7 +164,8 @@ void view3d_keymap(wmKeyConfig *keyconf) RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1); /* 3D mouse */ - WM_keymap_add_item(keymap, "VIEW3D_OT_ndof", NDOF_MOTION, 0, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_orbit", NDOF_MOTION, 0, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_pan", NDOF_MOTION, 0, KM_SHIFT, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT); RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BACK, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BACK); -- cgit v1.2.3 From 73a9ce7ec04bd1170b292c8f2c83a8c5c10a95ad Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Wed, 27 Jul 2011 07:42:53 +0000 Subject: svn merge -r38558:38752 https://svn.blender.org/svnroot/bf-blender/trunk/blender . --- source/blender/blenkernel/BKE_blender.h | 2 +- source/blender/blenkernel/BKE_effect.h | 1 + source/blender/blenkernel/CMakeLists.txt | 4 + source/blender/blenkernel/SConscript | 1 + source/blender/blenkernel/intern/effect.c | 23 +-- source/blender/blenkernel/intern/seqeffects.c | 2 +- source/blender/blenkernel/intern/text.c | 10 +- source/blender/blenkernel/intern/writeavi.c | 7 +- .../blender/blenkernel/intern/writeframeserver.c | 2 + source/blender/editors/armature/editarmature.c | 2 - source/blender/editors/include/ED_node.h | 3 + .../blender/editors/interface/interface_handlers.c | 11 +- .../blender/editors/interface/interface_layout.c | 12 +- source/blender/editors/interface/interface_panel.c | 4 +- .../blender/editors/interface/interface_regions.c | 11 ++ .../editors/interface/interface_templates.c | 20 +- source/blender/editors/object/object_add.c | 4 +- source/blender/editors/object/object_edit.c | 12 +- source/blender/editors/render/render_shading.c | 2 +- source/blender/editors/space_image/image_ops.c | 6 +- source/blender/editors/space_node/drawnode.c | 15 +- source/blender/editors/space_node/node_draw.c | 13 +- source/blender/editors/space_node/node_edit.c | 150 +++++++++++++- .../editors/space_sequencer/sequencer_add.c | 6 +- source/blender/editors/space_text/text_ops.c | 21 +- source/blender/editors/space_view3d/view3d_edit.c | 1 - .../blender/editors/space_view3d/view3d_header.c | 11 -- source/blender/editors/transform/transform.c | 2 +- source/blender/editors/transform/transform.h | 2 +- .../editors/transform/transform_conversions.c | 14 +- .../blender/editors/transform/transform_generics.c | 2 +- source/blender/editors/transform/transform_ops.c | 2 + source/blender/editors/transform/transform_snap.c | 13 +- source/blender/editors/util/undo.c | 8 +- source/blender/editors/uvedit/uvedit_ops.c | 131 ++++++++++++ source/blender/gpu/intern/gpu_material.c | 2 +- source/blender/imbuf/IMB_imbuf.h | 2 +- source/blender/imbuf/intern/filter.c | 219 +++++++++++---------- source/blender/makesdna/DNA_node_types.h | 4 + source/blender/makesdna/DNA_scene_types.h | 5 +- source/blender/makesrna/intern/CMakeLists.txt | 4 + source/blender/makesrna/intern/SConscript | 2 + source/blender/makesrna/intern/rna_access.c | 6 +- source/blender/makesrna/intern/rna_object_api.c | 2 +- source/blender/makesrna/intern/rna_scene.c | 10 +- source/blender/makesrna/intern/rna_wm.c | 2 +- source/blender/python/mathutils/mathutils.h | 2 + source/blender/python/mathutils/mathutils_Matrix.c | 14 +- .../python/mathutils/mathutils_Quaternion.c | 26 ++- source/blender/python/mathutils/mathutils_Vector.c | 80 +++++++- .../blender/render/intern/source/convertblender.c | 12 +- source/blender/render/intern/source/rendercore.c | 22 +-- source/blender/windowmanager/WM_api.h | 1 + source/blender/windowmanager/intern/wm.c | 6 + 54 files changed, 713 insertions(+), 238 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 25fb6f9f9ff..18f6ad21333 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -53,7 +53,7 @@ extern "C" { /* can be left blank, otherwise a,b,c... etc with no quotes */ #define BLENDER_VERSION_CHAR a /* alpha/beta/rc/release, docs use this */ -#define BLENDER_VERSION_CYCLE release +#define BLENDER_VERSION_CYCLE beta struct ListBase; struct MemFile; diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index 97ac711651b..12f9383cefb 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -105,6 +105,7 @@ typedef struct EffectorCache { /* precalculated for guides */ struct GuideEffectorData *guide_data; float guide_loc[4], guide_dir[3], guide_radius; + float velocity[3]; float frame; int flag; diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 9a384c40e24..defcef58463 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -279,6 +279,10 @@ if(WITH_IMAGE_CINEON) add_definitions(-DWITH_CINEON) endif() +if(WITH_IMAGE_FRAMESERVER) + add_definitions(-DWITH_FRAMESERVER) +endif() + if(WITH_IMAGE_HDR) add_definitions(-DWITH_HDR) endif() diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index 36afce7946c..5ea42ee65ae 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -22,6 +22,7 @@ incs += ' ' + env['BF_ZLIB_INC'] defs = [ 'GLEW_STATIC' ] defs.append('WITH_SMOKE') # TODO, make optional +defs.append('WITH_FRAMESERVER') # TODO, make optional if env['WITH_BF_PYTHON']: incs += ' ../python' diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index ee46bef6038..4b95c44f55f 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -241,6 +241,16 @@ static void precalculate_effector(EffectorCache *eff) } else if(eff->psys) psys_update_particle_tree(eff->psys, eff->scene->r.cfra); + + /* Store object velocity */ + if(eff->ob) { + float old_vel[3]; + + where_is_object_time(eff->scene, eff->ob, cfra - 1.0f); + copy_v3_v3(old_vel, eff->ob->obmat[3]); + where_is_object_time(eff->scene, eff->ob, cfra); + sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel); + } } static EffectorCache *new_effector_cache(Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd) { @@ -680,10 +690,6 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin Object *ob = eff->ob; Object obcopy = *ob; - /* XXX this is not thread-safe, but used from multiple threads by - particle system */ - where_is_object_time(eff->scene, ob, cfra); - /* use z-axis as normal*/ normalize_v3_v3(efd->nor, ob->obmat[2]); @@ -702,13 +708,8 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin VECCOPY(efd->loc, ob->obmat[3]); } - if(real_velocity) { - VECCOPY(efd->vel, ob->obmat[3]); - - where_is_object_time(eff->scene, ob, cfra - 1.0f); - - sub_v3_v3v3(efd->vel, efd->vel, ob->obmat[3]); - } + if(real_velocity) + copy_v3_v3(efd->vel, eff->velocity); *eff->ob = obcopy; diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index fbb5a77fa04..8c19b0c15c3 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -2373,7 +2373,7 @@ static void RVBlurBitmap2_float ( float* map, int width,int height, /* Blancmange (bmange@airdmhor.gen.nz) */ k = -1.0f/(2.0f*(float)M_PI*blur*blur); - fval=0; + for (ix = 0;ix< halfWidth;ix++){ weight = (float)exp(k*(ix*ix)); filter[halfWidth - ix] = weight; diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index da329503c9f..2c507370288 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -400,7 +400,13 @@ Text *add_text(const char *file, const char *relpath) llen++; } - if (llen!=0 || ta->nlines==0) { + /* create new line in cases: + - rest of line (if last line in file hasn't got \n terminator). + in this case content of such line would be used to fill text line buffer + - file is empty. in this case new line is needed to start editing from. + - last characted in buffer is \n. in this case new line is needed to + deal with newline at end of file. (see [#28087]) (sergey) */ + if (llen!=0 || ta->nlines==0 || buffer[len-1]=='\n') { tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); tmp->format= NULL; @@ -1417,6 +1423,8 @@ void txt_insert_buf(Text *text, const char *in_buffer) } undoing= u; + + (void)count; } /******************/ diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c index ba7f9bdd415..769a3f9b11e 100644 --- a/source/blender/blenkernel/intern/writeavi.c +++ b/source/blender/blenkernel/intern/writeavi.c @@ -105,13 +105,18 @@ bMovieHandle *BKE_get_movie_handle(int imtype) mh.get_movie_path = filepath_ffmpeg; } #endif +#ifdef WITH_FRAMESERVER if (imtype == R_FRAMESERVER) { mh.start_movie = start_frameserver; mh.append_movie = append_frameserver; mh.end_movie = end_frameserver; mh.get_next_frame = frameserver_loop; } - +#endif + + /* incase all above are disabled */ + (void)imtype; + return &mh; } diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index 2239f6d3147..d13d15d1269 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -22,6 +22,7 @@ * */ +#ifdef WITH_FRAMESERVER #include #include @@ -381,3 +382,4 @@ void end_frameserver(void) shutdown_socket_system(); } +#endif /* WITH_FRAMESERVER */ diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 20352206121..628cdbf21e9 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -1478,10 +1478,8 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, wmEvent *e bArmature *arm; EditBone *bone, *curBone, *next; int extend= RNA_boolean_get(op->ptr, "extend"); - ARegion *ar; Object *obedit= CTX_data_edit_object(C); arm= obedit->data; - ar= CTX_wm_region(C); view3d_operator_needs_opengl(C); diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h index 829ad3217a9..dfa457c22de 100644 --- a/source/blender/editors/include/ED_node.h +++ b/source/blender/editors/include/ED_node.h @@ -39,6 +39,7 @@ struct Tex; struct bContext; struct bNode; struct ID; +struct ScrArea; /* drawnode.c */ void ED_init_node_butfuncs(void); @@ -51,6 +52,8 @@ void ED_node_generic_update(struct Main *bmain, struct bNodeTree *ntree, struct void ED_node_shader_default(struct Material *ma); void ED_node_composit_default(struct Scene *sce); void ED_node_texture_default(struct Tex *tex); +void ED_node_link_intersect_test(struct ScrArea *sa, int test); +void ED_node_link_insert(struct ScrArea *sa); /* node ops.c */ void ED_operatormacros_node(void); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index e9ec4ccc66d..c5275ea98b5 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1879,7 +1879,6 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle if(but->autocomplete_func || data->searchbox) { changed= ui_textedit_autocomplete(C, but, data); update= 1; /* do live update for tab key */ - retval= WM_UI_HANDLER_BREAK; } /* the hotkey here is not well defined, was G.qual so we check all */ else if(event->shift || event->ctrl || event->alt || event->oskey) { @@ -2325,8 +2324,8 @@ static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, floa if(fac != 1.0f) { /* snap in unit-space */ tempf /= fac; - softmin /= fac; - softmax /= fac; + /* softmin /= fac; */ /* UNUSED */ + /* softmax /= fac; */ /* UNUSED */ softrange /= fac; } @@ -3469,13 +3468,13 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap, CurveMapping *cumap= (CurveMapping*)but->poin; CurveMap *cuma= cumap->cm+cumap->cur; CurveMapPoint *cmp= cuma->curve; - float fx, fy, zoomx, zoomy, offsx, offsy; + float fx, fy, zoomx, zoomy /*, offsx, offsy */ /* UNUSED */; int a, changed= 0; zoomx= (but->x2-but->x1)/(cumap->curr.xmax-cumap->curr.xmin); zoomy= (but->y2-but->y1)/(cumap->curr.ymax-cumap->curr.ymin); - offsx= cumap->curr.xmin; - offsy= cumap->curr.ymin; + /* offsx= cumap->curr.xmin; */ + /* offsy= cumap->curr.ymin; */ if(snap) { float d[2]; diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 79a90fb9d1d..2f0bcc9d5b4 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -149,10 +149,10 @@ typedef struct uiLayoutItemBx { uiBut *roundbox; } uiLayoutItemBx; -typedef struct uiLayoutItemSplt { +typedef struct uiLayoutItemSplit { uiLayout litem; float percentage; -} uiLayoutItemSplt; +} uiLayoutItemSplit; typedef struct uiLayoutItemRoot { uiLayout litem; @@ -1615,7 +1615,7 @@ static void ui_litem_layout_row(uiLayout *litem) int x, y, w, tot, totw, neww, itemw, minw, itemh, offset; int fixedw, freew, fixedx, freex, flag= 0, lastw= 0; - x= litem->x; + /* x= litem->x; */ /* UNUSED */ y= litem->y; w= litem->w; totw= 0; @@ -2020,7 +2020,7 @@ static void ui_litem_estimate_split(uiLayout *litem) static void ui_litem_layout_split(uiLayout *litem) { - uiLayoutItemSplt *split= (uiLayoutItemSplt*)litem; + uiLayoutItemSplit *split= (uiLayoutItemSplit*)litem; uiItem *item; float percentage; const int tot= BLI_countlist(&litem->items); @@ -2242,9 +2242,9 @@ uiLayout *uiLayoutOverlap(uiLayout *layout) uiLayout *uiLayoutSplit(uiLayout *layout, float percentage, int align) { - uiLayoutItemSplt *split; + uiLayoutItemSplit *split; - split= MEM_callocN(sizeof(uiLayoutItemSplt), "uiLayoutItemSplt"); + split= MEM_callocN(sizeof(uiLayoutItemSplit), "uiLayoutItemSplit"); split->litem.item.type= ITEM_LAYOUT_SPLIT; split->litem.root= layout->root; split->litem.align= align; diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 9ed3cabb4cb..3b20533dcd4 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -575,8 +575,8 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, rcti *rect) ui_draw_tria_rect(&itemrect, 'h'); else ui_draw_tria_rect(&itemrect, 'v'); - - + + (void)ofsx; } /************************** panel alignment *************************/ diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 62043f240e4..9e7717260e6 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -484,6 +484,17 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) } } } + else if (ELEM(but->type, MENU, PULLDOWN)) { + if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) { + if(but->menu_create_func && WM_menutype_contains((MenuType *)but->poin)) { + MenuType *mt= (MenuType *)but->poin; + BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Python: %s", mt->idname); + data->color[data->totline]= 0x888888; + data->totline++; + } + } + + } assert(data->totline < MAX_TOOLTIP_LINES); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 25dbb68a258..34315494e14 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -851,7 +851,7 @@ uiLayout *uiTemplateModifier(uiLayout *layout, bContext *C, PointerRNA *ptr) /* verify we have valid data */ if(!RNA_struct_is_a(ptr->type, &RNA_Modifier)) { - RNA_warning("uiTemplateModifier: expected modifier on object.\n"); + RNA_warning("uiTemplateModifier: Expected modifier on object.\n"); return NULL; } @@ -859,7 +859,7 @@ uiLayout *uiTemplateModifier(uiLayout *layout, bContext *C, PointerRNA *ptr) md= ptr->data; if(!ob || !(GS(ob->id.name) == ID_OB)) { - RNA_warning("uiTemplateModifier: expected modifier on object.\n"); + RNA_warning("uiTemplateModifier: Expected modifier on object.\n"); return NULL; } @@ -976,9 +976,6 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) block= uiLayoutGetBlock(box); /* Draw constraint header */ - - /* rounded header */ - // rb_col= (con->flag & CONSTRAINT_ACTIVE)?50:20; // UNUSED /* open/close */ uiBlockSetEmboss(block, UI_EMBOSSN); @@ -1083,7 +1080,7 @@ uiLayout *uiTemplateConstraint(uiLayout *layout, PointerRNA *ptr) /* verify we have valid data */ if(!RNA_struct_is_a(ptr->type, &RNA_Constraint)) { - RNA_warning("uiTemplateConstraint: expected constraint on object.\n"); + RNA_warning("uiTemplateConstraint: Expected constraint on object.\n"); return NULL; } @@ -1091,7 +1088,7 @@ uiLayout *uiTemplateConstraint(uiLayout *layout, PointerRNA *ptr) con= ptr->data; if(!ob || !(GS(ob->id.name) == ID_OB)) { - RNA_warning("uiTemplateConstraint: expected constraint on object.\n"); + RNA_warning("uiTemplateConstraint: Expected constraint on object.\n"); return NULL; } @@ -1137,7 +1134,7 @@ void uiTemplatePreview(uiLayout *layout, ID *id, int show_buttons, ID *parent, M PointerRNA texture_ptr; if(id && !ELEM4(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA)) { - RNA_warning("uiTemplatePreview: expected ID of type material, texture, lamp or world.\n"); + RNA_warning("uiTemplatePreview: Expected ID of type material, texture, lamp or world.\n"); return; } @@ -2171,14 +2168,14 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * if(prop) { type= RNA_property_type(prop); if(type != PROP_COLLECTION) { - RNA_warning("uiTemplateList: expected collection property.\n"); + RNA_warning("uiTemplateList: Expected collection property.\n"); return; } } activetype= RNA_property_type(activeprop); if(activetype != PROP_INT) { - RNA_warning("uiTemplateList: expected integer property.\n"); + RNA_warning("uiTemplateList: Expected integer property.\n"); return; } @@ -2200,7 +2197,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * /* create list items */ RNA_PROP_BEGIN(ptr, itemptr, prop) { /* create button */ - if(i == 9) + if(!(i % 9)) row= uiLayoutRow(col, 0); icon= list_item_icon_get(C, &itemptr, rnaicon, 1); @@ -2215,7 +2212,6 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * } else if(listtype == 'c') { /* compact layout */ - found= 0; row= uiLayoutRow(layout, 1); diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 7ca172c6945..f5f97c6a5f6 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -806,14 +806,14 @@ static int object_delete_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); - int islamp= 0; + /* int islamp= 0; */ /* UNUSED */ if(CTX_data_edit_object(C)) return OPERATOR_CANCELLED; CTX_DATA_BEGIN(C, Base*, base, selected_bases) { - if(base->object->type==OB_LAMP) islamp= 1; + /* if(base->object->type==OB_LAMP) islamp= 1; */ /* deselect object -- it could be used in other scenes */ base->object->flag &= ~SELECT; diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 29a740affc5..395705dc029 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -2162,16 +2162,20 @@ static int game_property_copy_exec(bContext *C, wmOperator *op) } CTX_DATA_END; } } - else if (ELEM(type, COPY_PROPERTIES_REPLACE, COPY_PROPERTIES_MERGE)) { + + else { CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) { if (ob != ob_iter) { if (ob->data != ob_iter->data){ - if (type == 2) {/* merge */ + if (type == COPY_PROPERTIES_REPLACE) + copy_properties( &ob_iter->prop, &ob->prop ); + + /* merge - the default when calling with no argument */ + else { for(prop = ob->prop.first; prop; prop= prop->next ) { set_ob_property(ob_iter, prop); } - } else /* replace */ - copy_properties( &ob_iter->prop, &ob->prop ); + } } } } diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index fdd53d27b02..cfed2750e18 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -108,7 +108,7 @@ void OBJECT_OT_material_slot_add(wmOperatorType *ot) /* identifiers */ ot->name= "Add Material Slot"; ot->idname= "OBJECT_OT_material_slot_add"; - ot->description="Add a new material slot or duplicate the selected one"; + ot->description="Add a new material slot"; /* api callbacks */ ot->exec= material_slot_add_exec; diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 77fb129e278..204d5dfb1b1 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -554,7 +554,7 @@ static int view_selected_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene; Object *obedit; Image *ima; - float size, min[2], max[2], d[2]; + float size, min[2], max[2], d[2], aspx, aspy; int width, height; /* retrieve state */ @@ -565,6 +565,10 @@ static int view_selected_exec(bContext *C, wmOperator *UNUSED(op)) ima= ED_space_image(sima); ED_space_image_size(sima, &width, &height); + ED_image_aspect(ima, &aspx, &aspy); + + width= width*aspx; + height= height*aspy; /* get bounds */ if(!ED_uvedit_minmax(scene, ima, obedit, min, max)) diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 1bf2c3d89bd..50e657bbb61 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -1869,10 +1869,17 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) else { /* check cyclic */ if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) { - if(link->fromnode->flag & SELECT) - th_col1= TH_EDGE_SELECT; - if(link->tonode->flag & SELECT) - th_col2= TH_EDGE_SELECT; + /* special indicated link, on drop-node */ + if(link->flag & NODE_LINKFLAG_HILITE) { + th_col1= th_col2= TH_ACTIVE; + } + else { + /* regular link */ + if(link->fromnode->flag & SELECT) + th_col1= TH_EDGE_SELECT; + if(link->tonode->flag & SELECT) + th_col2= TH_EDGE_SELECT; + } do_shaded= 1; do_triple= 1; } diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index cd1fa5c16a7..950b3c72fe7 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -781,14 +781,15 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN iconbutw, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, 0.5, ""); } { /* always hide/reveal unused sockets */ - int shade; - - iconofs-=iconbutw; // XXX re-enable - /*if(node_has_hidden_sockets(node)) + /* int shade; + if(node_has_hidden_sockets(node)) shade= -40; - else*/ - shade= -90; + else + shade= -90; */ + + iconofs-=iconbutw; + uiDefIconBut(node->block, LABEL, B_REDR, ICON_PLUS, iconofs, rct->ymax-NODE_DY, iconbutw, UI_UNIT_Y, NULL, 0.0, 0.0, 1.0, 0.5, ""); } diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index abc7b273ec9..4230a43d2ec 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -2492,6 +2492,151 @@ void NODE_OT_links_cut(wmOperatorType *ot) RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); } +/* ********************* automatic node insert on dragging ******************* */ + +/* assumes sockets in list */ +static bNodeSocket *socket_best_match(ListBase *sockets, int type) +{ + bNodeSocket *sock; + + /* first, match type */ + for(sock= sockets->first; sock; sock= sock->next) + if(!(sock->flag & SOCK_HIDDEN)) + if(type == sock->type) + return sock; + + /* then just use first unhidden socket */ + for(sock= sockets->first; sock; sock= sock->next) + if(!(sock->flag & SOCK_HIDDEN)) + return sock; + + /* OK, let's unhide proper one */ + for(sock= sockets->first; sock; sock= sock->next) { + if(type == sock->type) { + sock->flag &= ~SOCK_HIDDEN; + return sock; + } + } + + /* just the first */ + sock= sockets->first; + sock->flag &= ~SOCK_HIDDEN; + + return sockets->first; +} + +/* prevent duplicate testing code below */ +static SpaceNode *ed_node_link_conditions(ScrArea *sa, bNode **select) +{ + SpaceNode *snode= sa?sa->spacedata.first:NULL; + bNode *node; + bNodeLink *link; + + /* no unlucky accidents */ + if(sa==NULL || sa->spacetype!=SPACE_NODE) return NULL; + + *select= NULL; + + for(node= snode->edittree->nodes.first; node; node= node->next) { + if(node->flag & SELECT) { + if(*select) + break; + else + *select= node; + } + } + /* only one selected */ + if(node || *select==NULL) return NULL; + + /* correct node */ + if((*select)->inputs.first==NULL || (*select)->outputs.first==NULL) return NULL; + + /* test node for links */ + for(link= snode->edittree->links.first; link; link=link->next) { + if(link->tonode == *select || link->fromnode == *select) + return NULL; + } + + return snode; +} + +/* assumes link with NODE_LINKFLAG_HILITE set */ +void ED_node_link_insert(ScrArea *sa) +{ + bNode *node, *select; + SpaceNode *snode= ed_node_link_conditions(sa, &select); + bNodeLink *link; + bNodeSocket *sockto; + + if(snode==NULL) return; + + /* get the link */ + for(link= snode->edittree->links.first; link; link=link->next) + if(link->flag & NODE_LINKFLAG_HILITE) + break; + + if(link) { + node= link->tonode; + sockto= link->tosock; + + link->tonode= select; + link->tosock= socket_best_match(&select->inputs, link->fromsock->type); + link->flag &= ~NODE_LINKFLAG_HILITE; + + nodeAddLink(snode->edittree, select, socket_best_match(&select->outputs, sockto->type), node, sockto); + ntreeSolveOrder(snode->edittree); /* needed for pointers */ + snode_tag_changed(snode, select); + ED_node_changed_update(snode->id, select); + } +} + + +/* test == 0, clear all intersect flags */ +void ED_node_link_intersect_test(ScrArea *sa, int test) +{ + bNode *select; + SpaceNode *snode= ed_node_link_conditions(sa, &select); + bNodeLink *link, *selink=NULL; + float mcoords[6][2]; + + if(snode==NULL) return; + + /* clear flags */ + for(link= snode->edittree->links.first; link; link=link->next) + link->flag &= ~NODE_LINKFLAG_HILITE; + + if(test==0) return; + + /* okay, there's 1 node, without links, now intersect */ + mcoords[0][0]= select->totr.xmin; + mcoords[0][1]= select->totr.ymin; + mcoords[1][0]= select->totr.xmax; + mcoords[1][1]= select->totr.ymin; + mcoords[2][0]= select->totr.xmax; + mcoords[2][1]= select->totr.ymax; + mcoords[3][0]= select->totr.xmin; + mcoords[3][1]= select->totr.ymax; + mcoords[4][0]= select->totr.xmin; + mcoords[4][1]= select->totr.ymin; + mcoords[5][0]= select->totr.xmax; + mcoords[5][1]= select->totr.ymax; + + /* we only tag a single link for intersect now */ + /* idea; use header dist when more? */ + for(link= snode->edittree->links.first; link; link=link->next) { + + if(cut_links_intersect(link, mcoords, 5)) { /* intersect code wants edges */ + if(selink) + break; + selink= link; + } + } + + if(link==NULL && selink) + selink->flag |= NODE_LINKFLAG_HILITE; +} + + /* ******************************** */ // XXX some code needing updating to operators... @@ -2914,7 +3059,8 @@ void NODE_OT_delete(wmOperatorType *ot) /* note: in cmp_util.c is similar code, for node_compo_pass_on() */ /* used for disabling node (similar code in node_draw.c for disable line) */ -static void node_delete_reconnect(bNodeTree* tree, bNode* node) { +static void node_delete_reconnect(bNodeTree* tree, bNode* node) +{ bNodeLink *link, *next; bNodeSocket *valsocket= NULL, *colsocket= NULL, *vecsocket= NULL; bNodeSocket *deliveringvalsocket= NULL, *deliveringcolsocket= NULL, *deliveringvecsocket= NULL; @@ -3142,3 +3288,5 @@ void NODE_OT_add_file(wmOperatorType *ot) RNA_def_string(ot->srna, "name", "Image", 24, "Name", "Datablock name to assign."); } + + diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index f6e3dc3dd0a..36e334990cb 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -303,7 +303,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad Scene *scene= CTX_data_scene(C); /* only for sound */ Editing *ed= seq_give_editing(scene, TRUE); SeqLoadInfo seq_load; - Sequence *seq; + /* Sequence *seq; */ /* UNUSED */ int tot_files; seq_load_operator_info(&seq_load, op); @@ -324,13 +324,13 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad RNA_string_get(&itemptr, "name", file_only); BLI_join_dirfile(seq_load.path, sizeof(seq_load.path), dir_only, file_only); - seq= seq_load_func(C, ed->seqbasep, &seq_load); + /* seq= */ seq_load_func(C, ed->seqbasep, &seq_load); } RNA_END; } else { /* single file */ - seq= seq_load_func(C, ed->seqbasep, &seq_load); + /* seq= */ seq_load_func(C, ed->seqbasep, &seq_load); } if (seq_load.tot_success==0) { diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 2bd6bd624df..13eb24ed1f2 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -36,6 +36,7 @@ #include #include /* ispunct */ #include +#include #include "MEM_guardedalloc.h" @@ -449,15 +450,14 @@ static void txt_write_file(Text *text, ReportList *reports) FILE *fp; TextLine *tmp; struct stat st; - int res; - char file[FILE_MAXDIR+FILE_MAXFILE]; + char filepath[FILE_MAXDIR+FILE_MAXFILE]; - BLI_strncpy(file, text->name, FILE_MAXDIR+FILE_MAXFILE); - BLI_path_abs(file, G.main->name); + BLI_strncpy(filepath, text->name, FILE_MAXDIR+FILE_MAXFILE); + BLI_path_abs(filepath, G.main->name); - fp= fopen(file, "w"); + fp= fopen(filepath, "w"); if(fp==NULL) { - BKE_report(reports, RPT_ERROR, "Unable to save file."); + BKE_reportf(reports, RPT_ERROR, "Unable to save \"%s\": %s.", filepath, errno ? strerror(errno) : "Unknown error writing file"); return; } @@ -471,8 +471,13 @@ static void txt_write_file(Text *text, ReportList *reports) fclose (fp); - res= stat(file, &st); - text->mtime= st.st_mtime; + if(stat(filepath, &st) == 0) { + text->mtime= st.st_mtime; + } + else { + text->mtime= 0; + BKE_reportf(reports, RPT_WARNING, "Unable to stat \"%s\": %s.", filepath, errno ? strerror(errno) : "Unknown error starrng file"); + } if(text->flags & TXT_ISDIRTY) text->flags ^= TXT_ISDIRTY; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index b343718d39b..94224698063 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -129,7 +129,6 @@ void ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d) } else { ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist); - root_parent= v3d->camera; DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB); WM_main_add_notifier(NC_OBJECT|ND_TRANSFORM, v3d->camera); } diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 75c8d5cae73..ae80a554e08 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -505,17 +505,6 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); uiItemR(row, &v3dptr, "use_pivot_point_align", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); - /* NDOF */ - /* Not implemented yet - if (G.ndofdevice ==0 ) { - uiDefIconTextButC(block, ICONTEXTROW,B_NDOF, ICON_NDOF_TURN, ndof_pup(), 0,0,UI_UNIT_X+10,UI_UNIT_Y, &(v3d->ndofmode), 0, 3.0, 0, 0, "Ndof mode"); - - uiDefIconButC(block, TOG, B_NDOF, ICON_NDOF_DOM, - 0,0,UI_UNIT_X,UI_UNIT_Y, - &v3d->ndoffilter, 0, 1, 0, 0, "dominant axis"); - } - */ - /* Transform widget / manipulators */ row= uiLayoutRow(layout, 1); uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 81aade5ca64..7f8d5976e86 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -969,7 +969,7 @@ int transformEvent(TransInfo *t, wmEvent *event) break; case OKEY: if (t->flag & T_PROP_EDIT && event->shift) { - t->prop_mode = (t->prop_mode + 1) % 6; + t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX; calculatePropRatio(t); t->redraw |= TREDRAW_HARD; } diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index d8e750acb88..d8e42488787 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -96,7 +96,7 @@ typedef struct TransSnap { short modeSelect; short align; char project; - char project_self; + char snap_self; short peel; short status; float snapPoint[3]; /* snapping from this point */ diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 16bfc75c979..0a5e290643a 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -87,6 +87,7 @@ #include "ED_object.h" #include "ED_markers.h" #include "ED_mesh.h" +#include "ED_node.h" #include "ED_types.h" #include "ED_uvedit.h" #include "ED_curve.h" /* for ED_curve_editnurbs */ @@ -2182,6 +2183,12 @@ void flushTransNodes(TransInfo *t) td->loc2d[0]= td->loc[0]; td->loc2d[1]= td->loc[1]; } + + /* handle intersection with noodles */ + if(t->total==1) { + ED_node_link_intersect_test(t->sa, 1); + } + } /* *** SEQUENCE EDITOR *** */ @@ -4756,7 +4763,12 @@ void special_aftertrans_update(bContext *C, TransInfo *t) } else if (t->spacetype == SPACE_NODE) { - /* pass */ + if(cancelled == 0) + ED_node_link_insert(t->sa); + + /* clear link line */ + ED_node_link_intersect_test(t->sa, 0); + } else if (t->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 20a26d8c58d..6d0a978700f 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1070,7 +1070,7 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) } } // Need stuff to take it from edit mesh or whatnot here - else + else if (t->spacetype == SPACE_VIEW3D) { if (t->obedit && t->obedit->type == OB_MESH && (((Mesh *)t->obedit->data)->editflag & ME_EDIT_MIRROR_X)) { diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 0b0b22fb689..a779982099e 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -960,6 +960,8 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0); + WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0); km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0); diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index d9d9b0f9102..933d90ebbf2 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -392,7 +392,7 @@ static void initSnappingMode(TransInfo *t) } else { - t->tsnap.modeSelect = t->tsnap.project_self ? SNAP_ALL : SNAP_NOT_OBEDIT; + t->tsnap.modeSelect = t->tsnap.snap_self ? SNAP_ALL : SNAP_NOT_OBEDIT; } } /* Particles edit mode*/ @@ -458,9 +458,9 @@ void initSnapping(TransInfo *t, wmOperator *op) t->tsnap.project = RNA_boolean_get(op->ptr, "use_snap_project"); } - if (RNA_struct_find_property(op->ptr, "use_snap_project_self")) + if (RNA_struct_find_property(op->ptr, "use_snap_self")) { - t->tsnap.project = RNA_boolean_get(op->ptr, "use_snap_project_self"); + t->tsnap.snap_self = RNA_boolean_get(op->ptr, "use_snap_self"); } } } @@ -473,7 +473,7 @@ void initSnapping(TransInfo *t, wmOperator *op) t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) == SCE_SNAP_ROTATE); t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); - t->tsnap.project_self = !((t->settings->snap_flag & SCE_SNAP_PROJECT_NO_SELF) == SCE_SNAP_PROJECT_NO_SELF); + t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) == SCE_SNAP_NO_SELF); t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); } @@ -1944,6 +1944,11 @@ static void applyGrid(TransInfo *t, float *val, int max_index, float fac[3], Gea int i; float asp[3] = {1.0f, 1.0f, 1.0f}; // TODO: Remove hard coded limit here (3) + if(max_index > 3) { + printf("applyGrid: invalid index %d, clamping\n", max_index); + max_index= 3; + } + // Early bailing out if no need to snap if (fac[action] == 0.0f) return; diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index 8a6ec7f75db..a2381a208ef 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -358,19 +358,25 @@ int ED_undo_operator_repeat(bContext *C, struct wmOperator *op) ret= 1; } } + else { + if (G.f & G_DEBUG) { + printf("redo_cb: WM_operator_repeat_check returned false %s\n", op->type->name); + } + } /* set region back */ CTX_wm_region_set(C, ar); } else { if (G.f & G_DEBUG) { - printf("redo_cb: WM_operator_repeat_check returned false %s\n", op->type->name); + printf("redo_cb: ED_undo_operator_repeat called with NULL 'op'\n"); } } return ret; } + void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void *UNUSED(arg_unused)) { ED_undo_operator_repeat(C, (wmOperator *)arg_op); diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index c09f8cff02d..70659994c55 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -1057,6 +1057,134 @@ static void weld_align_uv(bContext *C, int tool) } } + if(tool == 's' || tool == 't' || tool == 'u') { + /* pass 1&2 variables */ + int i, j; + int starttmpl= -1, connectedtostarttmpl= -1, startcorner; + int endtmpl= -1, connectedtoendtmpl= -1, endcorner; + MTFace *startface, *endface; + int itmpl, jtmpl; + EditVert *eve; + int pass; /* first 2 passes find endpoints, 3rd pass moves middle points, 4th pass is fail-on-face-selected */ + EditFace *startefa, *endefa; + + /* pass 3 variables */ + float startx, starty, firstm, firstb, midx, midy; + float endx, endy, secondm, secondb, midmovedx, midmovedy; + float IsVertical_check= -1; + float IsHorizontal_check= -1; + + for(i= 0, eve= em->verts.first; eve; eve= eve->next, i++) /* give each point a unique name */ + eve->tmp.l= i; + for(pass= 1; pass <= 3; pass++) { /* do this for each endpoint */ + if(pass == 3){ /* calculate */ + startx= startface->uv[startcorner][0]; + starty= startface->uv[startcorner][1]; + endx= endface->uv[endcorner][0]; + endy= endface->uv[endcorner][1]; + firstm= (endy-starty)/(endx-startx); + firstb= starty-(firstm*startx); + secondm= -1.0f/firstm; + if(startx == endx) IsVertical_check= startx; + if(starty == endy) IsHorizontal_check= starty; + } + for(efa= em->faces.first; efa; efa= efa->next) { /* for each face */ + tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); /* get face */ + if(uvedit_face_visible(scene, ima, efa, tf)) { /* if you can see it */ + if(uvedit_face_selected(scene, efa, tf)) { /* if the face is selected, get out now! */ + pass= 4; + break; + } + for(i= 0; (i < 3 || (i == 3 && efa->v4)); i++) { /* for each point of the face */ + itmpl= (*(&efa->v1 + i))->tmp.l; /* get unique name for points */ + if(pass == 3) { /* move */ + if(uvedit_uv_selected(scene, efa, tf, i)) { + if(!(itmpl == starttmpl || itmpl == endtmpl)) { + if(IsVertical_check != -1) tf->uv[i][0]= IsVertical_check; + if(IsHorizontal_check != -1) tf->uv[i][1]= IsHorizontal_check; + if((IsVertical_check == -1) && (IsHorizontal_check == -1)) { + midx= tf->uv[i][0]; + midy= tf->uv[i][1]; + if(tool == 's') { + secondb= midy-(secondm*midx); + midmovedx= (secondb-firstb)/(firstm-secondm); + midmovedy= (secondm*midmovedx)+secondb; + tf->uv[i][0]= midmovedx; + tf->uv[i][1]= midmovedy; + } + else if(tool == 't') { + tf->uv[i][0]= (midy-firstb)/firstm; /* midmovedx */ + } + else if(tool == 'u') { + tf->uv[i][1]= (firstm*midx)+firstb; /* midmovedy */ + } + } + } + } + } + else { + for(j= 0; (j < 3 || (j == 3 && efa->v4)); j++) { /* also for each point on the face */ + jtmpl= (*(&efa->v1 + j))->tmp.l; + if(i != j && (!efa->v4 || ABS(i-j) != 2)) { /* if the points are connected */ + /* quad (0,1,2,3) 0,1 0,3 1,0 1,2 2,1 2,3 3,0 3,2 + * triangle (0,1,2) 0,1 0,2 1,0 1,2 2,0 2,1 */ + if(uvedit_uv_selected(scene, efa, tf, i) && uvedit_uv_selected(scene, efa, tf, j)) { + /* if the edge is selected */ + if(pass == 1) { /* if finding first endpoint */ + if(starttmpl == -1) { /* if the first endpoint isn't found yet */ + starttmpl= itmpl; /* set unique name for endpoint */ + connectedtostarttmpl= jtmpl; + /* get point that endpoint is connected to */ + startface= tf; /* get face it's on */ + startcorner= i; /* what corner of the face? */ + startefa= efa; + efa= em->faces.first; + tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); + i= -1; + break; + } + if(starttmpl == itmpl && jtmpl != connectedtostarttmpl) { + starttmpl= -1; /* not an endpoint */ + efa= startefa; + tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); + i= startcorner; + break; + } + } + else if(pass == 2) { /* if finding second endpoint */ + if(endtmpl == -1 && itmpl != starttmpl) { + endtmpl= itmpl; + connectedtoendtmpl= jtmpl; + endface= tf; + endcorner= i; + endefa= efa; + efa= em->faces.first; + tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); + i= -1; + break; + } + if(endtmpl == itmpl && jtmpl != connectedtoendtmpl) { + endtmpl= -1; + efa= endefa; + tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); + i= endcorner; + break; + } + } + } + } + } + } + } + } + } + if(pass == 2 && (starttmpl == -1 || endtmpl == -1)) { + /* if endpoints aren't found */ + pass=4; + } + } + } + uvedit_live_unwrap_update(sima, scene, obedit); DAG_id_tag_update(obedit->data, 0); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); @@ -1074,6 +1202,9 @@ static int align_exec(bContext *C, wmOperator *op) static void UV_OT_align(wmOperatorType *ot) { static EnumPropertyItem axis_items[] = { + {'s', "ALIGN_S", 0, "Straighten", "Align UVs along the line defined by the endpoints"}, + {'t', "ALIGN_T", 0, "Straighten X", "Align UVs along the line defined by the endpoints along the X axis"}, + {'u', "ALIGN_U", 0, "Straighten Y", "Align UVs along the line defined by the endpoints along the Y axis"}, {'a', "ALIGN_AUTO", 0, "Align Auto", "Automatically choose the axis on which there is most alignment already"}, {'x', "ALIGN_X", 0, "Align X", "Align UVs on X axis"}, {'y', "ALIGN_Y", 0, "Align Y", "Align UVs on Y axis"}, diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 3804aad6848..806c70d841f 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -671,7 +671,7 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la i = is; GPU_link(mat, "shade_visifac", i, visifac, shi->refl, &i); - vn = shi->vn; + /*if(ma->mode & MA_TANGENT_VN) GPU_link(mat, "shade_tangent_v_spec", GPU_attribute(CD_TANGENT, ""), &vn);*/ diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index ff01e3a8a1e..36123592c54 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -252,7 +252,7 @@ void IMB_filter(struct ImBuf *ibuf); void IMB_filterN(struct ImBuf *out, struct ImBuf *in); void IMB_mask_filter_extend(char *mask, int width, int height); void IMB_mask_clear(struct ImBuf *ibuf, char *mask, int val); -void IMB_filter_extend(struct ImBuf *ibuf, char *mask); +void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter); void IMB_makemipmap(struct ImBuf *ibuf, int use_filter); void IMB_remakemipmap(struct ImBuf *ibuf, int use_filter); struct ImBuf *IMB_getmipmap(struct ImBuf *ibuf, int level); diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index d12360e5a7e..1644e653df4 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -21,7 +21,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Morten Mikkelsen. * * ***** END GPL LICENSE BLOCK ***** * filter.c @@ -326,121 +326,132 @@ void IMB_mask_clear(ImBuf *ibuf, char *mask, int val) } } -#define EXTEND_PIXEL(color, w) if((color)[3]) {r+= w*(color)[0]; g+= w*(color)[1]; b+= w*(color)[2]; a+= w*(color)[3]; tot+=w;} +static int filter_make_index(const int x, const int y, const int w, const int h) +{ + if(x<0 || x>=w || y<0 || y>=h) return -1; /* return bad index */ + else return y*w+x; +} + +static int check_pixel_assigned(const void *buffer, const char *mask, const int index, const int depth, const int is_float) +{ + int res = 0; + + if(index>=0) { + const int alpha_index = depth*index+(depth-1); + + if(mask!=NULL) { + res = mask[index]!=0 ? 1 : 0; + } + else if( (is_float && ((const float *) buffer)[alpha_index]!=0.0f) || + (!is_float && ((const unsigned char *) buffer)[alpha_index]!=0) ) { + res=1; + } + } + + return res; +} /* if alpha is zero, it checks surrounding pixels and averages color. sets new alphas to 1.0 * * When a mask is given, only effect pixels with a mask value of 1, defined as BAKE_MASK_MARGIN in rendercore.c * */ -void IMB_filter_extend(struct ImBuf *ibuf, char *mask) +void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) { - register char *row1, *row2, *row3; - register char *cp; - int rowlen, x, y; - - rowlen= ibuf->x; - - - if (ibuf->rect_float) { - float *temprect; - float *row1f, *row2f, *row3f; - float *fp; - temprect= MEM_dupallocN(ibuf->rect_float); - - for(y=1; y<=ibuf->y; y++) { - /* setup rows */ - row1f= (float *)(temprect + (y-2)*rowlen*4); - row2f= row1f + 4*rowlen; - row3f= row2f + 4*rowlen; - if(y==1) - row1f= row2f; - else if(y==ibuf->y) - row3f= row2f; - - fp= (float *)(ibuf->rect_float + (y-1)*rowlen*4); - - for(x=0; xx; + const int height= ibuf->y; + const int depth= 4; /* always 4 channels */ + const int chsize= ibuf->rect_float ? sizeof(float) : sizeof(unsigned char); + const int bsize= width*height*depth*chsize; + const int is_float= ibuf->rect_float!=NULL; + void *dstbuf= (void *) MEM_dupallocN(ibuf->rect_float ? (void *) ibuf->rect_float : (void *) ibuf->rect); + char *dstmask= mask==NULL ? NULL : (char *) MEM_dupallocN(mask); + void *srcbuf= ibuf->rect_float ? (void *) ibuf->rect_float : (void *) ibuf->rect; + char *srcmask= mask; + int cannot_early_out= 1, r, n, k, i, j, c; + float weight[25]; + + /* build a weights buffer */ + n= 2; + k= 0; + for(i = -n; i <= n; i++) + for(j = -n; j <= n; j++) + weight[k++] = sqrt((float) i * i + j * j); + + /* run passes */ + for(r = 0; cannot_early_out == 1 && r < filter; r++) { + int x, y; + cannot_early_out = 0; + + for(y= 0; y 255 ? 255 : (acc[c] < 0 ? 0 : ((unsigned char) (acc[c]+0.5f))); + } + } + + if(dstmask!=NULL) dstmask[index]=FILTER_MASK_MARGIN; /* assigned */ + cannot_early_out = 1; + } } } - fp+=4; - - if(x!=0) { - row1f+=4; row2f+=4; row3f+=4; - } } } - MEM_freeN(temprect); - } - else if(ibuf->rect) { - int *temprect; - - /* make a copy, to prevent flooding */ - temprect= MEM_dupallocN(ibuf->rect); - - for(y=1; y<=ibuf->y; y++) { - /* setup rows */ - row1= (char *)(temprect + (y-2)*rowlen); - row2= row1 + 4*rowlen; - row3= row2 + 4*rowlen; - if(y==1) - row1= row2; - else if(y==ibuf->y) - row3= row2; - - cp= (char *)(ibuf->rect + (y-1)*rowlen); - - for(x=0; xflag */ +#define NODE_LINKFLAG_HILITE 1 + /* the basis for a Node tree, all links and nodes reside internal here */ /* only re-usable node trees are in the library though, materials and textures allocate own tree struct */ typedef struct bNodeTree { diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 3c14dacf973..2211f93a8ae 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1074,7 +1074,7 @@ typedef struct Scene { #define SCE_SNAP_ROTATE 2 #define SCE_SNAP_PEEL_OBJECT 4 #define SCE_SNAP_PROJECT 8 -#define SCE_SNAP_PROJECT_NO_SELF 16 +#define SCE_SNAP_NO_SELF 16 /* toolsettings->snap_target */ #define SCE_SNAP_TARGET_CLOSEST 0 #define SCE_SNAP_TARGET_CENTER 1 @@ -1107,7 +1107,8 @@ typedef struct Scene { #define PROP_SHARP 3 #define PROP_LIN 4 #define PROP_CONST 5 -#define PROP_RANDOM 6 +#define PROP_RANDOM 6 +#define PROP_MODE_MAX 7 /* toolsettings->proportional */ #define PROP_EDIT_OFF 0 diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index c9865bf3df4..cb593e7deab 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -171,6 +171,10 @@ if(WITH_IMAGE_HDR) add_definitions(-DWITH_HDR) endif() +if(WITH_IMAGE_FRAMESERVER) + add_definitions(-DWITH_FRAMESERVER) +endif() + if(WITH_AUDASPACE) add_definitions(-DWITH_AUDASPACE) endif() diff --git a/source/blender/makesrna/intern/SConscript b/source/blender/makesrna/intern/SConscript index 421c3a60691..5e43ed9b2fb 100644 --- a/source/blender/makesrna/intern/SConscript +++ b/source/blender/makesrna/intern/SConscript @@ -54,6 +54,8 @@ if env['WITH_BF_CINEON']: if env['WITH_BF_HDR']: defs.append('WITH_HDR') +defs.append('WITH_FRAMESERVER') # TODO, make optional + if env['WITH_BF_FFMPEG']: defs.append('WITH_FFMPEG') incs += ' ' + env['BF_FFMPEG_INC'] diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index d9fbdd7caf2..dcf2400b9ba 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4407,15 +4407,15 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSE if(!(parm->flag & PROP_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) { switch(parm->type) { case PROP_BOOLEAN: - if(parm->arraydimension) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size); + if(parm->arraydimension) memcpy(data, ((BooleanPropertyRNA*)parm)->defaultarray, size); else memcpy(data, &((BooleanPropertyRNA*)parm)->defaultvalue, size); break; case PROP_INT: - if(parm->arraydimension) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size); + if(parm->arraydimension) memcpy(data, ((IntPropertyRNA*)parm)->defaultarray, size); else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size); break; case PROP_FLOAT: - if(parm->arraydimension) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size); + if(parm->arraydimension) memcpy(data, ((FloatPropertyRNA*)parm)->defaultarray, size); else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size); break; case PROP_ENUM: diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 9018fd8c71a..21fa28af01a 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -544,7 +544,7 @@ void RNA_api_object(StructRNA *srna) /* location of point for test and max distance */ parm= RNA_def_float_vector(func, "point", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_float(func, "max_dist", sqrt(FLT_MAX), 0.0, FLT_MAX, "", "", 0.0, FLT_MAX); + RNA_def_float(func, "max_dist", sqrt(FLT_MAX), 0.0, FLT_MAX, "", "", 0.0, FLT_MAX); /* return location and normal */ parm= RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "The location on the object closest to the point", -1e4, 1e4); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 662ce04552e..f4028e45e96 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -135,7 +135,9 @@ EnumPropertyItem image_type_items[] = { #endif {R_AVIJPEG, "AVI_JPEG", ICON_FILE_MOVIE, "AVI JPEG", "Output video in AVI JPEG format"}, {R_AVIRAW, "AVI_RAW", ICON_FILE_MOVIE, "AVI Raw", "Output video in AVI Raw format"}, +#ifdef WITH_FRAMESERVER {R_FRAMESERVER, "FRAMESERVER", ICON_FILE_SCRIPT, "Frame Server", "Output image to a frameserver"}, +#endif #ifdef WITH_FFMPEG {R_H264, "H264", ICON_FILE_MOVIE, "H.264", "Output video in H.264 format"}, {R_FFMPEG, "FFMPEG", ICON_FILE_MOVIE, "MPEG", "Output video in MPEG format"}, @@ -1176,9 +1178,9 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_icon(prop, ICON_RETOPO, 0); RNA_def_property_update(prop, NC_SCENE|ND_TOOLSETTINGS, NULL); /* header redraw */ - prop= RNA_def_property(srna, "use_snap_project_self", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "snap_flag", SCE_SNAP_PROJECT_NO_SELF); - RNA_def_property_ui_text(prop, "Project to Self", "Project into its self (editmode)"); + prop= RNA_def_property(srna, "use_snap_self", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "snap_flag", SCE_SNAP_NO_SELF); + RNA_def_property_ui_text(prop, "Project to Self", "Snap onto its self (editmode)"); RNA_def_property_ui_icon(prop, ICON_ORTHO, 0); RNA_def_property_update(prop, NC_SCENE|ND_TOOLSETTINGS, NULL); /* header redraw */ @@ -2813,7 +2815,7 @@ static void rna_def_scene_render_data(BlenderRNA *brna) prop= RNA_def_property(srna, "bake_margin", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "bake_filter"); - RNA_def_property_range(prop, 0, 32); + RNA_def_property_range(prop, 0, 64); RNA_def_property_ui_text(prop, "Margin", "Amount of pixels to extend the baked result with, as post process filter"); prop= RNA_def_property(srna, "bake_distance", PROP_FLOAT, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 31e1d73c8de..a046be59ab5 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1025,7 +1025,7 @@ static StructRNA *rna_Operator_register(Main *bmain, ReportList *reports, void * rna_Operator_unregister(bmain, ot->ext.srna); } - /* create a new menu type */ + /* create a new operator type */ dummyot.ext.srna= RNA_def_struct(&BLENDER_RNA, dummyot.idname, "Operator"); RNA_def_struct_flag(dummyot.ext.srna, STRUCT_NO_IDPROPERTIES); /* operator properties are registered separately */ dummyot.ext.data= data; diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h index 7454cfe78b3..b798b5e7003 100644 --- a/source/blender/python/mathutils/mathutils.h +++ b/source/blender/python/mathutils/mathutils.h @@ -108,4 +108,6 @@ int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index); int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix); int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix); +int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject *mat); + #endif /* MATHUTILS_H */ diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 76a0994c3aa..3953171f263 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -1612,8 +1612,20 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) } } else if(mat1) { + /*VEC * MATRIX */ + if(VectorObject_Check(m2)) { + VectorObject *vec2= (VectorObject *)m2; + float tvec[4]; + if(BaseMath_ReadCallback(vec2) == -1) + return NULL; + if(column_vector_multiplication(tvec, vec2, mat1) == -1) { + return NULL; + } + + return newVectorObject(tvec, vec2->size, Py_NEW, Py_TYPE(m2)); + } /*FLOAT/INT * MATRIX */ - if (((scalar= PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred())==0) { + else if (((scalar= PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred())==0) { return matrix_mul_float(mat1, scalar); } } diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 3b05b9a250b..2be258a1ef0 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -753,8 +753,30 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) return quat_mul_float(quat2, scalar); } } - else if (quat1) { /* QUAT*FLOAT */ - if((((scalar= PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred())==0)) { + else if (quat1) { + /* QUAT * VEC */ + if (VectorObject_Check(q2)) { + VectorObject *vec2 = (VectorObject *)q2; + float tvec[3]; + + if(vec2->size != 3) { + PyErr_SetString(PyExc_ValueError, + "Vector multiplication: " + "only 3D vector rotations (with quats) " + "currently supported"); + return NULL; + } + if(BaseMath_ReadCallback(vec2) == -1) { + return NULL; + } + + copy_v3_v3(tvec, vec2->vec); + mul_qt_v3(quat1->quat, tvec); + + return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(vec2)); + } + /* QUAT * FLOAT */ + else if((((scalar= PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred())==0)) { return quat_mul_float(quat1, scalar); } } diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index e2c958adaa5..a954c07c98d 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -37,6 +37,8 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +extern void PyC_LineSpit(void); + #define MAX_DIMENSIONS 4 /* Swizzle axes get packed into a single value that is used as a closure. Each @@ -1081,7 +1083,7 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2) * note: vector/matrix multiplication IS NOT COMMUTATIVE!!!! * note: assume read callbacks have been done first. */ -static int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec, MatrixObject * mat) +int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec, MatrixObject * mat) { float vec_cpy[MAX_DIMENSIONS]; double dot = 0.0f; @@ -1159,8 +1161,29 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) } else if (vec1) { if (MatrixObject_Check(v2)) { + extern void PyC_LineSpit(void); + /* VEC * MATRIX */ + /* this is deprecated!, use the reverse instead */ float tvec[MAX_DIMENSIONS]; + + +/* ------ to be removed ------*/ +#ifndef MATH_STANDALONE +#ifdef WITH_ASSERT_ABORT + PyErr_SetString(PyExc_ValueError, + "(Vector * Matrix) is now removed, reverse the " + "order (promoted to an Error for Debug builds)"); + return NULL; +#else + printf("Warning: (Vector * Matrix) is now deprecated, " + "reverse the multiplication order in the script.\n"); + PyC_LineSpit(); +#endif +#endif /* ifndef MATH_STANDALONE */ +/* ------ to be removed ------*/ + + if(BaseMath_ReadCallback((MatrixObject *)v2) == -1) return NULL; if(column_vector_multiplication(tvec, vec1, (MatrixObject*)v2) == -1) { @@ -1183,6 +1206,24 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) if(BaseMath_ReadCallback(quat2) == -1) { return NULL; } + + +/* ------ to be removed ------*/ +#ifndef MATH_STANDALONE +#ifdef WITH_ASSERT_ABORT + PyErr_SetString(PyExc_ValueError, + "(Vector * Quat) is now removed, reverse the " + "order (promoted to an Error for Debug builds)"); + return NULL; +#else + printf("Warning: (Vector * Quat) is now deprecated, " + "reverse the multiplication order in the script.\n"); + PyC_LineSpit(); +#endif +#endif /* ifndef MATH_STANDALONE */ +/* ------ to be removed ------*/ + + copy_v3_v3(tvec, vec1->vec); mul_qt_v3(quat2->quat, tvec); return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(vec1)); @@ -1226,6 +1267,24 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2) if(column_vector_multiplication(rvec, vec, (MatrixObject*)v2) == -1) return NULL; + +/* ------ to be removed ------*/ +#ifndef MATH_STANDALONE +#ifdef WITH_ASSERT_ABORT + PyErr_SetString(PyExc_ValueError, + "(Vector *= Matrix) is now removed, reverse the " + "order (promoted to an Error for Debug builds) " + "and uses the non in-place multiplication."); + return NULL; +#else + printf("Warning: (Vector *= Matrix) is now deprecated, " + "reverse the (non in-place) multiplication order in the script.\n"); + PyC_LineSpit(); +#endif +#endif /* ifndef MATH_STANDALONE */ +/* ------ to be removed ------*/ + + memcpy(vec->vec, rvec, sizeof(float) * vec->size); } else if (QuaternionObject_Check(v2)) { @@ -1242,6 +1301,25 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2) if(BaseMath_ReadCallback(quat2) == -1) { return NULL; } + + +/* ------ to be removed ------*/ +#ifndef MATH_STANDALONE +#ifdef WITH_ASSERT_ABORT + PyErr_SetString(PyExc_ValueError, + "(Vector *= Quat) is now removed, reverse the " + "order (promoted to an Error for Debug builds) " + "and uses the non in-place multiplication."); + return NULL; +#else + printf("Warning: (Vector *= Quat) is now deprecated, " + "reverse the (non in-place) multiplication order in the script.\n"); + PyC_LineSpit(); +#endif +#endif /* ifndef MATH_STANDALONE */ +/* ------ to be removed ------*/ + + mul_qt_v3(quat2->quat, vec->vec); } else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC *= FLOAT */ diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 583b792f240..b385b507707 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -3375,7 +3375,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) /* test for 100% transparant */ ok= 1; - if(ma->alpha==0.0f && ma->spectra==0.0f && ma->filter==0.0f && (ma->mode & MA_TRANSP)) { + if(ma->alpha==0.0f && ma->spectra==0.0f && ma->filter==0.0f && (ma->mode & MA_TRANSP) && (ma->mode & MA_RAYMIRROR)==0) { ok= 0; /* texture on transparency? */ for(a=0; amain= bmain; @@ -5778,6 +5778,14 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, if(re->r.mode & R_RAYTRACE) makeraytree(re); + /* point density texture */ + if(!re->test_break(re->tbh)) + make_pointdensities(re); + + /* voxel data texture */ + if(!re->test_break(re->tbh)) + make_voxeldata(re); + /* occlusion */ if((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh)) if(re->wrld.ao_gather_method == WO_AOGATHER_APPROX) diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 3aca334cffe..a7e19c8db4f 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2577,27 +2577,7 @@ void RE_bake_ibuf_filter(ImBuf *ibuf, char *mask, const int filter) /* Margin */ if(filter) { - char *temprect; - int i; - - /* extend the mask +2 pixels from the image, - * this is so colors dont blend in from outside */ - - for(i=0; i< filter; i++) - IMB_mask_filter_extend(mask, ibuf->x, ibuf->y); - - temprect = MEM_dupallocN(mask); - - /* expand twice to clear this many pixels, so they blend back in */ - IMB_mask_filter_extend(temprect, ibuf->x, ibuf->y); - IMB_mask_filter_extend(temprect, ibuf->x, ibuf->y); - - /* clear all pixels in the margin */ - IMB_mask_clear(ibuf, temprect, FILTER_MASK_MARGIN); - MEM_freeN(temprect); - - for(i= 0; i < filter; i++) - IMB_filter_extend(ibuf, mask); + IMB_filter_extend(ibuf, mask, filter); } /* if the bake results in new alpha then change the image setting */ diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 67294a8eb53..e6325e2101a 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -272,6 +272,7 @@ void WM_operator_py_idname(char *to, const char *from); /* *************** menu types ******************** */ struct MenuType *WM_menutype_find(const char *idname, int quiet); int WM_menutype_add(struct MenuType* mt); +int WM_menutype_contains(struct MenuType* mt); void WM_menutype_freelink(struct MenuType* mt); void WM_menutype_free(void); diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index bcd5cf38f88..a535c0bc1f8 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -175,6 +175,12 @@ int WM_menutype_add(MenuType* mt) return 1; } +/* inefficient but only used for tooltip code */ +int WM_menutype_contains(MenuType* mt) +{ + return (mt != NULL && BLI_findindex(&menutypes, mt) != -1); +} + void WM_menutype_freelink(MenuType* mt) { BLI_freelinkN(&menutypes, mt); -- cgit v1.2.3 From d55f6c64a24c9e8e46f2a7d33da17aff24ce6d1a Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Thu, 28 Jul 2011 13:44:36 +0000 Subject: speed button mapping to ndof sensitivity change operator. --- source/blender/windowmanager/intern/wm_operators.c | 47 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 44e42966c77..1b48e36d2b7 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -3432,7 +3432,34 @@ static void WM_OT_memory_statistics(wmOperatorType *ot) } /* ******************************************************* */ - + +static int wm_ndof_sensitivity_exec(bContext *UNUSED(C), wmOperator *op) +{ + float change = 0.1f; + int dir = 1; + if(RNA_boolean_get(op->ptr, "decrease")) + dir = -1; + if(RNA_boolean_get(op->ptr, "fast")) + change = 1.0f; + + + U.ndof_sensitivity += (dir * change); + printf("new sensitivity: %f\n", U.ndof_sensitivity); + return OPERATOR_FINISHED; +} + +static void WM_OT_ndof_sensitivity_change(wmOperatorType *ot) +{ + ot->name= "Change NDOF sensitivity"; + ot->idname= "WM_OT_ndof_sensitivity_change"; + ot->description="Change NDOF sensitivity"; + + ot->exec= wm_ndof_sensitivity_exec; + + RNA_def_boolean(ot->srna, "decrease", 1, "Decrease NDOF sensitivity", "If true then action decreases NDOF sensitivity instead of increasing"); + RNA_def_boolean(ot->srna, "fast", 0, "Fast NDOF sensitivity change", "If true then action change with factor 1.0, otherwise 0.1"); +} +/* ******************************************************* */ /* called on initialize WM_exit() */ void wm_operatortype_free(void) { @@ -3472,6 +3499,7 @@ void wm_operatortype_init(void) WM_operatortype_append(WM_OT_ndof_menu); WM_operatortype_append(WM_OT_call_menu); WM_operatortype_append(WM_OT_radial_control); + WM_operatortype_append(WM_OT_ndof_sensitivity_change); #if defined(WIN32) WM_operatortype_append(WM_OT_console_toggle); #endif @@ -3740,6 +3768,23 @@ void wm_window_keymap(wmKeyConfig *keyconf) kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F12KEY, KM_PRESS, KM_SHIFT, 0); RNA_string_set(kmi->ptr, "data_path", "area.type"); RNA_string_set(kmi->ptr, "value", "DOPESHEET_EDITOR"); + + /* ndof speed */ + kmi= WM_keymap_add_item(keymap, "WM_OT_ndof_sensitivity_change", NDOF_BUTTON_PLUS, KM_PRESS, 0, 0); + RNA_boolean_set(kmi->ptr, "decrease", FALSE); + RNA_boolean_set(kmi->ptr, "fast", FALSE); + + kmi= WM_keymap_add_item(keymap, "WM_OT_ndof_sensitivity_change", NDOF_BUTTON_MINUS, KM_PRESS, 0, 0); + RNA_boolean_set(kmi->ptr, "decrease", TRUE); + RNA_boolean_set(kmi->ptr, "fast", FALSE); + + kmi= WM_keymap_add_item(keymap, "WM_OT_ndof_sensitivity_change", NDOF_BUTTON_PLUS, KM_PRESS, KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "decrease", FALSE); + RNA_boolean_set(kmi->ptr, "fast", TRUE); + + kmi= WM_keymap_add_item(keymap, "WM_OT_ndof_sensitivity_change", NDOF_BUTTON_MINUS, KM_PRESS, KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "decrease", TRUE); + RNA_boolean_set(kmi->ptr, "fast", TRUE); gesture_circle_modal_keymap(keyconf); gesture_border_modal_keymap(keyconf); -- cgit v1.2.3 From b8dcf3a662f35fef388294c635386b952f6bf981 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 28 Jul 2011 14:28:27 +0000 Subject: Fix part of #27944: color managment discrepancy in GLSL materials with nodes. --- source/blender/gpu/intern/gpu_material.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 806c70d841f..274884000db 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1371,9 +1371,6 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) mat->obcolalpha = 1; GPU_link(mat, "shade_alpha_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined); } - - if(gpu_do_color_management(mat)) - GPU_link(mat, "linearrgb_to_srgb", shr->combined, &shr->combined); } static GPUNodeLink *GPU_blender_material(GPUMaterial *mat, Material *ma) @@ -1408,6 +1405,10 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma) GPU_material_output_link(mat, outlink); } + if(gpu_do_color_management(mat)) + if(mat->outlink) + GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); + /*if(!GPU_material_construct_end(mat)) { GPU_material_free(mat); mat= NULL; -- cgit v1.2.3 From 6d2754e07d0785e30c75cf6498b94f1fb5f54f46 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 28 Jul 2011 15:51:59 +0000 Subject: Fix #27719: custom RNA properties fail to update drivers. Hopefully this is not too slow, but now we do a dependency graph tag also for these in addition to regular ID properties, not sure how to get around it. --- source/blender/makesrna/intern/rna_access.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index dcf2400b9ba..e71be8c153e 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1364,13 +1364,13 @@ static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerR if(prop->noteflag) WM_main_add_notifier(prop->noteflag, ptr->id.data); } - else { + + if(!is_rna || (prop->flag & PROP_IDPROPERTY)) { /* WARNING! This is so property drivers update the display! * not especially nice */ DAG_id_tag_update(ptr->id.data, OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME); WM_main_add_notifier(NC_WINDOW, NULL); } - } /* must keep in sync with 'rna_property_update' -- cgit v1.2.3 From 26589497529ca3c8da85391d4976d286a371e258 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 29 Jul 2011 01:24:03 +0000 Subject: pep8 cleanup, also print message when attempting to run in animation player mode. --- source/blender/windowmanager/intern/wm_init_exit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index ed28696ef69..4c280fe4341 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -155,7 +155,8 @@ void WM_init(bContext *C, int argc, const char **argv) BPY_python_start(argc, argv); BPY_driver_reset(); - BPY_app_handlers_reset(); + BPY_app_handlers_reset(); /* causes addon callbacks to be freed [#28068], + * but this is actually what we want. */ BPY_modules_load_user(C); #else (void)argc; /* unused */ -- cgit v1.2.3 From fb738f4929e88b21ebcfb724ae3f460ef6e0f949 Mon Sep 17 00:00:00 2001 From: Lukas Toenne Date: Fri, 29 Jul 2011 07:14:03 +0000 Subject: When relinking node group outputs from sockets of different type, automatically change the output to the source type. Feature request by Daniel Salazar. --- source/blender/editors/space_node/node_edit.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 18d4d85e3ff..c719f749582 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -2216,6 +2216,12 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) /* we might need to remove a link */ if(in_out==SOCK_OUT) node_remove_extra_links(snode, link->tosock, link); + + /* when linking to group outputs, update the socket type */ + /* XXX this should all be part of a generic update system */ + if (!link->tonode) { + link->tosock->type = link->fromsock->type; + } } else if (outside_group_rect(snode) && (link->tonode || link->fromnode)) { /* automatically add new group socket */ -- cgit v1.2.3 From 24def76ac899e106b4a04364504ba0cbc100d7f7 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Fri, 29 Jul 2011 07:58:03 +0000 Subject: svn merge -r38753:38813 https://svn.blender.org/svnroot/bf-blender/trunk/blender . --- source/blender/blenkernel/intern/cdderivedmesh.c | 2 ++ source/blender/blenkernel/intern/customdata.c | 1 - source/blender/blenkernel/intern/material.c | 2 +- source/blender/blenkernel/intern/multires.c | 18 ++++++------ source/blender/collada/MaterialExporter.cpp | 32 ++++++++++++++++++--- source/blender/collada/MaterialExporter.h | 3 ++ source/blender/editors/interface/resources.c | 9 +++--- source/blender/editors/space_node/node_edit.c | 8 +++++- .../editors/space_sequencer/sequencer_add.c | 33 ++++++++++++++++++---- source/blender/editors/transform/transform_snap.c | 21 ++++++++------ source/blender/gpu/intern/gpu_material.c | 7 +++-- source/blender/makesdna/DNA_modifier_types.h | 1 + source/blender/makesrna/intern/rna_access.c | 4 +-- source/blender/makesrna/intern/rna_modifier.c | 5 ++++ source/blender/windowmanager/intern/wm_init_exit.c | 3 +- 15 files changed, 109 insertions(+), 40 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 3abfa05e1fd..662c872b7f1 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1287,6 +1287,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); offset += sizeof(float)*4; } + (void)offset; } curface++; if(mface->v4) { @@ -1327,6 +1328,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang); offset += sizeof(float)*4; } + (void)offset; } curface++; i++; diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 45faba8439c..8d19322c0db 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -466,7 +466,6 @@ static void layerInterp_mdisps(void **sources, float *UNUSED(weights), MDisps tris[2]; int vindex[4] = {0}; - S = 0; for(i = 0; i < 2; i++) for(y = 0; y < 4; y++) for(x = 0; x < 4; x++) diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 962c7fd5e86..3f01c55e935 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -550,7 +550,7 @@ Material *material_pop_id(ID *id, int index) Material **mat; if(index + 1 != (*totcol)) - memmove((*matar), (*matar) + 1, sizeof(void *) * ((*totcol) - (index + 1))); + memmove((*matar)+index, (*matar)+(index+1), sizeof(void *) * ((*totcol) - (index + 1))); (*totcol)--; diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index d833c184274..88a670ecb22 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -465,12 +465,13 @@ static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lv return multires_dm_create_from_derived(&mmd, 1, dm, ob, 0, 0); } -static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal) +static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal, int plain_uv) { SubsurfModifierData smd= {{NULL}}; smd.levels = smd.renderLevels = lvl; - smd.flags |= eSubsurfModifierFlag_SubsurfUv; + if(!plain_uv) + smd.flags |= eSubsurfModifierFlag_SubsurfUv; if(simple) smd.subdivType = ME_SIMPLE_SUBSURF; if(optimal) @@ -591,7 +592,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) /* subdivide the mesh to highest level without displacements */ cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - origdm = subsurf_dm_create_local(ob, cddm, totlvl, 0, 0); + origdm = subsurf_dm_create_local(ob, cddm, totlvl, 0, 0, mmd->flags & eMultiresModifierFlag_PlainUv); cddm->release(cddm); /* calc disps */ @@ -626,7 +627,7 @@ static void multires_subdivide(MultiresModifierData *mmd, Object *ob, int totlvl /* create subsurf DM from original mesh at high level */ cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0); + highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); /* create multires DM from original mesh at low level */ lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple); @@ -830,7 +831,7 @@ static void multiresModifier_update(DerivedMesh *dm) else cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple, 0); + highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); /* create multires DM from original mesh and displacements */ lowdm = multires_dm_create_local(ob, cddm, lvl, totlvl, mmd->simple); @@ -884,7 +885,7 @@ static void multiresModifier_update(DerivedMesh *dm) else cddm = CDDM_from_mesh(me, NULL); DM_set_only_copy(cddm, CD_MASK_BAREMESH); - subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple, 0); + subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); cddm->release(cddm); multiresModifier_disp_run(dm, me, 1, 0, subdm->getGridData(subdm), mmd->totlvl); @@ -927,7 +928,8 @@ DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int loca return dm; result = subsurf_dm_create_local(ob, dm, lvl, - mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges); + mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges, + mmd->flags & eMultiresModifierFlag_PlainUv); if(!local_mmd) { ccgdm = (CCGDerivedMesh*)result; @@ -1633,7 +1635,7 @@ static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3]) MEM_freeN(vertCos); /* scaled ccgDM for tangent space of object with applied scale */ - dm= subsurf_dm_create_local(ob, cddm, high_mmd.totlvl, high_mmd.simple, 0); + dm= subsurf_dm_create_local(ob, cddm, high_mmd.totlvl, high_mmd.simple, 0, mmd->flags & eMultiresModifierFlag_PlainUv); cddm->release(cddm); /*numGrids= dm->getNumGrids(dm);*/ /*UNUSED*/ diff --git a/source/blender/collada/MaterialExporter.cpp b/source/blender/collada/MaterialExporter.cpp index a44fa6802f2..9d29177578d 100644 --- a/source/blender/collada/MaterialExporter.cpp +++ b/source/blender/collada/MaterialExporter.cpp @@ -37,12 +37,36 @@ MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw): COLLADASW::Li void MaterialsExporter::exportMaterials(Scene *sce, bool export_selected) { - openLibrary(); + if(hasMaterials(sce)) { + openLibrary(); - MaterialFunctor mf; - mf.forEachMaterialInScene(sce, *this, export_selected); + MaterialFunctor mf; + mf.forEachMaterialInScene(sce, *this, export_selected); - closeLibrary(); + closeLibrary(); + } +} + + +bool MaterialsExporter::hasMaterials(Scene *sce) +{ + Base *base = (Base *)sce->base.first; + + while(base) { + Object *ob= base->object; + int a; + for(a = 0; a < ob->totcol; a++) + { + Material *ma = give_current_material(ob, a+1); + + // no material, but check all of the slots + if (!ma) continue; + + return true; + } + base= base->next; + } + return false; } void MaterialsExporter::operator()(Material *ma, Object *ob) diff --git a/source/blender/collada/MaterialExporter.h b/source/blender/collada/MaterialExporter.h index 0a7a276d857..c080e4b0596 100644 --- a/source/blender/collada/MaterialExporter.h +++ b/source/blender/collada/MaterialExporter.h @@ -51,6 +51,9 @@ public: MaterialsExporter(COLLADASW::StreamWriter *sw); void exportMaterials(Scene *sce, bool export_selected); void operator()(Material *ma, Object *ob); + +private: + bool hasMaterials(Scene *sce); }; // used in forEachMaterialInScene diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 5f405a5f51e..cdc839e084a 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1115,10 +1115,11 @@ void init_userdef_do_versions(void) } if(U.pad_rot_angle==0) U.pad_rot_angle= 15; - - if(U.flag & USER_CUSTOM_RANGE) - vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */ - + + /* signal for derivedmesh to use colorband */ + /* run incase this was on and is now off in the user prefs [#28096] */ + vDM_ColorBand_store((U.flag & USER_CUSTOM_RANGE) ? (&U.coba_weight):NULL); + if (bmain->versionfile <= 191) { strcpy(U.plugtexdir, U.textudir); strcpy(U.sounddir, "/"); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 4230a43d2ec..c719f749582 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -1101,7 +1101,7 @@ void NODE_OT_backimage_move(wmOperatorType *ot) ot->cancel= snode_bg_viewmove_cancel; /* flags */ - ot->flag= OPTYPE_BLOCKING; + ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER; } static int backimage_zoom(bContext *C, wmOperator *op) @@ -2216,6 +2216,12 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) /* we might need to remove a link */ if(in_out==SOCK_OUT) node_remove_extra_links(snode, link->tosock, link); + + /* when linking to group outputs, update the socket type */ + /* XXX this should all be part of a generic update system */ + if (!link->tonode) { + link->tosock->type = link->fromsock->type; + } } else if (outside_group_rect(snode) && (link->tonode || link->fromnode)) { /* automatically add new group socket */ diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 36e334990cb..b105b2507ab 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -101,6 +101,8 @@ static void sequencer_generic_props__internal(wmOperatorType *ot, int flag) RNA_def_boolean(ot->srna, "replace_sel", 1, "Replace Selection", "replace the current selection"); + RNA_def_boolean(ot->srna, "overlap", 0, "Allow Overlap", "Don't correct overlap on new sequence strips"); + if(flag & SEQPROP_FILES) RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", ""); } @@ -250,7 +252,11 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op) seq_active_set(scene, seq); seq->flag |= SELECT; } - + + if(RNA_boolean_get(op->ptr, "overlap") == FALSE) { + if(seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + } + WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); return OPERATOR_FINISHED; @@ -303,8 +309,9 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad Scene *scene= CTX_data_scene(C); /* only for sound */ Editing *ed= seq_give_editing(scene, TRUE); SeqLoadInfo seq_load; - /* Sequence *seq; */ /* UNUSED */ + Sequence *seq; int tot_files; + const short overlap= RNA_boolean_get(op->ptr, "overlap"); seq_load_operator_info(&seq_load, op); @@ -324,13 +331,21 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad RNA_string_get(&itemptr, "name", file_only); BLI_join_dirfile(seq_load.path, sizeof(seq_load.path), dir_only, file_only); - /* seq= */ seq_load_func(C, ed->seqbasep, &seq_load); + seq= seq_load_func(C, ed->seqbasep, &seq_load); + + if(overlap == FALSE) { + if(seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + } } RNA_END; } else { /* single file */ - /* seq= */ seq_load_func(C, ed->seqbasep, &seq_load); + seq= seq_load_func(C, ed->seqbasep, &seq_load); + + if(overlap == FALSE) { + if(seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + } } if (seq_load.tot_success==0) { @@ -506,7 +521,11 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) /* last active name */ strncpy(ed->act_imagedir, strip->dir, FILE_MAXDIR-1); - + + if(RNA_boolean_get(op->ptr, "overlap") == FALSE) { + if(seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + } + WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); return OPERATOR_FINISHED; @@ -656,7 +675,9 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) } } - if(seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if(RNA_boolean_get(op->ptr, "overlap") == FALSE) { + if(seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + } update_changed_seq_and_deps(scene, seq, 1, 1); /* runs calc_sequence */ diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 933d90ebbf2..ca89670dedb 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -467,14 +467,17 @@ void initSnapping(TransInfo *t, wmOperator *op) /* use scene defaults only when transform is modal */ else if (t->flag & T_MODAL) { - if (ts->snap_flag & SCE_SNAP) { - t->modifiers |= MOD_SNAP; - } + if(ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE)) + { + if (ts->snap_flag & SCE_SNAP) { + t->modifiers |= MOD_SNAP; + } - t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) == SCE_SNAP_ROTATE); - t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); - t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) == SCE_SNAP_NO_SELF); - t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); + t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) == SCE_SNAP_ROTATE); + t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); + t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) == SCE_SNAP_NO_SELF); + t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); + } } t->tsnap.target = snap_target; @@ -1944,9 +1947,9 @@ static void applyGrid(TransInfo *t, float *val, int max_index, float fac[3], Gea int i; float asp[3] = {1.0f, 1.0f, 1.0f}; // TODO: Remove hard coded limit here (3) - if(max_index > 3) { + if(max_index > 2) { printf("applyGrid: invalid index %d, clamping\n", max_index); - max_index= 3; + max_index= 2; } // Early bailing out if no need to snap diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 806c70d841f..274884000db 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1371,9 +1371,6 @@ void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr) mat->obcolalpha = 1; GPU_link(mat, "shade_alpha_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined); } - - if(gpu_do_color_management(mat)) - GPU_link(mat, "linearrgb_to_srgb", shr->combined, &shr->combined); } static GPUNodeLink *GPU_blender_material(GPUMaterial *mat, Material *ma) @@ -1408,6 +1405,10 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma) GPU_material_output_link(mat, outlink); } + if(gpu_do_color_management(mat)) + if(mat->outlink) + GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); + /*if(!GPU_material_construct_end(mat)) { GPU_material_free(mat); mat= NULL; diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index d2d8e014015..3787675f339 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -624,6 +624,7 @@ typedef struct MultiresModifierData { typedef enum { eMultiresModifierFlag_ControlEdges = (1<<0), + eMultiresModifierFlag_PlainUv = (1<<1), } MultiresModifierFlag; typedef struct FluidsimModifierData { diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index dcf2400b9ba..e71be8c153e 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1364,13 +1364,13 @@ static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerR if(prop->noteflag) WM_main_add_notifier(prop->noteflag, ptr->id.data); } - else { + + if(!is_rna || (prop->flag & PROP_IDPROPERTY)) { /* WARNING! This is so property drivers update the display! * not especially nice */ DAG_id_tag_update(ptr->id.data, OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME); WM_main_add_notifier(NC_WINDOW, NULL); } - } /* must keep in sync with 'rna_property_update' diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index d2c1b862fee..ba655915fb6 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -805,6 +805,11 @@ static void rna_def_modifier_multires(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flags", eMultiresModifierFlag_ControlEdges); RNA_def_property_ui_text(prop, "Optimal Display", "Skip drawing/rendering of interior subdivided edges"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop= RNA_def_property(srna, "use_subsurf_uv", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "flags", eMultiresModifierFlag_PlainUv); + RNA_def_property_ui_text(prop, "Subdivide UVs", "Use subsurf to subdivide UVs"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); } static void rna_def_modifier_lattice(BlenderRNA *brna) diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 7dd865984b3..e22829577f4 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -155,7 +155,8 @@ void WM_init(bContext *C, int argc, const char **argv) BPY_python_start(argc, argv); BPY_driver_reset(); - BPY_app_handlers_reset(); + BPY_app_handlers_reset(); /* causes addon callbacks to be freed [#28068], + * but this is actually what we want. */ BPY_modules_load_user(C); #else (void)argc; /* unused */ -- cgit v1.2.3 From 99997ccd181a6fcae5288fbd67a8eb32c71e9e3e Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Fri, 29 Jul 2011 20:46:30 +0000 Subject: Fix for [#28117] Diffuse reflection IPO curve not imported correctly from 2.49b files --- source/blender/blenkernel/intern/ipo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 4f921f005f4..2ae6f533bd4 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -518,7 +518,7 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index) return "alpha"; case MA_REF: - return "diffuse_reflection"; + return "diffuse_intensity"; case MA_EMIT: return "emit"; -- cgit v1.2.3 From 6a27da310c61b3372d565060506221a5afb9fe43 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Fri, 29 Jul 2011 20:59:46 +0000 Subject: While looking at the bug report, found some more issues... This is the result of RNA renaming at it's glance. ;-) --- source/blender/blenkernel/intern/ipo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 2ae6f533bd4..104ce2b3b32 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -527,7 +527,7 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index) return "ambient"; case MA_SPEC: - return "specular_reflection"; + return "specular_intensity"; case MA_HARD: return "specular_hardness"; @@ -551,13 +551,13 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index) return "raytrace_mirror.fresnel"; case MA_FRESMIRI: - return "raytrace_mirror.fresnel_fac"; + return "raytrace_mirror.fresnel_factor"; case MA_FRESTRA: return "raytrace_transparency.fresnel"; case MA_FRESTRAI: - return "raytrace_transparency.fresnel_fac"; + return "raytrace_transparency.fresnel_factor"; case MA_ADD: return "halo.add"; -- cgit v1.2.3 From aec91c0cf530d637a15c95cf1e4d0e27a7660a4c Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Fri, 29 Jul 2011 21:07:51 +0000 Subject: ndof sensitivity operator follows power curve and respects min/max --- source/blender/windowmanager/intern/wm_operators.c | 37 +++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 1b48e36d2b7..d813fd913ab 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -3435,16 +3435,36 @@ static void WM_OT_memory_statistics(wmOperatorType *ot) static int wm_ndof_sensitivity_exec(bContext *UNUSED(C), wmOperator *op) { - float change = 0.1f; - int dir = 1; - if(RNA_boolean_get(op->ptr, "decrease")) - dir = -1; + const float min = 0.25f, max = 4.f; // TODO: get these from RNA property + float change; + float sensitivity = U.ndof_sensitivity; + if(RNA_boolean_get(op->ptr, "fast")) - change = 1.0f; + change = 0.5f; // 50% change + else + change = 0.1f; // 10% + if(RNA_boolean_get(op->ptr, "decrease")) + { + sensitivity -= sensitivity * change; + if (sensitivity < min) + sensitivity = min; + } + else + { + sensitivity += sensitivity * change; + if (sensitivity > max) + sensitivity = max; + } + + if (sensitivity != U.ndof_sensitivity) + { + U.ndof_sensitivity = sensitivity; + printf("new sensitivity: %f\n", U.ndof_sensitivity); + } + else + printf("same sensitivity: %f\n", U.ndof_sensitivity); - U.ndof_sensitivity += (dir * change); - printf("new sensitivity: %f\n", U.ndof_sensitivity); return OPERATOR_FINISHED; } @@ -3457,8 +3477,9 @@ static void WM_OT_ndof_sensitivity_change(wmOperatorType *ot) ot->exec= wm_ndof_sensitivity_exec; RNA_def_boolean(ot->srna, "decrease", 1, "Decrease NDOF sensitivity", "If true then action decreases NDOF sensitivity instead of increasing"); - RNA_def_boolean(ot->srna, "fast", 0, "Fast NDOF sensitivity change", "If true then action change with factor 1.0, otherwise 0.1"); + RNA_def_boolean(ot->srna, "fast", 0, "Fast NDOF sensitivity change", "If true then sensitivity changes 50%, otherwise 10%"); } + /* ******************************************************* */ /* called on initialize WM_exit() */ void wm_operatortype_free(void) -- cgit v1.2.3 From 632f59c7bce051f359e57bf872fb624cb6643d87 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 30 Jul 2011 05:23:10 +0000 Subject: improved visual rotation guide --- source/blender/editors/space_view3d/view3d_draw.c | 51 +++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 2b863bf794c..6e3f6549ba3 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -681,7 +681,7 @@ static void draw_rotation_guide(RegionView3D *rv3d) float o[3]; // center of rotation float end[3]; // endpoints for drawing - float color[4] = {1,1,0,1}; // bright yellow so it stands out during development + float color[4] = {0.f ,0.4235f, 1.f, 1.f}; // bright blue so it matches device LEDs negate_v3_v3(o, rv3d->ofs); @@ -699,7 +699,7 @@ static void draw_rotation_guide(RegionView3D *rv3d) mul_v3_v3fl(scaled_axis, rv3d->rot_axis, scale); glBegin(GL_LINE_STRIP); - color[3] = 0; // more transparent toward the ends + color[3] = 0.f; // more transparent toward the ends glColor4fv(color); add_v3_v3v3(end, o, scaled_axis); glVertex3fv(end); @@ -711,16 +711,52 @@ static void draw_rotation_guide(RegionView3D *rv3d) glColor4fv(color); glVertex3fv(o); - color[3] = 0; + color[3] = 0.f; glColor4fv(color); sub_v3_v3v3(end, o, scaled_axis); glVertex3fv(end); glEnd(); - color[3] = 1; // solid dot + // -- draw ring around rotation center -- + { + #define ROT_AXIS_DETAIL 13 + const float s = 0.05f * scale; + const float step = 2.f * M_PI / ROT_AXIS_DETAIL; + float angle; + int i; + + float q[4]; // rotate ring so it's perpendicular to axis + const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f; + if (!upright) + { + const float up[3] = {0.f, 0.f, 1.f}; + float vis_angle, vis_axis[3]; + + cross_v3_v3v3(vis_axis, up, rv3d->rot_axis); + vis_angle = acosf(dot_v3v3(up, rv3d->rot_axis)); + axis_angle_to_quat(q, vis_axis, vis_angle); + } + + color[3] = 0.25f; // somewhat faint + glColor4fv(color); + glBegin(GL_LINE_LOOP); + for (i = 0, angle = 0.f; i < ROT_AXIS_DETAIL; ++i, angle += step) + { + float p[3] = { s * cosf(angle), s * sinf(angle), 0.f }; + + if (!upright) + mul_qt_v3(q, p); + + add_v3_v3(p, o); + glVertex3fv(p); + } + glEnd(); + } + + color[3] = 1.f; // solid dot } else - color[3] = 0.5; // see-through dot + color[3] = 0.5f; // see-through dot // -- draw rotation center -- glColor4fv(color); @@ -2680,10 +2716,9 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) BDR_drawSketch(C); } -//#if 0 // not yet... - if (U.ndof_flag & NDOF_SHOW_GUIDE) + if ((U.ndof_flag & NDOF_SHOW_GUIDE) && (rv3d->viewlock != RV3D_LOCKED) && (rv3d->persp != RV3D_CAMOB)) + // TODO: draw something else (but not this) during fly mode draw_rotation_guide(rv3d); -//#endif ED_region_pixelspace(ar); -- cgit v1.2.3 From f66ec41b6a3b74f079c19494357c268e1ab39e85 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 30 Jul 2011 09:24:10 +0000 Subject: quiet some compiler warnings & fix possible (but unlikely) crash. also added GPLv2+ header to resources.c. --- source/blender/blenlib/intern/BLI_args.c | 6 ++++-- source/blender/editors/curve/editcurve.c | 15 ++++++++------ source/blender/editors/interface/interface_anim.c | 24 +++++++++++++++++++++++ source/blender/editors/interface/resources.c | 7 ++++--- source/blender/editors/object/object_relations.c | 6 +++--- 5 files changed, 44 insertions(+), 14 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index 7bc93a3d3a0..5f31565d65b 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -290,8 +290,10 @@ void BLI_argsParse(struct bArgs *ba, int pass, BA_ArgCallback default_cb, void * } i += retval; } else if (retval == -1){ - if (a->key->pass != -1) - ba->passes[i] = pass; + if (a) { + if (a->key->pass != -1) + ba->passes[i] = pass; + } break; } } diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 06d88b16fa8..8b9477adf92 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -6544,12 +6544,15 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newob) BLI_assert(!"invalid nurbs type"); return NULL; } - - /* always do: */ - nu->flag |= CU_SMOOTH; - - test2DNurb(nu); - + + BLI_assert(nu != NULL); + + if(nu) { /* should always be set */ + nu->flag |= CU_SMOOTH; + + test2DNurb(nu); + } + return nu; } diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 75e7ee701a2..03003173e20 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -1,3 +1,27 @@ +/* + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): + * + * ***** END GPL LICENSE BLOCK ***** + */ + /** \file blender/editors/interface/interface_anim.c * \ingroup edinterface */ diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 56ef5e9e8cc..2b4003c7af0 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1,6 +1,3 @@ -/** \file blender/editors/interface/resources.c - * \ingroup edinterface - */ /* * $Id$ * @@ -33,6 +30,10 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ +/** \file blender/editors/interface/resources.c + * \ingroup edinterface + */ + #include #include #include diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index f21241b6e7a..0fb7cf8b640 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1096,7 +1096,7 @@ static int move_to_layer_exec(bContext *C, wmOperator *op) Scene *scene= CTX_data_scene(C); View3D *v3d= CTX_wm_view3d(C); unsigned int lay, local; - int islamp= 0; + /* int islamp= 0; */ /* UNUSED */ lay= move_to_layer_init(C, op); lay &= 0xFFFFFF; @@ -1112,7 +1112,7 @@ static int move_to_layer_exec(bContext *C, wmOperator *op) base->object->lay= lay; base->object->flag &= ~SELECT; base->flag &= ~SELECT; - if(base->object->type==OB_LAMP) islamp= 1; + /* if(base->object->type==OB_LAMP) islamp= 1; */ } CTX_DATA_END; } @@ -1124,7 +1124,7 @@ static int move_to_layer_exec(bContext *C, wmOperator *op) local= base->lay & 0xFF000000; base->lay= lay + local; base->object->lay= lay; - if(base->object->type==OB_LAMP) islamp= 1; + /* if(base->object->type==OB_LAMP) islamp= 1; */ } CTX_DATA_END; } -- cgit v1.2.3 From d163ce55953bd04b42c2c79f6729e47228c01a9a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 30 Jul 2011 13:18:04 +0000 Subject: bpy fix for crash/assert on running dir() on a non collection property + some other minor corrections. --- source/blender/editors/transform/transform.c | 2 +- source/blender/makesrna/intern/rna_wm_api.c | 2 +- source/blender/python/intern/bpy_rna.c | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index eea77e36f7c..59e9e681e2b 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -4659,7 +4659,7 @@ static int createSlideVerts(TransInfo *t) #define EDGE_SLIDE_MIN 30 if (len_squared_v2v2(start, end) < (EDGE_SLIDE_MIN * EDGE_SLIDE_MIN)) { if(ABS(start[0]-end[0]) + ABS(start[1]-end[1]) < 4.0f) { - /* even more exceptional case, points are ontop of eachother */ + /* even more exceptional case, points are ontop of each other */ end[0]= start[0]; end[1]= start[1] + EDGE_SLIDE_MIN; } diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index e250cc84aa3..d44b68950f7 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -205,7 +205,7 @@ void RNA_api_operator(StructRNA *srna) /* check */ func= RNA_def_function(srna, "check", NULL); - RNA_def_function_ui_description(func, "Check the operator settings."); + RNA_def_function_ui_description(func, "Check the operator settings, return True to signal a change to redraw."); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); parm= RNA_def_pointer(func, "context", "Context", "", ""); RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 6e1b9c807f3..2dcfe3731c7 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -3262,11 +3262,15 @@ static PyObject *pyrna_prop_dir(BPy_PropertyRNA *self) * */ ret= PyList_New(0); - if (!BPy_PropertyRNA_CheckExact(self)) + if (!BPy_PropertyRNA_CheckExact(self)) { pyrna_dir_members_py(ret, (PyObject *)self); + } - if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) - pyrna_dir_members_rna(ret, &r_ptr); + if(RNA_property_type(self->prop) == PROP_COLLECTION) { + if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { + pyrna_dir_members_rna(ret, &r_ptr); + } + } return ret; } -- cgit v1.2.3 From 805a169f7065222ce047d950c55b585b36bc4b24 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Sat, 30 Jul 2011 15:45:27 +0000 Subject: Bugfix #28121 Linked Library objects or object->data should not allow to go to sculptmode. Also cleaned up mode menu with invalid entries then. --- source/blender/editors/screen/screen_ops.c | 2 +- source/blender/editors/space_view3d/view3d_header.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 68326edfb11..1410331700f 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -301,7 +301,7 @@ int ED_operator_object_active_editable(bContext *C) int ED_operator_object_active_editable_mesh(bContext *C) { Object *ob = ED_object_active_context(C); - return ((ob != NULL) && !(ob->id.lib) && !(ob->restrictflag & OB_RESTRICT_VIEW) && ob->type == OB_MESH); + return ((ob != NULL) && !(ob->id.lib) && !(ob->restrictflag & OB_RESTRICT_VIEW) && ob->type == OB_MESH && !(((ID *)ob->data)->lib)); } int ED_operator_object_active_editable_font(bContext *C) diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index ae80a554e08..5b95ae63e56 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -280,7 +280,8 @@ static char *view3d_modeselect_pup(Scene *scene) str += sprintf(str, formatstr, "Object Mode", OB_MODE_OBJECT, ICON_OBJECT_DATA); - if(ob==NULL) return string; + if(ob==NULL || ob->data==NULL) return string; + if(ob->id.lib || ((ID *)ob->data)->lib) return string; /* if active object is editable */ if ( ((ob->type == OB_MESH) -- cgit v1.2.3 From 601eb684208eb3f5e8025b81be30817b87daeb98 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 31 Jul 2011 02:03:21 +0000 Subject: Added SkinNode DNA and customdata. --- source/blender/blenkernel/intern/customdata.c | 21 ++++++++++++++++----- source/blender/makesdna/DNA_customdata_types.h | 4 +++- source/blender/makesdna/DNA_meshdata_types.h | 5 +++++ 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 8d19322c0db..1f18c78d070 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -805,7 +805,15 @@ static void layerDefault_mcol(void *data, int count) mcol[i] = default_mcol; } - +static void layerDefault_skin(void *data, int count) +{ + SkinNode *n = data; + int i; + + for(i = 0; i < count; i++) { + n[i].radius = 1; + } +} static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { {sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL}, @@ -843,7 +851,8 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { layerSwap_mcol, layerDefault_mcol}, {sizeof(MCol)*4, "MCol", 4, "TexturedCol", NULL, NULL, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol}, - {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL} + {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, + {sizeof(SkinNode), "SkinNode", 1, "Skin", NULL, NULL, NULL, NULL, layerDefault_skin} }; static const char *LAYERTYPENAMES[CD_NUMTYPES] = { @@ -851,7 +860,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = { /* 5-9 */ "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFlags", /* 10-14 */ "CDMFloatProperty", "CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco", /* 15-19 */ "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent", "CDMDisps", - /* 20-23 */"CDWeightMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco" + /* 20-24 */ "CDWeightMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco", "CDSkinNode" }; const CustomDataMask CD_MASK_BAREMESH = @@ -859,10 +868,12 @@ const CustomDataMask CD_MASK_BAREMESH = const CustomDataMask CD_MASK_MESH = CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | - CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS; + CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | + CD_MASK_SKIN_NODE; const CustomDataMask CD_MASK_EDITMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | - CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS; + CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | + CD_MASK_SKIN_NODE; const CustomDataMask CD_MASK_DERIVEDMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO | diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index cdfcf465c6c..061e9460956 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -92,7 +92,8 @@ typedef struct CustomData { #define CD_ID_MCOL 21 #define CD_TEXTURE_MCOL 22 #define CD_CLOTH_ORCO 23 -#define CD_NUMTYPES 24 +#define CD_SKIN_NODE 24 +#define CD_NUMTYPES 25 /* Bits for CustomDataMask */ #define CD_MASK_MVERT (1 << CD_MVERT) @@ -117,6 +118,7 @@ typedef struct CustomData { #define CD_MASK_MDISPS (1 << CD_MDISPS) #define CD_MASK_WEIGHT_MCOL (1 << CD_WEIGHT_MCOL) #define CD_MASK_CLOTH_ORCO (1 << CD_CLOTH_ORCO) +#define CD_MASK_SKIN_NODE (1 << CD_SKIN_NODE) /* CustomData.flag */ diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index e3510b3a25a..a71c4970eb5 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -184,6 +184,11 @@ typedef struct PartialVisibility { unsigned int totface, totedge, totvert, pad; } PartialVisibility; +typedef struct SkinNode { + float radius; + int pad; +} SkinNode; + /* mvert->flag (1=SELECT) */ #define ME_SPHERETEST 2 #define ME_VERT_TMP_TAG 4 -- cgit v1.2.3 From cae05598b1d10a70a0e37f28b6e49a5b5715a30f Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 31 Jul 2011 02:03:28 +0000 Subject: Added DNA and RNA for skin modifier, stubbed in skin modifier functions --- source/blender/makesdna/DNA_modifier_types.h | 14 +++++ source/blender/makesrna/intern/rna_modifier.c | 15 +++++ source/blender/modifiers/CMakeLists.txt | 1 + source/blender/modifiers/MOD_modifiertypes.h | 1 + source/blender/modifiers/intern/MOD_skin.c | 88 +++++++++++++++++++++++++++ source/blender/modifiers/intern/MOD_util.c | 1 + 6 files changed, 120 insertions(+) create mode 100644 source/blender/modifiers/intern/MOD_skin.c (limited to 'source/blender') diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 3787675f339..483bd339b3d 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -71,6 +71,7 @@ typedef enum ModifierType { eModifierType_Solidify, eModifierType_Screw, eModifierType_Warp, + eModifierType_Skin, NUM_MODIFIER_TYPES } ModifierType; @@ -785,4 +786,17 @@ typedef enum { /* PROP_RANDOM not used */ } WarpModifierFalloff; +typedef enum SkinModifierFlags { + MOD_SKIN_DRAW_SKIN = (1<<0), + MOD_SKIN_DRAW_NODES = (1<<1), +} SkinModifierFlags; + +typedef struct SkinModifierData { + ModifierData modifier; + float threshold; + int subdiv; + int flag; + int pad; +} SkinModifierData; + #endif diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index ba655915fb6..b4a4c593ba9 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -68,6 +68,7 @@ EnumPropertyItem modifier_type_items[] ={ {eModifierType_Solidify, "SOLIDIFY", ICON_MOD_SOLIDIFY, "Solidify", ""}, {eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""}, {eModifierType_UVProject, "UV_PROJECT", ICON_MOD_UVPROJECT, "UV Project", ""}, + {eModifierType_Skin, "SKIN", ICON_MOD_ARMATURE, "Skin", ""}, {0, "", 0, "Deform", ""}, {eModifierType_Armature, "ARMATURE", ICON_MOD_ARMATURE, "Armature", ""}, {eModifierType_Cast, "CAST", ICON_MOD_CAST, "Cast", ""}, @@ -183,6 +184,8 @@ static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr) return &RNA_ScrewModifier; case eModifierType_Warp: return &RNA_WarpModifier; + case eModifierType_Skin: + return &RNA_SkinModifier; default: return &RNA_Modifier; } @@ -2412,6 +2415,17 @@ static void rna_def_modifier_screw(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update");*/ } +static void rna_def_modifier_skin(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "SkinModifier", "Modifier"); + RNA_def_struct_ui_text(srna, "Skin Modifier", "Generate Skin"); + RNA_def_struct_sdna(srna, "SkinModifierData"); + RNA_def_struct_ui_icon(srna, ICON_MOD_ARMATURE); +} + void RNA_def_modifier(BlenderRNA *brna) { StructRNA *srna; @@ -2509,6 +2523,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_smoke(brna); rna_def_modifier_solidify(brna); rna_def_modifier_screw(brna); + rna_def_modifier_skin(brna); } #endif diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index d1f153265ac..7db03f48631 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -70,6 +70,7 @@ set(SRC intern/MOD_shapekey.c intern/MOD_shrinkwrap.c intern/MOD_simpledeform.c + intern/MOD_skin.c intern/MOD_smoke.c intern/MOD_smooth.c intern/MOD_softbody.c diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h index 4e44a226c64..329037ee210 100644 --- a/source/blender/modifiers/MOD_modifiertypes.h +++ b/source/blender/modifiers/MOD_modifiertypes.h @@ -72,6 +72,7 @@ extern ModifierTypeInfo modifierType_ShapeKey; extern ModifierTypeInfo modifierType_Solidify; extern ModifierTypeInfo modifierType_Screw; extern ModifierTypeInfo modifierType_Warp; +extern ModifierTypeInfo modifierType_Skin; /* MOD_util.c */ void modifier_type_init(ModifierTypeInfo *types[]); diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c new file mode 100644 index 00000000000..adc47f32c9c --- /dev/null +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -0,0 +1,88 @@ +/* +* $Id$ +* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* ***** END GPL LICENSE BLOCK ***** +* +*/ + +/** \file blender/modifiers/intern/MOD_skin.c + * \ingroup modifiers + */ + + +#include + +#include "BKE_cdderivedmesh.h" +#include "BKE_modifier.h" + +#include "DNA_mesh_types.h" +#include "DNA_object_types.h" + +#include "MOD_util.h" + +static void initData(ModifierData *md) +{ + SkinModifierData *smd = (SkinModifierData*)md; + + smd->threshold = 0; + smd->subdiv = 1; + smd->flag = MOD_SKIN_DRAW_NODES; +} + +static void copyData(ModifierData *md, ModifierData *target) +{ + SkinModifierData *smd = (SkinModifierData*) md; + SkinModifierData *tsmd = (SkinModifierData*) target; + + tsmd->threshold = smd->threshold; + tsmd->subdiv = smd->subdiv; + tsmd->flag = smd->flag; +} + +static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm, + int useRenderParams, int isFinalCalc) +{ + return dm; +} + + +ModifierTypeInfo modifierType_Skin = { + /* name */ "Skin", + /* structName */ "SkinModifierData", + /* structSize */ sizeof(SkinModifierData), + /* type */ eModifierTypeType_Constructive, + /* flags */ eModifierTypeFlag_AcceptsMesh, + + /* copyData */ copyData, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ applyModifier, + /* applyModifierEM */ NULL, + /* initData */ initData, + /* requiredDataMask */ NULL, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, +}; diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index e9b835eab81..e823a347ced 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -295,5 +295,6 @@ void modifier_type_init(ModifierTypeInfo *types[]) INIT_TYPE(Solidify); INIT_TYPE(Screw); INIT_TYPE(Warp); + INIT_TYPE(Skin); #undef INIT_TYPE } -- cgit v1.2.3 From cff57b14a122a7925d8fb6aeb0ecd53984fa0c58 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 31 Jul 2011 02:03:39 +0000 Subject: Imported bsphere.c, mostly ifdef'd out for now --- source/blender/blenkernel/CMakeLists.txt | 1 + source/blender/blenkernel/intern/bsphere.c | 1178 +++++++++++++++++++++++++ source/blender/blenkernel/intern/customdata.c | 2 +- 3 files changed, 1180 insertions(+), 1 deletion(-) create mode 100644 source/blender/blenkernel/intern/bsphere.c (limited to 'source/blender') diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index defcef58463..e549a205325 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -81,6 +81,7 @@ set(SRC intern/boids.c intern/booleanops_mesh.c intern/brush.c + intern/bsphere.c intern/bullet.c intern/bvhutils.c intern/cdderivedmesh.c diff --git a/source/blender/blenkernel/intern/bsphere.c b/source/blender/blenkernel/intern/bsphere.c new file mode 100644 index 00000000000..d8a75f62172 --- /dev/null +++ b/source/blender/blenkernel/intern/bsphere.c @@ -0,0 +1,1178 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2011 by Nicholas Bishop + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_modifier_types.h" + +#include "BLI_utildefines.h" +#include "BLI_heap.h" +#include "BLI_ghash.h" +#include "BLI_listbase.h" +#include "BLI_math.h" + +#include "BKE_cdderivedmesh.h" +#include "BKE_DerivedMesh.h" +#include "BKE_global.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_subsurf.h" + +#include + +typedef struct Tri { + struct Tri *next, *prev; + unsigned int v[3]; + float no[3]; + float area; + int marked; +} Tri; + +typedef struct Edge { + struct Edge *next, *prev; + unsigned int v[2]; + Tri *tri[2]; +} Edge; + +/* note: a `frame' is four vertices (contiguous within the MVert + array), stored simply as the index of the first vertex */ + +static void create_frame(float frame[4][3], const float co[3], float radius, + const float mat[3][3], float x_offset) +{ + float rx[3], ry[3], rz[3]; + int i; + + mul_v3_v3fl(ry, mat[1], radius); + mul_v3_v3fl(rz, mat[2], radius); + + add_v3_v3v3(frame[3], co, ry); + add_v3_v3v3(frame[3], frame[3], rz); + + sub_v3_v3v3(frame[2], co, ry); + add_v3_v3v3(frame[2], frame[2], rz); + + sub_v3_v3v3(frame[1], co, ry); + sub_v3_v3v3(frame[1], frame[1], rz); + + add_v3_v3v3(frame[0], co, ry); + sub_v3_v3v3(frame[0], frame[0], rz); + + mul_v3_v3fl(rx, mat[0], x_offset); + for(i = 0; i < 4; i++) + add_v3_v3v3(frame[i], frame[i], rx); +} + +static void create_mid_frame(float frame[4][3], + const float co1[3], const float co2[3], + const SkinNode *n1, const SkinNode *n2, + const float mat[3][3]) +{ + create_frame(frame, co1, (n1->radius + n2->radius) / 2, + mat, len_v3v3(co1, co2) / 2); +} + +static void add_face(MFace *mface, int *totface, + int v1, int v2, int v3, int v4) +{ + MFace *f; + + f = &mface[*totface]; + f->v1 = v1; + f->v2 = v2; + f->v3 = v3; + f->v4 = v4 == -1 ? 0 : v4; + if(!v4) { + f->v1 = v3; + f->v2 = v4; + f->v3 = v1; + f->v4 = v2; + } + (*totface)++; +} + +static void connect_frames(MFace *mface, int *totface, int frame1, int frame2) +{ + int i; + + for(i = 0; i < 4; i++) { + add_face(mface, totface, + frame2 + i, + frame2 + (i+1) % 4, + frame1 + (i+1) % 4, + frame1 + i); + } +} + +static Tri *add_triangle(ListBase *tris, MVert *mvert, int v1, int v2, int v3) +{ + Tri *t; + + t = MEM_callocN(sizeof(Tri), "add_triangle.tri"); + t->v[0] = v1; + t->v[1] = v2; + t->v[2] = v3; + BLI_addtail(tris, t); + + normal_tri_v3(t->no, mvert[t->v[0]].co, mvert[t->v[1]].co, mvert[t->v[2]].co); + t->area = area_tri_v3(mvert[t->v[0]].co, mvert[t->v[1]].co, mvert[t->v[2]].co); + + return t; +} + +static int point_tri_side(const Tri *t, MVert *mvert, int v) +{ + float p[3], d; + sub_v3_v3v3(p, mvert[v].co, mvert[t->v[0]].co); + d = dot_v3v3(t->no, p); + if(d < 0) return -1; + else if(d > 0) return 1; + else return 0; +} + +static int mark_v_outside_tris(ListBase *tris, MVert *mvert, int v) +{ + Tri *t; + int outside = 0; + + /* probably there's a much better way to do this */ + for(t = tris->first; t; t = t->next) { + if((t->marked = point_tri_side(t, mvert, v) > 0)) + outside = 1; + } + return outside; +} + +static int edge_match(int e1_0, int e1_1, const unsigned int e2[2]) +{ + /* XXX: maybe isn't necesseary to check both directions? */ + return (e1_0 == e2[0] && e1_1 == e2[1]) || + (e1_0 == e2[1] && e1_1 == e2[0]); +} + +/* returns true if the edge (e1, e2) is already in edges; that edge is + deleted here as well. if not found just returns 0 */ +static int check_for_dup(ListBase *edges, unsigned int e1, unsigned int e2) +{ + Edge *e, *next; + + for(e = edges->first; e; e = next) { + next = e->next; + + if(edge_match(e1, e2, e->v)) { + /* remove the interior edge */ + BLI_freelinkN(edges, e); + return 1; + } + } + + return 0; +} + +static void expand_boundary_edges(ListBase *edges, Tri *t) +{ + Edge *new; + int i; + + /* insert each triangle edge into the boundary list; if any of + its edges are already in there, remove the edge entirely */ + for(i = 0; i < 3; i++) { + if(!check_for_dup(edges, t->v[i], t->v[(i+1)%3])) { + new = MEM_callocN(sizeof(Edge), "Edge"); + new->v[0] = t->v[i]; + new->v[1] = t->v[(i+1)%3]; + BLI_addtail(edges, new); + } + } +} + +static int tri_matches_frame(const Tri *t, int frame) +{ + int i, j, match = 0; + for(i = 0; i < 3; i++) { + for(j = 0; j < 4; j++) { + if(t->v[i] == frame + j) { + match++; + if(match >= 3) + return 1; + } + } + } + return 0; +} + +static void quad_from_tris(const Edge *e, int ndx[4]) +{ + int i, j, opp = -1; + + /* find what the second tri has that the first doesn't */ + for(i = 0; i < 3; i++) { + if(e->tri[1]->v[i] != e->tri[0]->v[0] && + e->tri[1]->v[i] != e->tri[0]->v[1] && + e->tri[1]->v[i] != e->tri[0]->v[2]) { + opp = e->tri[1]->v[i]; + break; + } + } + assert(opp != -1); + + for(i = 0, j = 0; i < 3; i++, j++) { + ndx[j] = e->tri[0]->v[i]; + /* when the triangle edge cuts across our quad-to-be, + throw in the second triangle's vertex */ + if((e->tri[0]->v[i] == e->v[0] || e->tri[0]->v[i] == e->v[1]) && + (e->tri[0]->v[(i+1)%3] == e->v[0] || e->tri[0]->v[(i+1)%3] == e->v[1])) { + j++; + ndx[j] = opp; + } + } +} + +static void add_quad_from_tris(MFace *mface, int *totface, const Edge *e) +{ + int ndx[4]; + + quad_from_tris(e, ndx); + + add_face(mface, totface, ndx[0], ndx[1], ndx[2], ndx[3]); +} + +static GHash *calc_edges(ListBase *tris) +{ + GHash *adj; + ListBase *edges; + Edge *e; + Tri *t; + int i, e1, e2; + + /* XXX: vertex range might be a little funky? so using a + hash here */ + adj = BLI_ghash_new(BLI_ghashutil_inthash, + BLI_ghashutil_intcmp, + "calc_edges adj"); + + for(t = tris->first; t; t = t->next) { + for(i = 0; i < 3; i++) { + e1 = t->v[i]; + e2 = t->v[(i+1)%3]; + assert(e1 != e2); + if(e1 > e2) + SWAP(int, e1, e2); + + edges = BLI_ghash_lookup(adj, SET_INT_IN_POINTER(e1)); + if(!edges) { + edges = MEM_callocN(sizeof(ListBase), + "calc_edges ListBase"); + BLI_ghash_insert(adj, SET_INT_IN_POINTER(e1), edges); + } + + /* find the edge in the adjacency list */ + for(e = edges->first; e; e = e->next) { + assert(e->v[0] == e1); + if(e->v[1] == e2) + break; + } + + /* if not found, create the edge */ + if(!e) { + e = MEM_callocN(sizeof(Edge), "calc_edges Edge"); + e->v[0] = e1; + e->v[1] = e2; + BLI_addtail(edges, e); + } + + /* should never be more than two faces + attached to an edge here */ + assert(!e->tri[0] || !e->tri[1]); + + if(!e->tri[0]) + e->tri[0] = t; + else if(!e->tri[1]) + e->tri[1] = t; + } + } + + return adj; +} + +static int is_quad_symmetric(const MVert *mvert, const Edge *e) +{ + int ndx[4]; + float a[3]; + + quad_from_tris(e, ndx); + + copy_v3_v3(a, mvert[ndx[0]].co); + a[0] = -a[0]; + + if(len_v3v3(a, mvert[ndx[1]].co) < FLT_EPSILON) { + copy_v3_v3(a, mvert[ndx[2]].co); + a[0] = -a[0]; + if(len_v3v3(a, mvert[ndx[3]].co) < FLT_EPSILON) + return 1; + } + else if(len_v3v3(a, mvert[ndx[3]].co) < FLT_EPSILON) { + copy_v3_v3(a, mvert[ndx[2]].co); + a[0] = -a[0]; + if(len_v3v3(a, mvert[ndx[1]].co) < FLT_EPSILON) + return 1; + } + + return 0; +} + +static void output_hull(const MVert *mvert, MFace *mface, int *totface, ListBase *tris) +{ + Heap *heap; + GHash *adj; + GHashIterator *iter; + ListBase *edges; + Edge *e; + Tri *t; + float score; + + heap = BLI_heap_new(); + adj = calc_edges(tris); + + /* unmark all triangles */ + for(t = tris->first; t; t = t->next) + t->marked = 0; + + /* build heap */ + iter = BLI_ghashIterator_new(adj); + while(!BLI_ghashIterator_isDone(iter)) { + edges = BLI_ghashIterator_getValue(iter); + for(e = edges->first; e; e = e->next) { + /* only care if the edge is used by more than + one triangle */ + if(e->tri[0] && e->tri[1]) { + score = (e->tri[0]->area + e->tri[1]->area) * + dot_v3v3(e->tri[0]->no, e->tri[1]->no); + + /* increase score if the triangles + form a symmetric quad */ + if(is_quad_symmetric(mvert, e)) + score *= 10; + + BLI_heap_insert(heap, -score, e); + } + } + + BLI_ghashIterator_step(iter); + } + BLI_ghashIterator_free(iter); + + while(!BLI_heap_empty(heap)) { + e = BLI_heap_popmin(heap); + + /* if both triangles still free, outupt as a quad */ + if(!e->tri[0]->marked && !e->tri[1]->marked) { + add_quad_from_tris(mface, totface, e); + e->tri[0]->marked = 1; + e->tri[1]->marked = 1; + } + } + + /* free edge list */ + iter = BLI_ghashIterator_new(adj); + while(!BLI_ghashIterator_isDone(iter)) { + edges = BLI_ghashIterator_getValue(iter); + BLI_freelistN(edges); + MEM_freeN(edges); + BLI_ghashIterator_step(iter); + } + BLI_ghashIterator_free(iter); + BLI_ghash_free(adj, NULL, NULL); + BLI_heap_free(heap, NULL); + + /* write out any remaining triangles */ + for(t = tris->first; t; t = t->next) { + if(!t->marked) + add_face(mface, totface, t->v[0], t->v[1], t->v[2], -1); + } +} + +/* for vertex `v', find which triangles must be deleted to extend the + hull; find the boundary edges of that hole so that it can be filled + with connections to the new vertex, and update the `tri' list to + delete the marked triangles */ +static void add_point(ListBase *tris, MVert *mvert, int v) +{ + ListBase edges = {NULL, NULL}; + Tri *t, *next; + Edge *e; + + for(t = tris->first; t; t = next) { + next = t->next; + + /* check if triangle is `visible' to v */ + if(t->marked) { + expand_boundary_edges(&edges, t); + /* remove the triangle */ + BLI_freelinkN(tris, t); + } + } + + /* fill hole boundary with triangles to new point */ + for(e = edges.first; e; e = e->next) + add_triangle(tris, mvert, e->v[0], e->v[1], v); + BLI_freelistN(&edges); +} + +static void build_hull(MFace *mface, int *totface, + MVert *mvert, int *frames, int totframe) +{ + ListBase tris = {NULL, NULL}; + Tri *t, *next; + int i, j; + + /* use first frame to make initial degenerate pyramid */ + add_triangle(&tris, mvert, frames[0], frames[0] + 1, frames[0] + 2); + add_triangle(&tris, mvert, frames[0] + 1, frames[0], frames[0] + 3); + add_triangle(&tris, mvert, frames[0] + 2, frames[0] + 1, frames[0] + 3); + add_triangle(&tris, mvert, frames[0], frames[0] + 2, frames[0] + 3); + + for(i = 1; i < totframe; i++) { + for(j = 0; j < 4; j++) { + int v = frames[i] + j; + + /* ignore point already inside hull */ + if(mark_v_outside_tris(&tris, mvert, v)) { + /* expand hull and delete interior triangles */ + add_point(&tris, mvert, v); + } + } + } + + /* remove triangles that would fill the original frames */ + for(t = tris.first; t; t = next) { + next = t->next; + + for(i = 0; i < totframe; i++) { + if(tri_matches_frame(t, frames[i])) { + BLI_freelinkN(&tris, t); + break; + } + } + } + + output_hull(mvert, mface, totface, &tris); + + BLI_freelistN(&tris); +} + +/* test: build hull on origdm */ +#if 0 +static DerivedMesh *test_hull(DerivedMesh *origdm) +{ + DerivedMesh *dm; + MVert *mvert, *origmvert; + MFace *mface; + int *frames; + int totvert = 0, totface = 0, totframe, i; + + /* TODO */ + totface = 2000; + totvert = origdm->getNumVerts(origdm); + dm = CDDM_new(totvert, 0, totface); + + mvert = CDDM_get_verts(dm); + mface = CDDM_get_faces(dm); + + origmvert = CDDM_get_verts(origdm); + for(i = 0; i < totvert; i++) + mvert[i] = origmvert[i]; + + assert(totvert % 4 == 0); + totframe = totvert / 4; + + frames = MEM_callocN(sizeof(int) * totframe, "frames"); + for(i = 0; i < totframe; i++) + frames[i] = i*4; + + totface = 0; + build_hull(mface, &totface, mvert, frames, totframe); + + CDDM_calc_edges(dm); + //CDDM_calc_normals(dm); + + MEM_freeN(frames); + + return dm; +} +#endif + +/* TODO */ +static void calc_edge_mat(float mat[3][3], const float a[3], const float b[3]) +{ + float Z[3] = {0, 0, 1}; + float dot; + + /* x = edge direction */ + sub_v3_v3v3(mat[0], b, a); + normalize_v3(mat[0]); + + dot = dot_v3v3(mat[0], Z); + if(dot > -1 + FLT_EPSILON && dot < 1 - FLT_EPSILON) { + /* y = Z cross x */ + cross_v3_v3v3(mat[1], Z, mat[0]); + normalize_v3(mat[1]); + + /* z = x cross y */ + cross_v3_v3v3(mat[2], mat[0], mat[1]); + normalize_v3(mat[2]); + } + else { + mat[1][0] = 1; + mat[1][1] = 0; + mat[1][2] = 0; + mat[2][0] = 0; + mat[2][1] = 1; + mat[2][2] = 0; + } +} + +/* BMesh paper */ +#if 0 +static float calc_R_sub_i_squared(const BSphereNode *n) +{ + const float alpha = 1.5; + //const float alpha = 1; + const float R_sub_i = n->size[0] * alpha; + return R_sub_i * R_sub_i; +} + +/* equation (2) */ +static float calc_r_squared(const float v[3], const BSphereNode *n) +{ + return len_squared_v3v3(v, n->co); +} + +/* equation (1) */ +static float calc_f_sub_i(const float v[3], const BSphereNode *n) +{ + float r_squared; + float R_sub_i_squared; + + r_squared = calc_r_squared(v, n); + R_sub_i_squared = calc_R_sub_i_squared(n); + + if(r_squared <= R_sub_i_squared) + return powf(1.0f - (r_squared / R_sub_i_squared), 2); + else + return 0; +} + +/* equation (3) */ +static float calc_I(const float x[3], float T, const ListBase *base) +{ + BSphereNode *n; + float a = -T; + + for(n = base->first; n; n = n->next) { + a += calc_I(x, 0, &n->children); + a += calc_f_sub_i(x, n); + } + + //printf("calc_I: %f, %f\n", -T, a); + + return a; +} + +/* kinda my own guess here */ +static void calc_gradient(float g[3], const float x[3], const ListBase *base) +{ + BSphereNode *n; + + for(n = base->first; n; n = n->next) { + float R_sub_i_squared = calc_R_sub_i_squared(n); + float dist = len_v3v3(x, n->co); + float f = calc_f_sub_i(x, n); + float d = 1.0f / R_sub_i_squared; + float tmp[3]; + + /* XXX: other possibilities... */ + if(f > 0) { + sub_v3_v3v3(tmp, x, n->co); + mul_v3_fl(tmp, -4*d * (1 - d * dist)); + + /* not sure if I'm doing this right; intent is + to flip direction when x is `beneath' the + level set */ + if(len_v3v3(x, n->co) > n->size[0]) + negate_v3(tmp); + + add_v3_v3(g, tmp); + } + + calc_gradient(g, x, &n->children); + } +} + +/* equation (5) */ +static float calc_F(const float x[3], const float K[2], float T, const ListBase *base) +{ + float f_of_K; + float I_target; + + /* TODO */ + f_of_K = 1.0f / (1 + fabs(K[0]) + fabs(K[1])); + //f_of_K = 1; + + /* TODO */ + I_target = 0; + + return (calc_I(x, T, base) - I_target) /*TODO: * f_of_K*/; +} + +static float smallest_radius(const ListBase *base) +{ + BSphereNode *n; + float s = FLT_MAX, t; + + for(n = base->first; n; n = n->next) { + if(n->size[0] < s) + s = n->size[0]; + if((t = smallest_radius(&n->children)) < s) + s = t; + } + + return s; +} + +/* equation (7) */ +static float calc_delta_t(float F_max, float k, const ListBase *base, int print) +{ + float min_r_sub_i; + float step; + + min_r_sub_i = smallest_radius(base); + step = min_r_sub_i / powf(2, k); + + if(print) { + printf("min_r: %f, 2^k=%f, step=%f\n", min_r_sub_i, powf(2, k), step); + } + + return step / F_max; +} + +/* equation (6) */ +static float evolve_x(float x[3], const float K[2], float T, + int k, const ListBase *base, int i, float F_max) +{ + float tmp[3], no[3]; + float F, dt; + + F = calc_F(x, K, T, base); + + if(F < FLT_EPSILON) { + //printf("stability reached for ndx=%d\n", i); + return 0; + } + + /* TODO ;-) */ + if(F > F_max) + F_max = F; + + dt = calc_delta_t(F_max, k, base, 0); + + dt = F / 2; + + if(i == 0) + ;//printf("F=%.3f, dt=%.3f\n", F, calc_delta_t(F_max, k, base, 1)); + + zero_v3(no); + calc_gradient(no, x, base); + normalize_v3(no); + negate_v3(no); + + mul_v3_v3fl(tmp, no, F * dt); + add_v3_v3(x, tmp); + + return F_max; +} + +static void bsphere_evolve(MVert *mvert, int totvert, const ListBase *base, + float T, int steps, float subdiv_level) +{ + int i, s; + + for(i = 0; i < totvert; i++) { + float F_max = 0; + /* TODO: for now just doing a constant number of steps */ + for(s = 0; s < steps; s++) { + /* TODO */ + float K[2] = {0, 0}; + + F_max = evolve_x(mvert[i].co, K, T, subdiv_level, base, i, F_max); + } + } +} +#endif + +typedef enum { + START_CAP = 1, + END_CAP = 2, + NODE_BISECT = 4, + CHILD_EDGE_BISECT = 8, + + IN_FRAME = 16, + OUT_FRAME = 32, +} FrameFlag; + +typedef struct { + int totframe; + int outbase; + FrameFlag flag; + float co[0][4][3]; +} Frames; + +static Frames *frames_create(FrameFlag flag) +{ + Frames *frames; + int totframe; + totframe = (!!(flag & START_CAP) + !!(flag & END_CAP) + + !!(flag & NODE_BISECT) + !!(flag & CHILD_EDGE_BISECT)); + assert(totframe); + frames = MEM_callocN(sizeof(Frames) + sizeof(float)*totframe*4*3, + "frames_create.frames"); + frames->totframe = totframe; + frames->flag = flag; + assert((flag & (END_CAP|CHILD_EDGE_BISECT)) != (END_CAP|CHILD_EDGE_BISECT)); + return frames; +} + +static int frame_offset(Frames *frames, FrameFlag flag) +{ + int n = 0; + + assert(flag == IN_FRAME || flag == OUT_FRAME || + !(flag & (IN_FRAME|OUT_FRAME))); + + if(flag == IN_FRAME) + return 0; + else if(flag == OUT_FRAME) + return frames->totframe-1; + + assert((flag & frames->flag) == flag); + + if(flag == START_CAP) return n; + if(frames->flag & START_CAP) n++; + + if(flag == NODE_BISECT) return n; + if(frames->flag & NODE_BISECT) n++; + + if(flag == END_CAP) return n; + if(frames->flag & END_CAP) n++; + + if(flag == CHILD_EDGE_BISECT) return n; + if(frames->flag & CHILD_EDGE_BISECT) n++; + + assert(!"bad frame offset flag"); +} + +static int frame_base(Frames *frames, FrameFlag flag) +{ + return frames->outbase + 4*frame_offset(frames, flag); +} + +static void *frame_co(Frames *frames, FrameFlag flag) +{ + return frames->co[frame_offset(frames, flag)]; +} + +static int frames_totvert(Frames *frames) +{ + return frames->totframe*4; +} + +#if 0 +static int bsphere_build_frames(BSphereNode *n, GHash *ghash, + float (*parent_mat)[3], FrameFlag flag); + +/* builds the `cap' of polygons for the end of a BSphere chain */ +static int bsphere_end_node_frames(BSphereNode *n, + GHash *ghash, + float parent_mat[3][3], + FrameFlag flag) +{ + Frames *frames; + float rad; + + assert(flag == 0 || flag == START_CAP); + frames = frames_create(NODE_BISECT|END_CAP|flag, n, ghash); + + /* TODO */ + rad = n->size[0]; + + if(flag & START_CAP) + create_frame(frame_co(frames, START_CAP), n, parent_mat, -rad, rad); + + /* frame to bisect the node */ + create_frame(frame_co(frames, NODE_BISECT), n, parent_mat, 0, rad); + + /* frame to cap end node */ + create_frame(frame_co(frames, END_CAP), n, parent_mat, rad, rad); + + return frames_totvert(frames); +} + +static int bsphere_connection_node_frames(BSphereNode *n, + GHash *ghash, + float parent_mat[3][3], + FrameFlag flag) +{ + Frames *frames; + BSphereNode *child; + float childmat[3][3], nodemat[3][3], axis[3], angle, rad, child_rad; + int totvert; + + assert(flag == 0 || flag == START_CAP); + + child = n->children.first; + + /* if child is not a branch node, bisect the child edge */ + if(BLI_countlist(&child->children) <= 1) + flag |= CHILD_EDGE_BISECT; + + frames = frames_create(NODE_BISECT|flag, n, ghash); + totvert = frames_totvert(frames); + + /* TODO */ + rad = n->size[0]; + child_rad = child->size[0]; + + /* build matrix to give to child */ + sub_v3_v3v3(childmat[0], child->co, n->co); + normalize_v3(childmat[0]); + angle = angle_normalized_v3v3(parent_mat[0], childmat[0]); + cross_v3_v3v3(axis, parent_mat[0], childmat[0]); + normalize_v3(axis); + rotate_normalized_v3_v3v3fl(childmat[1], parent_mat[1], axis, angle); + rotate_normalized_v3_v3v3fl(childmat[2], parent_mat[2], axis, angle); + + /* build child */ + totvert += bsphere_build_frames(child, ghash, childmat, 0); + + /* frame that bisects the node */ + angle /= 2; + copy_v3_v3(nodemat[0], parent_mat[0]); + rotate_normalized_v3_v3v3fl(nodemat[1], parent_mat[1], axis, angle); + rotate_normalized_v3_v3v3fl(nodemat[2], parent_mat[2], axis, angle); + create_frame(frame_co(frames, NODE_BISECT), n, nodemat, 0, rad); + + if(flag & START_CAP) + create_frame(frame_co(frames, START_CAP), n, nodemat, -rad, rad); + + if(flag & CHILD_EDGE_BISECT) + create_mid_frame(frame_co(frames, CHILD_EDGE_BISECT), n, child, childmat); + + return totvert; +} + +static int bsphere_branch_node_frames(BSphereNode *n, GHash *ghash) +{ + BSphereNode *child; + int totvert = 0; + float rad; + + rad = n->size[0]; + + /* build children */ + for(child = n->children.first; child; child = child->next) { + float childmat[3][3]; + + calc_edge_mat(childmat, n->co, child->co); + + totvert += bsphere_build_frames(child, ghash, childmat, 0); + } + + /* TODO: for now, builds no frames of its own */ + + return totvert; +} + +static int bsphere_build_frames(BSphereNode *n, GHash *ghash, + float parent_mat[3][3], FrameFlag flag) +{ + BSphereNode *child; + + child = n->children.first; + + if(!child) + return bsphere_end_node_frames(n, ghash, parent_mat, flag); + else if(!child->next) + return bsphere_connection_node_frames(n, ghash, parent_mat, flag); + else + return bsphere_branch_node_frames(n, ghash); +} + +static GHash *bsphere_frames(BSphere *bs, int *totvert) +{ + GHash *ghash; + BSphereNode *n, *child; + + ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, + "bsphere_frames.ghash"); + (*totvert) = 0; + + for(n = bs->rootbase.first; n; n = n->next) { + float mat[3][3]; + + child = n->children.first; + if(!child || (child && child->next)) { + set_v3(mat[0], 0, 0, 1); + set_v3(mat[1], 1, 0, 0); + set_v3(mat[2], 0, 1, 0); + } + else if(!child->next) { + calc_edge_mat(mat, n->co, child->co); + } + + (*totvert) += bsphere_build_frames(n, ghash, mat, START_CAP); + } + + return ghash; +} + +static void output_frames(Frames *frames, MVert *mvert, MFace *mface, + int *totvert, int *totface) +{ + int b, i, j; + + frames->outbase = (*totvert); + for(i = 0; i < frames->totframe; i++) { + for(j = 0; j < 4; j++) { + copy_v3_v3(mvert[(*totvert)].co, frames->co[i][j]); + (*totvert)++; + } + + if(i > 0) { + connect_frames(mface, totface, + frames->outbase + 4*(i-1), + frames->outbase + 4*i); + } + } + + if(frames->flag & START_CAP) { + b = frame_base(frames, START_CAP); + add_face(mface, totface, b, b+1, b+2, b+3); + } + if(frames->flag & END_CAP) { + b = frame_base(frames, END_CAP); + add_face(mface, totface, b+3, b+2, b+1, b+0); + } +} + +static void bsphere_build_skin(BSphereNode *parent, ListBase *base, + GHash *frames, MVert *mvert, + MFace *mface, int *totvert, int *totface) +{ + BSphereNode *n, *child; + Frames *node_frames, *child_frames, *parent_frames; + int *hull_frames, totchild, i; + + for(n = base->first; n; n = n->next) { + if((node_frames = BLI_ghash_lookup(frames, n))) + output_frames(node_frames, mvert, mface, totvert, totface); + + bsphere_build_skin(n, &n->children, frames, mvert, mface, totvert, totface); + + child = n->children.first; + if(child && !child->next) { + child_frames = BLI_ghash_lookup(frames, child); + if(child_frames) { + connect_frames(mface, totface, + frame_base(node_frames, OUT_FRAME), + frame_base(child_frames, IN_FRAME)); + } + } + else if(child && child->next) { + totchild = BLI_countlist(&n->children); + hull_frames = MEM_callocN(sizeof(int) * (1+totchild), + "bsphere_build_skin.hull_frames"); + i = 0; + for(child = n->children.first; child; child = child->next) { + child_frames = BLI_ghash_lookup(frames, child); + assert(child_frames); + hull_frames[i++] = frame_base(child_frames, IN_FRAME); + } + parent_frames = BLI_ghash_lookup(frames, parent); + if(parent_frames) + hull_frames[i] = frame_base(parent_frames, OUT_FRAME); + else + totchild--; + build_hull(mface, totface, mvert, hull_frames, totchild+1); + MEM_freeN(hull_frames); + } + } +} + +static DerivedMesh *bsphere_base_skin(BSphere *bs) +{ + DerivedMesh *dm; + GHash *ghash; + MVert *mvert; + MFace *mface; + int totvert, totface = 0; + + /* no nodes, nothing to do */ + if(!bs->rootbase.first) + return NULL; + + /* could probably do all this in one fell [recursive] swoop + using some tricksies and clevers, but multiple passes is + easier :) */ + ghash = bsphere_frames(bs, &totvert); + + totface = totvert * 1.5; + /* XXX: sizes OK? */ + dm = CDDM_new(totvert, 0, totface); + + mvert = CDDM_get_verts(dm); + mface = CDDM_get_faces(dm); + + totvert = totface = 0; + bsphere_build_skin(NULL, &bs->rootbase, ghash, mvert, mface, &totvert, &totface); + BLI_ghash_free(ghash, NULL, (void*)MEM_freeN); + + CDDM_lower_num_verts(dm, totvert); + CDDM_lower_num_faces(dm, totface); + + CDDM_calc_edges(dm); + CDDM_calc_normals(dm); + + return dm; +} + +/* generate random points (just for testing) */ +DerivedMesh *bsphere_random_points(BSphere *UNUSED(bs)) +{ + DerivedMesh *dm; + MVert *mvert; + const int totvert = 1;//50000; + int i; + + dm = CDDM_new(totvert, 0, 0); + + mvert = CDDM_get_verts(dm); + + srand(1); + for(i = 0; i < totvert; i++) { + mvert[i].co[0] = rand() / (float)RAND_MAX - 0.5; + mvert[i].co[1] = rand() / (float)RAND_MAX - 0.5; + mvert[i].co[2] = rand() / (float)RAND_MAX - 0.5; + } + + return dm; +} + +DerivedMesh *bsphere_test_surface(BSphere *bs, DerivedMesh *input) +{ + DerivedMesh *dm; + MVert *mvert; + + if(!input) + return NULL; + + dm = CDDM_copy(input); + mvert = CDDM_get_verts(dm); + bsphere_evolve(mvert, input->getNumVerts(input), &bs->rootbase, + bs->skin_threshold, bs->evolve, 2); + + return dm; +} + +DerivedMesh *bsphere_test_gradient(BSphere *bs, DerivedMesh *input) +{ + DerivedMesh *dm; + MVert *mvert; + MEdge *medge; + int totvert; + int i; + + if(!input) + return NULL; + + totvert = input->getNumVerts(input); + dm = CDDM_new(totvert*2, totvert, 0); + + mvert = CDDM_get_verts(dm); + medge = CDDM_get_edges(dm); + + memcpy(mvert, CDDM_get_verts(input), sizeof(MVert) * totvert); + + for(i = 0; i < totvert; i++) { + const float *b = mvert[i].co; + float *g = mvert[totvert+i].co; + float K[2] = {0, 0}; + + zero_v3(g); + calc_gradient(g, b, &bs->rootbase); + normalize_v3(g); + + mul_v3_fl(g, -calc_F(b, K, bs->skin_threshold, &bs->rootbase)); + add_v3_v3(g, b); + + medge[i].v1 = i; + medge[i].v2 = totvert+i; + } + + return dm; +} + +DerivedMesh *bsphere_get_skin_dm(BSphere *bs) +{ + DerivedMesh *dm, *subdm; + + dm = bsphere_base_skin(bs); + + /* subdivide once */ + if(dm && bs->subdiv_level > 0) { + SubsurfModifierData smd; + + memset(&smd, 0, sizeof(smd)); + smd.subdivType = ME_CC_SUBSURF; + smd.levels = bs->subdiv_level; + subdm = subsurf_make_derived_from_derived(dm, &smd, 0, 0, 0, 0); + dm->release(dm); + /* for convenience, convert back to cddm (could use ccgdm + later for better performance though? (TODO)) */ + dm = CDDM_copy(subdm); + subdm->release(subdm); + + bsphere_evolve(CDDM_get_verts(dm), dm->getNumVerts(dm), &bs->rootbase, + bs->skin_threshold, bs->evolve, bs->subdiv_level); + } + + return dm; +} +#endif diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 1f18c78d070..b9d6badfbe9 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -811,7 +811,7 @@ static void layerDefault_skin(void *data, int count) int i; for(i = 0; i < count; i++) { - n[i].radius = 1; + n[i].radius = 0.25; } } -- cgit v1.2.3 From 6c3bb8b9030a86388d42a752b0cba2826630c4c6 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 31 Jul 2011 02:03:48 +0000 Subject: EditMesh-based skin node drawing --- source/blender/blenkernel/CMakeLists.txt | 1 - source/blender/blenkernel/intern/bsphere.c | 1178 ------------------------ source/blender/blenkernel/intern/customdata.c | 21 +- source/blender/makesdna/DNA_customdata_types.h | 4 +- source/blender/makesdna/DNA_meshdata_types.h | 5 - source/blender/makesdna/DNA_modifier_types.h | 14 - source/blender/makesrna/intern/rna_modifier.c | 15 - source/blender/modifiers/CMakeLists.txt | 1 - source/blender/modifiers/MOD_modifiertypes.h | 1 - source/blender/modifiers/intern/MOD_skin.c | 88 -- source/blender/modifiers/intern/MOD_util.c | 1 - 11 files changed, 6 insertions(+), 1323 deletions(-) delete mode 100644 source/blender/blenkernel/intern/bsphere.c delete mode 100644 source/blender/modifiers/intern/MOD_skin.c (limited to 'source/blender') diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index e549a205325..defcef58463 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -81,7 +81,6 @@ set(SRC intern/boids.c intern/booleanops_mesh.c intern/brush.c - intern/bsphere.c intern/bullet.c intern/bvhutils.c intern/cdderivedmesh.c diff --git a/source/blender/blenkernel/intern/bsphere.c b/source/blender/blenkernel/intern/bsphere.c deleted file mode 100644 index d8a75f62172..00000000000 --- a/source/blender/blenkernel/intern/bsphere.c +++ /dev/null @@ -1,1178 +0,0 @@ -/* - * $Id$ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2011 by Nicholas Bishop - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "MEM_guardedalloc.h" - -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" -#include "DNA_modifier_types.h" - -#include "BLI_utildefines.h" -#include "BLI_heap.h" -#include "BLI_ghash.h" -#include "BLI_listbase.h" -#include "BLI_math.h" - -#include "BKE_cdderivedmesh.h" -#include "BKE_DerivedMesh.h" -#include "BKE_global.h" -#include "BKE_library.h" -#include "BKE_main.h" -#include "BKE_subsurf.h" - -#include - -typedef struct Tri { - struct Tri *next, *prev; - unsigned int v[3]; - float no[3]; - float area; - int marked; -} Tri; - -typedef struct Edge { - struct Edge *next, *prev; - unsigned int v[2]; - Tri *tri[2]; -} Edge; - -/* note: a `frame' is four vertices (contiguous within the MVert - array), stored simply as the index of the first vertex */ - -static void create_frame(float frame[4][3], const float co[3], float radius, - const float mat[3][3], float x_offset) -{ - float rx[3], ry[3], rz[3]; - int i; - - mul_v3_v3fl(ry, mat[1], radius); - mul_v3_v3fl(rz, mat[2], radius); - - add_v3_v3v3(frame[3], co, ry); - add_v3_v3v3(frame[3], frame[3], rz); - - sub_v3_v3v3(frame[2], co, ry); - add_v3_v3v3(frame[2], frame[2], rz); - - sub_v3_v3v3(frame[1], co, ry); - sub_v3_v3v3(frame[1], frame[1], rz); - - add_v3_v3v3(frame[0], co, ry); - sub_v3_v3v3(frame[0], frame[0], rz); - - mul_v3_v3fl(rx, mat[0], x_offset); - for(i = 0; i < 4; i++) - add_v3_v3v3(frame[i], frame[i], rx); -} - -static void create_mid_frame(float frame[4][3], - const float co1[3], const float co2[3], - const SkinNode *n1, const SkinNode *n2, - const float mat[3][3]) -{ - create_frame(frame, co1, (n1->radius + n2->radius) / 2, - mat, len_v3v3(co1, co2) / 2); -} - -static void add_face(MFace *mface, int *totface, - int v1, int v2, int v3, int v4) -{ - MFace *f; - - f = &mface[*totface]; - f->v1 = v1; - f->v2 = v2; - f->v3 = v3; - f->v4 = v4 == -1 ? 0 : v4; - if(!v4) { - f->v1 = v3; - f->v2 = v4; - f->v3 = v1; - f->v4 = v2; - } - (*totface)++; -} - -static void connect_frames(MFace *mface, int *totface, int frame1, int frame2) -{ - int i; - - for(i = 0; i < 4; i++) { - add_face(mface, totface, - frame2 + i, - frame2 + (i+1) % 4, - frame1 + (i+1) % 4, - frame1 + i); - } -} - -static Tri *add_triangle(ListBase *tris, MVert *mvert, int v1, int v2, int v3) -{ - Tri *t; - - t = MEM_callocN(sizeof(Tri), "add_triangle.tri"); - t->v[0] = v1; - t->v[1] = v2; - t->v[2] = v3; - BLI_addtail(tris, t); - - normal_tri_v3(t->no, mvert[t->v[0]].co, mvert[t->v[1]].co, mvert[t->v[2]].co); - t->area = area_tri_v3(mvert[t->v[0]].co, mvert[t->v[1]].co, mvert[t->v[2]].co); - - return t; -} - -static int point_tri_side(const Tri *t, MVert *mvert, int v) -{ - float p[3], d; - sub_v3_v3v3(p, mvert[v].co, mvert[t->v[0]].co); - d = dot_v3v3(t->no, p); - if(d < 0) return -1; - else if(d > 0) return 1; - else return 0; -} - -static int mark_v_outside_tris(ListBase *tris, MVert *mvert, int v) -{ - Tri *t; - int outside = 0; - - /* probably there's a much better way to do this */ - for(t = tris->first; t; t = t->next) { - if((t->marked = point_tri_side(t, mvert, v) > 0)) - outside = 1; - } - return outside; -} - -static int edge_match(int e1_0, int e1_1, const unsigned int e2[2]) -{ - /* XXX: maybe isn't necesseary to check both directions? */ - return (e1_0 == e2[0] && e1_1 == e2[1]) || - (e1_0 == e2[1] && e1_1 == e2[0]); -} - -/* returns true if the edge (e1, e2) is already in edges; that edge is - deleted here as well. if not found just returns 0 */ -static int check_for_dup(ListBase *edges, unsigned int e1, unsigned int e2) -{ - Edge *e, *next; - - for(e = edges->first; e; e = next) { - next = e->next; - - if(edge_match(e1, e2, e->v)) { - /* remove the interior edge */ - BLI_freelinkN(edges, e); - return 1; - } - } - - return 0; -} - -static void expand_boundary_edges(ListBase *edges, Tri *t) -{ - Edge *new; - int i; - - /* insert each triangle edge into the boundary list; if any of - its edges are already in there, remove the edge entirely */ - for(i = 0; i < 3; i++) { - if(!check_for_dup(edges, t->v[i], t->v[(i+1)%3])) { - new = MEM_callocN(sizeof(Edge), "Edge"); - new->v[0] = t->v[i]; - new->v[1] = t->v[(i+1)%3]; - BLI_addtail(edges, new); - } - } -} - -static int tri_matches_frame(const Tri *t, int frame) -{ - int i, j, match = 0; - for(i = 0; i < 3; i++) { - for(j = 0; j < 4; j++) { - if(t->v[i] == frame + j) { - match++; - if(match >= 3) - return 1; - } - } - } - return 0; -} - -static void quad_from_tris(const Edge *e, int ndx[4]) -{ - int i, j, opp = -1; - - /* find what the second tri has that the first doesn't */ - for(i = 0; i < 3; i++) { - if(e->tri[1]->v[i] != e->tri[0]->v[0] && - e->tri[1]->v[i] != e->tri[0]->v[1] && - e->tri[1]->v[i] != e->tri[0]->v[2]) { - opp = e->tri[1]->v[i]; - break; - } - } - assert(opp != -1); - - for(i = 0, j = 0; i < 3; i++, j++) { - ndx[j] = e->tri[0]->v[i]; - /* when the triangle edge cuts across our quad-to-be, - throw in the second triangle's vertex */ - if((e->tri[0]->v[i] == e->v[0] || e->tri[0]->v[i] == e->v[1]) && - (e->tri[0]->v[(i+1)%3] == e->v[0] || e->tri[0]->v[(i+1)%3] == e->v[1])) { - j++; - ndx[j] = opp; - } - } -} - -static void add_quad_from_tris(MFace *mface, int *totface, const Edge *e) -{ - int ndx[4]; - - quad_from_tris(e, ndx); - - add_face(mface, totface, ndx[0], ndx[1], ndx[2], ndx[3]); -} - -static GHash *calc_edges(ListBase *tris) -{ - GHash *adj; - ListBase *edges; - Edge *e; - Tri *t; - int i, e1, e2; - - /* XXX: vertex range might be a little funky? so using a - hash here */ - adj = BLI_ghash_new(BLI_ghashutil_inthash, - BLI_ghashutil_intcmp, - "calc_edges adj"); - - for(t = tris->first; t; t = t->next) { - for(i = 0; i < 3; i++) { - e1 = t->v[i]; - e2 = t->v[(i+1)%3]; - assert(e1 != e2); - if(e1 > e2) - SWAP(int, e1, e2); - - edges = BLI_ghash_lookup(adj, SET_INT_IN_POINTER(e1)); - if(!edges) { - edges = MEM_callocN(sizeof(ListBase), - "calc_edges ListBase"); - BLI_ghash_insert(adj, SET_INT_IN_POINTER(e1), edges); - } - - /* find the edge in the adjacency list */ - for(e = edges->first; e; e = e->next) { - assert(e->v[0] == e1); - if(e->v[1] == e2) - break; - } - - /* if not found, create the edge */ - if(!e) { - e = MEM_callocN(sizeof(Edge), "calc_edges Edge"); - e->v[0] = e1; - e->v[1] = e2; - BLI_addtail(edges, e); - } - - /* should never be more than two faces - attached to an edge here */ - assert(!e->tri[0] || !e->tri[1]); - - if(!e->tri[0]) - e->tri[0] = t; - else if(!e->tri[1]) - e->tri[1] = t; - } - } - - return adj; -} - -static int is_quad_symmetric(const MVert *mvert, const Edge *e) -{ - int ndx[4]; - float a[3]; - - quad_from_tris(e, ndx); - - copy_v3_v3(a, mvert[ndx[0]].co); - a[0] = -a[0]; - - if(len_v3v3(a, mvert[ndx[1]].co) < FLT_EPSILON) { - copy_v3_v3(a, mvert[ndx[2]].co); - a[0] = -a[0]; - if(len_v3v3(a, mvert[ndx[3]].co) < FLT_EPSILON) - return 1; - } - else if(len_v3v3(a, mvert[ndx[3]].co) < FLT_EPSILON) { - copy_v3_v3(a, mvert[ndx[2]].co); - a[0] = -a[0]; - if(len_v3v3(a, mvert[ndx[1]].co) < FLT_EPSILON) - return 1; - } - - return 0; -} - -static void output_hull(const MVert *mvert, MFace *mface, int *totface, ListBase *tris) -{ - Heap *heap; - GHash *adj; - GHashIterator *iter; - ListBase *edges; - Edge *e; - Tri *t; - float score; - - heap = BLI_heap_new(); - adj = calc_edges(tris); - - /* unmark all triangles */ - for(t = tris->first; t; t = t->next) - t->marked = 0; - - /* build heap */ - iter = BLI_ghashIterator_new(adj); - while(!BLI_ghashIterator_isDone(iter)) { - edges = BLI_ghashIterator_getValue(iter); - for(e = edges->first; e; e = e->next) { - /* only care if the edge is used by more than - one triangle */ - if(e->tri[0] && e->tri[1]) { - score = (e->tri[0]->area + e->tri[1]->area) * - dot_v3v3(e->tri[0]->no, e->tri[1]->no); - - /* increase score if the triangles - form a symmetric quad */ - if(is_quad_symmetric(mvert, e)) - score *= 10; - - BLI_heap_insert(heap, -score, e); - } - } - - BLI_ghashIterator_step(iter); - } - BLI_ghashIterator_free(iter); - - while(!BLI_heap_empty(heap)) { - e = BLI_heap_popmin(heap); - - /* if both triangles still free, outupt as a quad */ - if(!e->tri[0]->marked && !e->tri[1]->marked) { - add_quad_from_tris(mface, totface, e); - e->tri[0]->marked = 1; - e->tri[1]->marked = 1; - } - } - - /* free edge list */ - iter = BLI_ghashIterator_new(adj); - while(!BLI_ghashIterator_isDone(iter)) { - edges = BLI_ghashIterator_getValue(iter); - BLI_freelistN(edges); - MEM_freeN(edges); - BLI_ghashIterator_step(iter); - } - BLI_ghashIterator_free(iter); - BLI_ghash_free(adj, NULL, NULL); - BLI_heap_free(heap, NULL); - - /* write out any remaining triangles */ - for(t = tris->first; t; t = t->next) { - if(!t->marked) - add_face(mface, totface, t->v[0], t->v[1], t->v[2], -1); - } -} - -/* for vertex `v', find which triangles must be deleted to extend the - hull; find the boundary edges of that hole so that it can be filled - with connections to the new vertex, and update the `tri' list to - delete the marked triangles */ -static void add_point(ListBase *tris, MVert *mvert, int v) -{ - ListBase edges = {NULL, NULL}; - Tri *t, *next; - Edge *e; - - for(t = tris->first; t; t = next) { - next = t->next; - - /* check if triangle is `visible' to v */ - if(t->marked) { - expand_boundary_edges(&edges, t); - /* remove the triangle */ - BLI_freelinkN(tris, t); - } - } - - /* fill hole boundary with triangles to new point */ - for(e = edges.first; e; e = e->next) - add_triangle(tris, mvert, e->v[0], e->v[1], v); - BLI_freelistN(&edges); -} - -static void build_hull(MFace *mface, int *totface, - MVert *mvert, int *frames, int totframe) -{ - ListBase tris = {NULL, NULL}; - Tri *t, *next; - int i, j; - - /* use first frame to make initial degenerate pyramid */ - add_triangle(&tris, mvert, frames[0], frames[0] + 1, frames[0] + 2); - add_triangle(&tris, mvert, frames[0] + 1, frames[0], frames[0] + 3); - add_triangle(&tris, mvert, frames[0] + 2, frames[0] + 1, frames[0] + 3); - add_triangle(&tris, mvert, frames[0], frames[0] + 2, frames[0] + 3); - - for(i = 1; i < totframe; i++) { - for(j = 0; j < 4; j++) { - int v = frames[i] + j; - - /* ignore point already inside hull */ - if(mark_v_outside_tris(&tris, mvert, v)) { - /* expand hull and delete interior triangles */ - add_point(&tris, mvert, v); - } - } - } - - /* remove triangles that would fill the original frames */ - for(t = tris.first; t; t = next) { - next = t->next; - - for(i = 0; i < totframe; i++) { - if(tri_matches_frame(t, frames[i])) { - BLI_freelinkN(&tris, t); - break; - } - } - } - - output_hull(mvert, mface, totface, &tris); - - BLI_freelistN(&tris); -} - -/* test: build hull on origdm */ -#if 0 -static DerivedMesh *test_hull(DerivedMesh *origdm) -{ - DerivedMesh *dm; - MVert *mvert, *origmvert; - MFace *mface; - int *frames; - int totvert = 0, totface = 0, totframe, i; - - /* TODO */ - totface = 2000; - totvert = origdm->getNumVerts(origdm); - dm = CDDM_new(totvert, 0, totface); - - mvert = CDDM_get_verts(dm); - mface = CDDM_get_faces(dm); - - origmvert = CDDM_get_verts(origdm); - for(i = 0; i < totvert; i++) - mvert[i] = origmvert[i]; - - assert(totvert % 4 == 0); - totframe = totvert / 4; - - frames = MEM_callocN(sizeof(int) * totframe, "frames"); - for(i = 0; i < totframe; i++) - frames[i] = i*4; - - totface = 0; - build_hull(mface, &totface, mvert, frames, totframe); - - CDDM_calc_edges(dm); - //CDDM_calc_normals(dm); - - MEM_freeN(frames); - - return dm; -} -#endif - -/* TODO */ -static void calc_edge_mat(float mat[3][3], const float a[3], const float b[3]) -{ - float Z[3] = {0, 0, 1}; - float dot; - - /* x = edge direction */ - sub_v3_v3v3(mat[0], b, a); - normalize_v3(mat[0]); - - dot = dot_v3v3(mat[0], Z); - if(dot > -1 + FLT_EPSILON && dot < 1 - FLT_EPSILON) { - /* y = Z cross x */ - cross_v3_v3v3(mat[1], Z, mat[0]); - normalize_v3(mat[1]); - - /* z = x cross y */ - cross_v3_v3v3(mat[2], mat[0], mat[1]); - normalize_v3(mat[2]); - } - else { - mat[1][0] = 1; - mat[1][1] = 0; - mat[1][2] = 0; - mat[2][0] = 0; - mat[2][1] = 1; - mat[2][2] = 0; - } -} - -/* BMesh paper */ -#if 0 -static float calc_R_sub_i_squared(const BSphereNode *n) -{ - const float alpha = 1.5; - //const float alpha = 1; - const float R_sub_i = n->size[0] * alpha; - return R_sub_i * R_sub_i; -} - -/* equation (2) */ -static float calc_r_squared(const float v[3], const BSphereNode *n) -{ - return len_squared_v3v3(v, n->co); -} - -/* equation (1) */ -static float calc_f_sub_i(const float v[3], const BSphereNode *n) -{ - float r_squared; - float R_sub_i_squared; - - r_squared = calc_r_squared(v, n); - R_sub_i_squared = calc_R_sub_i_squared(n); - - if(r_squared <= R_sub_i_squared) - return powf(1.0f - (r_squared / R_sub_i_squared), 2); - else - return 0; -} - -/* equation (3) */ -static float calc_I(const float x[3], float T, const ListBase *base) -{ - BSphereNode *n; - float a = -T; - - for(n = base->first; n; n = n->next) { - a += calc_I(x, 0, &n->children); - a += calc_f_sub_i(x, n); - } - - //printf("calc_I: %f, %f\n", -T, a); - - return a; -} - -/* kinda my own guess here */ -static void calc_gradient(float g[3], const float x[3], const ListBase *base) -{ - BSphereNode *n; - - for(n = base->first; n; n = n->next) { - float R_sub_i_squared = calc_R_sub_i_squared(n); - float dist = len_v3v3(x, n->co); - float f = calc_f_sub_i(x, n); - float d = 1.0f / R_sub_i_squared; - float tmp[3]; - - /* XXX: other possibilities... */ - if(f > 0) { - sub_v3_v3v3(tmp, x, n->co); - mul_v3_fl(tmp, -4*d * (1 - d * dist)); - - /* not sure if I'm doing this right; intent is - to flip direction when x is `beneath' the - level set */ - if(len_v3v3(x, n->co) > n->size[0]) - negate_v3(tmp); - - add_v3_v3(g, tmp); - } - - calc_gradient(g, x, &n->children); - } -} - -/* equation (5) */ -static float calc_F(const float x[3], const float K[2], float T, const ListBase *base) -{ - float f_of_K; - float I_target; - - /* TODO */ - f_of_K = 1.0f / (1 + fabs(K[0]) + fabs(K[1])); - //f_of_K = 1; - - /* TODO */ - I_target = 0; - - return (calc_I(x, T, base) - I_target) /*TODO: * f_of_K*/; -} - -static float smallest_radius(const ListBase *base) -{ - BSphereNode *n; - float s = FLT_MAX, t; - - for(n = base->first; n; n = n->next) { - if(n->size[0] < s) - s = n->size[0]; - if((t = smallest_radius(&n->children)) < s) - s = t; - } - - return s; -} - -/* equation (7) */ -static float calc_delta_t(float F_max, float k, const ListBase *base, int print) -{ - float min_r_sub_i; - float step; - - min_r_sub_i = smallest_radius(base); - step = min_r_sub_i / powf(2, k); - - if(print) { - printf("min_r: %f, 2^k=%f, step=%f\n", min_r_sub_i, powf(2, k), step); - } - - return step / F_max; -} - -/* equation (6) */ -static float evolve_x(float x[3], const float K[2], float T, - int k, const ListBase *base, int i, float F_max) -{ - float tmp[3], no[3]; - float F, dt; - - F = calc_F(x, K, T, base); - - if(F < FLT_EPSILON) { - //printf("stability reached for ndx=%d\n", i); - return 0; - } - - /* TODO ;-) */ - if(F > F_max) - F_max = F; - - dt = calc_delta_t(F_max, k, base, 0); - - dt = F / 2; - - if(i == 0) - ;//printf("F=%.3f, dt=%.3f\n", F, calc_delta_t(F_max, k, base, 1)); - - zero_v3(no); - calc_gradient(no, x, base); - normalize_v3(no); - negate_v3(no); - - mul_v3_v3fl(tmp, no, F * dt); - add_v3_v3(x, tmp); - - return F_max; -} - -static void bsphere_evolve(MVert *mvert, int totvert, const ListBase *base, - float T, int steps, float subdiv_level) -{ - int i, s; - - for(i = 0; i < totvert; i++) { - float F_max = 0; - /* TODO: for now just doing a constant number of steps */ - for(s = 0; s < steps; s++) { - /* TODO */ - float K[2] = {0, 0}; - - F_max = evolve_x(mvert[i].co, K, T, subdiv_level, base, i, F_max); - } - } -} -#endif - -typedef enum { - START_CAP = 1, - END_CAP = 2, - NODE_BISECT = 4, - CHILD_EDGE_BISECT = 8, - - IN_FRAME = 16, - OUT_FRAME = 32, -} FrameFlag; - -typedef struct { - int totframe; - int outbase; - FrameFlag flag; - float co[0][4][3]; -} Frames; - -static Frames *frames_create(FrameFlag flag) -{ - Frames *frames; - int totframe; - totframe = (!!(flag & START_CAP) + !!(flag & END_CAP) + - !!(flag & NODE_BISECT) + !!(flag & CHILD_EDGE_BISECT)); - assert(totframe); - frames = MEM_callocN(sizeof(Frames) + sizeof(float)*totframe*4*3, - "frames_create.frames"); - frames->totframe = totframe; - frames->flag = flag; - assert((flag & (END_CAP|CHILD_EDGE_BISECT)) != (END_CAP|CHILD_EDGE_BISECT)); - return frames; -} - -static int frame_offset(Frames *frames, FrameFlag flag) -{ - int n = 0; - - assert(flag == IN_FRAME || flag == OUT_FRAME || - !(flag & (IN_FRAME|OUT_FRAME))); - - if(flag == IN_FRAME) - return 0; - else if(flag == OUT_FRAME) - return frames->totframe-1; - - assert((flag & frames->flag) == flag); - - if(flag == START_CAP) return n; - if(frames->flag & START_CAP) n++; - - if(flag == NODE_BISECT) return n; - if(frames->flag & NODE_BISECT) n++; - - if(flag == END_CAP) return n; - if(frames->flag & END_CAP) n++; - - if(flag == CHILD_EDGE_BISECT) return n; - if(frames->flag & CHILD_EDGE_BISECT) n++; - - assert(!"bad frame offset flag"); -} - -static int frame_base(Frames *frames, FrameFlag flag) -{ - return frames->outbase + 4*frame_offset(frames, flag); -} - -static void *frame_co(Frames *frames, FrameFlag flag) -{ - return frames->co[frame_offset(frames, flag)]; -} - -static int frames_totvert(Frames *frames) -{ - return frames->totframe*4; -} - -#if 0 -static int bsphere_build_frames(BSphereNode *n, GHash *ghash, - float (*parent_mat)[3], FrameFlag flag); - -/* builds the `cap' of polygons for the end of a BSphere chain */ -static int bsphere_end_node_frames(BSphereNode *n, - GHash *ghash, - float parent_mat[3][3], - FrameFlag flag) -{ - Frames *frames; - float rad; - - assert(flag == 0 || flag == START_CAP); - frames = frames_create(NODE_BISECT|END_CAP|flag, n, ghash); - - /* TODO */ - rad = n->size[0]; - - if(flag & START_CAP) - create_frame(frame_co(frames, START_CAP), n, parent_mat, -rad, rad); - - /* frame to bisect the node */ - create_frame(frame_co(frames, NODE_BISECT), n, parent_mat, 0, rad); - - /* frame to cap end node */ - create_frame(frame_co(frames, END_CAP), n, parent_mat, rad, rad); - - return frames_totvert(frames); -} - -static int bsphere_connection_node_frames(BSphereNode *n, - GHash *ghash, - float parent_mat[3][3], - FrameFlag flag) -{ - Frames *frames; - BSphereNode *child; - float childmat[3][3], nodemat[3][3], axis[3], angle, rad, child_rad; - int totvert; - - assert(flag == 0 || flag == START_CAP); - - child = n->children.first; - - /* if child is not a branch node, bisect the child edge */ - if(BLI_countlist(&child->children) <= 1) - flag |= CHILD_EDGE_BISECT; - - frames = frames_create(NODE_BISECT|flag, n, ghash); - totvert = frames_totvert(frames); - - /* TODO */ - rad = n->size[0]; - child_rad = child->size[0]; - - /* build matrix to give to child */ - sub_v3_v3v3(childmat[0], child->co, n->co); - normalize_v3(childmat[0]); - angle = angle_normalized_v3v3(parent_mat[0], childmat[0]); - cross_v3_v3v3(axis, parent_mat[0], childmat[0]); - normalize_v3(axis); - rotate_normalized_v3_v3v3fl(childmat[1], parent_mat[1], axis, angle); - rotate_normalized_v3_v3v3fl(childmat[2], parent_mat[2], axis, angle); - - /* build child */ - totvert += bsphere_build_frames(child, ghash, childmat, 0); - - /* frame that bisects the node */ - angle /= 2; - copy_v3_v3(nodemat[0], parent_mat[0]); - rotate_normalized_v3_v3v3fl(nodemat[1], parent_mat[1], axis, angle); - rotate_normalized_v3_v3v3fl(nodemat[2], parent_mat[2], axis, angle); - create_frame(frame_co(frames, NODE_BISECT), n, nodemat, 0, rad); - - if(flag & START_CAP) - create_frame(frame_co(frames, START_CAP), n, nodemat, -rad, rad); - - if(flag & CHILD_EDGE_BISECT) - create_mid_frame(frame_co(frames, CHILD_EDGE_BISECT), n, child, childmat); - - return totvert; -} - -static int bsphere_branch_node_frames(BSphereNode *n, GHash *ghash) -{ - BSphereNode *child; - int totvert = 0; - float rad; - - rad = n->size[0]; - - /* build children */ - for(child = n->children.first; child; child = child->next) { - float childmat[3][3]; - - calc_edge_mat(childmat, n->co, child->co); - - totvert += bsphere_build_frames(child, ghash, childmat, 0); - } - - /* TODO: for now, builds no frames of its own */ - - return totvert; -} - -static int bsphere_build_frames(BSphereNode *n, GHash *ghash, - float parent_mat[3][3], FrameFlag flag) -{ - BSphereNode *child; - - child = n->children.first; - - if(!child) - return bsphere_end_node_frames(n, ghash, parent_mat, flag); - else if(!child->next) - return bsphere_connection_node_frames(n, ghash, parent_mat, flag); - else - return bsphere_branch_node_frames(n, ghash); -} - -static GHash *bsphere_frames(BSphere *bs, int *totvert) -{ - GHash *ghash; - BSphereNode *n, *child; - - ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, - "bsphere_frames.ghash"); - (*totvert) = 0; - - for(n = bs->rootbase.first; n; n = n->next) { - float mat[3][3]; - - child = n->children.first; - if(!child || (child && child->next)) { - set_v3(mat[0], 0, 0, 1); - set_v3(mat[1], 1, 0, 0); - set_v3(mat[2], 0, 1, 0); - } - else if(!child->next) { - calc_edge_mat(mat, n->co, child->co); - } - - (*totvert) += bsphere_build_frames(n, ghash, mat, START_CAP); - } - - return ghash; -} - -static void output_frames(Frames *frames, MVert *mvert, MFace *mface, - int *totvert, int *totface) -{ - int b, i, j; - - frames->outbase = (*totvert); - for(i = 0; i < frames->totframe; i++) { - for(j = 0; j < 4; j++) { - copy_v3_v3(mvert[(*totvert)].co, frames->co[i][j]); - (*totvert)++; - } - - if(i > 0) { - connect_frames(mface, totface, - frames->outbase + 4*(i-1), - frames->outbase + 4*i); - } - } - - if(frames->flag & START_CAP) { - b = frame_base(frames, START_CAP); - add_face(mface, totface, b, b+1, b+2, b+3); - } - if(frames->flag & END_CAP) { - b = frame_base(frames, END_CAP); - add_face(mface, totface, b+3, b+2, b+1, b+0); - } -} - -static void bsphere_build_skin(BSphereNode *parent, ListBase *base, - GHash *frames, MVert *mvert, - MFace *mface, int *totvert, int *totface) -{ - BSphereNode *n, *child; - Frames *node_frames, *child_frames, *parent_frames; - int *hull_frames, totchild, i; - - for(n = base->first; n; n = n->next) { - if((node_frames = BLI_ghash_lookup(frames, n))) - output_frames(node_frames, mvert, mface, totvert, totface); - - bsphere_build_skin(n, &n->children, frames, mvert, mface, totvert, totface); - - child = n->children.first; - if(child && !child->next) { - child_frames = BLI_ghash_lookup(frames, child); - if(child_frames) { - connect_frames(mface, totface, - frame_base(node_frames, OUT_FRAME), - frame_base(child_frames, IN_FRAME)); - } - } - else if(child && child->next) { - totchild = BLI_countlist(&n->children); - hull_frames = MEM_callocN(sizeof(int) * (1+totchild), - "bsphere_build_skin.hull_frames"); - i = 0; - for(child = n->children.first; child; child = child->next) { - child_frames = BLI_ghash_lookup(frames, child); - assert(child_frames); - hull_frames[i++] = frame_base(child_frames, IN_FRAME); - } - parent_frames = BLI_ghash_lookup(frames, parent); - if(parent_frames) - hull_frames[i] = frame_base(parent_frames, OUT_FRAME); - else - totchild--; - build_hull(mface, totface, mvert, hull_frames, totchild+1); - MEM_freeN(hull_frames); - } - } -} - -static DerivedMesh *bsphere_base_skin(BSphere *bs) -{ - DerivedMesh *dm; - GHash *ghash; - MVert *mvert; - MFace *mface; - int totvert, totface = 0; - - /* no nodes, nothing to do */ - if(!bs->rootbase.first) - return NULL; - - /* could probably do all this in one fell [recursive] swoop - using some tricksies and clevers, but multiple passes is - easier :) */ - ghash = bsphere_frames(bs, &totvert); - - totface = totvert * 1.5; - /* XXX: sizes OK? */ - dm = CDDM_new(totvert, 0, totface); - - mvert = CDDM_get_verts(dm); - mface = CDDM_get_faces(dm); - - totvert = totface = 0; - bsphere_build_skin(NULL, &bs->rootbase, ghash, mvert, mface, &totvert, &totface); - BLI_ghash_free(ghash, NULL, (void*)MEM_freeN); - - CDDM_lower_num_verts(dm, totvert); - CDDM_lower_num_faces(dm, totface); - - CDDM_calc_edges(dm); - CDDM_calc_normals(dm); - - return dm; -} - -/* generate random points (just for testing) */ -DerivedMesh *bsphere_random_points(BSphere *UNUSED(bs)) -{ - DerivedMesh *dm; - MVert *mvert; - const int totvert = 1;//50000; - int i; - - dm = CDDM_new(totvert, 0, 0); - - mvert = CDDM_get_verts(dm); - - srand(1); - for(i = 0; i < totvert; i++) { - mvert[i].co[0] = rand() / (float)RAND_MAX - 0.5; - mvert[i].co[1] = rand() / (float)RAND_MAX - 0.5; - mvert[i].co[2] = rand() / (float)RAND_MAX - 0.5; - } - - return dm; -} - -DerivedMesh *bsphere_test_surface(BSphere *bs, DerivedMesh *input) -{ - DerivedMesh *dm; - MVert *mvert; - - if(!input) - return NULL; - - dm = CDDM_copy(input); - mvert = CDDM_get_verts(dm); - bsphere_evolve(mvert, input->getNumVerts(input), &bs->rootbase, - bs->skin_threshold, bs->evolve, 2); - - return dm; -} - -DerivedMesh *bsphere_test_gradient(BSphere *bs, DerivedMesh *input) -{ - DerivedMesh *dm; - MVert *mvert; - MEdge *medge; - int totvert; - int i; - - if(!input) - return NULL; - - totvert = input->getNumVerts(input); - dm = CDDM_new(totvert*2, totvert, 0); - - mvert = CDDM_get_verts(dm); - medge = CDDM_get_edges(dm); - - memcpy(mvert, CDDM_get_verts(input), sizeof(MVert) * totvert); - - for(i = 0; i < totvert; i++) { - const float *b = mvert[i].co; - float *g = mvert[totvert+i].co; - float K[2] = {0, 0}; - - zero_v3(g); - calc_gradient(g, b, &bs->rootbase); - normalize_v3(g); - - mul_v3_fl(g, -calc_F(b, K, bs->skin_threshold, &bs->rootbase)); - add_v3_v3(g, b); - - medge[i].v1 = i; - medge[i].v2 = totvert+i; - } - - return dm; -} - -DerivedMesh *bsphere_get_skin_dm(BSphere *bs) -{ - DerivedMesh *dm, *subdm; - - dm = bsphere_base_skin(bs); - - /* subdivide once */ - if(dm && bs->subdiv_level > 0) { - SubsurfModifierData smd; - - memset(&smd, 0, sizeof(smd)); - smd.subdivType = ME_CC_SUBSURF; - smd.levels = bs->subdiv_level; - subdm = subsurf_make_derived_from_derived(dm, &smd, 0, 0, 0, 0); - dm->release(dm); - /* for convenience, convert back to cddm (could use ccgdm - later for better performance though? (TODO)) */ - dm = CDDM_copy(subdm); - subdm->release(subdm); - - bsphere_evolve(CDDM_get_verts(dm), dm->getNumVerts(dm), &bs->rootbase, - bs->skin_threshold, bs->evolve, bs->subdiv_level); - } - - return dm; -} -#endif diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index b9d6badfbe9..8d19322c0db 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -805,15 +805,7 @@ static void layerDefault_mcol(void *data, int count) mcol[i] = default_mcol; } -static void layerDefault_skin(void *data, int count) -{ - SkinNode *n = data; - int i; - - for(i = 0; i < count; i++) { - n[i].radius = 0.25; - } -} + static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { {sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL}, @@ -851,8 +843,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { layerSwap_mcol, layerDefault_mcol}, {sizeof(MCol)*4, "MCol", 4, "TexturedCol", NULL, NULL, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol}, - {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, - {sizeof(SkinNode), "SkinNode", 1, "Skin", NULL, NULL, NULL, NULL, layerDefault_skin} + {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL} }; static const char *LAYERTYPENAMES[CD_NUMTYPES] = { @@ -860,7 +851,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = { /* 5-9 */ "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFlags", /* 10-14 */ "CDMFloatProperty", "CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco", /* 15-19 */ "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent", "CDMDisps", - /* 20-24 */ "CDWeightMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco", "CDSkinNode" + /* 20-23 */"CDWeightMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco" }; const CustomDataMask CD_MASK_BAREMESH = @@ -868,12 +859,10 @@ const CustomDataMask CD_MASK_BAREMESH = const CustomDataMask CD_MASK_MESH = CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | - CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | - CD_MASK_SKIN_NODE; + CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS; const CustomDataMask CD_MASK_EDITMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | - CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | - CD_MASK_SKIN_NODE; + CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS; const CustomDataMask CD_MASK_DERIVEDMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO | diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 061e9460956..cdfcf465c6c 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -92,8 +92,7 @@ typedef struct CustomData { #define CD_ID_MCOL 21 #define CD_TEXTURE_MCOL 22 #define CD_CLOTH_ORCO 23 -#define CD_SKIN_NODE 24 -#define CD_NUMTYPES 25 +#define CD_NUMTYPES 24 /* Bits for CustomDataMask */ #define CD_MASK_MVERT (1 << CD_MVERT) @@ -118,7 +117,6 @@ typedef struct CustomData { #define CD_MASK_MDISPS (1 << CD_MDISPS) #define CD_MASK_WEIGHT_MCOL (1 << CD_WEIGHT_MCOL) #define CD_MASK_CLOTH_ORCO (1 << CD_CLOTH_ORCO) -#define CD_MASK_SKIN_NODE (1 << CD_SKIN_NODE) /* CustomData.flag */ diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index a71c4970eb5..e3510b3a25a 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -184,11 +184,6 @@ typedef struct PartialVisibility { unsigned int totface, totedge, totvert, pad; } PartialVisibility; -typedef struct SkinNode { - float radius; - int pad; -} SkinNode; - /* mvert->flag (1=SELECT) */ #define ME_SPHERETEST 2 #define ME_VERT_TMP_TAG 4 diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 483bd339b3d..3787675f339 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -71,7 +71,6 @@ typedef enum ModifierType { eModifierType_Solidify, eModifierType_Screw, eModifierType_Warp, - eModifierType_Skin, NUM_MODIFIER_TYPES } ModifierType; @@ -786,17 +785,4 @@ typedef enum { /* PROP_RANDOM not used */ } WarpModifierFalloff; -typedef enum SkinModifierFlags { - MOD_SKIN_DRAW_SKIN = (1<<0), - MOD_SKIN_DRAW_NODES = (1<<1), -} SkinModifierFlags; - -typedef struct SkinModifierData { - ModifierData modifier; - float threshold; - int subdiv; - int flag; - int pad; -} SkinModifierData; - #endif diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index b4a4c593ba9..ba655915fb6 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -68,7 +68,6 @@ EnumPropertyItem modifier_type_items[] ={ {eModifierType_Solidify, "SOLIDIFY", ICON_MOD_SOLIDIFY, "Solidify", ""}, {eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""}, {eModifierType_UVProject, "UV_PROJECT", ICON_MOD_UVPROJECT, "UV Project", ""}, - {eModifierType_Skin, "SKIN", ICON_MOD_ARMATURE, "Skin", ""}, {0, "", 0, "Deform", ""}, {eModifierType_Armature, "ARMATURE", ICON_MOD_ARMATURE, "Armature", ""}, {eModifierType_Cast, "CAST", ICON_MOD_CAST, "Cast", ""}, @@ -184,8 +183,6 @@ static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr) return &RNA_ScrewModifier; case eModifierType_Warp: return &RNA_WarpModifier; - case eModifierType_Skin: - return &RNA_SkinModifier; default: return &RNA_Modifier; } @@ -2415,17 +2412,6 @@ static void rna_def_modifier_screw(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Modifier_update");*/ } -static void rna_def_modifier_skin(BlenderRNA *brna) -{ - StructRNA *srna; - PropertyRNA *prop; - - srna= RNA_def_struct(brna, "SkinModifier", "Modifier"); - RNA_def_struct_ui_text(srna, "Skin Modifier", "Generate Skin"); - RNA_def_struct_sdna(srna, "SkinModifierData"); - RNA_def_struct_ui_icon(srna, ICON_MOD_ARMATURE); -} - void RNA_def_modifier(BlenderRNA *brna) { StructRNA *srna; @@ -2523,7 +2509,6 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_smoke(brna); rna_def_modifier_solidify(brna); rna_def_modifier_screw(brna); - rna_def_modifier_skin(brna); } #endif diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index 7db03f48631..d1f153265ac 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -70,7 +70,6 @@ set(SRC intern/MOD_shapekey.c intern/MOD_shrinkwrap.c intern/MOD_simpledeform.c - intern/MOD_skin.c intern/MOD_smoke.c intern/MOD_smooth.c intern/MOD_softbody.c diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h index 329037ee210..4e44a226c64 100644 --- a/source/blender/modifiers/MOD_modifiertypes.h +++ b/source/blender/modifiers/MOD_modifiertypes.h @@ -72,7 +72,6 @@ extern ModifierTypeInfo modifierType_ShapeKey; extern ModifierTypeInfo modifierType_Solidify; extern ModifierTypeInfo modifierType_Screw; extern ModifierTypeInfo modifierType_Warp; -extern ModifierTypeInfo modifierType_Skin; /* MOD_util.c */ void modifier_type_init(ModifierTypeInfo *types[]); diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c deleted file mode 100644 index adc47f32c9c..00000000000 --- a/source/blender/modifiers/intern/MOD_skin.c +++ /dev/null @@ -1,88 +0,0 @@ -/* -* $Id$ -* -* ***** BEGIN GPL LICENSE BLOCK ***** -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* ***** END GPL LICENSE BLOCK ***** -* -*/ - -/** \file blender/modifiers/intern/MOD_skin.c - * \ingroup modifiers - */ - - -#include - -#include "BKE_cdderivedmesh.h" -#include "BKE_modifier.h" - -#include "DNA_mesh_types.h" -#include "DNA_object_types.h" - -#include "MOD_util.h" - -static void initData(ModifierData *md) -{ - SkinModifierData *smd = (SkinModifierData*)md; - - smd->threshold = 0; - smd->subdiv = 1; - smd->flag = MOD_SKIN_DRAW_NODES; -} - -static void copyData(ModifierData *md, ModifierData *target) -{ - SkinModifierData *smd = (SkinModifierData*) md; - SkinModifierData *tsmd = (SkinModifierData*) target; - - tsmd->threshold = smd->threshold; - tsmd->subdiv = smd->subdiv; - tsmd->flag = smd->flag; -} - -static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm, - int useRenderParams, int isFinalCalc) -{ - return dm; -} - - -ModifierTypeInfo modifierType_Skin = { - /* name */ "Skin", - /* structName */ "SkinModifierData", - /* structSize */ sizeof(SkinModifierData), - /* type */ eModifierTypeType_Constructive, - /* flags */ eModifierTypeFlag_AcceptsMesh, - - /* copyData */ copyData, - /* deformVerts */ NULL, - /* deformMatrices */ NULL, - /* deformVertsEM */ NULL, - /* deformMatricesEM */ NULL, - /* applyModifier */ applyModifier, - /* applyModifierEM */ NULL, - /* initData */ initData, - /* requiredDataMask */ NULL, - /* freeData */ NULL, - /* isDisabled */ NULL, - /* updateDepgraph */ NULL, - /* dependsOnTime */ NULL, - /* dependsOnNormals */ NULL, - /* foreachObjectLink */ NULL, - /* foreachIDLink */ NULL, -}; diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index e823a347ced..e9b835eab81 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -295,6 +295,5 @@ void modifier_type_init(ModifierTypeInfo *types[]) INIT_TYPE(Solidify); INIT_TYPE(Screw); INIT_TYPE(Warp); - INIT_TYPE(Skin); #undef INIT_TYPE } -- cgit v1.2.3 From 670f58023c478995ed055e194482ab288db436a7 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 31 Jul 2011 02:34:53 +0000 Subject: == PBVH == OK, after that failure of committing a bunch of old junk, hopefully this is what I actually meant to commit :) * Added big comments to some of the fields in struct PBVHNode. I always forget the details of these, so finally wrote it down properly. * Changed types of PBVHNode.face_vert_indices and PBVHNode.flag to better reflect their contents. * There should be no functional changes here. --- source/blender/blenlib/intern/pbvh.c | 83 +++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 20 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 85d79ae3b85..0613765b868 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -26,7 +26,6 @@ - #include "DNA_meshdata_types.h" #include "MEM_guardedalloc.h" @@ -85,25 +84,61 @@ struct PBVHNode { /* Opaque handle for drawing code */ void *draw_buffers; - int *vert_indices; - /* Voxel bounds */ BB vb; BB orig_vb; - /* For internal nodes */ + /* For internal nodes, the offset of the children in the PBVH + 'nodes' array. */ int children_offset; - /* Pointer into bvh prim_indices */ - int *prim_indices; - int *face_vert_indices; + /* Pointer into the PBVH prim_indices array and the number of + primitives used by this leaf node. + Used for leaf nodes in both mesh- and multires-based PBVHs. + */ + int *prim_indices; unsigned int totprim; + + /* Array of indices into the mesh's MVert array. Contains the + indices of all vertices used by faces that are within this + node's bounding box. + + Note that a vertex might be used by a multiple faces, and + these faces might be in different leaf nodes. Such a vertex + will appear in the vert_indices array of each of those leaf + nodes. + + In order to support cases where you want access to multiple + nodes' vertices without duplication, the vert_indices array + is ordered such that the first part of the array, up to + index 'uniq_verts', contains "unique" vertex indices. These + vertices might not be truly unique to this node, but if + they appear in another node's vert_indices array, they will + be above that node's 'uniq_verts' value. + + Used for leaf nodes in a mesh-based PBVH (not multires.) + */ + int *vert_indices; unsigned int uniq_verts, face_verts; - char flag; + /* An array mapping face corners into the vert_indices + array. The array is sized to match 'totprim', and each of + the face's corners gets an index into the vert_indices + array, in the same order as the corners in the original + MFace. The fourth value should not be used if the original + face is a triangle. + + Used for leaf nodes in a mesh-based PBVH (not multires.) + */ + int (*face_vert_indices)[4]; + + /* Indicates whether this node is a leaf or not; also used for + marking various updates that need to be applied. */ + PBVHNodeFlags flag : 8; - float tmin; // used for raycasting, is how close bb is to the ray point + /* Used for raycasting: how close bb is to the ray point. */ + float tmin; int proxy_count; PBVHProxyNode* proxies; @@ -339,15 +374,15 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) node->uniq_verts = node->face_verts = 0; totface= node->totprim; - node->face_vert_indices = MEM_callocN(sizeof(int) * - 4*totface, "bvh node face vert indices"); + node->face_vert_indices = MEM_callocN(sizeof(int) * 4*totface, + "bvh node face vert indices"); for(i = 0; i < totface; ++i) { MFace *f = bvh->faces + node->prim_indices[i]; int sides = f->v4 ? 4 : 3; for(j = 0; j < sides; ++j) { - node->face_vert_indices[i*4 + j]= + node->face_vert_indices[i][j]= map_insert_vert(bvh, map, &node->face_verts, &node->uniq_verts, (&f->v1)[j]); } @@ -373,9 +408,17 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) BLI_ghashIterator_free(iter); - for(i = 0; i < totface*4; ++i) - if(node->face_vert_indices[i] < 0) - node->face_vert_indices[i]= -node->face_vert_indices[i] + node->uniq_verts - 1; + for(i = 0; i < totface; ++i) { + MFace *f = bvh->faces + node->prim_indices[i]; + int sides = f->v4 ? 4 : 3; + + for(j = 0; j < sides; ++j) { + if(node->face_vert_indices[i][j] < 0) + node->face_vert_indices[i][j]= + -node->face_vert_indices[i][j] + + node->uniq_verts - 1; + } + } if(!G.background) { node->draw_buffers = @@ -1340,20 +1383,20 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], if(bvh->faces) { MVert *vert = bvh->verts; int *faces= node->prim_indices; - int *face_verts= node->face_vert_indices; int totface= node->totprim; int i; for(i = 0; i < totface; ++i) { MFace *f = bvh->faces + faces[i]; + int *face_verts = node->face_vert_indices[i]; if(origco) { /* intersect with backuped original coordinates */ hit |= ray_face_intersection(ray_start, ray_normal, - origco[face_verts[i*4+0]], - origco[face_verts[i*4+1]], - origco[face_verts[i*4+2]], - f->v4? origco[face_verts[i*4+3]]: NULL, + origco[face_verts[0]], + origco[face_verts[1]], + origco[face_verts[2]], + f->v4? origco[face_verts[3]]: NULL, dist); } else { -- cgit v1.2.3 From 4745e3da129fcf208e72d11e60e53a339c275fd7 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 31 Jul 2011 03:06:00 +0000 Subject: improved ndof fly: precision mode, camera position, camera animation --- source/blender/editors/space_view3d/view3d_fly.c | 244 +++++++++++++---------- 1 file changed, 136 insertions(+), 108 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index c7ebc296896..34e355c977e 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -599,6 +599,75 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) } } + +static void move_camera(bContext* C, RegionView3D* rv3d, FlyInfo* fly, int orientationChanged, int positionChanged) +{ + /* we are in camera view so apply the view ofs and quat to the view matrix and set the camera to the view */ + + View3D* v3d = fly->v3d; + Scene *scene= fly->scene; + ID *id_key; + + /* transform the parent or the camera? */ + if(fly->root_parent) { + Object *ob_update; + + float view_mat[4][4]; + float prev_view_mat[4][4]; + float prev_view_imat[4][4]; + float diff_mat[4][4]; + float parent_mat[4][4]; + + ED_view3d_to_m4(prev_view_mat, fly->rv3d->ofs, fly->rv3d->viewquat, fly->rv3d->dist); + invert_m4_m4(prev_view_imat, prev_view_mat); + ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); + mul_m4_m4m4(diff_mat, prev_view_imat, view_mat); + mul_m4_m4m4(parent_mat, fly->root_parent->obmat, diff_mat); + object_apply_mat4(fly->root_parent, parent_mat, TRUE, FALSE); + + // where_is_object(scene, fly->root_parent); + + ob_update= v3d->camera->parent; + while(ob_update) { + DAG_id_tag_update(&ob_update->id, OB_RECALC_OB); + ob_update= ob_update->parent; + } + + id_key= &fly->root_parent->id; + } + else { + float view_mat[4][4]; + ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); + object_apply_mat4(v3d->camera, view_mat, TRUE, FALSE); + id_key= &v3d->camera->id; + } + + /* record the motion */ + if (autokeyframe_cfra_can_key(scene, id_key)) { + ListBase dsources = {NULL, NULL}; + + /* add datasource override for the camera object */ + ANIM_relative_keyingset_add_source(&dsources, id_key, NULL, NULL); + + /* insert keyframes + * 1) on the first frame + * 2) on each subsequent frame + * TODO: need to check in future that frame changed before doing this + */ + if (orientationChanged) { + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation"); + ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); + } + if (positionChanged) { + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location"); + ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); + } + + /* free temp data */ + BLI_freelistN(&dsources); + } +} + static int flyApply(bContext *C, FlyInfo *fly) { @@ -611,11 +680,7 @@ static int flyApply(bContext *C, FlyInfo *fly) a fly loop where the user can move move the view as if they are flying */ RegionView3D *rv3d= fly->rv3d; - View3D *v3d = fly->v3d; ARegion *ar = fly->ar; - Scene *scene= fly->scene; - - float prev_view_mat[4][4]; float mat[3][3], /* 3x3 copy of the view matrix so we can move allong the view axis */ dvec[3]={0,0,0}, /* this is the direction thast added to the view offset per redraw */ @@ -638,8 +703,6 @@ static int flyApply(bContext *C, FlyInfo *fly) printf("fly timer %d\n", iteration++); #endif - if(fly->root_parent) - ED_view3d_to_m4(prev_view_mat, fly->rv3d->ofs, fly->rv3d->viewquat, fly->rv3d->dist); xmargin= ar->winx/20.0f; ymargin= ar->winy/20.0f; @@ -756,7 +819,7 @@ static int flyApply(bContext *C, FlyInfo *fly) mul_m3_v3(mat, upvec); } - axis_angle_to_quat( tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC); /* Rotate about the relative up vec */ + axis_angle_to_quat(tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC); /* Rotate about the relative up vec */ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); if (fly->xlock) fly->xlock = 2;/*check for rotation*/ @@ -850,69 +913,9 @@ static int flyApply(bContext *C, FlyInfo *fly) ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X off/Z off, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB"); #endif - /* we are in camera view so apply the view ofs and quat to the view matrix and set the camera to the view */ - if (rv3d->persp==RV3D_CAMOB) { - ID *id_key; - /* transform the parent or the camera? */ - if(fly->root_parent) { - Object *ob_update; - - float view_mat[4][4]; - float prev_view_imat[4][4]; - float diff_mat[4][4]; - float parent_mat[4][4]; - - invert_m4_m4(prev_view_imat, prev_view_mat); - ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); - mul_m4_m4m4(diff_mat, prev_view_imat, view_mat); - mul_m4_m4m4(parent_mat, fly->root_parent->obmat, diff_mat); - object_apply_mat4(fly->root_parent, parent_mat, TRUE, FALSE); - - // where_is_object(scene, fly->root_parent); - - ob_update= v3d->camera->parent; - while(ob_update) { - DAG_id_tag_update(&ob_update->id, OB_RECALC_OB); - ob_update= ob_update->parent; - } - - copy_m4_m4(prev_view_mat, view_mat); - - id_key= &fly->root_parent->id; + if (rv3d->persp==RV3D_CAMOB) + move_camera(C, rv3d, fly, (fly->xlock || fly->zlock || moffset[0] || moffset[1]), fly->speed); - } - else { - float view_mat[4][4]; - ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); - object_apply_mat4(v3d->camera, view_mat, TRUE, FALSE); - id_key= &v3d->camera->id; - } - - /* record the motion */ - if (autokeyframe_cfra_can_key(scene, id_key)) { - ListBase dsources = {NULL, NULL}; - - /* add datasource override for the camera object */ - ANIM_relative_keyingset_add_source(&dsources, id_key, NULL, NULL); - - /* insert keyframes - * 1) on the first frame - * 2) on each subsequent frame - * TODO: need to check in future that frame changed before doing this - */ - if (fly->xlock || fly->zlock || moffset[0] || moffset[1]) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation"); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); - } - if (fly->speed) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location"); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); - } - - /* free temp data */ - BLI_freelistN(&dsources); - } - } } else /*were not redrawing but we need to update the time else the view will jump */ fly->time_lastdraw= PIL_check_seconds_timer(); @@ -931,13 +934,8 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) RegionView3D* rv3d = fly->rv3d; const int flag = U.ndof_flag; - const int shouldRotate = TRUE, - shouldTranslate = TRUE; - - // const int shouldRotate = flag & NDOF_SHOULD_ROTATE, - // shouldTranslate = flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM); - // might also be something in FlyInfo that restricts motion - // if so, change these ^^ + int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE), + shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM)); float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); @@ -959,22 +957,36 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) forward_sensitivity * ndof->tz }; + if (fly->use_precision) + speed *= 0.2f; + mul_v3_fl(trans, speed * dt); // transform motion from view to world coordinates mul_qt_v3(view_inv, trans); if (flag & NDOF_FLY_HELICOPTER) - // could also use RNA to get a simple boolean value { // replace world z component with device y (yes it makes sense) trans[2] = speed * dt * vertical_sensitivity * ndof->ty; } - // move center of view opposite of hand motion (this is camera mode, not object mode) - sub_v3_v3(rv3d->ofs, trans); + if (rv3d->persp==RV3D_CAMOB) { + // respect camera position locks + Object *lock_ob= fly->root_parent ? fly->root_parent : fly->v3d->camera; + if (lock_ob->protectflag & OB_LOCK_LOCX) trans[0] = 0.0; + if (lock_ob->protectflag & OB_LOCK_LOCY) trans[1] = 0.0; + if (lock_ob->protectflag & OB_LOCK_LOCZ) trans[2] = 0.0; + } - fly->redraw = 1; + if (trans[0] || trans[1] || trans[2]) + { + // move center of view opposite of hand motion (this is camera mode, not object mode) + sub_v3_v3(rv3d->ofs, trans); + shouldTranslate = TRUE; + } + else + shouldTranslate = FALSE; } if (shouldRotate) @@ -985,44 +997,60 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) float axis[3]; float angle = turn_sensitivity * ndof_to_angle_axis(ndof, axis); - // transform rotation axis from view to world coordinates - mul_qt_v3(view_inv, axis); + if (fabsf(angle) > 0.0001f) + { + shouldRotate = TRUE; - // apply rotation to view - axis_angle_to_quat(rotation, axis, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + if (fly->use_precision) + angle *= 0.2f; - if (flag & NDOF_LOCK_HORIZON) - // force an upright viewpoint - // TODO: make this less... sudden - { - float view_horizon[3] = {1, 0, 0}; // view +x - float view_direction[3] = {0, 0, -1}; // view -z (into screen) + // transform rotation axis from view to world coordinates + mul_qt_v3(view_inv, axis); - // find new inverse since viewquat has changed - invert_qt_qt(view_inv, rv3d->viewquat); - // could apply reverse rotation to existing view_inv to save a few cycles + // apply rotation to view + axis_angle_to_quat(rotation, axis, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); - // transform view vectors to world coordinates - mul_qt_v3(view_inv, view_horizon); - mul_qt_v3(view_inv, view_direction); + if (flag & NDOF_LOCK_HORIZON) + // force an upright viewpoint + // TODO: make this less... sudden + { + float view_horizon[3] = {1, 0, 0}; // view +x + float view_direction[3] = {0, 0, -1}; // view -z (into screen) - // find difference between view & world horizons - // true horizon lives in world xy plane, so look only at difference in z - angle = -asinf(view_horizon[2]); + // find new inverse since viewquat has changed + invert_qt_qt(view_inv, rv3d->viewquat); + // could apply reverse rotation to existing view_inv to save a few cycles - #ifdef NDOF_FLY_DEBUG - printf("lock horizon: adjusting %.1f degrees\n\n", RAD2DEG(angle)); - #endif + // transform view vectors to world coordinates + mul_qt_v3(view_inv, view_horizon); + mul_qt_v3(view_inv, view_direction); - // rotate view so view horizon = world horizon - axis_angle_to_quat(rotation, view_direction, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + // find difference between view & world horizons + // true horizon lives in world xy plane, so look only at difference in z + angle = -asinf(view_horizon[2]); + + #ifdef NDOF_FLY_DEBUG + printf("lock horizon: adjusting %.1f degrees\n\n", RAD2DEG(angle)); + #endif + + // rotate view so view horizon = world horizon + axis_angle_to_quat(rotation, view_direction, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + } + + rv3d->view = RV3D_VIEW_USER; } + else + shouldRotate = FALSE; + } - rv3d->view = RV3D_VIEW_USER; + if (shouldTranslate || shouldRotate) + { + fly->redraw = TRUE; - fly->redraw = 1; + if (rv3d->persp==RV3D_CAMOB) + move_camera(C, rv3d, fly, shouldRotate, shouldTranslate); } return OPERATOR_FINISHED; -- cgit v1.2.3 From f4293067c1420827ddfa62e62430870c6b790a8a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 31 Jul 2011 03:15:37 +0000 Subject: py api: sphinx doc corrections, pep8 cleanup and style edits, also added __all__ to some modules which were missing it. --- source/blender/python/intern/bpy_rna.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 2dcfe3731c7..502b25842de 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -6411,7 +6411,9 @@ PyDoc_STRVAR(pyrna_register_class_doc, " If the class has a *register* class method it will be called\n" " before registration.\n" "\n" -" .. note:: :exc:`ValueError` exception is raised if the class is not a\n" +" .. note::\n" +"\n" +" :exc:`ValueError` exception is raised if the class is not a\n" " subclass of a registerable blender class.\n" "\n" ); -- cgit v1.2.3 From e8c3c4097a146b059fa52893a2a1b6e89cdb3094 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Sun, 31 Jul 2011 06:03:14 +0000 Subject: SVN maintenance. --- source/blender/editors/interface/interface_anim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 03003173e20..d9691819b29 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -1,5 +1,5 @@ /* - * $Id: + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * -- cgit v1.2.3 From 679b528177a29a1008efe26daeebef31d73978c1 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 31 Jul 2011 06:26:03 +0000 Subject: fix for immobile camera (NDOF_SHOULD_ROTATE etc.) -- should revisit later --- source/blender/editors/space_view3d/view3d_fly.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 34e355c977e..38d93ab59f3 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -29,7 +29,7 @@ /* defines VIEW3D_OT_fly modal operator */ -// #define NDOF_FLY_DEBUG +//#define NDOF_FLY_DEBUG #include "DNA_anim_types.h" #include "DNA_scene_types.h" @@ -145,7 +145,6 @@ void fly_modal_keymap(wmKeyConfig *keyconf) /* assign map to operators */ WM_modalkeymap_assign(keymap, "VIEW3D_OT_fly"); - } typedef struct FlyInfo { @@ -670,7 +669,6 @@ static void move_camera(bContext* C, RegionView3D* rv3d, FlyInfo* fly, int orien static int flyApply(bContext *C, FlyInfo *fly) { - #define FLY_ROTATE_FAC 2.5f /* more is faster */ #define FLY_ZUP_CORRECT_FAC 0.1f /* amount to correct per step */ #define FLY_ZUP_CORRECT_ACCEL 0.05f /* increase upright momentum each step */ @@ -934,13 +932,16 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) RegionView3D* rv3d = fly->rv3d; const int flag = U.ndof_flag; - int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE), - shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM)); +// int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE), +// shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM)); + + int shouldRotate = (fly->pan_view == FALSE), + shouldTranslate = TRUE; float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); - rv3d->rot_angle = 0; // disable onscreen rotation doo-dad + rv3d->rot_angle = 0.f; // disable onscreen rotation doo-dad if (shouldTranslate) { @@ -974,9 +975,9 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) if (rv3d->persp==RV3D_CAMOB) { // respect camera position locks Object *lock_ob= fly->root_parent ? fly->root_parent : fly->v3d->camera; - if (lock_ob->protectflag & OB_LOCK_LOCX) trans[0] = 0.0; - if (lock_ob->protectflag & OB_LOCK_LOCY) trans[1] = 0.0; - if (lock_ob->protectflag & OB_LOCK_LOCZ) trans[2] = 0.0; + if (lock_ob->protectflag & OB_LOCK_LOCX) trans[0] = 0.f; + if (lock_ob->protectflag & OB_LOCK_LOCY) trans[1] = 0.f; + if (lock_ob->protectflag & OB_LOCK_LOCZ) trans[2] = 0.f; } if (trans[0] || trans[1] || trans[2]) @@ -1015,8 +1016,8 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // force an upright viewpoint // TODO: make this less... sudden { - float view_horizon[3] = {1, 0, 0}; // view +x - float view_direction[3] = {0, 0, -1}; // view -z (into screen) + float view_horizon[3] = {1.f, 0.f, 0.f}; // view +x + float view_direction[3] = {0.f, 0.f, -1.f}; // view -z (into screen) // find new inverse since viewquat has changed invert_qt_qt(view_inv, rv3d->viewquat); @@ -1124,6 +1125,7 @@ static int fly_modal(bContext *C, wmOperator *op, wmEvent *event) WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, fly_object); } + // puts("redraw!"); // too frequent, fix tomorrow. ED_region_tag_redraw(CTX_wm_region(C)); } -- cgit v1.2.3 From f4a1dc4c8dd353aa614bc7c00846e5076ddc2dc2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 31 Jul 2011 07:58:50 +0000 Subject: when converting curves from poly -> nurbs, dont enable Bezier-U flag. Not sure why this was enabled, possibly from copy/paste with bezier->nurbs code? If you have meny poly lines there was no nice way to convert these into a smoothed nurbs curve. Ran into this when trying to convert generated ivy into smooth nurbs. --- source/blender/editors/curve/editcurve.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 8b9477adf92..210f36ca074 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -3432,7 +3432,6 @@ static int convertspline(short type, Nurb *nu) nu->type = CU_NURBS; nu->orderu= 4; nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */ - nu->flagu |= CU_NURB_BEZIER; nurbs_knot_calc_u(nu); a= nu->pntsu*nu->pntsv; bp= nu->bp; -- cgit v1.2.3 From 432bd158fbdb9d56f9499dcc0e465f4e148abbf3 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Sun, 31 Jul 2011 11:12:38 +0000 Subject: bugfix [#28111] material.pop breaks mt->mat_nr create a new parameter for materials.pop() to not remove material slot. this way the mat_nr is still the old one. for the default behaviour we now have material remapping (i.e. data_delete_material_index_id(id, index)). This new function is brought from the material_slot remove function. --- source/blender/blenkernel/BKE_material.h | 2 +- source/blender/blenkernel/intern/material.c | 101 +++++++++++++++++----------- source/blender/blenkernel/intern/mesh.c | 4 +- source/blender/makesrna/intern/rna_ID.c | 1 + 4 files changed, 66 insertions(+), 42 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index c445408609c..88965d12e4a 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -78,7 +78,7 @@ int object_remove_material_slot(struct Object *ob); /* rna api */ void material_append_id(struct ID *id, struct Material *ma); -struct Material *material_pop_id(struct ID *id, int index); +struct Material *material_pop_id(struct ID *id, int index, int remove_material_slot); /* rendering */ diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 3f01c55e935..1f2544c9706 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -61,7 +61,7 @@ #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_node.h" - +#include "BKE_curve.h" #include "GPU_material.h" @@ -515,6 +515,37 @@ short *give_totcolp_id(ID *id) return NULL; } +void data_delete_material_index_id(ID *id, int index) +{ + Mesh *me; + Curve *cu; + Nurb *nu; + int curvetype; + + switch(GS(id->name)) { + case ID_ME: + me=(Mesh *)id; + mesh_delete_material_index(me, index); + break; + case ID_CU: + cu= (Curve *)id; + nu= cu->nurb.first; + + curvetype=curve_type(cu); + if (!ELEM(curvetype, OB_CURVE, OB_SURF)) + return; + + while (nu) { + if(nu->mat_nr && nu->mat_nr>=index) { + nu->mat_nr--; + if (curvetype == OB_CURVE) nu->charidx--; + } + nu= nu->next; + } + break; + } +} + void material_append_id(ID *id, Material *ma) { Material ***matar; @@ -532,7 +563,7 @@ void material_append_id(ID *id, Material *ma) } } -Material *material_pop_id(ID *id, int index) +Material *material_pop_id(ID *id, int index, int remove_material_slot) { Material *ret= NULL; Material ***matar; @@ -540,27 +571,36 @@ Material *material_pop_id(ID *id, int index) short *totcol= give_totcolp_id(id); if(index >= 0 && index < (*totcol)) { ret= (*matar)[index]; - id_us_min((ID *)ret); - if(*totcol <= 1) { - *totcol= 0; - MEM_freeN(*matar); - *matar= NULL; - } - else { - Material **mat; - - if(index + 1 != (*totcol)) - memmove((*matar)+index, (*matar)+(index+1), sizeof(void *) * ((*totcol) - (index + 1))); + id_us_min((ID *)ret); - (*totcol)--; - - mat= MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); - memcpy(mat, *matar, sizeof(void *) * (*totcol)); - MEM_freeN(*matar); + if (remove_material_slot) { + if(*totcol <= 1) { + *totcol= 0; + MEM_freeN(*matar); + *matar= NULL; + } + else { + Material **mat; + if(index + 1 != (*totcol)) + memmove((*matar)+index, (*matar)+(index+1), sizeof(void *) * ((*totcol) - (index + 1))); + + (*totcol)--; + + mat= MEM_callocN(sizeof(void *) * (*totcol), "newmatar"); + memcpy(mat, *matar, sizeof(void *) * (*totcol)); + MEM_freeN(*matar); + + *matar= mat; + test_object_materials(id); + } - *matar= mat; - test_object_materials(id); + /* decrease mat_nr index */ + data_delete_material_index_id(id, index); } + + /* don't remove material slot, only clear it*/ + else + (*matar)[index]= NULL; } } @@ -1025,8 +1065,6 @@ int object_remove_material_slot(Object *ob) { Material *mao, ***matarar; Object *obt; - Curve *cu; - Nurb *nu; short *totcolp; int a, actcol; @@ -1086,23 +1124,8 @@ int object_remove_material_slot(Object *ob) } /* check indices from mesh */ - - if(ob->type==OB_MESH) { - Mesh *me= get_mesh(ob); - mesh_delete_material_index(me, actcol-1); - freedisplist(&ob->disp); - } - else if ELEM(ob->type, OB_CURVE, OB_SURF) { - cu= ob->data; - nu= cu->nurb.first; - - while(nu) { - if(nu->mat_nr && nu->mat_nr>=actcol-1) { - nu->mat_nr--; - if (ob->type == OB_CURVE) nu->charidx--; - } - nu= nu->next; - } + if (ELEM3(ob->type, OB_MESH, OB_CURVE, OB_SURF)) { + data_delete_material_index_id(&ob->id, actcol-1); freedisplist(&ob->disp); } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 45a60b842a7..32819226361 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1254,10 +1254,10 @@ void mesh_to_curve(Scene *scene, Object *ob) void mesh_delete_material_index(Mesh *me, int index) { + MFace *mf; int i; - for (i=0; itotface; i++) { - MFace *mf = &((MFace*) me->mface)[i]; + for (i=0, mf=me->mface; itotface; i++, mf++) { if (mf->mat_nr && mf->mat_nr>=index) mf->mat_nr--; } diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 3ce84e3a19f..6d7fc0ee57b 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -418,6 +418,7 @@ static void rna_def_ID_materials(BlenderRNA *brna) RNA_def_function_ui_description(func, "Remove a material from the data block."); parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Index of material to remove.", 0, INT_MAX); RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_boolean(func, "remove_material_slot", 1, "", "Remove the material slot and assign 1st material to old faces."); parm= RNA_def_pointer(func, "material", "Material", "", "Material to remove."); RNA_def_function_return(func, parm); } -- cgit v1.2.3 From c74bb09584371520b9b557cbaa8ae13356bf5e1a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 31 Jul 2011 12:43:41 +0000 Subject: fix for material slot removal (r38879) - The object ID was being passed to the data_delete_material_index_id() from object_remove_material_slot(), rather then the object data. (so the material slot fix wouldnt run in that case). - add support for fixing text object materials too. --- source/blender/blenkernel/BKE_curve.h | 1 + source/blender/blenkernel/intern/curve.c | 25 ++++++++++++++++++++++++ source/blender/blenkernel/intern/material.c | 30 +++++++---------------------- source/blender/makesrna/intern/rna_ID.c | 5 +++-- 4 files changed, 36 insertions(+), 25 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 0491116d199..557ce417b14 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -115,5 +115,6 @@ int minmax_curve(struct Curve *cu, float min[3], float max[3]); int curve_center_median(struct Curve *cu, float cent[3]); int curve_center_bounds(struct Curve *cu, float cent[3]); void curve_translate(struct Curve *cu, float offset[3], int do_keys); +void curve_delete_material_index(struct Curve *cu, int index); #endif diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 202a3f28d9a..66ab11938f3 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -3259,3 +3259,28 @@ void curve_translate(Curve *cu, float offset[3], int do_keys) } } } + +void curve_delete_material_index(Curve *cu, int index) +{ + const int curvetype= curve_type(cu); + + if(curvetype == OB_FONT) { + struct CharInfo *info= cu->strinfo; + int i; + for(i= cu->len-1; i >= 0; i--, info++) { + if (info->mat_nr && info->mat_nr>=index) { + info->mat_nr--; + } + } + } + else { + Nurb *nu; + + for (nu= cu->nurb.first; nu; nu= nu->next) { + if(nu->mat_nr && nu->mat_nr>=index) { + nu->mat_nr--; + if (curvetype == OB_CURVE) nu->charidx--; + } + } + } +} diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 1f2544c9706..9c455e84109 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -517,31 +517,15 @@ short *give_totcolp_id(ID *id) void data_delete_material_index_id(ID *id, int index) { - Mesh *me; - Curve *cu; - Nurb *nu; - int curvetype; - switch(GS(id->name)) { case ID_ME: - me=(Mesh *)id; - mesh_delete_material_index(me, index); + mesh_delete_material_index((Mesh *)id, index); break; case ID_CU: - cu= (Curve *)id; - nu= cu->nurb.first; - - curvetype=curve_type(cu); - if (!ELEM(curvetype, OB_CURVE, OB_SURF)) - return; - - while (nu) { - if(nu->mat_nr && nu->mat_nr>=index) { - nu->mat_nr--; - if (curvetype == OB_CURVE) nu->charidx--; - } - nu= nu->next; - } + curve_delete_material_index((Curve *)id, index); + break; + case ID_MB: + /* meta-elems dont have materials atm */ break; } } @@ -1124,8 +1108,8 @@ int object_remove_material_slot(Object *ob) } /* check indices from mesh */ - if (ELEM3(ob->type, OB_MESH, OB_CURVE, OB_SURF)) { - data_delete_material_index_id(&ob->id, actcol-1); + if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) { + data_delete_material_index_id((ID *)ob->data, actcol-1); freedisplist(&ob->disp); } diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 6d7fc0ee57b..8d57403ec35 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -35,6 +35,7 @@ #include "DNA_ID.h" #include "DNA_vfont_types.h" +#include "DNA_material_types.h" #include "DNA_object_types.h" #include "WM_types.h" @@ -416,9 +417,9 @@ static void rna_def_ID_materials(BlenderRNA *brna) func= RNA_def_function(srna, "pop", "material_pop_id"); RNA_def_function_ui_description(func, "Remove a material from the data block."); - parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Index of material to remove.", 0, INT_MAX); + parm= RNA_def_int(func, "index", 0, 0, MAXMAT, "", "Index of material to remove.", 0, MAXMAT); RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_boolean(func, "remove_material_slot", 1, "", "Remove the material slot and assign 1st material to old faces."); + RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned."); parm= RNA_def_pointer(func, "material", "Material", "", "Material to remove."); RNA_def_function_return(func, parm); } -- cgit v1.2.3 From 5c8344bcc9f8f2c319346420766d9e4110beb607 Mon Sep 17 00:00:00 2001 From: Janne Karhu Date: Sun, 31 Jul 2011 16:26:02 +0000 Subject: Bug fix: loading a file that had particles using a dupligroup from a liblinked file without the library file being present crashed --- source/blender/blenloader/intern/readfile.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4ad99c02b2d..0633794c6ed 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3162,7 +3162,7 @@ static void lib_link_particlesettings(FileData *fd, Main *main) if(part->effector_weights) part->effector_weights->group = newlibadr(fd, part->id.lib, part->effector_weights->group); - if(part->dupliweights.first) { + if(part->dupliweights.first && part->dup_group) { int index_ok = 0; /* check for old files without indices (all indexes 0) */ dw = part->dupliweights.first; @@ -3193,6 +3193,9 @@ static void lib_link_particlesettings(FileData *fd, Main *main) dw->ob = newlibadr(fd, part->id.lib, dw->ob); } } + else { + part->dupliweights.first = part->dupliweights.last = NULL; + } if(part->boids) { BoidState *state = part->boids->states.first; -- cgit v1.2.3 From f48b9062619ecc685e81dca12d588f5524efe41d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 1 Aug 2011 02:52:08 +0000 Subject: fix for failure to create curve knots when both endpoint and bezier U were enabled. use default when invalid settings given. removed odd/annoying bit shifting of the flagu/v for such basic function made code hard to understand and would fail if new flags were added. --- source/blender/blenkernel/intern/curve.c | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 66ab11938f3..07e450479e4 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -580,29 +580,24 @@ void addNurbPointsBezier(Nurb *nu, int number) /* ~~~~~~~~~~~~~~~~~~~~Non Uniform Rational B Spline calculations ~~~~~~~~~~~ */ -static void calcknots(float *knots, short aantal, short order, short type) -/* knots: number of pnts NOT corrected for cyclic */ -/* type; 0: uniform, 1: endpoints, 2: bezier */ +static void calcknots(float *knots, const short aantal, const short order, const short flag) { + /* knots: number of pnts NOT corrected for cyclic */ + const int t= aantal + order; float k; - int a, t; - - t = aantal+order; - if(type==0) { + int a; - for(a=0;a=order && a<=aantal) k+= 1.0f; } - } - else if(type==2) { - /* Warning, the order MUST be 2 or 4, if this is not enforced, the displist will be corrupt */ + break; + case CU_NURB_BEZIER: + /* Warning, the order MUST be 2 or 4, + * if this is not enforced, the displist will be corrupt */ if(order==4) { k= 0.34; for(a=0;aknotsu, nu->pntsu, nu->orderu, 0); /* cyclic should be uniform */ makecyclicknots(nu->knotsu, nu->pntsu, nu->orderu); } else { - calcknots(nu->knotsu, nu->pntsu, nu->orderu, nu->flagu>>1); + calcknots(nu->knotsu, nu->pntsu, nu->orderu, nu->flagu); } } else nu->knotsu= NULL; @@ -675,7 +676,7 @@ static void makeknots(Nurb *nu, short uv) calcknots(nu->knotsv, nu->pntsv, nu->orderv, 0); /* cyclic should be uniform */ makecyclicknots(nu->knotsv, nu->pntsv, nu->orderv); } else { - calcknots(nu->knotsv, nu->pntsv, nu->orderv, nu->flagv>>1); + calcknots(nu->knotsv, nu->pntsv, nu->orderv, nu->flagv); } } else nu->knotsv= NULL; -- cgit v1.2.3 From 9da712a581f59fc7794151fe5f07a4fb396881f2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 1 Aug 2011 02:58:44 +0000 Subject: replace dutch variable name 'aantal' with 'tot' --- source/blender/blenkernel/intern/curve.c | 16 ++++++++-------- source/blender/blenkernel/intern/key.c | 8 ++++---- source/blender/editors/space_view3d/view3d_select.c | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 07e450479e4..7aa28c3f681 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -580,19 +580,19 @@ void addNurbPointsBezier(Nurb *nu, int number) /* ~~~~~~~~~~~~~~~~~~~~Non Uniform Rational B Spline calculations ~~~~~~~~~~~ */ -static void calcknots(float *knots, const short aantal, const short order, const short flag) +static void calcknots(float *knots, const short tot, const short order, const short flag) { /* knots: number of pnts NOT corrected for cyclic */ - const int t= aantal + order; + const int tot_order= tot + order; float k; int a; switch(flag & (CU_NURB_ENDPOINT|CU_NURB_BEZIER)) { case CU_NURB_ENDPOINT: k= 0.0; - for(a=1;a<=t;a++) { + for(a=1; a <= tot_order; a++) { knots[a-1]= k; - if(a>=order && a<=aantal) k+= 1.0f; + if(a >= order && a <= tot) k+= 1.0f; } break; case CU_NURB_BEZIER: @@ -600,15 +600,15 @@ static void calcknots(float *knots, const short aantal, const short order, const * if this is not enforced, the displist will be corrupt */ if(order==4) { k= 0.34; - for(a=0;a=order && a<=aantal) k+= 0.5f; + for(a=0; a < tot_order; a++) { + if(a >= order && a <= tot) k+= 0.5f; knots[a]= floorf(k); } } @@ -617,7 +617,7 @@ static void calcknots(float *knots, const short aantal, const short order, const } break; default: - for(a=0;aselcol; - aantal= (size-1)/2; + len= (size-1)/2; rc= 0; dirvec[0][0]= 1; @@ -910,7 +910,7 @@ static unsigned int samplerect(unsigned int *buf, int size, unsigned int dontdo) bufmin= buf; bufmax= buf+ size*size; - buf+= aantal*size+ aantal; + buf+= len*size+ len; for(tel=1;tel<=size;tel++) { -- cgit v1.2.3 From af39f2636019e387dc9f572249c09ad9cf9631bc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 1 Aug 2011 05:25:30 +0000 Subject: fix, uvproject modifier wasn't copying the uv layer name, also edit var names from recent commit to better fit with other functions. --- source/blender/blenkernel/intern/curve.c | 16 ++++++++-------- source/blender/modifiers/intern/MOD_uvproject.c | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 7aa28c3f681..eb364af6ff8 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -580,19 +580,19 @@ void addNurbPointsBezier(Nurb *nu, int number) /* ~~~~~~~~~~~~~~~~~~~~Non Uniform Rational B Spline calculations ~~~~~~~~~~~ */ -static void calcknots(float *knots, const short tot, const short order, const short flag) +static void calcknots(float *knots, const short pnts, const short order, const short flag) { /* knots: number of pnts NOT corrected for cyclic */ - const int tot_order= tot + order; + const int pnts_order= pnts + order; float k; int a; switch(flag & (CU_NURB_ENDPOINT|CU_NURB_BEZIER)) { case CU_NURB_ENDPOINT: k= 0.0; - for(a=1; a <= tot_order; a++) { + for(a=1; a <= pnts_order; a++) { knots[a-1]= k; - if(a >= order && a <= tot) k+= 1.0f; + if(a >= order && a <= pnts) k+= 1.0f; } break; case CU_NURB_BEZIER: @@ -600,15 +600,15 @@ static void calcknots(float *knots, const short tot, const short order, const sh * if this is not enforced, the displist will be corrupt */ if(order==4) { k= 0.34; - for(a=0; a < tot_order; a++) { + for(a=0; a < pnts_order; a++) { knots[a]= floorf(k); k+= (1.0f/3.0f); } } else if(order==3) { k= 0.6f; - for(a=0; a < tot_order; a++) { - if(a >= order && a <= tot) k+= 0.5f; + for(a=0; a < pnts_order; a++) { + if(a >= order && a <= pnts) k+= 0.5f; knots[a]= floorf(k); } } @@ -617,7 +617,7 @@ static void calcknots(float *knots, const short tot, const short order, const sh } break; default: - for(a=0; a < tot_order; a++) { + for(a=0; a < pnts_order; a++) { knots[a]= (float)a; } break; diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index a5d2e0b38c7..922ae8c1e92 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -42,6 +42,7 @@ #include "DNA_object_types.h" #include "BLI_math.h" +#include "BLI_string.h" #include "BLI_uvproject.h" #include "BLI_utildefines.h" @@ -83,6 +84,7 @@ static void copyData(ModifierData *md, ModifierData *target) tumd->aspecty = umd->aspecty; tumd->scalex = umd->scalex; tumd->scaley = umd->scaley; + BLI_strncpy(tumd->uvlayer_name, umd->uvlayer_name, sizeof(umd->uvlayer_name)); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md)) -- cgit v1.2.3 From cd793378dbe7b761e22b2c48540ff2afc92e22ad Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 1 Aug 2011 06:50:24 +0000 Subject: fix [#28112] Vertex paint crash --- source/blender/blenkernel/intern/DerivedMesh.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index d9c98bc0200..62b8830de20 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1883,7 +1883,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos /* set the DerivedMesh to only copy needed data */ mask= (CustomDataMask)GET_INT_FROM_POINTER(curr->link); - DM_set_only_copy(dm, mask); + /* needMapping check here fixes bug [#28112], otherwise its + * possible that it wont be copied */ + DM_set_only_copy(dm, mask | (needMapping ? CD_MASK_ORIGINDEX : 0)); /* add cloth rest shape key if need */ if(mask & CD_MASK_CLOTH_ORCO) -- cgit v1.2.3 From c965d1d2ccfd57926476cb5c091afa35c6de217f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 1 Aug 2011 08:53:57 +0000 Subject: fix [#28061] Texture (paint) bleeding on edges respect clamp u/v image options. --- source/blender/editors/sculpt_paint/paint_image.c | 26 +++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index c9a6aa87cd0..32004fd4525 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -2187,7 +2187,7 @@ static int IsectPoly2Df_twoside(const float pt[2], float uv[][2], const int tot) /* One of the most important function for projectiopn painting, since it selects the pixels to be added into each bucket. * initialize pixels from this face where it intersects with the bucket_index, optionally initialize pixels for removing seams */ -static void project_paint_face_init(const ProjPaintState *ps, const int thread_index, const int bucket_index, const int face_index, const int image_index, rctf *bucket_bounds, const ImBuf *ibuf) +static void project_paint_face_init(const ProjPaintState *ps, const int thread_index, const int bucket_index, const int face_index, const int image_index, rctf *bucket_bounds, const ImBuf *ibuf, const short clamp_u, const short clamp_v) { /* Projection vars, to get the 3D locations into screen space */ MemArena *arena = ps->arena_mt[thread_index]; @@ -2304,14 +2304,24 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i if (pixel_bounds_array(uv_clip, &bounds_px, ibuf->x, ibuf->y, uv_clip_tot)) { - + + if(clamp_u) { + CLAMP(bounds_px.xmin, 0, ibuf->x); + CLAMP(bounds_px.xmax, 0, ibuf->x); + } + + if(clamp_v) { + CLAMP(bounds_px.ymin, 0, ibuf->y); + CLAMP(bounds_px.ymax, 0, ibuf->y); + } + /* clip face and */ has_isect = 0; for (y = bounds_px.ymin; y < bounds_px.ymax; y++) { //uv[1] = (((float)y) + 0.5f) / (float)ibuf->y; uv[1] = (float)y / ibuf_yf; /* use pixel offset UV coords instead */ - + has_x_isect = 0; for (x = bounds_px.xmin; x < bounds_px.xmax; x++) { //uv[0] = (((float)x) + 0.5f) / ibuf->x; @@ -2630,6 +2640,7 @@ static void project_bucket_init(const ProjPaintState *ps, const int thread_index LinkNode *node; int face_index, image_index=0; ImBuf *ibuf = NULL; + Image *ima = NULL; MTFace *tf; Image *tpage_last = NULL; @@ -2638,9 +2649,10 @@ static void project_bucket_init(const ProjPaintState *ps, const int thread_index if (ps->image_tot==1) { /* Simple loop, no context switching */ ibuf = ps->projImages[0].ibuf; - + ima = ps->projImages[0].ima; + for (node = ps->bucketFaces[bucket_index]; node; node= node->next) { - project_paint_face_init(ps, thread_index, bucket_index, GET_INT_FROM_POINTER(node->link), 0, bucket_bounds, ibuf); + project_paint_face_init(ps, thread_index, bucket_index, GET_INT_FROM_POINTER(node->link), 0, bucket_bounds, ibuf, ima->tpageflag & IMA_CLAMP_U, ima->tpageflag & IMA_CLAMP_V); } } else { @@ -2659,14 +2671,14 @@ static void project_bucket_init(const ProjPaintState *ps, const int thread_index for (image_index=0; image_index < ps->image_tot; image_index++) { if (ps->projImages[image_index].ima == tpage_last) { ibuf = ps->projImages[image_index].ibuf; + ima = ps->projImages[image_index].ima; break; } } } /* context switching done */ - project_paint_face_init(ps, thread_index, bucket_index, face_index, image_index, bucket_bounds, ibuf); - + project_paint_face_init(ps, thread_index, bucket_index, face_index, image_index, bucket_bounds, ibuf, ima->tpageflag & IMA_CLAMP_U, ima->tpageflag & IMA_CLAMP_V); } } -- cgit v1.2.3 From db494472ac02ff73dbc0984940e7758321e5642d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 02:28:37 +0000 Subject: don't include fcurve modifiers when getting an actions frame range. could too easily give a range of 600,000 which would make exporters hang. --- source/blender/makesrna/intern/rna_action.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c index 7fdb96fda6e..cfedee3c6cd 100644 --- a/source/blender/makesrna/intern/rna_action.c +++ b/source/blender/makesrna/intern/rna_action.c @@ -191,8 +191,9 @@ static void rna_Action_active_pose_marker_index_range(PointerRNA *ptr, int *min, static void rna_Action_frame_range_get(PointerRNA *ptr,float *values) -{ - calc_action_range(ptr->id.data, values, values+1, 1); +{ /* don't include modifiers because they too easily can have very large + * ranges: MINAFRAMEF to MAXFRAMEF. */ + calc_action_range(ptr->id.data, values, values+1, FALSE); } -- cgit v1.2.3 From fcd7d2b486f2435907423188ffdfe2840c966b0b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 05:52:27 +0000 Subject: NDOF related edits - fix for building without NDOF on X11 - quiet some warnings --- source/blender/editors/space_image/image_ops.c | 2 +- source/blender/editors/space_view3d/view3d_edit.c | 4 ++-- source/blender/windowmanager/intern/wm_operators.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 204d5dfb1b1..a7c90bb0aed 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -445,7 +445,7 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) * that explains the negative signs in the code below */ -static int view_ndof_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) { SpaceImage *sima= CTX_wm_space_image(C); ARegion *ar= CTX_wm_region(C); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 94224698063..09e703d6ce0 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -968,7 +968,7 @@ void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]) q[3] = scale * z; } -static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) // -- "orbit" navigation (trackball/turntable) // -- zooming // -- panning in rotationally-locked views @@ -1118,7 +1118,7 @@ void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot) ot->flag = 0; } -static int ndof_pan_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) // -- "pan" navigation // -- zoom or dolly? { diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index d813fd913ab..d9c3300fcef 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1411,7 +1411,7 @@ static void WM_OT_search_menu(wmOperatorType *ot) ot->poll= wm_search_menu_poll; } -static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +static int wm_ndof_menu_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) { uiPupMenuInvoke(C,"VIEW3D_MT_ndof_settings"); -- cgit v1.2.3 From ed306416f5db7516be502b69b677e90a332c3b91 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 06:40:40 +0000 Subject: replace WM_OT_ndof_menu with a key->menu assignment. --- source/blender/windowmanager/intern/wm_operators.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index d9c3300fcef..7dc4bfb65a6 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1411,22 +1411,6 @@ static void WM_OT_search_menu(wmOperatorType *ot) ot->poll= wm_search_menu_poll; } -static int wm_ndof_menu_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) -{ - uiPupMenuInvoke(C,"VIEW3D_MT_ndof_settings"); - - return OPERATOR_FINISHED; // <-- correct? - return OPERATOR_CANCELLED; // <-- correct? -} - -static void WM_OT_ndof_menu(wmOperatorType *ot) -{ - ot->name = "NDOF Menu"; - ot->idname = "WM_OT_ndof_menu"; - - ot->invoke = wm_ndof_menu_invoke; -} - static int wm_call_menu_exec(bContext *C, wmOperator *op) { char idname[BKE_ST_MAXNAME]; @@ -3517,7 +3501,6 @@ void wm_operatortype_init(void) WM_operatortype_append(WM_OT_debug_menu); WM_operatortype_append(WM_OT_splash); WM_operatortype_append(WM_OT_search_menu); - WM_operatortype_append(WM_OT_ndof_menu); WM_operatortype_append(WM_OT_call_menu); WM_operatortype_append(WM_OT_radial_control); WM_operatortype_append(WM_OT_ndof_sensitivity_change); @@ -3743,7 +3726,7 @@ void wm_window_keymap(wmKeyConfig *keyconf) /* menus that can be accessed anywhere in blender */ WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "WM_OT_ndof_menu", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); + WM_keymap_add_menu(keymap, "VIEW3D_MT_ndof_settings", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); /* Space switching */ kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */ -- cgit v1.2.3 From 70b4758ff8756a55a1c88156a852b80a0d3c2ef9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 07:08:22 +0000 Subject: Made wmNDOFMotionData use a vector rather then xyz members, makes it nicer to use with math functions. ndof_to_angle_axis and ndof_to_quat now use math functions. --- source/blender/editors/space_image/image_ops.c | 6 +-- source/blender/editors/space_view3d/view3d_edit.c | 63 +++++++--------------- source/blender/editors/space_view3d/view3d_fly.c | 8 +-- source/blender/editors/transform/transform_ops.c | 6 +-- source/blender/windowmanager/WM_types.h | 4 +- .../blender/windowmanager/intern/wm_event_system.c | 12 ++--- 6 files changed, 37 insertions(+), 62 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index a7c90bb0aed..6e84c1a7f0c 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -461,8 +461,8 @@ static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) const float zoom_sensitivity = 0.5f; const float pan_sensitivity = 300.f; - float pan_x = pan_sensitivity * dt * ndof->tx / sima->zoom; - float pan_y = pan_sensitivity * dt * ndof->ty / sima->zoom; + float pan_x = pan_sensitivity * dt * ndof->tvec[0] / sima->zoom; + float pan_y = pan_sensitivity * dt * ndof->tvec[1] / sima->zoom; /* "mouse zoom" factor = 1 + (dx + dy) / 300 * what about "ndof zoom" factor? should behave like this: @@ -470,7 +470,7 @@ static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) * move forward -> factor > 1 * move backward -> factor < 1 */ - float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->tz; + float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->tvec[2]; sima_zoom_set_factor(sima, ar, zoom_factor); sima->xof += pan_x; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 09e703d6ce0..8d77aeaea1b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -931,42 +931,18 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) // NDOF utility functions // (should these functions live in this file?) float ndof_to_angle_axis(struct wmNDOFMotionData* ndof, float axis[3]) - { - const float x = ndof->rx; - const float y = ndof->ry; - const float z = ndof->rz; - - float angular_velocity = sqrtf(x*x + y*y + z*z); - float angle = ndof->dt * angular_velocity; - - float scale = 1.f / angular_velocity; - - // normalize - axis[0] = scale * x; - axis[1] = scale * y; - axis[2] = scale * z; - - return angle; - } +{ + return ndof->dt * normalize_v3_v3(axis, ndof->rvec); +} void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]) - { - const float x = ndof->rx; - const float y = ndof->ry; - const float z = ndof->rz; - - float angular_velocity = sqrtf(x*x + y*y + z*z); - float angle = ndof->dt * angular_velocity; - - // combined scaling factor -- normalize axis while converting to quaternion - float scale = sin(0.5f * angle) / angular_velocity; +{ + float axis[3]; + float angle; - // convert axis-angle to quaternion - q[0] = cos(0.5f * angle); - q[1] = scale * x; - q[2] = scale * y; - q[3] = scale * z; - } + angle= ndof_to_angle_axis(ndof, axis); + axis_angle_to_quat(q, axis, angle); +} static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) // -- "orbit" navigation (trackball/turntable) @@ -987,7 +963,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event const float pan_sensitivity = 1.f; // rather have bool, but... - int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz); + int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec); float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); @@ -998,19 +974,19 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt); #endif - if (ndof->tz) { + if (ndof->tvec[2]) { // Zoom! // velocity should be proportional to the linear velocity attained by rotational motion of same strength // [got that?] // proportional to arclength = radius * angle - float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; + float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tvec[2]; rv3d->dist += zoom_distance; } if (rv3d->viewlock == RV3D_LOCKED) { /* rotation not allowed -- explore panning options instead */ - float pan_vec[3] = {ndof->tx, ndof->ty, 0}; + float pan_vec[3] = {ndof->tvec[0], ndof->tvec[1], 0.0f}; mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); /* transform motion from view to world coordinates */ @@ -1072,7 +1048,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event mul_qt_v3(view_inv, xvec); /* Perform the up/down rotation */ - angle = rot_sensitivity * dt * ndof->rx; + angle = rot_sensitivity * dt * ndof->rvec[0]; if (invert) angle = -angle; rot[0] = cos(angle); @@ -1080,7 +1056,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); /* Perform the orbital rotation */ - angle = rot_sensitivity * dt * ndof->ry; + angle = rot_sensitivity * dt * ndof->rvec[1]; if (invert) angle = -angle; @@ -1155,11 +1131,10 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) const float vertical_sensitivity = 0.4f; const float lateral_sensitivity = 0.6f; - float pan_vec[3] = { - lateral_sensitivity * ndof->tx, - vertical_sensitivity * ndof->ty, - forward_sensitivity * ndof->tz - }; + float pan_vec[3] = {lateral_sensitivity * ndof->tvec[0], + vertical_sensitivity * ndof->tvec[1], + forward_sensitivity * ndof->tvec[2] + }; mul_v3_fl(pan_vec, speed * dt); #endif diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 38d93ab59f3..5c53faf96a6 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -953,9 +953,9 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // ^^ this is ok for default cube scene, but should scale with.. something float trans[3] = { - lateral_sensitivity * ndof->tx, - vertical_sensitivity * ndof->ty, - forward_sensitivity * ndof->tz + lateral_sensitivity * ndof->tvec[0], + vertical_sensitivity * ndof->tvec[1], + forward_sensitivity * ndof->tvec[2] }; if (fly->use_precision) @@ -969,7 +969,7 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) if (flag & NDOF_FLY_HELICOPTER) { // replace world z component with device y (yes it makes sense) - trans[2] = speed * dt * vertical_sensitivity * ndof->ty; + trans[2] = speed * dt * vertical_sensitivity * ndof->tvec[1]; } if (rv3d->persp==RV3D_CAMOB) { diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index a779982099e..0efd25c4faa 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -361,10 +361,10 @@ static int transform_modal(bContext *C, wmOperator *op, wmEvent *event) TransInfo *t = op->customdata; if (event->type == NDOF_MOTION) - { - // puts("transform_modal: passing through NDOF_MOTION"); + { + /* puts("transform_modal: passing through NDOF_MOTION"); */ return OPERATOR_PASS_THROUGH; - } + } /* XXX insert keys are called here, and require context */ t->context= C; diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 7476410ec19..7fd52e89a5f 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -389,8 +389,8 @@ typedef struct wmNDOFMotionData { /* awfully similar to GHOST_TEventNDOFMotionData... */ // Each component normally ranges from -1 to +1, but can exceed that. // These use blender standard view coordinates, with positive rotations being CCW about the axis. - float tx, ty, tz; // translation - float rx, ry, rz; // rotation: + float tvec[3]; // translation + float rvec[3]; // rotation: // axis = (rx,ry,rz).normalized // amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg] float dt; // time since previous NDOF Motion event diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 322cd3b5642..0abae2e06b7 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2323,13 +2323,13 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g const float s = U.ndof_sensitivity; - data->tx = s * ghost->tx; - data->ty = s * ghost->ty; - data->tz = s * ghost->tz; + data->tvec[0]= s * ghost->tx; + data->tvec[1]= s * ghost->ty; + data->tvec[2]= s * ghost->tz; - data->rx = s * ghost->rx; - data->ry = s * ghost->ry; - data->rz = s * ghost->rz; + data->rvec[0]= s * ghost->rx; + data->rvec[1]= s * ghost->ry; + data->rvec[2]= s * ghost->rz; data->dt = ghost->dt; -- cgit v1.2.3 From d4a6884fcfbedcb1b13f65b071bfcf1e04f3ef9d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 07:49:34 +0000 Subject: add back timer based redraw, not sure why this was removed r38908. Zealous redraws now use commented define. --- source/blender/editors/space_view3d/view3d_fly.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 5c53faf96a6..ca64476b35e 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -30,6 +30,7 @@ /* defines VIEW3D_OT_fly modal operator */ //#define NDOF_FLY_DEBUG +//#define NDOF_FLY_DRAW_TOOMUCH // is this needed for ndof? - commented so redraw doesnt thrash - campbell #include "DNA_anim_types.h" #include "DNA_scene_types.h" @@ -289,8 +290,10 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->zlock_momentum=0.0f; fly->grid= 1.0f; fly->use_precision= 0; - fly->redraw= 1; +#ifdef NDOF_FLY_DRAW_TOOMUCH + fly->redraw= 1; +#endif fly->dvec_prev[0]= fly->dvec_prev[1]= fly->dvec_prev[2]= 0.0f; fly->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); @@ -436,7 +439,10 @@ static int flyEnd(bContext *C, FlyInfo *fly) static void flyEvent(FlyInfo *fly, wmEvent *event) { - if (event->type == MOUSEMOVE) { + if (event->type == TIMER && event->customdata == fly->timer) { + fly->redraw = 1; + } + else if (event->type == MOUSEMOVE) { VECCOPY2D(fly->mval, event->mval); } else if (event->type == NDOF_MOTION) { @@ -746,9 +752,9 @@ static int flyApply(bContext *C, FlyInfo *fly) double time_current; /*time how fast it takes for us to redraw, this is so simple scenes dont fly too fast */ float time_redraw; float time_redraw_clamped; - +#ifdef NDOF_FLY_DRAW_TOOMUCH fly->redraw= 1; - +#endif time_current= PIL_check_seconds_timer(); time_redraw= (float)(time_current - fly->time_lastdraw); time_redraw_clamped= MIN2(0.05f, time_redraw); /* clamt the redraw time to avoid jitter in roll correction */ @@ -1125,7 +1131,7 @@ static int fly_modal(bContext *C, wmOperator *op, wmEvent *event) WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, fly_object); } - // puts("redraw!"); // too frequent, fix tomorrow. + // puts("redraw!"); // too frequent, commented with NDOF_FLY_DRAW_TOOMUCH for now ED_region_tag_redraw(CTX_wm_region(C)); } -- cgit v1.2.3 From 078dff64d2963e56675e490927d675c13626a956 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 08:12:50 +0000 Subject: no functional changes. style edits, also renamed ndof_to_angle_axis --> ndof_to_axis_angle --- source/blender/editors/space_view3d/view3d_edit.c | 6 +- source/blender/editors/space_view3d/view3d_fly.c | 237 +++++++++++---------- .../blender/editors/space_view3d/view3d_intern.h | 2 +- 3 files changed, 126 insertions(+), 119 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 8d77aeaea1b..e6fd9e8867b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -930,7 +930,7 @@ void VIEW3D_OT_rotate(wmOperatorType *ot) // NDOF utility functions // (should these functions live in this file?) -float ndof_to_angle_axis(struct wmNDOFMotionData* ndof, float axis[3]) +float ndof_to_axis_angle(struct wmNDOFMotionData* ndof, float axis[3]) { return ndof->dt * normalize_v3_v3(axis, ndof->rvec); } @@ -940,7 +940,7 @@ void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]) float axis[3]; float angle; - angle= ndof_to_angle_axis(ndof, axis); + angle= ndof_to_axis_angle(ndof, axis); axis_angle_to_quat(q, axis, angle); } @@ -1023,7 +1023,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event mul_qt_qtqt(rot, rot, view_inv_conj); #else // ---------------------------------------- Mike's revised version float axis[3]; - float angle = rot_sensitivity * ndof_to_angle_axis(ndof, axis); + float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis); if (invert) angle = -angle; diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index ca64476b35e..046037a092f 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -109,7 +109,7 @@ void fly_modal_keymap(wmKeyConfig *keyconf) wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Fly Modal"); /* this function is called for each spacetype, only needs to add map once */ - if(keymap) return; + if (keymap) return; keymap= WM_modalkeymap_add(keyconf, "View3D Fly Modal", modal_items); @@ -261,21 +261,21 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->ar = CTX_wm_region(C); fly->scene= CTX_data_scene(C); - #ifdef NDOF_FLY_DEBUG +#ifdef NDOF_FLY_DEBUG puts("\n-- fly begin --"); - #endif +#endif - if(fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->id.lib) { + if (fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->id.lib) { BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library"); return FALSE; } - if(fly->v3d->ob_centre) { + if (fly->v3d->ob_centre) { BKE_report(op->reports, RPT_ERROR, "Cannot fly when the view is locked to an object"); return FALSE; } - if(fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->constraints.first) { + if (fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->constraints.first) { BKE_report(op->reports, RPT_ERROR, "Cannot fly an object with constraints"); return FALSE; } @@ -319,7 +319,7 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->dist_backup= fly->rv3d->dist; if (fly->rv3d->persp==RV3D_CAMOB) { Object *ob_back; - if((U.uiflag & USER_CAM_LOCK_NO_PARENT)==0 && (fly->root_parent=fly->v3d->camera->parent)) { + if ((U.uiflag & USER_CAM_LOCK_NO_PARENT)==0 && (fly->root_parent=fly->v3d->camera->parent)) { while(fly->root_parent->parent) fly->root_parent= fly->root_parent->parent; ob_back= fly->root_parent; @@ -337,7 +337,8 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even negate_v3_v3(fly->rv3d->ofs, fly->v3d->camera->obmat[3]); fly->rv3d->dist=0.0; - } else { + } + else { /* perspective or ortho */ if (fly->rv3d->persp==RV3D_ORTHO) fly->rv3d->persp= RV3D_PERSP; /*if ortho projection, make perspective */ @@ -373,12 +374,12 @@ static int flyEnd(bContext *C, FlyInfo *fly) float upvec[3]; - if(fly->state == FLY_RUNNING) + if (fly->state == FLY_RUNNING) return OPERATOR_RUNNING_MODAL; - #ifdef NDOF_FLY_DEBUG +#ifdef NDOF_FLY_DEBUG puts("\n-- fly end --"); - #endif +#endif WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), fly->timer); @@ -390,14 +391,14 @@ static int flyEnd(bContext *C, FlyInfo *fly) /* Revert to original view? */ if (fly->persp_backup==RV3D_CAMOB) { /* a camera view */ Object *ob_back; - if(fly->root_parent)ob_back= fly->root_parent; - else ob_back= fly->v3d->camera; + ob_back= (fly->root_parent) ? fly->root_parent : fly->v3d->camera; /* store the original camera loc and rot */ object_tfm_restore(ob_back, fly->obtfm); DAG_id_tag_update(&ob_back->id, OB_RECALC_OB); - } else { + } + else { /* Non Camera we need to reset the view back to the original location bacause the user canceled*/ copy_qt_qt(rv3d->viewquat, fly->rot_backup); copy_v3_v3(rv3d->ofs, fly->ofs_backup); @@ -422,13 +423,13 @@ static int flyEnd(bContext *C, FlyInfo *fly) rv3d->rflag &= ~RV3D_NAVIGATING; //XXX2.5 BIF_view3d_previewrender_signal(fly->sa, PR_DBASE|PR_DISPRECT); /* not working at the moment not sure why */ - if(fly->obtfm) + if (fly->obtfm) MEM_freeN(fly->obtfm); - if(fly->ndof) + if (fly->ndof) MEM_freeN(fly->ndof); - if(fly->state == FLY_CONFIRM) { + if (fly->state == FLY_CONFIRM) { MEM_freeN(fly); return OPERATOR_FINISHED; } @@ -451,37 +452,37 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) // static const char* tag_name = "3D mouse position"; wmNDOFMotionData* incoming_ndof = (wmNDOFMotionData*) event->customdata; - switch (incoming_ndof->progress) - { + switch (incoming_ndof->progress) { case P_STARTING: // start keeping track of 3D mouse position - #ifdef NDOF_FLY_DEBUG +#ifdef NDOF_FLY_DEBUG puts("start keeping track of 3D mouse position"); - #endif +#endif // fall through... case P_IN_PROGRESS: // update 3D mouse position - #ifdef NDOF_FLY_DEBUG +#ifdef NDOF_FLY_DEBUG putchar('.'); fflush(stdout); - #endif - if (fly->ndof == NULL) +#endif + if (fly->ndof == NULL) { // fly->ndof = MEM_mallocN(sizeof(wmNDOFMotionData), tag_name); fly->ndof = MEM_dupallocN(incoming_ndof); // fly->ndof = malloc(sizeof(wmNDOFMotionData)); - else + } + else { memcpy(fly->ndof, incoming_ndof, sizeof(wmNDOFMotionData)); + } break; case P_FINISHING: // stop keeping track of 3D mouse position - #ifdef NDOF_FLY_DEBUG +#ifdef NDOF_FLY_DEBUG puts("stop keeping track of 3D mouse position"); - #endif - if (fly->ndof) - { +#endif + if (fly->ndof) { MEM_freeN(fly->ndof); // free(fly->ndof); fly->ndof = NULL; - } + } /* update the time else the view will jump when 2D mouse/timer resume */ fly->time_lastdraw= PIL_check_seconds_timer(); break; @@ -511,7 +512,9 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) /*Mouse wheel delays range from 0.5==slow to 0.01==fast*/ time_wheel = 1.0f + (10.0f - (20.0f * MIN2(time_wheel, 0.5f))); /* 0-0.5 -> 0-5.0 */ - if (fly->speed<0.0f) fly->speed= 0.0f; + if (fly->speed < 0.0f) { + fly->speed= 0.0f; + } else { if (event->shift) fly->speed += fly->grid*time_wheel * 0.1f; @@ -530,7 +533,9 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) fly->time_lastwheel = time_currwheel; time_wheel = 1.0f + (10.0f - (20.0f * MIN2(time_wheel, 0.5f))); /* 0-0.5 -> 0-5.0 */ - if (fly->speed>0) fly->speed=0; + if (fly->speed > 0.0f) { + fly->speed=0; + } else { if (event->shift) fly->speed-= fly->grid*time_wheel * 0.1f; @@ -614,7 +619,7 @@ static void move_camera(bContext* C, RegionView3D* rv3d, FlyInfo* fly, int orien ID *id_key; /* transform the parent or the camera? */ - if(fly->root_parent) { + if (fly->root_parent) { Object *ob_update; float view_mat[4][4]; @@ -702,10 +707,10 @@ static int flyApply(bContext *C, FlyInfo *fly) unsigned char apply_rotation= 1; /* if the user presses shift they can look about without movinf the direction there looking*/ - #ifdef NDOF_FLY_DEBUG +#ifdef NDOF_FLY_DEBUG static unsigned int iteration = 1; printf("fly timer %d\n", iteration++); - #endif +#endif xmargin= ar->winx/20.0f; @@ -736,18 +741,18 @@ static int flyApply(bContext *C, FlyInfo *fly) * * the mouse moves isnt linear */ - if(moffset[0]) { + if (moffset[0]) { moffset[0] /= ar->winx - (xmargin*2); moffset[0] *= fabsf(moffset[0]); } - if(moffset[1]) { + if (moffset[1]) { moffset[1] /= ar->winy - (ymargin*2); moffset[1] *= fabsf(moffset[1]); } /* Should we redraw? */ - if(fly->speed != 0.0f || moffset[0] || moffset[1] || fly->zlock || fly->xlock || dvec[0] || dvec[1] || dvec[2] ) { + if (fly->speed != 0.0f || moffset[0] || moffset[1] || fly->zlock || fly->xlock || dvec[0] || dvec[1] || dvec[2] ) { float dvec_tmp[3]; double time_current; /*time how fast it takes for us to redraw, this is so simple scenes dont fly too fast */ float time_redraw; @@ -781,8 +786,8 @@ static int flyApply(bContext *C, FlyInfo *fly) mul_m3_v3(mat, dvec_tmp); mul_v3_fl(dvec_tmp, time_redraw * 200.0f * fly->grid); - - } else { + } + else { float roll; /* similar to the angle between the camera's up and the Z-up, but its very rough so just roll*/ /* rotate about the X axis- look up/down */ @@ -803,23 +808,24 @@ static int flyApply(bContext *C, FlyInfo *fly) if (moffset[0]) { /* if we're upside down invert the moffset */ - upvec[0]=0; - upvec[1]=1; - upvec[2]=0; + upvec[0]= 0.0f; + upvec[1]= 1.0f; + upvec[2]= 0.0f; mul_m3_v3(mat, upvec); - if(upvec[2] < 0.0f) + if (upvec[2] < 0.0f) moffset[0]= -moffset[0]; /* make the lock vectors */ if (fly->zlock) { - upvec[0]=0; - upvec[1]=0; - upvec[2]=1; - } else { - upvec[0]=0; - upvec[1]=1; - upvec[2]=0; + upvec[0]= 0.0f; + upvec[1]= 0.0f; + upvec[2]= 1.0f; + } + else { + upvec[0]= 0.0f; + upvec[1]= 1.0f; + upvec[2]= 0.0f; mul_m3_v3(mat, upvec); } @@ -831,25 +837,26 @@ static int flyApply(bContext *C, FlyInfo *fly) } if (fly->zlock==2) { - upvec[0]=1; - upvec[1]=0; - upvec[2]=0; + upvec[0]= 1.0f; + upvec[1]= 0.0f; + upvec[2]= 0.0f; mul_m3_v3(mat, upvec); /*make sure we have some z rolling*/ if (fabsf(upvec[2]) > 0.00001f) { - roll= upvec[2]*5; - upvec[0]=0; /*rotate the view about this axis*/ - upvec[1]=0; - upvec[2]=1; + roll= upvec[2] * 5.0f; + upvec[0]= 0.0f; /*rotate the view about this axis*/ + upvec[1]= 0.0f; + upvec[2]= 1.0f; mul_m3_v3(mat, upvec); axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->zlock_momentum * FLY_ZUP_CORRECT_FAC); /* Rotate about the relative up vec */ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL; - } else { - fly->zlock=1; /* dont check until the view rotates again */ + } + else { + fly->zlock= 1; /* dont check until the view rotates again */ fly->zlock_momentum= 0.0f; } } @@ -860,8 +867,8 @@ static int flyApply(bContext *C, FlyInfo *fly) upvec[2]=1; mul_m3_v3(mat, upvec); /*make sure we have some z rolling*/ - if (fabs(upvec[2]) > 0.00001) { - roll= upvec[2] * -5; + if (fabs(upvec[2]) > 0.00001f) { + roll= upvec[2] * -5.0f; upvec[0]= 1.0f; /*rotate the view about this axis*/ upvec[1]= 0.0f; @@ -873,7 +880,8 @@ static int flyApply(bContext *C, FlyInfo *fly) mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); fly->xlock_momentum += 0.05f; - } else { + } + else { fly->xlock=1; /* see above */ fly->xlock_momentum= 0.0f; } @@ -920,9 +928,11 @@ static int flyApply(bContext *C, FlyInfo *fly) if (rv3d->persp==RV3D_CAMOB) move_camera(C, rv3d, fly, (fly->xlock || fly->zlock || moffset[0] || moffset[1]), fly->speed); - } else - /*were not redrawing but we need to update the time else the view will jump */ + } + else { + /* we're not redrawing but we need to update the time else the view will jump */ fly->time_lastdraw= PIL_check_seconds_timer(); + } /* end drawing */ copy_v3_v3(fly->dvec_prev, dvec); } @@ -932,14 +942,14 @@ static int flyApply(bContext *C, FlyInfo *fly) static int flyApply_ndof(bContext *C, FlyInfo *fly) { - // shorthand for oft-used variables + /* shorthand for oft-used variables */ wmNDOFMotionData* ndof = fly->ndof; const float dt = ndof->dt; RegionView3D* rv3d = fly->rv3d; const int flag = U.ndof_flag; -// int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE), -// shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM)); +/* int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE), + shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM)); */ int shouldRotate = (fly->pan_view == FALSE), shouldTranslate = TRUE; @@ -949,14 +959,13 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) rv3d->rot_angle = 0.f; // disable onscreen rotation doo-dad - if (shouldTranslate) - { + if (shouldTranslate) { const float forward_sensitivity = 1.f; const float vertical_sensitivity = 0.4f; const float lateral_sensitivity = 0.6f; - float speed = 10.f; // blender units per second - // ^^ this is ok for default cube scene, but should scale with.. something + float speed = 10.f; /* blender units per second */ + /* ^^ this is ok for default cube scene, but should scale with.. something */ float trans[3] = { lateral_sensitivity * ndof->tvec[0], @@ -972,11 +981,10 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) // transform motion from view to world coordinates mul_qt_v3(view_inv, trans); - if (flag & NDOF_FLY_HELICOPTER) - { - // replace world z component with device y (yes it makes sense) + if (flag & NDOF_FLY_HELICOPTER) { + /* replace world z component with device y (yes it makes sense) */ trans[2] = speed * dt * vertical_sensitivity * ndof->tvec[1]; - } + } if (rv3d->persp==RV3D_CAMOB) { // respect camera position locks @@ -986,79 +994,77 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly) if (lock_ob->protectflag & OB_LOCK_LOCZ) trans[2] = 0.f; } - if (trans[0] || trans[1] || trans[2]) - { + if (!is_zero_v3(trans)) { // move center of view opposite of hand motion (this is camera mode, not object mode) sub_v3_v3(rv3d->ofs, trans); shouldTranslate = TRUE; - } - else + } + else { shouldTranslate = FALSE; } + } - if (shouldRotate) - { + if (shouldRotate) { const float turn_sensitivity = 1.f; float rotation[4]; float axis[3]; - float angle = turn_sensitivity * ndof_to_angle_axis(ndof, axis); + float angle = turn_sensitivity * ndof_to_axis_angle(ndof, axis); - if (fabsf(angle) > 0.0001f) - { + if (fabsf(angle) > 0.0001f) { shouldRotate = TRUE; if (fly->use_precision) angle *= 0.2f; - // transform rotation axis from view to world coordinates + /* transform rotation axis from view to world coordinates */ mul_qt_v3(view_inv, axis); // apply rotation to view axis_angle_to_quat(rotation, axis, angle); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); - if (flag & NDOF_LOCK_HORIZON) - // force an upright viewpoint - // TODO: make this less... sudden - { - float view_horizon[3] = {1.f, 0.f, 0.f}; // view +x - float view_direction[3] = {0.f, 0.f, -1.f}; // view -z (into screen) + if (flag & NDOF_LOCK_HORIZON) { + /* force an upright viewpoint + * TODO: make this less... sudden */ + float view_horizon[3] = {1.f, 0.f, 0.f}; /* view +x */ + float view_direction[3] = {0.f, 0.f, -1.f}; /* view -z (into screen) */ - // find new inverse since viewquat has changed + /* find new inverse since viewquat has changed */ invert_qt_qt(view_inv, rv3d->viewquat); - // could apply reverse rotation to existing view_inv to save a few cycles + /* could apply reverse rotation to existing view_inv to save a few cycles */ - // transform view vectors to world coordinates + /* transform view vectors to world coordinates */ mul_qt_v3(view_inv, view_horizon); mul_qt_v3(view_inv, view_direction); - // find difference between view & world horizons - // true horizon lives in world xy plane, so look only at difference in z + /* find difference between view & world horizons + * true horizon lives in world xy plane, so look only at difference in z */ angle = -asinf(view_horizon[2]); - #ifdef NDOF_FLY_DEBUG +#ifdef NDOF_FLY_DEBUG printf("lock horizon: adjusting %.1f degrees\n\n", RAD2DEG(angle)); - #endif +#endif - // rotate view so view horizon = world horizon + /* rotate view so view horizon = world horizon */ axis_angle_to_quat(rotation, view_direction, angle); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); - } + } rv3d->view = RV3D_VIEW_USER; - } - else + } + else { shouldRotate = FALSE; } + } - if (shouldTranslate || shouldRotate) - { + if (shouldTranslate || shouldRotate) { fly->redraw = TRUE; - if (rv3d->persp==RV3D_CAMOB) + if (rv3d->persp==RV3D_CAMOB) { move_camera(C, rv3d, fly, shouldRotate, shouldTranslate); } + } return OPERATOR_FINISHED; } @@ -1069,14 +1075,14 @@ static int fly_invoke(bContext *C, wmOperator *op, wmEvent *event) RegionView3D *rv3d= CTX_wm_region_view3d(C); FlyInfo *fly; - if(rv3d->viewlock) + if (rv3d->viewlock) return OPERATOR_CANCELLED; fly= MEM_callocN(sizeof(FlyInfo), "FlyOperation"); op->customdata= fly; - if(initFlyInfo(C, fly, op, event)==FALSE) { + if (initFlyInfo(C, fly, op, event)==FALSE) { MEM_freeN(op->customdata); return OPERATOR_CANCELLED; } @@ -1111,23 +1117,24 @@ static int fly_modal(bContext *C, wmOperator *op, wmEvent *event) flyEvent(fly, event); - if (fly->ndof) // 3D mouse overrules [2D mouse + timer] - { - if (event->type==NDOF_MOTION) + if (fly->ndof) { /* 3D mouse overrules [2D mouse + timer] */ + if (event->type==NDOF_MOTION) { flyApply_ndof(C, fly); } - else if (event->type==TIMER && event->customdata == fly->timer) + } + else if (event->type==TIMER && event->customdata == fly->timer) { flyApply(C, fly); + } do_draw |= fly->redraw; exit_code = flyEnd(C, fly); - if(exit_code!=OPERATOR_RUNNING_MODAL) + if (exit_code!=OPERATOR_RUNNING_MODAL) do_draw= TRUE; - if(do_draw) { - if(rv3d->persp==RV3D_CAMOB) { + if (do_draw) { + if (rv3d->persp==RV3D_CAMOB) { WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, fly_object); } diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index c4207b0ce25..ab3ce37ff15 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -95,7 +95,7 @@ void VIEW3D_OT_drawtype(struct wmOperatorType *ot); void view3d_boxview_copy(ScrArea *sa, ARegion *ar); void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4]); -float ndof_to_angle_axis(struct wmNDOFMotionData* ndof, float axis[3]); +float ndof_to_axis_angle(struct wmNDOFMotionData* ndof, float axis[3]); /* view3d_fly.c */ void view3d_keymap(struct wmKeyConfig *keyconf); -- cgit v1.2.3 From f1c68bdbec98edfd212e80aa7a80fe1f93c4a100 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Tue, 2 Aug 2011 09:12:58 +0000 Subject: Don't show NDOF guide by default. --- source/blender/editors/interface/resources.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 16f3789ecb1..0c755180b3a 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1587,7 +1587,7 @@ void init_userdef_do_versions(void) if (U.ndof_sensitivity == 0.0f) { U.ndof_sensitivity = 1.0f; - U.ndof_flag = NDOF_SHOW_GUIDE | NDOF_LOCK_HORIZON | + U.ndof_flag = NDOF_LOCK_HORIZON | NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE; } -- cgit v1.2.3 From 73fc78c5d81920fc4b3dbcb8fcf4fdc6ab6dd3d6 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Tue, 2 Aug 2011 09:18:21 +0000 Subject: Debug print removed. --- source/blender/windowmanager/intern/wm_operators.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 7dc4bfb65a6..a47dfacf358 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -3428,26 +3428,20 @@ static int wm_ndof_sensitivity_exec(bContext *UNUSED(C), wmOperator *op) else change = 0.1f; // 10% - if(RNA_boolean_get(op->ptr, "decrease")) - { + if(RNA_boolean_get(op->ptr, "decrease")) { sensitivity -= sensitivity * change; if (sensitivity < min) sensitivity = min; - } - else - { + } + else { sensitivity += sensitivity * change; if (sensitivity > max) sensitivity = max; - } + } - if (sensitivity != U.ndof_sensitivity) - { + if (sensitivity != U.ndof_sensitivity) { U.ndof_sensitivity = sensitivity; - printf("new sensitivity: %f\n", U.ndof_sensitivity); - } - else - printf("same sensitivity: %f\n", U.ndof_sensitivity); + } return OPERATOR_FINISHED; } -- cgit v1.2.3 From de0db6c8daaf4f6276b43bd4c78d623fdb0eafb9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 10:56:09 +0000 Subject: unit arg for FloatVectorProeprty --- source/blender/python/intern/bpy_props.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index 0ba80bf0850..a0ad1ff7850 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -326,6 +326,11 @@ static int bpy_prop_callback_assign(struct PropertyRNA *prop, PyObject *update_c " :type description: string\n" \ +#define BPY_PROPDEF_UNIT_DOC \ +" :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n" \ +" :type unit: string\n" \ + + #define BPY_PROPDEF_UPDATE_DOC \ " :arg update: function to be called when this value is modified,\n" \ " This function must take 2 values (self, context) and return None.\n" \ @@ -639,8 +644,7 @@ BPY_PROPDEF_DESC_DOC " :type options: set\n" " :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n" " :type subtype: string\n" -" :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n" -" :type unit: string\n" +BPY_PROPDEF_UNIT_DOC BPY_PROPDEF_UPDATE_DOC ); static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) @@ -679,7 +683,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_SUBTYPE_CHECK(FloatProperty, property_flag_items, property_subtype_number_items) if(pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) { - PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit"); + PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit", pyunit); return NULL; } @@ -716,6 +720,7 @@ BPY_PROPDEF_DESC_DOC " :type options: set\n" " :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n" " :type subtype: string\n" +BPY_PROPDEF_UNIT_DOC " :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n" " :type size: int\n" BPY_PROPDEF_UPDATE_DOC @@ -727,7 +732,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec BPY_PROPDEF_HEAD(FloatVectorProperty) if(srna) { - static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "size", "update", NULL}; + static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", "size", "update", NULL}; const char *id=NULL, *name="", *description=""; int id_len; float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f}; @@ -738,15 +743,17 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec int opts=0; char *pysubtype= NULL; int subtype= PROP_NONE; + char *pyunit= NULL; + int unit= PROP_UNIT_NONE; PyObject *update_cb= NULL; if (!PyArg_ParseTupleAndKeywords(args, kw, - "s#|ssOfffffiO!siO:FloatVectorProperty", + "s#|ssOfffffiO!ssiO:FloatVectorProperty", (char **)kwlist, &id, &id_len, &name, &description, &pydef, &min, &max, &soft_min, &soft_max, &step, &precision, &PySet_Type, - &pyopts, &pysubtype, &size, + &pyopts, &pysubtype, &pyunit, &size, &update_cb)) { return NULL; @@ -754,6 +761,11 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec BPY_PROPDEF_SUBTYPE_CHECK(FloatVectorProperty, property_flag_items, property_subtype_array_items) + if(pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) { + PyErr_Format(PyExc_TypeError, "FloatVectorProperty(unit='%s'): invalid unit", pyunit); + return NULL; + } + if(size < 1 || size > PYRNA_STACK_ARRAY) { PyErr_Format(PyExc_TypeError, "FloatVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size); return NULL; @@ -766,7 +778,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec return NULL; } - prop= RNA_def_property(srna, id, PROP_FLOAT, subtype); + prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit); RNA_def_property_array(prop, size); if(pydef) RNA_def_property_float_array_default(prop, def); RNA_def_property_range(prop, min, max); -- cgit v1.2.3 From 3af9651b903e05cea956f2358394fec3e0c81ef6 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 2 Aug 2011 22:50:06 +0000 Subject: ndof changes: turned off 3D mouse during transform, removed timing bug in image/uv, added option for zoom axis (up/down vs. forward/backward) --- source/blender/editors/space_image/image_ops.c | 9 ++------ source/blender/editors/transform/transform_ops.c | 6 ++++++ source/blender/makesdna/DNA_userdef_types.h | 3 +++ .../blender/windowmanager/intern/wm_event_system.c | 25 +++++++++++++++++----- 4 files changed, 31 insertions(+), 12 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 6e84c1a7f0c..1f37583b445 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -452,14 +452,9 @@ static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - float dt = ndof->dt > 0.25f ? 0.0125f : ndof->dt; - /* this is probably the first event for this motion, so set dt to something reasonable - * TODO: replace such guesswork with a flag or field from the NDOF manager - */ - /* tune these until it feels right */ - const float zoom_sensitivity = 0.5f; - const float pan_sensitivity = 300.f; + const float zoom_sensitivity = 0.5f; // 50% per second (I think) + const float pan_sensitivity = 300.f; // screen pixels per second float pan_x = pan_sensitivity * dt * ndof->tvec[0] / sima->zoom; float pan_y = pan_sensitivity * dt * ndof->tvec[1] / sima->zoom; diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 0efd25c4faa..fb40cee95fb 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -360,11 +360,17 @@ static int transform_modal(bContext *C, wmOperator *op, wmEvent *event) TransInfo *t = op->customdata; + #if 0 + // stable 2D mouse coords map to different 3D coords while the 3D mouse is active + // in other words, 2D deltas are no longer good enough! + // disable until individual 'transformers' behave better + if (event->type == NDOF_MOTION) { /* puts("transform_modal: passing through NDOF_MOTION"); */ return OPERATOR_PASS_THROUGH; } + #endif /* XXX insert keys are called here, and require context */ t->context= C; diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 12f8cd656a0..0bf812f1ec2 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -600,6 +600,9 @@ extern UserDef U; /* from blenkernel blender.c */ /* actually... users probably don't care about what the mode is called, just that it feels right */ #define NDOF_ORBIT_INVERT_AXES (1 << 6) +/* zoom is up/down if this flag is set (otherwise forward/backward) */ +#define NDOF_ZOOM_UPDOWN (1 << 7) +#define NDOF_INVERT_ZOOM (1 << 8) #ifdef __cplusplus diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 0abae2e06b7..9a25c4b581d 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2324,12 +2324,27 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g const float s = U.ndof_sensitivity; data->tvec[0]= s * ghost->tx; - data->tvec[1]= s * ghost->ty; - data->tvec[2]= s * ghost->tz; - data->rvec[0]= s * ghost->rx; - data->rvec[1]= s * ghost->ry; - data->rvec[2]= s * ghost->rz; + + if (U.ndof_flags & NDOF_ZOOM_UPDOWN) + { + // swap Y and Z + data->tvec[1]= s * ghost->tz; + data->tvec[2]= s * ghost->ty; + + // should this affect rotation also? + // initial guess is 'yes', but get user feedback immediately! + data->rvec[1]= s * ghost->rz; + data->rvec[2]= s * ghost->ry; + } + else + { + data->tvec[1]= s * ghost->ty; + data->tvec[2]= s * ghost->tz; + + data->rvec[1]= s * ghost->ry; + data->rvec[2]= s * ghost->rz; + } data->dt = ghost->dt; -- cgit v1.2.3 From 17133e1a1d737771c6afcb701c1a32f035bf03c6 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Tue, 2 Aug 2011 23:49:07 +0000 Subject: Compile fix. --- source/blender/editors/space_image/image_ops.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 1f37583b445..e0ebde589a8 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -452,6 +452,7 @@ static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + float dt = ndof->dt; /* tune these until it feels right */ const float zoom_sensitivity = 0.5f; // 50% per second (I think) const float pan_sensitivity = 300.f; // screen pixels per second -- cgit v1.2.3 From dc4b104e60d99176fbe32c06dff0b190b3313e3d Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Tue, 2 Aug 2011 23:52:07 +0000 Subject: typo fix. --- source/blender/windowmanager/intern/wm_event_system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 9a25c4b581d..2f0c1a72be9 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2326,7 +2326,7 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g data->tvec[0]= s * ghost->tx; data->rvec[0]= s * ghost->rx; - if (U.ndof_flags & NDOF_ZOOM_UPDOWN) + if (U.ndof_flag & NDOF_ZOOM_UPDOWN) { // swap Y and Z data->tvec[1]= s * ghost->tz; -- cgit v1.2.3 From a10245a1fa0243cc2e8bb739b589693fc26aa2c8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 Aug 2011 05:32:07 +0000 Subject: fix [#28151] export OBJ don't save the extension also correct some typos --- source/blender/editors/space_view3d/view3d_view.c | 2 +- source/blender/render/intern/source/rendercore.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index eeaf87757ce..ed0b2645c99 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -1190,7 +1190,7 @@ int ED_view3d_lock(RegionView3D *rv3d) return TRUE; } -/* dont set windows active in in here, is used by renderwin too */ +/* dont set windows active in here, is used by renderwin too */ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d) { if(rv3d->persp==RV3D_CAMOB) { /* obs/camera */ diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index a7e19c8db4f..c08d6c0f456 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -730,7 +730,7 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) if(zpass==NULL) return; - /* check for at least one sun lamp that its atmosphere flag is is enabled */ + /* check for at least one sun lamp that its atmosphere flag is enabled */ for(go=R.lights.first; go; go= go->next) { lar= go->lampren; if(lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_AP)) -- cgit v1.2.3 From 9cf3bcd414bc0a6df0abc451040bc3098fe81e5d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 Aug 2011 06:30:19 +0000 Subject: add note in scene.frame_current that frace_set() updates animation data. --- source/blender/makesrna/intern/rna_scene.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index f4028e45e96..b3d8bc8ea18 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -3251,7 +3251,7 @@ void RNA_def_scene(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "r.cfra"); RNA_def_property_range(prop, MINAFRAME, MAXFRAME); RNA_def_property_int_funcs(prop, NULL, "rna_Scene_current_frame_set", NULL); - RNA_def_property_ui_text(prop, "Current Frame", "Current Frame"); + RNA_def_property_ui_text(prop, "Current Frame", "Current Frame, to update animation data from python frame_set() instead"); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); RNA_def_property_update(prop, NC_SCENE|ND_FRAME, "rna_Scene_frame_update"); -- cgit v1.2.3 From e320db106691a6912fca05f6a8dfb09a3d4f2128 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 Aug 2011 08:02:32 +0000 Subject: fix [#28135] Edge slide changes UV --- source/blender/editors/include/ED_transform.h | 1 + source/blender/editors/transform/transform.c | 14 ++++++-------- source/blender/editors/transform/transform_generics.c | 16 ++++++++++++++++ source/blender/editors/transform/transform_ops.c | 7 ++++++- 4 files changed, 29 insertions(+), 9 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index d4d7f971b74..00ae7dda2e3 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -148,6 +148,7 @@ void BIF_selectOrientation(void); #define P_ALIGN_SNAP (P_GEO_SNAP|(1 << 5)) #define P_CONSTRAINT (1 << 6) #define P_OPTIONS (1 << 7) +#define P_CORRECT_UV (1 << 8) void Transform_Properties(struct wmOperatorType *ot, int flags); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 92ac8471172..39e26bc6436 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -4243,7 +4243,7 @@ static int createSlideVerts(TransInfo *t) /* UV correction vars */ GHash **uvarray= NULL; SlideData *sld = MEM_callocN(sizeof(*sld), "sld"); - int uvlay_tot= CustomData_number_of_layers(&em->fdata, CD_MTFACE); + const int uvlay_tot= (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) ? CustomData_number_of_layers(&em->fdata, CD_MTFACE) : 0; int uvlay_idx; TransDataSlideUv *slideuvs=NULL, *suv=NULL, *suv_last=NULL; RegionView3D *v3d = t->ar ? t->ar->regiondata : NULL; /* background mode support */ @@ -4615,7 +4615,7 @@ static int createSlideVerts(TransInfo *t) sld->end[0] = (int) end[0]; sld->end[1] = (int) end[1]; - if (uvlay_tot) { // XXX && (scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT)) { + if (uvlay_tot) { int maxnum = 0; uvarray = MEM_callocN( uvlay_tot * sizeof(GHash *), "SlideUVs Array"); @@ -4805,8 +4805,6 @@ void initEdgeSlide(TransInfo *t) int doEdgeSlide(TransInfo *t, float perc) { - Mesh *me= t->obedit->data; - EditMesh *em = me->edit_mesh; SlideData *sld = t->customData; EditVert *ev, *nearest = sld->nearest; EditVert *centerVert, *upVert, *downVert; @@ -4817,7 +4815,7 @@ int doEdgeSlide(TransInfo *t, float perc) int prop=1, flip=0; /* UV correction vars */ GHash **uvarray= sld->uvhash; - int uvlay_tot= CustomData_number_of_layers(&em->fdata, CD_MTFACE); + const int uvlay_tot= sld->uvlay_tot; int uvlay_idx; TransDataSlideUv *suv; float uv_tmp[2]; @@ -4843,7 +4841,7 @@ int doEdgeSlide(TransInfo *t, float perc) tempev = editedge_getOtherVert((perc>=0)?tempsv->up:tempsv->down, ev); interp_v3_v3v3(ev->co, tempsv->origvert.co, tempev->co, fabs(perc)); - if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { + if (uvlay_tot) { for (uvlay_idx=0; uvlay_idxfuv_list && suv->uv_up && suv->uv_down) { @@ -4873,7 +4871,7 @@ int doEdgeSlide(TransInfo *t, float perc) if(newlen < 0.0f) {newlen = 0.0;} if(flip == 0) { interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen)); - if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { + if (uvlay_tot) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idxco, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen)); - if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { + if (uvlay_tot) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idxoptions |= CTX_NO_PET; } } + + /* initialize UV transform from */ + if (RNA_struct_find_property(op->ptr, "correct_uv")) { + if(RNA_property_is_set(op->ptr, "correct_uv")) { + if(RNA_boolean_get(op->ptr, "correct_uv")) { + t->settings->uvcalc_flag |= UVCALC_TRANSFORM_CORRECT; + } + else { + t->settings->uvcalc_flag &= ~UVCALC_TRANSFORM_CORRECT; + } + } + else { + RNA_boolean_set(op->ptr, "correct_uv", t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT); + } + } + } else if(t->spacetype==SPACE_IMAGE) { diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index fb40cee95fb..54e0b31e201 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -508,6 +508,11 @@ void Transform_Properties(struct wmOperatorType *ot, int flags) RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Object data texture space", ""); } + if (flags & P_CORRECT_UV) + { + RNA_def_boolean(ot->srna, "correct_uv", 0, "Correct UV coords when transforming", ""); + } + // Add confirm method all the time. At the end because it's not really that important and should be hidden only in log, not in keymap edit /*prop =*/ RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button"); //RNA_def_property_flag(prop, PROP_HIDDEN); @@ -755,7 +760,7 @@ void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot) RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f); - Transform_Properties(ot, P_MIRROR|P_SNAP); + Transform_Properties(ot, P_MIRROR|P_SNAP|P_CORRECT_UV); } void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot) -- cgit v1.2.3 From 461bb17d31cc17c07a4b00437b5b90d58f14a894 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 Aug 2011 09:28:16 +0000 Subject: fix [#27965] VSE: no visual feedback on locked strips added xpm -> opengl stipple conversion script. --- source/blender/editors/include/BIF_glutil.h | 2 ++ source/blender/editors/screen/glutil.c | 38 ++++++++++++++++++++++ .../editors/space_sequencer/sequencer_draw.c | 19 +++++++++++ 3 files changed, 59 insertions(+) (limited to 'source/blender') diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index c9615204607..27bd31c20ff 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -52,6 +52,8 @@ void fdrawXORcirc(float xofs, float yofs, float rad); /* glStipple defines */ extern unsigned char stipple_halftone[128]; extern unsigned char stipple_quarttone[128]; +extern unsigned char stipple_diag_stripes_pos[128]; +extern unsigned char stipple_diag_stripes_neg[128]; /** * Draw a lined (non-looping) arc with the given diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 2918c98c84a..f56ae17d366 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -92,6 +92,44 @@ GLubyte stipple_quarttone[128] = { 136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0}; +GLubyte stipple_diag_stripes_pos[128] = { + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f}; + + +GLubyte stipple_diag_stripes_neg[128] = { + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80, + 0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01, + 0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07, + 0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f, + 0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f, + 0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe, + 0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8, + 0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, + 0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80}; + + void fdrawbezier(float vec[4][3]) { float dist; diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 594d2942e8f..98687bb90e0 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -639,6 +639,25 @@ static void draw_seq_strip(Scene *scene, ARegion *ar, Sequence *seq, int outline /* draw sound wave */ if(seq->type == SEQ_SOUND) drawseqwave(scene, seq, x1, y1, x2, y2, (ar->v2d.cur.xmax - ar->v2d.cur.xmin)/ar->winx); + /* draw lock */ + if(seq->flag & SEQ_LOCK) { + glEnable(GL_POLYGON_STIPPLE); + glEnable(GL_BLEND); + + /* light stripes */ + glColor4ub(255, 255, 255, 32); + glPolygonStipple(stipple_diag_stripes_pos); + glRectf(x1, y1, x2, y2); + + /* dark stripes */ + glColor4ub(0, 0, 0, 32); + glPolygonStipple(stipple_diag_stripes_neg); + glRectf(x1, y1, x2, y2); + + glDisable(GL_POLYGON_STIPPLE); + glDisable(GL_BLEND); + } + get_seq_color3ubv(scene, seq, col); if (G.moving && (seq->flag & SELECT)) { if(seq->flag & SEQ_OVERLAP) { -- cgit v1.2.3 From 9eef0646d4fc5344e85e8e4eae63795ffd4b766b Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Wed, 3 Aug 2011 14:21:49 +0000 Subject: Crash in MMB moves (etc): commit of today was reading NULL pointer. --- source/blender/editors/transform/transform_generics.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index f8df4e4ee75..c81c398e696 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -887,6 +887,7 @@ void resetTransRestrictions(TransInfo *t) t->flag &= ~T_ALL_RESTRICTIONS; } +/* the *op can be NULL */ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) { Scene *sce = CTX_data_scene(C); @@ -1015,7 +1016,7 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) } /* initialize UV transform from */ - if (RNA_struct_find_property(op->ptr, "correct_uv")) { + if (op && RNA_struct_find_property(op->ptr, "correct_uv")) { if(RNA_property_is_set(op->ptr, "correct_uv")) { if(RNA_boolean_get(op->ptr, "correct_uv")) { t->settings->uvcalc_flag |= UVCALC_TRANSFORM_CORRECT; -- cgit v1.2.3 From e5e6f91856efe3d78eab747c25be4e1d0a5988ef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Aug 2011 01:56:36 +0000 Subject: fix [#28114] Render Crash existing check for driver to use GIL was not thread safe and could cause, details in the report. This bug was caused by a check to avoid hanging, a fix for [#27683] that worked in 2.4x because the UI didn't use python to draw while rendering. Apply a different fix for [#27683], when calling an operator, call PyEval_SaveThread(), then PyEval_RestoreThread() so the GIL can be aquired by threads started by the operator - in this case bake starting a thread that evaluates drivers. --- source/blender/python/intern/bpy_driver.c | 17 ++++++++++------- source/blender/python/intern/bpy_operator.c | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'source/blender') diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index bcd5df97c2c..d68fd9a9111 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -41,8 +41,6 @@ #include "bpy_driver.h" -#include "../generic/py_capi_utils.h" - /* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */ PyObject *bpy_pydriver_Dict= NULL; @@ -89,7 +87,7 @@ int bpy_pydriver_create_dict(void) void BPY_driver_reset(void) { PyGILState_STATE gilstate; - int use_gil= !PYC_INTERPRETER_ACTIVE; + int use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */ if(use_gil) gilstate= PyGILState_Ensure(); @@ -120,9 +118,14 @@ static void pydriver_error(ChannelDriver *driver) /* This evals py driver expressions, 'expr' is a Python expression that * should evaluate to a float number, which is returned. * - * note: PyGILState_Ensure() isnt always called because python can call the - * bake operator which intern starts a thread which calls scene update which - * does a driver update. to avoid a deadlock check PYC_INTERPRETER_ACTIVE if PyGILState_Ensure() is needed. + * (old)note: PyGILState_Ensure() isnt always called because python can call + * the bake operator which intern starts a thread which calls scene update + * which does a driver update. to avoid a deadlock check PYC_INTERPRETER_ACTIVE + * if PyGILState_Ensure() is needed - see [#27683] + * + * (new)note: checking if python is running is not threadsafe [#28114] + * now release the GIL on python operator execution instead, using + * PyEval_SaveThread() / PyEval_RestoreThread() so we dont lock up blender. */ float BPY_driver_exec(ChannelDriver *driver) { @@ -149,7 +152,7 @@ float BPY_driver_exec(ChannelDriver *driver) return 0.0f; } - use_gil= !PYC_INTERPRETER_ACTIVE; + use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */ if(use_gil) gilstate= PyGILState_Ensure(); diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index b8883e655f2..4a17c45ae38 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -55,6 +55,10 @@ #include "BKE_report.h" #include "BKE_context.h" +/* so operators called can spawn threads which aquire the GIL */ +#define BPY_RELEASE_GIL + + static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) { wmOperatorType *ot; @@ -219,7 +223,22 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList"); BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these dont move into global reports */ - operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports); +#ifdef BPY_RELEASE_GIL + /* release GIL, since a thread could be started from an operator + * that updates a driver */ + /* note: I havve not seen any examples of code that does this + * so it may not be officially supported but seems to work ok. */ + { + PyThreadState *ts= PyEval_SaveThread(); +#endif + + operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports); + +#ifdef BPY_RELEASE_GIL + /* regain GIL */ + PyEval_RestoreThread(ts); + } +#endif error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE); -- cgit v1.2.3 From 0578d55f1ef700b96ae8a8c33c1f8b54a200c7d9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Aug 2011 09:47:09 +0000 Subject: when appending with a NULL context dont print warnigns about scene not being set - was annoying for BGE LibLoad. --- source/blender/blenloader/intern/readfile.c | 36 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 0633794c6ed..0a24dfaed72 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -13047,10 +13047,10 @@ static void append_do_cursor(Scene *scene, Library *curlib, short flag) } } +/* Context == NULL signifies not to do any scene manipulation */ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, int idcode, short flag) { Main *mainvar; - Scene *scene= CTX_data_scene(C); Library *curlib; /* make main consistent */ @@ -13079,22 +13079,28 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in lib_verify_nodetree(mainvar, FALSE); fix_relpaths_library(G.main->name, mainvar); /* make all relative paths, relative to the open blend file */ - /* give a base to loose objects. If group append, do it for objects too */ - if(scene) { - const short is_link= (flag & FILE_LINK) != 0; - if(idcode==ID_SCE) { - /* dont instance anything when linking in scenes, assume the scene its self instances the data */ - } - else { - give_base_to_objects(mainvar, scene, curlib, idcode, is_link); + if(C) { + Scene *scene= CTX_data_scene(C); - if (flag & FILE_GROUP_INSTANCE) { - give_base_to_groups(mainvar, scene); + /* give a base to loose objects. If group append, do it for objects too */ + if(scene) { + const short is_link= (flag & FILE_LINK) != 0; + if(idcode==ID_SCE) { + /* dont instance anything when linking in scenes, assume the scene its self instances the data */ + } + else { + give_base_to_objects(mainvar, scene, curlib, idcode, is_link); + + if (flag & FILE_GROUP_INSTANCE) { + give_base_to_groups(mainvar, scene); + } } } - } - else { - printf("library_append_end, scene is NULL (objects wont get bases)\n"); + else { + printf("library_append_end, scene is NULL (objects wont get bases)\n"); + } + + append_do_cursor(scene, curlib, flag); } /* has been removed... erm, why? s..ton) */ /* 20040907: looks like they are give base already in append_named_part(); -Nathan L */ @@ -13105,8 +13111,6 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in blo_freefiledata( *fd ); *fd = NULL; } - - append_do_cursor(scene, curlib, flag); } void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag) -- cgit v1.2.3 From 9da70f74d37c7c0001a2705afc8fe5044f63bb0a Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 4 Aug 2011 10:05:14 +0000 Subject: UserPref/Node editor feature: Change the level of noodle curving. Some people like curved lines, other hate them. This commit will let the user change the level of curving. In UserPreferences=>Themes=>Node editor=>Noodle curving the level can be modified. Allowed range is 0-10 with the default on 5 The patch will default everything to the way blender works ATM. File subversion has been increased otherwise older 258 files got straight lines. The data is stored in the ThemeSpace.noodle_curving the bezierdrawing is done in the drawnode. Also tested the Line cut tool --- source/blender/editors/include/UI_resources.h | 4 +++- source/blender/editors/interface/resources.c | 14 ++++++++++++-- source/blender/editors/space_node/drawnode.c | 4 ++-- source/blender/makesdna/DNA_userdef_types.h | 2 +- source/blender/makesrna/intern/rna_userdef.c | 7 +++++++ 5 files changed, 25 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h index 2311aafbb17..d0c2b387445 100644 --- a/source/blender/editors/include/UI_resources.h +++ b/source/blender/editors/include/UI_resources.h @@ -242,7 +242,9 @@ enum { TH_DRAWEXTRA_EDGELEN, TH_DRAWEXTRA_FACEAREA, - TH_DRAWEXTRA_FACEANG + TH_DRAWEXTRA_FACEANG, + + TH_NODE_CURVING }; /* XXX WARNING: previous is saved in file, so do not change order! */ diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 0c755180b3a..f58383830cb 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -360,7 +360,9 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo cp= ts->syntaxv; break; case TH_NODE_GROUP: cp= ts->syntaxc; break; - + case TH_NODE_CURVING: + cp= &ts->noodle_curving; break; + case TH_SEQ_MOVIE: cp= ts->movie; break; case TH_SEQ_IMAGE: @@ -787,6 +789,7 @@ void ui_theme_init_default(void) SETCOL(btheme->tnode.syntaxb, 108, 105, 111, 255); /* operator */ SETCOL(btheme->tnode.syntaxv, 104, 106, 117, 255); /* generator */ SETCOL(btheme->tnode.syntaxc, 105, 117, 110, 255); /* group */ + btheme->tnode.noodle_curving = 5; /* space logic */ btheme->tlogic= btheme->tv3d; @@ -1553,7 +1556,14 @@ void init_userdef_do_versions(void) /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs, so that it doesn't linger around from old configs like a ghost */ U.autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET; } - + + if (bmain->versionfile < 258 || (bmain->versionfile == 258 && bmain->subversionfile < 2)) { + bTheme *btheme; + for(btheme= U.themes.first; btheme; btheme= btheme->next) { + btheme->tnode.noodle_curving = 5; + } + } + /* GL Texture Garbage Collection (variable abused above!) */ if (U.textimeout == 0) { U.texcollectrate = 60; diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 50e657bbb61..c32d05e9c30 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -1768,8 +1768,8 @@ int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, floa vec[3][0]= snode->mx; vec[3][1]= snode->my; } - - dist= 0.5f*ABS(vec[0][0] - vec[3][0]); + + dist= UI_GetThemeValue(TH_NODE_CURVING)*0.10f*ABS(vec[0][0] - vec[3][0]); /* check direction later, for top sockets */ vec[1][0]= vec[0][0]+dist; diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 0bf812f1ec2..aa6da3aaeca 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -220,7 +220,7 @@ typedef struct ThemeSpace { char console_cursor[4]; char vertex_size, outline_width, facedot_size; - char bpad; + char noodle_curving; char syntaxl[4], syntaxn[4], syntaxb[4]; // syntax for textwindow and nodes char syntaxv[4], syntaxc[4]; diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 7a9193571fd..a1a99c34e70 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -1351,6 +1351,13 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna) RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Group Node", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); + + prop= RNA_def_property(srna, "noodle_curving", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "noodle_curving"); + RNA_def_property_int_default(prop, 5); + RNA_def_property_range(prop, 0, 10); + RNA_def_property_ui_text(prop, "Noodle curving", "Curving of the noodle"); + RNA_def_property_update(prop, 0, "rna_userdef_update"); } static void rna_def_userdef_theme_space_logic(BlenderRNA *brna) -- cgit v1.2.3 From cdea64e32cbe1a8b9c9312b04cf15b0ac3daf685 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Aug 2011 11:27:13 +0000 Subject: remove append to cursor code, wasnt used and made some naive assumptions about object locations. --- source/blender/blenloader/intern/readfile.c | 49 ----------------------------- source/blender/makesdna/DNA_space_types.h | 2 +- 2 files changed, 1 insertion(+), 50 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 0a24dfaed72..d60ac492f97 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -12999,53 +12999,6 @@ Main* BLO_library_append_begin(const bContext *C, BlendHandle** bh, const char * return library_append_begin(C, &fd, filepath); } -static void append_do_cursor(Scene *scene, Library *curlib, short flag) -{ - Base *centerbase; - Object *ob; - float *curs, centerloc[3], vec[3], min[3], max[3]; - int count= 0; - - /* when not linking (appending)... */ - if(flag & FILE_LINK) - return; - - /* we're not appending at cursor */ - if((flag & FILE_ATCURSOR) == 0) - return; - - /* find the center of everything appended */ - INIT_MINMAX(min, max); - centerbase= (scene->base.first); - while(centerbase) { - if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) { - VECCOPY(vec, centerbase->object->loc); - DO_MINMAX(vec, min, max); - count++; - } - centerbase= centerbase->next; - } - /* we haven't found any objects to move to cursor */ - if(!count) - return; - - /* move from the center of the appended objects to cursor */ - mid_v3_v3v3(centerloc, min, max); - curs = scene->cursor; - VECSUB(centerloc,curs,centerloc); - - /* now translate the center of the objects */ - centerbase= (scene->base.first); - while(centerbase) { - if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) { - ob= centerbase->object; - ob->loc[0] += centerloc[0]; - ob->loc[1] += centerloc[1]; - ob->loc[2] += centerloc[2]; - } - centerbase= centerbase->next; - } -} /* Context == NULL signifies not to do any scene manipulation */ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, int idcode, short flag) @@ -13099,8 +13052,6 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in else { printf("library_append_end, scene is NULL (objects wont get bases)\n"); } - - append_do_cursor(scene, curlib, flag); } /* has been removed... erm, why? s..ton) */ /* 20040907: looks like they are give base already in append_named_part(); -Nathan L */ diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index ff9f2269f53..1549bd71748 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -703,7 +703,7 @@ enum FileSortTypeE { #define FILE_HIDE_DOT (1<<3) #define FILE_AUTOSELECT (1<<4) #define FILE_ACTIVELAY (1<<5) -#define FILE_ATCURSOR (1<<6) +/* #define FILE_ATCURSOR (1<<6) */ /* deprecated */ #define FILE_DIRSEL_ONLY (1<<7) #define FILE_FILTER (1<<8) #define FILE_BOOKMARKS (1<<9) -- cgit v1.2.3 From 26fe903502368f1a255f44bbc75e308e08a5d659 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 4 Aug 2011 12:19:50 +0000 Subject: Typo when reading line curving. The subversion is 1, so smaller than 1 should be converted --- source/blender/editors/interface/resources.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index f58383830cb..32e87b3a793 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1557,7 +1557,7 @@ void init_userdef_do_versions(void) U.autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET; } - if (bmain->versionfile < 258 || (bmain->versionfile == 258 && bmain->subversionfile < 2)) { + if (bmain->versionfile < 258 || (bmain->versionfile == 258 && bmain->subversionfile < 1)) { bTheme *btheme; for(btheme= U.themes.first; btheme; btheme= btheme->next) { btheme->tnode.noodle_curving = 5; -- cgit v1.2.3 From 36bf4385c2c2a1d3f462d30138b6815287d8e548 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Aug 2011 13:22:38 +0000 Subject: fix for building with clang. makesrna wasnt linking with sqrt --- source/blender/makesrna/intern/rna_object_api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 21fa28af01a..d48f1c93da8 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -45,9 +45,9 @@ // #include "ED_mesh.h" -#include "BLI_math.h" #ifdef RNA_RUNTIME +#include "BLI_math.h" #include "BKE_main.h" #include "BKE_global.h" @@ -544,7 +544,8 @@ void RNA_api_object(StructRNA *srna) /* location of point for test and max distance */ parm= RNA_def_float_vector(func, "point", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4); RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_float(func, "max_dist", sqrt(FLT_MAX), 0.0, FLT_MAX, "", "", 0.0, FLT_MAX); + /* default is sqrt(FLT_MAX) */ + RNA_def_float(func, "max_dist", 1.844674352395373e+19, 0.0, FLT_MAX, "", "", 0.0, FLT_MAX); /* return location and normal */ parm= RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "The location on the object closest to the point", -1e4, 1e4); -- cgit v1.2.3 From f77af0a8cef8e7be6245c6f4c52dd05f6c7a387f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 05:26:19 +0000 Subject: change BLO_library_append_begin to take a main argument rather then a context, means the BGE doesnt need to make a new empty context just to pass as an arg. added doxygen description too. this quiets the print when the BGE does linking. --- source/blender/blenloader/BLO_readfile.h | 16 ++++++++++------ source/blender/blenloader/intern/readfile.c | 7 +++---- source/blender/python/intern/bpy_library.c | 3 ++- source/blender/windowmanager/intern/wm_operators.c | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 85d4b936c51..47931477728 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -211,7 +211,16 @@ int BLO_has_bfile_extension(char *str); */ int BLO_is_a_library(const char *path, char *dir, char *group); -struct Main* BLO_library_append_begin(const struct bContext *C, BlendHandle** bh, const char *filepath); + +/** + * Initialize the BlendHandle for appending or linking library data. + * + * @param mainvar The current main database eg G.main or CTX_data_main(C). + * @param bh A blender file handle as returned by BLO_blendhandle_from_file or BLO_blendhandle_from_memory. + * @param filepath Used for relative linking, copied to the lib->name + * @return the library Main, to be passed to BLO_library_append_named_part as mainl. + */ +struct Main* BLO_library_append_begin(struct Main *mainvar, BlendHandle** bh, const char *filepath); /** @@ -243,11 +252,6 @@ void BLO_library_append_end(const struct bContext *C, struct Main *mainl, BlendH void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname); -/* deprecated */ -#if 1 -void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, int idcode, short flag, struct Main *mainvar, struct Scene *scene, struct ReportList *reports); -#endif - BlendFileData* blo_read_blendafterruntime(int file, char *name, int actualsize, struct ReportList *reports); #ifdef __cplusplus diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d60ac492f97..44c8ca97be9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -12975,9 +12975,8 @@ static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r) /* common routine to append/link something from a library */ -static Main* library_append_begin(const bContext *C, FileData **fd, const char *filepath) +static Main* library_append_begin(Main *mainvar, FileData **fd, const char *filepath) { - Main *mainvar= CTX_data_main(C); Main *mainl; /* make mains */ @@ -12993,10 +12992,10 @@ static Main* library_append_begin(const bContext *C, FileData **fd, const char * return mainl; } -Main* BLO_library_append_begin(const bContext *C, BlendHandle** bh, const char *filepath) +Main* BLO_library_append_begin(Main *mainvar, BlendHandle** bh, const char *filepath) { FileData *fd= (FileData*)(*bh); - return library_append_begin(C, &fd, filepath); + return library_append_begin(mainvar, &fd, filepath); } diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c index 85bffb5a8cc..4ce3e0356e2 100644 --- a/source/blender/python/intern/bpy_library.c +++ b/source/blender/python/intern/bpy_library.c @@ -39,6 +39,7 @@ #include "BKE_library.h" #include "BKE_idcode.h" #include "BKE_report.h" +#include "BKE_context.h" #include "BLI_utildefines.h" #include "BLI_string.h" @@ -317,7 +318,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) flag_all_listbases_ids(LIB_PRE_EXISTING, 1); /* here appending/linking starts */ - mainl= BLO_library_append_begin(BPy_GetContext(), &(self->blo_handle), self->relpath); + mainl= BLO_library_append_begin(CTX_data_main(BPy_GetContext()), &(self->blo_handle), self->relpath); { int i= 0, code; diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index a47dfacf358..5a05be0fefc 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1690,7 +1690,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) flag_all_listbases_ids(LIB_PRE_EXISTING, 1); /* here appending/linking starts */ - mainl = BLO_library_append_begin(C, &bh, libname); + mainl = BLO_library_append_begin(bmain, &bh, libname); if(totfiles == 0) { BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag); } -- cgit v1.2.3 From 82e863bdae70b1297318aa7fd98f72cab074ef66 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 06:06:15 +0000 Subject: fix [#28102] Typing 'C:' into the file selector's directory asks to make a new directory. --- source/blender/editors/space_file/file_ops.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 77524c7e117..d4253495e97 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -64,6 +64,7 @@ #include #include #include +#include /* for events */ #define NOTACTIVEFILE 0 @@ -1079,8 +1080,18 @@ static void file_expand_directory(bContext *C) } #ifdef WIN32 - if (sfile->params->dir[0] == '\0') + if (sfile->params->dir[0] == '\0') { get_default_root(sfile->params->dir); + } + /* change "C:" --> "C:\", [#28102] */ + else if ( (isalpha(sfile->params->dir[0]) && + (sfile->params->dir[1] == ':')) && + (sfile->params->dir[2] == '\0') + + ) { + sfile->params->dir[2]= '\\'; + sfile->params->dir[3]= '\0'; + } #endif } } -- cgit v1.2.3 From c946969bb90c177319c183e7155c6f360230ea2f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 06:09:30 +0000 Subject: fix for possible uninitialized RNA strings, when RNA_string_get property is not found, initialize the string to "". --- source/blender/makesrna/intern/rna_access.c | 7 +++++-- source/blender/windowmanager/intern/wm_operators.c | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index e71be8c153e..f1056c86a4c 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4007,10 +4007,13 @@ void RNA_string_get(PointerRNA *ptr, const char *name, char *value) { PropertyRNA *prop= RNA_struct_find_property(ptr, name); - if(prop) + if(prop) { RNA_property_string_get(ptr, prop, value); - else + } + else { printf("RNA_string_get: %s.%s not found.\n", ptr->type->identifier, name); + value[0]= '\0'; + } } char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen) diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 5a05be0fefc..7238cede2cc 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1621,7 +1621,6 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) int idcode, totfiles=0; short flag; - name[0] = '\0'; RNA_string_get(op->ptr, "filename", name); RNA_string_get(op->ptr, "directory", dir); -- cgit v1.2.3 From f48631e9a4afb8d7d4ab4e15963b38ba75605f68 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 06:26:54 +0000 Subject: fix [#28160] Pressing Y on an image sequence to seperate the images takes them out of their meta strips dont show a popup anymore, was silly because you had to change the value for before anything was done, can use f6 redo popup instead, sequencer should eventually have a view3d operator redo panel. --- source/blender/editors/space_sequencer/sequencer_edit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index b7a7b6b5412..6a69d32d307 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -1785,7 +1785,7 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op) se = give_stripelem(seq, cfra); seq_new= seq_dupli_recursive(scene, scene, seq, SEQ_DUPE_UNIQUE_NAME); - BLI_addtail(&ed->seqbase, seq_new); + BLI_addtail(ed->seqbasep, seq_new); seq_new->start= start_ofs; seq_new->type= SEQ_IMAGE; @@ -1839,7 +1839,6 @@ void SEQUENCER_OT_images_separate(wmOperatorType *ot) ot->description="On image sequences strips, it return a strip for each image"; /* api callbacks */ - ot->invoke= WM_operator_props_popup; ot->exec= sequencer_separate_images_exec; ot->poll= sequencer_edit_poll; -- cgit v1.2.3 From ad7ea2f89205dd67b84ec76d70352ad56004293a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 09:04:11 +0000 Subject: get a tad more vertical space in the toolbar. --- source/blender/editors/curve/editfont.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 649ff9e953a..6c95df53d39 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1649,10 +1649,10 @@ static int open_exec(bContext *C, wmOperator *op) VFont *font; PropertyPointerRNA *pprop; PointerRNA idptr; - char str[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", str); + char filepath[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", filepath); - font = load_vfont(str); + font= load_vfont(filepath); if(!font) { if(op->customdata) MEM_freeN(op->customdata); -- cgit v1.2.3 From a157112ac5c6465fd8d9518af87ce86a5250eeba Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 10:45:32 +0000 Subject: fix for icon scaling with the DPI setting - icons were scaling by the sqrt(dpi)/8.48528, but infact they only need to be scaled by (dpi/72). - UI_icon_get_width value was being used without multiplying by dpi scale. --- source/blender/editors/include/UI_interface.h | 3 +++ source/blender/editors/interface/interface_handlers.c | 2 +- source/blender/editors/interface/interface_icons.c | 3 ++- source/blender/editors/interface/interface_widgets.c | 15 +++++++-------- 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 61e19655f8d..1bae6ce0214 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -164,6 +164,9 @@ typedef struct uiLayout uiLayout; /* scale fixed button widths by this to account for DPI * 8.4852 == sqrtf(72.0f)) */ #define UI_DPI_FAC (sqrtf((float)U.dpi) / 8.48528137423857f) +#define UI_DPI_ICON_FAC (((float)U.dpi) / 72.0f) +/* 16 to copy ICON_DEFAULT_HEIGHT */ +#define UI_DPI_ICON_SIZE ((float)16 * UI_DPI_ICON_FAC) /* Button types, bits stored in 1 value... and a short even! - bits 0-4: bitnr (0-31) diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index c5275ea98b5..b3272a2e3d4 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1290,7 +1290,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho else if(ELEM(but->type, TEX, SEARCH_MENU)) { startx += 5; if (but->flag & UI_HAS_ICON) - startx += 16; + startx += UI_DPI_ICON_SIZE; } /* mouse dragged outside the widget to the left */ diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 3bf2a9ddd02..412c0233c35 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -742,6 +742,7 @@ static DrawInfo *icon_create_drawinfo(void) return di; } +/* note!, returns unscaled by DPI, may need to multiply result by UI_DPI_ICON_FAC */ int UI_icon_get_width(int icon_id) { Icon *icon = NULL; @@ -952,7 +953,7 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al Icon *icon = NULL; DrawInfo *di = NULL; IconImage *iimg; - float fdraw_size= UI_DPI_FAC*draw_size; + float fdraw_size= UI_DPI_ICON_FAC*draw_size; int w, h; icon = BKE_icon_get(icon_id); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 25a64994f5c..d235fd0c16a 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -771,7 +771,6 @@ static void widget_draw_preview(BIFIconID icon, float UNUSED(alpha), rcti *rect) /* icons have been standardized... and this call draws in untransformed coordinates */ -#define ICON_HEIGHT UI_DPI_FAC*16.0f static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect) { @@ -791,15 +790,15 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect if(aspect != but->aspect) { /* prevent scaling up icon in pupmenu */ if (aspect < 1.0f) { - height= ICON_HEIGHT; + height= UI_DPI_ICON_SIZE; aspect = 1.0f; } else - height= ICON_HEIGHT/aspect; + height= UI_DPI_ICON_SIZE/aspect; } else - height= ICON_HEIGHT; + height= UI_DPI_ICON_SIZE; /* calculate blend color */ if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) { @@ -866,7 +865,7 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10; int okwidth= rect->xmax-rect->xmin - border; - if (but->flag & UI_HAS_ICON) okwidth -= 16; + if (but->flag & UI_HAS_ICON) okwidth -= UI_DPI_ICON_SIZE; /* need to set this first */ uiStyleFontSet(fstyle); @@ -1149,7 +1148,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB if (but->flag & UI_HAS_ICON) { widget_draw_icon(but, but->icon+but->iconadd, 1.0f, rect); - rect->xmin += UI_icon_get_width(but->icon+but->iconadd); + rect->xmin += (int)((float)UI_icon_get_width(but->icon+but->iconadd) * UI_DPI_ICON_FAC); if(but->editstr || (but->flag & UI_TEXT_LEFT)) rect->xmin += 5; @@ -3133,7 +3132,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic /* text location offset */ rect->xmin+=5; - if(iconid) rect->xmin+= ICON_HEIGHT; + if(iconid) rect->xmin+= UI_DPI_ICON_SIZE; /* cut string in 2 parts? */ cpoin= strchr(name, '|'); @@ -3158,7 +3157,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic if(iconid) { int xs= rect->xmin+4; - int ys= 1 + (rect->ymin+rect->ymax- ICON_HEIGHT)/2; + int ys= 1 + (rect->ymin+rect->ymax- UI_DPI_ICON_SIZE)/2; glEnable(GL_BLEND); UI_icon_draw_aspect(xs, ys, iconid, 1.2f, 0.5f); /* XXX scale weak get from fstyle? */ glDisable(GL_BLEND); -- cgit v1.2.3 From db319f8544a908a280a92550fc4c2cc706fc12e2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 14:53:13 +0000 Subject: move the ndof menu into the userpref's since it adjusts preferences, also renamed VIEW3D_MT_ndof_settings -> USERPREF_MT_ndof_settings since it has no view3d specific settings. --- source/blender/windowmanager/intern/wm_operators.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 7238cede2cc..cea2d6b3fe5 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -3719,7 +3719,7 @@ void wm_window_keymap(wmKeyConfig *keyconf) /* menus that can be accessed anywhere in blender */ WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); - WM_keymap_add_menu(keymap, "VIEW3D_MT_ndof_settings", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); + WM_keymap_add_menu(keymap, "USERPREF_MT_ndof_settings", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); /* Space switching */ kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */ -- cgit v1.2.3 From 85fe36ab611aae8b47089c24110d4d176bc8143c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 16:21:37 +0000 Subject: pyrna - add own callable function type rather then using a standard python method, gives small speedup drawing buttons since every layout.prop/col/operator/menu etc creates and throws away one of these. --- source/blender/python/intern/bpy_rna.c | 135 +++++++++++++++++++++++++-------- source/blender/python/intern/bpy_rna.h | 10 +++ 2 files changed, 115 insertions(+), 30 deletions(-) (limited to 'source/blender') diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 502b25842de..d517205e2fe 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -908,6 +908,13 @@ static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self) return ret; } + +static PyObject *pyrna_func_repr(BPy_FunctionRNA *self) +{ + return PyUnicode_FromFormat("<%.200s %.200s.%.200s()>", Py_TYPE(self)->tp_name, RNA_struct_identifier(self->ptr.type), RNA_function_identifier(self->func)); +} + + static long pyrna_struct_hash(BPy_StructRNA *self) { return _Py_HashPointer(self->ptr.data); @@ -1344,36 +1351,16 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha return error_val; } -static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw); -static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func) +static PyObject *pyrna_func_to_py(PointerRNA *ptr, FunctionRNA *func) { - static PyMethodDef func_meth= {"", (PyCFunction)pyrna_func_call, METH_VARARGS|METH_KEYWORDS, "python rna function"}; - PyObject *self; - PyObject *ret; - - if(func==NULL) { - PyErr_Format(PyExc_RuntimeError, - "%.200s: type attempted to get NULL function", - RNA_struct_identifier(pyrna->ptr.type)); - return NULL; - } - - self= PyTuple_New(2); - - PyTuple_SET_ITEM(self, 0, (PyObject *)pyrna); - Py_INCREF(pyrna); - - PyTuple_SET_ITEM(self, 1, PyCapsule_New((void *)func, NULL, NULL)); - - ret= PyCFunction_New(&func_meth, self); - Py_DECREF(self); - - return ret; + BPy_FunctionRNA* pyfunc= (BPy_FunctionRNA *) PyObject_NEW(BPy_FunctionRNA, &pyrna_func_Type); + pyfunc->ptr= *ptr; + pyfunc->func= func; + return (PyObject *)pyfunc; } - static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value, const char *error_prefix) { /* XXX hard limits should be checked here */ @@ -3001,7 +2988,7 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname) } /* RNA function only if callback is declared (no optional functions) */ else if ((func= RNA_struct_find_function(&self->ptr, name)) && RNA_function_defined(func)) { - ret= pyrna_func_to_py((BPy_DummyPointerRNA *)self, func); + ret= pyrna_func_to_py(&self->ptr, func); } else if (self->ptr.type == &RNA_Context) { bContext *C= self->ptr.data; @@ -3303,7 +3290,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject } else if ((func= RNA_struct_find_function(&r_ptr, name))) { PyObject *self_collection= pyrna_struct_CreatePyObject(&r_ptr); - ret= pyrna_func_to_py((BPy_DummyPointerRNA *)self_collection, func); + ret= pyrna_func_to_py(&((BPy_DummyPointerRNA *)self_collection)->ptr, func); Py_DECREF(self_collection); return ret; @@ -4257,11 +4244,11 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat return ret; } -static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw) +static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject *kw) { /* Note, both BPy_StructRNA and BPy_PropertyRNA can be used here */ - PointerRNA *self_ptr= &(((BPy_DummyPointerRNA *)PyTuple_GET_ITEM(self, 0))->ptr); - FunctionRNA *self_func= PyCapsule_GetPointer(PyTuple_GET_ITEM(self, 1), NULL); + PointerRNA *self_ptr= &self->ptr; + FunctionRNA *self_func= self->func; PointerRNA funcptr; ParameterList parms; @@ -5045,6 +5032,91 @@ static PyTypeObject pyrna_prop_collection_idprop_Type= { NULL }; +/*-----------------------BPy_PropertyRNA method def------------------------------*/ +PyTypeObject pyrna_func_Type= { + PyVarObject_HEAD_INIT(NULL, 0) + "bpy_func", /* tp_name */ + sizeof(BPy_FunctionRNA), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + NULL, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */ + (reprfunc) pyrna_func_repr, /* tp_repr */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + NULL, /* PySequenceMethods *tp_as_sequence; */ + NULL, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + NULL, /* hashfunc tp_hash; */ + (ternaryfunc)pyrna_func_call, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + + /* will only use these if this is a subtype of a py class */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ +#ifdef USE_WEAKREFS + offsetof(BPy_PropertyRNA, in_weakreflist), /* long tp_weaklistoffset; */ +#else + 0, +#endif + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + + /*** Attribute descriptor and subclassing stuff ***/ + NULL, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + NULL, /* newfunc tp_new; */ + /* Low-level free-memory routine */ + NULL, /* freefunc tp_free; */ + /* For PyObject_IS_GC */ + NULL, /* inquiry tp_is_gc; */ + NULL, /* PyObject *tp_bases; */ + /* method resolution order */ + NULL, /* PyObject *tp_mro; */ + NULL, /* PyObject *tp_cache; */ + NULL, /* PyObject *tp_subclasses; */ + NULL, /* PyObject *tp_weaklist; */ + NULL +}; + #ifdef USE_PYRNA_ITER /* --- collection iterator: start --- */ /* wrap rna collection iterator functions */ @@ -5516,6 +5588,9 @@ void BPY_rna_init(void) if(PyType_Ready(&pyrna_prop_collection_idprop_Type) < 0) return; + if(PyType_Ready(&pyrna_func_Type) < 0) + return; + #ifdef USE_PYRNA_ITER if(PyType_Ready(&pyrna_prop_collection_iter_Type) < 0) return; diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 5db352af53d..3796984ea81 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -71,6 +71,7 @@ extern PyTypeObject pyrna_struct_Type; extern PyTypeObject pyrna_prop_Type; extern PyTypeObject pyrna_prop_array_Type; extern PyTypeObject pyrna_prop_collection_Type; +extern PyTypeObject pyrna_func_Type; #define BPy_StructRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_struct_Type)) #define BPy_StructRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_struct_Type) @@ -142,6 +143,15 @@ typedef struct { CollectionPropertyIterator iter; } BPy_PropertyCollectionIterRNA; +typedef struct { + PyObject_HEAD /* required python macro */ +#ifdef USE_WEAKREFS + PyObject *in_weakreflist; +#endif + PointerRNA ptr; + FunctionRNA *func; +} BPy_FunctionRNA; + /* cheap trick */ #define BPy_BaseTypeRNA BPy_PropertyRNA -- cgit v1.2.3 From 3a82a690abca993866c30f03696e8d2415455f64 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Aug 2011 16:29:38 +0000 Subject: ifdef out support for for python owning and freeing BPy_StructRNA because this is only used for doc generation and it makes _every_ blender/python instance 4 bytes bigger - vertex/bezier point/object/scene/group etc. --- source/blender/python/intern/bpy_operator.c | 2 ++ source/blender/python/intern/bpy_rna.c | 4 ++++ source/blender/python/intern/bpy_rna.h | 8 ++++++++ 3 files changed, 14 insertions(+) (limited to 'source/blender') diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 4a17c45ae38..4b05a9c0c72 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -397,7 +397,9 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); +#ifdef PYRNA_FREE_SUPPORT pyrna->freeptr= TRUE; +#endif return (PyObject *)pyrna; } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index d517205e2fe..4447a0476f4 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -957,11 +957,13 @@ static int pyrna_struct_clear(BPy_StructRNA *self) /* use our own dealloc so we can free a property if we use one */ static void pyrna_struct_dealloc(BPy_StructRNA *self) { +#ifdef PYRNA_FREE_SUPPORT if (self->freeptr && self->ptr.data) { IDP_FreeProperty(self->ptr.data); MEM_freeN(self->ptr.data); self->ptr.data= NULL; } +#endif /* PYRNA_FREE_SUPPORT */ #ifdef USE_WEAKREFS if (self->in_weakreflist != NULL) { @@ -5495,7 +5497,9 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr) } pyrna->ptr= *ptr; +#ifdef PYRNA_FREE_SUPPORT pyrna->freeptr= FALSE; +#endif #ifdef USE_PYRNA_STRUCT_REFERENCE pyrna->reference= NULL; diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 3796984ea81..30f6c02115a 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -62,6 +62,11 @@ #if defined(USE_PYRNA_INVALIDATE_GC) && defined(USE_PYRNA_INVALIDATE_WEAKREF) #error "Only 1 reference check method at a time!" #endif + +/* only used by operator introspection get_rna(), this is only used for doc gen + * so prefer the leak to the memory bloat for now. */ +// #define PYRNA_FREE_SUPPORT + /* --- end bpy build options --- */ struct ID; @@ -108,7 +113,10 @@ typedef struct { * hold onto the collection iterator to prevent it from freeing allocated data we may use */ PyObject *reference; #endif /* !USE_PYRNA_STRUCT_REFERENCE */ + +#ifdef PYRNA_FREE_SUPPORT int freeptr; /* needed in some cases if ptr.data is created on the fly, free when deallocing */ +#endif /* PYRNA_FREE_SUPPORT */ } BPy_StructRNA; typedef struct { -- cgit v1.2.3 From e6e4c7ef8bd53b06c879302bbfd3d6a00c6c48af Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 5 Aug 2011 20:45:26 +0000 Subject: KEYMAP REFACTORING Diff Keymaps User edited keymaps now no longer override the builtin keymaps entirely, but rather save only the difference and reapply those changes. This means they can stay better in sync when the builtin keymaps change. The diff/patch algorithm is not perfect, but better for the common case where only a few items are changed rather than entire keymaps The main weakness is that if a builtin keymap item changes, user modification of that item may need to be redone in some cases. Keymap Editor The most noticeable change here is that there is no longer an "Edit" button for keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps and items that have been edited. Shortcuts for addons can also be edited in the keymap editor. Addons Addons now should only modify the new addon keyconfiguration, the keymap items there will be added to the builtin ones for handling events, and not get lost when starting new files. Example code of register/unregister: km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D") km.keymap_items.new('my.operator', 'ESC', 'PRESS') km = wm.keyconfigs.addon.keymaps["3D View"] km.keymap_items.remove(km.keymap_items["my.operator"]) Compatibility The changes made are not forward compatible, i.e. if you save user preferences with newer versions, older versions will not have key configuration changes that were made. --- source/blender/blenkernel/intern/blender.c | 33 +- source/blender/blenloader/intern/readfile.c | 40 +- source/blender/blenloader/intern/writefile.c | 24 +- .../blender/editors/interface/interface_handlers.c | 25 +- source/blender/editors/interface/resources.c | 2 +- source/blender/makesdna/DNA_userdef_types.h | 3 +- source/blender/makesdna/DNA_windowmanager_types.h | 24 +- source/blender/makesrna/intern/rna_internal.h | 3 + source/blender/makesrna/intern/rna_scene.c | 2 +- source/blender/makesrna/intern/rna_userdef.c | 6 - source/blender/makesrna/intern/rna_wm.c | 247 ++----- source/blender/makesrna/intern/rna_wm_api.c | 183 +++++- source/blender/windowmanager/WM_api.h | 44 +- source/blender/windowmanager/WM_keymap.h | 104 +++ source/blender/windowmanager/intern/wm.c | 10 +- .../blender/windowmanager/intern/wm_event_system.c | 6 + source/blender/windowmanager/intern/wm_files.c | 13 +- source/blender/windowmanager/intern/wm_keymap.c | 718 ++++++++++++++++----- 18 files changed, 1022 insertions(+), 465 deletions(-) create mode 100644 source/blender/windowmanager/WM_keymap.h (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 8b4bbbd3c83..7e2097d1233 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -330,28 +330,45 @@ static int handle_subversion_warning(Main *main) return 1; } +static void keymap_item_free(wmKeyMapItem *kmi) +{ + if(kmi->properties) { + IDP_FreeProperty(kmi->properties); + MEM_freeN(kmi->properties); + } + if(kmi->ptr) + MEM_freeN(kmi->ptr); +} + void BKE_userdef_free(void) { wmKeyMap *km; wmKeyMapItem *kmi; + wmKeyMapDiffItem *kmdi; - for(km=U.keymaps.first; km; km=km->next) { - for(kmi=km->items.first; kmi; kmi=kmi->next) { - if(kmi->properties) { - IDP_FreeProperty(kmi->properties); - MEM_freeN(kmi->properties); + for(km=U.user_keymaps.first; km; km=km->next) { + for(kmdi=km->diff_items.first; kmdi; kmdi=kmdi->next) { + if(kmdi->add_item) { + keymap_item_free(kmdi->add_item); + MEM_freeN(kmdi->add_item); + } + if(kmdi->remove_item) { + keymap_item_free(kmdi->remove_item); + MEM_freeN(kmdi->remove_item); } - if(kmi->ptr) - MEM_freeN(kmi->ptr); } + for(kmi=km->items.first; kmi; kmi=kmi->next) + keymap_item_free(kmi); + + BLI_freelistN(&km->diff_items); BLI_freelistN(&km->items); } BLI_freelistN(&U.uistyles); BLI_freelistN(&U.uifonts); BLI_freelistN(&U.themes); - BLI_freelistN(&U.keymaps); + BLI_freelistN(&U.user_keymaps); BLI_freelistN(&U.addons); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 44c8ca97be9..bd12677485c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4726,6 +4726,8 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) wm->keyconfigs.first= wm->keyconfigs.last= NULL; wm->defaultconf= NULL; + wm->addonconf= NULL; + wm->userconf= NULL; wm->jobs.first= wm->jobs.last= NULL; wm->drags.first= wm->drags.last= NULL; @@ -11762,33 +11764,57 @@ static void lib_link_all(FileData *fd, Main *main) lib_link_library(fd, main); /* only init users */ } +static void direct_link_keymapitem(FileData *fd, wmKeyMapItem *kmi) +{ + kmi->properties= newdataadr(fd, kmi->properties); + if(kmi->properties) + IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + kmi->ptr= NULL; + kmi->flag &= ~KMI_UPDATE; +} static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) { UserDef *user; wmKeyMap *keymap; wmKeyMapItem *kmi; + wmKeyMapDiffItem *kmdi; bfd->user= user= read_struct(fd, bhead, "user def"); /* read all data into fd->datamap */ bhead= read_data_into_oldnewmap(fd, bhead, "user def"); + if(user->keymaps.first) { + /* backwards compatibility */ + user->user_keymaps= user->keymaps; + user->keymaps.first= user->keymaps.last= NULL; + } + link_list(fd, &user->themes); - link_list(fd, &user->keymaps); + link_list(fd, &user->user_keymaps); link_list(fd, &user->addons); - for(keymap=user->keymaps.first; keymap; keymap=keymap->next) { + for(keymap=user->user_keymaps.first; keymap; keymap=keymap->next) { keymap->modal_items= NULL; keymap->poll= NULL; + keymap->flag &= ~KEYMAP_UPDATE; + link_list(fd, &keymap->diff_items); link_list(fd, &keymap->items); - for(kmi=keymap->items.first; kmi; kmi=kmi->next) { - kmi->properties= newdataadr(fd, kmi->properties); - if(kmi->properties) - IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - kmi->ptr= NULL; + + for(kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) { + kmdi->remove_item= newdataadr(fd, kmdi->remove_item); + kmdi->add_item= newdataadr(fd, kmdi->add_item); + + if(kmdi->remove_item) + direct_link_keymapitem(fd, kmdi->remove_item); + if(kmdi->add_item) + direct_link_keymapitem(fd, kmdi->add_item); } + + for(kmi=keymap->items.first; kmi; kmi=kmi->next) + direct_link_keymapitem(fd, kmi); } // XXX diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index bf86527b9d3..7d65248c0e9 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -717,11 +717,19 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) /* for renderdeamon } } +static void write_keymapitem(WriteData *wd, wmKeyMapItem *kmi) +{ + writestruct(wd, DATA, "wmKeyMapItem", 1, kmi); + if(kmi->properties) + IDP_WriteProperty(kmi->properties, wd); +} + static void write_userdef(WriteData *wd) { bTheme *btheme; wmKeyMap *keymap; wmKeyMapItem *kmi; + wmKeyMapDiffItem *kmdi; bAddon *bext; uiStyle *style; @@ -730,15 +738,19 @@ static void write_userdef(WriteData *wd) for(btheme= U.themes.first; btheme; btheme=btheme->next) writestruct(wd, DATA, "bTheme", 1, btheme); - for(keymap= U.keymaps.first; keymap; keymap=keymap->next) { + for(keymap= U.user_keymaps.first; keymap; keymap=keymap->next) { writestruct(wd, DATA, "wmKeyMap", 1, keymap); - for(kmi=keymap->items.first; kmi; kmi=kmi->next) { - writestruct(wd, DATA, "wmKeyMapItem", 1, kmi); - - if(kmi->properties) - IDP_WriteProperty(kmi->properties, wd); + for(kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) { + writestruct(wd, DATA, "wmKeyMapDiffItem", 1, kmdi); + if(kmdi->remove_item) + write_keymapitem(wd, kmdi->remove_item); + if(kmdi->add_item) + write_keymapitem(wd, kmdi->add_item); } + + for(kmi=keymap->items.first; kmi; kmi=kmi->next) + write_keymapitem(wd, kmi); } for(bext= U.addons.first; bext; bext=bext->next) diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index b3272a2e3d4..d8d8354b0b9 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -4067,7 +4067,6 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event)) /* complex code to change name of button */ if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) { - wmKeyMap *km= NULL; char *butstr_orig; // XXX but->str changed... should not, remove the hotkey from it @@ -4080,10 +4079,6 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event)) but->str= but->strdata; ui_check_but(but); - - /* set the keymap editable else the key wont save */ - WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, 1, &km); - WM_keymap_copy_to_user(km); } else { /* shortcut was removed */ @@ -4095,6 +4090,7 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event)) static uiBlock *menu_change_shortcut(bContext *C, ARegion *ar, void *arg) { + wmWindowManager *wm= CTX_wm_manager(C); uiBlock *block; uiBut *but = (uiBut *)arg; wmKeyMap *km; @@ -4107,7 +4103,7 @@ static uiBlock *menu_change_shortcut(bContext *C, ARegion *ar, void *arg) kmi = WM_keymap_item_find_id(km, kmi_id); - RNA_pointer_create(NULL, &RNA_KeyMapItem, kmi, &ptr); + RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr); block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS); uiBlockSetHandleFunc(block, but_shortcut_name_func, but); @@ -4126,6 +4122,7 @@ static uiBlock *menu_change_shortcut(bContext *C, ARegion *ar, void *arg) static uiBlock *menu_add_shortcut(bContext *C, ARegion *ar, void *arg) { + wmWindowManager *wm= CTX_wm_manager(C); uiBlock *block; uiBut *but = (uiBut *)arg; wmKeyMap *km; @@ -4134,19 +4131,25 @@ static uiBlock *menu_add_shortcut(bContext *C, ARegion *ar, void *arg) uiLayout *layout; uiStyle *style= U.uistyles.first; IDProperty *prop= (but->opptr)? but->opptr->data: NULL; + int kmi_id; /* XXX this guess_opname can potentially return a different keymap than being found on adding later... */ km = WM_keymap_guess_opname(C, but->optype->idname); kmi = WM_keymap_add_item(km, but->optype->idname, AKEY, KM_PRESS, 0, 0); + kmi_id = kmi->id; - if (prop) { + /* copy properties, prop can be NULL for reset */ + if(prop) prop= IDP_CopyProperty(prop); - } - - /* prop can be NULL */ WM_keymap_properties_reset(kmi, prop); - RNA_pointer_create(NULL, &RNA_KeyMapItem, kmi, &ptr); + /* update and get pointers again */ + WM_keyconfig_update(wm); + + km = WM_keymap_guess_opname(C, but->optype->idname); + kmi = WM_keymap_item_find_id(km, kmi_id); + + RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr); block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS); uiBlockSetHandleFunc(block, but_shortcut_name_func, but); diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 32e87b3a793..f3db6ad11ae 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1425,7 +1425,7 @@ void init_userdef_do_versions(void) if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 8)) { wmKeyMap *km; - for(km=U.keymaps.first; km; km=km->next) { + for(km=U.user_keymaps.first; km; km=km->next) { if (strcmp(km->idname, "Armature_Sketch")==0) strcpy(km->idname, "Armature Sketch"); else if (strcmp(km->idname, "View3D")==0) diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index aa6da3aaeca..a555a196060 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -341,7 +341,8 @@ typedef struct UserDef { struct ListBase themes; struct ListBase uifonts; struct ListBase uistyles; - struct ListBase keymaps; + struct ListBase keymaps; /* deprecated in favor of user_keymaps */ + struct ListBase user_keymaps; struct ListBase addons; char keyconfigstr[64]; diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h index 31e59f18626..1f0ae28a00d 100644 --- a/source/blender/makesdna/DNA_windowmanager_types.h +++ b/source/blender/makesdna/DNA_windowmanager_types.h @@ -144,7 +144,9 @@ typedef struct wmWindowManager { ListBase drags; /* active dragged items */ ListBase keyconfigs; /* known key configurations */ - struct wmKeyConfig *defaultconf; /* default configuration, not saved */ + struct wmKeyConfig *defaultconf; /* default configuration */ + struct wmKeyConfig *addonconf; /* addon configuration */ + struct wmKeyConfig *userconf; /* user configuration */ ListBase timers; /* active timers */ struct wmTimer *autosavetimer; /* timer for auto save */ @@ -239,15 +241,26 @@ typedef struct wmKeyMapItem { struct PointerRNA *ptr; /* rna pointer to access properties */ } wmKeyMapItem; +/* used instead of wmKeyMapItem for diff keymaps */ +typedef struct wmKeyMapDiffItem { + struct wmKeyMapDiffItem *next, *prev; + + wmKeyMapItem *remove_item; + wmKeyMapItem *add_item; +} wmKeyMapDiffItem; + /* wmKeyMapItem.flag */ -#define KMI_INACTIVE 1 -#define KMI_EXPANDED 2 +#define KMI_INACTIVE 1 +#define KMI_EXPANDED 2 +#define KMI_USER_MODIFIED 4 +#define KMI_UPDATE 8 /* stored in WM, the actively used keymaps */ typedef struct wmKeyMap { struct wmKeyMap *next, *prev; ListBase items; + ListBase diff_items; char idname[64]; /* global editor keymaps, or for more per space/region */ short spaceid; /* same IDs as in DNA_space_types.h */ @@ -263,9 +276,12 @@ typedef struct wmKeyMap { /* wmKeyMap.flag */ #define KEYMAP_MODAL 1 /* modal map, not using operatornames */ -#define KEYMAP_USER 2 /* user created keymap */ +#define KEYMAP_USER 2 /* user keymap */ #define KEYMAP_EXPANDED 4 #define KEYMAP_CHILDREN_EXPANDED 8 +#define KEYMAP_DIFF 16 /* diff keymap for user preferences */ +#define KEYMAP_USER_MODIFIED 32 /* keymap has user modifications */ +#define KEYMAP_UPDATE 64 typedef struct wmKeyConfig { struct wmKeyConfig *next, *prev; diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 9175806e2bb..c0ae7b02b1a 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -238,9 +238,12 @@ void RNA_api_image(struct StructRNA *srna); void RNA_api_operator(struct StructRNA *srna); void RNA_api_macro(struct StructRNA *srna); void RNA_api_keyconfig(struct StructRNA *srna); +void RNA_api_keyconfigs(struct StructRNA *srna); void RNA_api_keyingset(struct StructRNA *srna); void RNA_api_keymap(struct StructRNA *srna); +void RNA_api_keymaps(struct StructRNA *srna); void RNA_api_keymapitem(struct StructRNA *srna); +void RNA_api_keymapitems(struct StructRNA *srna); void RNA_api_area(struct StructRNA *srna); void RNA_api_main(struct StructRNA *srna); void RNA_api_material(StructRNA *srna); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index b3d8bc8ea18..29cfc695911 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1409,7 +1409,7 @@ void rna_def_render_layer_common(StructRNA *srna, int scene) prop= RNA_def_property(srna, "layers_zmask", PROP_BOOLEAN, PROP_LAYER); RNA_def_property_boolean_sdna(prop, NULL, "lay_zmask", 1); RNA_def_property_array(prop, 20); - RNA_def_property_ui_text(prop, "Zmask Layers", "Zmask scene layers"); + RNA_def_property_ui_text(prop, "Zmask Layers", "Zmask scene layers for solid faces"); if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL); else RNA_def_property_clear_flag(prop, PROP_EDITABLE); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index a1a99c34e70..b3dbafeab7d 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2795,12 +2795,6 @@ static void rna_def_userdef_input(BlenderRNA *brna) RNA_def_property_range(prop, 0, 32); RNA_def_property_ui_text(prop, "Wheel Scroll Lines", "The number of lines scrolled at a time with the mouse wheel"); - /* U.keymaps - custom keymaps that have been edited from default configs */ - prop= RNA_def_property(srna, "edited_keymaps", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "keymaps", NULL); - RNA_def_property_struct_type(prop, "KeyMap"); - RNA_def_property_ui_text(prop, "Edited Keymaps", ""); - prop= RNA_def_property(srna, "active_keyconfig", PROP_STRING, PROP_DIRPATH); RNA_def_property_string_sdna(prop, NULL, "keyconfigstr"); RNA_def_property_ui_text(prop, "Key Config", "The name of the active key configuration"); diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index a046be59ab5..307cf0e175a 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -578,22 +578,6 @@ static EnumPropertyItem *rna_KeyMapItem_propvalue_itemf(bContext *C, PointerRNA wmKeyConfig *kc; wmKeyMap *km; - /* check user keymaps */ - for(km=U.keymaps.first; km; km=km->next) { - wmKeyMapItem *kmi; - for (kmi=km->items.first; kmi; kmi=kmi->next) { - if (kmi == ptr->data) { - if (!km->modal_items) { - if (!WM_keymap_user_init(wm, km)) { - return keymap_propvalue_items; /* ERROR */ - } - } - - return km->modal_items; - } - } - } - for(kc=wm->keyconfigs.first; kc; kc=kc->next) { for(km=kc->keymaps.first; km; km=km->next) { /* only check if it's a modal keymap */ @@ -654,12 +638,13 @@ static PointerRNA rna_WindowManager_active_keyconfig_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_KeyConfig, kc); } -static void rna_WindowManager_active_keyconfig_set(PointerRNA *UNUSED(ptr), PointerRNA value) +static void rna_WindowManager_active_keyconfig_set(PointerRNA *ptr, PointerRNA value) { + wmWindowManager *wm= ptr->data; wmKeyConfig *kc= value.data; if(kc) - BLI_strncpy(U.keyconfigstr, kc->idname, sizeof(U.keyconfigstr)); + WM_keyconfig_set_active(wm, kc->idname); } static void rna_wmKeyMapItem_idname_get(PointerRNA *ptr, char *value) @@ -1130,93 +1115,6 @@ static StructRNA* rna_MacroOperator_refine(PointerRNA *opr) return (op->type && op->type->ext.srna)? op->type->ext.srna: &RNA_Macro; } -static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, const char *idname, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier) -{ -// wmWindowManager *wm = CTX_wm_manager(C); - char idname_bl[OP_MAX_TYPENAME]; - int modifier= 0; - - /* only on non-modal maps */ - if (km->flag & KEYMAP_MODAL) { - BKE_report(reports, RPT_ERROR, "Not a non-modal keymap."); - return NULL; - } - - WM_operator_bl_idname(idname_bl, idname); - - if(shift) modifier |= KM_SHIFT; - if(ctrl) modifier |= KM_CTRL; - if(alt) modifier |= KM_ALT; - if(oskey) modifier |= KM_OSKEY; - - if(any) modifier = KM_ANY; - - return WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); -} - -static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km, bContext *C, ReportList *reports, const char *propvalue_str, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier) -{ - wmWindowManager *wm = CTX_wm_manager(C); - int modifier= 0; - int propvalue = 0; - - /* only modal maps */ - if ((km->flag & KEYMAP_MODAL) == 0) { - BKE_report(reports, RPT_ERROR, "Not a modal keymap."); - return NULL; - } - - if (!km->modal_items) { - if(!WM_keymap_user_init(wm, km)) { - BKE_report(reports, RPT_ERROR, "User defined keymap doesn't correspond to a system keymap."); - return NULL; - } - } - - if (!km->modal_items) { - BKE_report(reports, RPT_ERROR, "No property values defined."); - return NULL; - } - - - if(RNA_enum_value_from_id(km->modal_items, propvalue_str, &propvalue)==0) { - BKE_report(reports, RPT_WARNING, "Property value not in enumeration."); - } - - if(shift) modifier |= KM_SHIFT; - if(ctrl) modifier |= KM_CTRL; - if(alt) modifier |= KM_ALT; - if(oskey) modifier |= KM_OSKEY; - - if(any) modifier = KM_ANY; - - return WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue); -} - -static wmKeyMap *rna_keymap_new(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid, int modal) -{ - if (modal == 0) { - return WM_keymap_find(keyconf, idname, spaceid, regionid); - } else { - return WM_modalkeymap_add(keyconf, idname, NULL); /* items will be lazy init */ - } -} - -static wmKeyMap *rna_keymap_find(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid) -{ - return WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid); -} - -static wmKeyMap *rna_keymap_find_modal(wmKeyConfig *UNUSED(keyconf), const char *idname) -{ - wmOperatorType *ot = WM_operatortype_find(idname, 0); - - if (!ot) - return NULL; - else - return ot->modalkeymap; -} - /* just to work around 'const char *' warning and to ensure this is a python op */ static void rna_Operator_bl_idname_set(PointerRNA *ptr, const char *value) { @@ -1242,6 +1140,12 @@ static void rna_Operator_bl_description_set(PointerRNA *ptr, const char *value) else assert(!"setting the bl_description on a non-builtin operator"); } +static void rna_KeyMapItem_update(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + wmKeyMapItem *kmi= ptr->data; + WM_keyconfig_update_tag(NULL, kmi); +} + #else /* RNA_RUNTIME */ static void rna_def_operator(BlenderRNA *brna) @@ -1566,9 +1470,6 @@ static void rna_def_wm_keyconfigs(BlenderRNA *brna, PropertyRNA *cprop) StructRNA *srna; PropertyRNA *prop; - FunctionRNA *func; - PropertyRNA *parm; - RNA_def_property_srna(cprop, "KeyConfigurations"); srna= RNA_def_struct(brna, "KeyConfigurations", NULL); RNA_def_struct_sdna(srna, "wmWindowManager"); @@ -1578,23 +1479,24 @@ static void rna_def_wm_keyconfigs(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_property_struct_type(prop, "KeyConfig"); RNA_def_property_pointer_funcs(prop, "rna_WindowManager_active_keyconfig_get", "rna_WindowManager_active_keyconfig_set", NULL, NULL); RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Active KeyConfig", "Active wm KeyConfig"); + RNA_def_property_ui_text(prop, "Active KeyConfig", "Active key configuration (preset)"); prop= RNA_def_property(srna, "default", PROP_POINTER, PROP_NEVER_NULL); RNA_def_property_pointer_sdna(prop, NULL, "defaultconf"); RNA_def_property_struct_type(prop, "KeyConfig"); - RNA_def_property_ui_text(prop, "Default Key Configuration", ""); + RNA_def_property_ui_text(prop, "Default Key Configuration", "Default builtin key configuration"); + + prop= RNA_def_property(srna, "addon", PROP_POINTER, PROP_NEVER_NULL); + RNA_def_property_pointer_sdna(prop, NULL, "addonconf"); + RNA_def_property_struct_type(prop, "KeyConfig"); + RNA_def_property_ui_text(prop, "Addon Key Configuration", "Key configuration that can be extended by addons, and is added to the active configuration when handling events"); + + prop= RNA_def_property(srna, "user", PROP_POINTER, PROP_NEVER_NULL); + RNA_def_property_pointer_sdna(prop, NULL, "userconf"); + RNA_def_property_struct_type(prop, "KeyConfig"); + RNA_def_property_ui_text(prop, "User Key Configuration", "Final key configuration that combines keymaps from the active and addon configurations, and can be edited by the user"); - /* funcs */ - func= RNA_def_function(srna, "new", "WM_keyconfig_new_user"); // add_keyconfig - parm= RNA_def_string(func, "name", "", 0, "Name", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "keyconfig", "KeyConfig", "Key Configuration", "Added key configuration."); - RNA_def_function_return(func, parm); - - func= RNA_def_function(srna, "remove", "WM_keyconfig_remove"); // remove_keyconfig - parm= RNA_def_pointer(func, "keyconfig", "KeyConfig", "Key Configuration", "Removed key configuration."); - RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_api_keyconfigs(srna); } static void rna_def_windowmanager(BlenderRNA *brna) @@ -1631,107 +1533,30 @@ static void rna_def_windowmanager(BlenderRNA *brna) static void rna_def_keymap_items(BlenderRNA *brna, PropertyRNA *cprop) { StructRNA *srna; -// PropertyRNA *prop; - - FunctionRNA *func; - PropertyRNA *parm; RNA_def_property_srna(cprop, "KeyMapItems"); srna= RNA_def_struct(brna, "KeyMapItems", NULL); RNA_def_struct_sdna(srna, "wmKeyMap"); RNA_def_struct_ui_text(srna, "KeyMap Items", "Collection of keymap items"); - func= RNA_def_function(srna, "new", "rna_KeyMap_item_new"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); - parm= RNA_def_string(func, "idname", "", 0, "Operator Identifier", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_boolean(func, "any", 0, "Any", ""); - RNA_def_boolean(func, "shift", 0, "Shift", ""); - RNA_def_boolean(func, "ctrl", 0, "Ctrl", ""); - RNA_def_boolean(func, "alt", 0, "Alt", ""); - RNA_def_boolean(func, "oskey", 0, "OS Key", ""); - RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", ""); - parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item."); - RNA_def_function_return(func, parm); - - func= RNA_def_function(srna, "new_modal", "rna_KeyMap_item_new_modal"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS); - parm= RNA_def_string(func, "propvalue", "", 0, "Property Value", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_boolean(func, "any", 0, "Any", ""); - RNA_def_boolean(func, "shift", 0, "Shift", ""); - RNA_def_boolean(func, "ctrl", 0, "Ctrl", ""); - RNA_def_boolean(func, "alt", 0, "Alt", ""); - RNA_def_boolean(func, "oskey", 0, "OS Key", ""); - RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", ""); - parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item."); - RNA_def_function_return(func, parm); - - func= RNA_def_function(srna, "remove", "WM_keymap_remove_item"); - parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - - func= RNA_def_function(srna, "from_id", "WM_keymap_item_find_id"); - parm= RNA_def_property(func, "id", PROP_INT, PROP_NONE); - RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_property_ui_text(parm, "id", "ID of the item"); - parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", ""); - RNA_def_function_return(func, parm); - + RNA_api_keymapitems(srna); } static void rna_def_wm_keymaps(BlenderRNA *brna, PropertyRNA *cprop) { StructRNA *srna; - //PropertyRNA *prop; - - FunctionRNA *func; - PropertyRNA *parm; - RNA_def_property_srna(cprop, "KeyMaps"); srna= RNA_def_struct(brna, "KeyMaps", NULL); RNA_def_struct_sdna(srna, "wmKeyConfig"); RNA_def_struct_ui_text(srna, "Key Maps", "Collection of keymaps"); - func= RNA_def_function(srna, "new", "rna_keymap_new"); // add_keymap - parm= RNA_def_string(func, "name", "", 0, "Name", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_enum(func, "space_type", space_type_items, SPACE_EMPTY, "Space Type", ""); - RNA_def_enum(func, "region_type", region_type_items, RGN_TYPE_WINDOW, "Region Type", ""); - RNA_def_boolean(func, "modal", 0, "Modal", ""); - parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Added key map."); - RNA_def_function_return(func, parm); - - func= RNA_def_function(srna, "find", "rna_keymap_find"); // find_keymap - parm= RNA_def_string(func, "name", "", 0, "Name", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_enum(func, "space_type", space_type_items, SPACE_EMPTY, "Space Type", ""); - RNA_def_enum(func, "region_type", region_type_items, RGN_TYPE_WINDOW, "Region Type", ""); - parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map."); - RNA_def_function_return(func, parm); - - func= RNA_def_function(srna, "find_modal", "rna_keymap_find_modal"); // find_keymap_modal - parm= RNA_def_string(func, "name", "", 0, "Operator Name", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map."); - RNA_def_function_return(func, parm); - + RNA_api_keymaps(srna); } static void rna_def_keyconfig(BlenderRNA *brna) { StructRNA *srna; - // FunctionRNA *func; - // PropertyRNA *parm; PropertyRNA *prop; static EnumPropertyItem map_type_items[] = { @@ -1794,8 +1619,8 @@ static void rna_def_keyconfig(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Items", "Items in the keymap, linking an operator to an input event"); rna_def_keymap_items(brna, prop); - prop= RNA_def_property(srna, "is_user_defined", PROP_BOOLEAN, PROP_NEVER_NULL); - RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_USER); + prop= RNA_def_property(srna, "is_user_modified", PROP_BOOLEAN, PROP_NEVER_NULL); + RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_USER_MODIFIED); RNA_def_property_ui_text(prop, "User Defined", "Keymap is defined by the user"); prop= RNA_def_property(srna, "is_modal", PROP_BOOLEAN, PROP_NONE); @@ -1826,6 +1651,7 @@ static void rna_def_keyconfig(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Identifier", "Identifier of operator to call on input event"); RNA_def_property_string_funcs(prop, "rna_wmKeyMapItem_idname_get", "rna_wmKeyMapItem_idname_length", "rna_wmKeyMapItem_idname_set"); RNA_def_struct_name_property(srna, prop); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); @@ -1836,62 +1662,73 @@ static void rna_def_keyconfig(BlenderRNA *brna) RNA_def_property_struct_type(prop, "OperatorProperties"); RNA_def_property_pointer_funcs(prop, "rna_KeyMapItem_properties_get", NULL, NULL, NULL); RNA_def_property_ui_text(prop, "Properties", "Properties to set when the operator is called"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "map_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "maptype"); RNA_def_property_enum_items(prop, map_type_items); RNA_def_property_enum_funcs(prop, "rna_wmKeyMapItem_map_type_get", "rna_wmKeyMapItem_map_type_set", NULL); RNA_def_property_ui_text(prop, "Map Type", "Type of event mapping"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type"); RNA_def_property_enum_items(prop, event_type_items); RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_type_itemf"); RNA_def_property_ui_text(prop, "Type", "Type of event"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "val"); RNA_def_property_enum_items(prop, event_value_items); RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_value_itemf"); RNA_def_property_ui_text(prop, "Value", ""); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "id", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "id"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "id", "ID of the item"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "any", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_any_getf", "rna_KeyMapItem_any_setf"); RNA_def_property_ui_text(prop, "Any", "Any modifier keys pressed"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "shift", 0); // RNA_def_property_enum_sdna(prop, NULL, "shift"); // RNA_def_property_enum_items(prop, keymap_modifiers_items); RNA_def_property_ui_text(prop, "Shift", "Shift key pressed"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 0); // RNA_def_property_enum_sdna(prop, NULL, "ctrl"); // RNA_def_property_enum_items(prop, keymap_modifiers_items); RNA_def_property_ui_text(prop, "Ctrl", "Control key pressed"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "alt", 0); // RNA_def_property_enum_sdna(prop, NULL, "alt"); // RNA_def_property_enum_items(prop, keymap_modifiers_items); RNA_def_property_ui_text(prop, "Alt", "Alt key pressed"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "oskey", 0); // RNA_def_property_enum_sdna(prop, NULL, "oskey"); // RNA_def_property_enum_items(prop, keymap_modifiers_items); RNA_def_property_ui_text(prop, "OS Key", "Operating system key pressed"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "key_modifier", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "keymodifier"); RNA_def_property_enum_items(prop, event_type_items); RNA_def_property_ui_text(prop, "Key Modifier", "Regular key pressed as a modifier"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", KMI_EXPANDED); @@ -1903,15 +1740,21 @@ static void rna_def_keyconfig(BlenderRNA *brna) RNA_def_property_enum_items(prop, keymap_propvalue_items); RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_propvalue_itemf"); RNA_def_property_ui_text(prop, "Property Value", "The value this event translates to in a modal keymap"); + RNA_def_property_update(prop, 0, "rna_KeyMapItem_update"); prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", KMI_INACTIVE); RNA_def_property_ui_text(prop, "Active", "Activate or deactivate item"); RNA_def_property_ui_icon(prop, ICON_CHECKBOX_DEHLT, 1); + prop= RNA_def_property(srna, "is_user_modified", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", KMI_USER_MODIFIED); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "User Modified", "Is this keymap item modified by the user"); + prop= RNA_def_property(srna, "is_user_defined", PROP_BOOLEAN, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "User Defined", "Is this keymap item user defined (doesn't just override a builtin item)"); + RNA_def_property_ui_text(prop, "User Defined", "Is this keymap item user defined (doesn't just replace a builtin item)"); RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_userdefined_get", NULL); RNA_api_keymapitem(srna); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index d44b68950f7..89e946f498a 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -84,6 +84,85 @@ void rna_event_timer_remove(struct wmWindowManager *wm, wmTimer *timer) WM_event_remove_timer(wm, timer->win, timer); } +static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km, ReportList *reports, const char *idname, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier) +{ +// wmWindowManager *wm = CTX_wm_manager(C); + char idname_bl[OP_MAX_TYPENAME]; + int modifier= 0; + + /* only on non-modal maps */ + if (km->flag & KEYMAP_MODAL) { + BKE_report(reports, RPT_ERROR, "Not a non-modal keymap."); + return NULL; + } + + WM_operator_bl_idname(idname_bl, idname); + + if(shift) modifier |= KM_SHIFT; + if(ctrl) modifier |= KM_CTRL; + if(alt) modifier |= KM_ALT; + if(oskey) modifier |= KM_OSKEY; + + if(any) modifier = KM_ANY; + + return WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier); +} + +static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km, ReportList *reports, const char *propvalue_str, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier) +{ + int modifier= 0; + int propvalue = 0; + + /* only modal maps */ + if ((km->flag & KEYMAP_MODAL) == 0) { + BKE_report(reports, RPT_ERROR, "Not a modal keymap."); + return NULL; + } + + if (!km->modal_items) { + BKE_report(reports, RPT_ERROR, "No property values defined."); + return NULL; + } + + + if(RNA_enum_value_from_id(km->modal_items, propvalue_str, &propvalue)==0) { + BKE_report(reports, RPT_WARNING, "Property value not in enumeration."); + } + + if(shift) modifier |= KM_SHIFT; + if(ctrl) modifier |= KM_CTRL; + if(alt) modifier |= KM_ALT; + if(oskey) modifier |= KM_OSKEY; + + if(any) modifier = KM_ANY; + + return WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue); +} + +static wmKeyMap *rna_keymap_new(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid, int modal) +{ + if (modal == 0) { + return WM_keymap_find(keyconf, idname, spaceid, regionid); + } else { + return WM_modalkeymap_add(keyconf, idname, NULL); /* items will be lazy init */ + } +} + +static wmKeyMap *rna_keymap_find(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid) +{ + return WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid); +} + +static wmKeyMap *rna_keymap_find_modal(wmKeyConfig *UNUSED(keyconf), const char *idname) +{ + wmOperatorType *ot = WM_operatortype_find(idname, 0); + + if (!ot) + return NULL; + else + return ot->modalkeymap; +} + #else #define WM_GEN_INVOKE_EVENT (1<<0) @@ -301,11 +380,8 @@ void RNA_api_keymap(StructRNA *srna) parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Active key map."); RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "copy_to_user", "WM_keymap_copy_to_user"); - parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "User editable key map."); - RNA_def_function_return(func, parm); - - RNA_def_function(srna, "restore_to_default", "WM_keymap_restore_to_default"); + func= RNA_def_function(srna, "restore_to_default", "WM_keymap_restore_to_default"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); func= RNA_def_function(srna, "restore_item_to_default", "rna_keymap_restore_item_to_default"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); @@ -324,5 +400,102 @@ void RNA_api_keymapitem(StructRNA *srna) parm= RNA_def_boolean(func, "result", 0, "Comparison result", ""); RNA_def_function_return(func, parm); } + +void RNA_api_keymapitems(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + func= RNA_def_function(srna, "new", "rna_KeyMap_item_new"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm= RNA_def_string(func, "idname", "", 0, "Operator Identifier", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_boolean(func, "any", 0, "Any", ""); + RNA_def_boolean(func, "shift", 0, "Shift", ""); + RNA_def_boolean(func, "ctrl", 0, "Ctrl", ""); + RNA_def_boolean(func, "alt", 0, "Alt", ""); + RNA_def_boolean(func, "oskey", 0, "OS Key", ""); + RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", ""); + parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "new_modal", "rna_KeyMap_item_new_modal"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm= RNA_def_string(func, "propvalue", "", 0, "Property Value", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_boolean(func, "any", 0, "Any", ""); + RNA_def_boolean(func, "shift", 0, "Shift", ""); + RNA_def_boolean(func, "ctrl", 0, "Ctrl", ""); + RNA_def_boolean(func, "alt", 0, "Alt", ""); + RNA_def_boolean(func, "oskey", 0, "OS Key", ""); + RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", ""); + parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "remove", "WM_keymap_remove_item"); + parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "from_id", "WM_keymap_item_find_id"); + parm= RNA_def_property(func, "id", PROP_INT, PROP_NONE); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_property_ui_text(parm, "id", "ID of the item"); + parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", ""); + RNA_def_function_return(func, parm); +} + +void RNA_api_keymaps(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + func= RNA_def_function(srna, "new", "rna_keymap_new"); // add_keymap + parm= RNA_def_string(func, "name", "", 0, "Name", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_enum(func, "space_type", space_type_items, SPACE_EMPTY, "Space Type", ""); + RNA_def_enum(func, "region_type", region_type_items, RGN_TYPE_WINDOW, "Region Type", ""); + RNA_def_boolean(func, "modal", 0, "Modal", ""); + parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Added key map."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "find", "rna_keymap_find"); // find_keymap + parm= RNA_def_string(func, "name", "", 0, "Name", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_enum(func, "space_type", space_type_items, SPACE_EMPTY, "Space Type", ""); + RNA_def_enum(func, "region_type", region_type_items, RGN_TYPE_WINDOW, "Region Type", ""); + parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "find_modal", "rna_keymap_find_modal"); // find_keymap_modal + parm= RNA_def_string(func, "name", "", 0, "Operator Name", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map."); + RNA_def_function_return(func, parm); +} + +void RNA_api_keyconfigs(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + func= RNA_def_function(srna, "new", "WM_keyconfig_new_user"); // add_keyconfig + parm= RNA_def_string(func, "name", "", 0, "Name", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_pointer(func, "keyconfig", "KeyConfig", "Key Configuration", "Added key configuration."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "remove", "WM_keyconfig_remove"); // remove_keyconfig + parm= RNA_def_pointer(func, "keyconfig", "KeyConfig", "Key Configuration", "Removed key configuration."); + RNA_def_property_flag(parm, PROP_REQUIRED); +} + #endif diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index e6325e2101a..42c3096dfc9 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -41,6 +41,7 @@ /* dna-savable wmStructs here */ #include "DNA_windowmanager_types.h" +#include "WM_keymap.h" #ifdef __cplusplus extern "C" { @@ -114,50 +115,9 @@ void WM_paint_cursor_end(struct wmWindowManager *wm, void *handle); void WM_cursor_warp (struct wmWindow *win, int x, int y); - /* keyconfig and keymap */ -wmKeyConfig *WM_keyconfig_new (struct wmWindowManager *wm, const char *idname); -wmKeyConfig *WM_keyconfig_new_user(struct wmWindowManager *wm, const char *idname); -void WM_keyconfig_remove (struct wmWindowManager *wm, struct wmKeyConfig *keyconf); -void WM_keyconfig_free (struct wmKeyConfig *keyconf); -void WM_keyconfig_userdef(void); - -void WM_keymap_init (struct bContext *C); -void WM_keymap_free (struct wmKeyMap *keymap); - -wmKeyMapItem *WM_keymap_verify_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); -wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); -wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, const char *idname, int type, - int val, int modifier, int keymodifier); - -void WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); -char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len); - -wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid); -wmKeyMap *WM_keymap_find(struct wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid); -wmKeyMap *WM_keymap_find_all(const struct bContext *C, const char *idname, int spaceid, int regionid); -wmKeyMap *WM_keymap_active(struct wmWindowManager *wm, struct wmKeyMap *keymap); -wmKeyMap *WM_keymap_guess_opname(const struct bContext *C, const char *opname); -int WM_keymap_user_init(struct wmWindowManager *wm, struct wmKeyMap *keymap); -wmKeyMap *WM_keymap_copy_to_user(struct wmKeyMap *keymap); -void WM_keymap_restore_to_default(struct wmKeyMap *keymap); -void WM_keymap_properties_reset(struct wmKeyMapItem *kmi, struct IDProperty *properties); -void WM_keymap_restore_item_to_default(struct bContext *C, struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); - -wmKeyMapItem *WM_keymap_item_find_id(struct wmKeyMap *keymap, int id); -int WM_keymap_item_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2); + /* event map */ int WM_userdef_event_map(int kmitype); -wmKeyMap *WM_modalkeymap_add(struct wmKeyConfig *keyconf, const char *idname, struct EnumPropertyItem *items); -wmKeyMap *WM_modalkeymap_get(struct wmKeyConfig *keyconf, const char *idname); -wmKeyMapItem *WM_modalkeymap_add_item(struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value); -void WM_modalkeymap_assign(struct wmKeyMap *km, const char *opname); - -const char *WM_key_event_string(short type); -int WM_key_event_operator_id(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, int hotkey, struct wmKeyMap **keymap_r); -char *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, char *str, int len); - /* handlers */ struct wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap); diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h new file mode 100644 index 00000000000..e00cd288c9a --- /dev/null +++ b/source/blender/windowmanager/WM_keymap.h @@ -0,0 +1,104 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2007 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef WM_KEYMAP_H +#define WM_KEYMAP_H + +/** \file WM_keymap.h + * \ingroup wm + */ + +/* dna-savable wmStructs here */ +#include "DNA_windowmanager_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct EnumPropertyItem; + +/* Key Configuration */ + +wmKeyConfig *WM_keyconfig_new (struct wmWindowManager *wm, const char *idname); +wmKeyConfig *WM_keyconfig_new_user(struct wmWindowManager *wm, const char *idname); +void WM_keyconfig_remove (struct wmWindowManager *wm, struct wmKeyConfig *keyconf); +void WM_keyconfig_free (struct wmKeyConfig *keyconf); + +void WM_keyconfig_set_active(struct wmWindowManager *wm, const char *idname); + +void WM_keyconfig_update(struct wmWindowManager *wm); +void WM_keyconfig_update_tag(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); + +/* Keymap */ + +void WM_keymap_init (struct bContext *C); +void WM_keymap_free (struct wmKeyMap *keymap); + +wmKeyMapItem *WM_keymap_verify_item(struct wmKeyMap *keymap, const char *idname, int type, + int val, int modifier, int keymodifier); +wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, const char *idname, int type, + int val, int modifier, int keymodifier); +wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, const char *idname, int type, + int val, int modifier, int keymodifier); + +void WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); +char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len); + +wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid); +wmKeyMap *WM_keymap_find(struct wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid); +wmKeyMap *WM_keymap_find_all(const struct bContext *C, const char *idname, int spaceid, int regionid); +wmKeyMap *WM_keymap_active(struct wmWindowManager *wm, struct wmKeyMap *keymap); +wmKeyMap *WM_keymap_guess_opname(const struct bContext *C, const char *opname); + +wmKeyMapItem *WM_keymap_item_find_id(struct wmKeyMap *keymap, int id); +int WM_keymap_item_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2); + +/* Modal Keymap */ + +wmKeyMap *WM_modalkeymap_add(struct wmKeyConfig *keyconf, const char *idname, struct EnumPropertyItem *items); +wmKeyMap *WM_modalkeymap_get(struct wmKeyConfig *keyconf, const char *idname); +wmKeyMapItem *WM_modalkeymap_add_item(struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value); +void WM_modalkeymap_assign(struct wmKeyMap *km, const char *opname); + +/* Keymap Editor */ + +void WM_keymap_restore_to_default(struct wmKeyMap *keymap, struct bContext *C); +void WM_keymap_properties_reset(struct wmKeyMapItem *kmi, struct IDProperty *properties); +void WM_keymap_restore_item_to_default(struct bContext *C, struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); + +/* Key Event */ + +const char *WM_key_event_string(short type); +int WM_key_event_operator_id(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, int hotkey, struct wmKeyMap **keymap_r); +char *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, char *str, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* WM_KEYMAP_H */ + diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index a535c0bc1f8..1d5cf1cdc53 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -210,12 +210,18 @@ void WM_keymap_init(bContext *C) if(!wm->defaultconf) wm->defaultconf= WM_keyconfig_new(wm, "Blender"); + if(!wm->addonconf) + wm->addonconf= WM_keyconfig_new(wm, "Blender Addon"); + if(!wm->userconf) + wm->userconf= WM_keyconfig_new(wm, "Blender User"); - if(wm && CTX_py_init_get(C) && (wm->initialized & WM_INIT_KEYMAP) == 0) { + if(CTX_py_init_get(C) && (wm->initialized & WM_INIT_KEYMAP) == 0) { /* create default key config */ wm_window_keymap(wm->defaultconf); ED_spacetypes_keymap(wm->defaultconf); - WM_keyconfig_userdef(); + + WM_keyconfig_update_tag(NULL, NULL); + WM_keyconfig_update(wm); wm->initialized |= WM_INIT_KEYMAP; } diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 2f0c1a72be9..0dac0bd7401 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1735,6 +1735,9 @@ void wm_event_do_handlers(bContext *C) wmWindowManager *wm= CTX_wm_manager(C); wmWindow *win; + /* update key configuration before handling events */ + WM_keyconfig_update(wm); + for(win= wm->windows.first; win; win= win->next) { wmEvent *event; @@ -1938,6 +1941,9 @@ void wm_event_do_handlers(bContext *C) CTX_wm_window_set(C, NULL); } + + /* update key configuration after handling events */ + WM_keyconfig_update(wm); } /* ********** filesector handling ************ */ diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 27fc0caeccc..20f9d2237c2 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -224,6 +224,14 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist) oldwm= oldwmlist->first; wm= G.main->wm.first; + /* move addon key configuration to new wm, to preserve their keymaps */ + if(oldwm->addonconf) { + wm->addonconf= oldwm->addonconf; + BLI_remlink(&oldwm->keyconfigs, oldwm->addonconf); + oldwm->addonconf= NULL; + BLI_addtail(&wm->keyconfigs, wm->addonconf); + } + /* ensure making new keymaps and set space types */ wm->initialized= 0; wm->winactive= NULL; @@ -794,11 +802,14 @@ int WM_write_homefile(bContext *C, wmOperator *op) wmWindow *win= CTX_wm_window(C); char filepath[FILE_MAXDIR+FILE_MAXFILE]; int fileflags; - + /* check current window and close it if temp */ if(win->screen->temp) wm_window_close(C, wm, win); + /* update keymaps in user preferences */ + WM_keyconfig_update(wm); + BLI_make_file_string("/", filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE); printf("trying to save homefile at %s ", filepath); diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 1720c738dd7..bf48f0e21e4 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -61,14 +61,67 @@ #include "wm_event_system.h" #include "wm_event_types.h" -/* ********************* key config ***********************/ +/******************************* Keymap Item ********************************** + * Item in a keymap, that maps from an event to an operator or modal map item */ -static void keymap_properties_set(wmKeyMapItem *kmi) +static wmKeyMapItem *wm_keymap_item_copy(wmKeyMapItem *kmi) +{ + wmKeyMapItem *kmin = MEM_dupallocN(kmi); + + kmin->prev= kmin->next= NULL; + kmin->flag &= ~KMI_UPDATE; + + if(kmin->properties) { + kmin->ptr= MEM_callocN(sizeof(PointerRNA), "UserKeyMapItemPtr"); + WM_operator_properties_create(kmin->ptr, kmin->idname); + + kmin->properties= IDP_CopyProperty(kmin->properties); + kmin->ptr->data= kmin->properties; + } + + return kmin; +} + +static void wm_keymap_item_free(wmKeyMapItem *kmi) +{ + /* not kmi itself */ + if(kmi->ptr) { + WM_operator_properties_free(kmi->ptr); + MEM_freeN(kmi->ptr); + } +} + +static void wm_keymap_item_properties_set(wmKeyMapItem *kmi) { WM_operator_properties_alloc(&(kmi->ptr), &(kmi->properties), kmi->idname); WM_operator_properties_sanitize(kmi->ptr, 1); } +static int wm_keymap_item_equals_result(wmKeyMapItem *a, wmKeyMapItem *b) +{ + if(strcmp(a->idname, b->idname) != 0) + return 0; + + if(!((a->ptr==NULL && b->ptr==NULL) || + (a->ptr && b->ptr && IDP_EqualsProperties(a->ptr->data, b->ptr->data)))) + return 0; + + return (a->propvalue == b->propvalue); +} + +static int wm_keymap_item_equals(wmKeyMapItem *a, wmKeyMapItem *b) +{ + return (wm_keymap_item_equals_result(a, b) && + a->type == b->type && + a->val == b->val && + a->shift == b->shift && + a->ctrl == b->ctrl && + a->alt == b->alt && + a->oskey == b->oskey && + a->keymodifier == b->keymodifier && + a->maptype == b->maptype); +} + /* properties can be NULL, otherwise the arg passed is used and ownership is given to the kmi */ void WM_keymap_properties_reset(wmKeyMapItem *kmi, struct IDProperty *properties) { @@ -78,9 +131,41 @@ void WM_keymap_properties_reset(wmKeyMapItem *kmi, struct IDProperty *properties kmi->ptr = NULL; kmi->properties = properties; - keymap_properties_set(kmi); + wm_keymap_item_properties_set(kmi); +} + +/**************************** Keymap Diff Item ********************************* + * Item in a diff keymap, used for saving diff of keymaps in user preferences */ + +static wmKeyMapDiffItem *wm_keymap_diff_item_copy(wmKeyMapDiffItem *kmdi) +{ + wmKeyMapDiffItem *kmdin = MEM_dupallocN(kmdi); + + kmdin->next = kmdin->prev = NULL; + if(kmdi->add_item) + kmdin->add_item = wm_keymap_item_copy(kmdi->add_item); + if(kmdi->remove_item) + kmdin->remove_item = wm_keymap_item_copy(kmdi->remove_item); + + return kmdin; +} + +static void wm_keymap_diff_item_free(wmKeyMapDiffItem *kmdi) +{ + if(kmdi->remove_item) { + wm_keymap_item_free(kmdi->remove_item); + MEM_freeN(kmdi->remove_item); + } + if(kmdi->add_item) { + wm_keymap_item_free(kmdi->add_item); + MEM_freeN(kmdi->add_item); + } } +/***************************** Key Configuration ****************************** + * List of keymaps for all editors, modes, ... . There is a builtin default key + * configuration, a user key configuration, and other preset configurations. */ + wmKeyConfig *WM_keyconfig_new(wmWindowManager *wm, const char *idname) { wmKeyConfig *keyconf; @@ -106,6 +191,7 @@ void WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf) if (keyconf) { if (strncmp(U.keyconfigstr, keyconf->idname, sizeof(U.keyconfigstr)) == 0) { BLI_strncpy(U.keyconfigstr, wm->defaultconf->idname, sizeof(U.keyconfigstr)); + WM_keyconfig_update_tag(NULL, NULL); } BLI_remlink(&wm->keyconfigs, keyconf); @@ -125,21 +211,6 @@ void WM_keyconfig_free(wmKeyConfig *keyconf) MEM_freeN(keyconf); } -void WM_keyconfig_userdef(void) -{ - wmKeyMap *km; - wmKeyMapItem *kmi; - - for(km=U.keymaps.first; km; km=km->next) { - /* modal keymaps don't have operator properties */ - if ((km->flag & KEYMAP_MODAL) == 0) { - for(kmi=km->items.first; kmi; kmi=kmi->next) { - keymap_properties_set(kmi); - } - } - } -} - static wmKeyConfig *wm_keyconfig_list_find(ListBase *lb, char *idname) { wmKeyConfig *kc; @@ -151,23 +222,84 @@ static wmKeyConfig *wm_keyconfig_list_find(ListBase *lb, char *idname) return NULL; } -/* ************************ free ************************* */ +wmKeyConfig *WM_keyconfig_active(wmWindowManager *wm) +{ + wmKeyConfig *keyconf; -void WM_keymap_free(wmKeyMap *keymap) + /* first try from preset */ + keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr); + if(keyconf) + return keyconf; + + /* otherwise use default */ + return wm->defaultconf; +} + +void WM_keyconfig_set_active(wmWindowManager *wm, const char *idname) { - wmKeyMapItem *kmi; + /* setting a different key configuration as active: we ensure all is + updated properly before and after making the change */ + + WM_keyconfig_update(wm); + + BLI_strncpy(U.keyconfigstr, idname, sizeof(U.keyconfigstr)); + + WM_keyconfig_update_tag(NULL, NULL); + WM_keyconfig_update(wm); +} + +/********************************** Keymap ************************************* + * List of keymap items for one editor, mode, modal operator, ... */ + +static wmKeyMap *wm_keymap_new(const char *idname, int spaceid, int regionid) +{ + wmKeyMap *km= MEM_callocN(sizeof(struct wmKeyMap), "keymap list"); + + BLI_strncpy(km->idname, idname, KMAP_MAX_NAME); + km->spaceid= spaceid; + km->regionid= regionid; + + return km; +} + +static wmKeyMap *wm_keymap_copy(wmKeyMap *keymap) +{ + wmKeyMap *keymapn = MEM_dupallocN(keymap); + wmKeyMapItem *kmi, *kmin; + wmKeyMapDiffItem *kmdi, *kmdin; + + keymapn->modal_items= keymap->modal_items; + keymapn->poll= keymap->poll; + keymapn->items.first= keymapn->items.last= NULL; + keymapn->flag &= ~(KEYMAP_UPDATE|KEYMAP_EXPANDED); + + for(kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) { + kmdin= wm_keymap_diff_item_copy(kmdi); + BLI_addtail(&keymapn->items, kmdin); + } for(kmi=keymap->items.first; kmi; kmi=kmi->next) { - if(kmi->ptr) { - WM_operator_properties_free(kmi->ptr); - MEM_freeN(kmi->ptr); - } + kmin= wm_keymap_item_copy(kmi); + BLI_addtail(&keymapn->items, kmin); } - BLI_freelistN(&keymap->items); + return keymapn; } -/* ***************** generic call, exported **************** */ +void WM_keymap_free(wmKeyMap *keymap) +{ + wmKeyMapItem *kmi; + wmKeyMapDiffItem *kmdi; + + for(kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) + wm_keymap_diff_item_free(kmdi); + + for(kmi=keymap->items.first; kmi; kmi=kmi->next) + wm_keymap_item_free(kmi); + + BLI_freelistN(&keymap->diff_items); + BLI_freelistN(&keymap->items); +} static void keymap_event_set(wmKeyMapItem *kmi, short type, short val, int modifier, short keymodifier) { @@ -229,7 +361,7 @@ wmKeyMapItem *WM_keymap_verify_item(wmKeyMap *keymap, const char *idname, int ty keymap_item_set_id(keymap, kmi); keymap_event_set(kmi, type, val, modifier, keymodifier); - keymap_properties_set(kmi); + wm_keymap_item_properties_set(kmi); } return kmi; } @@ -243,10 +375,12 @@ wmKeyMapItem *WM_keymap_add_item(wmKeyMap *keymap, const char *idname, int type, BLI_strncpy(kmi->idname, idname, OP_MAX_TYPENAME); keymap_event_set(kmi, type, val, modifier, keymodifier); - keymap_properties_set(kmi); + wm_keymap_item_properties_set(kmi); keymap_item_set_id(keymap, kmi); + WM_keyconfig_update_tag(keymap, kmi); + return kmi; } @@ -266,6 +400,232 @@ void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi) MEM_freeN(kmi->ptr); } BLI_freelinkN(&keymap->items, kmi); + + WM_keyconfig_update_tag(keymap, kmi); + } +} + +/************************** Keymap Diff and Patch **************************** + * Rather than saving the entire keymap for user preferences, we only save a + * diff so that changes in the defaults get synced. This system is not perfect + * but works better than overriding the keymap entirely when only few items + * are changed. */ + +static void wm_keymap_addon_add(wmKeyMap *keymap, wmKeyMap *addonmap) +{ + wmKeyMapItem *kmi, *kmin; + + for(kmi=addonmap->items.first; kmi; kmi=kmi->next) { + kmin = wm_keymap_item_copy(kmi); + keymap_item_set_id(keymap, kmin); + BLI_addhead(&keymap->items, kmin); + } +} + +static wmKeyMapItem *wm_keymap_find_item_equals(wmKeyMap *km, wmKeyMapItem *needle) +{ + wmKeyMapItem *kmi; + + for(kmi=km->items.first; kmi; kmi=kmi->next) + if(wm_keymap_item_equals(kmi, needle)) + return kmi; + + return NULL; +} + +static wmKeyMapItem *wm_keymap_find_item_equals_result(wmKeyMap *km, wmKeyMapItem *needle) +{ + wmKeyMapItem *kmi; + + for(kmi=km->items.first; kmi; kmi=kmi->next) + if(wm_keymap_item_equals_result(kmi, needle)) + return kmi; + + return NULL; +} + +static void wm_keymap_diff(wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km, wmKeyMap *orig_km, wmKeyMap *addon_km) +{ + wmKeyMapItem *kmi, *to_kmi, *orig_kmi; + wmKeyMapDiffItem *kmdi; + + for(kmi=from_km->items.first; kmi; kmi=kmi->next) { + to_kmi = WM_keymap_item_find_id(to_km, kmi->id); + + if(!to_kmi) { + /* remove item */ + kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); + kmdi->remove_item = wm_keymap_item_copy(kmi); + BLI_addtail(&diff_km->diff_items, kmdi); + } + else if(to_kmi && !wm_keymap_item_equals(kmi, to_kmi)) { + /* replace item */ + kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); + kmdi->remove_item = wm_keymap_item_copy(kmi); + kmdi->add_item = wm_keymap_item_copy(to_kmi); + BLI_addtail(&diff_km->diff_items, kmdi); + } + + /* sync expanded flag back to original so we don't loose it on repatch */ + if(to_kmi) { + orig_kmi = WM_keymap_item_find_id(orig_km, kmi->id); + + if(!orig_kmi) + orig_kmi = wm_keymap_find_item_equals(addon_km, kmi); + + if(orig_kmi) { + orig_kmi->flag &= ~KMI_EXPANDED; + orig_kmi->flag |= (to_kmi->flag & KMI_EXPANDED); + } + } + } + + for(kmi=to_km->items.first; kmi; kmi=kmi->next) { + if(kmi->id < 0) { + /* add item */ + kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); + kmdi->add_item = wm_keymap_item_copy(kmi); + BLI_addtail(&diff_km->diff_items, kmdi); + } + } +} + +static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km) +{ + wmKeyMapDiffItem *kmdi; + wmKeyMapItem *kmi_remove, *kmi_add; + + for(kmdi=diff_km->diff_items.first; kmdi; kmdi=kmdi->next) { + /* find item to remove */ + kmi_remove = NULL; + if(kmdi->remove_item) { + kmi_remove = wm_keymap_find_item_equals(km, kmdi->remove_item); + if(!kmi_remove) + kmi_remove = wm_keymap_find_item_equals_result(km, kmdi->remove_item); + } + + /* add item */ + if(kmdi->add_item) { + /* only if nothing to remove or item to remove found */ + if(!kmdi->remove_item || kmi_remove) { + kmi_add = wm_keymap_item_copy(kmdi->add_item); + kmi_add->flag |= KMI_USER_MODIFIED; + + if(kmi_remove) { + kmi_add->flag &= ~KMI_EXPANDED; + kmi_add->flag |= (kmi_remove->flag & KMI_EXPANDED); + kmi_add->id = kmi_remove->id; + BLI_insertlinkbefore(&km->items, kmi_remove, kmi_add); + } + else { + keymap_item_set_id(km, kmi_add); + BLI_addtail(&km->items, kmi_add); + } + } + } + + /* remove item */ + if(kmi_remove) { + wm_keymap_item_free(kmi_remove); + BLI_freelinkN(&km->items, kmi_remove); + } + } +} + +static void wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap) +{ + wmKeyMap *km; + int expanded = 0; + + /* remove previous keymap in list, we will replace it */ + km = WM_keymap_list_find(lb, defaultmap->idname, defaultmap->spaceid, defaultmap->regionid); + if(km) { + expanded = (km->flag & (KEYMAP_EXPANDED|KEYMAP_CHILDREN_EXPANDED)); + WM_keymap_free(km); + BLI_freelinkN(lb, km); + } + + /* copy new keymap from an existing one */ + if(usermap && !(usermap->flag & KEYMAP_DIFF)) { + /* for compatibiltiy with old user preferences with non-diff + keymaps we override the original entirely */ + wmKeyMapItem *kmi, *orig_kmi; + + km = wm_keymap_copy(usermap); + km->modal_items = defaultmap->modal_items; + km->poll = defaultmap->poll; + + /* try to find corresponding id's for items */ + for(kmi=km->items.first; kmi; kmi=kmi->next) { + orig_kmi = wm_keymap_find_item_equals(defaultmap, kmi); + if(!orig_kmi) + orig_kmi = wm_keymap_find_item_equals_result(defaultmap, kmi); + + if(orig_kmi) + kmi->id = orig_kmi->id; + else + kmi->id = -(km->kmi_id++); + } + + km->flag |= KEYMAP_UPDATE; /* update again to create diff */ + } + else + km = wm_keymap_copy(defaultmap); + + /* add addon keymap items */ + if(addonmap) + wm_keymap_addon_add(km, addonmap); + + /* tag as being user edited */ + if(usermap) + km->flag |= KEYMAP_USER_MODIFIED; + km->flag |= KEYMAP_USER|expanded; + + /* apply user changes of diff keymap */ + if(usermap && (usermap->flag & KEYMAP_DIFF)) + wm_keymap_patch(km, usermap); + + /* add to list */ + BLI_addtail(lb, km); +} + +static void wm_keymap_diff_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *km) +{ + wmKeyMap *diffmap, *prevmap, *origmap; + + /* create temporary default + addon keymap for diff */ + origmap = defaultmap; + + if(addonmap) { + defaultmap = wm_keymap_copy(defaultmap); + wm_keymap_addon_add(defaultmap, addonmap); + } + + /* remove previous diff keymap in list, we will replace it */ + prevmap = WM_keymap_list_find(lb, km->idname, km->spaceid, km->regionid); + if(prevmap) { + WM_keymap_free(prevmap); + BLI_freelinkN(lb, prevmap); + } + + /* create diff keymap */ + diffmap= wm_keymap_new(km->idname, km->spaceid, km->regionid); + diffmap->flag |= KEYMAP_DIFF; + wm_keymap_diff(diffmap, defaultmap, km, origmap, addonmap); + + /* add to list if not empty */ + if(diffmap->diff_items.first) { + BLI_addtail(lb, diffmap); + } + else { + WM_keymap_free(diffmap); + MEM_freeN(diffmap); + } + + /* free temporary default map */ + if(addonmap) { + WM_keymap_free(defaultmap); + MEM_freeN(defaultmap); } } @@ -292,11 +652,10 @@ wmKeyMap *WM_keymap_find(wmKeyConfig *keyconf, const char *idname, int spaceid, wmKeyMap *km= WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid); if(km==NULL) { - km= MEM_callocN(sizeof(struct wmKeyMap), "keymap list"); - BLI_strncpy(km->idname, idname, KMAP_MAX_NAME); - km->spaceid= spaceid; - km->regionid= regionid; + km= wm_keymap_new(idname, spaceid, regionid); BLI_addtail(&keyconf->keymaps, km); + + WM_keyconfig_update_tag(km, NULL); } return km; @@ -304,29 +663,9 @@ wmKeyMap *WM_keymap_find(wmKeyConfig *keyconf, const char *idname, int spaceid, wmKeyMap *WM_keymap_find_all(const bContext *C, const char *idname, int spaceid, int regionid) { - wmWindowManager *wm = CTX_wm_manager(C); - wmKeyConfig *keyconf; - wmKeyMap *km; - - /* first user defined keymaps */ - km= WM_keymap_list_find(&U.keymaps, idname, spaceid, regionid); - if (km) - return km; - - /* then user key config */ - keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr); - if(keyconf) { - km= WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid); - if (km) - return km; - } - - /* then use default */ - km= WM_keymap_list_find(&wm->defaultconf->keymaps, idname, spaceid, regionid); - if (km) - return km; - else - return NULL; + wmWindowManager *wm= CTX_wm_manager(C); + + return WM_keymap_list_find(&wm->userconf->keymaps, idname, spaceid, regionid); } /* ****************** modal keymaps ************ */ @@ -366,6 +705,8 @@ wmKeyMapItem *WM_modalkeymap_add_item(wmKeyMap *km, int type, int val, int modif keymap_item_set_id(km, kmi); + WM_keyconfig_update_tag(km, kmi); + return kmi; } @@ -588,169 +929,209 @@ int WM_keymap_item_compare(wmKeyMapItem *k1, wmKeyMapItem *k2) return 1; } -/* ***************** user preferences ******************* */ +/************************* Update Final Configuration ************************* + * On load or other changes, the final user key configuration is rebuilt from + * the preset, addon and user preferences keymaps. We also test if the final + * configuration changed and write the changes to the user preferences. */ + +static int WM_KEYMAP_UPDATE = 0; -int WM_keymap_user_init(wmWindowManager *wm, wmKeyMap *keymap) +void WM_keyconfig_update_tag(wmKeyMap *km, wmKeyMapItem *kmi) { - wmKeyConfig *keyconf; - wmKeyMap *km; + /* quick tag to do delayed keymap updates */ + WM_KEYMAP_UPDATE= 1; - if(!keymap) - return 0; + if(km) + km->flag |= KEYMAP_UPDATE; + if(kmi) + kmi->flag |= KMI_UPDATE; +} - /* init from user key config */ - keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr); - if(keyconf) { - km= WM_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - if(km) { - keymap->poll= km->poll; /* lazy init */ - keymap->modal_items= km->modal_items; - return 1; - } - } +static int wm_keymap_test_and_clear_update(wmKeyMap *km) +{ + wmKeyMapItem *kmi; + int update; + + update= (km->flag & KEYMAP_UPDATE); + km->flag &= ~KEYMAP_UPDATE; - /* or from default */ - km= WM_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - if(km) { - keymap->poll= km->poll; /* lazy init */ - keymap->modal_items= km->modal_items; - return 1; + for(kmi=km->items.first; kmi; kmi=kmi->next) { + update= update || (kmi->flag & KMI_UPDATE); + kmi->flag &= ~KMI_UPDATE; } - - return 0; + + return update; } -wmKeyMap *WM_keymap_active(wmWindowManager *wm, wmKeyMap *keymap) +static wmKeyMap *wm_keymap_preset(wmWindowManager *wm, wmKeyMap *km) { - wmKeyConfig *keyconf; - wmKeyMap *km; + wmKeyConfig *keyconf= WM_keyconfig_active(wm); + wmKeyMap *keymap; + keymap= WM_keymap_list_find(&keyconf->keymaps, km->idname, km->spaceid, km->regionid); if(!keymap) - return NULL; - - /* first user defined keymaps */ - km= WM_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - if(km) { - km->poll= keymap->poll; /* lazy init */ - km->modal_items= keymap->modal_items; - return km; - } - - /* then user key config */ - keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr); - if(keyconf) { - km= WM_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - if(km) { - km->poll= keymap->poll; /* lazy init */ - km->modal_items= keymap->modal_items; - return km; - } - } + keymap= WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, km->spaceid, km->regionid); - /* then use default */ - km= WM_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - return km; + return keymap; } -wmKeyMap *WM_keymap_copy_to_user(wmKeyMap *keymap) +void WM_keyconfig_update(wmWindowManager *wm) { - wmKeyMap *usermap; + wmKeyMap *km, *defaultmap, *addonmap, *usermap; wmKeyMapItem *kmi; + wmKeyMapDiffItem *kmdi; + int compat_update = 0; - usermap= WM_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - - /* XXX this function is only used by RMB setting hotkeys, and it clears maps on 2nd try this way */ - if(keymap==usermap) - return keymap; + if(!WM_KEYMAP_UPDATE) + return; - if(!usermap) { - /* not saved yet, duplicate existing */ - usermap= MEM_dupallocN(keymap); - usermap->modal_items= NULL; - usermap->poll= NULL; - usermap->flag |= KEYMAP_USER; + /* update operator properties for non-modal user keymaps */ + for(km=U.user_keymaps.first; km; km=km->next) { + if((km->flag & KEYMAP_MODAL) == 0) { + for(kmdi=km->diff_items.first; kmdi; kmdi=kmdi->next) { + if(kmdi->add_item) + wm_keymap_item_properties_set(kmdi->add_item); + if(kmdi->remove_item) + wm_keymap_item_properties_set(kmdi->remove_item); + } - BLI_addtail(&U.keymaps, usermap); + for(kmi=km->items.first; kmi; kmi=kmi->next) + wm_keymap_item_properties_set(kmi); + } } - else { - /* already saved, free items for re-copy */ - WM_keymap_free(usermap); + + /* update U.user_keymaps with user key configuration changes */ + for(km=wm->userconf->keymaps.first; km; km=km->next) { + /* only diff if the user keymap was modified */ + if(wm_keymap_test_and_clear_update(km)) { + /* find keymaps */ + defaultmap= wm_keymap_preset(wm, km); + addonmap= WM_keymap_list_find(&wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid); + + /* diff */ + wm_keymap_diff_update(&U.user_keymaps, defaultmap, addonmap, km); + } } - BLI_duplicatelist(&usermap->items, &keymap->items); + /* create user key configuration from preset + addon + user preferences */ + for(km=wm->defaultconf->keymaps.first; km; km=km->next) { + /* find keymaps */ + defaultmap= wm_keymap_preset(wm, km); + addonmap= WM_keymap_list_find(&wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid); + usermap= WM_keymap_list_find(&U.user_keymaps, km->idname, km->spaceid, km->regionid); - for(kmi=usermap->items.first; kmi; kmi=kmi->next) { - if(kmi->properties) { - kmi->ptr= MEM_callocN(sizeof(PointerRNA), "UserKeyMapItemPtr"); - WM_operator_properties_create(kmi->ptr, kmi->idname); + /* add */ + wm_keymap_patch_update(&wm->userconf->keymaps, defaultmap, addonmap, usermap); - kmi->properties= IDP_CopyProperty(kmi->properties); - kmi->ptr->data= kmi->properties; - } + /* in case of old non-diff keymaps, force extra update to create diffs */ + compat_update = compat_update || (usermap && !(usermap->flag & KEYMAP_DIFF)); } - for(kmi=keymap->items.first; kmi; kmi=kmi->next) - kmi->flag &= ~KMI_EXPANDED; + WM_KEYMAP_UPDATE= 0; + + if(compat_update) { + WM_keyconfig_update_tag(NULL, NULL); + WM_keyconfig_update(wm); + } +} + +/********************************* Event Handling ***************************** + * Handlers have pointers to the keymap in the default configuration. During + * event handling this function is called to get the keymap from the final + * configuration. */ + +wmKeyMap *WM_keymap_active(wmWindowManager *wm, wmKeyMap *keymap) +{ + wmKeyMap *km; + + if(!keymap) + return NULL; + + /* first user defined keymaps */ + km= WM_keymap_list_find(&wm->userconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); + + if(km) + return km; - return usermap; + return keymap; } +/******************************* Keymap Editor ******************************** + * In the keymap editor the user key configuration is edited. */ + void WM_keymap_restore_item_to_default(bContext *C, wmKeyMap *keymap, wmKeyMapItem *kmi) { wmWindowManager *wm = CTX_wm_manager(C); - wmKeyConfig *keyconf; - wmKeyMap *km = NULL; + wmKeyMap *defaultmap, *addonmap; + wmKeyMapItem *orig; - /* look in user key config */ - keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr); - if(keyconf) { - km= WM_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - } + if(!keymap) + return; + + /* construct default keymap from preset + addons */ + defaultmap= wm_keymap_preset(wm, keymap); + addonmap= WM_keymap_list_find(&wm->addonconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); - if (!km) { - /* or from default */ - km= WM_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); + if(addonmap) { + defaultmap = wm_keymap_copy(defaultmap); + wm_keymap_addon_add(defaultmap, addonmap); } - if (km) { - wmKeyMapItem *orig = WM_keymap_item_find_id(km, kmi->id); + /* find original item */ + orig = WM_keymap_item_find_id(defaultmap, kmi->id); - if (orig) { - if(strcmp(orig->idname, kmi->idname) != 0) { - BLI_strncpy(kmi->idname, orig->idname, sizeof(kmi->idname)); + if(orig) { + /* restore to original */ + if(strcmp(orig->idname, kmi->idname) != 0) { + BLI_strncpy(kmi->idname, orig->idname, sizeof(kmi->idname)); + WM_keymap_properties_reset(kmi, NULL); + } - WM_keymap_properties_reset(kmi, NULL); - } - - if (orig->properties) { - kmi->properties= IDP_CopyProperty(orig->properties); - kmi->ptr->data= kmi->properties; + if (orig->properties) { + if(kmi->properties) { + IDP_FreeProperty(kmi->properties); + MEM_freeN(kmi->properties); + kmi->properties= NULL; } - kmi->propvalue = orig->propvalue; - kmi->type = orig->type; - kmi->val = orig->val; - kmi->shift = orig->shift; - kmi->ctrl = orig->ctrl; - kmi->alt = orig->alt; - kmi->oskey = orig->oskey; - kmi->keymodifier = orig->keymodifier; - kmi->maptype = orig->maptype; - + kmi->properties= IDP_CopyProperty(orig->properties); + kmi->ptr->data= kmi->properties; } + kmi->propvalue = orig->propvalue; + kmi->type = orig->type; + kmi->val = orig->val; + kmi->shift = orig->shift; + kmi->ctrl = orig->ctrl; + kmi->alt = orig->alt; + kmi->oskey = orig->oskey; + kmi->keymodifier = orig->keymodifier; + kmi->maptype = orig->maptype; + + WM_keyconfig_update_tag(keymap, kmi); + } + + /* free temporary keymap */ + if(addonmap) { + WM_keymap_free(defaultmap); + MEM_freeN(defaultmap); } } -void WM_keymap_restore_to_default(wmKeyMap *keymap) +void WM_keymap_restore_to_default(wmKeyMap *keymap, bContext *C) { + wmWindowManager *wm = CTX_wm_manager(C); wmKeyMap *usermap; - usermap= WM_keymap_list_find(&U.keymaps, keymap->idname, keymap->spaceid, keymap->regionid); + /* remove keymap from U.user_keymaps and update */ + usermap= WM_keymap_list_find(&U.user_keymaps, keymap->idname, keymap->spaceid, keymap->regionid); if(usermap) { WM_keymap_free(usermap); - BLI_freelinkN(&U.keymaps, usermap); + BLI_freelinkN(&U.user_keymaps, usermap); + + WM_keyconfig_update_tag(NULL, NULL); + WM_keyconfig_update(wm); } } @@ -951,3 +1332,4 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname) return km; } + -- cgit v1.2.3 From d78be1f76209bed9924ff2439ac3f817aee7966c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 6 Aug 2011 04:19:30 +0000 Subject: remove copy modifiers function, now handled in link data operator. --- source/blender/editors/object/object_edit.c | 107 +--------------------------- 1 file changed, 3 insertions(+), 104 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 395705dc029..c8d38218533 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1049,109 +1049,6 @@ static void copymenu_logicbricks(Scene *scene, View3D *v3d, Object *ob) } } -static void copymenu_modifiers(Main *bmain, Scene *scene, View3D *v3d, Object *ob) -{ - Base *base; - int i, event; - char str[512]; - const char *errorstr= NULL; - - strcpy(str, "Copy Modifiers %t"); - - sprintf(str+strlen(str), "|All%%x%d|%%l", NUM_MODIFIER_TYPES); - - for (i=eModifierType_None+1; iflags&eModifierTypeFlag_AcceptsCVs) || - (ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) { - sprintf(str+strlen(str), "|%s%%x%d", mti->name, i); - } - } - - event = pupmenu(str); - if(event<=0) return; - - for (base= FIRSTBASE; base; base= base->next) { - if(base->object != ob) { - if(TESTBASELIB(v3d, base)) { - - base->object->recalc |= OB_RECALC_OB|OB_RECALC_DATA; - - if (base->object->type==ob->type) { - /* copy all */ - if (event==NUM_MODIFIER_TYPES) { - ModifierData *md; - object_free_modifiers(base->object); - - for (md=ob->modifiers.first; md; md=md->next) { - ModifierData *nmd = NULL; - - if(ELEM3(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance)) continue; - - if(md->type == eModifierType_Collision) - continue; - - nmd = modifier_new(md->type); - modifier_copyData(md, nmd); - BLI_addtail(&base->object->modifiers, nmd); - modifier_unique_name(&base->object->modifiers, nmd); - } - - copy_object_particlesystems(base->object, ob); - copy_object_softbody(base->object, ob); - } else { - /* copy specific types */ - ModifierData *md, *mdn; - - /* remove all with type 'event' */ - for (md=base->object->modifiers.first; md; md=mdn) { - mdn= md->next; - if(md->type==event) { - BLI_remlink(&base->object->modifiers, md); - modifier_free(md); - } - } - - /* copy all with type 'event' */ - for (md=ob->modifiers.first; md; md=md->next) { - if (md->type==event) { - - mdn = modifier_new(event); - BLI_addtail(&base->object->modifiers, mdn); - modifier_unique_name(&base->object->modifiers, mdn); - - modifier_copyData(md, mdn); - } - } - - if(event == eModifierType_ParticleSystem) { - object_free_particlesystems(base->object); - copy_object_particlesystems(base->object, ob); - } - else if(event == eModifierType_Softbody) { - object_free_softbody(base->object); - copy_object_softbody(base->object, ob); - } - } - } - else - errorstr= "Did not copy modifiers to other Object types"; - } - } - } - -// if(errorstr) notice(errorstr); - - DAG_scene_sort(bmain, scene); - -} - /* both pointers should exist */ static void copy_texture_space(Object *to, Object *ob) { @@ -1196,6 +1093,7 @@ static void copy_texture_space(Object *to, Object *ob) } +/* UNUSED, keep incase we want to copy functionality for use elsewhere */ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) { Object *ob; @@ -1221,7 +1119,8 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event) return; } else if(event==24) { - copymenu_modifiers(bmain, scene, v3d, ob); + /* moved to object_link_modifiers */ + /* copymenu_modifiers(bmain, scene, v3d, ob); */ return; } -- cgit v1.2.3 From dc4dede8029801580683551b39f967c206720736 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 6 Aug 2011 06:38:18 +0000 Subject: for UI text drawing use BLF_ascender(fs->uifont_id) rather then BLF_height(fs->uifont_id, "2"), while profiling draw noticed that the hash lookup on the character and utf8 next were being called on every text draw, use BLF_ascender since it doesn't do any lookups. --- source/blender/editors/interface/interface_style.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 5f2a757d2e3..8d4b4209120 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -149,9 +149,9 @@ void uiStyleFontDrawExt(uiFontStyle *fs, rcti *rect, const char *str, int xofs=0, yofs; uiStyleFontSet(fs); - - height= BLF_height(fs->uifont_id, "2"); /* correct offset is on baseline, the j is below that */ - yofs= floor( 0.5f*(rect->ymax - rect->ymin - height)); + + height= BLF_ascender(fs->uifont_id); + yofs= ceil( 0.5f*(rect->ymax - rect->ymin - height)); if(fs->align==UI_STYLE_TEXT_CENTER) { xofs= floor( 0.5f*(rect->xmax - rect->xmin - BLF_width(fs->uifont_id, str))); @@ -206,9 +206,9 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str) uiStyleFontSet(fs); - height= BLF_height(fs->uifont_id, "2"); /* correct offset is on baseline, the j is below that */ + height= BLF_ascender(fs->uifont_id); /* becomes x-offset when rotated */ - xofs= floor( 0.5f*(rect->ymax - rect->ymin - height)) + 1; + xofs= ceil( 0.5f*(rect->ymax - rect->ymin - height)); /* ignore UI_STYLE, always aligned to top */ -- cgit v1.2.3 From 2f5809d8317e8dd7a3e4edc30a6f709fb632bb83 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 6 Aug 2011 14:57:55 +0000 Subject: make ui_def_but_rna into 2 functions, once which takes a prop, another which takes a propname, no functional change yet but lets us avoid duplicate hash lookups. --- source/blender/editors/interface/interface.c | 238 ++++++++++++++------------- 1 file changed, 128 insertions(+), 110 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 8aed0d58a07..78e24c3bccb 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2490,138 +2490,141 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, return but; } -static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) +/* ui_def_but_rna_propname and ui_def_but_rna + * both take the same args except for propname vs prop, this is done so we can + * avoid an extra lookup on 'prop' when its already available. + * + * When this kind of change won't disrupt branches, best look into making more + * of our UI functions take prop rather then propname. + */ + +#define UI_DEF_BUT_RNA_DISABLE(but) \ + but->flag |= UI_BUT_DISABLED; \ + but->lock = 1; \ + but->lockstr = "" + + +static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip) { uiBut *but; - PropertyRNA *prop; PropertyType proptype; int freestr= 0, icon= 0; - prop= RNA_struct_find_property(ptr, propname); + proptype= RNA_property_type(prop); - if(prop) { - proptype= RNA_property_type(prop); - - /* use rna values if parameters are not specified */ - if(!str) { - if(type == MENU && proptype == PROP_ENUM) { - EnumPropertyItem *item; - DynStr *dynstr; - int i, totitem, value, free; - - RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free); - value= RNA_property_enum_get(ptr, prop); - - dynstr= BLI_dynstr_new(); - BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop)); - for(i=0; ievil_C, ptr, prop, &item, &totitem, &free); + value= RNA_property_enum_get(ptr, prop); + + dynstr= BLI_dynstr_new(); + BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop)); + for(i=0; ievil_C, ptr, prop, &item, &totitem, &free); - for(i=0; ievil_C, ptr, prop, &item, &totitem, &free); + for(i=0; itype), propname); - str= propname; } /* now create button */ but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip); - if(prop) { - but->rnapoin= *ptr; - but->rnaprop= prop; + but->rnapoin= *ptr; + but->rnaprop= prop; - if(RNA_property_array_length(&but->rnapoin, but->rnaprop)) - but->rnaindex= index; - else - but->rnaindex= 0; - } + if(RNA_property_array_length(&but->rnapoin, but->rnaprop)) + but->rnaindex= index; + else + but->rnaindex= 0; if(icon) { but->icon= (BIFIconID)icon; @@ -2629,10 +2632,8 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s but->flag|= UI_ICON_LEFT; } - if (!prop || !RNA_property_editable(&but->rnapoin, prop)) { - but->flag |= UI_BUT_DISABLED; - but->lock = 1; - but->lockstr = ""; + if (!RNA_property_editable(&but->rnapoin, prop)) { + UI_DEF_BUT_RNA_DISABLE(but); } /* If this button uses units, calculate the step from this */ @@ -2645,6 +2646,23 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s return but; } +static uiBut *ui_def_but_rna_propname(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, propname); + uiBut *but; + + if(prop) { + but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, prop, index, min, max, a1, a2, tip); + } + else { + but= ui_def_but(block, type, retval, propname, x1, y1, x2, y2, NULL, min, max, a1, a2, tip); + + UI_DEF_BUT_RNA_DISABLE(but); + } + + return but; +} + static uiBut *ui_def_but_operator(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, const char *tip) { uiBut *but; @@ -2857,7 +2875,7 @@ uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x1, { uiBut *but; - but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); + but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); if(but) ui_check_but(but); @@ -2942,7 +2960,7 @@ uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x1, int { uiBut *but; - but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); + but= ui_def_but_rna_propname(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); if(but) { if(icon) { but->icon= (BIFIconID) icon; @@ -3027,7 +3045,7 @@ uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, const c { uiBut *but; - but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); + but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); if(but) { if(icon) { but->icon= (BIFIconID) icon; -- cgit v1.2.3 From 79e359f92af3b26d10c3f65ba9548863b7010546 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 6 Aug 2011 16:00:00 +0000 Subject: rna/ui: avoid duplicate property gHash lookups by passing the property when its already been found. added _prop suffix to ui functions which take a prop rather then a propname, may change this later since its not that nice but for gsoc branches this keeps existing UI functions working the same. --- source/blender/editors/include/UI_interface.h | 3 + source/blender/editors/interface/interface.c | 102 +++++++++------------ .../blender/editors/interface/interface_layout.c | 18 ++-- .../blender/editors/interface/interface_regions.c | 29 +++--- .../editors/interface/interface_templates.c | 14 +-- source/blender/editors/interface/interface_utils.c | 43 ++++----- 6 files changed, 95 insertions(+), 114 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 1bae6ce0214..3fe012ea73e 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -410,6 +410,7 @@ uiBut *uiDefButBitS(uiBlock *block, int type, int bit, int retval, const char *s uiBut *uiDefButC(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefButBitC(uiBlock *block, int type, int bit, int retval, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip); +uiBut *uiDefButR_prop(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefButO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, const char *tip); uiBut *uiDefButTextO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip); @@ -429,6 +430,7 @@ uiBut *uiDefIconButBitS(uiBlock *block, int type, int bit, int retval, int icon, uiBut *uiDefIconButC(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefIconButBitC(uiBlock *block, int type, int bit, int retval, int icon, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip); +uiBut *uiDefIconButR_prop(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, struct PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefIconButO(uiBlock *block, int type, const char *opname, int opcontext, int icon, int x1, int y1, short x2, short y2, const char *tip); uiBut *uiDefIconTextBut(uiBlock *block, @@ -447,6 +449,7 @@ uiBut *uiDefIconTextButBitS(uiBlock *block, int type, int bit, int retval, int i uiBut *uiDefIconTextButC(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefIconTextButBitC(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, char *poin, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip); +uiBut *uiDefIconTextButR_prop(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip); uiBut *uiDefIconTextButO(uiBlock *block, int type, const char *opname, int opcontext, int icon, const char *str, int x1, int y1, short x2, short y2, const char *tip); /* for passing inputs to ButO buttons */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 78e24c3bccb..e31e3a26b40 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2830,6 +2830,16 @@ static void autocomplete_id(bContext *C, char *str, void *arg_v) } } +static void ui_check_but_and_iconize(uiBut *but, int icon) +{ + if(icon) { + but->icon= (BIFIconID) icon; + but->flag|= UI_HAS_ICON; + } + + ui_check_but(but); +} + static uiBut *uiDefButBit(uiBlock *block, int type, int bit, int retval, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip) { int bitIdx= findBitIndex(bit); @@ -2874,31 +2884,29 @@ uiBut *uiDefButBitC(uiBlock *block, int type, int bit, int retval, const char *s uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { uiBut *but; - but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); - if(but) - ui_check_but(but); - + ui_check_but(but); + return but; +} +uiBut *uiDefButR_prop(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip) +{ + uiBut *but; + but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, prop, index, min, max, a1, a2, tip); + ui_check_but(but); return but; } uiBut *uiDefButO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, const char *tip) { uiBut *but; - but= ui_def_but_operator(block, type, opname, opcontext, str, x1, y1, x2, y2, tip); - if(but) - ui_check_but(but); - + ui_check_but(but); return but; } uiBut *uiDefButTextO(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip) { uiBut *but= ui_def_but_operator_text(block, type, opname, opcontext, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip); - - if(but) - ui_check_but(but); - + ui_check_but(but); return but; } @@ -2906,12 +2914,7 @@ uiBut *uiDefButTextO(uiBlock *block, int type, const char *opname, int opcontext uiBut *uiDefIconBut(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip) { uiBut *but= ui_def_but(block, type, retval, "", x1, y1, x2, y2, poin, min, max, a1, a2, tip); - - but->icon= (BIFIconID) icon; - but->flag|= UI_HAS_ICON; - - ui_check_but(but); - + ui_check_but_and_iconize(but, icon); return but; } static uiBut *uiDefIconButBit(uiBlock *block, int type, int bit, int retval, int icon, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip) @@ -2959,29 +2962,22 @@ uiBut *uiDefIconButBitC(uiBlock *block, int type, int bit, int retval, int icon, uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { uiBut *but; - but= ui_def_but_rna_propname(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); - if(but) { - if(icon) { - but->icon= (BIFIconID) icon; - but->flag|= UI_HAS_ICON; - } - ui_check_but(but); - } - + ui_check_but_and_iconize(but, icon); + return but; +} +uiBut *uiDefIconButR_prop(uiBlock *block, int type, int retval, int icon, int x1, int y1, short x2, short y2, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip) +{ + uiBut *but; + but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, prop, index, min, max, a1, a2, tip); + ui_check_but_and_iconize(but, icon); return but; } uiBut *uiDefIconButO(uiBlock *block, int type, const char *opname, int opcontext, int icon, int x1, int y1, short x2, short y2, const char *tip) { uiBut *but; - but= ui_def_but_operator(block, type, opname, opcontext, "", x1, y1, x2, y2, tip); - if(but) { - but->icon= (BIFIconID) icon; - but->flag|= UI_HAS_ICON; - ui_check_but(but); - } - + ui_check_but_and_iconize(but, icon); return but; } @@ -2989,14 +2985,8 @@ uiBut *uiDefIconButO(uiBlock *block, int type, const char *opname, int opcontext uiBut *uiDefIconTextBut(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip) { uiBut *but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip); - - but->icon= (BIFIconID) icon; - but->flag|= UI_HAS_ICON; - + ui_check_but_and_iconize(but, icon); but->flag|= UI_ICON_LEFT; - - ui_check_but(but); - return but; } static uiBut *uiDefIconTextButBit(uiBlock *block, int type, int bit, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip) @@ -3044,31 +3034,25 @@ uiBut *uiDefIconTextButBitC(uiBlock *block, int type, int bit, int retval, int i uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip) { uiBut *but; - but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip); - if(but) { - if(icon) { - but->icon= (BIFIconID) icon; - but->flag|= UI_HAS_ICON; - } - but->flag|= UI_ICON_LEFT; - ui_check_but(but); - } - + ui_check_but_and_iconize(but, icon); + but->flag|= UI_ICON_LEFT; + return but; +} +uiBut *uiDefIconTextButR_prop(uiBlock *block, int type, int retval, int icon, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip) +{ + uiBut *but; + but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, prop, index, min, max, a1, a2, tip); + ui_check_but_and_iconize(but, icon); + but->flag|= UI_ICON_LEFT; return but; } uiBut *uiDefIconTextButO(uiBlock *block, int type, const char *opname, int opcontext, int icon, const char *str, int x1, int y1, short x2, short y2, const char *tip) { uiBut *but; - but= ui_def_but_operator(block, type, opname, opcontext, str, x1, y1, x2, y2, tip); - if(but) { - but->icon= (BIFIconID) icon; - but->flag|= UI_HAS_ICON; - but->flag|= UI_ICON_LEFT; - ui_check_but(but); - } - + ui_check_but_and_iconize(but, icon); + but->flag|= UI_ICON_LEFT; return but; } diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 2f0bcc9d5b4..85cc944f03b 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -419,7 +419,7 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, const char *name, in } } else if(subtype == PROP_DIRECTION) { - uiDefButR(block, BUT_NORMAL, 0, name, x, y, UI_UNIT_X*3, UI_UNIT_Y*3, ptr, RNA_property_identifier(prop), 0, 0, 0, -1, -1, NULL); + uiDefButR_prop(block, BUT_NORMAL, 0, name, x, y, UI_UNIT_X*3, UI_UNIT_Y*3, ptr, prop, 0, 0, 0, -1, -1, NULL); } else { if(ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA) && !expand) @@ -461,11 +461,9 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt { uiBut *but; EnumPropertyItem *item; - const char *identifier; const char *name; int a, totitem, itemw, icon, value, free; - identifier= RNA_property_identifier(prop); RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free); uiBlockSetCurLayout(block, ui_item_local_sublayout(layout, layout, 1)); @@ -479,11 +477,11 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt itemw= ui_text_icon_width(block->curlayout, name, icon, 0); if(icon && name[0] && !icon_only) - but= uiDefIconTextButR(block, ROW, 0, icon, name, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL); + but= uiDefIconTextButR_prop(block, ROW, 0, icon, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); else if(icon) - but= uiDefIconButR(block, ROW, 0, icon, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL); + but= uiDefIconButR_prop(block, ROW, 0, icon, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); else - but= uiDefButR(block, ROW, 0, name, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL); + but= uiDefButR_prop(block, ROW, 0, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); if(ui_layout_local_dir(layout) != UI_LAYOUT_HORIZONTAL) but->flag |= UI_TEXT_LEFT; @@ -540,7 +538,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, NULL); } else if(flag & UI_ITEM_R_EVENT) { - uiDefButR(block, KEYEVT, 0, name, x, y, w, h, ptr, RNA_property_identifier(prop), index, 0, 0, -1, -1, NULL); + uiDefButR_prop(block, KEYEVT, 0, name, x, y, w, h, ptr, prop, index, 0, 0, -1, -1, NULL); } else if(flag & UI_ITEM_R_FULL_EVENT) { if(RNA_struct_is_a(ptr->type, &RNA_KeyMapItem)) { @@ -548,7 +546,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n WM_keymap_item_to_string(ptr->data, buf, sizeof(buf)); - but= uiDefButR(block, HOTKEYEVT, 0, buf, x, y, w, h, ptr, RNA_property_identifier(prop), 0, 0, 0, -1, -1, NULL); + but= uiDefButR_prop(block, HOTKEYEVT, 0, buf, x, y, w, h, ptr, prop, 0, 0, 0, -1, -1, NULL); uiButSetFunc(but, ui_keymap_but_cb, but, NULL); if (flag & UI_ITEM_R_IMMEDIATE) uiButSetFlag(but, UI_BUT_IMMEDIATE); @@ -1008,11 +1006,11 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index const char *identifier= RNA_property_identifier(prop); if(icon && name[0] && !icon_only) - uiDefIconTextButR(block, ROW, 0, icon, name, 0, 0, w, h, ptr, identifier, -1, 0, value, -1, -1, NULL); + uiDefIconTextButR_prop(block, ROW, 0, icon, name, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL); else if(icon) uiDefIconButR(block, ROW, 0, icon, 0, 0, w, h, ptr, identifier, -1, 0, value, -1, -1, NULL); else - uiDefButR(block, ROW, 0, name, 0, 0, w, h, ptr, identifier, -1, 0, value, -1, -1, NULL); + uiDefButR_prop(block, ROW, 0, name, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL); } /* expanded enum */ else if(type == PROP_ENUM && (expand || RNA_property_flag(prop) & PROP_ENUM_FLAG)) diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 9e7717260e6..f7460e77030 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1934,31 +1934,31 @@ static void do_picker_new_mode_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(a #define PICKER_TOTAL_W (PICKER_W+PICKER_SPACE+PICKER_BAR) -static void circle_picker(uiBlock *block, PointerRNA *ptr, const char *propname) +static void circle_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop) { uiBut *bt; /* HS circle */ - bt= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, PICKER_H, PICKER_W, ptr, propname, 0, 0.0, 0.0, 0, 0, "Color"); + bt= uiDefButR_prop(block, HSVCIRCLE, 0, "", 0, 0, PICKER_H, PICKER_W, ptr, prop, 0, 0.0, 0.0, 0, 0, "Color"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); /* value */ - bt= uiDefButR(block, HSVCUBE, 0, "", PICKER_W+PICKER_SPACE,0,PICKER_BAR,PICKER_H, ptr, propname, 0, 0.0, 0.0, UI_GRAD_V_ALT, 0, "Value"); + bt= uiDefButR_prop(block, HSVCUBE, 0, "", PICKER_W+PICKER_SPACE,0,PICKER_BAR,PICKER_H, ptr, prop, 0, 0.0, 0.0, UI_GRAD_V_ALT, 0, "Value"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); } -static void square_picker(uiBlock *block, PointerRNA *ptr, const char *propname, int type) +static void square_picker(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type) { uiBut *bt; int bartype = type + 3; /* HS square */ - bt= uiDefButR(block, HSVCUBE, 0, "", 0, PICKER_BAR+PICKER_SPACE, PICKER_TOTAL_W, PICKER_H, ptr, propname, 0, 0.0, 0.0, type, 0, "Color"); + bt= uiDefButR_prop(block, HSVCUBE, 0, "", 0, PICKER_BAR+PICKER_SPACE, PICKER_TOTAL_W, PICKER_H, ptr, prop, 0, 0.0, 0.0, type, 0, "Color"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); /* value */ - bt= uiDefButR(block, HSVCUBE, 0, "", 0, 0, PICKER_TOTAL_W, PICKER_BAR, ptr, propname, 0, 0.0, 0.0, bartype, 0, "Value"); + bt= uiDefButR_prop(block, HSVCUBE, 0, "", 0, 0, PICKER_TOTAL_W, PICKER_BAR, ptr, prop, 0, 0.0, 0.0, bartype, 0, "Value"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); } @@ -1973,7 +1973,6 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR static char hexcol[128]; float rgb_gamma[3]; float min, max, step, precision; - const char *propname = RNA_property_identifier(prop); float *hsv= ui_block_hsv_get(block); ui_block_hsv_get(block); @@ -1999,16 +1998,16 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR switch (U.color_picker_type) { case USER_CP_CIRCLE: - circle_picker(block, ptr, propname); + circle_picker(block, ptr, prop); break; case USER_CP_SQUARE_SV: - square_picker(block, ptr, propname, UI_GRAD_SV); + square_picker(block, ptr, prop, UI_GRAD_SV); break; case USER_CP_SQUARE_HS: - square_picker(block, ptr, propname, UI_GRAD_HS); + square_picker(block, ptr, prop, UI_GRAD_HS); break; case USER_CP_SQUARE_HV: - square_picker(block, ptr, propname, UI_GRAD_HV); + square_picker(block, ptr, prop, UI_GRAD_HV); break; } @@ -2027,11 +2026,11 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR /* RGB values */ uiBlockBeginAlign(block); - bt= uiDefButR(block, NUMSLI, 0, "R ", 0, -60, butwidth, UI_UNIT_Y, ptr, propname, 0, 0.0, 0.0, 0, 3, "Red"); + bt= uiDefButR_prop(block, NUMSLI, 0, "R ", 0, -60, butwidth, UI_UNIT_Y, ptr, prop, 0, 0.0, 0.0, 0, 3, "Red"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); - bt= uiDefButR(block, NUMSLI, 0, "G ", 0, -80, butwidth, UI_UNIT_Y, ptr, propname, 1, 0.0, 0.0, 0, 3, "Green"); + bt= uiDefButR_prop(block, NUMSLI, 0, "G ", 0, -80, butwidth, UI_UNIT_Y, ptr, prop, 1, 0.0, 0.0, 0, 3, "Green"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); - bt= uiDefButR(block, NUMSLI, 0, "B ", 0, -100, butwidth, UI_UNIT_Y, ptr, propname, 2, 0.0, 0.0, 0, 3, "Blue"); + bt= uiDefButR_prop(block, NUMSLI, 0, "B ", 0, -100, butwidth, UI_UNIT_Y, ptr, prop, 2, 0.0, 0.0, 0, 3, "Blue"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); // could use uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND|UI_ITEM_R_SLIDER, "", ICON_NONE); @@ -2048,7 +2047,7 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR uiBlockEndAlign(block); if(rgb[3] != FLT_MAX) { - bt= uiDefButR(block, NUMSLI, 0, "A ", 0, -120, butwidth, UI_UNIT_Y, ptr, propname, 3, 0.0, 0.0, 0, 0, "Alpha"); + bt= uiDefButR_prop(block, NUMSLI, 0, "A ", 0, -120, butwidth, UI_UNIT_Y, ptr, prop, 3, 0.0, 0.0, 0, 0, "Alpha"); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); } else { diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 34315494e14..2d443bbfcd0 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -1884,7 +1884,7 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propnam col = uiLayoutColumn(layout, 0); row= uiLayoutRow(col, 1); - but= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, propname, -1, 0.0, 0.0, 0, 0, ""); + but= uiDefButR_prop(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, prop, -1, 0.0, 0.0, 0, 0, ""); if(lock) { but->flag |= UI_BUT_COLOR_LOCK; @@ -1903,7 +1903,7 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, const char *propnam uiItemS(row); if (value_slider) - uiDefButR(block, HSVCUBE, 0, "", WHEEL_SIZE+6, 0, 14, WHEEL_SIZE, ptr, propname, -1, softmin, softmax, UI_GRAD_V_ALT, 0, ""); + uiDefButR_prop(block, HSVCUBE, 0, "", WHEEL_SIZE+6, 0, 14, WHEEL_SIZE, ptr, prop, -1, softmin, softmax, UI_GRAD_V_ALT, 0, ""); } /********************* Layer Buttons Template ************************/ @@ -2034,7 +2034,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int return rnaicon; } -static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, const char *activepropname) +static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop) { uiBlock *block= uiLayoutGetBlock(layout); uiBut *but; @@ -2048,7 +2048,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe /* list item behind label & other buttons */ sub= uiLayoutRow(overlap, 0); - but= uiDefButR(block, LISTROW, 0, "", 0,0, UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, ""); + but= uiDefButR_prop(block, LISTROW, 0, "", 0,0, UI_UNIT_X*10,UI_UNIT_Y, activeptr, activeprop, 0, 0, i, 0, 0, ""); uiButSetFlag(but, UI_BUT_NO_TOOLTIP); sub= uiLayoutRow(overlap, 0); @@ -2201,7 +2201,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * row= uiLayoutRow(col, 0); icon= list_item_icon_get(C, &itemptr, rnaicon, 1); - but= uiDefIconButR(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, ""); + but= uiDefIconButR_prop(block, LISTROW, 0, icon, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activeprop, 0, 0, i, 0, 0, ""); uiButSetFlag(but, UI_BUT_NO_TOOLTIP); @@ -2241,7 +2241,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * /* next/prev button */ sprintf(str, "%d :", i); - but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activepropname, 0, 0, 0, 0, 0, ""); + but= uiDefIconTextButR_prop(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, ""); if(i == 0) uiButSetFlag(but, UI_BUT_DISABLED); } @@ -2280,7 +2280,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * /* create list items */ RNA_PROP_BEGIN(ptr, itemptr, prop) { if(i >= pa->list_scroll && ilist_scroll+items) - list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activepropname); + list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop); i++; } diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 1ec125c2f26..f660dbb9edd 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -51,56 +51,53 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, const char *name, int icon, int x1, int y1, int x2, int y2) { uiBut *but=NULL; - const char *propname= RNA_property_identifier(prop); - char prop_item[MAX_IDPROP_NAME+4]; /* size of the ID prop name + room for [""] */ - int arraylen= RNA_property_array_length(ptr, prop); - - /* support for custom props */ - if(RNA_property_is_idprop(prop)) { - sprintf(prop_item, "[\"%s\"]", propname); - propname= prop_item; - } switch(RNA_property_type(prop)) { - case PROP_BOOLEAN: { + case PROP_BOOLEAN: + { + int arraylen= RNA_property_array_length(ptr, prop); if(arraylen && index == -1) return NULL; if(icon && name && name[0] == '\0') - but= uiDefIconButR(block, ICONTOG, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefIconButR_prop(block, ICONTOG, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); else if(icon) - but= uiDefIconTextButR(block, ICONTOG, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefIconTextButR_prop(block, ICONTOG, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); else - but= uiDefButR(block, OPTION, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefButR_prop(block, OPTION, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; } case PROP_INT: case PROP_FLOAT: + { + int arraylen= RNA_property_array_length(ptr, prop); + if(arraylen && index == -1) { if(ELEM(RNA_property_subtype(prop), PROP_COLOR, PROP_COLOR_GAMMA)) - but= uiDefButR(block, COL, 0, name, x1, y1, x2, y2, ptr, propname, 0, 0, 0, -1, -1, NULL); + but= uiDefButR_prop(block, COL, 0, name, x1, y1, x2, y2, ptr, prop, 0, 0, 0, -1, -1, NULL); } else if(RNA_property_subtype(prop) == PROP_PERCENTAGE || RNA_property_subtype(prop) == PROP_FACTOR) - but= uiDefButR(block, NUMSLI, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefButR_prop(block, NUMSLI, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); else - but= uiDefButR(block, NUM, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefButR_prop(block, NUM, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; + } case PROP_ENUM: if(icon && name && name[0] == '\0') - but= uiDefIconButR(block, MENU, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefIconButR_prop(block, MENU, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); else if(icon) - but= uiDefIconTextButR(block, MENU, 0, icon, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefIconTextButR_prop(block, MENU, 0, icon, NULL, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); else - but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefButR_prop(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; case PROP_STRING: if(icon && name && name[0] == '\0') - but= uiDefIconButR(block, TEX, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefIconButR_prop(block, TEX, 0, icon, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); else if(icon) - but= uiDefIconTextButR(block, TEX, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefIconTextButR_prop(block, TEX, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); else - but= uiDefButR(block, TEX, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefButR_prop(block, TEX, 0, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; case PROP_POINTER: { PointerRNA pptr; @@ -112,7 +109,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind if(icon == ICON_DOT) icon= 0; - but= uiDefIconTextButR(block, IDPOIN, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); + but= uiDefIconTextButR_prop(block, IDPOIN, 0, icon, name, x1, y1, x2, y2, ptr, prop, index, 0, 0, -1, -1, NULL); break; } case PROP_COLLECTION: { -- cgit v1.2.3 From 5dd2b3e06f0164bf4313a172240ad7f4d37bacbe Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 6 Aug 2011 22:31:16 +0000 Subject: fixed crash when NDOF operators were called without an NDOF_MOTION event --- source/blender/editors/space_image/image_ops.c | 49 ++-- source/blender/editors/space_view3d/view3d_edit.c | 318 +++++++++++----------- 2 files changed, 185 insertions(+), 182 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index e0ebde589a8..ea8c7fc0cfa 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -447,34 +447,41 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) { - SpaceImage *sima= CTX_wm_space_image(C); - ARegion *ar= CTX_wm_region(C); + if (event->type != NDOF_MOTION) + return OPERATOR_CANCELLED; + else { + SpaceImage *sima= CTX_wm_space_image(C); + ARegion *ar= CTX_wm_region(C); - wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - float dt = ndof->dt; - /* tune these until it feels right */ - const float zoom_sensitivity = 0.5f; // 50% per second (I think) - const float pan_sensitivity = 300.f; // screen pixels per second + float dt = ndof->dt; + /* tune these until it feels right */ + const float zoom_sensitivity = 0.5f; // 50% per second (I think) + const float pan_sensitivity = 300.f; // screen pixels per second - float pan_x = pan_sensitivity * dt * ndof->tvec[0] / sima->zoom; - float pan_y = pan_sensitivity * dt * ndof->tvec[1] / sima->zoom; + float pan_x = pan_sensitivity * dt * ndof->tvec[0] / sima->zoom; + float pan_y = pan_sensitivity * dt * ndof->tvec[1] / sima->zoom; - /* "mouse zoom" factor = 1 + (dx + dy) / 300 - * what about "ndof zoom" factor? should behave like this: - * at rest -> factor = 1 - * move forward -> factor > 1 - * move backward -> factor < 1 - */ - float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->tvec[2]; + /* "mouse zoom" factor = 1 + (dx + dy) / 300 + * what about "ndof zoom" factor? should behave like this: + * at rest -> factor = 1 + * move forward -> factor > 1 + * move backward -> factor < 1 + */ + float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->tvec[2]; - sima_zoom_set_factor(sima, ar, zoom_factor); - sima->xof += pan_x; - sima->yof += pan_y; + if (U.ndof_flag & NDOF_ZOOM_INVERT) + zoom_factor = -zoom_factor; - ED_region_tag_redraw(ar); + sima_zoom_set_factor(sima, ar, zoom_factor); + sima->xof += pan_x; + sima->yof += pan_y; - return OPERATOR_FINISHED; + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; + } } void IMAGE_OT_view_ndof(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index e6fd9e8867b..3e6bbc13334 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -949,134 +949,125 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event // -- zooming // -- panning in rotationally-locked views { - RegionView3D* rv3d = CTX_wm_region_view3d(C); - wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + if (event->type != NDOF_MOTION) + return OPERATOR_CANCELLED; + else { + RegionView3D* rv3d = CTX_wm_region_view3d(C); + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; - rv3d->rot_angle = 0.f; // off by default, until changed later this function + rv3d->rot_angle = 0.f; // off by default, until changed later this function - if (ndof->progress != P_FINISHING) { - const float dt = ndof->dt; - - // tune these until everything feels right - const float rot_sensitivity = 1.f; - const float zoom_sensitivity = 1.f; - const float pan_sensitivity = 1.f; - - // rather have bool, but... - int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec); - - float view_inv[4]; - invert_qt_qt(view_inv, rv3d->viewquat); - - //#define DEBUG_NDOF_MOTION - #ifdef DEBUG_NDOF_MOTION - printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n", - ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt); - #endif - - if (ndof->tvec[2]) { - // Zoom! - // velocity should be proportional to the linear velocity attained by rotational motion of same strength - // [got that?] - // proportional to arclength = radius * angle - - float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tvec[2]; - rv3d->dist += zoom_distance; - } - - if (rv3d->viewlock == RV3D_LOCKED) { - /* rotation not allowed -- explore panning options instead */ - float pan_vec[3] = {ndof->tvec[0], ndof->tvec[1], 0.0f}; - mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); - - /* transform motion from view to world coordinates */ + if (ndof->progress != P_FINISHING) { + const float dt = ndof->dt; + + // tune these until everything feels right + const float rot_sensitivity = 1.f; + const float zoom_sensitivity = 1.f; + const float pan_sensitivity = 1.f; + + // rather have bool, but... + int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec); + + float view_inv[4]; invert_qt_qt(view_inv, rv3d->viewquat); - mul_qt_v3(view_inv, pan_vec); - - /* move center of view opposite of hand motion (this is camera mode, not object mode) */ - sub_v3_v3(rv3d->ofs, pan_vec); - } - - if (has_rotation) { - - const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; - - rv3d->view = RV3D_VIEW_USER; - - if (U.flag & USER_TRACKBALL) { - float rot[4]; - #if 0 // -------------------------- Mike's nifty original version - float view_inv_conj[4]; - - ndof_to_quat(ndof, rot); - // mul_qt_fl(rot, rot_sensitivity); - // ^^ no apparent effect - - if (invert) - invert_qt(rot); - - copy_qt_qt(view_inv_conj, view_inv); - conjugate_qt(view_inv_conj); - - // transform rotation from view to world coordinates - mul_qt_qtqt(rot, view_inv, rot); - mul_qt_qtqt(rot, rot, view_inv_conj); - #else // ---------------------------------------- Mike's revised version - float axis[3]; - float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis); - - if (invert) - angle = -angle; - - // transform rotation axis from view to world coordinates - mul_qt_v3(view_inv, axis); - - // update the onscreen doo-dad - rv3d->rot_angle = angle; - copy_v3_v3(rv3d->rot_axis, axis); - - axis_angle_to_quat(rot, axis, angle); - #endif // -------------------------------------------- - // apply rotation - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); - } else { - /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ - float angle, rot[4]; - float xvec[3] = {1,0,0}; - - /* Determine the direction of the x vector (for rotating up and down) */ - mul_qt_v3(view_inv, xvec); - - /* Perform the up/down rotation */ - angle = rot_sensitivity * dt * ndof->rvec[0]; - if (invert) - angle = -angle; - rot[0] = cos(angle); - mul_v3_v3fl(rot+1, xvec, sin(angle)); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); - - /* Perform the orbital rotation */ - angle = rot_sensitivity * dt * ndof->rvec[1]; - if (invert) - angle = -angle; - - // update the onscreen doo-dad - rv3d->rot_angle = angle; - rv3d->rot_axis[0] = 0; - rv3d->rot_axis[1] = 0; - rv3d->rot_axis[2] = 1; - - rot[0] = cos(angle); - rot[1] = rot[2] = 0.0; - rot[3] = sin(angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + + //#define DEBUG_NDOF_MOTION + #ifdef DEBUG_NDOF_MOTION + printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n", + ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt); + #endif + + if (ndof->tvec[2]) { + // Zoom! + // velocity should be proportional to the linear velocity attained by rotational motion of same strength + // [got that?] + // proportional to arclength = radius * angle + + float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tvec[2]; + + if (U.ndof_flag & NDOF_ZOOM_INVERT) + zoom_distance = -zoom_distance; + + rv3d->dist += zoom_distance; + } + + if (rv3d->viewlock == RV3D_LOCKED) { + /* rotation not allowed -- explore panning options instead */ + float pan_vec[3] = {ndof->tvec[0], ndof->tvec[1], 0.0f}; + mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); + + /* transform motion from view to world coordinates */ + invert_qt_qt(view_inv, rv3d->viewquat); + mul_qt_v3(view_inv, pan_vec); + + /* move center of view opposite of hand motion (this is camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, pan_vec); + } + + if (has_rotation) { + + const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; + + rv3d->view = RV3D_VIEW_USER; + + if (U.flag & USER_TRACKBALL) { + float rot[4]; + float axis[3]; + float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis); + + if (invert) + angle = -angle; + + // transform rotation axis from view to world coordinates + mul_qt_v3(view_inv, axis); + + // update the onscreen doo-dad + rv3d->rot_angle = angle; + copy_v3_v3(rv3d->rot_axis, axis); + + axis_angle_to_quat(rot, axis, angle); + + // apply rotation + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + } else { + /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ + float angle, rot[4]; + float xvec[3] = {1,0,0}; + + /* Determine the direction of the x vector (for rotating up and down) */ + mul_qt_v3(view_inv, xvec); + + /* Perform the up/down rotation */ + angle = rot_sensitivity * dt * ndof->rvec[0]; + if (invert) + angle = -angle; + rot[0] = cos(angle); + mul_v3_v3fl(rot+1, xvec, sin(angle)); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + + /* Perform the orbital rotation */ + angle = rot_sensitivity * dt * ndof->rvec[1]; + if (invert) + angle = -angle; + + // update the onscreen doo-dad + rv3d->rot_angle = angle; + rv3d->rot_axis[0] = 0; + rv3d->rot_axis[1] = 0; + rv3d->rot_axis[2] = 1; + + rot[0] = cos(angle); + rot[1] = rot[2] = 0.0; + rot[3] = sin(angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); + } } } - } - ED_region_tag_redraw(CTX_wm_region(C)); + ED_region_tag_redraw(CTX_wm_region(C)); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; + } } void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot) @@ -1098,57 +1089,62 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) // -- "pan" navigation // -- zoom or dolly? { - RegionView3D* rv3d = CTX_wm_region_view3d(C); - wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + if (event->type != NDOF_MOTION) + return OPERATOR_CANCELLED; + else { + RegionView3D* rv3d = CTX_wm_region_view3d(C); + wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata; + - rv3d->rot_angle = 0.f; // we're panning here! so erase any leftover rotation from other operators + rv3d->rot_angle = 0.f; // we're panning here! so erase any leftover rotation from other operators - if (ndof->progress != P_FINISHING) { - const float dt = ndof->dt; - float view_inv[4]; + if (ndof->progress != P_FINISHING) { + const float dt = ndof->dt; + float view_inv[4]; #if 0 // ------------------------------------------- zoom with Z - // tune these until everything feels right - const float zoom_sensitivity = 1.f; - const float pan_sensitivity = 1.f; - - float pan_vec[3] = { - ndof->tx, ndof->ty, 0 - }; - - // "zoom in" or "translate"? depends on zoom mode in user settings? - if (ndof->tz) { - float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; - rv3d->dist += zoom_distance; - } - - mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); + // tune these until everything feels right + const float zoom_sensitivity = 1.f; + const float pan_sensitivity = 1.f; + + float pan_vec[3] = { + ndof->tx, ndof->ty, 0 + }; + + // "zoom in" or "translate"? depends on zoom mode in user settings? + if (ndof->tz) { + float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz; + rv3d->dist += zoom_distance; + } + + mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt); #else // ------------------------------------------------------- dolly with Z - float speed = 10.f; // blender units per second - // ^^ this is ok for default cube scene, but should scale with.. something + float speed = 10.f; // blender units per second + // ^^ this is ok for default cube scene, but should scale with.. something - // tune these until everything feels right - const float forward_sensitivity = 1.f; - const float vertical_sensitivity = 0.4f; - const float lateral_sensitivity = 0.6f; + // tune these until everything feels right + const float forward_sensitivity = 1.f; + const float vertical_sensitivity = 0.4f; + const float lateral_sensitivity = 0.6f; - float pan_vec[3] = {lateral_sensitivity * ndof->tvec[0], - vertical_sensitivity * ndof->tvec[1], - forward_sensitivity * ndof->tvec[2] - }; + float pan_vec[3] = {lateral_sensitivity * ndof->tvec[0], + vertical_sensitivity * ndof->tvec[1], + forward_sensitivity * ndof->tvec[2] + }; - mul_v3_fl(pan_vec, speed * dt); + mul_v3_fl(pan_vec, speed * dt); #endif - /* transform motion from view to world coordinates */ - invert_qt_qt(view_inv, rv3d->viewquat); - mul_qt_v3(view_inv, pan_vec); + /* transform motion from view to world coordinates */ + invert_qt_qt(view_inv, rv3d->viewquat); + mul_qt_v3(view_inv, pan_vec); - /* move center of view opposite of hand motion (this is camera mode, not object mode) */ - sub_v3_v3(rv3d->ofs, pan_vec); - } + /* move center of view opposite of hand motion (this is camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, pan_vec); + } - ED_region_tag_redraw(CTX_wm_region(C)); + ED_region_tag_redraw(CTX_wm_region(C)); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; + } } void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot) -- cgit v1.2.3 From 6c821f4078414c81128ebf0d35187054df238371 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 6 Aug 2011 23:13:36 +0000 Subject: stricter NDOF guards for Windows (forgot in earlier commit) --- source/blender/makesdna/DNA_userdef_types.h | 2 +- source/blender/makesrna/intern/rna_userdef.c | 13 +++++++++++++ source/blender/windowmanager/intern/wm_event_system.c | 12 +++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index a555a196060..556f554eb98 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -603,7 +603,7 @@ extern UserDef U; /* from blenkernel blender.c */ #define NDOF_ORBIT_INVERT_AXES (1 << 6) /* zoom is up/down if this flag is set (otherwise forward/backward) */ #define NDOF_ZOOM_UPDOWN (1 << 7) -#define NDOF_INVERT_ZOOM (1 << 8) +#define NDOF_ZOOM_INVERT (1 << 8) #ifdef __cplusplus diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index b3dbafeab7d..57044188dd9 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2746,19 +2746,32 @@ static void rna_def_userdef_input(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Drag Threshold", "Amount of pixels you have to drag before dragging UI items happens"); /* 3D mouse settings */ + /* global options */ prop= RNA_def_property(srna, "ndof_sensitivity", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.25f, 4.0f); RNA_def_property_ui_text(prop, "Sensitivity", "Overall sensitivity of the 3D Mouse"); + prop= RNA_def_property(srna, "ndof_zoom_updown", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_ZOOM_UPDOWN); + RNA_def_property_ui_text(prop, "Zoom = Up/Down", "Zoom using up/down on the device (otherwise forward/backward)"); + + prop= RNA_def_property(srna, "ndof_zoom_invert", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_ZOOM_INVERT); + RNA_def_property_ui_text(prop, "Invert Zoom", "Zoom using opposite direction"); + + /* 3D view */ prop= RNA_def_property(srna, "ndof_show_guide", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_SHOW_GUIDE); RNA_def_property_ui_text(prop, "Show Navigation Guide", "Display the center and axis during rotation"); /* TODO: update description when fly-mode visuals are in place ("projected position in fly mode")*/ + /* 3D view: orbit */ prop= RNA_def_property(srna, "ndof_orbit_invert_axes", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_ORBIT_INVERT_AXES); RNA_def_property_ui_text(prop, "Invert Axes", "Toggle between moving the viewpoint or moving the scene being viewed"); + /* in 3Dx docs, this is called 'object mode' vs. 'target camera mode' + /* 3D view: fly */ prop= RNA_def_property(srna, "ndof_lock_horizon", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_LOCK_HORIZON); RNA_def_property_ui_text(prop, "Lock Horizon", "Keep horizon level while flying with 3D Mouse"); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 0dac0bd7401..258d6bbc025 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2330,26 +2330,28 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g const float s = U.ndof_sensitivity; data->tvec[0]= s * ghost->tx; + data->rvec[0]= s * ghost->rx; + data->rvec[1]= s * ghost->ry; + data->rvec[2]= s * ghost->rz; if (U.ndof_flag & NDOF_ZOOM_UPDOWN) { - // swap Y and Z + // rotate so Y is where Z was (maintain handed-ness) data->tvec[1]= s * ghost->tz; - data->tvec[2]= s * ghost->ty; + data->tvec[2]= s * -ghost->ty; // should this affect rotation also? // initial guess is 'yes', but get user feedback immediately! +#if 0 // after turning this on, my guess becomes 'no' data->rvec[1]= s * ghost->rz; data->rvec[2]= s * ghost->ry; +#endif } else { data->tvec[1]= s * ghost->ty; data->tvec[2]= s * ghost->tz; - - data->rvec[1]= s * ghost->ry; - data->rvec[2]= s * ghost->rz; } data->dt = ghost->dt; -- cgit v1.2.3 From 117ec4a91ac996480611788998645bd6de40d706 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 7 Aug 2011 04:22:33 +0000 Subject: comment unused vars --- source/blender/editors/interface/interface_handlers.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index d8d8354b0b9..6f3ca2bf003 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2856,7 +2856,7 @@ static int ui_do_but_SLI(bContext *C, uiBlock *block, uiBut *but, uiHandleButton static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event) { - int mx, my, click= 0; + int mx, my /*, click= 0 */; int retval= WM_UI_HANDLER_CONTINUE; int horizontal= (but->x2 - but->x1 > but->y2 - but->y1); @@ -2878,8 +2878,10 @@ static int ui_do_but_SCROLL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); retval= WM_UI_HANDLER_BREAK; } - else if(ELEM(event->type, PADENTER, RETKEY) && event->val==KM_PRESS) + /* UNUSED - otherwise code is ok, add back if needed */ + /* else if(ELEM(event->type, PADENTER, RETKEY) && event->val==KM_PRESS) click= 1; + */ } } else if(data->state == BUTTON_STATE_NUM_EDITING) { @@ -3677,6 +3679,9 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt return WM_UI_HANDLER_BREAK; } + /* UNUSED but keep for now */ + (void)changed; + return WM_UI_HANDLER_CONTINUE; } @@ -3691,12 +3696,12 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx Histogram *hist = (Histogram *)but->poin; /* rcti rect; */ int changed= 1; - float dx, dy, yfac=1.f; + float /* dx, */ dy, yfac=1.f; /* UNUSED */ /* rect.xmin= but->x1; rect.xmax= but->x2; */ /* rect.ymin= but->y1; rect.ymax= but->y2; */ - dx = mx - data->draglastx; + /* dx = mx - data->draglastx; */ /* UNUSED */ dy = my - data->draglasty; @@ -3774,12 +3779,12 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx, Scopes *scopes = (Scopes *)but->poin; /* rcti rect; */ int changed= 1; - float dx, dy, yfac=1.f; + float /* dx, */ dy /* , yfac=1.f */; /* UNUSED */ /* rect.xmin= but->x1; rect.xmax= but->x2; */ /* rect.ymin= but->y1; rect.ymax= but->y2; */ - dx = mx - data->draglastx; + /* dx = mx - data->draglastx; */ /* UNUSED */ dy = my - data->draglasty; @@ -3788,7 +3793,7 @@ static int ui_numedit_but_WAVEFORM(uiBut *but, uiHandleButtonData *data, int mx, scopes->wavefrm_height = (but->y2 - but->y1) + (data->dragstarty - my); } else { /* scale waveform values */ - yfac = scopes->wavefrm_yfac; + /* yfac = scopes->wavefrm_yfac; */ /* UNUSED */ scopes->wavefrm_yfac += dy/200.0f; CLAMP(scopes->wavefrm_yfac, 0.5f, 2.f); -- cgit v1.2.3 From a02d7c1ba76adbf3ff432111af4c3c81a0812c3a Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 7 Aug 2011 11:01:55 +0000 Subject: Fix #28169: keymap bug when using a preset configuration, e.g. object mode keymap was also being used in edit mode. --- source/blender/windowmanager/intern/wm_keymap.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index bf48f0e21e4..2fb0a1b2ab9 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -532,7 +532,7 @@ static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km) } } -static void wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap) +static wmKeyMap *wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap) { wmKeyMap *km; int expanded = 0; @@ -552,8 +552,6 @@ static void wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap wmKeyMapItem *kmi, *orig_kmi; km = wm_keymap_copy(usermap); - km->modal_items = defaultmap->modal_items; - km->poll = defaultmap->poll; /* try to find corresponding id's for items */ for(kmi=km->items.first; kmi; kmi=kmi->next) { @@ -587,6 +585,8 @@ static void wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap /* add to list */ BLI_addtail(lb, km); + + return km; } static void wm_keymap_diff_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *km) @@ -977,7 +977,7 @@ static wmKeyMap *wm_keymap_preset(wmWindowManager *wm, wmKeyMap *km) void WM_keyconfig_update(wmWindowManager *wm) { - wmKeyMap *km, *defaultmap, *addonmap, *usermap; + wmKeyMap *km, *defaultmap, *addonmap, *usermap, *kmn; wmKeyMapItem *kmi; wmKeyMapDiffItem *kmdi; int compat_update = 0; @@ -1021,7 +1021,12 @@ void WM_keyconfig_update(wmWindowManager *wm) usermap= WM_keymap_list_find(&U.user_keymaps, km->idname, km->spaceid, km->regionid); /* add */ - wm_keymap_patch_update(&wm->userconf->keymaps, defaultmap, addonmap, usermap); + kmn= wm_keymap_patch_update(&wm->userconf->keymaps, defaultmap, addonmap, usermap); + + if(kmn) { + kmn->modal_items= km->modal_items; + kmn->poll= km->poll; + } /* in case of old non-diff keymaps, force extra update to create diffs */ compat_update = compat_update || (usermap && !(usermap->flag & KEYMAP_DIFF)); -- cgit v1.2.3 From 0dea4df76442ffce1e0e7162fab103f6cca99b12 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sun, 7 Aug 2011 14:57:25 +0000 Subject: Changed do_version condition for noodle_curving. It should be re-set to 5 for files saved in 2.58.1 release. --- source/blender/editors/interface/resources.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index f3db6ad11ae..e71f709f89b 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1557,7 +1557,7 @@ void init_userdef_do_versions(void) U.autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET; } - if (bmain->versionfile < 258 || (bmain->versionfile == 258 && bmain->subversionfile < 1)) { + if (bmain->versionfile < 258 || (bmain->versionfile == 258 && bmain->subversionfile < 2)) { bTheme *btheme; for(btheme= U.themes.first; btheme; btheme= btheme->next) { btheme->tnode.noodle_curving = 5; -- cgit v1.2.3 From 3a55da7616fa5613b8a95a591059bb55102dbfb4 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 7 Aug 2011 17:01:44 +0000 Subject: removed old ndof transform code, to be replaced with modern stuff in 2.6 --- source/blender/editors/transform/CMakeLists.txt | 1 - source/blender/editors/transform/transform.c | 5 - source/blender/editors/transform/transform.h | 26 ---- .../blender/editors/transform/transform_generics.c | 1 - .../editors/transform/transform_ndofinput.c | 162 --------------------- source/blender/editors/transform/transform_ops.c | 7 +- 6 files changed, 2 insertions(+), 200 deletions(-) delete mode 100644 source/blender/editors/transform/transform_ndofinput.c (limited to 'source/blender') diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt index 283b09f42e4..e44cc1f5df3 100644 --- a/source/blender/editors/transform/CMakeLists.txt +++ b/source/blender/editors/transform/CMakeLists.txt @@ -41,7 +41,6 @@ set(SRC transform_generics.c transform_input.c transform_manipulator.c - transform_ndofinput.c transform_ops.c transform_orientations.c transform_snap.c diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 39e26bc6436..c1c812e8c68 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1006,11 +1006,6 @@ int transformEvent(TransInfo *t, wmEvent *event) else view_editmove(event->type); t->redraw= 1; break; -#if 0 - case NDOF_MOTION: - // should have been caught by tranform_modal - return OPERATOR_PASS_THROUGH; -#endif default: handled = 0; break; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index d8e42488787..485344875d4 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -67,14 +67,6 @@ struct wmTimer; struct ARegion; struct ReportList; -typedef struct NDofInput { - int flag; - int axis; - float fval[7]; - float factor[3]; -} NDofInput; - - /* The ctrl value has different meaning: 0 : No value has been typed @@ -273,7 +265,6 @@ typedef struct TransInfo { TransCon con; /* transformed constraint */ TransSnap tsnap; NumInput num; /* numerical input */ - NDofInput ndof; /* ndof input */ MouseInput mouse; /* mouse input */ char redraw; /* redraw flag */ float prop_size; /* proportional circle radius */ @@ -340,9 +331,6 @@ typedef struct TransInfo { /* ******************** Macros & Prototypes *********************** */ -/* NDOFINPUT FLAGS */ -#define NDOF_INIT 1 - /* transinfo->state */ #define TRANS_STARTING 0 #define TRANS_RUNNING 1 @@ -683,20 +671,6 @@ void calculatePropRatio(TransInfo *t); void getViewVector(TransInfo *t, float coord[3], float vec[3]); -/*********************** NDofInput ********************************/ - -void initNDofInput(NDofInput *n); -int hasNDofInput(NDofInput *n); -void applyNDofInput(NDofInput *n, float *vec); -int handleNDofInput(NDofInput *n, struct wmEvent *event); - -/* handleNDofInput return values */ -#define NDOF_REFRESH 1 -#define NDOF_NOMOVE 2 -#define NDOF_CONFIRM 3 -#define NDOF_CANCEL 4 - - /*********************** Transform Orientations ******************************/ void initTransformOrientation(struct bContext *C, TransInfo *t); diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index c81c398e696..306796efee9 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1165,7 +1165,6 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) setTransformViewMatrices(t); initNumInput(&t->num); - initNDofInput(&t->ndof); return 1; } diff --git a/source/blender/editors/transform/transform_ndofinput.c b/source/blender/editors/transform/transform_ndofinput.c deleted file mode 100644 index c5946163770..00000000000 --- a/source/blender/editors/transform/transform_ndofinput.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * $Id$ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is: all of this file. - * - * Contributor(s): Martin Poirier - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/editors/transform/transform_ndofinput.c - * \ingroup edtransform - */ - - - #include /* fabs */ -#include /* for sprintf */ - -#include "BLI_utildefines.h" - -#include "BKE_global.h" /* for G */ - /* ABS */ - -#include "WM_types.h" - -#include "transform.h" - -#if 0 -static int updateNDofMotion(NDofInput *n); // return 0 when motion is null -#endif -static void resetNDofInput(NDofInput *n); - -void initNDofInput(NDofInput *n) -{ - int i; - - n->flag = 0; - n->axis = 0; - - resetNDofInput(n); - - for(i = 0; i < 3; i++) - { - n->factor[i] = 1.0f; - } -} - -static void resetNDofInput(NDofInput *n) -{ - int i; - for(i = 0; i < 6; i++) - { - n->fval[i] = 0.0f; - } -} - - -int handleNDofInput(NDofInput *UNUSED(n), wmEvent *UNUSED(event)) -{ - int retval = 0; - // TRANSFORM_FIX_ME -#if 0 - switch(event) - { - case NDOFMOTION: - if (updateNDofMotion(n) == 0) - { - retval = NDOF_NOMOVE; - } - else - { - retval = NDOF_REFRESH; - } - break; - case NDOFBUTTON: - if (val == 1) - { - retval = NDOF_CONFIRM; - } - else if (val == 2) - { - retval = NDOF_CANCEL; - resetNDofInput(n); - n->flag &= ~NDOF_INIT; - } - break; - } -#endif - return retval; -} - -int hasNDofInput(NDofInput *n) -{ - return (n->flag & NDOF_INIT) == NDOF_INIT; -} - -void applyNDofInput(NDofInput *n, float *vec) -{ - if (hasNDofInput(n)) - { - int i, j; - - for (i = 0, j = 0; i < 6; i++) - { - if (n->axis & (1 << i)) - { - vec[j] = n->fval[i] * n->factor[j]; - j++; - } - } - } -} - -// TRANSFORM_FIX_ME -#if 0 - -static int updateNDofMotion(NDofInput *n) -{ - float fval[7]; - int i; - int retval = 0; - - getndof(fval); - - if (G.vd->ndoffilter) - filterNDOFvalues(fval); - - for(i = 0; i < 6; i++) - { - if (!retval && fval[i] != 0.0f) - { - retval = 1; - } - - n->fval[i] += fval[i] / 1024.0f; - } - - n->flag |= NDOF_INIT; - - return retval; -} -#endif - - - - diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 54e0b31e201..231293024f0 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -360,17 +360,14 @@ static int transform_modal(bContext *C, wmOperator *op, wmEvent *event) TransInfo *t = op->customdata; - #if 0 +#if 0 // stable 2D mouse coords map to different 3D coords while the 3D mouse is active // in other words, 2D deltas are no longer good enough! // disable until individual 'transformers' behave better if (event->type == NDOF_MOTION) - { - /* puts("transform_modal: passing through NDOF_MOTION"); */ return OPERATOR_PASS_THROUGH; - } - #endif +#endif /* XXX insert keys are called here, and require context */ t->context= C; -- cgit v1.2.3 From f12df1e3863ca2043947c64786e0f3c7f0fccca0 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 7 Aug 2011 17:22:47 +0000 Subject: ndof data change: operators can access values as vectors or components, as both are handy --- source/blender/windowmanager/WM_types.h | 10 +++++-- .../blender/windowmanager/intern/wm_event_system.c | 33 ++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 7fd52e89a5f..697133bb163 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -389,8 +389,14 @@ typedef struct wmNDOFMotionData { /* awfully similar to GHOST_TEventNDOFMotionData... */ // Each component normally ranges from -1 to +1, but can exceed that. // These use blender standard view coordinates, with positive rotations being CCW about the axis. - float tvec[3]; // translation - float rvec[3]; // rotation: + union { + float tvec[3]; // translation + struct { float tx, ty, tz; }; + }; + union { + float rvec[3]; // rotation: + struct { float rx, ry, rz; }; + }; // axis = (rx,ry,rz).normalized // amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg] float dt; // time since previous NDOF Motion event diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 258d6bbc025..c1fd903c479 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2329,29 +2329,32 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g const float s = U.ndof_sensitivity; - data->tvec[0]= s * ghost->tx; + data->tx = s * ghost->tx; - data->rvec[0]= s * ghost->rx; - data->rvec[1]= s * ghost->ry; - data->rvec[2]= s * ghost->rz; + data->rx = s * ghost->rx; + data->rx = s * ghost->ry; + data->rx = s * ghost->rz; if (U.ndof_flag & NDOF_ZOOM_UPDOWN) { - // rotate so Y is where Z was (maintain handed-ness) - data->tvec[1]= s * ghost->tz; - data->tvec[2]= s * -ghost->ty; - - // should this affect rotation also? - // initial guess is 'yes', but get user feedback immediately! -#if 0 // after turning this on, my guess becomes 'no' - data->rvec[1]= s * ghost->rz; - data->rvec[2]= s * ghost->ry; + /* rotate so Y is where Z was */ + data->ty = s * ghost->tz; + data->tz = s * ghost->ty; + /* maintain handed-ness? or just do what feels right? */ + + /* should this affect rotation also? + * initial guess is 'yes', but get user feedback immediately! + */ +#if 0 + /* after turning this on, my guess becomes 'no' */ + data->ry = s * ghost->rz; + data->rz = s * ghost->ry; #endif } else { - data->tvec[1]= s * ghost->ty; - data->tvec[2]= s * ghost->tz; + data->ty = s * ghost->ty; + data->tz = s * ghost->tz; } data->dt = ghost->dt; -- cgit v1.2.3 From 5681380db0f46ec16f942ecba9002061ce37b87d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 7 Aug 2011 17:38:36 +0000 Subject: simplify x11 path code, had unneeded NULL checks and std namespace --- source/blender/windowmanager/intern/wm_event_system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index c1fd903c479..413ff181f11 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2332,8 +2332,8 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g data->tx = s * ghost->tx; data->rx = s * ghost->rx; - data->rx = s * ghost->ry; - data->rx = s * ghost->rz; + data->ry = s * ghost->ry; + data->rz = s * ghost->rz; if (U.ndof_flag & NDOF_ZOOM_UPDOWN) { -- cgit v1.2.3 From 28ae6d85fee9ec32c7a16b9fa004ba6fef3d84f8 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 7 Aug 2011 18:57:39 +0000 Subject: fixed typo --- source/blender/makesrna/intern/rna_userdef.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 57044188dd9..a685c6deb34 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2769,7 +2769,7 @@ static void rna_def_userdef_input(BlenderRNA *brna) prop= RNA_def_property(srna, "ndof_orbit_invert_axes", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ndof_flag", NDOF_ORBIT_INVERT_AXES); RNA_def_property_ui_text(prop, "Invert Axes", "Toggle between moving the viewpoint or moving the scene being viewed"); - /* in 3Dx docs, this is called 'object mode' vs. 'target camera mode' + /* in 3Dx docs, this is called 'object mode' vs. 'target camera mode' */ /* 3D view: fly */ prop= RNA_def_property(srna, "ndof_lock_horizon", PROP_BOOLEAN, PROP_NONE); -- cgit v1.2.3 From 349c838996a5d042bb3ebb06162ab9b2c6716fdd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 8 Aug 2011 05:43:04 +0000 Subject: add missing header to cmake files (else some IDE's wont index it) --- source/blender/windowmanager/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender') diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 20ac3ba7077..dc83e29b497 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -67,6 +67,7 @@ set(SRC intern/wm_window.c WM_api.h + WM_keymap.h WM_types.h wm.h wm_cursors.h -- cgit v1.2.3 From cc0ec3aa33e09b964cc6f4d0c8d253671ebebf4a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 8 Aug 2011 08:22:01 +0000 Subject: fix [#28178] make single user copy of object data doesn't work --- source/blender/editors/include/ED_object.h | 2 +- .../editors/interface/interface_templates.c | 38 +++++++++++++--------- source/blender/editors/object/object_relations.c | 14 ++++++++ source/blender/makesrna/RNA_access.h | 1 + 4 files changed, 39 insertions(+), 16 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 28d0a9520b2..c646ec55506 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -108,7 +108,7 @@ int ED_object_add_generic_get_opts(struct bContext *C, struct wmOperator *op, fl struct Object *ED_object_add_type(struct bContext *C, int type, float *loc, float *rot, int enter_editmode, unsigned int layer); void ED_object_single_users(struct Main *bmain, struct Scene *scene, int full); - +void ED_object_single_user(struct Scene *scene, struct Object *ob); /* object motion paths */ void ED_objects_clear_paths(struct bContext *C); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 2d443bbfcd0..35125d1483e 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -53,6 +53,7 @@ #include "BKE_displist.h" #include "ED_screen.h" +#include "ED_object.h" #include "ED_render.h" #include "RNA_access.h" @@ -275,18 +276,28 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) break; case UI_ID_ALONE: if(id) { + const int do_scene_obj= (GS(id->name) == ID_OB) && + (template->ptr.type == &RNA_SceneObjects); + /* make copy */ - if(id_copy(id, &newid, 0) && newid) { - /* copy animation actions too */ - BKE_copy_animdata_id_action(id); - /* us is 1 by convention, but RNA_property_pointer_set - will also incremement it, so set it to zero */ - newid->us= 0; - - /* assign copy */ - RNA_id_pointer_create(newid, &idptr); - RNA_property_pointer_set(&template->ptr, template->prop, idptr); - RNA_property_update(C, &template->ptr, template->prop); + if(do_scene_obj) { + Scene *scene= CTX_data_scene(C); + ED_object_single_user(scene, (struct Object *)id); + WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene); + } + else { + if(id_copy(id, &newid, 0) && newid) { + /* copy animation actions too */ + BKE_copy_animdata_id_action(id); + /* us is 1 by convention, but RNA_property_pointer_set + will also incremement it, so set it to zero */ + newid->us= 0; + + /* assign copy */ + RNA_id_pointer_create(newid, &idptr); + RNA_property_pointer_set(&template->ptr, template->prop, idptr); + RNA_property_update(C, &template->ptr, template->prop); + } } } break; @@ -404,10 +415,7 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str sprintf(str, "%d", id->us); - if(id->us<10) - but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X,UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy."); - else - but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X+10,UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy."); + but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X + ((id->us < 10) ? 0:10), UI_UNIT_Y, NULL, 0, 0, 0, 0, "Displays number of users of this data. Click to make a single-user copy."); uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ALONE)); if(!id_copy(id, NULL, 1 /* test only */) || (idfrom && idfrom->lib) || !editable) diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 0fb7cf8b640..225e6e73563 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1402,6 +1402,20 @@ static void single_object_users(Scene *scene, View3D *v3d, int flag) set_sca_new_poins(); } +/* not an especially efficient function, only added so the single user + * button can be functional.*/ +void ED_object_single_user(Scene *scene, Object *ob) +{ + Base *base; + + for(base= FIRSTBASE; base; base= base->next) { + if(base->object == ob) base->flag |= OB_DONE; + else base->flag &= ~OB_DONE; + } + + single_object_users(scene, NULL, OB_DONE); +} + static void new_id_matar(Material **matar, int totcol) { ID *id; diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 882fbce9271..0033a1ff437 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -392,6 +392,7 @@ extern StructRNA RNA_Scene; extern StructRNA RNA_SceneGameData; extern StructRNA RNA_SceneRenderLayer; extern StructRNA RNA_SceneSequence; +extern StructRNA RNA_SceneObjects; extern StructRNA RNA_Scopes; extern StructRNA RNA_Screen; extern StructRNA RNA_ScrewModifier; -- cgit v1.2.3 From 24acf58fc47f1ed6132bcaa07b86b756e1b3194a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 8 Aug 2011 09:01:09 +0000 Subject: quiet harmless py resource warning - file opened but not closed. --- source/blender/editors/interface/interface_templates.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 35125d1483e..305a4a8b3d6 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -277,7 +277,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) case UI_ID_ALONE: if(id) { const int do_scene_obj= (GS(id->name) == ID_OB) && - (template->ptr.type == &RNA_SceneObjects); + (template->ptr.type == &RNA_SceneObjects); /* make copy */ if(do_scene_obj) { -- cgit v1.2.3 From 85b77c931d2de579671dbe68640341407f91ecb2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 8 Aug 2011 14:50:10 +0000 Subject: fix [#28183] Wavefront OBJ import has no preset saving --- .../blender/editors/interface/interface_layout.c | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 85cc944f03b..df654cf3645 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2745,6 +2745,25 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in uiItemL(layout, "* Redo Unsupported *", ICON_NONE); // XXX, could give some nicer feedback or not show redo panel at all? } + /* menu */ + if(op->type->flag & OPTYPE_PRESET) { + /* XXX, no simple way to get WM_MT_operator_presets.bl_label from python! Label remains the same always! */ + PointerRNA op_ptr; + uiLayout *row; + + row= uiLayoutRow(layout, TRUE); + uiItemM(row, (bContext *)C, "WM_MT_operator_presets", NULL, ICON_NONE); + + WM_operator_properties_create(&op_ptr, "WM_OT_operator_preset_add"); + RNA_string_set(&op_ptr, "operator", op->type->idname); + op_ptr= uiItemFullO(row, "WM_OT_operator_preset_add", "", ICON_ZOOMIN, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0); + + WM_operator_properties_create(&op_ptr, "WM_OT_operator_preset_add"); + RNA_string_set(&op_ptr, "operator", op->type->idname); + RNA_boolean_set(&op_ptr, "remove_active", 1); + op_ptr= uiItemFullO(row, "WM_OT_operator_preset_add", "", ICON_ZOOMOUT, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0); + } + if(op->type->ui) { op->layout= layout; op->type->ui((bContext*)C, op); @@ -2759,25 +2778,6 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); - /* menu */ - if(op->type->flag & OPTYPE_PRESET) { - /* XXX, no simple way to get WM_MT_operator_presets.bl_label from python! Label remains the same always! */ - PointerRNA op_ptr; - uiLayout *row; - - row= uiLayoutRow(layout, TRUE); - uiItemM(row, (bContext *)C, "WM_MT_operator_presets", NULL, ICON_NONE); - - WM_operator_properties_create(&op_ptr, "WM_OT_operator_preset_add"); - RNA_string_set(&op_ptr, "operator", op->type->idname); - op_ptr= uiItemFullO(row, "WM_OT_operator_preset_add", "", ICON_ZOOMIN, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0); - - WM_operator_properties_create(&op_ptr, "WM_OT_operator_preset_add"); - RNA_string_set(&op_ptr, "operator", op->type->idname); - RNA_boolean_set(&op_ptr, "remove_active", 1); - op_ptr= uiItemFullO(row, "WM_OT_operator_preset_add", "", ICON_ZOOMOUT, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0); - } - /* main draw call */ empty= uiDefAutoButsRNA(layout, &ptr, check_prop, label_align) == 0; -- cgit v1.2.3 From 2dfc51388c7f67a271a4765d2492ab3cb36c2814 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Tue, 9 Aug 2011 07:33:51 +0000 Subject: Blender 2.59: * Update the readme file * Update link to release logs, they point to http://www.blender.org/development/release-logs/blender-259/ now --- source/blender/windowmanager/intern/wm_operators.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index cea2d6b3fe5..610a962ba62 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1247,7 +1247,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar col = uiLayoutColumn(split, 0); uiItemL(col, "Links", ICON_NONE); uiItemStringO(col, "Donations", ICON_URL, "WM_OT_url_open", "url", "http://www.blender.org/blenderorg/blender-foundation/donation-payment/"); - uiItemStringO(col, "Release Log", ICON_URL, "WM_OT_url_open", "url", "http://www.blender.org/development/release-logs/blender-258/"); + uiItemStringO(col, "Release Log", ICON_URL, "WM_OT_url_open", "url", "http://www.blender.org/development/release-logs/blender-259/"); uiItemStringO(col, "Manual", ICON_URL, "WM_OT_url_open", "url", "http://wiki.blender.org/index.php/Doc:2.5/Manual"); uiItemStringO(col, "Blender Website", ICON_URL, "WM_OT_url_open", "url", "http://www.blender.org/"); uiItemStringO(col, "User Community", ICON_URL, "WM_OT_url_open", "url", "http://www.blender.org/community/user-community/"); // -- cgit v1.2.3 From 22694c993a7e32767db4719e9fa37e93445b66a8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 9 Aug 2011 14:50:40 +0000 Subject: fix [#28186] textboxes properties not animatable --- source/blender/makesrna/intern/rna_curve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c index 260d483b9d2..599d36ec8b8 100644 --- a/source/blender/makesrna/intern/rna_curve.c +++ b/source/blender/makesrna/intern/rna_curve.c @@ -651,7 +651,7 @@ static char *rna_TextBox_path(PointerRNA *ptr) int index= (int)(tb - cu->tb); if (index >= 0 && index < cu->totbox) - return BLI_sprintfN("textboxes[%d]", index); + return BLI_sprintfN("text_boxes[%d]", index); else return BLI_strdup(""); } -- cgit v1.2.3