Revision: 40898
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40898
Author:   campbellbarton
Date:     2011-10-10 07:21:42 +0000 (Mon, 10 Oct 2011)
Log Message:
-----------
updates to navmesh
- 2 new navmesh operators, reset and clear navmesh data.
- rename operators to be more consistent with existing names.
- some minor edits to draw function, was getting the custom data for every 
index when it already had the array.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_game.py
    trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
    trunk/blender/source/blender/editors/mesh/mesh_intern.h
    trunk/blender/source/blender/editors/mesh/mesh_navmesh.c
    trunk/blender/source/blender/editors/mesh/mesh_ops.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_game.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_game.py      
2011-10-10 07:21:05 UTC (rev 40897)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_game.py      
2011-10-10 07:21:42 UTC (rev 40898)
@@ -169,10 +169,15 @@
             layout.prop(ob, "hide_render", text="Invisible")
 
         elif physics_type == 'NAVMESH':
-            layout.operator("mesh.assign_navpolygon")
-            layout.operator("mesh.assign_new_navpolygon")
+            layout.operator("mesh.navmesh_face_copy")
+            layout.operator("mesh.navmesh_face_add")
 
+            layout.separator()
 
+            layout.operator("mesh.navmesh_reset")
+            layout.operator("mesh.navmesh_clear")
+
+
 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, Panel):
     bl_label = "Collision Bounds"
     COMPAT_ENGINES = {'BLENDER_GAME'}

Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c        
2011-10-10 07:21:05 UTC (rev 40897)
+++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c        
2011-10-10 07:21:42 UTC (rev 40898)
@@ -2970,7 +2970,7 @@
        return (a & (1 << b)) >> b;
 }
 
-static void navmesh_intToCol(int i, float* col)
+BM_INLINE void navmesh_intToCol(int i, float col[3])
 {
        int     r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1;
        int     g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1;
@@ -2985,8 +2985,7 @@
        int a, glmode;
        MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
        MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
-       int* polygonIdx = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST);
-       const float BLACK_COLOR[3] = {0.f, 0.f, 0.f};
+       int *polygonIdx = (int *)CustomData_get_layer(&dm->faceData, CD_RECAST);
        float col[3];
 
        if (!polygonIdx)
@@ -3007,11 +3006,13 @@
                glBegin(glmode = GL_QUADS);
                for(a = 0; a < dm->numFaceData; a++, mface++) {
                        int new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES;
-                       int polygonIdx = *(int*)CustomData_get(&dm->faceData, 
a, CD_RECAST);
-                       if (polygonIdx<=0)
-                               memcpy(col, BLACK_COLOR, 3*sizeof(float));
-                       else
-                               navmesh_intToCol(polygonIdx, col);
+                       int pi = polygonIdx[a];
+                       if (pi <= 0) {
+                               zero_v3(col);
+                       }
+                       else {
+                               navmesh_intToCol(pi, col);
+                       }
 
                        if(new_glmode != glmode) {
                                glEnd();

Modified: trunk/blender/source/blender/editors/mesh/mesh_intern.h
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_intern.h     2011-10-10 
07:21:05 UTC (rev 40897)
+++ trunk/blender/source/blender/editors/mesh/mesh_intern.h     2011-10-10 
07:21:42 UTC (rev 40898)
@@ -258,9 +258,11 @@
 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);
+void MESH_OT_navmesh_make(struct wmOperatorType *ot);
+void MESH_OT_navmesh_face_copy(struct wmOperatorType *ot);
+void MESH_OT_navmesh_face_add(struct wmOperatorType *ot);
+void MESH_OT_navmesh_reset(struct wmOperatorType *ot);
+void MESH_OT_navmesh_clear(struct wmOperatorType *ot);
 
 #endif // MESH_INTERN_H
 

Modified: trunk/blender/source/blender/editors/mesh/mesh_navmesh.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_navmesh.c    2011-10-10 
07:21:05 UTC (rev 40897)
+++ trunk/blender/source/blender/editors/mesh/mesh_navmesh.c    2011-10-10 
07:21:42 UTC (rev 40898)
@@ -47,6 +47,7 @@
 #include "BKE_scene.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_cdderivedmesh.h"
+#include "BKE_report.h"
 
 #include "BLI_editVert.h"
 #include "BLI_listbase.h"
@@ -436,7 +437,7 @@
 
        CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
                if(base->object->body_type==OB_BODY_TYPE_NAVMESH) {
-                       if(!navmeshBase || base==CTX_data_active_base(C))
+                       if(!navmeshBase || base == scene->basact)
                                navmeshBase= base;
                }
                else
@@ -455,12 +456,12 @@
        return OPERATOR_FINISHED;
 }
 
-void MESH_OT_create_navmesh(wmOperatorType *ot)
+void MESH_OT_navmesh_make(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Create navigation mesh";
        ot->description= "Create navigation mesh for selected objects";
-       ot->idname= "MESH_OT_create_navmesh";
+       ot->idname= "MESH_OT_navmesh_make";
 
        /* api callbacks */
        ot->exec= create_navmesh_exec;
@@ -469,35 +470,35 @@
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int assign_navpolygon_exec(bContext *C, wmOperator *UNUSED(op))
+static int navmesh_face_copy_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
 
        /* do work here */
-       int targetPolyIdx= -1;
-       EditFace *ef, *efa;
-       efa= EM_get_actFace(em, 0);
+       EditFace *efa_act= EM_get_actFace(em, 0);
 
-       if(efa) {
+       if(efa_act) {
                if(CustomData_has_layer(&em->fdata, CD_RECAST)) {
-                       targetPolyIdx= *(int*)CustomData_em_get(&em->fdata, 
efa->data, CD_RECAST);
+                       EditFace *efa;
+                       int targetPolyIdx= *(int*)CustomData_em_get(&em->fdata, 
efa_act->data, CD_RECAST);
                        targetPolyIdx= targetPolyIdx>=0? targetPolyIdx : 
-targetPolyIdx;
 
-                       if(targetPolyIdx>0) {
+                       if(targetPolyIdx > 0) {
                                /* set target poly idx to other selected faces 
*/
-                               ef= (EditFace*)em->faces.last;
-                               while(ef)  {
-                                       if((ef->f & SELECT )&& ef!=efa)  {
-                                               int* recastDataBlock= 
(int*)CustomData_em_get(&em->fdata, ef->data, CD_RECAST);
+                               for (efa= (EditFace *)em->faces.first; efa; 
efa= efa->next) {
+                                       if((efa->f & SELECT) && efa != efa_act) 
 {
+                                               int* recastDataBlock= 
(int*)CustomData_em_get(&em->fdata, efa->data, CD_RECAST);
                                                *recastDataBlock= targetPolyIdx;
                                        }
-                                       ef= ef->prev;
                                }
                        }
-               }               
+                       else {
+                               BKE_report(op->reports, RPT_ERROR, "Active face 
has no index set");
+                       }
+               }
        }
-       
+
        DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
@@ -506,16 +507,16 @@
        return OPERATOR_FINISHED;
 }
 
-void MESH_OT_assign_navpolygon(struct wmOperatorType *ot)
+void MESH_OT_navmesh_face_copy(struct wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Assign polygon index";
-       ot->description= "Assign polygon index to face by active face";
-       ot->idname= "MESH_OT_assign_navpolygon";
+       ot->name= "NavMesh Copy Face Index";
+       ot->description= "Copy the index from the active face";
+       ot->idname= "MESH_OT_navmesh_face_copy";
 
        /* api callbacks */
        ot->poll= ED_operator_editmesh;
-       ot->exec= assign_navpolygon_exec;
+       ot->exec= navmesh_face_copy_exec;
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -556,7 +557,7 @@
        return freeIdx;
 }
 
-static int assign_new_navpolygon_exec(bContext *C, wmOperator *UNUSED(op))
+static int navmesh_face_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
@@ -585,17 +586,94 @@
        return OPERATOR_FINISHED;
 }
 
-void MESH_OT_assign_new_navpolygon(struct wmOperatorType *ot)
+void MESH_OT_navmesh_face_add(struct wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Assign new polygon index";
-       ot->description= "Assign new polygon index to face";
-       ot->idname= "MESH_OT_assign_new_navpolygon";
+       ot->name= "NavMesh New Face Index";
+       ot->description= "Add a new index and assign it to selected faces";
+       ot->idname= "MESH_OT_navmesh_face_add";
 
        /* api callbacks */
        ot->poll= ED_operator_editmesh;
-       ot->exec= assign_new_navpolygon_exec;
+       ot->exec= navmesh_face_add_exec;
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
+
+static int navmesh_obmode_data_poll(bContext *C)
+{
+       Object *ob = ED_object_active_context(C);
+       if (ob && (ob->mode == OB_MODE_OBJECT) && (ob->type == OB_MESH)) {
+               Mesh *me= ob->data;
+               return CustomData_has_layer(&me->fdata, CD_RECAST);
+       }
+       return FALSE;
+}
+
+static int navmesh_obmode_poll(bContext *C)
+{
+       Object *ob = ED_object_active_context(C);
+       if (ob && (ob->mode == OB_MODE_OBJECT) && (ob->type == OB_MESH)) {
+               return TRUE;
+       }
+       return FALSE;
+}
+
+static int navmesh_reset_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Object *ob = ED_object_active_context(C);
+       Mesh *me= ob->data;
+
+       CustomData_free_layers(&me->fdata, CD_RECAST, me->totface);
+
+       BKE_mesh_ensure_navmesh(me);
+
+       DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, &me->id);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_navmesh_reset(struct wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "NavMesh Reset Index Values";
+       ot->description= "Assign a new index to every face";
+       ot->idname= "MESH_OT_navmesh_reset";
+
+       /* api callbacks */
+       ot->poll= navmesh_obmode_poll;
+       ot->exec= navmesh_reset_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int navmesh_clear_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Object *ob = ED_object_active_context(C);
+       Mesh *me= ob->data;
+
+       CustomData_free_layers(&me->fdata, CD_RECAST, me->totface);
+
+       DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, &me->id);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_navmesh_clear(struct wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "NavMesh Clear Data";
+       ot->description= "Remove navmesh data from this mesh";
+       ot->idname= "MESH_OT_navmesh_clear";
+
+       /* api callbacks */
+       ot->poll= navmesh_obmode_data_poll;
+       ot->exec= navmesh_clear_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}

Modified: trunk/blender/source/blender/editors/mesh/mesh_ops.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_ops.c        2011-10-10 
07:21:05 UTC (rev 40897)
+++ trunk/blender/source/blender/editors/mesh/mesh_ops.c        2011-10-10 
07:21:42 UTC (rev 40898)
@@ -153,9 +153,11 @@
        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);
+       WM_operatortype_append(MESH_OT_navmesh_make);
+       WM_operatortype_append(MESH_OT_navmesh_face_copy);

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to