[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31127] branches/soc-2010-nicolasbishop/ source/blender/editors/sculpt_paint: == Ptex ==
Nicholas Bishop
nicholasbishop at gmail.com
Sat Aug 7 01:16:33 CEST 2010
Revision: 31127
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31127
Author: nicholasbishop
Date: 2010-08-07 01:16:31 +0200 (Sat, 07 Aug 2010)
Log Message:
-----------
== Ptex ==
Undo support
Modified Paths:
--------------
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h 2010-08-06 22:24:33 UTC (rev 31126)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h 2010-08-06 23:16:31 UTC (rev 31127)
@@ -226,7 +226,7 @@
typedef enum {
PBVH_UNDO_CO_NO = (1<<0),
PBVH_UNDO_PMASK = (1<<1),
- PBVH_UNDO_COLOR = (1<<2)
+ PBVH_UNDO_PTEX = (1<<2)
} PBVHUndoFlag;
typedef struct PBVHUndoNode PBVHUndoNode;
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c 2010-08-06 22:24:33 UTC (rev 31126)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c 2010-08-06 23:16:31 UTC (rev 31127)
@@ -2007,7 +2007,7 @@
BLI_pbvh_get_customdata(pbvh, &vdata, &fdata);
for(n = 0; n < totnode; ++n) {
- pbvh_undo_push_node(nodes[n], PBVH_UNDO_COLOR, ob);
+ pbvh_undo_push_node(nodes[n], PBVH_UNDO_PTEX, ob);
if(BLI_pbvh_uses_grids(pbvh)) {
#if 0 /* TODO */
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c 2010-08-06 22:24:33 UTC (rev 31126)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c 2010-08-06 23:16:31 UTC (rev 31127)
@@ -54,6 +54,7 @@
#include "ED_sculpt.h"
#include "paint_intern.h"
#include "sculpt_intern.h"
+#include "ptex.h"
/************************** Undo *************************/
@@ -73,9 +74,9 @@
/* paint mask */
float *pmask;
char pmask_name[32];
- /* vertex colors */
- float (*color)[4];
- char color_name[32];
+ /* ptex */
+ MPtex *mptex;
+ char mptex_name[32];
/* non-multires */
/* to verify if me->totvert it still the same */
@@ -83,7 +84,7 @@
/* to restore into the right location */
int *vert_indices;
int *face_indices;
- /* for per-facecorner data (colors) */
+ /* for per-face data (mptex) */
int totface;
/* multires */
@@ -161,7 +162,6 @@
{
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- Mesh *me = ob->data;
DerivedMesh *dm = mesh_get_derived_final(scene, ob, 0);
PBVH *pbvh;
PBVHUndoNode *unode;
@@ -199,36 +199,16 @@
SWAP(float, pmask[unode->vert_indices[i]],
unode->pmask[i]);
}
- if(unode->color) {
- MCol *mcol;
+ if(unode->mptex) {
+ MPtex *mptex;
- mcol = CustomData_get_layer_named(fdata,
- CD_MCOL,
- unode->color_name);
+ mptex = CustomData_get_layer_named(fdata,
+ CD_MPTEX,
+ unode->mptex_name);
for(i=0; i<unode->totface; i++) {
- int face_index = unode->face_indices[i];
- MFace *f = me->mface + face_index;
- int S = f->v4?4:3;
-
- for(j=0; j<S; ++j) {
- MCol *col;
- float fcol[4];
-
- col = mcol + face_index*4+j;
-
- fcol[0] = mcol->b / 255.0f;
- fcol[1] = mcol->g / 255.0f;
- fcol[2] = mcol->r / 255.0f;
- fcol[3] = mcol->a / 255.0f;
-
- swap_v4_v4(fcol, unode->color[i*4+j]);
-
- mcol->b = fcol[0] * 255.0f;
- mcol->g = fcol[0] * 255.0f;
- mcol->r = fcol[0] * 255.0f;
- mcol->a = fcol[0] * 255.0f;
- }
+ SWAP(MPtex, unode->mptex[i],
+ mptex[unode->face_indices[i]]);
}
}
}
@@ -236,8 +216,8 @@
/* multires restore */
DMGridData **grids, *grid;
GridKey *gridkey;
- float (*co)[3] = NULL, *pmask = NULL, (*color)[4] = NULL;
- int gridsize, active_pmask, active_color;
+ float (*co)[3] = NULL, *pmask = NULL;
+ int gridsize, active_pmask;
if(dm->getNumGrids(dm) != unode->maxgrid)
continue;
@@ -256,10 +236,6 @@
pmask = unode->pmask;
active_pmask = gridelem_active_offset(vdata, gridkey, CD_PAINTMASK);
}
- if(unode->color) {
- color = unode->color;
- active_color = gridelem_active_offset(fdata, gridkey, CD_MCOL);
- }
for(j=0; j<unode->totgrid; j++) {
grid= grids[unode->grid_indices[j]];
@@ -276,11 +252,6 @@
*pmask);
++pmask;
}
- if(color) {
- swap_v4_v4(GRIDELEM_COLOR(elem, gridkey)[active_color],
- *color);
- ++color;
- }
}
}
}
@@ -315,6 +286,7 @@
static void pbvh_undo_free(ListBase *lb)
{
PBVHUndoNode *unode;
+ int i;
for(unode=lb->first; unode; unode=unode->next) {
if(unode->co)
@@ -323,8 +295,11 @@
MEM_freeN(unode->no);
if(unode->pmask)
MEM_freeN(unode->pmask);
- if(unode->color)
- MEM_freeN(unode->color);
+ if(unode->mptex) {
+ for(i = 0; i < unode->totface; ++i)
+ MEM_freeN(unode->mptex[i].data);
+ MEM_freeN(unode->mptex);
+ }
if(unode->vert_indices)
MEM_freeN(unode->vert_indices);
if(unode->face_indices)
@@ -368,7 +343,6 @@
GridKey *gridkey;
int uses_grids, totgrid, *grid_indices;
- int grids_active_color;
/* list is manipulated by multiple threads, so we lock */
BLI_lock_thread(LOCK_CUSTOM1);
@@ -432,36 +406,36 @@
totbytes += sizeof(float) * unode->totvert;
}
}
- if(flag & PBVH_UNDO_COLOR) {
- int totcol, active;
- active= CustomData_get_active_layer_index(fdata, CD_MCOL);
+ if(flag & PBVH_UNDO_PTEX) {
+ int i, j, active;
+ active= CustomData_get_active_layer_index(fdata, CD_MPTEX);
- if(active == -1)
- flag &= ~PBVH_UNDO_COLOR;
+ if(active == -1 || uses_grids /* TODO */)
+ flag &= ~PBVH_UNDO_PTEX;
else {
- BLI_strncpy(unode->color_name,
+ BLI_strncpy(unode->mptex_name,
fdata->layers[active].name,
- sizeof(unode->color_name));
+ sizeof(unode->mptex_name));
- if(uses_grids) {
- totcol= unode->totvert;
- grids_active_color = gridelem_active_offset(fdata, gridkey, CD_MCOL);
- }
- else {
- BLI_pbvh_node_get_faces(pbvh, node,
- &mface, &face_indices,
- NULL, &totface);
- unode->totface= totface;
+ BLI_pbvh_node_get_faces(pbvh, node,
+ &mface, &face_indices,
+ NULL, &totface);
+ unode->totface= totface;
- unode->face_indices= MEM_mapallocN(sizeof(int)*unode->totface,
- "PBVHUndoNode.face_indices");
- totbytes += sizeof(int)*unode->totface;
+ unode->face_indices= MEM_mapallocN(sizeof(int)*unode->totface,
+ "PBVHUndoNode.face_indices");
+ totbytes += sizeof(int)*unode->totface;
- totcol= totface * 4;
+ unode->mptex= MEM_mapallocN(sizeof(MPtex)*totface, "PBVHUndoNode.mptex");
+ totbytes += sizeof(MPtex)*totface;
+
+ for(i = 0; i < totface; ++i) {
+ MPtex *pt = ((MPtex*)fdata->layers[active].data) + face_indices[i];
+ for(j = 0; j < pt->subfaces; ++j) {
+ totbytes += pt->channels*ptex_data_size(pt->type) *
+ pt->res[j][0] * pt->res[j][1];
+ }
}
-
- unode->color= MEM_mapallocN(sizeof(float)*4*totcol, "PBVHUndoNode.color");
- totbytes += sizeof(float)*4*totcol;
}
}
@@ -484,13 +458,6 @@
if(vd.mask_active)
unode->pmask[vd.i]= *vd.mask_active;
}
- if(flag & PBVH_UNDO_COLOR) {
- /* only copy for multires here */
- if(uses_grids) {
- copy_v4_v4(unode->color[vd.i],
- GRIDELEM_COLOR(vd.elem, vd.gridkey)[grids_active_color]);
- }
- }
if(vd.vert_indices)
unode->vert_indices[vd.i]= vd.vert_indices[vd.i];
@@ -501,31 +468,19 @@
if(unode->grid_indices)
memcpy(unode->grid_indices, grid_indices, sizeof(int)*totgrid);
- /* non-multires: per face copy of color data */
- if(!uses_grids && (flag & PBVH_UNDO_COLOR)) {
- int active, i, j;
+ /* non-multires: per face copy of ptex data */
+ if(!uses_grids && (flag & PBVH_UNDO_PTEX)) {
+ int active, i;
- active = CustomData_get_active_layer_index(fdata, CD_MCOL);
+ active = CustomData_get_active_layer_index(fdata, CD_MPTEX);
for(i = 0; i < totface; ++i) {
int face_index = face_indices[i];
- MFace *f = mface + face_index;
- int S = f->v4 ? 4 : 3;
+ MPtex *pt = ((MPtex*)fdata->layers[active].data) + face_index;
unode->face_indices[i]= face_index;
-
- for(j = 0; j < S; ++j) {
- MCol *mcol = fdata->layers[active].data;
- float fcol[4];
-
- mcol += face_index*4 + j;
- fcol[0] = mcol->b / 255.0f;
- fcol[1] = mcol->g / 255.0f;
- fcol[2] = mcol->r / 255.0f;
- fcol[3] = mcol->a / 255.0f;
-
- copy_v4_v4(unode->color[i*4 + j], fcol);
- }
+ unode->mptex[i] = *pt;
+ unode->mptex[i].data = MEM_dupallocN(pt->data);
}
}
More information about the Bf-blender-cvs
mailing list