[Bf-blender-cvs] [8f81f27] cycles-ptex-12: Texpaint beginning
Nicholas Bishop
noreply at git.blender.org
Mon Jan 26 02:05:11 CET 2015
Commit: 8f81f275a45c2639f1f6b24820254192fb0ad5ee
Author: Nicholas Bishop
Date: Thu Jan 22 20:02:51 2015 +0100
Branches: cycles-ptex-12
https://developer.blender.org/rB8f81f275a45c2639f1f6b24820254192fb0ad5ee
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..c09f557 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -2839,7 +2839,11 @@ static void project_bucket_init(const ProjPaintState *ps, const int thread_index
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, &tmpibuf, ima->tpageflag & IMA_CLAMP_U, ima->tpageflag & IMA_CLAMP_V);
+ project_paint_face_init(ps, thread_index, bucket_index,
+ GET_INT_FROM_POINTER(node->link), 0,
+ bucket_bounds, ibuf, &tmpibuf,
+ ima ? ima->tpageflag & IMA_CLAMP_U : 0,
+ ima ? ima->tpageflag & IMA_CLAMP_V : 0);
}
}
else {
@@ -3003,6 +3007,8 @@ static void project_paint_delayed_face_init(ProjPaintState *ps, const MFace *mf,
/* run once per stroke before projection painting */
static void project_paint_begin(ProjPaintState *ps)
{
+ int ptex;
+
/* Viewport vars */
float mat[3][3];
@@ -3042,7 +3048,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 +3083,9 @@ 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(&(((Mesh *)ps->ob->data)->ldata),
+ CD_LOOP_PTEX)) {
if (ps->dm_release)
ps->dm->release(ps->dm);
@@ -3087,6 +3099,7 @@ 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");
@@ -3432,6 +3445,9 @@ static void project_paint_begin(ProjPaintState *ps)
slot_last = slot;
}
+ // TODO
+ slot->ima = loop_ptex->image;
+
/* don't allow using the same inage for painting and stencilling */
if (slot->ima == ps->stencil_ima)
continue;
@@ -3443,7 +3459,27 @@ static void project_paint_begin(ProjPaintState *ps)
tpage = ps->stencil_ima;
}
- *tf = tf_base + face_index;
+ //*tf = tf_base + face_index;
+ *tf = MEM_callocN(sizeof(MTFace), "bad");
+ {
+ 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) {
@@ -3469,9 +3505,9 @@ static void project_paint_begin(ProjPaintState *ps)
}
/* tfbase here should be non-null! */
- BLI_assert (tf_base != NULL);
+ //BLI_assert (tf_base != NULL);
- if (is_face_sel && tpage) {
+ if (is_face_sel/* && tpage*/) {
const float *v1coSS, *v2coSS, *v3coSS, *v4coSS = NULL;
v1coSS = ps->screenCoords[mf->v1];
@@ -3557,7 +3593,7 @@ static void project_paint_begin(ProjPaintState *ps)
tpage_last = tpage;
}
- if (image_index != -1) {
+ /*if (image_index != -1)*/ {
/* Initialize the faces screen pixels */
/* Add this to a list to initialize later */
project_paint_delayed_face_init(ps, mf, face_index);
@@ -3565,14 +3601,29 @@ static void project_paint_begin(ProjPaintState *ps)
}
}
+ // TODO, ptex testing
+ //ps->image_tot++;
+
/* build an array of images we use*/
projIma = ps->projImages = (ProjPaintImage *)BLI_memarena_alloc(arena, sizeof(ProjPaintImage) * ps->image_tot);
- for (node = image_LinkList, i = 0; node; node = node->next, i++, projIma++) {
+ ptex = 1;
+ for (node = image_LinkList, i = 0; node || ptex; node = node->next, i++, projIma++) {
int size;
- projIma->ima = node->link;
- projIma->touch = 0;
+ if (ptex) {
+ Mesh *me = ps->ob->data;
+ MLoopPtex *loop_ptex;
+ memset(projIma, 0, sizeof(*projIma));
+ loop_ptex = CustomData_get_layer(&me->ldata, CD_LOOP_PTEX);
+ if (loop_ptex) {
+ projIma->ima = loop_ptex->image;
+ }
+ }
+ else {
+ projIma->ima = node->link;
+ }
projIma->ibuf = BKE_image_acquire_ibuf(projIma->ima, NULL, NULL);
+ projIma->touch = 0;
size = sizeof(void **) * IMAPAINT_TILE_NUMBER(projIma->ibuf->x) * IMAPAINT_TILE_NUMBER(projIma->ibuf->y);
projIma->partRedrawRect = BLI_memarena_alloc(arena, sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
memset(projIma->partRedrawRect, 0, sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
@@ -3582,6 +3633,8 @@ static void project_paint_begin(ProjPaintState *ps)
memset(projIma->maskRect, 0, size);
projIma->valid = (bool **) BLI_memarena_alloc(arena, size);
memset(projIma->valid, 0, size);
+
+ break;
}
/* we have built the array, discard the linked list */
@@ -5068,6 +5121,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! */
More information about the Bf-blender-cvs
mailing list