Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-10-10 11:21:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-10 11:21:42 +0400
commit2de1bd7dc568d30edd8656cb221720dc0d881f4f (patch)
treebf6a1d8c4fbeeae07a3a938dcb7bdfd80d3b76cb /source
parent70cd4b77bb3ed0fc3f2498421f9452eb1408d8c2 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c17
-rw-r--r--source/blender/editors/mesh/mesh_intern.h8
-rw-r--r--source/blender/editors/mesh/mesh_navmesh.c134
-rw-r--r--source/blender/editors/mesh/mesh_ops.c8
4 files changed, 125 insertions, 42 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 53973608cd6..bc6492f92ae 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2970,7 +2970,7 @@ BM_INLINE int navmesh_bit(int a, int b)
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 @@ static void navmesh_drawColored(DerivedMesh *dm)
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 @@ static void navmesh_drawColored(DerivedMesh *dm)
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();
diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h
index 6dce92bf07b..9e6b4e84e54 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -258,9 +258,11 @@ 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);
+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
diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c
index f427b51570b..4ae1cdeed02 100644
--- a/source/blender/editors/mesh/mesh_navmesh.c
+++ b/source/blender/editors/mesh/mesh_navmesh.c
@@ -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 @@ static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op))
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 @@ static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op))
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 @@ void MESH_OT_create_navmesh(wmOperatorType *ot)
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 @@ static int assign_navpolygon_exec(bContext *C, wmOperator *UNUSED(op))
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 @@ static int findFreeNavPolyIndex(EditMesh* em)
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,16 +586,93 @@ static int assign_new_navpolygon_exec(bContext *C, wmOperator *UNUSED(op))
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;
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index f44f7fbb8d5..b1f0daeaddc 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -153,9 +153,11 @@ void ED_operatortypes_mesh(void)
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);
+ WM_operatortype_append(MESH_OT_navmesh_face_add);
+ WM_operatortype_append(MESH_OT_navmesh_reset);
+ WM_operatortype_append(MESH_OT_navmesh_clear);
#endif
}