Merging etch-a-ton branch in trunk.
authorMartin Poirier <theeth@yahoo.com>
Mon, 16 Mar 2009 02:55:42 +0000 (02:55 +0000)
committerMartin Poirier <theeth@yahoo.com>
Mon, 16 Mar 2009 02:55:42 +0000 (02:55 +0000)
Slightly out of date documentation in wiki, I'll be updating that tomorrow.

http://wiki.blender.org/index.php/User:Theeth/etch-a-ton

1  2 
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_scene_types.h
source/blender/src/drawview.c
source/blender/src/transform_snap.c

index dc9c97cb3f5f6181c151365e307e2fc1064d725f,7fc2a995a2f2ef7aae6aba899376d98f7e4c40af..2c6a2f2bb3a8ecf7c3d66aa5bf37205d07b4a604
@@@ -7387,47 -7390,7 +7390,25 @@@ static void do_versions(FileData *fd, L
                                ima->flag |= IMA_DO_PREMUL;
                        }
                }
-               if (main->versionfile < 245 || main->subversionfile < 12)
-               {
-                       /* initialize skeleton generation toolsettings */
-                       for(sce=main->scene.first; sce; sce = sce->id.next)
-                       {
-                               sce->toolsettings->skgen_resolution = 50;
-                               sce->toolsettings->skgen_threshold_internal     = 0.01f;
-                               sce->toolsettings->skgen_threshold_external     = 0.01f;
-                               sce->toolsettings->skgen_angle_limit                    = 45.0f;
-                               sce->toolsettings->skgen_length_ratio                   = 1.3f;
-                               sce->toolsettings->skgen_length_limit                   = 1.5f;
-                               sce->toolsettings->skgen_correlation_limit              = 0.98f;
-                               sce->toolsettings->skgen_symmetry_limit                 = 0.1f;
-                               sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
-                               sce->toolsettings->skgen_postpro_passes = 1;
-                               sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_SUB_CORRELATION;
-                               sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
-                               sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
-                               sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
-                       }
-               }
        }
 +      
 +      /* sanity check for skgen
 +       * */
 +      {
 +              Scene *sce;
 +              for(sce=main->scene.first; sce; sce = sce->id.next)
 +              {
 +                      if (sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[1] ||
 +                              sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[2] ||
 +                              sce->toolsettings->skgen_subdivisions[1] == sce->toolsettings->skgen_subdivisions[2])
 +                      {
 +                                      sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
 +                                      sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
 +                                      sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
 +                      }
 +              }
 +      }
 +      
  
        if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 2)) {
                Image *ima;
                }
        }
        
 -      if (main->versionfile < 248 || main->subversionfile < 2)
 -      {
 +      if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 2)) {
                Scene *sce;
                
 -              for(sce=main->scene.first; sce; sce = sce->id.next)
 -              {
 -                      /* Note, these will need to be added for painting */
 +              /* Note, these will need to be added for painting */
 +              for (sce= main->scene.first; sce; sce= sce->id.next) {
                        sce->toolsettings->imapaint.seam_bleed = 2;
                        sce->toolsettings->imapaint.normal_angle = 80;
+                       /* initialize skeleton generation toolsettings */
+                       sce->toolsettings->skgen_resolution = 250;
+                       sce->toolsettings->skgen_threshold_internal     = 0.1f;
+                       sce->toolsettings->skgen_threshold_external     = 0.1f;
+                       sce->toolsettings->skgen_angle_limit                    = 30.0f;
+                       sce->toolsettings->skgen_length_ratio                   = 1.3f;
+                       sce->toolsettings->skgen_length_limit                   = 1.5f;
+                       sce->toolsettings->skgen_correlation_limit              = 0.98f;
+                       sce->toolsettings->skgen_symmetry_limit                 = 0.1f;
+                       sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
+                       sce->toolsettings->skgen_postpro_passes = 3;
+                       sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_SUB_CORRELATION|SKGEN_HARMONIC;
+                       sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
+                       sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
+                       sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
+                       
+                       sce->toolsettings->skgen_retarget_angle_weight = 1.0f;
+                       sce->toolsettings->skgen_retarget_length_weight = 1.0f;
+                       sce->toolsettings->skgen_retarget_distance_weight = 1.0f;
+       
+                       /* Skeleton Sketching */
+                       sce->toolsettings->bone_sketching = 0;
+                       sce->toolsettings->skgen_retarget_roll = SK_RETARGET_ROLL_VIEW;
                }
        }
 -
 +      
-       
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
  
index 09c2344d53acc6abebf6370f4f99251deeaa794c,35e086b418adb79cf64df9bfa0b76995f9508a98..b8a734b6e941ffa5b7a616b29784b26626e3c762
@@@ -892,6 -902,25 +902,25 @@@ typedef struct Scene 
  #define SKGEN_AVERAGE                 1
  #define SKGEN_SHARPEN                 2
  
 -#define       SK_CONVERT_CUT_FIXED                    1
 -#define       SK_CONVERT_CUT_LENGTH                   2
 -#define       SK_CONVERT_CUT_ADAPTATIVE               3
 -#define       SK_CONVERT_RETARGET                             4
+ /* toolsettings->bone_sketching */
+ #define BONE_SKETCHING                        1
+ #define BONE_SKETCHING_QUICK  2
+ #define BONE_SKETCHING_ADJUST 4
+ /* toolsettings->bone_sketching_convert */
++#define       SK_CONVERT_CUT_FIXED                    0
++#define       SK_CONVERT_CUT_LENGTH                   1
++#define       SK_CONVERT_CUT_ADAPTATIVE               2
++#define       SK_CONVERT_RETARGET                             3
+ /* toolsettings->skgen_retarget_options */
+ #define       SK_RETARGET_AUTONAME                    1
+ /* toolsettings->skgen_retarget_roll */
+ #define       SK_RETARGET_ROLL_VIEW                   1
+ #define       SK_RETARGET_ROLL_JOINT                  2
  #ifdef __cplusplus
  }
  #endif
index 44b61c816a55e94bd9d2996eda966f14cddad033,cb4fa246562569c67a5b6524a1ee4c0a62c54784..2cc8a9510a6acb70135fae03e8fe3598329e37e8
@@@ -2272,6 -2274,141 +2274,141 @@@ static void view3d_panel_transform_spac
        if(yco < 0) uiNewPanelHeight(block, height-yco);
  }
  
 -              uiDefButC(block, MENU, B_REDR, "Subdivision Method%t|Length%x2|Adaptative%x3|Fixed%x1|Template%x4", 10,yco,60,19, &G.scene->toolsettings->bone_sketching_convert, 0, 0, 0, 0, subdiv_tooltip[(unsigned char)G.scene->toolsettings->bone_sketching_convert]);
+ static void delete_sketch_armature(void *arg1, void *arg2)
+ {
+       BIF_deleteSketch();
+ }
+ static void convert_sketch_armature(void *arg1, void *arg2)
+ {
+       BIF_convertSketch();
+ }
+ static void assign_template_sketch_armature(void *arg1, void *arg2)
+ {
+       int index = *(int*)arg1;
+       BIF_setTemplate(index);
+ }
+ static void view3d_panel_bonesketch_spaces(short cntrl)
+ {
+       static int template_index;
+       static char joint_label[128];
+       uiBlock *block;
+       uiBut *but;
+       char *bone_name;
+       int yco = 130, height = 140;
+       int nb_joints;
+       /* replace with check call to sketching lib */
+       if (G.obedit && G.obedit->type == OB_ARMATURE)
+       {
+               static char subdiv_tooltip[4][64] = {
+                       "Subdivide arcs based on a fixed number of bones",
+                       "Subdivide arcs in bones of equal length",
+                       "Subdivide arcs based on correlation",
+                       "Retarget template to stroke"
+                       };
+               
+               block= uiNewBlock(&curarea->uiblocks, "view3d_panel_bonesketch_spaces", UI_EMBOSS, UI_HELV, curarea->win);
+               uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE  | cntrl);
+               uiSetPanelHandler(VIEW3D_HANDLER_BONESKETCH);  // for close and esc
+       
+               if(uiNewPanel(curarea, block, "Bone Sketching", "View3d", 10, 230, 250, height)==0) return;
+       
+               uiNewPanelHeight(block, height);
+       
+               uiBlockBeginAlign(block);
+               
+               /* use real flag instead of 1 */
+               uiDefButBitC(block, TOG, BONE_SKETCHING, B_REDR, "Use Bone Sketching", 10, yco, 160, 20, &G.scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Use sketching to create and edit bones");
+               uiDefButBitC(block, TOG, BONE_SKETCHING_ADJUST, B_REDR, "A", 170, yco, 20, 20, &G.scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Adjust strokes by drawing near them");
+               uiDefButBitC(block, TOG, BONE_SKETCHING_QUICK, B_REDR, "Q", 190, yco, 20, 20, &G.scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Automatically convert and delete on stroke end");
+               yco -= 20;
+               
+               but = uiDefBut(block, BUT, B_REDR, "Convert", 10,yco,100,20, 0, 0, 0, 0, 0, "Convert sketch to armature");
+               uiButSetFunc(but, convert_sketch_armature, NULL, NULL);
+               but = uiDefBut(block, BUT, B_REDR, "Delete", 110,yco,100,20, 0, 0, 0, 0, 0, "Delete sketch");
+               uiButSetFunc(but, delete_sketch_armature, NULL, NULL);
+               yco -= 20;
+               
+               uiBlockEndAlign(block);
+               uiBlockBeginAlign(block);
+               
++              uiDefButC(block, MENU, B_REDR, "Subdivision Method%t|Length%x1|Adaptative%x2|Fixed%x0|Template%x3", 10,yco,60,19, &G.scene->toolsettings->bone_sketching_convert, 0, 0, 0, 0, subdiv_tooltip[(unsigned char)G.scene->toolsettings->bone_sketching_convert]);
+               switch(G.scene->toolsettings->bone_sketching_convert)
+               {
+               case SK_CONVERT_CUT_LENGTH:
+                       uiDefButF(block, NUM, B_REDR,                                   "Lim:",         70, yco, 140, 19, &G.scene->toolsettings->skgen_length_limit,0.1,50.0, 10, 0,           "Maximum length of the subdivided bones");
+                       yco -= 20;
+                       break;
+               case SK_CONVERT_CUT_ADAPTATIVE:
+                       uiDefButF(block, NUM, B_REDR,                                   "Thres:",                       70, yco, 140, 19, &G.scene->toolsettings->skgen_correlation_limit,0.0, 1.0, 0.01, 0,    "Correlation threshold for subdivision");
+                       yco -= 20;
+                       break;
+               default:
+               case SK_CONVERT_CUT_FIXED:
+                       uiDefButC(block, NUM, B_REDR,                                   "Num:",         70, yco, 140, 19, &G.scene->toolsettings->skgen_subdivision_number,1, 100, 1, 5,        "Number of subdivided bones");
+                       yco -= 20;
+                       break;
+               case SK_CONVERT_RETARGET:
+                       uiDefButC(block, ROW, B_DIFF, "No",                     70,  yco, 40,19, &G.scene->toolsettings->skgen_retarget_roll, 0, 0, 0, 0,                                                                       "No special roll treatment");
+                       uiDefButC(block, ROW, B_DIFF, "View",           110,  yco, 50,19, &G.scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_VIEW, 0, 0,                          "Roll bones perpendicular to view");
+                       uiDefButC(block, ROW, B_DIFF, "Joint",          160, yco, 50,19, &G.scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_JOINT, 0, 0,                          "Roll bones relative to joint bend");
+                       yco -= 30;
+                       uiBlockEndAlign(block);
+                       uiBlockBeginAlign(block);
+                       /* button here to select what to do (copy or not), template, ...*/
+                       BIF_makeListTemplates();
+                       template_index = BIF_currentTemplate();
+                       
+                       but = uiDefButI(block, MENU, B_REDR, BIF_listTemplates(), 10,yco,200,19, &template_index, 0, 0, 0, 0, "Template");
+                       uiButSetFunc(but, assign_template_sketch_armature, &template_index, NULL);
+                       
+                       yco -= 20;
+                       
+                       uiDefButF(block, NUM, B_DIFF,                                                   "A:",                   10, yco, 66,19, &G.scene->toolsettings->skgen_retarget_angle_weight, 0, 10, 1, 0,               "Angle Weight");
+                       uiDefButF(block, NUM, B_DIFF,                                                   "L:",                   76, yco, 67,19, &G.scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0,              "Length Weight");
+                       uiDefButF(block, NUM, B_DIFF,                                                   "D:",           143,yco, 67,19, &G.scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0,            "Distance Weight");
+                       yco -= 20;
+                       
+                       uiDefBut(block, TEX,B_DIFF,"S:",                                                        10,  yco, 90, 20, G.scene->toolsettings->skgen_side_string, 0.0, 8.0, 0, 0, "Text to replace &S with");
+                       uiDefBut(block, TEX,B_DIFF,"N:",                                                        100, yco, 90, 20, G.scene->toolsettings->skgen_num_string, 0.0, 8.0, 0, 0, "Text to replace &N with");
+                       uiDefIconButBitC(block, TOG, SK_RETARGET_AUTONAME, B_DIFF, ICON_AUTO,190,yco,20,20, &G.scene->toolsettings->skgen_retarget_options, 0, 0, 0, 0, "Use Auto Naming");     
+                       yco -= 20;
+       
+                       /* auto renaming magic */
+                       uiBlockEndAlign(block);
+                       
+                       nb_joints = BIF_nbJointsTemplate();
+       
+                       if (nb_joints == -1)
+                       {
+                               nb_joints = G.totvertsel;
+                       }
+                       
+                       bone_name = BIF_nameBoneTemplate();
+                       
+                       BLI_snprintf(joint_label, 32, "%i joints: %s", nb_joints, bone_name);
+                       
+                       uiDefBut(block, LABEL, 1, joint_label,                                  10, yco, 200, 20, NULL, 0.0, 0.0, 0, 0, "");
+                       yco -= 20;
+                       break;
+               }
+               uiBlockEndAlign(block);
+               
+               uiDefButBitS(block, TOG, SCE_SNAP_PEEL_OBJECT, B_DIFF, "Peel Objects", 10, yco, 200, 20, &G.scene->snap_flag, 0, 0, 0, 0, "Peel whole objects as one");
+               if(yco < 0) uiNewPanelHeight(block, height-yco);
+       }
+ }
  
  static void view3d_panel_object(short cntrl)  // VIEW3D_HANDLER_OBJECT
  {
index eeb5eaeec10d4546607b991c87a6d57a4ec55f5c,6be8b0e881a7397fe74a57ea1fd5eca8b6446d31..99a6c3713a93565b546382f49e46624af8f6b29b
@@@ -1186,21 -1563,10 +1563,11 @@@ int peelObjects(ListBase *depth_peels, 
                                        Object *ob = dupli_ob->ob;
                                        
                                        if (ob->type == OB_MESH) {
 -                                              DerivedMesh *dm = mesh_get_derived_final(ob, CD_MASK_BAREMESH);
 +                                              DerivedMesh *dm;
 +                                              int editmesh = 0;
                                                int val;
                                                
-                                               if (ob == G.obedit)
-                                               {
-                                                       dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
-                                                       editmesh = 1;
-                                               }
-                                               else
-                                               {
-                                                       dm = mesh_get_derived_final(ob, CD_MASK_BAREMESH);
-                                               }
-                                               
-                                               val = snapDerivedMesh(ob, dm, dupli_ob->mat, ray_start, ray_normal, mval, loc, no, dist, &depth, editmesh);
+                                               val = peelDerivedMesh(ob, dm, dupli_ob->mat, ray_start, ray_normal, mval, depth_peels);
        
                                                retval = retval || val;