Merging r40572 through r40597 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 27 Sep 2011 09:26:46 +0000 (09:26 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 27 Sep 2011 09:26:46 +0000 (09:26 +0000)
80 files changed:
CMakeLists.txt
build_files/cmake/cmake_static_check_cppcheck.py
build_files/cmake/project_source_info.py
extern/recastnavigation/recast-capi.cpp
extern/recastnavigation/recast-capi.h
intern/audaspace/Python/AUD_PyAPI.cpp
release/scripts/modules/bpy_extras/anim_utils.py
release/scripts/modules/bpy_extras/keyconfig_utils.py
release/scripts/startup/bl_operators/console.py
release/scripts/startup/bl_operators/view3d.py
release/scripts/startup/bl_operators/wm.py
release/scripts/startup/bl_ui/properties_data_modifier.py
release/scripts/startup/bl_ui/properties_game.py
release/scripts/startup/bl_ui/properties_particle.py
release/scripts/startup/bl_ui/space_text.py
source/blender/blenfont/intern/blf_lang.c
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/ipo.c
source/blender/blenkernel/intern/key.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/seqeffects.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/writeframeserver.c
source/blender/blenlib/intern/storage.c
source/blender/blenlib/intern/winstuff.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/armature/poselib.c
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_anim.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_style.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_utils.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/mesh/CMakeLists.txt
source/blender/editors/mesh/SConscript
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_navmesh.c [new file with mode: 0644]
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/object/CMakeLists.txt
source/blender/editors/object/SConscript
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_navmesh.cpp [deleted file]
source/blender/editors/object/object_ops.c
source/blender/editors/physics/particle_edit.c
source/blender/editors/sculpt_paint/paint_undo.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_sequencer/sequencer_select.c
source/blender/editors/space_text/text_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/transform/transform.c
source/blender/editors/util/editmode_undo.c
source/blender/modifiers/intern/MOD_armature.c
source/blender/modifiers/intern/MOD_bevel.c
source/blender/modifiers/intern/MOD_cast.c
source/blender/modifiers/intern/MOD_curve.c
source/blender/modifiers/intern/MOD_displace.c
source/blender/modifiers/intern/MOD_hook.c
source/blender/modifiers/intern/MOD_lattice.c
source/blender/modifiers/intern/MOD_smooth.c
source/blender/modifiers/intern/MOD_warp.c
source/blender/modifiers/intern/MOD_wave.c
source/blender/nodes/intern/node_common.c
source/blender/python/generic/IDProp.c
source/blender/python/generic/bgl.c
source/blender/python/generic/bpy_internal_import.c
source/blender/python/generic/py_capi_utils.c
source/blender/python/intern/bpy_rna.c
source/blender/python/intern/bpy_rna_array.c
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pipeline.c
source/blender/windowmanager/intern/wm_event_system.c
source/creator/creator.c

index e8d0616..a45a356 100644 (file)
@@ -1156,14 +1156,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)
index fdd380c..1c8d619 100644 (file)
@@ -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) + " %:"
index 83e4e05..c636d77 100644 (file)
@@ -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:
index 52c4cdc..2348497 100644 (file)
@@ -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;
+}
index 0d20fdf..58fe08e 100644 (file)
 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
index 928c67c..3ec0880 100644 (file)
@@ -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<float> 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);
                }
index 9482dc3..9848586 100644 (file)
@@ -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()
index abde3dd..49b6047 100644 (file)
@@ -220,7 +220,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):
index de95363..109ca75 100644 (file)
@@ -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'}
-        
index 805f2b5..05b5321 100644 (file)
@@ -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):
index 72efdee..85e7991 100644 (file)
@@ -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"
index 98466b4..d2d4c26 100644 (file)
@@ -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)
index 469c1e6..7650e7b 100644 (file)
@@ -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
@@ -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:")
index edd5745..eceefc7 100644 (file)
@@ -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):
index d0a3a53..c3b2e30 100644 (file)
@@ -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
index b5c6b5b..0a10288 100644 (file)
@@ -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, ':');
index 73ddcbe..8d18a1c 100644 (file)
@@ -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);
index d1f9b10..31a76b5 100644 (file)
@@ -520,7 +520,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 */
index 71ca797..b885e60 100644 (file)
@@ -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));
index 4b8209a..656bb3e 100644 (file)
@@ -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));
index bf8a8ab..52223ec 100644 (file)
@@ -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;
index e5d7417..70b4479 100644 (file)
@@ -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) {
index 3a33d6d..94fbd49 100644 (file)
@@ -3657,7 +3657,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);
 
index d13d15d..15cb3b6 100644 (file)
@@ -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) {
index f088c5e..8be86a4 100644 (file)
@@ -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
index 66080ed..bf816a9 100644 (file)
@@ -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 */
 
index daf384d..5c70f6a 100644 (file)
@@ -517,7 +517,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;
@@ -5678,7 +5678,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));
                        }
                }
        }
@@ -5687,7 +5687,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);
                        }
                }
@@ -12411,7 +12411,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) {
index 8a7d837..bf2e17c 100644 (file)
@@ -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 */
index c5d72f6..1e5224f 100644 (file)
@@ -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"
 
@@ -577,7 +578,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);
 
index 8f440f7..aad67b6 100644 (file)
@@ -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;
@@ -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) {
@@ -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;
        
index 1113f90..c359967 100644 (file)
@@ -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;
index b120112..789d9bf 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "BLI_math.h"
 #include "BLI_rect.h"
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_colortools.h"
@@ -836,7 +837,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);
index 9892887..a197324 100644 (file)
@@ -1124,9 +1124,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);
                }
@@ -1147,7 +1147,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);
                        
                }
@@ -4460,7 +4460,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);
index ff2f8bc..d56f224 100644 (file)
@@ -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);
 
@@ -518,7 +518,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);
index ae66d64..ab07cb4 100644 (file)
@@ -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);
index 4221f7c..4a9eb81 100644 (file)
@@ -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);
@@ -230,9 +230,11 @@ void ui_set_name_menu(uiBut *but, int value)
        int i;
        
        md= decompose_menu_string(but->str);
-       for (i=0; i<md->nitems; i++)
-               if (md->items[i].retval==value)
-                       strcpy(but->drawstr, md->items[i].str);
+       for (i=0; i<md->nitems; i++) {
+               if (md->items[i].retval==value) {
+                       BLI_strncpy(but->drawstr, md->items[i].str, sizeof(but->drawstr));
+               }
+       }
        
        menudata_free(md);
 }
@@ -1611,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);
@@ -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);
@@ -2152,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);
 }
@@ -2202,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;
 
@@ -2275,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);
@@ -2369,7 +2368,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 +2466,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 +2506,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);
index 2a183e3..3009d4f 100644 (file)
@@ -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;
        }
        
index 2560611..c00b0e0 100644 (file)
@@ -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);
index a49060e..206ecba 100644 (file)
@@ -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;
index 8c2ec6c..6399434 100644 (file)
@@ -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);
@@ -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;
                
@@ -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]);
index 02a25a2..f45f706 100644 (file)
@@ -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}")
index b992ae5..24c63a5 100644 (file)
@@ -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] )
index 4d62042..6dce92b 100644 (file)
@@ -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/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c
new file mode 100644 (file)
index 0000000..b0d15a0
--- /dev/null
@@ -0,0 +1,597 @@
+/**
+* $Id$
+*
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* 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) 2011 by Blender Foundation
+* All rights reserved.
+*
+* The Original Code is: all of this file.
+*
+* Contributor(s): Benoit Bolsee,
+*                 Nick Samarin
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+#include <math.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_ID.h"
+
+#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 "BLI_math_vector.h"
+
+#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"
+
+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;
+       MFace *mface;
+       float co[3], wco[3];
+       Object *ob;
+       LinkNode *oblink, *dmlink;
+       DerivedMesh *dm;
+       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);
+               BLI_linklist_append(&dms, (void*)dm);
+
+               nverts+= dm->getNumVerts(dm);
+               nfaces= dm->getNumFaces(dm);
+               ntris+= nfaces;
+
+               /* resolve quad faces */
+               mface= dm->getFaceArray(dm);
+               for(i= 0; i<nfaces; i++) {
+                       MFace* mf= &mface[i];
+                       if(mf->v4)
+                               ntris+=1;
+               }
+       }
+
+       /* 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;
+
+               curnverts= dm->getNumVerts(dm);
+               mvert= dm->getVertArray(dm);
+
+               /* copy verts */
+               for(i= 0; i<curnverts; i++) {
+                       MVert *v= &mvert[i];
+
+                       copy_v3_v3(co, v->co);
+                       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];
+               }
+
+               /* create tris */
+               curnfaces= dm->getNumFaces(dm);
+               mface= dm->getFaceArray(dm);
+
+               for(i= 0; i<curnfaces; i++) {
+                       MFace* mf= &mface[i];
+
+                       tri[0]= basenverts + mf->v1;
+                       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;
+                               tri += 3;
+                       }
+               }
+
+               basenverts+= curnverts;
+       }
+
+       /* 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;
+       *verts_r= verts;
+       *ntris_r= ntris;
+       *tris_r= tris;
+}
+
+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];
+       struct recast_heightfield *solid;
+       unsigned char *triflags;
+       struct recast_compactHeightfield* chf;
+       struct recast_contourSet *cset;
+       int width, height, walkableHeight, walkableClimb, walkableRadius;
+       int minRegionSize, mergeRegionSize, maxEdgeLen;
+       float detailSampleDist, detailSampleMaxError;
+
+       recast_calcBounds(verts, nverts, bmin, bmax);
+
+       /* ** 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;
+
+       /* 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();
+
+       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");
+
+       /* 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 ** */
+       recast_filterLedgeSpans(walkableHeight, walkableClimb, solid);
+       recast_filterWalkableLowHeightSpans(walkableHeight, solid);
+
+       /* ** Step 4: Partition walkable surface to simple regions ** */
+
+       chf= recast_newCompactHeightfield();
+       if(!recast_buildCompactHeightfield(walkableHeight, walkableClimb, RECAST_WALKABLE, solid, chf)) {
+               recast_destroyHeightfield(solid);
+               recast_destroyCompactHeightfield(chf);
+
+               return 0;
+       }
+
+       recast_destroyHeightfield(solid);
+
+       /* 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)) {
+               recast_destroyCompactHeightfield(chf);
+
+               return 0;
+       }
+
+       /* ** Step 5: Trace and simplify region contours ** */
+       /* Create contours */
+       cset= recast_newContourSet();
+
+       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)) {
+               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= recast_newPolyMeshDetail();
+       if(!recast_buildPolyMeshDetail(*pmesh, chf, detailSampleDist, detailSampleMaxError, *dmesh)) {
+               recast_destroyCompactHeightfield(chf);
+               recast_destroyContourSet(cset);
+               recast_destroyPolyMesh(*pmesh);
+               recast_destroyPolyMeshDetail(*dmesh);
+
+               return 0;
+       }
+
+       recast_destroyCompactHeightfield(chf);
+       recast_destroyContourSet(cset);
+
+       return 1;
+}
+
+static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh, struct recast_polyMeshDetail *dmesh, Base* base)
+{
+       float co[3], rot[3];
+       EditMesh *em;
+       int i,j, k;
+       unsigned short* v;
+       int face[3];
+       Main *bmain= CTX_data_main(C);
+       Scene *scene= CTX_data_scene(C);
+       Object* obedit;
+       int createob= base==NULL;
+       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 */
+               obedit= ED_object_add_type(C, OB_MESH, co, rot, FALSE, 1);
+       }
+       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));
+
+       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);
+       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);
+       }
+
+       /* 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);
+
+       for(i= 0; i<nmeshes; i++) {
+               int uniquevbase= em->totvert;
+               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; j<ndv; j++) {
+                       copy_v3_v3(co, &dverts[3*(vbase + j)]);
+                       SWAP(float, co[1], co[2]);
+                       addvertlist(em, co, NULL);
+               }
+
+               EM_init_index_arrays(em, 1, 0, 0);
+
+               /* create faces */
+               for(j= 0; j<trinum; j++) {
+                       unsigned char* tri= &tris[4*(tribase+j)];
+                       EditFace* newFace;
+                       int* polygonIdx;
+
+                       for(k= 0; k<3; k++) {
+                               if(tri[k]<nv)
+                                       face[k]= p[tri[k]]; /* shared vertex */
+                               else
+                                       face[k]= uniquevbase+tri[k]-nv; /* unique vertex */
+                       }
+                       newFace= addfacelist(em, EM_get_vert_for_index(face[0]), EM_get_vert_for_index(face[2]),
+                                                                       EM_get_vert_for_index(face[1]), NULL, NULL, NULL);
+
+                       /* 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();
+       }
+
+       recast_destroyPolyMesh(pmesh);
+       recast_destroyPolyMeshDetail(dmesh);
+
+       BKE_mesh_end_editmesh((Mesh*)obedit->data, em);
+       
+       DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+
+       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;
+               rename_id((ID *)obedit, "Navmesh");
+       }
+       
+       md= modifiers_findByType(obedit, eModifierType_NavMesh);
+       if(!md) {
+               ED_object_modifier_add(NULL, bmain, scene, obedit, NULL, eModifierType_NavMesh);
+       }
+
+       return obedit;
+}
+
+static int create_navmesh_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       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;
+
+       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);
+       createRepresentation(C, pmesh, dmesh, navmeshBase);
+
+       MEM_freeN(verts);
+       MEM_freeN(tris);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_create_navmesh(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Create navigation mesh";
+       ot->description= "Create navigation mesh for selected objects";
+       ot->idname= "MESH_OT_create_navmesh";
+
+       /* api callbacks */
+       ot->exec= create_navmesh_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+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;
+       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;
+                                       }
+                                       ef= ef->prev;
+                               }
+                       }
+               }               
+       }
+       
+       DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       BKE_mesh_end_editmesh((Mesh*)obedit->data, em);
+
+       return OPERATOR_FINISHED;
+}
+
+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= "MESH_OT_assign_navpolygon";
+
+       /* api callbacks */
+       ot->poll= ED_operator_editmesh;
+       ot->exec= assign_navpolygon_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+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= 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;
+               idx++;
+               ef= ef->prev;
+       }
+
+       qsort(indices, numfaces, sizeof(int), compare);
+
+       /* search first free index */
+       freeIdx= 1;
+       for(i= 0; i<numfaces; i++) {
+               if(indices[i]==freeIdx)
+                       freeIdx++;
+               else if(indices[i]>freeIdx)
+                       break;
+       }
+
+       MEM_freeN(indices);
+
+       return freeIdx;
+}
+
+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;
+                               }
+                               ef= ef->prev;
+                       }
+               }
+       }
+
+       DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+
+       BKE_mesh_end_editmesh((Mesh*)obedit->data, em);
+       return OPERATOR_FINISHED;
+}
+
+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= "MESH_OT_assign_new_navpolygon";
+
+       /* api callbacks */
+       ot->poll= ED_operator_editmesh;
+       ot->exec= assign_new_navpolygon_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
index 282eeef..f44f7fb 100644 (file)
@@ -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? */
index b9b8ddc..c78c9fd 100644 (file)
@@ -58,16 +58,6 @@ set(SRC
        object_intern.h
 )
 
-if(WITH_GAMEENGINE)
-       list(APPEND INC
-               ../../../../extern/recastnavigation/Recast/Include
-       )
-
-       list(APPEND SRC
-               object_navmesh.cpp
-       )
-endif()
-
 if(WITH_PYTHON)
        add_definitions(-DWITH_PYTHON)
 endif()
index cdda165..d473923 100644 (file)
@@ -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 = []
 
index 434111c..7bb98f4 100644 (file)
@@ -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_navmesh.cpp b/source/blender/editors/object/object_navmesh.cpp
deleted file mode 100644 (file)
index ae97b40..0000000
+++ /dev/null
@@ -1,628 +0,0 @@
-/**
-* $Id$
-*
-* ***** BEGIN GPL LICENSE BLOCK *****
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* 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
-* All rights reserved.
-*
-* The Original Code is: all of this file.
-*
-* Contributor(s): none yet.
-*
-* ***** END GPL LICENSE BLOCK *****
-*/
-
-#include <math.h>
-#include "Recast.h"
-
-extern "C"
-{
-#include "MEM_guardedalloc.h"
-
-#include "DNA_scene_types.h"
-#include "DNA_object_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_ID.h"
-
-#include "BKE_library.h"
-#include "BKE_depsgraph.h"
-#include "BKE_context.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 "RNA_access.h"
-
-#include "ED_mesh.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);
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-static void createVertsTrisData(bContext *C, LinkNode* obs, int& nverts, float*& verts, int &ntris, int*& tris)
-{
-       MVert *mvert;
-       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;
-
-       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);
-               BLI_linklist_append(&dms, (void*)dm);
-
-               nverts += dm->getNumVerts(dm);
-               nfaces = dm->getNumFaces(dm);
-               ntris += nfaces;
-
-               //resolve quad faces
-               mface = dm->getFaceArray(dm);
-               for (i=0; i<nfaces; i++)
-               {
-                       MFace* mf = &mface[i];
-                       if (mf->v4)
-                               ntris+=1;
-               }
-       }
-
-       //create data
-       verts = (float*) MEM_mallocN(sizeof(float)*3*nverts, "verts");
-       tris = (int*) MEM_mallocN(sizeof(int)*3*ntris, "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;
-
-               curnverts = dm->getNumVerts(dm);
-               mvert = dm->getVertArray(dm);
-               //copy verts    
-               for (i=0; i<curnverts; i++)
-               {
-                       MVert *v = &mvert[i];
-                       copy_v3_v3(co, v->co);
-                       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];
-               }
-
-               //create tris
-               curnfaces = dm->getNumFaces(dm);
-               mface = dm->getFaceArray(dm);
-               for (i=0; i<curnfaces; i++)
-               {
-                       MFace* mf = &mface[i]; 
-                       tri[0]= basenverts + mf->v1; 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; 
-                               tri += 3;
-                       }
-               }
-               basenverts += curnverts;
-       }
-
-       //release derived mesh
-       for (dmlink = dms; dmlink; dmlink = dmlink->next)
-       {
-               dm = (DerivedMesh*) dmlink->link;
-               dm->release(dm);
-       }
-       BLI_linklist_free(dms, NULL);
-}
-
-static bool buildNavMesh(const RecastData& recastParams, int nverts, float* verts, int ntris, int* tris,
-                                                                rcPolyMesh*& pmesh, rcPolyMeshDetail*& dmesh)
-{
-       float bmin[3], bmax[3];
-       rcHeightfield* solid;
-       unsigned char *triflags;
-       rcCompactHeightfield* chf;
-       rcContourSet *cset;
-
-       rcCalcBounds(verts, nverts, bmin, bmax);
-
-       //
-       // Step 1. Initialize build config.
-       //
-       rcConfig cfg;
-       memset(&cfg, 0, sizeof(cfg));
-       {
-/*
-               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;
-*/
-               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;
-
-       }
-
-       // 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);
-
-       //
-       // Step 2. Rasterize input polygon soup.
-       //
-       // Allocate voxel heightfield where we rasterize our input data to.
-       solid = new rcHeightfield;
-       if (!solid)
-               return false;
-
-       if (!rcCreateHeightfield(*solid, cfg.width, cfg.height, cfg.bmin, cfg.bmax, cfg.cs, cfg.ch))
-               return false;
-
-       // Allocate array that can hold triangle flags.
-       triflags = (unsigned char*) MEM_mallocN(sizeof(unsigned char)*ntris, "triflags");
-       if (!triflags)
-               return false;
-       // 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);
-       MEM_freeN(triflags);
-       MEM_freeN(verts);
-       MEM_freeN(tris);
-
-       //
-       // Step 3. Filter walkables surfaces.
-       //
-       rcFilterLedgeSpans(cfg.walkableHeight, cfg.walkableClimb, *solid);
-       rcFilterWalkableLowHeightSpans(cfg.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;
-
-       delete solid; 
-
-       // Prepare for region partitioning, by calculating distance field along the walkable surface.
-       if (!rcBuildDistanceField(*chf))
-               return false;
-
-       // Partition the walkable surface into simple regions without holes.
-       if (!rcBuildRegions(*chf, cfg.walkableRadius, cfg.borderSize, cfg.minRegionSize, cfg.mergeRegionSize))
-               return false;
-
-       //
-       // Step 5. Trace and simplify region contours.
-       //
-       // Create contours.
-       cset = new rcContourSet;
-       if (!cset)
-               return false;
-
-       if (!rcBuildContours(*chf, cfg.maxSimplificationError, cfg.maxEdgeLen, *cset))
-               return false;
-
-       //
-       // Step 6. Build polygons mesh from contours.
-       //
-       pmesh = new rcPolyMesh;
-       if (!pmesh)
-               return false;
-       if (!rcBuildPolyMesh(*cset, cfg.maxVertsPerPoly, *pmesh))
-               return false;
-
-
-       //
-       // Step 7. Create detail mesh which allows to access approximate height on each polygon.
-       //
-
-       dmesh = new rcPolyMeshDetail;
-       if (!dmesh)
-               return false;
-
-       if (!rcBuildPolyMeshDetail(*pmesh, *chf, cfg.detailSampleDist, cfg.detailSampleMaxError, *dmesh))
-               return false;
-
-       delete chf;
-       delete cset;
-
-       return true;
-}
-
-static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshDetail*& dmesh, Base* base)
-{
-       float co[3], rot[3];
-       EditMesh *em;
-       int i,j, k;
-       unsigned short* v;
-       int face[3];
-       Main *bmain = CTX_data_main(C);
-       Scene *scene= CTX_data_scene(C);
-       Object* obedit;
-       int createob = base==NULL;
-       zero_v3(co);
-       zero_v3(rot);
-       if (createob)
-       {
-               //create new object
-               obedit = ED_object_add_type(C, OB_MESH, co, rot, FALSE, 1);
-       }
-       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));
-
-       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
-       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;
-               SWAP(float, co[1], co[2]);
-               addvertlist(em, co, NULL);
-       }
-
-       //create custom data layer to save polygon idx
-       CustomData_add_layer_named(&em->fdata, CD_RECAST, CD_CALLOC, NULL, 0, "recastData");
-
-       //create verts and faces for detailed mesh
-       for (i=0; i<dmesh->nmeshes; i++)
-       {
-               int uniquevbase = em->totvert;
-               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];
-               int nv = 0;
-               for (j = 0; j < pmesh->nvp; ++j)
-               {
-                       if (p[j] == 0xffff) break;
-                       nv++;
-               }
-               //create unique verts 
-               for (j=nv; j<ndv; j++)
-               {
-                       copy_v3_v3(co, &dmesh->verts[3*(vbase + j)]);
-                       SWAP(float, co[1], co[2]);
-                       addvertlist(em, co, NULL);
-               }
-
-               EM_init_index_arrays(em, 1, 0, 0);
-               
-               //create faces
-               for (j=0; j<trinum; j++)
-               {
-                       unsigned char* tri = &dmesh->tris[4*(tribase+j)];
-                       EditFace* newFace;
-                       for (k=0; k<3; k++)
-                       {
-                               if (tri[k]<nv)
-                                       face[k] = p[tri[k]]; //shared vertex
-                               else
-                                       face[k] = uniquevbase+tri[k]-nv; //unique vertex
-                       }
-                       newFace = addfacelist(em, EM_get_vert_for_index(face[0]), EM_get_vert_for_index(face[2]), 
-                                                                       EM_get_vert_for_index(face[1]), NULL, NULL, NULL);
-
-                       //set navigation polygon idx to the custom layer
-                       int* 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;
-
-       BKE_mesh_end_editmesh((Mesh*)obedit->data, em);
-       
-       DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
-
-       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;
-               rename_id((ID *)obedit, "Navmesh");
-       }
-       
-       ModifierData *md= modifiers_findByType(obedit, eModifierType_NavMesh);
-       if (!md)
-       {
-               ED_object_modifier_add(NULL, bmain, scene, obedit, NULL, eModifierType_NavMesh);
-       }
-
-       return obedit;
-}
-
-static int create_navmesh_exec(bContext *C, wmOperator *op)
-{
-       Scene* scene = CTX_data_scene(C);
-       int nverts, ntris;
-       float* verts;
-       int* tris;
-       rcPolyMesh* pmesh;
-       rcPolyMeshDetail* 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;
-               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;
-               }
-               else
-                       BLI_linklist_append(&obs, (void*)base->object);
-       }
-       CTX_DATA_END;
-       createVertsTrisData(C, obs, nverts, verts, ntris, tris);
-       BLI_linklist_free(obs, NULL);
-       buildNavMesh(scene->gm.recastData, nverts, verts, ntris, tris, pmesh, dmesh);
-       createRepresentation(C, pmesh, dmesh, navmeshBase);
-
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_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";
-
-       /* api callbacks */
-       ot->exec= create_navmesh_exec;
-
-       /* flags */
-       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 *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
-
-       //do work here
-       int targetPolyIdx = -1;
-       EditFace *ef, *efa;
-       efa = EM_get_actFace(em, 0);
-       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;
-                               }
-                       }
-               }               
-       }
-       
-       DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
-       BKE_mesh_end_editmesh((Mesh*)obedit->data, em);
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_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";
-
-       /* api callbacks */
-       ot->poll = assign_navpolygon_poll;
-       ot->exec= assign_navpolygon_exec;
-
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-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];
-       EditFace* ef = (EditFace*)em->faces.last;
-       int idx = 0;
-       while(ef) 
-       {
-               int polyIdx = *(int*)CustomData_em_get(&em->fdata, ef->data, CD_RECAST);
-               indices[idx] = polyIdx;
-               idx++;
-               ef = ef->prev;
-       }
-       qsort(indices, numfaces, sizeof(int), compare);
-       //search first free index
-       int freeIdx = 1;
-       for (int i=0; i<numfaces; i++)
-       {
-               if (indices[i]==freeIdx)
-                       freeIdx++;
-               else if (indices[i]>freeIdx)
-                       break;
-       }
-       delete [] indices;
-       return freeIdx;
-}
-
-static int assign_new_navpolygon_exec(bContext *C, wmOperator *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;
-                               }
-                               ef = ef->prev;
-                       }
-               }
-       }               
-
-       DAG_id_tag_update((ID*)obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
-       BKE_mesh_end_editmesh((Mesh*)obedit->data, em);
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_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";
-
-       /* api callbacks */
-       ot->poll = assign_navpolygon_poll;
-       ot->exec= assign_new_navpolygon_exec;
-
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-}
index a9cb042..5a2437b 100644 (file)
@@ -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
 }
 
 
index 74e91cf..019d6df 100644 (file)
@@ -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 */
index ba0c2c8..345cda6 100644 (file)
@@ -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;
index 62d6d5f..5a888e6 100644 (file)
@@ -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;
 
index 3751d8e..8bc0ae5 100644 (file)
@@ -33,6 +33,7 @@
 #ifndef ED_NODE_INTERN_H
 #define ED_NODE_INTERN_H
 
+#include <stddef.h> /* for size_t */
 #include "UI_interface.h"
 
 /* internal exports only */
index a6cc650..c0919ef 100644 (file)
@@ -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);
                                }
                        }
        
index 4c61711..10d355b 100644 (file)
@@ -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);
                
index 0854f9f..d3d7b1b 100644 (file)
@@ -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)
index fb90ad0..16463a2 100644 (file)
@@ -1391,6 +1391,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)) {
index bcbc134..f38ae13 100644 (file)
@@ -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;
index 0b46d95..0ef85a4 100644 (file)
@@ -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))
index 277f404..197e6a2 100644 (file)
@@ -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)
index 4061128..b0e001f 100644 (file)
@@ -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))
index d928c23..b732158 100644 (file)
@@ -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)
index fb7aeac..b0d9892 100644 (file)
@@ -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)
index 785abc7..ad97ee8 100644 (file)
@@ -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)
index 31c17fb..4ff92e3 100644 (file)
@@ -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)
index 16898a8..5e13b8a 100644 (file)
@@ -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))
index 36d3dc8..a088ba8 100644 (file)
@@ -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;
 }
 
index 4b5769f..820c7e1 100644 (file)
@@ -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))
index 8225c98..fa5a3c7 100644 (file)
@@ -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;
index 2543d34..e6883eb 100644 (file)
@@ -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)) {
index 44d42a4..35c211d 100644 (file)
@@ -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,
index 67ed90c..9026010 100644 (file)
@@ -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);
 }
index d5bd44f..17fda6d 100644 (file)
@@ -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)));
+               }
        }
 }
 
index 3175c0d..bcbd767 100644 (file)
@@ -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; i<seq_len; i++) {
+                       for(i=0; i < seq_len; i++) {
                                item= PySequence_GetItem(value, i);
 
                                if(item==NULL) {
index e50ce23..cab5772 100644 (file)
@@ -61,12 +61,12 @@ typedef void (*RNA_SetIndexFunc)(PointerRNA *, PropertyRNA *, int index, void *)
 static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[],
                                                           ItemTypeCheckFunc check_item_type, const char *item_type_str, const char *error_prefix)
 {
-       int i;
+       Py_ssize_t i;
 
        /* not the last dimension */
        if (dim + 1 < totdim) {
                /* check that a sequence contains dimsize[dim] items */
-               const int seq_size= PySequence_Size(seq);
+               const Py_ssize_t seq_size= PySequence_Size(seq);
                if(seq_size == -1) {
                        PyErr_Format(PyExc_ValueError, "%s sequence expected at dimension %d, not '%s'",
                                     error_prefix, (int)dim + 1, Py_TYPE(seq)->tp_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.
         *
index b972569..f06707c 100644 (file)
@@ -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? */
        
index 05bcc32..7835ae6 100644 (file)
@@ -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);
        }
        
index dad43b4..cfeaee1 100644 (file)
@@ -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))
index 38196ee..f1b9549 100644 (file)
@@ -528,8 +528,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");
@@ -554,17 +554,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;
@@ -581,10 +581,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
@@ -620,6 +618,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");
@@ -646,8 +647,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') {
@@ -729,9 +730,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);
@@ -771,9 +772,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);
@@ -790,9 +791,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 {
@@ -804,8 +805,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);
@@ -823,8 +824,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);
@@ -842,8 +843,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);