Fix for add hook/vertex parent for meshes
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 19 Sep 2011 08:25:31 +0000 (08:25 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 19 Sep 2011 08:25:31 +0000 (08:25 +0000)
The only way to achieve this is to re-load editMesh.
After this commit you can't iterate through vertices and insert
hooks/parents from script anymore -- this operators are now
treated as topology-changing and shouldn't be used when iterating
via geometries.

source/blender/editors/object/object_hook.c
source/blender/editors/object/object_relations.c

index fd4581a..09db4b8 100644 (file)
@@ -292,7 +292,7 @@ static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, flo
        return totvert;
 }
 
-static int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
+static int object_hook_index_array(Scene *scene, Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
 {
        *indexar= NULL;
        *tot= 0;
@@ -302,7 +302,12 @@ static int object_hook_index_array(Object *obedit, int *tot, int **indexar, char
                case OB_MESH:
                {
                        Mesh *me= obedit->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
+                       EditMesh *em;
+
+                       load_editMesh(scene, obedit);
+                       make_editMesh(scene, obedit);
+
+                       em = BKE_mesh_get_editmesh(me);
 
                        /* check selected vertices first */
                        if( return_editmesh_indexar(em, tot, indexar, cent_r)) {
@@ -427,7 +432,7 @@ static void add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *o
        int tot, ok, *indexar;
        char name[32];
        
-       ok = object_hook_index_array(obedit, &tot, &indexar, name, cent);
+       ok = object_hook_index_array(scene, obedit, &tot, &indexar, name, cent);
        
        if (!ok) return;        // XXX error("Requires selected vertices or active Vertex Group");
        
@@ -760,7 +765,7 @@ static int object_hook_assign_exec(bContext *C, wmOperator *op)
        
        /* assign functionality */
        
-       if(!object_hook_index_array(ob, &tot, &indexar, name, cent)) {
+       if(!object_hook_index_array(CTX_data_scene(C), ob, &tot, &indexar, name, cent)) {
                BKE_report(op->reports, RPT_WARNING, "Requires selected vertices or active vertex group");
                return OPERATOR_CANCELLED;
        }
index 4d7f6fa..97c9b2d 100644 (file)
@@ -95,6 +95,7 @@
 #include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
+#include "ED_mesh.h"
 
 #include "object_intern.h"
 
@@ -122,7 +123,12 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
        
        if(obedit->type==OB_MESH) {
                Mesh *me= obedit->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
+               EditMesh *em;
+
+               load_editMesh(scene, obedit);
+               make_editMesh(scene, obedit);
+
+               em = BKE_mesh_get_editmesh(me);
 
                eve= em->verts.first;
                while(eve) {