[Bf-blender-cvs] [a6a3989] master: Texture Paint Add Simple UVs:

Antony Riakiotakis noreply at git.blender.org
Fri Oct 31 14:38:12 CET 2014


Commit: a6a3989617e680327bda2357fe506d86574e2618
Author: Antony Riakiotakis
Date:   Fri Oct 31 14:37:36 2014 +0100
Branches: master
https://developer.blender.org/rBa6a3989617e680327bda2357fe506d86574e2618

Texture Paint Add Simple UVs:

Add simple uvs now does a cube unwrap and pack operation. Result is not
optimal by far but it should not result in crashes and it will be quite
usable for simple cases.

===================================================================

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/include/ED_uvedit.h
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_ops.c
M	source/blender/editors/uvedit/uvedit_intern.h
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/editors/uvedit/uvedit_smart_stitch.c
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 81cdaf6..2218886 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -794,7 +794,7 @@ class VIEW3D_PT_imapaint_tools_missing(Panel, View3DPaintPanel):
             col.separator()
             col.label("Missing UVs", icon='INFO')
             col.label("Unwrap the mesh in edit mode or generate a simple UVs")
-            col.operator("mesh.uv_texture_add", text="Add Simple UVs")
+            col.operator("paint.add_simple_uvs")
     
         if toolsettings.mode == 'MATERIAL':
             if toolsettings.missing_materials:
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 6a562da..c9faad6 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -267,6 +267,7 @@ void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int
 void ED_mesh_calc_tessface(struct Mesh *mesh);
 void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges, int calc_tessface);
 
+void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name);
 int  ED_mesh_uv_texture_add(struct Mesh *me, const char *name, const bool active_set);
 bool ED_mesh_uv_texture_remove_index(struct Mesh *me, const int n);
 bool ED_mesh_uv_texture_remove_active(struct Mesh *me);
diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h
index 4b82fa4..70dc003 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -31,6 +31,7 @@
 #define __ED_UVEDIT_H__
 
 struct ARegionType;
+struct BMesh;
 struct BMEditMesh;
 struct BMFace;
 struct BMLoop;
@@ -52,6 +53,7 @@ void ED_keymap_uvedit(struct wmKeyConfig *keyconf);
 
 void ED_uvedit_assign_image(struct Main *bmain, struct Scene *scene, struct Object *obedit, struct Image *ima, struct Image *previma);
 bool ED_uvedit_minmax(struct Scene *scene, struct Image *ima, struct Object *obedit, float min[2], float max[2]);
+void ED_uvedit_select_all(struct BMesh *bm);
 
 bool ED_object_get_active_image(struct Object *ob, int mat_nr,
                                 struct Image **r_ima, struct ImageUser **r_iuser, struct bNode **r_node, struct bNodeTree **r_ntree);
@@ -98,10 +100,13 @@ void ED_uvedit_live_unwrap_re_solve(void);
 void ED_uvedit_live_unwrap_end(short cancel);
 
 void ED_uvedit_live_unwrap(struct Scene *scene, struct Object *obedit);
+void ED_uvedit_pack_islands(struct Scene *scene, struct Object *ob, struct BMesh *bm, bool selected, bool correct_aspect, bool do_rotate);
+void ED_uvedit_cube_project_unwrap(struct Object *ob, struct BMesh *bm, float cube_size, bool use_select);
 
 /* single call up unwrap using scene settings, used for edge tag unwrapping */
 void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel);
 
+
 /* uvedit_draw.c */
 void draw_image_cursor(struct ARegion *ar, const float cursor[2]);
 void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit, struct Object *obact);
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 68471bf..e2ce97a 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -336,6 +336,26 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
 	return layernum_dst;
 }
 
+void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name)
+{
+	BMEditMesh *em;
+	int layernum_dst;
+
+	if (me->edit_btmesh) {
+		em = me->edit_btmesh;
+
+		layernum_dst = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
+		if (layernum_dst == 0)
+			ED_mesh_uv_texture_add(me, name, true);
+	}
+	else {
+		layernum_dst = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+		if (layernum_dst == 0)
+			ED_mesh_uv_texture_add(me, name, true);
+	}
+}
+
+
 bool ED_mesh_uv_texture_remove_index(Mesh *me, const int n)
 {
 	CustomData *pdata = GET_CD_DATA(me, pdata), *ldata = GET_CD_DATA(me, ldata);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 214084a..e1b3348 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -105,6 +105,9 @@
 
 #include "IMB_colormanagement.h"
 
+#include "bmesh.h"
+//#include "bmesh_tools.h"
+
 #include "paint_intern.h"
 
 /* Defines and Structs */
@@ -5233,9 +5236,9 @@ static int texture_paint_delete_texture_paint_slot_exec(bContext *C, wmOperator
 	
 	BKE_texpaint_slot_refresh_cache(scene, ma);
 	DAG_id_tag_update(&ma->id, 0);
-	WM_event_add_notifier(C, NC_MATERIAL, CTX_data_scene(C));
+	WM_event_add_notifier(C, NC_MATERIAL, ma);
 	/* we need a notifier for data change since we change the displayed modifier uvs */
-	WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);			
+	WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
 	return OPERATOR_FINISHED;
 }
 
@@ -5254,3 +5257,64 @@ void PAINT_OT_delete_texture_paint_slot(wmOperatorType *ot)
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
+
+static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	/* no checks here, poll function does them for us */
+	Object *ob = CTX_data_active_object(C);
+	Scene *scene = CTX_data_scene(C);
+	Mesh *me = ob->data;
+	bool synch_selection = (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
+
+	BMesh *bm = BM_mesh_create(&bm_mesh_allocsize_default);
+
+	/* turn synch selection off, since we are not in edit mode we need to ensure only the uv flags are tested */
+	scene->toolsettings->uv_flag &= ~UV_SYNC_SELECTION;
+
+	ED_mesh_uv_texture_ensure(me, NULL);
+
+	BM_mesh_bm_from_me(bm, me, true, false, 0);
+
+	/* select all uv loops first - pack parameters needs this to make sure charts are registered */
+	ED_uvedit_select_all(bm);
+	ED_uvedit_cube_project_unwrap(ob, bm, 1.0, false);
+	/* set the margin really quickly before the packing operation*/
+	scene->toolsettings->uvcalc_margin = 0.001f;
+	ED_uvedit_pack_islands(scene, ob, bm, false, false, true);
+	BM_mesh_bm_to_me(bm, me, false);
+	BM_mesh_free(bm);
+
+	if (synch_selection)
+		scene->toolsettings->uv_flag |= UV_SYNC_SELECTION;
+
+	DAG_id_tag_update(ob->data, 0);
+	WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+	WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, scene);
+	return OPERATOR_FINISHED;
+}
+
+static int add_simple_uvs_poll(bContext *C)
+{
+	Object *ob = CTX_data_active_object(C);
+
+	if (!ob || ob->type != OB_MESH || ob->mode != OB_MODE_TEXTURE_PAINT)
+		return false;
+
+	return true;
+}
+
+void PAINT_OT_add_simple_uvs(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Add simple UVs";
+	ot->description = "Add cube map uvs on mesh";
+	ot->idname = "PAINT_OT_add_simple_uvs";
+
+	/* api callbacks */
+	ot->exec = add_simple_uvs_exec;
+	ot->poll = add_simple_uvs_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index c3b7ec6..b89d99c 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -184,6 +184,7 @@ void PAINT_OT_image_from_view(struct wmOperatorType *ot);
 void PAINT_OT_add_texture_paint_slot(struct wmOperatorType *ot);
 void PAINT_OT_delete_texture_paint_slot(struct wmOperatorType *ot);
 void PAINT_OT_image_paint(struct wmOperatorType *ot);
+void PAINT_OT_add_simple_uvs(struct wmOperatorType *ot);
 
 /* uv sculpting */
 int uv_sculpt_poll(struct bContext *C);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index dc6be9c..2a09b0c 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -1085,6 +1085,7 @@ void ED_operatortypes_paint(void)
 	WM_operatortype_append(PAINT_OT_brush_colors_flip);
 	WM_operatortype_append(PAINT_OT_add_texture_paint_slot);
 	WM_operatortype_append(PAINT_OT_delete_texture_paint_slot);
+	WM_operatortype_append(PAINT_OT_add_simple_uvs);
 
 	/* weight */
 	WM_operatortype_append(PAINT_OT_weight_paint_toggle);
diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h
index 52365ff..8865bc6 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -41,6 +41,7 @@ struct SpaceImage;
 struct UvElementMap;
 struct wmOperatorType;
 struct BMEditMesh;
+struct BMesh;
 struct BMFace;
 struct BMLoop;
 struct BMEdge;
@@ -71,7 +72,7 @@ void uv_find_nearest_edge(struct Scene *scene, struct Image *ima, struct BMEditM
 /* utility tool functions */
 
 void uvedit_live_unwrap_update(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit);
-void uvedit_get_aspect(struct Scene *scene, struct Object *ob, struct BMEditMesh *em, float *aspx, float *aspy);
+void uvedit_get_aspect(struct Scene *scene, struct Object *ob, struct BMesh *em, float *aspx, float *aspy);
 
 /* operators */
 
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 4b34154..35a9bb9 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -668,6 +668,24 @@ bool ED_uvedit_minmax(Scene *scene, Image *ima, Object *obedit, float r_min[2],
 	return changed;
 }
 
+/* Be careful when using this, it bypasses all synchronization options */
+void ED_uvedit_select_all(BMesh *bm)
+{
+	BMFace *efa;
+	BMLoop *l;
+	BMIter iter, liter;
+	MLoopUV *luv;
+
+	const int cd_loop_uv_offset  = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
+
+	BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+		BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+			luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+			luv->flag |= MLOOPUV_VERTSEL;
+		}
+	}
+}
+
 static bool ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[2])
 {
 	BMEditMe

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list