[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40279] branches/soc-2011-onion-uv-tools/ source/blender/editors/sculpt_paint/sculpt_uv.c: Added missing svn properties to sculpt_uv.c
Antony Riakiotakis
kalast at gmail.com
Sat Sep 17 03:00:49 CEST 2011
Revision: 40279
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40279
Author: psy-fi
Date: 2011-09-17 01:00:49 +0000 (Sat, 17 Sep 2011)
Log Message:
-----------
Added missing svn properties to sculpt_uv.c
Modified Paths:
--------------
branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c
Property Changed:
----------------
branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c 2011-09-17 00:57:02 UTC (rev 40278)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c 2011-09-17 01:00:49 UTC (rev 40279)
@@ -1,767 +1,767 @@
-/*
- * $Id$
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Antony Riakiotakis
- *
- * ***** END GPL LICENSE BLOCK *****
- *
- * UV Brush tools (currently smoothing only)
- *
- */
-
-/** \file blender/editors/sculpt_paint/paint_uv.c
- * \ingroup edsculpt
- */
-
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_editVert.h"
-#include "BLI_math.h"
-#include "BLI_ghash.h"
-
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_brush_types.h"
-#include "DNA_meshdata_types.h"
-
-#include "BKE_brush.h"
-#include "BKE_paint.h"
-#include "BKE_context.h"
-#include "BKE_main.h"
-#include "BKE_depsgraph.h"
-#include "BKE_mesh.h"
-#include "BKE_customdata.h"
-
-#include "ED_screen.h"
-#include "ED_image.h"
-#include "ED_mesh.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "RNA_access.h"
-#include "RNA_define.h"
-#include "RNA_enum_types.h"
-
-#include "paint_intern.h"
-#include "uvedit_intern.h"
-
-#include "UI_view2d.h"
-
-#define MARK_BOUNDARY 1
-
-typedef struct UvAdjacencyElement {
- /* pointer to original uvelement */
- UvElement *element;
- /* uv pointer for convenience. Caution, this points to the original UVs! */
- float *uv;
- /* general use flag (Used to check if Element is boundary here) */
- char flag;
-} UvAdjacencyElement;
-
-typedef struct UvEdge {
- unsigned int uv1;
- unsigned int uv2;
- /* general use flag (Used to check if edge is boundary here, and propagates to adjacency elements) */
- char flag;
-}UvEdge;
-
-
-typedef struct UVInitialStrokeElement{
- /* index to unique uv */
- int uv;
- /* strength of brush on initial position */
- float strength;
- /* initial uv position */
- float initial_uv[2];
-}UVInitialStrokeElement;
-
-typedef struct UVInitialStroke{
- /* Initial Selection,for grab brushes for instance */
- UVInitialStrokeElement *initialSelection;
-
- /* total initially selected UVs*/
- int totalInitialSelected;
-
- /* initial mouse coordinates */
- float init_coord[2];
-}UVInitialStroke;
-
-
-/* custom data for uv smoothing brush */
-typedef struct UvSculptData{
- /* Contains the first of each set of coincident uvs.
- * These will be used to perform smoothing on and propagate the changes
- * to their coincident uvs */
- UvAdjacencyElement *uv;
-
- /* ...Is what it says */
- int totalUniqueUvs;
-
- /* Edges used for adjacency info, used with laplacian smoothing */
- UvEdge *uvedges;
-
- /* Need I say more? */
- int totalUvEdges;
-
- /* data for initial stroke, used by tools like grab */
- UVInitialStroke *initial_stroke;
-
- /* Timer to be used for airbrush-type brush */
- wmTimer *timer;
-
- /* To determine quickly adjacent uvs */
- UvElementMap *elementMap;
-
- /* uvsmooth Paint for fast reference */
- Paint *uvsculpt;
-}UvSculptData;
-
-/*********** Improved Laplacian Relaxation Operator ************************/
-/* Original code by Raul "farsthary"
- * adapted to uv smoothing by Antony Riakiatakis
- */
-
-typedef struct Temp_UvData{
- float sum_co[2], p[2], b[2], sum_b[2];
- int ncounter;
-}Temp_UVData;
-
-
-
-void HC_relaxation_iteration_uv(EditMesh *em, UvSculptData *sculptdata, float mouse_coord[2], float alpha, float radius, float aspectRatio){
- Temp_UVData *tmp_uvdata;
- float diff[2];
- int i;
- float radius_root = sqrt(radius);
- Brush *brush = paint_brush(sculptdata->uvsculpt);
-
- tmp_uvdata = (Temp_UVData *)MEM_callocN(sculptdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
-
- /* counting neighbors */
- for (i = 0; i < sculptdata->totalUvEdges; i++){
- UvEdge *tmpedge = sculptdata->uvedges+i;
- tmp_uvdata[tmpedge->uv1].ncounter++;
- tmp_uvdata[tmpedge->uv2].ncounter++;
-
- add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_co, sculptdata->uv[tmpedge->uv1].uv);
- add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, sculptdata->uv[tmpedge->uv2].uv);
- }
-
- for (i = 0; i < sculptdata->totalUniqueUvs; i++){
- copy_v2_v2(diff,tmp_uvdata[i].sum_co);
- mul_v2_fl(diff,1.f/tmp_uvdata[i].ncounter);
- copy_v2_v2(tmp_uvdata[i].p,diff);
-
- tmp_uvdata[i].b[0] = diff[0] - sculptdata->uv[i].uv[0];
- tmp_uvdata[i].b[1] = diff[1] - sculptdata->uv[i].uv[1];
- }
-
- for (i = 0; i < sculptdata->totalUvEdges; i++){
- UvEdge *tmpedge = sculptdata->uvedges+i;
- add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_b, tmp_uvdata[tmpedge->uv2].b);
- add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_b, tmp_uvdata[tmpedge->uv1].b);
- }
-
- for (i = 0; i < sculptdata->totalUniqueUvs; i++){
- float dist;
- /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
- * If ever uv brushes get their own mode we should check for toolsettings option too */
- if((sculptdata->uv[i].flag & MARK_BOUNDARY)){
- continue;
- }
-
- sub_v2_v2v2(diff, sculptdata->uv[i].uv, mouse_coord);
- diff[1] /= aspectRatio;
- if((dist = dot_v2v2(diff, diff)) <= radius){
- UvElement *element;
- float strength;
- strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
-
- sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*(tmp_uvdata[i].p[0] - 0.5f*(tmp_uvdata[i].b[0] + tmp_uvdata[i].sum_b[0]/tmp_uvdata[i].ncounter));
- sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*(tmp_uvdata[i].p[1] - 0.5f*(tmp_uvdata[i].b[1] + tmp_uvdata[i].sum_b[1]/tmp_uvdata[i].ncounter));
-
- for(element = sculptdata->uv[i].element; element; element = element->next){
- MTFace *mt;
- if(element->separate && element != sculptdata->uv[i].element)
- break;
- mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
- copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
- }
- }
- }
-
- MEM_freeN(tmp_uvdata);
-
- return;
-}
-
-static void laplacian_relaxation_iteration_uv(EditMesh *em, UvSculptData *sculptdata, float mouse_coord[2], float alpha, float radius, float aspectRatio)
-{
- Temp_UVData *tmp_uvdata;
- float diff[2];
- int i;
- float radius_root = sqrt(radius);
- Brush *brush = paint_brush(sculptdata->uvsculpt);
-
- tmp_uvdata = (Temp_UVData *)MEM_callocN(sculptdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
-
- /* counting neighbors */
- for (i = 0; i < sculptdata->totalUvEdges; i++){
- UvEdge *tmpedge = sculptdata->uvedges+i;
- tmp_uvdata[tmpedge->uv1].ncounter++;
- tmp_uvdata[tmpedge->uv2].ncounter++;
-
- add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_co, sculptdata->uv[tmpedge->uv1].uv);
- add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, sculptdata->uv[tmpedge->uv2].uv);
- }
-
- /* Original Lacplacian algorithm included removal of normal component of translation. here it is not
- * needed since we translate along the UV plane always.*/
- for (i = 0; i < sculptdata->totalUniqueUvs; i++){
- copy_v2_v2(tmp_uvdata[i].p, tmp_uvdata[i].sum_co);
- mul_v2_fl(tmp_uvdata[i].p, 1.f/tmp_uvdata[i].ncounter);
- }
-
- for (i = 0; i < sculptdata->totalUniqueUvs; i++){
- float dist;
- /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
- * If ever uv brushes get their own mode we should check for toolsettings option too */
- if((sculptdata->uv[i].flag & MARK_BOUNDARY)){
- continue;
- }
-
- sub_v2_v2v2(diff, sculptdata->uv[i].uv, mouse_coord);
- diff[1] /= aspectRatio;
- if((dist = dot_v2v2(diff, diff)) <= radius){
- UvElement *element;
- float strength;
- strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
-
- sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*tmp_uvdata[i].p[0];
- sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*tmp_uvdata[i].p[1];
-
- for(element = sculptdata->uv[i].element; element; element = element->next){
- MTFace *mt;
- if(element->separate && element != sculptdata->uv[i].element)
- break;
- mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
- copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
- }
- }
- }
-
- MEM_freeN(tmp_uvdata);
-
- return;
-}
-
-
-static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event, Object *obedit)
-{
- float co[2], radius, radius_root;
- ARegion *ar= CTX_wm_region(C);
- EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
- unsigned int tool;
- UvSculptData *sculptdata = (UvSculptData *)op->customdata;
- SpaceImage *sima;
- int invert;
- int width, height;
- float aspectRatio;
- float alpha, zoomx, zoomy;
- Brush *brush = paint_brush(sculptdata->uvsculpt);
- tool = CTX_data_scene(C)->toolsettings->uv_sculpt_tool;
-
- invert = RNA_boolean_get(op->ptr, "invert")? -1 : 1;
- alpha = brush_alpha(brush);
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
-
- sima = CTX_wm_space_image(C);
- ED_space_image_size(sima, &width, &height);
- ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
-
- radius = brush_size(brush)/(width*zoomx);
- aspectRatio = width/(float)height;
-
- /* We will compare squares to save some computation */
- radius = radius*radius;
- radius_root = sqrt(radius);
-
- if(tool == UV_SCULPT_TOOL_PINCH){
- int i;
- alpha *= invert;
- for (i = 0; i < sculptdata->totalUniqueUvs; i++){
- float dist, diff[2];
- /* This is supposed to happen only if "Lock Borders" is on, since we have initialization on stroke start
- * If ever uv brushes get their own mode we should check for toolsettings option too */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list