Commit: a75321650761b6d774104a815f52a335a10f4169
Author: Nicholas Bishop
Date:   Thu Jan 22 20:02:51 2015 +0100
Branches: cycles-ptex-19
https://developer.blender.org/rBa75321650761b6d774104a815f52a335a10f4169

Texpaint beginning

===================================================================

M       source/blender/editors/sculpt_paint/paint_image_proj.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 3e67501..ec57cd8 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -222,6 +222,9 @@ typedef struct ProjPaintState {
        MTFace         **dm_mtface_clone;    /* other UV map, use for cloning 
between layers */
        MTFace         *dm_mtface_stencil;
 
+       /* TODO */
+       MTFace *dm_mtface_ptex;
+
        Image *stencil_ima;
        Image *canvas_ima;
        Image *clone_ima;
@@ -3042,7 +3045,11 @@ static void project_paint_begin(ProjPaintState *ps)
 
        const int diameter = 2 * BKE_brush_size_get(ps->scene, ps->brush);
 
-       bool reset_threads = false;
+       bool reset_threads = true;
+
+       Mesh *me = ps->ob->data;
+       MLoopPtex *loop_ptex = CustomData_get_layer(&me->ldata, CD_LOOP_PTEX);
+       MTessFacePtex *tess_ptex = NULL;
 
        /* ---- end defines ---- */
 
@@ -3073,7 +3080,8 @@ static void project_paint_begin(ProjPaintState *ps)
                ps->dm_release = true;
        }
 
-       if (!CustomData_has_layer(&ps->dm->faceData, CD_MTFACE)) {
+       if (!CustomData_has_layer(&ps->dm->faceData, CD_MTFACE) &&
+               !CustomData_has_layer(&ps->dm->faceData, CD_TESSFACE_PTEX)) {
 
                if (ps->dm_release)
                        ps->dm->release(ps->dm);
@@ -3087,9 +3095,15 @@ static void project_paint_begin(ProjPaintState *ps)
        ps->dm_totvert = ps->dm->getNumVerts(ps->dm);
        ps->dm_totface = ps->dm->getNumTessFaces(ps->dm);
 
+       tess_ptex = ps->dm->getTessFaceDataArray(ps->dm, CD_TESSFACE_PTEX);
        ps->dm_mvert = ps->dm->getVertArray(ps->dm);
        ps->dm_mface = ps->dm->getTessFaceArray(ps->dm);
        ps->dm_mtface = MEM_mallocN(ps->dm_totface * sizeof(MTFace *), 
"proj_paint_mtfaces");
+       // TODO
+       if (CustomData_has_layer(&ps->dm->faceData, CD_TESSFACE_PTEX)) {
+               ps->dm_mtface_ptex = MEM_callocN(ps->dm_totface * 
sizeof(*ps->dm_mtface_ptex),
+                                                                               
 "ProjPaintState.dm_mtface_ptex");
+       }
 
        if (ps->do_face_sel) {
                index_mf_to_mpoly = ps->dm->getTessFaceDataArray(ps->dm, 
CD_ORIGINDEX);
@@ -3422,6 +3436,8 @@ static void project_paint_begin(ProjPaintState *ps)
                        slot = project_paint_face_paint_slot(ps, face_index);
                        /* all faces should have a valid slot, reassert here */
                        if (slot == NULL) {
+                               // TODO
+                               BLI_assert(!"Ptex TODO");
                                tf_base = 
CustomData_get_layer(&ps->dm->faceData, CD_MTFACE);
                                tpage = ps->canvas_ima;
                        }
@@ -3432,6 +3448,12 @@ static void project_paint_begin(ProjPaintState *ps)
                                        slot_last = slot;
                                }
 
+                               // TODO
+                               if (loop_ptex) {
+                                       slot->ima = loop_ptex->image;
+                                       tf_base = ps->dm_mtface_ptex;
+                               }
+
                                /* don't allow using the same inage for 
painting and stencilling */
                                if (slot->ima == ps->stencil_ima)
                                        continue;
@@ -3444,6 +3466,26 @@ static void project_paint_begin(ProjPaintState *ps)
                }
 
                *tf = tf_base + face_index;
+               // TODO
+               if (ps->dm_mtface_ptex) {
+                       ImBuf *ibuf = BKE_image_acquire_ibuf(slot->ima, NULL, 
NULL);
+                       if (ibuf && ibuf->ptex_coords) {
+                               // I'm sleepy                           
+                               int abc;
+                               for (abc = 0; abc < 4; abc++) {
+                                       float *dst = (*tf)->uv[abc];
+                                       const MLoopPtexUV *src = 
&tess_ptex[face_index].corners[abc];
+                                       const float *pc = 
ibuf->ptex_coords[src->id];
+
+                                       copy_v2_v2(dst, src->uv);
+                                       mul_v2_v2(dst, pc + 2);
+                                       add_v2_v2(dst, pc);
+                                       dst[0] /= ibuf->x;
+                                       dst[1] /= ibuf->y;
+                               }
+                       }
+                       BKE_image_release_ibuf(slot->ima, ibuf, NULL);
+               }
 
                if (ps->do_layer_clone) {
                        if (ps->do_material_slots) {
@@ -3629,6 +3671,10 @@ static void project_paint_end(ProjPaintState *ps)
                BLI_spin_end(ps->tile_lock);
                MEM_freeN((void *)ps->tile_lock);
        }
+       if (ps->dm_mtface_ptex) {
+               MEM_freeN(ps->dm_mtface_ptex);
+               ps->dm_mtface_ptex = NULL;
+       }
        image_undo_end_locks();
 
 #ifndef PROJ_DEBUG_NOSEAMBLEED
@@ -5068,6 +5114,12 @@ bool BKE_paint_proj_mesh_data_check(Scene *scene, Object 
*ob, bool *uvs, bool *m
 
        if (layernum == 0) {
                hasuvs = false;
+
+               layernum = CustomData_number_of_layers(&me->ldata, 
CD_LOOP_PTEX);
+
+               if (layernum) {
+                       hasuvs = true;
+               }
        }
 
        /* Make sure we have a stencil to paint on! */

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

Reply via email to