Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2010-03-09 07:32:40 +0300
committerJoseph Eagar <joeedh@gmail.com>2010-03-09 07:32:40 +0300
commit71003b9bcc88ecf6138c3debb9abba4637c8e61a (patch)
tree7f85d40231311a36a72f731a7c07b8dbd6fff577 /source/blender/editors/uvedit
parentea540496c8281dcba899fb6b29c1bcfbb53a0482 (diff)
parent790d6ca256e6b572826b2bf214c6fd6c8a623969 (diff)
merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though further work may be needed because changes made by the merge
Diffstat (limited to 'source/blender/editors/uvedit')
-rw-r--r--source/blender/editors/uvedit/uvedit_draw.c2
-rw-r--r--source/blender/editors/uvedit/uvedit_intern.h2
-rw-r--r--source/blender/editors/uvedit/uvedit_ops.c50
-rw-r--r--source/blender/editors/uvedit/uvedit_parametrizer.c8
-rw-r--r--source/blender/editors/uvedit/uvedit_unwrap_ops.c107
5 files changed, 103 insertions, 66 deletions
diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c
index e5fef360446..e96fda1eca6 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -15,7 +15,7 @@
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h
index c36631613e4..59f19d85209 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -15,7 +15,7 @@
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* All rights reserved.
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 67a06423993..e7ae94f97c4 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -15,7 +15,7 @@
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
@@ -1265,14 +1265,14 @@ static int align_exec(bContext *C, wmOperator *op)
void UV_OT_align(wmOperatorType *ot)
{
static EnumPropertyItem axis_items[] = {
- {'a', "ALIGN_AUTO", 0, "Align Auto", "Automatically choose the axis on which there is most alignment already."},
- {'x', "ALIGN_X", 0, "Align X", "Align UVs on X axis."},
- {'y', "ALIGN_Y", 0, "Align Y", "Align UVs on Y axis."},
+ {'a', "ALIGN_AUTO", 0, "Align Auto", "Automatically choose the axis on which there is most alignment already"},
+ {'x', "ALIGN_X", 0, "Align X", "Align UVs on X axis"},
+ {'y', "ALIGN_Y", 0, "Align Y", "Align UVs on Y axis"},
{0, NULL, 0, NULL, NULL}};
/* identifiers */
ot->name= "Align";
- ot->description= "Align selected UV vertices to an axis.";
+ ot->description= "Align selected UV vertices to an axis";
ot->idname= "UV_OT_align";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1297,7 +1297,7 @@ void UV_OT_weld(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Weld";
- ot->description= "Weld selected UV vertices together.";
+ ot->description= "Weld selected UV vertices together";
ot->idname= "UV_OT_weld";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1465,7 +1465,7 @@ void UV_OT_stitch(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Stitch";
- ot->description= "Stitch selected UV vertices by proximity.";
+ ot->description= "Stitch selected UV vertices by proximity";
ot->idname= "UV_OT_stitch";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1525,7 +1525,7 @@ void UV_OT_select_inverse(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Inverse";
- ot->description= "Select inverse of (un)selected UV vertices.";
+ ot->description= "Select inverse of (un)selected UV vertices";
ot->idname= "UV_OT_select_inverse";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1632,7 +1632,7 @@ void UV_OT_select_all(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select or Deselect All";
- ot->description= "Change selection of all UV vertices.";
+ ot->description= "Change selection of all UV vertices";
ot->idname= "UV_OT_select_all";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1976,7 +1976,7 @@ void UV_OT_select(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select";
- ot->description= "Select UV vertice.";
+ ot->description= "Select UV vertice";
ot->idname= "UV_OT_select";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2025,7 +2025,7 @@ void UV_OT_select_loop(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Loop Select";
- ot->description= "Select a loop of connected UV vertices.";
+ ot->description= "Select a loop of connected UV vertices";
ot->idname= "UV_OT_select_loop";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2104,7 +2104,7 @@ void UV_OT_select_linked(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Linked";
- ot->description= "Select all UV vertices linked to the active UV map.";
+ ot->description= "Select all UV vertices linked to the active UV map";
ot->idname= "UV_OT_select_linked";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2131,7 +2131,7 @@ void UV_OT_select_linked_pick(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Linked Pick";
- ot->description= "Select all UV vertices linked under the mouse.";
+ ot->description= "Select all UV vertices linked under the mouse";
ot->idname= "UV_OT_select_linked_pick";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2202,7 +2202,7 @@ void UV_OT_unlink_selection(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Unlink Selection";
- ot->description= "Unlink selected UV vertices from active UV map.";
+ ot->description= "Unlink selected UV vertices from active UV map";
ot->idname= "UV_OT_unlink_selection";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2460,7 +2460,7 @@ void UV_OT_select_border(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Border Select";
- ot->description= "Select UV vertices using border selection.";
+ ot->description= "Select UV vertices using border selection";
ot->idname= "UV_OT_select_border";
/* api callbacks */
@@ -2553,7 +2553,7 @@ void UV_OT_circle_select(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Circle Select";
- ot->description= "Select UV vertices using circle selection.";
+ ot->description= "Select UV vertices using circle selection";
ot->idname= "UV_OT_circle_select";
/* api callbacks */
@@ -2629,7 +2629,7 @@ void UV_OT_snap_cursor(wmOperatorType *ot)
/* identifiers */
ot->name= "Snap Cursor";
- ot->description= "Snap cursor to target type.";
+ ot->description= "Snap cursor to target type";
ot->idname= "UV_OT_snap_cursor";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2838,7 +2838,7 @@ void UV_OT_snap_selection(wmOperatorType *ot)
/* identifiers */
ot->name= "Snap Selection";
- ot->description= "Snap selected UV vertices to target type.";
+ ot->description= "Snap selected UV vertices to target type";
ot->idname= "UV_OT_snap_selection";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2892,7 +2892,7 @@ void UV_OT_pin(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Pin";
- ot->description= "Set/clear selected UV vertices as anchored between multiple unwrap operations.";
+ ot->description= "Set/clear selected UV vertices as anchored between multiple unwrap operations";
ot->idname= "UV_OT_pin";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2940,7 +2940,7 @@ void UV_OT_select_pinned(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Selected Pinned";
- ot->description= "Select all pinned UV vertices.";
+ ot->description= "Select all pinned UV vertices";
ot->idname= "UV_OT_select_pinned";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -3008,7 +3008,7 @@ void UV_OT_hide(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Hide Selected";
- ot->description= "Hide (un)selected UV vertices.";
+ ot->description= "Hide (un)selected UV vertices";
ot->idname= "UV_OT_hide";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -3072,7 +3072,7 @@ void UV_OT_reveal(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Reveal Hidden";
- ot->description= "Reveal all hidden UV vertices.";
+ ot->description= "Reveal all hidden UV vertices";
ot->idname= "UV_OT_reveal";
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -3115,7 +3115,7 @@ void UV_OT_cursor_set(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Set 2D Cursor";
- ot->description= "Set 2D cursor location.";
+ ot->description= "Set 2D cursor location";
ot->idname= "UV_OT_cursor_set";
/* api callbacks */
@@ -3181,7 +3181,7 @@ void UV_OT_tile_set(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Set Tile";
- ot->description= "Set UV image tile coordinates.";
+ ot->description= "Set UV image tile coordinates";
ot->idname= "UV_OT_tile_set";
/* api callbacks */
@@ -3265,6 +3265,8 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "UV_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "UV_OT_select_pinned", PKEY, KM_PRESS, KM_SHIFT, 0);
+ WM_keymap_add_item(keymap, "UV_OT_weld", WKEY, KM_PRESS, 0, 0);
+
/* uv operations */
WM_keymap_add_item(keymap, "UV_OT_stitch", VKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 0a455edf398..b2d20eb7526 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -1378,11 +1378,11 @@ static void p_polygon_kernel_center(float (*points)[2], int npoints, float *cent
if (nnewpoints*2 > size) {
size *= 2;
- free(oldpoints);
- oldpoints = malloc(sizeof(float)*2*size);
+ MEM_freeN(oldpoints);
+ oldpoints = MEM_mallocN(sizeof(float)*2*size, "oldpoints");
memcpy(oldpoints, newpoints, sizeof(float)*2*nnewpoints);
- free(newpoints);
- newpoints = malloc(sizeof(float)*2*size);
+ MEM_freeN(newpoints);
+ newpoints = MEM_mallocN(sizeof(float)*2*size, "newpoints");
}
else {
float (*sw_points)[2] = oldpoints;
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 5f472a26eff..6275549e3c5 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -15,7 +15,7 @@
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
@@ -702,14 +702,14 @@ static void uv_map_transform(bContext *C, wmOperator *op, float center[3], float
static void uv_transform_properties(wmOperatorType *ot, int radius)
{
static EnumPropertyItem direction_items[]= {
- {VIEW_ON_EQUATOR, "VIEW_ON_EQUATOR", 0, "View on Equator", "3D view is on the equator."},
- {VIEW_ON_POLES, "VIEW_ON_POLES", 0, "View on Poles", "3D view is on the poles."},
- {ALIGN_TO_OBJECT, "ALIGN_TO_OBJECT", 0, "Align to Object", "Align according to object transform."},
+ {VIEW_ON_EQUATOR, "VIEW_ON_EQUATOR", 0, "View on Equator", "3D view is on the equator"},
+ {VIEW_ON_POLES, "VIEW_ON_POLES", 0, "View on Poles", "3D view is on the poles"},
+ {ALIGN_TO_OBJECT, "ALIGN_TO_OBJECT", 0, "Align to Object", "Align according to object transform"},
{0, NULL, 0, NULL, NULL}
};
static EnumPropertyItem align_items[]= {
- {POLAR_ZX, "POLAR_ZX", 0, "Polar ZX", "Polar 0 is X."},
- {POLAR_ZY, "POLAR_ZY", 0, "Polar ZY", "Polar 0 is Y."},
+ {POLAR_ZX, "POLAR_ZX", 0, "Polar ZX", "Polar 0 is X"},
+ {POLAR_ZY, "POLAR_ZY", 0, "Polar ZY", "Polar 0 is Y"},
{0, NULL, 0, NULL, NULL}
};
@@ -910,30 +910,58 @@ static void uv_from_view_bounds(float target[2], float source[3], float rotmat[4
target[1] = pv[2];
}
-static void uv_from_camera(float camsize, float xasp, float yasp, float target[2], float source[3], float rotmat[4][4], float cammat[4][4], int persp)
+typedef struct UvCameraInfo {
+ float camangle;
+ float camsize;
+ float xasp, yasp;
+ float shiftx, shifty;
+ float rotmat[4][4];
+ float caminv[4][4];
+ short do_persp, do_pano;
+} UvCameraInfo;
+
+//static void uv_from_camera(float camsize, float camangle, float xasp, float yasp, float target[2], float source[3], float rotmat[4][4], float caminv[4][4], int persp, int pano)
+static void uv_from_camera(UvCameraInfo *uci, float target[2], float source[3])
{
-
float pv4[4];
copy_v3_v3(pv4, source);
pv4[3]= 1.0;
/* rotmat is the object matrix in this case */
- mul_m4_v4(rotmat, pv4);
-
- /* cammat is the inverse camera matrix */
- mul_m4_v4(cammat, pv4);
+ mul_m4_v4(uci->rotmat, pv4);
- if (pv4[2]==0.0f) pv4[2]=0.00001f; /* don't allow div by 0 */
+ /* caminv is the inverse camera matrix */
+ mul_m4_v4(uci->caminv, pv4);
- if (persp&&CAM_ORTHO) {
- target[0]=((pv4[0]/camsize)*xasp)+0.5f;
- target[1]=((pv4[1]/camsize)*yasp)+0.5f;
+ if(uci->do_pano) {
+ float angle= atan2f(pv4[0], -pv4[2]) / (M_PI * 2.0); /* angle around the camera */
+ if (uci->do_persp==0) {
+ target[0] = angle; /* no correct method here, just map to 0-1 */
+ target[1] = pv4[1] / uci->camsize;
+ }
+ else {
+ float vec2d[2]= {pv4[0], pv4[2]}; /* 2D position from the camera */
+ target[0] = angle * (M_PI / uci->camangle);
+ target[1] = pv4[1] / (len_v2(vec2d) * uci->camsize);
+ }
}
else {
- target[0]=((-pv4[0]*(camsize/pv4[2])*xasp)/2)+0.5;
- target[1]=((-pv4[1]*(camsize/pv4[2])*yasp)/2)+0.5;
+ if (pv4[2]==0.0f) pv4[2]=0.00001f; /* don't allow div by 0 */
+
+ if (uci->do_persp==0) {
+ target[0]=(pv4[0]/uci->camsize) * uci->xasp;
+ target[1]=(pv4[1]/uci->camsize) * uci->yasp;
+ }
+ else {
+ target[0]=(-pv4[0]*((1.0f/uci->camsize)/pv4[2])*uci->xasp) / 2.0f;
+ target[1]=(-pv4[1]*((1.0f/uci->camsize)/pv4[2])*uci->yasp) / 2.0f;
+ }
}
+
+ /* adds camera shift + 0.5 */
+ target[0] += uci->shiftx;
+ target[1] += uci->shifty;
}
static void uv_from_view(ARegion *ar, float target[2], float source[3], float rotmat[4][4])
@@ -985,13 +1013,13 @@ static int from_view_exec(bContext *C, wmOperator *op)
Camera *camera= NULL;
BMEditMesh *em= ((Mesh*)obedit->data)->edit_btmesh;
ARegion *ar = CTX_wm_region(C);
+ View3D *v3d= CTX_wm_view3d(C);
RegionView3D *rv3d= CTX_wm_region_view3d(C);
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
MLoopUV *luv;
- float invmat[4][4],rotmat[4][4];
- float xasp, yasp, camsize;
+ float rotmat[4][4];
/* add uvs if they don't exist yet */
if(!ED_uvedit_ensure_uvs(C, scene, obedit)) {
@@ -999,8 +1027,8 @@ static int from_view_exec(bContext *C, wmOperator *op)
}
/* establish the camera object, so we can default to view mapping if anything is wrong with it */
- if ((rv3d->persp==RV3D_CAMOB) && (scene->camera) && (scene->camera->type==OB_CAMERA)) {
- camera=scene->camera->data;
+ if ((rv3d->persp==RV3D_CAMOB) && (v3d->camera) && (v3d->camera->type==OB_CAMERA)) {
+ camera= v3d->camera->data;
}
if(RNA_boolean_get(op->ptr, "orthographic")) {
@@ -1017,34 +1045,41 @@ static int from_view_exec(bContext *C, wmOperator *op)
}
}
else if (camera) {
-
- if (camera->type==CAM_PERSP) {
- camsize=1/tan(DEG2RAD(camera->angle)/2.0f); /* calcs ez as distance from camera plane to viewer */
- }
- else {
- camsize=camera->ortho_scale;
- }
+ UvCameraInfo uci;
- if (invert_m4_m4(invmat,scene->camera->obmat)) {
- copy_m4_m4(rotmat, obedit->obmat);
+ uci.do_pano = (camera->flag & CAM_PANORAMA);
+ uci.do_persp = (camera->type==CAM_PERSP);
+
+ uci.camangle= DEG2RAD(camera->angle)/2.0f;
+ uci.camsize= uci.do_persp ? uci.camsize= tanf(uci.camangle) : camera->ortho_scale;
+
+ if (invert_m4_m4(uci.caminv, v3d->camera->obmat)) {
+
+ /* normal projection */
+ copy_m4_m4(uci.rotmat, obedit->obmat);
/* also make aspect ratio adjustment factors */
if (scene->r.xsch > scene->r.ysch) {
- xasp=1;
- yasp=(float)(scene->r.xsch)/(float)(scene->r.ysch);
+ uci.xasp= 1.0f;
+ uci.yasp= (float)(scene->r.xsch)/(float)(scene->r.ysch);
}
else {
- xasp=(float)(scene->r.ysch)/(float)(scene->r.xsch);
- yasp=1;
+ uci.xasp= (float)(scene->r.ysch)/(float)(scene->r.xsch);
+ uci.yasp= 1.0f;
}
+
+ /* include 0.5f here to move the UVs into the center */
+ uci.shiftx = 0.5f - camera->shiftx;
+ uci.shifty = 0.5f - camera->shifty;
+
BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
if (!BM_TestHFlag(efa, BM_SELECT))
continue;
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
- uv_from_camera(camsize, xasp, yasp, luv->uv, l->v->co, rotmat, invmat, camera->type);
+ uv_from_camera(&uci, luv->uv, l->v->co);
}
}
}