From 8a423f59ea123948383f024695bf058213169d82 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 26 Sep 2011 15:39:15 +0000 Subject: [PATCH 01/13] pep8 cleanup and fix for keymap test operator from my own recent fix. --- .../cmake/cmake_static_check_cppcheck.py | 2 +- build_files/cmake/project_source_info.py | 5 +---- .../scripts/modules/bpy_extras/anim_utils.py | 6 +++--- .../modules/bpy_extras/keyconfig_utils.py | 2 +- .../scripts/startup/bl_operators/console.py | 13 +++++++----- .../scripts/startup/bl_operators/view3d.py | 21 ++++++++++++++----- release/scripts/startup/bl_operators/wm.py | 6 +++--- release/scripts/startup/bl_ui/space_text.py | 6 ++++-- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/build_files/cmake/cmake_static_check_cppcheck.py b/build_files/cmake/cmake_static_check_cppcheck.py index fdd380c5b4d..1c8d619a513 100644 --- a/build_files/cmake/cmake_static_check_cppcheck.py +++ b/build_files/cmake/cmake_static_check_cppcheck.py @@ -58,8 +58,8 @@ def main(): check_commands.append((c, cmd)) - process_functions = [] + def my_process(i, c, cmd): percent = 100.0 * (i / (len(check_commands) - 1)) percent_str = "[" + ("%.2f]" % percent).rjust(7) + " %:" diff --git a/build_files/cmake/project_source_info.py b/build_files/cmake/project_source_info.py index 83e4e05dc0f..c636d778aaa 100644 --- a/build_files/cmake/project_source_info.py +++ b/build_files/cmake/project_source_info.py @@ -161,8 +161,6 @@ def queue_processes(process_funcs, job_total=-1): del multiprocessing if job_total == 1: - import os - import sys for func, args in process_funcs: sys.stdout.flush() sys.stderr.flush() @@ -171,14 +169,13 @@ def queue_processes(process_funcs, job_total=-1): process.wait() else: import time - import subprocess processes = [] for func, args in process_funcs: # wait until a thread is free while 1: processes[:] = [p for p in processes if p.poll() is None] - + if len(processes) <= job_total: break else: diff --git a/release/scripts/modules/bpy_extras/anim_utils.py b/release/scripts/modules/bpy_extras/anim_utils.py index 9482dc3e1c9..9848586a144 100644 --- a/release/scripts/modules/bpy_extras/anim_utils.py +++ b/release/scripts/modules/bpy_extras/anim_utils.py @@ -59,7 +59,7 @@ def bake_action(frame_start, :arg action: An action to bake the data into, or None for a new action to be created. :type action: :class:`bpy.types.Action` or None - + :return: an action or None :rtype: :class:`bpy.types.Action` """ @@ -115,7 +115,6 @@ def bake_action(frame_start, return info - def obj_frame_info(obj): info = {} # parent = obj.parent @@ -183,7 +182,8 @@ def bake_action(frame_start, pbone.constraints.remove(pbone.constraints[0]) for f in frame_range: - matrix = pose_info[(f - frame_start) // frame_step][name]["matrix_key"] + f_step = (f - frame_start) // frame_step + matrix = pose_info[f_step][name]["matrix_key"] # pbone.location = matrix.to_translation() # pbone.rotation_quaternion = matrix.to_quaternion() diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils.py b/release/scripts/modules/bpy_extras/keyconfig_utils.py index 081b0780622..e87db659918 100644 --- a/release/scripts/modules/bpy_extras/keyconfig_utils.py +++ b/release/scripts/modules/bpy_extras/keyconfig_utils.py @@ -218,7 +218,7 @@ def keyconfig_export(wm, kc, filepath): def keyconfig_test(kc): - def testEntry(self, kc, entry, src=None, parent=None): + def testEntry(kc, entry, src=None, parent=None): result = False def kmistr(kmi): diff --git a/release/scripts/startup/bl_operators/console.py b/release/scripts/startup/bl_operators/console.py index de953630f00..109ca758ea8 100644 --- a/release/scripts/startup/bl_operators/console.py +++ b/release/scripts/startup/bl_operators/console.py @@ -37,12 +37,14 @@ class ConsoleExec(Operator): if execute: return execute(context) else: - print("Error: bpy.ops.console.execute_" + sc.language + " - not found") + print("Error: bpy.ops.console.execute_%s - not found" % + sc.language) return {'FINISHED'} class ConsoleAutocomplete(Operator): - '''Evaluate the namespace up until the cursor and give a list of options or complete the name if there is only one''' + """Evaluate the namespace up until the cursor and give a list of """ \ + """options or complete the name if there is only one""" bl_idname = "console.autocomplete" bl_label = "Console Autocomplete" @@ -54,7 +56,8 @@ class ConsoleAutocomplete(Operator): if autocomplete: return autocomplete(context) else: - print("Error: bpy.ops.console.autocomplete_" + sc.language + " - not found") + print("Error: bpy.ops.console.autocomplete_%s - not found" % + sc.language) return {'FINISHED'} @@ -76,7 +79,8 @@ class ConsoleBanner(Operator): if banner: return banner(context) else: - print("Error: bpy.ops.console.banner_" + sc.language + " - not found") + print("Error: bpy.ops.console.banner_%s - not found" % + sc.language) return {'FINISHED'} @@ -103,4 +107,3 @@ class ConsoleLanguage(Operator): remove_duplicates=True) return {'FINISHED'} - diff --git a/release/scripts/startup/bl_operators/view3d.py b/release/scripts/startup/bl_operators/view3d.py index 805f2b5105b..05b53219119 100644 --- a/release/scripts/startup/bl_operators/view3d.py +++ b/release/scripts/startup/bl_operators/view3d.py @@ -36,7 +36,10 @@ class VIEW3D_OT_edit_mesh_extrude_individual_move(Operator): # totvert = mesh.total_vert_sel if select_mode[2] and totface == 1: - bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN', TRANSFORM_OT_translate={"constraint_orientation": 'NORMAL', "constraint_axis": (False, False, True)}) + bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN', + TRANSFORM_OT_translate={ + "constraint_orientation": 'NORMAL', + "constraint_axis": (False, False, True)}) elif select_mode[2] and totface > 1: bpy.ops.mesh.extrude_faces_move('INVOKE_REGION_WIN') elif select_mode[1] and totedge >= 1: @@ -44,7 +47,8 @@ class VIEW3D_OT_edit_mesh_extrude_individual_move(Operator): else: bpy.ops.mesh.extrude_vertices_move('INVOKE_REGION_WIN') - # ignore return from operators above because they are 'RUNNING_MODAL', and cause this one not to be freed. [#24671] + # ignore return from operators above because they are 'RUNNING_MODAL', + # and cause this one not to be freed. [#24671] return {'FINISHED'} def invoke(self, context, event): @@ -64,13 +68,20 @@ class VIEW3D_OT_edit_mesh_extrude_move(Operator): # totvert = mesh.total_vert_sel if totface >= 1: - bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN', TRANSFORM_OT_translate={"constraint_orientation": 'NORMAL', "constraint_axis": (False, False, True)}) + bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN', + TRANSFORM_OT_translate={ + "constraint_orientation": 'NORMAL', + "constraint_axis": (False, False, True)}) elif totedge == 1: - bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN', TRANSFORM_OT_translate={"constraint_orientation": 'NORMAL', "constraint_axis": (True, True, False)}) + bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN', + TRANSFORM_OT_translate={ + "constraint_orientation": 'NORMAL', + "constraint_axis": (True, True, False)}) else: bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN') - # ignore return from operators above because they are 'RUNNING_MODAL', and cause this one not to be freed. [#24671] + # ignore return from operators above because they are 'RUNNING_MODAL', + # and cause this one not to be freed. [#24671] return {'FINISHED'} def invoke(self, context, event): diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index 72efdeeb5b3..85e79914ce3 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -1180,7 +1180,7 @@ class WM_OT_copy_prev_settings(Operator): return {'CANCELLED'} - + class WM_OT_keyconfig_test(Operator): "Test keyconfig for conflicts" bl_idname = "wm.keyconfig_test" @@ -1447,8 +1447,8 @@ class WM_OT_operator_cheat_sheet(Operator): textblock.write('\n'.join(op_strings)) self.report({'INFO'}, "See OperatorList.txt textblock") return {'FINISHED'} - - + + class WM_OT_addon_enable(Operator): "Enable an addon" bl_idname = "wm.addon_enable" diff --git a/release/scripts/startup/bl_ui/space_text.py b/release/scripts/startup/bl_ui/space_text.py index d0a3a53aa85..c3b2e30cb12 100644 --- a/release/scripts/startup/bl_ui/space_text.py +++ b/release/scripts/startup/bl_ui/space_text.py @@ -66,9 +66,11 @@ class TEXT_HT_header(Header): row = layout.row() if text.filepath: if text.is_dirty: - row.label(text="File" + ": *%r " % text.filepath + "(unsaved)") + row.label(text="File" + ": *%r " % + text.filepath + "(unsaved)") else: - row.label(text="File" + ": %r" % text.filepath) + row.label(text="File" + ": %r" % + text.filepath) else: row.label(text="Text: External" if text.library From fbdfdfefd814128520198c033866cc50298f1758 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 26 Sep 2011 16:53:04 +0000 Subject: [PATCH 02/13] use BLI_snprintf rather than sprintf for interface functions --- .../scripts/startup/bl_ui/properties_game.py | 2 +- .../startup/bl_ui/properties_particle.py | 2 +- source/blender/editors/interface/interface.c | 6 ++--- .../editors/interface/interface_draw.c | 3 ++- .../editors/interface/interface_handlers.c | 8 +++---- .../editors/interface/interface_layout.c | 2 +- .../editors/interface/interface_regions.c | 24 ++++++++++--------- .../editors/interface/interface_style.c | 2 +- .../editors/interface/interface_templates.c | 15 +++++------- .../editors/interface/interface_utils.c | 3 ++- 10 files changed, 34 insertions(+), 33 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_game.py b/release/scripts/startup/bl_ui/properties_game.py index 469c1e68706..8cb73d2449b 100644 --- a/release/scripts/startup/bl_ui/properties_game.py +++ b/release/scripts/startup/bl_ui/properties_game.py @@ -204,7 +204,7 @@ class PHYSICS_PT_game_obstacles(PhysicsButtonsPanel, Panel): def poll(cls, context): game = context.object.game rd = context.scene.render - return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine in cls.COMPAT_ENGINES) + return (game.physics_type in {'DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC'}) and (rd.engine in cls.COMPAT_ENGINES) def draw_header(self, context): game = context.active_object.game diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py index edd5745cf17..eceefc70b5c 100644 --- a/release/scripts/startup/bl_ui/properties_particle.py +++ b/release/scripts/startup/bl_ui/properties_particle.py @@ -988,7 +988,7 @@ class PARTICLE_PT_draw(ParticleButtonsPanel, Panel): col.label(text="Color:") col.prop(part, "draw_color", text="") sub = col.row() - sub.active = part.draw_color in ('VELOCITY', 'ACCELERATION') + sub.active = (part.draw_color in {'VELOCITY', 'ACCELERATION'}) sub.prop(part, "color_maximum", text="Max") if (path): diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 8f440f7b61a..49156d3cf4a 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2143,8 +2143,8 @@ void ui_check_but(uiBut *but) UI_GET_BUT_VALUE_INIT(but, value) if(ui_is_but_float(but)) { - if(value == (double) FLT_MAX) sprintf(but->drawstr, "%sinf", but->str); - else if(value == (double) -FLT_MAX) sprintf(but->drawstr, "%s-inf", but->str); + if(value == (double) FLT_MAX) BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%sinf", but->str); + else if(value == (double) -FLT_MAX) BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s-inf", but->str); /* support length type buttons */ else if(ui_is_but_unit(but)) { char new_str[sizeof(but->drawstr)]; @@ -2157,7 +2157,7 @@ void ui_check_but(uiBut *but) } } else { - sprintf(but->drawstr, "%s%d", but->str, (int)value); + BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%d", but->str, (int)value); } if(but->rnaprop) { diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index fd437d2b0e5..b65be48f7ee 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -39,6 +39,7 @@ #include "BLI_math.h" #include "BLI_rect.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "BKE_colortools.h" @@ -835,7 +836,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), /* draw grid lines here */ for (i=0; i<6; i++) { char str[4]; - sprintf(str,"%-3d",i*20); + BLI_snprintf(str, sizeof(str), "%-3d",i*20); str[3]='\0'; fdrawline(rect.xmin+22, yofs+(i/5.f)*h, rect.xmax+1, yofs+(i/5.f)*h); BLF_draw_default(rect.xmin+1, yofs-5+(i/5.f)*h, 0, str, sizeof(str)-1); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index e4776cdb5f2..568eaf358e5 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1113,9 +1113,9 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, if(but->poin==NULL && but->rnapoin.data==NULL); else if(mode=='c') { if(ui_is_but_float(but)) - sprintf(buf, "%f", ui_get_but_val(but)); + BLI_snprintf(buf, sizeof(buf), "%f", ui_get_but_val(but)); else - sprintf(buf, "%d", (int)ui_get_but_val(but)); + BLI_snprintf(buf, sizeof(buf), "%d", (int)ui_get_but_val(but)); WM_clipboard_text_set(buf, 0); } @@ -1136,7 +1136,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, else if(mode=='c') { ui_get_but_vectorf(but, rgb); - sprintf(buf, "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]); + BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", rgb[0], rgb[1], rgb[2]); WM_clipboard_text_set(buf, 0); } @@ -4367,7 +4367,7 @@ static int ui_but_menu(bContext *C, uiBut *but) PointerRNA ptr_props; if(but->rnapoin.data && but->rnaprop) { - sprintf(buf, "%s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop)); + BLI_snprintf(buf, sizeof(buf), "%s.%s", RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop)); WM_operator_properties_create(&ptr_props, "WM_OT_doc_view"); RNA_string_set(&ptr_props, "doc_id", buf); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index ae66d649a06..ab07cb4bbf6 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1219,7 +1219,7 @@ static void rna_search_cb(const struct bContext *C, void *arg_but, const char *s #if 0 /* this name is used for a string comparison and can't be modified, TODO */ name_uiprefix_id(name_ui, id); #else - strcpy(name_ui, id->name+2); + BLI_strncpy(name_ui, id->name+2, sizeof(name_ui)); #endif name= BLI_strdup(name_ui); iconid= ui_id_icon_get((bContext*)C, id, 1); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 4221f7c30ff..c0d6a07bdde 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -230,9 +230,11 @@ void ui_set_name_menu(uiBut *but, int value) int i; md= decompose_menu_string(but->str); - for (i=0; initems; i++) - if (md->items[i].retval==value) - strcpy(but->drawstr, md->items[i].str); + for (i=0; initems; i++) { + if (md->items[i].retval==value) { + BLI_strncpy(but->drawstr, md->items[i].str, sizeof(but->drawstr)); + } + } menudata_free(md); } @@ -1798,7 +1800,7 @@ static void ui_update_block_buts_rgb(uiBlock *block, float *rgb) if (rgb_gamma[1] > 1.0f) rgb_gamma[1] = modf(rgb_gamma[1], &intpart); if (rgb_gamma[2] > 1.0f) rgb_gamma[2] = modf(rgb_gamma[2], &intpart); - sprintf(col, "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2])); + BLI_snprintf(col, sizeof(col), "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2])); strcpy(bt->poin, col); } @@ -1986,10 +1988,10 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR /* existence of profile means storage is in linear color space, with display correction */ if (block->color_profile == BLI_PR_NONE) { - sprintf(tip, "Value in Display Color Space"); + BLI_strncpy(tip, "Value in Display Color Space", sizeof(tip)); copy_v3_v3(rgb_gamma, rgb); } else { - sprintf(tip, "Value in Linear RGB Color Space"); + BLI_strncpy(tip, "Value in Linear RGB Color Space", sizeof(tip)); /* make an sRGB version, for Hex code */ linearrgb_to_srgb_v3_v3(rgb_gamma, rgb); } @@ -2058,7 +2060,7 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR rgb[3]= 1.0f; } - sprintf(hexcol, "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2])); + BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2])); bt= uiDefBut(block, TEX, 0, "Hex: ", 0, -60, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)"); uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol); @@ -2369,7 +2371,7 @@ uiPopupMenu *uiPupMenuBegin(bContext *C, const char *title, int icon) char titlestr[256]; if(icon) { - sprintf(titlestr, " %s", title); + BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); uiDefIconTextBut(pup->block, LABEL, 0, icon, titlestr, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); } else { @@ -2467,7 +2469,7 @@ void uiPupMenuOkee(bContext *C, const char *opname, const char *str, ...) va_list ap; char titlestr[256]; - sprintf(titlestr, "OK? %%i%d", ICON_QUESTION); + BLI_snprintf(titlestr, sizeof(titlestr), "OK? %%i%d", ICON_QUESTION); va_start(ap, str); vconfirm_opname(C, opname, titlestr, str, ap); @@ -2507,9 +2509,9 @@ void uiPupMenuError(bContext *C, const char *str, ...) char nfmt[256]; char titlestr[256]; - sprintf(titlestr, "Error %%i%d", ICON_ERROR); + BLI_snprintf(titlestr, sizeof(titlestr), "Error %%i%d", ICON_ERROR); - sprintf(nfmt, "%s", str); + BLI_strncpy(nfmt, str, sizeof(nfmt)); va_start(ap, str); vconfirm_opname(C, NULL, titlestr, nfmt, ap); diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 2a183e3d994..3009d4fea09 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -315,7 +315,7 @@ void uiStyleInit(void) font= MEM_callocN(sizeof(uiFont), "ui font"); BLI_addtail(&U.uifonts, font); - strcpy(font->filename, "default"); + BLI_strncpy(font->filename, "default", sizeof(font->filename)); font->uifont_id= UIFONT_DEFAULT; } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index bec9e6a7664..a4622f50725 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -412,7 +412,7 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str if(id->us > 1) { char str[32]; - sprintf(str, "%d", id->us); + BLI_snprintf(str, sizeof(str), "%d", id->us); but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X + ((id->us < 10) ? 0:10), UI_UNIT_Y, NULL, 0, 0, 0, 0, UI_translate_do_tooltip(_("Displays number of users of this data. Click to make a single-user copy"))); @@ -724,7 +724,7 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob, Modif block= uiLayoutGetBlock(row); /* VIRTUAL MODIFIER */ // XXX this is not used now, since these cannot be accessed via RNA - sprintf(str, "%s parent deform", md->name); + BLI_snprintf(str, sizeof(str), "%s parent deform", md->name); uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); but = uiDefBut(block, BUT, 0, UI_translate_do_iface(N_("Make Real")), 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0, @@ -959,13 +959,10 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) cti= constraint_get_typeinfo(con); if (cti == NULL) { /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */ - if (con->type == CONSTRAINT_TYPE_NULL) - strcpy(typestr, "Null"); - else - strcpy(typestr, "Unknown"); + BLI_strncpy(typestr, (con->type == CONSTRAINT_TYPE_NULL) ? "Null" : "Unknown", sizeof(typestr)); } else - strcpy(typestr, cti->name); + BLI_strncpy(typestr, cti->name, sizeof(typestr)); /* determine whether constraint is proxy protected or not */ if (proxylocked_constraints_owner(ob, pchan)) @@ -2112,7 +2109,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe manode= give_node_material(ma); if(manode) { char str[MAX_ID_NAME + 12]; - sprintf(str, "Node %s", manode->id.name+2); + BLI_snprintf(str, sizeof(str), "Node %s", manode->id.name+2); uiItemL(sub, str, ui_id_icon_get(C, &manode->id, 1)); } else if(ma->use_nodes) { @@ -2281,7 +2278,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * uiItemL(row, "", ICON_NONE); /* next/prev button */ - sprintf(str, "%d :", i); + BLI_snprintf(str, sizeof(str), "%d :", i); but= uiDefIconTextButR_prop(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, ""); if(i == 0) uiButSetFlag(but, UI_BUT_DISABLED); diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index a49060eaca2..206ecbad1d0 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -36,6 +36,7 @@ #include "DNA_object_types.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BLF_translation.h" @@ -116,7 +117,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind } case PROP_COLLECTION: { char text[256]; - sprintf(text, UI_translate_do_iface(N_("%d items")), RNA_property_collection_length(ptr, prop)); + BLI_snprintf(text, sizeof(text), UI_translate_do_iface(N_("%d items")), RNA_property_collection_length(ptr, prop)); but= uiDefBut(block, LABEL, 0, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, NULL); uiButSetFlag(but, UI_BUT_DISABLED); break; From dc76be62d99f4da1983cfa84aa9c6d86124064ab Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 26 Sep 2011 17:30:56 +0000 Subject: [PATCH 03/13] replace strnlen with BLI_strnlen, make some args const - no functional changes. --- source/blender/editors/include/UI_interface.h | 2 +- source/blender/editors/interface/interface.c | 22 +++++++++---------- .../editors/interface/interface_anim.c | 2 +- .../editors/interface/interface_intern.h | 6 ++--- .../editors/interface/interface_regions.c | 19 +++++++--------- .../editors/interface/interface_widgets.c | 4 ++-- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index f5abebbebd5..67b17a891ca 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -576,7 +576,7 @@ void uiButSetFocusOnEnter (struct wmWindow *win, uiBut *but); typedef struct AutoComplete AutoComplete; -AutoComplete *autocomplete_begin(const char *startname, int maxlen); +AutoComplete *autocomplete_begin(const char *startname, size_t maxlen); void autocomplete_do_name(AutoComplete *autocpl, const char *name); void autocomplete_end(AutoComplete *autocpl, char *autoname); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 49156d3cf4a..aad67b6b0be 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1528,7 +1528,7 @@ static double ui_get_but_scale_unit(uiBut *but, double value) } /* str will be overwritten */ -void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen) +void ui_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) { if(ui_is_but_unit(but)) { UnitSettings *unit= but->block->unit; @@ -1576,7 +1576,7 @@ static float ui_get_but_step_unit(uiBut *but, float step_default) } -void ui_get_but_string(uiBut *but, char *str, int maxlen) +void ui_get_but_string(uiBut *but, char *str, size_t maxlen) { if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) { PropertyType type; @@ -2176,7 +2176,7 @@ void ui_check_but(uiBut *but) BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value); } else { - strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); + BLI_strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); } break; @@ -2194,7 +2194,7 @@ void ui_check_but(uiBut *but) break; case KEYEVT: - strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); + BLI_strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); if (but->flag & UI_SELECT) { strcat(but->drawstr, "Press a key"); } @@ -2226,15 +2226,15 @@ void ui_check_but(uiBut *but) strcat(but->drawstr, "Press a key "); } else - strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); + BLI_strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); break; case BUT_TOGDUAL: /* trying to get the dual-icon to left of text... not very nice */ if(but->str[0]) { - strncpy(but->drawstr, " ", UI_MAX_DRAW_STR); - strncpy(but->drawstr+2, but->str, UI_MAX_DRAW_STR-2); + BLI_strncpy(but->drawstr, " ", UI_MAX_DRAW_STR); + BLI_strncpy(but->drawstr+2, but->str, UI_MAX_DRAW_STR-2); } break; @@ -2242,13 +2242,13 @@ void ui_check_but(uiBut *but) case HSVCIRCLE: break; default: - strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); + BLI_strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR); } /* if we are doing text editing, this will override the drawstr */ if(but->editstr) - strncpy(but->drawstr, but->editstr, UI_MAX_DRAW_STR); + BLI_strncpy(but->drawstr, but->editstr, UI_MAX_DRAW_STR); /* text clipping moved to widget drawing code itself */ } @@ -2822,12 +2822,12 @@ static int findBitIndex(unsigned int x) { /* autocomplete helper functions */ struct AutoComplete { - int maxlen; + size_t maxlen; char *truncate; const char *startname; }; -AutoComplete *autocomplete_begin(const char *startname, int maxlen) +AutoComplete *autocomplete_begin(const char *startname, size_t maxlen) { AutoComplete *autocpl; diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 1113f90a652..c35996701ee 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -83,7 +83,7 @@ void ui_but_anim_flag(uiBut *but, float cfra) } } -int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen) +int ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen) { FCurve *fcu; ChannelDriver *driver; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 72eb869dea0..94eb180bd06 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -364,8 +364,8 @@ extern void ui_set_but_vectorf(uiBut *but, float *vec); extern void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float mx, float my); -extern void ui_get_but_string(uiBut *but, char *str, int maxlen); -extern void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen); +extern void ui_get_but_string(uiBut *but, char *str, size_t maxlen); +extern void ui_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen); extern int ui_set_but_string(struct bContext *C, uiBut *but, const char *str); extern int ui_get_but_string_max_length(uiBut *but); @@ -517,7 +517,7 @@ void ui_but_anim_copy_driver(struct bContext *C); void ui_but_anim_paste_driver(struct bContext *C); void ui_but_anim_add_keyingset(struct bContext *C); void ui_but_anim_remove_keyingset(struct bContext *C); -int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen); +int ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen); int ui_but_anim_expression_set(uiBut *but, const char *str); int ui_but_anim_expression_create(uiBut *but, const char *str); void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index c0d6a07bdde..4a9eb8113fe 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -84,7 +84,7 @@ typedef struct MenuEntry { } MenuEntry; typedef struct MenuData { - char *instr; + const char *instr; const char *title; int titleicon; @@ -92,7 +92,7 @@ typedef struct MenuData { int nitems, itemssize; } MenuData; -static MenuData *menudata_new(char *instr) +static MenuData *menudata_new(const char *instr) { MenuData *md= MEM_mallocN(sizeof(*md), "MenuData"); @@ -137,7 +137,7 @@ static void menudata_add_item(MenuData *md, const char *str, int retval, int ico static void menudata_free(MenuData *md) { - MEM_freeN(md->instr); + MEM_freeN((void *)md->instr); if (md->items) MEM_freeN(md->items); MEM_freeN(md); @@ -156,7 +156,7 @@ static void menudata_free(MenuData *md) * @param str String to be parsed. * @retval new menudata structure, free with menudata_free() */ -static MenuData *decompose_menu_string(char *str) +static MenuData *decompose_menu_string(const char *str) { char *instr= BLI_strdup(str); MenuData *md= menudata_new(instr); @@ -1613,7 +1613,7 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a uiBut *bt; MenuData *md; MenuEntry *entry; - char *instr= arg_str; + const char *instr= arg_str; int columns, rows, a, b; uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT); @@ -2154,7 +2154,7 @@ static int ui_popup_string_hash(char *str) return hash; } -static int ui_popup_menu_hash(char *str) +static int ui_popup_menu_hash(const char *str) { return BLI_ghashutil_strhash(str); } @@ -2204,8 +2204,6 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi { uiBlock *block; uiBut *bt; - ScrArea *sa; - ARegion *ar; uiPopupMenu *pup= arg_pup; int offset[2], direction, minwidth, width, height, flip; @@ -2277,10 +2275,9 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi else { /* for a header menu we set the direction automatic */ if(!pup->slideout && flip) { - sa= CTX_wm_area(C); - ar= CTX_wm_region(C); - + ScrArea *sa= CTX_wm_area(C); if(sa && sa->headertype==HEADERDOWN) { + ARegion *ar= CTX_wm_region(C); if(ar && ar->regiontype == RGN_TYPE_HEADER) { uiBlockSetDirection(block, UI_TOP); uiBlockFlipOrder(block); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 45829646145..62bb93055b5 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -574,7 +574,7 @@ static void widget_check_trias(uiWidgetTrias *tria, rcti *rect) /* prepares shade colors */ -static void shadecolors4(char *coltop, char *coldown, const char *color, short shadetop, short shadedown) +static void shadecolors4(char coltop[4], char *coldown, const char *color, short shadetop, short shadedown) { coltop[0]= CLAMPIS(color[0]+shadetop, 0, 255); @@ -1493,7 +1493,7 @@ void ui_widget_color_init(ThemeUI *tui) /* ************ button callbacks, state ***************** */ -static void widget_state_blend(char *cp, const char *cpstate, const float fac) +static void widget_state_blend(char cp[3], const char cpstate[3], const float fac) { if(fac != 0.0f) { cp[0]= (int)((1.0f-fac)*cp[0] + fac*cpstate[0]); From e897c8e83e1277767d9a44cb0ecb6f8a279dddc3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 26 Sep 2011 17:32:50 +0000 Subject: [PATCH 04/13] fix [#28742] UILayout.menu() with icon misbehaves in headers --- source/blender/editors/interface/interface_widgets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 62bb93055b5..0215cc05d36 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -889,7 +889,7 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect UI_icon_draw_aspect(xs, ys, icon, aspect, alpha); } - if(but->flag & UI_ICON_SUBMENU) { + if((but->flag & UI_ICON_SUBMENU) && (but->dt == UI_EMBOSSP)) { xs= rect->xmax-17; ys= (rect->ymin+rect->ymax- height)/2; From 58587a38818b0dba25886c97d584285fef4e9249 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 26 Sep 2011 18:51:10 +0000 Subject: [PATCH 05/13] replace strncpy with BLI_strncpy, in some cases strncpy was being misused since it doesnt ensure \0 termination. also dont call CTX_data_scene() twice when checking for function arguments. --- source/blender/blenfont/intern/blf_lang.c | 2 +- source/blender/blenkernel/intern/action.c | 2 +- source/blender/blenkernel/intern/blender.c | 2 +- source/blender/blenkernel/intern/ipo.c | 2 +- source/blender/blenkernel/intern/key.c | 6 +-- source/blender/blenkernel/intern/node.c | 2 +- source/blender/blenkernel/intern/seqeffects.c | 5 +- source/blender/blenkernel/intern/sequencer.c | 2 +- source/blender/blenloader/intern/readfile.c | 8 +-- source/blender/editors/armature/poselib.c | 2 +- .../blender/editors/physics/particle_edit.c | 2 +- .../blender/editors/sculpt_paint/paint_undo.c | 3 +- .../space_sequencer/sequencer_select.c | 8 +-- source/blender/editors/space_text/text_draw.c | 3 +- source/blender/editors/util/editmode_undo.c | 2 +- .../blender/modifiers/intern/MOD_armature.c | 3 +- source/blender/modifiers/intern/MOD_bevel.c | 2 +- source/blender/modifiers/intern/MOD_cast.c | 3 +- source/blender/modifiers/intern/MOD_curve.c | 3 +- .../blender/modifiers/intern/MOD_displace.c | 5 +- source/blender/modifiers/intern/MOD_hook.c | 5 +- source/blender/modifiers/intern/MOD_lattice.c | 3 +- source/blender/modifiers/intern/MOD_smooth.c | 3 +- source/blender/modifiers/intern/MOD_warp.c | 5 +- source/blender/modifiers/intern/MOD_wave.c | 3 +- source/blender/nodes/intern/node_common.c | 2 +- .../python/generic/bpy_internal_import.c | 2 +- .../render/intern/source/convertblender.c | 2 +- .../blender/render/intern/source/pipeline.c | 2 +- source/creator/creator.c | 53 ++++++++++--------- 30 files changed, 79 insertions(+), 68 deletions(-) diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index b5c6b5bd68c..0a102884969 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -158,7 +158,7 @@ void BLF_lang_set(const char *str) char *s; /* store defaul locale */ - strncpy(default_locale, env_language, sizeof(default_locale)); + BLI_strncpy(default_locale, env_language, sizeof(default_locale)); /* use first language as default */ s= strchr(default_locale, ':'); diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 73ddcbecf94..8d18a1c27e7 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -270,7 +270,7 @@ bActionGroup *action_groups_add_new (bAction *act, const char name[]) /* make it selected, with default name */ agrp->flag = AGRP_SELECTED; - strncpy(agrp->name, name[0] ? name : "Group", sizeof(agrp->name)); + BLI_strncpy(agrp->name, name[0] ? name : "Group", sizeof(agrp->name)); /* add to action, and validate */ BLI_addtail(&act->groups, agrp); diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 27ea1585e4b..1c729470da4 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -518,7 +518,7 @@ void BKE_write_undo(bContext *C, const char *name) /* make new */ curundo= uel= MEM_callocN(sizeof(UndoElem), "undo file"); - strncpy(uel->name, name, MAXUNDONAME-1); + BLI_strncpy(uel->name, name, sizeof(uel->name)); BLI_addtail(&undobase, uel); /* and limit amount to the maximum */ diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 71ca79706db..b885e608b15 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -1103,7 +1103,7 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c agrp->flag = AGRP_SELECTED; if (muteipo) agrp->flag |= AGRP_MUTED; - strncpy(agrp->name, grpname, sizeof(agrp->name)); + BLI_strncpy(agrp->name, grpname, sizeof(agrp->name)); BLI_addtail(&tmp_act.groups, agrp); BLI_uniquename(&tmp_act.groups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name)); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 4b8209ab77e..656bb3ef853 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1445,10 +1445,10 @@ KeyBlock *add_keyblock(Key *key, const char *name) tot= BLI_countlist(&key->block); if(name) { - strncpy(kb->name, name, sizeof(kb->name)); + BLI_strncpy(kb->name, name, sizeof(kb->name)); } else { - if(tot==1) strcpy(kb->name, "Basis"); - else sprintf(kb->name, "Key %d", tot-1); + if(tot==1) BLI_strncpy(kb->name, "Basis", sizeof(kb->name)); + else BLI_snprintf(kb->name, sizeof(kb->name), "Key %d", tot-1); } BLI_uniquename(&key->block, kb, "Key", '.', offsetof(KeyBlock, name), sizeof(kb->name)); diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 524a63a8a95..f0be3c99f13 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1682,7 +1682,7 @@ void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwid void node_type_storage(bNodeType *ntype, const char *storagename, void (*freestoragefunc)(struct bNode *), void (*copystoragefunc)(struct bNode *, struct bNode *)) { if (storagename) - strncpy(ntype->storagename, storagename, sizeof(ntype->storagename)); + BLI_strncpy(ntype->storagename, storagename, sizeof(ntype->storagename)); else ntype->storagename[0] = '\0'; ntype->copystoragefunc = copystoragefunc; diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index e5d74177c91..70b44792b30 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -41,6 +41,7 @@ #include "BLI_math.h" /* windows needs for M_PI */ #include "BLI_utildefines.h" +#include "BLI_string.h" #include "DNA_scene_types.h" #include "DNA_sequence_types.h" @@ -177,7 +178,7 @@ static void open_plugin_seq(PluginSeq *pis, const char *seqname) MEM_freeN(info); cp= BLI_dynlib_find_symbol(pis->handle, "seqname"); - if(cp) strncpy(cp, seqname, 21); + if(cp) BLI_strncpy(cp, seqname, 21); } else { printf ("Plugin returned unrecognized version number\n"); return; @@ -203,7 +204,7 @@ static PluginSeq *add_plugin_seq(const char *str, const char *seqname) pis= MEM_callocN(sizeof(PluginSeq), "PluginSeq"); - strncpy(pis->name, str, FILE_MAXDIR+FILE_MAXFILE); + BLI_strncpy(pis->name, str, FILE_MAX); open_plugin_seq(pis, seqname); if(pis->doit==NULL) { diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index a3237da6234..743111b925f 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -3653,7 +3653,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo calc_sequence_disp(scene, seq); /* last active name */ - strncpy(ed->act_sounddir, strip->dir, FILE_MAXDIR-1); + BLI_strncpy(ed->act_sounddir, strip->dir, FILE_MAXDIR); seq_load_apply(scene, seq, seq_load); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 6163fa015a8..f1f055b4004 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -516,7 +516,7 @@ static Main *blo_find_main(FileData *fd, ListBase *mainlist, const char *filepat BLI_addtail(mainlist, m); lib= alloc_libblock(&m->library, ID_LI, "lib"); - strncpy(lib->name, filepath, sizeof(lib->name)-1); + BLI_strncpy(lib->name, filepath, sizeof(lib->name)); BLI_strncpy(lib->filepath, name1, sizeof(lib->filepath)); m->curlib= lib; @@ -5614,7 +5614,7 @@ static void fix_relpaths_library(const char *basepath, Main *main) * link into an unsaved blend file. See [#27405]. * The remap relative option will make it relative again on save - campbell */ if (strncmp(lib->name, "//", 2)==0) { - strncpy(lib->name, lib->filepath, sizeof(lib->name)); + BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name)); } } } @@ -5623,7 +5623,7 @@ static void fix_relpaths_library(const char *basepath, Main *main) /* Libraries store both relative and abs paths, recreate relative paths, * relative to the blend file since indirectly linked libs will be relative to their direct linked library */ if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */ - strncpy(lib->name, lib->filepath, sizeof(lib->name)); + BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name)); BLI_path_rel(lib->name, basepath); } } @@ -12240,7 +12240,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath) bfd->main->versionfile= fd->fileversion; bfd->type= BLENFILETYPE_BLEND; - strncpy(bfd->main->name, filepath, sizeof(bfd->main->name)-1); + BLI_strncpy(bfd->main->name, filepath, sizeof(bfd->main->name)); while(bhead) { switch(bhead->code) { diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index 8a7d837d2a8..bf2e17c4e87 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -993,7 +993,7 @@ static void poselib_preview_apply (bContext *C, wmOperator *op) memcpy(&tempstr[index+1], &pld->searchstr[index], 64-index); } else { - strncpy(tempstr, pld->searchstr, 64); + BLI_strncpy(tempstr, pld->searchstr, sizeof(tempstr)); } /* get marker name */ diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 74e91cf32ea..019d6df9b73 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -3918,7 +3918,7 @@ void PE_undo_push(Scene *scene, const char *str) /* make new */ edit->curundo= undo= MEM_callocN(sizeof(PTCacheUndo), "particle undo file"); - strncpy(undo->name, str, 64-1); + BLI_strncpy(undo->name, str, sizeof(undo->name)); BLI_addtail(&edit->undo, undo); /* and limit amount to the maximum */ diff --git a/source/blender/editors/sculpt_paint/paint_undo.c b/source/blender/editors/sculpt_paint/paint_undo.c index ba0c2c8be92..345cda63f5a 100644 --- a/source/blender/editors/sculpt_paint/paint_undo.c +++ b/source/blender/editors/sculpt_paint/paint_undo.c @@ -34,6 +34,7 @@ #include "BLI_listbase.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "DNA_userdef_types.h" @@ -106,7 +107,7 @@ static void undo_stack_push_begin(UndoStack *stack, const char *name, UndoRestor BLI_addtail(&stack->elems, uel); /* name can be a dynamic string */ - strncpy(uel->name, name, MAXUNDONAME-1); + BLI_strncpy(uel->name, name, sizeof(uel->name)); /* limit amount to the maximum amount*/ nr= 0; diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index a6cc65017bb..c0919ef3043 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -169,11 +169,11 @@ static void UNUSED_FUNCTION(select_single_seq)(Scene *scene, Sequence *seq, int if((seq->type==SEQ_IMAGE) || (seq->type==SEQ_MOVIE)) { if(seq->strip) - strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1); + BLI_strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR); } else if(seq->type==SEQ_SOUND) { if(seq->strip) - strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1); + BLI_strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR); } seq->flag|= SELECT; recurs_sel_seq(seq); @@ -389,12 +389,12 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event) if ((seq->type == SEQ_IMAGE) || (seq->type == SEQ_MOVIE)) { if(seq->strip) { - strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1); + BLI_strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR); } } else if (seq->type == SEQ_SOUND) { if(seq->strip) { - strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1); + BLI_strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR); } } diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 4c617115a3d..10d355bd0c3 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1421,8 +1421,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar) y -= st->lheight; - strncpy(str, item->name, SUGG_LIST_WIDTH); - str[SUGG_LIST_WIDTH] = '\0'; + BLI_strncpy(str, item->name, SUGG_LIST_WIDTH); w = text_font_width(st, str); diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c index bcbc134d06d..f38ae136f71 100644 --- a/source/blender/editors/util/editmode_undo.c +++ b/source/blender/editors/util/editmode_undo.c @@ -142,7 +142,7 @@ void undo_editmode_push(bContext *C, const char *name, /* make new */ curundo= uel= MEM_callocN(sizeof(UndoElem), "undo editmode"); - strncpy(uel->name, name, MAXUNDONAME-1); + BLI_strncpy(uel->name, name, sizeof(uel->name)); BLI_addtail(&undobase, uel); uel->getdata= getdata; diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index 0b46d950950..0ef85a49899 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -42,6 +42,7 @@ #include "DNA_mesh_types.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_cdderivedmesh.h" @@ -70,7 +71,7 @@ static void copyData(ModifierData *md, ModifierData *target) tamd->object = amd->object; tamd->deformflag = amd->deformflag; tamd->multi = amd->multi; - strncpy(tamd->defgrp_name, amd->defgrp_name, 32); + BLI_strncpy(tamd->defgrp_name, amd->defgrp_name, 32); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md)) diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 277f404f64d..197e6a24342 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -72,7 +72,7 @@ static void copyData(ModifierData *md, ModifierData *target) tbmd->lim_flags = bmd->lim_flags; tbmd->e_flags = bmd->e_flags; tbmd->bevel_angle = bmd->bevel_angle; - strncpy(tbmd->defgrp_name, bmd->defgrp_name, 32); + BLI_strncpy(tbmd->defgrp_name, bmd->defgrp_name, 32); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c index 4061128b5ad..b0e001f0978 100644 --- a/source/blender/modifiers/intern/MOD_cast.c +++ b/source/blender/modifiers/intern/MOD_cast.c @@ -40,6 +40,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_deform.h" @@ -77,7 +78,7 @@ static void copyData(ModifierData *md, ModifierData *target) tcmd->flag = cmd->flag; tcmd->type = cmd->type; tcmd->object = cmd->object; - strncpy(tcmd->defgrp_name, cmd->defgrp_name, 32); + BLI_strncpy(tcmd->defgrp_name, cmd->defgrp_name, 32); } static int isDisabled(ModifierData *md, int UNUSED(useRenderParams)) diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index d928c239eac..b732158358d 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -41,6 +41,7 @@ #include "DNA_object_types.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_cdderivedmesh.h" @@ -65,7 +66,7 @@ static void copyData(ModifierData *md, ModifierData *target) tcmd->defaxis = cmd->defaxis; tcmd->object = cmd->object; - strncpy(tcmd->name, cmd->name, 32); + BLI_strncpy(tcmd->name, cmd->name, 32); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index fb7aeacecc8..b0d9892a8df 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -40,6 +40,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_cdderivedmesh.h" @@ -75,11 +76,11 @@ static void copyData(ModifierData *md, ModifierData *target) tdmd->texture = dmd->texture; tdmd->strength = dmd->strength; tdmd->direction = dmd->direction; - strncpy(tdmd->defgrp_name, dmd->defgrp_name, 32); + BLI_strncpy(tdmd->defgrp_name, dmd->defgrp_name, 32); tdmd->midlevel = dmd->midlevel; tdmd->texmapping = dmd->texmapping; tdmd->map_object = dmd->map_object; - strncpy(tdmd->uvlayer_name, dmd->uvlayer_name, 32); + BLI_strncpy(tdmd->uvlayer_name, dmd->uvlayer_name, 32); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index 785abc7d4d1..ad97ee82ee2 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -41,6 +41,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_action.h" #include "BKE_cdderivedmesh.h" @@ -72,8 +73,8 @@ static void copyData(ModifierData *md, ModifierData *target) thmd->totindex = hmd->totindex; thmd->indexar = MEM_dupallocN(hmd->indexar); memcpy(thmd->parentinv, hmd->parentinv, sizeof(hmd->parentinv)); - strncpy(thmd->name, hmd->name, 32); - strncpy(thmd->subtarget, hmd->subtarget, 32); + BLI_strncpy(thmd->name, hmd->name, 32); + BLI_strncpy(thmd->subtarget, hmd->subtarget, 32); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c index 31c17fb7376..4ff92e3c86d 100644 --- a/source/blender/modifiers/intern/MOD_lattice.c +++ b/source/blender/modifiers/intern/MOD_lattice.c @@ -40,6 +40,7 @@ #include "DNA_object_types.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_cdderivedmesh.h" @@ -57,7 +58,7 @@ static void copyData(ModifierData *md, ModifierData *target) LatticeModifierData *tlmd = (LatticeModifierData*) target; tlmd->object = lmd->object; - strncpy(tlmd->name, lmd->name, 32); + BLI_strncpy(tlmd->name, lmd->name, 32); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 16898a80b53..5e13b8a6d3c 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -39,6 +39,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_cdderivedmesh.h" #include "BKE_particle.h" @@ -69,7 +70,7 @@ static void copyData(ModifierData *md, ModifierData *target) tsmd->fac = smd->fac; tsmd->repeat = smd->repeat; tsmd->flag = smd->flag; - strncpy(tsmd->defgrp_name, smd->defgrp_name, 32); + BLI_strncpy(tsmd->defgrp_name, smd->defgrp_name, 32); } static int isDisabled(ModifierData *md, int UNUSED(useRenderParams)) diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 36d3dc88b56..a088ba80b3d 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -33,6 +33,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_cdderivedmesh.h" #include "BKE_modifier.h" @@ -73,13 +74,13 @@ static void copyData(ModifierData *md, ModifierData *target) twmd->strength = wmd->strength; twmd->falloff_radius = wmd->falloff_radius; twmd->falloff_type = wmd->falloff_type; - strncpy(twmd->defgrp_name, wmd->defgrp_name, sizeof(twmd->defgrp_name)); + BLI_strncpy(twmd->defgrp_name, wmd->defgrp_name, sizeof(twmd->defgrp_name)); twmd->curfalloff = curvemapping_copy(wmd->curfalloff); /* map info */ twmd->texture = wmd->texture; twmd->map_object = wmd->map_object; - strncpy(twmd->uvlayer_name, wmd->uvlayer_name, sizeof(twmd->uvlayer_name)); + BLI_strncpy(twmd->uvlayer_name, wmd->uvlayer_name, sizeof(twmd->uvlayer_name)); twmd->texmapping= wmd->texmapping; } diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index 4b5769ff603..820c7e16f53 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -42,6 +42,7 @@ #include "DNA_object_types.h" #include "BLI_utildefines.h" +#include "BLI_string.h" #include "BKE_DerivedMesh.h" @@ -98,7 +99,7 @@ static void copyData(ModifierData *md, ModifierData *target) twmd->texture = wmd->texture; twmd->map_object = wmd->map_object; twmd->texmapping = wmd->texmapping; - strncpy(twmd->defgrp_name, wmd->defgrp_name, 32); + BLI_strncpy(twmd->defgrp_name, wmd->defgrp_name, 32); } static int dependsOnTime(ModifierData *UNUSED(md)) diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 8225c986409..fa5a3c727c2 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -567,7 +567,7 @@ bNodeSocket *node_group_add_socket(bNodeTree *ngroup, const char *name, int type bNodeSocketType *stype = ntreeGetSocketType(type); bNodeSocket *gsock = MEM_callocN(sizeof(bNodeSocket), "bNodeSocket"); - strncpy(gsock->name, name, sizeof(gsock->name)); + BLI_strncpy(gsock->name, name, sizeof(gsock->name)); gsock->type = type; /* group sockets are dynamically added */ gsock->flag |= SOCK_DYNAMIC; diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 67ed90c79eb..90260100c83 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -120,7 +120,7 @@ PyObject *bpy_text_import(Text *text) } len= strlen(text->id.name+2); - strncpy(modulename, text->id.name+2, len); + BLI_strncpy(modulename, text->id.name+2, len); modulename[len - 3]= '\0'; /* remove .py */ return PyImport_ExecCodeModule(modulename, text->compiled); } diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index b972569fdf6..f06707c94fe 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -5026,7 +5026,7 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l /* per second, per object, stats print this */ re->i.infostr= "Preparing Scene data"; re->i.cfra= scene->r.cfra; - strncpy(re->i.scenename, scene->id.name+2, 20); + BLI_strncpy(re->i.scenename, scene->id.name+2, sizeof(re->i.scenename)); /* XXX add test if dbase was filled already? */ diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 05bcc32a90a..7835ae6dcd3 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -1198,7 +1198,7 @@ Render *RE_NewRender(const char *name) /* new render data struct */ re= MEM_callocN(sizeof(Render), "new render"); BLI_addtail(&RenderGlobal.renderlist, re); - strncpy(re->name, name, RE_MAXNAME); + BLI_strncpy(re->name, name, RE_MAXNAME); BLI_rw_mutex_init(&re->resultmutex); } diff --git a/source/creator/creator.c b/source/creator/creator.c index d25b0be30d8..3ce469de4e8 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -520,8 +520,8 @@ static int set_output(int argc, const char **argv, void *data) { bContext *C = data; if (argc >= 1){ - if (CTX_data_scene(C)) { - Scene *scene= CTX_data_scene(C); + Scene *scene= CTX_data_scene(C); + if (scene) { BLI_strncpy(scene->r.pic, argv[1], sizeof(scene->r.pic)); } else { printf("\nError: no blend loaded. cannot use '-o / --render-output'.\n"); @@ -546,17 +546,17 @@ static int set_engine(int argc, const char **argv, void *data) exit(0); } else { - if (CTX_data_scene(C)==NULL) { - printf("\nError: no blend loaded. order the arguments so '-E / --engine ' is after a blend is loaded.\n"); - } - else { - Scene *scene= CTX_data_scene(C); + Scene *scene= CTX_data_scene(C); + if (scene) { RenderData *rd = &scene->r; if(BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) { BLI_strncpy_utf8(rd->engine, argv[1], sizeof(rd->engine)); } } + else { + printf("\nError: no blend loaded. order the arguments so '-E / --engine ' is after a blend is loaded.\n"); + } } return 1; @@ -573,10 +573,8 @@ static int set_image_type(int argc, const char **argv, void *data) bContext *C = data; if (argc >= 1){ const char *imtype = argv[1]; - if (CTX_data_scene(C)==NULL) { - printf("\nError: no blend loaded. order the arguments so '-F / --render-format' is after the blend is loaded.\n"); - } else { - Scene *scene= CTX_data_scene(C); + Scene *scene= CTX_data_scene(C); + if (scene) { if (!strcmp(imtype,"TGA")) scene->r.imtype = R_TARGA; else if (!strcmp(imtype,"IRIS")) scene->r.imtype = R_IRIS; #ifdef WITH_DDS @@ -612,6 +610,9 @@ static int set_image_type(int argc, const char **argv, void *data) #endif else printf("\nError: Format from '-F / --render-format' not known or not compiled in this release.\n"); } + else { + printf("\nError: no blend loaded. order the arguments so '-F / --render-format' is after the blend is loaded.\n"); + } return 1; } else { printf("\nError: you must specify a format after '-F / --render-foramt'.\n"); @@ -638,8 +639,8 @@ static int set_extension(int argc, const char **argv, void *data) { bContext *C = data; if (argc >= 1) { - if (CTX_data_scene(C)) { - Scene *scene= CTX_data_scene(C); + Scene *scene= CTX_data_scene(C); + if (scene) { if (argv[1][0] == '0') { scene->r.scemode &= ~R_EXTENSION; } else if (argv[1][0] == '1') { @@ -721,9 +722,9 @@ example: static int render_frame(int argc, const char **argv, void *data) { bContext *C = data; - if (CTX_data_scene(C)) { + Scene *scene= CTX_data_scene(C); + if (scene) { Main *bmain= CTX_data_main(C); - Scene *scene= CTX_data_scene(C); if (argc > 1) { Render *re = RE_NewRender(scene->id.name); @@ -763,9 +764,9 @@ static int render_frame(int argc, const char **argv, void *data) static int render_animation(int UNUSED(argc), const char **UNUSED(argv), void *data) { bContext *C = data; - if (CTX_data_scene(C)) { + Scene *scene= CTX_data_scene(C); + if (scene) { Main *bmain= CTX_data_main(C); - Scene *scene= CTX_data_scene(C); Render *re= RE_NewRender(scene->id.name); ReportList reports; BKE_reports_init(&reports, RPT_PRINT); @@ -782,9 +783,9 @@ static int set_scene(int argc, const char **argv, void *data) { if(argc > 1) { bContext *C= data; - Scene *sce= set_scene_name(CTX_data_main(C), argv[1]); - if(sce) { - CTX_data_scene_set(C, sce); + Scene *scene= set_scene_name(CTX_data_main(C), argv[1]); + if(scene) { + CTX_data_scene_set(C, scene); } return 1; } else { @@ -796,8 +797,8 @@ static int set_scene(int argc, const char **argv, void *data) static int set_start_frame(int argc, const char **argv, void *data) { bContext *C = data; - if (CTX_data_scene(C)) { - Scene *scene= CTX_data_scene(C); + Scene *scene= CTX_data_scene(C); + if (scene) { if (argc > 1) { int frame = atoi(argv[1]); (scene->r.sfra) = CLAMPIS(frame, MINFRAME, MAXFRAME); @@ -815,8 +816,8 @@ static int set_start_frame(int argc, const char **argv, void *data) static int set_end_frame(int argc, const char **argv, void *data) { bContext *C = data; - if (CTX_data_scene(C)) { - Scene *scene= CTX_data_scene(C); + Scene *scene= CTX_data_scene(C); + if (scene) { if (argc > 1) { int frame = atoi(argv[1]); (scene->r.efra) = CLAMPIS(frame, MINFRAME, MAXFRAME); @@ -834,8 +835,8 @@ static int set_end_frame(int argc, const char **argv, void *data) static int set_skip_frame(int argc, const char **argv, void *data) { bContext *C = data; - if (CTX_data_scene(C)) { - Scene *scene= CTX_data_scene(C); + Scene *scene= CTX_data_scene(C); + if (scene) { if (argc > 1) { int frame = atoi(argv[1]); (scene->r.frame_step) = CLAMPIS(frame, 1, MAXFRAME); From 217030120463276043fa977656d3cd5bc13cd411 Mon Sep 17 00:00:00 2001 From: Martin Poirier Date: Tue, 27 Sep 2011 01:28:15 +0000 Subject: [PATCH 06/13] [#28681] Switching transform type doesn't register correct operator for 'repeat'. Reported by Nicholas Rishel Part of a potential fix, see discussion in tracker. --- source/blender/editors/transform/transform.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index fbe0a1864bf..c77f7620326 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1358,6 +1358,11 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) int proportional = 0; PropertyRNA *prop; + // Save back mode in case we're in the generic operator + if ((prop= RNA_struct_find_property(op->ptr, "mode"))) { + RNA_property_enum_set(op->ptr, prop, t->mode); + } + if ((prop= RNA_struct_find_property(op->ptr, "value"))) { float *values= (t->flag & T_AUTOVALUES) ? t->auto_values : t->values; if (RNA_property_array_check(prop)) { From f4dec97cef4b320c6f3ffd2ddc39d429da4fd4d5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 27 Sep 2011 01:32:27 +0000 Subject: [PATCH 07/13] fix for building on windows, clear some warnings too --- CMakeLists.txt | 17 +++++++++++------ .../blenkernel/intern/writeframeserver.c | 4 ++++ source/blender/blenlib/intern/storage.c | 2 +- source/blender/blenlib/intern/winstuff.c | 10 +++++----- source/blender/editors/include/UI_interface.h | 1 + source/blender/editors/space_node/node_intern.h | 1 + 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79579fd9370..3b9e3bdcb92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1153,14 +1153,19 @@ endif() # set the endian define -include(TestBigEndian) -test_big_endian(_SYSTEM_BIG_ENDIAN) -if(_SYSTEM_BIG_ENDIAN) - add_definitions(-D__BIG_ENDIAN__) -else() +if(MSVC) + # for some reason this fails on msvc add_definitions(-D__LITTLE_ENDIAN__) +else() + include(TestBigEndian) + test_big_endian(_SYSTEM_BIG_ENDIAN) + if(_SYSTEM_BIG_ENDIAN) + add_definitions(-D__BIG_ENDIAN__) + else() + add_definitions(-D__LITTLE_ENDIAN__) + endif() + unset(_SYSTEM_BIG_ENDIAN) endif() -unset(_SYSTEM_BIG_ENDIAN) if(WITH_IMAGE_OPENJPEG) diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index d13d15d1269..15cb3b66db7 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -257,7 +257,11 @@ int frameserver_loop(RenderData *rd, ReportList *UNUSED(reports)) struct timeval tv; struct sockaddr_in addr; int len, rval; +#ifdef FREE_WINDOWS + int socklen; +#else unsigned int socklen; +#endif char buf[4096]; if (connsock != -1) { diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index f088c5e2787..8be86a4b407 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -488,7 +488,7 @@ LinkNode *BLI_read_file_as_lines(const char *name) buf= MEM_mallocN(size, "file_as_lines"); if (buf) { - int i, last= 0; + size_t i, last= 0; /* * size = because on win32 reading diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 66080ed2a85..bf816a91fb3 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -301,7 +301,7 @@ char* dirname(char *path) { char *p; if( path == NULL || *path == '\0' ) - return "."; + return "."; p = path + strlen(path) - 1; while( *p == '/' ) { if( p == path ) @@ -309,11 +309,11 @@ char* dirname(char *path) *p-- = '\0'; } while( p >= path && *p != '/' ) - p--; + p--; return - p < path ? "." : - p == path ? "/" : - (*p = '\0', path); + p < path ? "." : + p == path ? "/" : + (*p = '\0', path); } /* End of copied part */ diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 67b17a891ca..4a895472b33 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -34,6 +34,7 @@ #ifndef UI_INTERFACE_H #define UI_INTERFACE_H +#include "BLO_sys_types.h" /* size_t */ #include "RNA_types.h" #include "DNA_userdef_types.h" diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index 3751d8efae8..8bc0ae51415 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -33,6 +33,7 @@ #ifndef ED_NODE_INTERN_H #define ED_NODE_INTERN_H +#include /* for size_t */ #include "UI_interface.h" /* internal exports only */ From d98bcb8a77c0a06dc35669dd8898f1f9f2ad85c6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 27 Sep 2011 04:07:48 +0000 Subject: [PATCH 08/13] fix for py/rna api bug: PyC_UnicodeAsByte(), used for getting python strings as bytes wasnt clearning utf-8 conversion errors. this would raise an error when getting an operators filepath. --- source/blender/python/generic/py_capi_utils.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index d5bd44fc288..17fda6d08a7 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -363,12 +363,15 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) * chars since blender doesnt limit this */ return result; } - else if(PyBytes_Check(py_str)) { - PyErr_Clear(); - return PyBytes_AS_STRING(py_str); - } else { - return PyBytes_AS_STRING((*coerce= PyUnicode_EncodeFSDefault(py_str))); + PyErr_Clear(); + + if(PyBytes_Check(py_str)) { + return PyBytes_AS_STRING(py_str); + } + else { + return PyBytes_AS_STRING((*coerce= PyUnicode_EncodeFSDefault(py_str))); + } } } From 928e2784c6596f64ca5201eed269959865d15970 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 27 Sep 2011 05:28:06 +0000 Subject: [PATCH 09/13] py api - use Py_ssize_t when dealing with python sequence sizes - dont call PySequence_Size(py_b) in a loop (its slow). - use faster sequence/float parsing in aud.Factory.filter --- intern/audaspace/Python/AUD_PyAPI.cpp | 22 +++++++++++++------- source/blender/python/generic/IDProp.c | 2 +- source/blender/python/generic/bgl.c | 4 ++-- source/blender/python/intern/bpy_rna.c | 4 ++-- source/blender/python/intern/bpy_rna_array.c | 12 +++++------ 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/intern/audaspace/Python/AUD_PyAPI.cpp b/intern/audaspace/Python/AUD_PyAPI.cpp index 928c67c5196..3ec088053ca 100644 --- a/intern/audaspace/Python/AUD_PyAPI.cpp +++ b/intern/audaspace/Python/AUD_PyAPI.cpp @@ -848,6 +848,8 @@ Factory_filter(Factory* self, PyObject* args) { PyObject* py_b; PyObject* py_a = NULL; + Py_ssize_t py_a_len; + Py_ssize_t py_b_len; if(!PyArg_ParseTuple(args, "O|O:filter", &py_b, &py_a)) return NULL; @@ -858,7 +860,10 @@ Factory_filter(Factory* self, PyObject* args) return NULL; } - if(!PySequence_Size(py_b) || (py_a != NULL && !PySequence_Size(py_a))) + py_a_len= py_a ? PySequence_Size(py_a) : 0; + py_b_len= PySequence_Size(py_b); + + if(!py_b_len || ((py_a != NULL) && !py_b_len)) { PyErr_SetString(PyExc_ValueError, "The sequence has to contain at least one value!"); return NULL; @@ -867,30 +872,31 @@ Factory_filter(Factory* self, PyObject* args) std::vector a, b; PyObject* py_value; float value; - int result; - for(int i = 0; i < PySequence_Size(py_b); i++) + for(Py_ssize_t i = 0; i < py_b_len; i++) { py_value = PySequence_GetItem(py_b, i); - result = PyArg_Parse(py_value, "f:filter", &value); + value= (float)PyFloat_AsDouble(py_value); Py_DECREF(py_value); - if(!result) + if (value==-1.0f && PyErr_Occurred()) { return NULL; + } b.push_back(value); } if(py_a) { - for(int i = 0; i < PySequence_Size(py_a); i++) + for(Py_ssize_t i = 0; i < py_a_len; i++) { py_value = PySequence_GetItem(py_a, i); - result = PyArg_Parse(py_value, "f:filter", &value); + value= (float)PyFloat_AsDouble(py_value); Py_DECREF(py_value); - if(!result) + if (value==-1.0f && PyErr_Occurred()) { return NULL; + } a.push_back(value); } diff --git a/source/blender/python/generic/IDProp.c b/source/blender/python/generic/IDProp.c index 2543d34f58c..e6883eb30af 100644 --- a/source/blender/python/generic/IDProp.c +++ b/source/blender/python/generic/IDProp.c @@ -269,7 +269,7 @@ static int idp_sequence_type(PyObject *seq) PyObject *item; int type= IDP_INT; - int i, len = PySequence_Size(seq); + Py_ssize_t i, len = PySequence_Size(seq); for (i=0; i < len; i++) { item = PySequence_GetItem(seq, i); if (PyFloat_Check(item)) { diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 44d42a479ec..35c211d5424 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -286,8 +286,8 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject Buffer *buffer; int dimensions[MAX_DIMENSIONS]; - int i, type; - int ndimensions = 0; + int type; + Py_ssize_t i, ndimensions = 0; if(kwds && PyDict_Size(kwds)) { PyErr_SetString(PyExc_TypeError, diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 3175c0d088e..bcbd7670e2c 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1718,7 +1718,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } case PROP_COLLECTION: { - int seq_len, i; + Py_ssize_t seq_len, i; PyObject *item; PointerRNA itemptr; ListBase *lb; @@ -1736,7 +1736,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } seq_len= PySequence_Size(value); - for(i=0; itp_name); @@ -147,8 +147,8 @@ static int count_items(PyObject *seq, int dim) int totitem= 0; if(dim > 1) { - const int seq_size= PySequence_Size(seq); - int i; + const Py_ssize_t seq_size= PySequence_Size(seq); + Py_ssize_t i; for (i= 0; i < seq_size; i++) { PyObject *item= PySequence_GetItem(seq, i); if(item) { @@ -281,9 +281,9 @@ static char *copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *pro static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index) { - unsigned int i; int totdim= RNA_property_array_dimension(ptr, prop, NULL); - const int seq_size= PySequence_Size(seq); + const Py_ssize_t seq_size= PySequence_Size(seq); + Py_ssize_t i; /* Regarding PySequence_GetItem() failing. * From a25c7f647e3050239d0c0ea35db37a3e48f84e4c Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 27 Sep 2011 09:09:43 +0000 Subject: [PATCH 10/13] navmesh: convert object_navmesh.cpp to plain c. --- extern/recastnavigation/recast-capi.cpp | 215 +++++++++++++++ extern/recastnavigation/recast-capi.h | 86 ++++++ source/blender/editors/object/CMakeLists.txt | 4 +- source/blender/editors/object/SConscript | 4 +- .../{object_navmesh.cpp => object_navmesh.c} | 254 +++++++++++------- .../editors/space_view3d/view3d_edit.c | 2 +- .../windowmanager/intern/wm_event_system.c | 3 - 7 files changed, 461 insertions(+), 107 deletions(-) rename source/blender/editors/object/{object_navmesh.cpp => object_navmesh.c} (70%) diff --git a/extern/recastnavigation/recast-capi.cpp b/extern/recastnavigation/recast-capi.cpp index 52c4cdc90ed..2348497b0d7 100644 --- a/extern/recastnavigation/recast-capi.cpp +++ b/extern/recastnavigation/recast-capi.cpp @@ -35,3 +35,218 @@ int recast_buildMeshAdjacency(unsigned short* polys, const int npolys, { return (int) buildMeshAdjacency(polys, npolys, nverts, vertsPerPoly); } + +void recast_calcBounds(const float *verts, int nv, float *bmin, float *bmax) +{ + rcCalcBounds(verts, nv, bmin, bmax); +} + +void recast_calcGridSize(const float *bmin, const float *bmax, float cs, int *w, int *h) +{ + rcCalcGridSize(bmin, bmax, cs, w, h); +} + +struct recast_heightfield *recast_newHeightfield(void) +{ + return (struct recast_heightfield *) (new rcHeightfield); +} + +void recast_destroyHeightfield(struct recast_heightfield *heightfield) +{ + delete (rcHeightfield *) heightfield; +} + +int recast_createHeightfield(struct recast_heightfield *hf, int width, int height, + const float *bmin, const float* bmax, float cs, float ch) +{ + return rcCreateHeightfield(*(rcHeightfield *)hf, width, height, bmin, bmax, cs, ch); +} + +void recast_markWalkableTriangles(const float walkableSlopeAngle,const float *verts, int nv, + const int *tris, int nt, unsigned char *flags) +{ + rcMarkWalkableTriangles(walkableSlopeAngle, verts, nv, tris, nt, flags); +} + +void recast_rasterizeTriangles(const float *verts, int nv, const int *tris, + const unsigned char *flags, int nt, struct recast_heightfield *solid) +{ + rcRasterizeTriangles(verts, nv, tris, flags, nt, *(rcHeightfield *) solid); +} + +void recast_filterLedgeSpans(const int walkableHeight, const int walkableClimb, + struct recast_heightfield *solid) +{ + rcFilterLedgeSpans(walkableHeight, walkableClimb, *(rcHeightfield *) solid); +} + +void recast_filterWalkableLowHeightSpans(int walkableHeight, struct recast_heightfield *solid) +{ + rcFilterWalkableLowHeightSpans(walkableHeight, *(rcHeightfield *) solid); +} + +struct recast_compactHeightfield *recast_newCompactHeightfield(void) +{ + return (struct recast_compactHeightfield *) (new rcCompactHeightfield); +} + +void recast_destroyCompactHeightfield(struct recast_compactHeightfield *compactHeightfield) +{ + delete (rcCompactHeightfield *) compactHeightfield; +} + +int recast_buildCompactHeightfield(const int walkableHeight, const int walkableClimb, + unsigned char flags, struct recast_heightfield *hf, struct recast_compactHeightfield *chf) +{ + int rcFlags = 0; + + if(flags & RECAST_WALKABLE) + rcFlags |= RC_WALKABLE; + + if(flags & RECAST_REACHABLE) + rcFlags |= RC_REACHABLE; + + return rcBuildCompactHeightfield(walkableHeight, walkableClimb, rcFlags, + *(rcHeightfield *) hf, *(rcCompactHeightfield *) chf); +} + +int recast_buildDistanceField(struct recast_compactHeightfield *chf) +{ + return rcBuildDistanceField(*(rcCompactHeightfield *) chf); +} + +int recast_buildRegions(struct recast_compactHeightfield *chf, int walkableRadius, int borderSize, + int minRegionSize, int mergeRegionSize) +{ + return rcBuildRegions(*(rcCompactHeightfield *) chf, walkableRadius, borderSize, + minRegionSize, mergeRegionSize); +} + +struct recast_contourSet *recast_newContourSet(void) +{ + return (struct recast_contourSet *) (new rcContourSet); +} + +void recast_destroyContourSet(struct recast_contourSet *contourSet) +{ + delete (rcContourSet *) contourSet; +} + +int recast_buildContours(struct recast_compactHeightfield *chf, + const float maxError, const int maxEdgeLen, struct recast_contourSet *cset) +{ + return rcBuildContours(*(rcCompactHeightfield *) chf, maxError, maxEdgeLen, *(rcContourSet *) cset); +} + +struct recast_polyMesh *recast_newPolyMesh(void) +{ + return (recast_polyMesh *) (new rcPolyMesh); +} + +void recast_destroyPolyMesh(struct recast_polyMesh *polyMesh) +{ + delete (rcPolyMesh *) polyMesh; +} + +int recast_buildPolyMesh(struct recast_contourSet *cset, int nvp, struct recast_polyMesh *mesh) +{ + return rcBuildPolyMesh(*(rcContourSet *) cset, nvp, * (rcPolyMesh *) mesh); +} + +unsigned short *recast_polyMeshGetVerts(struct recast_polyMesh *mesh, int *nverts) +{ + rcPolyMesh *pmesh = (rcPolyMesh *)mesh; + + if (nverts) + *nverts = pmesh->nverts; + + return pmesh->verts; +} + +void recast_polyMeshGetBoundbox(struct recast_polyMesh *mesh, float *bmin, float *bmax) +{ + rcPolyMesh *pmesh = (rcPolyMesh *)mesh; + + if (bmin) { + bmin[0] = pmesh->bmin[0]; + bmin[1] = pmesh->bmin[1]; + bmin[2] = pmesh->bmin[2]; + } + + if (bmax) { + bmax[0] = pmesh->bmax[0]; + bmax[1] = pmesh->bmax[1]; + bmax[2] = pmesh->bmax[2]; + } +} + +void recast_polyMeshGetCell(struct recast_polyMesh *mesh, float *cs, float *ch) +{ + rcPolyMesh *pmesh = (rcPolyMesh *)mesh; + + if (cs) + *cs = pmesh->cs; + + if (ch) + *ch = pmesh->ch; +} + +unsigned short *recast_polyMeshGetPolys(struct recast_polyMesh *mesh, int *npolys, int *nvp) +{ + rcPolyMesh *pmesh = (rcPolyMesh *)mesh; + + if (npolys) + *npolys = pmesh->npolys; + + if (nvp) + *nvp = pmesh->nvp; + + return pmesh->polys; +} + +struct recast_polyMeshDetail *recast_newPolyMeshDetail(void) +{ + return (struct recast_polyMeshDetail *) (new rcPolyMeshDetail); +} + +void recast_destroyPolyMeshDetail(struct recast_polyMeshDetail *polyMeshDetail) +{ + delete (rcPolyMeshDetail *) polyMeshDetail; +} + +int recast_buildPolyMeshDetail(const struct recast_polyMesh *mesh, const struct recast_compactHeightfield *chf, + const float sampleDist, const float sampleMaxError, struct recast_polyMeshDetail *dmesh) +{ + return rcBuildPolyMeshDetail(*(rcPolyMesh *) mesh, *(rcCompactHeightfield *) chf, + sampleDist, sampleMaxError, *(rcPolyMeshDetail *) dmesh); +} + +float *recast_polyMeshDetailGetVerts(struct recast_polyMeshDetail *mesh, int *nverts) +{ + rcPolyMeshDetail *dmesh = (rcPolyMeshDetail *)mesh; + + if (nverts) + *nverts = dmesh->nverts; + + return dmesh->verts; +} + +unsigned char *recast_polyMeshDetailGetTris(struct recast_polyMeshDetail *mesh, int *ntris) +{ + rcPolyMeshDetail *dmesh = (rcPolyMeshDetail *)mesh; + + if (ntris) + *ntris = dmesh->ntris; + + return dmesh->tris; +} + +unsigned short *recast_polyMeshDetailGetMeshes(struct recast_polyMeshDetail *mesh, int *nmeshes) +{ + rcPolyMeshDetail *dmesh = (rcPolyMeshDetail *)mesh; + + if (nmeshes) + *nmeshes = dmesh->nmeshes; + + return dmesh->meshes; +} diff --git a/extern/recastnavigation/recast-capi.h b/extern/recastnavigation/recast-capi.h index 0d20fdf9981..58fe08e6335 100644 --- a/extern/recastnavigation/recast-capi.h +++ b/extern/recastnavigation/recast-capi.h @@ -32,9 +32,95 @@ extern "C" { #endif +struct recast_polyMesh; +struct recast_polyMeshDetail; +struct recast_heightfield; +struct recast_compactHeightfield; +struct recast_contourSet; + +enum recast_SpanFlags +{ + RECAST_WALKABLE = 0x01, + RECAST_REACHABLE = 0x02 +}; + int recast_buildMeshAdjacency(unsigned short* polys, const int npolys, const int nverts, const int vertsPerPoly); +void recast_calcBounds(const float *verts, int nv, float *bmin, float *bmax); + +void recast_calcGridSize(const float *bmin, const float *bmax, float cs, int *w, int *h); + +struct recast_heightfield *recast_newHeightfield(void); + +void recast_destroyHeightfield(struct recast_heightfield *heightfield); + +int recast_createHeightfield(struct recast_heightfield *hf, int width, int height, + const float *bmin, const float* bmax, float cs, float ch); + +void recast_markWalkableTriangles(const float walkableSlopeAngle,const float *verts, int nv, + const int *tris, int nt, unsigned char *flags); + +void recast_rasterizeTriangles(const float *verts, int nv, const int *tris, + const unsigned char *flags, int nt, struct recast_heightfield *solid); + +void recast_filterLedgeSpans(const int walkableHeight, const int walkableClimb, + struct recast_heightfield *solid); + +void recast_filterWalkableLowHeightSpans(int walkableHeight, struct recast_heightfield *solid); + +struct recast_compactHeightfield *recast_newCompactHeightfield(void); + +void recast_destroyCompactHeightfield(struct recast_compactHeightfield *compactHeightfield); + +int recast_buildCompactHeightfield(const int walkableHeight, const int walkableClimb, + unsigned char flags, struct recast_heightfield *hf, struct recast_compactHeightfield *chf); + +int recast_buildDistanceField(struct recast_compactHeightfield *chf); + +int recast_buildRegions(struct recast_compactHeightfield *chf, int walkableRadius, int borderSize, + int minRegionSize, int mergeRegionSize); + +/* Contour set */ + +struct recast_contourSet *recast_newContourSet(void); + +void recast_destroyContourSet(struct recast_contourSet *contourSet); + +int recast_buildContours(struct recast_compactHeightfield *chf, + const float maxError, const int maxEdgeLen, struct recast_contourSet *cset); + +/* Poly mesh */ + +struct recast_polyMesh *recast_newPolyMesh(void); + +void recast_destroyPolyMesh(struct recast_polyMesh *polyMesh); + +int recast_buildPolyMesh(struct recast_contourSet *cset, int nvp, struct recast_polyMesh *mesh); + +unsigned short *recast_polyMeshGetVerts(struct recast_polyMesh *mesh, int *nverts); + +void recast_polyMeshGetBoundbox(struct recast_polyMesh *mesh, float *bmin, float *bmax); + +void recast_polyMeshGetCell(struct recast_polyMesh *mesh, float *cs, float *ch); + +unsigned short *recast_polyMeshGetPolys(struct recast_polyMesh *mesh, int *npolys, int *nvp); + +/* Poly mesh detail */ + +struct recast_polyMeshDetail *recast_newPolyMeshDetail(void); + +void recast_destroyPolyMeshDetail(struct recast_polyMeshDetail *polyMeshDetail); + +int recast_buildPolyMeshDetail(const struct recast_polyMesh *mesh, const struct recast_compactHeightfield *chf, + const float sampleDist, const float sampleMaxError, struct recast_polyMeshDetail *dmesh); + +float *recast_polyMeshDetailGetVerts(struct recast_polyMeshDetail *mesh, int *nverts); + +unsigned char *recast_polyMeshDetailGetTris(struct recast_polyMeshDetail *mesh, int *ntris); + +unsigned short *recast_polyMeshDetailGetMeshes(struct recast_polyMeshDetail *mesh, int *nmeshes); + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt index b9b8ddc6305..b0b4f9dc0eb 100644 --- a/source/blender/editors/object/CMakeLists.txt +++ b/source/blender/editors/object/CMakeLists.txt @@ -60,11 +60,11 @@ set(SRC if(WITH_GAMEENGINE) list(APPEND INC - ../../../../extern/recastnavigation/Recast/Include + ../../../../extern/recastnavigation ) list(APPEND SRC - object_navmesh.cpp + object_navmesh.c ) endif() diff --git a/source/blender/editors/object/SConscript b/source/blender/editors/object/SConscript index cdda16582ef..d4739236ba1 100644 --- a/source/blender/editors/object/SConscript +++ b/source/blender/editors/object/SConscript @@ -1,13 +1,13 @@ #!/usr/bin/python Import ('env') -sources = env.Glob('*.c') + env.Glob('*.cpp') +sources = env.Glob('*.c') incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf' incs += ' ../../windowmanager #/intern/guardedalloc ../../blenloader' incs += ' ../../makesrna ../../python ../../ikplugin' incs += ' ../../render/extern/include ../../gpu' # for object_bake.c -incs += ' #extern/recastnavigation/Recast/Include' +incs += ' #extern/recastnavigation' defs = [] diff --git a/source/blender/editors/object/object_navmesh.cpp b/source/blender/editors/object/object_navmesh.c similarity index 70% rename from source/blender/editors/object/object_navmesh.cpp rename to source/blender/editors/object/object_navmesh.c index ae97b40eb49..413d8757be2 100644 --- a/source/blender/editors/object/object_navmesh.cpp +++ b/source/blender/editors/object/object_navmesh.c @@ -28,10 +28,7 @@ */ #include -#include "Recast.h" -extern "C" -{ #include "MEM_guardedalloc.h" #include "DNA_scene_types.h" @@ -43,20 +40,27 @@ extern "C" #include "BKE_library.h" #include "BKE_depsgraph.h" #include "BKE_context.h" +#include "BKE_main.h" #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_scene.h" #include "BKE_DerivedMesh.h" #include "BKE_cdderivedmesh.h" + #include "BLI_editVert.h" #include "BLI_listbase.h" #include "BLI_utildefines.h" -#include "ED_object.h" #include "BLI_math_vector.h" +#include "ED_object.h" +#include "ED_mesh.h" + #include "RNA_access.h" -#include "ED_mesh.h" +#include "WM_api.h" +#include "WM_types.h" + +#include "recast-capi.h" /*mesh/mesh_intern.h */ extern struct EditVert *addvertlist(EditMesh *em, float *vec, struct EditVert *example); @@ -65,10 +69,7 @@ extern void free_vertlist(EditMesh *em, ListBase *edve); extern void free_edgelist(EditMesh *em, ListBase *lb); extern void free_facelist(EditMesh *em, ListBase *lb); -#include "WM_api.h" -#include "WM_types.h" - -static void createVertsTrisData(bContext *C, LinkNode* obs, int& nverts, float*& verts, int &ntris, int*& tris) +static void createVertsTrisData(bContext *C, LinkNode* obs, int *nverts_r, float **verts_r, int *ntris_r, int **tris_r) { MVert *mvert; int nfaces = 0, *tri, i, curnverts, basenverts, curnfaces; @@ -80,13 +81,16 @@ static void createVertsTrisData(bContext *C, LinkNode* obs, int& nverts, float*& Scene* scene = CTX_data_scene(C); LinkNode* dms = NULL; + int nverts, ntris, *tris; + float *verts; + nverts = 0; ntris = 0; //calculate number of verts and tris for (oblink = obs; oblink; oblink = oblink->next) { ob = (Object*) oblink->link; - DerivedMesh *dm = mesh_create_derived_no_virtual(scene, ob, NULL, CD_MASK_MESH); + dm = mesh_create_derived_no_virtual(scene, ob, NULL, CD_MASK_MESH); BLI_linklist_append(&dms, (void*)dm); nverts += dm->getNumVerts(dm); @@ -104,8 +108,8 @@ static void createVertsTrisData(bContext *C, LinkNode* obs, int& nverts, float*& } //create data - verts = (float*) MEM_mallocN(sizeof(float)*3*nverts, "verts"); - tris = (int*) MEM_mallocN(sizeof(int)*3*ntris, "faces"); + verts = MEM_mallocN(sizeof(float)*3*nverts, "verts"); + tris = MEM_mallocN(sizeof(int)*3*ntris, "faces"); basenverts = 0; tri = tris; @@ -152,24 +156,30 @@ static void createVertsTrisData(bContext *C, LinkNode* obs, int& nverts, float*& dm->release(dm); } BLI_linklist_free(dms, NULL); + + *nverts_r= nverts; + *verts_r= verts; + *ntris_r= ntris; + *tris_r= tris; } -static bool buildNavMesh(const RecastData& recastParams, int nverts, float* verts, int ntris, int* tris, - rcPolyMesh*& pmesh, rcPolyMeshDetail*& dmesh) +static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts, int ntris, int *tris, + struct recast_polyMesh **pmesh, struct recast_polyMeshDetail **dmesh) { float bmin[3], bmax[3]; - rcHeightfield* solid; + struct recast_heightfield *solid; unsigned char *triflags; - rcCompactHeightfield* chf; - rcContourSet *cset; + struct recast_compactHeightfield* chf; + struct recast_contourSet *cset; + int width, height, walkableHeight, walkableClimb, walkableRadius; + int minRegionSize, mergeRegionSize, maxEdgeLen; + float detailSampleDist, detailSampleMaxError; - rcCalcBounds(verts, nverts, bmin, bmax); + recast_calcBounds(verts, nverts, bmin, bmax); // // Step 1. Initialize build config. // - rcConfig cfg; - memset(&cfg, 0, sizeof(cfg)); { /* float cellsize = 0.3f; @@ -199,6 +209,7 @@ static bool buildNavMesh(const RecastData& recastParams, int nverts, float* vert cfg.detailSampleDist = detailsampledist< 0.9f ? 0 : cellsize * detailsampledist; cfg.detailSampleMaxError = cellheight * detailsamplemaxerror; */ +#if 0 cfg.cs = recastParams.cellsize; cfg.ch = recastParams.cellheight; cfg.walkableSlopeAngle = recastParams.agentmaxslope/((float)M_PI)*180.f; @@ -213,102 +224,123 @@ static bool buildNavMesh(const RecastData& recastParams, int nverts, float* vert cfg.detailSampleDist = recastParams.detailsampledist< 0.9f ? 0 : recastParams.cellsize * recastParams.detailsampledist; cfg.detailSampleMaxError = recastParams.cellheight * recastParams.detailsamplemaxerror; - +#endif } + walkableHeight = (int)ceilf(recastParams->agentheight/ recastParams->cellheight); + walkableClimb = (int)floorf(recastParams->agentmaxclimb / recastParams->cellheight); + walkableRadius = (int)ceilf(recastParams->agentradius / recastParams->cellsize); + minRegionSize = (int)(recastParams->regionminsize * recastParams->regionminsize); + mergeRegionSize = (int)(recastParams->regionmergesize * recastParams->regionmergesize); + maxEdgeLen = (int)(recastParams->edgemaxlen/recastParams->cellsize); + detailSampleDist = recastParams->detailsampledist< 0.9f ? 0 : + recastParams->cellsize * recastParams->detailsampledist; + detailSampleMaxError = recastParams->cellheight * recastParams->detailsamplemaxerror; + // Set the area where the navigation will be build. - vcopy(cfg.bmin, bmin); - vcopy(cfg.bmax, bmax); - rcCalcGridSize(cfg.bmin, cfg.bmax, cfg.cs, &cfg.width, &cfg.height); + recast_calcGridSize(bmin, bmax, recastParams->cellsize, &width, &height); // // Step 2. Rasterize input polygon soup. // // Allocate voxel heightfield where we rasterize our input data to. - solid = new rcHeightfield; - if (!solid) - return false; + solid = recast_newHeightfield(); - if (!rcCreateHeightfield(*solid, cfg.width, cfg.height, cfg.bmin, cfg.bmax, cfg.cs, cfg.ch)) - return false; + if (!recast_createHeightfield(solid, width, height, bmin, bmax, recastParams->cellsize, recastParams->cellheight)) { + recast_destroyHeightfield(solid); + + return 0; + } // Allocate array that can hold triangle flags. - triflags = (unsigned char*) MEM_mallocN(sizeof(unsigned char)*ntris, "triflags"); - if (!triflags) - return false; + triflags = MEM_callocN(sizeof(unsigned char)*ntris, "triflags"); + // Find triangles which are walkable based on their slope and rasterize them. - memset(triflags, 0, ntris*sizeof(unsigned char)); - rcMarkWalkableTriangles(cfg.walkableSlopeAngle, verts, nverts, tris, ntris, triflags); - rcRasterizeTriangles(verts, nverts, tris, triflags, ntris, *solid); + recast_markWalkableTriangles(RAD2DEG(recastParams->agentmaxslope), verts, nverts, tris, ntris, triflags); + recast_rasterizeTriangles(verts, nverts, tris, triflags, ntris, solid); MEM_freeN(triflags); - MEM_freeN(verts); - MEM_freeN(tris); // // Step 3. Filter walkables surfaces. // - rcFilterLedgeSpans(cfg.walkableHeight, cfg.walkableClimb, *solid); - rcFilterWalkableLowHeightSpans(cfg.walkableHeight, *solid); + recast_filterLedgeSpans(walkableHeight, walkableClimb, solid); + recast_filterWalkableLowHeightSpans(walkableHeight, solid); // // Step 4. Partition walkable surface to simple regions. // - chf = new rcCompactHeightfield; - if (!chf) - return false; - if (!rcBuildCompactHeightfield(cfg.walkableHeight, cfg.walkableClimb, RC_WALKABLE, *solid, *chf)) - return false; + chf = recast_newCompactHeightfield(); + if (!recast_buildCompactHeightfield(walkableHeight, walkableClimb, RECAST_WALKABLE, solid, chf)) { + recast_destroyHeightfield(solid); + recast_destroyCompactHeightfield(chf); - delete solid; + return 0; + } + + recast_destroyHeightfield(solid); // Prepare for region partitioning, by calculating distance field along the walkable surface. - if (!rcBuildDistanceField(*chf)) - return false; + if (!recast_buildDistanceField(chf)) { + recast_destroyCompactHeightfield(chf); + + return 0; + } // Partition the walkable surface into simple regions without holes. - if (!rcBuildRegions(*chf, cfg.walkableRadius, cfg.borderSize, cfg.minRegionSize, cfg.mergeRegionSize)) - return false; + if (!recast_buildRegions(chf, walkableRadius, 0, minRegionSize, mergeRegionSize)) { + recast_destroyCompactHeightfield(chf); + + return 0; + } // // Step 5. Trace and simplify region contours. // // Create contours. - cset = new rcContourSet; - if (!cset) - return false; + cset = recast_newContourSet(); - if (!rcBuildContours(*chf, cfg.maxSimplificationError, cfg.maxEdgeLen, *cset)) - return false; + if (!recast_buildContours(chf, recastParams->edgemaxerror, maxEdgeLen, cset)) { + recast_destroyCompactHeightfield(chf); + recast_destroyContourSet(cset); + + return 0; + } // // Step 6. Build polygons mesh from contours. // - pmesh = new rcPolyMesh; - if (!pmesh) - return false; - if (!rcBuildPolyMesh(*cset, cfg.maxVertsPerPoly, *pmesh)) - return false; + *pmesh = recast_newPolyMesh(); + if (!recast_buildPolyMesh(cset, recastParams->vertsperpoly, *pmesh)) { + recast_destroyCompactHeightfield(chf); + recast_destroyContourSet(cset); + recast_destroyPolyMesh(*pmesh); + + return 0; + } // // Step 7. Create detail mesh which allows to access approximate height on each polygon. // - dmesh = new rcPolyMeshDetail; - if (!dmesh) - return false; + *dmesh = recast_newPolyMeshDetail(); + if (!recast_buildPolyMeshDetail(*pmesh, chf, detailSampleDist, detailSampleMaxError, *dmesh)) { + recast_destroyCompactHeightfield(chf); + recast_destroyContourSet(cset); + recast_destroyPolyMesh(*pmesh); + recast_destroyPolyMeshDetail(*dmesh); - if (!rcBuildPolyMeshDetail(*pmesh, *chf, cfg.detailSampleDist, cfg.detailSampleMaxError, *dmesh)) - return false; + return 0; + } - delete chf; - delete cset; + recast_destroyCompactHeightfield(chf); + recast_destroyContourSet(cset); - return true; + return 1; } -static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshDetail*& dmesh, Base* base) +static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, struct recast_polyMeshDetail *dmesh, Base* base) { float co[3], rot[3]; EditMesh *em; @@ -319,8 +351,15 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD Scene *scene= CTX_data_scene(C); Object* obedit; int createob = base==NULL; + int nverts, nmeshes, nvp; + unsigned short *verts, *meshes, *polys; + float bmin[3], cs, ch, *dverts; + unsigned char *tris; + ModifierData *md; + zero_v3(co); zero_v3(rot); + if (createob) { //create new object @@ -347,11 +386,15 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD } //create verts for polygon mesh - for(i = 0; i < pmesh->nverts; i++) { - v = &pmesh->verts[3*i]; - co[0] = pmesh->bmin[0] + v[0]*pmesh->cs; - co[1] = pmesh->bmin[1] + v[1]*pmesh->ch; - co[2] = pmesh->bmin[2] + v[2]*pmesh->cs; + verts = recast_polyMeshGetVerts(pmesh, &nverts); + recast_polyMeshGetBoundbox(pmesh, bmin, NULL); + recast_polyMeshGetCell(pmesh, &cs, &ch); + + for(i = 0; i < nverts; i++) { + v = &verts[3*i]; + co[0] = bmin[0] + v[0]*cs; + co[1] = bmin[1] + v[1]*ch; + co[2] = bmin[2] + v[2]*cs; SWAP(float, co[1], co[2]); addvertlist(em, co, NULL); } @@ -360,16 +403,21 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD CustomData_add_layer_named(&em->fdata, CD_RECAST, CD_CALLOC, NULL, 0, "recastData"); //create verts and faces for detailed mesh - for (i=0; inmeshes; i++) + meshes = recast_polyMeshDetailGetMeshes(dmesh, &nmeshes); + polys = recast_polyMeshGetPolys(pmesh, NULL, &nvp); + dverts = recast_polyMeshDetailGetVerts(dmesh, NULL); + tris = recast_polyMeshDetailGetTris(dmesh, NULL); + + for (i=0; itotvert; - unsigned short vbase = dmesh->meshes[4*i+0]; - unsigned short ndv = dmesh->meshes[4*i+1]; - unsigned short tribase = dmesh->meshes[4*i+2]; - unsigned short trinum = dmesh->meshes[4*i+3]; - const unsigned short* p = &pmesh->polys[i*pmesh->nvp*2]; + unsigned short vbase = meshes[4*i+0]; + unsigned short ndv = meshes[4*i+1]; + unsigned short tribase = meshes[4*i+2]; + unsigned short trinum = meshes[4*i+3]; + const unsigned short* p = &polys[i*nvp*2]; int nv = 0; - for (j = 0; j < pmesh->nvp; ++j) + for (j = 0; j < nvp; ++j) { if (p[j] == 0xffff) break; nv++; @@ -377,7 +425,7 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD //create unique verts for (j=nv; jverts[3*(vbase + j)]); + copy_v3_v3(co, &dverts[3*(vbase + j)]); SWAP(float, co[1], co[2]); addvertlist(em, co, NULL); } @@ -387,8 +435,10 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD //create faces for (j=0; jtris[4*(tribase+j)]; + unsigned char* tri = &tris[4*(tribase+j)]; EditFace* newFace; + int* polygonIdx; + for (k=0; k<3; k++) { if (tri[k]fdata, newFace->data, CD_RECAST); + polygonIdx = (int*)CustomData_em_get(&em->fdata, newFace->data, CD_RECAST); *polygonIdx = i+1; //add 1 to avoid zero idx } EM_free_index_arrays(); } - delete pmesh; pmesh = NULL; - delete dmesh; dmesh = NULL; + recast_destroyPolyMesh(pmesh); + recast_destroyPolyMeshDetail(dmesh); BKE_mesh_end_editmesh((Mesh*)obedit->data, em); @@ -427,7 +477,7 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD rename_id((ID *)obedit, "Navmesh"); } - ModifierData *md= modifiers_findByType(obedit, eModifierType_NavMesh); + md= modifiers_findByType(obedit, eModifierType_NavMesh); if (!md) { ED_object_modifier_add(NULL, bmain, scene, obedit, NULL, eModifierType_NavMesh); @@ -436,16 +486,17 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD return obedit; } -static int create_navmesh_exec(bContext *C, wmOperator *op) +static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op)) { Scene* scene = CTX_data_scene(C); int nverts, ntris; float* verts; int* tris; - rcPolyMesh* pmesh; - rcPolyMeshDetail* dmesh; + struct recast_polyMesh *pmesh; + struct recast_polyMeshDetail *dmesh; LinkNode* obs = NULL; Base* navmeshBase = NULL; + //CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) //expand macros to avoid error in convertion from void* { ListBase ctx_data_list; @@ -464,9 +515,9 @@ static int create_navmesh_exec(bContext *C, wmOperator *op) BLI_linklist_append(&obs, (void*)base->object); } CTX_DATA_END; - createVertsTrisData(C, obs, nverts, verts, ntris, tris); + createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris); BLI_linklist_free(obs, NULL); - buildNavMesh(scene->gm.recastData, nverts, verts, ntris, tris, pmesh, dmesh); + buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh); createRepresentation(C, pmesh, dmesh, navmeshBase); return OPERATOR_FINISHED; @@ -494,7 +545,7 @@ static int assign_navpolygon_poll(bContext *C) return (((Mesh*)ob->data)->edit_mesh != NULL); } -static int assign_navpolygon_exec(bContext *C, wmOperator *op) +static int assign_navpolygon_exec(bContext *C, wmOperator *UNUSED(op)) { Object *obedit= CTX_data_edit_object(C); EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); @@ -551,13 +602,15 @@ void OBJECT_OT_assign_navpolygon(struct wmOperatorType *ot) static int compare(const void * a, const void * b){ return ( *(int*)a - *(int*)b ); } + static int findFreeNavPolyIndex(EditMesh* em) { //construct vector of indices int numfaces = em->totface; - int* indices = new int[numfaces]; + int* indices = MEM_callocN(sizeof(int)*numfaces, "findFreeNavPolyIndex(indices)"); EditFace* ef = (EditFace*)em->faces.last; - int idx = 0; + int i, idx = 0, freeIdx = 1; + while(ef) { int polyIdx = *(int*)CustomData_em_get(&em->fdata, ef->data, CD_RECAST); @@ -565,21 +618,25 @@ static int findFreeNavPolyIndex(EditMesh* em) idx++; ef = ef->prev; } + qsort(indices, numfaces, sizeof(int), compare); + //search first free index - int freeIdx = 1; - for (int i=0; ifreeIdx) break; } - delete [] indices; + + MEM_freeN(indices); + return freeIdx; } -static int assign_new_navpolygon_exec(bContext *C, wmOperator *op) +static int assign_new_navpolygon_exec(bContext *C, wmOperator *UNUSED(op)) { Object *obedit= CTX_data_edit_object(C); EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); @@ -625,4 +682,3 @@ void OBJECT_OT_assign_new_navpolygon(struct wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -} diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 0854f9f3685..d3d7b1b1505 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -3226,7 +3226,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *eve else WM_event_add_notifier(C, NC_SCENE|NA_EDITED, scene); - return OPERATOR_FINISHED; + return OPERATOR_PASS_THROUGH; } void VIEW3D_OT_cursor3d(wmOperatorType *ot) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index dad43b4fe69..cfeaee18416 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1270,10 +1270,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand if(ot) retval= wm_operator_invoke(C, ot, event, properties, NULL, FALSE); } - /* Finished and pass through flag as handled */ - if(retval == (OPERATOR_FINISHED|OPERATOR_PASS_THROUGH)) - return WM_HANDLER_HANDLED; /* Modal unhandled, break */ if(retval == (OPERATOR_PASS_THROUGH|OPERATOR_RUNNING_MODAL)) From dcccf3fc1f915d0c8a3f2f8763170b6ff9394b8a Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 27 Sep 2011 09:09:52 +0000 Subject: [PATCH 11/13] navmesh: solve bad level calls to edit mesh functions Move navmesh operators from editors/object to editors/mesh --- .../startup/bl_ui/properties_data_modifier.py | 4 +- .../scripts/startup/bl_ui/properties_game.py | 2 +- source/blender/editors/mesh/CMakeLists.txt | 12 ++++++ source/blender/editors/mesh/SConscript | 6 +++ source/blender/editors/mesh/mesh_intern.h | 12 ++++-- .../object_navmesh.c => mesh/mesh_navmesh.c} | 42 +++++++------------ source/blender/editors/mesh/mesh_ops.c | 6 +++ source/blender/editors/object/CMakeLists.txt | 10 ----- source/blender/editors/object/object_intern.h | 5 --- source/blender/editors/object/object_ops.c | 6 --- 10 files changed, 52 insertions(+), 53 deletions(-) rename source/blender/editors/{object/object_navmesh.c => mesh/mesh_navmesh.c} (93%) diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index 98466b41c2e..d2d4c263d50 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -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) diff --git a/release/scripts/startup/bl_ui/properties_game.py b/release/scripts/startup/bl_ui/properties_game.py index 8cb73d2449b..7650e7b6ee1 100644 --- a/release/scripts/startup/bl_ui/properties_game.py +++ b/release/scripts/startup/bl_ui/properties_game.py @@ -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:") diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 02a25a2a122..f45f706b892 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -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}") diff --git a/source/blender/editors/mesh/SConscript b/source/blender/editors/mesh/SConscript index b992ae5f04c..24c63a5dc54 100644 --- a/source/blender/editors/mesh/SConscript +++ b/source/blender/editors/mesh/SConscript @@ -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] ) diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 4d620424b0a..6dce92bf07b 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -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 diff --git a/source/blender/editors/object/object_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c similarity index 93% rename from source/blender/editors/object/object_navmesh.c rename to source/blender/editors/mesh/mesh_navmesh.c index 413d8757be2..2b64fb24e78 100644 --- a/source/blender/editors/object/object_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -54,21 +54,16 @@ #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 */ diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 282eeef906f..f44f7fbb8d5 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -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? */ diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt index b0b4f9dc0eb..c78c9fddbe8 100644 --- a/source/blender/editors/object/CMakeLists.txt +++ b/source/blender/editors/object/CMakeLists.txt @@ -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() diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 434111c1227..7bb98f4aeb1 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -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 */ diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index a9cb0423739..5a2437b1911 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -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 } From b66f219687cc55b731017cc6602c079166bf1462 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 27 Sep 2011 09:09:55 +0000 Subject: [PATCH 12/13] navmesh: code clean-up, should be no functional changes. --- source/blender/editors/mesh/mesh_navmesh.c | 487 +++++++++------------ 1 file changed, 205 insertions(+), 282 deletions(-) diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c index 2b64fb24e78..b0d15a0dc68 100644 --- a/source/blender/editors/mesh/mesh_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -17,12 +17,13 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -* The Original Code is Copyright (C) 2004 by Blender Foundation +* The Original Code is Copyright (C) 2011 by Blender Foundation * All rights reserved. * * The Original Code is: all of this file. * -* Contributor(s): none yet. +* Contributor(s): Benoit Bolsee, +* Nick Samarin * * ***** END GPL LICENSE BLOCK ***** */ @@ -67,89 +68,95 @@ static void createVertsTrisData(bContext *C, LinkNode* obs, int *nverts_r, float **verts_r, int *ntris_r, int **tris_r) { MVert *mvert; - int nfaces = 0, *tri, i, curnverts, basenverts, curnfaces; + int nfaces= 0, *tri, i, curnverts, basenverts, curnfaces; MFace *mface; float co[3], wco[3]; Object *ob; LinkNode *oblink, *dmlink; DerivedMesh *dm; - Scene* scene = CTX_data_scene(C); - LinkNode* dms = NULL; + Scene* scene= CTX_data_scene(C); + LinkNode* dms= NULL; int nverts, ntris, *tris; float *verts; - nverts = 0; - ntris = 0; - //calculate number of verts and tris - for (oblink = obs; oblink; oblink = oblink->next) - { - ob = (Object*) oblink->link; - dm = mesh_create_derived_no_virtual(scene, ob, NULL, CD_MASK_MESH); + nverts= 0; + ntris= 0; + + /* calculate number of verts and tris */ + for(oblink= obs; oblink; oblink= oblink->next) { + ob= (Object*) oblink->link; + dm= mesh_create_derived_no_virtual(scene, ob, NULL, CD_MASK_MESH); BLI_linklist_append(&dms, (void*)dm); - nverts += dm->getNumVerts(dm); - nfaces = dm->getNumFaces(dm); - ntris += nfaces; + nverts+= dm->getNumVerts(dm); + nfaces= dm->getNumFaces(dm); + ntris+= nfaces; - //resolve quad faces - mface = dm->getFaceArray(dm); - for (i=0; iv4) + /* resolve quad faces */ + mface= dm->getFaceArray(dm); + for(i= 0; iv4) ntris+=1; } } - //create data - verts = MEM_mallocN(sizeof(float)*3*nverts, "createVertsTrisData verts"); - tris = MEM_mallocN(sizeof(int)*3*ntris, "createVertsTrisData faces"); + /* create data */ + verts= MEM_mallocN(sizeof(float)*3*nverts, "createVertsTrisData verts"); + tris= MEM_mallocN(sizeof(int)*3*ntris, "createVertsTrisData faces"); - basenverts = 0; - tri = tris; - for (oblink = obs, dmlink = dms; oblink && dmlink; - oblink = oblink->next, dmlink = dmlink->next) - { - ob = (Object*) oblink->link; - dm = (DerivedMesh*) dmlink->link; + basenverts= 0; + tri= tris; + for(oblink= obs, dmlink= dms; oblink && dmlink; + oblink= oblink->next, dmlink= dmlink->next) { + ob= (Object*) oblink->link; + dm= (DerivedMesh*) dmlink->link; + + curnverts= dm->getNumVerts(dm); + mvert= dm->getVertArray(dm); + + /* copy verts */ + for(i= 0; igetNumVerts(dm); - mvert = dm->getVertArray(dm); - //copy verts - for (i=0; ico); mul_v3_m4v3(wco, ob->obmat, co); - verts[3*(basenverts+i)+0] = wco[0]; - verts[3*(basenverts+i)+1] = wco[2]; - verts[3*(basenverts+i)+2] = wco[1]; + + verts[3*(basenverts+i)+0]= wco[0]; + verts[3*(basenverts+i)+1]= wco[2]; + verts[3*(basenverts+i)+2]= wco[1]; } - //create tris - curnfaces = dm->getNumFaces(dm); - mface = dm->getFaceArray(dm); - for (i=0; iv1; tri[1]= basenverts + mf->v3; tri[2]= basenverts + mf->v2; + /* create tris */ + curnfaces= dm->getNumFaces(dm); + mface= dm->getFaceArray(dm); + + for(i= 0; iv1; + tri[1]= basenverts + mf->v3; + tri[2]= basenverts + mf->v2; tri += 3; - if (mf->v4) - { - tri[0]= basenverts + mf->v1; tri[1]= basenverts + mf->v4; tri[2]= basenverts + mf->v3; + + if(mf->v4) { + tri[0]= basenverts + mf->v1; + tri[1]= basenverts + mf->v4; + tri[2]= basenverts + mf->v3; tri += 3; } } - basenverts += curnverts; + + basenverts+= curnverts; } - //release derived mesh - for (dmlink = dms; dmlink; dmlink = dmlink->next) - { - dm = (DerivedMesh*) dmlink->link; + /* release derived mesh */ + for(dmlink= dms; dmlink; dmlink= dmlink->next) { + dm= (DerivedMesh*) dmlink->link; dm->release(dm); } + BLI_linklist_free(dms, NULL); *nverts_r= nverts; @@ -172,101 +179,46 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts recast_calcBounds(verts, nverts, bmin, bmax); - // - // Step 1. Initialize build config. - // - { -/* - float cellsize = 0.3f; - float cellheight = 0.2f; - float agentmaxslope = M_PI/4; - float agentmaxclimb = 0.9f; - float agentheight = 2.0f; - float agentradius = 0.6f; - float edgemaxlen = 12.0f; - float edgemaxerror = 1.3f; - float regionminsize = 50.f; - float regionmergesize = 20.f; - int vertsperpoly = 6; - float detailsampledist = 6.0f; - float detailsamplemaxerror = 1.0f; - cfg.cs = cellsize; - cfg.ch = cellheight; - cfg.walkableSlopeAngle = agentmaxslope/M_PI*180.f; - cfg.walkableHeight = (int)ceilf(agentheight/ cfg.ch); - cfg.walkableClimb = (int)floorf(agentmaxclimb / cfg.ch); - cfg.walkableRadius = (int)ceilf(agentradius / cfg.cs); - cfg.maxEdgeLen = (int)(edgemaxlen/cellsize); - cfg.maxSimplificationError = edgemaxerror; - cfg.minRegionSize = (int)rcSqr(regionminsize); - cfg.mergeRegionSize = (int)rcSqr(regionmergesize); - cfg.maxVertsPerPoly = vertsperpoly; - cfg.detailSampleDist = detailsampledist< 0.9f ? 0 : cellsize * detailsampledist; - cfg.detailSampleMaxError = cellheight * detailsamplemaxerror; -*/ -#if 0 - cfg.cs = recastParams.cellsize; - cfg.ch = recastParams.cellheight; - cfg.walkableSlopeAngle = recastParams.agentmaxslope/((float)M_PI)*180.f; - cfg.walkableHeight = (int)ceilf(recastParams.agentheight/ cfg.ch); - cfg.walkableClimb = (int)floorf(recastParams.agentmaxclimb / cfg.ch); - cfg.walkableRadius = (int)ceilf(recastParams.agentradius / cfg.cs); - cfg.maxEdgeLen = (int)(recastParams.edgemaxlen/recastParams.cellsize); - cfg.maxSimplificationError = recastParams.edgemaxerror; - cfg.minRegionSize = (int)rcSqr(recastParams.regionminsize); - cfg.mergeRegionSize = (int)rcSqr(recastParams.regionmergesize); - cfg.maxVertsPerPoly = recastParams.vertsperpoly; - cfg.detailSampleDist = recastParams.detailsampledist< 0.9f ? 0 : - recastParams.cellsize * recastParams.detailsampledist; - cfg.detailSampleMaxError = recastParams.cellheight * recastParams.detailsamplemaxerror; -#endif - } - - walkableHeight = (int)ceilf(recastParams->agentheight/ recastParams->cellheight); - walkableClimb = (int)floorf(recastParams->agentmaxclimb / recastParams->cellheight); - walkableRadius = (int)ceilf(recastParams->agentradius / recastParams->cellsize); - minRegionSize = (int)(recastParams->regionminsize * recastParams->regionminsize); - mergeRegionSize = (int)(recastParams->regionmergesize * recastParams->regionmergesize); - maxEdgeLen = (int)(recastParams->edgemaxlen/recastParams->cellsize); - detailSampleDist = recastParams->detailsampledist< 0.9f ? 0 : + /* ** Step 1. Initialize build config ** */ + walkableHeight= (int)ceilf(recastParams->agentheight/ recastParams->cellheight); + walkableClimb= (int)floorf(recastParams->agentmaxclimb / recastParams->cellheight); + walkableRadius= (int)ceilf(recastParams->agentradius / recastParams->cellsize); + minRegionSize= (int)(recastParams->regionminsize * recastParams->regionminsize); + mergeRegionSize= (int)(recastParams->regionmergesize * recastParams->regionmergesize); + maxEdgeLen= (int)(recastParams->edgemaxlen/recastParams->cellsize); + detailSampleDist= recastParams->detailsampledist< 0.9f ? 0 : recastParams->cellsize * recastParams->detailsampledist; - detailSampleMaxError = recastParams->cellheight * recastParams->detailsamplemaxerror; + detailSampleMaxError= recastParams->cellheight * recastParams->detailsamplemaxerror; - // Set the area where the navigation will be build. + /* Set the area where the navigation will be build. */ recast_calcGridSize(bmin, bmax, recastParams->cellsize, &width, &height); - // - // Step 2. Rasterize input polygon soup. - // - // Allocate voxel heightfield where we rasterize our input data to. - solid = recast_newHeightfield(); + /* ** Step 2: Rasterize input polygon soup ** */ + /* Allocate voxel heightfield where we rasterize our input data to */ + solid= recast_newHeightfield(); - if (!recast_createHeightfield(solid, width, height, bmin, bmax, recastParams->cellsize, recastParams->cellheight)) { + if(!recast_createHeightfield(solid, width, height, bmin, bmax, recastParams->cellsize, recastParams->cellheight)) { recast_destroyHeightfield(solid); return 0; } - // Allocate array that can hold triangle flags. - triflags = MEM_callocN(sizeof(unsigned char)*ntris, "buildNavMesh triflags"); + /* Allocate array that can hold triangle flags */ + triflags= MEM_callocN(sizeof(unsigned char)*ntris, "buildNavMesh triflags"); - // Find triangles which are walkable based on their slope and rasterize them. + /* Find triangles which are walkable based on their slope and rasterize them */ recast_markWalkableTriangles(RAD2DEG(recastParams->agentmaxslope), verts, nverts, tris, ntris, triflags); recast_rasterizeTriangles(verts, nverts, tris, triflags, ntris, solid); MEM_freeN(triflags); - // - // Step 3. Filter walkables surfaces. - // + /* ** Step 3: Filter walkables surfaces ** */ recast_filterLedgeSpans(walkableHeight, walkableClimb, solid); recast_filterWalkableLowHeightSpans(walkableHeight, solid); - // - // Step 4. Partition walkable surface to simple regions. - // + /* ** Step 4: Partition walkable surface to simple regions ** */ - chf = recast_newCompactHeightfield(); - if (!recast_buildCompactHeightfield(walkableHeight, walkableClimb, RECAST_WALKABLE, solid, chf)) { + chf= recast_newCompactHeightfield(); + if(!recast_buildCompactHeightfield(walkableHeight, walkableClimb, RECAST_WALKABLE, solid, chf)) { recast_destroyHeightfield(solid); recast_destroyCompactHeightfield(chf); @@ -275,38 +227,34 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts recast_destroyHeightfield(solid); - // Prepare for region partitioning, by calculating distance field along the walkable surface. - if (!recast_buildDistanceField(chf)) { + /* Prepare for region partitioning, by calculating distance field along the walkable surface */ + if(!recast_buildDistanceField(chf)) { recast_destroyCompactHeightfield(chf); return 0; } - // Partition the walkable surface into simple regions without holes. - if (!recast_buildRegions(chf, walkableRadius, 0, minRegionSize, mergeRegionSize)) { + /* Partition the walkable surface into simple regions without holes */ + if(!recast_buildRegions(chf, walkableRadius, 0, minRegionSize, mergeRegionSize)) { recast_destroyCompactHeightfield(chf); return 0; } - // - // Step 5. Trace and simplify region contours. - // - // Create contours. - cset = recast_newContourSet(); + /* ** Step 5: Trace and simplify region contours ** */ + /* Create contours */ + cset= recast_newContourSet(); - if (!recast_buildContours(chf, recastParams->edgemaxerror, maxEdgeLen, cset)) { + if(!recast_buildContours(chf, recastParams->edgemaxerror, maxEdgeLen, cset)) { recast_destroyCompactHeightfield(chf); recast_destroyContourSet(cset); return 0; } - // - // Step 6. Build polygons mesh from contours. - // - *pmesh = recast_newPolyMesh(); - if (!recast_buildPolyMesh(cset, recastParams->vertsperpoly, *pmesh)) { + /* ** Step 6: Build polygons mesh from contours ** */ + *pmesh= recast_newPolyMesh(); + if(!recast_buildPolyMesh(cset, recastParams->vertsperpoly, *pmesh)) { recast_destroyCompactHeightfield(chf); recast_destroyContourSet(cset); recast_destroyPolyMesh(*pmesh); @@ -315,12 +263,10 @@ static int buildNavMesh(const RecastData *recastParams, int nverts, float *verts } - // - // Step 7. Create detail mesh which allows to access approximate height on each polygon. - // + /* ** Step 7: Create detail mesh which allows to access approximate height on each polygon ** */ - *dmesh = recast_newPolyMeshDetail(); - if (!recast_buildPolyMeshDetail(*pmesh, chf, detailSampleDist, detailSampleMaxError, *dmesh)) { + *dmesh= recast_newPolyMeshDetail(); + if(!recast_buildPolyMeshDetail(*pmesh, chf, detailSampleDist, detailSampleMaxError, *dmesh)) { recast_destroyCompactHeightfield(chf); recast_destroyContourSet(cset); recast_destroyPolyMesh(*pmesh); @@ -342,10 +288,10 @@ 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); + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object* obedit; - int createob = base==NULL; + int createob= base==NULL; int nverts, nmeshes, nvp; unsigned short *verts, *meshes, *polys; float bmin[3], cs, ch, *dverts; @@ -355,98 +301,92 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, zero_v3(co); zero_v3(rot); - if (createob) - { - //create new object - obedit = ED_object_add_type(C, OB_MESH, co, rot, FALSE, 1); + if(createob) { + /* create new object */ + obedit= ED_object_add_type(C, OB_MESH, co, rot, FALSE, 1); } - else - { - obedit = base->object; + else { + obedit= base->object; scene_select_base(scene, base); copy_v3_v3(obedit->loc, co); copy_v3_v3(obedit->rot, rot); } ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); - em = BKE_mesh_get_editmesh(((Mesh *)obedit->data)); + em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)); - if (!createob) - { - //clear + if(!createob) { + /* clear */ if(em->verts.first) free_vertlist(em, &em->verts); if(em->edges.first) free_edgelist(em, &em->edges); if(em->faces.first) free_facelist(em, &em->faces); if(em->selected.first) BLI_freelistN(&(em->selected)); } - //create verts for polygon mesh - verts = recast_polyMeshGetVerts(pmesh, &nverts); + /* create verts for polygon mesh */ + verts= recast_polyMeshGetVerts(pmesh, &nverts); recast_polyMeshGetBoundbox(pmesh, bmin, NULL); recast_polyMeshGetCell(pmesh, &cs, &ch); - for(i = 0; i < nverts; i++) { - v = &verts[3*i]; - co[0] = bmin[0] + v[0]*cs; - co[1] = bmin[1] + v[1]*ch; - co[2] = bmin[2] + v[2]*cs; + for(i= 0; ifdata, CD_RECAST, CD_CALLOC, NULL, 0, "recastData"); + /* create custom data layer to save polygon idx */ + CustomData_add_layer_named(&em->fdata, CD_RECAST, CD_CALLOC, NULL, 0, "createRepresentation recastData"); - //create verts and faces for detailed mesh - meshes = recast_polyMeshDetailGetMeshes(dmesh, &nmeshes); - polys = recast_polyMeshGetPolys(pmesh, NULL, &nvp); - dverts = recast_polyMeshDetailGetVerts(dmesh, NULL); - tris = recast_polyMeshDetailGetTris(dmesh, NULL); + /* create verts and faces for detailed mesh */ + meshes= recast_polyMeshDetailGetMeshes(dmesh, &nmeshes); + polys= recast_polyMeshGetPolys(pmesh, NULL, &nvp); + dverts= recast_polyMeshDetailGetVerts(dmesh, NULL); + tris= recast_polyMeshDetailGetTris(dmesh, NULL); - for (i=0; itotvert; - unsigned short vbase = meshes[4*i+0]; - unsigned short ndv = meshes[4*i+1]; - unsigned short tribase = meshes[4*i+2]; - unsigned short trinum = meshes[4*i+3]; - const unsigned short* p = &polys[i*nvp*2]; - int nv = 0; - for (j = 0; j < nvp; ++j) - { - if (p[j] == 0xffff) break; + for(i= 0; itotvert; + unsigned short vbase= meshes[4*i+0]; + unsigned short ndv= meshes[4*i+1]; + unsigned short tribase= meshes[4*i+2]; + unsigned short trinum= meshes[4*i+3]; + const unsigned short* p= &polys[i*nvp*2]; + int nv= 0; + + for(j= 0; j < nvp; ++j) { + if(p[j]==0xffff) break; nv++; } - //create unique verts - for (j=nv; jfdata, newFace->data, CD_RECAST); - *polygonIdx = i+1; //add 1 to avoid zero idx + /* set navigation polygon idx to the custom layer */ + polygonIdx= (int*)CustomData_em_get(&em->fdata, newFace->data, CD_RECAST); + *polygonIdx= i+1; /* add 1 to avoid zero idx */ } EM_free_index_arrays(); @@ -464,17 +404,15 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, ED_object_exit_editmode(C, EM_FREEDATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); - if (createob) - { - obedit->gameflag &= ~OB_COLLISION; - obedit->gameflag |= OB_NAVMESH; - obedit->body_type = OB_BODY_TYPE_NAVMESH; + if(createob) { + obedit->gameflag&= ~OB_COLLISION; + obedit->gameflag|= OB_NAVMESH; + obedit->body_type= OB_BODY_TYPE_NAVMESH; rename_id((ID *)obedit, "Navmesh"); } md= modifiers_findByType(obedit, eModifierType_NavMesh); - if (!md) - { + if(!md) { ED_object_modifier_add(NULL, bmain, scene, obedit, NULL, eModifierType_NavMesh); } @@ -483,33 +421,25 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene* scene = CTX_data_scene(C); + Scene* scene= CTX_data_scene(C); int nverts, ntris; float* verts; int* tris; struct recast_polyMesh *pmesh; struct recast_polyMeshDetail *dmesh; - LinkNode* obs = NULL; - Base* navmeshBase = NULL; + LinkNode* obs= NULL; + Base* navmeshBase= NULL; - //CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) //expand macros to avoid error in convertion from void* - { - ListBase ctx_data_list; - CollectionPointerLink *ctx_link; - CTX_data_selected_editable_bases(C, &ctx_data_list); - for(ctx_link = (CollectionPointerLink *)ctx_data_list.first; - ctx_link; ctx_link = (CollectionPointerLink *)ctx_link->next) { - Base* base= (Base*)ctx_link->ptr.data; - { - if (base->object->body_type==OB_BODY_TYPE_NAVMESH) - { - if (!navmeshBase || base==CTX_data_active_base(C)) - navmeshBase = base; + 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; } 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); @@ -540,28 +470,25 @@ static int assign_navpolygon_exec(bContext *C, wmOperator *UNUSED(op)) Object *obedit= CTX_data_edit_object(C); EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); - //do work here - int targetPolyIdx = -1; + /* do work here */ + int targetPolyIdx= -1; EditFace *ef, *efa; - efa = EM_get_actFace(em, 0); - if (efa) - { - if (CustomData_has_layer(&em->fdata, CD_RECAST)) - { - targetPolyIdx = *(int*)CustomData_em_get(&em->fdata, efa->data, CD_RECAST); - targetPolyIdx = targetPolyIdx>=0? targetPolyIdx : -targetPolyIdx; - 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); - *recastDataBlock = targetPolyIdx; + efa= EM_get_actFace(em, 0); + + if(efa) { + if(CustomData_has_layer(&em->fdata, CD_RECAST)) { + targetPolyIdx= *(int*)CustomData_em_get(&em->fdata, efa->data, CD_RECAST); + targetPolyIdx= targetPolyIdx>=0? targetPolyIdx : -targetPolyIdx; + + 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); + *recastDataBlock= targetPolyIdx; } - ef = ef->prev; + ef= ef->prev; } } } @@ -571,6 +498,7 @@ static int assign_navpolygon_exec(bContext *C, wmOperator *UNUSED(op)) WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); BKE_mesh_end_editmesh((Mesh*)obedit->data, em); + return OPERATOR_FINISHED; } @@ -595,29 +523,27 @@ static int compare(const void * a, const void * b){ static int findFreeNavPolyIndex(EditMesh* em) { - //construct vector of indices - int numfaces = em->totface; - int* indices = MEM_callocN(sizeof(int)*numfaces, "findFreeNavPolyIndex(indices)"); - EditFace* ef = (EditFace*)em->faces.last; - int i, idx = 0, freeIdx = 1; + /* construct vector of indices */ + int numfaces= em->totface; + int* indices= MEM_callocN(sizeof(int)*numfaces, "findFreeNavPolyIndex(indices)"); + EditFace* ef= (EditFace*)em->faces.last; + int i, idx= 0, freeIdx= 1; - while(ef) - { - int polyIdx = *(int*)CustomData_em_get(&em->fdata, ef->data, CD_RECAST); - indices[idx] = polyIdx; + while(ef) { + int polyIdx= *(int*)CustomData_em_get(&em->fdata, ef->data, CD_RECAST); + indices[idx]= polyIdx; idx++; - ef = ef->prev; + ef= ef->prev; } qsort(indices, numfaces, sizeof(int), compare); - //search first free index - freeIdx = 1; - for (i=0; ifreeIdx) + else if(indices[i]>freeIdx) break; } @@ -630,26 +556,23 @@ static int assign_new_navpolygon_exec(bContext *C, wmOperator *UNUSED(op)) { Object *obedit= CTX_data_edit_object(C); EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data); - EditFace *ef; - if (CustomData_has_layer(&em->fdata, CD_RECAST)) - { - int targetPolyIdx = findFreeNavPolyIndex(em); - if (targetPolyIdx>0) - { - //set target poly idx to selected faces - ef = (EditFace*)em->faces.last; - while(ef) - { - if(ef->f & SELECT ) - { - int* recastDataBlock = (int*)CustomData_em_get(&em->fdata, ef->data, CD_RECAST); - *recastDataBlock = targetPolyIdx; + + if(CustomData_has_layer(&em->fdata, CD_RECAST)) { + int targetPolyIdx= findFreeNavPolyIndex(em); + + if(targetPolyIdx>0) { + /* set target poly idx to selected faces */ + ef= (EditFace*)em->faces.last; + while(ef) { + if(ef->f & SELECT) { + int *recastDataBlock= (int*)CustomData_em_get(&em->fdata, ef->data, CD_RECAST); + *recastDataBlock= targetPolyIdx; } - ef = ef->prev; + ef= ef->prev; } } - } + } DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); From a1857b407c422163482ac1db727fa21ac8a12a82 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 27 Sep 2011 09:21:17 +0000 Subject: [PATCH 13/13] Fixing typo in comment - no functional changes --- source/blender/editors/sculpt_paint/sculpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 62d6d5f16b8..5a888e6f595 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -154,7 +154,7 @@ static int sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob) if(mmd) return 0; - /* non-locked shaoe keys could be handled in the same way as deformed mesh */ + /* non-locked shape keys could be handled in the same way as deformed mesh */ if((ob->shapeflag&OB_SHAPE_LOCK)==0 && me->key && ob->shapenr) return 1;