[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38738] branches/soc-2011-onion/source/ blender/editors: smart stitch

Antony Riakiotakis kalast at gmail.com
Tue Jul 26 19:23:53 CEST 2011


Revision: 38738
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38738
Author:   psy-fi
Date:     2011-07-26 17:23:52 +0000 (Tue, 26 Jul 2011)
Log Message:
-----------
smart stitch
============================
- weight export tool: Export weights in UV space. Check toolbar in weight paint mode. Object needs UV layer for this to work.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/include/ED_screen.h
    branches/soc-2011-onion/source/blender/editors/screen/screen_ops.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2011-onion/source/blender/editors/space_view3d/view3d_draw.c

Modified: branches/soc-2011-onion/source/blender/editors/include/ED_screen.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/include/ED_screen.h	2011-07-26 16:37:38 UTC (rev 38737)
+++ branches/soc-2011-onion/source/blender/editors/include/ED_screen.h	2011-07-26 17:23:52 UTC (rev 38738)
@@ -169,6 +169,7 @@
 int		ED_operator_editmball(struct bContext *C);
 int		ED_operator_uvedit(struct bContext *C);
 int		ED_operator_uvmap(struct bContext *C);
+int		ED_operator_uvmap_mesh(struct bContext *C);
 int		ED_operator_posemode(struct bContext *C);
 
 

Modified: branches/soc-2011-onion/source/blender/editors/screen/screen_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/screen/screen_ops.c	2011-07-26 16:37:38 UTC (rev 38737)
+++ branches/soc-2011-onion/source/blender/editors/screen/screen_ops.c	2011-07-26 17:23:52 UTC (rev 38738)
@@ -382,6 +382,20 @@
 	return 0;
 }
 
+int ED_operator_uvmap_mesh(bContext *C)
+{
+	Object *ob= CTX_data_active_object(C);
+
+	if(ob && ob->type==OB_MESH){
+		Mesh *me = ob->data;
+		if(CustomData_get_layer(&me->fdata, CD_MTFACE) != NULL){
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 int ED_operator_editsurfcurve(bContext *C)
 {
 	Object *obedit= CTX_data_edit_object(C);

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c	2011-07-26 16:37:38 UTC (rev 38737)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c	2011-07-26 17:23:52 UTC (rev 38738)
@@ -67,6 +67,7 @@
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_cdderivedmesh.h"
 #include "BKE_idprop.h"
 #include "BKE_brush.h"
 #include "BKE_image.h"
@@ -77,6 +78,8 @@
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
+#include "BKE_global.h"
+#include "BKE_deform.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -5605,6 +5608,7 @@
 	int h= settings->imapaint.screen_grab_size[1];
 
 	RNA_string_get(op->ptr, "directory", directory);
+	BLI_cleanup_dir(NULL, directory);
 
 	if(view3d_weight_offscreen_draw(scene, v3d, ar, ob, w, h, directory))
 		return OPERATOR_FINISHED;
@@ -5638,27 +5642,142 @@
 }
 
 
-/* This function is actually a selection of the code path implemented by texture_paint_image_from_view_exec.
- * We really don't need all checks + we need to draw only the selected object */
+/* Similar to above but easier, since we work in uv space */
 static int weight_layers_to_uv_images_exec(bContext *C, wmOperator *op)
 {
-	char filename[FILE_MAX];
+	char directory[FILE_MAXDIR];
 	Scene *scene= CTX_data_scene(C);
-	View3D *v3d = CTX_wm_view3d(C);
-	ARegion *ar =  CTX_wm_region(C);
 	Object *ob = CTX_data_active_object(C);
+	Mesh *me= ob->data;
+	GPUOffScreen *ofs;
+	int maxsize;
+	char err_out[256] = "unknown";
+	MDeformVert *dw;
+	ImBuf *ibuf;
+	bDeformGroup *defgrp;
+	int defnum = 0;
+	int i;
 
 	ToolSettings *settings= scene->toolsettings;
 	int w= settings->imapaint.screen_grab_size[0];
 	int h= settings->imapaint.screen_grab_size[1];
-	RNA_string_get(op->ptr, "directory", filename);
+	RNA_string_get(op->ptr, "directory", directory);
+	BLI_cleanup_dir(NULL, directory);
 
-	//if(view3d_weight_offscreen_draw(scene, v3d, ar, ob, w, h))
-		return OPERATOR_FINISHED;
-	//else return OPERATOR_CANCELLED;
+	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize);
 
+	if(w > maxsize) w= maxsize;
+	if(h > maxsize) h= maxsize;
+
+	glPushAttrib(GL_LIGHTING_BIT);
+
+	ofs= GPU_offscreen_create(&w, &h, err_out);
+	if(ofs == NULL)
+		return OPERATOR_CANCELLED;
+
+	ibuf= IMB_allocImBuf(w, h, 32, IB_rect);
+	if(!ibuf){
+		GPU_offscreen_free(ofs);
+		return OPERATOR_CANCELLED;
+	}
+	ibuf->ftype = PNG;
+
+	GPU_offscreen_bind(ofs);
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glPushMatrix();
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	/* set flags */
+	G.f |= G_RENDER_OGL;
+
+	glClearColor(0.0, 0.0, 0.0, 0.0);
+
+	/* get our vert groups */
+	dw = CustomData_get_layer(&me->vdata, CD_MDEFORMVERT);
+
+	glShadeModel(GL_SMOOTH);
+
+	/* Do this for each vertex group */
+	for(defgrp = ob->defbase.first; defgrp; defgrp = defgrp->next, defnum++){
+		char imagefile[FILE_MAX];
+
+		MFace *mface= me->mface;
+		MTFace *tface= CustomData_get_layer(&me->fdata, CD_MTFACE);
+		int a;
+
+		glClear(GL_COLOR_BUFFER_BIT);
+
+		for(a=me->totface; a>0; a--, tface++, mface++) {
+			float col1 = defvert_find_weight(dw+mface->v1, defnum);
+			float col2 = defvert_find_weight(dw+mface->v2, defnum);
+			float col3 = defvert_find_weight(dw+mface->v3, defnum);
+			if(mface->v4){
+				glBegin(GL_QUADS);
+			}
+			else{
+				glBegin(GL_TRIANGLES);
+			}
+			glColor4f(col1,col1,col1, col1);
+			glVertex2fv(tface->uv[0]);
+			glColor4f(col2,col2,col2,col2);
+			glVertex2fv(tface->uv[1]);
+			glColor4f(col3,col3,col3,col3);
+			glVertex2fv(tface->uv[2]);
+			if(mface->v4){
+				float col4 = defvert_find_weight(dw+mface->v4, defnum);
+				glColor4f(col4,col4,col4,col4);
+				glVertex2fv(tface->uv[3]);
+			}
+			glEnd();
+		}
+
+		glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+
+		i = 0;
+		do{
+			if(i)
+				BLI_snprintf(imagefile, FILE_MAX, "%s%s_%s.%d.png", directory, ob->id.name, defgrp->name, i-1);
+			else
+				BLI_snprintf(imagefile, FILE_MAX, "%s%s_%s.png", directory, ob->id.name, defgrp->name);
+			i++;
+		}while(BLI_exists(imagefile));
+		/* cleanup the name so that it contains no illegal characters*/
+		BLI_clean(imagefile);
+		IMB_saveiff(ibuf, imagefile, 0);
+	}
+
+
+	IMB_freeImBuf(ibuf);
+
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+
+	glColor4ub(255, 255, 255, 255); // XXX, without this the sequencer flickers with opengl draw enabled, need to find out why - campbell
+
+	G.f &= ~G_RENDER_OGL;
+
+	/* unbind */
+	GPU_offscreen_unbind(ofs);
+	GPU_offscreen_free(ofs);
+
+	glPopAttrib();
+
+	return OPERATOR_FINISHED;
 }
 
+static int weight_layers_to_uv_images_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)){
+	if(RNA_property_is_set(op->ptr, "directory"))
+		return weight_layers_to_uv_images_exec(C, op);
+	WM_event_add_fileselect(C, op);
+	return OPERATOR_RUNNING_MODAL;
+}
+
 void PAINT_OT_weight_layers_to_uv_images(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -5667,8 +5786,9 @@
 	ot->description= "Make multiple png images from vertex group of the active object in uv space";
 
 	/* api callbacks */
+	ot->invoke= weight_layers_to_uv_images_invoke;
 	ot->exec= weight_layers_to_uv_images_exec;
-	ot->poll= ED_operator_region_view3d_active;
+	ot->poll= ED_operator_uvmap_mesh;
 
 	/* flags */
 	ot->flag= OPTYPE_REGISTER;

Modified: branches/soc-2011-onion/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/space_view3d/view3d_draw.c	2011-07-26 16:37:38 UTC (rev 38737)
+++ branches/soc-2011-onion/source/blender/editors/space_view3d/view3d_draw.c	2011-07-26 17:23:52 UTC (rev 38738)
@@ -2850,13 +2850,12 @@
 
 		glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
 
-		BLI_cleanup_dir(NULL, directory);
 		i = 0;
 		do{
 			if(i)
-				BLI_snprintf(imagefile, 1024, "%s%s_%s.%d.png", directory, ob->id.name, defgrp->name, i-1);
+				BLI_snprintf(imagefile, FILE_MAX, "%s%s_%s.%d.png", directory, ob->id.name, defgrp->name, i-1);
 			else
-				BLI_snprintf(imagefile, 1024, "%s%s_%s.png", directory, ob->id.name, defgrp->name);
+				BLI_snprintf(imagefile, FILE_MAX, "%s%s_%s.png", directory, ob->id.name, defgrp->name);
 			i++;
 		}while(BLI_exists(imagefile));
 		/* cleanup the name so that it contains no illegal characters*/




More information about the Bf-blender-cvs mailing list