Merged revision(s) 58452-58584 from trunk/blender into soc-2013-dingto.
authorThomas Dinges <blender@dingto.org>
Wed, 24 Jul 2013 21:56:06 +0000 (21:56 +0000)
committerThomas Dinges <blender@dingto.org>
Wed, 24 Jul 2013 21:56:06 +0000 (21:56 +0000)
220 files changed:
intern/cycles/app/cycles_test.cpp
intern/cycles/kernel/kernel_random.h
intern/cycles/util/util_task.cpp
intern/cycles/util/util_view.cpp
release/scripts/startup/bl_ui/properties_data_modifier.py
release/scripts/startup/bl_ui/space_image.py
release/scripts/startup/bl_ui/space_sequencer.py
release/scripts/startup/bl_ui/space_view3d.py
release/scripts/startup/bl_ui/space_view3d_toolbar.py
source/blender/avi/intern/avi_options.c
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/BKE_bmesh.h [deleted file]
source/blender/blenkernel/BKE_curve.h
source/blender/blenkernel/BKE_global.h
source/blender/blenkernel/BKE_pbvh.h
source/blender/blenkernel/BKE_sequencer.h
source/blender/blenkernel/BKE_text.h
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/editderivedmesh.c
source/blender/blenkernel/intern/editmesh.c
source/blender/blenkernel/intern/fcurve.c
source/blender/blenkernel/intern/fmodifier.c
source/blender/blenkernel/intern/idprop.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/mask.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/modifiers_bmesh.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/packedFile.c
source/blender/blenkernel/intern/paint.c
source/blender/blenkernel/intern/pbvh.c
source/blender/blenkernel/intern/pbvh_bmesh.c
source/blender/blenkernel/intern/pbvh_intern.h
source/blender/blenkernel/intern/property.c
source/blender/blenkernel/intern/rigidbody.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenkernel/intern/text.c
source/blender/blenkernel/intern/texture.c
source/blender/blenkernel/intern/writeffmpeg.c
source/blender/blenlib/BLI_bitmap.h
source/blender/blenlib/BLI_path_util.h
source/blender/blenlib/BLI_string_utf8.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/fileops.c
source/blender/blenlib/intern/math_color.c
source/blender/blenlib/intern/math_matrix.c
source/blender/blenlib/intern/math_rotation.c
source/blender/blenlib/intern/noise.c
source/blender/blenlib/intern/path_util.c
source/blender/blenlib/intern/storage.c
source/blender/blenlib/intern/string.c
source/blender/blenlib/intern/string_utf8.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/bmesh/CMakeLists.txt
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/intern/bmesh_construct.h
source/blender/bmesh/intern/bmesh_core.c
source/blender/bmesh/intern/bmesh_mesh_conv.c
source/blender/bmesh/intern/bmesh_operators.h
source/blender/bmesh/intern/bmesh_polygon.c
source/blender/bmesh/intern/bmesh_polygon.h
source/blender/bmesh/intern/bmesh_queries.c
source/blender/bmesh/intern/bmesh_queries.h
source/blender/bmesh/operators/bmo_dupe.c
source/blender/bmesh/operators/bmo_normals.c
source/blender/bmesh/operators/bmo_similar.c
source/blender/bmesh/operators/bmo_subdivide.c
source/blender/bmesh/tools/BME_bevel.c [deleted file]
source/blender/compositor/intern/COM_SocketReader.h
source/blender/compositor/intern/COM_WorkScheduler.cpp
source/blender/compositor/operations/COM_BlurBaseOperation.cpp
source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp
source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp
source/blender/compositor/operations/COM_MathBaseOperation.cpp
source/blender/compositor/operations/COM_MixAddOperation.cpp
source/blender/compositor/operations/COM_MixBurnOperation.cpp
source/blender/compositor/operations/COM_MixColorOperation.cpp
source/blender/compositor/operations/COM_MixDarkenOperation.cpp
source/blender/compositor/operations/COM_MixDifferenceOperation.cpp
source/blender/compositor/operations/COM_MixDivideOperation.cpp
source/blender/compositor/operations/COM_MixDodgeOperation.cpp
source/blender/compositor/operations/COM_MixHueOperation.cpp
source/blender/compositor/operations/COM_MixLightenOperation.cpp
source/blender/compositor/operations/COM_MixLinearLightOperation.cpp
source/blender/compositor/operations/COM_MixOverlayOperation.cpp
source/blender/compositor/operations/COM_MixSaturationOperation.cpp
source/blender/compositor/operations/COM_MixScreenOperation.cpp
source/blender/compositor/operations/COM_MixSoftLightOperation.cpp
source/blender/compositor/operations/COM_MixSubtractOperation.cpp
source/blender/compositor/operations/COM_MixValueOperation.cpp
source/blender/editors/animation/anim_channels_defines.c
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/animation/anim_markers.c
source/blender/editors/animation/keyframing.c
source/blender/editors/armature/armature_skinning.c
source/blender/editors/curve/curve_intern.h
source/blender/editors/curve/curve_ops.c
source/blender/editors/curve/editcurve.c
source/blender/editors/curve/editfont.c
source/blender/editors/include/ED_mesh.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_ops.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/interface/resources.c
source/blender/editors/mask/mask_add.c
source/blender/editors/mask/mask_ops.c
source/blender/editors/mesh/editface.c
source/blender/editors/mesh/editmesh_knife.c
source/blender/editors/mesh/editmesh_select.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/editmesh_utils.c
source/blender/editors/mesh/mesh_data.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_hook.c
source/blender/editors/object/object_lattice.c
source/blender/editors/object/object_modifier.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_vgroup.c
source/blender/editors/render/render_opengl.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt_paint/paint_hide.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/paint_vertex_proj.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_intern.h
source/blender/editors/sculpt_paint/sculpt_undo.c
source/blender/editors/space_action/space_action.c
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/space_file/filelist.c
source/blender/editors/space_graph/space_graph.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_info/space_info.c
source/blender/editors/space_nla/nla_channels.c
source/blender/editors/space_nla/nla_draw.c
source/blender/editors/space_nla/space_nla.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_add.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c
source/blender/editors/space_node/space_node.c
source/blender/editors/space_outliner/outliner_draw.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/editors/space_text/space_text.c
source/blender/editors/space_text/text_autocomplete.c
source/blender/editors/space_time/space_time.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_fly.c
source/blender/editors/space_view3d/view3d_iterators.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_manipulator.c
source/blender/editors/transform/transform_orientations.c
source/blender/editors/util/crazyspace.c
source/blender/editors/util/numinput.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/gpu/intern/gpu_buffers.c
source/blender/gpu/intern/gpu_extensions.c
source/blender/imbuf/intern/cineon/logImageCore.c
source/blender/imbuf/intern/cineon/logmemfile.c
source/blender/imbuf/intern/colormanagement.c
source/blender/imbuf/intern/indexer.c
source/blender/imbuf/intern/jpeg.c
source/blender/imbuf/intern/png.c
source/blender/imbuf/intern/thumbs.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/makesrna/intern/rna_modifier.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_object.c
source/blender/modifiers/intern/MOD_bevel.c
source/blender/modifiers/intern/MOD_ocean.c
source/blender/modifiers/intern/MOD_simpledeform.c
source/blender/nodes/composite/nodes/node_composite_image.c
source/blender/nodes/texture/nodes/node_texture_math.c
source/blender/python/bmesh/bmesh_py_ops_call.c
source/blender/python/intern/bpy_rna.c
source/blender/python/intern/bpy_rna_array.c
source/blender/python/mathutils/mathutils_Color.c
source/blender/python/mathutils/mathutils_Euler.c
source/blender/python/mathutils/mathutils_Matrix.c
source/blender/python/mathutils/mathutils_Quaternion.c
source/blender/python/mathutils/mathutils_geometry.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_keymap.c
source/blenderplayer/bad_level_call_stubs/stubs.c
source/creator/creator.c
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/Expressions/FloatValue.cpp
source/gameengine/Expressions/IntValue.cpp
source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
source/gameengine/Ketsji/KX_BlenderMaterial.h
source/gameengine/Ketsji/KX_PythonSeq.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

index 625e8cc1706b6aba2efb18edfc569b002cb26089..6d7c5912cb5a592fe3a1aa58f0c9ad9e62fb7760 100644 (file)
@@ -181,7 +181,7 @@ static void resize(int width, int height)
                options.session->reset(session_buffer_params(), options.session_params.samples);
 }
 
-void keyboard(unsigned char key)
+static void keyboard(unsigned char key)
 {
        if(key == 'r')
                options.session->reset(session_buffer_params(), options.session_params.samples);
index 6292adff6a5f76f6e428734857bf8680970d5181..c86ac34a057015b577bc9504af6efbaa95c9cb19 100644 (file)
@@ -141,11 +141,13 @@ __device_inline void path_rng_2D(KernelGlobals *kg, RNG *rng, int sample, int nu
                int p = *rng + dimension;
                cmj_sample_2D(sample, num_samples, p, fx, fy);
        }
+       else
 #endif
-
-       /* sobol */
-       *fx = path_rng_1D(kg, rng, sample, num_samples, dimension);
-       *fy = path_rng_1D(kg, rng, sample, num_samples, dimension + 1);
+       {
+               /* sobol */
+               *fx = path_rng_1D(kg, rng, sample, num_samples, dimension);
+               *fy = path_rng_1D(kg, rng, sample, num_samples, dimension + 1);
+       }
 }
 
 __device_inline void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sample, int num_samples, RNG *rng, int x, int y, float *fx, float *fy)
index 07960805f7748b6f2f2f15b22726eeff228a1a03..89d990cc5d90f239541abafdf155a719a3972b19 100644 (file)
@@ -189,10 +189,6 @@ void TaskScheduler::init(int num_threads)
                        /* automatic number of threads */
                        num_threads = system_cpu_thread_count();
                }
-               else {
-                       /* manual number of threads */
-                       num_threads;
-               }
 
                /* launch threads that will be waiting for work */
                threads.resize(num_threads);
index 328c0c9739158d8791d0def85e7503d0d9df271d..d9934fa1356f2e6196c37dbe043d4e70257b3b4e 100644 (file)
@@ -136,7 +136,7 @@ static void view_keyboard(unsigned char key, int x, int y)
        }
 }
 
-void view_idle()
+static void view_idle(void)
 {
        if(V.redraw) {
                V.redraw = false;
index 89e90618383564efbcc94fba4886a77c8fdc1c7d..861d64382ef5d733821c9da38ebf28a51a3e04cd 100644 (file)
@@ -715,9 +715,11 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col = split.column()
         col.label(text="Origin:")
         col.prop(md, "origin", text="")
-        sub = col.column()
-        sub.active = (md.origin is not None)
-        sub.prop(md, "use_relative")
+
+        if md.deform_method in {'TAPER', 'STRETCH', 'TWIST'}:
+            col.label(text="Lock:")
+            col.prop(md, "lock_x")
+            col.prop(md, "lock_y")
 
         col = split.column()
         col.label(text="Deform:")
@@ -726,9 +728,6 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         else:
             col.prop(md, "angle")
         col.prop(md, "limits", slider=True)
-        if md.deform_method in {'TAPER', 'STRETCH', 'TWIST'}:
-            col.prop(md, "lock_x")
-            col.prop(md, "lock_y")
 
     def SMOKE(self, layout, ob, md):
         layout.label(text="Settings can be found inside the Physics context")
index eb0d9c5082dfb34d075f091b01402032de09613a..22e2e6e08a2a533cbe16edbbb858cbffccc42462 100644 (file)
@@ -232,6 +232,7 @@ class IMAGE_MT_uvs_snap(Menu):
 
         layout.operator("uv.snap_selected", text="Selected to Pixels").target = 'PIXELS'
         layout.operator("uv.snap_selected", text="Selected to Cursor").target = 'CURSOR'
+        layout.operator("uv.snap_selected", text="Selected to Cursor (Offset)").target = 'CURSOR_OFFSET'
         layout.operator("uv.snap_selected", text="Selected to Adjacent Unselected").target = 'ADJACENT_UNSELECTED'
 
         layout.separator()
index 3477353ba0dc0a04e7d4838e210c30be13fd3892..791916370805667f73de27626e65a8ddddc05763 100644 (file)
@@ -671,13 +671,14 @@ class SEQUENCER_PT_sound(SequencerButtonsPanel, Panel):
         layout.separator()
         layout.prop(strip, "filepath", text="")
 
-        row = layout.row()
-        if sound.packed_file:
-            row.operator("sound.unpack", icon='PACKAGE', text="Unpack")
-        else:
-            row.operator("sound.pack", icon='UGLYPACKAGE', text="Pack")
+        if sound is not None:
+            row = layout.row()
+            if sound.packed_file:
+                row.operator("sound.unpack", icon='PACKAGE', text="Unpack")
+            else:
+                row.operator("sound.pack", icon='UGLYPACKAGE', text="Pack")
 
-        row.prop(sound, "use_memory_cache")
+            row.prop(sound, "use_memory_cache")
 
         layout.prop(strip, "show_waveform")
         layout.prop(strip, "volume")
index a5c8e7727b278782036748adc3e638442623182c..0ad8cdccca892a616b3b61007780216d324fd380 100644 (file)
@@ -293,7 +293,10 @@ class VIEW3D_MT_snap(Menu):
         layout = self.layout
 
         layout.operator("view3d.snap_selected_to_grid", text="Selection to Grid")
-        layout.operator("view3d.snap_selected_to_cursor", text="Selection to Cursor")
+        props = layout.operator("view3d.snap_selected_to_cursor", text="Selection to Cursor")
+        props.use_offset = False
+        props = layout.operator("view3d.snap_selected_to_cursor", text="Selection to Cursor (Offset)")
+        props.use_offset = True
 
         layout.separator()
 
@@ -2194,7 +2197,9 @@ class VIEW3D_MT_edit_curve_specials(Menu):
         layout.operator("curve.spline_weight_set")
         layout.operator("curve.radius_set")
         layout.operator("curve.smooth")
+        layout.operator("curve.smooth_weight")
         layout.operator("curve.smooth_radius")
+        layout.operator("curve.smooth_tilt")
 
 
 class VIEW3D_MT_edit_curve_showhide(ShowHideMenu, Menu):
index 1383775042d97532594a8c8b5f4df2447901495c..f253801f431363db8c50c3888d61a6497c6700d4 100644 (file)
@@ -277,7 +277,6 @@ class VIEW3D_PT_tools_curveedit(View3DPanel, Panel):
         col.operator("curve.switch_direction")
         col.operator("curve.spline_type_set")
         col.operator("curve.radius_set")
-        col.operator("curve.smooth_radius")
 
         col = layout.column(align=True)
         col.label(text="Handles:")
index f7759a1099fa1cdbf22aba3878a16d5c14da4840..c552cbe87242eb4ee9add21e09317291d4f36e72 100644 (file)
@@ -112,7 +112,7 @@ AviError AVI_set_compress_option(AviMovie *movie, int option_type, int stream, A
                                                        awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
                                                }
                                        }
-
+                                       break;
                        }
 
                        fseek(movie->fp, movie->offset_table[0], SEEK_SET);
index 40fc71e82ca8f360791f6814e9adc8dfa4e9ceb1..8396380fd06d4aa1922c61ace0399b05227564fb 100644 (file)
@@ -152,6 +152,11 @@ typedef enum DMDrawFlag {
        DM_DRAW_ALWAYS_SMOOTH = 2
 } DMDrawFlag;
 
+typedef enum DMForeachFlag {
+       DM_FOREACH_NOP = 0,
+       DM_FOREACH_USE_NORMAL = (1 << 0),  /* foreachMappedVert, foreachMappedFaceCenter */
+} DMForeachFlag;
+
 typedef enum DMDirtyFlag {
        /* dm has valid tessellated faces, but tessellated CDDATA need to be updated. */
        DM_DIRTY_TESS_CDLAYERS = 1 << 0,
@@ -285,7 +290,8 @@ struct DerivedMesh {
        void (*foreachMappedVert)(DerivedMesh *dm,
                                  void (*func)(void *userData, int index, const float co[3],
                                               const float no_f[3], const short no_s[3]),
-                                 void *userData);
+                                 void *userData,
+                                 DMForeachFlag flag);
 
        /** Iterate over each mapped edge in the derived mesh, calling the
         * given function with the original edge and the mapped edge's new
@@ -303,7 +309,8 @@ struct DerivedMesh {
        void (*foreachMappedFaceCenter)(DerivedMesh *dm,
                                        void (*func)(void *userData, int index,
                                                     const float cent[3], const float no[3]),
-                                       void *userData);
+                                       void *userData,
+                                       DMForeachFlag flag);
 
        /** Iterate over all vertex points, calling DO_MINMAX with given args.
         *
index 8c556e00aaaf01cdf8f2c6555d89be6e353cb96a..a0c2908a646a5408c50ebf89a3c983b09ba9ebe5 100644 (file)
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         268
-#define BLENDER_SUBVERSION      0
+#define BLENDER_SUBVERSION      1
 
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262
@@ -50,7 +50,7 @@ extern "C" {
 
 /* used by packaging tools */
 /* can be left blank, otherwise a,b,c... etc with no quotes */
-#define BLENDER_VERSION_CHAR   
+#define BLENDER_VERSION_CHAR   a
 /* alpha/beta/rc/release, docs use this */
 #define BLENDER_VERSION_CYCLE   alpha
 
diff --git a/source/blender/blenkernel/BKE_bmesh.h b/source/blender/blenkernel/BKE_bmesh.h
deleted file mode 100644 (file)
index 0dfab26..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ***** 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 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Geoffrey Bantle.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __BKE_BMESH_H__
-#define __BKE_BMESH_H__
-
-/** \file BKE_bmesh.h
- *  \ingroup bke
- *  \since January 2007
- *  \brief BMesh modeler structure and functions.
- *
- */
-
-/*NOTE: this is the bmesh 1.0 code.  it's completely outdated.*/
-
-/* uncomment to use the new bevel operator as a modifier */
-#define USE_BM_BEVEL_OP_AS_MOD
-
-/* bevel tool defines */
-/* element flags */
-#define BME_BEVEL_ORIG          1
-#define BME_BEVEL_BEVEL         (1 << 1)
-#define BME_BEVEL_NONMAN        (1 << 2)
-#define BME_BEVEL_WIRE          (1 << 3)
-
-/* tool options */
-#define BME_BEVEL_SELECT        1
-#define BME_BEVEL_VERT          (1 << 1)
-#define BME_BEVEL_RADIUS        (1 << 2)
-#define BME_BEVEL_ANGLE         (1 << 3)
-#define BME_BEVEL_WEIGHT        (1 << 4)
-#define BME_BEVEL_VGROUP        (1 << 5)
-//~ #define BME_BEVEL_EWEIGHT          (1<<4)
-//~ #define BME_BEVEL_VWEIGHT          (1<<5)
-#define BME_BEVEL_PERCENT       (1 << 6)
-#define BME_BEVEL_EMIN          (1 << 7)
-#define BME_BEVEL_EMAX          (1 << 8)
-#define BME_BEVEL_RUNNING       (1 << 9)
-#define BME_BEVEL_RES           (1 << 10)
-
-#define BME_BEVEL_EVEN          (1 << 11) /* this is a new setting not related to old (trunk bmesh bevel code) but adding
-                                              * here because they are mixed - campbell */
-#define BME_BEVEL_DIST          (1 << 12) /* same as above */
-
-#define BME_BEVEL_OVERLAP_OK    (1 << 13)
-
-typedef struct BME_TransData {
-       struct BMesh *bm; /* the bmesh the vert belongs to */
-       struct BMVert *v;  /* pointer to the vert this tdata applies to */
-       float co[3];  /* the original coordinate */
-       float org[3]; /* the origin */
-       float vec[3]; /* a directional vector; always, always normalize! */
-       void *loc;    /* a pointer to the data to transform (likely the vert's cos) */
-       float factor; /* primary scaling factor; also accumulates number of weighted edges for beveling tool */
-       float weight; /* another scaling factor; used primarily for propogating vertex weights to transforms; */
-                     /* weight is also used across recursive bevels to help with the math */
-       float maxfactor; /* the unscaled, original factor (used only by "edge verts" in recursive beveling) */
-       float *max;   /* the maximum distance this vert can be transformed; negative is infinite
-                      * it points to the "parent" maxfactor (where maxfactor makes little sense)
-                      * where the max limit is stored (limits are stored per-corner) */
-} BME_TransData;
-
-typedef struct BME_TransData_Head {
-       struct GHash *gh;       /* the hash structure for element lookup */
-       struct MemArena *ma;    /* the memory "pool" we will be drawing individual elements from */
-       int len;
-} BME_TransData_Head;
-
-struct BME_TransData *BME_get_transdata(struct BME_TransData_Head *td, struct BMVert *v);
-void BME_free_transdata(struct BME_TransData_Head *td);
-struct BMesh *BME_bevel(struct BMesh *bm, float value, int res, int options, int defgrp_index, float angle,
-                        BME_TransData_Head **rtd);
-
-#endif
index 3be77086336b44c34a97a315229763076f4e3373..93f9ec276aa483516fe8c1badff07c2269413c72 100644 (file)
@@ -129,6 +129,14 @@ bool BKE_nurb_type_convert(struct Nurb *nu, const short type, const bool use_han
 void BKE_nurb_points_add(struct Nurb *nu, int number);
 void BKE_nurb_bezierPoints_add(struct Nurb *nu, int number);
 
+struct BezTriple *BKE_nurb_bezt_get_next(struct Nurb *nu, struct BezTriple *bezt);
+struct BezTriple *BKE_nurb_bezt_get_prev(struct Nurb *nu, struct BezTriple *bezt);
+struct BPoint    *BKE_nurb_bpoint_get_next(struct Nurb *nu, struct BPoint *bp);
+struct BPoint    *BKE_nurb_bpoint_get_prev(struct Nurb *nu, struct BPoint *bp);
+
+void BKE_nurb_bezt_calc_normal(struct Nurb *nu, struct BezTriple *bezt, float r_normal[3]);
+void BKE_nurb_bezt_calc_plane(struct Nurb *nu, struct BezTriple *bezt, float r_plane[3]);
+
 void BKE_nurb_handle_calc(struct BezTriple *bezt, struct BezTriple *prev,  struct BezTriple *next, int mode);
 
 void BKE_nurb_handles_calc(struct Nurb *nu);
index 0699344a8878c24d08062a936d58ad8b9d64b7af..9d33af1a0f4224816d0525184533bcbbc0fc6348 100644 (file)
@@ -46,7 +46,6 @@ extern "C" {
 /* forwards */
 struct Main;
 struct Object;
-struct BME_Glob;
 
 typedef struct Global {
 
index 48c16f8db388bd604dc74947cab165016d00a0de..7d3d8d7dcbd325394af071d44a2efdc030f00d65 100644 (file)
@@ -223,7 +223,7 @@ typedef struct PBVHVertexIter {
        struct CCGElem **grids;
        struct CCGElem *grid;
        struct CCGKey *key;
-       BLI_bitmap *grid_hidden, gh;
+       BLI_bitmap **grid_hidden, *gh;
        int *grid_indices;
        int totgrid;
        int gridsize;
index 4494d127082091e498b0966b19523194f0662510..749b04d7328a1fa0a5522181154561250a2b1927 100644 (file)
@@ -208,6 +208,10 @@ int BKE_sequencer_recursive_apply(struct Sequence *seq, int (*apply_func)(struct
 
 void BKE_sequencer_free_clipboard(void);
 
+void BKE_sequence_clipboard_pointers_free(struct Sequence *seq);
+void BKE_sequence_clipboard_pointers_store(struct Sequence *seq);
+void BKE_sequence_clipboard_pointers_restore(struct Sequence *seq, struct Main *bmain);
+
 void BKE_sequence_free(struct Scene *scene, struct Sequence *seq);
 const char *BKE_sequence_give_name(struct Sequence *seq);
 void BKE_sequence_calc(struct Scene *scene, struct Sequence *seq);
@@ -319,8 +323,6 @@ void BKE_sequence_base_dupli_recursive(struct Scene *scene, struct Scene *scene_
 bool BKE_sequence_is_valid_check(struct Sequence *seq);
 
 void BKE_sequencer_clear_scene_in_allseqs(struct Main *bmain, struct Scene *sce);
-void BKE_sequencer_clear_movieclip_in_clipboard(struct MovieClip *clip);
-void BKE_sequencer_clear_mask_in_clipboard(struct Mask *mask);
 
 struct Sequence *BKE_sequence_get_by_name(struct ListBase *seqbase, const char *name, int recursive);
 
index 2406fa51c8462b7fc950686e37d0eba1c35ca67c..24fd763d0784c42b96ca0b9b48f13151c202d591 100644 (file)
@@ -86,7 +86,6 @@ void  txt_sel_all                     (struct Text *text);
 void   txt_sel_line            (struct Text *text);
 char   *txt_sel_to_buf         (struct Text *text);
 void   txt_insert_buf          (struct Text *text, const char *in_buffer);
-void   txt_print_undo          (struct Text *text);
 void   txt_undo_add_op         (struct Text *text, int op);
 void   txt_do_undo                     (struct Text *text);
 void   txt_do_redo                     (struct Text *text);
@@ -106,6 +105,10 @@ int                txt_setcurr_tab_spaces(struct Text *text, int space);
 bool   txt_cursor_is_line_start(struct Text *text);
 bool   txt_cursor_is_line_end(struct Text *text);
 
+#if 0
+void   txt_print_undo          (struct Text *text);
+#endif
+
 /* utility functions, could be moved somewhere more generic but are python/text related  */
 int text_check_bracket(const char ch);
 int text_check_delim(const char ch);
index 2f51f9f17feec66a2e4fcbeff3f2192ea78394db..655e0d65133a5aaced5d1861b98658f7a8cd8e2f 100644 (file)
@@ -165,7 +165,6 @@ set(SRC
        BKE_armature.h
        BKE_autoexec.h
        BKE_blender.h
-       BKE_bmesh.h
        BKE_bmfont.h
        BKE_bmfont_types.h
        BKE_boids.h
index 9fea3d2e13f507d7dbfa8053844c80b3a4c05db8..ba680147201487fd2aa95b25c44fc52a666d0e56 100644 (file)
@@ -1036,7 +1036,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
                                        if (ob->type != OB_MBALL) ob->flag |= OB_DONE;  /* doesnt render */
 
                                        if (me->edit_btmesh) {
-                                               dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void *) &vdd);
+                                               dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void *) &vdd, DM_FOREACH_USE_NORMAL);
                                        }
                                        else {
                                                for (a = 0; a < totvert; a++) {
index 2ede5acd6e94d58843e79a65a98a0f86c9097dd9..d37ccae308951ec2380e89d17c66b50b3d9ba733 100644 (file)
@@ -1329,6 +1329,7 @@ void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, float mat[3][3], short use_compa
                                mat3_to_compatible_eulO(pchan->eul, pchan->eul, pchan->rotmode, mat);
                        else
                                mat3_to_eulO(pchan->eul, pchan->rotmode, mat);
+                       break;
        }
 }
 
index faa4d8d3071dac29c2a45f4f049ed0ec95d6b4e5..0e294f388386891b08e697558303dfc6bc412894 100644 (file)
@@ -1548,19 +1548,26 @@ static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOption
 static void cdDM_foreachMappedVert(
         DerivedMesh *dm,
         void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
-        void *userData)
+        void *userData,
+        DMForeachFlag flag)
 {
        MVert *mv = CDDM_get_verts(dm);
-       int i, orig, *index = DM_get_vert_data_layer(dm, CD_ORIGINDEX);
+       int *index = DM_get_vert_data_layer(dm, CD_ORIGINDEX);
+       int i;
 
-       for (i = 0; i < dm->numVertData; i++, mv++) {
-               if (index) {
-                       orig = *index++;
+       if (index) {
+               for (i = 0; i < dm->numVertData; i++, mv++) {
+                       const short *no = (flag & DM_FOREACH_USE_NORMAL) ? mv->no : NULL;
+                       const int orig = *index++;
                        if (orig == ORIGINDEX_NONE) continue;
-                       func(userData, orig, mv->co, NULL, mv->no);
+                       func(userData, orig, mv->co, NULL, no);
+               }
+       }
+       else {
+               for (i = 0; i < dm->numVertData; i++, mv++) {
+                       const short *no = (flag & DM_FOREACH_USE_NORMAL) ? mv->no : NULL;
+                       func(userData, i, mv->co, NULL, no);
                }
-               else
-                       func(userData, i, mv->co, NULL, mv->no);
        }
 }
 
@@ -1588,47 +1595,37 @@ static void cdDM_foreachMappedEdge(
 static void cdDM_foreachMappedFaceCenter(
         DerivedMesh *dm,
         void (*func)(void *userData, int index, const float cent[3], const float no[3]),
-        void *userData)
+        void *userData,
+        DMForeachFlag flag)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
        MVert *mvert = cddm->mvert;
        MPoly *mp;
        MLoop *ml;
-       int i, j, orig, *index;
+       int i, orig, *index;
 
        index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX);
        mp = cddm->mpoly;
        for (i = 0; i < dm->numPolyData; i++, mp++) {
                float cent[3];
-               float no[3];
+               float *no, _no[3];
 
                if (index) {
                        orig = *index++;
                        if (orig == ORIGINDEX_NONE) continue;
                }
-               else
+               else {
                        orig = i;
+               }
                
                ml = &cddm->mloop[mp->loopstart];
-               cent[0] = cent[1] = cent[2] = 0.0f;
-               for (j = 0; j < mp->totloop; j++, ml++) {
-                       add_v3_v3v3(cent, cent, mvert[ml->v].co);
-               }
-               mul_v3_fl(cent, 1.0f / (float)j);
+               BKE_mesh_calc_poly_center(mp, ml, mvert, cent);
 
-               ml = &cddm->mloop[mp->loopstart];
-               if (j > 3) {
-                       normal_quad_v3(no,
-                                      mvert[(ml + 0)->v].co,
-                                      mvert[(ml + 1)->v].co,
-                                      mvert[(ml + 2)->v].co,
-                                      mvert[(ml + 3)->v].co);
+               if (flag & DM_FOREACH_USE_NORMAL) {
+                       BKE_mesh_calc_poly_normal(mp, ml, mvert, (no = _no));
                }
                else {
-                       normal_tri_v3(no,
-                                     mvert[(ml + 0)->v].co,
-                                     mvert[(ml + 1)->v].co,
-                                     mvert[(ml + 2)->v].co);
+                       no = NULL;
                }
 
                func(userData, orig, cent, no);
index a7311d5efc73bb0a77ed6eea4bd2c0b02150d11c..05ffd4a626571ea3abf1cac5ad0a0d479b05bf6c 100644 (file)
@@ -476,7 +476,6 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
                BKE_ptcache_validate(cache, 0);
                cache->last_exact= 0;
                cache->flag &= ~PTCACHE_REDO_NEEDED;
-               return;
        }
        
        // unused in the moment, calculated separately in implicit.c
index 00a479b8b880364073059cd53774ce9df3eea771..43e5cc101a76e7065c8af4e2ef8fdce1b27863a3 100644 (file)
@@ -681,6 +681,143 @@ void BKE_nurb_bezierPoints_add(Nurb *nu, int number)
        nu->pntsu += number;
 }
 
+
+BezTriple *BKE_nurb_bezt_get_next(Nurb *nu, BezTriple *bezt)
+{
+       BezTriple *bezt_next;
+
+       BLI_assert(ARRAY_HAS_ITEM(bezt, nu->bezt, nu->pntsu));
+
+       if (bezt == &nu->bezt[nu->pntsu - 1]) {
+               if (nu->flagu & CU_NURB_CYCLIC) {
+                       bezt_next = nu->bezt;
+               }
+               else {
+                       bezt_next = NULL;
+               }
+       }
+       else {
+               bezt_next = bezt + 1;
+       }
+
+       return bezt_next;
+}
+
+BPoint *BKE_nurb_bpoint_get_next(Nurb *nu, BPoint *bp)
+{
+       BPoint *bp_next;
+
+       BLI_assert(ARRAY_HAS_ITEM(bp, nu->bp, nu->pntsu));
+
+       if (bp == &nu->bp[nu->pntsu - 1]) {
+               if (nu->flagu & CU_NURB_CYCLIC) {
+                       bp_next = nu->bp;
+               }
+               else {
+                       bp_next = NULL;
+               }
+       }
+       else {
+               bp_next = bp + 1;
+       }
+
+       return bp_next;
+}
+
+BezTriple *BKE_nurb_bezt_get_prev(Nurb *nu, BezTriple *bezt)
+{
+       BezTriple *bezt_prev;
+
+       BLI_assert(ARRAY_HAS_ITEM(bezt, nu->bezt, nu->pntsu));
+
+       if (bezt == nu->bezt) {
+               if (nu->flagu & CU_NURB_CYCLIC) {
+                       bezt_prev = &nu->bezt[nu->pntsu - 1];
+               }
+               else {
+                       bezt_prev = NULL;
+               }
+       }
+       else {
+               bezt_prev = bezt - 1;
+       }
+
+       return bezt_prev;
+}
+
+BPoint *BKE_nurb_bpoint_get_prev(Nurb *nu, BPoint *bp)
+{
+       BPoint *bp_prev;
+
+       BLI_assert(ARRAY_HAS_ITEM(bp, nu->bp, nu->pntsu));
+
+       if (bp == nu->bp) {
+               if (nu->flagu & CU_NURB_CYCLIC) {
+                       bp_prev = &nu->bp[nu->pntsu - 1];
+               }
+               else {
+                       bp_prev = NULL;
+               }
+       }
+       else {
+               bp_prev = bp - 1;
+       }
+
+       return bp_prev;
+}
+
+void BKE_nurb_bezt_calc_normal(struct Nurb *UNUSED(nu), struct BezTriple *bezt, float r_normal[3])
+{
+       /* calculate the axis matrix from the spline */
+       float dir_prev[3], dir_next[3];
+
+       sub_v3_v3v3(dir_prev, bezt->vec[0], bezt->vec[1]);
+       sub_v3_v3v3(dir_next, bezt->vec[1], bezt->vec[2]);
+
+       normalize_v3(dir_prev);
+       normalize_v3(dir_next);
+
+       add_v3_v3v3(r_normal, dir_prev, dir_next);
+       normalize_v3(r_normal);
+}
+
+void BKE_nurb_bezt_calc_plane(struct Nurb *nu, struct BezTriple *bezt, float r_plane[3])
+{
+       float dir_prev[3], dir_next[3];
+
+       sub_v3_v3v3(dir_prev, bezt->vec[0], bezt->vec[1]);
+       sub_v3_v3v3(dir_next, bezt->vec[1], bezt->vec[2]);
+
+       normalize_v3(dir_prev);
+       normalize_v3(dir_next);
+
+       cross_v3_v3v3(r_plane, dir_prev, dir_next);
+       if (normalize_v3(r_plane) < FLT_EPSILON) {
+               BezTriple *bezt_prev = BKE_nurb_bezt_get_prev(nu, bezt);
+               BezTriple *bezt_next = BKE_nurb_bezt_get_next(nu, bezt);
+
+               if (bezt_prev) {
+                       sub_v3_v3v3(dir_prev, bezt_prev->vec[1], bezt->vec[1]);
+                       normalize_v3(dir_prev);
+               }
+               if (bezt_next) {
+                       sub_v3_v3v3(dir_next, bezt->vec[1], bezt_next->vec[1]);
+                       normalize_v3(dir_next);
+               }
+               cross_v3_v3v3(r_plane, dir_prev, dir_next);
+       }
+
+       /* matches with bones more closely */
+       {
+               float dir_mid[3], tvec[3];
+               add_v3_v3v3(dir_mid, dir_prev, dir_next);
+               cross_v3_v3v3(tvec, r_plane, dir_mid);
+               copy_v3_v3(r_plane, tvec);
+       }
+
+       normalize_v3(r_plane);
+}
+
 /* ~~~~~~~~~~~~~~~~~~~~Non Uniform Rational B Spline calculations ~~~~~~~~~~~ */
 
 
@@ -2173,6 +2310,7 @@ static void make_bevel_list_3D(BevList *bl, int smooth_iter, int twist_mode)
                        break;
                default: /* CU_TWIST_Z_UP default, pre 2.49c */
                        make_bevel_list_3D_zup(bl);
+                       break;
        }
 
        if (bl->poly == -1) /* check its not cyclic */
index 28fa5cc689b867e6ae2c9e414175dccffdab7ae2..d69ec6a9597803205182612f9ccf666ce209fca8 100644 (file)
@@ -218,9 +218,16 @@ static void layerFree_bmesh_elem_py_ptr(void *data, int count, int size)
 static void layerInterp_mdeformvert(void **sources, const float *weights,
                                     const float *UNUSED(sub_weights), int count, void *dest)
 {
+       /* a single linked list of MDeformWeight's
+        * use this to avoid double allocs (which LinkNode would do) */
+       struct MDeformWeight_Link {
+               struct MDeformWeight_Link *next;
+               MDeformWeight dw;
+       };
+
        MDeformVert *dvert = dest;
-       LinkNode *dest_dw = NULL; /* a list of lists of MDeformWeight pointers */
-       LinkNode *node;
+       struct MDeformWeight_Link *dest_dwlink = NULL;
+       struct MDeformWeight_Link *node;
        int i, j, totweight;
 
        if (count <= 0) return;
@@ -238,8 +245,8 @@ static void layerInterp_mdeformvert(void **sources, const float *weights,
                        if (weight == 0.0f)
                                continue;
 
-                       for (node = dest_dw; node; node = node->next) {
-                               MDeformWeight *tmp_dw = (MDeformWeight *)node->link;
+                       for (node = dest_dwlink; node; node = node->next) {
+                               MDeformWeight *tmp_dw = &node->dw;
 
                                if (tmp_dw->def_nr == dw->def_nr) {
                                        tmp_dw->weight += weight;
@@ -249,11 +256,14 @@ static void layerInterp_mdeformvert(void **sources, const float *weights,
 
                        /* if this def_nr is not in the list, add it */
                        if (!node) {
-                               MDeformWeight *tmp_dw = MEM_callocN(sizeof(*tmp_dw),
-                                                                   "layerInterp_mdeformvert tmp_dw");
-                               tmp_dw->def_nr = dw->def_nr;
-                               tmp_dw->weight = weight;
-                               BLI_linklist_prepend(&dest_dw, tmp_dw);
+                               struct MDeformWeight_Link *tmp_dwlink = MEM_mallocN(sizeof(*tmp_dwlink), __func__);
+                               tmp_dwlink->dw.def_nr = dw->def_nr;
+                               tmp_dwlink->dw.weight = weight;
+
+                               /* inline linklist */
+                               tmp_dwlink->next = dest_dwlink;
+                               dest_dwlink = tmp_dwlink;
+
                                totweight++;
                        }
                }
@@ -262,20 +272,31 @@ static void layerInterp_mdeformvert(void **sources, const float *weights,
        /* delay writing to the destination incase dest is in sources */
 
        /* now we know how many unique deform weights there are, so realloc */
-       if (dvert->dw) MEM_freeN(dvert->dw);
+       if (dvert->dw && (dvert->totweight == totweight)) {
+               /* pass (fastpath if we don't need to realloc) */
+       }
+       else {
+               if (dvert->dw) {
+                       MEM_freeN(dvert->dw);
+               }
+
+               if (totweight) {
+                       dvert->dw = MEM_mallocN(sizeof(*dvert->dw) * totweight, __func__);
+               }
+       }
 
        if (totweight) {
-               dvert->dw = MEM_mallocN(sizeof(*dvert->dw) * totweight,
-                                       "layerInterp_mdeformvert dvert->dw");
+               struct MDeformWeight_Link *node_next;
                dvert->totweight = totweight;
-
-               for (i = 0, node = dest_dw; node; node = node->next, ++i)
-                       dvert->dw[i] = *((MDeformWeight *)node->link);
+               for (i = 0, node = dest_dwlink; node; node = node_next, i++) {
+                       node_next = node->next;
+                       dvert->dw[i] = node->dw;
+                       MEM_freeN(node);
+               }
        }
-       else
+       else {
                memset(dvert, 0, sizeof(*dvert));
-
-       BLI_linklist_free(dest_dw, MEM_freeN);
+       }
 }
 
 static void layerCopy_tface(const void *source, void *dest, int count)
@@ -2391,6 +2412,7 @@ bool CustomData_bmesh_merge(CustomData *source, CustomData *dest,
                        BLI_assert(!"invalid type given");
                        iter_type = BM_VERTS_OF_MESH;
                        totelem = bm->totvert;
+                       break;
        }
 
        dest->pool = NULL;
index 2206770dfbd7b064bf54aac0d46f211c9f62e398..4ce06623baec8f31dbac01188934478ec66c7c2d 100644 (file)
@@ -558,6 +558,7 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                                }
                                else
                                        dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Parent");
+                               break;
                }
                /* exception case: parent is duplivert */
                if (ob->type == OB_MBALL && (ob->parent->transflag & OB_DUPLIVERTS)) {
@@ -619,8 +620,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                                node2 = dag_get_node(dag, cam->dof_ob);
                                dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Camera DoF");
                        }
+                       break;
                }
-               break;
                case OB_MBALL: 
                {
                        Object *mom = BKE_mball_basis_find(scene, ob);
@@ -629,8 +630,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                                node2 = dag_get_node(dag, mom);
                                dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Metaball");  /* mom depends on children! */
                        }
+                       break;
                }
-               break;
                case OB_CURVE:
                case OB_FONT:
                {
@@ -650,8 +651,8 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
                                        dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Texture On Curve");
                                }
                        }
+                       break;
                }
-               break;
        }
        
        /* material drivers */
index ddd5e4a1e02ebaea472c371126d91f084bebd9b8..720500d188b263a260847bd44fcca1dd84a0bf1d 100644 (file)
@@ -69,11 +69,120 @@ typedef struct EditDerivedBMesh {
 
        BMEditMesh *em;
 
-       float (*vertexCos)[3];
-       float (*vertexNos)[3];
-       float (*polyNos)[3];
+       /** when set, \a vertexNos, polyNos are lazy initialized */
+       const float (*vertexCos)[3];
+
+       /** lazy initialize (when \a vertexCos is set) */
+       float const (*vertexNos)[3];
+       float const (*polyNos)[3];
+       /** also lazy init but dont depend on \a vertexCos */
+       const float (*polyCos)[3];
 } EditDerivedBMesh;
 
+/* -------------------------------------------------------------------- */
+/* Lazy initialize datastructures */
+
+static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm);
+
+static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm)
+{
+       if (bmdm->vertexCos && (bmdm->vertexNos == NULL)) {
+
+               BMesh *bm = bmdm->em->bm;
+               const float (*vertexCos)[3], (*polyNos)[3];
+               float (*vertexNos)[3];
+
+               BMFace *efa;
+               BMVert *eve;
+               BMIter fiter;
+               BMIter viter;
+               int i;
+
+               vertexCos = bmdm->vertexCos;
+               vertexNos = MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__);
+
+               /* calculate vertex normals from poly normals */
+               emDM_ensurePolyNormals(bmdm);
+
+               BM_mesh_elem_index_ensure(bm, BM_FACE);
+
+               vertexCos = bmdm->vertexCos;
+               polyNos = bmdm->polyNos;
+
+               BM_ITER_MESH_INDEX (eve, &viter, bm, BM_VERTS_OF_MESH, i) {
+                       float *no = vertexNos[i];
+                       BM_ITER_ELEM (efa, &fiter, eve, BM_FACES_OF_VERT) {
+                               add_v3_v3(no, polyNos[BM_elem_index_get(efa)]);
+                       }
+
+                       /* following Mesh convention; we use vertex coordinate itself
+                        * for normal in this case */
+                       if (UNLIKELY(normalize_v3(no) == 0.0f)) {
+                               normalize_v3_v3(no, vertexCos[i]);
+                       }
+               }
+
+               bmdm->vertexNos = (const float (*)[3])vertexNos;
+       }
+}
+
+static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
+{
+       if (bmdm->vertexCos && (bmdm->polyNos == NULL)) {
+               BMesh *bm = bmdm->em->bm;
+               const float (*vertexCos)[3];
+               float (*polyNos)[3];
+
+               BMFace *efa;
+               BMIter fiter;
+               int i;
+
+               BM_mesh_elem_index_ensure(bm, BM_VERT);
+
+               polyNos = MEM_mallocN(sizeof(*polyNos) * bm->totface, __func__);
+
+               vertexCos = bmdm->vertexCos;
+
+               BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
+                       BM_elem_index_set(efa, i); /* set_inline */
+                       BM_face_calc_normal_vcos(bm, efa, polyNos[i], vertexCos);
+               }
+               bm->elem_index_dirty &= ~BM_FACE;
+
+               bmdm->polyNos = (const float (*)[3])polyNos;
+       }
+}
+
+static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
+{
+       if (bmdm->polyCos == NULL) {
+               BMesh *bm = bmdm->em->bm;
+               float (*polyCos)[3];
+
+               BMFace *efa;
+               BMIter fiter;
+               int i;
+
+               polyCos = MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__);
+
+               if (bmdm->vertexCos) {
+                       const float (*vertexCos)[3];
+                       vertexCos = bmdm->vertexCos;
+
+                       BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
+                               BM_face_calc_center_mean_vcos(bm, efa, polyCos[i], vertexCos);
+                       }
+               }
+               else {
+                       BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
+                               BM_face_calc_center_mean(efa, polyCos[i]);
+                       }
+               }
+
+               bmdm->polyCos = (const float (*)[3])polyCos;
+       }
+}
+
 static void emDM_calcNormals(DerivedMesh *dm)
 {
        /* Nothing to do: normals are already calculated and stored on the
@@ -86,9 +195,11 @@ static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm))
        /* do nothing */
 }
 
-static void emDM_foreachMappedVert(DerivedMesh *dm,
-                                   void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
-                                   void *userData)
+static void emDM_foreachMappedVert(
+        DerivedMesh *dm,
+        void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
+        void *userData,
+        DMForeachFlag flag)
 {
        EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
        BMesh *bm = bmdm->em->bm;
@@ -97,13 +208,26 @@ static void emDM_foreachMappedVert(DerivedMesh *dm,
        int i;
 
        if (bmdm->vertexCos) {
+               const float (*vertexCos)[3] = bmdm->vertexCos;
+               const float (*vertexNos)[3];
+
+               if (flag & DM_FOREACH_USE_NORMAL) {
+                       emDM_ensureVertNormals(bmdm);
+                       vertexNos = bmdm->vertexNos;
+               }
+               else {
+                       vertexNos = NULL;
+               }
+
                BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
-                       func(userData, i, bmdm->vertexCos[i], bmdm->vertexNos[i], NULL);
+                       const float *no = (flag & DM_FOREACH_USE_NORMAL) ? vertexNos[i] : NULL;
+                       func(userData, i, vertexCos[i], no, NULL);
                }
        }
        else {
                BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
-                       func(userData, i, eve->co, eve->no, NULL);
+                       const float *no = (flag & DM_FOREACH_USE_NORMAL) ? eve->no : NULL;
+                       func(userData, i, eve->co, no, NULL);
                }
        }
 }
@@ -248,56 +372,42 @@ static void emDM_drawUVEdges(DerivedMesh *dm)
        glEnd();
 }
 
-static void emDM__calcFaceCent(BMFace *efa, float cent[3], float (*vertexCos)[3])
-{
-       BMIter liter;
-       BMLoop *l;
-       int tot = 0;
-
-       zero_v3(cent);
-
-       /*simple (and stupid) median (average) based method :/ */
-
-       if (vertexCos) {
-               BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-                       add_v3_v3(cent, vertexCos[BM_elem_index_get(l->v)]);
-                       tot++;
-               }
-       }
-       else {
-               BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-                       add_v3_v3(cent, l->v->co);
-                       tot++;
-               }
-       }
-
-       if (tot == 0) return;
-       mul_v3_fl(cent, 1.0f / (float)tot);
-}
-
-static void emDM_foreachMappedFaceCenter(DerivedMesh *dm,
-                                         void (*func)(void *userData, int index, const float co[3], const float no[3]),
-                                         void *userData)
+static void emDM_foreachMappedFaceCenter(
+        DerivedMesh *dm,
+        void (*func)(void *userData, int index, const float co[3], const float no[3]),
+        void *userData,
+        DMForeachFlag flag)
 {
        EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
        BMesh *bm = bmdm->em->bm;
-       float (*polyNos)[3] = NULL;
+       const float (*polyNos)[3];
+       const float (*polyCos)[3];
        BMFace *efa;
        BMIter iter;
-       float cent[3];
        int i;
 
-       /* ensure for face center calculation */
-       if (bmdm->vertexCos) {
-               BM_mesh_elem_index_ensure(bm, BM_VERT);
-               polyNos = bmdm->polyNos;
+       emDM_ensurePolyCenters(bmdm);
+       polyCos = bmdm->polyCos;  /* always set */
 
-               BLI_assert(polyNos != NULL);
+       if (flag & DM_FOREACH_USE_NORMAL) {
+               emDM_ensurePolyNormals(bmdm);
+               polyNos = bmdm->polyNos;  /* maybe NULL */
+       }
+       else {
+               polyNos = NULL;
        }
 
-       BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
-               emDM__calcFaceCent(efa, cent, bmdm->vertexCos);
-               func(userData, i, cent, polyNos ? polyNos[i] : efa->no);
+       if (polyNos) {
+               BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
+                       const float *no = polyNos[i];
+                       func(userData, i, polyCos[i], no);
+               }
+       }
+       else {
+               BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
+                       const float *no = (flag & DM_FOREACH_USE_NORMAL) ? efa->no : NULL;
+                       func(userData, i, polyCos[i], no);
+               }
        }
 }
 
@@ -349,10 +459,20 @@ static void emDM_drawMappedFaces(DerivedMesh *dm,
 
        if (bmdm->vertexCos) {
                /* add direct access */
-               float (*vertexCos)[3] = bmdm->vertexCos;
-               float (*vertexNos)[3] = bmdm->vertexNos;
-               float (*polyNos)[3]   = bmdm->polyNos;
-               // int *triPolyMap = bmdm->triPolyMap;
+               const float (*vertexCos)[3] = bmdm->vertexCos;
+               const float (*vertexNos)[3];
+               const float (*polyNos)[3];
+
+               if (skip_normals) {
+                       vertexNos = NULL;
+                       polyNos = NULL;
+               }
+               else {
+                       emDM_ensureVertNormals(bmdm);
+                       emDM_ensurePolyNormals(bmdm);
+                       vertexNos = bmdm->vertexNos;
+                       polyNos = bmdm->polyNos;
+               }
 
                BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
 
@@ -561,9 +681,6 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
        BMEditMesh *em = bmdm->em;
        BMesh *bm = em->bm;
        struct BMLoop *(*looptris)[3] = em->looptris;
-       float (*vertexCos)[3] = bmdm->vertexCos;
-       float (*vertexNos)[3] = bmdm->vertexNos;
-       float (*polyNos)[3]   = bmdm->polyNos;
        BMFace *efa;
        MLoopUV *luv[3], dummyluv = {{0}};
        MLoopCol *lcol[3] = {NULL} /* , dummylcol = {0} */;
@@ -593,7 +710,17 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
                BM_mesh_elem_index_ensure(bm, BM_VERT);
        }
 
-       if (vertexCos) {
+       if (bmdm->vertexCos) {
+               /* add direct access */
+               const float (*vertexCos)[3] = bmdm->vertexCos;
+               const float (*vertexNos)[3];
+               const float (*polyNos)[3];
+
+               emDM_ensureVertNormals(bmdm);
+               emDM_ensurePolyNormals(bmdm);
+               vertexNos = bmdm->vertexNos;
+               polyNos = bmdm->polyNos;
+
                BM_mesh_elem_index_ensure(bm, BM_VERT);
 
                for (i = 0; i < em->tottri; i++) {
@@ -791,9 +918,11 @@ static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
        BMEditMesh *em = bmdm->em;
        BMesh *bm = em->bm;
        struct BMLoop *(*looptris)[3] = em->looptris;
-       float (*vertexCos)[3] = bmdm->vertexCos;
-       float (*vertexNos)[3] = bmdm->vertexNos;
-       float (*polyNos)[3]   = bmdm->polyNos;
+       /* add direct access */
+       const float (*vertexCos)[3] = bmdm->vertexCos;
+       const float (*vertexNos)[3];
+       const float (*polyNos)[3];
+
        BMFace *efa;
        DMVertexAttribs attribs;
        GPUVertexAttribs gattribs;
@@ -805,6 +934,11 @@ static void emDM_drawMappedFacesGLSL(DerivedMesh *dm,
 
        memset(&attribs, 0, sizeof(attribs));
 
+       emDM_ensureVertNormals(bmdm);
+       emDM_ensurePolyNormals(bmdm);
+       vertexNos = bmdm->vertexNos;
+       polyNos = bmdm->polyNos;
+
        /* always use smooth shading even for flat faces, else vertex colors wont interpolate */
        glShadeModel(GL_SMOOTH);
        BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
@@ -926,9 +1060,9 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm,
        BMEditMesh *em = bmdm->em;
        BMesh *bm = em->bm;
        struct BMLoop *(*looptris)[3] = em->looptris;
-       float (*vertexCos)[3] = bmdm->vertexCos;
-       float (*vertexNos)[3] = bmdm->vertexNos;
-       float (*polyNos)[3]   = bmdm->polyNos;
+       const float (*vertexCos)[3] = bmdm->vertexCos;
+       const float (*vertexNos)[3];
+       const float (*polyNos)[3];
        BMFace *efa;
        DMVertexAttribs attribs = {{{0}}};
        GPUVertexAttribs gattribs;
@@ -936,6 +1070,12 @@ static void emDM_drawMappedFacesMat(DerivedMesh *dm,
 
        matnr = -1;
 
+       emDM_ensureVertNormals(bmdm);
+       emDM_ensurePolyNormals(bmdm);
+
+       vertexNos = bmdm->vertexNos;
+       polyNos = bmdm->polyNos;
+
        /* always use smooth shading even for flat faces, else vertex colors wont interpolate */
        glShadeModel(GL_SMOOTH);
 
@@ -1139,7 +1279,9 @@ static void emDM_getVertNo(DerivedMesh *dm, int index, float r_no[3])
                return;
        }
 
-       if (bmdm->vertexNos) {
+
+       if (bmdm->vertexCos) {
+               emDM_ensureVertNormals(bmdm);
                copy_v3_v3(r_no, bmdm->vertexNos[index]);
        }
        else {
@@ -1159,7 +1301,8 @@ static void emDM_getPolyNo(DerivedMesh *dm, int index, float r_no[3])
                return;
        }
 
-       if (bmdm->polyNos) {
+       if (bmdm->vertexCos) {
+               emDM_ensurePolyNormals(bmdm);
                copy_v3_v3(r_no, bmdm->polyNos[index]);
        }
        else {
@@ -1313,18 +1456,19 @@ static void emDM_copyLoopArray(DerivedMesh *dm, MLoop *r_loop)
 {
        EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
        BMesh *bm = bmdm->em->bm;
-       BMIter iter, liter;
+       BMIter iter;
        BMFace *efa;
-       BMLoop *l;
 
        BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE);
 
        BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
-               BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-                       r_loop->v = BM_elem_index_get(l->v);
-                       r_loop->e = BM_elem_index_get(l->e);
+               BMLoop *l_iter, *l_first;
+               l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
+               do {
+                       r_loop->v = BM_elem_index_get(l_iter->v);
+                       r_loop->e = BM_elem_index_get(l_iter->e);
                        r_loop++;
-               }
+               } while ((l_iter = l_iter->next) != l_first);
        }
 }
 
@@ -1439,8 +1583,16 @@ static void emDM_release(DerivedMesh *dm)
        if (DM_release(dm)) {
                if (bmdm->vertexCos) {
                        MEM_freeN(bmdm->vertexCos);
-                       MEM_freeN(bmdm->vertexNos);
-                       MEM_freeN(bmdm->polyNos);
+                       if (bmdm->vertexNos) {
+                               MEM_freeN(bmdm->vertexNos);
+                       }
+                       if (bmdm->polyNos) {
+                               MEM_freeN(bmdm->polyNos);
+                       }
+               }
+
+               if (bmdm->polyCos) {
+                       MEM_freeN(bmdm->polyCos);
                }
 
                MEM_freeN(bmdm);
@@ -1549,7 +1701,7 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em,
 
        bmdm->dm.release = emDM_release;
 
-       bmdm->vertexCos = vertexCos;
+       bmdm->vertexCos = (const float (*)[3])vertexCos;
        bmdm->dm.deformedOnly = (vertexCos != NULL);
 
        if (cd_dvert_offset != -1) {
@@ -1578,38 +1730,6 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em,
                }
        }
 
-       if (vertexCos) {
-               BMFace *efa;
-               BMVert *eve;
-               BMIter fiter;
-               BMIter viter;
-               int i;
-
-               BM_mesh_elem_index_ensure(bm, BM_VERT);
-
-               bmdm->vertexNos = MEM_callocN(sizeof(*bmdm->vertexNos) * bm->totvert, "bmdm_vno");
-               bmdm->polyNos = MEM_mallocN(sizeof(*bmdm->polyNos) * bm->totface, "bmdm_pno");
-
-               BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
-                       BM_elem_index_set(efa, i); /* set_inline */
-                       BM_face_normal_update_vcos(bm, efa, bmdm->polyNos[i], (float const (*)[3])vertexCos);
-               }
-               bm->elem_index_dirty &= ~BM_FACE;
-
-               BM_ITER_MESH_INDEX (eve, &viter, bm, BM_VERTS_OF_MESH, i) {
-                       float *no = bmdm->vertexNos[i];
-                       BM_ITER_ELEM (efa, &fiter, eve, BM_FACES_OF_VERT) {
-                               add_v3_v3(no, bmdm->polyNos[BM_elem_index_get(efa)]);
-                       }
-
-                       /* following Mesh convention; we use vertex coordinate itself
-                        * for normal in this case */
-                       if (UNLIKELY(normalize_v3(no) == 0.0f)) {
-                               normalize_v3_v3(no, vertexCos[i]);
-                       }
-               }
-       }
-
        return (DerivedMesh *)bmdm;
 }
 
@@ -1877,7 +1997,7 @@ static void statvis_calc_intersect(
 
 static void statvis_calc_distort(
         BMEditMesh *em,
-        const float (*vertexCos)[3],
+        const float (*vertexCos)[3], const float (*polyNos)[3],
         /* values for calculating */
         const float min, const float max,
         /* result */
@@ -1886,7 +2006,7 @@ static void statvis_calc_distort(
        BMIter iter;
        BMesh *bm = em->bm;
        BMFace *f;
-       float f_no[3];
+       const float *f_no;
        int index;
        const float minmax_irange = 1.0f / (max - min);
 
@@ -1903,10 +2023,10 @@ static void statvis_calc_distort(
                else {
                        BMLoop *l_iter, *l_first;
                        if (vertexCos) {
-                               BM_face_normal_update_vcos(bm, f, f_no, vertexCos);
+                               f_no = polyNos[index];
                        }
                        else {
-                               copy_v3_v3(f_no, f->no);
+                               f_no = f->no;
                        }
 
                        fac = 0.0f;
@@ -2006,7 +2126,7 @@ void BKE_editmesh_statvis_calc(BMEditMesh *em, DerivedMesh *dm,
                {
                        BKE_editmesh_color_ensure(em, BM_FACE);
                        statvis_calc_overhang(
-                                   em, bmdm ? (const float (*)[3])bmdm->polyNos : NULL,
+                                   em, bmdm ? bmdm->polyNos : NULL,
                                    statvis->overhang_min / (float)M_PI,
                                    statvis->overhang_max / (float)M_PI,
                                    statvis->overhang_axis,
@@ -2018,7 +2138,7 @@ void BKE_editmesh_statvis_calc(BMEditMesh *em, DerivedMesh *dm,
                        const float scale = 1.0f / mat4_to_scale(em->ob->obmat);
                        BKE_editmesh_color_ensure(em, BM_FACE);
                        statvis_calc_thickness(
-                                   em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
+                                   em, bmdm ? bmdm->vertexCos : NULL,
                                    statvis->thickness_min * scale,
                                    statvis->thickness_max * scale,
                                    statvis->thickness_samples,
@@ -2029,15 +2149,19 @@ void BKE_editmesh_statvis_calc(BMEditMesh *em, DerivedMesh *dm,
                {
                        BKE_editmesh_color_ensure(em, BM_FACE);
                        statvis_calc_intersect(
-                                   em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
+                                   em, bmdm ? bmdm->vertexCos : NULL,
                                    em->derivedFaceColor);
                        break;
                }
                case SCE_STATVIS_DISTORT:
                {
                        BKE_editmesh_color_ensure(em, BM_FACE);
+
+                       if (bmdm)
+                               emDM_ensurePolyNormals(bmdm);
+
                        statvis_calc_distort(
-                               em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
+                               em, bmdm ? bmdm->vertexCos : NULL, bmdm ? bmdm->polyNos : NULL,
                                statvis->distort_min,
                                statvis->distort_max,
                                em->derivedFaceColor);
@@ -2047,7 +2171,7 @@ void BKE_editmesh_statvis_calc(BMEditMesh *em, DerivedMesh *dm,
                {
                        BKE_editmesh_color_ensure(em, BM_VERT);
                        statvis_calc_sharp(
-                               em, bmdm ? (const float (*)[3])bmdm->vertexCos : NULL,
+                               em, bmdm ? bmdm->vertexCos : NULL,
                                statvis->sharp_min,
                                statvis->sharp_max,
                                /* in this case they are vertex colors */
@@ -2065,7 +2189,7 @@ void BKE_editmesh_statvis_calc(BMEditMesh *em, DerivedMesh *dm,
 struct CageUserData {
        int totvert;
        float (*cos_cage)[3];
-       BLI_bitmap visit_bitmap;
+       BLI_bitmap *visit_bitmap;
 };
 
 static void cage_mapped_verts_callback(void *userData, int index, const float co[3],
@@ -2082,7 +2206,7 @@ static void cage_mapped_verts_callback(void *userData, int index, const float co
 float (*BKE_editmesh_vertexCos_get(BMEditMesh *em, Scene *scene, int *r_numVerts))[3]
 {
        DerivedMesh *cage, *final;
-       BLI_bitmap visit_bitmap;
+       BLI_bitmap *visit_bitmap;
        struct CageUserData data;
        float (*cos_cage)[3];
 
@@ -2097,7 +2221,7 @@ float (*BKE_editmesh_vertexCos_get(BMEditMesh *em, Scene *scene, int *r_numVerts
        data.cos_cage = cos_cage;
        data.visit_bitmap = visit_bitmap;
 
-       cage->foreachMappedVert(cage, cage_mapped_verts_callback, &data);
+       cage->foreachMappedVert(cage, cage_mapped_verts_callback, &data, DM_FOREACH_NOP);
 
        MEM_freeN(visit_bitmap);
 
index 3e925b7311628154ac2401cbec8ee911b8e90af3..74cd8834d5d7b47e07c0a93b7f6bddf49df89be7 100644 (file)
@@ -373,5 +373,6 @@ void BKE_editmesh_color_ensure(BMEditMesh *em, const char htype)
                        break;
                default:
                        BLI_assert(0);
+                       break;
        }
 }
index 55a312f31ba9a384e61ec3f4a2e5e71871dee515..791c47cc551f335192ea33ddc50e4598a1365953 100644 (file)
@@ -1764,6 +1764,7 @@ static float evaluate_driver(ChannelDriver *driver, const float evaltime)
                         *      This is currently used as the mechanism which allows animated settings to be able
                         *  to be changed via the UI.
                         */
+                       break;
                }
        }
        
index 234f8667632b1db20875c0376d79985a91d0333d..915c75a0e7f003e2fdfaf07f09ea53f9279dc51f 100644 (file)
@@ -343,6 +343,8 @@ static void fcm_fn_generator_evaluate(FCurve *UNUSED(fcu), FModifier *fcm, float
                }
                default:
                        printf("Invalid Function-Generator for F-Modifier - %d\n", data->type);
+                       break;
+
        }
        
        /* execute function callback to set value if appropriate */
index f60823edcc8de75659e492734c0953ad19d44526..f20506af9676055bece8822395993483240602ac 100644 (file)
@@ -445,6 +445,7 @@ void IDP_SyncGroupValues(IDProperty *dest, IDProperty *src)
 
                                        IDP_FreeProperty(tmp);
                                        MEM_freeN(tmp);
+                                       break;
                                }
                        }
                }
@@ -709,9 +710,7 @@ int IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const int is_s
                        if (prop1->len == prop2->len && prop1->subtype == prop2->subtype) {
                                return memcmp(IDP_Array(prop1), IDP_Array(prop2), idp_size_table[(int)prop1->subtype] * prop1->len);
                        }
-                       else {
-                               return 0;
-                       }
+                       return 0;
                case IDP_GROUP:
                {
                        IDProperty *link1, *link2;
@@ -813,9 +812,7 @@ IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *n
                                prop->len = prop->totallen = val->array.len;
                                break;
                        }
-                       else {
-                               return NULL;
-                       }
+                       return NULL;
                }
                case IDP_STRING:
                {
@@ -911,5 +908,6 @@ void IDP_UnlinkProperty(IDProperty *prop)
        switch (prop->type) {
                case IDP_ID:
                        IDP_UnlinkID(prop);
+                       break;
        }
 }
index 135d847cce7c8a48f9e8840da11b349a5ff776cc..1a444d497a04791c8ec9ec7fcf00aa1a28c02676 100644 (file)
@@ -695,6 +695,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
                        break;
                default:
                        BKE_image_buf_fill_color(rect, rect_float, width, height, color);
+                       break;
        }
 
        if (rect_float) {
@@ -1120,6 +1121,7 @@ char BKE_imtype_valid_channels(const char imtype)
                case R_IMF_IMTYPE_QUICKTIME:
                case R_IMF_IMTYPE_DPX:
                        chan_flag |= IMA_CHAN_FLAG_ALPHA;
+                       break;
        }
 
        /* bw */
@@ -1131,6 +1133,7 @@ char BKE_imtype_valid_channels(const char imtype)
                case R_IMF_IMTYPE_TIFF:
                case R_IMF_IMTYPE_IRIS:
                        chan_flag |= IMA_CHAN_FLAG_BW;
+                       break;
        }
 
        return chan_flag;
index 4dc1e9be7edd4eeec7f8fa6fd877620e66cbd449..7eb4a3a2a8d7ebe9670d4c9e3e13d046df383f22 100644 (file)
@@ -1057,6 +1057,7 @@ void free_main(Main *mainvar)
                                case  32: BKE_libblock_free(lb, id); break;
                                default:
                                        BLI_assert(0);
+                                       break;
                        }
 #endif
                }
index b3c5ceefb2d53bf655c8d5494ad0eb528207db68..21e7fb3116e92c3d9a7f95cd380d291b82842f12 100644 (file)
@@ -939,8 +939,6 @@ void BKE_mask_free(Main *bmain, Mask *mask)
        SpaceLink *sl;
        Scene *scene;
 
-       BKE_sequencer_clear_mask_in_clipboard(mask);
-
        for (scr = bmain->screen.first; scr; scr = scr->id.next) {
                for (area = scr->areabase.first; area; area = area->next) {
                        for (sl = area->spacedata.first; sl; sl = sl->next) {
index e14b51975c8e19682fdde4ec44096b7d9c6b0f8a..300beae1078ea0462b95c565bcd23635206946e8 100644 (file)
@@ -1148,55 +1148,6 @@ void material_drivers_update(Scene *scene, Material *ma, float ctime)
 
        ma->id.flag &= ~LIB_DOIT;
 }
-       
-/* ****************** */
-#if 0 /* UNUSED */
-static char colname_array[125][20] = {
-"Black", "DarkRed", "HalfRed", "Red", "Red",
-"DarkGreen", "DarkOlive", "Brown", "Chocolate", "OrangeRed",
-"HalfGreen", "GreenOlive", "DryOlive", "Goldenrod", "DarkOrange",
-"LightGreen", "Chartreuse", "YellowGreen", "Yellow", "Gold",
-"Green", "LawnGreen", "GreenYellow", "LightOlive", "Yellow",
-"DarkBlue", "DarkPurple", "HotPink", "VioletPink", "RedPink",
-"SlateGray", "DarkGray", "PalePurple", "IndianRed", "Tomato",
-"SeaGreen", "PaleGreen", "GreenKhaki", "LightBrown", "LightSalmon",
-"SpringGreen", "PaleGreen", "MediumOlive", "YellowBrown", "LightGold",
-"LightGreen", "LightGreen", "LightGreen", "GreenYellow", "PaleYellow",
-"HalfBlue", "DarkSky", "HalfMagenta", "VioletRed", "DeepPink",
-"SteelBlue", "SkyBlue", "Orchid", "LightHotPink", "HotPink",
-"SeaGreen", "SlateGray", "MediumGray", "Burlywood", "LightPink",
-"SpringGreen", "Aquamarine", "PaleGreen", "Khaki", "PaleOrange",
-"SpringGreen", "SeaGreen", "PaleGreen", "PaleWhite", "YellowWhite",
-"LightBlue", "Purple", "MediumOrchid", "Magenta", "Magenta",
-"RoyalBlue", "SlateBlue", "MediumOrchid", "Orchid", "Magenta",
-"DeepSkyBlue", "LightSteelBlue", "LightSkyBlue", "Violet", "LightPink",
-"Cyan", "DarkTurquoise", "SkyBlue", "Gray", "Snow",
-"Mint", "Mint", "Aquamarine", "MintCream", "Ivory",
-"Blue", "Blue", "DarkMagenta", "DarkOrchid", "Magenta",
-"SkyBlue", "RoyalBlue", "LightSlateBlue", "MediumOrchid", "Magenta",
-"DodgerBlue", "SteelBlue", "MediumPurple", "PalePurple", "Plum",
-"DeepSkyBlue", "PaleBlue", "LightSkyBlue", "PalePurple", "Thistle",
-"Cyan", "ColdBlue", "PaleTurquoise", "GhostWhite", "White"
-};
-
-void automatname(Material *ma)
-{
-       int nr, r, g, b;
-       float ref;
-       
-       if (ma == NULL) return;
-       if (ma->mode & MA_SHLESS) ref = 1.0;
-       else ref = ma->ref;
-
-       r = (int)(4.99f * (ref * ma->r));
-       g = (int)(4.99f * (ref * ma->g));
-       b = (int)(4.99f * (ref * ma->b));
-       nr = r + 5 * g + 25 * b;
-       if (nr > 124) nr = 124;
-       new_id(&G.main->mat, (ID *)ma, colname_array[nr]);
-       
-}
-#endif
 
 int object_remove_material_slot(Object *ob)
 {
index b7257028316a6e509d3cdb157f7ee03cebcbd153..a94daed11e3fbc190f3290f32160c52cff983d0b 100644 (file)
@@ -37,7 +37,6 @@
 #include "BLI_array.h"
 
 #include "BKE_DerivedMesh.h"
-#include "BKE_bmesh.h"
 #include "BKE_editmesh.h"
 
 /* Static function for alloc */
index ef3b7ca0bdf7fbe6e23754df8ab1b72228c006e1..e8550e12e4f29a129e89bd7d4c668ee3b4c92d64 100644 (file)
@@ -1395,8 +1395,6 @@ void BKE_movieclip_build_proxy_frame_for_ibuf(MovieClip *clip, ImBuf *ibuf, stru
 
 void BKE_movieclip_free(MovieClip *clip)
 {
-       BKE_sequencer_clear_movieclip_in_clipboard(clip);
-
        free_buffers(clip);
 
        BKE_tracking_free(&clip->tracking);
index cba4c9206c948d07c5a33ea1968d2ef5b280281f..95bf56d00f2969ca30122b6077015e491ecc67f2 100644 (file)
@@ -105,15 +105,15 @@ void multires_customdata_delete(Mesh *me)
 }
 
 /** Grid hiding **/
-static BLI_bitmap multires_mdisps_upsample_hidden(BLI_bitmap lo_hidden,
-                                                  int lo_level,
-                                                  int hi_level,
+static BLI_bitmap *multires_mdisps_upsample_hidden(BLI_bitmap *lo_hidden,
+                                                   int lo_level,
+                                                   int hi_level,
 
-                                                  /* assumed to be at hi_level (or
-                                                   *  null) */
-                                                  BLI_bitmap prev_hidden)
+                                                   /* assumed to be at hi_level (or
+                                                    *  null) */
+                                                   BLI_bitmap *prev_hidden)
 {
-       BLI_bitmap subd;
+       BLI_bitmap *subd;
        int hi_gridsize = ccg_gridsize(hi_level);
        int lo_gridsize = ccg_gridsize(lo_level);
        int yh, xh, xl, yl, xo, yo, hi_ndx;
@@ -168,11 +168,11 @@ static BLI_bitmap multires_mdisps_upsample_hidden(BLI_bitmap lo_hidden,
        return subd;
 }
 
-static BLI_bitmap multires_mdisps_downsample_hidden(BLI_bitmap old_hidden,
-                                                    int old_level,
-                                                    int new_level)
+static BLI_bitmap *multires_mdisps_downsample_hidden(BLI_bitmap *old_hidden,
+                                                     int old_level,
+                                                     int new_level)
 {
-       BLI_bitmap new_hidden;
+       BLI_bitmap *new_hidden;
        int new_gridsize = ccg_gridsize(new_level);
        int old_gridsize = ccg_gridsize(old_level);
        int x, y, factor, old_value;
@@ -200,7 +200,7 @@ static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm,
                                             Mesh *me, int level)
 {
        const MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
-       BLI_bitmap *grid_hidden = ccgdm->gridHidden;
+       BLI_bitmap **grid_hidden = ccgdm->gridHidden;
        int *gridOffset;
        int i, j;
        
@@ -210,7 +210,7 @@ static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm,
                for (j = 0; j < me->mpoly[i].totloop; j++) {
                        int g = gridOffset[i] + j;
                        const MDisps *md = &mdisps[g];
-                       BLI_bitmap gh = md->hidden;
+                       BLI_bitmap *gh = md->hidden;
                        
                        if (gh) {
                                grid_hidden[g] =
@@ -224,7 +224,7 @@ static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm,
  * the current level of md.hidden) */
 static void multires_mdisps_subdivide_hidden(MDisps *md, int new_level)
 {
-       BLI_bitmap subd;
+       BLI_bitmap *subd;
        
        BLI_assert(md->hidden);
 
@@ -647,7 +647,7 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl)
 
                                        multires_copy_grid(ndisps, hdisps, nsize, hsize);
                                        if (mdisp->hidden) {
-                                               BLI_bitmap gh =
+                                               BLI_bitmap *gh =
                                                    multires_mdisps_downsample_hidden(mdisp->hidden,
                                                                                      mdisp->level,
                                                                                      lvl);
@@ -1251,7 +1251,7 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm)
 void multires_modifier_update_hidden(DerivedMesh *dm)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
-       BLI_bitmap *grid_hidden = ccgdm->gridHidden;
+       BLI_bitmap **grid_hidden = ccgdm->gridHidden;
        Mesh *me = ccgdm->multires.ob->data;
        MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
        int totlvl = ccgdm->multires.totlvl;
@@ -1262,7 +1262,7 @@ void multires_modifier_update_hidden(DerivedMesh *dm)
                
                for (i = 0; i < me->totloop; i++) {
                        MDisps *md = &mdisps[i];
-                       BLI_bitmap gh = grid_hidden[i];
+                       BLI_bitmap *gh = grid_hidden[i];
 
                        if (!gh && md->hidden) {
                                MEM_freeN(md->hidden);
index 1df644318244c88dacf6f2ed2246e1c92909c12b..daa57afe14e4e44260f92a5d69abaaceb2fe961d 100644 (file)
@@ -1614,6 +1614,7 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
 
                        if (use_compat) mat3_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, tmat);
                        else            mat3_to_eulO(ob->rot, ob->rotmode, tmat);
+                       break;
                }
        }
 }
index f97429d7e650be6bbe27beb93a6a8d076819cafc..11d58c945fd0491c71e72f5942a1b984897ca076 100644 (file)
@@ -85,6 +85,7 @@ int seekPackedFile(PackedFile *pf, int offset, int whence)
                                break;
                        default:
                                oldseek = -1;
+                               break;
                }
                if (seek < 0) {
                        seek = 0;
@@ -448,7 +449,8 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na
                                        temp = local_name;
                                        break;
                                }
-                       /* else fall through and create it */
+                               /* else create it */
+                               /* fall-through */
                        case PF_WRITE_LOCAL:
                                if (writePackedFile(reports, local_name, pf, 1) == RET_OK) {
                                        temp = local_name;
@@ -461,7 +463,8 @@ char *unpackFile(ReportList *reports, const char *abs_name, const char *local_na
                                        temp = abs_name;
                                        break;
                                }
-                       /* else fall through and create it */
+                               /* else create it */
+                               /* fall-through */
                        case PF_WRITE_ORIGINAL:
                                if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) {
                                        temp = abs_name;
index 0dbe4c56a09358b05524ede9dfd9b983d2694e68..b47a493581ef9abea1a7dd1b99d7ea81515a0e81 100644 (file)
@@ -139,8 +139,7 @@ Paint *BKE_paint_get_active(Scene *sce)
                                case OB_MODE_EDIT:
                                        if (ts->use_uv_sculpt)
                                                return &ts->uvsculpt->paint;
-                                       else
-                                               return &ts->imapaint.paint;
+                                       return &ts->imapaint.paint;
                        }
                }
 
@@ -187,8 +186,7 @@ Paint *BKE_paint_get_active_from_context(const bContext *C)
                                case OB_MODE_EDIT:
                                        if (ts->use_uv_sculpt)
                                                return &ts->uvsculpt->paint;
-                                       else
-                                               return &ts->imapaint.paint;
+                                       return &ts->imapaint.paint;
                                default:
                                        return &ts->imapaint.paint;
                        }
@@ -238,8 +236,7 @@ PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
                                case OB_MODE_EDIT:
                                        if (ts->use_uv_sculpt)
                                                return PAINT_SCULPT_UV;
-                                       else
-                                               return PAINT_TEXTURE_2D;
+                                       return PAINT_TEXTURE_2D;
                                default:
                                        return PAINT_TEXTURE_2D;
                        }
index 99e6e898685cc63b20294019f251d080b4aaa67a..a0cc37dcf3f676c2788bcb45da060512fe3f07d8 100644 (file)
@@ -538,7 +538,7 @@ void BKE_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int
 
 /* Do a full rebuild with on Grids data structure */
 void BKE_pbvh_build_grids(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj,
-                          int totgrid, CCGKey *key, void **gridfaces, DMFlagMat *flagmats, BLI_bitmap *grid_hidden)
+                          int totgrid, CCGKey *key, void **gridfaces, DMFlagMat *flagmats, BLI_bitmap **grid_hidden)
 {
        BBC *prim_bbc = NULL;
        BB cb;
@@ -1253,7 +1253,7 @@ void BKE_pbvh_bounding_box(const PBVH *bvh, float min[3], float max[3])
        }
 }
 
-BLI_bitmap *BKE_pbvh_grid_hidden(const PBVH *bvh)
+BLI_bitmap **BKE_pbvh_grid_hidden(const PBVH *bvh)
 {
        BLI_assert(bvh->type == PBVH_GRIDS);
        return bvh->grid_hidden;
@@ -1469,7 +1469,7 @@ static int pbvh_grids_node_raycast(PBVH *bvh, PBVHNode *node,
 
        for (i = 0; i < totgrid; ++i) {
                CCGElem *grid = bvh->grids[node->prim_indices[i]];
-               BLI_bitmap gh;
+               BLI_bitmap *gh;
 
                if (!grid)
                        continue;
@@ -1664,7 +1664,7 @@ void BKE_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
 }
 
 void BKE_pbvh_grids_update(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, void **gridfaces,
-                           DMFlagMat *flagmats, BLI_bitmap *grid_hidden)
+                           DMFlagMat *flagmats, BLI_bitmap **grid_hidden)
 {
        int a;
 
index c6a5552dbf78de2bfc806d2743e0a0fc77a21b30..cd21f8ad96805fa1a1a51aa4e8a4cb1d769cace3 100644 (file)
@@ -294,7 +294,7 @@ static BMVert *pbvh_bmesh_vert_create(PBVH *bvh, int node_index,
 
 static BMFace *pbvh_bmesh_face_create(PBVH *bvh, int node_index,
                                       BMVert *v_tri[3], BMEdge *e_tri[3],
-                                      const BMFace *UNUSED(example))
+                                      const BMFace *f_example)
 {
        BMFace *f;
        void *val = SET_INT_IN_POINTER(node_index);
@@ -302,9 +302,10 @@ static BMFace *pbvh_bmesh_face_create(PBVH *bvh, int node_index,
        /* ensure we never add existing face */
        BLI_assert(BM_face_exists(v_tri, 3, NULL) == false);
 
-       /* Note: passing NULL for the 'example' parameter, profiling shows
-        * a small performance bump */
        f = BM_face_create(bvh->bm, v_tri, e_tri, 3, 0);
+       // BM_elem_attrs_copy(bvh->bm, bvh->bm, f_example, f);
+       f->mat_nr = f_example->mat_nr;
+
        if (!BLI_ghash_haskey(bvh->bm_face_to_node, f)) {
 
                BLI_ghash_insert(bvh->nodes[node_index].bm_faces, f, NULL);
index b3f7bf6e3d16f58a90af71b28bcd430dfef0a69f..4154b8e4799e4def4037729f6dec4d831c26330d 100644 (file)
@@ -139,11 +139,11 @@ struct PBVH {
        void **gridfaces;
        const DMFlagMat *grid_flag_mats;
        int totgrid;
-       BLI_bitmap *grid_hidden;
+       BLI_bitmap **grid_hidden;
 
        /* Only used during BVH build and update,
         * don't need to remain valid after */
-       BLI_bitmap vert_bitmap;
+       BLI_bitmap *vert_bitmap;
 
 #ifdef PERFCNTRS
        int perf_modified;
index ec23a7db8a1bfbb981ae70ff2a4d41e551b6c491..73f2a864e32ac296b8e056410ea89da9405be937 100644 (file)
@@ -177,9 +177,9 @@ void BKE_bproperty_unique(bProperty *first, bProperty *prop, int force)
                        i = 0;
 
                        do { /* ensure we have enough chars for the new number in the name */
-                               BLI_snprintf(num, sizeof(num), "%d", i++);
-                               BLI_strncpy(new_name, base_name, sizeof(prop->name) - strlen(num));
-                               strcat(new_name, num);
+                               const size_t num_len = BLI_snprintf(num, sizeof(num), "%d", i++);
+                               BLI_snprintf(new_name, sizeof(prop->name),
+                                            "%.*s%s", (int)(sizeof(prop->name) - num_len), base_name, num);
                        } while (bproperty_get(first, prop, new_name));
 
                        BLI_strncpy(prop->name, new_name, sizeof(prop->name));
index a300e2f21562875b8b2cb8e1f76a82ac995a7d97..f32769923815037a714e7740ee3328133478c970 100644 (file)
@@ -288,18 +288,18 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
                        for (i = 0; (i < totface) && (mface) && (mvert); i++, mface++) {
                                /* add first triangle - verts 1,2,3 */
                                {
-                                       MVert *va = (IN_RANGE(mface->v1, 0, totvert)) ? (mvert + mface->v1) : (mvert);
-                                       MVert *vb = (IN_RANGE(mface->v2, 0, totvert)) ? (mvert + mface->v2) : (mvert);
-                                       MVert *vc = (IN_RANGE(mface->v3, 0, totvert)) ? (mvert + mface->v3) : (mvert);
+                                       MVert *va = (mface->v1 < totvert) ? (mvert + mface->v1) : (mvert);
+                                       MVert *vb = (mface->v2 < totvert) ? (mvert + mface->v2) : (mvert);
+                                       MVert *vc = (mface->v3 < totvert) ? (mvert + mface->v3) : (mvert);
 
                                        RB_trimesh_add_triangle(mdata, va->co, vb->co, vc->co);
                                }
 
                                /* add second triangle if needed - verts 1,3,4 */
                                if (mface->v4) {
-                                       MVert *va = (IN_RANGE(mface->v1, 0, totvert)) ? (mvert + mface->v1) : (mvert);
-                                       MVert *vb = (IN_RANGE(mface->v3, 0, totvert)) ? (mvert + mface->v3) : (mvert);
-                                       MVert *vc = (IN_RANGE(mface->v4, 0, totvert)) ? (mvert + mface->v4) : (mvert);
+                                       MVert *va = (mface->v1 < totvert) ? (mvert + mface->v1) : (mvert);
+                                       MVert *vb = (mface->v3 < totvert) ? (mvert + mface->v3) : (mvert);
+                                       MVert *vc = (mface->v4 < totvert) ? (mvert + mface->v4) : (mvert);
 
                                        RB_trimesh_add_triangle(mdata, va->co, vb->co, vc->co);
                                }
@@ -602,7 +602,7 @@ void BKE_rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, shor
                                        RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->spring_damping_z);
 
                                        RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint);
-                               /* fall through */
+                                       /* fall-through */
                                case RBC_TYPE_6DOF:
                                        if (rbc->type == RBC_TYPE_6DOF) /* a litte awkward but avoids duplicate code for limits */
                                                rbc->physics_constraint = RB_constraint_new_6dof(loc, rot, rb1, rb2);
index b080cfcff2f63bdeb2d61f61e044bb303a62ed01..34b19e3f357163f8fe5ae603bedea37e6a24959a 100644 (file)
@@ -65,6 +65,7 @@
 #include "BKE_fcurve.h"
 #include "BKE_scene.h"
 #include "BKE_mask.h"
+#include "BKE_library.h"
 
 #include "RNA_access.h"
 
@@ -265,6 +266,7 @@ static void seq_free_clipboard_recursive(Sequence *seq_parent)
                seq_free_clipboard_recursive(seq);
        }
 
+       BKE_sequence_clipboard_pointers_free(seq_parent);
        BKE_sequence_free_ex(NULL, seq_parent, FALSE);
 }
 
@@ -279,6 +281,101 @@ void BKE_sequencer_free_clipboard(void)
        seqbase_clipboard.first = seqbase_clipboard.last = NULL;
 }
 
+/* -------------------------------------------------------------------- */
+/* Manage pointers in the clipboard.
+ * note that these pointers should _never_ be access in the sequencer,
+ * they are only for storage while in the clipboard
+ * notice 'newid' is used for temp pointer storage here, validate on access.
+ */
+#define ID_PT (*id_pt)
+static void seqclipboard_ptr_free(ID **id_pt)
+{
+       if (ID_PT) {
+               BLI_assert(ID_PT->newid != NULL);
+               MEM_freeN(ID_PT);
+               ID_PT = NULL;
+       }
+}
+static void seqclipboard_ptr_store(ID **id_pt)
+{
+       if (ID_PT) {
+               ID *id_prev = ID_PT;
+               ID_PT = MEM_dupallocN(ID_PT);
+               ID_PT->newid = id_prev;
+       }
+}
+static void seqclipboard_ptr_restore(Main *bmain, ID **id_pt)
+{
+       if (ID_PT) {
+               const ListBase *lb = which_libbase(bmain, GS(ID_PT->name));
+               void *id_restore;
+
+               BLI_assert(ID_PT->newid != NULL);
+               if (BLI_findindex(lb, (ID_PT)->newid) != -1) {
+                       /* the pointer is still valid */
+                       id_restore = (ID_PT)->newid;
+               }
+               else {
+                       /* the pointer of the same name still exists  */
+                       id_restore = BLI_findstring(lb, (ID_PT)->name + 2, offsetof(ID, name) + 2);
+               }
+
+               if (id_restore == NULL) {
+                       /* check for a data with the same filename */
+                       switch (GS(ID_PT->name)) {
+                               case ID_SO:
+                               {
+                                       id_restore = BLI_findstring(lb, ((bSound *)ID_PT)->name, offsetof(bSound, name));
+                                       if (id_restore == NULL) {
+                                               id_restore = sound_new_file(bmain, ((bSound *)ID_PT)->name);
+                                               (ID_PT)->newid = id_restore;  /* reuse next time */
+                                       }
+                                       break;
+                               }
+                               case ID_MC:
+                               {
+                                       id_restore = BLI_findstring(lb, ((MovieClip *)ID_PT)->name, offsetof(MovieClip, name));
+                                       if (id_restore == NULL) {
+                                               id_restore = BKE_movieclip_file_add(bmain, ((MovieClip *)ID_PT)->name);
+                                               (ID_PT)->newid = id_restore;  /* reuse next time */
+                                       }
+                                       break;
+                               }
+                       }
+               }
+
+               ID_PT = id_restore;
+       }
+}
+#undef ID_PT
+
+void BKE_sequence_clipboard_pointers_free(Sequence *seq)
+{
+       seqclipboard_ptr_free((ID **)&seq->scene);
+       seqclipboard_ptr_free((ID **)&seq->scene_camera);
+       seqclipboard_ptr_free((ID **)&seq->clip);
+       seqclipboard_ptr_free((ID **)&seq->mask);
+       seqclipboard_ptr_free((ID **)&seq->sound);
+}
+void BKE_sequence_clipboard_pointers_store(Sequence *seq)
+{
+       seqclipboard_ptr_store((ID **)&seq->scene);
+       seqclipboard_ptr_store((ID **)&seq->scene_camera);
+       seqclipboard_ptr_store((ID **)&seq->clip);
+       seqclipboard_ptr_store((ID **)&seq->mask);
+       seqclipboard_ptr_store((ID **)&seq->sound);
+}
+void BKE_sequence_clipboard_pointers_restore(Sequence *seq, Main *bmain)
+{
+       seqclipboard_ptr_restore(bmain, (ID **)&seq->scene);
+       seqclipboard_ptr_restore(bmain, (ID **)&seq->scene_camera);
+       seqclipboard_ptr_restore(bmain, (ID **)&seq->clip);
+       seqclipboard_ptr_restore(bmain, (ID **)&seq->mask);
+       seqclipboard_ptr_restore(bmain, (ID **)&seq->sound);
+}
+/* end clipboard pointer mess */
+
+
 Editing *BKE_sequencer_editing_ensure(Scene *scene)
 {
        if (scene->ed == NULL) {
@@ -818,33 +915,6 @@ void BKE_sequencer_clear_scene_in_allseqs(Main *bmain, Scene *scene)
                        BKE_sequencer_base_recursive_apply(&scene_iter->ed->seqbase, clear_scene_in_allseqs_cb, scene);
                }
        }
-
-       /* also clear clipboard */
-       BKE_sequencer_base_recursive_apply(&seqbase_clipboard, clear_scene_in_allseqs_cb, scene);
-}
-
-static int clear_movieclip_in_clipboard_cb(Sequence *seq, void *arg_pt)
-{
-       if (seq->clip == (MovieClip *)arg_pt)
-               seq->clip = NULL;
-       return 1;
-}
-
-void BKE_sequencer_clear_movieclip_in_clipboard(MovieClip *clip)
-{
-       BKE_sequencer_base_recursive_apply(&seqbase_clipboard, clear_movieclip_in_clipboard_cb, clip);
-}
-
-static int clear_mask_in_clipboard_cb(Sequence *seq, void *arg_pt)
-{
-       if (seq->mask == (Mask *)arg_pt)
-               seq->mask = NULL;
-       return 1;
-}
-
-void BKE_sequencer_clear_mask_in_clipboard(Mask *mask)
-{
-       BKE_sequencer_base_recursive_apply(&seqbase_clipboard, clear_mask_in_clipboard_cb, mask);
 }
 
 typedef struct SeqUniqueInfo {
@@ -4245,6 +4315,12 @@ static Sequence *seq_dupli(Scene *scene, Scene *scene_to, Sequence *seq, int dup
                if (seq->scene_sound)
                        seqn->scene_sound = sound_scene_add_scene_sound_defaults(sce_audio, seqn);
        }
+       else if (seq->type == SEQ_TYPE_MOVIECLIP) {
+               /* avoid assert */
+       }
+       else if (seq->type == SEQ_TYPE_MASK) {
+               /* avoid assert */
+       }
        else if (seq->type == SEQ_TYPE_MOVIE) {
                seqn->strip->stripdata =
                        MEM_dupallocN(seq->strip->stripdata);
@@ -4256,7 +4332,7 @@ static Sequence *seq_dupli(Scene *scene, Scene *scene_to, Sequence *seq, int dup
                if (seq->scene_sound)
                        seqn->scene_sound = sound_add_scene_sound_defaults(sce_audio, seqn);
 
-               seqn->sound->id.us++;
+               id_us_plus((ID *)seqn->sound);
        }
        else if (seq->type == SEQ_TYPE_IMAGE) {
                seqn->strip->stripdata =
@@ -4278,7 +4354,8 @@ static Sequence *seq_dupli(Scene *scene, Scene *scene_to, Sequence *seq, int dup
 
        }
        else {
-               fprintf(stderr, "Aiiiiekkk! sequence type not handled in duplicate!\nExpect a crash now...\n");
+               /* sequence type not handled in duplicate! Expect a crash now... */
+               BLI_assert(0);
        }
 
        if (dupe_flag & SEQ_DUPE_UNIQUE_NAME)
index 26a5dada108e490299046d317b8ca256e433c3f9..cc33727030af0bcc7c8bf1b124273222785f55b8 100644 (file)
@@ -1505,7 +1505,8 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3])
 static void ccgDM_foreachMappedVert(
         DerivedMesh *dm,
         void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
-        void *userData)
+        void *userData,
+        DMForeachFlag flag)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
        CCGVertIterator *vi;
@@ -1514,11 +1515,13 @@ static void ccgDM_foreachMappedVert(
 
        for (vi = ccgSubSurf_getVertIterator(ccgdm->ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) {
                CCGVert *v = ccgVertIterator_getCurrent(vi);
-               CCGElem *vd = ccgSubSurf_getVertData(ccgdm->ss, v);
-               int index = ccgDM_getVertMapIndex(ccgdm->ss, v);
+               const int index = ccgDM_getVertMapIndex(ccgdm->ss, v);
 
-               if (index != -1)
-                       func(userData, index, CCG_elem_co(&key, vd), CCG_elem_no(&key, vd), NULL);
+               if (index != -1) {
+                       CCGElem *vd = ccgSubSurf_getVertData(ccgdm->ss, v);
+                       const float *no = (flag & DM_FOREACH_USE_NORMAL) ? CCG_elem_no(&key, vd) : NULL;
+                       func(userData, index, CCG_elem_co(&key, vd), no, NULL);
+               }
        }
 
        ccgVertIterator_free(vi);
@@ -1539,12 +1542,13 @@ static void ccgDM_foreachMappedEdge(
 
        for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) {
                CCGEdge *e = ccgEdgeIterator_getCurrent(ei);
-               CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
-               int index = ccgDM_getEdgeMapIndex(ss, e);
+               const int index = ccgDM_getEdgeMapIndex(ss, e);
 
                if (index != -1) {
-                       for (i = 0; i < edgeSize - 1; i++)
+                       CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
+                       for (i = 0; i < edgeSize - 1; i++) {
                                func(userData, index, CCG_elem_offset_co(&key, edgeData, i), CCG_elem_offset_co(&key, edgeData, i + 1));
+                       }
                }
        }
 
@@ -2530,7 +2534,8 @@ static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm,
 static void ccgDM_foreachMappedFaceCenter(
         DerivedMesh *dm,
         void (*func)(void *userData, int index, const float co[3], const float no[3]),
-        void *userData)
+        void *userData,
+        DMForeachFlag flag)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
        CCGSubSurf *ss = ccgdm->ss;
@@ -2541,13 +2546,13 @@ static void ccgDM_foreachMappedFaceCenter(
 
        for (fi = ccgSubSurf_getFaceIterator(ss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
                CCGFace *f = ccgFaceIterator_getCurrent(fi);
-               int index = ccgDM_getFaceMapIndex(ss, f);
+               const int index = ccgDM_getFaceMapIndex(ss, f);
 
                if (index != -1) {
                        /* Face center data normal isn't updated atm. */
                        CCGElem *vd = ccgSubSurf_getFaceGridData(ss, f, 0, 0, 0);
-
-                       func(userData, index, CCG_elem_co(&key, vd), CCG_elem_no(&key, vd));
+                       const float *no = (flag & DM_FOREACH_USE_NORMAL) ? CCG_elem_no(&key, vd) : NULL;
+                       func(userData, index, CCG_elem_co(&key, vd), no);
                }
        }
 
@@ -2925,7 +2930,7 @@ static void ccgdm_create_grids(DerivedMesh *dm)
        gridFaces = MEM_mallocN(sizeof(CCGFace *) * numGrids, "ccgdm.gridFaces");
        gridFlagMats = MEM_mallocN(sizeof(DMFlagMat) * numGrids, "ccgdm.gridFlagMats");
 
-       ccgdm->gridHidden = MEM_callocN(sizeof(BLI_bitmap) * numGrids, "ccgdm.gridHidden");
+       ccgdm->gridHidden = MEM_callocN(sizeof(*ccgdm->gridHidden) * numGrids, "ccgdm.gridHidden");
 
        for (gIndex = 0, index = 0; index < numFaces; index++) {
                CCGFace *f = ccgdm->faceMap[index].face;
@@ -2997,7 +3002,7 @@ static DMFlagMat *ccgDM_getGridFlagMats(DerivedMesh *dm)
        return ccgdm->gridFlagMats;
 }
 
-static BLI_bitmap *ccgDM_getGridHidden(DerivedMesh *dm)
+static BLI_bitmap **ccgDM_getGridHidden(DerivedMesh *dm)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
        
index aec924e15b3082667d3eb51cc22d0da814295f22..0daa9de3ae268100f2e22e12687def4e9639d5c8 100644 (file)
@@ -1496,6 +1496,7 @@ static int max_undo_test(Text *text, int x)
        return 1;
 }
 
+#if 0  /* UNUSED */
 static void dump_buffer(Text *text) 
 {
        int i = 0;
@@ -1607,6 +1608,7 @@ void txt_print_undo(Text *text)
                                        c_len = BLI_str_utf8_from_unicode(uc, c);
                                        c[c_len] = '\0';
                                        puts(c);
+                                       break;
                                }
                        }
                }
@@ -1659,6 +1661,7 @@ void txt_print_undo(Text *text)
                i++;
        }
 }
+#endif
 
 static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short value) 
 {
@@ -1850,6 +1853,7 @@ static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, s
                        /* should never happen */
                        BLI_assert(0);
                        unicode = 0;
+                       break;
        }
        
        return unicode;
@@ -1925,6 +1929,7 @@ static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, s
                        /* should never happen */
                        BLI_assert(0);
                        unicode = 0;
+                       break;
        }
        
        return unicode;
@@ -2013,10 +2018,7 @@ void txt_do_undo(Text *text)
                        buf[i] = 0;
 
                        /* skip over the length that was stored again */
-                       text->undo_pos--;
-                       text->undo_pos--;
-                       text->undo_pos--; 
-                       text->undo_pos--;
+                       text->undo_pos -= 4;
 
                        /* Get the cursor positions */
                        txt_undo_read_cursors(text->undo_buf, &text->undo_pos, &curln, &curc, &selln, &selc);
@@ -2050,10 +2052,7 @@ void txt_do_undo(Text *text)
                        MEM_freeN(buf);
                        
                        /* skip over the length that was stored again */
-                       text->undo_pos--;
-                       text->undo_pos--;
-                       text->undo_pos--;
-                       text->undo_pos--;
+                       text->undo_pos -= 4;
 
                        /* get and restore the cursors */
                        txt_undo_read_cursors(text->undo_buf, &text->undo_pos, &curln, &curc, &selln, &selc);
@@ -2204,10 +2203,7 @@ void txt_do_redo(Text *text)
                        text->undo_pos += linep;
 
                        /* skip over the length that was stored again */
-                       text->undo_pos++;
-                       text->undo_pos++;
-                       text->undo_pos++; 
-                       text->undo_pos++;
+                       text->undo_pos += 4;
                        
                        txt_delete_sel(text);
 
@@ -2233,10 +2229,7 @@ void txt_do_redo(Text *text)
                        MEM_freeN(buf);
 
                        /* skip over the length that was stored again */
-                       text->undo_pos++;
-                       text->undo_pos++;
-                       text->undo_pos++; 
-                       text->undo_pos++;
+                       text->undo_pos += 4;
 
                        break;
                        
@@ -2366,7 +2359,7 @@ static void txt_delete_line(Text *text, TextLine *line)
 
 static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb)
 {
-       char *tmp;
+       char *tmp, *s;
 
        if (!text) return;
        
@@ -2375,8 +2368,10 @@ static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb)
 
        tmp = MEM_mallocN(linea->len + lineb->len + 1, "textline_string");
        
-       strcpy(tmp, linea->line);
-       strcat(tmp, lineb->line);
+       s = tmp;
+       s += BLI_strcpy_rlen(s, linea->line);
+       s += BLI_strcpy_rlen(s, lineb->line);
+       (void)s;
 
        make_new_line(linea, tmp);
        
index 1d0b0deae7ed4c2d0445be8cc3e92cd4813f0233..e2b7358525ac449350c17adf070cdeec898e672e 100644 (file)
@@ -906,42 +906,6 @@ void BKE_texture_make_local(Tex *tex)
        }
 }
 
-/* ------------------------------------------------------------------------- */
-#if 0 /* UNUSED */
-void autotexname(Tex *tex)
-{
-       Main *bmain = G.main;
-       char texstr[20][15] = {"None", "Clouds", "Wood", "Marble", "Magic", "Blend",
-                                  "Stucci", "Noise", "Image", "EnvMap", "Musgrave",
-                                  "Voronoi", "DistNoise", "Point Density", "Voxel Data", "Ocean", "", "", ""};
-       Image *ima;
-       char di[FILE_MAXDIR], fi[FILE_MAXFILE];
-       
-       if (tex) {
-               if (tex->use_nodes) {
-                       new_id(&bmain->tex, (ID *)tex, "Noddy");
-               }
-               else if (tex->type == TEX_IMAGE) {
-                       ima = tex->ima;
-                       if (ima) {
-                               BLI_split_file_part(ima->name, fi, sizeof(fi));
-                               strcpy(di, "I.");
-                               strcat(di, fi);
-                               new_id(&bmain->tex, (ID *)tex, di);
-                       }
-                       else {
-                               new_id(&bmain->tex, (ID *)tex, texstr[tex->type]);
-                       }
-               }
-               else {
-                       new_id(&bmain->tex, (ID *)tex, texstr[tex->type]);
-               }
-       }
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
 Tex *give_current_object_texture(Object *ob)
 {
        Material *ma, *node_ma;
index 110d67b3d47d28a47fe971f9fb26fd4655ee4a56..538c98cc899367cbf23ab57d0eafebe36ef08659 100644 (file)
@@ -877,6 +877,7 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report
                        break;
                case FFMPEG_MP3:
                        fmt->audio_codec = CODEC_ID_MP3;
+                       /* fall-through */
                case FFMPEG_WAV:
                        fmt->video_codec = CODEC_ID_NONE;
                        break;
index 02e5d6bd79705df3fe5cc0d7ab88272bf2dedab6..ca98d28cc402167c50344a1f5ba0bc33c78b2ac4 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef __BLI_BITMAP_H__
 #define __BLI_BITMAP_H__
 
-typedef unsigned int *BLI_bitmap;
+typedef unsigned int BLI_bitmap;
 
 /* warning: the bitmap does not keep track of its own size or check
  * for out-of-bounds access */
@@ -48,7 +48,7 @@ typedef unsigned int *BLI_bitmap;
 /* allocate memory for a bitmap with '_tot' bits; free
  *  with MEM_freeN() */
 #define BLI_BITMAP_NEW(_tot, _alloc_string) \
-       ((BLI_bitmap)MEM_callocN(BLI_BITMAP_SIZE(_tot), \
+       ((BLI_bitmap *)MEM_callocN(BLI_BITMAP_SIZE(_tot), \
                                 _alloc_string))
 
 /* get the value of a single bit at '_index' */
index e0a34e35acc99db45beabbbf6312e62acde96e07..cb812fe8595e85445e00b7c633d4aecda0477882 100644 (file)
@@ -89,7 +89,18 @@ void BLI_make_existing_file(const char *name);
 void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen);
 void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen);
 void BLI_split_file_part(const char *string, char *file, const size_t filelen);
-void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file);
+void BLI_path_append(char *__restrict dst, const size_t maxlen,
+                     const char *__restrict file)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
+void BLI_join_dirfile(char *__restrict string, const size_t maxlen,
+                      const char *__restrict dir, const char *__restrict file)
+#ifdef __GNUC__
+__attribute__((nonnull))
+#endif
+;
 const char *BLI_path_basename(const char *path);
 
 typedef enum bli_rebase_state {
index adef843d2cc18ff439fa5252d9637a7dc06a5bd9..db32190494aa6fdf1141b77b6d4956becbb2f284 100644 (file)
 extern "C" {
 #endif
 
-char        *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy);
-char        *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy);
-int          BLI_utf8_invalid_byte(const char *str, int length);
-int          BLI_utf8_invalid_strip(char *str, int length);
+#ifdef __GNUC__
+#  define ATTR_NONULL __attribute__((nonnull))
+#  define ATTR_NONULL_FIRST  __attribute__((nonnull(1)))
+#  define ATTR_UNUSED_RESULT __attribute__((warn_unused_result))
+#else
+#  define ATTR_NONULL
+#  define ATTR_NONULL_FIRST
+#  define ATTR_UNUSED_RESULT
+#endif
+
+char        *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy)  ATTR_NONULL;
+char        *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy)  ATTR_NONULL;
+int          BLI_utf8_invalid_byte(const char *str, int length)  ATTR_NONULL;
+int          BLI_utf8_invalid_strip(char *str, int length)  ATTR_NONULL;
 
-int          BLI_str_utf8_size(const char *p); /* warning, can return -1 on bad chars */
-int          BLI_str_utf8_size_safe(const char *p);
+int          BLI_str_utf8_size(const char *p)  ATTR_NONULL; /* warning, can return -1 on bad chars */
+int          BLI_str_utf8_size_safe(const char *p)  ATTR_NONULL;
 /* copied from glib */
-unsigned int BLI_str_utf8_as_unicode(const char *p);
-unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index);
-unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index);
-unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index);
+unsigned int BLI_str_utf8_as_unicode(const char *p)  ATTR_NONULL;
+unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index)  ATTR_NONULL;
+unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index)  ATTR_NONULL;
+unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index)  ATTR_NONULL;
 size_t       BLI_str_utf8_from_unicode(unsigned int c, char *outbuf);
 
-char        *BLI_str_find_prev_char_utf8(const char *str, const char *p);
-char        *BLI_str_find_next_char_utf8(const char *p, const char *end);
-char        *BLI_str_prev_char_utf8(const char *p);
+char        *BLI_str_find_prev_char_utf8(const char *str, const char *p)  ATTR_NONULL;
+char        *BLI_str_find_next_char_utf8(const char *p, const char *end)  ATTR_NONULL_FIRST;
+char        *BLI_str_prev_char_utf8(const char *p)  ATTR_NONULL;
 
 /* wchar_t functions, copied from blenders own font.c originally */
-size_t       BLI_wstrlen_utf8(const wchar_t *src);
-size_t       BLI_strlen_utf8_ex(const char *strc, int *r_len_bytes);
-size_t       BLI_strlen_utf8(const char *strc);
-size_t       BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, int *r_len_bytes);
-size_t       BLI_strnlen_utf8(const char *strc, const size_t maxlen);
-size_t       BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxcpy);
-size_t       BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, const size_t maxcpy);
+size_t       BLI_wstrlen_utf8(const wchar_t *src)  ATTR_NONULL;
+size_t       BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes)  ATTR_NONULL;
+size_t       BLI_strlen_utf8(const char *strc)  ATTR_NONULL;
+size_t       BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes)  ATTR_NONULL;
+size_t       BLI_strnlen_utf8(const char *strc, const size_t maxlen)  ATTR_NONULL;
+size_t       BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxcpy)  ATTR_NONULL;
+size_t       BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, const size_t maxcpy)  ATTR_NONULL;
 
 /* count columns that character/string occupies, based on wcwidth.c */
 int          BLI_wcwidth(wchar_t ucs);
-int          BLI_wcswidth(const wchar_t *pwcs, size_t n);
-int          BLI_str_utf8_char_width(const char *p); /* warning, can return -1 on bad chars */
-int          BLI_str_utf8_char_width_safe(const char *p);
+int          BLI_wcswidth(const wchar_t *pwcs, size_t n)  ATTR_NONULL;
+int          BLI_str_utf8_char_width(const char *p)  ATTR_NONULL; /* warning, can return -1 on bad chars */
+int          BLI_str_utf8_char_width_safe(const char *p)  ATTR_NONULL;
 
 #define      BLI_UTF8_MAX 6        /* mem */
 #define      BLI_UTF8_WIDTH_MAX 2  /* columns */
 #define      BLI_UTF8_ERR ((unsigned int)-1)
 
+#undef ATTR_NONULL
+#undef ATTR_NONULL_FIRST
+#undef ATTR_UNUSED_RESULT
+
 #ifdef __cplusplus
 }
 #endif
index d30d3f3d256a6a04a730e8b2e512dc8031d89b20..10b3c01d2741c0ec14d140a8260d36aad3c993e1 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <limits.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -255,22 +256,14 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef
 GHashIterator *BLI_ghashIterator_new(GHash *gh)
 {
        GHashIterator *ghi = MEM_mallocN(sizeof(*ghi), "ghash iterator");
-       ghi->gh = gh;
-       ghi->curEntry = NULL;
-       ghi->curBucket = (unsigned int)-1;
-       while (!ghi->curEntry) {
-               ghi->curBucket++;
-               if (ghi->curBucket == ghi->gh->nbuckets)
-                       break;
-               ghi->curEntry = ghi->gh->buckets[ghi->curBucket];
-       }
+       BLI_ghashIterator_init(ghi, gh);
        return ghi;
 }
 void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
 {
        ghi->gh = gh;
        ghi->curEntry = NULL;
-       ghi->curBucket = (unsigned int)-1;
+       ghi->curBucket = UINT_MAX;  /* wraps to zero */
        while (!ghi->curEntry) {
                ghi->curBucket++;
                if (ghi->curBucket == ghi->gh->nbuckets)
index 26b9e08c7f66386924a5dc126323038c5c2c2e44..af0359c00872a8a52cebb4e187686a643d6533a8 100644 (file)
@@ -445,7 +445,7 @@ static void join_dirfile_alloc(char **dst, size_t *alloc_len, const char *dir, c
        size_t len = strlen(dir) + strlen(file) + 1;
 
        if (*dst == NULL)
-               *dst = MEM_callocN(len + 1, "join_dirfile_alloc path");
+               *dst = MEM_mallocN(len + 1, "join_dirfile_alloc path");
        else if (*alloc_len < len)
                *dst = MEM_reallocN(*dst, len + 1);
 
index 3f802c492c21162fb3263fd779b100dace613d60..8cfe4706937019bf8b8e563f84a646be8e429969 100644 (file)
@@ -150,6 +150,7 @@ void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, in
                        break;
                default:
                        assert(!"invalid colorspace");
+                       break;
        }
 
        *ly = y;
@@ -183,7 +184,8 @@ void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, in
                        b = y + 1.772f * cb - 226.816f;
                        break;
                default:
-                       assert(!"invalid colorspace");
+                       BLI_assert(0);
+                       break;
        }
        *lr = r / 255.0f;
        *lg = g / 255.0f;
index cd7dfdc6d2f7d8817c99b48038bf9e8a2565f556..312805e23f64c301be5fe962fd1fa1d01f0f385c 100644 (file)
@@ -839,6 +839,7 @@ void orthogonalize_m3(float mat[3][3], int axis)
                        break;
                default:
                        BLI_assert(0);
+                       break;
        }
        mul_v3_fl(mat[0], size[0]);
        mul_v3_fl(mat[1], size[1]);
@@ -922,6 +923,7 @@ void orthogonalize_m4(float mat[4][4], int axis)
                        break;
                default:
                        BLI_assert(0);
+                       break;
        }
        mul_v3_fl(mat[0], size[0]);
        mul_v3_fl(mat[1], size[1]);
index dc0c48cf33fd171c3394fcf3433c1f1a1475bd65..9fd8c479d6ed12a2a956013cd7575025c98e4b3b 100644 (file)
@@ -857,7 +857,8 @@ void single_axis_angle_to_mat3(float mat[3][3], const char axis, const float ang
                        mat[2][2] = 1.0f;
                        break;
                default:
-                       assert(0);
+                       BLI_assert(0);
+                       break;
        }
 }
 
index 6e52145c65391dcb1f915785189c0f508bfd2f73..2f94e833e9d6815781e6f8e220183304d8d802c0 100644 (file)
@@ -1252,6 +1252,7 @@ void voronoi(float x, float y, float z, float *da, float *pa, float me, int dtyp
                case 0:
                default:
                        distfunc = dist_Real;
+                       break;
        }
 
        xi = (int)(floor(x));
@@ -1467,6 +1468,7 @@ float BLI_gNoise(float noisesize, float x, float y, float z, int hard, int noise
                        x += 1;
                        y += 1;
                        z += 1;
+                       break;
                }
        }
 
@@ -1522,6 +1524,7 @@ float BLI_gTurbulence(float noisesize, float x, float y, float z, int oct, int h
                        x += 1;
                        y += 1;
                        z += 1;
+                       break;
        }
 
        if (noisesize != 0.0f) {
@@ -1596,6 +1599,7 @@ float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves
                default:
                {
                        noisefunc = orgBlenderNoiseS;
+                       break;
                }
        }
        
@@ -1667,6 +1671,7 @@ float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, floa
                default:
                {
                        noisefunc = orgBlenderNoiseS;
+                       break;
                }
        }
 
@@ -1734,6 +1739,7 @@ float mg_HeteroTerrain(float x, float y, float z, float H, float lacunarity, flo
                default:
                {
                        noisefunc = orgBlenderNoiseS;
+                       break;
                }
        }
 
@@ -1808,6 +1814,7 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity
                default:
                {
                        noisefunc = orgBlenderNoiseS;
+                       break;
                }
        }
 
@@ -1884,6 +1891,7 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity
                default:
                {
                        noisefunc = orgBlenderNoiseS;
+                       break;
                }
        }
 
@@ -1950,6 +1958,7 @@ float mg_VLNoise(float x, float y, float z, float distortion, int nbas1, int nba
                default:
                {
                        noisefunc1 = orgBlenderNoiseS;
+                       break;
                }
        }
 
@@ -1985,6 +1994,7 @@ float mg_VLNoise(float x, float y, float z, float distortion, int nbas1, int nba
                default:
                {
                        noisefunc2 = orgBlenderNoiseS;
+                       break;
                }
        }
 
index 4c089e9920285d0d2c8050c82941ca338c9dae68..2c06a812c8a1edc04f7d2ce9fbb3a4a151e9a0e3 100644 (file)
@@ -695,8 +695,10 @@ bool BLI_path_frame(char *path, int frame, int digits)
 
        if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */
                char tmp[FILE_MAX];
-               sprintf(tmp, "%.*s%.*d%s", ch_sta, path, ch_end - ch_sta, frame, path + ch_end);
-               strcpy(path, tmp);
+               BLI_snprintf(tmp, sizeof(tmp),
+                            "%.*s%.*d%s",
+                            ch_sta, path, ch_end - ch_sta, frame, path + ch_end);
+               BLI_strncpy(path, tmp, FILE_MAX);
                return true;
        }
        return false;
@@ -1228,6 +1230,7 @@ const char *BLI_get_folder(int folder_id, const char *subfolder)
 
                default:
                        BLI_assert(0);
+                       break;
        }
        
        return path;
@@ -1256,7 +1259,9 @@ const char *BLI_get_user_folder_notest(int folder_id, const char *subfolder)
                        break;
                default:
                        BLI_assert(0);
+                       break;
        }
+
        if ('\0' == path[0]) {
                return NULL;
        }
@@ -1306,6 +1311,7 @@ const char *BLI_get_folder_version(const int id, const int ver, const bool do_ch
                        path[0] = '\0'; /* in case do_check is false */
                        ok = false;
                        BLI_assert(!"incorrect ID");
+                       break;
        }
 
        if (!ok && do_check) {
@@ -1684,6 +1690,26 @@ void BLI_split_file_part(const char *string, char *file, const size_t filelen)
        BLI_split_dirfile(string, NULL, file, 0, filelen);
 }
 
+/**
+ * Append a filename to a dir, ensuring slash separates.
+ */
+void BLI_path_append(char *dst, const size_t maxlen, const char *file)
+{
+       size_t dirlen = BLI_strnlen(dst, maxlen);
+
+       /* inline BLI_add_slash */
+       if ((dirlen > 0) && (dst[dirlen - 1] != SEP)) {
+               dst[dirlen++] = SEP;
+               dst[dirlen] = '\0';
+       }
+
+       if (dirlen >= maxlen) {
+               return; /* fills the path */
+       }
+
+       BLI_strncpy(dst + dirlen, file, maxlen - dirlen);
+}
+
 /**
  * Simple appending of filename to dir, does not check for valid path!
  * Puts result into *dst, which may be same area as *dir.
@@ -1692,15 +1718,16 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha
 {
        size_t dirlen = BLI_strnlen(dir, maxlen);
 
-       if (dst != dir) {
-               if (dirlen == maxlen) {
-                       memcpy(dst, dir, dirlen);
-                       dst[dirlen - 1] = '\0';
-                       return; /* dir fills the path */
-               }
-               else {
-                       memcpy(dst, dir, dirlen + 1);
-               }
+       /* args can't match */
+       BLI_assert(!ELEM(dst, dir, file));
+
+       if (dirlen == maxlen) {
+               memcpy(dst, dir, dirlen);
+               dst[dirlen - 1] = '\0';
+               return; /* dir fills the path */
+       }
+       else {
+               memcpy(dst, dir, dirlen + 1);
        }
 
        if (dirlen + 1 >= maxlen) {
@@ -1717,10 +1744,6 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha
                return; /* fills the path */
        }
 
-       if (file == NULL) {
-               return;
-       }
-
        BLI_strncpy(dst + dirlen, file, maxlen - dirlen);
 }
 
@@ -1836,7 +1859,7 @@ int BLI_rebase_path(char *abs, size_t abs_len,
                        /* subdirectories relative to blend_dir */
                        BLI_join_dirfile(dest_path, sizeof(dest_path), dest_dir, rel_dir);
                        /* same subdirectories relative to dest_dir */
-                       BLI_join_dirfile(dest_path, sizeof(dest_path), dest_path, base);
+                       BLI_path_append(dest_path, sizeof(dest_path), base);
                        /* keeping original item basename */
                }
 
@@ -2057,7 +2080,7 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name
                                        else {
                                                strncpy(filename, path, sizeof(filename));
                                        }
-                                       BLI_join_dirfile(fullname, maxlen, fullname, name);
+                                       BLI_path_append(fullname, maxlen, name);
                                        if (add_win32_extension(filename)) {
                                                BLI_strncpy(fullname, filename, maxlen);
                                                break;
index aeeae000fff18e433786e5325c6dbc6bfdc2221b..34c6e6321311e4c5254df4f2ea002afb59cab4a9 100644 (file)
@@ -388,17 +388,14 @@ static void bli_adddirstrings(struct BuildDirCtx *dir_ctx)
                 */
                st_size = file->s.st_size;
 
-               /* FIXME: Either change decimal prefixes to binary ones
-                * <http://en.wikipedia.org/wiki/Binary_prefix>, or change
-                * divisor factors from 1024 to 1000. */
                if (st_size > 1024 * 1024 * 1024) {
-                       BLI_snprintf(file->size, sizeof(file->size), "%.2f GB", ((double)st_size) / (1024 * 1024 * 1024));
+                       BLI_snprintf(file->size, sizeof(file->size), "%.2f GiB", ((double)st_size) / (1024 * 1024 * 1024));
                }
                else if (st_size > 1024 * 1024) {
-                       BLI_snprintf(file->size, sizeof(file->size), "%.1f MB", ((double)st_size) / (1024 * 1024));
+                       BLI_snprintf(file->size, sizeof(file->size), "%.1f MiB", ((double)st_size) / (1024 * 1024));
                }
                else if (st_size > 1024) {
-                       BLI_snprintf(file->size, sizeof(file->size), "%d KB", (int)(st_size / 1024));
+                       BLI_snprintf(file->size, sizeof(file->size), "%d KiB", (int)(st_size / 1024));
                }
                else {
                        BLI_snprintf(file->size, sizeof(file->size), "%d B", (int)st_size);
index 24e14d04c682665567a95679df62181a608b4887..3de57ccb54f313d9d591f4425b30b813cf878aaf 100644 (file)
@@ -87,15 +87,18 @@ char *BLI_strdup(const char *str)
  */
 char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2)
 {
-       size_t len;
-       char *n;
-       
-       len = strlen(str1) + strlen(str2);
-       n = MEM_mallocN(len + 1, "strdupcat");
-       strcpy(n, str1);
-       strcat(n, str2);
+       /* include the NULL terminator of str2 only */
+       const size_t str1_len = strlen(str1);
+       const size_t str2_len = strlen(str2) + 1;
+       char *str, *s;
        
-       return n;
+       str = MEM_mallocN(str1_len + str2_len, "strdupcat");
+       s = str;
+
+       memcpy(s, str1, str1_len); s += str1_len;
+       memcpy(s, str2, str2_len);
+
+       return str;
 }
 
 /**
@@ -240,6 +243,7 @@ size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const siz
                                goto escape_finish;
                        case '\\':
                        case '"':
+                               /* fall-through */
 
                        /* less common but should also be support */
                        case '\t':
@@ -253,9 +257,10 @@ size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const siz
                                        /* not enough space to escape */
                                        break;
                                }
-                       /* intentionally pass through */
+                               /* fall-through */
                        default:
                                *dst = *src;
+                               break;
                }
                dst++;
                src++;
index d435ed8f6e7730c7ce1000d0eb86bd76ef65483f..225b3c5538f7d37123447e2579dbaa63c03cc224 100644 (file)
@@ -260,7 +260,7 @@ size_t BLI_wstrlen_utf8(const wchar_t *src)
        return len;
 }
 
-size_t BLI_strlen_utf8_ex(const char *strc, int *r_len_bytes)
+size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes)
 {
        size_t len;
        const char *strc_orig = strc;
@@ -268,7 +268,7 @@ size_t BLI_strlen_utf8_ex(const char *strc, int *r_len_bytes)
        for (len = 0; *strc; len++)
                strc += BLI_str_utf8_size_safe(strc);
 
-       *r_len_bytes = (strc - strc_orig);
+       *r_len_bytes = (size_t)(strc - strc_orig);
        return len;
 }
 
@@ -282,7 +282,7 @@ size_t BLI_strlen_utf8(const char *strc)
        return len;
 }
 
-size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, int *r_len_bytes)
+size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes)
 {
        size_t len;
        const char *strc_orig = strc;
@@ -292,7 +292,7 @@ size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, int *r_len_byt
                strc += BLI_str_utf8_size_safe(strc);
        }
 
-       *r_len_bytes = (strc - strc_orig);
+       *r_len_bytes = (size_t)(strc - strc_orig);
        return len;
 }
 
index 50273cb33f31a712f5d428560057cd55509bbfcd..1ed22a5325145e004d018b0b7fe40d9c32faaea8 100644 (file)
@@ -5803,21 +5803,23 @@ static void *restore_pointer_by_name(Main *mainp, ID *id, int user)
        return NULL;
 }
 
+static void lib_link_seq_clipboard_pt_restore(ID *id, Main *newmain)
+{
+       if (id) {
+               /* clipboard must ensure this */
+               BLI_assert(id->newid != NULL);
+               id->newid = restore_pointer_by_name(newmain, (ID *)id->newid, 1);
+       }
+}
 static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
 {
        Main *newmain = (Main *)arg_pt;
-       
-       if (seq->sound) {
-               seq->sound = restore_pointer_by_name(newmain, (ID *)seq->sound, 0);
-               seq->sound->id.us++;
-       }
-       
-       if (seq->scene)
-               seq->scene = restore_pointer_by_name(newmain, (ID *)seq->scene, 1);
-       
-       if (seq->scene_camera)
-               seq->scene_camera = restore_pointer_by_name(newmain, (ID *)seq->scene_camera, 1);
-       
+
+       lib_link_seq_clipboard_pt_restore((ID *)seq->scene, newmain);
+       lib_link_seq_clipboard_pt_restore((ID *)seq->scene_camera, newmain);
+       lib_link_seq_clipboard_pt_restore((ID *)seq->clip, newmain);
+       lib_link_seq_clipboard_pt_restore((ID *)seq->mask, newmain);
+       lib_link_seq_clipboard_pt_restore((ID *)seq->sound, newmain);
        return 1;
 }
 
@@ -9487,7 +9489,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-
+       if (!MAIN_VERSION_ATLEAST(main, 268, 1)) {
+               Brush *brush;
+               for (brush = main->brush.first; brush; brush = brush->id.next) {
+                       brush->spacing = MAX2(1, brush->spacing);
+               }
+       }
+       
        {
                bScreen *sc;
                Object *ob;
index dd4361be1ff704ce64b64e5797fda502181d7756..e170107713c7836f964fd1ec4f6a4a5f08fef573 100644 (file)
@@ -1660,8 +1660,8 @@ static void write_curves(WriteData *wd, ListBase *idbase)
                        
                        if (cu->vfont) {
                                /* TODO, sort out 'cu->len', in editmode its character, object mode its bytes */
-                               int len_bytes;
-                               int len_chars = BLI_strlen_utf8_ex(cu->str, &len_bytes);
+                               size_t len_bytes;
+                               size_t len_chars = BLI_strlen_utf8_ex(cu->str, &len_bytes);
 
                                writedata(wd, DATA, len_bytes + 1, cu->str);
                                writestruct(wd, DATA, "CharInfo", len_chars + 1, cu->strinfo);
index b3dd2f57523fa19941db5149aaf9b71a4d2d4a4a..350c1d71a434a47eab6cbaf04133531bcda629a6 100644 (file)
@@ -23,7 +23,7 @@
 #
 # ***** END GPL LICENSE BLOCK *****
 
-set(INC 
+set(INC
        .
        ../blenfont
        ../blenkernel
@@ -50,7 +50,7 @@ set(SRC
        operators/bmo_edgenet.c
        operators/bmo_extrude.c
        operators/bmo_fill_edgeloop.c
-       operators/bmo_fill_grid.c 
+       operators/bmo_fill_grid.c
        operators/bmo_hull.c
        operators/bmo_inset.c
        operators/bmo_join_triangles.c
@@ -115,7 +115,6 @@ set(SRC
        intern/bmesh_operator_api.h
        intern/bmesh_error.h
 
-       tools/BME_bevel.c
        tools/bmesh_bevel.c
        tools/bmesh_bevel.h
        tools/bmesh_decimate_collapse.c
index 4ec0a3699d067e5908edb102ef8dee6a22f6c185..39b127c410e71e2ae8ad4adbd79e6d51e3393f28 100644 (file)
@@ -817,11 +817,6 @@ void BM_elem_attrs_copy_ex(BMesh *bm_src, BMesh *bm_dst, const void *ele_src_v,
 
        BLI_assert(ele_src->htype == ele_dst->htype);
 
-       if (ele_src->htype != ele_dst->htype) {
-               BLI_assert(!"type mismatch");
-               return;
-       }
-
        if ((hflag_mask & BM_ELEM_SELECT) == 0) {
                /* First we copy select */
                if (BM_elem_flag_test((BMElem *)ele_src, BM_ELEM_SELECT)) {
@@ -833,6 +828,9 @@ void BM_elem_attrs_copy_ex(BMesh *bm_src, BMesh *bm_dst, const void *ele_src_v,
        if (hflag_mask == 0) {
                ele_dst->hflag = ele_src->hflag;
        }
+       else if (hflag_mask == 0xff) {
+               /* pass */
+       }
        else {
                ele_dst->hflag = ((ele_dst->hflag & hflag_mask) | (ele_src->hflag & ~hflag_mask));
        }
@@ -853,13 +851,26 @@ void BM_elem_attrs_copy_ex(BMesh *bm_src, BMesh *bm_dst, const void *ele_src_v,
                        break;
                default:
                        BLI_assert(0);
+                       break;
        }
 }
 
 void BM_elem_attrs_copy(BMesh *bm_src, BMesh *bm_dst, const void *ele_src, void *ele_dst)
 {
        /* BMESH_TODO, default 'use_flags' to false */
-       BM_elem_attrs_copy_ex(bm_src, bm_dst, ele_src, ele_dst, 0);
+       BM_elem_attrs_copy_ex(bm_src, bm_dst, ele_src, ele_dst, BM_ELEM_SELECT);
+}
+
+void BM_elem_select_copy(BMesh *UNUSED(bm_src), BMesh *bm_dst, const void *ele_src_v, void *ele_dst_v)
+{
+       const BMHeader *ele_src = ele_src_v;
+       BMHeader *ele_dst = ele_dst_v;
+
+       BLI_assert(ele_src->htype == ele_dst->htype);
+
+       if ((ele_src->hflag & BM_ELEM_SELECT) != (ele_dst->hflag & BM_ELEM_SELECT)) {
+               BM_elem_select_set(bm_dst, (BMElem *)ele_dst, (ele_src->hflag & BM_ELEM_SELECT) != 0);
+       }
 }
 
 /* helper function for 'BM_mesh_copy' */
@@ -893,7 +904,8 @@ static BMFace *bm_mesh_copy_new_face(BMesh *bm_new, BMesh *bm_old,
        /* use totface in case adding some faces fails */
        BM_elem_index_set(f_new, (bm_new->totface - 1)); /* set_inline */
 
-       BM_elem_attrs_copy(bm_old, bm_new, f, f_new);
+       BM_elem_attrs_copy_ex(bm_old, bm_new, f, f_new, 0xff);
+       f_new->head.hflag = f->head.hflag;  /* low level! don't do this for normal api use */
 
        j = 0;
        l_iter = l_first = BM_FACE_FIRST_LOOP(f_new);
@@ -950,7 +962,8 @@ BMesh *BM_mesh_copy(BMesh *bm_old)
        BM_ITER_MESH_INDEX (v, &iter, bm_old, BM_VERTS_OF_MESH, i) {
                /* copy between meshes so cant use 'example' argument */
                v_new = BM_vert_create(bm_new, v->co, NULL, BM_CREATE_SKIP_CD);
-               BM_elem_attrs_copy(bm_old, bm_new, v, v_new);
+               BM_elem_attrs_copy_ex(bm_old, bm_new, v, v_new, 0xff);
+               v_new->head.hflag = v->head.hflag;  /* low level! don't do this for normal api use */
                vtable[i] = v_new;
                BM_elem_index_set(v, i); /* set_inline */
                BM_elem_index_set(v_new, i); /* set_inline */
@@ -967,7 +980,8 @@ BMesh *BM_mesh_copy(BMesh *bm_old)
                                       vtable[BM_elem_index_get(e->v2)],
                                       e, BM_CREATE_SKIP_CD);
 
-               BM_elem_attrs_copy(bm_old, bm_new, e, e_new);
+               BM_elem_attrs_copy_ex(bm_old, bm_new, e, e_new, 0xff);
+               e_new->head.hflag = e->head.hflag;  /* low level! don't do this for normal api use */
                etable[i] = e_new;
                BM_elem_index_set(e, i); /* set_inline */
                BM_elem_index_set(e_new, i); /* set_inline */
@@ -990,6 +1004,12 @@ BMesh *BM_mesh_copy(BMesh *bm_old)
        bm_old->elem_index_dirty &= ~BM_FACE;
        bm_new->elem_index_dirty &= ~BM_FACE;
 
+
+       /* low level! don't do this for normal api use */
+       bm_new->totvertsel = bm_old->totvertsel;
+       bm_new->totedgesel = bm_old->totedgesel;
+       bm_new->totfacesel = bm_old->totfacesel;
+
        /* safety check */
        BLI_assert(i == bm_old->totface);
 
index 3dcb1eb1ccb68cf28e00b60a541a4b9804e3b788..9552ef6f5a4ad5dfb31547b5c65f1720080162d4 100644 (file)
@@ -53,6 +53,7 @@ void BMO_remove_tagged_context(BMesh *bm, const short oflag, const int type);
 void BM_elem_attrs_copy_ex(BMesh *bm_src, BMesh *bm_dst, const void *ele_src_v, void *ele_dst_v,
                            const char hflag_mask);
 void BM_elem_attrs_copy(BMesh *bm_src, BMesh *bm_dst, const void *ele_src_v, void *ele_dst_v);
+void BM_elem_select_copy(BMesh *bm_src, BMesh *bm_dst, const void *ele_src_v, void *ele_dst_v);
 
 void   BM_mesh_copy_init_customdata(BMesh *bm_dst, BMesh *bm_src, const struct BMAllocTemplate *allocsize);
 BMesh *BM_mesh_copy(BMesh *bm_old);
index ecb776e75892a7824dcc0a07e251c88124ec46ea..05c462ac672df3bac91a9663e7fb319ba8eb9005 100644 (file)
@@ -502,6 +502,7 @@ int bmesh_elem_check(void *element, const char htype)
                }
                default:
                        BLI_assert(0);
+                       break;
        }
 
        BMESH_ASSERT(err == 0);
index 7c4af8eaa3b745ed00782c5f96dac451904b53ce..184fed59f011204e14f7854c537ae637b9018416 100644 (file)
@@ -583,9 +583,8 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, bool do_tessface)
        MEdge *med, *medge;
        BMVert *v, *eve;
        BMEdge *e;
-       BMLoop *l;
        BMFace *f;
-       BMIter iter, liter;
+       BMIter iter;
        int i, j, ototvert;
 
        const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
@@ -699,22 +698,26 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, bool do_tessface)
        i = 0;
        j = 0;
        BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+               BMLoop *l_iter, *l_first;
                mpoly->loopstart = j;
                mpoly->totloop = f->len;
                mpoly->mat_nr = f->mat_nr;
                mpoly->flag = BM_face_flag_to_mflag(f);
 
-               l = BM_iter_new(&liter, bm, BM_LOOPS_OF_FACE, f);
-               for ( ; l; l = BM_iter_step(&liter), j++, mloop++) {
-                       mloop->e = BM_elem_index_get(l->e);
-                       mloop->v = BM_elem_index_get(l->v);
+               l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+               do {
+                       mloop->e = BM_elem_index_get(l_iter->e);
+                       mloop->v = BM_elem_index_get(l_iter->v);
 
-                       /* copy over customdat */
-                       CustomData_from_bmesh_block(&bm->ldata, &me->ldata, l->head.data, j);
-                       BM_CHECK_ELEMENT(l);
-                       BM_CHECK_ELEMENT(l->e);
-                       BM_CHECK_ELEMENT(l->v);
-               }
+                       /* copy over customdata */
+                       CustomData_from_bmesh_block(&bm->ldata, &me->ldata, l_iter->head.data, j);
+
+                       j++;
+                       mloop++;
+                       BM_CHECK_ELEMENT(l_iter);
+                       BM_CHECK_ELEMENT(l_iter->e);
+                       BM_CHECK_ELEMENT(l_iter->v);
+               } while ((l_iter = l_iter->next) != l_first);
 
                if (f == bm->act_face) me->act_face = i;
 
index 4c6129cf43fcb2cfd357af0243b0c1c5cfd37c96..56d63694d88598b2b9748400069f957590791fc5 100644 (file)
@@ -49,9 +49,9 @@ enum {
 };
 
 enum {
+       SUBDIV_SELECT_NONE,
        SUBDIV_SELECT_ORIG,
        SUBDIV_SELECT_INNER,
-       SUBDIV_SELECT_INNER_SEL,
        SUBDIV_SELECT_LOOPCUT
 };
 
index 88186df89fb7c2a298678951d708b5033fa5f936..1ecb3c2b9acfcf10a044b78c05261ede491dc931 100644 (file)
@@ -125,7 +125,7 @@ static void bm_face_calc_poly_normal(BMFace *f, float n[3])
  * Same as #calc_poly_normal and #bm_face_calc_poly_normal
  * but takes an array of vertex locations.
  */
-static void bm_face_calc_poly_normal_vertex_cos(BMFace *f, float n[3],
+static void bm_face_calc_poly_normal_vertex_cos(BMFace *f, float r_no[3],
                                                 float const (*vertexCos)[3])
 {
        BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
@@ -133,22 +133,40 @@ static void bm_face_calc_poly_normal_vertex_cos(BMFace *f, float n[3],
        float const *v_prev = vertexCos[BM_elem_index_get(l_first->prev->v)];
        float const *v_curr = vertexCos[BM_elem_index_get(l_first->v)];
 
-       zero_v3(n);
+       zero_v3(r_no);
 
        /* Newell's Method */
        do {
-               add_newell_cross_v3_v3v3(n, v_prev, v_curr);
+               add_newell_cross_v3_v3v3(r_no, v_prev, v_curr);
 
                l_iter = l_iter->next;
                v_prev = v_curr;
                v_curr = vertexCos[BM_elem_index_get(l_iter->v)];
        } while (l_iter != l_first);
 
-       if (UNLIKELY(normalize_v3(n) == 0.0f)) {
-               n[2] = 1.0f; /* other axis set to 0.0 */
+       if (UNLIKELY(normalize_v3(r_no) == 0.0f)) {
+               r_no[2] = 1.0f; /* other axis set to 0.0 */
        }
 }
 
+/**
+ * \brief COMPUTE POLY CENTER (BMFace)
+ */
+static void bm_face_calc_poly_center_mean_vertex_cos(BMFace *f, float r_cent[3],
+                                                     float const (*vertexCos)[3])
+{
+       BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
+       BMLoop *l_iter  = l_first;
+
+       zero_v3(r_cent);
+
+       /* Newell's Method */
+       do {
+               add_v3_v3(r_cent, vertexCos[BM_elem_index_get(l_iter->v)]);
+       } while ((l_iter = l_iter->next) != l_first);
+       mul_v3_fl(r_cent, 1.0f / f->len);
+}
+
 /**
  * For tools that insist on using triangles, ideally we would cache this data.
  *
@@ -370,8 +388,7 @@ void BM_face_calc_center_bounds(BMFace *f, float r_cent[3])
  */
 void BM_face_calc_center_mean(BMFace *f, float r_cent[3])
 {
-       BMLoop *l_iter;
-       BMLoop *l_first;
+       BMLoop *l_iter, *l_first;
 
        zero_v3(r_cent);
 
@@ -379,9 +396,7 @@ void BM_face_calc_center_mean(BMFace *f, float r_cent[3])
        do {
                add_v3_v3(r_cent, l_iter->v->co);
        } while ((l_iter = l_iter->next) != l_first);
-
-       if (f->len)
-               mul_v3_fl(r_cent, 1.0f / (float) f->len);
+       mul_v3_fl(r_cent, 1.0f / (float) f->len);
 }
 
 /**
@@ -601,9 +616,9 @@ void BM_face_normal_update(BMFace *f)
        BM_face_calc_normal(f, f->no);
 }
 
-/* exact same as 'bmesh_face_normal_update' but accepts vertex coords */
-void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3],
-                                float const (*vertexCos)[3])
+/* exact same as 'BM_face_calc_normal' but accepts vertex coords */
+void BM_face_calc_normal_vcos(BMesh *bm, BMFace *f, float r_no[3],
+                              float const (*vertexCos)[3])
 {
        BMLoop *l;
 
@@ -620,7 +635,7 @@ void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3],
                        const float *co3 = vertexCos[BM_elem_index_get((l = l->next)->v)];
                        const float *co4 = vertexCos[BM_elem_index_get((l->next)->v)];
 
-                       normal_quad_v3(no, co1, co2, co3, co4);
+                       normal_quad_v3(r_no, co1, co2, co3, co4);
                        break;
                }
                case 3:
@@ -629,22 +644,33 @@ void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3],
                        const float *co2 = vertexCos[BM_elem_index_get((l = l->next)->v)];
                        const float *co3 = vertexCos[BM_elem_index_get((l->next)->v)];
 
-                       normal_tri_v3(no, co1, co2, co3);
+                       normal_tri_v3(r_no, co1, co2, co3);
                        break;
                }
                case 0:
                {
-                       zero_v3(no);
+                       zero_v3(r_no);
                        break;
                }
                default:
                {
-                       bm_face_calc_poly_normal_vertex_cos(f, no, vertexCos);
+                       bm_face_calc_poly_normal_vertex_cos(f, r_no, vertexCos);
                        break;
                }
        }
 }
 
+/* exact same as 'BM_face_calc_normal' but accepts vertex coords */
+void BM_face_calc_center_mean_vcos(BMesh *bm, BMFace *f, float r_cent[3],
+                                   float const (*vertexCos)[3])
+{
+       /* must have valid index data */
+       BLI_assert((bm->elem_index_dirty & BM_VERT) == 0);
+       (void)bm;
+
+       bm_face_calc_poly_center_mean_vertex_cos(f, r_cent, vertexCos);
+}
+
 /**
  * \brief Face Flip Normal
  *
index 2f6b54b91d307425f6b19b3d916645489b32e3cf..91fe94f8e48aa184a5ca52221554f4c99dbfb324 100644 (file)
@@ -34,16 +34,18 @@ int   BM_face_calc_tessellation(BMFace *f, BMLoop **r_loops, int (*r_index)[3])
 #endif
 ;
 void  BM_face_calc_normal(BMFace *f, float r_no[3]);
+void  BM_face_calc_normal_vcos(BMesh *bm, BMFace *f, float r_no[3],
+                               float const (*vertexCos)[3]);
 float BM_face_calc_area(BMFace *f);
 float BM_face_calc_perimeter(BMFace *f);
 void  BM_face_calc_plane(BMFace *f, float r_plane[3]);
 void  BM_face_calc_center_bounds(BMFace *f, float center[3]);
 void  BM_face_calc_center_mean(BMFace *f, float center[3]);
+void  BM_face_calc_center_mean_vcos(BMesh *bm, BMFace *f, float r_cent[3],
+                                    float const (*vertexCos)[3]);
 void  BM_face_calc_center_mean_weighted(BMFace *f, float center[3]);
 
 void  BM_face_normal_update(BMFace *f);
-void  BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3],
-                                 float const (*vertexCos)[3]);
 
 void  BM_edge_normals_update(BMEdge *e);
 
index a00bef0228baa5a51be78ebf9844fbe6a537db05..9dc5ae61d6136b1c251135167d00a938c3f60989 100644 (file)
@@ -338,16 +338,16 @@ bool BM_verts_in_face(BMFace *f, BMVert **varr, int len)
  */
 bool BM_edge_in_face(BMFace *f, BMEdge *e)
 {
-       BMLoop *l_iter;
-       BMLoop *l_first;
-
-       l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+       if (e->l) {
+               BMLoop *l_iter, *l_first;
 
-       do {
-               if (l_iter->e == e) {
-                       return true;
-               }
-       } while ((l_iter = l_iter->next) != l_first);
+               l_iter = l_first = e->l;
+               do {
+                       if (l_iter->f == f) {
+                               return true;
+                       }
+               } while ((l_iter = l_iter->radial_next) != l_first);
+       }
 
        return false;
 }
@@ -1758,20 +1758,27 @@ float BM_mesh_calc_volume(BMesh *bm, bool is_signed)
        return vol;
 }
 
-
+/* note, almost duplicate of BM_mesh_calc_edge_groups, keep in sync */
 /**
- * TODO (as we need)
- * - option to walk over faces by verts.
- * - option to walk over non manifold edges.
+ * Calculate isolated groups of faces with optional filtering.
  *
  * \param bm  the BMesh.
- * \param r_groups_array  Array of ints to fill in, length of bm->totface.
+ * \param r_groups_array  Array of ints to fill in, length of bm->totface
+ *        (or when hflag_test is set, the number of flagged faces).
  * \param r_group_index  index, length pairs into \a r_groups_array, size of return value
- * int pairs: (array_start, array_length).
+ *        int pairs: (array_start, array_length).
+ * \param filter_fn  Filter the edges or verts we step over (depends on \a htype_step)
+ *        as to which types we deal with.
+ * \param user_data  Optional user data for \a filter_fn, can be NULL.
+ * \param hflag_test  Optional flag to test faces,
+ *        use to exclude faces from the calculation, 0 for all faces.
+ * \param htype_step  BM_VERT to walk over face-verts, BM_EDGE to walk over faces edges
+ *        (having both set is supported too).
  * \return The number of groups found.
  */
 int BM_mesh_calc_face_groups(BMesh *bm, int *r_groups_array, int (**r_group_index)[2],
-                             void *user_data, bool (*filter_fn)(BMEdge *, void *user_data))
+                             BMElemFilterFunc filter_fn, void *user_data,
+                             const char hflag_test, const char htype_step)
 {
 #ifdef DEBUG
        int group_index_len = 1;
@@ -1786,11 +1793,11 @@ int BM_mesh_calc_face_groups(BMesh *bm, int *r_groups_array, int (**r_group_inde
 
        int group_curr = 0;
 
-       const unsigned int tot_faces = bm->totface;
+       unsigned int tot_faces = 0;
        unsigned int tot_touch = 0;
 
-       BMFace **fstack;
-       STACK_DECLARE(fstack);
+       BMFace **stack;
+       STACK_DECLARE(stack);
 
        BMIter iter;
        BMFace *f;
@@ -1798,28 +1805,38 @@ int BM_mesh_calc_face_groups(BMesh *bm, int *r_groups_array, int (**r_group_inde
 
        STACK_INIT(group_array);
 
+       BLI_assert(((htype_step & ~(BM_VERT | BM_EDGE)) == 0) && (htype_step != 0));
+
        /* init the array */
        BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) {
+               if ((hflag_test == 0) || BM_elem_flag_test(f, hflag_test)) {
+                       tot_faces++;
+                       BM_elem_flag_disable(f, BM_ELEM_TAG);
+               }
+               else {
+                       /* never walk over tagged */
+                       BM_elem_flag_enable(f, BM_ELEM_TAG);
+               }
+
                BM_elem_index_set(f, i); /* set_inline */
-               BM_elem_flag_disable(f, BM_ELEM_TAG);
        }
        bm->elem_index_dirty &= ~BM_FACE;
 
        /* detect groups */
-       fstack = MEM_mallocN(sizeof(*fstack) * tot_faces, __func__);
+       stack = MEM_mallocN(sizeof(*stack) * tot_faces, __func__);
 
        while (tot_touch != tot_faces) {
-               int *fg;
+               int *group_item;
                bool ok = false;
 
                BLI_assert(tot_touch < tot_faces);
 
-               STACK_INIT(fstack);
+               STACK_INIT(stack);
 
                BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
                        if (BM_elem_flag_test(f, BM_ELEM_TAG) == false) {
                                BM_elem_flag_enable(f, BM_ELEM_TAG);
-                               STACK_PUSH(fstack, f);
+                               STACK_PUSH(stack, f);
                                ok = true;
                                break;
                        }
@@ -1833,36 +1850,193 @@ int BM_mesh_calc_face_groups(BMesh *bm, int *r_groups_array, int (**r_group_inde
                        group_index = MEM_reallocN(group_index, sizeof(*group_index) * group_index_len);
                }
 
-               fg = group_index[group_curr];
-               fg[0] = STACK_SIZE(group_array);
-               fg[1] = 0;
+               group_item = group_index[group_curr];
+               group_item[0] = STACK_SIZE(group_array);
+               group_item[1] = 0;
 
-               while ((f = STACK_POP(fstack))) {
+               while ((f = STACK_POP(stack))) {
                        BMLoop *l_iter, *l_first;
 
                        /* add face */
                        STACK_PUSH(group_array, BM_elem_index_get(f));
                        tot_touch++;
-                       fg[1]++;
+                       group_item[1]++;
                        /* done */
 
-                       /* search for other faces */
-                       l_iter = l_first = BM_FACE_FIRST_LOOP(f);
-                       do {
-                               BMLoop *l_other = l_iter->radial_next;
-                               if ((l_other != l_iter) && filter_fn(l_iter->e, user_data)) {
-                                       if (BM_elem_flag_test(l_other->f, BM_ELEM_TAG) == false) {
-                                               BM_elem_flag_enable(l_other->f, BM_ELEM_TAG);
-                                               STACK_PUSH(fstack, l_other->f);
+                       if (htype_step & BM_EDGE) {
+                               /* search for other faces */
+                               l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+                               do {
+                                       BMLoop *l_radial_iter = l_iter->radial_next;
+                                       if ((l_radial_iter != l_iter) &&
+                                           ((filter_fn == NULL) || filter_fn((BMElem *)l_iter->e, user_data)))
+                                       {
+                                               do {
+                                                       BMFace *f_other = l_radial_iter->f;
+                                                       if (BM_elem_flag_test(f_other, BM_ELEM_TAG) == false) {
+                                                               BM_elem_flag_enable(f_other, BM_ELEM_TAG);
+                                                               STACK_PUSH(stack, f_other);
+                                                       }
+                                               } while ((l_radial_iter = l_radial_iter->radial_next) != l_iter);
+                                       }
+                               } while ((l_iter = l_iter->next) != l_first);
+                       }
+
+                       if (htype_step & BM_VERT) {
+                               BMIter liter;
+                               /* search for other faces */
+                               l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+                               do {
+                                       if ((filter_fn == NULL) || filter_fn((BMElem *)l_iter->v, user_data)) {
+                                               BMLoop *l_other;
+                                               BM_ITER_ELEM (l_other, &liter, l_iter, BM_LOOPS_OF_LOOP) {
+                                                       BMFace *f_other = l_other->f;
+                                                       if (BM_elem_flag_test(f_other, BM_ELEM_TAG) == false) {
+                                                               BM_elem_flag_enable(f_other, BM_ELEM_TAG);
+                                                               STACK_PUSH(stack, f_other);
+                                                       }
+                                               }
+                                       }
+                               } while ((l_iter = l_iter->next) != l_first);
+                       }
+               }
+
+               group_curr++;
+       }
+
+       MEM_freeN(stack);
+
+       /* reduce alloc to required size */
+       group_index = MEM_reallocN(group_index, sizeof(*group_index) * group_curr);
+       *r_group_index = group_index;
+
+       return group_curr;
+}
+
+/* note, almost duplicate of BM_mesh_calc_face_groups, keep in sync */
+/**
+ * Calculate isolated groups of edges with optional filtering.
+ *
+ * \param bm  the BMesh.
+ * \param r_groups_array  Array of ints to fill in, length of bm->totedge
+ *        (or when hflag_test is set, the number of flagged edges).
+ * \param r_group_index  index, length pairs into \a r_groups_array, size of return value
+ *        int pairs: (array_start, array_length).
+ * \param filter_fn  Filter the edges or verts we step over (depends on \a htype_step)
+ *        as to which types we deal with.
+ * \param user_data  Optional user data for \a filter_fn, can be NULL.
+ * \param hflag_test  Optional flag to test edges,
+ *        use to exclude edges from the calculation, 0 for all edges.
+ * \return The number of groups found.
+ *
+ * \note Unlike #BM_mesh_calc_face_groups there is no 'htype_step' argument,
+ *       since we always walk over verts.
+ */
+int BM_mesh_calc_edge_groups(BMesh *bm, int *r_groups_array, int (**r_group_index)[2],
+                             BMElemFilterFunc filter_fn, void *user_data,
+                             const char hflag_test)
+{
+#ifdef DEBUG
+       int group_index_len = 1;
+#else
+       int group_index_len = 32;
+#endif
+
+       int (*group_index)[2] = MEM_mallocN(sizeof(*group_index) * group_index_len, __func__);
+
+       int *group_array = r_groups_array;
+       STACK_DECLARE(group_array);
+
+       int group_curr = 0;
+
+       unsigned int tot_edges = 0;
+       unsigned int tot_touch = 0;
+
+       BMEdge **stack;
+       STACK_DECLARE(stack);
+
+       BMIter iter;
+       BMEdge *e;
+       int i;
+
+       STACK_INIT(group_array);
+
+       /* init the array */
+       BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) {
+               if ((hflag_test == 0) || BM_elem_flag_test(e, hflag_test)) {
+                       tot_edges++;
+                       BM_elem_flag_disable(e, BM_ELEM_TAG);
+               }
+               else {
+                       /* never walk over tagged */
+                       BM_elem_flag_enable(e, BM_ELEM_TAG);
+               }
+
+               BM_elem_index_set(e, i); /* set_inline */
+       }
+       bm->elem_index_dirty &= ~BM_FACE;
+
+       /* detect groups */
+       stack = MEM_mallocN(sizeof(*stack) * tot_edges, __func__);
+
+       while (tot_touch != tot_edges) {
+               int *group_item;
+               bool ok = false;
+
+               BLI_assert(tot_touch < tot_edges);
+
+               STACK_INIT(stack);
+
+               BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
+                       if (BM_elem_flag_test(e, BM_ELEM_TAG) == false) {
+                               BM_elem_flag_enable(e, BM_ELEM_TAG);
+                               STACK_PUSH(stack, e);
+                               ok = true;
+                               break;
+                       }
+               }
+
+               BLI_assert(ok == true);
+
+               /* manage arrays */
+               if (group_index_len == group_curr) {
+                       group_index_len *= 2;
+                       group_index = MEM_reallocN(group_index, sizeof(*group_index) * group_index_len);
+               }
+
+               group_item = group_index[group_curr];
+               group_item[0] = STACK_SIZE(group_array);
+               group_item[1] = 0;
+
+               while ((e = STACK_POP(stack))) {
+                       BMIter viter;
+                       BMIter eiter;
+                       BMVert *v;
+
+                       /* add edge */
+                       STACK_PUSH(group_array, BM_elem_index_get(e));
+                       tot_touch++;
+                       group_item[1]++;
+                       /* done */
+
+                       /* search for other edges */
+                       BM_ITER_ELEM (v, &viter, e, BM_VERTS_OF_EDGE) {
+                               if ((filter_fn == NULL) || filter_fn((BMElem *)v, user_data)) {
+                                       BMEdge *e_other;
+                                       BM_ITER_ELEM (e_other, &eiter, v, BM_EDGES_OF_VERT) {
+                                               if (BM_elem_flag_test(e_other, BM_ELEM_TAG) == false) {
+                                                       BM_elem_flag_enable(e_other, BM_ELEM_TAG);
+                                                       STACK_PUSH(stack, e_other);
+                                               }
                                        }
                                }
-                       } while ((l_iter = l_iter->next) != l_first);
+                       }
                }
 
                group_curr++;
        }
 
-       MEM_freeN(fstack);
+       MEM_freeN(stack);
 
        /* reduce alloc to required size */
        group_index = MEM_reallocN(group_index, sizeof(*group_index) * group_curr);
@@ -1890,6 +2064,7 @@ float bmesh_subd_falloff_calc(const int falloff, float val)
                        break;
                default:
                        BLI_assert(0);
+                       break;
        }
 
        return val;
index 94dae1d1d239cb28044a76bc0e8c113369316b45..23d89cf92faf41fa0f4cb33004e135aae2e8449c 100644 (file)
@@ -27,6 +27,8 @@
  *  \ingroup bmesh
  */
 
+typedef bool (*BMElemFilterFunc)(BMElem *, void *user_data);
+
 bool    BM_vert_in_face(BMFace *f, BMVert *v);
 int     BM_verts_in_face_count(BMFace *f, BMVert **varr, int len);
 bool    BM_verts_in_face(BMFace *f, BMVert **varr, int len);
@@ -115,8 +117,13 @@ bool BM_face_is_any_vert_flag_test(BMFace *f, const char hflag);
 bool BM_face_is_any_edge_flag_test(BMFace *f, const char hflag);
 
 float BM_mesh_calc_volume(BMesh *bm, bool is_signed);
+
 int   BM_mesh_calc_face_groups(BMesh *bm, int *r_groups_array, int (**r_group_index)[2],
-                               void *user_data, bool (*filter_fn)(BMEdge *, void *user_data));
+                               BMElemFilterFunc filter_fn, void *user_data,
+                               const char hflag_test, const char htype_step);
+int   BM_mesh_calc_edge_groups(BMesh *bm, int *r_groups_array, int (**r_group_index)[2],
+                               BMElemFilterFunc filter_fn, void *user_data,
+                               const char hflag_test);
 
 /* not really any good place  to put this */
 float bmesh_subd_falloff_calc(const int falloff, float val);
index d65e2669a58dfd3363920139390cdbda3ce8df59..481039694740db1a535a2f5b165289d5346512bf 100644 (file)
@@ -150,10 +150,7 @@ static BMFace *copy_face(BMOperator *op,
 #endif
 
        /* lookup edge */
-       for (i = 0, source_loop = BM_iter_new(&iter, source_mesh, BM_LOOPS_OF_FACE, source_face);
-            source_loop;
-            source_loop = BM_iter_step(&iter), i++)
-       {
+       BM_ITER_ELEM_INDEX (source_loop, &iter, source_face, BM_LOOPS_OF_FACE, i) {
                vtar[i] = BLI_ghash_lookup(vhash, source_loop->v);
                edar[i] = BLI_ghash_lookup(ehash, source_loop->e);
        }
index 4291fc22793e840d8c2820151fa9f741a20db294..025b8557331993c1ec607d033ac6ab4ca2cacb37 100644 (file)
@@ -40,9 +40,9 @@
 #define FACE_FLIP      (1 << 1)
 #define FACE_TEMP      (1 << 2)
 
-static bool bmo_recalc_normal_edge_filter_cb(BMEdge *e, void *UNUSED(user_data))
+static bool bmo_recalc_normal_edge_filter_cb(BMElem *ele, void *UNUSED(user_data))
 {
-       return BM_edge_is_manifold(e);
+       return BM_edge_is_manifold((BMEdge *)ele);
 }
 
 /**
@@ -115,7 +115,7 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f
                do {
                        BMLoop *l_other = l_iter->radial_next;
 
-                       if ((l_other != l_iter) && bmo_recalc_normal_edge_filter_cb(l_iter->e, NULL)) {
+                       if ((l_other != l_iter) && bmo_recalc_normal_edge_filter_cb((BMElem *)l_iter->e, NULL)) {
                                if (!BMO_elem_flag_test(bm, l_other->f, FACE_TEMP)) {
                                        BMO_elem_flag_enable(bm, l_other->f, FACE_TEMP);
                                        BMO_elem_flag_set(bm, l_other->f, FACE_FLIP, (l_other->v == l_iter->v) != flip_state);
@@ -146,14 +146,15 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f
 
 void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op)
 {
-       int *groups_array = MEM_mallocN(sizeof(groups_array) * bm->totface, __func__);
+       int *groups_array = MEM_mallocN(sizeof(*groups_array) * bm->totface, __func__);
        int faces_len;
        BMFace **faces_arr = BM_iter_as_arrayN(bm, BM_FACES_OF_MESH, NULL, &faces_len, NULL, 0);
-       BMFace **faces_grp = MEM_mallocN(sizeof(faces_grp) * bm->totface, __func__);
+       BMFace **faces_grp = MEM_mallocN(sizeof(*faces_grp) * bm->totface, __func__);
 
        int (*group_index)[2];
        const int group_tot = BM_mesh_calc_face_groups(bm, groups_array, &group_index,
-                                                      NULL, bmo_recalc_normal_edge_filter_cb);
+                                                      bmo_recalc_normal_edge_filter_cb, NULL,
+                                                      0, BM_EDGE);
        int i;
 
 
index b02f9cdfaa6af571d801efcdbdb5ec486d7ae69e..2d6ceb23f37f8c7c0f2462c365c53cf43da416ad 100644 (file)
@@ -262,6 +262,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op)
 #endif
                                        default:
                                                BLI_assert(0);
+                                               break;
                                }
                        }
                }
@@ -495,6 +496,7 @@ void bmo_similar_edges_exec(BMesh *bm, BMOperator *op)
 #endif
                                        default:
                                                BLI_assert(0);
+                                               break;
                                }
                        }
                }
@@ -627,6 +629,7 @@ void bmo_similar_verts_exec(BMesh *bm, BMOperator *op)
                                                break;
                                        default:
                                                BLI_assert(0);
+                                               break;
                                }
                        }
                }
index 6b55d5ea87702f29805125378f0fd703ed3b07cd..d0b23c3cdfba70b937b4465039117133c359c259 100644 (file)
@@ -1203,24 +1203,22 @@ void BM_mesh_esubdivide(BMesh *bm, const char edge_hflag,
        
        BMO_op_exec(bm, &op);
        
-       if (seltype == SUBDIV_SELECT_INNER) {
-               BMOIter iter;
-               BMElem *ele;
-
-               for (ele = BMO_iter_new(&iter, op.slots_out, "geom_inner.out", BM_EDGE | BM_VERT); ele; ele = BMO_iter_step(&iter)) {
-                       BM_elem_select_set(bm, ele, true);
-               }
-       }
-       else if (seltype == SUBDIV_SELECT_LOOPCUT) {
-               BMOIter iter;
-               BMElem *ele;
-               
-               /* deselect input */
-               BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false);
-
-               for (ele = BMO_iter_new(&iter, op.slots_out, "geom_inner.out", BM_EDGE); ele; ele = BMO_iter_step(&iter)) {
-                       BM_edge_select_set(bm, (BMEdge *)ele, true);
-               }
+       switch (seltype) {
+               case SUBDIV_SELECT_NONE:
+                       break;
+               case SUBDIV_SELECT_ORIG:
+                       /* set the newly created data to be selected */
+                       BMO_slot_buffer_hflag_enable(bm, op.slots_out, "geom_inner.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
+                       BM_mesh_select_flush(bm);
+                       break;
+               case SUBDIV_SELECT_INNER:
+                       BMO_slot_buffer_hflag_enable(bm, op.slots_out, "geom_inner.out", BM_EDGE | BM_VERT, BM_ELEM_SELECT, true);
+                       break;
+               case SUBDIV_SELECT_LOOPCUT:
+                       /* deselect input */
+                       BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false);
+                       BMO_slot_buffer_hflag_enable(bm, op.slots_out, "geom_inner.out", BM_EDGE, BM_ELEM_SELECT, true);
+                       break;
        }
 
        BMO_op_finish(bm, &op);
diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c
deleted file mode 100644 (file)
index ba553e2..0000000
+++ /dev/null
@@ -1,1160 +0,0 @@
-/*
- * ***** 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 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Geoffrey Bantle and Levi Schooley.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_listBase.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_mesh_types.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_ghash.h"
-#include "BLI_memarena.h"
-
-#include "BKE_editmesh.h"
-#include "BKE_bmesh.h"
-
-#include "bmesh.h"
-#include "intern/bmesh_private.h"
-
-/* BMESH_TODO
- *
- * Date: 2011-11-24 06:25
- * Sender: Andrew Wiggin
- * Status update: I have code changes to actually make basic bevel modifier work. The things that still need to be done:
- * - clean up the changes
- * - get bevel by weight and bevel by angles working for vertex only bevel.
- * - the code uses adaptations of a couple of bmesh APIs,
- * that work a little differently. for example, a join faces that doesn't just create a new face and then delete the
- * original two faces and all associated loops, it extends one of the original faces to cover all the original loops
- * (except for the loop on the join edge which is of course deleted). the bevel code currently requires this because it
- * expects to be able to continue walking loop lists and doesn't like for loops to be deleted out from under it
- * while working...
- * but bmesh APIs don't do it this way because it makes it trickier to manage the interp during these operations,
- * so I need to decide what to do in these cases.
- */
-
-/* BMESH_TODO - resolve this */
-#define BMESH_263_VERT_BEVEL_WORKAROUND
-
-/* ------- Bevel code starts here -------- */
-
-static BME_TransData_Head *BME_init_transdata(int bufsize)
-{
-       BME_TransData_Head *td;
-
-       td = MEM_callocN(sizeof(BME_TransData_Head), "BM transdata header");
-       td->gh = BLI_ghash_ptr_new("BME_init_transdata gh");
-       td->ma = BLI_memarena_new(bufsize, "BME_TransData arena");
-       BLI_memarena_use_calloc(td->ma);
-
-       return td;
-}
-
-void BME_free_transdata(BME_TransData_Head *td)
-{
-       BLI_ghash_free(td->gh, NULL, NULL);
-       BLI_memarena_free(td->ma);
-       MEM_freeN(td);
-}
-
-static BME_TransData *BME_assign_transdata(BME_TransData_Head *td, BMesh *bm, BMVert *v,
-                                           float *co, float *org, float *vec, float *loc,
-                                           float factor, float weight, float maxfactor, float *max)
-{
-       BME_TransData *vtd;
-       int is_new = false;
-
-       if (v == NULL) {
-               return NULL;
-       }
-
-       if ((vtd = BLI_ghash_lookup(td->gh, v)) == NULL && bm != NULL) {
-               vtd = BLI_memarena_alloc(td->ma, sizeof(*vtd));
-               BLI_ghash_insert(td->gh, v, vtd);
-               td->len++;
-               is_new = true;
-       }
-
-       vtd->bm = bm;
-       vtd->v = v;
-
-       if (co != NULL) {
-               copy_v3_v3(vtd->co, co);
-       }
-
-       if (org == NULL && is_new) {
-               copy_v3_v3(vtd->org, v->co); /* default */
-       }
-       else if (org != NULL) {
-               copy_v3_v3(vtd->org, org);
-       }
-
-       if (vec != NULL) {
-               copy_v3_v3(vtd->vec, vec);
-               normalize_v3(vtd->vec);
-       }
-
-       vtd->loc = loc;
-
-       vtd->factor = factor;
-       vtd->weight = weight;
-       vtd->maxfactor = maxfactor;
-       vtd->max = max;
-
-       return vtd;
-}
-
-BME_TransData *BME_get_transdata(BME_TransData_Head *td, BMVert *v)
-{
-       BME_TransData *vtd;
-       vtd = BLI_ghash_lookup(td->gh, v);
-       return vtd;
-}
-
-/* a hack (?) to use the transdata memarena to allocate floats for use with the max limits */
-static float *BME_new_transdata_float(BME_TransData_Head *td)
-{
-       return BLI_memarena_alloc(td->ma, sizeof(float));
-}
-
-/* ported from before bmesh merge into trunk (was called)
- * problem with this is it creates 2 vert faces */
-static void BME_Bevel_Dissolve_Disk(BMesh *bm, BMVert *v)
-{
-       BMFace *f;
-       BMEdge *e;
-       bool done;
-
-       if (v->e) {
-               done = false;
-               while (!done) {
-                       done = true;
-                       e = v->e; /*loop the edge looking for a edge to dissolve*/
-                       do {
-                               f = NULL;
-                               if (BM_edge_is_manifold(e)) {
-                                       f = bmesh_jfke(bm, e->l->f, e->l->radial_next->f, e);
-                               }
-                               if (f) {
-                                       done = false;
-                                       break;
-                               }
-                               e = bmesh_disk_edge_next(e, v);
-                       } while (e != v->e);
-               }
-               BM_vert_collapse_edge(bm, v->e, v, true);
-               // bmesh_jekv(bm, v->e, v, false);
-       }
-}
-
-static int BME_bevel_is_split_vert(BMesh *bm, BMLoop *l)
-{
-       /* look for verts that have already been added to the edge when
-        * beveling other polys; this can be determined by testing the
-        * vert and the edges around it for originality
-        */
-       if (!BMO_elem_flag_test(bm, l->v, BME_BEVEL_ORIG) &&
-           BMO_elem_flag_test(bm, l->e, BME_BEVEL_ORIG) &&
-           BMO_elem_flag_test(bm, l->prev->e, BME_BEVEL_ORIG))
-       {
-               return 1;
-       }
-       return 0;
-}
-
-/* get a vector, vec, that points from v1->co to wherever makes sense to
- * the bevel operation as a whole based on the relationship between v1 and v2
- * (won't necessarily be a vec from v1->co to v2->co, though it probably will be);
- * the return value is -1 for failure, 0 if we used vert co's, and 1 if we used transform origins */
-static int BME_bevel_get_vec(float vec[3], BMVert *v1, BMVert *v2, BME_TransData_Head *td)
-{
-       BME_TransData *vtd1, *vtd2;
-
-       vtd1 = BME_get_transdata(td, v1);
-       vtd2 = BME_get_transdata(td, v2);
-       if (!vtd1 || !vtd2) {
-               //printf("BME_bevel_get_vec() got called without proper BME_TransData\n");
-               return -1;
-       }
-
-       /* compare the transform origins to see if we can use the vert co's;
-        * if they belong to different origins, then we will use the origins to determine
-        * the vector */
-       if (compare_v3v3(vtd1->org, vtd2->org, 0.000001f)) {
-               sub_v3_v3v3(vec, v2->co, v1->co);
-               if (len_v3(vec) < 0.000001f) {
-                       zero_v3(vec);
-               }
-               return 0;
-       }
-       else {
-               sub_v3_v3v3(vec, vtd2->org, vtd1->org);
-               if (len_v3(vec) < 0.000001f) {
-                       zero_v3(vec);
-               }
-               return 1;
-       }
-}
-
-/* "Projects" a vector perpendicular to vec2 against vec1, such that
- * the projected vec1 + vec2 has a min distance of 1 from the "edge" defined by vec2.
- * note: the direction, is_forward, is used in conjunction with up_vec to determine
- * whether this is a convex or concave corner. If it is a concave corner, it will
- * be projected "backwards." If vec1 is before vec2, is_forward should be 0 (we are projecting backwards).
- * vec1 is the vector to project onto (expected to be normalized)
- * vec2 is the direction of projection (pointing away from vec1)
- * up_vec is used for orientation (expected to be normalized)
- * returns the length of the projected vector that lies along vec1 */
-static float BME_bevel_project_vec(float *vec1, float *vec2, float *up_vec,
-                                   int is_forward, BME_TransData_Head *UNUSED(td))
-{
-       float factor, vec3[3], tmp[3], c1, c2;
-
-       cross_v3_v3v3(tmp, vec1, vec2);
-       normalize_v3(tmp);
-       factor = dot_v3v3(up_vec, tmp);
-       if ((factor > 0 && is_forward) || (factor < 0 && !is_forward)) {
-               cross_v3_v3v3(vec3, vec2, tmp); /* hmm, maybe up_vec should be used instead of tmp */
-       }
-       else {
-               cross_v3_v3v3(vec3, tmp, vec2); /* hmm, maybe up_vec should be used instead of tmp */
-       }
-       normalize_v3(vec3);
-       c1 = dot_v3v3(vec3, vec1);
-       c2 = dot_v3v3(vec1, vec1);
-       if (fabsf(c1) < 0.000001f || fabsf(c2) < 0.000001f) {
-               factor = 0.0f;
-       }
-       else {
-               factor = c2 / c1;
-       }
-
-       return factor;
-}
-
-/* BME_bevel_split_edge() is the main math work-house; its responsibilities are:
- * using the vert and the loop passed, get or make the split vert, set its coordinates
- * and transform properties, and set the max limits.
- * Finally, return the split vert. */
-static BMVert *BME_bevel_split_edge(BMesh *bm, BMVert *v, BMVert *v1, BMLoop *l,
-                                    float *up_vec, float value, BME_TransData_Head *td)
-{
-       BME_TransData *vtd, *vtd1, *vtd2;
-       BMVert *sv, *v2, *v3, *ov;
-       BMLoop *lv1, *lv2;
-       BMEdge *ne, *e1, *e2;
-       float maxfactor, scale, len, dis, vec1[3], vec2[3], t_up_vec[3];
-       int is_edge, forward, is_split_vert;
-
-       /* ov, vtd2, and is_split_vert are set but UNUSED */
-       (void)ov, (void)vtd2, (void)is_split_vert;
-
-       if (l == NULL) {
-               /* what you call operator overloading in C :)
-                * I wanted to use the same function for both wire edges and poly loops
-                * so... here we walk around edges to find the needed verts */
-               forward = 1;
-               is_split_vert = 0;
-               if (v->e == NULL) {
-                       //printf("We can't split a loose vert's edge!\n");
-                       return NULL;
-               }
-               e1 = v->e; /* we just use the first two edges */
-               e2 = bmesh_disk_edge_next(v->e, v);
-               if (e1 == e2) {
-                       //printf("You need at least two edges to use BME_bevel_split_edge()\n");
-                       return NULL;
-               }
-               v2 = BM_edge_other_vert(e1, v);
-               v3 = BM_edge_other_vert(e2, v);
-               if (v1 != v2 && v1 != v3) {
-                       //printf("Error: more than 2 edges in v's disk cycle, or v1 does not share an edge with v\n");
-                       return NULL;
-               }
-               if (v1 == v2) {
-                       v2 = v3;
-               }
-               else {
-                       e1 = e2;
-               }
-               ov = BM_edge_other_vert(e1, v);
-               sv = BM_edge_split(bm, e1, v, &ne, 0.0f);
-               //BME_data_interp_from_verts(bm, v, ov, sv, 0.25); /* this is technically wrong.. */
-               //BME_data_interp_from_faceverts(bm, v, ov, sv, 0.25);
-               //BME_data_interp_from_faceverts(bm, ov, v, sv, 0.25);
-               BME_assign_transdata(td, bm, sv, sv->co, sv->co, NULL, sv->co, 0, -1, -1, NULL); /* quick default */
-               BMO_elem_flag_enable(bm, sv, BME_BEVEL_BEVEL);
-               BMO_elem_flag_enable(bm, ne, BME_BEVEL_ORIG); /* mark edge as original, even though it isn't */
-               BME_bevel_get_vec(vec1, v1, v, td);
-               BME_bevel_get_vec(vec2, v2, v, td);
-               cross_v3_v3v3(t_up_vec, vec1, vec2);
-               normalize_v3(t_up_vec);
-               up_vec = t_up_vec;
-       }
-       else {
-               /* establish loop direction */
-               if (l->v == v) {
-                       forward = 1;
-                       lv1 = l->next;
-                       lv2 = l->prev;
-                       v1 = l->next->v;
-                       v2 = l->prev->v;
-               }
-               else if (l->next->v == v) {
-                       forward = 0;
-                       lv1 = l;
-                       lv2 = l->next->next;
-                       v1 = l->v;
-                       v2 = l->next->next->v;
-               }
-               else {
-                       //printf("ERROR: BME_bevel_split_edge() - v must be adjacent to l\n");
-                       return NULL;
-               }
-
-               if (BME_bevel_is_split_vert(bm, lv1)) {
-                       is_split_vert = 1;
-                       sv = v1;
-                       v1 = forward ? l->next->next->v : l->prev->v;
-               }
-               else {
-                       is_split_vert = 0;
-                       ov = BM_edge_other_vert(l->e, v);
-                       sv = BM_edge_split(bm, l->e, v, &ne, 0.0f);
-                       //BME_data_interp_from_verts(bm, v, ov, sv, 0.25); /* this is technically wrong.. */
-                       //BME_data_interp_from_faceverts(bm, v, ov, sv, 0.25);
-                       //BME_data_interp_from_faceverts(bm, ov, v, sv, 0.25);
-                       BME_assign_transdata(td, bm, sv, sv->co, sv->co, NULL, sv->co, 0, -1, -1, NULL); /* quick default */
-                       BMO_elem_flag_enable(bm, sv, BME_BEVEL_BEVEL);
-                       BMO_elem_flag_enable(bm, ne, BME_BEVEL_ORIG); /* mark edge as original, even though it isn't */
-               }
-
-               if (BME_bevel_is_split_vert(bm, lv2)) {
-                       v2 = forward ? lv2->prev->v : lv2->next->v;
-               }
-       }
-
-       is_edge = BME_bevel_get_vec(vec1, v, v1, td); /* get the vector we will be projecting onto */
-       BME_bevel_get_vec(vec2, v, v2, td); /* get the vector we will be projecting parallel to */
-       len = normalize_v3(vec1);
-
-       vtd = BME_get_transdata(td, sv);
-       vtd1 = BME_get_transdata(td, v);
-       vtd2 = BME_get_transdata(td, v1);
-
-       if (vtd1->loc == NULL) {
-               /* this is a vert with data only for calculating initial weights */
-               if (vtd1->weight < 0.0f) {
-                       vtd1->weight = 0.0f;
-               }
-               scale = vtd1->weight / vtd1->factor;
-               if (!vtd1->max) {
-                       vtd1->max = BME_new_transdata_float(td);
-                       *vtd1->max = -1;
-               }
-       }
-       else {
-               scale = vtd1->weight;
-       }
-       vtd->max = vtd1->max;
-
-       if (is_edge && vtd1->loc != NULL) {
-               maxfactor = vtd1->maxfactor;
-       }
-       else {
-               maxfactor = scale * BME_bevel_project_vec(vec1, vec2, up_vec, forward, td);
-               if (vtd->maxfactor > 0 && vtd->maxfactor < maxfactor) {
-                       maxfactor = vtd->maxfactor;
-               }
-       }
-
-       dis = BMO_elem_flag_test(bm, v1, BME_BEVEL_ORIG) ? len / 3 : len / 2;
-       if (is_edge || dis > maxfactor * value) {
-               dis = maxfactor * value;
-       }
-       madd_v3_v3v3fl(sv->co, v->co, vec1, dis);
-       sub_v3_v3v3(vec1, sv->co, vtd1->org);
-       dis = normalize_v3(vec1);
-       BME_assign_transdata(td, bm, sv, vtd1->org, vtd1->org, vec1, sv->co, dis, scale, maxfactor, vtd->max);
-
-       return sv;
-}
-
-#if 0 /* UNUSED */
-static float BME_bevel_set_max(BMVert *v1, BMVert *v2, float value, BME_TransData_Head *td)
-{
-       BME_TransData *vtd1, *vtd2;
-       float max, fac1, fac2, vec1[3], vec2[3], vec3[3];
-
-       BME_bevel_get_vec(vec1, v1, v2, td);
-       vtd1 = BME_get_transdata(td, v1);
-       vtd2 = BME_get_transdata(td, v2);
-
-       if (vtd1->loc == NULL) {
-               fac1 = 0;
-       }
-       else {
-               copy_v3_v3(vec2, vtd1->vec);
-               mul_v3_fl(vec2, vtd1->factor);
-               if (dot_v3v3(vec1, vec1)) {
-                       project_v3_v3v3(vec2, vec2, vec1);
-                       fac1 = len_v3(vec2) / value;
-               }
-               else {
-                       fac1 = 0;
-               }
-       }
-
-       if (vtd2->loc == NULL) {
-               fac2 = 0;
-       }
-       else {
-               copy_v3_v3(vec3, vtd2->vec);
-               mul_v3_fl(vec3, vtd2->factor);
-               if (dot_v3v3(vec1, vec1)) {
-                       project_v3_v3v3(vec2, vec3, vec1);
-                       fac2 = len_v3(vec2) / value;
-               }
-               else {
-                       fac2 = 0;
-               }
-       }
-
-       if (fac1 || fac2) {
-               max = len_v3(vec1) / (fac1 + fac2);
-               if (vtd1->max && (*vtd1->max < 0 || max < *vtd1->max)) {
-                       *vtd1->max = max;
-               }
-               if (vtd2->max && (*vtd2->max < 0 || max < *vtd2->max)) {
-                       *vtd2->max = max;
-               }
-       }
-       else {
-               max = -1;
-       }
-
-       return max;
-}
-#endif
-
-#if 0 /* UNUSED */
-static BMVert *BME_bevel_wire(BMesh *bm, BMVert *v, float value, int res, int UNUSED(options), BME_TransData_Head *td)
-{
-       BMVert *ov1, *ov2, *v1, *v2;
-
-       ov1 = BM_edge_other_vert(v->e, v);
-       ov2 = BM_edge_other_vert(bmesh_disk_edge_next(v->e, v), v);
-
-       /* split the edges */
-       v1 = BME_bevel_split_edge(bm, v, ov1, NULL, NULL, value, td);
-       BMO_elem_flag_enable(bm, v1, BME_BEVEL_NONMAN);
-       v2 = BME_bevel_split_edge(bm, v, ov2, NULL, NULL, value, td);
-       BMO_elem_flag_enable(bm, v2, BME_BEVEL_NONMAN);
-
-       if (value > 0.5) {
-               BME_bevel_set_max(v1, ov1, value, td);
-               BME_bevel_set_max(v2, ov2, value, td);
-       }
-
-       /* remove the original vert */
-       if (res) {
-               /* bmesh_jekv; */
-
-               //void BM_vert_collapse_faces(BMesh *bm, BMEdge *ke, BMVert *kv, float fac, int calcnorm) {
-               //hrm, why is there a fac here? it just removes a vert
-               BM_vert_collapse_edge(bm, v->e, v);
-       }
-
-       return v1;
-}
-#endif
-
-static BMLoop *BME_bevel_edge(BMesh *bm, BMLoop *l, float value, int UNUSED(options),
-                              float *up_vec, BME_TransData_Head *td)
-{
-       BMVert *v1, *v2, *kv;
-       BMLoop *kl = NULL, *nl;
-       BMEdge *e, *ke, *se;
-       BMFace *f, *jf;
-
-       f = l->f;
-       e = l->e;
-
-       /* sanity check */
-       if (!BMO_elem_flag_test(bm, l->e, BME_BEVEL_BEVEL) &&
-           (BMO_elem_flag_test(bm, l->v, BME_BEVEL_BEVEL) || BMO_elem_flag_test(bm, l->next->v, BME_BEVEL_BEVEL)))
-       {
-               return l;
-       }
-
-       /* checks and operations for prev edge */
-       /* first, check to see if this edge was inset previously */
-       if (!BMO_elem_flag_test(bm, l->prev->e, BME_BEVEL_ORIG) &&
-           !BMO_elem_flag_test(bm, l->v, BME_BEVEL_NONMAN))
-       {
-               kl = l->prev->radial_next;
-               kl = (kl->v == l->v) ? kl->prev : kl->next;
-               kv = l->v;
-       }
-       else {
-               kv = NULL;
-       }
-       /* get/make the first vert to be used in SFME */
-       if (BMO_elem_flag_test(bm, l->v, BME_BEVEL_NONMAN)) {
-               v1 = l->v;
-       }
-       else { /* we'll need to split the previous edge */
-               v1 = BME_bevel_split_edge(bm, l->v, NULL, l->prev, up_vec, value, td);
-       }
-       /* if we need to clean up geometry... */
-       if (kv) {
-               se = l->next->e;
-               jf = NULL;
-               if (kl->v == kv) {
-                       BM_face_split(bm, kl->f, kl->prev->v, kl->next->v, &nl, kl->prev->e, true);
-                       ke = kl->e;
-                       /* BMESH-TODO: jfke doesn't handle customdata */
-                       jf = bmesh_jfke(bm, kl->prev->radial_next->f, kl->f, kl->prev->e);
-                       BM_vert_collapse_edge(bm, ke, kv, false);
-               }
-               else {
-                       BM_face_split(bm, kl->f, kl->next->next->v, kl->v, &nl, kl->next->e, true);
-                       ke = kl->e;
-                       /* BMESH-TODO: jfke doesn't handle customdata */
-                       jf = bmesh_jfke(bm, kl->next->radial_next->f, kl->f, kl->next->e);
-                       BM_vert_collapse_edge(bm, ke, kv, false);
-               }
-               /* find saved loop pointer */
-               l = se->l;
-               while (l->f != jf) {
-                       l = l->radial_next;
-                       BLI_assert(l != se->l);
-               }
-               l = l->prev;
-       }
-
-       /* checks and operations for the next edge */
-       /* first, check to see if this edge was inset previously  */
-       if (!BMO_elem_flag_test(bm, l->next->e, BME_BEVEL_ORIG) &&
-           !BMO_elem_flag_test(bm, l->next->v, BME_BEVEL_NONMAN))
-       {
-               kl = l->next->radial_next;
-               kl = (kl->v == l->next->v) ? kl->prev : kl->next;
-               kv = l->next->v;
-       }
-       else {
-               kv = NULL;
-       }
-       /* get/make the second vert to be used in SFME */
-       if (BMO_elem_flag_test(bm, l->next->v, BME_BEVEL_NONMAN)) {
-               v2 = l->next->v;
-       }
-       else { /* we'll need to split the next edge */
-               v2 = BME_bevel_split_edge(bm, l->next->v, NULL, l->next, up_vec, value, td);
-       }
-       /* if we need to clean up geometry... */
-       if (kv) {
-               se = l->e;
-               jf = NULL;
-               if (kl->v == kv) {
-                       BM_face_split(bm, kl->f, kl->prev->v, kl->next->v, &nl, kl->prev->e, true);
-                       ke = kl->e;
-                       /* BMESH-TODO: jfke doesn't handle customdata */
-                       jf = bmesh_jfke(bm, kl->prev->radial_next->f, kl->f, kl->prev->e);
-                       BM_vert_collapse_edge(bm, ke, kv, false);
-               }
-               else {
-                       BM_face_split(bm, kl->f, kl->next->next->v, kl->v, &nl, kl->next->e, true);
-                       ke = kl->e;
-                       /* BMESH-TODO: jfke doesn't handle customdata */
-                       jf = bmesh_jfke(bm, kl->next->radial_next->f, kl->f, kl->next->e);
-                       BM_vert_collapse_edge(bm, ke, kv, false);
-               }
-               /* find saved loop pointer */
-               l = se->l;
-               while (l->f != jf) {
-                       l = l->radial_next;
-                       BLI_assert(l != se->l);
-               }
-       }
-
-       if (!BMO_elem_flag_test(bm, v1, BME_BEVEL_NONMAN) || !BMO_elem_flag_test(bm, v2, BME_BEVEL_NONMAN)) {
-               BM_face_split(bm, f, v2, v1, &l, e, true);
-               BMO_elem_flag_enable(bm, l->e, BME_BEVEL_BEVEL);
-               l = l->radial_next;
-       }
-
-       if (l->f != f) {
-               //printf("Whoops! You got something out of order in BME_bevel_edge()!\n");
-       }
-
-       return l;
-}
-
-static BMLoop *BME_bevel_vert(BMesh *bm, BMLoop *l, float value, int UNUSED(options),
-                              float up_vec[3], BME_TransData_Head *td)
-{
-       BMVert *v1, *v2;
-       /* BMFace *f; */ /* UNUSED */
-
-       /* get/make the first vert to be used in SFME */
-       /* may need to split the previous edge */
-       v1 = BME_bevel_split_edge(bm, l->v, NULL, l->prev, up_vec, value, td);
-
-       /* get/make the second vert to be used in SFME */
-       /* may need to split this edge (so move l) */
-       l = l->prev;
-       v2 = BME_bevel_split_edge(bm, l->next->v, NULL, l->next, up_vec, value, td);
-       l = l->next->next;
-
-       /* "cut off" this corner */
-       /* f = */ BM_face_split(bm, l->f, v2, v1, NULL, l->e, true);
-
-       return l;
-}
-
-/*
- *                     BME_bevel_poly
- *
- *     Polygon inset tool:
- *
- *     Insets a polygon/face based on the flagss of its vertices
- *     and edges. Used by the bevel tool only, for now.
- *  The parameter "value" is the distance to inset (should be negative).
- *  The parameter "options" is not currently used.
- *
- *     Returns -
- *  A BMFace pointer to the resulting inner face.
- */
-static BMFace *BME_bevel_poly(BMesh *bm, BMFace *f, float value, int options, BME_TransData_Head *td)
-{
-       BMLoop *l /*, *o */;
-       BME_TransData *vtd1, *vtd2;
-       float up_vec[3], vec1[3], vec2[3], vec3[3], fac1, fac2, max = -1;
-       int len, i;
-       BMIter iter;
-
-       zero_v3(up_vec);
-
-       /* find a good normal for this face (there's better ways, I'm sure) */
-       BM_ITER_ELEM (l, &iter, f, BM_LOOPS_OF_FACE) {
-#ifdef BMESH_263_VERT_BEVEL_WORKAROUND
-               add_newell_cross_v3_v3v3(up_vec, l->prev->v->co, l->v->co);
-#else
-               BME_bevel_get_vec(vec1, l->v, l->next->v, td);
-               BME_bevel_get_vec(vec2, l->prev->v, l->v, td);
-               cross_v3_v3v3(vec3, vec2, vec1);
-               add_v3_v3(up_vec, vec3);
-
-#endif
-       }
-       normalize_v3(up_vec);
-
-       /* Can't use a BM_LOOPS_OF_FACE iterator here, because the loops are being modified
-        * and so the end condition will never hi */
-       for (l = BM_FACE_FIRST_LOOP(f)->prev, i = 0, len = f->len; i < len; i++, l = l->next) {
-               if (BMO_elem_flag_test(bm, l->e, BME_BEVEL_BEVEL) && BMO_elem_flag_test(bm, l->e, BME_BEVEL_ORIG)) {
-                       max = 1.0f;
-                       l = BME_bevel_edge(bm, l, value, options, up_vec, td);
-               }
-               else if (BMO_elem_flag_test(bm, l->v, BME_BEVEL_BEVEL) &&
-                        BMO_elem_flag_test(bm, l->v, BME_BEVEL_ORIG) &&
-                        !BMO_elem_flag_test(bm, l->prev->e, BME_BEVEL_BEVEL))
-               {
-                       /* avoid making double vertices [#33438] */
-                       BME_TransData *vtd;
-                       vtd = BME_get_transdata(td, l->v);
-                       if (vtd->weight == 0.0f) {
-                               BMO_elem_flag_disable(bm, l->v, BME_BEVEL_BEVEL);
-                       }
-                       else {
-                               max = 1.0f;
-                               l = BME_bevel_vert(bm, l, value, options, up_vec, td);
-                       }
-               }
-       }
-
-       f = l->f;
-
-       /* max pass */
-       if (value > 0.5f && max > 0.0f) {
-               max = -1;
-               BM_ITER_ELEM (l, &iter, f, BM_LOOPS_OF_FACE) {
-                       if (BMO_elem_flag_test(bm, l->e, BME_BEVEL_BEVEL) || BMO_elem_flag_test(bm, l->e, BME_BEVEL_ORIG)) {
-                               BME_bevel_get_vec(vec1, l->v, l->next->v, td);
-                               vtd1 = BME_get_transdata(td, l->v);
-                               vtd2 = BME_get_transdata(td, l->next->v);
-                               if (vtd1->loc == NULL) {
-                                       fac1 = 0;
-                               }
-                               else {
-                                       copy_v3_v3(vec2, vtd1->vec);
-                                       mul_v3_fl(vec2, vtd1->factor);
-                                       if (dot_v3v3(vec1, vec1)) {
-                                               project_v3_v3v3(vec2, vec2, vec1);
-                                               fac1 = len_v3(vec2) / value;
-                                       }
-                                       else {
-                                               fac1 = 0;
-                                       }
-                               }
-                               if (vtd2->loc == NULL) {
-                                       fac2 = 0;
-                               }
-                               else {
-                                       copy_v3_v3(vec3, vtd2->vec);
-                                       mul_v3_fl(vec3, vtd2->factor);
-                                       if (dot_v3v3(vec1, vec1)) {
-                                               project_v3_v3v3(vec2, vec3, vec1);
-                                               fac2 = len_v3(vec2) / value;
-                                       }
-                                       else {
-                                               fac2 = 0;
-                                       }
-                               }
-                               if (fac1 || fac2) {
-                                       max = len_v3(vec1) / (fac1 + fac2);
-                                       if (vtd1->max && (*vtd1->max < 0 || max < *vtd1->max)) {
-                                               *vtd1->max = max;
-                                       }
-                                       if (vtd2->max && (*vtd2->max < 0 || max < *vtd2->max)) {
-                                               *vtd2->max = max;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       /* return l->f; */
-       return NULL;
-}
-
-static float BME_bevel_get_angle(BMEdge *e, BMVert *v)
-{
-       BMVert *v1, *v2;
-       BMLoop *l1, *l2;
-       float vec1[3], vec2[3], vec3[3], vec4[3];
-
-       l1 = e->l;
-       l2 = e->l->radial_next;
-       if (l1->v == v) {
-               v1 = l1->prev->v;
-               v2 = l1->next->v;
-       }
-       else {
-               v1 = l1->next->next->v;
-               v2 = l1->v;
-       }
-       sub_v3_v3v3(vec1, v1->co, v->co);
-       sub_v3_v3v3(vec2, v2->co, v->co);
-       cross_v3_v3v3(vec3, vec1, vec2);
-
-       l1 = l2;
-       if (l1->v == v) {
-               v1 = l1->prev->v;
-               v2 = l1->next->v;
-       }
-       else {
-               v1 = l1->next->next->v;
-               v2 = l1->v;
-       }
-       sub_v3_v3v3(vec1, v1->co, v->co);
-       sub_v3_v3v3(vec2, v2->co, v->co);
-       cross_v3_v3v3(vec4, vec2, vec1);
-
-       normalize_v3(vec3);
-       normalize_v3(vec4);
-
-       return dot_v3v3(vec3, vec4);
-}
-
-static float BME_bevel_get_angle_vert(BMVert *v)
-{
-       BMIter iter;
-       BMLoop *l;
-       float n[3];
-       float n_tmp[3];
-       float angle_diff = 0.0f;
-       float tot_angle = 0.0f;
-
-
-       BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
-               const float angle = BM_loop_calc_face_angle(l);
-               tot_angle += angle;
-               BM_loop_calc_face_normal(l, n_tmp);
-               madd_v3_v3fl(n, n_tmp, angle);
-       }
-       normalize_v3(n);
-
-       BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
-               /* could cache from before */
-               BM_loop_calc_face_normal(l, n_tmp);
-               angle_diff += angle_normalized_v3v3(n, n_tmp) * BM_loop_calc_face_angle(l);
-       }
-
-       /* return cosf(angle_diff + 0.001f); */ /* compare with dot product */
-       return (angle_diff / tot_angle) * (float)(M_PI / 2.0);
-}
-
-static void BME_bevel_add_vweight(BME_TransData_Head *td, BMesh *bm, BMVert *v, float weight, float factor, int options)
-{
-       BME_TransData *vtd;
-
-       if (BMO_elem_flag_test(bm, v, BME_BEVEL_NONMAN)) {
-               return;
-       }
-
-       BMO_elem_flag_enable(bm, v, BME_BEVEL_BEVEL);
-       if ((vtd = BME_get_transdata(td, v))) {
-               if (options & BME_BEVEL_EMIN) {
-                       vtd->factor = 1.0;
-                       if (vtd->weight < 0 || weight < vtd->weight) {
-                               vtd->weight = weight;
-                       }
-               }
-               else if (options & BME_BEVEL_EMAX) {
-                       vtd->factor = 1.0;
-                       if (weight > vtd->weight) {
-                               vtd->weight = weight;
-                       }
-               }
-               else if (vtd->weight < 0.0f) {
-                       vtd->factor = factor;
-                       vtd->weight = weight;
-               }
-               else {
-                       vtd->factor += factor; /* increment number of edges with weights (will be averaged) */
-                       vtd->weight += weight; /* accumulate all the weights */
-               }
-       }
-       else {
-               /* we'll use vtd->loc == NULL to mark that this vert is not moving */
-               vtd = BME_assign_transdata(td, bm, v, v->co, NULL, NULL, NULL, factor, weight, -1, NULL);
-       }
-}
-
-static void bevel_init_verts(BMesh *bm, int options, float angle, BME_TransData_Head *td)
-{
-       BMVert *v;
-       BMIter iter;
-       float weight;
-       /* const float threshold = (options & BME_BEVEL_ANGLE) ? cosf(angle + 0.001) : 0.0f; */ /* UNUSED */
-
-       BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-               weight = 0.0f;
-               if (!BMO_elem_flag_test(bm, v, BME_BEVEL_NONMAN)) {
-                       /* modifiers should not use selection */
-                       if (options & BME_BEVEL_SELECT) {
-                               if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
-                                       weight = 1.0f;
-                               }
-                       }
-                       /* bevel weight NYI */
-                       else if (options & BME_BEVEL_WEIGHT) {
-                               weight = BM_elem_float_data_get(&bm->vdata, v, CD_BWEIGHT);
-                       }
-                       else if (options & BME_BEVEL_ANGLE) {
-                               /* dont set weight_v1/weight_v2 here, add direct */
-                               if (BME_bevel_get_angle_vert(v) > angle) {
-                                       weight = 1.0f;
-                               }
-                       }
-                       else {
-                               weight = 1.0f;
-                       }
-
-                       if (weight > 0.0f) {
-                               BMO_elem_flag_enable(bm, v, BME_BEVEL_BEVEL);
-                               BME_assign_transdata(td, bm, v, v->co, v->co, NULL, NULL, 1.0, weight, -1, NULL);
-                       }
-               }
-       }
-}
-
-static void bevel_init_edges(BMesh *bm, int options, float angle, BME_TransData_Head *td)
-{
-       BMEdge *e;
-       int count;
-       float weight;
-       BMIter iter;
-       const float threshold = (options & BME_BEVEL_ANGLE) ? cosf(angle + 0.001f) : 0.0f;
-
-       BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
-               weight = 0.0f;
-               if (!BMO_elem_flag_test(bm, e, BME_BEVEL_NONMAN)) {
-                       if (options & BME_BEVEL_SELECT) {
-                               if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
-                                       weight = 1.0f;
-                               }
-                       }
-                       else if (options & BME_BEVEL_WEIGHT) {
-                               weight = BM_elem_float_data_get(&bm->edata, e, CD_BWEIGHT);
-                       }
-                       else if (options & BME_BEVEL_ANGLE) {
-                               /* dont set weight_v1/weight_v2 here, add direct */
-                               if (!BMO_elem_flag_test(bm, e->v1, BME_BEVEL_NONMAN) && BME_bevel_get_angle(e, e->v1) < threshold) {
-                                       BMO_elem_flag_enable(bm, e, BME_BEVEL_BEVEL);
-                                       BME_bevel_add_vweight(td, bm, e->v1, 1.0, 1.0, options);
-                               }
-                               else {
-                                       BME_bevel_add_vweight(td, bm, e->v1, 0.0, 1.0, options);
-                               }
-                               if (!BMO_elem_flag_test(bm, e->v2, BME_BEVEL_NONMAN) && BME_bevel_get_angle(e, e->v2) < threshold) {
-                                       BMO_elem_flag_enable(bm, e, BME_BEVEL_BEVEL);
-                                       BME_bevel_add_vweight(td, bm, e->v2, 1.0, 1.0, options);
-                               }
-                               else {
-                                       BME_bevel_add_vweight(td, bm, e->v2, 0.0, 1.0, options);
-                               }
-                       }
-                       else {
-                               weight = 1.0f;
-                       }
-
-                       if (weight > 0.0f) {
-                               BMO_elem_flag_enable(bm, e, BME_BEVEL_BEVEL);
-                               BME_bevel_add_vweight(td, bm, e->v1, weight, 1.0, options);
-                               BME_bevel_add_vweight(td, bm, e->v2, weight, 1.0, options);
-                       }
-               }
-       }
-
-       /* clean up edges with 2 faces that share more than one edg */
-       BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
-               if (BMO_elem_flag_test(bm, e, BME_BEVEL_BEVEL)) {
-                       count = BM_face_share_edge_count(e->l->f, e->l->radial_next->f);
-                       if (count > 1) BMO_elem_flag_disable(bm, e, BME_BEVEL_BEVEL);
-               }
-       }
-}
-
-static BMesh *BME_bevel_initialize(BMesh *bm, int options,
-                                   int UNUSED(defgrp_index), float angle, BME_TransData_Head *td)
-{
-       BMVert *v /*, *v2 */;
-       BMEdge *e /*, *curedg */;
-       BMFace *f;
-       BMIter iter;
-       int /* wire, */ len;
-
-       /* tag non-manifold geometry */
-       BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-               BMO_elem_flag_enable(bm, v, BME_BEVEL_ORIG);
-               if (v->e) {
-                       BME_assign_transdata(td, bm, v, v->co, v->co, NULL, NULL, 0, -1, -1, NULL);
-                       if (!BM_vert_is_manifold(v)) {
-                               BMO_elem_flag_enable(bm, v, BME_BEVEL_NONMAN);
-                       }
-
-                       /* test wire ver */
-                       len = BM_vert_edge_count(v);
-                       if (len == 2 && BM_vert_is_wire(v))
-                               BMO_elem_flag_disable(bm, v, BME_BEVEL_NONMAN);
-               }
-               else {
-                       BMO_elem_flag_enable(bm, v, BME_BEVEL_NONMAN);
-               }
-       }
-
-       BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
-               BMO_elem_flag_enable(bm, e, BME_BEVEL_ORIG);
-               if (!(BM_edge_is_boundary(e) || BM_edge_is_manifold(e))) {
-                       BMO_elem_flag_enable(bm, e->v1, BME_BEVEL_NONMAN);
-                       BMO_elem_flag_enable(bm, e->v2, BME_BEVEL_NONMAN);
-                       BMO_elem_flag_enable(bm, e, BME_BEVEL_NONMAN);
-               }
-               if (BMO_elem_flag_test(bm, e->v1, BME_BEVEL_NONMAN) || BMO_elem_flag_test(bm, e->v2, BME_BEVEL_NONMAN)) {
-                       BMO_elem_flag_enable(bm, e, BME_BEVEL_NONMAN);
-               }
-       }
-
-       BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
-               BMO_elem_flag_enable(bm, f, BME_BEVEL_ORIG);
-       }
-
-       if (options & BME_BEVEL_VERT) {
-               bevel_init_verts(bm, options, angle, td);
-       }
-       else {
-               bevel_init_edges(bm, options, angle, td);
-       }
-
-       return bm;
-
-}
-
-#if 0
-
-static BMesh *BME_bevel_reinitialize(BMesh *bm)
-{
-       BMVert *v;
-       BMEdge *e;
-       BMFace *f;
-       BMIter iter;
-
-       BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-               BMO_elem_flag_enable(bm, v, BME_BEVEL_ORIG);
-       }
-       BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
-               BMO_elem_flag_enable(bm, e, BME_BEVEL_ORIG);
-       }
-       BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
-               BMO_elem_flag_enable(bm, f, BME_BEVEL_ORIG);
-       }
-       return bm;
-
-}
-
-#endif
-
-/**
- * BME_bevel_mesh
- *
- * Mesh beveling tool:
- *
- * Bevels an entire mesh. It currently uses the flags of
- * its vertices and edges to track topological changes.
- * The parameter "value" is the distance to inset (should be negative).
- * The parameter "options" is not currently used.
- *
- * \return A BMesh pointer to the BM passed as a parameter.
- */
-
-static BMesh *BME_bevel_mesh(BMesh *bm, float value, int UNUSED(res), int options,
-                             int UNUSED(defgrp_index), BME_TransData_Head *td)
-{
-       BMVert *v;
-       BMEdge *e, *curedge;
-       BMLoop *l, *l2;
-       BMFace *f;
-       BMIter iter;
-
-       /* unsigned int i, len; */
-
-       /* bevel poly */
-       BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
-               if (BMO_elem_flag_test(bm, f, BME_BEVEL_ORIG)) {
-                       BME_bevel_poly(bm, f, value, options, td);
-               }
-       }
-
-       /* get rid of beveled edge */
-       BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
-               if (BMO_elem_flag_test(bm, e, BME_BEVEL_BEVEL) && BMO_elem_flag_test(bm, e, BME_BEVEL_ORIG)) {
-                       BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e, true);
-               }
-       }
-
-       /* link up corners and cli */
-       BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-               if (BMO_elem_flag_test(bm, v, BME_BEVEL_ORIG) && BMO_elem_flag_test(bm, v, BME_BEVEL_BEVEL)) {
-                       curedge = v->e;
-                       do {
-                               l = curedge->l;
-                               l2 = l->radial_next;
-                               if (l->v != v) l = l->next;
-                               if (l2->v != v) l2 = l2->next;
-                               if (l->f->len > 3)
-                                       BM_face_split(bm, l->f, l->next->v, l->prev->v, &l, l->e, true);  /* clip this corner off */
-                               if (l2->f->len > 3)
-                                       BM_face_split(bm, l2->f, l2->next->v, l2->prev->v, &l, l2->e, true);  /* clip this corner off */
-                               curedge = bmesh_disk_edge_next(curedge, v);
-                       } while (curedge != v->e);
-                       BME_Bevel_Dissolve_Disk(bm, v);
-               }
-       }
-
-#ifdef DEBUG
-       /* Debug print, remov */
-       BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
-               if (f->len == 2) {
-                       printf("%s: warning, 2 edge face\n", __func__);
-               }
-       }
-#endif
-
-       return bm;
-}
-
-BMesh *BME_bevel(BMesh *bm, float value, int res, int options, int defgrp_index, float angle,
-                 BME_TransData_Head **rtd)
-{
-       BMVert *v;
-       BMIter iter;
-
-       BME_TransData_Head *td;
-       BME_TransData *vtd;
-       int i;
-       double fac = 1.0, d;
-
-       td = BME_init_transdata(BLI_MEMARENA_STD_BUFSIZE);
-       /* recursion math courtesy of Martin Poirier (theeth) */
-       for (i = 0; i < res - 1; i++) {
-               if (i == 0) fac += 1.0 / 3.0;
-               else        fac += 1.0 /