Revision: 39112
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39112
Author:   psy-fi
Date:     2011-08-07 01:35:35 +0000 (Sun, 07 Aug 2011)
Log Message:
-----------
Smooth uv brush
=================
-Some operator custom data defined
-Code made so far to get a feel for how brushes handle coordinates in uv 
editor. A minor problem with brush size remains.
-Better poll function for uv smooth brushes (could be used for objecs other 
than meshes causing crashes)
-a few warning fixes

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h
    branches/soc-2011-onion/source/blender/editors/include/ED_sculpt.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c

Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h       
2011-08-06 23:25:13 UTC (rev 39111)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h       
2011-08-07 01:35:35 UTC (rev 39112)
@@ -47,6 +47,9 @@
 struct PBVH;
 struct Scene;
 struct StrokeCache;
+struct PaintPersistentBase;
+struct PaintSessionMeshcache;
+struct PaintSessionTexcache;
 
 void paint_init(struct Paint *p, int ob_mode);
 void free_paint(struct Paint *p);

Modified: branches/soc-2011-onion/source/blender/editors/include/ED_sculpt.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/include/ED_sculpt.h  
2011-08-06 23:25:13 UTC (rev 39111)
+++ branches/soc-2011-onion/source/blender/editors/include/ED_sculpt.h  
2011-08-07 01:35:35 UTC (rev 39112)
@@ -38,6 +38,7 @@
 struct RegionView3D;
 struct wmKeyConfig;
 struct wmWindowManager;
+struct ViewContext;
 
 /* sculpt.c */
 void ED_operatortypes_sculpt(void);

Modified: 
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c   
2011-08-06 23:25:13 UTC (rev 39111)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c   
2011-08-07 01:35:35 UTC (rev 39112)
@@ -51,6 +51,7 @@
 #include "BLI_memarena.h"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
+#include "BLI_editVert.h"
 
 #include "PIL_time.h"
 
@@ -89,6 +90,7 @@
 #include "ED_screen.h"
 #include "ED_sculpt.h"
 #include "ED_view3d.h"
+#include "ED_mesh.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -4541,14 +4543,20 @@
 
 static int uv_smooth_brush_poll(const bContext *C)
 {
+       EditMesh *em;
+       int ret;
        Object *obedit = CTX_data_edit_object(C);
        SpaceImage *sima= CTX_wm_space_image(C);
        ToolSettings *toolsettings = CTX_data_scene(C)->toolsettings;
 
-       if(!uv_smooth_brush(C) || !obedit)
+       if(!uv_smooth_brush(C) || !obedit || obedit->type != OB_MESH)
                return 0;
 
-       if(sima) {
+       em = BKE_mesh_get_editmesh(obedit->data);
+       ret = EM_texFaceCheck(em);
+       BKE_mesh_end_editmesh(obedit->data, em);
+
+       if(ret && sima) {
                ARegion *ar= CTX_wm_region(C);
                if((toolsettings->use_uv_smooth) && 
ar->regiontype==RGN_TYPE_WINDOW)
                        return 1;
@@ -5011,7 +5019,7 @@
        RNA_def_collection_runtime(ot->srna, "stroke", 
&RNA_OperatorStrokeElement, "Stroke", "");
 }
 
-static int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
+int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
 {
        RegionView3D *rv3d= CTX_wm_region_view3d(C);
 

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c      
2011-08-06 23:25:13 UTC (rev 39111)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c      
2011-08-07 01:35:35 UTC (rev 39112)
@@ -38,16 +38,20 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_editVert.h"
 
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_brush_types.h"
+#include "DNA_meshdata_types.h"
 
 #include "BKE_brush.h"
+#include "BKE_paint.h"
 #include "BKE_context.h"
 #include "BKE_main.h"
 #include "BKE_depsgraph.h"
 #include "BKE_mesh.h"
+#include "BKE_customdata.h"
 
 #include "ED_screen.h"
 
@@ -60,15 +64,67 @@
 
 #include "paint_intern.h"
 
+#include "UI_view2d.h"
+
+typedef struct UvAdjacencyElement {
+       /* pointer to original uv of MTFace */
+       float *uv[2];
+       /* similar to uvvertmaps, holds the next uv corresponding to the vertex 
*/
+       struct UvAdjacencyElement *next;
+} UvAdjacencyElement;
+
+typedef struct UvAdjacencyEdge {
+       UvAdjacencyElement *uv1;
+       UvAdjacencyElement *uv2;
+}UvAdjacencyEdge;
+
+/* custom data for uv smoothing brush */
 typedef struct SmoothBrushData{
+       /* All uvs of the mesh */
+       UvAdjacencyElement *uvs;
+
+       /* Contains pointers to the first of each set of coincident uvs.
+        * These will be used to perform smoothing on and propagate the changes
+        * to their coincident uvs */
+       UvAdjacencyElement **uvCoincidentBases;
+
+       /* Edges used for adjacency info, used with laplacian smoothing */
+       UvAdjacencyEdge *uvedges;
+
        /* Timer to be used for airbrush-type brush */
        wmTimer *timer;
+
+       /* uvsmooth Paint for fast reference */
+       Paint *uvpaint
 }SmoothBrushData;
 
 
-static void uv_smooth_stroke_apply(bContext *C, wmOperator *op, wmEvent *event)
+static void uv_smooth_stroke_apply(bContext *C, wmOperator *op, wmEvent 
*event, Object *obedit)
 {
-       printf("little ducks\n");
+       float co[2], radius;
+       ARegion *ar= CTX_wm_region(C);
+       EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
+       EditFace *efa;
+       SmoothBrushData *smoothbrushdata = (SmoothBrushData *)op->customdata;
+
+       UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], 
&co[0], &co[1]);
+
+       radius = brush_size(paint_brush(smoothbrushdata->uvpaint));
+       //ED_space_image_size(sima, &width, &height);
+
+       for(efa = em->faces.first; efa; efa= efa->next){
+               int nverts, i;
+               MTFace *mt = CustomData_em_get(&em->fdata, efa->data, 
CD_MTFACE);
+               nverts = efa->v4 ? 4 : 3;
+
+               for(i = 0; i < nverts; i++)
+               {
+                       //if()
+               }
+       }
+       /* for tradition's sake */
+       printf("little ducks coords: %f %f, brush size: %f\n", co[0], co[1], 
radius);
+       BKE_mesh_end_editmesh(obedit->data, em);
 }
 
 
@@ -82,29 +138,29 @@
        op->customdata = NULL;
 }
 
-static int uv_smooth_stroke_init(bContext *UNUSED(C), wmOperator *op)
+static SmoothBrushData *uv_smooth_stroke_init(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
+       ToolSettings *ts = scene->toolsettings;
        SmoothBrushData *data = MEM_mallocN(sizeof(*data), "UV Smooth Brush 
Data");
-       if(data)
-       {
-               op->customdata = data;
-               return 1;
+       op->customdata = data;
+       if(data){
+               data->uvpaint = &ts->uvsmooth->paint;
        }
-       else
-               return 0;
+       return op->customdata;
 }
 
 static int uv_smooth_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        SmoothBrushData *data;
+       Object *obedit = CTX_data_edit_object(C);
 
-       if(!uv_smooth_stroke_init(C, op)) {
+       if(!(data = uv_smooth_stroke_init(C, op))) {
                return OPERATOR_CANCELLED;
        }
 
-       uv_smooth_stroke_apply(C, op, event);
+       uv_smooth_stroke_apply(C, op, event, obedit);
 
-       data = op->customdata;
        data->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), 
TIMER, 0.01f);
 
        if(!data->timer){
@@ -118,10 +174,12 @@
 
 static int uv_smooth_stroke_exec(bContext *C, wmOperator *op)
 {
+       Object *obedit = CTX_data_edit_object(C);
+
        if(!uv_smooth_stroke_init(C, op)) {
                return OPERATOR_CANCELLED;
        }
-//     uv_smooth_stroke_apply(C, op, event);
+//     uv_smooth_stroke_apply(C, op, event, obedit);
 
        uv_smooth_stroke_exit(C, op);
        return OPERATOR_FINISHED;
@@ -140,11 +198,11 @@
                        return OPERATOR_FINISHED;
                case MOUSEMOVE:
                case INBETWEEN_MOUSEMOVE:
-                       uv_smooth_stroke_apply(C, op, event);
+                       uv_smooth_stroke_apply(C, op, event, obedit);
                        break;
                case TIMER:
                        if(event->customdata == data->timer)
-                               uv_smooth_stroke_apply(C, op, event);
+                               uv_smooth_stroke_apply(C, op, event, obedit);
                        break;
                default:
                        return OPERATOR_RUNNING_MODAL;

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

Reply via email to