[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27282] trunk/blender: reproject operator, use to reproject edited renders back into textures.
Campbell Barton
ideasman42 at gmail.com
Fri Mar 5 19:19:33 CET 2010
Revision: 27282
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27282
Author: campbellbarton
Date: 2010-03-05 19:19:32 +0100 (Fri, 05 Mar 2010)
Log Message:
-----------
reproject operator, use to reproject edited renders back into textures.
- uses project paint options (UV bleed, normals, culling)
- bicubic interolation from the image
- multithraded
TODO.
project into multiple objects at once.
Modified Paths:
--------------
trunk/blender/release/scripts/ui/space_view3d.py
trunk/blender/release/scripts/ui/space_view3d_toolbar.py
trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
trunk/blender/source/blender/makesrna/RNA_enum_types.h
trunk/blender/source/blender/windowmanager/intern/wm_operators.c
Modified: trunk/blender/release/scripts/ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/ui/space_view3d.py 2010-03-05 16:47:52 UTC (rev 27281)
+++ trunk/blender/release/scripts/ui/space_view3d.py 2010-03-05 18:19:32 UTC (rev 27282)
@@ -81,10 +81,6 @@
if toolsettings.proportional_editing != 'DISABLED':
row.prop(toolsettings, "proportional_editing_falloff", text="", icon_only=True)
- # paint save
- if mode_string == 'PAINT_TEXTURE':
- row.operator("image.save_dirty", text="Save Edited")
-
# Snap
row = layout.row(align=True)
row.prop(toolsettings, "snap", text="")
Modified: trunk/blender/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- trunk/blender/release/scripts/ui/space_view3d_toolbar.py 2010-03-05 16:47:52 UTC (rev 27281)
+++ trunk/blender/release/scripts/ui/space_view3d_toolbar.py 2010-03-05 18:19:32 UTC (rev 27282)
@@ -906,6 +906,10 @@
sub = col.column()
sub.prop(ipaint, "seam_bleed")
+
+ sub = col.column()
+ col.operator("image.save_dirty", text="Save Edited")
+ col.operator("paint.camera_project")
class VIEW3D_MT_tools_projectpaint_clone(bpy.types.Menu):
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c 2010-03-05 16:47:52 UTC (rev 27281)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c 2010-03-05 18:19:32 UTC (rev 27282)
@@ -65,6 +65,7 @@
#include "DNA_windowmanager_types.h"
#include "BKE_context.h"
+#include "BKE_object.h"
#include "BKE_brush.h"
#include "BKE_global.h"
#include "BKE_image.h"
@@ -94,6 +95,7 @@
#include "RNA_access.h"
#include "RNA_define.h"
+#include "RNA_enum_types.h"
#include "GPU_draw.h"
@@ -184,6 +186,9 @@
#define PROJ_FACE_NOSEAM3 1<<6
#define PROJ_FACE_NOSEAM4 1<<7
+#define PROJ_SRC_VIEW 1
+#define PROJ_SRC_CAM 2
+
/* a slightly scaled down face is used to get fake 3D location for edge pixels in the seams
* as this number approaches 1.0f the likelihood increases of float precision errors where
* it is occluded by an adjacent face */
@@ -218,6 +223,7 @@
RegionView3D *rv3d;
ARegion *ar;
Scene *scene;
+ int source; /* PROJ_SRC_**** */
Brush *brush;
short tool, blend;
@@ -259,6 +265,7 @@
float screenMax[2];
float screen_width; /* Calculated from screenMin & screenMax */
float screen_height;
+ int winx, winy; /* from the carea or from the projection render */
/* options for projection painting */
int do_layer_clone;
@@ -286,6 +293,10 @@
float viewPos[3]; /* View location in object relative 3D space, so can compare to verts */
float clipsta, clipend;
+ /* reproject vars */
+ ImBuf *reproject_ibuf;
+
+
/* threads */
int thread_tot;
int bucketMin[2];
@@ -742,6 +753,7 @@
int face_index;
int isect_ret;
float w[3]; /* not needed when clipping */
+ const short do_clip= ps->rv3d ? ps->rv3d->rflag & RV3D_CLIPPING : 0;
/* we could return 0 for 1 face buckets, as long as this function assumes
* that the point its testing is only every originated from an existing face */
@@ -751,14 +763,14 @@
if (orig_face != face_index) {
mf = ps->dm_mface + face_index;
- if(ps->rv3d->rflag & RV3D_CLIPPING)
+ if(do_clip)
isect_ret = project_paint_occlude_ptv_clip(ps, mf, pixelScreenCo, ps->screenCoords[mf->v1], ps->screenCoords[mf->v2], ps->screenCoords[mf->v3], 0);
else
isect_ret = project_paint_occlude_ptv(pixelScreenCo, ps->screenCoords[mf->v1], ps->screenCoords[mf->v2], ps->screenCoords[mf->v3], w, ps->is_ortho);
/* Note, if isect_ret==-1 then we dont want to test the other side of the quad */
if (isect_ret==0 && mf->v4) {
- if(ps->rv3d->rflag & RV3D_CLIPPING)
+ if(do_clip)
isect_ret = project_paint_occlude_ptv_clip(ps, mf, pixelScreenCo, ps->screenCoords[mf->v1], ps->screenCoords[mf->v3], ps->screenCoords[mf->v4], 1);
else
isect_ret = project_paint_occlude_ptv(pixelScreenCo, ps->screenCoords[mf->v1], ps->screenCoords[mf->v3], ps->screenCoords[mf->v4], w, ps->is_ortho);
@@ -2199,6 +2211,7 @@
int uv_clip_tot;
const short is_ortho = ps->is_ortho;
const short do_backfacecull = ps->do_backfacecull;
+ const short do_clip= ps->rv3d ? ps->rv3d->rflag & RV3D_CLIPPING : 0;
vCo[0] = ps->dm_mvert[mf->v1].co;
vCo[1] = ps->dm_mvert[mf->v2].co;
@@ -2298,7 +2311,7 @@
else screen_px_from_persp(uv, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, pixelScreenCo, w);
/* a pitty we need to get the worldspace pixel location here */
- if(ps->rv3d->rflag & RV3D_CLIPPING) {
+ if(do_clip) {
interp_v3_v3v3v3(wco, ps->dm_mvert[ (*(&mf->v1 + i1)) ].co, ps->dm_mvert[ (*(&mf->v1 + i2)) ].co, ps->dm_mvert[ (*(&mf->v1 + i3)) ].co, w);
if(view3d_test_clipping(ps->rv3d, wco, 1)) {
continue; /* Watch out that no code below this needs to run */
@@ -2479,8 +2492,8 @@
if (!is_ortho) {
pixelScreenCo[3] = 1.0f;
mul_m4_v4((float(*)[4])ps->projectMat, pixelScreenCo); /* cast because of const */
- pixelScreenCo[0] = (float)(ps->ar->winx/2.0f)+(ps->ar->winx/2.0f)*pixelScreenCo[0]/pixelScreenCo[3];
- pixelScreenCo[1] = (float)(ps->ar->winy/2.0f)+(ps->ar->winy/2.0f)*pixelScreenCo[1]/pixelScreenCo[3];
+ pixelScreenCo[0] = (float)(ps->winx/2.0f)+(ps->winx/2.0f)*pixelScreenCo[0]/pixelScreenCo[3];
+ pixelScreenCo[1] = (float)(ps->winy/2.0f)+(ps->winy/2.0f)*pixelScreenCo[1]/pixelScreenCo[3];
pixelScreenCo[2] = pixelScreenCo[2]/pixelScreenCo[3]; /* Use the depth for bucket point occlusion */
}
@@ -2513,7 +2526,7 @@
}
/* a pitty we need to get the worldspace pixel location here */
- if(ps->rv3d->rflag & RV3D_CLIPPING) {
+ if(do_clip) {
if (side) interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w);
else interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w);
@@ -2768,6 +2781,7 @@
float (*projScreenCo)[4]; /* Note, we could have 4D vectors are only needed for */
float projMargin;
+
/* Image Vars - keep track of images we have used */
LinkNode *image_LinkList = NULL;
LinkNode *node;
@@ -2786,7 +2800,8 @@
/* ---- end defines ---- */
- ED_view3d_local_clipping(ps->rv3d, ps->ob->obmat); /* faster clipping lookups */
+ if(ps->source==PROJ_SRC_VIEW)
+ ED_view3d_local_clipping(ps->rv3d, ps->ob->obmat); /* faster clipping lookups */
/* paint onto the derived mesh */
@@ -2796,7 +2811,7 @@
ps->dm_release= FALSE;
}
else {
- ps->dm = mesh_get_derived_final(ps->scene, ps->ob, ps->v3d->customdata_mask);
+ ps->dm = mesh_get_derived_final(ps->scene, ps->ob, ps->v3d->customdata_mask | CD_MASK_MTFACE);
ps->dm_release= TRUE;
}
@@ -2861,44 +2876,81 @@
ps->viewDir[1] = 0.0f;
ps->viewDir[2] = 1.0f;
- view3d_get_object_project_mat(ps->rv3d, ps->ob, ps->projectMat);
-
- /* viewDir - object relative */
- invert_m4_m4(ps->ob->imat, ps->ob->obmat);
- copy_m3_m4(mat, ps->rv3d->viewinv);
- mul_m3_v3(mat, ps->viewDir);
- copy_m3_m4(mat, ps->ob->imat);
- mul_m3_v3(mat, ps->viewDir);
- normalize_v3(ps->viewDir);
-
- /* viewPos - object relative */
- VECCOPY(ps->viewPos, ps->rv3d->viewinv[3]);
- copy_m3_m4(mat, ps->ob->imat);
- mul_m3_v3(mat, ps->viewPos);
- add_v3_v3v3(ps->viewPos, ps->viewPos, ps->ob->imat[3]);
-
- { /* only use these for running 'get_view3d_viewplane' */
+ {
rctf viewplane;
-
- ps->is_ortho = get_view3d_viewplane(ps->v3d, ps->rv3d, ps->ar->winx, ps->ar->winy, &viewplane, &ps->clipsta, &ps->clipend, NULL);
-
- //printf("%f %f\n", ps->clipsta, ps->clipend);
- if (ps->is_ortho) { /* only needed for ortho */
- float fac = 2.0f / (ps->clipend - ps->clipsta);
- ps->clipsta *= fac;
- ps->clipend *= fac;
+ float viewmat[4][4];
+ float viewinv[4][4];
+
+ invert_m4_m4(ps->ob->imat, ps->ob->obmat);
+
+ if(ps->source==PROJ_SRC_VIEW) {
+ ps->winx= ps->ar->winx;
+ ps->winy= ps->ar->winy;
+
+ copy_m4_m4(viewmat, ps->rv3d->viewmat);
+ copy_m4_m4(viewinv, ps->rv3d->viewinv);
+
+ view3d_get_object_project_mat(ps->rv3d, ps->ob, ps->projectMat);
+
+ ps->is_ortho= get_view3d_viewplane(ps->v3d, ps->rv3d, ps->winx, ps->winy, &viewplane, &ps->clipsta, &ps->clipend, NULL);
+
+ //printf("%f %f\n", ps->clipsta, ps->clipend);
+ if (ps->is_ortho) { /* only needed for ortho */
+ float fac = 2.0f / (ps->clipend - ps->clipsta);
+ ps->clipsta *= fac;
+ ps->clipend *= fac;
+ }
+ else {
+ /* TODO - can we even adjust for clip start/end? */
+ }
}
- else {
- /* TODO - can we even adjust for clip start/end? */
+ else if (ps->source==PROJ_SRC_CAM) {
+ Object *camera= ps->scene->camera;
+ rctf viewplane;
+ float winmat[4][4];
+ float vmat[4][4];
+
+ /* dont actually use these */
+ float _viewdx, _viewdy, _ycor, _lens=0.0f;
+
+
+ ps->winx= ps->reproject_ibuf->x;
+ ps->winy= ps->reproject_ibuf->y;
+
+ /* viewmat & viewinv */
+ copy_m4_m4(viewinv, ps->scene->camera->obmat);
+ normalize_m4(viewinv);
+ invert_m4_m4(viewmat, viewinv);
+
+ /* camera winmat */
+ object_camera_matrix(&ps->scene->r, camera, ps->winx, ps->winy, 0,
+ winmat, &viewplane, &ps->clipsta, &ps->clipend,
+ &_lens, &_ycor, &_viewdx, &_viewdy);
+
+
+ /* same as view3d_get_object_project_mat */
+ mul_m4_m4m4(vmat, ps->ob->obmat, viewmat);
+ mul_m4_m4m4(ps->projectMat, vmat, winmat);
+
+ ps->is_ortho= (ps->scene->r.mode & R_ORTHO) ? 1 : 0;
}
+
+
+ /* viewDir - object relative */
+ invert_m4_m4(ps->ob->imat, ps->ob->obmat);
+ copy_m3_m4(mat, viewinv);
+ mul_m3_v3(mat, ps->viewDir);
+ copy_m3_m4(mat, ps->ob->imat);
+ mul_m3_v3(mat, ps->viewDir);
+ normalize_v3(ps->viewDir);
+ /* viewPos - object relative */
+ VECCOPY(ps->viewPos, viewinv[3]);
+ copy_m3_m4(mat, ps->ob->imat);
+ mul_m3_v3(mat, ps->viewPos);
+ add_v3_v3v3(ps->viewPos, ps->viewPos, ps->ob->imat[3]);
}
- ps->is_airbrush = (ps->brush->flag & BRUSH_AIRBRUSH) ? 1 : 0;
-
- ps->is_texbrush = (ps->brush->mtex.tex) ? 1 : 0;
-
-
/* calculate vert screen coords
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list