[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38133] branches/soc-2011-onion: Vertex Weights Export Tool

Antony Riakiotakis kalast at gmail.com
Wed Jul 6 01:27:57 CEST 2011


Revision: 38133
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38133
Author:   psy-fi
Date:     2011-07-05 23:27:57 +0000 (Tue, 05 Jul 2011)
Log Message:
-----------
Vertex Weights Export Tool
=====================
-added display function, missing the actual draw code but everything is almost set.

Probably will need to implement own Framebuffer Object initialization to get float format, or will try to tweak existing GPU_offscreen_create.

Modified Paths:
--------------
    branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2011-onion/source/blender/editors/include/ED_view3d.h
    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/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-07-05 22:33:01 UTC (rev 38132)
+++ branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-07-05 23:27:57 UTC (rev 38133)
@@ -1119,7 +1119,7 @@
 
     def draw(self, context):
         layout = self.layout
-
+        ipaint = context.tool_settings.image_paint
         ob = context.active_object
 
         col = layout.column()
@@ -1130,6 +1130,8 @@
         col.operator("object.vertex_group_clean", text="Clean")
         col.operator("object.vertex_group_levels", text="Levels")
         col.operator("paint.weight_layers_image_from_view", text="Save As Layered Image")
+        row = col.row(align=True)
+        row.prop(ipaint, "screen_grab_size", text="")
 
 
 class VIEW3D_PT_tools_weightpaint_options(View3DPanel, bpy.types.Panel):

Modified: branches/soc-2011-onion/source/blender/editors/include/ED_view3d.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/include/ED_view3d.h	2011-07-05 22:33:01 UTC (rev 38132)
+++ branches/soc-2011-onion/source/blender/editors/include/ED_view3d.h	2011-07-05 23:27:57 UTC (rev 38133)
@@ -275,6 +275,7 @@
 
 struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag, char err_out[256]);
 struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Scene *scene, struct Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256]);
+int view3d_weight_offscreen_draw(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, struct Object *ob, int w, int h);
 
 
 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);

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-05 22:33:01 UTC (rev 38132)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c	2011-07-05 23:27:57 UTC (rev 38133)
@@ -96,6 +96,7 @@
 #include "RNA_enum_types.h"
 
 #include "GPU_draw.h"
+#include "GPU_extensions.h"
 
 #include "paint_intern.h"
 
@@ -5596,9 +5597,27 @@
 	RNA_def_string_file_name(ot->srna, "filepath", "", FILE_MAX, "File Path", "Name of the file");
 }
 
+/* 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 */
 static int weight_layers_image_from_view_exec(bContext *C, wmOperator *op)
 {
-	return OPERATOR_FINISHED;
+//	char filename[FILE_MAX];
+	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);
+
+	ToolSettings *settings= scene->toolsettings;
+	int w= settings->imapaint.screen_grab_size[0];
+	int h= settings->imapaint.screen_grab_size[1];
+
+	if(view3d_weight_offscreen_draw(scene, v3d, ar, ob, w, h))
+		return OPERATOR_FINISHED;
+	else return OPERATOR_CANCELLED;
+
+//	RNA_string_get(op->ptr, "filepath", filename);
+
+
 }
 
 void PAINT_OT_weight_layers_image_from_view(wmOperatorType *ot)
@@ -5615,5 +5634,6 @@
 	/* flags */
 	ot->flag= OPTYPE_REGISTER;
 
+	/* Copied from above, may come in handy */
 //	RNA_def_string_file_name(ot->srna, "filepath", "", FILE_MAX, "File Path", "Name of the file");
 }

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-05 22:33:01 UTC (rev 38132)
+++ branches/soc-2011-onion/source/blender/editors/space_view3d/view3d_draw.c	2011-07-05 23:27:57 UTC (rev 38133)
@@ -2686,3 +2686,118 @@
 
 	v3d->flag |= V3D_INVALID_BACKBUF;
 }
+
+int view3d_weight_offscreen_draw(Scene *scene, View3D *v3d, ARegion *ar, Object *ob, int w, int h)
+{
+	GPUOffScreen *ofs;
+	int maxsize;
+	float *winmatarg = NULL;
+	float winmat[4][4];
+	RegionView3D *rv3d= ar->regiondata;
+	char err_out[256] = "unknown";
+	int bwinx, bwiny;
+	rcti brect;
+	int zbufbackup = v3d->zbuf;
+
+	/* render 3d view */
+	if(rv3d->persp==RV3D_CAMOB && v3d->camera) {
+		float _clipsta, _clipend, _lens, _yco, _dx, _dy;
+		rctf _viewplane;
+
+		object_camera_matrix(&scene->r, v3d->camera, w, h, 0, winmat, &_viewplane, &_clipsta, &_clipend, &_lens, &_yco, &_dx, &_dy);
+		winmatarg = &winmat[0][0];
+	}
+
+	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 0;
+
+	GPU_offscreen_bind(ofs);
+
+	glPushMatrix();
+
+	/* set temporary new size */
+	bwinx= ar->winx;
+	bwiny= ar->winy;
+	brect= ar->winrct;
+
+	ar->winx= w;
+	ar->winy= h;
+	ar->winrct.xmin= 0;
+	ar->winrct.ymin= 0;
+	ar->winrct.xmax= w;
+	ar->winrct.ymax= h;
+
+
+	/* set flags */
+	G.f |= G_RENDER_OGL;
+
+	glClearColor(0.0, 0.0, 0.0, 0.0);
+
+	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+
+	/* setup view matrices */
+	view3d_main_area_setup_view(scene, v3d, ar, NULL, winmatarg);
+
+	/* set zbuffer */
+	v3d->zbuf= TRUE;
+	glEnable(GL_DEPTH_TEST);
+
+	ED_view3d_init_mats_rv3d_gl(ob, rv3d);
+
+	/*
+	if(scene->set) {
+		Scene *sce_iter;
+		for(SETLOOPER(scene->set, sce_iter, base)) {
+			if(v3d->lay & base->lay) {
+				UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
+				draw_object(scene, ar, v3d, base, DRAW_CONSTCOLOR|DRAW_SCENESET);
+
+				if(base->object->transflag & OB_DUPLI)
+					draw_dupli_objects_color(scene, ar, v3d, base, TH_WIRE);
+			}
+		}
+	}
+
+	for(base= scene->base.first; base; base= base->next) {
+		if(v3d->lay & base->lay) {
+			if(base->object->transflag & OB_DUPLI)
+				draw_dupli_objects(scene, ar, v3d, base);
+
+			draw_object(scene, ar, v3d, base, 0);
+		}
+	}
+	 */
+
+	/* cleanup */
+	if(!zbufbackup) {
+		v3d->zbuf= FALSE;
+		glDisable(GL_DEPTH_TEST);
+	}
+
+	/* restore size */
+	ar->winx= bwinx;
+	ar->winy= bwiny;
+	ar->winrct = brect;
+
+	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 1;
+}




More information about the Bf-blender-cvs mailing list