Revision: 24047
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24047
Author:   eman
Date:     2009-10-22 05:22:44 +0200 (Thu, 22 Oct 2009)

Log Message:
-----------
* makenurbCurve 
 - Added stride into function declaration to match recent changes in 2.5 for 
Bevel
 - Should fix compile problem on linux
 - Stride var not currently respected, as nurbana only accepts float buffers 
and this expects BevPoint too
* Refine Surface
 - Modal operator based on loopcut
 - First draft, not finished
  - The UI will be refactored, it's currently clunky
  - Numerical input hasn't been ported over from 2.4 yet
  - Redo/tweak not hooked up

Modified Paths:
--------------
    branches/nurbs25/intern/nurbana/extern/nurbana.h
    branches/nurbs25/release/scripts/ui/space_view3d_toolbar.py
    branches/nurbs25/source/blender/blenkernel/intern/curve.c
    branches/nurbs25/source/blender/editors/curve/curve_intern.h
    branches/nurbs25/source/blender/editors/curve/curve_ops.c
    branches/nurbs25/source/blender/editors/curve/editcurve.c
    branches/nurbs25/source/blender/editors/space_view3d/drawobject.c

Modified: branches/nurbs25/intern/nurbana/extern/nurbana.h
===================================================================
--- branches/nurbs25/intern/nurbana/extern/nurbana.h    2009-10-22 03:12:44 UTC 
(rev 24046)
+++ branches/nurbs25/intern/nurbana/extern/nurbana.h    2009-10-22 03:22:44 UTC 
(rev 24047)
@@ -59,7 +59,7 @@
        nbReal y;
        nbReal z;
        nbReal H;
-       // This extra data makes nurbana struct compatible with blender
+       // This extra data makes nurbana struct compatible with blender BPoint
        float alfa, weight;             /* alfa: tilt in 3D View, weight: used 
for softbody goal weight */
        short f1, hide;
        float radius, pad;              /* user-set radius per point for 
bevelling etc */

Modified: branches/nurbs25/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/nurbs25/release/scripts/ui/space_view3d_toolbar.py 2009-10-22 
03:12:44 UTC (rev 24046)
+++ branches/nurbs25/release/scripts/ui/space_view3d_toolbar.py 2009-10-22 
03:22:44 UTC (rev 24047)
@@ -125,7 +125,7 @@
                col.itemO("curve.cyclic_toggle")
                col.itemO("curve.switch_direction")
                col.itemO("curve.spline_type_set")
-               
+
                col = layout.column(align=True)
                col.itemL(text="Handles:")
                col.item_enumO("curve.handle_type_set", "type", 'AUTOMATIC')
@@ -171,6 +171,7 @@
                col.itemO("curve.delete")
                col.itemO("curve.cyclic_toggle")
                col.itemO("curve.switch_direction")
+               col.itemO("curve.surface_refine")       
                
                col = layout.column(align=True)
                col.itemL(text="Modeling:")

Modified: branches/nurbs25/source/blender/blenkernel/intern/curve.c
===================================================================
--- branches/nurbs25/source/blender/blenkernel/intern/curve.c   2009-10-22 
03:12:44 UTC (rev 24046)
+++ branches/nurbs25/source/blender/blenkernel/intern/curve.c   2009-10-22 
03:22:44 UTC (rev 24047)
@@ -841,7 +841,7 @@
        NRB_getIsoPoints(nu->nurbanaPtr,data);
 }
 
-void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float 
*radius_array, int resolu)
+void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float 
*radius_array, int resolu, int stride)
 /* coord_array has to be 3*4*pntsu*resolu in size and zero-ed
  * tilt_array and radius_array will be written to if valid */
 {
@@ -877,6 +877,8 @@
        if(radius_array)
                printf("radius_array!\n");
 */
+
+       // FIXME eman 'stride' is currently ignored, as nurbana assumes float 
arrays.
        NRB_GenerateCurve(nu->nurbanaPtr,coord_array,tilt_array, radius_array, 
resolu);
 }
 

Modified: branches/nurbs25/source/blender/editors/curve/curve_intern.h
===================================================================
--- branches/nurbs25/source/blender/editors/curve/curve_intern.h        
2009-10-22 03:12:44 UTC (rev 24046)
+++ branches/nurbs25/source/blender/editors/curve/curve_intern.h        
2009-10-22 03:22:44 UTC (rev 24047)
@@ -82,6 +82,9 @@
 void CURVE_OT_smooth(struct wmOperatorType *ot);
 void CURVE_OT_smooth_radius(struct wmOperatorType *ot);
 
+// Nurbana operators
+void CURVE_OT_surface_refine(struct wmOperatorType *ot);
+
 void CURVE_OT_de_select_first(struct wmOperatorType *ot);
 void CURVE_OT_de_select_last(struct wmOperatorType *ot);
 void CURVE_OT_select_all_toggle(struct wmOperatorType *ot);

Modified: branches/nurbs25/source/blender/editors/curve/curve_ops.c
===================================================================
--- branches/nurbs25/source/blender/editors/curve/curve_ops.c   2009-10-22 
03:12:44 UTC (rev 24046)
+++ branches/nurbs25/source/blender/editors/curve/curve_ops.c   2009-10-22 
03:22:44 UTC (rev 24047)
@@ -77,6 +77,7 @@
        uiItemO(layout, NULL, 0, "CURVE_OT_radius_set");
        uiItemO(layout, NULL, 0, "CURVE_OT_smooth");
        uiItemO(layout, NULL, 0, "CURVE_OT_smooth_radius");
+       uiItemO(layout, NULL, 0, "CURVE_OT_surface_refine");
        uiPupMenuEnd(C, pup);
 
        return OPERATOR_CANCELLED;
@@ -137,6 +138,8 @@
        WM_operatortype_append(CURVE_OT_smooth);
        WM_operatortype_append(CURVE_OT_smooth_radius);
 
+       WM_operatortype_append(CURVE_OT_surface_refine);
+
        WM_operatortype_append(CURVE_OT_de_select_first);
        WM_operatortype_append(CURVE_OT_de_select_last);
        WM_operatortype_append(CURVE_OT_select_all_toggle);
@@ -247,6 +250,8 @@
        WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, 
KM_ALT|KM_CTRL, 0);
        RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, 
KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1);
 
+       WM_keymap_add_item(keymap, "CURVE_OT_surface_refine", YKEY, KM_PRESS, 
KM_SHIFT, 0);
+
        WM_keymap_add_item(keymap, "CURVE_OT_specials_menu", WKEY, KM_PRESS, 0, 
0);
 
        ED_object_generic_keymap(keyconf, keymap, TRUE);

Modified: branches/nurbs25/source/blender/editors/curve/editcurve.c
===================================================================
--- branches/nurbs25/source/blender/editors/curve/editcurve.c   2009-10-22 
03:12:44 UTC (rev 24046)
+++ branches/nurbs25/source/blender/editors/curve/editcurve.c   2009-10-22 
03:22:44 UTC (rev 24047)
@@ -77,6 +77,8 @@
 #include "ED_types.h"
 #include "ED_util.h"
 #include "ED_view3d.h"
+#include "ED_screen.h"
+#include "ED_space_api.h"
 
 #include "UI_interface.h"
 
@@ -84,10 +86,37 @@
 #include "RNA_define.h"
 
 #include "nurbana.h"
+#include "BIF_gl.h"
+#include "BIF_glutil.h" /* for paint cursor */
 
 /* still need to eradicate a few :( */
 #define callocstructN(x,y,name) (x*)MEM_callocN((y)* sizeof(x),name)
 
+typedef struct nurbsOpData {
+       ARegion *ar;            /* region that ringsel was activated in */
+       void *draw_handle;      /* for drawing preview loop */
+
+       //float (*edges)[2][3];
+       //int totedge;
+
+       ViewContext vc;
+
+       Object *ob;
+       Nurb *nu;
+       //EditMesh *em;
+       //EditEdge *eed;
+       
+       short direction;
+       short direction_confirmed;
+       short mval_old[2];
+       int size[2];
+       float* buffer[2];//U, bufferV;
+       float index;
+       float newKnotVal;
+       //int extend;
+       //int do_cut;
+} nurbsOpData;
+
 float nurbcircle[8][2]= {
        {0.0, -1.0}, {-1.0, -1.0}, {-1.0, 0.0}, {-1.0,  1.0},
        {0.0,  1.0}, { 1.0,  1.0}, { 1.0, 0.0}, { 1.0, -1.0}
@@ -1371,6 +1400,242 @@
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/*************************************************************/
+/******************* nurbana functions ***********************/
+/*************************************************************/
+
+/******************* Surface refine operator ******************/
+static void surface_refine_cleanup(bContext *C, wmOperator *op)
+{
+       nurbsOpData *lcd= op->customdata;
+
+       MEM_freeN(lcd->buffer[0]);
+       MEM_freeN(lcd->buffer[1]);
+       /* deactivate the extra drawing stuff in 3D-View */
+       ED_region_draw_cb_exit(lcd->ar->type, lcd->draw_handle);
+}
+static int surface_refine_cancel (bContext *C, wmOperator *op)
+{
+       surface_refine_cleanup(C,op);
+       return OPERATOR_CANCELLED;
+}
+
+
+static void draw_surface_curve(const bContext *C, ARegion *ar, void *arg)
+{
+       float *buffer = NULL;
+       int size = 0;
+       int i=0;
+       float index = 0.3;
+
+       nurbsOpData *lcd = arg;
+       
+       Object *obedit= CTX_data_edit_object(C);
+       ListBase *editnurb= curve_get_editcurve(obedit);
+       Nurb *nu = lcd->nu;
+
+       size = nu->pntsv * nu->resolv;
+
+       buffer = lcd->buffer[lcd->direction];
+       size = lcd->size[lcd->direction];
+
+       if(!lcd->direction_confirmed)
+       {
+               
NRB_GenerateCurveOnSurface(nu->nurbanaPtr,buffer,0,0.5,lcd->direction,3);
+               glPushMatrix();   
+
+               // Draw selected part of the surface
+               glColor3ub(255, 0, 0);
+
+               glBegin(GL_LINE_STRIP);
+               for(i = 0; i < size*3; i+=3)
+                       glVertex3f(buffer[i],buffer[i+1],buffer[i+2]);
+               if (nu->flagv & CU_CYCLIC)
+                       glVertex3f(buffer[0],buffer[1],buffer[2]);
+               glEnd(); 
+
+               glPopMatrix();  
+       }
+       else
+       {
+               float largestKnot,smallestKnot;
+       
+               largestKnot = 
NRB_getLastKnotValue(nu->nurbanaPtr,lcd->direction);
+               smallestKnot = 
NRB_getFirstKnotValue(nu->nurbanaPtr,lcd->direction);
+
+               
NRB_GenerateCurveOnSurface(nu->nurbanaPtr,buffer,0,lcd->index,lcd->direction,0);
+         
+               glPushMatrix();   
+               glMultMatrixf(lcd->ob->obmat);
+
+               // Draw selected part of the surface
+               glColor3ub(0, 255, 0);
+
+               glBegin(GL_LINE_STRIP);
+               for(i = 0; i < size*3; i+=3)
+                       glVertex3f(buffer[i],buffer[i+1],buffer[i+2]);
+               if (nu->flagv & CU_CYCLIC)
+                       glVertex3f(buffer[0],buffer[1],buffer[2]);
+               glEnd(); 
+
+               glPopMatrix();
+       }
+}
+
+static int surface_refine_modal (bContext *C, wmOperator *op, wmEvent *event)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       ListBase *editnurb= curve_get_editcurve(obedit);
+       Nurb *nu;
+       nurbsOpData *lcd = op->customdata;
+
+       nu = lcd->nu;
+
+       lcd->vc.mval[0] = event->mval[0];
+       lcd->vc.mval[1] = event->mval[1];
+
+       view3d_operator_needs_opengl(C);
+       switch (event->type) {
+               case LEFTMOUSE: /* confirm */ // XXX hardcoded
+                       if (event->val == KM_RELEASE) {
+                               if(!lcd->direction_confirmed)
+                                       lcd->direction_confirmed = 1;
+                               else
+                               {
+                                       BPoint *bp;
+                                       int a,b;
+                                       
NRB_KnotInsert(nu->nurbanaPtr,&lcd->newKnotVal,1,lcd->direction);//NRB_Refine(nu->nurbanaPtr,
 1, 1);//FIXME nbReal *X, int r, bool UV) ;
+                                       bp= nu->bp;
+                                       for(a=0; a<nu->pntsv; a++) {
+                                               for(b=0; b<nu->pntsu; b++) {
+                                                       bp->f1 |= SELECT;
+                                                       bp++;
+                                               }
+                                       }
+                                       ED_region_tag_redraw(lcd->ar);
+                                       surface_refine_cleanup(C, op);
+                                       return OPERATOR_FINISHED;
+                               }
+                       }
+                       break;
+               case RIGHTMOUSE: /* abort */ // XXX hardcoded
+               case ESCKEY:
+                       if (event->val == KM_RELEASE) {
+                               /* finish */
+                               surface_refine_cleanup(C, op);
+                               return OPERATOR_FINISHED;
+                               
+                       }
+                       ED_region_tag_redraw(lcd->ar);
+                       break;
+
+               case MOUSEMOVE: { 
+                       float epsilon = 2.5;
+                       int a,b;
+
+                       if(!lcd->direction_confirmed)
+                       {
+                               a = abs(lcd->mval_old[0]-event->mval[0])+1;
+                               b = abs(lcd->mval_old[1]-event->mval[1])+1;
+
+                               // Detect which direction the mouse is mostly 
moving in
+                               if(b && (a / (float)b) > epsilon)
+                                       lcd->direction = 1; //printf("moving 
horizontal\n");
+                               else if (a && (b / (float)a) > epsilon)
+                                       lcd->direction = 0; //printf("moving 
vertical\n");
+                       }
+                       else
+                       {
+                               float index = lcd->index;
+
+                               float largestKnot,smallestKnot;
+
+                               //float newKnotVal = 0;
+
+                               largestKnot = 
NRB_getLastKnotValue(nu->nurbanaPtr, lcd->direction);
+                               smallestKnot = 
NRB_getFirstKnotValue(nu->nurbanaPtr, lcd->direction);
+                               index -= (lcd->mval_old[lcd->direction] - 
event->mval[lcd->direction])/100.0;
+                               if(index > 1)
+                                       index = 1;
+                               if(index < 0)
+                                       index = 0;
+                               lcd->newKnotVal = smallestKnot + ((largestKnot 
- smallestKnot)*index);
+                               printf("small big index knot %f %f %f 
%f\n",smallestKnot,largestKnot,index,lcd->newKnotVal);
+                               lcd->index = index;

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to