forked from bartvdbraak/blender
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.
This commit is contained in:
parent
70cd4b77bb
commit
2de1bd7dc5
@ -169,8 +169,13 @@ class PHYSICS_PT_game_physics(PhysicsButtonsPanel, Panel):
|
||||
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):
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user