Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2012-01-22 03:01:25 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2012-01-22 03:01:25 +0400
commit68ae82bb479a79de72cf174763f3244f64e28bb0 (patch)
tree159f1f1a8211ff2d2d89a80f94739cc0f0dfe696
parent3667cddf1ada28b6964bc9beeb7cce31f04e18a8 (diff)
parentb95beea539b22baeb68013c4e65fb0455b968890 (diff)
Merged changes in the trunk up to revision 43585.
Conflicts resolved: source/blender/editors/include/UI_resources.h source/blender/editors/interface/resources.c source/blender/makesrna/intern/rna_scene.c
-rw-r--r--CMakeLists.txt43
-rw-r--r--SConstruct5
-rw-r--r--build_files/cmake/cmake_static_check_cppcheck.py3
-rw-r--r--build_files/cmake/config/blender_lite.cmake3
-rwxr-xr-xbuild_files/cmake/project_info.py4
-rw-r--r--build_files/cmake/project_source_info.py1
-rw-r--r--build_files/scons/tools/Blender.py2
-rw-r--r--build_files/scons/tools/btools.py13
-rw-r--r--extern/CMakeLists.txt4
-rw-r--r--extern/SConscript3
-rw-r--r--extern/carve/CMakeLists.txt166
-rw-r--r--extern/carve/LICENSE.GPL2361
-rw-r--r--extern/carve/SConscript23
-rwxr-xr-xextern/carve/bundle.sh124
-rw-r--r--extern/carve/files.txt107
-rw-r--r--extern/carve/include/carve/aabb.hpp150
-rw-r--r--extern/carve/include/carve/aabb_impl.hpp423
-rw-r--r--extern/carve/include/carve/carve.hpp238
-rw-r--r--extern/carve/include/carve/cbrt.h93
-rw-r--r--extern/carve/include/carve/classification.hpp115
-rw-r--r--extern/carve/include/carve/collection.hpp51
-rw-r--r--extern/carve/include/carve/collection/unordered.hpp43
-rw-r--r--extern/carve/include/carve/collection/unordered/boost_impl.hpp45
-rw-r--r--extern/carve/include/carve/collection/unordered/fallback_impl.hpp40
-rw-r--r--extern/carve/include/carve/collection/unordered/libstdcpp_impl.hpp61
-rw-r--r--extern/carve/include/carve/collection/unordered/std_impl.hpp23
-rw-r--r--extern/carve/include/carve/collection/unordered/tr1_impl.hpp58
-rw-r--r--extern/carve/include/carve/collection/unordered/vcpp_impl.hpp65
-rw-r--r--extern/carve/include/carve/collection_types.hpp63
-rw-r--r--extern/carve/include/carve/colour.hpp47
-rw-r--r--extern/carve/include/carve/config.h12
-rw-r--r--extern/carve/include/carve/convex_hull.hpp52
-rw-r--r--extern/carve/include/carve/csg.hpp498
-rw-r--r--extern/carve/include/carve/csg_triangulator.hpp434
-rw-r--r--extern/carve/include/carve/debug_hooks.hpp97
-rw-r--r--extern/carve/include/carve/djset.hpp134
-rw-r--r--extern/carve/include/carve/edge_decl.hpp68
-rw-r--r--extern/carve/include/carve/edge_impl.hpp23
-rw-r--r--extern/carve/include/carve/exact.hpp702
-rw-r--r--extern/carve/include/carve/face_decl.hpp208
-rw-r--r--extern/carve/include/carve/face_impl.hpp140
-rw-r--r--extern/carve/include/carve/faceloop.hpp103
-rw-r--r--extern/carve/include/carve/geom.hpp363
-rw-r--r--extern/carve/include/carve/geom2d.hpp403
-rw-r--r--extern/carve/include/carve/geom3d.hpp310
-rw-r--r--extern/carve/include/carve/geom_impl.hpp651
-rw-r--r--extern/carve/include/carve/gnu_cxx.h4
-rw-r--r--extern/carve/include/carve/heap.hpp425
-rw-r--r--extern/carve/include/carve/input.hpp251
-rw-r--r--extern/carve/include/carve/interpolator.hpp332
-rw-r--r--extern/carve/include/carve/intersection.hpp267
-rw-r--r--extern/carve/include/carve/iobj.hpp106
-rw-r--r--extern/carve/include/carve/kd_node.hpp308
-rw-r--r--extern/carve/include/carve/math.hpp60
-rw-r--r--extern/carve/include/carve/math_constants.hpp33
-rw-r--r--extern/carve/include/carve/matrix.hpp262
-rw-r--r--extern/carve/include/carve/mesh.hpp845
-rw-r--r--extern/carve/include/carve/mesh_impl.hpp1015
-rw-r--r--extern/carve/include/carve/mesh_ops.hpp975
-rw-r--r--extern/carve/include/carve/mesh_simplify.hpp1574
-rw-r--r--extern/carve/include/carve/octree_decl.hpp193
-rw-r--r--extern/carve/include/carve/octree_impl.hpp79
-rw-r--r--extern/carve/include/carve/pointset.hpp24
-rw-r--r--extern/carve/include/carve/pointset_decl.hpp61
-rw-r--r--extern/carve/include/carve/pointset_impl.hpp36
-rw-r--r--extern/carve/include/carve/pointset_iter.hpp18
-rw-r--r--extern/carve/include/carve/poly.hpp24
-rw-r--r--extern/carve/include/carve/poly_decl.hpp25
-rw-r--r--extern/carve/include/carve/poly_impl.hpp25
-rw-r--r--extern/carve/include/carve/polyhedron_base.hpp149
-rw-r--r--extern/carve/include/carve/polyhedron_decl.hpp184
-rw-r--r--extern/carve/include/carve/polyhedron_impl.hpp287
-rw-r--r--extern/carve/include/carve/polyline.hpp24
-rw-r--r--extern/carve/include/carve/polyline_decl.hpp151
-rw-r--r--extern/carve/include/carve/polyline_impl.hpp160
-rw-r--r--extern/carve/include/carve/polyline_iter.hpp199
-rw-r--r--extern/carve/include/carve/rescale.hpp100
-rw-r--r--extern/carve/include/carve/rtree.hpp501
-rw-r--r--extern/carve/include/carve/spacetree.hpp264
-rw-r--r--extern/carve/include/carve/tag.hpp44
-rw-r--r--extern/carve/include/carve/timing.hpp96
-rw-r--r--extern/carve/include/carve/tree.hpp324
-rw-r--r--extern/carve/include/carve/triangulator.hpp175
-rw-r--r--extern/carve/include/carve/triangulator_impl.hpp851
-rw-r--r--extern/carve/include/carve/util.hpp31
-rw-r--r--extern/carve/include/carve/vcpp_config.h17
-rw-r--r--extern/carve/include/carve/vector.hpp163
-rw-r--r--extern/carve/include/carve/vertex_decl.hpp111
-rw-r--r--extern/carve/include/carve/vertex_impl.hpp24
-rwxr-xr-xextern/carve/include/carve/win32.h55
-rw-r--r--extern/carve/lib/aabb.cpp29
-rw-r--r--extern/carve/lib/carve.cpp29
-rw-r--r--extern/carve/lib/convex_hull.cpp100
-rw-r--r--extern/carve/lib/csg.cpp93
-rw-r--r--extern/carve/lib/csg_collector.cpp371
-rw-r--r--extern/carve/lib/csg_collector.hpp24
-rw-r--r--extern/carve/lib/csg_data.hpp52
-rw-r--r--extern/carve/lib/csg_detail.hpp71
-rw-r--r--extern/carve/lib/edge.cpp23
-rw-r--r--extern/carve/lib/face.cpp278
-rw-r--r--extern/carve/lib/geom2d.cpp260
-rw-r--r--extern/carve/lib/geom3d.cpp164
-rw-r--r--extern/carve/lib/intersect.cpp1668
-rw-r--r--extern/carve/lib/intersect_classify_common.hpp46
-rw-r--r--extern/carve/lib/intersect_classify_common_impl.hpp362
-rw-r--r--extern/carve/lib/intersect_classify_edge.cpp820
-rw-r--r--extern/carve/lib/intersect_classify_group.cpp220
-rw-r--r--extern/carve/lib/intersect_common.hpp83
-rw-r--r--extern/carve/lib/intersect_debug.cpp65
-rw-r--r--extern/carve/lib/intersect_debug.hpp29
-rw-r--r--extern/carve/lib/intersect_face_division.cpp1709
-rw-r--r--extern/carve/lib/intersect_group.cpp232
-rw-r--r--extern/carve/lib/intersect_half_classify_group.cpp199
-rw-r--r--extern/carve/lib/intersection.cpp92
-rw-r--r--extern/carve/lib/math.cpp347
-rw-r--r--extern/carve/lib/mesh.cpp1203
-rw-r--r--extern/carve/lib/octree.cpp399
-rw-r--r--extern/carve/lib/pointset.cpp59
-rw-r--r--extern/carve/lib/polyhedron.cpp1103
-rw-r--r--extern/carve/lib/polyline.cpp67
-rw-r--r--extern/carve/lib/tag.cpp24
-rw-r--r--extern/carve/lib/timing.cpp436
-rw-r--r--extern/carve/lib/triangulator.cpp1211
-rwxr-xr-xextern/carve/mkfiles.sh4
-rw-r--r--extern/carve/patches/files/config.h12
-rw-r--r--extern/carve/patches/files/random.hpp773
-rw-r--r--extern/carve/patches/gcc46.patch11
-rw-r--r--extern/carve/patches/includes.patch84
-rw-r--r--extern/carve/patches/mesh_iterator.patch21
-rw-r--r--extern/carve/patches/mingw.patch15
-rw-r--r--extern/carve/patches/series6
-rw-r--r--extern/carve/patches/strict_flags.patch46
-rw-r--r--extern/carve/patches/win32.patch29
-rw-r--r--intern/boolop/CMakeLists.txt102
-rw-r--r--intern/boolop/SConscript22
-rw-r--r--intern/boolop/intern/BOP_BSPNode.cpp7
-rw-r--r--intern/boolop/intern/BOP_BSPNode.h4
-rw-r--r--intern/boolop/intern/BOP_BSPTree.cpp1
-rw-r--r--intern/boolop/intern/BOP_CarveInterface.cpp403
-rw-r--r--intern/boolop/intern/BOP_Edge.cpp1
-rw-r--r--intern/boolop/intern/BOP_Face.h5
-rw-r--r--intern/boolop/intern/BOP_Indexs.h5
-rw-r--r--intern/boolop/intern/BOP_Interface.cpp32
-rw-r--r--intern/boolop/intern/BOP_MathUtils.cpp1
-rw-r--r--intern/boolop/intern/BOP_Merge.h4
-rw-r--r--intern/boolop/intern/BOP_Merge2.h4
-rw-r--r--intern/boolop/intern/BOP_Mesh.h8
-rw-r--r--intern/boolop/intern/BOP_Segment.cpp4
-rw-r--r--intern/boolop/intern/BOP_Segment.h3
-rw-r--r--intern/boolop/intern/BOP_Splitter.cpp1
-rw-r--r--intern/boolop/intern/BOP_Triangulator.cpp1
-rw-r--r--intern/cycles/blender/addon/enums.py4
-rw-r--r--intern/cycles/blender/addon/properties.py413
-rw-r--r--intern/cycles/blender/addon/ui.py35
-rw-r--r--intern/cycles/blender/blender_object.cpp34
-rw-r--r--intern/cycles/blender/blender_shader.cpp3
-rw-r--r--intern/cycles/blender/blender_sync.cpp1
-rw-r--r--intern/cycles/blender/blender_sync.h1
-rw-r--r--intern/cycles/bvh/bvh.cpp31
-rw-r--r--intern/cycles/bvh/bvh.h4
-rw-r--r--intern/cycles/bvh/bvh_params.h11
-rw-r--r--intern/cycles/device/device_cpu.cpp4
-rw-r--r--intern/cycles/kernel/kernel.cl2
-rw-r--r--intern/cycles/kernel/kernel.cpp2
-rw-r--r--intern/cycles/kernel/kernel.cu2
-rw-r--r--intern/cycles/kernel/kernel.h4
-rw-r--r--intern/cycles/kernel/kernel_compat_cpu.h1
-rw-r--r--intern/cycles/kernel/kernel_compat_cuda.h1
-rw-r--r--intern/cycles/kernel/kernel_differential.h4
-rw-r--r--intern/cycles/kernel/kernel_displace.h4
-rw-r--r--intern/cycles/kernel/kernel_emission.h84
-rw-r--r--intern/cycles/kernel/kernel_light.h133
-rw-r--r--intern/cycles/kernel/kernel_montecarlo.h34
-rw-r--r--intern/cycles/kernel/kernel_optimized.cpp2
-rw-r--r--intern/cycles/kernel/kernel_path.h13
-rw-r--r--intern/cycles/kernel/kernel_shader.h2
-rw-r--r--intern/cycles/kernel/kernel_textures.h2
-rw-r--r--intern/cycles/kernel/kernel_types.h12
-rw-r--r--intern/cycles/kernel/svm/svm_image.h5
-rw-r--r--intern/cycles/render/light.cpp189
-rw-r--r--intern/cycles/render/light.h3
-rw-r--r--intern/cycles/render/mesh.cpp1
-rw-r--r--intern/cycles/render/mesh_displace.cpp9
-rw-r--r--intern/cycles/render/scene.h2
-rw-r--r--intern/cycles/util/util_cache.cpp63
-rw-r--r--intern/cycles/util/util_cache.h49
-rw-r--r--intern/ghost/GHOST_ISystem.h15
-rw-r--r--intern/ghost/intern/GHOST_NDOFManager.cpp58
-rw-r--r--intern/ghost/intern/GHOST_NDOFManager.h1
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.cpp31
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp24
-rw-r--r--intern/ghost/test/CMakeLists.txt23
-rw-r--r--release/scripts/modules/addon_utils.py8
-rw-r--r--release/scripts/modules/bpy/utils.py17
-rw-r--r--release/scripts/modules/bpy_extras/keyconfig_utils.py1
-rw-r--r--release/scripts/modules/rna_xml.py5
-rw-r--r--release/scripts/startup/bl_operators/clip.py5
-rw-r--r--release/scripts/startup/bl_operators/wm.py4
-rw-r--r--release/scripts/startup/bl_ui/__init__.py2
-rw-r--r--release/scripts/startup/bl_ui/properties_data_modifier.py11
-rw-r--r--release/scripts/startup/bl_ui/properties_game.py4
-rw-r--r--release/scripts/startup/bl_ui/properties_paint_common.py61
-rw-r--r--release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py18
-rw-r--r--release/scripts/startup/bl_ui/properties_render.py6
-rw-r--r--release/scripts/startup/bl_ui/properties_texture.py42
-rw-r--r--release/scripts/startup/bl_ui/space_clip.py37
-rw-r--r--release/scripts/startup/bl_ui/space_image.py111
-rw-r--r--release/scripts/startup/bl_ui/space_time.py16
-rw-r--r--release/scripts/startup/bl_ui/space_userpref.py1
-rw-r--r--release/scripts/startup/bl_ui/space_view3d.py38
-rw-r--r--release/scripts/startup/bl_ui/space_view3d_toolbar.py108
-rw-r--r--source/blender/blenkernel/BKE_DerivedMesh.h5
-rw-r--r--source/blender/blenkernel/BKE_armature.h4
-rw-r--r--source/blender/blenkernel/BKE_array_mallocn.h85
-rw-r--r--source/blender/blenkernel/BKE_blender.h2
-rw-r--r--source/blender/blenkernel/BKE_global.h2
-rw-r--r--source/blender/blenkernel/BKE_image.h2
-rw-r--r--source/blender/blenkernel/BKE_main.h2
-rw-r--r--source/blender/blenkernel/BKE_mesh.h38
-rw-r--r--source/blender/blenkernel/BKE_text.h57
-rw-r--r--source/blender/blenkernel/BKE_utildefines.h6
-rw-r--r--source/blender/blenkernel/CMakeLists.txt1
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c76
-rw-r--r--source/blender/blenkernel/intern/armature.c332
-rw-r--r--source/blender/blenkernel/intern/brush.c31
-rw-r--r--source/blender/blenkernel/intern/constraint.c15
-rw-r--r--source/blender/blenkernel/intern/curve.c5
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c337
-rw-r--r--source/blender/blenkernel/intern/image.c6
-rw-r--r--source/blender/blenkernel/intern/image_gen.c15
-rw-r--r--source/blender/blenkernel/intern/key.c2
-rw-r--r--source/blender/blenkernel/intern/mesh.c12
-rw-r--r--source/blender/blenkernel/intern/movieclip.c2
-rw-r--r--source/blender/blenkernel/intern/node.c48
-rw-r--r--source/blender/blenkernel/intern/paint.c5
-rw-r--r--source/blender/blenkernel/intern/scene.c4
-rw-r--r--source/blender/blenkernel/intern/sequencer.c4
-rw-r--r--source/blender/blenkernel/intern/softbody.c4
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c45
-rw-r--r--source/blender/blenkernel/intern/text.c825
-rw-r--r--source/blender/blenlib/BLI_math_color.h9
-rw-r--r--source/blender/blenlib/BLI_math_geom.h5
-rw-r--r--source/blender/blenlib/BLI_math_vector.h4
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c2
-rw-r--r--source/blender/blenlib/intern/boxpack2d.c2
-rw-r--r--source/blender/blenlib/intern/math_color.c37
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c16
-rw-r--r--source/blender/blenlib/intern/math_geom.c55
-rw-r--r--source/blender/blenlib/intern/math_rotation.c2
-rw-r--r--source/blender/blenlib/intern/math_vector.c14
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c30
-rw-r--r--source/blender/blenloader/BLO_readfile.h2
-rw-r--r--source/blender/blenloader/intern/readfile.c51
-rw-r--r--source/blender/blenloader/intern/writefile.c8
-rw-r--r--source/blender/blenpluginapi/iff.h2
-rw-r--r--source/blender/editors/animation/anim_channels_defines.c2
-rw-r--r--source/blender/editors/animation/anim_channels_edit.c17
-rw-r--r--source/blender/editors/animation/anim_markers.c10
-rw-r--r--source/blender/editors/animation/keyframing.c2
-rw-r--r--source/blender/editors/armature/armature_ops.c27
-rw-r--r--source/blender/editors/armature/editarmature_retarget.c2
-rw-r--r--source/blender/editors/curve/curve_ops.c20
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c3
-rw-r--r--source/blender/editors/include/ED_image.h5
-rw-r--r--source/blender/editors/include/ED_mesh.h7
-rw-r--r--source/blender/editors/include/ED_uvedit.h2
-rw-r--r--source/blender/editors/include/ED_view3d.h4
-rw-r--r--source/blender/editors/include/UI_interface_icons.h2
-rw-r--r--source/blender/editors/include/UI_resources.h77
-rw-r--r--source/blender/editors/interface/interface.c73
-rw-r--r--source/blender/editors/interface/interface_handlers.c17
-rw-r--r--source/blender/editors/interface/interface_icons.c4
-rw-r--r--source/blender/editors/interface/interface_intern.h3
-rw-r--r--source/blender/editors/interface/interface_layout.c37
-rw-r--r--source/blender/editors/interface/interface_ops.c4
-rw-r--r--source/blender/editors/interface/interface_panel.c3
-rw-r--r--source/blender/editors/interface/interface_regions.c44
-rw-r--r--source/blender/editors/interface/interface_templates.c14
-rw-r--r--source/blender/editors/interface/interface_widgets.c2
-rw-r--r--source/blender/editors/interface/resources.c40
-rw-r--r--source/blender/editors/interface/view2d.c7
-rw-r--r--source/blender/editors/interface/view2d_ops.c9
-rw-r--r--source/blender/editors/mesh/editmesh_lib.c230
-rw-r--r--source/blender/editors/mesh/editmesh_loop.c324
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c2
-rw-r--r--source/blender/editors/mesh/loopcut.c10
-rw-r--r--source/blender/editors/mesh/mesh_data.c82
-rw-r--r--source/blender/editors/mesh/mesh_ops.c13
-rw-r--r--source/blender/editors/metaball/mball_ops.c8
-rw-r--r--source/blender/editors/object/object_add.c2
-rw-r--r--source/blender/editors/object/object_bake.c25
-rw-r--r--source/blender/editors/object/object_edit.c6
-rw-r--r--source/blender/editors/object/object_ops.c78
-rw-r--r--source/blender/editors/physics/physics_ops.c24
-rw-r--r--source/blender/editors/render/render_opengl.c6
-rw-r--r--source/blender/editors/screen/screen_ops.c26
-rw-r--r--source/blender/editors/sculpt_paint/CMakeLists.txt3
-rw-r--r--source/blender/editors/sculpt_paint/SConscript2
-rw-r--r--source/blender/editors/sculpt_paint/paint_cursor.c607
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c109
-rw-r--r--source/blender/editors/sculpt_paint/paint_intern.h8
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c140
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c553
-rw-r--r--source/blender/editors/sculpt_paint/paint_utils.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c30
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_intern.h2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_uv.c780
-rw-r--r--source/blender/editors/space_buttons/buttons_context.c1
-rw-r--r--source/blender/editors/space_clip/clip_graph_draw.c7
-rw-r--r--source/blender/editors/space_clip/clip_graph_ops.c13
-rw-r--r--source/blender/editors/space_clip/clip_ops.c2
-rw-r--r--source/blender/editors/space_clip/clip_utils.c2
-rw-r--r--source/blender/editors/space_clip/space_clip.c39
-rw-r--r--source/blender/editors/space_clip/tracking_ops.c6
-rw-r--r--source/blender/editors/space_console/space_console.c11
-rw-r--r--source/blender/editors/space_file/filelist.c9
-rw-r--r--source/blender/editors/space_file/space_file.c8
-rw-r--r--source/blender/editors/space_graph/graph_ops.c3
-rw-r--r--source/blender/editors/space_image/image_draw.c40
-rw-r--r--source/blender/editors/space_image/image_ops.c40
-rw-r--r--source/blender/editors/space_image/space_image.c8
-rw-r--r--source/blender/editors/space_info/info_ops.c2
-rw-r--r--source/blender/editors/space_nla/nla_ops.c14
-rw-r--r--source/blender/editors/space_node/node_edit.c2
-rw-r--r--source/blender/editors/space_node/node_ops.c26
-rw-r--r--source/blender/editors/space_node/node_templates.c11
-rw-r--r--source/blender/editors/space_outliner/outliner_intern.h2
-rw-r--r--source/blender/editors/space_outliner/outliner_ops.c25
-rw-r--r--source/blender/editors/space_outliner/outliner_select.c75
-rw-r--r--source/blender/editors/space_script/script_edit.c2
-rw-r--r--source/blender/editors/space_sequencer/sequencer_draw.c2
-rw-r--r--source/blender/editors/space_sequencer/sequencer_edit.c4
-rw-r--r--source/blender/editors/space_sequencer/sequencer_ops.c38
-rw-r--r--source/blender/editors/space_text/space_text.c27
-rw-r--r--source/blender/editors/space_text/text_draw.c224
-rw-r--r--source/blender/editors/space_text/text_intern.h3
-rw-r--r--source/blender/editors/space_text/text_ops.c339
-rw-r--r--source/blender/editors/space_view3d/drawarmature.c49
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c7
-rw-r--r--source/blender/editors/space_view3d/drawobject.c28
-rw-r--r--source/blender/editors/space_view3d/drawvolume.c7
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c6
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c57
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c307
-rw-r--r--source/blender/editors/space_view3d/view3d_fly.c54
-rw-r--r--source/blender/editors/space_view3d/view3d_header.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h3
-rw-r--r--source/blender/editors/space_view3d/view3d_ops.c9
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_snap.c15
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c13
-rw-r--r--source/blender/editors/transform/transform_conversions.c343
-rw-r--r--source/blender/editors/transform/transform_generics.c15
-rw-r--r--source/blender/editors/transform/transform_ops.c74
-rw-r--r--source/blender/editors/uvedit/CMakeLists.txt1
-rw-r--r--source/blender/editors/uvedit/uvedit_draw.c110
-rw-r--r--source/blender/editors/uvedit/uvedit_intern.h58
-rw-r--r--source/blender/editors/uvedit/uvedit_ops.c462
-rw-r--r--source/blender/editors/uvedit/uvedit_parametrizer.c18
-rw-r--r--source/blender/editors/uvedit/uvedit_smart_stitch.c1467
-rw-r--r--source/blender/editors/uvedit/uvedit_unwrap_ops.c228
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c3
-rw-r--r--source/blender/gpu/intern/gpu_draw.c156
-rw-r--r--source/blender/imbuf/IMB_imbuf_types.h2
-rw-r--r--source/blender/imbuf/intern/IMB_anim.h6
-rw-r--r--source/blender/imbuf/intern/IMB_indexer.h2
-rw-r--r--source/blender/imbuf/intern/divers.c55
-rw-r--r--source/blender/makesdna/DNA_ID.h4
-rw-r--r--source/blender/makesdna/DNA_brush_types.h2
-rw-r--r--source/blender/makesdna/DNA_customdata_types.h2
-rw-r--r--source/blender/makesdna/DNA_dynamicpaint_types.h13
-rw-r--r--source/blender/makesdna/DNA_fileglobal_types.h2
-rw-r--r--source/blender/makesdna/DNA_image_types.h3
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h2
-rw-r--r--source/blender/makesdna/DNA_movieclip_types.h4
-rw-r--r--source/blender/makesdna/DNA_node_types.h12
-rw-r--r--source/blender/makesdna/DNA_object_fluidsim.h4
-rw-r--r--source/blender/makesdna/DNA_object_force.h2
-rw-r--r--source/blender/makesdna/DNA_scene_types.h33
-rw-r--r--source/blender/makesdna/DNA_sequence_types.h18
-rw-r--r--source/blender/makesdna/DNA_sound_types.h2
-rw-r--r--source/blender/makesdna/DNA_space_types.h22
-rw-r--r--source/blender/makesdna/DNA_texture_types.h4
-rw-r--r--source/blender/makesdna/DNA_tracking_types.h7
-rw-r--r--source/blender/makesdna/DNA_userdef_types.h37
-rw-r--r--source/blender/makesdna/DNA_vfont_types.h2
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/SConscript4
-rw-r--r--source/blender/makesrna/intern/rna_controller.c19
-rw-r--r--source/blender/makesrna/intern/rna_dynamicpaint.c25
-rw-r--r--source/blender/makesrna/intern/rna_fluidsim.c6
-rw-r--r--source/blender/makesrna/intern/rna_main.c4
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c16
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c2
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c62
-rw-r--r--source/blender/makesrna/intern/rna_scene.c73
-rw-r--r--source/blender/makesrna/intern/rna_sculpt_paint.c15
-rw-r--r--source/blender/makesrna/intern/rna_sensor.c21
-rw-r--r--source/blender/makesrna/intern/rna_tracking.c2
-rw-r--r--source/blender/makesrna/intern/rna_ui.c2
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c48
-rw-r--r--source/blender/modifiers/intern/MOD_boolean.c1
-rw-r--r--source/blender/modifiers/intern/MOD_build.c151
-rw-r--r--source/blender/modifiers/intern/MOD_solidify.c2
-rw-r--r--source/blender/nodes/NOD_socket.h33
-rw-r--r--source/blender/nodes/intern/node_common.c195
-rw-r--r--source/blender/nodes/intern/node_socket.c355
-rw-r--r--source/blender/python/intern/bpy_interface.c5
-rw-r--r--source/blender/python/intern/bpy_props.c111
-rw-r--r--source/blender/python/intern/bpy_rna.c34
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c9
-rw-r--r--source/blender/render/extern/include/RE_shader_ext.h4
-rw-r--r--source/blender/render/intern/source/imagetexture.c6
-rw-r--r--source/blender/render/intern/source/render_texture.c3
-rw-r--r--source/blender/render/intern/source/rendercore.c38
-rw-r--r--source/blender/windowmanager/WM_types.h4
-rw-r--r--source/blender/windowmanager/intern/wm_dragdrop.c2
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c9
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c3
-rw-r--r--source/blenderplayer/CMakeLists.txt4
-rw-r--r--source/blenderplayer/bad_level_call_stubs/stubs.c5
-rw-r--r--source/creator/CMakeLists.txt22
-rw-r--r--source/creator/creator.c13
-rw-r--r--source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp2
-rw-r--r--source/gameengine/Converter/BL_ActionActuator.cpp4
-rw-r--r--source/gameengine/Converter/BL_ShapeActionActuator.cpp4
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp10
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.cpp2
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.h2
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorSensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.h4
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyActuator.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_RandomActuator.cpp2
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp2
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_IpoActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_RaySensor.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_SceneActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_TouchSensor.cpp2
-rw-r--r--source/gameengine/Rasterizer/RAS_TexVert.cpp2
-rw-r--r--source/tests/bl_mesh_modifiers.py254
445 files changed, 40564 insertions, 4215 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 61a1bd3a080..fb6b946b0c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -208,6 +208,9 @@ option(WITH_LZMA "Enable best LZMA compression, (used for pointcache)"
# Camera/motion tracking
option(WITH_LIBMV "Enable libmv structure from motion library" ON)
+# Mesh boolean lib
+option(WITH_CARVE "Enable Carve library to handle mesh boolean operations" ON)
+
# Misc
option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
option(WITH_RAYOPTIMIZATION "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
@@ -300,9 +303,13 @@ if(WITH_PYTHON_MODULE)
set(WITH_HEADLESS ON)
endif()
-# auto enable openimageio and boost for cycles
+# auto enable openimageio for cycles
if(WITH_CYCLES)
set(WITH_OPENIMAGEIO ON)
+endif()
+
+# auto enable boost for cycles and carve
+if(WITH_CYCLES OR WITH_CARVE)
set(WITH_BOOST ON)
endif()
@@ -1085,16 +1092,28 @@ elseif(APPLE)
endif()
if(WITH_PYTHON)
- # we use precompiled libraries for py 3.2 and up by default
+ if(NOT WITH_PYTHON_MODULE)
+ # we use precompiled libraries for py 3.2 and up by default
- # normally cached but not since we include them with blender
- set(PYTHON_VERSION 3.2)
- set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
- # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
- set(PYTHON_LIBRARY python${PYTHON_VERSION})
- set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
- # set(PYTHON_LINKFLAGS "-u _PyMac_Error") # won't build with this enabled
+ # normally cached but not since we include them with blender
+ set(PYTHON_VERSION 3.2)
+ set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
+ # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
+ set(PYTHON_LIBRARY python${PYTHON_VERSION})
+ set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
+ # set(PYTHON_LINKFLAGS "-u _PyMac_Error") # won't build with this enabled
+ else()
+ # module must be compiled against Python framework
+ # normally cached but not since we include them with blender
+ set(PYTHON_VERSION 3.2)
+ set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
+ set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
+ #set(PYTHON_LIBRARY python${PYTHON_VERSION})
+ set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-3.2m")
+ #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python") # won't build with this enabled
+ endif()
+
# uncached vars
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
@@ -1189,7 +1208,11 @@ elseif(APPLE)
set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
set(WITH_INPUT_NDOF OFF) # unsupported
endif()
-
+
+ if(WITH_PYTHON_MODULE)
+ set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/python")# force cmake to link right framework
+ endif()
+
if(WITH_OPENCOLLADA)
set(OPENCOLLADA ${LIBDIR}/opencollada)
diff --git a/SConstruct b/SConstruct
index ee43015cf6e..0dd59add019 100644
--- a/SConstruct
+++ b/SConstruct
@@ -147,9 +147,8 @@ if toolset:
env.Tool('mstoolkit', [toolpath])
else:
env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
- # xxx commented out, as was supressing warnings under mingw..
- #if env:
- # btools.SetupSpawn(env)
+ if env:
+ btools.SetupSpawn(env)
else:
if bitness==64 and platform=='win32':
env = BlenderEnvironment(ENV = os.environ, MSVS_ARCH='amd64')
diff --git a/build_files/cmake/cmake_static_check_cppcheck.py b/build_files/cmake/cmake_static_check_cppcheck.py
index 8720cb83054..6c13f3a079a 100644
--- a/build_files/cmake/cmake_static_check_cppcheck.py
+++ b/build_files/cmake/cmake_static_check_cppcheck.py
@@ -37,7 +37,8 @@ CHECKER_BIN = "cppcheck"
CHECKER_ARGS = [
# not sure why this is needed, but it is.
"-I" + os.path.join(project_source_info.SOURCE_DIR, "extern", "glew", "include"),
-
+ "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR,
+ # "--max-configs=1", # speeds up execution
# "--check-config", # when includes are missing
# "--enable=all", # if you want sixty hundred pedantic suggestions
]
diff --git a/build_files/cmake/config/blender_lite.cmake b/build_files/cmake/config/blender_lite.cmake
index 26fa7623f21..e72a0fff355 100644
--- a/build_files/cmake/config/blender_lite.cmake
+++ b/build_files/cmake/config/blender_lite.cmake
@@ -15,6 +15,7 @@ set(WITH_CODEC_SNDFILE OFF CACHE FORCE BOOL)
set(WITH_CYCLES OFF CACHE FORCE BOOL)
set(WITH_FFTW3 OFF CACHE FORCE BOOL)
set(WITH_LIBMV OFF CACHE FORCE BOOL)
+set(WITH_CARVE OFF CACHE FORCE BOOL)
set(WITH_GAMEENGINE OFF CACHE FORCE BOOL)
set(WITH_IK_ITASC OFF CACHE FORCE BOOL)
set(WITH_IMAGE_CINEON OFF CACHE FORCE BOOL)
@@ -33,6 +34,7 @@ set(WITH_LZO OFF CACHE FORCE BOOL)
set(WITH_MOD_BOOLEAN OFF CACHE FORCE BOOL)
set(WITH_MOD_DECIMATE OFF CACHE FORCE BOOL)
set(WITH_MOD_FLUID OFF CACHE FORCE BOOL)
+set(WITH_MOD_REMESH OFF CACHE FORCE BOOL)
set(WITH_MOD_SMOKE OFF CACHE FORCE BOOL)
set(WITH_MOD_OCEANSIM OFF CACHE FORCE BOOL)
set(WITH_AUDASPACE OFF CACHE FORCE BOOL)
@@ -43,3 +45,4 @@ set(WITH_PYTHON_INSTALL OFF CACHE FORCE BOOL)
set(WITH_RAYOPTIMIZATION OFF CACHE FORCE BOOL)
set(WITH_SDL OFF CACHE FORCE BOOL)
set(WITH_X11_XINPUT OFF CACHE FORCE BOOL)
+set(WITH_X11_XF86VMODE OFF CACHE FORCE BOOL)
diff --git a/build_files/cmake/project_info.py b/build_files/cmake/project_info.py
index 65afd109302..77574f17e2e 100755
--- a/build_files/cmake/project_info.py
+++ b/build_files/cmake/project_info.py
@@ -133,7 +133,7 @@ def cmake_advanced_info():
""" Extracr includes and defines from cmake.
"""
- def create_eclipse_project(CMAKE_DIR):
+ def create_eclipse_project():
print("CMAKE_DIR %r" % CMAKE_DIR)
if sys.platform == "win32":
cmd = 'cmake "%s" -G"Eclipse CDT4 - MinGW Makefiles"' % CMAKE_DIR
@@ -145,7 +145,7 @@ def cmake_advanced_info():
includes = []
defines = []
- create_eclipse_project(CMAKE_DIR)
+ create_eclipse_project()
from xml.dom.minidom import parse
tree = parse(join(CMAKE_DIR, ".cproject"))
diff --git a/build_files/cmake/project_source_info.py b/build_files/cmake/project_source_info.py
index a39ed94bd69..ed17ec5bac4 100644
--- a/build_files/cmake/project_source_info.py
+++ b/build_files/cmake/project_source_info.py
@@ -160,7 +160,6 @@ def build_info(use_c=True, use_cxx=True, ignore_prefix_list=None):
def queue_processes(process_funcs, job_total=-1):
""" Takes a list of function arg pairs, each function must return a process
"""
- import sys
if job_total == -1:
import multiprocessing
diff --git a/build_files/scons/tools/Blender.py b/build_files/scons/tools/Blender.py
index 5392f6707bd..c2e6a203d71 100644
--- a/build_files/scons/tools/Blender.py
+++ b/build_files/scons/tools/Blender.py
@@ -272,7 +272,7 @@ def setup_syslibs(lenv):
syslibs += Split(lenv['BF_PTHREADS_LIB'])
if lenv['WITH_BF_COLLADA']:
syslibs.append(lenv['BF_PCRE_LIB'])
- if lenv['BF_DEBUG']:
+ if lenv['BF_DEBUG'] and (lenv['OURPLATFORM'] != 'linux'):
syslibs += [colladalib+'_d' for colladalib in Split(lenv['BF_OPENCOLLADA_LIB'])]
else:
syslibs += Split(lenv['BF_OPENCOLLADA_LIB'])
diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py
index 493bc7b8e02..a71ab04b888 100644
--- a/build_files/scons/tools/btools.py
+++ b/build_files/scons/tools/btools.py
@@ -161,7 +161,7 @@ def validate_arguments(args, bc):
'WITH_BF_CYCLES', 'WITH_BF_CYCLES_CUDA_BINARIES' 'BF_CYCLES_CUDA_NVCC', 'BF_CYCLES_CUDA_NVCC', 'WITH_BF_CYCLES_CUDA_THREADED_COMPILE',
'WITH_BF_OIIO', 'WITH_BF_STATICOIIO', 'BF_OIIO', 'BF_OIIO_INC', 'BF_OIIO_LIB', 'BF_OIIO_LIB_STATIC', 'BF_OIIO_LIBPATH',
'WITH_BF_BOOST', 'WITH_BF_STATICBOOST', 'BF_BOOST', 'BF_BOOST_INC', 'BF_BOOST_LIB', 'BF_BOOST_LIB_STATIC', 'BF_BOOST_LIBPATH',
- 'WITH_BF_LIBMV'
+ 'WITH_BF_LIBMV', 'WITH_BF_CARVE'
]
# Have options here that scons expects to be lists
@@ -222,15 +222,15 @@ class ourSpawn:
newargs = string.join(args[1:], ' ')
cmdline = cmd + " " + newargs
startupinfo = subprocess.STARTUPINFO()
- startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+ #startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False)
data, err = proc.communicate()
rv = proc.wait()
- if rv:
- print "====="
- print err
- print "====="
+ if data:
+ print(data)
+ if err:
+ print(err)
return rv
def SetupSpawn( env ):
@@ -521,6 +521,7 @@ def read_opts(env, cfg, args):
(BoolVariable('WITH_BF_LZO', 'Enable fast LZO pointcache compression', True)),
(BoolVariable('WITH_BF_LZMA', 'Enable best LZMA pointcache compression', True)),
+ (BoolVariable('WITH_BF_CARVE', 'Enable carve library for mesh boolean operations', True)),
(BoolVariable('WITH_BF_LIBMV', 'Enable libmv structure from motion library', True)),
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 60253e08d4c..6215673eb44 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -67,3 +67,7 @@ endif()
if(WITH_LIBMV)
add_subdirectory(libmv)
endif()
+
+if(WITH_CARVE)
+ add_subdirectory(carve)
+endif()
diff --git a/extern/SConscript b/extern/SConscript
index 031471a8a01..738342b3dcc 100644
--- a/extern/SConscript
+++ b/extern/SConscript
@@ -31,3 +31,6 @@ if env['WITH_BF_LZMA']:
if env['WITH_BF_LIBMV']:
SConscript(['libmv/SConscript'])
+
+if env['WITH_BF_CARVE']:
+ SConscript(['carve/SConscript'])
diff --git a/extern/carve/CMakeLists.txt b/extern/carve/CMakeLists.txt
new file mode 100644
index 00000000000..abd35d33c1c
--- /dev/null
+++ b/extern/carve/CMakeLists.txt
@@ -0,0 +1,166 @@
+# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# The Original Code is Copyright (C) 2006, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Jacques Beaurai, Erwin Coumans
+#
+# ***** END GPL LICENSE BLOCK *****
+
+# NOTE: This file is automatically generated by bundle.sh script
+# If you're doing changes in this file, please update template
+# in that script too
+
+set(INC
+ include
+)
+
+set(INC_SYS
+)
+
+set(SRC
+ lib/carve.cpp
+ lib/mesh.cpp
+ lib/intersect_group.cpp
+ lib/intersect_classify_edge.cpp
+ lib/intersect_classify_group.cpp
+ lib/polyhedron.cpp
+ lib/geom3d.cpp
+ lib/polyline.cpp
+ lib/csg_collector.cpp
+ lib/triangulator.cpp
+ lib/intersect_face_division.cpp
+ lib/intersect_half_classify_group.cpp
+ lib/edge.cpp
+ lib/math.cpp
+ lib/geom2d.cpp
+ lib/tag.cpp
+ lib/intersection.cpp
+ lib/convex_hull.cpp
+ lib/csg.cpp
+ lib/intersect.cpp
+ lib/face.cpp
+ lib/pointset.cpp
+ lib/timing.cpp
+ lib/octree.cpp
+ lib/aabb.cpp
+ lib/intersect_debug.cpp
+
+ lib/intersect_classify_common.hpp
+ lib/csg_data.hpp
+ lib/csg_collector.hpp
+ lib/intersect_common.hpp
+ lib/intersect_classify_common_impl.hpp
+ lib/csg_detail.hpp
+ lib/intersect_debug.hpp
+
+ include/carve/polyhedron_decl.hpp
+ include/carve/geom2d.hpp
+ include/carve/exact.hpp
+ include/carve/triangulator_impl.hpp
+ include/carve/collection.hpp
+ include/carve/pointset.hpp
+ include/carve/djset.hpp
+ include/carve/kd_node.hpp
+ include/carve/polyline.hpp
+ include/carve/polyline_iter.hpp
+ include/carve/geom3d.hpp
+ include/carve/edge_decl.hpp
+ include/carve/face_decl.hpp
+ include/carve/aabb_impl.hpp
+ include/carve/colour.hpp
+ include/carve/pointset_iter.hpp
+ include/carve/polyline_decl.hpp
+ include/carve/rescale.hpp
+ include/carve/mesh_impl.hpp
+ include/carve/classification.hpp
+ include/carve/util.hpp
+ include/carve/triangulator.hpp
+ include/carve/polyhedron_base.hpp
+ include/carve/rtree.hpp
+ include/carve/math.hpp
+ include/carve/math_constants.hpp
+ include/carve/octree_decl.hpp
+ include/carve/input.hpp
+ include/carve/mesh_ops.hpp
+ include/carve/debug_hooks.hpp
+ include/carve/mesh_simplify.hpp
+ include/carve/interpolator.hpp
+ include/carve/poly_decl.hpp
+ include/carve/csg.hpp
+ include/carve/mesh.hpp
+ include/carve/carve.hpp
+ include/carve/gnu_cxx.h
+ include/carve/polyhedron_impl.hpp
+ include/carve/poly_impl.hpp
+ include/carve/aabb.hpp
+ include/carve/convex_hull.hpp
+ include/carve/vertex_decl.hpp
+ include/carve/win32.h
+ include/carve/edge_impl.hpp
+ include/carve/tag.hpp
+ include/carve/tree.hpp
+ include/carve/heap.hpp
+ include/carve/matrix.hpp
+ include/carve/poly.hpp
+ include/carve/vector.hpp
+ include/carve/intersection.hpp
+ include/carve/faceloop.hpp
+ include/carve/geom_impl.hpp
+ include/carve/octree_impl.hpp
+ include/carve/spacetree.hpp
+ include/carve/collection/unordered/std_impl.hpp
+ include/carve/collection/unordered/tr1_impl.hpp
+ include/carve/collection/unordered/libstdcpp_impl.hpp
+ include/carve/collection/unordered/boost_impl.hpp
+ include/carve/collection/unordered/vcpp_impl.hpp
+ include/carve/collection/unordered/fallback_impl.hpp
+ include/carve/collection/unordered.hpp
+ include/carve/face_impl.hpp
+ include/carve/pointset_impl.hpp
+ include/carve/cbrt.h
+ include/carve/vcpp_config.h
+ include/carve/geom.hpp
+ include/carve/vertex_impl.hpp
+ include/carve/polyline_impl.hpp
+ include/carve/pointset_decl.hpp
+ include/carve/timing.hpp
+ include/carve/csg_triangulator.hpp
+ include/carve/iobj.hpp
+ include/carve/collection_types.hpp
+)
+
+if(WITH_BOOST)
+ if(NOT MSVC)
+ # Boost is setting as preferred collections library in the Carve code when using MSVC compiler
+ add_definitions(
+ -DHAVE_BOOST_UNORDERED_COLLECTIONS
+ )
+ endif()
+
+ add_definitions(
+ -DCARVE_SYSTEM_BOOST
+ )
+
+ list(APPEND INC
+ ${BOOST_INCLUDE_DIR}
+ )
+endif()
+
+blender_add_lib(extern_carve "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/extern/carve/LICENSE.GPL2 b/extern/carve/LICENSE.GPL2
new file mode 100644
index 00000000000..792acb92f6a
--- /dev/null
+++ b/extern/carve/LICENSE.GPL2
@@ -0,0 +1,361 @@
+ GNU GENERAL PUBLIC LICENSE
+
+ The Qt GUI Toolkit is Copyright (C) 1994-2008 Trolltech ASA.
+
+ You may use, distribute and copy the Qt GUI Toolkit under the terms of
+ GNU General Public License version 2, which is displayed below.
+
+-------------------------------------------------------------------------
+
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
+-------------------------------------------------------------------------
+
+In addition, as a special exception, Trolltech gives permission to link the
+code of its release of Qt with the OpenSSL project's "OpenSSL" library (or
+modified versions of it that use the same license as the "OpenSSL"
+library), and distribute the linked executables. You must comply with the GNU
+General Public License version 2 or the GNU General Public License version 3
+in all respects for all of the code used other than the "OpenSSL" code. If
+you modify this file, you may extend this exception to your version of the
+file, but you are not obligated to do so. If you do not wish to do so,
+delete this exception statement from your version of this file.
diff --git a/extern/carve/SConscript b/extern/carve/SConscript
new file mode 100644
index 00000000000..e2f3c814e2e
--- /dev/null
+++ b/extern/carve/SConscript
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+# NOTE: This file is automatically generated by bundle.sh script
+# If you're doing changes in this file, please update template
+# in that script too
+
+Import ('env')
+
+sources = env.Glob('lib/*.cpp')
+
+defs = []
+incs = ['include']
+
+if env['WITH_BF_BOOST']:
+ if env['OURPLATFORM'] not in ('win32-vc', 'win64-vc'):
+ # Boost is setting as preferred collections library in the Carve code when using MSVC compiler
+ if env['OURPLATFORM'] != 'win32-mingw':
+ defs.append('HAVE_BOOST_UNORDERED_COLLECTIONS')
+
+ defs.append('CARVE_SYSTEM_BOOST')
+ incs.append(env['BF_BOOST_INC'])
+
+env.BlenderLib ('extern_carve', Split(sources), incs, defs, libtype=['extern'], priority=[40] )
diff --git a/extern/carve/bundle.sh b/extern/carve/bundle.sh
new file mode 100755
index 00000000000..3f9028619a5
--- /dev/null
+++ b/extern/carve/bundle.sh
@@ -0,0 +1,124 @@
+#!/bin/sh
+
+if [ -d ./.svn ]; then
+ echo "This script is supposed to work only when using git-svn"
+ exit 1
+fi
+
+tmp=`mktemp -d`
+
+hg clone https://code.google.com/p/carve/ $tmp/carve
+
+for p in `cat ./patches/series`; do
+ echo "Applying patch $p..."
+ cat ./patches/$p | patch -d $tmp/carve -p1
+done
+
+rm -rf include
+rm -rf lib
+
+cat "files.txt" | while f=`line`; do
+ mkdir -p `dirname $f`
+ cp $tmp/carve/$f $f
+done
+
+rm -rf $tmp
+
+sources=`find ./lib -type f -iname '*.cc' -or -iname '*.cpp' -or -iname '*.c' | sed -r 's/^\.\//\t/'`
+headers=`find ./lib -type f -iname '*.h' -or -iname '*.hpp' | sed -r 's/^\.\//\t/'`
+includes=`find ./include -type f -iname '*.h' -or -iname '*.hpp' | sed -r 's/^\.\//\t/'`
+
+mkdir -p include/carve/external/boost
+cp patches/files/random.hpp include/carve/external/boost/random.hpp
+cp patches/files/config.h include/carve/config.h
+
+cat > CMakeLists.txt << EOF
+# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# The Original Code is Copyright (C) 2006, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Jacques Beaurai, Erwin Coumans
+#
+# ***** END GPL LICENSE BLOCK *****
+
+# NOTE: This file is automatically generated by bundle.sh script
+# If you're doing changes in this file, please update template
+# in that script too
+
+set(INC
+ include
+)
+
+set(INC_SYS
+)
+
+set(SRC
+${sources}
+
+${headers}
+
+${includes}
+)
+
+if(WITH_BOOST)
+ if(NOT MSVC)
+ # Boost is setting as preferred collections library in the Carve code when using MSVC compiler
+ add_definitions(
+ -DHAVE_BOOST_UNORDERED_COLLECTIONS
+ )
+ endif()
+
+ add_definitions(
+ -DCARVE_SYSTEM_BOOST
+ )
+
+ list(APPEND INC
+ \${BOOST_INCLUDE_DIR}
+ )
+endif()
+
+blender_add_lib(extern_carve "\${SRC}" "\${INC}" "\${INC_SYS}")
+EOF
+
+cat > SConscript << EOF
+#!/usr/bin/python
+
+# NOTE: This file is automatically generated by bundle.sh script
+# If you're doing changes in this file, please update template
+# in that script too
+
+Import ('env')
+
+sources = env.Glob('lib/*.cpp')
+
+defs = []
+incs = ['include']
+
+if env['WITH_BF_BOOST']:
+ if env['OURPLATFORM'] not in ('win32-vc', 'win64-vc'):
+ # Boost is setting as preferred collections library in the Carve code when using MSVC compiler
+ if env['OURPLATFORM'] != 'win32-mingw':
+ defs.append('HAVE_BOOST_UNORDERED_COLLECTIONS')
+
+ defs.append('CARVE_SYSTEM_BOOST')
+ incs.append(env['BF_BOOST_INC'])
+
+env.BlenderLib ('extern_carve', Split(sources), incs, defs, libtype=['extern'], priority=[40] )
+EOF
diff --git a/extern/carve/files.txt b/extern/carve/files.txt
new file mode 100644
index 00000000000..c3cb9275950
--- /dev/null
+++ b/extern/carve/files.txt
@@ -0,0 +1,107 @@
+include/carve/polyhedron_decl.hpp
+include/carve/geom2d.hpp
+include/carve/exact.hpp
+include/carve/triangulator_impl.hpp
+include/carve/collection.hpp
+include/carve/pointset.hpp
+include/carve/djset.hpp
+include/carve/kd_node.hpp
+include/carve/polyline.hpp
+include/carve/polyline_iter.hpp
+include/carve/geom3d.hpp
+include/carve/edge_decl.hpp
+include/carve/face_decl.hpp
+include/carve/aabb_impl.hpp
+include/carve/colour.hpp
+include/carve/pointset_iter.hpp
+include/carve/polyline_decl.hpp
+include/carve/rescale.hpp
+include/carve/mesh_impl.hpp
+include/carve/classification.hpp
+include/carve/util.hpp
+include/carve/triangulator.hpp
+include/carve/polyhedron_base.hpp
+include/carve/rtree.hpp
+include/carve/math.hpp
+include/carve/math_constants.hpp
+include/carve/octree_decl.hpp
+include/carve/input.hpp
+include/carve/mesh_ops.hpp
+include/carve/debug_hooks.hpp
+include/carve/mesh_simplify.hpp
+include/carve/interpolator.hpp
+include/carve/poly_decl.hpp
+include/carve/csg.hpp
+include/carve/mesh.hpp
+include/carve/carve.hpp
+include/carve/gnu_cxx.h
+include/carve/polyhedron_impl.hpp
+include/carve/poly_impl.hpp
+include/carve/aabb.hpp
+include/carve/convex_hull.hpp
+include/carve/vertex_decl.hpp
+include/carve/win32.h
+include/carve/edge_impl.hpp
+include/carve/tag.hpp
+include/carve/tree.hpp
+include/carve/heap.hpp
+include/carve/matrix.hpp
+include/carve/poly.hpp
+include/carve/vector.hpp
+include/carve/intersection.hpp
+include/carve/faceloop.hpp
+include/carve/geom_impl.hpp
+include/carve/octree_impl.hpp
+include/carve/spacetree.hpp
+include/carve/collection/unordered/std_impl.hpp
+include/carve/collection/unordered/tr1_impl.hpp
+include/carve/collection/unordered/libstdcpp_impl.hpp
+include/carve/collection/unordered/boost_impl.hpp
+include/carve/collection/unordered/vcpp_impl.hpp
+include/carve/collection/unordered/fallback_impl.hpp
+include/carve/collection/unordered.hpp
+include/carve/face_impl.hpp
+include/carve/pointset_impl.hpp
+include/carve/cbrt.h
+include/carve/vcpp_config.h
+include/carve/geom.hpp
+include/carve/vertex_impl.hpp
+include/carve/polyline_impl.hpp
+include/carve/pointset_decl.hpp
+include/carve/timing.hpp
+include/carve/csg_triangulator.hpp
+include/carve/iobj.hpp
+include/carve/collection_types.hpp
+lib/carve.cpp
+lib/mesh.cpp
+lib/intersect_group.cpp
+lib/intersect_classify_common.hpp
+lib/intersect_classify_edge.cpp
+lib/intersect_classify_group.cpp
+lib/csg_data.hpp
+lib/polyhedron.cpp
+lib/csg_collector.hpp
+lib/geom3d.cpp
+lib/polyline.cpp
+lib/csg_collector.cpp
+lib/triangulator.cpp
+lib/intersect_face_division.cpp
+lib/intersect_half_classify_group.cpp
+lib/edge.cpp
+lib/math.cpp
+lib/geom2d.cpp
+lib/tag.cpp
+lib/intersection.cpp
+lib/convex_hull.cpp
+lib/intersect_common.hpp
+lib/intersect_classify_common_impl.hpp
+lib/csg.cpp
+lib/intersect.cpp
+lib/csg_detail.hpp
+lib/face.cpp
+lib/pointset.cpp
+lib/timing.cpp
+lib/octree.cpp
+lib/aabb.cpp
+lib/intersect_debug.hpp
+lib/intersect_debug.cpp
diff --git a/extern/carve/include/carve/aabb.hpp b/extern/carve/include/carve/aabb.hpp
new file mode 100644
index 00000000000..20ee028aa45
--- /dev/null
+++ b/extern/carve/include/carve/aabb.hpp
@@ -0,0 +1,150 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom.hpp>
+
+#include <vector>
+
+namespace carve {
+ namespace geom {
+
+
+
+ // n-dimensional AABB
+ template<unsigned ndim>
+ struct aabb {
+ typedef vector<ndim> vector_t;
+ typedef aabb<ndim> aabb_t;
+
+ vector_t pos; // the centre of the AABB
+ vector_t extent; // the extent of the AABB - the vector from the centre to the maximal vertex.
+
+ void empty();
+
+ bool isEmpty() const;
+
+ void fit(const vector_t &v1);
+ void fit(const vector_t &v1, const vector_t &v2);
+ void fit(const vector_t &v1, const vector_t &v2, const vector_t &v3);
+
+ template<typename iter_t, typename value_type>
+ void _fit(iter_t begin, iter_t end, value_type);
+
+ template<typename iter_t>
+ void _fit(iter_t begin, iter_t end, vector_t);
+
+ template<typename iter_t>
+ void _fit(iter_t begin, iter_t end, aabb_t);
+
+ template<typename iter_t>
+ void fit(iter_t begin, iter_t end);
+
+ template<typename iter_t, typename adapt_t>
+ void fit(iter_t begin, iter_t end, adapt_t adapt);
+
+ void unionAABB(const aabb<ndim> &a);
+
+ void expand(double pad);
+
+ bool completelyContains(const aabb<ndim> &other) const;
+
+ bool containsPoint(const vector_t &v) const;
+
+ bool intersectsLineSegment(const vector_t &v1, const vector_t &v2) const;
+
+ double axisSeparation(const aabb<ndim> &other, unsigned axis) const;
+
+ double maxAxisSeparation(const aabb<ndim> &other) const;
+
+ bool intersects(const aabb<ndim> &other) const;
+ bool intersects(const sphere<ndim> &s) const;
+ bool intersects(const plane<ndim> &plane) const;
+ bool intersects(const ray<ndim> &ray) const;
+ bool intersects(tri<ndim> tri) const;
+ bool intersects(const linesegment<ndim> &ls) const;
+
+ std::pair<double, double> rangeInDirection(const carve::geom::vector<ndim> &v) const;
+
+ vector_t min() const;
+ vector_t mid() const;
+ vector_t max() const;
+
+ double min(unsigned dim) const;
+ double mid(unsigned dim) const;
+ double max(unsigned dim) const;
+
+ double volume() const;
+
+ int compareAxis(const axis_pos &ap) const;
+
+ void constrainMax(const axis_pos &ap);
+ void constrainMin(const axis_pos &ap);
+
+ aabb getAABB() const;
+
+ aabb(const vector_t &_pos = vector_t::ZERO(),
+ const vector_t &_extent = vector_t::ZERO());
+
+ template<typename iter_t, typename adapt_t>
+ aabb(iter_t begin, iter_t end, adapt_t adapt);
+
+ template<typename iter_t>
+ aabb(iter_t begin, iter_t end);
+
+ aabb(const aabb<ndim> &a, const aabb<ndim> &b);
+ };
+
+ template<unsigned ndim>
+ bool operator==(const aabb<ndim> &a, const aabb<ndim> &b);
+
+ template<unsigned ndim>
+ bool operator!=(const aabb<ndim> &a, const aabb<ndim> &b);
+
+ template<unsigned ndim>
+ std::ostream &operator<<(std::ostream &o, const aabb<ndim> &a);
+
+
+
+ template<unsigned ndim, typename obj_t>
+ struct get_aabb {
+ aabb<ndim> operator()(const obj_t &obj) const {
+ return obj.getAABB();
+ }
+ };
+
+ template<unsigned ndim, typename obj_t>
+ struct get_aabb<ndim, obj_t *> {
+ aabb<ndim> operator()(const obj_t *obj) const {
+ return obj->getAABB();
+ }
+ };
+
+
+
+ }
+}
+
+namespace carve {
+ namespace geom3d {
+ typedef carve::geom::aabb<3> AABB;
+ }
+}
+
+#include <carve/aabb_impl.hpp>
diff --git a/extern/carve/include/carve/aabb_impl.hpp b/extern/carve/include/carve/aabb_impl.hpp
new file mode 100644
index 00000000000..ccdddef160b
--- /dev/null
+++ b/extern/carve/include/carve/aabb_impl.hpp
@@ -0,0 +1,423 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/vector.hpp>
+#include <carve/geom3d.hpp>
+
+#include <carve/geom.hpp>
+
+#include <vector>
+
+namespace carve {
+ namespace geom {
+
+ template<unsigned ndim>
+ void aabb<ndim>::empty() {
+ pos.setZero();
+ extent.setZero();
+ }
+
+ template<unsigned ndim>
+ bool aabb<ndim>::isEmpty() const {
+ return extent.exactlyZero();
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t, typename value_type>
+ void aabb<ndim>::_fit(iter_t begin, iter_t end, value_type) {
+ if (begin == end) {
+ empty();
+ return;
+ }
+
+ vector_t min, max;
+ aabb<ndim> a = get_aabb<ndim, value_type>()(*begin); ++begin;
+ min = a.min();
+ max = a.max();
+ while (begin != end) {
+ aabb<ndim> a = get_aabb<ndim, value_type>()(*begin); ++begin;
+ assign_op(min, min, a.min(), carve::util::min_functor());
+ assign_op(max, max, a.max(), carve::util::max_functor());
+ }
+
+ pos = (min + max) / 2.0;
+ assign_op(extent, max - pos, pos - min, carve::util::max_functor());
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void aabb<ndim>::_fit(iter_t begin, iter_t end, vector_t) {
+ if (begin == end) {
+ empty();
+ return;
+ }
+
+ vector_t min, max;
+ bounds(begin, end, min, max);
+ pos = (min + max) / 2.0;
+ assign_op(extent, max - pos, pos - min, carve::util::max_functor());
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void aabb<ndim>::_fit(iter_t begin, iter_t end, aabb_t) {
+ if (begin == end) {
+ empty();
+ return;
+ }
+
+ vector_t min, max;
+ aabb<ndim> a = *begin++;
+ min = a.min();
+ max = a.max();
+ while (begin != end) {
+ aabb<ndim> a = *begin; ++begin;
+ assign_op(min, min, a.min(), carve::util::min_functor());
+ assign_op(max, max, a.max(), carve::util::max_functor());
+ }
+
+ pos = (min + max) / 2.0;
+ assign_op(extent, max - pos, pos - min, carve::util::max_functor());
+ }
+
+ template<unsigned ndim>
+ void aabb<ndim>::fit(const vector_t &v1) {
+ pos = v1;
+ extent.setZero();
+ }
+
+ template<unsigned ndim>
+ void aabb<ndim>::fit(const vector_t &v1, const vector_t &v2) {
+ vector_t min, max;
+ assign_op(min, v1, v2, carve::util::min_functor());
+ assign_op(max, v1, v2, carve::util::max_functor());
+
+ pos = (min + max) / 2.0;
+ assign_op(extent, max - pos, pos - min, carve::util::max_functor());
+ }
+
+ template<unsigned ndim>
+ void aabb<ndim>::fit(const vector_t &v1, const vector_t &v2, const vector_t &v3) {
+ vector_t min, max;
+ min = max = v1;
+
+ assign_op(min, min, v2, carve::util::min_functor());
+ assign_op(max, max, v2, carve::util::max_functor());
+ assign_op(min, min, v3, carve::util::min_functor());
+ assign_op(max, max, v3, carve::util::max_functor());
+
+ pos = (min + max) / 2.0;
+ assign_op(extent, max - pos, pos - min, carve::util::max_functor());
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t, typename adapt_t>
+ void aabb<ndim>::fit(iter_t begin, iter_t end, adapt_t adapt) {
+ vector_t min, max;
+
+ bounds(begin, end, adapt, min, max);
+ pos = (min + max) / 2.0;
+ assign_op(extent, max - pos, pos - min, carve::util::max_functor());
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void aabb<ndim>::fit(iter_t begin, iter_t end) {
+ _fit(begin, end, typename std::iterator_traits<iter_t>::value_type());
+ }
+
+ template<unsigned ndim>
+ void aabb<ndim>::expand(double pad) {
+ extent += pad;
+ }
+
+ template<unsigned ndim>
+ void aabb<ndim>::unionAABB(const aabb<ndim> &a) {
+ vector_t vmin, vmax;
+
+ assign_op(vmin, min(), a.min(), carve::util::min_functor());
+ assign_op(vmax, max(), a.max(), carve::util::max_functor());
+ pos = (vmin + vmax) / 2.0;
+ assign_op(extent, vmax - pos, pos - vmin, carve::util::max_functor());
+ }
+
+ template<unsigned ndim>
+ bool aabb<ndim>::completelyContains(const aabb<ndim> &other) const {
+ for (unsigned i = 0; i < ndim; ++i) {
+ if (fabs(other.pos.v[i] - pos.v[i]) + other.extent.v[i] > extent.v[i]) return false;
+ }
+ return true;
+ }
+
+ template<unsigned ndim>
+ bool aabb<ndim>::containsPoint(const vector_t &v) const {
+ for (unsigned i = 0; i < ndim; ++i) {
+ if (fabs(v.v[i] - pos.v[i]) > extent.v[i]) return false;
+ }
+ return true;
+ }
+
+ template<unsigned ndim>
+ double aabb<ndim>::axisSeparation(const aabb<ndim> &other, unsigned axis) const {
+ return fabs(other.pos.v[axis] - pos.v[axis]) - extent.v[axis] - other.extent.v[axis];
+ }
+
+ template<unsigned ndim>
+ double aabb<ndim>::maxAxisSeparation(const aabb<ndim> &other) const {
+ double m = axisSeparation(other, 0);
+ for (unsigned i = 1; i < ndim; ++i) {
+ m = std::max(m, axisSeparation(other, i));
+ }
+ return m;
+ }
+
+ template<unsigned ndim>
+ bool aabb<ndim>::intersects(const aabb<ndim> &other) const {
+ return maxAxisSeparation(other) <= 0.0;
+ }
+
+ template<unsigned ndim>
+ bool aabb<ndim>::intersects(const sphere<ndim> &s) const {
+ double r = 0.0;
+ for (unsigned i = 0; i < ndim; ++i) {
+ double t = fabs(s.C[i] - pos[i]) - extent[i]; if (t > 0.0) r += t*t;
+ }
+ return r <= s.r*s.r;
+ }
+
+ template<unsigned ndim>
+ bool aabb<ndim>::intersects(const plane<ndim> &plane) const {
+ double d1 = fabs(distance(plane, pos));
+ double d2 = dot(abs(plane.N), extent);
+ return d1 <= d2;
+ }
+
+ template<unsigned ndim>
+ bool aabb<ndim>::intersects(const linesegment<ndim> &ls) const {
+ return intersectsLineSegment(ls.v1, ls.v2);
+ }
+
+ template<unsigned ndim>
+ std::pair<double, double> aabb<ndim>::rangeInDirection(const carve::geom::vector<ndim> &v) const {
+ double d1 = dot(v, pos);
+ double d2 = dot(abs(v), extent);
+
+ return std::make_pair(d1 - d2, d1 + d2);
+ }
+
+ template<unsigned ndim>
+ typename aabb<ndim>::vector_t aabb<ndim>::min() const { return pos - extent; }
+
+ template<unsigned ndim>
+ typename aabb<ndim>::vector_t aabb<ndim>::mid() const { return pos; }
+
+ template<unsigned ndim>
+ typename aabb<ndim>::vector_t aabb<ndim>::max() const { return pos + extent; }
+
+ template<unsigned ndim>
+ double aabb<ndim>::min(unsigned dim) const { return pos.v[dim] - extent.v[dim]; }
+
+ template<unsigned ndim>
+ double aabb<ndim>::mid(unsigned dim) const { return pos.v[dim]; }
+
+ template<unsigned ndim>
+ double aabb<ndim>::max(unsigned dim) const { return pos.v[dim] + extent.v[dim]; }
+
+ template<unsigned ndim>
+ double aabb<ndim>::volume() const {
+ double v = 1.0;
+ for (size_t dim = 0; dim < ndim; ++dim) { v *= 2.0 * extent.v[dim]; }
+ return v;
+ }
+
+ template<unsigned ndim>
+ int aabb<ndim>::compareAxis(const axis_pos &ap) const {
+ double p = ap.pos - pos[ap.axis];
+ if (p > extent[ap.axis]) return -1;
+ if (p < -extent[ap.axis]) return +1;
+ return 0;
+ }
+
+ template<unsigned ndim>
+ void aabb<ndim>::constrainMax(const axis_pos &ap) {
+ if (pos[ap.axis] + extent[ap.axis] > ap.pos) {
+ double min = std::min(ap.pos, pos[ap.axis] - extent[ap.axis]);
+ pos[ap.axis] = (min + ap.pos) / 2.0;
+ extent[ap.axis] = ap.pos - pos[ap.axis];
+ }
+ }
+
+ template<unsigned ndim>
+ void aabb<ndim>::constrainMin(const axis_pos &ap) {
+ if (pos[ap.axis] - extent[ap.axis] < ap.pos) {
+ double max = std::max(ap.pos, pos[ap.axis] + extent[ap.axis]);
+ pos[ap.axis] = (ap.pos + max) / 2.0;
+ extent[ap.axis] = pos[ap.axis] - ap.pos;
+ }
+ }
+
+ template<unsigned ndim>
+ aabb<ndim> aabb<ndim>::getAABB() const {
+ return *this;
+ }
+
+ template<unsigned ndim>
+ aabb<ndim>::aabb(const vector_t &_pos,
+ const vector_t &_extent) : pos(_pos), extent(_extent) {
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t, typename adapt_t>
+ aabb<ndim>::aabb(iter_t begin, iter_t end, adapt_t adapt) {
+ fit(begin, end, adapt);
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ aabb<ndim>::aabb(iter_t begin, iter_t end) {
+ fit(begin, end);
+ }
+
+ template<unsigned ndim>
+ aabb<ndim>::aabb(const aabb<ndim> &a, const aabb<ndim> &b) {
+ fit(a, b);
+ }
+
+ template<unsigned ndim>
+ bool operator==(const aabb<ndim> &a, const aabb<ndim> &b) {
+ return a.pos == b.pos && a.extent == b.extent;
+ }
+
+ template<unsigned ndim>
+ bool operator!=(const aabb<ndim> &a, const aabb<ndim> &b) {
+ return a.pos != b.pos || a.extent != b.extent;
+ }
+
+ template<unsigned ndim>
+ std::ostream &operator<<(std::ostream &o, const aabb<ndim> &a) {
+ o << (a.pos - a.extent) << "--" << (a.pos + a.extent);
+ return o;
+ }
+
+ template<>
+ inline bool aabb<3>::intersects(const ray<3> &ray) const {
+ vector<3> t = pos - ray.v;
+ double r;
+
+ //l.cross(x-axis)?
+ r = extent.y * fabs(ray.D.z) + extent.z * fabs(ray.D.y);
+ if (fabs(t.y * ray.D.z - t.z * ray.D.y) > r) return false;
+
+ //ray.D.cross(y-axis)?
+ r = extent.x * fabs(ray.D.z) + extent.z * fabs(ray.D.x);
+ if (fabs(t.z * ray.D.x - t.x * ray.D.z) > r) return false;
+
+ //ray.D.cross(z-axis)?
+ r = extent.x*fabs(ray.D.y) + extent.y*fabs(ray.D.x);
+ if (fabs(t.x * ray.D.y - t.y * ray.D.x) > r) return false;
+
+ return true;
+ }
+
+ template<>
+ inline bool aabb<3>::intersectsLineSegment(const vector<3> &v1, const vector<3> &v2) const {
+ vector<3> half_length = 0.5 * (v2 - v1);
+ vector<3> t = pos - half_length - v1;
+ double r;
+
+ //do any of the principal axes form a separating axis?
+ if(fabs(t.x) > extent.x + fabs(half_length.x)) return false;
+ if(fabs(t.y) > extent.y + fabs(half_length.y)) return false;
+ if(fabs(t.z) > extent.z + fabs(half_length.z)) return false;
+
+ // NOTE: Since the separating axis is perpendicular to the line in
+ // these last four cases, the line does not contribute to the
+ // projection.
+
+ //line.cross(x-axis)?
+ r = extent.y * fabs(half_length.z) + extent.z * fabs(half_length.y);
+ if (fabs(t.y * half_length.z - t.z * half_length.y) > r) return false;
+
+ //half_length.cross(y-axis)?
+ r = extent.x * fabs(half_length.z) + extent.z * fabs(half_length.x);
+ if (fabs(t.z * half_length.x - t.x * half_length.z) > r) return false;
+
+ //half_length.cross(z-axis)?
+ r = extent.x*fabs(half_length.y) + extent.y*fabs(half_length.x);
+ if (fabs(t.x * half_length.y - t.y * half_length.x) > r) return false;
+
+ return true;
+ }
+
+ template<int Ax, int Ay, int Az, int c>
+ static inline bool intersectsTriangle_axisTest_3(const aabb<3> &aabb, const tri<3> &tri) {
+ const int d = (c+1) % 3, e = (c+2) % 3;
+ const vector<3> a = cross(VECTOR(Ax, Ay, Az), tri.v[d] - tri.v[c]);
+ double p1 = dot(a, tri.v[c]), p2 = dot(a, tri.v[e]);
+ if (p1 > p2) std::swap(p1, p2);
+ const double r = dot(abs(a), aabb.extent);
+ return !(p1 > r || p2 < -r);
+ }
+
+ template<int c>
+ static inline bool intersectsTriangle_axisTest_2(const aabb<3> &aabb, const tri<3> &tri) {
+ double vmin = std::min(std::min(tri.v[0][c], tri.v[1][c]), tri.v[2][c]),
+ vmax = std::max(std::max(tri.v[0][c], tri.v[1][c]), tri.v[2][c]);
+ return !(vmin > aabb.extent[c] || vmax < -aabb.extent[c]);
+ }
+
+ static inline bool intersectsTriangle_axisTest_1(const aabb<3> &aabb, const tri<3> &tri) {
+ vector<3> n = cross(tri.v[1] - tri.v[0], tri.v[2] - tri.v[0]);
+ double d1 = fabs(dot(n, tri.v[0]));
+ double d2 = dot(abs(n), aabb.extent);
+ return d1 <= d2;
+ }
+
+ template<>
+ inline bool aabb<3>::intersects(tri<3> tri) const {
+ tri.v[0] -= pos;
+ tri.v[1] -= pos;
+ tri.v[2] -= pos;
+
+ if (!intersectsTriangle_axisTest_2<0>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_2<1>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_2<2>(*this, tri)) return false;
+
+ if (!intersectsTriangle_axisTest_3<1,0,0,0>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_3<1,0,0,1>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_3<1,0,0,2>(*this, tri)) return false;
+
+ if (!intersectsTriangle_axisTest_3<0,1,0,0>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_3<0,1,0,1>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_3<0,1,0,2>(*this, tri)) return false;
+
+ if (!intersectsTriangle_axisTest_3<0,0,1,0>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_3<0,0,1,1>(*this, tri)) return false;
+ if (!intersectsTriangle_axisTest_3<0,0,1,2>(*this, tri)) return false;
+
+ if (!intersectsTriangle_axisTest_1(*this, tri)) return false;
+
+ return true;
+ }
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/carve.hpp b/extern/carve/include/carve/carve.hpp
new file mode 100644
index 00000000000..90ca6b4977b
--- /dev/null
+++ b/extern/carve/include/carve/carve.hpp
@@ -0,0 +1,238 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#if defined(CMAKE_BUILD)
+# include <carve/config.h>
+#elif defined(XCODE_BUILD)
+# include <carve/xcode_config.h>
+#elif defined(_MSC_VER)
+# include <carve/vcpp_config.h>
+#else
+# include <carve/config.h>
+#endif
+
+#if defined(WIN32)
+# include <carve/win32.h>
+#elif defined(__GNUC__)
+# include <carve/gnu_cxx.h>
+#endif
+
+#if defined(CARVE_SYSTEM_BOOST)
+# define BOOST_INCLUDE(x) <boost/x>
+#else
+# define BOOST_INCLUDE(x) <carve/external/boost/x>
+#endif
+
+#include <math.h>
+
+#include <string>
+#include <set>
+#include <map>
+#include <vector>
+#include <list>
+#include <sstream>
+#include <iomanip>
+
+#include <carve/collection.hpp>
+
+#include <carve/util.hpp>
+
+#include <stdarg.h>
+
+#define STR(x) #x
+#define XSTR(x) STR(x)
+
+/**
+ * \brief Top level Carve namespace.
+ */
+namespace carve {
+ static struct noinit_t {} NOINIT;
+
+ inline std::string fmtstring(const char *fmt, ...);
+
+ /**
+ * \brief Base class for all Carve exceptions.
+ */
+ struct exception {
+ private:
+ mutable std::string err;
+ mutable std::ostringstream accum;
+
+ public:
+ exception(const std::string &e) : err(e), accum() { }
+ exception() : err(), accum() { }
+ exception(const exception &e) : err(e.str()), accum() { }
+ exception &operator=(const exception &e) {
+ if (this != &e) {
+ err = e.str();
+ accum.str("");
+ }
+ return *this;
+ }
+
+ const std::string &str() const {
+ if (accum.str().size() > 0) {
+ err += accum.str();
+ accum.str("");
+ }
+ return err;
+ }
+
+ template<typename T>
+ exception &operator<<(const T &t) {
+ accum << t;
+ return *this;
+ }
+ };
+
+ template<typename iter_t, typename order_t = std::less<typename std::iterator_traits<iter_t>::value_type > >
+ struct index_sort {
+ iter_t base;
+ order_t order;
+ index_sort(const iter_t &_base) : base(_base), order() { }
+ index_sort(const iter_t &_base, const order_t &_order) : base(_base), order(_order) { }
+ template<typename U>
+ bool operator()(const U &a, const U &b) {
+ return order(*(base + a), *(base + b));
+ }
+ };
+
+ template<typename iter_t, typename order_t>
+ index_sort<iter_t, order_t> make_index_sort(const iter_t &base, const order_t &order) {
+ return index_sort<iter_t, order_t>(base, order);
+ }
+
+ template<typename iter_t>
+ index_sort<iter_t> make_index_sort(const iter_t &base) {
+ return index_sort<iter_t>(base);
+ }
+
+
+ enum RayIntersectionClass {
+ RR_DEGENERATE = -2,
+ RR_PARALLEL = -1,
+ RR_NO_INTERSECTION = 0,
+ RR_INTERSECTION = 1
+ };
+
+ enum LineIntersectionClass {
+ COLINEAR = -1,
+ NO_INTERSECTION = 0,
+ INTERSECTION_LL = 1,
+ INTERSECTION_PL = 2,
+ INTERSECTION_LP = 3,
+ INTERSECTION_PP = 4
+ };
+
+ enum PointClass {
+ POINT_UNK = -2,
+ POINT_OUT = -1,
+ POINT_ON = 0,
+ POINT_IN = 1,
+ POINT_VERTEX = 2,
+ POINT_EDGE = 3
+ };
+
+ enum IntersectionClass {
+ INTERSECT_BAD = -1,
+ INTERSECT_NONE = 0,
+ INTERSECT_FACE = 1,
+ INTERSECT_VERTEX = 2,
+ INTERSECT_EDGE = 3,
+ INTERSECT_PLANE = 4,
+ };
+
+
+
+ extern double EPSILON;
+ extern double EPSILON2;
+
+ static inline void setEpsilon(double ep) { EPSILON = ep; EPSILON2 = ep * ep; }
+
+
+
+ template<typename T>
+ struct identity_t {
+ typedef T argument_type;
+ typedef T result_type;
+ const T &operator()(const T &t) const { return t; }
+ };
+
+
+
+ template<typename iter_t>
+ inline bool is_sorted(iter_t first, iter_t last) {
+ if (first == last) return true;
+
+ iter_t iter = first;
+ iter_t next = first; ++next;
+ for (; next != last; iter = next, ++next) {
+ if (*next < *iter) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+
+ template<typename iter_t,
+ typename pred_t>
+ inline bool is_sorted(iter_t first, iter_t last, pred_t pred) {
+ if (first == last) return true;
+
+ iter_t iter = first;
+ iter_t next = first; ++next;
+ for (; next != last; iter = next, ++next) {
+ if (pred(*next, *iter)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+
+ inline double rangeSeparation(const std::pair<double, double> &a,
+ const std::pair<double, double> &b) {
+ if (a.second < b.first) {
+ return b.first - a.second;
+ } else if (b.second < a.first) {
+ return a.first - b.second;
+ } else {
+ return 0.0;
+ }
+ }
+}
+
+
+#if defined(_MSC_VER)
+# define MACRO_BEGIN do {
+# define MACRO_END __pragma(warning(push)) __pragma(warning(disable:4127)) } while(0) __pragma(warning(pop))
+#else
+# define MACRO_BEGIN do {
+# define MACRO_END } while(0)
+#endif
+
+#if !defined(CARVE_NODEBUG)
+# define CARVE_ASSERT(x) MACRO_BEGIN if (!(x)) throw carve::exception() << __FILE__ << ":" << __LINE__ << " " << #x; MACRO_END
+#else
+# define CARVE_ASSERT(X)
+#endif
+
+#define CARVE_FAIL(x) MACRO_BEGIN throw carve::exception() << __FILE__ << ":" << __LINE__ << " " << #x; MACRO_END
diff --git a/extern/carve/include/carve/cbrt.h b/extern/carve/include/carve/cbrt.h
new file mode 100644
index 00000000000..aeceab01426
--- /dev/null
+++ b/extern/carve/include/carve/cbrt.h
@@ -0,0 +1,93 @@
+// N.B. only appropriate for IEEE doubles.
+// Cube root implementation obtained from code with the following notice:
+
+/* @(#)s_cbrt.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ */
+
+/* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly
+ but these catch some common cases. */
+
+#if defined(i386) || defined(i486) || \
+ defined(intel) || defined(x86) || defined(i86pc) || \
+ defined(__alpha) || defined(__osf__)
+#define __LITTLE_ENDIAN
+#endif
+
+#ifdef __LITTLE_ENDIAN
+#define __HI(x) *(1+(int*)&x)
+#define __LO(x) *(int*)&x
+#define __HIp(x) *(1+(int*)x)
+#define __LOp(x) *(int*)x
+#else
+#define __HI(x) *(int*)&x
+#define __LO(x) *(1+(int*)&x)
+#define __HIp(x) *(int*)x
+#define __LOp(x) *(1+(int*)x)
+#endif
+
+/* cbrt(x)
+ * Return cube root of x
+ */
+
+inline double cbrt(double x) {
+
+ static const unsigned
+ B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */
+ B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */
+ static const double
+ C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */
+ D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */
+ E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */
+ F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */
+ G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
+
+ int hx;
+ double r,s,t=0.0,w;
+ unsigned sign;
+
+ hx = __HI(x); /* high word of x */
+ sign=hx&0x80000000; /* sign= sign(x) */
+ hx ^=sign;
+ if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
+ if((hx|__LO(x))==0)
+ return(x); /* cbrt(0) is itself */
+
+ __HI(x) = hx; /* x <- |x| */
+ /* rough cbrt to 5 bits */
+ if(hx<0x00100000) /* subnormal number */
+ {__HI(t)=0x43500000; /* set t= 2**54 */
+ t*=x; __HI(t)=__HI(t)/3+B2;
+ }
+ else
+ __HI(t)=hx/3+B1;
+
+
+ /* new cbrt to 23 bits, may be implemented in single precision */
+ r=t*t/x;
+ s=C+r*t;
+ t*=G+F/(s+E+D/s);
+
+ /* chopped to 20 bits and make it larger than cbrt(x) */
+ __LO(t)=0; __HI(t)+=0x00000001;
+
+ /* one step newton iteration to 53 bits with error less than 0.667 ulps */
+ s=t*t; /* t*t is exact */
+ r=x/s;
+ w=t+t;
+ r=(r-t)/(w+r); /* r-s is exact */
+ t=t+t*r;
+
+ /* retore the sign bit */
+ __HI(t) |= sign;
+ return(t);
+}
diff --git a/extern/carve/include/carve/classification.hpp b/extern/carve/include/carve/classification.hpp
new file mode 100644
index 00000000000..7df86db7823
--- /dev/null
+++ b/extern/carve/include/carve/classification.hpp
@@ -0,0 +1,115 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/collection_types.hpp>
+
+namespace carve {
+ namespace csg {
+
+ enum FaceClass {
+ FACE_UNCLASSIFIED = -3,
+ FACE_ON_ORIENT_OUT = -2,
+ FACE_OUT = -1,
+ FACE_ON = 0,
+ FACE_IN = +1,
+ FACE_ON_ORIENT_IN = +2
+ };
+
+ enum FaceClassBit {
+ FACE_ON_ORIENT_OUT_BIT = 0x01,
+ FACE_OUT_BIT = 0x02,
+ FACE_IN_BIT = 0x04,
+ FACE_ON_ORIENT_IN_BIT = 0x08,
+
+ FACE_ANY_BIT = 0x0f,
+ FACE_ON_BIT = 0x09,
+ FACE_NOT_ON_BIT = 0x06
+ };
+
+ static inline FaceClass class_bit_to_class(unsigned i) {
+ if (i & FACE_ON_ORIENT_OUT_BIT) return FACE_ON_ORIENT_OUT;
+ if (i & FACE_OUT_BIT) return FACE_OUT;
+ if (i & FACE_IN_BIT) return FACE_IN;
+ if (i & FACE_ON_ORIENT_IN_BIT) return FACE_ON_ORIENT_IN;
+ return FACE_UNCLASSIFIED;
+ }
+
+ static inline unsigned class_to_class_bit(FaceClass f) {
+ switch (f) {
+ case FACE_ON_ORIENT_OUT: return FACE_ON_ORIENT_OUT_BIT;
+ case FACE_OUT: return FACE_OUT_BIT;
+ case FACE_ON: return FACE_ON_BIT;
+ case FACE_IN: return FACE_IN_BIT;
+ case FACE_ON_ORIENT_IN: return FACE_ON_ORIENT_IN_BIT;
+ case FACE_UNCLASSIFIED: return FACE_ANY_BIT;
+ default: return 0;
+ }
+ }
+
+ enum EdgeClass {
+ EDGE_UNK = -2,
+ EDGE_OUT = -1,
+ EDGE_ON = 0,
+ EDGE_IN = 1
+ };
+
+
+
+ const char *ENUM(FaceClass f);
+ const char *ENUM(PointClass p);
+
+
+
+ struct ClassificationInfo {
+ const carve::mesh::Mesh<3> *intersected_mesh;
+ FaceClass classification;
+
+ ClassificationInfo() : intersected_mesh(NULL), classification(FACE_UNCLASSIFIED) { }
+ ClassificationInfo(const carve::mesh::Mesh<3> *_intersected_mesh,
+ FaceClass _classification) :
+ intersected_mesh(_intersected_mesh),
+ classification(_classification) {
+ }
+ bool intersectedMeshIsClosed() const {
+ return intersected_mesh->isClosed();
+ }
+ };
+
+
+
+ struct EC2 {
+ EdgeClass cls[2];
+ EC2() { cls[0] = cls[1] = EDGE_UNK; }
+ EC2(EdgeClass a, EdgeClass b) { cls[0] = a; cls[1] = b; }
+ };
+
+ struct PC2 {
+ PointClass cls[2];
+ PC2() { cls[0] = cls[1] = POINT_UNK; }
+ PC2(PointClass a, PointClass b) { cls[0] = a; cls[1] = b; }
+ };
+
+ typedef std::unordered_map<std::pair<const carve::mesh::MeshSet<3>::vertex_t *, const carve::mesh::MeshSet<3>::vertex_t *>,
+ EC2> EdgeClassification;
+
+ typedef std::unordered_map<const carve::mesh::Vertex<3> *, PC2> VertexClassification;
+
+ }
+}
diff --git a/extern/carve/include/carve/collection.hpp b/extern/carve/include/carve/collection.hpp
new file mode 100644
index 00000000000..ace63d174f6
--- /dev/null
+++ b/extern/carve/include/carve/collection.hpp
@@ -0,0 +1,51 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/collection/unordered.hpp>
+
+namespace carve {
+
+ template<typename set_t>
+ class set_insert_iterator : public std::iterator<std::output_iterator_tag, void, void, void, void> {
+
+ protected:
+ set_t *set;
+ public:
+
+ set_insert_iterator(set_t &s) : set(&s) {
+ }
+
+ set_insert_iterator &
+ operator=(typename set_t::const_reference value) {
+ set->insert(value);
+ return *this;
+ }
+
+ set_insert_iterator &operator*() { return *this; }
+ set_insert_iterator &operator++() { return *this; }
+ set_insert_iterator &operator++(int) { return *this; }
+ };
+
+ template<typename set_t>
+ inline set_insert_iterator<set_t>
+ set_inserter(set_t &s) {
+ return set_insert_iterator<set_t>(s);
+ }
+
+}
diff --git a/extern/carve/include/carve/collection/unordered.hpp b/extern/carve/include/carve/collection/unordered.hpp
new file mode 100644
index 00000000000..494a1ca4013
--- /dev/null
+++ b/extern/carve/include/carve/collection/unordered.hpp
@@ -0,0 +1,43 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#if defined(HAVE_STD_UNORDERED_COLLECTIONS)
+
+# include <carve/collection/unordered/std_impl.hpp>
+
+#elif defined(HAVE_TR1_UNORDERED_COLLECTIONS)
+
+# include <carve/collection/unordered/tr1_impl.hpp>
+
+#elif defined(HAVE_BOOST_UNORDERED_COLLECTIONS)
+
+# include <carve/collection/unordered/boost_impl.hpp>
+
+#elif defined(HAVE_LIBSTDCPP_UNORDERED_COLLECTIONS)
+
+# include <carve/collection/unordered/libstdcpp_impl.hpp>
+
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
+
+# include <carve/collection/unordered/vcpp_impl.hpp>
+
+#else
+
+# include <carve/collection/unordered/fallback_impl.hpp>
+
+#endif
diff --git a/extern/carve/include/carve/collection/unordered/boost_impl.hpp b/extern/carve/include/carve/collection/unordered/boost_impl.hpp
new file mode 100644
index 00000000000..96b1407e9eb
--- /dev/null
+++ b/extern/carve/include/carve/collection/unordered/boost_impl.hpp
@@ -0,0 +1,45 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include BOOST_INCLUDE(unordered_set.hpp)
+#include BOOST_INCLUDE(unordered_map.hpp)
+
+#include <functional>
+
+namespace std {
+ template <typename Key, typename T, typename Hash = boost::hash<Key>,
+ typename Pred = std::equal_to<Key> >
+ class unordered_map : public boost::unordered_map<Key, T, Hash, Pred> {
+
+ public:
+ typedef T data_type;
+ };
+
+ template <typename Key, typename T, typename Hash = boost::hash<Key>,
+ typename Pred = std::equal_to<Key> >
+ class unordered_multimap : public boost::unordered_multimap<Key, T, Hash, Pred> {
+ };
+
+ template <typename Value, typename Hash = boost::hash<Value>,
+ typename Pred = std::equal_to<Value> >
+ class unordered_set : public boost::unordered_set<Value, Hash, Pred> {
+ };
+}
+
+#undef UNORDERED_COLLECTIONS_SUPPORT_RESIZE
diff --git a/extern/carve/include/carve/collection/unordered/fallback_impl.hpp b/extern/carve/include/carve/collection/unordered/fallback_impl.hpp
new file mode 100644
index 00000000000..70422b2a215
--- /dev/null
+++ b/extern/carve/include/carve/collection/unordered/fallback_impl.hpp
@@ -0,0 +1,40 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <set>
+#include <map>
+
+namespace std {
+
+ template<typename K, typename T, typename H = int>
+ class unordered_map : public std::map<K, T> {
+ typedef std::map<K, T> super;
+ public:
+ typedef T data_type;
+ };
+
+ template<typename K, typename H = int>
+ class unordered_set : public std::set<K> {
+ typedef std::set<K> super;
+ public:
+ };
+
+}
+
+#undef UNORDERED_COLLECTIONS_SUPPORT_RESIZE
diff --git a/extern/carve/include/carve/collection/unordered/libstdcpp_impl.hpp b/extern/carve/include/carve/collection/unordered/libstdcpp_impl.hpp
new file mode 100644
index 00000000000..e1ad430709d
--- /dev/null
+++ b/extern/carve/include/carve/collection/unordered/libstdcpp_impl.hpp
@@ -0,0 +1,61 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#include <ext/hash_map>
+#include <ext/hash_set>
+
+namespace __gnu_cxx {
+ template <typename T>
+ struct hash<T *> : public std::unary_function<T *, size_t> {
+ size_t operator()(T *v) const {
+ size_t x = (size_t)(v);
+ return x + (x>>3);
+ }
+ };
+
+ template <typename A, typename B>
+ struct hash<std::pair<A, B> > : public std::unary_function<std::pair<A, B>, size_t> {
+ size_t operator()(const std::pair<A, B> &v) const {
+ std::size_t seed = 0;
+
+ seed ^= hash<A>()(v.first);
+ seed ^= hash<B>()(v.second) + (seed<<6) + (seed>>2);
+
+ return seed;
+ }
+ };
+}
+
+namespace std {
+
+ template<typename K, typename V, typename H = __gnu_cxx::hash<K> >
+ class unordered_map : public __gnu_cxx::hash_map<K, V, H> {
+ typedef __gnu_cxx::hash_map<K, V, H> super;
+ public:
+ typedef typename super::mapped_type data_type;
+ };
+
+ template<typename K, typename H = __gnu_cxx::hash<K> >
+ class unordered_set : public __gnu_cxx::hash_set<K, H> {
+ typedef __gnu_cxx::hash_set<K, H> super;
+ public:
+ };
+
+}
+
+#define UNORDERED_COLLECTIONS_SUPPORT_RESIZE 1
diff --git a/extern/carve/include/carve/collection/unordered/std_impl.hpp b/extern/carve/include/carve/collection/unordered/std_impl.hpp
new file mode 100644
index 00000000000..68a3f122e86
--- /dev/null
+++ b/extern/carve/include/carve/collection/unordered/std_impl.hpp
@@ -0,0 +1,23 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <unordered_map>
+#include <unordered_set>
+
+#undef UNORDERED_COLLECTIONS_SUPPORT_RESIZE
diff --git a/extern/carve/include/carve/collection/unordered/tr1_impl.hpp b/extern/carve/include/carve/collection/unordered/tr1_impl.hpp
new file mode 100644
index 00000000000..2c7f39f6a74
--- /dev/null
+++ b/extern/carve/include/carve/collection/unordered/tr1_impl.hpp
@@ -0,0 +1,58 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <tr1/unordered_map>
+#include <tr1/unordered_set>
+#include <tr1/functional>
+
+namespace std {
+ namespace tr1 {
+ template <typename A, typename B>
+ struct hash<std::pair<A, B> > : public std::unary_function<std::pair<A, B>, size_t> {
+ size_t operator()(const std::pair<A, B> &v) const {
+ std::size_t seed = 0;
+
+ seed ^= hash<A>()(v.first);
+ seed ^= hash<B>()(v.second) + (seed<<6) + (seed>>2);
+
+ return seed;
+ }
+ };
+ }
+
+
+
+ template <typename Key, typename T,
+ typename Hash = tr1::hash<Key>,
+ typename Pred = std::equal_to<Key> >
+ class unordered_map : public std::tr1::unordered_map<Key, T, Hash, Pred> {
+ public:
+ typedef T data_type;
+ };
+
+ template <typename Value,
+ typename Hash = tr1::hash<Value>,
+ typename Pred = std::equal_to<Value> >
+ class unordered_set : public std::tr1::unordered_set<Value, Hash, Pred> {
+ public:
+ };
+
+}
+
+#undef UNORDERED_COLLECTIONS_SUPPORT_RESIZE
diff --git a/extern/carve/include/carve/collection/unordered/vcpp_impl.hpp b/extern/carve/include/carve/collection/unordered/vcpp_impl.hpp
new file mode 100644
index 00000000000..825edad1433
--- /dev/null
+++ b/extern/carve/include/carve/collection/unordered/vcpp_impl.hpp
@@ -0,0 +1,65 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <hash_map>
+#include <hash_set>
+
+namespace std {
+
+ namespace {
+
+ template<class Value, class Hash> class hash_traits {
+ Hash hash_value;
+ std::less<Value> comp;
+ public:
+ enum {
+ bucket_size = 4,
+ min_buckets = 8
+ };
+ // hash _Keyval to size_t value
+ size_t operator()(const Value& v) const {
+ return ((size_t)hash_value(v));
+ }
+ // test if _Keyval1 ordered before _Keyval2
+ bool operator()(const Value& v1, const Value& v2) const {
+ return (comp(v1, v2));
+ }
+ };
+
+ }
+
+ template <typename Key, typename T, typename Hash = stdext::hash_compare<Key, less<Key> >, typename Pred = std::equal_to<Key> >
+ class unordered_map
+ : public stdext::hash_map<Key, T, hash_traits<Key, Hash> > {
+ typedef stdext::hash_map<Key, T, hash_traits<Key, Hash> > super;
+ public:
+ unordered_map() : super() {}
+ };
+
+ template <typename Value, typename Hash = stdext::hash_compare<Key, less<Key> >, typename Pred = std::equal_to<Value> >
+ class unordered_set
+ : public stdext::hash_set<Value, hash_traits<Value, Hash> > {
+ typedef stdext::hash_set<Value, hash_traits<Value, Hash> > super;
+ public:
+ unordered_set() : super() {}
+ };
+
+}
+
+#undef UNORDERED_COLLECTIONS_SUPPORT_RESIZE
diff --git a/extern/carve/include/carve/collection_types.hpp b/extern/carve/include/carve/collection_types.hpp
new file mode 100644
index 00000000000..997d5811801
--- /dev/null
+++ b/extern/carve/include/carve/collection_types.hpp
@@ -0,0 +1,63 @@
+
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/mesh.hpp>
+
+namespace carve {
+ namespace csg {
+
+ typedef std::pair<
+ carve::mesh::MeshSet<3>::vertex_t *,
+ carve::mesh::MeshSet<3>::vertex_t *> V2;
+
+ typedef std::pair<
+ carve::mesh::MeshSet<3>::face_t *,
+ carve::mesh::MeshSet<3>::face_t *> F2;
+
+ static inline V2 ordered_edge(
+ carve::mesh::MeshSet<3>::vertex_t *a,
+ carve::mesh::MeshSet<3>::vertex_t *b) {
+ return V2(std::min(a, b), std::max(a, b));
+ }
+
+ static inline V2 flip(const V2 &v) {
+ return V2(v.second, v.first);
+ }
+
+ // include/carve/csg.hpp include/carve/faceloop.hpp
+ // lib/intersect.cpp lib/intersect_classify_common_impl.hpp
+ // lib/intersect_classify_edge.cpp
+ // lib/intersect_classify_group.cpp
+ // lib/intersect_classify_simple.cpp
+ // lib/intersect_face_division.cpp lib/intersect_group.cpp
+ // lib/intersect_half_classify_group.cpp
+ typedef std::unordered_set<V2> V2Set;
+
+ // include/carve/csg.hpp include/carve/polyhedron_decl.hpp
+ // lib/csg_collector.cpp lib/intersect.cpp
+ // lib/intersect_common.hpp lib/intersect_face_division.cpp
+ // lib/polyhedron.cpp
+ typedef std::unordered_map<
+ carve::mesh::MeshSet<3>::vertex_t *,
+ carve::mesh::MeshSet<3>::vertex_t *> VVMap;
+ }
+}
diff --git a/extern/carve/include/carve/colour.hpp b/extern/carve/include/carve/colour.hpp
new file mode 100644
index 00000000000..420f8f7e13b
--- /dev/null
+++ b/extern/carve/include/carve/colour.hpp
@@ -0,0 +1,47 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/geom.hpp>
+
+namespace carve {
+ namespace colour {
+ static inline void HSV2RGB(float H, float S, float V, float &r, float &g, float &b) {
+ H = 6.0f * H;
+ if (S < 5.0e-6) {
+ r = g = b = V; return;
+ } else {
+ int i = (int)H;
+ float f = H - i;
+ float p1 = V * (1.0f - S);
+ float p2 = V * (1.0f - S * f);
+ float p3 = V * (1.0f - S * (1.0f - f));
+ switch (i) {
+ case 0: r = V; g = p3; b = p1; return;
+ case 1: r = p2; g = V; b = p1; return;
+ case 2: r = p1; g = V; b = p3; return;
+ case 3: r = p1; g = p2; b = V; return;
+ case 4: r = p3; g = p1; b = V; return;
+ case 5: r = V; g = p1; b = p2; return;
+ }
+ }
+ r = g = b = 0.0;
+ }
+ }
+}
diff --git a/extern/carve/include/carve/config.h b/extern/carve/include/carve/config.h
new file mode 100644
index 00000000000..fdae2d2843f
--- /dev/null
+++ b/extern/carve/include/carve/config.h
@@ -0,0 +1,12 @@
+#define CARVE_VERSION "2.0.0a"
+
+#undef CARVE_DEBUG
+#undef CARVE_DEBUG_WRITE_PLY_DATA
+
+#if defined(__GNUC__)
+# if !defined(HAVE_BOOST_UNORDERED_COLLECTIONS)
+# define HAVE_TR1_UNORDERED_COLLECTIONS
+# endif
+
+# define HAVE_STDINT_H
+#endif
diff --git a/extern/carve/include/carve/convex_hull.hpp b/extern/carve/include/carve/convex_hull.hpp
new file mode 100644
index 00000000000..bcb7c97e20f
--- /dev/null
+++ b/extern/carve/include/carve/convex_hull.hpp
@@ -0,0 +1,52 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <list>
+#include <vector>
+#include <algorithm>
+
+#include <carve/carve.hpp>
+
+#include <carve/geom2d.hpp>
+
+namespace carve {
+ namespace geom {
+ std::vector<int> convexHull(const std::vector<carve::geom2d::P2> &points);
+
+ template<typename project_t, typename polygon_container_t>
+ std::vector<int> convexHull(const project_t &project, const polygon_container_t &points) {
+ std::vector<carve::geom2d::P2> proj;
+ proj.reserve(points.size());
+ for (typename polygon_container_t::const_iterator i = points.begin(); i != points.end(); ++i) {
+ proj.push_back(project(*i));
+ }
+ return convexHull(proj);
+ }
+
+ template<typename project_t, typename iter_t>
+ std::vector<int> convexHull(const project_t &project, iter_t beg, iter_t end, size_t size_hint = 0) {
+ std::vector<carve::geom2d::P2> proj;
+ if (size_hint) proj.reserve(size_hint);
+ for (; beg != end; ++beg) {
+ proj.push_back(project(*beg));
+ }
+ return convexHull(proj);
+ }
+ }
+}
diff --git a/extern/carve/include/carve/csg.hpp b/extern/carve/include/carve/csg.hpp
new file mode 100644
index 00000000000..db32273a33c
--- /dev/null
+++ b/extern/carve/include/carve/csg.hpp
@@ -0,0 +1,498 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <list>
+#include <vector>
+#include <algorithm>
+
+#include <carve/carve.hpp>
+
+#include <carve/geom3d.hpp>
+
+#include <carve/mesh.hpp>
+
+#include <carve/collection_types.hpp>
+#include <carve/classification.hpp>
+#include <carve/iobj.hpp>
+#include <carve/faceloop.hpp>
+#include <carve/intersection.hpp>
+#include <carve/rtree.hpp>
+
+namespace carve {
+ namespace csg {
+
+ class VertexPool {
+ typedef carve::mesh::MeshSet<3>::vertex_t vertex_t;
+
+ const static unsigned blocksize = 1024;
+ typedef std::list<std::vector<vertex_t> > pool_t;
+ pool_t pool;
+ public:
+ void reset();
+ vertex_t *get(const vertex_t::vector_t &v = vertex_t::vector_t::ZERO());
+ bool inPool(vertex_t *v) const;
+
+ VertexPool();
+ ~VertexPool();
+ };
+
+
+
+ namespace detail {
+ struct Data;
+ class LoopEdges;
+ }
+
+ /**
+ * \class CSG
+ * \brief The class responsible for the computation of CSG operations.
+ *
+ */
+ class CSG {
+ private:
+
+ public:
+ typedef carve::mesh::MeshSet<3> meshset_t;
+
+ struct Hook {
+ /**
+ * \class Hook
+ * \brief Provides API access to intermediate steps in CSG calculation.
+ *
+ */
+ virtual void intersectionVertex(const meshset_t::vertex_t * /* vertex */,
+ const IObjPairSet & /* intersections */) {
+ }
+ virtual void processOutputFace(std::vector<meshset_t::face_t *> & /* faces */,
+ const meshset_t::face_t * /* orig_face */,
+ bool /* flipped */) {
+ }
+ virtual void resultFace(const meshset_t::face_t * /* new_face */,
+ const meshset_t::face_t * /* orig_face */,
+ bool /* flipped */) {
+ }
+
+ virtual ~Hook() {
+ }
+ };
+
+ /**
+ * \class Hooks
+ * \brief Management of API hooks.
+ *
+ */
+ class Hooks {
+ public:
+ enum {
+ RESULT_FACE_HOOK = 0,
+ PROCESS_OUTPUT_FACE_HOOK = 1,
+ INTERSECTION_VERTEX_HOOK = 2,
+ HOOK_MAX = 3,
+
+ RESULT_FACE_BIT = 0x0001,
+ PROCESS_OUTPUT_FACE_BIT = 0x0002,
+ INTERSECTION_VERTEX_BIT = 0x0004
+ };
+
+ std::vector<std::list<Hook *> > hooks;
+
+ bool hasHook(unsigned hook_num);
+
+ void intersectionVertex(const meshset_t::vertex_t *vertex,
+ const IObjPairSet &intersections);
+
+ void processOutputFace(std::vector<meshset_t::face_t *> &faces,
+ const meshset_t::face_t *orig_face,
+ bool flipped);
+
+ void resultFace(const meshset_t::face_t *new_face,
+ const meshset_t::face_t *orig_face,
+ bool flipped);
+
+ void registerHook(Hook *hook, unsigned hook_bits);
+ void unregisterHook(Hook *hook);
+
+ void reset();
+
+ Hooks();
+ ~Hooks();
+ };
+
+ /**
+ * \class Collector
+ * \brief Base class for objects responsible for selecting result from which form the result polyhedron.
+ *
+ */
+ class Collector {
+ Collector(const Collector &);
+ Collector &operator=(const Collector &);
+
+ protected:
+
+ public:
+ virtual void collect(FaceLoopGroup *group, CSG::Hooks &) =0;
+ virtual meshset_t *done(CSG::Hooks &) =0;
+
+ Collector() {}
+ virtual ~Collector() {}
+ };
+
+ private:
+ typedef carve::geom::RTreeNode<3, carve::mesh::Face<3> *> face_rtree_t;
+ typedef std::unordered_map<carve::mesh::Face<3> *, std::vector<carve::mesh::Face<3> *> > face_pairs_t;
+
+ /// The computed intersection data.
+ Intersections intersections;
+
+ /// A map from intersection point to a set of intersections
+ /// represented by pairs of intersection objects.
+ VertexIntersections vertex_intersections;
+
+ /// A pool from which temporary vertices are allocated. Also
+ /// provides testing for pool membership.
+ VertexPool vertex_pool;
+
+ void init();
+
+ void makeVertexIntersections();
+
+ void groupIntersections();
+
+ void _generateVertexVertexIntersections(carve::mesh::MeshSet<3>::vertex_t *va,
+ carve::mesh::MeshSet<3>::edge_t *eb);
+ void generateVertexVertexIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b);
+
+ void _generateVertexEdgeIntersections(carve::mesh::MeshSet<3>::vertex_t *va,
+ carve::mesh::MeshSet<3>::edge_t *eb);
+ void generateVertexEdgeIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b);
+
+ void _generateEdgeEdgeIntersections(carve::mesh::MeshSet<3>::edge_t *ea,
+ carve::mesh::MeshSet<3>::edge_t *eb);
+ void generateEdgeEdgeIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b);
+
+ void _generateVertexFaceIntersections(carve::mesh::MeshSet<3>::face_t *fa,
+ carve::mesh::MeshSet<3>::edge_t *eb);
+ void generateVertexFaceIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b);
+
+ void _generateEdgeFaceIntersections(carve::mesh::MeshSet<3>::face_t *fa,
+ carve::mesh::MeshSet<3>::edge_t *eb);
+ void generateEdgeFaceIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b);
+
+ void generateIntersectionCandidates(carve::mesh::MeshSet<3> *a,
+ const face_rtree_t *a_node,
+ carve::mesh::MeshSet<3> *b,
+ const face_rtree_t *b_node,
+ face_pairs_t &face_pairs,
+ bool descend_a = true);
+ /**
+ * \brief Compute all points of intersection between poly \a a and poly \a b
+ *
+ * @param a Polyhedron a.
+ * @param b Polyhedron b.
+ */
+ void generateIntersections(meshset_t *a,
+ const face_rtree_t *a_node,
+ meshset_t *b,
+ const face_rtree_t *b_node,
+ detail::Data &data);
+
+ /**
+ * \brief Generate tables of intersecting pairs of faces.
+ *
+ * @param[out] data Internal data-structure holding intersection info.
+ */
+ void intersectingFacePairs(detail::Data &data);
+
+ /**
+ * \brief Divide edges in \a edges that are intersected by polyhedron \a poly
+ *
+ * @param edges The edges to divide.
+ * @param[in] poly The polyhedron to divide against.
+ * @param[in,out] data Intersection information.
+ */
+ void divideEdges(
+ const std::vector<meshset_t::edge_t> &edges,
+ meshset_t *poly,
+ detail::Data &data);
+
+ void divideIntersectedEdges(detail::Data &data);
+
+ /**
+ * \brief From the intersection points of pairs of intersecting faces, compute intersection edges.
+ *
+ * @param[out] eclass Classification information about created edges.
+ * @param[in,out] data Intersection information.
+ */
+ void makeFaceEdges(
+ EdgeClassification &eclass,
+ detail::Data &data);
+
+ friend void classifyEasyFaces(
+ FaceLoopList &face_loops,
+ VertexClassification &vclass,
+ meshset_t *other_poly,
+ int other_poly_num,
+ CSG &csg,
+ CSG::Collector &collector);
+
+ size_t generateFaceLoops(
+ meshset_t *poly,
+ const detail::Data &data,
+ FaceLoopList &face_loops_out);
+
+
+
+ // intersect_group.cpp
+
+ /**
+ * \brief Build a loop edge mapping from a list of face loops.
+ *
+ * @param[in] loops A list of face loops.
+ * @param[in] edge_count A hint as to the number of edges in \a loops.
+ * @param[out] edge_map The calculated map of edges to loops.
+ */
+ void makeEdgeMap(
+ const FaceLoopList &loops,
+ size_t edge_count,
+ detail::LoopEdges &edge_map);
+
+ /**
+ * \brief Divide a list of face loops into groups that are connected by at least one edge not present in \a no_cross.
+ *
+ * @param[in] src The source mesh from which these loops derive.
+ * @param[in,out] face_loops The list of loops (will be emptied as a side effect)
+ * @param[in] loop_edges A loop edge map used for traversing connected loops.
+ * @param[in] no_cross A set of edges not to cross.
+ * @param[out] out_loops A list of grouped face loops.
+ */
+ void groupFaceLoops(
+ carve::mesh::MeshSet<3> *src,
+ FaceLoopList &face_loops,
+ const detail::LoopEdges &loop_edges,
+ const V2Set &no_cross,
+ FLGroupList &out_loops);
+
+ /**
+ * \brief Find the set of edges shared between two edge maps.
+ *
+ * @param[in] edge_map_a The first edge map.
+ * @param[in] edge_map_b The second edge map.
+ * @param[out] shared_edges The resulting set of common edges.
+ */
+ void findSharedEdges(
+ const detail::LoopEdges &edge_map_a,
+ const detail::LoopEdges &edge_map_b,
+ V2Set &shared_edges);
+
+
+ // intersect_classify_edge.cpp
+
+ /**
+ *
+ *
+ * @param shared_edges
+ * @param vclass
+ * @param poly_a
+ * @param a_loops_grouped
+ * @param a_edge_map
+ * @param poly_b
+ * @param b_loops_grouped
+ * @param b_edge_map
+ * @param collector
+ */
+ void classifyFaceGroupsEdge(
+ const V2Set &shared_edges,
+ VertexClassification &vclass,
+ meshset_t *poly_a,
+ const face_rtree_t *poly_a_rtree,
+ FLGroupList &a_loops_grouped,
+ const detail::LoopEdges &a_edge_map,
+ meshset_t *poly_b,
+ const face_rtree_t *poly_b_rtree,
+ FLGroupList &b_loops_grouped,
+ const detail::LoopEdges &b_edge_map,
+ CSG::Collector &collector);
+
+ // intersect_classify_group.cpp
+
+ /**
+ *
+ *
+ * @param shared_edges
+ * @param vclass
+ * @param poly_a
+ * @param a_loops_grouped
+ * @param a_edge_map
+ * @param poly_b
+ * @param b_loops_grouped
+ * @param b_edge_map
+ * @param collector
+ */
+ void classifyFaceGroups(
+ const V2Set &shared_edges,
+ VertexClassification &vclass,
+ meshset_t *poly_a,
+ const face_rtree_t *poly_a_rtree,
+ FLGroupList &a_loops_grouped,
+ const detail::LoopEdges &a_edge_map,
+ meshset_t *poly_b,
+ const face_rtree_t *poly_b_rtree,
+ FLGroupList &b_loops_grouped,
+ const detail::LoopEdges &b_edge_map,
+ CSG::Collector &collector);
+
+ // intersect_half_classify_group.cpp
+
+ /**
+ *
+ *
+ * @param shared_edges
+ * @param vclass
+ * @param poly_a
+ * @param a_loops_grouped
+ * @param a_edge_map
+ * @param poly_b
+ * @param b_loops_grouped
+ * @param b_edge_map
+ * @param FaceClass
+ * @param b_out
+ */
+ void halfClassifyFaceGroups(
+ const V2Set &shared_edges,
+ VertexClassification &vclass,
+ meshset_t *poly_a,
+ const face_rtree_t *poly_a_rtree,
+ FLGroupList &a_loops_grouped,
+ const detail::LoopEdges &a_edge_map,
+ meshset_t *poly_b,
+ const face_rtree_t *poly_b_rtree,
+ FLGroupList &b_loops_grouped,
+ const detail::LoopEdges &b_edge_map,
+ std::list<std::pair<FaceClass, meshset_t *> > &b_out);
+
+ // intersect.cpp
+
+ /**
+ * \brief The main calculation method for CSG.
+ *
+ * @param[in] a Polyhedron a
+ * @param[in] b Polyhedron b
+ * @param[out] vclass
+ * @param[out] eclass
+ * @param[out] a_face_loops
+ * @param[out] b_face_loops
+ * @param[out] a_edge_count
+ * @param[out] b_edge_count
+ */
+ void calc(
+ meshset_t *a,
+ const face_rtree_t *a_rtree,
+ meshset_t *b,
+ const face_rtree_t *b_rtree,
+ VertexClassification &vclass,
+ EdgeClassification &eclass,
+ FaceLoopList &a_face_loops,
+ FaceLoopList &b_face_loops,
+ size_t &a_edge_count,
+ size_t &b_edge_count);
+
+ public:
+ /**
+ * \enum OP
+ * \brief Enumeration of the supported CSG operations.
+ */
+ enum OP {
+ UNION, /**< in a or b. */
+ INTERSECTION, /**< in a and b. */
+ A_MINUS_B, /**< in a, but not b. */
+ B_MINUS_A, /**< in b, but not a. */
+ SYMMETRIC_DIFFERENCE, /**< in a or b, but not both. */
+ ALL /**< all split faces from a and b */
+ };
+
+ /**
+ * \enum CLASSIFY_TYPE
+ * \brief The type of classification algorithm to use.
+ */
+ enum CLASSIFY_TYPE {
+ CLASSIFY_NORMAL, /**< Normal (group) classifier. */
+ CLASSIFY_EDGE /**< Edge classifier. */
+ };
+
+ CSG::Hooks hooks; /**< The manager for calculation hooks. */
+
+ CSG();
+ ~CSG();
+
+ /**
+ * \brief Compute a CSG operation between two polyhedra, \a a and \a b.
+ *
+ * @param a Polyhedron a
+ * @param b Polyhedron b
+ * @param collector The collector (determines the CSG operation performed)
+ * @param shared_edges A pointer to a set that will be populated with shared edges (if not NULL).
+ * @param classify_type The type of classifier to use.
+ *
+ * @return
+ */
+ meshset_t *compute(
+ meshset_t *a,
+ meshset_t *b,
+ CSG::Collector &collector,
+ V2Set *shared_edges = NULL,
+ CLASSIFY_TYPE classify_type = CLASSIFY_NORMAL);
+
+ /**
+ * \brief Compute a CSG operation between two closed polyhedra, \a a and \a b.
+ *
+ * @param a Polyhedron a
+ * @param b Polyhedron b
+ * @param op The CSG operation (A collector is created automatically).
+ * @param shared_edges A pointer to a set that will be populated with shared edges (if not NULL).
+ * @param classify_type The type of classifier to use.
+ *
+ * @return
+ */
+ meshset_t *compute(
+ meshset_t *a,
+ meshset_t *b,
+ OP op,
+ V2Set *shared_edges = NULL,
+ CLASSIFY_TYPE classify_type = CLASSIFY_NORMAL);
+
+ void slice(
+ meshset_t *a,
+ meshset_t *b,
+ std::list<meshset_t *> &a_sliced,
+ std::list<meshset_t *> &b_sliced,
+ V2Set *shared_edges = NULL);
+
+ bool sliceAndClassify(
+ meshset_t *closed,
+ meshset_t *open,
+ std::list<std::pair<FaceClass, meshset_t *> > &result,
+ V2Set *shared_edges = NULL);
+ };
+ }
+}
diff --git a/extern/carve/include/carve/csg_triangulator.hpp b/extern/carve/include/carve/csg_triangulator.hpp
new file mode 100644
index 00000000000..740585571bf
--- /dev/null
+++ b/extern/carve/include/carve/csg_triangulator.hpp
@@ -0,0 +1,434 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#include <carve/csg.hpp>
+#include <carve/tag.hpp>
+#include <carve/poly.hpp>
+#include <carve/triangulator.hpp>
+#include <deque>
+
+namespace carve {
+ namespace csg {
+
+ namespace detail {
+ template<bool with_improvement>
+ class CarveTriangulator : public csg::CSG::Hook {
+
+ public:
+ CarveTriangulator() {
+ }
+
+ virtual ~CarveTriangulator() {
+ }
+
+ virtual void processOutputFace(std::vector<carve::mesh::MeshSet<3>::face_t *> &faces,
+ const carve::mesh::MeshSet<3>::face_t *orig,
+ bool flipped) {
+ std::vector<carve::mesh::MeshSet<3>::face_t *> out_faces;
+
+ size_t n_tris = 0;
+ for (size_t f = 0; f < faces.size(); ++f) {
+ CARVE_ASSERT(faces[f]->nVertices() >= 3);
+ n_tris += faces[f]->nVertices() - 2;
+ }
+
+ out_faces.reserve(n_tris);
+
+ for (size_t f = 0; f < faces.size(); ++f) {
+ carve::mesh::MeshSet<3>::face_t *face = faces[f];
+
+ if (face->nVertices() == 3) {
+ out_faces.push_back(face);
+ continue;
+ }
+
+ std::vector<triangulate::tri_idx> result;
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> vloop;
+ face->getVertices(vloop);
+
+ triangulate::triangulate(
+ carve::mesh::MeshSet<3>::face_t::projection_mapping(face->project),
+ vloop,
+ result);
+
+ if (with_improvement) {
+ triangulate::improve(
+ carve::mesh::MeshSet<3>::face_t::projection_mapping(face->project),
+ vloop,
+ carve::mesh::vertex_distance(),
+ result);
+ }
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> fv;
+ fv.resize(3);
+ for (size_t i = 0; i < result.size(); ++i) {
+ fv[0] = vloop[result[i].a];
+ fv[1] = vloop[result[i].b];
+ fv[2] = vloop[result[i].c];
+ out_faces.push_back(face->create(fv.begin(), fv.end(), false));
+ }
+ delete face;
+ }
+ std::swap(faces, out_faces);
+ }
+ };
+ }
+
+ typedef detail::CarveTriangulator<false> CarveTriangulator;
+ typedef detail::CarveTriangulator<true> CarveTriangulatorWithImprovement;
+
+ class CarveTriangulationImprover : public csg::CSG::Hook {
+ public:
+ CarveTriangulationImprover() {
+ }
+
+ virtual ~CarveTriangulationImprover() {
+ }
+
+ virtual void processOutputFace(std::vector<carve::mesh::MeshSet<3>::face_t *> &faces,
+ const carve::mesh::MeshSet<3>::face_t *orig,
+ bool flipped) {
+ if (faces.size() == 1) return;
+
+ // doing improvement as a separate hook is much messier than
+ // just incorporating it into the triangulation hook.
+
+ typedef std::map<carve::mesh::MeshSet<3>::vertex_t *, size_t> vert_map_t;
+ std::vector<carve::mesh::MeshSet<3>::face_t *> out_faces;
+ vert_map_t vert_map;
+
+ out_faces.reserve(faces.size());
+
+
+ carve::mesh::MeshSet<3>::face_t::projection_mapping projector(faces[0]->project);
+
+ std::vector<triangulate::tri_idx> result;
+
+ for (size_t f = 0; f < faces.size(); ++f) {
+ carve::mesh::MeshSet<3>::face_t *face = faces[f];
+ if (face->nVertices() != 3) {
+ out_faces.push_back(face);
+ } else {
+ triangulate::tri_idx tri;
+ for (carve::mesh::MeshSet<3>::face_t::edge_iter_t i = face->begin(); i != face->end(); ++i) {
+ size_t v = 0;
+ vert_map_t::iterator j = vert_map.find(i->vert);
+ if (j == vert_map.end()) {
+ v = vert_map.size();
+ vert_map[i->vert] = v;
+ } else {
+ v = (*j).second;
+ }
+ tri.v[i.idx()] = v;
+ }
+ result.push_back(tri);
+ delete face;
+ }
+ }
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> verts;
+ verts.resize(vert_map.size());
+ for (vert_map_t::iterator i = vert_map.begin(); i != vert_map.end(); ++i) {
+ verts[(*i).second] = (*i).first;
+ }
+
+ triangulate::improve(projector, verts, carve::mesh::vertex_distance(), result);
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> fv;
+ fv.resize(3);
+ for (size_t i = 0; i < result.size(); ++i) {
+ fv[0] = verts[result[i].a];
+ fv[1] = verts[result[i].b];
+ fv[2] = verts[result[i].c];
+ out_faces.push_back(orig->create(fv.begin(), fv.end(), false));
+ }
+
+ std::swap(faces, out_faces);
+ }
+ };
+
+ class CarveTriangulationQuadMerger : public csg::CSG::Hook {
+ // this code is incomplete.
+ typedef std::map<V2, F2> edge_map_t;
+
+ public:
+ CarveTriangulationQuadMerger() {
+ }
+
+ virtual ~CarveTriangulationQuadMerger() {
+ }
+
+ double scoreQuad(edge_map_t::iterator i, edge_map_t &edge_map) {
+ if (!(*i).second.first || !(*i).second.second) return -1;
+ return 0;
+ }
+
+ carve::mesh::MeshSet<3>::face_t *mergeQuad(edge_map_t::iterator i, edge_map_t &edge_map) {
+ return NULL;
+ }
+
+ void recordEdge(carve::mesh::MeshSet<3>::vertex_t *v1,
+ carve::mesh::MeshSet<3>::vertex_t *v2,
+ carve::mesh::MeshSet<3>::face_t *f,
+ edge_map_t &edge_map) {
+ if (v1 < v2) {
+ edge_map[V2(v1, v2)].first = f;
+ } else {
+ edge_map[V2(v2, v1)].second = f;
+ }
+ }
+
+ virtual void processOutputFace(std::vector<carve::mesh::MeshSet<3>::face_t *> &faces,
+ const carve::mesh::MeshSet<3>::face_t *orig,
+ bool flipped) {
+ if (faces.size() == 1) return;
+
+ std::vector<carve::mesh::MeshSet<3>::face_t *> out_faces;
+ edge_map_t edge_map;
+
+ out_faces.reserve(faces.size());
+
+ poly::p2_adapt_project<3> projector(faces[0]->project);
+
+ for (size_t f = 0; f < faces.size(); ++f) {
+ carve::mesh::MeshSet<3>::face_t *face = faces[f];
+ if (face->nVertices() != 3) {
+ out_faces.push_back(face);
+ } else {
+ carve::mesh::MeshSet<3>::face_t::vertex_t *v1, *v2, *v3;
+ v1 = face->edge->vert;
+ v2 = face->edge->next->vert;
+ v3 = face->edge->next->next->vert;
+ recordEdge(v1, v2, face, edge_map);
+ recordEdge(v2, v3, face, edge_map);
+ recordEdge(v3, v1, face, edge_map);
+ }
+ }
+
+ for (edge_map_t::iterator i = edge_map.begin(); i != edge_map.end();) {
+ if ((*i).second.first && (*i).second.second) {
+ ++i;
+ } else {
+ edge_map.erase(i++);
+ }
+ }
+
+ while (edge_map.size()) {
+ edge_map_t::iterator i = edge_map.begin();
+ edge_map_t::iterator best = i;
+ double best_score = scoreQuad(i, edge_map);
+ for (++i; i != edge_map.end(); ++i) {
+ double score = scoreQuad(i, edge_map);
+ if (score > best_score) best = i;
+ }
+ if (best_score < 0) break;
+ out_faces.push_back(mergeQuad(best, edge_map));
+ }
+
+ if (edge_map.size()) {
+ tagable::tag_begin();
+ for (edge_map_t::iterator i = edge_map.begin(); i != edge_map.end(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *a = const_cast<carve::mesh::MeshSet<3>::face_t *>((*i).second.first);
+ carve::mesh::MeshSet<3>::face_t *b = const_cast<carve::mesh::MeshSet<3>::face_t *>((*i).second.first);
+ if (a && a->tag_once()) out_faces.push_back(a);
+ if (b && b->tag_once()) out_faces.push_back(b);
+ }
+ }
+
+ std::swap(faces, out_faces);
+ }
+ };
+
+ class CarveHoleResolver : public csg::CSG::Hook {
+
+ public:
+ CarveHoleResolver() {
+ }
+
+ virtual ~CarveHoleResolver() {
+ }
+
+ bool findRepeatedEdges(const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ std::list<std::pair<size_t, size_t> > &edge_pos) {
+ std::map<V2, size_t> edges;
+ for (size_t i = 0; i < vertices.size() - 1; ++i) {
+ edges[std::make_pair(vertices[i], vertices[i+1])] = i;
+ }
+ edges[std::make_pair(vertices[vertices.size()-1], vertices[0])] = vertices.size() - 1;
+
+ for (std::map<V2, size_t>::iterator i = edges.begin(); i != edges.end(); ++i) {
+ V2 rev = V2((*i).first.second, (*i).first.first);
+ std::map<V2, size_t>::iterator j = edges.find(rev);
+ if (j != edges.end()) {
+ edge_pos.push_back(std::make_pair((*i).second, (*j).second));
+ }
+ }
+ return edge_pos.size() > 0;
+ }
+
+ void flood(size_t t1,
+ size_t t2,
+ size_t old_grp,
+ size_t new_grp_1,
+ size_t new_grp_2,
+ std::vector<size_t> &grp,
+ const std::vector<triangulate::tri_idx> &tris,
+ const std::map<std::pair<size_t, size_t>, size_t> &tri_edge) {
+ grp[t1] = new_grp_1;
+ grp[t2] = new_grp_2;
+
+ std::deque<size_t> to_visit;
+ to_visit.push_back(t1);
+ to_visit.push_back(t2);
+ std::vector<std::pair<size_t, size_t> > rev;
+ rev.resize(3);
+ while (to_visit.size()) {
+ size_t curr = to_visit.front();
+ to_visit.pop_front();
+ triangulate::tri_idx ct = tris[curr];
+ rev[0] = std::make_pair(ct.b, ct.a);
+ rev[1] = std::make_pair(ct.c, ct.b);
+ rev[2] = std::make_pair(ct.a, ct.c);
+
+ for (size_t i = 0; i < 3; ++i) {
+ std::map<std::pair<size_t, size_t>, size_t>::const_iterator adj = tri_edge.find(rev[i]);
+ if (adj == tri_edge.end()) continue;
+ size_t next = (*adj).second;
+ if (grp[next] != old_grp) continue;
+ grp[next] = grp[curr];
+ to_visit.push_back(next);
+ }
+ }
+ }
+
+ void findPerimeter(const std::vector<triangulate::tri_idx> &tris,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &verts,
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &out) {
+ std::map<std::pair<size_t, size_t>, size_t> edges;
+ for (size_t i = 0; i < tris.size(); ++i) {
+ edges[std::make_pair(tris[i].a, tris[i].b)] = i;
+ edges[std::make_pair(tris[i].b, tris[i].c)] = i;
+ edges[std::make_pair(tris[i].c, tris[i].a)] = i;
+ }
+ std::map<size_t, size_t> unpaired;
+ for (std::map<std::pair<size_t, size_t>, size_t>::iterator i = edges.begin(); i != edges.end(); ++i) {
+ if (edges.find(std::make_pair((*i).first.second, (*i).first.first)) == edges.end()) {
+ CARVE_ASSERT(unpaired.find((*i).first.first) == unpaired.end());
+ unpaired[(*i).first.first] = (*i).first.second;
+ }
+ }
+ out.clear();
+ out.reserve(unpaired.size());
+ size_t start = (*unpaired.begin()).first;
+ size_t vert = start;
+ do {
+ out.push_back(verts[vert]);
+ CARVE_ASSERT(unpaired.find(vert) != unpaired.end());
+ vert = unpaired[vert];
+ } while (vert != start);
+ }
+
+ virtual void processOutputFace(std::vector<carve::mesh::MeshSet<3>::face_t *> &faces,
+ const carve::mesh::MeshSet<3>::face_t *orig,
+ bool flipped) {
+ std::vector<carve::mesh::MeshSet<3>::face_t *> out_faces;
+
+ for (size_t f = 0; f < faces.size(); ++f) {
+ carve::mesh::MeshSet<3>::face_t *face = faces[f];
+
+ if (face->nVertices() == 3) {
+ out_faces.push_back(face);
+ continue;
+ }
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> vloop;
+ face->getVertices(vloop);
+
+ std::list<std::pair<size_t, size_t> > rep_edges;
+ if (!findRepeatedEdges(vloop, rep_edges)) {
+ out_faces.push_back(face);
+ continue;
+ }
+
+ std::vector<triangulate::tri_idx> result;
+ triangulate::triangulate(
+ carve::mesh::MeshSet<3>::face_t::projection_mapping(face->project),
+ vloop,
+ result);
+
+ std::map<std::pair<size_t, size_t>, size_t> tri_edge;
+ for (size_t i = 0; i < result.size(); ++i) {
+ tri_edge[std::make_pair(result[i].a, result[i].b)] = i;
+ tri_edge[std::make_pair(result[i].b, result[i].c)] = i;
+ tri_edge[std::make_pair(result[i].c, result[i].a)] = i;
+ }
+
+ std::vector<size_t> grp;
+ grp.resize(result.size(), 0);
+
+ size_t grp_max = 0;
+
+ while (rep_edges.size()) {
+ std::pair<size_t, size_t> e1, e2;
+
+ e1.first = rep_edges.front().first;
+ e1.second = (e1.first + 1) % vloop.size();
+
+ e2.first = rep_edges.front().second;
+ e2.second = (e2.first + 1) % vloop.size();
+
+ rep_edges.pop_front();
+
+ CARVE_ASSERT(tri_edge.find(e1) != tri_edge.end());
+ size_t t1 = tri_edge[e1];
+ CARVE_ASSERT(tri_edge.find(e2) != tri_edge.end());
+ size_t t2 = tri_edge[e2];
+
+ if (grp[t1] != grp[t2]) {
+ continue;
+ }
+
+ size_t t1g = ++grp_max;
+ size_t t2g = ++grp_max;
+
+ flood(t1, t2, grp[t1], t1g, t2g, grp, result, tri_edge);
+ }
+
+ std::set<size_t> groups;
+ std::copy(grp.begin(), grp.end(), std::inserter(groups, groups.begin()));
+
+ // now construct perimeters for each group.
+ std::vector<triangulate::tri_idx> grp_tris;
+ grp_tris.reserve(result.size());
+ for (std::set<size_t>::iterator i = groups.begin(); i != groups.end(); ++i) {
+ size_t grp_id = *i;
+ grp_tris.clear();
+ for (size_t j = 0; j < grp.size(); ++j) {
+ if (grp[j] == grp_id) {
+ grp_tris.push_back(result[j]);
+ }
+ }
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> grp_perim;
+ findPerimeter(grp_tris, vloop, grp_perim);
+ out_faces.push_back(face->create(grp_perim.begin(), grp_perim.end(), false));
+ }
+ }
+ std::swap(faces, out_faces);
+ }
+ };
+ }
+}
diff --git a/extern/carve/include/carve/debug_hooks.hpp b/extern/carve/include/carve/debug_hooks.hpp
new file mode 100644
index 00000000000..9ef7fc83573
--- /dev/null
+++ b/extern/carve/include/carve/debug_hooks.hpp
@@ -0,0 +1,97 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/vector.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/csg.hpp>
+
+#include <iomanip>
+
+template<typename MAP>
+void map_histogram(std::ostream &out, const MAP &map) {
+ std::vector<int> hist;
+ for (typename MAP::const_iterator i = map.begin(); i != map.end(); ++i) {
+ size_t n = (*i).second.size();
+ if (hist.size() <= n) {
+ hist.resize(n + 1);
+ }
+ hist[n]++;
+ }
+ int total = map.size();
+ std::string bar(50, '*');
+ for (size_t i = 0; i < hist.size(); i++) {
+ if (hist[i] > 0) {
+ out << std::setw(5) << i << " : " << std::setw(5) << hist[i] << " " << bar.substr(50 - hist[i] * 50 / total) << std::endl;
+ }
+ }
+}
+
+namespace carve {
+ namespace csg {
+ class IntersectDebugHooks {
+ public:
+ virtual void drawIntersections(const VertexIntersections & /* vint */) {
+ }
+
+ virtual void drawPoint(const carve::mesh::MeshSet<3>::vertex_t * /* v */,
+ float /* r */,
+ float /* g */,
+ float /* b */,
+ float /* a */,
+ float /* rad */) {
+ }
+ virtual void drawEdge(const carve::mesh::MeshSet<3>::vertex_t * /* v1 */,
+ const carve::mesh::MeshSet<3>::vertex_t * /* v2 */,
+ float /* rA */, float /* gA */, float /* bA */, float /* aA */,
+ float /* rB */, float /* gB */, float /* bB */, float /* aB */,
+ float /* thickness */ = 1.0) {
+ }
+
+ virtual void drawFaceLoopWireframe(const std::vector<carve::mesh::MeshSet<3>::vertex_t *> & /* face_loop */,
+ const carve::mesh::MeshSet<3>::vertex_t & /* normal */,
+ float /* r */, float /* g */, float /* b */, float /* a */,
+ bool /* inset */ = true) {
+ }
+
+ virtual void drawFaceLoop(const std::vector<carve::mesh::MeshSet<3>::vertex_t *> & /* face_loop */,
+ const carve::mesh::MeshSet<3>::vertex_t & /* normal */,
+ float /* r */, float /* g */, float /* b */, float /* a */,
+ bool /* offset */ = true,
+ bool /* lit */ = true) {
+ }
+
+ virtual void drawFaceLoop2(const std::vector<carve::mesh::MeshSet<3>::vertex_t *> & /* face_loop */,
+ const carve::mesh::MeshSet<3>::vertex_t & /* normal */,
+ float /* rF */, float /* gF */, float /* bF */, float /* aF */,
+ float /* rB */, float /* gB */, float /* bB */, float /* aB */,
+ bool /* offset */ = true,
+ bool /* lit */ = true) {
+ }
+
+ virtual ~IntersectDebugHooks() {
+ }
+ };
+
+ IntersectDebugHooks *intersect_installDebugHooks(IntersectDebugHooks *hooks);
+ bool intersect_debugEnabled();
+
+ }
+}
diff --git a/extern/carve/include/carve/djset.hpp b/extern/carve/include/carve/djset.hpp
new file mode 100644
index 00000000000..542858d59f4
--- /dev/null
+++ b/extern/carve/include/carve/djset.hpp
@@ -0,0 +1,134 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <vector>
+
+
+
+namespace carve {
+namespace djset {
+
+
+
+ class djset {
+
+ protected:
+ struct elem {
+ size_t parent, rank;
+ elem(size_t p, size_t r) : parent(p), rank(r) {}
+ elem() {}
+ };
+
+ std::vector<elem> set;
+ size_t n_sets;
+
+ public:
+ djset() : set(), n_sets(0) {
+ }
+
+ djset(size_t N) {
+ n_sets = N;
+ set.reserve(N);
+ for (size_t i = 0; i < N; ++i) {
+ set.push_back(elem(i,0));
+ }
+ }
+
+ void init(size_t N) {
+ if (N == set.size()) {
+ for (size_t i = 0; i < N; ++i) {
+ set[i] = elem(i,0);
+ }
+ n_sets = N;
+ } else {
+ djset temp(N);
+ std::swap(set, temp.set);
+ std::swap(n_sets, temp.n_sets);
+ }
+ }
+
+ size_t count() const {
+ return n_sets;
+ }
+
+ size_t find_set_head(size_t a) {
+ if (a == set[a].parent) return a;
+
+ size_t a_head = a;
+ while (set[a_head].parent != a_head) a_head = set[a_head].parent;
+ set[a].parent = a_head;
+ return a_head;
+ }
+
+ bool same_set(size_t a, size_t b) {
+ return find_set_head(a) == find_set_head(b);
+ }
+
+ void merge_sets(size_t a, size_t b) {
+ a = find_set_head(a);
+ b = find_set_head(b);
+ if (a != b) {
+ n_sets--;
+ if (set[a].rank < set[b].rank) {
+ set[a].parent = b;
+ } else if (set[b].rank < set[a].rank) {
+ set[b].parent = a;
+ } else {
+ set[a].rank++;
+ set[b].parent = a;
+ }
+ }
+ }
+
+ void get_index_to_set(std::vector<size_t> &index_set, std::vector<size_t> &set_size) {
+ index_set.clear();
+ index_set.resize(set.size(), n_sets);
+ set_size.clear();
+ set_size.resize(n_sets, 0);
+
+ size_t c = 0;
+ for (size_t i = 0; i < set.size(); ++i) {
+ size_t s = find_set_head(i);
+ if (index_set[s] == n_sets) index_set[s] = c++;
+ index_set[i] = index_set[s];
+ set_size[index_set[s]]++;
+ }
+ }
+
+ template<typename in_iter_t, typename out_collection_t>
+ void collate(in_iter_t in, out_collection_t &out) {
+ std::vector<size_t> set_id(set.size(), n_sets);
+ out.clear();
+ out.resize(n_sets);
+ size_t c = 0;
+ for (size_t i = 0; i < set.size(); ++i) {
+ size_t s = find_set_head(i);
+ if (set_id[s] == n_sets) set_id[s] = c++;
+ s = set_id[s];
+ std::insert_iterator<typename out_collection_t::value_type> j(out[s], out[s].end());
+ *j = *in++;
+ }
+ }
+ };
+
+
+
+}
+}
diff --git a/extern/carve/include/carve/edge_decl.hpp b/extern/carve/include/carve/edge_decl.hpp
new file mode 100644
index 00000000000..cafef5de7b1
--- /dev/null
+++ b/extern/carve/include/carve/edge_decl.hpp
@@ -0,0 +1,68 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/vector.hpp>
+#include <carve/tag.hpp>
+
+#include <vector>
+#include <list>
+
+namespace carve {
+ namespace poly {
+
+
+
+ struct Object;
+
+
+
+ template<unsigned ndim>
+ class Edge : public tagable {
+ public:
+ typedef Vertex<ndim> vertex_t;
+ typedef typename Vertex<ndim>::vector_t vector_t;
+ typedef Object obj_t;
+
+ const vertex_t *v1, *v2;
+ const obj_t *owner;
+
+ Edge(const vertex_t *_v1, const vertex_t *_v2, const obj_t *_owner) :
+ tagable(), v1(_v1), v2(_v2), owner(_owner) {
+ }
+
+ ~Edge() {
+ }
+ };
+
+
+
+ struct hash_edge_ptr {
+ template<unsigned ndim>
+ size_t operator()(const Edge<ndim> * const &e) const {
+ return (size_t)e;
+ }
+ };
+
+
+
+ }
+}
+
diff --git a/extern/carve/include/carve/edge_impl.hpp b/extern/carve/include/carve/edge_impl.hpp
new file mode 100644
index 00000000000..504972c7de0
--- /dev/null
+++ b/extern/carve/include/carve/edge_impl.hpp
@@ -0,0 +1,23 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+namespace carve {
+ namespace poly {
+ }
+}
diff --git a/extern/carve/include/carve/exact.hpp b/extern/carve/include/carve/exact.hpp
new file mode 100644
index 00000000000..afb491211fd
--- /dev/null
+++ b/extern/carve/include/carve/exact.hpp
@@ -0,0 +1,702 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <vector>
+#include <numeric>
+#include <algorithm>
+
+
+namespace carve {
+ namespace exact {
+
+ class exact_t : public std::vector<double> {
+ typedef std::vector<double> super;
+
+ public:
+ exact_t() : super() {
+ }
+
+ exact_t(double v, size_t sz = 1) : super(sz, v) {
+ }
+
+ template<typename iter_t>
+ exact_t(iter_t a, iter_t b) : super(a, b) {
+ }
+
+ exact_t(double a, double b) : super() {
+ reserve(2);
+ push_back(a);
+ push_back(b);
+ }
+
+ exact_t(double a, double b, double c) : super() {
+ reserve(3);
+ push_back(a);
+ push_back(b);
+ push_back(c);
+ }
+
+ exact_t(double a, double b, double c, double d) : super() {
+ reserve(4);
+ push_back(a);
+ push_back(b);
+ push_back(c);
+ push_back(d);
+ }
+
+ exact_t(double a, double b, double c, double d, double e) : super() {
+ reserve(5);
+ push_back(a);
+ push_back(b);
+ push_back(c);
+ push_back(d);
+ push_back(e);
+ }
+
+ exact_t(double a, double b, double c, double d, double e, double f) : super() {
+ reserve(6);
+ push_back(a);
+ push_back(b);
+ push_back(c);
+ push_back(d);
+ push_back(e);
+ push_back(f);
+ }
+
+ exact_t(double a, double b, double c, double d, double e, double f, double g) : super() {
+ reserve(7);
+ push_back(a);
+ push_back(b);
+ push_back(c);
+ push_back(d);
+ push_back(e);
+ push_back(f);
+ push_back(g);
+ }
+
+ exact_t(double a, double b, double c, double d, double e, double f, double g, double h) : super() {
+ reserve(8);
+ push_back(a);
+ push_back(b);
+ push_back(c);
+ push_back(d);
+ push_back(e);
+ push_back(f);
+ push_back(g);
+ push_back(h);
+ }
+
+ void compress();
+
+ exact_t compressed() const {
+ exact_t result(*this);
+ result.compress();
+ return result;
+ }
+
+ operator double() const {
+ return std::accumulate(begin(), end(), 0.0);
+ }
+
+ void removeZeroes() {
+ erase(std::remove(begin(), end(), 0.0), end());
+ }
+ };
+
+ inline std::ostream &operator<<(std::ostream &out, const exact_t &p) {
+ out << '{';
+ out << p[0];
+ for (size_t i = 1; i < p.size(); ++i) out << ';' << p[i];
+ out << '}';
+ return out;
+ }
+
+
+
+ namespace detail {
+ const struct constants_t {
+ double splitter; /* = 2^ceiling(p / 2) + 1. Used to split floats in half. */
+ double epsilon; /* = 2^(-p). Used to estimate roundoff errors. */
+ /* A set of coefficients used to calculate maximum roundoff errors. */
+ double resulterrbound;
+ double ccwerrboundA, ccwerrboundB, ccwerrboundC;
+ double o3derrboundA, o3derrboundB, o3derrboundC;
+ double iccerrboundA, iccerrboundB, iccerrboundC;
+ double isperrboundA, isperrboundB, isperrboundC;
+
+ constants_t() {
+ double half;
+ double check, lastcheck;
+ int every_other;
+
+ every_other = 1;
+ half = 0.5;
+ epsilon = 1.0;
+ splitter = 1.0;
+ check = 1.0;
+ /* Repeatedly divide `epsilon' by two until it is too small to add to */
+ /* one without causing roundoff. (Also check if the sum is equal to */
+ /* the previous sum, for machines that round up instead of using exact */
+ /* rounding. Not that this library will work on such machines anyway. */
+ do {
+ lastcheck = check;
+ epsilon *= half;
+ if (every_other) {
+ splitter *= 2.0;
+ }
+ every_other = !every_other;
+ check = 1.0 + epsilon;
+ } while ((check != 1.0) && (check != lastcheck));
+ splitter += 1.0;
+
+ /* Error bounds for orientation and incircle tests. */
+ resulterrbound = (3.0 + 8.0 * epsilon) * epsilon;
+ ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon;
+ ccwerrboundB = (2.0 + 12.0 * epsilon) * epsilon;
+ ccwerrboundC = (9.0 + 64.0 * epsilon) * epsilon * epsilon;
+ o3derrboundA = (7.0 + 56.0 * epsilon) * epsilon;
+ o3derrboundB = (3.0 + 28.0 * epsilon) * epsilon;
+ o3derrboundC = (26.0 + 288.0 * epsilon) * epsilon * epsilon;
+ iccerrboundA = (10.0 + 96.0 * epsilon) * epsilon;
+ iccerrboundB = (4.0 + 48.0 * epsilon) * epsilon;
+ iccerrboundC = (44.0 + 576.0 * epsilon) * epsilon * epsilon;
+ isperrboundA = (16.0 + 224.0 * epsilon) * epsilon;
+ isperrboundB = (5.0 + 72.0 * epsilon) * epsilon;
+ isperrboundC = (71.0 + 1408.0 * epsilon) * epsilon * epsilon;
+ }
+ } constants;
+
+ template<unsigned U, unsigned V>
+ struct op {
+ enum {
+ Vlo = V / 2,
+ Vhi = V - Vlo
+ };
+
+ static inline void add(const double *a, const double *b, double *r) {
+ double t[U + Vlo];
+ op<U, Vlo>::add(a, b, t);
+ for (size_t i = 0; i < Vlo; ++i) r[i] = t[i];
+ op<U, Vhi>::add(t + Vlo, b + Vlo, r + Vlo);
+ }
+
+ static inline void sub(const double *a, const double *b, double *r) {
+ double t[U + Vlo];
+ op<U, Vlo>::sub(a, b, t);
+ for (size_t i = 0; i < Vlo; ++i) r[i] = t[i];
+ op<U, Vhi>::sub(t + Vlo, b + Vlo, r + Vlo);
+ }
+ };
+
+ template<unsigned U>
+ struct op<U, 1> {
+ enum {
+ Ulo = U / 2,
+ Uhi = U - Ulo
+ };
+ static void add(const double *a, const double *b, double *r) {
+ double t[Ulo + 1];
+ op<Ulo, 1>::add(a, b, t);
+ for (size_t i = 0; i < Ulo; ++i) r[i] = t[i];
+ op<Uhi, 1>::add(a + Ulo, t + Ulo, r + Ulo);
+ }
+
+ static void sub(const double *a, const double *b, double *r) {
+ double t[Ulo + 1];
+ op<Ulo, 1>::sub(a, b, t);
+ for (size_t i = 0; i < Ulo; ++i) r[i] = t[i];
+ op<Uhi, 1>::add(a + Ulo, t + Ulo, r + Ulo);
+ }
+ };
+
+ template<>
+ struct op<1, 1> {
+ static void add_fast(const double *a, const double *b, double *r) {
+ assert(fabs(a[0]) >= fabs(b[0]));
+ volatile double sum = a[0] + b[0];
+ volatile double bvirt = sum - a[0];
+ r[0] = b[0] - bvirt;
+ r[1] = sum;
+ }
+
+ static void sub_fast(const double *a, const double *b, double *r) {
+ assert(fabs(a[0]) >= fabs(b[0]));
+ volatile double diff = a[0] - b[0];
+ volatile double bvirt = a[0] - diff;
+ r[0] = bvirt - b[0];
+ r[1] = diff;
+ }
+
+ static void add(const double *a, const double *b, double *r) {
+ volatile double sum = a[0] + b[0];
+ volatile double bvirt = sum - a[0];
+ double avirt = sum - bvirt;
+ double bround = b[0] - bvirt;
+ double around = a[0] - avirt;
+ r[0] = around + bround;
+ r[1] = sum;
+ }
+
+ static void sub(const double *a, const double *b, double *r) {
+ volatile double diff = a[0] - b[0];
+ volatile double bvirt = a[0] - diff;
+ double avirt = diff + bvirt;
+ double bround = bvirt - b[0];
+ double around = a[0] - avirt;
+ r[0] = around + bround;
+ r[1] = diff;
+ }
+ };
+
+
+ template<unsigned U, unsigned V>
+ static exact_t add(const double *a, const double *b) {
+ exact_t result;
+ result.resize(U + V);
+ op<U,V>::add(a, b, &result[0]);
+ return result;
+ }
+
+
+ template<unsigned U, unsigned V>
+ static exact_t sub(const double *a, const double *b) {
+ exact_t result;
+ result.resize(U + V);
+ op<U,V>::sub(a, b, &result[0]);
+ return result;
+ }
+
+
+ template<unsigned U, unsigned V>
+ static exact_t add(const exact_t &a, const exact_t &b) {
+ assert(a.size() == U);
+ assert(b.size() == V);
+ exact_t result;
+ result.resize(U + V);
+ std::fill(result.begin(), result.end(), std::numeric_limits<double>::quiet_NaN());
+ op<U,V>::add(&a[0], &b[0], &result[0]);
+ return result;
+ }
+
+
+ template<unsigned U, unsigned V>
+ static exact_t add(const exact_t &a, const double *b) {
+ assert(a.size() == U);
+ exact_t result;
+ result.resize(U + V);
+ std::fill(result.begin(), result.end(), std::numeric_limits<double>::quiet_NaN());
+ op<U,V>::add(&a[0], b, &result[0]);
+ return result;
+ }
+
+
+ template<unsigned U, unsigned V>
+ static exact_t sub(const exact_t &a, const exact_t &b) {
+ assert(a.size() == U);
+ assert(b.size() == V);
+ exact_t result;
+ result.resize(U + V);
+ std::fill(result.begin(), result.end(), std::numeric_limits<double>::quiet_NaN());
+ op<U,V>::sub(&a[0], &b[0], &result[0]);
+ return result;
+ }
+
+
+ template<unsigned U, unsigned V>
+ static exact_t sub(const exact_t &a, const double *b) {
+ assert(a.size() == U);
+ exact_t result;
+ result.resize(U + V);
+ std::fill(result.begin(), result.end(), std::numeric_limits<double>::quiet_NaN());
+ op<U,V>::sub(&a[0], &b[0], &result[0]);
+ return result;
+ }
+
+
+ static inline void split(const double a, double *r) {
+ volatile double c = constants.splitter * a;
+ volatile double abig = c - a;
+ r[1] = c - abig;
+ r[0] = a - r[1];
+ }
+
+ static inline void prod_1_1(const double *a, const double *b, double *r) {
+ r[1] = a[0] * b[0];
+ double a_sp[2]; split(a[0], a_sp);
+ double b_sp[2]; split(b[0], b_sp);
+ double err1 = r[1] - a_sp[1] * b_sp[1];
+ double err2 = err1 - a_sp[0] * b_sp[1];
+ double err3 = err2 - a_sp[1] * b_sp[0];
+ r[0] = a_sp[0] * b_sp[0] - err3;
+ }
+
+ static inline void prod_1_1s(const double *a, const double *b, const double *b_sp, double *r) {
+ r[1] = a[0] * b[0];
+ double a_sp[2]; split(a[0], a_sp);
+ double err1 = r[1] - a_sp[1] * b_sp[1];
+ double err2 = err1 - a_sp[0] * b_sp[1];
+ double err3 = err2 - a_sp[1] * b_sp[0];
+ r[0] = a_sp[0] * b_sp[0] - err3;
+ }
+
+ static inline void prod_1s_1s(const double *a, const double *a_sp, const double *b, const double *b_sp, double *r) {
+ r[1] = a[0] * b[0];
+ double err1 = r[1] - a_sp[1] * b_sp[1];
+ double err2 = err1 - a_sp[0] * b_sp[1];
+ double err3 = err2 - a_sp[1] * b_sp[0];
+ r[0] = a_sp[0] * b_sp[0] - err3;
+ }
+
+ static inline void prod_2_1(const double *a, const double *b, double *r) {
+ double b_sp[2]; split(b[0], b_sp);
+ double t1[2]; prod_1_1s(a+0, b, b_sp, t1);
+ r[0] = t1[0];
+ double t2[2]; prod_1_1s(a+1, b, b_sp, t2);
+ double t3[2]; op<1,1>::add(t1+1, t2, t3);
+ r[1] = t3[0];
+ double t4[2]; op<1,1>::add_fast(t2+1, t3+1, r + 2);
+ }
+
+ static inline void prod_1_2(const double *a, const double *b, double *r) {
+ prod_2_1(b, a, r);
+ }
+
+ static inline void prod_4_1(const double *a, const double *b, double *r) {
+ double b_sp[2]; split(b[0], b_sp);
+ double t1[2]; prod_1_1s(a+0, b, b_sp, t1);
+ r[0] = t1[0];
+ double t2[2]; prod_1_1s(a+1, b, b_sp, t2);
+ double t3[2]; op<1,1>::add(t1+1, t2, t3);
+ r[1] = t3[0];
+ double t4[2]; op<1,1>::add_fast(t2+1, t3+1, t4);
+ r[2] = t4[0];
+ double t5[2]; prod_1_1s(a+2, b, b_sp, t5);
+ double t6[2]; op<1,1>::add(t4+1, t5, t6);
+ r[3] = t6[0];
+ double t7[2]; op<1,1>::add_fast(t5+1, t6+1, t7);
+ r[4] = t7[0];
+ double t8[2]; prod_1_1s(a+3, b, b_sp, t8);
+ double t9[2]; op<1,1>::add(t7+1, t8, t9);
+ r[5] = t9[0];
+ op<1,1>::add_fast(t8+1, t9+1, r + 6);
+ }
+
+ static inline void prod_1_4(const double *a, const double *b, double *r) {
+ prod_4_1(b, a, r);
+ }
+
+ static inline void prod_2_2(const double *a, const double *b, double *r) {
+ double a1_sp[2]; split(a[1], a1_sp);
+ double a0_sp[2]; split(a[0], a0_sp);
+ double b1_sp[2]; split(b[1], b1_sp);
+ double b0_sp[2]; split(b[0], b0_sp);
+
+ double t1[2]; prod_1s_1s(a+0, a0_sp, b+0, b0_sp, t1);
+ r[0] = t1[0];
+ double t2[2]; prod_1s_1s(a+1, a1_sp, b+0, b0_sp, t2);
+
+ double t3[2]; op<1,1>::add(t1+1, t2, t3);
+ double t4[2]; op<1,1>::add_fast(t2+1, t3+1, t4);
+
+ double t5[2]; prod_1s_1s(a+0, a0_sp, b+1, b1_sp, t5);
+
+ double t6[2]; op<1,1>::add(t3, t5, t6);
+ r[1] = t6[0];
+ double t7[2]; op<1,1>::add(t4, t6+1, t7);
+ double t8[2]; op<1,1>::add(t4+1, t7+1, t8);
+
+ double t9[2]; prod_1s_1s(a+1, a1_sp, b+1, b1_sp, t9);
+
+ double t10[2]; op<1,1>::add(t5+1, t9, t10);
+ double t11[2]; op<1,1>::add(t7, t10, t11);
+ r[2] = t11[0];
+ double t12[2]; op<1,1>::add(t8, t11+1, t12);
+ double t13[2]; op<1,1>::add(t8+1, t12+1, t13);
+ double t14[2]; op<1,1>::add(t9+1, t10+1, t14);
+ double t15[2]; op<1,1>::add(t12, t14, t15);
+ r[3] = t15[0];
+ double t16[2]; op<1,1>::add(t13, t15+1, t16);
+ double t17[2]; op<1,1>::add(t13+1, t16+1, t17);
+ double t18[2]; op<1,1>::add(t16, t14+1, t18);
+ r[4] = t18[0];
+ double t19[2]; op<1,1>::add(t17, t18+1, t19);
+ r[5] = t19[0];
+ double t20[2]; op<1,1>::add(t17+1, t19+1, t20);
+ r[6] = t20[0];
+ r[7] = t20[1];
+ }
+
+
+
+ static inline void square(const double a, double *r) {
+ r[1] = a * a;
+ double a_sp[2]; split(a, a_sp);
+ double err1 = r[1] - (a_sp[1] * a_sp[1]);
+ double err3 = err1 - ((a_sp[1] + a_sp[1]) * a_sp[0]);
+ r[0] = a_sp[0] * a_sp[0] - err3;
+ }
+
+ static inline void square_2(const double *a, double *r) {
+ double t1[2]; square(a[0], t1);
+ r[0] = t1[0];
+ double t2 = a[0] + a[0];
+ double t3[2]; prod_1_1(a+1, &t2, t3);
+ double t4[3]; op<2,1>::add(t3, t1 + 1, t4);
+ r[1] = t4[0];
+ double t5[2]; square(a[1], t5);
+ double t6[4]; op<2,2>::add(t5, t4 + 1, r + 2);
+ }
+ }
+
+
+
+ void exact_t::compress() {
+ double sum[2];
+
+ int j = size() - 1;
+ double Q = (*this)[j];
+ for (int i = (int)size()-2; i >= 0; --i) {
+ detail::op<1,1>::add_fast(&Q, &(*this)[i], sum);
+ if (sum[0] != 0) {
+ (*this)[j--] = sum[1];
+ Q = sum[0];
+ } else {
+ Q = sum[1];
+ }
+ }
+ int j2 = 0;
+ for (int i = j + 1; i < (int)size(); ++i) {
+ detail::op<1,1>::add_fast(&(*this)[i], &Q, sum);
+ if (sum[0] != 0) {
+ (*this)[j2++] = sum[0];
+ }
+ Q = sum[1];
+ }
+ (*this)[j2++] = Q;
+
+ erase(begin() + j2, end());
+ }
+
+ template<typename iter_t>
+ void negate(iter_t begin, iter_t end) {
+ while (begin != end) { *begin = -*begin; ++begin; }
+ }
+
+ void negate(exact_t &e) {
+ negate(&e[0], &e[e.size()]);
+ }
+
+ template<typename iter_t>
+ void scale_zeroelim(iter_t ebegin,
+ iter_t eend,
+ double b,
+ exact_t &h) {
+ double Q;
+
+ h.clear();
+ double b_sp[2]; detail::split(b, b_sp);
+
+ double prod[2], sum[2];
+
+ detail::prod_1_1s((double *)ebegin++, &b, b_sp, prod);
+ Q = prod[1];
+ if (prod[0] != 0.0) {
+ h.push_back(prod[0]);
+ }
+ while (ebegin != eend) {
+ double enow = *ebegin++;
+ detail::prod_1_1s(&enow, &b, b_sp, prod);
+ detail::op<1,1>::add(&Q, prod, sum);
+ if (sum[0] != 0) {
+ h.push_back(sum[0]);
+ }
+ detail::op<1,1>::add_fast(prod+1, sum+1, sum);
+ Q = sum[1];
+ if (sum[0] != 0) {
+ h.push_back(sum[0]);
+ }
+ }
+ if ((Q != 0.0) || (h.size() == 0)) {
+ h.push_back(Q);
+ }
+ }
+
+ void scale_zeroelim(const exact_t &e,
+ double b,
+ exact_t &h) {
+ scale_zeroelim(&e[0], &e[e.size()], b, h);
+ }
+
+ template<typename iter_t>
+ void sum_zeroelim(iter_t ebegin,
+ iter_t eend,
+ iter_t fbegin,
+ iter_t fend,
+ exact_t &h) {
+ double Q;
+ double enow, fnow;
+
+ double sum[2];
+
+ enow = *ebegin;
+ fnow = *fbegin;
+
+ h.clear();
+
+ if ((fnow > enow) == (fnow > -enow)) {
+ Q = enow;
+ enow = *++ebegin;
+ } else {
+ Q = fnow;
+ fnow = *++fbegin;
+ }
+
+ if (ebegin != eend && fbegin != fend) {
+ if ((fnow > enow) == (fnow > -enow)) {
+ detail::op<1,1>::add_fast(&enow, &Q, sum);
+ enow = *++ebegin;
+ } else {
+ detail::op<1,1>::add_fast(&fnow, &Q, sum);
+ fnow = *++fbegin;
+ }
+ Q = sum[1];
+ if (sum[0] != 0.0) {
+ h.push_back(sum[0]);
+ }
+ while (ebegin != eend && fbegin != fend) {
+ if ((fnow > enow) == (fnow > -enow)) {
+ detail::op<1,1>::add(&Q, &enow, sum);
+ enow = *++ebegin;
+ } else {
+ detail::op<1,1>::add(&Q, &fnow, sum);
+ fnow = *++fbegin;
+ }
+ Q = sum[1];
+ if (sum[0] != 0.0) {
+ h.push_back(sum[0]);
+ }
+ }
+ }
+
+ while (ebegin != eend) {
+ detail::op<1,1>::add(&Q, &enow, sum);
+ enow = *++ebegin;
+ Q = sum[1];
+ if (sum[0] != 0.0) {
+ h.push_back(sum[0]);
+ }
+ }
+ while (fbegin != fend) {
+ detail::op<1,1>::add(&Q, &fnow, sum);
+ fnow = *++fbegin;
+ Q = sum[1];
+ if (sum[0] != 0.0) {
+ h.push_back(sum[0]);
+ }
+ }
+
+ if (Q != 0.0 || !h.size()) {
+ h.push_back(Q);
+ }
+ }
+
+ void sum_zeroelim(const exact_t &e,
+ const exact_t &f,
+ exact_t &h) {
+ sum_zeroelim(&e[0], &e[e.size()], &f[0], &f[f.size()], h);
+ }
+
+ void sum_zeroelim(const double *ebegin,
+ const double *eend,
+ const exact_t &f,
+ exact_t &h) {
+ sum_zeroelim(ebegin, eend, &f[0], &f[f.size()], h);
+ }
+
+ void sum_zeroelim(const exact_t &e,
+ const double *fbegin,
+ const double *fend,
+ exact_t &h) {
+ sum_zeroelim(&e[0], &e[e.size()], fbegin, fend, h);
+ }
+
+
+ // XXX: not implemented yet
+ //exact_t operator+(const exact_t &a, const exact_t &b) {
+ //}
+
+
+
+ void diffprod(const double a, const double b, const double c, const double d, double *r) {
+ // return ab - cd;
+ double ab[2], cd[2];
+ detail::prod_1_1(&a, &b, ab);
+ detail::prod_1_1(&c, &d, cd);
+ detail::op<2,2>::sub(ab, cd, r);
+ }
+
+ double orient3dexact(const double *pa,
+ const double *pb,
+ const double *pc,
+ const double *pd) {
+ using namespace detail;
+
+ double ab[4]; diffprod(pa[0], pb[1], pb[0], pa[1], ab);
+ double bc[4]; diffprod(pb[0], pc[1], pc[0], pb[1], bc);
+ double cd[4]; diffprod(pc[0], pd[1], pd[0], pc[1], cd);
+ double da[4]; diffprod(pd[0], pa[1], pa[0], pd[1], da);
+ double ac[4]; diffprod(pa[0], pc[1], pc[0], pa[1], ac);
+ double bd[4]; diffprod(pb[0], pd[1], pd[0], pb[1], bd);
+
+ exact_t temp;
+ exact_t cda, dab, abc, bcd;
+ exact_t adet, bdet, cdet, ddet, abdet, cddet, det;
+
+ sum_zeroelim(cd, cd + 4, da, da + 4, temp);
+ sum_zeroelim(temp, ac, ac + 4, cda);
+
+ sum_zeroelim(da, da + 4, ab, ab + 4, temp);
+ sum_zeroelim(temp, bd, bd + 4, dab);
+
+ negate(bd, bd + 4);
+ negate(ac, bd + 4);
+
+ sum_zeroelim(ab, ab + 4, bc, bc + 4, temp);
+ sum_zeroelim(temp, ac, ac + 4, abc);
+
+ sum_zeroelim(bc, bc + 4, cd, cd + 4, temp);
+ sum_zeroelim(temp, bd, bd + 4, bcd);
+
+ scale_zeroelim(bcd, +pa[2], adet);
+ scale_zeroelim(cda, -pb[2], bdet);
+ scale_zeroelim(dab, +pc[2], cdet);
+ scale_zeroelim(abc, -pd[2], ddet);
+
+ sum_zeroelim(adet, bdet, abdet);
+ sum_zeroelim(cdet, ddet, cddet);
+
+ sum_zeroelim(abdet, cddet, det);
+
+ return det[det.size() - 1];
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/face_decl.hpp b/extern/carve/include/carve/face_decl.hpp
new file mode 100644
index 00000000000..bc7afd44adc
--- /dev/null
+++ b/extern/carve/include/carve/face_decl.hpp
@@ -0,0 +1,208 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom2d.hpp>
+#include <carve/vector.hpp>
+#include <carve/matrix.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/aabb.hpp>
+#include <carve/tag.hpp>
+
+#include <vector>
+#include <list>
+#include <map>
+
+namespace carve {
+ namespace poly {
+
+
+
+ struct Object;
+
+ template<unsigned ndim>
+ class Edge;
+
+
+
+ template<unsigned ndim>
+ struct p2_adapt_project {
+ typedef carve::geom2d::P2 (*proj_t)(const carve::geom::vector<ndim> &);
+ proj_t proj;
+ p2_adapt_project(proj_t _proj) : proj(_proj) { }
+ carve::geom2d::P2 operator()(const carve::geom::vector<ndim> &v) const { return proj(v); }
+ carve::geom2d::P2 operator()(const carve::geom::vector<ndim> *v) const { return proj(*v); }
+ carve::geom2d::P2 operator()(const Vertex<ndim> &v) const { return proj(v.v); }
+ carve::geom2d::P2 operator()(const Vertex<ndim> *v) const { return proj(v->v); }
+ };
+
+
+ template<unsigned ndim>
+ class Face : public tagable {
+ public:
+ typedef Vertex<ndim> vertex_t;
+ typedef typename Vertex<ndim>::vector_t vector_t;
+ typedef Edge<ndim> edge_t;
+ typedef Object obj_t;
+ typedef carve::geom::aabb<ndim> aabb_t;
+ typedef carve::geom::plane<ndim> plane_t;
+
+ typedef carve::geom2d::P2 (*project_t)(const vector_t &);
+ typedef vector_t (*unproject_t)(const carve::geom2d::P2 &, const plane_t &);
+
+ protected:
+ std::vector<const vertex_t *> vertices; // pointer into polyhedron.vertices
+ std::vector<const edge_t *> edges; // pointer into polyhedron.edges
+
+ project_t getProjector(bool positive_facing, int axis);
+ unproject_t getUnprojector(bool positive_facing, int axis);
+
+ public:
+ typedef typename std::vector<const vertex_t *>::iterator vertex_iter_t;
+ typedef typename std::vector<const vertex_t *>::const_iterator const_vertex_iter_t;
+
+ typedef typename std::vector<const edge_t *>::iterator edge_iter_t;
+ typedef typename std::vector<const edge_t *>::const_iterator const_edge_iter_t;
+
+ obj_t *owner;
+
+ aabb_t aabb;
+ plane_t plane_eqn;
+ int manifold_id;
+ int group_id;
+
+ project_t project;
+ unproject_t unproject;
+
+ Face(const std::vector<const vertex_t *> &_vertices, bool delay_recalc = false);
+ Face(const vertex_t *v1, const vertex_t *v2, const vertex_t *v3, bool delay_recalc = false);
+ Face(const vertex_t *v1, const vertex_t *v2, const vertex_t *v3, const vertex_t *v4, bool delay_recalc = false);
+
+ template <typename iter_t>
+ Face(const Face *base, iter_t vbegin, iter_t vend, bool flipped) {
+ init(base, vbegin, vend, flipped);
+ }
+
+ Face(const Face *base, const std::vector<const vertex_t *> &_vertices, bool flipped) {
+ init(base, _vertices, flipped);
+ }
+
+ Face() {}
+ ~Face() {}
+
+ bool recalc();
+
+ template<typename iter_t>
+ Face *init(const Face *base, iter_t vbegin, iter_t vend, bool flipped);
+ Face *init(const Face *base, const std::vector<const vertex_t *> &_vertices, bool flipped);
+
+ template<typename iter_t>
+ Face *create(iter_t vbegin, iter_t vend, bool flipped) const;
+ Face *create(const std::vector<const vertex_t *> &_vertices, bool flipped) const;
+
+ Face *clone(bool flipped = false) const;
+ void invert();
+
+ void getVertexLoop(std::vector<const vertex_t *> &loop) const;
+
+ const vertex_t *&vertex(size_t idx);
+ const vertex_t *vertex(size_t idx) const;
+ size_t nVertices() const;
+
+ vertex_iter_t vbegin() { return vertices.begin(); }
+ vertex_iter_t vend() { return vertices.end(); }
+ const_vertex_iter_t vbegin() const { return vertices.begin(); }
+ const_vertex_iter_t vend() const { return vertices.end(); }
+
+ std::vector<carve::geom::vector<2> > projectedVertices() const;
+
+ const edge_t *&edge(size_t idx);
+ const edge_t *edge(size_t idx) const;
+ size_t nEdges() const;
+
+ edge_iter_t ebegin() { return edges.begin(); }
+ edge_iter_t eend() { return edges.end(); }
+ const_edge_iter_t ebegin() const { return edges.begin(); }
+ const_edge_iter_t eend() const { return edges.end(); }
+
+ bool containsPoint(const vector_t &p) const;
+ bool containsPointInProjection(const vector_t &p) const;
+ bool simpleLineSegmentIntersection(const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const;
+ IntersectionClass lineSegmentIntersection(const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const;
+ vector_t centroid() const;
+
+ p2_adapt_project<ndim> projector() const {
+ return p2_adapt_project<ndim>(project);
+ }
+
+ void swap(Face<ndim> &other);
+ };
+
+
+
+ struct hash_face_ptr {
+ template<unsigned ndim>
+ size_t operator()(const Face<ndim> * const &f) const {
+ return (size_t)f;
+ }
+ };
+
+
+
+ namespace face {
+
+
+
+ template<unsigned ndim>
+ static inline carve::geom2d::P2 project(const Face<ndim> *f, const typename Face<ndim>::vector_t &v) {
+ return f->project(v);
+ }
+
+
+
+ template<unsigned ndim>
+ static inline carve::geom2d::P2 project(const Face<ndim> &f, const typename Face<ndim>::vector_t &v) {
+ return f.project(v);
+ }
+
+
+
+ template<unsigned ndim>
+ static inline typename Face<ndim>::vector_t unproject(const Face<ndim> *f, const carve::geom2d::P2 &p) {
+ return f->unproject(p, f->plane_eqn);
+ }
+
+
+
+ template<unsigned ndim>
+ static inline typename Face<ndim>::vector_t unproject(const Face<ndim> &f, const carve::geom2d::P2 &p) {
+ return f.unproject(p, f.plane_eqn);
+ }
+
+
+
+ }
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/face_impl.hpp b/extern/carve/include/carve/face_impl.hpp
new file mode 100644
index 00000000000..771ba761111
--- /dev/null
+++ b/extern/carve/include/carve/face_impl.hpp
@@ -0,0 +1,140 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+namespace std {
+ template<unsigned ndim>
+ inline void swap(carve::poly::Face<ndim> &a, carve::poly::Face<ndim> &b) {
+ a.swap(b);
+ }
+}
+
+namespace carve {
+ namespace poly {
+ template<unsigned ndim>
+ void Face<ndim>::swap(Face<ndim> &other) {
+ std::swap(vertices, other.vertices);
+ std::swap(edges, other.edges);
+ std::swap(owner, other.owner);
+ std::swap(aabb, other.aabb);
+ std::swap(plane_eqn, other.plane_eqn);
+ std::swap(manifold_id, other.manifold_id);
+ std::swap(group_id, other.group_id);
+ std::swap(project, other.project);
+ std::swap(unproject, other.unproject);
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ Face<ndim> *Face<ndim>::init(const Face<ndim> *base, iter_t vbegin, iter_t vend, bool flipped) {
+ vertices.reserve(std::distance(vbegin, vend));
+
+ if (flipped) {
+ std::reverse_copy(vbegin, vend, std::back_inserter(vertices));
+ plane_eqn = -base->plane_eqn;
+ } else {
+ std::copy(vbegin, vend, std::back_inserter(vertices));
+ plane_eqn = base->plane_eqn;
+ }
+
+ edges.clear();
+ edges.resize(nVertices(), NULL);
+
+ aabb.fit(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr());
+ untag();
+
+ int da = carve::geom::largestAxis(plane_eqn.N);
+
+ project = getProjector(plane_eqn.N.v[da] > 0, da);
+ unproject = getUnprojector(plane_eqn.N.v[da] > 0, da);
+
+ return this;
+ }
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ Face<ndim> *Face<ndim>::create(iter_t vbegin, iter_t vend, bool flipped) const {
+ return (new Face)->init(this, vbegin, vend, flipped);
+ }
+
+ template<unsigned ndim>
+ Face<ndim> *Face<ndim>::create(const std::vector<const vertex_t *> &_vertices, bool flipped) const {
+ return (new Face)->init(this, _vertices.begin(), _vertices.end(), flipped);
+ }
+
+ template<unsigned ndim>
+ Face<ndim> *Face<ndim>::clone(bool flipped) const {
+ return (new Face)->init(this, vertices, flipped);
+ }
+
+ template<unsigned ndim>
+ void Face<ndim>::getVertexLoop(std::vector<const vertex_t *> &loop) const {
+ loop.resize(nVertices(), NULL);
+ std::copy(vbegin(), vend(), loop.begin());
+ }
+
+ template<unsigned ndim>
+ const typename Face<ndim>::edge_t *&Face<ndim>::edge(size_t idx) {
+ return edges[idx];
+ }
+
+ template<unsigned ndim>
+ const typename Face<ndim>::edge_t *Face<ndim>::edge(size_t idx) const {
+ return edges[idx];
+ }
+
+ template<unsigned ndim>
+ size_t Face<ndim>::nEdges() const {
+ return edges.size();
+ }
+
+ template<unsigned ndim>
+ const typename Face<ndim>::vertex_t *&Face<ndim>::vertex(size_t idx) {
+ return vertices[idx];
+ }
+
+ template<unsigned ndim>
+ const typename Face<ndim>::vertex_t *Face<ndim>::vertex(size_t idx) const {
+ return vertices[idx];
+ }
+
+ template<unsigned ndim>
+ size_t Face<ndim>::nVertices() const {
+ return vertices.size();
+ }
+
+ template<unsigned ndim>
+ typename Face<ndim>::vector_t Face<ndim>::centroid() const {
+ vector_t c;
+ carve::geom::centroid(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr(), c);
+ return c;
+ }
+
+ template<unsigned ndim>
+ std::vector<carve::geom::vector<2> > Face<ndim>::projectedVertices() const {
+ p2_adapt_project<ndim> proj = projector();
+ std::vector<carve::geom::vector<2> > result;
+ result.reserve(nVertices());
+ for (size_t i = 0; i < nVertices(); ++i) {
+ result.push_back(proj(vertex(i)->v));
+ }
+ return result;
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/faceloop.hpp b/extern/carve/include/carve/faceloop.hpp
new file mode 100644
index 00000000000..5df1d2080f3
--- /dev/null
+++ b/extern/carve/include/carve/faceloop.hpp
@@ -0,0 +1,103 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/classification.hpp>
+#include <carve/collection_types.hpp>
+
+namespace carve {
+ namespace csg {
+
+ struct FaceLoopGroup;
+
+ struct FaceLoop {
+ FaceLoop *next, *prev;
+ const carve::mesh::MeshSet<3>::face_t *orig_face;
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> vertices;
+ FaceLoopGroup *group;
+
+ FaceLoop(const carve::mesh::MeshSet<3>::face_t *f, const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &v) : next(NULL), prev(NULL), orig_face(f), vertices(v), group(NULL) {}
+ };
+
+
+ struct FaceLoopList {
+ FaceLoop *head, *tail;
+ unsigned count;
+
+ FaceLoopList() : head(NULL), tail(NULL), count(0) { }
+
+ void append(FaceLoop *f) {
+ f->prev = tail;
+ f->next = NULL;
+ if (tail) tail->next = f;
+ tail = f;
+ if (!head) head = f;
+ count++;
+ }
+
+ void prepend(FaceLoop *f) {
+ f->next = head;
+ f->prev = NULL;
+ if (head) head->prev = f;
+ head = f;
+ if (!tail) tail = f;
+ count++;
+ }
+
+ unsigned size() const {
+ return count;
+ }
+
+ FaceLoop *remove(FaceLoop *f) {
+ FaceLoop *r = f->next;
+ if (f->prev) { f->prev->next = f->next; } else { head = f->next; }
+ if (f->next) { f->next->prev = f->prev; } else { tail = f->prev; }
+ f->next = f->prev = NULL;
+ count--;
+ return r;
+ }
+
+ ~FaceLoopList() {
+ FaceLoop *a = head, *b;
+ while (a) {
+ b = a;
+ a = a->next;
+ delete b;
+ }
+ }
+ };
+
+ struct FaceLoopGroup {
+ const carve::mesh::MeshSet<3> *src;
+ FaceLoopList face_loops;
+ V2Set perimeter;
+ std::list<ClassificationInfo> classification;
+
+ FaceLoopGroup(const carve::mesh::MeshSet<3> *_src) : src(_src) {
+ }
+
+ FaceClass classificationAgainst(const carve::mesh::MeshSet<3>::mesh_t *mesh) const;
+ };
+
+
+
+ typedef std::list<FaceLoopGroup> FLGroupList;
+
+ }
+}
diff --git a/extern/carve/include/carve/geom.hpp b/extern/carve/include/carve/geom.hpp
new file mode 100644
index 00000000000..421083e3e3c
--- /dev/null
+++ b/extern/carve/include/carve/geom.hpp
@@ -0,0 +1,363 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <vector>
+
+namespace carve {
+ namespace geom {
+
+ template<unsigned ndim> struct aabb;
+
+ // ========================================================================
+ struct _uninitialized { };
+
+ template<unsigned ndim>
+ struct base {
+ double v[ndim];
+ };
+
+ template<> struct base<2> {union { double v[2]; struct { double x, y; }; }; };
+ template<> struct base<3> {union { double v[3]; struct { double x, y, z; }; }; };
+ template<> struct base<4> {union { double v[4]; struct { double x, y, z, w; }; }; };
+
+ template<unsigned ndim>
+ struct vector : public base<ndim> {
+ enum { __ndim = ndim };
+
+ static vector ZERO();
+ double length2() const;
+ double length() const;
+ vector<ndim> &normalize();
+ vector<ndim> normalized() const;
+ bool exactlyZero() const;
+ bool isZero(double epsilon = EPSILON) const;
+ void setZero();
+ void fill(double val);
+ vector<ndim> &scaleBy(double d);
+ vector<ndim> &invscaleBy(double d);
+ vector<ndim> scaled(double d) const;
+ vector<ndim> invscaled(double d) const;
+ vector<ndim> &negate();
+ vector<ndim> negated() const;
+ double &operator[](unsigned i);
+ const double &operator[](unsigned i) const;
+ template<typename assign_t>
+ vector<ndim> &operator=(const assign_t &t);
+ std::string asStr() const;
+
+ aabb<ndim> getAABB() const;
+
+ vector() { setZero(); }
+ vector(noinit_t) { }
+ };
+
+ template<unsigned ndim>
+ vector<ndim> vector<ndim>::ZERO() { vector<ndim> r; r.setZero(); return r; }
+
+ static inline vector<2> VECTOR(double x, double y) { vector<2> r; r.x = x; r.y = y; return r; }
+ static inline vector<3> VECTOR(double x, double y, double z) { vector<3> r; r.x = x; r.y = y; r.z = z; return r; }
+ static inline vector<4> VECTOR(double x, double y, double z, double w) { vector<4> r; r.x = x; r.y = y; r.z = z; r.w = w; return r; }
+
+ template<unsigned ndim> vector<ndim> operator+(const vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> vector<ndim> operator+(const vector<ndim> &a, double b);
+ template<unsigned ndim, typename val_t> vector<ndim> operator+(const vector<ndim> &a, const val_t &b);
+ template<unsigned ndim, typename val_t> vector<ndim> operator+(const val_t &a, const vector<ndim> &b);
+
+ template<unsigned ndim> vector<ndim> &operator+=(vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> vector<ndim> &operator+=(vector<ndim> &a, double b);
+ template<unsigned ndim, typename val_t> vector<ndim> &operator+=(vector<ndim> &a, const val_t &b);
+
+ template<unsigned ndim> vector<ndim> operator-(const vector<ndim> &a);
+
+ template<unsigned ndim> vector<ndim> operator-(const vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> vector<ndim> operator-(const vector<ndim> &a, double b);
+ template<unsigned ndim, typename val_t> vector<ndim> operator-(const vector<ndim> &a, const val_t &b);
+ template<unsigned ndim, typename val_t> vector<ndim> operator-(const val_t &a, const vector<ndim> &b);
+
+ template<unsigned ndim> vector<ndim> &operator-=(vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> vector<ndim> &operator-=(vector<ndim> &a, double b);
+ template<unsigned ndim, typename val_t> vector<ndim> &operator-=(vector<ndim> &a, const val_t &b);
+
+ template<unsigned ndim> vector<ndim> operator*(const vector<ndim> &a, double s);
+ template<unsigned ndim> vector<ndim> operator*(double s, const vector<ndim> &a);
+ template<unsigned ndim> vector<ndim> &operator*=(vector<ndim> &a, double s);
+
+ template<unsigned ndim> vector<ndim> operator/(const vector<ndim> &a, double s);
+ template<unsigned ndim> vector<ndim> &operator/=(vector<ndim> &a, double s);
+
+ template<unsigned ndim> bool operator==(const vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator!=(const vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator<(const vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator<=(const vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator>(const vector<ndim> &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator>=(const vector<ndim> &a, const vector<ndim> &b);
+
+ template<unsigned ndim> vector<ndim> abs(const vector<ndim> &a);
+
+ template<unsigned ndim> double distance2(const vector<ndim> &a, const vector<ndim> &b);
+
+ template<unsigned ndim> double distance(const vector<ndim> &a, const vector<ndim> &b);
+
+ template<unsigned ndim> bool equal(const vector<ndim> &a, const vector<ndim> &b);
+
+ template<unsigned ndim> int smallestAxis(const vector<ndim> &a);
+
+ template<unsigned ndim> int largestAxis(const vector<ndim> &a);
+
+ template<unsigned ndim> vector<2> select(const vector<ndim> &a, int a1, int a2);
+
+ template<unsigned ndim> vector<3> select(const vector<ndim> &a, int a1, int a2, int a3);
+
+ template<unsigned ndim, typename assign_t, typename oper_t>
+ vector<ndim> &assign_op(vector<ndim> &a, const assign_t &t, oper_t op);
+
+ template<unsigned ndim, typename assign1_t, typename assign2_t, typename oper_t>
+ vector<ndim> &assign_op(vector<ndim> &a, const assign1_t &t1, const assign2_t &t2, oper_t op);
+
+ template<unsigned ndim, typename iter_t>
+ void bounds(iter_t begin, iter_t end, vector<ndim> &min, vector<ndim> &max);
+
+ template<unsigned ndim, typename iter_t, typename adapt_t>
+ void bounds(iter_t begin, iter_t end, adapt_t adapt, vector<ndim> &min, vector<ndim> &max);
+
+ template<unsigned ndim, typename iter_t, typename adapt_t>
+ void centroid(iter_t begin, iter_t end, adapt_t adapt, vector<ndim> &c);
+
+ template<unsigned ndim, typename val_t> double dot(const vector<ndim> &a, const val_t &b);
+
+ static inline vector<3> cross(const vector<3> &a, const vector<3> &b);
+
+ static inline double cross(const vector<2> &a, const vector<2> &b);
+
+ static inline double dotcross(const vector<3> &a, const vector<3> &b, const vector<3> &c);
+
+
+
+ // ========================================================================
+ struct axis_pos {
+ int axis;
+ double pos;
+
+ axis_pos(int _axis, double _pos) : axis(_axis), pos(_pos) { }
+ };
+
+ template<unsigned ndim>
+ double distance(const axis_pos &a, const vector<ndim> &b);
+
+ template<unsigned ndim>
+ double distance2(const axis_pos &a, const vector<ndim> &b);
+
+ template<unsigned ndim> bool operator<(const axis_pos &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator<(const vector<ndim> &a, const axis_pos &b);
+
+ template<unsigned ndim> bool operator<=(const axis_pos &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator<=(const vector<ndim> &a, const axis_pos &b);
+
+ template<unsigned ndim> bool operator>(const axis_pos &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator>(const vector<ndim> &a, const axis_pos &b);
+
+ template<unsigned ndim> bool operator>=(const axis_pos &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator>=(const vector<ndim> &a, const axis_pos &b);
+
+ template<unsigned ndim> bool operator==(const axis_pos &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator==(const vector<ndim> &a, const axis_pos &b);
+
+ template<unsigned ndim> bool operator!=(const axis_pos &a, const vector<ndim> &b);
+ template<unsigned ndim> bool operator!=(const vector<ndim> &a, const axis_pos &b);
+
+
+
+ // ========================================================================
+ template<unsigned ndim>
+ struct ray {
+ typedef vector<ndim> vector_t;
+
+ vector_t D, v;
+
+ bool OK() const;
+
+ ray() { }
+ ray(vector_t _D, vector_t _v) : D(_D), v(_v) { }
+ };
+
+ template<unsigned ndim>
+ ray<ndim> rayThrough(const vector<ndim> &a, const vector<ndim> &b);
+
+ static inline double distance2(const ray<3> &r, const vector<3> &v);
+
+ static inline double distance(const ray<3> &r, const vector<3> &v);
+
+ static inline double distance2(const ray<2> &r, const vector<2> &v);
+
+ static inline double distance(const ray<2> &r, const vector<2> &v);
+
+
+
+ // ========================================================================
+ template<unsigned ndim>
+ struct linesegment {
+ typedef vector<ndim> vector_t;
+
+ vector_t v1;
+ vector_t v2;
+ vector_t midpoint;
+ vector_t half_length;
+
+ void update();
+ bool OK() const;
+ void flip();
+
+ aabb<ndim> getAABB() const;
+
+ linesegment(const vector_t &_v1, const vector_t &_v2);
+ };
+
+ template<unsigned ndim>
+ double distance2(const linesegment<ndim> &l, const vector<ndim> &v);
+
+ template<unsigned ndim>
+ double distance(const linesegment<ndim> &l, const vector<ndim> &v);
+
+
+
+ // ========================================================================
+ template<unsigned ndim>
+ struct plane {
+ typedef vector<ndim> vector_t;
+
+ vector_t N;
+ double d;
+
+ void negate();
+
+ plane();
+ plane(const vector_t &_N, vector_t _p);
+ plane(const vector_t &_N, double _d);
+ };
+
+ template<unsigned ndim>
+ inline plane<ndim> operator-(const plane<ndim> &p);
+
+ template<unsigned ndim, typename val_t>
+ double distance(const plane<ndim> &plane, const val_t &point);
+
+ template<unsigned ndim, typename val_t>
+ double distance2(const plane<ndim> &plane, const val_t &point);
+
+ template<unsigned ndim>
+ static inline vector<ndim> closestPoint(const plane<ndim> &p, const vector<ndim> &v);
+
+
+
+ // ========================================================================
+ template<unsigned ndim>
+ struct sphere {
+ typedef vector<ndim> vector_t;
+
+ vector_t C;
+ double r;
+
+ aabb<ndim> getAABB() const;
+
+ sphere();
+ sphere(const vector_t &_C, double _r);
+ };
+
+ template<unsigned ndim, typename val_t>
+ double distance(const sphere<ndim> &sphere, const val_t &point);
+
+ template<unsigned ndim, typename val_t>
+ double distance2(const sphere<ndim> &sphere, const val_t &point);
+
+ template<unsigned ndim>
+ static inline vector<ndim> closestPoint(const sphere<ndim> &sphere, const vector<ndim> &point);
+
+
+ // ========================================================================
+ template<unsigned ndim>
+ struct tri {
+ typedef vector<ndim> vector_t;
+
+ vector_t v[3];
+
+ aabb<ndim> getAABB() const;
+
+ tri(vector_t _v[3]);
+ tri(const vector_t &a, const vector_t &b, const vector_t &c);
+
+ vector_t normal() const {
+ return cross(v[1] - v[0], v[2] - v[1]).normalized();
+ }
+ };
+
+
+
+ template<unsigned ndim> std::ostream &operator<<(std::ostream &o, const vector<ndim> &v);
+ template<unsigned ndim> std::ostream &operator<<(std::ostream &o, const carve::geom::plane<ndim> &p);
+ template<unsigned ndim> std::ostream &operator<<(std::ostream &o, const carve::geom::sphere<ndim> &sphere);
+ template<unsigned ndim> std::ostream &operator<<(std::ostream &o, const carve::geom::tri<ndim> &tri);
+
+
+
+ template<unsigned ndim> vector<ndim> closestPoint(const tri<ndim> &tri, const vector<ndim> &pt);
+ template<unsigned ndim> double distance(const tri<ndim> &tri, const vector<ndim> &pt);
+ template<unsigned ndim> double distance2(const tri<ndim> &tri, const vector<ndim> &pt);
+
+
+
+ // ========================================================================
+ struct distance_functor {
+ template<typename obj1_t, typename obj2_t>
+ double operator()(const obj1_t &o1, const obj2_t &o2) {
+ return distance(o1, o2);
+ }
+ };
+
+
+
+ // ========================================================================
+ template<int base, int power> struct __pow__ { enum { val = __pow__<base, (power >> 1)>::val * __pow__<base, power - (power >> 1)>::val }; };
+ template<int base> struct __pow__<base, 1> { enum { val = base }; };
+ template<int base> struct __pow__<base, 0> { enum { val = 1 }; };
+
+ template<unsigned base, unsigned ndigits>
+ struct quantize {
+ typedef __pow__<base, ndigits> fac;
+
+ double operator()(double in) {
+ return round(in * fac::val) / fac::val;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> operator()(const vector<ndim> &in) {
+ vector<ndim> r(NOINIT);
+ assign_op(r, in, *this);
+ return r;
+ }
+ };
+
+
+
+ }
+}
+
+
+#include <carve/geom_impl.hpp>
diff --git a/extern/carve/include/carve/geom2d.hpp b/extern/carve/include/carve/geom2d.hpp
new file mode 100644
index 00000000000..731e22919b6
--- /dev/null
+++ b/extern/carve/include/carve/geom2d.hpp
@@ -0,0 +1,403 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/math.hpp>
+#include <carve/math_constants.hpp>
+
+#include <carve/geom.hpp>
+
+#include <vector>
+#include <algorithm>
+
+#include <math.h>
+
+#if defined(CARVE_DEBUG)
+# include <iostream>
+#endif
+
+#if defined CARVE_USE_EXACT_PREDICATES
+# include <carve/shewchuk_predicates.hpp>
+#endif
+
+namespace carve {
+ namespace geom2d {
+
+ typedef carve::geom::vector<2> P2;
+ typedef carve::geom::ray<2> Ray2;
+ typedef carve::geom::linesegment<2> LineSegment2;
+
+
+
+ struct p2_adapt_ident {
+ P2 &operator()(P2 &p) const { return p; }
+ const P2 &operator()(const P2 &p) const { return p; }
+ };
+
+
+
+ typedef std::vector<P2> P2Vector;
+
+ /**
+ * \brief Return the orientation of c with respect to the ray defined by a->b.
+ *
+ * (Can be implemented exactly)
+ *
+ * @param[in] a
+ * @param[in] b
+ * @param[in] c
+ *
+ * @return positive, if c to the left of a->b.
+ * zero, if c is colinear with a->b.
+ * negative, if c to the right of a->b.
+ */
+#if defined CARVE_USE_EXACT_PREDICATES
+ inline double orient2d(const P2 &a, const P2 &b, const P2 &c) {
+ return shewchuk::orient2d(a.v, b.v, c.v);
+ }
+#else
+ inline double orient2d(const P2 &a, const P2 &b, const P2 &c) {
+ double acx = a.x - c.x;
+ double bcx = b.x - c.x;
+ double acy = a.y - c.y;
+ double bcy = b.y - c.y;
+ return acx * bcy - acy * bcx;
+ }
+#endif
+
+ /**
+ * \brief Determine whether p is internal to the anticlockwise
+ * angle abc, where b is the apex of the angle.
+ *
+ * @param[in] a
+ * @param[in] b
+ * @param[in] c
+ * @param[in] p
+ *
+ * @return true, if p is contained in the anticlockwise angle from
+ * b->a to b->c. Reflex angles contain p if p lies
+ * on b->a or on b->c. Acute angles do not contain p
+ * if p lies on b->a or on b->c. This is so that
+ * internalToAngle(a,b,c,p) = !internalToAngle(c,b,a,p)
+ */
+ inline bool internalToAngle(const P2 &a,
+ const P2 &b,
+ const P2 &c,
+ const P2 &p) {
+ bool reflex = (a < c) ? orient2d(b, a, c) <= 0.0 : orient2d(b, c, a) > 0.0;
+ double d1 = orient2d(b, a, p);
+ double d2 = orient2d(b, c, p);
+ if (reflex) {
+ return d1 >= 0.0 || d2 <= 0.0;
+ } else {
+ return d1 > 0.0 && d2 < 0.0;
+ }
+ }
+
+ /**
+ * \brief Determine whether p is internal to the anticlockwise
+ * angle ac, with apex at (0,0).
+ *
+ * @param[in] a
+ * @param[in] c
+ * @param[in] p
+ *
+ * @return true, if p is contained in a0c.
+ */
+ inline bool internalToAngle(const P2 &a,
+ const P2 &c,
+ const P2 &p) {
+ return internalToAngle(a, P2::ZERO(), c, p);
+ }
+
+ template<typename P2vec>
+ bool isAnticlockwise(const P2vec &tri) {
+ return orient2d(tri[0], tri[1], tri[2]) > 0.0;
+ }
+
+ template<typename P2vec>
+ bool pointIntersectsTriangle(const P2 &p, const P2vec &tri) {
+ int orient = isAnticlockwise(tri) ? +1 : -1;
+ if (orient2d(tri[0], tri[1], p) * orient < 0) return false;
+ if (orient2d(tri[1], tri[2], p) * orient < 0) return false;
+ if (orient2d(tri[2], tri[0], p) * orient < 0) return false;
+ return true;
+ }
+
+ template<typename P2vec>
+ bool lineIntersectsTriangle(const P2 &p1, const P2 &p2, const P2vec &tri) {
+ double s[3];
+ // does tri lie on one side or the other of p1-p2?
+ s[0] = orient2d(p1, p2, tri[0]);
+ s[1] = orient2d(p1, p2, tri[1]);
+ s[2] = orient2d(p1, p2, tri[2]);
+ if (*std::max_element(s, s+3) < 0) return false;
+ if (*std::min_element(s, s+3) > 0) return false;
+
+ // does line lie entirely to the right of a triangle edge?
+ int orient = isAnticlockwise(tri) ? +1 : -1;
+ if (orient2d(tri[0], tri[1], p1) * orient < 0 && orient2d(tri[0], tri[1], p2) * orient < 0) return false;
+ if (orient2d(tri[1], tri[2], p1) * orient < 0 && orient2d(tri[1], tri[2], p2) * orient < 0) return false;
+ if (orient2d(tri[2], tri[0], p1) * orient < 0 && orient2d(tri[2], tri[0], p2) * orient < 0) return false;
+ return true;
+ }
+
+ template<typename P2vec>
+ int triangleLineOrientation(const P2 &p1, const P2 &p2, const P2vec &tri) {
+ double lo, hi, tmp;
+ lo = hi = orient2d(p1, p2, tri[0]);
+ tmp = orient2d(p1, p2, tri[1]); lo = std::min(lo, tmp); hi = std::max(hi, tmp);
+ tmp = orient2d(p1, p2, tri[2]); lo = std::min(lo, tmp); hi = std::max(hi, tmp);
+ if (hi < 0.0) return -1;
+ if (lo > 0.0) return +1;
+ return 0;
+ }
+
+ template<typename P2vec>
+ bool triangleIntersectsTriangle(const P2vec &tri_b, const P2vec &tri_a) {
+ int orient_a = isAnticlockwise(tri_a) ? +1 : -1;
+ if (triangleLineOrientation(tri_a[0], tri_a[1], tri_b) * orient_a < 0) return false;
+ if (triangleLineOrientation(tri_a[1], tri_a[2], tri_b) * orient_a < 0) return false;
+ if (triangleLineOrientation(tri_a[2], tri_a[0], tri_b) * orient_a < 0) return false;
+
+ int orient_b = isAnticlockwise(tri_b) ? +1 : -1;
+ if (triangleLineOrientation(tri_b[0], tri_b[1], tri_a) * orient_b < 0) return false;
+ if (triangleLineOrientation(tri_b[1], tri_b[2], tri_a) * orient_b < 0) return false;
+ if (triangleLineOrientation(tri_b[2], tri_b[0], tri_a) * orient_b < 0) return false;
+
+ return true;
+ }
+
+
+
+ static inline double atan2(const P2 &p) {
+ return ::atan2(p.y, p.x);
+ }
+
+
+
+ struct LineIntersectionInfo {
+ LineIntersectionClass iclass;
+ P2 ipoint;
+ int p1, p2;
+
+ LineIntersectionInfo(LineIntersectionClass _iclass,
+ P2 _ipoint = P2::ZERO(),
+ int _p1 = -1,
+ int _p2 = -1) :
+ iclass(_iclass), ipoint(_ipoint), p1(_p1), p2(_p2) {
+ }
+ };
+
+ struct PolyInclusionInfo {
+ PointClass iclass;
+ int iobjnum;
+
+ PolyInclusionInfo(PointClass _iclass,
+ int _iobjnum = -1) :
+ iclass(_iclass), iobjnum(_iobjnum) {
+ }
+ };
+
+ struct PolyIntersectionInfo {
+ IntersectionClass iclass;
+ P2 ipoint;
+ size_t iobjnum;
+
+ PolyIntersectionInfo(IntersectionClass _iclass,
+ const P2 &_ipoint,
+ size_t _iobjnum) :
+ iclass(_iclass), ipoint(_ipoint), iobjnum(_iobjnum) {
+ }
+ };
+
+ bool lineSegmentIntersection_simple(const P2 &l1v1, const P2 &l1v2,
+ const P2 &l2v1, const P2 &l2v2);
+ bool lineSegmentIntersection_simple(const LineSegment2 &l1,
+ const LineSegment2 &l2);
+
+ LineIntersectionInfo lineSegmentIntersection(const P2 &l1v1, const P2 &l1v2,
+ const P2 &l2v1, const P2 &l2v2);
+ LineIntersectionInfo lineSegmentIntersection(const LineSegment2 &l1,
+ const LineSegment2 &l2);
+
+ int lineSegmentPolyIntersections(const std::vector<P2> &points,
+ LineSegment2 line,
+ std::vector<PolyInclusionInfo> &out);
+
+ int sortedLineSegmentPolyIntersections(const std::vector<P2> &points,
+ LineSegment2 line,
+ std::vector<PolyInclusionInfo> &out);
+
+
+
+ static inline bool quadIsConvex(const P2 &a, const P2 &b, const P2 &c, const P2 &d) {
+ double s_1, s_2;
+
+ s_1 = carve::geom2d::orient2d(a, c, b);
+ s_2 = carve::geom2d::orient2d(a, c, d);
+ if ((s_1 < 0.0 && s_2 < 0.0) || (s_1 > 0.0 && s_2 > 0.0)) return false;
+
+ s_1 = carve::geom2d::orient2d(b, d, a);
+ s_2 = carve::geom2d::orient2d(b, d, c);
+ if ((s_1 < 0.0 && s_2 < 0.0) || (s_1 > 0.0 && s_2 > 0.0)) return false;
+
+ return true;
+ }
+
+ template<typename T, typename adapt_t>
+ inline bool quadIsConvex(const T &a, const T &b, const T &c, const T &d, adapt_t adapt) {
+ return quadIsConvex(adapt(a), adapt(b), adapt(c), adapt(d));
+ }
+
+
+
+ double signedArea(const std::vector<P2> &points);
+
+ static inline double signedArea(const P2 &a, const P2 &b, const P2 &c) {
+ return ((b.y + a.y) * (b.x - a.x) + (c.y + b.y) * (c.x - b.x) + (a.y + c.y) * (a.x - c.x)) / 2.0;
+ }
+
+ template<typename T, typename adapt_t>
+ double signedArea(const std::vector<T> &points, adapt_t adapt) {
+ P2Vector::size_type l = points.size();
+ double A = 0.0;
+
+ for (P2Vector::size_type i = 0; i < l - 1; i++) {
+ A += (adapt(points[i + 1]).y + adapt(points[i]).y) * (adapt(points[i + 1]).x - adapt(points[i]).x);
+ }
+ A += (adapt(points[0]).y + adapt(points[l - 1]).y) * (adapt(points[0]).x - adapt(points[l - 1]).x);
+
+ return A / 2.0;
+ }
+
+
+
+ template<typename iter_t, typename adapt_t>
+ double signedArea(iter_t begin, iter_t end, adapt_t adapt) {
+ double A = 0.0;
+ P2 p, n;
+
+ if (begin == end) return 0.0;
+
+ p = adapt(*begin);
+ for (iter_t c = begin; ++c != end; ) {
+ P2 n = adapt(*c);
+ A += (n.y + p.y) * (n.x - p.x);
+ p = n;
+ }
+ n = adapt(*begin);
+ A += (n.y + p.y) * (n.x - p.x);
+
+ return A / 2.0;
+ }
+
+
+
+ bool pointInPolySimple(const std::vector<P2> &points, const P2 &p);
+
+ template<typename T, typename adapt_t>
+ bool pointInPolySimple(const std::vector<T> &points, adapt_t adapt, const P2 &p) {
+ CARVE_ASSERT(points.size() > 0);
+ P2Vector::size_type l = points.size();
+ double s = 0.0;
+ double rp, r0, d;
+
+ rp = r0 = atan2(adapt(points[0]) - p);
+
+ for (P2Vector::size_type i = 1; i < l; i++) {
+ double r = atan2(adapt(points[i]) - p);
+ d = r - rp;
+ if (d > M_PI) d -= M_TWOPI;
+ if (d < -M_PI) d += M_TWOPI;
+ s = s + d;
+ rp = r;
+ }
+
+ d = r0 - rp;
+ if (d > M_PI) d -= M_TWOPI;
+ if (d < -M_PI) d += M_TWOPI;
+ s = s + d;
+
+ return !carve::math::ZERO(s);
+ }
+
+
+
+ PolyInclusionInfo pointInPoly(const std::vector<P2> &points, const P2 &p);
+
+ template<typename T, typename adapt_t>
+ PolyInclusionInfo pointInPoly(const std::vector<T> &points, adapt_t adapt, const P2 &p) {
+ P2Vector::size_type l = points.size();
+ for (unsigned i = 0; i < l; i++) {
+ if (equal(adapt(points[i]), p)) return PolyInclusionInfo(POINT_VERTEX, i);
+ }
+
+ for (unsigned i = 0; i < l; i++) {
+ unsigned j = (i + 1) % l;
+
+ if (std::min(adapt(points[i]).x, adapt(points[j]).x) - EPSILON < p.x &&
+ std::max(adapt(points[i]).x, adapt(points[j]).x) + EPSILON > p.x &&
+ std::min(adapt(points[i]).y, adapt(points[j]).y) - EPSILON < p.y &&
+ std::max(adapt(points[i]).y, adapt(points[j]).y) + EPSILON > p.y &&
+ distance2(carve::geom::rayThrough(adapt(points[i]), adapt(points[j])), p) < EPSILON2) {
+ return PolyInclusionInfo(POINT_EDGE, i);
+ }
+ }
+
+ if (pointInPolySimple(points, adapt, p)) {
+ return PolyInclusionInfo(POINT_IN);
+ }
+
+ return PolyInclusionInfo(POINT_OUT);
+ }
+
+
+
+ bool pickContainedPoint(const std::vector<P2> &poly, P2 &result);
+
+ template<typename T, typename adapt_t>
+ bool pickContainedPoint(const std::vector<T> &poly, adapt_t adapt, P2 &result) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "pickContainedPoint ";
+ for (unsigned i = 0; i < poly.size(); ++i) std::cerr << " " << adapt(poly[i]);
+ std::cerr << std::endl;
+#endif
+
+ const size_t S = poly.size();
+ P2 a, b, c;
+ for (unsigned i = 0; i < S; ++i) {
+ a = adapt(poly[i]);
+ b = adapt(poly[(i + 1) % S]);
+ c = adapt(poly[(i + 2) % S]);
+
+ if (cross(a - b, c - b) < 0) {
+ P2 p = (a + b + c) / 3;
+ if (pointInPolySimple(poly, adapt, p)) {
+ result = p;
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/geom3d.hpp b/extern/carve/include/carve/geom3d.hpp
new file mode 100644
index 00000000000..90d0672b81e
--- /dev/null
+++ b/extern/carve/include/carve/geom3d.hpp
@@ -0,0 +1,310 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/geom.hpp>
+
+#include <math.h>
+#include <carve/math_constants.hpp>
+
+#include <vector>
+#include <list>
+#include <map>
+
+#if defined(CARVE_DEBUG)
+# include <iostream>
+#endif
+
+#if defined CARVE_USE_EXACT_PREDICATES
+# include <carve/shewchuk_predicates.hpp>
+#endif
+
+namespace carve {
+ namespace geom3d {
+
+ typedef carve::geom::plane<3> Plane;
+ typedef carve::geom::ray<3> Ray;
+ typedef carve::geom::linesegment<3> LineSegment;
+ typedef carve::geom::vector<3> Vector;
+
+ template<typename iter_t, typename adapt_t>
+ bool fitPlane(iter_t begin, iter_t end, adapt_t adapt, Plane &plane) {
+ Vector centroid;
+ carve::geom::centroid(begin, end, adapt, centroid);
+ iter_t i;
+
+ Vector n = Vector::ZERO();
+ Vector v;
+ Vector p1, p2, p3, c1, c2;
+ if (begin == end) return false;
+
+ i = begin;
+ p1 = c1 = adapt(*i); if (++i == end) return false;
+ p2 = c2 = adapt(*i); if (++i == end) return false;
+
+#if defined(CARVE_DEBUG)
+ size_t N = 2;
+#endif
+ do {
+ p3 = adapt(*i);
+ v = cross(p3 - p2, p1 - p2);
+ if (v.v[largestAxis(v)]) v.negate();
+ n += v;
+ p1 = p2; p2 = p3;
+#if defined(CARVE_DEBUG)
+ ++N;
+#endif
+ } while (++i != end);
+
+ p1 = p2; p2 = p3; p3 = c1;
+ v = cross(p3 - p2, p1 - p2);
+ if (v.v[largestAxis(v)]) v.negate();
+ n += v;
+
+ p1 = p2; p2 = p3; p3 = c2;
+ v = cross(p3 - p2, p1 - p2);
+ if (v.v[largestAxis(v)]) v.negate();
+ n += v;
+
+ n.normalize();
+ plane.N = n;
+ plane.d = -dot(n, centroid);
+#if defined(CARVE_DEBUG)
+ if (N > 3) {
+ std::cerr << "N = " << N << " fitted distance:";
+ for (i = begin; i != end; ++i) {
+ Vector p = adapt(*i);
+ std::cerr << " {" << p << "} " << distance(plane, p);
+ }
+ std::cerr << std::endl;
+ }
+#endif
+ return true;
+ }
+
+ bool planeIntersection(const Plane &a, const Plane &b, Ray &r);
+
+ IntersectionClass rayPlaneIntersection(const Plane &p,
+ const Vector &v1,
+ const Vector &v2,
+ Vector &v,
+ double &t);
+
+ IntersectionClass lineSegmentPlaneIntersection(const Plane &p,
+ const LineSegment &line,
+ Vector &v);
+
+ RayIntersectionClass rayRayIntersection(const Ray &r1,
+ const Ray &r2,
+ Vector &v1,
+ Vector &v2,
+ double &mu1,
+ double &mu2);
+
+
+
+ // test whether point d is above, below or on the plane formed by the triangle a,b,c.
+ // return: +ve = d is below a,b,c
+ // -ve = d is above a,b,c
+ // 0 = d is on a,b,c
+#if defined CARVE_USE_EXACT_PREDICATES
+ inline double orient3d(const Vector &a,
+ const Vector &b,
+ const Vector &c,
+ const Vector &d) {
+ return shewchuk::orient3d(a.v, b.v, c.v, d.v);
+ }
+#else
+ inline double orient3d(const Vector &a,
+ const Vector &b,
+ const Vector &c,
+ const Vector &d) {
+ return dotcross((a - d), (b - d), (c - d));
+ }
+#endif
+
+ // Volume of a tetrahedron described by 4 points. Will be
+ // positive if the anticlockwise normal of a,b,c is oriented out
+ // of the tetrahedron.
+ //
+ // see: http://mathworld.wolfram.com/Tetrahedron.html
+ inline double tetrahedronVolume(const Vector &a,
+ const Vector &b,
+ const Vector &c,
+ const Vector &d) {
+ return dotcross((a - d), (b - d), (c - d)) / 6.0;
+ }
+
+ /**
+ * \brief Determine whether p is internal to the wedge defined by
+ * the area between the planes defined by a,b,c and a,b,d
+ * angle abc, where ab is the apex of the angle.
+ *
+ * @param[in] a
+ * @param[in] b
+ * @param[in] c
+ * @param[in] d
+ * @param[in] p
+ *
+ * @return true, if p is contained in the wedge defined by the
+ * area between the planes defined by a,b,c and
+ * a,b,d. If the wedge is reflex, p is considered to
+ * be contained if it lies on either plane. Acute
+ * wdges do not contain p if p lies on either
+ * plane. This is so that internalToWedge(a,b,c,d,p) =
+ * !internalToWedge(a,b,d,c,p)
+ */
+ inline bool internalToWedge(const Vector &a,
+ const Vector &b,
+ const Vector &c,
+ const Vector &d,
+ const Vector &p) {
+ bool reflex = (c < d) ?
+ orient3d(a, b, c, d) >= 0.0 :
+ orient3d(a, b, d, c) < 0.0;
+
+ double d1 = orient3d(a, b, c, p);
+ double d2 = orient3d(a, b, d, p);
+
+ if (reflex) {
+ // above a,b,c or below a,b,d (or coplanar with either)
+ return d1 <= 0.0 || d2 >= 0.0;
+ } else {
+ // above a,b,c and below a,b,d
+ return d1 < 0.0 && d2 > 0.0;
+ }
+ }
+
+ /**
+ * \brief Determine the ordering relationship of a and b, when
+ * rotating around direction, starting from base.
+ *
+ * @param[in] adirection
+ * @param[in] base
+ * @param[in] a
+ * @param[in] b
+ *
+ * @return
+ * * -1, if a is ordered before b around, rotating about direction.
+ * * 0, if a and b are equal in angle.
+ * * +1, if a is ordered after b around, rotating about direction.
+ */
+ inline int compareAngles(const Vector &direction, const Vector &base, const Vector &a, const Vector &b) {
+ const double d1 = carve::geom3d::orient3d(carve::geom::VECTOR(0,0,0), direction, a, b);
+ const double d2 = carve::geom3d::orient3d(carve::geom::VECTOR(0,0,0), direction, base, a);
+ const double d3 = carve::geom3d::orient3d(carve::geom::VECTOR(0,0,0), direction, base, b);
+
+ // CASE: a and b are coplanar wrt. direction.
+ if (d1 == 0.0) {
+ // a and b point in the same direction.
+ if (dot(a, b) > 0.0) {
+ // Neither is less than the other.
+ return 0;
+ }
+
+ // a and b point in opposite directions.
+ // * if d2 < 0.0, a is above plane(direction, base) and is less
+ // than b.
+ // * if d2 == 0.0 a is coplanar with plane(direction, base) and is
+ // less than b if it points in the same direction as base.
+ // * if d2 > 0.0, a is below plane(direction, base) and is greater
+ // than b.
+
+ if (d2 == 0.0) { return dot(a, base) > 0.0 ? -1 : +1; }
+ if (d3 == 0.0) { return dot(b, base) > 0.0 ? +1 : -1; }
+ if (d2 < 0.0 && d3 > 0.0) return -1;
+ if (d2 > 0.0 && d3 < 0.0) return +1;
+
+ // both a and b are to one side of plane(direction, base) -
+ // rounding error (if a and b are truly coplanar with
+ // direction, one should be above, and one should be below any
+ // other plane that is not itself coplanar with
+ // plane(direction, a|b) - which would imply d2 and d3 == 0.0).
+
+ // If both are below plane(direction, base) then the one that
+ // points in the same direction as base is greater.
+ // If both are above plane(direction, base) then the one that
+ // points in the same direction as base is lesser.
+ if (d2 > 0.0) { return dot(a, base) > 0.0 ? +1 : -1; }
+ else { return dot(a, base) > 0.0 ? -1 : +1; }
+ }
+
+ // CASE: a and b are not coplanar wrt. direction
+
+ if (d2 < 0.0) {
+ // if a is above plane(direction,base), then a is less than b if
+ // b is below plane(direction,base) or b is above plane(direction,a)
+ return (d3 > 0.0 || d1 < 0.0) ? -1 : +1;
+ } else if (d2 == 0.0) {
+ // if a is on plane(direction,base) then a is less than b if a
+ // points in the same direction as base, or b is below
+ // plane(direction,base)
+ return (dot(a, base) > 0.0 || d3 > 0.0) ? -1 : +1;
+ } else {
+ // if a is below plane(direction,base), then a is less than b if b
+ // is below plane(direction,base) and b is above plane(direction,a)
+ return (d3 > 0.0 && d1 < 0.0) ? -1 : +1;
+ }
+ }
+
+ // The anticlockwise angle from vector "from" to vector "to", oriented around the vector "orient".
+ static inline double antiClockwiseAngle(const Vector &from, const Vector &to, const Vector &orient) {
+ double dp = dot(from, to);
+ Vector cp = cross(from, to);
+ if (cp.isZero()) {
+ if (dp < 0) {
+ return M_PI;
+ } else {
+ return 0.0;
+ }
+ } else {
+ if (dot(cp, orient) > 0.0) {
+ return acos(dp);
+ } else {
+ return M_TWOPI - acos(dp);
+ }
+ }
+ }
+
+
+
+ static inline double antiClockwiseOrdering(const Vector &from, const Vector &to, const Vector &orient) {
+ double dp = dot(from, to);
+ Vector cp = cross(from, to);
+ if (cp.isZero()) {
+ if (dp < 0) {
+ return 2.0;
+ } else {
+ return 0.0;
+ }
+ } else {
+ if (dot(cp, orient) > 0.0) {
+ // 1..-1 -> 0..2
+ return 1.0 - dp;
+ } else {
+ // -1..1 -> 2..4
+ return dp + 1.0;
+ }
+ }
+ }
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/geom_impl.hpp b/extern/carve/include/carve/geom_impl.hpp
new file mode 100644
index 00000000000..4463ba2bd88
--- /dev/null
+++ b/extern/carve/include/carve/geom_impl.hpp
@@ -0,0 +1,651 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/math.hpp>
+
+namespace carve {
+ namespace geom {
+
+
+
+ template<unsigned ndim>
+ double vector<ndim>::length2() const { return dot(*this, *this); }
+ template<unsigned ndim>
+ double vector<ndim>::length() const { return sqrt(dot(*this, *this)); }
+
+ template<unsigned ndim>
+ vector<ndim> &vector<ndim>::normalize() { *this /= length(); return *this; }
+ template<unsigned ndim>
+ vector<ndim> vector<ndim>::normalized() const { return *this / length(); }
+
+ template<unsigned ndim>
+ bool vector<ndim>::exactlyZero() const {
+ for (unsigned i = 0; i < ndim; ++i) if (this->v[i]) return false;
+ return true;
+ }
+ template<unsigned ndim>
+ bool vector<ndim>::isZero(double epsilon) const {
+ return length2() < epsilon * epsilon;
+ }
+
+ template<unsigned ndim>
+ void vector<ndim>::setZero() { for (size_t i = 0; i < ndim; ++i) this->v[i] = 0.0; }
+
+ template<unsigned ndim>
+ void vector<ndim>::fill(double val) { for (size_t i = 0; i < ndim; ++i) this->v[i] = val; }
+
+ template<unsigned ndim>
+ vector<ndim> &vector<ndim>::scaleBy(double d) { for (unsigned i = 0; i < ndim; ++i) this->v[i] *= d; return *this; }
+ template<unsigned ndim>
+ vector<ndim> &vector<ndim>::invscaleBy(double d) { for (unsigned i = 0; i < ndim; ++i) this->v[i] /= d; return *this; }
+
+ template<unsigned ndim>
+ vector<ndim> vector<ndim>::scaled(double d) const { return *this * d; }
+ template<unsigned ndim>
+ vector<ndim> vector<ndim>::invscaled(double d) const { return *this / d; }
+
+ template<unsigned ndim>
+ vector<ndim> &vector<ndim>::negate() { for (unsigned i = 0; i < ndim; ++i) this->v[i] = -this->v[i]; return *this; }
+ template<unsigned ndim>
+ vector<ndim> vector<ndim>::negated() const { return -*this; }
+
+ template<unsigned ndim>
+ double &vector<ndim>::operator[](unsigned i) { return this->v[i]; }
+ template<unsigned ndim>
+ const double &vector<ndim>::operator[](unsigned i) const { return this->v[i]; }
+
+ template<unsigned ndim>
+ template<typename assign_t>
+ vector<ndim> &vector<ndim>::operator=(const assign_t &t) {
+ for (unsigned i = 0; i < ndim; ++i) this->v[i] = t[i];
+ return *this;
+ }
+
+ template<unsigned ndim>
+ std::string vector<ndim>::asStr() const {
+ std::ostringstream out;
+ out << '<';
+ out << std::setprecision(24);
+ for (unsigned i = 0; i < ndim; ++i) { if (i) out << ','; out << this->v[i]; }
+ out << '>';
+ return out.str();
+ }
+
+
+
+ template<unsigned ndim>
+ vector<ndim> operator+(const vector<ndim> &a, const vector<ndim> &b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] + b[i];
+ return c;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> operator+(const vector<ndim> &a, double b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] + b;
+ return c;
+ }
+
+ template<unsigned ndim, typename val_t>
+ vector<ndim> operator+(const vector<ndim> &a, const val_t &b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] + b[i];
+ return c;
+ }
+
+ template<unsigned ndim, typename val_t>
+ vector<ndim> operator+(const val_t &a, const vector<ndim> &b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] + b[i];
+ return c;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> &operator+=(vector<ndim> &a, const vector<ndim> &b) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] += b[i];
+ return a;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> &operator+=(vector<ndim> &a, double b) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] += b;
+ return a;
+ }
+
+ template<unsigned ndim, typename val_t>
+ vector<ndim> &operator+=(vector<ndim> &a, const val_t &b) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] += b[i];
+ return a;
+ }
+
+
+
+ template<unsigned ndim>
+ vector<ndim> operator-(const vector<ndim> &a) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = -a[i];
+ return c;
+ }
+
+
+
+ template<unsigned ndim>
+ vector<ndim> operator-(const vector<ndim> &a, double b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] - b;
+ return c;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> operator-(const vector<ndim> &a, const vector<ndim> &b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] - b[i];
+ return c;
+ }
+
+ template<unsigned ndim, typename val_t>
+ vector<ndim> operator-(const vector<ndim> &a, const val_t &b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] - b[i];
+ return c;
+ }
+
+ template<unsigned ndim, typename val_t>
+ vector<ndim> operator-(const val_t &a, const vector<ndim> &b) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] - b[i];
+ return c;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> &operator-=(vector<ndim> &a, const vector<ndim> &b) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] -= b[i];
+ return a;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> &operator-=(vector<ndim> &a, double b) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] -= b;
+ return a;
+ }
+
+ template<unsigned ndim, typename val_t>
+ vector<ndim> &operator-=(vector<ndim> &a, const val_t &b) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] -= b[i];
+ return a;
+ }
+
+
+
+ template<unsigned ndim>
+ vector<ndim> operator*(const vector<ndim> &a, double s) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] * s;
+ return c;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> operator*(double s, const vector<ndim> &a) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] * s;
+ return c;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> &operator*=(vector<ndim> &a, double s) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] *= s;
+ return a;
+ }
+
+
+
+ template<unsigned ndim>
+ vector<ndim> operator/(const vector<ndim> &a, double s) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = a[i] / s;
+ return c;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> &operator/=(vector<ndim> &a, double s) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] /= s;
+ return a;
+ }
+
+
+
+ template<unsigned ndim>
+ bool operator==(const vector<ndim> &a, const vector<ndim> &b) {
+ for (unsigned i = 0; i < ndim; ++i) { if (a[i] != b[i]) return false; }
+ return true;
+ }
+
+ template<unsigned ndim>
+ bool operator!=(const vector<ndim> &a, const vector<ndim> &b) {
+ return !(a == b);
+ }
+
+ template<unsigned ndim>
+ bool operator<(const vector<ndim> &a, const vector<ndim> &b) {
+ for (unsigned i = 0; i < ndim; ++i) { if (a[i] < b[i]) return true; if (a[i] > b[i]) return false; }
+ return false;
+ }
+
+ template<unsigned ndim>
+ bool operator<=(const vector<ndim> &a, const vector<ndim> &b) {
+ return !(b < a);
+ }
+
+ template<unsigned ndim>
+ bool operator>(const vector<ndim> &a, const vector<ndim> &b) {
+ return b < a;
+ }
+
+ template<unsigned ndim>
+ bool operator>=(const vector<ndim> &a, const vector<ndim> &b) {
+ return !(a < b);
+ }
+
+
+
+ template<unsigned ndim>
+ vector<ndim> abs(const vector<ndim> &a) {
+ vector<ndim> c(NOINIT);
+ for (unsigned i = 0; i < ndim; ++i) c[i] = fabs(a[i]);
+ return c;
+ }
+
+ template<unsigned ndim>
+ double distance2(const vector<ndim> &a, const vector<ndim> &b) {
+ return (b - a).length2();
+ }
+
+ template<unsigned ndim>
+ double distance(const vector<ndim> &a, const vector<ndim> &b) {
+ return (b - a).length();
+ }
+
+ template<unsigned ndim>
+ bool equal(const vector<ndim> &a, const vector<ndim> &b) {
+ return (b - a).isZero();
+ }
+
+ template<unsigned ndim>
+ int smallestAxis(const vector<ndim> &a) {
+ int x = 0;
+ double y = fabs(a[0]);
+ for (unsigned i = 1; i < ndim; ++i) {
+ double z = fabs(a[i]);
+ if (z <= y) { y = z; x = i; }
+ }
+ return x;
+ }
+
+ template<unsigned ndim>
+ int largestAxis(const vector<ndim> &a) {
+ int x = 0;
+ double y = fabs(a[0]);
+ for (unsigned i = 1; i < ndim; ++i) {
+ double z = fabs(a[i]);
+ if (z > y) { y = z; x = i; }
+ }
+ return x;
+ }
+
+ template<unsigned ndim>
+ vector<2> select(const vector<ndim> &a, int a1, int a2) {
+ vector<2> r(NOINIT);
+ r.v[0] = a.v[a1]; r.v[1] = a.v[a2];
+ return r;
+ }
+
+ template<unsigned ndim>
+ vector<3> select(const vector<ndim> &a, int a1, int a2, int a3) {
+ vector<3> r(NOINIT);
+ r.v[0] = a.v[a1]; r.v[1] = a.v[a2]; r.v[2] = a.v[a3];
+ return r;
+ }
+
+ template<unsigned ndim, typename assign_t, typename oper_t>
+ vector<ndim> &assign_op(vector<ndim> &a, const assign_t &t, oper_t op) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] = op(t[i]);
+ return a;
+ }
+
+ template<unsigned ndim, typename assign1_t, typename assign2_t, typename oper_t>
+ vector<ndim> &assign_op(vector<ndim> &a, const assign1_t &t1, const assign2_t &t2, oper_t op) {
+ for (unsigned i = 0; i < ndim; ++i) a[i] = op(t1[i], t2[i]);
+ return a;
+ }
+
+ template<unsigned ndim, typename iter_t>
+ void bounds(iter_t begin, iter_t end, vector<ndim> &min, vector<ndim> &max) {
+ if (begin == end) {
+ min.setZero();
+ max.setZero();
+ } else {
+ min = max = *begin;
+ while (++begin != end) {
+ vector<ndim> v = *begin;
+ assign_op(min, min, v, carve::util::min_functor());
+ assign_op(max, max, v, carve::util::max_functor());
+ }
+ }
+ }
+
+ template<unsigned ndim, typename iter_t, typename adapt_t>
+ void bounds(iter_t begin, iter_t end, adapt_t adapt, vector<ndim> &min, vector<ndim> &max) {
+ if (begin == end) {
+ min.setZero();
+ max.setZero();
+ } else {
+ min = max = adapt(*begin);
+ while (++begin != end) {
+ vector<ndim> v = adapt(*begin);
+ assign_op(min, min, v, carve::util::min_functor());
+ assign_op(max, max, v, carve::util::max_functor());
+ }
+ }
+ }
+
+ template<unsigned ndim, typename iter_t, typename adapt_t>
+ void centroid(iter_t begin, iter_t end, adapt_t adapt, vector<ndim> &c) {
+ c.setZero();
+ int n = 0;
+ while (begin != end) { c += adapt(*begin++); ++n; }
+ c /= double(n);
+ }
+
+ template<unsigned ndim, typename val_t>
+ double dot(const vector<ndim> &a, const val_t &b) {
+ double r = 0.0;
+ for (unsigned i = 0; i < ndim; ++i) r += a[i] * b[i];
+ return r;
+ }
+
+ static inline vector<3> cross(const vector<3> &a, const vector<3> &b) {
+ // Compute a x b
+ return VECTOR(+(a.y * b.z - a.z * b.y),
+ -(a.x * b.z - a.z * b.x),
+ +(a.x * b.y - a.y * b.x));
+ }
+
+ static inline double cross(const vector<2> &a, const vector<2> &b) {
+ // Compute a x b
+ return a.x * b.y - b.x * a.y;
+ }
+
+ static inline double dotcross(const vector<3> &a, const vector<3> &b, const vector<3> &c) {
+ // Compute a . (b x c)
+ return
+ (a.x * b.y * c.z + a.y * b.z * c.x + a.z * b.x * c.y) -
+ (a.x * b.z * c.y + a.y * b.x * c.z + a.z * b.y * c.x);
+ }
+
+
+
+ template<unsigned ndim>
+ double distance(const axis_pos &a, const vector<ndim> &b) {
+ return fabs(b[a.axis] - a.pos);
+ }
+
+ template<unsigned ndim>
+ double distance2(const axis_pos &a, const vector<ndim> &b) {
+ double r = fabs(b[a.axis] - a.pos);
+ return r * r;
+ }
+
+ template<unsigned ndim> bool operator<(const axis_pos &a, const vector<ndim> &b) { return a.pos < b[a.axis]; }
+ template<unsigned ndim> bool operator<(const vector<ndim> &a, const axis_pos &b) { return a[b.axis] < b.pos; }
+
+ template<unsigned ndim> bool operator<=(const axis_pos &a, const vector<ndim> &b) { return a.pos <= b[a.axis]; }
+ template<unsigned ndim> bool operator<=(const vector<ndim> &a, const axis_pos &b) { return a[b.axis] <= b.pos; }
+
+ template<unsigned ndim> bool operator>(const axis_pos &a, const vector<ndim> &b) { return a.pos > b[a.axis]; }
+ template<unsigned ndim> bool operator>(const vector<ndim> &a, const axis_pos &b) { return a[b.axis] > b.pos; }
+
+ template<unsigned ndim> bool operator>=(const axis_pos &a, const vector<ndim> &b) { return a.pos >= b[a.axis]; }
+ template<unsigned ndim> bool operator>=(const vector<ndim> &a, const axis_pos &b) { return a[b.axis] >= b.pos; }
+
+ template<unsigned ndim> bool operator==(const axis_pos &a, const vector<ndim> &b) { return a.pos == b[a.axis]; }
+ template<unsigned ndim> bool operator==(const vector<ndim> &a, const axis_pos &b) { return a[b.axis] == b.pos; }
+
+ template<unsigned ndim> bool operator!=(const axis_pos &a, const vector<ndim> &b) { return a.pos != b[a.axis]; }
+ template<unsigned ndim> bool operator!=(const vector<ndim> &a, const axis_pos &b) { return a[b.axis] != b.pos; }
+
+
+
+ template<unsigned ndim>
+ bool ray<ndim>::OK() const {
+ return !D.isZero();
+ }
+
+ template<unsigned ndim>
+ ray<ndim> rayThrough(const vector<ndim> &a, const vector<ndim> &b) {
+ return ray<ndim>(b - a, a);
+ }
+
+ static inline double distance2(const ray<3> &r, const vector<3> &v) {
+ return cross(r.D, v - r.v).length2() / r.D.length2();
+ }
+
+ static inline double distance(const ray<3> &r, const vector<3> &v) {
+ return sqrt(distance2(r, v));
+ }
+
+ static inline double distance2(const ray<2> &r, const vector<2> &v) {
+ double t = cross(r.D, v - r.v);
+ return (t * t) / r.D.length2();
+ }
+
+ static inline double distance(const ray<2> &r, const vector<2> &v) {
+ return sqrt(distance2(r, v));
+ }
+
+
+
+ template<unsigned ndim>
+ void linesegment<ndim>::update() {
+ midpoint = (v2 + v1) / 2.0;
+ half_length = (v2 - v1) / 2.0;
+ }
+
+ template<unsigned ndim>
+ bool linesegment<ndim>::OK() const {
+ return !half_length.isZero();
+ }
+
+ template<unsigned ndim>
+ void linesegment<ndim>::flip() {
+ std::swap(v1, v2);
+ half_length = (v2 - v1) / 2.0;
+ }
+
+ template<unsigned ndim>
+ aabb<ndim> linesegment<ndim>::getAABB() const {
+ aabb<ndim> r;
+ r.fit(v1, v2);
+ return r;
+ }
+
+ template<unsigned ndim>
+ linesegment<ndim>::linesegment(const vector_t &_v1, const vector_t &_v2) : v1(_v1), v2(_v2) {
+ update();
+ }
+
+
+
+ template<unsigned ndim>
+ double distance2(const linesegment<ndim> &l, const vector<ndim> &v) {
+ vector<ndim> D = l.v2 - l.v1;
+ double t = dot(v - l.v1, D) / dot(D, D);
+ if (t <= 0.0) return (v - l.v1).length2();
+ if (t >= 1.0) return (v - l.v2).length2();
+ vector<ndim> vc = D * t + l.v1;
+ return (v - vc).length2();
+ }
+
+ template<unsigned ndim>
+ double distance(const linesegment<ndim> &l, const vector<ndim> &v) {
+ return sqrt(distance2(l, v));
+ }
+
+
+ template<unsigned ndim>
+ void plane<ndim>::negate() {
+ N.negate();
+ d = -d;
+ }
+
+ template<unsigned ndim>
+ plane<ndim>::plane() {
+ N.setZero();
+ N[0] = 1.0;
+ d= 0.0;
+ }
+
+ template<unsigned ndim>
+ plane<ndim>::plane(const vector_t &_N, vector_t _p) : N(_N), d(-dot(_p, _N)) {
+ }
+
+ template<unsigned ndim>
+ plane<ndim>::plane(const vector_t &_N, double _d) : N(_N), d(_d) {
+ }
+
+
+
+ template<unsigned ndim>
+ plane<ndim> operator-(const plane<ndim> &p) {
+ return plane<ndim>(-p.N, -p.d);
+ }
+
+ template<unsigned ndim, typename val_t>
+ double distance(const plane<ndim> &plane, const val_t &point) {
+ return dot(plane.N, point) + plane.d;
+ }
+
+ template<unsigned ndim, typename val_t>
+ double distance2(const plane<ndim> &plane, const val_t &point) {
+ double d = distance(plane, point);
+ return d * d;
+ }
+
+ template<unsigned ndim>
+ vector<ndim> closestPoint(const plane<ndim> &p, const vector<ndim> &v) {
+ return v - p.N * (p.d + dot(p.N, v)) / dot(p.N, p.N);
+ }
+
+
+
+ template<unsigned ndim>
+ aabb<ndim> sphere<ndim>::getAABB() const {
+ aabb<ndim> r;
+ r.fit(C - r, C + r);
+ }
+
+ template<unsigned ndim>
+ sphere<ndim>::sphere() {
+ C.setZero();
+ r = 1.0;
+ }
+
+ template<unsigned ndim>
+ sphere<ndim>::sphere(const vector_t &_C, double _r) : C(_C), r(_r) {
+ }
+
+
+
+ template<unsigned ndim, typename val_t>
+ double distance(const sphere<ndim> &sphere, const val_t &point) {
+ return std::max(0.0, distance(sphere.C, point) - sphere.r);
+ }
+
+ template<unsigned ndim, typename val_t>
+ double distance2(const sphere<ndim> &sphere, const val_t &point) {
+ return std::max(0.0, distance2(sphere.C, point) - sphere.r * sphere.r);
+ }
+
+ template<unsigned ndim>
+ vector<ndim> closestPoint(const sphere<ndim> &sphere, const vector<ndim> &point) {
+ return (point - sphere.C).normalized() * sphere.r;
+ }
+
+
+
+ template<unsigned ndim>
+ aabb<ndim> tri<ndim>::getAABB() const {
+ aabb<ndim> aabb;
+ aabb.fit(v[0], v[1], v[2]);
+ return aabb;
+ }
+
+ template<unsigned ndim>
+ tri<ndim>::tri(vector_t _v[3]) {
+ std::copy(v, v+3, _v);
+ }
+
+ template<unsigned ndim>
+ tri<ndim>::tri(const vector_t &a, const vector_t &b, const vector_t &c) {
+ v[0] = a;
+ v[1] = b;
+ v[2] = c;
+ }
+
+
+
+ template<unsigned ndim>
+ std::ostream &operator<<(std::ostream &o, const vector<ndim> &v) {
+ o << v.asStr();
+ return o;
+ }
+
+ template<unsigned ndim>
+ std::ostream &operator<<(std::ostream &o, const carve::geom::plane<ndim> &p) {
+ o << p.N << ";" << p.d;
+ return o;
+ }
+
+ template<unsigned ndim>
+ std::ostream &operator<<(std::ostream &o, const carve::geom::sphere<ndim> &sphere) {
+ o << "{sphere " << sphere.C << ";" << sphere.r << "}";
+ return o;
+ }
+
+ template<unsigned ndim>
+ std::ostream &operator<<(std::ostream &o, const carve::geom::tri<ndim> &tri) {
+ o << "{tri " << tri.v[0] << ";" << tri.v[1] << ";" << tri.v[2] << "}";
+ return o;
+ }
+
+
+
+ template<unsigned ndim>
+ double distance(const tri<ndim> &tri, const vector<ndim> &pt) {
+ return distance(closestPoint(tri, pt), pt);
+ }
+
+
+
+ template<unsigned ndim>
+ double distance2(const tri<ndim> &tri, const vector<ndim> &pt) {
+ return distance2(closestPoint(tri, pt), pt);
+ }
+ }
+}
diff --git a/extern/carve/include/carve/gnu_cxx.h b/extern/carve/include/carve/gnu_cxx.h
new file mode 100644
index 00000000000..280fa360478
--- /dev/null
+++ b/extern/carve/include/carve/gnu_cxx.h
@@ -0,0 +1,4 @@
+// Copyright 2006 Tobias Sargeant (toby@permuted.net)
+// All rights reserved.
+
+#pragma once
diff --git a/extern/carve/include/carve/heap.hpp b/extern/carve/include/carve/heap.hpp
new file mode 100644
index 00000000000..20bdcf003e5
--- /dev/null
+++ b/extern/carve/include/carve/heap.hpp
@@ -0,0 +1,425 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+namespace carve {
+ namespace heap {
+ namespace detail {
+
+
+
+ struct ignore_position_t {
+ template<typename value_t>
+ void operator()(value_t &val, size_t idx) const {}
+ };
+
+
+
+ template<typename random_access_iter_t,
+ typename distance_t,
+ typename value_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void _adjust_heap(random_access_iter_t begin,
+ distance_t pos,
+ distance_t len,
+ value_t val,
+ pred_t pred,
+ pos_notifier_t notify) {
+ const distance_t top = pos;
+
+ distance_t child = pos * 2 + 2;
+ while (child < len) {
+ if (pred(begin[child], begin[child - 1])) child--;
+
+ begin[pos] = begin[child];
+ notify(begin[pos], pos);
+ pos = child;
+ child = pos * 2 + 2;
+ }
+
+ if (child == len) {
+ child--;
+ begin[pos] = begin[child];
+ notify(begin[pos], pos);
+ pos = child;
+ }
+
+ distance_t parent = (pos - 1) / 2;
+ while (pos > top && pred(begin[parent], val)) {
+ begin[pos] = begin[parent];
+ notify(begin[pos], pos);
+ pos = parent;
+ parent = (pos - 1) / 2;
+ }
+
+ begin[pos] = val;
+ notify(begin[pos], pos);
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename distance_t,
+ typename value_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void _push_heap(random_access_iter_t begin,
+ distance_t pos,
+ value_t val,
+ pred_t pred,
+ pos_notifier_t notify) {
+ distance_t parent = (pos - 1) / 2;
+ while (pos > 0 && pred(begin[parent], val)) {
+ begin[pos] = begin[parent];
+ notify(begin[pos], pos);
+ pos = parent;
+ parent = (pos - 1) / 2;
+ }
+ begin[pos] = val;
+ notify(begin[pos], pos);
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename distance_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void _remove_heap(random_access_iter_t begin,
+ distance_t pos,
+ distance_t len,
+ pred_t pred,
+ pos_notifier_t notify) {
+ --len;
+ if (pos != len) {
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+ value_t removed = begin[pos];
+ _adjust_heap(begin, pos, len, begin[len], pred, notify);
+ begin[len] = removed;
+ notify(begin[len], len);
+ }
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename distance_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void _make_heap(random_access_iter_t begin,
+ distance_t len,
+ pred_t pred,
+ pos_notifier_t notify) {
+ for (distance_t pos = len / 2; pos > 0; ) {
+ --pos;
+ _adjust_heap(begin, pos, len, begin[pos], pred, ignore_position_t());
+ }
+ for (distance_t pos = 0; pos < len; ++pos) {
+ notify(begin[pos], pos);
+ }
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename distance_t,
+ typename pred_t>
+ void _make_heap(random_access_iter_t begin,
+ distance_t len,
+ pred_t pred,
+ ignore_position_t) {
+ for (distance_t pos = len / 2; pos > 0; ) {
+ --pos;
+ _adjust_heap(begin, pos, len, begin[pos], pred, ignore_position_t());
+ }
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename distance_t,
+ typename pred_t>
+ bool _is_heap(random_access_iter_t begin,
+ distance_t len,
+ pred_t pred) {
+ distance_t parent = 0;
+
+ for (distance_t child = 1; child < len; ++child) {
+ if (pred(begin[parent], begin[child])) {
+ return false;
+ }
+ if (++child == len) break;
+ if (pred(begin[parent], begin[child])) {
+ return false;
+ }
+ ++parent;
+ }
+
+ return true;
+ }
+
+
+
+ }
+
+
+
+ template<typename random_access_iter_t>
+ void adjust_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ random_access_iter_t pos) {
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+
+ detail::_adjust_heap(begin, pos - begin, end - begin, *pos, std::less<value_t>());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t>
+ void adjust_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ random_access_iter_t pos,
+ pred_t pred) {
+ detail::_adjust_heap(begin, pos - begin, end - begin, *pos, pred);
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void adjust_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ random_access_iter_t pos,
+ pred_t pred,
+ pos_notifier_t notify) {
+ detail::_adjust_heap(begin, pos - begin, end - begin, *pos, pred, notify);
+ }
+
+
+
+ template<typename random_access_iter_t>
+ void remove_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ random_access_iter_t pos) {
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+
+ detail::_remove_heap(begin, pos - begin, end - begin, std::less<value_t>(), detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t>
+ void remove_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ random_access_iter_t pos,
+ pred_t pred) {
+ detail::_remove_heap(begin, pos - begin, end - begin, pred, detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void remove_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ random_access_iter_t pos,
+ pred_t pred,
+ pos_notifier_t notify) {
+ detail::_remove_heap(begin, pos - begin, end - begin, pred, notify);
+ }
+
+
+
+ template<typename random_access_iter_t>
+ void pop_heap(random_access_iter_t begin,
+ random_access_iter_t end) {
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ detail::_remove_heap(begin, distance_t(0), end - begin, std::less<value_t>(), detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t>
+ void pop_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred) {
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ detail::_remove_heap(begin, distance_t(0), end - begin, pred, detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void pop_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred,
+ pos_notifier_t notify) {
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ detail::_remove_heap(begin, distance_t(0), end - begin, pred, notify);
+ }
+
+
+
+ template<typename random_access_iter_t>
+ void push_heap(random_access_iter_t begin,
+ random_access_iter_t end) {
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ distance_t pos = end - begin - 1;
+ detail::_push_heap(begin, pos, begin[pos], std::less<value_t>(), detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t>
+ void push_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred) {
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ distance_t pos = end - begin - 1;
+ detail::_push_heap(begin, pos, begin[pos], pred, detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void push_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred,
+ pos_notifier_t notify) {
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ distance_t pos = end - begin - 1;
+ detail::_push_heap(begin, pos, begin[pos], pred, notify);
+ }
+
+
+
+ template<typename random_access_iter_t>
+ void make_heap(random_access_iter_t begin,
+ random_access_iter_t end) {
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+
+ detail::_make_heap(begin, end - begin, std::less<value_t>(), detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t>
+ void make_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred) {
+ detail::_make_heap(begin, end - begin, pred, detail::ignore_position_t());
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void make_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred,
+ pos_notifier_t notify) {
+ detail::_make_heap(begin, end - begin, pred, notify);
+ }
+
+
+
+ template<typename random_access_iter_t>
+ bool is_heap(random_access_iter_t begin,
+ random_access_iter_t end) {
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+
+ return detail::_is_heap(begin, end - begin, std::less<value_t>());
+ }
+
+
+
+ template<typename random_access_iter_t, typename pred_t>
+ bool is_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred) {
+ return detail::_is_heap(begin, end - begin, pred);
+ }
+
+
+
+ template<typename random_access_iter_t>
+ void sort_heap(random_access_iter_t begin,
+ random_access_iter_t end) {
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+ typedef typename std::iterator_traits<random_access_iter_t>::value_type value_t;
+
+ for (distance_t len = end - begin; len > 1; --len) {
+ detail::_remove_heap(begin, distance_t(0), len, std::less<value_t>(), detail::ignore_position_t());
+ }
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t>
+ void sort_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred) {
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ for (distance_t len = end - begin; len > 1; --len) {
+ detail::_remove_heap(begin, distance_t(0), len, pred, detail::ignore_position_t());
+ }
+ }
+
+
+
+ template<typename random_access_iter_t,
+ typename pred_t,
+ typename pos_notifier_t>
+ void sort_heap(random_access_iter_t begin,
+ random_access_iter_t end,
+ pred_t pred,
+ pos_notifier_t notify) {
+ typedef typename std::iterator_traits<random_access_iter_t>::difference_type distance_t;
+
+ for (distance_t len = end - begin; len > 1; --len) {
+ detail::_remove_heap(begin, distance_t(0), len, pred, detail::ignore_position_t());
+ notify(begin[len], len);
+ }
+ notify(begin[0], 0);
+ }
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/input.hpp b/extern/carve/include/carve/input.hpp
new file mode 100644
index 00000000000..a8bc8137d6c
--- /dev/null
+++ b/extern/carve/include/carve/input.hpp
@@ -0,0 +1,251 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/poly.hpp>
+#include <carve/mesh.hpp>
+#include <carve/polyline.hpp>
+#include <carve/pointset.hpp>
+
+
+
+namespace carve {
+ namespace input {
+
+ struct Data {
+ Data() {
+ }
+
+ virtual ~Data() {
+ }
+
+ virtual void transform(const carve::math::Matrix & /* transform */) {
+ }
+ };
+
+
+
+ struct VertexData : public Data {
+ std::vector<carve::geom3d::Vector> points;
+
+ VertexData() : Data() {
+ }
+
+ virtual ~VertexData() {
+ }
+
+ virtual void transform(const carve::math::Matrix &transform) {
+ for (size_t i = 0; i < points.size(); ++i) {
+ points[i] *= transform;
+ }
+ }
+
+ size_t addVertex(carve::geom3d::Vector point) {
+ size_t index = points.size();
+ points.push_back(point);
+ return index;
+ }
+
+ inline void reserveVertices(int count) {
+ points.reserve(count);
+ }
+
+ size_t getVertexCount() const {
+ return points.size();
+ }
+
+ const carve::geom3d::Vector &getVertex(int index) const {
+ return points[index];
+ }
+ };
+
+
+
+ struct PolyhedronData : public VertexData {
+ std::vector<int> faceIndices;
+ int faceCount;
+
+ PolyhedronData() : VertexData(), faceIndices(), faceCount(0) {
+ }
+
+ virtual ~PolyhedronData() {
+ }
+
+ void reserveFaces(int count, int avgFaceSize) {
+ faceIndices.reserve(faceIndices.size() + count * (1 + avgFaceSize));
+ }
+
+ int getFaceCount() const {
+ return faceCount;
+ }
+
+ template <typename Iter>
+ void addFace(Iter begin, Iter end) {
+ size_t n = std::distance(begin, end);
+ faceIndices.reserve(faceIndices.size() + n + 1);
+ faceIndices.push_back(n);
+ std::copy(begin, end, std::back_inserter(faceIndices));
+ ++faceCount;
+ }
+
+ void addFace(int a, int b, int c) {
+ faceIndices.push_back(3);
+ faceIndices.push_back(a);
+ faceIndices.push_back(b);
+ faceIndices.push_back(c);
+ ++faceCount;
+ }
+
+ void addFace(int a, int b, int c, int d) {
+ faceIndices.push_back(4);
+ faceIndices.push_back(a);
+ faceIndices.push_back(b);
+ faceIndices.push_back(c);
+ faceIndices.push_back(d);
+ ++faceCount;
+ }
+
+ void clearFaces() {
+ faceIndices.clear();
+ faceCount = 0;
+ }
+
+ carve::poly::Polyhedron *create() const {
+ return new carve::poly::Polyhedron(points, faceCount, faceIndices);
+ }
+
+ carve::mesh::MeshSet<3> *createMesh() const {
+ return new carve::mesh::MeshSet<3>(points, faceCount, faceIndices);
+ }
+ };
+
+
+
+ struct PolylineSetData : public VertexData {
+ typedef std::pair<bool, std::vector<int> > polyline_data_t;
+ std::list<polyline_data_t> polylines;
+
+ PolylineSetData() : VertexData(), polylines() {
+ }
+
+ virtual ~PolylineSetData() {
+ }
+
+ void beginPolyline(bool closed = false) {
+ polylines.push_back(std::make_pair(closed, std::vector<int>()));
+ }
+
+ void reservePolyline(size_t len) {
+ polylines.back().second.reserve(len);
+ }
+
+ void addPolylineIndex(int idx) {
+ polylines.back().second.push_back(idx);
+ }
+
+ carve::line::PolylineSet *create() const {
+ carve::line::PolylineSet *p = new carve::line::PolylineSet(points);
+
+ for (std::list<polyline_data_t>::const_iterator i = polylines.begin();
+ i != polylines.end();
+ ++i) {
+ p->addPolyline((*i).first, (*i).second.begin(), (*i).second.end());
+ }
+ return p;
+ }
+ };
+
+
+
+ struct PointSetData : public VertexData {
+
+ PointSetData() : VertexData() {
+ }
+
+ virtual ~PointSetData() {
+ }
+
+ carve::point::PointSet *create() const {
+ carve::point::PointSet *p = new carve::point::PointSet(points);
+ return p;
+ }
+ };
+
+
+
+ class Input {
+ public:
+ std::list<Data *> input;
+
+ Input() {
+ }
+
+ ~Input() {
+ for (std::list<Data *>::iterator i = input.begin(); i != input.end(); ++i) {
+ delete (*i);
+ }
+ }
+
+ void addDataBlock(Data *data) {
+ input.push_back(data);
+ }
+
+ void transform(const carve::math::Matrix &transform) {
+ if (transform == carve::math::Matrix::IDENT()) return;
+ for (std::list<Data *>::iterator i = input.begin(); i != input.end(); ++i) {
+ (*i)->transform(transform);
+ }
+ }
+
+ template<typename T>
+ static inline T *create(Data *d) {
+ return NULL;
+ }
+ };
+
+ template<>
+ inline carve::mesh::MeshSet<3> *Input::create(Data *d) {
+ PolyhedronData *p = dynamic_cast<PolyhedronData *>(d);
+ if (p == NULL) return NULL;
+ return p->createMesh();
+ }
+
+ template<>
+ inline carve::poly::Polyhedron *Input::create(Data *d) {
+ PolyhedronData *p = dynamic_cast<PolyhedronData *>(d);
+ if (p == NULL) return NULL;
+ return p->create();
+ }
+
+ template<>
+ inline carve::line::PolylineSet *Input::create(Data *d) {
+ PolylineSetData *p = dynamic_cast<PolylineSetData *>(d);
+ if (p == NULL) return NULL;
+ return p->create();
+ }
+
+ template<>
+ inline carve::point::PointSet *Input::create(Data *d) {
+ PointSetData *p = dynamic_cast<PointSetData *>(d);
+ if (p == NULL) return NULL;
+ return p->create();
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/interpolator.hpp b/extern/carve/include/carve/interpolator.hpp
new file mode 100644
index 00000000000..e1555105435
--- /dev/null
+++ b/extern/carve/include/carve/interpolator.hpp
@@ -0,0 +1,332 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/geom2d.hpp>
+#include <carve/poly.hpp>
+#include <carve/mesh.hpp>
+#include <carve/csg.hpp>
+
+namespace carve {
+ namespace interpolate {
+
+ static inline std::vector<double> polyInterpolate(const std::vector<carve::geom2d::P2> &s,
+ const carve::geom2d::P2 &v) {
+ // see hormann et al. 2006
+ const size_t SZ = s.size();
+ std::vector<double> r;
+ std::vector<double> A;
+ std::vector<double> D;
+
+ std::vector<double> result;
+
+ r.resize(SZ);
+ A.resize(SZ);
+ D.resize(SZ);
+
+ result.resize(SZ, 0.0);
+
+ for (size_t i = 0; i < SZ; ++i) {
+ size_t i2 = (i + 1) % SZ;
+ carve::geom2d::P2 si = s[i] - v;
+ carve::geom2d::P2 si2 = s[i2] - v;
+
+ r[i] = sqrt(dot(si, si));
+ A[i] = cross(si, si2) / 2.0;
+ D[i] = dot(si, si2);
+ if (fabs(r[i]) < 1e-16) {
+ result[i] = 1.0;
+ return result;
+ } else if (fabs(A[i]) < 1e-16 && D[i] < 0.0) {
+ double r2 = sqrt(dot(si2, si2));
+ result[i2] = r[i] / (r[i] + r2);
+ result[i] = r2 / (r[i] + r2);
+ return result;
+ }
+ }
+
+ double w_sum = 0.0;
+
+ for (size_t i = 0; i < SZ; ++i) {
+ size_t i_m = (i + SZ - 1) % SZ;
+ size_t i_p = (i + 1) % SZ;
+
+ double w = 0.0;
+ if (fabs(A[i_m]) > 1e-16)
+ w += (r[i_m] - D[i_m] / r[i]) / A[i_m];
+ if (fabs(A[i]) > 1e-16)
+ w += (r[i_p] - D[i] / r[i]) / A[i];
+
+ result[i] = w;
+ w_sum += w;
+ }
+
+ for (size_t i = 0; i < SZ; ++i) {
+ result[i] /= w_sum;
+ }
+
+// carve::geom2d::P2 test;
+// for (size_t i = 0; i < SZ; ++i) {
+// test = test + result[i] * s[i];
+// }
+
+ return result;
+ }
+
+ template<typename iter_t,
+ typename adapt_t,
+ typename val_t,
+ typename mod_t>
+ val_t interp(iter_t begin,
+ iter_t end,
+ adapt_t adapt,
+ const std::vector<val_t> &vals,
+ double x,
+ double y,
+ mod_t mod = mod_t()) {
+ std::vector<carve::geom2d::P2> s;
+ s.reserve(std::distance(begin, end));
+ std::transform(begin, end, std::back_inserter(s), adapt);
+ std::vector<double> weight = polyInterpolate(s, carve::geom::VECTOR(x, y));
+
+ val_t v;
+ for (size_t z = 0; z < weight.size(); z++) {
+ v += weight[z] * vals[z];
+ }
+
+ return mod(v);
+ }
+
+ template<typename iter_t,
+ typename adapt_t,
+ typename val_t>
+ val_t interp(iter_t begin,
+ iter_t end,
+ adapt_t adapt,
+ const std::vector<val_t> &vals,
+ double x,
+ double y) {
+ return interp(begin, end, adapt, vals, x, y, identity_t<val_t>());
+ }
+
+ template<typename vertex_t,
+ typename adapt_t,
+ typename val_t,
+ typename mod_t>
+ val_t interp(const std::vector<vertex_t> &poly,
+ adapt_t adapt,
+ const std::vector<val_t> &vals,
+ double x,
+ double y,
+ mod_t mod = mod_t()) {
+ return interp(poly.begin(), poly.end(), adapt, vals, x, y, mod);
+ }
+
+ template<typename vertex_t,
+ typename adapt_t,
+ typename val_t>
+ val_t interp(const std::vector<vertex_t> &poly,
+ adapt_t adapt,
+ const std::vector<val_t> &vals,
+ double x,
+ double y) {
+ return interp(poly.begin(), poly.end(), adapt, vals, x, y, identity_t<val_t>());
+ }
+
+ template<typename val_t,
+ typename mod_t>
+ val_t interp(const std::vector<carve::geom2d::P2> &poly,
+ const std::vector<val_t> &vals,
+ double x,
+ double y,
+ mod_t mod = mod_t()) {
+ std::vector<double> weight = polyInterpolate(poly, carve::geom::VECTOR(x, y));
+
+ val_t v;
+ for (size_t z = 0; z < weight.size(); z++) {
+ v += weight[z] * vals[z];
+ }
+
+ return mod(v);
+ }
+
+ template<typename val_t>
+ val_t interp(const std::vector<carve::geom2d::P2> &poly,
+ const std::vector<val_t> &vals,
+ double x,
+ double y) {
+ return interp(poly, vals, x, y, identity_t<val_t>());
+ }
+
+ class Interpolator {
+ public:
+ virtual void interpolate(const carve::mesh::MeshSet<3>::face_t *new_face,
+ const carve::mesh::MeshSet<3>::face_t *orig_face,
+ bool flipped) =0;
+
+ Interpolator() {
+ }
+
+ virtual ~Interpolator() {
+ }
+
+ class Hook : public carve::csg::CSG::Hook {
+ Interpolator *interpolator;
+ public:
+ virtual void resultFace(const carve::mesh::MeshSet<3>::face_t *new_face,
+ const carve::mesh::MeshSet<3>::face_t *orig_face,
+ bool flipped) {
+ interpolator->interpolate(new_face, orig_face, flipped);
+ }
+
+ Hook(Interpolator *_interpolator) : interpolator(_interpolator) {
+ }
+
+ virtual ~Hook() {
+ }
+ };
+
+ void installHooks(carve::csg::CSG &csg) {
+ csg.hooks.registerHook(new Hook(this), carve::csg::CSG::Hooks::RESULT_FACE_BIT);
+ }
+ };
+
+ template<typename attr_t>
+ class FaceVertexAttr : public Interpolator {
+
+ protected:
+ struct fv_hash {
+ size_t operator()(const std::pair<const carve::mesh::MeshSet<3>::face_t *, unsigned> &v) const {
+ return size_t(v.first) ^ size_t(v.second);
+ }
+ };
+
+ typedef std::unordered_map<const carve::mesh::MeshSet<3>::vertex_t *, attr_t> attrvmap_t;
+ typedef std::unordered_map<std::pair<const carve::mesh::MeshSet<3>::face_t *, unsigned>, attr_t, fv_hash> attrmap_t;
+
+ attrmap_t attrs;
+
+ public:
+ bool hasAttribute(const carve::mesh::MeshSet<3>::face_t *f, unsigned v) {
+ return attrs.find(std::make_pair(f, v)) != attrs.end();
+ }
+
+ attr_t getAttribute(const carve::mesh::MeshSet<3>::face_t *f, unsigned v, const attr_t &def = attr_t()) {
+ typename attrmap_t::const_iterator fv = attrs.find(std::make_pair(f, v));
+ if (fv != attrs.end()) {
+ return (*fv).second;
+ }
+ return def;
+ }
+
+ void setAttribute(const carve::mesh::MeshSet<3>::face_t *f, unsigned v, const attr_t &attr) {
+ attrs[std::make_pair(f, v)] = attr;
+ }
+
+ virtual void interpolate(const carve::mesh::MeshSet<3>::face_t *new_face,
+ const carve::mesh::MeshSet<3>::face_t *orig_face,
+ bool flipped) {
+ std::vector<attr_t> vertex_attrs;
+ attrvmap_t base_attrs;
+ vertex_attrs.reserve(orig_face->nVertices());
+
+ for (carve::mesh::MeshSet<3>::face_t::const_edge_iter_t e = orig_face->begin(); e != orig_face->end(); ++e) {
+ typename attrmap_t::const_iterator a = attrs.find(std::make_pair(orig_face, e.idx()));
+ if (a == attrs.end()) return;
+ vertex_attrs.push_back((*a).second);
+ base_attrs[e->vert] = vertex_attrs.back();
+ }
+
+ for (carve::mesh::MeshSet<3>::face_t::const_edge_iter_t e = new_face->begin(); e != new_face->end(); ++e) {
+ const carve::mesh::MeshSet<3>::vertex_t *vertex = e->vert;
+ typename attrvmap_t::const_iterator b = base_attrs.find(vertex);
+ if (b != base_attrs.end()) {
+ attrs[std::make_pair(new_face, e.idx())] = (*b).second;
+ } else {
+ carve::geom2d::P2 p = orig_face->project(e->vert->v);
+ attr_t attr = interp(orig_face->begin(),
+ orig_face->end(),
+ orig_face->projector(),
+ vertex_attrs,
+ p.x,
+ p.y);
+ attrs[std::make_pair(new_face, e.idx())] = attr;
+ }
+ }
+ }
+
+ FaceVertexAttr() : Interpolator() {
+ }
+
+ virtual ~FaceVertexAttr() {
+ }
+
+ };
+
+
+ template<typename attr_t>
+ class FaceAttr : public Interpolator {
+
+ protected:
+ struct f_hash {
+ size_t operator()(const carve::mesh::MeshSet<3>::face_t * const &f) const {
+ return size_t(f);
+ }
+ };
+
+ typedef std::unordered_map<const carve::mesh::MeshSet<3>::face_t *, attr_t, f_hash> attrmap_t;
+
+ attrmap_t attrs;
+
+ public:
+ bool hasAttribute(const carve::mesh::MeshSet<3>::face_t *f) {
+ return attrs.find(f) != attrs.end();
+ }
+
+ attr_t getAttribute(const carve::mesh::MeshSet<3>::face_t *f, const attr_t &def = attr_t()) {
+ typename attrmap_t::const_iterator i = attrs.find(f);
+ if (i != attrs.end()) {
+ return (*i).second;
+ }
+ return def;
+ }
+
+ void setAttribute(const carve::mesh::MeshSet<3>::face_t *f, const attr_t &attr) {
+ attrs[f] = attr;
+ }
+
+ virtual void interpolate(const carve::mesh::MeshSet<3>::face_t *new_face,
+ const carve::mesh::MeshSet<3>::face_t *orig_face,
+ bool flipped) {
+ typename attrmap_t::const_iterator i = attrs.find(orig_face);
+ if (i != attrs.end()) {
+ attrs[new_face] = (*i).second;
+ }
+ }
+
+ FaceAttr() : Interpolator() {
+ }
+
+ virtual ~FaceAttr() {
+ }
+
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/intersection.hpp b/extern/carve/include/carve/intersection.hpp
new file mode 100644
index 00000000000..1862a366abb
--- /dev/null
+++ b/extern/carve/include/carve/intersection.hpp
@@ -0,0 +1,267 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/collection_types.hpp>
+#include <carve/iobj.hpp>
+
+namespace carve {
+ namespace csg {
+
+ /**
+ * \class Intersections
+ * \brief Storage for computed intersections between vertices, edges and faces.
+ *
+ */
+ struct Intersections : public std::unordered_map<IObj, IObjVMapSmall, IObj_hash> {
+ typedef carve::mesh::MeshSet<3>::vertex_t vertex_t;
+ typedef carve::mesh::MeshSet<3>::edge_t edge_t;
+ typedef carve::mesh::MeshSet<3>::face_t face_t;
+
+ typedef std::unordered_map<IObj, IObjVMapSmall, IObj_hash> super;
+
+ ~Intersections() {
+ }
+
+ /**
+ * \brief Record the position of intersection between a pair of intersection objects.
+ *
+ * @param a The first intersecting object.
+ * @param b The second intersecting object.
+ * @param p The point of intersection.
+ */
+ void record(IObj a, IObj b, vertex_t *p) {
+ if (a > b) std::swap(a, b);
+ (*this)[a][b] = p;
+ (*this)[b][a] = p;
+ }
+
+ /**
+ * \brief Test whether vertex \a v intersects face \a f.
+ *
+ * @param v The vertex to test.
+ * @param f The face to test.
+ *
+ * @return true, if \a v intersects \a f.
+ */
+ bool intersectsFace(vertex_t *v, face_t *f) const;
+
+ /**
+ * \brief Collect sets of vertices, edges and faces that intersect \a obj
+ *
+ * @param[in] obj The intersection object to search for intersections.
+ * @param[out] collect_v A vector of vertices intersecting \a obj.
+ * @param[out] collect_e A vector of edges intersecting \a obj.
+ * @param[out] collect_f A vector of faces intersecting \a obj.
+ */
+ void collect(const IObj &obj,
+ std::vector<vertex_t *> *collect_v,
+ std::vector<edge_t *> *collect_e,
+ std::vector<face_t *> *collect_f) const;
+
+
+ /**
+ * \brief Determine whether two intersection objects intersect.
+ *
+ * @param a The first intersection object.
+ * @param b The second intersection object.
+ *
+ * @return true, if \a a and \a b intersect.
+ */
+ bool intersectsExactly(const IObj &a, const IObj &b) {
+ Intersections::const_iterator i = find(a);
+ if (i == end()) return false;
+ return i->second.find(b) != i->second.end();
+ }
+
+ /**
+ * \brief Determine whether an intersection object intersects a vertex.
+ *
+ * @param a The intersection object.
+ * @param v The vertex.
+ *
+ * @return true, if \a a and \a v intersect.
+ */
+ bool intersects(const IObj &a, vertex_t *v) {
+ Intersections::const_iterator i = find(a);
+ if (i == end()) return false;
+ if (i->second.find(v) != i->second.end()) return true;
+ return false;
+ }
+
+ /**
+ * \brief Determine whether an intersection object intersects an edge.
+ *
+ * @param a The intersection object.
+ * @param e The edge.
+ *
+ * @return true, if \a a and \a e intersect (either on the edge,
+ * or at either endpoint).
+ */
+ bool intersects(const IObj &a, edge_t *e) {
+ Intersections::const_iterator i = find(a);
+ if (i == end()) return false;
+ for (super::data_type::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
+ const IObj &obj = j->first;
+ switch (obj.obtype) {
+ case IObj::OBTYPE_VERTEX:
+ if (obj.vertex == e->v1() || obj.vertex == e->v2()) return true;
+ break;
+ case IObj::OBTYPE_EDGE:
+ if (obj.edge == e) return true;
+ break;
+ default:
+ break;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * \brief Determine whether an intersection object intersects a face.
+ *
+ * @param a The intersection object.
+ * @param f The face.
+ *
+ * @return true, if \a a and \a f intersect (either on the face,
+ * or at any associated edge or vertex).
+ */
+ bool intersects(const IObj &a, face_t *f) {
+ Intersections::const_iterator i = find(a);
+ if (i == end()) return false;
+ if (i->second.find(f) != i->second.end()) return true;
+ edge_t *e = f->edge;
+ do {
+ if (i->second.find(e) != i->second.end()) return true;
+ if (i->second.find(e->vert) != i->second.end()) return true;
+ e = e->next;
+ } while (e != f->edge);
+ return false;
+ }
+
+ /**
+ * \brief Determine whether an edge intersects another edge.
+ *
+ * @param e The edge.
+ * @param f The face.
+ *
+ * @return true, if \a e and \a f intersect.
+ */
+ bool intersects(edge_t *e1, edge_t *e2) {
+ if (intersects(e1->v1(), e2) || intersects(e1->v2(), e2) || intersects(IObj(e1), e2)) return true;
+ return false;
+ }
+
+ /**
+ * \brief Determine whether an edge intersects a face.
+ *
+ * @param e The edge.
+ * @param f The face.
+ *
+ * @return true, if \a e and \a f intersect.
+ */
+ bool intersects(edge_t *e, face_t *f) {
+ if (intersects(e->v1(), f) || intersects(e->v2(), f) || intersects(IObj(e), f)) return true;
+ return false;
+ }
+
+ /**
+ * \brief Determine the faces intersected by an edge.
+ *
+ * @tparam face_set_t A collection type holding face_t *
+ * @param[in] e The edge.
+ * @param[out] f The resulting set of faces.
+ */
+ template<typename face_set_t>
+ void intersectedFaces(edge_t *e, face_set_t &f) const {
+ std::vector<face_t *> intersected_faces;
+ std::vector<edge_t *> intersected_edges;
+ std::vector<vertex_t *> intersected_vertices;
+
+ collect(e, &intersected_vertices, &intersected_edges, &intersected_faces);
+
+ for (unsigned i = 0; i < intersected_vertices.size(); ++i) {
+ facesForVertex(intersected_vertices[i], f);
+ }
+ for (unsigned i = 0; i < intersected_edges.size(); ++i) {
+ facesForEdge(intersected_edges[i], f);
+ }
+ f.insert(intersected_faces.begin(), intersected_faces.end());
+ }
+
+ /**
+ * \brief Determine the faces intersected by a vertex.
+ *
+ * @tparam face_set_t A collection type holding face_t *
+ * @param[in] v The vertex.
+ * @param[out] f The resulting set of faces.
+ */
+ template<typename face_set_t>
+ void intersectedFaces(vertex_t *v, face_set_t &f) const {
+ std::vector<face_t *> intersected_faces;
+ std::vector<edge_t *> intersected_edges;
+ std::vector<vertex_t *> intersected_vertices;
+
+ collect(v, &intersected_vertices, &intersected_edges, &intersected_faces);
+
+ for (unsigned i = 0; i < intersected_vertices.size(); ++i) {
+ facesForVertex(intersected_vertices[i], f);
+ }
+ for (unsigned i = 0; i < intersected_edges.size(); ++i) {
+ facesForEdge(intersected_edges[i], f);
+ }
+ f.insert(intersected_faces.begin(), intersected_faces.end());
+ }
+
+ /**
+ * \brief Collect the set of faces that contain all vertices in \a verts.
+ *
+ * @tparam vertex_set_t A collection type holding vertex_t *
+ * @tparam face_set_t A collection type holding face_t *
+ * @param[in] verts A set of vertices.
+ * @param[out] result The resulting set of faces.
+ */
+ template<typename vertex_set_t, typename face_set_t>
+ void commonFaces(const vertex_set_t &verts, face_set_t &result) {
+
+ std::set<face_t *> ifaces, temp, out;
+ typename vertex_set_t::const_iterator i = verts.begin();
+ if (i == verts.end()) return;
+ intersectedFaces((*i), ifaces);
+ while (++i != verts.end()) {
+ temp.clear();
+ intersectedFaces((*i), temp);
+
+ out.clear();
+ std::set_intersection(temp.begin(), temp.end(),
+ ifaces.begin(), ifaces.end(),
+ set_inserter(out));
+ ifaces.swap(out);
+ }
+ std::copy(ifaces.begin(), ifaces.end(), set_inserter(result));
+ }
+
+ void clear() {
+ super::clear();
+ }
+
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/iobj.hpp b/extern/carve/include/carve/iobj.hpp
new file mode 100644
index 00000000000..13d88ec820b
--- /dev/null
+++ b/extern/carve/include/carve/iobj.hpp
@@ -0,0 +1,106 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+namespace carve {
+ namespace csg {
+ struct IObj {
+ enum {
+ OBTYPE_NONE = 0,
+ OBTYPE_VERTEX = 1,
+ OBTYPE_EDGE = 2,
+ OBTYPE_FACE = 4
+ } obtype;
+
+ union {
+ carve::mesh::MeshSet<3>::vertex_t *vertex;
+ carve::mesh::MeshSet<3>::edge_t *edge;
+ carve::mesh::MeshSet<3>::face_t *face;
+ intptr_t val;
+ };
+
+ IObj() : obtype(OBTYPE_NONE), val(0) { }
+ IObj(carve::mesh::MeshSet<3>::vertex_t *v) : obtype(OBTYPE_VERTEX), vertex(v) { }
+ IObj(carve::mesh::MeshSet<3>::edge_t *e) : obtype(OBTYPE_EDGE), edge(e) { }
+ IObj(carve::mesh::MeshSet<3>::face_t *f) : obtype(OBTYPE_FACE), face(f) { }
+ char typeChar() const { return "NVExF"[obtype]; }
+ };
+
+
+
+ struct IObj_hash {
+ inline size_t operator()(const IObj &i) const {
+ return (size_t)i.val;
+ }
+ inline size_t operator()(const std::pair<const IObj, const IObj> &i) const {
+ return (size_t)i.first.val ^ (size_t)i.second.val;
+ }
+ };
+
+
+
+ typedef std::unordered_set<std::pair<const IObj, const IObj>, IObj_hash> IObjPairSet;
+
+ typedef std::unordered_map<IObj, carve::mesh::MeshSet<3>::vertex_t *, IObj_hash> IObjVMap;
+ typedef std::map<IObj, carve::mesh::MeshSet<3>::vertex_t *> IObjVMapSmall;
+
+ class VertexIntersections :
+ public std::unordered_map<carve::mesh::MeshSet<3>::vertex_t *, IObjPairSet> {
+ };
+
+
+
+ static inline bool operator==(const carve::csg::IObj &a, const carve::csg::IObj &b) {
+ return a.obtype == b.obtype && a.val == b.val;
+ }
+
+ static inline bool operator!=(const carve::csg::IObj &a, const carve::csg::IObj &b) {
+ return a.obtype != b.obtype || a.val != b.val;
+ }
+
+ static inline bool operator<(const carve::csg::IObj &a, const carve::csg::IObj &b) {
+ return a.obtype < b.obtype || (a.obtype == b.obtype && a.val < b.val);
+ }
+
+ static inline bool operator<=(const carve::csg::IObj &a, const carve::csg::IObj &b) {
+ return a.obtype < b.obtype || (a.obtype == b.obtype && a.val <= b.val);
+ }
+
+ static inline bool operator>(const carve::csg::IObj &a, const carve::csg::IObj &b) {
+ return a.obtype > b.obtype || (a.obtype == b.obtype && a.val > b.val);
+ }
+
+ static inline bool operator>=(const carve::csg::IObj &a, const carve::csg::IObj &b) {
+ return a.obtype > b.obtype || (a.obtype == b.obtype && a.val >= b.val);
+ }
+
+ static inline std::ostream &operator<<(std::ostream &o, const carve::csg::IObj &a) {
+ switch (a.obtype) {
+ case carve::csg::IObj::OBTYPE_NONE: o << "NONE{}"; break;
+ case carve::csg::IObj::OBTYPE_VERTEX: o << "VERT{" << a.vertex << "}"; break;
+ case carve::csg::IObj::OBTYPE_EDGE: o << "EDGE{" << a.edge << "}"; break;
+ case carve::csg::IObj::OBTYPE_FACE: o << "FACE{" << a.face << "}"; break;
+ }
+ return o;
+ }
+
+ }
+}
+
diff --git a/extern/carve/include/carve/kd_node.hpp b/extern/carve/include/carve/kd_node.hpp
new file mode 100644
index 00000000000..f62584d50c2
--- /dev/null
+++ b/extern/carve/include/carve/kd_node.hpp
@@ -0,0 +1,308 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/geom.hpp>
+#include <carve/aabb.hpp>
+
+#include <queue>
+#include <list>
+#include <limits>
+
+namespace carve {
+ namespace geom {
+ template<unsigned ndim,
+ typename data_t,
+ typename inserter_t,
+ typename aabb_calc_t>
+ class kd_node {
+ kd_node(const kd_node &);
+ kd_node &operator=(const kd_node &);
+
+ public:
+ kd_node *c_neg;
+ kd_node *c_pos;
+ kd_node *parent;
+ axis_pos splitpos;
+
+ typedef vector<ndim> vector_t;
+ typedef std::list<data_t> container_t;
+
+ container_t data;
+
+ kd_node(kd_node *_parent = NULL) : c_neg(NULL), c_pos(NULL), parent(_parent), splitpos(0, 0.0) {
+ }
+
+ ~kd_node() {
+ if (c_neg) delete c_neg;
+ if (c_pos) delete c_pos;
+ }
+
+ template<typename visitor_t>
+ void closeNodes(const vector_t &p, double d, visitor_t &visit) const {
+ if (c_neg) {
+ double delta = splitpos.pos - p[splitpos.axis];
+ if (delta <= d) c_neg->closeNodes(p, d, visit);
+ if (delta >= -d) c_pos->closeNodes(p, d, visit);
+ } else {
+ visit(this);
+ }
+ }
+
+ void removeData(const data_t &d) {
+ typename container_t::iterator i = std::find(data.begin(), data.end(), d);
+
+ if (i != data.end()) {
+ data.erase(i);
+ }
+ }
+
+ void addData(const data_t &d) {
+ data.push_back(d);
+ }
+
+ void insert(const data_t &data, inserter_t &inserter) {
+ inserter.insert(this, data);
+ }
+
+ void insert(const data_t &data) {
+ inserter_t inserter;
+ insert(data, inserter);
+ }
+
+ void remove(const data_t &data, inserter_t &inserter) {
+ inserter.remove(this, data);
+ }
+
+ void remove(const data_t &data) {
+ inserter_t inserter;
+ remove(data, inserter);
+ }
+
+ carve::geom::aabb<ndim> nodeAABB() const {
+ carve::geom::aabb<ndim> aabb;
+ if (c_neg) {
+ aabb = c_neg->nodeAABB();
+ aabb.unionAABB(c_pos->nodeAABB());
+ } else {
+ if (data.size()) {
+ typename container_t::const_iterator i = data.begin();
+ aabb = aabb_calc_t()(*i);
+ while (i != data.end()) {
+ aabb.unionAABB(aabb_calc_t()(*i));
+ ++i;
+ }
+ }
+ }
+ return aabb;
+ }
+
+ bool split(axis_pos split_at, inserter_t &inserter) {
+ if (c_neg) {
+ // already split
+ return false;
+ }
+
+ c_neg = new kd_node(this);
+ c_pos = new kd_node(this);
+
+ // choose an axis and split point.
+ splitpos = split_at;
+
+ carve::geom::aabb<ndim> aabb;
+
+ if (splitpos.axis < 0 ||
+ splitpos.axis >= ndim ||
+ splitpos.pos == std::numeric_limits<double>::max()) {
+ // need an aabb
+ if (data.size()) {
+ typename container_t::const_iterator i = data.begin();
+ aabb = aabb_calc_t()(*i);
+ while (i != data.end()) {
+ aabb.unionAABB(aabb_calc_t()(*i));
+ ++i;
+ }
+ }
+ }
+
+ if (splitpos.axis < 0 || splitpos.axis >= ndim) {
+
+ // choose an axis;
+
+ // if no axis was specified, force calculation of the split position.
+ splitpos.pos = std::numeric_limits<double>::max();
+
+ // choose the axis of the AABB with the biggest extent.
+ splitpos.axis = largestAxis(aabb.extent);
+
+ if (parent && splitpos.axis == parent->splitpos.axis) {
+ // but don't choose the same axis as the parent node;
+ // choose the axis with the second greatest AABB extent.
+ double e = -1.0;
+ int a = -1;
+ for (unsigned i = 0; i < ndim; ++i) {
+ if (i == splitpos.axis) continue;
+ if (e < aabb.extent[i]) { a = i; e = aabb.extent[i]; }
+ }
+ if (a != -1) {
+ splitpos.axis = a;
+ }
+ }
+ }
+
+ if (splitpos.pos == std::numeric_limits<double>::max()) {
+ carve::geom::vector<ndim> min = aabb.min();
+ carve::geom::vector<ndim> max = aabb.max();
+ splitpos.pos = aabb.pos.v[splitpos.axis];
+ }
+
+ inserter.propagate(this);
+
+ return true;
+ }
+
+ bool split(axis_pos split_at = axis_pos(-1, std::numeric_limits<double>::max())) {
+ inserter_t inserter;
+ return split(split_at, inserter);
+ }
+
+ void splitn(int num, inserter_t &inserter) {
+ if (num <= 0) return;
+ if (!c_neg) {
+ split(inserter);
+ }
+ if (c_pos) c_pos->splitn(num-1, inserter);
+ if (c_neg) c_neg->splitn(num-1, inserter);
+ }
+
+ void splitn(int num) {
+ inserter_t inserter;
+ splitn(num, inserter);
+ }
+
+ template<typename split_t>
+ void splitn(int num, split_t splitter, inserter_t &inserter) {
+ if (num <= 0) return;
+ if (!c_neg) {
+ split(inserter, splitter(this));
+ }
+ if (c_pos) c_pos->splitn(num-1, inserter, splitter);
+ if (c_neg) c_neg->splitn(num-1, inserter, splitter);
+ }
+
+ template<typename split_t>
+ void splitn(int num, split_t splitter) {
+ inserter_t inserter;
+ splitn(num, splitter, inserter);
+ }
+
+ template<typename pred_t>
+ void splitpred(pred_t pred, inserter_t &inserter, int depth = 0) {
+ if (!c_neg) {
+ axis_pos splitpos(-1, std::numeric_limits<double>::max());
+ if (!pred(this, depth, splitpos)) return;
+ split(splitpos, inserter);
+ }
+ if (c_pos) c_pos->splitpred(pred, inserter, depth + 1);
+ if (c_neg) c_neg->splitpred(pred, inserter, depth + 1);
+ }
+
+ template<typename pred_t>
+ void splitpred(pred_t pred, int depth = 0) {
+ inserter_t inserter;
+ splitpred(pred, inserter, depth);
+ }
+
+ // distance_t must provide:
+ // double operator()(kd_node::data_t, vector<ndim>);
+ // double operator()(axis_pos, vector<ndim>);
+ template<typename distance_t>
+ struct near_point_query {
+
+ // q_t - the priority queue value type.
+ // q_t.first: distance from object to query point.
+ // q_t.second: pointer to object
+ typedef std::pair<double, const typename kd_node::data_t *> q_t;
+
+ // the queue priority should sort from smallest distance to largest, and on equal distance, by object pointer.
+ struct pcmp {
+ bool operator()(const q_t &a, const q_t &b) {
+ return (a.first > b.first) || ((a.first == b.first) && (a.second < b.second));
+ }
+ };
+
+ vector<ndim> point;
+ const kd_node *node;
+ std::priority_queue<q_t, std::vector<q_t>, pcmp> pq;
+
+ distance_t dist;
+ double dist_to_parent_split;
+
+ void addToPQ(kd_node *node) {
+ if (node->c_neg) {
+ addToPQ(node->c_neg);
+ addToPQ(node->c_pos);
+ } else {
+ for (typename kd_node::container_t::const_iterator i = node->data.begin(); i != node->data.end(); ++i) {
+ double d = dist((*i), point);
+ pq.push(std::make_pair(d, &(*i)));
+ }
+ }
+ }
+
+ const typename kd_node::data_t *next() {
+ while (1) {
+ if (pq.size()) {
+ q_t t = pq.top();
+ if (!node->parent || t.first < dist_to_parent_split) {
+ pq.pop();
+ return t.second;
+ }
+ }
+
+ if (!node->parent) return NULL;
+
+ if (node->parent->c_neg == node) {
+ addToPQ(node->parent->c_pos);
+ } else {
+ addToPQ(node->parent->c_neg);
+ }
+
+ node = node->parent;
+ dist_to_parent_split = dist(node->splitpos, point);
+ }
+ }
+
+ near_point_query(const vector<ndim> _point, const kd_node *_node) : point(_point), node(_node), pq(), dist() {
+ while (node->c_neg) {
+ node = (point[node->axis] < node->pos) ? node->c_neg : node->c_pos;
+ }
+ if (node->parent) {
+ dist_to_parent_split = dist(node->parent->splitpos, point);
+ } else {
+ dist_to_parent_split = HUGE_VAL;
+ }
+ addToPQ(node);
+ }
+ };
+
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/math.hpp b/extern/carve/include/carve/math.hpp
new file mode 100644
index 00000000000..ec9ff0a9663
--- /dev/null
+++ b/extern/carve/include/carve/math.hpp
@@ -0,0 +1,60 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/math_constants.hpp>
+
+#include <math.h>
+
+namespace carve {
+ namespace geom {
+ template<unsigned ndim> struct vector;
+ }
+}
+
+namespace carve {
+ namespace math {
+ struct Matrix3;
+ int cubic_roots(double c3, double c2, double c1, double c0, double *roots);
+
+ void eigSolveSymmetric(const Matrix3 &m,
+ double &l1, carve::geom::vector<3> &e1,
+ double &l2, carve::geom::vector<3> &e2,
+ double &l3, carve::geom::vector<3> &e3);
+
+ void eigSolve(const Matrix3 &m, double &l1, double &l2, double &l3);
+
+ static inline bool ZERO(double x) { return fabs(x) < carve::EPSILON; }
+
+ static inline double radians(double deg) { return deg * M_PI / 180.0; }
+ static inline double degrees(double rad) { return rad * 180.0 / M_PI; }
+
+ static inline double ANG(double x) {
+ return (x < 0) ? x + M_TWOPI : x;
+ }
+
+ template<typename T>
+ static inline const T &clamp(const T &val, const T &min, const T &max) {
+ if (val < min) return min;
+ if (val > max) return max;
+ return val;
+ }
+ }
+}
diff --git a/extern/carve/include/carve/math_constants.hpp b/extern/carve/include/carve/math_constants.hpp
new file mode 100644
index 00000000000..9d2c4fe0a46
--- /dev/null
+++ b/extern/carve/include/carve/math_constants.hpp
@@ -0,0 +1,33 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <math.h>
+
+#ifndef M_SQRT_3
+#define M_SQRT_3 1.73205080756887729352
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#ifndef M_TWOPI
+#define M_TWOPI (M_PI + M_PI)
+#endif
+
diff --git a/extern/carve/include/carve/matrix.hpp b/extern/carve/include/carve/matrix.hpp
new file mode 100644
index 00000000000..feb0cd72b97
--- /dev/null
+++ b/extern/carve/include/carve/matrix.hpp
@@ -0,0 +1,262 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <cstring>
+
+#include <carve/carve.hpp>
+
+#include <carve/math.hpp>
+#include <carve/geom.hpp>
+
+namespace carve {
+ namespace math {
+
+ struct Quaternion {
+ double x, y, z, w;
+
+ Quaternion(double _x, double _y, double _z, double _w) : x(_x), y(_y), z(_z), w(_w) {
+ }
+
+ Quaternion(double angle, const carve::geom::vector<3> &axis) {
+ double s = axis.length();
+ if (!carve::math::ZERO(s)) {
+ double c = 1.0 / s;
+ double omega = -0.5 * angle;
+ s = sin(omega);
+ x = axis.x * c * s;
+ y = axis.y * c * s;
+ z = axis.z * c * s;
+ w = cos(omega);
+ normalize();
+ } else {
+ x = y = z = 0.0;
+ w = 1.0;
+ }
+ }
+
+ double lengthSquared() const {
+ return x * x + y * y + z * z + w * w;
+ }
+
+ double length() const {
+ return sqrt(lengthSquared());
+ }
+
+ Quaternion normalized() const {
+ return Quaternion(*this).normalize();
+ }
+
+ Quaternion &normalize() {
+ double l = length();
+ if (l == 0.0) {
+ x = 1.0; y = 0.0; z = 0.0; w = 0.0;
+ } else {
+ x /= l; y /= l; z /= l; w /= l;
+ }
+ return *this;
+ }
+ };
+
+ struct Matrix3 {
+ // access: .m[col][row], .v[col * 4 + row], ._cr
+ union {
+ double m[3][3];
+ double v[9];
+ struct {
+ // transposed
+ double _11, _12, _13;
+ double _21, _22, _23;
+ double _31, _32, _33;
+ };
+ };
+ Matrix3(double __11, double __21, double __31,
+ double __12, double __22, double __32,
+ double __13, double __23, double __33) {
+ // nb, args are row major, storage is column major.
+ _11 = __11; _12 = __12; _13 = __13;
+ _21 = __21; _22 = __22; _23 = __23;
+ _31 = __31; _32 = __32; _33 = __33;
+ }
+ Matrix3(double _m[3][3]) {
+ std::memcpy(m, _m, sizeof(m));
+ }
+ Matrix3(double _v[9]) {
+ std::memcpy(v, _v, sizeof(v));
+ }
+ Matrix3() {
+ _11 = 1.00; _12 = 0.00; _13 = 0.00;
+ _21 = 0.00; _22 = 1.00; _23 = 0.00;
+ _31 = 0.00; _32 = 0.00; _33 = 1.00;
+ }
+ };
+
+ struct Matrix {
+ // access: .m[col][row], .v[col * 4 + row], ._cr
+ union {
+ double m[4][4];
+ double v[16];
+ struct {
+ // transposed
+ double _11, _12, _13, _14;
+ double _21, _22, _23, _24;
+ double _31, _32, _33, _34;
+ double _41, _42 ,_43, _44;
+ };
+ };
+ Matrix(double __11, double __21, double __31, double __41,
+ double __12, double __22, double __32, double __42,
+ double __13, double __23, double __33, double __43,
+ double __14, double __24, double __34, double __44) {
+ // nb, args are row major, storage is column major.
+ _11 = __11; _12 = __12; _13 = __13; _14 = __14;
+ _21 = __21; _22 = __22; _23 = __23; _24 = __24;
+ _31 = __31; _32 = __32; _33 = __33; _34 = __34;
+ _41 = __41; _42 = __42; _43 = __43; _44 = __44;
+ }
+ Matrix(double _m[4][4]) {
+ std::memcpy(m, _m, sizeof(m));
+ }
+ Matrix(double _v[16]) {
+ std::memcpy(v, _v, sizeof(v));
+ }
+ Matrix() {
+ _11 = 1.00; _12 = 0.00; _13 = 0.00; _14 = 0.00;
+ _21 = 0.00; _22 = 1.00; _23 = 0.00; _24 = 0.00;
+ _31 = 0.00; _32 = 0.00; _33 = 1.00; _34 = 0.00;
+ _41 = 0.00; _42 = 0.00; _43 = 0.00; _44 = 1.00;
+ }
+
+ static Matrix ROT(const Quaternion &q) {
+ const double w = q.w;
+ const double x = q.x;
+ const double y = q.y;
+ const double z = q.z;
+ return Matrix(1 - 2*y*y - 2*z*z, 2*x*y - 2*z*w, 2*x*z + 2*y*w, 0.0,
+ 2*x*y + 2*z*w, 1 - 2*x*x - 2*z*z, 2*y*z - 2*x*w, 0.0,
+ 2*x*z - 2*y*w, 2*y*z + 2*x*w, 1 - 2*x*x - 2*y*y, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+ }
+ static Matrix ROT(double angle, const carve::geom::vector<3> &axis) {
+ return ROT(Quaternion(angle, axis));
+ }
+ static Matrix ROT(double angle, double x, double y, double z) {
+ return ROT(Quaternion(angle, carve::geom::VECTOR(x, y, z)));
+ }
+ static Matrix TRANS(double x, double y, double z) {
+ return Matrix(1.0, 0.0, 0.0, x,
+ 0.0, 1.0, 0.0, y,
+ 0.0, 0.0, 1.0, z,
+ 0.0, 0.0, 0.0, 1.0);
+ }
+ static Matrix TRANS(const carve::geom::vector<3> &v) {
+ return TRANS(v.x, v.y, v.z);
+ }
+ static Matrix SCALE(double x, double y, double z) {
+ return Matrix(x, 0.0, 0.0, 0.0,
+ 0.0, y, 0.0, 0.0,
+ 0.0, 0.0, z, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+ }
+ static Matrix SCALE(const carve::geom::vector<3> &v) {
+ return SCALE(v.x, v.y, v.z);
+ }
+ static Matrix IDENT() {
+ return Matrix(1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+ }
+ };
+
+ static inline bool operator==(const Matrix &A, const Matrix &B) {
+ for (size_t i = 0; i < 16; ++i) if (A.v[i] != B.v[i]) return false;
+ return true;
+ }
+ static inline bool operator!=(const Matrix &A, const Matrix &B) {
+ return !(A == B);
+ }
+ static inline carve::geom::vector<3> operator*(const Matrix &A, const carve::geom::vector<3> &b) {
+ return carve::geom::VECTOR(
+ A._11 * b.x + A._21 * b.y + A._31 * b.z + A._41,
+ A._12 * b.x + A._22 * b.y + A._32 * b.z + A._42,
+ A._13 * b.x + A._23 * b.y + A._33 * b.z + A._43
+ );
+ }
+
+ static inline carve::geom::vector<3> &operator*=(carve::geom::vector<3> &b, const Matrix &A) {
+ b = A * b;
+ return b;
+ }
+
+ static inline carve::geom::vector<3> operator*(const Matrix3 &A, const carve::geom::vector<3> &b) {
+ return carve::geom::VECTOR(
+ A._11 * b.x + A._21 * b.y + A._31 * b.z,
+ A._12 * b.x + A._22 * b.y + A._32 * b.z,
+ A._13 * b.x + A._23 * b.y + A._33 * b.z
+ );
+ }
+
+ static inline carve::geom::vector<3> &operator*=(carve::geom::vector<3> &b, const Matrix3 &A) {
+ b = A * b;
+ return b;
+ }
+
+ static inline Matrix operator*(const Matrix &A, const Matrix &B) {
+ Matrix c;
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ c.m[i][j] = 0.0;
+ for (int k = 0; k < 4; k++) {
+ c.m[i][j] += A.m[k][j] * B.m[i][k];
+ }
+ }
+ }
+ return c;
+ }
+
+ static inline Matrix3 operator*(const Matrix3 &A, const Matrix3 &B) {
+ Matrix3 c;
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ c.m[i][j] = 0.0;
+ for (int k = 0; k < 3; k++) {
+ c.m[i][j] += A.m[k][j] * B.m[i][k];
+ }
+ }
+ }
+ return c;
+ }
+
+
+
+ struct matrix_transformation {
+ Matrix matrix;
+
+ matrix_transformation(const Matrix &_matrix) : matrix(_matrix) {
+ }
+
+ carve::geom::vector<3> operator()(const carve::geom::vector<3> &vector) const {
+ return matrix * vector;
+ }
+ };
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/mesh.hpp b/extern/carve/include/carve/mesh.hpp
new file mode 100644
index 00000000000..d4170e55133
--- /dev/null
+++ b/extern/carve/include/carve/mesh.hpp
@@ -0,0 +1,845 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/tag.hpp>
+#include <carve/djset.hpp>
+#include <carve/aabb.hpp>
+#include <carve/rtree.hpp>
+
+#include <iostream>
+
+namespace carve {
+ namespace poly {
+ class Polyhedron;
+ }
+
+ namespace mesh {
+
+
+ template<unsigned ndim> class Edge;
+ template<unsigned ndim> class Face;
+ template<unsigned ndim> class Mesh;
+ template<unsigned ndim> class MeshSet;
+
+
+
+ // A Vertex may participate in several meshes. If the Mesh belongs
+ // to a MeshSet, then the vertices come from the vertex_storage
+ // member of the MeshSet. This allows one to construct one or more
+ // Meshes out of sets of connected faces (possibly using vertices
+ // from a variety of MeshSets, and other storage), then create a
+ // MeshSet from the Mesh(es), causing the vertices to be
+ // collected, cloned and repointed into the MeshSet.
+
+ // Normally, in a half-edge structure, Vertex would have a member
+ // pointing to an incident edge, allowing the enumeration of
+ // adjacent faces and edges. Because we want to support vertex
+ // sharing between Meshes and groups of Faces, this is made more
+ // complex. If Vertex contained a list of incident edges, one from
+ // each disjoint face set, then this could be done (with the
+ // caveat that you'd need to pass in a Mesh pointer to the
+ // adjacency queries). However, it seems that this would
+ // unavoidably complicate the process of incorporating or removing
+ // a vertex into an edge.
+
+ // In most cases it is expected that a vertex will be arrived at
+ // via an edge or face in the mesh (implicit or explicit) of
+ // interest, so not storing this information will not hurt,
+ // overly.
+ template<unsigned ndim>
+ class Vertex : public tagable {
+ public:
+ typedef carve::geom::vector<ndim> vector_t;
+ typedef MeshSet<ndim> owner_t;
+ typedef carve::geom::aabb<ndim> aabb_t;
+
+ carve::geom::vector<ndim> v;
+
+ Vertex(const vector_t &_v) : tagable(), v(_v) {
+ }
+
+ Vertex() : tagable(), v() {
+ }
+
+ aabb_t getAABB() const {
+ return aabb_t(v, carve::geom::vector<ndim>::ZERO());
+ }
+ };
+
+
+
+ struct hash_vertex_pair {
+ template<unsigned ndim>
+ size_t operator()(const std::pair<Vertex<ndim> *, Vertex<ndim> *> &pair) const {
+ size_t r = (size_t)pair.first;
+ size_t s = (size_t)pair.second;
+ return r ^ ((s >> 16) | (s << 16));
+ }
+ template<unsigned ndim>
+ size_t operator()(const std::pair<const Vertex<ndim> *, const Vertex<ndim> *> &pair) const {
+ size_t r = (size_t)pair.first;
+ size_t s = (size_t)pair.second;
+ return r ^ ((s >> 16) | (s << 16));
+ }
+ };
+
+
+
+ struct vertex_distance {
+ template<unsigned ndim>
+ double operator()(const Vertex<ndim> &a, const Vertex<ndim> &b) const {
+ return carve::geom::distance(a.v, b.v);
+ }
+
+ template<unsigned ndim>
+ double operator()(const Vertex<ndim> *a, const Vertex<ndim> *b) const {
+ return carve::geom::distance(a->v, b->v);
+ }
+ };
+
+
+
+ namespace detail {
+ template<typename list_t> struct list_iter_t;
+ template<typename list_t, typename mapping_t> struct mapped_list_iter_t;
+ }
+
+
+
+ // The half-edge structure proper (Edge) is maintained by Face
+ // instances. Together with Face instances, the half-edge
+ // structure defines a simple mesh (either one or two faces
+ // incident on each edge).
+ template<unsigned ndim>
+ class Edge : public tagable {
+ public:
+ typedef Vertex<ndim> vertex_t;
+ typedef Face<ndim> face_t;
+
+ vertex_t *vert;
+ face_t *face;
+ Edge *prev, *next, *rev;
+
+ private:
+ static void _link(Edge *a, Edge *b) {
+ a->next = b; b->prev = a;
+ }
+
+ static void _freeloop(Edge *s) {
+ Edge *e = s;
+ do {
+ Edge *n = e->next;
+ delete e;
+ e = n;
+ } while (e != s);
+ }
+
+ static void _setloopface(Edge *s, face_t *f) {
+ Edge *e = s;
+ do {
+ e->face = f;
+ e = e->next;
+ } while (e != s);
+ }
+
+ static size_t _looplen(Edge *s) {
+ Edge *e = s;
+ face_t *f = s->face;
+ size_t c = 0;
+ do {
+ ++c;
+ CARVE_ASSERT(e->rev->rev == e);
+ CARVE_ASSERT(e->next->prev == e);
+ CARVE_ASSERT(e->face == f);
+ e = e->next;
+ } while (e != s);
+ return c;
+ }
+
+ public:
+ void validateLoop() {
+ Edge *e = this;
+ face_t *f = face;
+ size_t c = 0;
+ do {
+ ++c;
+ CARVE_ASSERT(e->rev == NULL || e->rev->rev == e);
+ CARVE_ASSERT(e->next == e || e->next->vert != e->vert);
+ CARVE_ASSERT(e->prev == e || e->prev->vert != e->vert);
+ CARVE_ASSERT(e->next->prev == e);
+ CARVE_ASSERT(e->prev->next == e);
+ CARVE_ASSERT(e->face == f);
+ e = e->next;
+ } while (e != this);
+ CARVE_ASSERT(f == NULL || c == f->n_edges);
+ }
+
+ size_t loopLen() {
+ return _looplen(this);
+ }
+
+ Edge *mergeFaces();
+
+ Edge *removeHalfEdge();
+
+ // Remove and delete this edge.
+ Edge *removeEdge();
+
+ // Unlink this edge from its containing edge loop. disconnect
+ // rev links. The rev links of the previous edge also change, as
+ // its successor vertex changes.
+ void unlink();
+
+ // Insert this edge into a loop before other. If edge was
+ // already in a loop, it needs to be removed first.
+ void insertBefore(Edge *other);
+
+ // Insert this edge into a loop after other. If edge was
+ // already in a loop, it needs to be removed first.
+ void insertAfter(Edge *other);
+
+ size_t loopSize() const;
+
+ vertex_t *v1() { return vert; }
+ vertex_t *v2() { return next->vert; }
+
+ const vertex_t *v1() const { return vert; }
+ const vertex_t *v2() const { return next->vert; }
+
+ Edge *perimNext() const;
+ Edge *perimPrev() const;
+
+ double length2() const {
+ return (v1()->v - v2()->v).length2();
+ }
+
+ double length() const {
+ return (v1()->v - v2()->v).length();
+ }
+
+ Edge(vertex_t *_vert, face_t *_face);
+
+ ~Edge();
+ };
+
+
+
+ // A Face contains a pointer to the beginning of the half-edge
+ // circular list that defines its boundary.
+ template<unsigned ndim>
+ class Face : public tagable {
+ public:
+ typedef Vertex<ndim> vertex_t;
+ typedef Edge<ndim> edge_t;
+ typedef Mesh<ndim> mesh_t;
+
+ typedef typename Vertex<ndim>::vector_t vector_t;
+ typedef carve::geom::aabb<ndim> aabb_t;
+ typedef carve::geom::plane<ndim> plane_t;
+ typedef carve::geom::vector<2> (*project_t)(const vector_t &);
+ typedef vector_t (*unproject_t)(const carve::geom::vector<2> &, const plane_t &);
+
+ struct vector_mapping {
+ typedef typename vertex_t::vector_t value_type;
+
+ value_type operator()(const carve::geom::vector<ndim> &v) const { return v; }
+ value_type operator()(const carve::geom::vector<ndim> *v) const { return *v; }
+ value_type operator()(const Edge<ndim> &e) const { return e.vert->v; }
+ value_type operator()(const Edge<ndim> *e) const { return e->vert->v; }
+ value_type operator()(const Vertex<ndim> &v) const { return v.v; }
+ value_type operator()(const Vertex<ndim> *v) const { return v->v; }
+ };
+
+ struct projection_mapping {
+ typedef carve::geom::vector<2> value_type;
+ project_t proj;
+ projection_mapping(project_t _proj) : proj(_proj) { }
+ value_type operator()(const carve::geom::vector<ndim> &v) const { return proj(v); }
+ value_type operator()(const carve::geom::vector<ndim> *v) const { return proj(*v); }
+ value_type operator()(const Edge<ndim> &e) const { return proj(e.vert->v); }
+ value_type operator()(const Edge<ndim> *e) const { return proj(e->vert->v); }
+ value_type operator()(const Vertex<ndim> &v) const { return proj(v.v); }
+ value_type operator()(const Vertex<ndim> *v) const { return proj(v->v); }
+ };
+
+ edge_t *edge;
+ size_t n_edges;
+ mesh_t *mesh;
+ size_t id;
+
+ plane_t plane;
+ project_t project;
+ unproject_t unproject;
+
+ private:
+ Face &operator=(const Face &other);
+
+ protected:
+ Face() : edge(NULL), n_edges(0), mesh(NULL), id(0), plane(), project(NULL), unproject(NULL) {
+ }
+
+ Face(const Face &other) :
+ edge(NULL), n_edges(other.n_edges), mesh(NULL), id(other.id),
+ plane(other.plane), project(other.project), unproject(other.unproject) {
+ }
+
+ project_t getProjector(bool positive_facing, int axis) const;
+ unproject_t getUnprojector(bool positive_facing, int axis) const;
+
+ public:
+ typedef detail::list_iter_t<Edge<ndim> > edge_iter_t;
+ typedef detail::list_iter_t<const Edge<ndim> > const_edge_iter_t;
+
+ edge_iter_t begin() { return edge_iter_t(edge, 0); }
+ edge_iter_t end() { return edge_iter_t(edge, n_edges); }
+
+ const_edge_iter_t begin() const { return const_edge_iter_t(edge, 0); }
+ const_edge_iter_t end() const { return const_edge_iter_t(edge, n_edges); }
+
+ bool containsPoint(const vector_t &p) const;
+ bool containsPointInProjection(const vector_t &p) const;
+ bool simpleLineSegmentIntersection(
+ const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const;
+ IntersectionClass lineSegmentIntersection(
+ const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const;
+
+ aabb_t getAABB() const;
+
+ bool recalc();
+
+ void clearEdges();
+
+ // build an edge loop in forward orientation from an iterator pair
+ template<typename iter_t>
+ void loopFwd(iter_t vbegin, iter_t vend);
+
+ // build an edge loop in reverse orientation from an iterator pair
+ template<typename iter_t>
+ void loopRev(iter_t vbegin, iter_t vend);
+
+ // initialize a face from an ordered list of vertices.
+ template<typename iter_t>
+ void init(iter_t begin, iter_t end);
+
+ // initialization of a triangular face.
+ void init(vertex_t *a, vertex_t *b, vertex_t *c);
+
+ // initialization of a quad face.
+ void init(vertex_t *a, vertex_t *b, vertex_t *c, vertex_t *d);
+
+ void getVertices(std::vector<vertex_t *> &verts) const;
+ void getProjectedVertices(std::vector<carve::geom::vector<2> > &verts) const;
+
+ projection_mapping projector() const {
+ return projection_mapping(project);
+ }
+
+ std::pair<double, double> rangeInDirection(const vector_t &v, const vector_t &b) const {
+ edge_t *e = edge;
+ double lo, hi;
+ lo = hi = carve::geom::dot(v, e->vert->v - b);
+ e = e->next;
+ for (; e != edge; e = e->next) {
+ double d = carve::geom::dot(v, e->vert->v - b);
+ lo = std::min(lo, d);
+ hi = std::max(hi, d);
+ }
+ return std::make_pair(lo, hi);
+ }
+
+ size_t nVertices() const {
+ return n_edges;
+ }
+
+ size_t nEdges() const {
+ return n_edges;
+ }
+
+ vector_t centroid() const;
+
+ static Face *closeLoop(edge_t *open_edge);
+
+ Face(edge_t *e) : edge(e), n_edges(0), mesh(NULL) {
+ do {
+ e->face = this;
+ n_edges++;
+ e = e->next;
+ } while (e != edge);
+ recalc();
+ }
+
+ Face(vertex_t *a, vertex_t *b, vertex_t *c) : edge(NULL), n_edges(0), mesh(NULL) {
+ init(a, b, c);
+ recalc();
+ }
+
+ Face(vertex_t *a, vertex_t *b, vertex_t *c, vertex_t *d) : edge(NULL), n_edges(0), mesh(NULL) {
+ init(a, b, c, d);
+ recalc();
+ }
+
+ template<typename iter_t>
+ Face(iter_t begin, iter_t end) : edge(NULL), n_edges(0), mesh(NULL) {
+ init(begin, end);
+ recalc();
+ }
+
+ template<typename iter_t>
+ Face *create(iter_t beg, iter_t end, bool reversed) const;
+
+ Face *clone(const vertex_t *old_base, vertex_t *new_base, std::unordered_map<const edge_t *, edge_t *> &edge_map) const;
+
+ void remove() {
+ edge_t *e = edge;
+ do {
+ if (e->rev) e->rev->rev = NULL;
+ e = e->next;
+ } while (e != edge);
+ }
+
+ void invert() {
+ // We invert the direction of the edges of the face in this
+ // way so that the edge rev pointers (if any) are still
+ // correct. It is expected that invert() will be called on
+ // every other face in the mesh, too, otherwise everything
+ // will get messed up.
+
+ {
+ // advance vertices.
+ edge_t *e = edge;
+ vertex_t *va = e->vert;
+ do {
+ e->vert = e->next->vert;
+ e = e->next;
+ } while (e != edge);
+ edge->prev->vert = va;
+ }
+
+ {
+ // swap prev and next pointers.
+ edge_t *e = edge;
+ do {
+ edge_t *n = e->next;
+ std::swap(e->prev, e->next);
+ e = n;
+ } while (e != edge);
+ }
+
+ plane.negate();
+
+ int da = carve::geom::largestAxis(plane.N);
+
+ project = getProjector(plane.N.v[da] > 0, da);
+ unproject = getUnprojector(plane.N.v[da] > 0, da);
+ }
+
+ void canonicalize();
+
+ ~Face() {
+ clearEdges();
+ }
+ };
+
+
+
+ namespace detail {
+ class FaceStitcher {
+ typedef Vertex<3> vertex_t;
+ typedef Edge<3> edge_t;
+ typedef Face<3> face_t;
+
+ typedef std::pair<const vertex_t *, const vertex_t *> vpair_t;
+ typedef std::list<edge_t *> edgelist_t;
+ typedef std::unordered_map<vpair_t, edgelist_t, carve::mesh::hash_vertex_pair> edge_map_t;
+ typedef std::unordered_map<const vertex_t *, std::set<const vertex_t *> > edge_graph_t;
+
+ edge_map_t edges;
+ edge_map_t complex_edges;
+
+ carve::djset::djset face_groups;
+ std::vector<bool> is_open;
+
+ edge_graph_t edge_graph;
+
+ struct EdgeOrderData {
+ size_t group_id;
+ bool is_reversed;
+ carve::geom::vector<3> face_dir;
+ edge_t *edge;
+
+ EdgeOrderData(edge_t *_edge, size_t _group_id, bool _is_reversed) :
+ group_id(_group_id),
+ is_reversed(_is_reversed) {
+ if (is_reversed) {
+ face_dir = -(_edge->face->plane.N);
+ } else {
+ face_dir = (_edge->face->plane.N);
+ }
+ edge = _edge;
+ }
+
+ struct TestGroups {
+ size_t fwd, rev;
+
+ TestGroups(size_t _fwd, size_t _rev) : fwd(_fwd), rev(_rev) {
+ }
+
+ bool operator()(const EdgeOrderData &eo) const {
+ return eo.group_id == (eo.is_reversed ? rev : fwd);
+ }
+ };
+
+ struct Cmp {
+ carve::geom::vector<3> edge_dir;
+ carve::geom::vector<3> base_dir;
+
+ Cmp(const carve::geom::vector<3> &_edge_dir,
+ const carve::geom::vector<3> &_base_dir) :
+ edge_dir(_edge_dir),
+ base_dir(_base_dir) {
+ }
+ bool operator()(const EdgeOrderData &a, const EdgeOrderData &b) const;
+ };
+ };
+
+ void extractConnectedEdges(std::vector<const vertex_t *>::iterator begin,
+ std::vector<const vertex_t *>::iterator end,
+ std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev);
+
+ size_t faceGroupID(const Face<3> *face);
+ size_t faceGroupID(const Edge<3> *edge);
+
+ void resolveOpenEdges();
+
+ void fuseEdges(std::vector<Edge<3> *> &fwd,
+ std::vector<Edge<3> *> &rev);
+
+ void joinGroups(std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev,
+ size_t fwd_grp,
+ size_t rev_grp);
+
+ void matchOrderedEdges(const std::vector<std::vector<EdgeOrderData> >::iterator begin,
+ const std::vector<std::vector<EdgeOrderData> >::iterator end,
+ std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev);
+
+ void reorder(std::vector<EdgeOrderData> &ordering, size_t fwd_grp);
+
+ void orderForwardAndReverseEdges(std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev,
+ std::vector<std::vector<EdgeOrderData> > &result);
+
+ void edgeIncidentGroups(const vpair_t &e,
+ const edge_map_t &all_edges,
+ std::pair<std::set<size_t>, std::set<size_t> > &groups);
+
+ void buildEdgeGraph(const edge_map_t &all_edges);
+ void extractPath(std::vector<const vertex_t *> &path);
+ void removePath(const std::vector<const vertex_t *> &path);
+ void matchSimpleEdges();
+ void construct();
+
+ template<typename iter_t>
+ void initEdges(iter_t begin, iter_t end);
+
+ template<typename iter_t>
+ void build(iter_t begin, iter_t end, std::vector<Mesh<3> *> &meshes);
+
+ public:
+ template<typename iter_t>
+ void create(iter_t begin, iter_t end, std::vector<Mesh<3> *> &meshes);
+ };
+ }
+
+
+
+ // A Mesh is a connected set of faces. It may be open (some edges
+ // have NULL rev members), or closed. On destruction, a Mesh
+ // should free its Faces (which will in turn free Edges, but not
+ // Vertices). A Mesh is edge-connected, which is to say that each
+ // face in the mesh shares an edge with at least one other face in
+ // the mesh. Touching at a vertex is not sufficient. This means
+ // that the perimeter of an open mesh visits each vertex no more
+ // than once.
+ template<unsigned ndim>
+ class Mesh {
+ public:
+ typedef Vertex<ndim> vertex_t;
+ typedef Edge<ndim> edge_t;
+ typedef Face<ndim> face_t;
+ typedef carve::geom::aabb<ndim> aabb_t;
+ typedef MeshSet<ndim> meshset_t;
+
+ std::vector<face_t *> faces;
+
+ // open_edges is a vector of all the edges in the mesh that
+ // don't have a matching edge in the opposite direction.
+ std::vector<edge_t *> open_edges;
+
+ // closed_edges is a vector of all the edges in the mesh that
+ // have a matching edge in the opposite direction, and whose
+ // address is lower than their counterpart. (i.e. for each pair
+ // of adjoining faces, one of the two half edges is stored in
+ // closed_edges).
+ std::vector<edge_t *> closed_edges;
+
+ bool is_negative;
+
+ meshset_t *meshset;
+
+ protected:
+ Mesh(std::vector<face_t *> &_faces,
+ std::vector<edge_t *> &_open_edges,
+ std::vector<edge_t *> &_closed_edges,
+ bool _is_negative);
+
+ public:
+ Mesh(std::vector<face_t *> &_faces);
+
+ ~Mesh();
+
+ template<typename iter_t>
+ static void create(iter_t begin, iter_t end, std::vector<Mesh<ndim> *> &meshes);
+
+ aabb_t getAABB() const {
+ return aabb_t(faces.begin(), faces.end());
+ }
+
+ bool isClosed() const {
+ return open_edges.size() == 0;
+ }
+
+ bool isNegative() const {
+ return is_negative;
+ }
+
+ double volume() const {
+ if (is_negative || !faces.size()) return 0.0;
+
+ double vol = 0.0;
+ typename vertex_t::vector_t origin = faces[0]->edge->vert->v;
+
+ for (size_t f = 0; f < faces.size(); ++f) {
+ face_t *face = faces[f];
+ edge_t *e1 = face->edge;
+ for (edge_t *e2 = e1->next ;e2->next != e1; e2 = e2->next) {
+ vol += carve::geom3d::tetrahedronVolume(e1->vert->v, e2->vert->v, e2->next->vert->v, origin);
+ }
+ }
+ return vol;
+ }
+
+ struct IsClosed {
+ bool operator()(const Mesh &mesh) const { return mesh.isClosed(); }
+ bool operator()(const Mesh *mesh) const { return mesh->isClosed(); }
+ };
+
+ struct IsNegative {
+ bool operator()(const Mesh &mesh) const { return mesh.isNegative(); }
+ bool operator()(const Mesh *mesh) const { return mesh->isNegative(); }
+ };
+
+ void cacheEdges();
+
+ void calcOrientation();
+
+ void recalc() {
+ for (size_t i = 0; i < faces.size(); ++i) faces[i]->recalc();
+ calcOrientation();
+ }
+
+ void invert() {
+ for (size_t i = 0; i < faces.size(); ++i) {
+ faces[i]->invert();
+ }
+ if (isClosed()) is_negative = !is_negative;
+ }
+
+ Mesh *clone(const vertex_t *old_base, vertex_t *new_base) const;
+ };
+
+ // A MeshSet manages vertex storage, and a collection of meshes.
+ // It should be easy to turn a vertex pointer into its index in
+ // its MeshSet vertex_storage.
+ template<unsigned ndim>
+ class MeshSet {
+ MeshSet();
+ MeshSet(const MeshSet &);
+ MeshSet &operator=(const MeshSet &);
+
+ template<typename iter_t>
+ void _init_from_faces(iter_t begin, iter_t end);
+
+ public:
+ typedef Vertex<ndim> vertex_t;
+ typedef Edge<ndim> edge_t;
+ typedef Face<ndim> face_t;
+ typedef Mesh<ndim> mesh_t;
+ typedef carve::geom::aabb<ndim> aabb_t;
+
+ std::vector<vertex_t> vertex_storage;
+ std::vector<mesh_t *> meshes;
+
+ public:
+ template<typename face_type>
+ struct FaceIter : public std::iterator<std::random_access_iterator_tag, face_type> {
+ typedef std::iterator<std::random_access_iterator_tag, face_type> super;
+ typedef typename super::difference_type difference_type;
+
+ const MeshSet<ndim> *obj;
+ size_t mesh, face;
+
+ FaceIter(const MeshSet<ndim> *_obj, size_t _mesh, size_t _face);
+
+ void fwd(size_t n);
+ void rev(size_t n);
+ void adv(int n);
+
+ FaceIter operator++(int) { FaceIter tmp = *this; tmp.fwd(1); return tmp; }
+ FaceIter operator+(int v) { FaceIter tmp = *this; tmp.adv(v); return tmp; }
+ FaceIter &operator++() { fwd(1); return *this; }
+ FaceIter &operator+=(int v) { adv(v); return *this; }
+
+ FaceIter operator--(int) { FaceIter tmp = *this; tmp.rev(1); return tmp; }
+ FaceIter operator-(int v) { FaceIter tmp = *this; tmp.adv(-v); return tmp; }
+ FaceIter &operator--() { rev(1); return *this; }
+ FaceIter &operator-=(int v) { adv(-v); return *this; }
+
+ difference_type operator-(const FaceIter &other) const;
+
+ bool operator==(const FaceIter &other) const {
+ return obj == other.obj && mesh == other.mesh && face == other.face;
+ }
+ bool operator!=(const FaceIter &other) const {
+ return !(*this == other);
+ }
+ bool operator<(const FaceIter &other) const {
+ CARVE_ASSERT(obj == other.obj);
+ return mesh < other.mesh || (mesh == other.mesh && face < other.face);
+ }
+ bool operator>(const FaceIter &other) const {
+ return other < *this;
+ }
+ bool operator<=(const FaceIter &other) const {
+ return !(other < *this);
+ }
+ bool operator>=(const FaceIter &other) const {
+ return !(*this < other);
+ }
+
+ face_type operator*() const {
+ return obj->meshes[mesh]->faces[face];
+ }
+ };
+
+ typedef FaceIter<const face_t *> const_face_iter;
+ typedef FaceIter<face_t *> face_iter;
+
+ face_iter faceBegin() { return face_iter(this, 0, 0); }
+ face_iter faceEnd() { return face_iter(this, meshes.size(), 0); }
+
+ const_face_iter faceBegin() const { return const_face_iter(this, 0, 0); }
+ const_face_iter faceEnd() const { return const_face_iter(this, meshes.size(), 0); }
+
+ aabb_t getAABB() const {
+ return aabb_t(meshes.begin(), meshes.end());
+ }
+
+ template<typename func_t>
+ void transform(func_t func) {
+ for (size_t i = 0; i < vertex_storage.size(); ++i) {
+ vertex_storage[i].v = func(vertex_storage[i].v);
+ }
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ meshes[i]->recalc();
+ }
+ }
+
+ MeshSet(const std::vector<typename vertex_t::vector_t> &points,
+ size_t n_faces,
+ const std::vector<int> &face_indices);
+
+ // Construct a mesh set from a set of disconnected faces. Takes
+ // posession of the face pointers.
+ MeshSet(std::vector<face_t *> &faces);
+
+ MeshSet(std::list<face_t *> &faces);
+
+ MeshSet(std::vector<vertex_t> &_vertex_storage,
+ std::vector<mesh_t *> &_meshes);
+
+ // This constructor consolidates and rewrites vertex pointers in
+ // each mesh, repointing them to local storage.
+ MeshSet(std::vector<mesh_t *> &_meshes);
+
+ MeshSet *clone() const;
+
+ ~MeshSet();
+
+ bool isClosed() const {
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ if (!meshes[i]->isClosed()) return false;
+ }
+ return true;
+ }
+
+
+ void invert() {
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ meshes[i]->invert();
+ }
+ }
+
+ void collectVertices();
+
+ void canonicalize();
+ };
+
+
+
+ carve::PointClass classifyPoint(
+ const carve::mesh::MeshSet<3> *meshset,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *face_rtree,
+ const carve::geom::vector<3> &v,
+ bool even_odd = false,
+ const carve::mesh::Mesh<3> *mesh = NULL,
+ const carve::mesh::Face<3> **hit_face = NULL);
+
+
+
+ }
+
+
+
+ mesh::MeshSet<3> *meshFromPolyhedron(const poly::Polyhedron *, int manifold_id);
+ poly::Polyhedron *polyhedronFromMesh(const mesh::MeshSet<3> *, int manifold_id);
+
+
+
+};
+
+#include <carve/mesh_impl.hpp>
diff --git a/extern/carve/include/carve/mesh_impl.hpp b/extern/carve/include/carve/mesh_impl.hpp
new file mode 100644
index 00000000000..23b0a436573
--- /dev/null
+++ b/extern/carve/include/carve/mesh_impl.hpp
@@ -0,0 +1,1015 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/geom2d.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/djset.hpp>
+
+#include <iostream>
+#include <deque>
+
+#include <stddef.h>
+
+namespace carve {
+ namespace mesh {
+
+
+
+ namespace detail {
+ template<typename list_t>
+ struct list_iter_t {
+ typedef std::bidirectional_iterator_tag iterator_category;
+ typedef list_t value_type;
+ typedef ptrdiff_t difference_type;
+ typedef value_type & reference;
+ typedef value_type * pointer;
+
+ list_t *curr;
+ int pos;
+
+ list_iter_t() { }
+ list_iter_t(list_t *_curr, int _pos) : curr(_curr), pos(_pos) { }
+
+ list_iter_t operator++(int) { list_iter_t result(*this); ++pos; curr = curr->next; return result; }
+ list_iter_t operator--(int) { list_iter_t result(*this); --pos; curr = curr->prev; return result; }
+
+ list_iter_t operator++() { ++pos; curr = curr->next; return *this; }
+ list_iter_t operator--() { --pos; curr = curr->prev; return *this; }
+
+ bool operator==(const list_iter_t &other) const { return curr == other.curr && pos == other.pos; }
+ bool operator!=(const list_iter_t &other) const { return curr != other.curr || pos != other.pos; }
+
+ reference operator*() { return *curr; }
+ pointer operator->() { return curr; }
+
+ int idx() const { return pos; }
+ };
+ }
+
+
+
+ template<unsigned ndim>
+ Edge<ndim> *Edge<ndim>::mergeFaces() {
+ if (rev == NULL) return NULL;
+
+ face_t *fwdface = face;
+ face_t *revface = rev->face;
+
+ size_t n_removed = 0;
+
+ Edge *splice_beg = this;
+ do {
+ splice_beg = splice_beg->prev;
+ ++n_removed;
+ } while (splice_beg != this &&
+ splice_beg->rev &&
+ splice_beg->next->rev->prev == splice_beg->rev);
+
+ if (splice_beg == this) {
+ // edge loops are completely matched.
+ return NULL;
+ }
+
+ Edge *splice_end = this;
+ do {
+ splice_end = splice_end->next;
+ ++n_removed;
+ } while (splice_end->rev &&
+ splice_end->prev->rev->next == splice_end->rev);
+
+ --n_removed;
+
+ Edge *link1_p = splice_beg;
+ Edge *link1_n = splice_beg->next->rev->next;
+
+ Edge *link2_p = splice_end->prev->rev->prev;
+ Edge *link2_n = splice_end;
+
+ CARVE_ASSERT(link1_p->face == fwdface);
+ CARVE_ASSERT(link1_n->face == revface);
+
+ CARVE_ASSERT(link2_p->face == revface);
+ CARVE_ASSERT(link2_n->face == fwdface);
+
+ Edge *left_loop = link1_p->next;
+
+ CARVE_ASSERT(left_loop->rev == link1_n->prev);
+
+ _link(link2_n->prev, link1_p->next);
+ _link(link1_n->prev, link2_p->next);
+
+ _link(link1_p, link1_n);
+ _link(link2_p, link2_n);
+
+ fwdface->edge = link1_p;
+
+ for (Edge *e = link1_n; e != link2_n; e = e->next) {
+ CARVE_ASSERT(e->face == revface);
+ e->face = fwdface;
+ fwdface->n_edges++;
+ }
+ for (Edge *e = link2_n; e != link1_n; e = e->next) {
+ CARVE_ASSERT(e->face == fwdface);
+ }
+
+ fwdface->n_edges -= n_removed;
+
+ revface->n_edges = 0;
+ revface->edge = NULL;
+
+ _setloopface(left_loop, NULL);
+ _setloopface(left_loop->rev, NULL);
+
+ return left_loop;
+ }
+
+
+
+ template<unsigned ndim>
+ Edge<ndim> *Edge<ndim>::removeHalfEdge() {
+ Edge *n = NULL;
+ if (face) {
+ face->n_edges--;
+ }
+
+ if (next == this) {
+ if (face) face->edge = NULL;
+ } else {
+ if (face && face->edge == this) face->edge = next;
+ next->prev = prev;
+ prev->next = next;
+ n = next;
+ }
+ delete this;
+ return n;
+ }
+
+
+
+ template<unsigned ndim>
+ Edge<ndim> *Edge<ndim>::removeEdge() {
+ if (rev) {
+ rev->removeHalfEdge();
+ }
+ return removeHalfEdge();
+ }
+
+
+
+ template<unsigned ndim>
+ void Edge<ndim>::unlink() {
+ if (rev) { rev->rev = NULL; rev = NULL; }
+ if (prev->rev) { prev->rev->rev = NULL; prev->rev = NULL; }
+
+ if (face) {
+ face->n_edges--;
+ if (face->edge == this) face->edge = next;
+ face = NULL;
+ }
+
+ next->prev = prev;
+ prev->next = next;
+
+ prev = next = this;
+ }
+
+
+
+ template<unsigned ndim>
+ void Edge<ndim>::insertBefore(Edge<ndim> *other) {
+ if (prev != this) unlink();
+ prev = other->prev;
+ next = other;
+ next->prev = this;
+ prev->next = this;
+
+ if (prev->rev) { prev->rev->rev = NULL; prev->rev = NULL; }
+ }
+
+
+
+ template<unsigned ndim>
+ void Edge<ndim>::insertAfter(Edge<ndim> *other) {
+ if (prev != this) unlink();
+ next = other->next;
+ prev = other;
+ next->prev = this;
+ prev->next = this;
+
+ if (prev->rev) { prev->rev->rev = NULL; prev->rev = NULL; }
+ }
+
+
+
+ template<unsigned ndim>
+ size_t Edge<ndim>::loopSize() const {
+ const Edge *e = this;
+ size_t n = 0;
+ do { e = e->next; ++n; } while (e != this);
+ return n;
+ }
+
+
+
+ template<unsigned ndim>
+ Edge<ndim> *Edge<ndim>::perimNext() const {
+ if (rev) return NULL;
+ Edge *e = next;
+ while(e->rev) {
+ e = e->rev->next;
+ }
+ return e;
+ }
+
+
+
+ template<unsigned ndim>
+ Edge<ndim> *Edge<ndim>::perimPrev() const {
+ if (rev) return NULL;
+ Edge *e = prev;
+ while(e->rev) {
+ e = e->rev->prev;
+ }
+ return e;
+ }
+
+
+
+ template<unsigned ndim>
+ Edge<ndim>::Edge(vertex_t *_vert, face_t *_face) :
+ vert(_vert), face(_face), prev(NULL), next(NULL), rev(NULL) {
+ prev = next = this;
+ }
+
+
+
+ template<unsigned ndim>
+ Edge<ndim>::~Edge() {
+ }
+
+
+
+ template<unsigned ndim>
+ typename Face<ndim>::aabb_t Face<ndim>::getAABB() const {
+ aabb_t aabb;
+ aabb.fit(begin(), end(), vector_mapping());
+ return aabb;
+ }
+
+
+
+ template<unsigned ndim>
+ bool Face<ndim>::recalc() {
+ if (!carve::geom3d::fitPlane(begin(), end(), vector_mapping(), plane)) {
+ return false;
+ }
+
+ int da = carve::geom::largestAxis(plane.N);
+ double A = carve::geom2d::signedArea(begin(), end(), projection_mapping(getProjector(false, da)));
+
+ if ((A < 0.0) ^ (plane.N.v[da] < 0.0)) {
+ plane.negate();
+ }
+
+ project = getProjector(plane.N.v[da] > 0, da);
+ unproject = getUnprojector(plane.N.v[da] > 0, da);
+
+ return true;
+ }
+
+
+
+ template<unsigned ndim>
+ void Face<ndim>::clearEdges() {
+ if (!edge) return;
+
+ edge_t *curr = edge;
+ do {
+ edge_t *next = curr->next;
+ delete curr;
+ curr = next;
+ } while (curr != edge);
+
+ edge = NULL;
+
+ n_edges = 0;
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void Face<ndim>::loopFwd(iter_t begin, iter_t end) {
+ clearEdges();
+ if (begin == end) return;
+ edge = new edge_t(*begin, this); ++n_edges; ++begin;
+ while (begin != end) {
+ edge_t *e = new edge_t(*begin, this);
+ e->insertAfter(edge->prev);
+ ++n_edges;
+ ++begin;
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void Face<ndim>::loopRev(iter_t begin, iter_t end) {
+ clearEdges();
+ if (begin == end) return;
+ edge = new edge_t(*begin, this); ++n_edges; ++begin;
+ while (begin != end) {
+ edge_t *e = new edge_t(*begin, this);
+ e->insertBefore(edge->next);
+ ++n_edges;
+ ++begin;
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void Face<ndim>::init(iter_t begin, iter_t end) {
+ loopFwd(begin, end);
+ }
+
+
+
+ template<unsigned ndim>
+ void Face<ndim>::init(vertex_t *a, vertex_t *b, vertex_t *c) {
+ clearEdges();
+ edge_t *ea = new edge_t(a, this);
+ edge_t *eb = new edge_t(b, this);
+ edge_t *ec = new edge_t(c, this);
+ eb->insertAfter(ea);
+ ec->insertAfter(eb);
+ edge = ea;
+ n_edges = 3;
+ }
+
+
+
+ template<unsigned ndim>
+ void Face<ndim>::init(vertex_t *a, vertex_t *b, vertex_t *c, vertex_t *d) {
+ clearEdges();
+ edge_t *ea = new edge_t(a, this);
+ edge_t *eb = new edge_t(b, this);
+ edge_t *ec = new edge_t(c, this);
+ edge_t *ed = new edge_t(d, this);
+ eb->insertAfter(ea);
+ ec->insertAfter(eb);
+ ed->insertAfter(ec);
+ edge = ea;
+ n_edges = 4;
+ }
+
+
+
+ template<unsigned ndim>
+ void Face<ndim>::getVertices(std::vector<vertex_t *> &verts) const {
+ verts.clear();
+ verts.reserve(n_edges);
+ const edge_t *e = edge;
+ do { verts.push_back(e->vert); e = e->next; } while (e != edge);
+ }
+
+
+
+ template<unsigned ndim>
+ void Face<ndim>::getProjectedVertices(std::vector<carve::geom::vector<2> > &verts) const {
+ verts.clear();
+ verts.reserve(n_edges);
+ const edge_t *e = edge;
+ do { verts.push_back(project(e->vert->v)); e = e->next; } while (e != edge);
+ }
+
+
+
+ template<unsigned ndim>
+ typename Face<ndim>::vector_t Face<ndim>::centroid() const {
+ vector_t v;
+ edge_t *e = edge;
+ do {
+ v += e->vert->v;
+ e = e->next;
+ } while(e != edge);
+ v /= n_edges;
+ return v;
+ }
+
+
+
+ template<unsigned ndim>
+ void Face<ndim>::canonicalize() {
+ edge_t *min = edge;
+ edge_t *e = edge;
+
+ do {
+ if (e->vert < min->vert) min = e;
+ e = e->next;
+ } while (e != edge);
+
+ edge = min;
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ Face<ndim> *Face<ndim>::create(iter_t beg, iter_t end, bool reversed) const {
+ Face *r = new Face();
+
+ if (reversed) {
+ r->loopRev(beg, end);
+ r->plane = -plane;
+ } else {
+ r->loopFwd(beg, end);
+ r->plane = plane;
+ }
+
+ int da = carve::geom::largestAxis(r->plane.N);
+
+ r->project = r->getProjector(r->plane.N.v[da] > 0, da);
+ r->unproject = r->getUnprojector(r->plane.N.v[da] > 0, da);
+
+ return r;
+ }
+
+
+
+ template<unsigned ndim>
+ Face<ndim> *Face<ndim>::clone(const vertex_t *old_base,
+ vertex_t *new_base,
+ std::unordered_map<const edge_t *, edge_t *> &edge_map) const {
+ Face *r = new Face(*this);
+
+ edge_t *e = edge;
+ edge_t *r_p = NULL;
+ edge_t *r_e;
+ do {
+ r_e = new edge_t(e->vert - old_base + new_base, r);
+ edge_map[e] = r_e;
+ if (r_p) {
+ r_p->next = r_e;
+ r_e->prev = r_p;
+ } else {
+ r->edge = r_e;
+ }
+ r_p = r_e;
+
+ if (e->rev) {
+ typename std::unordered_map<const edge_t *, edge_t *>::iterator rev_i = edge_map.find(e->rev);
+ if (rev_i != edge_map.end()) {
+ r_e->rev = (*rev_i).second;
+ (*rev_i).second->rev = r_e;
+ }
+ }
+
+ e = e->next;
+ } while (e != edge);
+ r_e->next = r->edge;
+ r->edge->prev = r_e;
+ return r;
+ }
+
+
+
+ template<unsigned ndim>
+ Mesh<ndim>::Mesh(std::vector<face_t *> &_faces,
+ std::vector<edge_t *> &_open_edges,
+ std::vector<edge_t *> &_closed_edges,
+ bool _is_negative) {
+ std::swap(faces, _faces);
+ std::swap(open_edges, _open_edges);
+ std::swap(closed_edges, _closed_edges);
+ is_negative = _is_negative;
+ meshset = NULL;
+
+ for (size_t i = 0; i < faces.size(); ++i) {
+ faces[i]->mesh = this;
+ }
+ }
+
+
+
+ namespace detail {
+ template<typename iter_t>
+ void FaceStitcher::initEdges(iter_t begin,
+ iter_t end) {
+ size_t c = 0;
+ for (iter_t i = begin; i != end; ++i) {
+ face_t *face = *i;
+ CARVE_ASSERT(face->mesh == NULL); // for the moment, can only insert a face into a mesh once.
+
+ face->id = c++;
+ edge_t *e = face->edge;
+ do {
+ edges[vpair_t(e->v1(), e->v2())].push_back(e);
+ e = e->next;
+ if (e->rev) { e->rev->rev = NULL; e->rev = NULL; }
+ } while (e != face->edge);
+ }
+ face_groups.init(c);
+ is_open.clear();
+ is_open.resize(c, false);
+ }
+
+ template<typename iter_t>
+ void FaceStitcher::build(iter_t begin,
+ iter_t end,
+ std::vector<Mesh<3> *> &meshes) {
+ // work out what set each face belongs to, and then construct
+ // mesh instances for each set of faces.
+ std::vector<size_t> index_set;
+ std::vector<size_t> set_size;
+ face_groups.get_index_to_set(index_set, set_size);
+
+ std::vector<std::vector<face_t *> > mesh_faces;
+ mesh_faces.resize(set_size.size());
+ for (size_t i = 0; i < set_size.size(); ++i) {
+ mesh_faces[i].reserve(set_size[i]);
+ }
+
+ for (iter_t i = begin; i != end; ++i) {
+ face_t *face = *i;
+ mesh_faces[index_set[face->id]].push_back(face);
+ }
+
+ meshes.clear();
+ meshes.reserve(mesh_faces.size());
+ for (size_t i = 0; i < mesh_faces.size(); ++i) {
+ meshes.push_back(new Mesh<3>(mesh_faces[i]));
+ }
+ }
+
+ template<typename iter_t>
+ void FaceStitcher::create(iter_t begin,
+ iter_t end,
+ std::vector<Mesh<3> *> &meshes) {
+ initEdges(begin, end);
+ construct();
+ build(begin, end, meshes);
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ void Mesh<ndim>::cacheEdges() {
+ closed_edges.clear();
+ open_edges.clear();
+
+ for (size_t i = 0; i < faces.size(); ++i) {
+ face_t *face = faces[i];
+ edge_t *e = face->edge;
+ do {
+ if (e->rev == NULL) {
+ open_edges.push_back(e);
+ } else if (e < e->rev) {
+ closed_edges.push_back(e);
+ }
+ e = e->next;
+ } while (e != face->edge);
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ Mesh<ndim>::Mesh(std::vector<face_t *> &_faces) : faces(), open_edges(), closed_edges(), meshset(NULL) {
+ faces.swap(_faces);
+ for (size_t i = 0; i < faces.size(); ++i) {
+ faces[i]->mesh = this;
+ }
+ cacheEdges();
+ calcOrientation();
+ }
+
+
+
+ template<unsigned ndim>
+ void Mesh<ndim>::calcOrientation() {
+ if (open_edges.size() || !closed_edges.size()) {
+ is_negative = false;
+ } else {
+ edge_t *emin = closed_edges[0];
+ if (emin->rev->v1()->v < emin->v1()->v) emin = emin->rev;
+ for (size_t i = 1; i < closed_edges.size(); ++i) {
+ if (closed_edges[i]->v1()->v < emin->v1()->v) emin = closed_edges[i];
+ if (closed_edges[i]->rev->v1()->v < emin->v1()->v) emin = closed_edges[i]->rev;
+ }
+
+ std::vector<face_t *> min_faces;
+ edge_t *e = emin;
+ do {
+ min_faces.push_back(e->face);
+ CARVE_ASSERT(e->rev != NULL);
+ e = e->rev->next;
+ CARVE_ASSERT(e->v1() == emin->v1());
+ CARVE_ASSERT(e->v1()->v < e->v2()->v);
+ CARVE_ASSERT(e->v1()->v.x <= e->v2()->v.x);
+ } while (e != emin);
+
+ double max_abs_x = 0.0;
+ for (size_t f = 0; f < min_faces.size(); ++f) {
+ if (fabs(min_faces[f]->plane.N.x) > fabs(max_abs_x)) max_abs_x = min_faces[f]->plane.N.x;
+ }
+ is_negative = max_abs_x > 0.0;
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ Mesh<ndim> *Mesh<ndim>::clone(const vertex_t *old_base,
+ vertex_t *new_base) const {
+ std::vector<face_t *> r_faces;
+ std::vector<edge_t *> r_open_edges;
+ std::vector<edge_t *> r_closed_edges;
+ std::unordered_map<const edge_t *, edge_t *> edge_map;
+
+ r_faces.reserve(faces.size());
+ r_open_edges.reserve(r_open_edges.size());
+ r_closed_edges.reserve(r_closed_edges.size());
+
+ for (size_t i = 0; i < faces.size(); ++i) {
+ r_faces.push_back(faces[i]->clone(old_base, new_base, edge_map));
+ }
+ for (size_t i = 0; i < closed_edges.size(); ++i) {
+ r_closed_edges.push_back(edge_map[closed_edges[i]]);
+ r_closed_edges.back()->rev = edge_map[closed_edges[i]->rev];
+ }
+ for (size_t i = 0; i < open_edges.size(); ++i) {
+ r_open_edges.push_back(edge_map[open_edges[i]]);
+ }
+
+ return new Mesh(r_faces, r_open_edges, r_closed_edges, is_negative);
+ }
+
+
+
+ template<unsigned ndim>
+ Mesh<ndim>::~Mesh() {
+ for (size_t i = 0; i < faces.size(); ++i) {
+ delete faces[i];
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void Mesh<ndim>::create(iter_t begin, iter_t end, std::vector<Mesh<ndim> *> &meshes) {
+ meshes.clear();
+ }
+
+
+
+ template<>
+ template<typename iter_t>
+ void Mesh<3>::create(iter_t begin, iter_t end, std::vector<Mesh<3> *> &meshes) {
+ detail::FaceStitcher().create(begin, end, meshes);
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename iter_t>
+ void MeshSet<ndim>::_init_from_faces(iter_t begin, iter_t end) {
+ typedef std::unordered_map<const vertex_t *, size_t> map_t;
+ map_t vmap;
+
+ for (iter_t i = begin; i != end; ++i) {
+ face_t *f = *i;
+ edge_t *e = f->edge;
+ do {
+ typename map_t::const_iterator j = vmap.find(e->vert);
+ if (j == vmap.end()) {
+ size_t idx = vmap.size();
+ vmap[e->vert] = idx;
+ }
+ e = e->next;
+ } while (e != f->edge);
+ }
+
+ vertex_storage.resize(vmap.size());
+ for (typename map_t::const_iterator i = vmap.begin(); i != vmap.end(); ++i) {
+ vertex_storage[(*i).second].v = (*i).first->v;
+ }
+
+ for (iter_t i = begin; i != end; ++i) {
+ face_t *f = *i;
+ edge_t *e = f->edge;
+ do {
+ e->vert = &vertex_storage[vmap[e->vert]];
+ e = e->next;
+ } while (e != f->edge);
+ }
+
+ mesh_t::create(begin, end, meshes);
+
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ meshes[i]->meshset = this;
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ MeshSet<ndim>::MeshSet(const std::vector<typename MeshSet<ndim>::vertex_t::vector_t> &points,
+ size_t n_faces,
+ const std::vector<int> &face_indices) {
+ vertex_storage.reserve(points.size());
+ std::vector<face_t *> faces;
+ faces.reserve(n_faces);
+ for (size_t i = 0; i < points.size(); ++i) {
+ vertex_storage.push_back(vertex_t(points[i]));
+ }
+
+ std::vector<vertex_t *> v;
+ size_t p = 0;
+ for (size_t i = 0; i < n_faces; ++i) {
+ const size_t N = face_indices[p++];
+ v.clear();
+ v.reserve(N);
+ for (size_t j = 0; j < N; ++j) {
+ v.push_back(&vertex_storage[face_indices[p++]]);
+ }
+ faces.push_back(new face_t(v.begin(), v.end()));
+ }
+ CARVE_ASSERT(p == face_indices.size());
+ mesh_t::create(faces.begin(), faces.end(), meshes);
+
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ meshes[i]->meshset = this;
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ MeshSet<ndim>::MeshSet(std::vector<face_t *> &faces) {
+ _init_from_faces(faces.begin(), faces.end());
+ }
+
+
+
+ template<unsigned ndim>
+ MeshSet<ndim>::MeshSet(std::list<face_t *> &faces) {
+ _init_from_faces(faces.begin(), faces.end());
+ }
+
+
+
+ template<unsigned ndim>
+ MeshSet<ndim>::MeshSet(std::vector<vertex_t> &_vertex_storage,
+ std::vector<mesh_t *> &_meshes) {
+ vertex_storage.swap(_vertex_storage);
+ meshes.swap(_meshes);
+
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ meshes[i]->meshset = this;
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ MeshSet<ndim>::MeshSet(std::vector<typename MeshSet<ndim>::mesh_t *> &_meshes) {
+ meshes.swap(_meshes);
+ std::unordered_map<vertex_t *, size_t> vert_idx;
+
+ for (size_t m = 0; m < meshes.size(); ++m) {
+ mesh_t *mesh = meshes[m];
+ CARVE_ASSERT(mesh->meshset == NULL);
+ mesh->meshset = this;
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ face_t *face = mesh->faces[f];
+ edge_t *edge = face->edge;
+ do {
+ vert_idx[edge->vert] = 0;
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+ }
+
+ vertex_storage.reserve(vert_idx.size());
+ for (typename std::unordered_map<vertex_t *, size_t>::iterator i = vert_idx.begin(); i != vert_idx.end(); ++i) {
+ (*i).second = vertex_storage.size();
+ vertex_storage.push_back(*(*i).first);
+ }
+
+ for (size_t m = 0; m < meshes.size(); ++m) {
+ mesh_t *mesh = meshes[m];
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ face_t *face = mesh->faces[f];
+ edge_t *edge = face->edge;
+ do {
+ size_t i = vert_idx[edge->vert];
+ edge->vert = &vertex_storage[i];
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ MeshSet<ndim> *MeshSet<ndim>::clone() const {
+ std::vector<vertex_t> r_vertex_storage = vertex_storage;
+ std::vector<mesh_t *> r_meshes;
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ r_meshes.push_back(meshes[i]->clone(&vertex_storage[0], &r_vertex_storage[0]));
+ }
+
+ return new MeshSet(r_vertex_storage, r_meshes);
+ }
+
+
+
+ template<unsigned ndim>
+ MeshSet<ndim>::~MeshSet() {
+ for (size_t i = 0; i < meshes.size(); ++i) {
+ delete meshes[i];
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename face_type>
+ MeshSet<ndim>::FaceIter<face_type>::FaceIter(const MeshSet<ndim> *_obj, size_t _mesh, size_t _face) : obj(_obj), mesh(_mesh), face(_face) {
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename face_type>
+ void MeshSet<ndim>::FaceIter<face_type>::fwd(size_t n) {
+ if (mesh < obj->meshes.size()) {
+ face += n;
+ while (face >= obj->meshes[mesh]->faces.size()) {
+ face -= obj->meshes[mesh++]->faces.size();
+ if (mesh == obj->meshes.size()) { face = 0; break; }
+ }
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename face_type>
+ void MeshSet<ndim>::FaceIter<face_type>::rev(size_t n) {
+ while (n > face) {
+ n -= face;
+ if (mesh == 0) { face = 0; return; }
+ face = obj->meshes[--mesh]->faces.size() - 1;
+ }
+ face -= n;
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename face_type>
+ void MeshSet<ndim>::FaceIter<face_type>::adv(int n) {
+ if (n > 0) {
+ fwd((size_t)n);
+ } else if (n < 0) {
+ rev((size_t)-n);
+ }
+ }
+
+
+
+ template<unsigned ndim>
+ template<typename face_type>
+ typename MeshSet<ndim>::template FaceIter<face_type>::difference_type
+ MeshSet<ndim>::FaceIter<face_type>::operator-(const FaceIter &other) const {
+ CARVE_ASSERT(obj == other.obj);
+ if (mesh == other.mesh) return face - other.face;
+
+ size_t m = 0;
+ for (size_t i = std::min(mesh, other.mesh) + 1; i < std::max(mesh, other.mesh); ++i) {
+ m += obj->meshes[i]->faces.size();
+ }
+
+ if (mesh < other.mesh) {
+ return -(difference_type)((obj->meshes[mesh]->faces.size() - face) + m + other.face);
+ } else {
+ return +(difference_type)((obj->meshes[other.mesh]->faces.size() - other.face) + m + face);
+ }
+ }
+
+
+
+ template<typename order_t>
+ struct VPtrSort {
+ order_t order;
+
+ VPtrSort(const order_t &_order = order_t()) : order(_order) {}
+
+ template<unsigned ndim>
+ bool operator()(carve::mesh::Vertex<ndim> *a,
+ carve::mesh::Vertex<ndim> *b) const {
+ return order(a->v, b->v);
+ }
+ };
+
+
+
+ template<unsigned ndim>
+ void MeshSet<ndim>::collectVertices() {
+ std::unordered_map<vertex_t *, size_t> vert_idx;
+
+ for (size_t m = 0; m < meshes.size(); ++m) {
+ mesh_t *mesh = meshes[m];
+
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ face_t *face = mesh->faces[f];
+ edge_t *edge = face->edge;
+ do {
+ vert_idx[edge->vert] = 0;
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+ }
+
+ std::vector<vertex_t> new_vertex_storage;
+ new_vertex_storage.reserve(vert_idx.size());
+ for (typename std::unordered_map<vertex_t *, size_t>::iterator
+ i = vert_idx.begin(); i != vert_idx.end(); ++i) {
+ (*i).second = new_vertex_storage.size();
+ new_vertex_storage.push_back(*(*i).first);
+ }
+
+ for (size_t m = 0; m < meshes.size(); ++m) {
+ mesh_t *mesh = meshes[m];
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ face_t *face = mesh->faces[f];
+ edge_t *edge = face->edge;
+ do {
+ size_t i = vert_idx[edge->vert];
+ edge->vert = &new_vertex_storage[i];
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+ }
+
+ std::swap(vertex_storage, new_vertex_storage);
+ }
+
+
+
+ template<unsigned ndim>
+ void MeshSet<ndim>::canonicalize() {
+ std::vector<vertex_t *> vptr;
+ std::vector<vertex_t *> vmap;
+ std::vector<vertex_t> vout;
+ const size_t N = vertex_storage.size();
+
+ vptr.reserve(N);
+ vout.reserve(N);
+ vmap.resize(N);
+
+ for (size_t i = 0; i != N; ++i) {
+ vptr.push_back(&vertex_storage[i]);
+ }
+ std::sort(vptr.begin(), vptr.end(), VPtrSort<std::less<typename vertex_t::vector_t> >());
+
+ for (size_t i = 0; i != N; ++i) {
+ vout.push_back(*vptr[i]);
+ vmap[vptr[i] - &vertex_storage[0]] = &vout[i];
+ }
+
+ for (face_iter i = faceBegin(); i != faceEnd(); ++i) {
+ for (typename face_t::edge_iter_t j = (*i)->begin(); j != (*i)->end(); ++j) {
+ (*j).vert = vmap[(*j).vert - &vertex_storage[0]];
+ }
+ (*i)->canonicalize();
+ }
+
+ vertex_storage.swap(vout);
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/mesh_ops.hpp b/extern/carve/include/carve/mesh_ops.hpp
new file mode 100644
index 00000000000..02b1bde4e45
--- /dev/null
+++ b/extern/carve/include/carve/mesh_ops.hpp
@@ -0,0 +1,975 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/mesh.hpp>
+
+#include <iostream>
+#include <fstream>
+
+namespace carve {
+ namespace mesh {
+ namespace detail {
+ // make a triangle out of three edges.
+ template<unsigned ndim>
+ void link(Edge<ndim> *e1, Edge<ndim> *e2, Edge<ndim> *e3, Face<ndim> *f = NULL) {
+ e1->next = e2; e2->next = e3; e3->next = e1;
+ e3->prev = e2; e2->prev = e1; e1->prev = e3;
+ e1->face = e2->face = e3->face = f;
+ if (f) {
+ f->edge = e1;
+ f->recalc();
+ }
+ }
+
+
+
+ template<unsigned ndim, typename proj_t>
+ double loopArea(carve::mesh::Edge<ndim> *edge, proj_t proj) {
+ double A = 0.0;
+ carve::mesh::Edge<3> *e = edge;
+ do {
+ carve::geom2d::P2 p1 = proj(e->vert->v);
+ carve::geom2d::P2 p2 = proj(e->next->vert->v);
+ A += (p2.y + p1.y) * (p2.x - p1.x);
+ e = e->next;
+ } while (e != edge);
+ return A / 2.0;
+ }
+
+
+
+ template<unsigned ndim, typename proj_t>
+ struct TriangulationData {
+ typedef Edge<ndim> edge_t;
+
+ struct VertexInfo {
+ double score;
+ carve::geom2d::P2 p;
+ bool convex;
+ bool failed;
+ VertexInfo *next, *prev;
+ edge_t *edge;
+
+ VertexInfo(edge_t *_edge,
+ const carve::geom2d::P2 &_p) :
+ score(0.0), p(_p), convex(false), failed(false), next(NULL), prev(NULL), edge(_edge) {
+ }
+
+ bool isCandidate() const {
+ return convex && !failed;
+ }
+
+ void fail() {
+ failed = true;
+ }
+
+ static bool isLeft(const VertexInfo *a, const VertexInfo *b, const geom2d::P2 &p) {
+ if (a < b) {
+ return carve::geom2d::orient2d(a->p, b->p, p) > 0.0;
+ } else {
+ return carve::geom2d::orient2d(b->p, a->p, p) < 0.0;
+ }
+ }
+
+ // is the ear prev->edge->next convex?
+ bool testForConvexVertex() const {
+ return isLeft(next, prev, p);
+ }
+
+ static double triScore(const geom2d::P2 &a, const geom2d::P2 &b, const geom2d::P2 &c) {
+ // score is in the range: [0, 1]
+ // equilateral triangles score 1
+ // sliver triangles score 0
+ double dab = (a - b).length();
+ double dbc = (b - c).length();
+ double dca = (c - a).length();
+
+ if (dab < 1e-10 || dbc < 1e-10 || dca < 1e-10) return 0.0;
+
+ return std::max(std::min((dab + dbc) / dca, std::min((dab + dca) / dbc, (dbc + dca) / dab)) - 1.0, 0.0);
+ }
+
+ // calculate a score for the ear edge.
+ double calcScore() const {
+ double this_tri = triScore(prev->p, p, next->p);
+ double next_tri = triScore(prev->p, next->p, next->next->p);
+ double prev_tri = triScore(prev->prev->p, prev->p, next->p);
+
+ return this_tri + std::max(next_tri, prev_tri) * .2;
+ }
+
+ void recompute() {
+ convex = testForConvexVertex();
+ failed = false;
+ if (convex) {
+ score = calcScore();
+ } else {
+ score = -1e-5;
+ }
+ }
+
+ static bool inTriangle(const VertexInfo *a,
+ const VertexInfo *b,
+ const VertexInfo *c,
+ const geom2d::P2 &e) {
+ return !isLeft(b, a, e) && !isLeft(c, b, e) && !isLeft(a, c, e);
+ }
+
+
+ bool isClipable() const {
+ for (const VertexInfo *v_test = next->next; v_test != prev; v_test = v_test->next) {
+ if (v_test->convex) {
+ continue;
+ }
+
+ if (v_test->p == prev->p || v_test->p == next->p) {
+ continue;
+ }
+
+ if (v_test->p == p) {
+ if (v_test->next->p == prev->p && v_test->prev->p == next->p) {
+ return false;
+ }
+
+ if (v_test->next->p == prev->p || v_test->prev->p == next->p) {
+ continue;
+ }
+ }
+
+ if (inTriangle(prev, this, next, v_test->p)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ };
+
+ struct order_by_score {
+ bool operator()(const VertexInfo *a, const VertexInfo *b) const {
+ return a->score < b->score;
+ }
+ };
+
+ typedef std::pair<VertexInfo *, VertexInfo *> diag_t;
+
+ proj_t proj;
+
+ geom2d::P2 P(const VertexInfo *vi) const {
+ return vi->p;
+ }
+
+ geom2d::P2 P(const edge_t *edge) const {
+ return proj(edge->vert->v);
+ }
+
+ bool isLeft(const edge_t *a, const edge_t *b, const geom2d::P2 &p) const {
+ if (a < b) {
+ return carve::geom2d::orient2d(P(a), P(b), p) > 0.0;
+ } else {
+ return carve::geom2d::orient2d(P(b), P(a), p) < 0.0;
+ }
+ }
+
+ bool testForConvexVertex(const edge_t *vert) const {
+ return isLeft(vert->next, vert->prev, P(vert));
+ }
+
+ bool inCone(const VertexInfo *vert, const geom2d::P2 &p) const {
+ return geom2d::internalToAngle(P(vert->next), P(vert), P(vert->prev), p);
+ }
+
+ int windingNumber(VertexInfo *vert, const carve::geom2d::P2 &point) const {
+ int wn = 0;
+
+ VertexInfo *v = vert;
+ geom2d::P2 v_p = P(vert);
+ do {
+ geom2d::P2 n_p = P(v->next);
+
+ if (v_p.y <= point.y) {
+ if (n_p.y > point.y && carve::geom2d::orient2d(v_p, n_p, point) > 0.0) {
+ ++wn;
+ }
+ } else {
+ if (n_p.y <= point.y && carve::geom2d::orient2d(v_p, n_p, point) < 0.0) {
+ --wn;
+ }
+ }
+ v = v->next;
+ v_p = n_p;
+ } while (v != vert);
+
+ return wn;
+ }
+
+ bool diagonalIsCandidate(diag_t diag) const {
+ VertexInfo *v1 = diag.first;
+ VertexInfo *v2 = diag.second;
+ return (inCone(v1, P(v2)) && inCone(v2, P(v1)));
+ }
+
+ bool testDiagonal(diag_t diag) const {
+ // test whether v1-v2 is a valid diagonal.
+ VertexInfo *v1 = diag.first;
+ VertexInfo *v2 = diag.second;
+ geom2d::P2 v1p = P(v1);
+ geom2d::P2 v2p = P(v2);
+
+ bool intersected = false;
+
+ for (VertexInfo *t = v1->next; !intersected && t != v1->prev; t = t->next) {
+ VertexInfo *u = t->next;
+ if (t == v2 || u == v2) continue;
+
+ geom2d::P2 tp = P(t);
+ geom2d::P2 up = P(u);
+
+ double l_a1 = carve::geom2d::orient2d(v1p, v2p, tp);
+ double l_a2 = carve::geom2d::orient2d(v1p, v2p, up);
+
+ double l_b1 = carve::geom2d::orient2d(tp, up, v1p);
+ double l_b2 = carve::geom2d::orient2d(tp, up, v2p);
+
+ if (l_a1 > l_a2) std::swap(l_a1, l_a2);
+ if (l_b1 > l_b2) std::swap(l_b1, l_b2);
+
+ if (l_a1 == 0.0 && l_a2 == 0.0 &&
+ l_b1 == 0.0 && l_b2 == 0.0) {
+ // colinear
+ if (std::max(tp.x, up.x) >= std::min(v1p.x, v2p.x) && std::min(tp.x, up.x) <= std::max(v1p.x, v2p.x)) {
+ // colinear and intersecting
+ intersected = true;
+ }
+ continue;
+ }
+
+ if (l_a2 <= 0.0 || l_a1 >= 0.0 || l_b2 <= 0.0 || l_b1 >= 0.0) {
+ // no intersection
+ continue;
+ }
+
+ intersected = true;
+ }
+
+ if (!intersected) {
+ // test whether midpoint winding == 1
+
+ carve::geom2d::P2 mid = (v1p + v2p) / 2;
+ if (windingNumber(v1, mid) == 1) {
+ // this diagonal is ok
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Find the vertex half way around the loop (rounds upwards).
+ VertexInfo *findMidpoint(VertexInfo *vert) const {
+ VertexInfo *v = vert;
+ VertexInfo *r = vert;
+ while (1) {
+ r = r->next;
+ v = v->next; if (v == vert) return r;
+ v = v->next; if (v == vert) return r;
+ }
+ }
+
+ // Test all diagonals with a separation of a-b by walking both
+ // pointers around the loop. In the case where a-b divides the
+ // loop exactly in half, this will test each diagonal twice,
+ // but avoiding this case is not worth the extra effort
+ // required.
+ diag_t scanDiagonals(VertexInfo *a, VertexInfo *b) const {
+ VertexInfo *v1 = a;
+ VertexInfo *v2 = b;
+
+ do {
+ diag_t d(v1, v2);
+ if (diagonalIsCandidate(d) && testDiagonal(d)) {
+ return d;
+ }
+ v1 = v1->next;
+ v2 = v2->next;
+ } while (v1 != a);
+
+ return diag_t(NULL, NULL);
+ }
+
+ diag_t scanAllDiagonals(VertexInfo *a) const {
+ // Rationale: We want to find a diagonal that splits the
+ // loop into two as evenly as possible, to reduce the number
+ // of times that diagonal splitting is required. Start by
+ // scanning all diagonals separated by loop_len / 2, then
+ // decrease the separation until we find something.
+
+ // loops of length 2 or 3 have no possible diagonal.
+ if (a->next == a || a->next->next == a) return diag_t(NULL, NULL);
+
+ VertexInfo *b = findMidpoint(a);
+ while (b != a->next) {
+ diag_t d = scanDiagonals(a, b);
+ if (d != diag_t(NULL, NULL)) return d;
+ b = b->prev;
+ }
+
+ return diag_t(NULL, NULL);
+ }
+
+ diag_t findDiagonal(VertexInfo *vert) const {
+ return scanAllDiagonals(vert);
+ }
+
+ diag_t findHighScoringDiagonal(VertexInfo *vert) const {
+ typedef std::pair<double, diag_t> heap_entry_t;
+ VertexInfo *v1, *v2;
+ std::vector<heap_entry_t> heap;
+ size_t loop_len = 0;
+
+ v1 = vert;
+ do {
+ ++loop_len;
+ v1 = v1->next;
+ } while (v1 != vert);
+
+ v1 = vert;
+ do {
+ v2 = v1->next->next;
+ size_t dist = 2;
+ do {
+ if (diagonalIsCandidate(diag_t(v1, v2))) {
+ double score = std::min(dist, loop_len - dist);
+ // double score = (v1->edge->vert->v - v2->edge->vert->v).length2();
+ heap.push_back(heap_entry_t(score, diag_t(v1, v2)));
+ }
+ v2 = v2->next;
+ ++dist;
+ } while (v2 != vert && v2 != v1->prev);
+ v1 = v1->next;
+ } while (v1->next->next != vert);
+
+ std::make_heap(heap.begin(), heap.end());
+
+ while (heap.size()) {
+ std::pop_heap(heap.begin(), heap.end());
+ heap_entry_t h = heap.back();
+ heap.pop_back();
+
+ if (testDiagonal(h.second)) return h.second;
+ }
+
+ // couldn't find a diagonal that was ok.
+ return diag_t(NULL, NULL);
+ }
+
+ void splitEdgeLoop(VertexInfo *v1, VertexInfo *v2) {
+ VertexInfo *v1_copy = new VertexInfo(new Edge<ndim>(v1->edge->vert, NULL), v1->p);
+ VertexInfo *v2_copy = new VertexInfo(new Edge<ndim>(v2->edge->vert, NULL), v2->p);
+
+ v1_copy->edge->rev = v2_copy->edge;
+ v2_copy->edge->rev = v1_copy->edge;
+
+ v1_copy->edge->prev = v1->edge->prev;
+ v1_copy->edge->next = v2->edge;
+
+ v2_copy->edge->prev = v2->edge->prev;
+ v2_copy->edge->next = v1->edge;
+
+ v1->edge->prev->next = v1_copy->edge;
+ v1->edge->prev = v2_copy->edge;
+
+ v2->edge->prev->next = v2_copy->edge;
+ v2->edge->prev = v1_copy->edge;
+
+ v1_copy->prev = v1->prev;
+ v1_copy->next = v2;
+
+ v2_copy->prev = v2->prev;
+ v2_copy->next = v1;
+
+ v1->prev->next = v1_copy;
+ v1->prev = v2_copy;
+
+ v2->prev->next = v2_copy;
+ v2->prev = v1_copy;
+ }
+
+ VertexInfo *findDegenerateEar(VertexInfo *edge) {
+ VertexInfo *v = edge;
+
+ if (v->next == v || v->next->next == v) return NULL;
+
+ do {
+ if (P(v) == P(v->next)) {
+ return v;
+ } else if (P(v) == P(v->next->next)) {
+ if (P(v->next) == P(v->next->next->next)) {
+ // a 'z' in the loop: z (a) b a b c -> remove a-b-a -> z (a) a b c -> remove a-a-b (next loop) -> z a b c
+ // z --(a)-- b
+ // /
+ // /
+ // a -- b -- d
+ return v->next;
+ } else {
+ // a 'shard' in the loop: z (a) b a c d -> remove a-b-a -> z (a) a b c d -> remove a-a-b (next loop) -> z a b c d
+ // z --(a)-- b
+ // /
+ // /
+ // a -- c -- d
+ // n.b. can only do this if the shard is pointing out of the polygon. i.e. b is outside z-a-c
+ if (!carve::geom2d::internalToAngle(P(v->next->next->next), P(v), P(v->prev), P(v->next))) {
+ return v->next;
+ }
+ }
+ }
+ v = v->next;
+ } while (v != edge);
+
+ return NULL;
+ }
+
+ // Clip off a vertex at vert, producing a triangle (with appropriate rev pointers)
+ template<typename out_iter_t>
+ VertexInfo *clipEar(VertexInfo *vert, out_iter_t out) {
+ CARVE_ASSERT(testForConvexVertex(vert->edge));
+
+ edge_t *p_edge = vert->edge->prev;
+ edge_t *n_edge = vert->edge->next;
+
+ edge_t *p_copy = new edge_t(p_edge->vert, NULL);
+ edge_t *n_copy = new edge_t(n_edge->vert, NULL);
+
+ n_copy->next = p_copy;
+ n_copy->prev = vert->edge;
+
+ p_copy->next = vert->edge;
+ p_copy->prev = n_copy;
+
+ vert->edge->next = n_copy;
+ vert->edge->prev = p_copy;
+
+ p_edge->next = n_edge;
+ n_edge->prev = p_edge;
+
+ if (p_edge->rev) {
+ p_edge->rev->rev = p_copy;
+ }
+ p_copy->rev = p_edge->rev;
+
+ p_edge->rev = n_copy;
+ n_copy->rev = p_edge;
+
+ *out++ = vert->edge;
+
+ if (vert->edge->face) {
+ if (vert->edge->face->edge == vert->edge) {
+ vert->edge->face->edge = n_edge;
+ }
+ vert->edge->face->n_edges--;
+ vert->edge->face = NULL;
+ }
+
+ vert->next->prev = vert->prev;
+ vert->prev->next = vert->next;
+
+ VertexInfo *n = vert->next;
+ delete vert;
+ return n;
+ }
+
+ template<typename out_iter_t>
+ size_t removeDegeneracies(VertexInfo *&begin, out_iter_t out) {
+ VertexInfo *v;
+ size_t count = 0;
+
+ while ((v = findDegenerateEar(begin)) != NULL) {
+ begin = clipEar(v, out);
+ ++count;
+ }
+ return count;
+ }
+
+ template<typename out_iter_t>
+ bool splitAndResume(VertexInfo *begin, out_iter_t out) {
+ diag_t diag;
+
+ diag = findDiagonal(begin);
+ if (diag == diag_t(NULL, NULL)) {
+ std::cerr << "failed to find diagonal" << std::endl;
+ return false;
+ }
+
+ // add a splitting edge between v1 and v2.
+ VertexInfo *v1 = diag.first;
+ VertexInfo *v2 = diag.second;
+
+ splitEdgeLoop(v1, v2);
+
+ v1->recompute();
+ v1->next->recompute();
+
+ v2->recompute();
+ v2->next->recompute();
+
+#if defined(CARVE_DEBUG)
+ dumpPoly(v1->edge, v2->edge);
+#endif
+
+#if defined(CARVE_DEBUG)
+ CARVE_ASSERT(!checkSelfIntersection(v1));
+ CARVE_ASSERT(!checkSelfIntersection(v2));
+#endif
+
+ bool r1 = doTriangulate(v1, out);
+ bool r2 = doTriangulate(v2, out);
+
+ return r1 && r2;
+ }
+
+ template<typename out_iter_t>
+ bool doTriangulate(VertexInfo *begin, out_iter_t out);
+
+ TriangulationData(proj_t _proj) : proj(_proj) {
+ }
+
+ VertexInfo *init(edge_t *begin) {
+ edge_t *e = begin;
+ VertexInfo *head = NULL, *tail = NULL, *v;
+ do {
+ VertexInfo *v = new VertexInfo(e, proj(e->vert->v));
+ if (tail != NULL) {
+ tail->next = v;
+ v->prev = tail;
+ } else {
+ head = v;
+ }
+ tail = v;
+
+ e = e->next;
+ } while (e != begin);
+ tail->next = head;
+ head->prev = tail;
+
+ v = head;
+ do {
+ v->recompute();
+ v = v->next;
+ } while (v != head);
+ return head;
+ }
+
+ class EarQueue {
+ TriangulationData &data;
+ std::vector<VertexInfo *> queue;
+
+ void checkheap() {
+#ifdef __GNUC__
+ CARVE_ASSERT(std::__is_heap(queue.begin(), queue.end(), order_by_score()));
+#endif
+ }
+
+ public:
+ EarQueue(TriangulationData &_data) : data(_data), queue() {
+ }
+
+ size_t size() const {
+ return queue.size();
+ }
+
+ void push(VertexInfo *v) {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ queue.push_back(v);
+ std::push_heap(queue.begin(), queue.end(), order_by_score());
+ }
+
+ VertexInfo *pop() {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ std::pop_heap(queue.begin(), queue.end(), order_by_score());
+ VertexInfo *v = queue.back();
+ queue.pop_back();
+ return v;
+ }
+
+ void remove(VertexInfo *v) {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ CARVE_ASSERT(std::find(queue.begin(), queue.end(), v) != queue.end());
+ double score = v->score;
+ if (v != queue[0]) {
+ v->score = queue[0]->score + 1;
+ std::make_heap(queue.begin(), queue.end(), order_by_score());
+ }
+ CARVE_ASSERT(v == queue[0]);
+ std::pop_heap(queue.begin(), queue.end(), order_by_score());
+ CARVE_ASSERT(queue.back() == v);
+ queue.pop_back();
+ v->score = score;
+ }
+
+ void changeScore(VertexInfo *v, double s_from, double s_to) {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ CARVE_ASSERT(std::find(queue.begin(), queue.end(), v) != queue.end());
+ if (s_from != s_to) {
+ v->score = s_to;
+ std::make_heap(queue.begin(), queue.end(), order_by_score());
+ }
+ }
+
+ void update(VertexInfo *v) {
+ VertexInfo pre = *v;
+ v->recompute();
+ VertexInfo post = *v;
+
+ if (pre.isCandidate()) {
+ if (post.isCandidate()) {
+ changeScore(v, pre.score, post.score);
+ } else {
+ remove(v);
+ }
+ } else {
+ if (post.isCandidate()) {
+ push(v);
+ }
+ }
+ }
+ };
+
+
+ bool checkSelfIntersection(const VertexInfo *vert) {
+ const VertexInfo *v1 = vert;
+ do {
+ const VertexInfo *v2 = vert->next->next;
+ do {
+ carve::geom2d::P2 a = v1->p;
+ carve::geom2d::P2 b = v1->next->p;
+ CARVE_ASSERT(a == proj(v1->edge->vert->v));
+ CARVE_ASSERT(b == proj(v1->edge->next->vert->v));
+
+ carve::geom2d::P2 c = v2->p;
+ carve::geom2d::P2 d = v2->next->p;
+ CARVE_ASSERT(c == proj(v2->edge->vert->v));
+ CARVE_ASSERT(d == proj(v2->edge->next->vert->v));
+
+ bool intersected = false;
+ if (a == c || a == d || b == c || b == d) {
+ } else {
+ intersected = true;
+
+ double l_a1 = carve::geom2d::orient2d(a, b, c);
+ double l_a2 = carve::geom2d::orient2d(a, b, d);
+ if (l_a1 > l_a2) std::swap(l_a1, l_a2);
+ if (l_a2 <= 0.0 || l_a1 >= 0.0) {
+ intersected = false;
+ }
+
+ double l_b1 = carve::geom2d::orient2d(c, d, a);
+ double l_b2 = carve::geom2d::orient2d(c, d, b);
+ if (l_b1 > l_b2) std::swap(l_b1, l_b2);
+ if (l_b2 <= 0.0 || l_b1 >= 0.0) {
+ intersected = false;
+ }
+
+ if (l_a1 == 0.0 && l_a2 == 0.0 && l_b1 == 0.0 && l_b2 == 0.0) {
+ if (std::max(a.x, b.x) >= std::min(c.x, d.x) && std::min(a.x, b.x) <= std::max(c.x, d.x)) {
+ // colinear and intersecting.
+ } else {
+ // colinear but not intersecting.
+ intersected = false;
+ }
+ }
+ }
+ if (intersected) {
+ carve::geom2d::P2 p[4] = { a, b, c, d };
+ carve::geom::aabb<2> A(p, p+4);
+ A.expand(5);
+
+ std::cerr << "\
+<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\
+<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n\
+<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n\
+ x=\"" << A.min().x << "px\" y=\"" << A.min().y << "\"\n\
+ width=\"" << A.extent.x * 2 << "\" height=\"" << A.extent.y * 2 << "\"\n\
+ viewBox=\"" << A.min().x << " " << A.min().y << " " << A.max().x << " " << A.max().y << "\"\n\
+ enable-background=\"new " << A.min().x << " " << A.min().y << " " << A.max().x << " " << A.max().y << "\"\n\
+ xml:space=\"preserve\">\n\
+<line fill=\"none\" stroke=\"#000000\" x1=\"" << a.x << "\" y1=\"" << a.y << "\" x2=\"" << b.x << "\" y2=\"" << b.y << "\"/>\n\
+<line fill=\"none\" stroke=\"#000000\" x1=\"" << c.x << "\" y1=\"" << c.y << "\" x2=\"" << d.x << "\" y2=\"" << d.y << "\"/>\n\
+</svg>\n";
+ return true;
+ }
+ v2 = v2->next;
+ } while (v2 != vert);
+ v1 = v1->next;
+ } while (v1 != vert);
+ return false;
+ }
+
+ carve::geom::aabb<2> make2d(const edge_t *edge, std::vector<geom2d::P2> &points) {
+ const edge_t *e = edge;
+ do {
+ points.push_back(P(e));
+ e = e->next;
+ } while(e != edge);
+ return carve::geom::aabb<2>(points.begin(), points.end());
+ }
+
+ void dumpLoop(std::ostream &out,
+ const std::vector<carve::geom2d::P2> &points,
+ const char *fill,
+ const char *stroke,
+ double stroke_width,
+ double offx,
+ double offy,
+ double scale
+ ) {
+ out << "<polygon fill=\"" << fill << "\" stroke=\"" << stroke << "\" stroke-width=\"" << stroke_width << "\" points=\"";
+ for (size_t i = 0; i < points.size(); ++i) {
+ if (i) out << ' ';
+ double x, y;
+ x = scale * (points[i].x - offx) + 5;
+ y = scale * (points[i].y - offy) + 5;
+ out << x << ',' << y;
+ }
+ out << "\" />" << std::endl;
+ }
+
+ void dumpPoly(const edge_t *edge, const edge_t *edge2 = NULL, const char *pfx = "poly_") {
+ static int step = 0;
+ std::ostringstream filename;
+ filename << pfx << step++ << ".svg";
+ std::cerr << "dumping to " << filename.str() << std::endl;
+ std::ofstream out(filename.str().c_str());
+
+ std::vector <geom2d::P2> points, points2;
+
+ carve::geom::aabb<2> A = make2d(edge, points);
+ if (edge2) {
+ A.unionAABB(make2d(edge2, points2));
+ }
+ A.expand(5);
+
+ out << "\
+<?xml version=\"1.0\"?>\n\
+<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n\
+<svg\n\
+ x=\"" << A.min().x << "px\" y=\"" << A.min().y << "\"\n\
+ width=\"" << A.extent.x * 2 << "\" height=\"" << A.extent.y * 2 << "\"\n\
+ viewBox=\"" << A.min().x << " " << A.min().y << " " << A.max().x << " " << A.max().y << "\"\n\
+ enable-background=\"new " << A.min().x << " " << A.min().y << " " << A.max().x << " " << A.max().y << "\"\n\
+ xml:space=\"preserve\">\n";
+
+ dumpLoop(out, points, "rgb(0,0,0)", "blue", 0.1, 0, 0, 1);
+ if (points2.size()) dumpLoop(out, points2, "rgb(255,0,0)", "blue", 0.1, 0, 0, 1);
+
+ out << "</svg>" << std::endl;
+ }
+ };
+
+ template<unsigned ndim, typename proj_t>
+ template<typename out_iter_t>
+ bool TriangulationData<ndim, proj_t>::doTriangulate(VertexInfo *begin, out_iter_t out) {
+ EarQueue vq(*this);
+
+#if defined(CARVE_DEBUG)
+ dumpPoly(begin->edge, NULL, "input_");
+ CARVE_ASSERT(!checkSelfIntersection(begin));
+#endif
+
+ VertexInfo *v = begin, *n, *p;
+ size_t remain = 0;
+ do {
+ if (v->isCandidate()) vq.push(v);
+ v = v->next;
+ remain++;
+ } while (v != begin);
+
+ while (remain > 3 && vq.size()) {
+ { static int __c = 0; if (++__c % 50 == 0) { break; } }
+ v = vq.pop();
+ if (!v->isClipable()) {
+ v->fail();
+ continue;
+ }
+
+ continue_clipping:
+ n = clipEar(v, out);
+ p = n->prev;
+ begin = n;
+ if (--remain == 3) break;
+ // if (checkSelfIntersection(begin)) {
+ // dumpPoly(begin->edge, NULL, "badclip_");
+ // CARVE_ASSERT(!!!"clip created self intersection");
+ // }
+
+ vq.update(n);
+ vq.update(p);
+
+ if (n->score < p->score) { std::swap(n, p); }
+ if (n->score > 0.25 && n->isCandidate() && n->isClipable()) {
+ vq.remove(n);
+ v = n;
+ goto continue_clipping;
+ }
+ if (p->score > 0.25 && p->isCandidate() && p->isClipable()) {
+ vq.remove(p);
+ v = p;
+ goto continue_clipping;
+ }
+ }
+
+ bool ret = false;
+
+#if defined(CARVE_DEBUG)
+ dumpPoly(begin->edge, NULL, "remainder_");
+#endif
+
+ if (remain > 3) {
+ std::vector<carve::geom2d::P2> temp;
+ temp.reserve(remain);
+ VertexInfo *v = begin;
+ do {
+ temp.push_back(P(v));
+ v = v->next;
+ } while (v != begin);
+
+ if (carve::geom2d::signedArea(temp) == 0) {
+ // XXX: this test will fail in cases where the boundary is
+ // twisted so that a negative area balances a positive area.
+ std::cerr << "got to here" << std::endl;
+ dumpPoly(begin->edge, NULL, "interesting_case_");
+ goto done;
+ }
+ }
+
+ if (remain > 3) {
+ remain -= removeDegeneracies(begin, out);
+ }
+
+ if (remain > 3) {
+ return splitAndResume(begin, out);
+ }
+
+ { double a = loopArea(begin->edge, proj); CARVE_ASSERT(a <= 0.0); }
+ *out++ = begin->edge;
+
+ v = begin;
+ do {
+ n = v->next;
+ delete v;
+ v = n;
+ } while (v != begin);
+
+ ret = true;
+
+ done:
+ return ret;
+ }
+ }
+
+
+
+ template<unsigned ndim, typename proj_t, typename out_iter_t>
+ void triangulate(Edge<ndim> *edge, proj_t proj, out_iter_t out) {
+ detail::TriangulationData<ndim, proj_t> triangulator(proj);
+ typename detail::TriangulationData<ndim, proj_t>::VertexInfo *v = triangulator.init(edge);
+ triangulator.removeDegeneracies(v, out);
+ triangulator.doTriangulate(v, out);
+ }
+
+ // given edge a-b, part of triangles a-b-c and b-a-d, make triangles c-a-d and b-c-d
+ template<unsigned ndim>
+ void flipTriEdge(Edge<ndim> *edge) {
+ CARVE_ASSERT(edge->rev != NULL);
+ CARVE_ASSERT(edge->face->nEdges() == 3);
+ CARVE_ASSERT(edge->rev->face->nEdges() == 3);
+
+ CARVE_ASSERT(edge->prev != edge);
+ CARVE_ASSERT(edge->next != edge);
+ CARVE_ASSERT(edge->rev->prev != edge->rev);
+ CARVE_ASSERT(edge->rev->next != edge->rev);
+
+ typedef Edge<ndim> edge_t;
+ typedef Face<ndim> face_t;
+
+ edge_t *t1[3], *t2[3];
+ face_t *f1, *f2;
+
+ t1[1] = edge; t2[1] = edge->rev;
+ t1[0] = t1[1]->prev; t1[2] = t1[1]->next;
+ t2[0] = t2[1]->prev; t2[2] = t2[1]->next;
+
+ f1 = t1[1]->face; f2 = t2[1]->face;
+
+ // std::cerr << t1[0]->vert << "->" << t1[1]->vert << "->" << t1[2]->vert << std::endl;
+ // std::cerr << t2[0]->vert << "->" << t2[1]->vert << "->" << t2[2]->vert << std::endl;
+
+ t1[1]->vert = t2[0]->vert;
+ t2[1]->vert = t1[0]->vert;
+
+ // std::cerr << t1[0]->vert << "->" << t2[2]->vert << "->" << t1[1]->vert << std::endl;
+ // std::cerr << t2[0]->vert << "->" << t1[2]->vert << "->" << t2[1]->vert << std::endl;
+
+ detail::link(t1[0], t2[2], t1[1], f1);
+ detail::link(t2[0], t1[2], t2[1], f2);
+
+ if (t1[0]->rev) CARVE_ASSERT(t1[0]->v2() == t1[0]->rev->v1());
+ if (t2[0]->rev) CARVE_ASSERT(t2[0]->v2() == t2[0]->rev->v1());
+ if (t1[2]->rev) CARVE_ASSERT(t1[2]->v2() == t1[2]->rev->v1());
+ if (t2[2]->rev) CARVE_ASSERT(t2[2]->v2() == t2[2]->rev->v1());
+ }
+
+ template<unsigned ndim>
+ void splitEdgeLoop(Edge<ndim> *v1, Edge<ndim> *v2) {
+ // v1 and v2 end up on different sides of the split.
+ Edge<ndim> *v1_copy = new Edge<ndim>(v1->vert, NULL);
+ Edge<ndim> *v2_copy = new Edge<ndim>(v2->vert, NULL);
+
+ v1_copy->rev = v2_copy;
+ v2_copy->rev = v1_copy;
+
+ v1_copy->prev = v1->prev;
+ v1_copy->next = v2;
+
+ v2_copy->prev = v2->prev;
+ v2_copy->next = v1;
+
+ v1->prev->next = v1_copy;
+ v1->prev = v2_copy;
+
+ v2->prev->next = v2_copy;
+ v2->prev = v1_copy;
+ }
+
+ template<unsigned ndim>
+ Edge<ndim> *clipVertex(Edge<ndim> *edge) {
+ Edge<ndim> *prev = edge->prev;
+ Edge<ndim> *next = edge->next;
+ splitEdgeLoop(edge->prev, edge->next);
+ return next;
+ }
+ }
+}
diff --git a/extern/carve/include/carve/mesh_simplify.hpp b/extern/carve/include/carve/mesh_simplify.hpp
new file mode 100644
index 00000000000..1c5169caf58
--- /dev/null
+++ b/extern/carve/include/carve/mesh_simplify.hpp
@@ -0,0 +1,1574 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+#include <carve/mesh.hpp>
+#include <carve/mesh_ops.hpp>
+#include <carve/geom2d.hpp>
+#include <carve/heap.hpp>
+#include <carve/rtree.hpp>
+#include <carve/triangle_intersection.hpp>
+
+#include <fstream>
+#include <string>
+#include <utility>
+#include <set>
+#include <algorithm>
+#include <vector>
+
+#include "write_ply.hpp"
+
+
+namespace carve {
+ namespace mesh {
+
+
+ class MeshSimplifier {
+ typedef carve::mesh::MeshSet<3> meshset_t;
+ typedef carve::mesh::Mesh<3> mesh_t;
+ typedef mesh_t::vertex_t vertex_t;
+ typedef vertex_t::vector_t vector_t;
+ typedef mesh_t::edge_t edge_t;
+ typedef mesh_t::face_t face_t;
+ typedef face_t::aabb_t aabb_t;
+
+ typedef carve::geom::RTreeNode<3, carve::mesh::Face<3> *> face_rtree_t;
+
+
+ struct EdgeInfo {
+ edge_t *edge;
+ double delta_v;
+
+ double c[4];
+ double l[2], t1[2], t2[2];
+ size_t heap_idx;
+
+ void update() {
+ const vertex_t *v1 = edge->vert;
+ const vertex_t *v2 = edge->next->vert;
+ const vertex_t *v3 = edge->next->next->vert;
+ const vertex_t *v4 = edge->rev ? edge->rev->next->next->vert : NULL;
+
+ l[0] = (v1->v - v2->v).length();
+
+ t1[0] = (v3->v - v1->v).length();
+ t1[1] = (v3->v - v2->v).length();
+
+ c[0] = std::max((t1[0] + t1[1]) / l[0] - 1.0, 0.0);
+
+ if (v4) {
+ l[1] = (v3->v - v4->v).length();
+ t2[0] = (v4->v - v1->v).length();
+ t2[1] = (v4->v - v2->v).length();
+ c[1] = std::max((t2[0] + t2[1]) / l[0] - 1.0, 0.0);
+ c[2] = std::max((t1[0] + t2[0]) / l[1] - 1.0, 0.0);
+ c[3] = std::max((t1[1] + t2[1]) / l[1] - 1.0, 0.0);
+ delta_v = carve::geom3d::tetrahedronVolume(v1->v, v2->v, v3->v, v4->v);
+ } else {
+ l[1] = 0.0;
+ t2[0] = t2[1] = 0.0;
+ c[1] = c[2] = c[3] = 0.0;
+ delta_v = 0.0;
+ }
+ }
+
+ EdgeInfo(edge_t *e) : edge(e) {
+ update();
+ }
+
+ EdgeInfo() : edge(NULL) {
+ delta_v = 0.0;
+ c[0] = c[1] = c[2] = c[3] = 0.0;
+ l[0] = l[1] = 0.0;
+ t1[0] = t1[1] = 0.0;
+ t2[0] = t2[1] = 0.0;
+ }
+
+ struct NotifyPos {
+ void operator()(EdgeInfo *edge, size_t pos) const { edge->heap_idx = pos; }
+ void operator()(EdgeInfo &edge, size_t pos) const { edge.heap_idx = pos; }
+ };
+ };
+
+
+
+ struct FlippableBase {
+ double min_dp;
+
+ FlippableBase(double _min_dp = 0.0) : min_dp(_min_dp) {
+ }
+
+ bool open(const EdgeInfo *e) const {
+ return e->edge->rev == NULL;
+ }
+
+ bool wouldCreateDegenerateEdge(const EdgeInfo *e) const {
+ return e->edge->prev->vert == e->edge->rev->prev->vert;
+ }
+
+ bool flippable_DotProd(const EdgeInfo *e) const {
+ using carve::geom::dot;
+ using carve::geom::cross;
+
+ if (open(e)) return false;
+
+ edge_t *edge = e->edge;
+
+ const vertex_t *v1 = edge->vert;
+ const vertex_t *v2 = edge->next->vert;
+ const vertex_t *v3 = edge->next->next->vert;
+ const vertex_t *v4 = edge->rev->next->next->vert;
+
+ if (dot(cross(v3->v - v2->v, v1->v - v2->v).normalized(),
+ cross(v4->v - v1->v, v2->v - v1->v).normalized()) < min_dp) return false;
+
+ if (dot(cross(v3->v - v4->v, v1->v - v4->v).normalized(),
+ cross(v4->v - v3->v, v2->v - v3->v).normalized()) < min_dp) return false;
+
+ return true;
+ }
+
+ virtual bool canFlip(const EdgeInfo *e) const {
+ return !open(e) && !wouldCreateDegenerateEdge(e) && score(e) > 0.0;
+ }
+
+ virtual double score(const EdgeInfo *e) const {
+ return std::min(e->c[2], e->c[3]) - std::min(e->c[0], e->c[1]);
+ }
+
+ class Priority {
+ Priority &operator=(const Priority &);
+ const FlippableBase &flip;
+
+ public:
+ Priority(const FlippableBase &_flip) : flip(_flip) {}
+ bool operator()(const EdgeInfo *a, const EdgeInfo *b) const { return flip.score(a) > flip.score(b); }
+ };
+
+ Priority priority() const {
+ return Priority(*this);
+ }
+ };
+
+
+
+ struct FlippableConservative : public FlippableBase {
+ FlippableConservative() : FlippableBase(0.0) {
+ }
+
+ bool connectsAlmostCoplanarFaces(const EdgeInfo *e) const {
+ // XXX: remove hard coded constants.
+ if (e->c[0] < 1e-10 || e->c[1] < 1e-10) return true;
+ return fabs(carve::geom::dot(e->edge->face->plane.N, e->edge->rev->face->plane.N) - 1.0) < 1e-10;
+ }
+
+ bool connectsExactlyCoplanarFaces(const EdgeInfo *e) const {
+ edge_t *edge = e->edge;
+ return
+ carve::geom3d::orient3d(edge->vert->v,
+ edge->next->vert->v,
+ edge->next->next->vert->v,
+ edge->rev->next->next->vert->v) == 0.0 &&
+ carve::geom3d::orient3d(edge->rev->vert->v,
+ edge->rev->next->vert->v,
+ edge->rev->next->next->vert->v,
+ edge->next->next->vert->v) == 0.0;
+ }
+
+ virtual bool canFlip(const EdgeInfo *e) const {
+ return FlippableBase::canFlip(e) && connectsExactlyCoplanarFaces(e) && flippable_DotProd(e);
+ }
+ };
+
+
+
+ struct FlippableColinearPair : public FlippableBase {
+
+ FlippableColinearPair() {
+ }
+
+
+ virtual double score(const EdgeInfo *e) const {
+ return e->l[0] - e->l[1];
+ }
+
+ virtual bool canFlip(const EdgeInfo *e) const {
+ if (!FlippableBase::canFlip(e)) return false;
+
+ if (e->c[0] > 1e-3 || e->c[1] > 1e-3) return false;
+
+ return true;
+ }
+ };
+
+
+
+ struct Flippable : public FlippableBase {
+ double min_colinearity;
+ double min_delta_v;
+
+ Flippable(double _min_colinearity,
+ double _min_delta_v,
+ double _min_normal_angle) :
+ FlippableBase(cos(_min_normal_angle)),
+ min_colinearity(_min_colinearity),
+ min_delta_v(_min_delta_v) {
+ }
+
+
+ virtual bool canFlip(const EdgeInfo *e) const {
+ if (!FlippableBase::canFlip(e)) return false;
+
+ if (fabs(e->delta_v) > min_delta_v) return false;
+
+ // if (std::min(e->c[0], e->c[1]) > min_colinearity) return false;
+
+ return flippable_DotProd(e);
+ }
+ };
+
+
+
+ struct EdgeMerger {
+ double min_edgelen;
+
+ virtual bool canMerge(const EdgeInfo *e) const {
+ return e->l[0] <= min_edgelen;
+ }
+
+ EdgeMerger(double _min_edgelen) : min_edgelen(_min_edgelen) {
+ }
+
+ double score(const EdgeInfo *e) const {
+ return min_edgelen - e->l[0];
+ }
+
+ class Priority {
+ Priority &operator=(const Priority &);
+
+ public:
+ const EdgeMerger &merger;
+ Priority(const EdgeMerger &_merger) : merger(_merger) {
+ }
+ bool operator()(const EdgeInfo *a, const EdgeInfo *b) const {
+ // collapse edges in order from shortest to longest.
+ return merger.score(a) < merger.score(b);
+ }
+ };
+
+ Priority priority() const {
+ return Priority(*this);
+ }
+ };
+
+
+
+ typedef std::unordered_map<edge_t *, EdgeInfo *> edge_info_map_t;
+ std::unordered_map<edge_t *, EdgeInfo *> edge_info;
+
+
+
+ void initEdgeInfo(mesh_t *mesh) {
+ for (size_t i = 0; i < mesh->faces.size(); ++i) {
+ edge_t *e = mesh->faces[i]->edge;
+ do {
+ edge_info[e] = new EdgeInfo(e);
+ e = e->next;
+ } while (e != mesh->faces[i]->edge);
+ }
+ }
+
+
+
+ void initEdgeInfo(meshset_t *meshset) {
+ for (size_t m = 0; m < meshset->meshes.size(); ++m) {
+ mesh_t *mesh = meshset->meshes[m];
+ initEdgeInfo(mesh);
+ }
+ }
+
+
+
+ void clearEdgeInfo() {
+ for (edge_info_map_t::iterator i = edge_info.begin(); i != edge_info.end(); ++i) {
+ delete (*i).second;
+ }
+ }
+
+
+
+ void updateEdgeFlipHeap(std::vector<EdgeInfo *> &edge_heap,
+ edge_t *edge,
+ const FlippableBase &flipper) {
+ std::unordered_map<edge_t *, EdgeInfo *>::const_iterator i = edge_info.find(edge);
+ CARVE_ASSERT(i != edge_info.end());
+ EdgeInfo *e = (*i).second;
+
+ bool heap_pre = e->heap_idx != ~0U;
+ (*i).second->update();
+ bool heap_post = edge->v1() < edge->v2() && flipper.canFlip(e);
+
+ if (!heap_pre && heap_post) {
+ edge_heap.push_back(e);
+ carve::heap::push_heap(edge_heap.begin(),
+ edge_heap.end(),
+ flipper.priority(),
+ EdgeInfo::NotifyPos());
+ } else if (heap_pre && !heap_post) {
+ CARVE_ASSERT(edge_heap[e->heap_idx] == e);
+ carve::heap::remove_heap(edge_heap.begin(),
+ edge_heap.end(),
+ edge_heap.begin() + e->heap_idx,
+ flipper.priority(),
+ EdgeInfo::NotifyPos());
+ CARVE_ASSERT(edge_heap.back() == e);
+ edge_heap.pop_back();
+ e->heap_idx = ~0U;
+ } else if (heap_pre && heap_post) {
+ CARVE_ASSERT(edge_heap[e->heap_idx] == e);
+ carve::heap::adjust_heap(edge_heap.begin(),
+ edge_heap.end(),
+ edge_heap.begin() + e->heap_idx,
+ flipper.priority(),
+ EdgeInfo::NotifyPos());
+ CARVE_ASSERT(edge_heap[e->heap_idx] == e);
+ }
+ }
+
+
+ std::string vk(const vertex_t *v1,
+ const vertex_t *v2,
+ const vertex_t *v3) {
+ const vertex_t *v[3];
+ v[0] = v1; v[1] = v2; v[2] = v3;
+ std::sort(v, v+3);
+ std::ostringstream s;
+ s << v[0] << ";" << v[1] << ";" << v[2];
+ return s.str();
+ }
+
+ std::string vk(const face_t *f) { return vk(f->edge->vert, f->edge->next->vert, f->edge->next->next->vert); }
+
+ int mapTriangle(const face_t *face,
+ const vertex_t *remap1, const vertex_t *remap2,
+ const vector_t &tgt,
+ vector_t tri[3]) {
+ edge_t *edge = face->edge;
+ int n_remaps = 0;
+ for (size_t i = 0; i < 3; edge = edge->next, ++i) {
+ if (edge->vert == remap1) { tri[i] = tgt; ++n_remaps; }
+ else if (edge->vert == remap2) { tri[i] = tgt; ++n_remaps; }
+ else { tri[i] = edge->vert->v; }
+ }
+ return n_remaps;
+ }
+
+ template<typename iter1_t, typename iter2_t>
+ int countIntersectionPairs(iter1_t fabegin, iter1_t faend,
+ iter2_t fbbegin, iter2_t fbend,
+ const vertex_t *remap1, const vertex_t *remap2,
+ const vector_t &tgt) {
+ vector_t tri_a[3], tri_b[3];
+ int remap_a, remap_b;
+ std::set<std::pair<const face_t *, const face_t *> > ints;
+
+ for (iter1_t i = fabegin; i != faend; ++i) {
+ remap_a = mapTriangle(*i, remap1, remap2, tgt, tri_a);
+ if (remap_a >= 2) continue;
+ for (iter2_t j = fbbegin; j != fbend; ++j) {
+ remap_b = mapTriangle(*j, remap1, remap2, tgt, tri_b);
+ if (remap_b >= 2) continue;
+ if (carve::geom::triangle_intersection_exact(tri_a, tri_b) == carve::geom::TR_TYPE_INT) {
+ ints.insert(std::make_pair(std::min(*i, *j), std::max(*i, *j)));
+ }
+ }
+ }
+
+ return ints.size();
+ }
+
+ int countIntersections(const vertex_t *v1,
+ const vertex_t *v2,
+ const vertex_t *v3,
+ const std::vector<face_t *> &faces) {
+ int n_int = 0;
+ vector_t tri_a[3], tri_b[3];
+ tri_a[0] = v1->v;
+ tri_a[1] = v2->v;
+ tri_a[2] = v3->v;
+
+ for (std::vector<face_t *>::const_iterator i = faces.begin(); i != faces.end(); ++i) {
+ face_t *fb = *i;
+ if (fb->nEdges() != 3) continue;
+ tri_b[0] = fb->edge->vert->v;
+ tri_b[1] = fb->edge->next->vert->v;
+ tri_b[2] = fb->edge->next->next->vert->v;
+
+ if (carve::geom::triangle_intersection_exact(tri_a, tri_b) == carve::geom::TR_TYPE_INT) {
+ n_int++;
+ }
+ }
+ return n_int;
+ }
+
+
+
+ int _findSelfIntersections(const face_rtree_t *a_node,
+ const face_rtree_t *b_node,
+ bool descend_a = true) {
+ int r = 0;
+
+ if (!a_node->bbox.intersects(b_node->bbox)) {
+ return 0;
+ }
+
+ if (a_node->child && (descend_a || !b_node->child)) {
+ for (face_rtree_t *node = a_node->child; node; node = node->sibling) {
+ r += _findSelfIntersections(node, b_node, false);
+ }
+ } else if (b_node->child) {
+ for (face_rtree_t *node = b_node->child; node; node = node->sibling) {
+ r += _findSelfIntersections(a_node, node, true);
+ }
+ } else {
+ for (size_t i = 0; i < a_node->data.size(); ++i) {
+ face_t *fa = a_node->data[i];
+ if (fa->nVertices() != 3) continue;
+
+ aabb_t aabb_a = fa->getAABB();
+
+ vector_t tri_a[3];
+ tri_a[0] = fa->edge->vert->v;
+ tri_a[1] = fa->edge->next->vert->v;
+ tri_a[2] = fa->edge->next->next->vert->v;
+
+ if (!aabb_a.intersects(b_node->bbox)) continue;
+
+ for (size_t j = 0; j < b_node->data.size(); ++j) {
+ face_t *fb = b_node->data[j];
+ if (fb->nVertices() != 3) continue;
+
+ vector_t tri_b[3];
+ tri_b[0] = fb->edge->vert->v;
+ tri_b[1] = fb->edge->next->vert->v;
+ tri_b[2] = fb->edge->next->next->vert->v;
+
+ if (carve::geom::triangle_intersection_exact(tri_a, tri_b) == carve::geom::TR_TYPE_INT) {
+ ++r;
+ }
+ }
+ }
+ }
+
+ return r;
+ }
+
+
+
+ int countSelfIntersections(meshset_t *meshset) {
+ int n_ints = 0;
+ face_rtree_t *tree = face_rtree_t::construct_STR(meshset->faceBegin(), meshset->faceEnd(), 4, 4);
+
+ for (meshset_t::face_iter f = meshset->faceBegin(); f != meshset->faceEnd(); ++f) {
+ face_t *fa = *f;
+ if (fa->nVertices() != 3) continue;
+
+ vector_t tri_a[3];
+ tri_a[0] = fa->edge->vert->v;
+ tri_a[1] = fa->edge->next->vert->v;
+ tri_a[2] = fa->edge->next->next->vert->v;
+
+ std::vector<face_t *> near_faces;
+ tree->search(fa->getAABB(), std::back_inserter(near_faces));
+
+ for (size_t f2 = 0; f2 < near_faces.size(); ++f2) {
+ const face_t *fb = near_faces[f2];
+ if (fb->nVertices() != 3) continue;
+
+ if (fa >= fb) continue;
+
+ vector_t tri_b[3];
+ tri_b[0] = fb->edge->vert->v;
+ tri_b[1] = fb->edge->next->vert->v;
+ tri_b[2] = fb->edge->next->next->vert->v;
+
+ if (carve::geom::triangle_intersection_exact(tri_a, tri_b) == carve::geom::TR_TYPE_INT) {
+ ++n_ints;
+ }
+ }
+ }
+
+ delete tree;
+
+ return n_ints;
+ }
+
+ size_t flipEdges(meshset_t *mesh,
+ const FlippableBase &flipper) {
+ face_rtree_t *tree = face_rtree_t::construct_STR(mesh->faceBegin(), mesh->faceEnd(), 4, 4);
+
+ size_t n_mods = 0;
+
+ std::vector<EdgeInfo *> edge_heap;
+
+ edge_heap.reserve(edge_info.size());
+
+ for (edge_info_map_t::iterator i = edge_info.begin();
+ i != edge_info.end();
+ ++i) {
+ EdgeInfo *e = (*i).second;
+ e->update();
+ if (e->edge->v1() < e->edge->v2() && flipper.canFlip(e)) {
+ edge_heap.push_back(e);
+ } else {
+ e->heap_idx = ~0U;
+ }
+ }
+
+ carve::heap::make_heap(edge_heap.begin(),
+ edge_heap.end(),
+ flipper.priority(),
+ EdgeInfo::NotifyPos());
+
+ while (edge_heap.size()) {
+// std::cerr << "test" << std::endl;
+// for (size_t m = 0; m < mesh->meshes.size(); ++m) {
+// for (size_t f = 0; f < mesh->meshes[m]->faces.size(); ++f) {
+// if (mesh->meshes[m]->faces[f]->edge) mesh->meshes[m]->faces[f]->edge->validateLoop();
+// }
+// }
+
+ carve::heap::pop_heap(edge_heap.begin(),
+ edge_heap.end(),
+ flipper.priority(),
+ EdgeInfo::NotifyPos());
+ EdgeInfo *e = edge_heap.back();
+// std::cerr << "flip " << e << std::endl;
+ edge_heap.pop_back();
+ e->heap_idx = ~0U;
+
+ aabb_t aabb;
+ aabb = e->edge->face->getAABB();
+ aabb.unionAABB(e->edge->rev->face->getAABB());
+
+ std::vector<face_t *> overlapping;
+ tree->search(aabb, std::back_inserter(overlapping));
+
+ // overlapping.erase(e->edge->face);
+ // overlapping.erase(e->edge->rev->face);
+
+ const vertex_t *v1 = e->edge->vert;
+ const vertex_t *v2 = e->edge->next->vert;
+ const vertex_t *v3 = e->edge->next->next->vert;
+ const vertex_t *v4 = e->edge->rev->next->next->vert;
+
+ int n_int1 = countIntersections(v1, v2, v3, overlapping);
+ int n_int2 = countIntersections(v2, v1, v4, overlapping);
+ int n_int3 = countIntersections(v3, v4, v2, overlapping);
+ int n_int4 = countIntersections(v4, v3, v1, overlapping);
+
+ if ((n_int3 + n_int4) - (n_int1 + n_int2) > 0) {
+ std::cerr << "delta[ints] = " << (n_int3 + n_int4) - (n_int1 + n_int2) << std::endl;
+ // avoid creating a self intersection.
+ continue;
+ }
+
+ n_mods++;
+ CARVE_ASSERT(flipper.canFlip(e));
+ edge_info[e->edge]->update();
+ edge_info[e->edge->rev]->update();
+
+ carve::mesh::flipTriEdge(e->edge);
+
+ tree->updateExtents(aabb);
+
+ updateEdgeFlipHeap(edge_heap, e->edge, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->rev, flipper);
+
+ CARVE_ASSERT(!flipper.canFlip(e));
+
+ updateEdgeFlipHeap(edge_heap, e->edge->next, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->next->next, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->rev->next, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->rev->next->next, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->next->rev, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->next->next->rev, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->rev->next->rev, flipper);
+ updateEdgeFlipHeap(edge_heap, e->edge->rev->next->next->rev, flipper);
+ }
+
+ delete tree;
+
+ return n_mods;
+ }
+
+
+
+ void removeFromEdgeMergeHeap(std::vector<EdgeInfo *> &edge_heap,
+ EdgeInfo *edge,
+ const EdgeMerger &merger) {
+ if (edge->heap_idx != ~0U) {
+ CARVE_ASSERT(edge_heap[edge->heap_idx] == edge);
+ carve::heap::remove_heap(edge_heap.begin(),
+ edge_heap.end(),
+ edge_heap.begin() + edge->heap_idx,
+ merger.priority(),
+ EdgeInfo::NotifyPos());
+ CARVE_ASSERT(edge_heap.back() == edge);
+ edge_heap.pop_back();
+ edge->heap_idx = ~0U;
+ }
+ }
+
+ void updateEdgeMergeHeap(std::vector<EdgeInfo *> &edge_heap,
+ EdgeInfo *edge,
+ const EdgeMerger &merger) {
+ bool heap_pre = edge->heap_idx != ~0U;
+ edge->update();
+ bool heap_post = merger.canMerge(edge);
+
+ if (!heap_pre && heap_post) {
+ edge_heap.push_back(edge);
+ carve::heap::push_heap(edge_heap.begin(),
+ edge_heap.end(),
+ merger.priority(),
+ EdgeInfo::NotifyPos());
+ } else if (heap_pre && !heap_post) {
+ CARVE_ASSERT(edge_heap[edge->heap_idx] == edge);
+ carve::heap::remove_heap(edge_heap.begin(),
+ edge_heap.end(),
+ edge_heap.begin() + edge->heap_idx,
+ merger.priority(),
+ EdgeInfo::NotifyPos());
+ CARVE_ASSERT(edge_heap.back() == edge);
+ edge_heap.pop_back();
+ edge->heap_idx = ~0U;
+ } else if (heap_pre && heap_post) {
+ CARVE_ASSERT(edge_heap[edge->heap_idx] == edge);
+ carve::heap::adjust_heap(edge_heap.begin(),
+ edge_heap.end(),
+ edge_heap.begin() + edge->heap_idx,
+ merger.priority(),
+ EdgeInfo::NotifyPos());
+ CARVE_ASSERT(edge_heap[edge->heap_idx] == edge);
+ }
+ }
+
+
+
+ // collapse edges edges based upon the predicate implemented by EdgeMerger.
+ size_t collapseEdges(meshset_t *mesh,
+ const EdgeMerger &merger) {
+ face_rtree_t *tree = face_rtree_t::construct_STR(mesh->faceBegin(), mesh->faceEnd(), 4, 4);
+
+ size_t n_mods = 0;
+
+ std::vector<EdgeInfo *> edge_heap;
+ std::unordered_map<vertex_t *, std::set<EdgeInfo *> > vert_to_edges;
+
+ edge_heap.reserve(edge_info.size());
+
+ for (edge_info_map_t::iterator i = edge_info.begin();
+ i != edge_info.end();
+ ++i) {
+ EdgeInfo *e = (*i).second;
+
+ vert_to_edges[e->edge->v1()].insert(e);
+ vert_to_edges[e->edge->v2()].insert(e);
+
+ if (merger.canMerge(e)) {
+ edge_heap.push_back(e);
+ } else {
+ e->heap_idx = ~0U;
+ }
+ }
+
+ carve::heap::make_heap(edge_heap.begin(),
+ edge_heap.end(),
+ merger.priority(),
+ EdgeInfo::NotifyPos());
+
+ while (edge_heap.size()) {
+// std::cerr << "test" << std::endl;
+// for (size_t m = 0; m < mesh->meshes.size(); ++m) {
+// for (size_t f = 0; f < mesh->meshes[m]->faces.size(); ++f) {
+// if (mesh->meshes[m]->faces[f]->edge) mesh->meshes[m]->faces[f]->edge->validateLoop();
+// }
+// }
+ carve::heap::pop_heap(edge_heap.begin(),
+ edge_heap.end(),
+ merger.priority(),
+ EdgeInfo::NotifyPos());
+ EdgeInfo *e = edge_heap.back();
+ edge_heap.pop_back();
+ e->heap_idx = ~0U;
+
+ edge_t *edge = e->edge;
+ vertex_t *v1 = edge->v1();
+ vertex_t *v2 = edge->v2();
+
+ std::set<face_t *> affected_faces;
+ for (std::set<EdgeInfo *>::iterator f = vert_to_edges[v1].begin();
+ f != vert_to_edges[v1].end();
+ ++f) {
+ affected_faces.insert((*f)->edge->face);
+ affected_faces.insert((*f)->edge->rev->face);
+ }
+ for (std::set<EdgeInfo *>::iterator f = vert_to_edges[v2].begin();
+ f != vert_to_edges[v2].end();
+ ++f) {
+ affected_faces.insert((*f)->edge->face);
+ affected_faces.insert((*f)->edge->rev->face);
+ }
+
+ std::vector<EdgeInfo *> edges_to_merge;
+ std::vector<EdgeInfo *> v1_incident;
+ std::vector<EdgeInfo *> v2_incident;
+
+ std::set_intersection(vert_to_edges[v1].begin(), vert_to_edges[v1].end(),
+ vert_to_edges[v2].begin(), vert_to_edges[v2].end(),
+ std::back_inserter(edges_to_merge));
+
+ CARVE_ASSERT(edges_to_merge.size() > 0);
+
+ std::set_difference(vert_to_edges[v1].begin(), vert_to_edges[v1].end(),
+ edges_to_merge.begin(), edges_to_merge.end(),
+ std::back_inserter(v1_incident));
+ std::set_difference(vert_to_edges[v2].begin(), vert_to_edges[v2].end(),
+ edges_to_merge.begin(), edges_to_merge.end(),
+ std::back_inserter(v2_incident));
+
+ vector_t aabb_min, aabb_max;
+ assign_op(aabb_min, v1->v, v2->v, carve::util::min_functor());
+ assign_op(aabb_max, v1->v, v2->v, carve::util::max_functor());
+
+ for (size_t i = 0; i < v1_incident.size(); ++i) {
+ assign_op(aabb_min, aabb_min, v1_incident[i]->edge->v1()->v, carve::util::min_functor());
+ assign_op(aabb_max, aabb_max, v1_incident[i]->edge->v1()->v, carve::util::max_functor());
+ assign_op(aabb_min, aabb_min, v1_incident[i]->edge->v2()->v, carve::util::min_functor());
+ assign_op(aabb_max, aabb_max, v1_incident[i]->edge->v2()->v, carve::util::max_functor());
+ }
+
+ for (size_t i = 0; i < v2_incident.size(); ++i) {
+ assign_op(aabb_min, aabb_min, v2_incident[i]->edge->v1()->v, carve::util::min_functor());
+ assign_op(aabb_max, aabb_max, v2_incident[i]->edge->v1()->v, carve::util::max_functor());
+ assign_op(aabb_min, aabb_min, v2_incident[i]->edge->v2()->v, carve::util::min_functor());
+ assign_op(aabb_max, aabb_max, v2_incident[i]->edge->v2()->v, carve::util::max_functor());
+ }
+
+ aabb_t aabb;
+ aabb.fit(aabb_min, aabb_max);
+
+ std::vector<face_t *> near_faces;
+ tree->search(aabb, std::back_inserter(near_faces));
+
+ double frac = 0.5; // compute this based upon v1_incident and v2_incident?
+ vector_t merge = frac * v1->v + (1 - frac) * v2->v;
+
+ int i1 = countIntersectionPairs(affected_faces.begin(), affected_faces.end(),
+ near_faces.begin(), near_faces.end(),
+ NULL, NULL, merge);
+ int i2 = countIntersectionPairs(affected_faces.begin(), affected_faces.end(),
+ near_faces.begin(), near_faces.end(),
+ v1, v2, merge);
+ if (i2 != i1) {
+ std::cerr << "near faces: " << near_faces.size() << " affected faces: " << affected_faces.size() << std::endl;
+ std::cerr << "merge delta[ints] = " << i2 - i1 << " pre: " << i1 << " post: " << i2 << std::endl;
+ if (i2 > i1) continue;
+ }
+
+ std::cerr << "collapse " << e << std::endl;
+
+ v2->v = merge;
+ ++n_mods;
+
+ for (size_t i = 0; i < v1_incident.size(); ++i) {
+ if (v1_incident[i]->edge->vert == v1) {
+ v1_incident[i]->edge->vert = v2;
+ }
+ }
+
+ for (size_t i = 0; i < v1_incident.size(); ++i) {
+ updateEdgeMergeHeap(edge_heap, v1_incident[i], merger);
+ }
+
+ for (size_t i = 0; i < v2_incident.size(); ++i) {
+ updateEdgeMergeHeap(edge_heap, v2_incident[i], merger);
+ }
+
+ vert_to_edges[v2].insert(vert_to_edges[v1].begin(), vert_to_edges[v1].end());
+ vert_to_edges.erase(v1);
+
+ for (size_t i = 0; i < edges_to_merge.size(); ++i) {
+ EdgeInfo *e = edges_to_merge[i];
+
+ removeFromEdgeMergeHeap(edge_heap, e, merger);
+ edge_info.erase(e->edge);
+
+ vert_to_edges[v1].erase(e);
+ vert_to_edges[v2].erase(e);
+
+ face_t *f1 = e->edge->face;
+
+ e->edge->removeHalfEdge();
+
+ if (f1->n_edges == 2) {
+ edge_t *e1 = f1->edge;
+ edge_t *e2 = f1->edge->next;
+ if (e1->rev) e1->rev->rev = e2->rev;
+ if (e2->rev) e2->rev->rev = e1->rev;
+ EdgeInfo *e1i = edge_info[e1];
+ EdgeInfo *e2i = edge_info[e2];
+ CARVE_ASSERT(e1i != NULL);
+ CARVE_ASSERT(e2i != NULL);
+ vert_to_edges[e1->v1()].erase(e1i);
+ vert_to_edges[e1->v2()].erase(e1i);
+ vert_to_edges[e2->v1()].erase(e2i);
+ vert_to_edges[e2->v2()].erase(e2i);
+ removeFromEdgeMergeHeap(edge_heap, e1i, merger);
+ removeFromEdgeMergeHeap(edge_heap, e2i, merger);
+ edge_info.erase(e1);
+ edge_info.erase(e2);
+ f1->clearEdges();
+ tree->remove(f1, aabb);
+
+ delete e1i;
+ delete e2i;
+ }
+ delete e;
+ }
+
+ tree->updateExtents(aabb);
+ }
+
+ delete tree;
+
+ return n_mods;
+ }
+
+
+
+ size_t mergeCoplanarFaces(mesh_t *mesh, double min_normal_angle) {
+ std::unordered_set<edge_t *> coplanar_face_edges;
+ double min_dp = cos(min_normal_angle);
+ size_t n_merge = 0;
+
+ for (size_t i = 0; i < mesh->closed_edges.size(); ++i) {
+ edge_t *e = mesh->closed_edges[i];
+ face_t *f1 = e->face;
+ face_t *f2 = e->rev->face;
+
+ if (carve::geom::dot(f1->plane.N, f2->plane.N) < min_dp) {
+ continue;
+ }
+
+ coplanar_face_edges.insert(std::min(e, e->rev));
+ }
+
+ while (coplanar_face_edges.size()) {
+ edge_t *edge = *coplanar_face_edges.begin();
+ if (edge->face == edge->rev->face) {
+ coplanar_face_edges.erase(edge);
+ continue;
+ }
+
+ edge_t *removed = edge->mergeFaces();
+ if (removed == NULL) {
+ coplanar_face_edges.erase(edge);
+ ++n_merge;
+ } else {
+ edge_t *e = removed;
+ do {
+ edge_t *n = e->next;
+ coplanar_face_edges.erase(std::min(e, e->rev));
+ delete e->rev;
+ delete e;
+ e = n;
+ } while (e != removed);
+ }
+ }
+ return n_merge;
+ }
+
+
+
+ uint8_t affected_axes(const face_t *face) {
+ uint8_t r = 0;
+ if (fabs(carve::geom::dot(face->plane.N, carve::geom::VECTOR(1,0,0))) > 0.001) r |= 1;
+ if (fabs(carve::geom::dot(face->plane.N, carve::geom::VECTOR(0,1,0))) > 0.001) r |= 2;
+ if (fabs(carve::geom::dot(face->plane.N, carve::geom::VECTOR(0,0,1))) > 0.001) r |= 4;
+ return r;
+ }
+
+
+
+ double median(std::vector<double> &v) {
+ if (v.size() & 1) {
+ size_t N = v.size() / 2 + 1;
+ std::nth_element(v.begin(), v.begin() + N, v.end());
+ return v[N];
+ } else {
+ size_t N = v.size() / 2;
+ std::nth_element(v.begin(), v.begin() + N, v.end());
+ return (v[N] + *std::min_element(v.begin() + N + 1, v.end())) / 2.0;
+ }
+ }
+
+
+
+ double harmonicmean(const std::vector<double> &v) {
+ double m = 0.0;
+ for (size_t i = 0; i < v.size(); ++i) {
+ m *= v[i];
+ }
+ return pow(m, 1.0 / v.size());
+ }
+
+
+
+ double mean(const std::vector<double> &v) {
+ double m = 0.0;
+ for (size_t i = 0; i < v.size(); ++i) {
+ m += v[i];
+ }
+ return m / v.size();
+ }
+
+
+
+ template<typename iter_t>
+ void snapFaces(iter_t begin, iter_t end, double grid, int axis) {
+ std::set<vertex_t *> vertices;
+ for (iter_t i = begin; i != end; ++i) {
+ face_t *face = *i;
+ edge_t *edge = face->edge;
+ do {
+ vertices.insert(edge->vert);
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+
+ std::vector<double> pos;
+ pos.reserve(vertices.size());
+ for (std::set<vertex_t *>::iterator i = vertices.begin(); i != vertices.end(); ++i) {
+ pos.push_back((*i)->v.v[axis]);
+ }
+
+ double med = median(pos);
+
+ double snap_pos = med;
+ if (grid) snap_pos = round(snap_pos / grid) * grid;
+
+ for (std::set<vertex_t *>::iterator i = vertices.begin(); i != vertices.end(); ++i) {
+ (*i)->v.v[axis] = snap_pos;
+ }
+
+ for (iter_t i = begin; i != end; ++i) {
+ face_t *face = *i;
+ face->recalc();
+ edge_t *edge = face->edge;
+ do {
+ if (edge->rev && edge->rev->face) edge->rev->face->recalc();
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+ }
+
+ carve::geom::plane<3> quantizePlane(const face_t *face,
+ int angle_xy_quantization,
+ int angle_z_quantization) {
+ if (!angle_xy_quantization && !angle_z_quantization) {
+ return face->plane;
+ }
+ carve::geom::vector<3> normal = face->plane.N;
+
+ if (angle_z_quantization) {
+ if (normal.x || normal.y) {
+ double a = asin(std::min(std::max(normal.z, 0.0), 1.0));
+ a = round(a * angle_z_quantization / (M_PI * 2)) * (M_PI * 2) / angle_z_quantization;
+ normal.z = sin(a);
+ double s = sqrt((1 - normal.z * normal.z) / (normal.x * normal.x + normal.y * normal.y));
+ normal.x = normal.x * s;
+ normal.y = normal.y * s;
+ }
+ }
+ if (angle_xy_quantization) {
+ if (normal.x || normal.y) {
+ double a = atan2(normal.y, normal.x);
+ a = round(a * angle_xy_quantization / (M_PI * 2)) * (M_PI * 2) / angle_xy_quantization;
+ double s = sqrt(1 - normal.z * normal.z);
+ s = std::min(std::max(s, 0.0), 1.0);
+ normal.x = cos(a) * s;
+ normal.y = sin(a) * s;
+ }
+ }
+
+ std::cerr << "normal = " << normal << std::endl;
+
+ std::vector<double> d_vec;
+ d_vec.reserve(face->nVertices());
+ edge_t *e = face->edge;
+ do {
+ d_vec.push_back(-carve::geom::dot(normal, e->vert->v));
+ e = e->next;
+ } while (e != face->edge);
+
+ return carve::geom::plane<3>(normal, mean(d_vec));
+ }
+
+
+
+ double summedError(const carve::geom::vector<3> &vert, const std::list<carve::geom::plane<3> > &planes) {
+ double d = 0;
+ for (std::list<carve::geom::plane<3> >::const_iterator i = planes.begin(); i != planes.end(); ++i) {
+ d += fabs(carve::geom::distance2(*i, vert));
+ }
+ return d;
+ }
+
+
+
+ double minimize(carve::geom::vector<3> &vert, const std::list<carve::geom::plane<3> > &planes, int axis) {
+ double num = 0.0;
+ double den = 0.0;
+ int a1 = (axis + 1) % 3;
+ int a2 = (axis + 2) % 3;
+ for (std::list<carve::geom::plane<3> >::const_iterator i = planes.begin(); i != planes.end(); ++i) {
+ const carve::geom::vector<3> &N = (*i).N;
+ const double d = (*i).d;
+ den += N.v[axis] * N.v[axis];
+ num -= N.v[axis] * (N.v[a1] * vert.v[a1] + N.v[a2] * vert.v[a2] + d);
+ }
+ if (fabs(den) < 1e-5) return vert.v[axis];
+ return num / den;
+ }
+
+
+
+ size_t cleanFaceEdges(mesh_t *mesh) {
+ size_t n_removed = 0;
+ for (size_t i = 0; i < mesh->faces.size(); ++i) {
+ face_t *face = mesh->faces[i];
+ edge_t *start = face->edge;
+ edge_t *edge = start;
+ do {
+ if (edge->next == edge->rev || edge->prev == edge->rev) {
+ edge = edge->removeEdge();
+ ++n_removed;
+ start = edge->prev;
+ } else {
+ edge = edge->next;
+ }
+ } while (edge != start);
+ }
+ return n_removed;
+ }
+
+
+
+ size_t cleanFaceEdges(meshset_t *mesh) {
+ size_t n_removed = 0;
+ for (size_t i = 0; i < mesh->meshes.size(); ++i) {
+ n_removed += cleanFaceEdges(mesh->meshes[i]);
+ }
+ return n_removed;
+ }
+
+
+
+ void removeRemnantFaces(mesh_t *mesh) {
+ size_t n = 0;
+ for (size_t i = 0; i < mesh->faces.size(); ++i) {
+ if (mesh->faces[i]->nEdges() == 0) {
+ delete mesh->faces[i];
+ } else {
+ mesh->faces[n++] = mesh->faces[i];
+ }
+ }
+ mesh->faces.resize(n);
+ }
+
+
+
+ void removeRemnantFaces(meshset_t *mesh) {
+ for (size_t i = 0; i < mesh->meshes.size(); ++i) {
+ removeRemnantFaces(mesh->meshes[i]);
+ }
+ }
+
+
+
+ edge_t *removeFin(edge_t *e) {
+ // e and e->next are shared with the same reverse triangle.
+ edge_t *e1 = e->prev;
+ edge_t *e2 = e->rev->next;
+ CARVE_ASSERT(e1->v2() == e2->v1());
+ CARVE_ASSERT(e2->v2() == e1->v1());
+
+ CARVE_ASSERT(e1->rev != e2 && e2->rev != e1);
+
+ edge_t *e1r = e1->rev;
+ edge_t *e2r = e2->rev;
+ if (e1r) e1r->rev = e2r;
+ if (e2r) e2r->rev = e1r;
+
+ face_t *f1 = e1->face;
+ face_t *f2 = e2->face;
+ f1->clearEdges();
+ f2->clearEdges();
+
+ return e1r;
+ }
+
+ size_t removeFin(face_t *face) {
+ if (face->edge == NULL || face->nEdges() != 3) return 0;
+ edge_t *e = face->edge;
+ do {
+ if (e->rev != NULL) {
+ face_t *revface = e->rev->face;
+ if (revface->nEdges() == 3) {
+ if (e->next->rev && e->next->rev->face == revface) {
+ if (e->next->next->rev && e->next->next->rev->face == revface) {
+ // isolated tripair
+ face->clearEdges();
+ revface->clearEdges();
+ return 1;
+ }
+ // fin
+ edge_t *spliced_edge = removeFin(e);
+ return 1 + removeFin(spliced_edge->face);
+ }
+ }
+ }
+ e = e->next;
+ } while (e != face->edge);
+ return 0;
+ }
+
+
+
+ public:
+ // Merge adjacent coplanar faces (where coplanar is determined
+ // by dot-product >= cos(min_normal_angle)).
+ size_t mergeCoplanarFaces(meshset_t *meshset, double min_normal_angle) {
+ size_t n_removed = 0;
+ for (size_t i = 0; i < meshset->meshes.size(); ++i) {
+ n_removed += mergeCoplanarFaces(meshset->meshes[i], min_normal_angle);
+ removeRemnantFaces(meshset->meshes[i]);
+ cleanFaceEdges(meshset->meshes[i]);
+ meshset->meshes[i]->cacheEdges();
+ }
+ return n_removed;
+ }
+
+ size_t improveMesh_conservative(meshset_t *meshset) {
+ initEdgeInfo(meshset);
+ size_t modifications = flipEdges(meshset, FlippableConservative());
+ clearEdgeInfo();
+ return modifications;
+ }
+
+
+
+ size_t improveMesh(meshset_t *meshset,
+ double min_colinearity,
+ double min_delta_v,
+ double min_normal_angle) {
+ initEdgeInfo(meshset);
+ size_t modifications = flipEdges(meshset, Flippable(min_colinearity, min_delta_v, min_normal_angle));
+ clearEdgeInfo();
+ return modifications;
+ }
+
+
+
+ size_t eliminateShortEdges(meshset_t *meshset,
+ double min_length) {
+ initEdgeInfo(meshset);
+ size_t modifications = collapseEdges(meshset, EdgeMerger(min_length));
+ removeRemnantFaces(meshset);
+ clearEdgeInfo();
+ return modifications;
+ }
+
+
+
+ // Snap vertices to grid, aligning almost flat axis-aligned
+ // faces to the axis, and flattening other faces as much as is
+ // possible. Passing a number less than DBL_MIN_EXPONENT (-1021)
+ // turns off snapping to grid (but face alignment is still
+ // performed).
+ void snap(meshset_t *meshset,
+ int log2_grid,
+ int angle_xy_quantization = 0,
+ int angle_z_quantization = 0) {
+ double grid = 0.0;
+ if (log2_grid >= std::numeric_limits<double>::min_exponent) grid = pow(2.0, (double)log2_grid);
+
+ typedef std::unordered_map<face_t *, uint8_t> axis_influence_map_t;
+ axis_influence_map_t axis_influence;
+
+ typedef std::unordered_map<face_t *, std::set<face_t *> > interaction_graph_t;
+ interaction_graph_t interacting_faces;
+
+ for (size_t m = 0; m < meshset->meshes.size(); ++m) {
+ mesh_t *mesh = meshset->meshes[m];
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ face_t *face = mesh->faces[f];
+ axis_influence[face] = affected_axes(face);
+ }
+ }
+
+ std::map<vertex_t *, std::list<carve::geom::plane<3> > > non_axis_vertices;
+ std::unordered_map<vertex_t *, uint8_t> vertex_constraints;
+
+ for (axis_influence_map_t::iterator i = axis_influence.begin(); i != axis_influence.end(); ++i) {
+ face_t *face = (*i).first;
+ uint8_t face_axes = (*i).second;
+ edge_t *edge = face->edge;
+ if (face_axes != 1 && face_axes != 2 && face_axes != 4) {
+ do {
+ non_axis_vertices[edge->vert].push_back(quantizePlane(face,
+ angle_xy_quantization,
+ angle_z_quantization));
+ edge = edge->next;
+ } while (edge != face->edge);
+ } else {
+ interacting_faces[face].insert(face);
+ do {
+ vertex_constraints[edge->vert] |= face_axes;
+
+ if (edge->rev && edge->rev->face) {
+ face_t *face2 = edge->rev->face;
+ uint8_t face2_axes = axis_influence[face2];
+ if (face2_axes == face_axes) {
+ interacting_faces[face].insert(face2);
+ }
+ }
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+ }
+
+ while (interacting_faces.size()) {
+ std::set<face_t *> face_set;
+ uint8_t axes = 0;
+
+ std::set<face_t *> open;
+ open.insert((*interacting_faces.begin()).first);
+ while (open.size()) {
+ face_t *curr = *open.begin();
+ open.erase(open.begin());
+ face_set.insert(curr);
+ axes |= axis_influence[curr];
+ for (interaction_graph_t::data_type::iterator i = interacting_faces[curr].begin(), e = interacting_faces[curr].end(); i != e; ++i) {
+ face_t *f = *i;
+ if (face_set.find(f) != face_set.end()) continue;
+ open.insert(f);
+ }
+ }
+
+ switch (axes) {
+ case 1: snapFaces(face_set.begin(), face_set.end(), grid, 0); break;
+ case 2: snapFaces(face_set.begin(), face_set.end(), grid, 1); break;
+ case 4: snapFaces(face_set.begin(), face_set.end(), grid, 2); break;
+ default: CARVE_FAIL("should not be reached");
+ }
+
+ for (std::set<face_t *>::iterator i = face_set.begin(); i != face_set.end(); ++i) {
+ interacting_faces.erase((*i));
+ }
+ }
+
+ for (std::map<vertex_t *, std::list<carve::geom::plane<3> > >::iterator i = non_axis_vertices.begin(); i != non_axis_vertices.end(); ++i) {
+ vertex_t *vert = (*i).first;
+ std::list<carve::geom::plane<3> > &planes = (*i).second;
+ uint8_t constraint = vertex_constraints[vert];
+
+ if (constraint == 7) continue;
+
+ double d = summedError(vert->v, planes);
+ for (size_t N = 0; ; N = (N+1) % 3) {
+ if (constraint & (1 << N)) continue;
+ vert->v[N] = minimize(vert->v, planes, N);
+ double d_next = summedError(vert->v, planes);
+ if (d - d_next < 1e-20) break;
+ d = d_next;
+ }
+
+ if (grid) {
+ carve::geom::vector<3> v_best = vert->v;
+ double d_best = 0.0;
+
+ for (size_t axes = 0; axes < 8; ++axes) {
+ carve::geom::vector<3> v = vert->v;
+ for (size_t N = 0; N < 3; ++N) {
+ if (constraint & (1 << N)) continue;
+ if (axes & (1<<N)) {
+ v.v[N] = ceil(v.v[N] / grid) * grid;
+ } else {
+ v.v[N] = floor(v.v[N] / grid) * grid;
+ }
+ }
+ double d = summedError(v, planes);
+ if (axes == 0 || d < d_best) {
+ v_best = v;
+ d_best = d;
+ }
+ }
+
+ vert->v = v_best;
+ }
+ }
+ }
+
+
+
+ size_t simplify(meshset_t *meshset,
+ double min_colinearity,
+ double min_delta_v,
+ double min_normal_angle,
+ double min_length) {
+ size_t modifications = 0;
+ size_t n, n_flip, n_merge;
+
+ initEdgeInfo(meshset);
+
+ std::cerr << "initial merge" << std::endl;
+ modifications = collapseEdges(meshset, EdgeMerger(0.0));
+ removeRemnantFaces(meshset);
+
+ do {
+ n_flip = n_merge = 0;
+ // std::cerr << "flip colinear pairs";
+ // n = flipEdges(meshset, FlippableColinearPair());
+ // std::cerr << " " << n << std::endl;
+ // n_flip = n;
+
+ std::cerr << "flip conservative";
+ n = flipEdges(meshset, FlippableConservative());
+ std::cerr << " " << n << std::endl;
+ n_flip += n;
+
+ std::cerr << "flip";
+ n = flipEdges(meshset, Flippable(min_colinearity, min_delta_v, min_normal_angle));
+ std::cerr << " " << n << std::endl;
+ n_flip += n;
+
+ std::cerr << "merge";
+ n = collapseEdges(meshset, EdgeMerger(min_length));
+ removeRemnantFaces(meshset);
+ std::cerr << " " << n << std::endl;
+ n_merge = n;
+
+ modifications += n_flip + n_merge;
+ std::cerr << "stats:" << n_flip << " " << n_merge << std::endl;
+ } while (n_flip || n_merge);
+
+ clearEdgeInfo();
+
+ for (size_t i = 0; i < meshset->meshes.size(); ++i) {
+ meshset->meshes[i]->cacheEdges();
+ }
+
+ return modifications;
+ }
+
+
+
+ size_t removeFins(mesh_t *mesh) {
+ size_t n_removed = 0;
+ for (size_t i = 0; i < mesh->faces.size(); ++i) {
+ n_removed += removeFin(mesh->faces[i]);
+ }
+ if (n_removed) removeRemnantFaces(mesh);
+ return n_removed;
+ }
+
+
+
+ size_t removeFins(meshset_t *meshset) {
+ size_t n_removed = 0;
+ for (size_t i = 0; i < meshset->meshes.size(); ++i) {
+ n_removed += removeFins(meshset->meshes[i]);
+ }
+ return n_removed;
+ }
+
+
+
+ size_t removeLowVolumeManifolds(meshset_t *meshset, double min_abs_volume) {
+ size_t n_removed;
+ for (size_t i = 0; i < meshset->meshes.size(); ++i) {
+ if (fabs(meshset->meshes[i]->volume()) < min_abs_volume) {
+ delete meshset->meshes[i];
+ meshset->meshes[i] = NULL;
+ ++n_removed;
+ }
+ }
+ meshset->meshes.erase(std::remove_if(meshset->meshes.begin(),
+ meshset->meshes.end(),
+ std::bind2nd(std::equal_to<mesh_t *>(), (mesh_t *)NULL)),
+ meshset->meshes.end());
+ return n_removed;
+ }
+
+ struct point_enumerator_t {
+ struct heapval_t {
+ double dist;
+ vector_t pt;
+ heapval_t(double _dist, vector_t _pt) : dist(_dist), pt(_pt) {
+ }
+ heapval_t() {}
+ bool operator==(const heapval_t &other) const { return dist == other.dist && pt == other.pt; }
+ bool operator<(const heapval_t &other) const { return dist > other.dist || (dist == other.dist && pt > other.pt); }
+ };
+
+ vector_t origin;
+ double rounding_fac;
+ heapval_t last;
+ std::vector<heapval_t> heap;
+
+ point_enumerator_t(vector_t _origin, int _base, int _n_dp) : origin(_origin), rounding_fac(pow(_base, _n_dp)), last(-1.0, _origin), heap() {
+ for (size_t i = 0; i < (1 << 3); ++i) {
+ vector_t t = origin;
+ for (size_t j = 0; j < 3; ++j) {
+ if (i & (1U << j)) {
+ t[j] = ceil(t[j] * rounding_fac) / rounding_fac;
+ } else {
+ t[j] = floor(t[j] * rounding_fac) / rounding_fac;
+ }
+ }
+ heap.push_back(heapval_t(carve::geom::distance2(origin, t), t));
+ }
+ std::make_heap(heap.begin(), heap.end());
+ }
+
+ vector_t next() {
+ heapval_t curr;
+ do {
+ CARVE_ASSERT(heap.size());
+ std::pop_heap(heap.begin(), heap.end());
+ curr = heap.back();
+ heap.pop_back();
+ } while (curr == last);
+
+ vector_t t;
+
+ for (int dx = -1; dx <= +1; ++dx) {
+ t.x = floor(curr.pt.x * rounding_fac + dx) / rounding_fac;
+ for (int dy = -1; dy <= +1; ++dy) {
+ t.y = floor(curr.pt.y * rounding_fac + dy) / rounding_fac;
+ for (int dz = -1; dz <= +1; ++dz) {
+ t.z = floor(curr.pt.z * rounding_fac + dz) / rounding_fac;
+ heapval_t h2(carve::geom::distance2(origin, t), t);
+ if (h2 < curr) {
+ heap.push_back(h2);
+ std::push_heap(heap.begin(), heap.end());
+ }
+ }
+ }
+ }
+ last = curr;
+ return curr.pt;
+ }
+ };
+
+ struct quantization_info_t {
+ point_enumerator_t *pt;
+ std::set<face_t *> faces;
+
+ quantization_info_t() : pt(NULL), faces() {
+ }
+
+ ~quantization_info_t() {
+ if (pt) delete pt;
+ }
+
+ aabb_t getAABB() const {
+ std::set<face_t *>::iterator i = faces.begin();
+ aabb_t aabb = (*i)->getAABB();
+ while (++i != faces.end()) {
+ aabb.unionAABB((*i)->getAABB());
+ }
+ return aabb;
+ }
+ };
+
+ void selfIntersectionAwareQuantize(meshset_t *meshset, int base, int n_dp) {
+ typedef std::unordered_map<vertex_t *, quantization_info_t> vfsmap_t;
+
+ vfsmap_t vertex_qinfo;
+
+ for (size_t m = 0; m < meshset->meshes.size(); ++m) {
+ mesh_t *mesh = meshset->meshes[m];
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ face_t *face = mesh->faces[f];
+ edge_t *e = face->edge;
+ do {
+ vertex_qinfo[e->vert].faces.insert(face);
+ e = e->next;
+ } while (e != face->edge);
+ }
+ }
+
+ face_rtree_t *tree = face_rtree_t::construct_STR(meshset->faceBegin(), meshset->faceEnd(), 4, 4);
+
+ for (vfsmap_t::iterator i = vertex_qinfo.begin(); i != vertex_qinfo.end(); ++i) {
+ (*i).second.pt = new point_enumerator_t((*i).first->v, base, n_dp);
+ }
+
+ while (vertex_qinfo.size()) {
+ std::vector<vertex_t *> quantized;
+
+ std::cerr << "vertex_qinfo.size() == " << vertex_qinfo.size() << std::endl;
+
+ for (vfsmap_t::iterator i = vertex_qinfo.begin(); i != vertex_qinfo.end(); ++i) {
+ vertex_t *vert = (*i).first;
+ quantization_info_t &qi = (*i).second;
+ vector_t q_pt = qi.pt->next();
+ aabb_t aabb = qi.getAABB();
+ aabb.unionAABB(aabb_t(q_pt));
+
+ std::vector<face_t *> overlapping;
+ tree->search(aabb, std::back_inserter(overlapping));
+
+
+ int n_intersections = countIntersectionPairs(qi.faces.begin(), qi.faces.end(),
+ overlapping.begin(), overlapping.end(),
+ vert, NULL, q_pt);
+
+ if (n_intersections == 0) {
+ vert->v = q_pt;
+ quantized.push_back((*i).first);
+ tree->updateExtents(aabb);
+ }
+ }
+ for (size_t i = 0; i < quantized.size(); ++i) {
+ vertex_qinfo.erase(quantized[i]);
+ }
+
+ if (!quantized.size()) break;
+ }
+ }
+
+
+ };
+ }
+}
diff --git a/extern/carve/include/carve/octree_decl.hpp b/extern/carve/include/carve/octree_decl.hpp
new file mode 100644
index 00000000000..a7e3ff5c77a
--- /dev/null
+++ b/extern/carve/include/carve/octree_decl.hpp
@@ -0,0 +1,193 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom3d.hpp>
+#include <carve/aabb.hpp>
+
+#include <carve/polyhedron_base.hpp>
+
+namespace carve {
+
+ namespace csg {
+
+ const double SLACK_FACTOR=1.0009765625;
+ const unsigned FACE_SPLIT_THRESHOLD=50U;
+ const unsigned EDGE_SPLIT_THRESHOLD=50U;
+ const unsigned POINT_SPLIT_THRESHOLD=20U;
+ const unsigned MAX_SPLIT_DEPTH=32;
+
+ class Octree {
+
+ public:
+ class Node {
+ private:
+ Node(const Node &node); // undefined.
+ Node &operator=(const Node &node); // undefined.
+
+ public:
+ Node *parent;
+ Node *children[8];
+ bool is_leaf;
+
+ carve::geom3d::Vector min;
+ carve::geom3d::Vector max;
+
+ std::vector<const carve::poly::Geometry<3>::face_t *> faces;
+ std::vector<const carve::poly::Geometry<3>::edge_t *> edges;
+ std::vector<const carve::poly::Geometry<3>::vertex_t *> vertices;
+
+ carve::geom3d::AABB aabb;
+
+ Node();
+
+ Node(const carve::geom3d::Vector &newMin, const carve::geom3d::Vector &newMax);
+ Node(Node *p, double x1, double y1, double z1, double x2, double y2, double z2);
+
+ ~Node();
+
+ bool mightContain(const carve::poly::Geometry<3>::face_t &face);
+ bool mightContain(const carve::poly::Geometry<3>::edge_t &edge);
+ bool mightContain(const carve::poly::Geometry<3>::vertex_t &p);
+ bool hasChildren();
+ bool hasGeometry();
+
+ template <class T>
+ void putInside(const T &input, Node *child, T &output);
+
+ bool split();
+ };
+
+
+
+ Node *root;
+
+
+
+ struct no_filter {
+ bool operator()(const carve::poly::Geometry<3>::edge_t *) { return true; }
+ bool operator()(const carve::poly::Geometry<3>::face_t *) { return true; }
+ };
+
+
+
+ Octree();
+
+ ~Octree();
+
+
+
+ void setBounds(const carve::geom3d::Vector &min, const carve::geom3d::Vector &max);
+ void setBounds(carve::geom3d::AABB aabb);
+
+
+
+ void addEdges(const std::vector<carve::poly::Geometry<3>::edge_t > &edges);
+ void addFaces(const std::vector<carve::poly::Geometry<3>::face_t > &faces);
+ void addVertices(const std::vector<const carve::poly::Geometry<3>::vertex_t *> &vertices);
+
+
+
+ static carve::geom3d::AABB makeAABB(const Node *node);
+
+
+
+ void doFindEdges(const carve::geom::aabb<3> &aabb,
+ Node *node,
+ std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
+ unsigned depth) const;
+ void doFindEdges(const carve::geom3d::LineSegment &l,
+ Node *node,
+ std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
+ unsigned depth) const;
+ void doFindEdges(const carve::geom3d::Vector &v,
+ Node *node,
+ std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
+ unsigned depth) const;
+ void doFindFaces(const carve::geom::aabb<3> &aabb,
+ Node *node,
+ std::vector<const carve::poly::Geometry<3>::face_t *> &out,
+ unsigned depth) const;
+ void doFindFaces(const carve::geom3d::LineSegment &l,
+ Node *node,
+ std::vector<const carve::poly::Geometry<3>::face_t *> &out,
+ unsigned depth) const;
+
+
+
+ void doFindVerticesAllowDupes(const carve::geom3d::Vector &v,
+ Node *node,
+ std::vector<const carve::poly::Geometry<3>::vertex_t *> &out,
+ unsigned depth) const;
+
+ void findVerticesNearAllowDupes(const carve::geom3d::Vector &v,
+ std::vector<const carve::poly::Geometry<3>::vertex_t *> &out) const;
+
+
+
+ template<typename filter_t>
+ void doFindEdges(const carve::poly::Geometry<3>::face_t &f, Node *node,
+ std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
+ unsigned depth,
+ filter_t filter) const;
+
+ template<typename filter_t>
+ void findEdgesNear(const carve::poly::Geometry<3>::face_t &f,
+ std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
+ filter_t filter) const;
+
+ void findEdgesNear(const carve::poly::Geometry<3>::face_t &f,
+ std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const {
+ return findEdgesNear(f, out, no_filter());
+ }
+
+
+
+ void findEdgesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
+ void findEdgesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
+ void findEdgesNear(const carve::poly::Geometry<3>::edge_t &e, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
+ void findEdgesNear(const carve::geom3d::Vector &v, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
+
+
+
+ void findFacesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
+ void findFacesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
+ void findFacesNear(const carve::poly::Geometry<3>::edge_t &e, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
+
+
+
+ static void doSplit(int maxSplit, Node *node);
+
+
+
+ template <typename FUNC>
+ void doIterate(int level, Node *node, const FUNC &f) const;
+
+ template <typename FUNC>
+ void iterateNodes(const FUNC &f) const;
+
+
+
+ void splitTree();
+
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/octree_impl.hpp b/extern/carve/include/carve/octree_impl.hpp
new file mode 100644
index 00000000000..5eadb1543a0
--- /dev/null
+++ b/extern/carve/include/carve/octree_impl.hpp
@@ -0,0 +1,79 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+namespace carve {
+ namespace csg {
+ template<typename filter_t>
+ void Octree::doFindEdges(const carve::poly::Geometry<3>::face_t &f,
+ Node *node,
+ std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
+ unsigned depth,
+ filter_t filter) const {
+ if (node == NULL) {
+ return;
+ }
+
+ if (node->aabb.intersects(f.aabb) && node->aabb.intersects(f.plane_eqn)) {
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(f, node->children[i], out, depth + 1, filter);
+ }
+ } else {
+ if (depth < MAX_SPLIT_DEPTH && node->edges.size() > EDGE_SPLIT_THRESHOLD) {
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(f, node->children[i], out, depth + 1, filter);
+ }
+ return;
+ }
+ }
+ for (std::vector<const carve::poly::Geometry<3>::edge_t*>::const_iterator it = node->edges.begin(), e = node->edges.end(); it != e; ++it) {
+ if ((*it)->tag_once()) {
+ if (filter(*it)) {
+ out.push_back(*it);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ template<typename filter_t>
+ void Octree::findEdgesNear(const carve::poly::Geometry<3>::face_t &f, std::vector<const carve::poly::Geometry<3>::edge_t *> &out, filter_t filter) const {
+ tagable::tag_begin();
+ doFindEdges(f, root, out, 0, filter);
+ }
+
+ template <typename func_t>
+ void Octree::doIterate(int level, Node *node, const func_t &f) const{
+ f(level, node);
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doIterate(level + 1, node->children[i], f);
+ }
+ }
+ }
+
+ template <typename func_t>
+ void Octree::iterateNodes(const func_t &f) const {
+ doIterate(0, root, f);
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/pointset.hpp b/extern/carve/include/carve/pointset.hpp
new file mode 100644
index 00000000000..c635ce47f2f
--- /dev/null
+++ b/extern/carve/include/carve/pointset.hpp
@@ -0,0 +1,24 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/pointset_decl.hpp>
+#include <carve/pointset_impl.hpp>
+#include <carve/pointset_iter.hpp>
diff --git a/extern/carve/include/carve/pointset_decl.hpp b/extern/carve/include/carve/pointset_decl.hpp
new file mode 100644
index 00000000000..d09f9e0e724
--- /dev/null
+++ b/extern/carve/include/carve/pointset_decl.hpp
@@ -0,0 +1,61 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#include <iterator>
+#include <list>
+#include <iterator>
+#include <limits>
+
+#include <carve/carve.hpp>
+#include <carve/tag.hpp>
+#include <carve/geom.hpp>
+#include <carve/kd_node.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/aabb.hpp>
+
+namespace carve {
+ namespace point {
+
+ struct Vertex : public tagable {
+ carve::geom3d::Vector v;
+ };
+
+
+
+ struct vec_adapt_vertex_ptr {
+ const carve::geom3d::Vector &operator()(const Vertex * const &v) { return v->v; }
+ carve::geom3d::Vector &operator()(Vertex *&v) { return v->v; }
+ };
+
+
+
+ struct PointSet {
+ std::vector<Vertex> vertices;
+ carve::geom3d::AABB aabb;
+
+ PointSet(const std::vector<carve::geom3d::Vector> &points);
+ PointSet() {
+ }
+
+ void sortVertices(const carve::geom3d::Vector &axis);
+
+ size_t vertexToIndex_fast(const Vertex *v) const;
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/pointset_impl.hpp b/extern/carve/include/carve/pointset_impl.hpp
new file mode 100644
index 00000000000..71b5f281c0f
--- /dev/null
+++ b/extern/carve/include/carve/pointset_impl.hpp
@@ -0,0 +1,36 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#include <vector>
+
+#include <carve/carve.hpp>
+#include <carve/tag.hpp>
+#include <carve/geom.hpp>
+#include <carve/kd_node.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/aabb.hpp>
+
+namespace carve {
+ namespace point {
+
+ inline size_t PointSet::vertexToIndex_fast(const Vertex *v) const {
+ return v - &vertices[0];
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/pointset_iter.hpp b/extern/carve/include/carve/pointset_iter.hpp
new file mode 100644
index 00000000000..13cf66e4584
--- /dev/null
+++ b/extern/carve/include/carve/pointset_iter.hpp
@@ -0,0 +1,18 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
diff --git a/extern/carve/include/carve/poly.hpp b/extern/carve/include/carve/poly.hpp
new file mode 100644
index 00000000000..913d0600aca
--- /dev/null
+++ b/extern/carve/include/carve/poly.hpp
@@ -0,0 +1,24 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/poly_decl.hpp>
+
+#include <carve/poly_impl.hpp>
diff --git a/extern/carve/include/carve/poly_decl.hpp b/extern/carve/include/carve/poly_decl.hpp
new file mode 100644
index 00000000000..fe550082dbb
--- /dev/null
+++ b/extern/carve/include/carve/poly_decl.hpp
@@ -0,0 +1,25 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/vertex_decl.hpp>
+#include <carve/edge_decl.hpp>
+#include <carve/face_decl.hpp>
+#include <carve/polyhedron_decl.hpp>
diff --git a/extern/carve/include/carve/poly_impl.hpp b/extern/carve/include/carve/poly_impl.hpp
new file mode 100644
index 00000000000..db5ae56e6d3
--- /dev/null
+++ b/extern/carve/include/carve/poly_impl.hpp
@@ -0,0 +1,25 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/vertex_impl.hpp>
+#include <carve/edge_impl.hpp>
+#include <carve/face_impl.hpp>
+#include <carve/polyhedron_impl.hpp>
diff --git a/extern/carve/include/carve/polyhedron_base.hpp b/extern/carve/include/carve/polyhedron_base.hpp
new file mode 100644
index 00000000000..f55146f2986
--- /dev/null
+++ b/extern/carve/include/carve/polyhedron_base.hpp
@@ -0,0 +1,149 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom3d.hpp>
+
+#include <carve/vertex_decl.hpp>
+#include <carve/edge_decl.hpp>
+#include <carve/face_decl.hpp>
+
+#include <stddef.h>
+
+namespace carve {
+ namespace poly {
+
+
+
+ struct Object {
+ };
+
+
+
+ template<typename array_t>
+ ptrdiff_t ptrToIndex_fast(const array_t &a, const typename array_t::value_type *v) {
+ return v - &a[0];
+ }
+
+ template<typename array_t>
+ ptrdiff_t ptrToIndex(const array_t &a, const typename array_t::value_type *v) {
+ if (v < &a.front() || v > &a.back()) return -1;
+ return v - &a[0];
+ }
+
+
+ template<unsigned ndim>
+ struct Geometry : public Object {
+ struct Connectivity {
+ } connectivity;
+ };
+
+
+
+ template<>
+ struct Geometry<2> : public Object {
+ typedef Vertex<2> vertex_t;
+ typedef Edge<2> edge_t;
+
+ struct Connectivity {
+ std::vector<std::vector<const edge_t *> > vertex_to_edge;
+ } connectivity;
+
+ std::vector<vertex_t> vertices;
+ std::vector<edge_t> edges;
+
+ ptrdiff_t vertexToIndex_fast(const vertex_t *v) const { return ptrToIndex_fast(vertices, v); }
+ ptrdiff_t vertexToIndex(const vertex_t *v) const { return ptrToIndex(vertices, v); }
+
+ ptrdiff_t edgeToIndex_fast(const edge_t *e) const { return ptrToIndex_fast(edges, e); }
+ ptrdiff_t edgeToIndex(const edge_t *e) const { return ptrToIndex(edges, e); }
+
+
+
+ // *** connectivity queries
+
+ template<typename T>
+ int vertexToEdges(const vertex_t *v, T result) const;
+ };
+
+
+
+ template<>
+ struct Geometry<3> : public Object {
+ typedef Vertex<3> vertex_t;
+ typedef Edge<3> edge_t;
+ typedef Face<3> face_t;
+
+ struct Connectivity {
+ std::vector<std::vector<const edge_t *> > vertex_to_edge;
+ std::vector<std::vector<const face_t *> > vertex_to_face;
+ std::vector<std::vector<const face_t *> > edge_to_face;
+ } connectivity;
+
+ std::vector<vertex_t> vertices;
+ std::vector<edge_t> edges;
+ std::vector<face_t> faces;
+
+ ptrdiff_t vertexToIndex_fast(const vertex_t *v) const { return ptrToIndex_fast(vertices, v); }
+ ptrdiff_t vertexToIndex(const vertex_t *v) const { return ptrToIndex(vertices, v); }
+
+ ptrdiff_t edgeToIndex_fast(const edge_t *e) const { return ptrToIndex_fast(edges, e); }
+ ptrdiff_t edgeToIndex(const edge_t *e) const { return ptrToIndex(edges, e); }
+
+ ptrdiff_t faceToIndex_fast(const face_t *f) const { return ptrToIndex_fast(faces, f); }
+ ptrdiff_t faceToIndex(const face_t *f) const { return ptrToIndex(faces, f); }
+
+ template<typename order_t>
+ bool orderVertices(order_t order);
+
+ bool orderVertices() { return orderVertices(std::less<vertex_t::vector_t>()); }
+
+
+
+ // *** connectivity queries
+
+ const face_t *connectedFace(const face_t *, const edge_t *) const;
+
+ template<typename T>
+ int _faceNeighbourhood(const face_t *f, int depth, T *result) const;
+
+ template<typename T>
+ int faceNeighbourhood(const face_t *f, int depth, T result) const;
+
+ template<typename T>
+ int faceNeighbourhood(const edge_t *e, int m_id, int depth, T result) const;
+
+ template<typename T>
+ int faceNeighbourhood(const vertex_t *v, int m_id, int depth, T result) const;
+
+ template<typename T>
+ int vertexToEdges(const vertex_t *v, T result) const;
+
+ template<typename T>
+ int edgeToFaces(const edge_t *e, T result) const;
+
+ template<typename T>
+ int vertexToFaces(const vertex_t *v, T result) const;
+ };
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/polyhedron_decl.hpp b/extern/carve/include/carve/polyhedron_decl.hpp
new file mode 100644
index 00000000000..fda2a304691
--- /dev/null
+++ b/extern/carve/include/carve/polyhedron_decl.hpp
@@ -0,0 +1,184 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom3d.hpp>
+
+#include <carve/polyhedron_base.hpp>
+#include <carve/octree_decl.hpp>
+#include <carve/collection_types.hpp>
+
+#include <assert.h>
+#include <list>
+
+
+namespace carve {
+ namespace mesh {
+ template<unsigned ndim>
+ class MeshSet;
+ }
+
+ namespace poly {
+ class Polyhedron;
+ }
+
+ poly::Polyhedron *polyhedronFromMesh(const mesh::MeshSet<3> *, int);
+
+ namespace poly {
+
+ class Polyhedron : public Geometry<3> {
+ private:
+ friend Polyhedron *carve::polyhedronFromMesh(const mesh::MeshSet<3> *, int);
+
+ Polyhedron() {
+ }
+
+ Polyhedron &operator=(const Polyhedron &); // not implemented
+
+ // *** initialization
+
+ bool initSpatialIndex();
+ void initVertexConnectivity();
+ void setFaceAndVertexOwner();
+
+ bool initConnectivity();
+ bool markManifolds();
+ bool calcManifoldEmbedding();
+
+ bool init();
+ void faceRecalc();
+
+ void commonFaceInit(bool _recalc);
+
+ public:
+ static void collectFaceVertices(std::vector<face_t > &faces,
+ std::vector<vertex_t > &vertices,
+ std::unordered_map<const vertex_t *, const vertex_t *> &vmap);
+
+ static void collectFaceVertices(std::vector<face_t > &faces,
+ std::vector<vertex_t > &vertices);
+
+ std::vector<bool> manifold_is_closed;
+ std::vector<bool> manifold_is_negative;
+
+ carve::geom3d::AABB aabb;
+ carve::csg::Octree octree;
+
+
+
+ // *** construction of Polyhedron objects
+
+ Polyhedron(const Polyhedron &);
+
+ // copy a single manifold
+ Polyhedron(const Polyhedron &, int m_id);
+
+ // copy a subset of manifolds
+ Polyhedron(const Polyhedron &, const std::vector<bool> &selected_manifolds);
+
+ Polyhedron(std::vector<face_t > &_faces,
+ std::vector<vertex_t > &_vertices,
+ bool _recalc = false);
+
+ Polyhedron(std::vector<face_t > &_faces,
+ bool _recalc = false);
+
+ Polyhedron(std::list<face_t > &_faces,
+ bool _recalc = false);
+
+ Polyhedron(const std::vector<carve::geom3d::Vector> &vertices,
+ int n_faces,
+ const std::vector<int> &face_indices);
+
+ ~Polyhedron();
+
+
+
+ // *** containment queries
+
+ void testVertexAgainstClosedManifolds(const carve::geom3d::Vector &v,
+ std::map<int, PointClass> &result,
+ bool ignore_orentation) const;
+
+ PointClass containsVertex(const carve::geom3d::Vector &v,
+ const face_t **hit_face = NULL,
+ bool even_odd = false,
+ int manifold_id = -1) const;
+
+
+
+ // *** locality queries
+
+ void findEdgesNear(const carve::geom::aabb<3> &aabb, std::vector<const edge_t *> &edges) const;
+ void findEdgesNear(const carve::geom3d::LineSegment &l, std::vector<const edge_t *> &edges) const;
+ void findEdgesNear(const carve::geom3d::Vector &v, std::vector<const edge_t *> &edges) const;
+ void findEdgesNear(const face_t &face, std::vector<const edge_t *> &edges) const;
+ void findEdgesNear(const edge_t &edge, std::vector<const edge_t *> &edges) const;
+
+ void findFacesNear(const carve::geom::aabb<3> &aabb, std::vector<const face_t *> &faces) const;
+ void findFacesNear(const carve::geom3d::LineSegment &l, std::vector<const face_t *> &faces) const;
+ void findFacesNear(const edge_t &edge, std::vector<const face_t *> &faces) const;
+
+
+
+ // *** manifold queries
+
+ inline bool vertexOnManifold(const vertex_t *v, int m_id) const;
+ inline bool edgeOnManifold(const edge_t *e, int m_id) const;
+
+ template<typename T>
+ int vertexManifolds(const vertex_t *v, T result) const;
+
+ template<typename T>
+ int edgeManifolds(const edge_t *e, T result) const;
+
+ size_t manifoldCount() const;
+
+ bool hasOpenManifolds() const;
+
+
+
+
+ // *** transformation
+
+ // flip face directions
+ void invertAll();
+ void invert(const std::vector<bool> &selected_manifolds);
+
+ void invert(int m_id);
+ void invert();
+
+ // matrix transform of vertices
+ void transform(const carve::math::Matrix &xform);
+
+ // arbitrary function transform of vertices
+ template<typename T>
+ void transform(const T &xform);
+
+ void print(std::ostream &) const;
+
+ void canonicalize();
+ };
+
+ std::ostream &operator<<(std::ostream &, const Polyhedron &);
+
+ }
+
+}
diff --git a/extern/carve/include/carve/polyhedron_impl.hpp b/extern/carve/include/carve/polyhedron_impl.hpp
new file mode 100644
index 00000000000..06d841c7192
--- /dev/null
+++ b/extern/carve/include/carve/polyhedron_impl.hpp
@@ -0,0 +1,287 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/timing.hpp>
+
+#include <assert.h>
+#include <list>
+
+namespace carve {
+ namespace poly {
+
+
+
+ template<typename order_t>
+ struct VPtrSort {
+ order_t order;
+
+ VPtrSort(const order_t &_order) : order(_order) {}
+ bool operator()(carve::poly::Polyhedron::vertex_t const *a,
+ carve::poly::Polyhedron::vertex_t const *b) const {
+ return order(a->v, b->v);
+ }
+ };
+
+ template<typename order_t>
+ bool Geometry<3>::orderVertices(order_t order) {
+ static carve::TimingName FUNC_NAME("Geometry<3>::orderVertices()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ std::vector<vertex_t *> vptr;
+ std::vector<vertex_t *> vmap;
+ std::vector<vertex_t> vout;
+ const size_t N = vertices.size();
+
+ vptr.reserve(N);
+ vout.reserve(N);
+ vmap.resize(N);
+
+ for (size_t i = 0; i != N; ++i) {
+ vptr.push_back(&vertices[i]);
+ }
+ std::sort(vptr.begin(), vptr.end(), VPtrSort<order_t>(order));
+
+ for (size_t i = 0; i != N; ++i) {
+ vout.push_back(*vptr[i]);
+ vmap[vertexToIndex_fast(vptr[i])] = &vout[i];
+ }
+
+ for (size_t i = 0; i < faces.size(); ++i) {
+ face_t &f = faces[i];
+ for (size_t j = 0; j < f.nVertices(); ++j) {
+ f.vertex(j) = vmap[vertexToIndex_fast(f.vertex(j))];
+ }
+ }
+ for (size_t i = 0; i < edges.size(); ++i) {
+ edges[i].v1 = vmap[vertexToIndex_fast(edges[i].v1)];
+ edges[i].v2 = vmap[vertexToIndex_fast(edges[i].v2)];
+ }
+
+ vout.swap(vertices);
+
+ return true;
+ }
+
+
+
+ template<typename T>
+ int Geometry<3>::_faceNeighbourhood(const face_t *f, int depth, T *result) const {
+ if (depth < 0 || f->is_tagged()) return 0;
+
+ f->tag();
+ *(*result)++ = f;
+
+ int r = 1;
+ for (size_t i = 0; i < f->edges.size(); ++i) {
+ const std::vector<const face_t *> &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(f->edges[i])];
+ const face_t *f2 = connectedFace(f, f->edges[i]);
+ if (f2) {
+ r += _faceNeighbourhood(f2, depth - 1, (*result));
+ }
+ }
+ return r;
+ }
+
+
+
+ template<typename T>
+ int Geometry<3>::faceNeighbourhood(const face_t *f, int depth, T result) const {
+ tagable::tag_begin();
+
+ return _faceNeighbourhood(f, depth, &result);
+ }
+
+
+
+ template<typename T>
+ int Geometry<3>::faceNeighbourhood(const edge_t *e, int m_id, int depth, T result) const {
+ tagable::tag_begin();
+
+ int r = 0;
+ const std::vector<const face_t *> &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(e)];
+ for (size_t i = 0; i < edge_faces.size(); ++i) {
+ face_t *f = edge_faces[i];
+ if (f && f->manifold_id == m_id) { r += _faceNeighbourhood(f, depth, &result); }
+ }
+ return r;
+ }
+
+
+
+ template<typename T>
+ int Geometry<3>::faceNeighbourhood(const vertex_t *v, int m_id, int depth, T result) const {
+ tagable::tag_begin();
+
+ int r = 0;
+ const std::vector<const face_t *> &vertex_faces = connectivity.vertex_to_face[vertexToIndex_fast(v)];
+ for (size_t i = 0; i < vertex_faces.size(); ++i) {
+ face_t *f = vertex_faces[i];
+ if (f && f->manifold_id == m_id) { r += _faceNeighbourhood(f, depth, &result); }
+ }
+ return r;
+ }
+
+
+
+ // accessing connectivity information.
+ template<typename T>
+ int Geometry<3>::vertexToEdges(const vertex_t *v, T result) const {
+ std::vector<const edge_t *> &e = connectivity.vertex_to_edge[vertexToIndex_fast(v)];
+ std::copy(e.begin(), e.end(), result);
+ return e.size();
+ }
+
+
+
+ template<typename T>
+ int Geometry<3>::vertexToFaces(const vertex_t *v, T result) const {
+ const std::vector<const face_t *> &vertex_faces = connectivity.vertex_to_face[vertexToIndex_fast(v)];
+ int c = 0;
+ for (size_t i = 0; i < vertex_faces.size(); ++i) {
+ *result++ = vertex_faces[i]; ++c;
+ }
+ return c;
+ }
+
+
+
+ template<typename T>
+ int Geometry<3>::edgeToFaces(const edge_t *e, T result) const {
+ const std::vector<const face_t *> &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(e)];
+ int c = 0;
+ for (size_t i = 0; i < edge_faces.size(); ++i) {
+ if (edge_faces[i] != NULL) { *result++ = edge_faces[i]; ++c; }
+ }
+ return c;
+ }
+
+
+
+ inline const Geometry<3>::face_t *Geometry<3>::connectedFace(const face_t *f, const edge_t *e) const {
+ const std::vector<const face_t *> &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(e)];
+ for (size_t i = 0; i < (edge_faces.size() & ~1U); i++) {
+ if (edge_faces[i] == f) return edge_faces[i^1];
+ }
+ return NULL;
+ }
+
+
+
+ inline void Polyhedron::invert(int m_id) {
+ std::vector<bool> selected_manifolds(manifold_is_closed.size(), false);
+ if (m_id >=0 && (unsigned)m_id < selected_manifolds.size()) selected_manifolds[m_id] = true;
+ invert(selected_manifolds);
+ }
+
+
+
+ inline void Polyhedron::invert() {
+ invertAll();
+ }
+
+
+
+ inline bool Polyhedron::edgeOnManifold(const edge_t *e, int m_id) const {
+ const std::vector<const face_t *> &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(e)];
+
+ for (size_t i = 0; i < edge_faces.size(); ++i) {
+ if (edge_faces[i] && edge_faces[i]->manifold_id == m_id) return true;
+ }
+ return false;
+ }
+
+ inline bool Polyhedron::vertexOnManifold(const vertex_t *v, int m_id) const {
+ const std::vector<const face_t *> &f = connectivity.vertex_to_face[vertexToIndex_fast(v)];
+
+ for (size_t i = 0; i < f.size(); ++i) {
+ if (f[i]->manifold_id == m_id) return true;
+ }
+ return false;
+ }
+
+
+
+ template<typename T>
+ int Polyhedron::edgeManifolds(const edge_t *e, T result) const {
+ const std::vector<const face_t *> &edge_faces = connectivity.edge_to_face[edgeToIndex_fast(e)];
+
+ for (size_t i = 0; i < (edge_faces.size() & ~1U); i += 2) {
+ const face_t *f1 = edge_faces[i];
+ const face_t *f2 = edge_faces[i+1];
+ assert (f1 || f2);
+ if (f1)
+ *result++ = f1->manifold_id;
+ else if (f2)
+ *result++ = f2->manifold_id;
+ }
+ return edge_faces.size() >> 1;
+ }
+
+
+
+ template<typename T>
+ int Polyhedron::vertexManifolds(const vertex_t *v, T result) const {
+ const std::vector<const face_t *> &f = connectivity.vertex_to_face[vertexToIndex_fast(v)];
+ std::set<int> em;
+
+ for (size_t i = 0; i < f.size(); ++i) {
+ em.insert(f[i]->manifold_id);
+ }
+
+ std::copy(em.begin(), em.end(), result);
+ return em.size();
+ }
+
+
+
+ template<typename T>
+ void Polyhedron::transform(const T &xform) {
+ for (size_t i = 0; i < vertices.size(); i++) {
+ vertices[i].v = xform(vertices[i].v);
+ }
+ faceRecalc();
+ init();
+ }
+
+
+
+ inline size_t Polyhedron::manifoldCount() const {
+ return manifold_is_closed.size();
+ }
+
+
+
+ inline bool Polyhedron::hasOpenManifolds() const {
+ for (size_t i = 0; i < manifold_is_closed.size(); ++i) {
+ if (!manifold_is_closed[i]) return true;
+ }
+ return false;
+ }
+
+
+
+ inline std::ostream &operator<<(std::ostream &o, const Polyhedron &p) {
+ p.print(o);
+ return o;
+ }
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/polyline.hpp b/extern/carve/include/carve/polyline.hpp
new file mode 100644
index 00000000000..a6789f8d0c5
--- /dev/null
+++ b/extern/carve/include/carve/polyline.hpp
@@ -0,0 +1,24 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/polyline_decl.hpp>
+#include <carve/polyline_impl.hpp>
+#include <carve/polyline_iter.hpp>
diff --git a/extern/carve/include/carve/polyline_decl.hpp b/extern/carve/include/carve/polyline_decl.hpp
new file mode 100644
index 00000000000..a29c56656ff
--- /dev/null
+++ b/extern/carve/include/carve/polyline_decl.hpp
@@ -0,0 +1,151 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#include <iterator>
+#include <list>
+#include <iterator>
+#include <limits>
+
+#include <carve/carve.hpp>
+#include <carve/tag.hpp>
+#include <carve/geom.hpp>
+#include <carve/kd_node.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/aabb.hpp>
+
+namespace carve {
+ namespace line {
+
+ struct PolylineEdge;
+ struct Polyline;
+ struct polyline_vertex_const_iter;
+ struct polyline_vertex_iter;
+ struct polyline_edge_const_iter;
+ struct polyline_edge_iter;
+
+
+
+ struct Vertex : public tagable {
+ carve::geom3d::Vector v;
+ std::list<std::pair<PolylineEdge *, PolylineEdge *> > edge_pairs;
+
+ void addEdgePair(PolylineEdge *in, PolylineEdge *out) {
+ edge_pairs.push_back(std::make_pair(in, out));
+ }
+ };
+
+
+
+ struct vec_adapt_vertex_ptr {
+ const carve::geom3d::Vector &operator()(const Vertex * const &v) { return v->v; }
+ carve::geom3d::Vector &operator()(Vertex *&v) { return v->v; }
+ };
+
+
+
+ struct PolylineEdge : public tagable {
+ Polyline *parent;
+ unsigned edgenum;
+ Vertex *v1, *v2;
+
+ PolylineEdge(Polyline *_parent, int _edgenum, Vertex *_v1, Vertex *_v2);
+
+ carve::geom3d::AABB aabb() const;
+
+ inline PolylineEdge *prevEdge() const;
+ inline PolylineEdge *nextEdge() const;
+ };
+
+
+
+ struct Polyline {
+ bool closed;
+ std::vector<PolylineEdge *> edges;
+
+ Polyline();
+
+ size_t vertexCount() const;
+
+ size_t edgeCount() const;
+
+ const PolylineEdge *edge(size_t e) const;
+
+ PolylineEdge *edge(size_t e);
+
+ const Vertex *vertex(size_t v) const;
+
+ Vertex *vertex(size_t v);
+
+ bool isClosed() const;
+
+ polyline_vertex_const_iter vbegin() const;
+ polyline_vertex_const_iter vend() const;
+ polyline_vertex_iter vbegin();
+ polyline_vertex_iter vend();
+
+ polyline_edge_const_iter ebegin() const;
+ polyline_edge_const_iter eend() const;
+ polyline_edge_iter ebegin();
+ polyline_edge_iter eend();
+
+ carve::geom3d::AABB aabb() const;
+
+ template<typename iter_t>
+ void _init(bool c, iter_t begin, iter_t end, std::vector<Vertex> &vertices);
+
+ template<typename iter_t>
+ void _init(bool closed, iter_t begin, iter_t end, std::vector<Vertex> &vertices, std::forward_iterator_tag);
+
+ template<typename iter_t>
+ void _init(bool closed, iter_t begin, iter_t end, std::vector<Vertex> &vertices, std::random_access_iterator_tag);
+
+ template<typename iter_t>
+ Polyline(bool closed, iter_t begin, iter_t end, std::vector<Vertex> &vertices);
+
+ ~Polyline() {
+ for (size_t i = 0; i < edges.size(); ++i) {
+ delete edges[i];
+ }
+ }
+ };
+
+
+
+ struct PolylineSet {
+ typedef std::list<Polyline *> line_list;
+ typedef line_list::iterator line_iter;
+ typedef line_list::const_iterator const_line_iter;
+
+ std::vector<Vertex> vertices;
+ line_list lines;
+ carve::geom3d::AABB aabb;
+
+ PolylineSet(const std::vector<carve::geom3d::Vector> &points);
+ PolylineSet() {
+ }
+
+ template<typename iter_t>
+ void addPolyline(bool closed, iter_t begin, iter_t end);
+
+ void sortVertices(const carve::geom3d::Vector &axis);
+
+ size_t vertexToIndex_fast(const Vertex *v) const;
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/polyline_impl.hpp b/extern/carve/include/carve/polyline_impl.hpp
new file mode 100644
index 00000000000..3c17980a9af
--- /dev/null
+++ b/extern/carve/include/carve/polyline_impl.hpp
@@ -0,0 +1,160 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+namespace carve {
+ namespace line {
+
+ inline PolylineEdge::PolylineEdge(Polyline *_parent, int _edgenum, Vertex *_v1, Vertex *_v2) :
+ tagable(), parent(_parent), edgenum(_edgenum), v1(_v1), v2(_v2) {
+ }
+
+ inline carve::geom3d::AABB PolylineEdge::aabb() const {
+ carve::geom3d::AABB a;
+ a.fit(v1->v, v2->v);
+ return a;
+ }
+
+ inline PolylineEdge *PolylineEdge::prevEdge() const {
+ if (edgenum) {
+ return parent->edge(edgenum - 1);
+ } else {
+ if (parent->closed) {
+ return parent->edge(parent->edgeCount() - 1);
+ } else {
+ return NULL;
+ }
+ }
+ }
+
+ inline PolylineEdge *PolylineEdge::nextEdge() const {
+ if (edgenum + 1 < parent->edgeCount()) {
+ return parent->edge(edgenum + 1);
+ } else {
+ if (parent->closed) {
+ return parent->edge(0);
+ } else {
+ return NULL;
+ }
+ }
+ }
+
+
+
+ inline Polyline::Polyline() : edges() {
+ }
+
+ inline size_t Polyline::vertexCount() const {
+ return edgeCount() + (closed ? 0 : 1);
+ }
+
+ inline size_t Polyline::edgeCount() const {
+ return edges.size();
+ }
+
+ inline const PolylineEdge *Polyline::edge(size_t e) const {
+ return edges[e % edges.size()];
+ }
+
+ inline PolylineEdge *Polyline::edge(size_t e) {
+ return edges[e % edges.size()];
+ }
+
+ inline const Vertex *Polyline::vertex(size_t v) const {
+ if (closed) {
+ v %= edgeCount();
+ } else if (v >= edgeCount()) {
+ return v == edgeCount() ? edges.back()->v2 : NULL;
+ }
+ return edges[v]->v1;
+ }
+
+ inline Vertex *Polyline::vertex(size_t v) {
+ if (closed) {
+ v %= edgeCount();
+ } else if (v >= edgeCount()) {
+ return v == edgeCount() ? edges.back()->v2 : NULL;
+ }
+ return edges[v]->v1;
+ }
+
+ inline bool Polyline::isClosed() const {
+ return closed;
+ }
+
+ template<typename iter_t>
+ void Polyline::_init(bool c, iter_t begin, iter_t end, std::vector<Vertex> &vertices) {
+ closed = c;
+
+ PolylineEdge *e;
+ if (begin == end) return;
+ size_t v1 = (int)*begin++;
+ if (begin == end) return;
+
+ while (begin != end) {
+ size_t v2 = (int)*begin++;
+ e = new PolylineEdge(this, edges.size(), &vertices[v1], &vertices[v2]);
+ edges.push_back(e);
+ v1 = v2;
+ }
+
+ if (closed) {
+ e = new PolylineEdge(this, edges.size(), edges.back()->v2, edges.front()->v1);
+ edges.push_back(e);
+
+ edges.front()->v1->addEdgePair(edges.back(), edges.front());
+ for (size_t i = 1; i < edges.size(); ++i) {
+ edges[i]->v1->addEdgePair(edges[i-1], edges[i]);
+ }
+ } else {
+ edges.front()->v1->addEdgePair(NULL, edges.front());
+ for (size_t i = 1; i < edges.size(); ++i) {
+ edges[i]->v1->addEdgePair(edges[i-1], edges[i]);
+ }
+ edges.back()->v2->addEdgePair(edges.back(), NULL);
+ }
+ }
+
+ template<typename iter_t>
+ void Polyline::_init(bool closed, iter_t begin, iter_t end, std::vector<Vertex> &vertices, std::forward_iterator_tag) {
+ _init(closed, begin, end, vertices);
+ }
+
+ template<typename iter_t>
+ void Polyline::_init(bool closed, iter_t begin, iter_t end, std::vector<Vertex> &vertices, std::random_access_iterator_tag) {
+ edges.reserve(end - begin - (closed ? 0 : 1));
+ _init(closed, begin, end, vertices);
+ }
+
+ template<typename iter_t>
+ Polyline::Polyline(bool closed, iter_t begin, iter_t end, std::vector<Vertex> &vertices) {
+ _init(closed, begin, end, vertices, typename std::iterator_traits<iter_t>::iterator_category());
+ }
+
+
+
+ template<typename iter_t>
+ void PolylineSet::addPolyline(bool closed, iter_t begin, iter_t end) {
+ Polyline *p = new Polyline(closed, begin, end, vertices);
+ lines.push_back(p);
+ }
+
+ inline size_t PolylineSet::vertexToIndex_fast(const Vertex *v) const {
+ return v - &vertices[0];
+ }
+ }
+}
diff --git a/extern/carve/include/carve/polyline_iter.hpp b/extern/carve/include/carve/polyline_iter.hpp
new file mode 100644
index 00000000000..8501e620fea
--- /dev/null
+++ b/extern/carve/include/carve/polyline_iter.hpp
@@ -0,0 +1,199 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+#pragma once
+
+#include <iterator>
+#include <list>
+#include <iterator>
+#include <limits>
+#include <cstddef>
+
+#include <carve/polyline_decl.hpp>
+
+namespace carve {
+ namespace line {
+
+ struct polyline_vertex_iter : public std::iterator<std::random_access_iterator_tag, Vertex *> {
+ Polyline *base;
+ size_t idx;
+
+ polyline_vertex_iter(Polyline *_base) : base(_base), idx(0) {
+ }
+
+ polyline_vertex_iter(Polyline *_base, size_t _idx) : base(_base), idx(_idx) {
+ }
+
+ polyline_vertex_iter operator++(int) { return polyline_vertex_iter(base, idx++); }
+ polyline_vertex_iter &operator++() { ++idx; return *this; }
+ polyline_vertex_iter &operator+=(int v) { idx += v; return *this; }
+
+ polyline_vertex_iter operator--(int) { return polyline_vertex_iter(base, idx--); }
+ polyline_vertex_iter &operator--() { --idx; return *this; }
+ polyline_vertex_iter &operator-=(int v) { idx -= v; return *this; }
+
+ Vertex *operator*() const {
+ return base->vertex(idx);
+ }
+ };
+
+
+
+ static inline ptrdiff_t operator-(const polyline_vertex_iter &a, const polyline_vertex_iter &b) { return a.idx - b.idx; }
+
+ static inline bool operator==(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx == b.idx; }
+ static inline bool operator!=(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx != b.idx; }
+ static inline bool operator<(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx < b.idx; }
+ static inline bool operator>(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx > b.idx; }
+ static inline bool operator<=(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx <= b.idx; }
+ static inline bool operator>=(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx >= b.idx; }
+
+
+
+ struct polyline_vertex_const_iter : public std::iterator<std::random_access_iterator_tag, Vertex *> {
+ const Polyline *base;
+ size_t idx;
+
+ polyline_vertex_const_iter(const Polyline *_base) : base(_base), idx(0) {
+ }
+
+ polyline_vertex_const_iter(const Polyline *_base, size_t _idx) : base(_base), idx(_idx) {
+ }
+
+ polyline_vertex_const_iter operator++(int) { return polyline_vertex_const_iter(base, idx++); }
+ polyline_vertex_const_iter &operator++() { ++idx; return *this; }
+ polyline_vertex_const_iter &operator+=(int v) { idx += v; return *this; }
+
+ polyline_vertex_const_iter operator--(int) { return polyline_vertex_const_iter(base, idx--); }
+ polyline_vertex_const_iter &operator--() { --idx; return *this; }
+ polyline_vertex_const_iter &operator-=(int v) { idx -= v; return *this; }
+
+ const Vertex *operator*() const {
+ return base->vertex(idx);
+ }
+ };
+
+
+
+ static inline ptrdiff_t operator-(const polyline_vertex_const_iter &a, const polyline_vertex_const_iter &b) { return a.idx - b.idx; }
+
+ static inline bool operator==(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx == b.idx; }
+ static inline bool operator!=(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx != b.idx; }
+ static inline bool operator<(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx < b.idx; }
+ static inline bool operator>(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx > b.idx; }
+ static inline bool operator<=(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx <= b.idx; }
+ static inline bool operator>=(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx >= b.idx; }
+
+ inline polyline_vertex_const_iter Polyline::vbegin() const {
+ return polyline_vertex_const_iter(this, 0);
+ }
+ inline polyline_vertex_const_iter Polyline::vend() const {
+ return polyline_vertex_const_iter(this, vertexCount());
+ }
+ inline polyline_vertex_iter Polyline::vbegin() {
+ return polyline_vertex_iter(this, 0);
+ }
+ inline polyline_vertex_iter Polyline::vend() {
+ return polyline_vertex_iter(this, vertexCount());
+ }
+
+
+
+ struct polyline_edge_iter : public std::iterator<std::random_access_iterator_tag, PolylineEdge *> {
+ Polyline *base;
+ size_t idx;
+
+ polyline_edge_iter(Polyline *_base) : base(_base), idx(0) {
+ }
+
+ polyline_edge_iter(Polyline *_base, size_t _idx) : base(_base), idx(_idx) {
+ }
+
+ polyline_edge_iter operator++(int) { return polyline_edge_iter(base, idx++); }
+ polyline_edge_iter &operator++() { ++idx; return *this; }
+ polyline_edge_iter &operator+=(int v) { idx += v; return *this; }
+
+ polyline_edge_iter operator--(int) { return polyline_edge_iter(base, idx--); }
+ polyline_edge_iter &operator--() { --idx; return *this; }
+ polyline_edge_iter &operator-=(int v) { idx -= v; return *this; }
+
+ PolylineEdge *operator*() const {
+ return base->edge(idx);
+ }
+ };
+
+
+
+ static inline int operator-(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx - b.idx; }
+
+ static inline bool operator==(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx == b.idx; }
+ static inline bool operator!=(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx != b.idx; }
+ static inline bool operator<(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx < b.idx; }
+ static inline bool operator>(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx > b.idx; }
+ static inline bool operator<=(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx <= b.idx; }
+ static inline bool operator>=(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx >= b.idx; }
+
+
+
+ struct polyline_edge_const_iter : public std::iterator<std::random_access_iterator_tag, PolylineEdge *> {
+ const Polyline *base;
+ size_t idx;
+
+ polyline_edge_const_iter(const Polyline *_base) : base(_base), idx(0) {
+ }
+
+ polyline_edge_const_iter(const Polyline *_base, size_t _idx) : base(_base), idx(_idx) {
+ }
+
+ polyline_edge_const_iter operator++(int) { return polyline_edge_const_iter(base, idx++); }
+ polyline_edge_const_iter &operator++() { ++idx; return *this; }
+ polyline_edge_const_iter &operator+=(int v) { idx += v; return *this; }
+
+ polyline_edge_const_iter operator--(int) { return polyline_edge_const_iter(base, idx--); }
+ polyline_edge_const_iter &operator--() { --idx; return *this; }
+ polyline_edge_const_iter &operator-=(int v) { idx -= v; return *this; }
+
+ const PolylineEdge *operator*() const {
+ return base->edge(idx);
+ }
+ };
+
+
+
+ static inline int operator-(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx - b.idx; }
+
+ static inline bool operator==(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx == b.idx; }
+ static inline bool operator!=(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx != b.idx; }
+ static inline bool operator<(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx < b.idx; }
+ static inline bool operator>(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx > b.idx; }
+ static inline bool operator<=(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx <= b.idx; }
+ static inline bool operator>=(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx >= b.idx; }
+
+ inline polyline_edge_const_iter Polyline::ebegin() const {
+ return polyline_edge_const_iter(this, 0);
+ }
+ inline polyline_edge_const_iter Polyline::eend() const {
+ return polyline_edge_const_iter(this, edgeCount());
+ }
+ inline polyline_edge_iter Polyline::ebegin() {
+ return polyline_edge_iter(this, 0);
+ }
+ inline polyline_edge_iter Polyline::eend() {
+ return polyline_edge_iter(this, edgeCount());
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/rescale.hpp b/extern/carve/include/carve/rescale.hpp
new file mode 100644
index 00000000000..6478298cfe6
--- /dev/null
+++ b/extern/carve/include/carve/rescale.hpp
@@ -0,0 +1,100 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/vector.hpp>
+#include <carve/aabb.hpp>
+#include <carve/matrix.hpp>
+
+#include <limits>
+
+namespace carve {
+ namespace rescale {
+
+ template<typename T>
+ T calc_scale(T max) {
+ const int radix = std::numeric_limits<T>::radix;
+
+ T div = T(1);
+ T m = fabs(max);
+ while (div < m) div *= radix;
+ m *= radix;
+ while (div > m) div /= radix;
+ return div;
+ }
+
+ template<typename T>
+ T calc_delta(T min, T max) {
+ const int radix = std::numeric_limits<T>::radix;
+
+ if (min >= T(0) || max <= T(0)) {
+ bool neg = false;
+ if (max <= T(0)) {
+ min = -min;
+ max = -max;
+ std::swap(min, max);
+ neg = true;
+ }
+ T t = T(1);
+ while (t > max) t /= radix;
+ while (t <= max/radix) t *= radix;
+ volatile T temp = t + min;
+ temp -= t;
+ if (neg) temp = -temp;
+ return temp;
+ } else {
+ return T(0);
+ }
+ }
+
+ struct rescale {
+ double dx, dy, dz, scale;
+
+ void init(double minx, double miny, double minz, double maxx, double maxy, double maxz) {
+ dx = calc_delta(minx, maxx); minx -= dx; maxx -= dx;
+ dy = calc_delta(miny, maxy); miny -= dy; maxy -= dy;
+ dz = calc_delta(minz, maxz); minz -= dz; maxz -= dz;
+ scale = calc_scale(std::max(std::max(fabs(minz), fabs(maxz)),
+ std::max(std::max(fabs(minx), fabs(maxx)),
+ std::max(fabs(miny), fabs(maxy)))));
+ }
+
+ rescale(double minx, double miny, double minz, double maxx, double maxy, double maxz) {
+ init(minx, miny, minz, maxx, maxy, maxz);
+ }
+ rescale(const carve::geom3d::Vector &min, const carve::geom3d::Vector &max) {
+ init(min.x, min.y, min.z, max.x, max.y, max.z);
+ }
+ };
+
+ struct fwd {
+ rescale r;
+ fwd(const rescale &_r) : r(_r) { }
+ carve::geom3d::Vector operator()(const carve::geom3d::Vector &v) const { return carve::geom::VECTOR((v.x - r.dx) / r.scale, (v.y - r.dy) / r.scale, (v.z - r.dz) / r.scale); }
+ };
+
+ struct rev {
+ rescale r;
+ rev(const rescale &_r) : r(_r) { }
+ carve::geom3d::Vector operator()(const carve::geom3d::Vector &v) const { return carve::geom::VECTOR((v.x * r.scale) + r.dx, (v.y * r.scale) + r.dy, (v.z * r.scale) + r.dz); }
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/rtree.hpp b/extern/carve/include/carve/rtree.hpp
new file mode 100644
index 00000000000..77f93c14e08
--- /dev/null
+++ b/extern/carve/include/carve/rtree.hpp
@@ -0,0 +1,501 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom.hpp>
+#include <carve/aabb.hpp>
+
+#include <iostream>
+
+#include <cmath>
+#include <limits>
+
+#if defined(HAVE_STDINT_H)
+# include <stdint.h>
+#endif
+
+namespace carve {
+ namespace geom {
+
+ template<unsigned ndim,
+ typename data_t,
+ typename aabb_calc_t = carve::geom::get_aabb<ndim, data_t> >
+ struct RTreeNode {
+ typedef aabb<ndim> aabb_t;
+ typedef vector<ndim> vector_t;
+ typedef RTreeNode<ndim, data_t, aabb_calc_t> node_t;
+
+ aabb_t bbox;
+ node_t *child;
+ node_t *sibling;
+ std::vector<data_t> data;
+
+ aabb_t getAABB() const { return bbox; }
+
+
+
+ struct data_aabb_t {
+ aabb_t bbox;
+ data_t data;
+
+ data_aabb_t() { }
+ data_aabb_t(const data_t &_data) : bbox(aabb_calc_t()(_data)), data(_data) {
+ }
+
+ aabb_t getAABB() const { return bbox; }
+
+ struct cmp {
+ size_t dim;
+ cmp(size_t _dim) : dim(_dim) { }
+ bool operator()(const data_aabb_t &a, const data_aabb_t &b) {
+ return a.bbox.pos.v[dim] < b.bbox.pos.v[dim];
+ }
+ };
+ };
+
+ // Fill an rtree node with a set of (data, aabb) pairs.
+ template<typename iter_t>
+ void _fill(iter_t begin, iter_t end, data_aabb_t) {
+ data.reserve(std::distance(begin, end));
+ for (iter_t i = begin; i != end; ++i) {
+ data.push_back((*i).data);
+ }
+ bbox.fit(begin, end);
+ }
+
+ // Fill an rtree node with a set of data.
+ template<typename iter_t>
+ void _fill(iter_t begin, iter_t end, data_t) {
+ data.reserve(std::distance(begin, end));
+ std::copy(begin, end, std::back_inserter(data));
+ bbox.fit(begin, end, aabb_calc_t());
+ }
+
+ // Fill an rtree node with a set of child nodes.
+ template<typename iter_t>
+ void _fill(iter_t begin, iter_t end, node_t *) {
+ iter_t i = begin;
+ node_t *curr = child = *i;
+ while (++i != end) {
+ curr->sibling = *i;
+ curr = curr->sibling;
+ }
+ bbox.fit(begin, end);
+ }
+
+ // Search the rtree for objects that intersect obj (generally an aabb).
+ // The aabb class must provide a method intersects(obj_t).
+ template<typename obj_t, typename out_iter_t>
+ void search(const obj_t &obj, out_iter_t out) const {
+ if (!bbox.intersects(obj)) return;
+ if (child) {
+ for (node_t *node = child; node; node = node->sibling) {
+ node->search(obj, out);
+ }
+ } else {
+ std::copy(data.begin(), data.end(), out);
+ }
+ }
+
+ // update the bounding box extents of nodes that intersect obj (generally an aabb).
+ // The aabb class must provide a method intersects(obj_t).
+ template<typename obj_t>
+ void updateExtents(const obj_t &obj) {
+ if (!bbox.intersects(obj)) return;
+
+ if (child) {
+ node_t *node = child;
+ node->updateExtents(obj);
+ bbox = node->bbox;
+ for (node = node->sibling; node; node = node->sibling) {
+ node->updateExtents(obj);
+ bbox.unionAABB(node->bbox);
+ }
+ } else {
+ bbox.fit(data.begin(), data.end());
+ }
+ }
+
+ // update the bounding box extents of nodes that intersect obj (generally an aabb).
+ // The aabb class must provide a method intersects(obj_t).
+ bool remove(const data_t &val, const aabb_t &val_aabb) {
+ if (!bbox.intersects(val_aabb)) return false;
+
+ if (child) {
+ node_t *node = child;
+ node->remove(val, val_aabb);
+ bbox = node->bbox;
+ bool removed = false;
+ for (node = node->sibling; node; node = node->sibling) {
+ if (!removed) removed = node->remove(val, val_aabb);
+ bbox.unionAABB(node->bbox);
+ }
+ return removed;
+ } else {
+ typename std::vector<data_t>::iterator i = std::remove(data.begin(), data.end(), val);
+ if (i == data.end()) {
+ return false;
+ }
+ data.erase(i, data.end());
+ bbox.fit(data.begin(), data.end());
+ return true;
+ }
+ }
+
+ template<typename iter_t>
+ RTreeNode(iter_t begin, iter_t end) : bbox(), child(NULL), sibling(NULL), data() {
+ _fill(begin, end, typename std::iterator_traits<iter_t>::value_type());
+ }
+
+
+
+ // functor for ordering nodes by increasing aabb midpoint, along a specified axis.
+ struct aabb_cmp_mid {
+ size_t dim;
+ aabb_cmp_mid(size_t _dim) : dim(_dim) { }
+
+ bool operator()(const node_t *a, const node_t *b) {
+ return a->bbox.mid(dim) < b->bbox.mid(dim);
+ }
+ bool operator()(const data_aabb_t &a, const data_aabb_t &b) {
+ return a.bbox.mid(dim) < b.bbox.mid(dim);
+ }
+ };
+
+ // functor for ordering nodes by increasing aabb minimum, along a specified axis.
+ struct aabb_cmp_min {
+ size_t dim;
+ aabb_cmp_min(size_t _dim) : dim(_dim) { }
+
+ bool operator()(const node_t *a, const node_t *b) {
+ return a->bbox.min(dim) < b->bbox.min(dim);
+ }
+ bool operator()(const data_aabb_t &a, const data_aabb_t &b) {
+ return a.bbox.min(dim) < b.bbox.min(dim);
+ }
+ };
+
+ // functor for ordering nodes by increasing aabb maximum, along a specified axis.
+ struct aabb_cmp_max {
+ size_t dim;
+ aabb_cmp_max(size_t _dim) : dim(_dim) { }
+
+ bool operator()(const node_t *a, const node_t *b) {
+ return a->bbox.max(dim) < b->bbox.max(dim);
+ }
+ bool operator()(const data_aabb_t &a, const data_aabb_t &b) {
+ return a.bbox.max(dim) < b.bbox.max(dim);
+ }
+ };
+
+ // facade for projecting node bounding box onto an axis.
+ struct aabb_extent {
+ size_t dim;
+ aabb_extent(size_t _dim) : dim(_dim) { }
+
+ double min(const node_t *a) { return a->bbox.pos.v[dim] - a->bbox.extent.v[dim]; }
+ double max(const node_t *a) { return a->bbox.pos.v[dim] + a->bbox.extent.v[dim]; }
+ double len(const node_t *a) { return 2.0 * a->bbox.extent.v[dim]; }
+ double min(const data_aabb_t &a) { return a.bbox.pos.v[dim] - a.bbox.extent.v[dim]; }
+ double max(const data_aabb_t &a) { return a.bbox.pos.v[dim] + a.bbox.extent.v[dim]; }
+ double len(const data_aabb_t &a) { return 2.0 * a.bbox.extent.v[dim]; }
+ };
+
+ template<typename iter_t>
+ static void makeNodes(const iter_t begin,
+ const iter_t end,
+ size_t dim_num,
+ uint32_t dim_mask,
+ size_t child_size,
+ std::vector<node_t *> &out) {
+ const size_t N = std::distance(begin, end);
+
+ size_t dim = ndim;
+ double r_best = N+1;
+
+ // find the sparsest remaining dimension to partition by.
+ for (size_t i = 0; i < ndim; ++i) {
+ if (dim_mask & (1U << i)) continue;
+ aabb_extent extent(i);
+ double dmin, dmax, dsum;
+
+ dmin = extent.min(*begin);
+ dmax = extent.max(*begin);
+ dsum = 0.0;
+ for (iter_t j = begin; j != end; ++j) {
+ dmin = std::min(dmin, extent.min(*j));
+ dmax = std::max(dmax, extent.max(*j));
+ dsum += extent.len(*j);
+ }
+ double r = dsum ? dsum / (dmax - dmin) : 0.0;
+ if (r_best > r) {
+ dim = i;
+ r_best = r;
+ }
+ }
+
+ CARVE_ASSERT(dim < ndim);
+
+ // dim = dim_num;
+
+ const size_t P = (N + child_size - 1) / child_size;
+ const size_t n_parts = (size_t)std::ceil(std::pow((double)P, 1.0 / (ndim - dim_num)));
+
+ std::sort(begin, end, aabb_cmp_mid(dim));
+
+ if (dim_num == ndim - 1 || n_parts == 1) {
+ for (size_t i = 0, s = 0, e = 0; i < P; ++i, s = e) {
+ e = N * (i+1) / P;
+ CARVE_ASSERT(e - s <= child_size);
+ out.push_back(new node_t(begin + s, begin + e));
+ }
+ } else {
+ for (size_t i = 0, s = 0, e = 0; i < n_parts; ++i, s = e) {
+ e = N * (i+1) / n_parts;
+ makeNodes(begin + s, begin + e, dim_num + 1, dim_mask | (1U << dim), child_size, out);
+ }
+ }
+ }
+
+ static node_t *construct_STR(std::vector<data_aabb_t> &data, size_t leaf_size, size_t internal_size) {
+ std::vector<node_t *> out;
+ makeNodes(data.begin(), data.end(), 0, 0, leaf_size, out);
+
+ while (out.size() > 1) {
+ std::vector<node_t *> next;
+ makeNodes(out.begin(), out.end(), 0, 0, internal_size, next);
+ std::swap(out, next);
+ }
+
+ CARVE_ASSERT(out.size() == 1);
+ return out[0];
+ }
+
+ template<typename iter_t>
+ static node_t *construct_STR(const iter_t &begin,
+ const iter_t &end,
+ size_t leaf_size,
+ size_t internal_size) {
+ std::vector<data_aabb_t> data;
+ data.reserve(std::distance(begin, end));
+ for (iter_t i = begin; i != end; ++i) {
+ data.push_back(*i);
+ }
+ return construct_STR(data, leaf_size, internal_size);
+ }
+
+
+ template<typename iter_t>
+ static node_t *construct_STR(const iter_t &begin1,
+ const iter_t &end1,
+ const iter_t &begin2,
+ const iter_t &end2,
+ size_t leaf_size,
+ size_t internal_size) {
+ std::vector<data_aabb_t> data;
+ data.reserve(std::distance(begin1, end1) + std::distance(begin2, end2));
+ for (iter_t i = begin1; i != end1; ++i) {
+ data.push_back(*i);
+ }
+ for (iter_t i = begin2; i != end2; ++i) {
+ data.push_back(*i);
+ }
+ return construct_STR(data, leaf_size, internal_size);
+ }
+
+
+ struct partition_info {
+ double score;
+ size_t partition_pos;
+
+ partition_info() : score(std::numeric_limits<double>::max()), partition_pos(0) {
+ }
+ partition_info(double _score, size_t _partition_pos) :
+ score(_score),
+ partition_pos(_partition_pos) {
+ }
+ };
+
+ static partition_info findPartition(typename std::vector<data_aabb_t>::iterator base,
+ std::vector<size_t>::iterator begin,
+ std::vector<size_t>::iterator end,
+ size_t part_size) {
+ partition_info best(std::numeric_limits<double>::max(), 0);
+ const size_t N = std::distance(begin, end);
+
+ std::vector<double> rhs_vol(N, 0.0);
+
+ aabb_t rhs = base[begin[N-1]].aabb;
+ rhs_vol[N-1] = rhs.volume();
+ for (size_t i = N - 1; i > 0; ) {
+ rhs.unionAABB(base[begin[--i]].aabb);
+ rhs_vol[i] = rhs.volume();
+ }
+
+ aabb_t lhs = base[begin[0]].aabb;
+ for (size_t i = 1; i < N; ++i) {
+ lhs.unionAABB(base[begin[i]].aabb);
+ if (i % part_size == 0 || (N - i) % part_size == 0) {
+ partition_info curr(lhs.volume() + rhs_vol[i], i);
+ if (best.score > curr.score) best = curr;
+ }
+ }
+ return best;
+ }
+
+ static void partition(typename std::vector<data_aabb_t>::iterator base,
+ std::vector<size_t>::iterator begin,
+ std::vector<size_t>::iterator end,
+ size_t part_size,
+ std::vector<size_t> &part_num,
+ size_t &part_next) {
+ const size_t N = std::distance(begin, end);
+
+ partition_info best;
+ partition_info curr;
+ size_t part_curr = part_num[*begin];
+
+ std::vector<size_t> tmp(begin, end);
+
+ for (size_t dim = 0; dim < ndim; ++dim) {
+ std::sort(tmp.begin(), tmp.end(), make_index_sort(base, aabb_cmp_min(dim)));
+ curr = findPartition(base, tmp.begin(), tmp.end(), part_size);
+ if (best.score > curr.score) {
+ best = curr;
+ std::copy(tmp.begin(), tmp.end(), begin);
+ }
+
+ std::sort(tmp.begin(), tmp.end(), make_index_sort(base, aabb_cmp_mid(dim)));
+ curr = findPartition(base, tmp.begin(), tmp.end(), part_size);
+ if (best.score > curr.score) {
+ best = curr;
+ std::copy(tmp.begin(), tmp.end(), begin);
+ }
+
+ std::sort(tmp.begin(), tmp.end(), make_index_sort(base, aabb_cmp_max(dim)));
+ curr = findPartition(base, tmp.begin(), tmp.end(), part_size);
+ if (best.score > curr.score) {
+ best = curr;
+ std::copy(tmp.begin(), tmp.end(), begin);
+ }
+ }
+
+ for (size_t j = 0; j < best.partition_pos; ++j) part_num[begin[j]] = part_curr;
+ for (size_t j = best.partition_pos; j < N; ++j) part_num[begin[j]] = part_next;
+ ++part_next;
+
+ if (best.partition_pos > part_size) {
+ partition(base, begin, begin + best.partition_pos, part_size, part_num, part_next);
+ }
+ if (N - best.partition_pos > part_size) {
+ partition(base, begin + best.partition_pos, end, part_size, part_num, part_next);
+ }
+ }
+
+ static size_t makePartitions(typename std::vector<data_aabb_t>::iterator begin,
+ typename std::vector<data_aabb_t>::iterator end,
+ size_t part_size,
+ std::vector<size_t> &part_num) {
+ const size_t N = std::distance(begin, end);
+ std::vector<size_t> idx;
+ idx.reserve(N);
+ for (size_t i = 0; i < N; ++i) { idx.push_back(i); }
+ size_t part_next = 1;
+
+ partition(begin, idx.begin(), idx.end(), part_size, part_num, part_next);
+ return part_next;
+ }
+
+ static node_t *construct_TGS(typename std::vector<data_aabb_t>::iterator begin,
+ typename std::vector<data_aabb_t>::iterator end,
+ size_t leaf_size,
+ size_t internal_size) {
+ size_t N = std::distance(begin, end);
+
+ if (N <= leaf_size) {
+ return new node_t(begin, end);
+ } else {
+ size_t P = (N + internal_size - 1) / internal_size;
+ std::vector<size_t> part_num(N, 0);
+ P = makePartitions(begin, end, P, part_num);
+
+ size_t S = 0, E = 0;
+ std::vector<node_t *> children;
+ for (size_t i = 0; i < P; ++i) {
+ size_t j = S, k = N;
+ while (true) {
+ while (true) {
+ if (j == k) goto done;
+ else if (part_num[j] == i) ++j;
+ else break;
+ }
+ --k;
+ while (true) {
+ if (j == k) goto done;
+ else if (part_num[k] != i) --k;
+ else break;
+ }
+ std::swap(*(begin+j), *(begin+k));
+ std::swap(part_num[j], part_num[k]);
+ ++j;
+ }
+ done:
+ E = j;
+ children.push_back(construct_TGS(begin + S, begin + E, leaf_size, internal_size));
+ S = E;
+ }
+ return new node_t(children.begin(), children.end());
+ }
+ }
+
+ template<typename iter_t>
+ static node_t *construct_TGS(const iter_t &begin,
+ const iter_t &end,
+ size_t leaf_size,
+ size_t internal_size) {
+ std::vector<data_aabb_t> data;
+ data.reserve(std::distance(begin, end));
+ for (iter_t i = begin; i != end; ++i) {
+ data.push_back(*i);
+ }
+ return construct_TGS(data.begin(), data.end(), leaf_size, internal_size);
+ }
+
+ template<typename iter_t>
+ static node_t *construct_TGS(const iter_t &begin1,
+ const iter_t &end1,
+ const iter_t &begin2,
+ const iter_t &end2,
+ size_t leaf_size,
+ size_t internal_size) {
+ std::vector<data_aabb_t> data;
+ data.reserve(std::distance(begin1, end1) + std::distance(begin2, end2));
+ for (iter_t i = begin1; i != end1; ++i) {
+ data.push_back(*i);
+ }
+ for (iter_t i = begin2; i != end2; ++i) {
+ data.push_back(*i);
+ }
+ return construct_TGS(data.begin(), data.end(), leaf_size, internal_size);
+ }
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/spacetree.hpp b/extern/carve/include/carve/spacetree.hpp
new file mode 100644
index 00000000000..f2ea2bb83a7
--- /dev/null
+++ b/extern/carve/include/carve/spacetree.hpp
@@ -0,0 +1,264 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom.hpp>
+#include <carve/aabb.hpp>
+#include <carve/vertex_decl.hpp>
+#include <carve/edge_decl.hpp>
+#include <carve/face_decl.hpp>
+
+namespace carve {
+
+ namespace space {
+
+ static inline bool intersection_test(const carve::geom::aabb<3> &aabb, const carve::poly::Face<3> *face) {
+ if (face->nVertices() == 3) {
+ return aabb.intersects(carve::geom::tri<3>(face->vertex(0)->v, face->vertex(1)->v, face->vertex(2)->v));
+ } else {
+ // partial, conservative SAT.
+ return aabb.intersects(face->aabb) && aabb.intersects(face->plane_eqn);
+ }
+ }
+
+ static inline bool intersection_test(const carve::geom::aabb<3> &aabb, const carve::poly::Edge<3> *edge) {
+ return aabb.intersectsLineSegment(edge->v1->v, edge->v2->v);
+ }
+
+ static inline bool intersection_test(const carve::geom::aabb<3> &aabb, const carve::poly::Vertex<3> *vertex) {
+ return aabb.intersects(vertex->v);
+ }
+
+
+
+ struct nodedata_FaceEdge {
+ std::vector<const carve::poly::Face<3> *> faces;
+ std::vector<const carve::poly::Edge<3> *> edges;
+
+ void add(const carve::poly::Face<3> *face) {
+ faces.push_back(face);
+ }
+
+ void add(const carve::poly::Edge<3> *edge) {
+ edges.push_back(edge);
+ }
+
+ template<typename iter_t>
+ void _fetch(iter_t &iter, const carve::poly::Edge<3> *) {
+ std::copy(edges.begin(), edges.end(), iter);
+ }
+
+ template<typename iter_t>
+ void _fetch(iter_t &iter, const carve::poly::Face<3> *) {
+ std::copy(faces.begin(), faces.end(), iter);
+ }
+
+ template<typename node_t>
+ void propagate(node_t *node) {
+ }
+
+ template<typename iter_t>
+ void fetch(iter_t &iter) {
+ return _fetch(iter, std::iterator_traits<iter_t>::value_type);
+ }
+ };
+
+
+
+ const static double SLACK_FACTOR = 1.0009765625;
+ const static unsigned MAX_SPLIT_DEPTH = 32;
+
+
+
+ template<unsigned n_dim, typename nodedata_t>
+ class SpatialSubdivTree {
+
+ typedef carve::geom::aabb<n_dim> aabb_t;
+ typedef carve::geom::vector<n_dim> vector_t;
+
+ public:
+
+ class Node {
+ enum {
+ n_children = 1 << n_dim
+ };
+
+ public:
+ Node *parent;
+ Node *children;
+
+ vector_t min;
+ vector_t max;
+
+ aabb_t aabb;
+
+ nodedata_t data;
+
+ private:
+ Node(const Node &node); // undefined.
+ Node &operator=(const Node &node); // undefined.
+
+ Node() {
+ }
+
+ inline aabb_t makeAABB() const {
+ vector_t centre = 0.5 * (min + max);
+ vector_t size = SLACK_FACTOR * 0.5 * (max - min);
+ return aabb_t(centre, size);
+ }
+
+ void setup(Node *_parent, const vector_t &_min, const vector_t &_max) {
+ parent = _parent;
+ min = _min;
+ max = _max;
+ aabb = makeAABB();
+ }
+
+ void alloc_children() {
+ vector_t mid = 0.5 * (min + max);
+ children = new Node[n_children];
+ for (size_t i = 0; i < (n_children); ++i) {
+ vector_t new_min, new_max;
+ for (size_t c = 0; c < n_dim; ++c) {
+ if (i & (1 << c)) {
+ new_min.v[c] = min.v[c];
+ new_max.v[c] = mid.v[c];
+ } else {
+ new_min.v[c] = mid.v[c];
+ new_max.v[c] = max.v[c];
+ }
+ }
+ children[i].setup(this, new_min, new_max);
+ }
+ }
+
+ void dealloc_children() {
+ delete [] children;
+ }
+
+ public:
+
+ inline bool isLeaf() const { return children == NULL; }
+
+ Node(Node *_parent, const vector_t &_min, const vector_t &_max) : parent(_parent), children(NULL), min(_min), max(_max) {
+ aabb = makeAABB();
+ }
+
+ ~Node() {
+ dealloc_children();
+ }
+
+ bool split() {
+ if (isLeaf()) {
+ alloc_children();
+ data.propagate(this);
+ }
+ return isLeaf();
+ }
+
+ template<typename obj_t>
+ void insert(const obj_t &object) {
+ if (!isLeaf()) {
+ for (size_t i = 0; i < n_children; ++i) {
+ if (intersection_test(children[i].aabb, object)) {
+ children[i].insert(object);
+ }
+ }
+ } else {
+ data.add(object);
+ }
+ }
+
+ template<typename obj_t>
+ void insertVector(typename std::vector<obj_t>::iterator beg, typename std::vector<obj_t>::iterator end) {
+ if (isLeaf()) {
+ while (beg != end) {
+ data.add(*beg);
+ }
+ } else {
+ for (size_t i = 0; i < n_children; ++i) {
+ typename std::vector<obj_t>::iterator mid = std::partition(beg, end, std::bind1st(intersection_test, children[i].aabb));
+ children[i].insertVector(beg, mid);
+ }
+ }
+ }
+
+ template<typename iter_t>
+ void insertMany(iter_t begin, iter_t end) {
+ if (isLeaf()) {
+ }
+ }
+
+ template<typename obj_t, typename iter_t, typename filter_t>
+ void findObjectsNear(const obj_t &object, iter_t &output, filter_t filter) {
+ if (!isLeaf()) {
+ for (size_t i = 0; i < n_children; ++i) {
+ if (intersection_test(children[i].aabb, object)) {
+ children[i].findObjectsNear(object, output, filter);
+ }
+ }
+ return;
+ }
+ data.fetch(output);
+ }
+
+ // bool hasGeometry();
+
+ // template <class T>
+ // void putInside(const T &input, Node *child, T &output);
+
+ };
+
+
+
+ Node *root;
+
+ SpatialSubdivTree(const vector_t &_min, const vector_t &_max) : root(new Node(NULL, _min, _max)) {
+ }
+
+ ~SpatialSubdivTree() {
+ delete root;
+ }
+
+ struct no_filter {
+ template<typename obj_t>
+ bool operator()(const obj_t &obj) const {
+ return true;
+ }
+ };
+
+ struct tag_filter {
+ template<typename obj_t>
+ bool operator()(const obj_t &obj) const {
+ return obj.tag_once();
+ }
+ };
+
+ // in order to be used as an input, aabb_t::intersect(const obj_t &) must exist.
+ template<typename obj_t, typename iter_t, typename filter_t>
+ void findObjectsNear(const obj_t &object, iter_t output, filter_t filter) {
+ if (!intersection_test(root->aabb, object)) return;
+ root->findObjectsNear(root, object, output, filter);
+ }
+
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/tag.hpp b/extern/carve/include/carve/tag.hpp
new file mode 100644
index 00000000000..57f9ba21460
--- /dev/null
+++ b/extern/carve/include/carve/tag.hpp
@@ -0,0 +1,44 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+namespace carve {
+
+ class tagable {
+ private:
+ static int s_count;
+
+ protected:
+ mutable int __tag;
+
+ public:
+ tagable(const tagable &) : __tag(s_count - 1) { }
+ tagable &operator=(const tagable &) { return *this; }
+
+ tagable() : __tag(s_count - 1) { }
+
+ void tag() const { __tag = s_count; }
+ void untag() const { __tag = s_count - 1; }
+ bool is_tagged() const { return __tag == s_count; }
+ bool tag_once() const { if (__tag == s_count) return false; __tag = s_count; return true; }
+
+ static void tag_begin() { s_count++; }
+ };
+}
diff --git a/extern/carve/include/carve/timing.hpp b/extern/carve/include/carve/timing.hpp
new file mode 100644
index 00000000000..f5051f72d63
--- /dev/null
+++ b/extern/carve/include/carve/timing.hpp
@@ -0,0 +1,96 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#ifndef CARVE_USE_TIMINGS
+#define CARVE_USE_TIMINGS 0
+#endif
+
+namespace carve {
+
+#if CARVE_USE_TIMINGS
+
+ class TimingName {
+ public:
+ TimingName(const char *name);
+ int id;
+ };
+
+ class TimingBlock {
+ public:
+ /**
+ * Starts timing at the end of this constructor, using the given ID. To
+ * associate an ID with a textual name, use Timing::registerID.
+ */
+ TimingBlock(int id);
+ TimingBlock(const TimingName &name);
+ ~TimingBlock();
+ };
+
+ class Timing {
+ public:
+
+ /**
+ * Starts timing against a particular ID.
+ */
+ static void start(int id);
+
+ static void start(const TimingName &id) {
+ start(id.id);
+ }
+
+ /**
+ * Stops the most recent timing block.
+ */
+ static double stop();
+
+ /**
+ * This will print out the current state of recorded time blocks. It will
+ * display the tree of timings, as well as the summaries down the bottom.
+ */
+ static void printTimings();
+
+ /**
+ * Associates a particular ID with a text string. This is used when
+ * printing out the timings.
+ */
+ static void registerID(int id, const char *name);
+
+ };
+
+#else
+
+ struct TimingName {
+ TimingName(const char *) {}
+ };
+ struct TimingBlock {
+ TimingBlock(int /* id */) {}
+ TimingBlock(const TimingName & /* name */) {}
+ };
+ struct Timing {
+ static void start(int /* id */) {}
+ static void start(const TimingName & /* id */) {}
+ static double stop() { return 0; }
+ static void printTimings() {}
+ static void registerID(int /* id */, const char * /* name */) {}
+ };
+
+#endif
+}
diff --git a/extern/carve/include/carve/tree.hpp b/extern/carve/include/carve/tree.hpp
new file mode 100644
index 00000000000..ba1bcc6e3c1
--- /dev/null
+++ b/extern/carve/include/carve/tree.hpp
@@ -0,0 +1,324 @@
+
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/matrix.hpp>
+#include <carve/timing.hpp>
+#include <carve/rescale.hpp>
+
+namespace carve {
+ namespace csg {
+
+ class CSG_TreeNode {
+ CSG_TreeNode(const CSG_TreeNode &);
+ CSG_TreeNode &operator=(const CSG_TreeNode &);
+
+ protected:
+
+ public:
+ CSG_TreeNode() {
+ }
+
+ virtual ~CSG_TreeNode() {
+ }
+
+ virtual carve::mesh::MeshSet<3> *eval(bool &is_temp, CSG &csg) =0;
+
+ virtual carve::mesh::MeshSet<3> *eval(CSG &csg) {
+ bool temp;
+ carve::mesh::MeshSet<3> *r = eval(temp, csg);
+ if (!temp) r = r->clone();
+ return r;
+ }
+ };
+
+
+
+ class CSG_TransformNode : public CSG_TreeNode {
+ carve::math::Matrix transform;
+ CSG_TreeNode *child;
+
+ public:
+ CSG_TransformNode(const carve::math::Matrix &_transform, CSG_TreeNode *_child) : transform(_transform), child(_child) {
+ }
+ virtual ~CSG_TransformNode() {
+ delete child;
+ }
+
+ virtual carve::mesh::MeshSet<3> *eval(bool &is_temp, CSG &csg) {
+ carve::mesh::MeshSet<3> *result = child->eval(is_temp, csg);
+ if (!is_temp) {
+ result = result->clone();
+ is_temp = true;
+ }
+ result->transform(carve::math::matrix_transformation(transform));
+ return result;
+ }
+ };
+
+
+
+
+ class CSG_InvertNode : public CSG_TreeNode {
+ std::vector<bool> selected_meshes;
+ CSG_TreeNode *child;
+
+ public:
+ CSG_InvertNode(CSG_TreeNode *_child) : selected_meshes(), child(_child) {
+ }
+ CSG_InvertNode(int g_id, CSG_TreeNode *_child) : selected_meshes(), child(_child) {
+ selected_meshes.resize(g_id + 1, false);
+ selected_meshes[g_id] = true;
+ }
+ virtual ~CSG_InvertNode() {
+ delete child;
+ }
+
+ template<typename T>
+ CSG_InvertNode(T start, T end, CSG_TreeNode *_child) : selected_meshes(), child(_child) {
+ while (start != end) {
+ int g_id = (int)(*start);
+ if (selected_meshes.size() < g_id + 1) selected_meshes.resize(g_id + 1, false);
+ selected_meshes[g_id] = true;
+ ++start;
+ }
+ }
+
+ virtual carve::mesh::MeshSet<3> *eval(bool &is_temp, CSG &csg) {
+ bool c_temp;
+ carve::mesh::MeshSet<3> *c = child->eval(c_temp, csg);
+ if (!c_temp) c = c->clone();
+ if (!selected_meshes.size()) {
+ c->invert();
+ } else {
+ for (size_t i = 0; i < c->meshes.size() && i < selected_meshes.size(); ++i) {
+ if (selected_meshes[i]) {
+ c->meshes[i]->invert();
+ }
+ }
+ }
+ is_temp = true;
+ return c;
+ }
+ };
+
+
+
+
+ class CSG_SelectNode : public CSG_TreeNode {
+ std::vector<bool> selected_meshes;
+ CSG_TreeNode *child;
+
+ public:
+ CSG_SelectNode(int m_id, CSG_TreeNode *_child) : selected_meshes(), child(_child) {
+ selected_meshes.resize(m_id + 1, false);
+ selected_meshes[m_id] = true;
+ }
+
+ template<typename T>
+ CSG_SelectNode(T start, T end, CSG_TreeNode *_child) : selected_meshes(), child(_child) {
+ while (start != end) {
+ int m_id = (int)(*start);
+ if ((int)selected_meshes.size() < m_id + 1) selected_meshes.resize(m_id + 1, false);
+ selected_meshes[m_id] = true;
+ ++start;
+ }
+ }
+
+ virtual ~CSG_SelectNode() {
+ delete child;
+ }
+
+ virtual carve::mesh::MeshSet<3> *eval(bool &is_temp, CSG &csg) {
+ bool c_temp;
+ carve::mesh::MeshSet<3> *c = child->eval(c_temp, csg);
+ if (!c_temp) c = c->clone();
+ size_t i = 0;
+ size_t j = 0;
+ for (size_t i = 0; i < c->meshes.size(); ++i) {
+ if (i >= selected_meshes.size() || !selected_meshes[i]) {
+ delete c->meshes[i];
+ c->meshes[i] = NULL;
+ } else {
+ c->meshes[j++] = c->meshes[i];
+ }
+ }
+ c->meshes.erase(c->meshes.begin() + j, c->meshes.end());
+ c->collectVertices();
+ is_temp = true;
+ return c;
+ }
+ };
+
+
+
+
+ class CSG_PolyNode : public CSG_TreeNode {
+ carve::mesh::MeshSet<3> *poly;
+ bool del;
+
+ public:
+ CSG_PolyNode(carve::mesh::MeshSet<3> *_poly, bool _del) : poly(_poly), del(_del) {
+ }
+ virtual ~CSG_PolyNode() {
+ static carve::TimingName FUNC_NAME("delete polyhedron");
+ carve::TimingBlock block(FUNC_NAME);
+
+ if (del) {
+ delete poly;
+ }
+ }
+
+ virtual carve::mesh::MeshSet<3> *eval(bool &is_temp, CSG &csg) {
+ is_temp = false;
+ return poly;
+ }
+ };
+
+
+
+ class CSG_OPNode : public CSG_TreeNode {
+ CSG_TreeNode *left, *right;
+ CSG::OP op;
+ bool rescale;
+ CSG::CLASSIFY_TYPE classify_type;
+
+ public:
+ CSG_OPNode(CSG_TreeNode *_left,
+ CSG_TreeNode *_right,
+ CSG::OP _op,
+ bool _rescale,
+ CSG::CLASSIFY_TYPE _classify_type = CSG::CLASSIFY_NORMAL) : left(_left), right(_right), op(_op), rescale(_rescale), classify_type(_classify_type) {
+ }
+
+ virtual ~CSG_OPNode() {
+ delete left;
+ delete right;
+ }
+
+ void minmax(double &min_x, double &min_y, double &min_z,
+ double &max_x, double &max_y, double &max_z,
+ const std::vector<carve::geom3d::Vector> &points) {
+ for (unsigned i = 1; i < points.size(); ++i) {
+ min_x = std::min(min_x, points[i].x);
+ max_x = std::max(max_x, points[i].x);
+ min_y = std::min(min_y, points[i].y);
+ max_y = std::max(max_y, points[i].y);
+ min_z = std::min(min_z, points[i].z);
+ max_z = std::max(max_z, points[i].z);
+ }
+ }
+
+ virtual carve::mesh::MeshSet<3> *evalScaled(bool &is_temp, CSG &csg) {
+ carve::mesh::MeshSet<3> *l, *r;
+ bool l_temp, r_temp;
+
+ l = left->eval(l_temp, csg);
+ r = right->eval(r_temp, csg);
+
+ if (!l_temp) { l = l->clone(); }
+ if (!r_temp) { r = r->clone(); }
+
+ carve::geom3d::Vector min, max;
+ carve::geom3d::Vector min_l, max_l;
+ carve::geom3d::Vector min_r, max_r;
+
+ carve::geom::bounds<3>(l->vertex_storage.begin(),
+ l->vertex_storage.end(),
+ carve::mesh::Face<3>::vector_mapping(),
+ min_l,
+ max_l);
+ carve::geom::bounds<3>(r->vertex_storage.begin(),
+ r->vertex_storage.end(),
+ carve::mesh::Face<3>::vector_mapping(),
+ min_r,
+ max_r);
+
+ carve::geom::assign_op(min, min_l, min_r, carve::util::min_functor());
+ carve::geom::assign_op(max, max_l, max_r, carve::util::max_functor());
+
+ carve::rescale::rescale scaler(min.x, min.y, min.z, max.x, max.y, max.z);
+
+ carve::rescale::fwd fwd_r(scaler);
+ carve::rescale::rev rev_r(scaler);
+
+ l->transform(fwd_r);
+ r->transform(fwd_r);
+
+ carve::mesh::MeshSet<3> *result = NULL;
+ {
+ static carve::TimingName FUNC_NAME("csg.compute()");
+ carve::TimingBlock block(FUNC_NAME);
+ result = csg.compute(l, r, op, NULL, classify_type);
+ }
+
+ {
+ static carve::TimingName FUNC_NAME("delete polyhedron");
+ carve::TimingBlock block(FUNC_NAME);
+
+ delete l;
+ delete r;
+ }
+
+ result->transform(rev_r);
+
+ is_temp = true;
+ return result;
+ }
+
+ virtual carve::mesh::MeshSet<3> *evalUnscaled(bool &is_temp, CSG &csg) {
+ carve::mesh::MeshSet<3> *l, *r;
+ bool l_temp, r_temp;
+
+ l = left->eval(l_temp, csg);
+ r = right->eval(r_temp, csg);
+
+ carve::mesh::MeshSet<3> *result = NULL;
+ {
+ static carve::TimingName FUNC_NAME("csg.compute()");
+ carve::TimingBlock block(FUNC_NAME);
+ result = csg.compute(l, r, op, NULL, classify_type);
+ }
+
+ {
+ static carve::TimingName FUNC_NAME("delete polyhedron");
+ carve::TimingBlock block(FUNC_NAME);
+
+ if (l_temp) delete l;
+ if (r_temp) delete r;
+ }
+
+ is_temp = true;
+ return result;
+ }
+
+
+ virtual carve::mesh::MeshSet<3> *eval(bool &is_temp, CSG &csg) {
+ if (rescale) {
+ return evalScaled(is_temp, csg);
+ } else {
+ return evalUnscaled(is_temp, csg);
+ }
+ }
+ };
+
+ }
+}
diff --git a/extern/carve/include/carve/triangulator.hpp b/extern/carve/include/carve/triangulator.hpp
new file mode 100644
index 00000000000..aa007f98077
--- /dev/null
+++ b/extern/carve/include/carve/triangulator.hpp
@@ -0,0 +1,175 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <list>
+#include <vector>
+#include <algorithm>
+
+#include <carve/carve.hpp>
+
+#include <carve/geom2d.hpp>
+
+namespace carve {
+ namespace triangulate {
+
+ /**
+ * \brief Merge a set of holes into a polygon. (templated)
+ *
+ * Take a polygon loop and a collection of hole loops, and patch
+ * the hole loops into the polygon loop, returning a vector of
+ * vertices from the polygon and holes, which describes a new
+ * polygon boundary with no holes. The new polygon boundary is
+ * constructed via the addition of edges * joining the polygon
+ * loop to the holes.
+ *
+ * This may be applied to arbitrary vertex data (generally
+ * carve::geom3d::Vertex pointers), but a projection function must
+ * be supplied to convert vertices to coordinates in 2-space, in
+ * which the work is performed.
+ *
+ * @tparam project_t A functor which converts vertices to a 2d
+ * projection.
+ * @tparam vert_t The vertex type.
+ * @param project The projection functor.
+ * @param f_loop The polygon loop into which holes are to be
+ * incorporated.
+ * @param h_loops The set of hole loops to be incorporated.
+ *
+ * @return A vector of vertex pointers.
+ */
+ template<typename project_t, typename vert_t>
+ static std::vector<vert_t>
+ incorporateHolesIntoPolygon(const project_t &project,
+ const std::vector<vert_t> &f_loop,
+ const std::vector<std::vector<vert_t> > &h_loops);
+
+ void
+ incorporateHolesIntoPolygon(const std::vector<std::vector<carve::geom2d::P2> > &poly,
+ std::vector<std::pair<size_t, size_t> > &result,
+ size_t poly_loop,
+ const std::vector<size_t> &hole_loops);
+
+ /**
+ * \brief Merge a set of holes into a polygon. (2d)
+ *
+ * Take a polygon loop and a collection of hole loops, and patch
+ * the hole loops into the polygon loop, returning a vector of
+ * containing the vertices from the polygon and holes which
+ * describes a new polygon boundary with no holes, through the
+ * addition of edges joining the polygon loop to the holes.
+ *
+ * @param poly A vector containing the face loop (the first
+ * element of poly) and the hole loops (second and
+ * subsequent elements of poly).
+ *
+ * @return A vector of pairs of <loop_number, index> that
+ * reference poly and define the result polygon loop.
+ */
+ std::vector<std::pair<size_t, size_t> > incorporateHolesIntoPolygon(const std::vector<std::vector<carve::geom2d::P2> > &poly);
+
+ std::vector<std::vector<std::pair<size_t, size_t> > > mergePolygonsAndHoles(const std::vector<std::vector<carve::geom2d::P2> > &poly);
+
+
+ struct tri_idx {
+ union {
+ unsigned v[3];
+ struct { unsigned a, b, c; };
+ };
+
+ tri_idx() : a(0), b(0), c(0) {
+ }
+ tri_idx(unsigned _a, unsigned _b, unsigned _c) : a(_a), b(_b), c(_c) {
+ }
+ };
+
+ /**
+ * \brief Triangulate a 2-dimensional polygon.
+ *
+ * Given a 2-dimensional polygon described as a vector of 2-d
+ * points, with no holes and no self-crossings, produce a
+ * triangulation using an ear-clipping algorithm.
+ *
+ * @param [in] poly A vector containing the input polygon.
+ * @param [out] result A vector of triangles, represented as
+ * indicies into poly.
+ */
+
+
+ void triangulate(const std::vector<carve::geom2d::P2> &poly, std::vector<tri_idx> &result);
+
+ /**
+ * \brief Triangulate a polygon (templated).
+ *
+ * @tparam project_t A functor which converts vertices to a 2d
+ * projection.
+ * @tparam vert_t The vertex type.
+ * @param [in] project The projection functor.
+ * @param [in] poly A vector containing the input polygon,
+ * represented as vert_t pointers.
+ * @param [out] result A vector of triangles, represented as
+ * indicies into poly.
+ */
+ template<typename project_t, typename vert_t>
+ void triangulate(const project_t &project,
+ const std::vector<vert_t> &poly,
+ std::vector<tri_idx> &result);
+
+ /**
+ * \brief Improve a candidate triangulation of poly by minimising
+ * the length of internal edges. (templated)
+ *
+ * @tparam project_t A functor which converts vertices to a 2d
+ * projection.
+ * @tparam vert_t The vertex type.
+ * @param [in] project The projection functor.
+ * @param [in] poly A vector containing the input polygon,
+ * represented as vert_t pointers.
+ * @param [inout] result A vector of triangles, represented as
+ * indicies into poly. On input, this vector
+ * must contain a candidate triangulation of
+ * poly. Calling improve() modifies the
+ * contents of the vector, returning an
+ * improved triangulation.
+ */
+ template<typename project_t, typename vert_t>
+ void improve(const project_t &project,
+ const std::vector<vert_t> &poly,
+ std::vector<tri_idx> &result);
+
+ /**
+ * \brief Improve a candidate triangulation of poly by minimising
+ * the length of internal edges.
+ *
+ * @param [in] poly A vector containing the input polygon.
+
+ * @param [inout] result A vector of triangles, represented as
+ * indicies into poly. On input, this vector
+ * must contain a candidate triangulation of
+ * poly. Calling improve() modifies the
+ * contents of the vector, returning an
+ * improved triangulation.
+ */
+ static inline void improve(const std::vector<carve::geom2d::P2> &poly, std::vector<tri_idx> &result) {
+ improve(carve::geom2d::p2_adapt_ident(), poly, result);
+ }
+
+ }
+}
+
+#include <carve/triangulator_impl.hpp>
diff --git a/extern/carve/include/carve/triangulator_impl.hpp b/extern/carve/include/carve/triangulator_impl.hpp
new file mode 100644
index 00000000000..476438fd248
--- /dev/null
+++ b/extern/carve/include/carve/triangulator_impl.hpp
@@ -0,0 +1,851 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/geom2d.hpp>
+
+#if defined(CARVE_DEBUG)
+# include <iostream>
+#endif
+
+namespace carve {
+ namespace triangulate {
+ namespace detail {
+
+
+
+ static inline bool axisOrdering(const carve::geom2d::P2 &a,
+ const carve::geom2d::P2 &b,
+ int axis) {
+ return a.v[axis] < b.v[axis] || (a.v[axis] == b.v[axis] && a.v[1-axis] < b.v[1-axis]);
+ }
+
+
+
+ /**
+ * \class order_h_loops
+ * \brief Provides an ordering of hole loops based upon a single
+ * projected axis.
+ *
+ * @tparam project_t A functor which converts vertices to a 2d
+ * projection.
+ * @tparam hole_t A collection of vertices.
+ */
+ template<typename project_t, typename vert_t>
+ class order_h_loops {
+ const project_t &project;
+ int axis;
+ public:
+
+ /**
+ *
+ * @param _project The projection functor.
+ * @param _axis The axis of the 2d projection upon which hole
+ * loops are ordered.
+ */
+ order_h_loops(const project_t &_project, int _axis) : project(_project), axis(_axis) { }
+
+ bool operator()(const vert_t &a,
+ const vert_t &b) const {
+ return axisOrdering(project(a), project(b), axis);
+ }
+
+ bool operator()(
+ const std::pair<const typename std::vector<vert_t> *, typename std::vector<vert_t>::const_iterator> &a,
+ const std::pair<const typename std::vector<vert_t> *, typename std::vector<vert_t>::const_iterator> &b) {
+ return axisOrdering(project(*(a.second)), project(*(b.second)), axis);
+ }
+ };
+
+
+
+ /**
+ * \class heap_ordering
+ * \brief Provides an ordering of vertex indicies in a polygon
+ * loop according to proximity to a vertex.
+ *
+ * @tparam project_t A functor which converts vertices to a 2d
+ * projection.
+ * @tparam vert_t A vertex type.
+ */
+ template<typename project_t, typename vert_t>
+ class heap_ordering {
+ const project_t &project;
+ const std::vector<vert_t> &loop;
+ const carve::geom2d::P2 p;
+ int axis;
+
+ public:
+ /**
+ *
+ * @param _project A functor which converts vertices to a 2d
+ * projection.
+ * @param _loop The polygon loop which indices address.
+ * @param _vert The vertex from which distance is measured.
+ *
+ */
+ heap_ordering(const project_t &_project,
+ const std::vector<vert_t> &_loop,
+ vert_t _vert,
+ int _axis) :
+ project(_project),
+ loop(_loop),
+ p(_project(_vert)),
+ axis(_axis) {
+ }
+
+ bool operator()(size_t a, size_t b) const {
+ carve::geom2d::P2 pa = project(loop[a]);
+ carve::geom2d::P2 pb = project(loop[b]);
+ double da = carve::geom::distance2(p, pa);
+ double db = carve::geom::distance2(p, pb);
+ if (da > db) return true;
+ if (da < db) return false;
+ return axisOrdering(pa, pb, axis);
+ }
+ };
+
+
+
+ /**
+ * \brief Given a polygon loop and a hole loop, and attachment
+ * points, insert the hole loop vertices into the polygon loop.
+ *
+ * @param[in,out] f_loop The polygon loop to incorporate the
+ * hole into.
+ * @param f_loop_attach[in] The index of the vertex of the
+ * polygon loop that the hole is to be
+ * attached to.
+ * @param hole_attach[in] A pair consisting of a pointer to a
+ * hole container and an iterator into
+ * that container reflecting the point of
+ * attachment of the hole.
+ */
+ template<typename vert_t>
+ void patchHoleIntoPolygon(std::vector<vert_t> &f_loop,
+ unsigned f_loop_attach,
+ const std::pair<const std::vector<vert_t> *,
+ typename std::vector<vert_t>::const_iterator> &hole_attach) {
+ // join the vertex curr of the polygon loop to the hole at
+ // h_loop_connect
+ f_loop.insert(f_loop.begin() + f_loop_attach + 1, hole_attach.first->size() + 2, NULL);
+ typename std::vector<vert_t>::iterator f = f_loop.begin() + f_loop_attach;
+
+ typename std::vector<vert_t>::const_iterator h = hole_attach.second;
+
+ while (h != hole_attach.first->end()) {
+ *++f = *h++;
+ }
+
+ h = hole_attach.first->begin();
+ typename std::vector<vert_t>::const_iterator he = hole_attach.second; ++he;
+ while (h != he) {
+ *++f = *h++;
+ }
+
+ *++f = f_loop[f_loop_attach];
+ }
+
+
+
+ struct vertex_info;
+
+
+
+ /**
+ * \brief Determine whether c is to the left of a->b.
+ */
+ static inline bool isLeft(const vertex_info *a,
+ const vertex_info *b,
+ const vertex_info *c);
+
+
+
+ /**
+ * \brief Determine whether d is contained in the triangle abc.
+ */
+ static inline bool pointInTriangle(const vertex_info *a,
+ const vertex_info *b,
+ const vertex_info *c,
+ const vertex_info *d);
+
+
+
+ /**
+ * \class vertex_info
+ * \brief Maintains a linked list of untriangulated vertices
+ * during a triangulation operation.
+ */
+
+ struct vertex_info {
+ vertex_info *prev;
+ vertex_info *next;
+ carve::geom2d::P2 p;
+ size_t idx;
+ double score;
+ bool convex;
+ bool failed;
+
+ vertex_info(const carve::geom2d::P2 &_p, size_t _idx) :
+ prev(NULL), next(NULL),
+ p(_p), idx(_idx),
+ score(0.0), convex(false) {
+ }
+
+ static double triScore(const vertex_info *p, const vertex_info *v, const vertex_info *n);
+
+ double calcScore() const;
+
+ void recompute() {
+ score = calcScore();
+ convex = isLeft(prev, this, next);
+ failed = false;
+ }
+
+ bool isCandidate() const {
+ return convex && !failed;
+ }
+
+ void remove() {
+ next->prev = prev;
+ prev->next = next;
+ }
+
+ bool isClipable() const;
+ };
+
+
+
+ static inline bool isLeft(const vertex_info *a,
+ const vertex_info *b,
+ const vertex_info *c) {
+ if (a->idx < b->idx && b->idx < c->idx) {
+ return carve::geom2d::orient2d(a->p, b->p, c->p) > 0.0;
+ } else if (a->idx < c->idx && c->idx < b->idx) {
+ return carve::geom2d::orient2d(a->p, c->p, b->p) < 0.0;
+ } else if (b->idx < a->idx && a->idx < c->idx) {
+ return carve::geom2d::orient2d(b->p, a->p, c->p) < 0.0;
+ } else if (b->idx < c->idx && c->idx < a->idx) {
+ return carve::geom2d::orient2d(b->p, c->p, a->p) > 0.0;
+ } else if (c->idx < a->idx && a->idx < b->idx) {
+ return carve::geom2d::orient2d(c->p, a->p, b->p) > 0.0;
+ } else {
+ return carve::geom2d::orient2d(c->p, b->p, a->p) < 0.0;
+ }
+ }
+
+
+
+ static inline bool pointInTriangle(const vertex_info *a,
+ const vertex_info *b,
+ const vertex_info *c,
+ const vertex_info *d) {
+ return !isLeft(a, c, d) && !isLeft(b, a, d) && !isLeft(c, b, d);
+ }
+
+
+
+ size_t removeDegeneracies(vertex_info *&begin, std::vector<carve::triangulate::tri_idx> &result);
+
+ bool splitAndResume(vertex_info *begin, std::vector<carve::triangulate::tri_idx> &result);
+
+ bool doTriangulate(vertex_info *begin, std::vector<carve::triangulate::tri_idx> &result);
+
+
+
+ typedef std::pair<unsigned, unsigned> vert_edge_t;
+
+
+
+ struct hash_vert_edge_t {
+ size_t operator()(const vert_edge_t &e) const {
+ size_t r = (size_t)e.first;
+ size_t s = (size_t)e.second;
+ return r ^ ((s >> 16) | (s << 16));
+ }
+ };
+
+
+
+ static inline vert_edge_t ordered_vert_edge_t(unsigned a, unsigned b) {
+ return (a < b) ? vert_edge_t(a, b) : vert_edge_t(b, a);
+ }
+
+
+
+ struct tri_pair_t {
+ carve::triangulate::tri_idx *a, *b;
+ double score;
+ size_t idx;
+
+ tri_pair_t() : a(NULL), b(NULL), score(0.0) {
+ }
+
+ static inline unsigned N(unsigned i) { return (i+1)%3; }
+ static inline unsigned P(unsigned i) { return (i+2)%3; }
+
+ void findSharedEdge(unsigned &ai, unsigned &bi) const {
+ if (a->v[1] == b->v[0]) { if (a->v[0] == b->v[1]) { ai = 0; bi = 0; } else { ai = 1; bi = 2; } return; }
+ if (a->v[1] == b->v[1]) { if (a->v[0] == b->v[2]) { ai = 0; bi = 1; } else { ai = 1; bi = 0; } return; }
+ if (a->v[1] == b->v[2]) { if (a->v[0] == b->v[0]) { ai = 0; bi = 2; } else { ai = 1; bi = 1; } return; }
+ if (a->v[2] == b->v[0]) { ai = 2; bi = 2; return; }
+ if (a->v[2] == b->v[1]) { ai = 2; bi = 0; return; }
+ if (a->v[2] == b->v[2]) { ai = 2; bi = 1; return; }
+ CARVE_FAIL("should not be reached");
+ }
+
+ void flip(vert_edge_t &old_edge,
+ vert_edge_t &new_edge,
+ vert_edge_t perim[4]);
+
+ template<typename project_t, typename vert_t, typename distance_calc_t>
+ double calc(const project_t &project,
+ const std::vector<vert_t> &poly,
+ distance_calc_t dist) {
+ unsigned ai, bi;
+ unsigned cross_ai, cross_bi;
+ unsigned ea, eb;
+
+ findSharedEdge(ai, bi);
+
+#if defined(CARVE_DEBUG)
+ if (carve::geom2d::signedArea(project(poly[a->v[0]]), project(poly[a->v[1]]), project(poly[a->v[2]])) > 0.0 ||
+ carve::geom2d::signedArea(project(poly[b->v[0]]), project(poly[b->v[1]]), project(poly[b->v[2]])) > 0.0) {
+ std::cerr << "warning: triangle pair " << this << " contains triangles with incorrect orientation" << std::endl;
+ }
+#endif
+
+ cross_ai = P(ai);
+ cross_bi = P(bi);
+
+ ea = a->v[cross_ai];
+ eb = b->v[cross_bi];
+
+ double side_1 = carve::geom2d::orient2d(project(poly[ea]), project(poly[eb]), project(poly[a->v[ai]]));
+ double side_2 = carve::geom2d::orient2d(project(poly[ea]), project(poly[eb]), project(poly[a->v[N(ai)]]));
+
+ bool can_flip = (side_1 < 0.0 && side_2 > 0.0) || (side_1 > 0.0 && side_2 < 0.0);
+
+ if (!can_flip) {
+ score = -1;
+ } else {
+ score =
+ dist(poly[a->v[ai]], poly[b->v[bi]]) -
+ dist(poly[a->v[cross_ai]], poly[b->v[cross_bi]]);
+ }
+ return score;
+ }
+
+ template<typename project_t, typename vert_t, typename distance_calc_t>
+ double edgeLen(const project_t &project,
+ const std::vector<vert_t> &poly,
+ distance_calc_t dist) const {
+ unsigned ai, bi;
+ findSharedEdge(ai, bi);
+ return dist(poly[a->v[ai]], poly[b->v[bi]]);
+ }
+ };
+
+
+
+ struct max_score {
+ bool operator()(const tri_pair_t *a, const tri_pair_t *b) const { return a->score < b->score; }
+ };
+
+
+
+ struct tri_pairs_t {
+ typedef std::unordered_map<vert_edge_t, tri_pair_t *, hash_vert_edge_t> storage_t;
+ storage_t storage;
+
+ tri_pairs_t() : storage() {
+ };
+
+ ~tri_pairs_t() {
+ for (storage_t::iterator i = storage.begin(); i != storage.end(); ++i) {
+ if ((*i).second) delete (*i).second;
+ }
+ }
+
+ void insert(unsigned a, unsigned b, carve::triangulate::tri_idx *t);
+
+ template<typename project_t, typename vert_t, typename distance_calc_t>
+ void updateEdge(tri_pair_t *tp,
+ const project_t &project,
+ const std::vector<vert_t> &poly,
+ distance_calc_t dist,
+ std::vector<tri_pair_t *> &edges,
+ size_t &n) {
+ double old_score = tp->score;
+ double new_score = tp->calc(project, poly, dist);
+#if defined(CARVE_DEBUG)
+ std::cerr << "tp:" << tp << " old_score: " << old_score << " new_score: " << new_score << std::endl;
+#endif
+ if (new_score > 0.0 && old_score <= 0.0) {
+ tp->idx = n;
+ edges[n++] = tp;
+ } else if (new_score <= 0.0 && old_score > 0.0) {
+ std::swap(edges[tp->idx], edges[--n]);
+ edges[tp->idx]->idx = tp->idx;
+ }
+ }
+
+ tri_pair_t *get(vert_edge_t &e) {
+ storage_t::iterator i;
+ i = storage.find(e);
+ if (i == storage.end()) return NULL;
+ return (*i).second;
+ }
+
+ template<typename project_t, typename vert_t, typename distance_calc_t>
+ void flip(const project_t &project,
+ const std::vector<vert_t> &poly,
+ distance_calc_t dist,
+ std::vector<tri_pair_t *> &edges,
+ size_t &n) {
+ vert_edge_t old_e, new_e;
+ vert_edge_t perim[4];
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "improvable edges: " << n << std::endl;
+#endif
+
+ tri_pair_t *tp = *std::max_element(edges.begin(), edges.begin() + n, max_score());
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "improving tri-pair: " << tp << " with score: " << tp->score << std::endl;
+#endif
+
+ tp->flip(old_e, new_e, perim);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "old_e: " << old_e.first << "," << old_e.second << " -> new_e: " << new_e.first << "," << new_e.second << std::endl;
+#endif
+
+ CARVE_ASSERT(storage.find(old_e) != storage.end());
+ storage.erase(old_e);
+ storage[new_e] = tp;
+
+ std::swap(edges[tp->idx], edges[--n]);
+ edges[tp->idx]->idx = tp->idx;
+
+ tri_pair_t *tp2;
+
+ tp2 = get(perim[0]);
+ if (tp2 != NULL) {
+ updateEdge(tp2, project, poly, dist, edges, n);
+ }
+
+ tp2 = get(perim[1]);
+ if (tp2 != NULL) {
+ CARVE_ASSERT(tp2->a == tp->b || tp2->b == tp->b);
+ if (tp2->a == tp->b) { tp2->a = tp->a; } else { tp2->b = tp->a; }
+ updateEdge(tp2, project, poly, dist, edges, n);
+ }
+
+ tp2 = get(perim[2]);
+ if (tp2 != NULL) {
+ updateEdge(tp2, project, poly, dist, edges, n);
+ }
+
+ tp2 = get(perim[3]);
+ if (tp2 != NULL) {
+ CARVE_ASSERT(tp2->a == tp->a || tp2->b == tp->a);
+ if (tp2->a == tp->a) { tp2->a = tp->b; } else { tp2->b = tp->b; }
+ updateEdge(tp2, project, poly, dist, edges, n);
+ }
+ }
+
+ template<typename project_t, typename vert_t, typename distance_calc_t>
+ size_t getInternalEdges(const project_t &project,
+ const std::vector<vert_t> &poly,
+ distance_calc_t dist,
+ std::vector<tri_pair_t *> &edges) {
+ size_t count = 0;
+
+ for (storage_t::iterator i = storage.begin(); i != storage.end();) {
+ tri_pair_t *tp = (*i).second;
+ if (tp->a && tp->b) {
+ tp->calc(project, poly, dist);
+ count++;
+#if defined(CARVE_DEBUG)
+ std::cerr << "internal edge: " << (*i).first.first << "," << (*i).first.second << " -> " << tp << " " << tp->score << std::endl;
+#endif
+ ++i;
+ } else {
+ delete (*i).second;
+ storage.erase(i++);
+ }
+ }
+
+ edges.resize(count);
+
+ size_t fwd = 0;
+ size_t rev = count;
+ for (storage_t::iterator i = storage.begin(); i != storage.end(); ++i) {
+ tri_pair_t *tp = (*i).second;
+ if (tp && tp->a && tp->b) {
+ if (tp->score > 0.0) {
+ edges[fwd++] = tp;
+ } else {
+ edges[--rev] = tp;
+ }
+ }
+ }
+
+ CARVE_ASSERT(fwd == rev);
+
+ return fwd;
+ }
+ };
+
+
+
+ template<typename project_t, typename vert_t>
+ static bool
+ testCandidateAttachment(const project_t &project,
+ std::vector<vert_t> &current_f_loop,
+ size_t curr,
+ carve::geom2d::P2 hole_min) {
+ const size_t SZ = current_f_loop.size();
+
+ size_t prev, next;
+
+ if (curr == 0) {
+ prev = SZ - 1; next = 1;
+ } else if (curr == SZ - 1) {
+ prev = curr - 1; next = 0;
+ } else {
+ prev = curr - 1; next = curr + 1;
+ }
+
+ if (!carve::geom2d::internalToAngle(project(current_f_loop[next]),
+ project(current_f_loop[curr]),
+ project(current_f_loop[prev]),
+ hole_min)) {
+ return false;
+ }
+
+ if (hole_min == project(current_f_loop[curr])) {
+ return true;
+ }
+
+ carve::geom2d::LineSegment2 test(hole_min, project(current_f_loop[curr]));
+
+ size_t v1 = current_f_loop.size() - 1;
+ size_t v2 = 0;
+ double v1_side = carve::geom2d::orient2d(test.v1, test.v2, project(current_f_loop[v1]));
+ double v2_side = 0;
+
+ while (v2 != current_f_loop.size()) {
+ v2_side = carve::geom2d::orient2d(test.v1, test.v2, project(current_f_loop[v2]));
+
+ if (v1_side != v2_side) {
+ // XXX: need to test vertices, not indices, because they may
+ // be duplicated.
+ if (project(current_f_loop[v1]) != project(current_f_loop[curr]) &&
+ project(current_f_loop[v2]) != project(current_f_loop[curr])) {
+ carve::geom2d::LineSegment2 test2(project(current_f_loop[v1]), project(current_f_loop[v2]));
+ if (carve::geom2d::lineSegmentIntersection_simple(test, test2)) {
+ // intersection; failed.
+ return false;
+ }
+ }
+ }
+
+ v1 = v2;
+ v1_side = v2_side;
+ ++v2;
+ }
+ return true;
+ }
+
+
+
+ }
+
+
+
+ template<typename project_t, typename vert_t>
+ static std::vector<vert_t>
+ incorporateHolesIntoPolygon(const project_t &project,
+ const std::vector<vert_t> &f_loop,
+ const std::vector<std::vector<vert_t> > &h_loops) {
+ typedef std::vector<vert_t> hole_t;
+ typedef typename std::vector<vert_t>::const_iterator vert_iter;
+ typedef typename std::vector<std::vector<vert_t> >::const_iterator hole_iter;
+
+ size_t N = f_loop.size();
+
+ // work out how much space to reserve for the patched in holes.
+ for (hole_iter i = h_loops.begin(); i != h_loops.end(); ++i) {
+ N += 2 + (*i).size();
+ }
+
+ // this is the vector that we will build the result in.
+ std::vector<vert_t> current_f_loop;
+ current_f_loop.reserve(N);
+
+ std::vector<size_t> f_loop_heap;
+ f_loop_heap.reserve(N);
+
+ for (unsigned i = 0; i < f_loop.size(); ++i) {
+ current_f_loop.push_back(f_loop[i]);
+ }
+
+ std::vector<std::pair<const std::vector<vert_t> *, vert_iter> > h_loop_min_vertex;
+
+ h_loop_min_vertex.reserve(h_loops.size());
+
+ // find the major axis for the holes - this is the axis that we
+ // will sort on for finding vertices on the polygon to join
+ // holes up to.
+ //
+ // it might also be nice to also look for whether it is better
+ // to sort ascending or descending.
+ //
+ // another trick that could be used is to modify the projection
+ // by 90 degree rotations or flipping about an axis. just as
+ // long as we keep the carve::geom3d::Vector pointers for the
+ // real data in sync, everything should be ok. then we wouldn't
+ // need to accomodate axes or sort order in the main loop.
+
+ // find the bounding box of all the holes.
+ bool first = true;
+ double min_x, min_y, max_x, max_y;
+ for (hole_iter i = h_loops.begin(); i != h_loops.end(); ++i) {
+ const hole_t &hole(*i);
+ for (vert_iter j = hole.begin(); j != hole.end(); ++j) {
+ carve::geom2d::P2 curr = project(*j);
+ if (first) {
+ min_x = max_x = curr.x;
+ min_y = max_y = curr.y;
+ first = false;
+ } else {
+ min_x = std::min(min_x, curr.x);
+ min_y = std::min(min_y, curr.y);
+ max_x = std::max(max_x, curr.x);
+ max_y = std::max(max_y, curr.y);
+ }
+ }
+ }
+
+ // choose the axis for which the bbox is largest.
+ int axis = (max_x - min_x) > (max_y - min_y) ? 0 : 1;
+
+ // for each hole, find the minimum vertex in the chosen axis.
+ for (hole_iter i = h_loops.begin(); i != h_loops.end(); ++i) {
+ const hole_t &hole = *i;
+ vert_iter best_i = std::min_element(hole.begin(), hole.end(), detail::order_h_loops<project_t, vert_t>(project, axis));
+ h_loop_min_vertex.push_back(std::make_pair(&hole, best_i));
+ }
+
+ // sort the holes by the minimum vertex.
+ std::sort(h_loop_min_vertex.begin(), h_loop_min_vertex.end(), detail::order_h_loops<project_t, vert_t>(project, axis));
+
+ // now, for each hole, find a vertex in the current polygon loop that it can be joined to.
+ for (unsigned i = 0; i < h_loop_min_vertex.size(); ++i) {
+ const size_t N_f_loop = current_f_loop.size();
+
+ // the index of the vertex in the hole to connect.
+ vert_iter h_loop_connect = h_loop_min_vertex[i].second;
+
+ carve::geom2d::P2 hole_min = project(*h_loop_connect);
+
+ f_loop_heap.clear();
+ // we order polygon loop vertices that may be able to be connected
+ // to the hole vertex by their distance to the hole vertex
+ detail::heap_ordering<project_t, vert_t> _heap_ordering(project, current_f_loop, *h_loop_connect, axis);
+
+ for (size_t j = 0; j < N_f_loop; ++j) {
+ // it is guaranteed that there exists a polygon vertex with
+ // coord < the min hole coord chosen, which can be joined to
+ // the min hole coord without crossing the polygon
+ // boundary. also, because we merge holes in ascending
+ // order, it is also true that this join can never cross
+ // another hole (and that doesn't need to be tested for).
+ if (project(current_f_loop[j]).v[axis] <= hole_min.v[axis]) {
+ f_loop_heap.push_back(j);
+ std::push_heap(f_loop_heap.begin(), f_loop_heap.end(), _heap_ordering);
+ }
+ }
+
+ // we are going to test each potential (according to the
+ // previous test) polygon vertex as a candidate join. we order
+ // by closeness to the hole vertex, so that the join we make
+ // is as small as possible. to test, we need to check the
+ // joining line segment does not cross any other line segment
+ // in the current polygon loop (excluding those that have the
+ // vertex that we are attempting to join with as an endpoint).
+ size_t attachment_point = current_f_loop.size();
+
+ while (f_loop_heap.size()) {
+ std::pop_heap(f_loop_heap.begin(), f_loop_heap.end(), _heap_ordering);
+ size_t curr = f_loop_heap.back();
+ f_loop_heap.pop_back();
+ // test the candidate join from current_f_loop[curr] to hole_min
+
+ if (!detail::testCandidateAttachment(project, current_f_loop, curr, hole_min)) {
+ continue;
+ }
+
+ attachment_point = curr;
+ break;
+ }
+
+ if (attachment_point == current_f_loop.size()) {
+ CARVE_FAIL("didn't manage to link up hole!");
+ }
+
+ detail::patchHoleIntoPolygon(current_f_loop, attachment_point, h_loop_min_vertex[i]);
+ }
+
+ return current_f_loop;
+ }
+
+
+
+ template<typename project_t, typename vert_t>
+ void triangulate(const project_t &project,
+ const std::vector<vert_t> &poly,
+ std::vector<tri_idx> &result) {
+ std::vector<detail::vertex_info *> vinfo;
+ const size_t N = poly.size();
+
+ result.clear();
+ if (N < 3) {
+ return;
+ }
+
+ result.reserve(poly.size() - 2);
+
+ if (N == 3) {
+ result.push_back(tri_idx(0, 1, 2));
+ return;
+ }
+
+ vinfo.resize(N);
+
+ vinfo[0] = new detail::vertex_info(project(poly[0]), 0);
+ for (size_t i = 1; i < N-1; ++i) {
+ vinfo[i] = new detail::vertex_info(project(poly[i]), i);
+ vinfo[i]->prev = vinfo[i-1];
+ vinfo[i-1]->next = vinfo[i];
+ }
+ vinfo[N-1] = new detail::vertex_info(project(poly[N-1]), N-1);
+ vinfo[N-1]->prev = vinfo[N-2];
+ vinfo[N-1]->next = vinfo[0];
+ vinfo[0]->prev = vinfo[N-1];
+ vinfo[N-2]->next = vinfo[N-1];
+
+ for (size_t i = 0; i < N; ++i) {
+ vinfo[i]->recompute();
+ }
+
+ detail::vertex_info *begin = vinfo[0];
+
+ removeDegeneracies(begin, result);
+ doTriangulate(begin, result);
+ }
+
+
+
+ template<typename project_t, typename vert_t, typename distance_calc_t>
+ void improve(const project_t &project,
+ const std::vector<vert_t> &poly,
+ distance_calc_t dist,
+ std::vector<tri_idx> &result) {
+ detail::tri_pairs_t tri_pairs;
+
+#if defined(CARVE_DEBUG)
+ bool warn = false;
+ for (size_t i = 0; i < result.size(); ++i) {
+ tri_idx &t = result[i];
+ if (carve::geom2d::signedArea(project(poly[t.a]), project(poly[t.b]), project(poly[t.c])) > 0) {
+ warn = true;
+ }
+ }
+ if (warn) {
+ std::cerr << "carve::triangulate::improve(): Some triangles are incorrectly oriented. Results may be incorrect." << std::endl;
+ }
+#endif
+
+ for (size_t i = 0; i < result.size(); ++i) {
+ tri_idx &t = result[i];
+ tri_pairs.insert(t.a, t.b, &t);
+ tri_pairs.insert(t.b, t.c, &t);
+ tri_pairs.insert(t.c, t.a, &t);
+ }
+
+ std::vector<detail::tri_pair_t *> edges;
+ size_t n = tri_pairs.getInternalEdges(project, poly, dist, edges);
+ for (size_t i = 0; i < n; ++i) {
+ edges[i]->idx = i;
+ }
+
+ // procedure:
+ // while a tri pair with a positive score exists:
+ // p = pair with highest positive score
+ // flip p, rewriting its two referenced triangles.
+ // negate p's score
+ // for each q in the up-to-four adjoining tri pairs:
+ // update q's tri ptr, if changed, and its score.
+
+#if defined(CARVE_DEBUG)
+ double initial_score = 0;
+ for (size_t i = 0; i < edges.size(); ++i) {
+ initial_score += edges[i]->edgeLen(project, poly, dist);
+ }
+ std::cerr << "initial score: " << initial_score << std::endl;
+#endif
+
+ while (n) {
+ tri_pairs.flip(project, poly, dist, edges, n);
+ }
+
+#if defined(CARVE_DEBUG)
+ double final_score = 0;
+ for (size_t i = 0; i < edges.size(); ++i) {
+ final_score += edges[i]->edgeLen(project, poly, dist);
+ }
+ std::cerr << "final score: " << final_score << std::endl;
+#endif
+
+#if defined(CARVE_DEBUG)
+ if (!warn) {
+ for (size_t i = 0; i < result.size(); ++i) {
+ tri_idx &t = result[i];
+ CARVE_ASSERT (carve::geom2d::signedArea(project(poly[t.a]), project(poly[t.b]), project(poly[t.c])) <= 0.0);
+ }
+ }
+#endif
+ }
+
+
+
+ template<typename project_t, typename vert_t>
+ void improve(const project_t &project,
+ const std::vector<vert_t> &poly,
+ std::vector<tri_idx> &result) {
+ improve(project, poly, carve::geom::distance_functor(), result);
+ }
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/util.hpp b/extern/carve/include/carve/util.hpp
new file mode 100644
index 00000000000..dc33f5b64ce
--- /dev/null
+++ b/extern/carve/include/carve/util.hpp
@@ -0,0 +1,31 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+namespace carve {
+ namespace util {
+ struct min_functor {
+ template<typename T>
+ const T &operator()(const T &a, const T &b) const { return std::min(a, b); }
+ };
+ struct max_functor {
+ template<typename T>
+ const T &operator()(const T &a, const T &b) const { return std::max(a, b); }
+ };
+ }
+}
diff --git a/extern/carve/include/carve/vcpp_config.h b/extern/carve/include/carve/vcpp_config.h
new file mode 100644
index 00000000000..5ebd4006159
--- /dev/null
+++ b/extern/carve/include/carve/vcpp_config.h
@@ -0,0 +1,17 @@
+/* include/carve/config.h. Generated from config.h.in by configure. */
+#pragma once
+
+#include <math.h>
+
+/* Define if using boost collections. Preferred, because the visual C++ unordered collections are slow and memory hungry. */
+#define HAVE_BOOST_UNORDERED_COLLECTIONS
+
+#if defined(_MSC_VER)
+# pragma warning(disable:4201)
+#endif
+
+#include <math.h>
+
+static inline double round(double value) {
+ return (value >= 0) ? floor(value + 0.5) : ceil(value - 0.5);
+}
diff --git a/extern/carve/include/carve/vector.hpp b/extern/carve/include/carve/vector.hpp
new file mode 100644
index 00000000000..6753ddb85d4
--- /dev/null
+++ b/extern/carve/include/carve/vector.hpp
@@ -0,0 +1,163 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/math_constants.hpp>
+#include <carve/geom.hpp>
+#include <carve/geom3d.hpp>
+
+#include <sstream>
+#include <algorithm>
+
+#include <math.h>
+
+namespace carve {
+ namespace geom3d {
+
+ struct hash_vector_ptr {
+ size_t operator()(const Vector * const &v) const {
+ return (size_t)v;
+ }
+ size_t operator()(const std::pair<const Vector *, const Vector *> &v) const {
+ size_t r = (size_t)v.first;
+ size_t s = (size_t)v.second;
+ return r ^ ((s >> 16) | (s << 16));
+ }
+ };
+
+
+
+ struct vec_adapt_ident {
+ const Vector &operator()(const Vector &v) const { return v; }
+ Vector &operator()(Vector &v) const { return v; }
+ };
+
+
+
+ struct vec_adapt_ptr {
+ const Vector &operator()(const Vector * const &v) const { return *v; }
+ Vector &operator()(Vector *&v) const { return *v; }
+ };
+
+
+
+ struct vec_adapt_pair_first {
+ template<typename pair_t> const Vector &operator()(const pair_t &v) const { return v.first; }
+ template<typename pair_t> Vector &operator()(pair_t &v) const { return v.first; }
+ };
+
+
+
+ struct vec_adapt_pair_second {
+ template<typename pair_t> const Vector &operator()(const pair_t &v) const { return v.second; }
+ template<typename pair_t> Vector &operator()(pair_t &v) const { return v.second; }
+ };
+
+
+
+ template<typename adapt_t>
+ struct vec_cmp_lt_x {
+ adapt_t adapt;
+ vec_cmp_lt_x(adapt_t _adapt = adapt_t()) : adapt(_adapt) {}
+ template<typename input_t> bool operator()(const input_t &a, const input_t &b) const { return adapt(a).x < adapt(b).x; }
+ };
+ template<typename adapt_t> vec_cmp_lt_x<adapt_t> vec_lt_x(adapt_t &adapt) { return vec_cmp_lt_x<adapt_t>(adapt); }
+
+
+
+ template<typename adapt_t>
+ struct vec_cmp_lt_y {
+ adapt_t adapt;
+ vec_cmp_lt_y(adapt_t _adapt = adapt_t()) : adapt(_adapt) {}
+ template<typename input_t> bool operator()(const input_t &a, const input_t &b) const { return adapt(a).y < adapt(b).y; }
+ };
+ template<typename adapt_t> vec_cmp_lt_y<adapt_t> vec_lt_y(adapt_t &adapt) { return vec_cmp_lt_y<adapt_t>(adapt); }
+
+
+
+ template<typename adapt_t>
+ struct vec_cmp_lt_z {
+ adapt_t adapt;
+ vec_cmp_lt_z(adapt_t _adapt = adapt_t()) : adapt(_adapt) {}
+ template<typename input_t> bool operator()(const input_t &a, const input_t &b) const { return adapt(a).z < adapt(b).z; }
+ };
+ template<typename adapt_t> vec_cmp_lt_z<adapt_t> vec_lt_z(adapt_t &adapt) { return vec_cmp_lt_z<adapt_t>(adapt); }
+
+
+
+ template<typename adapt_t>
+ struct vec_cmp_gt_x {
+ adapt_t adapt;
+ vec_cmp_gt_x(adapt_t _adapt = adapt_t()) : adapt(_adapt) {}
+ template<typename input_t> bool operator()(const input_t &a, const input_t &b) const { return adapt(a).x > adapt(b).x; }
+ };
+ template<typename adapt_t> vec_cmp_gt_x<adapt_t> vec_gt_x(adapt_t &adapt) { return vec_cmp_gt_x<adapt_t>(adapt); }
+
+
+
+ template<typename adapt_t>
+ struct vec_cmp_gt_y {
+ adapt_t adapt;
+ vec_cmp_gt_y(adapt_t _adapt = adapt_t()) : adapt(_adapt) {}
+ template<typename input_t> bool operator()(const input_t &a, const input_t &b) const { return adapt(a).y > adapt(b).y; }
+ };
+ template<typename adapt_t> vec_cmp_gt_y<adapt_t> vec_gt_y(adapt_t &adapt) { return vec_cmp_gt_y<adapt_t>(adapt); }
+
+
+
+ template<typename adapt_t>
+ struct vec_cmp_gt_z {
+ adapt_t adapt;
+ vec_cmp_gt_z(adapt_t _adapt = adapt_t()) : adapt(_adapt) {}
+ template<typename input_t> bool operator()(const input_t &a, const input_t &b) const { return adapt(a).z > adapt(b).z; }
+ };
+ template<typename adapt_t> vec_cmp_gt_z<adapt_t> vec_gt_z(adapt_t &adapt) { return vec_cmp_gt_z<adapt_t>(adapt); }
+
+
+
+ template<typename iter_t, typename adapt_t>
+ void sortInDirectionOfRay(const Vector &ray_dir, iter_t begin, iter_t end, adapt_t adapt) {
+ switch (carve::geom::largestAxis(ray_dir)) {
+ case 0:
+ if (ray_dir.x > 0) {
+ std::sort(begin, end, vec_lt_x(adapt));
+ } else {
+ std::sort(begin, end, vec_gt_x(adapt));
+ }
+ break;
+ case 1:
+ if (ray_dir.y > 0) {
+ std::sort(begin, end, vec_lt_y(adapt));
+ } else {
+ std::sort(begin, end, vec_gt_y(adapt));
+ }
+ break;
+ case 2:
+ if (ray_dir.z > 0) {
+ std::sort(begin, end, vec_lt_z(adapt));
+ } else {
+ std::sort(begin, end, vec_gt_z(adapt));
+ }
+ break;
+ }
+ }
+
+ }
+}
diff --git a/extern/carve/include/carve/vertex_decl.hpp b/extern/carve/include/carve/vertex_decl.hpp
new file mode 100644
index 00000000000..62c76473020
--- /dev/null
+++ b/extern/carve/include/carve/vertex_decl.hpp
@@ -0,0 +1,111 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/geom2d.hpp>
+#include <carve/vector.hpp>
+#include <carve/matrix.hpp>
+#include <carve/geom3d.hpp>
+#include <carve/aabb.hpp>
+#include <carve/tag.hpp>
+
+#include <vector>
+#include <list>
+#include <map>
+
+namespace carve {
+ namespace poly {
+
+
+
+ struct Object;
+
+
+
+ template<unsigned ndim>
+ class Vertex : public tagable {
+ public:
+ typedef carve::geom::vector<ndim> vector_t;
+ typedef Object obj_t;
+
+ vector_t v;
+ obj_t *owner;
+
+ Vertex() : tagable(), v() {
+ }
+
+ ~Vertex() {
+ }
+
+ Vertex(const vector_t &_v) : tagable(), v(_v) {
+ }
+ };
+
+
+
+ struct hash_vertex_ptr {
+ template<unsigned ndim>
+ size_t operator()(const Vertex<ndim> * const &v) const {
+ return (size_t)v;
+ }
+
+ template<unsigned ndim>
+ size_t operator()(const std::pair<const Vertex<ndim> *, const Vertex<ndim> *> &v) const {
+ size_t r = (size_t)v.first;
+ size_t s = (size_t)v.second;
+ return r ^ ((s >> 16) | (s << 16));
+ }
+
+ };
+
+
+
+ template<unsigned ndim>
+ double distance(const Vertex<ndim> *v1, const Vertex<ndim> *v2) {
+ return distance(v1->v, v2->v);
+ }
+
+ template<unsigned ndim>
+ double distance(const Vertex<ndim> &v1, const Vertex<ndim> &v2) {
+ return distance(v1.v, v2.v);
+ }
+
+ struct vec_adapt_vertex_ref {
+ template<unsigned ndim>
+ const typename Vertex<ndim>::vector_t &operator()(const Vertex<ndim> &v) const { return v.v; }
+
+ template<unsigned ndim>
+ typename Vertex<ndim>::vector_t &operator()(Vertex<ndim> &v) const { return v.v; }
+ };
+
+
+
+ struct vec_adapt_vertex_ptr {
+ template<unsigned ndim>
+ const typename Vertex<ndim>::vector_t &operator()(const Vertex<ndim> *v) const { return v->v; }
+
+ template<unsigned ndim>
+ typename Vertex<ndim>::vector_t &operator()(Vertex<ndim> *v) const { return v->v; }
+ };
+
+
+
+ }
+}
diff --git a/extern/carve/include/carve/vertex_impl.hpp b/extern/carve/include/carve/vertex_impl.hpp
new file mode 100644
index 00000000000..7e1803ae89c
--- /dev/null
+++ b/extern/carve/include/carve/vertex_impl.hpp
@@ -0,0 +1,24 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+namespace carve {
+ namespace poly {
+
+ }
+}
diff --git a/extern/carve/include/carve/win32.h b/extern/carve/include/carve/win32.h
new file mode 100755
index 00000000000..5f8ce3b3bf6
--- /dev/null
+++ b/extern/carve/include/carve/win32.h
@@ -0,0 +1,55 @@
+// Copyright 2006 Tobias Sargeant (toby@permuted.net)
+// All rights reserved.
+#pragma once
+
+#pragma warning (disable : 4996)
+#pragma warning (disable : 4786)
+
+#include <string.h>
+#include <stdlib.h>
+
+#if !defined(__MINGW32__)
+inline int strcasecmp(const char *a, const char *b) {
+ return _stricmp(a,b);
+}
+#endif
+
+inline void srandom(unsigned long input) {
+ srand(input);
+}
+
+inline long random() {
+ return rand();
+}
+
+#if defined(_MSC_VER)
+# include <carve/cbrt.h>
+
+#if _MSC_VER < 1300
+// intptr_t is an integer type that is big enough to hold a pointer
+// It is not defined in VC6 so include a definition here for the older compiler
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+#endif
+
+# if _MSC_VER < 1600
+// stdint.h is not available before VS2010
+#if defined(_WIN32) && !defined(__MINGW32__)
+/* The __intXX are built-in types of the visual complier! So we don't
+ need to include anything else here.
+ This typedefs should be in sync with types from MEM_sys_types.h */
+
+typedef signed __int8 int8_t;
+typedef signed __int16 int16_t;
+typedef signed __int32 int32_t;
+
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+#endif
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+# else
+# include <stdint.h>
+# endif
+#endif
diff --git a/extern/carve/lib/aabb.cpp b/extern/carve/lib/aabb.cpp
new file mode 100644
index 00000000000..188929a8cfa
--- /dev/null
+++ b/extern/carve/lib/aabb.cpp
@@ -0,0 +1,29 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/aabb.hpp>
+#include <carve/geom3d.hpp>
+
+namespace carve {
+ namespace geom3d {
+ }
+}
+
diff --git a/extern/carve/lib/carve.cpp b/extern/carve/lib/carve.cpp
new file mode 100644
index 00000000000..9af2d0408fb
--- /dev/null
+++ b/extern/carve/lib/carve.cpp
@@ -0,0 +1,29 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/carve.hpp>
+
+#define DEF_EPSILON 1.4901161193847656e-08
+
+namespace carve {
+ double EPSILON = DEF_EPSILON;
+ double EPSILON2 = DEF_EPSILON * DEF_EPSILON;
+}
diff --git a/extern/carve/lib/convex_hull.cpp b/extern/carve/lib/convex_hull.cpp
new file mode 100644
index 00000000000..616d8cbe561
--- /dev/null
+++ b/extern/carve/lib/convex_hull.cpp
@@ -0,0 +1,100 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/convex_hull.hpp>
+
+#include <algorithm>
+
+namespace {
+
+ bool grahamScan(const std::vector<carve::geom2d::P2> &points,
+ int vpp, int vp,
+ const std::vector<int> &ordered,
+ int start,
+ std::vector<int> &result, int _i = 0) {
+ carve::geom2d::P2 v1 = points[vp] - points[vpp];
+ if (start == (int)ordered.size()) return true;
+
+ for (int i = start; i < (int)ordered.size(); ++i) {
+ int v = ordered[i];
+ carve::geom2d::P2 v2 = points[v] - points[vp];
+
+ double cp = v1.x * v2.y - v2.x * v1.y;
+ if (cp < 0) return false;
+
+ int j = i + 1;
+ while (j < (int)ordered.size() && points[ordered[j]] == points[v]) j++;
+
+ result.push_back(v);
+ if (grahamScan(points, vp, v, ordered, j, result, _i + 1)) return true;
+ result.pop_back();
+ }
+
+ return false;
+ }
+
+}
+
+namespace carve {
+ namespace geom {
+
+ std::vector<int> convexHull(const std::vector<carve::geom2d::P2> &points) {
+ double max_x = points[0].x;
+ unsigned max_v = 0;
+
+ for (unsigned i = 1; i < points.size(); ++i) {
+ if (points[i].x > max_x) {
+ max_x = points[i].x;
+ max_v = i;
+ }
+ }
+
+ std::vector<std::pair<double, double> > angle_dist;
+ std::vector<int> ordered;
+ angle_dist.reserve(points.size());
+ ordered.reserve(points.size() - 1);
+ for (unsigned i = 0; i < points.size(); ++i) {
+ if (i == max_v) continue;
+ angle_dist[i] = std::make_pair(carve::math::ANG(carve::geom2d::atan2(points[i] - points[max_v])), distance2(points[i], points[max_v]));
+ ordered.push_back(i);
+ }
+
+ std::sort(ordered.begin(),
+ ordered.end(),
+ make_index_sort(angle_dist.begin()));
+
+ std::vector<int> result;
+ result.push_back(max_v);
+ result.push_back(ordered[0]);
+
+ if (!grahamScan(points, max_v, ordered[0], ordered, 1, result)) {
+ result.clear();
+ throw carve::exception("convex hull failed!");
+ }
+
+ return result;
+ }
+
+ }
+}
+
+
diff --git a/extern/carve/lib/csg.cpp b/extern/carve/lib/csg.cpp
new file mode 100644
index 00000000000..3d3dfb8bf75
--- /dev/null
+++ b/extern/carve/lib/csg.cpp
@@ -0,0 +1,93 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include "csg_detail.hpp"
+
+
+const char *carve::csg::ENUM(carve::csg::FaceClass f) {
+ if (f == FACE_ON_ORIENT_OUT) return "FACE_ON_ORIENT_OUT";
+ if (f == FACE_OUT) return "FACE_OUT";
+ if (f == FACE_IN) return "FACE_IN";
+ if (f == FACE_ON_ORIENT_IN) return "FACE_ON_ORIENT_IN";
+ return "???";
+}
+
+
+
+const char *carve::csg::ENUM(carve::PointClass p) {
+ if (p == POINT_UNK) return "POINT_UNK";
+ if (p == POINT_OUT) return "POINT_OUT";
+ if (p == POINT_ON) return "POINT_ON";
+ if (p == POINT_IN) return "POINT_IN";
+ if (p == POINT_VERTEX) return "POINT_VERTEX";
+ if (p == POINT_EDGE) return "POINT_EDGE";
+ return "???";
+}
+
+
+
+void carve::csg::detail::LoopEdges::addFaceLoop(FaceLoop *fl) {
+ carve::mesh::MeshSet<3>::vertex_t *v1, *v2;
+ v1 = fl->vertices[fl->vertices.size() - 1];
+ for (unsigned j = 0; j < fl->vertices.size(); ++j) {
+ v2 = fl->vertices[j];
+ (*this)[std::make_pair(v1, v2)].push_back(fl);
+ v1 = v2;
+ }
+}
+
+
+
+void carve::csg::detail::LoopEdges::sortFaceLoopLists() {
+ for (super::iterator i = begin(), e = end(); i != e; ++i) {
+ (*i).second.sort();
+ }
+}
+
+
+
+void carve::csg::detail::LoopEdges::removeFaceLoop(FaceLoop *fl) {
+ carve::mesh::MeshSet<3>::vertex_t *v1, *v2;
+ v1 = fl->vertices[fl->vertices.size() - 1];
+ for (unsigned j = 0; j < fl->vertices.size(); ++j) {
+ v2 = fl->vertices[j];
+ iterator l(find(std::make_pair(v1, v2)));
+ if (l != end()) {
+ (*l).second.remove(fl);
+ if (!(*l).second.size()) {
+ erase(l);
+ }
+ }
+ v1 = v2;
+ }
+}
+
+
+
+carve::csg::FaceClass carve::csg::FaceLoopGroup::classificationAgainst(const carve::mesh::MeshSet<3>::mesh_t *mesh) const {
+ for (std::list<ClassificationInfo>::const_iterator i = classification.begin(); i != classification.end(); ++i) {
+ if ((*i).intersected_mesh == mesh) {
+ return (*i).classification;
+ }
+ }
+ return FACE_UNCLASSIFIED;
+}
diff --git a/extern/carve/lib/csg_collector.cpp b/extern/carve/lib/csg_collector.cpp
new file mode 100644
index 00000000000..6e86b128b51
--- /dev/null
+++ b/extern/carve/lib/csg_collector.cpp
@@ -0,0 +1,371 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <iostream>
+#include "intersect_debug.hpp"
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+void writePLY(const std::string &out_file, const carve::mesh::MeshSet<3> *poly, bool ascii);
+#endif
+
+
+namespace carve {
+ namespace csg {
+ namespace {
+
+ class BaseCollector : public CSG::Collector {
+ BaseCollector();
+ BaseCollector(const BaseCollector &);
+ BaseCollector &operator=(const BaseCollector &);
+
+ protected:
+ struct face_data_t {
+ carve::mesh::MeshSet<3>::face_t *face;
+ const carve::mesh::MeshSet<3>::face_t *orig_face;
+ bool flipped;
+ face_data_t(carve::mesh::MeshSet<3>::face_t *_face,
+ const carve::mesh::MeshSet<3>::face_t *_orig_face,
+ bool _flipped) : face(_face), orig_face(_orig_face), flipped(_flipped) {
+ };
+ };
+
+ std::list<face_data_t> faces;
+
+ const carve::mesh::MeshSet<3> *src_a;
+ const carve::mesh::MeshSet<3> *src_b;
+
+ BaseCollector(const carve::mesh::MeshSet<3> *_src_a,
+ const carve::mesh::MeshSet<3> *_src_b) : CSG::Collector(), src_a(_src_a), src_b(_src_b) {
+ }
+
+ virtual ~BaseCollector() {
+ }
+
+ void FWD(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector /* normal */,
+ bool /* poly_a */,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ std::vector<carve::mesh::MeshSet<3>::face_t *> new_faces;
+ new_faces.reserve(1);
+ new_faces.push_back(orig_face->create(vertices.begin(), vertices.end(), false));
+ hooks.processOutputFace(new_faces, orig_face, false);
+ for (size_t i = 0; i < new_faces.size(); ++i) {
+ faces.push_back(face_data_t(new_faces[i], orig_face, false));
+ }
+
+#if defined(CARVE_DEBUG) && defined(DEBUG_PRINT_RESULT_FACES)
+ std::cerr << "+" << ENUM(face_class) << " ";
+ for (unsigned i = 0; i < vertices.size(); ++i) std::cerr << " " << vertices[i] << ":" << *vertices[i];
+ std::cerr << std::endl;
+#endif
+ }
+
+ void REV(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector /* normal */,
+ bool /* poly_a */,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ // normal = -normal;
+ std::vector<carve::mesh::MeshSet<3>::face_t *> new_faces;
+ new_faces.reserve(1);
+ new_faces.push_back(orig_face->create(vertices.begin(), vertices.end(), true));
+ hooks.processOutputFace(new_faces, orig_face, true);
+ for (size_t i = 0; i < new_faces.size(); ++i) {
+ faces.push_back(face_data_t(new_faces[i], orig_face, true));
+ }
+
+#if defined(CARVE_DEBUG) && defined(DEBUG_PRINT_RESULT_FACES)
+ std::cerr << "-" << ENUM(face_class) << " ";
+ for (unsigned i = 0; i < vertices.size(); ++i) std::cerr << " " << vertices[i] << ":" << *vertices[i];
+ std::cerr << std::endl;
+#endif
+ }
+
+ virtual void collect(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector normal,
+ bool poly_a,
+ FaceClass face_class,
+ CSG::Hooks &hooks) =0;
+
+ virtual void collect(FaceLoopGroup *grp, CSG::Hooks &hooks) {
+ std::list<ClassificationInfo> &cinfo = (grp->classification);
+
+ if (cinfo.size() == 0) {
+ std::cerr << "WARNING! group " << grp << " has no classification info!" << std::endl;
+ return;
+ }
+
+ FaceClass fc = FACE_UNCLASSIFIED;
+
+ unsigned fc_closed_bits = 0;
+ unsigned fc_open_bits = 0;
+ unsigned fc_bits = 0;
+
+ for (std::list<ClassificationInfo>::const_iterator i = grp->classification.begin(), e = grp->classification.end(); i != e; ++i) {
+
+ if ((*i).intersected_mesh == NULL) {
+ // classifier only returns global info
+ fc_closed_bits = class_to_class_bit((*i).classification);
+ break;
+ }
+
+ if ((*i).classification == FACE_UNCLASSIFIED) continue;
+ if ((*i).intersectedMeshIsClosed()) {
+ fc_closed_bits |= class_to_class_bit((*i).classification);
+ } else {
+ fc_open_bits |= class_to_class_bit((*i).classification);
+ }
+ }
+
+ if (fc_closed_bits) {
+ fc_bits = fc_closed_bits;
+ } else {
+ fc_bits = fc_open_bits;
+ }
+
+ fc = class_bit_to_class(fc_bits);
+
+ // handle the complex cases where a group is classified differently with respect to two or more closed manifolds.
+ if (fc == FACE_UNCLASSIFIED) {
+ unsigned inout_bits = fc_bits & FACE_NOT_ON_BIT;
+ unsigned on_bits = fc_bits & FACE_ON_BIT;
+
+ // both in and out. indicates an invalid manifold embedding.
+ if (inout_bits == (FACE_IN_BIT | FACE_OUT_BIT)) goto out;
+
+ // on, both orientations. could be caused by two manifolds touching at a face.
+ if (on_bits == (FACE_ON_ORIENT_IN_BIT | FACE_ON_ORIENT_OUT_BIT)) goto out;
+
+ // in or out, but also on (with orientation). the on classification takes precedence.
+ fc = class_bit_to_class(on_bits);
+ }
+
+ out:
+
+ if (fc == FACE_UNCLASSIFIED) {
+ std::cerr << "group " << grp << " is unclassified!" << std::endl;
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ static int uc_count = 0;
+
+ std::vector<carve::mesh::MeshSet<3>::face_t *> faces;
+
+ for (FaceLoop *f = grp->face_loops.head; f; f = f->next) {
+ carve::mesh::MeshSet<3>::face_t *temp = f->orig_face->create(f->vertices.begin(), f->vertices.end(), false);
+ faces.push_back(temp);
+ }
+
+ carve::mesh::MeshSet<3> *p = new carve::mesh::MeshSet<3>(faces);
+
+ std::ostringstream filename;
+ filename << "classifier_fail_" << ++uc_count << ".ply";
+ std::string out(filename.str().c_str());
+ ::writePLY(out, p, false);
+
+ delete p;
+#endif
+
+ return;
+ }
+
+ bool is_poly_a = grp->src == src_a;
+
+ for (FaceLoop *f = grp->face_loops.head; f; f = f->next) {
+ collect(f->orig_face, f->vertices, f->orig_face->plane.N, is_poly_a, fc, hooks);
+ }
+ }
+
+ virtual carve::mesh::MeshSet<3> *done(CSG::Hooks &hooks) {
+ std::vector<carve::mesh::MeshSet<3>::face_t *> f;
+ f.reserve(faces.size());
+ for (std::list<face_data_t>::iterator i = faces.begin(); i != faces.end(); ++i) {
+ f.push_back((*i).face);
+ }
+
+ carve::mesh::MeshSet<3> *p = new carve::mesh::MeshSet<3>(f);
+
+ if (hooks.hasHook(carve::csg::CSG::Hooks::RESULT_FACE_HOOK)) {
+ for (std::list<face_data_t>::iterator i = faces.begin(); i != faces.end(); ++i) {
+ hooks.resultFace((*i).face, (*i).orig_face, (*i).flipped);
+ }
+ }
+
+ return p;
+ }
+ };
+
+
+
+ class AllCollector : public BaseCollector {
+ public:
+ AllCollector(const carve::mesh::MeshSet<3> *_src_a,
+ const carve::mesh::MeshSet<3> *_src_b) : BaseCollector(_src_a, _src_b) {
+ }
+ virtual ~AllCollector() {
+ }
+ virtual void collect(FaceLoopGroup *grp, CSG::Hooks &hooks) {
+ for (FaceLoop *f = grp->face_loops.head; f; f = f->next) {
+ FWD(f->orig_face, f->vertices, f->orig_face->plane.N, f->orig_face->mesh->meshset == src_a, FACE_OUT, hooks);
+ }
+ }
+ virtual void collect(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector normal,
+ bool poly_a,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ FWD(orig_face, vertices, normal, poly_a, face_class, hooks);
+ }
+ };
+
+
+
+ class UnionCollector : public BaseCollector {
+ public:
+ UnionCollector(const carve::mesh::MeshSet<3> *_src_a,
+ const carve::mesh::MeshSet<3> *_src_b) : BaseCollector(_src_a, _src_b) {
+ }
+ virtual ~UnionCollector() {
+ }
+ virtual void collect(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector normal,
+ bool poly_a,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ if (face_class == FACE_OUT || (poly_a && face_class == FACE_ON_ORIENT_OUT)) {
+ FWD(orig_face, vertices, normal, poly_a, face_class, hooks);
+ }
+ }
+ };
+
+
+
+ class IntersectionCollector : public BaseCollector {
+ public:
+ IntersectionCollector(const carve::mesh::MeshSet<3> *_src_a,
+ const carve::mesh::MeshSet<3> *_src_b) : BaseCollector(_src_a, _src_b) {
+ }
+ virtual ~IntersectionCollector() {
+ }
+ virtual void collect(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector normal,
+ bool poly_a,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ if (face_class == FACE_IN || (poly_a && face_class == FACE_ON_ORIENT_OUT)) {
+ FWD(orig_face, vertices, normal, poly_a, face_class, hooks);
+ }
+ }
+ };
+
+
+
+ class SymmetricDifferenceCollector : public BaseCollector {
+ public:
+ SymmetricDifferenceCollector(const carve::mesh::MeshSet<3> *_src_a,
+ const carve::mesh::MeshSet<3> *_src_b) : BaseCollector(_src_a, _src_b) {
+ }
+ virtual ~SymmetricDifferenceCollector() {
+ }
+ virtual void collect(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector normal,
+ bool poly_a,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ if (face_class == FACE_OUT) {
+ FWD(orig_face, vertices, normal, poly_a, face_class, hooks);
+ } else if (face_class == FACE_IN) {
+ REV(orig_face, vertices, normal, poly_a, face_class, hooks);
+ }
+ }
+ };
+
+
+
+ class AMinusBCollector : public BaseCollector {
+ public:
+ AMinusBCollector(const carve::mesh::MeshSet<3> *_src_a,
+ const carve::mesh::MeshSet<3> *_src_b) : BaseCollector(_src_a, _src_b) {
+ }
+ virtual ~AMinusBCollector() {
+ }
+ virtual void collect(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector normal,
+ bool poly_a,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ if ((face_class == FACE_OUT || face_class == FACE_ON_ORIENT_IN) && poly_a) {
+ FWD(orig_face, vertices, normal, poly_a, face_class, hooks);
+ } else if (face_class == FACE_IN && !poly_a) {
+ REV(orig_face, vertices, normal, poly_a, face_class, hooks);
+ }
+ }
+ };
+
+
+
+ class BMinusACollector : public BaseCollector {
+ public:
+ BMinusACollector(const carve::mesh::MeshSet<3> *_src_a,
+ const carve::mesh::MeshSet<3> *_src_b) : BaseCollector(_src_a, _src_b) {
+ }
+ virtual ~BMinusACollector() {
+ }
+ virtual void collect(const carve::mesh::MeshSet<3>::face_t *orig_face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &vertices,
+ carve::geom3d::Vector normal,
+ bool poly_a,
+ FaceClass face_class,
+ CSG::Hooks &hooks) {
+ if ((face_class == FACE_OUT || face_class == FACE_ON_ORIENT_IN) && !poly_a) {
+ FWD(orig_face, vertices, normal, poly_a, face_class, hooks);
+ } else if (face_class == FACE_IN && poly_a) {
+ REV(orig_face, vertices, normal, poly_a, face_class, hooks);
+ }
+ }
+ };
+
+ }
+
+ CSG::Collector *makeCollector(CSG::OP op,
+ const carve::mesh::MeshSet<3> *poly_a,
+ const carve::mesh::MeshSet<3> *poly_b) {
+ switch (op) {
+ case CSG::UNION: return new UnionCollector(poly_a, poly_b);
+ case CSG::INTERSECTION: return new IntersectionCollector(poly_a, poly_b);
+ case CSG::A_MINUS_B: return new AMinusBCollector(poly_a, poly_b);
+ case CSG::B_MINUS_A: return new BMinusACollector(poly_a, poly_b);
+ case CSG::SYMMETRIC_DIFFERENCE: return new SymmetricDifferenceCollector(poly_a, poly_b);
+ case CSG::ALL: return new AllCollector(poly_a, poly_b);
+ }
+ return NULL;
+ }
+ }
+}
diff --git a/extern/carve/lib/csg_collector.hpp b/extern/carve/lib/csg_collector.hpp
new file mode 100644
index 00000000000..c68d3f3aa42
--- /dev/null
+++ b/extern/carve/lib/csg_collector.hpp
@@ -0,0 +1,24 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+namespace carve {
+ namespace csg {
+ CSG::Collector *makeCollector(CSG::OP op,
+ const carve::mesh::MeshSet<3> *poly_a,
+ const carve::mesh::MeshSet<3> *poly_b);
+ }
+}
diff --git a/extern/carve/lib/csg_data.hpp b/extern/carve/lib/csg_data.hpp
new file mode 100644
index 00000000000..085d05ce8d5
--- /dev/null
+++ b/extern/carve/lib/csg_data.hpp
@@ -0,0 +1,52 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/csg.hpp>
+
+#include "csg_detail.hpp"
+
+struct carve::csg::detail::Data {
+// * @param[out] vmap A mapping from vertex pointer to intersection point.
+// * @param[out] emap A mapping from edge pointer to intersection points.
+// * @param[out] fmap A mapping from face pointer to intersection points.
+// * @param[out] fmap_rev A mapping from intersection points to face pointers.
+ // map from intersected vertex to intersection point.
+ VVMap vmap;
+
+ // map from intersected edge to intersection points.
+ EVSMap emap;
+
+ // map from intersected face to intersection points.
+ FVSMap fmap;
+
+ // map from intersection point to intersected faces.
+ VFSMap fmap_rev;
+
+ // created by divideEdges().
+ // holds, for each edge, a
+ EVVMap divided_edges;
+
+ // created by faceSplitEdges.
+ FV2SMap face_split_edges;
+
+ // mapping from vertex to edge for potentially intersected
+ // faces. Saves building the vertex to edge map for all faces of
+ // both meshes.
+ VEVecMap vert_to_edges;
+};
diff --git a/extern/carve/lib/csg_detail.hpp b/extern/carve/lib/csg_detail.hpp
new file mode 100644
index 00000000000..4b8fca3d2d2
--- /dev/null
+++ b/extern/carve/lib/csg_detail.hpp
@@ -0,0 +1,71 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include <carve/carve.hpp>
+
+#include <carve/polyhedron_base.hpp>
+
+namespace carve {
+ namespace csg {
+ namespace detail {
+
+ typedef std::unordered_set<carve::mesh::MeshSet<3>::vertex_t *> VSet;
+ typedef std::unordered_set<carve::mesh::MeshSet<3>::face_t *> FSet;
+
+ typedef std::set<carve::mesh::MeshSet<3>::vertex_t *> VSetSmall;
+ typedef std::set<csg::V2> V2SetSmall;
+ typedef std::set<carve::mesh::MeshSet<3>::face_t *> FSetSmall;
+
+ typedef std::unordered_map<carve::mesh::MeshSet<3>::vertex_t *, VSetSmall> VVSMap;
+ typedef std::unordered_map<carve::mesh::MeshSet<3>::edge_t *, VSetSmall> EVSMap;
+ typedef std::unordered_map<carve::mesh::MeshSet<3>::face_t *, VSetSmall> FVSMap;
+
+ typedef std::unordered_map<carve::mesh::MeshSet<3>::vertex_t *, FSetSmall> VFSMap;
+ typedef std::unordered_map<carve::mesh::MeshSet<3>::face_t *, V2SetSmall> FV2SMap;
+
+ typedef std::unordered_map<
+ carve::mesh::MeshSet<3>::edge_t *,
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> > EVVMap;
+
+ typedef std::unordered_map<carve::mesh::MeshSet<3>::vertex_t *,
+ std::vector<carve::mesh::MeshSet<3>::edge_t *> > VEVecMap;
+
+
+ class LoopEdges : public std::unordered_map<V2, std::list<FaceLoop *> > {
+ typedef std::unordered_map<V2, std::list<FaceLoop *> > super;
+
+ public:
+ void addFaceLoop(FaceLoop *fl);
+ void sortFaceLoopLists();
+ void removeFaceLoop(FaceLoop *fl);
+ };
+
+ }
+ }
+}
+
+
+
+static inline std::ostream &operator<<(std::ostream &o, const carve::csg::detail::FSet &s) {
+ const char *sep="";
+ for (carve::csg::detail::FSet::const_iterator i = s.begin(); i != s.end(); ++i) {
+ o << sep << *i; sep=",";
+ }
+ return o;
+}
diff --git a/extern/carve/lib/edge.cpp b/extern/carve/lib/edge.cpp
new file mode 100644
index 00000000000..4414e6496f3
--- /dev/null
+++ b/extern/carve/lib/edge.cpp
@@ -0,0 +1,23 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/poly.hpp>
+
diff --git a/extern/carve/lib/face.cpp b/extern/carve/lib/face.cpp
new file mode 100644
index 00000000000..c0718923cbb
--- /dev/null
+++ b/extern/carve/lib/face.cpp
@@ -0,0 +1,278 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/poly.hpp>
+
+double CALC_X(const carve::geom::plane<3> &p, double y, double z) { return -(p.d + p.N.y * y + p.N.z * z) / p.N.x; }
+double CALC_Y(const carve::geom::plane<3> &p, double x, double z) { return -(p.d + p.N.x * x + p.N.z * z) / p.N.y; }
+double CALC_Z(const carve::geom::plane<3> &p, double x, double y) { return -(p.d + p.N.x * x + p.N.y * y) / p.N.z; }
+
+namespace carve {
+ namespace poly {
+
+ carve::geom2d::P2 _project_1(const carve::geom3d::Vector &v) {
+ return carve::geom::VECTOR(v.z, v.y);
+ }
+
+ carve::geom2d::P2 _project_2(const carve::geom3d::Vector &v) {
+ return carve::geom::VECTOR(v.x, v.z);
+ }
+
+ carve::geom2d::P2 _project_3(const carve::geom3d::Vector &v) {
+ return carve::geom::VECTOR(v.y, v.x);
+ }
+
+ carve::geom2d::P2 _project_4(const carve::geom3d::Vector &v) {
+ return carve::geom::VECTOR(v.y, v.z);
+ }
+
+ carve::geom2d::P2 _project_5(const carve::geom3d::Vector &v) {
+ return carve::geom::VECTOR(v.z, v.x);
+ }
+
+ carve::geom2d::P2 _project_6(const carve::geom3d::Vector &v) {
+ return carve::geom::VECTOR(v.x, v.y);
+ }
+
+
+ carve::geom3d::Vector _unproject_1(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
+ return carve::geom::VECTOR(CALC_X(plane_eqn, p.y, p.x), p.y, p.x);
+ }
+
+ carve::geom3d::Vector _unproject_2(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
+ return carve::geom::VECTOR(p.x, CALC_Y(plane_eqn, p.x, p.y), p.y);
+ }
+
+ carve::geom3d::Vector _unproject_3(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
+ return carve::geom::VECTOR(p.y, p.x, CALC_Z(plane_eqn, p.y, p.x));
+ }
+
+ carve::geom3d::Vector _unproject_4(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
+ return carve::geom::VECTOR(CALC_X(plane_eqn, p.x, p.y), p.x, p.y);
+ }
+
+ carve::geom3d::Vector _unproject_5(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
+ return carve::geom::VECTOR(p.y, CALC_Y(plane_eqn, p.y, p.x), p.x);
+ }
+
+ carve::geom3d::Vector _unproject_6(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
+ return carve::geom::VECTOR(p.x, p.y, CALC_Z(plane_eqn, p.x, p.y));
+ }
+
+ static carve::geom2d::P2 (*project_tab[2][3])(const carve::geom3d::Vector &) = {
+ { &_project_1, &_project_2, &_project_3 },
+ { &_project_4, &_project_5, &_project_6 }
+ };
+
+ static carve::geom3d::Vector (*unproject_tab[2][3])(const carve::geom2d::P2 &, const carve::geom3d::Plane &) = {
+ { &_unproject_1, &_unproject_2, &_unproject_3 },
+ { &_unproject_4, &_unproject_5, &_unproject_6 }
+ };
+
+ // only implemented for 3d.
+ template<unsigned ndim>
+ typename Face<ndim>::project_t Face<ndim>::getProjector(bool positive_facing, int axis) {
+ return NULL;
+ }
+
+ template<>
+ Face<3>::project_t Face<3>::getProjector(bool positive_facing, int axis) {
+ return project_tab[positive_facing ? 1 : 0][axis];
+ }
+
+ template<unsigned ndim>
+ typename Face<ndim>::unproject_t Face<ndim>::getUnprojector(bool positive_facing, int axis) {
+ return NULL;
+ }
+
+ template<>
+ Face<3>::unproject_t Face<3>::getUnprojector(bool positive_facing, int axis) {
+ return unproject_tab[positive_facing ? 1 : 0][axis];
+ }
+
+
+
+ template<unsigned ndim>
+ Face<ndim>::Face(const std::vector<const vertex_t *> &_vertices,
+ bool delay_recalc) : tagable() {
+ vertices = _vertices;
+ edges.resize(nVertices(), NULL);
+ if (!delay_recalc && !recalc()) { }
+ }
+
+ template<unsigned ndim>
+ Face<ndim>::Face(const vertex_t *a,
+ const vertex_t *b,
+ const vertex_t *c,
+ bool delay_recalc) : tagable() {
+ vertices.reserve(3);
+ vertices.push_back(a);
+ vertices.push_back(b);
+ vertices.push_back(c);
+ edges.resize(3, NULL);
+ if (!delay_recalc && !recalc()) { }
+ }
+
+ template<unsigned ndim>
+ Face<ndim>::Face(const vertex_t *a,
+ const vertex_t *b,
+ const vertex_t *c,
+ const vertex_t *d,
+ bool delay_recalc) : tagable() {
+ vertices.reserve(4);
+ vertices.push_back(a);
+ vertices.push_back(b);
+ vertices.push_back(c);
+ vertices.push_back(d);
+ edges.resize(4, NULL);
+ if (!delay_recalc && !recalc()) { }
+ }
+
+ template<unsigned ndim>
+ void Face<ndim>::invert() {
+ size_t n_verts = vertices.size();
+ std::reverse(vertices.begin(), vertices.end());
+
+ if (project != NULL) {
+ plane_eqn.negate();
+
+ int da = carve::geom::largestAxis(plane_eqn.N);
+
+ project = getProjector(plane_eqn.N.v[da] > 0, da);
+ unproject = getUnprojector(plane_eqn.N.v[da] > 0, da);
+ }
+
+ std::reverse(edges.begin(), edges.end() - 1);
+ for (size_t i = 0; i < n_verts; i++) {
+ const vertex_t *v1 = vertices[i];
+ const vertex_t *v2 = vertices[(i+1) % n_verts];
+ CARVE_ASSERT((edges[i]->v1 == v1 && edges[i]->v2 == v2) || (edges[i]->v1 == v2 && edges[i]->v2 == v1));
+ }
+ }
+
+ template<unsigned ndim>
+ bool Face<ndim>::recalc() {
+ aabb.fit(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr());
+
+ if (!carve::geom3d::fitPlane(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr(), plane_eqn)) {
+ return false;
+ }
+
+ int da = carve::geom::largestAxis(plane_eqn.N);
+ project = getProjector(false, da);
+
+ double A = carve::geom2d::signedArea(vertices, projector());
+ if ((A < 0.0) ^ (plane_eqn.N.v[da] < 0.0)) {
+ plane_eqn.negate();
+ }
+
+ project = getProjector(plane_eqn.N.v[da] > 0, da);
+ unproject = getUnprojector(plane_eqn.N.v[da] > 0, da);
+
+ return true;
+ }
+
+ template<unsigned ndim>
+ Face<ndim> *Face<ndim>::init(const Face *base, const std::vector<const vertex_t *> &_vertices, bool flipped) {
+ return init(base, _vertices.begin(), _vertices.end(), flipped);
+ }
+
+ template<unsigned ndim>
+ bool Face<ndim>::containsPoint(const vector_t &p) const {
+ if (!carve::math::ZERO(carve::geom::distance(plane_eqn, p))) return false;
+ // return pointInPolySimple(vertices, projector(), (this->*project)(p));
+ return carve::geom2d::pointInPoly(vertices, projector(), face::project(this, p)).iclass != POINT_OUT;
+ }
+
+ template<unsigned ndim>
+ bool Face<ndim>::containsPointInProjection(const vector_t &p) const {
+ return carve::geom2d::pointInPoly(vertices, projector(), face::project(this, p)).iclass != POINT_OUT;
+ }
+
+ template<unsigned ndim>
+ bool Face<ndim>::simpleLineSegmentIntersection(const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const {
+ if (!line.OK()) return false;
+
+ carve::geom3d::Vector p;
+ IntersectionClass intersects = carve::geom3d::lineSegmentPlaneIntersection(plane_eqn,
+ line,
+ p);
+ if (intersects == INTERSECT_NONE || intersects == INTERSECT_BAD) {
+ return false;
+ }
+
+ carve::geom2d::P2 proj_p(face::project(this, p));
+ if (carve::geom2d::pointInPolySimple(vertices, projector(), proj_p)) {
+ intersection = p;
+ return true;
+ }
+ return false;
+ }
+
+ // XXX: should try to return a pre-existing vertex in the case of a
+ // line-vertex intersection. as it stands, this code isn't used,
+ // so... meh.
+ template<unsigned ndim>
+ IntersectionClass Face<ndim>::lineSegmentIntersection(const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const {
+ if (!line.OK()) return INTERSECT_NONE;
+
+
+ carve::geom3d::Vector p;
+ IntersectionClass intersects = carve::geom3d::lineSegmentPlaneIntersection(plane_eqn,
+ line,
+ p);
+ if (intersects == INTERSECT_NONE || intersects == INTERSECT_BAD) {
+ return intersects;
+ }
+
+ carve::geom2d::P2 proj_p(face::project(this, p));
+
+ carve::geom2d::PolyInclusionInfo pi = carve::geom2d::pointInPoly(vertices, projector(), proj_p);
+ switch (pi.iclass) {
+ case POINT_VERTEX:
+ intersection = p;
+ return INTERSECT_VERTEX;
+
+ case POINT_EDGE:
+ intersection = p;
+ return INTERSECT_EDGE;
+
+ case POINT_IN:
+ intersection = p;
+ return INTERSECT_FACE;
+
+ case POINT_OUT:
+ return INTERSECT_NONE;
+
+ default:
+ break;
+ }
+ return INTERSECT_NONE;
+ }
+
+
+ }
+}
+
+// explicit instantiations.
+template class carve::poly::Face<3>;
diff --git a/extern/carve/lib/geom2d.cpp b/extern/carve/lib/geom2d.cpp
new file mode 100644
index 00000000000..bfa84f5fd24
--- /dev/null
+++ b/extern/carve/lib/geom2d.cpp
@@ -0,0 +1,260 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/geom2d.hpp>
+#include <carve/math.hpp>
+#include <carve/aabb.hpp>
+
+#include <algorithm>
+#include <iostream>
+
+namespace carve {
+ namespace geom2d {
+
+ bool lineSegmentIntersection_simple(const P2 &l1v1, const P2 &l1v2,
+ const P2 &l2v1, const P2 &l2v2) {
+ geom::aabb<2> l1_aabb, l2_aabb;
+ l1_aabb.fit(l1v1, l1v2);
+ l2_aabb.fit(l2v1, l2v2);
+
+ if (l1_aabb.maxAxisSeparation(l2_aabb) > 0.0) {
+ return false;
+ }
+
+ double l1v1_side = orient2d(l2v1, l2v2, l1v1);
+ double l1v2_side = orient2d(l2v1, l2v2, l1v2);
+
+ double l2v1_side = orient2d(l1v1, l1v2, l2v1);
+ double l2v2_side = orient2d(l1v1, l1v2, l2v2);
+
+ if (l1v1_side * l1v2_side > 0.0 || l2v1_side * l2v2_side > 0.0) {
+ return false;
+ }
+
+ return true;
+ }
+
+ bool lineSegmentIntersection_simple(const LineSegment2 &l1,
+ const LineSegment2 &l2) {
+ return lineSegmentIntersection_simple(l1.v1, l1.v2, l2.v1, l2.v2);
+ }
+
+ LineIntersectionInfo lineSegmentIntersection(const P2 &l1v1, const P2 &l1v2,
+ const P2 &l2v1, const P2 &l2v2) {
+ geom::aabb<2> l1_aabb, l2_aabb;
+ l1_aabb.fit(l1v1, l1v2);
+ l2_aabb.fit(l2v1, l2v2);
+
+ if (l1_aabb.maxAxisSeparation(l2_aabb) > EPSILON) {
+ return LineIntersectionInfo(NO_INTERSECTION);
+ }
+
+ if (carve::geom::equal(l1v1, l1v2) || carve::geom::equal(l2v1, l2v2)) {
+ throw carve::exception("zero length line in intersection test");
+ }
+
+ double dx13 = l1v1.x - l2v1.x;
+ double dy13 = l1v1.y - l2v1.y;
+ double dx43 = l2v2.x - l2v1.x;
+ double dy43 = l2v2.y - l2v1.y;
+ double dx21 = l1v2.x - l1v1.x;
+ double dy21 = l1v2.y - l1v1.y;
+ double ua_n = dx43 * dy13 - dy43 * dx13;
+ double ub_n = dx21 * dy13 - dy21 * dx13;
+ double u_d = dy43 * dx21 - dx43 * dy21;
+
+ if (carve::math::ZERO(u_d)) {
+ if (carve::math::ZERO(ua_n)) {
+ if (carve::geom::equal(l1v2, l2v1)) {
+ return LineIntersectionInfo(INTERSECTION_PP, l1v2, 1, 2);
+ }
+ if (carve::geom::equal(l1v1, l2v2)) {
+ return LineIntersectionInfo(INTERSECTION_PP, l1v1, 0, 4);
+ }
+ if (l1v2.x > l2v1.x && l1v1.x < l2v2.x) {
+ return LineIntersectionInfo(COLINEAR);
+ }
+ }
+ return LineIntersectionInfo(NO_INTERSECTION);
+ }
+
+ double ua = ua_n / u_d;
+ double ub = ub_n / u_d;
+
+ if (-EPSILON <= ua && ua <= 1.0 + EPSILON && -EPSILON <= ub && ub <= 1.0 + EPSILON) {
+ double x = l1v1.x + ua * (l1v2.x - l1v1.x);
+ double y = l1v1.y + ua * (l1v2.y - l1v1.y);
+
+ P2 p = carve::geom::VECTOR(x, y);
+
+ double d1 = distance2(p, l1v1);
+ double d2 = distance2(p, l1v2);
+ double d3 = distance2(p, l2v1);
+ double d4 = distance2(p, l2v2);
+
+ int n = -1;
+
+ if (std::min(d1, d2) < EPSILON2) {
+ if (d1 < d2) {
+ p = l1v1; n = 0;
+ } else {
+ p = l1v2; n = 1;
+ }
+ if (std::min(d3, d4) < EPSILON2) {
+ if (d3 < d4) {
+ return LineIntersectionInfo(INTERSECTION_PP, p, n, 2);
+ } else {
+ return LineIntersectionInfo(INTERSECTION_PP, p, n, 3);
+ }
+ } else {
+ return LineIntersectionInfo(INTERSECTION_PL, p, n, -1);
+ }
+ } else if (std::min(d3, d4) < EPSILON2) {
+ if (d3 < d4) {
+ return LineIntersectionInfo(INTERSECTION_LP, l2v1, -1, 2);
+ } else {
+ return LineIntersectionInfo(INTERSECTION_LP, l2v2, -1, 3);
+ }
+ } else {
+ return LineIntersectionInfo(INTERSECTION_LL, p, -1, -1);
+ }
+ }
+ return LineIntersectionInfo(NO_INTERSECTION);
+ }
+
+ LineIntersectionInfo lineSegmentIntersection(const LineSegment2 &l1,
+ const LineSegment2 &l2) {
+ return lineSegmentIntersection(l1.v1, l1.v2, l2.v1, l2.v2);
+ }
+
+ double signedArea(const P2Vector &points) {
+ return signedArea(points, p2_adapt_ident());
+ }
+
+ bool pointInPolySimple(const P2Vector &points, const P2 &p) {
+ return pointInPolySimple(points, p2_adapt_ident(), p);
+ }
+
+ PolyInclusionInfo pointInPoly(const P2Vector &points, const P2 &p) {
+ return pointInPoly(points, p2_adapt_ident(), p);
+ }
+
+ int lineSegmentPolyIntersections(const P2Vector &points,
+ LineSegment2 line,
+ std::vector<PolyIntersectionInfo> &out) {
+ int count = 0;
+
+ if (line.v2 < line.v1) { line.flip(); }
+ out.clear();
+
+ for (P2Vector::size_type i = 0, l = points.size(); i < l; i++) {
+ P2Vector::size_type j = (i + 1) % l;
+ LineIntersectionInfo e =
+ lineSegmentIntersection(LineSegment2(points[i], points[j]), line);
+
+ switch (e.iclass) {
+ case INTERSECTION_PL: {
+ out.push_back(PolyIntersectionInfo(INTERSECT_EDGE, e.ipoint, i));
+ count++;
+ break;
+ }
+ case INTERSECTION_PP: {
+ out.push_back(PolyIntersectionInfo(INTERSECT_VERTEX, e.ipoint, i + e.p2 - 2));
+ count++;
+ break;
+ }
+ case INTERSECTION_LP: {
+ out.push_back(PolyIntersectionInfo(INTERSECT_VERTEX, e.ipoint, i + e.p2 - 2));
+ count++;
+ break;
+ }
+ case INTERSECTION_LL: {
+ out.push_back(PolyIntersectionInfo(INTERSECT_EDGE, e.ipoint, i));
+ count++;
+ break;
+ }
+ case COLINEAR: {
+ int n1 = (int)i, n2 = (int)j;
+ P2 q1 = points[i], q2 = points[j];
+
+ if (q2 < q1) { std::swap(q1, q2); std::swap(n1, n2); }
+
+ if (equal(q1, line.v1)) {
+ out.push_back(PolyIntersectionInfo(INTERSECT_VERTEX, q1, n1));
+ } else if (q1.x < line.v1.x) {
+ out.push_back(PolyIntersectionInfo(INTERSECT_EDGE, line.v1, i));
+ } else {
+ out.push_back(PolyIntersectionInfo(INTERSECT_VERTEX, q1, n1));
+ }
+ if (equal(q2, line.v2)) {
+ out.push_back(PolyIntersectionInfo(INTERSECT_VERTEX, q2, n2));
+ } else if (line.v2.x < q2.x) {
+ out.push_back(PolyIntersectionInfo(INTERSECT_EDGE, line.v2, i));
+ } else {
+ out.push_back(PolyIntersectionInfo(INTERSECT_VERTEX, q2, n2));
+ }
+
+ count += 2;
+
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ return count;
+ }
+
+ struct FwdSort {
+ bool operator()(const PolyIntersectionInfo &a,
+ const PolyIntersectionInfo &b) const {
+ return a.ipoint < b.ipoint;
+ }
+ };
+
+ struct RevSort {
+ bool operator()(const PolyIntersectionInfo &a,
+ const PolyIntersectionInfo &b) const {
+ return a.ipoint < b.ipoint;
+ }
+ };
+
+ int sortedLineSegmentPolyIntersections(const P2Vector &points,
+ LineSegment2 line,
+ std::vector<PolyIntersectionInfo> &out) {
+
+ bool swapped = line.v2 < line.v1;
+
+ int count = lineSegmentPolyIntersections(points, line, out);
+ if (swapped) {
+ std::sort(out.begin(), out.end(), RevSort());
+ } else {
+ std::sort(out.begin(), out.end(), FwdSort());
+ }
+ return count;
+ }
+
+ bool pickContainedPoint(const std::vector<P2> &poly, P2 &result) {
+ return pickContainedPoint(poly, p2_adapt_ident(), result);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/geom3d.cpp b/extern/carve/lib/geom3d.cpp
new file mode 100644
index 00000000000..061dfe91802
--- /dev/null
+++ b/extern/carve/lib/geom3d.cpp
@@ -0,0 +1,164 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/math.hpp>
+#include <carve/geom3d.hpp>
+
+#include <algorithm>
+
+namespace carve {
+ namespace geom3d {
+
+ namespace {
+ int is_same(const std::vector<const Vector *> &a,
+ const std::vector<const Vector *> &b) {
+ if (a.size() != b.size()) return false;
+
+ const size_t S = a.size();
+ size_t i, j, p;
+
+ for (p = 0; p < S; ++p) {
+ if (a[0] == b[p]) break;
+ }
+ if (p == S) return 0;
+
+ for (i = 1, j = p + 1; j < S; ++i, ++j) if (a[i] != b[j]) goto not_fwd;
+ for ( j = 0; i < S; ++i, ++j) if (a[i] != b[j]) goto not_fwd;
+ return +1;
+
+not_fwd:
+ for (i = 1, j = p - 1; j != (size_t)-1; ++i, --j) if (a[i] != b[j]) goto not_rev;
+ for ( j = S - 1; i < S; ++i, --j) if (a[i] != b[j]) goto not_rev;
+ return -1;
+
+not_rev:
+ return 0;
+ }
+ }
+
+ bool planeIntersection(const Plane &a, const Plane &b, Ray &r) {
+ Vector N = cross(a.N, b.N);
+ if (N.isZero()) {
+ return false;
+ }
+ N.normalize();
+
+ double dot_aa = dot(a.N, a.N);
+ double dot_bb = dot(b.N, b.N);
+ double dot_ab = dot(a.N, b.N);
+
+ double determinant = dot_aa * dot_bb - dot_ab * dot_ab;
+
+ double c1 = ( a.d * dot_bb - b.d * dot_ab) / determinant;
+ double c2 = ( b.d * dot_aa - a.d * dot_ab) / determinant;
+
+ r.D = N;
+ r.v = c1 * a.N + c2 * b.N;
+
+ return true;
+ }
+
+ IntersectionClass rayPlaneIntersection(const Plane &p,
+ const Vector &v1,
+ const Vector &v2,
+ Vector &v,
+ double &t) {
+ Vector Rd = v2 - v1;
+ double Vd = dot(p.N, Rd);
+ double V0 = dot(p.N, v1) + p.d;
+
+ if (carve::math::ZERO(Vd)) {
+ if (carve::math::ZERO(V0)) {
+ return INTERSECT_BAD;
+ } else {
+ return INTERSECT_NONE;
+ }
+ }
+
+ t = -V0 / Vd;
+ v = v1 + t * Rd;
+ return INTERSECT_PLANE;
+ }
+
+ IntersectionClass lineSegmentPlaneIntersection(const Plane &p,
+ const LineSegment &line,
+ Vector &v) {
+ double t;
+ IntersectionClass r = rayPlaneIntersection(p, line.v1, line.v2, v, t);
+
+ if (r <= 0) return r;
+
+ if ((t < 0.0 && !equal(v, line.v1)) || (t > 1.0 && !equal(v, line.v2)))
+ return INTERSECT_NONE;
+
+ return INTERSECT_PLANE;
+ }
+
+ RayIntersectionClass rayRayIntersection(const Ray &r1,
+ const Ray &r2,
+ Vector &v1,
+ Vector &v2,
+ double &mu1,
+ double &mu2) {
+ if (!r1.OK() || !r2.OK()) return RR_DEGENERATE;
+
+ Vector v_13 = r1.v - r2.v;
+
+ double d1343 = dot(v_13, r2.D);
+ double d4321 = dot(r2.D, r1.D);
+ double d1321 = dot(v_13, r1.D);
+ double d4343 = dot(r2.D, r2.D);
+ double d2121 = dot(r1.D, r1.D);
+
+ double numer = d1343 * d4321 - d1321 * d4343;
+ double denom = d2121 * d4343 - d4321 * d4321;
+
+ // dc - eb
+ // -------
+ // ab - cc
+
+ // dc/eb - 1
+ // ---------
+ // a/e - cc/eb
+
+ // dc/b - e
+ // --------
+ // a - cc/b
+
+ // d/b - e/c
+ // ---------
+ // a/c - c/b
+
+ if (fabs(denom) * double(1<<10) <= fabs(numer)) {
+ return RR_PARALLEL;
+ }
+
+ mu1 = numer / denom;
+ mu2 = (d1343 + d4321 * mu1) / d4343;
+
+ v1 = r1.v + mu1 * r1.D;
+ v2 = r2.v + mu2 * r2.D;
+
+ return (equal(v1, v2)) ? RR_INTERSECTION : RR_NO_INTERSECTION;
+ }
+
+ }
+}
diff --git a/extern/carve/lib/intersect.cpp b/extern/carve/lib/intersect.cpp
new file mode 100644
index 00000000000..35166a6411e
--- /dev/null
+++ b/extern/carve/lib/intersect.cpp
@@ -0,0 +1,1668 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/pointset.hpp>
+#include <carve/polyline.hpp>
+
+#include <list>
+#include <set>
+#include <iostream>
+
+#include <algorithm>
+
+#include "csg_detail.hpp"
+#include "csg_data.hpp"
+
+#include "intersect_debug.hpp"
+#include "intersect_common.hpp"
+#include "intersect_classify_common.hpp"
+
+#include "csg_collector.hpp"
+
+#include <carve/timing.hpp>
+#include <carve/colour.hpp>
+
+
+
+
+carve::csg::VertexPool::VertexPool() {
+}
+
+carve::csg::VertexPool::~VertexPool() {
+}
+
+void carve::csg::VertexPool::reset() {
+ pool.clear();
+}
+
+carve::csg::VertexPool::vertex_t *carve::csg::VertexPool::get(const vertex_t::vector_t &v) {
+ if (!pool.size() || pool.back().size() == blocksize) {
+ pool.push_back(std::vector<vertex_t>());
+ pool.back().reserve(blocksize);
+ }
+ pool.back().push_back(vertex_t(v));
+ return &pool.back().back();
+}
+
+bool carve::csg::VertexPool::inPool(vertex_t *v) const {
+ for (pool_t::const_iterator i = pool.begin(); i != pool.end(); ++i) {
+ if (v >= &(i->front()) && v <= &(i->back())) return true;
+ }
+ return false;
+}
+
+
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+void writePLY(const std::string &out_file, const carve::point::PointSet *points, bool ascii);
+void writePLY(const std::string &out_file, const carve::line::PolylineSet *lines, bool ascii);
+void writePLY(const std::string &out_file, const carve::mesh::MeshSet<3> *poly, bool ascii);
+
+static carve::mesh::MeshSet<3> *faceLoopsToPolyhedron(const carve::csg::FaceLoopList &fl) {
+ std::vector<carve::mesh::MeshSet<3>::face_t *> faces;
+ faces.reserve(fl.size());
+ for (carve::csg::FaceLoop *f = fl.head; f; f = f->next) {
+ faces.push_back(f->orig_face->create(f->vertices.begin(), f->vertices.end(), false));
+ }
+ carve::mesh::MeshSet<3> *poly = new carve::mesh::MeshSet<3>(faces);
+
+ return poly;
+}
+#endif
+
+namespace {
+ /**
+ * \brief Sort a range [\a beg, \a end) of vertices in order of increasing dot product of vertex - \a base on \dir.
+ *
+ * @tparam[in] T a forward iterator type.
+ * @param[in] dir The direction in which to sort vertices.
+ * @param[in] base
+ * @param[in] beg The start of the vertex range to sort.
+ * @param[in] end The end of the vertex range to sort.
+ * @param[out] out The sorted vertex result.
+ * @param[in] size_hint A hint regarding the size of the output
+ * vector (to avoid needing to be able to calculate \a
+ * end - \a beg).
+ */
+ template<typename iter_t>
+ void orderVertices(iter_t beg, const iter_t end,
+ const carve::mesh::MeshSet<3>::vertex_t::vector_t &dir,
+ const carve::mesh::MeshSet<3>::vertex_t::vector_t &base,
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &out) {
+ typedef std::vector<std::pair<double, carve::mesh::MeshSet<3>::vertex_t *> > DVVector;
+ std::vector<std::pair<double, carve::mesh::MeshSet<3>::vertex_t *> > ordered_vertices;
+
+ ordered_vertices.reserve(std::distance(beg, end));
+
+ for (; beg != end; ++beg) {
+ carve::mesh::MeshSet<3>::vertex_t *v = (*beg);
+ ordered_vertices.push_back(std::make_pair(carve::geom::dot(v->v - base, dir), v));
+ }
+
+ std::sort(ordered_vertices.begin(), ordered_vertices.end());
+
+ out.clear();
+ out.reserve(ordered_vertices.size());
+ for (DVVector::const_iterator
+ i = ordered_vertices.begin(), e = ordered_vertices.end();
+ i != e;
+ ++i) {
+ out.push_back((*i).second);
+ }
+ }
+
+
+
+ /**
+ *
+ *
+ * @param dir
+ * @param base
+ * @param beg
+ * @param end
+ */
+ template<typename iter_t>
+ void selectOrderingProjection(iter_t beg, const iter_t end,
+ carve::mesh::MeshSet<3>::vertex_t::vector_t &dir,
+ carve::mesh::MeshSet<3>::vertex_t::vector_t &base) {
+ double dx, dy, dz;
+ carve::mesh::MeshSet<3>::vertex_t *min_x, *min_y, *min_z, *max_x, *max_y, *max_z;
+ if (beg == end) return;
+ min_x = max_x = min_y = max_y = min_z = max_z = *beg++;
+ for (; beg != end; ++beg) {
+ if (min_x->v.x > (*beg)->v.x) min_x = *beg;
+ if (min_y->v.y > (*beg)->v.y) min_y = *beg;
+ if (min_z->v.z > (*beg)->v.z) min_z = *beg;
+ if (max_x->v.x < (*beg)->v.x) max_x = *beg;
+ if (max_y->v.y < (*beg)->v.y) max_y = *beg;
+ if (max_z->v.z < (*beg)->v.z) max_z = *beg;
+ }
+
+ dx = max_x->v.x - min_x->v.x;
+ dy = max_y->v.y - min_y->v.y;
+ dz = max_z->v.z - min_z->v.z;
+
+ if (dx > dy) {
+ if (dx > dz) {
+ dir = max_x->v - min_x->v; base = min_x->v;
+ } else {
+ dir = max_z->v - min_z->v; base = min_z->v;
+ }
+ } else {
+ if (dy > dz) {
+ dir = max_y->v - min_y->v; base = min_y->v;
+ } else {
+ dir = max_z->v - min_z->v; base = min_z->v;
+ }
+ }
+ }
+}
+
+namespace {
+ struct dump_data {
+ carve::mesh::MeshSet<3>::vertex_t *i_pt;
+ carve::csg::IObj i_src;
+ carve::csg::IObj i_tgt;
+ dump_data(carve::mesh::MeshSet<3>::vertex_t *_i_pt,
+ carve::csg::IObj _i_src,
+ carve::csg::IObj _i_tgt) : i_pt(_i_pt), i_src(_i_src), i_tgt(_i_tgt) {
+ }
+ };
+
+
+
+ struct dump_sort {
+ bool operator()(const dump_data &a, const dump_data &b) const {
+ if (a.i_pt->v.x < b.i_pt->v.x) return true;
+ if (a.i_pt->v.x > b.i_pt->v.x) return false;
+ if (a.i_pt->v.y < b.i_pt->v.y) return true;
+ if (a.i_pt->v.y > b.i_pt->v.y) return false;
+ if (a.i_pt->v.z < b.i_pt->v.z) return true;
+ if (a.i_pt->v.z > b.i_pt->v.z) return false;
+ return false;
+ }
+ };
+
+
+
+ void dump_intersections(std::ostream &out, carve::csg::Intersections &csg_intersections) {
+ std::vector<dump_data> temp;
+
+ for (carve::csg::Intersections::const_iterator
+ i = csg_intersections.begin(),
+ ie = csg_intersections.end();
+ i != ie;
+ ++i) {
+ const carve::csg::IObj &i_src = ((*i).first);
+
+ for (carve::csg::Intersections::mapped_type::const_iterator
+ j = (*i).second.begin(),
+ je = (*i).second.end();
+ j != je;
+ ++j) {
+ const carve::csg::IObj &i_tgt = ((*j).first);
+ carve::mesh::MeshSet<3>::vertex_t *i_pt = ((*j).second);
+ temp.push_back(dump_data(i_pt, i_src, i_tgt));
+ }
+ }
+
+ std::sort(temp.begin(), temp.end(), dump_sort());
+
+ for (size_t i = 0; i < temp.size(); ++i) {
+ const carve::csg::IObj &i_src = temp[i].i_src;
+ const carve::csg::IObj &i_tgt = temp[i].i_tgt;
+ out
+ << "INTERSECTION: " << temp[i].i_pt << " (" << temp[i].i_pt->v << ") "
+ << "is " << i_src << ".." << i_tgt << std::endl;
+ }
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ std::vector<carve::geom3d::Vector> vertices;
+
+ for (carve::csg::Intersections::const_iterator
+ i = csg_intersections.begin(),
+ ie = csg_intersections.end();
+ i != ie;
+ ++i) {
+ for (carve::csg::Intersections::mapped_type::const_iterator
+ j = (*i).second.begin(),
+ je = (*i).second.end();
+ j != je;
+ ++j) {
+ carve::mesh::MeshSet<3>::vertex_t *i_pt = ((*j).second);
+ vertices.push_back(i_pt->v);
+ }
+ }
+
+ carve::point::PointSet points(vertices);
+
+ std::string outf("/tmp/intersection-points.ply");
+ ::writePLY(outf, &points, true);
+#endif
+ }
+
+
+
+ /**
+ * \brief Populate a collection with the faces adjoining an edge.
+ *
+ * @tparam face_set_t A collection type.
+ * @param e The edge for which to collect adjoining faces.
+ * @param faces
+ */
+ template<typename face_set_t>
+ inline void facesForVertex(carve::mesh::MeshSet<3>::vertex_t *v,
+ const carve::csg::detail::VEVecMap &ve,
+ face_set_t &faces) {
+ carve::csg::detail::VEVecMap::const_iterator vi = ve.find(v);
+ if (vi != ve.end()) {
+ for (carve::csg::detail::VEVecMap::data_type::const_iterator i = (*vi).second.begin(); i != (*vi).second.end(); ++i) {
+ faces.insert((*i)->face);
+ }
+ }
+ }
+
+ /**
+ * \brief Populate a collection with the faces adjoining an edge.
+ *
+ * @tparam face_set_t A collection type.
+ * @param e The edge for which to collect adjoining faces.
+ * @param faces
+ */
+ template<typename face_set_t>
+ inline void facesForEdge(carve::mesh::MeshSet<3>::edge_t *e,
+ face_set_t &faces) {
+ faces.insert(e->face);
+ }
+
+ /**
+ * \brief Populate a collection with the faces adjoining a face.
+ *
+ * @tparam face_set_t A collection type.
+ * @param f The face for which to collect adjoining faces.
+ * @param faces
+ */
+ template<typename face_set_t>
+ inline void facesForFace(carve::mesh::MeshSet<3>::face_t *f,
+ face_set_t &faces) {
+ faces.insert(f);
+ }
+
+ /**
+ * \brief Populate a collection with the faces adjoining an intersection object.
+ *
+ * @tparam face_set_t A collection type holding const carve::poly::Polyhedron::face_t *.
+ * @param obj The intersection object for which to collect adjoining faces.
+ * @param faces
+ */
+ template<typename face_set_t>
+ void facesForObject(const carve::csg::IObj &obj,
+ const carve::csg::detail::VEVecMap &ve,
+ face_set_t &faces) {
+ switch (obj.obtype) {
+ case carve::csg::IObj::OBTYPE_VERTEX:
+ facesForVertex(obj.vertex, ve, faces);
+ break;
+
+ case carve::csg::IObj::OBTYPE_EDGE:
+ facesForEdge(obj.edge, faces);
+ break;
+
+ case carve::csg::IObj::OBTYPE_FACE:
+ facesForFace(obj.face, faces);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+
+
+}
+
+
+
+bool carve::csg::CSG::Hooks::hasHook(unsigned hook_num) {
+ return hooks[hook_num].size() > 0;
+}
+
+void carve::csg::CSG::Hooks::intersectionVertex(const carve::mesh::MeshSet<3>::vertex_t *vertex,
+ const IObjPairSet &intersections) {
+ for (std::list<Hook *>::iterator j = hooks[INTERSECTION_VERTEX_HOOK].begin();
+ j != hooks[INTERSECTION_VERTEX_HOOK].end();
+ ++j) {
+ (*j)->intersectionVertex(vertex, intersections);
+ }
+}
+
+void carve::csg::CSG::Hooks::processOutputFace(std::vector<carve::mesh::MeshSet<3>::face_t *> &faces,
+ const carve::mesh::MeshSet<3>::face_t *orig_face,
+ bool flipped) {
+ for (std::list<Hook *>::iterator j = hooks[PROCESS_OUTPUT_FACE_HOOK].begin();
+ j != hooks[PROCESS_OUTPUT_FACE_HOOK].end();
+ ++j) {
+ (*j)->processOutputFace(faces, orig_face, flipped);
+ }
+}
+
+void carve::csg::CSG::Hooks::resultFace(const carve::mesh::MeshSet<3>::face_t *new_face,
+ const carve::mesh::MeshSet<3>::face_t *orig_face,
+ bool flipped) {
+ for (std::list<Hook *>::iterator j = hooks[RESULT_FACE_HOOK].begin();
+ j != hooks[RESULT_FACE_HOOK].end();
+ ++j) {
+ (*j)->resultFace(new_face, orig_face, flipped);
+ }
+}
+
+void carve::csg::CSG::Hooks::registerHook(Hook *hook, unsigned hook_bits) {
+ for (unsigned i = 0; i < HOOK_MAX; ++i) {
+ if (hook_bits & (1U << i)) {
+ hooks[i].push_back(hook);
+ }
+ }
+}
+
+void carve::csg::CSG::Hooks::unregisterHook(Hook *hook) {
+ for (unsigned i = 0; i < HOOK_MAX; ++i) {
+ hooks[i].erase(std::remove(hooks[i].begin(), hooks[i].end(), hook), hooks[i].end());
+ }
+}
+
+void carve::csg::CSG::Hooks::reset() {
+ for (unsigned i = 0; i < HOOK_MAX; ++i) {
+ for (std::list<Hook *>::iterator j = hooks[i].begin(); j != hooks[i].end(); ++j) {
+ delete (*j);
+ }
+ hooks[i].clear();
+ }
+}
+
+carve::csg::CSG::Hooks::Hooks() : hooks() {
+ hooks.resize(HOOK_MAX);
+}
+
+carve::csg::CSG::Hooks::~Hooks() {
+ reset();
+}
+
+
+
+void carve::csg::CSG::makeVertexIntersections() {
+ static carve::TimingName FUNC_NAME("CSG::makeVertexIntersections()");
+ carve::TimingBlock block(FUNC_NAME);
+ vertex_intersections.clear();
+ for (Intersections::const_iterator
+ i = intersections.begin(),
+ ie = intersections.end();
+ i != ie;
+ ++i) {
+ const IObj &i_src = ((*i).first);
+
+ for (Intersections::mapped_type::const_iterator
+ j = (*i).second.begin(),
+ je = (*i).second.end();
+ j != je;
+ ++j) {
+ const IObj &i_tgt = ((*j).first);
+ carve::mesh::MeshSet<3>::vertex_t *i_pt = ((*j).second);
+
+ vertex_intersections[i_pt].insert(std::make_pair(i_src, i_tgt));
+ }
+ }
+}
+
+
+
+static carve::mesh::MeshSet<3>::vertex_t *chooseWeldPoint(
+ const carve::csg::detail::VSet &equivalent,
+ carve::csg::VertexPool &vertex_pool) {
+ // XXX: choose a better weld point.
+ if (!equivalent.size()) return NULL;
+
+ for (carve::csg::detail::VSet::const_iterator
+ i = equivalent.begin(), e = equivalent.end();
+ i != e;
+ ++i) {
+ if (!vertex_pool.inPool((*i))) return (*i);
+ }
+ return *equivalent.begin();
+}
+
+
+
+static const carve::mesh::MeshSet<3>::vertex_t *weld(
+ const carve::csg::detail::VSet &equivalent,
+ carve::csg::VertexIntersections &vertex_intersections,
+ carve::csg::VertexPool &vertex_pool) {
+ carve::mesh::MeshSet<3>::vertex_t *weld_point = chooseWeldPoint(equivalent, vertex_pool);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "weld: " << equivalent.size() << " vertices ( ";
+ for (carve::csg::detail::VSet::const_iterator
+ i = equivalent.begin(), e = equivalent.end();
+ i != e;
+ ++i) {
+ const carve::mesh::MeshSet<3>::vertex_t *v = (*i);
+ std::cerr << " " << v;
+ }
+ std::cerr << ") to " << weld_point << std::endl;
+#endif
+
+ if (!weld_point) return NULL;
+
+ carve::csg::VertexIntersections::mapped_type &weld_tgt = (vertex_intersections[weld_point]);
+
+ for (carve::csg::detail::VSet::const_iterator
+ i = equivalent.begin(), e = equivalent.end();
+ i != e;
+ ++i) {
+ carve::mesh::MeshSet<3>::vertex_t *v = (*i);
+
+ if (v != weld_point) {
+ carve::csg::VertexIntersections::iterator j = vertex_intersections.find(v);
+
+ if (j != vertex_intersections.end()) {
+ weld_tgt.insert((*j).second.begin(), (*j).second.end());
+ vertex_intersections.erase(j);
+ }
+ }
+ }
+ return weld_point;
+}
+
+
+
+void carve::csg::CSG::groupIntersections() {
+#if 0 // old code, to be removed.
+ static carve::TimingName GROUP_INTERSECTONS("groupIntersections()");
+
+ carve::TimingBlock block(GROUP_INTERSECTONS);
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> vertices;
+ detail::VVSMap graph;
+#if defined(CARVE_DEBUG)
+ std::cerr << "groupIntersections()" << ": vertex_intersections.size()==" << vertex_intersections.size() << std::endl;
+#endif
+
+ vertices.reserve(vertex_intersections.size());
+ for (carve::csg::VertexIntersections::const_iterator
+ i = vertex_intersections.begin(),
+ e = vertex_intersections.end();
+ i != e;
+ ++i)
+ {
+ vertices.push_back((*i).first);
+ }
+ carve::geom3d::AABB aabb;
+ aabb.fit(vertices.begin(), vertices.end(), carve::poly::vec_adapt_vertex_ptr());
+ Octree vertex_intersections_octree;
+ vertex_intersections_octree.setBounds(aabb);
+
+ vertex_intersections_octree.addVertices(vertices);
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> out;
+ for (size_t i = 0, l = vertices.size(); i != l; ++i) {
+ // let's find all the vertices near this one.
+ out.clear();
+ vertex_intersections_octree.findVerticesNearAllowDupes(vertices[i]->v, out);
+
+ for (size_t j = 0; j < out.size(); ++j) {
+ if (vertices[i] != out[j] && carve::geom::equal(vertices[i]->v, out[j]->v)) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "EQ: " << vertices[i] << "," << out[j] << " " << vertices[i]->v << "," << out[j]->v << std::endl;
+#endif
+ graph[vertices[i]].insert(out[j]);
+ graph[out[j]].insert(vertices[i]);
+ }
+ }
+ }
+
+ detail::VSet visited, open;
+ while (graph.size()) {
+ visited.clear();
+ open.clear();
+ detail::VVSMap::iterator i = graph.begin();
+ open.insert((*i).first);
+ while (open.size()) {
+ detail::VSet::iterator t = open.begin();
+ const carve::mesh::MeshSet<3>::vertex_t *o = (*t);
+ open.erase(t);
+ i = graph.find(o);
+ CARVE_ASSERT(i != graph.end());
+ visited.insert(o);
+ for (detail::VVSMap::mapped_type::const_iterator
+ j = (*i).second.begin(),
+ je = (*i).second.end();
+ j != je;
+ ++j) {
+ if (visited.count((*j)) == 0) {
+ open.insert((*j));
+ }
+ }
+ graph.erase(i);
+ }
+ weld(visited, vertex_intersections, vertex_pool);
+ }
+#endif
+}
+
+
+
+void carve::csg::CSG::intersectingFacePairs(detail::Data &data) {
+ static carve::TimingName FUNC_NAME("CSG::intersectingFacePairs()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ // iterate over all intersection points.
+ for (VertexIntersections::const_iterator i = vertex_intersections.begin(), ie = vertex_intersections.end(); i != ie; ++i) {
+ carve::mesh::MeshSet<3>::vertex_t *i_pt = ((*i).first);
+ detail::VFSMap::mapped_type &face_set = (data.fmap_rev[i_pt]);
+
+ // for all pairs of intersecting objects at this point
+ for (VertexIntersections::data_type::const_iterator j = (*i).second.begin(), je = (*i).second.end(); j != je; ++j) {
+ const IObj &i_src = ((*j).first);
+ const IObj &i_tgt = ((*j).second);
+
+ // work out the faces involved. this updates fmap_rev.
+ facesForObject(i_src, data.vert_to_edges, face_set);
+ facesForObject(i_tgt, data.vert_to_edges, face_set);
+
+ // record the intersection with respect to any involved vertex.
+ if (i_src.obtype == IObj::OBTYPE_VERTEX) data.vmap[i_src.vertex] = i_pt;
+ if (i_tgt.obtype == IObj::OBTYPE_VERTEX) data.vmap[i_tgt.vertex] = i_pt;
+
+ // record the intersection with respect to any involved edge.
+ if (i_src.obtype == IObj::OBTYPE_EDGE) data.emap[i_src.edge].insert(i_pt);
+ if (i_tgt.obtype == IObj::OBTYPE_EDGE) data.emap[i_tgt.edge].insert(i_pt);
+ }
+
+ // record the intersection with respect to each face.
+ for (carve::csg::detail::VFSMap::mapped_type::const_iterator k = face_set.begin(), ke = face_set.end(); k != ke; ++k) {
+ carve::mesh::MeshSet<3>::face_t *f = (*k);
+ data.fmap[f].insert(i_pt);
+ }
+ }
+}
+
+
+
+void carve::csg::CSG::_generateVertexVertexIntersections(carve::mesh::MeshSet<3>::vertex_t *va,
+ carve::mesh::MeshSet<3>::edge_t *eb) {
+ if (intersections.intersects(va, eb->v1())) {
+ return;
+ }
+
+ double d_v1 = carve::geom::distance2(va->v, eb->v1()->v);
+
+ if (d_v1 < carve::EPSILON2) {
+ intersections.record(va, eb->v1(), va);
+ }
+}
+
+
+
+void carve::csg::CSG::generateVertexVertexIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b) {
+ carve::mesh::MeshSet<3>::edge_t *ea, *eb;
+
+ ea = a->edge;
+ do {
+ for (size_t i = 0; i < b.size(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *t = b[i];
+ eb = t->edge;
+ do {
+ _generateVertexVertexIntersections(ea->v1(), eb);
+ eb = eb->next;
+ } while (eb != t->edge);
+ }
+ ea = ea->next;
+ } while (ea != a->edge);
+}
+
+
+
+void carve::csg::CSG::_generateVertexEdgeIntersections(carve::mesh::MeshSet<3>::vertex_t *va,
+ carve::mesh::MeshSet<3>::edge_t *eb) {
+ if (intersections.intersects(va, eb)) {
+ return;
+ }
+
+ if (std::min(eb->v1()->v.x, eb->v2()->v.x) - carve::EPSILON > va->v.x ||
+ std::max(eb->v1()->v.x, eb->v2()->v.x) + carve::EPSILON < va->v.x ||
+ std::min(eb->v1()->v.y, eb->v2()->v.y) - carve::EPSILON > va->v.y ||
+ std::max(eb->v1()->v.y, eb->v2()->v.y) + carve::EPSILON < va->v.y ||
+ std::min(eb->v1()->v.z, eb->v2()->v.z) - carve::EPSILON > va->v.z ||
+ std::max(eb->v1()->v.z, eb->v2()->v.z) + carve::EPSILON < va->v.z) {
+ return;
+ }
+
+ double a = cross(eb->v2()->v - eb->v1()->v, va->v - eb->v1()->v).length2();
+ double b = (eb->v2()->v - eb->v1()->v).length2();
+
+ if (a < b * carve::EPSILON2) {
+ // vertex-edge intersection
+ intersections.record(eb, va, va);
+ if (eb->rev) intersections.record(eb->rev, va, va);
+ }
+}
+
+
+
+void carve::csg::CSG::generateVertexEdgeIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b) {
+ carve::mesh::MeshSet<3>::edge_t *ea, *eb;
+
+ ea = a->edge;
+ do {
+ for (size_t i = 0; i < b.size(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *t = b[i];
+ eb = t->edge;
+ do {
+ _generateVertexEdgeIntersections(ea->v1(), eb);
+ eb = eb->next;
+ } while (eb != t->edge);
+ }
+ ea = ea->next;
+ } while (ea != a->edge);
+}
+
+
+
+void carve::csg::CSG::_generateEdgeEdgeIntersections(carve::mesh::MeshSet<3>::edge_t *ea,
+ carve::mesh::MeshSet<3>::edge_t *eb) {
+ if (intersections.intersects(ea, eb)) {
+ return;
+ }
+
+ carve::mesh::MeshSet<3>::vertex_t *v1 = ea->v1(), *v2 = ea->v2();
+ carve::mesh::MeshSet<3>::vertex_t *v3 = eb->v1(), *v4 = eb->v2();
+
+ carve::geom::aabb<3> ea_aabb, eb_aabb;
+ ea_aabb.fit(v1->v, v2->v);
+ eb_aabb.fit(v3->v, v4->v);
+ if (ea_aabb.maxAxisSeparation(eb_aabb) > EPSILON) return;
+
+ carve::mesh::MeshSet<3>::vertex_t::vector_t p1, p2;
+ double mu1, mu2;
+
+ switch (carve::geom3d::rayRayIntersection(carve::geom3d::Ray(v2->v - v1->v, v1->v),
+ carve::geom3d::Ray(v4->v - v3->v, v3->v),
+ p1, p2, mu1, mu2)) {
+ case carve::RR_INTERSECTION: {
+ // edges intersect
+ if (mu1 >= 0.0 && mu1 <= 1.0 && mu2 >= 0.0 && mu2 <= 1.0) {
+ carve::mesh::MeshSet<3>::vertex_t *p = vertex_pool.get((p1 + p2) / 2.0);
+ intersections.record(ea, eb, p);
+ if (ea->rev) intersections.record(ea->rev, eb, p);
+ if (eb->rev) intersections.record(ea, eb->rev, p);
+ if (ea->rev && eb->rev) intersections.record(ea->rev, eb->rev, p);
+ }
+ break;
+ }
+ case carve::RR_PARALLEL: {
+ // edges parallel. any intersection of this type should have
+ // been handled by generateVertexEdgeIntersections().
+ break;
+ }
+ case carve::RR_DEGENERATE: {
+ throw carve::exception("degenerate edge");
+ break;
+ }
+ case carve::RR_NO_INTERSECTION: {
+ break;
+ }
+ }
+}
+
+
+
+void carve::csg::CSG::generateEdgeEdgeIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b) {
+ carve::mesh::MeshSet<3>::edge_t *ea, *eb;
+
+ ea = a->edge;
+ do {
+ for (size_t i = 0; i < b.size(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *t = b[i];
+ eb = t->edge;
+ do {
+ _generateEdgeEdgeIntersections(ea, eb);
+ eb = eb->next;
+ } while (eb != t->edge);
+ }
+ ea = ea->next;
+ } while (ea != a->edge);
+}
+
+
+
+void carve::csg::CSG::_generateVertexFaceIntersections(carve::mesh::MeshSet<3>::face_t *fa,
+ carve::mesh::MeshSet<3>::edge_t *eb) {
+ if (intersections.intersects(eb->v1(), fa)) {
+ return;
+ }
+
+ double d1 = carve::geom::distance(fa->plane, eb->v1()->v);
+
+ if (fabs(d1) < carve::EPSILON &&
+ fa->containsPoint(eb->v1()->v)) {
+ intersections.record(eb->v1(), fa, eb->v1());
+ }
+}
+
+
+
+void carve::csg::CSG::generateVertexFaceIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b) {
+ carve::mesh::MeshSet<3>::edge_t *ea, *eb;
+
+ for (size_t i = 0; i < b.size(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *t = b[i];
+ eb = t->edge;
+ do {
+ _generateVertexFaceIntersections(a, eb);
+ eb = eb->next;
+ } while (eb != t->edge);
+ }
+}
+
+
+
+void carve::csg::CSG::_generateEdgeFaceIntersections(carve::mesh::MeshSet<3>::face_t *fa,
+ carve::mesh::MeshSet<3>::edge_t *eb) {
+ if (intersections.intersects(eb, fa)) {
+ return;
+ }
+
+ carve::mesh::MeshSet<3>::vertex_t::vector_t _p;
+ if (fa->simpleLineSegmentIntersection(carve::geom3d::LineSegment(eb->v1()->v, eb->v2()->v), _p)) {
+ carve::mesh::MeshSet<3>::vertex_t *p = vertex_pool.get(_p);
+ intersections.record(eb, fa, p);
+ if (eb->rev) intersections.record(eb->rev, fa, p);
+ }
+}
+
+
+
+void carve::csg::CSG::generateEdgeFaceIntersections(carve::mesh::MeshSet<3>::face_t *a,
+ const std::vector<carve::mesh::MeshSet<3>::face_t *> &b) {
+ carve::mesh::MeshSet<3>::edge_t *ea, *eb;
+
+ for (size_t i = 0; i < b.size(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *t = b[i];
+ eb = t->edge;
+ do {
+ _generateEdgeFaceIntersections(a, eb);
+ eb = eb->next;
+ } while (eb != t->edge);
+ }
+}
+
+
+
+void carve::csg::CSG::generateIntersectionCandidates(carve::mesh::MeshSet<3> *a,
+ const face_rtree_t *a_node,
+ carve::mesh::MeshSet<3> *b,
+ const face_rtree_t *b_node,
+ face_pairs_t &face_pairs,
+ bool descend_a) {
+ if (!a_node->bbox.intersects(b_node->bbox)) {
+ return;
+ }
+
+ if (a_node->child && (descend_a || !b_node->child)) {
+ for (face_rtree_t *node = a_node->child; node; node = node->sibling) {
+ generateIntersectionCandidates(a, node, b, b_node, face_pairs, false);
+ }
+ } else if (b_node->child) {
+ for (face_rtree_t *node = b_node->child; node; node = node->sibling) {
+ generateIntersectionCandidates(a, a_node, b, node, face_pairs, true);
+ }
+ } else {
+ for (size_t i = 0; i < a_node->data.size(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *fa = a_node->data[i];
+ carve::geom::aabb<3> aabb_a = fa->getAABB();
+ if (aabb_a.maxAxisSeparation(b_node->bbox) > carve::EPSILON) continue;
+
+ for (size_t j = 0; j < b_node->data.size(); ++j) {
+ carve::mesh::MeshSet<3>::face_t *fb = b_node->data[j];
+ carve::geom::aabb<3> aabb_b = fb->getAABB();
+ if (aabb_b.maxAxisSeparation(aabb_a) > carve::EPSILON) continue;
+
+ std::pair<double, double> a_ra = fa->rangeInDirection(fa->plane.N, fa->edge->vert->v);
+ std::pair<double, double> b_ra = fb->rangeInDirection(fa->plane.N, fa->edge->vert->v);
+ if (carve::rangeSeparation(a_ra, b_ra) > carve::EPSILON) continue;
+
+ std::pair<double, double> a_rb = fa->rangeInDirection(fb->plane.N, fb->edge->vert->v);
+ std::pair<double, double> b_rb = fb->rangeInDirection(fb->plane.N, fb->edge->vert->v);
+ if (carve::rangeSeparation(a_rb, b_rb) > carve::EPSILON) continue;
+
+ if (!facesAreCoplanar(fa, fb)) {
+ face_pairs[fa].push_back(fb);
+ face_pairs[fb].push_back(fa);
+ }
+ }
+ }
+ }
+}
+
+
+
+
+void carve::csg::CSG::generateIntersections(carve::mesh::MeshSet<3> *a,
+ const face_rtree_t *a_rtree,
+ carve::mesh::MeshSet<3> *b,
+ const face_rtree_t *b_rtree,
+ detail::Data &data) {
+ face_pairs_t face_pairs;
+ generateIntersectionCandidates(a, a_rtree, b, b_rtree, face_pairs);
+
+ for (face_pairs_t::const_iterator i = face_pairs.begin(); i != face_pairs.end(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *f = (*i).first;
+ carve::mesh::MeshSet<3>::edge_t *e = f->edge;
+ do {
+ data.vert_to_edges[e->v1()].push_back(e);
+ e = e->next;
+ } while (e != f->edge);
+ }
+
+ for (face_pairs_t::const_iterator i = face_pairs.begin(); i != face_pairs.end(); ++i) {
+ generateVertexVertexIntersections((*i).first, (*i).second);
+ }
+
+ for (face_pairs_t::const_iterator i = face_pairs.begin(); i != face_pairs.end(); ++i) {
+ generateVertexEdgeIntersections((*i).first, (*i).second);
+ }
+
+ for (face_pairs_t::const_iterator i = face_pairs.begin(); i != face_pairs.end(); ++i) {
+ generateEdgeEdgeIntersections((*i).first, (*i).second);
+ }
+
+ for (face_pairs_t::const_iterator i = face_pairs.begin(); i != face_pairs.end(); ++i) {
+ generateVertexFaceIntersections((*i).first, (*i).second);
+ }
+
+ for (face_pairs_t::const_iterator i = face_pairs.begin(); i != face_pairs.end(); ++i) {
+ generateEdgeFaceIntersections((*i).first, (*i).second);
+ }
+
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "makeVertexIntersections" << std::endl;
+#endif
+ makeVertexIntersections();
+
+#if defined(CARVE_DEBUG)
+ std::cerr << " intersections.size() " << intersections.size() << std::endl;
+ map_histogram(std::cerr, intersections);
+ std::cerr << " vertex_intersections.size() " << vertex_intersections.size() << std::endl;
+ map_histogram(std::cerr, vertex_intersections);
+#endif
+
+#if defined(CARVE_DEBUG) && defined(DEBUG_DRAW_INTERSECTIONS)
+ HOOK(drawIntersections(vertex_intersections););
+#endif
+
+#if defined(CARVE_DEBUG)
+ std::cerr << " intersections.size() " << intersections.size() << std::endl;
+ std::cerr << " vertex_intersections.size() " << vertex_intersections.size() << std::endl;
+#endif
+
+ // notify about intersections.
+ if (hooks.hasHook(Hooks::INTERSECTION_VERTEX_HOOK)) {
+ for (VertexIntersections::const_iterator i = vertex_intersections.begin();
+ i != vertex_intersections.end();
+ ++i) {
+ hooks.intersectionVertex((*i).first, (*i).second);
+ }
+ }
+
+ // from here on, only vertex_intersections is used for intersection
+ // information.
+
+ // intersections still contains the vertex_to_face map. maybe that
+ // should be moved out into another class.
+ static_cast<Intersections::super>(intersections).clear();
+}
+
+
+
+carve::csg::CSG::CSG() {
+}
+
+
+
+/**
+ * \brief For each intersected edge, decompose into a set of vertex pairs representing an ordered set of edge fragments.
+ *
+ * @tparam[in,out] data Internal intersection data. data.emap is used to produce data.divided_edges.
+ */
+void carve::csg::CSG::divideIntersectedEdges(detail::Data &data) {
+ static carve::TimingName FUNC_NAME("CSG::divideIntersectedEdges()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ for (detail::EVSMap::const_iterator i = data.emap.begin(), ei = data.emap.end(); i != ei; ++i) {
+ carve::mesh::MeshSet<3>::edge_t *edge = (*i).first;
+ const detail::EVSMap::mapped_type &vertices = (*i).second;
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &verts = data.divided_edges[edge];
+ orderVertices(vertices.begin(), vertices.end(),
+ edge->v2()->v - edge->v1()->v, edge->v1()->v,
+ verts);
+ }
+}
+
+
+
+carve::csg::CSG::~CSG() {
+}
+
+
+
+void carve::csg::CSG::makeFaceEdges(carve::csg::EdgeClassification &eclass,
+ detail::Data &data) {
+ detail::FSet face_b_set;
+ for (detail::FVSMap::const_iterator
+ i = data.fmap.begin(), ie = data.fmap.end();
+ i != ie;
+ ++i) {
+ carve::mesh::MeshSet<3>::face_t *face_a = (*i).first;
+ const detail::FVSMap::mapped_type &face_a_intersections = ((*i).second);
+ face_b_set.clear();
+
+ // work out the set of faces from the opposing polyhedron that intersect face_a.
+ for (detail::FVSMap::mapped_type::const_iterator
+ j = face_a_intersections.begin(), je = face_a_intersections.end();
+ j != je;
+ ++j) {
+ for (detail::VFSMap::mapped_type::const_iterator
+ k = data.fmap_rev[*j].begin(), ke = data.fmap_rev[*j].end();
+ k != ke;
+ ++k) {
+ carve::mesh::MeshSet<3>::face_t *face_b = (*k);
+ if (face_a != face_b && face_b->mesh->meshset != face_a->mesh->meshset) {
+ face_b_set.insert(face_b);
+ }
+ }
+ }
+
+ // run through each intersecting face.
+ for (detail::FSet::const_iterator
+ j = face_b_set.begin(), je = face_b_set.end();
+ j != je;
+ ++j) {
+ carve::mesh::MeshSet<3>::face_t *face_b = (*j);
+ const detail::FVSMap::mapped_type &face_b_intersections = (data.fmap[face_b]);
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> vertices;
+ vertices.reserve(std::min(face_a_intersections.size(), face_b_intersections.size()));
+
+ // record the points of intersection between face_a and face_b
+ std::set_intersection(face_a_intersections.begin(),
+ face_a_intersections.end(),
+ face_b_intersections.begin(),
+ face_b_intersections.end(),
+ std::back_inserter(vertices));
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "face pair: "
+ << face_a << ":" << face_b
+ << " N(verts) " << vertices.size() << std::endl;
+ for (std::vector<carve::mesh::MeshSet<3>::vertex_t *>::const_iterator i = vertices.begin(), e = vertices.end(); i != e; ++i) {
+ std::cerr << (*i) << " " << (*i)->v << " ("
+ << carve::geom::distance(face_a->plane, (*i)->v) << ","
+ << carve::geom::distance(face_b->plane, (*i)->v) << ")"
+ << std::endl;
+ //CARVE_ASSERT(carve::geom3d::distance(face_a->plane_eqn, *(*i)) < EPSILON);
+ //CARVE_ASSERT(carve::geom3d::distance(face_b->plane_eqn, *(*i)) < EPSILON);
+ }
+#endif
+
+ // if there are two points of intersection, then the added edge is simple to determine.
+ if (vertices.size() == 2) {
+ carve::mesh::MeshSet<3>::vertex_t *v1 = vertices[0];
+ carve::mesh::MeshSet<3>::vertex_t *v2 = vertices[1];
+ carve::geom3d::Vector c = (v1->v + v2->v) / 2;
+
+ // determine whether the midpoint of the implied edge is contained in face_a and face_b
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "face_a->nVertices() = " << face_a->nVertices() << " face_a->containsPointInProjection(c) = " << face_a->containsPointInProjection(c) << std::endl;
+ std::cerr << "face_b->nVertices() = " << face_b->nVertices() << " face_b->containsPointInProjection(c) = " << face_b->containsPointInProjection(c) << std::endl;
+#endif
+
+ if (face_a->containsPointInProjection(c) && face_b->containsPointInProjection(c)) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "adding edge: " << v1 << "-" << v2 << std::endl;
+#if defined(DEBUG_DRAW_FACE_EDGES)
+ HOOK(drawEdge(v1, v2, 1, 1, 1, 1, 1, 1, 1, 1, 2.0););
+#endif
+#endif
+ // record the edge, with class information.
+ if (v1 > v2) std::swap(v1, v2);
+ eclass[ordered_edge(v1, v2)] = carve::csg::EC2(carve::csg::EDGE_ON, carve::csg::EDGE_ON);
+ data.face_split_edges[face_a].insert(std::make_pair(v1, v2));
+ data.face_split_edges[face_b].insert(std::make_pair(v1, v2));
+ }
+ continue;
+ }
+
+ // otherwise, it's more complex.
+ carve::geom3d::Vector base, dir;
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> ordered;
+
+ // skip coplanar edges. this simplifies the resulting
+ // mesh. eventually all coplanar face regions of two polyhedra
+ // must reach a point where they are no longer coplanar (or the
+ // polyhedra are identical).
+ if (!facesAreCoplanar(face_a, face_b)) {
+ // order the intersection vertices (they must lie along a
+ // vector, as the faces aren't coplanar).
+ selectOrderingProjection(vertices.begin(), vertices.end(), dir, base);
+ orderVertices(vertices.begin(), vertices.end(), dir, base, ordered);
+
+ // for each possible edge in the ordering, test the midpoint,
+ // and record if it's contained in face_a and face_b.
+ for (int k = 0, ke = (int)ordered.size() - 1; k < ke; ++k) {
+ carve::mesh::MeshSet<3>::vertex_t *v1 = ordered[k];
+ carve::mesh::MeshSet<3>::vertex_t *v2 = ordered[k + 1];
+ carve::geom3d::Vector c = (v1->v + v2->v) / 2;
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "testing edge: " << v1 << "-" << v2 << " at " << c << std::endl;
+ std::cerr << "a: " << face_a->containsPointInProjection(c) << " b: " << face_b->containsPointInProjection(c) << std::endl;
+ std::cerr << "face_a->containsPointInProjection(c): " << face_a->containsPointInProjection(c) << std::endl;
+ std::cerr << "face_b->containsPointInProjection(c): " << face_b->containsPointInProjection(c) << std::endl;
+#endif
+
+ if (face_a->containsPointInProjection(c) && face_b->containsPointInProjection(c)) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "adding edge: " << v1 << "-" << v2 << std::endl;
+#if defined(DEBUG_DRAW_FACE_EDGES)
+ HOOK(drawEdge(v1, v2, .5, .5, .5, 1, .5, .5, .5, 1, 2.0););
+#endif
+#endif
+ // record the edge, with class information.
+ if (v1 > v2) std::swap(v1, v2);
+ eclass[ordered_edge(v1, v2)] = carve::csg::EC2(carve::csg::EDGE_ON, carve::csg::EDGE_ON);
+ data.face_split_edges[face_a].insert(std::make_pair(v1, v2));
+ data.face_split_edges[face_b].insert(std::make_pair(v1, v2));
+ }
+ }
+ }
+ }
+ }
+
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ {
+ V2Set edges;
+ for (detail::FV2SMap::const_iterator i = data.face_split_edges.begin(); i != data.face_split_edges.end(); ++i) {
+ edges.insert((*i).second.begin(), (*i).second.end());
+ }
+
+ detail::VSet vertices;
+ for (V2Set::const_iterator i = edges.begin(); i != edges.end(); ++i) {
+ vertices.insert((*i).first);
+ vertices.insert((*i).second);
+ }
+
+ carve::line::PolylineSet intersection_graph;
+ intersection_graph.vertices.resize(vertices.size());
+ std::map<const carve::mesh::MeshSet<3>::vertex_t *, size_t> vmap;
+
+ size_t j = 0;
+ for (detail::VSet::const_iterator i = vertices.begin(); i != vertices.end(); ++i) {
+ intersection_graph.vertices[j].v = (*i)->v;
+ vmap[(*i)] = j++;
+ }
+
+ for (V2Set::const_iterator i = edges.begin(); i != edges.end(); ++i) {
+ size_t line[2];
+ line[0] = vmap[(*i).first];
+ line[1] = vmap[(*i).second];
+ intersection_graph.addPolyline(false, line, line + 2);
+ }
+
+ std::string out("/tmp/intersection-edges.ply");
+ ::writePLY(out, &intersection_graph, true);
+ }
+#endif
+}
+
+
+
+/**
+ *
+ *
+ * @param fll
+ */
+static void checkFaceLoopIntegrity(carve::csg::FaceLoopList &fll) {
+ static carve::TimingName FUNC_NAME("CSG::checkFaceLoopIntegrity()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ std::unordered_map<carve::csg::V2, int> counts;
+ for (carve::csg::FaceLoop *fl = fll.head; fl; fl = fl->next) {
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &loop = (fl->vertices);
+ carve::mesh::MeshSet<3>::vertex_t *v1, *v2;
+ v1 = loop[loop.size() - 1];
+ for (unsigned i = 0; i < loop.size(); ++i) {
+ v2 = loop[i];
+ if (v1 < v2) {
+ counts[std::make_pair(v1, v2)]++;
+ } else {
+ counts[std::make_pair(v2, v1)]--;
+ }
+ v1 = v2;
+ }
+ }
+ for (std::unordered_map<carve::csg::V2, int>::const_iterator
+ x = counts.begin(), xe = counts.end(); x != xe; ++x) {
+ if ((*x).second) {
+ std::cerr << "FACE LOOP ERROR: " << (*x).first.first << "-" << (*x).first.second << " : " << (*x).second << std::endl;
+ }
+ }
+}
+
+
+
+/**
+ *
+ *
+ * @param a
+ * @param b
+ * @param vclass
+ * @param eclass
+ * @param a_face_loops
+ * @param b_face_loops
+ * @param a_edge_count
+ * @param b_edge_count
+ * @param hooks
+ */
+void carve::csg::CSG::calc(carve::mesh::MeshSet<3> *a,
+ const face_rtree_t *a_rtree,
+ carve::mesh::MeshSet<3> *b,
+ const face_rtree_t *b_rtree,
+ carve::csg::VertexClassification &vclass,
+ carve::csg::EdgeClassification &eclass,
+ carve::csg::FaceLoopList &a_face_loops,
+ carve::csg::FaceLoopList &b_face_loops,
+ size_t &a_edge_count,
+ size_t &b_edge_count) {
+ detail::Data data;
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "init" << std::endl;
+#endif
+ init();
+
+ generateIntersections(a, a_rtree, b, b_rtree, data);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "intersectingFacePairs" << std::endl;
+#endif
+ intersectingFacePairs(data);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "emap:" << std::endl;
+ map_histogram(std::cerr, data.emap);
+ std::cerr << "fmap:" << std::endl;
+ map_histogram(std::cerr, data.fmap);
+ std::cerr << "fmap_rev:" << std::endl;
+ map_histogram(std::cerr, data.fmap_rev);
+#endif
+
+ // std::cerr << "removeCoplanarFaces" << std::endl;
+ // fp_intersections.removeCoplanarFaces();
+
+#if defined(CARVE_DEBUG) && defined(DEBUG_DRAW_OCTREE)
+ HOOK(drawOctree(a->octree););
+ HOOK(drawOctree(b->octree););
+#endif
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "divideIntersectedEdges" << std::endl;
+#endif
+ divideIntersectedEdges(data);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "makeFaceEdges" << std::endl;
+#endif
+ // makeFaceEdges(data.face_split_edges, eclass, data.fmap, data.fmap_rev);
+ makeFaceEdges(eclass, data);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "generateFaceLoops" << std::endl;
+#endif
+ a_edge_count = generateFaceLoops(a, data, a_face_loops);
+ b_edge_count = generateFaceLoops(b, data, b_face_loops);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "generated " << a_edge_count << " edges for poly a" << std::endl;
+ std::cerr << "generated " << b_edge_count << " edges for poly b" << std::endl;
+#endif
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ {
+ std::string out("/tmp/a_split.ply");
+ writePLY(out, faceLoopsToPolyhedron(a_face_loops), false);
+ }
+ {
+ std::string out("/tmp/b_split.ply");
+ writePLY(out, faceLoopsToPolyhedron(b_face_loops), false);
+ }
+#endif
+
+ checkFaceLoopIntegrity(a_face_loops);
+ checkFaceLoopIntegrity(b_face_loops);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "classify" << std::endl;
+#endif
+ // initialize some classification information.
+ for (std::vector<carve::mesh::MeshSet<3>::vertex_t>::iterator
+ i = a->vertex_storage.begin(), e = a->vertex_storage.end(); i != e; ++i) {
+ vclass[map_vertex(data.vmap, &(*i))].cls[0] = POINT_ON;
+ }
+ for (std::vector<carve::mesh::MeshSet<3>::vertex_t>::iterator
+ i = b->vertex_storage.begin(), e = b->vertex_storage.end(); i != e; ++i) {
+ vclass[map_vertex(data.vmap, &(*i))].cls[1] = POINT_ON;
+ }
+ for (VertexIntersections::const_iterator
+ i = vertex_intersections.begin(), e = vertex_intersections.end(); i != e; ++i) {
+ vclass[(*i).first] = PC2(POINT_ON, POINT_ON);
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << data.divided_edges.size() << " edges are split" << std::endl;
+ std::cerr << data.face_split_edges.size() << " faces are split" << std::endl;
+
+ std::cerr << "poly a: " << a_face_loops.size() << " face loops" << std::endl;
+ std::cerr << "poly b: " << b_face_loops.size() << " face loops" << std::endl;
+#endif
+
+ // std::cerr << "OCTREE A:" << std::endl;
+ // dump_octree_stats(a->octree.root, 0);
+ // std::cerr << "OCTREE B:" << std::endl;
+ // dump_octree_stats(b->octree.root, 0);
+}
+
+
+
+/**
+ *
+ *
+ * @param shared_edges
+ * @param result_list
+ * @param shared_edge_ptr
+ */
+void returnSharedEdges(carve::csg::V2Set &shared_edges,
+ std::list<carve::mesh::MeshSet<3> *> &result_list,
+ carve::csg::V2Set *shared_edge_ptr) {
+ // need to convert shared edges to point into result
+ typedef std::map<carve::geom3d::Vector, carve::mesh::MeshSet<3>::vertex_t *> remap_type;
+ remap_type remap;
+ for (std::list<carve::mesh::MeshSet<3> *>::iterator list_it =
+ result_list.begin(); list_it != result_list.end(); list_it++) {
+ carve::mesh::MeshSet<3> *result = *list_it;
+ if (result) {
+ for (std::vector<carve::mesh::MeshSet<3>::vertex_t>::iterator it =
+ result->vertex_storage.begin(); it != result->vertex_storage.end(); it++) {
+ remap.insert(std::make_pair((*it).v, &(*it)));
+ }
+ }
+ }
+ for (carve::csg::V2Set::iterator it = shared_edges.begin();
+ it != shared_edges.end(); it++) {
+ remap_type::iterator first_it = remap.find(((*it).first)->v);
+ remap_type::iterator second_it = remap.find(((*it).second)->v);
+ CARVE_ASSERT(first_it != remap.end() && second_it != remap.end());
+ shared_edge_ptr->insert(std::make_pair(first_it->second, second_it->second));
+ }
+}
+
+
+
+/**
+ *
+ *
+ * @param a
+ * @param b
+ * @param collector
+ * @param hooks
+ * @param shared_edges_ptr
+ * @param classify_type
+ *
+ * @return
+ */
+carve::mesh::MeshSet<3> *carve::csg::CSG::compute(carve::mesh::MeshSet<3> *a,
+ carve::mesh::MeshSet<3> *b,
+ carve::csg::CSG::Collector &collector,
+ carve::csg::V2Set *shared_edges_ptr,
+ CLASSIFY_TYPE classify_type) {
+ static carve::TimingName FUNC_NAME("CSG::compute");
+ carve::TimingBlock block(FUNC_NAME);
+
+ VertexClassification vclass;
+ EdgeClassification eclass;
+
+ FLGroupList a_loops_grouped;
+ FLGroupList b_loops_grouped;
+
+ FaceLoopList a_face_loops;
+ FaceLoopList b_face_loops;
+
+ size_t a_edge_count;
+ size_t b_edge_count;
+
+ face_rtree_t *a_rtree = face_rtree_t::construct_STR(a->faceBegin(), a->faceEnd(), 4, 4);
+ face_rtree_t *b_rtree = face_rtree_t::construct_STR(b->faceBegin(), b->faceEnd(), 4, 4);
+
+ {
+ static carve::TimingName FUNC_NAME("CSG::compute - calc()");
+ carve::TimingBlock block(FUNC_NAME);
+ calc(a, a_rtree, b, b_rtree, vclass, eclass,a_face_loops, b_face_loops, a_edge_count, b_edge_count);
+ }
+
+ detail::LoopEdges a_edge_map;
+ detail::LoopEdges b_edge_map;
+
+ {
+ static carve::TimingName FUNC_NAME("CSG::compute - makeEdgeMap()");
+ carve::TimingBlock block(FUNC_NAME);
+ makeEdgeMap(a_face_loops, a_edge_count, a_edge_map);
+ makeEdgeMap(b_face_loops, b_edge_count, b_edge_map);
+
+ }
+
+ {
+ static carve::TimingName FUNC_NAME("CSG::compute - sortFaceLoopLists()");
+ carve::TimingBlock block(FUNC_NAME);
+ a_edge_map.sortFaceLoopLists();
+ b_edge_map.sortFaceLoopLists();
+ }
+
+ V2Set shared_edges;
+
+ {
+ static carve::TimingName FUNC_NAME("CSG::compute - findSharedEdges()");
+ carve::TimingBlock block(FUNC_NAME);
+ findSharedEdges(a_edge_map, b_edge_map, shared_edges);
+ }
+
+ {
+ static carve::TimingName FUNC_NAME("CSG::compute - groupFaceLoops()");
+ carve::TimingBlock block(FUNC_NAME);
+ groupFaceLoops(a, a_face_loops, a_edge_map, shared_edges, a_loops_grouped);
+ groupFaceLoops(b, b_face_loops, b_edge_map, shared_edges, b_loops_grouped);
+#if defined(CARVE_DEBUG)
+ std::cerr << "*** a_loops_grouped.size(): " << a_loops_grouped.size() << std::endl;
+ std::cerr << "*** b_loops_grouped.size(): " << b_loops_grouped.size() << std::endl;
+#endif
+ }
+
+#if defined(CARVE_DEBUG) && defined(DEBUG_DRAW_GROUPS)
+ {
+ float n = 1.0 / (a_loops_grouped.size() + b_loops_grouped.size() + 1);
+ float H = 0.0, S = 1.0, V = 1.0;
+ float r, g, b;
+ for (FLGroupList::const_iterator i = a_loops_grouped.begin(); i != a_loops_grouped.end(); ++i) {
+ carve::colour::HSV2RGB(H, S, V, r, g, b); H += n;
+ drawFaceLoopList((*i).face_loops, r, g, b, 1.0, r * .5, g * .5, b * .5, 1.0, true);
+ }
+ for (FLGroupList::const_iterator i = b_loops_grouped.begin(); i != b_loops_grouped.end(); ++i) {
+ carve::colour::HSV2RGB(H, S, V, r, g, b); H += n;
+ drawFaceLoopList((*i).face_loops, r, g, b, 1.0, r * .5, g * .5, b * .5, 1.0, true);
+ }
+
+ for (FLGroupList::const_iterator i = a_loops_grouped.begin(); i != a_loops_grouped.end(); ++i) {
+ drawFaceLoopListWireframe((*i).face_loops);
+ }
+ for (FLGroupList::const_iterator i = b_loops_grouped.begin(); i != b_loops_grouped.end(); ++i) {
+ drawFaceLoopListWireframe((*i).face_loops);
+ }
+ }
+#endif
+
+ switch (classify_type) {
+ case CLASSIFY_EDGE:
+ classifyFaceGroupsEdge(shared_edges,
+ vclass,
+ a,
+ a_rtree,
+ a_loops_grouped,
+ a_edge_map,
+ b,
+ b_rtree,
+ b_loops_grouped,
+ b_edge_map,
+ collector);
+ break;
+ case CLASSIFY_NORMAL:
+ classifyFaceGroups(shared_edges,
+ vclass,
+ a,
+ a_rtree,
+ a_loops_grouped,
+ a_edge_map,
+ b,
+ b_rtree,
+ b_loops_grouped,
+ b_edge_map,
+ collector);
+ break;
+ }
+
+ carve::mesh::MeshSet<3> *result = collector.done(hooks);
+ if (result != NULL && shared_edges_ptr != NULL) {
+ std::list<carve::mesh::MeshSet<3> *> result_list;
+ result_list.push_back(result);
+ returnSharedEdges(shared_edges, result_list, shared_edges_ptr);
+ }
+ return result;
+}
+
+
+
+/**
+ *
+ *
+ * @param a
+ * @param b
+ * @param op
+ * @param hooks
+ * @param shared_edges
+ * @param classify_type
+ *
+ * @return
+ */
+carve::mesh::MeshSet<3> *carve::csg::CSG::compute(carve::mesh::MeshSet<3> *a,
+ carve::mesh::MeshSet<3> *b,
+ carve::csg::CSG::OP op,
+ carve::csg::V2Set *shared_edges,
+ CLASSIFY_TYPE classify_type) {
+ Collector *coll = makeCollector(op, a, b);
+ if (!coll) return NULL;
+
+ carve::mesh::MeshSet<3> *result = compute(a, b, *coll, shared_edges, classify_type);
+
+ delete coll;
+
+ return result;
+}
+
+
+
+/**
+ *
+ *
+ * @param closed
+ * @param open
+ * @param FaceClass
+ * @param result
+ * @param hooks
+ * @param shared_edges_ptr
+ *
+ * @return
+ */
+bool carve::csg::CSG::sliceAndClassify(carve::mesh::MeshSet<3> *closed,
+ carve::mesh::MeshSet<3> *open,
+ std::list<std::pair<FaceClass, carve::mesh::MeshSet<3> *> > &result,
+ carve::csg::V2Set *shared_edges_ptr) {
+ if (!closed->isClosed()) return false;
+ carve::csg::VertexClassification vclass;
+ carve::csg::EdgeClassification eclass;
+
+ carve::csg::FLGroupList a_loops_grouped;
+ carve::csg::FLGroupList b_loops_grouped;
+
+ carve::csg::FaceLoopList a_face_loops;
+ carve::csg::FaceLoopList b_face_loops;
+
+ size_t a_edge_count;
+ size_t b_edge_count;
+
+ face_rtree_t *closed_rtree = face_rtree_t::construct_STR(closed->faceBegin(), closed->faceEnd(), 4, 4);
+ face_rtree_t *open_rtree = face_rtree_t::construct_STR(open->faceBegin(), open->faceEnd(), 4, 4);
+
+ calc(closed, closed_rtree, open, open_rtree, vclass, eclass,a_face_loops, b_face_loops, a_edge_count, b_edge_count);
+
+ detail::LoopEdges a_edge_map;
+ detail::LoopEdges b_edge_map;
+
+ makeEdgeMap(a_face_loops, a_edge_count, a_edge_map);
+ makeEdgeMap(b_face_loops, b_edge_count, b_edge_map);
+
+ carve::csg::V2Set shared_edges;
+
+ findSharedEdges(a_edge_map, b_edge_map, shared_edges);
+
+ groupFaceLoops(closed, a_face_loops, a_edge_map, shared_edges, a_loops_grouped);
+ groupFaceLoops(open, b_face_loops, b_edge_map, shared_edges, b_loops_grouped);
+
+ halfClassifyFaceGroups(shared_edges,
+ vclass,
+ closed,
+ closed_rtree,
+ a_loops_grouped,
+ a_edge_map,
+ open,
+ open_rtree,
+ b_loops_grouped,
+ b_edge_map,
+ result);
+
+ if (shared_edges_ptr != NULL) {
+ std::list<carve::mesh::MeshSet<3> *> result_list;
+ for (std::list<std::pair<FaceClass, carve::mesh::MeshSet<3> *> >::iterator it = result.begin(); it != result.end(); it++) {
+ result_list.push_back(it->second);
+ }
+ returnSharedEdges(shared_edges, result_list, shared_edges_ptr);
+ }
+ return true;
+}
+
+
+
+/**
+ *
+ *
+ * @param a
+ * @param b
+ * @param a_sliced
+ * @param b_sliced
+ * @param hooks
+ * @param shared_edges_ptr
+ */
+void carve::csg::CSG::slice(carve::mesh::MeshSet<3> *a,
+ carve::mesh::MeshSet<3> *b,
+ std::list<carve::mesh::MeshSet<3> *> &a_sliced,
+ std::list<carve::mesh::MeshSet<3> *> &b_sliced,
+ carve::csg::V2Set *shared_edges_ptr) {
+ carve::csg::VertexClassification vclass;
+ carve::csg::EdgeClassification eclass;
+
+ carve::csg::FLGroupList a_loops_grouped;
+ carve::csg::FLGroupList b_loops_grouped;
+
+ carve::csg::FaceLoopList a_face_loops;
+ carve::csg::FaceLoopList b_face_loops;
+
+ size_t a_edge_count;
+ size_t b_edge_count;
+
+ face_rtree_t *a_rtree = face_rtree_t::construct_STR(a->faceBegin(), a->faceEnd(), 4, 4);
+ face_rtree_t *b_rtree = face_rtree_t::construct_STR(b->faceBegin(), b->faceEnd(), 4, 4);
+
+ calc(a, a_rtree, b, b_rtree, vclass, eclass,a_face_loops, b_face_loops, a_edge_count, b_edge_count);
+
+ detail::LoopEdges a_edge_map;
+ detail::LoopEdges b_edge_map;
+
+ makeEdgeMap(a_face_loops, a_edge_count, a_edge_map);
+ makeEdgeMap(b_face_loops, b_edge_count, b_edge_map);
+
+ carve::csg::V2Set shared_edges;
+
+ findSharedEdges(a_edge_map, b_edge_map, shared_edges);
+
+ groupFaceLoops(a, a_face_loops, a_edge_map, shared_edges, a_loops_grouped);
+ groupFaceLoops(b, b_face_loops, b_edge_map, shared_edges, b_loops_grouped);
+
+ for (carve::csg::FLGroupList::iterator
+ i = a_loops_grouped.begin(), e = a_loops_grouped.end();
+ i != e; ++i) {
+ Collector *all = makeCollector(ALL, a, b);
+ all->collect(&*i, hooks);
+ a_sliced.push_back(all->done(hooks));
+
+ delete all;
+ }
+
+ for (carve::csg::FLGroupList::iterator
+ i = b_loops_grouped.begin(), e = b_loops_grouped.end();
+ i != e; ++i) {
+ Collector *all = makeCollector(ALL, a, b);
+ all->collect(&*i, hooks);
+ b_sliced.push_back(all->done(hooks));
+
+ delete all;
+ }
+ if (shared_edges_ptr != NULL) {
+ std::list<carve::mesh::MeshSet<3> *> result_list;
+ result_list.insert(result_list.end(), a_sliced.begin(), a_sliced.end());
+ result_list.insert(result_list.end(), b_sliced.begin(), b_sliced.end());
+ returnSharedEdges(shared_edges, result_list, shared_edges_ptr);
+ }
+}
+
+
+
+/**
+ *
+ *
+ */
+void carve::csg::CSG::init() {
+ intersections.clear();
+ vertex_intersections.clear();
+ vertex_pool.reset();
+}
diff --git a/extern/carve/lib/intersect_classify_common.hpp b/extern/carve/lib/intersect_classify_common.hpp
new file mode 100644
index 00000000000..359c9af0e64
--- /dev/null
+++ b/extern/carve/lib/intersect_classify_common.hpp
@@ -0,0 +1,46 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+#include "intersect_common.hpp"
+
+template<typename T>
+static int is_same(const std::vector<T> &a,
+ const std::vector<T> &b) {
+ if (a.size() != b.size()) return false;
+
+ const size_t S = a.size();
+ size_t i, j, p;
+
+ for (p = 0; p < S; ++p) {
+ if (a[0] == b[p]) break;
+ }
+ if (p == S) return 0;
+
+ for (i = 1, j = p + 1; j < S; ++i, ++j) if (a[i] != b[j]) goto not_fwd;
+ for ( j = 0; i < S; ++i, ++j) if (a[i] != b[j]) goto not_fwd;
+ return +1;
+
+not_fwd:
+ for (i = 1, j = p - 1; j != (size_t)-1; ++i, --j) if (a[i] != b[j]) goto not_rev;
+ for ( j = S - 1; i < S; ++i, --j) if (a[i] != b[j]) goto not_rev;
+ return -1;
+
+not_rev:
+ return 0;
+}
diff --git a/extern/carve/lib/intersect_classify_common_impl.hpp b/extern/carve/lib/intersect_classify_common_impl.hpp
new file mode 100644
index 00000000000..3c141c81151
--- /dev/null
+++ b/extern/carve/lib/intersect_classify_common_impl.hpp
@@ -0,0 +1,362 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+namespace carve {
+ namespace csg {
+ typedef std::unordered_map<
+ carve::mesh::MeshSet<3>::vertex_t *,
+ std::list<FLGroupList::iterator> > GroupLookup;
+
+
+ inline bool isSameFwd(const V2Set &a, const V2Set &b) {
+ if (a.size() != b.size()) return false;
+ for (V2Set::const_iterator i = a.begin(), e = a.end(); i != e; ++i) {
+ if (b.find((*i)) == b.end()) return false;
+ }
+ return true;
+ }
+
+ inline bool isSameRev(const V2Set &a, const V2Set &b) {
+ if (a.size() != b.size()) return false;
+ for (V2Set::const_iterator i = a.begin(), e = a.end(); i != e; ++i) {
+ if (b.find(std::make_pair((*i).second, (*i).first)) == b.end()) return false;
+ }
+ return true;
+ }
+
+
+ static void performClassifySimpleOnFaceGroups(FLGroupList &a_groups,
+ FLGroupList &b_groups,
+ carve::mesh::MeshSet<3> *poly_a,
+ carve::mesh::MeshSet<3> *poly_b,
+ CSG::Collector &collector,
+ CSG::Hooks &hooks) {
+ // Simple ON faces groups are face groups that consist of a single
+ // face, and which have copy in both inputs. These are trivially ON.
+ // This has the side effect of short circuiting the case where the
+ // two inputs share geometry.
+ GroupLookup a_map, b_map;
+
+ // First, hash FaceLoopGroups with one FaceLoop based upon their
+ // minimum vertex pointer - this pointer must be shared between
+ // FaceLoops that this test catches.
+ for (FLGroupList::iterator i = a_groups.begin(); i != a_groups.end(); ++i) {
+ if ((*i).face_loops.size() != 1) continue;
+ FaceLoop *f = (*i).face_loops.head;
+ carve::mesh::MeshSet<3>::vertex_t *v = *std::min_element(f->vertices.begin(), f->vertices.end());
+ a_map[v].push_back(i);
+ }
+
+ for (FLGroupList::iterator i = b_groups.begin(); i != b_groups.end(); ++i) {
+ if ((*i).face_loops.size() != 1) continue;
+ FaceLoop *f = (*i).face_loops.head;
+ carve::mesh::MeshSet<3>::vertex_t *v = *std::min_element(f->vertices.begin(), f->vertices.end());
+ if (a_map.find(v) != a_map.end()) {
+ b_map[v].push_back(i);
+ }
+ }
+
+ // Then, iterate through the FaceLoops hashed in the first map, and
+ // find candidate matches in the second map.
+ for (GroupLookup::iterator j = b_map.begin(), je = b_map.end(); j != je; ++j) {
+ carve::mesh::MeshSet<3>::vertex_t *v = (*j).first;
+ GroupLookup::iterator i = a_map.find(v);
+
+ for (std::list<FLGroupList::iterator>::iterator bi = (*j).second.begin(), be = (*j).second.end(); bi != be;) {
+ FLGroupList::iterator b(*bi);
+ FaceLoop *f_b = (*b).face_loops.head;
+
+ // For each candidate match pair, see if their vertex pointers
+ // are the same, allowing for rotation and inversion.
+ for (std::list<FLGroupList::iterator>::iterator ai = (*i).second.begin(), ae = (*i).second.end(); ai != ae; ++ai) {
+ FLGroupList::iterator a(*ai);
+ FaceLoop *f_a = (*a).face_loops.head;
+
+ int s = is_same(f_a->vertices, f_b->vertices);
+ if (!s) continue;
+
+ // if they are ordered in the same direction, then they are
+ // oriented out, otherwise oriented in.
+ FaceClass fc = s == +1 ? FACE_ON_ORIENT_OUT : FACE_ON_ORIENT_IN;
+
+ (*a).classification.push_back(ClassificationInfo(NULL, fc));
+ (*b).classification.push_back(ClassificationInfo(NULL, fc));
+
+ collector.collect(&*a, hooks);
+ collector.collect(&*b, hooks);
+
+ a_groups.erase(a);
+ b_groups.erase(b);
+
+ (*i).second.erase(ai);
+ bi = (*j).second.erase(bi);
+
+ goto done;
+ }
+ ++bi;
+ done:;
+ }
+ }
+ }
+
+ template <typename CLASSIFIER>
+ static void performClassifyEasyFaceGroups(FLGroupList &group,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ VertexClassification &vclass,
+ const CLASSIFIER &classifier,
+ CSG::Collector &collector,
+ CSG::Hooks &hooks) {
+
+ for (FLGroupList::iterator i = group.begin(); i != group.end();) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "............group " << &(*i) << std::endl;
+#endif
+ FaceLoopGroup &grp = (*i);
+ FaceLoopList &curr = (grp.face_loops);
+ FaceClass fc;
+
+ for (FaceLoop *f = curr.head; f; f = f->next) {
+ for (size_t j = 0; j < f->vertices.size(); ++j) {
+ if (!classifier.pointOn(vclass, f, j)) {
+ PointClass pc = carve::mesh::classifyPoint(poly_a, poly_a_rtree, f->vertices[j]->v);
+ if (pc == POINT_IN || pc == POINT_OUT) {
+ classifier.explain(f, j, pc);
+ }
+ if (pc == POINT_IN) { fc = FACE_IN; goto accept; }
+ if (pc == POINT_OUT) { fc = FACE_OUT; goto accept; }
+ }
+ }
+ }
+ ++i;
+ continue;
+ accept: {
+ grp.classification.push_back(ClassificationInfo(NULL, fc));
+ collector.collect(&grp, hooks);
+ i = group.erase(i);
+ }
+ }
+ }
+
+
+ template <typename CLASSIFIER>
+ static void performClassifyHardFaceGroups(FLGroupList &group,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ const CLASSIFIER & /* classifier */,
+ CSG::Collector &collector,
+ CSG::Hooks &hooks) {
+ for (FLGroupList::iterator
+ i = group.begin(); i != group.end();) {
+ int n_in = 0, n_out = 0, n_on = 0;
+ FaceLoopGroup &grp = (*i);
+ FaceLoopList &curr = (grp.face_loops);
+ V2Set &perim = ((*i).perimeter);
+ FaceClass fc =FACE_UNCLASSIFIED;
+
+ for (FaceLoop *f = curr.head; f; f = f->next) {
+ carve::mesh::MeshSet<3>::vertex_t *v1, *v2;
+ v1 = f->vertices.back();
+ for (size_t j = 0; j < f->vertices.size(); ++j) {
+ v2 = f->vertices[j];
+ if (v1 < v2 && perim.find(std::make_pair(v1, v2)) == perim.end()) {
+ carve::geom3d::Vector c = (v1->v + v2->v) / 2.0;
+
+ PointClass pc = carve::mesh::classifyPoint(poly_a, poly_a_rtree, c);
+
+ switch (pc) {
+ case POINT_IN: n_in++; break;
+ case POINT_OUT: n_out++; break;
+ case POINT_ON: n_on++; break;
+ default: break; // does not happen.
+ }
+ }
+ v1 = v2;
+ }
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << ">>> n_in: " << n_in << " n_on: " << n_on << " n_out: " << n_out << std::endl;
+#endif
+
+ if (!n_in && !n_out) {
+ ++i;
+ continue;
+ }
+
+ if (n_in) fc = FACE_IN;
+ if (n_out) fc = FACE_OUT;
+
+ grp.classification.push_back(ClassificationInfo(NULL, fc));
+ collector.collect(&grp, hooks);
+ i = group.erase(i);
+ }
+ }
+
+ template <typename CLASSIFIER>
+ void performFaceLoopWork(carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ FLGroupList &b_loops_grouped,
+ const CLASSIFIER &classifier,
+ CSG::Collector &collector,
+ CSG::Hooks &hooks) {
+ for (FLGroupList::iterator i = b_loops_grouped.begin(), e = b_loops_grouped.end(); i != e;) {
+ FaceClass fc;
+
+ if (classifier.faceLoopSanityChecker(*i)) {
+ std::cerr << "UNEXPECTED face loop with size != 1." << std::endl;
+ ++i;
+ continue;
+ }
+ CARVE_ASSERT((*i).face_loops.size() == 1);
+
+ FaceLoop *fla = (*i).face_loops.head;
+
+ const carve::mesh::MeshSet<3>::face_t *f = (fla->orig_face);
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &loop = (fla->vertices);
+ std::vector<carve::geom2d::P2> proj;
+ proj.reserve(loop.size());
+ for (unsigned j = 0; j < loop.size(); ++j) {
+ proj.push_back(f->project(loop[j]->v));
+ }
+ carve::geom2d::P2 pv;
+ if (!carve::geom2d::pickContainedPoint(proj, pv)) {
+ CARVE_FAIL("Failed");
+ }
+ carve::geom3d::Vector v = f->unproject(pv, f->plane);
+
+ const carve::mesh::MeshSet<3>::face_t *hit_face;
+ PointClass pc = carve::mesh::classifyPoint(poly_a, poly_a_rtree, v, false, NULL, &hit_face);
+ switch (pc) {
+ case POINT_IN: fc = FACE_IN; break;
+ case POINT_OUT: fc = FACE_OUT; break;
+ case POINT_ON: {
+ double d = carve::geom::distance(hit_face->plane, v);
+#if defined(CARVE_DEBUG)
+ std::cerr << "d = " << d << std::endl;
+#endif
+ fc = d < 0 ? FACE_IN : FACE_OUT;
+ break;
+ }
+ default:
+ CARVE_FAIL("unhandled switch case -- should not happen");
+ }
+#if defined(CARVE_DEBUG)
+ std::cerr << "CLASS: " << (fc == FACE_IN ? "FACE_IN" : "FACE_OUT" ) << std::endl;
+#endif
+
+ (*i).classification.push_back(ClassificationInfo(NULL, fc));
+ collector.collect(&*i, hooks);
+ i = b_loops_grouped.erase(i);
+ }
+
+ }
+
+ template <typename CLASSIFIER>
+ void performClassifyFaceGroups(FLGroupList &a_loops_grouped,
+ FLGroupList &b_loops_grouped,
+ VertexClassification &vclass,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree,
+ const CLASSIFIER &classifier,
+ CSG::Collector &collector,
+ CSG::Hooks &hooks) {
+
+ classifier.classifySimple(a_loops_grouped, b_loops_grouped, vclass, poly_a, poly_b);
+ classifier.classifyEasy(a_loops_grouped, b_loops_grouped, vclass, poly_a, poly_a_rtree, poly_b, poly_b_rtree);
+ classifier.classifyHard(a_loops_grouped, b_loops_grouped, vclass, poly_a, poly_a_rtree, poly_b, poly_b_rtree);
+
+ {
+ GroupLookup a_map;
+ FLGroupList::iterator i, j;
+ FaceClass fc;
+
+ for (i = a_loops_grouped.begin(); i != a_loops_grouped.end(); ++i) {
+ V2Set::iterator it_end = (*i).perimeter.end();
+ V2Set::iterator it_begin = (*i).perimeter.begin();
+
+ if(it_begin != it_end) {
+ a_map[std::min_element(it_begin, it_end)->first].push_back(i);
+ }
+ }
+
+ for (i = b_loops_grouped.begin(); i != b_loops_grouped.end();) {
+ GroupLookup::iterator a = a_map.end();
+
+ V2Set::iterator it_end = (*i).perimeter.end();
+ V2Set::iterator it_begin = (*i).perimeter.begin();
+
+ if(it_begin != it_end) {
+ a = a_map.find(std::min_element(it_begin, it_end)->first);
+ }
+
+ if (a == a_map.end()) { ++i; continue; }
+
+ for (std::list<FLGroupList::iterator>::iterator ji = (*a).second.begin(), je = (*a).second.end(); ji != je; ++ji) {
+ j = (*ji);
+ if (isSameFwd((*i).perimeter, (*j).perimeter)) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "SAME FWD PAIR" << std::endl;
+#endif
+ fc = FACE_ON_ORIENT_OUT;
+ goto face_pair;
+ } else if (isSameRev((*i).perimeter, (*j).perimeter)) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "SAME REV PAIR" << std::endl;
+#endif
+ fc = FACE_ON_ORIENT_IN;
+ goto face_pair;
+ }
+ }
+ ++i;
+ continue;
+
+ face_pair: {
+ V2Set::iterator it_end = (*j).perimeter.end();
+ V2Set::iterator it_begin = (*j).perimeter.begin();
+
+ if(it_begin != it_end) {
+ a_map[std::min_element(it_begin, it_end)->first].remove(j);
+ }
+
+ (*i).classification.push_back(ClassificationInfo(NULL, fc));
+ (*j).classification.push_back(ClassificationInfo(NULL, fc));
+
+ collector.collect(&*i, hooks);
+ collector.collect(&*j, hooks);
+
+ j = a_loops_grouped.erase(j);
+ i = b_loops_grouped.erase(i);
+ }
+ }
+ }
+
+ // XXX: this may leave some face groups that are IN or OUT, and
+ // consist of a single face loop.
+ classifier.postRemovalCheck(a_loops_grouped, b_loops_grouped);
+
+ classifier.faceLoopWork(a_loops_grouped, b_loops_grouped, vclass, poly_a, poly_a_rtree, poly_b, poly_b_rtree);
+
+ classifier.finish(a_loops_grouped, b_loops_grouped);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/intersect_classify_edge.cpp b/extern/carve/lib/intersect_classify_edge.cpp
new file mode 100644
index 00000000000..d2c1fdd7c24
--- /dev/null
+++ b/extern/carve/lib/intersect_classify_edge.cpp
@@ -0,0 +1,820 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#if defined(HAVE_STDINT_H)
+#include <stdint.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/debug_hooks.hpp>
+#include <carve/colour.hpp>
+
+#include <list>
+#include <set>
+#include <iostream>
+
+#include <algorithm>
+
+#include "csg_detail.hpp"
+
+#include "intersect_common.hpp"
+#include "intersect_classify_common.hpp"
+
+#define ANGLE_EPSILON 1e-6
+
+namespace carve {
+ namespace csg {
+
+ namespace {
+
+ inline bool single_bit_set(uint32_t v) {
+ v &= v - 1;
+ return v == 0;
+ }
+
+ struct EdgeSurface {
+ FaceLoop *fwd;
+ double fwd_ang;
+ FaceLoop *rev;
+ double rev_ang;
+
+ EdgeSurface() : fwd(NULL), fwd_ang(0.0), rev(NULL), rev_ang(0.0) { }
+ };
+
+
+ typedef std::map<const carve::mesh::MeshSet<3>::mesh_t *, EdgeSurface> GrpEdgeSurfMap;
+
+ typedef std::pair<FaceLoopGroup *, const carve::mesh::MeshSet<3>::mesh_t *> ClassificationKey;
+
+ struct ClassificationData {
+ uint32_t class_bits : 5;
+ uint32_t class_decided : 1;
+
+ int c[5];
+
+ ClassificationData() {
+ class_bits = FACE_ANY_BIT;
+ class_decided = 0;
+ memset(c, 0, sizeof(c));
+ }
+ };
+
+ struct hash_classification {
+ size_t operator()(const ClassificationKey &f) const {
+ return (size_t)f.first ^ (size_t)f.second;
+ }
+ };
+
+ typedef std::unordered_map<ClassificationKey, ClassificationData, hash_classification> Classification;
+
+
+ struct hash_group_ptr {
+ size_t operator()(const FaceLoopGroup * const &f) const {
+ return (size_t)f;
+ }
+ };
+
+
+ typedef std::pair<size_t, const carve::mesh::MeshSet<3>::vertex_t *> PerimKey;
+
+ struct hash_perim_key {
+ size_t operator()(const PerimKey &v) const {
+ return (size_t)v.first ^ (size_t)v.second;
+ }
+ };
+
+ typedef std::unordered_map<std::pair<size_t, const carve::mesh::MeshSet<3>::vertex_t *>,
+ std::unordered_set<FaceLoopGroup *, hash_group_ptr>,
+ hash_perim_key> PerimMap;
+
+
+
+ struct hash_group_pair {
+ size_t operator()(const std::pair<int, const FaceLoopGroup *> &v) const {
+ return (size_t)v.first ^ (size_t)v.second;
+ }
+ };
+
+ typedef std::unordered_map<const FaceLoopGroup *,
+ std::unordered_set<std::pair<int, const FaceLoopGroup *>, hash_group_pair>,
+ hash_group_ptr> CandidateOnMap;
+
+
+
+ static inline void remove(carve::mesh::MeshSet<3>::vertex_t *a,
+ carve::mesh::MeshSet<3>::vertex_t *b,
+ carve::csg::detail::VVSMap &shared_edge_graph) {
+ carve::csg::detail::VVSMap::iterator i = shared_edge_graph.find(a);
+ CARVE_ASSERT(i != shared_edge_graph.end());
+ size_t n = (*i).second.erase(b);
+ CARVE_ASSERT(n == 1);
+ if ((*i).second.size() == 0) shared_edge_graph.erase(i);
+ }
+
+
+
+ static inline void remove(V2 edge,
+ carve::csg::detail::VVSMap &shared_edge_graph) {
+ remove(edge.first, edge.second, shared_edge_graph);
+ remove(edge.second, edge.first, shared_edge_graph);
+ }
+
+
+
+ static void walkGraphSegment(carve::csg::detail::VVSMap &shared_edge_graph,
+ const carve::csg::detail::VSet &branch_points,
+ V2 initial,
+ const carve::csg::detail::LoopEdges & /* a_edge_map */,
+ const carve::csg::detail::LoopEdges & /* b_edge_map */,
+ std::list<V2> &out) {
+ V2 curr;
+ curr = initial;
+ bool closed = false;
+
+ out.clear();
+ for (;;) {
+ // walk forward.
+ out.push_back(curr);
+ remove(curr, shared_edge_graph);
+
+ if (curr.second == initial.first) { closed = true; break; }
+ if (branch_points.find(curr.second) != branch_points.end()) break;
+ carve::csg::detail::VVSMap::const_iterator o = shared_edge_graph.find(curr.second);
+ if (o == shared_edge_graph.end()) break;
+ CARVE_ASSERT((*o).second.size() == 1);
+ curr.first = curr.second;
+ curr.second = *((*o).second.begin());
+ // test here that the set of incident groups hasn't changed.
+ }
+
+ if (!closed) {
+ // walk backward.
+ curr = initial;
+ for (;;) {
+ if (branch_points.find(curr.first) != branch_points.end()) break;
+ carve::csg::detail::VVSMap::const_iterator o = shared_edge_graph.find(curr.first);
+ if (o == shared_edge_graph.end()) break;
+ curr.second = curr.first;
+ curr.first = *((*o).second.begin());
+ // test here that the set of incident groups hasn't changed.
+
+ out.push_front(curr);
+ remove(curr, shared_edge_graph);
+ }
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "intersection segment: " << out.size() << " edges." << std::endl;
+#if defined(DEBUG_DRAW_INTERSECTION_LINE)
+ {
+ static float H = 0.0, S = 1.0, V = 1.0;
+ float r, g, b;
+
+ H = fmod((H + .37), 1.0);
+ S = 0.5 + fmod((S - 0.37), 0.5);
+ carve::colour::HSV2RGB(H, S, V, r, g, b);
+
+ if (out.size() > 1) {
+ drawEdges(out.begin(), ++out.begin(),
+ 0.0, 0.0, 0.0, 1.0,
+ r, g, b, 1.0,
+ 3.0);
+ drawEdges(++out.begin(), --out.end(),
+ r, g, b, 1.0,
+ r, g, b, 1.0,
+ 3.0);
+ drawEdges(--out.end(), out.end(),
+ r, g, b, 1.0,
+ 1.0, 1.0, 1.0, 1.0,
+ 3.0);
+ } else {
+ drawEdges(out.begin(), out.end(),
+ r, g, b, 1.0,
+ r, g, b, 1.0,
+ 3.0);
+ }
+ }
+#endif
+#endif
+ }
+
+
+
+ static carve::geom3d::Vector perpendicular(const carve::geom3d::Vector &v) {
+ if (fabs(v.x) < fabs(v.y)) {
+ if (fabs(v.x) < fabs(v.z)) {
+ return cross(v, carve::geom::VECTOR(1.0, 0.0, 0.0)).normalized();
+ } else {
+ return cross(v, carve::geom::VECTOR(0.0, 0.0, 1.0)).normalized();
+ }
+ } else {
+ if (fabs(v.y) < fabs(v.z)) {
+ return cross(v, carve::geom::VECTOR(0.0, 1.0, 0.0)).normalized();
+ } else {
+ return cross(v, carve::geom::VECTOR(1.0, 0.0, 1.0)).normalized();
+ }
+ }
+ }
+
+
+
+ static void classifyAB(const GrpEdgeSurfMap &a_edge_surfaces,
+ const GrpEdgeSurfMap &b_edge_surfaces,
+ Classification &classifications) {
+ // two faces in the a surface
+ for (GrpEdgeSurfMap::const_iterator ib = b_edge_surfaces.begin(), eb = b_edge_surfaces.end(); ib != eb; ++ib) {
+
+ if ((*ib).second.fwd) {
+ FaceLoopGroup *b_grp = ((*ib).second.fwd->group);
+
+ for (GrpEdgeSurfMap::const_iterator ia = a_edge_surfaces.begin(), ea = a_edge_surfaces.end(); ia != ea; ++ia) {
+
+ if ((*ia).second.fwd && (*ia).second.rev) {
+ const carve::mesh::MeshSet<3>::mesh_t *a_gid = (*ia).first;
+
+ ClassificationData &data = classifications[std::make_pair(b_grp, a_gid)];
+ if (data.class_decided) continue;
+
+ // an angle between (*ia).fwd_ang and (*ia).rev_ang is outside/above group a.
+ FaceClass fc;
+
+ if (fabs((*ib).second.fwd_ang - (*ia).second.fwd_ang) < ANGLE_EPSILON) {
+ fc = FACE_ON_ORIENT_OUT;
+ } else if (fabs((*ib).second.fwd_ang - (*ia).second.rev_ang) < ANGLE_EPSILON) {
+ fc = FACE_ON_ORIENT_IN;
+ } else {
+ double a1 = (*ia).second.fwd_ang;
+ double a2 = (*ia).second.rev_ang;
+ if (a1 < a2) {
+ if (a1 < (*ib).second.fwd_ang && (*ib).second.fwd_ang < a2) {
+ fc = FACE_IN;
+ } else {
+ fc = FACE_OUT;
+ }
+ } else {
+ if (a2 < (*ib).second.fwd_ang && (*ib).second.fwd_ang < a1) {
+ fc = FACE_OUT;
+ } else {
+ fc = FACE_IN;
+ }
+ }
+ }
+ data.c[fc + 2]++;
+ }
+ }
+ }
+
+ if ((*ib).second.rev) {
+ FaceLoopGroup *b_grp = ((*ib).second.rev->group);
+
+ for (GrpEdgeSurfMap::const_iterator ia = a_edge_surfaces.begin(), ea = a_edge_surfaces.end(); ia != ea; ++ia) {
+
+ if ((*ia).second.fwd && (*ia).second.rev) {
+ const carve::mesh::MeshSet<3>::mesh_t *a_gid = (*ia).first;
+
+ ClassificationData &data = (classifications[std::make_pair(b_grp, a_gid)]);
+ if (data.class_decided) continue;
+
+ // an angle between (*ia).fwd_ang and (*ia).rev_ang is outside/above group a.
+ FaceClass fc;
+
+ if (fabs((*ib).second.rev_ang - (*ia).second.fwd_ang) < ANGLE_EPSILON) {
+ fc = FACE_ON_ORIENT_IN;
+ } else if (fabs((*ib).second.rev_ang - (*ia).second.rev_ang) < ANGLE_EPSILON) {
+ fc = FACE_ON_ORIENT_OUT;
+ } else {
+ double a1 = (*ia).second.fwd_ang;
+ double a2 = (*ia).second.rev_ang;
+ if (a1 < a2) {
+ if (a1 < (*ib).second.rev_ang && (*ib).second.rev_ang < a2) {
+ fc = FACE_IN;
+ } else {
+ fc = FACE_OUT;
+ }
+ } else {
+ if (a2 < (*ib).second.rev_ang && (*ib).second.rev_ang < a1) {
+ fc = FACE_OUT;
+ } else {
+ fc = FACE_IN;
+ }
+ }
+ }
+ data.c[fc + 2]++;
+ }
+ }
+ }
+ }
+ }
+
+
+ static bool processForwardEdgeSurfaces(GrpEdgeSurfMap &edge_surfaces,
+ const std::list<FaceLoop *> &fwd,
+ const carve::geom3d::Vector &edge_vector,
+ const carve::geom3d::Vector &base_vector) {
+ for (std::list<FaceLoop *>::const_iterator i = fwd.begin(), e = fwd.end(); i != e; ++i) {
+ EdgeSurface &es = (edge_surfaces[(*i)->orig_face->mesh]);
+ if (es.fwd != NULL) return false;
+ es.fwd = (*i);
+ es.fwd_ang = carve::geom3d::antiClockwiseAngle((*i)->orig_face->plane.N, base_vector, edge_vector);
+ }
+ return true;
+ }
+
+ static bool processReverseEdgeSurfaces(GrpEdgeSurfMap &edge_surfaces,
+ const std::list<FaceLoop *> &rev,
+ const carve::geom3d::Vector &edge_vector,
+ const carve::geom3d::Vector &base_vector) {
+ for (std::list<FaceLoop *>::const_iterator i = rev.begin(), e = rev.end(); i != e; ++i) {
+ EdgeSurface &es = (edge_surfaces[(*i)->orig_face->mesh]);
+ if (es.rev != NULL) return false;
+ es.rev = (*i);
+ es.rev_ang = carve::geom3d::antiClockwiseAngle(-(*i)->orig_face->plane.N, base_vector, edge_vector);
+ }
+ return true;
+ }
+
+
+
+ static void processOneEdge(const V2 &edge,
+ const carve::csg::detail::LoopEdges &a_edge_map,
+ const carve::csg::detail::LoopEdges &b_edge_map,
+ Classification &a_classification,
+ Classification &b_classification) {
+ GrpEdgeSurfMap a_edge_surfaces;
+ GrpEdgeSurfMap b_edge_surfaces;
+
+ carve::geom3d::Vector edge_vector = (edge.second->v - edge.first->v).normalized();
+ carve::geom3d::Vector base_vector = perpendicular(edge_vector);
+
+ carve::csg::detail::LoopEdges::const_iterator ae_f = a_edge_map.find(edge);
+ carve::csg::detail::LoopEdges::const_iterator ae_r = a_edge_map.find(flip(edge));
+ CARVE_ASSERT(ae_f != a_edge_map.end() || ae_r != a_edge_map.end());
+
+ carve::csg::detail::LoopEdges::const_iterator be_f = b_edge_map.find(edge);
+ carve::csg::detail::LoopEdges::const_iterator be_r = b_edge_map.find(flip(edge));
+ CARVE_ASSERT(be_f != b_edge_map.end() || be_r != b_edge_map.end());
+
+ if (ae_f != a_edge_map.end() && !processForwardEdgeSurfaces(a_edge_surfaces, (*ae_f).second, edge_vector, base_vector)) return;
+ if (ae_r != a_edge_map.end() && !processReverseEdgeSurfaces(a_edge_surfaces, (*ae_r).second, edge_vector, base_vector)) return;
+ if (be_f != b_edge_map.end() && !processForwardEdgeSurfaces(b_edge_surfaces, (*be_f).second, edge_vector, base_vector)) return;
+ if (be_r != b_edge_map.end() && !processReverseEdgeSurfaces(b_edge_surfaces, (*be_r).second, edge_vector, base_vector)) return;
+
+ classifyAB(a_edge_surfaces, b_edge_surfaces, b_classification);
+ classifyAB(b_edge_surfaces, a_edge_surfaces, a_classification);
+ }
+
+
+
+ static void traceIntersectionGraph(const V2Set &shared_edges,
+ const FLGroupList & /* a_loops_grouped */,
+ const FLGroupList & /* b_loops_grouped */,
+ const carve::csg::detail::LoopEdges &a_edge_map,
+ const carve::csg::detail::LoopEdges &b_edge_map) {
+
+ carve::csg::detail::VVSMap shared_edge_graph;
+ carve::csg::detail::VSet branch_points;
+
+ // first, make the intersection graph.
+ for (V2Set::const_iterator i = shared_edges.begin(); i != shared_edges.end(); ++i) {
+ const V2Set::key_type &edge = (*i);
+ carve::csg::detail::VVSMap::mapped_type &out = (shared_edge_graph[edge.first]);
+ out.insert(edge.second);
+ if (out.size() == 3) branch_points.insert(edge.first);
+
+#if defined(CARVE_DEBUG) && defined(DEBUG_DRAW_INTERSECTION_LINE)
+ HOOK(drawEdge(edge.first, edge.second, 1, 1, 1, 1, 1, 1, 1, 1, 1.0););
+#endif
+ }
+#if defined(CARVE_DEBUG)
+ std::cerr << "graph nodes: " << shared_edge_graph.size() << std::endl;
+ std::cerr << "branch nodes: " << branch_points.size() << std::endl;
+#endif
+
+ std::list<V2> out;
+ while (shared_edge_graph.size()) {
+ carve::csg::detail::VVSMap::iterator i = shared_edge_graph.begin();
+ carve::mesh::MeshSet<3>::vertex_t *v1 = (*i).first;
+ carve::mesh::MeshSet<3>::vertex_t *v2 = *((*i).second.begin());
+ walkGraphSegment(shared_edge_graph, branch_points, V2(v1, v2), a_edge_map, b_edge_map, out);
+ }
+ }
+
+ void hashByPerimeter(FLGroupList &grp, PerimMap &perim_map) {
+ for (FLGroupList::iterator i = grp.begin(); i != grp.end(); ++i) {
+ size_t perim_size = (*i).perimeter.size();
+ // can be the case for non intersecting groups. (and groups that intersect at a point?)
+ if (!perim_size) continue;
+ const carve::mesh::MeshSet<3>::vertex_t *perim_min = std::min_element((*i).perimeter.begin(), (*i).perimeter.end())->first;
+ perim_map[std::make_pair(perim_size, perim_min)].insert(&(*i));
+ }
+ }
+
+
+
+ bool same_edge_set_fwd(const V2Set &a, const V2Set &b) {
+ if (a.size() != b.size()) return false;
+ for (V2Set::const_iterator i = a.begin(), e = a.end(); i != e; ++i) {
+ if (b.find(*i) == b.end()) return false;
+ }
+ return true;
+ }
+
+
+
+ bool same_edge_set_rev(const V2Set &a, const V2Set &b) {
+ if (a.size() != b.size()) return false;
+ for (V2Set::const_iterator i = a.begin(), e = a.end(); i != e; ++i) {
+ if (b.find(std::make_pair((*i).second, (*i).first)) == b.end()) return false;
+ }
+ return true;
+ }
+
+
+
+ int same_edge_set(const V2Set &a, const V2Set &b) {
+ if (same_edge_set_fwd(a, b)) return +1;
+ if (same_edge_set_rev(a, b)) return -1;
+ return 0;
+ }
+
+
+
+ void generateCandidateOnSets(FLGroupList &a_grp,
+ FLGroupList &b_grp,
+ CandidateOnMap &candidate_on_map,
+ Classification &a_classification,
+ Classification &b_classification) {
+ PerimMap a_grp_by_perim, b_grp_by_perim;
+
+ hashByPerimeter(a_grp, a_grp_by_perim);
+ hashByPerimeter(b_grp, b_grp_by_perim);
+
+ for (PerimMap::iterator i = a_grp_by_perim.begin(), ie = a_grp_by_perim.end(); i != ie; ++i) {
+ PerimMap::iterator j = b_grp_by_perim.find((*i).first);
+ if (j == b_grp_by_perim.end()) continue;
+
+ for (PerimMap::mapped_type::iterator a = (*i).second.begin(), ae = (*i).second.end(); a != ae; ++a) {
+ for (PerimMap::mapped_type::iterator b = (*j).second.begin(), be = (*j).second.end(); b != be; ++b) {
+ int x = same_edge_set((*a)->perimeter, (*b)->perimeter);
+ if (!x) continue;
+ candidate_on_map[(*a)].insert(std::make_pair(x, (*b)));
+ if ((*a)->face_loops.count == 1 && (*b)->face_loops.count == 1) {
+ uint32_t fcb = x == +1 ? FACE_ON_ORIENT_OUT_BIT : FACE_ON_ORIENT_IN_BIT;
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "paired groups: " << (*a) << ", " << (*b) << std::endl;
+#endif
+
+ ClassificationData &a_data = a_classification[std::make_pair((*a), (*b)->face_loops.head->orig_face->mesh)];
+ a_data.class_bits = fcb; a_data.class_decided = 1;
+
+ ClassificationData &b_data = b_classification[std::make_pair((*b), (*a)->face_loops.head->orig_face->mesh)];
+ b_data.class_bits = fcb; b_data.class_decided = 1;
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+
+ static inline std::string CODE(const FaceLoopGroup *grp) {
+ const std::list<ClassificationInfo> &cinfo = (grp->classification);
+ if (cinfo.size() == 0) {
+ return "?";
+ }
+
+ FaceClass fc = FACE_UNCLASSIFIED;
+
+ for (std::list<ClassificationInfo>::const_iterator i = grp->classification.begin(), e = grp->classification.end(); i != e; ++i) {
+ if ((*i).intersected_mesh == NULL) {
+ // classifier only returns global info
+ fc = (*i).classification;
+ break;
+ }
+
+ if ((*i).intersectedMeshIsClosed()) {
+ if ((*i).classification == FACE_UNCLASSIFIED) continue;
+ if (fc == FACE_UNCLASSIFIED) {
+ fc = (*i).classification;
+ } else if (fc != (*i).classification) {
+ return "X";
+ }
+ }
+ }
+ if (fc == FACE_IN) return "I";
+ if (fc == FACE_ON_ORIENT_IN) return "<";
+ if (fc == FACE_ON_ORIENT_OUT) return ">";
+ if (fc == FACE_OUT) return "O";
+ return "*";
+ }
+
+ void CSG::classifyFaceGroupsEdge(const V2Set &shared_edges,
+ VertexClassification &vclass,
+ carve::mesh::MeshSet<3> *poly_a,
+ const face_rtree_t *poly_a_rtree,
+ FLGroupList &a_loops_grouped,
+ const detail::LoopEdges &a_edge_map,
+ carve::mesh::MeshSet<3> *poly_b,
+ const face_rtree_t *poly_b_rtree,
+ FLGroupList &b_loops_grouped,
+ const detail::LoopEdges &b_edge_map,
+ CSG::Collector &collector) {
+ Classification a_classification;
+ Classification b_classification;
+
+ CandidateOnMap candidate_on_map;
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "a input loops (" << a_loops_grouped.size() << "): ";
+ for (FLGroupList::iterator i = a_loops_grouped.begin(); i != a_loops_grouped.end(); ++i) {
+ std::cerr << &*i << " ";
+ }
+ std::cerr << std::endl;
+ std::cerr << "b input loops (" << b_loops_grouped.size() << "): ";
+ for (FLGroupList::iterator i = b_loops_grouped.begin(); i != b_loops_grouped.end(); ++i) {
+ std::cerr << &*i << " ";
+ }
+ std::cerr << std::endl;
+#endif
+
+#if defined(DISPLAY_GRP_GRAPH)
+ // XXX: this is hopelessly inefficient.
+ std::map<const FaceLoopGroup *, std::set<const FaceLoopGroup *> > grp_graph_fwd, grp_graph_rev;
+ {
+ for (FLGroupList::iterator i = a_loops_grouped.begin(); i != a_loops_grouped.end(); ++i) {
+ FaceLoopGroup *src = &(*i);
+ for (V2Set::const_iterator k = src->perimeter.begin(); k != src->perimeter.end(); ++k) {
+ V2 fwd = *k;
+ V2 rev = std::make_pair(fwd.second, fwd.first);
+ for (FLGroupList::iterator j = a_loops_grouped.begin(); j != a_loops_grouped.end(); ++j) {
+ FaceLoopGroup *tgt = &(*j);
+ if (tgt->perimeter.find(fwd) != tgt->perimeter.end()) { grp_graph_fwd[src].insert(tgt); }
+ if (tgt->perimeter.find(rev) != tgt->perimeter.end()) { grp_graph_rev[src].insert(tgt); }
+ }
+ for (FLGroupList::iterator j = b_loops_grouped.begin(); j != b_loops_grouped.end(); ++j) {
+ FaceLoopGroup *tgt = &(*j);
+ if (tgt->perimeter.find(fwd) != tgt->perimeter.end()) { grp_graph_fwd[src].insert(tgt); }
+ if (tgt->perimeter.find(rev) != tgt->perimeter.end()) { grp_graph_rev[src].insert(tgt); }
+ }
+ }
+ }
+ for (FLGroupList::iterator i = b_loops_grouped.begin(); i != b_loops_grouped.end(); ++i) {
+ FaceLoopGroup *src = &(*i);
+ for (V2Set::const_iterator k = src->perimeter.begin(); k != src->perimeter.end(); ++k) {
+ V2 fwd = *k;
+ V2 rev = std::make_pair(fwd.second, fwd.first);
+ for (FLGroupList::iterator j = a_loops_grouped.begin(); j != a_loops_grouped.end(); ++j) {
+ FaceLoopGroup *tgt = &(*j);
+ if (tgt->perimeter.find(fwd) != tgt->perimeter.end()) { grp_graph_fwd[src].insert(tgt); }
+ if (tgt->perimeter.find(rev) != tgt->perimeter.end()) { grp_graph_rev[src].insert(tgt); }
+ }
+ for (FLGroupList::iterator j = b_loops_grouped.begin(); j != b_loops_grouped.end(); ++j) {
+ FaceLoopGroup *tgt = &(*j);
+ if (tgt->perimeter.find(fwd) != tgt->perimeter.end()) { grp_graph_fwd[src].insert(tgt); }
+ if (tgt->perimeter.find(rev) != tgt->perimeter.end()) { grp_graph_rev[src].insert(tgt); }
+ }
+ }
+ }
+ }
+#endif
+
+ generateCandidateOnSets(a_loops_grouped, b_loops_grouped, candidate_on_map, a_classification, b_classification);
+
+
+ for (V2Set::const_iterator i = shared_edges.begin(); i != shared_edges.end(); ++i) {
+ const V2 &edge = (*i);
+ processOneEdge(edge, a_edge_map, b_edge_map, a_classification, b_classification);
+ }
+
+
+ for (Classification::iterator i = a_classification.begin(), e = a_classification.end(); i != e; ++i) {
+ if (!(*i).second.class_decided) {
+ if ((*i).second.c[FACE_IN + 2] == 0) (*i).second.class_bits &= ~ FACE_IN_BIT;
+ if ((*i).second.c[FACE_ON_ORIENT_IN + 2] == 0) (*i).second.class_bits &= ~ FACE_ON_ORIENT_IN_BIT;
+ if ((*i).second.c[FACE_ON_ORIENT_OUT + 2] == 0) (*i).second.class_bits &= ~ FACE_ON_ORIENT_OUT_BIT;
+ if ((*i).second.c[FACE_OUT + 2] == 0) (*i).second.class_bits &= ~ FACE_OUT_BIT;
+
+ // XXX: this is the wrong thing to do. It's intended just as a test.
+ if ((*i).second.class_bits == (FACE_IN_BIT | FACE_OUT_BIT)) {
+ if ((*i).second.c[FACE_OUT + 2] > (*i).second.c[FACE_IN + 2]) {
+ (*i).second.class_bits = FACE_OUT_BIT;
+ } else {
+ (*i).second.class_bits = FACE_IN_BIT;
+ }
+ }
+
+ if (single_bit_set((*i).second.class_bits)) (*i).second.class_decided = 1;
+ }
+ }
+
+ for (Classification::iterator i = b_classification.begin(), e = b_classification.end(); i != e; ++i) {
+ if (!(*i).second.class_decided) {
+ if ((*i).second.c[FACE_IN + 2] == 0) (*i).second.class_bits &= ~ FACE_IN_BIT;
+ if ((*i).second.c[FACE_ON_ORIENT_IN + 2] == 0) (*i).second.class_bits &= ~ FACE_ON_ORIENT_IN_BIT;
+ if ((*i).second.c[FACE_ON_ORIENT_OUT + 2] == 0) (*i).second.class_bits &= ~ FACE_ON_ORIENT_OUT_BIT;
+ if ((*i).second.c[FACE_OUT + 2] == 0) (*i).second.class_bits &= ~ FACE_OUT_BIT;
+
+ // XXX: this is the wrong thing to do. It's intended just as a test.
+ if ((*i).second.class_bits == (FACE_IN_BIT | FACE_OUT_BIT)) {
+ if ((*i).second.c[FACE_OUT + 2] > (*i).second.c[FACE_IN + 2]) {
+ (*i).second.class_bits = FACE_OUT_BIT;
+ } else {
+ (*i).second.class_bits = FACE_IN_BIT;
+ }
+ }
+
+ if (single_bit_set((*i).second.class_bits)) (*i).second.class_decided = 1;
+ }
+ }
+
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "poly a:" << std::endl;
+ for (Classification::iterator i = a_classification.begin(), e = a_classification.end(); i != e; ++i) {
+ FaceLoopGroup *grp = ((*i).first.first);
+
+ std::cerr << " group: " << grp << " gid: " << (*i).first.second
+ << " "
+ << ((*i).second.class_decided ? "+" : "-")
+ << " "
+ << ((*i).second.class_bits & FACE_IN_BIT ? "I" : ".")
+ << ((*i).second.class_bits & FACE_ON_ORIENT_IN_BIT ? "<" : ".")
+ << ((*i).second.class_bits & FACE_ON_ORIENT_OUT_BIT ? ">" : ".")
+ << ((*i).second.class_bits & FACE_OUT_BIT ? "O" : ".")
+ << " ["
+ << std::setw(4) << (*i).second.c[0] << " "
+ << std::setw(4) << (*i).second.c[1] << " "
+ << std::setw(4) << (*i).second.c[2] << " "
+ << std::setw(4) << (*i).second.c[3] << " "
+ << std::setw(4) << (*i).second.c[4] << "]" << std::endl;
+ }
+
+ std::cerr << "poly b:" << std::endl;
+ for (Classification::iterator i = b_classification.begin(), e = b_classification.end(); i != e; ++i) {
+ FaceLoopGroup *grp = ((*i).first.first);
+
+ std::cerr << " group: " << grp << " gid: " << (*i).first.second
+ << " "
+ << ((*i).second.class_decided ? "+" : "-")
+ << " "
+ << ((*i).second.class_bits & FACE_IN_BIT ? "I" : ".")
+ << ((*i).second.class_bits & FACE_ON_ORIENT_IN_BIT ? "<" : ".")
+ << ((*i).second.class_bits & FACE_ON_ORIENT_OUT_BIT ? ">" : ".")
+ << ((*i).second.class_bits & FACE_OUT_BIT ? "O" : ".")
+ << " ["
+ << std::setw(4) << (*i).second.c[0] << " "
+ << std::setw(4) << (*i).second.c[1] << " "
+ << std::setw(4) << (*i).second.c[2] << " "
+ << std::setw(4) << (*i).second.c[3] << " "
+ << std::setw(4) << (*i).second.c[4] << "]" << std::endl;
+ }
+#endif
+
+ for (Classification::iterator i = a_classification.begin(), e = a_classification.end(); i != e; ++i) {
+ FaceLoopGroup *grp = ((*i).first.first);
+
+ grp->classification.push_back(ClassificationInfo());
+ ClassificationInfo &info = grp->classification.back();
+
+ info.intersected_mesh = (*i).first.second;
+
+ if ((*i).second.class_decided) {
+ info.classification = class_bit_to_class((*i).second.class_bits);
+ } else {
+ info.classification = FACE_UNCLASSIFIED;
+ }
+ }
+
+ for (Classification::iterator i = b_classification.begin(), e = b_classification.end(); i != e; ++i) {
+ FaceLoopGroup *grp = ((*i).first.first);
+
+ grp->classification.push_back(ClassificationInfo());
+ ClassificationInfo &info = grp->classification.back();
+
+ info.intersected_mesh = (*i).first.second;
+
+ if ((*i).second.class_decided) {
+ info.classification = class_bit_to_class((*i).second.class_bits);
+ } else {
+ info.classification = FACE_UNCLASSIFIED;
+ }
+ }
+
+ for (FLGroupList::iterator i = a_loops_grouped.begin(); i != a_loops_grouped.end(); ++i) {
+ if ((*i).classification.size() == 0) {
+#if defined(CARVE_DEBUG)
+ std::cerr << " non intersecting group (poly a): " << &(*i) << std::endl;
+#endif
+ bool classified = false;
+ for (FaceLoop *fl = (*i).face_loops.head; !classified && fl != NULL; fl = fl->next) {
+ for (size_t fli = 0; !classified && fli < fl->vertices.size(); ++fli) {
+ if (vclass[fl->vertices[fli]].cls[1] == POINT_UNK) {
+ vclass[fl->vertices[fli]].cls[1] = carve::mesh::classifyPoint(poly_b, poly_b_rtree, fl->vertices[fli]->v);
+ }
+ switch (vclass[fl->vertices[fli]].cls[1]) {
+ case POINT_IN:
+ (*i).classification.push_back(ClassificationInfo(NULL, FACE_IN));
+ classified = true;
+ break;
+ case POINT_OUT:
+ (*i).classification.push_back(ClassificationInfo(NULL, FACE_OUT));
+ classified = true;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ if (!classified) {
+ throw carve::exception("non intersecting group is not IN or OUT! (poly_a)");
+ }
+ }
+ }
+
+ for (FLGroupList::iterator i = b_loops_grouped.begin(); i != b_loops_grouped.end(); ++i) {
+ if ((*i).classification.size() == 0) {
+#if defined(CARVE_DEBUG)
+ std::cerr << " non intersecting group (poly b): " << &(*i) << std::endl;
+#endif
+ bool classified = false;
+ for (FaceLoop *fl = (*i).face_loops.head; !classified && fl != NULL; fl = fl->next) {
+ for (size_t fli = 0; !classified && fli < fl->vertices.size(); ++fli) {
+ if (vclass[fl->vertices[fli]].cls[0] == POINT_UNK) {
+ vclass[fl->vertices[fli]].cls[0] = carve::mesh::classifyPoint(poly_a, poly_a_rtree, fl->vertices[fli]->v);
+ }
+ switch (vclass[fl->vertices[fli]].cls[0]) {
+ case POINT_IN:
+ (*i).classification.push_back(ClassificationInfo(NULL, FACE_IN));
+ classified = true;
+ break;
+ case POINT_OUT:
+ (*i).classification.push_back(ClassificationInfo(NULL, FACE_OUT));
+ classified = true;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ if (!classified) {
+ throw carve::exception("non intersecting group is not IN or OUT! (poly_b)");
+ }
+ }
+ }
+
+#if defined(DISPLAY_GRP_GRAPH)
+#define POLY(grp) (std::string((grp)->face_loops.head->orig_face->polyhedron == poly_a ? "[A:" : "[B:") + CODE(grp) + "]")
+
+ for (std::map<const FaceLoopGroup *, std::set<const FaceLoopGroup *> >::iterator i = grp_graph_fwd.begin(); i != grp_graph_fwd.end(); ++i) {
+ const FaceLoopGroup *grp = (*i).first;
+
+ std::cerr << "GRP: " << grp << POLY(grp) << std::endl;
+
+ std::set<const FaceLoopGroup *> &fwd_set = grp_graph_fwd[grp];
+ std::set<const FaceLoopGroup *> &rev_set = grp_graph_rev[grp];
+ std::cerr << " FWD: ";
+ for (std::set<const FaceLoopGroup *>::const_iterator j = fwd_set.begin(); j != fwd_set.end(); ++j) {
+ std::cerr << " " << (*j) << POLY(*j);
+ }
+ std::cerr << std::endl;
+ std::cerr << " REV: ";
+ for (std::set<const FaceLoopGroup *>::const_iterator j = rev_set.begin(); j != rev_set.end(); ++j) {
+ std::cerr << " " << (*j) << POLY(*j);
+ }
+ std::cerr << std::endl;
+ }
+#endif
+
+ for (FLGroupList::iterator i = a_loops_grouped.begin(); i != a_loops_grouped.end(); ++i) {
+ collector.collect(&*i, hooks);
+ }
+
+ for (FLGroupList::iterator i = b_loops_grouped.begin(); i != b_loops_grouped.end(); ++i) {
+ collector.collect(&*i, hooks);
+ }
+
+ // traceIntersectionGraph(shared_edges, a_loops_grouped, b_loops_grouped, a_edge_map, b_edge_map);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/intersect_classify_group.cpp b/extern/carve/lib/intersect_classify_group.cpp
new file mode 100644
index 00000000000..4251af63f89
--- /dev/null
+++ b/extern/carve/lib/intersect_classify_group.cpp
@@ -0,0 +1,220 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/debug_hooks.hpp>
+
+#include <list>
+#include <set>
+#include <iostream>
+
+#include <algorithm>
+
+#include "intersect_common.hpp"
+#include "intersect_classify_common.hpp"
+#include "intersect_classify_common_impl.hpp"
+
+
+namespace carve {
+ namespace csg {
+
+ namespace {
+
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ // VC++ 6.0 gets an internal compiler when compiling
+ // the FaceMaker template. Not sure why but for now we just bypass
+ // the template
+ class FaceMaker0 {
+ public:
+ CSG::Collector &collector;
+ CSG::Hooks &hooks;
+
+ FaceMaker0(CSG::Collector &c, CSG::Hooks &h) : collector(c), hooks(h) {
+ }
+ bool pointOn(VertexClassification &vclass, FaceLoop *f, size_t index) const {
+ return vclass[f->vertices[index]].cls[1] == POINT_ON;
+ }
+ void explain(FaceLoop *f, size_t index, PointClass pc) const {
+#if defined(CARVE_DEBUG)
+ std::cerr << "face loop " << f << " from poly " << "ab"[0] << " is easy because vertex " << index << " (" << *f->vertices[index] << ") is " << ENUM(pc) << std::endl;
+#endif
+ }
+ };
+ class FaceMaker1 {
+ public:
+ CSG::Collector &collector;
+ CSG::Hooks &hooks;
+
+ FaceMaker1(CSG::Collector &c, CSG::Hooks &h) : collector(c), hooks(h) {
+ }
+ bool pointOn(VertexClassification &vclass, FaceLoop *f, size_t index) const {
+ return vclass[f->vertices[index]].cls[0] == POINT_ON;
+ }
+ void explain(FaceLoop *f, size_t index, PointClass pc) const {
+#if defined(CARVE_DEBUG)
+ std::cerr << "face loop " << f << " from poly " << "ab"[1] << " is easy because vertex " << index << " (" << *f->vertices[index] << ") is " << ENUM(pc) << std::endl;
+#endif
+ }
+ };
+#else
+ template <int poly_num>
+ class FaceMaker {
+ FaceMaker &operator=(const FaceMaker &);
+
+ public:
+ CSG::Collector &collector;
+ CSG::Hooks &hooks;
+
+ FaceMaker(CSG::Collector &c, CSG::Hooks &h) : collector(c), hooks(h) {
+ }
+
+ bool pointOn(VertexClassification &vclass, FaceLoop *f, size_t index) const {
+ return vclass[f->vertices[index]].cls[1 - poly_num] == POINT_ON;
+ }
+
+ void explain(FaceLoop *f, size_t index, PointClass pc) const {
+#if defined(CARVE_DEBUG)
+ std::cerr << "face loop " << f << " from poly " << "ab"[poly_num] << " is easy because vertex " << index << " (" << f->vertices[index]->v << ") is " << ENUM(pc) << std::endl;
+#endif
+ }
+ };
+ typedef FaceMaker<0> FaceMaker0;
+ typedef FaceMaker<1> FaceMaker1;
+#endif
+ class ClassifyFaceGroups {
+ ClassifyFaceGroups &operator=(const ClassifyFaceGroups &);
+
+ public:
+ CSG::Collector &collector;
+ CSG::Hooks &hooks;
+
+ ClassifyFaceGroups(CSG::Collector &c, CSG::Hooks &h) : collector(c), hooks(h) {
+ }
+
+ void classifySimple(FLGroupList &a_loops_grouped,
+ FLGroupList &b_loops_grouped,
+ VertexClassification & /* vclass */,
+ carve::mesh::MeshSet<3> *poly_a,
+ carve::mesh::MeshSet<3> *poly_b) const {
+ if (a_loops_grouped.size() < b_loops_grouped.size()) {
+ performClassifySimpleOnFaceGroups(a_loops_grouped, b_loops_grouped, poly_a, poly_b, collector, hooks);
+ } else {
+ performClassifySimpleOnFaceGroups(b_loops_grouped, a_loops_grouped, poly_b, poly_a, collector, hooks);
+ }
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of simple on groups: " << a_loops_grouped.size() << " a groups" << std::endl;
+ std::cerr << "after removal of simple on groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ }
+
+ void classifyEasy(FLGroupList &a_loops_grouped,
+ FLGroupList &b_loops_grouped,
+ VertexClassification &vclass,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree) const {
+ performClassifyEasyFaceGroups(a_loops_grouped, poly_b, poly_b_rtree, vclass, FaceMaker0(collector, hooks), collector, hooks);
+ performClassifyEasyFaceGroups(b_loops_grouped, poly_a, poly_a_rtree, vclass, FaceMaker1(collector, hooks), collector, hooks);
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of easy groups: " << a_loops_grouped.size() << " a groups" << std::endl;
+ std::cerr << "after removal of easy groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ }
+
+ void classifyHard(FLGroupList &a_loops_grouped,
+ FLGroupList &b_loops_grouped,
+ VertexClassification & /* vclass */,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree) const {
+ performClassifyHardFaceGroups(a_loops_grouped, poly_b, poly_b_rtree, FaceMaker0(collector, hooks), collector, hooks);
+ performClassifyHardFaceGroups(b_loops_grouped, poly_a, poly_a_rtree, FaceMaker1(collector, hooks), collector, hooks);
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of hard groups: " << a_loops_grouped.size() << " a groups" << std::endl;
+ std::cerr << "after removal of hard groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ }
+
+ void faceLoopWork(FLGroupList &a_loops_grouped,
+ FLGroupList &b_loops_grouped,
+ VertexClassification & /* vclass */,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree) const {
+ performFaceLoopWork(poly_b, poly_b_rtree, a_loops_grouped, *this, collector, hooks);
+ performFaceLoopWork(poly_a, poly_a_rtree, b_loops_grouped, *this, collector, hooks);
+ }
+
+ void postRemovalCheck(FLGroupList &a_loops_grouped,
+ FLGroupList &b_loops_grouped) const {
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of on groups: " << a_loops_grouped.size() << " a groups" << std::endl;
+ std::cerr << "after removal of on groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ }
+
+ bool faceLoopSanityChecker(FaceLoopGroup &i) const {
+ return i.face_loops.size() != 1;
+ }
+
+ void finish(FLGroupList &a_loops_grouped,FLGroupList &b_loops_grouped) const {
+#if defined(CARVE_DEBUG)
+ if (a_loops_grouped.size() || b_loops_grouped.size())
+ std::cerr << "UNCLASSIFIED! a=" << a_loops_grouped.size() << ", b=" << b_loops_grouped.size() << std::endl;
+#endif
+ }
+ };
+ }
+
+ void CSG::classifyFaceGroups(const V2Set & /* shared_edges */,
+ VertexClassification &vclass,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ FLGroupList &a_loops_grouped,
+ const detail::LoopEdges & /* a_edge_map */,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree,
+ FLGroupList &b_loops_grouped,
+ const detail::LoopEdges & /* b_edge_map */,
+ CSG::Collector &collector) {
+ ClassifyFaceGroups classifier(collector, hooks);
+#if defined(CARVE_DEBUG)
+ std::cerr << "initial groups: " << a_loops_grouped.size() << " a groups" << std::endl;
+ std::cerr << "initial groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ performClassifyFaceGroups(
+ a_loops_grouped,
+ b_loops_grouped,
+ vclass,
+ poly_a,
+ poly_a_rtree,
+ poly_b,
+ poly_b_rtree,
+ classifier,
+ collector,
+ hooks);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/intersect_common.hpp b/extern/carve/lib/intersect_common.hpp
new file mode 100644
index 00000000000..06f3cfdd4ec
--- /dev/null
+++ b/extern/carve/lib/intersect_common.hpp
@@ -0,0 +1,83 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#pragma once
+
+
+static inline bool facesAreCoplanar(const carve::mesh::MeshSet<3>::face_t *a, const carve::mesh::MeshSet<3>::face_t *b) {
+ carve::geom3d::Ray temp;
+ // XXX: Find a better definition. This may be a source of problems
+ // if floating point inaccuracies cause an incorrect answer.
+ return !carve::geom3d::planeIntersection(a->plane, b->plane, temp);
+}
+
+#if defined(CARVE_DEBUG)
+
+#include <carve/debug_hooks.hpp>
+
+#endif
+
+namespace carve {
+ namespace csg {
+
+ static inline carve::mesh::MeshSet<3>::vertex_t *map_vertex(const VVMap &vmap, carve::mesh::MeshSet<3>::vertex_t *v) {
+ VVMap::const_iterator i = vmap.find(v);
+ if (i == vmap.end()) return v;
+ return (*i).second;
+ }
+
+#if defined(CARVE_DEBUG)
+
+ class IntersectDebugHooks;
+ extern IntersectDebugHooks *g_debug;
+
+#define HOOK(x) do { if (g_debug) { g_debug->x } } while(0)
+
+ static inline void drawFaceLoopList(const FaceLoopList &ll,
+ float rF, float gF, float bF, float aF,
+ float rB, float gB, float bB, float aB,
+ bool lit) {
+ for (FaceLoop *flb = ll.head; flb; flb = flb->next) {
+ const carve::mesh::MeshSet<3>::face_t *f = (flb->orig_face);
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &loop = flb->vertices;
+ HOOK(drawFaceLoop2(loop, f->plane.N, rF, gF, bF, aF, rB, gB, bB, aB, true, lit););
+ HOOK(drawFaceLoopWireframe(loop, f->plane.N, 1, 1, 1, 0.1f););
+ }
+ }
+
+ static inline void drawFaceLoopListWireframe(const FaceLoopList &ll) {
+ for (FaceLoop *flb = ll.head; flb; flb = flb->next) {
+ const carve::mesh::MeshSet<3>::face_t *f = (flb->orig_face);
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &loop = flb->vertices;
+ HOOK(drawFaceLoopWireframe(loop, f->plane.N, 1, 1, 1, 0.1f););
+ }
+ }
+
+ template<typename T>
+ static inline void drawEdges(T begin, T end,
+ float rB, float gB, float bB, float aB,
+ float rE, float gE, float bE, float aE,
+ float w) {
+ for (; begin != end; ++begin) {
+ HOOK(drawEdge((*begin).first, (*begin).second, rB, gB, bB, aB, rE, gE, bE, aE, w););
+ }
+ }
+
+#endif
+
+ }
+}
diff --git a/extern/carve/lib/intersect_debug.cpp b/extern/carve/lib/intersect_debug.cpp
new file mode 100644
index 00000000000..c16854d5655
--- /dev/null
+++ b/extern/carve/lib/intersect_debug.cpp
@@ -0,0 +1,65 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+
+#include <list>
+#include <set>
+#include <iostream>
+
+#include <algorithm>
+
+#include "intersect_debug.hpp"
+
+namespace carve {
+ namespace csg {
+
+#if defined(CARVE_DEBUG)
+
+#define DEBUG_DRAW_FACE_EDGES
+#define DEBUG_DRAW_INTERSECTIONS
+// #define DEBUG_DRAW_OCTREE
+#define DEBUG_DRAW_INTERSECTION_LINE
+// #define DEBUG_DRAW_GROUPS
+// #define DEBUG_PRINT_RESULT_FACES
+
+ IntersectDebugHooks *g_debug = NULL;
+
+ IntersectDebugHooks *intersect_installDebugHooks(IntersectDebugHooks *hooks) {
+ IntersectDebugHooks *h = g_debug;
+ g_debug = hooks;
+ return h;
+ }
+
+ bool intersect_debugEnabled() { return true; }
+
+#else
+
+ IntersectDebugHooks *intersect_installDebugHooks(IntersectDebugHooks * /* hooks */) {
+ return NULL;
+ }
+
+ bool intersect_debugEnabled() { return false; }
+
+#endif
+
+ }
+}
diff --git a/extern/carve/lib/intersect_debug.hpp b/extern/carve/lib/intersect_debug.hpp
new file mode 100644
index 00000000000..be73a7c3dae
--- /dev/null
+++ b/extern/carve/lib/intersect_debug.hpp
@@ -0,0 +1,29 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#include <carve/debug_hooks.hpp>
+
+#if defined(CARVE_DEBUG)
+
+#define DEBUG_DRAW_FACE_EDGES
+#define DEBUG_DRAW_INTERSECTIONS
+// #define DEBUG_DRAW_OCTREE
+#define DEBUG_DRAW_INTERSECTION_LINE
+// #define DEBUG_DRAW_GROUPS
+// #define DEBUG_PRINT_RESULT_FACES
+
+#endif
diff --git a/extern/carve/lib/intersect_face_division.cpp b/extern/carve/lib/intersect_face_division.cpp
new file mode 100644
index 00000000000..6f2aa65ed67
--- /dev/null
+++ b/extern/carve/lib/intersect_face_division.cpp
@@ -0,0 +1,1709 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/polyline.hpp>
+#include <carve/debug_hooks.hpp>
+#include <carve/timing.hpp>
+#include <carve/triangulator.hpp>
+
+#include <list>
+#include <set>
+#include <iostream>
+
+#include <algorithm>
+
+#include "csg_detail.hpp"
+#include "csg_data.hpp"
+
+#include "intersect_common.hpp"
+
+
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+void writePLY(const std::string &out_file, const carve::line::PolylineSet *lines, bool ascii);
+#endif
+
+
+
+namespace {
+
+
+
+ template<typename T>
+ void populateVectorFromList(std::list<T> &l, std::vector<T> &v) {
+ v.clear();
+ v.reserve(l.size());
+ for (typename std::list<T>::iterator i = l.begin(); i != l.end(); ++i) {
+ v.push_back(T());
+ std::swap(*i, v.back());
+ }
+ l.clear();
+ }
+
+ template<typename T>
+ void populateListFromVector(std::vector<T> &v, std::list<T> &l) {
+ l.clear();
+ for (size_t i = 0; i < v.size(); ++i) {
+ l.push_back(T());
+ std::swap(v[i], l.back());
+ }
+ v.clear();
+ }
+
+
+
+ struct GraphEdge {
+ GraphEdge *next;
+ GraphEdge *prev;
+ GraphEdge *loop_next;
+ carve::mesh::MeshSet<3>::vertex_t *src;
+ carve::mesh::MeshSet<3>::vertex_t *tgt;
+ double ang;
+ int visited;
+
+ GraphEdge(carve::mesh::MeshSet<3>::vertex_t *_src, carve::mesh::MeshSet<3>::vertex_t *_tgt) :
+ next(NULL), prev(NULL), loop_next(NULL),
+ src(_src), tgt(_tgt),
+ ang(0.0), visited(-1) {
+ }
+ };
+
+
+
+ struct GraphEdges {
+ GraphEdge *edges;
+ carve::geom2d::P2 proj;
+
+ GraphEdges() : edges(NULL), proj() {
+ }
+ };
+
+
+
+ struct Graph {
+ typedef std::unordered_map<carve::mesh::MeshSet<3>::vertex_t *, GraphEdges> graph_t;
+
+ graph_t graph;
+
+ Graph() : graph() {
+ }
+
+ ~Graph() {
+ int c = 0;
+
+ GraphEdge *edge;
+ for (graph_t::iterator i = graph.begin(), e = graph.end(); i != e; ++i) {
+ edge = (*i).second.edges;
+ while (edge) {
+ GraphEdge *temp = edge;
+ ++c;
+ edge = edge->next;
+ delete temp;
+ }
+ }
+
+ if (c) {
+ std::cerr << "warning: "
+ << c
+ << " edges should have already been removed at graph destruction time"
+ << std::endl;
+ }
+ }
+
+ const carve::geom2d::P2 &projection(carve::mesh::MeshSet<3>::vertex_t *v) const {
+ graph_t::const_iterator i = graph.find(v);
+ CARVE_ASSERT(i != graph.end());
+ return (*i).second.proj;
+ }
+
+ void computeProjection(carve::mesh::MeshSet<3>::face_t *face) {
+ for (graph_t::iterator i = graph.begin(), e = graph.end(); i != e; ++i) {
+ (*i).second.proj = face->project((*i).first->v);
+ }
+ for (graph_t::iterator i = graph.begin(), e = graph.end(); i != e; ++i) {
+ for (GraphEdge *e = (*i).second.edges; e; e = e->next) {
+ e->ang = carve::math::ANG(carve::geom2d::atan2(projection(e->tgt) - projection(e->src)));
+ }
+ }
+ }
+
+ void print(std::ostream &out, const carve::csg::VertexIntersections *vi) const {
+ for (graph_t::const_iterator i = graph.begin(), e = graph.end(); i != e; ++i) {
+ out << (*i).first << (*i).first->v << '(' << projection((*i).first).x << ',' << projection((*i).first).y << ") :";
+ for (const GraphEdge *e = (*i).second.edges; e; e = e->next) {
+ out << ' ' << e->tgt << e->tgt->v << '(' << projection(e->tgt).x << ',' << projection(e->tgt).y << ')';
+ }
+ out << std::endl;
+ if (vi) {
+ carve::csg::VertexIntersections::const_iterator j = vi->find((*i).first);
+ if (j != vi->end()) {
+ out << " (int) ";
+ for (carve::csg::IObjPairSet::const_iterator
+ k = (*j).second.begin(), ke = (*j).second.end(); k != ke; ++k) {
+ if ((*k).first < (*k).second) {
+ out << (*k).first << ".." << (*k).second << "; ";
+ }
+ }
+ out << std::endl;
+ }
+ }
+ }
+ }
+
+ void addEdge(carve::mesh::MeshSet<3>::vertex_t *v1, carve::mesh::MeshSet<3>::vertex_t *v2) {
+ GraphEdges &edges = graph[v1];
+ GraphEdge *edge = new GraphEdge(v1, v2);
+ if (edges.edges) edges.edges->prev = edge;
+ edge->next = edges.edges;
+ edges.edges = edge;
+ }
+
+ void removeEdge(GraphEdge *edge) {
+ if (edge->prev != NULL) {
+ edge->prev->next = edge->next;
+ } else {
+ if (edge->next != NULL) {
+ GraphEdges &edges = (graph[edge->src]);
+ edges.edges = edge->next;
+ } else {
+ graph.erase(edge->src);
+ }
+ }
+ if (edge->next != NULL) {
+ edge->next->prev = edge->prev;
+ }
+ delete edge;
+ }
+
+ bool empty() const {
+ return graph.size() == 0;
+ }
+
+ GraphEdge *pickStartEdge() {
+ // Try and find a vertex from which there is only one outbound edge. Won't always succeed.
+ for (graph_t::iterator i = graph.begin(); i != graph.end(); ++i) {
+ GraphEdges &ge = i->second;
+ if (ge.edges->next == NULL) {
+ return ge.edges;
+ }
+ }
+ return (*graph.begin()).second.edges;
+ }
+
+ GraphEdge *outboundEdges(carve::mesh::MeshSet<3>::vertex_t *v) {
+ return graph[v].edges;
+ }
+ };
+
+
+
+ /**
+ * \brief Take a set of new edges and split a face based upon those edges.
+ *
+ * @param[in] face The face to be split.
+ * @param[in] edges
+ * @param[out] face_loops Output list of face loops
+ * @param[out] hole_loops Output list of hole loops
+ * @param vi
+ */
+ static void splitFace(carve::mesh::MeshSet<3>::face_t *face,
+ const carve::csg::V2Set &edges,
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &face_loops,
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &hole_loops,
+ const carve::csg::VertexIntersections & /* vi */) {
+ Graph graph;
+
+ for (carve::csg::V2Set::const_iterator
+ i = edges.begin(), e = edges.end();
+ i != e;
+ ++i) {
+ carve::mesh::MeshSet<3>::vertex_t *v1 = ((*i).first), *v2 = ((*i).second);
+ if (carve::geom::equal(v1->v, v2->v)) std::cerr << "WARNING! " << v1->v << "==" << v2->v << std::endl;
+ graph.addEdge(v1, v2);
+ }
+
+ graph.computeProjection(face);
+
+ while (!graph.empty()) {
+ GraphEdge *edge;
+ GraphEdge *start;
+ start = edge = graph.pickStartEdge();
+
+ edge->visited = 0;
+
+ int len = 0;
+
+ for (;;) {
+ double in_ang = M_PI + edge->ang;
+ if (in_ang > M_TWOPI) in_ang -= M_TWOPI;
+
+ GraphEdge *opts;
+ GraphEdge *out = NULL;
+ double best = M_TWOPI + 1.0;
+
+ for (opts = graph.outboundEdges(edge->tgt); opts; opts = opts->next) {
+ if (opts->tgt == edge->src) {
+ if (out == NULL && opts->next == NULL) out = opts;
+ } else {
+ double out_ang = carve::math::ANG(in_ang - opts->ang);
+
+ if (out == NULL || out_ang < best) {
+ out = opts;
+ best = out_ang;
+ }
+ }
+ }
+
+ CARVE_ASSERT(out != NULL);
+
+ edge->loop_next = out;
+
+ if (out->visited >= 0) {
+ while (start != out) {
+ GraphEdge *e = start;
+ start = start->loop_next;
+ e->loop_next = NULL;
+ e->visited = -1;
+ }
+ len = edge->visited - out->visited + 1;
+ break;
+ }
+
+ out->visited = edge->visited + 1;
+ edge = out;
+ }
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> loop(len);
+ std::vector<carve::geom2d::P2> projected(len);
+
+ edge = start;
+ for (int i = 0; i < len; ++i) {
+ GraphEdge *next = edge->loop_next;
+ loop[i] = edge->src;
+ projected[i] = graph.projection(edge->src);
+ graph.removeEdge(edge);
+ edge = next;
+ }
+
+ CARVE_ASSERT(edge == start);
+
+ if (carve::geom2d::signedArea(projected) < 0) {
+ face_loops.push_back(std::vector<carve::mesh::MeshSet<3>::vertex_t *>());
+ face_loops.back().swap(loop);
+ } else {
+ hole_loops.push_back(std::vector<carve::mesh::MeshSet<3>::vertex_t *>());
+ hole_loops.back().swap(loop);
+ }
+ }
+ }
+
+
+
+ /**
+ * \brief Determine the relationship between a face loop and a hole loop.
+ *
+ * Determine whether a face and hole share an edge, or a vertex,
+ * or do not touch. Find a hole vertex that is not part of the
+ * face, and a hole,face vertex pair that are coincident, if such
+ * a pair exists.
+ *
+ * @param[in] f A face loop.
+ * @param[in] f_sort A vector indexing \a f in address order
+ * @param[in] h A hole loop.
+ * @param[in] h_sort A vector indexing \a h in address order
+ * @param[out] f_idx Index of a face vertex that is shared with the hole.
+ * @param[out] h_idx Index of the hole vertex corresponding to \a f_idx.
+ * @param[out] unmatched_h_idx Index of a hole vertex that is not part of the face.
+ * @param[out] shares_vertex Boolean indicating that the face and the hole share a vertex.
+ * @param[out] shares_edge Boolean indicating that the face and the hole share an edge.
+ */
+ static void compareFaceLoopAndHoleLoop(const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &f,
+ const std::vector<unsigned> &f_sort,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &h,
+ const std::vector<unsigned> &h_sort,
+ unsigned &f_idx,
+ unsigned &h_idx,
+ int &unmatched_h_idx,
+ bool &shares_vertex,
+ bool &shares_edge) {
+ const size_t F = f.size();
+ const size_t H = h.size();
+
+ shares_vertex = shares_edge = false;
+ unmatched_h_idx = -1;
+
+ unsigned I, J;
+ for (I = J = 0; I < F && J < H;) {
+ unsigned i = f_sort[I], j = h_sort[J];
+ if (f[i] == h[j]) {
+ shares_vertex = true;
+ f_idx = i;
+ h_idx = j;
+ if (f[(i + F - 1) % F] == h[(j + 1) % H]) {
+ shares_edge = true;
+ }
+ carve::mesh::MeshSet<3>::vertex_t *t = f[i];
+ do { ++I; } while (I < F && f[f_sort[I]] == t);
+ do { ++J; } while (J < H && h[h_sort[J]] == t);
+ } else if (f[i] < h[j]) {
+ ++I;
+ } else {
+ unmatched_h_idx = j;
+ ++J;
+ }
+ }
+ if (J < H) {
+ unmatched_h_idx = h_sort[J];
+ }
+ }
+
+
+
+ /**
+ * \brief Compute an embedding for a set of face loops and hole loops.
+ *
+ * Because face and hole loops may be contained within each other,
+ * it must be determined which hole loops are directly contained
+ * within a face loop.
+ *
+ * @param[in] face The face from which these face and hole loops derive.
+ * @param[in] face_loops
+ * @param[in] hole_loops
+ * @param[out] containing_faces A vector which for each hole loop
+ * lists the indices of the face
+ * loops it is containined in.
+ * @param[out] hole_shared_vertices A map from a face,hole pair to
+ * a shared vertex pair.
+ */
+ static void computeContainment(carve::mesh::MeshSet<3>::face_t *face,
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &face_loops,
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &hole_loops,
+ std::vector<std::vector<int> > &containing_faces,
+ std::map<int, std::map<int, std::pair<unsigned, unsigned> > > &hole_shared_vertices) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "input: "
+ << face_loops.size() << "faces, "
+ << hole_loops.size() << "holes."
+ << std::endl;
+#endif
+
+ std::vector<std::vector<carve::geom2d::P2> > face_loops_projected, hole_loops_projected;
+ std::vector<carve::geom::aabb<2> > face_loop_aabb, hole_loop_aabb;
+ std::vector<std::vector<unsigned> > face_loops_sorted, hole_loops_sorted;
+
+ std::vector<double> face_loop_areas, hole_loop_areas;
+
+ face_loops_projected.resize(face_loops.size());
+ face_loops_sorted.resize(face_loops.size());
+ face_loop_aabb.resize(face_loops.size());
+ face_loop_areas.resize(face_loops.size());
+
+ hole_loops_projected.resize(hole_loops.size());
+ hole_loops_sorted.resize(hole_loops.size());
+ hole_loop_aabb.resize(hole_loops.size());
+ hole_loop_areas.resize(hole_loops.size());
+
+ // produce a projection of each face loop onto a 2D plane, and an
+ // index vector which sorts vertices by address.
+ for (size_t m = 0; m < face_loops.size(); ++m) {
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &f_loop = (face_loops[m]);
+ face_loops_projected[m].reserve(f_loop.size());
+ face_loops_sorted[m].reserve(f_loop.size());
+ for (size_t n = 0; n < f_loop.size(); ++n) {
+ face_loops_projected[m].push_back(face->project(f_loop[n]->v));
+ face_loops_sorted[m].push_back(n);
+ }
+ face_loop_areas.push_back(carve::geom2d::signedArea(face_loops_projected[m]));
+ std::sort(face_loops_sorted[m].begin(), face_loops_sorted[m].end(),
+ carve::make_index_sort(face_loops[m].begin()));
+ face_loop_aabb[m].fit(face_loops_projected[m].begin(), face_loops_projected[m].end());
+ }
+
+ // produce a projection of each hole loop onto a 2D plane, and an
+ // index vector which sorts vertices by address.
+ for (size_t m = 0; m < hole_loops.size(); ++m) {
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &h_loop = (hole_loops[m]);
+ hole_loops_projected[m].reserve(h_loop.size());
+ hole_loops_projected[m].reserve(h_loop.size());
+ for (size_t n = 0; n < h_loop.size(); ++n) {
+ hole_loops_projected[m].push_back(face->project(h_loop[n]->v));
+ hole_loops_sorted[m].push_back(n);
+ }
+ hole_loop_areas.push_back(carve::geom2d::signedArea(hole_loops_projected[m]));
+ std::sort(hole_loops_sorted[m].begin(), hole_loops_sorted[m].end(),
+ carve::make_index_sort(hole_loops[m].begin()));
+ hole_loop_aabb[m].fit(hole_loops_projected[m].begin(), hole_loops_projected[m].end());
+ }
+
+ containing_faces.resize(hole_loops.size());
+
+ for (unsigned i = 0; i < hole_loops.size(); ++i) {
+
+ for (unsigned j = 0; j < face_loops.size(); ++j) {
+ if (!face_loop_aabb[j].completelyContains(hole_loop_aabb[i])) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "face: " << j
+ << " hole: " << i
+ << " skipped test (aabb fail)"
+ << std::endl;
+#endif
+ continue;
+ }
+
+ unsigned f_idx, h_idx;
+ int unmatched_h_idx;
+ bool shares_vertex, shares_edge;
+ compareFaceLoopAndHoleLoop(face_loops[j],
+ face_loops_sorted[j],
+ hole_loops[i],
+ hole_loops_sorted[i],
+ f_idx, h_idx,
+ unmatched_h_idx,
+ shares_vertex,
+ shares_edge);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "face: " << j
+ << " hole: " << i
+ << " shares_vertex: " << shares_vertex
+ << " shares_edge: " << shares_edge
+ << std::endl;
+#endif
+
+ carve::geom3d::Vector test = hole_loops[i][0]->v;
+ carve::geom2d::P2 test_p = face->project(test);
+
+ if (shares_vertex) {
+ hole_shared_vertices[i][j] = std::make_pair(h_idx, f_idx);
+ // Hole touches face. Should be able to connect it up
+ // trivially. Still need to record its containment, so that
+ // the assignment below works.
+ if (unmatched_h_idx != -1) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "using unmatched vertex: " << unmatched_h_idx << std::endl;
+#endif
+ test = hole_loops[i][unmatched_h_idx]->v;
+ test_p = face->project(test);
+ } else {
+ // XXX: hole shares ALL vertices with face. Pick a point
+ // internal to the projected poly.
+ if (shares_edge) {
+ // Hole shares edge with face => face can't contain hole.
+ continue;
+ }
+
+ // XXX: how is this possible? Doesn't share an edge, but
+ // also doesn't have any vertices that are not in
+ // common. Degenerate hole?
+
+ // XXX: come up with a test case for this.
+ CARVE_FAIL("implement me");
+ }
+ }
+
+
+ // XXX: use loop area to avoid some point-in-poly tests? Loop
+ // area is faster, but not sure which is more robust.
+ if (carve::geom2d::pointInPolySimple(face_loops_projected[j], test_p)) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "contains: " << i << " - " << j << std::endl;
+#endif
+ containing_faces[i].push_back(j);
+ } else {
+#if defined(CARVE_DEBUG)
+ std::cerr << "does not contain: " << i << " - " << j << std::endl;
+#endif
+ }
+ }
+
+#if defined(CARVE_DEBUG)
+ if (containing_faces[i].size() == 0) {
+ //HOOK(drawFaceLoopWireframe(hole_loops[i], face->normal, 1.0, 0.0, 0.0, 1.0););
+ std::cerr << "hole loop: ";
+ for (unsigned j = 0; j < hole_loops[i].size(); ++j) {
+ std::cerr << " " << hole_loops[i][j] << ":" << hole_loops[i][j]->v;
+ }
+ std::cerr << std::endl;
+ for (unsigned j = 0; j < face_loops.size(); ++j) {
+ //HOOK(drawFaceLoopWireframe(face_loops[j], face->normal, 0.0, 1.0, 0.0, 1.0););
+ }
+ }
+#endif
+
+ // CARVE_ASSERT(containing_faces[i].size() >= 1);
+ }
+ }
+
+
+
+ /**
+ * \brief Merge face loops and hole loops to produce a set of face loops without holes.
+ *
+ * @param[in] face The face from which these face loops derive.
+ * @param[in,out] f_loops A list of face loops.
+ * @param[in] h_loops A list of hole loops to be incorporated into face loops.
+ */
+ static void mergeFacesAndHoles(carve::mesh::MeshSet<3>::face_t *face,
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &f_loops,
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &h_loops,
+ carve::csg::CSG::Hooks & /* hooks */) {
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > face_loops;
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > hole_loops;
+
+ std::vector<std::vector<int> > containing_faces;
+ std::map<int, std::map<int, std::pair<unsigned, unsigned> > > hole_shared_vertices;
+
+ {
+ // move input face and hole loops to temp vectors.
+ size_t m;
+ face_loops.resize(f_loops.size());
+ m = 0;
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::iterator
+ i = f_loops.begin(), ie = f_loops.end();
+ i != ie;
+ ++i, ++m) {
+ face_loops[m].swap((*i));
+ }
+
+ hole_loops.resize(h_loops.size());
+ m = 0;
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::iterator
+ i = h_loops.begin(), ie = h_loops.end();
+ i != ie;
+ ++i, ++m) {
+ hole_loops[m].swap((*i));
+ }
+ f_loops.clear();
+ h_loops.clear();
+ }
+
+ // work out the embedding of holes and faces.
+ computeContainment(face, face_loops, hole_loops, containing_faces, hole_shared_vertices);
+
+ int unassigned = (int)hole_loops.size();
+
+ std::vector<std::vector<int> > face_holes;
+ face_holes.resize(face_loops.size());
+
+ for (unsigned i = 0; i < containing_faces.size(); ++i) {
+ if (containing_faces[i].size() == 0) {
+ std::map<int, std::map<int, std::pair<unsigned, unsigned> > >::iterator it = hole_shared_vertices.find(i);
+ if (it != hole_shared_vertices.end()) {
+ std::map<int, std::pair<unsigned, unsigned> >::iterator it2 = (*it).second.begin();
+ int f = (*it2).first;
+ unsigned h_idx = (*it2).second.first;
+ unsigned f_idx = (*it2).second.second;
+
+ // patch the hole into the face directly. because
+ // f_loop[f_idx] == h_loop[h_idx], we don't need to
+ // duplicate the f_loop vertex.
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &f_loop = face_loops[f];
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &h_loop = hole_loops[i];
+
+ f_loop.insert(f_loop.begin() + f_idx + 1, h_loop.size(), NULL);
+
+ unsigned p = f_idx + 1;
+ for (unsigned a = h_idx + 1; a < h_loop.size(); ++a, ++p) {
+ f_loop[p] = h_loop[a];
+ }
+ for (unsigned a = 0; a <= h_idx; ++a, ++p) {
+ f_loop[p] = h_loop[a];
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "hook face " << f << " to hole " << i << "(vertex)" << std::endl;
+#endif
+ } else {
+ std::cerr << "uncontained hole loop does not share vertices with any face loop!" << std::endl;
+ }
+ unassigned--;
+ }
+ }
+
+
+ // work out which holes are directly contained within which faces.
+ while (unassigned) {
+ std::set<int> removed;
+
+ for (unsigned i = 0; i < containing_faces.size(); ++i) {
+ if (containing_faces[i].size() == 1) {
+ int f = containing_faces[i][0];
+ face_holes[f].push_back(i);
+#if defined(CARVE_DEBUG)
+ std::cerr << "hook face " << f << " to hole " << i << std::endl;
+#endif
+ removed.insert(f);
+ unassigned--;
+ }
+ }
+ for (std::set<int>::iterator f = removed.begin(); f != removed.end(); ++f) {
+ for (unsigned i = 0; i < containing_faces.size(); ++i) {
+ containing_faces[i].erase(std::remove(containing_faces[i].begin(),
+ containing_faces[i].end(),
+ *f),
+ containing_faces[i].end());
+ }
+ }
+ }
+
+#if 0
+ // use old templated projection code to patch holes into faces.
+ for (unsigned i = 0; i < face_loops.size(); ++i) {
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > face_hole_loops;
+ face_hole_loops.resize(face_holes[i].size());
+ for (unsigned j = 0; j < face_holes[i].size(); ++j) {
+ face_hole_loops[j].swap(hole_loops[face_holes[i][j]]);
+ }
+ if (face_hole_loops.size()) {
+
+ f_loops.push_back(carve::triangulate::incorporateHolesIntoPolygon(
+ carve::mesh::MeshSet<3>::face_t::projection_mapping(face->project),
+ face_loops[i],
+ face_hole_loops));
+ } else {
+ f_loops.push_back(face_loops[i]);
+ }
+ }
+
+#else
+ // use new 2d-only hole patching code.
+ for (size_t i = 0; i < face_loops.size(); ++i) {
+ if (!face_holes[i].size()) {
+ f_loops.push_back(face_loops[i]);
+ continue;
+ }
+
+ std::vector<std::vector<carve::geom2d::P2> > projected_poly;
+ projected_poly.resize(face_holes[i].size() + 1);
+ projected_poly[0].reserve(face_loops[i].size());
+ for (size_t j = 0; j < face_loops[i].size(); ++j) {
+ projected_poly[0].push_back(face->project(face_loops[i][j]->v));
+ }
+ for (size_t j = 0; j < face_holes[i].size(); ++j) {
+ projected_poly[j+1].reserve(hole_loops[face_holes[i][j]].size());
+ for (size_t k = 0; k < hole_loops[face_holes[i][j]].size(); ++k) {
+ projected_poly[j+1].push_back(face->project(hole_loops[face_holes[i][j]][k]->v));
+ }
+ }
+
+ std::vector<std::pair<size_t, size_t> > result = carve::triangulate::incorporateHolesIntoPolygon(projected_poly);
+
+ f_loops.push_back(std::vector<carve::mesh::MeshSet<3>::vertex_t *>());
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &out = f_loops.back();
+ out.reserve(result.size());
+ for (size_t j = 0; j < result.size(); ++j) {
+ if (result[j].first == 0) {
+ out.push_back(face_loops[i][result[j].second]);
+ } else {
+ out.push_back(hole_loops[face_holes[i][result[j].first-1]][result[j].second]);
+ }
+ }
+ }
+#endif
+ }
+
+
+
+ /**
+ * \brief Assemble the base loop for a face.
+ *
+ * The base loop is the original face loop, including vertices
+ * created by intersections crossing any of its edges.
+ *
+ * @param[in] face The face to process.
+ * @param[in] vmap
+ * @param[in] face_split_edges
+ * @param[in] divided_edges A mapping from edge pointer to sets of
+ * ordered vertices corrsponding to the intersection points
+ * on that edge.
+ * @param[out] base_loop A vector of the vertices of the base loop.
+ */
+ static void assembleBaseLoop(carve::mesh::MeshSet<3>::face_t *face,
+ const carve::csg::detail::Data &data,
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &base_loop) {
+ base_loop.clear();
+
+ // XXX: assumes that face->edges is in the same order as
+ // face->vertices. (Which it is)
+ carve::mesh::MeshSet<3>::edge_t *e = face->edge;
+ do {
+ base_loop.push_back(carve::csg::map_vertex(data.vmap, e->vert));
+
+ carve::csg::detail::EVVMap::const_iterator ev = data.divided_edges.find(e);
+
+ if (ev != data.divided_edges.end()) {
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &ev_vec = ((*ev).second);
+
+ for (size_t k = 0, ke = ev_vec.size(); k < ke;) {
+ base_loop.push_back(ev_vec[k++]);
+ }
+ }
+ e = e->next;
+ } while (e != face->edge);
+ }
+
+
+
+ // the crossing_data structure holds temporary information regarding
+ // paths, and their relationship to the loop of edges that forms the
+ // face perimeter.
+ struct crossing_data {
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> *path;
+ size_t edge_idx[2];
+
+ crossing_data(std::vector<carve::mesh::MeshSet<3>::vertex_t *> *p, size_t e1, size_t e2) : path(p) {
+ edge_idx[0] = e1; edge_idx[1] = e2;
+ }
+
+ bool operator<(const crossing_data &c) const {
+ // the sort order for paths is in order of increasing initial
+ // position on the edge loop, but decreasing final position.
+ return edge_idx[0] < c.edge_idx[0] || (edge_idx[0] == c.edge_idx[0] && edge_idx[1] > c.edge_idx[1]);
+ }
+ };
+
+
+
+ bool processCrossingEdges(carve::mesh::MeshSet<3>::face_t *face,
+ const carve::csg::VertexIntersections &vertex_intersections,
+ carve::csg::CSG::Hooks &hooks,
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &base_loop,
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &paths,
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &loops,
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &face_loops_out) {
+ const size_t N = base_loop.size();
+ std::vector<crossing_data> endpoint_indices;
+
+ endpoint_indices.reserve(paths.size());
+
+ for (size_t i = 0; i < paths.size(); ++i) {
+ endpoint_indices.push_back(crossing_data(&paths[i], N, N));
+ }
+
+ // locate endpoints of paths on the base loop.
+ for (size_t i = 0; i < N; ++i) {
+ for (size_t j = 0; j < paths.size(); ++j) {
+ // test beginning of path.
+ if (paths[j].front() == base_loop[i]) {
+ if (endpoint_indices[j].edge_idx[0] == N) {
+ endpoint_indices[j].edge_idx[0] = i;
+ } else {
+ // there is a duplicated vertex in the face perimeter. The
+ // path might attach to either of the duplicate instances
+ // so we have to work out which is the right one to attach
+ // to. We assume it's the index currently being examined,
+ // if the path heads in a direction that's internal to the
+ // angle made by the prior and next edges of the face
+ // perimeter. Otherwise, leave it as the currently
+ // selected index (until another duplicate is found, if it
+ // exists, and is tested).
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &p = *endpoint_indices[j].path;
+ const size_t pN = p.size();
+
+ carve::mesh::MeshSet<3>::vertex_t *a, *b, *c;
+ a = base_loop[(i+N-1)%N];
+ b = base_loop[i];
+ c = base_loop[(i+1)%N];
+
+ carve::mesh::MeshSet<3>::vertex_t *adj = (p[0] == base_loop[i]) ? p[1] : p[pN-2];
+
+ if (carve::geom2d::internalToAngle(face->project(c->v),
+ face->project(b->v),
+ face->project(a->v),
+ face->project(adj->v))) {
+ endpoint_indices[j].edge_idx[0] = i;
+ }
+ }
+ }
+
+ // test end of path.
+ if (paths[j].back() == base_loop[i]) {
+ if (endpoint_indices[j].edge_idx[1] == N) {
+ endpoint_indices[j].edge_idx[1] = i;
+ } else {
+ // Work out which of the duplicated vertices is the right
+ // one to attach to, as above.
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &p = *endpoint_indices[j].path;
+ const size_t pN = p.size();
+
+ carve::mesh::MeshSet<3>::vertex_t *a, *b, *c;
+ a = base_loop[(i+N-1)%N];
+ b = base_loop[i];
+ c = base_loop[(i+1)%N];
+
+ carve::mesh::MeshSet<3>::vertex_t *adj = (p[0] == base_loop[i]) ? p[1] : p[pN-2];
+
+ if (carve::geom2d::internalToAngle(face->project(c->v),
+ face->project(b->v),
+ face->project(a->v),
+ face->project(adj->v))) {
+ endpoint_indices[j].edge_idx[1] = i;
+ }
+ }
+ }
+ }
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "### N: " << N << std::endl;
+ for (size_t i = 0; i < paths.size(); ++i) {
+ std::cerr << "### path: " << i << " endpoints: " << endpoint_indices[i].edge_idx[0] << " - " << endpoint_indices[i].edge_idx[1] << std::endl;
+ }
+#endif
+
+
+ // divide paths up into those that connect to the base loop in two
+ // places (cross), and those that do not (noncross).
+ std::vector<crossing_data> cross, noncross;
+ cross.reserve(endpoint_indices.size() + 1);
+ noncross.reserve(endpoint_indices.size());
+
+ for (size_t i = 0; i < endpoint_indices.size(); ++i) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "### orienting path: " << i << " endpoints: " << endpoint_indices[i].edge_idx[0] << " - " << endpoint_indices[i].edge_idx[1] << std::endl;
+#endif
+ if (endpoint_indices[i].edge_idx[0] != N && endpoint_indices[i].edge_idx[1] != N) {
+ // Orient each path correctly. Paths should progress from
+ // smaller perimeter index to larger, but if the path starts
+ // and ends at the same perimeter index, then the decision
+ // needs to be made based upon area.
+ if (endpoint_indices[i].edge_idx[0] == endpoint_indices[i].edge_idx[1]) {
+ // The path forms a loop that starts and ends at the same
+ // vertex of the perimeter. In this case, we need to orient
+ // the path so that the constructed loop has the right
+ // signed area.
+ double area = carve::geom2d::signedArea(endpoint_indices[i].path->begin() + 1,
+ endpoint_indices[i].path->end(),
+ carve::mesh::MeshSet<3>::face_t::projection_mapping(face->project));
+ std::cerr << "HITS THIS CODE - area=" << area << std::endl;
+ if (area < 0) {
+ // XXX: Create test case to check that this is the correct sign for the area.
+ std::reverse(endpoint_indices[i].path->begin(), endpoint_indices[i].path->end());
+ }
+ } else {
+ if (endpoint_indices[i].edge_idx[0] > endpoint_indices[i].edge_idx[1]) {
+ std::swap(endpoint_indices[i].edge_idx[0], endpoint_indices[i].edge_idx[1]);
+ std::reverse(endpoint_indices[i].path->begin(), endpoint_indices[i].path->end());
+ }
+ }
+ }
+
+ if (endpoint_indices[i].edge_idx[0] != N &&
+ endpoint_indices[i].edge_idx[1] != N &&
+ endpoint_indices[i].edge_idx[0] != endpoint_indices[i].edge_idx[1]) {
+ cross.push_back(endpoint_indices[i]);
+ } else {
+ noncross.push_back(endpoint_indices[i]);
+ }
+ }
+
+ // add a temporary crossing path that connects the beginning and the
+ // end of the base loop. this stops us from needing special case
+ // code to handle the left over loop after all the other crossing
+ // paths are considered.
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> base_loop_temp_path;
+ base_loop_temp_path.reserve(2);
+ base_loop_temp_path.push_back(base_loop.front());
+ base_loop_temp_path.push_back(base_loop.back());
+
+ cross.push_back(crossing_data(&base_loop_temp_path, 0, base_loop.size() - 1));
+#if defined(CARVE_DEBUG)
+ std::cerr << "### crossing edge count (with sentinel): " << cross.size() << std::endl;
+#endif
+
+ // sort paths by increasing beginning point and decreasing ending point.
+ std::sort(cross.begin(), cross.end());
+ std::sort(noncross.begin(), noncross.end());
+
+ // divide up the base loop based upon crossing paths.
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > divided_base_loop;
+ divided_base_loop.reserve(cross.size());
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> out;
+
+ for (size_t i = 0; i < cross.size(); ++i) {
+ size_t j;
+ for (j = i + 1;
+ j < cross.size() &&
+ cross[i].edge_idx[0] == cross[j].edge_idx[0] &&
+ cross[i].edge_idx[1] == cross[j].edge_idx[1];
+ ++j) {}
+ if (j - i >= 2) {
+ // when there are multiple paths that begin and end at the
+ // same point, they need to be ordered so that the constructed
+ // loops have the right orientation. this means that the loop
+ // made by taking path(i+1) forward, then path(i) backward
+ // needs to have negative area. this combined area is equal to
+ // the area of path(i+1) minus the area of path(i). in turn
+ // this means that the loop made by path path(i+1) alone has
+ // to have smaller signed area than loop made by path(i).
+ // thus, we sort paths in order of decreasing area.
+
+ std::vector<std::pair<double, std::vector<carve::mesh::MeshSet<3>::vertex_t *> *> > order;
+ order.reserve(j - i);
+ for (size_t k = i; k < j; ++k) {
+ double area = carve::geom2d::signedArea(cross[k].path->begin(),
+ cross[k].path->end(),
+ carve::mesh::MeshSet<3>::face_t::projection_mapping(face->project));
+#if defined(CARVE_DEBUG)
+ std::cerr << "### k=" << k << " area=" << area << std::endl;
+#endif
+ order.push_back(std::make_pair(-area, cross[k].path));
+ }
+ std::sort(order.begin(), order.end());
+ for (size_t k = i; k < j; ++k) {
+ cross[k].path = order[k-i].second;
+#if defined(CARVE_DEBUG)
+ std::cerr << "### post-sort k=" << k << " cross[k].path->size()=" << cross[k].path->size() << std::endl;
+#endif
+ }
+ }
+ }
+
+ for (size_t i = 0; i < cross.size(); ++i) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "### i=" << i << " working on edge: " << cross[i].edge_idx[0] << " - " << cross[i].edge_idx[1] << std::endl;
+#endif
+ size_t e1_0 = cross[i].edge_idx[0];
+ size_t e1_1 = cross[i].edge_idx[1];
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &p1 = *cross[i].path;
+#if defined(CARVE_DEBUG)
+ std::cerr << "### path size = " << p1.size() << std::endl;
+#endif
+
+ out.clear();
+
+ if (i < cross.size() - 1 &&
+ cross[i+1].edge_idx[1] <= cross[i].edge_idx[1]) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "### complex case" << std::endl;
+#endif
+ // complex case. crossing path with other crossing paths embedded within.
+ size_t pos = e1_0;
+
+ size_t skip = i+1;
+
+ while (pos != e1_1) {
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &p2 = *cross[skip].path;
+ size_t e2_0 = cross[skip].edge_idx[0];
+ size_t e2_1 = cross[skip].edge_idx[1];
+
+ // copy up to the beginning of the next path.
+ std::copy(base_loop.begin() + pos, base_loop.begin() + e2_0, std::back_inserter(out));
+
+ CARVE_ASSERT(base_loop[e2_0] == p2[0]);
+ // copy the next path in the right direction.
+ std::copy(p2.begin(), p2.end() - 1, std::back_inserter(out));
+
+ // move to the position of the end of the path.
+ pos = e2_1;
+
+ // advance to the next hit path.
+ do {
+ ++skip;
+ } while(skip != cross.size() && cross[skip].edge_idx[0] < e2_1);
+
+ if (skip == cross.size()) break;
+
+ // if the next hit path is past the start point of the current path, we're done.
+ if (cross[skip].edge_idx[0] >= e1_1) break;
+ }
+
+ // copy up to the end of the path.
+ std::copy(base_loop.begin() + pos, base_loop.begin() + e1_1, std::back_inserter(out));
+
+ CARVE_ASSERT(base_loop[e1_1] == p1.back());
+ std::copy(p1.rbegin(), p1.rend() - 1, std::back_inserter(out));
+ } else {
+ size_t loop_size = (e1_1 - e1_0) + (p1.size() - 1);
+ out.reserve(loop_size);
+
+ std::copy(base_loop.begin() + e1_0, base_loop.begin() + e1_1, std::back_inserter(out));
+ std::copy(p1.rbegin(), p1.rend() - 1, std::back_inserter(out));
+
+ CARVE_ASSERT(out.size() == loop_size);
+ }
+ divided_base_loop.push_back(out);
+
+#if defined(CARVE_DEBUG)
+ {
+ std::vector<carve::geom2d::P2> projected;
+ projected.reserve(out.size());
+ for (size_t n = 0; n < out.size(); ++n) {
+ projected.push_back(face->project(out[n]->v));
+ }
+
+ double A = carve::geom2d::signedArea(projected);
+ std::cerr << "### out area=" << A << std::endl;
+ CARVE_ASSERT(A <= 0);
+ }
+#endif
+ }
+
+ if (!noncross.size() && !loops.size()) {
+ populateListFromVector(divided_base_loop, face_loops_out);
+ return true;
+ }
+
+ // for each divided base loop, work out which noncrossing paths and
+ // loops are part of it. use the old algorithm to combine these into
+ // the divided base loop. if none, the divided base loop is just
+ // output.
+ std::vector<std::vector<carve::geom2d::P2> > proj;
+ std::vector<carve::geom::aabb<2> > proj_aabb;
+ proj.resize(divided_base_loop.size());
+ proj_aabb.resize(divided_base_loop.size());
+
+ // calculate an aabb for each divided base loop, to avoid expensive
+ // point-in-poly tests.
+ for (size_t i = 0; i < divided_base_loop.size(); ++i) {
+ proj[i].reserve(divided_base_loop[i].size());
+ for (size_t j = 0; j < divided_base_loop[i].size(); ++j) {
+ proj[i].push_back(face->project(divided_base_loop[i][j]->v));
+ }
+ proj_aabb[i].fit(proj[i].begin(), proj[i].end());
+ }
+
+ for (size_t i = 0; i < divided_base_loop.size(); ++i) {
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> *> inc;
+ carve::geom2d::P2 test;
+
+ // for each noncrossing path, choose an endpoint that isn't on the
+ // base loop as a test point.
+ for (size_t j = 0; j < noncross.size(); ++j) {
+ if (noncross[j].edge_idx[0] < N) {
+ if (noncross[j].path->front() == base_loop[noncross[j].edge_idx[0]]) {
+ // noncrossing paths may be loops that run from the edge, back to the same vertex.
+ if (noncross[j].path->front() == noncross[j].path->back()) {
+ CARVE_ASSERT(noncross[j].path->size() > 2);
+ test = face->project((*noncross[j].path)[1]->v);
+ } else {
+ test = face->project(noncross[j].path->back()->v);
+ }
+ } else {
+ test = face->project(noncross[j].path->front()->v);
+ }
+ } else {
+ test = face->project(noncross[j].path->front()->v);
+ }
+
+ if (proj_aabb[i].intersects(test) &&
+ carve::geom2d::pointInPoly(proj[i], test).iclass != carve::POINT_OUT) {
+ inc.push_back(noncross[j].path);
+ }
+ }
+
+ // for each loop, just test with any point.
+ for (size_t j = 0; j < loops.size(); ++j) {
+ test = face->project(loops[j].front()->v);
+
+ if (proj_aabb[i].intersects(test) &&
+ carve::geom2d::pointInPoly(proj[i], test).iclass != carve::POINT_OUT) {
+ inc.push_back(&loops[j]);
+ }
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "### divided base loop:" << i << " inc.size()=" << inc.size() << std::endl;
+ std::cerr << "### inc = [";
+ for (size_t j = 0; j < inc.size(); ++j) {
+ std::cerr << " " << inc[j];
+ }
+ std::cerr << " ]" << std::endl;
+#endif
+
+ if (inc.size()) {
+ carve::csg::V2Set face_edges;
+
+ for (size_t j = 0; j < divided_base_loop[i].size() - 1; ++j) {
+ face_edges.insert(std::make_pair(divided_base_loop[i][j],
+ divided_base_loop[i][j+1]));
+ }
+
+ face_edges.insert(std::make_pair(divided_base_loop[i].back(),
+ divided_base_loop[i].front()));
+
+ for (size_t j = 0; j < inc.size(); ++j) {
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &path = *inc[j];
+ for (size_t k = 0; k < path.size() - 1; ++k) {
+ face_edges.insert(std::make_pair(path[k], path[k+1]));
+ face_edges.insert(std::make_pair(path[k+1], path[k]));
+ }
+ }
+
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > face_loops;
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > hole_loops;
+
+ splitFace(face, face_edges, face_loops, hole_loops, vertex_intersections);
+
+ if (hole_loops.size()) {
+ mergeFacesAndHoles(face, face_loops, hole_loops, hooks);
+ }
+ std::copy(face_loops.begin(), face_loops.end(), std::back_inserter(face_loops_out));
+ } else {
+ face_loops_out.push_back(divided_base_loop[i]);
+ }
+ }
+ return true;
+ }
+
+
+
+ void composeEdgesIntoPaths(const carve::csg::V2Set &edges,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &extra_endpoints,
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &paths,
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &loops) {
+ using namespace carve::csg;
+
+ detail::VVSMap vertex_graph;
+ detail::VSet endpoints;
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> path;
+
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > temp;
+
+ // build graph from edges.
+ for (V2Set::const_iterator i = edges.begin(); i != edges.end(); ++i) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "### edge: " << (*i).first << " - " << (*i).second << std::endl;
+#endif
+ vertex_graph[(*i).first].insert((*i).second);
+ vertex_graph[(*i).second].insert((*i).first);
+ }
+
+ // find the endpoints in the graph.
+ // every vertex with number of incident edges != 2 is an endpoint.
+ for (detail::VVSMap::const_iterator i = vertex_graph.begin(); i != vertex_graph.end(); ++i) {
+ if ((*i).second.size() != 2) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "### endpoint: " << (*i).first << std::endl;
+#endif
+ endpoints.insert((*i).first);
+ }
+ }
+
+ // every vertex on the perimeter of the face is also an endpoint.
+ for (size_t i = 0; i < extra_endpoints.size(); ++i) {
+ if (vertex_graph.find(extra_endpoints[i]) != vertex_graph.end()) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "### extra endpoint: " << extra_endpoints[i] << std::endl;
+#endif
+ endpoints.insert(extra_endpoints[i]);
+ }
+ }
+
+ while (endpoints.size()) {
+ carve::mesh::MeshSet<3>::vertex_t *v = *endpoints.begin();
+ detail::VVSMap::iterator p = vertex_graph.find(v);
+ if (p == vertex_graph.end()) {
+ endpoints.erase(endpoints.begin());
+ continue;
+ }
+
+ path.clear();
+ path.push_back(v);
+
+ for (;;) {
+ CARVE_ASSERT(p != vertex_graph.end());
+
+ // pick a connected vertex to move to.
+ if ((*p).second.size() == 0) break;
+
+ carve::mesh::MeshSet<3>::vertex_t *n = *((*p).second.begin());
+ detail::VVSMap::iterator q = vertex_graph.find(n);
+
+ // remove the link.
+ (*p).second.erase(n);
+ (*q).second.erase(v);
+
+ // move on.
+ v = n;
+ path.push_back(v);
+
+ if ((*p).second.size() == 0) vertex_graph.erase(p);
+ if ((*q).second.size() == 0) {
+ vertex_graph.erase(q);
+ q = vertex_graph.end();
+ }
+
+ p = q;
+
+ if (v == path[0] || p == vertex_graph.end() || endpoints.find(v) != endpoints.end()) break;
+ }
+ CARVE_ASSERT(endpoints.find(path.back()) != endpoints.end());
+
+ temp.push_back(path);
+ }
+
+ populateVectorFromList(temp, paths);
+ temp.clear();
+
+ // now only loops should remain in the graph.
+ while (vertex_graph.size()) {
+ detail::VVSMap::iterator p = vertex_graph.begin();
+ carve::mesh::MeshSet<3>::vertex_t *v = (*p).first;
+ CARVE_ASSERT((*p).second.size() == 2);
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> path;
+ path.clear();
+ path.push_back(v);
+
+ for (;;) {
+ CARVE_ASSERT(p != vertex_graph.end());
+ // pick a connected vertex to move to.
+
+ carve::mesh::MeshSet<3>::vertex_t *n = *((*p).second.begin());
+ detail::VVSMap::iterator q = vertex_graph.find(n);
+
+ // remove the link.
+ (*p).second.erase(n);
+ (*q).second.erase(v);
+
+ // move on.
+ v = n;
+ path.push_back(v);
+
+ if ((*p).second.size() == 0) vertex_graph.erase(p);
+ if ((*q).second.size() == 0) vertex_graph.erase(q);
+
+ p = q;
+
+ if (v == path[0]) break;
+ }
+
+ temp.push_back(path);
+ }
+ populateVectorFromList(temp, loops);
+ }
+
+
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ void dumpFacesAndHoles(const std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &face_loops,
+ const std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &hole_loops) {
+ std::map<carve::mesh::MeshSet<3>::vertex_t *, size_t> v_included;
+
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::const_iterator
+ i = face_loops.begin(); i != face_loops.end(); ++i) {
+ for (size_t j = 0; j < (*i).size(); ++j) {
+ if (v_included.find((*i)[j]) == v_included.end()) {
+ size_t &p = v_included[(*i)[j]];
+ p = v_included.size() - 1;
+ }
+ }
+ }
+
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::const_iterator
+ i = hole_loops.begin(); i != hole_loops.end(); ++i) {
+ for (size_t j = 0; j < (*i).size(); ++j) {
+ if (v_included.find((*i)[j]) == v_included.end()) {
+ size_t &p = v_included[(*i)[j]];
+ p = v_included.size() - 1;
+ }
+ }
+ }
+
+ carve::line::PolylineSet fh;
+ fh.vertices.resize(v_included.size());
+ for (std::map<carve::mesh::MeshSet<3>::vertex_t *, size_t>::const_iterator
+ i = v_included.begin(); i != v_included.end(); ++i) {
+ fh.vertices[(*i).second].v = (*i).first->v;
+ }
+
+ {
+ std::vector<size_t> connected;
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::const_iterator
+ i = face_loops.begin(); i != face_loops.end(); ++i) {
+ connected.clear();
+ for (size_t j = 0; j < (*i).size(); ++j) {
+ connected.push_back(v_included[(*i)[j]]);
+ }
+ fh.addPolyline(true, connected.begin(), connected.end());
+ }
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::const_iterator
+ i = hole_loops.begin(); i != hole_loops.end(); ++i) {
+ connected.clear();
+ for (size_t j = 0; j < (*i).size(); ++j) {
+ connected.push_back(v_included[(*i)[j]]);
+ }
+ fh.addPolyline(true, connected.begin(), connected.end());
+ }
+ }
+
+ std::string out("/tmp/hole_merge.ply");
+ ::writePLY(out, &fh, true);
+ }
+#endif
+
+
+
+ template<typename T>
+ std::string ptrstr(const T *ptr) {
+ std::ostringstream s;
+ s << ptr;
+ return s.str().substr(1);
+ }
+
+ void dumpAsGraph(carve::mesh::MeshSet<3>::face_t *face,
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &base_loop,
+ const carve::csg::V2Set &face_edges,
+ const carve::csg::V2Set &split_edges) {
+ std::map<carve::mesh::MeshSet<3>::vertex_t *, carve::geom2d::P2> proj;
+
+ for (size_t i = 0; i < base_loop.size(); ++i) {
+ proj[base_loop[i]] = face->project(base_loop[i]->v);
+ }
+ for (carve::csg::V2Set::const_iterator i = split_edges.begin(); i != split_edges.end(); ++i) {
+ proj[(*i).first] = face->project((*i).first->v);
+ proj[(*i).second] = face->project((*i).second->v);
+ }
+
+ {
+ carve::geom2d::P2 lo, hi;
+ std::map<carve::mesh::MeshSet<3>::vertex_t *, carve::geom2d::P2>::iterator i;
+ i = proj.begin();
+ lo = hi = (*i).second;
+ for (; i != proj.end(); ++i) {
+ lo.x = std::min(lo.x, (*i).second.x); lo.y = std::min(lo.y, (*i).second.y);
+ hi.x = std::max(hi.x, (*i).second.x); hi.y = std::max(hi.y, (*i).second.y);
+ }
+ for (i = proj.begin(); i != proj.end(); ++i) {
+ (*i).second.x = ((*i).second.x - lo.x) / (hi.x - lo.x) * 10;
+ (*i).second.y = ((*i).second.y - lo.y) / (hi.y - lo.y) * 10;
+ }
+ }
+
+ std::cerr << "graph G {\nnode [shape=circle,style=filled,fixedsize=true,width=\".1\",height=\".1\"];\nedge [len=4]\n";
+ for (std::map<carve::mesh::MeshSet<3>::vertex_t *, carve::geom2d::P2>::iterator i = proj.begin(); i != proj.end(); ++i) {
+ std::cerr << " " << ptrstr((*i).first) << " [pos=\"" << (*i).second.x << "," << (*i).second.y << "!\"];\n";
+ }
+ for (carve::csg::V2Set::const_iterator i = face_edges.begin(); i != face_edges.end(); ++i) {
+ std::cerr << " " << ptrstr((*i).first) << " -- " << ptrstr((*i).second) << ";\n";
+ }
+ for (carve::csg::V2Set::const_iterator i = split_edges.begin(); i != split_edges.end(); ++i) {
+ std::cerr << " " << ptrstr((*i).first) << " -- " << ptrstr((*i).second) << " [color=\"blue\"];\n";
+ }
+ std::cerr << "};\n";
+ }
+
+ void generateOneFaceLoop(carve::mesh::MeshSet<3>::face_t *face,
+ const carve::csg::detail::Data &data,
+ const carve::csg::VertexIntersections &vertex_intersections,
+ carve::csg::CSG::Hooks &hooks,
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > &face_loops) {
+ using namespace carve::csg;
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> base_loop;
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > hole_loops;
+
+ assembleBaseLoop(face, data, base_loop);
+
+ detail::FV2SMap::const_iterator fse_iter = data.face_split_edges.find(face);
+
+ face_loops.clear();
+
+ if (fse_iter == data.face_split_edges.end()) {
+ // simple case: input face is output face (possibly with the
+ // addition of vertices at intersections).
+ face_loops.push_back(base_loop);
+ return;
+ }
+
+ // complex case: input face is split into multiple output faces.
+ V2Set face_edges;
+
+ for (size_t j = 0, je = base_loop.size() - 1; j < je; ++j) {
+ face_edges.insert(std::make_pair(base_loop[j], base_loop[j + 1]));
+ }
+ face_edges.insert(std::make_pair(base_loop.back(), base_loop[0]));
+
+ // collect the split edges (as long as they're not on the perimeter)
+ const detail::FV2SMap::mapped_type &fse = ((*fse_iter).second);
+
+ // split_edges contains all of the edges created by intersections
+ // that aren't part of the perimeter of the face.
+ V2Set split_edges;
+
+ for (detail::FV2SMap::mapped_type::const_iterator
+ j = fse.begin(), je = fse.end();
+ j != je;
+ ++j) {
+ carve::mesh::MeshSet<3>::vertex_t *v1 = ((*j).first), *v2 = ((*j).second);
+
+ if (face_edges.find(std::make_pair(v1, v2)) == face_edges.end() &&
+ face_edges.find(std::make_pair(v2, v1)) == face_edges.end()) {
+
+ split_edges.insert(ordered_edge(v1, v2));
+ }
+ }
+
+ // face is unsplit.
+ if (!split_edges.size()) {
+ face_loops.push_back(base_loop);
+ return;
+ }
+
+#if defined(CARVE_DEBUG)
+ dumpAsGraph(face, base_loop, face_edges, split_edges);
+#endif
+
+#if 0
+ // old face splitting method.
+ for (V2Set::const_iterator i = split_edges.begin(); i != split_edges.end(); ++i) {
+ face_edges.insert(std::make_pair((*i).first, (*i).second));
+ face_edges.insert(std::make_pair((*i).second, (*i).first));
+ }
+ splitFace(face, face_edges, face_loops, hole_loops, vertex_intersections);
+
+ if (hole_loops.size()) {
+ mergeFacesAndHoles(face, face_loops, hole_loops, hooks);
+ }
+ return;
+#endif
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "### split_edges.size(): " << split_edges.size() << std::endl;
+#endif
+ if (split_edges.size() == 1) {
+ // handle the common case of a face that's split by a single edge.
+ carve::mesh::MeshSet<3>::vertex_t *v1 = split_edges.begin()->first;
+ carve::mesh::MeshSet<3>::vertex_t *v2 = split_edges.begin()->second;
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *>::iterator vi1 = std::find(base_loop.begin(), base_loop.end(), v1);
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *>::iterator vi2 = std::find(base_loop.begin(), base_loop.end(), v2);
+
+ if (vi1 != base_loop.end() && vi2 != base_loop.end()) {
+ // this is an inserted edge that connects two points on the base loop. nice and simple.
+ if (vi2 < vi1) std::swap(vi1, vi2);
+
+ size_t loop1_size = vi2 - vi1 + 1;
+ size_t loop2_size = base_loop.size() + 2 - loop1_size;
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> l1;
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> l2;
+
+ l1.reserve(loop1_size);
+ l2.reserve(loop2_size);
+
+ std::copy(vi1, vi2+1, std::back_inserter(l1));
+ std::copy(vi2, base_loop.end(), std::back_inserter(l2));
+ std::copy(base_loop.begin(), vi1+1, std::back_inserter(l2));
+
+ CARVE_ASSERT(l1.size() == loop1_size);
+ CARVE_ASSERT(l2.size() == loop2_size);
+
+ face_loops.push_back(l1);
+ face_loops.push_back(l2);
+
+ return;
+ }
+ }
+
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > paths;
+ std::vector<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > loops;
+
+ // Take the split edges and compose them into a set of paths and
+ // loops. Loops are edge paths that do not touch the boundary, or
+ // any other path or loop - they are holes cut out of the centre
+ // of the face. Paths are made up of all the other edge segments,
+ // and start and end at the face perimeter, or where they meet
+ // another path (sometimes both cases will be true).
+ composeEdgesIntoPaths(split_edges, base_loop, paths, loops);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "### paths.size(): " << paths.size() << std::endl;
+ std::cerr << "### loops.size(): " << loops.size() << std::endl;
+#endif
+
+ if (!paths.size()) {
+ // Loops found by composeEdgesIntoPaths() can't touch the
+ // boundary, or each other, so we can deal with the no paths
+ // case simply. The hole loops are the loops produced by
+ // composeEdgesIntoPaths() oriented so that their signed area
+ // wrt. the face is negative. The face loops are the base loop
+ // plus the hole loops, reversed.
+ face_loops.push_back(base_loop);
+
+ for (size_t i = 0; i < loops.size(); ++i) {
+ hole_loops.push_back(std::vector<carve::mesh::MeshSet<3>::vertex_t *>());
+ hole_loops.back().reserve(loops[i].size()-1);
+ std::copy(loops[i].begin(), loops[i].end()-1, std::back_inserter(hole_loops.back()));
+
+ face_loops.push_back(std::vector<carve::mesh::MeshSet<3>::vertex_t *>());
+ face_loops.back().reserve(loops[i].size()-1);
+ std::copy(loops[i].rbegin()+1, loops[i].rend(), std::back_inserter(face_loops.back()));
+
+ std::vector<carve::geom2d::P2> projected;
+ projected.reserve(face_loops.back().size());
+ for (size_t i = 0; i < face_loops.back().size(); ++i) {
+ projected.push_back(face->project(face_loops.back()[i]->v));
+ }
+
+ if (carve::geom2d::signedArea(projected) > 0.0) {
+ std::swap(face_loops.back(), hole_loops.back());
+ }
+ }
+
+ // if there are holes, then they need to be merged with faces.
+ if (hole_loops.size()) {
+ mergeFacesAndHoles(face, face_loops, hole_loops, hooks);
+ }
+ } else {
+ if (!processCrossingEdges(face, vertex_intersections, hooks, base_loop, paths, loops, face_loops)) {
+ // complex case - fall back to old edge tracing code.
+#if defined(CARVE_DEBUG)
+ std::cerr << "### processCrossingEdges failed. Falling back to edge tracing code" << std::endl;
+#endif
+ for (V2Set::const_iterator i = split_edges.begin(); i != split_edges.end(); ++i) {
+ face_edges.insert(std::make_pair((*i).first, (*i).second));
+ face_edges.insert(std::make_pair((*i).second, (*i).first));
+ }
+ splitFace(face, face_edges, face_loops, hole_loops, vertex_intersections);
+
+ if (hole_loops.size()) {
+ mergeFacesAndHoles(face, face_loops, hole_loops, hooks);
+ }
+ }
+ }
+ }
+
+
+
+}
+
+
+
+/**
+ * \brief Build a set of face loops for all (split) faces of a Polyhedron.
+ *
+ * @param[in] poly The polyhedron to process
+ * @param vmap
+ * @param face_split_edges
+ * @param divided_edges
+ * @param[out] face_loops_out The resulting face loops
+ *
+ * @return The number of edges generated.
+ */
+size_t carve::csg::CSG::generateFaceLoops(carve::mesh::MeshSet<3> *poly,
+ const detail::Data &data,
+ FaceLoopList &face_loops_out) {
+ static carve::TimingName FUNC_NAME("CSG::generateFaceLoops()");
+ carve::TimingBlock block(FUNC_NAME);
+ size_t generated_edges = 0;
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> base_loop;
+ std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > face_loops;
+
+ for (carve::mesh::MeshSet<3>::face_iter i = poly->faceBegin(); i != poly->faceEnd(); ++i) {
+ carve::mesh::MeshSet<3>::face_t *face = (*i);
+
+#if defined(CARVE_DEBUG)
+ double in_area = 0.0, out_area = 0.0;
+
+ {
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> base_loop;
+ assembleBaseLoop(face, data, base_loop);
+
+ {
+ std::vector<carve::geom2d::P2> projected;
+ projected.reserve(base_loop.size());
+ for (size_t n = 0; n < base_loop.size(); ++n) {
+ projected.push_back(face->project(base_loop[n]->v));
+ }
+
+ in_area = carve::geom2d::signedArea(projected);
+ std::cerr << "### in_area=" << in_area << std::endl;
+ }
+ }
+#endif
+
+ generateOneFaceLoop(face, data, vertex_intersections, hooks, face_loops);
+
+#if defined(CARVE_DEBUG)
+ {
+ V2Set face_edges;
+
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> base_loop;
+ assembleBaseLoop(face, data, base_loop);
+
+ for (size_t j = 0, je = base_loop.size() - 1; j < je; ++j) {
+ face_edges.insert(std::make_pair(base_loop[j+1], base_loop[j]));
+ }
+ face_edges.insert(std::make_pair(base_loop[0], base_loop.back()));
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::const_iterator fli = face_loops.begin(); fli != face_loops.end(); ++ fli) {
+
+ {
+ std::vector<carve::geom2d::P2> projected;
+ projected.reserve((*fli).size());
+ for (size_t n = 0; n < (*fli).size(); ++n) {
+ projected.push_back(face->project((*fli)[n]->v));
+ }
+
+ double area = carve::geom2d::signedArea(projected);
+ std::cerr << "### loop_area[" << std::distance((std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::const_iterator)face_loops.begin(), fli) << "]=" << area << std::endl;
+ out_area += area;
+ }
+
+ const std::vector<carve::mesh::MeshSet<3>::vertex_t *> &fl = *fli;
+ for (size_t j = 0, je = fl.size() - 1; j < je; ++j) {
+ face_edges.insert(std::make_pair(fl[j], fl[j+1]));
+ }
+ face_edges.insert(std::make_pair(fl.back(), fl[0]));
+ }
+ for (V2Set::const_iterator j = face_edges.begin(); j != face_edges.end(); ++j) {
+ if (face_edges.find(std::make_pair((*j).second, (*j).first)) == face_edges.end()) {
+ std::cerr << "### error: unmatched edge [" << (*j).first << "-" << (*j).second << "]" << std::endl;
+ }
+ }
+ std::cerr << "### out_area=" << out_area << std::endl;
+ if (out_area != in_area) {
+ std::cerr << "### error: area does not match. delta = " << (out_area - in_area) << std::endl;
+ // CARVE_ASSERT(fabs(out_area - in_area) < 1e-5);
+ }
+ }
+#endif
+
+ // now record all the resulting face loops.
+#if defined(CARVE_DEBUG)
+ std::cerr << "### ======" << std::endl;
+#endif
+ for (std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> >::const_iterator
+ f = face_loops.begin(), fe = face_loops.end();
+ f != fe;
+ ++f) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "### loop:";
+ for (size_t i = 0; i < (*f).size(); ++i) {
+ std::cerr << " " << (*f)[i];
+ }
+ std::cerr << std::endl;
+#endif
+
+ face_loops_out.append(new FaceLoop(face, *f));
+ generated_edges += (*f).size();
+ }
+#if defined(CARVE_DEBUG)
+ std::cerr << "### ======" << std::endl;
+#endif
+ }
+ return generated_edges;
+}
diff --git a/extern/carve/lib/intersect_group.cpp b/extern/carve/lib/intersect_group.cpp
new file mode 100644
index 00000000000..a1528569c01
--- /dev/null
+++ b/extern/carve/lib/intersect_group.cpp
@@ -0,0 +1,232 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/timing.hpp>
+
+#include "csg_detail.hpp"
+#include "intersect_common.hpp"
+
+void carve::csg::CSG::makeEdgeMap(const carve::csg::FaceLoopList &loops,
+ size_t edge_count,
+ detail::LoopEdges &edge_map) {
+#if defined(UNORDERED_COLLECTIONS_SUPPORT_RESIZE)
+ edge_map.resize(edge_count);
+#endif
+
+ for (carve::csg::FaceLoop *i = loops.head; i; i = i->next) {
+ edge_map.addFaceLoop(i);
+ i->group = NULL;
+ }
+}
+
+#include <carve/polyline.hpp>
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+void writePLY(const std::string &out_file, const carve::mesh::MeshSet<3> *poly, bool ascii);
+void writePLY(const std::string &out_file, const carve::line::PolylineSet *lines, bool ascii);
+#endif
+
+void carve::csg::CSG::findSharedEdges(const detail::LoopEdges &edge_map_a,
+ const detail::LoopEdges &edge_map_b,
+ V2Set &shared_edges) {
+ for (detail::LoopEdges::const_iterator
+ i = edge_map_a.begin(), e = edge_map_a.end();
+ i != e;
+ ++i) {
+ detail::LoopEdges::const_iterator j = edge_map_b.find((*i).first);
+ if (j != edge_map_b.end()) {
+ shared_edges.insert((*i).first);
+ }
+ }
+
+#if defined(CARVE_DEBUG)
+ detail::VVSMap edge_graph;
+
+ for (V2Set::const_iterator i = shared_edges.begin(); i != shared_edges.end(); ++i) {
+ edge_graph[(*i).first].insert((*i).second);
+ edge_graph[(*i).second].insert((*i).first);
+ }
+
+ std::cerr << "*** testing consistency of edge graph" << std::endl;
+ for (detail::VVSMap::const_iterator i = edge_graph.begin(); i != edge_graph.end(); ++i) {
+ if ((*i).second.size() > 2) {
+ std::cerr << "branch at: " << (*i).first << std::endl;
+ }
+ if ((*i).second.size() == 1) {
+ std::cerr << "endpoint at: " << (*i).first << std::endl;
+ std::cerr << "coordinate: " << (*i).first->v << std::endl;
+ }
+ }
+
+ {
+ carve::line::PolylineSet intersection_graph;
+ intersection_graph.vertices.resize(edge_graph.size());
+ std::map<const carve::mesh::MeshSet<3>::vertex_t *, size_t> vmap;
+
+ size_t j = 0;
+ for (detail::VVSMap::const_iterator i = edge_graph.begin(); i != edge_graph.end(); ++i) {
+ intersection_graph.vertices[j].v = (*i).first->v;
+ vmap[(*i).first] = j++;
+ }
+
+ while (edge_graph.size()) {
+ detail::VVSMap::iterator prior_i = edge_graph.begin();
+ carve::mesh::MeshSet<3>::vertex_t *prior = (*prior_i).first;
+ std::vector<size_t> connected;
+ connected.push_back(vmap[prior]);
+ while (prior_i != edge_graph.end() && (*prior_i).second.size()) {
+ carve::mesh::MeshSet<3>::vertex_t *next = *(*prior_i).second.begin();
+ detail::VVSMap::iterator next_i = edge_graph.find(next);
+ CARVE_ASSERT(next_i != edge_graph.end());
+ connected.push_back(vmap[next]);
+ (*prior_i).second.erase(next);
+ (*next_i).second.erase(prior);
+ if (!(*prior_i).second.size()) { edge_graph.erase(prior_i); prior_i = edge_graph.end(); }
+ if (!(*next_i).second.size()) { edge_graph.erase(next_i); next_i = edge_graph.end(); }
+ prior_i = next_i;
+ prior = next;
+ }
+ bool closed = connected.front() == connected.back();
+ for (size_t k = 0; k < connected.size(); ++k) {
+ std::cerr << " " << connected[k];
+ }
+ std::cerr << std::endl;
+ intersection_graph.addPolyline(closed, connected.begin(), connected.end());
+ }
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ std::string out("/tmp/intersection.ply");
+ ::writePLY(out, &intersection_graph, true);
+#endif
+ }
+
+ std::cerr << "*** edge graph consistency test done" << std::endl;
+#endif
+}
+
+
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+static carve::mesh::MeshSet<3> *groupToPolyhedron(const carve::csg::FaceLoopGroup &grp) {
+ const carve::csg::FaceLoopList &fl = grp.face_loops;
+ std::vector<carve::mesh::MeshSet<3>::face_t *> faces;
+ faces.reserve(fl.size());
+ for (carve::csg::FaceLoop *f = fl.head; f; f = f->next) {
+ faces.push_back(f->orig_face->create(f->vertices.begin(), f->vertices.end(), false));
+ }
+ carve::mesh::MeshSet<3> *poly = new carve::mesh::MeshSet<3>(faces);
+
+ poly->canonicalize();
+ return poly;
+}
+#endif
+
+
+
+void carve::csg::CSG::groupFaceLoops(carve::mesh::MeshSet<3> *src,
+ carve::csg::FaceLoopList &face_loops,
+ const carve::csg::detail::LoopEdges &loop_edges,
+ const carve::csg::V2Set &no_cross,
+ carve::csg::FLGroupList &out_loops) {
+ // Find all the groups of face loops that are connected by edges
+ // that are not part of no_cross.
+ // this could potentially be done with a disjoint set data-structure.
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ static int call_num = 0;
+ call_num++;
+#endif
+
+ static carve::TimingName GROUP_FACE_LOOPS("groupFaceLoops()");
+
+ carve::TimingBlock block(GROUP_FACE_LOOPS);
+
+ int tag_num = 0;
+ while (face_loops.size()) {
+ out_loops.push_back(FaceLoopGroup(src));
+ carve::csg::FaceLoopGroup &group = (out_loops.back());
+ carve::csg::FaceLoopList &curr = (group.face_loops);
+ carve::csg::V2Set &perim = (group.perimeter);
+
+ carve::csg::FaceLoop *expand = face_loops.head;
+
+ expand->group = &group;
+ face_loops.remove(expand);
+ curr.append(expand);
+
+ while (expand) {
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> &loop = (expand->vertices);
+ carve::mesh::MeshSet<3>::vertex_t *v1, *v2;
+
+ v1 = loop.back();
+ for (size_t i = 0; i < loop.size(); ++i) {
+ v2 = loop[i];
+
+ carve::csg::V2Set::const_iterator nc = no_cross.find(std::make_pair(v1, v2));
+ if (nc == no_cross.end()) {
+ carve::csg::detail::LoopEdges::const_iterator j;
+
+ j = loop_edges.find(std::make_pair(v1, v2));
+ if (j != loop_edges.end()) {
+ for (std::list<carve::csg::FaceLoop *>::const_iterator
+ k = (*j).second.begin(), ke = (*j).second.end();
+ k != ke; ++k) {
+ if ((*k)->group != NULL ||
+ (*k)->orig_face->mesh != expand->orig_face->mesh) continue;
+ face_loops.remove((*k));
+ curr.append((*k));
+ (*k)->group = &group;
+ }
+ }
+
+ j = loop_edges.find(std::make_pair(v2, v1));
+ if (j != loop_edges.end()) {
+ for (std::list<carve::csg::FaceLoop *>::const_iterator
+ k = (*j).second.begin(), ke = (*j).second.end();
+ k != ke; ++k) {
+ if ((*k)->group != NULL ||
+ (*k)->orig_face->mesh != expand->orig_face->mesh) continue;
+ face_loops.remove((*k));
+ curr.append((*k));
+ (*k)->group = &group;
+ }
+ }
+ } else {
+ perim.insert(std::make_pair(v1, v2));
+ }
+ v1 = v2;
+ }
+ expand = expand->next;
+ }
+ tag_num++;
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ {
+ carve::mesh::MeshSet<3> *poly = groupToPolyhedron(group);
+ char buf[128];
+ sprintf(buf, "/tmp/group-%d-%p.ply", call_num, &curr);
+ std::string out(buf);
+ ::writePLY(out, poly, false);
+ delete poly;
+ }
+#endif
+ }
+}
diff --git a/extern/carve/lib/intersect_half_classify_group.cpp b/extern/carve/lib/intersect_half_classify_group.cpp
new file mode 100644
index 00000000000..97915c784a0
--- /dev/null
+++ b/extern/carve/lib/intersect_half_classify_group.cpp
@@ -0,0 +1,199 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/debug_hooks.hpp>
+
+#include <list>
+#include <set>
+#include <iostream>
+
+#include <algorithm>
+
+#include "intersect_common.hpp"
+#include "intersect_classify_common.hpp"
+#include "intersect_classify_common_impl.hpp"
+
+namespace carve {
+ namespace csg {
+
+ namespace {
+ struct GroupPoly : public CSG::Collector {
+ carve::mesh::MeshSet<3> *want_groups_from;
+ std::list<std::pair<FaceClass, carve::mesh::MeshSet<3> *> > &out;
+
+ GroupPoly(carve::mesh::MeshSet<3> *poly,
+ std::list<std::pair<FaceClass, carve::mesh::MeshSet<3> *> > &_out) : CSG::Collector(), want_groups_from(poly), out(_out) {
+ }
+
+ virtual ~GroupPoly() {
+ }
+
+ virtual void collect(FaceLoopGroup *grp, CSG::Hooks & /* hooks */) {
+ if (grp->face_loops.head->orig_face->mesh->meshset != want_groups_from) return;
+
+ std::list<ClassificationInfo> &cinfo = (grp->classification);
+ if (cinfo.size() == 0) {
+ std::cerr << "WARNING! group " << grp << " has no classification info!" << std::endl;
+ return;
+ }
+ // XXX: check all the cinfo elements for consistency.
+ FaceClass fc = cinfo.front().classification;
+
+ std::vector<carve::mesh::MeshSet<3>::face_t *> faces;
+ faces.reserve(grp->face_loops.size());
+ for (FaceLoop *loop = grp->face_loops.head; loop != NULL; loop = loop->next) {
+ faces.push_back(loop->orig_face->create(loop->vertices.begin(), loop->vertices.end(), false));
+ }
+
+ out.push_back(std::make_pair(fc, new carve::mesh::MeshSet<3>(faces)));
+ }
+
+ virtual carve::mesh::MeshSet<3> *done(CSG::Hooks & /* hooks */) {
+ return NULL;
+ }
+ };
+
+ class FaceMaker {
+ public:
+
+ bool pointOn(VertexClassification &vclass, FaceLoop *f, size_t index) const {
+ return vclass[f->vertices[index]].cls[0] == POINT_ON;
+ }
+
+ void explain(FaceLoop *f, size_t index, PointClass pc) const {
+#if defined(CARVE_DEBUG)
+ std::cerr << "face loop " << f << " from poly b is easy because vertex " << index << " (" << f->vertices[index]->v << ") is " << ENUM(pc) << std::endl;
+#endif
+ }
+ };
+
+ class HalfClassifyFaceGroups {
+ HalfClassifyFaceGroups &operator=(const HalfClassifyFaceGroups &);
+
+ public:
+ std::list<std::pair<FaceClass, carve::mesh::MeshSet<3> *> > &b_out;
+ CSG::Hooks &hooks;
+
+ HalfClassifyFaceGroups(std::list<std::pair<FaceClass, carve::mesh::MeshSet<3> *> > &c, CSG::Hooks &h) : b_out(c), hooks(h) {
+ }
+
+ void classifySimple(FLGroupList &a_loops_grouped,
+ FLGroupList &b_loops_grouped,
+ VertexClassification & /* vclass */,
+ carve::mesh::MeshSet<3> *poly_a,
+ carve::mesh::MeshSet<3> *poly_b) const {
+ GroupPoly group_poly(poly_b, b_out);
+ performClassifySimpleOnFaceGroups(a_loops_grouped, b_loops_grouped, poly_a, poly_b, group_poly, hooks);
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of simple on groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ }
+
+ void classifyEasy(FLGroupList & /* a_loops_grouped */,
+ FLGroupList &b_loops_grouped,
+ VertexClassification & vclass,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree) const {
+ GroupPoly group_poly(poly_b, b_out);
+ performClassifyEasyFaceGroups(b_loops_grouped, poly_a, poly_a_rtree, vclass, FaceMaker(), group_poly, hooks);
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of easy groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ }
+
+ void classifyHard(FLGroupList & /* a_loops_grouped */,
+ FLGroupList &b_loops_grouped,
+ VertexClassification & /* vclass */,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree) const {
+ GroupPoly group_poly(poly_b, b_out);
+ performClassifyHardFaceGroups(b_loops_grouped, poly_a, poly_a_rtree, FaceMaker(), group_poly, hooks);
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of hard groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+
+ }
+
+ void faceLoopWork(FLGroupList & /* a_loops_grouped */,
+ FLGroupList &b_loops_grouped,
+ VertexClassification & /* vclass */,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree) const {
+ GroupPoly group_poly(poly_b, b_out);
+ performFaceLoopWork(poly_a, poly_a_rtree, b_loops_grouped, *this, group_poly, hooks);
+ }
+
+ void postRemovalCheck(FLGroupList & /* a_loops_grouped */,
+ FLGroupList &b_loops_grouped) const {
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removal of on groups: " << b_loops_grouped.size() << " b groups" << std::endl;
+#endif
+ }
+
+ bool faceLoopSanityChecker(FaceLoopGroup &i) const {
+ return false;
+ return i.face_loops.size() != 1;
+ }
+
+ void finish(FLGroupList &a_loops_grouped,FLGroupList &b_loops_grouped) const {
+#if defined(CARVE_DEBUG)
+ if (a_loops_grouped.size() || b_loops_grouped.size())
+ std::cerr << "UNCLASSIFIED! a=" << a_loops_grouped.size() << ", b=" << b_loops_grouped.size() << std::endl;
+#endif
+ }
+ };
+ }
+
+ void CSG::halfClassifyFaceGroups(const V2Set & /* shared_edges */,
+ VertexClassification &vclass,
+ carve::mesh::MeshSet<3> *poly_a,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_a_rtree,
+ FLGroupList &a_loops_grouped,
+ const detail::LoopEdges & /* a_edge_map */,
+ carve::mesh::MeshSet<3> *poly_b,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *poly_b_rtree,
+ FLGroupList &b_loops_grouped,
+ const detail::LoopEdges & /* b_edge_map */,
+ std::list<std::pair<FaceClass, carve::mesh::MeshSet<3> *> > &b_out) {
+ HalfClassifyFaceGroups classifier(b_out, hooks);
+ GroupPoly group_poly(poly_b, b_out);
+ performClassifyFaceGroups(
+ a_loops_grouped,
+ b_loops_grouped,
+ vclass,
+ poly_a,
+ poly_a_rtree,
+ poly_b,
+ poly_b_rtree,
+ classifier,
+ group_poly,
+ hooks);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/intersection.cpp b/extern/carve/lib/intersection.cpp
new file mode 100644
index 00000000000..2aa97131f7f
--- /dev/null
+++ b/extern/carve/lib/intersection.cpp
@@ -0,0 +1,92 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <algorithm>
+
+#include <carve/carve.hpp>
+#include <carve/poly.hpp>
+#include <carve/timing.hpp>
+#include <carve/intersection.hpp>
+
+
+
+void carve::csg::Intersections::collect(const IObj &obj,
+ std::vector<carve::mesh::MeshSet<3>::vertex_t *> *collect_v,
+ std::vector<carve::mesh::MeshSet<3>::edge_t *> *collect_e,
+ std::vector<carve::mesh::MeshSet<3>::face_t *> *collect_f) const {
+ carve::csg::Intersections::const_iterator i = find(obj);
+ if (i != end()) {
+ Intersections::mapped_type::const_iterator a, b;
+ for (a = (*i).second.begin(), b = (*i).second.end(); a != b; ++a) {
+ switch ((*a).first.obtype) {
+ case carve::csg::IObj::OBTYPE_VERTEX:
+ if (collect_v) collect_v->push_back((*a).first.vertex);
+ break;
+ case carve::csg::IObj::OBTYPE_EDGE:
+ if (collect_e) collect_e->push_back((*a).first.edge);
+ break;
+ case carve::csg::IObj::OBTYPE_FACE:
+ if (collect_f) collect_f->push_back((*a).first.face);
+ break;
+ default:
+ throw carve::exception("should not happen " __FILE__ ":" XSTR(__LINE__));
+ }
+ }
+ }
+}
+
+
+
+bool carve::csg::Intersections::intersectsFace(carve::mesh::MeshSet<3>::vertex_t *v,
+ carve::mesh::MeshSet<3>::face_t *f) const {
+ const_iterator i = find(v);
+ if (i != end()) {
+ mapped_type::const_iterator a, b;
+
+ for (a = (*i).second.begin(), b = (*i).second.end(); a != b; ++a) {
+ switch ((*a).first.obtype) {
+ case IObj::OBTYPE_VERTEX: {
+ const carve::mesh::MeshSet<3>::edge_t *edge = f->edge;
+ do {
+ if (edge->vert == (*a).first.vertex) return true;
+ edge = edge->next;
+ } while (edge != f->edge);
+ break;
+ }
+ case carve::csg::IObj::OBTYPE_EDGE: {
+ const carve::mesh::MeshSet<3>::edge_t *edge = f->edge;
+ do {
+ if (edge == (*a).first.edge) return true;
+ edge = edge->next;
+ } while (edge != f->edge);
+ break;
+ }
+ case carve::csg::IObj::OBTYPE_FACE: {
+ if ((*a).first.face == f) return true;
+ break;
+ }
+ default:
+ throw carve::exception("should not happen " __FILE__ ":" XSTR(__LINE__));
+ }
+ }
+ }
+ return false;
+}
diff --git a/extern/carve/lib/math.cpp b/extern/carve/lib/math.cpp
new file mode 100644
index 00000000000..811312c313e
--- /dev/null
+++ b/extern/carve/lib/math.cpp
@@ -0,0 +1,347 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/math.hpp>
+#include <carve/matrix.hpp>
+
+#include <iostream>
+#include <limits>
+
+#include <stdio.h>
+
+#define M_2PI_3 2.0943951023931953
+#define M_SQRT_3_4 0.8660254037844386
+#define EPS std::numeric_limits<double>::epsilon()
+
+namespace carve {
+ namespace math {
+
+ struct Root {
+ double root;
+ int multiplicity;
+
+ Root(double r) : root(r), multiplicity(1) {}
+ Root(double r, int m) : root(r), multiplicity(m) {}
+ };
+
+ void cplx_sqrt(double re, double im,
+ double &re_1, double &im_1,
+ double &re_2, double &im_2) {
+ if (re == 0.0 && im == 0.0) {
+ re_1 = re_2 = re;
+ im_1 = im_2 = im;
+ } else {
+ double d = sqrt(re * re + im * im);
+ re_1 = sqrt((d + re) / 2.0);
+ re_2 = re_1;
+ im_1 = fabs(sqrt((d - re) / 2.0));
+ im_2 = -im_1;
+ }
+ }
+
+ void cplx_cbrt(double re, double im,
+ double &re_1, double &im_1,
+ double &re_2, double &im_2,
+ double &re_3, double &im_3) {
+ if (re == 0.0 && im == 0.0) {
+ re_1 = re_2 = re_3 = re;
+ im_1 = im_2 = im_3 = im;
+ } else {
+ double r = cbrt(sqrt(re * re + im * im));
+ double t = atan2(im, re) / 3.0;
+ re_1 = r * cos(t);
+ im_1 = r * sin(t);
+ re_2 = r * cos(t + M_TWOPI / 3.0);
+ im_2 = r * sin(t + M_TWOPI / 3.0);
+ re_3 = r * cos(t + M_TWOPI * 2.0 / 3.0);
+ im_3 = r * sin(t + M_TWOPI * 2.0 / 3.0);
+ }
+ }
+
+ void add_root(std::vector<Root> &roots, double root) {
+ for (size_t i = 0; i < roots.size(); ++i) {
+ if (roots[i].root == root) {
+ roots[i].multiplicity++;
+ return;
+ }
+ }
+ roots.push_back(Root(root));
+ }
+
+ void linear_roots(double c1, double c0, std::vector<Root> &roots) {
+ roots.push_back(Root(c0 / c1));
+ }
+
+ void quadratic_roots(double c2, double c1, double c0, std::vector<Root> &roots) {
+ if (fabs(c2) < EPS) {
+ linear_roots(c1, c0, roots);
+ return;
+ }
+
+ double p = 0.5 * c1 / c2;
+ double dis = p * p - c0 / c2;
+
+ if (dis > 0.0) {
+ dis = sqrt(dis);
+ if (-p - dis != -p + dis) {
+ roots.push_back(Root(-p - dis));
+ roots.push_back(Root(-p + dis));
+ } else {
+ roots.push_back(Root(-p, 2));
+ }
+ }
+ }
+
+ void cubic_roots(double c3, double c2, double c1, double c0, std::vector<Root> &roots) {
+ int n_sol = 0;
+ double _r[3];
+
+ if (fabs(c3) < EPS) {
+ quadratic_roots(c2, c1, c0, roots);
+ return;
+ }
+
+ if (fabs(c0) < EPS) {
+ quadratic_roots(c3, c2, c1, roots);
+ add_root(roots, 0.0);
+ return;
+ }
+
+ double xN = -c2 / (3.0 * c3);
+ double yN = c0 + xN * (c1 + xN * (c2 + c3 * xN));
+
+ double delta_sq = (c2 * c2 - 3.0 * c3 * c1) / (9.0 * c3 * c3);
+ double h_sq = 4.0 / 9.0 * (c2 * c2 - 3.0 * c3 * c1) * (delta_sq * delta_sq);
+ double dis = yN * yN - h_sq;
+
+ if (dis > EPS) {
+ // One real root, two complex roots.
+
+ double dis_sqrt = sqrt(dis);
+ double r_p = yN - dis_sqrt;
+ double r_q = yN + dis_sqrt;
+ double p = cbrt(fabs(r_p)/(2.0 * c3));
+ double q = cbrt(fabs(r_q)/(2.0 * c3));
+
+ if (r_p > 0.0) p = -p;
+ if (r_q > 0.0) q = -q;
+
+ _r[0] = xN + p + q;
+ n_sol = 1;
+
+ double re = xN - p * .5 - q * .5;
+ double im = p * M_SQRT_3_4 - q * M_SQRT_3_4;
+
+ // root 2: xN + p * exp(M_2PI_3.i) + q * exp(-M_2PI_3.i);
+ // root 3: complex conjugate of root 2
+
+ if (im < EPS) {
+ _r[1] = _r[2] = re;
+ n_sol += 2;
+ }
+ } else if (dis < -EPS) {
+ // Three distinct real roots.
+ double theta = acos(-yN / sqrt(h_sq)) / 3.0;
+ double delta = sqrt(c2 * c2 - 3.0 * c3 * c1) / (3.0 * c3);
+
+ _r[0] = xN + (2.0 * delta) * cos(theta);
+ _r[1] = xN + (2.0 * delta) * cos(M_2PI_3 - theta);
+ _r[2] = xN + (2.0 * delta) * cos(M_2PI_3 + theta);
+ n_sol = 3;
+ } else {
+ // Three real roots (two or three equal).
+ double r = yN / (2.0 * c3);
+ double delta = cbrt(r);
+
+ _r[0] = xN + delta;
+ _r[1] = xN + delta;
+ _r[2] = xN - 2.0 * delta;
+ n_sol = 3;
+ }
+
+ for (int i=0; i < n_sol; i++) {
+ add_root(roots, _r[i]);
+ }
+ }
+
+ static void U(const Matrix3 &m,
+ double l,
+ double u[6],
+ double &u_max,
+ int &u_argmax) {
+ u[0] = (m._22 - l) * (m._33 - l) - m._23 * m._23;
+ u[1] = m._13 * m._23 - m._12 * (m._33 - l);
+ u[2] = m._12 * m._23 - m._13 * (m._22 - l);
+ u[3] = (m._11 - l) * (m._33 - l) - m._13 * m._13;
+ u[4] = m._12 * m._13 - m._23 * (m._11 - l);
+ u[5] = (m._11 - l) * (m._22 - l) - m._12 * m._12;
+
+ u_max = -1.0;
+ u_argmax = -1;
+
+ for (int i = 0; i < 6; ++i) {
+ if (u_max < fabs(u[i])) { u_max = fabs(u[i]); u_argmax = i; }
+ }
+ }
+
+ static void eig1(const Matrix3 &m, double l, carve::geom::vector<3> &e) {
+ double u[6];
+ double u_max;
+ int u_argmax;
+
+ U(m, l, u, u_max, u_argmax);
+
+ switch(u_argmax) {
+ case 0:
+ e.x = u[0]; e.y = u[1]; e.z = u[2]; break;
+ case 1: case 3:
+ e.x = u[1]; e.y = u[3]; e.z = u[4]; break;
+ case 2: case 4: case 5:
+ e.x = u[2]; e.y = u[4]; e.z = u[5]; break;
+ }
+ e.normalize();
+ }
+
+ static void eig2(const Matrix3 &m, double l, carve::geom::vector<3> &e1, carve::geom::vector<3> &e2) {
+ double u[6];
+ double u_max;
+ int u_argmax;
+
+ U(m, l, u, u_max, u_argmax);
+
+ switch(u_argmax) {
+ case 0: case 1:
+ e1.x = -m._12; e1.y = m._11; e1.z = 0.0;
+ e2.x = -m._13 * m._11; e2.y = -m._13 * m._12; e2.z = m._11 * m._11 + m._12 * m._12;
+ break;
+ case 2:
+ e1.x = m._12; e1.y = 0.0; e1.z = -m._11;
+ e2.x = -m._12 * m._11; e2.y = m._11 * m._11 + m._13 * m._13; e2.z = -m._12 * m._13;
+ break;
+ case 3: case 4:
+ e1.x = 0.0; e1.y = -m._23; e1.z = -m._22;
+ e2.x = m._22 * m._22 + m._23 * m._23; e2.y = -m._12 * m._22; e2.z = -m._12 * m._23;
+ break;
+ case 5:
+ e1.x = 0.0; e1.y = -m._33; e1.z = m._23;
+ e2.x = m._23 * m._23 + m._33 * m._33; e2.y = -m._13 * m._23; e2.z = -m._13 * m._33;
+ }
+ e1.normalize();
+ e2.normalize();
+ }
+
+ static void eig3(const Matrix3 &m,
+ double l,
+ carve::geom::vector<3> &e1,
+ carve::geom::vector<3> &e2,
+ carve::geom::vector<3> &e3) {
+ e1.x = 1.0; e1.y = 0.0; e1.z = 0.0;
+ e2.x = 0.0; e2.y = 1.0; e2.z = 0.0;
+ e3.x = 0.0; e3.y = 0.0; e3.z = 1.0;
+ }
+
+ void eigSolveSymmetric(const Matrix3 &m,
+ double &l1, carve::geom::vector<3> &e1,
+ double &l2, carve::geom::vector<3> &e2,
+ double &l3, carve::geom::vector<3> &e3) {
+ double c0 =
+ m._11 * m._22 * m._33 +
+ 2.0 * m._12 * m._13 * m._23 -
+ m._11 * m._23 * m._23 -
+ m._22 * m._13 * m._13 -
+ m._33 * m._12 * m._12;
+ double c1 =
+ m._11 * m._22 -
+ m._12 * m._12 +
+ m._11 * m._33 -
+ m._13 * m._13 +
+ m._22 * m._33 -
+ m._23 * m._23;
+ double c2 =
+ m._11 +
+ m._22 +
+ m._33;
+
+ double a = (3.0 * c1 - c2 * c2) / 3.0;
+ double b = (-2.0 * c2 * c2 * c2 + 9.0 * c1 * c2 - 27.0 * c0) / 27.0;
+
+ double Q = b * b / 4.0 + a * a * a / 27.0;
+
+ if (fabs(Q) < 1e-16) {
+ l1 = m._11; e1.x = 1.0; e1.y = 0.0; e1.z = 0.0;
+ l2 = m._22; e2.x = 0.0; e2.y = 1.0; e2.z = 0.0;
+ l3 = m._33; e3.x = 0.0; e3.y = 0.0; e3.z = 1.0;
+ } else if (Q > 0) {
+ l1 = l2 = c2 / 3.0 + cbrt(b / 2.0);
+ l3 = c2 / 3.0 - 2.0 * cbrt(b / 2.0);
+
+ eig2(m, l1, e1, e2);
+ eig1(m, l3, e3);
+ } else if (Q < 0) {
+ double t = atan2(sqrt(-Q), -b / 2.0);
+ double cos_t3 = cos(t / 3.0);
+ double sin_t3 = sin(t / 3.0);
+ double r = cbrt(sqrt(b * b / 4.0 - Q));
+
+ l1 = c2 / 3.0 + 2 * r * cos_t3;
+ l2 = c2 / 3.0 - r * (cos_t3 + M_SQRT_3 * sin_t3);
+ l3 = c2 / 3.0 - r * (cos_t3 - M_SQRT_3 * sin_t3);
+
+ eig1(m, l1, e1);
+ eig1(m, l2, e2);
+ eig1(m, l3, e3);
+ }
+ }
+
+ void eigSolve(const Matrix3 &m, double &l1, double &l2, double &l3) {
+ double c3, c2, c1, c0;
+ std::vector<Root> roots;
+
+ c3 = -1.0;
+ c2 = m._11 + m._22 + m._33;
+ c1 =
+ -(m._22 * m._33 + m._11 * m._22 + m._11 * m._33)
+ +(m._23 * m._32 + m._13 * m._31 + m._12 * m._21);
+ c0 =
+ +(m._11 * m._22 - m._12 * m._21) * m._33
+ -(m._11 * m._23 - m._13 * m._21) * m._32
+ +(m._12 * m._23 - m._13 * m._22) * m._31;
+
+ cubic_roots(c3, c2, c1, c0, roots);
+
+ for (size_t i = 0; i < roots.size(); i++) {
+ Matrix3 M(m);
+ M._11 -= roots[i].root;
+ M._22 -= roots[i].root;
+ M._33 -= roots[i].root;
+ // solve M.v = 0
+ }
+
+ std::cerr << "n_roots=" << roots.size() << std::endl;
+ for (size_t i = 0; i < roots.size(); i++) {
+ fprintf(stderr, " %.24f(%d)", roots[i].root, roots[i].multiplicity);
+ }
+ std::cerr << std::endl;
+ }
+
+ }
+}
+
diff --git a/extern/carve/lib/mesh.cpp b/extern/carve/lib/mesh.cpp
new file mode 100644
index 00000000000..55ab893c10a
--- /dev/null
+++ b/extern/carve/lib/mesh.cpp
@@ -0,0 +1,1203 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/mesh.hpp>
+#include <carve/mesh_impl.hpp>
+#include <carve/rtree.hpp>
+
+#include <carve/poly.hpp>
+
+namespace {
+ inline double CALC_X(const carve::geom::plane<3> &p, double y, double z) { return -(p.d + p.N.y * y + p.N.z * z) / p.N.x; }
+ inline double CALC_Y(const carve::geom::plane<3> &p, double x, double z) { return -(p.d + p.N.x * x + p.N.z * z) / p.N.y; }
+ inline double CALC_Z(const carve::geom::plane<3> &p, double x, double y) { return -(p.d + p.N.x * x + p.N.y * y) / p.N.z; }
+
+ carve::geom::vector<2> _project_1(const carve::geom::vector<3> &v) {
+ return carve::geom::VECTOR(v.z, v.y);
+ }
+
+ carve::geom::vector<2> _project_2(const carve::geom::vector<3> &v) {
+ return carve::geom::VECTOR(v.x, v.z);
+ }
+
+ carve::geom::vector<2> _project_3(const carve::geom::vector<3> &v) {
+ return carve::geom::VECTOR(v.y, v.x);
+ }
+
+ carve::geom::vector<2> _project_4(const carve::geom::vector<3> &v) {
+ return carve::geom::VECTOR(v.y, v.z);
+ }
+
+ carve::geom::vector<2> _project_5(const carve::geom::vector<3> &v) {
+ return carve::geom::VECTOR(v.z, v.x);
+ }
+
+ carve::geom::vector<2> _project_6(const carve::geom::vector<3> &v) {
+ return carve::geom::VECTOR(v.x, v.y);
+ }
+
+ carve::geom::vector<3> _unproject_1(const carve::geom::vector<2> &p, const carve::geom3d::Plane &plane) {
+ return carve::geom::VECTOR(CALC_X(plane, p.y, p.x), p.y, p.x);
+ }
+
+ carve::geom::vector<3> _unproject_2(const carve::geom::vector<2> &p, const carve::geom3d::Plane &plane) {
+ return carve::geom::VECTOR(p.x, CALC_Y(plane, p.x, p.y), p.y);
+ }
+
+ carve::geom::vector<3> _unproject_3(const carve::geom::vector<2> &p, const carve::geom3d::Plane &plane) {
+ return carve::geom::VECTOR(p.y, p.x, CALC_Z(plane, p.y, p.x));
+ }
+
+ carve::geom::vector<3> _unproject_4(const carve::geom::vector<2> &p, const carve::geom3d::Plane &plane) {
+ return carve::geom::VECTOR(CALC_X(plane, p.x, p.y), p.x, p.y);
+ }
+
+ carve::geom::vector<3> _unproject_5(const carve::geom::vector<2> &p, const carve::geom3d::Plane &plane) {
+ return carve::geom::VECTOR(p.y, CALC_Y(plane, p.y, p.x), p.x);
+ }
+
+ carve::geom::vector<3> _unproject_6(const carve::geom::vector<2> &p, const carve::geom3d::Plane &plane) {
+ return carve::geom::VECTOR(p.x, p.y, CALC_Z(plane, p.x, p.y));
+ }
+
+ static carve::geom::vector<2> (*project_tab[2][3])(const carve::geom::vector<3> &) = {
+ { &_project_1, &_project_2, &_project_3 },
+ { &_project_4, &_project_5, &_project_6 }
+ };
+
+ static carve::geom::vector<3> (*unproject_tab[2][3])(const carve::geom::vector<2> &, const carve::geom3d::Plane &) = {
+ { &_unproject_1, &_unproject_2, &_unproject_3 },
+ { &_unproject_4, &_unproject_5, &_unproject_6 }
+ };
+
+}
+
+namespace carve {
+ namespace mesh {
+
+
+
+ template<unsigned ndim>
+ typename Face<ndim>::project_t Face<ndim>::getProjector(bool positive_facing, int axis) const {
+ return NULL;
+ }
+
+
+
+ template<>
+ Face<3>::project_t Face<3>::getProjector(bool positive_facing, int axis) const {
+ return project_tab[positive_facing ? 1 : 0][axis];
+ }
+
+
+
+ template<unsigned ndim>
+ typename Face<ndim>::unproject_t Face<ndim>::getUnprojector(bool positive_facing, int axis) const {
+ return NULL;
+ }
+
+
+
+ template<>
+ Face<3>::unproject_t Face<3>::getUnprojector(bool positive_facing, int axis) const {
+ return unproject_tab[positive_facing ? 1 : 0][axis];
+ }
+
+
+
+ template<unsigned ndim>
+ bool Face<ndim>::containsPoint(const vector_t &p) const {
+ if (!carve::math::ZERO(carve::geom::distance(plane, p))) return false;
+ // return pointInPolySimple(vertices, projector(), (this->*project)(p));
+ std::vector<carve::geom::vector<2> > verts;
+ getProjectedVertices(verts);
+ return carve::geom2d::pointInPoly(verts, project(p)).iclass != carve::POINT_OUT;
+ }
+
+
+
+ template<unsigned ndim>
+ bool Face<ndim>::containsPointInProjection(const vector_t &p) const {
+ std::vector<carve::geom::vector<2> > verts;
+ getProjectedVertices(verts);
+ return carve::geom2d::pointInPoly(verts, project(p)).iclass != carve::POINT_OUT;
+ }
+
+
+
+ template<unsigned ndim>
+ bool Face<ndim>::simpleLineSegmentIntersection(
+ const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const {
+ if (!line.OK()) return false;
+
+ carve::mesh::MeshSet<3>::vertex_t::vector_t p;
+ carve::IntersectionClass intersects =
+ carve::geom3d::lineSegmentPlaneIntersection(plane, line, p);
+ if (intersects == carve::INTERSECT_NONE || intersects == carve::INTERSECT_BAD) {
+ return false;
+ }
+
+ std::vector<carve::geom::vector<2> > verts;
+ getProjectedVertices(verts);
+ if (carve::geom2d::pointInPolySimple(verts, project(p))) {
+ intersection = p;
+ return true;
+ }
+ return false;
+ }
+
+
+
+ template<unsigned ndim>
+ IntersectionClass Face<ndim>::lineSegmentIntersection(const carve::geom::linesegment<ndim> &line,
+ vector_t &intersection) const {
+ if (!line.OK()) return INTERSECT_NONE;
+
+
+ vector_t p;
+ IntersectionClass intersects = carve::geom3d::lineSegmentPlaneIntersection(plane, line, p);
+ if (intersects == INTERSECT_NONE || intersects == INTERSECT_BAD) {
+ return intersects;
+ }
+
+ std::vector<carve::geom::vector<2> > verts;
+ getProjectedVertices(verts);
+ carve::geom2d::PolyInclusionInfo pi = carve::geom2d::pointInPoly(verts, project(p));
+ switch (pi.iclass) {
+ case POINT_VERTEX:
+ intersection = p;
+ return INTERSECT_VERTEX;
+
+ case POINT_EDGE:
+ intersection = p;
+ return INTERSECT_EDGE;
+
+ case POINT_IN:
+ intersection = p;
+ return INTERSECT_FACE;
+
+ case POINT_OUT:
+ return INTERSECT_NONE;
+
+ default:
+ break;
+ }
+ return INTERSECT_NONE;
+ }
+
+
+
+ template<unsigned ndim>
+ Face<ndim> *Face<ndim>::closeLoop(typename Face<ndim>::edge_t *start) {
+ edge_t *e = start;
+ std::vector<edge_t *> loop_edges;
+ do {
+ CARVE_ASSERT(e->rev == NULL);
+ loop_edges.push_back(e);
+ e = e->perimNext();
+ } while (e != start);
+
+ const size_t N = loop_edges.size();
+ for (size_t i = 0; i < N; ++i) {
+ loop_edges[i]->rev = new edge_t(loop_edges[i]->v2(), NULL);
+ }
+
+ for (size_t i = 0; i < N; ++i) {
+ edge_t *e1 = loop_edges[i]->rev;
+ edge_t *e2 = loop_edges[(i+1)%N]->rev;
+ e1->prev = e2;
+ e2->next = e1;
+ }
+
+ Face *f = new Face(start->rev);
+
+ CARVE_ASSERT(f->n_edges == N);
+
+ return f;
+ }
+
+
+
+ namespace detail {
+
+
+
+ bool FaceStitcher::EdgeOrderData::Cmp::operator()(const EdgeOrderData &a, const EdgeOrderData &b) const {
+ int v = carve::geom3d::compareAngles(edge_dir, base_dir, a.face_dir, b.face_dir);
+ double da = carve::geom3d::antiClockwiseAngle(base_dir, a.face_dir, edge_dir);
+ double db = carve::geom3d::antiClockwiseAngle(base_dir, b.face_dir, edge_dir);
+ int v0 = v;
+ v = 0;
+ if (da < db) v = -1;
+ if (db < da) v = +1;
+ if (v0 != v) {
+ std::cerr << "v0= " << v0 << " v= " << v << " da= " << da << " db= " << db << " " << edge_dir << " " << base_dir << " " << a.face_dir << b.face_dir << std::endl;
+ }
+ if (v < 0) return true;
+ if (v == 0) {
+ if (a.is_reversed && !b.is_reversed) return true;
+ if (a.is_reversed == b.is_reversed) {
+ return a.group_id < b.group_id;
+ }
+ }
+ return false;
+ }
+
+
+
+ void FaceStitcher::matchSimpleEdges() {
+ // join faces that share an edge, where no other faces are incident.
+ for (edge_map_t::iterator i = edges.begin(); i != edges.end(); ++i) {
+ const vpair_t &ev = (*i).first;
+ edge_map_t::iterator j = edges.find(vpair_t(ev.second, ev.first));
+ if (j == edges.end()) {
+ for (edgelist_t::iterator k = (*i).second.begin(); k != (*i).second.end(); ++k) {
+ is_open[ (*k)->face->id] = true;
+ }
+ } else if ((*i).second.size() != 1 || (*j).second.size() != 1) {
+ std::swap(complex_edges[(*i).first], (*i).second);
+ } else {
+ // simple edge.
+ edge_t *a = (*i).second.front();
+ edge_t *b = (*j).second.front();
+ if (a < b) {
+ // every simple edge pair is encountered twice. only merge once.
+ a->rev = b;
+ b->rev = a;
+ face_groups.merge_sets(a->face->id, b->face->id);
+ }
+ }
+ }
+ }
+
+
+
+ size_t FaceStitcher::faceGroupID(const Face<3> *face) {
+ return face_groups.find_set_head(face->id);
+ }
+
+
+
+ size_t FaceStitcher::faceGroupID(const Edge<3> *edge) {
+ return face_groups.find_set_head(edge->face->id);
+ }
+
+
+
+ void FaceStitcher::orderForwardAndReverseEdges(std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev,
+ std::vector<std::vector<EdgeOrderData> > &result) {
+ const size_t Nfwd = efwd.size();
+ const size_t Nrev = erev.size();
+ const size_t N = efwd[0].size();
+
+ result.resize(N);
+
+ for (size_t i = 0; i < N; ++i) {
+ Edge<3> *base = efwd[0][i];
+
+ result[i].reserve(Nfwd + Nrev);
+ for (size_t j = 0; j < Nfwd; ++j) {
+ result[i].push_back(EdgeOrderData(efwd[j][i], j, false));
+ CARVE_ASSERT(efwd[0][i]->v1() == efwd[j][i]->v1());
+ CARVE_ASSERT(efwd[0][i]->v2() == efwd[j][i]->v2());
+ }
+ for (size_t j = 0; j < Nrev; ++j) {
+ result[i].push_back(EdgeOrderData(erev[j][i], j, true));
+ CARVE_ASSERT(erev[0][i]->v1() == erev[j][i]->v1());
+ CARVE_ASSERT(erev[0][i]->v2() == erev[j][i]->v2());
+ }
+
+ std::sort(result[i].begin(),
+ result[i].end(),
+ EdgeOrderData::Cmp(base->v2()->v - base->v1()->v, result[i][0].face_dir));
+ }
+ }
+
+
+
+ void FaceStitcher::edgeIncidentGroups(const vpair_t &e,
+ const edge_map_t &all_edges,
+ std::pair<std::set<size_t>, std::set<size_t> > &groups) {
+ groups.first.clear();
+ groups.second.clear();
+ edge_map_t::const_iterator i;
+
+ i = all_edges.find(e);
+ if (i != all_edges.end()) {
+ for (edgelist_t::const_iterator j = (*i).second.begin(); j != (*i).second.end(); ++j) {
+ groups.first.insert(faceGroupID(*j));
+ }
+ }
+
+ i = all_edges.find(vpair_t(e.second, e.first));
+ if (i != all_edges.end()) {
+ for (edgelist_t::const_iterator j = (*i).second.begin(); j != (*i).second.end(); ++j) {
+ groups.second.insert(faceGroupID(*j));
+ }
+ }
+ }
+
+
+
+ void FaceStitcher::buildEdgeGraph(const edge_map_t &all_edges) {
+ for (edge_map_t::const_iterator i = all_edges.begin();
+ i != all_edges.end();
+ ++i) {
+ edge_graph[(*i).first.first].insert((*i).first.second);
+ }
+ }
+
+
+
+ void FaceStitcher::extractPath(std::vector<const vertex_t *> &path) {
+ path.clear();
+
+ edge_graph_t::iterator iter = edge_graph.begin();
+
+
+ const vertex_t *init = (*iter).first;
+ const vertex_t *next = *(*iter).second.begin();
+ const vertex_t *prev = NULL;
+ const vertex_t *vert = init;
+
+ while ((*iter).second.size() == 2) {
+ prev = *std::find_if((*iter).second.begin(),
+ (*iter).second.end(),
+ std::bind2nd(std::not_equal_to<const vertex_t *>(), next));
+ next = vert;
+ vert = prev;
+ iter = edge_graph.find(vert);
+ CARVE_ASSERT(iter != edge_graph.end());
+ if (vert == init) break;
+ }
+ init = vert;
+
+ std::vector<const edge_t *> efwd;
+ std::vector<const edge_t *> erev;
+
+ edge_map_t::iterator edgeiter;
+ edgeiter = complex_edges.find(vpair_t(vert, next));
+ std::copy((*edgeiter).second.begin(), (*edgeiter).second.end(), std::back_inserter(efwd));
+
+ edgeiter = complex_edges.find(vpair_t(next, vert));
+ std::copy((*edgeiter).second.begin(), (*edgeiter).second.end(), std::back_inserter(erev));
+
+ path.push_back(vert);
+
+ prev = vert;
+ vert = next;
+ path.push_back(vert);
+ iter = edge_graph.find(vert);
+ CARVE_ASSERT(iter != edge_graph.end());
+
+ while (vert != init && (*iter).second.size() == 2) {
+ next = *std::find_if((*iter).second.begin(),
+ (*iter).second.end(),
+ std::bind2nd(std::not_equal_to<const vertex_t *>(), prev));
+
+ edgeiter = complex_edges.find(vpair_t(vert, next));
+ if ((*edgeiter).second.size() != efwd.size()) goto done;
+
+ for (size_t i = 0; i < efwd.size(); ++i) {
+ Edge<3> *e_next = efwd[i]->perimNext();
+ if (e_next->v2() != next) goto done;
+ efwd[i] = e_next;
+ }
+
+ edgeiter = complex_edges.find(vpair_t(next, vert));
+ if ((*edgeiter).second.size() != erev.size()) goto done;
+
+ for (size_t i = 0; i < erev.size(); ++i) {
+ Edge<3> *e_prev = erev[i]->perimPrev();
+ if (e_prev->v1() != next) goto done;
+ erev[i] = e_prev;
+ }
+
+ prev = vert;
+ vert = next;
+ path.push_back(vert);
+ iter = edge_graph.find(vert);
+ CARVE_ASSERT(iter != edge_graph.end());
+ }
+ done:;
+ }
+
+
+
+ void FaceStitcher::removePath(const std::vector<const vertex_t *> &path) {
+ for (size_t i = 1; i < path.size() - 1; ++i) {
+ edge_graph.erase(path[i]);
+ }
+
+ edge_graph[path[0]].erase(path[1]);
+ if (edge_graph[path[0]].size() == 0) {
+ edge_graph.erase(path[0]);
+ }
+
+ edge_graph[path[path.size()-1]].erase(path[path.size()-2]);
+ if (edge_graph[path[path.size()-1]].size() == 0) {
+ edge_graph.erase(path[path.size()-1]);
+ }
+ }
+
+
+
+ void FaceStitcher::reorder(std::vector<EdgeOrderData> &ordering,
+ size_t grp) {
+ if (!ordering[0].is_reversed && ordering[0].group_id == grp) return;
+ for (size_t i = 1; i < ordering.size(); ++i) {
+ if (!ordering[i].is_reversed && ordering[i].group_id == grp) {
+ std::vector<EdgeOrderData> temp;
+ temp.reserve(ordering.size());
+ std::copy(ordering.begin() + i, ordering.end(), std::back_inserter(temp));
+ std::copy(ordering.begin(), ordering.begin() + i, std::back_inserter(temp));
+ std::copy(temp.begin(), temp.end(), ordering.begin());
+ return;
+ }
+ }
+ }
+
+
+
+ struct lt_second {
+ template<typename pair_t>
+ bool operator()(const pair_t &a, const pair_t &b) const {
+ return a.second < b.second;
+ }
+ };
+
+
+
+ void FaceStitcher::fuseEdges(std::vector<Edge<3> *> &fwd,
+ std::vector<Edge<3> *> &rev) {
+ for (size_t i = 0; i < fwd.size(); ++i) {
+ fwd[i]->rev = rev[i];
+ rev[i]->rev = fwd[i];
+ face_groups.merge_sets(fwd[i]->face->id, rev[i]->face->id);
+ }
+ }
+
+
+
+ void FaceStitcher::joinGroups(std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev,
+ size_t fwd_grp,
+ size_t rev_grp) {
+ fuseEdges(efwd[fwd_grp], erev[rev_grp]);
+ }
+
+
+
+ void FaceStitcher::matchOrderedEdges(const std::vector<std::vector<EdgeOrderData> >::iterator begin,
+ const std::vector<std::vector<EdgeOrderData> >::iterator end,
+ std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev) {
+ typedef std::unordered_map<std::pair<size_t, size_t>, size_t> pair_counts_t;
+ for (;;) {
+ pair_counts_t pair_counts;
+
+ for (std::vector<std::vector<EdgeOrderData> >::iterator i = begin; i != end; ++i) {
+ std::vector<EdgeOrderData> &e = *i;
+ for (size_t j = 0; j < e.size(); ++j) {
+ if (!e[j].is_reversed && e[(j+1)%e.size()].is_reversed) {
+ pair_counts[std::make_pair(e[j].group_id,
+ e[(j+1)%e.size()].group_id)]++;
+ }
+ }
+ }
+
+ if (!pair_counts.size()) break;
+
+ std::vector<std::pair<size_t, std::pair<size_t, size_t> > > counts;
+ counts.reserve(pair_counts.size());
+ for (pair_counts_t::iterator iter = pair_counts.begin(); iter != pair_counts.end(); ++iter) {
+ counts.push_back(std::make_pair((*iter).second, (*iter).first));
+ }
+ std::make_heap(counts.begin(), counts.end());
+
+ std::set<size_t> rem_fwd, rem_rev;
+
+ while (counts.size()) {
+ std::pair<size_t, size_t> join = counts.front().second;
+ std::pop_heap(counts.begin(), counts.end());
+ counts.pop_back();
+ if (rem_fwd.find(join.first) != rem_fwd.end()) continue;
+ if (rem_rev.find(join.second) != rem_rev.end()) continue;
+
+ size_t g1 = join.first;
+ size_t g2 = join.second;
+
+ joinGroups(efwd, erev, g1, g2);
+
+ for (std::vector<std::vector<EdgeOrderData> >::iterator i = begin; i != end; ++i) {
+ (*i).erase(std::remove_if((*i).begin(), (*i).end(), EdgeOrderData::TestGroups(g1, g2)), (*i).end());
+ }
+
+ rem_fwd.insert(g1);
+ rem_rev.insert(g2);
+ }
+ }
+ }
+
+
+
+ void FaceStitcher::resolveOpenEdges() {
+ // Remove open regions of mesh. Doing this may make additional
+ // edges simple (for example, removing a fin from the edge of
+ // a cube), and may also expose more open mesh regions. In the
+ // latter case, the process must be repeated to deal with the
+ // newly uncovered regions.
+ std::unordered_set<size_t> open_groups;
+
+ for (size_t i = 0; i < is_open.size(); ++i) {
+ if (is_open[i]) open_groups.insert(face_groups.find_set_head(i));
+ }
+
+ while (!open_groups.empty()) {
+ std::list<vpair_t> edge_0, edge_1;
+
+ for (edge_map_t::iterator i = complex_edges.begin(); i != complex_edges.end(); ++i) {
+ bool was_modified = false;
+ for(edgelist_t::iterator j = (*i).second.begin(); j != (*i).second.end(); ) {
+ if (open_groups.find(faceGroupID(*j)) != open_groups.end()) {
+ j = (*i).second.erase(j);
+ was_modified = true;
+ } else {
+ ++j;
+ }
+ }
+ if (was_modified) {
+ if ((*i).second.empty()) {
+ edge_0.push_back((*i).first);
+ } else if ((*i).second.size() == 1) {
+ edge_1.push_back((*i).first);
+ }
+ }
+ }
+
+ for (std::list<vpair_t>::iterator i = edge_1.begin(); i != edge_1.end(); ++i) {
+ vpair_t e1 = *i;
+ edge_map_t::iterator e1i = complex_edges.find(e1);
+ if (e1i == complex_edges.end()) continue;
+ vpair_t e2 = vpair_t(e1.second, e1.first);
+ edge_map_t::iterator e2i = complex_edges.find(e2);
+ CARVE_ASSERT(e2i != complex_edges.end()); // each complex edge should have a mate.
+
+ if ((*e2i).second.size() == 1) {
+ // merge newly simple edges, delete both from complex_edges.
+ edge_t *a = (*e1i).second.front();
+ edge_t *b = (*e2i).second.front();
+ a->rev = b;
+ b->rev = a;
+ face_groups.merge_sets(a->face->id, b->face->id);
+ complex_edges.erase(e1i);
+ complex_edges.erase(e2i);
+ }
+ }
+
+ open_groups.clear();
+
+ for (std::list<vpair_t>::iterator i = edge_0.begin(); i != edge_0.end(); ++i) {
+ vpair_t e1 = *i;
+ edge_map_t::iterator e1i = complex_edges.find(e1);
+ vpair_t e2 = vpair_t(e1.second, e1.first);
+ edge_map_t::iterator e2i = complex_edges.find(e2);
+ if (e2i == complex_edges.end()) {
+ // This could occur, for example, when two faces share
+ // an edge in the same direction, but are both not
+ // touching anything else. Both get removed by the open
+ // group removal code, leaving an edge map with zero
+ // edges. The edge in the opposite direction does not
+ // exist, because there's no face that adjoins either of
+ // the two open faces.
+ continue;
+ }
+
+ for (edgelist_t::iterator j = (*e2i).second.begin(); j != (*e2i).second.end(); ++j) {
+ open_groups.insert(faceGroupID(*j));
+ }
+ complex_edges.erase(e1i);
+ complex_edges.erase(e2i);
+ }
+ }
+ }
+
+
+
+ void FaceStitcher::extractConnectedEdges(std::vector<const vertex_t *>::iterator begin,
+ std::vector<const vertex_t *>::iterator end,
+ std::vector<std::vector<Edge<3> *> > &efwd,
+ std::vector<std::vector<Edge<3> *> > &erev) {
+ const size_t N = std::distance(begin, end) - 1;
+
+ std::vector<const vertex_t *>::iterator e1, e2;
+ e1 = e2 = begin; ++e2;
+ vpair_t start_f = vpair_t(*e1, *e2);
+ vpair_t start_r = vpair_t(*e2, *e1);
+
+ const size_t Nfwd = complex_edges[start_f].size();
+ const size_t Nrev = complex_edges[start_r].size();
+
+ size_t j;
+ edgelist_t::iterator ji;
+
+ efwd.clear(); efwd.resize(Nfwd);
+ erev.clear(); erev.resize(Nrev);
+
+ for (j = 0, ji = complex_edges[start_f].begin();
+ ji != complex_edges[start_f].end();
+ ++j, ++ji) {
+ efwd[j].reserve(N);
+ efwd[j].push_back(*ji);
+ }
+
+ for (j = 0, ji = complex_edges[start_r].begin();
+ ji != complex_edges[start_r].end();
+ ++j, ++ji) {
+ erev[j].reserve(N);
+ erev[j].push_back(*ji);
+ }
+
+ std::vector<Edge<3> *> temp_f, temp_r;
+ temp_f.resize(Nfwd);
+ temp_r.resize(Nrev);
+
+ for (j = 1; j < N; ++j) {
+ ++e1; ++e2;
+ vpair_t ef = vpair_t(*e1, *e2);
+ vpair_t er = vpair_t(*e2, *e1);
+
+ if (complex_edges[ef].size() != Nfwd || complex_edges[ef].size() != Nrev) break;
+
+ for (size_t k = 0; k < Nfwd; ++k) {
+ Edge<3> *e_next = efwd[k].back()->perimNext();
+ CARVE_ASSERT(e_next == NULL || e_next->rev == NULL);
+ if (e_next == NULL || e_next->v2() != *e2) goto done;
+ CARVE_ASSERT(e_next->v1() == *e1);
+ CARVE_ASSERT(std::find(complex_edges[ef].begin(), complex_edges[ef].end(), e_next) != complex_edges[ef].end());
+ temp_f[k] = e_next;
+ }
+
+ for (size_t k = 0; k < Nrev; ++k) {
+ Edge<3> *e_next = erev[k].back()->perimPrev();
+ if (e_next == NULL || e_next->v1() != *e2) goto done;
+ CARVE_ASSERT(e_next->v2() == *e1);
+ CARVE_ASSERT(std::find(complex_edges[er].begin(), complex_edges[er].end(), e_next) != complex_edges[er].end());
+ temp_r[k] = e_next;
+ }
+
+ for (size_t k = 0; k < Nfwd; ++k) {
+ efwd[k].push_back(temp_f[k]);
+ }
+
+ for (size_t k = 0; k < Nrev; ++k) {
+ erev[k].push_back(temp_r[k]);
+ }
+ }
+ done:;
+ }
+
+
+
+ void FaceStitcher::construct() {
+ matchSimpleEdges();
+ if (!complex_edges.size()) return;
+
+ resolveOpenEdges();
+ if (!complex_edges.size()) return;
+
+ buildEdgeGraph(complex_edges);
+
+ std::list<std::vector<const vertex_t *> > paths;
+
+ while (edge_graph.size()) {
+ paths.push_back(std::vector<const vertex_t *>());
+ extractPath(paths.back());
+ removePath(paths.back());
+ };
+
+
+ for (std::list<std::vector<const vertex_t *> >::iterator path = paths.begin(); path != paths.end(); ++path) {
+ for (size_t i = 0; i < (*path).size() - 1;) {
+ std::vector<std::vector<Edge<3> *> > efwd, erev;
+
+ extractConnectedEdges((*path).begin() + i, (*path).end(), efwd, erev);
+
+ std::vector<std::vector<EdgeOrderData> > orderings;
+ orderForwardAndReverseEdges(efwd, erev, orderings);
+
+ matchOrderedEdges(orderings.begin(), orderings.end(), efwd, erev);
+ i += efwd[0].size();
+ }
+ }
+ }
+ }
+ }
+
+
+
+ // construct a MeshSet from a Polyhedron, maintaining on the
+ // connectivity information in the Polyhedron.
+ mesh::MeshSet<3> *meshFromPolyhedron(const poly::Polyhedron *poly, int manifold_id) {
+ typedef mesh::Vertex<3> vertex_t;
+ typedef mesh::Vertex<3>::vector_t vector_t;
+ typedef mesh::Edge<3> edge_t;
+ typedef mesh::Face<3> face_t;
+ typedef mesh::Mesh<3> mesh_t;
+ typedef mesh::MeshSet<3> meshset_t;
+
+ std::vector<vertex_t> vertex_storage;
+ vertex_storage.reserve(poly->vertices.size());
+ for (size_t i = 0; i < poly->vertices.size(); ++i) {
+ vertex_storage.push_back(vertex_t(poly->vertices[i].v));
+ }
+
+ std::vector<std::vector<face_t *> > faces;
+ faces.resize(poly->manifold_is_closed.size());
+
+ std::unordered_map<std::pair<size_t, size_t>, std::list<edge_t *> > vertex_to_edge;
+
+ std::vector<vertex_t *> vert_ptrs;
+ for (size_t i = 0; i < poly->faces.size(); ++i) {
+ const poly::Polyhedron::face_t &src = poly->faces[i];
+ if (manifold_id != -1 && src.manifold_id != manifold_id) continue;
+ vert_ptrs.clear();
+ vert_ptrs.reserve(src.nVertices());
+ for (size_t j = 0; j < src.nVertices(); ++j) {
+ size_t vi = poly->vertexToIndex_fast(src.vertex(j));
+ vert_ptrs.push_back(&vertex_storage[vi]);
+ }
+ face_t *face = new face_t(vert_ptrs.begin(), vert_ptrs.end());
+ face->id = src.manifold_id;
+ faces[src.manifold_id].push_back(face);
+
+ edge_t *edge = face->edge;
+ do {
+ vertex_to_edge[std::make_pair(size_t(edge->v1() - &vertex_storage[0]),
+ size_t(edge->v2() - &vertex_storage[0]))].push_back(edge);
+ edge = edge->next;
+ } while (edge != face->edge);
+ }
+
+ // copy connectivity from Polyhedron.
+ for (size_t i = 0; i < poly->edges.size(); ++i) {
+ const poly::Polyhedron::edge_t &src = poly->edges[i];
+ size_t v1i = poly->vertexToIndex_fast(src.v1);
+ size_t v2i = poly->vertexToIndex_fast(src.v2);
+
+ std::list<edge_t *> &efwd = vertex_to_edge[std::make_pair(v1i, v2i)];
+ std::list<edge_t *> &erev = vertex_to_edge[std::make_pair(v2i, v1i)];
+
+ const std::vector<const poly::Polyhedron::face_t *> &facepairs = poly->connectivity.edge_to_face[i];
+ for (size_t j = 0; j < facepairs.size(); j += 2) {
+ const poly::Polyhedron::face_t *fa, *fb;
+ fa = facepairs[j];
+ fb = facepairs[j+1];
+ if (!fa || !fb) continue;
+ CARVE_ASSERT(fa->manifold_id == fb->manifold_id);
+ if (manifold_id != -1 && fa->manifold_id != manifold_id) continue;
+
+ std::list<edge_t *>::iterator efwdi, erevi;
+ for (efwdi = efwd.begin(); efwdi != efwd.end() && (*efwdi)->face->id != (size_t)fa->manifold_id; ++efwdi);
+ for (erevi = erev.begin(); erevi != erev.end() && (*erevi)->face->id != (size_t)fa->manifold_id; ++erevi);
+ CARVE_ASSERT(efwdi != efwd.end() && erevi != erev.end());
+
+ (*efwdi)->rev = (*erevi);
+ (*erevi)->rev = (*efwdi);
+ }
+ }
+
+ std::vector<mesh_t *> meshes;
+ meshes.reserve(faces.size());
+ for (size_t i = 0; i < faces.size(); ++i) {
+ if (faces[i].size()) {
+ meshes.push_back(new mesh_t(faces[i]));
+ }
+ }
+
+ return new meshset_t(vertex_storage, meshes);
+ }
+
+
+
+ static void copyMeshFaces(const mesh::Mesh<3> *mesh,
+ size_t manifold_id,
+ const mesh::Vertex<3> *Vbase,
+ poly::Polyhedron *poly,
+ std::unordered_map<std::pair<size_t, size_t>, std::list<mesh::Edge<3> *> > &edges,
+ std::unordered_map<const mesh::Face<3> *, size_t> &face_map) {
+ std::vector<const poly::Polyhedron::vertex_t *> vert_ptr;
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ mesh::Face<3> *src = mesh->faces[f];
+ vert_ptr.clear();
+ vert_ptr.reserve(src->nVertices());
+ mesh::Edge<3> *e = src->edge;
+ do {
+ vert_ptr.push_back(&poly->vertices[e->vert - Vbase]);
+ edges[std::make_pair(e->v1() - Vbase, e->v2() - Vbase)].push_back(e);
+ e = e->next;
+ } while (e != src->edge);
+
+ face_map[src] = poly->faces.size();;
+
+ poly->faces.push_back(poly::Polyhedron::face_t(vert_ptr));
+ poly->faces.back().manifold_id = manifold_id;
+ poly->faces.back().owner = poly;
+ }
+ }
+
+
+
+ // construct a Polyhedron from a MeshSet
+ poly::Polyhedron *polyhedronFromMesh(const mesh::MeshSet<3> *mesh, int manifold_id) {
+ typedef poly::Polyhedron poly_t;
+ typedef poly::Polyhedron::vertex_t vertex_t;
+ typedef poly::Polyhedron::edge_t edge_t;
+ typedef poly::Polyhedron::face_t face_t;
+
+ poly::Polyhedron *poly = new poly::Polyhedron();
+ const mesh::Vertex<3> *Vbase = &mesh->vertex_storage[0];
+
+ poly->vertices.reserve(mesh->vertex_storage.size());
+ for (size_t i = 0; i < mesh->vertex_storage.size(); ++i) {
+ poly->vertices.push_back(vertex_t(mesh->vertex_storage[i].v));
+ poly->vertices.back().owner = poly;
+ }
+
+ size_t n_faces = 0;
+ if (manifold_id == -1) {
+ poly->manifold_is_closed.resize(mesh->meshes.size());
+ poly->manifold_is_negative.resize(mesh->meshes.size());
+ for (size_t m = 0; m < mesh->meshes.size(); ++m) {
+ n_faces += mesh->meshes[m]->faces.size();
+ poly->manifold_is_closed[m] = mesh->meshes[m]->isClosed();
+ poly->manifold_is_negative[m] = mesh->meshes[m]->isNegative();
+ }
+ } else {
+ poly->manifold_is_closed.resize(1);
+ poly->manifold_is_negative.resize(1);
+ n_faces = mesh->meshes[manifold_id]->faces.size();
+ poly->manifold_is_closed[manifold_id] = mesh->meshes[manifold_id]->isClosed();
+ poly->manifold_is_negative[manifold_id] = mesh->meshes[manifold_id]->isNegative();
+ }
+
+ std::unordered_map<std::pair<size_t, size_t>, std::list<mesh::Edge<3> *> > edges;
+ std::unordered_map<const mesh::Face<3> *, size_t> face_map;
+ poly->faces.reserve(n_faces);
+
+ if (manifold_id == -1) {
+ for (size_t m = 0; m < mesh->meshes.size(); ++m) {
+ copyMeshFaces(mesh->meshes[m], m, Vbase, poly, edges, face_map);
+ }
+ } else {
+ copyMeshFaces(mesh->meshes[manifold_id], 0, Vbase, poly, edges, face_map);
+ }
+
+ size_t n_edges = 0;
+ for (std::unordered_map<std::pair<size_t, size_t>, std::list<mesh::Edge<3> *> >::iterator i = edges.begin(); i != edges.end(); ++i) {
+ if ((*i).first.first < (*i).first.second || edges.find(std::make_pair((*i).first.second, (*i).first.first)) == edges.end()) {
+ n_edges++;
+ }
+ }
+
+ poly->edges.reserve(n_edges);
+ for (std::unordered_map<std::pair<size_t, size_t>, std::list<mesh::Edge<3> *> >::iterator i = edges.begin(); i != edges.end(); ++i) {
+ if ((*i).first.first < (*i).first.second ||
+ edges.find(std::make_pair((*i).first.second, (*i).first.first)) == edges.end()) {
+ poly->edges.push_back(edge_t(&poly->vertices[(*i).first.first],
+ &poly->vertices[(*i).first.second],
+ poly));
+ }
+ }
+
+ poly->initVertexConnectivity();
+
+ // build edge entries for face.
+ for (size_t f = 0; f < poly->faces.size(); ++f) {
+ face_t &face = poly->faces[f];
+ size_t N = face.nVertices();
+ for (size_t v = 0; v < N; ++v) {
+ size_t v1i = poly->vertexToIndex_fast(face.vertex(v));
+ size_t v2i = poly->vertexToIndex_fast(face.vertex((v+1)%N));
+ std::vector<const edge_t *> found_edge;
+ std::set_intersection(poly->connectivity.vertex_to_edge[v1i].begin(), poly->connectivity.vertex_to_edge[v1i].end(),
+ poly->connectivity.vertex_to_edge[v2i].begin(), poly->connectivity.vertex_to_edge[v2i].end(),
+ std::back_inserter(found_edge));
+ CARVE_ASSERT(found_edge.size() == 1);
+ face.edge(v) = found_edge[0];
+ }
+ }
+
+ poly->connectivity.edge_to_face.resize(poly->edges.size());
+
+ for (size_t i = 0; i < poly->edges.size(); ++i) {
+ size_t v1i = poly->vertexToIndex_fast(poly->edges[i].v1);
+ size_t v2i = poly->vertexToIndex_fast(poly->edges[i].v2);
+ std::list<mesh::Edge<3> *> &efwd = edges[std::make_pair(v1i, v2i)];
+ std::list<mesh::Edge<3> *> &erev = edges[std::make_pair(v1i, v2i)];
+
+ for (std::list<mesh::Edge<3> *>::iterator j = efwd.begin(); j != efwd.end(); ++j) {
+ mesh::Edge<3> *edge = *j;
+ if (face_map.find(edge->face) != face_map.end()) {
+ poly->connectivity.edge_to_face[i].push_back(&poly->faces[face_map[edge->face]]);
+ if (edge->rev == NULL) {
+ poly->connectivity.edge_to_face[i].push_back(NULL);
+ } else {
+ poly->connectivity.edge_to_face[i].push_back(&poly->faces[face_map[edge->rev->face]]);
+ }
+ }
+ }
+ for (std::list<mesh::Edge<3> *>::iterator j = erev.begin(); j != erev.end(); ++j) {
+ mesh::Edge<3> *edge = *j;
+ if (face_map.find(edge->face) != face_map.end()) {
+ if (edge->rev == NULL) {
+ poly->connectivity.edge_to_face[i].push_back(NULL);
+ poly->connectivity.edge_to_face[i].push_back(&poly->faces[face_map[edge->face]]);
+ }
+ }
+ }
+
+ }
+
+ poly->initSpatialIndex();
+
+ // XXX: at this point, manifold_is_negative is not set up. This
+ // info should be computed/stored in Mesh instances.
+
+ return poly;
+ }
+
+
+
+}
+
+
+
+// explicit instantiation for 2D case.
+// XXX: do not compile because of a missing definition for fitPlane in the 2d case.
+
+// template class carve::mesh::Vertex<2>;
+// template class carve::mesh::Edge<2>;
+// template class carve::mesh::Face<2>;
+// template class carve::mesh::Mesh<2>;
+// template class carve::mesh::MeshSet<2>;
+
+// explicit instantiation for 3D case.
+template class carve::mesh::Vertex<3>;
+template class carve::mesh::Edge<3>;
+template class carve::mesh::Face<3>;
+template class carve::mesh::Mesh<3>;
+template class carve::mesh::MeshSet<3>;
+
+
+
+carve::PointClass carve::mesh::classifyPoint(
+ const carve::mesh::MeshSet<3> *meshset,
+ const carve::geom::RTreeNode<3, carve::mesh::Face<3> *> *face_rtree,
+ const carve::geom::vector<3> &v,
+ bool even_odd,
+ const carve::mesh::Mesh<3> *mesh,
+ const carve::mesh::Face<3> **hit_face) {
+
+ if (hit_face) *hit_face = NULL;
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{containsVertex " << v << "}" << std::endl;
+#endif
+
+ if (!face_rtree->bbox.containsPoint(v)) {
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:OUT(aabb short circuit)}" << std::endl;
+#endif
+ // XXX: if the top level manifolds are negative, this should be POINT_IN.
+ // for the moment, this only works for a single manifold.
+ if (meshset->meshes.size() == 1 && meshset->meshes[0]->isNegative()) {
+ return POINT_IN;
+ }
+ return POINT_OUT;
+ }
+
+ std::vector<carve::mesh::Face<3> *> near_faces;
+ face_rtree->search(v, std::back_inserter(near_faces));
+
+ for (size_t i = 0; i < near_faces.size(); i++) {
+ if (mesh != NULL && mesh != near_faces[i]->mesh) continue;
+
+ // XXX: Do allow the tested vertex to be ON an open
+ // manifold. This was here originally because of the
+ // possibility of an open manifold contained within a closed
+ // manifold.
+
+ // if (!near_faces[i]->mesh->isClosed()) continue;
+
+ if (near_faces[i]->containsPoint(v)) {
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:ON(hits face " << near_faces[i] << ")}" << std::endl;
+#endif
+ if (hit_face) *hit_face = near_faces[i];
+ return POINT_ON;
+ }
+ }
+
+ double ray_len = face_rtree->bbox.extent.length() * 2;
+
+
+ std::vector<std::pair<const carve::mesh::Face<3> *, carve::geom::vector<3> > > manifold_intersections;
+
+ for (;;) {
+ double a1 = random() / double(RAND_MAX) * M_TWOPI;
+ double a2 = random() / double(RAND_MAX) * M_TWOPI;
+
+ carve::geom3d::Vector ray_dir = carve::geom::VECTOR(sin(a1) * sin(a2), cos(a1) * sin(a2), cos(a2));
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{testing ray: " << ray_dir << "}" << std::endl;
+#endif
+
+ carve::geom::vector<3> v2 = v + ray_dir * ray_len;
+
+ bool failed = false;
+ carve::geom::linesegment<3> line(v, v2);
+ carve::geom::vector<3> intersection;
+
+ near_faces.clear();
+ manifold_intersections.clear();
+ face_rtree->search(line, std::back_inserter(near_faces));
+
+ for (unsigned i = 0; !failed && i < near_faces.size(); i++) {
+ if (mesh != NULL && mesh != near_faces[i]->mesh) continue;
+
+ if (!near_faces[i]->mesh->isClosed()) continue;
+
+ switch (near_faces[i]->lineSegmentIntersection(line, intersection)) {
+ case INTERSECT_FACE: {
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{intersects face: " << near_faces[i]
+ << " dp: " << dot(ray_dir, near_faces[i]->plane.N) << "}" << std::endl;
+#endif
+
+ if (!even_odd && fabs(dot(ray_dir, near_faces[i]->plane.N)) < EPSILON) {
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{failing(small dot product)}" << std::endl;
+#endif
+
+ failed = true;
+ break;
+ }
+ manifold_intersections.push_back(std::make_pair(near_faces[i], intersection));
+ break;
+ }
+ case INTERSECT_NONE: {
+ break;
+ }
+ default: {
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{failing(degenerate intersection)}" << std::endl;
+#endif
+ failed = true;
+ break;
+ }
+ }
+ }
+
+ if (!failed) {
+ if (even_odd) {
+ return (manifold_intersections.size() & 1) ? POINT_IN : POINT_OUT;
+ }
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{intersections ok [count:"
+ << manifold_intersections.size()
+ << "], sorting}"
+ << std::endl;
+#endif
+
+ carve::geom3d::sortInDirectionOfRay(ray_dir,
+ manifold_intersections.begin(),
+ manifold_intersections.end(),
+ carve::geom3d::vec_adapt_pair_second());
+
+ std::map<const carve::mesh::Mesh<3> *, int> crossings;
+
+ for (size_t i = 0; i < manifold_intersections.size(); ++i) {
+ const carve::mesh::Face<3> *f = manifold_intersections[i].first;
+ if (dot(ray_dir, f->plane.N) < 0.0) {
+ crossings[f->mesh]++;
+ } else {
+ crossings[f->mesh]--;
+ }
+ }
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ for (std::map<const carve::mesh::Mesh<3> *, int>::const_iterator i = crossings.begin(); i != crossings.end(); ++i) {
+ std::cerr << "{mesh " << (*i).first << " crossing count: " << (*i).second << "}" << std::endl;
+ }
+#endif
+
+ for (size_t i = 0; i < manifold_intersections.size(); ++i) {
+ const carve::mesh::Face<3> *f = manifold_intersections[i].first;
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{intersection at "
+ << manifold_intersections[i].second
+ << " mesh: "
+ << f->mesh
+ << " count: "
+ << crossings[f->mesh]
+ << "}"
+ << std::endl;
+#endif
+
+ if (crossings[f->mesh] < 0) {
+ // inside this manifold.
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:IN}" << std::endl;
+#endif
+
+ return POINT_IN;
+ } else if (crossings[f->mesh] > 0) {
+ // outside this manifold, but it's an infinite manifold. (for instance, an inverted cube)
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:OUT}" << std::endl;
+#endif
+
+ return POINT_OUT;
+ }
+ }
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:OUT(default)}" << std::endl;
+#endif
+
+ return POINT_OUT;
+ }
+ }
+}
+
+
+
diff --git a/extern/carve/lib/octree.cpp b/extern/carve/lib/octree.cpp
new file mode 100644
index 00000000000..900a9614f47
--- /dev/null
+++ b/extern/carve/lib/octree.cpp
@@ -0,0 +1,399 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/octree_decl.hpp>
+#include <carve/octree_impl.hpp>
+
+#include <carve/poly_decl.hpp>
+
+namespace carve {
+ namespace csg {
+
+ Octree::Node::Node(const carve::geom3d::Vector &newMin, const carve::geom3d::Vector &newMax) :
+ parent(NULL), is_leaf(true), min(newMin), max(newMax) {
+ for (int i = 0; i < 8; ++i) children[i] = NULL;
+ aabb = Octree::makeAABB(this);
+ }
+
+ Octree::Node::Node(Node *p, double x1, double y1, double z1, double x2, double y2, double z2) :
+ parent(p), is_leaf(true), min(carve::geom::VECTOR(x1, y1, z1)), max(carve::geom::VECTOR(x2, y2, z2)) {
+ for (int i = 0; i < 8; ++i) children[i] = NULL;
+ aabb = Octree::makeAABB(this);
+ }
+
+ Octree::Node::~Node() {
+ for (int i = 0; i < 8; ++i) {
+ if (children[i] != NULL) {
+ (*children[i]).~Node();
+ }
+ }
+ if (children[0] != NULL) {
+ char *ptr = (char*)children[0];
+ delete[] ptr;
+ }
+ }
+
+ bool Octree::Node::mightContain(const carve::poly::Face<3> &face) {
+ if (face.nVertices() == 3) {
+ return aabb.intersects(carve::geom::tri<3>(face.vertex(0)->v, face.vertex(1)->v, face.vertex(2)->v));
+ } else {
+ return aabb.intersects(face.aabb) && aabb.intersects(face.plane_eqn);
+ }
+ }
+
+ bool Octree::Node::mightContain(const carve::poly::Edge<3> &edge) {
+ return aabb.intersectsLineSegment(edge.v1->v, edge.v2->v);
+ }
+
+ bool Octree::Node::mightContain(const carve::poly::Vertex<3> &p) {
+ return aabb.containsPoint(p.v);
+ }
+
+ bool Octree::Node::hasChildren() {
+ return !is_leaf;
+ }
+
+ bool Octree::Node::split() {
+ if (is_leaf && hasGeometry()) {
+
+ carve::geom3d::Vector mid = 0.5 * (min + max);
+ char *ptr = new char[sizeof(Node)*8];
+ children[0] = new (ptr + sizeof(Node) * 0) Node(this, min.x, min.y, min.z, mid.x, mid.y, mid.z);
+ children[1] = new (ptr + sizeof(Node) * 1) Node(this, mid.x, min.y, min.z, max.x, mid.y, mid.z);
+ children[2] = new (ptr + sizeof(Node) * 2) Node(this, min.x, mid.y, min.z, mid.x, max.y, mid.z);
+ children[3] = new (ptr + sizeof(Node) * 3) Node(this, mid.x, mid.y, min.z, max.x, max.y, mid.z);
+ children[4] = new (ptr + sizeof(Node) * 4) Node(this, min.x, min.y, mid.z, mid.x, mid.y, max.z);
+ children[5] = new (ptr + sizeof(Node) * 5) Node(this, mid.x, min.y, mid.z, max.x, mid.y, max.z);
+ children[6] = new (ptr + sizeof(Node) * 6) Node(this, min.x, mid.y, mid.z, mid.x, max.y, max.z);
+ children[7] = new (ptr + sizeof(Node) * 7) Node(this, mid.x, mid.y, mid.z, max.x, max.y, max.z);
+
+ for (int i = 0; i < 8; ++i) {
+ putInside(faces, children[i], children[i]->faces);
+ putInside(edges, children[i], children[i]->edges);
+ putInside(vertices, children[i], children[i]->vertices);
+ }
+
+ faces.clear();
+ edges.clear();
+ vertices.clear();
+ is_leaf = false;
+ }
+ return is_leaf;
+ }
+
+ template <class T>
+ void Octree::Node::putInside(const T &input, Node *child, T &output) {
+ for (typename T::const_iterator it = input.begin(), e = input.end(); it != e; ++it) {
+ if (child->mightContain(**it)) {
+ output.push_back(*it);
+ }
+ }
+ }
+
+ bool Octree::Node::hasGeometry() {
+ return faces.size() > 0 || edges.size() > 0 || vertices.size() > 0;
+ }
+
+ Octree::Octree() {
+ root = NULL;
+ }
+
+ Octree::~Octree() {
+ if (root) delete root;
+ }
+
+ void Octree::setBounds(const carve::geom3d::Vector &min, const carve::geom3d::Vector &max) {
+ if (root) delete root;
+ root = new Node(min, max);
+ }
+
+ void Octree::setBounds(carve::geom3d::AABB aabb) {
+ if (root) delete root;
+ aabb.extent = 1.1 * aabb.extent;
+ root = new Node(aabb.min(), aabb.max());
+ }
+
+ void Octree::addEdges(const std::vector<carve::poly::Edge<3> > &e) {
+ root->edges.reserve(root->edges.size() + e.size());
+ for (size_t i = 0; i < e.size(); ++i) {
+ root->edges.push_back(&e[i]);
+ }
+ }
+
+ void Octree::addFaces(const std::vector<carve::poly::Face<3> > &f) {
+ root->faces.reserve(root->faces.size() + f.size());
+ for (size_t i = 0; i < f.size(); ++i) {
+ root->faces.push_back(&f[i]);
+ }
+ }
+
+ void Octree::addVertices(const std::vector<const carve::poly::Vertex<3> *> &p) {
+ root->vertices.insert(root->vertices.end(), p.begin(), p.end());
+ }
+
+ carve::geom3d::AABB Octree::makeAABB(const Node *node) {
+ carve::geom3d::Vector centre = 0.5 * (node->min + node->max);
+ carve::geom3d::Vector size = SLACK_FACTOR * 0.5 * (node->max - node->min);
+ return carve::geom3d::AABB(centre, size);
+ }
+
+ void Octree::doFindEdges(const carve::geom::aabb<3> &aabb,
+ Node *node,
+ std::vector<const carve::poly::Edge<3> *> &out,
+ unsigned depth) const {
+ if (node == NULL) {
+ return;
+ }
+
+ if (node->aabb.intersects(aabb)) {
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(aabb, node->children[i], out, depth + 1);
+ }
+ } else {
+ if (depth < MAX_SPLIT_DEPTH && node->edges.size() > EDGE_SPLIT_THRESHOLD) {
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(aabb, node->children[i], out, depth + 1);
+ }
+ return;
+ }
+ }
+ for (std::vector<const carve::poly::Edge<3>*>::const_iterator it = node->edges.begin(), e = node->edges.end(); it != e; ++it) {
+ if ((*it)->tag_once()) {
+ out.push_back(*it);
+ }
+ }
+ }
+ }
+ }
+
+ void Octree::doFindEdges(const carve::geom3d::LineSegment &l,
+ Node *node,
+ std::vector<const carve::poly::Edge<3> *> &out,
+ unsigned depth) const {
+ if (node == NULL) {
+ return;
+ }
+
+ if (node->aabb.intersectsLineSegment(l.v1, l.v2)) {
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(l, node->children[i], out, depth + 1);
+ }
+ } else {
+ if (depth < MAX_SPLIT_DEPTH && node->edges.size() > EDGE_SPLIT_THRESHOLD) {
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(l, node->children[i], out, depth + 1);
+ }
+ return;
+ }
+ }
+ for (std::vector<const carve::poly::Edge<3>*>::const_iterator it = node->edges.begin(), e = node->edges.end(); it != e; ++it) {
+ if ((*it)->tag_once()) {
+ out.push_back(*it);
+ }
+ }
+ }
+ }
+ }
+
+ void Octree::doFindEdges(const carve::geom3d::Vector &v,
+ Node *node,
+ std::vector<const carve::poly::Edge<3> *> &out,
+ unsigned depth) const {
+ if (node == NULL) {
+ return;
+ }
+
+ if (node->aabb.containsPoint(v)) {
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(v, node->children[i], out, depth + 1);
+ }
+ } else {
+ if (depth < MAX_SPLIT_DEPTH && node->edges.size() > EDGE_SPLIT_THRESHOLD) {
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindEdges(v, node->children[i], out, depth + 1);
+ }
+ return;
+ }
+ }
+ for (std::vector<const carve::poly::Edge<3>*>::const_iterator
+ it = node->edges.begin(), e = node->edges.end(); it != e; ++it) {
+ if ((*it)->tag_once()) {
+ out.push_back(*it);
+ }
+ }
+ }
+ }
+ }
+
+ void Octree::doFindFaces(const carve::geom::aabb<3> &aabb,
+ Node *node,
+ std::vector<const carve::poly::Face<3>*> &out,
+ unsigned depth) const {
+ if (node == NULL) {
+ return;
+ }
+
+ if (node->aabb.intersects(aabb)) {
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindFaces(aabb, node->children[i], out, depth + 1);
+ }
+ } else {
+ if (depth < MAX_SPLIT_DEPTH && node->faces.size() > FACE_SPLIT_THRESHOLD) {
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindFaces(aabb, node->children[i], out, depth + 1);
+ }
+ return;
+ }
+ }
+ for (std::vector<const carve::poly::Face<3>*>::const_iterator it = node->faces.begin(), e = node->faces.end(); it != e; ++it) {
+ if ((*it)->tag_once()) {
+ out.push_back(*it);
+ }
+ }
+ }
+ }
+ }
+
+ void Octree::doFindFaces(const carve::geom3d::LineSegment &l,
+ Node *node,
+ std::vector<const carve::poly::Face<3>*> &out,
+ unsigned depth) const {
+ if (node == NULL) {
+ return;
+ }
+
+ if (node->aabb.intersectsLineSegment(l.v1, l.v2)) {
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindFaces(l, node->children[i], out, depth + 1);
+ }
+ } else {
+ if (depth < MAX_SPLIT_DEPTH && node->faces.size() > FACE_SPLIT_THRESHOLD) {
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindFaces(l, node->children[i], out, depth + 1);
+ }
+ return;
+ }
+ }
+ for (std::vector<const carve::poly::Face<3>*>::const_iterator it = node->faces.begin(), e = node->faces.end(); it != e; ++it) {
+ if ((*it)->tag_once()) {
+ out.push_back(*it);
+ }
+ }
+ }
+ }
+ }
+
+ void Octree::doFindVerticesAllowDupes(const carve::geom3d::Vector &v, Node *node, std::vector<const carve::poly::Vertex<3> *> &out, unsigned depth) const {
+ if (node == NULL) {
+ return;
+ }
+
+ if (node->aabb.containsPoint(v)) {
+ if (node->hasChildren()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindVerticesAllowDupes(v, node->children[i], out, depth + 1);
+ }
+ } else {
+ if (depth < MAX_SPLIT_DEPTH && node->vertices.size() > POINT_SPLIT_THRESHOLD) {
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doFindVerticesAllowDupes(v, node->children[i], out, depth + 1);
+ }
+ return;
+ }
+ }
+ for (std::vector<const carve::poly::Vertex<3> *>::const_iterator it = node->vertices.begin(), e = node->vertices.end(); it != e; ++it) {
+ out.push_back(*it);
+ }
+ }
+ }
+ }
+
+ void Octree::findEdgesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Edge<3>*> &out) const {
+ tagable::tag_begin();
+ doFindEdges(aabb, root, out, 0);
+ }
+
+ void Octree::findEdgesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Edge<3>*> &out) const {
+ tagable::tag_begin();
+ doFindEdges(l, root, out, 0);
+ }
+
+ void Octree::findEdgesNear(const carve::poly::Edge<3> &e, std::vector<const carve::poly::Edge<3>*> &out) const {
+ tagable::tag_begin();
+ doFindEdges(carve::geom3d::LineSegment(e.v1->v, e.v2->v), root, out, 0);
+ }
+
+ void Octree::findEdgesNear(const carve::geom3d::Vector &v, std::vector<const carve::poly::Edge<3>*> &out) const {
+ tagable::tag_begin();
+ doFindEdges(v, root, out, 0);
+ }
+
+ void Octree::findFacesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Face<3>*> &out) const {
+ tagable::tag_begin();
+ doFindFaces(aabb, root, out, 0);
+ }
+
+ void Octree::findFacesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Face<3>*> &out) const {
+ tagable::tag_begin();
+ doFindFaces(l, root, out, 0);
+ }
+
+ void Octree::findFacesNear(const carve::poly::Edge<3> &e, std::vector<const carve::poly::Face<3>*> &out) const {
+ tagable::tag_begin();
+ doFindFaces(carve::geom3d::LineSegment(e.v1->v, e.v2->v), root, out, 0);
+ }
+
+ void Octree::findVerticesNearAllowDupes(const carve::geom3d::Vector &v, std::vector<const carve::poly::Vertex<3> *> &out) const {
+ tagable::tag_begin();
+ doFindVerticesAllowDupes(v, root, out, 0);
+ }
+
+ void Octree::doSplit(int maxSplit, Node *node) {
+ // Don't split down any further than 4 levels.
+ if (maxSplit <= 0 || (node->edges.size() < 5 && node->faces.size() < 5)) {
+ return;
+ }
+
+ if (!node->split()) {
+ for (int i = 0; i < 8; ++i) {
+ doSplit(maxSplit - 1, node->children[i]);
+ }
+ }
+ }
+
+ void Octree::splitTree() {
+ // initially split 4 levels
+ doSplit(0, root);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/pointset.cpp b/extern/carve/lib/pointset.cpp
new file mode 100644
index 00000000000..7ecf0074c69
--- /dev/null
+++ b/extern/carve/lib/pointset.cpp
@@ -0,0 +1,59 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/geom.hpp>
+#include <carve/pointset.hpp>
+
+namespace carve {
+ namespace point {
+
+ PointSet::PointSet(const std::vector<carve::geom3d::Vector> &points) {
+ vertices.resize(points.size());
+ for (size_t i = 0; i < points.size(); ++i) {
+ vertices[i].v = points[i];
+ }
+ aabb.fit(points.begin(), points.end());
+ }
+
+ void PointSet::sortVertices(const carve::geom3d::Vector &axis) {
+ std::vector<std::pair<double, size_t> > temp;
+ temp.reserve(vertices.size());
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ temp.push_back(std::make_pair(dot(axis, vertices[i].v), i));
+ }
+ std::sort(temp.begin(), temp.end());
+
+ std::vector<Vertex> vnew;
+ vnew.reserve(vertices.size());
+
+ // std::vector<int> revmap;
+ // revmap.resize(vertices.size());
+
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ vnew.push_back(vertices[temp[i].second]);
+ // revmap[temp[i].second] = i;
+ }
+
+ vertices.swap(vnew);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/polyhedron.cpp b/extern/carve/lib/polyhedron.cpp
new file mode 100644
index 00000000000..93e667ffaf7
--- /dev/null
+++ b/extern/carve/lib/polyhedron.cpp
@@ -0,0 +1,1103 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#if defined(CARVE_DEBUG)
+#define DEBUG_CONTAINS_VERTEX
+#endif
+
+#include <carve/djset.hpp>
+
+#include <carve/geom.hpp>
+#include <carve/poly.hpp>
+
+#include <carve/octree_impl.hpp>
+
+#include <carve/timing.hpp>
+
+#include <algorithm>
+
+#include <carve/mesh.hpp>
+
+#include BOOST_INCLUDE(random.hpp)
+
+namespace {
+ bool emb_test(carve::poly::Polyhedron *poly,
+ std::map<int, std::set<int> > &embedding,
+ carve::geom3d::Vector v,
+ int m_id) {
+
+ std::map<int, carve::PointClass> result;
+#if defined(CARVE_DEBUG)
+ std::cerr << "test " << v << " (m_id:" << m_id << ")" << std::endl;
+#endif
+ poly->testVertexAgainstClosedManifolds(v, result, true);
+ std::set<int> inside;
+ for (std::map<int, carve::PointClass>::iterator j = result.begin();
+ j != result.end();
+ ++j) {
+ if ((*j).first == m_id) continue;
+ if ((*j).second == carve::POINT_IN) inside.insert((*j).first);
+ else if ((*j).second == carve::POINT_ON) {
+#if defined(CARVE_DEBUG)
+ std::cerr << " FAIL" << std::endl;
+#endif
+ return false;
+ }
+ }
+#if defined(CARVE_DEBUG)
+ std::cerr << " OK (inside.size()==" << inside.size() << ")" << std::endl;
+#endif
+ embedding[m_id] = inside;
+ return true;
+ }
+
+
+
+ struct order_faces {
+ bool operator()(const carve::poly::Polyhedron::face_t * const &a,
+ const carve::poly::Polyhedron::face_t * const &b) const {
+ return std::lexicographical_compare(a->vbegin(), a->vend(), b->vbegin(), b->vend());
+ }
+ };
+
+
+
+}
+
+
+
+namespace carve {
+ namespace poly {
+
+
+
+ bool Polyhedron::initSpatialIndex() {
+ static carve::TimingName FUNC_NAME("Polyhedron::initSpatialIndex()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ octree.setBounds(aabb);
+ octree.addFaces(faces);
+ octree.addEdges(edges);
+ octree.splitTree();
+
+ return true;
+ }
+
+
+
+ void Polyhedron::invertAll() {
+ for (size_t i = 0; i < faces.size(); ++i) {
+ faces[i].invert();
+ }
+
+ for (size_t i = 0; i < edges.size(); ++i) {
+ std::vector<const face_t *> &f = connectivity.edge_to_face[i];
+ for (size_t j = 0; j < (f.size() & ~1U); j += 2) {
+ std::swap(f[j], f[j+1]);
+ }
+ }
+
+ for (size_t i = 0; i < manifold_is_negative.size(); ++i) {
+ manifold_is_negative[i] = !manifold_is_negative[i];
+ }
+ }
+
+
+
+ void Polyhedron::invert(const std::vector<bool> &selected_manifolds) {
+ bool altered = false;
+ for (size_t i = 0; i < faces.size(); ++i) {
+ if (faces[i].manifold_id >= 0 &&
+ (unsigned)faces[i].manifold_id < selected_manifolds.size() &&
+ selected_manifolds[faces[i].manifold_id]) {
+ altered = true;
+ faces[i].invert();
+ }
+ }
+
+ if (altered) {
+ for (size_t i = 0; i < edges.size(); ++i) {
+ std::vector<const face_t *> &f = connectivity.edge_to_face[i];
+ for (size_t j = 0; j < (f.size() & ~1U); j += 2) {
+ int m_id = -1;
+ if (f[j]) m_id = f[j]->manifold_id;
+ if (f[j+1]) m_id = f[j+1]->manifold_id;
+ if (m_id >= 0 && (unsigned)m_id < selected_manifolds.size() && selected_manifolds[m_id]) {
+ std::swap(f[j], f[j+1]);
+ }
+ }
+ }
+
+ for (size_t i = 0; i < std::min(selected_manifolds.size(), manifold_is_negative.size()); ++i) {
+ manifold_is_negative[i] = !manifold_is_negative[i];
+ }
+ }
+ }
+
+
+
+ void Polyhedron::initVertexConnectivity() {
+ static carve::TimingName FUNC_NAME("static Polyhedron initVertexConnectivity()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ // allocate space for connectivity info.
+ connectivity.vertex_to_edge.resize(vertices.size());
+ connectivity.vertex_to_face.resize(vertices.size());
+
+ std::vector<size_t> vertex_face_count;
+
+ vertex_face_count.resize(vertices.size());
+
+ // work out how many faces/edges each vertex is connected to, in
+ // order to save on array reallocs.
+ for (unsigned i = 0; i < faces.size(); ++i) {
+ face_t &f = faces[i];
+ for (unsigned j = 0; j < f.nVertices(); j++) {
+ vertex_face_count[vertexToIndex_fast(f.vertex(j))]++;
+ }
+ }
+
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ connectivity.vertex_to_edge[i].reserve(vertex_face_count[i]);
+ connectivity.vertex_to_face[i].reserve(vertex_face_count[i]);
+ }
+
+ // record connectivity from vertex to edges.
+ for (size_t i = 0; i < edges.size(); ++i) {
+ size_t v1i = vertexToIndex_fast(edges[i].v1);
+ size_t v2i = vertexToIndex_fast(edges[i].v2);
+
+ connectivity.vertex_to_edge[v1i].push_back(&edges[i]);
+ connectivity.vertex_to_edge[v2i].push_back(&edges[i]);
+ }
+
+ // record connectivity from vertex to faces.
+ for (size_t i = 0; i < faces.size(); ++i) {
+ face_t &f = faces[i];
+ for (unsigned j = 0; j < f.nVertices(); j++) {
+ size_t vi = vertexToIndex_fast(f.vertex(j));
+ connectivity.vertex_to_face[vi].push_back(&f);
+ }
+ }
+ }
+
+
+
+ bool Polyhedron::initConnectivity() {
+ static carve::TimingName FUNC_NAME("Polyhedron::initConnectivity()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ // temporary measure: initialize connectivity by creating a
+ // half-edge mesh, and then converting back.
+
+ std::vector<mesh::Vertex<3> > vertex_storage;
+ vertex_storage.reserve(vertices.size());
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ vertex_storage.push_back(mesh::Vertex<3>(vertices[i].v));
+ }
+
+ std::vector<mesh::Face<3> *> mesh_faces;
+ std::unordered_map<const mesh::Face<3> *, size_t> face_map;
+ {
+ std::vector<mesh::Vertex<3> *> vert_ptrs;
+ for (size_t i = 0; i < faces.size(); ++i) {
+ const face_t &src = faces[i];
+ vert_ptrs.clear();
+ vert_ptrs.reserve(src.nVertices());
+ for (size_t j = 0; j < src.nVertices(); ++j) {
+ size_t vi = vertexToIndex_fast(src.vertex(j));
+ vert_ptrs.push_back(&vertex_storage[vi]);
+ }
+ mesh::Face<3> *face = new mesh::Face<3>(vert_ptrs.begin(), vert_ptrs.end());
+ mesh_faces.push_back(face);
+ face_map[face] = i;
+ }
+ }
+
+ std::vector<mesh::Mesh<3> *> meshes;
+ mesh::Mesh<3>::create(mesh_faces.begin(), mesh_faces.end(), meshes);
+ mesh::MeshSet<3> *meshset = new mesh::MeshSet<3>(vertex_storage, meshes);
+
+ manifold_is_closed.resize(meshset->meshes.size());
+ manifold_is_negative.resize(meshset->meshes.size());
+
+ std::unordered_map<std::pair<size_t, size_t>, std::list<mesh::Edge<3> *> > edge_map;
+
+ if (meshset->vertex_storage.size()) {
+ mesh::Vertex<3> *Vbase = &meshset->vertex_storage[0];
+ for (size_t m = 0; m < meshset->meshes.size(); ++m) {
+ mesh::Mesh<3> *mesh = meshset->meshes[m];
+ manifold_is_closed[m] = mesh->isClosed();
+ for (size_t f = 0; f < mesh->faces.size(); ++f) {
+ mesh::Face<3> *src = mesh->faces[f];
+ mesh::Edge<3> *e = src->edge;
+ faces[face_map[src]].manifold_id = m;
+ do {
+ edge_map[std::make_pair(e->v1() - Vbase, e->v2() - Vbase)].push_back(e);
+ e = e->next;
+ } while (e != src->edge);
+ }
+ }
+ }
+
+ size_t n_edges = 0;
+ for (std::unordered_map<std::pair<size_t, size_t>, std::list<mesh::Edge<3> *> >::iterator i = edge_map.begin(); i != edge_map.end(); ++i) {
+ if ((*i).first.first < (*i).first.second || edge_map.find(std::make_pair((*i).first.second, (*i).first.first)) == edge_map.end()) {
+ n_edges++;
+ }
+ }
+
+ edges.clear();
+ edges.reserve(n_edges);
+ for (std::unordered_map<std::pair<size_t, size_t>, std::list<mesh::Edge<3> *> >::iterator i = edge_map.begin(); i != edge_map.end(); ++i) {
+ if ((*i).first.first < (*i).first.second || edge_map.find(std::make_pair((*i).first.second, (*i).first.first)) == edge_map.end()) {
+ edges.push_back(edge_t(&vertices[(*i).first.first], &vertices[(*i).first.second], this));
+ }
+ }
+
+ initVertexConnectivity();
+
+ for (size_t f = 0; f < faces.size(); ++f) {
+ face_t &face = faces[f];
+ size_t N = face.nVertices();
+ for (size_t v = 0; v < N; ++v) {
+ size_t v1i = vertexToIndex_fast(face.vertex(v));
+ size_t v2i = vertexToIndex_fast(face.vertex((v+1)%N));
+ std::vector<const edge_t *> found_edge;
+
+ CARVE_ASSERT(carve::is_sorted(connectivity.vertex_to_edge[v1i].begin(), connectivity.vertex_to_edge[v1i].end()));
+ CARVE_ASSERT(carve::is_sorted(connectivity.vertex_to_edge[v2i].begin(), connectivity.vertex_to_edge[v2i].end()));
+
+ std::set_intersection(connectivity.vertex_to_edge[v1i].begin(), connectivity.vertex_to_edge[v1i].end(),
+ connectivity.vertex_to_edge[v2i].begin(), connectivity.vertex_to_edge[v2i].end(),
+ std::back_inserter(found_edge));
+
+ CARVE_ASSERT(found_edge.size() == 1);
+
+ face.edge(v) = found_edge[0];
+ }
+ }
+
+ connectivity.edge_to_face.resize(edges.size());
+
+ for (size_t i = 0; i < edges.size(); ++i) {
+ size_t v1i = vertexToIndex_fast(edges[i].v1);
+ size_t v2i = vertexToIndex_fast(edges[i].v2);
+ std::list<mesh::Edge<3> *> &efwd = edge_map[std::make_pair(v1i, v2i)];
+ std::list<mesh::Edge<3> *> &erev = edge_map[std::make_pair(v1i, v2i)];
+
+ for (std::list<mesh::Edge<3> *>::iterator j = efwd.begin(); j != efwd.end(); ++j) {
+ mesh::Edge<3> *edge = *j;
+ if (face_map.find(edge->face) != face_map.end()) {
+ connectivity.edge_to_face[i].push_back(&faces[face_map[edge->face]]);
+ if (edge->rev == NULL) {
+ connectivity.edge_to_face[i].push_back(NULL);
+ } else {
+ connectivity.edge_to_face[i].push_back(&faces[face_map[edge->rev->face]]);
+ }
+ }
+ }
+ for (std::list<mesh::Edge<3> *>::iterator j = erev.begin(); j != erev.end(); ++j) {
+ mesh::Edge<3> *edge = *j;
+ if (face_map.find(edge->face) != face_map.end()) {
+ if (edge->rev == NULL) {
+ connectivity.edge_to_face[i].push_back(NULL);
+ connectivity.edge_to_face[i].push_back(&faces[face_map[edge->face]]);
+ }
+ }
+ }
+ }
+
+ delete meshset;
+
+ return true;
+ }
+
+
+
+ bool Polyhedron::calcManifoldEmbedding() {
+ // this could be significantly sped up using bounding box tests
+ // to work out what pairs of manifolds are embedding candidates.
+ // A per-manifold AABB could also be used to speed up
+ // testVertexAgainstClosedManifolds().
+
+ static carve::TimingName FUNC_NAME("Polyhedron::calcManifoldEmbedding()");
+ static carve::TimingName CME_V("Polyhedron::calcManifoldEmbedding() (vertices)");
+ static carve::TimingName CME_E("Polyhedron::calcManifoldEmbedding() (edges)");
+ static carve::TimingName CME_F("Polyhedron::calcManifoldEmbedding() (faces)");
+
+ carve::TimingBlock block(FUNC_NAME);
+
+ const unsigned MCOUNT = manifoldCount();
+ if (MCOUNT < 2) return true;
+
+ std::set<int> vertex_manifolds;
+ std::map<int, std::set<int> > embedding;
+
+ carve::Timing::start(CME_V);
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ vertex_manifolds.clear();
+ if (vertexManifolds(&vertices[i], set_inserter(vertex_manifolds)) != 1) continue;
+ int m_id = *vertex_manifolds.begin();
+ if (embedding.find(m_id) == embedding.end()) {
+ if (emb_test(this, embedding, vertices[i].v, m_id) && embedding.size() == MCOUNT) {
+ carve::Timing::stop();
+ goto done;
+ }
+ }
+ }
+ carve::Timing::stop();
+
+ carve::Timing::start(CME_E);
+ for (size_t i = 0; i < edges.size(); ++i) {
+ if (connectivity.edge_to_face[i].size() == 2) {
+ int m_id;
+ const face_t *f1 = connectivity.edge_to_face[i][0];
+ const face_t *f2 = connectivity.edge_to_face[i][1];
+ if (f1) m_id = f1->manifold_id;
+ if (f2) m_id = f2->manifold_id;
+ if (embedding.find(m_id) == embedding.end()) {
+ if (emb_test(this, embedding, (edges[i].v1->v + edges[i].v2->v) / 2, m_id) && embedding.size() == MCOUNT) {
+ carve::Timing::stop();
+ goto done;
+ }
+ }
+ }
+ }
+ carve::Timing::stop();
+
+ carve::Timing::start(CME_F);
+ for (size_t i = 0; i < faces.size(); ++i) {
+ int m_id = faces[i].manifold_id;
+ if (embedding.find(m_id) == embedding.end()) {
+ carve::geom2d::P2 pv;
+ if (!carve::geom2d::pickContainedPoint(faces[i].projectedVertices(), pv)) continue;
+ carve::geom3d::Vector v = carve::poly::face::unproject(faces[i], pv);
+ if (emb_test(this, embedding, v, m_id) && embedding.size() == MCOUNT) {
+ carve::Timing::stop();
+ goto done;
+ }
+ }
+ }
+ carve::Timing::stop();
+
+ CARVE_FAIL("could not find test points");
+
+ // std::cerr << "could not find test points!!!" << std::endl;
+ // return true;
+ done:;
+ for (std::map<int, std::set<int> >::iterator i = embedding.begin(); i != embedding.end(); ++i) {
+#if defined(CARVE_DEBUG)
+ std::cerr << (*i).first << " : ";
+ std::copy((*i).second.begin(), (*i).second.end(), std::ostream_iterator<int>(std::cerr, ","));
+ std::cerr << std::endl;
+#endif
+ (*i).second.insert(-1);
+ }
+ std::set<int> parents, new_parents;
+ parents.insert(-1);
+
+ while (embedding.size()) {
+ new_parents.clear();
+ for (std::map<int, std::set<int> >::iterator i = embedding.begin(); i != embedding.end(); ++i) {
+ if ((*i).second.size() == 1) {
+ if (parents.find(*(*i).second.begin()) != parents.end()) {
+ new_parents.insert((*i).first);
+#if defined(CARVE_DEBUG)
+ std::cerr << "parent(" << (*i).first << "): " << *(*i).second.begin() << std::endl;
+#endif
+ } else {
+#if defined(CARVE_DEBUG)
+ std::cerr << "no parent: " << (*i).first << " (looking for: " << *(*i).second.begin() << ")" << std::endl;
+#endif
+ }
+ }
+ }
+ for (std::set<int>::const_iterator i = new_parents.begin(); i != new_parents.end(); ++i) {
+ embedding.erase(*i);
+ }
+ for (std::map<int, std::set<int> >::iterator i = embedding.begin(); i != embedding.end(); ++i) {
+ size_t n = 0;
+ for (std::set<int>::const_iterator j = parents.begin(); j != parents.end(); ++j) {
+ n += (*i).second.erase((*j));
+ }
+ CARVE_ASSERT(n != 0);
+ }
+ parents.swap(new_parents);
+ }
+
+ return true;
+ }
+
+
+
+ bool Polyhedron::init() {
+ static carve::TimingName FUNC_NAME("Polyhedron::init()");
+ carve::TimingBlock block(FUNC_NAME);
+
+ aabb.fit(vertices.begin(), vertices.end(), vec_adapt_vertex_ref());
+
+ connectivity.vertex_to_edge.clear();
+ connectivity.vertex_to_face.clear();
+ connectivity.edge_to_face.clear();
+
+ if (!initConnectivity()) return false;
+ if (!initSpatialIndex()) return false;
+
+ return true;
+ }
+
+
+
+ void Polyhedron::faceRecalc() {
+ for (size_t i = 0; i < faces.size(); ++i) {
+ if (!faces[i].recalc()) {
+ std::ostringstream out;
+ out << "face " << i << " recalc failed";
+ throw carve::exception(out.str());
+ }
+ }
+ }
+
+
+
+ Polyhedron::Polyhedron(const Polyhedron &poly) {
+ faces.reserve(poly.faces.size());
+
+ for (size_t i = 0; i < poly.faces.size(); ++i) {
+ const face_t &src = poly.faces[i];
+ faces.push_back(src);
+ }
+ commonFaceInit(false); // calls setFaceAndVertexOwner() and init()
+ }
+
+
+
+ Polyhedron::Polyhedron(const Polyhedron &poly, const std::vector<bool> &selected_manifolds) {
+ size_t n_faces = 0;
+
+ for (size_t i = 0; i < poly.faces.size(); ++i) {
+ const face_t &src = poly.faces[i];
+ if (src.manifold_id >= 0 &&
+ (unsigned)src.manifold_id < selected_manifolds.size() &&
+ selected_manifolds[src.manifold_id]) {
+ n_faces++;
+ }
+ }
+
+ faces.reserve(n_faces);
+
+ for (size_t i = 0; i < poly.faces.size(); ++i) {
+ const face_t &src = poly.faces[i];
+ if (src.manifold_id >= 0 &&
+ (unsigned)src.manifold_id < selected_manifolds.size() &&
+ selected_manifolds[src.manifold_id]) {
+ faces.push_back(src);
+ }
+ }
+
+ commonFaceInit(false); // calls setFaceAndVertexOwner() and init()
+ }
+
+
+
+ Polyhedron::Polyhedron(const Polyhedron &poly, int m_id) {
+ size_t n_faces = 0;
+
+ for (size_t i = 0; i < poly.faces.size(); ++i) {
+ const face_t &src = poly.faces[i];
+ if (src.manifold_id == m_id) n_faces++;
+ }
+
+ faces.reserve(n_faces);
+
+ for (size_t i = 0; i < poly.faces.size(); ++i) {
+ const face_t &src = poly.faces[i];
+ if (src.manifold_id == m_id) faces.push_back(src);
+ }
+
+ commonFaceInit(false); // calls setFaceAndVertexOwner() and init()
+ }
+
+
+
+ Polyhedron::Polyhedron(const std::vector<carve::geom3d::Vector> &_vertices,
+ int n_faces,
+ const std::vector<int> &face_indices) {
+ // The polyhedron is defined by a vector of vertices, which we
+ // want to copy, and a face index list, from which we need to
+ // generate a set of Faces.
+
+ vertices.clear();
+ vertices.resize(_vertices.size());
+ for (size_t i = 0; i < _vertices.size(); ++i) {
+ vertices[i].v = _vertices[i];
+ }
+
+ faces.reserve(n_faces);
+
+ std::vector<int>::const_iterator iter = face_indices.begin();
+ std::vector<const vertex_t *> v;
+ for (int i = 0; i < n_faces; ++i) {
+ int vertexCount = *iter++;
+
+ v.clear();
+
+ while (vertexCount--) {
+ CARVE_ASSERT(*iter >= 0);
+ CARVE_ASSERT((unsigned)*iter < vertices.size());
+ v.push_back(&vertices[*iter++]);
+ }
+ faces.push_back(face_t(v));
+ }
+
+ setFaceAndVertexOwner();
+
+ if (!init()) {
+ throw carve::exception("polyhedron creation failed");
+ }
+ }
+
+
+
+ Polyhedron::Polyhedron(std::vector<face_t> &_faces,
+ std::vector<vertex_t> &_vertices,
+ bool _recalc) {
+ faces.swap(_faces);
+ vertices.swap(_vertices);
+
+ setFaceAndVertexOwner();
+
+ if (_recalc) faceRecalc();
+
+ if (!init()) {
+ throw carve::exception("polyhedron creation failed");
+ }
+ }
+
+
+
+ Polyhedron::Polyhedron(std::vector<face_t> &_faces,
+ bool _recalc) {
+ faces.swap(_faces);
+ commonFaceInit(_recalc); // calls setFaceAndVertexOwner() and init()
+ }
+
+
+
+ Polyhedron::Polyhedron(std::list<face_t> &_faces,
+ bool _recalc) {
+ faces.reserve(_faces.size());
+ std::copy(_faces.begin(), _faces.end(), std::back_inserter(faces));
+ commonFaceInit(_recalc); // calls setFaceAndVertexOwner() and init()
+ }
+
+
+
+ void Polyhedron::collectFaceVertices(std::vector<face_t> &faces,
+ std::vector<vertex_t> &vertices,
+ std::unordered_map<const vertex_t *, const vertex_t *> &vmap) {
+ // Given a set of faces, copy all referenced vertices into a
+ // single vertex array and update the faces to point into that
+ // array. On exit, vmap contains a mapping from old pointer to
+ // new pointer.
+
+ vertices.clear();
+ vmap.clear();
+
+ for (size_t i = 0, il = faces.size(); i != il; ++i) {
+ face_t &f = faces[i];
+
+ for (size_t j = 0, jl = f.nVertices(); j != jl; ++j) {
+ vmap[f.vertex(j)] = NULL;
+ }
+ }
+
+ vertices.reserve(vmap.size());
+
+ for (std::unordered_map<const vertex_t *, const vertex_t *>::iterator i = vmap.begin(),
+ e = vmap.end();
+ i != e;
+ ++i) {
+ vertices.push_back(*(*i).first);
+ (*i).second = &vertices.back();
+ }
+
+ for (size_t i = 0, il = faces.size(); i != il; ++i) {
+ face_t &f = faces[i];
+
+ for (size_t j = 0, jl = f.nVertices(); j != jl; ++j) {
+ f.vertex(j) = vmap[f.vertex(j)];
+ }
+ }
+ }
+
+
+
+ void Polyhedron::collectFaceVertices(std::vector<face_t> &faces,
+ std::vector<vertex_t> &vertices) {
+ std::unordered_map<const vertex_t *, const vertex_t *> vmap;
+ collectFaceVertices(faces, vertices, vmap);
+ }
+
+
+
+ void Polyhedron::setFaceAndVertexOwner() {
+ for (size_t i = 0; i < vertices.size(); ++i) vertices[i].owner = this;
+ for (size_t i = 0; i < faces.size(); ++i) faces[i].owner = this;
+ }
+
+
+
+ void Polyhedron::commonFaceInit(bool _recalc) {
+ collectFaceVertices(faces, vertices);
+ setFaceAndVertexOwner();
+ if (_recalc) faceRecalc();
+
+ if (!init()) {
+ throw carve::exception("polyhedron creation failed");
+ }
+ }
+
+
+
+ Polyhedron::~Polyhedron() {
+ }
+
+
+
+ void Polyhedron::testVertexAgainstClosedManifolds(const carve::geom3d::Vector &v,
+ std::map<int, PointClass> &result,
+ bool ignore_orientation) const {
+
+ for (size_t i = 0; i < faces.size(); i++) {
+ if (!manifold_is_closed[faces[i].manifold_id]) continue; // skip open manifolds
+ if (faces[i].containsPoint(v)) {
+ result[faces[i].manifold_id] = POINT_ON;
+ }
+ }
+
+ double ray_len = aabb.extent.length() * 2;
+
+ std::vector<const face_t *> possible_faces;
+
+ std::vector<std::pair<const face_t *, carve::geom3d::Vector> > manifold_intersections;
+
+ boost::mt19937 rng;
+ boost::uniform_on_sphere<double> distrib(3);
+ boost::variate_generator<boost::mt19937 &, boost::uniform_on_sphere<double> > gen(rng, distrib);
+
+ for (;;) {
+ carve::geom3d::Vector ray_dir;
+ ray_dir = gen();
+
+ carve::geom3d::Vector v2 = v + ray_dir * ray_len;
+
+ bool failed = false;
+ carve::geom3d::LineSegment line(v, v2);
+ carve::geom3d::Vector intersection;
+
+ possible_faces.clear();
+ manifold_intersections.clear();
+ octree.findFacesNear(line, possible_faces);
+
+ for (unsigned i = 0; !failed && i < possible_faces.size(); i++) {
+ if (!manifold_is_closed[possible_faces[i]->manifold_id]) continue; // skip open manifolds
+ if (result.find(possible_faces[i]->manifold_id) != result.end()) continue; // already ON
+
+ switch (possible_faces[i]->lineSegmentIntersection(line, intersection)) {
+ case INTERSECT_FACE: {
+ manifold_intersections.push_back(std::make_pair(possible_faces[i], intersection));
+ break;
+ }
+ case INTERSECT_NONE: {
+ break;
+ }
+ default: {
+ failed = true;
+ break;
+ }
+ }
+ }
+
+ if (!failed) break;
+ }
+
+ std::vector<int> crossings(manifold_is_closed.size(), 0);
+
+ for (size_t i = 0; i < manifold_intersections.size(); ++i) {
+ const face_t *f = manifold_intersections[i].first;
+ crossings[f->manifold_id]++;
+ }
+
+ for (size_t i = 0; i < crossings.size(); ++i) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "crossing: " << i << " = " << crossings[i] << " is_negative = " << manifold_is_negative[i] << std::endl;
+#endif
+ if (!manifold_is_closed[i]) continue;
+ if (result.find(i) != result.end()) continue;
+ PointClass pc = (crossings[i] & 1) ? POINT_IN : POINT_OUT;
+ if (!ignore_orientation && manifold_is_negative[i]) pc = (PointClass)-pc;
+ result[i] = pc;
+ }
+ }
+
+
+
+ PointClass Polyhedron::containsVertex(const carve::geom3d::Vector &v,
+ const face_t **hit_face,
+ bool even_odd,
+ int manifold_id) const {
+ if (hit_face) *hit_face = NULL;
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{containsVertex " << v << "}" << std::endl;
+#endif
+
+ if (!aabb.containsPoint(v)) {
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:OUT(aabb short circuit)}" << std::endl;
+#endif
+ // XXX: if the top level manifolds are negative, this should be POINT_IN.
+ // for the moment, this only works for a single manifold.
+ if (manifold_is_negative.size() == 1 && manifold_is_negative[0]) return POINT_IN;
+ return POINT_OUT;
+ }
+
+ for (size_t i = 0; i < faces.size(); i++) {
+ if (manifold_id != -1 && manifold_id != faces[i].manifold_id) continue;
+
+ // XXX: Do allow the tested vertex to be ON an open
+ // manifold. This was here originally because of the
+ // possibility of an open manifold contained within a closed
+ // manifold.
+
+ // if (!manifold_is_closed[faces[i].manifold_id]) continue;
+
+ if (faces[i].containsPoint(v)) {
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:ON(hits face " << &faces[i] << ")}" << std::endl;
+#endif
+ if (hit_face) *hit_face = &faces[i];
+ return POINT_ON;
+ }
+ }
+
+ double ray_len = aabb.extent.length() * 2;
+
+ std::vector<const face_t *> possible_faces;
+
+ std::vector<std::pair<const face_t *, carve::geom3d::Vector> > manifold_intersections;
+
+ for (;;) {
+ double a1 = random() / double(RAND_MAX) * M_TWOPI;
+ double a2 = random() / double(RAND_MAX) * M_TWOPI;
+
+ carve::geom3d::Vector ray_dir = carve::geom::VECTOR(sin(a1) * sin(a2), cos(a1) * sin(a2), cos(a2));
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{testing ray: " << ray_dir << "}" << std::endl;
+#endif
+
+ carve::geom3d::Vector v2 = v + ray_dir * ray_len;
+
+ bool failed = false;
+ carve::geom3d::LineSegment line(v, v2);
+ carve::geom3d::Vector intersection;
+
+ possible_faces.clear();
+ manifold_intersections.clear();
+ octree.findFacesNear(line, possible_faces);
+
+ for (unsigned i = 0; !failed && i < possible_faces.size(); i++) {
+ if (manifold_id != -1 && manifold_id != faces[i].manifold_id) continue;
+
+ if (!manifold_is_closed[possible_faces[i]->manifold_id]) continue;
+
+ switch (possible_faces[i]->lineSegmentIntersection(line, intersection)) {
+ case INTERSECT_FACE: {
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{intersects face: " << possible_faces[i]
+ << " dp: " << dot(ray_dir, possible_faces[i]->plane_eqn.N) << "}" << std::endl;
+#endif
+
+ if (!even_odd && fabs(dot(ray_dir, possible_faces[i]->plane_eqn.N)) < EPSILON) {
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{failing(small dot product)}" << std::endl;
+#endif
+
+ failed = true;
+ break;
+ }
+ manifold_intersections.push_back(std::make_pair(possible_faces[i], intersection));
+ break;
+ }
+ case INTERSECT_NONE: {
+ break;
+ }
+ default: {
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{failing(degenerate intersection)}" << std::endl;
+#endif
+ failed = true;
+ break;
+ }
+ }
+ }
+
+ if (!failed) {
+ if (even_odd) {
+ return (manifold_intersections.size() & 1) ? POINT_IN : POINT_OUT;
+ }
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{intersections ok [count:"
+ << manifold_intersections.size()
+ << "], sorting}"
+ << std::endl;
+#endif
+
+ carve::geom3d::sortInDirectionOfRay(ray_dir,
+ manifold_intersections.begin(),
+ manifold_intersections.end(),
+ carve::geom3d::vec_adapt_pair_second());
+
+ std::vector<int> crossings(manifold_is_closed.size(), 0);
+
+ for (size_t i = 0; i < manifold_intersections.size(); ++i) {
+ const face_t *f = manifold_intersections[i].first;
+ if (dot(ray_dir, f->plane_eqn.N) < 0.0) {
+ crossings[f->manifold_id]++;
+ } else {
+ crossings[f->manifold_id]--;
+ }
+ }
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ for (size_t i = 0; i < crossings.size(); ++i) {
+ std::cerr << "{manifold " << i << " crossing count: " << crossings[i] << "}" << std::endl;
+ }
+#endif
+
+ for (size_t i = 0; i < manifold_intersections.size(); ++i) {
+ const face_t *f = manifold_intersections[i].first;
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{intersection at "
+ << manifold_intersections[i].second
+ << " id: "
+ << f->manifold_id
+ << " count: "
+ << crossings[f->manifold_id]
+ << "}"
+ << std::endl;
+#endif
+
+ if (crossings[f->manifold_id] < 0) {
+ // inside this manifold.
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:IN}" << std::endl;
+#endif
+
+ return POINT_IN;
+ } else if (crossings[f->manifold_id] > 0) {
+ // outside this manifold, but it's an infinite manifold. (for instance, an inverted cube)
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:OUT}" << std::endl;
+#endif
+
+ return POINT_OUT;
+ }
+ }
+
+#if defined(DEBUG_CONTAINS_VERTEX)
+ std::cerr << "{final:OUT(default)}" << std::endl;
+#endif
+
+ return POINT_OUT;
+ }
+ }
+ }
+
+
+
+ void Polyhedron::findEdgesNear(const carve::geom::aabb<3> &aabb,
+ std::vector<const edge_t *> &outEdges) const {
+ outEdges.clear();
+ octree.findEdgesNear(aabb, outEdges);
+ }
+
+
+
+ void Polyhedron::findEdgesNear(const carve::geom3d::LineSegment &line,
+ std::vector<const edge_t *> &outEdges) const {
+ outEdges.clear();
+ octree.findEdgesNear(line, outEdges);
+ }
+
+
+
+ void Polyhedron::findEdgesNear(const carve::geom3d::Vector &v,
+ std::vector<const edge_t *> &outEdges) const {
+ outEdges.clear();
+ octree.findEdgesNear(v, outEdges);
+ }
+
+
+
+ void Polyhedron::findEdgesNear(const face_t &face,
+ std::vector<const edge_t *> &edges) const {
+ edges.clear();
+ octree.findEdgesNear(face, edges);
+ }
+
+
+
+ void Polyhedron::findEdgesNear(const edge_t &edge,
+ std::vector<const edge_t *> &outEdges) const {
+ outEdges.clear();
+ octree.findEdgesNear(edge, outEdges);
+ }
+
+
+
+ void Polyhedron::findFacesNear(const carve::geom3d::LineSegment &line,
+ std::vector<const face_t *> &outFaces) const {
+ outFaces.clear();
+ octree.findFacesNear(line, outFaces);
+ }
+
+
+
+ void Polyhedron::findFacesNear(const carve::geom::aabb<3> &aabb,
+ std::vector<const face_t *> &outFaces) const {
+ outFaces.clear();
+ octree.findFacesNear(aabb, outFaces);
+ }
+
+
+
+ void Polyhedron::findFacesNear(const edge_t &edge,
+ std::vector<const face_t *> &outFaces) const {
+ outFaces.clear();
+ octree.findFacesNear(edge, outFaces);
+ }
+
+
+
+ void Polyhedron::transform(const carve::math::Matrix &xform) {
+ for (size_t i = 0; i < vertices.size(); i++) {
+ vertices[i].v = xform * vertices[i].v;
+ }
+ for (size_t i = 0; i < faces.size(); i++) {
+ faces[i].recalc();
+ }
+ init();
+ }
+
+
+
+ void Polyhedron::print(std::ostream &o) const {
+ o << "Polyhedron@" << this << " {" << std::endl;
+ for (std::vector<vertex_t >::const_iterator
+ i = vertices.begin(), e = vertices.end(); i != e; ++i) {
+ o << " V@" << &(*i) << " " << (*i).v << std::endl;
+ }
+ for (std::vector<edge_t >::const_iterator
+ i = edges.begin(), e = edges.end(); i != e; ++i) {
+ o << " E@" << &(*i) << " {" << std::endl;
+ o << " V@" << (*i).v1 << " - " << "V@" << (*i).v2 << std::endl;
+ const std::vector<const face_t *> &faces = connectivity.edge_to_face[edgeToIndex_fast(&(*i))];
+ for (size_t j = 0; j < (faces.size() & ~1U); j += 2) {
+ o << " fp: F@" << faces[j] << ", F@" << faces[j+1] << std::endl;
+ }
+ o << " }" << std::endl;
+ }
+ for (std::vector<face_t >::const_iterator
+ i = faces.begin(), e = faces.end(); i != e; ++i) {
+ o << " F@" << &(*i) << " {" << std::endl;
+ o << " vertices {" << std::endl;
+ for (face_t::const_vertex_iter_t j = (*i).vbegin(), je = (*i).vend(); j != je; ++j) {
+ o << " V@" << (*j) << std::endl;
+ }
+ o << " }" << std::endl;
+ o << " edges {" << std::endl;
+ for (face_t::const_edge_iter_t j = (*i).ebegin(), je = (*i).eend(); j != je; ++j) {
+ o << " E@" << (*j) << std::endl;
+ }
+ carve::geom::plane<3> p = (*i).plane_eqn;
+ o << " }" << std::endl;
+ o << " normal " << (*i).plane_eqn.N << std::endl;
+ o << " aabb " << (*i).aabb << std::endl;
+ o << " plane_eqn ";
+ carve::geom::operator<< <3>(o, p);
+ o << std::endl;
+ o << " }" << std::endl;
+ }
+
+ o << "}" << std::endl;
+ }
+
+
+
+ void Polyhedron::canonicalize() {
+ orderVertices();
+ for (size_t i = 0; i < faces.size(); i++) {
+ face_t &f = faces[i];
+ size_t j = std::distance(f.vbegin(),
+ std::min_element(f.vbegin(),
+ f.vend()));
+ if (j) {
+ {
+ std::vector<const vertex_t *> temp;
+ temp.reserve(f.nVertices());
+ std::copy(f.vbegin() + j, f.vend(), std::back_inserter(temp));
+ std::copy(f.vbegin(), f.vbegin() + j, std::back_inserter(temp));
+ std::copy(temp.begin(), temp.end(), f.vbegin());
+ }
+ {
+ std::vector<const edge_t *> temp;
+ temp.reserve(f.nEdges());
+ std::copy(f.ebegin() + j, f.eend(), std::back_inserter(temp));
+ std::copy(f.ebegin(), f.ebegin() + j, std::back_inserter(temp));
+ std::copy(temp.begin(), temp.end(), f.ebegin());
+ }
+ }
+ }
+
+ std::vector<face_t *> face_ptrs;
+ face_ptrs.reserve(faces.size());
+ for (size_t i = 0; i < faces.size(); ++i) face_ptrs.push_back(&faces[i]);
+ std::sort(face_ptrs.begin(), face_ptrs.end(), order_faces());
+ std::vector<face_t> sorted_faces;
+ sorted_faces.reserve(faces.size());
+ for (size_t i = 0; i < faces.size(); ++i) sorted_faces.push_back(*face_ptrs[i]);
+ std::swap(faces, sorted_faces);
+ }
+
+ }
+}
+
diff --git a/extern/carve/lib/polyline.cpp b/extern/carve/lib/polyline.cpp
new file mode 100644
index 00000000000..d9681c76a5c
--- /dev/null
+++ b/extern/carve/lib/polyline.cpp
@@ -0,0 +1,67 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/geom.hpp>
+#include <carve/vector.hpp>
+#include <carve/polyline.hpp>
+
+namespace carve {
+ namespace line {
+ carve::geom3d::AABB Polyline::aabb() const {
+ return carve::geom3d::AABB(vbegin(), vend(), vec_adapt_vertex_ptr());
+ }
+
+ PolylineSet::PolylineSet(const std::vector<carve::geom3d::Vector> &points) {
+ vertices.resize(points.size());
+ for (size_t i = 0; i < points.size(); ++i) vertices[i].v = points[i];
+ aabb.fit(points.begin(), points.end(), carve::geom3d::vec_adapt_ident());
+ }
+
+ void PolylineSet::sortVertices(const carve::geom3d::Vector &axis) {
+ std::vector<std::pair<double, size_t> > temp;
+ temp.reserve(vertices.size());
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ temp.push_back(std::make_pair(dot(axis, vertices[i].v), i));
+ }
+ std::sort(temp.begin(), temp.end());
+ std::vector<Vertex> vnew;
+ std::vector<int> revmap;
+ vnew.reserve(vertices.size());
+ revmap.resize(vertices.size());
+
+ for (size_t i = 0; i < vertices.size(); ++i) {
+ vnew.push_back(vertices[temp[i].second]);
+ revmap[temp[i].second] = i;
+ }
+
+ for (line_iter i = lines.begin(); i != lines.end(); ++i) {
+ Polyline &l = *(*i);
+ for (size_t j = 0; j < l.edges.size(); ++j) {
+ PolylineEdge &e = *l.edges[j];
+ if (e.v1) e.v1 = &vnew[revmap[vertexToIndex_fast(e.v1)]];
+ if (e.v2) e.v2 = &vnew[revmap[vertexToIndex_fast(e.v2)]];
+ }
+ }
+ vertices.swap(vnew);
+ }
+
+ }
+}
diff --git a/extern/carve/lib/tag.cpp b/extern/carve/lib/tag.cpp
new file mode 100644
index 00000000000..449eb555346
--- /dev/null
+++ b/extern/carve/lib/tag.cpp
@@ -0,0 +1,24 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/tag.hpp>
+
+int carve::tagable::s_count = 0;
diff --git a/extern/carve/lib/timing.cpp b/extern/carve/lib/timing.cpp
new file mode 100644
index 00000000000..a98796cd8a7
--- /dev/null
+++ b/extern/carve/lib/timing.cpp
@@ -0,0 +1,436 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if CARVE_USE_TIMINGS
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/timing.hpp>
+
+#include <cstring>
+#include <list>
+#include <stack>
+#include <vector>
+#include <map>
+#include <iostream>
+#include <string>
+#include <algorithm>
+
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <time.h>
+#include <sys/time.h>
+#endif
+
+#ifndef CARVE_USE_GLOBAL_NEW_DELETE
+#define CARVE_USE_GLOBAL_NEW_DELETE 0
+#endif
+
+namespace carve {
+ static uint64_t memoryCurr = 0;
+ static uint64_t memoryTotal = 0;
+ unsigned blkCntCurr[32] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
+ unsigned blkCntTotal[32] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
+
+ void addBlk(unsigned size) {
+ unsigned i = 0;
+ while (i < 31 && (1U<<i) < size) ++i;
+ blkCntCurr[i]++;
+ blkCntTotal[i]++;
+ }
+ void remBlk(unsigned size) {
+ unsigned i = 0;
+ while (i < 31 && (1<<i) < size) ++i;
+ blkCntCurr[i]--;
+ }
+}
+
+// lets provide a global new and delete as well
+
+#if CARVE_USE_GLOBAL_NEW_DELETE
+
+#if defined(__APPLE__)
+
+#include <stdlib.h>
+#include <malloc/malloc.h>
+
+void* carve_alloc(size_t size) {
+ void *p = malloc(size);
+ if (p == 0) throw std::bad_alloc(); // ANSI/ISO compliant behavior
+
+ unsigned sz = malloc_size(p);
+ carve::memoryCurr += sz;
+ carve::memoryTotal += sz;
+ carve::addBlk(sz);
+ return p;
+}
+
+void carve_free(void *p) {
+ unsigned sz = malloc_size(p);
+ carve::memoryCurr -= sz;
+ carve::remBlk(sz);
+ free(p);
+}
+
+#else
+
+void* carve_alloc(size_t size) {
+ void *p = malloc(size + 4);
+ if (p == 0) throw std::bad_alloc(); // ANSI/ISO compliant behavior
+
+ int *sizePtr = (int*)p;
+ *sizePtr = size;
+ ++sizePtr;
+ carve::memoryCurr += size;
+ carve::memoryTotal += size;
+ carve::addBlk(size);
+ return sizePtr;
+}
+
+void carve_free(void *p) {
+ // our memory block is actually a size of an int behind this pointer.
+ int *sizePtr = (int*)p;
+
+ --sizePtr;
+
+ carve::memoryCurr -= *sizePtr;
+ int size = *sizePtr;
+ carve::remBlk(size);
+ free(sizePtr);
+}
+
+#endif
+
+
+void* operator new (size_t size) {
+ return carve_alloc(size);
+}
+
+void* operator new[](size_t size) {
+ return carve_alloc(size);
+}
+
+
+void operator delete (void *p) {
+ carve_free(p);
+}
+
+void operator delete[](void *p) {
+ carve_free(p);
+}
+
+#endif
+
+namespace carve {
+
+
+
+#ifdef WIN32
+
+ typedef __int64 precise_time_t;
+
+ precise_time_t g_frequency;
+
+ void initTime() {
+ ::QueryPerformanceFrequency((LARGE_INTEGER*)&g_frequency);
+ }
+
+ void getTime(precise_time_t &t) {
+ ::QueryPerformanceCounter((LARGE_INTEGER*)&t);
+ }
+
+ double diffTime(precise_time_t from, precise_time_t to) {
+ return (double)(to - from) / (double)g_frequency;
+ }
+
+#else
+
+ typedef double precise_time_t;
+
+ void initTime() {
+ }
+
+ void getTime(precise_time_t &t) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ t = tv.tv_sec + tv.tv_usec / 1000000.0;
+ }
+
+ double diffTime(precise_time_t from, precise_time_t to) {
+ return to - from;
+ }
+
+#endif
+
+ struct Entry {
+ Entry(int _id) {
+ id = _id;
+ time = 0;
+ parent = NULL;
+ }
+ int id;
+ double time;
+ int64_t memoryDiff;
+ int64_t allocTotal;
+ int delta_blk_cnt_curr[32];
+ int delta_blk_cnt_total[32];
+ Entry *parent;
+ std::vector<Entry *> children;
+ };
+
+ struct Timer {
+ struct cmp {
+ bool operator()(const std::pair<int, double> &a, const std::pair<int, double> &b) const {
+ return b.second < a.second;
+ }
+ bool operator()(const Entry * const &a, const Entry * const &b) const {
+ return b->time < a->time;
+ }
+ };
+
+ Timer() {
+ initTime();
+ }
+
+ struct Snapshot {
+ precise_time_t time;
+ uint64_t memory_curr;
+ uint64_t memory_total;
+ unsigned blk_cnt_curr[32];
+ unsigned blk_cnt_total[32];
+ };
+
+ static void getSnapshot(Snapshot &snapshot) {
+ getTime(snapshot.time);
+ snapshot.memory_curr = carve::memoryCurr;
+ snapshot.memory_total = carve::memoryTotal;
+ std::memcpy(snapshot.blk_cnt_curr, carve::blkCntCurr, sizeof(carve::blkCntCurr));
+ std::memcpy(snapshot.blk_cnt_total, carve::blkCntTotal, sizeof(carve::blkCntTotal));
+ }
+
+ static void compareSnapshot(const Snapshot &from, const Snapshot &to, Entry *entry) {
+ entry->time = diffTime(from.time, to.time);
+ entry->memoryDiff = to.memory_curr - from.memory_curr;
+ entry->allocTotal = to.memory_total - from.memory_total;
+ for (int i = 0; i < 32; i++) {
+ entry->delta_blk_cnt_curr[i] = to.blk_cnt_curr[i] - from.blk_cnt_curr[i];
+ entry->delta_blk_cnt_total[i] = to.blk_cnt_total[i] - from.blk_cnt_total[i];
+ }
+ }
+
+ std::stack<std::pair<Entry*, Snapshot> > currentTimers;
+
+ void startTiming(int id) {
+ entries.push_back(Entry(id));
+ currentTimers.push(std::make_pair(&entries.back(), Snapshot()));
+ getSnapshot(currentTimers.top().second);
+ }
+
+ double endTiming() {
+ Snapshot end;
+ getSnapshot(end);
+
+ Entry *entry = currentTimers.top().first;
+ compareSnapshot(currentTimers.top().second, end, entry);
+
+ currentTimers.pop();
+ if (!currentTimers.empty()) {
+ entry->parent = currentTimers.top().first;
+ entry->parent->children.push_back(entry);
+ } else {
+ root_entries.push_back(entry);
+ }
+ //std::sort(entry->children.begin(), entry->children.end(), cmp());
+ return entry->time;
+ }
+
+ typedef std::list<Entry> EntryList;
+ EntryList entries;
+ std::vector<Entry *> root_entries;
+
+ std::map<int, std::string> names;
+
+ static std::string formatMemory(int64_t value) {
+
+ std::ostringstream result;
+
+ result << (value >= 0 ? "+" : "-");
+ if (value < 0) {
+ value = -value;
+ }
+
+ int power = 1;
+ while (value > pow(10.0, power)) {
+ power++;
+ }
+
+ for (power--; power >= 0; power--) {
+ int64_t base = pow(10.0, power);
+ int64_t amount = value / base;
+ result <<
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ (long)
+#endif
+ amount;
+ if (power > 0 && (power % 3) == 0) {
+ result << ",";
+ }
+ value -= amount * base;
+ }
+
+ result << " bytes";
+
+ return result.str();
+ }
+
+ void printEntries(std::ostream &o, const std::vector<Entry *> &entries, const std::string &indent, double parent_time) {
+ if (parent_time <= 0.0) {
+ parent_time = 0.0;
+ for (size_t i = 0; i < entries.size(); ++i) {
+ parent_time += entries[i]->time;
+ }
+ }
+ double t_tot = 0.0;
+ for (size_t i = 0; i < entries.size(); ++i) {
+ const Entry *entry = entries[i];
+
+ std::ostringstream r;
+ r << indent;
+ std::string str = names[entry->id];
+ if (str.empty()) {
+ r << "(" << entry->id << ")";
+ } else {
+ r << str;
+ }
+ r << " ";
+ std::string pad(r.str().size(), ' ');
+ r << " - exectime: " << entry->time << "s (" << (entry->time * 100.0 / parent_time) << "%)" << std::endl;
+ if (entry->allocTotal || entry->memoryDiff) {
+ r << pad << " - alloc: " << formatMemory(entry->allocTotal) << " delta: " << formatMemory(entry->memoryDiff) << std::endl;
+ r << pad << " - alloc blks:";
+ for (int i = 0; i < 32; i++) { if (entry->delta_blk_cnt_total[i]) r << ' ' << ((1 << (i - 1)) + 1) << '-' << (1 << i) << ':' << entry->delta_blk_cnt_total[i]; }
+ r << std::endl;
+ r << pad << " - delta blks:";
+ for (int i = 0; i < 32; i++) { if (entry->delta_blk_cnt_curr[i]) r << ' ' << ((1 << (i - 1)) + 1) << '-' << (1 << i) << ':' << entry->delta_blk_cnt_curr[i]; }
+ r << std::endl;
+ }
+ o << r.str();
+ t_tot += entry->time;
+ if (entry->children.size()) printEntries(o, entry->children, indent + " ", entry->time);
+ }
+ if (t_tot < parent_time) {
+ o << indent << "*** unaccounted: " << (parent_time - t_tot) << "s (" << (100.0 - t_tot * 100.0 / parent_time) << "%)" << std::endl;
+ }
+ }
+
+ void print() {
+ std::map<int, double> totals;
+ std::cerr << "Timings: " << std::endl;
+ // print out all the entries.
+
+ //std::sort(root_entries.begin(), root_entries.end(), cmp());
+
+ printEntries(std::cerr, root_entries, " ", -1.0);
+
+ for (EntryList::const_iterator it = entries.begin(); it != entries.end(); ++it) {
+ totals[(*it).id] += (*it).time;
+ }
+
+ std::cerr << std::endl;
+ std::cerr << "Totals: " << std::endl;
+
+ std::vector<std::pair<int, double> > sorted_totals;
+ sorted_totals.reserve(totals.size());
+ for (std::map<int,double>::iterator it = totals.begin(); it != totals.end(); ++it) {
+ sorted_totals.push_back(*it);
+ }
+
+ std::sort(sorted_totals.begin(), sorted_totals.end(), cmp());
+
+ for (std::vector<std::pair<int,double> >::iterator it = sorted_totals.begin(); it != sorted_totals.end(); ++it) {
+ std::cerr << " ";
+ std::string str = names[it->first];
+ if (str.empty()) {
+ std::cerr << "(" << it->first << ")";
+ } else {
+ std::cerr << str;
+ }
+ std::cerr << " - " << it->second << "s " << std::endl;
+ }
+ }
+ void registerID(int id, const char *name) {
+ names[id] = name;
+ }
+ int registerID(const char *name) {
+ int id = names.size() + 1;
+ names[id] = name;
+ return id;
+ }
+
+ };
+
+ Timer timer;
+
+
+ TimingBlock::TimingBlock(int id) {
+#if CARVE_USE_TIMINGS
+ timer.startTiming(id);
+#endif
+ }
+
+ TimingBlock::TimingBlock(const TimingName &name) {
+#if CARVE_USE_TIMINGS
+ timer.startTiming(name.id);
+#endif
+ }
+
+
+ TimingBlock::~TimingBlock() {
+#if CARVE_USE_TIMINGS
+ timer.endTiming();
+#endif
+ }
+ void Timing::start(int id) {
+#if CARVE_USE_TIMINGS
+ timer.startTiming(id);
+#endif
+ }
+
+ double Timing::stop() {
+#if CARVE_USE_TIMINGS
+ return timer.endTiming();
+#endif
+ }
+
+ void Timing::printTimings() {
+ timer.print();
+ }
+
+ void Timing::registerID(int id, const char *name) {
+ timer.registerID(id, name);
+ }
+
+ TimingName::TimingName(const char *name) {
+ id = timer.registerID(name);
+ }
+
+}
+
+#endif
diff --git a/extern/carve/lib/triangulator.cpp b/extern/carve/lib/triangulator.cpp
new file mode 100644
index 00000000000..b36aecf98be
--- /dev/null
+++ b/extern/carve/lib/triangulator.cpp
@@ -0,0 +1,1211 @@
+// Begin License:
+// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
+// All rights reserved.
+//
+// This file is part of the Carve CSG Library (http://carve-csg.com/)
+//
+// This file may be used under the terms of the GNU General Public
+// License version 2.0 as published by the Free Software Foundation
+// and appearing in the file LICENSE.GPL2 included in the packaging of
+// this file.
+//
+// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE.
+// End:
+
+
+#if defined(HAVE_CONFIG_H)
+# include <carve_config.h>
+#endif
+
+#include <carve/csg.hpp>
+#include <carve/triangulator.hpp>
+
+#include <fstream>
+#include <sstream>
+
+#include <algorithm>
+
+
+namespace {
+ // private code related to hole patching.
+
+ class order_h_loops_2d {
+ order_h_loops_2d &operator=(const order_h_loops_2d &);
+
+ const std::vector<std::vector<carve::geom2d::P2> > &poly;
+ int axis;
+ public:
+
+ order_h_loops_2d(const std::vector<std::vector<carve::geom2d::P2> > &_poly, int _axis) :
+ poly(_poly), axis(_axis) {
+ }
+
+ bool operator()(const std::pair<size_t, size_t> &a,
+ const std::pair<size_t, size_t> &b) const {
+ return carve::triangulate::detail::axisOrdering(poly[a.first][a.second], poly[b.first][b.second], axis);
+ }
+ };
+
+ class heap_ordering_2d {
+ heap_ordering_2d &operator=(const heap_ordering_2d &);
+
+ const std::vector<std::vector<carve::geom2d::P2> > &poly;
+ const std::vector<std::pair<size_t, size_t> > &loop;
+ const carve::geom2d::P2 p;
+ int axis;
+
+ public:
+
+ heap_ordering_2d(const std::vector<std::vector<carve::geom2d::P2> > &_poly,
+ const std::vector<std::pair<size_t, size_t> > &_loop,
+ const carve::geom2d::P2 _p,
+ int _axis) : poly(_poly), loop(_loop), p(_p), axis(_axis) {
+ }
+
+ bool operator()(size_t a, size_t b) const {
+ double da = carve::geom::distance2(p, poly[loop[a].first][loop[a].second]);
+ double db = carve::geom::distance2(p, poly[loop[b].first][loop[b].second]);
+ if (da > db) return true;
+ if (da < db) return false;
+ return carve::triangulate::detail::axisOrdering(poly[loop[a].first][loop[a].second], poly[loop[b].first][loop[b].second], axis);
+ }
+ };
+
+ static inline void patchHoleIntoPolygon_2d(std::vector<std::pair<size_t, size_t> > &f_loop,
+ size_t f_loop_attach,
+ size_t h_loop,
+ size_t h_loop_attach,
+ size_t h_loop_size) {
+ f_loop.insert(f_loop.begin() + f_loop_attach + 1, h_loop_size + 2, std::make_pair(h_loop, 0));
+ size_t f = f_loop_attach + 1;
+
+ for (size_t h = h_loop_attach; h != h_loop_size; ++h) {
+ f_loop[f++].second = h;
+ }
+
+ for (size_t h = 0; h <= h_loop_attach; ++h) {
+ f_loop[f++].second = h;
+ }
+
+ f_loop[f] = f_loop[f_loop_attach];
+ }
+
+ static inline const carve::geom2d::P2 &pvert(const std::vector<std::vector<carve::geom2d::P2> > &poly, const std::pair<size_t, size_t> &idx) {
+ return poly[idx.first][idx.second];
+ }
+}
+
+
+namespace {
+ // private code related to triangulation.
+
+ using carve::triangulate::detail::vertex_info;
+
+ struct vertex_info_ordering {
+ bool operator()(const vertex_info *a, const vertex_info *b) const {
+ return a->score < b->score;
+ }
+ };
+
+ struct vertex_info_l2norm_inc_ordering {
+ const vertex_info *v;
+ vertex_info_l2norm_inc_ordering(const vertex_info *_v) : v(_v) {
+ }
+ bool operator()(const vertex_info *a, const vertex_info *b) const {
+ return carve::geom::distance2(v->p, a->p) > carve::geom::distance2(v->p, b->p);
+ }
+ };
+
+ class EarQueue {
+ std::vector<vertex_info *> queue;
+
+ void checkheap() {
+#ifdef __GNUC__
+ CARVE_ASSERT(std::__is_heap(queue.begin(), queue.end(), vertex_info_ordering()));
+#endif
+ }
+
+ public:
+ EarQueue() {
+ }
+
+ size_t size() const {
+ return queue.size();
+ }
+
+ void push(vertex_info *v) {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ queue.push_back(v);
+ std::push_heap(queue.begin(), queue.end(), vertex_info_ordering());
+ }
+
+ vertex_info *pop() {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ std::pop_heap(queue.begin(), queue.end(), vertex_info_ordering());
+ vertex_info *v = queue.back();
+ queue.pop_back();
+ return v;
+ }
+
+ void remove(vertex_info *v) {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ CARVE_ASSERT(std::find(queue.begin(), queue.end(), v) != queue.end());
+ double score = v->score;
+ if (v != queue[0]) {
+ v->score = queue[0]->score + 1;
+ std::make_heap(queue.begin(), queue.end(), vertex_info_ordering());
+ }
+ CARVE_ASSERT(v == queue[0]);
+ std::pop_heap(queue.begin(), queue.end(), vertex_info_ordering());
+ CARVE_ASSERT(queue.back() == v);
+ queue.pop_back();
+ v->score = score;
+ }
+
+ void changeScore(vertex_info *v, double score) {
+#if defined(CARVE_DEBUG)
+ checkheap();
+#endif
+ CARVE_ASSERT(std::find(queue.begin(), queue.end(), v) != queue.end());
+ if (v->score != score) {
+ v->score = score;
+ std::make_heap(queue.begin(), queue.end(), vertex_info_ordering());
+ }
+ }
+
+ // 39% of execution time
+ void updateVertex(vertex_info *v) {
+ double spre = v->score;
+ bool qpre = v->isCandidate();
+ v->recompute();
+ bool qpost = v->isCandidate();
+ double spost = v->score;
+
+ v->score = spre;
+
+ if (qpre) {
+ if (qpost) {
+ if (v->score != spre) {
+ changeScore(v, spost);
+ }
+ } else {
+ remove(v);
+ }
+ } else {
+ if (qpost) {
+ push(v);
+ }
+ }
+ }
+ };
+
+
+
+ int windingNumber(vertex_info *begin, const carve::geom2d::P2 &point) {
+ int wn = 0;
+
+ vertex_info *v = begin;
+ do {
+ if (v->p.y <= point.y) {
+ if (v->next->p.y > point.y && carve::geom2d::orient2d(v->p, v->next->p, point) > 0.0) {
+ ++wn;
+ }
+ } else {
+ if (v->next->p.y <= point.y && carve::geom2d::orient2d(v->p, v->next->p, point) < 0.0) {
+ --wn;
+ }
+ }
+ v = v->next;
+ } while (v != begin);
+
+ return wn;
+ }
+
+
+
+ bool internalToAngle(const vertex_info *a,
+ const vertex_info *b,
+ const vertex_info *c,
+ const carve::geom2d::P2 &p) {
+ return carve::geom2d::internalToAngle(a->p, b->p, c->p, p);
+ }
+
+
+
+ bool findDiagonal(vertex_info *begin, vertex_info *&v1, vertex_info *&v2) {
+ vertex_info *t;
+ std::vector<vertex_info *> heap;
+
+ v1 = begin;
+ do {
+ heap.clear();
+
+ for (v2 = v1->next->next; v2 != v1->prev; v2 = v2->next) {
+ if (!internalToAngle(v1->next, v1, v1->prev, v2->p) ||
+ !internalToAngle(v2->next, v2, v2->prev, v1->p)) continue;
+
+ heap.push_back(v2);
+ std::push_heap(heap.begin(), heap.end(), vertex_info_l2norm_inc_ordering(v1));
+ }
+
+ while (heap.size()) {
+ std::pop_heap(heap.begin(), heap.end(), vertex_info_l2norm_inc_ordering(v1));
+ v2 = heap.back(); heap.pop_back();
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "testing: " << v1 << " - " << v2 << std::endl;
+ std::cerr << " length = " << (v2->p - v1->p).length() << std::endl;
+ std::cerr << " pos: " << v1->p << " - " << v2->p << std::endl;
+#endif
+ // test whether v1-v2 is a valid diagonal.
+ double v_min_x = std::min(v1->p.x, v2->p.x);
+ double v_max_x = std::max(v1->p.x, v2->p.x);
+
+ bool intersected = false;
+
+ for (t = v1->next; !intersected && t != v1->prev; t = t->next) {
+ vertex_info *u = t->next;
+ if (t == v2 || u == v2) continue;
+
+ double l1 = carve::geom2d::orient2d(v1->p, v2->p, t->p);
+ double l2 = carve::geom2d::orient2d(v1->p, v2->p, u->p);
+
+ if ((l1 > 0.0 && l2 > 0.0) || (l1 < 0.0 && l2 < 0.0)) {
+ // both on the same side; no intersection
+ continue;
+ }
+
+ double dx13 = v1->p.x - t->p.x;
+ double dy13 = v1->p.y - t->p.y;
+ double dx43 = u->p.x - t->p.x;
+ double dy43 = u->p.y - t->p.y;
+ double dx21 = v2->p.x - v1->p.x;
+ double dy21 = v2->p.y - v1->p.y;
+ double ua_n = dx43 * dy13 - dy43 * dx13;
+ double ub_n = dx21 * dy13 - dy21 * dx13;
+ double u_d = dy43 * dx21 - dx43 * dy21;
+
+ if (carve::math::ZERO(u_d)) {
+ // parallel
+ if (carve::math::ZERO(ua_n)) {
+ // colinear
+ if (std::max(t->p.x, u->p.x) >= v_min_x && std::min(t->p.x, u->p.x) <= v_max_x) {
+ // colinear and intersecting
+ intersected = true;
+ }
+ }
+ } else {
+ // not parallel
+ double ua = ua_n / u_d;
+ double ub = ub_n / u_d;
+
+ if (0.0 <= ua && ua <= 1.0 && 0.0 <= ub && ub <= 1.0) {
+ intersected = true;
+ }
+ }
+#if defined(CARVE_DEBUG)
+ if (intersected) {
+ std::cerr << " failed on edge: " << t << " - " << u << std::endl;
+ std::cerr << " pos: " << t->p << " - " << u->p << std::endl;
+ }
+#endif
+ }
+
+ if (!intersected) {
+ // test whether midpoint winding == 1
+
+ carve::geom2d::P2 mid = (v1->p + v2->p) / 2;
+ if (windingNumber(begin, mid) == 1) {
+ // this diagonal is ok
+ return true;
+ }
+ }
+ }
+
+ // couldn't find a diagonal from v1 that was ok.
+ v1 = v1->next;
+ } while (v1 != begin);
+ return false;
+ }
+
+
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ void dumpPoly(const std::vector<carve::geom2d::P2> &points,
+ const std::vector<carve::triangulate::tri_idx> &result) {
+ static int step = 0;
+ std::ostringstream filename;
+ filename << "poly_" << step++ << ".svg";
+ std::cerr << "dumping to " << filename.str() << std::endl;
+ std::ofstream out(filename.str().c_str());
+
+ double minx = points[0].x, maxx = points[0].x;
+ double miny = points[0].y, maxy = points[0].y;
+
+ for (size_t i = 1; i < points.size(); ++i) {
+ minx = std::min(points[i].x, minx); maxx = std::max(points[i].x, maxx);
+ miny = std::min(points[i].y, miny); maxy = std::max(points[i].y, maxy);
+ }
+ double scale = 100 / std::max(maxx-minx, maxy-miny);
+
+ maxx *= scale; minx *= scale;
+ maxy *= scale; miny *= scale;
+
+ double width = maxx - minx + 10;
+ double height = maxy - miny + 10;
+
+ out << "\
+<?xml version=\"1.0\"?>\n\
+<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n\
+<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"" << width << "\" height=\"" << height << "\">\n";
+
+ out << "<polygon fill=\"rgb(0,0,0)\" stroke=\"blue\" stroke-width=\"0.1\" points=\"";
+ for (size_t i = 0; i < points.size(); ++i) {
+ if (i) out << ' ';
+ double x, y;
+ x = scale * (points[i].x) - minx + 5;
+ y = scale * (points[i].y) - miny + 5;
+ out << x << ',' << y;
+ }
+ out << "\" />" << std::endl;
+
+ for (size_t i = 0; i < result.size(); ++i) {
+ out << "<polygon fill=\"rgb(255,255,255)\" stroke=\"black\" stroke-width=\"0.1\" points=\"";
+ double x, y;
+ x = scale * (points[result[i].a].x) - minx + 5;
+ y = scale * (points[result[i].a].y) - miny + 5;
+ out << x << ',' << y << ' ';
+ x = scale * (points[result[i].b].x) - minx + 5;
+ y = scale * (points[result[i].b].y) - miny + 5;
+ out << x << ',' << y << ' ';
+ x = scale * (points[result[i].c].x) - minx + 5;
+ y = scale * (points[result[i].c].y) - miny + 5;
+ out << x << ',' << y;
+ out << "\" />" << std::endl;
+ }
+
+ out << "</svg>" << std::endl;
+ }
+#endif
+}
+
+
+
+double carve::triangulate::detail::vertex_info::triScore(const vertex_info *p, const vertex_info *v, const vertex_info *n) {
+
+ // different scoring functions.
+#if 0
+ bool convex = isLeft(p, v, n);
+ if (!convex) return -1e-5;
+
+ double a1 = carve::geom2d::atan2(p->p - v->p) - carve::geom2d::atan2(n->p - v->p);
+ double a2 = carve::geom2d::atan2(v->p - n->p) - carve::geom2d::atan2(p->p - n->p);
+ if (a1 < 0) a1 += M_PI * 2;
+ if (a2 < 0) a2 += M_PI * 2;
+
+ return std::min(a1, std::min(a2, M_PI - a1 - a2)) / (M_PI / 3);
+#endif
+
+#if 1
+ // range: 0 - 1
+ double a, b, c;
+
+ bool convex = isLeft(p, v, n);
+ if (!convex) return -1e-5;
+
+ a = (n->p - v->p).length();
+ b = (p->p - n->p).length();
+ c = (v->p - p->p).length();
+
+ if (a < 1e-10 || b < 1e-10 || c < 1e-10) return 0.0;
+
+ return std::max(std::min((a+b)/c, std::min((a+c)/b, (b+c)/a)) - 1.0, 0.0);
+#endif
+}
+
+
+
+double carve::triangulate::detail::vertex_info::calcScore() const {
+
+#if 0
+ // examine only this triangle.
+ double this_tri = triScore(prev, this, next);
+ return this_tri;
+#endif
+
+#if 1
+ // attempt to look ahead in the neighbourhood to attempt to clip ears that have good neighbours.
+ double this_tri = triScore(prev, this, next);
+ double next_tri = triScore(prev, next, next->next);
+ double prev_tri = triScore(prev->prev, prev, next);
+
+ return this_tri + std::max(next_tri, prev_tri) * .2;
+#endif
+
+#if 0
+ // attempt to penalise ears that will require producing a sliver triangle.
+ double score = triScore(prev, this, next);
+
+ double a1, a2;
+ a1 = carve::geom2d::atan2(prev->p - next->p);
+ a2 = carve::geom2d::atan2(next->next->p - next->p);
+ if (fabs(a1 - a2) < 1e-5) score -= .5;
+
+ a1 = carve::geom2d::atan2(next->p - prev->p);
+ a2 = carve::geom2d::atan2(prev->prev->p - prev->p);
+ if (fabs(a1 - a2) < 1e-5) score -= .5;
+
+ return score;
+#endif
+}
+
+
+
+bool carve::triangulate::detail::vertex_info::isClipable() const {
+ for (const vertex_info *v_test = next->next; v_test != prev; v_test = v_test->next) {
+ if (v_test->convex) {
+ continue;
+ }
+
+ if (v_test->p == prev->p ||
+ v_test->p == next->p) {
+ continue;
+ }
+
+ if (v_test->p == p) {
+ if (v_test->next->p == prev->p &&
+ v_test->prev->p == next->p) {
+ return false;
+ }
+ if (v_test->next->p == prev->p ||
+ v_test->prev->p == next->p) {
+ continue;
+ }
+ }
+
+ if (pointInTriangle(prev, this, next, v_test)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+
+size_t carve::triangulate::detail::removeDegeneracies(vertex_info *&begin, std::vector<carve::triangulate::tri_idx> &result) {
+ vertex_info *v = begin;
+ vertex_info *n;
+ size_t count = 0;
+ do {
+ bool remove = false;
+ if (v->p == v->next->p) {
+ remove = true;
+ } else if (v->p == v->next->next->p) {
+ if (v->next->p == v->next->next->next->p) {
+ // a 'z' in the loop: z (a) b a b c -> remove a-b-a -> z (a) a b c -> remove a-a-b (next loop) -> z a b c
+ // z --(a)-- b
+ // /
+ // /
+ // a -- b -- d
+ remove = true;
+ } else {
+ // a 'shard' in the loop: z (a) b a c d -> remove a-b-a -> z (a) a b c d -> remove a-a-b (next loop) -> z a b c d
+ // z --(a)-- b
+ // /
+ // /
+ // a -- c -- d
+ // n.b. can only do this if the shard is pointing out of the polygon. i.e. b is outside z-a-c
+ remove = !internalToAngle(v->next->next->next, v, v->prev, v->next->p);
+ }
+ }
+
+ if (remove) {
+ result.push_back(carve::triangulate::tri_idx(v->idx, v->next->idx, v->next->next->idx));
+ n = v->next;
+ if (n == begin) begin = n->next;
+ n->remove();
+ count++;
+ delete n;
+ continue;
+ }
+
+ v = v->next;
+ } while (v != begin);
+ return count;
+}
+
+
+
+bool carve::triangulate::detail::splitAndResume(vertex_info *begin, std::vector<carve::triangulate::tri_idx> &result) {
+ vertex_info *v1, *v2;
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ {
+ std::vector<carve::triangulate::tri_idx> dummy;
+ std::vector<carve::geom2d::P2> dummy_p;
+ vertex_info *v = begin;
+ do {
+ dummy_p.push_back(v->p);
+ v = v->next;
+ } while (v != begin);
+ std::cerr << "input to splitAndResume:" << std::endl;
+ dumpPoly(dummy_p, dummy);
+ }
+#endif
+
+
+ if (!findDiagonal(begin, v1, v2)) return false;
+
+ vertex_info *v1_copy = new vertex_info(*v1);
+ vertex_info *v2_copy = new vertex_info(*v2);
+
+ v1->next = v2;
+ v2->prev = v1;
+
+ v1_copy->next->prev = v1_copy;
+ v2_copy->prev->next = v2_copy;
+
+ v1_copy->prev = v2_copy;
+ v2_copy->next = v1_copy;
+
+ bool r1 = doTriangulate(v1, result);
+ bool r2 = doTriangulate(v1_copy, result);
+ return r1 && r2;
+}
+
+
+
+bool carve::triangulate::detail::doTriangulate(vertex_info *begin, std::vector<carve::triangulate::tri_idx> &result) {
+#if defined(CARVE_DEBUG)
+ std::cerr << "entering doTriangulate" << std::endl;
+#endif
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ {
+ std::vector<carve::triangulate::tri_idx> dummy;
+ std::vector<carve::geom2d::P2> dummy_p;
+ vertex_info *v = begin;
+ do {
+ dummy_p.push_back(v->p);
+ v = v->next;
+ } while (v != begin);
+ dumpPoly(dummy_p, dummy);
+ }
+#endif
+
+ EarQueue vq;
+
+ vertex_info *v = begin;
+ size_t remain = 0;
+ do {
+ if (v->isCandidate()) vq.push(v);
+ v = v->next;
+ remain++;
+ } while (v != begin);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "remain = " << remain << std::endl;
+#endif
+
+ while (vq.size()) {
+ vertex_info *v = vq.pop();
+ if (!v->isClipable()) {
+ v->failed = true;
+ continue;
+ }
+
+ continue_clipping:
+ vertex_info *n = v->next;
+ vertex_info *p = v->prev;
+
+ result.push_back(carve::triangulate::tri_idx(v->prev->idx, v->idx, v->next->idx));
+
+#if defined(CARVE_DEBUG)
+ {
+ std::vector<carve::geom2d::P2> temp;
+ temp.push_back(v->prev->p);
+ temp.push_back(v->p);
+ temp.push_back(v->next->p);
+ std::cerr << "clip " << v << " idx = " << v->idx << " score = " << v->score << " area = " << carve::geom2d::signedArea(temp) << " " << temp[0] << " " << temp[1] << " " << temp[2] << std::endl;
+ }
+#endif
+
+ v->remove();
+ remain--;
+ if (v == begin) begin = v->next;
+ delete v;
+
+ vq.updateVertex(n);
+ vq.updateVertex(p);
+
+ if (n->score < p->score) { std::swap(n, p); }
+
+ if (n->score > 0.25 && n->isCandidate() && n->isClipable()) {
+ vq.remove(n);
+ v = n;
+#if defined(CARVE_DEBUG)
+ std::cerr << " continue clipping (n), score = " << n->score << std::endl;
+#endif
+ goto continue_clipping;
+ }
+
+ if (p->score > 0.25 && p->isCandidate() && p->isClipable()) {
+ vq.remove(p);
+ v = p;
+#if defined(CARVE_DEBUG)
+ std::cerr << " continue clipping (p), score = " << n->score << std::endl;
+#endif
+ goto continue_clipping;
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "looking for new start point" << std::endl;
+ std::cerr << "remain = " << remain << std::endl;
+#endif
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "doTriangulate complete; remain=" << remain << std::endl;
+#endif
+
+ bool ret = true;
+
+ if (remain > 3) {
+ std::vector<carve::geom2d::P2> temp;
+ temp.reserve(remain);
+ vertex_info *v = begin;
+
+ do {
+ temp.push_back(v->p);
+ v = v->next;
+ } while (v != begin);
+
+ if (carve::geom2d::signedArea(temp) == 0) {
+ // XXX: this test will fail in cases where the boundary is
+ // twisted so that a negative area balances a positive area.
+#if defined(CARVE_DEBUG)
+ std::cerr << "skeleton remains. complete." << std::endl;
+#endif
+ goto done;
+ }
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "before removeDegeneracies: remain=" << remain << std::endl;
+#endif
+ remain -= removeDegeneracies(begin, result);
+#if defined(CARVE_DEBUG)
+ std::cerr << "after removeDegeneracies: remain=" << remain << std::endl;
+#endif
+ }
+
+ if (remain > 3) {
+ return splitAndResume(begin, result);
+ } else if (remain == 3) {
+ result.push_back(carve::triangulate::tri_idx(begin->idx, begin->next->idx, begin->next->next->idx));
+ ret = true;
+ } else {
+ ret = true;
+ }
+
+ done:
+ vertex_info *d = begin;
+ do {
+ vertex_info *n = d->next;
+ delete d;
+ d = n;
+ } while (d != begin);
+
+ return ret;
+}
+
+
+
+bool testCandidateAttachment(const std::vector<std::vector<carve::geom2d::P2> > &poly,
+ std::vector<std::pair<size_t, size_t> > &current_f_loop,
+ size_t curr,
+ carve::geom2d::P2 hole_min) {
+ const size_t SZ = current_f_loop.size();
+
+ if (!carve::geom2d::internalToAngle(pvert(poly, current_f_loop[(curr+1) % SZ]),
+ pvert(poly, current_f_loop[curr]),
+ pvert(poly, current_f_loop[(curr+SZ-1) % SZ]),
+ hole_min)) {
+ return false;
+ }
+
+ if (hole_min == pvert(poly, current_f_loop[curr])) {
+ return true;
+ }
+
+ carve::geom2d::LineSegment2 test(hole_min, pvert(poly, current_f_loop[curr]));
+
+ size_t v1 = current_f_loop.size() - 1;
+ size_t v2 = 0;
+ double v1_side = carve::geom2d::orient2d(test.v1, test.v2, pvert(poly, current_f_loop[v1]));
+ double v2_side = 0;
+
+ while (v2 != current_f_loop.size()) {
+ v2_side = carve::geom2d::orient2d(test.v1, test.v2, pvert(poly, current_f_loop[v2]));
+
+ if (v1_side != v2_side) {
+ // XXX: need to test vertices, not indices, because they may
+ // be duplicated.
+ if (pvert(poly, current_f_loop[v1]) != pvert(poly, current_f_loop[curr]) &&
+ pvert(poly, current_f_loop[v2]) != pvert(poly, current_f_loop[curr])) {
+ carve::geom2d::LineSegment2 test2(pvert(poly, current_f_loop[v1]), pvert(poly, current_f_loop[v2]));
+ if (carve::geom2d::lineSegmentIntersection_simple(test, test2)) {
+ // intersection; failed.
+ return false;
+ }
+ }
+ }
+
+ v1 = v2;
+ v1_side = v2_side;
+ ++v2;
+ }
+ return true;
+}
+
+
+
+void
+carve::triangulate::incorporateHolesIntoPolygon(
+ const std::vector<std::vector<carve::geom2d::P2> > &poly,
+ std::vector<std::pair<size_t, size_t> > &result,
+ size_t poly_loop,
+ const std::vector<size_t> &hole_loops) {
+ typedef std::vector<carve::geom2d::P2> loop_t;
+
+ size_t N = poly[poly_loop].size();
+
+ // work out how much space to reserve for the patched in holes.
+ for (size_t i = 0; i < hole_loops.size(); i++) {
+ N += 2 + poly[hole_loops[i]].size();
+ }
+
+ // this is the vector that we will build the result in.
+ result.clear();
+ result.reserve(N);
+
+ // this is a heap of result indices that defines the vertex test order.
+ std::vector<size_t> f_loop_heap;
+ f_loop_heap.reserve(N);
+
+ // add the poly loop to result.
+ for (size_t i = 0; i < poly[poly_loop].size(); ++i) {
+ result.push_back(std::make_pair((size_t)poly_loop, i));
+ }
+
+ if (hole_loops.size() == 0) {
+ return;
+ }
+
+ std::vector<std::pair<size_t, size_t> > h_loop_min_vertex;
+
+ h_loop_min_vertex.reserve(hole_loops.size());
+
+ // find the major axis for the holes - this is the axis that we
+ // will sort on for finding vertices on the polygon to join
+ // holes up to.
+ //
+ // it might also be nice to also look for whether it is better
+ // to sort ascending or descending.
+ //
+ // another trick that could be used is to modify the projection
+ // by 90 degree rotations or flipping about an axis. just as
+ // long as we keep the carve::geom3d::Vector pointers for the
+ // real data in sync, everything should be ok. then we wouldn't
+ // need to accomodate axes or sort order in the main loop.
+
+ // find the bounding box of all the holes.
+ carve::geom2d::P2 h_min, h_max;
+ h_min = h_max = poly[hole_loops[0]][0];
+ for (size_t i = 0; i < hole_loops.size(); ++i) {
+ const loop_t &hole = poly[hole_loops[i]];
+ for (size_t j = 0; j < hole.size(); ++j) {
+ assign_op(h_min, h_min, hole[j], carve::util::min_functor());
+ assign_op(h_max, h_max, hole[j], carve::util::max_functor());
+ }
+ }
+ // choose the axis for which the bbox is largest.
+ int axis = (h_max.x - h_min.x) > (h_max.y - h_min.y) ? 0 : 1;
+
+ // for each hole, find the minimum vertex in the chosen axis.
+ for (size_t i = 0; i < hole_loops.size(); ++i) {
+ const loop_t &hole = poly[hole_loops[i]];
+ size_t best, curr;
+ best = 0;
+ for (curr = 1; curr != hole.size(); ++curr) {
+ if (detail::axisOrdering(hole[curr], hole[best], axis)) {
+ best = curr;
+ }
+ }
+ h_loop_min_vertex.push_back(std::make_pair(hole_loops[i], best));
+ }
+
+ // sort the holes by the minimum vertex.
+ std::sort(h_loop_min_vertex.begin(), h_loop_min_vertex.end(), order_h_loops_2d(poly, axis));
+
+ // now, for each hole, find a vertex in the current polygon loop that it can be joined to.
+ for (unsigned i = 0; i < h_loop_min_vertex.size(); ++i) {
+ // the index of the vertex in the hole to connect.
+ size_t hole_i = h_loop_min_vertex[i].first;
+ size_t hole_i_connect = h_loop_min_vertex[i].second;
+
+ carve::geom2d::P2 hole_min = poly[hole_i][hole_i_connect];
+
+ f_loop_heap.clear();
+ // we order polygon loop vertices that may be able to be connected
+ // to the hole vertex by their distance to the hole vertex
+ heap_ordering_2d _heap_ordering(poly, result, hole_min, axis);
+
+ const size_t SZ = result.size();
+ for (size_t j = 0; j < SZ; ++j) {
+ // it is guaranteed that there exists a polygon vertex with
+ // coord < the min hole coord chosen, which can be joined to
+ // the min hole coord without crossing the polygon
+ // boundary. also, because we merge holes in ascending
+ // order, it is also true that this join can never cross
+ // another hole (and that doesn't need to be tested for).
+ if (pvert(poly, result[j]).v[axis] <= hole_min.v[axis]) {
+ f_loop_heap.push_back(j);
+ std::push_heap(f_loop_heap.begin(), f_loop_heap.end(), _heap_ordering);
+ }
+ }
+
+ // we are going to test each potential (according to the
+ // previous test) polygon vertex as a candidate join. we order
+ // by closeness to the hole vertex, so that the join we make
+ // is as small as possible. to test, we need to check the
+ // joining line segment does not cross any other line segment
+ // in the current polygon loop (excluding those that have the
+ // vertex that we are attempting to join with as an endpoint).
+ size_t attachment_point = result.size();
+
+ while (f_loop_heap.size()) {
+ std::pop_heap(f_loop_heap.begin(), f_loop_heap.end(), _heap_ordering);
+ size_t curr = f_loop_heap.back();
+ f_loop_heap.pop_back();
+ // test the candidate join from result[curr] to hole_min
+
+ if (!testCandidateAttachment(poly, result, curr, hole_min)) {
+ continue;
+ }
+
+ attachment_point = curr;
+ break;
+ }
+
+ if (attachment_point == result.size()) {
+ CARVE_FAIL("didn't manage to link up hole!");
+ }
+
+ patchHoleIntoPolygon_2d(result, attachment_point, hole_i, hole_i_connect, poly[hole_i].size());
+ }
+}
+
+
+
+std::vector<std::pair<size_t, size_t> >
+carve::triangulate::incorporateHolesIntoPolygon(const std::vector<std::vector<carve::geom2d::P2> > &poly) {
+#if 1
+ std::vector<std::pair<size_t, size_t> > result;
+ std::vector<size_t> hole_indices;
+ hole_indices.reserve(poly.size() - 1);
+ for (size_t i = 1; i < poly.size(); ++i) {
+ hole_indices.push_back(i);
+ }
+
+ incorporateHolesIntoPolygon(poly, result, 0, hole_indices);
+
+ return result;
+
+#else
+ typedef std::vector<carve::geom2d::P2> loop_t;
+ size_t N = poly[0].size();
+ //
+ // work out how much space to reserve for the patched in holes.
+ for (size_t i = 0; i < poly.size(); i++) {
+ N += 2 + poly[i].size();
+ }
+
+ // this is the vector that we will build the result in.
+ std::vector<std::pair<size_t, size_t> > current_f_loop;
+ current_f_loop.reserve(N);
+
+ // this is a heap of current_f_loop indices that defines the vertex test order.
+ std::vector<size_t> f_loop_heap;
+ f_loop_heap.reserve(N);
+
+ // add the poly loop to current_f_loop.
+ for (size_t i = 0; i < poly[0].size(); ++i) {
+ current_f_loop.push_back(std::make_pair((size_t)0, i));
+ }
+
+ if (poly.size() == 1) {
+ return current_f_loop;
+ }
+
+ std::vector<std::pair<size_t, size_t> > h_loop_min_vertex;
+
+ h_loop_min_vertex.reserve(poly.size() - 1);
+
+ // find the major axis for the holes - this is the axis that we
+ // will sort on for finding vertices on the polygon to join
+ // holes up to.
+ //
+ // it might also be nice to also look for whether it is better
+ // to sort ascending or descending.
+ //
+ // another trick that could be used is to modify the projection
+ // by 90 degree rotations or flipping about an axis. just as
+ // long as we keep the carve::geom3d::Vector pointers for the
+ // real data in sync, everything should be ok. then we wouldn't
+ // need to accomodate axes or sort order in the main loop.
+
+ // find the bounding box of all the holes.
+ double min_x, min_y, max_x, max_y;
+ min_x = max_x = poly[1][0].x;
+ min_y = max_y = poly[1][0].y;
+ for (size_t i = 1; i < poly.size(); ++i) {
+ const loop_t &hole = poly[i];
+ for (size_t j = 0; j < hole.size(); ++j) {
+ min_x = std::min(min_x, hole[j].x);
+ min_y = std::min(min_y, hole[j].y);
+ max_x = std::max(max_x, hole[j].x);
+ max_y = std::max(max_y, hole[j].y);
+ }
+ }
+
+ // choose the axis for which the bbox is largest.
+ int axis = (max_x - min_x) > (max_y - min_y) ? 0 : 1;
+
+ // for each hole, find the minimum vertex in the chosen axis.
+ for (size_t i = 1; i < poly.size(); ++i) {
+ const loop_t &hole = poly[i];
+ size_t best, curr;
+ best = 0;
+ for (curr = 1; curr != hole.size(); ++curr) {
+ if (detail::axisOrdering(hole[curr], hole[best], axis)) {
+ best = curr;
+ }
+ }
+ h_loop_min_vertex.push_back(std::make_pair(i, best));
+ }
+
+ // sort the holes by the minimum vertex.
+ std::sort(h_loop_min_vertex.begin(), h_loop_min_vertex.end(), order_h_loops_2d(poly, axis));
+
+ // now, for each hole, find a vertex in the current polygon loop that it can be joined to.
+ for (unsigned i = 0; i < h_loop_min_vertex.size(); ++i) {
+ // the index of the vertex in the hole to connect.
+ size_t hole_i = h_loop_min_vertex[i].first;
+ size_t hole_i_connect = h_loop_min_vertex[i].second;
+
+ carve::geom2d::P2 hole_min = poly[hole_i][hole_i_connect];
+
+ f_loop_heap.clear();
+ // we order polygon loop vertices that may be able to be connected
+ // to the hole vertex by their distance to the hole vertex
+ heap_ordering_2d _heap_ordering(poly, current_f_loop, hole_min, axis);
+
+ const size_t SZ = current_f_loop.size();
+ for (size_t j = 0; j < SZ; ++j) {
+ // it is guaranteed that there exists a polygon vertex with
+ // coord < the min hole coord chosen, which can be joined to
+ // the min hole coord without crossing the polygon
+ // boundary. also, because we merge holes in ascending
+ // order, it is also true that this join can never cross
+ // another hole (and that doesn't need to be tested for).
+ if (pvert(poly, current_f_loop[j]).v[axis] <= hole_min.v[axis]) {
+ f_loop_heap.push_back(j);
+ std::push_heap(f_loop_heap.begin(), f_loop_heap.end(), _heap_ordering);
+ }
+ }
+
+ // we are going to test each potential (according to the
+ // previous test) polygon vertex as a candidate join. we order
+ // by closeness to the hole vertex, so that the join we make
+ // is as small as possible. to test, we need to check the
+ // joining line segment does not cross any other line segment
+ // in the current polygon loop (excluding those that have the
+ // vertex that we are attempting to join with as an endpoint).
+ size_t attachment_point = current_f_loop.size();
+
+ while (f_loop_heap.size()) {
+ std::pop_heap(f_loop_heap.begin(), f_loop_heap.end(), _heap_ordering);
+ size_t curr = f_loop_heap.back();
+ f_loop_heap.pop_back();
+ // test the candidate join from current_f_loop[curr] to hole_min
+
+ if (!testCandidateAttachment(poly, current_f_loop, curr, hole_min)) {
+ continue;
+ }
+
+ attachment_point = curr;
+ break;
+ }
+
+ if (attachment_point == current_f_loop.size()) {
+ CARVE_FAIL("didn't manage to link up hole!");
+ }
+
+ patchHoleIntoPolygon_2d(current_f_loop, attachment_point, hole_i, hole_i_connect, poly[hole_i].size());
+ }
+
+ return current_f_loop;
+#endif
+}
+
+
+
+std::vector<std::vector<std::pair<size_t, size_t> > >
+carve::triangulate::mergePolygonsAndHoles(const std::vector<std::vector<carve::geom2d::P2> > &poly) {
+ std::vector<size_t> poly_indices, hole_indices;
+
+ poly_indices.reserve(poly.size());
+ hole_indices.reserve(poly.size());
+
+ for (size_t i = 0; i < poly.size(); ++i) {
+ if (carve::geom2d::signedArea(poly[i]) < 0) {
+ poly_indices.push_back(i);
+ } else {
+ hole_indices.push_back(i);
+ }
+ }
+
+ std::vector<std::vector<std::pair<size_t, size_t> > > result;
+ result.resize(poly_indices.size());
+
+ if (hole_indices.size() == 0) {
+ for (size_t i = 0; i < poly.size(); ++i) {
+ result[i].resize(poly[i].size());
+ for (size_t j = 0; j < poly[i].size(); ++j) {
+ result[i].push_back(std::make_pair(i, j));
+ }
+ }
+ return result;
+ }
+
+ if (poly_indices.size() == 1) {
+ incorporateHolesIntoPolygon(poly, result[0], poly_indices[0], hole_indices);
+
+ return result;
+ }
+
+ throw carve::exception("not implemented");
+}
+
+
+
+void carve::triangulate::triangulate(const std::vector<carve::geom2d::P2> &poly,
+ std::vector<carve::triangulate::tri_idx> &result) {
+ std::vector<detail::vertex_info *> vinfo;
+ const size_t N = poly.size();
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "TRIANGULATION BEGINS" << std::endl;
+#endif
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ dumpPoly(poly, result);
+#endif
+
+ result.clear();
+ if (N < 3) {
+ return;
+ }
+
+ result.reserve(poly.size() - 2);
+
+ if (N == 3) {
+ result.push_back(tri_idx(0, 1, 2));
+ return;
+ }
+
+ vinfo.resize(N);
+
+ vinfo[0] = new detail::vertex_info(poly[0], 0);
+ for (size_t i = 1; i < N-1; ++i) {
+ vinfo[i] = new detail::vertex_info(poly[i], i);
+ vinfo[i]->prev = vinfo[i-1];
+ vinfo[i-1]->next = vinfo[i];
+ }
+ vinfo[N-1] = new detail::vertex_info(poly[N-1], N-1);
+ vinfo[N-1]->prev = vinfo[N-2];
+ vinfo[N-1]->next = vinfo[0];
+ vinfo[0]->prev = vinfo[N-1];
+ vinfo[N-2]->next = vinfo[N-1];
+
+ for (size_t i = 0; i < N; ++i) {
+ vinfo[i]->recompute();
+ }
+
+ detail::vertex_info *begin = vinfo[0];
+
+ removeDegeneracies(begin, result);
+ doTriangulate(begin, result);
+
+#if defined(CARVE_DEBUG)
+ std::cerr << "TRIANGULATION ENDS" << std::endl;
+#endif
+
+#if defined(CARVE_DEBUG_WRITE_PLY_DATA)
+ dumpPoly(poly, result);
+#endif
+}
+
+
+
+void carve::triangulate::detail::tri_pair_t::flip(vert_edge_t &old_edge,
+ vert_edge_t &new_edge,
+ vert_edge_t perim[4]) {
+ unsigned ai, bi;
+ unsigned cross_ai, cross_bi;
+
+ findSharedEdge(ai, bi);
+ old_edge = ordered_vert_edge_t(a->v[ai], b->v[bi]);
+
+ cross_ai = P(ai);
+ cross_bi = P(bi);
+ new_edge = ordered_vert_edge_t(a->v[cross_ai], b->v[cross_bi]);
+
+ score = -score;
+
+ a->v[N(ai)] = b->v[cross_bi];
+ b->v[N(bi)] = a->v[cross_ai];
+
+ perim[0] = ordered_vert_edge_t(a->v[P(ai)], a->v[ai]);
+ perim[1] = ordered_vert_edge_t(a->v[N(ai)], a->v[ai]); // this edge was a b-edge
+
+ perim[2] = ordered_vert_edge_t(b->v[P(bi)], b->v[bi]);
+ perim[3] = ordered_vert_edge_t(b->v[N(bi)], b->v[bi]); // this edge was an a-edge
+}
+
+
+
+void carve::triangulate::detail::tri_pairs_t::insert(unsigned a, unsigned b, carve::triangulate::tri_idx *t) {
+ tri_pair_t *tp;
+ if (a < b) {
+ tp = storage[vert_edge_t(a,b)];
+ if (!tp) {
+ tp = storage[vert_edge_t(a,b)] = new tri_pair_t;
+ }
+ tp->a = t;
+ } else {
+ tp = storage[vert_edge_t(b,a)];
+ if (!tp) {
+ tp = storage[vert_edge_t(b,a)] = new tri_pair_t;
+ }
+ tp->b = t;
+ }
+}
diff --git a/extern/carve/mkfiles.sh b/extern/carve/mkfiles.sh
new file mode 100755
index 00000000000..d117d7531bd
--- /dev/null
+++ b/extern/carve/mkfiles.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+find ./include/ -type f | sed -r 's/^\.\///' > files.txt
+find ./lib/ -type f | sed -r 's/^\.\///' >> files.txt
diff --git a/extern/carve/patches/files/config.h b/extern/carve/patches/files/config.h
new file mode 100644
index 00000000000..fdae2d2843f
--- /dev/null
+++ b/extern/carve/patches/files/config.h
@@ -0,0 +1,12 @@
+#define CARVE_VERSION "2.0.0a"
+
+#undef CARVE_DEBUG
+#undef CARVE_DEBUG_WRITE_PLY_DATA
+
+#if defined(__GNUC__)
+# if !defined(HAVE_BOOST_UNORDERED_COLLECTIONS)
+# define HAVE_TR1_UNORDERED_COLLECTIONS
+# endif
+
+# define HAVE_STDINT_H
+#endif
diff --git a/extern/carve/patches/files/random.hpp b/extern/carve/patches/files/random.hpp
new file mode 100644
index 00000000000..15866bb496e
--- /dev/null
+++ b/extern/carve/patches/files/random.hpp
@@ -0,0 +1,773 @@
+#pragma once
+
+#include <iostream>
+#include <vector>
+#include <limits>
+#include <stdexcept>
+#include <cmath>
+#include <algorithm>
+
+#if !defined(_MSC_VER)
+#include <stdint.h>
+#endif
+
+namespace boost {
+
+// type_traits could help here, but I don't want to depend on type_traits.
+template<class T>
+struct ptr_helper
+{
+ typedef T value_type;
+ typedef T& reference_type;
+ typedef const T& rvalue_type;
+ static reference_type ref(T& r) { return r; }
+ static const T& ref(const T& r) { return r; }
+};
+
+template<class T>
+struct ptr_helper<T&>
+{
+ typedef T value_type;
+ typedef T& reference_type;
+ typedef T& rvalue_type;
+ static reference_type ref(T& r) { return r; }
+ static const T& ref(const T& r) { return r; }
+};
+
+template<class T>
+struct ptr_helper<T*>
+{
+ typedef T value_type;
+ typedef T& reference_type;
+ typedef T* rvalue_type;
+ static reference_type ref(T * p) { return *p; }
+ static const T& ref(const T * p) { return *p; }
+};
+
+template<class UniformRandomNumberGenerator>
+class pass_through_engine
+{
+private:
+ typedef ptr_helper<UniformRandomNumberGenerator> helper_type;
+
+public:
+ typedef typename helper_type::value_type base_type;
+ typedef typename base_type::result_type result_type;
+
+ explicit pass_through_engine(UniformRandomNumberGenerator rng)
+ // make argument an rvalue to avoid matching Generator& constructor
+ : _rng(static_cast<typename helper_type::rvalue_type>(rng))
+ { }
+
+ result_type min () const { return (base().min)(); }
+ result_type max () const { return (base().max)(); }
+ base_type& base() { return helper_type::ref(_rng); }
+ const base_type& base() const { return helper_type::ref(_rng); }
+
+ result_type operator()() { return base()(); }
+
+private:
+ UniformRandomNumberGenerator _rng;
+};
+
+template<class RealType>
+class new_uniform_01
+{
+public:
+ typedef RealType input_type;
+ typedef RealType result_type;
+ // compiler-generated copy ctor and copy assignment are fine
+ result_type min () const { return result_type(0); }
+ result_type max () const { return result_type(1); }
+ void reset() { }
+
+ template<class Engine>
+ result_type operator()(Engine& eng) {
+ for (;;) {
+ typedef typename Engine::result_type base_result;
+ result_type factor = result_type(1) /
+ (result_type((eng.max)()-(eng.min)()) +
+ result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0));
+ result_type result = result_type(eng() - (eng.min)()) * factor;
+ if (result < result_type(1))
+ return result;
+ }
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os, const new_uniform_01&)
+ {
+ return os;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, new_uniform_01&)
+ {
+ return is;
+ }
+};
+
+template<class UniformRandomNumberGenerator, class RealType>
+class backward_compatible_uniform_01
+{
+ typedef ptr_helper<UniformRandomNumberGenerator> traits;
+ typedef pass_through_engine<UniformRandomNumberGenerator> internal_engine_type;
+public:
+ typedef UniformRandomNumberGenerator base_type;
+ typedef RealType result_type;
+
+ static const bool has_fixed_range = false;
+
+ explicit backward_compatible_uniform_01(typename traits::rvalue_type rng)
+ : _rng(rng),
+ _factor(result_type(1) /
+ (result_type((_rng.max)()-(_rng.min)()) +
+ result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0)))
+ {
+ }
+ // compiler-generated copy ctor and copy assignment are fine
+
+ result_type min () const { return result_type(0); }
+ result_type max () const { return result_type(1); }
+ typename traits::value_type& base() { return _rng.base(); }
+ const typename traits::value_type& base() const { return _rng.base(); }
+ void reset() { }
+
+ result_type operator()() {
+ for (;;) {
+ result_type result = result_type(_rng() - (_rng.min)()) * _factor;
+ if (result < result_type(1))
+ return result;
+ }
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os, const backward_compatible_uniform_01& u)
+ {
+ os << u._rng;
+ return os;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, backward_compatible_uniform_01& u)
+ {
+ is >> u._rng;
+ return is;
+ }
+
+private:
+ typedef typename internal_engine_type::result_type base_result;
+ internal_engine_type _rng;
+ result_type _factor;
+};
+
+// A definition is required even for integral static constants
+template<class UniformRandomNumberGenerator, class RealType>
+const bool backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType>::has_fixed_range;
+
+template<class UniformRandomNumberGenerator>
+struct select_uniform_01
+{
+ template<class RealType>
+ struct apply
+ {
+ typedef backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType> type;
+ };
+};
+
+template<>
+struct select_uniform_01<float>
+{
+ template<class RealType>
+ struct apply
+ {
+ typedef new_uniform_01<float> type;
+ };
+};
+
+template<>
+struct select_uniform_01<double>
+{
+ template<class RealType>
+ struct apply
+ {
+ typedef new_uniform_01<double> type;
+ };
+};
+
+template<>
+struct select_uniform_01<long double>
+{
+ template<class RealType>
+ struct apply
+ {
+ typedef new_uniform_01<long double> type;
+ };
+};
+
+// Because it is so commonly used: uniform distribution on the real [0..1)
+// range. This allows for specializations to avoid a costly int -> float
+// conversion plus float multiplication
+template<class UniformRandomNumberGenerator = double, class RealType = double>
+class uniform_01
+ : public select_uniform_01<UniformRandomNumberGenerator>::template apply<RealType>::type
+{
+ typedef typename select_uniform_01<UniformRandomNumberGenerator>::template apply<RealType>::type impl_type;
+ typedef ptr_helper<UniformRandomNumberGenerator> traits;
+public:
+
+ uniform_01() {}
+
+ explicit uniform_01(typename traits::rvalue_type rng)
+ : impl_type(rng)
+ {
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_01& u)
+ {
+ os << static_cast<const impl_type&>(u);
+ return os;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, uniform_01& u)
+ {
+ is >> static_cast<impl_type&>(u);
+ return is;
+ }
+};
+
+template<class UniformRandomNumberGenerator, class IntType = unsigned long>
+class uniform_int_float
+{
+public:
+ typedef UniformRandomNumberGenerator base_type;
+ typedef IntType result_type;
+
+ uniform_int_float(base_type rng, IntType min_arg = 0, IntType max_arg = 0xffffffff)
+ : _rng(rng), _min(min_arg), _max(max_arg)
+ {
+ init();
+ }
+
+ result_type min () const { return _min; }
+ result_type max () const { return _max; }
+ base_type& base() { return _rng.base(); }
+ const base_type& base() const { return _rng.base(); }
+
+ result_type operator()()
+ {
+ return static_cast<IntType>(_rng() * _range) + _min;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_int_float& ud)
+ {
+ os << ud._min << " " << ud._max;
+ return os;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, uniform_int_float& ud)
+ {
+ is >> std::ws >> ud._min >> std::ws >> ud._max;
+ ud.init();
+ return is;
+ }
+
+private:
+ void init()
+ {
+ _range = static_cast<base_result>(_max-_min)+1;
+ }
+
+ typedef typename base_type::result_type base_result;
+ uniform_01<base_type> _rng;
+ result_type _min, _max;
+ base_result _range;
+};
+
+
+template<class UniformRandomNumberGenerator, class CharT, class Traits>
+std::basic_ostream<CharT,Traits>&
+operator<<(
+ std::basic_ostream<CharT,Traits>& os
+ , const pass_through_engine<UniformRandomNumberGenerator>& ud
+ )
+{
+ return os << ud.base();
+}
+
+template<class UniformRandomNumberGenerator, class CharT, class Traits>
+std::basic_istream<CharT,Traits>&
+operator>>(
+ std::basic_istream<CharT,Traits>& is
+ , const pass_through_engine<UniformRandomNumberGenerator>& ud
+ )
+{
+ return is >> ud.base();
+}
+
+
+
+template<class RealType = double>
+class normal_distribution
+{
+public:
+ typedef RealType input_type;
+ typedef RealType result_type;
+
+ explicit normal_distribution(const result_type& mean_arg = result_type(0),
+ const result_type& sigma_arg = result_type(1))
+ : _mean(mean_arg), _sigma(sigma_arg), _valid(false)
+ {
+ //assert(_sigma >= result_type(0));
+ }
+
+ // compiler-generated copy constructor is NOT fine, need to purge cache
+ normal_distribution(const normal_distribution& other)
+ : _mean(other._mean), _sigma(other._sigma), _valid(false)
+ {
+ }
+
+ // compiler-generated copy ctor and assignment operator are fine
+
+ RealType mean() const { return _mean; }
+ RealType sigma() const { return _sigma; }
+
+ void reset() { _valid = false; }
+
+ template<class Engine>
+ result_type operator()(Engine& eng)
+ {
+#ifndef BOOST_NO_STDC_NAMESPACE
+ // allow for Koenig lookup
+ using std::sqrt; using std::log; using std::sin; using std::cos;
+#endif
+ if(!_valid) {
+ _r1 = eng();
+ _r2 = eng();
+ _cached_rho = sqrt(-result_type(2) * log(result_type(1)-_r2));
+ _valid = true;
+ } else {
+ _valid = false;
+ }
+ // Can we have a boost::mathconst please?
+ const result_type pi = result_type(3.14159265358979323846);
+
+ return _cached_rho * (_valid ?
+ cos(result_type(2)*pi*_r1) :
+ sin(result_type(2)*pi*_r1))
+ * _sigma + _mean;
+ }
+
+#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os, const normal_distribution& nd)
+ {
+ os << nd._mean << " " << nd._sigma << " "
+ << nd._valid << " " << nd._cached_rho << " " << nd._r1;
+ return os;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, normal_distribution& nd)
+ {
+ is >> std::ws >> nd._mean >> std::ws >> nd._sigma
+ >> std::ws >> nd._valid >> std::ws >> nd._cached_rho
+ >> std::ws >> nd._r1;
+ return is;
+ }
+#endif
+private:
+ result_type _mean, _sigma;
+ result_type _r1, _r2, _cached_rho;
+ bool _valid;
+};
+
+// http://www.math.keio.ac.jp/matumoto/emt.html
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+class mersenne_twister
+{
+public:
+ typedef UIntType result_type;
+ static const int word_size = w;
+ static const int state_size = n;
+ static const int shift_size = m;
+ static const int mask_bits = r;
+ static const UIntType parameter_a = a;
+ static const int output_u = u;
+ static const int output_s = s;
+ static const UIntType output_b = b;
+ static const int output_t = t;
+ static const UIntType output_c = c;
+ static const int output_l = l;
+
+ static const bool has_fixed_range = false;
+
+ mersenne_twister() { seed(); }
+
+ explicit mersenne_twister(const UIntType& value)
+ { seed(value); }
+ template<class It> mersenne_twister(It& first, It last) { seed(first,last); }
+
+ template<class Generator> \
+ explicit mersenne_twister(Generator& gen)
+ { seed(gen); }
+
+ // compiler-generated copy ctor and assignment operator are fine
+
+ void seed() { seed(UIntType(5489)); }
+
+ void seed(const UIntType& value)
+ {
+ // New seeding algorithm from
+ // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
+ // In the previous versions, MSBs of the seed affected only MSBs of the
+ // state x[].
+ const UIntType mask = ~0u;
+ x[0] = value & mask;
+ for (i = 1; i < n; i++) {
+ // See Knuth "The Art of Computer Programming" Vol. 2, 3rd ed., page 106
+ x[i] = (1812433253UL * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;
+ }
+ }
+
+ // For GCC, moving this function out-of-line prevents inlining, which may
+ // reduce overall object code size. However, MSVC does not grok
+ // out-of-line definitions of member function templates.
+ template<class Generator> \
+ void seed(Generator& gen)
+ {
+/*#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
+ BOOST_STATIC_ASSERT(!std::numeric_limits<result_type>::is_signed);
+#endif*/
+ // I could have used std::generate_n, but it takes "gen" by value
+ for(int j = 0; j < n; j++)
+ x[j] = gen();
+ i = n;
+ }
+
+ template<class It>
+ void seed(It& first, It last)
+ {
+ int j;
+ for(j = 0; j < n && first != last; ++j, ++first)
+ x[j] = *first;
+ i = n;
+ if(first == last && j < n)
+ throw std::invalid_argument("mersenne_twister::seed");
+ }
+
+ result_type min () const { return 0; }
+ result_type max () const
+ {
+ // avoid "left shift count >= with of type" warning
+ result_type res = 0;
+ for(int j = 0; j < w; ++j)
+ res |= (1u << j);
+ return res;
+ }
+
+ result_type operator()();
+ static bool validation(result_type v) { return val == v; }
+
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os, const mersenne_twister& mt)
+ {
+ for(int j = 0; j < mt.state_size; ++j)
+ os << mt.compute(j) << " ";
+ return os;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, mersenne_twister& mt)
+ {
+ for(int j = 0; j < mt.state_size; ++j)
+ is >> mt.x[j] >> std::ws;
+ // MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template
+ // value parameter "n" available from the class template scope, so use
+ // the static constant with the same value
+ mt.i = mt.state_size;
+ return is;
+ }
+
+ friend bool operator==(const mersenne_twister& x, const mersenne_twister& y)
+ {
+ for(int j = 0; j < state_size; ++j)
+ if(x.compute(j) != y.compute(j))
+ return false;
+ return true;
+ }
+
+ friend bool operator!=(const mersenne_twister& x, const mersenne_twister& y)
+ { return !(x == y); }
+
+private:
+ // returns x(i-n+index), where index is in 0..n-1
+ UIntType compute(unsigned int index) const
+ {
+ // equivalent to (i-n+index) % 2n, but doesn't produce negative numbers
+ return x[ (i + n + index) % (2*n) ];
+ }
+ void twist(int block);
+
+ // state representation: next output is o(x(i))
+ // x[0] ... x[k] x[k+1] ... x[n-1] x[n] ... x[2*n-1] represents
+ // x(i-k) ... x(i) x(i+1) ... x(i-k+n-1) x(i-k-n) ... x[i(i-k-1)]
+ // The goal is to always have x(i-n) ... x(i-1) available for
+ // operator== and save/restore.
+
+ UIntType x[2*n];
+ int i;
+};
+
+// A definition is required even for integral static constants
+
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const bool mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::has_fixed_range;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::state_size;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::shift_size;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::mask_bits;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::parameter_a;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_u;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_s;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_b;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_t;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const UIntType mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_c;
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+const int mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::output_l;
+
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+void mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::twist(int block)
+{
+ const UIntType upper_mask = (~0u) << r;
+ const UIntType lower_mask = ~upper_mask;
+
+ if(block == 0) {
+ for(int j = n; j < 2*n; j++) {
+ UIntType y = (x[j-n] & upper_mask) | (x[j-(n-1)] & lower_mask);
+ x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
+ }
+ } else if (block == 1) {
+ // split loop to avoid costly modulo operations
+ { // extra scope for MSVC brokenness w.r.t. for scope
+ for(int j = 0; j < n-m; j++) {
+ UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
+ x[j] = x[j+n+m] ^ (y >> 1) ^ (y&1 ? a : 0);
+ }
+ }
+
+ for(int j = n-m; j < n-1; j++) {
+ UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
+ x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
+ }
+ // last iteration
+ UIntType y = (x[2*n-1] & upper_mask) | (x[0] & lower_mask);
+ x[n-1] = x[m-1] ^ (y >> 1) ^ (y&1 ? a : 0);
+ i = 0;
+ }
+}
+
+template<class UIntType, int w, int n, int m, int r, UIntType a, int u,
+ int s, UIntType b, int t, UIntType c, int l, UIntType val>
+inline typename mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::result_type
+mersenne_twister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::operator()()
+{
+ if(i == n)
+ twist(0);
+ else if(i >= 2*n)
+ twist(1);
+ // Step 4
+ UIntType z = x[i];
+ ++i;
+ z ^= (z >> u);
+ z ^= ((z << s) & b);
+ z ^= ((z << t) & c);
+ z ^= (z >> l);
+ return z;
+}
+
+typedef mersenne_twister<uint32_t,32,351,175,19,0xccab8ee7,11,
+ 7,0x31b6ab00,15,0xffe50000,17, 0xa37d3c92> mt11213b;
+
+// validation by experiment from mt19937.c
+typedef mersenne_twister<uint32_t,32,624,397,31,0x9908b0df,11,
+ 7,0x9d2c5680,15,0xefc60000,18, 3346425566U> mt19937;
+
+
+template<class RealType = double, class Cont = std::vector<RealType> >
+class uniform_on_sphere
+{
+public:
+ typedef RealType input_type;
+ typedef Cont result_type;
+
+ explicit uniform_on_sphere(int dim = 2) : _container(dim), _dim(dim) { }
+
+ // compiler-generated copy ctor and assignment operator are fine
+
+ void reset() { _normal.reset(); }
+
+ template<class Engine>
+ const result_type & operator()(Engine& eng)
+ {
+ RealType sqsum = 0;
+ for(typename Cont::iterator it = _container.begin();
+ it != _container.end();
+ ++it) {
+ RealType val = _normal(eng);
+ *it = val;
+ sqsum += val * val;
+ }
+ using std::sqrt;
+ // for all i: result[i] /= sqrt(sqsum)
+ std::transform(_container.begin(), _container.end(), _container.begin(),
+ std::bind2nd(std::divides<RealType>(), sqrt(sqsum)));
+ return _container;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_ostream<CharT,Traits>&
+ operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_on_sphere& sd)
+ {
+ os << sd._dim;
+ return os;
+ }
+
+ template<class CharT, class Traits>
+ friend std::basic_istream<CharT,Traits>&
+ operator>>(std::basic_istream<CharT,Traits>& is, uniform_on_sphere& sd)
+ {
+ is >> std::ws >> sd._dim;
+ sd._container.resize(sd._dim);
+ return is;
+ }
+
+private:
+ normal_distribution<RealType> _normal;
+ result_type _container;
+ int _dim;
+};
+
+
+
+template<bool have_int, bool want_int>
+struct engine_helper;
+
+
+template<>
+struct engine_helper<true, true>
+{
+ template<class Engine, class DistInputType>
+ struct impl
+ {
+ typedef pass_through_engine<Engine> type;
+ };
+};
+
+template<>
+struct engine_helper<false, false>
+{
+ template<class Engine, class DistInputType>
+ struct impl
+ {
+ typedef uniform_01<Engine, DistInputType> type;
+ };
+};
+
+template<>
+struct engine_helper<true, false>
+{
+ template<class Engine, class DistInputType>
+ struct impl
+ {
+ typedef uniform_01<Engine, DistInputType> type;
+ };
+};
+
+template<>
+struct engine_helper<false, true>
+{
+ template<class Engine, class DistInputType>
+ struct impl
+ {
+ typedef uniform_int_float<Engine, unsigned long> type;
+ };
+};
+
+template<class Engine, class Distribution>
+class variate_generator
+{
+private:
+ typedef pass_through_engine<Engine> decorated_engine;
+
+public:
+ typedef typename decorated_engine::base_type engine_value_type;
+ typedef Engine engine_type;
+ typedef Distribution distribution_type;
+ typedef typename Distribution::result_type result_type;
+
+ variate_generator(Engine e, Distribution d)
+ : _eng(decorated_engine(e)), _dist(d) { }
+
+ result_type operator()() { return _dist(_eng); }
+ template<class T>
+ result_type operator()(T value) { return _dist(_eng, value); }
+
+ engine_value_type& engine() { return _eng.base().base(); }
+ const engine_value_type& engine() const { return _eng.base().base(); }
+
+ distribution_type& distribution() { return _dist; }
+ const distribution_type& distribution() const { return _dist; }
+
+ result_type min () const { return (distribution().min)(); }
+ result_type max () const { return (distribution().max)(); }
+
+private:
+ enum {
+ have_int = std::numeric_limits<typename decorated_engine::result_type>::is_integer,
+ want_int = std::numeric_limits<typename Distribution::input_type>::is_integer
+ };
+ typedef typename engine_helper<have_int, want_int>::template impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
+
+ internal_engine_type _eng;
+ distribution_type _dist;
+};
+
+} // namespace boost
diff --git a/extern/carve/patches/gcc46.patch b/extern/carve/patches/gcc46.patch
new file mode 100644
index 00000000000..a8384dcdab8
--- /dev/null
+++ b/extern/carve/patches/gcc46.patch
@@ -0,0 +1,11 @@
+diff -r 525472fb477a include/carve/polyline_iter.hpp
+--- a/include/carve/polyline_iter.hpp Sun Jan 15 23:07:40 2012 -0500
++++ b/include/carve/polyline_iter.hpp Wed Jan 18 00:41:13 2012 +0600
+@@ -20,6 +20,7 @@
+ #include <list>
+ #include <iterator>
+ #include <limits>
++#include <cstddef>
+
+ #include <carve/polyline_decl.hpp>
+
diff --git a/extern/carve/patches/includes.patch b/extern/carve/patches/includes.patch
new file mode 100644
index 00000000000..bdf97c846e7
--- /dev/null
+++ b/extern/carve/patches/includes.patch
@@ -0,0 +1,84 @@
+diff -r c8cbec41cd35 include/carve/exact.hpp
+--- a/include/carve/exact.hpp Thu Dec 01 15:51:44 2011 -0500
++++ b/include/carve/exact.hpp Wed Jan 11 18:48:16 2012 +0600
+@@ -21,7 +21,7 @@
+
+ #include <vector>
+ #include <numeric>
+-
++#include <algorithm>
+
+
+ namespace carve {
+diff -r c8cbec41cd35 include/carve/geom2d.hpp
+--- a/include/carve/geom2d.hpp Thu Dec 01 15:51:44 2011 -0500
++++ b/include/carve/geom2d.hpp Wed Jan 11 18:48:16 2012 +0600
+@@ -25,6 +25,7 @@
+ #include <carve/geom.hpp>
+
+ #include <vector>
++#include <algorithm>
+
+ #include <math.h>
+
+diff -r c8cbec41cd35 include/carve/mesh_impl.hpp
+--- a/include/carve/mesh_impl.hpp Thu Dec 01 15:51:44 2011 -0500
++++ b/include/carve/mesh_impl.hpp Wed Jan 11 18:48:16 2012 +0600
+@@ -24,6 +24,8 @@
+ #include <iostream>
+ #include <deque>
+
++#include <stddef.h>
++
+ namespace carve {
+ namespace mesh {
+
+diff -r c8cbec41cd35 include/carve/polyhedron_base.hpp
+--- a/include/carve/polyhedron_base.hpp Thu Dec 01 15:51:44 2011 -0500
++++ b/include/carve/polyhedron_base.hpp Wed Jan 11 18:48:16 2012 +0600
+@@ -25,6 +25,8 @@
+ #include <carve/edge_decl.hpp>
+ #include <carve/face_decl.hpp>
+
++#include <stddef.h>
++
+ namespace carve {
+ namespace poly {
+
+diff -r c8cbec41cd35 include/carve/rtree.hpp
+--- a/include/carve/rtree.hpp Thu Dec 01 15:51:44 2011 -0500
++++ b/include/carve/rtree.hpp Wed Jan 11 18:48:16 2012 +0600
+@@ -27,6 +27,10 @@
+ #include <cmath>
+ #include <limits>
+
++#if defined(HAVE_STDINT_H)
++# include <stdint.h>
++#endif
++
+ namespace carve {
+ namespace geom {
+
+diff -r c8cbec41cd35 include/carve/vector.hpp
+--- a/include/carve/vector.hpp Thu Dec 01 15:51:44 2011 -0500
++++ b/include/carve/vector.hpp Wed Jan 11 18:48:16 2012 +0600
+@@ -24,6 +24,7 @@
+ #include <carve/geom3d.hpp>
+
+ #include <sstream>
++#include <algorithm>
+
+ #include <math.h>
+
+diff -r c8cbec41cd35 src/extrude.cpp
+--- a/src/extrude.cpp Thu Dec 01 15:51:44 2011 -0500
++++ b/src/extrude.cpp Wed Jan 11 18:48:16 2012 +0600
+@@ -34,6 +34,8 @@
+ #include <cctype>
+ #include <stdexcept>
+
++#include <stdexcept>
++
+ template<unsigned ndim>
+ carve::geom::vector<ndim> lerp(
+ double t,
diff --git a/extern/carve/patches/mesh_iterator.patch b/extern/carve/patches/mesh_iterator.patch
new file mode 100644
index 00000000000..1b9e12866bf
--- /dev/null
+++ b/extern/carve/patches/mesh_iterator.patch
@@ -0,0 +1,21 @@
+diff -r c8cbec41cd35 include/carve/mesh.hpp
+--- a/include/carve/mesh.hpp Thu Dec 01 15:51:44 2011 -0500
++++ b/include/carve/mesh.hpp Thu Jan 12 00:19:58 2012 +0600
+@@ -719,13 +719,13 @@
+ void rev(size_t n);
+ void adv(int n);
+
+- FaceIter operator++(int) { FaceIter tmp = *this; fwd(1); return tmp; }
+- FaceIter operator+(int v) { FaceIter tmp = *this; adv(v); return tmp; }
++ FaceIter operator++(int) { FaceIter tmp = *this; tmp.fwd(1); return tmp; }
++ FaceIter operator+(int v) { FaceIter tmp = *this; tmp.adv(v); return tmp; }
+ FaceIter &operator++() { fwd(1); return *this; }
+ FaceIter &operator+=(int v) { adv(v); return *this; }
+
+- FaceIter operator--(int) { FaceIter tmp = *this; rev(1); return tmp; }
+- FaceIter operator-(int v) { FaceIter tmp = *this; adv(-v); return tmp; }
++ FaceIter operator--(int) { FaceIter tmp = *this; tmp.rev(1); return tmp; }
++ FaceIter operator-(int v) { FaceIter tmp = *this; tmp.adv(-v); return tmp; }
+ FaceIter &operator--() { rev(1); return *this; }
+ FaceIter &operator-=(int v) { adv(-v); return *this; }
+
diff --git a/extern/carve/patches/mingw.patch b/extern/carve/patches/mingw.patch
new file mode 100644
index 00000000000..c237edf18e9
--- /dev/null
+++ b/extern/carve/patches/mingw.patch
@@ -0,0 +1,15 @@
+diff -r 525472fb477a include/carve/win32.h
+--- a/include/carve/win32.h Sun Jan 15 23:07:40 2012 -0500
++++ b/include/carve/win32.h Wed Jan 18 00:40:10 2012 +0600
+@@ -8,9 +8,11 @@
+ #include <string.h>
+ #include <stdlib.h>
+
++#if !defined(__MINGW32__)
+ inline int strcasecmp(const char *a, const char *b) {
+ return _stricmp(a,b);
+ }
++#endif
+
+ inline void srandom(unsigned long input) {
+ srand(input);
diff --git a/extern/carve/patches/series b/extern/carve/patches/series
new file mode 100644
index 00000000000..585d90659bd
--- /dev/null
+++ b/extern/carve/patches/series
@@ -0,0 +1,6 @@
+strict_flags.patch
+includes.patch
+win32.patch
+mesh_iterator.patch
+mingw.patch
+gcc46.patch
diff --git a/extern/carve/patches/strict_flags.patch b/extern/carve/patches/strict_flags.patch
new file mode 100644
index 00000000000..5e4b867ba26
--- /dev/null
+++ b/extern/carve/patches/strict_flags.patch
@@ -0,0 +1,46 @@
+diff -r 47dfdaff1dd5 include/carve/csg_triangulator.hpp
+--- a/include/carve/csg_triangulator.hpp Thu Jan 12 15:49:04 2012 -0500
++++ b/include/carve/csg_triangulator.hpp Fri Jan 13 03:13:32 2012 +0600
+@@ -174,6 +174,7 @@
+
+ double scoreQuad(edge_map_t::iterator i, edge_map_t &edge_map) {
+ if (!(*i).second.first || !(*i).second.second) return -1;
++ return 0;
+ }
+
+ carve::mesh::MeshSet<3>::face_t *mergeQuad(edge_map_t::iterator i, edge_map_t &edge_map) {
+diff -r 47dfdaff1dd5 include/carve/exact.hpp
+--- a/include/carve/exact.hpp Thu Jan 12 15:49:04 2012 -0500
++++ b/include/carve/exact.hpp Fri Jan 13 03:13:32 2012 +0600
+@@ -379,7 +379,7 @@
+ prod_2_1(b, a, r);
+ }
+
+- static inline double prod_4_1(const double *a, const double *b, double *r) {
++ static inline void prod_4_1(const double *a, const double *b, double *r) {
+ double b_sp[2]; split(b[0], b_sp);
+ double t1[2]; prod_1_1s(a+0, b, b_sp, t1);
+ r[0] = t1[0];
+@@ -639,8 +639,9 @@
+ }
+
+
+- exact_t operator+(const exact_t &a, const exact_t &b) {
+- }
++ // XXX: not implemented yet
++ //exact_t operator+(const exact_t &a, const exact_t &b) {
++ //}
+
+
+
+diff -r 47dfdaff1dd5 src/selfintersect.cpp
+--- a/src/selfintersect.cpp Thu Jan 12 15:49:04 2012 -0500
++++ b/src/selfintersect.cpp Fri Jan 13 03:13:32 2012 +0600
+@@ -465,6 +465,7 @@
+
+ // returns true if no intersection, based upon edge^a_i and edge^b_j separating axis.
+ bool sat_edge(const vec3 tri_a[3], const vec3 tri_b[3], unsigned i, unsigned j) {
++ return false;
+ }
+
+
diff --git a/extern/carve/patches/win32.patch b/extern/carve/patches/win32.patch
new file mode 100644
index 00000000000..e0834ef1ce1
--- /dev/null
+++ b/extern/carve/patches/win32.patch
@@ -0,0 +1,29 @@
+diff -r 47dfdaff1dd5 include/carve/win32.h
+--- a/include/carve/win32.h Thu Jan 12 15:49:04 2012 -0500
++++ b/include/carve/win32.h Fri Jan 13 03:15:51 2012 +0600
+@@ -32,14 +32,19 @@
+
+ # if _MSC_VER < 1600
+ // stdint.h is not available before VS2010
+-typedef char int8_t;
+-typedef short int16_t;
+-typedef long int32_t;
++#if defined(_WIN32) && !defined(__MINGW32__)
++/* The __intXX are built-in types of the visual complier! So we don't
++ need to include anything else here.
++ This typedefs should be in sync with types from MEM_sys_types.h */
+
+-typedef unsigned char uint8_t;
+-typedef unsigned short uint16_t;
+-typedef unsigned long uint32_t;
++typedef signed __int8 int8_t;
++typedef signed __int16 int16_t;
++typedef signed __int32 int32_t;
+
++typedef unsigned __int8 uint8_t;
++typedef unsigned __int16 uint16_t;
++typedef unsigned __int32 uint32_t;
++#endif
+ typedef __int64 int64_t;
+ typedef unsigned __int64 uint64_t;
+ # else
diff --git a/intern/boolop/CMakeLists.txt b/intern/boolop/CMakeLists.txt
index 29ea1a28c5f..d0870c8da9c 100644
--- a/intern/boolop/CMakeLists.txt
+++ b/intern/boolop/CMakeLists.txt
@@ -39,43 +39,71 @@ set(INC_SYS
)
-set(SRC
- intern/BOP_BBox.cpp
- intern/BOP_BSPNode.cpp
- intern/BOP_BSPTree.cpp
- intern/BOP_Edge.cpp
- intern/BOP_Face.cpp
- intern/BOP_Face2Face.cpp
- intern/BOP_Interface.cpp
- intern/BOP_MathUtils.cpp
- intern/BOP_Merge.cpp
- intern/BOP_Merge2.cpp
- intern/BOP_Mesh.cpp
- intern/BOP_Segment.cpp
- intern/BOP_Splitter.cpp
- intern/BOP_Tag.cpp
- intern/BOP_Triangulator.cpp
- intern/BOP_Vertex.cpp
+if(NOT WITH_CARVE)
+ set(SRC
+ intern/BOP_BBox.cpp
+ intern/BOP_BSPNode.cpp
+ intern/BOP_BSPTree.cpp
+ intern/BOP_Edge.cpp
+ intern/BOP_Face.cpp
+ intern/BOP_Face2Face.cpp
+ intern/BOP_Interface.cpp
+ intern/BOP_MathUtils.cpp
+ intern/BOP_Merge.cpp
+ intern/BOP_Merge2.cpp
+ intern/BOP_Mesh.cpp
+ intern/BOP_Segment.cpp
+ intern/BOP_Splitter.cpp
+ intern/BOP_Tag.cpp
+ intern/BOP_Triangulator.cpp
+ intern/BOP_Vertex.cpp
- extern/BOP_Interface.h
- intern/BOP_BBox.h
- intern/BOP_BSPNode.h
- intern/BOP_BSPTree.h
- intern/BOP_Chrono.h
- intern/BOP_Edge.h
- intern/BOP_Face.h
- intern/BOP_Face2Face.h
- intern/BOP_Indexs.h
- intern/BOP_MathUtils.h
- intern/BOP_Merge.h
- intern/BOP_Merge2.h
- intern/BOP_Mesh.h
- intern/BOP_Misc.h
- intern/BOP_Segment.h
- intern/BOP_Splitter.h
- intern/BOP_Tag.h
- intern/BOP_Triangulator.h
- intern/BOP_Vertex.h
-)
+ extern/BOP_Interface.h
+ intern/BOP_BBox.h
+ intern/BOP_BSPNode.h
+ intern/BOP_BSPTree.h
+ intern/BOP_Chrono.h
+ intern/BOP_Edge.h
+ intern/BOP_Face.h
+ intern/BOP_Face2Face.h
+ intern/BOP_Indexs.h
+ intern/BOP_MathUtils.h
+ intern/BOP_Merge.h
+ intern/BOP_Merge2.h
+ intern/BOP_Mesh.h
+ intern/BOP_Misc.h
+ intern/BOP_Segment.h
+ intern/BOP_Splitter.h
+ intern/BOP_Tag.h
+ intern/BOP_Triangulator.h
+ intern/BOP_Vertex.h
+ )
+else()
+ set(SRC
+ intern/BOP_CarveInterface.cpp
+ extern/BOP_Interface.h
+ )
+
+ list(APPEND INC
+ ../../extern/carve/include
+ )
+
+ if(WITH_BOOST)
+ if(NOT MSVC)
+ # Boost is setting as preferred collections library in the Carve code when using MSVC compiler
+ add_definitions(
+ -DHAVE_BOOST_UNORDERED_COLLECTIONS
+ )
+ endif()
+
+ add_definitions(
+ -DCARVE_SYSTEM_BOOST
+ )
+
+ list(APPEND INC
+ ${BOOST_INCLUDE_DIR}
+ )
+ endif()
+endif()
blender_add_lib(bf_intern_bop "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/intern/boolop/SConscript b/intern/boolop/SConscript
index 5cf32862f96..0efed532cb9 100644
--- a/intern/boolop/SConscript
+++ b/intern/boolop/SConscript
@@ -1,14 +1,30 @@
#!/usr/bin/python
Import ('env')
-sources = env.Glob('intern/*.cpp')
-
incs = '. intern extern ../moto/include ../container ../memutil'
incs += ' ../../source/blender/makesdna ../../intern/guardedalloc'
incs += ' ../../source/blender/blenlib'
+defs = []
+
+if not env['WITH_BF_CARVE']:
+ sources = env.Glob('intern/*.cpp')
+ sources.remove('intern' + os.sep + 'BOP_CarveInterface.cpp')
+else:
+ sources = env.Glob('intern/BOP_CarveInterface.cpp')
+ incs += ' ../../extern/carve/include'
+
+ if env['WITH_BF_BOOST']:
+ if env['OURPLATFORM'] not in ('win32-vc', 'win64-vc'):
+ # Boost is setting as preferred collections library in the Carve code when using MSVC compiler
+ if env['OURPLATFORM'] != 'win32-mingw':
+ defs.append('HAVE_BOOST_UNORDERED_COLLECTIONS')
+
+ defs.append('CARVE_SYSTEM_BOOST')
+ incs += ' ' + env['BF_BOOST_INC']
+
if (env['OURPLATFORM'] == 'win32-mingw'):
env.BlenderLib ('bf_intern_bop', sources, Split(incs) , [], libtype='intern', priority = 5 )
else:
- env.BlenderLib ('bf_intern_bop', sources, Split(incs) , [], libtype='intern', priority = 5 )
+ env.BlenderLib ('bf_intern_bop', sources, Split(incs) , defs, libtype='intern', priority = 5 )
diff --git a/intern/boolop/intern/BOP_BSPNode.cpp b/intern/boolop/intern/BOP_BSPNode.cpp
index 178961510d5..7d9071b3132 100644
--- a/intern/boolop/intern/BOP_BSPNode.cpp
+++ b/intern/boolop/intern/BOP_BSPNode.cpp
@@ -35,7 +35,6 @@
#include "MT_assert.h"
#include "MT_MinMax.h"
#include <iostream>
-using namespace std;
/**
* Constructs a new BSP node.
@@ -707,13 +706,13 @@ int BOP_BSPNode::splitTriangle(MT_Point3* res,
*/
void BOP_BSPNode::print(unsigned int deep)
{
- cout << "(" << deep << "," << m_plane << ")," << endl;
+ std::cout << "(" << deep << "," << m_plane << ")," << std::endl;
if (m_inChild != NULL)
m_inChild->print(deep + 1);
else
- cout << "(" << deep+1 << ",None)," << endl;
+ std::cout << "(" << deep+1 << ",None)," << std::endl;
if (m_outChild != NULL)
m_outChild->print(deep + 1);
else
- cout << "(" << deep+1 << ",None)," << endl;
+ std::cout << "(" << deep+1 << ",None)," << std::endl;
}
diff --git a/intern/boolop/intern/BOP_BSPNode.h b/intern/boolop/intern/BOP_BSPNode.h
index 1a52f385ce7..9f924407b62 100644
--- a/intern/boolop/intern/BOP_BSPNode.h
+++ b/intern/boolop/intern/BOP_BSPNode.h
@@ -37,8 +37,8 @@
#include "BOP_Tag.h"
#include "BOP_Face.h"
-typedef vector<MT_Point3> BOP_BSPPoints;
-typedef vector<MT_Point3>::const_iterator BOP_IT_BSPPoints;
+typedef std::vector<MT_Point3> BOP_BSPPoints;
+typedef std::vector<MT_Point3>::const_iterator BOP_IT_BSPPoints;
class BOP_BSPNode
{
diff --git a/intern/boolop/intern/BOP_BSPTree.cpp b/intern/boolop/intern/BOP_BSPTree.cpp
index 0a8b3cc98fc..7a8ed417be4 100644
--- a/intern/boolop/intern/BOP_BSPTree.cpp
+++ b/intern/boolop/intern/BOP_BSPTree.cpp
@@ -33,7 +33,6 @@
#include "BOP_BSPTree.h"
#include <vector>
#include <iostream>
-using namespace std;
/**
* Constructs a new BSP tree.
diff --git a/intern/boolop/intern/BOP_CarveInterface.cpp b/intern/boolop/intern/BOP_CarveInterface.cpp
new file mode 100644
index 00000000000..4db4fdd819d
--- /dev/null
+++ b/intern/boolop/intern/BOP_CarveInterface.cpp
@@ -0,0 +1,403 @@
+/*
+ * ***** 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) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file boolop/intern/BOP_CarveInterface.cpp
+ * \ingroup boolopintern
+ */
+
+#include "../extern/BOP_Interface.h"
+#include "../../bsp/intern/BSP_CSGMesh_CFIterator.h"
+
+#include <carve/csg_triangulator.hpp>
+#include <carve/interpolator.hpp>
+#include <carve/rescale.hpp>
+
+typedef unsigned int uint;
+
+#define MAX(x,y) ((x)>(y)?(x):(y))
+#define MIN(x,y) ((x)<(y)?(x):(y))
+
+static int isFacePlanar(CSG_IFace &face, std::vector<carve::geom3d::Vector> &vertices)
+{
+ carve::geom3d::Vector v1, v2, v3, cross;
+
+ if (face.vertex_number == 4) {
+ v1 = vertices[face.vertex_index[1]] - vertices[face.vertex_index[0]];
+ v2 = vertices[face.vertex_index[3]] - vertices[face.vertex_index[0]];
+ v3 = vertices[face.vertex_index[2]] - vertices[face.vertex_index[0]];
+
+ cross = carve::geom::cross(v1, v2);
+
+ float production = carve::geom::dot(cross, v3);
+ float magnitude = 1e-6 * cross.length();
+
+ return fabs(production) < magnitude;
+ }
+
+ return 1;
+}
+
+static carve::mesh::MeshSet<3> *Carve_addMesh(CSG_FaceIteratorDescriptor& face_it,
+ CSG_VertexIteratorDescriptor& vertex_it,
+ carve::interpolate::FaceAttr<uint> &oface_num,
+ uint &num_origfaces )
+{
+ CSG_IVertex vertex;
+ std::vector<carve::geom3d::Vector> vertices;
+
+ while (!vertex_it.Done(vertex_it.it)) {
+ vertex_it.Fill(vertex_it.it,&vertex);
+ vertices.push_back(carve::geom::VECTOR(vertex.position[0],
+ vertex.position[1],
+ vertex.position[2]));
+ vertex_it.Step(vertex_it.it);
+ }
+
+ CSG_IFace face;
+ std::vector<int> f;
+ int numfaces = 0;
+
+ // now for the polygons.
+ // we may need to decalare some memory for user defined face properties.
+
+ std::vector<int> forig;
+ while (!face_it.Done(face_it.it)) {
+ face_it.Fill(face_it.it,&face);
+
+ if (isFacePlanar(face, vertices)) {
+ f.push_back(face.vertex_number);
+ f.push_back(face.vertex_index[0]);
+ f.push_back(face.vertex_index[1]);
+ f.push_back(face.vertex_index[2]);
+
+ if (face.vertex_number == 4)
+ f.push_back(face.vertex_index[3]);
+
+ forig.push_back(face.orig_face);
+ ++numfaces;
+ face_it.Step(face_it.it);
+ ++num_origfaces;
+ }
+ else {
+ f.push_back(3);
+ f.push_back(face.vertex_index[0]);
+ f.push_back(face.vertex_index[1]);
+ f.push_back(face.vertex_index[2]);
+
+ forig.push_back(face.orig_face);
+ ++numfaces;
+
+ if (face.vertex_number == 4) {
+ f.push_back(3);
+ f.push_back(face.vertex_index[0]);
+ f.push_back(face.vertex_index[2]);
+ f.push_back(face.vertex_index[3]);
+
+ forig.push_back(face.orig_face);
+ ++numfaces;
+ }
+
+ face_it.Step(face_it.it);
+ ++num_origfaces;
+ }
+ }
+
+ carve::mesh::MeshSet<3> *poly = new carve::mesh::MeshSet<3> (vertices, numfaces, f);
+
+ uint i;
+ carve::mesh::MeshSet<3>::face_iter face_iter = poly->faceBegin();
+ for (i = 0; face_iter != poly->faceEnd(); ++face_iter, ++i) {
+ carve::mesh::MeshSet<3>::face_t *face = *face_iter;
+ oface_num.setAttribute(face, forig[i]);
+ }
+
+ return poly;
+}
+
+// check whether two faces share an edge, and if so merge them
+static uint quadMerge(std::map<carve::mesh::MeshSet<3>::vertex_t*, uint> *vertexToIndex_map,
+ carve::mesh::MeshSet<3>::face_t *f1, carve::mesh::MeshSet<3>::face_t *f2,
+ uint v, uint quad[4])
+{
+ uint current, n1, p1, n2, p2;
+ uint v1[3];
+ uint v2[3];
+
+ // get the vertex indices for each face
+ v1[0] = vertexToIndex_map->find(f1->edge->vert)->second;
+ v1[1] = vertexToIndex_map->find(f1->edge->next->vert)->second;
+ v1[2] = vertexToIndex_map->find(f1->edge->next->next->vert)->second;
+
+ v2[0] = vertexToIndex_map->find(f2->edge->vert)->second;
+ v2[1] = vertexToIndex_map->find(f2->edge->next->vert)->second;
+ v2[2] = vertexToIndex_map->find(f2->edge->next->next->vert)->second;
+
+ // locate the current vertex we're examining, and find the next and
+ // previous vertices based on the face windings
+ if (v1[0] == v) {current = 0; p1 = 2; n1 = 1;}
+ else if (v1[1] == v) {current = 1; p1 = 0; n1 = 2;}
+ else {current = 2; p1 = 1; n1 = 0;}
+
+ if (v2[0] == v) {p2 = 2; n2 = 1;}
+ else if (v2[1] == v) {p2 = 0; n2 = 2;}
+ else {p2 = 1; n2 = 0;}
+
+ // if we find a match, place indices into quad in proper order and return
+ // success code
+ if (v1[p1] == v2[n2]) {
+ quad[0] = v1[current];
+ quad[1] = v1[n1];
+ quad[2] = v1[p1];
+ quad[3] = v2[p2];
+
+ return 1;
+ }
+ else if (v1[n1] == v2[p2]) {
+ quad[0] = v1[current];
+ quad[1] = v2[n2];
+ quad[2] = v1[n1];
+ quad[3] = v1[p1];
+
+ return 1;
+ }
+
+ return 0;
+}
+
+static BSP_CSGMesh* Carve_exportMesh(carve::mesh::MeshSet<3>* &poly, carve::interpolate::FaceAttr<uint> &oface_num,
+ uint num_origfaces)
+{
+ uint i;
+ BSP_CSGMesh* outputMesh = BSP_CSGMesh::New();
+
+ if (outputMesh == NULL)
+ return NULL;
+
+ std::vector<BSP_MVertex>* vertices = new std::vector<BSP_MVertex>;
+
+ outputMesh->SetVertices(vertices);
+
+ std::map<carve::mesh::MeshSet<3>::vertex_t*, uint> vertexToIndex_map;
+ std::vector<carve::mesh::MeshSet<3>::vertex_t>::iterator it = poly->vertex_storage.begin();
+ for (i = 0; it != poly->vertex_storage.end(); ++i, ++it) {
+ carve::mesh::MeshSet<3>::vertex_t *vertex = &(*it);
+ vertexToIndex_map[vertex] = i;
+ }
+
+ for (i = 0; i < poly->vertex_storage.size(); ++i ) {
+ BSP_MVertex outVtx(MT_Point3 (poly->vertex_storage[i].v[0],
+ poly->vertex_storage[i].v[1],
+ poly->vertex_storage[i].v[2]));
+ outVtx.m_edges.clear();
+ outputMesh->VertexSet().push_back(outVtx);
+ }
+
+ // build vectors of faces for each original face and each vertex
+ std::vector< std::vector<uint> > vi(poly->vertex_storage.size());
+ std::vector< std::vector<uint> > ofaces(num_origfaces);
+ carve::mesh::MeshSet<3>::face_iter face_iter = poly->faceBegin();
+ for (i = 0; face_iter != poly->faceEnd(); ++face_iter, ++i) {
+ carve::mesh::MeshSet<3>::face_t *f = *face_iter;
+ ofaces[oface_num.getAttribute(f)].push_back(i);
+ carve::mesh::MeshSet<3>::face_t::edge_iter_t edge_iter = f->begin();
+ for (; edge_iter != f->end(); ++edge_iter) {
+ int index = vertexToIndex_map[edge_iter->vert];
+ vi[index].push_back(i);
+ }
+ }
+
+ uint quadverts[4] = {0, 0, 0, 0};
+ // go over each set of faces which belong to an original face
+ std::vector< std::vector<uint> >::const_iterator fii;
+ uint orig = 0;
+ for (fii=ofaces.begin(); fii!=ofaces.end(); ++fii, ++orig) {
+ std::vector<uint> fl = *fii;
+ // go over a single set from an original face
+ while (fl.size() > 0) {
+ // remove one new face
+ uint findex = fl.back();
+ fl.pop_back();
+
+ carve::mesh::MeshSet<3>::face_t *f = *(poly->faceBegin() + findex);
+
+ // add all information except vertices to the output mesh
+ outputMesh->FaceSet().push_back(BSP_MFace());
+ BSP_MFace& outFace = outputMesh->FaceSet().back();
+ outFace.m_verts.clear();
+ outFace.m_plane.setValue(f->plane.N.v);
+ outFace.m_orig_face = orig;
+
+ // for each vertex of this face, check other faces containing
+ // that vertex to see if there is a neighbor also belonging to
+ // the original face
+ uint result = 0;
+
+ carve::mesh::MeshSet<3>::face_t::edge_iter_t edge_iter = f->begin();
+ for (; edge_iter != f->end(); ++edge_iter) {
+ int v = vertexToIndex_map[edge_iter->vert];
+ for (uint pos2=0; !result && pos2 < vi[v].size();pos2++) {
+
+ // if we find the current face, ignore it
+ uint otherf = vi[v][pos2];
+ if (findex == otherf)
+ continue;
+
+ carve::mesh::MeshSet<3>::face_t *f2 = *(poly->faceBegin() + otherf);
+
+ // if other face doesn't have the same original face,
+ // ignore it also
+ uint other_orig = oface_num.getAttribute(f2);
+ if (orig != other_orig)
+ continue;
+
+ // if, for some reason, we don't find the other face in
+ // the current set of faces, ignore it
+ uint other_index = 0;
+ while (other_index < fl.size() && fl[other_index] != otherf) ++other_index;
+ if (other_index == fl.size()) continue;
+
+ // see if the faces share an edge
+ result = quadMerge(&vertexToIndex_map, f, f2, v, quadverts);
+ // if faces can be merged, then remove the other face
+ // from the current set
+ if (result) {
+ uint replace = fl.back();
+ fl.pop_back();
+ if(otherf != replace)
+ fl[other_index] = replace;
+ }
+ }
+ }
+
+ // if we merged faces, use the list of common vertices; otherwise
+ // use the faces's vertices
+ if (result) {
+ // make quat using verts stored in result
+ outFace.m_verts.push_back(quadverts[0]);
+ outFace.m_verts.push_back(quadverts[1]);
+ outFace.m_verts.push_back(quadverts[2]);
+ outFace.m_verts.push_back(quadverts[3]);
+ } else {
+ carve::mesh::MeshSet<3>::face_t::edge_iter_t edge_iter = f->begin();
+ for (; edge_iter != f->end(); ++edge_iter) {
+ //int index = ofacevert_num.getAttribute(f, edge_iter.idx());
+ int index = vertexToIndex_map[edge_iter->vert];
+ outFace.m_verts.push_back( index );
+ }
+ }
+ }
+ }
+
+ // Build the mesh edges using topological informtion
+ outputMesh->BuildEdges();
+
+ return outputMesh;
+}
+
+/**
+ * Performs a generic booleam operation, the entry point for external modules.
+ * @param opType Boolean operation type BOP_INTERSECTION, BOP_UNION, BOP_DIFFERENCE
+ * @param outputMesh Output mesh, the final result (the object C)
+ * @param obAFaces Object A faces list
+ * @param obAVertices Object A vertices list
+ * @param obBFaces Object B faces list
+ * @param obBVertices Object B vertices list
+ * @param interpFunc Interpolating function
+ * @return operation state: BOP_OK, BOP_NO_SOLID, BOP_ERROR
+ */
+BoolOpState BOP_performBooleanOperation(BoolOpType opType,
+ BSP_CSGMesh** outputMesh,
+ CSG_FaceIteratorDescriptor obAFaces,
+ CSG_VertexIteratorDescriptor obAVertices,
+ CSG_FaceIteratorDescriptor obBFaces,
+ CSG_VertexIteratorDescriptor obBVertices)
+{
+ carve::csg::CSG::OP op;
+ carve::mesh::MeshSet<3> *left, *right, *output;
+ carve::csg::CSG csg;
+ carve::geom3d::Vector min, max;
+ carve::interpolate::FaceAttr<uint> oface_num;
+ uint num_origfaces = 0;
+
+ switch (opType) {
+ case BOP_UNION:
+ op = carve::csg::CSG::UNION;
+ break;
+ case BOP_INTERSECTION:
+ op = carve::csg::CSG::INTERSECTION;
+ break;
+ case BOP_DIFFERENCE:
+ op = carve::csg::CSG::A_MINUS_B;
+ break;
+ default:
+ return BOP_ERROR;
+ }
+
+ left = Carve_addMesh(obAFaces, obAVertices, oface_num, num_origfaces );
+ right = Carve_addMesh(obBFaces, obBVertices, oface_num, num_origfaces );
+
+ min.x = max.x = left->vertex_storage[0].v.x;
+ min.y = max.y = left->vertex_storage[0].v.y;
+ min.z = max.z = left->vertex_storage[0].v.z;
+ for (uint i = 1; i < left->vertex_storage.size(); ++i) {
+ min.x = MIN(min.x,left->vertex_storage[i].v.x);
+ min.y = MIN(min.y,left->vertex_storage[i].v.y);
+ min.z = MIN(min.z,left->vertex_storage[i].v.z);
+ max.x = MAX(max.x,left->vertex_storage[i].v.x);
+ max.y = MAX(max.y,left->vertex_storage[i].v.y);
+ max.z = MAX(max.z,left->vertex_storage[i].v.z);
+ }
+ for (uint i = 0; i < right->vertex_storage.size(); ++i) {
+ min.x = MIN(min.x,right->vertex_storage[i].v.x);
+ min.y = MIN(min.y,right->vertex_storage[i].v.y);
+ min.z = MIN(min.z,right->vertex_storage[i].v.z);
+ max.x = MAX(max.x,right->vertex_storage[i].v.x);
+ max.y = MAX(max.y,right->vertex_storage[i].v.y);
+ max.z = MAX(max.z,right->vertex_storage[i].v.z);
+ }
+
+ carve::rescale::rescale scaler(min.x, min.y, min.z, max.x, max.y, max.z);
+ carve::rescale::fwd fwd_r(scaler);
+ carve::rescale::rev rev_r(scaler);
+
+ left->transform(fwd_r);
+ right->transform(fwd_r);
+
+ csg.hooks.registerHook(new carve::csg::CarveTriangulator, carve::csg::CSG::Hooks::PROCESS_OUTPUT_FACE_BIT);
+
+ oface_num.installHooks(csg);
+ output = csg.compute( left, right, op, NULL, carve::csg::CSG::CLASSIFY_EDGE);
+ delete left;
+ delete right;
+
+ output->transform(rev_r);
+
+ *outputMesh = Carve_exportMesh( output, oface_num, num_origfaces);
+ delete output;
+
+ return BOP_OK;
+}
diff --git a/intern/boolop/intern/BOP_Edge.cpp b/intern/boolop/intern/BOP_Edge.cpp
index c53dde35d33..fc03dd897d3 100644
--- a/intern/boolop/intern/BOP_Edge.cpp
+++ b/intern/boolop/intern/BOP_Edge.cpp
@@ -105,7 +105,6 @@ bool BOP_Edge::removeFace(BOP_Index i)
#ifdef BOP_DEBUG
#include <iostream>
-using namespace std;
/**
* Implements operator <<.
diff --git a/intern/boolop/intern/BOP_Face.h b/intern/boolop/intern/BOP_Face.h
index 7aaee2bd045..6f79b8b17c0 100644
--- a/intern/boolop/intern/BOP_Face.h
+++ b/intern/boolop/intern/BOP_Face.h
@@ -40,12 +40,11 @@
#include "BOP_Misc.h"
#include <iostream>
#include <vector>
-using namespace std;
class BOP_Face;
-typedef vector<BOP_Face *> BOP_Faces;
-typedef vector<BOP_Face *>::iterator BOP_IT_Faces;
+typedef std::vector<BOP_Face *> BOP_Faces;
+typedef std::vector<BOP_Face *>::iterator BOP_IT_Faces;
class BOP_Face
{
diff --git a/intern/boolop/intern/BOP_Indexs.h b/intern/boolop/intern/BOP_Indexs.h
index 74c2025e74a..4e71c66d4a4 100644
--- a/intern/boolop/intern/BOP_Indexs.h
+++ b/intern/boolop/intern/BOP_Indexs.h
@@ -34,10 +34,9 @@
#define BOP_Indexs_H
#include <vector>
-using namespace std;
typedef unsigned int BOP_Index;
-typedef vector<BOP_Index> BOP_Indexs;
-typedef vector<BOP_Index>::iterator BOP_IT_Indexs;
+typedef std::vector<BOP_Index> BOP_Indexs;
+typedef std::vector<BOP_Index>::iterator BOP_IT_Indexs;
#endif
diff --git a/intern/boolop/intern/BOP_Interface.cpp b/intern/boolop/intern/BOP_Interface.cpp
index f11c4eaffae..b18a4334263 100644
--- a/intern/boolop/intern/BOP_Interface.cpp
+++ b/intern/boolop/intern/BOP_Interface.cpp
@@ -86,7 +86,7 @@ BoolOpState BOP_performBooleanOperation(BoolOpType opType,
CSG_VertexIteratorDescriptor obBVertices)
{
#ifdef BOP_DEBUG
- cout << "BEGIN BOP_performBooleanOperation" << endl;
+ std::cout << "BEGIN BOP_performBooleanOperation" << std::endl;
#endif
// Set invert flags depending on boolean operation type:
@@ -124,7 +124,7 @@ BoolOpState BOP_performBooleanOperation(BoolOpType opType,
*outputMesh = BOP_exportMesh(&meshC, invertMeshC);
#ifdef BOP_DEBUG
- cout << "END BOP_performBooleanOperation" << endl;
+ std::cout << "END BOP_performBooleanOperation" << std::endl;
#endif
return result;
@@ -151,7 +151,7 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
float t = 0.0f;
float c = 0.0f;
chrono.start();
- cout << "---" << endl;
+ std::cout << "---" << std::endl;
#endif
// Create BSPs trees for mesh A & B
@@ -163,7 +163,7 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
#ifdef BOP_DEBUG
c = chrono.stamp(); t += c;
- cout << "Create BSP " << c << endl;
+ std::cout << "Create BSP " << c << std::endl;
#endif
unsigned int numVertices = meshC->getNumVertexs();
@@ -179,7 +179,7 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
#ifdef BOP_DEBUG
c = chrono.stamp(); t += c;
- cout << "mesh Filter " << c << endl;
+ std::cout << "mesh Filter " << c << std::endl;
#endif
// Face 2 Face
@@ -187,7 +187,7 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
#ifdef BOP_DEBUG
c = chrono.stamp(); t += c;
- cout << "Face2Face " << c << endl;
+ std::cout << "Face2Face " << c << std::endl;
#endif
// BSP classification
@@ -196,7 +196,7 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
#ifdef BOP_DEBUG
c = chrono.stamp(); t += c;
- cout << "Classification " << c << endl;
+ std::cout << "Classification " << c << std::endl;
#endif
// Process overlapped faces
@@ -204,7 +204,7 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
#ifdef BOP_DEBUG
c = chrono.stamp(); t += c;
- cout << "Remove overlap " << c << endl;
+ std::cout << "Remove overlap " << c << std::endl;
#endif
// Sew two meshes
@@ -212,7 +212,7 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
#ifdef BOP_DEBUG
c = chrono.stamp(); t += c;
- cout << "Sew " << c << endl;
+ std::cout << "Sew " << c << std::endl;
#endif
// Merge faces
@@ -229,13 +229,13 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
static int state = -1;
if (G.rt == 100) {
if( state != 1 ) {
- cout << "Boolean code using old merge technique." << endl;
+ std::cout << "Boolean code using old merge technique." << std::endl;
state = 1;
}
BOP_Merge::getInstance().mergeFaces(meshC,numVertices);
} else {
if( state != 0 ) {
- cout << "Boolean code using new merge technique." << endl;
+ std::cout << "Boolean code using new merge technique." << std::endl;
state = 0;
}
BOP_Merge2::getInstance().mergeFaces(meshC,numVertices);
@@ -245,8 +245,8 @@ BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC,
#ifdef BOP_DEBUG
c = chrono.stamp(); t += c;
- cout << "Merge faces " << c << endl;
- cout << "Total " << t << endl;
+ std::cout << "Merge faces " << c << std::endl;
+ std::cout << "Total " << t << std::endl;
// Test integrity
meshC->testMesh();
#endif
@@ -460,7 +460,7 @@ BSP_CSGMesh* BOP_newEmptyMesh()
BSP_CSGMesh* mesh = BSP_CSGMesh::New();
if (mesh == NULL) return mesh;
- vector<BSP_MVertex>* vertices = new vector<BSP_MVertex>;
+ std::vector<BSP_MVertex>* vertices = new std::vector<BSP_MVertex>;
mesh->SetVertices(vertices);
@@ -481,8 +481,8 @@ BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* mesh,
if (outputMesh == NULL) return NULL;
// vtx index dictionary, to translate indeces from input to output.
- map<int,unsigned int> dic;
- map<int,unsigned int>::iterator itDic;
+ std::map<int,unsigned int> dic;
+ std::map<int,unsigned int>::iterator itDic;
unsigned int count = 0;
diff --git a/intern/boolop/intern/BOP_MathUtils.cpp b/intern/boolop/intern/BOP_MathUtils.cpp
index aa9083d17b6..bcc0cca194e 100644
--- a/intern/boolop/intern/BOP_MathUtils.cpp
+++ b/intern/boolop/intern/BOP_MathUtils.cpp
@@ -34,7 +34,6 @@
#include "BOP_MathUtils.h"
#include <iostream>
-using namespace std;
/**
* Compares two scalars with EPSILON accuracy.
diff --git a/intern/boolop/intern/BOP_Merge.h b/intern/boolop/intern/BOP_Merge.h
index 64be7b18cb8..5a24579e7b5 100644
--- a/intern/boolop/intern/BOP_Merge.h
+++ b/intern/boolop/intern/BOP_Merge.h
@@ -41,8 +41,8 @@
#include "BOP_MathUtils.h"
#include "MEM_SmartPtr.h"
-typedef vector< BOP_Faces > BOP_LFaces;
-typedef vector< BOP_Faces >::iterator BOP_IT_LFaces;
+typedef std::vector< BOP_Faces > BOP_LFaces;
+typedef std::vector< BOP_Faces >::iterator BOP_IT_LFaces;
class BOP_Merge {
private:
diff --git a/intern/boolop/intern/BOP_Merge2.h b/intern/boolop/intern/BOP_Merge2.h
index 2b79fd95ce6..78a4caff7d9 100644
--- a/intern/boolop/intern/BOP_Merge2.h
+++ b/intern/boolop/intern/BOP_Merge2.h
@@ -42,8 +42,8 @@
#include "BOP_MathUtils.h"
#include "MEM_SmartPtr.h"
-typedef vector< BOP_Faces > BOP_LFaces;
-typedef vector< BOP_Faces >::iterator BOP_IT_LFaces;
+typedef std::vector< BOP_Faces > BOP_LFaces;
+typedef std::vector< BOP_Faces >::iterator BOP_IT_LFaces;
class BOP_Merge2 {
private:
diff --git a/intern/boolop/intern/BOP_Mesh.h b/intern/boolop/intern/BOP_Mesh.h
index 8550333664f..271e97fe454 100644
--- a/intern/boolop/intern/BOP_Mesh.h
+++ b/intern/boolop/intern/BOP_Mesh.h
@@ -40,10 +40,10 @@
#include "BOP_Face.h"
#include "DNA_listBase.h"
-typedef vector<BOP_Vertex *> BOP_Vertexs;
-typedef vector<BOP_Edge *> BOP_Edges;
-typedef vector<BOP_Vertex *>::iterator BOP_IT_Vertexs;
-typedef vector<BOP_Edge *>::iterator BOP_IT_Edges;
+typedef std::vector<BOP_Vertex *> BOP_Vertexs;
+typedef std::vector<BOP_Edge *> BOP_Edges;
+typedef std::vector<BOP_Vertex *>::iterator BOP_IT_Vertexs;
+typedef std::vector<BOP_Edge *>::iterator BOP_IT_Edges;
#ifdef HASH
typedef struct EdgeEntry {
diff --git a/intern/boolop/intern/BOP_Segment.cpp b/intern/boolop/intern/BOP_Segment.cpp
index a9c0d30da1c..79e04380015 100644
--- a/intern/boolop/intern/BOP_Segment.cpp
+++ b/intern/boolop/intern/BOP_Segment.cpp
@@ -242,8 +242,8 @@ unsigned int BOP_Segment::getConfig()
/**
* Implements operator <<
*/
-ostream &operator<<(ostream &stream, const BOP_Segment &c)
+std::ostream &operator<<(std::ostream &stream, const BOP_Segment &c)
{
- cout << "m_v1: " << c.m_v1 << "(" << c.m_cfg1 << ") m_v2: " << c.m_v2 << "(" << c.m_cfg2 << ")";
+ std::cout << "m_v1: " << c.m_v1 << "(" << c.m_cfg1 << ") m_v2: " << c.m_v2 << "(" << c.m_cfg2 << ")";
return stream;
}
diff --git a/intern/boolop/intern/BOP_Segment.h b/intern/boolop/intern/BOP_Segment.h
index 44ea069dc8c..4a2b4509846 100644
--- a/intern/boolop/intern/BOP_Segment.h
+++ b/intern/boolop/intern/BOP_Segment.h
@@ -35,7 +35,6 @@
#include "BOP_Indexs.h"
#include <iostream>
-using namespace std;
class BOP_Segment
{
@@ -69,7 +68,7 @@ public:
void sort();
unsigned int getConfig();
- friend ostream &operator<<(ostream &stream, const BOP_Segment &c);
+ friend std::ostream &operator<<(std::ostream &stream, const BOP_Segment &c);
};
#endif
diff --git a/intern/boolop/intern/BOP_Splitter.cpp b/intern/boolop/intern/BOP_Splitter.cpp
index 26b111ff552..0839b6af30b 100644
--- a/intern/boolop/intern/BOP_Splitter.cpp
+++ b/intern/boolop/intern/BOP_Splitter.cpp
@@ -34,7 +34,6 @@
#include "BOP_Tag.h"
#include <iostream>
-using namespace std;
/**
* Returns the split point resulting from intersect a plane and a mesh face
diff --git a/intern/boolop/intern/BOP_Triangulator.cpp b/intern/boolop/intern/BOP_Triangulator.cpp
index 8f94eb1f7b7..ca1e3ad2b6b 100644
--- a/intern/boolop/intern/BOP_Triangulator.cpp
+++ b/intern/boolop/intern/BOP_Triangulator.cpp
@@ -32,7 +32,6 @@
#include "BOP_Triangulator.h"
#include <iostream>
-using namespace std;
void BOP_addFace(BOP_Mesh* mesh, BOP_Faces *faces, BOP_Face* face, BOP_TAG tag);
void BOP_splitQuad(BOP_Mesh* mesh, MT_Plane3 plane, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4,
diff --git a/intern/cycles/blender/addon/enums.py b/intern/cycles/blender/addon/enums.py
index da4c73a5d3b..e1b138def3c 100644
--- a/intern/cycles/blender/addon/enums.py
+++ b/intern/cycles/blender/addon/enums.py
@@ -21,8 +21,8 @@
from . import engine
devices = (
- ("CPU", "CPU", "Use CPU for rendering"),
- ("GPU", "GPU Compute", "Use GPU compute device for rendering, configured in user preferences"))
+ ("CPU", "CPU", "Use CPU for rendering"),
+ ("GPU", "GPU Compute", "Use GPU compute device for rendering, configured in user preferences"))
feature_set = (
("SUPPORTED", "Supported", "Only use finished and supported features"),
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 0b096c529b8..7e7e83b4f69 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -33,76 +33,189 @@ from . import enums
class CyclesRenderSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
- bpy.types.Scene.cycles = PointerProperty(type=cls, name="Cycles Render Settings", description="Cycles render settings")
-
- cls.device = EnumProperty(name="Device", description="Device to use for rendering",
- items=enums.devices, default="CPU")
-
- cls.feature_set = EnumProperty(name="Feature Set", description="Feature set to use for rendering",
- items=enums.feature_set, default="SUPPORTED")
-
- cls.shading_system = EnumProperty(name="Shading System", description="Shading system to use for rendering",
- items=enums.shading_systems, default="GPU_COMPATIBLE")
-
- cls.samples = IntProperty(name="Samples", description="Number of samples to render for each pixel",
- default=10, min=1, max=2147483647)
- cls.preview_samples = IntProperty(name="Preview Samples", description="Number of samples to render in the viewport, unlimited if 0",
- default=10, min=0, max=2147483647)
- cls.preview_pause = BoolProperty(name="Pause Preview", description="Pause all viewport preview renders",
- default=False)
-
- cls.no_caustics = BoolProperty(name="No Caustics", description="Leave out caustics, resulting in a darker image with less noise",
- default=False)
- cls.blur_caustics = FloatProperty(name="Blur Caustics", description="Blur caustics to reduce noise",
- default=0.0, min=0.0, max=1.0)
-
- cls.min_bounces = IntProperty(name="Min Bounces", description="Minimum number of bounces, setting this lower than the maximum enables probalistic path termination (faster but noisier)",
- default=3, min=0, max=1024)
- cls.max_bounces = IntProperty(name="Max Bounces", description="Total maximum number of bounces",
- default=8, min=0, max=1024)
-
- cls.diffuse_bounces = IntProperty(name="Diffuse Bounces", description="Maximum number of diffuse reflection bounces, bounded by total maximum",
- default=128, min=0, max=1024)
- cls.glossy_bounces = IntProperty(name="Glossy Bounces", description="Maximum number of glossy reflection bounces, bounded by total maximum",
- default=128, min=0, max=1024)
- cls.transmission_bounces = IntProperty(name="Transmission Bounces", description="Maximum number of transmission bounces, bounded by total maximum",
- default=128, min=0, max=1024)
-
- cls.transparent_min_bounces = IntProperty(name="Transparent Min Bounces", description="Minimum number of transparent bounces, setting this lower than the maximum enables probalistic path termination (faster but noisier)",
- default=8, min=0, max=1024)
- cls.transparent_max_bounces = IntProperty(name="Transparent Max Bounces", description="Maximum number of transparent bounces",
- default=8, min=0, max=1024)
- cls.use_transparent_shadows = BoolProperty(name="Transparent Shadows", description="Use transparency of surfaces for rendering shadows",
- default=True)
-
- cls.film_exposure = FloatProperty(name="Exposure", description="Image brightness scale",
- default=1.0, min=0.0, max=10.0)
- cls.film_transparent = BoolProperty(name="Transparent", description="World background is transparent",
- default=False)
-
- cls.filter_type = EnumProperty(name="Filter Type", description="Pixel filter type",
- items=enums.filter_types, default="GAUSSIAN")
- cls.filter_width = FloatProperty(name="Filter Width", description="Pixel filter width",
- default=1.5, min=0.01, max=10.0)
-
- cls.seed = IntProperty(name="Seed", description="Seed value for integrator to get different noise patterns",
- default=0, min=0, max=2147483647)
-
- cls.debug_tile_size = IntProperty(name="Tile Size", description="",
- default=1024, min=1, max=4096)
- cls.debug_min_size = IntProperty(name="Min Size", description="",
- default=64, min=1, max=4096)
- cls.debug_reset_timeout = FloatProperty(name="Reset timeout", description="",
- default=0.1, min=0.01, max=10.0)
- cls.debug_cancel_timeout = FloatProperty(name="Cancel timeout", description="",
- default=0.1, min=0.01, max=10.0)
- cls.debug_text_timeout = FloatProperty(name="Text timeout", description="",
- default=1.0, min=0.01, max=10.0)
-
- cls.debug_bvh_type = EnumProperty(name="Viewport BVH Type", description="Choose between faster updates, or faster render",
- items=enums.bvh_types, default="DYNAMIC_BVH")
- cls.debug_use_spatial_splits = BoolProperty(name="Use Spatial Splits", description="Use BVH spatial splits: longer builder time, faster render",
- default=False)
+ bpy.types.Scene.cycles = PointerProperty(
+ name="Cycles Render Settings",
+ description="Cycles render settings",
+ type=cls,
+ )
+ cls.device = EnumProperty(
+ name="Device",
+ description="Device to use for rendering",
+ items=enums.devices,
+ default='CPU',
+ )
+ cls.feature_set = EnumProperty(
+ name="Feature Set",
+ description="Feature set to use for rendering",
+ items=enums.feature_set,
+ default='SUPPORTED',
+ )
+ cls.shading_system = EnumProperty(
+ name="Shading System",
+ description="Shading system to use for rendering",
+ items=enums.shading_systems,
+ default='GPU_COMPATIBLE',
+ )
+
+ cls.samples = IntProperty(
+ name="Samples",
+ description="Number of samples to render for each pixel",
+ min=1, max=2147483647,
+ default=10,
+ )
+ cls.preview_samples = IntProperty(
+ name="Preview Samples",
+ description="Number of samples to render in the viewport, unlimited if 0",
+ min=0, max=2147483647,
+ default=10,
+ )
+ cls.preview_pause = BoolProperty(
+ name="Pause Preview",
+ description="Pause all viewport preview renders",
+ default=False,
+ )
+
+ cls.no_caustics = BoolProperty(
+ name="No Caustics",
+ description="Leave out caustics, resulting in a darker image with less noise",
+ default=False,
+ )
+ cls.blur_caustics = FloatProperty(
+ name="Blur Caustics",
+ description="Blur caustics to reduce noise",
+ min=0.0, max=1.0,
+ default=0.0,
+ )
+
+ cls.min_bounces = IntProperty(
+ name="Min Bounces",
+ description="Minimum number of bounces, setting this lower than the maximum enables probalistic path termination (faster but noisier)",
+ min=0, max=1024,
+ default=3,
+ )
+ cls.max_bounces = IntProperty(
+ name="Max Bounces",
+ description="Total maximum number of bounces",
+ min=0, max=1024,
+ default=8,
+ )
+
+ cls.diffuse_bounces = IntProperty(
+ name="Diffuse Bounces",
+ description="Maximum number of diffuse reflection bounces, bounded by total maximum",
+ min=0, max=1024,
+ default=128,
+ )
+ cls.glossy_bounces = IntProperty(
+ name="Glossy Bounces",
+ description="Maximum number of glossy reflection bounces, bounded by total maximum",
+ min=0, max=1024,
+ default=128,
+ )
+ cls.transmission_bounces = IntProperty(
+ name="Transmission Bounces",
+ description="Maximum number of transmission bounces, bounded by total maximum",
+ min=0, max=1024,
+ default=128,
+ )
+
+ cls.transparent_min_bounces = IntProperty(
+ name="Transparent Min Bounces",
+ description="Minimum number of transparent bounces, setting this lower than the maximum enables probalistic path termination (faster but noisier)",
+ min=0, max=1024,
+ default=8,
+ )
+ cls.transparent_max_bounces = IntProperty(
+ name="Transparent Max Bounces",
+ description="Maximum number of transparent bounces",
+ min=0, max=1024,
+ default=8,
+ )
+ cls.use_transparent_shadows = BoolProperty(
+ name="Transparent Shadows",
+ description="Use transparency of surfaces for rendering shadows",
+ default=True,
+ )
+
+ cls.film_exposure = FloatProperty(
+ name="Exposure",
+ description="Image brightness scale",
+ min=0.0, max=10.0,
+ default=1.0,
+ )
+ cls.film_transparent = BoolProperty(
+ name="Transparent",
+ description="World background is transparent",
+ default=False,
+ )
+
+ cls.filter_type = EnumProperty(
+ name="Filter Type",
+ description="Pixel filter type",
+ items=enums.filter_types,
+ default='GAUSSIAN',
+ )
+ cls.filter_width = FloatProperty(
+ name="Filter Width",
+ description="Pixel filter width",
+ min=0.01, max=10.0,
+ default=1.5,
+ )
+
+ cls.seed = IntProperty(
+ name="Seed",
+ description="Seed value for integrator to get different noise patterns",
+ min=0, max=2147483647,
+ default=0,
+ )
+
+ cls.debug_tile_size = IntProperty(
+ name="Tile Size",
+ description="",
+ min=1, max=4096,
+ default=1024,
+ )
+ cls.debug_min_size = IntProperty(
+ name="Min Size",
+ description="",
+ min=1, max=4096,
+ default=64,
+ )
+ cls.debug_reset_timeout = FloatProperty(
+ name="Reset timeout",
+ description="",
+ min=0.01, max=10.0,
+ default=0.1,
+ )
+ cls.debug_cancel_timeout = FloatProperty(
+ name="Cancel timeout",
+ description="",
+ min=0.01, max=10.0,
+ default=0.1,
+ )
+ cls.debug_text_timeout = FloatProperty(
+ name="Text timeout",
+ description="",
+ min=0.01, max=10.0,
+ default=1.0,
+ )
+
+ cls.debug_bvh_type = EnumProperty(
+ name="Viewport BVH Type",
+ description="Choose between faster updates, or faster render",
+ items=enums.bvh_types,
+ default='DYNAMIC_BVH',
+ )
+ cls.debug_use_spatial_splits = BoolProperty(
+ name="Use Spatial Splits",
+ description="Use BVH spatial splits: longer builder time, faster render",
+ default=False,
+ )
+ cls.use_cache = BoolProperty(
+ name="Cache BVH",
+ description="Cache last built BVH to disk for faster re-render if no geometry changed",
+ default=False,
+ )
@classmethod
def unregister(cls):
@@ -112,14 +225,31 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
class CyclesCameraSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
- bpy.types.Camera.cycles = PointerProperty(type=cls, name="Cycles Camera Settings", description="Cycles camera settings")
-
- cls.aperture_size = FloatProperty(name="Aperture Size", description="Radius of the aperture for depth of field",
- default=0.0, min=0.0, max=10.0)
- cls.aperture_blades = IntProperty(name="Aperture Blades", description="Number of blades in aperture for polygonal bokeh (at least 3)",
- default=0, min=0, max=100)
- cls.aperture_rotation = FloatProperty(name="Aperture Rotation", description="Rotation of blades in aperture",
- default=0, soft_min=-math.pi, soft_max=math.pi, subtype='ANGLE')
+ bpy.types.Camera.cycles = PointerProperty(
+ name="Cycles Camera Settings",
+ description="Cycles camera settings",
+ type=cls,
+ )
+
+ cls.aperture_size = FloatProperty(
+ name="Aperture Size",
+ description="Radius of the aperture for depth of field",
+ min=0.0, max=10.0,
+ default=0.0,
+ )
+ cls.aperture_blades = IntProperty(
+ name="Aperture Blades",
+ description="Number of blades in aperture for polygonal bokeh (at least 3)",
+ min=0, max=100,
+ default=0,
+ )
+ cls.aperture_rotation = FloatProperty(
+ name="Aperture Rotation",
+ description="Rotation of blades in aperture",
+ soft_min=-math.pi, soft_max=math.pi,
+ subtype='ANGLE',
+ default=0,
+ )
@classmethod
def unregister(cls):
@@ -129,9 +259,21 @@ class CyclesCameraSettings(bpy.types.PropertyGroup):
class CyclesMaterialSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
- bpy.types.Material.cycles = PointerProperty(type=cls, name="Cycles Material Settings", description="Cycles material settings")
- cls.sample_as_light = BoolProperty(name="Sample as Lamp", description="Use direct light sampling for this material, disabling may reduce overall noise for large objects that emit little light compared to other light sources", default=True)
- cls.homogeneous_volume = BoolProperty(name="Homogeneous Volume", description="When using volume rendering, assume volume has the same density everywhere, for faster rendering", default=False)
+ bpy.types.Material.cycles = PointerProperty(
+ name="Cycles Material Settings",
+ description="Cycles material settings",
+ type=cls,
+ )
+ cls.sample_as_light = BoolProperty(
+ name="Sample as Lamp",
+ description="Use direct light sampling for this material, disabling may reduce overall noise for large objects that emit little light compared to other light sources",
+ default=True,
+ )
+ cls.homogeneous_volume = BoolProperty(
+ name="Homogeneous Volume",
+ description="When using volume rendering, assume volume has the same density everywhere, for faster rendering",
+ default=False,
+ )
@classmethod
def unregister(cls):
@@ -141,8 +283,16 @@ class CyclesMaterialSettings(bpy.types.PropertyGroup):
class CyclesLampSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
- bpy.types.Lamp.cycles = PointerProperty(type=cls, name="Cycles Lamp Settings", description="Cycles lamp settings")
- cls.cast_shadow = BoolProperty(name="Cast Shadow", description="Lamp casts shadows", default=True)
+ bpy.types.Lamp.cycles = PointerProperty(
+ name="Cycles Lamp Settings",
+ description="Cycles lamp settings",
+ type=cls,
+ )
+ cls.cast_shadow = BoolProperty(
+ name="Cast Shadow",
+ description="Lamp casts shadows",
+ default=True,
+ )
@classmethod
def unregister(cls):
@@ -152,7 +302,22 @@ class CyclesLampSettings(bpy.types.PropertyGroup):
class CyclesWorldSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
- bpy.types.World.cycles = PointerProperty(type=cls, name="Cycles World Settings", description="Cycles world settings")
+ bpy.types.World.cycles = PointerProperty(
+ name="Cycles World Settings",
+ description="Cycles world settings",
+ type=cls,
+ )
+ cls.sample_as_light = BoolProperty(
+ name="Sample as Lamp",
+ description="Use direct light sampling for the environment, enabling for non-solid colors is recommended",
+ default=False,
+ )
+ cls.sample_map_resolution = IntProperty(
+ name="Map Resolution",
+ description="Importance map size is resolution x resolution; higher values potentially produce less noise, at the cost of memory and speed",
+ min=4, max=8096,
+ default=256,
+ )
@classmethod
def unregister(cls):
@@ -162,13 +327,37 @@ class CyclesWorldSettings(bpy.types.PropertyGroup):
class CyclesVisibilitySettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
- bpy.types.Object.cycles_visibility = PointerProperty(type=cls, name="Cycles Visibility Settings", description="Cycles visibility settings")
-
- cls.camera = BoolProperty(name="Camera", description="Object visibility for camera rays", default=True)
- cls.diffuse = BoolProperty(name="Diffuse", description="Object visibility for diffuse reflection rays", default=True)
- cls.glossy = BoolProperty(name="Glossy", description="Object visibility for glossy reflection rays", default=True)
- cls.transmission = BoolProperty(name="Transmission", description="Object visibility for transmission rays", default=True)
- cls.shadow = BoolProperty(name="Shadow", description="Object visibility for shadow rays", default=True)
+ bpy.types.Object.cycles_visibility = PointerProperty(
+ name="Cycles Visibility Settings",
+ description="Cycles visibility settings",
+ type=cls,
+ )
+
+ cls.camera = BoolProperty(
+ name="Camera",
+ description="Object visibility for camera rays",
+ default=True,
+ )
+ cls.diffuse = BoolProperty(
+ name="Diffuse",
+ description="Object visibility for diffuse reflection rays",
+ default=True,
+ )
+ cls.glossy = BoolProperty(
+ name="Glossy",
+ description="Object visibility for glossy reflection rays",
+ default=True,
+ )
+ cls.transmission = BoolProperty(
+ name="Transmission",
+ description="Object visibility for transmission rays",
+ default=True,
+ )
+ cls.shadow = BoolProperty(
+ name="Shadow",
+ description="Object visibility for shadow rays",
+ default=True,
+ )
@classmethod
def unregister(cls):
@@ -178,15 +367,39 @@ class CyclesVisibilitySettings(bpy.types.PropertyGroup):
class CyclesMeshSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
- bpy.types.Mesh.cycles = PointerProperty(type=cls, name="Cycles Mesh Settings", description="Cycles mesh settings")
- bpy.types.Curve.cycles = PointerProperty(type=cls, name="Cycles Mesh Settings", description="Cycles mesh settings")
- bpy.types.MetaBall.cycles = PointerProperty(type=cls, name="Cycles Mesh Settings", description="Cycles mesh settings")
-
- cls.displacement_method = EnumProperty(name="Displacement Method", description="Method to use for the displacement",
- items=enums.displacement_methods, default="BUMP")
- cls.use_subdivision = BoolProperty(name="Use Subdivision", description="Subdivide mesh for rendering",
- default=False)
- cls.dicing_rate = FloatProperty(name="Dicing Rate", description="", default=1.0, min=0.001, max=1000.0)
+ bpy.types.Mesh.cycles = PointerProperty(
+ name="Cycles Mesh Settings",
+ description="Cycles mesh settings",
+ type=cls,
+ )
+ bpy.types.Curve.cycles = PointerProperty(
+ name="Cycles Mesh Settings",
+ description="Cycles mesh settings",
+ type=cls,
+ )
+ bpy.types.MetaBall.cycles = PointerProperty(
+ name="Cycles Mesh Settings",
+ description="Cycles mesh settings",
+ type=cls,
+ )
+
+ cls.displacement_method = EnumProperty(
+ name="Displacement Method",
+ description="Method to use for the displacement",
+ items=enums.displacement_methods,
+ default='BUMP',
+ )
+ cls.use_subdivision = BoolProperty(
+ name="Use Subdivision",
+ description="Subdivide mesh for rendering",
+ default=False,
+ )
+ cls.dicing_rate = FloatProperty(
+ name="Dicing Rate",
+ description="",
+ min=0.001, max=1000.0,
+ default=1.0,
+ )
@classmethod
def unregister(cls):
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index ea23e2b56a5..67ff79a2037 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -147,6 +147,8 @@ class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
sub.label(text="Acceleration structure:")
sub.prop(cscene, "debug_bvh_type", text="")
sub.prop(cscene, "debug_use_spatial_splits")
+ sub.prop(cscene, "use_cache")
+
class CyclesRender_PT_layers(CyclesButtonsPanel, Panel):
bl_label = "Layers"
@@ -451,10 +453,38 @@ class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
layout = self.layout
world = context.world
+
if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
layout.prop(world, "horizon_color", text="Color")
+class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
+ bl_label = "Settings"
+ bl_context = "world"
+ bl_options = {'DEFAULT_CLOSED'}
+
+ @classmethod
+ def poll(cls, context):
+ return context.world and CyclesButtonsPanel.poll(context)
+
+ def draw(self, context):
+ layout = self.layout
+
+ world = context.world
+ cworld = world.cycles
+
+ split = layout.split()
+ col = split.column()
+
+ col.prop(cworld, "sample_as_light")
+ row = col.row()
+ row.active = cworld.sample_as_light
+ row.prop(cworld, "sample_map_resolution")
+
+ col = split.column()
+ col.label()
+
+
class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
bl_label = "Volume"
bl_context = "world"
@@ -707,7 +737,7 @@ def draw_device(self, context):
scene = context.scene
layout = self.layout
- if scene.render.engine == "CYCLES":
+ if scene.render.engine == 'CYCLES':
cscene = scene.cycles
layout.prop(cscene, "feature_set")
@@ -718,6 +748,7 @@ def draw_device(self, context):
elif device_type == 'OPENCL' and cscene.feature_set == 'EXPERIMENTAL':
layout.prop(cscene, "device")
+
def draw_pause(self, context):
layout = self.layout
scene = context.scene
@@ -725,7 +756,7 @@ def draw_pause(self, context):
if scene.render.engine == "CYCLES":
view = context.space_data
- if view.viewport_shade == "RENDERED":
+ if view.viewport_shade == 'RENDERED':
cscene = scene.cycles
layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 608cb33eadd..bc7868e0192 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -16,10 +16,13 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "graph.h"
#include "light.h"
#include "mesh.h"
#include "object.h"
#include "scene.h"
+#include "nodes.h"
+#include "shader.h"
#include "blender_sync.h"
#include "blender_util.h"
@@ -152,6 +155,35 @@ void BlenderSync::sync_light(BL::Object b_parent, int b_index, BL::Object b_ob,
light->tag_update(scene);
}
+void BlenderSync::sync_background_light()
+{
+ BL::World b_world = b_scene.world();
+
+ PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
+ bool sample_as_light = get_boolean(cworld, "sample_as_light");
+
+ if(sample_as_light) {
+ /* test if we need to sync */
+ Light *light;
+ ObjectKey key(b_world, 0, b_world);
+
+ if(light_map.sync(&light, b_world, b_world, key) ||
+ world_recalc ||
+ b_world.ptr.data != world_map)
+ {
+ light->type = LIGHT_BACKGROUND;
+ light->map_resolution = get_int(cworld, "sample_map_resolution");
+ light->shader = scene->default_background;
+
+ light->tag_update(scene);
+ light_map.set_recalc(b_world);
+ }
+ }
+
+ world_map = b_world.ptr.data;
+ world_recalc = false;
+}
+
/* Object */
void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm, uint layer_flag)
@@ -263,6 +295,8 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d)
}
}
+ sync_background_light();
+
/* handle removed data and modified pointers */
if(light_map.post_sync())
scene->light_manager->tag_update(scene);
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index f5ffc321476..1ce134f3094 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -700,9 +700,6 @@ void BlenderSync::sync_world()
if(background->modified(prevbackground))
background->tag_update(scene);
-
- world_map = b_world.ptr.data;
- world_recalc = false;
}
/* Sync Lamps */
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index c00320f0094..29ab0ebef1f 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -236,6 +236,7 @@ SceneParams BlenderSync::get_scene_params(BL::Scene b_scene, bool background)
params.bvh_type = (SceneParams::BVHType)RNA_enum_get(&cscene, "debug_bvh_type");
params.use_bvh_spatial_split = RNA_boolean_get(&cscene, "debug_use_spatial_splits");
+ params.use_bvh_cache = (background)? RNA_boolean_get(&cscene, "use_cache"): false;
return params;
}
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 7b65376bd84..5e76a0a0b1e 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -80,6 +80,7 @@ private:
Mesh *sync_mesh(BL::Object b_ob, bool object_updated);
void sync_object(BL::Object b_parent, int b_index, BL::Object b_object, Transform& tfm, uint layer_flag);
void sync_light(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm);
+ void sync_background_light();
/* util */
void find_shader(BL::ID id, vector<uint>& used_shaders, int default_shader);
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index cd3ad709812..c9bfa964332 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -75,12 +75,18 @@ bool BVH::cache_read(CacheData& key)
foreach(Object *ob, objects) {
key.add(ob->mesh->verts);
key.add(ob->mesh->triangles);
+ key.add(&ob->bounds, sizeof(ob->bounds));
+ key.add(&ob->visibility, sizeof(ob->visibility));
+ key.add(&ob->mesh->transform_applied, sizeof(bool));
}
CacheData value;
if(Cache::global.lookup(key, value)) {
+ cache_filename = key.get_filename();
+
value.read(pack.root_index);
+ value.read(pack.SAH);
value.read(pack.nodes);
value.read(pack.object_node);
@@ -101,6 +107,7 @@ void BVH::cache_write(CacheData& key)
CacheData value;
value.add(pack.root_index);
+ value.add(pack.SAH);
value.add(pack.nodes);
value.add(pack.object_node);
@@ -111,6 +118,26 @@ void BVH::cache_write(CacheData& key)
value.add(pack.is_leaf);
Cache::global.insert(key, value);
+
+ cache_filename = key.get_filename();
+}
+
+void BVH::clear_cache_except()
+{
+ set<string> except;
+
+ if(!cache_filename.empty())
+ except.insert(cache_filename);
+
+ foreach(Object *ob, objects) {
+ Mesh *mesh = ob->mesh;
+ BVH *bvh = mesh->bvh;
+
+ if(bvh && !bvh->cache_filename.empty())
+ except.insert(bvh->cache_filename);
+ }
+
+ Cache::global.clear_except("bvh", except);
}
/* Building */
@@ -177,6 +204,10 @@ void BVH::build(Progress& progress)
if(params.use_cache) {
progress.set_substatus("Writing BVH cache");
cache_write(key);
+
+ /* clear other bvh files from cache */
+ if(params.top_level)
+ clear_cache_except();
}
}
diff --git a/intern/cycles/bvh/bvh.h b/intern/cycles/bvh/bvh.h
index e502af72335..30ae7dac106 100644
--- a/intern/cycles/bvh/bvh.h
+++ b/intern/cycles/bvh/bvh.h
@@ -20,6 +20,7 @@
#include "bvh_params.h"
+#include "util_string.h"
#include "util_types.h"
#include "util_vector.h"
@@ -83,6 +84,7 @@ public:
PackedBVH pack;
BVHParams params;
vector<Object*> objects;
+ string cache_filename;
static BVH *create(const BVHParams& params, const vector<Object*>& objects);
virtual ~BVH() {}
@@ -90,6 +92,8 @@ public:
void build(Progress& progress);
void refit(Progress& progress);
+ void clear_cache_except();
+
protected:
BVH(const BVHParams& params, const vector<Object*>& objects);
diff --git a/intern/cycles/bvh/bvh_params.h b/intern/cycles/bvh/bvh_params.h
index b38e40cfbda..38093438500 100644
--- a/intern/cycles/bvh/bvh_params.h
+++ b/intern/cycles/bvh/bvh_params.h
@@ -26,7 +26,7 @@ class BVHParams
{
public:
/* spatial split area threshold */
- bool use_spatial_split;
+ int use_spatial_split;
float spatial_split_alpha;
/* SAH costs */
@@ -38,13 +38,15 @@ public:
int max_leaf_size;
/* object or mesh level bvh */
- bool top_level;
+ int top_level;
/* disk cache */
- bool use_cache;
+ int use_cache;
/* QBVH */
- bool use_qbvh;
+ int use_qbvh;
+
+ int pad;
/* fixed parameters */
enum {
@@ -67,6 +69,7 @@ public:
top_level = false;
use_cache = false;
use_qbvh = false;
+ pad = false;
}
/* SAH costs */
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index f4b2b7a8269..25da978edd8 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -217,7 +217,7 @@ public:
#ifdef WITH_OPTIMIZED_KERNEL
if(system_cpu_support_optimized()) {
for(int x = task.shader_x; x < task.shader_x + task.shader_w; x++) {
- kernel_cpu_optimized_shader(kg, (uint4*)task.shader_input, (float3*)task.shader_output, task.shader_eval_type, x);
+ kernel_cpu_optimized_shader(kg, (uint4*)task.shader_input, (float4*)task.shader_output, task.shader_eval_type, x);
if(tasks.worker_cancel())
break;
@@ -227,7 +227,7 @@ public:
#endif
{
for(int x = task.shader_x; x < task.shader_x + task.shader_w; x++) {
- kernel_cpu_shader(kg, (uint4*)task.shader_input, (float3*)task.shader_output, task.shader_eval_type, x);
+ kernel_cpu_shader(kg, (uint4*)task.shader_input, (float4*)task.shader_output, task.shader_eval_type, x);
if(tasks.worker_cancel())
break;
diff --git a/intern/cycles/kernel/kernel.cl b/intern/cycles/kernel/kernel.cl
index 479cf9b2e64..305d81339c2 100644
--- a/intern/cycles/kernel/kernel.cl
+++ b/intern/cycles/kernel/kernel.cl
@@ -80,7 +80,7 @@ __kernel void kernel_ocl_tonemap(
kernel_film_tonemap(kg, rgba, buffer, sample, resolution, x, y, offset, stride);
}
-/*__kernel void kernel_ocl_shader(__global uint4 *input, __global float3 *output, int type, int sx)
+/*__kernel void kernel_ocl_shader(__global uint4 *input, __global float *output, int type, int sx)
{
int x = sx + get_global_id(0);
diff --git a/intern/cycles/kernel/kernel.cpp b/intern/cycles/kernel/kernel.cpp
index e66ddd86cd6..9e0d252772b 100644
--- a/intern/cycles/kernel/kernel.cpp
+++ b/intern/cycles/kernel/kernel.cpp
@@ -218,7 +218,7 @@ void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer, int sam
/* Shader Evaluation */
-void kernel_cpu_shader(KernelGlobals *kg, uint4 *input, float3 *output, int type, int i)
+void kernel_cpu_shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int i)
{
kernel_shader_evaluate(kg, input, output, (ShaderEvalType)type, i);
}
diff --git a/intern/cycles/kernel/kernel.cu b/intern/cycles/kernel/kernel.cu
index c97aeb67548..4e585fd563d 100644
--- a/intern/cycles/kernel/kernel.cu
+++ b/intern/cycles/kernel/kernel.cu
@@ -44,7 +44,7 @@ extern "C" __global__ void kernel_cuda_tonemap(uchar4 *rgba, float4 *buffer, int
kernel_film_tonemap(NULL, rgba, buffer, sample, resolution, x, y, offset, stride);
}
-extern "C" __global__ void kernel_cuda_shader(uint4 *input, float3 *output, int type, int sx)
+extern "C" __global__ void kernel_cuda_shader(uint4 *input, float4 *output, int type, int sx)
{
int x = sx + blockDim.x*blockIdx.x + threadIdx.x;
diff --git a/intern/cycles/kernel/kernel.h b/intern/cycles/kernel/kernel.h
index 20d43c91169..df6b5ee92da 100644
--- a/intern/cycles/kernel/kernel.h
+++ b/intern/cycles/kernel/kernel.h
@@ -40,7 +40,7 @@ void kernel_cpu_path_trace(KernelGlobals *kg, float4 *buffer, unsigned int *rng_
int sample, int x, int y, int offset, int stride);
void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer,
int sample, int resolution, int x, int y, int offset, int stride);
-void kernel_cpu_shader(KernelGlobals *kg, uint4 *input, float3 *output,
+void kernel_cpu_shader(KernelGlobals *kg, uint4 *input, float4 *output,
int type, int i);
#ifdef WITH_OPTIMIZED_KERNEL
@@ -48,7 +48,7 @@ void kernel_cpu_optimized_path_trace(KernelGlobals *kg, float4 *buffer, unsigned
int sample, int x, int y, int offset, int stride);
void kernel_cpu_optimized_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer,
int sample, int resolution, int x, int y, int offset, int stride);
-void kernel_cpu_optimized_shader(KernelGlobals *kg, uint4 *input, float3 *output,
+void kernel_cpu_optimized_shader(KernelGlobals *kg, uint4 *input, float4 *output,
int type, int i);
#endif
diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h
index 783ae519845..79f894bfdac 100644
--- a/intern/cycles/kernel/kernel_compat_cpu.h
+++ b/intern/cycles/kernel/kernel_compat_cpu.h
@@ -141,6 +141,7 @@ template<typename T> struct texture_image {
};
typedef texture<float4> texture_float4;
+typedef texture<float2> texture_float2;
typedef texture<float> texture_float;
typedef texture<uint> texture_uint;
typedef texture<int> texture_int;
diff --git a/intern/cycles/kernel/kernel_compat_cuda.h b/intern/cycles/kernel/kernel_compat_cuda.h
index 40129a2f68f..cc719bfadbc 100644
--- a/intern/cycles/kernel/kernel_compat_cuda.h
+++ b/intern/cycles/kernel/kernel_compat_cuda.h
@@ -45,6 +45,7 @@
/* Textures */
typedef texture<float4, 1> texture_float4;
+typedef texture<float2, 1> texture_float2;
typedef texture<float, 1> texture_float;
typedef texture<uint, 1> texture_uint;
typedef texture<int, 1> texture_int;
diff --git a/intern/cycles/kernel/kernel_differential.h b/intern/cycles/kernel/kernel_differential.h
index 4e2b1ea7d13..5b4290a7722 100644
--- a/intern/cycles/kernel/kernel_differential.h
+++ b/intern/cycles/kernel/kernel_differential.h
@@ -71,8 +71,8 @@ __device void differential_dudv(differential *du, differential *dv, float3 dPdu,
* and the same for dudy and dvdy. the denominator is the same for both
* solutions, so we compute it only once.
*
- * dP.dx = dPdu * dudx + dPdv * dvdx;
- * dP.dy = dPdu * dudy + dPdv * dvdy; */
+ * dP.dx = dPdu * dudx + dPdv * dvdx;
+ * dP.dy = dPdu * dudy + dPdv * dvdy; */
float det = (dPdu.x*dPdv.y - dPdv.x*dPdu.y);
diff --git a/intern/cycles/kernel/kernel_displace.h b/intern/cycles/kernel/kernel_displace.h
index c39e5e43dbb..73666892cf3 100644
--- a/intern/cycles/kernel/kernel_displace.h
+++ b/intern/cycles/kernel/kernel_displace.h
@@ -18,7 +18,7 @@
CCL_NAMESPACE_BEGIN
-__device void kernel_shader_evaluate(KernelGlobals *kg, uint4 *input, float3 *output, ShaderEvalType type, int i)
+__device void kernel_shader_evaluate(KernelGlobals *kg, uint4 *input, float4 *output, ShaderEvalType type, int i)
{
ShaderData sd;
uint4 in = input[i];
@@ -62,7 +62,7 @@ __device void kernel_shader_evaluate(KernelGlobals *kg, uint4 *input, float3 *ou
}
/* write output */
- output[i] = out;
+ output[i] = make_float4(out.x, out.y, out.z, 0.0f);
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/kernel_emission.h b/intern/cycles/kernel/kernel_emission.h
index b81db721eb3..51698f3a9bd 100644
--- a/intern/cycles/kernel/kernel_emission.h
+++ b/intern/cycles/kernel/kernel_emission.h
@@ -25,21 +25,31 @@ __device float3 direct_emissive_eval(KernelGlobals *kg, float rando,
{
/* setup shading at emitter */
ShaderData sd;
-
- shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v);
- ls->Ng = sd.Ng;
-
- /* no path flag, we're evaluating this for all closures. that's weak but
- we'd have to do multiple evaluations otherwise */
- shader_eval_surface(kg, &sd, rando, 0);
-
float3 eval;
- /* evaluate emissive closure */
- if(sd.flag & SD_EMISSION)
- eval = shader_emissive_eval(kg, &sd);
- else
- eval = make_float3(0.0f, 0.0f, 0.0f);
+ if(ls->type == LIGHT_BACKGROUND) {
+ Ray ray;
+ ray.D = ls->D;
+ ray.P = ls->P;
+ ray.dP.dx = make_float3(0.0f, 0.0f, 0.0f);
+ ray.dP.dy = make_float3(0.0f, 0.0f, 0.0f);
+ shader_setup_from_background(kg, &sd, &ray);
+ eval = shader_eval_background(kg, &sd, 0);
+ }
+ else {
+ shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v);
+ ls->Ng = sd.Ng;
+
+ /* no path flag, we're evaluating this for all closures. that's weak but
+ we'd have to do multiple evaluations otherwise */
+ shader_eval_surface(kg, &sd, rando, 0);
+
+ /* evaluate emissive closure */
+ if(sd.flag & SD_EMISSION)
+ eval = shader_emissive_eval(kg, &sd);
+ else
+ eval = make_float3(0.0f, 0.0f, 0.0f);
+ }
shader_release(kg, &sd);
@@ -51,25 +61,31 @@ __device bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
{
LightSample ls;
+ float pdf = -1.0f;
+
#ifdef __MULTI_LIGHT__
if(lindex != -1) {
/* sample position on a specified light */
- light_select(kg, lindex, randu, randv, sd->P, &ls);
+ light_select(kg, lindex, randu, randv, sd->P, &ls, &pdf);
}
else
#endif
{
/* sample a light and position on int */
- light_sample(kg, randt, randu, randv, sd->P, &ls);
+ light_sample(kg, randt, randu, randv, sd->P, &ls, &pdf);
}
/* compute pdf */
- float pdf = light_sample_pdf(kg, &ls, -ls.D, ls.t);
+ if(pdf < 0.0f)
+ pdf = light_sample_pdf(kg, &ls, -ls.D, ls.t);
+
+ if(pdf == 0.0f)
+ return false;
/* evaluate closure */
*eval = direct_emissive_eval(kg, rando, &ls, randu, randv, -ls.D);
- if(is_zero(*eval) || pdf == 0.0f)
+ if(is_zero(*eval))
return false;
/* todo: use visbility flag to skip lights */
@@ -83,7 +99,7 @@ __device bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
if(is_zero(*eval))
return false;
- if(ls.prim != ~0) {
+ if(ls.prim != ~0 || ls.type == LIGHT_BACKGROUND) {
/* multiple importance sampling */
float mis_weight = power_heuristic(pdf, bsdf_pdf);
*eval *= mis_weight;
@@ -125,7 +141,8 @@ __device float3 indirect_emission(KernelGlobals *kg, ShaderData *sd, float t, in
float3 L = shader_emissive_eval(kg, sd);
if(!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_SAMPLE_AS_LIGHT)) {
- /* multiple importance sampling */
+ /* multiple importance sampling, get triangle light pdf,
+ and compute weight with respect to BSDF pdf */
float pdf = triangle_light_pdf(kg, sd->Ng, sd->I, t);
float mis_weight = power_heuristic(bsdf_pdf, pdf);
@@ -135,5 +152,34 @@ __device float3 indirect_emission(KernelGlobals *kg, ShaderData *sd, float t, in
return L;
}
+/* Indirect Background */
+
+__device float3 indirect_background(KernelGlobals *kg, Ray *ray, int path_flag, float bsdf_pdf)
+{
+#ifdef __BACKGROUND__
+ /* evaluate background closure */
+ ShaderData sd;
+ shader_setup_from_background(kg, &sd, ray);
+ float3 L = shader_eval_background(kg, &sd, path_flag);
+ shader_release(kg, &sd);
+
+ /* check if background light exists or if we should skip pdf */
+ int res = kernel_data.integrator.pdf_background_res;
+
+ if(!(path_flag & PATH_RAY_MIS_SKIP) && res) {
+ /* multiple importance sampling, get background light pdf for ray
+ direction, and compute weight with respect to BSDF pdf */
+ float pdf = background_light_pdf(kg, ray->D);
+ float mis_weight = power_heuristic(bsdf_pdf, pdf);
+
+ return L*mis_weight;
+ }
+
+ return L;
+#else
+ return make_float3(0.8f, 0.8f, 0.8f);
+#endif
+}
+
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index d5d47b28d59..4c2b69c2716 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -26,6 +26,7 @@ typedef struct LightSample {
int object;
int prim;
int shader;
+ LightType type;
} LightSample;
/* Regular Light */
@@ -58,13 +59,125 @@ __device float3 area_light_sample(float3 axisu, float3 axisv, float randu, float
return axisu*randu + axisv*randv;
}
+__device float3 background_light_sample(KernelGlobals *kg, float randu, float randv, float *pdf)
+{
+ /* for the following, the CDF values are actually a pair of floats, with the
+ function value as X and the actual CDF as Y. The last entry's function
+ value is the CDF total. */
+ int res = kernel_data.integrator.pdf_background_res;
+ int cdf_count = res + 1;
+
+ /* this is basically std::lower_bound as used by pbrt */
+ int first = 0;
+ int count = res;
+
+ while(count > 0) {
+ int step = count >> 1;
+ int middle = first + step;
+
+ if(kernel_tex_fetch(__light_background_marginal_cdf, middle).y < randv) {
+ first = middle + 1;
+ count -= step + 1;
+ }
+ else
+ count = step;
+ }
+
+ int index_v = max(0, first - 1);
+ kernel_assert(index_v >= 0 && index_v < res);
+
+ float2 cdf_v = kernel_tex_fetch(__light_background_marginal_cdf, index_v);
+ float2 cdf_next_v = kernel_tex_fetch(__light_background_marginal_cdf, index_v + 1);
+ float2 cdf_last_v = kernel_tex_fetch(__light_background_marginal_cdf, res);
+
+ /* importance-sampled V direction */
+ float dv = (randv - cdf_v.y) / (cdf_next_v.y - cdf_v.y);
+ float v = (index_v + dv) / res;
+
+ /* this is basically std::lower_bound as used by pbrt */
+ first = 0;
+ count = res;
+ while(count > 0) {
+ int step = count >> 1;
+ int middle = first + step;
+
+ if(kernel_tex_fetch(__light_background_conditional_cdf, index_v * cdf_count + middle).y < randu) {
+ first = middle + 1;
+ count -= step + 1;
+ }
+ else
+ count = step;
+ }
+
+ int index_u = max(0, first - 1);
+ kernel_assert(index_u >= 0 && index_u < res);
+
+ float2 cdf_u = kernel_tex_fetch(__light_background_conditional_cdf, index_v * cdf_count + index_u);
+ float2 cdf_next_u = kernel_tex_fetch(__light_background_conditional_cdf, index_v * cdf_count + index_u + 1);
+ float2 cdf_last_u = kernel_tex_fetch(__light_background_conditional_cdf, index_v * cdf_count + res);
+
+ /* importance-sampled U direction */
+ float du = (randu - cdf_u.y) / (cdf_next_u.y - cdf_u.y);
+ float u = (index_u + du) / res;
+
+ /* spherical coordinates */
+ float theta = v * M_PI_F;
+ float phi = u * M_PI_F * 2.0f;
+
+ /* compute pdf */
+ float denom = cdf_last_u.x * cdf_last_v.x;
+ float sin_theta = sinf(theta);
+
+ if(sin_theta == 0.0f || denom == 0.0f)
+ *pdf = 0.0f;
+ else
+ *pdf = (cdf_u.x * cdf_v.x)/(2.0f * M_PI_F * M_PI_F * sin_theta * denom);
+
+ *pdf *= kernel_data.integrator.pdf_lights;
+
+ /* compute direction */
+ return spherical_to_direction(theta, phi);
+}
+
+__device float background_light_pdf(KernelGlobals *kg, float3 direction)
+{
+ float2 uv = direction_to_equirectangular(direction);
+ int res = kernel_data.integrator.pdf_background_res;
+
+ float sin_theta = sinf(uv.y * M_PI_F);
+
+ if(sin_theta == 0.0f)
+ return 0.0f;
+
+ int index_u = clamp((int)(uv.x * res), 0, res - 1);
+ int index_v = clamp((int)(uv.y * res), 0, res - 1);
+
+ /* pdfs in V direction */
+ float2 cdf_last_u = kernel_tex_fetch(__light_background_conditional_cdf, index_v * (res + 1) + res);
+ float2 cdf_last_v = kernel_tex_fetch(__light_background_marginal_cdf, res);
+
+ float denom = cdf_last_u.x * cdf_last_v.x;
+
+ if(denom == 0.0f)
+ return 0.0f;
+
+ /* pdfs in U direction */
+ float2 cdf_u = kernel_tex_fetch(__light_background_conditional_cdf, index_v * (res + 1) + index_u);
+ float2 cdf_v = kernel_tex_fetch(__light_background_marginal_cdf, index_v);
+
+ float pdf = (cdf_u.x * cdf_v.x)/(2.0f * M_PI_F * M_PI_F * sin_theta * denom);
+
+ return pdf * kernel_data.integrator.pdf_lights;
+}
+
__device void regular_light_sample(KernelGlobals *kg, int point,
- float randu, float randv, float3 P, LightSample *ls)
+ float randu, float randv, float3 P, LightSample *ls, float *pdf)
{
float4 data0 = kernel_tex_fetch(__light_data, point*LIGHT_SIZE + 0);
float4 data1 = kernel_tex_fetch(__light_data, point*LIGHT_SIZE + 1);
LightType type = (LightType)__float_as_int(data0.x);
+ ls->type = type;
if(type == LIGHT_DISTANT) {
/* distant light */
@@ -79,6 +192,15 @@ __device void regular_light_sample(KernelGlobals *kg, int point,
ls->D = -D;
ls->t = FLT_MAX;
}
+ else if(type == LIGHT_BACKGROUND) {
+ /* infinite area light (e.g. light dome or env light) */
+ float3 D = background_light_sample(kg, randu, randv, pdf);
+
+ ls->P = D;
+ ls->Ng = D;
+ ls->D = -D;
+ ls->t = FLT_MAX;
+ }
else {
ls->P = make_float3(data0.y, data0.z, data0.w);
@@ -139,6 +261,7 @@ __device void triangle_light_sample(KernelGlobals *kg, int prim, int object,
ls->object = object;
ls->prim = prim;
ls->t = 0.0f;
+ ls->type = LIGHT_AREA;
#ifdef __INSTANCING__
/* instance transform */
@@ -192,7 +315,7 @@ __device int light_distribution_sample(KernelGlobals *kg, float randt)
/* Generic Light */
-__device void light_sample(KernelGlobals *kg, float randt, float randu, float randv, float3 P, LightSample *ls)
+__device void light_sample(KernelGlobals *kg, float randt, float randu, float randv, float3 P, LightSample *ls, float *pdf)
{
/* sample index */
int index = light_distribution_sample(kg, randt);
@@ -207,7 +330,7 @@ __device void light_sample(KernelGlobals *kg, float randt, float randu, float ra
}
else {
int point = -prim-1;
- regular_light_sample(kg, point, randu, randv, P, ls);
+ regular_light_sample(kg, point, randu, randv, P, ls, pdf);
}
/* compute incoming direction and distance */
@@ -227,9 +350,9 @@ __device float light_sample_pdf(KernelGlobals *kg, LightSample *ls, float3 I, fl
return pdf;
}
-__device void light_select(KernelGlobals *kg, int index, float randu, float randv, float3 P, LightSample *ls)
+__device void light_select(KernelGlobals *kg, int index, float randu, float randv, float3 P, LightSample *ls, float *pdf)
{
- regular_light_sample(kg, index, randu, randv, P, ls);
+ regular_light_sample(kg, index, randu, randv, P, ls, pdf);
}
__device float light_select_pdf(KernelGlobals *kg, LightSample *ls, float3 I, float t)
diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h
index df291b66b23..9776baf65e4 100644
--- a/intern/cycles/kernel/kernel_montecarlo.h
+++ b/intern/cycles/kernel/kernel_montecarlo.h
@@ -104,13 +104,13 @@ __device_inline void sample_uniform_hemisphere(const float3 N,
__device float3 sample_uniform_sphere(float u1, float u2)
{
- float z = 1.0f - 2.0f*u1;
- float r = sqrtf(fmaxf(0.0f, 1.0f - z*z));
- float phi = 2.0f*M_PI_F*u2;
- float x = r*cosf(phi);
- float y = r*sinf(phi);
+ float z = 1.0f - 2.0f*u1;
+ float r = sqrtf(fmaxf(0.0f, 1.0f - z*z));
+ float phi = 2.0f*M_PI_F*u2;
+ float x = r*cosf(phi);
+ float y = r*sinf(phi);
- return make_float3(x, y, z);
+ return make_float3(x, y, z);
}
__device float power_heuristic(float a, float b)
@@ -203,6 +203,28 @@ __device float3 spherical_to_direction(float theta, float phi)
cosf(theta));
}
+/* Equirectangular */
+
+__device float2 direction_to_equirectangular(float3 dir)
+{
+ float u = (atan2f(dir.y, dir.x) + M_PI_F)/(2.0f*M_PI_F);
+ float v = atan2f(dir.z, hypotf(dir.x, dir.y))/M_PI_F + 0.5f;
+
+ return make_float2(u, v);
+}
+
+__device float3 equirectangular_to_direction(float u, float v)
+{
+ /* XXX check correctness? */
+ float theta = M_PI_F*v;
+ float phi = 2.0f*M_PI_F*u;
+
+ return make_float3(
+ sin(theta)*cos(phi),
+ sin(theta)*sin(phi),
+ cos(theta));
+}
+
CCL_NAMESPACE_END
#endif /* __KERNEL_MONTECARLO_CL__ */
diff --git a/intern/cycles/kernel/kernel_optimized.cpp b/intern/cycles/kernel/kernel_optimized.cpp
index c437e06adfa..50341021d9d 100644
--- a/intern/cycles/kernel/kernel_optimized.cpp
+++ b/intern/cycles/kernel/kernel_optimized.cpp
@@ -49,7 +49,7 @@ void kernel_cpu_optimized_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffe
/* Shader Evaluate */
-void kernel_cpu_optimized_shader(KernelGlobals *kg, uint4 *input, float3 *output, int type, int i)
+void kernel_cpu_optimized_shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int i)
{
kernel_shader_evaluate(kg, input, output, (ShaderEvalType)type, i);
}
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
index d27ad861c6a..c80d2068506 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -260,14 +260,9 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, R
Ltransparent += average(throughput);
}
else {
-#ifdef __BACKGROUND__
- ShaderData sd;
- shader_setup_from_background(kg, &sd, &ray);
- L += throughput*shader_eval_background(kg, &sd, state.flag);
- shader_release(kg, &sd);
-#else
- L += throughput*make_float3(0.8f, 0.8f, 0.8f);
-#endif
+ /* sample background shader */
+ float3 background_L = indirect_background(kg, &ray, state.flag, ray_pdf);
+ L += throughput*background_L;
}
break;
@@ -362,7 +357,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, R
throughput *= bsdf_eval/bsdf_pdf;
/* set labels */
-#ifdef __EMISSION__
+#if defined(__EMISSION__) || defined(__BACKGROUND__)
ray_pdf = bsdf_pdf;
#endif
diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h
index 570e0721268..9c59e1566a9 100644
--- a/intern/cycles/kernel/kernel_shader.h
+++ b/intern/cycles/kernel/kernel_shader.h
@@ -151,7 +151,7 @@ __device void shader_setup_from_sample(KernelGlobals *kg, ShaderData *sd,
instanced = true;
else
#endif
- sd->object = -sd->object-1;
+ sd->object = ~sd->object;
#ifdef __INSTANCING__
}
#endif
diff --git a/intern/cycles/kernel/kernel_textures.h b/intern/cycles/kernel/kernel_textures.h
index 2bfb1b3b88e..ca7ae432efa 100644
--- a/intern/cycles/kernel/kernel_textures.h
+++ b/intern/cycles/kernel/kernel_textures.h
@@ -33,6 +33,8 @@ KERNEL_TEX(float4, texture_float4, __attributes_float3)
/* lights */
KERNEL_TEX(float4, texture_float4, __light_distribution)
KERNEL_TEX(float4, texture_float4, __light_data)
+KERNEL_TEX(float2, texture_float2, __light_background_marginal_cdf)
+KERNEL_TEX(float2, texture_float2, __light_background_conditional_cdf)
/* shaders */
KERNEL_TEX(uint4, texture_uint4, __svm_nodes)
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 2c03a34df1f..008ec0bdf28 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -165,6 +165,7 @@ typedef enum ShaderFlag {
typedef enum LightType {
LIGHT_POINT,
LIGHT_DISTANT,
+ LIGHT_BACKGROUND,
LIGHT_AREA
} LightType;
@@ -379,18 +380,19 @@ typedef struct KernelIntegrator {
int num_all_lights;
float pdf_triangles;
float pdf_lights;
+ int pdf_background_res;
/* bounces */
int min_bounce;
int max_bounce;
- int max_diffuse_bounce;
- int max_glossy_bounce;
- int max_transmission_bounce;
+ int max_diffuse_bounce;
+ int max_glossy_bounce;
+ int max_transmission_bounce;
/* transparent */
- int transparent_min_bounce;
- int transparent_max_bounce;
+ int transparent_min_bounce;
+ int transparent_max_bounce;
int transparent_shadows;
/* caustics */
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index 62e24166970..073021bdd54 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -175,9 +175,8 @@ __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float
decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb);
float3 co = stack_load_float3(stack, co_offset);
- float u = (atan2f(co.y, co.x) + M_PI_F)/(2*M_PI_F);
- float v = atan2f(co.z, hypotf(co.x, co.y))/M_PI_F + 0.5f;
- float4 f = svm_image_texture(kg, id, u, v);
+ float2 uv = direction_to_equirectangular(co);
+ float4 f = svm_image_texture(kg, id, uv.x, uv.y);
float3 r = make_float3(f.x, f.y, f.z);
if(srgb) {
diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 74943fd0ff7..eea5cfb0137 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -26,8 +26,74 @@
#include "util_foreach.h"
#include "util_progress.h"
+#include "kernel_montecarlo.h"
+
CCL_NAMESPACE_BEGIN
+static void dump_background_pixels(Device *device, DeviceScene *dscene, int res, vector<float3>& pixels)
+{
+ /* create input */
+ int width = res;
+ int height = res;
+
+ device_vector<uint4> d_input;
+ device_vector<float4> d_output;
+
+ uint4 *d_input_data = d_input.resize(width*height);
+
+ for(int y = 0; y < height; y++) {
+ for(int x = 0; x < width; x++) {
+ float u = x/(float)width;
+ float v = y/(float)height;
+ float3 D = -equirectangular_to_direction(u, v);
+
+ uint4 in = make_uint4(__float_as_int(D.x), __float_as_int(D.y), __float_as_int(D.z), 0);
+ d_input_data[x + y*width] = in;
+ }
+ }
+
+ /* compute on device */
+ float4 *d_output_data = d_output.resize(width*height);
+ memset((void*)d_output.data_pointer, 0, d_output.memory_size());
+
+ device->const_copy_to("__data", &dscene->data, sizeof(dscene->data));
+
+ device->mem_alloc(d_input, MEM_READ_ONLY);
+ device->mem_copy_to(d_input);
+ device->mem_alloc(d_output, MEM_WRITE_ONLY);
+
+ DeviceTask main_task(DeviceTask::SHADER);
+ main_task.shader_input = d_input.device_pointer;
+ main_task.shader_output = d_output.device_pointer;
+ main_task.shader_eval_type = SHADER_EVAL_BACKGROUND;
+ main_task.shader_x = 0;
+ main_task.shader_w = width*height;
+
+ list<DeviceTask> split_tasks;
+ main_task.split_max_size(split_tasks, 128*128);
+
+ foreach(DeviceTask& task, split_tasks) {
+ device->task_add(task);
+ device->task_wait();
+ }
+
+ device->mem_copy_from(d_output, 0, 1, d_output.size(), sizeof(float4));
+ device->mem_free(d_input);
+ device->mem_free(d_output);
+
+ d_output_data = reinterpret_cast<float4*>(d_output.data_pointer);
+
+ pixels.resize(width*height);
+
+ for(int y = 0; y < height; y++) {
+ for(int x = 0; x < width; x++) {
+ pixels[y*width + x].x = d_output_data[y*width + x].x;
+ pixels[y*width + x].y = d_output_data[y*width + x].y;
+ pixels[y*width + x].z = d_output_data[y*width + x].z;
+ }
+ }
+}
+
/* Light */
Light::Light()
@@ -44,6 +110,8 @@ Light::Light()
axisv = make_float3(0.0f, 0.0f, 0.0f);
sizev = 1.0f;
+ map_resolution = 512;
+
cast_shadow = true;
shader = 0;
}
@@ -66,6 +134,8 @@ LightManager::~LightManager()
void LightManager::device_update_distribution(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
{
+ progress.set_status("Updating Lights", "Computing distribution");
+
/* option to always sample all point lights */
bool multi_light = false;
@@ -109,7 +179,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
/* triangles */
size_t offset = 0;
- size_t j = 0;
+ int j = 0;
foreach(Object *object, scene->objects) {
Mesh *mesh = object->mesh;
@@ -128,7 +198,10 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
/* sum area */
if(have_emission) {
Transform tfm = object->tfm;
- int object_id = (mesh->transform_applied)? -j-1: j;
+ int object_id = j;
+
+ if(mesh->transform_applied)
+ object_id = ~object_id;
for(size_t i = 0; i < mesh->triangles.size(); i++) {
Shader *shader = scene->shaders[mesh->shader[i]];
@@ -161,9 +234,9 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
if(!multi_light) {
float lightarea = (totarea > 0.0f)? totarea/scene->lights.size(): 1.0f;
- for(size_t i = 0; i < scene->lights.size(); i++, offset++) {
+ for(int i = 0; i < scene->lights.size(); i++, offset++) {
distribution[offset].x = totarea;
- distribution[offset].y = __int_as_float(-i-1);
+ distribution[offset].y = __int_as_float(~(int)i);
distribution[offset].z = 1.0f;
distribution[offset].w = scene->lights[i]->size;
totarea += lightarea;
@@ -229,6 +302,99 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
dscene->light_distribution.clear();
}
+void LightManager::device_update_background(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
+{
+ KernelIntegrator *kintegrator = &dscene->data.integrator;
+ Light *background_light = NULL;
+
+ /* find background light */
+ foreach(Light *light, scene->lights) {
+ if(light->type == LIGHT_BACKGROUND) {
+ background_light = light;
+ break;
+ }
+ }
+
+ /* no background light found, signal renderer to skip sampling */
+ if(!background_light) {
+ kintegrator->pdf_background_res = 0;
+ return;
+ }
+
+ progress.set_status("Updating Lights", "Importance map");
+
+ assert(kintegrator->use_direct_light);
+
+ /* get the resolution from the light's size (we stuff it in there) */
+ int res = background_light->map_resolution;
+ kintegrator->pdf_background_res = res;
+
+ assert(res > 0);
+
+ vector<float3> pixels;
+ dump_background_pixels(device, dscene, res, pixels);
+
+ if(progress.get_cancel())
+ return;
+
+ /* build row distributions and column distribution for the infinite area environment light */
+ int cdf_count = res + 1;
+ float2 *marg_cdf = dscene->light_background_marginal_cdf.resize(cdf_count);
+ float2 *cond_cdf = dscene->light_background_conditional_cdf.resize(cdf_count * cdf_count);
+
+ /* conditional CDFs (rows, U direction) */
+ for(int i = 0; i < res; i++) {
+ float sin_theta = sinf(M_PI_F * (i + 0.5f) / res);
+ float3 env_color = pixels[i * res];
+ float ave_luminamce = average(env_color);
+
+ cond_cdf[i * cdf_count].x = ave_luminamce * sin_theta;
+ cond_cdf[i * cdf_count].y = 0.0f;
+
+ for(int j = 1; j < res; j++) {
+ env_color = pixels[i * res + j];
+ ave_luminamce = average(env_color);
+
+ cond_cdf[i * cdf_count + j].x = ave_luminamce * sin_theta;
+ cond_cdf[i * cdf_count + j].y = cond_cdf[i * cdf_count + j - 1].y + cond_cdf[i * cdf_count + j - 1].x / res;
+ }
+
+ float cdf_total = cond_cdf[i * cdf_count + res - 1].y + cond_cdf[i * cdf_count + res - 1].x / res;
+
+ /* stuff the total into the brightness value for the last entry, because
+ we are going to normalize the CDFs to 0.0 to 1.0 afterwards */
+ cond_cdf[i * cdf_count + res].x = cdf_total;
+
+ if(cdf_total > 0.0f)
+ for(int j = 1; j < res; j++)
+ cond_cdf[i * cdf_count + j].y /= cdf_total;
+
+ cond_cdf[i * cdf_count + res].y = 1.0f;
+ }
+
+ /* marginal CDFs (column, V direction, sum of rows) */
+ marg_cdf[0].x = cond_cdf[res].x;
+ marg_cdf[0].y = 0.0f;
+
+ for(int i = 1; i < res; i++) {
+ marg_cdf[i].x = cond_cdf[i * cdf_count + res].x;
+ marg_cdf[i].y = marg_cdf[i - 1].y + marg_cdf[i - 1].x / res;
+ }
+
+ float cdf_total = marg_cdf[res - 1].y + marg_cdf[res - 1].x / res;
+ marg_cdf[res].x = cdf_total;
+
+ if(cdf_total > 0.0f)
+ for(int i = 1; i < res; i++)
+ marg_cdf[i].y /= cdf_total;
+
+ marg_cdf[res].y = 1.0f;
+
+ /* update device */
+ device->tex_alloc("__light_background_marginal_cdf", dscene->light_background_marginal_cdf);
+ device->tex_alloc("__light_background_conditional_cdf", dscene->light_background_conditional_cdf);
+}
+
void LightManager::device_update_points(Device *device, DeviceScene *dscene, Scene *scene)
{
if(scene->lights.size() == 0)
@@ -261,6 +427,14 @@ void LightManager::device_update_points(Device *device, DeviceScene *dscene, Sce
light_data[i*LIGHT_SIZE + 2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
light_data[i*LIGHT_SIZE + 3] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
}
+ else if(light->type == LIGHT_BACKGROUND) {
+ shader_id &= ~SHADER_AREA_LIGHT;
+
+ light_data[i*LIGHT_SIZE + 0] = make_float4(__int_as_float(light->type), 0.0f, 0.0f, 0.0f);
+ light_data[i*LIGHT_SIZE + 1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ light_data[i*LIGHT_SIZE + 2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ light_data[i*LIGHT_SIZE + 3] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ }
else if(light->type == LIGHT_AREA) {
float3 axisu = light->axisu*(light->sizeu*light->size);
float3 axisv = light->axisv*(light->sizev*light->size);
@@ -288,6 +462,9 @@ void LightManager::device_update(Device *device, DeviceScene *dscene, Scene *sce
device_update_distribution(device, dscene, scene, progress);
if(progress.get_cancel()) return;
+ device_update_background(device, dscene, scene, progress);
+ if(progress.get_cancel()) return;
+
need_update = false;
}
@@ -295,9 +472,13 @@ void LightManager::device_free(Device *device, DeviceScene *dscene)
{
device->tex_free(dscene->light_distribution);
device->tex_free(dscene->light_data);
+ device->tex_free(dscene->light_background_marginal_cdf);
+ device->tex_free(dscene->light_background_conditional_cdf);
dscene->light_distribution.clear();
dscene->light_data.clear();
+ dscene->light_background_marginal_cdf.clear();
+ dscene->light_background_conditional_cdf.clear();
}
void LightManager::tag_update(Scene *scene)
diff --git a/intern/cycles/render/light.h b/intern/cycles/render/light.h
index 19cbcb55386..0ed143f5ad1 100644
--- a/intern/cycles/render/light.h
+++ b/intern/cycles/render/light.h
@@ -46,6 +46,8 @@ public:
float3 axisv;
float sizev;
+ int map_resolution;
+
bool cast_shadow;
int shader;
@@ -68,6 +70,7 @@ public:
protected:
void device_update_points(Device *device, DeviceScene *dscene, Scene *scene);
void device_update_distribution(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
+ void device_update_background(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
};
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 5d65ce69a00..cd533f24058 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -586,6 +586,7 @@ void MeshManager::device_update_bvh(Device *device, DeviceScene *dscene, Scene *
bparams.top_level = true;
bparams.use_qbvh = scene->params.use_qbvh;
bparams.use_spatial_split = scene->params.use_bvh_spatial_split;
+ bparams.use_cache = scene->params.use_bvh_cache;
delete bvh;
bvh = BVH::create(bparams, scene->objects);
diff --git a/intern/cycles/render/mesh_displace.cpp b/intern/cycles/render/mesh_displace.cpp
index c4f3e43bfba..a6f8e3f6be8 100644
--- a/intern/cycles/render/mesh_displace.cpp
+++ b/intern/cycles/render/mesh_displace.cpp
@@ -89,7 +89,7 @@ bool MeshManager::displace(Device *device, Scene *scene, Mesh *mesh, Progress& p
return false;
/* run device task */
- device_vector<float3> d_output;
+ device_vector<float4> d_output;
d_output.resize(d_input.size());
device->mem_alloc(d_input, MEM_READ_ONLY);
@@ -106,7 +106,7 @@ bool MeshManager::displace(Device *device, Scene *scene, Mesh *mesh, Progress& p
device->task_add(task);
device->task_wait();
- device->mem_copy_from(d_output, 0, 1, d_output.size(), sizeof(float3));
+ device->mem_copy_from(d_output, 0, 1, d_output.size(), sizeof(float4));
device->mem_free(d_input);
device->mem_free(d_output);
@@ -118,7 +118,7 @@ bool MeshManager::displace(Device *device, Scene *scene, Mesh *mesh, Progress& p
done.resize(mesh->verts.size(), false);
int k = 0;
- float3 *offset = (float3*)d_output.data_pointer;
+ float4 *offset = (float4*)d_output.data_pointer;
for(size_t i = 0; i < mesh->triangles.size(); i++) {
Mesh::Triangle t = mesh->triangles[i];
@@ -130,7 +130,8 @@ bool MeshManager::displace(Device *device, Scene *scene, Mesh *mesh, Progress& p
for(int j = 0; j < 3; j++) {
if(!done[t.v[j]]) {
done[t.v[j]] = true;
- mesh->verts[t.v[j]] += offset[k++];
+ float3 off = float4_to_float3(offset[k++]);
+ mesh->verts[t.v[j]] += off;
}
}
}
diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h
index 17bd7e20129..4a5224f8a94 100644
--- a/intern/cycles/render/scene.h
+++ b/intern/cycles/render/scene.h
@@ -78,6 +78,8 @@ public:
/* lights */
device_vector<float4> light_distribution;
device_vector<float4> light_data;
+ device_vector<float2> light_background_marginal_cdf;
+ device_vector<float2> light_background_conditional_cdf;
/* shaders */
device_vector<uint4> svm_nodes;
diff --git a/intern/cycles/util/util_cache.cpp b/intern/cycles/util/util_cache.cpp
index 49a0f62cae8..44d784ba741 100644
--- a/intern/cycles/util/util_cache.cpp
+++ b/intern/cycles/util/util_cache.cpp
@@ -19,11 +19,18 @@
#include <stdio.h>
#include "util_cache.h"
+#include "util_debug.h"
#include "util_foreach.h"
+#include "util_map.h"
#include "util_md5.h"
#include "util_path.h"
#include "util_types.h"
+#define BOOST_FILESYSTEM_VERSION 2
+
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
+
CCL_NAMESPACE_BEGIN
/* CacheData */
@@ -32,6 +39,7 @@ CacheData::CacheData(const string& name_)
{
name = name_;
f = NULL;
+ have_filename = false;
}
CacheData::~CacheData()
@@ -40,24 +48,35 @@ CacheData::~CacheData()
fclose(f);
}
+const string& CacheData::get_filename()
+{
+ if(!have_filename) {
+ MD5Hash hash;
+
+ foreach(const CacheBuffer& buffer, buffers)
+ if(buffer.size)
+ hash.append((uint8_t*)buffer.data, buffer.size);
+
+ filename = name + "_" + hash.get_hex();
+ have_filename = true;
+ }
+
+ return filename;
+}
+
/* Cache */
Cache Cache::global;
-string Cache::data_filename(const CacheData& key)
+string Cache::data_filename(CacheData& key)
{
- MD5Hash hash;
-
- foreach(const CacheBuffer& buffer, key.buffers)
- hash.append((uint8_t*)buffer.data, buffer.size);
-
- string fname = key.name + "_" + hash.get_hex();
- return path_get("cache/" + fname);
+ return path_user_get(path_join("cache", key.get_filename()));
}
-void Cache::insert(const CacheData& key, const CacheData& value)
+void Cache::insert(CacheData& key, CacheData& value)
{
string filename = data_filename(key);
+ path_create_directories(filename);
FILE *f = fopen(filename.c_str(), "wb");
if(!f) {
@@ -65,17 +84,18 @@ void Cache::insert(const CacheData& key, const CacheData& value)
return;
}
- foreach(const CacheBuffer& buffer, value.buffers) {
+ foreach(CacheBuffer& buffer, value.buffers) {
if(!fwrite(&buffer.size, sizeof(buffer.size), 1, f))
fprintf(stderr, "Failed to write to file %s.\n", filename.c_str());
- if(!fwrite(buffer.data, buffer.size, 1, f))
- fprintf(stderr, "Failed to write to file %s.\n", filename.c_str());
+ if(buffer.size)
+ if(!fwrite(buffer.data, buffer.size, 1, f))
+ fprintf(stderr, "Failed to write to file %s.\n", filename.c_str());
}
fclose(f);
}
-bool Cache::lookup(const CacheData& key, CacheData& value)
+bool Cache::lookup(CacheData& key, CacheData& value)
{
string filename = data_filename(key);
FILE *f = fopen(filename.c_str(), "rb");
@@ -89,5 +109,22 @@ bool Cache::lookup(const CacheData& key, CacheData& value)
return true;
}
+void Cache::clear_except(const string& name, const set<string>& except)
+{
+ string dir = path_user_get("cache");
+
+ if(boost::filesystem::exists(dir)) {
+ boost::filesystem::directory_iterator it(dir), it_end;
+
+ for(; it != it_end; it++) {
+ string filename = it->path().filename();
+
+ if(boost::starts_with(filename, name))
+ if(except.find(filename) == except.end())
+ boost::filesystem::remove(it->path());
+ }
+ }
+}
+
CCL_NAMESPACE_END
diff --git a/intern/cycles/util/util_cache.h b/intern/cycles/util/util_cache.h
index 6e3c7c47e39..e8f111a5397 100644
--- a/intern/cycles/util/util_cache.h
+++ b/intern/cycles/util/util_cache.h
@@ -32,6 +32,7 @@
* different scenes where it may be hard to detect duplicate work.
*/
+#include "util_set.h"
#include "util_string.h"
#include "util_vector.h"
@@ -50,25 +51,25 @@ class CacheData {
public:
vector<CacheBuffer> buffers;
string name;
+ string filename;
+ bool have_filename;
FILE *f;
CacheData(const string& name = "");
~CacheData();
+ const string& get_filename();
+
template<typename T> void add(const vector<T>& data)
{
- if(data.size()) {
- CacheBuffer buffer(&data[0], data.size()*sizeof(T));
- buffers.push_back(buffer);
- }
+ CacheBuffer buffer(data.size()? &data[0]: NULL, data.size()*sizeof(T));
+ buffers.push_back(buffer);
}
template<typename T> void add(const array<T>& data)
{
- if(data.size()) {
- CacheBuffer buffer(&data[0], data.size()*sizeof(T));
- buffers.push_back(buffer);
- }
+ CacheBuffer buffer(data.size()? &data[0]: NULL, data.size()*sizeof(T));
+ buffers.push_back(buffer);
}
void add(void *data, size_t size)
@@ -85,6 +86,12 @@ public:
buffers.push_back(buffer);
}
+ void add(float& data)
+ {
+ CacheBuffer buffer(&data, sizeof(float));
+ buffers.push_back(buffer);
+ }
+
void add(size_t& data)
{
CacheBuffer buffer(&data, sizeof(size_t));
@@ -113,12 +120,30 @@ public:
void read(int& data)
{
+ size_t size;
+
+ if(!fread(&size, sizeof(size), 1, f))
+ fprintf(stderr, "Failed to read int size from cache.\n");
if(!fread(&data, sizeof(data), 1, f))
fprintf(stderr, "Failed to read int from cache.\n");
}
+ void read(float& data)
+ {
+ size_t size;
+
+ if(!fread(&size, sizeof(size), 1, f))
+ fprintf(stderr, "Failed to read float size from cache.\n");
+ if(!fread(&data, sizeof(data), 1, f))
+ fprintf(stderr, "Failed to read float from cache.\n");
+ }
+
void read(size_t& data)
{
+ size_t size;
+
+ if(!fread(&size, sizeof(size), 1, f))
+ fprintf(stderr, "Failed to read size_t size from cache.\n");
if(!fread(&data, sizeof(data), 1, f))
fprintf(stderr, "Failed to read size_t from cache.\n");
}
@@ -128,11 +153,13 @@ class Cache {
public:
static Cache global;
- void insert(const CacheData& key, const CacheData& value);
- bool lookup(const CacheData& key, CacheData& value);
+ void insert(CacheData& key, CacheData& value);
+ bool lookup(CacheData& key, CacheData& value);
+
+ void clear_except(const string& name, const set<string>& except);
protected:
- string data_filename(const CacheData& key);
+ string data_filename(CacheData& key);
};
CCL_NAMESPACE_END
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 4d2f41b48bd..3ec8d3d2fbf 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -68,13 +68,28 @@ class GHOST_IEventConsumer;
* <li> Access to the state of the mouse buttons and the keyboard.</li>
* <li> Menus for windows with events generated when they are accessed (this is
* work in progress).</li>
+ * <li> Video mode switching.</li>
+ * <li> Copy/Paste buffers.</li>
+ * <li> System paths.</li>
* </ul>
* Font management has been moved to a separate library.
*
* \section platforms Platforms
*
+ * GHOST supports the following platforms:
+ * <ul>
+ * <li> OSX Cocoa.</li>
+ * <li> OSX Carbon.</li>
+ * <li> Windows.</li>
+ * <li> X11.</li>
+ * <li> SDL1.3 (experemental).</li>
+ * <li> NULL (headless mode).</li>
+ * </ul>
+ *
* \section Building GHOST
*
+ * GHOST is not build standalone however there are tests in intern/ghost/test
+ *
* \section interface Interface
* GHOST has two programming interfaces:
* <ul>
diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp
index be5d45128f9..db4ed306dbe 100644
--- a/intern/ghost/intern/GHOST_NDOFManager.cpp
+++ b/intern/ghost/intern/GHOST_NDOFManager.cpp
@@ -137,6 +137,37 @@ static const NDOF_ButtonT SpacePilotPro_HID_map[] = {
NDOF_BUTTON_MINUS
};
+// latest HW: button-compatible with SpacePilotPro, just fewer of them
+static const NDOF_ButtonT SpaceMousePro_HID_map[] = {
+ NDOF_BUTTON_MENU,
+ NDOF_BUTTON_FIT,
+ NDOF_BUTTON_TOP,
+ NDOF_BUTTON_NONE, // left
+ NDOF_BUTTON_RIGHT,
+ NDOF_BUTTON_FRONT,
+ NDOF_BUTTON_NONE, // bottom
+ NDOF_BUTTON_NONE, // back
+ NDOF_BUTTON_ROLL_CW,
+ NDOF_BUTTON_NONE, // roll ccw
+ NDOF_BUTTON_NONE, // iso 1
+ NDOF_BUTTON_NONE, // iso 2
+ NDOF_BUTTON_1,
+ NDOF_BUTTON_2,
+ NDOF_BUTTON_3,
+ NDOF_BUTTON_4,
+ NDOF_BUTTON_NONE, // 5
+ NDOF_BUTTON_NONE, // 6
+ NDOF_BUTTON_NONE, // 7
+ NDOF_BUTTON_NONE, // 8
+ NDOF_BUTTON_NONE, // 9
+ NDOF_BUTTON_NONE, // 10
+ NDOF_BUTTON_NONE, // esc key
+ NDOF_BUTTON_NONE, // alt key
+ NDOF_BUTTON_NONE, // shift key
+ NDOF_BUTTON_NONE, // ctrl key
+ NDOF_BUTTON_ROTATE,
+};
+
/* this is the older SpacePilot (sans Pro)
* thanks to polosson for the info in this table */
static const NDOF_ButtonT SpacePilot_HID_map[] = {
@@ -210,6 +241,12 @@ bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ
m_deviceType = NDOF_SpacePilotPro;
m_buttonCount = 31;
break;
+ case 0xC62B:
+ puts("ndof: using SpaceMousePro");
+ m_deviceType = NDOF_SpaceMousePro;
+ m_buttonCount = 27;
+ // ^^ actually has 15 buttons, but their HID codes range from 0 to 26
+ break;
// -- older devices --
case 0xC625:
@@ -237,6 +274,8 @@ bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ
else {
m_buttonMask = ~(-1 << m_buttonCount);
+ // special case for SpaceMousePro? maybe...
+
#ifdef DEBUG_NDOF_BUTTONS
printf("ndof: %d buttons -> hex:%X\n", m_buttonCount, m_buttonMask);
#endif
@@ -261,6 +300,16 @@ void GHOST_NDOFManager::updateRotation(short r[3], GHOST_TUns64 time)
void GHOST_NDOFManager::sendButtonEvent(NDOF_ButtonT button, bool press, GHOST_TUns64 time, GHOST_IWindow* window)
{
+ if (button == NDOF_BUTTON_NONE) {
+ // just being exceptionally cautious...
+ // air-tight button masking and proper function key emulation
+ // should guarantee we never get to this point
+#ifdef DEBUG_NDOF_BUTTONS
+ printf("discarding NDOF_BUTTON_NONE (should not escape the NDOF manager)\n");
+#endif
+ return;
+ }
+
GHOST_EventNDOFButton* event = new GHOST_EventNDOFButton(time, window);
GHOST_TEventNDOFButtonData* data = (GHOST_TEventNDOFButtonData*) event->getData();
@@ -317,6 +366,15 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64
default: sendButtonEvent(SpacePilotPro_HID_map[button_number], press, time, window);
}
break;
+ case NDOF_SpaceMousePro:
+ switch (button_number) {
+ case 22: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break;
+ case 23: sendKeyEvent(GHOST_kKeyLeftAlt, press, time, window); break;
+ case 24: sendKeyEvent(GHOST_kKeyLeftShift, press, time, window); break;
+ case 25: sendKeyEvent(GHOST_kKeyLeftControl, press, time, window); break;
+ default: sendButtonEvent(SpaceMousePro_HID_map[button_number], press, time, window);
+ }
+ break;
case NDOF_SpacePilot:
switch (button_number) {
case 10: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break;
diff --git a/intern/ghost/intern/GHOST_NDOFManager.h b/intern/ghost/intern/GHOST_NDOFManager.h
index 34759035664..701f458ccf1 100644
--- a/intern/ghost/intern/GHOST_NDOFManager.h
+++ b/intern/ghost/intern/GHOST_NDOFManager.h
@@ -37,6 +37,7 @@ typedef enum {
NDOF_SpaceNavigator,
NDOF_SpaceExplorer,
NDOF_SpacePilotPro,
+ NDOF_SpaceMousePro,
// older devices
NDOF_SpacePilot
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 4ae87da4efe..9cae2c27e65 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -1240,26 +1240,25 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const
{
- char *buffer;
+ wchar_t *buffer;
char *temp_buff;
- if ( IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(NULL) ) {
+ if ( IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL) ) {
size_t len = 0;
- HANDLE hData = GetClipboardData( CF_TEXT );
+ HANDLE hData = GetClipboardData( CF_UNICODETEXT );
if (hData == NULL) {
CloseClipboard();
return NULL;
}
- buffer = (char*)GlobalLock( hData );
+ buffer = (wchar_t*)GlobalLock( hData );
if (!buffer) {
CloseClipboard();
return NULL;
}
- len = strlen(buffer);
- temp_buff = (char*) malloc(len+1);
- strncpy(temp_buff, buffer, len);
- temp_buff[len] = '\0';
+ len = WideCharToMultiByte(CP_UTF8, 0, buffer, -1, NULL, 0, NULL, NULL);
+ temp_buff = (char*) malloc(len);
+ WideCharToMultiByte(CP_UTF8, 0, buffer, -1, temp_buff, len, NULL, NULL);
/* Buffer mustn't be accessed after CloseClipboard
it would like accessing free-d memory */
@@ -1278,18 +1277,20 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
if (OpenClipboard(NULL)) {
HLOCAL clipbuffer;
- char *data;
+ wchar_t *data;
if (buffer) {
EmptyClipboard();
- clipbuffer = LocalAlloc(LMEM_FIXED,((strlen(buffer)+1)));
- data = (char*)GlobalLock(clipbuffer);
-
- strcpy(data, (char*)buffer);
- data[strlen(buffer)] = '\0';
+ int wlen = MultiByteToWideChar(CP_UTF8, 0, buffer, -1, NULL, 0);
+
+ clipbuffer = LocalAlloc(LMEM_FIXED, wlen * sizeof(wchar_t));
+ data = (wchar_t*)GlobalLock(clipbuffer);
+
+ MultiByteToWideChar(CP_UTF8, 0, buffer, -1, data, wlen);
+
LocalUnlock(clipbuffer);
- SetClipboardData(CF_TEXT,clipbuffer);
+ SetClipboardData(CF_UNICODETEXT,clipbuffer);
}
CloseClipboard();
} else {
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index de0cf641c2d..22c16009591 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -422,6 +422,18 @@ processEvents(
return anyProcessed;
}
+
+#ifdef WITH_X11_XINPUT
+/* set currently using tablet mode (stylus or eraser) depending on device ID */
+static void setTabletMode(GHOST_WindowX11 * window, XID deviceid)
+{
+ if(deviceid == window->GetXTablet().StylusID)
+ window->GetXTablet().CommonData.Active= GHOST_kTabletModeStylus;
+ else if(deviceid == window->GetXTablet().EraserID)
+ window->GetXTablet().CommonData.Active= GHOST_kTabletModeEraser;
+}
+#endif /* WITH_X11_XINPUT */
+
void
GHOST_SystemX11::processEvent(XEvent *xe)
{
@@ -824,6 +836,12 @@ GHOST_SystemX11::processEvent(XEvent *xe)
if(xe->type == window->GetXTablet().MotionEvent)
{
XDeviceMotionEvent* data = (XDeviceMotionEvent*)xe;
+
+ /* stroke might begin without leading ProxyIn event,
+ * this happens when window is opened when stylus is already hovering
+ * around tablet surface */
+ setTabletMode(window, data->deviceid);
+
window->GetXTablet().CommonData.Pressure=
data->axis_data[2]/((float)window->GetXTablet().PressureLevels);
@@ -837,10 +855,8 @@ GHOST_SystemX11::processEvent(XEvent *xe)
else if(xe->type == window->GetXTablet().ProxInEvent)
{
XProximityNotifyEvent* data = (XProximityNotifyEvent*)xe;
- if(data->deviceid == window->GetXTablet().StylusID)
- window->GetXTablet().CommonData.Active= GHOST_kTabletModeStylus;
- else if(data->deviceid == window->GetXTablet().EraserID)
- window->GetXTablet().CommonData.Active= GHOST_kTabletModeEraser;
+
+ setTabletMode(window, data->deviceid);
}
else if(xe->type == window->GetXTablet().ProxOutEvent)
window->GetXTablet().CommonData.Active= GHOST_kTabletModeNone;
diff --git a/intern/ghost/test/CMakeLists.txt b/intern/ghost/test/CMakeLists.txt
index f834b55b387..75f082fe834 100644
--- a/intern/ghost/test/CMakeLists.txt
+++ b/intern/ghost/test/CMakeLists.txt
@@ -35,6 +35,25 @@ endmacro()
# -----------------------------------------------------------------------------
+# Defines
+
+# set the endian define
+if(MSVC)
+ # for some reason this fails on msvc
+ add_definitions(-D__LITTLE_ENDIAN__)
+else()
+ include(TestBigEndian)
+ test_big_endian(_SYSTEM_BIG_ENDIAN)
+ if(_SYSTEM_BIG_ENDIAN)
+ add_definitions(-D__BIG_ENDIAN__)
+ else()
+ add_definitions(-D__LITTLE_ENDIAN__)
+ endif()
+ unset(_SYSTEM_BIG_ENDIAN)
+endif()
+
+
+# -----------------------------------------------------------------------------
# Libraries
# ghost
@@ -74,6 +93,7 @@ add_library(bli_lib
"../../../source/blender/blenlib/intern/fileops.c"
"../../../source/blender/blenlib/intern/rct.c"
"../../../source/blender/blenlib/intern/string.c"
+ "../../../source/blender/blenlib/intern/string_utf8.c"
"../../../source/blender/blenlib/intern/listbase.c"
"../../../source/blender/blenlib/intern/storage.c"
"../../../source/blender/blenlib/intern/path_util.c"
@@ -87,6 +107,8 @@ find_package(OpenGL REQUIRED)
find_package(Freetype REQUIRED)
+find_package(ZLIB REQUIRED)
+
include_directories(${CMAKE_SOURCE_DIR}/../)
include_directories(${OPENGL_INCLUDE_DIR})
include_directories(${FREETYPE_INCLUDE_DIRS})
@@ -151,5 +173,6 @@ target_link_libraries(multitest_c
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${FREETYPE_LIBRARY}
+ ${ZLIB_LIBRARIES}
${PLATFORM_LINKLIBS}
)
diff --git a/release/scripts/modules/addon_utils.py b/release/scripts/modules/addon_utils.py
index b64b32b3126..2b1616a0022 100644
--- a/release/scripts/modules/addon_utils.py
+++ b/release/scripts/modules/addon_utils.py
@@ -38,17 +38,17 @@ addons_fake_modules = {}
def paths():
# RELEASE SCRIPTS: official scripts distributed in Blender releases
- paths = _bpy.utils.script_paths("addons")
+ addon_paths = _bpy.utils.script_paths("addons")
# CONTRIB SCRIPTS: good for testing but not official scripts yet
# if folder addons_contrib/ exists, scripts in there will be loaded too
- paths += _bpy.utils.script_paths("addons_contrib")
+ addon_paths += _bpy.utils.script_paths("addons_contrib")
# EXTERN SCRIPTS: external projects scripts
# if folder addons_extern/ exists, scripts in there will be loaded too
- paths += _bpy.utils.script_paths("addons_extern")
+ addon_paths += _bpy.utils.script_paths("addons_extern")
- return paths
+ return addon_paths
def modules(module_cache):
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py
index 442d257b237..d5abcb03164 100644
--- a/release/scripts/modules/bpy/utils.py
+++ b/release/scripts/modules/bpy/utils.py
@@ -281,10 +281,7 @@ def script_paths(subdir=None, user_pref=True, check_all=False):
prefs = _bpy.context.user_preferences
# add user scripts dir
- if user_pref:
- user_script_path = prefs.filepaths.script_directory
- else:
- user_script_path = None
+ user_script = prefs.filepaths.script_directory if user_pref else None
if check_all:
# all possible paths
@@ -294,7 +291,7 @@ def script_paths(subdir=None, user_pref=True, check_all=False):
# only paths blender uses
base_paths = _bpy_script_paths()
- for path in base_paths + (user_script_path, ):
+ for path in base_paths + (user_script, ):
if path:
path = _os.path.normpath(path)
if path not in scripts and _os.path.isdir(path):
@@ -303,13 +300,13 @@ def script_paths(subdir=None, user_pref=True, check_all=False):
if subdir is None:
return scripts
- script_paths = []
+ scripts_subdir = []
for path in scripts:
path_subdir = _os.path.join(path, subdir)
if _os.path.isdir(path_subdir):
- script_paths.append(path_subdir)
+ scripts_subdir.append(path_subdir)
- return script_paths
+ return scripts_subdir
def refresh_script_paths():
@@ -464,7 +461,7 @@ def keyconfig_set(filepath):
keyconfigs.active = kc_new
-def user_resource(type, path="", create=False):
+def user_resource(resource_type, path="", create=False):
"""
Return a user resource path (normally from the users home directory).
@@ -479,7 +476,7 @@ def user_resource(type, path="", create=False):
:rtype: string
"""
- target_path = _user_resource(type, path)
+ target_path = _user_resource(resource_type, path)
if create:
# should always be true.
diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils.py b/release/scripts/modules/bpy_extras/keyconfig_utils.py
index a9eb86aaf79..20b0669e531 100644
--- a/release/scripts/modules/bpy_extras/keyconfig_utils.py
+++ b/release/scripts/modules/bpy_extras/keyconfig_utils.py
@@ -70,6 +70,7 @@ KM_HIERARCHY = [
('Image', 'IMAGE_EDITOR', 'WINDOW', [
('UV Editor', 'EMPTY', 'WINDOW', []), # image (reverse order, UVEdit before Image
('Image Paint', 'EMPTY', 'WINDOW', []), # image and view3d
+ ('UV Sculpt', 'EMPTY', 'WINDOW', []),
('Image Generic', 'IMAGE_EDITOR', 'WINDOW', [])
]),
diff --git a/release/scripts/modules/rna_xml.py b/release/scripts/modules/rna_xml.py
index 634c74178fa..c39d904bf08 100644
--- a/release/scripts/modules/rna_xml.py
+++ b/release/scripts/modules/rna_xml.py
@@ -141,7 +141,7 @@ def rna2xml(fw=print_ln,
return number_to_str(s, subsubvalue_type)
else:
return " ".join([str_recursive(si) for si in s])
-
+
array_value = " ".join(str_recursive(v) for v in subvalue_rna)
node_attrs.append("%s=\"%s\"" % (prop, array_value))
@@ -308,13 +308,13 @@ def xml2rna(root_xml,
rna2xml_node(root_xml, root_rna)
-
# -----------------------------------------------------------------------------
# Utility function used by presets.
# The idea is you can run a preset like a script with a few args.
#
# This roughly matches the operator 'bpy.ops.script.python_file_run'
+
def _get_context_val(context, path):
path_full = "context." + path
try:
@@ -328,6 +328,7 @@ def _get_context_val(context, path):
return value
+
def xml_file_run(context, filepath, rna_map):
import xml.dom.minidom
diff --git a/release/scripts/startup/bl_operators/clip.py b/release/scripts/startup/bl_operators/clip.py
index 28628a48a0b..ac82ffbf48f 100644
--- a/release/scripts/startup/bl_operators/clip.py
+++ b/release/scripts/startup/bl_operators/clip.py
@@ -76,6 +76,7 @@ def CLIP_camera_for_clip(context, clip):
return camera
+
def CLIP_track_view_selected(sc, track):
if track.select_anchor:
return True
@@ -118,7 +119,7 @@ class CLIP_OT_track_to_empty(Operator):
constraint.track = track.name
constraint.use_3d_position = False
constraint.object = tracking_object.name
- constraint.camera = CLIP_camera_for_clip(context, clip);
+ constraint.camera = CLIP_camera_for_clip(context, clip)
def execute(self, context):
sc = context.space_data
@@ -127,7 +128,7 @@ class CLIP_OT_track_to_empty(Operator):
for track in tracking_object.tracks:
if CLIP_track_view_selected(sc, track):
- self._link_track(context, clip, tracking_object ,track)
+ self._link_track(context, clip, tracking_object, track)
return {'FINISHED'}
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 970245fbf87..e9cb8af1cbd 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -166,9 +166,10 @@ class BRUSH_OT_active_index_set(Operator):
if attr is None:
return {'CANCELLED'}
+ toolsettings = context.tool_settings
for i, brush in enumerate((cur for cur in bpy.data.brushes if getattr(cur, attr))):
if i == self.index:
- getattr(context.tool_settings, self.mode).brush = brush
+ getattr(toolsettings, self.mode).brush = brush
return {'FINISHED'}
return {'CANCELLED'}
@@ -1768,4 +1769,3 @@ class WM_OT_addon_expand(Operator):
info = addon_utils.module_bl_info(mod)
info["show_expanded"] = not info["show_expanded"]
return {'FINISHED'}
-
diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index 6aa08a7f50d..84049e9f1fe 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -86,7 +86,7 @@ def register():
# space_userprefs.py
from bpy.props import StringProperty, EnumProperty
- WindowManager = bpy.types.WindowManager
+ from bpy.types import WindowManager
def addon_filter_items(self, context):
import addon_utils
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 9be3b00e4cf..766daba58b8 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -814,12 +814,13 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
def REMESH(self, layout, ob, md):
layout.prop(md, "mode")
-
- layout.prop(md, "octree_depth")
- layout.prop(md, "scale")
+
row = layout.row()
- row.active = md.mode == "SHARP"
- row.prop(md, "sharpness")
+ row.prop(md, "octree_depth")
+ row.prop(md, "scale")
+
+ if md.mode == "SHARP":
+ layout.prop(md, "sharpness")
layout.prop(md, "remove_disconnected_pieces")
row = layout.row()
diff --git a/release/scripts/startup/bl_ui/properties_game.py b/release/scripts/startup/bl_ui/properties_game.py
index f0f964f9a31..ee5702e324e 100644
--- a/release/scripts/startup/bl_ui/properties_game.py
+++ b/release/scripts/startup/bl_ui/properties_game.py
@@ -244,7 +244,7 @@ class RenderButtonsPanel():
return (rd.engine in cls.COMPAT_ENGINES)
-class RENDER_PT_embedded(RenderButtonsPanel, bpy.types.Panel):
+class RENDER_PT_embedded(RenderButtonsPanel, Panel):
bl_label = "Embedded Player"
COMPAT_ENGINES = {'BLENDER_GAME'}
@@ -287,7 +287,7 @@ class RENDER_PT_game_player(RenderButtonsPanel, Panel):
col = row.column()
col.prop(gs, "use_desktop")
col.active = gs.show_fullscreen
-
+
col = layout.column()
col.label(text="Quality:")
col.prop(gs, "samples")
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
new file mode 100644
index 00000000000..25ea85a9a6a
--- /dev/null
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -0,0 +1,61 @@
+# ##### 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.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+
+class UnifiedPaintPanel():
+ # subclass must set
+ # bl_space_type = 'IMAGE_EDITOR'
+ # bl_region_type = 'UI'
+
+ @staticmethod
+ def paint_settings(context):
+ toolsettings = context.tool_settings
+
+ if context.sculpt_object:
+ return toolsettings.sculpt
+ elif context.vertex_paint_object:
+ return toolsettings.vertex_paint
+ elif context.weight_paint_object:
+ return toolsettings.weight_paint
+ elif context.image_paint_object:
+ return toolsettings.image_paint
+ elif context.particle_edit_object:
+ return toolsettings.particle_edit
+
+ return None
+
+ @staticmethod
+ def unified_paint_settings(parent, context):
+ ups = context.tool_settings.unified_paint_settings
+ parent.label(text="Unified Settings:")
+ parent.prop(ups, "use_unified_size", text="Size")
+ parent.prop(ups, "use_unified_strength", text="Strength")
+
+ @staticmethod
+ def prop_unified_size(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
+ ups = context.tool_settings.unified_paint_settings
+ ptr = ups if ups.use_unified_size else brush
+ parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
+
+ @staticmethod
+ def prop_unified_strength(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
+ ups = context.tool_settings.unified_paint_settings
+ ptr = ups if ups.use_unified_strength else brush
+ parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
diff --git a/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py b/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
index 3797d7f363c..e6801f00fce 100644
--- a/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
+++ b/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
@@ -137,11 +137,14 @@ class PHYSICS_PT_dp_advanced_canvas(PhysicButtonsPanel, Panel):
# dissolve
if surface_type == 'PAINT':
split = layout.split(percentage=0.35)
- split.label(text="Wetmap drying:")
+ split.prop(surface, "use_drying", text="Dry:")
col = split.column()
+ col.active = surface.use_drying
split = col.split(percentage=0.7)
- split.prop(surface, "dry_speed", text="Time")
+ col = split.column(align=True)
+ col.prop(surface, "dry_speed", text="Time")
+ col.prop(surface, "color_dry_threshold")
split.prop(surface, "use_dry_log", text="Slow")
if surface_type != 'WAVE':
@@ -179,7 +182,10 @@ class PHYSICS_PT_dp_advanced_canvas(PhysicButtonsPanel, Panel):
col.prop(surface, "wave_spring")
layout.separator()
- layout.prop(surface, "brush_group", text="Brush Group")
+ layout.prop(surface, "brush_group")
+ row = layout.row()
+ row.prop(surface, "brush_influence_scale")
+ row.prop(surface, "brush_radius_scale")
class PHYSICS_PT_dp_canvas_output(PhysicButtonsPanel, Panel):
@@ -406,14 +412,14 @@ class PHYSICS_PT_dp_brush_source(PhysicButtonsPanel, Panel):
col.prop(brush, "paint_distance", text="Paint Distance")
split = layout.row().split(percentage=0.4)
sub = split.column()
- if brush.paint_source == 'DISTANCE':
+ if brush.paint_source in {'DISTANCE', 'VOLUME_DISTANCE'}:
sub.prop(brush, "use_proximity_project")
- elif brush.paint_source == 'VOLUME_DISTANCE':
+ if brush.paint_source == 'VOLUME_DISTANCE':
sub.prop(brush, "invert_proximity")
sub.prop(brush, "use_negative_volume")
sub = split.column()
- if brush.paint_source == 'DISTANCE':
+ if brush.paint_source in {'DISTANCE', 'VOLUME_DISTANCE'}:
column = sub.column()
column.active = brush.use_proximity_project
column.prop(brush, "ray_direction")
diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index e18375229f1..72b41cca62c 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -963,9 +963,9 @@ class RENDER_PT_stamp(RenderButtonsPanel, Panel):
rd = context.scene.render
layout.active = rd.use_stamp
-
+
layout.prop(rd, "stamp_font_size", text="Font Size")
-
+
row = layout.row()
row.column().prop(rd, "stamp_foreground", slider=True)
row.column().prop(rd, "stamp_background", slider=True)
@@ -978,7 +978,7 @@ class RENDER_PT_stamp(RenderButtonsPanel, Panel):
col.prop(rd, "use_stamp_render_time", text="RenderTime")
col.prop(rd, "use_stamp_frame", text="Frame")
col.prop(rd, "use_stamp_scene", text="Scene")
-
+
col = split.column()
col.prop(rd, "use_stamp_camera", text="Camera")
col.prop(rd, "use_stamp_lens", text="Lens")
diff --git a/release/scripts/startup/bl_ui/properties_texture.py b/release/scripts/startup/bl_ui/properties_texture.py
index c7f94bb4a3d..6e54bdde024 100644
--- a/release/scripts/startup/bl_ui/properties_texture.py
+++ b/release/scripts/startup/bl_ui/properties_texture.py
@@ -19,6 +19,14 @@
# <pep8 compliant>
import bpy
from bpy.types import Menu, Panel
+
+from bpy.types import (Brush,
+ Lamp,
+ Material,
+ ParticleSettings,
+ Texture,
+ World)
+
from rna_prop_ui import PropertyPanel
@@ -91,7 +99,7 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel, Panel):
engine = context.scene.render.engine
if not (hasattr(context, "texture_slot") or hasattr(context, "texture_node")):
return False
- return ((context.material or context.world or context.lamp or context.brush or context.texture or context.particle_system or isinstance(context.space_data.pin_id, bpy.types.ParticleSettings))
+ return ((context.material or context.world or context.lamp or context.brush or context.texture or context.particle_system or isinstance(context.space_data.pin_id, ParticleSettings))
and (engine in cls.COMPAT_ENGINES))
def draw(self, context):
@@ -103,14 +111,14 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel, Panel):
idblock = context_tex_datablock(context)
pin_id = space.pin_id
- if space.use_pin_id and not isinstance(pin_id, bpy.types.Texture):
+ if space.use_pin_id and not isinstance(pin_id, Texture):
idblock = pin_id
pin_id = None
if not space.use_pin_id:
layout.prop(space, "texture_context", expand=True)
- tex_collection = (pin_id is None) and (node is None) and (not isinstance(idblock, bpy.types.Brush))
+ tex_collection = (pin_id is None) and (node is None) and (not isinstance(idblock, Brush))
if tex_collection:
row = layout.row()
@@ -413,7 +421,7 @@ class TEXTURE_PT_image_sampling(TextureTypePanel, Panel):
col = split.column()
#Only for Material based textures, not for Lamp/World...
- if slot and isinstance(idblock, bpy.types.Material):
+ if slot and isinstance(idblock, Material):
col.prop(tex, "use_normal_map")
row = col.row()
row.active = tex.use_normal_map
@@ -801,7 +809,7 @@ class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
@classmethod
def poll(cls, context):
idblock = context_tex_datablock(context)
- if isinstance(idblock, bpy.types.Brush) and not context.sculpt_object:
+ if isinstance(idblock, Brush) and not context.sculpt_object:
return False
if not getattr(context, "texture_slot", None):
@@ -818,7 +826,7 @@ class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
tex = context.texture_slot
# textype = context.texture
- if not isinstance(idblock, bpy.types.Brush):
+ if not isinstance(idblock, Brush):
split = layout.split(percentage=0.3)
col = split.column()
col.label(text="Coordinates:")
@@ -847,7 +855,7 @@ class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
split.label(text="Object:")
split.prop(tex, "object", text="")
- if isinstance(idblock, bpy.types.Brush):
+ if isinstance(idblock, Brush):
if context.sculpt_object:
layout.label(text="Brush Mapping:")
layout.prop(tex, "map_mode", expand=True)
@@ -856,7 +864,7 @@ class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
row.active = tex.map_mode in {'FIXED', 'TILED'}
row.prop(tex, "angle")
else:
- if isinstance(idblock, bpy.types.Material):
+ if isinstance(idblock, Material):
split = layout.split(percentage=0.3)
split.label(text="Projection:")
split.prop(tex, "mapping", text="")
@@ -889,7 +897,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
@classmethod
def poll(cls, context):
idblock = context_tex_datablock(context)
- if isinstance(idblock, bpy.types.Brush):
+ if isinstance(idblock, Brush):
return False
if not getattr(context, "texture_slot", None):
@@ -915,7 +923,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
sub.prop(tex, factor, text=name, slider=True)
return sub # XXX, temp. use_map_normal needs to override.
- if isinstance(idblock, bpy.types.Material):
+ if isinstance(idblock, Material):
if idblock.type in {'SURFACE', 'WIRE'}:
split = layout.split()
@@ -978,7 +986,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
factor_but(col, "use_map_color_transmission", "transmission_color_factor", "Transmission Color")
factor_but(col, "use_map_color_reflection", "reflection_color_factor", "Reflection Color")
- elif isinstance(idblock, bpy.types.Lamp):
+ elif isinstance(idblock, Lamp):
split = layout.split()
col = split.column()
@@ -987,7 +995,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
col = split.column()
factor_but(col, "use_map_shadow", "shadow_factor", "Shadow")
- elif isinstance(idblock, bpy.types.World):
+ elif isinstance(idblock, World):
split = layout.split()
col = split.column()
@@ -997,7 +1005,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
col = split.column()
factor_but(col, "use_map_zenith_up", "zenith_up_factor", "Zenith Up")
factor_but(col, "use_map_zenith_down", "zenith_down_factor", "Zenith Down")
- elif isinstance(idblock, bpy.types.ParticleSettings):
+ elif isinstance(idblock, ParticleSettings):
split = layout.split()
col = split.column()
@@ -1028,7 +1036,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
layout.separator()
- if not isinstance(idblock, bpy.types.ParticleSettings):
+ if not isinstance(idblock, ParticleSettings):
split = layout.split()
col = split.column()
@@ -1041,10 +1049,10 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
col.prop(tex, "invert", text="Negative")
col.prop(tex, "use_stencil")
- if isinstance(idblock, bpy.types.Material) or isinstance(idblock, bpy.types.World):
+ if isinstance(idblock, Material) or isinstance(idblock, World):
col.prop(tex, "default_value", text="DVar", slider=True)
- if isinstance(idblock, bpy.types.Material):
+ if isinstance(idblock, Material):
layout.label(text="Bump Mapping:")
# only show bump settings if activated but not for normal-map images
@@ -1063,7 +1071,7 @@ class TEXTURE_PT_influence(TextureSlotPanel, Panel):
class TEXTURE_PT_custom_props(TextureButtonsPanel, PropertyPanel, Panel):
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
_context_path = "texture"
- _property_type = bpy.types.Texture
+ _property_type = Texture
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py
index 0cf3a921167..55c10a56015 100644
--- a/release/scripts/startup/bl_ui/space_clip.py
+++ b/release/scripts/startup/bl_ui/space_clip.py
@@ -117,7 +117,7 @@ class CLIP_PT_tools_marker(Panel):
if settings.show_default_expanded:
col = box.column()
row = col.row(align=True)
- label = bpy.types.CLIP_MT_tracking_settings_presets.bl_label
+ label = CLIP_MT_tracking_settings_presets.bl_label
row.menu('CLIP_MT_tracking_settings_presets', text=label)
row.operator("clip.tracking_settings_preset_add",
text="", icon='ZOOMIN')
@@ -162,22 +162,25 @@ class CLIP_PT_tools_tracking(Panel):
def draw(self, context):
layout = self.layout
- # clip = context.space_data.clip # UNUSED
row = layout.row(align=True)
- row.operator("clip.track_markers", text="", icon='FRAME_PREV').backwards = True
+ props = row.operator("clip.track_markers", text="", icon='FRAME_PREV')
+ props.backwards = True
props = row.operator("clip.track_markers", text="",
icon='PLAY_REVERSE')
props.backwards = True
props.sequence = True
- row.operator("clip.track_markers", text="", icon='PLAY').sequence = True
+ props = row.operator("clip.track_markers", text="", icon='PLAY')
+ props.sequence = True
row.operator("clip.track_markers", text="", icon='FRAME_NEXT')
col = layout.column(align=True)
- col.operator("clip.clear_track_path", text="Clear After").action = 'REMAINED'
+ props = col.operator("clip.clear_track_path", text="Clear After")
+ props.action = 'REMAINED'
- col.operator("clip.clear_track_path", text="Clear Before").action = 'UPTO'
+ props = col.operator("clip.clear_track_path", text="Clear Before")
+ props.action = 'UPTO'
col.operator("clip.clear_track_path", text="Clear").action = 'ALL'
layout.operator("clip.join_tracks", text="Join")
@@ -371,7 +374,7 @@ class CLIP_PT_objects(Panel):
def draw(self, context):
layout = self.layout
-
+
sc = context.space_data
tracking = sc.clip.tracking
@@ -478,7 +481,8 @@ class CLIP_PT_tracking_camera(Panel):
label = bpy.types.CLIP_MT_camera_presets.bl_label
row.menu('CLIP_MT_camera_presets', text=label)
row.operator("clip.camera_preset_add", text="", icon='ZOOMIN')
- row.operator("clip.camera_preset_add", text="", icon='ZOOMOUT').remove_active = True
+ props = row.operator("clip.camera_preset_add", text="", icon='ZOOMOUT')
+ props.remove_active = True
row = layout.row(align=True)
sub = row.split(percentage=0.65)
@@ -942,7 +946,8 @@ class CLIP_MT_select(Menu):
layout.separator()
- layout.operator("clip.select_all", text="Select/Deselect all").action = 'TOGGLE'
+ props = layout.operator("clip.select_all", text="Select/Deselect all")
+ props.action = 'TOGGLE'
layout.operator("clip.select_all", text="Inverse").action = 'INVERT'
layout.menu("CLIP_MT_select_grouped")
@@ -967,8 +972,12 @@ class CLIP_MT_tracking_specials(Menu):
def draw(self, context):
layout = self.layout
- layout.operator("clip.disable_markers", text="Enable Markers").action = 'ENABLE'
- layout.operator("clip.disable_markers", text="Disable markers").action = 'DISABLE'
+ props = layout.operator("clip.disable_markers",
+ text="Enable Markers")
+ props.action = 'ENABLE'
+
+ props = layout.operator("clip.disable_markers", text="Disable markers")
+ props.action = 'DISABLE'
layout.separator()
layout.operator("clip.set_origin")
@@ -990,7 +999,7 @@ class CLIP_MT_camera_presets(Menu):
bl_label = "Camera Presets"
preset_subdir = "tracking_camera"
preset_operator = "script.execute_preset"
- draw = bpy.types.Menu.draw_preset
+ draw = Menu.draw_preset
class CLIP_MT_track_color_presets(Menu):
@@ -998,7 +1007,7 @@ class CLIP_MT_track_color_presets(Menu):
bl_label = "Color Presets"
preset_subdir = "tracking_track_color"
preset_operator = "script.execute_preset"
- draw = bpy.types.Menu.draw_preset
+ draw = Menu.draw_preset
class CLIP_MT_tracking_settings_presets(Menu):
@@ -1006,7 +1015,7 @@ class CLIP_MT_tracking_settings_presets(Menu):
bl_label = "Tracking Presets"
preset_subdir = "tracking_settings"
preset_operator = "script.execute_preset"
- draw = bpy.types.Menu.draw_preset
+ draw = Menu.draw_preset
class CLIP_MT_track_color_specials(Menu):
diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index ef0e55d74e4..aabf86c6c18 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -19,6 +19,11 @@
# <pep8 compliant>
import bpy
from bpy.types import Header, Menu, Panel
+from .properties_paint_common import UnifiedPaintPanel
+
+class ImagePaintPanel(UnifiedPaintPanel):
+ bl_space_type = 'IMAGE_EDITOR'
+ bl_region_type = 'UI'
class BrushButtonsPanel():
@@ -52,7 +57,8 @@ class IMAGE_MT_view(Menu):
layout.prop(sima, "use_realtime_update")
if show_uvedit:
layout.prop(toolsettings, "show_uv_local_view")
- layout.prop(uv, "show_other_objects")
+
+ layout.prop(uv, "show_other_objects")
layout.separator()
@@ -146,9 +152,11 @@ class IMAGE_MT_image(Menu):
if ima.source in {'FILE', 'GENERATED'} and ima.type != 'OPEN_EXR_MULTILAYER':
layout.operator("image.pack", text="Pack As PNG").as_png = True
- layout.separator()
+ if not context.tool_settings.use_uv_sculpt:
+ layout.separator()
+ layout.prop(sima, "use_image_paint")
- layout.prop(sima, "use_image_paint")
+ layout.separator()
class IMAGE_MT_image_invert(Menu):
@@ -256,6 +264,10 @@ class IMAGE_MT_uvs(Menu):
layout.separator()
+ layout.prop(toolsettings, "use_uv_sculpt")
+
+ layout.separator()
+
layout.prop(uv, "use_live_unwrap")
layout.operator("uv.unwrap")
layout.operator("uv.pin", text="Unpin").clear = True
@@ -267,6 +279,8 @@ class IMAGE_MT_uvs(Menu):
layout.operator("uv.average_islands_scale")
layout.operator("uv.minimize_stretch")
layout.operator("uv.stitch")
+ layout.operator("uv.mark_seam")
+ layout.operator("uv.seams_from_islands")
layout.operator("mesh.faces_mirror_uv")
layout.separator()
@@ -632,7 +646,7 @@ class IMAGE_PT_view_properties(Panel):
sub.row().prop(uvedit, "draw_stretch_type", expand=True)
-class IMAGE_PT_paint(Panel):
+class IMAGE_PT_paint(Panel, ImagePaintPanel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
bl_label = "Paint"
@@ -657,13 +671,13 @@ class IMAGE_PT_paint(Panel):
col.prop(brush, "color", text="")
row = col.row(align=True)
- row.prop(brush, "size", slider=True)
- row.prop(brush, "use_pressure_size", toggle=True, text="")
+ self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
+ self.prop_unified_size(row, context, brush, "use_pressure_size")
row = col.row(align=True)
- row.prop(brush, "strength", slider=True)
- row.prop(brush, "use_pressure_strength", toggle=True, text="")
-
+ self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
+ self.prop_unified_strength(row, context, brush, "use_pressure_strength")
+
row = col.row(align=True)
row.prop(brush, "jitter", slider=True)
row.prop(brush, "use_pressure_jitter", toggle=True, text="")
@@ -697,8 +711,8 @@ class IMAGE_PT_tools_brush_tool(BrushButtonsPanel, Panel):
def draw(self, context):
layout = self.layout
- settings = context.tool_settings.image_paint
- brush = settings.brush
+ toolsettings = context.tool_settings.image_paint
+ brush = toolsettings.brush
layout.prop(brush, "image_tool", text="")
@@ -753,5 +767,80 @@ class IMAGE_PT_paint_curve(BrushButtonsPanel, Panel):
row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE'
row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
+
+class IMAGE_UV_sculpt_curve(Panel):
+ bl_space_type = 'IMAGE_EDITOR'
+ bl_region_type = 'UI'
+ bl_label = "UV Sculpt Curve"
+ bl_options = {'DEFAULT_CLOSED'}
+
+ @classmethod
+ def poll(cls, context):
+ sima = context.space_data
+ toolsettings = context.tool_settings.image_paint
+ return sima.show_uvedit and context.tool_settings.use_uv_sculpt and not (sima.show_paint and toolsettings.brush)
+
+ def draw(self, context):
+ layout = self.layout
+
+ toolsettings = context.tool_settings
+ uvsculpt = toolsettings.uv_sculpt
+ brush = uvsculpt.brush
+
+ layout.template_curve_mapping(brush, "curve")
+
+ row = layout.row(align=True)
+ row.operator("brush.curve_preset", icon="SMOOTHCURVE", text="").shape = 'SMOOTH'
+ row.operator("brush.curve_preset", icon="SPHERECURVE", text="").shape = 'ROUND'
+ row.operator("brush.curve_preset", icon="ROOTCURVE", text="").shape = 'ROOT'
+ row.operator("brush.curve_preset", icon="SHARPCURVE", text="").shape = 'SHARP'
+ row.operator("brush.curve_preset", icon="LINCURVE", text="").shape = 'LINE'
+ row.operator("brush.curve_preset", icon="NOCURVE", text="").shape = 'MAX'
+
+
+class IMAGE_UV_sculpt(Panel, ImagePaintPanel):
+ bl_space_type = 'IMAGE_EDITOR'
+ bl_region_type = 'UI'
+ bl_label = "UV Sculpt"
+
+ @classmethod
+ def poll(cls, context):
+ sima = context.space_data
+ toolsettings = context.tool_settings.image_paint
+ return sima.show_uvedit and context.tool_settings.use_uv_sculpt and not (sima.show_paint and toolsettings.brush)
+
+ def draw(self, context):
+ layout = self.layout
+
+ toolsettings = context.tool_settings
+ uvsculpt = toolsettings.uv_sculpt
+ brush = uvsculpt.brush
+
+ if brush:
+ col = layout.column()
+
+ row = col.row(align=True)
+ self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
+ self.prop_unified_size(row, context, brush, "use_pressure_size")
+
+ row = col.row(align=True)
+ self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
+ self.prop_unified_strength(row, context, brush, "use_pressure_strength")
+
+ split = layout.split()
+ col = split.column()
+
+ col.prop(toolsettings, "uv_sculpt_lock_borders")
+ col.prop(toolsettings, "uv_sculpt_all_islands")
+
+ split = layout.split()
+ col = split.column()
+
+ col.prop(toolsettings, "uv_sculpt_tool")
+
+ if toolsettings.uv_sculpt_tool == 'RELAX':
+ col.prop(toolsettings, "uv_relax_method")
+
+
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
diff --git a/release/scripts/startup/bl_ui/space_time.py b/release/scripts/startup/bl_ui/space_time.py
index bb0e8cfdae5..7720fddb084 100644
--- a/release/scripts/startup/bl_ui/space_time.py
+++ b/release/scripts/startup/bl_ui/space_time.py
@@ -28,7 +28,7 @@ class TIME_HT_header(Header):
layout = self.layout
scene = context.scene
- tools = context.tool_settings
+ toolsettings = context.tool_settings
screen = context.screen
row = layout.row(align=True)
@@ -80,11 +80,11 @@ class TIME_HT_header(Header):
layout.separator()
row = layout.row(align=True)
- row.prop(tools, "use_keyframe_insert_auto", text="", toggle=True)
- row.prop(tools, "use_keyframe_insert_keyingset", text="", toggle=True)
- if screen.is_animation_playing and tools.use_keyframe_insert_auto:
+ row.prop(toolsettings, "use_keyframe_insert_auto", text="", toggle=True)
+ row.prop(toolsettings, "use_keyframe_insert_keyingset", text="", toggle=True)
+ if screen.is_animation_playing and toolsettings.use_keyframe_insert_auto:
subsub = row.row()
- subsub.prop(tools, "use_record_with_nla", toggle=True)
+ subsub.prop(toolsettings, "use_record_with_nla", toggle=True)
row = layout.row(align=True)
row.prop_search(scene.keying_sets_all, "active", scene, "keying_sets_all", text="")
@@ -193,10 +193,10 @@ class TIME_MT_autokey(Menu):
def draw(self, context):
layout = self.layout
- tools = context.tool_settings
+ toolsettings = context.tool_settings
- layout.prop_enum(tools, "auto_keying_mode", 'ADD_REPLACE_KEYS')
- layout.prop_enum(tools, "auto_keying_mode", 'REPLACE_KEYS')
+ layout.prop_enum(toolsettings, "auto_keying_mode", 'ADD_REPLACE_KEYS')
+ layout.prop_enum(toolsettings, "auto_keying_mode", 'REPLACE_KEYS')
def marker_menu_generic(layout):
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 98dd7802f71..8a2dff8f050 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -425,6 +425,7 @@ class USERPREF_PT_system(Panel):
col.label(text="OpenGL:")
col.prop(system, "gl_clip_alpha", slider=True)
col.prop(system, "use_mipmaps")
+ col.prop(system, "use_16bit_textures")
col.label(text="Anisotropic Filtering")
col.prop(system, "anisotropic_filter", text="")
col.prop(system, "use_vertex_buffer_objects")
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index b06428ef39e..5e6edfed052 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -761,7 +761,7 @@ class VIEW3D_MT_object_clear(Menu):
layout.operator("object.location_clear", text="Location")
layout.operator("object.rotation_clear", text="Rotation")
layout.operator("object.scale_clear", text="Scale")
- layout ("object.origin_clear", text="Origin")
+ layout.operator("object.origin_clear", text="Origin")
class VIEW3D_MT_object_specials(Menu):
@@ -1110,9 +1110,9 @@ class VIEW3D_MT_sculpt(Menu):
def draw(self, context):
layout = self.layout
- tool_settings = context.tool_settings
- sculpt = tool_settings.sculpt
- brush = tool_settings.sculpt.brush
+ toolsettings = context.tool_settings
+ sculpt = toolsettings.sculpt
+ brush = toolsettings.sculpt.brush
layout.operator("ed.undo")
layout.operator("ed.redo")
@@ -1148,8 +1148,8 @@ class VIEW3D_MT_sculpt(Menu):
layout.prop(sculpt, "show_brush")
# TODO, make available from paint menu!
- layout.prop(tool_settings, "sculpt_paint_use_unified_size", text="Unify Size")
- layout.prop(tool_settings, "sculpt_paint_use_unified_strength", text="Unify Strength")
+ layout.prop(toolsettings, "sculpt_paint_use_unified_size", text="Unify Size")
+ layout.prop(toolsettings, "sculpt_paint_use_unified_strength", text="Unify Strength")
# ********** Particle menu **********
@@ -1453,7 +1453,7 @@ class VIEW3D_MT_edit_mesh(Menu):
def draw(self, context):
layout = self.layout
- settings = context.tool_settings
+ toolsettings = context.tool_settings
layout.operator("ed.undo")
layout.operator("ed.redo")
@@ -1485,9 +1485,9 @@ class VIEW3D_MT_edit_mesh(Menu):
layout.separator()
- layout.prop(settings, "use_mesh_automerge")
- layout.prop_menu_enum(settings, "proportional_edit")
- layout.prop_menu_enum(settings, "proportional_edit_falloff")
+ layout.prop(toolsettings, "use_mesh_automerge")
+ layout.prop_menu_enum(toolsettings, "proportional_edit")
+ layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
layout.separator()
@@ -1728,7 +1728,7 @@ class VIEW3D_MT_edit_mesh_showhide(ShowHideMenu, Menu):
def draw_curve(self, context):
layout = self.layout
- settings = context.tool_settings
+ toolsettings = context.tool_settings
layout.menu("VIEW3D_MT_transform")
layout.menu("VIEW3D_MT_mirror")
@@ -1750,8 +1750,8 @@ def draw_curve(self, context):
layout.separator()
- layout.prop_menu_enum(settings, "proportional_edit")
- layout.prop_menu_enum(settings, "proportional_edit_falloff")
+ layout.prop_menu_enum(toolsettings, "proportional_edit")
+ layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
layout.separator()
@@ -1880,7 +1880,7 @@ class VIEW3D_MT_edit_meta(Menu):
def draw(self, context):
layout = self.layout
- settings = context.tool_settings
+ toolsettings = context.tool_settings
layout.operator("ed.undo")
layout.operator("ed.redo")
@@ -1899,8 +1899,8 @@ class VIEW3D_MT_edit_meta(Menu):
layout.separator()
- layout.prop_menu_enum(settings, "proportional_edit")
- layout.prop_menu_enum(settings, "proportional_edit_falloff")
+ layout.prop_menu_enum(toolsettings, "proportional_edit")
+ layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
layout.separator()
@@ -1924,7 +1924,7 @@ class VIEW3D_MT_edit_lattice(Menu):
def draw(self, context):
layout = self.layout
- settings = context.tool_settings
+ toolsettings = context.tool_settings
layout.menu("VIEW3D_MT_transform")
layout.menu("VIEW3D_MT_mirror")
@@ -1936,8 +1936,8 @@ class VIEW3D_MT_edit_lattice(Menu):
layout.separator()
- layout.prop_menu_enum(settings, "proportional_edit")
- layout.prop_menu_enum(settings, "proportional_edit_falloff")
+ layout.prop_menu_enum(toolsettings, "proportional_edit")
+ layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
class VIEW3D_MT_edit_armature(Menu):
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 248452a0e8c..ff482e7cb74 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -19,6 +19,7 @@
# <pep8 compliant>
import bpy
from bpy.types import Menu, Panel
+from .properties_paint_common import UnifiedPaintPanel
class View3DPanel():
@@ -447,47 +448,12 @@ class VIEW3D_PT_tools_posemode_options(View3DPanel, Panel):
# ********** default tools for paint modes ****************
-class PaintPanel():
+class View3DPaintPanel(UnifiedPaintPanel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
- @staticmethod
- def paint_settings(context):
- ts = context.tool_settings
- if context.sculpt_object:
- return ts.sculpt
- elif context.vertex_paint_object:
- return ts.vertex_paint
- elif context.weight_paint_object:
- return ts.weight_paint
- elif context.image_paint_object:
- return ts.image_paint
- elif context.particle_edit_object:
- return ts.particle_edit
-
- return None
-
- @staticmethod
- def unified_paint_settings(parent, context):
- ups = context.tool_settings.unified_paint_settings
- parent.label(text="Unified Settings:")
- parent.prop(ups, "use_unified_size", text="Size")
- parent.prop(ups, "use_unified_strength", text="Strength")
-
- @staticmethod
- def prop_unified_size(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
- ups = context.tool_settings.unified_paint_settings
- ptr = ups if ups.use_unified_size else brush
- parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
-
- @staticmethod
- def prop_unified_strength(parent, context, brush, prop_name, icon='NONE', text="", slider=False):
- ups = context.tool_settings.unified_paint_settings
- ptr = ups if ups.use_unified_strength else brush
- parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider)
-
-class VIEW3D_PT_tools_brush(PaintPanel, Panel):
+class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
bl_label = "Brush"
@classmethod
@@ -497,6 +463,7 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
def draw(self, context):
layout = self.layout
+ toolsettings = context.tool_settings
settings = self.paint_settings(context)
brush = settings.brush
@@ -541,7 +508,7 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
row = col.row(align=True)
- ups = context.tool_settings.unified_paint_settings
+ ups = toolsettings.unified_paint_settings
if ((ups.use_unified_size and ups.use_locked_size) or
((not ups.use_unified_size) and brush.use_locked_size)):
self.prop_unified_size(row, context, brush, "use_locked_size", icon='LOCKED')
@@ -559,16 +526,16 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
if brush.use_space and tool != 'SMOOTH':
if brush.use_space_atten:
- row.prop(brush, "use_space_atten", toggle=True, text="", icon='LOCKED')
+ row.prop(brush, "use_space_atten", toggle=True, icon='LOCKED')
else:
- row.prop(brush, "use_space_atten", toggle=True, text="", icon='UNLOCKED')
+ row.prop(brush, "use_space_atten", toggle=True, icon='UNLOCKED')
- self.prop_unified_strength(row, context, brush, "strength")
+ self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
if tool == 'ROTATE':
row = col.row(align=True)
- self.prop_unified_strength(row, context, brush, "strength")
+ self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
if tool != 'SMOOTH':
@@ -660,7 +627,7 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
self.prop_unified_size(row, context, brush, "use_pressure_size")
row = col.row(align=True)
- self.prop_unified_strength(row, context, brush, "strength")
+ self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
row = col.row(align=True)
@@ -675,9 +642,9 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
# Weight Paint Mode #
elif context.weight_paint_object and brush:
- layout.prop(context.tool_settings, "vertex_group_weight", text="Weight", slider=True)
- layout.prop(context.tool_settings, "use_auto_normalize", text="Auto Normalize")
- layout.prop(context.tool_settings, "use_multipaint", text="Multi-Paint")
+ layout.prop(toolsettings, "vertex_group_weight", text="Weight", slider=True)
+ layout.prop(toolsettings, "use_auto_normalize", text="Auto Normalize")
+ layout.prop(toolsettings, "use_multipaint", text="Multi-Paint")
col = layout.column()
@@ -686,7 +653,7 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
self.prop_unified_size(row, context, brush, "use_pressure_size")
row = col.row(align=True)
- self.prop_unified_strength(row, context, brush, "strength")
+ self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
row = col.row(align=True)
@@ -704,7 +671,7 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
self.prop_unified_size(row, context, brush, "use_pressure_size")
row = col.row(align=True)
- self.prop_unified_strength(row, context, brush, "strength")
+ self.prop_unified_strength(row, context, brush, "strength", text="Strength")
self.prop_unified_strength(row, context, brush, "use_pressure_strength")
# XXX - TODO
@@ -713,7 +680,7 @@ class VIEW3D_PT_tools_brush(PaintPanel, Panel):
#row.prop(brush, "use_pressure_jitter", toggle=True, text="")
-class VIEW3D_PT_tools_brush_texture(PaintPanel, Panel):
+class VIEW3D_PT_tools_brush_texture(Panel, View3DPaintPanel):
bl_label = "Texture"
bl_options = {'DEFAULT_CLOSED'}
@@ -792,7 +759,7 @@ class VIEW3D_PT_tools_brush_texture(PaintPanel, Panel):
sub.prop(brush, "texture_overlay_alpha", text="Alpha")
-class VIEW3D_PT_tools_brush_tool(PaintPanel, Panel):
+class VIEW3D_PT_tools_brush_tool(Panel, View3DPaintPanel):
bl_label = "Tool"
bl_options = {'DEFAULT_CLOSED'}
@@ -826,7 +793,7 @@ class VIEW3D_PT_tools_brush_tool(PaintPanel, Panel):
row.prop(brush, "use_paint_image", text="", icon='TPAINT_HLT')
-class VIEW3D_PT_tools_brush_stroke(PaintPanel, Panel):
+class VIEW3D_PT_tools_brush_stroke(Panel, View3DPaintPanel):
bl_label = "Stroke"
bl_options = {'DEFAULT_CLOSED'}
@@ -918,7 +885,7 @@ class VIEW3D_PT_tools_brush_stroke(PaintPanel, Panel):
# row.prop(brush, "use_pressure_spacing", toggle=True, text="")
-class VIEW3D_PT_tools_brush_curve(PaintPanel, Panel):
+class VIEW3D_PT_tools_brush_curve(Panel, View3DPaintPanel):
bl_label = "Curve"
bl_options = {'DEFAULT_CLOSED'}
@@ -945,7 +912,7 @@ class VIEW3D_PT_tools_brush_curve(PaintPanel, Panel):
row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
-class VIEW3D_PT_sculpt_options(PaintPanel, Panel):
+class VIEW3D_PT_sculpt_options(Panel, View3DPaintPanel):
bl_label = "Options"
bl_options = {'DEFAULT_CLOSED'}
@@ -956,8 +923,8 @@ class VIEW3D_PT_sculpt_options(PaintPanel, Panel):
def draw(self, context):
layout = self.layout
- tool_settings = context.tool_settings
- sculpt = tool_settings.sculpt
+ toolsettings = context.tool_settings
+ sculpt = toolsettings.sculpt
layout.label(text="Lock:")
row = layout.row(align=True)
@@ -973,7 +940,7 @@ class VIEW3D_PT_sculpt_options(PaintPanel, Panel):
self.unified_paint_settings(layout, context)
-class VIEW3D_PT_sculpt_symmetry(PaintPanel, Panel):
+class VIEW3D_PT_sculpt_symmetry(Panel, View3DPaintPanel):
bl_label = "Symmetry"
bl_options = {'DEFAULT_CLOSED'}
@@ -997,17 +964,17 @@ class VIEW3D_PT_sculpt_symmetry(PaintPanel, Panel):
layout.prop(sculpt, "use_symmetry_feather", text="Feather")
-class VIEW3D_PT_tools_brush_appearance(PaintPanel, Panel):
+class VIEW3D_PT_tools_brush_appearance(Panel, View3DPaintPanel):
bl_label = "Appearance"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
- ts = context.tool_settings
- return ((context.sculpt_object and ts.sculpt) or
- (context.vertex_paint_object and ts.vertex_paint) or
- (context.weight_paint_object and ts.weight_paint) or
- (context.image_paint_object and ts.image_paint))
+ toolsettings = context.tool_settings
+ return ((context.sculpt_object and toolsettings.sculpt) or
+ (context.vertex_paint_object and toolsettings.vertex_paint) or
+ (context.weight_paint_object and toolsettings.weight_paint) or
+ (context.image_paint_object and toolsettings.image_paint))
def draw(self, context):
layout = self.layout
@@ -1059,7 +1026,7 @@ class VIEW3D_PT_tools_weightpaint(View3DPanel, Panel):
col.operator("object.vertex_group_fix", text="Fix Deforms")
-class VIEW3D_PT_tools_weightpaint_options(PaintPanel, Panel):
+class VIEW3D_PT_tools_weightpaint_options(Panel, View3DPaintPanel):
bl_context = "weightpaint"
bl_label = "Options"
@@ -1095,15 +1062,15 @@ class VIEW3D_PT_tools_weightpaint_options(PaintPanel, Panel):
# ********** default tools for vertex-paint ****************
-class VIEW3D_PT_tools_vertexpaint(PaintPanel, Panel):
+class VIEW3D_PT_tools_vertexpaint(Panel, View3DPaintPanel):
bl_context = "vertexpaint"
bl_label = "Options"
def draw(self, context):
layout = self.layout
- tool_settings = context.tool_settings
- vpaint = tool_settings.vertex_paint
+ toolsettings = context.tool_settings
+ vpaint = toolsettings.vertex_paint
col = layout.column()
#col.prop(vpaint, "mode", text="")
@@ -1141,8 +1108,9 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel, Panel):
ob = context.active_object
mesh = ob.data
- ipaint = context.tool_settings.image_paint
- settings = context.tool_settings.image_paint
+ toolsettings = context.tool_settings
+ ipaint = toolsettings.image_paint
+ settings = toolsettings.image_paint
use_projection = ipaint.use_projection
col = layout.column()
@@ -1188,7 +1156,7 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel, Panel):
col.operator("image.save_dirty", text="Save All Edited")
-class VIEW3D_PT_imagepaint_options(PaintPanel):
+class VIEW3D_PT_imagepaint_options(View3DPaintPanel):
bl_label = "Options"
bl_options = {'DEFAULT_CLOSED'}
@@ -1199,8 +1167,6 @@ class VIEW3D_PT_imagepaint_options(PaintPanel):
def draw(self, context):
layout = self.layout
- tool_settings = context.tool_settings
-
col = layout.column()
self.unified_paint_settings(col, context)
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 5f451ce7821..0c47c833cb3 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -584,5 +584,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm);
/* Set object's bounding box based on DerivedMesh min/max data */
void DM_set_object_boundbox(struct Object *ob, DerivedMesh *dm);
+/* debug only */
+#ifndef NDEBUG
+char *DM_debug_info(DerivedMesh *dm);
+void DM_debug_print(DerivedMesh *dm);
#endif
+#endif
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index b301b7cf03b..a89bfbd50b1 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -114,6 +114,10 @@ void pchan_apply_mat4(struct bPoseChannel *pchan, float mat[][4], short use_coma
void pchan_to_mat4(struct bPoseChannel *pchan, float chan_mat[4][4]);
void pchan_calc_mat(struct bPoseChannel *pchan);
+/* Get the "pchan to pose" transform matrix. These matrices apply the effects of
+ * HINGE/NO_SCALE/NO_LOCAL_LOCATION options over the pchan loc/rot/scale transformations. */
+void pchan_to_pose_mat(struct bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4]);
+
/* Rotation Mode Conversions - Used for PoseChannels + Objects... */
void BKE_rotMode_change_values(float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode);
diff --git a/source/blender/blenkernel/BKE_array_mallocn.h b/source/blender/blenkernel/BKE_array_mallocn.h
deleted file mode 100644
index 0f312360521..00000000000
--- a/source/blender/blenkernel/BKE_array_mallocn.h
+++ /dev/null
@@ -1,85 +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) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef BKE_ARRAY_MALLOCN_H
-#define BKE_ARRAY_MALLOCN_H
-
-/** \file BKE_array_mallocn.h
- * \ingroup bke
- * \brief little array macro library.
- */
-
-/* example of usage:
- *
- * int *arr = NULL;
- * V_DECLARE(arr);
- * int i;
- *
- * for (i=0; i<10; i++) {
- * V_GROW(arr);
- * arr[i] = something;
- * }
- * V_FREE(arr);
- *
- * arrays are buffered, using double-buffering (so on each reallocation,
- * the array size is doubled). supposedly this should give good Big Oh
- * behaviour, though it may not be the best in practice.
- */
-
-#define V_DECLARE(vec) int _##vec##_count=0; void *_##vec##_tmp
-
-/* in the future, I plan on having V_DECLARE allocate stack memory it'll
- * use at first, and switch over to heap when it needs more. that'll mess
- * up cases where you'd want to use this API to build a dynamic list for
- * non-local use, so all such cases should use this macro.*/
-#define V_DYNDECLARE(vec) V_DECLARE(vec)
-
-/*this returns the entire size of the array, including any buffering.*/
-#define V_SIZE(vec) ((signed int)((vec)==NULL ? 0 : MEM_allocN_len(vec) / sizeof(*vec)))
-
-/*this returns the logical size of the array, not including buffering.*/
-#define V_COUNT(vec) _##vec##_count
-
-/*grow the array by one. zeroes the new elements.*/
-#define V_GROW(vec) \
- V_SIZE(vec) > _##vec##_count ? _##vec##_count++ : \
- ((_##vec##_tmp = MEM_callocN(sizeof(*vec)*(_##vec##_count*2+2), #vec " " __FILE__ " ")),\
- (void)(vec && memcpy(_##vec##_tmp, vec, sizeof(*vec) * _##vec##_count)),\
- (void)(vec && (MEM_freeN(vec),1)),\
- (vec = _##vec##_tmp),\
- _##vec##_count++)
-
-#define V_FREE(vec) if (vec) MEM_freeN(vec);
-
-/*resets the logical size of an array to zero, but doesn't
- free the memory.*/
-#define V_RESET(vec) _##vec##_count=0
-
-/*set the count of the array*/
-#define V_SETCOUNT(vec, count) _##vec##_count = (count)
-
-#endif // BKE_ARRAY_MALLOCN_H
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 3632eb33717..f24687e0fc9 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 261
-#define BLENDER_SUBVERSION 2
+#define BLENDER_SUBVERSION 3
#define BLENDER_MINVERSION 250
#define BLENDER_MINSUBVERSION 0
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index 7668d5392da..ee3edbb47e7 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -53,7 +53,7 @@ typedef struct Global {
struct Main *main;
/* strings: lastsaved */
- char ima[256], lib[256];
+ char ima[1024], lib[1024]; /* 1024 = FILE_MAX */
/* flag: if != 0 G.main->name contains valid relative base path */
int relbase_valid;
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index c829fc69b05..5cdc3537f5b 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -186,7 +186,7 @@ void BKE_image_merge(struct Image *dest, struct Image *source);
int BKE_image_has_alpha(struct Image *image);
/* image_gen.c */
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4]);
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4]);
void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int height, int width);
void BKE_image_buf_fill_checker_color(unsigned char *rect, float *rect_float, int height, int width);
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index ada0761f7d2..7a7f6dfb6f9 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -50,7 +50,7 @@ struct Library;
typedef struct Main {
struct Main *next, *prev;
- char name[240];
+ char name[1024]; /* 1024 = FILE_MAX */
short versionfile, subversionfile;
short minversionfile, minsubversionfile;
int revision; /* svn revision of binary that saved file */
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 53ff7d873ad..30a4b154e31 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -52,7 +52,10 @@ struct CustomData;
struct DerivedMesh;
struct Scene;
struct MLoopUV;
-
+struct UvVertMap;
+struct UvMapVert;
+struct UvElementMap;
+struct UvElement;
#ifdef __cplusplus
extern "C" {
#endif
@@ -126,6 +129,39 @@ typedef struct UvMapVert {
unsigned char tfindex, separate, flag;
} UvMapVert;
+typedef struct UvElementMap {
+ /* address UvElements by their vertex */
+ struct UvElement **vert;
+ /* UvElement Store */
+ struct UvElement *buf;
+ /* Total number of UVs in the layer. Useful to know */
+ int totalUVs;
+ /* Number of Islands in the mesh */
+ int totalIslands;
+ /* Stores the starting index in buf where each island begins */
+ int *islandIndices;
+} UvElementMap;
+
+typedef struct UvElement {
+ /* Next UvElement corresponding to same vertex */
+ struct UvElement *next;
+ /* Face the element belongs to */
+ struct EditFace *face;
+ /* Index in the editFace of the uv */
+ unsigned char tfindex;
+ /* Whether this element is the first of coincident elements */
+ unsigned char separate;
+ /* general use flag */
+ unsigned char flag;
+ /* If generating element map with island sorting, this stores the island index */
+ unsigned short island;
+} UvElement;
+
+/* invalid island index is max short. If any one has the patience
+ * to make that many islands, he can bite me :p */
+#define INVALID_ISLAND 0xFFFF
+
+
UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned int totface, unsigned int totvert, int selected, float *limit);
UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v);
void free_uv_vert_map(UvVertMap *vmap);
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index a951347d946..f0c054560c4 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -46,7 +46,8 @@ void free_text (struct Text *text);
void txt_set_undostate (int u);
int txt_get_undostate (void);
struct Text* add_empty_text (const char *name);
-int reopen_text (struct Text *text);
+int txt_extended_ascii_as_utf8(char **str);
+int reopen_text (struct Text *text);
struct Text* add_text (const char *file, const char *relpath);
struct Text* copy_text (struct Text *ta);
void unlink_text (struct Main *bmain, struct Text *text);
@@ -59,6 +60,8 @@ void txt_order_cursors (struct Text *text);
int txt_find_string (struct Text *text, const char *findstr, int wrap, int match_case);
int txt_has_sel (struct Text *text);
int txt_get_span (struct TextLine *from, struct TextLine *to);
+int txt_utf8_offset_to_index(char *str, int offset);
+int txt_utf8_index_to_offset(char *str, int index);
void txt_move_up (struct Text *text, short sel);
void txt_move_down (struct Text *text, short sel);
void txt_move_left (struct Text *text, short sel);
@@ -86,9 +89,9 @@ void txt_do_redo (struct Text *text);
void txt_split_curline (struct Text *text);
void txt_backspace_char (struct Text *text);
void txt_backspace_word (struct Text *text);
-int txt_add_char (struct Text *text, char add);
-int txt_add_raw_char (struct Text *text, char add);
-int txt_replace_char (struct Text *text, char add);
+int txt_add_char (struct Text *text, unsigned int add);
+int txt_add_raw_char (struct Text *text, unsigned int add);
+int txt_replace_char (struct Text *text, unsigned int add);
void txt_export_to_object(struct Text *text);
void txt_export_to_objects(struct Text *text);
void txt_unindent (struct Text *text);
@@ -127,34 +130,48 @@ int text_check_whitespace(char ch);
#define UNDO_SLEFT 005
#define UNDO_SRIGHT 006
#define UNDO_SUP 007
-#define UNDO_SDOWN 021
+#define UNDO_SDOWN 010
/* Complex movement (opcode is followed
* by 4 character line ID + a 2 character
* position ID and opcode (repeat)) */
-#define UNDO_CTO 022
-#define UNDO_STO 023
-
-/* Complex editing (opcode is followed
- * by 1 character ID and opcode (repeat)) */
-#define UNDO_INSERT 024
-#define UNDO_BS 025
-#define UNDO_DEL 026
+#define UNDO_CTO 011
+#define UNDO_STO 012
+
+/* Complex editing */
+/* 1 - opcode is followed by 1 byte for ascii character and opcode (repeat)) */
+/* 2 - opcode is followed by 2 bytes for utf-8 character and opcode (repeat)) */
+/* 3 - opcode is followed by 3 bytes for utf-8 character and opcode (repeat)) */
+/* 4 - opcode is followed by 4 bytes for unicode character and opcode (repeat)) */
+#define UNDO_INSERT_1 013
+#define UNDO_INSERT_2 014
+#define UNDO_INSERT_3 015
+#define UNDO_INSERT_4 016
+
+#define UNDO_BS_1 017
+#define UNDO_BS_2 020
+#define UNDO_BS_3 021
+#define UNDO_BS_4 022
+
+#define UNDO_DEL_1 023
+#define UNDO_DEL_2 024
+#define UNDO_DEL_3 025
+#define UNDO_DEL_4 026
/* Text block (opcode is followed
* by 4 character length ID + the text
* block itself + the 4 character length
* ID (repeat) and opcode (repeat)) */
-#define UNDO_DBLOCK 027 /* Delete block */
-#define UNDO_IBLOCK 030 /* Insert block */
+#define UNDO_DBLOCK 027 /* Delete block */
+#define UNDO_IBLOCK 030 /* Insert block */
/* Misc */
-#define UNDO_SWAP 031 /* Swap cursors */
+#define UNDO_SWAP 031 /* Swap cursors */
-#define UNDO_INDENT 032
-#define UNDO_UNINDENT 033
-#define UNDO_COMMENT 034
-#define UNDO_UNCOMMENT 035
+#define UNDO_INDENT 032
+#define UNDO_UNINDENT 033
+#define UNDO_COMMENT 034
+#define UNDO_UNCOMMENT 035
/* Marker flags */
#define TMARK_TEMP 0x01 /* Remove on non-editing events, don't save */
diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h
index b5b3c7e67eb..a6a9bb0c0f6 100644
--- a/source/blender/blenkernel/BKE_utildefines.h
+++ b/source/blender/blenkernel/BKE_utildefines.h
@@ -43,9 +43,9 @@ extern "C" {
/* these values need to be hardcoded in structs, dna does not recognize defines */
/* also defined in DNA_space_types.h */
#ifndef FILE_MAXDIR
-#define FILE_MAXDIR 160
-#define FILE_MAXFILE 80
-#define FILE_MAX 240
+#define FILE_MAXDIR 768
+#define FILE_MAXFILE 256
+#define FILE_MAX 1024
#endif
/* this weirdo pops up in two places ... */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 86530d18c9b..1d5bdb36de7 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -158,7 +158,6 @@ set(SRC
BKE_anim.h
BKE_animsys.h
BKE_armature.h
- BKE_array_mallocn.h
BKE_blender.h
BKE_bmesh.h
BKE_bmeshCustomData.h
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 0ff46045f78..b670a360a6a 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2313,3 +2313,79 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm)
#endif /* WITH_GAMEENGINE */
/* --- NAVMESH (end) --- */
+
+
+/* derivedmesh info printing function,
+ * to help track down differences DM output */
+
+#ifndef NDEBUG
+#include "BLI_dynstr.h"
+
+static void dm_debug_info_layers(DynStr *dynstr, DerivedMesh *dm, void *(*getElemDataArray)(DerivedMesh *, int))
+{
+ int type;
+
+ for (type = 0; type < CD_NUMTYPES; type++) {
+ /* note: doesnt account for multiple layers */
+ void *pt = getElemDataArray(dm, type);
+ if (pt) {
+ const char *name = CustomData_layertype_name(type);
+ const int size = CustomData_sizeof(type);
+ const char *structname;
+ int structnum;
+ CustomData_file_write_info(type, &structname, &structnum);
+ BLI_dynstr_appendf(dynstr,
+ " dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n",
+ name, structname, type, (void *)pt, size, (int)(MEM_allocN_len(pt) / size));
+ }
+ }
+}
+
+char *DM_debug_info(DerivedMesh *dm)
+{
+ DynStr *dynstr= BLI_dynstr_new();
+ char *ret;
+ const char *tstr;
+
+ BLI_dynstr_appendf(dynstr, "{\n");
+ BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)dm);
+ switch (dm->type) {
+ case DM_TYPE_CDDM: tstr = "DM_TYPE_CDDM"; break;
+ case DM_TYPE_EDITMESH: tstr = "DM_TYPE_EDITMESH"; break;
+ case DM_TYPE_CCGDM: tstr = "DM_TYPE_CCGDM"; break;
+ default: tstr = "UNKNOWN"; break;
+ }
+ BLI_dynstr_appendf(dynstr, " 'type': '%s',\n", tstr);
+ BLI_dynstr_appendf(dynstr, " 'numVertData': %d,\n", dm->numVertData);
+ BLI_dynstr_appendf(dynstr, " 'numEdgeData': %d,\n", dm->numEdgeData);
+ BLI_dynstr_appendf(dynstr, " 'numFaceData': %d,\n", dm->numFaceData);
+ BLI_dynstr_appendf(dynstr, " 'deformedOnly': %d,\n", dm->deformedOnly);
+
+ BLI_dynstr_appendf(dynstr, " 'vertexLayers': (\n");
+ dm_debug_info_layers(dynstr, dm, dm->getVertDataArray);
+ BLI_dynstr_appendf(dynstr, " ),\n");
+
+ BLI_dynstr_appendf(dynstr, " 'edgeLayers': (\n");
+ dm_debug_info_layers(dynstr, dm, dm->getEdgeDataArray);
+ BLI_dynstr_appendf(dynstr, " ),\n");
+
+ BLI_dynstr_appendf(dynstr, " 'faceLayers': (\n");
+ dm_debug_info_layers(dynstr, dm, dm->getFaceDataArray);
+ BLI_dynstr_appendf(dynstr, " ),\n");
+
+ BLI_dynstr_appendf(dynstr, "}\n");
+
+ ret = BLI_dynstr_get_cstring(dynstr);
+ BLI_dynstr_free(dynstr);
+ return ret;
+}
+
+void DM_debug_print(DerivedMesh *dm)
+{
+ char *str = DM_debug_info(dm);
+ printf("%s", str);
+ fflush(stdout);
+ MEM_freeN(str);
+}
+
+#endif /* NDEBUG */
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index ae04b7760c2..4f83bcf7e7f 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -590,7 +590,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest)
/* ************ Armature Deform ******************* */
typedef struct bPoseChanDeform {
- Mat4 *b_bone_mats;
+ Mat4 *b_bone_mats;
DualQuat *dual_quat;
DualQuat *b_bone_dual_quats;
} bPoseChanDeform;
@@ -1123,66 +1123,183 @@ void armature_loc_world_to_pose(Object *ob, float *inloc, float *outloc)
copy_v3_v3(outloc, nLocMat[3]);
}
-/* Convert Pose-Space Matrix to Bone-Space Matrix
- * NOTE: this cannot be used to convert to pose-space transforms of the supplied
- * pose-channel into its local space (i.e. 'visual'-keyframing)
+/* Construct the matrices (rot/scale and loc) to apply the PoseChannels into the armature (object) space.
+ * I.e. (roughly) the "pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b)" in the
+ * pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b)
+ * ...function.
+ *
+ * This allows to get the transformations of a bone in its object space, *before* constraints (and IK)
+ * get applied (used by pose evaluation code).
+ * And reverse: to find pchan transformations needed to place a bone at a given loc/rot/scale
+ * in object space (used by interactive transform, and snapping code).
+ *
+ * Note that, with the HINGE/NO_SCALE/NO_LOCAL_LOCATION options, the location matrix
+ * will differ from the rotation/scale matrix...
+ *
+ * NOTE: This cannot be used to convert to pose-space transforms of the supplied
+ * pose-channel into its local space (i.e. 'visual'-keyframing).
+ * (note: I don't understand that, so I keep it :p --mont29).
*/
-void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outmat[][4])
+void pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_mat[][4])
{
- float pc_trans[4][4], inv_trans[4][4];
- float pc_posemat[4][4], inv_posemat[4][4];
- float pose_mat[4][4];
-
- /* paranoia: prevent crashes with no pose-channel supplied */
- if (pchan==NULL) return;
-
- /* default flag */
- if((pchan->bone->flag & BONE_NO_LOCAL_LOCATION)==0) {
- /* get the inverse matrix of the pchan's transforms */
- switch(pchan->rotmode) {
- case ROT_MODE_QUAT:
- loc_quat_size_to_mat4(pc_trans, pchan->loc, pchan->quat, pchan->size);
- break;
- case ROT_MODE_AXISANGLE:
- loc_axisangle_size_to_mat4(pc_trans, pchan->loc, pchan->rotAxis, pchan->rotAngle, pchan->size);
- break;
- default: /* euler */
- loc_eul_size_to_mat4(pc_trans, pchan->loc, pchan->eul, pchan->size);
+ Bone *bone, *parbone;
+ bPoseChannel *parchan;
+
+ /* set up variables for quicker access below */
+ bone= pchan->bone;
+ parbone= bone->parent;
+ parchan= pchan->parent;
+
+ if(parchan) {
+ float offs_bone[4][4]; /* yoffs(b-1) + root(b) + bonemat(b). */
+
+ /* Bone transform itself. */
+ copy_m4_m3(offs_bone, bone->bone_mat);
+
+ /* The bone's root offset (is in the parent's coordinate system). */
+ copy_v3_v3(offs_bone[3], bone->head);
+
+ /* Get the length translation of parent (length along y axis). */
+ offs_bone[3][1]+= parbone->length;
+
+ /* Compose the rotscale matrix for this bone. */
+ if((bone->flag & BONE_HINGE) && (bone->flag & BONE_NO_SCALE)) {
+ /* Parent rest rotation and scale. */
+ mult_m4_m4m4(rotscale_mat, parbone->arm_mat, offs_bone);
}
+ else if(bone->flag & BONE_HINGE) {
+ /* Parent rest rotation and pose scale. */
+ float tmat[4][4], tscale[3];
- copy_m4_m4(pose_mat, pchan->pose_mat);
- }
- else {
- /* local location, this is not default, different calculation
- * note: only tested for location with pose bone snapping.
- * If this is not useful in other cases the BONE_NO_LOCAL_LOCATION
- * case may have to be split into its own function. */
- unit_m4(pc_trans);
- copy_v3_v3(pc_trans[3], pchan->loc);
+ /* Extract the scale of the parent pose matrix. */
+ mat4_to_size(tscale, parchan->pose_mat);
+ size_to_mat4(tmat, tscale);
+
+ /* Applies the parent pose scale to the rest matrix. */
+ mult_m4_m4m4(tmat, tmat, parbone->arm_mat);
+
+ mult_m4_m4m4(rotscale_mat, tmat, offs_bone);
+ }
+ else if(bone->flag & BONE_NO_SCALE) {
+ /* Parent pose rotation and rest scale (i.e. no scaling). */
+ float tmat[4][4];
+ copy_m4_m4(tmat, parchan->pose_mat);
+ normalize_m4(tmat);
+ mult_m4_m4m4(rotscale_mat, tmat, offs_bone);
+ }
+ else
+ mult_m4_m4m4(rotscale_mat, parchan->pose_mat, offs_bone);
+
+# if 1
+ /* Compose the loc matrix for this bone. */
+ /* NOTE: That version deos not modify bone's loc when HINGE/NO_SCALE options are set. */
- /* use parents rotation/scale space + own absolute position */
- if(pchan->parent) copy_m4_m4(pose_mat, pchan->parent->pose_mat);
- else unit_m4(pose_mat);
+ /* In this case, use the object's space *orientation*. */
+ if(bone->flag & BONE_NO_LOCAL_LOCATION) {
+ /* XXX I'm sure that code can be simplified! */
+ float bone_loc[4][4], bone_rotscale[3][3], tmat4[4][4], tmat3[3][3];
+ unit_m4(bone_loc);
+ unit_m4(loc_mat);
+ unit_m4(tmat4);
+
+ mul_v3_m4v3(bone_loc[3], parchan->pose_mat, offs_bone[3]);
+
+ unit_m3(bone_rotscale);
+ copy_m3_m4(tmat3, parchan->pose_mat);
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+
+ copy_m4_m3(tmat4, bone_rotscale);
+ mult_m4_m4m4(loc_mat, bone_loc, tmat4);
+ }
+ /* Those flags do not affect position, use plain parent transform space! */
+ else if(bone->flag & (BONE_HINGE|BONE_NO_SCALE)) {
+ mult_m4_m4m4(loc_mat, parchan->pose_mat, offs_bone);
+ }
+ /* Else (i.e. default, usual case), just use the same matrix for rotation/scaling, and location. */
+ else
+ copy_m4_m4(loc_mat, rotscale_mat);
+# endif
+# if 0
+ /* Compose the loc matrix for this bone. */
+ /* NOTE: That version modifies bone's loc when HINGE/NO_SCALE options are set. */
+
+ /* In these cases we need to compute location separately */
+ if(bone->flag & (BONE_HINGE|BONE_NO_SCALE|BONE_NO_LOCAL_LOCATION)) {
+ float bone_loc[4][4], bone_rotscale[3][3], tmat4[4][4], tmat3[3][3];
+ unit_m4(bone_loc);
+ unit_m4(loc_mat);
+ unit_m4(tmat4);
+
+ mul_v3_m4v3(bone_loc[3], parchan->pose_mat, offs_bone[3]);
+
+ /* "No local location" is not transformed by bone matrix. */
+ /* This only affects orientations (rotations), as scale is always 1.0 here. */
+ if(bone->flag & BONE_NO_LOCAL_LOCATION)
+ unit_m3(bone_rotscale);
+ else
+ /* We could also use bone->bone_mat directly, here... */
+ copy_m3_m4(bone_rotscale, offs_bone);
+
+ if(bone->flag & BONE_HINGE) {
+ copy_m3_m4(tmat3, parbone->arm_mat);
+ /* for hinge-only, we use armature *rotation*, but pose mat *scale*! */
+ if(!(bone->flag & BONE_NO_SCALE)) {
+ float size[3], tsmat[3][3];
+ mat4_to_size(size, parchan->pose_mat);
+ size_to_mat3(tsmat, size);
+ mul_m3_m3m3(tmat3, tsmat, tmat3);
+ }
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+ }
+ else if(bone->flag & BONE_NO_SCALE) {
+ /* For no-scale only, normalized parent pose mat is enough! */
+ copy_m3_m4(tmat3, parchan->pose_mat);
+ normalize_m3(tmat3);
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+ }
+ /* NO_LOCAL_LOCATION only. */
+ else {
+ copy_m3_m4(tmat3, parchan->pose_mat);
+ mul_m3_m3m3(bone_rotscale, tmat3, bone_rotscale);
+ }
- copy_v3_v3(pose_mat[3], pchan->pose_mat[3]);
+ copy_m4_m3(tmat4, bone_rotscale);
+ mult_m4_m4m4(loc_mat, bone_loc, tmat4);
+ }
+ /* Else, just use the same matrix for rotation/scaling, and location. */
+ else
+ copy_m4_m4(loc_mat, rotscale_mat);
+# endif
}
+ /* Root bones. */
+ else {
+ /* Rotation/scaling. */
+ copy_m4_m4(rotscale_mat, pchan->bone->arm_mat);
+ /* Translation. */
+ if(pchan->bone->flag & BONE_NO_LOCAL_LOCATION) {
+ /* Translation of arm_mat, without the rotation. */
+ unit_m4(loc_mat);
+ copy_v3_v3(loc_mat[3], pchan->bone->arm_mat[3]);
+ }
+ else
+ copy_m4_m4(loc_mat, rotscale_mat);
+ }
+}
+
+/* Convert Pose-Space Matrix to Bone-Space Matrix.
+ * NOTE: this cannot be used to convert to pose-space transforms of the supplied
+ * pose-channel into its local space (i.e. 'visual'-keyframing)
+ */
+void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outmat[][4])
+{
+ float rotscale_mat[4][4], loc_mat[4][4];
+ pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+ invert_m4(rotscale_mat);
+ invert_m4(loc_mat);
- invert_m4_m4(inv_trans, pc_trans);
-
- /* Remove the pchan's transforms from it's pose_mat.
- * This should leave behind the effects of restpose +
- * parenting + constraints
- */
- mult_m4_m4m4(pc_posemat, pose_mat, inv_trans);
-
- /* get the inverse of the leftovers so that we can remove
- * that component from the supplied matrix
- */
- invert_m4_m4(inv_posemat, pc_posemat);
-
- /* get the new matrix */
- mult_m4_m4m4(outmat, inv_posemat, inmat);
+ mult_m4_m4m4(outmat, rotscale_mat, inmat);
+ mul_v3_m4v3(outmat[3], loc_mat, inmat[3]);
}
/* Convert Pose-Space Location to Bone-Space Location
@@ -2263,98 +2380,30 @@ void where_is_pose_bone_tail(bPoseChannel *pchan)
*/
void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, int do_extra)
{
- Bone *bone, *parbone;
- bPoseChannel *parchan;
- float vec[3];
-
- /* set up variables for quicker access below */
- bone= pchan->bone;
- parbone= bone->parent;
- parchan= pchan->parent;
-
- /* this gives a chan_mat with actions (ipos) results */
- if(do_extra) pchan_calc_mat(pchan);
- else unit_m4(pchan->chan_mat);
+ /* This gives a chan_mat with actions (ipos) results. */
+ if(do_extra)
+ pchan_calc_mat(pchan);
+ else
+ unit_m4(pchan->chan_mat);
- /* construct the posemat based on PoseChannels, that we do before applying constraints */
+ /* Construct the posemat based on PoseChannels, that we do before applying constraints. */
/* pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b) */
-
- if(parchan) {
- float offs_bone[4][4]; // yoffs(b-1) + root(b) + bonemat(b)
-
- /* bone transform itself */
- copy_m4_m3(offs_bone, bone->bone_mat);
-
- /* The bone's root offset (is in the parent's coordinate system) */
- copy_v3_v3(offs_bone[3], bone->head);
-
- /* Get the length translation of parent (length along y axis) */
- offs_bone[3][1]+= parbone->length;
-
- /* Compose the matrix for this bone */
- if((bone->flag & BONE_HINGE) && (bone->flag & BONE_NO_SCALE)) { // uses restposition rotation, but actual position
- float tmat[4][4];
- /* the rotation of the parent restposition */
- copy_m4_m4(tmat, parbone->arm_mat);
- mul_serie_m4(pchan->pose_mat, tmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
- }
- else if(bone->flag & BONE_HINGE) { // same as above but apply parent scale
- float tmat[4][4];
-
- /* apply the parent matrix scale */
- float tsmat[4][4], tscale[3];
-
- /* the rotation of the parent restposition */
- copy_m4_m4(tmat, parbone->arm_mat);
-
- /* extract the scale of the parent matrix */
- mat4_to_size(tscale, parchan->pose_mat);
- size_to_mat4(tsmat, tscale);
- mult_m4_m4m4(tmat, tsmat, tmat);
-
- mul_serie_m4(pchan->pose_mat, tmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
- }
- else if(bone->flag & BONE_NO_SCALE) {
- float orthmat[4][4];
-
- /* do transform, with an ortho-parent matrix */
- copy_m4_m4(orthmat, parchan->pose_mat);
- normalize_m4(orthmat);
- mul_serie_m4(pchan->pose_mat, orthmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
- }
- else
- mul_serie_m4(pchan->pose_mat, parchan->pose_mat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL);
-
- /* in these cases we need to compute location separately */
- if(bone->flag & (BONE_HINGE|BONE_NO_SCALE|BONE_NO_LOCAL_LOCATION)) {
- float bone_loc[3], chan_loc[3];
-
- mul_v3_m4v3(bone_loc, parchan->pose_mat, offs_bone[3]);
- copy_v3_v3(chan_loc, pchan->chan_mat[3]);
-
- /* no local location is not transformed by bone matrix */
- if(!(bone->flag & BONE_NO_LOCAL_LOCATION))
- mul_mat3_m4_v3(offs_bone, chan_loc);
-
- /* for hinge we use armature instead of pose mat */
- if(bone->flag & BONE_HINGE) mul_mat3_m4_v3(parbone->arm_mat, chan_loc);
- else mul_mat3_m4_v3(parchan->pose_mat, chan_loc);
-
- add_v3_v3v3(pchan->pose_mat[3], bone_loc, chan_loc);
- }
- }
- else {
- mult_m4_m4m4(pchan->pose_mat, bone->arm_mat, pchan->chan_mat);
-
- /* optional location without arm_mat rotation */
- if(bone->flag & BONE_NO_LOCAL_LOCATION)
- add_v3_v3v3(pchan->pose_mat[3], bone->arm_mat[3], pchan->chan_mat[3]);
-
- /* only rootbones get the cyclic offset (unless user doesn't want that) */
- if ((bone->flag & BONE_NO_CYCLICOFFSET) == 0)
+ {
+ float rotscale_mat[4][4], loc_mat[4][4];
+ pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+ /* Rotation and scale. */
+ mult_m4_m4m4(pchan->pose_mat, rotscale_mat, pchan->chan_mat);
+ /* Location. */
+ mul_v3_m4v3(pchan->pose_mat[3], loc_mat, pchan->chan_mat[3]);
+ }
+
+ /* Only rootbones get the cyclic offset (unless user doesn't want that). */
+ /* XXX That could be a problem for snapping and other "reverse transform" features... */
+ if(!pchan->parent) {
+ if((pchan->bone->flag & BONE_NO_CYCLICOFFSET) == 0)
add_v3_v3(pchan->pose_mat[3], ob->pose->cyclic_offset);
}
-
+
if(do_extra) {
#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */
@@ -2365,6 +2414,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti
/* Do constraints */
if (pchan->constraints.first) {
bConstraintOb *cob;
+ float vec[3];
/* make a copy of location of PoseChannel for later */
copy_v3_v3(vec, pchan->pose_mat[3]);
@@ -2388,7 +2438,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti
}
}
}
-
+
/* calculate head */
copy_v3_v3(pchan->pose_head, pchan->pose_mat[3]);
/* calculate tail */
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 362fa6e5e9a..f2514c1030b 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -527,7 +527,7 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
float xy[2], rgba[4], *dstf;
int x, y, rowbytes, xoff, yoff, imbflag;
const int radius= brush_size(scene, brush);
- char *dst, crgb[3];
+ unsigned char *dst, crgb[3];
const float alpha= brush_alpha(scene, brush);
float brush_rgb[3];
@@ -571,10 +571,10 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
}
else {
float alpha_f; /* final float alpha to convert to char */
- F3TOCHAR3(brush->rgb, crgb);
+ rgb_float_to_uchar(crgb, brush->rgb);
for (y=0; y < ibuf->y; y++) {
- dst = (char*)ibuf->rect + y*rowbytes;
+ dst = (unsigned char *)ibuf->rect + y*rowbytes;
for (x=0; x < ibuf->x; x++, dst+=4) {
xy[0] = x + xoff;
@@ -590,19 +590,15 @@ void brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall,
}
else if (texfall == 1) {
brush_sample_tex(scene, brush, xy, rgba, 0);
- dst[0] = FTOCHAR(rgba[0]);
- dst[1] = FTOCHAR(rgba[1]);
- dst[2] = FTOCHAR(rgba[2]);
- dst[3] = FTOCHAR(rgba[3]);
+ rgba_float_to_uchar(dst, rgba);
}
else if (texfall == 2) {
brush_sample_tex(scene, brush, xy, rgba, 0);
mul_v3_v3(rgba, brush->rgb);
alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
- dst[0] = FTOCHAR(rgba[0]);
- dst[1] = FTOCHAR(rgba[1]);
- dst[2] = FTOCHAR(rgba[2]);
+ rgb_float_to_uchar(dst, rgba);
+
dst[3] = FTOCHAR(alpha_f);
}
else {
@@ -843,7 +839,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
Brush *brush= painter->brush;
ImBuf *ibuf, *maskibuf, *texibuf;
float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4];
- char *b, *m, *t, *ot= NULL;
+ unsigned char *b, *m, *t, *ot= NULL;
int dotexold, origx= x, origy= y;
const int radius= brush_size(painter->scene, brush);
@@ -895,12 +891,12 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
}
else {
for (; y < h; y++) {
- b = (char*)ibuf->rect + (y*ibuf->x + origx)*4;
- t = (char*)texibuf->rect + (y*texibuf->x + origx)*4;
- m = (char*)maskibuf->rect + (y*maskibuf->x + origx)*4;
+ b = (unsigned char *)ibuf->rect + (y*ibuf->x + origx)*4;
+ t = (unsigned char *)texibuf->rect + (y*texibuf->x + origx)*4;
+ m = (unsigned char *)maskibuf->rect + (y*maskibuf->x + origx)*4;
if (dotexold)
- ot = (char*)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
+ ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
for (x=origx; x < w; x++, b+=4, m+=4, t+=4) {
if (dotexold) {
@@ -915,10 +911,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
xy[1] = y + yoff;
brush_sample_tex(scene, brush, xy, rgba, 0);
- t[0]= FTOCHAR(rgba[0]);
- t[1]= FTOCHAR(rgba[1]);
- t[2]= FTOCHAR(rgba[2]);
- t[3]= FTOCHAR(rgba[3]);
+ rgba_float_to_uchar(t, rgba);
}
b[0] = t[0]*m[0]/255;
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 77a4a6a429c..2bda3066af0 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -2775,13 +2775,14 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
/* store Z orientation before destroying obmat */
normalize_v3_v3(zz, cob->matrix[2]);
- sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]);
- vec[0] /= size[0];
- vec[1] /= size[1];
- vec[2] /= size[2];
-
- dist = normalize_v3(vec);
- //dist = len_v3v3( ob->obmat[3], targetmat[3]);
+ dist = len_v3v3(cob->matrix[3], ct->matrix[3]);
+ /* XXX What was all that for??? Makes the constraint buggy with scaled objects, see #29940. */
+/* sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]);*/
+/* vec[0] /= size[0];*/
+/* vec[1] /= size[1];*/
+/* vec[2] /= size[2];*/
+
+/* dist = normalize_v3(vec);*/
/* data->orglength==0 occurs on first run, and after 'R' button is clicked */
if (data->orglength == 0)
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 0f1c73c59c1..6536dfb529e 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -368,9 +368,8 @@ void tex_space_curve(Curve *cu)
dl= cu->disp.first;
while(dl) {
- if(dl->type==DL_INDEX3 || dl->type==DL_INDEX3) tot= dl->nr;
- else tot= dl->nr*dl->parts;
-
+ tot = ELEM(dl->type, DL_INDEX3, DL_INDEX4) ? dl->nr : dl->nr * dl->parts;
+
if(tot) doit= 1;
fp= dl->verts;
while(tot--) {
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index f93aee80ab8..6a2207d455c 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -101,9 +101,10 @@ static int neighY[8] = {0,1,1, 1, 0,-1,-1,-1};
#define EFF_MOVEMENT_PER_FRAME 0.05f
/* initial wave time factor */
#define WAVE_TIME_FAC (1.0f/24.f)
-#define WAVE_INIT_SIZE 5.0f
+#define CANVAS_REL_SIZE 5.0f
/* drying limits */
#define MIN_WETNESS 0.001f
+#define MAX_WETNESS 5.0f
/* dissolve macro */
#define VALUE_DISSOLVE(VALUE, TIME, SCALE, LOG) (VALUE) = (LOG) ? (VALUE) * (pow(MIN_WETNESS,1.0f/(1.2f*((float)(TIME))/(SCALE)))) : (VALUE) - 1.0f/(TIME)*(SCALE)
@@ -187,11 +188,12 @@ typedef struct ImgSeqFormatData {
Vec3f *barycentricWeights; /* b-weights for all pixel samples */
} ImgSeqFormatData;
+#if 0 /* UNUSED */
typedef struct EffVelPoint {
float previous_pos[3];
float previous_vel[3];
} EffVelPoint;
-
+#endif
/* adjacency data flags */
#define ADJ_ON_MESH_EDGE (1<<0)
@@ -422,15 +424,31 @@ static void blendColors(float t_color[3], float t_alpha, float s_color[3], float
result[3] = f_alpha;
}
-/* assumes source alpha > 0.0f or results NaN colors */
-static void mixColors(float *t_color, float t_alpha, float *s_color, float s_alpha)
+/* Mix two alpha weighed colors by a defined ratio. output is saved at a_color */
+static float mixColors(float a_color[3], float a_weight, float b_color[3], float b_weight, float ratio)
{
- float factor = (s_alpha<t_alpha) ? 1.0f : t_alpha/s_alpha;
+ float weight_ratio, factor;
+ if (b_weight) {
+ /* if first value has no weight just use b_color */
+ if (!a_weight) {
+ copy_v3_v3(a_color, b_color);
+ return b_weight*ratio;
+ }
+ weight_ratio = b_weight/(a_weight+b_weight);
+ }
+ else return a_weight*(1.0f-ratio);
- /* set initial color depending on existing alpha */
- interp_v3_v3v3(t_color, s_color, t_color, factor);
+ /* calculate final interpolation factor */
+ if (ratio<=0.5f) {
+ factor = weight_ratio*(ratio*2.0f);
+ }
+ else {
+ ratio = (ratio*2.0f - 1.0f);
+ factor = weight_ratio*(1.0f-ratio) + ratio;
+ }
/* mix final color */
- interp_v3_v3v3(t_color, t_color, s_color, s_alpha);
+ interp_v3_v3v3(a_color, a_color, b_color, factor);
+ return (1.0f-factor)*a_weight + factor*b_weight;
}
/* set "ignore cache" flag for all caches on this object */
@@ -617,6 +635,12 @@ static void boundInsert(Bounds3D *b, float point[3])
}
}
+float getSurfaceDimension(PaintSurfaceData *sData)
+{
+ Bounds3D *mb = &sData->bData->mesh_bounds;
+ return MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2]));
+}
+
static void freeGrid(PaintSurfaceData *data)
{
PaintBakeData *bData = data->bData;
@@ -959,17 +983,21 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett
/* Set initial values */
surface->flags = MOD_DPAINT_ANTIALIAS | MOD_DPAINT_MULALPHA | MOD_DPAINT_DRY_LOG | MOD_DPAINT_DISSOLVE_LOG |
- MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1;
+ MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING;
surface->effect = 0;
surface->effect_ui = 1;
surface->diss_speed = 250;
surface->dry_speed = 500;
+ surface->color_dry_threshold = 1.0f;
surface->depth_clamp = 0.0f;
surface->disp_factor = 1.0f;
surface->disp_type = MOD_DPAINT_DISP_DISPLACE;
surface->image_fileformat = MOD_DPAINT_IMGFORMAT_PNG;
+ surface->influence_scale = 1.0f;
+ surface->radius_scale = 1.0f;
+
surface->init_color[0] = 1.0f;
surface->init_color[1] = 1.0f;
surface->init_color[2] = 1.0f;
@@ -1508,7 +1536,7 @@ static int dynamicPaint_checkSurfaceData(DynamicPaintSurface *surface)
/* apply displacing vertex surface to the derived mesh */
-static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, DerivedMesh *result, int update_normals)
+static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, DerivedMesh *result)
{
PaintSurfaceData *sData = surface->data;
@@ -1531,10 +1559,6 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Deri
mvert[i].co[2] -= normal[2]*val;
}
}
- else return;
-
- if (update_normals)
- CDDM_calc_normals(result);
}
/*
@@ -1549,6 +1573,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if(pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) {
DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
+ int update_normals = 0;
pmd->canvas->flags &= ~MOD_DPAINT_PREVIEW_READY;
/* loop through surfaces */
@@ -1589,11 +1614,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if (col) {
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
- int j=0;
+ int j = (mface[i].v4) ? 4 : 3;
Material *material = give_current_material(ob, mface[i].mat_nr+1);
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
if (surface->preview_id == MOD_DPAINT_SURFACE_PREV_PAINT) {
float c[3];
@@ -1642,9 +1667,9 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if (col) {
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
- int j=0;
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ int j = (mface[i].v4) ? 4 : 3;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
index *= 4;
col[i*4+j].a = FTOCHAR(fcolor[index+3]);
@@ -1666,10 +1691,9 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
if (col) {
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
- int j=0;
-
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ int j = (mface[i].v4) ? 4 : 3;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
col[i*4+j].a = 255;
col[i*4+j].r =
col[i*4+j].g =
@@ -1697,9 +1721,9 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
#pragma omp parallel for schedule(static)
for (i=0; i<numOfFaces; i++) {
float temp_color[3];
- int j=0;
- for (; j<((mface[i].v4)?4:3); j++) {
- int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+ int j = (mface[i].v4) ? 4 : 3;
+ while (j--) {
+ int index = *((&mface[i].v1)+j);
weight_to_rgb(temp_color, weight[index]);
col[i*4+j].r = FTOCHAR(temp_color[2]);
@@ -1748,14 +1772,20 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
normal_short_to_float_v3(normal, mvert[i].no);
madd_v3_v3fl(mvert[i].co, normal, wPoint[i].height);
}
- CDDM_calc_normals(result);
+ update_normals = 1;
}
/* displace */
- dynamicPaint_applySurfaceDisplace(surface, result, 1);
+ if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
+ dynamicPaint_applySurfaceDisplace(surface, result);
+ update_normals = 1;
+ }
}
}
}
+
+ if (update_normals)
+ CDDM_calc_normals(result);
}
/* make a copy of dm to use as brush data */
if (pmd->brush) {
@@ -2574,14 +2604,8 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char* filenam
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
PaintPoint *point = &((PaintPoint*)sData->type_data)[index];
- ibuf->rect_float[pos] = point->color[0];
- ibuf->rect_float[pos+1] = point->color[1];
- ibuf->rect_float[pos+2] = point->color[2];
- /* mix wet layer */
- if (point->e_alpha) mixColors(&ibuf->rect_float[pos], point->alpha, point->e_color, point->e_alpha);
-
- /* use highest alpha */
- ibuf->rect_float[pos+3] = (point->e_alpha > point->alpha) ? point->e_alpha : point->alpha;
+ /* blend wet and dry layers */
+ blendColors(point->color, point->alpha, point->e_color, point->e_alpha, &ibuf->rect_float[pos]);
/* Multiply color by alpha if enabled */
if (surface->flags & MOD_DPAINT_MULALPHA) {
@@ -2912,7 +2936,13 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned
float paint[3], float influence, float depth, float vel_factor, float timescale)
{
PaintSurfaceData *sData = surface->data;
- float strength = influence * brush->alpha;
+ float strength;
+
+ /* apply influence scale */
+ influence *= surface->influence_scale;
+ depth *= surface->influence_scale;
+
+ strength = influence * brush->alpha;
CLAMP(strength, 0.0f, 1.0f);
/* Sample velocity colorband if required */
@@ -2991,12 +3021,12 @@ static void dynamicPaint_updatePointData(DynamicPaintSurface *surface, unsigned
}
/* checks whether surface and brush bounds intersect depending on brush type */
-static int meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush)
+static int meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush, float brush_radius)
{
if (brush->collision == MOD_DPAINT_COL_VOLUME)
return boundsIntersect(b1, b2);
else if (brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST)
- return boundsIntersectDist(b1, b2, brush->paint_distance);
+ return boundsIntersectDist(b1, b2, brush_radius);
else return 1;
}
@@ -3123,6 +3153,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
{
BVHTreeFromMesh treeData = {0};
float avg_brushNor[3] = {0.0f};
+ float brush_radius = brush->paint_distance * surface->radius_scale;
int numOfVerts;
int ii;
Bounds3D mesh_bb = {0};
@@ -3141,7 +3172,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
boundInsert(&mesh_bb, mvert[ii].co);
/* for project brush calculate average normal */
- if (brush->collision & MOD_DPAINT_COL_DIST && brush->flags & MOD_DPAINT_PROX_PROJECT) {
+ if (brush->flags & MOD_DPAINT_PROX_PROJECT) {
float nor[3];
normal_short_to_float_v3(nor, mvert[ii].no);
mul_mat3_m4_v3(brushOb->obmat, nor);
@@ -3151,7 +3182,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
}
}
- if (brush->collision & MOD_DPAINT_COL_DIST && brush->flags & MOD_DPAINT_PROX_PROJECT) {
+ if (brush->flags & MOD_DPAINT_PROX_PROJECT) {
mul_v3_fl(avg_brushNor, 1.0f/(float)numOfVerts);
/* instead of null vector use positive z */
if (!(MIN3(avg_brushNor[0],avg_brushNor[1],avg_brushNor[2])))
@@ -3161,7 +3192,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
}
/* check bounding box collision */
- if(grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush))
+ if(grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius))
/* Build a bvh tree from transformed vertices */
if (bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 8))
{
@@ -3173,7 +3204,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
int id;
/* check grid cell bounding box */
- if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush))
+ if (!grid->s_num[c_index] || !meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius))
continue;
/* loop through cell points and process brush */
@@ -3234,7 +3265,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
hit.index = -1;
hit.dist = 9999;
nearest.index = -1;
- nearest.dist = brush->paint_distance * brush->paint_distance; /* find_nearest uses squared distance */
+ nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */
/* Check volume collision */
if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST)
@@ -3292,9 +3323,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
if (inner_proximity && !hit_found) continue;
/* If pure distance proximity, find the nearest point on the mesh */
- if (brush->collision != MOD_DPAINT_COL_DIST || !(brush->flags & MOD_DPAINT_PROX_PROJECT)) {
+ if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) {
if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) {
- proxDist = sqrt(nearest.dist);
+ proxDist = sqrtf(nearest.dist);
copy_v3_v3(hitCo, nearest.co);
hQuad = (nearest.no[0] == 1.0f);
face = nearest.index;
@@ -3314,7 +3345,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
proj_ray[2] = 1.0f;
}
hit.index = -1;
- hit.dist = brush->paint_distance;
+ hit.dist = brush_radius;
/* Do a face normal directional raycast, and use that distance */
if(BLI_bvhtree_ray_cast(treeData.tree, ray_start, proj_ray, 0.0f, &hit, mesh_faces_spherecast_dp, &treeData) != -1)
@@ -3327,8 +3358,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
}
/* If a hit was found, calculate required values */
- if (proxDist >= 0.0f && proxDist <= brush->paint_distance) {
- proximity_factor = proxDist / brush->paint_distance;
+ if (proxDist >= 0.0f && proxDist <= brush_radius) {
+ proximity_factor = proxDist / brush_radius;
CLAMP(proximity_factor, 0.0f, 1.0f);
if (!inner_proximity)
proximity_factor = 1.0f - proximity_factor;
@@ -3514,8 +3545,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface,
int invalidParticles = 0;
int p = 0;
- float solidradius = (brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius;
- float smooth = brush->particle_smooth;
+ float solidradius = surface->radius_scale*((brush->flags & MOD_DPAINT_PART_RAD) ? psys->part->size : brush->particle_radius);
+ float smooth = brush->particle_smooth*surface->radius_scale;
float range = solidradius + smooth;
float particle_timestep = 0.04f * part->timetweak;
@@ -3744,6 +3775,7 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po
Object *brushOb, BrushMaterials *bMats, Scene *scene, float timescale)
{
int index;
+ float brush_radius = brush->paint_distance * surface->radius_scale;
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
Vec3f brushVel;
@@ -3761,13 +3793,13 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po
float colorband[4] = {0.0f};
float strength;
- if (distance>brush->paint_distance) continue;
+ if (distance > brush_radius) continue;
/* Smooth range or color ramp */
if (brush->proximity_falloff == MOD_DPAINT_PRFALL_SMOOTH ||
brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP) {
- strength = 1.0f - distance / brush->paint_distance;
+ strength = 1.0f - distance / brush_radius;
CLAMP(strength, 0.0f, 1.0f);
}
else strength = 1.0f;
@@ -3832,8 +3864,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po
else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE ||
surface->type == MOD_DPAINT_SURFACE_T_WAVE) {
/* get displace depth */
- float disp_intersect = (1.0f - sqrtf((brush->paint_distance-distance) / brush->paint_distance)) * brush->paint_distance;
- depth = (brush->paint_distance - disp_intersect) / bData->bNormal[index].normal_scale;
+ float disp_intersect = (1.0f - sqrtf((brush_radius-distance) / brush_radius)) * brush_radius;
+ depth = (brush_radius - disp_intersect) / bData->bNormal[index].normal_scale;
if (depth<0.0f) depth = 0.0f;
}
dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale);
@@ -3936,7 +3968,7 @@ void surface_determineForceTargetPoints(PaintSurfaceData *sData, int index, floa
if (closest_id[1] != -1) {
float force_proj[3];
float tangent[3];
- float neigh_diff = acos(dot_v3v3(bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir));
+ float neigh_diff = acosf(dot_v3v3(bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir));
float force_intersect;
float temp;
@@ -4008,7 +4040,6 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus
if (n_index != -1 && closest_d[i]>0.0f) {
float dir_dot = closest_d[i], dir_factor;
float speed_scale = eff_scale*smudge_str/bNeighs[n_index].dist;
- float mix;
PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]];
/* just skip if angle is too extreme */
@@ -4018,13 +4049,11 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrus
if (dir_factor > brush->smudge_strength) dir_factor = brush->smudge_strength;
/* mix new color and alpha */
- mix = dir_factor*pPoint->alpha;
- if (mix) mixColors(ePoint->color, ePoint->alpha, pPoint->color, mix);
+ mixColors(ePoint->color, ePoint->alpha, pPoint->color, pPoint->alpha, dir_factor);
ePoint->alpha = ePoint->alpha*(1.0f-dir_factor) + pPoint->alpha*dir_factor;
/* smudge "wet layer" */
- mix = dir_factor*pPoint->e_alpha;
- if (mix) mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, mix);
+ mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, pPoint->e_alpha, dir_factor);
ePoint->e_alpha = ePoint->e_alpha*(1.0f-dir_factor) + pPoint->e_alpha*dir_factor;
pPoint->wetness *= (1.0f-dir_factor);
}
@@ -4041,7 +4070,7 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s
{
double average_force = 0.0f;
float shrink_speed=0.0f, spread_speed=0.0f;
- float fastest_effect;
+ float fastest_effect, avg_dist;
int steps;
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
@@ -4118,9 +4147,10 @@ static int dynamicPaint_prepareEffectStep(DynamicPaintSurface *surface, Scene *s
shrink_speed = surface->shrink_speed;
fastest_effect = MAX3(spread_speed, shrink_speed, average_force);
+ avg_dist = bData->average_dist*CANVAS_REL_SIZE/getSurfaceDimension(sData);
- steps = (int)ceil(1.5f*EFF_MOVEMENT_PER_FRAME*fastest_effect/bData->average_dist*timescale);
- CLAMP(steps, 1, 14);
+ steps = (int)ceil(1.5f*EFF_MOVEMENT_PER_FRAME*fastest_effect/avg_dist*timescale);
+ CLAMP(steps, 1, 20);
return steps;
}
@@ -4132,6 +4162,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
{
PaintSurfaceData *sData = surface->data;
BakeNeighPoint *bNeighs = sData->bData->bNeighs;
+ float distance_scale = getSurfaceDimension(sData)/CANVAS_REL_SIZE;
int index;
timescale /= steps;
@@ -4141,7 +4172,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
* Spread Effect
*/
if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD) {
- float eff_scale = EFF_MOVEMENT_PER_FRAME*surface->spread_speed*timescale;
+ float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->spread_speed*timescale;
/* Copy current surface to the previous points array to read unmodified values */
memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint));
@@ -4151,7 +4182,6 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
{
int i;
int numOfNeighs = sData->adj_data->n_num[index];
- float totalAlpha = 0.0f;
PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index];
/* Only reads values from the surface copy (prevPoint[]),
@@ -4160,39 +4190,23 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
/* Loop through neighbouring points */
for (i=0; i<numOfNeighs; i++) {
int n_index = sData->adj_data->n_index[index]+i;
- float w_factor, alphaAdd = 0.0f;
+ float w_factor /* , p_alpha = pPoint->e_alpha */ /* UNUSED */;
PaintPoint *ePoint = &prevPoint[sData->adj_data->n_target[n_index]];
float speed_scale = (bNeighs[n_index].dist<eff_scale) ? 1.0f : eff_scale/bNeighs[n_index].dist;
- float color_mix = (MIN2(ePoint->wetness, pPoint->wetness))*0.25f*surface->color_spread_speed;
-
- totalAlpha += ePoint->e_alpha;
+ float color_mix = (MIN3(ePoint->wetness, pPoint->wetness, 1.0f))*0.25f*surface->color_spread_speed;
/* do color mixing */
- if (color_mix > MIN_WETNESS) mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, color_mix);
-
- /* Check if neighbouring point has higher wetness,
- * if so, add it's wetness to this point as well*/
- if (ePoint->wetness <= pPoint->wetness) continue;
- w_factor = ePoint->wetness/numOfNeighs * (ePoint->wetness - pPoint->wetness) * speed_scale;
- if (w_factor <= MIN_WETNESS) continue;
-
- if (ePoint->e_alpha > pPoint->e_alpha) {
- alphaAdd = ePoint->e_alpha/numOfNeighs * (ePoint->wetness*ePoint->e_alpha - pPoint->wetness*pPoint->e_alpha) * speed_scale;
- }
+ if (color_mix) mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, color_mix);
- /* mix new color */
- mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, w_factor);
+ /* Only continue if surrounding point has higher wetness */
+ if (ePoint->wetness<pPoint->wetness || ePoint->wetness<MIN_WETNESS) continue;
- pPoint->e_alpha += alphaAdd;
- pPoint->wetness += w_factor;
+ w_factor = 1.0f/numOfNeighs * MIN2(ePoint->wetness, 1.0f) * speed_scale;
+ CLAMP(w_factor, 0.0f, 1.0f);
- if (pPoint->e_alpha > 1.0f) pPoint->e_alpha = 1.0f;
- }
-
- /* For antialiasing sake, don't let alpha go much higher than average alpha of neighbours */
- if (pPoint->e_alpha > (totalAlpha/numOfNeighs+0.25f)) {
- pPoint->e_alpha = (totalAlpha/numOfNeighs+0.25f);
- if (pPoint->e_alpha>1.0f) pPoint->e_alpha = 1.0f;
+ /* mix new wetness and color */
+ pPoint->wetness = (1.0f-w_factor)*pPoint->wetness + w_factor*ePoint->wetness;
+ pPoint->e_alpha = mixColors(pPoint->e_color, pPoint->e_alpha, ePoint->e_color, ePoint->e_alpha, w_factor);
}
}
}
@@ -4201,7 +4215,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
* Shrink Effect
*/
if (surface->effect & MOD_DPAINT_EFFECT_DO_SHRINK) {
- float eff_scale = EFF_MOVEMENT_PER_FRAME*surface->shrink_speed*timescale;
+ float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*surface->shrink_speed*timescale;
/* Copy current surface to the previous points array to read unmodified values */
memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint));
@@ -4251,7 +4265,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
*/
if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force)
{
- float eff_scale = EFF_MOVEMENT_PER_FRAME*timescale/2.0f;
+ float eff_scale = distance_scale*EFF_MOVEMENT_PER_FRAME*timescale/2.0f;
/* Copy current surface to the previous points array to read unmodified values */
memcpy(prevPoint, sData->type_data, sData->total_points*sizeof(struct PaintPoint));
@@ -4264,8 +4278,9 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
float closest_d[2];
/* adjust drip speed depending on wetness */
- float w_factor = pPoint_prev->wetness*0.5f - 0.025f;
+ float w_factor = pPoint_prev->wetness - 0.025f;
if (w_factor <= 0) continue;
+ CLAMP(w_factor, 0.0f, 1.0f);
/* get force affect points */
surface_determineForceTargetPoints(sData, index, &force[index*4], closest_d, closest_id);
@@ -4274,41 +4289,38 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force
for (i=0; i<2; i++) {
int n_index = closest_id[i];
if (n_index != -1 && closest_d[i]>0.0f) {
- float dir_dot = closest_d[i], dir_factor;
+ float dir_dot = closest_d[i], dir_factor, a_factor;
float speed_scale = eff_scale*force[index*4+3]/bNeighs[n_index].dist;
PaintPoint *ePoint = &((PaintPoint*)sData->type_data)[sData->adj_data->n_target[n_index]];
+ float e_wet = ePoint->wetness;
/* just skip if angle is too extreme */
if (dir_dot <= 0.0f) continue;
- dir_factor = dir_dot * speed_scale * w_factor;
- if (dir_factor > (0.5f/steps)) dir_factor = (0.5f/steps);
+ dir_factor = dir_dot * MIN2(speed_scale, 1.0f) * w_factor;
+ if (dir_factor > 0.5f) dir_factor = 0.5f;
- /* mix new color */
- if (dir_factor) mixColors(ePoint->e_color, ePoint->e_alpha, pPoint->e_color, dir_factor);
-
- ePoint->e_alpha += dir_factor;
+ /* mix new wetness*/
ePoint->wetness += dir_factor;
- if (ePoint->e_alpha > 1.0f) ePoint->e_alpha = 1.0f;
+ CLAMP(ePoint->wetness, 0.0f, MAX_WETNESS);
- /* and decrease paint wetness on current point */
- pPoint->wetness -= dir_factor;
+ /* mix new color */
+ a_factor = dir_factor / pPoint_prev->wetness;
+ CLAMP(a_factor, 0.0f, 1.0f);
+ mixColors(ePoint->e_color, ePoint->e_alpha, pPoint_prev->e_color, pPoint_prev->e_alpha, a_factor);
+ /* dripping is supposed to preserve alpha level */
+ if (pPoint_prev->e_alpha > ePoint->e_alpha) {
+ ePoint->e_alpha += a_factor * pPoint_prev->e_alpha;
+ if (ePoint->e_alpha > pPoint_prev->e_alpha)
+ ePoint->e_alpha = pPoint_prev->e_alpha;
+ }
+
+ /* decrease paint wetness on current point */
+ pPoint->wetness -= (ePoint->wetness - e_wet);
+ CLAMP(pPoint->wetness, 0.0f, MAX_WETNESS);
}
}
}
-
- /* Keep values within acceptable range */
- #pragma omp parallel for schedule(static)
- for (index = 0; index < sData->total_points; index++)
- {
- PaintPoint *cPoint = &((PaintPoint*)sData->type_data)[index];
-
- if (cPoint->e_alpha > 1.0f) cPoint->e_alpha=1.0f;
- if (cPoint->wetness > 2.0f) cPoint->wetness=2.0f;
-
- if (cPoint->e_alpha < 0.0f) cPoint->e_alpha=0.0f;
- if (cPoint->wetness < 0.0f) cPoint->wetness=0.0f;
- }
}
}
@@ -4323,7 +4335,7 @@ void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale)
double average_dist = 0.0f;
Bounds3D *mb = &sData->bData->mesh_bounds;
float canvas_size = MAX3((mb->max[0]-mb->min[0]), (mb->max[1]-mb->min[1]), (mb->max[2]-mb->min[2]));
- float wave_scale = WAVE_INIT_SIZE/canvas_size;
+ float wave_scale = CANVAS_REL_SIZE/canvas_size;
/* allocate memory */
PaintWavePoint *prevPoint = MEM_mallocN(sData->total_points*sizeof(PaintWavePoint), "Temp previous points for wave simulation");
@@ -4436,48 +4448,53 @@ static void dynamicPaint_surfacePreStep(DynamicPaintSurface *surface, float time
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
PaintPoint *pPoint = &((PaintPoint*)sData->type_data)[index];
/* drying */
- if (pPoint->wetness >= MIN_WETNESS) {
- int i;
- float dry_ratio, f_color[4];
- float p_wetness = pPoint->wetness;
- VALUE_DISSOLVE(pPoint->wetness, surface->dry_speed, timescale, (surface->flags & MOD_DPAINT_DRY_LOG));
- if (pPoint->wetness<0.0f) pPoint->wetness=0.0f;
- dry_ratio = pPoint->wetness/p_wetness;
+ if (surface->flags & MOD_DPAINT_USE_DRYING) {
+ if (pPoint->wetness >= MIN_WETNESS) {
+ int i;
+ float dry_ratio, f_color[4];
+ float p_wetness = pPoint->wetness;
+ VALUE_DISSOLVE(pPoint->wetness, surface->dry_speed, timescale, (surface->flags & MOD_DPAINT_DRY_LOG));
+ if (pPoint->wetness<0.0f) pPoint->wetness=0.0f;
- /*
- * Slowly "shift" paint from wet layer to dry layer as it drys:
- */
- /* make sure alpha values are within proper range */
- CLAMP(pPoint->alpha, 0.0f, 1.0f);
- CLAMP(pPoint->e_alpha, 0.0f, 1.0f);
-
- /* get current final blended color of these layers */
- blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
- /* reduce wet layer alpha by dry factor */
- pPoint->e_alpha *= dry_ratio;
-
- /* now calculate new alpha for dry layer that keeps final blended color unchanged */
- pPoint->alpha = (f_color[3] - pPoint->e_alpha)/(1.0f-pPoint->e_alpha);
- /* for each rgb component, calculate a new dry layer color that keeps the final blend color
- * with these new alpha values. (wet layer color doesnt change)*/
- if (pPoint->alpha) {
- for (i=0; i<3; i++) {
- pPoint->color[i] = (f_color[i]*f_color[3] - pPoint->e_color[i]*pPoint->e_alpha)/(pPoint->alpha*(1.0f-pPoint->e_alpha));
+ if (pPoint->wetness < surface->color_dry_threshold) {
+ dry_ratio = pPoint->wetness/p_wetness;
+
+ /*
+ * Slowly "shift" paint from wet layer to dry layer as it drys:
+ */
+ /* make sure alpha values are within proper range */
+ CLAMP(pPoint->alpha, 0.0f, 1.0f);
+ CLAMP(pPoint->e_alpha, 0.0f, 1.0f);
+
+ /* get current final blended color of these layers */
+ blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
+ /* reduce wet layer alpha by dry factor */
+ pPoint->e_alpha *= dry_ratio;
+
+ /* now calculate new alpha for dry layer that keeps final blended color unchanged */
+ pPoint->alpha = (f_color[3] - pPoint->e_alpha)/(1.0f-pPoint->e_alpha);
+ /* for each rgb component, calculate a new dry layer color that keeps the final blend color
+ * with these new alpha values. (wet layer color doesnt change)*/
+ if (pPoint->alpha) {
+ for (i=0; i<3; i++) {
+ pPoint->color[i] = (f_color[i]*f_color[3] - pPoint->e_color[i]*pPoint->e_alpha)/(pPoint->alpha*(1.0f-pPoint->e_alpha));
+ }
+ }
}
- }
- pPoint->state = DPAINT_PAINT_WET;
- }
- /* in case of just dryed paint, just mix it to the dry layer and mark it empty */
- else if (pPoint->state > 0) {
- float f_color[4];
- blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
- copy_v3_v3(pPoint->color, f_color);
- pPoint->alpha = f_color[3];
- /* clear wet layer */
- pPoint->wetness = 0.0f;
- pPoint->e_alpha = 0.0f;
- pPoint->state = DPAINT_PAINT_DRY;
+ pPoint->state = DPAINT_PAINT_WET;
+ }
+ /* in case of just dryed paint, just mix it to the dry layer and mark it empty */
+ else if (pPoint->state > 0) {
+ float f_color[4];
+ blendColors(pPoint->color, pPoint->alpha, pPoint->e_color, pPoint->e_alpha, f_color);
+ copy_v3_v3(pPoint->color, f_color);
+ pPoint->alpha = f_color[3];
+ /* clear wet layer */
+ pPoint->wetness = 0.0f;
+ pPoint->e_alpha = 0.0f;
+ pPoint->state = DPAINT_PAINT_DRY;
+ }
}
if (surface->flags & MOD_DPAINT_DISSOLVE) {
@@ -4925,7 +4942,7 @@ int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Obje
/* apply previous displace on derivedmesh if incremental surface */
if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL)
- dynamicPaint_applySurfaceDisplace(surface, surface->canvas->dm, 0);
+ dynamicPaint_applySurfaceDisplace(surface, surface->canvas->dm);
/* update bake data */
dynamicPaint_generateBakeData(surface, scene, cObject);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 9e5917f0b07..0a80e8a3d56 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1111,9 +1111,9 @@ int BKE_add_image_extension(char *string, const char imtype)
if(BLI_testextensie_array(string, imb_ext_image)
|| (G.have_quicktime && BLI_testextensie_array(string, imb_ext_image_qt))) {
return BLI_replace_extension(string, FILE_MAX, extension);
- } else {
+ }
+ else {
return BLI_ensure_extension(string, FILE_MAX, extension);
- return TRUE;
}
}
@@ -1608,7 +1608,7 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf)
return(ok);
}
-/* same as BKE_write_ibuf_as but crappy workaround not to perminantly modify
+/* same as BKE_write_ibuf() but crappy workaround not to perminantly modify
* _some_, values in the imbuf */
int BKE_write_ibuf_as(ImBuf *ibuf, const char *name, ImageFormatData *imf,
const short save_copy)
diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c
index a93d0221cf0..c6cb8c9582a 100644
--- a/source/blender/blenkernel/intern/image_gen.c
+++ b/source/blender/blenkernel/intern/image_gen.c
@@ -33,7 +33,7 @@
#include "BLI_math_base.h"
#include "BLF_api.h"
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4])
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4])
{
int x, y;
@@ -41,22 +41,17 @@ void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width,
if(rect_float) {
for(y= 0; y<height; y++) {
for(x= 0; x<width; x++) {
- rect_float[0]= color[0];
- rect_float[1]= color[1];
- rect_float[2]= color[2];
- rect_float[3]= color[3];
+ copy_v4_v4(rect_float, color);
rect_float+= 4;
}
}
}
if(rect) {
- char ccol[4];
+ unsigned char ccol[4];
+
+ rgba_float_to_uchar(ccol, color);
- ccol[0]= (char)(color[0]*255.0f);
- ccol[1]= (char)(color[1]*255.0f);
- ccol[2]= (char)(color[2]*255.0f);
- ccol[3]= (char)(color[3]*255.0f);
for(y= 0; y<height; y++) {
for(x= 0; x<width; x++) {
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index eb7d07a6f7d..b2385a5cdb8 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -377,7 +377,7 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float *t, int cycl)
if(k1->next==NULL) k[0]=k1;
k1=k1->next;
}
- k1= k[1];
+ /* k1= k[1]; */ /* UNUSED */
t[0]= k[0]->pos;
t[1]+= dpos;
t[2]= k[2]->pos + dpos;
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index ef2249409f0..cba92e7a14c 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -42,12 +42,12 @@
#include "DNA_meshdata_types.h"
#include "DNA_ipo_types.h"
+#include "BLI_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_bpath.h"
#include "BLI_editVert.h"
#include "BLI_math.h"
#include "BLI_edgehash.h"
-#include "BLI_utildefines.h"
#include "BKE_animsys.h"
#include "BKE_main.h"
@@ -1292,11 +1292,11 @@ float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]
{
int i, numVerts = me->totvert;
float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1");
-
+
if (numVerts_r) *numVerts_r = numVerts;
for (i=0; i<numVerts; i++)
- VECCOPY(cos[i], me->mvert[i].co);
-
+ copy_v3_v3(cos[i], me->mvert[i].co);
+
return cos;
}
@@ -1589,7 +1589,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
mesh_loops_to_mface_corners(fdata, ldata, pdata,
lindex, k, i, 3,
numTex, numCol, hasWCol);
- test_index_face(mf, fdata, totface, 3);
+ test_index_face(mf, fdata, k, 3);
}
else {
/*sort loop indices to ensure winding is correct*/
@@ -1609,7 +1609,7 @@ int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
mesh_loops_to_mface_corners(fdata, ldata, pdata,
lindex, k, i, 4,
numTex, numCol, hasWCol);
- test_index_face(mf, fdata, totface, 4);
+ test_index_face(mf, fdata, k, 4);
}
mf->edcode= 0;
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 3b1dc2973ad..bb8e420451f 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -981,7 +981,7 @@ static void movieclip_build_proxy_ibuf(MovieClip *clip, ImBuf *ibuf, int cfra, i
{
char name[FILE_MAX];
int quality, rectx, recty;
- int size= size= rendersize_to_number(proxy_render_size);
+ int size= rendersize_to_number(proxy_render_size);
ImBuf *scaleibuf;
get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 359470eecf2..96ee2bd0349 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -159,7 +159,6 @@ void ntreeInitTypes(bNodeTree *ntree)
static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char *name, int type)
{
- bNodeSocketType *stype= ntreeGetSocketType(type);
bNodeSocket *sock;
sock= MEM_callocN(sizeof(bNodeSocket), "sock");
@@ -169,8 +168,8 @@ static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char
sock->type= type;
sock->storage = NULL;
- if (stype->value_structsize > 0)
- sock->default_value = MEM_callocN(stype->value_structsize, "default socket value");
+ sock->default_value = node_socket_make_default_value(type);
+ node_socket_init_default_value(type, sock->default_value);
return sock;
}
@@ -216,8 +215,7 @@ void nodeRemoveSocket(bNodeTree *ntree, bNode *node, bNodeSocket *sock)
BLI_remlink(&node->inputs, sock);
BLI_remlink(&node->outputs, sock);
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
MEM_freeN(sock);
node->update |= NODE_UPDATE;
@@ -236,13 +234,10 @@ void nodeRemoveAllSockets(bNodeTree *ntree, bNode *node)
}
for (sock=node->inputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&node->inputs);
for (sock=node->outputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
-
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&node->outputs);
node->update |= NODE_UPDATE;
@@ -396,7 +391,8 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node)
oldsock->new_sock= sock;
sock->stack_index= 0;
- sock->default_value = (oldsock->default_value ? MEM_dupallocN(oldsock->default_value) : NULL);
+ sock->default_value = node_socket_make_default_value(oldsock->type);
+ node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value);
/* XXX some compositor node (e.g. image, render layers) still store
* some persistent buffer data here, need to clear this to avoid dangling pointers.
@@ -410,7 +406,8 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node)
oldsock->new_sock= sock;
sock->stack_index= 0;
- sock->default_value = (oldsock->default_value ? MEM_dupallocN(oldsock->default_value) : NULL);
+ sock->default_value = node_socket_make_default_value(oldsock->type);
+ node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value);
/* XXX some compositor node (e.g. image, render layers) still store
* some persistent buffer data here, need to clear this to avoid dangling pointers.
@@ -658,13 +655,15 @@ bNodeTree *ntreeCopyTree(bNodeTree *ntree)
for(gsock= newtree->inputs.first, oldgsock= ntree->inputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) {
oldgsock->new_sock= gsock;
gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL);
- gsock->default_value = (oldgsock->default_value ? MEM_dupallocN(oldgsock->default_value) : NULL);
+ gsock->default_value = node_socket_make_default_value(oldgsock->type);
+ node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value);
}
BLI_duplicatelist(&newtree->outputs, &ntree->outputs);
for(gsock= newtree->outputs.first, oldgsock= ntree->outputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) {
oldgsock->new_sock= gsock;
gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL);
- gsock->default_value = (oldgsock->default_value ? MEM_dupallocN(oldgsock->default_value) : NULL);
+ gsock->default_value = node_socket_make_default_value(oldgsock->type);
+ node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value);
}
/* copy links */
@@ -790,16 +789,11 @@ void nodeAddToPreview(bNode *node, float *col, int x, int y, int do_manage)
unsigned char *tar= preview->rect+ 4*((preview->xsize*y) + x);
if(do_manage) {
- tar[0]= FTOCHAR(linearrgb_to_srgb(col[0]));
- tar[1]= FTOCHAR(linearrgb_to_srgb(col[1]));
- tar[2]= FTOCHAR(linearrgb_to_srgb(col[2]));
+ linearrgb_to_srgb_uchar4(tar, col);
}
else {
- tar[0]= FTOCHAR(col[0]);
- tar[1]= FTOCHAR(col[1]);
- tar[2]= FTOCHAR(col[2]);
+ rgba_float_to_uchar(tar, col);
}
- tar[3]= FTOCHAR(col[3]);
}
//else printf("prv out bound x y %d %d\n", x, y);
}
@@ -868,14 +862,12 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node)
for (sock=node->inputs.first; sock; sock = nextsock) {
nextsock = sock->next;
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
MEM_freeN(sock);
}
for (sock=node->outputs.first; sock; sock = nextsock) {
nextsock = sock->next;
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
MEM_freeN(sock);
}
@@ -929,12 +921,10 @@ void ntreeFreeTree(bNodeTree *ntree)
}
for (sock=ntree->inputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&ntree->inputs);
for (sock=ntree->outputs.first; sock; sock=sock->next)
- if (sock->default_value)
- MEM_freeN(sock->default_value);
+ node_socket_free_default_value(sock->type, sock->default_value);
BLI_freelistN(&ntree->outputs);
}
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index fe848f3d76c..2b3f792f777 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -66,6 +66,11 @@ Paint *paint_get_active(Scene *sce)
return &ts->wpaint->paint;
case OB_MODE_TEXTURE_PAINT:
return &ts->imapaint.paint;
+ case OB_MODE_EDIT:
+ if(ts->use_uv_sculpt)
+ return &ts->uvsculpt->paint;
+ else
+ return &ts->imapaint.paint;
}
}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 7ea4fd751c4..d6b85b80f20 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -304,6 +304,10 @@ void free_scene(Scene *sce)
free_paint(&sce->toolsettings->sculpt->paint);
MEM_freeN(sce->toolsettings->sculpt);
}
+ if(sce->toolsettings->uvsculpt) {
+ free_paint(&sce->toolsettings->uvsculpt->paint);
+ MEM_freeN(sce->toolsettings->uvsculpt);
+ }
free_paint(&sce->toolsettings->imapaint.paint);
MEM_freeN(sce->toolsettings);
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 71377799651..08b53115919 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -1690,10 +1690,10 @@ static ImBuf * input_preprocess(
if(rct) {
float rgb[3];
for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) {
- rgb_byte_to_float(rct, rgb);
+ rgb_uchar_to_float(rgb, rct);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb, rgb+1, rgb+2);
- rgb_float_to_byte(rgb, rct);
+ rgb_float_to_uchar(rct, rgb);
}
}
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 8d20a06d009..46a3f776e43 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -3468,7 +3468,7 @@ static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff,Object *
bs->len= globallen((bp-dw-dv-1)->vec, bp->vec,ob);
bs++;
}
- if( (v < lt->pntsv-1) && (u) ) {
+ if( (v < lt->pntsv-1) && (u != 0) ) {
bs->v1 = bpc;
bs->v2 = bpc-dw+dv-1;
bs->springtype=SB_BEND;
@@ -3485,7 +3485,7 @@ static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff,Object *
bs->len= globallen((bp+dw-dv-1)->vec, bp->vec,ob);
bs++;
}
- if( (v < lt->pntsv-1) && (u) ) {
+ if( (v < lt->pntsv-1) && (u != 0) ) {
bs->v1 = bpc;
bs->v2 = bpc+dw+dv-1;
bs->springtype=SB_BEND;
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index f7acdc78749..e4fa2bde63b 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -92,9 +92,17 @@ static void arena_release(CCGAllocatorHDL a) {
BLI_memarena_free(a);
}
-static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAging, int useArena, int UNUSED(useFlatSubdiv)) {
+typedef enum {
+ CCG_USE_AGING = 1,
+ CCG_USE_ARENA = 2,
+ CCG_CALC_NORMALS = 4,
+} CCGFlags;
+
+static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, CCGFlags flags) {
CCGMeshIFC ifc;
CCGSubSurf *ccgSS;
+ int useAging = !!(flags & CCG_USE_AGING);
+ int useArena = flags & CCG_USE_ARENA;
/* subdivLevels==0 is not allowed */
subdivLevels = MAX2(subdivLevels, 1);
@@ -102,7 +110,6 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin
if (prevSS) {
int oldUseAging;
- useAging = !!useAging;
ccgSubSurf_getUseAgeCounts(prevSS, &oldUseAging, NULL, NULL, NULL);
if (oldUseAging!=useAging) {
@@ -119,7 +126,7 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin
} else {
ifc.vertUserSize = ifc.edgeUserSize = ifc.faceUserSize = 8;
}
- ifc.vertDataSize = sizeof(DMGridData);
+ ifc.vertDataSize = sizeof(float) * (flags & CCG_CALC_NORMALS ? 6 : 3);
if (useArena) {
CCGAllocatorIFC allocatorIFC;
@@ -139,7 +146,10 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin
ccgSubSurf_setUseAgeCounts(ccgSS, 1, 8, 8, 8);
}
- ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, no));
+ if (flags & CCG_CALC_NORMALS)
+ ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, no));
+ else
+ ccgSubSurf_setCalcVertexNormals(ccgSS, 0, 0);
return ccgSS;
}
@@ -322,7 +332,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
return;
/* create a CCGSubSurf from uv's */
- uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), 0, 1, 0);
+ uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), CCG_USE_ARENA);
if(!ss_sync_from_uv(uvss, ss, dm, dmtface)) {
ccgSubSurf_free(uvss);
@@ -353,14 +363,14 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
int numVerts = ccgSubSurf_getFaceNumVerts(f);
for (S=0; S<numVerts; S++) {
- DMGridData *faceGridData= ccgSubSurf_getFaceGridDataArray(uvss, f, S);
+ float (*faceGridData)[3]= ccgSubSurf_getFaceGridDataArray(uvss, f, S);
for(y = 0; y < gridFaces; y++) {
for(x = 0; x < gridFaces; x++) {
- copy_v2_v2(tf->uv[0], faceGridData[(y + 0)*gridSize + x + 0].co);
- copy_v2_v2(tf->uv[1], faceGridData[(y + 1)*gridSize + x + 0].co);
- copy_v2_v2(tf->uv[2], faceGridData[(y + 1)*gridSize + x + 1].co);
- copy_v2_v2(tf->uv[3], faceGridData[(y + 0)*gridSize + x + 1].co);
+ copy_v2_v2(tf->uv[0], faceGridData[(y + 0)*gridSize + x + 0]);
+ copy_v2_v2(tf->uv[1], faceGridData[(y + 1)*gridSize + x + 0]);
+ copy_v2_v2(tf->uv[2], faceGridData[(y + 1)*gridSize + x + 1]);
+ copy_v2_v2(tf->uv[3], faceGridData[(y + 0)*gridSize + x + 1]);
tf++;
}
@@ -2773,7 +2783,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
int isFinalCalc, int forEditMode, int inEditMode)
{
int useSimple = smd->subdivType == ME_SIMPLE_SUBSURF;
- int useAging = smd->flags & eSubsurfModifierFlag_DebugIncr;
+ CCGFlags useAging = smd->flags & eSubsurfModifierFlag_DebugIncr ? CCG_USE_AGING : 0;
int useSubsurfUv = smd->flags & eSubsurfModifierFlag_SubsurfUv;
int drawInteriorEdges = !(smd->flags & eSubsurfModifierFlag_ControlEdges);
CCGDerivedMesh *result;
@@ -2781,8 +2791,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
if(forEditMode) {
int levels= (smd->modifier.scene)? get_render_subsurf_level(&smd->modifier.scene->r, smd->levels): smd->levels;
- smd->emCache = _getSubSurf(smd->emCache, levels, useAging, 0,
- useSimple);
+ smd->emCache = _getSubSurf(smd->emCache, levels, useAging|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(smd->emCache, dm, vertCos, useSimple);
result = getCCGDerivedMesh(smd->emCache,
@@ -2796,7 +2805,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
if(levels == 0)
return dm;
- ss = _getSubSurf(NULL, levels, 0, 1, useSimple);
+ ss = _getSubSurf(NULL, levels, CCG_USE_ARENA|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
@@ -2806,7 +2815,6 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
result->freeSS = 1;
} else {
int useIncremental = (smd->flags & eSubsurfModifierFlag_Incremental);
- int useAging = smd->flags & eSubsurfModifierFlag_DebugIncr;
int levels= (smd->modifier.scene)? get_render_subsurf_level(&smd->modifier.scene->r, smd->levels): smd->levels;
CCGSubSurf *ss;
@@ -2827,8 +2835,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
}
if(useIncremental && isFinalCalc) {
- smd->mCache = ss = _getSubSurf(smd->mCache, levels,
- useAging, 0, useSimple);
+ smd->mCache = ss = _getSubSurf(smd->mCache, levels, useAging|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
@@ -2841,7 +2848,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
smd->mCache = NULL;
}
- ss = _getSubSurf(NULL, levels, 0, 1, useSimple);
+ ss = _getSubSurf(NULL, levels, CCG_USE_ARENA|CCG_CALC_NORMALS);
ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
result = getCCGDerivedMesh(ss, drawInteriorEdges, useSubsurfUv, dm);
@@ -2863,7 +2870,7 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3])
* calculated vert positions is incorrect for the verts
* on the boundary of the mesh.
*/
- CCGSubSurf *ss = _getSubSurf(NULL, 1, 0, 1, 0);
+ CCGSubSurf *ss = _getSubSurf(NULL, 1, CCG_USE_ARENA);
float edge_sum[3], face_sum[3];
CCGVertIterator *vi;
DerivedMesh *dm = CDDM_from_mesh(me, NULL);
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 7e102bc9854..8e5cc8c48e3 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -33,6 +33,8 @@
#include <string.h> /* strstr */
#include <sys/types.h>
#include <sys/stat.h>
+#include <wchar.h>
+#include <wctype.h>
#include "MEM_guardedalloc.h"
@@ -215,8 +217,48 @@ Text *add_empty_text(const char *name)
return ta;
}
+/* this function replaces extended ascii characters */
+/* to a valid utf-8 sequences */
+int txt_extended_ascii_as_utf8(char **str)
+{
+ int bad_char, added= 0, i= 0;
+ int length = strlen(*str);
+
+ while ((*str)[i]) {
+ if((bad_char= BLI_utf8_invalid_byte(*str+i, length-i)) == -1)
+ break;
+
+ added++;
+ i+= bad_char + 1;
+ }
+
+ if (added != 0) {
+ char *newstr = MEM_mallocN(length+added+1, "text_line");
+ int mi = 0;
+ i= 0;
+
+ while ((*str)[i]) {
+ if((bad_char= BLI_utf8_invalid_byte((*str)+i, length-i)) == -1) {
+ memcpy(newstr+mi, (*str)+i, length - i + 1);
+ break;
+ }
+
+ memcpy(newstr+mi, (*str)+i, bad_char);
+
+ BLI_str_utf8_from_unicode((*str)[i+bad_char], newstr+mi+bad_char);
+ i+= bad_char+1;
+ mi+= bad_char+2;
+ }
+ newstr[length+added] = '\0';
+ MEM_freeN(*str);
+ *str = newstr;
+ }
+
+ return added;
+}
+
// this function removes any control characters from
-// a textline
+// a textline and fixes invalid utf-8 sequences
static void cleanup_textline(TextLine * tl)
{
@@ -229,6 +271,7 @@ static void cleanup_textline(TextLine * tl)
i--;
}
}
+ tl->len+= txt_extended_ascii_as_utf8(&tl->line);
}
int reopen_text(Text *text)
@@ -689,16 +732,10 @@ static void txt_make_dirty (Text *text)
}
/* 0:whitespace, 1:punct, 2:alphanumeric */
-static short txt_char_type (char ch)
-{
- if (ch <= ' ') return 0; /* 32 */
- if (ch <= '/') return 1; /* 47 */
- if (ch <= '9') return 2; /* 57 */
- if (ch <= '@') return 1; /* 64 */
- if (ch <= 'Z') return 2; /* 90 */
- if (ch == '_') return 2; /* 95, dont delimit '_' */
- if (ch <= '`') return 1; /* 96 */
- if (ch <= 'z') return 2; /* 122 */
+static short txt_char_type(unsigned int ch)
+{
+ if (iswspace(ch)) return 0;
+ if (iswalpha(ch) || iswdigit(ch)) return 2;
return 1;
}
@@ -731,9 +768,42 @@ static void txt_curs_first (Text *text, TextLine **linep, int *charp)
}
}
-/****************************/
+/*****************************/
/* Cursor movement functions */
-/****************************/
+/*****************************/
+
+int txt_utf8_offset_to_index(char *str, int offset)
+{
+ int index= 0, pos= 0;
+ while (pos != offset) {
+ pos += BLI_str_utf8_size(str + pos);
+ index++;
+ }
+ return index;
+}
+
+int txt_utf8_index_to_offset(char *str, int index)
+{
+ int offset= 0, pos= 0;
+ while (pos != index) {
+ offset += BLI_str_utf8_size(str + offset);
+ pos++;
+ }
+ return offset;
+}
+
+/* returns the real number of characters in string */
+/* not the same as BLI_strlen_utf8, which returns length for wide characters */
+static int txt_utf8_len(const char *src)
+{
+ int len;
+
+ for (len=0; *src; len++) {
+ src += BLI_str_utf8_size(src);
+ }
+
+ return len;
+}
void txt_move_up(Text *text, short sel)
{
@@ -747,13 +817,13 @@ void txt_move_up(Text *text, short sel)
old= *charp;
if((*linep)->prev) {
+ int index = txt_utf8_offset_to_index((*linep)->line, *charp);
*linep= (*linep)->prev;
- if (*charp > (*linep)->len) {
- *charp= (*linep)->len;
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, (*linep)->next), old, txt_get_span(text->lines.first, *linep), (unsigned short) *charp);
- } else {
- if(!undoing) txt_undo_add_op(text, sel?UNDO_SUP:UNDO_CUP);
- }
+ if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len;
+ else *charp= txt_utf8_index_to_offset((*linep)->line, index);
+
+ if(!undoing)
+ txt_undo_add_op(text, sel?UNDO_SUP:UNDO_CUP);
} else {
txt_move_bol(text, sel);
}
@@ -773,12 +843,13 @@ void txt_move_down(Text *text, short sel)
old= *charp;
if((*linep)->next) {
+ int index = txt_utf8_offset_to_index((*linep)->line, *charp);
*linep= (*linep)->next;
- if (*charp > (*linep)->len) {
- *charp= (*linep)->len;
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, (*linep)->prev), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
- } else
- if(!undoing) txt_undo_add_op(text, sel?UNDO_SDOWN:UNDO_CDOWN);
+ if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len;
+ else *charp= txt_utf8_index_to_offset((*linep)->line, index);
+
+ if(!undoing)
+ txt_undo_add_op(text, sel?UNDO_SDOWN:UNDO_CDOWN);
} else {
txt_move_eol(text, sel);
}
@@ -790,7 +861,7 @@ void txt_move_left(Text *text, short sel)
{
TextLine **linep;
int *charp, oundoing= undoing;
- int tabsize = 1, i=0;
+ int tabsize= 0, i= 0;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
@@ -799,32 +870,36 @@ void txt_move_left(Text *text, short sel)
undoing= 1;
- // do nice left only if there are only spaces
- // TXT_TABSIZE hardcoded in DNA_text_types.h
- if (text->flags & TXT_TABSTOSPACES) {
- tabsize = TXT_TABSIZE;
-
- if (*charp < tabsize)
- tabsize = *charp;
- else {
- for (i=0;i<(*charp);i++)
+ if (*charp== 0) {
+ if ((*linep)->prev) {
+ txt_move_up(text, sel);
+ *charp= (*linep)->len;
+ }
+ }
+ else {
+ // do nice left only if there are only spaces
+ // TXT_TABSIZE hardcoded in DNA_text_types.h
+ if (text->flags & TXT_TABSTOSPACES) {
+ tabsize= (*charp < TXT_TABSIZE) ? *charp : TXT_TABSIZE;
+
+ for (i=0; i<(*charp); i++)
if ((*linep)->line[i] != ' ') {
- tabsize = 1;
+ tabsize= 0;
break;
}
+
// if in the middle of the space-tab
- if ((*charp) % tabsize != 0)
- tabsize = ((*charp) % tabsize);
+ if (tabsize && (*charp) % TXT_TABSIZE != 0)
+ tabsize= ((*charp) % TXT_TABSIZE);
}
- }
-
- if (*charp== 0) {
- if ((*linep)->prev) {
- txt_move_up(text, sel);
- *charp= (*linep)->len;
+
+ if (tabsize)
+ (*charp)-= tabsize;
+ else {
+ const char *prev= BLI_str_prev_char_utf8((*linep)->line + *charp);
+ *charp= prev - (*linep)->line;
}
}
- else (*charp)-= tabsize;
undoing= oundoing;
if(!undoing) txt_undo_add_op(text, sel?UNDO_SLEFT:UNDO_CLEFT);
@@ -835,8 +910,7 @@ void txt_move_left(Text *text, short sel)
void txt_move_right(Text *text, short sel)
{
TextLine **linep;
- int *charp, oundoing= undoing;
- int tabsize=1, i=0;
+ int *charp, oundoing= undoing, do_tab= 0, i;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
@@ -845,32 +919,33 @@ void txt_move_right(Text *text, short sel)
undoing= 1;
- // do nice right only if there are only spaces
- // spaces hardcoded in DNA_text_types.h
- if (text->flags & TXT_TABSTOSPACES) {
- tabsize = TXT_TABSIZE;
-
- if ((*charp) + tabsize > (*linep)->len)
- tabsize = 1;
- else {
- for (i=0;i<(*charp) + tabsize - ((*charp) % tabsize);i++)
- if ((*linep)->line[i] != ' ') {
- tabsize = 1;
- break;
- }
- // if in the middle of the space-tab
- tabsize -= (*charp) % tabsize;
- }
- }
-
if (*charp== (*linep)->len) {
if ((*linep)->next) {
txt_move_down(text, sel);
*charp= 0;
}
- } else {
- (*charp)+=tabsize;
+ }
+ else {
+ // do nice right only if there are only spaces
+ // spaces hardcoded in DNA_text_types.h
+ if (text->flags & TXT_TABSTOSPACES && (*linep)->line[*charp]== ' ') {
+ do_tab= 1;
+ for (i=0; i<*charp; i++)
+ if ((*linep)->line[i]!= ' ') {
+ do_tab= 0;
+ break;
+ }
+ }
+
+ if (do_tab) {
+ int tabsize= (*charp) % TXT_TABSIZE + 1;
+ for (i=*charp+1; (*linep)->line[i]==' ' && tabsize<TXT_TABSIZE; i++)
+ tabsize++;
+ (*charp)= i;
+ }
+ else (*charp)+= BLI_str_utf8_size((*linep)->line + *charp);
}
+
undoing= oundoing;
if(!undoing) txt_undo_add_op(text, sel?UNDO_SRIGHT:UNDO_CRIGHT);
@@ -896,9 +971,12 @@ void txt_jump_left(Text *text, short sel)
count= 0;
for (i=0; i<3; i++) {
if (count < 2) {
- while (*charp>0 && txt_char_type((*linep)->line[*charp-1])==i) {
- txt_move_left(text, sel);
- count++;
+ while (*charp>0) {
+ char *sym= BLI_str_prev_char_utf8((*linep)->line + *charp);
+ if (txt_char_type(BLI_str_utf8_as_unicode(sym))==i) {
+ txt_move_left(text, sel);
+ count++;
+ } else break;
}
}
}
@@ -927,9 +1005,12 @@ void txt_jump_right(Text *text, short sel)
count= 0;
for (i=0; i<3; i++) {
if (count < 2) {
- while (*charp<(*linep)->len && txt_char_type((*linep)->line[*charp])==i) {
- txt_move_right(text, sel);
- count++;
+ while (*charp<(*linep)->len) {
+ char *sym= (*linep)->line + *charp;
+ if (txt_char_type(BLI_str_utf8_as_unicode(sym))==i) {
+ txt_move_right(text, sel);
+ count++;
+ } else break;
}
}
}
@@ -1014,6 +1095,7 @@ void txt_move_toline (Text *text, unsigned int line, short sel)
txt_move_to(text, line, 0, sel);
}
+/* Moves to a certain byte in a line, not a certain utf8-character! */
void txt_move_to (Text *text, unsigned int line, unsigned int ch, short sel)
{
TextLine **linep, *oldl;
@@ -1396,42 +1478,45 @@ static void txt_shift_markers(Text *text, int lineno, int count)
void txt_insert_buf(Text *text, const char *in_buffer)
{
- int i=0, l=0, j, u, len, lineno= -1, count= 0;
+ int l=0, u, len, lineno= -1, count= 0;
+ size_t i=0, j;
TextLine *add;
+ char *buffer;
if (!text) return;
if (!in_buffer) return;
txt_delete_sel(text);
- if(!undoing) txt_undo_add_block (text, UNDO_IBLOCK, in_buffer);
+ len= strlen(in_buffer);
+ buffer= BLI_strdupn(in_buffer, len);
+ len+= txt_extended_ascii_as_utf8(&buffer);
+
+ if(!undoing) txt_undo_add_block(text, UNDO_IBLOCK, buffer);
u= undoing;
undoing= 1;
/* Read the first line (or as close as possible */
- while (in_buffer[i] && in_buffer[i]!='\n') {
- txt_add_raw_char(text, in_buffer[i]);
- i++;
- }
+ while (buffer[i] && buffer[i]!='\n')
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &i));
- if (in_buffer[i]=='\n') txt_split_curline(text);
- else { undoing = u; return; }
+ if (buffer[i]=='\n') txt_split_curline(text);
+ else { undoing = u; MEM_freeN(buffer); return; }
i++;
/* Read as many full lines as we can */
- len= strlen(in_buffer);
lineno= txt_get_span(text->lines.first, text->curl);
while (i<len) {
l=0;
- while (in_buffer[i] && in_buffer[i]!='\n') {
+ while (buffer[i] && buffer[i]!='\n') {
i++; l++;
}
- if(in_buffer[i]=='\n') {
- add= txt_new_linen(in_buffer +(i-l), l);
+ if(buffer[i]=='\n') {
+ add= txt_new_linen(buffer +(i-l), l);
BLI_insertlinkbefore(&text->lines, text->curl, add);
i++;
count++;
@@ -1441,21 +1526,19 @@ void txt_insert_buf(Text *text, const char *in_buffer)
count= 0;
}
- for (j= i-l; j<i && j<(int)strlen(in_buffer); j++) {
- txt_add_raw_char(text, in_buffer[j]);
- }
+ for (j= i-l; j<i && j<len; )
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &j));
break;
}
}
+
+ MEM_freeN(buffer);
if(count) {
txt_shift_markers(text, lineno, count);
- count= 0;
}
undoing= u;
-
- (void)count;
}
/******************/
@@ -1525,12 +1608,30 @@ void txt_print_undo(Text *text)
ops= "Selection ";
} else if (op==UNDO_CTO) {
ops= "Cursor ";
- } else if (op==UNDO_INSERT) {
- ops= "Insert";
- } else if (op==UNDO_BS) {
- ops= "Backspace";
- } else if (op==UNDO_DEL) {
- ops= "Delete";
+ } else if (op==UNDO_INSERT_1) {
+ ops= "Insert ascii ";
+ } else if (op==UNDO_INSERT_2) {
+ ops= "Insert 2 bytes ";
+ } else if (op==UNDO_INSERT_3) {
+ ops= "Insert 3 bytes ";
+ } else if (op==UNDO_INSERT_4) {
+ ops= "Insert unicode ";
+ } else if (op==UNDO_BS_1) {
+ ops= "Backspace for ascii ";
+ } else if (op==UNDO_BS_2) {
+ ops= "Backspace for 2 bytes ";
+ } else if (op==UNDO_BS_3) {
+ ops= "Backspace for 3 bytes ";
+ } else if (op==UNDO_BS_4) {
+ ops= "Backspace for unicode ";
+ } else if (op==UNDO_DEL_1) {
+ ops= "Delete ascii ";
+ } else if (op==UNDO_DEL_2) {
+ ops= "Delete 2 bytes ";
+ } else if (op==UNDO_DEL_3) {
+ ops= "Delete 3 bytes ";
+ } else if (op==UNDO_DEL_4) {
+ ops= "Delete unicode ";
} else if (op==UNDO_SWAP) {
ops= "Cursor swap";
} else if (op==UNDO_DBLOCK) {
@@ -1550,10 +1651,35 @@ void txt_print_undo(Text *text)
}
printf ("Op (%o) at %d = %s", op, i, ops);
- if (op==UNDO_INSERT || op==UNDO_BS || op==UNDO_DEL) {
- i++;
- printf (" - Char is %c", text->undo_buf[i]);
+ if (op >= UNDO_INSERT_1 && op <= UNDO_DEL_4) {
i++;
+ printf (" - Char is ");
+ switch (op) {
+ case UNDO_INSERT_1: case UNDO_BS_1: case UNDO_DEL_1:
+ printf ("%c", text->undo_buf[i]);
+ i++;
+ break;
+ case UNDO_INSERT_2: case UNDO_BS_2: case UNDO_DEL_2:
+ printf ("%c%c", text->undo_buf[i], text->undo_buf[i+1]);
+ i+=2;
+ break;
+ case UNDO_INSERT_3: case UNDO_BS_3: case UNDO_DEL_3:
+ printf ("%c%c%c", text->undo_buf[i], text->undo_buf[i+1], text->undo_buf[i+2]);
+ i+=3;
+ break;
+ case UNDO_INSERT_4: case UNDO_BS_4: case UNDO_DEL_4: {
+ unsigned int uc;
+ char c[BLI_UTF8_MAX+1];
+ size_t c_len;
+ uc= text->undo_buf[i]; i++;
+ uc= uc+(text->undo_buf[i]<<8); i++;
+ uc= uc+(text->undo_buf[i]<<16); i++;
+ uc= uc+(text->undo_buf[i]<<24); i++;
+ c_len= BLI_str_utf8_from_unicode(uc, c);
+ c[c_len]= '\0';
+ printf ("%s", c);
+ }
+ }
} else if (op==UNDO_STO || op==UNDO_CTO) {
i++;
@@ -1635,40 +1761,43 @@ static void txt_undo_add_op(Text *text, int op)
text->undo_buf[text->undo_pos+1]= 0;
}
+static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short value)
+{
+ undo_buf[*undo_pos]= (value)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>8)&0xff;
+ (*undo_pos)++;
+}
+
+static void txt_undo_store_uint32(char *undo_buf, int *undo_pos, unsigned int value)
+{
+ undo_buf[*undo_pos]= (value)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>8)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>16)&0xff;
+ (*undo_pos)++;
+ undo_buf[*undo_pos]= (value>>24)&0xff;
+ (*undo_pos)++;
+}
+
static void txt_undo_add_block(Text *text, int op, const char *buf)
{
- int length;
-
- length= strlen(buf);
+ unsigned int length= strlen(buf);
if(!max_undo_test(text, length+11))
return;
text->undo_pos++;
text->undo_buf[text->undo_pos]= op;
-
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>24)&0xff;
-
text->undo_pos++;
+
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length);
+
strncpy(text->undo_buf+text->undo_pos, buf, length);
text->undo_pos+=length;
- text->undo_buf[text->undo_pos]= (length)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (length>>24)&0xff;
-
- text->undo_pos++;
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, length);
text->undo_buf[text->undo_pos]= op;
text->undo_buf[text->undo_pos+1]= 0;
@@ -1685,51 +1814,143 @@ void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fr
text->undo_buf[text->undo_pos]= op;
text->undo_pos++;
- text->undo_buf[text->undo_pos]= (fromc)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (fromc>>8)&0xff;
+
+ txt_undo_store_uint16(text->undo_buf, &text->undo_pos, fromc);
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, froml);
+ txt_undo_store_uint16(text->undo_buf, &text->undo_pos, toc);
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, tol);
+
+ text->undo_buf[text->undo_pos]= op;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (froml>>24)&0xff;
+ text->undo_buf[text->undo_pos+1]= 0;
+}
+static void txt_undo_add_charop(Text *text, int op_start, unsigned int c)
+{
+ char utf8[BLI_UTF8_MAX];
+ size_t i, utf8_size = BLI_str_utf8_from_unicode(c, utf8);
+
+ if(!max_undo_test(text, 3 + utf8_size))
+ return;
+
text->undo_pos++;
- text->undo_buf[text->undo_pos]= (toc)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (toc>>8)&0xff;
+
+ if (utf8_size < 4) {
+ text->undo_buf[text->undo_pos]= op_start + utf8_size - 1;
+ text->undo_pos++;
+
+ for (i = 0; i < utf8_size; i++) {
+ text->undo_buf[text->undo_pos]= utf8[i];
+ text->undo_pos++;
+ }
+
+ text->undo_buf[text->undo_pos]= op_start + utf8_size - 1;
+ } else {
+ text->undo_buf[text->undo_pos]= op_start + 3;
+ text->undo_pos++;
+ txt_undo_store_uint32(text->undo_buf, &text->undo_pos, c);
+ text->undo_buf[text->undo_pos]= op_start + 3;
+ }
+
+ text->undo_buf[text->undo_pos+1]= 0;
+}
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol>>8)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol>>16)&0xff;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= (tol>>24)&0xff;
+static unsigned short txt_undo_read_uint16(const char *undo_buf, int *undo_pos)
+{
+ unsigned short val;
+ val= undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ return val;
+}
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= op;
+static unsigned int txt_undo_read_uint32(const char *undo_buf, int *undo_pos)
+{
+ unsigned int val;
+ val= undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ val= (val<<8)+undo_buf[*undo_pos]; (*undo_pos)--;
+ return val;
+}
- text->undo_buf[text->undo_pos+1]= 0;
+static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, short bytes)
+{
+ unsigned int unicode;
+ char utf8[BLI_UTF8_MAX+1];
+
+ switch (bytes) {
+ case 1: /* ascii */
+ unicode = undo_buf[*undo_pos]; (*undo_pos)--;
+ break;
+ case 2: /* 2-byte symbol */
+ utf8[2] = '\0';
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--;
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--;
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 3: /* 3-byte symbol */
+ utf8[3] = '\0';
+ utf8[2] = undo_buf[*undo_pos]; (*undo_pos)--;
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)--;
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)--;
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 4: /* 32-bit unicode symbol */
+ unicode= txt_undo_read_uint32(undo_buf, undo_pos);
+ }
+
+ return unicode;
}
-static void txt_undo_add_charop(Text *text, int op, char c)
+static unsigned short txt_redo_read_uint16(const char *undo_buf, int *undo_pos)
{
- if(!max_undo_test(text, 4))
- return;
+ unsigned short val;
+ val = undo_buf[*undo_pos]; (*undo_pos)++;
+ val = val+(undo_buf[*undo_pos]<<8); (*undo_pos)++;
+ return val;
+}
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= op;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= c;
- text->undo_pos++;
- text->undo_buf[text->undo_pos]= op;
- text->undo_buf[text->undo_pos+1]= 0;
+static unsigned int txt_redo_read_uint32(const char *undo_buf, int *undo_pos)
+{
+ unsigned int val;
+ val= undo_buf[*undo_pos]; (*undo_pos)++;
+ val= val+(undo_buf[*undo_pos]<<8); (*undo_pos)++;
+ val= val+(undo_buf[*undo_pos]<<16); (*undo_pos)++;
+ val= val+(undo_buf[*undo_pos]<<24); (*undo_pos)++;
+ return val;
+}
+
+static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, short bytes)
+{
+ unsigned int unicode;
+ char utf8[BLI_UTF8_MAX+1];
+
+ switch (bytes) {
+ case 1: /* ascii */
+ unicode = undo_buf[*undo_pos]; (*undo_pos)++;
+ break;
+ case 2: /* 2-byte symbol */
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[2] = '\0';
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 3: /* 3-byte symbol */
+ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[1] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[2] = undo_buf[*undo_pos]; (*undo_pos)++;
+ utf8[3] = '\0';
+ unicode= BLI_str_utf8_as_unicode(utf8);
+ break;
+ case 4: /* 32-bit unicode symbol */
+ unicode= txt_undo_read_uint32(undo_buf, undo_pos);
+ default:
+ /* should never happen */
+ BLI_assert(0);
+ unicode= 0;
+ }
+
+ return unicode;
}
void txt_do_undo(Text *text)
@@ -1792,13 +2013,8 @@ void txt_do_undo(Text *text)
text->undo_pos--;
text->undo_pos--;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
-
- charp= text->undo_buf[text->undo_pos]; text->undo_pos--;
- charp= (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
+ charp= txt_undo_read_uint16(text->undo_buf, &text->undo_pos);
if (op==UNDO_CTO) {
txt_move_toline(text, linep, 0);
@@ -1812,23 +2028,23 @@ void txt_do_undo(Text *text)
text->undo_pos--;
break;
- case UNDO_INSERT:
+ case UNDO_INSERT_1: case UNDO_INSERT_2: case UNDO_INSERT_3: case UNDO_INSERT_4:
txt_backspace_char(text);
- text->undo_pos--;
+ text->undo_pos-= op - UNDO_INSERT_1 + 1;
text->undo_pos--;
break;
- case UNDO_BS:
- txt_add_char(text, text->undo_buf[text->undo_pos]);
+ case UNDO_BS_1: case UNDO_BS_2: case UNDO_BS_3: case UNDO_BS_4:
+ charp = op - UNDO_BS_1 + 1;
+ txt_add_char(text, txt_undo_read_unicode(text->undo_buf, &text->undo_pos, charp));
text->undo_pos--;
- text->undo_pos--;
- break;
-
- case UNDO_DEL:
- txt_add_char(text, text->undo_buf[text->undo_pos]);
+ break;
+
+ case UNDO_DEL_1: case UNDO_DEL_2: case UNDO_DEL_3: case UNDO_DEL_4:
+ charp = op - UNDO_DEL_1 + 1;
+ txt_add_char(text, txt_undo_read_unicode(text->undo_buf, &text->undo_pos, charp));
txt_move_left(text, 0);
text->undo_pos--;
- text->undo_pos--;
break;
case UNDO_SWAP:
@@ -1836,10 +2052,7 @@ void txt_do_undo(Text *text)
break;
case UNDO_DBLOCK:
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
buf= MEM_mallocN(linep+1, "dblock buffer");
for (i=0; i < linep; i++){
@@ -1863,25 +2076,31 @@ void txt_do_undo(Text *text)
}
text->curc= holdc;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ text->undo_pos--;
+ text->undo_pos--;
+ text->undo_pos--;
+ text->undo_pos--;
text->undo_pos--;
break;
case UNDO_IBLOCK:
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep= (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
-
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
txt_delete_sel(text);
+
+ /* txt_backspace_char removes utf8-characters, not bytes */
+ buf= MEM_mallocN(linep+1, "iblock buffer");
+ for (i=0; i < linep; i++){
+ buf[(linep-1)-i]= text->undo_buf[text->undo_pos];
+ text->undo_pos--;
+ }
+ buf[i]= 0;
+ linep= txt_utf8_len(buf);
+ MEM_freeN(buf);
+
while (linep>0) {
txt_backspace_char(text);
- text->undo_pos--;
linep--;
}
@@ -1897,30 +2116,23 @@ void txt_do_undo(Text *text)
case UNDO_UNINDENT:
case UNDO_COMMENT:
case UNDO_UNCOMMENT:
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
//linep is now the end line of the selection
- charp = text->undo_buf[text->undo_pos]; text->undo_pos--;
- charp = (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos);
//charp is the last char selected or text->line->len
- //set the selcetion for this now
+
+ //set the selection for this now
text->selc = charp;
text->sell = text->lines.first;
for (i= 0; i < linep; i++) {
text->sell = text->sell->next;
}
- linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
- linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep= txt_undo_read_uint32(text->undo_buf, &text->undo_pos);
//first line to be selected
- charp = text->undo_buf[text->undo_pos]; text->undo_pos--;
- charp = (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ charp = txt_undo_read_uint16(text->undo_buf, &text->undo_pos);
//first postion to be selected
text->curc = charp;
text->curl = text->lines.first;
@@ -2014,22 +2226,22 @@ void txt_do_redo(Text *text)
txt_move_down(text, 1);
break;
- case UNDO_INSERT:
- text->undo_pos++;
- txt_add_char(text, text->undo_buf[text->undo_pos]);
+ case UNDO_INSERT_1: case UNDO_INSERT_2: case UNDO_INSERT_3: case UNDO_INSERT_4:
text->undo_pos++;
+ charp = op - UNDO_INSERT_1 + 1;
+ txt_add_char(text, txt_redo_read_unicode(text->undo_buf, &text->undo_pos, charp));
break;
- case UNDO_BS:
+ case UNDO_BS_1: case UNDO_BS_2: case UNDO_BS_3: case UNDO_BS_4:
text->undo_pos++;
txt_backspace_char(text);
- text->undo_pos++;
+ text->undo_pos+= op - UNDO_BS_1 + 1;
break;
- case UNDO_DEL:
+ case UNDO_DEL_1: case UNDO_DEL_2: case UNDO_DEL_3: case UNDO_DEL_4:
text->undo_pos++;
txt_delete_char(text);
- text->undo_pos++;
+ text->undo_pos+= op - UNDO_DEL_1 + 1;
break;
case UNDO_SWAP:
@@ -2049,15 +2261,8 @@ void txt_do_redo(Text *text)
text->undo_pos++;
- charp= text->undo_buf[text->undo_pos];
- text->undo_pos++;
- charp= charp+(text->undo_buf[text->undo_pos]<<8);
-
- text->undo_pos++;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ charp= txt_redo_read_uint16(text->undo_buf, &text->undo_pos);
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
if (op==UNDO_CTO) {
txt_move_toline(text, linep, 0);
@@ -2072,12 +2277,9 @@ void txt_do_redo(Text *text)
case UNDO_DBLOCK:
text->undo_pos++;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
-
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
txt_delete_sel(text);
+
text->undo_pos+=linep;
text->undo_pos++;
@@ -2089,10 +2291,7 @@ void txt_do_redo(Text *text)
case UNDO_IBLOCK:
text->undo_pos++;
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
buf= MEM_mallocN(linep+1, "iblock buffer");
memcpy (buf, &text->undo_buf[text->undo_pos], linep);
@@ -2102,26 +2301,21 @@ void txt_do_redo(Text *text)
txt_insert_buf(text, buf);
MEM_freeN(buf);
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
- (void)linep;
-
+ text->undo_pos++;
+ text->undo_pos++;
+ text->undo_pos++;
+ text->undo_pos++;
break;
+
case UNDO_INDENT:
case UNDO_UNINDENT:
case UNDO_COMMENT:
case UNDO_UNCOMMENT:
text->undo_pos++;
- charp = text->undo_buf[text->undo_pos]; text->undo_pos++;
- charp = charp+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos);
//charp is the first char selected or 0
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
//linep is now the first line of the selection
//set the selcetion for this now
text->curc = charp;
@@ -2130,13 +2324,10 @@ void txt_do_redo(Text *text)
text->curl = text->curl->next;
}
- charp = text->undo_buf[text->undo_pos]; text->undo_pos++;
- charp = charp+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ charp = txt_redo_read_uint16(text->undo_buf, &text->undo_pos);
//last postion to be selected
- linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
- linep = linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+
+ linep= txt_redo_read_uint32(text->undo_buf, &text->undo_pos);
//Last line to be selected
text->selc = charp;
@@ -2203,8 +2394,7 @@ void txt_split_curline (Text *text)
left[text->curc]=0;
right= MEM_mallocN(text->curl->len - text->curc+1, "textline_string");
- if (text->curl->len - text->curc) memcpy(right, text->curl->line+text->curc, text->curl->len-text->curc);
- right[text->curl->len - text->curc]=0;
+ memcpy(right, text->curl->line+text->curc, text->curl->len-text->curc+1);
MEM_freeN(text->curl->line);
if (text->curl->format) MEM_freeN(text->curl->format);
@@ -2228,7 +2418,7 @@ void txt_split_curline (Text *text)
txt_clean_text(text);
txt_pop_sel(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_INSERT, '\n');
+ if(!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, '\n');
}
static void txt_delete_line (Text *text, TextLine *line)
@@ -2296,9 +2486,9 @@ static void txt_combine_lines (Text *text, TextLine *linea, TextLine *lineb)
txt_clean_text(text);
}
-void txt_delete_char (Text *text)
+void txt_delete_char(Text *text)
{
- char c='\n';
+ unsigned int c='\n';
if (!text) return;
if (!text->curl) return;
@@ -2314,12 +2504,14 @@ void txt_delete_char (Text *text)
txt_pop_sel(text);
}
} else { /* Just deleting a char */
- int i= text->curc;
+ size_t c_len = 0;
+ TextMarker *mrk;
+ c= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len);
- TextMarker *mrk= txt_find_marker_region(text, text->curl, i-1, text->curl->len, 0, 0);
+ mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0);
if (mrk) {
int lineno= mrk->lineno;
- if (mrk->end==i) {
+ if (mrk->end==text->curc) {
if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) {
txt_clear_markers(text, mrk->group, TMARK_TEMP);
} else {
@@ -2328,18 +2520,15 @@ void txt_delete_char (Text *text)
return;
}
do {
- if (mrk->start>i) mrk->start--;
- mrk->end--;
+ if (mrk->start>text->curc) mrk->start-= c_len;
+ mrk->end-= c_len;
mrk= mrk->next;
} while (mrk && mrk->lineno==lineno);
}
- c= text->curl->line[i];
- while(i< text->curl->len) {
- text->curl->line[i]= text->curl->line[i+1];
- i++;
- }
- text->curl->len--;
+ memmove(text->curl->line+text->curc, text->curl->line+text->curc+c_len, text->curl->len-text->curc-c_len+1);
+
+ text->curl->len-= c_len;
txt_pop_sel(text);
}
@@ -2347,7 +2536,7 @@ void txt_delete_char (Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_DEL, c);
+ if(!undoing) txt_undo_add_charop(text, UNDO_DEL_1, c);
}
void txt_delete_word (Text *text)
@@ -2358,7 +2547,7 @@ void txt_delete_word (Text *text)
void txt_backspace_char (Text *text)
{
- char c='\n';
+ unsigned int c='\n';
if (!text) return;
if (!text->curl) return;
@@ -2378,12 +2567,15 @@ void txt_backspace_char (Text *text)
txt_pop_sel(text);
}
else { /* Just backspacing a char */
- int i= text->curc-1;
+ size_t c_len = 0;
+ TextMarker *mrk;
+ char *prev = BLI_str_prev_char_utf8(text->curl->line + text->curc);
+ c= BLI_str_utf8_as_unicode_and_size(prev, &c_len);
- TextMarker *mrk= txt_find_marker_region(text, text->curl, i, text->curl->len, 0, 0);
+ mrk= txt_find_marker_region(text, text->curl, text->curc - c_len, text->curl->len, 0, 0);
if (mrk) {
int lineno= mrk->lineno;
- if (mrk->start==i+1) {
+ if (mrk->start==text->curc) {
if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) {
txt_clear_markers(text, mrk->group, TMARK_TEMP);
} else {
@@ -2392,19 +2584,16 @@ void txt_backspace_char (Text *text)
return;
}
do {
- if (mrk->start>i) mrk->start--;
- mrk->end--;
+ if (mrk->start>text->curc - c_len) mrk->start-= c_len;
+ mrk->end-= c_len;
mrk= mrk->next;
} while (mrk && mrk->lineno==lineno);
}
- c= text->curl->line[i];
- while(i< text->curl->len) {
- text->curl->line[i]= text->curl->line[i+1];
- i++;
- }
- text->curl->len--;
- text->curc--;
+ memcpy(text->curl->line + text->curc - c_len, text->curl->line + text->curc, text->curl->len-text->curc+1);
+
+ text->curl->len-= c_len;
+ text->curc-= c_len;
txt_pop_sel(text);
}
@@ -2412,7 +2601,7 @@ void txt_backspace_char (Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_BS, c);
+ if(!undoing) txt_undo_add_charop(text, UNDO_BS_1, c);
}
void txt_backspace_word (Text *text)
@@ -2436,11 +2625,12 @@ static void txt_convert_tab_to_spaces (Text *text)
txt_insert_buf(text, sb);
}
-static int txt_add_char_intern (Text *text, char add, int replace_tabs)
+static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs)
{
- int len, lineno;
- char *tmp;
+ int lineno;
+ char *tmp, ch[BLI_UTF8_MAX];
TextMarker *mrk;
+ size_t add_len;
if (!text) return 0;
if (!text->curl) return 0;
@@ -2458,43 +2648,42 @@ static int txt_add_char_intern (Text *text, char add, int replace_tabs)
txt_delete_sel(text);
+ add_len = BLI_str_utf8_from_unicode(add, ch);
mrk= txt_find_marker_region(text, text->curl, text->curc-1, text->curl->len, 0, 0);
if (mrk) {
lineno= mrk->lineno;
do {
- if (mrk->start>text->curc) mrk->start++;
- mrk->end++;
+ if (mrk->start>text->curc) mrk->start+= add_len;
+ mrk->end+= add_len;
mrk= mrk->next;
} while (mrk && mrk->lineno==lineno);
}
- tmp= MEM_mallocN(text->curl->len+2, "textline_string");
+ tmp= MEM_mallocN(text->curl->len+add_len+1, "textline_string");
- if(text->curc) memcpy(tmp, text->curl->line, text->curc);
- tmp[text->curc]= add;
-
- len= text->curl->len - text->curc;
- if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len);
- tmp[text->curl->len+1]=0;
+ memcpy(tmp, text->curl->line, text->curc);
+ memcpy(tmp+text->curc, ch, add_len);
+ memcpy(tmp+text->curc+add_len, text->curl->line+text->curc, text->curl->len-text->curc+1);
+
make_new_line(text->curl, tmp);
- text->curc++;
+ text->curc+= add_len;
txt_pop_sel(text);
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_INSERT, add);
+ if(!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, add);
return 1;
}
-int txt_add_char (Text *text, char add)
+int txt_add_char (Text *text, unsigned int add)
{
return txt_add_char_intern(text, add, text->flags & TXT_TABSTOSPACES);
}
-int txt_add_raw_char (Text *text, char add)
+int txt_add_raw_char (Text *text, unsigned int add)
{
return txt_add_char_intern(text, add, 0);
}
@@ -2505,34 +2694,48 @@ void txt_delete_selected(Text *text)
txt_make_dirty(text);
}
-int txt_replace_char (Text *text, char add)
+int txt_replace_char (Text *text, unsigned int add)
{
- char del;
+ unsigned int del;
+ size_t del_size = 0, add_size;
+ char ch[BLI_UTF8_MAX];
if (!text) return 0;
if (!text->curl) return 0;
/* If text is selected or we're at the end of the line just use txt_add_char */
if (text->curc==text->curl->len || txt_has_sel(text) || add=='\n') {
- TextMarker *mrk;
int i= txt_add_char(text, add);
- mrk= txt_find_marker(text, text->curl, text->curc, 0, 0);
- if (mrk && mrk->end==text->curc) mrk->end--;
+ TextMarker *mrk= txt_find_marker(text, text->curl, text->curc, 0, 0);
+ if (mrk) BLI_freelinkN(&text->markers, mrk);
return i;
}
- del= text->curl->line[text->curc];
- text->curl->line[text->curc]= (unsigned char) add;
- text->curc++;
- txt_pop_sel(text);
+ del= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size);
+ add_size= BLI_str_utf8_from_unicode(add, ch);
+ if (add_size > del_size) {
+ char *tmp= MEM_mallocN(text->curl->len+add_size-del_size+1, "textline_string");
+ memcpy(tmp, text->curl->line, text->curc);
+ memcpy(tmp+text->curc+add_size, text->curl->line+text->curc+del_size, text->curl->len-text->curc-del_size+1);
+ MEM_freeN(text->curl->line);
+ text->curl->line = tmp;
+ } else if (add_size < del_size) {
+ char *tmp= text->curl->line;
+ memmove(tmp+text->curc+add_size, tmp+text->curc+del_size, text->curl->len-text->curc-del_size+1);
+ }
+
+ memcpy(text->curl->line + text->curc, ch, add_size);
+ text->curc+= add_size;
+
+ txt_pop_sel(text);
txt_make_dirty(text);
txt_clean_text(text);
/* Should probably create a new op for this */
if(!undoing) {
- txt_undo_add_charop(text, UNDO_DEL, del);
- txt_undo_add_charop(text, UNDO_INSERT, add);
+ txt_undo_add_charop(text, UNDO_DEL_1, del);
+ txt_undo_add_charop(text, UNDO_INSERT_1, add);
}
return 1;
}
@@ -2548,15 +2751,19 @@ void txt_indent(Text *text)
/* hardcoded: TXT_TABSIZE = 4 spaces: */
int spaceslen = TXT_TABSIZE;
+ if (ELEM3(NULL, text, text->curl, text->sell)) {
+ return;
+ }
+
+ if (!text) return;
+ if (!text->curl) return;
+ if (!text->sell) return;
+
/* insert spaces rather than tabs */
if (text->flags & TXT_TABSTOSPACES){
add = tab_to_spaces;
indentlen = spaceslen;
}
-
- if (!text) return;
- if (!text->curl) return;
- if (!text->sell) return;
num = 0;
while (TRUE)
@@ -2609,16 +2816,16 @@ void txt_unindent(Text *text)
/* hardcoded: TXT_TABSIZE = 4 spaces: */
int spaceslen = TXT_TABSIZE;
+ if (!text) return;
+ if (!text->curl) return;
+ if (!text->sell) return;
+
/* insert spaces rather than tabs */
if (text->flags & TXT_TABSTOSPACES){
remove = tab_to_spaces;
indent = spaceslen;
}
- if (!text) return;
- if (!text->curl) return;
- if (!text->sell) return;
-
while(TRUE)
{
int i = 0;
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 6d37aabd6ab..f4d6882b5d8 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -91,6 +91,9 @@ MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4]);
MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4]);
MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4]);
+MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3]);
+MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4]);
+
void BLI_init_srgb_conversion(void);
/************************** Other *************************/
@@ -101,8 +104,10 @@ void minmax_rgb(short c[3]);
void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
-void rgb_byte_to_float(const unsigned char in[3], float out[3]);
-void rgb_float_to_byte(const float in[3], unsigned char out[3]);
+void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3]);
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4]);
+void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3]);
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]);
/***************** lift/gamma/gain / ASC-CDL conversion *****************/
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 27da6c1025d..8d18f5253c4 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -54,6 +54,8 @@ float area_tri_v3(const float a[3], const float b[3], const float c[3]);
float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]);
float area_poly_v3(int nr, float verts[][3], const float normal[3]);
+int is_quad_convex_v3(const float *v1, const float *v2, const float *v3, const float *v4);
+
/********************************* Distance **********************************/
float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2]);
@@ -221,6 +223,9 @@ void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3],
float n4[3], const float f_no[3], const float co1[3], const float co2[3],
const float co3[3], const float co4[3]);
+void accumulate_vertex_normals_poly(float **vertnos, float polyno[3],
+ float **vertcos, float vdiffs[][3], int nverts);
+
/********************************* Tangents **********************************/
typedef struct VertexTangent {
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index e9e44ed7b2c..12a0b1892a1 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -116,9 +116,10 @@ MINLINE void star_m3_v3(float rmat[3][3],float a[3]);
/*********************************** Length **********************************/
+MINLINE float len_squared_v2(const float v[2]);
MINLINE float len_v2(const float a[2]);
MINLINE float len_v2v2(const float a[2], const float b[2]);
-MINLINE float len_squared_v2v2(const float a[3], const float b[3]);
+MINLINE float len_squared_v2v2(const float a[2], const float b[2]);
MINLINE float len_v3(const float a[3]);
MINLINE float len_v3v3(const float a[3], const float b[3]);
MINLINE float len_squared_v3v3(const float a[3], const float b[3]);
@@ -170,6 +171,7 @@ float angle_v3v3v3(const float a[3], const float b[3], const float c[3]);
float angle_normalized_v3v3(const float v1[3], const float v2[3]);
void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
+void angle_poly_v3(float* angles, const float* verts[3], int len);
/********************************* Geometry **********************************/
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 9f388b68c38..e10082348be 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -40,8 +40,8 @@
// #include "BLI_blenlib.h"
-#include "BLI_mempool.h"
#include "BLI_utildefines.h"
+#include "BLI_mempool.h"
#include "BLI_ghash.h"
#include "BLO_sys_types.h" // for intptr_t support
diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c
index 073b4b5d0c6..cf18fbd57cd 100644
--- a/source/blender/blenlib/intern/boxpack2d.c
+++ b/source/blender/blenlib/intern/boxpack2d.c
@@ -390,7 +390,7 @@ void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_he
} else if ( vert->trb && vert->brb &&
(box == vert->trb || box == vert->brb) ) {
if (vert->trb->w > vert->brb->w) {
- vert->brb->v[TR]->free &= ~(TRF|TRF);
+ vert->brb->v[TR]->free &= ~(TLF|TRF);
} else if (vert->trb->w < vert->brb->w) {
vert->trb->v[BR]->free &= ~(BLF|BRF);
} else { /*same*/
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 20df893015d..ca2aeca8f36 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -337,24 +337,29 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b)
*b /= 255.0f;
}
-void rgb_byte_to_float(const unsigned char in[3], float out[3])
+void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3])
{
- out[0]= ((float)in[0]) / 255.0f;
- out[1]= ((float)in[1]) / 255.0f;
- out[2]= ((float)in[2]) / 255.0f;
+ col_r[0]= ((float)col_ub[0]) / 255.0f;
+ col_r[1]= ((float)col_ub[1]) / 255.0f;
+ col_r[2]= ((float)col_ub[2]) / 255.0f;
}
-void rgb_float_to_byte(const float in[3], unsigned char out[3])
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4])
{
- int r, g, b;
-
- r= (int)(in[0] * 255.0f);
- g= (int)(in[1] * 255.0f);
- b= (int)(in[2] * 255.0f);
-
- out[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r);
- out[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g);
- out[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
+ col_r[0]= ((float)col_ub[0]) / 255.0f;
+ col_r[1]= ((float)col_ub[1]) / 255.0f;
+ col_r[2]= ((float)col_ub[2]) / 255.0f;
+ col_r[3]= ((float)col_ub[3]) / 255.0f;
+}
+
+void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3])
+{
+ F3TOCHAR3(col_f, col_r);
+}
+
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4])
+{
+ F4TOCHAR4(col_f, col_r);
}
/* ********************************* color transforms ********************************* */
@@ -490,9 +495,9 @@ void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset)
{
float rgb_float[3];
- rgb_byte_to_float(rgb, rgb_float);
+ rgb_uchar_to_float(rgb_float, rgb);
rgb_float_set_hue_float_offset(rgb_float, hue_offset);
- rgb_float_to_byte(rgb_float, rgb);
+ rgb_float_to_uchar(rgb, rgb_float);
}
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index 1247632cf79..386452ed592 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -62,6 +62,22 @@ MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
srgb[3] = linear[3];
}
+MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3])
+{
+ float srgb_f[3];
+
+ linearrgb_to_srgb_v3_v3(srgb_f, linear);
+ F3TOCHAR3(srgb_f, srgb);
+}
+
+MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
+{
+ float srgb_f[4];
+
+ linearrgb_to_srgb_v4(srgb_f, linear);
+ F4TOCHAR4(srgb_f, srgb);
+}
+
/* predivide versions to work on associated/premultipled alpha. if this should
be done or not depends on the background the image will be composited over,
ideally you would never do color space conversion on an image with alpha
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index ef04e5e9bce..d7880e40626 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2382,6 +2382,38 @@ void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3],
}
}
+/* Add weighted face normal component into normals of the face vertices.
+ Caller must pass pre-allocated vdiffs of nverts length. */
+void accumulate_vertex_normals_poly(float **vertnos, float polyno[3],
+ float **vertcos, float vdiffs[][3], int nverts)
+{
+ int i;
+
+ /* calculate normalized edge directions for each edge in the poly */
+ for (i = 0; i < nverts; i++) {
+ sub_v3_v3v3(vdiffs[i], vertcos[(i+1) % nverts], vertcos[i]);
+ normalize_v3(vdiffs[i]);
+ }
+
+ /* accumulate angle weighted face normal */
+ {
+ const float *prev_edge = vdiffs[nverts-1];
+ int i;
+
+ for(i=0; i<nverts; i++) {
+ const float *cur_edge = vdiffs[i];
+
+ /* calculate angle between the two poly edges incident on
+ this vertex */
+ const float fac= saacos(-dot_v3v3(cur_edge, prev_edge));
+
+ /* accumulate */
+ madd_v3_v3fl(vertnos[i], polyno, fac);
+ prev_edge = cur_edge;
+ }
+ }
+}
+
/********************************* Tangents **********************************/
/* For normal map tangents we need to detect uv boundaries, and only average
@@ -3038,3 +3070,26 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl
return contrib;
}
+
+/* evaluate if entire quad is a proper convex quad */
+ int is_quad_convex_v3(const float *v1, const float *v2, const float *v3, const float *v4)
+ {
+ float nor[3], nor1[3], nor2[3], vec[4][2];
+ int axis_a, axis_b;
+
+ /* define projection, do both trias apart, quad is undefined! */
+ normal_tri_v3(nor1, v1, v2, v3);
+ normal_tri_v3(nor2, v1, v3, v4);
+ add_v3_v3v3(nor, nor1, nor2);
+
+ axis_dominant_v3(&axis_a, &axis_b, nor);
+
+ vec[0][0]= v1[axis_a]; vec[0][1]= v1[axis_b];
+ vec[1][0]= v2[axis_a]; vec[1][1]= v2[axis_b];
+
+ vec[2][0]= v3[axis_a]; vec[2][1]= v3[axis_b];
+ vec[3][0]= v4[axis_a]; vec[3][1]= v4[axis_b];
+
+ /* linetests, the 2 diagonals have to instersect to be convex */
+ return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0) ? 1 : 0;
+}
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 5596b6f9f22..b0e6fe51810 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -811,7 +811,7 @@ void single_axis_angle_to_mat3(float mat[3][3], const char axis, const float ang
mat[2][2] = 1.0f;
break;
default:
- assert("invalid axis");
+ assert(0);
}
}
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 590a48e8085..47deb705def 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -239,6 +239,20 @@ void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const
angles[3]= (float)M_PI - angle_normalized_v3v3(ed4, ed1);
}
+void angle_poly_v3(float *angles, const float *verts[3], int len)
+{
+ int i;
+ float vec[3][3];
+
+ sub_v3_v3v3(vec[2], verts[len-1], verts[0]);
+ normalize_v3(vec[2]);
+ for (i = 0; i < len; i++) {
+ sub_v3_v3v3(vec[i%3], verts[i%len], verts[(i+1)%len]);
+ normalize_v3(vec[i%3]);
+ angles[i] = (float)M_PI - angle_normalized_v3v3(vec[(i+2)%3], vec[i%3]);
+ }
+}
+
/********************************* Geometry **********************************/
/* Project v1 on v2 */
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 4570bd5e99e..9c5d8f3261f 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -429,6 +429,11 @@ MINLINE void star_m3_v3(float rmat[][3], float a[3])
/*********************************** Length **********************************/
+MINLINE float len_squared_v2(const float v[2])
+{
+ return v[0]*v[0] + v[1]*v[1];
+}
+
MINLINE float len_v2(const float v[2])
{
return (float)sqrtf(v[0]*v[0] + v[1]*v[1]);
@@ -448,7 +453,7 @@ MINLINE float len_v3(const float a[3])
return sqrtf(dot_v3v3(a, a));
}
-MINLINE float len_squared_v2v2(const float a[3], const float b[3])
+MINLINE float len_squared_v2v2(const float a[2], const float b[2])
{
float d[2];
@@ -510,6 +515,29 @@ MINLINE float normalize_v3_v3(float r[3], const float a[3])
return d;
}
+MINLINE double normalize_v3_d(double n[3])
+{
+ double d= n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
+
+ /* a larger value causes normalize errors in a
+ scaled down models with camera xtreme close */
+ if(d > 1.0e-35) {
+ double mul;
+
+ d= sqrt(d);
+ mul = 1.0 / d;
+
+ n[0] *= mul;
+ n[1] *= mul;
+ n[2] *= mul;
+ } else {
+ n[0] = n[1] = n[2] = 0;
+ d= 0.0;
+ }
+
+ return d;
+}
+
MINLINE float normalize_v3(float n[3])
{
return normalize_v3_v3(n, n);
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 38925ea5238..d63baca883e 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -65,7 +65,7 @@ typedef struct BlendFileData {
int fileflags;
int displaymode;
int globalf;
- char filename[240]; /* 240 = FILE_MAX */
+ char filename[1024]; /* 1024 = FILE_MAX */
struct bScreen* curscreen;
struct Scene* curscene;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fffe6a737a4..b28fba06ef2 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -98,9 +98,9 @@
#include "MEM_guardedalloc.h"
+#include "BLI_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
-#include "BLI_utildefines.h"
#include "BKE_anim.h"
#include "BKE_action.h"
@@ -136,6 +136,7 @@
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
+#include "BKE_text.h" // for txt_extended_ascii_as_utf8
#include "BKE_texture.h" // for open_plugin_tex
#include "BKE_tracking.h"
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
@@ -4716,7 +4717,7 @@ static void lib_link_scene(FileData *fd, Main *main)
link_paint(fd, sce, &sce->toolsettings->vpaint->paint);
link_paint(fd, sce, &sce->toolsettings->wpaint->paint);
link_paint(fd, sce, &sce->toolsettings->imapaint.paint);
-
+ link_paint(fd, sce, &sce->toolsettings->uvsculpt->paint);
sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
for(base= sce->base.first; base; base= next) {
@@ -4851,6 +4852,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
direct_link_paint(fd, (Paint**)&sce->toolsettings->sculpt);
direct_link_paint(fd, (Paint**)&sce->toolsettings->vpaint);
direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
+ direct_link_paint(fd, (Paint**)&sce->toolsettings->uvsculpt);
sce->toolsettings->imapaint.paintcursor= NULL;
sce->toolsettings->particle.paintcursor= NULL;
@@ -13162,6 +13164,49 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
}
+
+ if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 3))
+ {
+ {
+ /* convert extended ascii to utf-8 for text editor */
+ Text *text;
+ for (text= main->text.first; text; text= text->id.next)
+ if(!(text->flags & TXT_ISEXT)) {
+ TextLine *tl;
+
+ for (tl= text->lines.first; tl; tl= tl->next) {
+ int added= txt_extended_ascii_as_utf8(&tl->line);
+ tl->len+= added;
+
+ /* reset cursor position if line was changed */
+ if (added && tl == text->curl)
+ text->curc = 0;
+ }
+ }
+ }
+ {
+ /* set new dynamic paint values */
+ Object *ob;
+ for(ob = main->object.first; ob; ob = ob->id.next) {
+ ModifierData *md;
+ for(md= ob->modifiers.first; md; md= md->next) {
+ if (md->type == eModifierType_DynamicPaint) {
+ DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
+ if(pmd->canvas)
+ {
+ DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
+ for (; surface; surface=surface->next) {
+ surface->color_dry_threshold = 1.0f;
+ surface->influence_scale = 1.0f;
+ surface->radius_scale = 1.0f;
+ surface->flags |= MOD_DPAINT_USE_DRYING;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
/* put compatibility code here until next subversion bump */
{
@@ -14679,7 +14724,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
/* allow typing in a new lib path */
if(G.rt==-666) {
while(fd==NULL) {
- char newlib_path[240] = { 0 };
+ char newlib_path[FILE_MAX] = { 0 };
printf("Missing library...'\n");
printf(" current file: %s\n", G.main->name);
printf(" absolute lib: %s\n", mainptr->curlib->filepath);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 015b74e5a7d..5eb7034ed65 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -89,6 +89,9 @@ Any case: direct data is ALWAYS after the lib block
#include "BLI_winstuff.h"
#endif
+/* allow writefile to use deprecated functionality (for forward compatibility code) */
+#define DNA_DEPRECATED_ALLOW
+
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_actuator_types.h"
@@ -654,7 +657,7 @@ static void write_node_socket(WriteData *wd, bNodeSocket *sock)
/* forward compatibility code, so older blenders still open */
sock->stack_type = 1;
-
+
if(sock->default_value) {
bNodeSocketValueFloat *valfloat;
bNodeSocketValueVector *valvector;
@@ -1966,6 +1969,9 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
if(tos->sculpt) {
writestruct(wd, DATA, "Sculpt", 1, tos->sculpt);
}
+ if(tos->uvsculpt) {
+ writestruct(wd, DATA, "UvSculpt", 1, tos->uvsculpt);
+ }
// write_paint(wd, &tos->imapaint.paint);
diff --git a/source/blender/blenpluginapi/iff.h b/source/blender/blenpluginapi/iff.h
index 6bd4e5bb2b0..f07e80b36ce 100644
--- a/source/blender/blenpluginapi/iff.h
+++ b/source/blender/blenpluginapi/iff.h
@@ -63,7 +63,7 @@ typedef struct ImBuf {
int channels; /**< amount of channels in rect_float (0 = 4 channel default) */
float dither; /**< random dither value, for conversion from float -> byte rect */
short profile; /** color space/profile preset that the byte rect buffer represents */
- char profile_filename[256]; /** to be implemented properly, specific filename for custom profiles */
+ char profile_filename[1024]; /** to be implemented properly, specific filename for custom profiles */
/* mipmapping */
struct ImBuf *mipmap[IB_MIPMAP_LEVELS]; /**< MipMap levels, a series of halved images */
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index eab71323494..e6be35c48a7 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -187,7 +187,7 @@ static void acf_generic_channel_color(bAnimContext *ac, bAnimListElem *ale, floa
}
/* copy the colors over, transforming from bytes to floats */
- rgb_byte_to_float(cp, color);
+ rgb_uchar_to_float(color, cp);
}
else {
// FIXME: what happens when the indention is 1 greater than what it should be (due to grouping)?
diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index 32021447d6a..9122bc277d9 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -2429,20 +2429,21 @@ void ED_operatortypes_animchannels(void)
void ED_keymap_animchannels(wmKeyConfig *keyconf)
{
wmKeyMap *keymap = WM_keymap_find(keyconf, "Animation Channels", 0, 0);
-
+ wmKeyMapItem *kmi;
+
/* selection */
/* click-select */
// XXX for now, only leftmouse....
WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "children_only", 1);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "children_only", TRUE);
/* rename */
WM_keymap_add_item(keymap, "ANIM_OT_channels_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
/* deselect all */
WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", AKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", TRUE);
/* borderselect */
WM_keymap_add_item(keymap, "ANIM_OT_channels_select_border", BKEY, KM_PRESS, 0, 0);
@@ -2464,9 +2465,11 @@ void ED_keymap_animchannels(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "all", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, KM_CTRL, 0)->ptr, "all", 0);
-
+ kmi = WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "all", FALSE);
+ kmi = WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "all", FALSE);
+
/* rearranging */
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "direction", REARRANGE_ANIMCHAN_UP);
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "direction", REARRANGE_ANIMCHAN_DOWN);
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index cc1fae170d0..216bb8d0e08 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -1490,15 +1490,17 @@ void ED_marker_keymap(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "MARKER_OT_move", EVT_TWEAK_S, KM_ANY, 0, 0);
WM_keymap_verify_item(keymap, "MARKER_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
#ifdef DURIAN_CAMERA_SWITCH
kmi= WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "camera", 1);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ RNA_boolean_set(kmi->ptr, "camera", TRUE);
kmi= WM_keymap_add_item(keymap, "MARKER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "camera", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "camera", TRUE);
#else
(void)kmi;
#endif
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 54314980e03..84206c4275e 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -1200,7 +1200,7 @@ static int insert_key_menu_invoke (bContext *C, wmOperator *op, wmEvent *UNUSED(
else {
/* just call the exec() on the active keyingset */
RNA_enum_set(op->ptr, "type", 0);
- RNA_boolean_set(op->ptr, "confirm_success", 1);
+ RNA_boolean_set(op->ptr, "confirm_success", TRUE);
return op->type->exec(C, op);
}
diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c
index 81482466a30..7379a278d01 100644
--- a/source/blender/editors/armature/armature_ops.c
+++ b/source/blender/editors/armature/armature_ops.c
@@ -182,7 +182,7 @@ void ED_operatormacros_armature(void)
if(ot) {
ot->description= "Create new bones from the selected joints and move them";
otmacro=WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude");
- RNA_boolean_set(otmacro->ptr, "forked", 0);
+ RNA_boolean_set(otmacro->ptr, "forked", FALSE);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
}
@@ -193,7 +193,7 @@ void ED_operatormacros_armature(void)
if(ot) {
ot->description= "Create new bones from the selected joints and move them";
otmacro=WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude");
- RNA_boolean_set(otmacro->ptr, "forked", 1);
+ RNA_boolean_set(otmacro->ptr, "forked", TRUE);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
}
@@ -220,16 +220,17 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "SKETCH_OT_gesture", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "snap", 1);
+ RNA_boolean_set(kmi->ptr, "snap", TRUE);
WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, 0, 0);
kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "snap", 1);
+ RNA_boolean_set(kmi->ptr, "snap", TRUE);
/* only set in editmode armature, by space_view3d listener */
kmi = WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+
WM_keymap_add_item(keymap, "ARMATURE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "ARMATURE_OT_align", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
WM_keymap_add_item(keymap, "ARMATURE_OT_calculate_roll", NKEY, KM_PRESS, KM_CTRL, 0);
@@ -304,9 +305,11 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_menu(keymap, "INFO_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
- WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, 0, 0);
- kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+
WM_keymap_add_item(keymap, "POSE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_menu(keymap, "VIEW3D_MT_pose_apply", AKEY, KM_PRESS, KM_CTRL, 0);
@@ -321,9 +324,11 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "POSE_OT_rotation_mode_set", RKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "POSE_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
+ kmi = WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "flipped", FALSE);
+
kmi= WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "flipped", 1);
+ RNA_boolean_set(kmi->ptr, "flipped", TRUE);
kmi = WM_keymap_add_item(keymap, "POSE_OT_select_all", AKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c
index 9ec27b69835..a8978a0bbde 100644
--- a/source/blender/editors/armature/editarmature_retarget.c
+++ b/source/blender/editors/armature/editarmature_retarget.c
@@ -450,7 +450,7 @@ static void renameTemplateBone(char *name, char *template_name, ListBase *editbo
{
int i, j;
- for (i = 0, j = 0; template_name[i] != '\0' && i < (MAXBONENAME-1) && j < (MAXBONENAME-1); i++)
+ for (i = 0, j = 0; i < (MAXBONENAME-1) && j < (MAXBONENAME-1) && template_name[i] != '\0'; i++)
{
if (template_name[i] == '&')
{
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index 60fca7ae4bd..b213f797d47 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -145,14 +145,14 @@ void ED_operatormacros_curve(void)
WM_operatortype_macro_define(ot, "CURVE_OT_duplicate");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("CURVE_OT_extrude_move", "Extrude Curve and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude curve and move result";
WM_operatortype_macro_define(ot, "CURVE_OT_extrude");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
}
void ED_keymap_curve(wmKeyConfig *keyconf)
@@ -210,7 +210,8 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "FONT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FONT_OT_text_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
- RNA_boolean_set(WM_keymap_add_item(keymap, "FONT_OT_text_insert", BACKSPACEKEY, KM_PRESS, KM_ALT, 0)->ptr, "accent", 1); // accented characters
+ kmi = WM_keymap_add_item(keymap, "FONT_OT_text_insert", BACKSPACEKEY, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "accent", TRUE); /* accented characters */
/* only set in editmode curve, by space_view3d listener */
keymap= WM_keymap_find(keyconf, "Curve", 0, 0);
@@ -231,8 +232,11 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CURVE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "CURVE_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
+
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "CURVE_OT_separate", PKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CURVE_OT_extrude_move", EKEY, KM_PRESS, 0, 0);
@@ -248,8 +252,10 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", TFM_CURVE_SHRINKFATTEN);
WM_keymap_add_item(keymap, "CURVE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "OBJECT_OT_vertex_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 150e0ba90e4..954c79bb17d 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -55,7 +55,8 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
/* Draw */
/* draw */
- WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, DKEY);
+ kmi=WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, DKEY);
+ RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
/* draw - straight lines */
kmi=WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_CTRL, DKEY);
RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_STRAIGHT);
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h
index 957b58b141c..05cde05f25c 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -53,6 +53,7 @@ void ED_space_image_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoo
void ED_space_image_uv_aspect(struct SpaceImage *sima, float *aspx, float *aspy);
void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings);
+void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings);
void ED_image_size(struct Image *ima, int *width, int *height);
void ED_image_aspect(struct Image *ima, float *aspx, float *aspy);
@@ -66,8 +67,8 @@ int ED_space_image_show_uvshadow(struct SpaceImage *sima, struct Object *obedit)
/* UI level image (texture) updating... render calls own stuff (too) */
void ED_image_update_frame(const struct Main *mainp, int cfra);
-void ED_image_draw_info(struct ARegion *ar, int color_manage, int channels,
- int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf);
+void ED_image_draw_info(struct ARegion *ar, int color_manage, int channels, int x, int y,
+ const unsigned char cp[4], const float fp[4], int *zp, float *zpf);
#endif /* ED_IMAGE_H */
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 6b374274205..160e3eea6cc 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -155,6 +155,9 @@ struct UvVertMap *EM_make_uv_vert_map(struct EditMesh *em, int selected, int do_
struct UvMapVert *EM_get_uv_map_vert(struct UvVertMap *vmap, unsigned int v);
void EM_free_uv_vert_map(struct UvVertMap *vmap);
+struct UvElementMap *EM_make_uv_element_map(struct EditMesh *em, int selected, int doIslands);
+void EM_free_uv_element_map(struct UvElementMap *vmap);
+
void EM_add_data_layer(struct EditMesh *em, struct CustomData *data, int type, const char *name);
void EM_free_data_layer(struct EditMesh *em, struct CustomData *data, int type);
@@ -232,6 +235,10 @@ void ED_mesh_faces_add(struct Mesh *mesh, struct ReportList *reports, int count)
void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count);
void ED_mesh_vertices_add(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+
void ED_mesh_transform(struct Mesh *me, float *mat);
void ED_mesh_calc_normals(struct Mesh *me);
void ED_mesh_material_link(struct Mesh *me, struct Material *ma);
diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h
index 0666884351a..bc8a12c97cc 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -81,7 +81,7 @@ void ED_uvedit_live_unwrap_end(short cancel);
void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel);
/* uvedit_draw.c */
-void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit);
+void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit, struct Object *obact);
/* uvedit_buttons.c */
void ED_uvedit_buttons_register(struct ARegionType *art);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 2148b0d04a6..f087cdc7442 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -279,10 +279,10 @@ void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct AR
int winx, int winy, float viewmat[][4], float winmat[][4]);
struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag, char err_out[256]);
-struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, struct Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256]);
+struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Scene *scene, struct Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256]);
-Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
+struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, short do_clip);
int ED_view3d_lock(struct RegionView3D *rv3d);
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index e9c213dec35..e5ad51169a8 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -41,7 +41,7 @@ struct Material;
typedef struct IconFile {
struct IconFile *next, *prev;
- char filename[80]; // FILE_MAXFILE size
+ char filename[256]; // FILE_MAXFILE size
int index;
} IconFile;
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index 683d35daf66..75aa996088f 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -45,79 +45,10 @@ typedef enum {
} BIFIconID;
#define BIFICONID_FIRST (ICON_NONE)
-#define BIFNICONIDS (BIFICONID_LAST-BIFICONID_FIRST + 1)
#undef DEF_ICON
#undef DEF_VICO
-
-typedef enum {
-#define BIFCOLORSHADE_FIRST (COLORSHADE_DARK)
- COLORSHADE_DARK,
- COLORSHADE_GREY,
- COLORSHADE_MEDIUM,
- COLORSHADE_HILITE,
- COLORSHADE_LIGHT,
- COLORSHADE_WHITE
-#define BIFCOLORSHADE_LAST (COLORSHADE_WHITE)
-#define BIFNCOLORSHADES (BIFCOLORSHADE_LAST-BIFCOLORSHADE_FIRST + 1)
-} BIFColorShade;
-
-typedef enum {
-#define BIFCOLORID_FIRST (BUTGREY)
- BUTGREY = 0,
- BUTGREEN,
- BUTBLUE,
- BUTSALMON,
- MIDGREY,
- BUTPURPLE,
- BUTYELLOW,
- REDALERT,
- BUTRUST,
- BUTWHITE,
- BUTDBLUE,
- BUTPINK,
- BUTDPINK,
- BUTMACTIVE,
-
- BUTIPO,
- BUTAUDIO,
- BUTCAMERA,
- BUTRANDOM,
- BUTEDITOBJECT,
- BUTPROPERTY,
- BUTSCENE,
- BUTMOTION,
- BUTMESSAGE,
- BUTACTION,
- BUTCD,
- BUTGAME,
- BUTVISIBILITY,
- BUTYUCK,
- BUTSEASICK,
- BUTCHOKE,
- BUTIMPERIAL,
-
- BUTTEXTCOLOR,
- BUTTEXTPRESSED,
- BUTSBACKGROUND,
-
- VIEWPORTBACKCOLOR,
- VIEWPORTGRIDCOLOR,
- VIEWPORTACTIVECOLOR,
- VIEWPORTSELECTEDCOLOR,
- VIEWPORTUNSELCOLOR,
-
- EDITVERTSEL,
- EDITVERTUNSEL,
- EDITEDGESEL,
- EDITEDGEUNSEL
-
-#define BIFCOLORID_LAST (EDITEDGEUNSEL)
-#define BIFNCOLORIDS (BIFCOLORID_LAST-BIFCOLORID_FIRST + 1)
-
-} BIFColorID;
-
enum {
TH_REDALERT,
@@ -256,6 +187,14 @@ enum {
TH_PATH_AFTER,
TH_CAMERA_PATH,
TH_LOCK_MARKER,
+
+ TH_STITCH_PREVIEW_FACE,
+ TH_STITCH_PREVIEW_EDGE,
+ TH_STITCH_PREVIEW_VERT,
+ TH_STITCH_PREVIEW_STITCHABLE,
+ TH_STITCH_PREVIEW_UNSTITCHABLE,
+ TH_STITCH_PREVIEW_ACTIVE,
+
TH_FREESTYLE_EDGE_MARK,
TH_FREESTYLE_FACE_MARK
};
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 7ff69277843..c112918833e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1693,10 +1693,15 @@ static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char *
return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1);
}
-static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value)
+#endif /* WITH_PYTHON */
+
+
+int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value)
{
int ok= FALSE;
+#ifdef WITH_PYTHON
+
if(str[0] != '\0') {
int is_unit_but= ui_is_but_unit(but);
/* only enable verbose if we won't run again with units */
@@ -1718,10 +1723,16 @@ static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str,
}
}
+#else /* WITH_PYTHON */
+
+ value= atof(str);
+ ok = TRUE;
+
+#endif /* WITH_PYTHON */
+
return ok;
}
-#endif // WITH_PYTHON
int ui_set_but_string(bContext *C, uiBut *but, const char *str)
{
@@ -1788,13 +1799,9 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str)
/* number editing */
double value;
-#ifdef WITH_PYTHON
if(ui_set_but_string_eval_num(C, but, str, &value) == FALSE) {
return 0;
}
-#else
- value= atof(str);
-#endif // WITH_PYTHON
if(!ui_is_but_float(but)) value= (int)floor(value + 0.5);
if(but->type==NUMABS) value= fabs(value);
@@ -1939,21 +1946,32 @@ static void ui_free_but(const bContext *C, uiBut *but)
WM_operator_properties_free(but->opptr);
MEM_freeN(but->opptr);
}
- if(but->func_argN) MEM_freeN(but->func_argN);
+
+ if(but->func_argN) {
+ MEM_freeN(but->func_argN);
+ }
+
if(but->active) {
/* XXX solve later, buttons should be free-able without context ideally,
* however they may have open tooltips or popup windows, which need to
* be closed using a context pointer */
- if(C)
+ if (C) {
ui_button_active_free(C, but);
- else
- if(but->active)
+ }
+ else {
+ if(but->active) {
MEM_freeN(but->active);
+ }
+ }
+ }
+ if (but->str && but->str != but->strdata) {
+ MEM_freeN(but->str);
}
- if(but->str && but->str != but->strdata) MEM_freeN(but->str);
ui_free_link(but->link);
- if((but->type == BUT_IMAGE) && but->poin) IMB_freeImBuf((struct ImBuf *)but->poin);
+ if ((but->type == BUT_IMAGE) && but->poin) {
+ IMB_freeImBuf((struct ImBuf *)but->poin);
+ }
MEM_freeN(but);
}
@@ -1968,11 +1986,13 @@ void uiFreeBlock(const bContext *C, uiBlock *block)
ui_free_but(C, but);
}
- if(block->unit)
+ if (block->unit) {
MEM_freeN(block->unit);
+ }
- if(block->func_argN)
+ if (block->func_argN) {
MEM_freeN(block->func_argN);
+ }
CTX_store_free_list(&block->contexts);
@@ -2639,8 +2659,9 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
str= BLI_dynstr_get_cstring(dynstr);
BLI_dynstr_free(dynstr);
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
freestr= 1;
}
@@ -2656,10 +2677,12 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
}
}
- if(!str)
- str= RNA_property_ui_name(prop);
- if(free)
+ if (!str) {
+ str = RNA_property_ui_name(prop);
+ }
+ if (free) {
MEM_freeN(item);
+ }
}
else {
str= RNA_property_ui_name(prop);
@@ -2739,9 +2762,10 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
but->a1= ui_get_but_step_unit(but, but->a1);
}
- if(freestr)
+ if (freestr) {
MEM_freeN((void *)str);
-
+ }
+
return but;
}
@@ -3353,8 +3377,9 @@ void uiBlockSetFunc(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2
void uiBlockSetNFunc(uiBlock *block, uiButHandleFunc func, void *argN, void *arg2)
{
- if(block->func_argN)
+ if (block->func_argN) {
MEM_freeN(block->func_argN);
+ }
block->funcN= func;
block->func_argN= argN;
@@ -3383,8 +3408,9 @@ void uiButSetFunc(uiBut *but, uiButHandleFunc func, void *arg1, void *arg2)
void uiButSetNFunc(uiBut *but, uiButHandleNFunc funcN, void *argN, void *arg2)
{
- if(but->func_argN)
+ if (but->func_argN) {
MEM_freeN(but->func_argN);
+ }
but->funcN= funcN;
but->func_argN= argN;
@@ -3422,8 +3448,9 @@ uiBut *uiDefBlockButN(uiBlock *block, uiBlockCreateFunc func, void *argN, const
{
uiBut *but= ui_def_but(block, BLOCK, 0, str, x1, y1, x2, y2, NULL, 0.0, 0.0, 0.0, 0.0, tip);
but->block_create_func= func;
- if(but->func_argN)
+ if (but->func_argN) {
MEM_freeN(but->func_argN);
+ }
but->func_argN= argN;
ui_check_but(but);
return but;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 3a19bb2a90c..311f0f87b50 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1115,8 +1115,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
{
static ColorBand but_copypaste_coba = {0};
char buf[UI_MAX_DRAW_STR+1]= {0};
- double val;
-
+
if(mode=='v' && but->lock)
return;
@@ -1140,17 +1139,16 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
if(but->poin==NULL && but->rnapoin.data==NULL);
else if(mode=='c') {
- if(ui_is_but_float(but))
- BLI_snprintf(buf, sizeof(buf), "%f", ui_get_but_val(but));
- else
- BLI_snprintf(buf, sizeof(buf), "%d", (int)ui_get_but_val(but));
-
+ ui_get_but_string(but, buf, sizeof(buf));
WM_clipboard_text_set(buf, 0);
}
else {
- if (sscanf(buf, " %lf ", &val) == 1) {
+ double val;
+
+ if (ui_set_but_string_eval_num(C, but, buf, &val)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
data->value= val;
+ ui_set_but_string(C, but, buf);
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
}
@@ -1703,8 +1701,9 @@ static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste
changed= 1;
}
- if(pbuf)
+ if (pbuf) {
MEM_freeN(pbuf);
+ }
}
/* cut & copy */
else if (copy || cut) {
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index a7d8c688f43..3feda5d4db4 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -665,7 +665,9 @@ static void init_iconfile_list(struct ListBase *list)
for(; i>=0; i--){
MEM_freeN(dir[i].relname);
MEM_freeN(dir[i].path);
- if (dir[i].string) MEM_freeN(dir[i].string);
+ if (dir[i].string) {
+ MEM_freeN(dir[i].string);
+ }
}
free(dir);
dir= NULL;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index e31d7e39d89..2980b28d522 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -163,7 +163,7 @@ struct uiBut {
float hardmin, hardmax, softmin, softmax;
float a1, a2;
float aspect;
- char col[4];
+ unsigned char col[4];
uiButHandleFunc func;
void *func_arg1;
@@ -356,6 +356,7 @@ extern void ui_get_but_string(uiBut *but, char *str, size_t maxlen);
extern void ui_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen);
extern int ui_set_but_string(struct bContext *C, uiBut *but, const char *str);
extern int ui_get_but_string_max_length(uiBut *but);
+extern int ui_set_but_string_eval_num(struct bContext *C, uiBut *but, const char *str, double *value);
extern void ui_set_but_default(struct bContext *C, short all);
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index a01efa25d19..eb55cf912d6 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -320,7 +320,7 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index)
int len= RNA_property_array_length(ptr, prop);
if(!shift) {
- RNA_property_boolean_set_index(ptr, prop, index, 1);
+ RNA_property_boolean_set_index(ptr, prop, index, TRUE);
for(i=0; i<len; i++)
if(i != index)
@@ -499,8 +499,9 @@ static void ui_item_enum_expand(uiLayout *layout, uiBlock *block, PointerRNA *pt
}
uiBlockSetCurLayout(block, layout);
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
/* callback for keymap item change button */
@@ -705,12 +706,15 @@ static const char *ui_menu_enumpropname(uiLayout *layout, const char *opname, co
RNA_property_enum_items_gettexted(layout->root->block->evil_C, &ptr, prop, &item, &totitem, &free);
if(RNA_enum_name(item, retval, &name)) {
- if(free) MEM_freeN(item);
+ if (free) {
+ MEM_freeN(item);
+ }
return name;
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
return "";
@@ -792,8 +796,9 @@ void uiItemsFullEnumO(uiLayout *layout, const char *opname, const char *propname
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
}
@@ -845,13 +850,16 @@ void uiItemEnumO_string(uiLayout *layout, const char *name, int icon, const char
if((prop= RNA_struct_find_property(&ptr, propname))) {
RNA_property_enum_items_gettexted(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free);
if(item==NULL || RNA_enum_value_from_id(item, value_str, &value)==0) {
- if(free) MEM_freeN(item);
+ if(free) {
+ MEM_freeN(item);
+ }
RNA_warning("%s.%s, enum %s not found", RNA_struct_identifier(ptr.type), propname, value_str);
return;
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
else {
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
@@ -1096,7 +1104,9 @@ void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *pr
RNA_property_enum_items_gettexted(layout->root->block->evil_C, ptr, prop, &item, NULL, &free);
if(!RNA_enum_value_from_id(item, value, &ivalue)) {
- if(free) MEM_freeN(item);
+ if (free) {
+ MEM_freeN(item);
+ }
ui_item_disabled(layout, propname);
RNA_warning("enum property value not found: %s", value);
return;
@@ -1109,8 +1119,9 @@ void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *pr
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname)
@@ -1160,8 +1171,9 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
}
@@ -2731,8 +2743,9 @@ const char *uiLayoutIntrospect(uiLayout *layout)
{
DynStr *ds= BLI_dynstr_new();
- if(str)
+ if (str) {
MEM_freeN(str);
+ }
ui_intro_uiLayout(ds, layout);
@@ -2783,7 +2796,7 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in
WM_operator_properties_create(&op_ptr, "WM_OT_operator_preset_add");
RNA_string_set(&op_ptr, "operator", op->type->idname);
- RNA_boolean_set(&op_ptr, "remove_active", 1);
+ RNA_boolean_set(&op_ptr, "remove_active", TRUE);
op_ptr= uiItemFullO(row, "WM_OT_operator_preset_add", "", ICON_ZOOMOUT, op_ptr.data, WM_OP_INVOKE_DEFAULT, 0);
}
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index b50df29918d..40cf0213203 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -494,7 +494,7 @@ struct uiEditSourceStore {
} uiEditSourceStore;
struct uiEditSourceButStore {
- char py_dbg_fn[240];
+ char py_dbg_fn[FILE_MAX];
int py_dbg_ln;
} uiEditSourceButStore;
@@ -584,7 +584,7 @@ void UI_editsource_active_but_test(uiBut *but)
/* editsource operator component */
static int editsource_text_edit(bContext *C, wmOperator *op,
- char filepath[240], int line)
+ char filepath[FILE_MAX], int line)
{
struct Main *bmain= CTX_data_main(C);
Text *text;
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index c21bc09ff27..d802c8640b8 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -772,8 +772,9 @@ static int uiAlignPanelStep(ScrArea *sa, ARegion *ar, float fac, int drag)
ui_panel_copy_offset(pa, pa->paneltab);
/* free panelsort array */
- for(ps= panelsort, a=0; a<tot; a++, ps++)
+ for (ps = panelsort, a = 0; a < tot; a++, ps++) {
MEM_freeN(ps->pa);
+ }
MEM_freeN(panelsort);
return done;
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 0c5aed83c1b..8e336a363df 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -138,8 +138,9 @@ static void menudata_add_item(MenuData *md, const char *str, int retval, int ico
static void menudata_free(MenuData *md)
{
MEM_freeN((void *)md->instr);
- if (md->items)
+ if (md->items) {
MEM_freeN(md->items);
+ }
MEM_freeN(md);
}
@@ -394,8 +395,9 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
}
}
- if(free)
+ if (free) {
MEM_freeN(item);
+ }
}
}
@@ -982,8 +984,9 @@ static void ui_searchbox_region_free_cb(ARegion *ar)
int a;
/* free search data */
- for(a=0; a<data->items.maxitem; a++)
+ for (a = 0; a < data->items.maxitem; a++) {
MEM_freeN(data->items.names[a]);
+ }
MEM_freeN(data->items.names);
MEM_freeN(data->items.pointers);
MEM_freeN(data->items.icons);
@@ -1182,8 +1185,9 @@ void ui_but_search_test(uiBut *but)
uiButSetFlag(but, UI_BUT_REDALERT);
}
- for(x1=0; x1<items->maxitem; x1++)
+ for (x1 = 0; x1 < items->maxitem; x1++) {
MEM_freeN(items->names[x1]);
+ }
MEM_freeN(items->names);
MEM_freeN(items);
}
@@ -1611,6 +1615,7 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a
MenuEntry *entry;
const char *instr= arg_str;
int columns, rows, a, b;
+ int column_start= 0, column_end= 0;
uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
@@ -1654,17 +1659,30 @@ static void ui_block_func_MENUSTR(bContext *UNUSED(C), uiLayout *layout, void *a
/* create items */
split= uiLayoutSplit(layout, 0, 0);
- for(a=0, b=0; a<md->nitems; a++, b++) {
+ for(a=0; a<md->nitems; a++) {
+ if(a == column_end) {
+ /* start new column, and find out where it ends in advance, so we
+ can flip the order of items properly per column */
+ column_start= a;
+ column_end= md->nitems;
+
+ for(b=a+1; b<md->nitems; b++) {
+ entry= &md->items[b];
+
+ /* new column on N rows or on separation label */
+ if(((b-a) % rows == 0) || (entry->sepr && entry->str[0])) {
+ column_end = b;
+ break;
+ }
+ }
+
+ column= uiLayoutColumn(split, 0);
+ }
+
if(block->flag & UI_BLOCK_NO_FLIP)
entry= &md->items[a];
else
- entry= &md->items[md->nitems-a-1];
-
- /* new column on N rows or on separation label */
- if((b % rows == 0) || (entry->sepr && entry->str[0])) {
- column= uiLayoutColumn(split, 0);
- b= 0;
- }
+ entry= &md->items[column_start + column_end-1-a];
if(entry->sepr) {
uiItemL(column, entry->str, entry->icon);
@@ -2460,7 +2478,7 @@ static void confirm_operator(bContext *C, wmOperator *op, const char *title, con
char *s, buf[512];
s= buf;
- if (title) s+= sprintf(s, "%s%%t|%s", title, item);
+ if (title) s+= BLI_snprintf(s, sizeof(buf), "%s%%t|%s", title, item);
(void)s;
handle= ui_popup_menu_create(C, NULL, NULL, NULL, NULL, buf);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 3a72c98e8f0..ba481f49abc 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1958,10 +1958,10 @@ static void handle_layer_buttons(bContext *C, void *arg1, void *arg2)
tot= RNA_property_array_length(&but->rnapoin, but->rnaprop);
/* Normally clicking only selects one layer */
- RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, cur, 1);
+ RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, cur, TRUE);
for(i = 0; i < tot; ++i) {
if(i != cur)
- RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, i, 0);
+ RNA_property_boolean_set_index(&but->rnapoin, but->rnaprop, i, FALSE);
}
}
@@ -2268,8 +2268,9 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
/* free name */
- if(namebuf)
+ if (namebuf) {
MEM_freeN(namebuf);
+ }
}
void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, const char *prop_list, int rows, int maxrows, int listtype)
@@ -2373,8 +2374,9 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
icon= list_item_icon_get(C, &itemptr, rnaicon, 0);
uiItemL(row, (name)? name: "", icon);
- if(name)
+ if (name) {
MEM_freeN((void *)name);
+ }
}
i++;
@@ -2627,9 +2629,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
uiBlockBeginAlign(block);
but= uiDefBut(block, ROUNDBOX, 0, "", 0, 0, UI_UNIT_X+10, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
/* set the report's bg color in but->col - ROUNDBOX feature */
- but->col[0]= FTOCHAR(rti->col[0]);
- but->col[1]= FTOCHAR(rti->col[1]);
- but->col[2]= FTOCHAR(rti->col[2]);
+ rgb_float_to_uchar(but->col, rti->col);
but->col[3]= 255;
but= uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X+10, 0, UI_UNIT_X+width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index f5c62f65512..19acfaccaa3 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2501,7 +2501,7 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
if (color_profile)
linearrgb_to_srgb_v3_v3(col, col);
- F4TOCHAR4(col, wcol->inner);
+ rgba_float_to_uchar((unsigned char *)wcol->inner, col);
wcol->shaded = 0;
wcol->alpha_check = (wcol->inner[3] < 255);
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 53a48e17698..472e2088d43 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -414,6 +414,28 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
cp= ts->preview_back;
break;
+ case TH_STITCH_PREVIEW_FACE:
+ cp = ts->preview_stitch_face;
+ break;
+
+ case TH_STITCH_PREVIEW_EDGE:
+ cp = ts->preview_stitch_edge;
+ break;
+
+ case TH_STITCH_PREVIEW_VERT:
+ cp = ts->preview_stitch_vert;
+ break;
+
+ case TH_STITCH_PREVIEW_STITCHABLE:
+ cp = ts->preview_stitch_stitchable;
+ break;
+
+ case TH_STITCH_PREVIEW_UNSTITCHABLE:
+ cp = ts->preview_stitch_unstitchable;
+ break;
+ case TH_STITCH_PREVIEW_ACTIVE:
+ cp = ts->preview_stitch_active;
+ break;
case TH_MARKER_OUTLINE:
cp= ts->marker_outline; break;
case TH_MARKER:
@@ -752,6 +774,11 @@ void ui_theme_init_default(void)
SETCOL(btheme->tima.face_select, 255, 133, 0, 60);
SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
SETCOLF(btheme->tima.preview_back, 0.45, 0.45, 0.45, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_face, 0.5, 0.5, 0.0, 0.2);
+ SETCOLF(btheme->tima.preview_stitch_edge, 1.0, 0.0, 1.0, 0.2);
+ SETCOLF(btheme->tima.preview_stitch_vert, 0.0, 0.0, 1.0, 0.2);
+ SETCOLF(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
/* space text */
btheme->text= btheme->tv3d;
@@ -1685,6 +1712,19 @@ void init_userdef_do_versions(void)
}
}
+ if (bmain->versionfile < 262){
+ bTheme *btheme;
+ for(btheme= U.themes.first; btheme; btheme= btheme->next) {
+ SETCOLF(btheme->tima.preview_stitch_face, 0.071, 0.259, 0.694, 0.150);
+ SETCOLF(btheme->tima.preview_stitch_edge, 1.0, 0.522, 0.0, 0.7);
+ SETCOLF(btheme->tima.preview_stitch_vert, 1.0, 0.522, 0.0, 0.5);
+ SETCOLF(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_active, 0.886, 0.824, 0.765, 0.140);
+ }
+ U.use_16bit_textures = 0;
+ }
+
/* Freestyle color settings */
{
bTheme *btheme;
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index b8201d762df..3eb8aba7334 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -1339,8 +1339,9 @@ void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy)
void UI_view2d_grid_free(View2DGrid *grid)
{
/* only free if there's a grid */
- if (grid)
+ if (grid) {
MEM_freeN(grid);
+ }
}
/* *********************************************************************** */
@@ -1754,7 +1755,9 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
void UI_view2d_scrollers_free(View2DScrollers *scrollers)
{
/* need to free grid as well... */
- if (scrollers->grid) MEM_freeN(scrollers->grid);
+ if (scrollers->grid) {
+ MEM_freeN(scrollers->grid);
+ }
MEM_freeN(scrollers);
}
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 2959d525cfb..234b2733bd3 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -1689,7 +1689,8 @@ void UI_view2d_operatortypes(void)
void UI_view2d_keymap(wmKeyConfig *keyconf)
{
wmKeyMap *keymap= WM_keymap_find(keyconf, "View2D", 0, 0);
-
+ wmKeyMapItem *kmi;
+
/* scrollers */
WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", MIDDLEMOUSE, KM_PRESS, 0, 0);
@@ -1750,8 +1751,10 @@ void UI_view2d_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "page", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "page", 1);
+ kmi = WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "page", TRUE);
+ kmi = WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", PAGEUPKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "page", TRUE);
WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MOUSEZOOM, 0, 0, 0);
diff --git a/source/blender/editors/mesh/editmesh_lib.c b/source/blender/editors/mesh/editmesh_lib.c
index 8dea636f0b6..5ec147a742b 100644
--- a/source/blender/editors/mesh/editmesh_lib.c
+++ b/source/blender/editors/mesh/editmesh_lib.c
@@ -2322,7 +2322,7 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
for(a=0, ev=em->verts.first; ev; a++, ev= ev->next) {
UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
UvMapVert *iterv, *v, *lastv, *next;
- float *uv, *uv2, uvdiff[2];
+ float *uv, *uv2;
while(vlist) {
v= vlist;
@@ -2332,8 +2332,8 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
efa = EM_get_face_for_index(v->f);
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
- uv = tf->uv[v->tfindex];
-
+ uv = tf->uv[v->tfindex];
+
lastv= NULL;
iterv= vlist;
@@ -2342,8 +2342,6 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
efa = EM_get_face_for_index(iterv->f);
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
uv2 = tf->uv[iterv->tfindex];
-
- sub_v2_v2v2(uvdiff, uv2, uv);
if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
if(lastv) lastv->next= next;
@@ -2353,22 +2351,224 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array
}
else
lastv=iterv;
-
iterv= next;
}
-
newvlist->separate = 1;
}
-
vmap->vert[a]= newvlist;
}
-
+
+
if (do_face_idx_array)
EM_free_index_arrays();
-
+
+ return vmap;
+}
+
+/* A specialized vert map used by stitch operator */
+UvElementMap *EM_make_uv_element_map(EditMesh *em, int selected, int do_islands)
+{
+ EditVert *ev;
+ EditFace *efa;
+
+ /* vars from original func */
+ UvElementMap *vmap;
+ UvElement *buf;
+ UvElement *islandbuf;
+ MTFace *tf;
+ unsigned int a;
+ int i,j, totuv, nverts, nislands = 0, islandbufsize = 0;
+ unsigned int *map;
+ /* for uv island creation */
+ EditFace **stack;
+ int stacksize = 0;
+
+ /* we need the vert */
+ for(ev = em->verts.first, i = 0; ev; ev = ev->next, i++)
+ ev->tmp.l = i;
+
+ totuv = 0;
+
+ for(efa = em->faces.first; efa; efa = efa->next)
+ if(!selected || ((!efa->h) && (efa->f & SELECT)))
+ totuv += (efa->v4)? 4: 3;
+
+ if(totuv == 0)
+ return NULL;
+
+ vmap = (UvElementMap *)MEM_callocN(sizeof(*vmap), "UvVertElementMap");
+ if(!vmap)
+ return NULL;
+
+ vmap->vert = (UvElement**)MEM_callocN(sizeof(*vmap->vert)*em->totvert, "UvElementVerts");
+ buf = vmap->buf = (UvElement*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvElement");
+
+ if(!vmap->vert || !vmap->buf) {
+ EM_free_uv_element_map(vmap);
+ return NULL;
+ }
+
+ vmap->totalUVs = totuv;
+
+ for(efa = em->faces.first; efa; a++, efa = efa->next) {
+ if(!selected || ((!efa->h) && (efa->f & SELECT))) {
+ nverts = (efa->v4)? 4: 3;
+
+ for(i = 0; i<nverts; i++) {
+ buf->tfindex = i;
+ buf->face = efa;
+ buf->separate = 0;
+ buf->island = INVALID_ISLAND;
+
+ buf->next = vmap->vert[(*(&efa->v1 + i))->tmp.l];
+ vmap->vert[(*(&efa->v1 + i))->tmp.l] = buf;
+
+ buf++;
+ }
+ }
+
+ efa->tmp.l = INVALID_ISLAND;
+ }
+
+ /* sort individual uvs for each vert */
+ for(a = 0, ev = em->verts.first; ev; a++, ev = ev->next) {
+ UvElement *newvlist = NULL, *vlist = vmap->vert[a];
+ UvElement *iterv, *v, *lastv, *next;
+ float *uv, *uv2;
+
+ while(vlist) {
+ v= vlist;
+ vlist= vlist->next;
+ v->next= newvlist;
+ newvlist= v;
+
+ efa = v->face;
+ tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ uv = tf->uv[v->tfindex];
+
+ lastv= NULL;
+ iterv= vlist;
+
+ while(iterv) {
+ next= iterv->next;
+ efa = iterv->face;
+ tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ uv2 = tf->uv[iterv->tfindex];
+
+ if(fabsf(uv[0]-uv2[0]) < STD_UV_CONNECT_LIMIT && fabsf(uv[1]-uv2[1]) < STD_UV_CONNECT_LIMIT) {
+ if(lastv) lastv->next = next;
+ else vlist = next;
+ iterv->next = newvlist;
+ newvlist = iterv;
+ }
+ else
+ lastv = iterv;
+
+ iterv = next;
+ }
+
+ newvlist->separate = 1;
+ }
+
+ vmap->vert[a] = newvlist;
+ }
+
+ if(do_islands) {
+ /* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */
+
+ /* map holds the map from current vmap->buf to the new, sorted map*/
+ map = MEM_mallocN(sizeof(*map)*totuv, "uvelement_remap");
+ stack = MEM_mallocN(sizeof(*stack)*em->totface, "uv_island_face_stack");
+ islandbuf = MEM_callocN(sizeof(*islandbuf)*totuv, "uvelement_island_buffer");
+
+ for(i = 0; i < totuv; i++) {
+ if(vmap->buf[i].island == INVALID_ISLAND) {
+ vmap->buf[i].island = nislands;
+ stack[0] = vmap->buf[i].face;
+ stack[0]->tmp.l = nislands;
+ stacksize=1;
+
+ while(stacksize > 0) {
+ efa = stack[--stacksize];
+ nverts = efa->v4? 4 : 3;
+
+ for(j = 0; j < nverts; j++) {
+ UvElement *element, *initelement = vmap->vert[(*(&efa->v1 + j))->tmp.l];
+
+ for(element = initelement; element; element = element->next) {
+ if(element->separate)
+ initelement = element;
+
+ if(element->face == efa) {
+ /* found the uv corresponding to our face and vertex. Now fill it to the buffer */
+ element->island = nislands;
+ map[element - vmap->buf] = islandbufsize;
+ islandbuf[islandbufsize].tfindex = element->tfindex;
+ islandbuf[islandbufsize].face = element->face;
+ islandbuf[islandbufsize].separate = element->separate;
+ islandbuf[islandbufsize].island = nislands;
+ islandbufsize++;
+
+ for(element = initelement; element; element = element->next) {
+ if(element->separate && element != initelement)
+ break;
+
+ if(element->face->tmp.l == INVALID_ISLAND) {
+ stack[stacksize++] = element->face;
+ element->face->tmp.l = nislands;
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ nislands++;
+ }
+ }
+
+ /* remap */
+ for(i = 0; i < em->totvert; i++) {
+ /* important since we may do selection only. Some of these may be NULL */
+ if(vmap->vert[i])
+ vmap->vert[i] = &islandbuf[map[vmap->vert[i] - vmap->buf]];
+ }
+
+ vmap->islandIndices = MEM_callocN(sizeof(*vmap->islandIndices)*nislands,"UvVertMap2_island_indices");
+ if(!vmap->islandIndices) {
+ MEM_freeN(islandbuf);
+ MEM_freeN(stack);
+ MEM_freeN(map);
+ EM_free_uv_element_map(vmap);
+ }
+
+ j = 0;
+ for(i = 0; i < totuv; i++) {
+ UvElement *element = vmap->buf[i].next;
+ if(element == NULL)
+ islandbuf[map[i]].next = NULL;
+ else
+ islandbuf[map[i]].next = &islandbuf[map[element - vmap->buf]];
+
+ if(islandbuf[i].island != j) {
+ j++;
+ vmap->islandIndices[j] = i;
+ }
+ }
+
+ MEM_freeN(vmap->buf);
+
+ vmap->buf = islandbuf;
+ vmap->totalIslands = nislands;
+ MEM_freeN(stack);
+ MEM_freeN(map);
+ }
+
return vmap;
}
+
UvMapVert *EM_get_uv_map_vert(UvVertMap *vmap, unsigned int v)
{
return vmap->vert[v];
@@ -2383,6 +2583,16 @@ void EM_free_uv_vert_map(UvVertMap *vmap)
}
}
+void EM_free_uv_element_map(UvElementMap *vmap)
+{
+ if (vmap) {
+ if (vmap->vert) MEM_freeN(vmap->vert);
+ if (vmap->buf) MEM_freeN(vmap->buf);
+ if (vmap->islandIndices) MEM_freeN(vmap->islandIndices);
+ MEM_freeN(vmap);
+ }
+}
+
/* poll call for mesh operators requiring a view3d context */
int EM_view3d_poll(bContext *C)
{
diff --git a/source/blender/editors/mesh/editmesh_loop.c b/source/blender/editors/mesh/editmesh_loop.c
index 70cbbf5a93c..d9854ea7678 100644
--- a/source/blender/editors/mesh/editmesh_loop.c
+++ b/source/blender/editors/mesh/editmesh_loop.c
@@ -56,7 +56,6 @@ editmesh_loop: tools with own drawing subloops, select, knife, subdiv
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
-#include "BKE_array_mallocn.h"
#include "PIL_time.h"
@@ -77,329 +76,6 @@ editmesh_loop: tools with own drawing subloops, select, knife, subdiv
static void error(const char *UNUSED(arg)) {}
/* **** XXX ******** */
-#if 0 /* UNUSED 2.5 */
-static void edgering_sel(EditMesh *em, EditEdge *startedge, int select, int previewlines)
-{
- EditEdge *eed;
- EditFace *efa;
- EditVert *v[2][2];
- float co[2][3];
- int looking= 1,i;
-
- /* in eed->f1 we put the valence (amount of faces in edge) */
- /* in eed->f2 we put tagged flag as correct loop */
- /* in efa->f1 we put tagged flag as correct to select */
-
- for(eed= em->edges.first; eed; eed= eed->next) {
- eed->f1= 0;
- eed->f2= 0;
- }
- for(efa= em->faces.first; efa; efa= efa->next) {
- efa->f1= 0;
- if(efa->h==0) {
- efa->e1->f1++;
- efa->e2->f1++;
- efa->e3->f1++;
- if(efa->e4) efa->e4->f1++;
- }
- }
-
- // tag startedge OK
- startedge->f2= 1;
-
- while(looking) {
- looking= 0;
-
- for(efa= em->faces.first; efa; efa= efa->next) {
- if(efa->e4 && efa->f1==0 && efa->h == 0) { // not done quad
- if(efa->e1->f1<=2 && efa->e2->f1<=2 && efa->e3->f1<=2 && efa->e4->f1<=2) { // valence ok
-
- // if edge tagged, select opposing edge and mark face ok
- if(efa->e1->f2) {
- efa->e3->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- else if(efa->e2->f2) {
- efa->e4->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- if(efa->e3->f2) {
- efa->e1->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- if(efa->e4->f2) {
- efa->e2->f2= 1;
- efa->f1= 1;
- looking= 1;
- }
- }
- }
- }
- }
-
- if(previewlines > 0 && select == 0){
-// XXX persp(PERSP_VIEW);
-// XXX glPushMatrix();
-// XXX mymultmatrix(obedit->obmat);
-
- for(efa= em->faces.first; efa; efa= efa->next) {
- if(efa->v4 == NULL) { continue; }
- if(efa->h == 0){
- if(efa->e1->f2 == 1){
- if(efa->e1->h == 1 || efa->e3->h == 1 )
- continue;
-
- v[0][0] = efa->v1;
- v[0][1] = efa->v2;
- v[1][0] = efa->v4;
- v[1][1] = efa->v3;
- } else if(efa->e2->f2 == 1){
- if(efa->e2->h == 1 || efa->e4->h == 1)
- continue;
- v[0][0] = efa->v2;
- v[0][1] = efa->v3;
- v[1][0] = efa->v1;
- v[1][1] = efa->v4;
- } else { continue; }
-
- for(i=1;i<=previewlines;i++){
- co[0][0] = (v[0][1]->co[0] - v[0][0]->co[0])*(i/((float)previewlines+1))+v[0][0]->co[0];
- co[0][1] = (v[0][1]->co[1] - v[0][0]->co[1])*(i/((float)previewlines+1))+v[0][0]->co[1];
- co[0][2] = (v[0][1]->co[2] - v[0][0]->co[2])*(i/((float)previewlines+1))+v[0][0]->co[2];
-
- co[1][0] = (v[1][1]->co[0] - v[1][0]->co[0])*(i/((float)previewlines+1))+v[1][0]->co[0];
- co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1])*(i/((float)previewlines+1))+v[1][0]->co[1];
- co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2];
- glColor3ub(255, 0, 255);
- glBegin(GL_LINES);
- glVertex3f(co[0][0],co[0][1],co[0][2]);
- glVertex3f(co[1][0],co[1][1],co[1][2]);
- glEnd();
- }
- }
- }
- glPopMatrix();
- } else {
-
- /* (de)select the edges */
- for(eed= em->edges.first; eed; eed= eed->next) {
- if(eed->f2) EM_select_edge(eed, select);
- }
- }
-}
-
-static void CutEdgeloop(Object *obedit, wmOperator *op, EditMesh *em, int numcuts)
-{
- ViewContext vc; // XXX
- EditEdge *nearest=NULL, *eed;
- float fac;
- int keys = 0, holdnum=0, selectmode, dist;
- int mvalo[2] = {0, 0}, mval[2] = {0, 0};
- short event=0, val, choosing=1, cancel=0, cuthalf = 0, smooth=0;
- short hasHidden = 0;
- char msg[128];
-
- selectmode = em->selectmode;
-
- if(em->selectmode & SCE_SELECT_FACE){
- em->selectmode = SCE_SELECT_EDGE;
- EM_selectmode_set(em);
- }
-
-
- BIF_undo_push("Loopcut Begin");
- while(choosing && !cancel){
-// XXX getmouseco_areawin(mval);
- if (mval[0] != mvalo[0] || mval[1] != mvalo[1]) {
- mvalo[0] = mval[0];
- mvalo[1] = mval[1];
- dist= 50;
- nearest = findnearestedge(&vc, &dist); // returns actual distance in dist
-// scrarea_do_windraw(curarea); // after findnearestedge, backbuf!
-
- BLI_snprintf(msg, sizeof(msg),"Number of Cuts: %d (S)mooth: %s", numcuts, smooth ? "on":"off");
-
-// headerprint(msg);
- /* Need to figure preview */
- if(nearest){
- edgering_sel(em, nearest, 0, numcuts);
- }
-// XXX screen_swapbuffers();
-
- /* backbuffer refresh for non-apples (no aux) */
-#ifndef __APPLE__
-// XXX if(G.vd->drawtype>OB_WIRE && (G.vd->flag & V3D_ZBUF_SELECT)) {
-// backdrawview3d(0);
-// }
-#endif
- }
- else PIL_sleep_ms(10); // idle
-
-
- while(qtest())
- {
- val=0;
-// XXX event= extern_qread(&val);
- if(val && (event == MOUSEX || event == MOUSEY)){ ; }
- else if(val && ((event==LEFTMOUSE || event==RETKEY) || (event == MIDDLEMOUSE || event==PADENTER)))
- {
- if(event == MIDDLEMOUSE){
- cuthalf = 1;
- }
- if (nearest==NULL)
- cancel = 1;
- choosing=0;
- mvalo[0] = -1;
- }
- else if(val && (event==ESCKEY || event==RIGHTMOUSE ))
- {
- choosing=0;
- cancel = 1;
- mvalo[0] = -1;
- }
- else if(val && (event==PADPLUSKEY || event==WHEELUPMOUSE))
- {
- numcuts++;
- mvalo[0] = -1;
- }
- else if(val && (event==PADMINUS || event==WHEELDOWNMOUSE))
- {
- if(numcuts > 1){
- numcuts--;
- mvalo[0] = -1;
- }
- }
- else if(val && event==SKEY)
- {
- if(smooth){smooth=0;}
- else { smooth=1; }
- mvalo[0] = -1;
- }
-
- else if(val){
- holdnum = -1;
- switch(event){
- case PAD9:
- case NINEKEY:
- holdnum = 9; break;
- case PAD8:
- case EIGHTKEY:
- holdnum = 8;break;
- case PAD7:
- case SEVENKEY:
- holdnum = 7;break;
- case PAD6:
- case SIXKEY:
- holdnum = 6;break;
- case PAD5:
- case FIVEKEY:
- holdnum = 5;break;
- case PAD4:
- case FOURKEY:
- holdnum = 4;break;
- case PAD3:
- case THREEKEY:
- holdnum = 3; break;
- case PAD2:
- case TWOKEY:
- holdnum = 2;break;
- case PAD1:
- case ONEKEY:
- holdnum = 1; break;
- case PAD0:
- case ZEROKEY:
- holdnum = 0;break;
- case BACKSPACEKEY:
- holdnum = -2;break;
- }
- if(holdnum >= 0 && numcuts*10 < 130){
- if(keys == 0){ // first level numeric entry
- if(holdnum > 0){
- numcuts = holdnum;
- keys++;
- }
- } else if(keys > 0){//highrt level numeric entry
- numcuts *= 10;
- numcuts += holdnum;
- keys++;
- }
- } else if (holdnum == -2){// backspace
- if (keys > 1){
- numcuts /= 10;
- keys--;
- } else {
- numcuts=1;
- keys = 0;
- }
- }
- mvalo[0] = -1;
- break;
- } // End Numeric Entry
- } //End while(qtest())
- } // End Choosing
-
- if(cancel){
- return;
- }
- /* clean selection */
- for(eed=em->edges.first; eed; eed = eed->next){
- EM_select_edge(eed,0);
- }
- /* select edge ring */
- edgering_sel(em, nearest, 1, 0);
-
- /* now cut the loops */
- if(smooth){
- fac= 1.0f;
-// XXX if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
- fac= 0.292f*fac;
- esubdivideflag(obedit, em, SELECT,fac,0,B_SMOOTH,numcuts, SUBDIV_CORNER_PATH, SUBDIV_SELECT_LOOPCUT);
- } else {
- esubdivideflag(obedit, em, SELECT,0,0,0,numcuts,SUBDIV_CORNER_PATH, SUBDIV_SELECT_LOOPCUT);
- }
- /* if this was a single cut, enter edgeslide mode */
- if(numcuts == 1 && hasHidden == 0){
- if(cuthalf)
- EdgeSlide(em, op, 1,0.0);
- else {
- if(EdgeSlide(em, op, 0,0.0) == -1){
- BIF_undo();
- }
- }
- }
-
- if(em->selectmode != selectmode){
- em->selectmode = selectmode;
- EM_selectmode_set(em);
- }
-
-// DAG_id_tag_update(obedit->data, 0);
- return;
-}
-#endif
-
-/* *************** LOOP SELECT ************* */
-#if 0
-static short edgeFaces(EditMesh *em, EditEdge *e)
-{
- EditFace *search=NULL;
- short count = 0;
-
- search = em->faces.first;
- while(search){
- if((search->e1 == e || search->e2 == e) || (search->e3 == e || search->e4 == e))
- count++;
- search = search->next;
- }
- return count;
-}
-#endif
-
-
-
/* ***************** TRAIL ************************
Read a trail of mouse coords and return them as an array of CutCurve structs
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index f0687031bae..48b96eaf927 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -4279,7 +4279,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
BKE_mesh_end_editmesh(obedit->data, em);
// RNA_enum_set(op->ptr, "proportional", 0);
-// RNA_boolean_set(op->ptr, "mirror", 0);
+// RNA_boolean_set(op->ptr, "mirror", FALSE);
// WM_operator_name_call(C, "TRANSFORM_OT_translate", WM_OP_INVOKE_REGION_WIN, op->ptr);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/mesh/loopcut.c b/source/blender/editors/mesh/loopcut.c
index 42728eb7ea1..6ff62b16bde 100644
--- a/source/blender/editors/mesh/loopcut.c
+++ b/source/blender/editors/mesh/loopcut.c
@@ -45,6 +45,7 @@
#include "PIL_time.h"
+#include "BLI_array.h"
#include "BLI_blenlib.h"
#include "BLI_dynstr.h" /*for WM_operator_pystring */
#include "BLI_editVert.h"
@@ -58,7 +59,6 @@
#include "BKE_modifier.h"
#include "BKE_report.h"
#include "BKE_scene.h"
-#include "BKE_array_mallocn.h"
#include "BIF_gl.h"
#include "BIF_glutil.h" /* for paint cursor */
@@ -138,7 +138,7 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
EditFace *efa;
EditVert *v[2][2];
float (*edges)[2][3] = NULL;
- V_DYNDECLARE(edges);
+ BLI_array_declare(edges);
float co[2][3];
int looking=1, i, tot=0;
@@ -240,9 +240,9 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1])*(i/((float)previewlines+1))+v[1][0]->co[1];
co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2];
- V_GROW(edges);
- VECCOPY(edges[tot][0], co[0]);
- VECCOPY(edges[tot][1], co[1]);
+ BLI_array_growone(edges);
+ copy_v3_v3(edges[tot][0], co[0]);
+ copy_v3_v3(edges[tot][1], co[1]);
tot++;
}
}
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index e40c806fd17..d752d90ffdd 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -695,6 +695,46 @@ static void mesh_add_faces(Mesh *mesh, int len)
mesh->totface= totface;
}
+static void mesh_remove_verts(Mesh *mesh, int len)
+{
+ int totvert;
+
+ if(len == 0)
+ return;
+
+ totvert= mesh->totvert - len;
+ CustomData_free_elem(&mesh->vdata, totvert, len);
+
+ /* set final vertex list size */
+ mesh->totvert= totvert;
+}
+
+static void mesh_remove_edges(Mesh *mesh, int len)
+{
+ int totedge;
+
+ if(len == 0)
+ return;
+
+ totedge= mesh->totedge - len;
+ CustomData_free_elem(&mesh->edata, totedge, len);
+
+ mesh->totedge= totedge;
+}
+
+static void mesh_remove_faces(Mesh *mesh, int len)
+{
+ int totface;
+
+ if(len == 0)
+ return;
+
+ totface= mesh->totface - len; /* new face count */
+ CustomData_free_elem(&mesh->fdata, totface, len);
+
+ mesh->totface= totface;
+}
+
/*
void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces)
{
@@ -742,6 +782,48 @@ void ED_mesh_vertices_add(Mesh *mesh, ReportList *reports, int count)
mesh_add_verts(mesh, count);
}
+void ED_mesh_faces_remove(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't remove faces in edit mode");
+ return;
+ }
+ else if(count > mesh->totface) {
+ BKE_report(reports, RPT_ERROR, "Can't remove more faces than the mesh contains");
+ return;
+ }
+
+ mesh_remove_faces(mesh, count);
+}
+
+void ED_mesh_edges_remove(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't remove edges in edit mode");
+ return;
+ }
+ else if(count > mesh->totedge) {
+ BKE_report(reports, RPT_ERROR, "Can't remove more edges than the mesh contains");
+ return;
+ }
+
+ mesh_remove_edges(mesh, count);
+}
+
+void ED_mesh_vertices_remove(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't remove vertices in edit mode");
+ return;
+ }
+ else if(count > mesh->totvert) {
+ BKE_report(reports, RPT_ERROR, "Can't remove more vertices than the mesh contains");
+ return;
+ }
+
+ mesh_remove_verts(mesh, count);
+}
+
void ED_mesh_calc_normals(Mesh *me)
{
mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index 21f44ff89bc..e6268d80c21 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -190,14 +190,14 @@ void ED_operatormacros_mesh(void)
WM_operatortype_macro_define(ot, "MESH_OT_duplicate");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_rip_move", "Rip", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Rip polygons and move the result";
WM_operatortype_macro_define(ot, "MESH_OT_rip");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_region_move", "Extrude Region and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude region and move result";
@@ -205,7 +205,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 1);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_faces_move", "Extrude Individual Faces and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude faces and move result";
@@ -213,7 +213,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 2);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_shrink_fatten");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_edges_move", "Extrude Only Edges and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude edges and move result";
@@ -221,7 +221,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 3);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
ot= WM_operatortype_append_macro("MESH_OT_extrude_vertices_move", "Extrude Only Vertices and Move", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Extrude vertices and move result";
@@ -229,7 +229,7 @@ void ED_operatormacros_mesh(void)
RNA_enum_set(otmacro->ptr, "type", 4);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
- RNA_boolean_set(otmacro->ptr, "mirror", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", FALSE);
}
/* note mesh keymap also for other space? */
@@ -302,6 +302,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "MESH_OT_fill", FKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "MESH_OT_beautify_fill", FKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
+
WM_keymap_add_item(keymap, "MESH_OT_quads_convert_to_tris", TKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "MESH_OT_tris_convert_to_quads", JKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "MESH_OT_edge_flip", FKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
diff --git a/source/blender/editors/metaball/mball_ops.c b/source/blender/editors/metaball/mball_ops.c
index 4c69bb3e559..c7635bcf2cc 100644
--- a/source/blender/editors/metaball/mball_ops.c
+++ b/source/blender/editors/metaball/mball_ops.c
@@ -37,6 +37,8 @@
#include "ED_mball.h"
#include "ED_screen.h"
+#include "BLI_utildefines.h"
+
#include "mball_intern.h"
void ED_operatortypes_metaball(void)
@@ -62,8 +64,10 @@ void ED_keymap_metaball(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OBJECT_OT_metaball_add", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "MBALL_OT_reveal_metaelems", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "MBALL_OT_hide_metaelems", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "MBALL_OT_delete_metaelems", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "MBALL_OT_delete_metaelems", DELKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index c53549728f6..64bbf604f67 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -484,7 +484,7 @@ static int object_camera_add_exec(bContext *C, wmOperator *op)
float loc[3], rot[3];
/* force view align for cameras */
- RNA_boolean_set(op->ptr, "view_align", 1);
+ RNA_boolean_set(op->ptr, "view_align", TRUE);
object_add_generic_invoke_options(C, op);
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index a02b90a1d16..2fe2e71f2d9 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -807,10 +807,8 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
ibuf->userflags= IB_RECT_INVALID;
} else {
- char *rrgb= (char*)ibuf->rect + pixel*4;
- rrgb[0]= FTOCHAR(vec[0]);
- rrgb[1]= FTOCHAR(vec[1]);
- rrgb[2]= FTOCHAR(vec[2]);
+ unsigned char *rrgb= (unsigned char *)ibuf->rect + pixel*4;
+ rgb_float_to_uchar(rrgb, vec);
rrgb[3]= 255;
}
}
@@ -1257,7 +1255,7 @@ typedef struct BakeRender {
Main *main;
Scene *scene;
struct Object *actob;
- int tot, ready;
+ int result, ready;
ReportList *reports;
@@ -1330,7 +1328,7 @@ static void finish_bake_internal(BakeRender *bkr)
if(bkr->prev_r_raytrace == 0)
bkr->scene->r.mode &= ~R_RAYTRACE;
- if(bkr->tot) {
+ if(bkr->result==BAKE_RESULT_OK) {
Image *ima;
/* force OpenGL reload and mipmap recalc */
for(ima= G.main->image.first; ima; ima= ima->id.next) {
@@ -1357,7 +1355,7 @@ static void *do_bake_render(void *bake_v)
{
BakeRender *bkr= bake_v;
- bkr->tot= RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
+ bkr->result= RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
bkr->ready= 1;
return NULL;
@@ -1379,7 +1377,7 @@ static void bake_startjob(void *bkv, short *stop, short *do_update, float *progr
RE_Database_Baking(bkr->re, bmain, scene, scene->lay, scene->r.bake_mode, bkr->actob);
/* baking itself is threaded, cannot use test_break in threads. we also update optional imagewindow */
- bkr->tot= RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
+ bkr->result= RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
}
static void bake_update(void *bkv)
@@ -1398,7 +1396,11 @@ static void bake_freejob(void *bkv)
BakeRender *bkr= bkv;
finish_bake_internal(bkr);
- if(bkr->tot==0) BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
+ if(bkr->result==BAKE_RESULT_NO_OBJECTS)
+ BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
+ else if(bkr->result==BAKE_RESULT_FEEDBACK_LOOP)
+ BKE_report(bkr->reports, RPT_WARNING, "Feedback loop detected");
+
MEM_freeN(bkr);
G.rendering = 0;
}
@@ -1515,7 +1517,10 @@ static int bake_image_exec(bContext *C, wmOperator *op)
}
BLI_end_threads(&threads);
- if(bkr.tot==0) BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
+ if(bkr.result==BAKE_RESULT_NO_OBJECTS)
+ BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
+ else if(bkr.result==BAKE_RESULT_FEEDBACK_LOOP)
+ BKE_report(op->reports, RPT_ERROR, "Feedback loop detected");
finish_bake_internal(&bkr);
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 61ba54e7d36..2dc170a8a23 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -88,7 +88,7 @@
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_util.h"
-
+#include "ED_image.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -513,11 +513,15 @@ void ED_object_enter_editmode(bContext *C, int flag)
static int editmode_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
+ ToolSettings *toolsettings = CTX_data_tool_settings(C);
+
if(!CTX_data_edit_object(C))
ED_object_enter_editmode(C, EM_WAITCURSOR);
else
ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* had EM_DO_UNDO but op flag calls undo too [#24685] */
+ ED_space_image_uv_sculpt_update(CTX_wm_manager(C), toolsettings);
+
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 99eeaf334a8..09ae6365363 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -235,7 +235,7 @@ void ED_operatormacros_object(void)
if(ot) {
ot->description = "Duplicate selected objects and move them";
otmacro= WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
- RNA_boolean_set(otmacro->ptr, "linked", 1);
+ RNA_boolean_set(otmacro->ptr, "linked", TRUE);
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF);
}
@@ -268,20 +268,20 @@ void ED_keymap_object(wmKeyConfig *keyconf)
/* Note: this keymap works disregarding mode */
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_POSE);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_POSE);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", VKEY, KM_PRESS, 0, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_VERTEX_PAINT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_VERTEX_PAINT);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0);
- RNA_enum_set(kmi->ptr, "mode", OB_MODE_WEIGHT_PAINT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_enum_set(kmi->ptr, "mode", OB_MODE_WEIGHT_PAINT);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
WM_keymap_add_item(keymap, "OBJECT_OT_origin_set", CKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
@@ -296,27 +296,29 @@ void ED_keymap_object(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "VIEW3D_OT_game_start", PKEY, KM_PRESS, 0, 0);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
- RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
WM_keymap_add_item(keymap, "OBJECT_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_select_mirror", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
- RNA_boolean_set(kmi->ptr, "extend", FALSE);
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
- RNA_boolean_set(kmi->ptr, "extend", TRUE);
-
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
- RNA_boolean_set(kmi->ptr, "extend", FALSE);
- kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
- RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
WM_keymap_verify_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_verify_item(keymap, "OBJECT_OT_parent_no_inverse_set", PKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
@@ -333,20 +335,34 @@ void ED_keymap_object(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "OBJECT_OT_origin_clear", OKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_clear", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
/* same as above but for rendering */
WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_clear", HKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_CTRL, 0);
-// RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "unselected", 1); // conflicts, removing
+
+ /* conflicts, removing */
+#if 0
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+#endif
WM_keymap_add_item(keymap, "OBJECT_OT_move_to_layer", MKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "use_global", TRUE);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "use_global", FALSE);
+
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "use_global", TRUE);
+
WM_keymap_add_item(keymap, "OBJECT_OT_delete", DELKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_delete", DELKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "use_global", TRUE);
+ RNA_boolean_set(kmi->ptr, "use_global", FALSE);
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_delete", DELKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "use_global", TRUE);
WM_keymap_add_menu(keymap, "INFO_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
@@ -392,7 +408,7 @@ void ED_keymap_object(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OBJECT_OT_vertex_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
- /* menus */
+ /* menus */
WM_keymap_add_menu(keymap, "VIEW3D_MT_hook", HKEY, KM_PRESS, KM_CTRL, 0);
ED_object_generic_keymap(keyconf, keymap, 2);
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index 09f99a58dd7..473ed50b5e2 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -39,8 +39,11 @@
#include "ED_physics.h"
#include "ED_object.h"
+#include "BLI_utildefines.h"
+
#include "physics_intern.h" // own include
+
/***************************** particles ***********************************/
static void operatortypes_particle(void)
@@ -93,23 +96,30 @@ static void keymap_particle(wmKeyConfig *keyconf)
keymap= WM_keymap_find(keyconf, "Particle", 0, 0);
keymap->poll= PE_poll;
- WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", AKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
WM_keymap_add_item(keymap, "PARTICLE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1);
+
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "PARTICLE_OT_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_delete", DELKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
kmi = WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", 1);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 06e15f4a5f6..13383445c93 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -240,7 +240,7 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
}
BKE_makepicstring(name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, FALSE);
- ok= BKE_write_ibuf(ibuf, name, &scene->r.im_format); /* no need to stamp here */
+ ok= BKE_write_ibuf_as(ibuf, name, &scene->r.im_format, TRUE); /* no need to stamp here */
if(ok) printf("OpenGL Render written to '%s'\n", name);
else printf("OpenGL Render failed to write '%s'\n", name);
}
@@ -272,8 +272,8 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op)
/* ensure we have a 3d view */
if(!ED_view3d_context_activate(C)) {
- RNA_boolean_set(op->ptr, "view_context", 0);
- is_view_context= 0;
+ RNA_boolean_set(op->ptr, "view_context", FALSE);
+ is_view_context = 0;
}
/* only one render job at a time */
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 2632c239625..0d724dc1b28 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3492,7 +3492,7 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
{
ListBase *lb;
wmKeyMap *keymap;
- //wmKeyMapItem *kmi;
+ wmKeyMapItem *kmi;
/* Screen Editing ------------------------------------------------ */
keymap= WM_keymap_find(keyconf, "Screen Editing", 0, 0);
@@ -3559,7 +3559,8 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
/* render */
WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, KM_CTRL, 0)->ptr, "animation", 1);
+ kmi = WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "animation", TRUE);
WM_keymap_add_item(keymap, "RENDER_OT_view_cancel", ESCKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "RENDER_OT_view_show", F11KEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "RENDER_OT_play_rendered_anim", F11KEY, KM_PRESS, KM_CTRL, 0);
@@ -3583,20 +3584,21 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", WHEELDOWNMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "delta", 1);
RNA_int_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_offset", WHEELUPMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "delta", -1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", UPARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", DOWNARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", 0);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", UPARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", TRUE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", DOWNARROWKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "end", FALSE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", TRUE);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "end", FALSE);
WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", UPARROWKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "next", 0);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "next", FALSE);
WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", MEDIALAST, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", MEDIAFIRST, KM_PRESS, 0, 0)->ptr, "next", 0);
+ kmi = WM_keymap_add_item(keymap, "SCREEN_OT_keyframe_jump", MEDIAFIRST, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "next", FALSE);
/* play (forward and backwards) */
WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "reverse", 1);
+ RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "reverse", TRUE);
WM_keymap_add_item(keymap, "SCREEN_OT_animation_cancel", ESCKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", MEDIAPLAY, KM_PRESS, 0, 0);
@@ -3606,11 +3608,11 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
#if 0 // XXX: disabled for restoring later... bad implementation
keymap= WM_keymap_find(keyconf, "Frames", 0, 0);
kmi = WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "cycle_speed", 1);
+ RNA_boolean_set(kmi->ptr, "cycle_speed", TRUE);
kmi = WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "reverse", 1);
- RNA_boolean_set(kmi->ptr, "cycle_speed", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
+ RNA_boolean_set(kmi->ptr, "cycle_speed", TRUE);
WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", DOWNARROWKEY, KM_PRESS, KM_ALT, 0);
#endif
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index 30f49264e90..9fa91af7aec 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -27,6 +27,7 @@ set(INC
../../imbuf
../../makesdna
../../makesrna
+ ../uvedit
../../render/extern/include
../../windowmanager
../../../../intern/guardedalloc
@@ -37,6 +38,7 @@ set(INC_SYS
)
set(SRC
+ paint_cursor.c
paint_image.c
paint_ops.c
paint_stroke.c
@@ -45,6 +47,7 @@ set(SRC
paint_vertex.c
sculpt.c
sculpt_undo.c
+ sculpt_uv.c
paint_intern.h
sculpt_intern.h
diff --git a/source/blender/editors/sculpt_paint/SConscript b/source/blender/editors/sculpt_paint/SConscript
index b3927fcee68..dd82e01240b 100644
--- a/source/blender/editors/sculpt_paint/SConscript
+++ b/source/blender/editors/sculpt_paint/SConscript
@@ -8,7 +8,7 @@ defs = []
incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
incs += ' ../../render/extern/include'
-incs += ' ../../gpu ../../makesrna ../../blenloader'
+incs += ' ../../gpu ../../makesrna ../../blenloader ../uvedit'
if env['OURPLATFORM'] == 'linux':
cflags='-pthread'
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
new file mode 100644
index 00000000000..0148f11b930
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -0,0 +1,607 @@
+/*
+ * ***** 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) 2009 by Nicholas Bishop
+ * All rights reserved.
+ *
+ * Contributor(s): Jason Wilkins, Tom Musgrove.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/editors/sculpt_paint/paint_cursor.c
+ * \ingroup edsculpt
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_brush_types.h"
+#include "DNA_color_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+
+#include "BKE_brush.h"
+#include "BKE_context.h"
+#include "BKE_paint.h"
+
+#include "WM_api.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "ED_view3d.h"
+
+#include "paint_intern.h"
+/* still needed for sculpt_stroke_get_location, should be
+ removed eventually (TODO) */
+#include "sculpt_intern.h"
+
+/* TODOs:
+
+ Some of the cursor drawing code is doing non-draw stuff
+ (e.g. updating the brush rake angle). This should be cleaned up
+ still.
+
+ There is also some ugliness with sculpt-specific code.
+ */
+
+typedef struct Snapshot {
+ float size[3];
+ float ofs[3];
+ float rot;
+ int brush_size;
+ int winx;
+ int winy;
+ int brush_map_mode;
+ int curve_changed_timestamp;
+} Snapshot;
+
+static int same_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
+{
+ MTex* mtex = &brush->mtex;
+
+ return (((mtex->tex) &&
+ equals_v3v3(mtex->ofs, snap->ofs) &&
+ equals_v3v3(mtex->size, snap->size) &&
+ mtex->rot == snap->rot) &&
+
+ /* make brush smaller shouldn't cause a resample */
+ ((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED &&
+ (brush_size(vc->scene, brush) <= snap->brush_size)) ||
+ (brush_size(vc->scene, brush) == snap->brush_size)) &&
+
+ (mtex->brush_map_mode == snap->brush_map_mode) &&
+ (vc->ar->winx == snap->winx) &&
+ (vc->ar->winy == snap->winy));
+}
+
+static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
+{
+ if (brush->mtex.tex) {
+ snap->brush_map_mode = brush->mtex.brush_map_mode;
+ copy_v3_v3(snap->ofs, brush->mtex.ofs);
+ copy_v3_v3(snap->size, brush->mtex.size);
+ snap->rot = brush->mtex.rot;
+ }
+ else {
+ snap->brush_map_mode = -1;
+ snap->ofs[0]= snap->ofs[1]= snap->ofs[2]= -1;
+ snap->size[0]= snap->size[1]= snap->size[2]= -1;
+ snap->rot = -1;
+ }
+
+ snap->brush_size = brush_size(vc->scene, brush);
+ snap->winx = vc->ar->winx;
+ snap->winy = vc->ar->winy;
+}
+
+static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
+{
+ static GLuint overlay_texture = 0;
+ static int init = 0;
+ static int tex_changed_timestamp = -1;
+ static int curve_changed_timestamp = -1;
+ static Snapshot snap;
+ static int old_size = -1;
+
+ GLubyte* buffer = NULL;
+
+ int size;
+ int j;
+ int refresh;
+
+#ifndef _OPENMP
+ (void)sd; /* quied unused warning */
+#endif
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0;
+
+ refresh =
+ !overlay_texture ||
+ (br->mtex.tex &&
+ (!br->mtex.tex->preview ||
+ br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp)) ||
+ !br->curve ||
+ br->curve->changed_timestamp != curve_changed_timestamp ||
+ !same_snap(&snap, br, vc);
+
+ if (refresh) {
+ if (br->mtex.tex && br->mtex.tex->preview)
+ tex_changed_timestamp = br->mtex.tex->preview->changed_timestamp[0];
+
+ if (br->curve)
+ curve_changed_timestamp = br->curve->changed_timestamp;
+
+ make_snap(&snap, br, vc);
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ int s = brush_size(vc->scene, br);
+ int r = 1;
+
+ for (s >>= 1; s > 0; s >>= 1)
+ r++;
+
+ size = (1<<r);
+
+ if (size < 256)
+ size = 256;
+
+ if (size < old_size)
+ size = old_size;
+ }
+ else
+ size = 512;
+
+ if (old_size != size) {
+ if (overlay_texture) {
+ glDeleteTextures(1, &overlay_texture);
+ overlay_texture = 0;
+ }
+
+ init = 0;
+
+ old_size = size;
+ }
+
+ buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "load_tex");
+
+ #pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
+ for (j= 0; j < size; j++) {
+ int i;
+ float y;
+ float len;
+
+ for (i= 0; i < size; i++) {
+
+ // largely duplicated from tex_strength
+
+ const float rotation = -br->mtex.rot;
+ float radius = brush_size(vc->scene, br);
+ int index = j*size + i;
+ float x;
+ float avg;
+
+ x = (float)i/size;
+ y = (float)j/size;
+
+ x -= 0.5f;
+ y -= 0.5f;
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
+ x *= vc->ar->winx / radius;
+ y *= vc->ar->winy / radius;
+ }
+ else {
+ x *= 2;
+ y *= 2;
+ }
+
+ len = sqrtf(x*x + y*y);
+
+ if ((br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) || len <= 1) {
+ /* it is probably worth optimizing for those cases where
+ the texture is not rotated by skipping the calls to
+ atan2, sqrtf, sin, and cos. */
+ if (br->mtex.tex && (rotation > 0.001f || rotation < -0.001f)) {
+ const float angle = atan2f(y, x) + rotation;
+
+ x = len * cosf(angle);
+ y = len * sinf(angle);
+ }
+
+ x *= br->mtex.size[0];
+ y *= br->mtex.size[1];
+
+ x += br->mtex.ofs[0];
+ y += br->mtex.ofs[1];
+
+ avg = br->mtex.tex ? paint_get_tex_pixel(br, x, y) : 1;
+
+ avg += br->texture_sample_bias;
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED)
+ avg *= brush_curve_strength(br, len, 1); /* Falloff curve */
+
+ buffer[index] = 255 - (GLubyte)(255*avg);
+ }
+ else {
+ buffer[index] = 0;
+ }
+ }
+ }
+
+ if (!overlay_texture)
+ glGenTextures(1, &overlay_texture);
+ }
+ else {
+ size= old_size;
+ }
+
+ glBindTexture(GL_TEXTURE_2D, overlay_texture);
+
+ if (refresh) {
+ if (!init) {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ init = 1;
+ }
+ else {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ }
+
+ if (buffer)
+ MEM_freeN(buffer);
+ }
+
+ glEnable(GL_TEXTURE_2D);
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+ }
+
+ return 1;
+}
+
+static int project_brush_radius(ViewContext *vc,
+ float radius,
+ const float location[3])
+{
+ float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
+
+ ED_view3d_global_to_vector(vc->rv3d, location, view);
+
+ // create a vector that is not orthogonal to view
+
+ if (fabsf(view[0]) < 0.1f) {
+ nonortho[0] = view[0] + 1.0f;
+ nonortho[1] = view[1];
+ nonortho[2] = view[2];
+ }
+ else if (fabsf(view[1]) < 0.1f) {
+ nonortho[0] = view[0];
+ nonortho[1] = view[1] + 1.0f;
+ nonortho[2] = view[2];
+ }
+ else {
+ nonortho[0] = view[0];
+ nonortho[1] = view[1];
+ nonortho[2] = view[2] + 1.0f;
+ }
+
+ // get a vector in the plane of the view
+ cross_v3_v3v3(ortho, nonortho, view);
+ normalize_v3(ortho);
+
+ // make a point on the surface of the brush tagent to the view
+ mul_v3_fl(ortho, radius);
+ add_v3_v3v3(offset, location, ortho);
+
+ // project the center of the brush, and the tangent point to the view onto the screen
+ project_float(vc->ar, location, p1);
+ project_float(vc->ar, offset, p2);
+
+ // the distance between these points is the size of the projected brush in pixels
+ return len_v2v2(p1, p2);
+}
+
+static int sculpt_get_brush_geometry(bContext* C, ViewContext *vc,
+ int x, int y, int* pixel_radius,
+ float location[3])
+{
+ Scene *scene = CTX_data_scene(C);
+ Paint *paint = paint_get_active(scene);
+ Brush *brush = paint_brush(paint);
+ float window[2];
+ int hit;
+
+ window[0] = x + vc->ar->winrct.xmin;
+ window[1] = y + vc->ar->winrct.ymin;
+
+ if(vc->obact->sculpt && vc->obact->sculpt->pbvh &&
+ sculpt_stroke_get_location(C, location, window)) {
+ *pixel_radius =
+ project_brush_radius(vc,
+ brush_unprojected_radius(scene, brush),
+ location);
+
+ if (*pixel_radius == 0)
+ *pixel_radius = brush_size(scene, brush);
+
+ mul_m4_v3(vc->obact->obmat, location);
+
+ hit = 1;
+ }
+ else {
+ Sculpt* sd = CTX_data_tool_settings(C)->sculpt;
+ Brush* brush = paint_brush(&sd->paint);
+
+ *pixel_radius = brush_size(scene, brush);
+ hit = 0;
+ }
+
+ return hit;
+}
+
+/* Draw an overlay that shows what effect the brush's texture will
+ have on brush strength */
+/* TODO: sculpt only for now */
+static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
+ ViewContext *vc, int x, int y)
+{
+ rctf quad;
+
+ /* check for overlay mode */
+ if(!(brush->flag & BRUSH_TEXTURE_OVERLAY) ||
+ !(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED)))
+ return;
+
+ /* save lots of GL state
+ TODO: check on whether all of these are needed? */
+ glPushAttrib(GL_COLOR_BUFFER_BIT|
+ GL_CURRENT_BIT|
+ GL_DEPTH_BUFFER_BIT|
+ GL_ENABLE_BIT|
+ GL_LINE_BIT|
+ GL_POLYGON_BIT|
+ GL_STENCIL_BUFFER_BIT|
+ GL_TRANSFORM_BIT|
+ GL_VIEWPORT_BIT|
+ GL_TEXTURE_BIT);
+
+ if(load_tex(sd, brush, vc)) {
+ glEnable(GL_BLEND);
+
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glDepthMask(GL_FALSE);
+ glDepthFunc(GL_ALWAYS);
+
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+ glLoadIdentity();
+
+ if(brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ /* brush rotation */
+ glTranslatef(0.5, 0.5, 0);
+ glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ?
+ sd->last_angle : sd->special_rotation),
+ 0.0, 0.0, 1.0);
+ glTranslatef(-0.5f, -0.5f, 0);
+
+ /* scale based on tablet pressure */
+ if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush)) {
+ glTranslatef(0.5f, 0.5f, 0);
+ glScalef(1.0f/sd->pressure_value, 1.0f/sd->pressure_value, 1);
+ glTranslatef(-0.5f, -0.5f, 0);
+ }
+
+ if(sd->draw_anchored) {
+ const float *aim = sd->anchored_initial_mouse;
+ const rcti *win = &vc->ar->winrct;
+ quad.xmin = aim[0]-sd->anchored_size - win->xmin;
+ quad.ymin = aim[1]-sd->anchored_size - win->ymin;
+ quad.xmax = aim[0]+sd->anchored_size - win->xmin;
+ quad.ymax = aim[1]+sd->anchored_size - win->ymin;
+ }
+ else {
+ const int radius= brush_size(vc->scene, brush);
+ quad.xmin = x - radius;
+ quad.ymin = y - radius;
+ quad.xmax = x + radius;
+ quad.ymax = y + radius;
+ }
+ }
+ else {
+ quad.xmin = 0;
+ quad.ymin = 0;
+ quad.xmax = vc->ar->winrct.xmax - vc->ar->winrct.xmin;
+ quad.ymax = vc->ar->winrct.ymax - vc->ar->winrct.ymin;
+ }
+
+ /* set quad color */
+ glColor4f(U.sculpt_paint_overlay_col[0],
+ U.sculpt_paint_overlay_col[1],
+ U.sculpt_paint_overlay_col[2],
+ brush->texture_overlay_alpha / 100.0f);
+
+ /* draw textured quad */
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0);
+ glVertex2f(quad.xmin, quad.ymin);
+ glTexCoord2f(1, 0);
+ glVertex2f(quad.xmax, quad.ymin);
+ glTexCoord2f(1, 1);
+ glVertex2f(quad.xmax, quad.ymax);
+ glTexCoord2f(0, 1);
+ glVertex2f(quad.xmin, quad.ymax);
+ glEnd();
+
+ glPopMatrix();
+ }
+
+ glPopAttrib();
+}
+
+/* Special actions taken when paint cursor goes over mesh */
+/* TODO: sculpt only for now */
+static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
+ const float location[3])
+{
+ float unprojected_radius, projected_radius;
+
+ /* update the brush's cached 3D radius */
+ if(!brush_use_locked_size(vc->scene, brush)) {
+ /* get 2D brush radius */
+ if(sd->draw_anchored)
+ projected_radius = sd->anchored_size;
+ else {
+ if(brush->flag & BRUSH_ANCHORED)
+ projected_radius = 8;
+ else
+ projected_radius = brush_size(vc->scene, brush);
+ }
+
+ /* convert brush radius from 2D to 3D */
+ unprojected_radius = paint_calc_object_space_radius(vc, location,
+ projected_radius);
+
+ /* scale 3D brush radius by pressure */
+ if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush))
+ unprojected_radius *= sd->pressure_value;
+
+ /* set cached value in either Brush or UnifiedPaintSettings */
+ brush_set_unprojected_radius(vc->scene, brush, unprojected_radius);
+ }
+}
+
+static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
+{
+ Scene *scene = CTX_data_scene(C);
+ Paint *paint = paint_get_active(scene);
+ Brush *brush = paint_brush(paint);
+ ViewContext vc;
+ float final_radius;
+ float translation[2];
+ float outline_alpha, *outline_col;
+
+ /* set various defaults */
+ translation[0] = x;
+ translation[1] = y;
+ outline_alpha = 0.5;
+ outline_col = brush->add_col;
+ final_radius = brush_size(scene, brush);
+
+ /* check that brush drawing is enabled */
+ if(!(paint->flags & PAINT_SHOW_BRUSH))
+ return;
+
+ /* can't use stroke vc here because this will be called during
+ mouse over too, not just during a stroke */
+ view3d_set_viewcontext(C, &vc);
+
+ /* TODO: as sculpt and other paint modes are unified, this
+ special mode of drawing will go away */
+ if(vc.obact->sculpt) {
+ Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
+ float location[3];
+ int pixel_radius, hit;
+
+ /* this is probably here so that rake takes into
+ account the brush movements before the stroke
+ starts, but this doesn't really belong in draw code
+ (TODO) */
+ {
+ const float u = 0.5f;
+ const float v = 1 - u;
+ const float r = 20;
+
+ const float dx = sd->last_x - x;
+ const float dy = sd->last_y - y;
+
+ if(dx*dx + dy*dy >= r*r) {
+ sd->last_angle = atan2(dx, dy);
+
+ sd->last_x = u*sd->last_x + v*x;
+ sd->last_y = u*sd->last_y + v*y;
+ }
+ }
+
+ /* test if brush is over the mesh */
+ hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location);
+
+ /* draw overlay */
+ paint_draw_alpha_overlay(sd, brush, &vc, x, y);
+
+ if(brush_use_locked_size(scene, brush))
+ brush_set_size(scene, brush, pixel_radius);
+
+ /* check if brush is subtracting, use different color then */
+ /* TODO: no way currently to know state of pen flip or
+ invert key modifier without starting a stroke */
+ if((!(brush->flag & BRUSH_INVERTED) ^
+ !(brush->flag & BRUSH_DIR_IN)) &&
+ ELEM5(brush->sculpt_tool, SCULPT_TOOL_DRAW,
+ SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY,
+ SCULPT_TOOL_PINCH, SCULPT_TOOL_CREASE))
+ outline_col = brush->sub_col;
+
+ /* only do if brush is over the mesh */
+ if(hit)
+ paint_cursor_on_hit(sd, brush, &vc, location);
+
+ if(sd->draw_anchored) {
+ final_radius = sd->anchored_size;
+ translation[0] = sd->anchored_initial_mouse[0] - vc.ar->winrct.xmin;
+ translation[1] = sd->anchored_initial_mouse[1] - vc.ar->winrct.ymin;
+ }
+ }
+
+ /* make lines pretty */
+ glEnable(GL_BLEND);
+ glEnable(GL_LINE_SMOOTH);
+
+ /* set brush color */
+ glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha);
+
+ /* draw brush outline */
+ glTranslatef(translation[0], translation[1], 0);
+ glutil_draw_lined_arc(0.0, M_PI*2.0, final_radius, 40);
+ glTranslatef(-translation[0], -translation[1], 0);
+
+ /* restore GL state */
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+}
+
+/* Public API */
+
+void paint_cursor_start(bContext *C, int (*poll)(bContext *C))
+{
+ Paint *p = paint_get_active(CTX_data_scene(C));
+
+ if(p && !p->paint_cursor)
+ p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
+}
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 8eeca2e4e15..a5b79d0c974 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -50,6 +50,7 @@
#include "BLI_memarena.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
+#include "BLI_editVert.h"
#include "PIL_time.h"
@@ -80,6 +81,8 @@
#include "BKE_paint.h"
#include "BKE_report.h"
#include "BKE_scene.h"
+#include "BKE_global.h"
+#include "BKE_deform.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
@@ -91,6 +94,7 @@
#include "ED_sculpt.h"
#include "ED_uvedit.h"
#include "ED_view3d.h"
+#include "ED_mesh.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -100,6 +104,7 @@
#include "RNA_enum_types.h"
#include "GPU_draw.h"
+#include "GPU_extensions.h"
#include "paint_intern.h"
@@ -3742,15 +3747,13 @@ static void do_projectpaint_smear(ProjPaintState *ps, ProjPixel *projPixel, floa
static void do_projectpaint_smear_f(ProjPaintState *ps, ProjPixel *projPixel, float alpha, float mask, MemArena *smearArena, LinkNode **smearPixels_f, float co[2])
{
- unsigned char rgba_ub[4];
- unsigned char rgba_smear[4];
+ float rgba[4];
- if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1)==0)
+ if (project_paint_PickColor(ps, co, rgba, NULL, 1)==0)
return;
- IMAPAINT_FLOAT_RGBA_TO_CHAR(rgba_smear, projPixel->pixel.f_pt);
/* (ProjPixelClone *)projPixel)->clonepx.uint = IMB_blend_color(*((unsigned int *)rgba_smear), *((unsigned int *)rgba_ub), (int)(alpha*mask*255), ps->blend); */
- blend_color_mix(((ProjPixelClone *)projPixel)->clonepx.ch, rgba_smear, (rgba_ub), (int)(alpha*mask*255));
+ blend_color_mix_float(((ProjPixelClone *)projPixel)->clonepx.f, projPixel->pixel.f_pt, rgba, alpha*mask);
BLI_linklist_prepend_arena(smearPixels_f, (void *)projPixel, smearArena);
}
@@ -3782,8 +3785,8 @@ static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, flo
{
if (ps->is_texbrush) {
/* rgba already holds a texture result here from higher level function */
- float rgba_br[3];
if(use_color_correction){
+ float rgba_br[3];
srgb_to_linearrgb_v3_v3(rgba_br, ps->brush->rgb);
mul_v3_v3(rgba, rgba_br);
}
@@ -3999,7 +4002,7 @@ static void *do_projectpaint_thread(void *ph_v)
for (node= smearPixels_f; node; node= node->next) {
projPixel = node->link;
- IMAPAINT_CHAR_RGBA_TO_FLOAT(projPixel->pixel.f_pt, ((ProjPixelClone *)projPixel)->clonepx.ch);
+ copy_v4_v4(projPixel->pixel.f_pt, ((ProjPixelClone *)projPixel)->clonepx.f);
}
BLI_memarena_free(smearArena);
@@ -4167,7 +4170,8 @@ static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, s
if(texpaint || (sima && sima->lock)) {
int w = imapaintpartial.x2 - imapaintpartial.x1;
int h = imapaintpartial.y2 - imapaintpartial.y1;
- GPU_paint_update_image(image, imapaintpartial.x1, imapaintpartial.y1, w, h, !texpaint);
+ /* Testing with partial update in uv editor too */
+ GPU_paint_update_image(image, imapaintpartial.x1, imapaintpartial.y1, w, h, 0);//!texpaint);
}
}
@@ -4606,6 +4610,16 @@ static Brush *image_paint_brush(bContext *C)
return paint_brush(&settings->imapaint.paint);
}
+static Brush *uv_sculpt_brush(bContext *C)
+{
+ Scene *scene= CTX_data_scene(C);
+ ToolSettings *settings= scene->toolsettings;
+
+ if(!settings->uvsculpt)
+ return NULL;
+ return paint_brush(&settings->uvsculpt->paint);
+}
+
static int image_paint_poll(bContext *C)
{
Object *obact = CTX_data_active_object(C);
@@ -4630,6 +4644,31 @@ static int image_paint_poll(bContext *C)
return 0;
}
+static int uv_sculpt_brush_poll(bContext *C)
+{
+ EditMesh *em;
+ int ret;
+ Object *obedit = CTX_data_edit_object(C);
+ SpaceImage *sima= CTX_wm_space_image(C);
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *toolsettings = scene->toolsettings;
+
+ if(!uv_sculpt_brush(C) || !obedit || obedit->type != OB_MESH)
+ return 0;
+
+ em = BKE_mesh_get_editmesh(obedit->data);
+ ret = EM_texFaceCheck(em);
+ BKE_mesh_end_editmesh(obedit->data, em);
+
+ if(ret && sima) {
+ ARegion *ar= CTX_wm_region(C);
+ if((toolsettings->use_uv_sculpt) && ar->regiontype==RGN_TYPE_WINDOW)
+ return 1;
+ }
+
+ return 0;
+}
+
static int image_paint_3d_poll(bContext *C)
{
if(CTX_wm_region_view3d(C))
@@ -5086,7 +5125,7 @@ void PAINT_OT_image_paint(wmOperatorType *ot)
RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
}
-static int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
+int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
{
RegionView3D *rv3d= CTX_wm_region_view3d(C);
@@ -5112,16 +5151,27 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
#define PX_SIZE_FADE_MIN 4.0f
Scene *scene= CTX_data_scene(C);
- Brush *brush= image_paint_brush(C);
+ //Brush *brush= image_paint_brush(C);
Paint *paint= paint_get_active(scene);
+ Brush *brush= paint_brush(paint);
if(paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
+ ToolSettings *ts;
float zoomx, zoomy;
const float size= (float)brush_size(scene, brush);
const short use_zoom= get_imapaint_zoom(C, &zoomx, &zoomy);
- const float pixel_size= MAX2(size * zoomx, size * zoomy);
+ float pixel_size;
float alpha= 0.5f;
+ ts = scene->toolsettings;
+
+ if(use_zoom && !ts->use_uv_sculpt){
+ pixel_size = MAX2(size * zoomx, size * zoomy);
+ }
+ else {
+ pixel_size = size;
+ }
+
/* fade out the brush (cheap trick to work around brush interfearing with sampling [#])*/
if(pixel_size < PX_SIZE_FADE_MIN) {
return;
@@ -5134,7 +5184,8 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
glTranslatef((float)x, (float)y, 0.0f);
- if(use_zoom)
+ /* No need to scale for uv sculpting, on the contrary it might be useful to keep unscaled */
+ if(use_zoom && !ts->use_uv_sculpt)
glScalef(zoomx, zoomy, 1.0f);
glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha);
@@ -5152,14 +5203,16 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
static void toggle_paint_cursor(bContext *C, int enable)
{
- ToolSettings *settings= CTX_data_scene(C)->toolsettings;
+ wmWindowManager *wm= CTX_wm_manager(C);
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *settings= scene->toolsettings;
if(settings->imapaint.paintcursor && !enable) {
- WM_paint_cursor_end(CTX_wm_manager(C), settings->imapaint.paintcursor);
+ WM_paint_cursor_end(wm, settings->imapaint.paintcursor);
settings->imapaint.paintcursor = NULL;
}
else if(enable)
- settings->imapaint.paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, brush_drawcursor, NULL);
+ settings->imapaint.paintcursor= WM_paint_cursor_activate(wm, image_paint_poll, brush_drawcursor, NULL);
}
/* enable the paint cursor if it isn't already.
@@ -5178,6 +5231,27 @@ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings)
}
}
+
+void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings)
+{
+ if(settings->use_uv_sculpt) {
+ if(!settings->uvsculpt) {
+ settings->uvsculpt = MEM_callocN(sizeof(*settings->uvsculpt), "UV Smooth paint");
+ settings->uv_sculpt_tool = UV_SCULPT_TOOL_GRAB;
+ settings->uv_sculpt_settings = UV_SCULPT_LOCK_BORDERS | UV_SCULPT_ALL_ISLANDS;
+ settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN;
+ }
+
+ paint_init(&settings->uvsculpt->paint, PAINT_CURSOR_SCULPT);
+
+ WM_paint_cursor_activate(wm, uv_sculpt_brush_poll,
+ brush_drawcursor, NULL);
+ }
+ else {
+ if(settings->uvsculpt)
+ settings->uvsculpt->paint.flags &= ~PAINT_SHOW_BRUSH;
+ }
+}
/************************ grab clone operator ************************/
typedef struct GrabClone {
@@ -5499,6 +5573,11 @@ int image_texture_paint_poll(bContext *C)
return (texture_paint_poll(C) || image_paint_poll(C));
}
+int uv_sculpt_poll(bContext *C)
+{
+ return uv_sculpt_brush_poll(C);
+}
+
int facemask_paint_poll(bContext *C)
{
return paint_facesel_test(CTX_data_active_object(C));
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index a5e68f9a244..73dc1e236f6 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -50,7 +50,7 @@ struct wmOperator;
struct wmOperatorType;
/* paint_stroke.c */
-typedef int (*StrokeGetLocation)(struct bContext *C, struct PaintStroke *stroke, float location[3], float mouse[2]);
+typedef int (*StrokeGetLocation)(struct bContext *C, float location[3], float mouse[2]);
typedef int (*StrokeTestStart)(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
typedef void (*StrokeUpdateStep)(struct bContext *C, struct PaintStroke *stroke, struct PointerRNA *itemptr);
typedef void (*StrokeDone)(struct bContext *C, struct PaintStroke *stroke);
@@ -103,6 +103,10 @@ void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
void PAINT_OT_project_image(struct wmOperatorType *ot);
void PAINT_OT_image_from_view(struct wmOperatorType *ot);
+/* uv sculpting */
+int uv_sculpt_poll(struct bContext *C);
+
+void SCULPT_OT_uv_sculpt_stroke(struct wmOperatorType *ot);
/* paint_utils.c */
@@ -126,7 +130,7 @@ void paint_calc_redraw_planes(float planes[4][4],
const struct rcti *screen_rect);
void projectf(struct bglMats *mats, const float v[3], float p[2]);
-float paint_calc_object_space_radius(struct ViewContext *vc, float center[3], float pixel_radius);
+float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius);
float paint_get_tex_pixel(struct Brush* br, float u, float v);
int imapaint_pick_face(struct ViewContext *vc, struct Mesh *me, const int mval[2], unsigned int *index);
void imapaint_pick_uv(struct Scene *scene, struct Object *ob, unsigned int faceindex, const int xy[2], float uv[2]);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index e81e1f6dc77..c2026b30ab2 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -340,6 +340,39 @@ static void BRUSH_OT_image_tool_set(wmOperatorType *ot)
}
+static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
+{
+ Brush *brush;
+ Scene *scene= CTX_data_scene(C);
+ ToolSettings *ts = scene->toolsettings;
+ ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
+ brush = ts->uvsculpt->paint.brush;
+ /* To update toolshelf */
+ WM_event_add_notifier(C, NC_BRUSH|NA_EDITED, brush);
+
+ return OPERATOR_FINISHED;
+}
+
+static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot)
+{
+ /* from rna_scene.c */
+ extern EnumPropertyItem uv_sculpt_tool_items[];
+ /* identifiers */
+ ot->name = "UV Sculpt Tool Set";
+ ot->description = "Set the uv sculpt tool";
+ ot->idname = "BRUSH_OT_uv_sculpt_tool_set";
+
+ /* api callbacks */
+ ot->exec = brush_uv_sculpt_tool_set_exec;
+ ot->poll = uv_sculpt_poll;
+
+ /* flags */
+ ot->flag = 0;
+
+ /* props */
+ ot->prop = RNA_def_enum(ot->srna, "tool", uv_sculpt_tool_items, 0, "Tool", "");
+}
+
/**************************** registration **********************************/
void ED_operatortypes_paint(void)
@@ -355,6 +388,7 @@ void ED_operatortypes_paint(void)
WM_operatortype_append(BRUSH_OT_vertex_tool_set);
WM_operatortype_append(BRUSH_OT_weight_tool_set);
WM_operatortype_append(BRUSH_OT_image_tool_set);
+ WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set);
/* image */
WM_operatortype_append(PAINT_OT_texture_paint_toggle);
@@ -373,6 +407,9 @@ void ED_operatortypes_paint(void)
WM_operatortype_append(PAINT_OT_weight_sample);
WM_operatortype_append(PAINT_OT_weight_sample_group);
+ /* uv */
+ WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke);
+
/* vertex selection */
WM_operatortype_append(PAINT_OT_vert_select_all);
WM_operatortype_append(PAINT_OT_vert_select_inverse);
@@ -395,67 +432,14 @@ void ED_operatortypes_paint(void)
static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
{
wmKeyMapItem *kmi;
-
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 0);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 1);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 2);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 3);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 4);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 5);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 6);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 7);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 8);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 9);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 10);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 11);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 12);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 13);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 14);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 15);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 16);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 17);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 18);
- kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(kmi->ptr, "mode", mode);
- RNA_int_set(kmi->ptr, "index", 19);
+ int i;
+ /* index 0-9 (zero key is tenth), shift key for index 10-19 */
+ for (i = 0; i < 20; i++) {
+ kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
+ ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
+ RNA_string_set(kmi->ptr, "mode", mode);
+ RNA_int_set(kmi->ptr, "index", i);
+ }
}
static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
@@ -556,11 +540,11 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
/* multires switch */
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
RNA_int_set(kmi->ptr, "level", 1);
- RNA_boolean_set(kmi->ptr, "relative", 1);
+ RNA_boolean_set(kmi->ptr, "relative", TRUE);
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
RNA_int_set(kmi->ptr, "level", -1);
- RNA_boolean_set(kmi->ptr, "relative", 1);
+ RNA_boolean_set(kmi->ptr, "relative", TRUE);
ed_keymap_paint_brush_switch(keymap, "sculpt");
ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
@@ -636,8 +620,10 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0)->ptr, "deselect", 1);
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
/* Image/Texture Paint mode */
@@ -662,10 +648,30 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+
+ keymap= WM_keymap_find(keyconf, "UV Sculpt", 0, 0);
+ keymap->poll= uv_sculpt_poll;
+
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
+
+ RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0, 0)->ptr, "mode", BRUSH_STROKE_NORMAL);
+ RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "mode", BRUSH_STROKE_INVERT);
+ RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
+
+ ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
+ ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
+
+ RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_RELAX);
+ RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_PINCH);
+ RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_GRAB);
+
}
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index c3e0c35f524..cd8262f06bd 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -56,9 +56,6 @@
#include "ED_view3d.h"
#include "paint_intern.h"
-/* still needed for sculpt_stroke_get_location, should be
- removed eventually (TODO) */
-#include "sculpt_intern.h"
#include <float.h>
#include <math.h>
@@ -108,545 +105,6 @@ static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata
glDisable(GL_LINE_SMOOTH);
}
-typedef struct Snapshot {
- float size[3];
- float ofs[3];
- float rot;
- int brush_size;
- int winx;
- int winy;
- int brush_map_mode;
- int curve_changed_timestamp;
-} Snapshot;
-
-static int same_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
-{
- MTex* mtex = &brush->mtex;
-
- return (((mtex->tex) &&
- equals_v3v3(mtex->ofs, snap->ofs) &&
- equals_v3v3(mtex->size, snap->size) &&
- mtex->rot == snap->rot) &&
-
- /* make brush smaller shouldn't cause a resample */
- ((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED &&
- (brush_size(vc->scene, brush) <= snap->brush_size)) ||
- (brush_size(vc->scene, brush) == snap->brush_size)) &&
-
- (mtex->brush_map_mode == snap->brush_map_mode) &&
- (vc->ar->winx == snap->winx) &&
- (vc->ar->winy == snap->winy));
-}
-
-static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
-{
- if (brush->mtex.tex) {
- snap->brush_map_mode = brush->mtex.brush_map_mode;
- copy_v3_v3(snap->ofs, brush->mtex.ofs);
- copy_v3_v3(snap->size, brush->mtex.size);
- snap->rot = brush->mtex.rot;
- }
- else {
- snap->brush_map_mode = -1;
- snap->ofs[0]= snap->ofs[1]= snap->ofs[2]= -1;
- snap->size[0]= snap->size[1]= snap->size[2]= -1;
- snap->rot = -1;
- }
-
- snap->brush_size = brush_size(vc->scene, brush);
- snap->winx = vc->ar->winx;
- snap->winy = vc->ar->winy;
-}
-
-static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
-{
- static GLuint overlay_texture = 0;
- static int init = 0;
- static int tex_changed_timestamp = -1;
- static int curve_changed_timestamp = -1;
- static Snapshot snap;
- static int old_size = -1;
-
- GLubyte* buffer = NULL;
-
- int size;
- int j;
- int refresh;
-
-#ifndef _OPENMP
- (void)sd; /* quied unused warning */
-#endif
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0;
-
- refresh =
- !overlay_texture ||
- (br->mtex.tex &&
- (!br->mtex.tex->preview ||
- br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp)) ||
- !br->curve ||
- br->curve->changed_timestamp != curve_changed_timestamp ||
- !same_snap(&snap, br, vc);
-
- if (refresh) {
- if (br->mtex.tex && br->mtex.tex->preview)
- tex_changed_timestamp = br->mtex.tex->preview->changed_timestamp[0];
-
- if (br->curve)
- curve_changed_timestamp = br->curve->changed_timestamp;
-
- make_snap(&snap, br, vc);
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
- int s = brush_size(vc->scene, br);
- int r = 1;
-
- for (s >>= 1; s > 0; s >>= 1)
- r++;
-
- size = (1<<r);
-
- if (size < 256)
- size = 256;
-
- if (size < old_size)
- size = old_size;
- }
- else
- size = 512;
-
- if (old_size != size) {
- if (overlay_texture) {
- glDeleteTextures(1, &overlay_texture);
- overlay_texture = 0;
- }
-
- init = 0;
-
- old_size = size;
- }
-
- buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "load_tex");
-
- #pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
- for (j= 0; j < size; j++) {
- int i;
- float y;
- float len;
-
- for (i= 0; i < size; i++) {
-
- // largely duplicated from tex_strength
-
- const float rotation = -br->mtex.rot;
- float radius = brush_size(vc->scene, br);
- int index = j*size + i;
- float x;
- float avg;
-
- x = (float)i/size;
- y = (float)j/size;
-
- x -= 0.5f;
- y -= 0.5f;
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
- x *= vc->ar->winx / radius;
- y *= vc->ar->winy / radius;
- }
- else {
- x *= 2;
- y *= 2;
- }
-
- len = sqrtf(x*x + y*y);
-
- if ((br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) || len <= 1) {
- /* it is probably worth optimizing for those cases where
- the texture is not rotated by skipping the calls to
- atan2, sqrtf, sin, and cos. */
- if (br->mtex.tex && (rotation > 0.001f || rotation < -0.001f)) {
- const float angle = atan2f(y, x) + rotation;
-
- x = len * cosf(angle);
- y = len * sinf(angle);
- }
-
- x *= br->mtex.size[0];
- y *= br->mtex.size[1];
-
- x += br->mtex.ofs[0];
- y += br->mtex.ofs[1];
-
- avg = br->mtex.tex ? paint_get_tex_pixel(br, x, y) : 1;
-
- avg += br->texture_sample_bias;
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED)
- avg *= brush_curve_strength(br, len, 1); /* Falloff curve */
-
- buffer[index] = 255 - (GLubyte)(255*avg);
- }
- else {
- buffer[index] = 0;
- }
- }
- }
-
- if (!overlay_texture)
- glGenTextures(1, &overlay_texture);
- }
- else {
- size= old_size;
- }
-
- glBindTexture(GL_TEXTURE_2D, overlay_texture);
-
- if (refresh) {
- if (!init) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
- init = 1;
- }
- else {
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
- }
-
- if (buffer)
- MEM_freeN(buffer);
- }
-
- glEnable(GL_TEXTURE_2D);
-
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
- }
-
- return 1;
-}
-
-static int project_brush_radius(RegionView3D* rv3d, float radius, float location[3], bglMats* mats)
-{
- float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
-
- ED_view3d_global_to_vector(rv3d, location, view);
-
- // create a vector that is not orthogonal to view
-
- if (fabsf(view[0]) < 0.1f) {
- nonortho[0] = view[0] + 1.0f;
- nonortho[1] = view[1];
- nonortho[2] = view[2];
- }
- else if (fabsf(view[1]) < 0.1f) {
- nonortho[0] = view[0];
- nonortho[1] = view[1] + 1.0f;
- nonortho[2] = view[2];
- }
- else {
- nonortho[0] = view[0];
- nonortho[1] = view[1];
- nonortho[2] = view[2] + 1.0f;
- }
-
- // get a vector in the plane of the view
- cross_v3_v3v3(ortho, nonortho, view);
- normalize_v3(ortho);
-
- // make a point on the surface of the brush tagent to the view
- mul_v3_fl(ortho, radius);
- add_v3_v3v3(offset, location, ortho);
-
- // project the center of the brush, and the tagent point to the view onto the screen
- projectf(mats, location, p1);
- projectf(mats, offset, p2);
-
- // the distance between these points is the size of the projected brush in pixels
- return len_v2v2(p1, p2);
-}
-
-static int sculpt_get_brush_geometry(bContext* C, int x, int y, int* pixel_radius,
- float location[3])
-{
- struct PaintStroke *stroke;
- const Scene *scene = CTX_data_scene(C);
- float window[2];
- int hit;
-
- stroke = paint_stroke_new(C, NULL, NULL, NULL, NULL, 0);
-
- window[0] = x + stroke->vc.ar->winrct.xmin;
- window[1] = y + stroke->vc.ar->winrct.ymin;
-
- if(stroke->vc.obact->sculpt && stroke->vc.obact->sculpt->pbvh &&
- sculpt_stroke_get_location(C, stroke, location, window)) {
- *pixel_radius = project_brush_radius(stroke->vc.rv3d,
- brush_unprojected_radius(scene, stroke->brush),
- location, &stroke->mats);
-
- if (*pixel_radius == 0)
- *pixel_radius = brush_size(scene, stroke->brush);
-
- mul_m4_v3(stroke->vc.obact->obmat, location);
-
- hit = 1;
- }
- else {
- Sculpt* sd = CTX_data_tool_settings(C)->sculpt;
- Brush* brush = paint_brush(&sd->paint);
-
- *pixel_radius = brush_size(scene, brush);
- hit = 0;
- }
-
- paint_stroke_free(stroke);
-
- return hit;
-}
-
-/* Draw an overlay that shows what effect the brush's texture will
- have on brush strength */
-/* TODO: sculpt only for now */
-static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
- ViewContext *vc, int x, int y)
-{
- rctf quad;
-
- /* check for overlay mode */
- if(!(brush->flag & BRUSH_TEXTURE_OVERLAY) ||
- !(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED)))
- return;
-
- /* save lots of GL state
- TODO: check on whether all of these are needed? */
- glPushAttrib(GL_COLOR_BUFFER_BIT|
- GL_CURRENT_BIT|
- GL_DEPTH_BUFFER_BIT|
- GL_ENABLE_BIT|
- GL_LINE_BIT|
- GL_POLYGON_BIT|
- GL_STENCIL_BUFFER_BIT|
- GL_TRANSFORM_BIT|
- GL_VIEWPORT_BIT|
- GL_TEXTURE_BIT);
-
- if(load_tex(sd, brush, vc)) {
- glEnable(GL_BLEND);
-
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDepthMask(GL_FALSE);
- glDepthFunc(GL_ALWAYS);
-
- glMatrixMode(GL_TEXTURE);
- glPushMatrix();
- glLoadIdentity();
-
- if(brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
- /* brush rotation */
- glTranslatef(0.5, 0.5, 0);
- glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ?
- sd->last_angle : sd->special_rotation),
- 0.0, 0.0, 1.0);
- glTranslatef(-0.5f, -0.5f, 0);
-
- /* scale based on tablet pressure */
- if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush)) {
- glTranslatef(0.5f, 0.5f, 0);
- glScalef(1.0f/sd->pressure_value, 1.0f/sd->pressure_value, 1);
- glTranslatef(-0.5f, -0.5f, 0);
- }
-
- if(sd->draw_anchored) {
- const float *aim = sd->anchored_initial_mouse;
- const rcti *win = &vc->ar->winrct;
- quad.xmin = aim[0]-sd->anchored_size - win->xmin;
- quad.ymin = aim[1]-sd->anchored_size - win->ymin;
- quad.xmax = aim[0]+sd->anchored_size - win->xmin;
- quad.ymax = aim[1]+sd->anchored_size - win->ymin;
- }
- else {
- const int radius= brush_size(vc->scene, brush);
- quad.xmin = x - radius;
- quad.ymin = y - radius;
- quad.xmax = x + radius;
- quad.ymax = y + radius;
- }
- }
- else {
- quad.xmin = 0;
- quad.ymin = 0;
- quad.xmax = vc->ar->winrct.xmax - vc->ar->winrct.xmin;
- quad.ymax = vc->ar->winrct.ymax - vc->ar->winrct.ymin;
- }
-
- /* set quad color */
- glColor4f(U.sculpt_paint_overlay_col[0],
- U.sculpt_paint_overlay_col[1],
- U.sculpt_paint_overlay_col[2],
- brush->texture_overlay_alpha / 100.0f);
-
- /* draw textured quad */
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(quad.xmin, quad.ymin);
- glTexCoord2f(1, 0);
- glVertex2f(quad.xmax, quad.ymin);
- glTexCoord2f(1, 1);
- glVertex2f(quad.xmax, quad.ymax);
- glTexCoord2f(0, 1);
- glVertex2f(quad.xmin, quad.ymax);
- glEnd();
-
- glPopMatrix();
- }
-
- glPopAttrib();
-}
-
-/* Special actions taken when paint cursor goes over mesh */
-/* TODO: sculpt only for now */
-static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
- float location[3], float *visual_strength)
-{
- float unprojected_radius, projected_radius;
-
- /* TODO: check whether this should really only be done when
- brush is over mesh? */
- if(sd->draw_pressure && brush_use_alpha_pressure(vc->scene, brush))
- (*visual_strength) *= sd->pressure_value;
-
- if(sd->draw_anchored)
- projected_radius = sd->anchored_size;
- else {
- if(brush->flag & BRUSH_ANCHORED)
- projected_radius = 8;
- else
- projected_radius = brush_size(vc->scene, brush);
- }
- unprojected_radius = paint_calc_object_space_radius(vc, location,
- projected_radius);
-
- if(sd->draw_pressure && brush_use_size_pressure(vc->scene, brush))
- unprojected_radius *= sd->pressure_value;
-
- if(!brush_use_locked_size(vc->scene, brush))
- brush_set_unprojected_radius(vc->scene, brush, unprojected_radius);
-}
-
-static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
-{
- Scene *scene = CTX_data_scene(C);
- Paint *paint = paint_get_active(scene);
- Brush *brush = paint_brush(paint);
- ViewContext vc;
- float final_radius;
- float translation[2];
- float outline_alpha, *outline_col;
-
- /* set various defaults */
- translation[0] = x;
- translation[1] = y;
- outline_alpha = 0.5;
- outline_col = brush->add_col;
- final_radius = brush_size(scene, brush);
-
- /* check that brush drawing is enabled */
- if(!(paint->flags & PAINT_SHOW_BRUSH))
- return;
-
- /* can't use stroke vc here because this will be called during
- mouse over too, not just during a stroke */
- view3d_set_viewcontext(C, &vc);
-
- /* TODO: as sculpt and other paint modes are unified, this
- special mode of drawing will go away */
- if(vc.obact->sculpt) {
- Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
- float location[3];
- int pixel_radius, hit;
- const float root_alpha = brush_alpha(scene, brush);
- float visual_strength = root_alpha*root_alpha;
- const float min_alpha = 0.20f;
- const float max_alpha = 0.80f;
-
- /* this is probably here so that rake takes into
- account the brush movements before the stroke
- starts, but this doesn't really belong in draw code
- (TODO) */
- {
- const float u = 0.5f;
- const float v = 1 - u;
- const float r = 20;
-
- const float dx = sd->last_x - x;
- const float dy = sd->last_y - y;
-
- if(dx*dx + dy*dy >= r*r) {
- sd->last_angle = atan2(dx, dy);
-
- sd->last_x = u*sd->last_x + v*x;
- sd->last_y = u*sd->last_y + v*y;
- }
- }
-
- /* test if brush is over the mesh */
- hit = sculpt_get_brush_geometry(C, x, y, &pixel_radius, location);
-
- /* draw overlay */
- paint_draw_alpha_overlay(sd, brush, &vc, x, y);
-
- if(brush_use_locked_size(scene, brush))
- brush_set_size(scene, brush, pixel_radius);
-
- /* check if brush is subtracting, use different color then */
- /* TODO: no way currently to know state of pen flip or
- invert key modifier without starting a stroke */
- if((!(brush->flag & BRUSH_INVERTED) ^
- !(brush->flag & BRUSH_DIR_IN)) &&
- ELEM5(brush->sculpt_tool, SCULPT_TOOL_DRAW,
- SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY,
- SCULPT_TOOL_PINCH, SCULPT_TOOL_CREASE))
- outline_col = brush->sub_col;
-
- /* only do if brush is over the mesh */
- if(hit)
- paint_cursor_on_hit(sd, brush, &vc, location, &visual_strength);
-
- /* don't show effect of strength past the soft limit */
- if(visual_strength > 1)
- visual_strength = 1;
-
- outline_alpha = ((paint->flags & PAINT_SHOW_BRUSH_ON_SURFACE) ?
- min_alpha + (visual_strength*(max_alpha-min_alpha)) : 0.50f);
-
- if(sd->draw_anchored) {
- final_radius = sd->anchored_size;
- translation[0] = sd->anchored_initial_mouse[0] - vc.ar->winrct.xmin;
- translation[1] = sd->anchored_initial_mouse[1] - vc.ar->winrct.ymin;
- }
- }
-
- /* make lines pretty */
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
-
- /* set brush color */
- glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha);
-
- /* draw brush outline */
- glTranslatef(translation[0], translation[1], 0);
- glutil_draw_lined_arc(0.0, M_PI*2.0, final_radius, 40);
- glTranslatef(-translation[0], -translation[1], 0);
-
- /* restore GL state */
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
-}
-
/* if this is a tablet event, return tablet pressure and set *pen_flip
to 1 if the eraser tool is being used, 0 otherwise */
static float event_tablet_data(wmEvent *event, int *pen_flip)
@@ -705,7 +163,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
/* TODO: can remove the if statement once all modes have this */
if(stroke->get_location)
- stroke->get_location(C, stroke, location, mouse);
+ stroke->get_location(C, location, mouse);
else
zero_v3(location);
@@ -969,12 +427,3 @@ int paint_poll(bContext *C)
CTX_wm_area(C)->spacetype == SPACE_VIEW3D &&
CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW;
}
-
-void paint_cursor_start(bContext *C, int (*poll)(bContext *C))
-{
- Paint *p = paint_get_active(CTX_data_scene(C));
-
- if(p && !p->paint_cursor)
- p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
-}
-
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index fdacc2d15f5..0705ea29985 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -152,7 +152,7 @@ void projectf(bglMats *mats, const float v[3], float p[2])
p[1]= uy;
}
-float paint_calc_object_space_radius(ViewContext *vc, float center[3],
+float paint_calc_object_space_radius(ViewContext *vc, const float center[3],
float pixel_radius)
{
Object *ob = vc->obact;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 27a0bc8f502..ce84e43955b 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3105,7 +3105,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob,
halfway[0] = (float)dx * 0.5f + cache->initial_mouse[0];
halfway[1] = (float)dy * 0.5f + cache->initial_mouse[1];
- if (sculpt_stroke_get_location(C, stroke, out, halfway)) {
+ if (sculpt_stroke_get_location(C, out, halfway)) {
copy_v3_v3(sd->anchored_location, out);
copy_v2_v2(sd->anchored_initial_mouse, halfway);
copy_v2_v2(cache->tex_mouse, halfway);
@@ -3207,23 +3207,29 @@ static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float* tmin)
(This allows us to ignore the GL depth buffer)
Returns 0 if the ray doesn't hit the mesh, non-zero otherwise
*/
-int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2])
+int sculpt_stroke_get_location(bContext *C, float out[3], float mouse[2])
{
- ViewContext *vc = paint_stroke_view_context(stroke);
- Object *ob = vc->obact;
- SculptSession *ss= ob->sculpt;
- StrokeCache *cache= ss->cache;
+ ViewContext vc;
+ Object *ob;
+ SculptSession *ss;
+ StrokeCache *cache;
float ray_start[3], ray_end[3], ray_normal[3], dist;
float obimat[4][4];
float mval[2];
SculptRaycastData srd;
- mval[0] = mouse[0] - vc->ar->winrct.xmin;
- mval[1] = mouse[1] - vc->ar->winrct.ymin;
+ view3d_set_viewcontext(C, &vc);
+
+ ob = vc.obact;
+ ss = ob->sculpt;
+ cache = ss->cache;
sculpt_stroke_modifiers_check(C, ob);
- ED_view3d_win_to_segment_clip(vc->ar, vc->v3d, mval, ray_start, ray_end);
+ mval[0] = mouse[0] - vc.ar->winrct.xmin;
+ mval[1] = mouse[1] - vc.ar->winrct.ymin;
+
+ ED_view3d_win_to_segment_clip(vc.ar, vc.v3d, mval, ray_start, ray_end);
invert_m4_m4(obimat, ob->obmat);
mul_m4_v3(obimat, ray_start);
@@ -3232,7 +3238,7 @@ int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float ou
sub_v3_v3v3(ray_normal, ray_end, ray_start);
dist= normalize_v3(ray_normal);
- srd.ss = vc->obact->sculpt;
+ srd.ss = vc.obact->sculpt;
srd.ray_start = ray_start;
srd.ray_normal = ray_normal;
srd.dist = dist;
@@ -3371,14 +3377,14 @@ static void sculpt_flush_update(bContext *C)
/* Returns whether the mouse/stylus is over the mesh (1)
or over the background (0) */
-static int over_mesh(bContext *C, struct wmOperator *op, float x, float y)
+static int over_mesh(bContext *C, struct wmOperator *UNUSED(op), float x, float y)
{
float mouse[2], co[3];
mouse[0] = x;
mouse[1] = y;
- return sculpt_stroke_get_location(C, op->customdata, co, mouse);
+ return sculpt_stroke_get_location(C, co, mouse);
}
static int sculpt_stroke_test_start(bContext *C, struct wmOperator *op,
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 42205a8da04..275d1d52355 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -73,7 +73,7 @@ void sculpt_stroke_free(struct SculptStroke *);
void sculpt_stroke_add_point(struct SculptStroke *, const short x, const short y);
void sculpt_stroke_apply(struct Sculpt *sd, struct SculptStroke *);
void sculpt_stroke_apply_all(struct Sculpt *sd, struct SculptStroke *);
-int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2]);
+int sculpt_stroke_get_location(bContext *C, float out[3], float mouse[2]);
/* Undo */
diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c
new file mode 100644
index 00000000000..bf8cb58a2f5
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/sculpt_uv.c
@@ -0,0 +1,780 @@
+/*
+ * ***** 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) Blender Foundation, 2002-2009
+ * All rights reserved.
+ *
+ * Contributor(s): Antony Riakiotakis
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ * UV Sculpt tools
+ *
+ */
+
+/** \file blender/editors/sculpt_paint/sculpt_uv.c
+ * \ingroup edsculpt
+ */
+
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_editVert.h"
+#include "BLI_math.h"
+#include "BLI_ghash.h"
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_brush_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_brush.h"
+#include "BKE_paint.h"
+#include "BKE_context.h"
+#include "BKE_main.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mesh.h"
+#include "BKE_customdata.h"
+
+#include "ED_screen.h"
+#include "ED_image.h"
+#include "ED_mesh.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "paint_intern.h"
+#include "uvedit_intern.h"
+
+#include "UI_view2d.h"
+
+#define MARK_BOUNDARY 1
+
+typedef struct UvAdjacencyElement {
+ /* pointer to original uvelement */
+ UvElement *element;
+ /* uv pointer for convenience. Caution, this points to the original UVs! */
+ float *uv;
+ /* general use flag (Used to check if Element is boundary here) */
+ char flag;
+} UvAdjacencyElement;
+
+typedef struct UvEdge {
+ unsigned int uv1;
+ unsigned int uv2;
+ /* general use flag (Used to check if edge is boundary here, and propagates to adjacency elements) */
+ char flag;
+}UvEdge;
+
+typedef struct UVInitialStrokeElement{
+ /* index to unique uv */
+ int uv;
+
+ /* strength of brush on initial position */
+ float strength;
+
+ /* initial uv position */
+ float initial_uv[2];
+}UVInitialStrokeElement;
+
+typedef struct UVInitialStroke{
+ /* Initial Selection,for grab brushes for instance */
+ UVInitialStrokeElement *initialSelection;
+
+ /* total initially selected UVs*/
+ int totalInitialSelected;
+
+ /* initial mouse coordinates */
+ float init_coord[2];
+}UVInitialStroke;
+
+
+/* custom data for uv smoothing brush */
+typedef struct UvSculptData{
+ /* Contains the first of each set of coincident uvs.
+ * These will be used to perform smoothing on and propagate the changes
+ * to their coincident uvs */
+ UvAdjacencyElement *uv;
+
+ /* ...Is what it says */
+ int totalUniqueUvs;
+
+ /* Edges used for adjacency info, used with laplacian smoothing */
+ UvEdge *uvedges;
+
+ /* need I say more? */
+ int totalUvEdges;
+
+ /* data for initial stroke, used by tools like grab */
+ UVInitialStroke *initial_stroke;
+
+ /* timer to be used for airbrush-type brush */
+ wmTimer *timer;
+
+ /* to determine quickly adjacent uvs */
+ UvElementMap *elementMap;
+
+ /* uvsmooth Paint for fast reference */
+ Paint *uvsculpt;
+
+ /* tool to use. duplicating here to change if modifier keys are pressed */
+ char tool;
+
+ /* store invert flag here */
+ char invert;
+}UvSculptData;
+
+/*********** Improved Laplacian Relaxation Operator ************************/
+/* original code by Raul Fernandez Hernandez "farsthary" *
+ * adapted to uv smoothing by Antony Riakiatakis *
+ ***************************************************************************/
+
+typedef struct Temp_UvData{
+ float sum_co[2], p[2], b[2], sum_b[2];
+ int ncounter;
+}Temp_UVData;
+
+
+
+void HC_relaxation_iteration_uv(EditMesh *em, UvSculptData *sculptdata, float mouse_coord[2], float alpha, float radius, float aspectRatio){
+ Temp_UVData *tmp_uvdata;
+ float diff[2];
+ int i;
+ float radius_root = sqrt(radius);
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+
+ tmp_uvdata = (Temp_UVData *)MEM_callocN(sculptdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
+
+ /* counting neighbors */
+ for (i = 0; i < sculptdata->totalUvEdges; i++){
+ UvEdge *tmpedge = sculptdata->uvedges+i;
+ tmp_uvdata[tmpedge->uv1].ncounter++;
+ tmp_uvdata[tmpedge->uv2].ncounter++;
+
+ add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_co, sculptdata->uv[tmpedge->uv1].uv);
+ add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, sculptdata->uv[tmpedge->uv2].uv);
+ }
+
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ copy_v2_v2(diff,tmp_uvdata[i].sum_co);
+ mul_v2_fl(diff,1.f/tmp_uvdata[i].ncounter);
+ copy_v2_v2(tmp_uvdata[i].p,diff);
+
+ tmp_uvdata[i].b[0] = diff[0] - sculptdata->uv[i].uv[0];
+ tmp_uvdata[i].b[1] = diff[1] - sculptdata->uv[i].uv[1];
+ }
+
+ for (i = 0; i < sculptdata->totalUvEdges; i++){
+ UvEdge *tmpedge = sculptdata->uvedges+i;
+ add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_b, tmp_uvdata[tmpedge->uv2].b);
+ add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_b, tmp_uvdata[tmpedge->uv1].b);
+ }
+
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ float dist;
+ /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
+ * If ever uv brushes get their own mode we should check for toolsettings option too */
+ if((sculptdata->uv[i].flag & MARK_BOUNDARY)){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, sculptdata->uv[i].uv, mouse_coord);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ UvElement *element;
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+
+ sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*(tmp_uvdata[i].p[0] - 0.5f*(tmp_uvdata[i].b[0] + tmp_uvdata[i].sum_b[0]/tmp_uvdata[i].ncounter));
+ sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*(tmp_uvdata[i].p[1] - 0.5f*(tmp_uvdata[i].b[1] + tmp_uvdata[i].sum_b[1]/tmp_uvdata[i].ncounter));
+
+ for(element = sculptdata->uv[i].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[i].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
+ }
+ }
+ }
+
+ MEM_freeN(tmp_uvdata);
+
+ return;
+}
+
+static void laplacian_relaxation_iteration_uv(EditMesh *em, UvSculptData *sculptdata, float mouse_coord[2], float alpha, float radius, float aspectRatio)
+{
+ Temp_UVData *tmp_uvdata;
+ float diff[2];
+ int i;
+ float radius_root = sqrt(radius);
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+
+ tmp_uvdata = (Temp_UVData *)MEM_callocN(sculptdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
+
+ /* counting neighbors */
+ for (i = 0; i < sculptdata->totalUvEdges; i++){
+ UvEdge *tmpedge = sculptdata->uvedges+i;
+ tmp_uvdata[tmpedge->uv1].ncounter++;
+ tmp_uvdata[tmpedge->uv2].ncounter++;
+
+ add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_co, sculptdata->uv[tmpedge->uv1].uv);
+ add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, sculptdata->uv[tmpedge->uv2].uv);
+ }
+
+ /* Original Lacplacian algorithm included removal of normal component of translation. here it is not
+ * needed since we translate along the UV plane always.*/
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ copy_v2_v2(tmp_uvdata[i].p, tmp_uvdata[i].sum_co);
+ mul_v2_fl(tmp_uvdata[i].p, 1.f/tmp_uvdata[i].ncounter);
+ }
+
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ float dist;
+ /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
+ * If ever uv brushes get their own mode we should check for toolsettings option too */
+ if((sculptdata->uv[i].flag & MARK_BOUNDARY)){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, sculptdata->uv[i].uv, mouse_coord);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ UvElement *element;
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+
+ sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*tmp_uvdata[i].p[0];
+ sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*tmp_uvdata[i].p[1];
+
+ for(element = sculptdata->uv[i].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[i].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
+ }
+ }
+ }
+
+ MEM_freeN(tmp_uvdata);
+
+ return;
+}
+
+
+static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event, Object *obedit)
+{
+ float co[2], radius, radius_root;
+ Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
+ EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
+ unsigned int tool;
+ UvSculptData *sculptdata = (UvSculptData *)op->customdata;
+ SpaceImage *sima;
+ int invert;
+ int width, height;
+ float aspectRatio;
+ float alpha, zoomx, zoomy;
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+ ToolSettings *toolsettings = CTX_data_tool_settings(C);
+ tool = sculptdata->tool;
+ invert = sculptdata->invert? -1 : 1;
+ alpha = brush_alpha(scene, brush);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
+
+ sima = CTX_wm_space_image(C);
+ ED_space_image_size(sima, &width, &height);
+ ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
+
+ radius = brush_size(scene, brush)/(width*zoomx);
+ aspectRatio = width/(float)height;
+
+ /* We will compare squares to save some computation */
+ radius = radius*radius;
+ radius_root = sqrt(radius);
+
+ /*
+ * Pinch Tool
+ */
+ if(tool == UV_SCULPT_TOOL_PINCH){
+ int i;
+ alpha *= invert;
+ for (i = 0; i < sculptdata->totalUniqueUvs; i++){
+ float dist, diff[2];
+ /* This is supposed to happen only if "Lock Borders" is on, since we have initialization on stroke start
+ * If ever uv brushes get their own mode we should check for toolsettings option too */
+ if(sculptdata->uv[i].flag & MARK_BOUNDARY){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, sculptdata->uv[i].uv, co);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ UvElement *element;
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+ normalize_v2(diff);
+
+ sculptdata->uv[i].uv[0] -= strength*diff[0]*0.001;
+ sculptdata->uv[i].uv[1] -= strength*diff[1]*0.001;
+
+ for(element = sculptdata->uv[i].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[i].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[i].uv);
+ }
+ }
+ }
+ }
+
+ /*
+ * Smooth Tool
+ */
+ else if(tool == UV_SCULPT_TOOL_RELAX){
+ unsigned int method = toolsettings->uv_relax_method;
+ if(method == UV_SCULPT_TOOL_RELAX_HC){
+ HC_relaxation_iteration_uv(em, sculptdata, co, alpha, radius, aspectRatio);
+ }else{
+ laplacian_relaxation_iteration_uv(em, sculptdata, co, alpha, radius, aspectRatio);
+ }
+ }
+
+ /*
+ * Grab Tool
+ */
+ else if(tool == UV_SCULPT_TOOL_GRAB){
+ int i;
+ float diff[2];
+ sub_v2_v2v2(diff, co, sculptdata->initial_stroke->init_coord);
+
+ for(i = 0; i < sculptdata->initial_stroke->totalInitialSelected; i++ ){
+ UvElement *element;
+ int uvindex = sculptdata->initial_stroke->initialSelection[i].uv;
+ float strength = sculptdata->initial_stroke->initialSelection[i].strength;
+ sculptdata->uv[uvindex].uv[0] = sculptdata->initial_stroke->initialSelection[i].initial_uv[0] + strength*diff[0];
+ sculptdata->uv[uvindex].uv[1] = sculptdata->initial_stroke->initialSelection[i].initial_uv[1] + strength*diff[1];
+
+ for(element = sculptdata->uv[uvindex].element; element; element = element->next){
+ MTFace *mt;
+ if(element->separate && element != sculptdata->uv[uvindex].element)
+ break;
+ mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+ copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[uvindex].uv);
+ }
+ }
+ }
+
+ BKE_mesh_end_editmesh(obedit->data, em);
+}
+
+
+static void uv_sculpt_stroke_exit(bContext *C, wmOperator *op)
+{
+ UvSculptData *data = op->customdata;
+ if(data->timer){
+ WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), data->timer);
+ }
+ if(data->elementMap)
+ {
+ EM_free_uv_element_map(data->elementMap);
+ }
+ if(data->uv){
+ MEM_freeN(data->uv);
+ }
+ if(data->uvedges){
+ MEM_freeN(data->uvedges);
+ }
+ if(data->initial_stroke){
+ if(data->initial_stroke->initialSelection){
+ MEM_freeN(data->initial_stroke->initialSelection);
+ }
+ MEM_freeN(data->initial_stroke);
+ }
+
+ MEM_freeN(data);
+ op->customdata = NULL;
+}
+
+static int get_uv_element_offset_from_face(UvElementMap *map, EditFace *efa, int index, int island_index, int doIslands){
+ UvElement *element = ED_get_uv_element(map, efa, index);
+ if(!element || (doIslands && element->island != island_index)){
+ return -1;
+ }
+ return element - map->buf;
+}
+
+
+static unsigned int uv_edge_hash(const void *key){
+ UvEdge *edge = (UvEdge *)key;
+ return
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) +
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1));
+}
+
+static int uv_edge_compare(const void *a, const void *b){
+ UvEdge *edge1 = (UvEdge *)a;
+ UvEdge *edge2 = (UvEdge *)b;
+
+ if((edge1->uv1 == edge2->uv1) && (edge1->uv2 == edge2->uv2)){
+ return 0;
+ }
+ return 1;
+}
+
+
+static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent *event)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *obedit = CTX_data_edit_object(C);
+ ToolSettings *ts = scene->toolsettings;
+ UvSculptData *data = MEM_callocN(sizeof(*data), "UV Smooth Brush Data");
+ EditMesh *em = BKE_mesh_get_editmesh(obedit->data);
+
+ op->customdata = data;
+
+ if(data){
+ int counter = 0, i;
+ ARegion *ar= CTX_wm_region(C);
+ float co[2];
+ EditFace *efa;
+ UvEdge *edges;
+ GHash *edgeHash;
+ GHashIterator* ghi;
+ MTFace *mt;
+ int do_island_optimization = !(ts->uv_sculpt_settings & UV_SCULPT_ALL_ISLANDS);
+ int island_index = 0;
+ /* Holds, for each UvElement in elementMap, a pointer to its unique uv.*/
+ int *uniqueUv;
+ data->tool = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_SMOOTH)? UV_SCULPT_TOOL_RELAX : ts->uv_sculpt_tool;
+ data->invert = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT)? 1 : 0;
+
+ data->uvsculpt = &ts->uvsculpt->paint;
+
+ if(do_island_optimization){
+ /* We will need island information */
+ if(ts->uv_flag & UV_SYNC_SELECTION){
+ data->elementMap = EM_make_uv_element_map(em, 0, 1);
+ }else{
+ data->elementMap = EM_make_uv_element_map(em, 1, 1);
+ }
+ }else {
+ if(ts->uv_flag & UV_SYNC_SELECTION){
+ data->elementMap = EM_make_uv_element_map(em, 0, 0);
+ }else{
+ data->elementMap = EM_make_uv_element_map(em, 1, 0);
+ }
+ }
+
+ if(!data->elementMap){
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+
+ /* Mouse coordinates, useful for some functions like grab and sculpt all islands */
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
+
+ /* we need to find the active island here */
+ if(do_island_optimization){
+ UvElement *element;
+ NearestHit hit;
+ Image *ima= CTX_data_edit_image(C);
+ uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
+
+ element = ED_get_uv_element(data->elementMap, hit.efa, hit.uv);
+ island_index = element->island;
+ }
+
+
+ /* Count 'unique' uvs */
+ for(i = 0; i < data->elementMap->totalUVs; i++){
+ if(data->elementMap->buf[i].separate
+ && (!do_island_optimization || data->elementMap->buf[i].island == island_index)){
+ counter++;
+ }
+ }
+
+ /* Allocate the unique uv buffers */
+ data->uv = MEM_mallocN(sizeof(*data->uv)*counter, "uv_brush_unique_uvs");
+ uniqueUv = MEM_mallocN(sizeof(*uniqueUv)*data->elementMap->totalUVs, "uv_brush_unique_uv_map");
+ edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "uv_brush_edge_hash");
+ /* we have at most totalUVs edges */
+ edges = MEM_mallocN(sizeof(*edges)*data->elementMap->totalUVs, "uv_brush_all_edges");
+ if(!data->uv || !uniqueUv || !edgeHash || !edges){
+ if(edges){
+ MEM_freeN(edges);
+ }
+ if(uniqueUv){
+ MEM_freeN(uniqueUv);
+ }
+ if(edgeHash){
+ MEM_freeN(edgeHash);
+ }
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+
+ data->totalUniqueUvs = counter;
+ /* So that we can use this as index for the UvElements */
+ counter = -1;
+ /* initialize the unique UVs */
+ for(i = 0; i < em->totvert; i++){
+ UvElement *element = data->elementMap->vert[i];
+ for(; element; element = element->next){
+ if(element->separate){
+ if(do_island_optimization && (element->island != island_index)){
+ /* skip this uv if not on the active island */
+ for(; element->next && !(element->next->separate); element = element->next)
+ ;
+ continue;
+ }
+ efa = element->face;
+ mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+
+ counter++;
+ data->uv[counter].element = element;
+ data->uv[counter].flag = 0;
+ data->uv[counter].uv = mt->uv[element->tfindex];
+ }
+ /* pointer arithmetic to the rescue, as always :)*/
+ uniqueUv[element - data->elementMap->buf] = counter;
+ }
+ }
+
+ /* Now, on to generate our uv connectivity data */
+ for(efa = em->faces.first, counter = 0; efa; efa = efa->next){
+ int nverts = efa->v4 ? 4 : 3;
+ for(i = 0; i < nverts; i++){
+ int offset1, itmp1 = get_uv_element_offset_from_face(data->elementMap, efa, i, island_index, do_island_optimization);
+ int offset2, itmp2 = get_uv_element_offset_from_face(data->elementMap, efa, (i+1)%nverts, island_index, do_island_optimization);
+
+ /* Skip edge if not found(unlikely) or not on valid island */
+ if(itmp1 == -1 || itmp2 == -1)
+ continue;
+
+ offset1 = uniqueUv[itmp1];
+ offset2 = uniqueUv[itmp2];
+
+ edges[counter].flag = 0;
+ /* using an order policy, sort uvs according to address space. This avoids
+ * Having two different UvEdges with the same uvs on different positions */
+ if(offset1 < offset2){
+ edges[counter].uv1 = offset1;
+ edges[counter].uv2 = offset2;
+ }
+ else{
+ edges[counter].uv1 = offset2;
+ edges[counter].uv2 = offset1;
+ }
+ /* Hack! Set the value of the key to its flag. Now we can set the flag when an edge exists twice :) */
+ if(BLI_ghash_haskey(edgeHash, &edges[counter])){
+ char *flag = BLI_ghash_lookup(edgeHash, &edges[counter]);
+ *flag = 1;
+ }
+ else{
+ /* Hack mentioned */
+ BLI_ghash_insert(edgeHash, &edges[counter], &edges[counter].flag);
+ }
+ counter++;
+ }
+ }
+ MEM_freeN(uniqueUv);
+
+ /* Allocate connectivity data, we allocate edges once */
+ data->uvedges = MEM_mallocN(sizeof(*data->uvedges)*BLI_ghash_size(edgeHash), "uv_brush_edge_connectivity_data");
+ if(!data->uvedges){
+ BLI_ghash_free(edgeHash, NULL, NULL);
+ MEM_freeN(edges);
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+ ghi = BLI_ghashIterator_new(edgeHash);
+ if(!ghi){
+ BLI_ghash_free(edgeHash, NULL, NULL);
+ MEM_freeN(edges);
+ uv_sculpt_stroke_exit(C, op);
+ return NULL;
+ }
+ /* fill the edges with data */
+ for(i = 0; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)){
+ data->uvedges[i++] = *((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ }
+ data->totalUvEdges = BLI_ghash_size(edgeHash);
+
+ /* cleanup temporary stuff */
+ BLI_ghashIterator_free(ghi);
+ BLI_ghash_free(edgeHash, NULL, NULL);
+ MEM_freeN(edges);
+
+ /* transfer boundary edge property to uvs */
+ if(ts->uv_sculpt_settings & UV_SCULPT_LOCK_BORDERS){
+ for(i = 0; i < data->totalUvEdges; i++){
+ if(!data->uvedges[i].flag){
+ data->uv[data->uvedges[i].uv1].flag |= MARK_BOUNDARY;
+ data->uv[data->uvedges[i].uv2].flag |= MARK_BOUNDARY;
+ }
+ }
+ }
+
+ /* Allocate initial selection for grab tool */
+ if(data->tool){
+ float radius, radius_root;
+ UvSculptData *sculptdata = (UvSculptData *)op->customdata;
+ SpaceImage *sima;
+ int width, height;
+ float aspectRatio;
+ float alpha, zoomx, zoomy;
+ Brush *brush = paint_brush(sculptdata->uvsculpt);
+
+ alpha = brush_alpha(scene, brush);
+
+ radius = brush_size(scene, brush);
+ sima = CTX_wm_space_image(C);
+ ED_space_image_size(sima, &width, &height);
+ ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
+
+ aspectRatio = width/(float)height;
+ radius /= (width*zoomx);
+ radius = radius*radius;
+ radius_root = sqrt(radius);
+
+ /* Allocate selection stack */
+ data->initial_stroke = MEM_mallocN(sizeof(*data->initial_stroke), "uv_sculpt_initial_stroke");
+ if(!data->initial_stroke){
+ uv_sculpt_stroke_exit(C, op);
+ }
+ data->initial_stroke->initialSelection = MEM_mallocN(sizeof(*data->initial_stroke->initialSelection)*data->totalUniqueUvs, "uv_sculpt_initial_selection");
+ if(!data->initial_stroke->initialSelection){
+ uv_sculpt_stroke_exit(C, op);
+ }
+
+ copy_v2_v2(data->initial_stroke->init_coord, co);
+
+ counter = 0;
+
+ for(i = 0; i < data->totalUniqueUvs; i++){
+ float dist, diff[2];
+ if(data->uv[i].flag & MARK_BOUNDARY){
+ continue;
+ }
+
+ sub_v2_v2v2(diff, data->uv[i].uv, co);
+ diff[1] /= aspectRatio;
+ if((dist = dot_v2v2(diff, diff)) <= radius){
+ float strength;
+ strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+
+ data->initial_stroke->initialSelection[counter].uv = i;
+ data->initial_stroke->initialSelection[counter].strength = strength;
+ copy_v2_v2(data->initial_stroke->initialSelection[counter].initial_uv, data->uv[i].uv);
+ counter++;
+ }
+ }
+
+ data->initial_stroke->totalInitialSelected = counter;
+ }
+ }
+
+ return op->customdata;
+}
+
+static int uv_sculpt_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ UvSculptData *data;
+ Object *obedit = CTX_data_edit_object(C);
+
+ if(!(data = uv_sculpt_stroke_init(C, op, event))) {
+ return OPERATOR_CANCELLED;
+ }
+
+ uv_sculpt_stroke_apply(C, op, event, obedit);
+
+ data->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.001f);
+
+ if(!data->timer){
+ uv_sculpt_stroke_exit(C, op);
+ return OPERATOR_CANCELLED;
+ }
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+
+static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ UvSculptData *data = (UvSculptData *)op->customdata;
+ Object *obedit = CTX_data_edit_object(C);
+
+ switch(event->type) {
+ case LEFTMOUSE:
+ case MIDDLEMOUSE:
+ case RIGHTMOUSE:
+ uv_sculpt_stroke_exit(C, op);
+ return OPERATOR_FINISHED;
+
+ case MOUSEMOVE:
+ case INBETWEEN_MOUSEMOVE:
+ uv_sculpt_stroke_apply(C, op, event, obedit);
+ break;
+ case TIMER:
+ if(event->customdata == data->timer)
+ uv_sculpt_stroke_apply(C, op, event, obedit);
+ break;
+ default:
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ ED_region_tag_redraw(CTX_wm_region(C));
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ DAG_id_tag_update(obedit->data, 0);
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void SCULPT_OT_uv_sculpt_stroke(wmOperatorType *ot)
+{
+ static EnumPropertyItem stroke_mode_items[] = {
+ {BRUSH_STROKE_NORMAL, "NORMAL", 0, "Normal", "Apply brush normally"},
+ {BRUSH_STROKE_INVERT, "INVERT", 0, "Invert", "Invert action of brush for duration of stroke"},
+ {BRUSH_STROKE_SMOOTH, "RELAX", 0, "Relax", "Switch brush to relax mode for duration of stroke"},
+ {0}
+ };
+
+ /* identifiers */
+ ot->name = "Sculpt UVs";
+ ot->description = "Sculpt UVs using a brush";
+ ot->idname = "SCULPT_OT_uv_sculpt_stroke";
+
+ /* api callbacks */
+ ot->invoke = uv_sculpt_stroke_invoke;
+ ot->modal = uv_sculpt_stroke_modal;
+ ot->poll = uv_sculpt_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* props */
+ RNA_def_enum(ot->srna, "mode", stroke_mode_items, BRUSH_STROKE_NORMAL, "Mode", "Stroke Mode");
+}
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index 4c028612320..57981431492 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -1061,7 +1061,6 @@ ID *buttons_context_id_path(const bContext *C)
if(ptr->id.data) {
return ptr->id.data;
- break;
}
}
}
diff --git a/source/blender/editors/space_clip/clip_graph_draw.c b/source/blender/editors/space_clip/clip_graph_draw.c
index 9aba6db0c80..e913ae77f05 100644
--- a/source/blender/editors/space_clip/clip_graph_draw.c
+++ b/source/blender/editors/space_clip/clip_graph_draw.c
@@ -155,15 +155,16 @@ void tracking_segment_end_cb(void *UNUSED(userdata))
}
static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
- MovieTrackingMarker *marker, int UNUSED(coord), float val)
+ MovieTrackingMarker *marker, int coord, float val)
{
struct { MovieTrackingTrack *act_track; int sel; float xscale, yscale, hsize; } *data = userdata;
- int sel= 0;
+ int sel= 0, sel_flag;
if(track!=data->act_track)
return;
- sel= (marker->flag&MARKER_GRAPH_SEL) ? 1 : 0;
+ sel_flag= coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y;
+ sel= (marker->flag & sel_flag) ? 1 : 0;
if(sel == data->sel) {
if(sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c
index 08d6bcf47bc..8be5e520b1f 100644
--- a/source/blender/editors/space_clip/clip_graph_ops.c
+++ b/source/blender/editors/space_clip/clip_graph_ops.c
@@ -68,13 +68,13 @@ static void toggle_selection_cb(void *userdata, MovieTrackingMarker *marker)
switch(data->action) {
case SEL_SELECT:
- marker->flag|= MARKER_GRAPH_SEL;
+ marker->flag|= (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
break;
case SEL_DESELECT:
- marker->flag&= ~MARKER_GRAPH_SEL;
+ marker->flag&= ~(MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
break;
case SEL_INVERT:
- marker->flag^= MARKER_GRAPH_SEL;
+ marker->flag^= (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
break;
}
}
@@ -177,7 +177,10 @@ static int mouse_select_knot(bContext *C, float co[2], int extend)
clip_graph_tracking_iterate(sc, &selectdata, toggle_selection_cb);
}
- userdata.marker->flag|= MARKER_GRAPH_SEL;
+ if(userdata.coord==0)
+ userdata.marker->flag|= MARKER_GRAPH_SEL_X;
+ else
+ userdata.marker->flag|= MARKER_GRAPH_SEL_Y;
return 1;
}
@@ -335,7 +338,7 @@ static int delete_knot_exec(bContext *C, wmOperator *UNUSED(op))
while(a<act_track->markersnr) {
MovieTrackingMarker *marker= &act_track->markers[a];
- if(marker->flag&MARKER_GRAPH_SEL)
+ if(marker->flag & (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y))
clip_delete_marker(C, clip, tracksbase, act_track, marker);
else
a++;
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 45c7043c44c..06dd96603ef 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -999,5 +999,5 @@ void ED_operatormacros_clip(void)
ot->description = "Add new marker and slide it with mouse until mouse button release";
WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
- RNA_boolean_set(otmacro->ptr, "release_confirm", 1);
+ RNA_boolean_set(otmacro->ptr, "release_confirm", TRUE);
}
diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c
index 3ca8fc35c7f..46442d39a7b 100644
--- a/source/blender/editors/space_clip/clip_utils.c
+++ b/source/blender/editors/space_clip/clip_utils.c
@@ -95,7 +95,7 @@ void clip_graph_tracking_values_iterate_track(SpaceClip *sc, MovieTrackingTrack
}
/* value is a pixels per frame speed */
- val= (marker->pos[coord] - prevval) * ((i==0) ? (width) : (height));
+ val= (marker->pos[coord] - prevval) * ((coord==0) ? (width) : (height));
val/= marker->framenr-prevfra;
if(func)
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 82da9b3b956..04871156412 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -399,22 +399,24 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
/* 2d tracking */
kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "backwards", 1);
+ RNA_boolean_set(kmi->ptr, "backwards", TRUE);
+ RNA_boolean_set(kmi->ptr, "sequence", FALSE);
WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "sequence", 1);
+ RNA_boolean_set(kmi->ptr, "backwards", FALSE);
+ RNA_boolean_set(kmi->ptr, "sequence", TRUE);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "backwards", 1);
- RNA_boolean_set(kmi->ptr, "sequence", 1);
+ RNA_boolean_set(kmi->ptr, "backwards", TRUE);
+ RNA_boolean_set(kmi->ptr, "sequence", TRUE);
/* mode */
kmi= WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "mode", SC_MODE_RECONSTRUCTION);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_mode_set", TABKEY, KM_PRESS, KM_CTRL, 0);
RNA_enum_set(kmi->ptr, "mode", SC_MODE_DISTORTION);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
/* ******** Hotkeys avalaible for main region only ******** */
@@ -461,10 +463,14 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CLIP_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
/* selection */
- WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
- WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", AKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
WM_keymap_add_item(keymap, "CLIP_OT_select_border", BKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0);
WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
@@ -490,10 +496,11 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
kmi= WM_keymap_add_item(keymap, "CLIP_OT_lock_tracks", LKEY, KM_PRESS, KM_ALT, 0);
RNA_enum_set(kmi->ptr, "action", 1); /* unlock */
- WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
+ kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
kmi= WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks", HKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "unselected", 1);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0);
@@ -527,8 +534,10 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CLIP_OT_change_frame", ACTIONMOUSE, KM_PRESS, 0, 0);
/* selection */
- WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "CLIP_OT_graph_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
/* delete */
WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_curve", DELKEY, KM_PRESS, 0, 0);
@@ -536,6 +545,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", DELKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", XKEY, KM_PRESS, KM_SHIFT, 0);
+
+ transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
}
const char *clip_context_dir[]= {"edit_movieclip", NULL};
diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c
index b67fac69745..6cf8a988571 100644
--- a/source/blender/editors/space_clip/tracking_ops.c
+++ b/source/blender/editors/space_clip/tracking_ops.c
@@ -2520,9 +2520,8 @@ static int set_scale_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
SpaceClip *sc= CTX_wm_space_clip(C);
MovieClip *clip= ED_space_clip(sc);
- float dist= RNA_float_get(op->ptr, "distance");
- if(dist==0.0f)
+ if(!RNA_struct_property_is_set(op->ptr, "distance"))
RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist);
return set_scale_exec(C, op);
@@ -2573,9 +2572,8 @@ static int set_solution_scale_invoke(bContext *C, wmOperator *op, wmEvent *UNUSE
{
SpaceClip *sc= CTX_wm_space_clip(C);
MovieClip *clip= ED_space_clip(sc);
- float dist= RNA_float_get(op->ptr, "distance");
- if(dist==0.0f)
+ if(!RNA_struct_property_is_set(op->ptr, "distance"))
RNA_float_set(op->ptr, "distance", clip->tracking.settings.object_distance);
return set_solution_scale_exec(C, op);
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index c713317aa7e..3df8e98be3a 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -276,24 +276,25 @@ static void console_keymap(struct wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
- RNA_boolean_set(WM_keymap_add_item(keymap, "CONSOLE_OT_history_cycle", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "reverse", 1);
+ kmi = WM_keymap_add_item(keymap, "CONSOLE_OT_history_cycle", UPARROWKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
WM_keymap_add_item(keymap, "CONSOLE_OT_history_cycle", DOWNARROWKEY, KM_PRESS, 0, 0);
/*
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index dee8db88d49..23250fc6696 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -586,7 +586,7 @@ const char * filelist_dir(struct FileList* filelist)
void filelist_setdir(struct FileList* filelist, const char *dir)
{
- BLI_strncpy(filelist->dir, dir, FILE_MAX);
+ BLI_strncpy(filelist->dir, dir, sizeof(filelist->dir));
}
void filelist_imgsize(struct FileList* filelist, short w, short h)
@@ -853,10 +853,9 @@ static void filelist_read_library(struct FileList* filelist)
for(num=0; num<filelist->numfiles; num++, file++) {
if(BLO_has_bfile_extension(file->relname)) {
char name[FILE_MAX];
-
- BLI_strncpy(name, filelist->dir, sizeof(name));
- strcat(name, file->relname);
-
+
+ BLI_join_dirfile(name, sizeof(name), filelist->dir, file->relname);
+
/* prevent current file being used as acceptable dir */
if (BLI_path_cmp(G.main->name, name) != 0) {
file->type &= ~S_IFMT;
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 7bc71e333ea..02c9728348e 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -410,13 +410,13 @@ static void file_keymap(struct wmKeyConfig *keyconf)
/* keys for main area */
keymap= WM_keymap_find(keyconf, "File Browser Main", SPACE_FILE, 0);
kmi= WM_keymap_add_item(keymap, "FILE_OT_execute", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
- RNA_boolean_set(kmi->ptr, "need_active", 1);
+ RNA_boolean_set(kmi->ptr, "need_active", TRUE);
WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, 0, 0);
kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "fill", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "fill", TRUE);
WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FILE_OT_refresh", PADPERIOD, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c
index aa245585d11..aba58098563 100644
--- a/source/blender/editors/space_graph/graph_ops.c
+++ b/source/blender/editors/space_graph/graph_ops.c
@@ -383,7 +383,8 @@ static void graphedit_keymap_keyframes (wmKeyConfig *keyconf, wmKeyMap *keymap)
WM_keymap_add_item(keymap, "GRAPH_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
/* F-Modifiers */
- RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "only_active", 0);
+ kmi = WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "only_active", FALSE);
/* animation module */
/* channels list
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 41fc861f8e4..9ec9c5ef0e0 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -111,7 +111,8 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar)
}
/* used by node view too */
-void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf)
+void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int y,
+ const unsigned char cp[4], const float fp[4], int *zp, float *zpf)
{
char str[256];
float dx= 6;
@@ -211,39 +212,46 @@ void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int
/* color rectangle */
if (channels==1) {
- if (fp)
+ if (fp) {
col[0] = col[1] = col[2] = fp[0];
- else if (cp)
+ }
+ else if (cp) {
col[0] = col[1] = col[2] = (float)cp[0]/255.0f;
- else
+ }
+ else {
col[0] = col[1] = col[2] = 0.0f;
+ }
+ col[3] = 1.0f;
}
else if (channels==3) {
- if (fp)
+ if (fp) {
copy_v3_v3(col, fp);
+ }
else if (cp) {
- col[0] = (float)cp[0]/255.0f;
- col[1] = (float)cp[1]/255.0f;
- col[2] = (float)cp[2]/255.0f;
+ rgb_uchar_to_float(col, cp);
}
- else
+ else {
zero_v3(col);
+ }
+ col[3] = 1.0f;
}
else if (channels==4) {
if (fp)
copy_v4_v4(col, fp);
else if (cp) {
- col[0] = (float)cp[0]/255.0f;
- col[1] = (float)cp[1]/255.0f;
- col[2] = (float)cp[2]/255.0f;
- col[3] = (float)cp[3]/255.0f;
+ rgba_uchar_to_float(col, cp);
}
- else
+ else {
zero_v4(col);
+ }
}
+ else {
+ BLI_assert(0);
+ zero_v4(col);
+ }
+
if (color_manage) {
- linearrgb_to_srgb_v3_v3(finalcol, col);
- finalcol[3] = col[3];
+ linearrgb_to_srgb_v4(finalcol, col);
}
else {
copy_v4_v4(finalcol, col);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 06674513868..1ac5ba56145 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -178,6 +178,30 @@ int space_image_main_area_poll(bContext *C)
return 0;
}
+/* For IMAGE_OT_curves_point_set to avoid sampling when in uv smooth mode */
+int space_image_main_area_not_uv_brush_poll(bContext *C)
+{
+ SpaceImage *sima= CTX_wm_space_image(C);
+
+ ToolSettings *toolsettings = CTX_data_scene(C)->toolsettings;
+ if(sima && !toolsettings->uvsculpt)
+ return 1;
+
+ return 0;
+}
+
+static int space_image_image_sample_poll(bContext *C)
+{
+ SpaceImage *sima= CTX_wm_space_image(C);
+ Object *obedit= CTX_data_edit_object(C);
+ ToolSettings *toolsettings = CTX_data_scene(C)->toolsettings;
+
+ if(obedit){
+ if(ED_space_image_show_uvedit(sima, obedit) && (toolsettings->use_uv_sculpt))
+ return 0;
+ }
+ return space_image_main_area_poll(C);
+}
/********************** view pan operator *********************/
typedef struct ViewPanData {
@@ -858,7 +882,9 @@ static int image_replace_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
RNA_string_get(op->ptr, "filepath", str);
- BLI_strncpy(sima->image->name, str, sizeof(sima->image->name)); /* we cant do much if the str is longer then 240 :/ */
+
+ /* we cant do much if the str is longer then FILE_MAX :/ */
+ BLI_strncpy(sima->image->name, str, sizeof(sima->image->name));
/* XXX unpackImage frees image buffers */
ED_preview_kill_jobs(C);
@@ -1754,12 +1780,12 @@ typedef struct ImageSampleInfo {
int x, y;
int channels;
- char col[4];
+ unsigned char col[4];
float colf[4];
int z;
float zf;
- char *colp;
+ unsigned char *colp;
float *colfp;
int *zp;
float *zfp;
@@ -1794,7 +1820,7 @@ static void image_sample_apply(bContext *C, wmOperator *op, wmEvent *event)
if(fx>=0.0f && fy>=0.0f && fx<1.0f && fy<1.0f) {
float *fp;
- char *cp;
+ unsigned char *cp;
int x= (int)(fx*ibuf->x), y= (int)(fy*ibuf->y);
CLAMP(x, 0, ibuf->x-1);
@@ -1811,7 +1837,7 @@ static void image_sample_apply(bContext *C, wmOperator *op, wmEvent *event)
info->zfp= NULL;
if(ibuf->rect) {
- cp= (char *)(ibuf->rect + y*ibuf->x + x);
+ cp= (unsigned char *)(ibuf->rect + y*ibuf->x + x);
info->col[0]= cp[0];
info->col[1]= cp[1];
@@ -1947,7 +1973,7 @@ void IMAGE_OT_sample(wmOperatorType *ot)
ot->invoke= image_sample_invoke;
ot->modal= image_sample_modal;
ot->cancel= image_sample_cancel;
- ot->poll= space_image_main_area_poll;
+ ot->poll= space_image_image_sample_poll;
/* flags */
ot->flag= OPTYPE_BLOCKING;
@@ -2084,7 +2110,7 @@ void IMAGE_OT_curves_point_set(wmOperatorType *ot)
ot->invoke= image_sample_invoke;
ot->modal= image_sample_modal;
ot->cancel= image_sample_cancel;
- ot->poll= space_image_main_area_poll;
+ ot->poll= space_image_main_area_not_uv_brush_poll;
/* properties */
RNA_def_enum(ot->srna, "point", point_items, 0, "Point", "Set black point or white point for curves");
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 4421ad8e4f9..fd7895052f1 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -543,7 +543,7 @@ static void image_keymap(struct wmKeyConfig *keyconf)
/* toggle editmode is handy to have while UV unwrapping */
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
- RNA_boolean_set(kmi->ptr, "toggle", 1);
+ RNA_boolean_set(kmi->ptr, "toggle", TRUE);
}
/* dropboxes */
@@ -773,6 +773,9 @@ static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
keymap= WM_keymap_find(wm->defaultconf, "UV Editor", 0, 0);
WM_event_add_keymap_handler(&ar->handlers, keymap);
+ keymap= WM_keymap_find(wm->defaultconf, "UV Sculpt", 0, 0);
+ WM_event_add_keymap_handler(&ar->handlers, keymap);
+
/* own keymaps */
keymap= WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
WM_event_add_keymap_handler(&ar->handlers, keymap);
@@ -785,6 +788,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
SpaceImage *sima= CTX_wm_space_image(C);
+ Object *obact= CTX_data_active_object(C);
Object *obedit= CTX_data_edit_object(C);
Scene *scene= CTX_data_scene(C);
View2D *v2d= &ar->v2d;
@@ -810,7 +814,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
/* and uvs in 0.0-1.0 space */
UI_view2d_view_ortho(v2d);
- draw_uvedit_main(sima, ar, scene, obedit);
+ draw_uvedit_main(sima, ar, scene, obedit, obact);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c
index 2090b4eae0a..87f9a5d65aa 100644
--- a/source/blender/editors/space_info/info_ops.c
+++ b/source/blender/editors/space_info/info_ops.c
@@ -124,7 +124,7 @@ static const EnumPropertyItem unpack_all_method_items[] = {
{PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use files in original location (create when necessary)", ""},
{PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write files to original location (overwrite existing files)", ""},
{PF_KEEP, "KEEP", 0, "Disable AutoPack, keep all packed files", ""},
- {PF_ASK, "ASK", 0, "Ask for each file", ""},
+ /* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */
{0, NULL, 0, NULL, NULL}};
static int unpack_all_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c
index f173a3d3835..55831de876c 100644
--- a/source/blender/editors/space_nla/nla_ops.c
+++ b/source/blender/editors/space_nla/nla_ops.c
@@ -169,17 +169,23 @@ void nla_operatortypes(void)
static void nla_keymap_channels(wmKeyMap *keymap)
{
+ wmKeyMapItem *kmi;
+
/* NLA-specific (different to standard channels keymap) -------------------------- */
/* selection */
/* click-select */
// XXX for now, only leftmouse....
- WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
/* channel operations */
/* add tracks */
- WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "above_selected", 1);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "above_selected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "above_selected", TRUE);
/* delete tracks */
WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", XKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index 5beac4ea212..3301f89ab7a 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -1334,7 +1334,7 @@ typedef struct ImageSampleInfo {
int channels;
int color_manage;
- char col[4];
+ unsigned char col[4];
float colf[4];
int draw;
diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c
index b71776f4266..508021540b5 100644
--- a/source/blender/editors/space_node/node_ops.c
+++ b/source/blender/editors/space_node/node_ops.c
@@ -114,8 +114,10 @@ void ED_operatormacros_node(void)
/* modified operator call for duplicating with input links */
ot= WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
ot->description = "Duplicate selected nodes keeping input links and move them";
+
mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
- RNA_boolean_set(mot->ptr, "keep_inputs", 1);
+ RNA_boolean_set(mot->ptr, "keep_inputs", TRUE);
+
WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
ot= WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer", OPTYPE_UNDO);
@@ -144,11 +146,12 @@ void node_keymap(struct wmKeyConfig *keyconf)
RNA_boolean_set(kmi->ptr, "extend", FALSE);
kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "extend", FALSE);
- kmi= WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
RNA_boolean_set(kmi->ptr, "extend", TRUE);
- kmi= WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
RNA_boolean_set(kmi->ptr, "extend", TRUE);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0)->ptr, "tweak", 1);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_boolean_set(kmi->ptr, "tweak", TRUE);
/* each of these falls through if not handled... */
WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
@@ -163,10 +166,12 @@ void node_keymap(struct wmKeyConfig *keyconf)
kmi= WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
RNA_float_set(kmi->ptr, "factor", 1.2f);
WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0);
-
- WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "replace", 1);
-
+
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "replace", FALSE);
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "replace", TRUE);
+
WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
/* modified operator call for duplicating with input links */
@@ -180,7 +185,10 @@ void node_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
+
+ kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "tweak", FALSE);
+
WM_keymap_add_item(keymap, "NODE_OT_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_delete", DELKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_delete_reconnect", XKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c
index a733d45c20b..8d82dd3fb53 100644
--- a/source/blender/editors/space_node/node_templates.c
+++ b/source/blender/editors/space_node/node_templates.c
@@ -49,6 +49,8 @@
#include "RNA_access.h"
+#include "NOD_socket.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -205,12 +207,9 @@ static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_t
nodeRemLink(ntree, link);
}
- if(sock_prev->default_value) {
- if(sock_from->default_value)
- MEM_freeN(sock_from->default_value);
-
- sock_from->default_value = MEM_dupallocN(sock_prev->default_value);
- }
+ node_socket_free_default_value(sock_from->type, sock_from->default_value);
+ sock_from->default_value = node_socket_make_default_value(sock_from->type);
+ node_socket_copy_default_value(sock_from->type, sock_from->default_value, sock_prev->default_value);
}
}
}
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 4065b3e2e0b..3b6b4334880 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -198,6 +198,8 @@ void OUTLINER_OT_show_one_level(struct wmOperatorType *ot);
void OUTLINER_OT_show_active(struct wmOperatorType *ot);
void OUTLINER_OT_show_hierarchy(struct wmOperatorType *ot);
+void OUTLINER_OT_select_border(struct wmOperatorType *ot);
+
void OUTLINER_OT_selected_toggle(struct wmOperatorType *ot);
void OUTLINER_OT_expanded_toggle(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c
index 0d3f2e85414..0de26cece93 100644
--- a/source/blender/editors/space_outliner/outliner_ops.c
+++ b/source/blender/editors/space_outliner/outliner_ops.c
@@ -38,6 +38,7 @@
#include "RNA_access.h"
+#include "BLI_utildefines.h"
#include "outliner_intern.h"
@@ -48,6 +49,7 @@
void outliner_operatortypes(void)
{
WM_operatortype_append(OUTLINER_OT_item_activate);
+ WM_operatortype_append(OUTLINER_OT_select_border);
WM_operatortype_append(OUTLINER_OT_item_openclose);
WM_operatortype_append(OUTLINER_OT_item_rename);
WM_operatortype_append(OUTLINER_OT_operation);
@@ -80,14 +82,21 @@ void outliner_operatortypes(void)
void outliner_keymap(wmKeyConfig *keyconf)
{
wmKeyMap *keymap= WM_keymap_find(keyconf, "Outliner", SPACE_OUTLINER, 0);
+ wmKeyMapItem *kmi;
WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
+
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+
+ WM_keymap_add_item(keymap, "OUTLINER_OT_select_border", BKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, 0, 0)->ptr, "extend", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0)->ptr, "extend", 1);
-
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, 0, 0)->ptr, "all", 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "all", 1);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "all", FALSE);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "all", TRUE);
WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "OUTLINER_OT_operation", RIGHTMOUSE, KM_PRESS, 0, 0);
@@ -98,10 +107,12 @@ void outliner_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PADPERIOD, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEDOWNKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "up", 1);
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEUPKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "up", TRUE);
WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADPLUSKEY, KM_PRESS, 0, 0); /* open */
- RNA_boolean_set(WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADMINUS, KM_PRESS, 0, 0)->ptr, "open", 0); /* close */
+ kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADMINUS, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "open", FALSE); /* close */
WM_keymap_verify_item(keymap, "OUTLINER_OT_selected_toggle", AKEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "OUTLINER_OT_expanded_toggle", AKEY, KM_PRESS, KM_SHIFT, 0);
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index bf570c929cc..345e7a835f4 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -875,3 +875,78 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot)
}
/* ****************************************************** */
+
+/* **************** Border Select Tool ****************** */
+static void outliner_item_border_select(Scene *scene, SpaceOops *soops, rctf *rectf, TreeElement *te, int gesture_mode)
+{
+ TreeStoreElem *tselem= TREESTORE(te);
+
+ if (te->ys <= rectf->ymax && te->ys + UI_UNIT_Y >= rectf->ymin) {
+ if (gesture_mode == GESTURE_MODAL_SELECT) {
+ tselem->flag |= TSE_SELECTED;
+ }
+ else {
+ tselem->flag &= ~TSE_SELECTED;
+ }
+ }
+
+ /* Look at its children. */
+ if ((tselem->flag & TSE_CLOSED) == 0) {
+ for (te = te->subtree.first; te; te = te->next) {
+ outliner_item_border_select(scene, soops, rectf, te, gesture_mode);
+ }
+ }
+ return;
+}
+
+static int outliner_border_select_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene= CTX_data_scene(C);
+ SpaceOops *soops= CTX_wm_space_outliner(C);
+ ARegion *ar= CTX_wm_region(C);
+ TreeElement *te;
+ rcti rect;
+ rctf rectf;
+ int gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
+
+ rect.xmin= RNA_int_get(op->ptr, "xmin");
+ rect.ymin= RNA_int_get(op->ptr, "ymin");
+ UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
+
+ rect.xmax= RNA_int_get(op->ptr, "xmax");
+ rect.ymax= RNA_int_get(op->ptr, "ymax");
+ UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
+
+ for(te= soops->tree.first; te; te= te->next) {
+ outliner_item_border_select(scene, soops, &rectf, te, gesture_mode);
+ }
+
+ WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_select_border(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Border Select";
+ ot->idname= "OUTLINER_OT_select_border";
+ ot->description= "Use box selection to select tree elements";
+
+ /* api callbacks */
+ ot->invoke= WM_border_select_invoke;
+ ot->exec= outliner_border_select_exec;
+ ot->modal= WM_border_select_modal;
+ ot->cancel= WM_border_select_cancel;
+
+ ot->poll= ED_operator_outliner_active;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* rna */
+ WM_operator_properties_gesture_border(ot, FALSE);
+}
+
+/* ****************************************************** */
diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c
index b0c2de390a2..7702e952e24 100644
--- a/source/blender/editors/space_script/script_edit.c
+++ b/source/blender/editors/space_script/script_edit.c
@@ -96,8 +96,8 @@ static int script_reload_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
#else
(void)C; /* unused */
-#endif
return OPERATOR_CANCELLED;
+#endif
}
void SCRIPT_OT_reload(wmOperatorType *ot)
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 176ffd91e3b..511f1524fae 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -143,7 +143,7 @@ static void get_seq_color3ubv(Scene *curscene, Sequence *seq, unsigned char col[
case SEQ_COLOR:
if (colvars->col) {
- rgb_float_to_byte(colvars->col, col);
+ rgb_float_to_uchar(col, colvars->col);
} else {
col[0] = col[1] = col[2] = 128;
}
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index 56c2e0ee4d1..c46a1eebc2e 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -3034,10 +3034,10 @@ static int sequencer_change_path_invoke(bContext *C, wmOperator *op, wmEvent *UN
/* set default display depending on seq type */
if(seq->type == SEQ_IMAGE) {
- RNA_boolean_set(op->ptr, "filter_movie", 0);
+ RNA_boolean_set(op->ptr, "filter_movie", FALSE);
}
else {
- RNA_boolean_set(op->ptr, "filter_image", 0);
+ RNA_boolean_set(op->ptr, "filter_image", FALSE);
}
WM_event_add_fileselect(C, op);
diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c
index a6d8b6c2612..ec9f8bb36d9 100644
--- a/source/blender/editors/space_sequencer/sequencer_ops.c
+++ b/source/blender/editors/space_sequencer/sequencer_ops.c
@@ -136,9 +136,11 @@ void sequencer_keymap(wmKeyConfig *keyconf)
RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
-
- RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0)->ptr, "type", SEQ_CUT_SOFT);
- RNA_enum_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", SEQ_CUT_HARD);
+
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "type", SEQ_CUT_SOFT);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_cut", KKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set(kmi->ptr, "type", SEQ_CUT_HARD);
kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_mute", HKEY, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "unselected", FALSE);
@@ -212,25 +214,27 @@ void sequencer_keymap(wmKeyConfig *keyconf)
/* 2.4x method, now use Alt for handles and select the side based on which handle was selected */
/*
- RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "linked_left", 1);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "linked_right", 1);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "linked_left", 1);
- RNA_boolean_set(kmi->ptr, "linked_right", 1);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL|KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "linked_left", 1);
- RNA_boolean_set(kmi->ptr, "linked_right", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "linked_left", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_left", TRUE);
kmi= WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0);
- RNA_boolean_set(kmi->ptr, "extend", 1);
- RNA_boolean_set(kmi->ptr, "linked_right", 1);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
+ RNA_boolean_set(kmi->ptr, "linked_right", TRUE);
*/
/* 2.5 method, Alt and use selected handle */
@@ -263,8 +267,10 @@ void sequencer_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "SEQUENCER_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "SEQUENCER_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", FALSE);
+ kmi = WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", TRUE);
WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index 7e6af8ea789..314afeac0e6 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -268,19 +268,19 @@ static void text_keymap(struct wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 0);
+ RNA_boolean_set(kmi->ptr, "reverse", FALSE);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "space_data.font_size");
- RNA_boolean_set(kmi->ptr, "reverse", 1);
+ RNA_boolean_set(kmi->ptr, "reverse", TRUE);
WM_keymap_add_item(keymap, "TEXT_OT_new", NKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
@@ -298,8 +298,10 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_copy", INSERTKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_paste", INSERTKEY, KM_PRESS, KM_SHIFT, 0);
- if(U.uiflag & USER_MMB_PASTE) // XXX not dynamic
- RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0)->ptr, "selection", 1);
+ if(U.uiflag & USER_MMB_PASTE) { // XXX not dynamic
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "selection", TRUE);
+ }
WM_keymap_add_item(keymap, "TEXT_OT_jump", JKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_CTRL, 0);
@@ -307,8 +309,10 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_CTRL, 0)->ptr, "split_lines", 1);
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "split_lines", FALSE);
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "split_lines", TRUE);
WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
@@ -357,12 +361,15 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_overwrite_toggle", INSERTKEY, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", MIDDLEMOUSE, KM_PRESS, 0, 0);
+
WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0);
- WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_selection_set", EVT_TWEAK_L, KM_ANY, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
+ kmi = WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "select", TRUE);
RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1);
RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1);
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index 25b9c2f2864..8a78f236fea 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -72,7 +72,7 @@ static void text_font_end(SpaceText *UNUSED(st))
{
}
-static int text_font_draw(SpaceText *UNUSED(st), int x, int y, char *str)
+static int text_font_draw(SpaceText *UNUSED(st), int x, int y, const char *str)
{
BLF_position(mono, x, y, 0);
BLF_draw(mono, str, BLF_DRAW_STR_DUMMY_MAX);
@@ -92,19 +92,28 @@ static int text_font_draw_character(SpaceText *st, int x, int y, char c)
return st->cwidth;
}
-int text_font_width(SpaceText *UNUSED(st), const char *str)
+static int text_font_draw_character_utf8(SpaceText *st, int x, int y, const char *c)
{
- return BLF_width(mono, str);
+ char str[BLI_UTF8_MAX+1];
+ size_t len = BLI_str_utf8_size(c);
+ memcpy(str, c, len);
+ str[len]= '\0';
+
+ BLF_position(mono, x, y, 0);
+ BLF_draw(mono, str, len);
+
+ return st->cwidth;
}
/****************** flatten string **********************/
-static void flatten_string_append(FlattenString *fs, char c, int accum)
+static void flatten_string_append(FlattenString *fs, const char *c, int accum, int len)
{
- if(fs->pos>=fs->len && fs->pos>=sizeof(fs->fixedbuf)-1) {
+ int i;
+
+ if(fs->pos+len > fs->len) {
char *nbuf; int *naccum;
- if(fs->len) fs->len*= 2;
- else fs->len= sizeof(fs->fixedbuf) * 2;
+ fs->len*= 2;
nbuf= MEM_callocN(sizeof(*fs->buf)*fs->len, "fs->buf");
naccum= MEM_callocN(sizeof(*fs->accum)*fs->len, "fs->accum");
@@ -121,35 +130,45 @@ static void flatten_string_append(FlattenString *fs, char c, int accum)
fs->accum= naccum;
}
- fs->buf[fs->pos]= c;
- fs->accum[fs->pos]= accum;
-
- fs->pos++;
+ for (i = 0; i < len; i++)
+ {
+ fs->buf[fs->pos+i]= c[i];
+ fs->accum[fs->pos+i]= accum;
+ }
+
+ fs->pos+= len;
}
int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
{
- int r = 0, i = 0;
+ int r, i, total = 0;
memset(fs, 0, sizeof(FlattenString));
fs->buf= fs->fixedbuf;
fs->accum= fs->fixedaccum;
-
- for(r=0, i=0; *in; r++, in++) {
- if(*in=='\t') {
- if(fs->pos && *(in-1)=='\t')
- i= st->tabnumber;
- else if(st->tabnumber > 0)
- i= st->tabnumber - (fs->pos%st->tabnumber);
+ fs->len = sizeof(fs->fixedbuf);
+ for(r = 0, i = 0; *in; r++) {
+ if(*in=='\t') {
+ i= st->tabnumber - (total%st->tabnumber);
+ total+= i;
+
while(i--)
- flatten_string_append(fs, ' ', r);
+ flatten_string_append(fs, " ", r, 1);
+
+ in++;
+ }
+ else {
+ size_t len= BLI_str_utf8_size(in);
+ flatten_string_append(fs, in, r, len);
+ in += len;
+ total++;
}
- else
- flatten_string_append(fs, *in, r);
}
+
+ flatten_string_append(fs, "\0", r, 1);
- return fs->pos;
+ return total;
}
void flatten_string_free(FlattenString *fs)
@@ -304,9 +323,8 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
else orig = 0xFF;
- flatten_string(st, &fs, line->line);
+ len = flatten_string(st, &fs, line->line);
str = fs.buf;
- len = strlen(str);
if(!text_check_format_len(line, len)) {
flatten_string_free(&fs);
return;
@@ -318,7 +336,7 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
if(*str == '\\') {
*fmt = prev; fmt++; str++;
if(*str == '\0') break;
- *fmt = prev; fmt++; str++;
+ *fmt = prev; fmt++; str += BLI_str_utf8_size(str);
continue;
}
/* Handle continuations */
@@ -339,14 +357,16 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
*fmt = 'l';
+ str += BLI_str_utf8_size(str) - 1;
}
/* Not in a string... */
else {
/* Deal with comments first */
- if(prev == '#' || *str == '#')
+ if(prev == '#' || *str == '#') {
*fmt = '#';
- /* Strings */
- else if(*str == '"' || *str == '\'') {
+ str += BLI_str_utf8_size(str) - 1;
+ } else if(*str == '"' || *str == '\'') {
+ /* Strings */
find = *str;
cont = (*str== '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR;
if(*(str+1) == find && *(str+2) == find) {
@@ -371,14 +391,18 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
*fmt = 'n';
}
- else
+ else {
+ str += BLI_str_utf8_size(str) - 1;
*fmt = 'q';
+ }
/* Punctuation */
else if(text_check_delim(*str))
*fmt = '!';
/* Identifiers and other text (no previous ws. or delims. so text continues) */
- else if(prev == 'q')
+ else if(prev == 'q') {
+ str += BLI_str_utf8_size(str) - 1;
*fmt = 'q';
+ }
/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
else {
/* Special vars(v) or built-in keywords(b) */
@@ -395,8 +419,10 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
*fmt = prev;
}
- else
+ else {
+ str += BLI_str_utf8_size(str) - 1;
*fmt = 'q';
+ }
}
}
prev = *fmt;
@@ -408,14 +434,11 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
*fmt = '\0'; fmt++;
*fmt = cont;
- /* Debugging */
- //print_format(st, line);
-
/* If continuation has changed and we're allowed, process the next line */
if(cont!=orig && do_next && line->next) {
txt_format_line(st, line->next, do_next);
}
-
+
flatten_string_free(&fs);
}
@@ -539,13 +562,14 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
}
max= wrap_width(st, ar);
+ cursin = txt_utf8_offset_to_index(linein->line, cursin);
while(linep) {
start= 0;
end= max;
chop= 1;
*offc= 0;
- for(i=0, j=0; linep->line[j]!='\0'; j++) {
+ for(i=0, j=0; linep->line[j]; j+=BLI_str_utf8_size(linep->line+j)) {
int chars;
/* Mimic replacement of tabs */
@@ -591,6 +615,7 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
}
}
+/* cursin - mem, offc - view */
void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *offl, int *offc)
{
int i, j, start, end, chars, max, chop;
@@ -607,8 +632,9 @@ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursi
end= max;
chop= 1;
*offc= 0;
+ cursin = txt_utf8_offset_to_index(linein->line, cursin);
- for(i=0, j=0; linein->line[j]!='\0'; j++) {
+ for(i=0, j=0; linein->line[j]; j += BLI_str_utf8_size(linein->line + j)) {
/* Mimic replacement of tabs */
ch= linein->line[j];
@@ -653,7 +679,7 @@ int text_get_char_pos(SpaceText *st, const char *line, int cur)
{
int a=0, i;
- for(i=0; i<cur && line[i]; i++) {
+ for(i=0; i<cur && line[i]; i += BLI_str_utf8_size(line + i)) {
if(line[i]=='\t')
a += st->tabnumber-a%st->tabnumber;
else
@@ -662,54 +688,65 @@ int text_get_char_pos(SpaceText *st, const char *line, int cur)
return a;
}
-static int text_draw_wrapped(SpaceText *st, char *str, int x, int y, int w, char *format, int skip)
+static const char *txt_utf8_get_nth(const char *str, int n)
+{
+ int pos= 0;
+ while (str[pos] && n--) {
+ pos+= BLI_str_utf8_size(str + pos);
+ }
+ return str + pos;
+}
+
+static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w, const char *format, int skip)
{
FlattenString fs;
- int basex, i, a, len, start, end, max, lines;
+ int basex, i, a, start, end, max, lines; /* view */
+ int mi, ma, mstart, mend; /* mem */
- len= flatten_string(st, &fs, str);
+ flatten_string(st, &fs, str);
str= fs.buf;
max= w/st->cwidth;
if(max<8) max= 8;
basex= x;
-
lines= 1;
- start= 0;
- end= max;
- for(i=0; i<len; i++) {
+
+ start= 0; mstart= 0;
+ end= max; mend= txt_utf8_get_nth(str, max) - str;
+
+ for(i=0, mi=0; str[mi]; i++, mi+=BLI_str_utf8_size(str+mi)) {
if(i-start >= max) {
/* skip hidden part of line */
if(skip) {
skip--;
- start= end;
- end += max;
+ start= end; mstart= mend;
+ end += max; mend= txt_utf8_get_nth(str+mend, max) - str;
continue;
}
/* Draw the visible portion of text on the overshot line */
- for(a=start; a<end; a++) {
+ for(a=start, ma=mstart; a<end; a++, ma+=BLI_str_utf8_size(str+ma)) {
if(st->showsyntax && format) format_draw_color(format[a]);
- x += text_font_draw_character(st, x, y, str[a]);
+ x += text_font_draw_character_utf8(st, x, y, str + ma);
}
y -= st->lheight;
x= basex;
lines++;
- start= end;
- end += max;
+ start= end; mstart= mend;
+ end += max; mend= txt_utf8_get_nth(str+mend, max) - str;
if(y<=0) break;
}
- else if(str[i]==' ' || str[i]=='-') {
- end = i+1;
+ else if(str[mi]==' ' || str[mi]=='-') {
+ end = i+1; mend = mi+1;
}
}
/* Draw the remaining text */
- for(a=start; a<len && y > 0; a++) {
+ for(a=start, ma=mstart; str[ma] && y > 0; a++, ma+=BLI_str_utf8_size(str+ma)) {
if(st->showsyntax && format)
format_draw_color(format[a]);
- x += text_font_draw_character(st, x, y, str[a]);
+ x += text_font_draw_character_utf8(st, x, y, str+ma);
}
flatten_string_free(&fs);
@@ -717,45 +754,36 @@ static int text_draw_wrapped(SpaceText *st, char *str, int x, int y, int w, char
return lines;
}
-static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int draw, int x, int y, char *format)
+static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int draw, int x, int y, const char *format)
{
FlattenString fs;
- int r=0, w= 0, amount;
- int *acc;
- char *in;
+ int *acc, r=0;
+ const char *in;
- w= flatten_string(st, &fs, str);
+ int w= flatten_string(st, &fs, str);
if(w < cshift) {
flatten_string_free(&fs);
return 0; /* String is shorter than shift */
}
- in= fs.buf+cshift;
+ in= txt_utf8_get_nth(fs.buf, cshift);
acc= fs.accum+cshift;
w= w-cshift;
if(draw) {
+ int amount = maxwidth ? MIN2(w, maxwidth) : w;
+
if(st->showsyntax && format) {
- int a;
+ int a, str_shift= 0;
format = format+cshift;
-
- amount = strlen(in);
- if(maxwidth)
- amount= MIN2(amount, maxwidth);
-
+
for(a = 0; a < amount; a++) {
format_draw_color(format[a]);
- x += text_font_draw_character(st, x, y, in[a]);
+ x += text_font_draw_character_utf8(st, x, y, in + str_shift);
+ str_shift += BLI_str_utf8_size(in + str_shift);
}
}
- else {
- amount = strlen(in);
- if(maxwidth)
- amount= MIN2(amount, maxwidth);
-
- in[amount]= 0;
- text_font_draw(st, x, y, in);
- }
+ else text_font_draw(st, x, y, in);
}
else {
while(w-- && *acc++ < maxwidth)
@@ -976,8 +1004,8 @@ int text_get_visible_lines(SpaceText *st, ARegion *ar, const char *str)
max= wrap_width(st, ar);
lines= 1;
start= 0;
- end= max;
- for(i= 0, j= 0; str[j] != '\0'; j++) {
+ end= max;
+ for(i= 0, j= 0; str[j]; j+=BLI_str_utf8_size(str+j)) {
/* Mimic replacement of tabs */
ch= str[j];
if(ch=='\t') {
@@ -1421,7 +1449,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
BLI_strncpy(str, item->name, SUGG_LIST_WIDTH);
- w = text_font_width(st, str);
+ w = BLF_width(mono, str);
if(item == sel) {
UI_ThemeColor(TH_SHADE2);
@@ -1496,8 +1524,6 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
glRecti(x-4, y, ar->winx, y-st->lheight), y-=st->lheight;
glRecti(x-4, y, x+toc*st->cwidth, y-st->lheight); y-=st->lheight;
-
- (void)y;
}
}
else {
@@ -1569,8 +1595,9 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
{
TextLine *startl, *endl, *linep;
Text *text = st->text;
- int b, c, startc, endc, find, stack;
- int viewc, viewl, offl, offc, x, y;
+ int b, fc, find, stack, viewc, viewl, offl, offc, x, y;
+ int startc, endc, c;
+
char ch;
// showsyntax must be on or else the format string will be null
@@ -1584,21 +1611,23 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
linep= startl;
c= startc;
+ fc= txt_utf8_offset_to_index(linep->line, startc);
endl= NULL;
endc= -1;
find= -b;
stack= 0;
/* Dont highlight backets if syntax HL is off or bracket in string or comment. */
- if(!linep->format || linep->format[c] == 'l' || linep->format[c] == '#')
+ if(!linep->format || linep->format[fc] == 'l' || linep->format[fc] == '#')
return;
if(b>0) {
/* opening bracket, search forward for close */
- c++;
+ fc++;
+ c+= BLI_str_utf8_size(linep->line+c);
while(linep) {
while(c<linep->len) {
- if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') {
+ if(linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
b= text_check_bracket(linep->line[c]);
if(b==find) {
if(stack==0) {
@@ -1612,19 +1641,22 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
stack++;
}
}
- c++;
+ fc++;
+ c+= BLI_str_utf8_size(linep->line+c);
}
if(endl) break;
linep= linep->next;
c= 0;
+ fc= 0;
}
}
else {
/* closing bracket, search backward for open */
- c--;
+ fc--;
+ if (c>0) c -= linep->line+c-BLI_str_prev_char_utf8(linep->line+c);
while(linep) {
- while(c>=0) {
- if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') {
+ while(fc>=0) {
+ if(linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
b= text_check_bracket(linep->line[c]);
if(b==find) {
if(stack==0) {
@@ -1638,11 +1670,17 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
stack++;
}
}
- c--;
+ fc--;
+ if (c>0) c -= linep->line+c-BLI_str_prev_char_utf8(linep->line+c);
}
if(endl) break;
linep= linep->prev;
- if(linep) c= linep->len-1;
+ if(linep) {
+ if (linep->format) fc= strlen(linep->format)-1;
+ else fc= -1;
+ if (linep->len) c= BLI_str_prev_char_utf8(linep->line+linep->len)-linep->line;
+ else fc= -1;
+ }
}
}
diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h
index 62cd4fedf0e..043fb97547b 100644
--- a/source/blender/editors/space_text/text_intern.h
+++ b/source/blender/editors/space_text/text_intern.h
@@ -47,9 +47,6 @@ struct wmWindowManager;
/* text_draw.c */
void draw_text_main(struct SpaceText *st, struct ARegion *ar);
-int text_font_width_character(struct SpaceText *st);
-int text_font_width(struct SpaceText *st, const char *str);
-
void text_update_line_edited(struct TextLine *line);
void text_update_edited(struct Text *text);
void text_update_character_width(struct SpaceText *st);
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index e8ad6e19fd4..eab06474546 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -1420,7 +1420,7 @@ static int text_get_cursor_rel(SpaceText* st, ARegion *ar, TextLine *linein, int
end= max;
chop= loop= 1;
- for(i=0, j=0; loop; j++) {
+ for(i=0, j=0; loop; j+=BLI_str_utf8_size(linein->line+j)) {
int chars;
/* Mimic replacement of tabs */
ch= linein->line[j];
@@ -1595,7 +1595,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
chop= loop= 1;
*charp= 0;
- for(i=0, j=0; loop; j++) {
+ for(i=0, j=0; loop; j+=BLI_str_utf8_size((*linep)->line+j)) {
int chars;
/* Mimic replacement of tabs */
ch= (*linep)->line[j];
@@ -1610,7 +1610,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
*charp= endj;
if(j>=oldc) {
- if(ch=='\0') *charp= start;
+ if(ch=='\0') *charp= txt_utf8_index_to_offset((*linep)->line, start);
loop= 0;
break;
}
@@ -1623,7 +1623,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
}
else if(ch==' ' || ch=='-' || ch=='\0') {
if(j>=oldc) {
- *charp= start;
+ *charp= txt_utf8_index_to_offset((*linep)->line, start);
loop= 0;
break;
}
@@ -1663,7 +1663,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
chop= loop= 1;
*charp= 0;
- for(i=0, j=0; loop; j++) {
+ for(i=0, j=0; loop; j+=BLI_str_utf8_size((*linep)->line+j)) {
int chars;
/* Mimic replacement of tabs */
ch= (*linep)->line[j];
@@ -1675,7 +1675,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
while(chars--) {
if(i-start>=max) {
- if(chop) endj= j-1;
+ if(chop) endj= BLI_str_prev_char_utf8((*linep)->line+j)-(*linep)->line;
if(endj>=oldc) {
if(ch=='\0') *charp= (*linep)->len;
@@ -2232,8 +2232,8 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
text_scroll_apply(C, op, event);
scroll_exit(C, op);
return OPERATOR_FINISHED;
- }
-
+ }
+
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
@@ -2314,9 +2314,20 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event)
tsc->scrollbar= 1;
tsc->zone= zone;
op->customdata= tsc;
-
st->flags|= ST_SCROLL_SELECT;
+ /* jump scroll, works in v2d but needs to be added here too :S */
+ if (event->type == MIDDLEMOUSE) {
+ tsc->old[0] = ar->winrct.xmin + (st->txtbar.xmax + st->txtbar.xmin) / 2;
+ tsc->old[1] = ar->winrct.ymin + (st->txtbar.ymax + st->txtbar.ymin) / 2;
+
+ tsc->delta[0] = 0;
+ tsc->delta[1] = 0;
+ tsc->first = 0;
+ tsc->zone= SCROLLHANDLE_BAR;
+ text_scroll_apply(C, op, event);
+ }
+
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
@@ -2353,148 +2364,183 @@ typedef struct SetSelection {
short old[2];
} SetSelection;
-static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel)
+static int flatten_len(SpaceText *st, const char *str)
{
- FlattenString fs;
- Text *text= st->text;
- TextLine **linep;
- int *charp;
- int w;
-
- text_update_character_width(st);
+ int i, total = 0;
- if(sel) { linep= &text->sell; charp= &text->selc; }
- else { linep= &text->curl; charp= &text->curc; }
+ for(i = 0; str[i]; i += BLI_str_utf8_size(str+i)) {
+ if(str[i]=='\t') {
+ total += st->tabnumber - total%st->tabnumber;
+ }
+ else total++;
+ }
- y= (ar->winy - 2 - y)/st->lheight;
-
- if(st->showlinenrs)
- x-= TXT_OFFSET+TEXTXLOC;
- else
- x-= TXT_OFFSET;
+ return total;
+}
- if(x<0) x= 0;
- x = (x/st->cwidth) + st->left;
+static int flatten_index_to_offset(SpaceText *st, const char *str, int index)
+{
+ int i, j;
+ for (i= 0, j= 0; i < index; j += BLI_str_utf8_size(str+j))
+ if(str[j]=='\t')
+ i += st->tabnumber - i%st->tabnumber;
+ else
+ i++;
- if(st->wordwrap) {
- int i, j, endj, curs, max, chop, start, end, loop, found;
- char ch;
-
- /* Point to first visible line */
- *linep= text->lines.first;
- i= st->top;
- while(i>0 && *linep) {
- int lines= text_get_visible_lines(st, ar, (*linep)->line);
+ return j;
+}
- if (i-lines<0) {
- y+= i;
- break;
- } else {
- *linep= (*linep)->next;
- i-= lines;
- }
+static TextLine *get_first_visible_line(SpaceText *st, ARegion *ar, int *y)
+{
+ TextLine *linep = st->text->lines.first;
+ int i;
+ for (i = st->top; i > 0 && linep; ) {
+ int lines = text_get_visible_lines(st, ar, linep->line);
+
+ if (i-lines < 0) {
+ *y += i;
+ break;
+ } else {
+ linep = linep->next;
+ i -= lines;
}
+ }
+ return linep;
+}
- max= wrap_width(st, ar);
-
- loop= 1;
- found= 0;
- while(loop && *linep) {
- start= 0;
- end= max;
- chop= 1;
- curs= 0;
- endj= 0;
- for(i=0, j=0; loop; j++) {
- int chars;
-
- /* Mimic replacement of tabs */
- ch= (*linep)->line[j];
- if(ch=='\t') {
- chars= st->tabnumber-i%st->tabnumber;
- ch= ' ';
- }
- else
- chars= 1;
-
- while(chars--) {
- /* Gone too far, go back to last wrap point */
- if(y<0) {
- *charp= endj;
- loop= 0;
- break;
+static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, int y, int sel)
+{
+ Text *text = st->text;
+ int max = wrap_width(st, ar); /* view */
+ int charp; /* mem */
+ int loop = 1, found = 0; /* flags */
+ char ch;
+
+ /* Point to first visible line */
+ TextLine *linep = get_first_visible_line(st, ar, &y);
+
+ while(loop && linep) {
+ int i = 0, start = 0, end = max; /* view */
+ int j = 0, curs = 0, endj = 0; /* mem */
+ int chop = 1; /* flags */
+
+ for (; loop; j += BLI_str_utf8_size(linep->line+j)) {
+ int chars;
+
+ /* Mimic replacement of tabs */
+ ch = linep->line[j];
+ if(ch == '\t') {
+ chars = st->tabnumber - i%st->tabnumber;
+ ch = ' ';
+ }
+ else chars = 1;
+
+ while (chars--) {
+ /* Gone too far, go back to last wrap point */
+ if (y < 0) {
+ charp = endj;
+ loop = 0;
+ break;
/* Exactly at the cursor */
- }
- else if(y==0 && i-start==x) {
- /* current position could be wrapped to next line */
- /* this should be checked when end of current line would be reached */
- *charp= curs= j;
- found= 1;
+ }
+ else if (y == 0 && i-start == x) {
+ /* current position could be wrapped to next line */
+ /* this should be checked when end of current line would be reached */
+ charp = curs= j;
+ found = 1;
/* Prepare curs for next wrap */
+ }
+ else if(i - end == x) {
+ curs = j;
+ }
+ if (i - start >= max) {
+ if (found) {
+ /* exact cursor position was found, check if it's */
+ /* still on needed line (hasn't been wrapped) */
+ if (charp > endj && !chop && ch!='\0') charp = endj;
+ loop = 0;
+ break;
}
- else if(i-end==x) {
- curs= j;
+
+ if(chop) endj = j;
+ start = end;
+ end += max;
+
+ if(j < linep->len)
+ y--;
+
+ chop = 1;
+ if (y == 0 && i-start >= x) {
+ charp = curs;
+ loop = 0;
+ break;
}
- if(i-start>=max) {
- if(found) {
- /* exact cursor position was found, check if it's */
- /* still on needed line (hasn't been wrapped) */
- if(*charp>endj && !chop && ch!='\0') (*charp)= endj;
- loop= 0;
- break;
- }
-
- if(chop) endj= j;
- start= end;
- end += max;
-
- if(j<(*linep)->len)
- y--;
-
- chop= 1;
- if(y==0 && i-start>=x) {
- *charp= curs;
- loop= 0;
- break;
- }
+ }
+ else if (ch == ' ' || ch == '-' || ch == '\0') {
+ if (found) {
+ loop = 0;
+ break;
}
- else if(ch==' ' || ch=='-' || ch=='\0') {
- if(found) {
- loop= 0;
- break;
- }
-
- if(y==0 && i-start>=x) {
- *charp= curs;
- loop= 0;
- break;
- }
- end = i+1;
- endj = j;
- chop= 0;
+
+ if(y == 0 && i-start >= x) {
+ charp = curs;
+ loop = 0;
+ break;
}
- i++;
+ end = i + 1;
+ endj = j;
+ chop = 0;
}
- if(ch=='\0') break;
+ i++;
}
- if(!loop || found) break;
+
+ if(ch == '\0') break;
+ }
+
+ if(!loop || found) break;
+
+ if(!linep->next) {
+ charp = linep->len;
+ break;
+ }
+
+ /* On correct line but didn't meet cursor, must be at end */
+ if (y == 0) {
+ charp = linep->len;
+ break;
+ }
+ linep = linep->next;
+
+ y--;
+ }
+
+ if(sel) { text->sell = linep; text->selc = charp; }
+ else { text->curl = linep; text->curc = charp; }
+}
- if(!(*linep)->next) {
- *charp= (*linep)->len;
- break;
- }
+static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel)
+{
+ Text *text= st->text;
+ text_update_character_width(st);
+ y= (ar->winy - 2 - y)/st->lheight;
- /* On correct line but didn't meet cursor, must be at end */
- if(y==0) {
- *charp= (*linep)->len;
- break;
- }
- *linep= (*linep)->next;
- y--;
- }
+ if(st->showlinenrs) x-= TXT_OFFSET+TEXTXLOC;
+ else x-= TXT_OFFSET;
+ if(x<0) x= 0;
+ x = (x/st->cwidth) + st->left;
+
+ if(st->wordwrap) {
+ text_cursor_set_to_pos_wrapped(st, ar, x, y, sel);
}
else {
+ TextLine **linep;
+ int *charp;
+ int w;
+
+ if(sel) { linep= &text->sell; charp= &text->selc; }
+ else { linep= &text->curl; charp= &text->curc; }
+
y-= txt_get_span(text->lines.first, *linep) - st->top;
if(y>0) {
@@ -2505,10 +2551,9 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int
}
- w= flatten_string(st, &fs, (*linep)->line);
- if(x<w) *charp= fs.accum[x];
+ w= flatten_len(st, (*linep)->line);
+ if(x<w) *charp= flatten_index_to_offset(st, (*linep)->line, x);
else *charp= (*linep)->len;
- flatten_string_free(&fs);
}
if(!sel) txt_pop_sel(text);
}
@@ -2751,19 +2796,23 @@ static int text_insert_exec(bContext *C, wmOperator *op)
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
char *str;
- int done = 0, i;
+ int done = 0;
+ size_t i = 0;
+ unsigned int code;
text_drawcache_tag_update(st, 0);
str= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
if(st && st->overwrite) {
- for(i=0; str[i]; i++) {
- done |= txt_replace_char(text, str[i]);
+ while (str[i]) {
+ code = BLI_str_utf8_as_unicode_step(str, &i);
+ done |= txt_replace_char(text, code);
}
} else {
- for(i=0; str[i]; i++) {
- done |= txt_add_char(text, str[i]);
+ while (str[i]) {
+ code = BLI_str_utf8_as_unicode_step(str, &i);
+ done |= txt_add_char(text, code);
}
}
@@ -2791,9 +2840,17 @@ static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_PASS_THROUGH;
}
else {
- char str[2];
- str[0]= event->ascii;
- str[1]= '\0';
+ char str[BLI_UTF8_MAX+1];
+ size_t len;
+
+ if (event->utf8_buf[0]) {
+ len = BLI_str_utf8_size(event->utf8_buf);
+ memcpy(str, event->utf8_buf, len);
+ } else {
+ /* in theory, ghost can set value to extended ascii here */
+ len = BLI_str_utf8_from_unicode(event->ascii, str);
+ }
+ str[len]= '\0';
RNA_string_set(op->ptr, "text", str);
}
}
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c
index 17cb1ce2995..599e113ba97 100644
--- a/source/blender/editors/space_view3d/drawarmature.c
+++ b/source/blender/editors/space_view3d/drawarmature.c
@@ -526,7 +526,8 @@ static void draw_bone_solid_octahedral(void)
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, 0, bone_octahedral_solid_normals);
glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts);
- glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris)/sizeof(unsigned int), GL_UNSIGNED_INT, bone_octahedral_solid_tris);
+ glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris)/sizeof(unsigned int),
+ GL_UNSIGNED_INT, bone_octahedral_solid_tris);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
#endif
@@ -738,7 +739,9 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel
/* smat, imat = mat & imat to draw screenaligned */
-static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_sphere_bone_wire(float smat[][4], float imat[][4],
+ int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
float head, tail /*, length*/;
float *headvec, *tailvec, dirvec[3];
@@ -843,7 +846,8 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag,
}
/* does wire only for outline selecting */
-static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
GLUquadricObj *qobj;
float head, tail, length;
@@ -973,7 +977,8 @@ static GLubyte bm_dot5[]= {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
static GLubyte bm_dot7[]= {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
-static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
float length;
@@ -1107,7 +1112,8 @@ static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float l
}
}
-static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
float xwidth, length, zwidth;
@@ -1220,7 +1226,8 @@ static void draw_wire_bone_segments(bPoseChannel *pchan, Mat4 *bbones, float len
}
}
-static void draw_wire_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
+static void draw_wire_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id,
+ bPoseChannel *pchan, EditBone *ebone)
{
Mat4 *bbones = NULL;
int segments = 0;
@@ -1340,7 +1347,8 @@ static void draw_bone(int dt, int armflag, int boneflag, short constflag, unsign
}
}
-static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
+static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob,
+ int dt, int armflag, int boneflag, unsigned int id, float length)
{
if(ob==NULL) return;
@@ -1573,7 +1581,8 @@ static void draw_pose_dofs(Object *ob)
glColor3ub(50, 50, 255); // blue, Z axis limit
glBegin(GL_LINE_STRIP);
for (a=-16; a<=16; a++) {
- float fac= ((float)a)/16.0f * 0.5f; /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ float fac= ((float)a)/16.0f * 0.5f;
phi= fac * (pchan->limitmax[2] - pchan->limitmin[2]);
@@ -1596,7 +1605,8 @@ static void draw_pose_dofs(Object *ob)
glColor3ub(255, 50, 50); // Red, X axis limit
glBegin(GL_LINE_STRIP);
for (a=-16; a<=16; a++) {
- float fac= ((float)a)/16.0f * 0.5f; /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
+ float fac= ((float)a)/16.0f * 0.5f;
phi= (float)(0.5*M_PI) + fac * (pchan->limitmax[0] - pchan->limitmin[0]);
i= (a == -16) ? 2 : 3;
@@ -1630,7 +1640,8 @@ static void bone_matrix_translate_y(float mat[][4], float y)
}
/* assumes object is Armature with pose */
-static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, const short is_ghost, const short is_outline)
+static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt,
+ const short is_ghost, const short is_outline)
{
RegionView3D *rv3d= ar->regiondata;
Object *ob= base->object;
@@ -1730,10 +1741,13 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
if (use_custom) {
/* if drawwire, don't try to draw in solid */
- if (pchan->bone->flag & BONE_DRAWWIRE)
+ if (pchan->bone->flag & BONE_DRAWWIRE) {
draw_wire= 1;
- else
- draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
+ }
+ else {
+ draw_custom_bone(scene, v3d, rv3d, pchan->custom,
+ OB_SOLID, arm->flag, flag, index, bone->length);
+ }
}
else if (arm->drawtype==ARM_LINE)
; /* nothing in solid */
@@ -1817,7 +1831,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
if (bone == arm->act_bone)
flag |= BONE_DRAW_ACTIVE;
- draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
+ draw_custom_bone(scene, v3d, rv3d, pchan->custom,
+ OB_WIRE, arm->flag, flag, index, bone->length);
glPopMatrix();
}
@@ -1966,7 +1981,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
unsigned char col[4];
float col_f[4];
glGetFloatv(GL_CURRENT_COLOR, col_f); /* incase this is not set below */
- rgb_float_to_byte(col_f, col);
+ rgb_float_to_uchar(col, col_f);
col[3]= 255;
if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
@@ -2580,7 +2595,3 @@ int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, in
return retval;
}
-
-/* *************** END Armature drawing ******************* */
-
-
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index b1842578c20..5f521cc3dd1 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -349,11 +349,8 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O
Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp);
}
- obcol[0]= CLAMPIS(ob->col[0]*255, 0, 255);
- obcol[1]= CLAMPIS(ob->col[1]*255, 0, 255);
- obcol[2]= CLAMPIS(ob->col[2]*255, 0, 255);
- obcol[3]= CLAMPIS(ob->col[3]*255, 0, 255);
-
+ rgba_float_to_uchar(obcol, ob->col);
+
glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
if(solidtex || v3d->drawtype==OB_TEXTURE) istex= 1;
else istex= 0;
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index afe11cdd37f..fd0338c8206 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -2707,10 +2707,14 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em, UnitSet
mul_mat3_m4_v3(ob->obmat, v1);
mul_mat3_m4_v3(ob->obmat, v2);
}
- if(unit->system)
- bUnit_AsString(numstr, sizeof(numstr), len_v3v3(v1, v2)*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE);
- else
+
+ if(unit->system) {
+ bUnit_AsString(numstr, sizeof(numstr), len_v3v3(v1, v2) * unit->scale_length, 3,
+ unit->system, B_UNIT_LENGTH, do_split, FALSE);
+ }
+ else {
sprintf(numstr, conv_float, len_v3v3(v1, v2));
+ }
view3d_cached_text_draw_add(vmid, numstr, 0, V3D_CACHE_TEXT_ASCII, col);
}
@@ -2718,7 +2722,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em, UnitSet
}
if(me->drawflag & ME_DRAWEXTRA_FACEAREA) {
-// XXX extern int faceselectedOR(EditFace *efa, int flag); // editmesh.h shouldn't be in this file... ok for now?
+// XXX extern int faceselectedOR(EditFace *efa, int flag); // editmesh.h shouldn't be in this file... ok for now?
UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
for(efa= em->faces.first; efa; efa= efa->next) {
@@ -2741,10 +2745,14 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em, UnitSet
else
area = area_tri_v3(v1, v2, v3);
- if(unit->system)
- bUnit_AsString(numstr, sizeof(numstr), area*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE); // XXX should be B_UNIT_AREA
- else
+ if(unit->system) {
+ // XXX should be B_UNIT_AREA
+ bUnit_AsString(numstr, sizeof(numstr), area * unit->scale_length, 3,
+ unit->system, B_UNIT_LENGTH, do_split, FALSE);
+ }
+ else {
sprintf(numstr, conv_float, area);
+ }
view3d_cached_text_draw_add(efa->cent, numstr, 0, V3D_CACHE_TEXT_ASCII, col);
}
@@ -4126,7 +4134,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
if(v3d->zbuf) glDepthMask(1);
if((ma) && (part->draw_col == PART_DRAW_COL_MAT)) {
- rgb_float_to_byte(&(ma->r), tcol);
+ rgb_float_to_uchar(tcol, &(ma->r));
copy_v3_v3(ma_col, &ma->r);
}
@@ -6178,7 +6186,7 @@ static void drawRBpivot(bRigidBodyJointConstraint *data)
float curcol[4];
unsigned char tcol[4];
glGetFloatv(GL_CURRENT_COLOR, curcol);
- rgb_float_to_byte(curcol, tcol);
+ rgb_float_to_uchar(tcol, curcol);
tcol[3]= 255;
eul_to_mat4(mat,&data->axX);
@@ -6801,7 +6809,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
float curcol[4];
unsigned char tcol[4];
glGetFloatv(GL_CURRENT_COLOR, curcol);
- rgb_float_to_byte(curcol, tcol);
+ rgb_float_to_uchar(tcol, curcol);
tcol[3]= 255;
view3d_cached_text_draw_add(zero, ob->id.name+2, 10, 0, tcol);
}
diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c
index 8308a4a9ccf..1ed8e44a26b 100644
--- a/source/blender/editors/space_view3d/drawvolume.c
+++ b/source/blender/editors/space_view3d/drawvolume.c
@@ -170,7 +170,8 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3
float cor[3] = {1.,1.,1.};
int gl_depth = 0, gl_blend = 0;
- /* draw slices of smoke is adapted from c++ code authored by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */
+ /* draw slices of smoke is adapted from c++ code authored
+ * by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */
float cv[][3] = {
{1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f},
{1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}
@@ -424,7 +425,9 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
for (i = 0; i < numpoints; i++) {
- glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
+ glTexCoord3d((points[i * 3 + 0] - min[0]) * cor[0] / size[0],
+ (points[i * 3 + 1] - min[1]) * cor[1] / size[1],
+ (points[i * 3 + 2] - min[2]) * cor[2] / size[2]);
glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
}
glEnd();
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index f2906ca9559..94ab847c91b 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -1023,7 +1023,8 @@ static void space_view3d_listener(struct ScrArea *sa, struct wmNotifier *wmn)
break;
}
-#if 0 // removed since BKE_image_user_calc_frame is now called in draw_bgpic because screen_ops doesnt call the notifier.
+ // removed since BKE_image_user_calc_frame is now called in draw_bgpic because screen_ops doesnt call the notifier.
+#if 0
if (wmn->category == NC_SCENE && wmn->data == ND_FRAME) {
View3D *v3d = area->spacedata.first;
BGpic *bgpic = v3d->bgpicbase.first;
@@ -1048,7 +1049,8 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
View3D *v3d= CTX_wm_view3d(C);
Scene *scene= CTX_data_scene(C);
Base *base;
- unsigned int lay = v3d ? v3d->lay:scene->lay; /* fallback to the scene layer, allows duplicate and other oject operators to run outside the 3d view */
+ /* fallback to the scene layer, allows duplicate and other object operators to run outside the 3d view */
+ unsigned int lay = v3d ? v3d->lay:scene->lay;
if(CTX_data_dir(member)) {
CTX_data_dir_set(result, view3d_context_dir);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index ad85ff6dea8..4f46a746b9e 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -471,7 +471,8 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit)
/* emphasise division lines lighter instead of darker, if background is darker than grid */
UI_GetColorPtrShade3ubv(col_grid, col_grid_light, 10);
UI_GetColorPtrShade3ubv(col_grid, col_grid_emphasise,
- (((col_grid[0]+col_grid[1]+col_grid[2])+30) > (col_bg[0]+col_bg[1]+col_bg[2])) ? 20 : -10);
+ (((col_grid[0]+col_grid[1]+col_grid[2])+30) >
+ (col_bg[0]+col_bg[1]+col_bg[2])) ? 20 : -10);
/* set fixed axis */
vert[0][0]= vert[2][1]= grid;
@@ -923,7 +924,8 @@ static void draw_selected_name(Scene *scene, Object *ob)
BLF_draw_default(offset, 10, 0.0f, info, sizeof(info));
}
-static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewborder_r, short no_shift, short no_zoom)
+static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d,
+ rctf *viewborder_r, short no_shift, short no_zoom)
{
CameraParams params;
rctf rect_view, rect_camera;
@@ -962,7 +964,8 @@ void ED_view3d_calc_camera_border_size(Scene *scene, ARegion *ar, View3D *v3d, R
size_r[1]= viewborder.ymax - viewborder.ymin;
}
-void ED_view3d_calc_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewborder_r, short no_shift)
+void ED_view3d_calc_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d,
+ rctf *viewborder_r, short no_shift)
{
view3d_camera_border(scene, ar, v3d, rv3d, viewborder_r, no_shift, FALSE);
}
@@ -1097,7 +1100,9 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
setlinestyle(0);
+
UI_ThemeColor(TH_BACK);
+
glRectf(x1i, y1i, x2i, y2i);
#ifdef VIEW3D_CAMERA_BORDER_HACK
@@ -1109,6 +1114,13 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
#endif
setlinestyle(3);
+
+ /* outer line not to confuse with object selecton */
+ if (v3d->flag2 & V3D_LOCK_CAMERA) {
+ UI_ThemeColor(TH_REDALERT);
+ glRectf(x1i - 1, y1i - 1, x2i + 1, y2i + 1);
+ }
+
UI_ThemeColor(TH_WIRE);
glRectf(x1i, y1i, x2i, y2i);
@@ -1386,7 +1398,12 @@ ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax,
view3d_validate_backbuf(vc);
- glReadPixels(vc->ar->winrct.xmin+xminc, vc->ar->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+ glReadPixels(vc->ar->winrct.xmin + xminc,
+ vc->ar->winrct.ymin + yminc,
+ (xmaxc-xminc + 1),
+ (ymaxc-yminc + 1),
+ GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+
glReadBuffer(GL_BACK);
if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
@@ -1810,11 +1827,13 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
* offset feature (used in group-duplicate.blend but no longer works in 2.5)
* so for now it should be ok to - campbell */
- if( (dob_next==NULL || dob_next->ob != dob->ob) || /* if this is the last no need to make a displist */
- (dob->ob->type == OB_LAMP) || /* lamp drawing messes with matrices, could be handled smarter... but this works */
- (dob->type == OB_DUPLIGROUP && dob->animated) ||
- !(bb_tmp= object_get_boundbox(dob->ob))
- ) {
+ if ( /* if this is the last no need to make a displist */
+ (dob_next==NULL || dob_next->ob != dob->ob) ||
+ /* lamp drawing messes with matrices, could be handled smarter... but this works */
+ (dob->ob->type == OB_LAMP) ||
+ (dob->type == OB_DUPLIGROUP && dob->animated) ||
+ !(bb_tmp= object_get_boundbox(dob->ob)))
+ {
// printf("draw_dupli_objects_color: skipping displist for %s\n", dob->ob->id.name+2);
use_displist= 0;
}
@@ -2142,7 +2161,8 @@ typedef struct View3DShadow {
GPULamp *lamp;
} View3DShadow;
-static void gpu_render_lamp_update(Scene *scene, View3D *v3d, Object *ob, Object *par, float obmat[][4], ListBase *shadows)
+static void gpu_render_lamp_update(Scene *scene, View3D *v3d, Object *ob, Object *par,
+ float obmat[][4], ListBase *shadows)
{
GPULamp *lamp;
Lamp *la = (Lamp*)ob->data;
@@ -2236,7 +2256,9 @@ CustomDataMask ED_view3d_datamask(Scene *scene, View3D *v3d)
{
CustomDataMask mask= 0;
- if(ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) || ((v3d->drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX))) {
+ if ( ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) ||
+ ((v3d->drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX)))
+ {
mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
if(scene_use_new_shading_nodes(scene)) {
@@ -2344,7 +2366,8 @@ static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar,
glLoadMatrixf(rv3d->viewmat);
}
-void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy, float viewmat[][4], float winmat[][4])
+void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
+ int winx, int winy, float viewmat[][4], float winmat[][4])
{
RegionView3D *rv3d= ar->regiondata;
Base *base;
@@ -2469,13 +2492,15 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
glPopMatrix();
- glColor4ub(255, 255, 255, 255); // XXX, without this the sequencer flickers with opengl draw enabled, need to find out why - campbell
+ // XXX, without this the sequencer flickers with opengl draw enabled, need to find out why - campbell
+ glColor4ub(255, 255, 255, 255);
G.f &= ~G_RENDER_OGL;
}
/* utility func for ED_view3d_draw_offscreen */
-ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey, unsigned int flag, char err_out[256])
+ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar,
+ int sizex, int sizey, unsigned int flag, char err_out[256])
{
RegionView3D *rv3d= ar->regiondata;
ImBuf *ibuf;
@@ -2530,7 +2555,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in
}
/* creates own 3d views, used by the sequencer */
-ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256])
+ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int width, int height,
+ unsigned int flag, int drawtype, char err_out[256])
{
View3D v3d= {NULL};
ARegion ar= {NULL};
@@ -2889,6 +2915,7 @@ static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha
else if(U.uiflag & USER_SHOW_VIEWPORTNAME) {
draw_viewport_name(ar, v3d);
}
+
if (grid_unit) { /* draw below the viewport name */
char numstr[32]= "";
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 224df5b9f80..2620fe4ac71 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -208,10 +208,9 @@ static void view3d_boxview_clip(ScrArea *sa)
normal_tri_v3( clip[5],bb->vec[0], bb->vec[2], bb->vec[1]);
/* then plane equations */
- for(val=0; val<5; val++) {
- clip[val][3]= - clip[val][0]*bb->vec[val][0] - clip[val][1]*bb->vec[val][1] - clip[val][2]*bb->vec[val][2];
+ for(val=0; val<6; val++) {
+ clip[val][3] = -dot_v3v3(clip[val], bb->vec[val % 5]);
}
- clip[5][3]= - clip[5][0]*bb->vec[0][0] - clip[5][1]*bb->vec[0][1] - clip[5][2]*bb->vec[0][2];
/* create bounding box */
for(ar= sa->regionbase.first; ar; ar= ar->next) {
@@ -519,52 +518,54 @@ static void viewops_data_free(bContext *C, wmOperator *op)
static const float thres = 0.93f; //cos(20 deg);
-#define COS45 0.70710678118654746
+#define COS45 0.7071068
#define SIN45 COS45
-static float snapquats[39][5] = {
+#define NUM_SNAP_QUATS 39
+
+static const float snapquats[NUM_SNAP_QUATS][5] = {
/*{q0, q1, q3, q4, view}*/
- {COS45, -SIN45, 0.0, 0.0, RV3D_VIEW_FRONT}, //front
- {0.0, 0.0, -SIN45, -SIN45, RV3D_VIEW_BACK}, //back
- {1.0, 0.0, 0.0, 0.0, RV3D_VIEW_TOP}, //top
- {0.0, -1.0, 0.0, 0.0, RV3D_VIEW_BOTTOM}, //bottom
- {0.5, -0.5, -0.5, -0.5, RV3D_VIEW_RIGHT}, //left
- {0.5, -0.5, 0.5, 0.5, RV3D_VIEW_LEFT}, //right
+ {COS45, -SIN45, 0.0, 0.0, RV3D_VIEW_FRONT},
+ {0.0, 0.0, -SIN45, -SIN45, RV3D_VIEW_BACK},
+ {1.0, 0.0, 0.0, 0.0, RV3D_VIEW_TOP},
+ {0.0, -1.0, 0.0, 0.0, RV3D_VIEW_BOTTOM},
+ {0.5, -0.5, -0.5, -0.5, RV3D_VIEW_RIGHT},
+ {0.5, -0.5, 0.5, 0.5, RV3D_VIEW_LEFT},
/* some more 45 deg snaps */
- {0.65328145027160645, -0.65328145027160645, 0.27059805393218994, 0.27059805393218994, 0},
- {0.92387950420379639, 0.0, 0.0, 0.38268342614173889, 0},
- {0.0, -0.92387950420379639, 0.38268342614173889, 0.0, 0},
- {0.35355335474014282, -0.85355335474014282, 0.35355338454246521, 0.14644660055637360, 0},
- {0.85355335474014282, -0.35355335474014282, 0.14644660055637360, 0.35355338454246521, 0},
- {0.49999994039535522, -0.49999994039535522, 0.49999997019767761, 0.49999997019767761, 0},
- {0.27059802412986755, -0.65328145027160645, 0.65328145027160645, 0.27059802412986755, 0},
- {0.65328145027160645, -0.27059802412986755, 0.27059802412986755, 0.65328145027160645, 0},
- {0.27059799432754517, -0.27059799432754517, 0.65328139066696167, 0.65328139066696167, 0},
- {0.38268336653709412, 0.0, 0.0, 0.92387944459915161, 0},
- {0.0, -0.38268336653709412, 0.92387944459915161, 0.0, 0},
- {0.14644658565521240, -0.35355335474014282, 0.85355335474014282, 0.35355335474014282, 0},
- {0.35355335474014282, -0.14644658565521240, 0.35355335474014282, 0.85355335474014282, 0},
- {0.0, 0.0, 0.92387944459915161, 0.38268336653709412, 0},
- {-0.0, 0.0, 0.38268336653709412, 0.92387944459915161, 0},
- {-0.27059802412986755, 0.27059802412986755, 0.65328133106231689, 0.65328133106231689, 0},
- {-0.38268339633941650, 0.0, 0.0, 0.92387938499450684, 0},
- {0.0, 0.38268339633941650, 0.92387938499450684, 0.0, 0},
- {-0.14644658565521240, 0.35355338454246521, 0.85355329513549805, 0.35355332493782043, 0},
- {-0.35355338454246521, 0.14644658565521240, 0.35355332493782043, 0.85355329513549805, 0},
- {-0.49999991059303284, 0.49999991059303284, 0.49999985098838806, 0.49999985098838806, 0},
- {-0.27059799432754517, 0.65328145027160645, 0.65328139066696167, 0.27059799432754517, 0},
- {-0.65328145027160645, 0.27059799432754517, 0.27059799432754517, 0.65328139066696167, 0},
- {-0.65328133106231689, 0.65328133106231689, 0.27059793472290039, 0.27059793472290039, 0},
- {-0.92387932538986206, 0.0, 0.0, 0.38268333673477173, 0},
- {0.0, 0.92387932538986206, 0.38268333673477173, 0.0, 0},
- {-0.35355329513549805, 0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0},
- {-0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0.35355329513549805, 0},
- {-0.38268330693244934, 0.92387938499450684, 0.0, 0.0, 0},
- {-0.92387938499450684, 0.38268330693244934, 0.0, 0.0, 0},
- {-COS45, 0.0, 0.0, SIN45, 0},
- {COS45, 0.0, 0.0, SIN45, 0},
- {0.0, 0.0, 0.0, 1.0, 0}
+ { 0.6532815, -0.6532815, 0.2705981, 0.2705981, 0},
+ { 0.9238795, 0.0, 0.0, 0.3826834, 0},
+ { 0.0, -0.9238795, 0.3826834, 0.0, 0},
+ { 0.3535534, -0.8535534, 0.3535534, 0.1464466, 0},
+ { 0.8535534, -0.3535534, 0.1464466, 0.3535534, 0},
+ { 0.4999999, -0.4999999, 0.5, 0.5, 0},
+ { 0.2705980, -0.6532815, 0.6532815, 0.2705980, 0},
+ { 0.6532815, -0.2705980, 0.2705980, 0.6532815, 0},
+ { 0.2705978, -0.2705980, 0.6532814, 0.6532814, 0},
+ { 0.3826834, 0.0, 0.0, 0.9238794, 0},
+ { 0.0, -0.3826834, 0.9238794, 0.0, 0},
+ { 0.1464466, -0.3535534, 0.8535534, 0.3535534, 0},
+ { 0.3535534, -0.1464466, 0.3535534, 0.8535534, 0},
+ { 0.0, 0.0, 0.9238794, 0.3826834, 0},
+ {-0.0, 0.0, 0.3826834, 0.9238794, 0},
+ {-0.2705980, 0.2705980, 0.6532813, 0.6532813, 0},
+ {-0.3826834, 0.0, 0.0, 0.9238794, 0},
+ { 0.0, 0.3826834, 0.9238794, 0.0, 0},
+ {-0.1464466, 0.3535534, 0.8535533, 0.3535533, 0},
+ {-0.3535534, 0.1464466, 0.3535533, 0.8535533, 0},
+ {-0.4999999, 0.4999999, 0.4999999, 0.4999999, 0},
+ {-0.2705980, 0.6532815, 0.6532814, 0.2705980, 0},
+ {-0.6532815, 0.2705980, 0.2705980, 0.6532814, 0},
+ {-0.6532813, 0.6532813, 0.2705979, 0.2705979, 0},
+ {-0.9238793, 0.0, 0.0, 0.3826833, 0},
+ { 0.0, 0.9238793, 0.3826833, 0.0, 0},
+ {-0.3535533, 0.8535533, 0.3535533, 0.1464466, 0},
+ {-0.8535533, 0.3535533, 0.1464466, 0.3535533, 0},
+ {-0.3826833, 0.9238794, 0.0, 0.0, 0},
+ {-0.9238794, 0.3826833, 0.0, 0.0, 0},
+ {-COS45, 0.0, 0.0, SIN45, 0},
+ { COS45, 0.0, 0.0, SIN45, 0},
+ { 0.0, 0.0, 0.0, 1.0, 0}
};
enum {
@@ -725,7 +726,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y)
mul_qt_v3(viewquat_inv, zaxis);
- for (i = 0 ; i < 39; i++){
+ for (i = 0 ; i < NUM_SNAP_QUATS; i++){
float view = (int)snapquats[i][4];
float viewquat_inv_test[4];
@@ -921,6 +922,22 @@ static int view3d_camera_active_poll(bContext *C)
return 0;
}
+/* test for unlocked camera view in quad view */
+static int view3d_camera_user_poll(bContext *C)
+{
+ View3D *v3d;
+ ARegion *ar;
+
+ if (ED_view3d_context_user_region(C, &v3d, &ar)) {
+ RegionView3D *rv3d = ar->regiondata;
+ if(rv3d->persp==RV3D_CAMOB) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static int viewrotate_cancel(bContext *C, wmOperator *op)
{
viewops_data_free(C, op);
@@ -946,8 +963,9 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
}
-// NDOF utility functions
-// (should these functions live in this file?)
+/* NDOF utility functions
+ * (should these functions live in this file?)
+ */
float ndof_to_axis_angle(struct wmNDOFMotionData* ndof, float axis[3])
{
return ndof->dt * normalize_v3_v3(axis, ndof->rvec);
@@ -958,7 +976,7 @@ void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4])
float axis[3];
float angle;
- angle= ndof_to_axis_angle(ndof, axis);
+ angle = ndof_to_axis_angle(ndof, axis);
axis_angle_to_quat(q, axis, angle);
}
@@ -968,69 +986,67 @@ void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4])
*/
static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
- if (event->type != NDOF_MOTION) {
+ if (event->type != NDOF_MOTION)
return OPERATOR_CANCELLED;
- }
else {
- View3D *v3d= CTX_wm_view3d(C);
+ View3D *v3d = CTX_wm_view3d(C);
RegionView3D* rv3d = CTX_wm_region_view3d(C);
wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata;
ED_view3d_camera_lock_init(v3d, rv3d);
- rv3d->rot_angle = 0.f; // off by default, until changed later this function
+ rv3d->rot_angle = 0.f; /* off by default, until changed later this function */
if (ndof->progress != P_FINISHING) {
const float dt = ndof->dt;
-
- // tune these until everything feels right
+
+ /* tune these until everything feels right */
const float rot_sensitivity = 1.f;
const float zoom_sensitivity = 1.f;
const float pan_sensitivity = 1.f;
-
- // rather have bool, but...
- int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec);
-
+
+ const int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec);
+
float view_inv[4];
invert_qt_qt(view_inv, rv3d->viewquat);
-
- //#define DEBUG_NDOF_MOTION
+
+ /* #define DEBUG_NDOF_MOTION */
#ifdef DEBUG_NDOF_MOTION
printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n",
ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt);
#endif
-
- if (ndof->tvec[2]) {
- // Zoom!
- // velocity should be proportional to the linear velocity attained by rotational motion of same strength
- // [got that?]
- // proportional to arclength = radius * angle
-
- float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tvec[2];
+
+ if (ndof->tz) {
+ /* Zoom!
+ * velocity should be proportional to the linear velocity attained by rotational motion of same strength
+ * [got that?]
+ * proportional to arclength = radius * angle
+ */
+ float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
if (U.ndof_flag & NDOF_ZOOM_INVERT)
zoom_distance = -zoom_distance;
rv3d->dist += zoom_distance;
}
-
+
if (rv3d->viewlock == RV3D_LOCKED) {
/* rotation not allowed -- explore panning options instead */
- float pan_vec[3] = {ndof->tvec[0], ndof->tvec[1], 0.0f};
+ float pan_vec[3] = {ndof->tx, ndof->ty, 0.0f};
mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
-
+
/* transform motion from view to world coordinates */
invert_qt_qt(view_inv, rv3d->viewquat);
mul_qt_v3(view_inv, pan_vec);
-
+
/* move center of view opposite of hand motion (this is camera mode, not object mode) */
sub_v3_v3(rv3d->ofs, pan_vec);
}
-
+
if (has_rotation) {
-
+
rv3d->view = RV3D_VIEW_USER;
-
+
if (U.flag & USER_TRACKBALL) {
float rot[4];
float axis[3];
@@ -1045,44 +1061,46 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event
if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
axis[1] = -axis[1];
- // transform rotation axis from view to world coordinates
+ /* transform rotation axis from view to world coordinates */
mul_qt_v3(view_inv, axis);
-
- // update the onscreen doo-dad
+
+ /* update the onscreen doo-dad */
rv3d->rot_angle = angle;
copy_v3_v3(rv3d->rot_axis, axis);
-
+
axis_angle_to_quat(rot, axis, angle);
- // apply rotation
+ /* apply rotation */
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+
} else {
+
/* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
float angle, rot[4];
float xvec[3] = {1,0,0};
-
+
/* Determine the direction of the x vector (for rotating up and down) */
mul_qt_v3(view_inv, xvec);
-
+
/* Perform the up/down rotation */
- angle = rot_sensitivity * dt * ndof->rvec[0];
+ angle = rot_sensitivity * dt * ndof->rx;
if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
angle = -angle;
rot[0] = cos(angle);
mul_v3_v3fl(rot+1, xvec, sin(angle));
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
-
+
/* Perform the orbital rotation */
- angle = rot_sensitivity * dt * ndof->rvec[1];
+ angle = rot_sensitivity * dt * ndof->ry;
if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
angle = -angle;
-
- // update the onscreen doo-dad
+
+ /* update the onscreen doo-dad */
rv3d->rot_angle = angle;
rv3d->rot_axis[0] = 0;
rv3d->rot_axis[1] = 0;
rv3d->rot_axis[2] = 1;
-
+
rot[0] = cos(angle);
rot[1] = rot[2] = 0.0;
rot[3] = sin(angle);
@@ -1119,9 +1137,8 @@ void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot)
*/
static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
- if (event->type != NDOF_MOTION) {
+ if (event->type != NDOF_MOTION)
return OPERATOR_CANCELLED;
- }
else {
View3D *v3d= CTX_wm_view3d(C);
RegionView3D* rv3d = CTX_wm_region_view3d(C);
@@ -1129,13 +1146,13 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
ED_view3d_camera_lock_init(v3d, rv3d);
- rv3d->rot_angle = 0.f; // we're panning here! so erase any leftover rotation from other operators
+ rv3d->rot_angle = 0.f; /* we're panning here! so erase any leftover rotation from other operators */
if (ndof->progress != P_FINISHING) {
const float dt = ndof->dt;
float view_inv[4];
-#if 0 // ------------------------------------------- zoom with Z
- // tune these until everything feels right
+#if 0 /* ------------------------------------------- zoom with Z */
+ /* tune these until everything feels right */
const float zoom_sensitivity = 1.f;
const float pan_sensitivity = 1.f;
@@ -1143,18 +1160,18 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
ndof->tx, ndof->ty, 0
};
- // "zoom in" or "translate"? depends on zoom mode in user settings?
+ /* "zoom in" or "translate"? depends on zoom mode in user settings? */
if (ndof->tz) {
float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
rv3d->dist += zoom_distance;
}
-
+
mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
-#else // ------------------------------------------------------- dolly with Z
- float speed = 10.f; // blender units per second
- // ^^ this is ok for default cube scene, but should scale with.. something
+#else /* ------------------------------------------------------- dolly with Z */
+ float speed = 10.f; /* blender units per second */
+ /* ^^ this is ok for default cube scene, but should scale with.. something */
- // tune these until everything feels right
+ /* tune these until everything feels right */
const float forward_sensitivity = 1.f;
const float vertical_sensitivity = 0.4f;
const float lateral_sensitivity = 0.6f;
@@ -2075,8 +2092,8 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "center", 0, "Center", "");
}
-
-static int viewselected_exec(bContext *C, wmOperator *UNUSED(op)) /* like a localview without local!, was centerview() in 2.4x */
+/* like a localview without local!, was centerview() in 2.4x */
+static int viewselected_exec(bContext *C, wmOperator *UNUSED(op))
{
ARegion *ar= CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
@@ -2257,13 +2274,18 @@ void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was view3d_home() in 2.4x */
{
- ARegion *ar= CTX_wm_region(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
- View3D *v3d= CTX_wm_view3d(C);
Scene *scene= CTX_data_scene(C);
float xfac, yfac;
float size[2];
+ View3D *v3d;
+ ARegion *ar;
+ RegionView3D *rv3d;
+
+ /* no NULL check is needed, poll checks */
+ ED_view3d_context_user_region(C, &v3d, &ar);
+ rv3d = ar->regiondata;
+
rv3d->camdx= rv3d->camdy= 0.0f;
ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size);
@@ -2289,7 +2311,7 @@ void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
/* api callbacks */
ot->exec= view3d_center_camera_exec;
- ot->poll= view3d_camera_active_poll;
+ ot->poll= view3d_camera_user_poll;
/* flags */
ot->flag= 0;
@@ -2430,9 +2452,15 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* convert border to 3d coordinates */
- if (( !gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) ||
- ( !gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p_corner[0], &p_corner[1], &p_corner[2])))
+ if ( (!gluUnProject(cent[0], cent[1], depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport,
+ &p[0], &p[1], &p[2])) ||
+ (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport,
+ &p_corner[0], &p_corner[1], &p_corner[2])))
+ {
return OPERATOR_CANCELLED;
+ }
dvec[0] = p[0]-p_corner[0];
dvec[1] = p[1]-p_corner[1];
@@ -2453,7 +2481,10 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
new_dist = rv3d->dist;
/* convert the drawn rectangle into 3d space */
- if (depth_close!=FLT_MAX && gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) {
+ if (depth_close != FLT_MAX && gluUnProject(cent[0], cent[1], depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport,
+ &p[0], &p[1], &p[2]))
+ {
new_ofs[0] = -p[0];
new_ofs[1] = -p[1];
new_ofs[2] = -p[2];
@@ -2543,11 +2574,16 @@ static void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d)
static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene= CTX_data_scene(C);
- ARegion *ar= CTX_wm_region(C);
- view3d_set_1_to_1_viewborder(scene, ar, CTX_wm_view3d(C));
+ View3D *v3d;
+ ARegion *ar;
- WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
+ /* no NULL check is needed, poll checks */
+ ED_view3d_context_user_region(C, &v3d, &ar);
+
+ view3d_set_1_to_1_viewborder(scene, ar, v3d);
+
+ WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
return OPERATOR_FINISHED;
}
@@ -2561,7 +2597,7 @@ void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot)
/* api callbacks */
ot->exec= view3d_zoom_1_to_1_camera_exec;
- ot->poll= view3d_camera_active_poll;
+ ot->poll= view3d_camera_user_poll;
/* flags */
ot->flag= 0;
@@ -2582,7 +2618,9 @@ static EnumPropertyItem prop_view_items[] = {
/* would like to make this a generic function - outside of transform */
-static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, float q1, float q2, float q3, float q4, short view, int perspo, int align_active)
+static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
+ float q1, float q2, float q3, float q4,
+ short view, int perspo, int align_active)
{
RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
float new_quat[4];
@@ -2660,6 +2698,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
static int perspo = RV3D_PERSP;
int viewnum, align_active, nextperspo;
+ /* no NULL check is needed, poll checks */
ED_view3d_context_user_region(C, &v3d, &ar);
rv3d = ar->regiondata;
@@ -2680,27 +2719,33 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
switch (viewnum) {
case RV3D_VIEW_BOTTOM :
- axis_set_view(C, v3d, ar, 0.0, -1.0, 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.0, -1.0, 0.0, 0.0,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_BACK:
- axis_set_view(C, v3d, ar, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0),
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_LEFT:
- axis_set_view(C, v3d, ar, 0.5, -0.5, 0.5, 0.5, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.5, -0.5, 0.5, 0.5,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_TOP:
- axis_set_view(C, v3d, ar, 1.0, 0.0, 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 1.0, 0.0, 0.0, 0.0,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_FRONT:
- axis_set_view(C, v3d, ar, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_RIGHT:
- axis_set_view(C, v3d, ar, 0.5, -0.5, -0.5, -0.5, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.5, -0.5, -0.5, -0.5,
+ viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_CAMERA:
@@ -2762,7 +2807,9 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
else{
/* return to settings of last view */
/* does smooth_view too */
- axis_set_view(C, v3d, ar, rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3], rv3d->lview, rv3d->lpersp, 0);
+ axis_set_view(C, v3d, ar,
+ rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3],
+ rv3d->lview, rv3d->lpersp, 0);
}
}
break;
@@ -3194,6 +3241,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *eve
/* re initialize */
project_int_noclip(ar, fp, mval);
flip= initgrabz(rv3d, fp[0], fp[1], fp[2]);
+ (void)flip;
}
if(mval[0]!=IS_CLIPPED) {
@@ -3358,7 +3406,7 @@ static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int marg
}
/* XXX todo Zooms in on a border drawn by the user */
-int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3] ) //, float *autodist )
+int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3])
{
bglMats mats; /* ZBuffer depth vars */
float depth_close= FLT_MAX;
@@ -3376,8 +3424,11 @@ int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2]
cent[0] = (double)mval[0];
cent[1] = (double)mval[1];
- if (!gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+ if (!gluUnProject(cent[0], cent[1], depth_close,
+ mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+ {
return 0;
+ }
mouse_worldloc[0] = (float)p[0];
mouse_worldloc[1] = (float)p[1];
@@ -3401,7 +3452,8 @@ int ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode) //
}
// no 4x4 sampling, run view_autodist_init first
-int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth) //, float *autodist )
+int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3],
+ int margin, float *force_depth) //, float *autodist )
{
bglMats mats; /* ZBuffer depth vars, could cache? */
float depth;
@@ -3420,8 +3472,12 @@ int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldl
cent[1] = (double)mval[1];
bgl_get_mats(&mats);
- if (!gluUnProject(cent[0], cent[1], depth, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+
+ if (!gluUnProject(cent[0], cent[1], depth,
+ mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
+ {
return 0;
+ }
mouse_worldloc[0] = (float)p[0];
mouse_worldloc[1] = (float)p[1];
@@ -3456,7 +3512,8 @@ static int depth_segment_cb(int x, int y, void *userData)
}
}
-int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth)
+int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2],
+ int margin, float *depth)
{
struct { struct ARegion *ar; int margin; float depth; } data = {NULL};
int p1[2];
diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c
index 981d46774dc..801f2d5c8eb 100644
--- a/source/blender/editors/space_view3d/view3d_fly.c
+++ b/source/blender/editors/space_view3d/view3d_fly.c
@@ -135,7 +135,8 @@ void fly_modal_keymap(wmKeyConfig *keyconf)
WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_DECELERATE);
WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_PAN_ENABLE);
- WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PAN_DISABLE); /* XXX - Bug in the event system, middle mouse release doesnt work */
+ /* XXX - Bug in the event system, middle mouse release doesnt work */
+ WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PAN_DISABLE);
/* WASD */
WM_modalkeymap_add_item(keymap, WKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_FORWARD);
@@ -170,7 +171,8 @@ typedef struct FlyInfo {
short state;
short redraw;
unsigned char use_precision;
- unsigned char use_freelook; /* if the user presses shift they can look about without movinf the direction there looking */
+ unsigned char use_freelook; /* if the user presses shift they can look about
+ * without moving the direction there looking */
int mval[2]; /* latest 2D mouse values */
wmNDOFMotionData* ndof; /* latest 3D mouse values */
@@ -195,7 +197,8 @@ typedef struct FlyInfo {
/* backup values */
float dist_backup; /* backup the views distance since we use a zero dist for fly mode */
float ofs_backup[3]; /* backup the views offset incase the user cancels flying in non camera mode */
- float rot_backup[4]; /* backup the views quat incase the user cancels flying in non camera mode. (quat for view, eul for camera) */
+ float rot_backup[4]; /* backup the views quat incase the user cancels flying in non camera mode.
+ * (quat for view, eul for camera) */
short persp_backup; /* remember if were ortho or not, only used for restoring the view if it was a ortho view */
short is_ortho_cam; /* are we flying an ortho camera in perspective view,
@@ -580,7 +583,8 @@ static void flyEvent(FlyInfo *fly, wmEvent *event)
/* impliment WASD keys */
case FLY_MODAL_DIR_FORWARD:
if (fly->speed < 0.0f) fly->speed= -fly->speed; /* flip speed rather than stopping, game like motion */
- else if (fly->axis==2) fly->speed += fly->grid; /* increse like mousewheel if were already moving in that difection*/
+ else if (fly->axis==2) fly->speed += fly->grid; /* increse like mousewheel if were already
+ * moving in that difection*/
fly->axis= 2;
break;
case FLY_MODAL_DIR_BACKWARD:
@@ -738,8 +742,10 @@ static int flyApply(bContext *C, FlyInfo *fly)
xmargin, ymargin; /* x and y margin are define the safe area where the mouses movement wont rotate the view */
#ifdef NDOF_FLY_DEBUG
- static unsigned int iteration = 1;
- printf("fly timer %d\n", iteration++);
+ {
+ static unsigned int iteration = 1;
+ printf("fly timer %d\n", iteration++);
+ }
#endif
@@ -782,7 +788,11 @@ static int flyApply(bContext *C, FlyInfo *fly)
}
/* Should we redraw? */
- if (fly->speed != 0.0f || moffset[0] || moffset[1] || fly->zlock || fly->xlock || dvec[0] || dvec[1] || dvec[2] ) {
+ if ( (fly->speed != 0.0f) ||
+ moffset[0] || moffset[1] ||
+ fly->zlock || fly->xlock ||
+ dvec[0] || dvec[1] || dvec[2])
+ {
float dvec_tmp[3];
double time_current; /*time how fast it takes for us to redraw, this is so simple scenes dont fly too fast */
float time_redraw;
@@ -792,7 +802,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
#endif
time_current= PIL_check_seconds_timer();
time_redraw= (float)(time_current - fly->time_lastdraw);
- time_redraw_clamped= MIN2(0.05f, time_redraw); /* clamt the redraw time to avoid jitter in roll correction */
+ time_redraw_clamped= MIN2(0.05f, time_redraw); /* clamp redraw time to avoid jitter in roll correction */
fly->time_lastdraw= time_current;
/*fprintf(stderr, "%f\n", time_redraw);*/ /* 0.002 is a small redraw 0.02 is larger */
@@ -818,7 +828,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
mul_v3_fl(dvec_tmp, time_redraw * 200.0f * fly->grid);
}
else {
- float roll; /* similar to the angle between the camera's up and the Z-up, but its very rough so just roll*/
+ float roll; /* similar to the angle between the camera's up and the Z-up,
+ * but its very rough so just roll*/
/* rotate about the X axis- look up/down */
if (moffset[1]) {
@@ -826,7 +837,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
upvec[1]=0;
upvec[2]=0;
mul_m3_v3(mat, upvec);
- axis_angle_to_quat( tmp_quat, upvec, (float)moffset[1] * time_redraw * -FLY_ROTATE_FAC); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat( tmp_quat, upvec, (float)moffset[1] * time_redraw * -FLY_ROTATE_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
if (fly->xlock) fly->xlock = 2; /*check for rotation*/
@@ -859,7 +871,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
mul_m3_v3(mat, upvec);
}
- axis_angle_to_quat(tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat(tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
if (fly->xlock) fly->xlock = 2;/*check for rotation*/
@@ -880,7 +893,9 @@ static int flyApply(bContext *C, FlyInfo *fly)
upvec[2]= 1.0f;
mul_m3_v3(mat, upvec);
- axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->zlock_momentum * FLY_ZUP_CORRECT_FAC); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat(tmp_quat, upvec,
+ roll * time_redraw_clamped * fly->zlock_momentum * FLY_ZUP_CORRECT_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL;
@@ -906,7 +921,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
mul_m3_v3(mat, upvec);
- axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->xlock_momentum*0.1f); /* Rotate about the relative up vec */
+ /* Rotate about the relative up vec */
+ axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->xlock_momentum*0.1f);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
fly->xlock_momentum += 0.05f;
@@ -949,18 +965,6 @@ static int flyApply(bContext *C, FlyInfo *fly)
add_v3_v3(rv3d->ofs, dvec);
- /* todo, dynamic keys */
-#if 0
- if (fly->zlock && fly->xlock)
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X on/Z on, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
- else if (fly->zlock)
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X off/Z on, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
- else if (fly->xlock)
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X on/Z off, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
- else
- ED_area_headerprint(fly->ar, "FlyKeys Speed:(+/- | Wheel), Upright Axis:X off/Z off, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB");
-#endif
-
if (rv3d->persp==RV3D_CAMOB)
move_camera(C, rv3d, fly, (fly->xlock || fly->zlock || moffset[0] || moffset[1]), fly->speed);
diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c
index 315da0423d1..00bb8d16943 100644
--- a/source/blender/editors/space_view3d/view3d_header.c
+++ b/source/blender/editors/space_view3d/view3d_header.c
@@ -230,7 +230,7 @@ static int view3d_layers_invoke(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_PASS_THROUGH;
if(event->shift)
- RNA_boolean_set(op->ptr, "extend", 1);
+ RNA_boolean_set(op->ptr, "extend", TRUE);
if(event->alt) {
int nr= RNA_int_get(op->ptr, "nr") + 10;
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index e7c9a1bd3a0..f6c82b0ba9d 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -164,7 +164,8 @@ void VIEW3D_OT_game_start(struct wmOperatorType *ot);
int ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[][4], struct BoundBox *bb);
-void smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *, float *ofs, float *quat, float *dist, float *lens);
+void smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *,
+ float *ofs, float *quat, float *dist, float *lens);
void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); /* rect: for picking */
void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d);
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index 4594544b4f8..759f3edf20f 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -121,7 +121,7 @@ void view3d_keymap(wmKeyConfig *keyconf)
keymap= WM_keymap_find(keyconf, "3D View", SPACE_VIEW3D, 0);
kmi = WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", 1);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
/*
* Doesn't work with KM_SHIFT, have to use KM_ANY and filter in invoke
* */
@@ -160,8 +160,11 @@ void view3d_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_camera_1_to_1", PADENTER, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_camera", HOMEKEY, KM_PRESS, 0, 0); /* only with camera view */
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0)->ptr, "center", 0); /* only without camera view */
- RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1);
+
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "center", FALSE); /* only without camera view */
+ kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "center", TRUE);
/* numpad view hotkeys*/
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA);
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index ce93ca56a65..1b153d03e45 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -257,7 +257,9 @@ static int view3d_selectable_data(bContext *C)
if (ob->mode & OB_MODE_SCULPT) {
return 0;
}
- if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) {
+ if ((ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) &&
+ !paint_facesel_test(ob) && !paint_vertsel_test(ob))
+ {
return 0;
}
}
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c
index 6bc1b3acce6..3665b0b13c3 100644
--- a/source/blender/editors/space_view3d/view3d_snap.c
+++ b/source/blender/editors/space_view3d/view3d_snap.c
@@ -505,7 +505,6 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
if(pchan->bone->layer & arm->layer) {
if((pchan->bone->flag & BONE_CONNECTED)==0) {
float nLoc[3];
- float inv_restmat[4][4];
/* get nearest grid point to snap to */
copy_v3_v3(nLoc, pchan->pose_mat[3]);
@@ -517,9 +516,8 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
/* Back in object space... */
mul_m4_v3(ob->imat, vec);
- /* get location of grid point in *rest* bone-space */
- invert_m4_m4(inv_restmat, pchan->bone->arm_mat);
- mul_m4_v3(inv_restmat, vec);
+ /* Get location of grid point in pose space. */
+ armature_loc_pose_to_bone(pchan, vec, vec);
/* adjust location */
if ((pchan->protectflag & OB_LOCK_LOCX)==0)
@@ -642,12 +640,9 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op))
if(pchan->bone->flag & BONE_SELECTED) {
if(pchan->bone->layer & arm->layer) {
if((pchan->bone->flag & BONE_CONNECTED)==0) {
- float inv_restmat[4][4];
-
- /* get location of cursor in *rest* bone-space */
- invert_m4_m4(inv_restmat, pchan->bone->arm_mat);
- mul_m4_v3(inv_restmat, vec);
-
+ /* Get position in pchan (pose) space. */
+ armature_loc_pose_to_bone(pchan, vec, vec);
+
/* copy new position */
if ((pchan->protectflag & OB_LOCK_LOCX)==0)
pchan->loc[0]= vec[0];
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 11492ee7804..f57d8a5ec1b 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -120,7 +120,8 @@ struct SmoothViewStore {
/* will start timer if appropriate */
/* the arguments are the desired situation */
-void smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera, float *ofs, float *quat, float *dist, float *lens)
+void smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera,
+ float *ofs, float *quat, float *dist, float *lens)
{
wmWindowManager *wm= CTX_wm_manager(C);
wmWindow *win= CTX_wm_window(C);
@@ -998,7 +999,8 @@ int ED_view3d_clip_range_get(View3D *v3d, RegionView3D *rv3d, float *clipsta, fl
}
/* also exposed in previewrender.c */
-int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy, rctf *viewplane, float *clipsta, float *clipend)
+int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy,
+ rctf *viewplane, float *clipsta, float *clipend)
{
CameraParams params;
@@ -1023,7 +1025,12 @@ void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect) /* rect: for pick
orth= ED_view3d_viewplane_get(v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend);
rv3d->is_persp= !orth;
- // printf("%d %d %f %f %f %f %f %f\n", winx, winy, viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax, clipsta, clipend);
+#if 0
+ printf("%s: %d %d %f %f %f %f %f %f\n", __func__, winx, winy,
+ viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax,
+ clipsta, clipend);
+#endif
+
x1= viewplane.xmin;
y1= viewplane.ymin;
x2= viewplane.xmax;
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 44dc909314a..0563cc3adf5 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -515,7 +515,7 @@ static short apply_targetless_ik(Object *ob)
static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, TransData *td)
{
Bone *bone= pchan->bone;
- float pmat[3][3], omat[3][3], bmat[3][3];
+ float pmat[3][3], omat[3][3];
float cmat[3][3], tmat[3][3];
float vec[3];
@@ -569,39 +569,71 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
copy_qt_qt(td->ext->iquat, pchan->quat);
}
td->ext->rotOrder= pchan->rotmode;
-
+
/* proper way to get parent transform + own transform + constraints transform */
copy_m3_m4(omat, ob->obmat);
+ /* New code, using "generic" pchan_to_pose_mat(). */
+ {
+ float rotscale_mat[4][4], loc_mat[4][4];
+
+ pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+ if (t->mode == TFM_TRANSLATION)
+ copy_m3_m4(pmat, loc_mat);
+ else
+ copy_m3_m4(pmat, rotscale_mat);
+
+ if (constraints_list_needinv(t, &pchan->constraints)) {
+ copy_m3_m4(tmat, pchan->constinv);
+ invert_m3_m3(cmat, tmat);
+ mul_serie_m3(td->mtx, pmat, omat, cmat, NULL,NULL,NULL,NULL,NULL);
+ }
+ else
+ mul_serie_m3(td->mtx, pmat, omat, NULL, NULL,NULL,NULL,NULL,NULL);
+ }
+
+ /* XXX Old code. Will remove it later. */
+#if 0
if (ELEM(t->mode, TFM_TRANSLATION, TFM_RESIZE) && (pchan->bone->flag & BONE_NO_LOCAL_LOCATION))
unit_m3(bmat);
else
copy_m3_m3(bmat, pchan->bone->bone_mat);
if (pchan->parent) {
- if(pchan->bone->flag & BONE_HINGE)
+ if(pchan->bone->flag & BONE_HINGE) {
copy_m3_m4(pmat, pchan->parent->bone->arm_mat);
- else
+ if(!(pchan->bone->flag & BONE_NO_SCALE)) {
+ float tsize[3], tsmat[3][3];
+ mat4_to_size(tsize, pchan->parent->pose_mat);
+ size_to_mat3(tsmat, tsize);
+ mul_m3_m3m3(pmat, tsmat, pmat);
+ }
+ }
+ else {
copy_m3_m4(pmat, pchan->parent->pose_mat);
+ if(pchan->bone->flag & BONE_NO_SCALE)
+ normalize_m3(pmat);
+ }
if (constraints_list_needinv(t, &pchan->constraints)) {
copy_m3_m4(tmat, pchan->constinv);
invert_m3_m3(cmat, tmat);
- mul_serie_m3(td->mtx, bmat, pmat, omat, cmat, NULL,NULL,NULL,NULL); // dang mulserie swaps args
+ mul_serie_m3(td->mtx, bmat, pmat, omat, cmat, NULL,NULL,NULL,NULL);
}
else
- mul_serie_m3(td->mtx, bmat, pmat, omat, NULL,NULL,NULL,NULL,NULL); // dang mulserie swaps args
+ mul_serie_m3(td->mtx, bmat, pmat, omat, NULL,NULL,NULL,NULL,NULL);
}
else {
if (constraints_list_needinv(t, &pchan->constraints)) {
copy_m3_m4(tmat, pchan->constinv);
invert_m3_m3(cmat, tmat);
- mul_serie_m3(td->mtx, bmat, omat, cmat, NULL,NULL,NULL,NULL,NULL); // dang mulserie swaps args
+ mul_serie_m3(td->mtx, bmat, omat, cmat, NULL,NULL,NULL,NULL,NULL);
}
else
- mul_m3_m3m3(td->mtx, omat, bmat); // Mat3MulMat3 has swapped args!
+ mul_m3_m3m3(td->mtx, omat, bmat);
}
+# endif
invert_m3_m3(td->smtx, td->mtx);
@@ -2268,6 +2300,18 @@ void flushTransSeq(TransInfo *t)
seq_prev= seq;
}
+
+ if (ELEM(t->mode, TFM_SEQ_SLIDE, TFM_TIME_TRANSLATE)) { /* originally TFM_TIME_EXTEND, transform changes */
+ /* Special annoying case here, need to calc metas with TFM_TIME_EXTEND only */
+ seq= seqbasep->first;
+
+ while(seq) {
+ if (seq->type == SEQ_META && seq->flag & SELECT)
+ calc_sequence(t->scene, seq);
+ seq= seq->next;
+ }
+ }
+
/* need to do the overlap check in a new loop otherwise adjacent strips
* will not be updated and we'll get false positives */
seq_prev= NULL;
@@ -2287,17 +2331,6 @@ void flushTransSeq(TransInfo *t)
}
seq_prev= seq;
}
-
- if (t->mode == TFM_SEQ_SLIDE) { /* originally TFM_TIME_EXTEND, transform changes */
- /* Special annoying case here, need to calc metas with TFM_TIME_EXTEND only */
- seq= seqbasep->first;
-
- while(seq) {
- if (seq->type == SEQ_META && seq->flag & SELECT)
- calc_sequence(t->scene, seq);
- seq= seq->next;
- }
- }
}
/* ********************* UV ****************** */
@@ -5297,7 +5330,15 @@ static void createTransNodeData(bContext *C, TransInfo *t)
/* *** CLIP EDITOR *** */
+enum {
+ transDataTracking_ModeTracks = 0,
+ transDataTracking_ModeCurves = 1,
+} transDataTracking_Mode;
+
typedef struct TransDataTracking {
+ int mode, flag;
+
+ /* tracks transformation from main window */
int area;
float *relative, *loc;
float soffset[2], srelative[2];
@@ -5306,6 +5347,10 @@ typedef struct TransDataTracking {
float (*smarkers)[2];
int markersnr;
MovieTrackingMarker *markers;
+
+ /* marker transformation from curves editor */
+ float *prev_pos, scale;
+ short coord;
} TransDataTracking;
static void markerToTransDataInit(TransData *td, TransData2D *td2d,
@@ -5313,6 +5358,8 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d,
{
int anchor = area==TRACK_AREA_POINT && off;
+ tdt->mode = transDataTracking_ModeTracks;
+
if(anchor) {
td2d->loc[0] = rel[0]; /* hold original location */
td2d->loc[1] = rel[1];
@@ -5367,8 +5414,7 @@ static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
{
MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
- track->transflag= marker->flag;
-
+ tdt->flag= marker->flag;
marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, track->offset, marker->pos, track->offset);
@@ -5397,7 +5443,7 @@ static void transDataTrackingFree(TransInfo *t)
}
}
-static void createTransTrackingData(bContext *C, TransInfo *t)
+static void createTransTrackingTracksData(bContext *C, TransInfo *t)
{
TransData *td;
TransData2D *td2d;
@@ -5409,11 +5455,6 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
TransDataTracking *tdt;
int framenr = sc->user.framenr;
- if(!clip || !BKE_movieclip_has_frame(clip, &sc->user)) {
- t->total = 0;
- return;
- }
-
/* count */
t->total = 0;
@@ -5422,13 +5463,11 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
if(TRACK_VIEW_SELECTED(sc, track) && (track->flag&TRACK_LOCKED)==0) {
marker= BKE_tracking_get_marker(track, framenr);
- if(marker) {
- t->total++; /* offset */
+ t->total++; /* offset */
- if(track->flag&SELECT) t->total++;
- if(track->pat_flag&SELECT) t->total+= 2;
- if(track->search_flag&SELECT) t->total+= 2;
- }
+ if(track->flag&SELECT) t->total++;
+ if(track->pat_flag&SELECT) t->total+= 2;
+ if(track->search_flag&SELECT) t->total+= 2;
}
track = track->next;
@@ -5478,6 +5517,194 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
}
}
+static void markerToTransCurveDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
+ MovieTrackingMarker *marker, MovieTrackingMarker *prev_marker,
+ short coord, float size)
+{
+ float frames_delta = (marker->framenr - prev_marker->framenr);
+
+ tdt->flag = marker->flag;
+ marker->flag &= ~MARKER_TRACKED;
+
+ tdt->mode = transDataTracking_ModeCurves;
+ tdt->coord = coord;
+ tdt->scale = 1.0f / size * frames_delta;
+ tdt->prev_pos = prev_marker->pos;
+
+ /* calculate values depending on marker's speed */
+ td2d->loc[0] = marker->framenr;
+ td2d->loc[1] = (marker->pos[coord] - prev_marker->pos[coord]) * size / frames_delta;
+ td2d->loc[2] = 0.0f;
+
+ td2d->loc2d = marker->pos; /* current location */
+
+ td->flag = 0;
+ td->loc = td2d->loc;
+ VECCOPY(td->center, td->loc);
+ VECCOPY(td->iloc, td->loc);
+
+ memset(td->axismtx, 0, sizeof(td->axismtx));
+ td->axismtx[2][2] = 1.0f;
+
+ td->ext= NULL; td->val= NULL;
+
+ td->flag |= TD_SELECTED;
+ td->dist= 0.0;
+
+ unit_m3(td->mtx);
+ unit_m3(td->smtx);
+}
+
+static void createTransTrackingCurvesData(bContext *C, TransInfo *t)
+{
+ TransData *td;
+ TransData2D *td2d;
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip(sc);
+ ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker, *prev_marker;
+ TransDataTracking *tdt;
+ int i, width, height;
+
+ BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+
+ /* count */
+ t->total = 0;
+
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ for(i = 1; i < track->markersnr; i++) {
+ marker = &track->markers[i];
+ prev_marker = &track->markers[i-1];
+
+ if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+ continue;
+
+ if(marker->flag & MARKER_GRAPH_SEL_X)
+ t->total += 1;
+
+ if(marker->flag & MARKER_GRAPH_SEL_Y)
+ t->total += 1;
+ }
+ }
+
+ track = track->next;
+ }
+
+ if(t->total==0)
+ return;
+
+ td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransTracking TransData");
+ td2d = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransTracking TransData2D");
+ tdt = t->customData = MEM_callocN(t->total*sizeof(TransDataTracking), "TransTracking TransDataTracking");
+
+ t->customFree = transDataTrackingFree;
+
+ /* create actual data */
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ for(i = 1; i < track->markersnr; i++) {
+ marker = &track->markers[i];
+ prev_marker = &track->markers[i-1];
+
+ if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+ continue;
+
+ if(marker->flag & MARKER_GRAPH_SEL_X) {
+ markerToTransCurveDataInit(td, td2d, tdt, marker, &track->markers[i-1], 0, width);
+ td += 1;
+ td2d += 1;
+ tdt += 1;
+ }
+
+ if(marker->flag & MARKER_GRAPH_SEL_Y) {
+ markerToTransCurveDataInit(td, td2d, tdt, marker, &track->markers[i-1], 1, height);
+
+ td += 1;
+ td2d += 1;
+ tdt += 1;
+ }
+ }
+ }
+
+ track = track->next;
+ }
+}
+
+static void createTransTrackingData(bContext *C, TransInfo *t)
+{
+ ARegion *ar = CTX_wm_region(C);
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip(sc);
+
+ if(!clip || !BKE_movieclip_has_frame(clip, &sc->user)) {
+ t->total = 0;
+ return;
+ }
+
+ if(ar->regiontype == RGN_TYPE_PREVIEW) {
+ /* transformation was called from graph editor */
+ createTransTrackingCurvesData(C, t);
+ }
+ else {
+ createTransTrackingTracksData(C, t);
+ }
+}
+
+static void cancelTransTracking(TransInfo *t)
+{
+ TransDataTracking *tdt = t->customData;
+ SpaceClip *sc= t->sa->spacedata.first;
+ MovieClip *clip= ED_space_clip(sc);
+ ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
+ MovieTrackingTrack *track;
+ MovieTrackingMarker *marker;
+ int a, framenr = sc->user.framenr;
+
+ if(tdt->mode == transDataTracking_ModeTracks) {
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ marker = BKE_tracking_get_marker(track, framenr);
+ marker->flag = tdt->flag;
+
+ tdt++;
+
+ if(track->flag&SELECT) tdt++;
+ if(track->pat_flag&SELECT) tdt += 2;
+ if(track->search_flag&SELECT) tdt += 2;
+ }
+
+ track = track->next;
+ }
+ }
+ else if(tdt->mode == transDataTracking_ModeCurves) {
+ MovieTrackingMarker *prev_marker;
+
+ track = tracksbase->first;
+ while(track) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+ for(a = 1; a < track->markersnr; a++) {
+ marker = &track->markers[a];
+ prev_marker = &track->markers[a-1];
+
+ if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+ continue;
+
+ if(marker->flag & (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y)) {
+ marker->flag = tdt->flag;
+ }
+ }
+ }
+
+ track = track->next;
+ }
+ }
+}
+
void flushTransTracking(TransInfo *t)
{
TransData *td;
@@ -5485,36 +5712,44 @@ void flushTransTracking(TransInfo *t)
TransDataTracking *tdt;
int a;
+ if(t->state == TRANS_CANCEL)
+ cancelTransTracking(t);
+
/* flush to 2d vector from internally used 3d vector */
for(a=0, td= t->data, td2d= t->data2d, tdt= t->customData; a<t->total; a++, td2d++, td++, tdt++) {
- if(t->flag&T_ALT_TRANSFORM) {
- if(tdt->area==TRACK_AREA_POINT && tdt->relative) {
- float d[2], d2[2];
-
- if(!tdt->smarkers) {
- tdt->smarkers= MEM_callocN(sizeof(*tdt->smarkers)*tdt->markersnr, "flushTransTracking markers");
- for(a= 0; a<tdt->markersnr; a++)
- copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos);
- }
+ if(tdt->mode == transDataTracking_ModeTracks) {
+ if(t->flag&T_ALT_TRANSFORM) {
+ if(tdt->area==TRACK_AREA_POINT && tdt->relative) {
+ float d[2], d2[2];
+
+ if(!tdt->smarkers) {
+ tdt->smarkers= MEM_callocN(sizeof(*tdt->smarkers)*tdt->markersnr, "flushTransTracking markers");
+ for(a= 0; a<tdt->markersnr; a++)
+ copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos);
+ }
- sub_v2_v2v2(d, td2d->loc, tdt->soffset);
- sub_v2_v2(d, tdt->srelative);
+ sub_v2_v2v2(d, td2d->loc, tdt->soffset);
+ sub_v2_v2(d, tdt->srelative);
- sub_v2_v2v2(d2, td2d->loc, tdt->srelative);
+ sub_v2_v2v2(d2, td2d->loc, tdt->srelative);
- for(a= 0; a<tdt->markersnr; a++)
- add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
+ for(a= 0; a<tdt->markersnr; a++)
+ add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
- negate_v2_v2(td2d->loc2d, d);
+ negate_v2_v2(td2d->loc2d, d);
+ }
}
- }
- if(tdt->area!=TRACK_AREA_POINT || tdt->relative==0) {
- td2d->loc2d[0] = td2d->loc[0];
- td2d->loc2d[1] = td2d->loc[1];
+ if(tdt->area!=TRACK_AREA_POINT || tdt->relative==0) {
+ td2d->loc2d[0] = td2d->loc[0];
+ td2d->loc2d[1] = td2d->loc[1];
- if(tdt->relative)
- sub_v2_v2(td2d->loc2d, tdt->relative);
+ if(tdt->relative)
+ sub_v2_v2(td2d->loc2d, tdt->relative);
+ }
+ }
+ else if(tdt->mode == transDataTracking_ModeCurves) {
+ td2d->loc2d[tdt->coord] = tdt->prev_pos[tdt->coord] + td2d->loc[1] * tdt->scale;
}
}
}
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index fff683b1ef6..3c019c1680f 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -644,24 +644,11 @@ static void recalcData_clip(TransInfo *t)
ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
MovieTrackingTrack *track;
- if(t->state == TRANS_CANCEL) {
- track= tracksbase->first;
- while(track) {
- if(TRACK_VIEW_SELECTED(sc, track)) {
- MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
-
- marker->flag= track->transflag;
- }
-
- track= track->next;
- }
- }
-
flushTransTracking(t);
track= tracksbase->first;
while(track) {
- if(TRACK_VIEW_SELECTED(sc, track)) {
+ if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
if (t->mode == TFM_TRANSLATION) {
if(TRACK_AREA_SELECTED(track, TRACK_AREA_PAT))
BKE_tracking_clamp_track(track, CLAMP_PAT_POS);
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index b7aba109cdd..1843768bcd7 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -843,7 +843,7 @@ void transform_operatortypes(void)
void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
{
- wmKeyMapItem *km;
+ wmKeyMapItem *kmi;
wmKeyMap *modalmap;
/* transform.c, only adds modal map once, checks if it's there */
@@ -879,71 +879,71 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
- km = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
- RNA_boolean_set(km->ptr, "use", 1);
+ kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "use", TRUE);
WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(km->ptr, "data_path", "tool_settings.use_snap");
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
WM_keymap_add_item(keymap, "TRANSFORM_OT_snap_type", TABKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
- km = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(km->ptr, "texture_space", 1);
+ kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
- km = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
- RNA_boolean_set(km->ptr, "texture_space", 1);
+ kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
break;
case SPACE_ACTION:
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_SCALE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_SLIDE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
break;
case SPACE_IPO:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
break;
case SPACE_NLA:
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TRANSLATION);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TRANSLATION);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_SCALE);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
break;
case SPACE_NODE:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
- km= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_A, KM_ANY, 0, 0);
- RNA_boolean_set(km->ptr, "release_confirm", 1);
- km= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
- RNA_boolean_set(km->ptr, "release_confirm", 1);
+ kmi= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_A, KM_ANY, 0, 0);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
+ kmi= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
+ RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
@@ -954,8 +954,8 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
- km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
- RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
+ kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
break;
case SPACE_IMAGE:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
@@ -970,8 +970,8 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_string_set(km->ptr, "data_path", "tool_settings.use_snap");
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
break;
case SPACE_CLIP:
WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/uvedit/CMakeLists.txt b/source/blender/editors/uvedit/CMakeLists.txt
index ce078c2b1f1..a747c2ac6bd 100644
--- a/source/blender/editors/uvedit/CMakeLists.txt
+++ b/source/blender/editors/uvedit/CMakeLists.txt
@@ -39,6 +39,7 @@ set(SRC
uvedit_draw.c
uvedit_ops.c
uvedit_parametrizer.c
+ uvedit_smart_stitch.c
uvedit_unwrap_ops.c
uvedit_intern.h
diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c
index 0da3f66fc6f..6ced91f0d01 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -380,12 +380,9 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFac
}
}
-static void draw_uvs_other(Scene *scene, Object *obedit, MTFace *activetf)
+static void draw_uvs_other(Scene *scene, Object *obedit, Image *curimage)
{
Base *base;
- Image *curimage;
-
- curimage= (activetf)? activetf->tpage: NULL;
glColor3ub(96, 96, 96);
@@ -419,6 +416,34 @@ static void draw_uvs_other(Scene *scene, Object *obedit, MTFace *activetf)
}
}
+static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob)
+{
+ Mesh *me= ob->data;
+ Image *curimage = ED_space_image(sima);
+
+ if(sima->flag & SI_DRAW_OTHER)
+ draw_uvs_other(scene, ob, curimage);
+
+ glColor3ub(112, 112, 112);
+
+ if(me->mtface) {
+ MFace *mface= me->mface;
+ MTFace *tface= me->mtface;
+ int a;
+
+ for(a=me->totface; a>0; a--, tface++, mface++) {
+ if(tface->tpage == curimage) {
+ glBegin(GL_LINE_LOOP);
+ glVertex2fv(tface->uv[0]);
+ glVertex2fv(tface->uv[1]);
+ glVertex2fv(tface->uv[2]);
+ if(mface->v4) glVertex2fv(tface->uv[3]);
+ glEnd();
+ }
+ }
+ }
+}
+
/* draws uv's in the image space */
static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
{
@@ -432,6 +457,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
float pointsize;
int drawfaces, interpedges;
Image *ima= sima->image;
+ StitchPreviewer *stitch_preview = uv_get_stitch_previewer();
em= BKE_mesh_get_editmesh(me);
activetf= EM_get_active_mtface(em, &efa_act, NULL, 0); /* will be set to NULL if hidden */
@@ -445,8 +471,11 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
interpedges= (ts->uv_selectmode == UV_SELECT_VERTEX);
/* draw other uvs */
- if(sima->flag & SI_DRAW_OTHER)
- draw_uvs_other(scene, obedit, activetf);
+ if(sima->flag & SI_DRAW_OTHER) {
+ Image *curimage= (activetf)? activetf->tpage: NULL;
+
+ draw_uvs_other(scene, obedit, curimage);
+ }
/* 1. draw shadow mesh */
@@ -522,7 +551,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
}
}
-
+
/* 3. draw active face stippled */
if(activetf) {
@@ -831,24 +860,81 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
bglEnd();
}
+ /* finally draw stitch preview */
+ if(stitch_preview) {
+ glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ glEnable(GL_BLEND);
+
+ UI_ThemeColor4(TH_STITCH_PREVIEW_ACTIVE);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_tris);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris*3);
+
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_quads);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_static_quads*4);
+
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_tris);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+ /*UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);*/
+
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_quads);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+ /*UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);*/
+
+ glDisable(GL_BLEND);
+
+ /* draw vert preview */
+ glPointSize(pointsize*2.0);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_STITCHABLE);
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_stitchable);
+ glDrawArrays(GL_POINTS, 0, stitch_preview->num_stitchable);
+
+ UI_ThemeColor4(TH_STITCH_PREVIEW_UNSTITCHABLE);
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_unstitchable);
+ glDrawArrays(GL_POINTS, 0, stitch_preview->num_unstitchable);
+
+ glPopClientAttrib();
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ }
+
glPointSize(1.0);
BKE_mesh_end_editmesh(obedit->data, em);
}
-void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit)
+void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit, Object *obact)
{
- int show_uvedit, show_uvshadow;
+ ToolSettings *toolsettings = scene->toolsettings;
+ int show_uvedit, show_uvshadow, show_texpaint_uvshadow;
+ show_texpaint_uvshadow = (obact && obact->type == OB_MESH && obact->mode == OB_MODE_TEXTURE_PAINT);
show_uvedit= ED_space_image_show_uvedit(sima, obedit);
show_uvshadow= ED_space_image_show_uvshadow(sima, obedit);
- if(show_uvedit || show_uvshadow) {
+ if(show_uvedit || show_uvshadow || show_texpaint_uvshadow) {
if(show_uvshadow)
draw_uvs_shadow(obedit);
- else
+ else if(show_uvedit)
draw_uvs(sima, scene, obedit);
+ else
+ draw_uvs_texpaint(sima, scene, obact);
- if(show_uvedit)
+ if(show_uvedit && !(toolsettings->use_uv_sculpt))
drawcursor_sima(sima, ar);
}
}
diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h
index 7d83f529d92..ef25159a3af 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -32,25 +32,74 @@
#ifndef ED_UVEDIT_INTERN_H
#define ED_UVEDIT_INTERN_H
-struct SpaceImage;
struct EditFace;
-struct MTFace;
-struct Scene;
+struct EditMesh;
struct Image;
+struct MTFace;
struct Object;
+struct Scene;
+struct SpaceImage;
+struct UvElementMap;
struct wmOperatorType;
/* id can be from 0 to 3 */
#define TF_PIN_MASK(id) (TF_PIN1 << id)
#define TF_SEL_MASK(id) (TF_SEL1 << id)
-
/* geometric utilities */
+
void uv_center(float uv[][2], float cent[2], int quad);
float uv_area(float uv[][2], int quad);
void uv_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy);
+/* find nearest */
+
+typedef struct NearestHit {
+ struct EditFace *efa;
+ struct MTFace *tf;
+
+ int vert, uv;
+ int edge, vert2;
+} NearestHit;
+
+void uv_find_nearest_vert(struct Scene *scene, struct Image *ima, struct EditMesh *em, float co[2], float penalty[2], struct NearestHit *hit);
+void uv_find_nearest_edge(struct Scene *scene, struct Image *ima, struct EditMesh *em, float co[2], struct NearestHit *hit);
+
+/* utility tool functions */
+
+struct UvElement *ED_get_uv_element(struct UvElementMap *map, struct EditFace *efa, int index);
+void uvedit_live_unwrap_update(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit);
+
+/* smart stitch */
+
+/* object that stores display data for previewing before accepting stitching */
+typedef struct StitchPreviewer {
+ /* OpenGL requires different calls for Triangles and Quads.
+ * here we'll store the quads of the mesh */
+ float *preview_quads;
+ /* ...and here we'll store the triangles*/
+ float *preview_tris;
+ /* preview data. These will be either the previewed vertices or edges depending on stitch mode settings */
+ float *preview_stitchable;
+ float *preview_unstitchable;
+ /* here we'll store the number of triangles and quads to be drawn */
+ unsigned int num_tris;
+ unsigned int num_quads;
+ unsigned int num_stitchable;
+ unsigned int num_unstitchable;
+
+ /* store static island Quads */
+ float *static_quads;
+ /* ...and here we'll store the triangles*/
+ float *static_tris;
+ unsigned int num_static_tris;
+ unsigned int num_static_quads;
+} StitchPreviewer;
+
+StitchPreviewer *uv_get_stitch_previewer(void);
+
/* operators */
+
void UV_OT_average_islands_scale(struct wmOperatorType *ot);
void UV_OT_cube_project(struct wmOperatorType *ot);
void UV_OT_cylinder_project(struct wmOperatorType *ot);
@@ -60,6 +109,7 @@ void UV_OT_pack_islands(struct wmOperatorType *ot);
void UV_OT_reset(struct wmOperatorType *ot);
void UV_OT_sphere_project(struct wmOperatorType *ot);
void UV_OT_unwrap(struct wmOperatorType *ot);
+void UV_OT_stitch(struct wmOperatorType *ot);
#endif /* ED_UVEDIT_INTERN_H */
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 7d56d5c479f..5f836ec4ca7 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -20,7 +20,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): none yet.
+ * Contributor(s): Antony Riakiotakis.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -94,6 +94,28 @@ int ED_uvedit_test(Object *obedit)
return ret;
}
+static int ED_operator_uvedit_can_uv_sculpt(struct bContext *C)
+{
+ SpaceImage *sima= CTX_wm_space_image(C);
+ ToolSettings *toolsettings = CTX_data_tool_settings(C);
+ Object *obedit= CTX_data_edit_object(C);
+
+ return ED_space_image_show_uvedit(sima, obedit) && !(toolsettings->use_uv_sculpt);
+}
+
+static int UNUSED_FUNCTION(ED_operator_uvmap_mesh)(bContext *C)
+{
+ Object *ob= CTX_data_active_object(C);
+
+ if(ob && ob->type==OB_MESH) {
+ Mesh *me = ob->data;
+
+ if(CustomData_get_layer(&me->fdata, CD_MTFACE) != NULL)
+ return 1;
+ }
+
+ return 0;
+}
/**************************** object active image *****************************/
static int is_image_texture_node(bNode *node)
@@ -400,7 +422,7 @@ void uvedit_uv_deselect(Scene *scene, EditFace *efa, MTFace *tf, int i)
/*********************** live unwrap utilities ***********************/
-static void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
+void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
{
if(sima && (sima->flag & SI_LIVE_UNWRAP)) {
ED_uvedit_live_unwrap_begin(scene, obedit);
@@ -527,15 +549,7 @@ static int uvedit_center(Scene *scene, Image *ima, Object *obedit, float *cent,
/************************** find nearest ****************************/
-typedef struct NearestHit {
- EditFace *efa;
- MTFace *tf;
-
- int vert, uv;
- int edge, vert2;
-} NearestHit;
-
-static void find_nearest_uv_edge(Scene *scene, Image *ima, EditMesh *em, float co[2], NearestHit *hit)
+void uv_find_nearest_edge(Scene *scene, Image *ima, EditMesh *em, float co[2], NearestHit *hit)
{
MTFace *tf;
EditFace *efa;
@@ -633,7 +647,7 @@ static int nearest_uv_between(MTFace *tf, int nverts, int id, float co[2], float
return (c1*c2 >= 0.0f);
}
-static void find_nearest_uv_vert(Scene *scene, Image *ima, EditMesh *em, float co[2], float penalty[2], NearestHit *hit)
+void uv_find_nearest_vert(Scene *scene, Image *ima, EditMesh *em, float co[2], float penalty[2], NearestHit *hit)
{
EditFace *efa;
EditVert *eve;
@@ -750,6 +764,17 @@ static UvMapVert *uv_vertex_map_get(UvVertMap *vmap, EditFace *efa, int a)
return NULL;
}
+UvElement *ED_get_uv_element(UvElementMap *map, EditFace *efa, int index)
+{
+ UvElement *element = map->vert[(*(&efa->v1 + index))->tmp.l];
+
+ for(; element; element = element->next)
+ if(element->face == efa)
+ return element;
+
+ return NULL;
+}
+
static int uv_edge_tag_faces(UvMapVert *first1, UvMapVert *first2, int *totface)
{
UvMapVert *iterv1, *iterv2;
@@ -1296,197 +1321,6 @@ static void UV_OT_weld(wmOperatorType *ot)
ot->poll= ED_operator_uvedit;
}
-/* ******************** stitch operator **************** */
-
-/* just for averaging UVs */
-typedef struct UVVertAverage {
- float uv[2];
- int count;
-} UVVertAverage;
-
-static int stitch_exec(bContext *C, wmOperator *op)
-{
- SpaceImage *sima;
- Scene *scene;
- Object *obedit;
- EditMesh *em;
- EditFace *efa;
- EditVert *eve;
- Image *ima;
- MTFace *tf;
-
- scene= CTX_data_scene(C);
- obedit= CTX_data_edit_object(C);
- em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
- ima= CTX_data_edit_image(C);
- sima= CTX_wm_space_image(C);
-
- if(RNA_boolean_get(op->ptr, "use_limit")) {
- UvVertMap *vmap;
- UvMapVert *vlist, *iterv;
- float newuv[2], limit[2];
- int a, vtot;
-
- limit[0]= RNA_float_get(op->ptr, "limit");
- limit[1]= limit[0];
-
- EM_init_index_arrays(em, 0, 0, 1);
- vmap= EM_make_uv_vert_map(em, 1, 0, limit);
-
- if(vmap == NULL) {
- BKE_mesh_end_editmesh(obedit->data, em);
- return OPERATOR_CANCELLED;
- }
-
- for(a=0, eve= em->verts.first; eve; a++, eve= eve->next) {
- vlist= EM_get_uv_map_vert(vmap, a);
-
- while(vlist) {
- newuv[0]= 0; newuv[1]= 0;
- vtot= 0;
-
- for(iterv=vlist; iterv; iterv=iterv->next) {
- if((iterv != vlist) && iterv->separate)
- break;
-
- efa = EM_get_face_for_index(iterv->f);
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_uv_selected(scene, efa, tf, iterv->tfindex)) {
- newuv[0] += tf->uv[iterv->tfindex][0];
- newuv[1] += tf->uv[iterv->tfindex][1];
- vtot++;
- }
- }
-
- if(vtot > 1) {
- newuv[0] /= vtot; newuv[1] /= vtot;
-
- for(iterv=vlist; iterv; iterv=iterv->next) {
- if((iterv != vlist) && iterv->separate)
- break;
-
- efa = EM_get_face_for_index(iterv->f);
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_uv_selected(scene, efa, tf, iterv->tfindex)) {
- tf->uv[iterv->tfindex][0]= newuv[0];
- tf->uv[iterv->tfindex][1]= newuv[1];
- }
- }
- }
-
- vlist= iterv;
- }
- }
-
- EM_free_uv_vert_map(vmap);
- EM_free_index_arrays();
- }
- else {
- UVVertAverage *uv_average, *uvav;
- int count;
-
- // index and count verts
- for(count=0, eve=em->verts.first; eve; count++, eve= eve->next)
- eve->tmp.l = count;
-
- uv_average= MEM_callocN(sizeof(UVVertAverage)*count, "Stitch");
-
- // gather uv averages per vert
- for(efa= em->faces.first; efa; efa= efa->next) {
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_face_visible(scene, ima, efa, tf)) {
- if(uvedit_uv_selected(scene, efa, tf, 0)) {
- uvav = uv_average + efa->v1->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[0][0];
- uvav->uv[1] += tf->uv[0][1];
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 1)) {
- uvav = uv_average + efa->v2->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[1][0];
- uvav->uv[1] += tf->uv[1][1];
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 2)) {
- uvav = uv_average + efa->v3->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[2][0];
- uvav->uv[1] += tf->uv[2][1];
- }
-
- if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
- uvav = uv_average + efa->v4->tmp.l;
- uvav->count++;
- uvav->uv[0] += tf->uv[3][0];
- uvav->uv[1] += tf->uv[3][1];
- }
- }
- }
-
- // apply uv welding
- for(efa= em->faces.first; efa; efa= efa->next) {
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-
- if(uvedit_face_visible(scene, ima, efa, tf)) {
- if(uvedit_uv_selected(scene, efa, tf, 0)) {
- uvav = uv_average + efa->v1->tmp.l;
- tf->uv[0][0] = uvav->uv[0]/uvav->count;
- tf->uv[0][1] = uvav->uv[1]/uvav->count;
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 1)) {
- uvav = uv_average + efa->v2->tmp.l;
- tf->uv[1][0] = uvav->uv[0]/uvav->count;
- tf->uv[1][1] = uvav->uv[1]/uvav->count;
- }
-
- if(uvedit_uv_selected(scene, efa, tf, 2)) {
- uvav = uv_average + efa->v3->tmp.l;
- tf->uv[2][0] = uvav->uv[0]/uvav->count;
- tf->uv[2][1] = uvav->uv[1]/uvav->count;
- }
-
- if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
- uvav = uv_average + efa->v4->tmp.l;
- tf->uv[3][0] = uvav->uv[0]/uvav->count;
- tf->uv[3][1] = uvav->uv[1]/uvav->count;
- }
- }
- }
-
- MEM_freeN(uv_average);
- }
-
- uvedit_live_unwrap_update(sima, scene, obedit);
- DAG_id_tag_update(obedit->data, 0);
- WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
- BKE_mesh_end_editmesh(obedit->data, em);
- return OPERATOR_FINISHED;
-}
-
-static void UV_OT_stitch(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name= "Stitch";
- ot->description= "Stitch selected UV vertices by proximity";
- ot->idname= "UV_OT_stitch";
- ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
- /* api callbacks */
- ot->exec= stitch_exec;
- ot->poll= ED_operator_uvedit;
-
- /* properties */
- RNA_def_boolean(ot->srna, "use_limit", 1, "Use Limit", "Stitch UVs within a specified limit distance");
- RNA_def_float(ot->srna, "limit", 0.01f, 0.0f, FLT_MAX, "Limit", "Limit distance in normalized coordinates", -FLT_MAX, FLT_MAX);
-}
-
/* ******************** (de)select all operator **************** */
static void select_all_perform(bContext *C, int action)
@@ -1660,7 +1494,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
/* find nearest element */
if(loop) {
/* find edge */
- find_nearest_uv_edge(scene, ima, em, co, &hit);
+ uv_find_nearest_edge(scene, ima, em, co, &hit);
if(hit.efa == NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
return OPERATOR_CANCELLED;
@@ -1668,7 +1502,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
}
else if(selectmode == UV_SELECT_VERTEX) {
/* find vertex */
- find_nearest_uv_vert(scene, ima, em, co, penalty, &hit);
+ uv_find_nearest_vert(scene, ima, em, co, penalty, &hit);
if(hit.efa == NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
return OPERATOR_CANCELLED;
@@ -1683,7 +1517,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
}
else if(selectmode == UV_SELECT_EDGE) {
/* find edge */
- find_nearest_uv_edge(scene, ima, em, co, &hit);
+ uv_find_nearest_edge(scene, ima, em, co, &hit);
if(hit.efa == NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
return OPERATOR_CANCELLED;
@@ -1723,7 +1557,7 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
else hitv[3]= 0xFFFFFFFF;
}
else if(selectmode == UV_SELECT_ISLAND) {
- find_nearest_uv_vert(scene, ima, em, co, NULL, &hit);
+ uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
if(hit.efa==NULL) {
BKE_mesh_end_editmesh(obedit->data, em);
@@ -2015,7 +1849,7 @@ static int select_linked_internal(bContext *C, wmOperator *op, wmEvent *event, i
RNA_float_get_array(op->ptr, "location", co);
}
- find_nearest_uv_vert(scene, ima, em, co, NULL, &hit);
+ uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
hit_p= &hit;
}
@@ -3312,6 +3146,180 @@ static void UV_OT_tile_set(wmOperatorType *ot)
RNA_def_int_vector(ot->srna, "tile", 2, NULL, 0, INT_MAX, "Tile", "Tile coordinate", 0, 10);
}
+
+static int seams_from_islands_exec(bContext *C, wmOperator *op)
+{
+ UvVertMap *vmap;
+ Object *ob = CTX_data_edit_object(C);
+ Mesh *me= (Mesh*)ob->data;
+ EditMesh *em;
+ EditEdge *editedge;
+ float limit[2] = {STD_UV_CONNECT_LIMIT, STD_UV_CONNECT_LIMIT};
+ char mark_seams = RNA_boolean_get(op->ptr, "mark_seams");
+ char mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp");
+
+ em = BKE_mesh_get_editmesh(me);
+
+ if(!EM_texFaceCheck(em)) {
+ BKE_mesh_end_editmesh(ob->data, em);
+ return OPERATOR_CANCELLED;
+ }
+
+ /* This code sets editvert->tmp.l to the index. This will be useful later on. */
+ EM_init_index_arrays(em, 0, 0, 1);
+ vmap = EM_make_uv_vert_map(em, 0, 0, limit);
+
+ for(editedge = em->edges.first; editedge; editedge = editedge->next) {
+ /* flags to determine if we uv is separated from first editface match */
+ char separated1 = 0, separated2;
+ /* set to denote edge must be flagged as seam */
+ char faces_separated = 0;
+ /* flag to keep track if uv1 is disconnected from first editface match */
+ char v1coincident = 1;
+ /* For use with v1coincident. v1coincident will change only if we've had commonFaces */
+ int commonFaces = 0;
+
+ EditFace *efa1, *efa2;
+
+ UvMapVert *mv1, *mvinit1, *mv2, *mvinit2, *mviter;
+ /* mv2cache stores the first of the list of coincident uv's for later comparison
+ * mv2sep holds the last separator and is copied to mv2cache when a hit is first found */
+ UvMapVert *mv2cache = NULL, *mv2sep = NULL;
+
+ mvinit1 = vmap->vert[editedge->v1->tmp.l];
+ if(mark_seams)
+ editedge->seam = 0;
+
+ for(mv1 = mvinit1; mv1 && !faces_separated; mv1 = mv1->next) {
+ if(mv1->separate && commonFaces)
+ v1coincident = 0;
+
+ separated2 = 0;
+ efa1 = EM_get_face_for_index(mv1->f);
+ mvinit2 = vmap->vert[editedge->v2->tmp.l];
+
+ for(mv2 = mvinit2; mv2; mv2 = mv2->next) {
+ if(mv2->separate)
+ mv2sep = mv2;
+
+ efa2 = EM_get_face_for_index(mv2->f);
+ if(efa1 == efa2) {
+ /* if v1 is not coincident no point in comparing */
+ if(v1coincident) {
+ /* have we found previously anything? */
+ if(mv2cache) {
+ /* flag seam unless proved to be coincident with previous hit */
+ separated2 = 1;
+ for(mviter = mv2cache; mviter; mviter = mviter->next) {
+ if(mviter->separate && mviter != mv2cache)
+ break;
+ /* coincident with previous hit, do not flag seam */
+ if(mviter == mv2)
+ separated2 = 0;
+ }
+ }
+ /* First hit case, store the hit in the cache */
+ else {
+ mv2cache = mv2sep;
+ commonFaces = 1;
+ }
+ }
+ else
+ separated1 = 1;
+
+ if(separated1 || separated2) {
+ faces_separated = 1;
+ break;
+ }
+ }
+ }
+ }
+
+ if(faces_separated) {
+ if(mark_seams)
+ editedge->seam = 1;
+ if(mark_sharp)
+ editedge->sharp = 1;
+ }
+ }
+
+ me->drawflag |= ME_DRAWSEAMS;
+
+ EM_free_uv_vert_map(vmap);
+ EM_free_index_arrays();
+ BKE_mesh_end_editmesh(me, em);
+
+ DAG_id_tag_update(&me->id, 0);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
+
+ return OPERATOR_FINISHED;
+}
+
+
+static void UV_OT_seams_from_islands(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Seams From Islands";
+ ot->description= "Set mesh seams according to island setup in the UV editor";
+ ot->idname= "UV_OT_seams_from_islands";
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* api callbacks */
+ ot->exec= seams_from_islands_exec;
+ ot->poll= ED_operator_uvedit;
+
+ RNA_def_boolean(ot->srna, "mark_seams", 1, "Mark Seams", "Mark boundary edges as seams");
+ RNA_def_boolean(ot->srna, "mark_sharp", 0, "Mark Sharp", "Mark boundary edges as sharp");
+}
+
+static int mark_seam_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = CTX_data_edit_object(C);
+ Scene *scene = CTX_data_scene(C);
+ Mesh *me= (Mesh*)ob->data;
+ EditMesh *em= BKE_mesh_get_editmesh(me);
+ EditFace *efa;
+
+ for(efa = em->faces.first; efa; efa = efa->next) {
+ MTFace *mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ int i, nverts = efa->v4? 4 : 3;
+
+ for(i = 0; i < nverts; i++)
+ if(uvedit_edge_selected(scene, efa, mt, i))
+ (*(&efa->e1 + i))->seam = 1;
+ }
+
+ me->drawflag |= ME_DRAWSEAMS;
+
+ if(scene->toolsettings->edge_mode_live_unwrap)
+ ED_unwrap_lscm(scene, ob, FALSE);
+
+ BKE_mesh_end_editmesh(me, em);
+
+ DAG_id_tag_update(&me->id, 0);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
+
+ return OPERATOR_FINISHED;
+}
+
+static void UV_OT_mark_seam(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Mark Seams";
+ ot->description= "Mark selected UV edges as seams";
+ ot->idname= "UV_OT_mark_seam";
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* api callbacks */
+ ot->exec= mark_seam_exec;
+ ot->poll= ED_operator_uvedit;
+}
+
+
/* ************************** registration **********************************/
void ED_operatortypes_uvedit(void)
@@ -3331,6 +3339,8 @@ void ED_operatortypes_uvedit(void)
WM_operatortype_append(UV_OT_align);
WM_operatortype_append(UV_OT_stitch);
+ WM_operatortype_append(UV_OT_seams_from_islands);
+ WM_operatortype_append(UV_OT_mark_seam);
WM_operatortype_append(UV_OT_weld);
WM_operatortype_append(UV_OT_pin);
@@ -3357,7 +3367,14 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
wmKeyMapItem *kmi;
keymap= WM_keymap_find(keyconf, "UV Editor", 0, 0);
- keymap->poll= ED_operator_uvedit;
+ keymap->poll= ED_operator_uvedit_can_uv_sculpt;
+
+ /* Uv sculpt toggle */
+ kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
+
+ /* Mark edge seam */
+ WM_keymap_add_item(keymap, "UV_OT_mark_seam", EKEY, KM_PRESS, KM_CTRL, 0);
/* pick selection */
RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select", SELECTMOUSE, KM_PRESS, 0, 0)->ptr, "extend", FALSE);
@@ -3366,8 +3383,11 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_loop", SELECTMOUSE, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "extend", TRUE);
/* border/circle selection */
- WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "pinned", 1);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "pinned", FALSE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "pinned", TRUE);
+
WM_keymap_add_item(keymap, "UV_OT_circle_select", CKEY, KM_PRESS, 0, 0);
/* selection manipulation */
@@ -3377,16 +3397,21 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE);
WM_keymap_add_item(keymap, "UV_OT_unlink_selected", LKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "UV_OT_select_all", AKEY, KM_PRESS, 0, 0);
- RNA_enum_set(WM_keymap_add_item(keymap, "UV_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "action", SEL_INVERT);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_all", AKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
+
WM_keymap_add_item(keymap, "UV_OT_select_pinned", PKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_weldalign", WKEY, KM_PRESS, 0, 0);
/* uv operations */
WM_keymap_add_item(keymap, "UV_OT_stitch", VKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, KM_ALT, 0)->ptr, "clear", 1);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "clear", FALSE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, KM_ALT, 0);
+ RNA_boolean_set(kmi->ptr, "clear", TRUE);
/* unwrap */
WM_keymap_add_item(keymap, "UV_OT_unwrap", EKEY, KM_PRESS, 0, 0);
@@ -3395,8 +3420,11 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "UV_OT_average_islands_scale", AKEY, KM_PRESS, KM_CTRL, 0);
/* hide */
- WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "unselected", TRUE);
+
WM_keymap_add_item(keymap, "UV_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
/* cursor */
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 7ad573231c9..d651a17b624 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -91,7 +91,7 @@ typedef struct PVert {
} u;
struct PEdge *edge;
- float *co;
+ float co[3];
float uv[2];
unsigned char flag;
@@ -655,11 +655,15 @@ static void p_face_backup_uvs(PFace *f)
{
PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next;
- if (e1->orig_uv && e2->orig_uv && e3->orig_uv) {
+ if (e1->orig_uv) {
e1->old_uv[0] = e1->orig_uv[0];
e1->old_uv[1] = e1->orig_uv[1];
+ }
+ if (e2->orig_uv) {
e2->old_uv[0] = e2->orig_uv[0];
e2->old_uv[1] = e2->orig_uv[1];
+ }
+ if (e3->orig_uv) {
e3->old_uv[0] = e3->orig_uv[0];
e3->old_uv[1] = e3->orig_uv[1];
}
@@ -669,11 +673,15 @@ static void p_face_restore_uvs(PFace *f)
{
PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next;
- if (e1->orig_uv && e2->orig_uv && e3->orig_uv) {
+ if (e1->orig_uv) {
e1->orig_uv[0] = e1->old_uv[0];
e1->orig_uv[1] = e1->old_uv[1];
+ }
+ if (e2->orig_uv) {
e2->orig_uv[0] = e2->old_uv[0];
e2->orig_uv[1] = e2->old_uv[1];
+ }
+ if (e3->orig_uv) {
e3->orig_uv[0] = e3->old_uv[0];
e3->orig_uv[1] = e3->old_uv[1];
}
@@ -684,7 +692,7 @@ static void p_face_restore_uvs(PFace *f)
static PVert *p_vert_add(PHandle *handle, PHashKey key, float *co, PEdge *e)
{
PVert *v = (PVert*)BLI_memarena_alloc(handle->arena, sizeof *v);
- v->co = co;
+ copy_v3_v3(v->co, co);
v->u.key = key;
v->edge = e;
v->flag = 0;
@@ -708,7 +716,7 @@ static PVert *p_vert_copy(PChart *chart, PVert *v)
{
PVert *nv = (PVert*)BLI_memarena_alloc(chart->handle->arena, sizeof *nv);
- nv->co = v->co;
+ copy_v3_v3(nv->co, v->co);
nv->uv[0] = v->uv[0];
nv->uv[1] = v->uv[1];
nv->u.key = v->u.key;
diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c
new file mode 100644
index 00000000000..3731d348522
--- /dev/null
+++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c
@@ -0,0 +1,1467 @@
+/*
+ * ***** 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) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Antony Riakiotakis.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/uvedit/uvedit_stitch.c
+ * \ingroup eduv
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_object_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_scene_types.h"
+
+#include "BLI_editVert.h"
+#include "BLI_ghash.h"
+#include "BLI_math.h"
+#include "BLI_math_vector.h"
+#include "BLI_string.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mesh.h"
+
+#include "ED_mesh.h"
+#include "ED_uvedit.h"
+#include "ED_screen.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "UI_view2d.h"
+
+#include "uvedit_intern.h"
+
+/* ********************** smart stitch operator *********************** */
+
+
+struct IslandStitchData;
+
+/* This is a straightforward implementation, count the uv's in the island that will move and take the mean displacement/rotation and apply it to all
+ * elements of the island except from the stitchable */
+typedef struct IslandStitchData{
+ /* rotation can be used only for edges, for vertices there is no such notion */
+ float rotation;
+ float translation[2];
+ /* Used for rotation, the island will rotate around this point */
+ float medianPoint[2];
+ int numOfElements;
+ int num_rot_elements;
+ /* flag to remember if island has been added for preview */
+ char addedForPreview;
+ /* flag an island to be considered for determining static island */
+ char stitchableCandidate;
+ /* if edge rotation is used, flag so that vertex rotation is not used */
+ char use_edge_rotation;
+}IslandStitchData;
+
+/* just for averaging UVs */
+typedef struct UVVertAverage {
+ float uv[2];
+ unsigned short count;
+} UVVertAverage;
+
+typedef struct UvEdge {
+ /* index to uv buffer */
+ unsigned int uv1;
+ unsigned int uv2;
+ /* general use flag (Used to check if edge is boundary here, and propagates to adjacency elements) */
+ char flag;
+ /* element that guarantees element->face has the face on element->tfindex and element->tfindex+1 is the second uv */
+ UvElement *element;
+}UvEdge;
+
+
+/* stitch state object */
+typedef struct StitchState {
+ /* use limit flag */
+ char use_limit;
+ /* limit to operator, same as original operator */
+ float limit_dist;
+ /* snap uv islands together during stitching */
+ char snap_islands;
+ /* stich at midpoints or at islands */
+ char midpoints;
+ /* editmesh, cached for use in modal handler */
+ EditMesh *em;
+ /* element map for getting info about uv connectivity */
+ UvElementMap *element_map;
+ /* edge container */
+ UvEdge *uvedges;
+ /* container of first of a group of coincident uvs, these will be operated upon */
+ UvElement **uvs;
+ /* maps uvelements to their first coincident uv */
+ int *map;
+ /* 2D normals per uv to calculate rotation for snapping */
+ float *normals;
+ /* edge storage */
+ UvEdge *edges;
+
+ /* count of separate uvs and edges */
+ int total_boundary_edges;
+ int total_separate_uvs;
+ /* hold selection related information */
+ UvElement **selection_stack;
+ int selection_size;
+ /* island that stays in place */
+ int static_island;
+ /* store number of primitives per face so that we can allocate the active island buffer later */
+ unsigned int *quads_per_island;
+ unsigned int *tris_per_island;
+} StitchState;
+
+
+/*
+ * defines for UvElement flags
+ */
+#define STITCH_SELECTED 1
+#define STITCH_STITCHABLE 2
+#define STITCH_PROCESSED 4
+#define STITCH_BOUNDARY 8
+#define STITCH_STITCHABLE_CANDIDATE 16
+
+#define STITCH_NO_PREVIEW -1
+
+/* previewer stuff (see uvedit_intern.h for more info) */
+static StitchPreviewer *_stitch_preview;
+
+/* constructor */
+static StitchPreviewer * stitch_preview_init(void)
+{
+ _stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), "stitch_previewer");
+ _stitch_preview->preview_quads = NULL;
+ _stitch_preview->preview_tris = NULL;
+ _stitch_preview->preview_stitchable = NULL;
+ _stitch_preview->preview_unstitchable = NULL;
+
+ _stitch_preview->num_quads = 0;
+ _stitch_preview->num_tris = 0;
+ _stitch_preview->num_stitchable = 0;
+ _stitch_preview->num_unstitchable = 0;
+
+ _stitch_preview->static_quads = NULL;
+ _stitch_preview->static_tris = NULL;
+
+ _stitch_preview->num_static_tris = 0;
+ _stitch_preview->num_static_quads = 0;
+
+ return _stitch_preview;
+}
+
+/* destructor...yeah this should be C++ :) */
+static void stitch_preview_delete(void)
+{
+ if(_stitch_preview)
+ {
+ if(_stitch_preview->preview_quads){
+ MEM_freeN(_stitch_preview->preview_quads);
+ _stitch_preview->preview_quads = NULL;
+ }
+ if(_stitch_preview->preview_tris){
+ MEM_freeN(_stitch_preview->preview_tris);
+ _stitch_preview->preview_tris = NULL;
+ }
+ if(_stitch_preview->preview_stitchable){
+ MEM_freeN(_stitch_preview->preview_stitchable);
+ _stitch_preview->preview_stitchable = NULL;
+ }
+ if(_stitch_preview->preview_unstitchable){
+ MEM_freeN(_stitch_preview->preview_unstitchable);
+ _stitch_preview->preview_unstitchable = NULL;
+ }
+ if(_stitch_preview->static_quads){
+ MEM_freeN(_stitch_preview->static_quads);
+ _stitch_preview->static_quads = NULL;
+ }
+ if(_stitch_preview->static_tris){
+ MEM_freeN(_stitch_preview->static_tris);
+ _stitch_preview->static_tris = NULL;
+ }
+ MEM_freeN(_stitch_preview);
+ _stitch_preview = NULL;
+ }
+}
+
+
+/* "getter method" */
+StitchPreviewer *uv_get_stitch_previewer(void)
+{
+ return _stitch_preview;
+}
+
+#define HEADER_LENGTH 256
+
+/* This function updates the header of the UV editor when the stitch tool updates its settings */
+static void stitch_update_header(StitchState *stitch_state, bContext *C)
+{
+ static char str[] = "(S)nap %s, (M)idpoints %s, (L)imit %.2f (Alt Wheel adjust) %s, Switch (I)sland, shift select vertices";
+
+ char msg[HEADER_LENGTH];
+ ScrArea *sa= CTX_wm_area(C);
+
+ if(sa) {
+ BLI_snprintf(msg, HEADER_LENGTH, str,
+ stitch_state->snap_islands? "On" : "Off",
+ stitch_state->midpoints? "On": "Off",
+ stitch_state->limit_dist,
+ stitch_state->use_limit? "On" : "Off");
+
+ ED_area_headerprint(sa, msg);
+ }
+}
+
+static int getNumOfIslandUvs(UvElementMap *elementMap, int island){
+ if(island == elementMap->totalIslands-1){
+ return elementMap->totalUVs - elementMap->islandIndices[island];
+ }else{
+ return elementMap->islandIndices[island+1] - elementMap->islandIndices[island];
+ }
+}
+
+static void stitch_uv_rotate(float rotation, float medianPoint[2], float uv[2]){
+ float uv_rotation_result[2];
+
+ uv[0] -= medianPoint[0];
+ uv[1] -= medianPoint[1];
+
+ uv_rotation_result[0] = cos(rotation)*uv[0] - sin(rotation)*uv[1];
+ uv_rotation_result[1] = sin(rotation)*uv[0] + cos(rotation)*uv[1];
+
+ uv[0] = uv_rotation_result[0] + medianPoint[0];
+ uv[1] = uv_rotation_result[1] + medianPoint[1];
+}
+
+static int stitch_check_uvs_stitchable(UvElement *element, UvElement *element_iter, StitchState *state){
+ float limit;
+ int do_limit;
+
+ if(element_iter == element){
+ return 0;
+ }
+
+ limit = state->limit_dist;
+ do_limit = state->use_limit;
+
+ if(do_limit){
+ MTFace *mtface_orig = CustomData_em_get(&state->em->fdata, element->face->data, CD_MTFACE);
+ MTFace *mtface_iter = CustomData_em_get(&state->em->fdata, element_iter->face->data, CD_MTFACE);
+
+ if(fabs(mtface_orig->uv[element->tfindex][0] - mtface_iter->uv[element_iter->tfindex][0]) < limit
+ && fabs(mtface_orig->uv[element->tfindex][1] - mtface_iter->uv[element_iter->tfindex][1]) < limit){
+ return 1;
+ }else
+ return 0;
+ }else
+ return 1;
+}
+
+
+static int stitch_check_uvs_state_stitchable(UvElement *element, UvElement *element_iter, StitchState *state){
+ if(state->snap_islands && element->island == element_iter->island)
+ return 0;
+
+ return stitch_check_uvs_stitchable(element, element_iter, state);
+}
+
+
+/* calculate snapping for islands */
+static void stitch_calculate_island_snapping(StitchState *state, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final){
+ int i;
+ EditFace *efa;
+ MTFace *mt;
+ UvElement *element;
+
+ for(i = 0; i < state->element_map->totalIslands; i++){
+ if(island_stitch_data[i].addedForPreview){
+ int numOfIslandUVs = 0, j;
+
+ /* check to avoid divide by 0 */
+ if(island_stitch_data[i].num_rot_elements>0){
+ island_stitch_data[i].rotation /= island_stitch_data[i].num_rot_elements;
+ island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfElements;
+ island_stitch_data[i].medianPoint[1] /= island_stitch_data[i].numOfElements;
+ }
+ island_stitch_data[i].translation[0] /= island_stitch_data[i].numOfElements;
+ island_stitch_data[i].translation[1] /= island_stitch_data[i].numOfElements;
+ numOfIslandUVs = getNumOfIslandUvs(state->element_map, i);
+ element = &state->element_map->buf[state->element_map->islandIndices[i]];
+ for(j = 0; j < numOfIslandUVs; j++, element++){
+ /* stitchable uvs have already been processed, don't process */
+ if(!(element->flag & STITCH_PROCESSED)){
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ if(final){
+
+ stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, mt->uv[element->tfindex]);
+
+ mt->uv[element->tfindex][0] += island_stitch_data[i].translation[0];
+ mt->uv[element->tfindex][1] += island_stitch_data[i].translation[1];
+ }
+ else if(efa->tmp.l != STITCH_NO_PREVIEW){
+ if(efa->v4){
+
+ stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->preview_quads[efa->tmp.l + 2*element->tfindex]);
+
+ preview->preview_quads[efa->tmp.l + 2*element->tfindex] += island_stitch_data[i].translation[0];
+ preview->preview_quads[efa->tmp.l + 2*element->tfindex + 1] += island_stitch_data[i].translation[1];
+ }
+ else {
+
+ stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->preview_tris[efa->tmp.l + 2*element->tfindex]);
+
+ preview->preview_tris[efa->tmp.l + 2*element->tfindex] += island_stitch_data[i].translation[0];
+ preview->preview_tris[efa->tmp.l + 2*element->tfindex + 1] += island_stitch_data[i].translation[1];
+ }
+ }
+ }
+ /* cleanup */
+ element->flag &= STITCH_SELECTED;
+ }
+ }
+ }
+}
+
+
+
+static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *state, UVVertAverage *uv_average, unsigned int *uvfinal_map, IslandStitchData *island_stitch_data)
+{
+ UvElement *element1, *element2;
+ EditFace *efa1;
+ EditFace *efa2;
+ MTFace *mt1;
+ MTFace *mt2;
+ float uv1[2], uv2[2];
+ float edgecos, edgesin;
+ int index1, index2;
+ float rotation;
+
+ element1 = state->uvs[edge->uv1];
+ element2 = state->uvs[edge->uv2];
+
+ efa1 = element1->face;
+ mt1 = CustomData_em_get(&state->em->fdata, efa1->data, CD_MTFACE);
+ efa2 = element2->face;
+ mt2 = CustomData_em_get(&state->em->fdata, efa2->data, CD_MTFACE);
+
+ index1 = uvfinal_map[element1 - state->element_map->buf];
+ index2 = uvfinal_map[element2 - state->element_map->buf];
+
+ /* the idea here is to take the directions of the edges and find the rotation between final and initial
+ * direction. This, using inner and outer vector products, gives the angle. Directions are differences so... */
+ uv1[0] = mt2->uv[element2->tfindex][0] - mt1->uv[element1->tfindex][0];
+ uv1[1] = mt2->uv[element2->tfindex][1] - mt1->uv[element1->tfindex][1];
+
+ uv2[0] = uv_average[index2].uv[0] - uv_average[index1].uv[0];
+ uv2[1] = uv_average[index2].uv[1] - uv_average[index1].uv[1];
+
+ normalize_v2(uv1);
+ normalize_v2(uv2);
+
+ edgecos = uv1[0]*uv2[0] + uv1[1]*uv2[1];
+ edgesin = uv1[0]*uv2[1] - uv2[0]*uv1[1];
+
+ rotation = (edgesin > 0)? acos(MAX2(-1.0, MIN2(1.0, edgecos))): -acos(MAX2(-1.0, MIN2(1.0, edgecos)));
+
+ island_stitch_data[element1->island].num_rot_elements++;
+ island_stitch_data[element1->island].rotation += rotation;
+}
+
+
+static void stitch_island_calculate_vert_rotation(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data)
+{
+ float edgecos = 1, edgesin = 0;
+ int index;
+ UvElement *element_iter;
+ float rotation = 0;
+
+ if(element->island == state->static_island && !state->midpoints)
+ return;
+
+ index = (*(&element->face->v1 + element->tfindex))->tmp.l;
+
+ element_iter = state->element_map->vert[index];
+
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate && stitch_check_uvs_state_stitchable(element, element_iter, state)){
+ int index_tmp1, index_tmp2;
+ float normal[2];
+ /* easily possible*/
+
+ index_tmp1 = element_iter - state->element_map->buf;
+ index_tmp1 = state->map[index_tmp1];
+ index_tmp2 = element - state->element_map->buf;
+ index_tmp2 = state->map[index_tmp2];
+
+ negate_v2_v2(normal, state->normals + index_tmp2*2);
+ edgecos = dot_v2v2(normal, state->normals + index_tmp1*2);
+ edgesin = cross_v2v2(normal, state->normals + index_tmp1*2);
+ rotation += (edgesin > 0)? acos(edgecos): -acos(edgecos);
+ }
+ }
+
+ if(state->midpoints)
+ rotation /= 2.0;
+ island_stitch_data[element->island].num_rot_elements++;
+ island_stitch_data[element->island].rotation += rotation;
+}
+
+
+static void stitch_state_delete(StitchState *stitch_state)
+{
+ if(stitch_state){
+ if(stitch_state->element_map){
+ EM_free_uv_element_map(stitch_state->element_map);
+ }
+ if(stitch_state->uvs){
+ MEM_freeN(stitch_state->uvs);
+ }
+ if(stitch_state->selection_stack){
+ MEM_freeN(stitch_state->selection_stack);
+ }
+ if(stitch_state->quads_per_island){
+ MEM_freeN(stitch_state->quads_per_island);
+ }
+ if(stitch_state->tris_per_island){
+ MEM_freeN(stitch_state->tris_per_island);
+ }
+ if(stitch_state->map){
+ MEM_freeN(stitch_state->map);
+ }
+ if(stitch_state->normals){
+ MEM_freeN(stitch_state->normals);
+ }
+ if(stitch_state->edges){
+ MEM_freeN(stitch_state->edges);
+ }
+ MEM_freeN(stitch_state);
+ }
+}
+
+
+
+/* checks for remote uvs that may be stitched with a certain uv, flags them if stitchable. */
+static void determine_uv_stitchability(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data){
+ int vert_index;
+ UvElement *element_iter;
+
+ vert_index = (*(&element->face->v1 + element->tfindex))->tmp.l;
+ element_iter = state->element_map->vert[vert_index];
+
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ if(element_iter == element){
+ continue;
+ }
+ if(stitch_check_uvs_stitchable(element, element_iter, state)){
+ island_stitch_data[element_iter->island].stitchableCandidate = 1;
+ island_stitch_data[element->island].stitchableCandidate = 1;
+ element->flag |= STITCH_STITCHABLE_CANDIDATE;
+ }
+ }
+ }
+}
+
+
+/* set preview buffer position of UV face in editface->tmp.l */
+static void stitch_set_face_preview_buffer_position(EditFace *efa, StitchPreviewer *preview)
+{
+ if(efa->tmp.l == STITCH_NO_PREVIEW)
+ {
+ if(efa->v4)
+ {
+ efa->tmp.l = preview->num_quads*8;
+ preview->num_quads++;
+ } else {
+ efa->tmp.l = preview->num_tris*6;
+ preview->num_tris++;
+ }
+ }
+}
+
+
+/* setup face preview for all coincident uvs and their faces */
+static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data){
+ StitchPreviewer *preview = uv_get_stitch_previewer();
+
+ /* static island does not change so returning immediately */
+ if(state->snap_islands && !state->midpoints && state->static_island == element->island)
+ return;
+
+ if(state->snap_islands){
+ island_stitch_data[element->island].addedForPreview = 1;
+ }
+
+ do{
+ stitch_set_face_preview_buffer_position(element->face, preview);
+ element = element->next;
+ }while(element && !element->separate);
+}
+
+
+/* checks if uvs are indeed stitchable and registers so that they can be shown in preview */
+static void stitch_validate_stichability(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data){
+ UvElement *element_iter;
+ StitchPreviewer *preview;
+
+ preview = uv_get_stitch_previewer();
+ element_iter = state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ if(element_iter == element)
+ continue;
+ if(stitch_check_uvs_stitchable(element, element_iter, state)){
+ if(((element_iter->island == state->static_island) || (element->island == state->static_island)) &&
+ !((element_iter->island == element->island) && state->snap_islands)){
+ element->flag |= STITCH_STITCHABLE;
+ preview->num_stitchable++;
+ stitch_setup_face_preview_for_uv_group(element, state, island_stitch_data);
+ return;
+ }
+ }
+ }
+ }
+
+ /* this can happen if the uvs to be stitched are not on a stitchable island */
+ if(!(element->flag & STITCH_STITCHABLE)){
+ preview->num_unstitchable++;
+ }
+}
+
+/* main processing function. It calculates preview and final positions. */
+static int stitch_process_data(StitchState *state, Scene *scene, int final)
+{
+ int i;
+ StitchPreviewer *preview = uv_get_stitch_previewer();
+ IslandStitchData *island_stitch_data = NULL;
+ int previous_island = state->static_island;
+ EditFace *efa;
+ EditVert *ev;
+ UVVertAverage *final_position;
+ char stitch_midpoints = state->midpoints;
+ /* used to map uv indices to uvaverage indices for selection */
+ unsigned int *uvfinal_map;
+
+ /* cleanup previous preview */
+ stitch_preview_delete();
+ preview = stitch_preview_init();
+ if(preview == NULL)
+ return 0;
+ /* each face holds its position in the preview buffer in tmp. -1 is uninitialized */
+ for(efa = state->em->faces.first; efa; efa = efa->next){
+ efa->tmp.l = STITCH_NO_PREVIEW;
+ }
+
+ island_stitch_data = MEM_callocN(sizeof(*island_stitch_data)*state->element_map->totalIslands, "stitch_island_data");
+ if(!island_stitch_data){
+ return 0;
+ }
+
+ /* store indices to editVerts. */
+ for(ev = state->em->verts.first, i = 0; ev; ev = ev->next, i++){
+ ev->tmp.l = i;
+ }
+
+ /*****************************************
+ * First determine stitchability of uvs *
+ *****************************************/
+
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ determine_uv_stitchability(element, state, island_stitch_data);
+ }
+
+ /* set static island to one that is added for preview */
+ state->static_island %= state->element_map->totalIslands;
+ while(!(island_stitch_data[state->static_island].stitchableCandidate)){
+ state->static_island++;
+ state->static_island %= state->element_map->totalIslands;
+ /* this is entirely possible if for example limit stitching with no stitchable verts or no selection */
+ if(state->static_island == previous_island)
+ break;
+ }
+
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE_CANDIDATE){
+ element->flag &= ~STITCH_STITCHABLE_CANDIDATE;
+ stitch_validate_stichability(element, state, island_stitch_data);
+ }else{
+ /* add to preview for unstitchable */
+ preview->num_unstitchable++;
+ }
+ }
+
+ /*****************************************
+ * Setup preview for stitchable islands *
+ *****************************************/
+ if(state->snap_islands){
+ for(i = 0; i < state->element_map->totalIslands; i++){
+ if(island_stitch_data[i].addedForPreview){
+ int numOfIslandUVs = 0, j;
+ UvElement *element;
+ numOfIslandUVs = getNumOfIslandUvs(state->element_map, i);
+ element = &state->element_map->buf[state->element_map->islandIndices[i]];
+ for(j = 0; j < numOfIslandUVs; j++, element++){
+ stitch_set_face_preview_buffer_position(element->face, preview);
+ }
+ }
+ }
+ }
+
+ /*********************************************************************
+ * Setup the preview buffers and fill them with the appropriate data *
+ *********************************************************************/
+ if(!final){
+ unsigned int tricount = 0, quadcount = 0;
+ int stitchBufferIndex = 0, unstitchBufferIndex = 0;
+ /* initialize the preview buffers */
+ preview->preview_quads = (float *)MEM_mallocN(preview->num_quads*sizeof(float)*8, "quad_uv_stitch_prev");
+ preview->preview_tris = (float *)MEM_mallocN(preview->num_tris*sizeof(float)*6, "tri_uv_stitch_prev");
+
+ preview->preview_stitchable = (float *)MEM_mallocN(preview->num_stitchable*sizeof(float)*2, "stitch_preview_stichable_data");
+ preview->preview_unstitchable = (float *)MEM_mallocN(preview->num_unstitchable*sizeof(float)*2, "stitch_preview_unstichable_data");
+
+ preview->static_quads = (float *)MEM_mallocN(state->quads_per_island[state->static_island]*sizeof(float)*8, "static_island_preview_quads");
+ preview->static_tris = (float *)MEM_mallocN(state->tris_per_island[state->static_island]*sizeof(float)*6, "static_island_preview_tris");
+
+ preview->num_static_quads = state->quads_per_island[state->static_island];
+ preview->num_static_tris = state->tris_per_island[state->static_island];
+ /* will cause cancel and freeing of all data structures so OK */
+ if(!preview->preview_quads || !preview->preview_tris || !preview->preview_stitchable || !preview->preview_unstitchable){
+ return 0;
+ }
+
+ /* copy data from MTFaces to the preview display buffers */
+ for(efa = state->em->faces.first; efa; efa = efa->next){
+ MTFace *mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ UvElement *element = ED_get_uv_element(state->element_map, efa, 0);
+
+ if(element){
+ if(efa->tmp.l != STITCH_NO_PREVIEW){
+ if(efa->v4) {
+ memcpy(preview->preview_quads+efa->tmp.l, &mt->uv[0][0], 8*sizeof(float));
+ } else {
+ memcpy(preview->preview_tris+efa->tmp.l, &mt->uv[0][0], 6*sizeof(float));
+ }
+ }
+
+ if(element->island == state->static_island){
+ if(efa->v4) {
+ memcpy(preview->static_quads + quadcount*8, &mt->uv[0][0], 8*sizeof(float));
+ quadcount++;
+ } else {
+ memcpy(preview->static_tris + tricount*6, &mt->uv[0][0], 6*sizeof(float));
+ tricount++;
+ }
+ }
+ }
+ }
+
+ /* fill the appropriate preview buffers */
+ for(i = 0; i < state->total_separate_uvs; i++){
+ UvElement *element = (UvElement *)state->uvs[i];
+ if(element->flag & STITCH_STITCHABLE){
+ MTFace *mt;
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ preview->preview_stitchable[stitchBufferIndex*2] = mt->uv[element->tfindex][0];
+ preview->preview_stitchable[stitchBufferIndex*2 + 1] = mt->uv[element->tfindex][1];
+ stitchBufferIndex++;
+ }
+ else if(element->flag & STITCH_SELECTED){
+ MTFace *mt;
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ preview->preview_unstitchable[unstitchBufferIndex*2] = mt->uv[element->tfindex][0];
+ preview->preview_unstitchable[unstitchBufferIndex*2 + 1] = mt->uv[element->tfindex][1];
+ unstitchBufferIndex++;
+ }
+ }
+ }
+
+ /******************************************************
+ * Here we calculate the final coordinates of the uvs *
+ ******************************************************/
+
+ final_position = MEM_callocN(state->selection_size*sizeof(*final_position), "stitch_uv_average");
+ uvfinal_map = MEM_mallocN(state->element_map->totalUVs*sizeof(*uvfinal_map), "stitch_uv_final_map");
+
+ /* first pass, calculate final position for stitchable uvs of the static island */
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE){
+ MTFace *mt;
+
+ UvElement *element_iter;
+
+ uvfinal_map[element - state->element_map->buf] = i;
+
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ final_position[i].uv[0] = mt->uv[element->tfindex][0];
+ final_position[i].uv[1] = mt->uv[element->tfindex][1];
+ final_position[i].count = 1;
+
+ if(state->snap_islands && element->island == state->static_island && !stitch_midpoints)
+ continue;
+
+ element_iter = state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+
+ for(;element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ if(stitch_check_uvs_state_stitchable(element, element_iter, state)){
+ efa = element_iter->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ if(stitch_midpoints){
+ final_position[i].uv[0] += mt->uv[element_iter->tfindex][0];
+ final_position[i].uv[1] += mt->uv[element_iter->tfindex][1];
+ final_position[i].count++;
+ }else if(element_iter->island == state->static_island){
+ /* if multiple uvs on the static island exist,
+ * last checked remains. to disambiguate we need to limit or use
+ * edge stitch */
+ final_position[i].uv[0] = mt->uv[element_iter->tfindex][0];
+ final_position[i].uv[1] = mt->uv[element_iter->tfindex][1];
+ }
+ }
+ }
+ }
+ }
+ if(stitch_midpoints){
+ final_position[i].uv[0] /= final_position[i].count;
+ final_position[i].uv[1] /= final_position[i].count;
+ }
+ }
+
+ /* second pass, calculate island rotation and translation before modifying any uvs */
+ if(state->snap_islands){
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE){
+ MTFace *mt;
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ /* accumulate each islands' translation from stitchable elements. it is important to do here
+ * because in final pass MTFaces get modified and result is zero. */
+ island_stitch_data[element->island].translation[0] += final_position[i].uv[0] - mt->uv[element->tfindex][0];
+ island_stitch_data[element->island].translation[1] += final_position[i].uv[1] - mt->uv[element->tfindex][1];
+ island_stitch_data[element->island].medianPoint[0] += mt->uv[element->tfindex][0];
+ island_stitch_data[element->island].medianPoint[1] += mt->uv[element->tfindex][1];
+ island_stitch_data[element->island].numOfElements++;
+ }
+ }
+
+ /* only calculate rotation when an edge has been fully selected */
+ for(i = 0; i < state->total_boundary_edges; i++){
+ UvEdge *edge = state->edges+i;
+ if((state->uvs[edge->uv1]->flag & STITCH_STITCHABLE) && (state->uvs[edge->uv2]->flag & STITCH_STITCHABLE)){
+ stitch_island_calculate_edge_rotation(edge, state, final_position, uvfinal_map, island_stitch_data);
+ island_stitch_data[state->uvs[edge->uv1]->island].use_edge_rotation = 1;
+ }
+ }
+
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(!island_stitch_data[element->island].use_edge_rotation){
+ if(element->flag & STITCH_STITCHABLE){
+ stitch_island_calculate_vert_rotation(element, state, island_stitch_data);
+ }
+ }
+ }
+
+ }
+
+ /* third pass, propagate changes to coincident uvs */
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE){
+ UvElement *element_iter = element;
+ /* propagate to coincident uvs */
+ do{
+ MTFace *mt;
+
+ efa = element_iter->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ element_iter->flag |= STITCH_PROCESSED;
+ /* either flush to preview or to the MTFace, if final */
+ if(final){
+ mt->uv[element_iter->tfindex][0] = final_position[i].uv[0];
+ mt->uv[element_iter->tfindex][1] = final_position[i].uv[1];
+
+ uvedit_uv_select(scene, efa, mt, element_iter->tfindex);
+ }else if(efa->tmp.l != STITCH_NO_PREVIEW){
+ if(efa->v4){
+ *(preview->preview_quads+efa->tmp.l + element_iter->tfindex*2) = final_position[i].uv[0];
+ *(preview->preview_quads+efa->tmp.l + element_iter->tfindex*2 + 1) = final_position[i].uv[1];
+ }else{
+ *(preview->preview_tris+efa->tmp.l + element_iter->tfindex*2) = final_position[i].uv[0];
+ *(preview->preview_tris+efa->tmp.l + element_iter->tfindex*2 + 1) = final_position[i].uv[1];
+ }
+ }
+
+ /* end of calculations, keep only the selection flag */
+ if( (!state->snap_islands) || ((!stitch_midpoints) && (element_iter->island == state->static_island))) {
+ element_iter->flag &= STITCH_SELECTED;
+ }
+
+ element_iter = element_iter->next;
+ }while(element_iter && !element_iter->separate);
+ }
+ }
+
+ /* final pass, calculate Island translation/rotation if needed */
+ if(state->snap_islands){
+ stitch_calculate_island_snapping(state, preview, island_stitch_data, final);
+ }
+
+ MEM_freeN(final_position);
+ MEM_freeN(uvfinal_map);
+ MEM_freeN(island_stitch_data);
+
+ return 1;
+}
+
+/* Stitch hash initialisation functions */
+static unsigned int uv_edge_hash(const void *key){
+ UvEdge *edge = (UvEdge *)key;
+ return
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) +
+ BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1));
+}
+
+static int uv_edge_compare(const void *a, const void *b){
+ UvEdge *edge1 = (UvEdge *)a;
+ UvEdge *edge2 = (UvEdge *)b;
+
+ if((edge1->uv1 == edge2->uv1) && (edge1->uv2 == edge2->uv2)){
+ return 0;
+ }
+ return 1;
+}
+
+
+/* Select all common uvs */
+static void stitch_select_uv(UvElement *element, StitchState *stitch_state, int always_select)
+{
+ /* This works due to setting of tmp in find nearest uv vert */
+ UvElement *element_iter;
+ UvElement **selection_stack = stitch_state->selection_stack;
+
+ element_iter = stitch_state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+ /* first deselect all common uvs */
+ for(; element_iter; element_iter = element_iter->next){
+ if(element_iter->separate){
+ /* only separators go to selection */
+ if(element_iter->flag & STITCH_SELECTED){
+ int i;
+ if(always_select)
+ continue;
+
+ element_iter->flag &= ~STITCH_SELECTED;
+ for(i = 0; i < stitch_state->selection_size; i++){
+ if(selection_stack[i] == element_iter){
+ (stitch_state->selection_size)--;
+ selection_stack[i] = selection_stack[stitch_state->selection_size];
+ break;
+ }
+ }
+ }else{
+ element_iter->flag |= STITCH_SELECTED;
+ selection_stack[(stitch_state->selection_size)++] = element_iter;
+ }
+ }
+ }
+}
+
+static void stitch_calculate_edge_normal(EditMesh *em, UvEdge *edge, float *normal)
+{
+ UvElement *element = edge->element;
+ EditFace *efa = element->face;
+ MTFace *mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ int nverts = efa->v4?4 : 3;
+ int index = (element->tfindex + 2)%nverts;
+ float tangent[2], internal[2];
+
+ sub_v2_v2v2(tangent, mt->uv[(element->tfindex + 1)%nverts], mt->uv[element->tfindex]);
+ sub_v2_v2v2(internal, mt->uv[index], mt->uv[element->tfindex]);
+
+ /* choose one of the normals */
+ normal[0] = tangent[1];
+ normal[1] = -tangent[0];
+
+ /* if normal points inside the face, invert */
+ if(dot_v2v2(normal, internal) > 0){
+ normal[0] = -tangent[1];
+ normal[1] = tangent[0];
+ }
+
+ normalize_v2(normal);
+}
+
+static int stitch_init(bContext *C, wmOperator *op)
+{
+ /* for fast edge lookup... */
+ GHash *edgeHash;
+ /* ...and actual edge storage */
+ UvEdge *edges;
+ int total_edges;
+ /* maps uvelements to their first coincident uv */
+ int *map;
+ int counter = 0, i;
+ EditFace *efa;
+ EditMesh *em;
+ GHashIterator* ghi;
+ UvEdge *all_edges;
+ StitchState *state = MEM_mallocN(sizeof(StitchState), "stitch state");
+ Scene *scene = CTX_data_scene(C);
+ ToolSettings *ts = scene->toolsettings;
+
+ Object *obedit = CTX_data_edit_object(C);
+
+ op->customdata = state;
+
+ if(!state)
+ return 0;
+
+ /* initialize state */
+ state->use_limit = RNA_boolean_get(op->ptr, "use_limit");
+ state->limit_dist = RNA_float_get(op->ptr, "limit");
+ state->em = em = BKE_mesh_get_editmesh((Mesh*)obedit->data);
+ state->snap_islands = RNA_boolean_get(op->ptr, "snap_islands");
+ state->static_island = RNA_int_get(op->ptr, "static_island");
+ state->midpoints = RNA_boolean_get(op->ptr, "midpoint_snap");
+ /* in uv synch selection, all uv's are visible */
+ if(ts->uv_flag & UV_SYNC_SELECTION){
+ state->element_map = EM_make_uv_element_map(state->em, 0, 1);
+ }else{
+ state->element_map = EM_make_uv_element_map(state->em, 1, 1);
+ }
+ if(!state->element_map){
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ /* Entirely possible if redoing last operator that static island is bigger than total number of islands.
+ * This ensures we get no hang in the island checking code in stitch_process_data. */
+ state->static_island %= state->element_map->totalIslands;
+
+ /* Count 'unique' uvs */
+ for(i = 0; i < state->element_map->totalUVs; i++){
+ if(state->element_map->buf[i].separate){
+ counter++;
+ }
+ }
+
+ /* Allocate the unique uv buffers */
+ state->uvs = MEM_mallocN(sizeof(*state->uvs)*counter, "uv_stitch_unique_uvs");
+ /* internal uvs need no normals but it is hard and slow to keep a map of
+ * normals only for boundary uvs, so allocating for all uvs */
+ state->normals = MEM_callocN(sizeof(*state->normals)*counter*2, "uv_stitch_normals");
+ state->total_separate_uvs = counter;
+ /* we can at most have totalUVs edges or uvs selected. Actually they are less, considering we store only
+ * unique uvs for processing but I am accounting for all bizarre cases, especially for edges, this way */
+ state->selection_stack = MEM_mallocN(sizeof(*state->selection_stack)*counter, "uv_stitch_selection_stack");
+ state->map = map = MEM_mallocN(sizeof(*map)*state->element_map->totalUVs, "uv_stitch_unique_map");
+ /* Allocate the edge stack */
+ edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash");
+ all_edges = MEM_mallocN(sizeof(*all_edges)*state->element_map->totalUVs, "stitch_all_edges");
+
+ if(!state->selection_stack || !state->uvs || !map || !edgeHash || !all_edges){
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ /* So that we can use this as index for the UvElements */
+ counter = -1;
+ /* initialize the unique UVs and map */
+ for(i = 0; i < state->em->totvert; i++){
+ UvElement *element = state->element_map->vert[i];
+ for(; element; element = element->next){
+ if(element->separate){
+ counter++;
+ state->uvs[counter] = element;
+ }
+ /* pointer arithmetic to the rescue, as always :)*/
+ map[element - state->element_map->buf] = counter;
+ }
+ }
+
+ /* Now, on to generate our uv connectivity data */
+ for(efa = state->em->faces.first, counter = 0; efa; efa = efa->next){
+ if((ts->uv_flag & UV_SYNC_SELECTION) || (!efa->h && efa->f & SELECT)){
+ int nverts = efa->v4 ? 4 : 3;
+
+ for(i = 0; i < nverts; i++){
+ UvElement *element = ED_get_uv_element(state->element_map, efa, i);
+ int offset1, itmp1 = element - state->element_map->buf;
+ int offset2, itmp2 = ED_get_uv_element(state->element_map, efa, (i+1)%nverts) - state->element_map->buf;
+
+ offset1 = map[itmp1];
+ offset2 = map[itmp2];
+
+ all_edges[counter].flag = 0;
+ all_edges[counter].element = element;
+ /* using an order policy, sort uvs according to address space. This avoids
+ * Having two different UvEdges with the same uvs on different positions */
+ if(offset1 < offset2){
+ all_edges[counter].uv1 = offset1;
+ all_edges[counter].uv2 = offset2;
+ }
+ else{
+ all_edges[counter].uv1 = offset2;
+ all_edges[counter].uv2 = offset1;
+ }
+
+ if(BLI_ghash_haskey(edgeHash, &all_edges[counter])){
+ char *flag = BLI_ghash_lookup(edgeHash, &all_edges[counter]);
+ *flag = 0;
+ }
+ else{
+ BLI_ghash_insert(edgeHash, &all_edges[counter], &(all_edges[counter].flag));
+ all_edges[counter].flag = STITCH_BOUNDARY;
+ }
+ counter++;
+ }
+ }
+ }
+
+
+ ghi = BLI_ghashIterator_new(edgeHash);
+ total_edges = 0;
+ /* fill the edges with data */
+ for(; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)){
+ UvEdge *edge = ((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ if(edge->flag & STITCH_BOUNDARY){
+ total_edges++;
+ }
+ }
+ state->edges = edges = MEM_mallocN(sizeof(*edges)*total_edges, "stitch_edges");
+ if(!ghi || !edges){
+ MEM_freeN(all_edges);
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ state->total_boundary_edges = total_edges;
+
+ /* fill the edges with data */
+ for(i = 0, BLI_ghashIterator_init(ghi, edgeHash); !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)){
+ UvEdge *edge = ((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ if(edge->flag & STITCH_BOUNDARY){
+ edges[i++] = *((UvEdge *)BLI_ghashIterator_getKey(ghi));
+ }
+ }
+
+ /* cleanup temporary stuff */
+ BLI_ghashIterator_free(ghi);
+ MEM_freeN(all_edges);
+
+ /* refill hash with new pointers to cleanup duplicates */
+ BLI_ghash_free(edgeHash, NULL, NULL);
+
+ /***** calculate 2D normals for boundary uvs *****/
+
+ /* we use boundary edges to calculate 2D normals.
+ * to disambiguate the direction of the normal, we also need
+ * a point "inside" the island, that can be provided by
+ * the opposite uv for a quad, or the next uv for a triangle. */
+
+ for(i = 0; i < total_edges; i++){
+ float normal[2];
+ stitch_calculate_edge_normal(em, edges + i, normal);
+
+ add_v2_v2(state->normals + edges[i].uv1*2, normal);
+ add_v2_v2(state->normals + edges[i].uv2*2, normal);
+
+ normalize_v2(state->normals + edges[i].uv1*2);
+ normalize_v2(state->normals + edges[i].uv2*2);
+ }
+
+
+ /***** fill selection stack *******/
+
+ state->selection_size = 0;
+
+ /* Load old selection if redoing operator with different settings */
+ if(RNA_struct_property_is_set(op->ptr, "selection")){
+ int faceIndex, elementIndex;
+ UvElement *element;
+
+ EM_init_index_arrays(em, 0, 0, 1);
+
+
+ RNA_BEGIN(op->ptr, itemptr, "selection") {
+ faceIndex = RNA_int_get(&itemptr, "face_index");
+ elementIndex = RNA_int_get(&itemptr, "element_index");
+ efa = EM_get_face_for_index(faceIndex);
+ element = ED_get_uv_element(state->element_map, efa, elementIndex);
+ stitch_select_uv(element, state, 1);
+ }
+ RNA_END;
+
+ EM_free_index_arrays();
+ /* Clear the selection */
+ RNA_collection_clear(op->ptr, "selection");
+
+ } else {
+ for(efa = state->em->faces.first ; efa; efa = efa->next){
+ int numOfVerts;
+ MTFace *mt;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ numOfVerts = efa->v4 ? 4 : 3;
+
+ for(i = 0; i < numOfVerts; i++){
+ if(uvedit_uv_selected(scene, efa, mt, i)){
+ UvElement *element = ED_get_uv_element(state->element_map, efa, i);
+ stitch_select_uv(element, state, 1);
+ }
+ }
+ }
+ }
+
+ /***** initialise static island preview data *****/
+
+ state->quads_per_island = MEM_mallocN(sizeof(*state->quads_per_island)*state->element_map->totalIslands,
+ "stitch island quads");
+ state->tris_per_island = MEM_mallocN(sizeof(*state->tris_per_island)*state->element_map->totalIslands,
+ "stitch island tris");
+ for(i = 0; i < state->element_map->totalIslands; i++){
+ state->quads_per_island[i] = 0;
+ state->tris_per_island[i] = 0;
+ }
+
+ for(efa = state->em->faces.first; efa; efa = efa->next){
+ UvElement *element = ED_get_uv_element(state->element_map, efa, 0);
+
+ if(element){
+ if(efa->v4){
+ state->quads_per_island[element->island]++;
+ }
+ else {
+ state->tris_per_island[element->island]++;
+ }
+ }
+ }
+
+ if(!stitch_process_data(state, scene, 0)){
+ stitch_state_delete(state);
+ return 0;
+ }
+
+ stitch_update_header(state, C);
+ return 1;
+}
+
+static int stitch_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+ Object *obedit = CTX_data_edit_object(C);
+ if(!stitch_init(C, op))
+ return OPERATOR_CANCELLED;
+
+ WM_event_add_modal_handler(C, op);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void stitch_exit(bContext *C, wmOperator *op, int finished)
+{
+ StitchState *stitch_state;
+ Scene *scene;
+ SpaceImage *sima;
+ ScrArea *sa= CTX_wm_area(C);
+ Object *obedit;
+
+ scene= CTX_data_scene(C);
+ obedit= CTX_data_edit_object(C);
+ sima= CTX_wm_space_image(C);
+
+ stitch_state = (StitchState *)op->customdata;
+
+ if(finished){
+ EditFace *efa;
+ int i;
+
+ RNA_float_set(op->ptr, "limit", stitch_state->limit_dist);
+ RNA_boolean_set(op->ptr, "use_limit", stitch_state->use_limit);
+ RNA_boolean_set(op->ptr, "snap_islands", stitch_state->snap_islands);
+ RNA_int_set(op->ptr, "static_island", stitch_state->static_island);
+ RNA_boolean_set(op->ptr, "midpoint_snap", stitch_state->midpoints);
+
+ for(i = 0, efa = stitch_state->em->faces.first; efa; efa = efa->next, i++){
+ efa->tmp.l = i;
+ }
+
+ /* Store selection for re-execution of stitch */
+ for(i = 0; i < stitch_state->selection_size; i++){
+ PointerRNA itemptr;
+ UvElement *element = stitch_state->selection_stack[i];
+
+ RNA_collection_add(op->ptr, "selection", &itemptr);
+
+ RNA_int_set(&itemptr, "face_index", element->face->tmp.l);
+ RNA_int_set(&itemptr, "element_index", element->tfindex);
+ }
+
+
+ uvedit_live_unwrap_update(sima, scene, obedit);
+ }
+
+ if(sa)
+ ED_area_headerprint(sa, NULL);
+
+ DAG_id_tag_update(obedit->data, 0);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ BKE_mesh_end_editmesh(obedit->data, stitch_state->em);
+
+ stitch_state_delete(stitch_state);
+ op->customdata = NULL;
+
+ stitch_preview_delete();
+}
+
+
+static int stitch_cancel(bContext *C, wmOperator *op)
+{
+ stitch_exit(C, op, 0);
+ return OPERATOR_CANCELLED;
+}
+
+
+static int stitch_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+
+ if(!stitch_init(C, op))
+ return OPERATOR_CANCELLED;
+ if(stitch_process_data((StitchState *)op->customdata, scene, 1)){
+ stitch_exit(C, op, 1);
+ return OPERATOR_FINISHED;
+ }else {
+ return stitch_cancel(C, op);
+ }
+}
+
+static void stitch_select(bContext *C, Scene *scene, wmEvent *event, StitchState *stitch_state){
+ /* add uv under mouse to processed uv's */
+ float co[2];
+ NearestHit hit;
+ ARegion *ar= CTX_wm_region(C);
+ Image *ima= CTX_data_edit_image(C);
+
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
+ uv_find_nearest_vert(scene, ima, stitch_state->em, co, NULL, &hit);
+
+ if(hit.efa)
+ {
+ /* Add vertex to selection, deselect all common uv's of vert other
+ * than selected and update the preview. This behavior was decided so that
+ * you can do stuff like deselect the opposite stitchable vertex and the initial still gets deselected */
+
+ /* This works due to setting of tmp in find nearest uv vert */
+ UvElement *element = ED_get_uv_element(stitch_state->element_map, hit.efa, hit.uv);
+ stitch_select_uv(element, stitch_state, 0);
+
+ }
+}
+
+static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ StitchState *stitch_state;
+ Scene *scene = CTX_data_scene(C);
+
+ stitch_state = (StitchState *)op->customdata;
+
+ switch(event->type){
+ case MIDDLEMOUSE:
+ return OPERATOR_PASS_THROUGH;
+
+ /* Cancel */
+ case ESCKEY:
+ return stitch_cancel(C, op);
+
+
+ case LEFTMOUSE:
+ if(event->shift && (U.flag & USER_LMOUSESELECT)){
+ if(event->val == KM_RELEASE){
+ stitch_select(C, scene, event, stitch_state);
+
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ }
+ break;
+ }
+ case PADENTER:
+ case RETKEY:
+ if(stitch_process_data(stitch_state, scene, 1)){
+ stitch_exit(C, op, 1);
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return stitch_cancel(C, op);
+ }
+
+ /* Increase limit */
+ case PADPLUSKEY:
+ case WHEELUPMOUSE:
+ if(event->alt){
+ stitch_state->limit_dist += 0.01;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ else{
+ return OPERATOR_PASS_THROUGH;
+ }
+ /* Decrease limit */
+ case PADMINUS:
+ case WHEELDOWNMOUSE:
+ if(event->alt){
+ stitch_state->limit_dist -= 0.01;
+ stitch_state->limit_dist = MAX2(0.01, stitch_state->limit_dist);
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }else{
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ /* Use Limit (Default off)*/
+ case LKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->use_limit = !stitch_state->use_limit;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ return OPERATOR_RUNNING_MODAL;
+
+ case IKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->static_island++;
+ stitch_state->static_island %= stitch_state->element_map->totalIslands;
+
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ return OPERATOR_RUNNING_MODAL;
+
+ case MKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->midpoints = !stitch_state->midpoints;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ }
+ break;
+
+ /* Select geometry*/
+ case RIGHTMOUSE:
+ if(!event->shift){
+ return stitch_cancel(C, op);
+ }
+ if(event->val == KM_RELEASE && !(U.flag & USER_LMOUSESELECT)){
+ stitch_select(C, scene, event, stitch_state);
+
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ }
+ return OPERATOR_RUNNING_MODAL;
+
+ /* snap islands on/off */
+ case SKEY:
+ if(event->val == KM_PRESS){
+ stitch_state->snap_islands = !stitch_state->snap_islands;
+ if(!stitch_process_data(stitch_state, scene, 0)){
+ return stitch_cancel(C, op);
+ }
+ break;
+ } else
+ return OPERATOR_RUNNING_MODAL;
+
+ default:
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ /* if updated settings, renew feedback message */
+ stitch_update_header(stitch_state, C);
+ ED_region_tag_redraw(CTX_wm_region(C));
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void UV_OT_stitch(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Stitch";
+ ot->description = "Stitch selected UV vertices by proximity";
+ ot->idname = "UV_OT_stitch";
+ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* api callbacks */
+ ot->invoke = stitch_invoke;
+ ot->modal = stitch_modal;
+ ot->exec = stitch_exec;
+ ot->cancel = stitch_cancel;
+ ot->poll= ED_operator_uvedit;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "use_limit", 0, "Use Limit", "Stitch UVs within a specified limit distance");
+ RNA_def_boolean(ot->srna, "snap_islands", 1, "Snap Islands", "Snap islands together. On edge stitch mode, rotates the islands too");
+
+ RNA_def_float(ot->srna, "limit", 0.01f, 0.0f, FLT_MAX, "Limit", "Limit distance in normalized coordinates", 0.0, FLT_MAX);
+ RNA_def_int(ot->srna, "static_island", 0, 0, INT_MAX, "Static Island", "Island that stays in place when stitching islands", 0, INT_MAX);
+ RNA_def_boolean(ot->srna, "midpoint_snap", 0, "Snap At Midpoint", "Uv's are stitched at midpoint instead of at static island");
+ prop = RNA_def_collection_runtime(ot->srna, "selection", &RNA_SelectedUvElement, "Selection", "");
+ /* Selection should not be editable or viewed in toolbar */
+ RNA_def_property_flag(prop, PROP_HIDDEN);
+}
+
+
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 17e5bebd6b0..3ed4df66778 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -40,6 +40,7 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_modifier_types.h"
#include "BLI_math.h"
#include "BLI_edgehash.h"
@@ -48,12 +49,15 @@
#include "BLI_utildefines.h"
#include "BLI_string.h"
+#include "BKE_cdderivedmesh.h"
+#include "BKE_subsurf.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
+#include "BKE_report.h"
#include "PIL_time.h"
@@ -272,6 +276,201 @@ static ParamHandle *construct_param_handle(Scene *scene, EditMesh *em, short imp
return handle;
}
+
+static void texface_from_original_index(EditFace *editFace, MTFace *texFace, int index, float **uv, ParamBool *pin, ParamBool *select, Scene *scene)
+{
+ int i, nverts = (editFace->v4)? 4: 3;
+
+ *uv = NULL;
+ *pin = 0;
+ *select = 1;
+
+ if(index == ORIGINDEX_NONE)
+ return;
+
+ for(i = 0; i < nverts; i++) {
+ if((*(&editFace->v1 + i))->tmp.t == index) {
+ *uv = texFace->uv[i];
+ *pin = ((texFace->unwrap & TF_PIN_MASK(i)) != 0);
+ *select = (uvedit_uv_selected(scene, editFace, texFace, i) != 0);
+ }
+ }
+}
+
+/* unwrap handle initialization for subsurf aware-unwrapper. The many modifications required to make the original function(see above)
+ * work justified the existence of a new function. */
+static ParamHandle *construct_param_handle_subsurfed(Scene *scene, EditMesh *editMesh, short fill, short sel, short correct_aspect)
+{
+ ParamHandle *handle;
+ /* index pointers */
+ MFace *face;
+ MEdge *edge;
+ EditVert *editVert;
+ MTFace *texface;
+ EditFace *editFace, **editFaceTmp;
+ EditEdge *editEdge, **editEdgeTmp;
+ int i;
+
+ /* modifier initialization data, will control what type of subdivision will happen*/
+ SubsurfModifierData smd = {{0}};
+ /* Used to hold subsurfed Mesh */
+ DerivedMesh *derivedMesh, *initialDerived;
+ /* holds original indices for subsurfed mesh */
+ int *origVertIndices, *origFaceIndices, *origEdgeIndices;
+ /* Holds vertices of subsurfed mesh */
+ MVert *subsurfedVerts;
+ MEdge *subsurfedEdges;
+ MFace *subsurfedFaces;
+ MTFace *subsurfedTexfaces;
+ /* number of vertices and faces for subsurfed mesh*/
+ int numOfEdges, numOfFaces;
+
+ /* holds a map to editfaces for every subsurfed MFace. These will be used to get hidden/ selected flags etc. */
+ EditFace **faceMap;
+ /* Mini container to hold all EditFaces so that they may be indexed easily and fast. */
+ EditFace **editFaceArray;
+ /* similar to the above, we need a way to map edges to their original ones */
+ EditEdge **edgeMap;
+ EditEdge **editEdgeArray;
+
+ handle = param_construct_begin();
+
+ if(correct_aspect) {
+ EditFace *eface = EM_get_actFace(editMesh, 1);
+
+ if(eface) {
+ float aspx, aspy;
+ texface= CustomData_em_get(&editMesh->fdata, eface->data, CD_MTFACE);
+
+ ED_image_uv_aspect(texface->tpage, &aspx, &aspy);
+
+ if(aspx!=aspy)
+ param_aspect_ratio(handle, aspx, aspy);
+ }
+ }
+
+ /* number of subdivisions to perform */
+ smd.levels = scene->toolsettings->uv_subsurf_level;
+ smd.subdivType = ME_CC_SUBSURF;
+
+ initialDerived = CDDM_from_editmesh(editMesh, NULL);
+ derivedMesh = subsurf_make_derived_from_derived(initialDerived, &smd,
+ 0, NULL, 0, 0, 1);
+
+ initialDerived->release(initialDerived);
+
+ /* get the derived data */
+ subsurfedVerts = derivedMesh->getVertArray(derivedMesh);
+ subsurfedEdges = derivedMesh->getEdgeArray(derivedMesh);
+ subsurfedFaces = derivedMesh->getFaceArray(derivedMesh);
+
+ origVertIndices = derivedMesh->getVertDataArray(derivedMesh, CD_ORIGINDEX);
+ origEdgeIndices = derivedMesh->getEdgeDataArray(derivedMesh, CD_ORIGINDEX);
+ origFaceIndices = derivedMesh->getFaceDataArray(derivedMesh, CD_ORIGINDEX);
+
+ subsurfedTexfaces = derivedMesh->getFaceDataArray(derivedMesh, CD_MTFACE);
+
+ numOfEdges = derivedMesh->getNumEdges(derivedMesh);
+ numOfFaces = derivedMesh->getNumFaces(derivedMesh);
+
+ faceMap = MEM_mallocN(numOfFaces*sizeof(EditFace *), "unwrap_edit_face_map");
+ editFaceArray = MEM_mallocN(editMesh->totface*sizeof(EditFace *), "unwrap_editFaceArray");
+
+ /* fill edit face array with edit faces */
+ for(editFace = editMesh->faces.first, editFaceTmp = editFaceArray; editFace; editFace= editFace->next, editFaceTmp++)
+ *editFaceTmp = editFace;
+
+ /* map subsurfed faces to original editFaces */
+ for(i = 0; i < numOfFaces; i++)
+ faceMap[i] = editFaceArray[origFaceIndices[i]];
+
+ MEM_freeN(editFaceArray);
+
+ edgeMap = MEM_mallocN(numOfEdges*sizeof(EditEdge *), "unwrap_edit_edge_map");
+ editEdgeArray = MEM_mallocN(editMesh->totedge*sizeof(EditEdge *), "unwrap_editEdgeArray");
+
+ /* fill edit edge array with edit edges */
+ for(editEdge = editMesh->edges.first, editEdgeTmp = editEdgeArray; editEdge; editEdge= editEdge->next, editEdgeTmp++)
+ *editEdgeTmp = editEdge;
+
+ /* map subsurfed edges to original editEdges */
+ for(i = 0; i < numOfEdges; i++) {
+ /* not all edges correspond to an old edge */
+ edgeMap[i] = (origEdgeIndices[i] != -1)?
+ editEdgeArray[origEdgeIndices[i]] : NULL;
+ }
+
+ MEM_freeN(editEdgeArray);
+
+ /* we need the editvert indices too */
+ for(editVert = editMesh->verts.first, i=0; editVert; editVert = editVert->next, i++)
+ editVert->tmp.t = i;
+
+ /* Prepare and feed faces to the solver */
+ for(i = 0; i < numOfFaces; i++) {
+ ParamKey key, vkeys[4];
+ ParamBool pin[4], select[4];
+ float *co[4];
+ float *uv[4];
+ EditFace *origFace = faceMap[i];
+ MTFace *origtexface = (MTFace *)CustomData_em_get(&editMesh->fdata, origFace->data, CD_MTFACE);
+
+ face = subsurfedFaces+i;
+
+ if(scene->toolsettings->uv_flag & UV_SYNC_SELECTION) {
+ if(origFace->h)
+ continue;
+ }
+ else {
+ if((origFace->h) || (sel && (origFace->f & SELECT)==0))
+ continue;
+ }
+
+ /* Now we feed the rest of the data from the subsurfed faces */
+ texface= subsurfedTexfaces+i;
+
+ /* We will not check for v4 here. Subsurfed mfaces always have 4 vertices. */
+ key = (ParamKey)face;
+ vkeys[0] = (ParamKey)face->v1;
+ vkeys[1] = (ParamKey)face->v2;
+ vkeys[2] = (ParamKey)face->v3;
+ vkeys[3] = (ParamKey)face->v4;
+
+ co[0] = subsurfedVerts[face->v1].co;
+ co[1] = subsurfedVerts[face->v2].co;
+ co[2] = subsurfedVerts[face->v3].co;
+ co[3] = subsurfedVerts[face->v4].co;
+
+ /* This is where all the magic is done. If the vertex exists in the, we pass the original uv pointer to the solver, thus
+ * flushing the solution to the edit mesh. */
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v1], &uv[0], &pin[0], &select[0], scene);
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v2], &uv[1], &pin[1], &select[1], scene);
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v3], &uv[2], &pin[2], &select[2], scene);
+ texface_from_original_index(origFace, origtexface, origVertIndices[face->v4], &uv[3], &pin[3], &select[3], scene);
+
+ param_face_add(handle, key, 4, vkeys, co, uv, pin, select);
+ }
+
+ /* these are calculated from original mesh too */
+ for(edge = subsurfedEdges, i = 0; i < numOfEdges; i++, edge++) {
+ if((edgeMap[i] != NULL) && edgeMap[i]->seam) {
+ ParamKey vkeys[2];
+ vkeys[0] = (ParamKey)edge->v1;
+ vkeys[1] = (ParamKey)edge->v2;
+ param_edge_set_seam(handle, vkeys);
+ }
+ }
+
+ param_construct_end(handle, fill, 0);
+
+ /* cleanup */
+ MEM_freeN(faceMap);
+ MEM_freeN(edgeMap);
+ derivedMesh->release(derivedMesh);
+
+ return handle;
+}
+
/* ******************** Minimize Stretch operator **************** */
typedef struct MinStretch {
@@ -582,13 +781,17 @@ void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit)
EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
short abf = scene->toolsettings->unwrapper == 0;
short fillholes = scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES;
+ short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
if(!ED_uvedit_test(obedit)) {
BKE_mesh_end_editmesh(obedit->data, em);
return;
}
- liveHandle = construct_param_handle(scene, em, 0, fillholes, 0, 1);
+ if(use_subsurf)
+ liveHandle = construct_param_handle_subsurfed(scene, em, fillholes, 0, 1);
+ else
+ liveHandle = construct_param_handle(scene, em, 0, fillholes, 0, 1);
param_lscm_begin(liveHandle, PARAM_TRUE, abf);
BKE_mesh_end_editmesh(obedit->data, em);
@@ -900,14 +1103,17 @@ static void uv_map_clip_correct(EditMesh *em, wmOperator *op)
/* assumes UV Map is checked, doesn't run update funcs */
void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel)
{
- EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
ParamHandle *handle;
+ EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
const short fill_holes= scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES;
const short correct_aspect= !(scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT);
- short implicit= 0;
+ const short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
- handle= construct_param_handle(scene, em, implicit, fill_holes, sel, correct_aspect);
+ if(use_subsurf)
+ handle = construct_param_handle_subsurfed(scene, em, fill_holes, sel, correct_aspect);
+ else
+ handle= construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect);
param_lscm_begin(handle, PARAM_FALSE, scene->toolsettings->unwrapper == 0);
param_lscm_solve(handle);
@@ -930,6 +1136,9 @@ static int unwrap_exec(bContext *C, wmOperator *op)
int method = RNA_enum_get(op->ptr, "method");
int fill_holes = RNA_boolean_get(op->ptr, "fill_holes");
int correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
+ int use_subsurf = RNA_boolean_get(op->ptr, "use_subsurf_data");
+ int subsurf_level = RNA_int_get(op->ptr, "uv_subsurf_level");
+ float obsize[3], unitsize[3] = {1.0f, 1.0f, 1.0f};
short implicit= 0;
if(!uvedit_have_selection(scene, em, implicit)) {
@@ -944,8 +1153,14 @@ static int unwrap_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ mat4_to_size(obsize, obedit->obmat);
+ if(!compare_v3v3(obsize, unitsize, 1e-4f))
+ BKE_report(op->reports, RPT_INFO, "Object scale is not 1.0. Unwrap will operate on a non-scaled version of the mesh.");
+
/* remember last method for live unwrap */
scene->toolsettings->unwrapper = method;
+
+ scene->toolsettings->uv_subsurf_level = subsurf_level;
if(fill_holes) scene->toolsettings->uvcalc_flag |= UVCALC_FILLHOLES;
else scene->toolsettings->uvcalc_flag &= ~UVCALC_FILLHOLES;
@@ -953,6 +1168,9 @@ static int unwrap_exec(bContext *C, wmOperator *op)
if(correct_aspect) scene->toolsettings->uvcalc_flag &= ~UVCALC_NO_ASPECT_CORRECT;
else scene->toolsettings->uvcalc_flag |= UVCALC_NO_ASPECT_CORRECT;
+ if(use_subsurf) scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF;
+ else scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF;
+
/* execute unwrap */
ED_unwrap_lscm(scene, obedit, TRUE);
@@ -986,6 +1204,8 @@ void UV_OT_unwrap(wmOperatorType *ot)
"Virtual fill holes in mesh before unwrapping, to better avoid overlaps and preserve symmetry");
RNA_def_boolean(ot->srna, "correct_aspect", 1, "Correct Aspect",
"Map UVs taking image aspect ratio into account");
+ RNA_def_boolean(ot->srna, "use_subsurf_data", 0, "Use Subsurf Data", "Map UV's taking vertex position after subsurf into account");
+ RNA_def_int(ot->srna, "uv_subsurf_level", 1, 1, 6, "SubSurf Target", "Number of times to subdivide before calculating UV's", 1, 6);
}
/**************** Project From View operator **************/
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index d623697921c..203fd00538f 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -653,7 +653,7 @@ static char *code_generate_vertex(ListBase *nodes)
int GPU_bicubic_bump_support(void)
{
- return GLEW_ARB_texture_gather && GLEW_ARB_texture_query_lod && GLEW_VERSION_3_0;
+ return GLEW_ARB_texture_query_lod && GLEW_VERSION_3_0;
}
void GPU_code_generate_glsl_lib(void)
@@ -669,7 +669,6 @@ void GPU_code_generate_glsl_lib(void)
if(GPU_bicubic_bump_support()){
BLI_dynstr_append(ds, "/* These are needed for high quality bump mapping */\n"
"#version 130\n"
- "#extension GL_ARB_texture_gather: enable\n"
"#extension GL_ARB_texture_query_lod: enable\n"
"#define BUMP_BICUBIC\n");
}
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 5d36ba169f3..59802f2cf58 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -410,9 +410,12 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
ImBuf *ibuf = NULL;
unsigned int *bind = NULL;
int rectw, recth, tpx=0, tpy=0, y;
- unsigned int *rectrow, *tilerectrow;
unsigned int *tilerect= NULL, *scalerect= NULL, *rect= NULL;
+ float *ftilerect= NULL, *fscalerect = NULL, *frect = NULL;
+ float *srgb_frect = NULL;
short texwindx, texwindy, texwinsx, texwinsy;
+ /* flag to determine whether high resolution format is used */
+ int use_high_bit_depth = FALSE, do_color_management = FALSE;
/* initialize tile mode and number of repeats */
GTS.ima = ima;
@@ -462,9 +465,20 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
if(ibuf==NULL)
return 0;
- /* ensure we have a char buffer and not only float */
- if ((ibuf->rect==NULL) && ibuf->rect_float)
- IMB_rect_from_float(ibuf);
+ if(ibuf->rect_float) {
+ if(U.use_16bit_textures) {
+ /* use high precision textures. This is relatively harmless because OpenGL gives us
+ a high precision format only if it is available */
+ use_high_bit_depth = TRUE;
+ }
+
+ /* TODO unneeded when float images are correctly treated as linear always */
+ if(ibuf->profile == IB_PROFILE_LINEAR_RGB)
+ do_color_management = TRUE;
+
+ if(ibuf->rect==NULL)
+ IMB_rect_from_float(ibuf);
+ }
/* currently, tpage refresh is used by ima sequences */
if(ima->tpageflag & IMA_TPAGE_REFRESH) {
@@ -498,17 +512,39 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
tpx= texwindx;
tpy= texwindy;
- rect= ibuf->rect + texwinsy*ibuf->x + texwinsx;
+ if(use_high_bit_depth) {
+ if(do_color_management) {
+ srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
+ IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
+ ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+ frect= srgb_frect + texwinsy*ibuf->x + texwinsx;
+ }
+ else
+ frect= ibuf->rect_float + texwinsy*ibuf->x + texwinsx;
+ }
+ else
+ rect= ibuf->rect + texwinsy*ibuf->x + texwinsx;
}
}
else {
/* regular image mode */
bind= &ima->bindcode;
-
+
if(*bind==0) {
tpx= ibuf->x;
tpy= ibuf->y;
rect= ibuf->rect;
+ if(use_high_bit_depth) {
+ if(do_color_management) {
+ frect = srgb_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(*srgb_frect)*4, "floar_buf_col_cor");
+ IMB_buffer_float_from_float(srgb_frect, ibuf->rect_float,
+ ibuf->channels, IB_PROFILE_SRGB, ibuf->profile, 0,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->x);
+ }
+ else
+ frect= ibuf->rect_float;
+ }
}
}
@@ -523,26 +559,57 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
/* for tiles, copy only part of image into buffer */
if (GTS.tilemode) {
- tilerect= MEM_mallocN(rectw*recth*sizeof(*tilerect), "tilerect");
+ if(use_high_bit_depth) {
+ float *frectrow, *ftilerectrow;
- for (y=0; y<recth; y++) {
- rectrow= &rect[y*ibuf->x];
- tilerectrow= &tilerect[y*rectw];
-
- memcpy(tilerectrow, rectrow, tpx*sizeof(*rectrow));
+ ftilerect= MEM_mallocN(rectw*recth*sizeof(*ftilerect), "tilerect");
+
+ for (y=0; y<recth; y++) {
+ frectrow= &frect[y*ibuf->x];
+ ftilerectrow= &ftilerect[y*rectw];
+
+ memcpy(ftilerectrow, frectrow, tpx*sizeof(*frectrow));
+ }
+
+ frect= ftilerect;
}
+ else {
+ unsigned int *rectrow, *tilerectrow;
+
+ tilerect= MEM_mallocN(rectw*recth*sizeof(*tilerect), "tilerect");
+
+ for (y=0; y<recth; y++) {
+ rectrow= &rect[y*ibuf->x];
+ tilerectrow= &tilerect[y*rectw];
+
+ memcpy(tilerectrow, rectrow, tpx*sizeof(*rectrow));
+ }
- rect= tilerect;
+ rect= tilerect;
+ }
}
- /* scale if not a power of two */
+ /* scale if not a power of two. this is not strictly necessary for newer
+ GPUs (OpenGL version >= 2.0) since they support non-power-of-two-textures */
if (!is_pow2_limit(rectw) || !is_pow2_limit(recth)) {
rectw= smaller_pow2_limit(rectw);
recth= smaller_pow2_limit(recth);
- scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
- gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
- rect= scalerect;
+ if(use_high_bit_depth) {
+ fscalerect= MEM_mallocN(rectw*recth*sizeof(*fscalerect)*4, "fscalerect");
+ gluScaleImage(GL_RGBA, tpx, tpy, GL_FLOAT, frect, rectw, recth, GL_FLOAT, fscalerect);
+ /* frect will refer to ibuf->rect_float when not color converting. We don't want to free that */
+ if(do_color_management)
+ MEM_freeN(frect);
+
+ frect = fscalerect;
+ }
+ else {
+ scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
+ gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
+
+ rect= scalerect;
+ }
}
/* create image */
@@ -550,12 +617,18 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
glBindTexture( GL_TEXTURE_2D, *bind);
if (!(gpu_get_mipmap() && mipmap)) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+ if(use_high_bit_depth)
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
+ else
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
}
else {
- gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+ if(use_high_bit_depth)
+ gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA16, rectw, recth, GL_RGBA, GL_FLOAT, frect);
+ else
+ gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
@@ -570,9 +643,14 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
/* clean up */
if (tilerect)
MEM_freeN(tilerect);
+ if (ftilerect)
+ MEM_freeN(ftilerect);
if (scalerect)
MEM_freeN(scalerect);
-
+ if (fscalerect)
+ MEM_freeN(fscalerect);
+ if (srgb_frect)
+ MEM_freeN(srgb_frect);
return *bind;
}
@@ -692,23 +770,21 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
- if (ibuf->rect_float){
- /*This case needs a whole new buffer*/
- if(ibuf->rect==NULL) {
- IMB_rect_from_float(ibuf);
- }
- else {
- /* Do partial drawing. 'buffer' holds only the changed part. Needed for color corrected result */
- float *buffer = (float *)MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
- IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h);
- glBindTexture(GL_TEXTURE_2D, ima->bindcode);
- glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
+ /* if color correction is needed, we must update the part that needs updating. */
+ if(ibuf->rect_float && (!U.use_16bit_textures || (ibuf->profile == IB_PROFILE_LINEAR_RGB))) {
+ float *buffer = MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
+ IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h);
+
+ glBindTexture(GL_TEXTURE_2D, ima->bindcode);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
GL_FLOAT, buffer);
- MEM_freeN(buffer);
- if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
- ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
- return;
- }
+
+ MEM_freeN(buffer);
+
+ if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
+ ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
+
+ return;
}
glBindTexture(GL_TEXTURE_2D, ima->bindcode);
@@ -717,8 +793,12 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap)
glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
- glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
- GL_UNSIGNED_BYTE, ibuf->rect);
+ if(ibuf->rect_float)
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
+ GL_FLOAT, ibuf->rect_float);
+ else
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
+ GL_UNSIGNED_BYTE, ibuf->rect);
glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index adf6f4a143b..cb5d6721566 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -50,7 +50,7 @@
struct ImMetaData;
#define IB_MIPMAP_LEVELS 20
-#define IB_FILENAME_SIZE 1023
+#define IB_FILENAME_SIZE 1024
/**
* \ingroup imbuf
diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h
index b627baf99bd..a9f020c94e8 100644
--- a/source/blender/imbuf/intern/IMB_anim.h
+++ b/source/blender/imbuf/intern/IMB_anim.h
@@ -136,9 +136,9 @@ struct anim {
int x, y;
/* voor op nummer */
- char name[256];
+ char name[1024];
/* voor sequence */
- char first[256];
+ char first[1024];
/* movie */
void *movie;
@@ -189,7 +189,7 @@ struct anim {
struct redcode_handle * redcodeCtx;
#endif
- char index_dir[256];
+ char index_dir[768];
int proxies_tried;
int indices_tried;
diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h
index 62608cbbd79..f9d90208078 100644
--- a/source/blender/imbuf/intern/IMB_indexer.h
+++ b/source/blender/imbuf/intern/IMB_indexer.h
@@ -62,7 +62,7 @@ typedef struct anim_index_entry {
} anim_index_entry;
struct anim_index {
- char name[256];
+ char name[1024];
int num_entries;
struct anim_index_entry * entries;
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 442309ccf7a..a8ca282de66 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -164,19 +164,6 @@ MINLINE unsigned char dither_value(unsigned short v_in, DitherContext *di, int i
/************************* Generic Buffer Conversion *************************/
-MINLINE void byte_to_float_v4(float f[4], const uchar b[4])
-{
- f[0]= b[0] * (1.0f/255.0f);
- f[1]= b[1] * (1.0f/255.0f);
- f[2]= b[2] * (1.0f/255.0f);
- f[3]= b[3] * (1.0f/255.0f);
-}
-
-MINLINE void float_to_byte_v4(uchar b[4], const float f[4])
-{
- F4TOCHAR4(f, b);
-}
-
MINLINE void ushort_to_byte_v4(uchar b[4], const unsigned short us[4])
{
b[0]= USHORTTOUCHAR(us[0]);
@@ -233,7 +220,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
if(profile_to == profile_from) {
/* no color space conversion */
for(x = 0; x < width; x++, from+=3, to+=4) {
- F3TOCHAR3(from, to);
+ rgb_float_to_uchar(to, from);
to[3] = 255;
}
}
@@ -241,7 +228,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
/* convert from linear to sRGB */
for(x = 0; x < width; x++, from+=3, to+=4) {
linearrgb_to_srgb_v3_v3(tmp, from);
- F3TOCHAR3(tmp, to);
+ rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
@@ -249,7 +236,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
/* convert from sRGB to linear */
for(x = 0; x < width; x++, from+=3, to+=4) {
srgb_to_linearrgb_v3_v3(tmp, from);
- F3TOCHAR3(tmp, to);
+ rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
@@ -267,7 +254,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
}
else {
for(x = 0; x < width; x++, from+=4, to+=4)
- float_to_byte_v4(to, from);
+ rgba_float_to_uchar(to, from);
}
}
else if(profile_to == IB_PROFILE_SRGB) {
@@ -316,13 +303,13 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
else if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
srgb_to_linearrgb_predivide_v4(tmp, from);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
srgb_to_linearrgb_v4(tmp, from);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -358,7 +345,7 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
if(profile_to == profile_from) {
/* no color space conversion */
for(x = 0; x < width; x++, from+=4, to+=4)
- byte_to_float_v4(to, from);
+ rgba_uchar_to_float(to, from);
}
else if(profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert sRGB to linear */
@@ -377,13 +364,13 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
/* convert linear to sRGB */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_predivide_v4(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_v4(to, tmp);
}
}
@@ -502,16 +489,16 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
/* convert to sRGB to linear */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
srgb_to_linearrgb_predivide_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
srgb_to_linearrgb_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -519,16 +506,16 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
/* convert from linear to sRGB */
if(predivide) {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_predivide_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
else {
for(x = 0; x < width; x++, from+=4, to+=4) {
- byte_to_float_v4(tmp, from);
+ rgba_uchar_to_float(tmp, from);
linearrgb_to_srgb_v4(tmp, tmp);
- float_to_byte_v4(to, tmp);
+ rgba_float_to_uchar(to, tmp);
}
}
}
@@ -658,15 +645,19 @@ void IMB_convert_profile(ImBuf *ibuf, int profile)
profile_from = IB_PROFILE_LINEAR_RGB;
else if(ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE))
profile_from = IB_PROFILE_SRGB;
- else
+ else {
BLI_assert(0);
+ profile_from = IB_PROFILE_SRGB; /* dummy, should never happen */
+ }
if(profile == IB_PROFILE_LINEAR_RGB)
profile_to = IB_PROFILE_LINEAR_RGB;
else if(ELEM(profile, IB_PROFILE_SRGB, IB_PROFILE_NONE))
profile_to = IB_PROFILE_SRGB;
- else
+ else {
BLI_assert(0);
+ profile_to = IB_PROFILE_SRGB; /* dummy, should never happen */
+ }
/* do conversion */
if(ibuf->rect_float) {
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 0e58ca6bd61..97b88692822 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -128,8 +128,8 @@ typedef struct Library {
ID id;
ID *idblock;
struct FileData *filedata;
- char name[240]; /* path name used for reading, can be relative and edited in the outliner */
- char filepath[240]; /* absolute filepath, this is only for convenience,
+ char name[1024]; /* path name used for reading, can be relative and edited in the outliner */
+ char filepath[1024]; /* absolute filepath, this is only for convenience,
* 'name' is the real path used on file read but in
* some cases its useful to access the absolute one,
* This is set on file read.
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 6e7385d683d..690c3c95964 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -59,7 +59,7 @@ typedef struct Brush {
struct ImBuf *icon_imbuf;
PreviewImage *preview;
- char icon_filepath[240];
+ char icon_filepath[1024]; /* 1024 = FILE_MAX */
float normal_weight;
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index 00a0cf8881f..a4bb5715174 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -55,7 +55,7 @@ typedef struct CustomDataLayer {
#define MAX_CUSTOMDATA_LAYER_NAME 64
typedef struct CustomDataExternal {
- char filename[240]; /* FILE_MAX */
+ char filename[1024]; /* FILE_MAX */
} CustomDataExternal;
/** structure which stores custom element data associated with mesh elements
diff --git a/source/blender/makesdna/DNA_dynamicpaint_types.h b/source/blender/makesdna/DNA_dynamicpaint_types.h
index cee8e5cd8d7..aff4607da51 100644
--- a/source/blender/makesdna/DNA_dynamicpaint_types.h
+++ b/source/blender/makesdna/DNA_dynamicpaint_types.h
@@ -55,6 +55,7 @@ struct PaintSurfaceData;
#define MOD_DPAINT_WAVE_OPEN_BORDERS (1<<7) /* passes waves through mesh edges */
#define MOD_DPAINT_DISP_INCREMENTAL (1<<8) /* builds displace on top of earlier values */
+#define MOD_DPAINT_USE_DRYING (1<<9) /* use drying */
#define MOD_DPAINT_OUT1 (1<<10) /* output primary surface */
#define MOD_DPAINT_OUT2 (1<<11) /* output secondary surface */
@@ -69,8 +70,8 @@ struct PaintSurfaceData;
/* effect */
#define MOD_DPAINT_EFFECT_DO_SPREAD (1<<0) /* do spread effect */
-#define MOD_DPAINT_EFFECT_DO_DRIP (1<<1) /* do spread effect */
-#define MOD_DPAINT_EFFECT_DO_SHRINK (1<<2) /* do spread effect */
+#define MOD_DPAINT_EFFECT_DO_DRIP (1<<1) /* do drip effect */
+#define MOD_DPAINT_EFFECT_DO_SHRINK (1<<2) /* do shrink effect */
/* preview_id */
#define MOD_DPAINT_SURFACE_PREV_PAINT 0
@@ -114,18 +115,20 @@ typedef struct DynamicPaintSurface {
char init_layername[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
int dry_speed, diss_speed;
+ float color_dry_threshold;
float depth_clamp, disp_factor;
float spread_speed, color_spread_speed, shrink_speed;
float drip_vel, drip_acc;
+ /* per surface brush settings */
+ float influence_scale, radius_scale;
+
/* wave settings */
float wave_damping, wave_speed, wave_timescale, wave_spring;
- int pad_;
-
char uvlayer_name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
- char image_output_path[240];
+ char image_output_path[1024]; /* 1024 = FILE_MAX */
char output_name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
char output_name2[64]; /* MAX_CUSTOMDATA_LAYER_NAME */ /* some surfaces have 2 outputs */
diff --git a/source/blender/makesdna/DNA_fileglobal_types.h b/source/blender/makesdna/DNA_fileglobal_types.h
index 31ad628d630..ed9f3cec987 100644
--- a/source/blender/makesdna/DNA_fileglobal_types.h
+++ b/source/blender/makesdna/DNA_fileglobal_types.h
@@ -51,7 +51,7 @@ typedef struct FileGlobal {
int revision; /* svn revision from buildinfo */
int pad;
/* file path where this was saved, for recover */
- char filename[240]; /* 240 = FILE_MAX */
+ char filename[1024]; /* 1024 = FILE_MAX */
} FileGlobal;
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index a1b0ab06ecd..8f6cc5bf354 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -69,7 +69,7 @@ typedef struct ImageUser {
typedef struct Image {
ID id;
- char name[240]; /* file path */
+ char name[1024]; /* file path, 1024 = FILE_MAX */
ListBase ibufs; /* not written in file */
struct GPUTexture *gputexture; /* not written in file */
@@ -120,6 +120,7 @@ typedef struct Image {
#define IMA_DEPRECATED 64
#define IMA_OLD_PREMUL 128
#define IMA_CM_PREDIVIDE 256
+#define IMA_USED_FOR_RENDER 512
/* Image.tpageflag */
#define IMA_TILES 1
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index e310f148110..dca401f12e8 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -773,7 +773,7 @@ typedef struct OceanModifierData {
int bakestart;
int bakeend;
- char cachepath[240]; // FILE_MAX
+ char cachepath[1024]; // FILE_MAX
char foamlayername[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
char cached;
char geometry_mode;
diff --git a/source/blender/makesdna/DNA_movieclip_types.h b/source/blender/makesdna/DNA_movieclip_types.h
index 5d2f2f5978f..1a56c273922 100644
--- a/source/blender/makesdna/DNA_movieclip_types.h
+++ b/source/blender/makesdna/DNA_movieclip_types.h
@@ -51,7 +51,7 @@ typedef struct MovieClipUser {
} MovieClipUser;
typedef struct MovieClipProxy {
- char dir[160]; /* custom directory for index and proxy files (defaults to BL_proxy) */
+ char dir[768]; /* custom directory for index and proxy files (defaults to BL_proxy) */
short tc; /* time code in use */
short quality; /* proxy build quality */
@@ -64,7 +64,7 @@ typedef struct MovieClipProxy {
typedef struct MovieClip {
ID id;
- char name[240]; /* file path */
+ char name[1024]; /* file path, 1024 = FILE_MAX */
int source; /* sequence or movie */
int lastframe; /* last accessed frame number */
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index fe4f6905f42..33ac75912fa 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -85,19 +85,21 @@ typedef struct bNodeSocket {
/* execution data */
short stack_index; /* local stack index */
- short stack_type; /* deprecated, kept for forward compatibility */
+ /* XXX deprecated, kept for forward compatibility */
+ short stack_type DNA_DEPRECATED;
int pad3;
void *cache; /* cached data from execution */
/* internal data to retrieve relations and groups */
int own_index; /* group socket identifiers, to find matching pairs after reading files */
- int to_index DNA_DEPRECATED; /* XXX deprecated, only used for restoring old group node links */
+ /* XXX deprecated, only used for restoring old group node links */
+ int to_index DNA_DEPRECATED;
struct bNodeSocket *groupsock;
struct bNodeLink *link; /* a link pointer, set in ntreeUpdateTree */
- /* DEPRECATED only needed for do_versions */
- bNodeStack ns; /* custom data for inputs, only UI writes in this */
+ /* XXX deprecated, socket input values are stored in default_value now. kept for forward compatibility */
+ bNodeStack ns DNA_DEPRECATED; /* custom data for inputs, only UI writes in this */
} bNodeSocket;
/* sock->type */
@@ -347,7 +349,7 @@ typedef struct NodeHueSat {
} NodeHueSat;
typedef struct NodeImageFile {
- char name[256];
+ char name[1024]; /* 1024 = FILE_MAX */
struct ImageFormatData im_format;
int sfra, efra;
} NodeImageFile;
diff --git a/source/blender/makesdna/DNA_object_fluidsim.h b/source/blender/makesdna/DNA_object_fluidsim.h
index 022dc53848f..3f87f8a3e9c 100644
--- a/source/blender/makesdna/DNA_object_fluidsim.h
+++ b/source/blender/makesdna/DNA_object_fluidsim.h
@@ -89,8 +89,8 @@ typedef struct FluidsimSettings {
struct Mesh *meshBB;
/* store output path, and file prefix for baked fluid surface */
- /* strlens; 80= FILE_MAXFILE, 160= FILE_MAXDIR */
- char surfdataPath[240];
+ /* strlens; 256= FILE_MAXFILE, 768= FILE_MAXDIR */
+ char surfdataPath[1024];
/* store start coords of axis aligned bounding box together with size */
/* values are inited during derived mesh display */
diff --git a/source/blender/makesdna/DNA_object_force.h b/source/blender/makesdna/DNA_object_force.h
index 28c28bbf329..1707c0d3929 100644
--- a/source/blender/makesdna/DNA_object_force.h
+++ b/source/blender/makesdna/DNA_object_force.h
@@ -195,7 +195,7 @@ typedef struct PointCache {
char name[64];
char prev_name[64];
char info[64];
- char path[240]; /* file path */
+ char path[1024]; /* file path, 1024 = FILE_MAX */
char *cached_frames; /* array of length endframe-startframe+1 with flags to indicate cached frames */
/* can be later used for other per frame flags too if needed */
struct ListBase mem_cache;
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 5cb6fca7c5e..52cd9d3c09b 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -476,14 +476,14 @@ typedef struct RenderData {
float bake_maxdist, bake_biasdist, bake_pad;
/* path to render output */
- char pic[240];
+ char pic[1024]; /* 1024 = FILE_MAX */
/* stamps flags. */
int stamp;
short stamp_font_id, pad3; /* select one of blenders bitmap fonts */
/* stamp info user data. */
- char stamp_udata[160];
+ char stamp_udata[768];
/* foreground/background color. */
float fg_stamp[4];
@@ -676,10 +676,20 @@ typedef struct GameData {
#define GAME_MAT_MULTITEX 1
#define GAME_MAT_GLSL 2
-/* *************************************************************** */
+/* UV Paint */
+#define UV_SCULPT_LOCK_BORDERS 1
+#define UV_SCULPT_ALL_ISLANDS 2
+
+#define UV_SCULPT_TOOL_PINCH 1
+#define UV_SCULPT_TOOL_RELAX 2
+#define UV_SCULPT_TOOL_GRAB 3
+
+#define UV_SCULPT_TOOL_RELAX_LAPLACIAN 1
+#define UV_SCULPT_TOOL_RELAX_HC 2
+
/* Markers */
-typedef struct TimeMarker {
+typedef struct TimeMarker {
struct TimeMarker *next, *prev;
int frame;
char name[64];
@@ -785,6 +795,9 @@ typedef struct Sculpt {
int pad;
} Sculpt;
+typedef struct UvSculpt {
+ Paint paint;
+} UvSculpt;
/* ------------------------------------------- */
/* Vertex Paint */
@@ -860,6 +873,7 @@ typedef struct ToolSettings {
VPaint *vpaint; /* vertex paint */
VPaint *wpaint; /* weight paint */
Sculpt *sculpt;
+ UvSculpt *uvsculpt; /* uv smooth */
/* Vertex groups */
float vgroup_weight;
@@ -899,7 +913,7 @@ typedef struct ToolSettings {
short uvcalc_mapalign;
short uvcalc_flag;
short uv_flag, uv_selectmode;
- short uv_pad;
+ short uv_subsurf_level;
/* Grease Pencil */
short gpencil_flags;
@@ -971,10 +985,14 @@ typedef struct ToolSettings {
char auto_normalize; /*auto normalizing mode in wpaint*/
char multipaint; /* paint multiple bones in wpaint */
+ /* UV painting */
+ int use_uv_sculpt;
+ int uv_sculpt_settings;
+ int uv_sculpt_tool;
+ int uv_relax_method;
/* XXX: these sculpt_paint_* fields are deprecated, use the
unified_paint_settings field instead! */
- short sculpt_paint_settings DNA_DEPRECATED;
- short pad1;
+ short sculpt_paint_settings DNA_DEPRECATED; short pad1;
int sculpt_paint_unified_size DNA_DEPRECATED;
float sculpt_paint_unified_unprojected_radius DNA_DEPRECATED;
float sculpt_paint_unified_alpha DNA_DEPRECATED;
@@ -1427,6 +1445,7 @@ typedef enum SculptFlags {
#define UVCALC_FILLHOLES 1
#define UVCALC_NO_ASPECT_CORRECT 2 /* would call this UVCALC_ASPECT_CORRECT, except it should be default with old file */
#define UVCALC_TRANSFORM_CORRECT 4 /* adjust UV's while transforming to avoid distortion */
+#define UVCALC_USESUBSURF 8 /* Use mesh data after subsurf to compute UVs*/
/* toolsettings->uv_flag */
#define UV_SYNC_SELECTION 1
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index fa501de8d6d..20399e541d7 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -41,10 +41,10 @@ struct Ipo;
struct Scene;
struct bSound;
-/* strlens; 80= FILE_MAXFILE, 160= FILE_MAXDIR */
+/* strlens; 256= FILE_MAXFILE, 768= FILE_MAXDIR */
typedef struct StripElem {
- char name[80];
+ char name[256];
int orig_width, orig_height;
} StripElem;
@@ -71,10 +71,10 @@ typedef struct StripColorBalance {
} StripColorBalance;
typedef struct StripProxy {
- char dir[160]; // custom directory for index and proxy files
+ char dir[768]; // custom directory for index and proxy files
// (defaults to BL_proxy)
- char file[80]; // custom file
+ char file[256]; // custom file
struct anim *anim; // custom proxy anim file
short tc; // time code in use
@@ -91,7 +91,7 @@ typedef struct Strip {
int rt, len, us, done;
int startstill, endstill;
StripElem *stripdata;
- char dir[160];
+ char dir[768];
StripProxy *proxy;
StripCrop *crop;
StripTransform *transform;
@@ -100,7 +100,7 @@ typedef struct Strip {
typedef struct PluginSeq {
- char name[256];
+ char name[1024]; /* 1024 = FILE_MAX */
void *handle;
char *pname;
@@ -191,8 +191,8 @@ typedef struct Editing {
/* Context vars, used to be static */
Sequence *act_seq;
- char act_imagedir[256];
- char act_sounddir[256];
+ char act_imagedir[1024]; /* 1024 = FILE_MAX */
+ char act_sounddir[1024]; /* 1024 = FILE_MAX */
int over_ofs, over_cfra;
int over_flag, pad;
@@ -353,7 +353,7 @@ typedef struct SpeedControlVars {
*/
-#define SEQ_HAS_PATH(_seq) (ELEM5((_seq)->type, SEQ_MOVIE, SEQ_IMAGE, SEQ_SOUND, SEQ_RAM_SOUND, SEQ_HD_SOUND))
+#define SEQ_HAS_PATH(_seq) (ELEM4((_seq)->type, SEQ_MOVIE, SEQ_IMAGE, SEQ_RAM_SOUND, SEQ_HD_SOUND))
#endif
diff --git a/source/blender/makesdna/DNA_sound_types.h b/source/blender/makesdna/DNA_sound_types.h
index f530730a544..1dab9effa9e 100644
--- a/source/blender/makesdna/DNA_sound_types.h
+++ b/source/blender/makesdna/DNA_sound_types.h
@@ -49,7 +49,7 @@ typedef struct bSound {
/**
* The path to the sound file.
*/
- char name[240];
+ char name[1024]; /* 1024 = FILE_MAX */
/**
* The packed file.
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index aa7a84c577b..8f986a5f7cc 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -174,10 +174,11 @@ typedef struct SpaceSeq {
typedef struct FileSelectParams {
char title[32]; /* title, also used for the text of the execute button */
- char dir[240]; /* directory */
- char file[80]; /* file */
- char renamefile[80];
- char renameedit[80]; /* annoying but the first is only used for initialization */
+ char dir[1056]; /* directory, FILE_MAX_LIBEXTRA, 1024 + 32, this is for extreme case when 1023 length path
+ * needs to be linked in, where foo.blend/Armature need adding */
+ char file[256]; /* file */
+ char renamefile[256];
+ char renameedit[256]; /* annoying but the first is only used for initialization */
char filter_glob[64]; /* list of filetypes to filter */
@@ -343,8 +344,9 @@ typedef struct Script {
void *py_globaldict;
int flags, lastspace;
- char scriptname[256]; /* store the script file here so we can re-run it on loading blender, if "Enable Scripts" is on */
- char scriptarg[256];
+ /* store the script file here so we can re-run it on loading blender, if "Enable Scripts" is on */
+ char scriptname[1024]; /* 1024 = FILE_MAX */
+ char scriptarg[256]; /* 1024 = FILE_MAX */
} Script;
#define SCRIPT_SET_NULL(_script) _script->py_draw = _script->py_event = _script->py_button = _script->py_browsercallback = _script->py_globaldict = NULL; _script->flags = 0;
@@ -622,9 +624,11 @@ enum FileSortTypeE {
/* these values need to be hardcoded in structs, dna does not recognize defines */
/* also defined in BKE */
-#define FILE_MAXDIR 160
-#define FILE_MAXFILE 80
-#define FILE_MAX 240
+#define FILE_MAXDIR 768
+#define FILE_MAXFILE 256
+#define FILE_MAX 1024
+
+#define FILE_MAX_LIBEXTRA (FILE_MAX + 32)
/* filesel types */
#define FILE_UNIX 8
diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h
index e711124d39c..de844fd2d7f 100644
--- a/source/blender/makesdna/DNA_texture_types.h
+++ b/source/blender/makesdna/DNA_texture_types.h
@@ -105,7 +105,7 @@ typedef unsigned short dna_ushort_fix;
#endif
typedef struct PluginTex {
- char name[160];
+ char name[1024];
void *handle;
char *pname;
@@ -200,7 +200,7 @@ typedef struct VoxelData {
struct Object *object; /* for rendering smoke sims */
float int_multiplier;
int still_frame;
- char source_path[240];
+ char source_path[1024]; /* 1024 = FILE_MAX */
/* temporary data */
float *dataset;
diff --git a/source/blender/makesdna/DNA_tracking_types.h b/source/blender/makesdna/DNA_tracking_types.h
index a8b3a7183cf..6ab8b5524ff 100644
--- a/source/blender/makesdna/DNA_tracking_types.h
+++ b/source/blender/makesdna/DNA_tracking_types.h
@@ -91,12 +91,8 @@ typedef struct MovieTrackingTrack {
float bundle_pos[3]; /* reconstructed position */
float error; /* average track reprojection error */
- int pad;
-
/* ** UI editing ** */
int flag, pat_flag, search_flag; /* flags (selection, ...) */
- short transflag; /* transform flags */
- char pad3[2];
float color[3]; /* custom color for track */
/* tracking algorithm to use; can be KLT or SAD */
@@ -213,7 +209,8 @@ enum {
/* MovieTrackingMarker->flag */
#define MARKER_DISABLED (1<<0)
#define MARKER_TRACKED (1<<1)
-#define MARKER_GRAPH_SEL (1<<2)
+#define MARKER_GRAPH_SEL_X (1<<2)
+#define MARKER_GRAPH_SEL_Y (1<<3)
/* MovieTrackingTrack->flag */
#define TRACK_HAS_BUNDLE (1<<1)
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 5be3799a419..cf7aa79de1b 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -60,7 +60,7 @@ struct ColorBand;
/* first font is the default (index 0), others optional */
typedef struct uiFont {
struct uiFont *next, *prev;
- char filename[256];
+ char filename[1024];/* 1024 = FILE_MAX */
short blf_id; /* from blfont lib */
short uifont_id; /* own id */
short r_to_l; /* fonts that read from left to right */
@@ -158,7 +158,7 @@ typedef struct ThemeUI {
uiPanelColors panel;
- char iconfile[80]; // FILE_MAXFILE length
+ char iconfile[256]; // FILE_MAXFILE length
float icon_alpha;
float pad;
@@ -253,7 +253,12 @@ typedef struct ThemeSpace {
char hpad[7];
char preview_back[4];
-
+ char preview_stitch_face[4];
+ char preview_stitch_edge[4];
+ char preview_stitch_vert[4];
+ char preview_stitch_stitchable[4];
+ char preview_stitch_unstitchable[4];
+ char preview_stitch_active[4];
} ThemeSpace;
@@ -319,16 +324,16 @@ typedef struct SolidLight {
typedef struct UserDef {
int flag, dupflag;
int savetime;
- char tempdir[160]; // FILE_MAXDIR length
- char fontdir[160];
- char renderdir[240]; // FILE_MAX length
- char textudir[160];
- char plugtexdir[160];
- char plugseqdir[160];
- char pythondir[160];
- char sounddir[160];
- char image_editor[240]; // FILE_MAX length
- char anim_player[240]; // FILE_MAX length
+ char tempdir[768]; /* FILE_MAXDIR length */
+ char fontdir[768];
+ char renderdir[1024]; /* FILE_MAX length */
+ char textudir[768];
+ char plugtexdir[768];
+ char plugseqdir[768];
+ char pythondir[768];
+ char sounddir[768];
+ char image_editor[1024]; /* 1024 = FILE_MAX */
+ char anim_player[1024]; /* 1024 = FILE_MAX */
int anim_player_preset;
short v2d_min_gridsize; /* minimum spacing between gridlines in View2D grids */
@@ -392,19 +397,17 @@ typedef struct UserDef {
short widget_unit; /* defaults to 20 for 72 DPI setting */
short anisotropic_filter;
- /*short pad[3]; */
+ short use_16bit_textures, pad8;
float ndof_sensitivity; /* overall sensitivity of 3D mouse */
int ndof_flag; /* flags for 3D mouse */
- char versemaster[160];
- char verseuser[160];
float glalphaclip;
short autokey_mode; /* autokeying mode */
short autokey_flag; /* flags for autokeying */
- short text_render, pad9[3]; /*options for text rendering*/
+ short text_render, pad9; /*options for text rendering*/
struct ColorBand coba_weight; /* from texture.h */
diff --git a/source/blender/makesdna/DNA_vfont_types.h b/source/blender/makesdna/DNA_vfont_types.h
index 7132751848d..d6168af6028 100644
--- a/source/blender/makesdna/DNA_vfont_types.h
+++ b/source/blender/makesdna/DNA_vfont_types.h
@@ -42,7 +42,7 @@ struct VFontData;
typedef struct VFont {
ID id;
- char name[256];
+ char name[1024]; /* 1024 = FILE_MAX */
struct VFontData *data;
struct PackedFile * packedfile;
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 3996e109b2c..7487a4429b1 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -451,6 +451,7 @@ extern StructRNA RNA_Scopes;
extern StructRNA RNA_Screen;
extern StructRNA RNA_ScrewModifier;
extern StructRNA RNA_Sculpt;
+extern StructRNA RNA_SelectedUvElement;
extern StructRNA RNA_Sensor;
extern StructRNA RNA_Sequence;
extern StructRNA RNA_SequenceColorBalance;
diff --git a/source/blender/makesrna/intern/SConscript b/source/blender/makesrna/intern/SConscript
index b74972b204c..26fa793de9d 100644
--- a/source/blender/makesrna/intern/SConscript
+++ b/source/blender/makesrna/intern/SConscript
@@ -101,6 +101,10 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
if env['WITH_BF_INTERNATIONAL']:
defs.append('WITH_INTERNATIONAL')
+if not env['BF_DEBUG']:
+ defs.append('NDEBUG')
+
+
makesrna_tool.Append(CPPDEFINES=defs)
makesrna_tool.Append (CPPPATH = Split(incs))
diff --git a/source/blender/makesrna/intern/rna_controller.c b/source/blender/makesrna/intern/rna_controller.c
index 5278c1e3532..7dfb3597a29 100644
--- a/source/blender/makesrna/intern/rna_controller.c
+++ b/source/blender/makesrna/intern/rna_controller.c
@@ -48,6 +48,7 @@ EnumPropertyItem controller_type_items[] ={
#ifdef RNA_RUNTIME
#include "BKE_sca.h"
+#include "DNA_actuator_types.h"
static struct StructRNA* rna_Controller_refine(struct PointerRNA *ptr)
{
@@ -132,6 +133,18 @@ static void rna_Controller_state_number_set(struct PointerRNA *ptr, const int va
cont->state_mask = (1 << (value - 1));
}
+static void rna_Controller_actuators_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ bController *cont = (bController *)ptr->data;
+ rna_iterator_array_begin(iter, cont->links, sizeof(bActuator *), (int)cont->totlinks, 0, NULL);
+}
+
+static int rna_Controller_actuators_length(PointerRNA *ptr)
+{
+ bController *cont = (bController *)ptr->data;
+ return (int) cont->totlinks;
+}
+
#if 0 /* editable is set to false, comment for now. */
static void rna_Controller_state_get(PointerRNA *ptr, int *values)
{
@@ -212,6 +225,12 @@ void RNA_def_controller(BlenderRNA *brna)
RNA_def_property_ui_icon(prop, ICON_BOOKMARKS, 1);
RNA_def_property_update(prop, NC_LOGIC, NULL);
+ prop= RNA_def_property(srna, "actuators", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
+ RNA_def_property_struct_type(prop, "Actuator");
+ RNA_def_property_ui_text(prop, "Actuators", "The list containing the actuators connected to the controller");
+ RNA_def_property_collection_funcs(prop, "rna_Controller_actuators_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", "rna_Controller_actuators_length", NULL, NULL, NULL);
+
/* State */
// array of OB_MAX_STATES
diff --git a/source/blender/makesrna/intern/rna_dynamicpaint.c b/source/blender/makesrna/intern/rna_dynamicpaint.c
index 4886a4f30b1..95770685077 100644
--- a/source/blender/makesrna/intern/rna_dynamicpaint.c
+++ b/source/blender/makesrna/intern/rna_dynamicpaint.c
@@ -395,6 +395,10 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_range(prop, 1.0, 10000.0);
RNA_def_property_ui_range(prop, 1.0, 10000.0, 5, 0);
RNA_def_property_ui_text(prop, "Dissolve Speed", "Approximately in how many frames should dissolve happen");
+
+ prop= RNA_def_property(srna, "use_drying", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_DPAINT_USE_DRYING);
+ RNA_def_property_ui_text(prop, "Dry", "Enable to make surface wetness dry over time");
prop= RNA_def_property(srna, "dry_speed", PROP_INT, PROP_NONE);
RNA_def_property_range(prop, 1.0, 10000.0);
@@ -443,6 +447,20 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Anti-aliasing", "Use 5x multisampling to smoothen paint edges");
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaintSurface_reset");
+ prop= RNA_def_property(srna, "brush_influence_scale", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "influence_scale");
+ RNA_def_property_range(prop, 0.0, 1.0);
+ RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
+ RNA_def_property_ui_text(prop, "Influence Scale", "Adjust influence brush objects have on this surface");
+ RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaint_redoModifier");
+
+ prop= RNA_def_property(srna, "brush_radius_scale", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "radius_scale");
+ RNA_def_property_range(prop, 0.0, 10.0);
+ RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
+ RNA_def_property_ui_text(prop, "Radius Scale", "Adjust radius of proximity brushes or particles for this surface");
+ RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaint_redoModifier");
+
/*
* Initial Color
*/
@@ -454,6 +472,7 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING_DRAW|ND_MODIFIER, "rna_DynamicPaintSurface_initialcolortype");
prop= RNA_def_property(srna, "init_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Color", "Initial color of the surface");
RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING_DRAW|ND_MODIFIER, "rna_DynamicPaintSurface_reset");
@@ -495,6 +514,12 @@ static void rna_def_canvas_surface(BlenderRNA *brna)
RNA_def_property_ui_range(prop, 0.01, 5.0, 1, 2);
RNA_def_property_ui_text(prop, "Spread Speed", "How fast spread effect moves on the canvas surface");
+ prop= RNA_def_property(srna, "color_dry_threshold", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "color_dry_threshold");
+ RNA_def_property_range(prop, 0.0, 1.0);
+ RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
+ RNA_def_property_ui_text(prop, "Color Dry", "The wetness level when colors start to shift to the background");
+
prop= RNA_def_property(srna, "color_spread_speed", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "color_spread_speed");
RNA_def_property_range(prop, 0.0, 2.0);
diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c
index 428f56b5130..f853e7b8dd9 100644
--- a/source/blender/makesrna/intern/rna_fluidsim.c
+++ b/source/blender/makesrna/intern/rna_fluidsim.c
@@ -304,7 +304,7 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_fluid_find_enframe");
prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_string_maxlength(prop, 240);
+ RNA_def_property_string_maxlength(prop, FILE_MAX);
RNA_def_property_string_sdna(prop, NULL, "surfdataPath");
RNA_def_property_ui_text(prop, "Path", "Directory (and/or filename prefix) to store baked fluid simulation files in");
RNA_def_property_update(prop, 0, "rna_fluid_update");
@@ -381,7 +381,7 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna)
RNA_def_property_int_sdna(prop, NULL, "surfaceSubdivs");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_range(prop, 0, 5);
- RNA_def_property_ui_text(prop, "Surface Subdivisions", "Number of isosurface subdivisions (this is necessary for the inclusion of particles into the surface generation - WARNING: can lead to longer computation times !)");
+ RNA_def_property_ui_text(prop, "Surface Subdivisions", "Number of isosurface subdivisions (this is necessary for the inclusion of particles into the surface generation - WARNING: can lead to longer computation times !)");
prop= RNA_def_property(srna, "use_speed_vectors", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "domainNovecgen", 0);
@@ -554,7 +554,7 @@ static void rna_def_fluidsim_particle(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Alpha Influence", "Amount of particle alpha change, inverse of size influence: 0=off (all same alpha), 1=full (large particles get lower alphas, smaller ones higher values)");
prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_string_maxlength(prop, 240);
+ RNA_def_property_string_maxlength(prop, FILE_MAX);
RNA_def_property_string_sdna(prop, NULL, "surfdataPath");
RNA_def_property_ui_text(prop, "Path", "Directory (and/or filename prefix) to store and load particles from");
RNA_def_property_update(prop, 0, "rna_fluid_update");
diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c
index 2af4c04d1ce..d5f39dbd28a 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -32,6 +32,8 @@
#include "rna_internal.h"
+#include "BKE_utildefines.h"
+
#ifdef RNA_RUNTIME
#include "BKE_main.h"
@@ -330,7 +332,7 @@ void RNA_def_main(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_BLENDER);
prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_string_maxlength(prop, 240);
+ RNA_def_property_string_maxlength(prop, FILE_MAX);
RNA_def_property_string_funcs(prop, "rna_Main_filepath_get", "rna_Main_filepath_length", "rna_Main_filepath_set");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 74620b11d50..be4cfd583a9 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1709,6 +1709,10 @@ static void rna_def_mesh_vertices(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "ED_mesh_vertices_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
+
+ func= RNA_def_function(srna, "remove", "ED_mesh_vertices_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to remove", 0, INT_MAX);
}
/* mesh.edges */
@@ -1727,7 +1731,11 @@ static void rna_def_mesh_edges(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "ED_mesh_edges_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
- RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to add", 0, INT_MAX);
+
+ func= RNA_def_function(srna, "remove", "ED_mesh_edges_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to remove", 0, INT_MAX);
}
/* mesh.faces */
@@ -1756,7 +1764,11 @@ static void rna_def_mesh_faces(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "ED_mesh_faces_add");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
- RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of faces to add", 0, INT_MAX);
+
+ func= RNA_def_function(srna, "remove", "ED_mesh_faces_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of faces to remove", 0, INT_MAX);
}
/* mesh.vertex_colors */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index a04ddec2098..989202f785c 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3071,7 +3071,7 @@ static void rna_def_node_socket_subtype(BlenderRNA *brna, int type, int subtype,
};
#undef SUBTYPE
- #define SUBTYPE(socktype, stypename, id, idname) if (subtype==PROP_##id) propsubtype = PROP_##id;
+ #define SUBTYPE(socktype, stypename, id, idname) if (subtype == (PROP_##id)) propsubtype = PROP_##id;
NODE_DEFINE_SUBTYPES
#undef SUBTYPE
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 877da130357..0246e22d928 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -63,6 +63,7 @@
#include "BKE_font.h"
#include "BKE_mball.h"
#include "BKE_modifier.h"
+#include "BKE_cdderivedmesh.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
@@ -470,6 +471,44 @@ int rna_Object_is_modified(Object *ob, Scene *scene, int settings)
return object_is_modified(scene, ob) & settings;
}
+#ifndef NDEBUG
+void rna_Object_dm_info(struct Object *ob, int type, char *result)
+{
+ DerivedMesh *dm = NULL;
+ int dm_release = FALSE;
+ char *ret = NULL;
+
+ result[0] = '\0';
+
+ switch(type) {
+ case 0:
+ if (ob->type == OB_MESH) {
+ dm = CDDM_from_mesh(ob->data, ob);
+ ret = DM_debug_info(dm);
+ dm_release = TRUE;
+ }
+ break;
+ case 1:
+ dm = ob->derivedDeform;
+ break;
+ case 2:
+ dm = ob->derivedFinal;
+ break;
+ }
+
+ if (dm) {
+ ret = DM_debug_info(dm);
+ if (dm_release) {
+ dm->release(dm);
+ }
+ if (ret) {
+ strcpy(result, ret);
+ MEM_freeN(ret);
+ }
+ }
+}
+#endif /* NDEBUG */
+
#else
void RNA_api_object(StructRNA *srna)
@@ -483,6 +522,15 @@ void RNA_api_object(StructRNA *srna)
{0, NULL, 0, NULL, NULL}
};
+#ifndef NDEBUG
+ static EnumPropertyItem mesh_dm_info_items[] = {
+ {0, "SOURCE", 0, "Source", "Source mesh"},
+ {1, "DEFORM", 0, "Deform", "Objects deform mesh"},
+ {2, "FINAL", 0, "Final", "Objects final mesh"},
+ {0, NULL, 0, NULL, NULL}
+ };
+#endif
+
/* mesh */
func= RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
RNA_def_function_ui_description(func, "Create a Mesh datablock with modifiers applied");
@@ -585,6 +633,20 @@ void RNA_api_object(StructRNA *srna)
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_boolean(func, "result", 0, "", "Object visibility");
RNA_def_function_return(func, parm);
+
+
+#ifndef NDEBUG
+ /* mesh */
+ func= RNA_def_function(srna, "dm_info", "rna_Object_dm_info");
+ RNA_def_function_ui_description(func, "Returns a string for derived mesh data");
+
+ parm= RNA_def_enum(func, "type", mesh_dm_info_items, 0, "", "Modifier settings to apply");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ /* weak!, no way to return dynamic string type */
+ parm= RNA_def_string(func, "result", "result", 16384, "result", "");
+ RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */
+ RNA_def_function_output(func, parm);
+#endif /* NDEBUG */
}
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index e8b6e9e05d3..9be42ad13af 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -64,6 +64,18 @@
#include "BLI_threads.h"
+EnumPropertyItem uv_sculpt_relaxation_items[] = {
+ {UV_SCULPT_TOOL_RELAX_LAPLACIAN, "LAPLACIAN", 0, "Laplacian", "Use Laplacian method for relaxation"},
+ {UV_SCULPT_TOOL_RELAX_HC, "HC", 0, "HC", "Use HC method for relaxation"},
+ {0, NULL, 0, NULL, NULL}};
+
+EnumPropertyItem uv_sculpt_tool_items[] = {
+ {UV_SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", "Pinch UVs"},
+ {UV_SCULPT_TOOL_RELAX, "RELAX", 0, "Relax", "Relax UVs"},
+ {UV_SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", "Grab UVs"},
+ {0, NULL, 0, NULL, NULL}};
+
+
EnumPropertyItem snap_target_items[] = {
{SCE_SNAP_TARGET_CLOSEST, "CLOSEST", 0, "Closest", "Snap closest point onto target"},
{SCE_SNAP_TARGET_CENTER, "CENTER", 0, "Center", "Snap center onto target"},
@@ -268,11 +280,17 @@ EnumPropertyItem image_color_depth_items[] = {
#include "ED_view3d.h"
#include "ED_mesh.h"
#include "ED_keyframing.h"
+#include "ED_image.h"
#include "RE_engine.h"
#include "FRS_freestyle.h"
+static void rna_SpaceImageEditor_uv_sculpt_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
+{
+ ED_space_image_uv_sculpt_update(bmain->wm.first, scene->toolsettings);
+}
+
static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
{
Scene *scene= (Scene*)ptr->data;
@@ -872,6 +890,7 @@ static EnumPropertyItem *rna_RenderSettings_qtcodecsettings_audiocodecType_itemf
#endif
#endif
+#ifdef WITH_FFMPEG
static void rna_FFmpegSettings_lossless_output_set(PointerRNA *ptr, int value)
{
Scene *scene = (Scene *) ptr->id.data;
@@ -881,10 +900,9 @@ static void rna_FFmpegSettings_lossless_output_set(PointerRNA *ptr, int value)
rd->ffcodecdata.flags |= FFMPEG_LOSSLESS_OUTPUT;
else
rd->ffcodecdata.flags &= ~FFMPEG_LOSSLESS_OUTPUT;
-#ifdef WITH_FFMPEG
ffmpeg_verify_lossless_format(rd, &rd->im_format);
-#endif
}
+#endif
static int rna_RenderSettings_active_layer_index_get(PointerRNA *ptr)
{
@@ -1476,10 +1494,38 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "imapaint");
RNA_def_property_ui_text(prop, "Image Paint", "");
+ prop= RNA_def_property(srna, "uv_sculpt", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "uvsculpt");
+ RNA_def_property_ui_text(prop, "UV Sculpt", "");
+
prop= RNA_def_property(srna, "particle_edit", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "particle");
RNA_def_property_ui_text(prop, "Particle Edit", "");
+ prop= RNA_def_property(srna, "use_uv_sculpt", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "use_uv_sculpt", 1);
+ RNA_def_property_ui_text(prop, "UV Sculpt", "Enable brush for uv sculpting");
+ RNA_def_property_ui_icon(prop, ICON_TPAINT_HLT, 0);
+ RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, "rna_SpaceImageEditor_uv_sculpt_update");
+
+ prop= RNA_def_property(srna, "uv_sculpt_lock_borders", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "uv_sculpt_settings", UV_SCULPT_LOCK_BORDERS);
+ RNA_def_property_ui_text(prop, "Lock Borders", "Disables editing of boundary edges");
+
+ prop= RNA_def_property(srna, "uv_sculpt_all_islands", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "uv_sculpt_settings", UV_SCULPT_ALL_ISLANDS);
+ RNA_def_property_ui_text(prop, "Sculpt All Islands", "Brush operates on all islands");
+
+ prop= RNA_def_property(srna, "uv_sculpt_tool", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "uv_sculpt_tool");
+ RNA_def_property_enum_items(prop, uv_sculpt_tool_items);
+ RNA_def_property_ui_text(prop, "UV Sculpt Tools", "Select Tools for the UV sculpt brushes");
+
+ prop= RNA_def_property(srna, "uv_relax_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "uv_relax_method");
+ RNA_def_property_enum_items(prop, uv_sculpt_relaxation_items);
+ RNA_def_property_ui_text(prop, "Relaxation Method", "Algorithm used for UV relaxation");
+
/* Transform */
prop= RNA_def_property(srna, "proportional_edit", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "proportional");
@@ -4285,6 +4331,28 @@ static void rna_def_scene_keying_sets_all(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET, NULL);
}
+/* Runtime property, used to remember uv indices, used only in UV stitch for now.
+ */
+static void rna_def_selected_uv_element(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna= RNA_def_struct(brna, "SelectedUvElement", "PropertyGroup");
+ RNA_def_struct_ui_text(srna, "Selected Uv Element", "");
+
+ /* store the index to the UV element selected */
+ prop= RNA_def_property(srna, "element_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_flag(prop, PROP_IDPROPERTY);
+ RNA_def_property_ui_text(prop, "Element Index", "");
+
+ prop= RNA_def_property(srna, "face_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_flag(prop, PROP_IDPROPERTY);
+ RNA_def_property_ui_text(prop, "Face Index", "");
+}
+
+
+
void RNA_def_scene(BlenderRNA *brna)
{
StructRNA *srna;
@@ -4618,6 +4686,7 @@ void RNA_def_scene(BlenderRNA *brna)
rna_def_scene_game_data(brna);
rna_def_scene_render_layer(brna);
rna_def_transform_orientation(brna);
+ rna_def_selected_uv_element(brna);
/* Scene API */
RNA_api_scene(srna);
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index cd929d3aeda..67304997571 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -289,6 +289,16 @@ static void rna_def_sculpt(BlenderRNA *brna)
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Sculpt_update");
}
+
+static void rna_def_uv_sculpt(BlenderRNA *brna)
+{
+ StructRNA *srna;
+
+ srna= RNA_def_struct(brna, "UvSculpt", "Paint");
+ RNA_def_struct_ui_text(srna, "UV Sculpting", "");
+}
+
+
/* use for weight paint too */
static void rna_def_vertex_paint(BlenderRNA *brna)
{
@@ -466,12 +476,12 @@ static void rna_def_particle_edit(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Brush", "");
prop= RNA_def_property(srna, "draw_step", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 2, 10);
+ RNA_def_property_range(prop, 1, 10);
RNA_def_property_ui_text(prop, "Steps", "How many steps to draw the path with");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_ParticleEdit_redo");
prop= RNA_def_property(srna, "fade_frames", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 2, 100);
+ RNA_def_property_range(prop, 1, 100);
RNA_def_property_ui_text(prop, "Frames", "How many frames to fade");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_ParticleEdit_update");
@@ -548,6 +558,7 @@ void RNA_def_sculpt_paint(BlenderRNA *brna)
{
rna_def_paint(brna);
rna_def_sculpt(brna);
+ rna_def_uv_sculpt(brna);
rna_def_vertex_paint(brna);
rna_def_image_paint(brna);
rna_def_particle_edit(brna);
diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c
index 6459c145a3a..4413eee9395 100644
--- a/source/blender/makesrna/intern/rna_sensor.c
+++ b/source/blender/makesrna/intern/rna_sensor.c
@@ -61,6 +61,7 @@ EnumPropertyItem sensor_type_items[] ={
#ifdef RNA_RUNTIME
#include "BKE_sca.h"
+#include "DNA_controller_types.h"
static StructRNA* rna_Sensor_refine(struct PointerRNA *ptr)
{
@@ -125,6 +126,19 @@ static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
}
/* Always keep in alphabetical order */
+
+static void rna_Sensor_controllers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ bSensor *sens = (bSensor *)ptr->data;
+ rna_iterator_array_begin(iter, sens->links, sizeof(bController *), (int)sens->totlinks, 0, NULL);
+}
+
+static int rna_Sensor_controllers_length(PointerRNA *ptr)
+{
+ bSensor *sens = (bSensor *)ptr->data;
+ return (int) sens->totlinks;
+}
+
EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
{
EnumPropertyItem *item= NULL;
@@ -327,6 +341,13 @@ static void rna_def_sensor(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Tap", "Trigger controllers only for an instant, even while the sensor remains true");
RNA_def_property_update(prop, NC_LOGIC, NULL);
+ prop= RNA_def_property(srna, "controllers", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
+ RNA_def_property_struct_type(prop, "Controller");
+ RNA_def_property_ui_text(prop, "Controllers", "The list containing the controllers connected to the sensor");
+ RNA_def_property_collection_funcs(prop, "rna_Sensor_controllers_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", "rna_Sensor_controllers_length", NULL, NULL, NULL);
+
+
RNA_api_sensor(srna);
}
diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c
index 01f3889d684..5573ceccf8f 100644
--- a/source/blender/makesrna/intern/rna_tracking.c
+++ b/source/blender/makesrna/intern/rna_tracking.c
@@ -1232,7 +1232,7 @@ static void rna_def_trackingObjects(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "remove", "rna_trackingObject_remove");
RNA_def_function_ui_description(func, "Remove tracking object from this movie clip");
- parm= RNA_def_pointer(func, "object", "MovieTrackingObject", "", "Motion tracking object to be removed");
+ RNA_def_pointer(func, "object", "MovieTrackingObject", "", "Motion tracking object to be removed");
/* active object */
prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index be0fec41aa1..8e3178a6298 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -823,7 +823,7 @@ static void rna_def_menu(BlenderRNA *brna)
"class name is \"OBJECT_MT_hello\", and bl_idname is not set by the "
"script, then bl_idname = \"OBJECT_MT_hello\")");
- prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
+ prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_TRANSLATE);
RNA_def_property_string_sdna(prop, NULL, "type->label");
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_property_ui_text(prop, "Label", "The menu label");
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 160787556ed..dad58ddbef6 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -37,6 +37,7 @@
#include "DNA_userdef_types.h"
#include "DNA_brush_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_scene_types.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -147,6 +148,12 @@ static void rna_userdef_gl_texture_limit_update(Main *bmain, Scene *scene, Point
rna_userdef_update(bmain, scene, ptr);
}
+static void rna_userdef_gl_use_16bit_textures(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ GPU_free_images();
+ rna_userdef_update(bmain, scene, ptr);
+}
+
static void rna_userdef_select_mouse_set(PointerRNA *ptr,int value)
{
UserDef *userdef = (UserDef*)ptr->data;
@@ -1633,6 +1640,42 @@ static void rna_def_userdef_theme_space_image(BlenderRNA *brna)
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Scope region background color", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_face", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_face");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview face color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_edge", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_edge");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview edge color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_vert", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_vert");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview vertex color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_stitchable", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_stitchable");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview stitchable color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_unstitchable", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_unstitchable");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview unstitchable color", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop= RNA_def_property(srna, "preview_stitch_active", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "preview_stitch_active");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_ui_text(prop, "Stitch preview active island", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
}
static void rna_def_userdef_theme_space_seq(BlenderRNA *brna)
@@ -2910,6 +2953,11 @@ static void rna_def_userdef_system(BlenderRNA *brna)
"Scale textures for the 3D View (looks nicer but uses more memory and slows image reloading)");
RNA_def_property_update(prop, 0, "rna_userdef_mipmap_update");
+ prop= RNA_def_property(srna, "use_16bit_textures", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "use_16bit_textures", 1);
+ RNA_def_property_ui_text(prop, "16 Bit Float Textures", "Use 16 bit per component texture for float images");
+ RNA_def_property_update(prop, 0, "rna_userdef_gl_use_16bit_textures");
+
prop= RNA_def_property(srna, "use_vertex_buffer_objects", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "gameflags", USER_DISABLE_VBO);
RNA_def_property_ui_text(prop, "VBOs", "Use Vertex Buffer Objects (or Vertex Arrays, if unsupported) for viewport rendering");
diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c
index e502878fca5..16f0912bd9b 100644
--- a/source/blender/modifiers/intern/MOD_boolean.c
+++ b/source/blender/modifiers/intern/MOD_boolean.c
@@ -47,7 +47,6 @@
#include "MOD_boolean_util.h"
#include "MOD_util.h"
-
static void copyData(ModifierData *md, ModifierData *target)
{
BooleanModifierData *bmd = (BooleanModifierData*) md;
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index 119934ea2f0..ebb5bd9ab9b 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -76,135 +76,150 @@ static int dependsOnTime(ModifierData *UNUSED(md))
}
static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
- DerivedMesh *derivedData,
- int UNUSED(useRenderParams),
- int UNUSED(isFinalCalc))
+ DerivedMesh *derivedData,
+ int UNUSED(useRenderParams),
+ int UNUSED(isFinalCalc))
{
DerivedMesh *dm = derivedData;
DerivedMesh *result;
BuildModifierData *bmd = (BuildModifierData*) md;
int i;
- int numFaces, numEdges;
+ int numFaces_dst, numEdges_dst;
int *vertMap, *edgeMap, *faceMap;
float frac;
GHashIterator *hashIter;
/* maps vert indices in old mesh to indices in new mesh */
GHash *vertHash = BLI_ghash_new(BLI_ghashutil_inthash,
- BLI_ghashutil_intcmp, "build ve apply gh");
+ BLI_ghashutil_intcmp, "build ve apply gh");
/* maps edge indices in new mesh to indices in old mesh */
GHash *edgeHash = BLI_ghash_new(BLI_ghashutil_inthash,
- BLI_ghashutil_intcmp, "build ed apply gh");
+ BLI_ghashutil_intcmp, "build ed apply gh");
- const int maxVerts= dm->getNumVerts(dm);
- const int maxEdges= dm->getNumEdges(dm);
- const int maxFaces= dm->getNumFaces(dm);
+ const int numVert_src= dm->getNumVerts(dm);
+ const int numEdge_src= dm->getNumEdges(dm);
+ const int numFace_src= dm->getNumFaces(dm);
- vertMap = MEM_callocN(sizeof(*vertMap) * maxVerts, "build modifier vertMap");
- for(i = 0; i < maxVerts; ++i) vertMap[i] = i;
- edgeMap = MEM_callocN(sizeof(*edgeMap) * maxEdges, "build modifier edgeMap");
- for(i = 0; i < maxEdges; ++i) edgeMap[i] = i;
- faceMap = MEM_callocN(sizeof(*faceMap) * maxFaces, "build modifier faceMap");
- for(i = 0; i < maxFaces; ++i) faceMap[i] = i;
+ vertMap = MEM_callocN(sizeof(*vertMap) * numVert_src, "build modifier vertMap");
+ for (i = 0; i < numVert_src; i++) vertMap[i] = i;
+ edgeMap = MEM_callocN(sizeof(*edgeMap) * numEdge_src, "build modifier edgeMap");
+ for (i = 0; i < numEdge_src; i++) edgeMap[i] = i;
+ faceMap = MEM_callocN(sizeof(*faceMap) * numFace_src, "build modifier faceMap");
+ for (i = 0; i < numFace_src; i++) faceMap[i] = i;
frac = (BKE_curframe(md->scene) - bmd->start) / bmd->length;
CLAMP(frac, 0.0f, 1.0f);
- numFaces = dm->getNumFaces(dm) * frac;
- numEdges = dm->getNumEdges(dm) * frac;
+ numFaces_dst = dm->getNumFaces(dm) * frac;
+ numEdges_dst = dm->getNumEdges(dm) * frac;
/* if there's at least one face, build based on faces */
- if(numFaces) {
- if(bmd->randomize)
+ if (numFaces_dst) {
+ if (bmd->randomize) {
BLI_array_randomize(faceMap, sizeof(*faceMap),
- maxFaces, bmd->seed);
+ numFace_src, bmd->seed);
+ }
/* get the set of all vert indices that will be in the final mesh,
- * mapped to the new indices
- */
- for(i = 0; i < numFaces; ++i) {
+ * mapped to the new indices
+ */
+ for (i = 0; i < numFaces_dst; i++) {
MFace mf;
dm->getFace(dm, faceMap[i], &mf);
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1)))
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v1),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v2)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v2))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v2),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v3)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v3))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v3),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(mf.v4 && !BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v4)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (mf.v4 && !BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v4))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(mf.v4),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
}
/* get the set of edges that will be in the new mesh (i.e. all edges
- * that have both verts in the new mesh)
- */
- for(i = 0; i < maxEdges; ++i) {
+ * that have both verts in the new mesh)
+ */
+ for (i = 0; i < numEdge_src; i++) {
MEdge me;
dm->getEdge(dm, i, &me);
- if(BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1))
- && BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
- BLI_ghash_insert(edgeHash,
- SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)), SET_INT_IN_POINTER(i));
+ if ( BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1)) &&
+ BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
+ {
+ BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)),
+ SET_INT_IN_POINTER(i));
+ }
}
- } else if(numEdges) {
- if(bmd->randomize)
+ }
+ else if (numEdges_dst) {
+ if (bmd->randomize) {
BLI_array_randomize(edgeMap, sizeof(*edgeMap),
- maxEdges, bmd->seed);
+ numEdge_src, bmd->seed);
+ }
/* get the set of all vert indices that will be in the final mesh,
- * mapped to the new indices
- */
- for(i = 0; i < numEdges; ++i) {
+ * mapped to the new indices
+ */
+ for (i = 0; i < numEdges_dst; i++) {
MEdge me;
dm->getEdge(dm, edgeMap[i], &me);
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1)))
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me.v1),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
- if(!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)))
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
+ if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2))) {
BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me.v2),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ }
}
/* get the set of edges that will be in the new mesh
- */
- for(i = 0; i < numEdges; ++i) {
+ */
+ for (i = 0; i < numEdges_dst; i++) {
MEdge me;
dm->getEdge(dm, edgeMap[i], &me);
BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(BLI_ghash_size(edgeHash)),
- SET_INT_IN_POINTER(edgeMap[i]));
+ SET_INT_IN_POINTER(edgeMap[i]));
}
- } else {
+ }
+ else {
int numVerts = dm->getNumVerts(dm) * frac;
- if(bmd->randomize)
+ if (bmd->randomize) {
BLI_array_randomize(vertMap, sizeof(*vertMap),
- maxVerts, bmd->seed);
+ numVert_src, bmd->seed);
+ }
/* get the set of all vert indices that will be in the final mesh,
* mapped to the new indices
*/
- for(i = 0; i < numVerts; ++i)
- BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(vertMap[i]), SET_INT_IN_POINTER(i));
+ for (i = 0; i < numVerts; i++) {
+ BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(vertMap[i]),
+ SET_INT_IN_POINTER(i));
+ }
}
/* now we know the number of verts, edges and faces, we can create
- * the mesh
- */
+ * the mesh
+ */
result = CDDM_from_template(dm, BLI_ghash_size(vertHash),
- BLI_ghash_size(edgeHash), numFaces);
+ BLI_ghash_size(edgeHash), numFaces_dst);
/* copy the vertices across */
- for( hashIter = BLI_ghashIterator_new(vertHash);
- !BLI_ghashIterator_isDone(hashIter);
- BLI_ghashIterator_step(hashIter)
- ) {
+ for ( hashIter = BLI_ghashIterator_new(vertHash);
+ !BLI_ghashIterator_isDone(hashIter);
+ BLI_ghashIterator_step(hashIter))
+ {
MVert source;
MVert *dest;
int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter));
@@ -219,7 +234,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
BLI_ghashIterator_free(hashIter);
/* copy the edges across, remapping indices */
- for(i = 0; i < BLI_ghash_size(edgeHash); ++i) {
+ for (i = 0; i < BLI_ghash_size(edgeHash); i++) {
MEdge source;
MEdge *dest;
int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i)));
@@ -235,7 +250,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
}
/* copy the faces across, remapping indices */
- for(i = 0; i < numFaces; ++i) {
+ for (i = 0; i < numFaces_dst; i++) {
MFace source;
MFace *dest;
int orig_v4;
@@ -248,7 +263,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2)));
source.v3 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v3)));
- if(source.v4)
+ if (source.v4)
source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4)));
DM_copy_face_data(dm, result, faceMap[i], i, 1);
@@ -258,14 +273,14 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
}
CDDM_calc_normals(result);
-
+
BLI_ghash_free(vertHash, NULL, NULL);
BLI_ghash_free(edgeHash, NULL, NULL);
MEM_freeN(vertMap);
MEM_freeN(edgeMap);
MEM_freeN(faceMap);
-
+
return result;
}
diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c
index 99f5117e3cd..d16fa0c503c 100644
--- a/source/blender/modifiers/intern/MOD_solidify.c
+++ b/source/blender/modifiers/intern/MOD_solidify.c
@@ -583,7 +583,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* faces */
mf= mface + (numFaces * 2);
- origindex= result->getFaceDataArray(result, CD_ORIGINDEX);
+
for(i=0; i<newFaces; i++, mf++) {
int eidx= new_edge_arr[i];
int fidx= edge_users[eidx];
diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h
index 6a6413d508f..fb3946bae6c 100644
--- a/source/blender/nodes/NOD_socket.h
+++ b/source/blender/nodes/NOD_socket.h
@@ -47,26 +47,19 @@ struct bNodeStack;
void node_socket_type_init(struct bNodeSocketType *types[]);
-struct bNodeSocket *nodeAddInputInt(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, int value, int min, int max);
-struct bNodeSocket *nodeAddOutputInt(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, float value, float min, float max);
-struct bNodeSocket *nodeAddOutputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name, char value);
-struct bNodeSocket *nodeAddOutputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputVector(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype, float x, float y, float z, float min, float max);
-struct bNodeSocket *nodeAddOutputVector(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name, float r, float g, float b, float a);
-struct bNodeSocket *nodeAddOutputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputShader(struct bNodeTree *ntree, struct bNode *node, const char *name);
-struct bNodeSocket *nodeAddOutputShader(struct bNodeTree *ntree, struct bNode *node, const char *name);
-
-struct bNodeSocket *nodeAddInputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name);
-struct bNodeSocket *nodeAddOutputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name);
+void *node_socket_make_default_value(int type);
+void node_socket_free_default_value(int type, void *default_value);
+void node_socket_init_default_value(int type, void *default_value);
+void node_socket_copy_default_value(int type, void *to_default_value, void *from_default_value);
+void node_socket_convert_default_value(int to_type, void *to_default_value, int from_type, void *from_default_value);
+
+void node_socket_set_default_value_int(void *default_value, PropertySubType subtype, int value, int min, int max);
+void node_socket_set_default_value_float(void *default_value, PropertySubType subtype, float value, float min, float max);
+void node_socket_set_default_value_boolean(void *default_value, char value);
+void node_socket_set_default_value_vector(void *default_value, PropertySubType subtype, float x, float y, float z, float min, float max);
+void node_socket_set_default_value_rgba(void *default_value, float r, float g, float b, float a);
+void node_socket_set_default_value_shader(void *default_value);
+void node_socket_set_default_value_mesh(void *default_value);
struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp);
diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c
index 5a6cebb51ce..e5571b19614 100644
--- a/source/blender/nodes/intern/node_common.c
+++ b/source/blender/nodes/intern/node_common.c
@@ -100,8 +100,8 @@ bNodeSocket *node_group_add_extern_socket(bNodeTree *UNUSED(ntree), ListBase *lb
sock->groupsock = gsock;
sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF);
- if (gsock->default_value)
- sock->default_value = MEM_dupallocN(gsock->default_value);
+ sock->default_value = node_socket_make_default_value(sock->type);
+ node_socket_copy_default_value(sock->type, sock->default_value, gsock->default_value);
if(lb)
BLI_addtail(lb, sock);
@@ -247,177 +247,6 @@ bNode *node_group_make_from_selected(bNodeTree *ntree)
return gnode;
}
-/* XXX This is a makeshift function to have useful initial group socket values.
- * In the end this should be implemented by a flexible socket data conversion system,
- * which is yet to be implemented. The idea is that beside default standard conversions,
- * such as int-to-float, it should be possible to quickly select a conversion method or
- * a chain of conversions for each input, whenever there is more than one option.
- * E.g. a vector-to-float conversion could use either of the x/y/z components or
- * the vector length.
- *
- * In the interface this could be implemented by a pseudo-script textbox on linked inputs,
- * with quick selection from a predefined list of conversion options. Some Examples:
- * - vector component 'z' (vector->float): "z"
- * - greyscale color (float->color): "grey"
- * - color luminance (color->float): "lum"
- * - matrix column 2 length (matrix->vector->float): "col[1].len"
- * - mesh vertex coordinate 'y' (mesh->vertex->vector->float): "vertex.co.y"
- *
- * The actual conversion is then done by a series of conversion functions,
- * which are defined in the socket type structs.
- */
-static void convert_socket_value(bNodeSocket *from, bNodeSocket *to)
-{
- /* XXX only one of these pointers is valid! just putting them here for convenience */
- bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from->default_value;
- bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from->default_value;
- bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from->default_value;
- bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from->default_value;
- bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from->default_value;
-
- bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to->default_value;
- bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to->default_value;
- bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to->default_value;
- bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to->default_value;
- bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to->default_value;
-
- switch (from->type) {
- case SOCK_FLOAT:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = fromfloat->value;
- break;
- case SOCK_INT:
- toint->value = (int)fromfloat->value;
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromfloat->value > 0.0f);
- break;
- case SOCK_VECTOR:
- tovector->value[0] = tovector->value[1] = tovector->value[2] = fromfloat->value;
- break;
- case SOCK_RGBA:
- torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = fromfloat->value;
- break;
- }
- break;
- case SOCK_INT:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = (float)fromint->value;
- break;
- case SOCK_INT:
- toint->value = fromint->value;
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromint->value > 0);
- break;
- case SOCK_VECTOR:
- tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)fromint->value;
- break;
- case SOCK_RGBA:
- torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)fromint->value;
- break;
- }
- break;
- case SOCK_BOOLEAN:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = (float)frombool->value;
- break;
- case SOCK_INT:
- toint->value = (int)frombool->value;
- break;
- case SOCK_BOOLEAN:
- tobool->value = frombool->value;
- break;
- case SOCK_VECTOR:
- tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)frombool->value;
- break;
- case SOCK_RGBA:
- torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)frombool->value;
- break;
- }
- break;
- case SOCK_VECTOR:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = fromvector->value[0];
- break;
- case SOCK_INT:
- toint->value = (int)fromvector->value[0];
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromvector->value[0] > 0.0f);
- break;
- case SOCK_VECTOR:
- copy_v3_v3(tovector->value, fromvector->value);
- break;
- case SOCK_RGBA:
- copy_v3_v3(torgba->value, fromvector->value);
- torgba->value[3] = 1.0f;
- break;
- }
- break;
- case SOCK_RGBA:
- switch (to->type) {
- case SOCK_FLOAT:
- tofloat->value = fromrgba->value[0];
- break;
- case SOCK_INT:
- toint->value = (int)fromrgba->value[0];
- break;
- case SOCK_BOOLEAN:
- tobool->value = (fromrgba->value[0] > 0.0f);
- break;
- case SOCK_VECTOR:
- copy_v3_v3(tovector->value, fromrgba->value);
- break;
- case SOCK_RGBA:
- copy_v4_v4(torgba->value, fromrgba->value);
- break;
- }
- break;
- }
-}
-
-static void copy_socket_value(bNodeSocket *from, bNodeSocket *to)
-{
- /* XXX only one of these pointers is valid! just putting them here for convenience */
- bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from->default_value;
- bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from->default_value;
- bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from->default_value;
- bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from->default_value;
- bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from->default_value;
-
- bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to->default_value;
- bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to->default_value;
- bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to->default_value;
- bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to->default_value;
- bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to->default_value;
-
- if (from->type != to->type)
- return;
-
- switch (from->type) {
- case SOCK_FLOAT:
- *tofloat = *fromfloat;
- break;
- case SOCK_INT:
- *toint = *fromint;
- break;
- case SOCK_BOOLEAN:
- *tobool = *frombool;
- break;
- case SOCK_VECTOR:
- *tovector = *fromvector;
- break;
- case SOCK_RGBA:
- *torgba = *fromrgba;
- break;
- }
-}
-
/* returns 1 if its OK */
int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
{
@@ -489,7 +318,7 @@ int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
}
else {
/* copy the default input value from the group socket default to the external socket */
- convert_socket_value(gsock, link->tosock);
+ node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, gsock->type, gsock->default_value);
}
}
}
@@ -517,7 +346,7 @@ int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
}
else {
/* copy the default input value from the group node socket default to the internal socket */
- convert_socket_value(insock, link->tosock);
+ node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, insock->type, insock->default_value);
nodeRemLink(wgroup, link);
}
}
@@ -600,7 +429,7 @@ bNodeSocket *node_group_expose_socket(bNodeTree *ngroup, bNodeSocket *sock, int
bNodeSocket *gsock= node_group_add_socket(ngroup, sock->name, sock->type, in_out);
/* initialize the default value. */
- copy_socket_value(sock, gsock);
+ node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
return gsock;
}
@@ -616,7 +445,7 @@ void node_group_expose_all_sockets(bNodeTree *ngroup)
gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_IN);
/* initialize the default value. */
- copy_socket_value(sock, gsock);
+ node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
sock->link = nodeAddLink(ngroup, NULL, gsock, node, sock);
}
@@ -626,7 +455,7 @@ void node_group_expose_all_sockets(bNodeTree *ngroup)
gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_OUT);
/* initialize the default value. */
- copy_socket_value(sock, gsock);
+ node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
gsock->link = nodeAddLink(ngroup, node, sock, NULL, gsock);
}
@@ -832,11 +661,12 @@ bNodeTemplate node_forloop_template(bNode *node)
void node_forloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp)
{
- /* bNodeSocket *sock; */ /* UNUSED */
+ bNodeSocket *sock;
node->id = (ID*)ntemp->ngroup;
- /* sock = */ nodeAddInputFloat(ntree, node, "Iterations", PROP_UNSIGNED, 1, 0, 10000);
+ sock = nodeAddSocket(ntree, node, SOCK_IN, "Iterations", SOCK_FLOAT);
+ node_socket_set_default_value_float(sock->default_value, PROP_UNSIGNED, 1, 0, 10000);
/* NB: group socket input/output roles are inverted internally!
* Group "inputs" work as outputs in links and vice versa.
@@ -938,11 +768,12 @@ void node_loop_update_tree(bNodeTree *ngroup)
void node_whileloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp)
{
- /* bNodeSocket *sock; */ /* UNUSED */
+ bNodeSocket *sock;
node->id = (ID*)ntemp->ngroup;
- /* sock = */ nodeAddInputFloat(ntree, node, "Condition", PROP_NONE, 1, 0, 1);
+ sock = nodeAddSocket(ntree, node, SOCK_IN, "Condition", SOCK_FLOAT);
+ node_socket_set_default_value_float(sock->default_value, PROP_NONE, 1, 0, 1);
/* max iterations */
node->custom1 = 10000;
diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c
index 9381eff30dd..f03aff8fb92 100644
--- a/source/blender/nodes/intern/node_socket.c
+++ b/source/blender/nodes/intern/node_socket.c
@@ -29,6 +29,7 @@
* \ingroup nodes
*/
+#include <limits.h>
#include "DNA_node_types.h"
@@ -172,171 +173,311 @@ void node_socket_type_init(bNodeSocketType *types[])
#undef INIT_TYPE
}
-struct bNodeSocket *nodeAddInputInt(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype,
- int value, int min, int max)
+void *node_socket_make_default_value(int type)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_INT);
- bNodeSocketValueInt *dval= (bNodeSocketValueInt*)sock->default_value;
- dval->subtype = subtype;
- dval->value = value;
- dval->min = min;
- dval->max = max;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputInt(struct bNodeTree *ntree, struct bNode *node, const char *name)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_INT);
- return sock;
+ /* XXX currently just allocates from stype->structsize.
+ * it might become necessary to do more complex allocations for later types.
+ */
+ bNodeSocketType *stype = ntreeGetSocketType(type);
+ if (stype->value_structsize > 0) {
+ void *default_value = MEM_callocN(stype->value_structsize, "default socket value");
+ return default_value;
+ }
+ else
+ return NULL;
}
-struct bNodeSocket *nodeAddInputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype,
- float value, float min, float max)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_FLOAT);
- bNodeSocketValueFloat *dval= (bNodeSocketValueFloat*)sock->default_value;
- dval->subtype = subtype;
- dval->value = value;
- dval->min = min;
- dval->max = max;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputFloat(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_free_default_value(int UNUSED(type), void *default_value)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_FLOAT);
- return sock;
+ /* XXX can just free the pointee for all current socket types. */
+ if (default_value)
+ MEM_freeN(default_value);
}
-struct bNodeSocket *nodeAddInputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name, char value)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_BOOLEAN);
- bNodeSocketValueBoolean *dval= (bNodeSocketValueBoolean*)sock->default_value;
- dval->value = value;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputBoolean(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_init_default_value(int type, void *default_value)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_BOOLEAN);
- return sock;
+ switch (type) {
+ case SOCK_FLOAT:
+ node_socket_set_default_value_float(default_value, PROP_NONE, 0.0f, -FLT_MAX, FLT_MAX);
+ break;
+ case SOCK_INT:
+ node_socket_set_default_value_int(default_value, PROP_NONE, 0, INT_MIN, INT_MAX);
+ break;
+ case SOCK_BOOLEAN:
+ node_socket_set_default_value_boolean(default_value, FALSE);
+ break;
+ case SOCK_VECTOR:
+ node_socket_set_default_value_vector(default_value, PROP_NONE, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX);
+ break;
+ case SOCK_RGBA:
+ node_socket_set_default_value_rgba(default_value, 0.0f, 0.0f, 0.0f, 1.0f);
+ break;
+ case SOCK_SHADER:
+ node_socket_set_default_value_shader(default_value);
+ break;
+ case SOCK_MESH:
+ node_socket_set_default_value_mesh(default_value);
+ break;
+ }
}
-struct bNodeSocket *nodeAddInputVector(struct bNodeTree *ntree, struct bNode *node, const char *name, PropertySubType subtype,
- float x, float y, float z, float min, float max)
+void node_socket_set_default_value_int(void *default_value, PropertySubType subtype, int value, int min, int max)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_VECTOR);
- bNodeSocketValueVector *dval= (bNodeSocketValueVector*)sock->default_value;
- dval->subtype = subtype;
- dval->value[0] = x;
- dval->value[1] = y;
- dval->value[2] = z;
- dval->min = min;
- dval->max = max;
- return sock;
-}
-struct bNodeSocket *nodeAddOutputVector(struct bNodeTree *ntree, struct bNode *node, const char *name)
-{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_VECTOR);
- return sock;
+ bNodeSocketValueInt *val = default_value;
+ val->subtype = subtype;
+ val->value = value;
+ val->min = min;
+ val->max = max;
}
-struct bNodeSocket *nodeAddInputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name,
- float r, float g, float b, float a)
+void node_socket_set_default_value_float(void *default_value, PropertySubType subtype, float value, float min, float max)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_RGBA);
- bNodeSocketValueRGBA *dval= (bNodeSocketValueRGBA*)sock->default_value;
- dval->value[0] = r;
- dval->value[1] = g;
- dval->value[2] = b;
- dval->value[3] = a;
- return sock;
+ bNodeSocketValueFloat *val = default_value;
+ val->subtype = subtype;
+ val->value = value;
+ val->min = min;
+ val->max = max;
}
-struct bNodeSocket *nodeAddOutputRGBA(struct bNodeTree *ntree, struct bNode *node, const char *name)
+
+void node_socket_set_default_value_boolean(void *default_value, char value)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_RGBA);
- return sock;
+ bNodeSocketValueBoolean *val = default_value;
+ val->value = value;
}
-struct bNodeSocket *nodeAddInputShader(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_set_default_value_vector(void *default_value, PropertySubType subtype, float x, float y, float z, float min, float max)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_SHADER);
- return sock;
+ bNodeSocketValueVector *val = default_value;
+ val->subtype = subtype;
+ val->value[0] = x;
+ val->value[1] = y;
+ val->value[2] = z;
+ val->min = min;
+ val->max = max;
}
-struct bNodeSocket *nodeAddOutputShader(struct bNodeTree *ntree, struct bNode *node, const char *name)
+
+void node_socket_set_default_value_rgba(void *default_value, float r, float g, float b, float a)
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_SHADER);
- return sock;
+ bNodeSocketValueRGBA *val = default_value;
+ val->value[0] = r;
+ val->value[1] = g;
+ val->value[2] = b;
+ val->value[3] = a;
}
-struct bNodeSocket *nodeAddInputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name)
+void node_socket_set_default_value_shader(void *UNUSED(default_value))
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_IN, name, SOCK_MESH);
- return sock;
}
-struct bNodeSocket *nodeAddOutputMesh(struct bNodeTree *ntree, struct bNode *node, const char *name)
+
+void node_socket_set_default_value_mesh(void *UNUSED(default_value))
{
- bNodeSocket *sock= nodeAddSocket(ntree, node, SOCK_OUT, name, SOCK_MESH);
- return sock;
}
-struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
+
+void node_socket_copy_default_value(int type, void *to_default_value, void *from_default_value)
{
- bNodeSocket *sock;
- switch (stemp->type) {
- case SOCK_INT:
- sock = nodeAddInputInt(ntree, node, stemp->name, stemp->subtype, (int)stemp->val1, (int)stemp->min, (int)stemp->max);
- break;
+ /* XXX only one of these pointers is valid! just putting them here for convenience */
+ bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from_default_value;
+ bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from_default_value;
+ bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from_default_value;
+ bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from_default_value;
+ bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from_default_value;
+
+ bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to_default_value;
+ bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to_default_value;
+ bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to_default_value;
+ bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to_default_value;
+ bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to_default_value;
+
+ switch (type) {
case SOCK_FLOAT:
- sock = nodeAddInputFloat(ntree, node, stemp->name, stemp->subtype, stemp->val1, stemp->min, stemp->max);
+ *tofloat = *fromfloat;
+ break;
+ case SOCK_INT:
+ *toint = *fromint;
break;
case SOCK_BOOLEAN:
- sock = nodeAddInputBoolean(ntree, node, stemp->name, (char)stemp->val1);
+ *tobool = *frombool;
break;
case SOCK_VECTOR:
- sock = nodeAddInputVector(ntree, node, stemp->name, stemp->subtype, stemp->val1, stemp->val2, stemp->val3, stemp->min, stemp->max);
+ *tovector = *fromvector;
break;
case SOCK_RGBA:
- sock = nodeAddInputRGBA(ntree, node, stemp->name, stemp->val1, stemp->val2, stemp->val3, stemp->val4);
+ *torgba = *fromrgba;
break;
- case SOCK_SHADER:
- sock = nodeAddInputShader(ntree, node, stemp->name);
+ }
+}
+
+/* XXX This is a makeshift function to have useful initial group socket values.
+ * In the end this should be implemented by a flexible socket data conversion system,
+ * which is yet to be implemented. The idea is that beside default standard conversions,
+ * such as int-to-float, it should be possible to quickly select a conversion method or
+ * a chain of conversions for each input, whenever there is more than one option.
+ * E.g. a vector-to-float conversion could use either of the x/y/z components or
+ * the vector length.
+ *
+ * In the interface this could be implemented by a pseudo-script textbox on linked inputs,
+ * with quick selection from a predefined list of conversion options. Some Examples:
+ * - vector component 'z' (vector->float): "z"
+ * - greyscale color (float->color): "grey"
+ * - color luminance (color->float): "lum"
+ * - matrix column 2 length (matrix->vector->float): "col[1].len"
+ * - mesh vertex coordinate 'y' (mesh->vertex->vector->float): "vertex.co.y"
+ *
+ * The actual conversion is then done by a series of conversion functions,
+ * which are defined in the socket type structs.
+ */
+void node_socket_convert_default_value(int to_type, void *to_default_value, int from_type, void *from_default_value)
+{
+ /* XXX only one of these pointers is valid! just putting them here for convenience */
+ bNodeSocketValueFloat *fromfloat= (bNodeSocketValueFloat*)from_default_value;
+ bNodeSocketValueInt *fromint= (bNodeSocketValueInt*)from_default_value;
+ bNodeSocketValueBoolean *frombool= (bNodeSocketValueBoolean*)from_default_value;
+ bNodeSocketValueVector *fromvector= (bNodeSocketValueVector*)from_default_value;
+ bNodeSocketValueRGBA *fromrgba= (bNodeSocketValueRGBA*)from_default_value;
+
+ bNodeSocketValueFloat *tofloat= (bNodeSocketValueFloat*)to_default_value;
+ bNodeSocketValueInt *toint= (bNodeSocketValueInt*)to_default_value;
+ bNodeSocketValueBoolean *tobool= (bNodeSocketValueBoolean*)to_default_value;
+ bNodeSocketValueVector *tovector= (bNodeSocketValueVector*)to_default_value;
+ bNodeSocketValueRGBA *torgba= (bNodeSocketValueRGBA*)to_default_value;
+
+ switch (from_type) {
+ case SOCK_FLOAT:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = fromfloat->value;
+ break;
+ case SOCK_INT:
+ toint->value = (int)fromfloat->value;
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromfloat->value > 0.0f);
+ break;
+ case SOCK_VECTOR:
+ tovector->value[0] = tovector->value[1] = tovector->value[2] = fromfloat->value;
+ break;
+ case SOCK_RGBA:
+ torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = fromfloat->value;
+ break;
+ }
break;
- case SOCK_MESH:
- sock = nodeAddInputMesh(ntree, node, stemp->name);
+ case SOCK_INT:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = (float)fromint->value;
+ break;
+ case SOCK_INT:
+ toint->value = fromint->value;
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromint->value > 0);
+ break;
+ case SOCK_VECTOR:
+ tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)fromint->value;
+ break;
+ case SOCK_RGBA:
+ torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)fromint->value;
+ break;
+ }
+ break;
+ case SOCK_BOOLEAN:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = (float)frombool->value;
+ break;
+ case SOCK_INT:
+ toint->value = (int)frombool->value;
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = frombool->value;
+ break;
+ case SOCK_VECTOR:
+ tovector->value[0] = tovector->value[1] = tovector->value[2] = (float)frombool->value;
+ break;
+ case SOCK_RGBA:
+ torgba->value[0] = torgba->value[1] = torgba->value[2] = torgba->value[3] = (float)frombool->value;
+ break;
+ }
+ break;
+ case SOCK_VECTOR:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = fromvector->value[0];
+ break;
+ case SOCK_INT:
+ toint->value = (int)fromvector->value[0];
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromvector->value[0] > 0.0f);
+ break;
+ case SOCK_VECTOR:
+ copy_v3_v3(tovector->value, fromvector->value);
+ break;
+ case SOCK_RGBA:
+ copy_v3_v3(torgba->value, fromvector->value);
+ torgba->value[3] = 1.0f;
+ break;
+ }
+ break;
+ case SOCK_RGBA:
+ switch (to_type) {
+ case SOCK_FLOAT:
+ tofloat->value = fromrgba->value[0];
+ break;
+ case SOCK_INT:
+ toint->value = (int)fromrgba->value[0];
+ break;
+ case SOCK_BOOLEAN:
+ tobool->value = (fromrgba->value[0] > 0.0f);
+ break;
+ case SOCK_VECTOR:
+ copy_v3_v3(tovector->value, fromrgba->value);
+ break;
+ case SOCK_RGBA:
+ copy_v4_v4(torgba->value, fromrgba->value);
+ break;
+ }
break;
- default:
- sock = nodeAddSocket(ntree, node, SOCK_IN, stemp->name, stemp->type);
}
- sock->flag |= stemp->flag;
- return sock;
}
-struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
+
+struct bNodeSocket *node_add_input_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
{
- bNodeSocket *sock;
+ bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_IN, stemp->name, stemp->type);
+ sock->flag |= stemp->flag;
+
switch (stemp->type) {
case SOCK_INT:
- sock = nodeAddOutputInt(ntree, node, stemp->name);
+ node_socket_set_default_value_int(sock->default_value, stemp->subtype, (int)stemp->val1, (int)stemp->min, (int)stemp->max);
break;
case SOCK_FLOAT:
- sock = nodeAddOutputFloat(ntree, node, stemp->name);
+ node_socket_set_default_value_float(sock->default_value, stemp->subtype, stemp->val1, stemp->min, stemp->max);
break;
case SOCK_BOOLEAN:
- sock = nodeAddOutputBoolean(ntree, node, stemp->name);
+ node_socket_set_default_value_boolean(sock->default_value, (char)stemp->val1);
break;
case SOCK_VECTOR:
- sock = nodeAddOutputVector(ntree, node, stemp->name);
+ node_socket_set_default_value_vector(sock->default_value, stemp->subtype, stemp->val1, stemp->val2, stemp->val3, stemp->min, stemp->max);
break;
case SOCK_RGBA:
- sock = nodeAddOutputRGBA(ntree, node, stemp->name);
+ node_socket_set_default_value_rgba(sock->default_value, stemp->val1, stemp->val2, stemp->val3, stemp->val4);
break;
case SOCK_SHADER:
- sock = nodeAddOutputShader(ntree, node, stemp->name);
+ node_socket_set_default_value_shader(sock->default_value);
break;
case SOCK_MESH:
- sock = nodeAddOutputMesh(ntree, node, stemp->name);
+ node_socket_set_default_value_mesh(sock->default_value);
break;
- default:
- sock = nodeAddSocket(ntree, node, SOCK_OUT, stemp->name, stemp->type);
}
+
+ return sock;
+}
+
+struct bNodeSocket *node_add_output_from_template(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocketTemplate *stemp)
+{
+ bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_OUT, stemp->name, stemp->type);
return sock;
}
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 6c961d8e6a8..72c072c13d5 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -267,9 +267,10 @@ void BPY_python_start(int argc, const char **argv)
pyrna_alloc_types();
+#ifndef WITH_PYTHON_MODULE
+ /* py module runs atexit when bpy is freed */
BPY_atexit_register(); /* this can init any time */
-#ifndef WITH_PYTHON_MODULE
py_tstate = PyGILState_GetThisThreadState();
PyEval_ReleaseThread(py_tstate);
#endif
@@ -288,7 +289,9 @@ void BPY_python_end(void)
bpy_intern_string_exit();
+#ifndef WITH_PYTHON_MODULE
BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */
+#endif
Py_Finalize();
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index d94ba8b9441..414ebe47e97 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -374,7 +374,12 @@ static int bpy_struct_id_used(StructRNA *srna, char *identifier)
* but being abused from C so we can pass the srna along.
* This isnt incorrect since its a python object - but be careful */
PyDoc_STRVAR(BPy_BoolProperty_doc,
-".. function:: BoolProperty(name=\"\", description=\"\", default=False, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
+".. function:: BoolProperty(name=\"\", "
+ "description=\"\", "
+ "default=False, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "update=None)\n"
"\n"
" Returns a new boolean property definition.\n"
"\n"
@@ -438,7 +443,13 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(BPy_BoolVectorProperty_doc,
-".. function:: BoolVectorProperty(name=\"\", description=\"\", default=(False, False, False), options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
+".. function:: BoolVectorProperty(name=\"\", "
+ "description=\"\", "
+ "default=(False, False, False), "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "size=3, "
+ "update=None)\n"
"\n"
" Returns a new vector boolean property definition.\n"
"\n"
@@ -448,7 +459,9 @@ BPY_PROPDEF_DESC_DOC
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', "
+ "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', "
+ "'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
@@ -520,7 +533,15 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
}
PyDoc_STRVAR(BPy_IntProperty_doc,
-".. function:: IntProperty(name=\"\", description=\"\", default=0, min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, step=1, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
+".. function:: IntProperty(name=\"\", "
+ "description=\"\", "
+ "default=0, "
+ "min=-sys.maxint, max=sys.maxint, "
+ "soft_min=-sys.maxint, soft_max=sys.maxint, "
+ "step=1, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "update=None)\n"
"\n"
" Returns a new int property definition.\n"
"\n"
@@ -540,7 +561,8 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
if (srna) {
static const char *kwlist[] = {"attr", "name", "description", "default",
- "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "update", NULL};
+ "min", "max", "soft_min", "soft_max",
+ "step", "options", "subtype", "update", NULL};
const char *id = NULL, *name = NULL, *description = "";
int id_len;
int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1, def = 0;
@@ -586,7 +608,15 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(BPy_IntVectorProperty_doc,
-".. function:: IntVectorProperty(name=\"\", description=\"\", default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
+".. function:: IntVectorProperty(name=\"\", "
+ "description=\"\", "
+ "default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, "
+ "soft_min=-sys.maxint, "
+ "soft_max=sys.maxint, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "size=3, "
+ "update=None)\n"
"\n"
" Returns a new vector int property definition.\n"
"\n"
@@ -596,7 +626,9 @@ BPY_PROPDEF_DESC_DOC
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', "
+ "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', "
+ "'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
@@ -673,7 +705,17 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
PyDoc_STRVAR(BPy_FloatProperty_doc,
-".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', unit='NONE', update=None)\n"
+".. function:: FloatProperty(name=\"\", "
+ "description=\"\", "
+ "default=0.0, "
+ "min=sys.float_info.min, max=sys.float_info.max, "
+ "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
+ "step=3, "
+ "precision=2, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "unit='NONE', "
+ "update=None)\n"
"\n"
" Returns a new float property definition.\n"
"\n"
@@ -750,7 +792,17 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(BPy_FloatVectorProperty_doc,
-".. function:: FloatVectorProperty(name=\"\", description=\"\", default=(0.0, 0.0, 0.0), min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
+".. function:: FloatVectorProperty(name=\"\", "
+ "description=\"\", "
+ "default=(0.0, 0.0, 0.0), "
+ "min=sys.float_info.min, max=sys.float_info.max, "
+ "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
+ "step=3, "
+ "precision=2, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "size=3, "
+ "update=None)\n"
"\n"
" Returns a new vector float property definition.\n"
"\n"
@@ -760,7 +812,9 @@ BPY_PROPDEF_DESC_DOC
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', "
+ "'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', "
+ "'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
BPY_PROPDEF_UNIT_DOC
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
@@ -779,7 +833,8 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
"step", "precision", "options", "subtype", "unit", "size", "update", NULL};
const char *id = NULL, *name = NULL, *description = "";
int id_len;
- float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3, def[PYRNA_STACK_ARRAY] = {0.0f};
+ float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3;
+ float def[PYRNA_STACK_ARRAY] = {0.0f};
int precision = 2, size = 3;
PropertyRNA *prop;
PyObject *pydef = NULL;
@@ -843,7 +898,13 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
}
PyDoc_STRVAR(BPy_StringProperty_doc,
-".. function:: StringProperty(name=\"\", description=\"\", default=\"\", maxlen=0, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
+".. function:: StringProperty(name=\"\", "
+ "description=\"\", "
+ "default=\"\", "
+ "maxlen=0, "
+ "options={'ANIMATABLE'}, "
+ "subtype='NONE', "
+ "update=None)\n"
"\n"
" Returns a new string property definition.\n"
"\n"
@@ -978,7 +1039,8 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
(tmp.identifier = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
(tmp.name = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
(tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
- (item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1)) /* TODO, number isnt ensured to be unique from the script author */
+ /* TODO, number isnt ensured to be unique from the script author */
+ (item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1))
{
if (is_enum_flag) {
if (item_size < 4) {
@@ -1105,7 +1167,8 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt
err = -1;
}
else {
- eitems = enum_items_from_py(items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0);
+ eitems = enum_items_from_py(items_fast, NULL, &defvalue_dummy,
+ (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0);
Py_DECREF(items_fast);
@@ -1132,7 +1195,12 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt
}
PyDoc_STRVAR(BPy_EnumProperty_doc,
-".. function:: EnumProperty(items, name=\"\", description=\"\", default=\"\", options={'ANIMATABLE'}, update=None)\n"
+".. function:: EnumProperty(items, "
+ "name=\"\", "
+ "description=\"\", "
+ "default=\"\", "
+ "options={'ANIMATABLE'}, "
+ "update=None)\n"
"\n"
" Returns a new enumerator property definition.\n"
"\n"
@@ -1218,7 +1286,8 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
- eitems = enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG) != 0);
+ eitems = enum_items_from_py(items_fast, def, &defvalue,
+ (opts & PROP_ENUM_FLAG) != 0);
Py_DECREF(items_fast);
@@ -1287,7 +1356,10 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
}
PyDoc_STRVAR(BPy_PointerProperty_doc,
-".. function:: PointerProperty(type=\"\", description=\"\", options={'ANIMATABLE'}, update=None)\n"
+".. function:: PointerProperty(type=\"\", "
+ "description=\"\", "
+ "options={'ANIMATABLE'}, "
+ "update=None)\n"
"\n"
" Returns a new pointer property definition.\n"
"\n"
@@ -1349,7 +1421,10 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
}
PyDoc_STRVAR(BPy_CollectionProperty_doc,
-".. function:: CollectionProperty(items, type=\"\", description=\"\", default=\"\", options={'ANIMATABLE'})\n"
+".. function:: CollectionProperty(items, "
+ "type=\"\", "
+ "description=\"\", "
+ "options={'ANIMATABLE'})\n"
"\n"
" Returns a new collection property definition.\n"
"\n"
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 4940c53551e..bfb79ea6531 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -7158,8 +7158,25 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
const char *identifier;
PyObject *py_cls_meth;
+ if (!PyType_Check(py_class)) {
+ PyErr_Format(PyExc_ValueError,
+ "register_class(...): "
+ "expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
+ return NULL;
+ }
+
if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna)) {
- PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass");
+ PyErr_SetString(PyExc_ValueError,
+ "register_class(...): "
+ "already registered as a subclass");
+ return NULL;
+ }
+
+ if (!pyrna_write_check()) {
+ PyErr_Format(PyExc_RuntimeError,
+ "register_class(...): "
+ "can't run in readonly state '%.200s'",
+ ((PyTypeObject *)py_class)->tp_name);
return NULL;
}
@@ -7284,12 +7301,27 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
StructRNA *srna;
PyObject *py_cls_meth;
+ if (!PyType_Check(py_class)) {
+ PyErr_Format(PyExc_ValueError,
+ "register_class(...): "
+ "expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
+ return NULL;
+ }
+
/*if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna) == NULL) {
PWM_cursor_wait(0);
PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass");
return NULL;
}*/
+ if (!pyrna_write_check()) {
+ PyErr_Format(PyExc_RuntimeError,
+ "unregister_class(...): "
+ "can't run in readonly state '%.200s'",
+ ((PyTypeObject *)py_class)->tp_name);
+ return NULL;
+ }
+
srna = pyrna_struct_as_srna(py_class, 0, "unregister_class(...):");
if (srna == NULL)
return NULL;
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index f10d8c48c92..7fe4b5ba5dd 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -1939,13 +1939,6 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name);
return NULL;
}
-static PyObject *Matrix_inv(MatrixObject *self)
-{
- if (BaseMath_ReadCallback(self) == -1)
- return NULL;
-
- return Matrix_invert(self);
-}
/*-----------------PROTOCOL DECLARATIONS--------------------------*/
static PySequenceMethods Matrix_SeqMethods = {
@@ -2049,7 +2042,7 @@ static PyNumberMethods Matrix_NumMethods = {
(unaryfunc) 0, /*tp_positive*/
(unaryfunc) 0, /*tp_absolute*/
(inquiry) 0, /*tp_bool*/
- (unaryfunc) Matrix_inv, /*nb_invert*/
+ (unaryfunc) Matrix_inverted, /*nb_invert*/
NULL, /*nb_lshift*/
(binaryfunc)0, /*nb_rshift*/
NULL, /*nb_and*/
diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h
index dd0a0f308ce..2f585f91d44 100644
--- a/source/blender/render/extern/include/RE_shader_ext.h
+++ b/source/blender/render/extern/include/RE_shader_ext.h
@@ -210,4 +210,8 @@ int RE_bake_shade_all_selected(struct Render *re, int type, struct Object *actob
struct Image *RE_bake_shade_get_image(void);
void RE_bake_ibuf_filter(struct ImBuf *ibuf, char *mask, const int filter);
+#define BAKE_RESULT_OK 0
+#define BAKE_RESULT_NO_OBJECTS 1
+#define BAKE_RESULT_FEEDBACK_LOOP 2
+
#endif /* RE_SHADER_EXT_H */
diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c
index 0b6e1b8ee01..2d64828b6b3 100644
--- a/source/blender/render/intern/source/imagetexture.c
+++ b/source/blender/render/intern/source/imagetexture.c
@@ -131,6 +131,8 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul
return retval;
ibuf= BKE_image_get_ibuf(ima, &tex->iuser);
+
+ ima->flag|= IMA_USED_FOR_RENDER;
}
if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
return retval;
@@ -1441,6 +1443,8 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const
return retval;
ibuf= BKE_image_get_ibuf(ima, &tex->iuser);
+
+ ima->flag|= IMA_USED_FOR_RENDER;
}
if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
return retval;
@@ -1812,6 +1816,8 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *res
if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
ibuf->rect-= (ibuf->x*ibuf->y);
+
+ ima->flag|= IMA_USED_FOR_RENDER;
}
void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result)
diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c
index 5fba0bba48c..95cad5a4e46 100644
--- a/source/blender/render/intern/source/render_texture.c
+++ b/source/blender/render/intern/source/render_texture.c
@@ -2127,7 +2127,8 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
fMagnitude *= len_v3(vN);
}
- for(xyz=0; xyz<3; xyz++)
+ if(ntap_bump->fPrevMagnitude > 0.0f)
+ for(xyz=0; xyz<3; xyz++)
ntap_bump->vNacc[xyz] *= fMagnitude / ntap_bump->fPrevMagnitude;
ntap_bump->fPrevMagnitude = fMagnitude;
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
index 630acf3d88a..2d3837acbfa 100644
--- a/source/blender/render/intern/source/rendercore.c
+++ b/source/blender/render/intern/source/rendercore.c
@@ -2166,21 +2166,13 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua
}
}
else {
- char *col= (char *)(bs->rect + bs->rectx*y + x);
+ unsigned char *col= (unsigned char *)(bs->rect + bs->rectx*y + x);
if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE) && (R.r.color_mgt_flag & R_COLOR_MANAGEMENT)) {
- float srgb[3];
- srgb[0]= linearrgb_to_srgb(shr.combined[0]);
- srgb[1]= linearrgb_to_srgb(shr.combined[1]);
- srgb[2]= linearrgb_to_srgb(shr.combined[2]);
-
- col[0]= FTOCHAR(srgb[0]);
- col[1]= FTOCHAR(srgb[1]);
- col[2]= FTOCHAR(srgb[2]);
- } else {
- col[0]= FTOCHAR(shr.combined[0]);
- col[1]= FTOCHAR(shr.combined[1]);
- col[2]= FTOCHAR(shr.combined[2]);
+ linearrgb_to_srgb_uchar3(col, shr.combined);
+ }
+ else {
+ rgb_float_to_uchar(col, shr.combined);
}
if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) {
@@ -2212,9 +2204,7 @@ static void bake_displacement(void *handle, ShadeInput *UNUSED(shi), float dist,
col[3]= 1.0f;
} else {
char *col= (char *)(bs->rect + bs->rectx*y + x);
- col[0]= FTOCHAR(disp);
- col[1]= FTOCHAR(disp);
- col[2]= FTOCHAR(disp);
+ col[0] = col[1] = col[2] = FTOCHAR(disp);
col[3]= 255;
}
if (bs->rect_mask) {
@@ -2450,6 +2440,11 @@ static int get_next_bake_face(BakeShade *bs)
if(ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4))
continue;
+ if(ima->flag & IMA_USED_FOR_RENDER) {
+ ima->id.flag &= ~LIB_DOIT;
+ continue;
+ }
+
/* find the image for the first time? */
if(ima->id.flag & LIB_DOIT) {
ima->id.flag &= ~LIB_DOIT;
@@ -2594,7 +2589,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
BakeShade *handles;
ListBase threads;
Image *ima;
- int a, vdone=0, usemask=0;
+ int a, vdone=0, usemask=0, result=BAKE_RESULT_OK;
/* initialize render global */
R= *re;
@@ -2611,6 +2606,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
for(ima= G.main->image.first; ima; ima= ima->id.next) {
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
ima->id.flag |= LIB_DOIT;
+ ima->flag&= ~IMA_USED_FOR_RENDER;
if(ibuf) {
ibuf->userdata = NULL; /* use for masking if needed */
if(ibuf->rect_float)
@@ -2669,6 +2665,9 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
if((ima->id.flag & LIB_DOIT)==0) {
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
+ if(ima->flag & IMA_USED_FOR_RENDER)
+ result= BAKE_RESULT_FEEDBACK_LOOP;
+
if(!ibuf)
continue;
@@ -2689,7 +2688,10 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
BLI_end_threads(&threads);
- return vdone;
+ if(vdone==0)
+ result= BAKE_RESULT_NO_OBJECTS;
+
+ return result;
}
struct Image *RE_bake_shade_get_image(void)
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 758cf7bd61c..357eaf2633b 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -526,14 +526,14 @@ typedef struct wmDrag {
int icon, type; /* type, see WM_DRAG defines above */
void *poin;
- char path[240]; /* FILE_MAX */
+ char path[1024]; /* FILE_MAX */
double value;
struct ImBuf *imb; /* if no icon but imbuf should be drawn around cursor */
float scale;
int sx, sy;
- char opname[240]; /* FILE_MAX */ /* if set, draws operator name*/
+ char opname[200]; /* if set, draws operator name*/
} wmDrag;
/* dropboxes are like keymaps, part of the screen/area/region definition */
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 94f6eb19e2c..299266154dd 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -248,7 +248,7 @@ void wm_drags_check_ops(bContext *C, wmEvent *event)
/* ************** draw ***************** */
-static void wm_drop_operator_draw(char *name, int x, int y)
+static void wm_drop_operator_draw(const char *name, int x, int y)
{
int width= UI_GetStringWidth(name);
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 24af3ffedc1..661bd90435c 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -1213,7 +1213,14 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
km = WM_keymap_find_all(C, "Pose", 0, 0);
}
else if (strstr(opname, "SCULPT_OT")) {
- km = WM_keymap_find_all(C, "Sculpt", 0, 0);
+ switch(CTX_data_mode_enum(C)) {
+ case OB_MODE_SCULPT:
+ km = WM_keymap_find_all(C, "Sculpt", 0, 0);
+ break;
+ case OB_MODE_EDIT:
+ km = WM_keymap_find_all(C, "UV Sculpt", 0, 0);
+ break;
+ }
}
else if (strstr(opname, "MBALL_OT")) {
km = WM_keymap_find_all(C, "Metaball", 0, 0);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index edd822bd2da..3a3be292f07 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3807,6 +3807,7 @@ static void gesture_border_modal_keymap(wmKeyConfig *keyconf)
WM_modalkeymap_assign(keymap, "MARKER_OT_select_border");
WM_modalkeymap_assign(keymap, "NLA_OT_select_border");
WM_modalkeymap_assign(keymap, "NODE_OT_select_border");
+ WM_modalkeymap_assign(keymap, "OUTLINER_OT_select_border");
// WM_modalkeymap_assign(keymap, "SCREEN_OT_border_select"); // template
WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_border");
WM_modalkeymap_assign(keymap, "SEQUENCER_OT_view_ghost_border");
@@ -3882,7 +3883,7 @@ void wm_window_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
kmi= WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "copy", 1);
+ RNA_boolean_set(kmi->ptr, "copy", TRUE);
WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "WM_OT_quit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blenderplayer/CMakeLists.txt b/source/blenderplayer/CMakeLists.txt
index fed9e60a638..223df9c8b6a 100644
--- a/source/blenderplayer/CMakeLists.txt
+++ b/source/blenderplayer/CMakeLists.txt
@@ -180,6 +180,10 @@ endif()
list(APPEND BLENDER_SORTED_LIBS bf_intern_moto)
endif()
+ if(WITH_CARVE)
+ list(APPEND BLENDER_SORTED_LIBS extern_carve)
+ endif()
+
if(WITH_CODEC_QUICKTIME)
list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
endif()
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c
index b63a04c62a2..56516f6662e 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -205,6 +205,8 @@ int ED_space_image_show_paint(struct SpaceImage *sima){return 0;}
void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings){}
void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit, struct Image *ima){}
struct ImBuf *ED_space_image_buffer(struct SpaceImage *sima){return (struct ImBuf *) NULL;}
+void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings){}
+
void ED_screen_set_scene(struct bContext *C, struct Scene *scene){}
void ED_space_clip_set(struct bContext *C, struct SpaceClip *sc, struct MovieClip *clip){}
@@ -298,6 +300,9 @@ void ED_mesh_update(struct Mesh *mesh, struct bContext *C){}
void ED_mesh_vertices_add(struct Mesh *mesh, struct ReportList *reports, int count){}
void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count){}
void ED_mesh_faces_add(struct Mesh *mesh, struct ReportList *reports, int count){}
+void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count){}
+void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count){}
+void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int count){}
void ED_mesh_material_link(struct Mesh *mesh, struct Material *ma){}
int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob, struct Mesh *me){return 0;}
int ED_mesh_uv_texture_add(struct bContext *C, struct Mesh *me){return 0;}
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index aebf5d6ebe9..898504d7a17 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -179,6 +179,15 @@ if(WITH_PYTHON_MODULE)
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin # only needed on windows
)
+ if(APPLE)
+ set_target_properties(
+ blender
+ PROPERTIES
+ LINK_FLAGS_RELEASE "${PLATFORM_LINKFLAGS}"
+ LINK_FLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG}"
+ )
+ endif()
+
if(WIN32)
# python modules use this
set_target_properties(
@@ -235,7 +244,11 @@ elseif(WIN32)
set(TARGETDIR_VER ${TARGETDIR}/${BLENDER_VERSION})
elseif(APPLE)
- set(TARGETDIR_VER ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION})
+ if(WITH_PYTHON_MODULE)
+ set(TARGETDIR_VER ${TARGETDIR}/${BLENDER_VERSION})
+ else()
+ set(TARGETDIR_VER ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION})
+ endif()
endif()
@@ -617,10 +630,11 @@ elseif(APPLE)
)
# python
- if(WITH_PYTHON)
+ if(WITH_PYTHON AND NOT WITH_PYTHON_MODULE)
# the python zip is first extract as part of the build process,
# and then later installed as part of make install. this is much
# quicker, and means we can easily exclude files on copy
+ # Not needed for PYTHON_MODULE or WEB_PLUGIN due uses Pyhon framework
add_custom_target(
extractpyzip
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python)
@@ -865,6 +879,10 @@ endif()
list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
endif()
+ if(WITH_CARVE)
+ list(APPEND BLENDER_SORTED_LIBS extern_carve)
+ endif()
+
foreach(SORTLIB ${BLENDER_SORTED_LIBS})
set(REMLIB ${SORTLIB})
foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
diff --git a/source/creator/creator.c b/source/creator/creator.c
index ee4f5c068a8..8220eb808e8 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -1110,6 +1110,13 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
/* allow python module to call main */
#define main main_python_enter
static void *evil_C= NULL;
+
+#ifdef __APPLE__
+/* environ is not available in mac shared libraries */
+#include <crt_externs.h>
+char **environ = NULL;
+#endif
+
#endif
int main(int argc, const char **argv)
@@ -1119,6 +1126,10 @@ int main(int argc, const char **argv)
bArgs *ba;
#ifdef WITH_PYTHON_MODULE
+#ifdef __APPLE__
+ environ = *_NSGetEnviron();
+#endif
+
#undef main
evil_C= C;
#endif
@@ -1132,7 +1143,7 @@ int main(int argc, const char **argv)
#endif
setCallbacks();
-#ifdef __APPLE__
+#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE)
/* patch to ignore argument finder gives us (pid?) */
if (argc==2 && strncmp(argv[1], "-psn_", 5)==0) {
extern int GHOST_HACK_getFirstFile(char buf[]);
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 445f2b8f0ba..493516aeef4 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -286,7 +286,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
if (bfd) BLO_blendfiledata_free(bfd);
- char basedpath[240];
+ char basedpath[FILE_MAX];
// base the actuator filename with respect
// to the original file working directory
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp
index 2aab0498765..c63b32830b0 100644
--- a/source/gameengine/Converter/BL_ActionActuator.cpp
+++ b/source/gameengine/Converter/BL_ActionActuator.cpp
@@ -526,8 +526,8 @@ PyAttributeDef BL_ActionActuator::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("channelNames", BL_ActionActuator, pyattr_get_channel_names),
KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority),
KX_PYATTRIBUTE_RW_FUNCTION("frame", BL_ActionActuator, pyattr_get_frame, pyattr_set_frame),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, 31, false, BL_ActionActuator, m_propname),
- KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 31, false, BL_ActionActuator, m_framepropname),
+ KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ActionActuator, m_propname),
+ KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ActionActuator, m_framepropname),
KX_PYATTRIBUTE_RW_FUNCTION("useContinue", BL_ActionActuator, pyattr_get_use_continue, pyattr_set_use_continue),
KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime),
KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ActionActuator,m_playtype,CheckType),
diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
index aa62479d420..d679d1a5792 100644
--- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp
+++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
@@ -519,8 +519,8 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = {
KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action),
KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority),
KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, 31, false, BL_ShapeActionActuator, m_propname),
- KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 31, false, BL_ShapeActionActuator, m_framepropname),
+ KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_propname),
+ KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_framepropname),
KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime),
KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType),
{ NULL } //Sentinel
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
index 4fe436d634c..bed9e538090 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
@@ -888,11 +888,11 @@ void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
{
//KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
+#if 0
Object* blenderObject = gameObj->GetBlenderObject();
if (blenderObject && blenderObject->ipo)
{
// XXX animato
-#if 0
Ipo* ipo = blenderObject->ipo;
//create the curves, if not existing
@@ -903,17 +903,11 @@ void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotX"));
testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotY"));
testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ"));
-#endif
}
+#endif
}
-
}
-
-
}
-
-
-
}
#ifdef WITH_PYTHON
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp
index be14400f33a..e577a5e5f99 100644
--- a/source/gameengine/Converter/KX_ConvertActuators.cpp
+++ b/source/gameengine/Converter/KX_ConvertActuators.cpp
@@ -83,7 +83,7 @@
#include "BLI_blenlib.h"
#include "BLI_math_base.h"
-#define FILE_MAX 240 // repeated here to avoid dependency from BKE_utildefines.h
+#define FILE_MAX 1024 // repeated here to avoid dependency from BKE_utildefines.h
#include "KX_NetworkMessageActuator.h"
diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h
index b1072dd8336..107ae453c8e 100644
--- a/source/gameengine/Expressions/PyObjectPlus.h
+++ b/source/gameengine/Expressions/PyObjectPlus.h
@@ -54,6 +54,8 @@ extern "C" {
}
#endif
+#define MAX_PROP_NAME 64
+
static inline void Py_Fatal(const char *M)
{
fprintf(stderr, "%s\n", M);
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
index 8b0ea2394c8..8b7702228ce 100644
--- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
@@ -150,7 +150,7 @@ PyMethodDef SCA_ActuatorSensor::Methods[] = {
};
PyAttributeDef SCA_ActuatorSensor::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW_CHECK("actuator",0,100,false,SCA_ActuatorSensor,m_checkactname,CheckActuator),
+ KX_PYATTRIBUTE_STRING_RW_CHECK("actuator",0,MAX_PROP_NAME,false,SCA_ActuatorSensor,m_checkactname,CheckActuator),
{ NULL } //Sentinel
};
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h
index 87b37a8ef39..051bc2aafce 100644
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.h
+++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h
@@ -133,8 +133,8 @@ public:
/* for moving logic bricks between scenes */
- virtual void Replace_IScene(SCA_IScene *val) {};
- virtual void Replace_NetworkScene(NG_NetworkScene *val) {};
+ virtual void Replace_IScene(SCA_IScene *val) {}
+ virtual void Replace_NetworkScene(NG_NetworkScene *val) {}
#ifdef WITH_PYTHON
// python methods
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
index 45780735c49..97cd01dff38 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
@@ -479,8 +479,8 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("key",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_hotkey),
KX_PYATTRIBUTE_SHORT_RW("hold1",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual),
KX_PYATTRIBUTE_SHORT_RW("hold2",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual2),
- KX_PYATTRIBUTE_STRING_RW("toggleProperty",0,100,false,SCA_KeyboardSensor,m_toggleprop),
- KX_PYATTRIBUTE_STRING_RW("targetProperty",0,100,false,SCA_KeyboardSensor,m_targetprop),
+ KX_PYATTRIBUTE_STRING_RW("toggleProperty",0,MAX_PROP_NAME,false,SCA_KeyboardSensor,m_toggleprop),
+ KX_PYATTRIBUTE_STRING_RW("targetProperty",0,MAX_PROP_NAME,false,SCA_KeyboardSensor,m_targetprop),
{ NULL } //Sentinel
};
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
index e7283978ae1..441c833d3a8 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
@@ -111,7 +111,7 @@ public:
/* --------------------------------------------------------------------- */
// KeyEvents:
- KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,getEventList);
+ KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,getEventList);
// KeyStatus:
KX_PYMETHOD_DOC_O(SCA_KeyboardSensor,getKeyStatus);
diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
index 844cf7ae96d..544b1da76af 100644
--- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
@@ -257,7 +257,7 @@ PyMethodDef SCA_PropertyActuator::Methods[] = {
};
PyAttributeDef SCA_PropertyActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,100,false,SCA_PropertyActuator,m_propname,CheckProperty),
+ KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,MAX_PROP_NAME,false,SCA_PropertyActuator,m_propname,CheckProperty),
KX_PYATTRIBUTE_STRING_RW("value",0,100,false,SCA_PropertyActuator,m_exprtxt),
KX_PYATTRIBUTE_INT_RW("mode", KX_ACT_PROP_NODEF+1, KX_ACT_PROP_MAX-1, false, SCA_PropertyActuator, m_type), /* ATTR_TODO add constents to game logic dict */
{ NULL } //Sentinel
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp
index e1ee6c75b95..8e324bbb0d7 100644
--- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp
+++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp
@@ -377,7 +377,7 @@ PyMethodDef SCA_PropertySensor::Methods[] = {
PyAttributeDef SCA_PropertySensor::Attributes[] = {
KX_PYATTRIBUTE_INT_RW_CHECK("mode",KX_PROPSENSOR_NODEF,KX_PROPSENSOR_MAX-1,false,SCA_PropertySensor,m_checktype,modeChange),
- KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,100,false,SCA_PropertySensor,m_checkpropname,CheckProperty),
+ KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,MAX_PROP_NAME,false,SCA_PropertySensor,m_checkpropname,CheckProperty),
KX_PYATTRIBUTE_STRING_RW_CHECK("value",0,100,false,SCA_PropertySensor,m_checkpropval,validValueForProperty),
KX_PYATTRIBUTE_STRING_RW_CHECK("min",0,100,false,SCA_PropertySensor,m_checkpropval,validValueForIntervalProperty),
KX_PYATTRIBUTE_STRING_RW_CHECK("max",0,100,false,SCA_PropertySensor,m_checkpropmaxval,validValueForIntervalProperty),
diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp
index 430326cbce0..59925f44040 100644
--- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp
@@ -361,7 +361,7 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = {
KX_PYATTRIBUTE_FLOAT_RO("para1",SCA_RandomActuator,m_parameter1),
KX_PYATTRIBUTE_FLOAT_RO("para2",SCA_RandomActuator,m_parameter2),
KX_PYATTRIBUTE_ENUM_RO("distribution",SCA_RandomActuator,m_distribution),
- KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,100,false,SCA_RandomActuator,m_propname,CheckProperty),
+ KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,MAX_PROP_NAME,false,SCA_RandomActuator,m_propname,CheckProperty),
KX_PYATTRIBUTE_RW_FUNCTION("seed",SCA_RandomActuator,pyattr_get_seed,pyattr_set_seed),
{ NULL } //Sentinel
};
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index c725847037a..9166f0dded4 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -765,7 +765,7 @@ int main(int argc, char** argv)
// if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
if (exitcode == KX_EXIT_REQUEST_START_OTHER_GAME)
{
- char basedpath[240];
+ char basedpath[FILE_MAX];
// base the actuator filename relative to the last file
BLI_strncpy(basedpath, exitstring.Ptr(), sizeof(basedpath));
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
index 5d5f3ff3f87..9d5a6907c46 100644
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
+++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
@@ -129,7 +129,7 @@ PyMethodDef KX_NetworkMessageActuator::Methods[] = {
};
PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("propName", 0, 100, false, KX_NetworkMessageActuator, m_toPropName),
+ KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_NetworkMessageActuator, m_toPropName),
KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject),
KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody),
KX_PYATTRIBUTE_STRING_RW("body", 0, 16384, false, KX_NetworkMessageActuator, m_body),
diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
index ea3a64d0d73..da8df24d704 100644
--- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
+++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
@@ -600,7 +600,7 @@ PyAttributeDef KX_ConstraintActuator::Attributes[] = {
KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK("direction",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_refDirection,3,pyattr_check_direction),
KX_PYATTRIBUTE_INT_RW("option",0,0xFFFF,false,KX_ConstraintActuator,m_option),
KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_ConstraintActuator,m_activeTime),
- KX_PYATTRIBUTE_STRING_RW("propName",0,32,true,KX_ConstraintActuator,m_property),
+ KX_PYATTRIBUTE_STRING_RW("propName",0,MAX_PROP_NAME,true,KX_ConstraintActuator,m_property),
KX_PYATTRIBUTE_FLOAT_RW("min",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound),
KX_PYATTRIBUTE_FLOAT_RW("distance",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound),
KX_PYATTRIBUTE_FLOAT_RW("max",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_maximumBound),
diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp
index 878bdcedfda..e0cd9726104 100644
--- a/source/gameengine/Ketsji/KX_IpoActuator.cpp
+++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp
@@ -442,8 +442,8 @@ PyMethodDef KX_IpoActuator::Methods[] = {
PyAttributeDef KX_IpoActuator::Attributes[] = {
KX_PYATTRIBUTE_RW_FUNCTION("frameStart", KX_IpoActuator, pyattr_get_frame_start, pyattr_set_frame_start),
KX_PYATTRIBUTE_RW_FUNCTION("frameEnd", KX_IpoActuator, pyattr_get_frame_end, pyattr_set_frame_end),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, 64, false, KX_IpoActuator, m_propname),
- KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 64, false, KX_IpoActuator, m_framepropname),
+ KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_IpoActuator, m_propname),
+ KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, KX_IpoActuator, m_framepropname),
KX_PYATTRIBUTE_INT_RW("mode", KX_ACT_IPO_NODEF+1, KX_ACT_IPO_MAX-1, true, KX_IpoActuator, m_type),
KX_PYATTRIBUTE_BOOL_RW("useIpoAsForce", KX_IpoActuator, m_ipo_as_force),
KX_PYATTRIBUTE_BOOL_RW("useIpoAdd", KX_IpoActuator, m_ipo_add),
diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp
index 6fa14c94f99..0cc0e7318c1 100644
--- a/source/gameengine/Ketsji/KX_RaySensor.cpp
+++ b/source/gameengine/Ketsji/KX_RaySensor.cpp
@@ -352,7 +352,7 @@ PyAttributeDef KX_RaySensor::Attributes[] = {
KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_RaySensor, m_bFindMaterial),
KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_RaySensor, m_bXRay),
KX_PYATTRIBUTE_FLOAT_RW("range", 0, 10000, KX_RaySensor, m_distance),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, 100, false, KX_RaySensor, m_propertyname),
+ KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_RaySensor, m_propertyname),
KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RaySensor, m_axis),
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3),
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3),
diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp
index 16474437142..33708059784 100644
--- a/source/gameengine/Ketsji/KX_SceneActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp
@@ -249,7 +249,7 @@ PyMethodDef KX_SceneActuator::Methods[] =
};
PyAttributeDef KX_SceneActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("scene",0,32,true,KX_SceneActuator,m_nextSceneName),
+ KX_PYATTRIBUTE_STRING_RW("scene",0,MAX_ID_NAME-2,true,KX_SceneActuator,m_nextSceneName),
KX_PYATTRIBUTE_RW_FUNCTION("camera",KX_SceneActuator,pyattr_get_camera,pyattr_set_camera),
KX_PYATTRIBUTE_BOOL_RW("useRestart", KX_SceneActuator, m_restart),
KX_PYATTRIBUTE_INT_RW("mode", KX_SCENE_NODEF+1, KX_SCENE_MAX-1, true, KX_SceneActuator, m_mode),
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp
index aa864349035..d7bcf1306a1 100644
--- a/source/gameengine/Ketsji/KX_TouchSensor.cpp
+++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp
@@ -321,7 +321,7 @@ PyMethodDef KX_TouchSensor::Methods[] = {
};
PyAttributeDef KX_TouchSensor::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("propName",0,100,false,KX_TouchSensor,m_touchedpropname),
+ KX_PYATTRIBUTE_STRING_RW("propName",0,MAX_PROP_NAME,false,KX_TouchSensor,m_touchedpropname),
KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial),
KX_PYATTRIBUTE_BOOL_RW("usePulseCollision",KX_TouchSensor,m_bTouchPulse),
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_TouchSensor, pyattr_get_object_hit),
diff --git a/source/gameengine/Rasterizer/RAS_TexVert.cpp b/source/gameengine/Rasterizer/RAS_TexVert.cpp
index 18a987a332a..1e8630c72d8 100644
--- a/source/gameengine/Rasterizer/RAS_TexVert.cpp
+++ b/source/gameengine/Rasterizer/RAS_TexVert.cpp
@@ -104,7 +104,7 @@ void RAS_TexVert::SetFlag(const short flag)
void RAS_TexVert::SetUnit(const unsigned int u)
{
- m_unit = u<=MAX_UNIT?u:MAX_UNIT;
+ m_unit = u <= (unsigned int) MAX_UNIT ? u: (unsigned int)MAX_UNIT;
}
void RAS_TexVert::SetNormal(const MT_Vector3& normal)
diff --git a/source/tests/bl_mesh_modifiers.py b/source/tests/bl_mesh_modifiers.py
index af6aaae819c..917ccbc0d24 100644
--- a/source/tests/bl_mesh_modifiers.py
+++ b/source/tests/bl_mesh_modifiers.py
@@ -25,12 +25,18 @@
# Later, we may have a way to check the results are valid.
-# ./blender.bin --factory-startup --python bl_mesh_modifiers.py
+# ./blender.bin --factory-startup --python source/tests/bl_mesh_modifiers.py
+#
+
+import math
+USE_QUICK_RENDER = False
+IS_BMESH = hasattr(__import__("bpy").types, "LoopColors")
# -----------------------------------------------------------------------------
# utility funcs
+
def render_gl(context, filepath, shade):
def ctx_viewport_shade(context, shade):
@@ -45,6 +51,7 @@ def render_gl(context, filepath, shade):
render = scene.render
render.filepath = filepath
render.image_settings.file_format = 'PNG'
+ render.image_settings.color_mode = 'RGB'
render.use_file_extension = True
render.use_antialiasing = False
@@ -55,15 +62,16 @@ def render_gl(context, filepath, shade):
ctx_viewport_shade(context, shade)
+ #~ # stop to inspect!
+ #~ if filepath == "test_cube_shell_solidify_subsurf_wp_wire":
+ #~ assert(0)
+ #~ else:
+ #~ return
+
bpy.ops.render.opengl(write_still=True,
view_context=True)
- # stop to inspect!
- # if filepath == "test_cube_shell_solidify_subsurf_ob_textured":
- # assert(0)
-
-
def render_gl_all_modes(context, obj, filepath=""):
assert(obj != None)
@@ -79,8 +87,12 @@ def render_gl_all_modes(context, obj, filepath=""):
scene.tool_settings.mesh_select_mode = False, True, False
# render
- render_gl(context, filepath + "_ob_wire", shade='WIREFRAME')
render_gl(context, filepath + "_ob_solid", shade='SOLID')
+
+ if USE_QUICK_RENDER:
+ return
+
+ render_gl(context, filepath + "_ob_wire", shade='WIREFRAME')
render_gl(context, filepath + "_ob_textured", shade='TEXTURED')
# -------------------------------------------------------------------------
@@ -191,13 +203,34 @@ def defaults_object(obj):
mesh.show_normal_vertex = True
# lame!
- for face in mesh.faces:
- face.use_smooth = True
+ if IS_BMESH:
+ for poly in mesh.polygons:
+ poly.use_smooth = True
+ else:
+ for face in mesh.faces:
+ face.use_smooth = True
+
+
+def defaults_modifier(mod):
+ mod.show_in_editmode = True
+ mod.show_on_cage = True
# -----------------------------------------------------------------------------
# models (utils)
+
+if IS_BMESH:
+ def mesh_bmesh_poly_elems(poly, elems):
+ vert_start = poly.loop_start
+ vert_total = poly.loop_total
+ return elems[vert_start:vert_start + vert_total]
+
+ def mesh_bmesh_poly_vertices(poly):
+ return [loop.vertex_index
+ for loop in mesh_bmesh_poly_elems(poly, poly.id_data.loops)]
+
+
def mesh_bounds(mesh):
xmin = ymin = zmin = +100000000.0
xmax = ymax = zmax = -100000000.0
@@ -216,23 +249,67 @@ def mesh_bounds(mesh):
def mesh_uv_add(obj):
+
+ uvs = ((0.0, 0.0),
+ (0.0, 1.0),
+ (1.0, 1.0),
+ (1.0, 0.0))
+
uv_lay = obj.data.uv_textures.new()
- for uv in uv_lay.data:
- uv.uv1 = 0.0, 0.0
- uv.uv2 = 0.0, 1.0
- uv.uv3 = 1.0, 1.0
- uv.uv4 = 1.0, 0.0
+
+ if IS_BMESH:
+ # XXX, odd that we need to do this. until uvs and texface
+ # are separated we will need to keep it
+ uv_loops = obj.data.uv_loop_layers[-1]
+ uv_list = uv_loops.data[:]
+ for poly in obj.data.polygons:
+ poly_uvs = mesh_bmesh_poly_elems(poly, uv_list)
+ for i, c in enumerate(poly_uvs):
+ c.uv = uvs[i % 4]
+ else:
+ for uv in uv_lay.data:
+ uv.uv1 = uvs[0]
+ uv.uv2 = uvs[1]
+ uv.uv3 = uvs[2]
+ uv.uv4 = uvs[3]
return uv_lay
def mesh_vcol_add(obj, mode=0):
+
+ colors = ((0.0, 0.0, 0.0), # black
+ (1.0, 0.0, 0.0), # red
+ (0.0, 1.0, 0.0), # green
+ (0.0, 0.0, 1.0), # blue
+ (1.0, 1.0, 0.0), # yellow
+ (0.0, 1.0, 1.0), # cyan
+ (1.0, 0.0, 1.0), # magenta
+ (1.0, 1.0, 1.0), # white
+ )
+
+ def colors_get(i):
+ return colors[i % len(colors)]
+
vcol_lay = obj.data.vertex_colors.new()
- for col in vcol_lay.data:
- col.color1 = 1.0, 0.0, 0.0
- col.color2 = 0.0, 1.0, 0.0
- col.color3 = 0.0, 0.0, 1.0
- col.color4 = 0.0, 0.0, 0.0
+
+ mesh = obj.data
+
+ if IS_BMESH:
+ col_list = vcol_lay.data[:]
+ for poly in mesh.polygons:
+ face_verts = mesh_bmesh_poly_vertices(poly)
+ poly_cols = mesh_bmesh_poly_elems(poly, col_list)
+ for i, c in enumerate(poly_cols):
+ c.color = colors_get(face_verts[i])
+ else:
+ for i, col in enumerate(vcol_lay.data):
+ face_verts = mesh.faces[i].vertices
+ col.color1 = colors_get(face_verts[0])
+ col.color2 = colors_get(face_verts[1])
+ col.color3 = colors_get(face_verts[2])
+ if len(face_verts) == 4:
+ col.color4 = colors_get(face_verts[3])
return vcol_lay
@@ -268,34 +345,33 @@ def mesh_armature_add(obj, mode=0):
# -----------------------------------------------------------------------------
# modifiers
-def modifier_subsurf_add(obj, levels=2):
+def modifier_subsurf_add(scene, obj, levels=2):
mod = obj.modifiers.new(name=whoami(), type='SUBSURF')
- mod.show_in_editmode = True
+ defaults_modifier(mod)
mod.levels = levels
mod.render_levels = levels
return mod
-def modifier_armature_add(obj):
+def modifier_armature_add(scene, obj):
mod = obj.modifiers.new(name=whoami(), type='ARMATURE')
- mod.show_in_editmode = True
+ defaults_modifier(mod)
arm_data = bpy.data.armatures.new(whoami())
- arm_ob = bpy.data.objects.new(whoami(), arm_data)
+ obj_arm = bpy.data.objects.new(whoami(), arm_data)
- scene = bpy.context.scene
- scene.objects.link(arm_ob)
+ scene.objects.link(obj_arm)
- arm_ob.select = True
- scene.objects.active = arm_ob
+ obj_arm.select = True
+ scene.objects.active = obj_arm
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
# XXX, annoying, remove bone.
while arm_data.edit_bones:
- arm_ob.edit_bones.remove(arm_data.edit_bones[-1])
+ obj_arm.edit_bones.remove(arm_data.edit_bones[-1])
bone_a = arm_data.edit_bones.new("Bone.A")
bone_b = arm_data.edit_bones.new("Bone.B")
@@ -310,17 +386,17 @@ def modifier_armature_add(obj):
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# 45d armature
- arm_ob.pose.bones["Bone.B"].rotation_quaternion = 1, -0.5, 0, 0
+ obj_arm.pose.bones["Bone.B"].rotation_quaternion = 1, -0.5, 0, 0
# set back to the original
scene.objects.active = obj
# display options
- arm_ob.show_x_ray = True
+ obj_arm.show_x_ray = True
arm_data.draw_type = 'STICK'
# apply to modifier
- mod.object = arm_ob
+ mod.object = obj_arm
mesh_vgroup_add(obj, name="Bone.A", axis=0, invert=True)
mesh_vgroup_add(obj, name="Bone.B", axis=0, invert=False)
@@ -328,22 +404,96 @@ def modifier_armature_add(obj):
return mod
-def modifier_mirror_add(obj):
+def modifier_mirror_add(scene, obj):
mod = obj.modifiers.new(name=whoami(), type='MIRROR')
- mod.show_in_editmode = True
+ defaults_modifier(mod)
return mod
-def modifier_solidify_add(obj, thickness=0.25):
+def modifier_solidify_add(scene, obj, thickness=0.25):
mod = obj.modifiers.new(name=whoami(), type='SOLIDIFY')
- mod.show_in_editmode = True
+ defaults_modifier(mod)
mod.thickness = thickness
return mod
+def modifier_hook_add(scene, obj, use_vgroup=True):
+ scene.objects.active = obj
+
+ # no nice way to add hooks from py api yet
+ # assume object mode, hook first face!
+ mesh = obj.data
+
+ if use_vgroup:
+ for v in mesh.vertices:
+ v.select = True
+ else:
+ for v in mesh.vertices:
+ v.select = False
+
+ if IS_BMESH:
+ face_verts = mesh_bmesh_poly_vertices(mesh.polygons[0])
+ else:
+ face_verts = mesh.faces[0].vertices[:]
+
+ for i in mesh.faces[0].vertices:
+ mesh.vertices[i].select = True
+
+ bpy.ops.object.mode_set(mode='EDIT', toggle=False)
+ bpy.ops.object.hook_add_newob()
+ bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
+
+ # mod = obj.modifiers.new(name=whoami(), type='HOOK')
+ mod = obj.modifiers[-1]
+ defaults_modifier(mod)
+
+ obj_hook = mod.object
+ obj_hook.rotation_euler = 0, math.radians(45), 0
+ obj_hook.show_x_ray = True
+
+ if use_vgroup:
+ mod.vertex_group = obj.vertex_groups[0].name
+
+ return mod
+
+
+def modifier_decimate_add(scene, obj):
+ mod = obj.modifiers.new(name=whoami(), type='DECIMATE')
+ defaults_modifier(mod)
+
+ mod.ratio = 1 / 3
+
+ return mod
+
+
+def modifier_build_add(scene, obj):
+ mod = obj.modifiers.new(name=whoami(), type='BUILD')
+ defaults_modifier(mod)
+
+ # ensure we display some faces
+ if IS_BMESH:
+ totface = len(obj.data.polygons)
+ else:
+ totface = len(obj.data.faces)
+
+ mod.frame_start = totface // 2
+ mod.frame_duration = totface
+
+ return mod
+
+
+def modifier_mask_add(scene, obj):
+ mod = obj.modifiers.new(name=whoami(), type='MASK')
+ defaults_modifier(mod)
+
+ mod.vertex_group = obj.vertex_groups[0].name
+
+ return mod
+
+
# -----------------------------------------------------------------------------
# models
@@ -578,6 +728,22 @@ global_tests.append(("mirror_single",
((modifier_mirror_add, dict()), ),
))
+global_tests.append(("hook_single",
+ ((modifier_hook_add, dict()), ),
+ ))
+
+global_tests.append(("decimate_single",
+ ((modifier_decimate_add, dict()), ),
+ ))
+
+global_tests.append(("build_single",
+ ((modifier_build_add, dict()), ),
+ ))
+
+global_tests.append(("mask_single",
+ ((modifier_mask_add, dict()), ),
+ ))
+
# combinations
global_tests.append(("mirror_subsurf",
@@ -591,7 +757,7 @@ global_tests.append(("solidify_subsurf",
))
-def apply_test(test, obj,
+def apply_test(test, scene, obj,
render_func=None,
render_args=None,
render_kwargs=None,
@@ -600,7 +766,7 @@ def apply_test(test, obj,
test_name, test_funcs = test
for cb, kwargs in test_funcs:
- cb(obj, **kwargs)
+ cb(scene, obj, **kwargs)
render_kwargs_copy = render_kwargs.copy()
@@ -612,14 +778,16 @@ def apply_test(test, obj,
# -----------------------------------------------------------------------------
# tests themselves!
+# having the 'test_' prefix automatically means these functions are called
+# for testing
def test_cube(context, test):
scene = context.scene
obj = make_cube_extra(scene)
- ctx_camera_setup(context, location=(4, 4, 4))
+ ctx_camera_setup(context, location=(3, 3, 3))
- apply_test(test, obj,
+ apply_test(test, scene, obj,
render_func=render_gl_all_modes,
render_args=(context, obj),
render_kwargs=dict(filepath=whoami()))
@@ -630,7 +798,7 @@ def test_cube_like(context, test):
obj = make_cube_like_extra(scene)
ctx_camera_setup(context, location=(5, 5, 5))
- apply_test(test, obj,
+ apply_test(test, scene, obj,
render_func=render_gl_all_modes,
render_args=(context, obj),
render_kwargs=dict(filepath=whoami()))
@@ -641,7 +809,7 @@ def test_cube_shell(context, test):
obj = make_cube_shell_extra(scene)
ctx_camera_setup(context, location=(4, 4, 4))
- apply_test(test, obj,
+ apply_test(test, scene, obj,
render_func=render_gl_all_modes,
render_args=(context, obj),
render_kwargs=dict(filepath=whoami()))
@@ -682,7 +850,6 @@ if __name__ == "__main__":
bpy.app.handlers.scene_update_post.remove(load_handler)
try:
main()
-
import sys
sys.exit(0)
except:
@@ -691,6 +858,7 @@ if __name__ == "__main__":
import sys
# sys.exit(1) # comment to debug
+
else:
load_handler.first = False