navmesh: solve bad level calls to edit mesh functions
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 27 Sep 2011 09:09:52 +0000 (09:09 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 27 Sep 2011 09:09:52 +0000 (09:09 +0000)
Move navmesh operators from editors/object to editors/mesh

release/scripts/startup/bl_ui/properties_data_modifier.py
release/scripts/startup/bl_ui/properties_game.py
source/blender/editors/mesh/CMakeLists.txt
source/blender/editors/mesh/SConscript
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_navmesh.c [moved from source/blender/editors/object/object_navmesh.c with 93% similarity]
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/object/CMakeLists.txt
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c

index 98466b41c2e1a42e00c9b823bc320e43eb55f59f..d2d4c263d5078d26f7c1cdc0c43882f0af0b3444 100644 (file)
@@ -380,8 +380,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "mirror_object", text="")
 
     def NAVMESH(self, layout, ob, md):
-        layout.operator("object.assign_navpolygon")
-        layout.operator("object.assign_new_navpolygon")
+        layout.operator("mesh.assign_navpolygon")
+        layout.operator("mesh.assign_new_navpolygon")
 
     def MULTIRES(self, layout, ob, md):
         layout.row().prop(md, "subdivision_type", expand=True)
index 8cb73d2449b0d1cc1573a85b651740e681f35edc..7650e7b6ee1dce8469350de8474fa775db3d525f 100644 (file)
@@ -412,7 +412,7 @@ class SCENE_PT_game_navmesh(SceneButtonsPanel, bpy.types.Panel):
 
         rd = context.scene.game_settings.recast_data
 
-        layout.operator("object.create_navmesh", text='Build navigation mesh')
+        layout.operator("mesh.create_navmesh", text='Build navigation mesh')
 
         col = layout.column()
         col.label(text="Rasterization:")
index 02a25a2a122740896449461eb9a8f17a585379e0..f45f706b8922a936bba817e44848c54badb50ba7 100644 (file)
@@ -52,4 +52,16 @@ set(SRC
        mesh_intern.h
 )
 
+if(WITH_GAMEENGINE)
+       add_definitions(-DWITH_GAMEENGINE)
+
+       list(APPEND INC
+               ../../../../extern/recastnavigation
+       )
+
+       list(APPEND SRC
+               mesh_navmesh.c
+       )
+endif()
+
 blender_add_lib(bf_editor_mesh "${SRC}" "${INC}" "${INC_SYS}")
index b992ae5f04c7067b681d92a9dd92b7a636933ac2..24c63a5dc54bc36d5f153a498b1ad97679c34c40 100644 (file)
@@ -15,4 +15,10 @@ if env['OURPLATFORM'] == 'linux':
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
     incs += ' ' + env['BF_PTHREADS_INC']
 
+if env['WITH_BF_GAMEENGINE']:
+    incs += ' #/extern/recastnavigation'
+    defs.append('WITH_GAMEENGINE')
+else:
+    sources.remove('mesh_navmesh.c')
+
 env.BlenderLib ( 'bf_editors_mesh', sources, Split(incs), [], libtype=['core'], priority=[45] )
index 4d620424b0a63095bfd716cba865d7386ff45ff3..6dce92bf07b99a6548926c92a8fd7168b3a97ddc 100644 (file)
@@ -40,6 +40,7 @@
 struct bContext;
 struct wmOperatorType;
 struct wmOperator;
+struct ViewContext;
 
 /* ******************** editface.c */
 
@@ -64,7 +65,7 @@ extern struct EditEdge *addedgelist(EditMesh *em, struct EditVert *v1, struct Ed
 extern struct EditFace *addfacelist(EditMesh *em, struct EditVert *v1, struct EditVert *v2, struct EditVert *v3, struct EditVert *v4, struct EditFace *example, struct EditFace *exampleEdges);
 extern struct EditEdge *findedgelist(EditMesh *em, struct EditVert *v1, struct EditVert *v2);
 
-void em_setup_viewcontext(struct bContext *C, ViewContext *vc);
+void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc);
 
 void MESH_OT_separate(struct wmOperatorType *ot);
 
@@ -169,7 +170,7 @@ void MESH_OT_solidify(struct wmOperatorType *ot);
 void MESH_OT_select_nth(struct wmOperatorType *ot);
 
 
-extern EditEdge *findnearestedge(ViewContext *vc, int *dist);
+extern EditEdge *findnearestedge(struct ViewContext *vc, int *dist);
 void editmesh_select_by_material(EditMesh *em, int index);
 void EM_recalc_normal_direction(EditMesh *em, int inside, int select); /* makes faces righthand turning */
 void EM_select_more(EditMesh *em);
@@ -185,7 +186,7 @@ void faceloop_select(EditMesh *em, EditEdge *startedge, int select);
  *             if 0, unselected vertice are given the bias
  * strict: if 1, the vertice corresponding to the sel parameter are ignored and not just biased 
  */
-extern EditVert *findnearestvert(ViewContext *vc, int *dist, short sel, short strict);
+extern EditVert *findnearestvert(struct ViewContext *vc, int *dist, short sel, short strict);
 
 
 /* ******************* editmesh_tools.c */
@@ -256,5 +257,10 @@ void MESH_OT_drop_named_image(struct wmOperatorType *ot);
 void MESH_OT_edgering_select(struct wmOperatorType *ot);
 void MESH_OT_loopcut(struct wmOperatorType *ot);
 
+/* ******************* mesh_navmesh.c */
+void MESH_OT_create_navmesh(struct wmOperatorType *ot);
+void MESH_OT_assign_navpolygon(struct wmOperatorType *ot);
+void MESH_OT_assign_new_navpolygon(struct wmOperatorType *ot);
+
 #endif // MESH_INTERN_H
 
similarity index 93%
rename from source/blender/editors/object/object_navmesh.c
rename to source/blender/editors/mesh/mesh_navmesh.c
index 413d8757be213b16b568913e0a5367a471b02bcd..2b64fb24e786d16b7cbf6e87fc89e56f4cb6f2b3 100644 (file)
 
 #include "ED_object.h"
 #include "ED_mesh.h"
+#include "ED_screen.h"
 
 #include "RNA_access.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "mesh_intern.h"
 #include "recast-capi.h"
 
-/*mesh/mesh_intern.h */
-extern struct EditVert *addvertlist(EditMesh *em, float *vec, struct EditVert *example);
-extern struct EditFace *addfacelist(EditMesh *em, struct EditVert *v1, struct EditVert *v2, struct EditVert *v3, struct EditVert *v4, struct EditFace *example, struct EditFace *exampleEdges);
-extern void free_vertlist(EditMesh *em, ListBase *edve);
-extern void free_edgelist(EditMesh *em, ListBase *lb);
-extern void free_facelist(EditMesh *em, ListBase *lb);
-
 static void createVertsTrisData(bContext *C, LinkNode* obs, int *nverts_r, float **verts_r, int *ntris_r, int **tris_r)
 {
        MVert *mvert;
@@ -108,8 +103,8 @@ static void createVertsTrisData(bContext *C, LinkNode* obs, int *nverts_r, float
        }
 
        //create data
-       verts = MEM_mallocN(sizeof(float)*3*nverts, "verts");
-       tris = MEM_mallocN(sizeof(int)*3*ntris, "faces");
+       verts = MEM_mallocN(sizeof(float)*3*nverts, "createVertsTrisData verts");
+       tris = MEM_mallocN(sizeof(int)*3*ntris, "createVertsTrisData faces");
 
        basenverts = 0;
        tri = tris;
@@ -253,7 +248,7 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts
        }
 
        // Allocate array that can hold triangle flags.
-       triflags = MEM_callocN(sizeof(unsigned char)*ntris, "triflags");
+       triflags = MEM_callocN(sizeof(unsigned char)*ntris, "buildNavMesh triflags");
 
        // Find triangles which are walkable based on their slope and rasterize them.
        recast_markWalkableTriangles(RAD2DEG(recastParams->agentmaxslope), verts, nverts, tris, ntris, triflags);
@@ -520,15 +515,18 @@ static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op))
        buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh);
        createRepresentation(C, pmesh, dmesh, navmeshBase);
 
+       MEM_freeN(verts);
+       MEM_freeN(tris);
+
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_create_navmesh(wmOperatorType *ot)
+void MESH_OT_create_navmesh(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Create navigation mesh";
        ot->description= "Create navigation mesh for selected objects";
-       ot->idname= "OBJECT_OT_create_navmesh";
+       ot->idname= "MESH_OT_create_navmesh";
 
        /* api callbacks */
        ot->exec= create_navmesh_exec;
@@ -537,14 +535,6 @@ void OBJECT_OT_create_navmesh(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int assign_navpolygon_poll(bContext *C)
-{
-       Object *ob= (Object *)CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
-       if (!ob || !ob->data)
-               return 0;
-       return (((Mesh*)ob->data)->edit_mesh != NULL);
-}
-
 static int assign_navpolygon_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
@@ -584,15 +574,15 @@ static int assign_navpolygon_exec(bContext *C, wmOperator *UNUSED(op))
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_assign_navpolygon(struct wmOperatorType *ot)
+void MESH_OT_assign_navpolygon(struct wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Assign polygon index";
        ot->description= "Assign polygon index to face by active face";
-       ot->idname= "OBJECT_OT_assign_navpolygon";
+       ot->idname= "MESH_OT_assign_navpolygon";
 
        /* api callbacks */
-       ot->poll = assign_navpolygon_poll;
+       ot->poll= ED_operator_editmesh;
        ot->exec= assign_navpolygon_exec;
 
        /* flags */
@@ -668,15 +658,15 @@ static int assign_new_navpolygon_exec(bContext *C, wmOperator *UNUSED(op))
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_assign_new_navpolygon(struct wmOperatorType *ot)
+void MESH_OT_assign_new_navpolygon(struct wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Assign new polygon index";
        ot->description= "Assign new polygon index to face";
-       ot->idname= "OBJECT_OT_assign_new_navpolygon";
+       ot->idname= "MESH_OT_assign_new_navpolygon";
 
        /* api callbacks */
-       ot->poll = assign_navpolygon_poll;
+       ot->poll= ED_operator_editmesh;
        ot->exec= assign_new_navpolygon_exec;
 
        /* flags */
index 282eeef906fa33fe9e88d6b45e478e1f80b7bedf..f44f7fbb8d5d3451e06bfa894150aa152963ca43 100644 (file)
@@ -151,6 +151,12 @@ void ED_operatortypes_mesh(void)
 
        WM_operatortype_append(MESH_OT_solidify);
        WM_operatortype_append(MESH_OT_select_nth);
+
+#ifdef WITH_GAMEENGINE
+       WM_operatortype_append(MESH_OT_create_navmesh);
+       WM_operatortype_append(MESH_OT_assign_navpolygon);
+       WM_operatortype_append(MESH_OT_assign_new_navpolygon);
+#endif
 }
 
 #if 0 /* UNUSED, remove? */
index b0b4f9dc0eb8600b236f6b5f2983d82366f6820a..c78c9fddbe86f5faf55dce96eae62b4bbf1c7509 100644 (file)
@@ -58,16 +58,6 @@ set(SRC
        object_intern.h
 )
 
-if(WITH_GAMEENGINE)
-       list(APPEND INC
-               ../../../../extern/recastnavigation
-       )
-
-       list(APPEND SRC
-               object_navmesh.c
-       )
-endif()
-
 if(WITH_PYTHON)
        add_definitions(-DWITH_PYTHON)
 endif()
index 434111c12277b6045d667af6858473b02b893e4a..7bb98f4aeb193eb27ce26b3d2df74fea8e6417d6 100644 (file)
@@ -225,10 +225,5 @@ void OBJECT_OT_group_remove(struct wmOperatorType *ot);
 /* object_bake.c */
 void OBJECT_OT_bake_image(wmOperatorType *ot);
 
-/* object_navmesh.cpp */
-void OBJECT_OT_create_navmesh(struct wmOperatorType *ot);
-void OBJECT_OT_assign_navpolygon(struct wmOperatorType *ot);
-void OBJECT_OT_assign_new_navpolygon(struct wmOperatorType *ot);
-
 #endif /* ED_OBJECT_INTERN_H */
 
index a9cb04237393873868e0576bf12895f62fa376d1..5a2437b19119c80f8223a6eafa668c05da23e396 100644 (file)
@@ -214,12 +214,6 @@ void ED_operatortypes_object(void)
 
        WM_operatortype_append(OBJECT_OT_bake_image);
        WM_operatortype_append(OBJECT_OT_drop_named_material);
-
-#ifdef WITH_GAMEENGINE
-       WM_operatortype_append(OBJECT_OT_create_navmesh);
-       WM_operatortype_append(OBJECT_OT_assign_navpolygon);
-       WM_operatortype_append(OBJECT_OT_assign_new_navpolygon);
-#endif
 }