Revision: 38170
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38170
Author:   psy-fi
Date:     2011-07-07 00:58:04 +0000 (Thu, 07 Jul 2011)
Log Message:
-----------
Vertex Weights Export Tool
=====================

*Completed the tool, To check out, see Weight paint mode->tools->save weight 
images
*Missing is ability to select export directory(maybe will make a python wrapper 
for that?), for now exporting to binary directory.

Final decision is to export as multiple png's. The filename format is <object 
name>_<group name>.png. I did this for various reasons, first, if I used 
layered tiff I had to implement layered tiff export, which required me to go 
over the specification. Too time consuming. Multilayered OpenEXR is not 
supported in GIMP out of the box so I went for the simpler and easier solution.

Modified Paths:
--------------
    
branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    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-06 21:37:31 UTC (rev 38169)
+++ 
branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py   
    2011-07-07 00:58:04 UTC (rev 38170)
@@ -1129,7 +1129,8 @@
         col.operator("object.vertex_group_invert", text="Invert")
         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")
+        col.operator("paint.weight_layers_image_from_view", text="Save Weight 
Images")
+       #lazy stuff, but maybe not so, export size should be unified. Maybe add 
better description to rna?
         row = col.row(align=True)
         row.prop(ipaint, "screen_grab_size", text="")
 

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-06 21:37:31 UTC (rev 38169)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c   
2011-07-07 00:58:04 UTC (rev 38170)
@@ -5625,7 +5625,7 @@
        /* identifiers */
        ot->name= "Weight layers image from View";
        ot->idname= "PAINT_OT_weight_layers_image_from_view";
-       ot->description= "Make an openEXR image containing luminance layers for 
each vertex group of the active object from the current 3D view";
+       ot->description= "Make multiple png images from vertex group of the 
active object as seen from the current view";
 
        /* api callbacks */
        ot->exec= weight_layers_image_from_view_exec;

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-06 21:37:31 UTC (rev 38169)
+++ branches/soc-2011-onion/source/blender/editors/space_view3d/view3d_draw.c   
2011-07-07 00:58:04 UTC (rev 38170)
@@ -44,6 +44,7 @@
 #include "DNA_lamp_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_world_types.h"
+#include "DNA_meshdata_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -63,6 +64,8 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_unit.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_deform.h"
 
 #include "RE_pipeline.h"       // make_stars
 
@@ -2698,8 +2701,23 @@
        int bwinx, bwiny;
        rcti brect;
        int zbufbackup = v3d->zbuf;
+       DerivedMesh *dm = mesh_get_derived_final(scene, ob, 
scene->customdata_mask);
+       int numOfQuads = 0;
+       MDeformVert *dw;
+       ImBuf *ibuf;
+       bDeformGroup *defgrp;
+       int defnum = 0;
+       int numOfFaces;
+       int numOfVerts;
+       MVert *verts;
+       MFace *faces;
+       unsigned char *weightColors;
+       int i;
 
-       /* render 3d view */
+       int *quadIndices, *triIndices;
+       unsigned int tri_buf_index = 0, quad_buf_index = 0;
+
+       /* change camera matrix if object camera */
        if(rv3d->persp==RV3D_CAMOB && v3d->camera) {
                float _clipsta, _clipend, _lens, _yco, _dx, _dy;
                rctf _viewplane;
@@ -2719,6 +2737,13 @@
        if(ofs == NULL)
                return 0;
 
+       ibuf= IMB_allocImBuf(w, h, 32, IB_rect);
+       if(!ibuf){
+               GPU_offscreen_free(ofs);
+               return 0;
+       }
+       ibuf->ftype = PNG;
+
        GPU_offscreen_bind(ofs);
 
        glPushMatrix();
@@ -2739,49 +2764,115 @@
        /* set flags */
        G.f |= G_RENDER_OGL;
 
+       /* set zbuffer */
+       v3d->zbuf= TRUE;
+       glEnable(GL_DEPTH_TEST);
+
        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);
+       ED_view3d_init_mats_rv3d_gl(ob, rv3d);
 
-       /* set zbuffer */
-       v3d->zbuf= TRUE;
-       glEnable(GL_DEPTH_TEST);
+       /* get our vert groups */
+       dw = dm->getVertDataArray(dm, CD_MDEFORMVERT);
+       verts = dm->getVertArray(dm);
+       faces = dm->getFaceArray(dm);
+       numOfVerts = dm->getNumVerts(dm);
+       numOfFaces = dm->getNumFaces(dm);
 
-       ED_view3d_init_mats_rv3d_gl(ob, rv3d);
+       /* Count the quads */
+       for(i = 0; i < numOfFaces; i++){
+               if((faces + i)->v4){
+                       numOfQuads++;
+               }
+       }
 
-       /*
-       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);
+       quadIndices = MEM_mallocN(numOfQuads*sizeof(unsigned int)*4, "Quad 
Indices for weight export");
+       triIndices = MEM_mallocN((numOfFaces - numOfQuads)*sizeof(unsigned 
int)*3, "Triangle Indices for weight export");
+       weightColors = MEM_mallocN(numOfVerts*4*sizeof(unsigned char), "Weight 
Colors for weight export");
+       if(!(quadIndices && triIndices && weightColors)){
+               if(quadIndices)
+                       MEM_freeN(quadIndices);
+               if(triIndices)
+                       MEM_freeN(triIndices);
+               if(weightColors)
+                       MEM_freeN(weightColors);
+               GPU_offscreen_free(ofs);
+               IMB_freeImBuf(ibuf);
+               return 0;
+       }
 
-                               if(base->object->transflag & OB_DUPLI)
-                                       draw_dupli_objects_color(scene, ar, 
v3d, base, TH_WIRE);
-                       }
+
+       /* fill the index arrays */
+       for(i = 0; i < numOfFaces; i++){
+               MFace *mfa = faces + i;
+               if(mfa->v4){
+                       quadIndices[quad_buf_index++] = mfa->v1;
+                       quadIndices[quad_buf_index++] = mfa->v2;
+                       quadIndices[quad_buf_index++] = mfa->v3;
+                       quadIndices[quad_buf_index++] = mfa->v4;
                }
+               else{
+                       triIndices[tri_buf_index++] = mfa->v1;
+                       triIndices[tri_buf_index++] = mfa->v2;
+                       triIndices[tri_buf_index++] = mfa->v3;
+               }
        }
 
-       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);
+       glColor3f(1.0 ,1.0, 1.0);
+       glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
+       glEnableClientState(GL_VERTEX_ARRAY);
+       glEnableClientState(GL_COLOR_ARRAY);
 
-                       draw_object(scene, ar, v3d, base, 0);
+       glVertexPointer(3, GL_FLOAT, sizeof(MVert), verts);
+       glColorPointer(4, GL_UNSIGNED_BYTE, 0, weightColors);
+
+       glShadeModel(GL_SMOOTH);
+
+       /* Do this for each vertex group */
+       for(defgrp = ob->defbase.first; defgrp; defgrp = defgrp->next, 
defnum++){
+               char filename[1024];
+
+               /* Fill the Weight buffer */
+               for(i = 0; i < numOfVerts; i++){
+                       weightColors[4*i] = weightColors[4*i+1] = 
weightColors[4*i +2] =
+                                       weightColors[4*i + 3] = 
FTOCHAR(defvert_find_weight(dw+i, defnum));
                }
+
+               glDrawElements(GL_TRIANGLES, 3*(numOfFaces - numOfQuads), 
GL_UNSIGNED_INT, triIndices);
+               glDrawElements(GL_QUADS, 4*numOfQuads, GL_UNSIGNED_INT, 
quadIndices);
+
+               /* ready to draw here */
+               glBegin(GL_POINTS);
+               glVertex3f(0.0, 0.0, 0.0);
+               glEnd();
+
+               glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+
+               sprintf(filename, "%s_%s.png", ob->id.name, defgrp->name);
+
+               IMB_saveiff(ibuf, filename, 0);
        }
-        */
+       glPopClientAttrib();
 
+       MEM_freeN(quadIndices);
+       MEM_freeN(triIndices);
+       MEM_freeN(weightColors);
+
        /* cleanup */
        if(!zbufbackup) {
                v3d->zbuf= FALSE;
                glDisable(GL_DEPTH_TEST);
        }
 
+       dm->release(dm);
+
+
+       IMB_freeImBuf(ibuf);
+
        /* restore size */
        ar->winx= bwinx;
        ar->winy= bwiny;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to