[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39317] branches/soc-2011-onion: Revision: 30911
Jason Wilkins
Jason.A.Wilkins at gmail.com
Fri Aug 12 05:16:58 CEST 2011
Revision: 39317
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39317
Author: jwilkins
Date: 2011-08-12 03:16:55 +0000 (Fri, 12 Aug 2011)
Log Message:
-----------
Revision: 30911
Author: nicholasbishop
Date: 5:10:34 PM, Friday, July 30, 2010
Message:
== VPaint ==
* Added an operator to convert vcols to texture; works for multires vcols too
* Still has some seam issues, need to do more intelligent bleeding
* Current UI is a menu item in the Image menu (Vertex Colors to Texture)
----
Modified : /branches/soc-2010-nicolasbishop/release/scripts/ui/space_image.py
Modified : /branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_math_geom.h
Modified : /branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
Modified : /branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
Modified : /branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ops.c
Modified : /branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
jwilkins:
fixed a bug that would allow uv coordinates that are out of range of the image to cause operator to reference memory outside the imbuf
Modified Paths:
--------------
branches/soc-2011-onion/release/scripts/startup/bl_ui/space_image.py
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_ops.c
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c
Modified: branches/soc-2011-onion/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- branches/soc-2011-onion/release/scripts/startup/bl_ui/space_image.py 2011-08-12 02:23:06 UTC (rev 39316)
+++ branches/soc-2011-onion/release/scripts/startup/bl_ui/space_image.py 2011-08-12 03:16:55 UTC (rev 39317)
@@ -147,10 +147,12 @@
layout.operator("image.pack", text="Pack As PNG").as_png = True
layout.separator()
-
layout.prop(sima, "use_image_paint")
+ layout.separator()
+ layout.operator("paint.vertex_colors_to_texture")
+
class IMAGE_MT_image_invert(bpy.types.Menu):
bl_label = "Invert"
Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h 2011-08-12 02:23:06 UTC (rev 39316)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h 2011-08-12 03:16:55 UTC (rev 39317)
@@ -240,6 +240,7 @@
void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot);
void PAINT_OT_vpaint_stroke(struct wmOperatorType *ot);
+void PAINT_OT_vertex_colors_to_texture(struct wmOperatorType *ot);
unsigned int vpaint_get_current_col(struct VPaint *vp);
Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c 2011-08-12 02:23:06 UTC (rev 39316)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c 2011-08-12 03:16:55 UTC (rev 39317)
@@ -34,10 +34,6 @@
#include "paint_stroke.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#include "MEM_guardedalloc.h"
#include "DNA_material_types.h"
@@ -516,11 +512,6 @@
return 0;
}
-typedef enum {
- LAYER_ADDED,
- LAYER_REMOVED
-} PaintMaskLayerOp;
-
static int mask_layer_poll(bContext *C)
{
return mask_poll(C) && ED_mesh_layers_poll(C);
Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_ops.c 2011-08-12 02:23:06 UTC (rev 39316)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_ops.c 2011-08-12 03:16:55 UTC (rev 39317)
@@ -401,6 +401,7 @@
WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
WM_operatortype_append(PAINT_OT_vpaint_stroke);
WM_operatortype_append(PAINT_OT_vertex_color_set);
+ WM_operatortype_append(PAINT_OT_vertex_colors_to_texture);
/* face-select */
WM_operatortype_append(PAINT_OT_face_select_linked);
Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c 2011-08-12 02:23:06 UTC (rev 39316)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c 2011-08-12 03:16:55 UTC (rev 39317)
@@ -77,6 +77,7 @@
#include "BKE_displist.h"
#include "BKE_dmgrid.h"
#include "BKE_global.h"
+#include "BKE_image.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_multires.h"
@@ -2678,6 +2679,218 @@
+/**** convert vertex colors to texture ****/
+static void vcol_to_tex_tri(ImBuf *ibuf,
+ float uv1[2], float uv2[2], float uv3[3],
+ float col1[3], float col2[3], float col3[3])
+{
+ /* ibuf coords */
+ float t[3][2];
+ float co[2];
+ rctf r;
+ int i;
+
+ t[0][0]= uv1[0] * ibuf->x;
+ t[0][1]= uv1[1] * ibuf->y;
+ t[1][0]= uv2[0] * ibuf->x;
+ t[1][1]= uv2[1] * ibuf->y;
+ t[2][0]= uv3[0] * ibuf->x;
+ t[2][1]= uv3[1] * ibuf->y;
+
+ r.xmin = MIN3(t[0][0], t[1][0], t[2][0]);
+ r.xmax = MAX3(t[0][0], t[1][0], t[2][0]);
+ r.ymin = MIN3(t[0][1], t[1][1], t[2][1]);
+ r.ymax = MAX3(t[0][1], t[1][1], t[2][1]);
+
+ /* expand by a pixel */
+ for(i = 0; i < 3; ++i) {
+ if(r.xmin == t[i][0])
+ --t[i][0];
+ if(r.xmax == t[i][0])
+ ++t[i][0];
+ if(r.ymin == t[i][1])
+ --t[i][1];
+ if(r.ymax == t[i][1])
+ ++t[i][1];
+ }
+
+ r.xmin = (int)round(r.xmin) - 2;
+ r.xmax = (int)round(r.xmax) + 2;
+ r.ymin = (int)round(r.ymin) - 2;
+ r.ymax = (int)round(r.ymax) + 2;
+
+ for(co[1] = r.ymin; co[1] <= r.ymax; ++co[1]) {
+ for(co[0] = r.xmin; co[0] <= r.xmax; ++co[0]) {
+ if(isect_point_tri_v2(co, t[0], t[1], t[2])) {
+ float w[3], col[3];
+ int offset = ibuf->x * co[1] + co[0];
+
+ if (offset < 0 || offset >= (ibuf->x * ibuf->y))
+ continue;
+
+ barycentric_weights_v2(t[0], t[1], t[2], co, w);
+ interp_v3_v3v3v3(col, col1, col2, col3, w);
+
+ if(ibuf->rect_float) {
+ copy_v3_v3(ibuf->rect_float + offset*4,
+ col);
+ }
+ else {
+ char *ccol = ((char*)ibuf->rect) +
+ offset*4;
+
+ ccol[0] = col[0] * 255.0;
+ ccol[1] = col[1] * 255.0;
+ ccol[2] = col[2] * 255.0;
+ }
+ }
+ }
+ }
+}
+
+static void multires_vcol_to_tex(ImBuf *ibuf, DerivedMesh *dm, Mesh *me,
+ MTFace *mtface)
+{
+ DMGridData **grids;
+ GridKey *gridkey;
+ int i, x, y, totgrid, gridsize, boundary, offset;
+
+ totgrid = dm->getNumGrids(dm);
+ gridsize = dm->getGridSize(dm);
+ grids = dm->getGridData(dm);
+ gridkey = dm->getGridKey(dm);
+
+ boundary = gridsize - 1;
+ offset = gridelem_active_offset(&me->fdata, gridkey, CD_MCOL);
+
+ for(i = 0; i < totgrid; ++i) {
+ DMGridData *grid = grids[i];
+
+ for(y = 0; y < boundary; ++y) {
+ for(x = 0; x < boundary; ++x, ++mtface) {
+ float *col[4];
+
+ col[0] = GRIDELEM_COLOR_AT(grid,
+ y*gridsize+x,
+ gridkey)[offset];
+ col[1] = GRIDELEM_COLOR_AT(grid,
+ (y+1)*gridsize+x,
+ gridkey)[offset];
+ col[2] = GRIDELEM_COLOR_AT(grid,
+ (y+1)*gridsize+(x+1),
+ gridkey)[offset];
+ col[3] = GRIDELEM_COLOR_AT(grid,
+ y*gridsize+(x+1),
+ gridkey)[offset];
+
+
+ vcol_to_tex_tri(ibuf, mtface->uv[0],
+ mtface->uv[1], mtface->uv[2],
+ col[0], col[1], col[2]);
+ vcol_to_tex_tri(ibuf, mtface->uv[0],
+ mtface->uv[2], mtface->uv[3],
+ col[0], col[2], col[3]);
+ }
+ }
+ }
+}
+
+static int vertex_colors_to_texture_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+ Image *ima = CTX_data_edit_image(C);
+ Mesh *me = ob->data;
+ DerivedMesh *dm;
+ CustomDataMultires *cdm;
+ ImBuf *ibuf;
+ MTFace *mtface;
+ int active_mcol, active_mtface;
+
+ active_mcol = CustomData_get_active_layer_index(&me->fdata, CD_MCOL);
+ active_mtface = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
+ ibuf = BKE_image_get_ibuf(ima, NULL);
+
+ dm = mesh_get_derived_final(scene, ob, CD_MASK_MTFACE);
+ mtface = dm->getFaceDataArray(dm, CD_MTFACE);
+
+ cdm = CustomData_get_layer(&me->fdata, CD_GRIDS);
+ if(dm->type == DM_TYPE_CCGDM && cdm &&
+ CustomData_multires_get_data(cdm, CD_MCOL,
+ me->fdata.layers[active_mcol].name)) {
+ /* multires vcols, special handling */
+ multires_vcol_to_tex(ibuf, dm, me, mtface);
+
+ }
+ else {
+ MFace *mface;
+ MCol *mcol;
+ int i, j, totface;
+
+ dm = mesh_get_derived_final(scene, ob, CD_MASK_MTFACE|CD_MASK_MCOL);
+
+ mface = dm->getFaceArray(dm);
+ mcol = dm->getFaceDataArray(dm, CD_MCOL);
+ totface = dm->getNumFaces(dm);
+
+ for(i = 0; i < totface; ++i) {
+ MFace *f = &mface[i];
+ MTFace *mtf = &mtface[i];
+ float fcol[4][4];
+ int S = f->v4?4:3;
+
+ for(j = 0; j < S; ++j) {
+ MCol *ccol = mcol + i*4 + j;
+ fcol[j][0] = ccol->b / 255.0;
+ fcol[j][1] = ccol->g / 255.0;
+ fcol[j][2] = ccol->r / 255.0;
+ fcol[j][3] = ccol->a / 255.0;
+ }
+
+ vcol_to_tex_tri(ibuf, mtf->uv[0], mtf->uv[1], mtf->uv[2],
+ fcol[0], fcol[1], fcol[2]);
+ if(f->v4) {
+ vcol_to_tex_tri(ibuf,
+ mtf->uv[0], mtf->uv[2], mtf->uv[3],
+ fcol[0], fcol[2], fcol[3]);
+ }
+ }
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static int vertex_colors_to_texture_poll(bContext *C)
+{
+ Object *ob= CTX_data_active_object(C);
+ Image *ima = CTX_data_edit_image(C);
+
+ if(ob && ima) {
+ Mesh *me = ob->data;
+
+ return
+ CustomData_get_active_layer_index(&me->fdata, CD_MCOL) >= 0 &&
+ CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) >= 0 &&
+ BKE_image_get_ibuf(ima, NULL);
+ }
+
+ return 0;
+}
+
+void PAINT_OT_vertex_colors_to_texture(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Vertex Colors to Texture";
+ ot->idname= "PAINT_OT_vertex_colors_to_texture";
+
+ /* api callbacks */
+ ot->exec= vertex_colors_to_texture_exec;
+ ot->poll= vertex_colors_to_texture_poll;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
/* ********************** weight from bones operator ******************* */
static int weight_from_bones_poll(bContext *C)
More information about the Bf-blender-cvs
mailing list