diff options
author | Miika Hamalainen <blender@miikah.org> | 2011-10-14 01:43:02 +0400 |
---|---|---|
committer | Miika Hamalainen <blender@miikah.org> | 2011-10-14 01:43:02 +0400 |
commit | 8be3249537e7930e0fa5adb59bc343455da309e9 (patch) | |
tree | 0f4f14b046742f4380540e06c529cd417ddbc541 /source/blender/editors/mesh | |
parent | 8bf78d7f5676520bf6f4241afb88fba506e342f4 (diff) | |
parent | 818c098004ff64adcc0ff24fe29d40850f5591ce (diff) |
Merge with trunk r40991
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 8 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_navmesh.c | 190 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_ops.c | 8 |
3 files changed, 148 insertions, 58 deletions
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 e4b884744e1..b8ace26991e 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" @@ -296,7 +297,6 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, int i,j, k; unsigned short* v; int face[3]; - Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object* obedit; int createob= base==NULL; @@ -305,7 +305,6 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, unsigned int *meshes; float bmin[3], cs, ch, *dverts; unsigned char *tris; - ModifierData *md; zero_v3(co); zero_v3(rot); @@ -419,53 +418,63 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, obedit->body_type= OB_BODY_TYPE_NAVMESH; rename_id((ID *)obedit, "Navmesh"); } - - md= modifiers_findByType(obedit, eModifierType_NavMesh); - if(!md) { - ED_object_modifier_add(NULL, bmain, scene, obedit, NULL, eModifierType_NavMesh); - } + + BKE_mesh_ensure_navmesh(obedit->data); return obedit; } -static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op)) +static int create_navmesh_exec(bContext *C, wmOperator *op) { Scene* scene= CTX_data_scene(C); - int nverts= 0, ntris= 0; - float *verts= NULL; - int *tris= 0; - struct recast_polyMesh *pmesh= NULL; - struct recast_polyMeshDetail *dmesh= NULL; LinkNode* obs= NULL; Base* navmeshBase= NULL; 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)) - navmeshBase= base; + if (base->object->type == OB_MESH) { + if (base->object->body_type==OB_BODY_TYPE_NAVMESH) { + if (!navmeshBase || base == scene->basact) { + navmeshBase= base; + } + } + else { + BLI_linklist_append(&obs, (void*)base->object); + } } - else - BLI_linklist_append(&obs, (void*)base->object); } CTX_DATA_END; - createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris); - BLI_linklist_free(obs, NULL); - buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh); - createRepresentation(C, pmesh, dmesh, navmeshBase); + if (obs) { + struct recast_polyMesh *pmesh= NULL; + struct recast_polyMeshDetail *dmesh= NULL; - MEM_freeN(verts); - MEM_freeN(tris); + int nverts= 0, ntris= 0; + int *tris= 0; + float *verts= NULL; - return OPERATOR_FINISHED; + createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris); + BLI_linklist_free(obs, NULL); + buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh); + createRepresentation(C, pmesh, dmesh, navmeshBase); + + MEM_freeN(verts); + MEM_freeN(tris); + + return OPERATOR_FINISHED; + } + else { + BKE_report(op->reports, RPT_ERROR, "No mesh objects found"); + + return OPERATOR_CANCELLED; + } } -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; @@ -474,35 +483,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); @@ -511,16 +520,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; @@ -561,7 +570,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); @@ -590,16 +599,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 } |