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:
authorLukas Tönne <lukas.toenne@gmail.com>2016-04-28 18:33:19 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2016-04-28 18:33:19 +0300
commit1f723603c882e6d79ab69bea6e5c034ae21a6ce7 (patch)
tree098b0133beea06c460c3e9e92010bc669d151e5d
parent3632c4997f5019d2a519996d9e216d474aa05d3b (diff)
parenta48d7407986d04492107a2ef16d0ff6f0d012c45 (diff)
Merge branch 'master' into temp_remove_particlestemp_remove_particles
-rw-r--r--CMakeLists.txt8
-rwxr-xr-xbuild_files/build_environment/install_deps.sh116
-rw-r--r--build_files/build_environment/install_deps_patches/llvm.patch15
-rw-r--r--build_files/buildbot/slave_compile.py2
-rw-r--r--build_files/buildbot/slave_pack.py2
-rw-r--r--build_files/cmake/config/blender_full.cmake2
-rw-r--r--build_files/cmake/macros.cmake7
-rw-r--r--doc/python_api/examples/bpy.props.3.py2
-rw-r--r--doc/python_api/examples/bpy.props.5.py6
-rwxr-xr-xdoc/python_api/sphinx_doc_gen.sh8
-rw-r--r--extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp2
-rw-r--r--extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp9
-rw-r--r--extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h4
-rw-r--r--extern/carve/lib/geom2d.cpp4
-rw-r--r--extern/carve/lib/geom3d.cpp2
-rw-r--r--extern/carve/lib/intersect.cpp10
-rw-r--r--extern/carve/lib/intersect_classify_edge.cpp5
-rw-r--r--extern/carve/lib/intersect_face_division.cpp2
-rw-r--r--extern/carve/lib/math.cpp6
-rw-r--r--extern/carve/lib/mesh.cpp2
-rw-r--r--extern/lzma/LzmaEnc.c3
-rw-r--r--intern/cycles/blender/blender_mesh.cpp9
-rw-r--r--intern/cycles/bvh/bvh.cpp3
-rw-r--r--intern/cycles/bvh/bvh_build.cpp11
-rw-r--r--intern/cycles/bvh/bvh_split.cpp7
-rw-r--r--intern/cycles/kernel/kernel_bake.h2
-rw-r--r--intern/cycles/render/light.cpp4
-rw-r--r--intern/cycles/render/mesh.cpp6
-rw-r--r--intern/cycles/render/object.cpp338
-rw-r--r--intern/cycles/render/object.h60
-rw-r--r--intern/cycles/render/osl.cpp4
-rw-r--r--intern/cycles/render/particles.cpp6
-rw-r--r--intern/cycles/render/scene.cpp20
-rw-r--r--intern/cycles/render/scene.h5
-rw-r--r--intern/cycles/render/session.cpp2
-rw-r--r--intern/cycles/render/svm.cpp4
-rw-r--r--intern/cycles/render/tables.cpp4
-rw-r--r--intern/cycles/util/util_guarded_allocator.h35
-rw-r--r--intern/cycles/util/util_stack_allocator.h25
-rw-r--r--intern/cycles/util/util_vector.h6
-rw-r--r--intern/elbeem/intern/loop_tools.h3
-rw-r--r--intern/elbeem/intern/ntl_ray.cpp6
-rw-r--r--intern/elbeem/intern/solver_init.cpp6
-rw-r--r--intern/elbeem/intern/solver_main.cpp2
-rw-r--r--intern/ghost/intern/GHOST_NDOFManagerUnix.cpp18
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp15
-rw-r--r--intern/openvdb/intern/openvdb_dense_convert.cc3
-rw-r--r--intern/openvdb/intern/openvdb_dense_convert.h3
-rw-r--r--release/scripts/startup/bl_ui/properties_data_modifier.py12
-rw-r--r--release/scripts/startup/bl_ui/space_sequencer.py10
-rw-r--r--release/scripts/startup/bl_ui/space_view3d.py2
-rw-r--r--release/scripts/startup/nodeitems_builtins.py17
-rw-r--r--source/blender/blenfont/BLF_api.h4
-rw-r--r--source/blender/blenfont/intern/blf.c11
-rw-r--r--source/blender/blenfont/intern/blf_font.c2
-rw-r--r--source/blender/blenkernel/BKE_DerivedMesh.h24
-rw-r--r--source/blender/blenkernel/BKE_blender.h82
-rw-r--r--source/blender/blenkernel/BKE_blender_copybuffer.h46
-rw-r--r--source/blender/blenkernel/BKE_blender_undo.h52
-rw-r--r--source/blender/blenkernel/BKE_blender_version.h44
-rw-r--r--source/blender/blenkernel/BKE_blendfile.h67
-rw-r--r--source/blender/blenkernel/BKE_mask.h6
-rw-r--r--source/blender/blenkernel/BKE_mesh.h5
-rw-r--r--source/blender/blenkernel/CMakeLists.txt9
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c402
-rw-r--r--source/blender/blenkernel/intern/action.c6
-rw-r--r--source/blender/blenkernel/intern/appdir.c2
-rw-r--r--source/blender/blenkernel/intern/armature.c13
-rw-r--r--source/blender/blenkernel/intern/blender.c977
-rw-r--r--source/blender/blenkernel/intern/blender_copybuffer.c143
-rw-r--r--source/blender/blenkernel/intern/blender_undo.c393
-rw-r--r--source/blender/blenkernel/intern/blendfile.c566
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c24
-rw-r--r--source/blender/blenkernel/intern/constraint.c2
-rw-r--r--source/blender/blenkernel/intern/customdata.c2
-rw-r--r--source/blender/blenkernel/intern/depsgraph.c35
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c235
-rw-r--r--source/blender/blenkernel/intern/font.c5
-rw-r--r--source/blender/blenkernel/intern/image.c2
-rw-r--r--source/blender/blenkernel/intern/image_gen.c7
-rw-r--r--source/blender/blenkernel/intern/mask.c2
-rw-r--r--source/blender/blenkernel/intern/material.c17
-rw-r--r--source/blender/blenkernel/intern/mesh_evaluate.c40
-rw-r--r--source/blender/blenkernel/intern/pointcache.c1
-rw-r--r--source/blender/blenkernel/intern/seqeffects.c12
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c30
-rw-r--r--source/blender/blenloader/intern/readfile.c16
-rw-r--r--source/blender/blenloader/intern/versioning_270.c16
-rw-r--r--source/blender/blenloader/intern/writefile.c2
-rw-r--r--source/blender/bmesh/tools/bmesh_decimate_dissolve.c6
-rw-r--r--source/blender/collada/DocumentExporter.cpp2
-rw-r--r--source/blender/collada/MeshImporter.cpp1
-rw-r--r--source/blender/depsgraph/intern/depsgraph_build.cc26
-rw-r--r--source/blender/depsgraph/intern/depsgraph_build_nodes.cc16
-rw-r--r--source/blender/depsgraph/intern/depsgraph_eval.cc115
-rw-r--r--source/blender/depsgraph/intern/depsgraph_tag.cc7
-rw-r--r--source/blender/editors/animation/drivers.c2
-rw-r--r--source/blender/editors/armature/editarmature_sketch.c20
-rw-r--r--source/blender/editors/curve/editcurve.c21
-rw-r--r--source/blender/editors/curve/editcurve_paint.c92
-rw-r--r--source/blender/editors/gpencil/gpencil_undo.c2
-rw-r--r--source/blender/editors/include/ED_transform.h87
-rw-r--r--source/blender/editors/include/ED_view3d.h12
-rw-r--r--source/blender/editors/interface/interface_handlers.c2
-rw-r--r--source/blender/editors/interface/interface_panel.c2
-rw-r--r--source/blender/editors/interface/interface_regions.c6
-rw-r--r--source/blender/editors/interface/interface_style.c6
-rw-r--r--source/blender/editors/interface/resources.c2
-rw-r--r--source/blender/editors/mask/mask_add.c89
-rw-r--r--source/blender/editors/mesh/editmesh_bevel.c11
-rw-r--r--source/blender/editors/mesh/editmesh_extrude.c28
-rw-r--r--source/blender/editors/mesh/editmesh_inset.c10
-rw-r--r--source/blender/editors/mesh/editmesh_select.c47
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c26
-rw-r--r--source/blender/editors/object/object_bake.c6
-rw-r--r--source/blender/editors/physics/dynamicpaint_ops.c3
-rw-r--r--source/blender/editors/render/render_internal.c3
-rw-r--r--source/blender/editors/screen/glutil.c9
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c8
-rw-r--r--source/blender/editors/sculpt_paint/paint_undo.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex.c4
-rw-r--r--source/blender/editors/space_action/action_edit.c5
-rw-r--r--source/blender/editors/space_file/filesel.c2
-rw-r--r--source/blender/editors/space_graph/graph_edit.c4
-rw-r--r--source/blender/editors/space_image/image_buttons.c2
-rw-r--r--source/blender/editors/space_image/image_ops.c57
-rw-r--r--source/blender/editors/space_info/info_stats.c2
-rw-r--r--source/blender/editors/space_nla/nla_edit.c4
-rw-r--r--source/blender/editors/space_node/node_templates.c36
-rw-r--r--source/blender/editors/space_outliner/outliner_edit.c34
-rw-r--r--source/blender/editors/space_outliner/outliner_intern.h10
-rw-r--r--source/blender/editors/space_outliner/outliner_tree.c62
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c82
-rw-r--r--source/blender/editors/space_view3d/view3d_ops.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_ruler.c62
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c33
-rw-r--r--source/blender/editors/space_view3d/view3d_walk.c51
-rw-r--r--source/blender/editors/transform/CMakeLists.txt1
-rw-r--r--source/blender/editors/transform/transform.h10
-rw-r--r--source/blender/editors/transform/transform_generics.c2
-rw-r--r--source/blender/editors/transform/transform_snap.c899
-rw-r--r--source/blender/editors/transform/transform_snap_object.c1207
-rw-r--r--source/blender/editors/util/editmode_undo.c2
-rw-r--r--source/blender/editors/util/undo.c2
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl18
-rw-r--r--source/blender/imbuf/intern/cineon/dpxlib.c4
-rw-r--r--source/blender/imbuf/intern/stereoimbuf.c3
-rw-r--r--source/blender/makesdna/DNA_fileglobal_types.h2
-rw-r--r--source/blender/makesdna/DNA_material_types.h5
-rw-r--r--source/blender/makesdna/DNA_sequence_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_fcurve.c111
-rw-r--r--source/blender/makesrna/intern/rna_nla.c62
-rw-r--r--source/blender/makesrna/intern/rna_scene.c2
-rw-r--r--source/blender/makesrna/intern/rna_scene_api.c21
-rw-r--r--source/blender/makesrna/intern/rna_sequencer.c10
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c4
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c6
-rw-r--r--source/blender/nodes/shader/node_shader_util.h1
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_lamp.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mapping.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_normal_map.c110
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_material.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_world.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_environment.c21
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_image.c20
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_texture.c22
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vectMath.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vectTransform.c16
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_absorption.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_scatter.c2
-rw-r--r--source/blender/nodes/texture/node_texture_util.h1
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c6
-rw-r--r--source/blender/python/generic/blf_py_api.c10
-rw-r--r--source/blender/python/intern/bpy.c2
-rw-r--r--source/blender/python/intern/bpy_app.c2
-rw-r--r--source/blender/python/intern/bpy_driver.c16
-rw-r--r--source/blender/python/intern/bpy_library_write.c17
-rw-r--r--source/blender/render/extern/include/RE_shader_ext.h1
-rw-r--r--source/blender/render/intern/include/render_types.h2
-rw-r--r--source/blender/render/intern/include/renderdatabase.h4
-rw-r--r--source/blender/render/intern/source/bake_api.c2
-rw-r--r--source/blender/render/intern/source/convertblender.c60
-rw-r--r--source/blender/render/intern/source/multires_bake.c2
-rw-r--r--source/blender/render/intern/source/renderdatabase.c41
-rw-r--r--source/blender/render/intern/source/shadeinput.c37
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c25
-rw-r--r--source/blender/windowmanager/intern/wm_files.c24
-rw-r--r--source/blender/windowmanager/intern/wm_init_exit.c13
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c4
-rw-r--r--source/blender/windowmanager/intern/wm_window.c6
-rw-r--r--source/blenderplayer/bad_level_call_stubs/stubs.c19
-rw-r--r--source/creator/CMakeLists.txt9
-rw-r--r--source/creator/creator.c2
-rw-r--r--source/creator/creator_args.c2
-rw-r--r--source/creator/creator_signals.c2
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.cpp2
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp6
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp2
199 files changed, 5012 insertions, 3185 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f05e9680c0a..438cb1cdd9f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -166,7 +166,7 @@ option_defaults_init(
)
# customize...
-if (UNIX AND NOT APPLE)
+if(UNIX AND NOT APPLE)
# some of these libraries are problematic on Linux
# disable less important dependencies by default
set(_init_CODEC_FFMPEG OFF)
@@ -2319,6 +2319,12 @@ elseif(APPLE)
endif()
# Get rid of eventually clashes, we export some symbols explicite as local
set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map")
+
+ # Suppress ranlib "has no symbols" warnings (workaround for T48250)
+ set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
+ set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()
#-----------------------------------------------------------------------------
diff --git a/build_files/build_environment/install_deps.sh b/build_files/build_environment/install_deps.sh
index de54ecbd946..75da86db9ea 100755
--- a/build_files/build_environment/install_deps.sh
+++ b/build_files/build_environment/install_deps.sh
@@ -341,7 +341,7 @@ OPENVDB_SKIP=false
# Version??
OPENCOLLADA_VERSION="1.3"
-OPENCOLLADA_FORCE_BUILD=true # no package!
+OPENCOLLADA_FORCE_BUILD=false
OPENCOLLADA_FORCE_REBUILD=false
OPENCOLLADA_SKIP=false
@@ -3288,7 +3288,7 @@ install_RPM() {
#### Install on ARCH-like ####
get_package_version_ARCH() {
- pacman -Si $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
+ pacman -Si $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+?(([0-9]+\.?)+).*/\1/'
}
check_package_ARCH() {
@@ -3385,8 +3385,8 @@ install_ARCH() {
_packages="base-devel git cmake \
libxi libxcursor libxrandr libxinerama glew libpng libtiff wget openal \
- $OPENJPEG_DEV $VORBIS_DEV $OGG_DEV $THEORA_DEV yasm sdl fftw \
- libxml2 yaml-cpp tinyxml"
+ $OPENJPEG_DEV $VORBIS_DEV $OGG_DEV $THEORA_DEV yasm sdl fftw intel-tbb \
+ libxml2 yaml-cpp tinyxml python-requests jemalloc"
OPENJPEG_USE=true
VORBIS_USE=true
@@ -3394,8 +3394,7 @@ install_ARCH() {
THEORA_USE=true
if [ "$WITH_ALL" = true ]; then
- # No libspacenav in official arch repos...
- _packages="$_packages jack"
+ _packages="$_packages jack libspnav"
fi
PRINT ""
@@ -3456,17 +3455,15 @@ install_ARCH() {
install_packages_ARCH python
clean_Python
PRINT ""
- if [ "$WITH_NUMPY" = true ]; then
- if [ "$NUMPY_SKIP" = true ]; then
- WARNING "Skipping NumPy installation, as requested..."
- else
- check_package_version_ge_ARCH python-numpy $NUMPY_VERSION_MIN
- if [ $? -eq 0 ]; then
- install_packages_ARCH python-numpy
+ if [ "$NUMPY_SKIP" = true ]; then
+ WARNING "Skipping NumPy installation, as requested..."
+ else
+ check_package_version_ge_ARCH python-numpy $NUMPY_VERSION_MIN
+ if [ $? -eq 0 ]; then
+ install_packages_ARCH python-numpy
else
WARNING "Sorry, using python package but no valid numpy package available!" \
- " Use --build-numpy to force building of both Python and NumPy."
- fi
+ "Use --build-numpy to force building of both Python and NumPy."
fi
fi
else
@@ -3501,27 +3498,21 @@ install_ARCH() {
fi
fi
+
PRINT ""
- _do_compile_ocio=false
if [ "$OCIO_SKIP" = true ]; then
WARNING "Skipping OpenColorIO installation, as requested..."
elif [ "$OCIO_FORCE_BUILD" = true ]; then
INFO "Forced OpenColorIO building, as requested..."
- _do_compile_ocio=true
- else
- # XXX Always force build of own OCIO, until linux distro guys update their package to default libyaml-cpp ver (0.5)!
- #check_package_version_ge_ARCH opencolorio $OCIO_VERSION_MIN
- #if [ $? -eq 0 ]; then
- #install_packages_ARCH opencolorio yaml-cpp tinyxml
- #clean_OCIO
- #else
- _do_compile_ocio=true
- #fi
- fi
-
- if [ "$_do_compile_ocio" = true ]; then
- install_packages_ARCH yaml-cpp tinyxml
compile_OCIO
+ else
+ check_package_version_ge_ARCH opencolorio $OCIO_VERSION_MIN
+ if [ $? -eq 0 ]; then
+ install_packages_ARCH opencolorio
+ clean_OCIO
+ else
+ compile_OCIO
+ fi
fi
@@ -3570,11 +3561,11 @@ install_ARCH() {
INFO "Forced LLVM building, as requested..."
_do_compile_llvm=true
else
- check_package_version_match_ARCH clang $LLVM_VERSION
+ check_package_version_match_ARCH llvm35 $LLVM_VERSION_MIN
if [ $? -eq 0 ]; then
- install_packages_ARCH llvm clang
+ install_packages_ARCH llvm35 clang35
have_llvm=true
- LLVM_VERSION=`check_package_version_ge_ARCH clang $LLVM_VERSION_MIN`
+ LLVM_VERSION=`get_package_version_ARCH llvm`
LLVM_VERSION_FOUND=$LLVM_VERSION
clean_LLVM
else
@@ -3586,8 +3577,6 @@ install_ARCH() {
install_packages_ARCH libffi
# LLVM can't find the arch ffi header dir...
_FFI_INCLUDE_DIR=`pacman -Ql libffi | grep -e ".*/ffi.h" | awk '{print $2}' | sed -r 's/(.*)\/ffi.h/\1/'`
- # LLVM 3.1 needs python2 to build and arch defaults to python3
- _PYTHON2_BIN="/usr/bin/python2"
PRINT ""
compile_LLVM
have_llvm=true
@@ -3603,19 +3592,18 @@ install_ARCH() {
INFO "Forced OpenShadingLanguage building, as requested..."
_do_compile_osl=true
else
- check_package_version_ge_ARCH openshadinglanguage $OSL_VERSION_MIN
- if [ $? -eq 0 ]; then
- install_packages_ARCH openshadinglanguage
- clean_OSL
- else
+ # XXX Compile for now due to requirement of LLVM 3.4 ...
+ #check_package_version_ge_ARCH openshadinglanguage $OSL_VERSION_MIN
+ #if [ $? -eq 0 ]; then
+ # install_packages_ARCH openshadinglanguage
+ # clean_OSL
+ #else
_do_compile_osl=true
- fi
+ #fi
fi
if [ "$_do_compile_osl" = true ]; then
if [ "$have_llvm" = true ]; then
- #XXX Note: will fail to build with LLVM 3.2!
- install_packages_ARCH intel-tbb
PRINT ""
compile_OSL
else
@@ -3625,21 +3613,19 @@ install_ARCH() {
PRINT ""
- _do_compile_osd=false
if [ "$OSD_SKIP" = true ]; then
WARNING "Skipping OpenSubdiv installation, as requested..."
elif [ "$OSD_FORCE_BUILD" = true ]; then
INFO "Forced OpenSubdiv building, as requested..."
- _do_compile_osd=true
- else
- # No package currently? Just build for now!
- _do_compile_osd=true
- fi
-
- if [ "$_do_compile_osd" = true ]; then
- install_packages_ARCH intel-tbb
- PRINT ""
compile_OSD
+ else
+ check_package_version_ge_ARCH opensubdiv $OSD_VERSION_MIN
+ if [ $? -eq 0 ]; then
+ install_packages_ARCH opensubdiv
+ clean_OSD
+ else
+ compile_OSD
+ fi
fi
@@ -3871,7 +3857,7 @@ print_info_ffmpeglink_RPM() {
}
print_info_ffmpeglink_ARCH() {
- pacman -Ql $_packages | grep -e ".*\/lib[^\/]\+\.so$" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", $0)); nlines++ }'
+ pacman -Ql $_packages | grep -e ".*\/lib[^\/]\+\.so$" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
}
print_info_ffmpeglink() {
@@ -3972,12 +3958,15 @@ print_info() {
_buildargs="$_buildargs $_1 $_2"
fi
- if [ -d $INST/ocio ]; then
+ if [ "$OCIO_SKIP" = false ]; then
_1="-D WITH_OPENCOLORIO=ON"
- _2="-D OPENCOLORIO_ROOT_DIR=$INST/ocio"
PRINT " $_1"
- PRINT " $_2"
- _buildargs="$_buildargs $_1 $_2"
+ _buildargs="$_buildargs $_1"
+ if [ -d $INST/ocio ]; then
+ _1="-D OPENCOLORIO_ROOT_DIR=$INST/ocio"
+ PRINT " $_1"
+ _buildargs="$_buildargs $_1"
+ fi
fi
if [ -d $INST/openexr ]; then
@@ -4022,12 +4011,15 @@ print_info() {
_buildargs="$_buildargs $_1 $_2"
fi
- if [ -d $INST/osd ]; then
+ if [ "$OSD_SKIP" = false ]; then
_1="-D WITH_OPENSUBDIV=ON"
- _2="-D OPENSUBDIV_ROOT_DIR=$INST/osd"
PRINT " $_1"
- PRINT " $_2"
- _buildargs="$_buildargs $_1 $_2"
+ _buildargs="$_buildargs $_1"
+ if [ -d $INST/osd ]; then
+ _1="-D OPENSUBDIV_ROOT_DIR=$INST/osd"
+ PRINT " $_1"
+ _buildargs="$_buildargs $_1"
+ fi
fi
if [ "$WITH_OPENCOLLADA" = true ]; then
diff --git a/build_files/build_environment/install_deps_patches/llvm.patch b/build_files/build_environment/install_deps_patches/llvm.patch
index 2e05c334569..968f011e57c 100644
--- a/build_files/build_environment/install_deps_patches/llvm.patch
+++ b/build_files/build_environment/install_deps_patches/llvm.patch
@@ -1,12 +1,11 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
-@@ -13,7 +13,7 @@
- set(LLVM_VERSION_MAJOR 3)
- set(LLVM_VERSION_MINOR 1)
+@@ -14,7 +14,7 @@
+ set(LLVM_VERSION_MINOR 4)
--set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}svn")
-+set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}")
+ if (NOT PACKAGE_VERSION)
+- set(PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}svn")
++ set(PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
+ endif()
- set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-
-
+ option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
diff --git a/build_files/buildbot/slave_compile.py b/build_files/buildbot/slave_compile.py
index 0f34551cfc8..4d7793d60c8 100644
--- a/build_files/buildbot/slave_compile.py
+++ b/build_files/buildbot/slave_compile.py
@@ -188,7 +188,7 @@ if 'cmake' in builder:
sys.exit(retcode)
if builder.startswith('linux') and target == 'cuda':
- blender_h = os.path.join(blender_dir, "source", "blender", "blenkernel", "BKE_blender.h")
+ blender_h = os.path.join(blender_dir, "source", "blender", "blenkernel", "BKE_blender_version.h")
blender_version = int(parse_header_file(blender_h, 'BLENDER_VERSION'))
blender_version = "%d.%d" % (blender_version // 100, blender_version % 100)
kernels = os.path.join(target_build_dir, 'intern', 'cycles', 'kernel')
diff --git a/build_files/buildbot/slave_pack.py b/build_files/buildbot/slave_pack.py
index 4deb0b1a081..b27017568cb 100644
--- a/build_files/buildbot/slave_pack.py
+++ b/build_files/buildbot/slave_pack.py
@@ -130,7 +130,7 @@ if builder.find('cmake') != -1:
blenderplayer = os.path.join(install_dir, 'blenderplayer')
buildinfo_h = os.path.join(build_dir, "source", "creator", "buildinfo.h")
- blender_h = os.path.join(blender_dir, "source", "blender", "blenkernel", "BKE_blender.h")
+ blender_h = os.path.join(blender_dir, "source", "blender", "blenkernel", "BKE_blender_version.h")
# Get version information
blender_version = int(parse_header_file(blender_h, 'BLENDER_VERSION'))
diff --git a/build_files/cmake/config/blender_full.cmake b/build_files/cmake/config/blender_full.cmake
index d708f1ccecf..df8ed881d96 100644
--- a/build_files/cmake/config/blender_full.cmake
+++ b/build_files/cmake/config/blender_full.cmake
@@ -69,7 +69,7 @@ elseif(WIN32)
set(WITH_CODEC_SNDFILE OFF CACHE BOOL "" FORCE)
set(WITH_CYCLES_OSL OFF CACHE BOOL "" FORCE)
endif()
-elseif (APPLE)
+elseif(APPLE)
set(WITH_JACK ON CACHE BOOL "" FORCE)
set(WITH_CODEC_QUICKTIME ON CACHE BOOL "" FORCE)
set(WITH_OPENSUBDIV OFF CACHE BOOL "" FORCE)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 85bc4008346..7f19e22c39e 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -968,6 +968,7 @@ macro(remove_strict_flags)
remove_cc_flag(
"-Wstrict-prototypes"
"-Wmissing-prototypes"
+ "-Wmissing-declarations"
"-Wmissing-format-attribute"
"-Wunused-local-typedefs"
"-Wunused-macros"
@@ -1095,10 +1096,10 @@ function(get_blender_version)
# - BLENDER_VERSION_CYCLE (alpha, beta, rc, release)
# So cmake depends on BKE_blender.h, beware of inf-loops!
- CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h
- ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender.h.done)
+ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h
+ ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender_version.h.done)
- file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
+ file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}")
diff --git a/doc/python_api/examples/bpy.props.3.py b/doc/python_api/examples/bpy.props.3.py
index e0b2cf419d2..807edde8f58 100644
--- a/doc/python_api/examples/bpy.props.3.py
+++ b/doc/python_api/examples/bpy.props.3.py
@@ -20,7 +20,7 @@ bpy.types.Scene.my_settings = \
bpy.props.CollectionProperty(type=SceneSettingItem)
# Assume an armature object selected
-print("Adding 3 values!")
+print("Adding 2 values!")
my_item = bpy.context.scene.my_settings.add()
my_item.name = "Spam"
diff --git a/doc/python_api/examples/bpy.props.5.py b/doc/python_api/examples/bpy.props.5.py
index 4e9d61d5385..87741cbab8a 100644
--- a/doc/python_api/examples/bpy.props.5.py
+++ b/doc/python_api/examples/bpy.props.5.py
@@ -48,9 +48,9 @@ bpy.types.Scene.test_array = bpy.props.BoolVectorProperty(size=2, get=get_array,
# Note: the getter/setter callback must use integer identifiers!
test_items = [
("RED", "Red", "", 1),
- ("GREEN", "Red", "", 2),
- ("BLUE", "Red", "", 3),
- ("YELLOW", "Red", "", 4),
+ ("GREEN", "Green", "", 2),
+ ("BLUE", "Blue", "", 3),
+ ("YELLOW", "Yellow", "", 4),
]
diff --git a/doc/python_api/sphinx_doc_gen.sh b/doc/python_api/sphinx_doc_gen.sh
index 697cd5a9b3f..7095808f251 100755
--- a/doc/python_api/sphinx_doc_gen.sh
+++ b/doc/python_api/sphinx_doc_gen.sh
@@ -33,10 +33,10 @@ SSH_UPLOAD="/data/www/vhosts/www.blender.org/api" # blender_python_api_VERSION,
# "_".join(str(v) for v in bpy.app.version)
# custom blender vars
blender_srcdir=$(dirname -- $0)/../..
-blender_version=$(grep "BLENDER_VERSION\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender.h" | awk '{print $3}')
-blender_version_char=$(grep "BLENDER_VERSION_CHAR\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender.h" | awk '{print $3}')
-blender_version_cycle=$(grep "BLENDER_VERSION_CYCLE\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender.h" | awk '{print $3}')
-blender_subversion=$(grep "BLENDER_SUBVERSION\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender.h" | awk '{print $3}')
+blender_version=$(grep "BLENDER_VERSION\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
+blender_version_char=$(grep "BLENDER_VERSION_CHAR\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
+blender_version_cycle=$(grep "BLENDER_VERSION_CYCLE\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
+blender_subversion=$(grep "BLENDER_SUBVERSION\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
if [ "$blender_version_cycle" = "release" ] ; then
BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)$blender_version_char"_release"
diff --git a/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp b/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp
index e49cf30d044..aea8c683732 100644
--- a/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp
+++ b/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp
@@ -51,6 +51,7 @@ namespace {
bottom_out = -displacement.cross(top_out) + rotation_matrix * bottom_in;
}
+/*
void InverseSpatialTransform(const btMatrix3x3 &rotation_matrix,
const btVector3 &displacement,
const btVector3 &top_in,
@@ -80,6 +81,7 @@ namespace {
top_out = a_top.cross(b_top);
bottom_out = a_bottom.cross(b_top) + a_top.cross(b_bottom);
}
+*/
}
diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp b/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp
index 293a393e55e..d96f85ec630 100644
--- a/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp
+++ b/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp
@@ -1127,6 +1127,7 @@ int nattrb=0;
int hasbounds=0;
int result = sscanf(node,"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
result = sscanf(node,"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
+(void)result;
node += nextLine(node);
pos.resize(nnode);
@@ -1208,10 +1209,10 @@ if(ele&&ele[0])
}
}
}
-printf("Nodes: %u\r\n",psb->m_nodes.size());
-printf("Links: %u\r\n",psb->m_links.size());
-printf("Faces: %u\r\n",psb->m_faces.size());
-printf("Tetras: %u\r\n",psb->m_tetras.size());
+printf("Nodes: %d\r\n",psb->m_nodes.size());
+printf("Links: %d\r\n",psb->m_links.size());
+printf("Faces: %d\r\n",psb->m_faces.size());
+printf("Tetras: %d\r\n",psb->m_tetras.size());
return(psb);
}
diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h b/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h
index 759509a1d86..1b9d02d79f9 100644
--- a/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h
+++ b/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h
@@ -422,7 +422,7 @@ static inline btVector3 BaryCoord( const btVector3& a,
}
//
-static btScalar ImplicitSolve( btSoftBody::ImplicitFn* fn,
+static inline btScalar ImplicitSolve( btSoftBody::ImplicitFn* fn,
const btVector3& a,
const btVector3& b,
const btScalar accuracy,
@@ -504,7 +504,7 @@ static inline btScalar VolumeOf( const btVector3& x0,
}
//
-static void EvaluateMedium( const btSoftBodyWorldInfo* wfi,
+static inline void EvaluateMedium( const btSoftBodyWorldInfo* wfi,
const btVector3& x,
btSoftBody::sMedium& medium)
{
diff --git a/extern/carve/lib/geom2d.cpp b/extern/carve/lib/geom2d.cpp
index 3b608238bb2..0e8f3a9377c 100644
--- a/extern/carve/lib/geom2d.cpp
+++ b/extern/carve/lib/geom2d.cpp
@@ -157,6 +157,7 @@ namespace carve {
return pointInPoly(points, p2_adapt_ident(), p);
}
+#if 0
static int lineSegmentPolyIntersections(const P2Vector &points,
LineSegment2 line,
std::vector<PolyIntersectionInfo> &out) {
@@ -224,6 +225,7 @@ namespace carve {
}
return count;
}
+#endif
struct FwdSort {
bool operator()(const PolyIntersectionInfo &a,
@@ -239,6 +241,7 @@ namespace carve {
}
};
+#if 0
static int sortedLineSegmentPolyIntersections(const P2Vector &points,
LineSegment2 line,
std::vector<PolyIntersectionInfo> &out) {
@@ -253,6 +256,7 @@ namespace carve {
}
return count;
}
+#endif
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
index e67ace51c8b..94085034f10 100644
--- a/extern/carve/lib/geom3d.cpp
+++ b/extern/carve/lib/geom3d.cpp
@@ -28,6 +28,7 @@ namespace carve {
namespace geom3d {
namespace {
+#if 0
int is_same(const std::vector<const Vector *> &a,
const std::vector<const Vector *> &b) {
if (a.size() != b.size()) return false;
@@ -52,6 +53,7 @@ not_fwd:
not_rev:
return 0;
}
+#endif
}
bool planeIntersection(const Plane &a, const Plane &b, Ray &r) {
diff --git a/extern/carve/lib/intersect.cpp b/extern/carve/lib/intersect.cpp
index e8e5d329c34..d780e08d224 100644
--- a/extern/carve/lib/intersect.cpp
+++ b/extern/carve/lib/intersect.cpp
@@ -236,6 +236,7 @@ namespace {
+#if 0
void dump_intersections(std::ostream &out, carve::csg::Intersections &csg_intersections) {
std::vector<dump_data> temp;
@@ -284,13 +285,14 @@ namespace {
vertices.push_back(i_pt->v);
}
}
+#endif
carve::point::PointSet points(vertices);
std::string outf("/tmp/intersection-points.ply");
::writePLY(outf, &points, true);
-#endif
}
+#endif
@@ -481,6 +483,7 @@ void carve::csg::CSG::makeVertexIntersections() {
+#if 0
static carve::mesh::MeshSet<3>::vertex_t *chooseWeldPoint(
const carve::csg::detail::VSet &equivalent,
carve::csg::VertexPool &vertex_pool) {
@@ -537,7 +540,7 @@ static const carve::mesh::MeshSet<3>::vertex_t *weld(
}
return weld_point;
}
-
+#endif
void carve::csg::CSG::groupIntersections() {
@@ -1219,6 +1222,7 @@ void carve::csg::CSG::makeFaceEdges(carve::csg::EdgeClassification &eclass,
*
* @param fll
*/
+#if 0
static void checkFaceLoopIntegrity(carve::csg::FaceLoopList &fll) {
static carve::TimingName FUNC_NAME("CSG::checkFaceLoopIntegrity()");
carve::TimingBlock block(FUNC_NAME);
@@ -1245,7 +1249,7 @@ static void checkFaceLoopIntegrity(carve::csg::FaceLoopList &fll) {
}
}
}
-
+#endif
/**
diff --git a/extern/carve/lib/intersect_classify_edge.cpp b/extern/carve/lib/intersect_classify_edge.cpp
index 4f7111a83bd..23cfa21b643 100644
--- a/extern/carve/lib/intersect_classify_edge.cpp
+++ b/extern/carve/lib/intersect_classify_edge.cpp
@@ -139,6 +139,7 @@ namespace carve {
+#if 0
static void walkGraphSegment(carve::csg::detail::VVSMap &shared_edge_graph,
const carve::csg::detail::VSet &branch_points,
V2 initial,
@@ -215,7 +216,7 @@ namespace carve {
#endif
#endif
}
-
+#endif
static carve::geom3d::Vector perpendicular(const carve::geom3d::Vector &v) {
@@ -383,6 +384,7 @@ namespace carve {
+#if 0
static void traceIntersectionGraph(const V2Set &shared_edges,
const FLGroupList & /* a_loops_grouped */,
const FLGroupList & /* b_loops_grouped */,
@@ -416,6 +418,7 @@ namespace carve {
walkGraphSegment(shared_edge_graph, branch_points, V2(v1, v2), a_edge_map, b_edge_map, out);
}
}
+#endif
void hashByPerimeter(FLGroupList &grp, PerimMap &perim_map) {
for (FLGroupList::iterator i = grp.begin(); i != grp.end(); ++i) {
diff --git a/extern/carve/lib/intersect_face_division.cpp b/extern/carve/lib/intersect_face_division.cpp
index 04c8bc5a79f..6554ef500ed 100644
--- a/extern/carve/lib/intersect_face_division.cpp
+++ b/extern/carve/lib/intersect_face_division.cpp
@@ -1409,6 +1409,7 @@ namespace {
return s.str().substr(1);
}
+#if 0
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,
@@ -1450,6 +1451,7 @@ namespace {
}
std::cerr << "};\n";
}
+#endif
void generateOneFaceLoop(carve::mesh::MeshSet<3>::face_t *face,
const carve::csg::detail::Data &data,
diff --git a/extern/carve/lib/math.cpp b/extern/carve/lib/math.cpp
index 9f8d45de9ba..3b7f95193c1 100644
--- a/extern/carve/lib/math.cpp
+++ b/extern/carve/lib/math.cpp
@@ -43,6 +43,7 @@ namespace carve {
};
namespace {
+#if 0
void cplx_sqrt(double re, double im,
double &re_1, double &im_1,
double &re_2, double &im_2) {
@@ -57,7 +58,9 @@ namespace carve {
im_2 = -im_1;
}
}
+#endif
+#if 0
void cplx_cbrt(double re, double im,
double &re_1, double &im_1,
double &re_2, double &im_2,
@@ -76,6 +79,7 @@ namespace carve {
im_3 = r * sin(t + M_TWOPI * 2.0 / 3.0);
}
}
+#endif
void add_root(std::vector<Root> &roots, double root) {
for (size_t i = 0; i < roots.size(); ++i) {
@@ -250,6 +254,7 @@ namespace carve {
e2.normalize();
}
+#if 0
static void eig3(const Matrix3 &m,
double l,
carve::geom::vector<3> &e1,
@@ -259,6 +264,7 @@ namespace carve {
e2.x = 0.0; e2.y = 1.0; e2.z = 0.0;
e3.x = 0.0; e3.y = 0.0; e3.z = 1.0;
}
+#endif
void eigSolveSymmetric(const Matrix3 &m,
double &l1, carve::geom::vector<3> &e1,
diff --git a/extern/carve/lib/mesh.cpp b/extern/carve/lib/mesh.cpp
index 34b04b9ac66..fe66927a707 100644
--- a/extern/carve/lib/mesh.cpp
+++ b/extern/carve/lib/mesh.cpp
@@ -774,7 +774,6 @@ namespace carve {
// 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;
@@ -884,7 +883,6 @@ namespace carve {
// 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;
diff --git a/extern/lzma/LzmaEnc.c b/extern/lzma/LzmaEnc.c
index 9196c43f64b..8c5636fc89e 100644
--- a/extern/lzma/LzmaEnc.c
+++ b/extern/lzma/LzmaEnc.c
@@ -1919,11 +1919,10 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
{
UInt32 beforeSize = kNumOpts;
- Bool btMode;
if (!RangeEnc_Alloc(&p->rc, alloc))
return SZ_ERROR_MEM;
- btMode = (p->matchFinderBase.btMode != 0);
#ifdef COMPRESS_MF_MT
+ Bool btMode = (p->matchFinderBase.btMode != 0);;
p->mtMode = (p->multiThread && !p->fastMode && btMode);
#endif
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 1f0aa5eef34..55ef913408f 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -657,7 +657,7 @@ static void create_mesh(Scene *scene,
static void create_subd_mesh(Scene *scene,
Mesh *mesh,
- BL::Object b_ob,
+ BL::Object& b_ob,
BL::Mesh& b_mesh,
PointerRNA *cmesh,
const vector<uint>& used_shaders,
@@ -976,7 +976,12 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
memcmp(mP, &mesh->verts[0], sizeof(float3)*numverts) == 0)
{
/* no motion, remove attributes again */
- VLOG(1) << "No actual deformation motion for object " << b_ob.name();
+ if(b_mesh.vertices.length() != numverts) {
+ VLOG(1) << "Topology differs, disabling motion blur.";
+ }
+ else {
+ VLOG(1) << "No actual deformation motion for object " << b_ob.name();
+ }
mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
if(attr_mN)
mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_NORMAL);
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index 9e63485c04e..5c474c8c3e9 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -327,6 +327,9 @@ void BVH::pack_instances(size_t nodes_size, size_t leaf_nodes_size)
data.x += prim_offset;
data.y += prim_offset;
pack_leaf_nodes[pack_leaf_nodes_offset] = data;
+ for(int j = 1; j < nsize_leaf; ++j) {
+ pack_leaf_nodes[pack_leaf_nodes_offset + j] = leaf_nodes_offset[i + j];
+ }
pack_leaf_nodes_offset += nsize_leaf;
}
}
diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index a0b09c780ce..bba89a8f35c 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -617,7 +617,7 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
BoundBox::empty,
BoundBox::empty};
int ob_num = 0;
-
+ int num_new_prims = 0;
/* Fill in per-type type/index array. */
for(int i = 0; i < range.size(); i++) {
const BVHReference& ref = references[range.start() + i];
@@ -629,10 +629,11 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
bounds[type_index].grow(ref.bounds());
visibility[type_index] |= objects[ref.prim_object()]->visibility;
+ ++num_new_prims;
}
else {
object_references.push_back(ref);
- ob_num++;
+ ++ob_num;
}
}
@@ -651,11 +652,11 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
vector<int, LeafStackAllocator> local_prim_type,
local_prim_index,
local_prim_object;
+ local_prim_type.resize(num_new_prims);
+ local_prim_index.resize(num_new_prims);
+ local_prim_object.resize(num_new_prims);
for(int i = 0; i < PRIMITIVE_NUM_TOTAL; ++i) {
int num = (int)p_type[i].size();
- local_prim_type.resize(start_index + num);
- local_prim_index.resize(start_index + num);
- local_prim_object.resize(start_index + num);
if(num != 0) {
assert(p_type[i].size() == p_index[i].size());
assert(p_type[i].size() == p_object[i].size());
diff --git a/intern/cycles/bvh/bvh_split.cpp b/intern/cycles/bvh/bvh_split.cpp
index 9185bd99d10..8084975565e 100644
--- a/intern/cycles/bvh/bvh_split.cpp
+++ b/intern/cycles/bvh/bvh_split.cpp
@@ -44,6 +44,8 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
const BVHReference *ref_ptr = &references_->at(range.start());
float min_sah = FLT_MAX;
+ storage_->right_bounds.resize(range.size());
+
for(int dim = 0; dim < 3; dim++) {
/* Sort references. */
bvh_reference_sort(range.start(),
@@ -53,8 +55,6 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
/* sweep right to left and determine bounds. */
BoundBox right_bounds = BoundBox::empty;
-
- storage_->right_bounds.resize(range.size());
for(int i = range.size() - 1; i > 0; i--) {
right_bounds.grow(ref_ptr[i].bounds());
storage_->right_bounds[i - 1] = right_bounds;
@@ -157,11 +157,10 @@ BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
}
/* select best split plane. */
+ storage_->right_bounds.resize(BVHParams::NUM_SPATIAL_BINS);
for(int dim = 0; dim < 3; dim++) {
/* sweep right to left and determine bounds. */
BoundBox right_bounds = BoundBox::empty;
-
- storage_->right_bounds.resize(BVHParams::NUM_SPATIAL_BINS);
for(int i = BVHParams::NUM_SPATIAL_BINS - 1; i > 0; i--) {
right_bounds.grow(storage_->bins[dim][i].bounds);
storage_->right_bounds[i - 1] = right_bounds;
diff --git a/intern/cycles/kernel/kernel_bake.h b/intern/cycles/kernel/kernel_bake.h
index 8e7a2c1b62b..d0ca256f323 100644
--- a/intern/cycles/kernel/kernel_bake.h
+++ b/intern/cycles/kernel/kernel_bake.h
@@ -303,7 +303,7 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
/* dummy initilizations copied from SHADER_EVAL_DISPLACE */
float3 I = Ng;
- float t = 0.0f;
+ float t = 1.0f;
float time = TIME_INVALID;
/* light passes */
diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 1637045ce84..fef28b25f3e 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -771,11 +771,11 @@ void LightManager::device_update_points(Device *device,
void LightManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
{
- VLOG(1) << "Total " << scene->lights.size() << " lights.";
-
if(!need_update)
return;
+ VLOG(1) << "Total " << scene->lights.size() << " lights.";
+
device_free(device, dscene);
use_light_visibility = false;
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 241a1c44ebf..cc8519219ed 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -528,7 +528,7 @@ void Mesh::compute_bvh(SceneParams *params, Progress *progress, int n, int total
delete bvh;
bvh = BVH::create(bparams, objects);
- bvh->build(*progress);
+ MEM_GUARDED_CALL(progress, bvh->build, *progress);
}
}
@@ -1232,11 +1232,11 @@ void MeshManager::device_update_displacement_images(Device *device,
void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
{
- VLOG(1) << "Total " << scene->meshes.size() << " meshes.";
-
if(!need_update)
return;
+ VLOG(1) << "Total " << scene->meshes.size() << " meshes.";
+
/* update normals */
foreach(Mesh *mesh, scene->meshes) {
foreach(uint shader, mesh->used_shaders) {
diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp
index 42bb665cb9f..a7ea75820ea 100644
--- a/intern/cycles/render/object.cpp
+++ b/intern/cycles/render/object.cpp
@@ -231,160 +231,260 @@ ObjectManager::~ObjectManager()
{
}
-void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene, Scene *scene, uint *object_flag, Progress& progress)
+void ObjectManager::device_update_object_transform(UpdateObejctTransformState *state,
+ Object *ob,
+ int object_index)
{
- float4 *objects;
- float4 *objects_vector = NULL;
- int i = 0;
- map<Mesh*, float> surface_area_map;
- map<ParticleSystem*, int> particle_offset;
- Scene::MotionType need_motion = scene->need_motion(device->info.advanced_shading);
- bool have_motion = false;
- bool have_curves = false;
-
- objects = dscene->objects.resize(OBJECT_SIZE*scene->objects.size());
- if(need_motion == Scene::MOTION_PASS)
- objects_vector = dscene->objects_vector.resize(OBJECT_VECTOR_SIZE*scene->objects.size());
-
- /* particle system device offsets
- * 0 is dummy particle, index starts at 1
+ float4 *objects = state->objects;
+ float4 *objects_vector = state->objects_vector;
+
+ Mesh *mesh = ob->mesh;
+ uint flag = 0;
+
+ /* Compute transformations. */
+ Transform tfm = ob->tfm;
+ Transform itfm = transform_inverse(tfm);
+
+ /* Compute surface area. for uniform scale we can do avoid the many
+ * transform calls and share computation for instances.
+ *
+ * TODO(brecht): Correct for displacement, and move to a better place.
*/
- int numparticles = 1;
- foreach(ParticleSystem *psys, scene->particle_systems) {
- particle_offset[psys] = numparticles;
- numparticles += psys->particles.size();
- }
+ float uniform_scale;
+ float surface_area = 0.0f;
+ float pass_id = ob->pass_id;
+ float random_number = (float)ob->random_id * (1.0f/(float)0xFFFFFFFF);
+ int particle_index = (ob->particle_system)
+ ? ob->particle_index + state->particle_offset[ob->particle_system]
+ : 0;
+
+ if(transform_uniform_scale(tfm, uniform_scale)) {
+ map<Mesh*, float>::iterator it;
+
+ /* NOTE: This isn't fully optimal and could in theory lead to multiple
+ * threads calculating area of the same mesh in parallel. However, this
+ * also prevents suspending all the threads when some mesh's area is
+ * not yet known.
+ */
+ state->surface_area_lock.lock();
+ it = state->surface_area_map.find(mesh);
+ state->surface_area_lock.unlock();
- foreach(Object *ob, scene->objects) {
- Mesh *mesh = ob->mesh;
- uint flag = 0;
-
- /* compute transformations */
- Transform tfm = ob->tfm;
- Transform itfm = transform_inverse(tfm);
-
- /* compute surface area. for uniform scale we can do avoid the many
- * transform calls and share computation for instances */
- /* todo: correct for displacement, and move to a better place */
- float uniform_scale;
- float surface_area = 0.0f;
- float pass_id = ob->pass_id;
- float random_number = (float)ob->random_id * (1.0f/(float)0xFFFFFFFF);
- int particle_index = (ob->particle_system)? ob->particle_index + particle_offset[ob->particle_system]: 0;
-
- if(transform_uniform_scale(tfm, uniform_scale)) {
- map<Mesh*, float>::iterator it = surface_area_map.find(mesh);
-
- if(it == surface_area_map.end()) {
- foreach(Mesh::Triangle& t, mesh->triangles) {
- float3 p1 = mesh->verts[t.v[0]];
- float3 p2 = mesh->verts[t.v[1]];
- float3 p3 = mesh->verts[t.v[2]];
-
- surface_area += triangle_area(p1, p2, p3);
- }
+ if(it == state->surface_area_map.end()) {
+ foreach(Mesh::Triangle& t, mesh->triangles) {
+ float3 p1 = mesh->verts[t.v[0]];
+ float3 p2 = mesh->verts[t.v[1]];
+ float3 p3 = mesh->verts[t.v[2]];
- surface_area_map[mesh] = surface_area;
+ surface_area += triangle_area(p1, p2, p3);
}
- else
- surface_area = it->second;
- surface_area *= uniform_scale;
+ state->surface_area_lock.lock();
+ state->surface_area_map[mesh] = surface_area;
+ state->surface_area_lock.unlock();
}
else {
- foreach(Mesh::Triangle& t, mesh->triangles) {
- float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]);
- float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]);
- float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]);
+ surface_area = it->second;
+ }
- surface_area += triangle_area(p1, p2, p3);
- }
+ surface_area *= uniform_scale;
+ }
+ else {
+ foreach(Mesh::Triangle& t, mesh->triangles) {
+ float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]);
+ float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]);
+ float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]);
+
+ surface_area += triangle_area(p1, p2, p3);
}
+ }
- /* pack in texture */
- int offset = i*OBJECT_SIZE;
-
- /* OBJECT_TRANSFORM */
- memcpy(&objects[offset], &tfm, sizeof(float4)*3);
- /* OBJECT_INVERSE_TRANSFORM */
- memcpy(&objects[offset+4], &itfm, sizeof(float4)*3);
- /* OBJECT_PROPERTIES */
- objects[offset+8] = make_float4(surface_area, pass_id, random_number, __int_as_float(particle_index));
-
- if(need_motion == Scene::MOTION_PASS) {
- /* motion transformations, is world/object space depending if mesh
- * comes with deformed position in object space, or if we transform
- * the shading point in world space */
- Transform mtfm_pre = ob->motion.pre;
- Transform mtfm_post = ob->motion.post;
-
- if(!mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)) {
- mtfm_pre = mtfm_pre * itfm;
- mtfm_post = mtfm_post * itfm;
- }
- else {
- flag |= SD_OBJECT_HAS_VERTEX_MOTION;
- }
+ /* Pack in texture. */
+ int offset = object_index*OBJECT_SIZE;
- memcpy(&objects_vector[i*OBJECT_VECTOR_SIZE+0], &mtfm_pre, sizeof(float4)*3);
- memcpy(&objects_vector[i*OBJECT_VECTOR_SIZE+3], &mtfm_post, sizeof(float4)*3);
+ /* OBJECT_TRANSFORM */
+ memcpy(&objects[offset], &tfm, sizeof(float4)*3);
+ /* OBJECT_INVERSE_TRANSFORM */
+ memcpy(&objects[offset+4], &itfm, sizeof(float4)*3);
+ /* OBJECT_PROPERTIES */
+ objects[offset+8] = make_float4(surface_area, pass_id, random_number, __int_as_float(particle_index));
+
+ if(state->need_motion == Scene::MOTION_PASS) {
+ /* Motion transformations, is world/object space depending if mesh
+ * comes with deformed position in object space, or if we transform
+ * the shading point in world space.
+ */
+ Transform mtfm_pre = ob->motion.pre;
+ Transform mtfm_post = ob->motion.post;
+
+ if(!mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)) {
+ mtfm_pre = mtfm_pre * itfm;
+ mtfm_post = mtfm_post * itfm;
+ }
+ else {
+ flag |= SD_OBJECT_HAS_VERTEX_MOTION;
}
+
+ memcpy(&objects_vector[object_index*OBJECT_VECTOR_SIZE+0], &mtfm_pre, sizeof(float4)*3);
+ memcpy(&objects_vector[object_index*OBJECT_VECTOR_SIZE+3], &mtfm_post, sizeof(float4)*3);
+ }
#ifdef __OBJECT_MOTION__
- else if(need_motion == Scene::MOTION_BLUR) {
- if(ob->use_motion) {
- /* decompose transformations for interpolation */
- DecompMotionTransform decomp;
-
- transform_motion_decompose(&decomp, &ob->motion, &ob->tfm);
- memcpy(&objects[offset], &decomp, sizeof(float4)*8);
- flag |= SD_OBJECT_MOTION;
- have_motion = true;
- }
+ else if(state->need_motion == Scene::MOTION_BLUR) {
+ if(ob->use_motion) {
+ /* decompose transformations for interpolation. */
+ DecompMotionTransform decomp;
+
+ transform_motion_decompose(&decomp, &ob->motion, &ob->tfm);
+ memcpy(&objects[offset], &decomp, sizeof(float4)*8);
+ flag |= SD_OBJECT_MOTION;
+ state->have_motion = true;
}
+ }
#endif
- if(mesh->use_motion_blur)
- have_motion = true;
+ if(mesh->use_motion_blur) {
+ state->have_motion = true;
+ }
- /* dupli object coords and motion info */
- int totalsteps = mesh->motion_steps;
- int numsteps = (totalsteps - 1)/2;
- int numverts = mesh->verts.size();
- int numkeys = mesh->curve_keys.size();
+ /* Dupli object coords and motion info. */
+ int totalsteps = mesh->motion_steps;
+ int numsteps = (totalsteps - 1)/2;
+ int numverts = mesh->verts.size();
+ int numkeys = mesh->curve_keys.size();
- objects[offset+9] = make_float4(ob->dupli_generated[0], ob->dupli_generated[1], ob->dupli_generated[2], __int_as_float(numkeys));
- objects[offset+10] = make_float4(ob->dupli_uv[0], ob->dupli_uv[1], __int_as_float(numsteps), __int_as_float(numverts));
+ objects[offset+9] = make_float4(ob->dupli_generated[0], ob->dupli_generated[1], ob->dupli_generated[2], __int_as_float(numkeys));
+ objects[offset+10] = make_float4(ob->dupli_uv[0], ob->dupli_uv[1], __int_as_float(numsteps), __int_as_float(numverts));
- /* object flag */
- if(ob->use_holdout)
- flag |= SD_HOLDOUT_MASK;
- object_flag[i] = flag;
+ /* Object flag. */
+ if(ob->use_holdout) {
+ flag |= SD_HOLDOUT_MASK;
+ }
+ state->object_flag[object_index] = flag;
- /* have curves */
- if(mesh->curves.size())
- have_curves = true;
+ /* Have curves. */
+ if(mesh->curves.size()) {
+ state->have_curves = true;
+ }
+}
- i++;
+bool ObjectManager::device_update_object_transform_pop_work(
+ UpdateObejctTransformState *state,
+ int *start_index,
+ int *num_objects)
+{
+ /* Tweakable parameter, number of objects per chunk.
+ * Too small value will cause some extra overhead due to spin lock,
+ * too big value might not use all threads nicely.
+ */
+ static const int OBJECTS_PER_TASK = 32;
+ bool have_work = false;
+ state->queue_lock.lock();
+ int num_scene_objects = state->scene->objects.size();
+ if(state->queue_start_object < num_scene_objects) {
+ int count = min(OBJECTS_PER_TASK,
+ num_scene_objects - state->queue_start_object);
+ *start_index = state->queue_start_object;
+ *num_objects = count;
+ state->queue_start_object += count;
+ have_work = true;
+ }
+ state->queue_lock.unlock();
+ return have_work;
+}
+
+void ObjectManager::device_update_object_transform_task(
+ UpdateObejctTransformState *state)
+{
+ int start_index, num_objects;
+ while(device_update_object_transform_pop_work(state,
+ &start_index,
+ &num_objects))
+ {
+ for(int i = 0; i < num_objects; ++i) {
+ const int object_index = start_index + i;
+ Object *ob = state->scene->objects[object_index];
+ device_update_object_transform(state, ob, object_index);
+ }
+ }
+}
- if(progress.get_cancel()) return;
+void ObjectManager::device_update_transforms(Device *device,
+ DeviceScene *dscene,
+ Scene *scene,
+ uint *object_flag,
+ Progress& progress)
+{
+ UpdateObejctTransformState state;
+ state.need_motion = scene->need_motion(device->info.advanced_shading);
+ state.have_motion = false;
+ state.have_curves = false;
+ state.scene = scene;
+ state.queue_start_object = 0;
+
+ state.object_flag = object_flag;
+ state.objects = dscene->objects.resize(OBJECT_SIZE*scene->objects.size());
+ if(state.need_motion == Scene::MOTION_PASS) {
+ state.objects_vector = dscene->objects_vector.resize(OBJECT_VECTOR_SIZE*scene->objects.size());
+ }
+ else {
+ state.objects_vector = NULL;
+ }
+
+ /* Particle system device offsets
+ * 0 is dummy particle, index starts at 1.
+ */
+ int numparticles = 1;
+ foreach(ParticleSystem *psys, scene->particle_systems) {
+ state.particle_offset[psys] = numparticles;
+ numparticles += psys->particles.size();
+ }
+
+ /* NOTE: If it's just a handful of objects we deal with them in a single
+ * thread to avoid threading overhead. However, this threshold is might
+ * need some tweaks to make mid-complex scenes optimal.
+ */
+ if(scene->objects.size() < 64) {
+ int object_index = 0;
+ foreach(Object *ob, scene->objects) {
+ device_update_object_transform(&state, ob, object_index);
+ object_index++;
+ if(progress.get_cancel()) {
+ return;
+ }
+ }
+ }
+ else {
+ const int num_threads = TaskScheduler::num_threads();
+ TaskPool pool;
+ for(int i = 0; i < num_threads; ++i) {
+ pool.push(function_bind(
+ &ObjectManager::device_update_object_transform_task,
+ this,
+ &state));
+ }
+ pool.wait_work();
+ if(progress.get_cancel()) {
+ return;
+ }
}
device->tex_alloc("__objects", dscene->objects);
- if(need_motion == Scene::MOTION_PASS)
+ if(state.need_motion == Scene::MOTION_PASS) {
device->tex_alloc("__objects_vector", dscene->objects_vector);
+ }
- dscene->data.bvh.have_motion = have_motion;
- dscene->data.bvh.have_curves = have_curves;
+ dscene->data.bvh.have_motion = state.have_motion;
+ dscene->data.bvh.have_curves = state.have_curves;
dscene->data.bvh.have_instancing = true;
}
void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
{
- VLOG(1) << "Total " << scene->objects.size() << " objects.";
-
if(!need_update)
return;
-
+
+ VLOG(1) << "Total " << scene->objects.size() << " objects.";
+
device_free(device, dscene);
if(scene->objects.size() == 0)
diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h
index 379d1748cdd..c2a79ca8dc4 100644
--- a/intern/cycles/render/object.h
+++ b/intern/cycles/render/object.h
@@ -17,9 +17,12 @@
#ifndef __OBJECT_H__
#define __OBJECT_H__
+#include "scene.h"
+
#include "util_boundbox.h"
#include "util_param.h"
#include "util_transform.h"
+#include "util_thread.h"
#include "util_types.h"
CCL_NAMESPACE_BEGIN
@@ -76,7 +79,12 @@ public:
~ObjectManager();
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
- void device_update_transforms(Device *device, DeviceScene *dscene, Scene *scene, uint *object_flag, Progress& progress);
+ void device_update_transforms(Device *device,
+ DeviceScene *dscene,
+ Scene *scene,
+ uint *object_flag,
+ Progress& progress);
+
void device_update_flags(Device *device,
DeviceScene *dscene,
Scene *scene,
@@ -87,6 +95,56 @@ public:
void tag_update(Scene *scene);
void apply_static_transforms(DeviceScene *dscene, Scene *scene, uint *object_flag, Progress& progress);
+
+protected:
+ /* Global state of object transform update. */
+ struct UpdateObejctTransformState {
+ /* Global state used by device_update_object_transform().
+ * Common for both threaded and non-threaded update.
+ */
+
+ /* Type of the motion required by the scene settings. */
+ Scene::MotionType need_motion;
+
+ /* Mapping from particle system to a index in packed particle array.
+ * Only used for read.
+ */
+ map<ParticleSystem*, int> particle_offset;
+
+ /* Mesh area.
+ * Used to avoid calculation of mesh area multiple times. Used for both
+ * read and write. Acquire surface_area_lock to keep it all thread safe.
+ */
+ map<Mesh*, float> surface_area_map;
+
+ /* Packed object arrays. Those will be filled in. */
+ uint *object_flag;
+ float4 *objects;
+ float4 *objects_vector;
+
+ /* Flags which will be synchronized to Integrator. */
+ bool have_motion;
+ bool have_curves;
+
+ /* ** Scheduling queue. ** */
+
+ Scene *scene;
+
+ /* Some locks to keep everything thread-safe. */
+ thread_spin_lock queue_lock;
+ thread_spin_lock surface_area_lock;
+
+ /* First unused object index in the queue. */
+ int queue_start_object;
+ };
+ void device_update_object_transform(UpdateObejctTransformState *state,
+ Object *ob,
+ const int object_index);
+ void device_update_object_transform_task(UpdateObejctTransformState *state);
+ bool device_update_object_transform_pop_work(
+ UpdateObejctTransformState *state,
+ int *start_index,
+ int *num_objects);
};
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp
index e1c5416b024..cb3cb8b9b1b 100644
--- a/intern/cycles/render/osl.cpp
+++ b/intern/cycles/render/osl.cpp
@@ -75,11 +75,11 @@ void OSLShaderManager::reset(Scene * /*scene*/)
void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
{
- VLOG(1) << "Total " << scene->shaders.size() << " shaders.";
-
if(!need_update)
return;
+ VLOG(1) << "Total " << scene->shaders.size() << " shaders.";
+
device_free(device, dscene, scene);
/* determine which shaders are in use */
diff --git a/intern/cycles/render/particles.cpp b/intern/cycles/render/particles.cpp
index 8f9e8c6d639..50726bb4574 100644
--- a/intern/cycles/render/particles.cpp
+++ b/intern/cycles/render/particles.cpp
@@ -93,12 +93,12 @@ void ParticleSystemManager::device_update_particles(Device *device, DeviceScene
void ParticleSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
{
+ if(!need_update)
+ return;
+
VLOG(1) << "Total " << scene->particle_systems.size()
<< " particle systems.";
- if(!need_update)
- return;
-
device_free(device, dscene);
progress.set_status("Updating Particle Systems", "Copying Particles to device");
diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp
index 29163c53109..b0052c30af4 100644
--- a/intern/cycles/render/scene.cpp
+++ b/intern/cycles/render/scene.cpp
@@ -135,7 +135,9 @@ void Scene::device_update(Device *device_, Progress& progress)
{
if(!device)
device = device_;
-
+
+ bool print_stats = need_data_update();
+
/* The order of updates is important, because there's dependencies between
* the different managers, using data computed by previous managers.
*
@@ -239,9 +241,11 @@ void Scene::device_update(Device *device_, Progress& progress)
device->const_copy_to("__data", &dscene.data, sizeof(dscene.data));
}
- VLOG(1) << "System memory statistics after full device sync:\n"
- << " Usage: " << util_guarded_get_mem_used() << "\n"
- << " Peak: " << util_guarded_get_mem_peak();
+ if(print_stats) {
+ VLOG(1) << "System memory statistics after full device sync:\n"
+ << " Usage: " << util_guarded_get_mem_used() << "\n"
+ << " Peak: " << util_guarded_get_mem_peak();
+ }
}
Scene::MotionType Scene::need_motion(bool advanced_shading)
@@ -278,11 +282,10 @@ bool Scene::need_update()
return (need_reset() || film->need_update);
}
-bool Scene::need_reset()
+bool Scene::need_data_update()
{
return (background->need_update
|| image_manager->need_update
- || camera->need_update
|| object_manager->need_update
|| mesh_manager->need_update
|| light_manager->need_update
@@ -295,6 +298,11 @@ bool Scene::need_reset()
|| film->need_update);
}
+bool Scene::need_reset()
+{
+ return need_data_update() || camera->need_update;
+}
+
void Scene::reset()
{
shader_manager->reset(this);
diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h
index d30a0cb45fe..b29aff88c01 100644
--- a/intern/cycles/render/scene.h
+++ b/intern/cycles/render/scene.h
@@ -213,6 +213,11 @@ public:
void device_free();
protected:
+ /* Check if some heavy data worth logging was updated.
+ * Mainly used to suppress extra annoying logging.
+ */
+ bool need_data_update();
+
void free_memory(bool final);
};
diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp
index 24f48b61349..63037311889 100644
--- a/intern/cycles/render/session.cpp
+++ b/intern/cycles/render/session.cpp
@@ -816,7 +816,7 @@ void Session::update_scene()
/* update scene */
if(scene->need_update()) {
progress.set_status("Updating Scene");
- scene->device_update(device, progress);
+ MEM_GUARDED_CALL(&progress, scene->device_update, device, progress);
}
}
diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp
index f3d39c1bd72..56fb57e9667 100644
--- a/intern/cycles/render/svm.cpp
+++ b/intern/cycles/render/svm.cpp
@@ -46,11 +46,11 @@ void SVMShaderManager::reset(Scene * /*scene*/)
void SVMShaderManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
{
- VLOG(1) << "Total " << scene->shaders.size() << " shaders.";
-
if(!need_update)
return;
+ VLOG(1) << "Total " << scene->shaders.size() << " shaders.";
+
/* test if we need to update */
device_free(device, dscene, scene);
diff --git a/intern/cycles/render/tables.cpp b/intern/cycles/render/tables.cpp
index ad3f4866072..cde024cc11c 100644
--- a/intern/cycles/render/tables.cpp
+++ b/intern/cycles/render/tables.cpp
@@ -37,11 +37,11 @@ LookupTables::~LookupTables()
void LookupTables::device_update(Device *device, DeviceScene *dscene)
{
- VLOG(1) << "Total " << lookup_tables.size() << " lookup tables.";
-
if(!need_update)
return;
+ VLOG(1) << "Total " << lookup_tables.size() << " lookup tables.";
+
device->tex_free(dscene->lookup_table);
if(lookup_tables.size() > 0)
diff --git a/intern/cycles/util/util_guarded_allocator.h b/intern/cycles/util/util_guarded_allocator.h
index f6004749a13..78453d214be 100644
--- a/intern/cycles/util/util_guarded_allocator.h
+++ b/intern/cycles/util/util_guarded_allocator.h
@@ -53,19 +53,24 @@ public:
size_t size = n * sizeof(T);
util_guarded_mem_alloc(size);
(void)hint;
-#ifdef WITH_BLENDER_GUARDEDALLOC
if(n == 0) {
return NULL;
}
+ T *mem;
+#ifdef WITH_BLENDER_GUARDEDALLOC
/* C++ standard requires allocation functions to allocate memory suitably
* aligned for any standard type. This is 16 bytes for 64 bit platform as
* far as i concerned. We might over-align on 32bit here, but that should
* be all safe actually.
*/
- return (T*)MEM_mallocN_aligned(size, 16, "Cycles Alloc");
+ mem = (T*)MEM_mallocN_aligned(size, 16, "Cycles Alloc");
#else
- return (T*)malloc(size);
+ mem = (T*)malloc(size);
#endif
+ if(mem == NULL) {
+ throw std::bad_alloc();
+ }
+ return mem;
}
void deallocate(T *p, size_t n)
@@ -97,7 +102,9 @@ public:
void construct(T *p, const T& val)
{
- new ((T *)p) T(val);
+ if(p != NULL) {
+ new ((T *)p) T(val);
+ }
}
void destroy(T *p)
@@ -157,6 +164,26 @@ public:
size_t util_guarded_get_mem_used(void);
size_t util_guarded_get_mem_peak(void);
+/* Call given function and keep track if it runs out of memory.
+ *
+ * If it does run out f memory, stop execution and set progress
+ * to do a global cancel.
+ *
+ * It's not fully robust, but good enough to catch obvious issues
+ * when running out of memory.
+ */
+#define MEM_GUARDED_CALL(progress, func, ...) \
+ do { \
+ try { \
+ (func)(__VA_ARGS__); \
+ } \
+ catch (std::bad_alloc&) { \
+ fprintf(stderr, "Error: run out of memory!\n"); \
+ fflush(stderr); \
+ (progress)->set_error("Out of memory"); \
+ } \
+ } while(false)
+
CCL_NAMESPACE_END
#endif /* __UTIL_GUARDED_ALLOCATOR_H__ */
diff --git a/intern/cycles/util/util_stack_allocator.h b/intern/cycles/util/util_stack_allocator.h
index 29260888eef..d7aab5b250c 100644
--- a/intern/cycles/util/util_stack_allocator.h
+++ b/intern/cycles/util/util_stack_allocator.h
@@ -40,14 +40,17 @@ public:
/* Allocator construction/destruction. */
StackAllocator()
- : pointer_(0) {}
+ : pointer_(0),
+ use_stack_(true) {}
StackAllocator(const StackAllocator&)
- : pointer_(0) {}
+ : pointer_(0),
+ use_stack_(true) {}
template <class U>
StackAllocator(const StackAllocator<SIZE, U>&)
- : pointer_(0) {}
+ : pointer_(0),
+ use_stack_(false) {}
/* Memory allocation/deallocation. */
@@ -57,14 +60,19 @@ public:
if(n == 0) {
return NULL;
}
- if(pointer_ + n >= SIZE) {
+ if(pointer_ + n >= SIZE || use_stack_ == false) {
size_t size = n * sizeof(T);
util_guarded_mem_alloc(size);
+ T *mem;
#ifdef WITH_BLENDER_GUARDEDALLOC
- return (T*)MEM_mallocN_aligned(size, 16, "Cycles Alloc");
+ mem = (T*)MEM_mallocN_aligned(size, 16, "Cycles Alloc");
#else
- return (T*)malloc(size);
+ mem = (T*)malloc(size);
#endif
+ if(mem == NULL) {
+ throw std::bad_alloc();
+ }
+ return mem;
}
T *mem = &data_[pointer_];
pointer_ += n;
@@ -104,7 +112,9 @@ public:
void construct(T *p, const T& val)
{
- new ((T *)p) T(val);
+ if(p != NULL) {
+ new ((T *)p) T(val);
+ }
}
void destroy(T *p)
@@ -151,6 +161,7 @@ public:
private:
int pointer_;
+ bool use_stack_;
T data_[SIZE];
};
diff --git a/intern/cycles/util/util_vector.h b/intern/cycles/util/util_vector.h
index 4eb0dde8308..ad579da2d2e 100644
--- a/intern/cycles/util/util_vector.h
+++ b/intern/cycles/util/util_vector.h
@@ -218,10 +218,16 @@ public:
protected:
inline T* mem_allocate(size_t N)
{
+ if(N == 0) {
+ return NULL;
+ }
T *mem = (T*)util_aligned_malloc(sizeof(T)*N, alignment);
if(mem != NULL) {
util_guarded_mem_alloc(sizeof(T)*N);
}
+ else {
+ throw std::bad_alloc();
+ }
return mem;
}
diff --git a/intern/elbeem/intern/loop_tools.h b/intern/elbeem/intern/loop_tools.h
index f06fa7c2861..661519b0375 100644
--- a/intern/elbeem/intern/loop_tools.h
+++ b/intern/elbeem/intern/loop_tools.h
@@ -22,6 +22,9 @@
int calcCellsFilled=0; \
int calcCellsEmptied=0; \
int calcNumUsedCells=0; \
+ /* This is a generic macro, and now all it's users are using all variables. */ \
+ (void)calcCurrentMass; \
+ (void)calcCellsFilled \
diff --git a/intern/elbeem/intern/ntl_ray.cpp b/intern/elbeem/intern/ntl_ray.cpp
index 1083fcdb68b..618017ae81d 100644
--- a/intern/elbeem/intern/ntl_ray.cpp
+++ b/intern/elbeem/intern/ntl_ray.cpp
@@ -299,7 +299,7 @@ void ntlRay::intersectBackAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &t, n
//! intersect ray with AABB
void ntlRay::intersectCompleteAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &tmin, gfxReal &tmax) const
{
- char inside = true; /* inside box? */
+ // char inside = true; /* inside box? */ /* UNUSED */
char hit = false; /* ray hits box? */
int whichPlane; /* intersection plane */
gfxReal candPlane[NUMDIM]; /* candidate plane */
@@ -315,11 +315,11 @@ void ntlRay::intersectCompleteAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &
if(origin[i] < mStart[i]) {
quadrant[i] = LEFT;
candPlane [i] = mStart[i];
- inside = false;
+ // inside = false;
} else if(origin[i] > mEnd[i]) {
quadrant[i] = RIGHT;
candPlane[i] = mEnd[i];
- inside = false;
+ // inside = false;
} else {
/* intersect with backside */
if(dir[i] > 0) {
diff --git a/intern/elbeem/intern/solver_init.cpp b/intern/elbeem/intern/solver_init.cpp
index 31372f12282..8b962d604cf 100644
--- a/intern/elbeem/intern/solver_init.cpp
+++ b/intern/elbeem/intern/solver_init.cpp
@@ -685,6 +685,8 @@ bool LbmFsgrSolver::initializeSolverMemory()
if(firstMInit) {
mrSetup();
}
+#else
+ (void)firstMInit;
#endif // LBM_INCLUDE_TESTSOLVERS==1
firstMInit=false;
@@ -1351,13 +1353,13 @@ bool LbmFsgrSolver::initializeSolverPostinit() {
} } \
if(ntype&(CFBndFreeslip)) { \
const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); \
- const LbmVec oldov=objvel; /*DEBUG*/ \
+ /* const LbmVec oldov=objvel; */ /*DEBUG*/ \
objvel = vec2L((*pNormals)[n]) *dp; \
/* if((j==24)&&(n%5==2)) errMsg("FSBT","n"<<n<<" v"<<objvel<<" nn"<<(*pNormals)[n]<<" dp"<<dp<<" oldov"<<oldov ); */ \
} \
else if(ntype&(CFBndPartslip)) { \
const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); \
- const LbmVec oldov=objvel; /*DEBUG*/ \
+ /* const LbmVec oldov=objvel; */ /*DEBUG*/ \
/* if((j==24)&&(n%5==2)) errMsg("FSBT","n"<<n<<" v"<<objvel<<" nn"<<(*pNormals)[n]<<" dp"<<dp<<" oldov"<<oldov ); */ \
const LbmFloat partv = mObjectPartslips[OId]; \
/*errMsg("PARTSLIP_DEBUG","l="<<l<<" ccel="<<RAC(ccel, dfInv[l] )<<" partv="<<partv<<",id="<<(int)(mnbf>>24)<<" newval="<<newval ); / part slip debug */ \
diff --git a/intern/elbeem/intern/solver_main.cpp b/intern/elbeem/intern/solver_main.cpp
index 46af6740cf1..55a8d3eb4aa 100644
--- a/intern/elbeem/intern/solver_main.cpp
+++ b/intern/elbeem/intern/solver_main.cpp
@@ -777,6 +777,8 @@ LbmFsgrSolver::mainLoop(int lev)
+ RAC(ccel,dET) - RAC(ccel,dEB)
+ RAC(ccel,dWT) - RAC(ccel,dWB);
+ (void)oldRho;
+
// now reconstruction
ux=oldUx, uy=oldUy, uz=oldUz; // no local vars, only for usqr
rho = REFERENCE_PRESSURE;
diff --git a/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp b/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp
index df516357c9e..8fea2a0261b 100644
--- a/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp
+++ b/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp
@@ -28,13 +28,22 @@
#include <spnav.h>
#include <stdio.h>
+#include <unistd.h>
+#define SPNAV_SOCK_PATH "/var/run/spnav.sock"
GHOST_NDOFManagerUnix::GHOST_NDOFManagerUnix(GHOST_System& sys)
: GHOST_NDOFManager(sys),
m_available(false)
{
- if (spnav_open() != -1) {
+ if (access(SPNAV_SOCK_PATH, F_OK) != 0) {
+#ifdef DEBUG
+ /* annoying for official builds, just adds noise and most people don't own these */
+ puts("ndof: spacenavd not found");
+ /* This isn't a hard error, just means the user doesn't have a 3D mouse. */
+#endif
+ }
+ else if (spnav_open() != -1) {
m_available = true;
/* determine exactly which device (if any) is plugged in */
@@ -55,13 +64,6 @@ GHOST_NDOFManagerUnix::GHOST_NDOFManagerUnix(GHOST_System& sys)
pclose(command_output);
}
}
- else {
-#ifdef DEBUG
- /* annoying for official builds, just adds noise and most people don't own these */
- puts("ndof: spacenavd not found");
- /* This isn't a hard error, just means the user doesn't have a 3D mouse. */
-#endif
- }
}
GHOST_NDOFManagerUnix::~GHOST_NDOFManagerUnix()
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index 3e1dbd18119..0c87ee17cb0 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -1925,10 +1925,19 @@ GHOST_TSuccess GHOST_SystemX11::pushDragDropEvent(GHOST_TEventType eventType,
* Basically it will not crash blender now if you have a X device that
* is configured but not plugged in.
*/
-int GHOST_X11_ApplicationErrorHandler(Display * /*display*/, XErrorEvent *theEvent)
+int GHOST_X11_ApplicationErrorHandler(Display *display, XErrorEvent *event)
{
- fprintf(stderr, "Ignoring Xlib error: error code %d request code %d\n",
- theEvent->error_code, theEvent->request_code);
+ char error_code_str[512];
+
+ XGetErrorText(display, event->error_code, error_code_str, sizeof(error_code_str));
+
+ fprintf(stderr,
+ "Received X11 Error:\n"
+ "\terror code: %d\n"
+ "\trequest code: %d\n"
+ "\tminor code: %d\n"
+ "\terror text: %s\n",
+ event->error_code, event->request_code, event->minor_code, error_code_str);
/* No exit! - but keep lint happy */
return 0;
diff --git a/intern/openvdb/intern/openvdb_dense_convert.cc b/intern/openvdb/intern/openvdb_dense_convert.cc
index d4f62776988..ef52408bd93 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.cc
+++ b/intern/openvdb/intern/openvdb_dense_convert.cc
@@ -115,7 +115,8 @@ openvdb::GridBase *OpenVDB_export_vector_grid(
vecgrid->setTransform(transform);
- if (mask) {
+ /* Avoid clipping against an empty grid. */
+ if (mask && !mask->tree().empty()) {
vecgrid = tools::clip(*vecgrid, *mask);
}
diff --git a/intern/openvdb/intern/openvdb_dense_convert.h b/intern/openvdb/intern/openvdb_dense_convert.h
index fd10334c4ad..284fd1ceeae 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.h
+++ b/intern/openvdb/intern/openvdb_dense_convert.h
@@ -64,7 +64,8 @@ GridType *OpenVDB_export_grid(
grid->setTransform(transform);
- if (mask) {
+ /* Avoid clipping against an empty grid. */
+ if (mask && !mask->tree().empty()) {
grid = tools::clip(*grid, *mask);
}
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 5de7159e858..4d694b00feb 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -503,13 +503,12 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
split = layout.split()
col = split.column()
- col.active = not md.is_bound
+ col.enabled = not md.is_bound
col.label(text="Object:")
col.prop(md, "object", text="")
col = split.column()
col.label(text="Vertex Group:")
-
row = col.row(align=True)
row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
sub = row.row(align=True)
@@ -517,16 +516,17 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
sub.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
layout.separator()
+ row = layout.row()
+ row.enabled = not md.is_bound
+ row.prop(md, "precision")
+ row.prop(md, "use_dynamic_bind")
+ layout.separator()
if md.is_bound:
layout.operator("object.meshdeform_bind", text="Unbind")
else:
layout.operator("object.meshdeform_bind", text="Bind")
- row = layout.row()
- row.prop(md, "precision")
- row.prop(md, "use_dynamic_bind")
-
def MIRROR(self, layout, ob, md):
split = layout.split(percentage=0.25)
diff --git a/release/scripts/startup/bl_ui/space_sequencer.py b/release/scripts/startup/bl_ui/space_sequencer.py
index 233145819e7..65fd0a43619 100644
--- a/release/scripts/startup/bl_ui/space_sequencer.py
+++ b/release/scripts/startup/bl_ui/space_sequencer.py
@@ -668,7 +668,15 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel, Panel):
col = layout.column()
col.prop(strip, "text")
col.prop(strip, "font_size")
- col.prop(strip, "use_shadow")
+
+ row = col.row()
+ row.prop(strip, "color")
+ row = col.row()
+ row.prop(strip, "use_shadow")
+ rowsub = row.row()
+ rowsub.active = strip.use_shadow
+ rowsub.prop(strip, "shadow_color", text="")
+
col.prop(strip, "align_x")
col.prop(strip, "align_y")
col.prop(strip, "location")
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 14d63f1e51d..b4c8967349f 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1843,6 +1843,8 @@ class VIEW3D_MT_hide_mask(Menu):
props = layout.operator("paint.mask_lasso_gesture", text="Lasso Mask")
+ layout.operator("particle.unify_length")
+ layout.operator("particle.unify_length")
# ********** Pose Menu **********
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 780662148e0..092cd31330c 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -24,27 +24,35 @@ from nodeitems_utils import NodeCategory, NodeItem, NodeItemCustom
# Subclasses for standard node types
-class CompositorNodeCategory(NodeCategory):
+class SortedNodeCategory(NodeCategory):
+ def __init__(self, identifier, name, description="", items=None):
+ # for builtin nodes the convention is to sort by name
+ if isinstance(items, list):
+ items = sorted(items, key=lambda item: item.label.lower())
+
+ super().__init__(identifier, name, description, items)
+
+class CompositorNodeCategory(SortedNodeCategory):
@classmethod
def poll(cls, context):
return (context.space_data.tree_type == 'CompositorNodeTree')
-class ShaderNewNodeCategory(NodeCategory):
+class ShaderNewNodeCategory(SortedNodeCategory):
@classmethod
def poll(cls, context):
return (context.space_data.tree_type == 'ShaderNodeTree' and
context.scene.render.use_shading_nodes)
-class ShaderOldNodeCategory(NodeCategory):
+class ShaderOldNodeCategory(SortedNodeCategory):
@classmethod
def poll(cls, context):
return (context.space_data.tree_type == 'ShaderNodeTree' and
not context.scene.render.use_shading_nodes)
-class TextureNodeCategory(NodeCategory):
+class TextureNodeCategory(SortedNodeCategory):
@classmethod
def poll(cls, context):
return context.space_data.tree_type == 'TextureNodeTree'
@@ -160,6 +168,7 @@ shader_node_categories = [
NodeItem("ShaderNodeMapping"),
NodeItem("ShaderNodeVectorCurve"),
NodeItem("ShaderNodeVectorTransform"),
+ NodeItem("ShaderNodeNormalMap"),
]),
ShaderOldNodeCategory("SH_CONVERTOR", "Converter", items=[
NodeItem("ShaderNodeValToRGB"),
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index e565ffe3cc1..1f38d64924c 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -153,7 +153,7 @@ void BLF_disable(int fontid, int option);
* the other argument are the rgba color.
* Take care that shadow need to be enable using BLF_enable!!!
*/
-void BLF_shadow(int fontid, int level, float r, float g, float b, float a);
+void BLF_shadow(int fontid, int level, const float rgba[4]) ATTR_NONNULL(3);
/* Set the offset for shadow text, this is the current cursor
* position plus this offset, don't need call BLF_position before
@@ -174,7 +174,7 @@ void BLF_shadow_offset(int fontid, int x, int y);
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, struct ColorManagedDisplay *display);
/* Set the color to be used for text. */
-void BLF_buffer_col(int fontid, float r, float g, float b, float a);
+void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2);
/* Draw the string into the buffer, this function draw in both buffer, float and unsigned char _BUT_
* it's not necessary set both buffer, NULL is valid here.
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 977fa771014..132a0ec3808 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -849,16 +849,13 @@ void BLF_wordwrap(int fontid, int wrap_width)
}
}
-void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
+void BLF_shadow(int fontid, int level, const float rgba[4])
{
FontBLF *font = blf_get(fontid);
if (font) {
font->shadow = level;
- font->shadow_col[0] = r;
- font->shadow_col[1] = g;
- font->shadow_col[2] = b;
- font->shadow_col[3] = a;
+ copy_v4_v4(font->shadow_col, rgba);
}
}
@@ -886,12 +883,12 @@ void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int
}
}
-void BLF_buffer_col(int fontid, float r, float g, float b, float a)
+void BLF_buffer_col(int fontid, const float rgba[4])
{
FontBLF *font = blf_get(fontid);
if (font) {
- ARRAY_SET_ITEMS(font->buf_info.col_init, r, g, b, a);
+ copy_v4_v4(font->buf_info.col_init, rgba);
}
}
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 7c6bef57aa4..dfebaecb96e 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -411,7 +411,7 @@ static void blf_font_draw_buffer_ex(
cbuf[0] = (unsigned char)((b_col_char[0] * a) + (cbuf[0] * (1.0f - a)));
cbuf[1] = (unsigned char)((b_col_char[1] * a) + (cbuf[1] * (1.0f - a)));
cbuf[2] = (unsigned char)((b_col_char[2] * a) + (cbuf[2] * (1.0f - a)));
- cbuf[3] = (unsigned char)((alphatest = ((int)cbuf[3] + (int)(a * 255)) < 255) ?
+ cbuf[3] = (unsigned char)(((alphatest = ((int)cbuf[3] + (int)(a * 255))) < 255) ?
alphatest : 255);
}
}
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index d7d6daa7e2a..7419b182c04 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -71,6 +71,7 @@
* as it is and stick with using BMesh and CDDM.
*/
+#include "DNA_defs.h"
#include "DNA_customdata_types.h"
#include "DNA_meshdata_types.h"
@@ -200,6 +201,8 @@ struct DerivedMesh {
/* use for converting to BMesh which doesn't store bevel weight and edge crease by default */
char cd_flag;
+ char tangent_mask; /* which tangent layers are calculated */
+
/** Calculate vert and face normals */
void (*calcNormals)(DerivedMesh *dm);
@@ -210,7 +213,9 @@ struct DerivedMesh {
void (*calcLoopNormalsSpaceArray)(DerivedMesh *dm, const bool use_split_normals, const float split_angle,
struct MLoopNorSpaceArray *r_lnors_spacearr);
- void (*calcLoopTangents)(DerivedMesh *dm);
+ void (*calcLoopTangents)(
+ DerivedMesh *dm, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_count);
/** Recalculates mesh tessellation */
void (*recalcTessellation)(DerivedMesh *dm);
@@ -763,7 +768,7 @@ typedef struct DMVertexAttribs {
struct {
float (*array)[4];
int em_offset, gl_index;
- } tang;
+ } tang[MAX_MTFACE];
struct {
float (*array)[3];
@@ -779,7 +784,20 @@ void DM_vertex_attributes_from_gpu(
void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert, int loop);
-void DM_calc_loop_tangents(DerivedMesh *dm);
+void DM_calc_tangents_names_from_gpu(
+ const struct GPUVertexAttribs *gattribs,
+ char (*tangent_names)[MAX_NAME], int *tangent_names_count);
+void DM_add_named_tangent_layer_for_uv(
+ CustomData *uv_data, CustomData *tan_data, int numLoopData,
+ const char *layer_name);
+void DM_calc_loop_tangents_step_0(
+ const CustomData *loopData, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_count,
+ bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
+ char *ract_uv_name, char *rren_uv_name, char *rtangent_mask);
+void DM_calc_loop_tangents(
+ DerivedMesh *dm, bool calc_active_tangent, const char (*tangent_names)[MAX_NAME],
+ int tangent_names_count);
void DM_calc_auto_bump_scale(DerivedMesh *dm);
/** Set object's bounding box based on DerivedMesh min/max data */
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index fdb34743f36..8ce85c8e615 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -38,88 +38,20 @@
extern "C" {
#endif
-/* these lines are grep'd, watch out for our not-so-awesome regex
- * and keep comment above the defines.
- * Use STRINGIFY() rather than defining with quotes */
-#define BLENDER_VERSION 277
-#define BLENDER_SUBVERSION 0
-/* Several breakages with 270, e.g. constraint deg vs rad */
-#define BLENDER_MINVERSION 270
-#define BLENDER_MINSUBVERSION 6
+void BKE_blender_free(void);
-/* used by packaging tools */
-/* can be left blank, otherwise a,b,c... etc with no quotes */
-#define BLENDER_VERSION_CHAR
-/* alpha/beta/rc/release, docs use this */
-#define BLENDER_VERSION_CYCLE alpha
+void BKE_blender_globals_init(void);
+void BKE_blender_globals_clear(void);
-extern char versionstr[]; /* from blender.c */
-
-struct MemFile;
-struct bContext;
-struct ReportList;
-struct Scene;
-struct Main;
-struct ID;
-
-int BKE_read_file(struct bContext *C, const char *filepath, struct ReportList *reports);
-
-#define BKE_READ_FILE_FAIL 0 /* no load */
-#define BKE_READ_FILE_OK 1 /* OK */
-#define BKE_READ_FILE_OK_USERPREFS 2 /* OK, and with new user settings */
-
-bool BKE_read_file_from_memory(
- struct bContext *C, const void *filebuf,
- int filelength, struct ReportList *reports, bool update_defaults);
-bool BKE_read_file_from_memfile(
- struct bContext *C, struct MemFile *memfile,
- struct ReportList *reports);
-
-int BKE_read_file_userdef(const char *filepath, struct ReportList *reports);
-int BKE_write_file_userdef(const char *filepath, struct ReportList *reports);
-
-void free_blender(void);
-void initglobals(void);
-
-/* load new userdef from file, exit blender */
-void BKE_userdef_free(void);
-/* handle changes in userdef */
-void BKE_userdef_state(void);
+void BKE_blender_userdef_free(void);
+void BKE_blender_userdef_refresh(void);
/* set this callback when a UI is running */
void BKE_blender_callback_test_break_set(void (*func)(void));
-int blender_test_break(void);
-
-#define BKE_UNDO_STR_MAX 64
-
-/* global undo */
-extern void BKE_undo_write(struct bContext *C, const char *name);
-extern void BKE_undo_step(struct bContext *C, int step);
-extern void BKE_undo_name(struct bContext *C, const char *name);
-extern bool BKE_undo_is_valid(const char *name);
-extern void BKE_undo_reset(void);
-extern void BKE_undo_number(struct bContext *C, int nr);
-extern const char *BKE_undo_get_name(int nr, bool *r_active);
-extern bool BKE_undo_save_file(const char *filename);
-extern struct Main *BKE_undo_get_main(struct Scene **r_scene);
-
-/* partial blend file writing */
-void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set);
-void BKE_blendfile_write_partial_begin(struct Main *bmain_src);
-bool BKE_blendfile_write_partial(
- struct Main *bmain_src, const char *filepath, const int write_flags, struct ReportList *reports);
-void BKE_blendfile_write_partial_end(struct Main *bmain_src);
-
-
-/* copybuffer (wrapper for BKE_blendfile_write_partial) */
-void BKE_copybuffer_begin(struct Main *bmain_src);
-void BKE_copybuffer_tag_ID(struct ID *id);
-bool BKE_copybuffer_save(struct Main *bmain_src, const char *filename, struct ReportList *reports);
-bool BKE_copybuffer_paste(struct bContext *C, const char *libname, const short flag, struct ReportList *reports);
+int BKE_blender_test_break(void);
#ifdef __cplusplus
}
#endif
-#endif
-
+#endif /* __BKE_BLENDER_H__ */
diff --git a/source/blender/blenkernel/BKE_blender_copybuffer.h b/source/blender/blenkernel/BKE_blender_copybuffer.h
new file mode 100644
index 00000000000..8aaf295c33a
--- /dev/null
+++ b/source/blender/blenkernel/BKE_blender_copybuffer.h
@@ -0,0 +1,46 @@
+/*
+ * ***** 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 *****
+ */
+#ifndef __BKE_BLENDER_COPYBUFFER_H__
+#define __BKE_BLENDER_COPYBUFFER_H__
+
+/** \file BKE_blender_copybuffer.h
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bContext;
+struct ReportList;
+struct Main;
+struct ID;
+
+/* copybuffer (wrapper for BKE_blendfile_write_partial) */
+void BKE_copybuffer_begin(struct Main *bmain_src);
+void BKE_copybuffer_tag_ID(struct ID *id);
+bool BKE_copybuffer_save(struct Main *bmain_src, const char *filename, struct ReportList *reports);
+bool BKE_copybuffer_paste(struct bContext *C, const char *libname, const short flag, struct ReportList *reports);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_BLENDER_COPYBUFFER_H__ */
diff --git a/source/blender/blenkernel/BKE_blender_undo.h b/source/blender/blenkernel/BKE_blender_undo.h
new file mode 100644
index 00000000000..cd18bd8db40
--- /dev/null
+++ b/source/blender/blenkernel/BKE_blender_undo.h
@@ -0,0 +1,52 @@
+/*
+ * ***** 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 *****
+ */
+#ifndef __BKE_BLENDER_UNDO_H__
+#define __BKE_BLENDER_UNDO_H__
+
+/** \file BKE_blender_undo.h
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bContext;
+struct Scene;
+struct Main;
+
+#define BKE_UNDO_STR_MAX 64
+
+/* global undo */
+extern void BKE_undo_write(struct bContext *C, const char *name);
+extern void BKE_undo_step(struct bContext *C, int step);
+extern void BKE_undo_name(struct bContext *C, const char *name);
+extern bool BKE_undo_is_valid(const char *name);
+extern void BKE_undo_reset(void);
+extern void BKE_undo_number(struct bContext *C, int nr);
+extern const char *BKE_undo_get_name(int nr, bool *r_active);
+extern bool BKE_undo_save_file(const char *filename);
+extern struct Main *BKE_undo_get_main(struct Scene **r_scene);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_BLENDER_UNDO_H__ */
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
new file mode 100644
index 00000000000..5e7fdb91645
--- /dev/null
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -0,0 +1,44 @@
+/*
+ * ***** 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 *****
+ */
+#ifndef __BKE_BLENDER_VERSION_H__
+#define __BKE_BLENDER_VERSION_H__
+
+/** \file BKE_blender_version.h
+ * \ingroup bke
+ */
+
+/* these lines are grep'd, watch out for our not-so-awesome regex
+ * and keep comment above the defines.
+ * Use STRINGIFY() rather than defining with quotes */
+#define BLENDER_VERSION 277
+#define BLENDER_SUBVERSION 0
+/* Several breakages with 270, e.g. constraint deg vs rad */
+#define BLENDER_MINVERSION 270
+#define BLENDER_MINSUBVERSION 6
+
+/* used by packaging tools */
+/* can be left blank, otherwise a,b,c... etc with no quotes */
+#define BLENDER_VERSION_CHAR
+/* alpha/beta/rc/release, docs use this */
+#define BLENDER_VERSION_CYCLE alpha
+
+extern char versionstr[]; /* from blender.c */
+
+#endif /* __BKE_BLENDER_VERSION_H__ */
diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
new file mode 100644
index 00000000000..6767fce3abd
--- /dev/null
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -0,0 +1,67 @@
+/*
+ * ***** 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 *****
+ */
+#ifndef __BKE_BLENDFILE_H__
+#define __BKE_BLENDFILE_H__
+
+/** \file BKE_blendfile.h
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bContext;
+struct ID;
+struct Main;
+struct MemFile;
+struct ReportList;
+
+int BKE_blendfile_read(struct bContext *C, const char *filepath, struct ReportList *reports);
+
+enum {
+ BKE_BLENDFILE_READ_FAIL = 0, /* no load */
+ BKE_BLENDFILE_READ_OK = 1, /* OK */
+ BKE_BLENDFILE_READ_OK_USERPREFS = 2, /* OK, and with new user settings */
+};
+
+bool BKE_blendfile_read_from_memory(
+ struct bContext *C, const void *filebuf,
+ int filelength, struct ReportList *reports, bool update_defaults);
+bool BKE_blendfile_read_from_memfile(
+ struct bContext *C, struct MemFile *memfile,
+ struct ReportList *reports);
+
+int BKE_blendfile_read_userdef(const char *filepath, struct ReportList *reports);
+int BKE_blendfile_write_userdef(const char *filepath, struct ReportList *reports);
+
+
+/* partial blend file writing */
+void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set);
+void BKE_blendfile_write_partial_begin(struct Main *bmain_src);
+bool BKE_blendfile_write_partial(
+ struct Main *bmain_src, const char *filepath, const int write_flags, struct ReportList *reports);
+void BKE_blendfile_write_partial_end(struct Main *bmain_src);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_BLENDFILE_H__ */
diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h
index 2f85db4d5d2..25893d54dca 100644
--- a/source/blender/blenkernel/BKE_mask.h
+++ b/source/blender/blenkernel/BKE_mask.h
@@ -61,8 +61,10 @@ typedef enum {
MASK_HANDLE_MODE_INDIVIDUAL_HANDLES = 2,
} eMaskhandleMode;
-struct MaskSplinePoint *BKE_mask_spline_point_array(struct MaskSpline *spline);
-struct MaskSplinePoint *BKE_mask_spline_point_array_from_point(struct MaskSpline *spline, struct MaskSplinePoint *point_ref);
+struct MaskSplinePoint *BKE_mask_spline_point_array(
+ struct MaskSpline *spline);
+struct MaskSplinePoint *BKE_mask_spline_point_array_from_point(
+ struct MaskSpline *spline, const struct MaskSplinePoint *point_ref);
/* mask layers */
struct MaskLayer *BKE_mask_layer_new(struct Mask *mask, const char *name);
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index a8f20a4ebc5..ac1f1576eba 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -293,8 +293,9 @@ void BKE_mesh_loops_to_mface_corners(
void BKE_mesh_loops_to_tessdata(
struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, struct MFace *mface,
int *polyindices, unsigned int (*loopindices)[4], const int num_faces);
-void BKE_mesh_tangent_loops_to_tessdata(struct CustomData *fdata, struct CustomData *ldata, struct MFace *mface,
- int *polyindices, unsigned int (*loopindices)[4], const int num_faces);
+void BKE_mesh_tangent_loops_to_tessdata(
+ struct CustomData *fdata, struct CustomData *ldata, struct MFace *mface,
+ int *polyindices, unsigned int (*loopindices)[4], const int num_faces, const char *layer_name);
int BKE_mesh_recalc_tessellation(
struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
struct MVert *mvert,
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 8f253e1219a..b8a6b230a02 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -75,6 +75,9 @@ set(SRC
intern/armature_update.c
intern/autoexec.c
intern/blender.c
+ intern/blender_copybuffer.c
+ intern/blender_undo.c
+ intern/blendfile.c
intern/bmfont.c
intern/bpath.c
intern/brush.c
@@ -189,6 +192,10 @@ set(SRC
BKE_armature.h
BKE_autoexec.h
BKE_blender.h
+ BKE_blender_copybuffer.h
+ BKE_blender_undo.h
+ BKE_blender_version.h
+ BKE_blendfile.h
BKE_bmfont.h
BKE_bmfont_types.h
BKE_bpath.h
@@ -407,7 +414,7 @@ if(WITH_PYTHON)
endif()
- if (PYTHON_EXECUTABLE)
+ if(PYTHON_EXECUTABLE)
get_filename_component(_python_exe_name ${PYTHON_EXECUTABLE} NAME)
add_definitions(-DPYTHON_EXECUTABLE_NAME=${_python_exe_name})
unset(_python_exe_name)
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index d120678c005..57926e6a56a 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -49,6 +49,7 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_linklist.h"
+#include "BLI_task.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_editmesh.h"
@@ -595,50 +596,49 @@ void DM_generate_tangent_tessface_data(DerivedMesh *dm, bool generate)
int mf_idx;
int *polyindex = CustomData_get_layer(fdata, CD_ORIGINDEX);
- unsigned int (*loopindex)[4];
+ unsigned int (*loopindex)[4] = NULL;
/* Should never occure, but better abort than segfault! */
if (!polyindex)
return;
if (generate) {
- for (int i = 0; i < ldata->totlayer; i++) {
- if (ldata->layers[i].type == CD_TANGENT) {
- CustomData_add_layer_named(fdata, CD_TANGENT, CD_CALLOC, NULL, totface, ldata->layers[i].name);
- }
- }
- CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
- }
-
- BLI_assert(CustomData_from_bmeshpoly_test(fdata, pdata, ldata, true));
-
- loopindex = MEM_mallocN(sizeof(*loopindex) * totface, __func__);
-
- for (mf_idx = 0, mf = mface; mf_idx < totface; mf_idx++, mf++) {
- const int mf_len = mf->v4 ? 4 : 3;
- unsigned int *ml_idx = loopindex[mf_idx];
- int i, not_done;
+ for (int j = 0; j < ldata->totlayer; j++) {
+ if (ldata->layers[j].type == CD_TANGENT) {
+ CustomData_add_layer_named(fdata, CD_TANGENT, CD_CALLOC, NULL, totface, ldata->layers[j].name);
+ CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
+
+ if (!loopindex) {
+ loopindex = MEM_mallocN(sizeof(*loopindex) * totface, __func__);
+ for (mf_idx = 0, mf = mface; mf_idx < totface; mf_idx++, mf++) {
+ const int mf_len = mf->v4 ? 4 : 3;
+ unsigned int *ml_idx = loopindex[mf_idx];
+
+ /* Find out loop indices. */
+ /* NOTE: This assumes tessface are valid and in sync with loop/poly... Else, most likely, segfault! */
+ for (int i = mp[polyindex[mf_idx]].loopstart, not_done = mf_len; not_done; i++) {
+ const int tf_v = BKE_MESH_TESSFACE_VINDEX_ORDER(mf, ml[i].v);
+ if (tf_v != -1) {
+ ml_idx[tf_v] = i;
+ not_done--;
+ }
+ }
+ }
+ }
- /* Find out loop indices. */
- /* NOTE: This assumes tessface are valid and in sync with loop/poly... Else, most likely, segfault! */
- for (i = mp[polyindex[mf_idx]].loopstart, not_done = mf_len; not_done; i++) {
- const int tf_v = BKE_MESH_TESSFACE_VINDEX_ORDER(mf, ml[i].v);
- if (tf_v != -1) {
- ml_idx[tf_v] = i;
- not_done--;
+ /* NOTE: quad detection issue - fourth vertidx vs fourth loopidx:
+ * Here, our tfaces' fourth vertex index is never 0 for a quad. However, we know our fourth loop index may be
+ * 0 for quads (because our quads may have been rotated compared to their org poly, see tessellation code).
+ * So we pass the MFace's, and BKE_mesh_loops_to_tessdata will use MFace->v4 index as quad test.
+ */
+ BKE_mesh_tangent_loops_to_tessdata(fdata, ldata, mface, polyindex, loopindex, totface, ldata->layers[j].name);
}
}
+ if (loopindex)
+ MEM_freeN(loopindex);
+ BLI_assert(CustomData_from_bmeshpoly_test(fdata, pdata, ldata, true));
}
- /* NOTE: quad detection issue - fourth vertidx vs fourth loopidx:
- * Here, our tfaces' fourth vertex index is never 0 for a quad. However, we know our fourth loop index may be
- * 0 for quads (because our quads may have been rotated compared to their org poly, see tessellation code).
- * So we pass the MFace's, and BKE_mesh_loops_to_tessdata will use MFace->v4 index as quad test.
- */
- BKE_mesh_tangent_loops_to_tessdata(fdata, ldata, mface, polyindex, loopindex, totface);
-
- MEM_freeN(loopindex);
-
if (G.debug & G_DEBUG)
printf("%s: Updated tessellated tangents of dm %p\n", __func__, dm);
}
@@ -3207,96 +3207,28 @@ finally:
pRes[3] = fSign;
}
-void DM_calc_loop_tangents(DerivedMesh *dm)
+void DM_calc_tangents_names_from_gpu(
+ const GPUVertexAttribs *gattribs,
+ char (*tangent_names)[MAX_NAME], int *r_tangent_names_count)
{
- /* mesh vars */
- const MLoopTri *looptri;
- MVert *mvert;
- MLoopUV *mloopuv;
- MPoly *mpoly;
- MLoop *mloop;
- float (*orco)[3] = NULL, (*tangent)[4];
- int /* totvert, */ totface;
- float (*fnors)[3];
- float (*tlnors)[3];
-
- if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) != -1)
- return;
-
- fnors = dm->getPolyDataArray(dm, CD_NORMAL);
- /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
- * have to check this is valid...
- */
- tlnors = dm->getLoopDataArray(dm, CD_NORMAL);
-
- /* check we have all the needed layers */
- /* totvert = dm->getNumVerts(dm); */ /* UNUSED */
- looptri = dm->getLoopTriArray(dm);
- totface = dm->getNumLoopTri(dm);
-
- mvert = dm->getVertArray(dm);
- mpoly = dm->getPolyArray(dm);
- mloop = dm->getLoopArray(dm);
- mloopuv = dm->getLoopDataArray(dm, CD_MLOOPUV);
-
- if (!mloopuv) {
- orco = dm->getVertDataArray(dm, CD_ORCO);
- if (!orco)
- return;
- }
-
- /* create tangent layer */
- DM_add_loop_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
- tangent = DM_get_loop_data_layer(dm, CD_TANGENT);
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- int num_face_as_quad_map;
- int *face_as_quad_map = NULL;
-
- /* map faces to quads */
- if (totface != dm->getNumPolys(dm)) {
- /* over alloc, since we dont know how many ngon or quads we have */
-
- /* map fake face index to looptri */
- face_as_quad_map = MEM_mallocN(sizeof(int) * totface, __func__);
- int i, j;
- for (i = 0, j = 0; j < totface; i++, j++) {
- face_as_quad_map[i] = j;
- /* step over all quads */
- if (mpoly[looptri[j].poly].totloop == 4) {
- j++; /* skips the nest looptri */
- }
+ int count = 0;
+ for (int b = 0; b < gattribs->totlayer; b++) {
+ if (gattribs->layer[b].type == CD_TANGENT) {
+ strcpy(tangent_names[count++], gattribs->layer[b].name);
}
- num_face_as_quad_map = i;
- }
- else {
- num_face_as_quad_map = totface;
}
-#endif
+ *r_tangent_names_count = count;
+}
+static void DM_calc_loop_tangents_thread(TaskPool *UNUSED(pool), void *taskdata, int UNUSED(threadid))
+{
+ struct SGLSLMeshToTangent *mesh2tangent = taskdata;
/* new computation method */
{
- SGLSLMeshToTangent mesh2tangent = {NULL};
SMikkTSpaceContext sContext = {NULL};
SMikkTSpaceInterface sInterface = {NULL};
- mesh2tangent.precomputedFaceNormals = fnors;
- mesh2tangent.precomputedLoopNormals = tlnors;
- mesh2tangent.looptri = looptri;
- mesh2tangent.mloopuv = mloopuv;
- mesh2tangent.mpoly = mpoly;
- mesh2tangent.mloop = mloop;
- mesh2tangent.mvert = mvert;
- mesh2tangent.orco = orco;
- mesh2tangent.tangent = tangent;
- mesh2tangent.numTessFaces = totface;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- mesh2tangent.face_as_quad_map = face_as_quad_map;
- mesh2tangent.num_face_as_quad_map = num_face_as_quad_map;
-#endif
-
- sContext.m_pUserData = &mesh2tangent;
+ sContext.m_pUserData = mesh2tangent;
sContext.m_pInterface = &sInterface;
sInterface.m_getNumFaces = dm_ts_GetNumFaces;
sInterface.m_getNumVerticesOfFace = dm_ts_GetNumVertsOfFace;
@@ -3307,13 +3239,211 @@ void DM_calc_loop_tangents(DerivedMesh *dm)
/* 0 if failed */
genTangSpaceDefault(&sContext);
+ }
+}
+
+void DM_add_named_tangent_layer_for_uv(
+ CustomData *uv_data, CustomData *tan_data, int numLoopData,
+ const char *layer_name)
+{
+ if (CustomData_get_named_layer_index(tan_data, CD_TANGENT, layer_name) == -1 &&
+ CustomData_get_named_layer_index(uv_data, CD_MLOOPUV, layer_name) != -1)
+ {
+ CustomData_add_layer_named(
+ tan_data, CD_TANGENT, CD_CALLOC, NULL,
+ numLoopData, layer_name);
+ }
+}
+
+/**
+ * Here we get some useful information such as active uv layer name and search if it is already in tangent_names.
+ * Also, we calculate tangent_mask that works as a descriptor of tangents state.
+ * If tangent_mask has changed, then recalculate tangents.
+ */
+void DM_calc_loop_tangents_step_0(
+ const CustomData *loopData, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_count,
+ bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
+ char *ract_uv_name, char *rren_uv_name, char *rtangent_mask) {
+ /* Active uv in viewport */
+ *ract_uv_n = CustomData_get_active_layer(loopData, CD_MLOOPUV);
+ ract_uv_name[0] = 0;
+ if (*ract_uv_n != -1) {
+ strcpy(ract_uv_name, loopData->layers[*ract_uv_n].name);
+ }
+
+ /* Active tangent in render */
+ *rren_uv_n = CustomData_get_render_layer(loopData, CD_MLOOPUV);
+ rren_uv_name[0] = 0;
+ if (*rren_uv_n != -1) {
+ strcpy(rren_uv_name, loopData->layers[*rren_uv_n].name);
+ }
+
+ /* If active tangent not in tangent_names we take it into account */
+ *rcalc_act = false;
+ *rcalc_ren = false;
+ for (int i = 0; i < tangent_names_count; i++) {
+ if (tangent_names[i][0] == 0) {
+ calc_active_tangent = true;
+ }
+ }
+ if (calc_active_tangent) {
+ *rcalc_act = true;
+ *rcalc_ren = true;
+ for (int i = 0; i < tangent_names_count; i++) {
+ if (STREQ(ract_uv_name, tangent_names[i]))
+ *rcalc_act = false;
+ if (STREQ(rren_uv_name, tangent_names[i]))
+ *rcalc_ren = false;
+ }
+ }
+ *rtangent_mask = 0;
+
+ const int uv_layer_num = CustomData_number_of_layers(loopData, CD_MLOOPUV);
+ for (int n = 0; n < uv_layer_num; n++) {
+ const char *name = CustomData_get_layer_name(loopData, CD_MLOOPUV, n);
+ bool add = false;
+ for (int i = 0; i < tangent_names_count; i++) {
+ if (tangent_names[i][0] && STREQ(tangent_names[i], name)) {
+ add = true;
+ break;
+ }
+ }
+ if ((*rcalc_act && ract_uv_name[0] && STREQ(ract_uv_name, name)) ||
+ (*rcalc_ren && rren_uv_name[0] && STREQ(rren_uv_name, name)))
+ {
+ add = true;
+ }
+ if (add)
+ *rtangent_mask |= 1 << n;
+ }
+}
+
+void DM_calc_loop_tangents(
+ DerivedMesh *dm, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_count)
+{
+ if (CustomData_number_of_layers(&dm->loopData, CD_MLOOPUV) == 0)
+ return;
+ int act_uv_n = -1;
+ int ren_uv_n = -1;
+ bool calc_act = false;
+ bool calc_ren = false;
+ char act_uv_name[MAX_NAME];
+ char ren_uv_name[MAX_NAME];
+ char tangent_mask = 0;
+ DM_calc_loop_tangents_step_0(
+ &dm->loopData, calc_active_tangent, tangent_names, tangent_names_count,
+ &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
+ if ((dm->tangent_mask | tangent_mask) != dm->tangent_mask) {
+ /* Check we have all the needed layers */
+ MPoly *mpoly = dm->getPolyArray(dm);
+ const MLoopTri *looptri = dm->getLoopTriArray(dm);
+ int totface = dm->getNumLoopTri(dm);
+ /* Allocate needed tangent layers */
+ for (int i = 0; i < tangent_names_count; i++)
+ if (tangent_names[i][0])
+ DM_add_named_tangent_layer_for_uv(&dm->loopData, &dm->loopData, dm->numLoopData, tangent_names[i]);
+ if (calc_act && act_uv_name[0])
+ DM_add_named_tangent_layer_for_uv(&dm->loopData, &dm->loopData, dm->numLoopData, act_uv_name);
+ if (calc_ren && ren_uv_name[0])
+ DM_add_named_tangent_layer_for_uv(&dm->loopData, &dm->loopData, dm->numLoopData, ren_uv_name);
#ifdef USE_LOOPTRI_DETECT_QUADS
+ int num_face_as_quad_map;
+ int *face_as_quad_map = NULL;
+
+ /* map faces to quads */
+ if (totface != dm->getNumPolys(dm)) {
+ /* over alloc, since we dont know how many ngon or quads we have */
+
+ /* map fake face index to looptri */
+ face_as_quad_map = MEM_mallocN(sizeof(int) * totface, __func__);
+ int k, j;
+ for (k = 0, j = 0; j < totface; k++, j++) {
+ face_as_quad_map[k] = j;
+ /* step over all quads */
+ if (mpoly[looptri[j].poly].totloop == 4) {
+ j++; /* skips the nest looptri */
+ }
+ }
+ num_face_as_quad_map = k;
+ }
+ else {
+ num_face_as_quad_map = totface;
+ }
+#endif
+
+ /* Calculation */
+ {
+ TaskScheduler *scheduler = BLI_task_scheduler_get();
+ TaskPool *task_pool;
+ task_pool = BLI_task_pool_create(scheduler, NULL);
+
+ dm->tangent_mask = 0;
+ /* Calculate tangent layers */
+ SGLSLMeshToTangent data_array[MAX_MTFACE];
+ const int tangent_layer_num = CustomData_number_of_layers(&dm->loopData, CD_TANGENT);
+ for (int n = 0; n < tangent_layer_num; n++) {
+ int index = CustomData_get_layer_index_n(&dm->loopData, CD_TANGENT, n);
+ BLI_assert(n < MAX_MTFACE);
+ SGLSLMeshToTangent *mesh2tangent = &data_array[n];
+ mesh2tangent->numTessFaces = totface;
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ mesh2tangent->face_as_quad_map = face_as_quad_map;
+ mesh2tangent->num_face_as_quad_map = num_face_as_quad_map;
+#endif
+ mesh2tangent->mvert = dm->getVertArray(dm);
+ mesh2tangent->mpoly = dm->getPolyArray(dm);
+ mesh2tangent->mloop = dm->getLoopArray(dm);
+ mesh2tangent->looptri = dm->getLoopTriArray(dm);
+ /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
+ * have to check this is valid...
+ */
+ mesh2tangent->precomputedLoopNormals = dm->getLoopDataArray(dm, CD_NORMAL);
+ mesh2tangent->precomputedFaceNormals = CustomData_get_layer(&dm->faceData, CD_NORMAL);
+
+ mesh2tangent->orco = NULL;
+ mesh2tangent->mloopuv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, dm->loopData.layers[index].name);
+ if (!mesh2tangent->mloopuv) {
+ mesh2tangent->orco = dm->getVertDataArray(dm, CD_ORCO);
+ if (!mesh2tangent->orco)
+ continue;
+ }
+ mesh2tangent->tangent = dm->loopData.layers[index].data;
+
+ /* Fill the resulting tangent_mask */
+ int uv_ind = CustomData_get_named_layer_index(&dm->loopData, CD_MLOOPUV, dm->loopData.layers[index].name);
+ int uv_start = CustomData_get_layer_index(&dm->loopData, CD_MLOOPUV);
+ BLI_assert(uv_ind != -1 && uv_start != -1);
+ BLI_assert(uv_ind - uv_start < MAX_MTFACE);
+ dm->tangent_mask |= 1 << (uv_ind - uv_start);
+ BLI_task_pool_push(task_pool, DM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW);
+ }
+
+ BLI_assert(dm->tangent_mask == tangent_mask);
+ BLI_task_pool_work_and_wait(task_pool);
+ BLI_task_pool_free(task_pool);
+ }
+#ifdef USE_LOOPTRI_DETECT_QUADS
if (face_as_quad_map) {
MEM_freeN(face_as_quad_map);
}
#undef USE_LOOPTRI_DETECT_QUADS
+
#endif
+
+ int uv_index, tan_index;
+
+ /* Update active layer index */
+ uv_index = CustomData_get_layer_index_n(&dm->loopData, CD_MLOOPUV, act_uv_n);
+ tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, dm->loopData.layers[uv_index].name);
+ CustomData_set_layer_active_index(&dm->loopData, CD_TANGENT, tan_index);
+
+ /* Update render layer index */
+ uv_index = CustomData_get_layer_index_n(&dm->loopData, CD_MLOOPUV, ren_uv_n);
+ tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, dm->loopData.layers[uv_index].name);
+ CustomData_set_layer_render_index(&dm->loopData, CD_TANGENT, tan_index);
}
}
@@ -3487,15 +3617,13 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
if (dm->auto_bump_scale <= 0.0f)
DM_calc_auto_bump_scale(dm);
- /* add a tangent layer if necessary */
- for (b = 0; b < gattribs->totlayer; b++) {
- if (gattribs->layer[b].type == CD_TANGENT) {
- if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) {
- dm->calcLoopTangents(dm);
- }
- break;
- }
- }
+ char tangent_names[MAX_MTFACE][MAX_NAME];
+ int tangent_names_count;
+ /* Add a tangent layer/layers. */
+ DM_calc_tangents_names_from_gpu(gattribs, tangent_names, &tangent_names_count);
+
+ if (tangent_names_count)
+ dm->calcLoopTangents(dm, false, (const char (*)[MAX_NAME])tangent_names, tangent_names_count);
for (b = 0; b < gattribs->totlayer; b++) {
if (gattribs->layer[b].type == CD_MTFACE) {
@@ -3541,20 +3669,24 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
}
else if (gattribs->layer[b].type == CD_TANGENT) {
/* note, even with 'is_editmesh' this uses the derived-meshes loop data */
- layer = CustomData_get_layer_index(&dm->loopData, CD_TANGENT);
- attribs->tottang = 1;
+ if (gattribs->layer[b].name[0])
+ layer = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, gattribs->layer[b].name);
+ else
+ layer = CustomData_get_active_layer_index(&dm->loopData, CD_TANGENT);
+
+ a = attribs->tottang++;
if (layer != -1) {
- attribs->tang.array = dm->loopData.layers[layer].data;
- attribs->tang.em_offset = dm->loopData.layers[layer].offset;
+ attribs->tang[a].array = dm->loopData.layers[layer].data;
+ attribs->tang[a].em_offset = dm->loopData.layers[layer].offset;
}
else {
- attribs->tang.array = NULL;
- attribs->tang.em_offset = -1;
+ attribs->tang[a].array = NULL;
+ attribs->tang[a].em_offset = -1;
}
- attribs->tang.gl_index = gattribs->layer[b].glindex;
+ attribs->tang[a].gl_index = gattribs->layer[b].glindex;
}
else if (gattribs->layer[b].type == CD_ORCO) {
/* original coordinates */
@@ -3636,10 +3768,12 @@ void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert,
}
/* tangent for normal mapping */
- if (attribs->tottang) {
- /*const*/ float (*array)[4] = attribs->tang.array;
- const float *tang = (array) ? array[loop] : zero;
- glVertexAttrib4fv(attribs->tang.gl_index, tang);
+ for (b = 0; b < attribs->tottang; b++) {
+ if (attribs->tang[b].array) {
+ /*const*/ float (*array)[4] = attribs->tang[b].array;
+ const float *tang = (array) ? array[a * 4 + vert] : zero;
+ glVertexAttrib4fv(attribs->tang[b].gl_index, tang);
+ }
}
}
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 3e1cf6a74a4..5b1bb8cb2bb 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -1414,6 +1414,12 @@ void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, c
workob->constraints.last = ob->constraints.last;
workob->pose = pose; /* need to set pose too, since this is used for both types of Action Constraint */
+ if (pose) {
+ BKE_pose_channels_hash_make(pose);
+ if (pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
+ BKE_pose_update_constraint_flags(pose);
+ }
+ }
BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr));
BLI_strncpy(workob->id.name, "OB<ConstrWorkOb>", sizeof(workob->id.name)); /* we don't use real object name, otherwise RNA screws with the real thing */
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index de21d9105e2..b1dcc40279f 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -32,7 +32,7 @@
#include "BLI_fileops.h"
#include "BLI_path_util.h"
-#include "BKE_blender.h" /* BLENDER_VERSION */
+#include "BKE_blender_version.h"
#include "BKE_appdir.h" /* own include */
#include "GHOST_Path-api.h"
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 54fe98940aa..564c670fb3a 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -633,7 +633,7 @@ typedef struct bPoseChanDeform {
DualQuat *b_bone_dual_quats;
} bPoseChanDeform;
-static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info, int use_quaternion)
+static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info, const bool use_quaternion)
{
Bone *bone = pchan->bone;
Mat4 b_bone[MAX_BBONE_SUBDIV], b_bone_rest[MAX_BBONE_SUBDIV];
@@ -867,16 +867,19 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float
bDeformGroup *dg;
DualQuat *dualquats = NULL;
float obinv[4][4], premat[4][4], postmat[4][4];
- const short use_envelope = deformflag & ARM_DEF_ENVELOPE;
- const short use_quaternion = deformflag & ARM_DEF_QUATERNION;
- const short invert_vgroup = deformflag & ARM_DEF_INVERT_VGROUP;
+ const bool use_envelope = (deformflag & ARM_DEF_ENVELOPE) != 0;
+ const bool use_quaternion = (deformflag & ARM_DEF_QUATERNION) != 0;
+ const bool invert_vgroup = (deformflag & ARM_DEF_INVERT_VGROUP) != 0;
int defbase_tot = 0; /* safety for vertexgroup index overflow */
int i, target_totvert = 0; /* safety for vertexgroup overflow */
bool use_dverts = false;
int armature_def_nr;
int totchan;
- if (arm->edbo) return;
+ /* in editmode, or not an armature */
+ if (arm->edbo || (armOb->pose == NULL)) {
+ return;
+ }
invert_m4_m4(obinv, target->obmat);
copy_m4_m4(premat, target->obmat);
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index baf93ffd824..15492fbd20d 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -27,89 +27,55 @@
/** \file blender/blenkernel/intern/blender.c
* \ingroup bke
+ *
+ * Application level startup/shutdown functionality.
*/
-#ifndef _GNU_SOURCE
-/* Needed for O_NOFOLLOW on some platforms. */
-# define _GNU_SOURCE 1
-#endif
-
-#ifndef _WIN32
-# include <unistd.h> // for read close
-#else
-# include <io.h> // for open close read
-#endif
-
#include <stdlib.h>
#include <stdio.h>
-#include <stddef.h>
#include <string.h>
-#include <fcntl.h> /* for open */
-#include <errno.h>
#include "MEM_guardedalloc.h"
-#include "DNA_userdef_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_windowmanager_types.h"
-
-#include "BLI_blenlib.h"
+#include "BLI_string.h"
+#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BLI_callbacks.h"
#include "IMB_imbuf.h"
#include "IMB_moviecache.h"
-#include "BKE_appdir.h"
-#include "BKE_blender.h"
-#include "BKE_bpath.h"
+#include "BKE_blender.h" /* own include */
+#include "BKE_blender_version.h" /* own include */
+#include "BKE_blendfile.h"
#include "BKE_brush.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
-#include "BKE_ipo.h"
#include "BKE_library.h"
-#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
-#include "BKE_sound.h"
#include "RE_pipeline.h"
#include "RE_render_ext.h"
#include "BLF_api.h"
-#include "BLO_undofile.h"
-#include "BLO_readfile.h"
-#include "BLO_writefile.h"
-
-#include "RNA_access.h"
-
-#include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie
-
-#include "IMB_colormanagement.h"
-
-#ifdef WITH_PYTHON
-# include "BPY_extern.h"
-#endif
Global G;
UserDef U;
-/* ListBase = {NULL, NULL}; */
char versionstr[48] = "";
/* ********** free ********** */
/* only to be called on exit blender */
-void free_blender(void)
+void BKE_blender_free(void)
{
/* samples are in a global list..., also sets G.main->sound->sample NULL */
BKE_main_free(G.main);
@@ -132,7 +98,7 @@ void free_blender(void)
free_nodesystem();
}
-void initglobals(void)
+void BKE_blender_globals_init(void)
{
memset(&G, 0, sizeof(Global));
@@ -154,300 +120,14 @@ void initglobals(void)
#endif
}
-/***/
-
-static void clear_global(void)
+void BKE_blender_globals_clear(void)
{
-// extern short winqueue_break; /* screen.c */
-
BKE_main_free(G.main); /* free all lib data */
-
-// free_vertexpaint();
G.main = NULL;
}
-static bool clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src)
-{
- strcpy(path_dst, path_src);
- BLI_path_native_slash(path_dst);
- return !STREQ(path_dst, path_src);
-}
-
-/* make sure path names are correct for OS */
-static void clean_paths(Main *main)
-{
- Scene *scene;
-
- BKE_bpath_traverse_main(main, clean_paths_visit_cb, BKE_BPATH_TRAVERSE_SKIP_MULTIFILE, NULL);
-
- for (scene = main->scene.first; scene; scene = scene->id.next) {
- BLI_path_native_slash(scene->r.pic);
- }
-}
-
-static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
-{
- wmWindow *win;
- for (win = wm->windows.first; win; win = win->next) {
- if (win->screen->scene == scene) {
- return true;
- }
- }
- return false;
-}
-
-/**
- * Context matching, handle no-ui case
- *
- * \note this is called on Undo so any slow conversion functions here
- * should be avoided or check (mode != LOAD_UNDO).
- *
- * \param bfd: Blend file data, freed by this function on exit.
- * \param filepath: File path or identifier.
- */
-static void setup_app_data(
- bContext *C, BlendFileData *bfd,
- const char *filepath, ReportList *reports)
-{
- Scene *curscene = NULL;
- const bool recover = (G.fileflags & G_FILE_RECOVER) != 0;
- enum {
- LOAD_UI = 1,
- LOAD_UI_OFF,
- LOAD_UNDO,
- } mode;
-
- if (BLI_listbase_is_empty(&bfd->main->screen)) {
- mode = LOAD_UNDO;
- }
- else if (G.fileflags & G_FILE_NO_UI) {
- mode = LOAD_UI_OFF;
- }
- else {
- mode = LOAD_UI;
- }
-
- if (mode != LOAD_UNDO) {
- /* may happen with library files */
- if (ELEM(NULL, bfd->curscreen, bfd->curscene)) {
- BKE_report(reports, RPT_WARNING, "Library file, loading empty scene");
- mode = LOAD_UI_OFF;
- }
- }
-
- /* Free all render results, without this stale data gets displayed after loading files */
- if (mode != LOAD_UNDO) {
- RE_FreeAllRenderResults();
- }
-
- /* Only make filepaths compatible when loading for real (not undo) */
- if (mode != LOAD_UNDO) {
- clean_paths(bfd->main);
- }
-
- /* XXX here the complex windowmanager matching */
-
- /* no load screens? */
- if (mode != LOAD_UI) {
- /* Logic for 'track_undo_scene' is to keep using the scene which the active screen has,
- * as long as the scene associated with the undo operation is visible in one of the open windows.
- *
- * - 'curscreen->scene' - scene the user is currently looking at.
- * - 'bfd->curscene' - scene undo-step was created in.
- *
- * This means users can have 2+ windows open and undo in both without screens switching.
- * But if they close one of the screens,
- * undo will ensure that the scene being operated on will be activated
- * (otherwise we'd be undoing on an off-screen scene which isn't acceptable).
- * see: T43424
- */
- bScreen *curscreen = NULL;
- bool track_undo_scene;
-
- /* comes from readfile.c */
- SWAP(ListBase, G.main->wm, bfd->main->wm);
- SWAP(ListBase, G.main->screen, bfd->main->screen);
-
- /* we re-use current screen */
- curscreen = CTX_wm_screen(C);
- /* but use new Scene pointer */
- curscene = bfd->curscene;
-
- track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first);
-
- if (curscene == NULL) {
- curscene = bfd->main->scene.first;
- }
- /* empty file, we add a scene to make Blender work */
- if (curscene == NULL) {
- curscene = BKE_scene_add(bfd->main, "Empty");
- }
-
- if (track_undo_scene) {
- /* keep the old (free'd) scene, let 'blo_lib_link_screen_restore'
- * replace it with 'curscene' if its needed */
- }
- else {
- /* and we enforce curscene to be in current screen */
- if (curscreen) {
- /* can run in bgmode */
- curscreen->scene = curscene;
- }
- }
-
- /* clear_global will free G.main, here we can still restore pointers */
- blo_lib_link_screen_restore(bfd->main, curscreen, curscene);
- /* curscreen might not be set when loading without ui (see T44217) so only re-assign if available */
- if (curscreen) {
- curscene = curscreen->scene;
- }
-
- if (track_undo_scene) {
- wmWindowManager *wm = bfd->main->wm.first;
- if (wm_scene_is_visible(wm, bfd->curscene) == false) {
- curscene = bfd->curscene;
- curscreen->scene = curscene;
- BKE_screen_view3d_scene_sync(curscreen);
- }
- }
- }
-
- /* free G.main Main database */
-// CTX_wm_manager_set(C, NULL);
- clear_global();
-
- /* clear old property update cache, in case some old references are left dangling */
- RNA_property_update_cache_free();
-
- G.main = bfd->main;
-
- CTX_data_main_set(C, G.main);
-
- if (bfd->user) {
-
- /* only here free userdef themes... */
- BKE_userdef_free();
-
- U = *bfd->user;
-
- /* Security issue: any blend file could include a USER block.
- *
- * Currently we load prefs from BLENDER_STARTUP_FILE and later on load BLENDER_USERPREF_FILE,
- * to load the preferences defined in the users home dir.
- *
- * This means we will never accidentally (or maliciously)
- * enable scripts auto-execution by loading a '.blend' file.
- */
- U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
-
- MEM_freeN(bfd->user);
- }
-
- /* case G_FILE_NO_UI or no screens in file */
- if (mode != LOAD_UI) {
- /* leave entire context further unaltered? */
- CTX_data_scene_set(C, curscene);
- }
- else {
- G.fileflags = bfd->fileflags;
- CTX_wm_manager_set(C, G.main->wm.first);
- CTX_wm_screen_set(C, bfd->curscreen);
- CTX_data_scene_set(C, bfd->curscene);
- CTX_wm_area_set(C, NULL);
- CTX_wm_region_set(C, NULL);
- CTX_wm_menu_set(C, NULL);
- curscene = bfd->curscene;
- }
-
- /* this can happen when active scene was lib-linked, and doesn't exist anymore */
- if (CTX_data_scene(C) == NULL) {
- /* in case we don't even have a local scene, add one */
- if (!G.main->scene.first)
- BKE_scene_add(G.main, "Empty");
-
- CTX_data_scene_set(C, G.main->scene.first);
- CTX_wm_screen(C)->scene = CTX_data_scene(C);
- curscene = CTX_data_scene(C);
- }
-
- BLI_assert(curscene == CTX_data_scene(C));
-
-
- /* special cases, override loaded flags: */
- if (G.f != bfd->globalf) {
- const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF);
- bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep);
- }
-
-
- G.f = bfd->globalf;
-
-#ifdef WITH_PYTHON
- /* let python know about new main */
- BPY_context_update(C);
-#endif
-
- /* FIXME: this version patching should really be part of the file-reading code,
- * but we still get too many unrelated data-corruption crashes otherwise... */
- if (G.main->versionfile < 250)
- do_versions_ipos_to_animato(G.main);
-
- G.main->recovered = 0;
-
- /* startup.blend or recovered startup */
- if (bfd->filename[0] == 0) {
- G.main->name[0] = 0;
- }
- else if (recover && G.relbase_valid) {
- /* in case of autosave or quit.blend, use original filename instead
- * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */
- filepath = bfd->filename;
- G.main->recovered = 1;
-
- /* these are the same at times, should never copy to the same location */
- if (G.main->name != filepath)
- BLI_strncpy(G.main->name, filepath, FILE_MAX);
- }
-
- /* baseflags, groups, make depsgraph, etc */
- /* first handle case if other windows have different scenes visible */
- if (mode == LOAD_UI) {
- wmWindowManager *wm = G.main->wm.first;
-
- if (wm) {
- wmWindow *win;
-
- for (win = wm->windows.first; win; win = win->next) {
- if (win->screen && win->screen->scene) /* zealous check... */
- if (win->screen->scene != curscene)
- BKE_scene_set_background(G.main, win->screen->scene);
- }
- }
- }
- BKE_scene_set_background(G.main, curscene);
-
- if (mode != LOAD_UNDO) {
- RE_FreeAllPersistentData();
- IMB_colormanagement_check_file_config(G.main);
- }
-
- MEM_freeN(bfd);
-
-}
-
-static int handle_subversion_warning(Main *main, ReportList *reports)
-{
- if (main->minversionfile > BLENDER_VERSION ||
- (main->minversionfile == BLENDER_VERSION &&
- main->minsubversionfile > BLENDER_SUBVERSION))
- {
- BKE_reportf(reports, RPT_ERROR, "File written by newer Blender binary (%d.%d), expect loss of data!",
- main->minversionfile, main->minsubversionfile);
- }
-
- return 1;
-}
+/***/
static void keymap_item_free(wmKeyMapItem *kmi)
{
@@ -459,7 +139,11 @@ static void keymap_item_free(wmKeyMapItem *kmi)
MEM_freeN(kmi->ptr);
}
-void BKE_userdef_free(void)
+/**
+ * When loading a new userdef from file,
+ * or when exiting Blender.
+ */
+void BKE_blender_userdef_free(void)
{
wmKeyMap *km;
wmKeyMapItem *kmi;
@@ -509,8 +193,10 @@ void BKE_userdef_free(void)
BLI_freelistN(&U.user_keymaps);
}
-/* handle changes in settings that need recalc */
-void BKE_userdef_state(void)
+/**
+ * Handle changes in settings that need refreshing.
+ */
+void BKE_blender_userdef_refresh(void)
{
/* prevent accidents */
if (U.pixelsize == 0) U.pixelsize = 1;
@@ -520,116 +206,6 @@ void BKE_userdef_state(void)
}
-int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
-{
- BlendFileData *bfd;
- int retval = BKE_READ_FILE_OK;
-
- if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL) /* don't print user-pref loading */
- printf("read blend: %s\n", filepath);
-
- bfd = BLO_read_from_file(filepath, reports);
- if (bfd) {
- if (bfd->user) retval = BKE_READ_FILE_OK_USERPREFS;
-
- if (0 == handle_subversion_warning(bfd->main, reports)) {
- BKE_main_free(bfd->main);
- MEM_freeN(bfd);
- bfd = NULL;
- retval = BKE_READ_FILE_FAIL;
- }
- else {
- setup_app_data(C, bfd, filepath, reports);
- }
- }
- else
- BKE_reports_prependf(reports, "Loading '%s' failed: ", filepath);
-
- return (bfd ? retval : BKE_READ_FILE_FAIL);
-}
-
-bool BKE_read_file_from_memory(
- bContext *C, const void *filebuf, int filelength,
- ReportList *reports, bool update_defaults)
-{
- BlendFileData *bfd;
-
- bfd = BLO_read_from_memory(filebuf, filelength, reports);
- if (bfd) {
- if (update_defaults)
- BLO_update_defaults_startup_blend(bfd->main);
- setup_app_data(C, bfd, "<memory2>", reports);
- }
- else {
- BKE_reports_prepend(reports, "Loading failed: ");
- }
-
- return (bfd != NULL);
-}
-
-/* memfile is the undo buffer */
-bool BKE_read_file_from_memfile(
- bContext *C, MemFile *memfile,
- ReportList *reports)
-{
- BlendFileData *bfd;
-
- bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports);
- if (bfd) {
- /* remove the unused screens and wm */
- while (bfd->main->wm.first)
- BKE_libblock_free_ex(bfd->main, bfd->main->wm.first, true);
- while (bfd->main->screen.first)
- BKE_libblock_free_ex(bfd->main, bfd->main->screen.first, true);
-
- setup_app_data(C, bfd, "<memory1>", reports);
- }
- else {
- BKE_reports_prepend(reports, "Loading failed: ");
- }
-
- return (bfd != NULL);
-}
-
-/* only read the userdef from a .blend */
-int BKE_read_file_userdef(const char *filepath, ReportList *reports)
-{
- BlendFileData *bfd;
- int retval = BKE_READ_FILE_FAIL;
-
- bfd = BLO_read_from_file(filepath, reports);
- if (bfd) {
- if (bfd->user) {
- retval = BKE_READ_FILE_OK_USERPREFS;
-
- /* only here free userdef themes... */
- BKE_userdef_free();
-
- U = *bfd->user;
- MEM_freeN(bfd->user);
- }
- BKE_main_free(bfd->main);
- MEM_freeN(bfd);
- }
-
- return retval;
-}
-
-/* only write the userdef in a .blend */
-int BKE_write_file_userdef(const char *filepath, ReportList *reports)
-{
- Main *mainb = MEM_callocN(sizeof(Main), "empty main");
- int retval = 0;
-
- if (BLO_write_file(mainb, filepath, G_FILE_USERPREFS, reports, NULL)) {
- retval = 1;
- }
-
- MEM_freeN(mainb);
-
- return retval;
-}
-
/* ***************** testing for break ************* */
static void (*blender_test_break_cb)(void) = NULL;
@@ -640,7 +216,7 @@ void BKE_blender_callback_test_break_set(void (*func)(void))
}
-int blender_test_break(void)
+int BKE_blender_test_break(void)
{
if (!G.background) {
if (blender_test_break_cb)
@@ -650,514 +226,3 @@ int blender_test_break(void)
return (G.is_break == true);
}
-
-/* -------------------------------------------------------------------- */
-
-/** \name Global Undo
- * \{ */
-
-#define UNDO_DISK 0
-
-typedef struct UndoElem {
- struct UndoElem *next, *prev;
- char str[FILE_MAX];
- char name[BKE_UNDO_STR_MAX];
- MemFile memfile;
- uintptr_t undosize;
-} UndoElem;
-
-static ListBase undobase = {NULL, NULL};
-static UndoElem *curundo = NULL;
-
-
-static int read_undosave(bContext *C, UndoElem *uel)
-{
- char mainstr[sizeof(G.main->name)];
- int success = 0, fileflags;
-
- /* This is needed so undoing/redoing doesn't crash with threaded previews going */
- WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C));
-
- BLI_strncpy(mainstr, G.main->name, sizeof(mainstr)); /* temporal store */
-
- fileflags = G.fileflags;
- G.fileflags |= G_FILE_NO_UI;
-
- if (UNDO_DISK)
- success = (BKE_read_file(C, uel->str, NULL) != BKE_READ_FILE_FAIL);
- else
- success = BKE_read_file_from_memfile(C, &uel->memfile, NULL);
-
- /* restore */
- BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */
- G.fileflags = fileflags;
-
- if (success) {
- /* important not to update time here, else non keyed tranforms are lost */
- DAG_on_visible_update(G.main, false);
- }
-
- return success;
-}
-
-/* name can be a dynamic string */
-void BKE_undo_write(bContext *C, const char *name)
-{
- uintptr_t maxmem, totmem, memused;
- int nr /*, success */ /* UNUSED */;
- UndoElem *uel;
-
- if ((U.uiflag & USER_GLOBALUNDO) == 0) {
- return;
- }
-
- if (U.undosteps == 0) {
- return;
- }
-
- /* remove all undos after (also when curundo == NULL) */
- while (undobase.last != curundo) {
- uel = undobase.last;
- BLI_remlink(&undobase, uel);
- BLO_memfile_free(&uel->memfile);
- MEM_freeN(uel);
- }
-
- /* make new */
- curundo = uel = MEM_callocN(sizeof(UndoElem), "undo file");
- BLI_strncpy(uel->name, name, sizeof(uel->name));
- BLI_addtail(&undobase, uel);
-
- /* and limit amount to the maximum */
- nr = 0;
- uel = undobase.last;
- while (uel) {
- nr++;
- if (nr == U.undosteps) break;
- uel = uel->prev;
- }
- if (uel) {
- while (undobase.first != uel) {
- UndoElem *first = undobase.first;
- BLI_remlink(&undobase, first);
- /* the merge is because of compression */
- BLO_memfile_merge(&first->memfile, &first->next->memfile);
- MEM_freeN(first);
- }
- }
-
-
- /* disk save version */
- if (UNDO_DISK) {
- static int counter = 0;
- char filepath[FILE_MAX];
- char numstr[32];
- int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on undo */
-
- /* calculate current filepath */
- counter++;
- counter = counter % U.undosteps;
-
- BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
- BLI_make_file_string("/", filepath, BKE_tempdir_session(), numstr);
-
- /* success = */ /* UNUSED */ BLO_write_file(CTX_data_main(C), filepath, fileflags, NULL, NULL);
-
- BLI_strncpy(curundo->str, filepath, sizeof(curundo->str));
- }
- else {
- MemFile *prevfile = NULL;
-
- if (curundo->prev) prevfile = &(curundo->prev->memfile);
-
- memused = MEM_get_memory_in_use();
- /* success = */ /* UNUSED */ BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags);
- curundo->undosize = MEM_get_memory_in_use() - memused;
- }
-
- if (U.undomemory != 0) {
- /* limit to maximum memory (afterwards, we can't know in advance) */
- totmem = 0;
- maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024;
-
- /* keep at least two (original + other) */
- uel = undobase.last;
- while (uel && uel->prev) {
- totmem += uel->undosize;
- if (totmem > maxmem) break;
- uel = uel->prev;
- }
-
- if (uel) {
- if (uel->prev && uel->prev->prev)
- uel = uel->prev;
-
- while (undobase.first != uel) {
- UndoElem *first = undobase.first;
- BLI_remlink(&undobase, first);
- /* the merge is because of compression */
- BLO_memfile_merge(&first->memfile, &first->next->memfile);
- MEM_freeN(first);
- }
- }
- }
-}
-
-/* 1 = an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */
-void BKE_undo_step(bContext *C, int step)
-{
-
- if (step == 0) {
- read_undosave(C, curundo);
- }
- else if (step == 1) {
- /* curundo should never be NULL, after restart or load file it should call undo_save */
- if (curundo == NULL || curundo->prev == NULL) {
- // XXX error("No undo available");
- }
- else {
- if (G.debug & G_DEBUG) printf("undo %s\n", curundo->name);
- curundo = curundo->prev;
- read_undosave(C, curundo);
- }
- }
- else {
- /* curundo has to remain current situation! */
-
- if (curundo == NULL || curundo->next == NULL) {
- // XXX error("No redo available");
- }
- else {
- read_undosave(C, curundo->next);
- curundo = curundo->next;
- if (G.debug & G_DEBUG) printf("redo %s\n", curundo->name);
- }
- }
-}
-
-void BKE_undo_reset(void)
-{
- UndoElem *uel;
-
- uel = undobase.first;
- while (uel) {
- BLO_memfile_free(&uel->memfile);
- uel = uel->next;
- }
-
- BLI_freelistN(&undobase);
- curundo = NULL;
-}
-
-/* based on index nr it does a restore */
-void BKE_undo_number(bContext *C, int nr)
-{
- curundo = BLI_findlink(&undobase, nr);
- BKE_undo_step(C, 0);
-}
-
-/* go back to the last occurance of name in stack */
-void BKE_undo_name(bContext *C, const char *name)
-{
- UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
-
- if (uel && uel->prev) {
- curundo = uel->prev;
- BKE_undo_step(C, 0);
- }
-}
-
-/* name optional */
-bool BKE_undo_is_valid(const char *name)
-{
- if (name) {
- UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
- return uel && uel->prev;
- }
-
- return undobase.last != undobase.first;
-}
-
-/* get name of undo item, return null if no item with this index */
-/* if active pointer, set it to 1 if true */
-const char *BKE_undo_get_name(int nr, bool *r_active)
-{
- UndoElem *uel = BLI_findlink(&undobase, nr);
-
- if (r_active) *r_active = false;
-
- if (uel) {
- if (r_active && (uel == curundo)) {
- *r_active = true;
- }
- return uel->name;
- }
- return NULL;
-}
-
-/**
- * Saves .blend using undo buffer.
- *
- * \return success.
- */
-bool BKE_undo_save_file(const char *filename)
-{
- UndoElem *uel;
- MemFileChunk *chunk;
- int file, oflags;
-
- if ((U.uiflag & USER_GLOBALUNDO) == 0) {
- return false;
- }
-
- uel = curundo;
- if (uel == NULL) {
- fprintf(stderr, "No undo buffer to save recovery file\n");
- return false;
- }
-
- /* note: This is currently used for autosave and 'quit.blend', where _not_ following symlinks is OK,
- * however if this is ever executed explicitly by the user, we may want to allow writing to symlinks.
- */
-
- oflags = O_BINARY | O_WRONLY | O_CREAT | O_TRUNC;
-#ifdef O_NOFOLLOW
- /* use O_NOFOLLOW to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
- oflags |= O_NOFOLLOW;
-#else
- /* TODO(sergey): How to deal with symlinks on windows? */
-# ifndef _MSC_VER
-# warning "Symbolic links will be followed on undo save, possibly causing CVE-2008-1103"
-# endif
-#endif
- file = BLI_open(filename, oflags, 0666);
-
- if (file == -1) {
- fprintf(stderr, "Unable to save '%s': %s\n",
- filename, errno ? strerror(errno) : "Unknown error opening file");
- return false;
- }
-
- for (chunk = uel->memfile.chunks.first; chunk; chunk = chunk->next) {
- if (write(file, chunk->buf, chunk->size) != chunk->size) {
- break;
- }
- }
-
- close(file);
-
- if (chunk) {
- fprintf(stderr, "Unable to save '%s': %s\n",
- filename, errno ? strerror(errno) : "Unknown error writing file");
- return false;
- }
- return true;
-}
-
-/* sets curscene */
-Main *BKE_undo_get_main(Scene **r_scene)
-{
- Main *mainp = NULL;
- BlendFileData *bfd = BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL);
-
- if (bfd) {
- mainp = bfd->main;
- if (r_scene) {
- *r_scene = bfd->curscene;
- }
-
- MEM_freeN(bfd);
- }
-
- return mainp;
-}
-
-/** \} */
-
-
-/* -------------------------------------------------------------------- */
-
-/** \name Partial `.blend` file save.
- * \{ */
-
-void BKE_blendfile_write_partial_begin(Main *bmain_src)
-{
- BKE_main_id_tag_all(bmain_src, LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT, false);
-}
-
-void BKE_blendfile_write_partial_tag_ID(ID *id, bool set)
-{
- if (set) {
- id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT;
- }
- else {
- id->tag &= ~(LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT);
- }
-}
-
-static void blendfile_write_partial_cb(void *UNUSED(handle), Main *UNUSED(bmain), void *vid)
-{
- if (vid) {
- ID *id = vid;
- /* only tag for need-expand if not done, prevents eternal loops */
- if ((id->tag & LIB_TAG_DOIT) == 0)
- id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT;
- }
-}
-
-/**
- * \return Success.
- */
-bool BKE_blendfile_write_partial(
- Main *bmain_src, const char *filepath, const int write_flags, ReportList *reports)
-{
- Main *bmain_dst = MEM_callocN(sizeof(Main), "copybuffer");
- ListBase *lbarray_dst[MAX_LIBARRAY], *lbarray_src[MAX_LIBARRAY];
- int a, retval;
-
- void *path_list_backup = NULL;
- const int path_list_flag = (BKE_BPATH_TRAVERSE_SKIP_LIBRARY | BKE_BPATH_TRAVERSE_SKIP_MULTIFILE);
-
- if (write_flags & G_FILE_RELATIVE_REMAP) {
- path_list_backup = BKE_bpath_list_backup(bmain_src, path_list_flag);
- }
-
- BLO_main_expander(blendfile_write_partial_cb);
- BLO_expand_main(NULL, bmain_src);
-
- /* move over all tagged blocks */
- set_listbasepointers(bmain_src, lbarray_src);
- a = set_listbasepointers(bmain_dst, lbarray_dst);
- while (a--) {
- ID *id, *nextid;
- ListBase *lb_dst = lbarray_dst[a], *lb_src = lbarray_src[a];
-
- for (id = lb_src->first; id; id = nextid) {
- nextid = id->next;
- if (id->tag & LIB_TAG_DOIT) {
- BLI_remlink(lb_src, id);
- BLI_addtail(lb_dst, id);
- }
- }
- }
-
-
- /* save the buffer */
- retval = BLO_write_file(bmain_dst, filepath, write_flags, reports, NULL);
-
- /* move back the main, now sorted again */
- set_listbasepointers(bmain_src, lbarray_dst);
- a = set_listbasepointers(bmain_dst, lbarray_src);
- while (a--) {
- ID *id;
- ListBase *lb_dst = lbarray_dst[a], *lb_src = lbarray_src[a];
-
- while ((id = BLI_pophead(lb_src))) {
- BLI_addtail(lb_dst, id);
- id_sort_by_name(lb_dst, id);
- }
- }
-
- MEM_freeN(bmain_dst);
-
- if (path_list_backup) {
- BKE_bpath_list_restore(bmain_src, path_list_flag, path_list_backup);
- BKE_bpath_list_free(path_list_backup);
- }
-
- return retval;
-}
-
-void BKE_blendfile_write_partial_end(Main *bmain_src)
-{
- BKE_main_id_tag_all(bmain_src, LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT, false);
-}
-
-/** \} */
-
-
-/* -------------------------------------------------------------------- */
-
-/** \name Copy/Paste `.blend`, partial saves.
- * \{ */
-
-void BKE_copybuffer_begin(Main *bmain_src)
-{
- BKE_blendfile_write_partial_begin(bmain_src);
-}
-
-void BKE_copybuffer_tag_ID(ID *id)
-{
- BKE_blendfile_write_partial_tag_ID(id, true);
-}
-
-/**
- * \return Success.
- */
-bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *reports)
-{
- const int write_flags = G_FILE_RELATIVE_REMAP;
-
- bool retval = BKE_blendfile_write_partial(bmain_src, filename, write_flags, reports);
-
- BKE_blendfile_write_partial_end(bmain_src);
-
- return retval;
-}
-
-/**
- * \return Success.
- */
-bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, ReportList *reports)
-{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
- Main *mainl = NULL;
- Library *lib;
- BlendHandle *bh;
-
- bh = BLO_blendhandle_from_file(libname, reports);
-
- if (bh == NULL) {
- /* error reports will have been made by BLO_blendhandle_from_file() */
- return false;
- }
-
- BKE_scene_base_deselect_all(scene);
-
- /* tag everything, all untagged data can be made local
- * its also generally useful to know what is new
- *
- * take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */
- BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
-
- /* here appending/linking starts */
- mainl = BLO_library_link_begin(bmain, &bh, libname);
-
- BLO_library_link_copypaste(mainl, bh);
-
- BLO_library_link_end(mainl, &bh, flag, scene, v3d);
-
- /* mark all library linked objects to be updated */
- BKE_main_lib_objects_recalc_all(bmain);
- IMB_colormanagement_check_file_config(bmain);
-
- /* append, rather than linking */
- lib = BLI_findstring(&bmain->library, libname, offsetof(Library, filepath));
- BKE_library_make_local(bmain, lib, true, false);
-
- /* important we unset, otherwise these object wont
- * link into other scenes from this blend file */
- BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
-
- /* recreate dependency graph to include new objects */
- DAG_relations_tag_update(bmain);
-
- BLO_blendhandle_close(bh);
- /* remove library... */
-
- return true;
-}
-
-/** \} */
diff --git a/source/blender/blenkernel/intern/blender_copybuffer.c b/source/blender/blenkernel/intern/blender_copybuffer.c
new file mode 100644
index 00000000000..ad01fac2144
--- /dev/null
+++ b/source/blender/blenkernel/intern/blender_copybuffer.c
@@ -0,0 +1,143 @@
+/*
+ * ***** 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 *****
+ */
+
+/** \file blender/blenkernel/intern/blender_copybuffer.c
+ * \ingroup bke
+ *
+ * Used for copy/paste operator, (using a temporary file).
+ */
+
+#include <stdlib.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_userdef_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+#include "BLI_callbacks.h"
+
+#include "IMB_imbuf.h"
+#include "IMB_moviecache.h"
+
+#include "BKE_blender_copybuffer.h" /* own include */
+#include "BKE_blendfile.h"
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+
+#include "BLO_readfile.h"
+#include "BLO_writefile.h"
+
+#include "IMB_colormanagement.h"
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Copy/Paste `.blend`, partial saves.
+ * \{ */
+
+void BKE_copybuffer_begin(Main *bmain_src)
+{
+ BKE_blendfile_write_partial_begin(bmain_src);
+}
+
+void BKE_copybuffer_tag_ID(ID *id)
+{
+ BKE_blendfile_write_partial_tag_ID(id, true);
+}
+
+/**
+ * \return Success.
+ */
+bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *reports)
+{
+ const int write_flags = G_FILE_RELATIVE_REMAP;
+
+ bool retval = BKE_blendfile_write_partial(bmain_src, filename, write_flags, reports);
+
+ BKE_blendfile_write_partial_end(bmain_src);
+
+ return retval;
+}
+
+/**
+ * \return Success.
+ */
+bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, ReportList *reports)
+{
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ Main *mainl = NULL;
+ Library *lib;
+ BlendHandle *bh;
+
+ bh = BLO_blendhandle_from_file(libname, reports);
+
+ if (bh == NULL) {
+ /* error reports will have been made by BLO_blendhandle_from_file() */
+ return false;
+ }
+
+ BKE_scene_base_deselect_all(scene);
+
+ /* tag everything, all untagged data can be made local
+ * its also generally useful to know what is new
+ *
+ * take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */
+ BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
+
+ /* here appending/linking starts */
+ mainl = BLO_library_link_begin(bmain, &bh, libname);
+
+ BLO_library_link_copypaste(mainl, bh);
+
+ BLO_library_link_end(mainl, &bh, flag, scene, v3d);
+
+ /* mark all library linked objects to be updated */
+ BKE_main_lib_objects_recalc_all(bmain);
+ IMB_colormanagement_check_file_config(bmain);
+
+ /* append, rather than linking */
+ lib = BLI_findstring(&bmain->library, libname, offsetof(Library, filepath));
+ BKE_library_make_local(bmain, lib, true, false);
+
+ /* important we unset, otherwise these object wont
+ * link into other scenes from this blend file */
+ BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
+
+ /* recreate dependency graph to include new objects */
+ DAG_relations_tag_update(bmain);
+
+ BLO_blendhandle_close(bh);
+ /* remove library... */
+
+ return true;
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c
new file mode 100644
index 00000000000..ca0a1b91cea
--- /dev/null
+++ b/source/blender/blenkernel/intern/blender_undo.c
@@ -0,0 +1,393 @@
+/*
+ * ***** 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 *****
+ */
+
+/** \file blender/blenkernel/intern/blender_undo.c
+ * \ingroup bke
+ *
+ * Blend file undo (known as 'Global Undo').
+ * DNA level diffing for undo.
+ */
+
+#ifndef _WIN32
+# include <unistd.h> // for read close
+#else
+# include <io.h> // for open close read
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <fcntl.h> /* for open */
+#include <errno.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+
+#include "BLI_fileops.h"
+#include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#include "IMB_imbuf.h"
+#include "IMB_moviecache.h"
+
+#include "BKE_blender_undo.h" /* own include */
+#include "BKE_blendfile.h"
+#include "BKE_appdir.h"
+#include "BKE_brush.h"
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_image.h"
+#include "BKE_main.h"
+#include "RE_pipeline.h"
+
+#include "BLO_undofile.h"
+#include "BLO_readfile.h"
+#include "BLO_writefile.h"
+
+#include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - remove asap, elubie
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Global Undo
+ * \{ */
+
+#define UNDO_DISK 0
+
+typedef struct UndoElem {
+ struct UndoElem *next, *prev;
+ char str[FILE_MAX];
+ char name[BKE_UNDO_STR_MAX];
+ MemFile memfile;
+ uintptr_t undosize;
+} UndoElem;
+
+static ListBase undobase = {NULL, NULL};
+static UndoElem *curundo = NULL;
+
+
+static int read_undosave(bContext *C, UndoElem *uel)
+{
+ char mainstr[sizeof(G.main->name)];
+ int success = 0, fileflags;
+
+ /* This is needed so undoing/redoing doesn't crash with threaded previews going */
+ WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C));
+
+ BLI_strncpy(mainstr, G.main->name, sizeof(mainstr)); /* temporal store */
+
+ fileflags = G.fileflags;
+ G.fileflags |= G_FILE_NO_UI;
+
+ if (UNDO_DISK)
+ success = (BKE_blendfile_read(C, uel->str, NULL) != BKE_BLENDFILE_READ_FAIL);
+ else
+ success = BKE_blendfile_read_from_memfile(C, &uel->memfile, NULL);
+
+ /* restore */
+ BLI_strncpy(G.main->name, mainstr, sizeof(G.main->name)); /* restore */
+ G.fileflags = fileflags;
+
+ if (success) {
+ /* important not to update time here, else non keyed tranforms are lost */
+ DAG_on_visible_update(G.main, false);
+ }
+
+ return success;
+}
+
+/* name can be a dynamic string */
+void BKE_undo_write(bContext *C, const char *name)
+{
+ uintptr_t maxmem, totmem, memused;
+ int nr /*, success */ /* UNUSED */;
+ UndoElem *uel;
+
+ if ((U.uiflag & USER_GLOBALUNDO) == 0) {
+ return;
+ }
+
+ if (U.undosteps == 0) {
+ return;
+ }
+
+ /* remove all undos after (also when curundo == NULL) */
+ while (undobase.last != curundo) {
+ uel = undobase.last;
+ BLI_remlink(&undobase, uel);
+ BLO_memfile_free(&uel->memfile);
+ MEM_freeN(uel);
+ }
+
+ /* make new */
+ curundo = uel = MEM_callocN(sizeof(UndoElem), "undo file");
+ BLI_strncpy(uel->name, name, sizeof(uel->name));
+ BLI_addtail(&undobase, uel);
+
+ /* and limit amount to the maximum */
+ nr = 0;
+ uel = undobase.last;
+ while (uel) {
+ nr++;
+ if (nr == U.undosteps) break;
+ uel = uel->prev;
+ }
+ if (uel) {
+ while (undobase.first != uel) {
+ UndoElem *first = undobase.first;
+ BLI_remlink(&undobase, first);
+ /* the merge is because of compression */
+ BLO_memfile_merge(&first->memfile, &first->next->memfile);
+ MEM_freeN(first);
+ }
+ }
+
+
+ /* disk save version */
+ if (UNDO_DISK) {
+ static int counter = 0;
+ char filepath[FILE_MAX];
+ char numstr[32];
+ int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on undo */
+
+ /* calculate current filepath */
+ counter++;
+ counter = counter % U.undosteps;
+
+ BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
+ BLI_make_file_string("/", filepath, BKE_tempdir_session(), numstr);
+
+ /* success = */ /* UNUSED */ BLO_write_file(CTX_data_main(C), filepath, fileflags, NULL, NULL);
+
+ BLI_strncpy(curundo->str, filepath, sizeof(curundo->str));
+ }
+ else {
+ MemFile *prevfile = NULL;
+
+ if (curundo->prev) prevfile = &(curundo->prev->memfile);
+
+ memused = MEM_get_memory_in_use();
+ /* success = */ /* UNUSED */ BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags);
+ curundo->undosize = MEM_get_memory_in_use() - memused;
+ }
+
+ if (U.undomemory != 0) {
+ /* limit to maximum memory (afterwards, we can't know in advance) */
+ totmem = 0;
+ maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024;
+
+ /* keep at least two (original + other) */
+ uel = undobase.last;
+ while (uel && uel->prev) {
+ totmem += uel->undosize;
+ if (totmem > maxmem) break;
+ uel = uel->prev;
+ }
+
+ if (uel) {
+ if (uel->prev && uel->prev->prev)
+ uel = uel->prev;
+
+ while (undobase.first != uel) {
+ UndoElem *first = undobase.first;
+ BLI_remlink(&undobase, first);
+ /* the merge is because of compression */
+ BLO_memfile_merge(&first->memfile, &first->next->memfile);
+ MEM_freeN(first);
+ }
+ }
+ }
+}
+
+/* 1 = an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */
+void BKE_undo_step(bContext *C, int step)
+{
+
+ if (step == 0) {
+ read_undosave(C, curundo);
+ }
+ else if (step == 1) {
+ /* curundo should never be NULL, after restart or load file it should call undo_save */
+ if (curundo == NULL || curundo->prev == NULL) {
+ // XXX error("No undo available");
+ }
+ else {
+ if (G.debug & G_DEBUG) printf("undo %s\n", curundo->name);
+ curundo = curundo->prev;
+ read_undosave(C, curundo);
+ }
+ }
+ else {
+ /* curundo has to remain current situation! */
+
+ if (curundo == NULL || curundo->next == NULL) {
+ // XXX error("No redo available");
+ }
+ else {
+ read_undosave(C, curundo->next);
+ curundo = curundo->next;
+ if (G.debug & G_DEBUG) printf("redo %s\n", curundo->name);
+ }
+ }
+}
+
+void BKE_undo_reset(void)
+{
+ UndoElem *uel;
+
+ uel = undobase.first;
+ while (uel) {
+ BLO_memfile_free(&uel->memfile);
+ uel = uel->next;
+ }
+
+ BLI_freelistN(&undobase);
+ curundo = NULL;
+}
+
+/* based on index nr it does a restore */
+void BKE_undo_number(bContext *C, int nr)
+{
+ curundo = BLI_findlink(&undobase, nr);
+ BKE_undo_step(C, 0);
+}
+
+/* go back to the last occurance of name in stack */
+void BKE_undo_name(bContext *C, const char *name)
+{
+ UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
+
+ if (uel && uel->prev) {
+ curundo = uel->prev;
+ BKE_undo_step(C, 0);
+ }
+}
+
+/* name optional */
+bool BKE_undo_is_valid(const char *name)
+{
+ if (name) {
+ UndoElem *uel = BLI_rfindstring(&undobase, name, offsetof(UndoElem, name));
+ return uel && uel->prev;
+ }
+
+ return undobase.last != undobase.first;
+}
+
+/* get name of undo item, return null if no item with this index */
+/* if active pointer, set it to 1 if true */
+const char *BKE_undo_get_name(int nr, bool *r_active)
+{
+ UndoElem *uel = BLI_findlink(&undobase, nr);
+
+ if (r_active) *r_active = false;
+
+ if (uel) {
+ if (r_active && (uel == curundo)) {
+ *r_active = true;
+ }
+ return uel->name;
+ }
+ return NULL;
+}
+
+/**
+ * Saves .blend using undo buffer.
+ *
+ * \return success.
+ */
+bool BKE_undo_save_file(const char *filename)
+{
+ UndoElem *uel;
+ MemFileChunk *chunk;
+ int file, oflags;
+
+ if ((U.uiflag & USER_GLOBALUNDO) == 0) {
+ return false;
+ }
+
+ uel = curundo;
+ if (uel == NULL) {
+ fprintf(stderr, "No undo buffer to save recovery file\n");
+ return false;
+ }
+
+ /* note: This is currently used for autosave and 'quit.blend', where _not_ following symlinks is OK,
+ * however if this is ever executed explicitly by the user, we may want to allow writing to symlinks.
+ */
+
+ oflags = O_BINARY | O_WRONLY | O_CREAT | O_TRUNC;
+#ifdef O_NOFOLLOW
+ /* use O_NOFOLLOW to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */
+ oflags |= O_NOFOLLOW;
+#else
+ /* TODO(sergey): How to deal with symlinks on windows? */
+# ifndef _MSC_VER
+# warning "Symbolic links will be followed on undo save, possibly causing CVE-2008-1103"
+# endif
+#endif
+ file = BLI_open(filename, oflags, 0666);
+
+ if (file == -1) {
+ fprintf(stderr, "Unable to save '%s': %s\n",
+ filename, errno ? strerror(errno) : "Unknown error opening file");
+ return false;
+ }
+
+ for (chunk = uel->memfile.chunks.first; chunk; chunk = chunk->next) {
+ if (write(file, chunk->buf, chunk->size) != chunk->size) {
+ break;
+ }
+ }
+
+ close(file);
+
+ if (chunk) {
+ fprintf(stderr, "Unable to save '%s': %s\n",
+ filename, errno ? strerror(errno) : "Unknown error writing file");
+ return false;
+ }
+ return true;
+}
+
+/* sets curscene */
+Main *BKE_undo_get_main(Scene **r_scene)
+{
+ Main *mainp = NULL;
+ BlendFileData *bfd = BLO_read_from_memfile(G.main, G.main->name, &curundo->memfile, NULL);
+
+ if (bfd) {
+ mainp = bfd->main;
+ if (r_scene) {
+ *r_scene = bfd->curscene;
+ }
+
+ MEM_freeN(bfd);
+ }
+
+ return mainp;
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
new file mode 100644
index 00000000000..4605a12f9a0
--- /dev/null
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -0,0 +1,566 @@
+/*
+ * ***** 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 *****
+ */
+
+/** \file blender/blenkernel/intern/blendfile.c
+ * \ingroup bke
+ *
+ * High level `.blend` file read/write,
+ * and functions for writing *partial* files (only selected data-blocks).
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_path_util.h"
+#include "BLI_utildefines.h"
+
+#include "IMB_colormanagement.h"
+
+#include "BKE_appdir.h"
+#include "BKE_blender.h"
+#include "BKE_blender_version.h"
+#include "BKE_blendfile.h"
+#include "BKE_bpath.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_ipo.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+
+#include "BLO_readfile.h"
+#include "BLO_writefile.h"
+
+#include "RNA_access.h"
+
+#include "RE_pipeline.h"
+
+#ifdef WITH_PYTHON
+# include "BPY_extern.h"
+#endif
+
+/* -------------------------------------------------------------------- */
+
+/** \name High Level `.blend` file read/write.
+ * \{ */
+
+static bool clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src)
+{
+ strcpy(path_dst, path_src);
+ BLI_path_native_slash(path_dst);
+ return !STREQ(path_dst, path_src);
+}
+
+/* make sure path names are correct for OS */
+static void clean_paths(Main *main)
+{
+ Scene *scene;
+
+ BKE_bpath_traverse_main(main, clean_paths_visit_cb, BKE_BPATH_TRAVERSE_SKIP_MULTIFILE, NULL);
+
+ for (scene = main->scene.first; scene; scene = scene->id.next) {
+ BLI_path_native_slash(scene->r.pic);
+ }
+}
+
+static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
+{
+ wmWindow *win;
+ for (win = wm->windows.first; win; win = win->next) {
+ if (win->screen->scene == scene) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Context matching, handle no-ui case
+ *
+ * \note this is called on Undo so any slow conversion functions here
+ * should be avoided or check (mode != LOAD_UNDO).
+ *
+ * \param bfd: Blend file data, freed by this function on exit.
+ * \param filepath: File path or identifier.
+ */
+static void setup_app_data(
+ bContext *C, BlendFileData *bfd,
+ const char *filepath, ReportList *reports)
+{
+ Scene *curscene = NULL;
+ const bool recover = (G.fileflags & G_FILE_RECOVER) != 0;
+ enum {
+ LOAD_UI = 1,
+ LOAD_UI_OFF,
+ LOAD_UNDO,
+ } mode;
+
+ if (BLI_listbase_is_empty(&bfd->main->screen)) {
+ mode = LOAD_UNDO;
+ }
+ else if (G.fileflags & G_FILE_NO_UI) {
+ mode = LOAD_UI_OFF;
+ }
+ else {
+ mode = LOAD_UI;
+ }
+
+ if (mode != LOAD_UNDO) {
+ /* may happen with library files */
+ if (ELEM(NULL, bfd->curscreen, bfd->curscene)) {
+ BKE_report(reports, RPT_WARNING, "Library file, loading empty scene");
+ mode = LOAD_UI_OFF;
+ }
+ }
+
+ /* Free all render results, without this stale data gets displayed after loading files */
+ if (mode != LOAD_UNDO) {
+ RE_FreeAllRenderResults();
+ }
+
+ /* Only make filepaths compatible when loading for real (not undo) */
+ if (mode != LOAD_UNDO) {
+ clean_paths(bfd->main);
+ }
+
+ /* XXX here the complex windowmanager matching */
+
+ /* no load screens? */
+ if (mode != LOAD_UI) {
+ /* Logic for 'track_undo_scene' is to keep using the scene which the active screen has,
+ * as long as the scene associated with the undo operation is visible in one of the open windows.
+ *
+ * - 'curscreen->scene' - scene the user is currently looking at.
+ * - 'bfd->curscene' - scene undo-step was created in.
+ *
+ * This means users can have 2+ windows open and undo in both without screens switching.
+ * But if they close one of the screens,
+ * undo will ensure that the scene being operated on will be activated
+ * (otherwise we'd be undoing on an off-screen scene which isn't acceptable).
+ * see: T43424
+ */
+ bScreen *curscreen = NULL;
+ bool track_undo_scene;
+
+ /* comes from readfile.c */
+ SWAP(ListBase, G.main->wm, bfd->main->wm);
+ SWAP(ListBase, G.main->screen, bfd->main->screen);
+
+ /* we re-use current screen */
+ curscreen = CTX_wm_screen(C);
+ /* but use new Scene pointer */
+ curscene = bfd->curscene;
+
+ track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first);
+
+ if (curscene == NULL) {
+ curscene = bfd->main->scene.first;
+ }
+ /* empty file, we add a scene to make Blender work */
+ if (curscene == NULL) {
+ curscene = BKE_scene_add(bfd->main, "Empty");
+ }
+
+ if (track_undo_scene) {
+ /* keep the old (free'd) scene, let 'blo_lib_link_screen_restore'
+ * replace it with 'curscene' if its needed */
+ }
+ else {
+ /* and we enforce curscene to be in current screen */
+ if (curscreen) {
+ /* can run in bgmode */
+ curscreen->scene = curscene;
+ }
+ }
+
+ /* BKE_blender_globals_clear will free G.main, here we can still restore pointers */
+ blo_lib_link_screen_restore(bfd->main, curscreen, curscene);
+ /* curscreen might not be set when loading without ui (see T44217) so only re-assign if available */
+ if (curscreen) {
+ curscene = curscreen->scene;
+ }
+
+ if (track_undo_scene) {
+ wmWindowManager *wm = bfd->main->wm.first;
+ if (wm_scene_is_visible(wm, bfd->curscene) == false) {
+ curscene = bfd->curscene;
+ curscreen->scene = curscene;
+ BKE_screen_view3d_scene_sync(curscreen);
+ }
+ }
+ }
+
+ /* free G.main Main database */
+// CTX_wm_manager_set(C, NULL);
+ BKE_blender_globals_clear();
+
+ /* clear old property update cache, in case some old references are left dangling */
+ RNA_property_update_cache_free();
+
+ G.main = bfd->main;
+
+ CTX_data_main_set(C, G.main);
+
+ if (bfd->user) {
+
+ /* only here free userdef themes... */
+ BKE_blender_userdef_free();
+
+ U = *bfd->user;
+
+ /* Security issue: any blend file could include a USER block.
+ *
+ * Currently we load prefs from BLENDER_STARTUP_FILE and later on load BLENDER_USERPREF_FILE,
+ * to load the preferences defined in the users home dir.
+ *
+ * This means we will never accidentally (or maliciously)
+ * enable scripts auto-execution by loading a '.blend' file.
+ */
+ U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
+
+ MEM_freeN(bfd->user);
+ }
+
+ /* case G_FILE_NO_UI or no screens in file */
+ if (mode != LOAD_UI) {
+ /* leave entire context further unaltered? */
+ CTX_data_scene_set(C, curscene);
+ }
+ else {
+ G.fileflags = bfd->fileflags;
+ CTX_wm_manager_set(C, G.main->wm.first);
+ CTX_wm_screen_set(C, bfd->curscreen);
+ CTX_data_scene_set(C, bfd->curscene);
+ CTX_wm_area_set(C, NULL);
+ CTX_wm_region_set(C, NULL);
+ CTX_wm_menu_set(C, NULL);
+ curscene = bfd->curscene;
+ }
+
+ /* this can happen when active scene was lib-linked, and doesn't exist anymore */
+ if (CTX_data_scene(C) == NULL) {
+ /* in case we don't even have a local scene, add one */
+ if (!G.main->scene.first)
+ BKE_scene_add(G.main, "Empty");
+
+ CTX_data_scene_set(C, G.main->scene.first);
+ CTX_wm_screen(C)->scene = CTX_data_scene(C);
+ curscene = CTX_data_scene(C);
+ }
+
+ BLI_assert(curscene == CTX_data_scene(C));
+
+
+ /* special cases, override loaded flags: */
+ if (G.f != bfd->globalf) {
+ const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF);
+ bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep);
+ }
+
+
+ G.f = bfd->globalf;
+
+#ifdef WITH_PYTHON
+ /* let python know about new main */
+ BPY_context_update(C);
+#endif
+
+ /* FIXME: this version patching should really be part of the file-reading code,
+ * but we still get too many unrelated data-corruption crashes otherwise... */
+ if (G.main->versionfile < 250)
+ do_versions_ipos_to_animato(G.main);
+
+ G.main->recovered = 0;
+
+ /* startup.blend or recovered startup */
+ if (bfd->filename[0] == 0) {
+ G.main->name[0] = 0;
+ }
+ else if (recover && G.relbase_valid) {
+ /* in case of autosave or quit.blend, use original filename instead
+ * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */
+ filepath = bfd->filename;
+ G.main->recovered = 1;
+
+ /* these are the same at times, should never copy to the same location */
+ if (G.main->name != filepath)
+ BLI_strncpy(G.main->name, filepath, FILE_MAX);
+ }
+
+ /* baseflags, groups, make depsgraph, etc */
+ /* first handle case if other windows have different scenes visible */
+ if (mode == LOAD_UI) {
+ wmWindowManager *wm = G.main->wm.first;
+
+ if (wm) {
+ wmWindow *win;
+
+ for (win = wm->windows.first; win; win = win->next) {
+ if (win->screen && win->screen->scene) /* zealous check... */
+ if (win->screen->scene != curscene)
+ BKE_scene_set_background(G.main, win->screen->scene);
+ }
+ }
+ }
+ BKE_scene_set_background(G.main, curscene);
+
+ if (mode != LOAD_UNDO) {
+ RE_FreeAllPersistentData();
+ IMB_colormanagement_check_file_config(G.main);
+ }
+
+ MEM_freeN(bfd);
+
+}
+
+static int handle_subversion_warning(Main *main, ReportList *reports)
+{
+ if (main->minversionfile > BLENDER_VERSION ||
+ (main->minversionfile == BLENDER_VERSION &&
+ main->minsubversionfile > BLENDER_SUBVERSION))
+ {
+ BKE_reportf(reports, RPT_ERROR, "File written by newer Blender binary (%d.%d), expect loss of data!",
+ main->minversionfile, main->minsubversionfile);
+ }
+
+ return 1;
+}
+
+int BKE_blendfile_read(bContext *C, const char *filepath, ReportList *reports)
+{
+ BlendFileData *bfd;
+ int retval = BKE_BLENDFILE_READ_OK;
+
+ if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL) /* don't print user-pref loading */
+ printf("read blend: %s\n", filepath);
+
+ bfd = BLO_read_from_file(filepath, reports);
+ if (bfd) {
+ if (bfd->user) retval = BKE_BLENDFILE_READ_OK_USERPREFS;
+
+ if (0 == handle_subversion_warning(bfd->main, reports)) {
+ BKE_main_free(bfd->main);
+ MEM_freeN(bfd);
+ bfd = NULL;
+ retval = BKE_BLENDFILE_READ_FAIL;
+ }
+ else {
+ setup_app_data(C, bfd, filepath, reports);
+ }
+ }
+ else
+ BKE_reports_prependf(reports, "Loading '%s' failed: ", filepath);
+
+ return (bfd ? retval : BKE_BLENDFILE_READ_FAIL);
+}
+
+bool BKE_blendfile_read_from_memory(
+ bContext *C, const void *filebuf, int filelength,
+ ReportList *reports, bool update_defaults)
+{
+ BlendFileData *bfd;
+
+ bfd = BLO_read_from_memory(filebuf, filelength, reports);
+ if (bfd) {
+ if (update_defaults)
+ BLO_update_defaults_startup_blend(bfd->main);
+ setup_app_data(C, bfd, "<memory2>", reports);
+ }
+ else {
+ BKE_reports_prepend(reports, "Loading failed: ");
+ }
+
+ return (bfd != NULL);
+}
+
+/* memfile is the undo buffer */
+bool BKE_blendfile_read_from_memfile(
+ bContext *C, struct MemFile *memfile,
+ ReportList *reports)
+{
+ BlendFileData *bfd;
+
+ bfd = BLO_read_from_memfile(CTX_data_main(C), G.main->name, memfile, reports);
+ if (bfd) {
+ /* remove the unused screens and wm */
+ while (bfd->main->wm.first)
+ BKE_libblock_free_ex(bfd->main, bfd->main->wm.first, true);
+ while (bfd->main->screen.first)
+ BKE_libblock_free_ex(bfd->main, bfd->main->screen.first, true);
+
+ setup_app_data(C, bfd, "<memory1>", reports);
+ }
+ else {
+ BKE_reports_prepend(reports, "Loading failed: ");
+ }
+
+ return (bfd != NULL);
+}
+
+/* only read the userdef from a .blend */
+int BKE_blendfile_read_userdef(const char *filepath, ReportList *reports)
+{
+ BlendFileData *bfd;
+ int retval = BKE_BLENDFILE_READ_FAIL;
+
+ bfd = BLO_read_from_file(filepath, reports);
+ if (bfd) {
+ if (bfd->user) {
+ retval = BKE_BLENDFILE_READ_OK_USERPREFS;
+
+ /* only here free userdef themes... */
+ BKE_blender_userdef_free();
+
+ U = *bfd->user;
+ MEM_freeN(bfd->user);
+ }
+ BKE_main_free(bfd->main);
+ MEM_freeN(bfd);
+ }
+
+ return retval;
+}
+
+/* only write the userdef in a .blend */
+int BKE_blendfile_write_userdef(const char *filepath, ReportList *reports)
+{
+ Main *mainb = MEM_callocN(sizeof(Main), "empty main");
+ int retval = 0;
+
+ if (BLO_write_file(mainb, filepath, G_FILE_USERPREFS, reports, NULL)) {
+ retval = 1;
+ }
+
+ MEM_freeN(mainb);
+
+ return retval;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Partial `.blend` file save.
+ * \{ */
+
+void BKE_blendfile_write_partial_begin(Main *bmain_src)
+{
+ BKE_main_id_tag_all(bmain_src, LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT, false);
+}
+
+void BKE_blendfile_write_partial_tag_ID(ID *id, bool set)
+{
+ if (set) {
+ id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT;
+ }
+ else {
+ id->tag &= ~(LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT);
+ }
+}
+
+static void blendfile_write_partial_cb(void *UNUSED(handle), Main *UNUSED(bmain), void *vid)
+{
+ if (vid) {
+ ID *id = vid;
+ /* only tag for need-expand if not done, prevents eternal loops */
+ if ((id->tag & LIB_TAG_DOIT) == 0)
+ id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT;
+ }
+}
+
+/**
+ * \return Success.
+ */
+bool BKE_blendfile_write_partial(
+ Main *bmain_src, const char *filepath, const int write_flags, ReportList *reports)
+{
+ Main *bmain_dst = MEM_callocN(sizeof(Main), "copybuffer");
+ ListBase *lbarray_dst[MAX_LIBARRAY], *lbarray_src[MAX_LIBARRAY];
+ int a, retval;
+
+ void *path_list_backup = NULL;
+ const int path_list_flag = (BKE_BPATH_TRAVERSE_SKIP_LIBRARY | BKE_BPATH_TRAVERSE_SKIP_MULTIFILE);
+
+ if (write_flags & G_FILE_RELATIVE_REMAP) {
+ path_list_backup = BKE_bpath_list_backup(bmain_src, path_list_flag);
+ }
+
+ BLO_main_expander(blendfile_write_partial_cb);
+ BLO_expand_main(NULL, bmain_src);
+
+ /* move over all tagged blocks */
+ set_listbasepointers(bmain_src, lbarray_src);
+ a = set_listbasepointers(bmain_dst, lbarray_dst);
+ while (a--) {
+ ID *id, *nextid;
+ ListBase *lb_dst = lbarray_dst[a], *lb_src = lbarray_src[a];
+
+ for (id = lb_src->first; id; id = nextid) {
+ nextid = id->next;
+ if (id->tag & LIB_TAG_DOIT) {
+ BLI_remlink(lb_src, id);
+ BLI_addtail(lb_dst, id);
+ }
+ }
+ }
+
+
+ /* save the buffer */
+ retval = BLO_write_file(bmain_dst, filepath, write_flags, reports, NULL);
+
+ /* move back the main, now sorted again */
+ set_listbasepointers(bmain_src, lbarray_dst);
+ a = set_listbasepointers(bmain_dst, lbarray_src);
+ while (a--) {
+ ID *id;
+ ListBase *lb_dst = lbarray_dst[a], *lb_src = lbarray_src[a];
+
+ while ((id = BLI_pophead(lb_src))) {
+ BLI_addtail(lb_dst, id);
+ id_sort_by_name(lb_dst, id);
+ }
+ }
+
+ MEM_freeN(bmain_dst);
+
+ if (path_list_backup) {
+ BKE_bpath_list_restore(bmain_src, path_list_flag, path_list_backup);
+ BKE_bpath_list_free(path_list_backup);
+ }
+
+ return retval;
+}
+
+void BKE_blendfile_write_partial_end(Main *bmain_src)
+{
+ BKE_main_id_tag_all(bmain_src, LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT, false);
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 519b7b44637..e6741657f47 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1049,11 +1049,13 @@ static void cdDM_drawMappedFacesGLSL(
numdata++;
}
}
- if (matconv[a].attribs.tottang && matconv[a].attribs.tang.array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.tang.gl_index;
- matconv[a].datatypes[numdata].size = 4;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
+ for (b = 0; b < matconv[a].attribs.tottang; b++) {
+ if (matconv[a].attribs.tang[b].array) {
+ matconv[a].datatypes[numdata].index = matconv[a].attribs.tang[b].gl_index;
+ matconv[a].datatypes[numdata].size = 4;
+ matconv[a].datatypes[numdata].type = GL_FLOAT;
+ numdata++;
+ }
}
if (numdata != 0) {
matconv[a].numdata = numdata;
@@ -1105,11 +1107,13 @@ static void cdDM_drawMappedFacesGLSL(
offset += sizeof(unsigned char) * 4;
}
}
- if (matconv[i].attribs.tottang && matconv[i].attribs.tang.array) {
- const float (*looptang)[4] = (const float (*)[4])matconv[i].attribs.tang.array;
- for (j = 0; j < mpoly->totloop; j++)
- copy_v4_v4((float *)&varray[offset + j * max_element_size], looptang[mpoly->loopstart + j]);
- offset += sizeof(float) * 4;
+ for (b = 0; b < matconv[i].attribs.tottang; b++) {
+ if (matconv[i].attribs.tottang && matconv[i].attribs.tang[b].array) {
+ const float (*looptang)[4] = (const float (*)[4])matconv[i].attribs.tang[b].array;
+ for (j = 0; j < mpoly->totloop; j++)
+ copy_v4_v4((float *)&varray[offset + j * max_element_size], looptang[mpoly->loopstart + j]);
+ offset += sizeof(float) * 4;
+ }
}
}
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index dabe606fa55..1b9ac499e1f 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3523,8 +3523,6 @@ static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra
free_bvhtree_from_mesh(&treeData);
- target->release(target);
-
if (fail == true) {
/* Don't move the point */
zero_v3(co);
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index a12d5434b30..b0d0dc08126 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1259,7 +1259,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerDefault_mloopcol, layerEqual_mloopcol, layerMultiply_mloopcol, layerInitMinMax_mloopcol,
layerAdd_mloopcol, layerDoMinMax_mloopcol, layerCopyValue_mloopcol, NULL, NULL, NULL, layerMaxNum_mloopcol},
/* 18: CD_TANGENT */
- {sizeof(float) * 4 * 4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
+ {sizeof(float) * 4 * 4, "", 0, N_("Tangent"), NULL, NULL, NULL, NULL, NULL},
/* 19: CD_MDISPS */
{sizeof(MDisps), "MDisps", 1, NULL, layerCopy_mdisps,
layerFree_mdisps, NULL, layerSwap_mdisps, NULL,
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index 0582d07d99c..30dcba66c5e 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -834,6 +834,8 @@ DagForest *build_dag(Main *bmain, Scene *sce, short mask)
}
dag->need_update = false;
+ BKE_main_id_tag_idcode(bmain, ID_OB, LIB_TAG_DOIT, false);
+
/* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later [#32017] */
BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
@@ -845,14 +847,43 @@ DagForest *build_dag(Main *bmain, Scene *sce, short mask)
/* add current scene objects */
for (base = sce->base.first; base; base = base->next) {
ob = base->object;
-
+ ob->id.tag |= LIB_TAG_DOIT;
build_dag_object(dag, scenenode, bmain, sce, ob, mask);
if (ob->proxy)
build_dag_object(dag, scenenode, bmain, sce, ob->proxy, mask);
if (ob->dup_group)
build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
}
-
+
+ /* There might be situations when object from current scene depends on
+ * objects form other scene AND objects from other scene has own
+ * dependencies on objects from other scene.
+ *
+ * This is really important to include such indirect dependencies in order
+ * to keep threaded update safe but since we don't really know if object is
+ * coming from current scene or another scene we do rather stupid tag-based
+ * check here: all the objects for which build_dag_object() was called are
+ * getting tagged with LIB_TAG_DOIT. This way if some node has untagged
+ * object we know it's an object from other scene.
+ *
+ * It should be enough to to it once, because if there's longer chain of
+ * indirect dependencies, all the new nodes will be added to the end of the
+ * list, meaning we'll keep covering them in this for loop.
+ */
+ for (node = sce->theDag->DagNode.first; node != NULL; node = node->next) {
+ if (node->type == ID_OB) {
+ ob = node->ob;
+ if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
+ ob->id.tag |= LIB_TAG_DOIT;
+ build_dag_object(dag, scenenode, bmain, sce, ob, mask);
+ if (ob->proxy)
+ build_dag_object(dag, scenenode, bmain, sce, ob->proxy, mask);
+ if (ob->dup_group)
+ build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
+ }
+ }
+ }
+
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
/* Now all relations were built, but we need to solve 1 exceptional case;
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 96bdfe88722..6c117447664 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -44,6 +44,7 @@
#include "BLI_math.h"
#include "BLI_jitter.h"
#include "BLI_bitmap.h"
+#include "BLI_task.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_mesh.h"
@@ -451,118 +452,148 @@ finally:
pRes[3] = fSign;
}
+static void emDM_calc_loop_tangents_thread(TaskPool *UNUSED(pool), void *taskdata, int UNUSED(threadid))
+{
+ struct SGLSLEditMeshToTangent *mesh2tangent = taskdata;
+ /* new computation method */
+ {
+ SMikkTSpaceContext sContext = {NULL};
+ SMikkTSpaceInterface sInterface = {NULL};
+ sContext.m_pUserData = mesh2tangent;
+ sContext.m_pInterface = &sInterface;
+ sInterface.m_getNumFaces = emdm_ts_GetNumFaces;
+ sInterface.m_getNumVerticesOfFace = emdm_ts_GetNumVertsOfFace;
+ sInterface.m_getPosition = emdm_ts_GetPosition;
+ sInterface.m_getTexCoord = emdm_ts_GetTextureCoordinate;
+ sInterface.m_getNormal = emdm_ts_GetNormal;
+ sInterface.m_setTSpaceBasic = emdm_ts_SetTSpace;
+ /* 0 if failed */
+ genTangSpaceDefault(&sContext);
+ }
+}
+
/**
* \see #DM_calc_loop_tangents, same logic but used arrays instead of #BMesh data.
*
* \note This function is not so normal, its using `bm->ldata` as input, but output's to `dm->loopData`.
* This is done because #CD_TANGENT is cache data used only for drawing.
*/
-static void emDM_calcLoopTangents(DerivedMesh *dm)
+
+static void emDM_calc_loop_tangents(
+ DerivedMesh *dm, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_count)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMEditMesh *em = bmdm->em;
BMesh *bm = bmdm->em->bm;
-
- /* mesh vars */
- int cd_loop_uv_offset;
- float (*orco)[3] = NULL, (*tangent)[4];
- int /* totvert, */ totface;
- const float (*fnors)[3];
- const float (*tlnors)[3];
- char htype_index = BM_LOOP;
-
- if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) != -1)
+ if (CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV) == 0)
return;
- fnors = bmdm->polyNos; /* dm->getPolyDataArray(dm, CD_NORMAL) */
-
- /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
- * have to check this is valid...
- */
- tlnors = dm->getLoopDataArray(dm, CD_NORMAL);
-
- /* check we have all the needed layers */
- totface = em->tottri;
-
- cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
-
- /* needed for indexing loop-tangents */
- htype_index = BM_LOOP;
- if (cd_loop_uv_offset == -1) {
- orco = dm->getVertDataArray(dm, CD_ORCO);
- if (!orco)
- return;
- /* needed for orco lookups */
- htype_index |= BM_VERT;
- }
-
- if (fnors) {
- /* needed for face normal lookups */
- htype_index |= BM_FACE;
- }
-
- BM_mesh_elem_index_ensure(bm, htype_index);
+ int act_uv_n = -1;
+ int ren_uv_n = -1;
+ bool calc_act = false;
+ bool calc_ren = false;
+ char act_uv_name[MAX_NAME];
+ char ren_uv_name[MAX_NAME];
+ char tangent_mask = 0;
+
+ DM_calc_loop_tangents_step_0(
+ &bm->ldata, calc_active_tangent, tangent_names, tangent_names_count,
+ &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
+
+ if ((dm->tangent_mask | tangent_mask) != dm->tangent_mask) {
+ for (int i = 0; i < tangent_names_count; i++)
+ if (tangent_names[i][0])
+ DM_add_named_tangent_layer_for_uv(&bm->ldata, &dm->loopData, dm->numLoopData, tangent_names[i]);
+ if (calc_act && act_uv_name[0])
+ DM_add_named_tangent_layer_for_uv(&bm->ldata, &dm->loopData, dm->numLoopData, act_uv_name);
+ if (calc_ren && ren_uv_name[0])
+ DM_add_named_tangent_layer_for_uv(&bm->ldata, &dm->loopData, dm->numLoopData, ren_uv_name);
+ int totface = em->tottri;
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ int num_face_as_quad_map;
+ int *face_as_quad_map = NULL;
- /* create tangent layer */
- DM_add_loop_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
- tangent = DM_get_loop_data_layer(dm, CD_TANGENT);
+ /* map faces to quads */
+ if (bmdm->em->tottri != bm->totface) {
+ /* over alloc, since we dont know how many ngon or quads we have */
-#ifdef USE_LOOPTRI_DETECT_QUADS
- int num_face_as_quad_map;
- int *face_as_quad_map = NULL;
-
- /* map faces to quads */
- if (bmdm->em->tottri != bm->totface) {
- /* over alloc, since we dont know how many ngon or quads we have */
-
- /* map fake face index to looptri */
- face_as_quad_map = MEM_mallocN(sizeof(int) * totface, __func__);
- int i, j;
- for (i = 0, j = 0; j < totface; i++, j++) {
- face_as_quad_map[i] = j;
- /* step over all quads */
- if (em->looptris[j][0]->f->len == 4) {
- j++; /* skips the nest looptri */
+ /* map fake face index to looptri */
+ face_as_quad_map = MEM_mallocN(sizeof(int) * totface, __func__);
+ int i, j;
+ for (i = 0, j = 0; j < totface; i++, j++) {
+ face_as_quad_map[i] = j;
+ /* step over all quads */
+ if (em->looptris[j][0]->f->len == 4) {
+ j++; /* skips the nest looptri */
+ }
}
+ num_face_as_quad_map = i;
+ }
+ else {
+ num_face_as_quad_map = totface;
}
- num_face_as_quad_map = i;
- }
- else {
- num_face_as_quad_map = totface;
- }
#endif
-
- /* new computation method */
- {
- SGLSLEditMeshToTangent mesh2tangent = {NULL};
- SMikkTSpaceContext sContext = {NULL};
- SMikkTSpaceInterface sInterface = {NULL};
-
- mesh2tangent.precomputedFaceNormals = fnors;
- mesh2tangent.precomputedLoopNormals = tlnors;
- mesh2tangent.looptris = (const BMLoop *(*)[3])em->looptris;
- mesh2tangent.cd_loop_uv_offset = cd_loop_uv_offset;
- mesh2tangent.orco = (const float (*)[3])orco;
- mesh2tangent.tangent = tangent;
- mesh2tangent.numTessFaces = totface;
-
+ /* Calculation */
+ {
+ TaskScheduler *scheduler = BLI_task_scheduler_get();
+ TaskPool *task_pool;
+ task_pool = BLI_task_pool_create(scheduler, NULL);
+
+ dm->tangent_mask = 0;
+ /* Calculate tangent layers */
+ SGLSLEditMeshToTangent data_array[MAX_MTFACE];
+ int index = 0;
+ int n = 0;
+ CustomData_update_typemap(&dm->loopData);
+ const int tangent_layer_num = CustomData_number_of_layers(&dm->loopData, CD_TANGENT);
+ for (n = 0; n < tangent_layer_num; n++) {
+ index = CustomData_get_layer_index_n(&dm->loopData, CD_TANGENT, n);
+ BLI_assert(n < MAX_MTFACE);
+ SGLSLEditMeshToTangent *mesh2tangent = &data_array[n];
+ mesh2tangent->numTessFaces = em->tottri;
#ifdef USE_LOOPTRI_DETECT_QUADS
- mesh2tangent.face_as_quad_map = face_as_quad_map;
- mesh2tangent.num_face_as_quad_map = num_face_as_quad_map;
+ mesh2tangent->face_as_quad_map = face_as_quad_map;
+ mesh2tangent->num_face_as_quad_map = num_face_as_quad_map;
#endif
+ mesh2tangent->precomputedFaceNormals = bmdm->polyNos; /* dm->getPolyDataArray(dm, CD_NORMAL) */
+ /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
+ * have to check this is valid...
+ */
+ mesh2tangent->precomputedLoopNormals = CustomData_get_layer(&dm->loopData, CD_NORMAL);
+ mesh2tangent->cd_loop_uv_offset = CustomData_get_n_offset(&bm->ldata, CD_MLOOPUV, n);
+
+ /* needed for indexing loop-tangents */
+ int htype_index = BM_LOOP;
+ if (mesh2tangent->cd_loop_uv_offset == -1) {
+ mesh2tangent->orco = dm->getVertDataArray(dm, CD_ORCO);
+ if (!mesh2tangent->orco)
+ continue;
+ /* needed for orco lookups */
+ htype_index |= BM_VERT;
+ }
+ if (mesh2tangent->precomputedFaceNormals) {
+ /* needed for face normal lookups */
+ htype_index |= BM_FACE;
+ }
+ BM_mesh_elem_index_ensure(bm, htype_index);
+
+ mesh2tangent->looptris = (const BMLoop *(*)[3])em->looptris;
+ mesh2tangent->tangent = dm->loopData.layers[index].data;
+
+ /* Fill the resulting tangent_mask */
+ int uv_ind = CustomData_get_named_layer_index(&bm->ldata, CD_MLOOPUV, dm->loopData.layers[index].name);
+ int uv_start = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV);
+ BLI_assert(uv_ind != -1 && uv_start != -1);
+ BLI_assert(uv_ind - uv_start < MAX_MTFACE);
+ dm->tangent_mask |= 1 << (uv_ind - uv_start);
+ BLI_task_pool_push(task_pool, emDM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW);
+ }
- sContext.m_pUserData = &mesh2tangent;
- sContext.m_pInterface = &sInterface;
- sInterface.m_getNumFaces = emdm_ts_GetNumFaces;
- sInterface.m_getNumVerticesOfFace = emdm_ts_GetNumVertsOfFace;
- sInterface.m_getPosition = emdm_ts_GetPosition;
- sInterface.m_getTexCoord = emdm_ts_GetTextureCoordinate;
- sInterface.m_getNormal = emdm_ts_GetNormal;
- sInterface.m_setTSpaceBasic = emdm_ts_SetTSpace;
-
- /* 0 if failed */
- genTangSpaceDefault(&sContext);
-
+ BLI_assert(dm->tangent_mask == tangent_mask);
+ BLI_task_pool_work_and_wait(task_pool);
+ BLI_task_pool_free(task_pool);
+ }
#ifdef USE_LOOPTRI_DETECT_QUADS
if (face_as_quad_map) {
MEM_freeN(face_as_quad_map);
@@ -570,6 +601,15 @@ static void emDM_calcLoopTangents(DerivedMesh *dm)
#undef USE_LOOPTRI_DETECT_QUADS
#endif
}
+ /* Update active layer index */
+ int uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, act_uv_n);
+ int tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, bm->ldata.layers[uv_index].name);
+ CustomData_set_layer_active_index(&dm->loopData, CD_TANGENT, tan_index);
+
+ /* Update render layer index */
+ uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, ren_uv_n);
+ tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, bm->ldata.layers[uv_index].name);
+ CustomData_set_layer_render_index(&dm->loopData, CD_TANGENT, tan_index);
}
/** \} */
@@ -1419,15 +1459,16 @@ static void emdm_pass_attrib_vertex_glsl(const DMVertexAttribs *attribs, const B
}
glVertexAttrib4ubv(attribs->mcol[i].gl_index, col);
}
- if (attribs->tottang) {
+
+ for (i = 0; i < attribs->tottang; i++) {
const float *tang;
- if (attribs->tang.em_offset != -1) {
- tang = attribs->tang.array[BM_elem_index_get(loop)];
+ if (attribs->tang[i].em_offset != -1) {
+ tang = attribs->tang[i].array[BM_elem_index_get(loop)];
}
else {
tang = zero;
}
- glVertexAttrib4fv(attribs->tang.gl_index, tang);
+ glVertexAttrib4fv(attribs->tang[i].gl_index, tang);
}
}
@@ -2218,7 +2259,7 @@ DerivedMesh *getEditDerivedBMesh(
bmdm->dm.calcNormals = emDM_calcNormals;
bmdm->dm.calcLoopNormals = emDM_calcLoopNormals;
bmdm->dm.calcLoopNormalsSpaceArray = emDM_calcLoopNormalsSpaceArray;
- bmdm->dm.calcLoopTangents = emDM_calcLoopTangents;
+ bmdm->dm.calcLoopTangents = emDM_calc_loop_tangents;
bmdm->dm.recalcTessellation = emDM_recalcTessellation;
bmdm->dm.recalcLoopTri = emDM_recalcLoopTri;
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 0a887dcf676..aed33d2c64d 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -1040,7 +1040,7 @@ makebreak:
timeofs += distfac * cu->xof; /* not cyclic */
ct = chartransdata;
- for (i = 0; i <= slen; i++, ct++) {
+ for (i = 0; i < slen; i++, ct++) {
float ctime, dtime, vec[4], tvec[4], rotvec[3];
float si, co;
@@ -1082,8 +1082,9 @@ makebreak:
sb = &selboxes[i - selstart];
sb->rot = -ct->rot;
}
-
}
+ /* null character is always zero width, no need to iterate over it */
+ chartransdata[slen] = chartransdata[slen - 1];
}
}
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index cdb3d1afc29..340b406722f 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1992,7 +1992,7 @@ void BKE_image_stamp_buf(
BLF_wordwrap(mono, width - (BUFF_MARGIN_X * 2));
BLF_buffer(mono, rectf, rect, width, height, channels, display);
- BLF_buffer_col(mono, UNPACK4(scene->r.fg_stamp));
+ BLF_buffer_col(mono, scene->r.fg_stamp);
pad = BLF_width_max(mono);
/* use 'h_fixed' rather than 'h', aligns better */
diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c
index 303d0c6adfc..10e7d46b315 100644
--- a/source/blender/blenkernel/intern/image_gen.c
+++ b/source/blender/blenkernel/intern/image_gen.c
@@ -297,6 +297,9 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width
*/
BLF_buffer(mono, rect_float, rect, width, height, 4, NULL);
+ const float text_color[4] = {0.0, 0.0, 0.0, 1.0};
+ const float text_outline[4] = {1.0, 1.0, 1.0, 1.0};
+
for (y = 0; y < height; y += step) {
text[1] = '1';
@@ -306,7 +309,7 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width
pen_y = y + 44;
/* terribly crappy outline font! */
- BLF_buffer_col(mono, 1.0, 1.0, 1.0, 1.0);
+ BLF_buffer_col(mono, text_outline);
BLF_position(mono, pen_x - outline, pen_y, 0.0);
BLF_draw_buffer(mono, text, 2);
@@ -326,7 +329,7 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width
BLF_position(mono, pen_x + outline, pen_y - outline, 0.0);
BLF_draw_buffer(mono, text, 2);
- BLF_buffer_col(mono, 0.0, 0.0, 0.0, 1.0);
+ BLF_buffer_col(mono, text_color);
BLF_position(mono, pen_x, pen_y, 0.0);
BLF_draw_buffer(mono, text, 2);
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index 12db3a87ba0..930a3c487ec 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -116,7 +116,7 @@ MaskSplinePoint *BKE_mask_spline_point_array(MaskSpline *spline)
return spline->points_deform ? spline->points_deform : spline->points;
}
-MaskSplinePoint *BKE_mask_spline_point_array_from_point(MaskSpline *spline, MaskSplinePoint *point_ref)
+MaskSplinePoint *BKE_mask_spline_point_array_from_point(MaskSpline *spline, const MaskSplinePoint *point_ref)
{
if ((point_ref >= spline->points) && (point_ref < &spline->points[spline->tot_point])) {
return spline->points;
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 809b45d4b36..1fec725dbb7 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1148,7 +1148,7 @@ static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode
/* parses the geom+tex nodes */
ntreeShaderGetTexcoMode(ntree, r_mode, &basemat->texco, &basemat->mode_l);
-
+ basemat->nmap_tangent_names_count = 0;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->id) {
if (GS(node->id->name) == ID_MA) {
@@ -1170,6 +1170,21 @@ static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode
else if (node->type == NODE_GROUP)
init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb);
}
+ else if (node->typeinfo->type == SH_NODE_NORMAL_MAP) {
+ basemat->mode2_l |= MA_TANGENT_CONCRETE;
+ NodeShaderNormalMap *nm = node->storage;
+ bool taken_into_account = false;
+ for (int i = 0; i < basemat->nmap_tangent_names_count; i++) {
+ if (STREQ(basemat->nmap_tangent_names[i], nm->uv_map)) {
+ taken_into_account = true;
+ break;
+ }
+ }
+ if (!taken_into_account) {
+ BLI_assert(basemat->nmap_tangent_names_count < MAX_MTFACE + 1);
+ strcpy(basemat->nmap_tangent_names[basemat->nmap_tangent_names_count++], nm->uv_map);
+ }
+ }
}
}
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 83e020cf2ea..577a21285f8 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -2417,30 +2417,42 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData
}
}
-void BKE_mesh_tangent_loops_to_tessdata(CustomData *fdata, CustomData *ldata, MFace *mface,
- int *polyindices, unsigned int (*loopindices)[4], const int num_faces)
+void BKE_mesh_tangent_loops_to_tessdata(
+ CustomData *fdata, CustomData *ldata, MFace *mface,
+ int *polyindices, unsigned int (*loopindices)[4], const int num_faces, const char *layer_name)
{
/* Note: performances are sub-optimal when we get a NULL mface, we could be ~25% quicker with dedicated code...
* Issue is, unless having two different functions with nearly the same code, there's not much ways to solve
* this. Better imho to live with it for now. :/ --mont29
*/
- const bool hasLoopTangent = CustomData_has_layer(ldata, CD_TANGENT);
+
+ float (*ftangents)[4] = NULL;
+ float (*ltangents)[4] = NULL;
+
int findex, j;
const int *pidx;
unsigned int (*lidx)[4];
- if (hasLoopTangent) {
- /* need to do for all uv maps at some point */
- float (*ftangents)[4] = CustomData_get_layer(fdata, CD_TANGENT);
- float (*ltangents)[4] = CustomData_get_layer(ldata, CD_TANGENT);
+ if (layer_name)
+ ltangents = CustomData_get_layer_named(ldata, CD_TANGENT, layer_name);
+ else
+ ltangents = CustomData_get_layer(ldata, CD_TANGENT);
- for (findex = 0, pidx = polyindices, lidx = loopindices;
- findex < num_faces;
- pidx++, lidx++, findex++)
- {
- int nverts = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3;
- for (j = nverts; j--;) {
- copy_v4_v4(ftangents[findex * 4 + j], ltangents[(*lidx)[j]]);
+ if (ltangents) {
+ /* need to do for all uv maps at some point */
+ if (layer_name)
+ ftangents = CustomData_get_layer_named(fdata, CD_TANGENT, layer_name);
+ else
+ ftangents = CustomData_get_layer(fdata, CD_TANGENT);
+ if (ftangents) {
+ for (findex = 0, pidx = polyindices, lidx = loopindices;
+ findex < num_faces;
+ pidx++, lidx++, findex++)
+ {
+ int nverts = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3;
+ for (j = nverts; j--;) {
+ copy_v4_v4(ftangents[findex * 4 + j], ltangents[(*lidx)[j]]);
+ }
}
}
}
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index a3529d8e6f2..c2950530e5c 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -58,7 +58,6 @@
#include "BKE_appdir.h"
#include "BKE_anim.h"
-#include "BKE_blender.h"
#include "BKE_cloth.h"
#include "BKE_dynamicpaint.h"
#include "BKE_key.h"
diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index 1b807adca4b..4086fc2b0f3 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -3084,6 +3084,10 @@ static void init_text_effect(Sequence *seq)
data = seq->effectdata = MEM_callocN(sizeof(TextVars), "textvars");
data->text_size = 30;
+
+ copy_v4_fl(data->color, 1.0f);
+ data->shadow_color[3] = 1.0f;
+
BLI_strncpy(data->text, "Text", sizeof(data->text));
data->loc[0] = 0.5f;
@@ -3099,7 +3103,9 @@ static int num_inputs_text(void)
static int early_out_text(Sequence *seq, float UNUSED(facf0), float UNUSED(facf1))
{
TextVars *data = seq->effectdata;
- if (data->text[0] == 0 || data->text_size < 1) {
+ if (data->text[0] == 0 || data->text_size < 1 ||
+ ((data->color[3] == 0.0f) && (data->shadow_color[3] == 0.0f || (data->flag & SEQ_TEXT_SHADOW) == 0)))
+ {
return EARLY_USE_INPUT_1;
}
return EARLY_NO_INPUT;
@@ -3188,11 +3194,11 @@ static ImBuf *do_text_effect(const SeqRenderData *context, Sequence *seq, float
fontx = BLF_width_max(mono);
fonty = line_height;
BLF_position(mono, x + max_ii(fontx / 25, 1), y + max_ii(fonty / 25, 1), 0.0f);
- BLF_buffer_col(mono, 0.0f, 0.0f, 0.0f, 1.0f);
+ BLF_buffer_col(mono, data->shadow_color);
BLF_draw_buffer(mono, data->text, BLF_DRAW_STR_DUMMY_MAX);
}
BLF_position(mono, x, y, 0.0f);
- BLF_buffer_col(mono, 1.0f, 1.0f, 1.0f, 1.0f);
+ BLF_buffer_col(mono, data->color);
BLF_draw_buffer(mono, data->text, BLF_DRAW_STR_DUMMY_MAX);
BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL);
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 97994332411..a84b8352417 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -3016,11 +3016,13 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
numdata++;
}
}
- if (matconv[a].attribs.tottang && matconv[a].attribs.tang.array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.tang.gl_index;
- matconv[a].datatypes[numdata].size = 4;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
+ for (b = 0; b < matconv[a].attribs.tottang; b++) {
+ if (matconv[a].attribs.tottang && matconv[a].attribs.tang[b].array) {
+ matconv[a].datatypes[numdata].index = matconv[a].attribs.tang[b].gl_index;
+ matconv[a].datatypes[numdata].size = 4;
+ matconv[a].datatypes[numdata].type = GL_FLOAT;
+ numdata++;
+ }
}
if (numdata != 0) {
matconv[a].numdata = numdata;
@@ -3105,15 +3107,17 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
offset += sizeof(unsigned char) * 4;
}
}
- if (matconv[i].attribs.tottang && matconv[i].attribs.tang.array) {
- const float (*looptang)[4] = (const float (*)[4])matconv[i].attribs.tang.array + tot_loops;
+ for (b = 0; b < matconv[i].attribs.tottang; b++) {
+ if (matconv[i].attribs.tottang && matconv[i].attribs.tang[b].array) {
+ const float (*looptang)[4] = (const float (*)[4])matconv[i].attribs.tang[b].array + tot_loops;
- copy_v4_v4((float *)&varray[offset], looptang[0]);
- copy_v4_v4((float *)&varray[offset + max_element_size], looptang[3]);
- copy_v4_v4((float *)&varray[offset + 2 * max_element_size], looptang[2]);
- copy_v4_v4((float *)&varray[offset + 3 * max_element_size], looptang[1]);
+ copy_v4_v4((float *)&varray[offset], looptang[0]);
+ copy_v4_v4((float *)&varray[offset + max_element_size], looptang[3]);
+ copy_v4_v4((float *)&varray[offset + 2 * max_element_size], looptang[2]);
+ copy_v4_v4((float *)&varray[offset + 3 * max_element_size], looptang[1]);
- offset += sizeof(float) * 4;
+ offset += sizeof(float) * 4;
+ }
}
tot_loops += 4;
@@ -4361,6 +4365,7 @@ static void ccgDM_recalcLoopTri(DerivedMesh *UNUSED(dm))
static const MLoopTri *ccgDM_getLoopTriArray(DerivedMesh *dm)
{
+ BLI_rw_mutex_lock(&loops_cache_rwlock, THREAD_LOCK_WRITE);
if (dm->looptris.array) {
BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);
}
@@ -4391,6 +4396,7 @@ static const MLoopTri *ccgDM_getLoopTriArray(DerivedMesh *dm)
lt->poly = poly_index;
}
}
+ BLI_rw_mutex_unlock(&loops_cache_rwlock);
return dm->looptris.array;
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 911d258cd6b..4369c6dad2f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7171,9 +7171,13 @@ static void direct_link_mask(FileData *fd, Mask *mask)
MaskSpline *spline;
MaskLayerShape *masklay_shape;
+ /* can't use newdataadr since it's a pointer within an array */
+ MaskSplinePoint *act_point_search = NULL;
+
link_list(fd, &masklay->splines);
for (spline = masklay->splines.first; spline; spline = spline->next) {
+ MaskSplinePoint *points_old = spline->points;
int i;
spline->points = newdataadr(fd, spline->points);
@@ -7184,6 +7188,14 @@ static void direct_link_mask(FileData *fd, Mask *mask)
if (point->tot_uw)
point->uw = newdataadr(fd, point->uw);
}
+
+ /* detect active point */
+ if ((act_point_search == NULL) &&
+ (masklay->act_point >= points_old) &&
+ (masklay->act_point < points_old + spline->tot_point))
+ {
+ act_point_search = &spline->points[masklay->act_point - points_old];
+ }
}
link_list(fd, &masklay->splines_shapes);
@@ -7201,7 +7213,7 @@ static void direct_link_mask(FileData *fd, Mask *mask)
}
masklay->act_spline = newdataadr(fd, masklay->act_spline);
- masklay->act_point = newdataadr(fd, masklay->act_point);
+ masklay->act_point = act_point_search;
}
}
@@ -7926,7 +7938,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */
- /* don't forget to set version number in BKE_blender.h! */
+ /* don't forget to set version number in BKE_blender_version.h! */
}
#if 0 // XXX: disabled for now... we still don't have this in the right place in the loading code for it to work
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 11c3049db92..b18b2b9fb5f 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1002,5 +1002,21 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ Sequence *seq;
+
+ SEQ_BEGIN (scene->ed, seq)
+ {
+ if (seq->type == SEQ_TYPE_TEXT) {
+ TextVars *data = seq->effectdata;
+ if (data->color[3] == 0.0f) {
+ copy_v4_fl(data->color, 1.0f);
+ data->shadow_color[3] = 1.0f;
+ }
+ }
+ }
+ SEQ_END
+ }
+
}
}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d19ed0ad278..de709538e42 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -144,7 +144,7 @@
#include "BLI_mempool.h"
#include "BKE_action.h"
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BKE_bpath.h"
#include "BKE_curve.h"
#include "BKE_constraint.h"
diff --git a/source/blender/bmesh/tools/bmesh_decimate_dissolve.c b/source/blender/bmesh/tools/bmesh_decimate_dissolve.c
index 5a7a2f3ee29..1a16bd13fef 100644
--- a/source/blender/bmesh/tools/bmesh_decimate_dissolve.c
+++ b/source/blender/bmesh/tools/bmesh_decimate_dissolve.c
@@ -226,6 +226,12 @@ static bool bm_vert_collapse_is_degenerate(BMVert *v)
BMVert *v_pair[2];
if (BM_vert_edge_pair(v, &e_pair[0], &e_pair[1])) {
+
+ /* allow wire edges */
+ if (BM_edge_is_wire(e_pair[0]) || BM_edge_is_wire(e_pair[1])) {
+ return false;
+ }
+
v_pair[0] = BM_edge_other_vert(e_pair[0], v);
v_pair[1] = BM_edge_other_vert(e_pair[1], v);
diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp
index 15e95a05425..bd32e989ae3 100644
--- a/source/blender/collada/DocumentExporter.cpp
+++ b/source/blender/collada/DocumentExporter.cpp
@@ -90,7 +90,7 @@ extern "C"
#include "BKE_action.h" // pose functions
#include "BKE_animsys.h"
#include "BKE_armature.h"
-#include "BKE_blender.h" // version info
+#include "BKE_blender_version.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_image.h"
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index 64df42fc823..a884268fd5e 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -39,7 +39,6 @@
#include "COLLADAFWPolygons.h"
extern "C" {
- #include "BKE_blender.h"
#include "BKE_customdata.h"
#include "BKE_displist.h"
#include "BKE_global.h"
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index 9f1d46fccd6..82f312c2171 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -242,17 +242,21 @@ static void deg_graph_build_finalize(Depsgraph *graph)
id_node->layers |= id_to->layers;
}
}
-
- /* Re-tag ID for update if it was tagged before the relations
- * update tag.
- */
- ID *id = id_node->id;
- if (id->tag & LIB_TAG_ID_RECALC_ALL &&
- id->tag & LIB_TAG_DOIT)
- {
- id_node->tag_update(graph);
- id->tag &= ~LIB_TAG_DOIT;
- }
+ }
+ }
+
+ /* Re-tag IDs for update if it was tagged before the relations update tag. */
+ for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
+ it != graph->id_hash.end();
+ ++it)
+ {
+ IDDepsNode *id_node = it->second;
+ ID *id = id_node->id;
+ if (id->tag & LIB_TAG_ID_RECALC_ALL &&
+ id->tag & LIB_TAG_DOIT)
+ {
+ id_node->tag_update(graph);
+ id->tag &= ~LIB_TAG_DOIT;
}
}
}
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cc b/source/blender/depsgraph/intern/depsgraph_build_nodes.cc
index 54a462a759a..04bda740068 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cc
@@ -731,6 +731,14 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob)
}
}
+ /* speed optimization for animation lookups */
+ if (ob->pose) {
+ BKE_pose_channels_hash_make(ob->pose);
+ if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
+ BKE_pose_update_constraint_flags(ob->pose);
+ }
+ }
+
/* Make sure pose is up-to-date with armature updates. */
add_operation_node(&arm->id,
DEPSNODE_TYPE_PARAMETERS,
@@ -825,6 +833,14 @@ void DepsgraphNodeBuilder::build_proxy_rig(Object *ob)
ID *obdata = (ID *)ob->data;
build_animdata(obdata);
+ BLI_assert(ob->pose != NULL);
+
+ /* speed optimization for animation lookups */
+ BKE_pose_channels_hash_make(ob->pose);
+ if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
+ BKE_pose_update_constraint_flags(ob->pose);
+ }
+
add_operation_node(&ob->id,
DEPSNODE_TYPE_EVAL_POSE,
DEPSOP_TYPE_INIT,
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc
index e8065766332..fb6722cc893 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cc
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cc
@@ -137,29 +137,29 @@ static void deg_task_run_func(TaskPool *pool,
DepsgraphEvalState *state = (DepsgraphEvalState *)BLI_task_pool_userdata(pool);
OperationDepsNode *node = (OperationDepsNode *)taskdata;
- if (!node->is_noop()) {
- /* Get context. */
- // TODO: who initialises this? "Init" operations aren't able to initialise it!!!
- /* TODO(sergey): Wedon't use component contexts at this moment. */
- /* ComponentDepsNode *comp = node->owner; */
- BLI_assert(node->owner != NULL);
-
- /* Take note of current time. */
- double start_time = PIL_check_seconds_timer();
- DepsgraphDebug::task_started(state->graph, node);
-
- /* Should only be the case for NOOPs, which never get to this point. */
- BLI_assert(node->evaluate);
-
- /* Perform operation. */
- node->evaluate(state->eval_ctx);
-
- /* Note how long this took. */
- double end_time = PIL_check_seconds_timer();
- DepsgraphDebug::task_completed(state->graph,
- node,
- end_time - start_time);
- }
+ BLI_assert(!node->is_noop() && "NOOP nodes should not actually be scheduled");
+
+ /* Get context. */
+ // TODO: who initialises this? "Init" operations aren't able to initialise it!!!
+ /* TODO(sergey): Wedon't use component contexts at this moment. */
+ /* ComponentDepsNode *comp = node->owner; */
+ BLI_assert(node->owner != NULL);
+
+ /* Take note of current time. */
+ double start_time = PIL_check_seconds_timer();
+ DepsgraphDebug::task_started(state->graph, node);
+
+ /* Should only be the case for NOOPs, which never get to this point. */
+ BLI_assert(node->evaluate);
+
+ /* Perform operation. */
+ node->evaluate(state->eval_ctx);
+
+ /* Note how long this took. */
+ double end_time = PIL_check_seconds_timer();
+ DepsgraphDebug::task_completed(state->graph,
+ node,
+ end_time - start_time);
schedule_children(pool, state->graph, node, state->layers);
}
@@ -230,26 +230,54 @@ static void calculate_eval_priority(OperationDepsNode *node)
}
}
+/* Schedule a node if it needs evaluation.
+ * dec_parents: Decrement pending parents count, true when child nodes are scheduled
+ * after a task has been completed.
+ */
+static void schedule_node(TaskPool *pool, Depsgraph *graph, int layers,
+ OperationDepsNode *node, bool dec_parents)
+{
+ int id_layers = node->owner->owner->layers;
+
+ if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0 &&
+ (id_layers & layers) != 0)
+ {
+ if (dec_parents) {
+ BLI_assert(node->num_links_pending > 0);
+ atomic_sub_uint32(&node->num_links_pending, 1);
+ }
+
+ if (node->num_links_pending == 0) {
+ BLI_spin_lock(&graph->lock);
+ bool need_schedule = !node->scheduled;
+ node->scheduled = true;
+ BLI_spin_unlock(&graph->lock);
+
+ if (need_schedule) {
+ if (node->is_noop()) {
+ /* skip NOOP node, schedule children right away */
+ schedule_children(pool, graph, node, layers);
+ }
+ else {
+ /* children are scheduled once this task is completed */
+ BLI_task_pool_push(pool, deg_task_run_func, node, false, TASK_PRIORITY_LOW);
+ }
+ }
+ }
+ }
+}
+
static void schedule_graph(TaskPool *pool,
Depsgraph *graph,
const int layers)
{
- BLI_spin_lock(&graph->lock);
for (Depsgraph::OperationNodes::const_iterator it = graph->operations.begin();
it != graph->operations.end();
++it)
{
OperationDepsNode *node = *it;
- IDDepsNode *id_node = node->owner->owner;
- if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) &&
- node->num_links_pending == 0 &&
- (id_node->layers & layers) != 0)
- {
- BLI_task_pool_push(pool, deg_task_run_func, node, false, TASK_PRIORITY_LOW);
- node->scheduled = true;
- }
+ schedule_node(pool, graph, layers, node, false);
}
- BLI_spin_unlock(&graph->lock);
}
static void schedule_children(TaskPool *pool,
@@ -270,26 +298,7 @@ static void schedule_children(TaskPool *pool,
continue;
}
- IDDepsNode *id_child = child->owner->owner;
- if ((id_child->layers & layers) != 0 &&
- (child->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
- {
- if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) {
- BLI_assert(child->num_links_pending > 0);
- atomic_sub_uint32(&child->num_links_pending, 1);
- }
-
- if (child->num_links_pending == 0) {
- BLI_spin_lock(&graph->lock);
- bool need_schedule = !child->scheduled;
- child->scheduled = true;
- BLI_spin_unlock(&graph->lock);
-
- if (need_schedule) {
- BLI_task_pool_push(pool, deg_task_run_func, child, false, TASK_PRIORITY_LOW);
- }
- }
- }
+ schedule_node(pool, graph, layers, child, (rel->flag & DEPSREL_FLAG_CYCLIC) == 0);
}
}
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc
index a711f2a98cb..4c711bfb8d6 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -400,12 +400,11 @@ void DEG_graph_on_visible_update(Main *bmain, Scene *scene)
* This is mainly needed on file load only, after that updates of invisible objects
* will be stored in the pending list.
*/
- for (Depsgraph::OperationNodes::const_iterator it = graph->operations.begin();
- it != graph->operations.end();
+ for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
+ it != graph->id_hash.end();
++it)
{
- OperationDepsNode *node = *it;
- IDDepsNode *id_node = node->owner->owner;
+ IDDepsNode *id_node = it->second;
ID *id = id_node->id;
if ((id->tag & LIB_TAG_ID_RECALC_ALL) != 0 ||
(id_node->layers & scene->lay_updated) == 0)
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index f92967ef5ff..afc4e5c9e61 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -886,7 +886,7 @@ void ANIM_OT_driver_button_add(wmOperatorType *ot)
/* identifiers */
ot->name = "Add Driver";
ot->idname = "ANIM_OT_driver_button_add";
- ot->description = "Add driver(s) for the property(s) connected represented by the highlighted button";
+ ot->description = "Add driver(s) for the property(s) represented by the highlighted button";
/* callbacks */
/* NOTE: No exec, as we need all these to use the current context info
diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c
index 87d75aa8fad..b62714700fa 100644
--- a/source/blender/editors/armature/editarmature_sketch.c
+++ b/source/blender/editors/armature/editarmature_sketch.c
@@ -1086,9 +1086,23 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S
mval[1] = dd->mval[1];
/* try to snap to closer object */
- found = snapObjectsContext(
- C, mval, SNAP_NOT_SELECTED,
- vec, no, &dist_px);
+ {
+ struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C), CTX_data_scene(C), 0,
+ CTX_wm_region(C), CTX_wm_view3d(C));
+
+ found = ED_transform_snap_object_project_view3d_mixed(
+ snap_context,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_NOT_SELECTED,
+ .snap_to_flag = SCE_SELECT_FACE,
+ },
+ mval, &dist_px, true,
+ vec, no);
+
+ ED_transform_snap_object_context_destroy(snap_context);
+ }
+
if (found == 1) {
pt->type = dd->type;
pt->mode = PT_SNAP;
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 9df611b3216..395da2cd2f1 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -4993,11 +4993,22 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (use_proj) {
const float mval[2] = {UNPACK2(event->mval)};
- float no_dummy[3];
- float dist_px_dummy;
- snapObjectsContext(
- C, mval, SNAP_NOT_OBEDIT,
- location, no_dummy, &dist_px_dummy);
+
+ struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C), vc.scene, 0,
+ vc.ar, vc.v3d);
+
+ ED_transform_snap_object_project_view3d_mixed(
+ snap_context,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_NOT_OBEDIT,
+ .snap_to_flag = SCE_SELECT_FACE,
+ },
+ mval, NULL, true,
+ location, NULL);
+
+
+ ED_transform_snap_object_context_destroy(snap_context);
}
if ((cu->flag & CU_3D) == 0) {
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 5c74a3e43c2..d24c33984ee 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -84,7 +84,7 @@ static float depth_read_zbuf(const ViewContext *vc, int x, int y)
static bool depth_unproject(
const ARegion *ar, const bglMats *mats,
- const int mval[2], const float depth,
+ const int mval[2], const double depth,
float r_location_world[3])
{
double p[3];
@@ -115,7 +115,7 @@ static bool depth_read_normal(
for (int y = 0; y < 2; y++) {
const int mval_ofs[2] = {mval[0] + (x - 1), mval[1] + (y - 1)};
- float depth = depth_read_zbuf(vc, mval_ofs[0], mval_ofs[1]);
+ const double depth = (double)depth_read_zbuf(vc, mval_ofs[0], mval_ofs[1]);
if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
if (depth_unproject(ar, mats, mval_ofs, depth, coords[i])) {
depths_valid[i] = true;
@@ -170,6 +170,11 @@ struct StrokeElem {
float mval[2];
float location_world[3];
float location_local[3];
+
+ /* surface normal, may be zero'd */
+ float normal_world[3];
+ float normal_local[3];
+
float pressure;
};
@@ -225,10 +230,26 @@ struct CurveDrawData {
void *draw_handle_view;
};
-static float stroke_elem_radius(const struct CurveDrawData *cdd, const struct StrokeElem *selem)
+static float stroke_elem_radius_from_pressure(const struct CurveDrawData *cdd, const float pressure)
{
const Curve *cu = cdd->vc.obedit->data;
- return ((selem->pressure * cdd->radius.range) + cdd->radius.min) * cu->ext2;
+ return ((pressure * cdd->radius.range) + cdd->radius.min) * cu->ext2;
+}
+
+static float stroke_elem_radius(const struct CurveDrawData *cdd, const struct StrokeElem *selem)
+{
+ return stroke_elem_radius_from_pressure(cdd, selem->pressure);
+}
+
+static void stroke_elem_pressure_set(const struct CurveDrawData *cdd, struct StrokeElem *selem, float pressure)
+{
+ if ((cdd->radius.offset != 0.0f) && !is_zero_v3(selem->normal_local)) {
+ const float adjust = stroke_elem_radius_from_pressure(cdd, pressure) -
+ stroke_elem_radius_from_pressure(cdd, selem->pressure);
+ madd_v3_v3fl(selem->location_local, selem->normal_local, adjust);
+ mul_v3_m4v3(selem->location_world, cdd->vc.obedit->obmat, selem->location_local);
+ }
+ selem->pressure = pressure;
}
static void stroke_elem_interp(
@@ -249,7 +270,7 @@ static bool stroke_elem_project(
const struct CurveDrawData *cdd,
const int mval_i[2], const float mval_fl[2],
const float radius_offset, const float radius,
- float r_location_world[3])
+ float r_location_world[3], float r_normal_world[3])
{
View3D *v3d = cdd->vc.v3d;
ARegion *ar = cdd->vc.ar;
@@ -266,6 +287,9 @@ static bool stroke_elem_project(
float lambda;
if (isect_ray_plane_v3(ray_origin, ray_direction, cdd->project.plane, &lambda, true)) {
madd_v3_v3v3fl(r_location_world, ray_origin, ray_direction, lambda);
+ if (r_normal_world) {
+ zero_v3(r_normal_world);
+ }
is_location_world_set = true;
}
}
@@ -275,15 +299,21 @@ static bool stroke_elem_project(
((unsigned int)mval_i[0] < depths->w) &&
((unsigned int)mval_i[1] < depths->h))
{
- float depth = depth_read_zbuf(&cdd->vc, mval_i[0], mval_i[1]);
+ const double depth = (double)depth_read_zbuf(&cdd->vc, mval_i[0], mval_i[1]);
if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
if (depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
is_location_world_set = true;
+ if (r_normal_world) {
+ zero_v3(r_normal_world);
+ }
if (radius_offset != 0.0f) {
float normal[3];
if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
madd_v3_v3fl(r_location_world, normal, radius_offset * radius);
+ if (r_normal_world) {
+ copy_v3_v3(r_normal_world, normal);
+ }
}
}
}
@@ -305,17 +335,28 @@ static bool stroke_elem_project_fallback(
const int mval_i[2], const float mval_fl[2],
const float radius_offset, const float radius,
const float location_fallback_depth[3],
- float r_location_world[3], float r_location_local[3])
+ float r_location_world[3], float r_location_local[3],
+ float r_normal_world[3], float r_normal_local[3])
{
bool is_depth_found = stroke_elem_project(
cdd, mval_i, mval_fl,
radius_offset, radius,
- r_location_world);
+ r_location_world, r_normal_world);
if (is_depth_found == false) {
ED_view3d_win_to_3d(cdd->vc.ar, location_fallback_depth, mval_fl, r_location_world);
+ zero_v3(r_normal_local);
}
mul_v3_m4v3(r_location_local, cdd->vc.obedit->imat, r_location_world);
+ if (!is_zero_v3(r_normal_world)) {
+ copy_v3_v3(r_normal_local, r_normal_world);
+ mul_transposed_mat3_m4_v3(cdd->vc.obedit->obmat, r_normal_local);
+ normalize_v3(r_normal_local);
+ }
+ else {
+ zero_v3(r_normal_local);
+ }
+
return is_depth_found;
}
@@ -333,7 +374,8 @@ static bool stroke_elem_project_fallback_elem(
cdd, mval_i, selem->mval,
cdd->radius.offset, radius,
location_fallback_depth,
- selem->location_world, selem->location_local);
+ selem->location_world, selem->location_local,
+ selem->normal_world, selem->normal_local);
}
/** \} */
@@ -602,7 +644,7 @@ static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
if (stroke_elem_project(
cdd, event->mval, mval_fl, 0.0f, 0.0f,
- location_no_offset))
+ location_no_offset, NULL))
{
sub_v3_v3v3(cdd->project.offset, cdd->prev.location_world_valid, location_no_offset);
if (!is_zero_v3(cdd->project.offset)) {
@@ -628,7 +670,7 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
view3d_set_viewcontext(C, &cdd->vc);
if (ELEM(NULL, cdd->vc.ar, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) {
MEM_freeN(cdd);
- BKE_report(op->reports, RPT_ERROR, "Unable to access 3D viewport.");
+ BKE_report(op->reports, RPT_ERROR, "Unable to access 3D viewport");
return false;
}
}
@@ -684,7 +726,7 @@ static void curve_draw_exec_precalc(wmOperator *op)
prop = RNA_struct_find_property(op->ptr, "corner_angle");
if (!RNA_property_is_set(op->ptr, prop)) {
- const float corner_angle = (cps->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) ? cps->corner_angle : M_PI;
+ const float corner_angle = (cps->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) ? cps->corner_angle : (float)M_PI;
RNA_property_float_set(op->ptr, prop, corner_angle);
}
@@ -738,20 +780,20 @@ static void curve_draw_exec_precalc(wmOperator *op)
selem_prev = selem;
}
- if (cps->radius_taper_start != 0.0) {
- selem_array[0]->pressure = 0.0f;
+ if (cps->radius_taper_start != 0.0f) {
const float len_taper_max = cps->radius_taper_start * len_3d;
- for (i = 1; i < stroke_len && lengths[i] < len_taper_max; i++) {
- selem_array[i]->pressure *= lengths[i] / len_taper_max;
+ for (i = 0; i < stroke_len && lengths[i] < len_taper_max; i++) {
+ const float pressure_new = selem_array[i]->pressure * (lengths[i] / len_taper_max);
+ stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
}
}
- if (cps->radius_taper_end != 0.0) {
- selem_array[stroke_len - 1]->pressure = 0.0f;
+ if (cps->radius_taper_end != 0.0f) {
const float len_taper_max = cps->radius_taper_end * len_3d;
const float len_taper_min = len_3d - len_taper_max;
- for (i = stroke_len - 2; i > 0 && lengths[i] > len_taper_min; i--) {
- selem_array[i]->pressure *= (len_3d - lengths[i]) / len_taper_max;
+ for (i = stroke_len - 1; i > 0 && lengths[i] > len_taper_min; i--) {
+ const float pressure_new = selem_array[i]->pressure * ((len_3d - lengths[i]) / len_taper_max);
+ stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
}
}
@@ -787,9 +829,9 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
ED_curve_deselect_all(cu->editnurb);
- const double radius_min = cps->radius_min;
- const double radius_max = cps->radius_max;
- const double radius_range = cps->radius_max - cps->radius_min;
+ const float radius_min = cps->radius_min;
+ const float radius_max = cps->radius_max;
+ const float radius_range = cps->radius_max - cps->radius_min;
Nurb *nu = MEM_callocN(sizeof(Nurb), __func__);
nu->pntsv = 1;
@@ -840,7 +882,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
unsigned int *corners = NULL;
unsigned int corners_len = 0;
- if (corner_angle < M_PI) {
+ if (corner_angle < (float)M_PI) {
/* this could be configurable... */
const float corner_radius_min = error_threshold / 8;
const float corner_radius_max = error_threshold * 2;
@@ -1058,7 +1100,7 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
cdd->project.use_depth = true;
}
else {
- BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane.");
+ BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
cdd->project.use_depth = false;
}
}
diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c
index 34e640a4b7b..c39a3aa5cfc 100644
--- a/source/blender/editors/gpencil/gpencil_undo.c
+++ b/source/blender/editors/gpencil/gpencil_undo.c
@@ -41,7 +41,7 @@
#include "BLI_listbase.h"
-#include "BKE_blender.h"
+#include "BKE_blender_undo.h"
#include "BKE_context.h"
#include "BKE_gpencil.h"
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index db8085a6696..39df52e5f68 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -43,6 +43,8 @@ struct wmEvent;
struct wmKeyConfig;
struct wmKeyMap;
struct wmOperatorType;
+struct Main;
+struct SnapObjectContext;
void transform_keymap_for_space(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int spaceid);
void transform_operatortypes(void);
@@ -187,27 +189,9 @@ bool peelObjectsContext(
struct ListBase *r_depth_peels);
bool snapObjectsTransform(
struct TransInfo *t, const float mval[2], SnapSelect snap_select,
+ float *dist_px,
/* return args */
- float r_loc[3], float r_no[3], float *r_dist_px);
-bool snapObjectsContext(
- struct bContext *C, const float mval[2], SnapSelect snap_select,
- /* return args */
- float r_loc[3], float r_no[3], float *r_dist_px);
-/* taks args for all settings */
-bool snapObjectsEx(
- struct Scene *scene, struct View3D *v3d, struct ARegion *ar, struct Base *base_act, struct Object *obedit,
- const float mval[2], SnapSelect snap_select, const short snap_mode,
- float *ray_depth,
- /* return args */
- float r_loc[3], float r_no[3], float *r_dist_px);
-bool snapObjectsRayEx(
- struct Scene *scene, struct View3D *v3d, struct ARegion *ar, struct Base *base_act, struct Object *obedit,
- const float mval[2], SnapSelect snap_select, const short snap_mode,
- const float ray_start[3], const float ray_normal[3], float *ray_depth,
- /* return args */
- float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
- struct Object **r_ob, float r_obmat[4][4]);
-
+ float r_loc[3], float r_no[3]);
bool snapNodesTransform(
struct TransInfo *t, const int mval[2], SnapSelect snap_select,
/* return args */
@@ -217,4 +201,67 @@ bool snapNodesContext(
/* return args */
float r_loc[2], float *r_dist_px, char *r_node_border);
+
+/* transform_snap_object.c */
+
+/* ED_transform_snap_object_*** API */
+struct SnapObjectParams {
+ SnapSelect snap_select;
+ union {
+ unsigned int snap_to : 4;
+ /* snap_target_flag: Snap to vert/edge/face. */
+ unsigned int snap_to_flag : 4;
+ };
+ /* use editmode cage */
+ unsigned int use_object_edit : 1;
+ /* special context sensitive handling for the active object */
+ unsigned int use_object_active : 1;
+};
+
+enum {
+ SNAP_OBJECT_USE_CACHE = (1 << 0),
+};
+
+typedef struct SnapObjectContext SnapObjectContext;
+SnapObjectContext *ED_transform_snap_object_context_create(
+ struct Main *bmain, struct Scene *scene, int flag);
+SnapObjectContext *ED_transform_snap_object_context_create_view3d(
+ struct Main *bmain, struct Scene *scene, int flag,
+ /* extra args for view3d */
+ struct ARegion *ar, struct View3D *v3d);
+void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx);
+
+bool ED_transform_snap_object_project_ray_ex(
+ struct SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float ray_start[3], const float ray_normal[3], float *ray_depth,
+ /* return args */
+ float r_loc[3], float r_no[3], int *r_index,
+ struct Object **r_ob, float r_obmat[4][4]);
+bool ED_transform_snap_object_project_ray(
+ SnapObjectContext *sctx,
+ const float ray_origin[3], const float ray_direction[3], float *ray_dist,
+ float r_co[3], float r_no[3]);
+
+bool ED_transform_snap_object_project_view3d_ex(
+ struct SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float mval[2], float *dist_px,
+ float *ray_depth,
+ float r_loc[3], float r_no[3], int *r_index);
+bool ED_transform_snap_object_project_view3d(
+ struct SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float mval[2], float *dist_px,
+ float *ray_depth,
+ /* return args */
+ float r_loc[3], float r_no[3]);
+bool ED_transform_snap_object_project_view3d_mixed(
+ SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float mval_fl[2], float *dist_px,
+ bool use_depth,
+ float r_co[3], float r_no[3]);
+
+
#endif /* __ED_TRANSFORM_H__ */
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index d8a3f5e75f5..c23c2eed890 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -396,18 +396,6 @@ void ED_view3d_operator_properties_viewmat_set(struct bContext *C, struct wmOper
void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, int *winx, int *winy, float persmat[4][4]);
#endif
-bool ED_view3d_snap_from_region(
- struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
- const float mval[2], float dist_px,
- bool use_depth, bool use_obedit,
- bool use_vert, bool use_edge, bool use_face,
- float r_co[3], float r_no[3]);
-
-bool ED_view3d_snap_from_ray(
- struct Scene *scene,
- const float ray_start[3], const float ray_normal[3],
- float r_co[3]);
-
/* render */
void ED_view3d_stop_render_preview(struct wmWindowManager *wm, struct ARegion *ar);
void ED_view3d_shade_update(struct Main *bmain, struct Scene *scene, struct View3D *v3d, struct ScrArea *sa);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 6c961179c6f..dd686f18a78 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -60,7 +60,7 @@
#include "PIL_time.h"
-#include "BKE_blender.h"
+#include "BKE_blender_undo.h"
#include "BKE_brush.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 2fdd84b626b..62b373c58c8 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -1679,7 +1679,7 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active)
BLF_size(fontid, fstyle_points, U.dpi);
BLF_enable(fontid, BLF_SHADOW);
- BLF_shadow(fontid, 3, 1.0f, 1.0f, 1.0f, 0.25f);
+ BLF_shadow(fontid, 3, (const float[4]){1.0f, 1.0f, 1.0f, 0.25f});
BLF_shadow_offset(fontid, -1, -1);
BLI_assert(UI_panel_category_is_visible(ar));
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index b3972bebd96..9e49d7e7e90 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -3006,7 +3006,8 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev
}
if (mt->poll && mt->poll(C, mt) == 0)
- return OPERATOR_CANCELLED;
+ /* cancel but allow event to pass through, just like operators do */
+ return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event);
layout = UI_pie_menu_layout(pie);
@@ -3237,7 +3238,8 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports)
}
if (mt->poll && mt->poll(C, mt) == 0)
- return OPERATOR_CANCELLED;
+ /* cancel but allow event to pass through, just like operators do */
+ return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
pup = UI_popup_menu_begin(C, IFACE_(mt->label), ICON_NONE);
layout = UI_popup_menu_layout(pup);
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index bfde02dbefd..423c48e5f55 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -160,7 +160,8 @@ void UI_fontstyle_draw_ex(
/* set the flag */
if (fs->shadow) {
font_flag |= BLF_SHADOW;
- BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
+ const float shadow_color[4] = {fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha};
+ BLF_shadow(fs->uifont_id, fs->shadow, shadow_color);
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
}
if (fs->kerning == 1) {
@@ -251,7 +252,8 @@ void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const ch
if (fs->shadow) {
BLF_enable(fs->uifont_id, BLF_SHADOW);
- BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
+ const float shadow_color[4] = {fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha};
+ BLF_shadow(fs->uifont_id, fs->shadow, shadow_color);
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
}
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index b1d2e329da1..3c862666aa6 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -96,7 +96,7 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
static char setting = 0;
const char *cp = error;
- /* ensure we're not getting a color after running BKE_userdef_free */
+ /* ensure we're not getting a color after running BKE_blender_userdef_free */
BLI_assert(BLI_findindex(&U.themes, theme_active) != -1);
BLI_assert(colorid != TH_UNDEFINED);
diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c
index 822bb429f9e..e3e8f35e7d8 100644
--- a/source/blender/editors/mask/mask_add.c
+++ b/source/blender/editors/mask/mask_add.c
@@ -194,12 +194,12 @@ bool ED_mask_find_nearest_diff_point(const bContext *C,
/******************** add vertex *********************/
-static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point,
- const float point_co[2], const float u,
- MaskSplinePoint *reference_point, const bool reference_adjacent)
+static void setup_vertex_point(
+ Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point,
+ const float point_co[2], const float u, const float ctime,
+ const MaskSplinePoint *reference_point, const bool reference_adjacent)
{
- MaskSplinePoint *prev_point = NULL;
- MaskSplinePoint *next_point = NULL;
+ const MaskSplinePoint *reference_parent_point = NULL;
BezTriple *bezt;
float co[3];
@@ -247,14 +247,44 @@ static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint *
else {
bezt->h1 = bezt->h2 = MAX2(reference_point->bezt.h2, reference_point->bezt.h1);
}
+
+ reference_parent_point = reference_point;
}
else if (reference_adjacent) {
if (spline->tot_point != 1) {
- int index = (int)(new_point - spline->points);
- prev_point = &spline->points[(index - 1) % spline->tot_point];
- next_point = &spline->points[(index + 1) % spline->tot_point];
+ MaskSplinePoint *prev_point, *next_point, *close_point;
- bezt->h1 = bezt->h2 = MAX2(prev_point->bezt.h2, next_point->bezt.h1);
+ const int index = (int)(new_point - spline->points);
+ if (spline->flag & MASK_SPLINE_CYCLIC) {
+ prev_point = &spline->points[mod_i(index - 1, spline->tot_point)];
+ next_point = &spline->points[mod_i(index + 1, spline->tot_point)];
+ }
+ else {
+ prev_point = (index != 0) ? &spline->points[index - 1] : NULL;
+ next_point = (index != spline->tot_point - 1) ? &spline->points[index + 1] : NULL;
+ }
+
+ if (prev_point && next_point) {
+ close_point = (len_squared_v2v2(new_point->bezt.vec[1], prev_point->bezt.vec[1]) <
+ len_squared_v2v2(new_point->bezt.vec[1], next_point->bezt.vec[1])) ?
+ prev_point : next_point;
+ }
+ else {
+ close_point = prev_point ? prev_point : next_point;
+ }
+
+ /* handle type */
+ char handle_type = 0;
+ if (prev_point) {
+ handle_type = prev_point->bezt.h2;
+ }
+ if (next_point) {
+ handle_type = MAX2(next_point->bezt.h2, handle_type);
+ }
+ bezt->h1 = bezt->h2 = handle_type;
+
+ /* parent */
+ reference_parent_point = close_point;
/* note, we may want to copy other attributes later, radius? pressure? color? */
}
@@ -264,7 +294,20 @@ static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint *
copy_v3_v3(bezt->vec[1], co);
copy_v3_v3(bezt->vec[2], co);
- BKE_mask_parent_init(&new_point->parent);
+ if (reference_parent_point) {
+ new_point->parent = reference_parent_point->parent;
+
+ if (new_point->parent.id) {
+ float parent_matrix[3][3];
+ BKE_mask_point_parent_matrix_get(new_point, ctime, parent_matrix);
+ invert_m3(parent_matrix);
+ mul_m3_v2(parent_matrix, new_point->bezt.vec[1]);
+ }
+ }
+ else {
+ BKE_mask_parent_init(&new_point->parent);
+ }
+
if (spline->tot_point != 1) {
BKE_mask_calc_handle_adjacent_interp(spline, new_point, u);
}
@@ -348,6 +391,9 @@ static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2
if (ED_mask_find_nearest_diff_point(C, mask, co, threshold, false, tangent, true, true,
&masklay, &spline, &point, &u, NULL))
{
+ Scene *scene = CTX_data_scene(C);
+ const float ctime = CFRA;
+
MaskSplinePoint *new_point;
int point_index = point - spline->points;
@@ -357,7 +403,7 @@ static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2
new_point = &spline->points[point_index + 1];
- setup_vertex_point(mask, spline, new_point, co, u, NULL, true);
+ setup_vertex_point(mask, spline, new_point, co, u, ctime, NULL, true);
/* TODO - we could pass the spline! */
BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index + 1, true, true);
@@ -375,6 +421,9 @@ static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2
static bool add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
{
+ Scene *scene = CTX_data_scene(C);
+ const float ctime = CFRA;
+
MaskSpline *spline;
MaskSplinePoint *point;
MaskSplinePoint *new_point = NULL, *ref_point = NULL;
@@ -454,7 +503,7 @@ static bool add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *masklay
masklay->act_point = new_point;
- setup_vertex_point(mask, spline, new_point, co, 0.5f, ref_point, false);
+ setup_vertex_point(mask, spline, new_point, co, 0.5f, ctime, ref_point, false);
if (masklay->splines_shapes.first) {
point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
@@ -468,34 +517,28 @@ static bool add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *masklay
static bool add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
{
+ Scene *scene = CTX_data_scene(C);
+ const float ctime = CFRA;
+
MaskSpline *spline;
- MaskSplinePoint *point;
MaskSplinePoint *new_point = NULL, *ref_point = NULL;
if (!masklay) {
/* if there's no masklay currently operationg on, create new one */
masklay = BKE_mask_layer_new(mask, "");
mask->masklay_act = mask->masklay_tot - 1;
- spline = NULL;
- point = NULL;
- }
- else {
- finSelectedSplinePoint(masklay, &spline, &point, true);
}
ED_mask_select_toggle_all(mask, SEL_DESELECT);
- if (!spline) {
- /* no selected splines in active masklay, create new spline */
- spline = BKE_mask_spline_add(masklay);
- }
+ spline = BKE_mask_spline_add(masklay);
masklay->act_spline = spline;
new_point = spline->points;
masklay->act_point = new_point;
- setup_vertex_point(mask, spline, new_point, co, 0.5f, ref_point, false);
+ setup_vertex_point(mask, spline, new_point, co, 0.5f, ctime, ref_point, false);
{
int point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index 847a7b5336e..5eaac72590b 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -137,8 +137,11 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
opdata->mesh_backup = EDBM_redo_state_store(em);
opdata->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
G.moving = G_TRANSFORM_EDIT;
- opdata->twtype = v3d->twtype;
- v3d->twtype = 0;
+
+ if (v3d) {
+ opdata->twtype = v3d->twtype;
+ v3d->twtype = 0;
+ }
}
return true;
@@ -206,7 +209,9 @@ static void edbm_bevel_exit(bContext *C, wmOperator *op)
ARegion *ar = CTX_wm_region(C);
EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
- v3d->twtype = opdata->twtype;
+ if (v3d) {
+ v3d->twtype = opdata->twtype;
+ }
G.moving = 0;
}
MEM_freeN(opdata);
diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c
index 161159d0be0..2401b749ab2 100644
--- a/source/blender/editors/mesh/editmesh_extrude.c
+++ b/source/blender/editors/mesh/editmesh_extrude.c
@@ -673,7 +673,7 @@ void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot)
/* api callbacks */
ot->invoke = edbm_dupli_extrude_cursor_invoke;
- ot->poll = ED_operator_editmesh;
+ ot->poll = ED_operator_editmesh_region_view3d;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -732,8 +732,17 @@ static int edbm_spin_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = ED_view3d_context_rv3d(C);
- RNA_float_set_array(op->ptr, "center", ED_view3d_cursor3d_get(scene, v3d));
- RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]);
+ PropertyRNA *prop;
+ prop = RNA_struct_find_property(op->ptr, "center");
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ RNA_property_float_set_array(op->ptr, prop, ED_view3d_cursor3d_get(scene, v3d));
+ }
+ if (rv3d) {
+ prop = RNA_struct_find_property(op->ptr, "axis");
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ RNA_property_float_set_array(op->ptr, prop, rv3d->viewinv[1]);
+ }
+ }
return edbm_spin_exec(C, op);
}
@@ -859,8 +868,17 @@ static int edbm_screw_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = ED_view3d_context_rv3d(C);
- RNA_float_set_array(op->ptr, "center", ED_view3d_cursor3d_get(scene, v3d));
- RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]);
+ PropertyRNA *prop;
+ prop = RNA_struct_find_property(op->ptr, "center");
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ RNA_property_float_set_array(op->ptr, prop, ED_view3d_cursor3d_get(scene, v3d));
+ }
+ if (rv3d) {
+ prop = RNA_struct_find_property(op->ptr, "axis");
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ RNA_property_float_set_array(op->ptr, prop, rv3d->viewinv[1]);
+ }
+ }
return edbm_screw_exec(C, op);
}
diff --git a/source/blender/editors/mesh/editmesh_inset.c b/source/blender/editors/mesh/editmesh_inset.c
index 937547c99ef..097117cce6b 100644
--- a/source/blender/editors/mesh/editmesh_inset.c
+++ b/source/blender/editors/mesh/editmesh_inset.c
@@ -143,8 +143,10 @@ static bool edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal)
opdata->mesh_backup = EDBM_redo_state_store(em);
opdata->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
G.moving = G_TRANSFORM_EDIT;
- opdata->twtype = v3d->twtype;
- v3d->twtype = 0;
+ if (v3d) {
+ opdata->twtype = v3d->twtype;
+ v3d->twtype = 0;
+ }
}
return true;
@@ -162,7 +164,9 @@ static void edbm_inset_exit(bContext *C, wmOperator *op)
ARegion *ar = CTX_wm_region(C);
EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
- v3d->twtype = opdata->twtype;
+ if (v3d) {
+ v3d->twtype = opdata->twtype;
+ }
G.moving = 0;
}
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 17250fbfb09..84ae35fae6e 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -2430,13 +2430,10 @@ static void select_linked_delimit_validate(BMesh *bm, int *delimit)
}
}
-static void select_linked_delimit_begin(BMesh *bm, short selectmode, int delimit)
+static void select_linked_delimit_begin(BMesh *bm, int delimit)
{
struct DelimitData delimit_data = {0};
- BMIter iter;
- BMEdge *e;
-
if (delimit & BMO_DELIM_UV) {
delimit_data.cd_loop_type = CD_MLOOPUV;
delimit_data.cd_loop_offset = CustomData_get_offset(&bm->ldata, delimit_data.cd_loop_type);
@@ -2447,19 +2444,13 @@ static void select_linked_delimit_begin(BMesh *bm, short selectmode, int delimit
/* grr, shouldn't need to alloc BMO flags here */
BM_mesh_elem_toolflags_ensure(bm);
- if (selectmode == SCE_SELECT_FACE) {
- BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
- const bool is_walk_ok = (
- (select_linked_delimit_test(e, delimit, &delimit_data) == false));
- BMO_elem_flag_set(bm, e, BMO_ELE_TAG, is_walk_ok);
- }
- }
- else {
- /* don't delimit selected edges in vert/edge mode */
+ {
+ BMIter iter;
+ BMEdge *e;
+
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
const bool is_walk_ok = (
- BM_elem_flag_test(e, BM_ELEM_SELECT) ||
(select_linked_delimit_test(e, delimit, &delimit_data) == false));
BMO_elem_flag_set(bm, e, BMO_ELE_TAG, is_walk_ok);
@@ -2491,7 +2482,7 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op)
select_linked_delimit_validate(bm, &delimit);
if (delimit) {
- select_linked_delimit_begin(em->bm, em->selectmode, delimit);
+ select_linked_delimit_begin(em->bm, delimit);
}
if (em->selectmode & SCE_SELECT_VERTEX) {
@@ -2501,6 +2492,17 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op)
BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT));
}
+ /* exclude all delimited verts */
+ if (delimit) {
+ BMEdge *e;
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (!BMO_elem_flag_test(bm, e, BMO_ELE_TAG)) {
+ BM_elem_flag_disable(e->v1, BM_ELEM_TAG);
+ BM_elem_flag_disable(e->v2, BM_ELEM_TAG);
+ }
+ }
+ }
+
BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL,
BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP,
BMW_FLAG_TEST_HIDDEN,
@@ -2546,8 +2548,17 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op)
else if (em->selectmode & SCE_SELECT_EDGE) {
BMEdge *e;
- BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
- BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT));
+ if (delimit) {
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ BM_elem_flag_set(
+ e, BM_ELEM_TAG,
+ (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_elem_flag_test(bm, e, BMO_ELE_TAG)));
+ }
+ }
+ else {
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT));
+ }
}
BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL,
@@ -2661,7 +2672,7 @@ static void edbm_select_linked_pick_ex(BMEditMesh *em, BMElem *ele, bool sel, in
select_linked_delimit_validate(bm, &delimit);
if (delimit) {
- select_linked_delimit_begin(bm, em->selectmode, delimit);
+ select_linked_delimit_begin(bm, delimit);
}
/* Note: logic closely matches 'edbm_select_linked_exec', keep in sync */
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index ee33f5f1655..44f0c6f2248 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -301,20 +301,30 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
ED_view3d_init_mats_rv3d(obedit, ar->regiondata);
+ struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C), CTX_data_scene(C), SNAP_OBJECT_USE_CACHE,
+ ar, CTX_wm_view3d(C));
+
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
- float mval[2], co_proj[3], no_dummy[3];
- float dist_px_dummy;
+ float mval[2], co_proj[3];
if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
- if (snapObjectsContext(
- C, mval, SNAP_NOT_OBEDIT,
- co_proj, no_dummy, &dist_px_dummy))
+ if (ED_transform_snap_object_project_view3d_mixed(
+ snap_context,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_NOT_OBEDIT,
+ .snap_to_flag = SCE_SELECT_FACE,
+ },
+ mval, NULL, true,
+ co_proj, NULL))
{
mul_v3_m4v3(eve->co, obedit->imat, co_proj);
}
}
}
}
+
+ ED_transform_snap_object_context_destroy(snap_context);
}
@@ -532,7 +542,7 @@ void MESH_OT_edge_collapse(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-static int edbm_add_edge_face__smooth_get(BMesh *bm)
+static bool edbm_add_edge_face__smooth_get(BMesh *bm)
{
BMEdge *e;
BMIter iter;
@@ -700,7 +710,7 @@ static int edbm_add_edge_face_exec(bContext *C, wmOperator *op)
BMOperator bmop;
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
- const short use_smooth = edbm_add_edge_face__smooth_get(em->bm);
+ const bool use_smooth = edbm_add_edge_face__smooth_get(em->bm);
const int totedge_orig = em->bm->totedge;
const int totface_orig = em->bm->totface;
/* when this is used to dissolve we could avoid this, but checking isnt too slow */
@@ -3566,7 +3576,7 @@ static int edbm_fill_grid_exec(bContext *C, wmOperator *op)
BMOperator bmop;
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
- const short use_smooth = edbm_add_edge_face__smooth_get(em->bm);
+ const bool use_smooth = edbm_add_edge_face__smooth_get(em->bm);
const int totedge_orig = em->bm->totedge;
const int totface_orig = em->bm->totface;
const bool use_interp_simple = RNA_boolean_get(op->ptr, "use_interp_simple");
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index 888bf832042..11d96da5786 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -700,7 +700,7 @@ static void bake_startjob(void *bkv, short *stop, short *do_update, float *progr
bkr->progress = progress;
RE_test_break_cb(bkr->re, NULL, thread_break);
- G.is_break = false; /* blender_test_break uses this global */
+ G.is_break = false; /* BKE_blender_test_break uses this global */
RE_Database_Baking(bkr->re, bmain, scene, scene->lay, scene->r.bake_mode, bkr->actob);
@@ -827,7 +827,7 @@ static int bake_image_exec(bContext *C, wmOperator *op)
bkr.reports = op->reports;
RE_test_break_cb(bkr.re, NULL, thread_break);
- G.is_break = false; /* blender_test_break uses this global */
+ G.is_break = false; /* BKE_blender_test_break uses this global */
RE_Database_Baking(bkr.re, bmain, scene, scene->lay, scene->r.bake_mode, (scene->r.bake_flag & R_BAKE_TO_ACTIVE) ? OBACT : NULL);
@@ -843,7 +843,7 @@ static int bake_image_exec(bContext *C, wmOperator *op)
/* used to redraw in 2.4x but this is just for exec in 2.5 */
if (!G.background)
- blender_test_break();
+ BKE_blender_test_break();
}
BLI_end_threads(&threads);
diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c
index 7cc17e4bfea..a5d2d2c8be7 100644
--- a/source/blender/editors/physics/dynamicpaint_ops.c
+++ b/source/blender/editors/physics/dynamicpaint_ops.c
@@ -39,7 +39,6 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "BKE_blender.h"
#include "BKE_context.h"
#include "BKE_deform.h"
#include "BKE_object_deform.h"
@@ -426,7 +425,7 @@ static void dpaint_bake_startjob(void *customdata, short *stop, short *do_update
job->start = PIL_check_seconds_timer();
job->success = 1;
- G.is_break = false; /* reset blender_test_break*/
+ G.is_break = false; /* reset BKE_blender_test_break*/
/* XXX annoying hack: needed to prevent data corruption when changing
* scene frame in separate threads
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index eb8ea01f750..1203889cf0e 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -49,7 +49,8 @@
#include "DNA_view3d_types.h"
#include "DNA_userdef_types.h"
-#include "BKE_blender.h"
+#include "BKE_blender_undo.h"
+#include "BKE_blender_version.h"
#include "BKE_camera.h"
#include "BKE_context.h"
#include "BKE_colortools.h"
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index b7ad911b6f5..a1c330d9dff 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -795,8 +795,13 @@ void bglPolygonOffset(float viewdist, float dist)
#endif
}
else {
- /* should be clipping value or so... */
- offs = 0.0005f * dist;
+ /* This adjustment effectively results in reducing the Z value by 0.25%.
+ *
+ * winmat[14] actually evaluates to `-2 * far * near / (far - near)`,
+ * is very close to -0.2 with default clip range, and is used as the coefficient multiplied by `w / z`,
+ * thus controlling the z dependent part of the depth value.
+ */
+ offs = winmat[14] * -0.0025f * dist;
}
winmat[14] -= offs;
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index b8693639673..f614025fa0e 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -1100,6 +1100,10 @@ static void uv_image_outset(
float (*orig_uv)[2], float (*outset_uv)[2], const float scaler,
const int ibuf_x, const int ibuf_y, const bool cw)
{
+ /* disallow shell-thickness to outset extreme values,
+ * otherwise near zero area UV's may extend thousands of pixels. */
+ const float scale_clamp = 5.0f;
+
float a1, a2, a3;
float puv[3][2]; /* pixelspace uv's */
float no1[2], no2[2], no3[2]; /* normals */
@@ -1150,6 +1154,10 @@ static void uv_image_outset(
a2 = shell_v2v2_normal_dir_to_dist(no2, dir1);
a3 = shell_v2v2_normal_dir_to_dist(no3, dir2);
+ CLAMP_MAX(a1, scale_clamp);
+ CLAMP_MAX(a2, scale_clamp);
+ CLAMP_MAX(a3, scale_clamp);
+
mul_v2_fl(no1, a1 * scaler);
mul_v2_fl(no2, a2 * scaler);
mul_v2_fl(no3, a3 * scaler);
diff --git a/source/blender/editors/sculpt_paint/paint_undo.c b/source/blender/editors/sculpt_paint/paint_undo.c
index 42f0aaab173..27d3f6648a2 100644
--- a/source/blender/editors/sculpt_paint/paint_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_undo.c
@@ -34,7 +34,7 @@
#include "DNA_userdef_types.h"
-#include "BKE_blender.h"
+#include "BKE_blender_undo.h"
#include "BKE_context.h"
#include "BKE_global.h"
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 6402e2d4de7..92be88bd5c6 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -2820,7 +2820,8 @@ static void vpaint_stroke_done(const bContext *C, struct PaintStroke *stroke)
struct VPaintData *vpd = paint_stroke_mode_data(stroke);
ViewContext *vc = &vpd->vc;
Object *ob = vc->obact;
-
+ Mesh *me = ob->data;
+
ED_vpaint_proj_handle_free(vpd->vp_handle);
MEM_freeN(vpd->indexar);
@@ -2831,6 +2832,7 @@ static void vpaint_stroke_done(const bContext *C, struct PaintStroke *stroke)
MEM_freeN(vpd->mlooptag);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+ DAG_id_tag_update(&me->id, 0);
MEM_freeN(vpd);
}
diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c
index b69547b0506..c0947dacbf0 100644
--- a/source/blender/editors/space_action/action_edit.c
+++ b/source/blender/editors/space_action/action_edit.c
@@ -239,6 +239,11 @@ static bool get_keyframe_extents(bAnimContext *ac, float *min, float *max, const
}
}
+ if (fabsf(*max - *min) < 0.001f) {
+ *min -= 0.0005f;
+ *max += 0.0005f;
+ }
+
/* free memory */
ANIM_animdata_freelist(&anim_data);
}
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 100329eddfc..7f4cd03c2fa 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -242,7 +242,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
if (params->display == FILE_DEFAULTDISPLAY) {
if (U.uiflag & USER_SHOW_THUMBNAILS) {
- if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE))
+ if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE | FILE_TYPE_FTFONT))
params->display = FILE_IMGDISPLAY;
else
params->display = FILE_SHORTDISPLAY;
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index e1cd1da3a25..effcd80e1f0 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -2393,7 +2393,9 @@ static EnumPropertyItem *graph_fmodifier_itemf(bContext *C, PointerRNA *UNUSED(p
continue;
index = RNA_enum_from_value(rna_enum_fmodifier_type_items, fmi->type);
- RNA_enum_item_add(&item, &totitem, &rna_enum_fmodifier_type_items[index]);
+ if (index != -1) { /* Not all types are implemented yet... */
+ RNA_enum_item_add(&item, &totitem, &rna_enum_fmodifier_type_items[index]);
+ }
}
RNA_enum_item_end(&item, &totitem);
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index f22152651e2..a2db6827b0e 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -177,7 +177,7 @@ void image_preview_event(int event)
G.is_break = false;
G.scene->nodetree->timecursor = set_timecursor;
- G.scene->nodetree->test_break = blender_test_break;
+ G.scene->nodetree->test_break = BKE_blender_test_break;
BIF_store_spare();
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 80dbfa140f6..ae5dcc4c73f 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -149,6 +149,34 @@ static void sima_zoom_set_factor(SpaceImage *sima, ARegion *ar, float zoomfac, c
sima_zoom_set(sima, ar, sima->zoom * zoomfac, location);
}
+/**
+ * Fits the view to the bounds exactly, caller should add margin if needed.
+ */
+static void sima_zoom_set_from_bounds(SpaceImage *sima, ARegion *ar, const rctf *bounds)
+{
+ int image_size[2];
+ float aspx, aspy;
+
+ ED_space_image_get_size(sima, &image_size[0], &image_size[1]);
+ ED_space_image_get_aspect(sima, &aspx, &aspy);
+
+ image_size[0] = image_size[0] * aspx;
+ image_size[1] = image_size[1] * aspy;
+
+ /* adjust offset and zoom */
+ sima->xof = roundf((BLI_rctf_cent_x(bounds) - 0.5f) * image_size[0]);
+ sima->yof = roundf((BLI_rctf_cent_y(bounds) - 0.5f) * image_size[1]);
+
+ float size_xy[2], size;
+ size_xy[0] = BLI_rcti_size_x(&ar->winrct) / (BLI_rctf_size_x(bounds) * image_size[0]);
+ size_xy[1] = BLI_rcti_size_y(&ar->winrct) / (BLI_rctf_size_y(bounds) * image_size[1]);
+
+ size = min_ff(size_xy[0], size_xy[1]);
+ CLAMP_MAX(size, 100.0f);
+
+ sima_zoom_set(sima, ar, size, NULL);
+}
+
#if 0 // currently unused
static int image_poll(bContext *C)
{
@@ -763,8 +791,6 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
Scene *scene;
Object *obedit;
Image *ima;
- float size, min[2], max[2], d[2], aspx, aspy;
- int width, height;
/* retrieve state */
sima = CTX_wm_space_image(C);
@@ -773,33 +799,28 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
obedit = CTX_data_edit_object(C);
ima = ED_space_image(sima);
- ED_space_image_get_size(sima, &width, &height);
- ED_space_image_get_aspect(sima, &aspx, &aspy);
-
- width = width * aspx;
- height = height * aspy;
/* get bounds */
+ float min[2], max[2];
if (ED_space_image_show_uvedit(sima, obedit)) {
- if (!ED_uvedit_minmax(scene, ima, obedit, min, max))
+ if (!ED_uvedit_minmax(scene, ima, obedit, min, max)) {
return OPERATOR_CANCELLED;
+ }
}
else if (ED_space_image_check_show_maskedit(scene, sima)) {
if (!ED_mask_selected_minmax(C, min, max)) {
return OPERATOR_CANCELLED;
}
}
+ rctf bounds = {
+ .xmin = min[0], .ymin = min[1],
+ .xmax = max[0], .ymax = max[1],
+ };
- /* adjust offset and zoom */
- sima->xof = (int)(((min[0] + max[0]) * 0.5f - 0.5f) * width);
- sima->yof = (int)(((min[1] + max[1]) * 0.5f - 0.5f) * height);
+ /* add some margin */
+ BLI_rctf_scale(&bounds, 1.4f);
- d[0] = max[0] - min[0];
- d[1] = max[1] - min[1];
- size = 0.5f * MAX2(d[0], d[1]) * MAX2(width, height) / 256.0f;
-
- if (size <= 0.01f) size = 0.01f;
- sima_zoom_set(sima, ar, 0.7f / size, NULL);
+ sima_zoom_set_from_bounds(sima, ar, &bounds);
ED_region_tag_redraw(ar);
@@ -3140,7 +3161,7 @@ static int image_record_composite_apply(bContext *C, wmOperator *op)
WM_cursor_time(CTX_wm_window(C), scene->r.cfra);
- // XXX scene->nodetree->test_break = blender_test_break;
+ // XXX scene->nodetree->test_break = BKE_blender_test_break;
// XXX scene->nodetree->test_break = NULL;
BKE_image_all_free_anim_ibufs(scene->r.cfra);
diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c
index fe66750a9ec..6e156750815 100644
--- a/source/blender/editors/space_info/info_stats.c
+++ b/source/blender/editors/space_info/info_stats.c
@@ -45,7 +45,7 @@
#include "BLT_translation.h"
#include "BKE_anim.h"
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
#include "BKE_DerivedMesh.h"
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c
index baf87f3fee5..a2159696394 100644
--- a/source/blender/editors/space_nla/nla_edit.c
+++ b/source/blender/editors/space_nla/nla_edit.c
@@ -2259,7 +2259,9 @@ static EnumPropertyItem *nla_fmodifier_itemf(bContext *C, PointerRNA *UNUSED(ptr
continue;
index = RNA_enum_from_value(rna_enum_fmodifier_type_items, fmi->type);
- RNA_enum_item_add(&item, &totitem, &rna_enum_fmodifier_type_items[index]);
+ if (index != -1) { /* Not all types are implemented yet... */
+ RNA_enum_item_add(&item, &totitem, &rna_enum_fmodifier_type_items[index]);
+ }
}
RNA_enum_item_end(&item, &totitem);
diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c
index 0cbb7ea0220..9d1cf65b8ac 100644
--- a/source/blender/editors/space_node/node_templates.c
+++ b/source/blender/editors/space_node/node_templates.c
@@ -32,6 +32,7 @@
#include "DNA_node_types.h"
#include "DNA_screen_types.h"
+#include "BLI_array.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
@@ -420,6 +421,13 @@ static int ui_compatible_sockets(int typeA, int typeB)
return (typeA == typeB);
}
+static int ui_node_item_name_compare(const void *a, const void *b)
+{
+ const bNodeType* type_a = *(const bNodeType**)a;
+ const bNodeType* type_b = *(const bNodeType**)b;
+ return BLI_natstrcmp(type_a->ui_name, type_b->ui_name);
+}
+
static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
{
bNodeTree *ntree = arg->ntree;
@@ -439,7 +447,26 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
compatibility = NODE_OLD_SHADING;
}
+ /* generate array of node types sorted by UI name */
+ bNodeType **sorted_ntypes = NULL;
+ BLI_array_declare(sorted_ntypes);
+
NODE_TYPES_BEGIN(ntype) {
+ if (compatibility && !(ntype->compatibility & compatibility))
+ continue;
+
+ if (ntype->nclass != nclass)
+ continue;
+
+ BLI_array_append(sorted_ntypes, ntype);
+ }
+ NODE_TYPES_END
+
+ qsort(sorted_ntypes, BLI_array_count(sorted_ntypes), sizeof(bNodeType*), ui_node_item_name_compare);
+
+ /* generate UI */
+ for (int j = 0; j < BLI_array_count(sorted_ntypes); j++) {
+ bNodeType *ntype = sorted_ntypes[j];
NodeLinkItem *items;
int totitems;
char name[UI_MAX_NAME_STR];
@@ -447,12 +474,6 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
int i, num = 0;
int icon = ICON_NONE;
- if (compatibility && !(ntype->compatibility & compatibility))
- continue;
-
- if (ntype->nclass != nclass)
- continue;
-
arg->node_type = ntype;
ui_node_link_items(arg, SOCK_OUT, &items, &totitems);
@@ -502,7 +523,8 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
if (items)
MEM_freeN(items);
}
- NODE_TYPES_END
+
+ BLI_array_free(sorted_ntypes);
}
static void node_menu_column_foreach_cb(void *calldata, int nclass, const char *name)
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 222fe27983c..2627b978b40 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -59,6 +59,7 @@
#include "ED_outliner.h"
#include "ED_screen.h"
#include "ED_keyframing.h"
+#include "ED_armature.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -743,14 +744,35 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
TreeElement *te;
int xdelta, ytop;
-
- // TODO: make this get this info from context instead...
- if (OBACT == NULL)
+
+ Object *obact = OBACT;
+
+ if (!obact)
return OPERATOR_CANCELLED;
-
- te = outliner_find_id(so, &so->tree, (ID *)OBACT);
+
+
+ te = outliner_find_id(so, &so->tree, &obact->id);
+
+ if (obact->type == OB_ARMATURE) {
+ /* traverse down the bone hierarchy in case of armature */
+ TreeElement *te_obact = te;
+
+ if (obact->mode & OB_MODE_POSE) {
+ bPoseChannel *pchan = CTX_data_active_pose_bone(C);
+ if (pchan) {
+ te = outliner_find_posechannel(so, &te_obact->subtree, pchan);
+ }
+ }
+ else if (obact->mode & OB_MODE_EDIT) {
+ EditBone *ebone = CTX_data_active_bone(C);
+ if (ebone) {
+ te = outliner_find_editbone(so, &te_obact->subtree, ebone);
+ }
+ }
+ }
+
if (te) {
- /* open up tree to active object */
+ /* open up tree to active object/bone */
if (outliner_open_back(te)) {
outliner_set_coordinates(ar, so);
}
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 3249c3f3ab7..155e41088d6 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -42,6 +42,8 @@ struct bContext;
struct Scene;
struct ID;
struct Object;
+struct bPoseChannel;
+struct EditBone;
typedef struct TreeElement {
struct TreeElement *next, *prev, *parent;
@@ -128,9 +130,11 @@ typedef enum {
void outliner_free_tree(ListBase *lb);
void outliner_cleanup_tree(struct SpaceOops *soops);
-TreeElement *outliner_find_tse(struct SpaceOops *soops, TreeStoreElem *tse);
-TreeElement *outliner_find_tree_element(ListBase *lb, TreeStoreElem *store_elem);
-TreeElement *outliner_find_id(struct SpaceOops *soops, ListBase *lb, struct ID *id);
+TreeElement *outliner_find_tse(struct SpaceOops *soops, const TreeStoreElem *tse);
+TreeElement *outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem);
+TreeElement *outliner_find_id(struct SpaceOops *soops, ListBase *lb, const struct ID *id);
+TreeElement *outliner_find_posechannel(struct SpaceOops *soops, ListBase *lb, const struct bPoseChannel *pchan);
+TreeElement *outliner_find_editbone(struct SpaceOops *soops, ListBase *lb, const struct EditBone *ebone);
struct ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode);
void outliner_build_tree(struct Main *mainvar, struct Scene *scene, struct SpaceOops *soops);
diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c
index 666179dd3c7..83d8519a7cb 100644
--- a/source/blender/editors/space_outliner/outliner_tree.c
+++ b/source/blender/editors/space_outliner/outliner_tree.c
@@ -198,7 +198,7 @@ void outliner_cleanup_tree(SpaceOops *soops)
}
/* Find specific item from the treestore */
-TreeElement *outliner_find_tree_element(ListBase *lb, TreeStoreElem *store_elem)
+TreeElement *outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem)
{
TreeElement *te, *tes;
for (te = lb->first; te; te = te->next) {
@@ -210,7 +210,7 @@ TreeElement *outliner_find_tree_element(ListBase *lb, TreeStoreElem *store_elem)
}
/* tse is not in the treestore, we use its contents to find a match */
-TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
+TreeElement *outliner_find_tse(SpaceOops *soops, const TreeStoreElem *tse)
{
TreeStoreElem *tselem;
@@ -225,25 +225,63 @@ TreeElement *outliner_find_tse(SpaceOops *soops, TreeStoreElem *tse)
}
/* Find treestore that refers to given ID */
-TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
+TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, const ID *id)
{
- TreeElement *te, *tes;
- TreeStoreElem *tselem;
-
- for (te = lb->first; te; te = te->next) {
- tselem = TREESTORE(te);
+ for (TreeElement *te = lb->first; te; te = te->next) {
+ TreeStoreElem *tselem = TREESTORE(te);
if (tselem->type == 0) {
- if (tselem->id == id) return te;
+ if (tselem->id == id) {
+ return te;
+ }
/* only deeper on scene or object */
- if (te->idcode == ID_OB || te->idcode == ID_SCE || (soops->outlinevis == SO_GROUPS && te->idcode == ID_GR)) {
- tes = outliner_find_id(soops, &te->subtree, id);
- if (tes) return tes;
+ if (ELEM(te->idcode, ID_OB, ID_SCE) ||
+ ((soops->outlinevis == SO_GROUPS) && (te->idcode == ID_GR)))
+ {
+ TreeElement *tes = outliner_find_id(soops, &te->subtree, id);
+ if (tes) {
+ return tes;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+TreeElement *outliner_find_posechannel(SpaceOops *soops, ListBase *lb, const bPoseChannel *pchan)
+{
+ for (TreeElement *te = lb->first; te; te = te->next) {
+ if (te->directdata == pchan) {
+ return te;
+ }
+
+ TreeStoreElem *tselem = TREESTORE(te);
+ if (ELEM(tselem->type, TSE_POSE_BASE, TSE_POSE_CHANNEL)) {
+ TreeElement *tes = outliner_find_posechannel(soops, &te->subtree, pchan);
+ if (tes) {
+ return tes;
}
}
}
return NULL;
}
+TreeElement *outliner_find_editbone(SpaceOops *soops, ListBase *lb, const EditBone *ebone)
+{
+ for (TreeElement *te = lb->first; te; te = te->next) {
+ if (te->directdata == ebone) {
+ return te;
+ }
+
+ TreeStoreElem *tselem = TREESTORE(te);
+ if (ELEM(tselem->type, 0, TSE_EBONE)) {
+ TreeElement *tes = outliner_find_editbone(soops, &te->subtree, ebone);
+ if (tes) {
+ return tes;
+ }
+ }
+ }
+ return NULL;
+}
ID *outliner_search_back(SpaceOops *UNUSED(soops), TreeElement *te, short idcode)
{
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 08f2961d1b3..f636a07b064 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -5167,85 +5167,3 @@ void ED_view3D_lock_clear(View3D *v3d)
v3d->ob_centre_cursor = false;
v3d->flag2 &= ~V3D_LOCK_CAMERA;
}
-
-/**
- * Convenience function for snap ray-casting.
- *
- * Given a ray, cast it into the scene (snapping to faces).
- *
- * \return Snap success
- */
-bool ED_view3d_snap_from_ray(
- Scene *scene,
- const float ray_start[3], const float ray_normal[3],
- float r_co[3])
-{
- float r_no_dummy[3];
- float ray_dist = BVH_RAYCAST_DIST_MAX;
- bool ret;
-
- struct Object *obedit = scene->obedit;
-
- /* try snap edge, then face if it fails */
- ret = snapObjectsRayEx(
- scene, NULL, NULL, NULL, obedit,
- NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
- ray_start, ray_normal, &ray_dist,
- r_co, r_no_dummy, NULL, NULL,
- NULL, NULL);
-
- return ret;
-}
-
-/**
- * Convenience function for performing snapping.
- *
- * Given a 2D region value, snap to vert/edge/face.
- *
- * \param mval: Screenspace coordinate.
- * \param dist_px: Maximum distance to snap (in pixels).
- * \param use_depth: Snap to the closest element, use when using more than one snap type.
- * \param use_obedit: Use editmode cage.
- * \param use_vert: Snap to verts.
- * \param use_edge: Snap to edges.
- * \param use_face: Snap to faces.
- * \param r_co: hit location.
- * \param r_no: hit normal (optional).
- * \return Snap success
- */
-bool ED_view3d_snap_from_region(
- Scene *scene, View3D *v3d, ARegion *ar,
- const float mval[2], float dist_px,
- bool use_depth, bool use_obedit,
- bool use_vert, bool use_edge, bool use_face,
- float r_co[3], float r_no[3])
-{
- float r_no_dummy[3];
- float ray_dist = BVH_RAYCAST_DIST_MAX;
- bool is_hit = false;
- float *r_no_ptr = r_no ? r_no : r_no_dummy;
-
- struct Object *obedit = use_obedit ? scene->obedit : NULL;
- const int elem_type[3] = {SCE_SNAP_MODE_VERTEX, SCE_SNAP_MODE_EDGE, SCE_SNAP_MODE_FACE};
- const bool elem_test[3] = {use_vert, use_edge, use_face};
-
- BLI_assert(use_vert || use_edge || use_face);
-
- for (int i = 0; i < 3; i++) {
- if (elem_test[i] && (is_hit == false || use_depth)) {
- if (use_depth == false) {
- ray_dist = BVH_RAYCAST_DIST_MAX;
- }
- if (snapObjectsEx(
- scene, v3d, ar, NULL, obedit,
- mval, SNAP_ALL, elem_type[i],
- &ray_dist,
- r_co, r_no_ptr, &dist_px))
- {
- is_hit = true;
- }
- }
- }
-
- return is_hit;
-}
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index a5411da131b..c30e688f1e7 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -44,7 +44,7 @@
#include "BLI_utildefines.h"
#include "BKE_appdir.h"
-#include "BKE_blender.h"
+#include "BKE_blender_copybuffer.h"
#include "BKE_context.h"
#include "BKE_main.h"
#include "BKE_report.h"
diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c
index 198cc3e5703..26eb707624a 100644
--- a/source/blender/editors/space_view3d/view3d_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_ruler.c
@@ -46,6 +46,7 @@
#include "ED_screen.h"
#include "ED_view3d.h"
+#include "ED_transform.h"
#include "ED_space_api.h"
#include "BLF_api.h"
@@ -109,6 +110,8 @@ typedef struct RulerInfo {
int state;
float drag_start_co[3];
+ struct SnapObjectContext *snap_context;
+
/* wm state */
wmWindow *win;
ScrArea *sa;
@@ -128,6 +131,7 @@ static RulerItem *ruler_item_add(RulerInfo *ruler_info)
static void ruler_item_remove(RulerInfo *ruler_info, RulerItem *ruler_item)
{
BLI_remlink(&ruler_info->items, ruler_item);
+
MEM_freeN(ruler_item);
}
@@ -632,6 +636,9 @@ static void view3d_ruler_end(const struct bContext *UNUSED(C), RulerInfo *ruler_
static void view3d_ruler_free(RulerInfo *ruler_info)
{
BLI_freelistN(&ruler_info->items);
+
+ ED_transform_snap_object_context_destroy(ruler_info->snap_context);
+
MEM_freeN(ruler_info);
}
@@ -642,11 +649,12 @@ static void view3d_ruler_item_project(RulerInfo *ruler_info, float r_co[3],
}
/* use for mousemove events */
-static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, const int mval[2],
- const bool do_thickness, const bool do_snap)
+static bool view3d_ruler_item_mousemove(
+ RulerInfo *ruler_info, const int mval[2],
+ const bool do_thickness, const bool do_snap)
{
const float eps_bias = 0.0002f;
- const float dist_px = MVAL_MAX_PX_DIST * U.pixelsize; /* snap dist */
+ float dist_px = MVAL_MAX_PX_DIST * U.pixelsize; /* snap dist */
RulerItem *ruler_item = ruler_item_active_get(ruler_info);
ruler_info->snap_flag &= ~RULER_SNAP_OK;
@@ -657,8 +665,8 @@ static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, cons
copy_v3_v3(co, ruler_info->drag_start_co);
view3d_ruler_item_project(ruler_info, co, mval);
if (do_thickness && ruler_item->co_index != 1) {
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = ruler_info->sa->spacedata.first;
+ // Scene *scene = CTX_data_scene(C);
+ // View3D *v3d = ruler_info->sa->spacedata.first;
const float mval_fl[2] = {UNPACK2(mval)};
float ray_normal[3];
float ray_start[3];
@@ -666,33 +674,37 @@ static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, cons
co_other = ruler_item->co[ruler_item->co_index == 0 ? 2 : 0];
- if (ED_view3d_snap_from_region(
- scene, v3d, ruler_info->ar,
- mval_fl, dist_px,
- true, false,
- false, false, true,
+ if (ED_transform_snap_object_project_view3d_mixed(
+ ruler_info->snap_context,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .snap_to_flag = SCE_SELECT_FACE,
+ },
+ mval_fl, &dist_px, true,
co, ray_normal))
{
negate_v3(ray_normal);
/* add some bias */
madd_v3_v3v3fl(ray_start, co, ray_normal, eps_bias);
- ED_view3d_snap_from_ray(
- scene,
- ray_start, ray_normal,
- co_other);
+ ED_transform_snap_object_project_ray(
+ ruler_info->snap_context,
+ ray_start, ray_normal, NULL,
+ co_other, NULL);
}
}
else if (do_snap) {
- Scene *scene = CTX_data_scene(C);
+ // Scene *scene = CTX_data_scene(C);
View3D *v3d = ruler_info->sa->spacedata.first;
const float mval_fl[2] = {UNPACK2(mval)};
bool use_depth = (v3d->drawtype >= OB_SOLID);
- if (ED_view3d_snap_from_region(
- scene, v3d, ruler_info->ar,
- mval_fl, dist_px,
- use_depth, false,
- true, true, use_depth,
+ if (ED_transform_snap_object_project_view3d_mixed(
+ ruler_info->snap_context,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .snap_to_flag = (SCE_SELECT_VERTEX | SCE_SELECT_EDGE) | (use_depth ? SCE_SELECT_FACE : 0),
+ },
+ mval_fl, &dist_px, use_depth,
co, NULL))
{
ruler_info->snap_flag |= RULER_SNAP_OK;
@@ -736,6 +748,10 @@ static int view3d_ruler_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
op->customdata = ruler_info;
+ ruler_info->snap_context = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C), CTX_data_scene(C), SNAP_OBJECT_USE_CACHE,
+ ar, CTX_wm_view3d(C));
+
ruler_info->win = win;
ruler_info->sa = sa;
ruler_info->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ruler_info_draw_pixel,
@@ -818,7 +834,7 @@ static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (use_depth) {
/* snap the first point added, not essential but handy */
ruler_item->co_index = 0;
- view3d_ruler_item_mousemove(C, ruler_info, event->mval, false, true);
+ view3d_ruler_item_mousemove(ruler_info, event->mval, false, true);
copy_v3_v3(ruler_info->drag_start_co, ruler_item->co[ruler_item->co_index]);
}
else {
@@ -871,7 +887,7 @@ static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
/* update the new location */
- view3d_ruler_item_mousemove(C, ruler_info, event->mval,
+ view3d_ruler_item_mousemove(ruler_info, event->mval,
event->shift != 0, event->ctrl != 0);
do_draw = true;
}
@@ -920,7 +936,7 @@ static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event)
case MOUSEMOVE:
{
if (ruler_info->state == RULER_STATE_DRAG) {
- if (view3d_ruler_item_mousemove(C, ruler_info, event->mval,
+ if (view3d_ruler_item_mousemove(ruler_info, event->mval,
event->shift != 0, event->ctrl != 0))
{
do_draw = true;
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 11623d06fff..fd7179d06dd 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -417,11 +417,12 @@ static void do_lasso_select_objects(ViewContext *vc, const int mcords[][2], cons
for (base = vc->scene->base.first; base; base = base->next) {
if (BASE_SELECTABLE(vc->v3d, base)) { /* use this to avoid un-needed lasso lookups */
- ED_view3d_project_base(vc->ar, base);
- if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) {
-
- ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT);
- base->object->flag = base->flag;
+ if (ED_view3d_project_base(vc->ar, base) == V3D_PROJ_RET_OK) {
+ if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) {
+
+ ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT);
+ base->object->flag = base->flag;
+ }
}
if (vc->obact == base->object && (base->object->mode & OB_MODE_POSE)) {
do_lasso_select_pose(vc, base->object, mcords, moves, select);
@@ -1093,20 +1094,22 @@ static Base *object_mouse_select_menu(bContext *C, ViewContext *vc, unsigned int
/* two selection methods, the CTRL select uses max dist of 15 */
if (buffer) {
- int a;
- for (a = 0; a < hits; a++) {
+ for (int a = 0; a < hits; a++) {
/* index was converted */
- if (base->selcol == buffer[(4 * a) + 3])
+ if (base->selcol == (buffer[(4 * a) + 3] & ~0xFFFF0000)) {
ok = true;
+ break;
+ }
}
}
else {
- int temp, dist = 15;
- ED_view3d_project_base(vc->ar, base);
-
- temp = abs(base->sx - mval[0]) + abs(base->sy - mval[1]);
- if (temp < dist)
- ok = true;
+ const int dist = 15 * U.pixelsize;
+ if (ED_view3d_project_base(vc->ar, base) == V3D_PROJ_RET_OK) {
+ const int delta_px[2] = {base->sx - mval[0], base->sy - mval[1]};
+ if (len_manhattan_v2_int(delta_px) < dist) {
+ ok = true;
+ }
+ }
}
if (ok) {
@@ -1465,7 +1468,7 @@ static bool ed_object_select_pick(
const bool has_bones = selectbuffer_has_bones(buffer, hits);
/* note; shift+alt goes to group-flush-selecting */
- if (has_bones == 0 && enumerate) {
+ if (enumerate) {
basact = object_mouse_select_menu(C, &vc, buffer, hits, mval, toggle);
}
else {
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
index 7e1202aef77..73ec0f664da 100644
--- a/source/blender/editors/space_view3d/view3d_walk.c
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -306,6 +306,8 @@ typedef struct WalkInfo {
float jump_height; /* maximum jump height */
float speed_factor; /* to use for fast/slow speeds */
+ struct SnapObjectContext *snap_context;
+
struct View3DCameraControl *v3d_camera_control;
} WalkInfo;
@@ -402,12 +404,14 @@ static void walk_navigation_mode_set(bContext *C, wmOperator *op, WalkInfo *walk
/**
* \param r_distance Distance to the hit point
*/
-static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *walk, const float dvec[3], float *r_distance)
+static bool walk_floor_distance_get(
+ RegionView3D *rv3d, WalkInfo *walk, const float dvec[3],
+ float *r_distance)
{
float ray_normal[3] = {0, 0, -1}; /* down */
float ray_start[3];
float r_location[3];
- float r_normal[3];
+ float r_normal_dummy[3];
float dvec_tmp[3];
bool ret;
@@ -418,12 +422,10 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w
mul_v3_v3fl(dvec_tmp, dvec, walk->grid);
add_v3_v3(ray_start, dvec_tmp);
- ret = snapObjectsRayEx(
- CTX_data_scene(C), NULL, NULL, NULL, NULL,
- NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
+ ret = ED_transform_snap_object_project_ray(
+ walk->snap_context,
ray_start, ray_normal, r_distance,
- r_location, r_normal, NULL, NULL,
- NULL, NULL);
+ r_location, r_normal_dummy);
/* artifically scale the distance to the scene size */
*r_distance /= walk->grid;
@@ -435,34 +437,30 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w
* \param r_location Location of the hit point
* \param r_normal Normal of the hit surface, transformed to always face the camera
*/
-static bool walk_ray_cast(bContext *C, RegionView3D *rv3d, WalkInfo *walk, float r_location[3], float r_normal[3], float *ray_distance)
+static bool walk_ray_cast(
+ RegionView3D *rv3d, WalkInfo *walk,
+ float r_location[3], float r_normal[3], float *ray_distance)
{
- float ray_normal[3] = {0, 0, 1}; /* forward */
+ float ray_normal[3] = {0, 0, -1}; /* forward */
float ray_start[3];
- float mat[3][3]; /* 3x3 copy of the view matrix so we can move along the view axis */
bool ret;
*ray_distance = BVH_RAYCAST_DIST_MAX;
copy_v3_v3(ray_start, rv3d->viewinv[3]);
- copy_m3_m4(mat, rv3d->viewinv);
- mul_m3_v3(mat, ray_normal);
+ mul_mat3_m4_v3(rv3d->viewinv, ray_normal);
- mul_v3_fl(ray_normal, -1);
normalize_v3(ray_normal);
- ret = snapObjectsRayEx(
- CTX_data_scene(C), NULL, NULL, NULL, NULL,
- NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
- ray_start, ray_normal, ray_distance,
- r_location, r_normal, NULL, NULL,
- NULL, NULL);
-
+ ret = ED_transform_snap_object_project_ray(
+ walk->snap_context,
+ ray_start, ray_normal, NULL,
+ r_location, r_normal);
/* dot is positive if both rays are facing the same direction */
if (dot_v3v3(ray_normal, r_normal) > 0) {
- copy_v3_fl3(r_normal, -r_normal[0], -r_normal[1], -r_normal[2]);
+ negate_v3(r_normal);
}
/* artifically scale the distance to the scene size */
@@ -575,6 +573,9 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
walk->rv3d->rflag |= RV3D_NAVIGATING;
+ walk->snap_context = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C), walk->scene, SNAP_OBJECT_USE_CACHE,
+ walk->ar, walk->v3d);
walk->v3d_camera_control = ED_view3d_cameracontrol_acquire(
walk->scene, walk->v3d, walk->rv3d,
@@ -625,6 +626,8 @@ static int walkEnd(bContext *C, WalkInfo *walk)
ED_region_draw_cb_exit(walk->ar->type, walk->draw_handle_pixel);
+ ED_transform_snap_object_context_destroy(walk->snap_context);
+
ED_view3d_cameracontrol_release(walk->v3d_camera_control, walk->state == WALK_CANCEL);
rv3d->rflag &= ~RV3D_NAVIGATING;
@@ -897,7 +900,7 @@ static void walkEvent(bContext *C, wmOperator *op, WalkInfo *walk, const wmEvent
{
float loc[3], nor[3];
float distance;
- bool ret = walk_ray_cast(C, walk->rv3d, walk, loc, nor, &distance);
+ bool ret = walk_ray_cast(walk->rv3d, walk, loc, nor, &distance);
/* in case we are teleporting middle way from a jump */
walk->speed_jump = 0.0f;
@@ -1178,7 +1181,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
float difference = -100.0f;
float fall_distance;
- ret = walk_floor_distance_get(C, rv3d, walk, dvec, &ray_distance);
+ ret = walk_floor_distance_get(rv3d, walk, dvec, &ray_distance);
if (ret) {
difference = walk->view_height - ray_distance;
@@ -1231,7 +1234,7 @@ static int walkApply(bContext *C, wmOperator *op, WalkInfo *walk)
if (t > walk->teleport.duration) {
/* check to see if we are landing */
- ret = walk_floor_distance_get(C, rv3d, walk, dvec, &ray_distance);
+ ret = walk_floor_distance_get(rv3d, walk, dvec, &ray_distance);
if (ret) {
difference = walk->view_height - ray_distance;
diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt
index f3047c088a9..b7de49d8158 100644
--- a/source/blender/editors/transform/CMakeLists.txt
+++ b/source/blender/editors/transform/CMakeLists.txt
@@ -49,6 +49,7 @@ set(SRC
transform_ops.c
transform_orientations.c
transform_snap.c
+ transform_snap_object.c
transform.h
)
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 6d6a9aa90bc..3c69a1cd6c3 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -101,6 +101,11 @@ typedef struct TransSnap {
* where the smallest absolute value defines whats closest.
*/
float (*distance)(struct TransInfo *, const float p1[3], const float p2[3]);
+
+ /**
+ * Re-usable snap context data.
+ */
+ SnapObjectContext *object_context;
} TransSnap;
typedef struct TransCon {
@@ -676,6 +681,7 @@ bool activeSnap(TransInfo *t);
bool validSnap(TransInfo *t);
void initSnapping(struct TransInfo *t, struct wmOperator *op);
+void freeSnapping(struct TransInfo *t);
void applyProject(TransInfo *t);
void applyGridAbsolute(TransInfo *t);
void applySnapping(TransInfo *t, float *vec);
@@ -785,4 +791,8 @@ void projectVertSlideData(TransInfo *t, bool is_final);
/* TODO. transform_queries.c */
bool checkUseAxisMatrix(TransInfo *t);
+#define TRANSFORM_DIST_MAX_PX 1000.0f
+#define TRANSFORM_SNAP_MAX_PX 100.0f
+#define TRANSFORM_DIST_INVALID -FLT_MAX
+
#endif
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 63b3e5244e9..537e6e65dce 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1493,6 +1493,8 @@ void postTrans(bContext *C, TransInfo *t)
if (t->mouse.data) {
MEM_freeN(t->mouse.data);
}
+
+ freeSnapping(t);
}
void applyTransObjects(TransInfo *t)
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 70ac225c431..236a223b5ff 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -36,8 +36,6 @@
#include "PIL_time.h"
-#include "DNA_armature_types.h"
-#include "DNA_curve_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_meshdata_types.h" /* Temporary, for snapping to other unselected meshes */
@@ -61,13 +59,11 @@
#include "BKE_editmesh.h"
#include "BKE_sequencer.h"
#include "BKE_main.h"
-#include "BKE_tracking.h"
#include "RNA_access.h"
#include "WM_types.h"
-#include "ED_armature.h"
#include "ED_image.h"
#include "ED_node.h"
#include "ED_uvedit.h"
@@ -83,10 +79,6 @@
/* this should be passed as an arg for use in snap functions */
#undef BASACT
-#define TRANSFORM_DIST_MAX_PX 1000.0f
-#define TRANSFORM_SNAP_MAX_PX 100.0f
-#define TRANSFORM_DIST_INVALID -FLT_MAX
-
/* use half of flt-max so we can scale up without an exception */
/********************* PROTOTYPES ***********************/
@@ -331,8 +323,8 @@ void applyProject(TransInfo *t)
if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
if (snapObjectsTransform(
- t, mval_fl, t->tsnap.modeSelect,
- loc, no, &dist_px))
+ t, mval_fl, t->tsnap.modeSelect, &dist_px,
+ loc, no))
{
// if (t->flag & (T_EDIT|T_POSE)) {
// mul_m4_v3(imat, loc);
@@ -565,6 +557,14 @@ static void initSnappingMode(TransInfo *t)
/* Always grid outside of 3D view */
t->tsnap.mode = SCE_SNAP_MODE_INCREMENT;
}
+
+ if (t->flag & (T_OBJECT | T_EDIT)) {
+ if (t->spacetype == SPACE_VIEW3D) {
+ t->tsnap.object_context = ED_transform_snap_object_context_create_view3d(
+ G.main, t->scene, SNAP_OBJECT_USE_CACHE,
+ t->ar, t->view);
+ }
+ }
}
void initSnapping(TransInfo *t, wmOperator *op)
@@ -628,6 +628,14 @@ void initSnapping(TransInfo *t, wmOperator *op)
initSnappingMode(t);
}
+void freeSnapping(TransInfo *t)
+{
+ if (t->tsnap.object_context) {
+ ED_transform_snap_object_context_destroy(t->tsnap.object_context);
+ t->tsnap.object_context = NULL;
+ }
+}
+
static void setSnappingCallback(TransInfo *t)
{
t->tsnap.calcSnap = CalcSnapGeometry;
@@ -994,8 +1002,8 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
else {
zero_v3(no); /* objects won't set this */
found = snapObjectsTransform(
- t, mval, t->tsnap.modeSelect,
- loc, no, &dist_px);
+ t, mval, t->tsnap.modeSelect, &dist_px,
+ loc, no);
}
if (found == true) {
@@ -1229,869 +1237,26 @@ static void TargetSnapClosest(TransInfo *t)
}
}
-static bool snapEdge(
- ARegion *ar, const float v1co[3], const short v1no[3], const float v2co[3], const short v2no[3],
- float obmat[4][4], float timat[3][3], const float mval_fl[2],
- const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], float *ray_depth,
- float r_loc[3], float r_no[3], float *r_dist_px)
-{
- float intersect[3] = {0, 0, 0}, ray_end[3], dvec[3];
- int result;
- bool retval = false;
-
- copy_v3_v3(ray_end, ray_normal_local);
- mul_v3_fl(ray_end, 2000);
- add_v3_v3v3(ray_end, ray_start_local, ray_end);
-
- result = isect_line_line_v3(v1co, v2co, ray_start_local, ray_end, intersect, dvec); /* dvec used but we don't care about result */
-
- if (result) {
- float edge_loc[3], vec[3];
- float mul;
-
- /* check for behind ray_start */
- sub_v3_v3v3(dvec, intersect, ray_start_local);
-
- sub_v3_v3v3(edge_loc, v1co, v2co);
- sub_v3_v3v3(vec, intersect, v2co);
-
- mul = dot_v3v3(vec, edge_loc) / dot_v3v3(edge_loc, edge_loc);
-
- if (mul > 1) {
- mul = 1;
- copy_v3_v3(intersect, v1co);
- }
- else if (mul < 0) {
- mul = 0;
- copy_v3_v3(intersect, v2co);
- }
-
- if (dot_v3v3(ray_normal_local, dvec) > 0) {
- float location[3];
- float new_depth;
- float screen_loc[2];
- float new_dist;
-
- copy_v3_v3(location, intersect);
-
- mul_m4_v3(obmat, location);
-
- new_depth = len_v3v3(location, ray_start);
-
- if (ED_view3d_project_float_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
- new_dist = len_manhattan_v2v2(mval_fl, screen_loc);
- }
- else {
- new_dist = TRANSFORM_DIST_MAX_PX;
- }
-
- /* 10% threshold if edge is closer but a bit further
- * this takes care of series of connected edges a bit slanted w.r.t the viewport
- * otherwise, it would stick to the verts of the closest edge and not slide along merrily
- * */
- if (new_dist <= *r_dist_px && new_depth < *ray_depth * 1.001f) {
- float n1[3], n2[3];
-
- *ray_depth = new_depth;
- retval = true;
-
- sub_v3_v3v3(edge_loc, v1co, v2co);
- sub_v3_v3v3(vec, intersect, v2co);
-
- mul = dot_v3v3(vec, edge_loc) / dot_v3v3(edge_loc, edge_loc);
-
- if (r_no) {
- normal_short_to_float_v3(n1, v1no);
- normal_short_to_float_v3(n2, v2no);
- interp_v3_v3v3(r_no, n2, n1, mul);
- mul_m3_v3(timat, r_no);
- normalize_v3(r_no);
- }
-
- copy_v3_v3(r_loc, location);
-
- *r_dist_px = new_dist;
- }
- }
- }
-
- return retval;
-}
-
-static bool snapVertex(
- ARegion *ar, const float vco[3], const short vno[3],
- float obmat[4][4], float timat[3][3], const float mval_fl[2],
- const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], float *ray_depth,
- float r_loc[3], float r_no[3], float *r_dist_px)
-{
- bool retval = false;
- float dvec[3];
-
- sub_v3_v3v3(dvec, vco, ray_start_local);
-
- if (dot_v3v3(ray_normal_local, dvec) > 0) {
- float location[3];
- float new_depth;
- float screen_loc[2];
- float new_dist;
-
- copy_v3_v3(location, vco);
-
- mul_m4_v3(obmat, location);
-
- new_depth = len_v3v3(location, ray_start);
-
- if (ED_view3d_project_float_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
- new_dist = len_manhattan_v2v2(mval_fl, screen_loc);
- }
- else {
- new_dist = TRANSFORM_DIST_MAX_PX;
- }
-
-
- if (new_dist <= *r_dist_px && new_depth < *ray_depth) {
- *ray_depth = new_depth;
- retval = true;
-
- copy_v3_v3(r_loc, location);
-
- if (r_no) {
- normal_short_to_float_v3(r_no, vno);
- mul_m3_v3(timat, r_no);
- normalize_v3(r_no);
- }
-
- *r_dist_px = new_dist;
- }
- }
-
- return retval;
-}
-
-static bool snapArmature(
- ARegion *ar, Object *ob, bArmature *arm, float obmat[4][4],
- const float mval[2], const short snap_to,
- const float ray_start[3], const float ray_normal[3], float *ray_depth,
- float r_loc[3], float *UNUSED(r_no), float *r_dist_px)
-{
- float imat[4][4];
- float ray_start_local[3], ray_normal_local[3];
- bool retval = false;
-
- invert_m4_m4(imat, obmat);
-
- mul_v3_m4v3(ray_start_local, imat, ray_start);
- mul_v3_mat3_m4v3(ray_normal_local, imat, ray_normal);
-
- if (arm->edbo) {
- EditBone *eBone;
-
- for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
- if (eBone->layer & arm->layer) {
- /* skip hidden or moving (selected) bones */
- if ((eBone->flag & (BONE_HIDDEN_A | BONE_ROOTSEL | BONE_TIPSEL)) == 0) {
- switch (snap_to) {
- case SCE_SNAP_MODE_VERTEX:
- retval |= snapVertex(ar, eBone->head, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- retval |= snapVertex(ar, eBone->tail, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- break;
- case SCE_SNAP_MODE_EDGE:
- retval |= snapEdge(ar, eBone->head, NULL, eBone->tail, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- break;
- }
- }
- }
- }
- }
- else if (ob->pose && ob->pose->chanbase.first) {
- bPoseChannel *pchan;
- Bone *bone;
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- bone = pchan->bone;
- /* skip hidden bones */
- if (bone && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
- const float *head_vec = pchan->pose_head;
- const float *tail_vec = pchan->pose_tail;
-
- switch (snap_to) {
- case SCE_SNAP_MODE_VERTEX:
- retval |= snapVertex(ar, head_vec, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- retval |= snapVertex(ar, tail_vec, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- break;
- case SCE_SNAP_MODE_EDGE:
- retval |= snapEdge(ar, head_vec, NULL, tail_vec, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- break;
- }
- }
- }
- }
-
- return retval;
-}
-
-static bool snapCurve(
- ARegion *ar, Object *ob, Curve *cu, float obmat[4][4],
- const float mval[2], const short snap_to,
- const float ray_start[3], const float ray_normal[3], float *ray_depth,
- float r_loc[3], float *UNUSED(r_no), float *r_dist_px)
-{
- float imat[4][4];
- float ray_start_local[3], ray_normal_local[3];
- bool retval = false;
- int u;
-
- Nurb *nu;
-
- /* only vertex snapping mode (eg control points and handles) supported for now) */
- if (snap_to != SCE_SNAP_MODE_VERTEX) {
- return retval;
- }
-
- invert_m4_m4(imat, obmat);
-
- copy_v3_v3(ray_start_local, ray_start);
- copy_v3_v3(ray_normal_local, ray_normal);
-
- mul_m4_v3(imat, ray_start_local);
- mul_mat3_m4_v3(imat, ray_normal_local);
-
- for (nu = (ob->mode == OB_MODE_EDIT ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) {
- for (u = 0; u < nu->pntsu; u++) {
- switch (snap_to) {
- case SCE_SNAP_MODE_VERTEX:
- {
- if (ob->mode == OB_MODE_EDIT) {
- if (nu->bezt) {
- /* don't snap to selected (moving) or hidden */
- if (nu->bezt[u].f2 & SELECT || nu->bezt[u].hide != 0) {
- break;
- }
- retval |= snapVertex(ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- /* don't snap if handle is selected (moving), or if it is aligning to a moving handle */
- if (!(nu->bezt[u].f1 & SELECT) && !(nu->bezt[u].h1 & HD_ALIGN && nu->bezt[u].f3 & SELECT)) {
- retval |= snapVertex(ar, nu->bezt[u].vec[0], NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- }
- if (!(nu->bezt[u].f3 & SELECT) && !(nu->bezt[u].h2 & HD_ALIGN && nu->bezt[u].f1 & SELECT)) {
- retval |= snapVertex(ar, nu->bezt[u].vec[2], NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- }
- }
- else {
- /* don't snap to selected (moving) or hidden */
- if (nu->bp[u].f1 & SELECT || nu->bp[u].hide != 0) {
- break;
- }
- retval |= snapVertex(ar, nu->bp[u].vec, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- }
- }
- else {
- /* curve is not visible outside editmode if nurb length less than two */
- if (nu->pntsu > 1) {
- if (nu->bezt) {
- retval |= snapVertex(ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- }
- else {
- retval |= snapVertex(ar, nu->bp[u].vec, NULL, obmat, NULL, mval, ray_start, ray_start_local, ray_normal_local, ray_depth, r_loc, NULL, r_dist_px);
- }
- }
- }
- break;
- }
- default:
- break;
- }
- }
- }
- return retval;
-}
-
-static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt)
-{
- const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
- return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly;
-}
-
-static bool snapDerivedMesh(
- ARegion *ar, Object *ob, DerivedMesh *dm, BMEditMesh *em, float obmat[4][4],
- const float mval[2], const short snap_to, bool do_bb,
- const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
- float r_loc[3], float r_no[3], float *r_dist_px, int *r_index)
-{
- bool retval = false;
- int totvert = dm->getNumVerts(dm);
-
- if (totvert > 0) {
- const bool do_ray_start_correction = (
- ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX) &&
- (ar && !((RegionView3D *)ar->regiondata)->is_persp));
- bool need_ray_start_correction_init = do_ray_start_correction;
-
- float imat[4][4];
- float timat[3][3]; /* transpose inverse matrix for normals */
- float ray_start_local[3], ray_normal_local[3];
- float local_scale, local_depth, len_diff;
-
- BVHTreeFromMesh treedata = {0};
-
- invert_m4_m4(imat, obmat);
- transpose_m3_m4(timat, imat);
-
- copy_v3_v3(ray_start_local, ray_start);
- copy_v3_v3(ray_normal_local, ray_normal);
-
- mul_m4_v3(imat, ray_start_local);
- mul_mat3_m4_v3(imat, ray_normal_local);
-
- /* local scale in normal direction */
- local_scale = normalize_v3(ray_normal_local);
- local_depth = *ray_depth;
- if (local_depth != BVH_RAYCAST_DIST_MAX) {
- local_depth *= local_scale;
- }
-
- if (do_bb) {
- BoundBox *bb = BKE_object_boundbox_get(ob);
-
- if (bb) {
- BoundBox bb_temp;
-
- /* We cannot aford a bbox with some null dimension, which may happen in some cases...
- * Threshold is rather high, but seems to be needed to get good behavior, see T46099. */
- bb = BKE_boundbox_ensure_minimum_dimensions(bb, &bb_temp, 1e-1f);
-
- /* Exact value here is arbitrary (ideally we would scale in pixel-space based on 'r_dist_px'),
- * scale up so we can snap against verts & edges on the boundbox, see T46816. */
- if (ELEM(snap_to, SCE_SNAP_MODE_VERTEX, SCE_SNAP_MODE_EDGE)) {
- BKE_boundbox_scale(&bb_temp, bb, 1.0f + 1e-1f);
- bb = &bb_temp;
- }
-
- /* was local_depth, see: T47838 */
- len_diff = BVH_RAYCAST_DIST_MAX;
-
- if (!BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, &len_diff)) {
- return retval;
- }
- need_ray_start_correction_init = false;
- }
- }
-
- treedata.em_evil = em;
- treedata.em_evil_all = false;
- switch (snap_to) {
- case SCE_SNAP_MODE_FACE:
- bvhtree_from_mesh_looptri(&treedata, dm, 0.0f, 4, 6);
- break;
- case SCE_SNAP_MODE_VERTEX:
- bvhtree_from_mesh_verts(&treedata, dm, 0.0f, 2, 6);
- break;
- }
-
- if (need_ray_start_correction_init) {
- /* We *need* a reasonably valid len_diff in this case.
- * Use BHVTree to find the closest face from ray_start_local.
- */
- BVHTreeNearest nearest;
-
- if (treedata.tree != NULL) {
- nearest.index = -1;
- nearest.dist_sq = FLT_MAX;
- /* Compute and store result. */
- BLI_bvhtree_find_nearest(
- treedata.tree, ray_start_local, &nearest, treedata.nearest_callback, &treedata);
- if (nearest.index != -1) {
- len_diff = sqrtf(nearest.dist_sq);
- }
- }
- }
- /* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already
- * been *inside* boundbox, leading to snap failures (see T38409).
- * Note also ar might be null (see T38435), in this case we assume ray_start is ok!
- */
- if (do_ray_start_correction) {
- float ray_org_local[3];
-
- copy_v3_v3(ray_org_local, ray_origin);
- mul_m4_v3(imat, ray_org_local);
-
- /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far
- * away ray_start values (as returned in case of ortho view3d), see T38358.
- */
- len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */
- madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local,
- len_diff - len_v3v3(ray_start_local, ray_org_local));
- local_depth -= len_diff;
- }
- else {
- len_diff = 0.0f;
- }
-
- switch (snap_to) {
- case SCE_SNAP_MODE_FACE:
- {
- BVHTreeRayHit hit;
-
- hit.index = -1;
- hit.dist = local_depth;
-
- if (treedata.tree &&
- BLI_bvhtree_ray_cast(treedata.tree, ray_start_local, ray_normal_local, 0.0f,
- &hit, treedata.raycast_callback, &treedata) != -1)
- {
- hit.dist += len_diff;
- hit.dist /= local_scale;
- if (hit.dist <= *ray_depth) {
- *ray_depth = hit.dist;
- copy_v3_v3(r_loc, hit.co);
- copy_v3_v3(r_no, hit.no);
-
- /* back to worldspace */
- mul_m4_v3(obmat, r_loc);
- mul_m3_v3(timat, r_no);
- normalize_v3(r_no);
-
- retval = true;
-
- if (r_index) {
- *r_index = dm_looptri_to_poly_index(dm, &treedata.looptri[hit.index]);
- }
- }
- }
- break;
- }
- case SCE_SNAP_MODE_VERTEX:
- {
- BVHTreeNearest nearest;
-
- nearest.index = -1;
- nearest.dist_sq = local_depth * local_depth;
- if (treedata.tree &&
- BLI_bvhtree_find_nearest_to_ray(
- treedata.tree, ray_start_local, ray_normal_local,
- &nearest, NULL, NULL) != -1)
- {
- const MVert *v = &treedata.vert[nearest.index];
- retval = snapVertex(
- ar, v->co, v->no, obmat, timat, mval,
- ray_start, ray_start_local, ray_normal_local, ray_depth,
- r_loc, r_no, r_dist_px);
- }
- break;
- }
- case SCE_SNAP_MODE_EDGE:
- {
- MVert *verts = dm->getVertArray(dm);
- MEdge *edges = dm->getEdgeArray(dm);
- int totedge = dm->getNumEdges(dm);
- const int *index_array = NULL;
- int index = 0;
- int i;
-
- if (em != NULL) {
- index_array = dm->getEdgeDataArray(dm, CD_ORIGINDEX);
- BM_mesh_elem_table_ensure(em->bm, BM_EDGE);
- }
-
- for (i = 0; i < totedge; i++) {
- MEdge *e = edges + i;
- bool test = true;
-
- if (em != NULL) {
- if (index_array) {
- index = index_array[i];
- }
- else {
- index = i;
- }
-
- if (index == ORIGINDEX_NONE) {
- test = false;
- }
- else {
- BMEdge *eed = BM_edge_at_index(em->bm, index);
-
- if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN) ||
- BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
- BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))
- {
- test = false;
- }
- }
- }
-
- if (test) {
- retval |= snapEdge(
- ar, verts[e->v1].co, verts[e->v1].no, verts[e->v2].co, verts[e->v2].no, obmat, timat,
- mval, ray_start, ray_start_local, ray_normal_local, ray_depth,
- r_loc, r_no, r_dist_px);
- }
- }
-
- break;
- }
- }
-
- free_bvhtree_from_mesh(&treedata);
- }
-
- return retval;
-}
-
-/* may extend later (for now just snaps to empty center) */
-static bool snapEmpty(
- ARegion *ar, Object *ob, float obmat[4][4],
- const float mval[2], const short snap_to,
- const float ray_start[3], const float ray_normal[3], float *ray_depth,
- float r_loc[3], float *UNUSED(r_no), float *r_dist_px)
-{
- float imat[4][4];
- float ray_start_local[3], ray_normal_local[3];
- bool retval = false;
-
- if (ob->transflag & OB_DUPLI) {
- return retval;
- }
- /* for now only vertex supported */
- if (snap_to != SCE_SNAP_MODE_VERTEX) {
- return retval;
- }
-
- invert_m4_m4(imat, obmat);
-
- mul_v3_m4v3(ray_start_local, imat, ray_start);
- mul_v3_mat3_m4v3(ray_normal_local, imat, ray_normal);
-
- switch (snap_to) {
- case SCE_SNAP_MODE_VERTEX:
- {
- const float zero_co[3] = {0.0f};
- retval |= snapVertex(
- ar, zero_co, NULL, obmat, NULL, mval,
- ray_start, ray_start_local, ray_normal_local, ray_depth,
- r_loc, NULL, r_dist_px);
- break;
- }
- default:
- break;
- }
-
- return retval;
-}
-
-static bool snapCamera(
- ARegion *ar, Scene *scene, Object *object, float obmat[4][4],
- const float mval[2], const short snap_to,
- const float ray_start[3], const float ray_normal[3], float *ray_depth,
- float r_loc[3], float *UNUSED(r_no), float *r_dist_px)
-{
- float orig_camera_mat[4][4], orig_camera_imat[4][4], imat[4][4];
- bool retval = false;
- MovieClip *clip = BKE_object_movieclip_get(scene, object, false);
- MovieTracking *tracking;
- float ray_start_local[3], ray_normal_local[3];
-
- if (clip == NULL) {
- return retval;
- }
- if (object->transflag & OB_DUPLI) {
- return retval;
- }
-
- tracking = &clip->tracking;
-
- BKE_tracking_get_camera_object_matrix(scene, object, orig_camera_mat);
-
- invert_m4_m4(orig_camera_imat, orig_camera_mat);
- invert_m4_m4(imat, obmat);
-
- switch (snap_to) {
- case SCE_SNAP_MODE_VERTEX:
- {
- MovieTrackingObject *tracking_object;
-
- for (tracking_object = tracking->objects.first;
- tracking_object;
- tracking_object = tracking_object->next)
- {
- ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
- MovieTrackingTrack *track;
- float reconstructed_camera_mat[4][4],
- reconstructed_camera_imat[4][4];
- float (*vertex_obmat)[4];
-
- copy_v3_v3(ray_start_local, ray_start);
- copy_v3_v3(ray_normal_local, ray_normal);
-
- if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) {
- BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object,
- CFRA, reconstructed_camera_mat);
-
- invert_m4_m4(reconstructed_camera_imat, reconstructed_camera_mat);
- }
-
- for (track = tracksbase->first; track; track = track->next) {
- float bundle_pos[3];
-
- if ((track->flag & TRACK_HAS_BUNDLE) == 0) {
- continue;
- }
-
- copy_v3_v3(bundle_pos, track->bundle_pos);
- if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
- mul_m4_v3(orig_camera_imat, ray_start_local);
- mul_mat3_m4_v3(orig_camera_imat, ray_normal_local);
- vertex_obmat = orig_camera_mat;
- }
- else {
- mul_m4_v3(reconstructed_camera_imat, bundle_pos);
- mul_m4_v3(imat, ray_start_local);
- mul_mat3_m4_v3(imat, ray_normal_local);
- vertex_obmat = obmat;
- }
-
- retval |= snapVertex(
- ar, bundle_pos, NULL, vertex_obmat, NULL, mval,
- ray_start, ray_start_local, ray_normal_local, ray_depth,
- r_loc, NULL, r_dist_px);
- }
- }
-
- break;
- }
- default:
- break;
- }
-
- return retval;
-}
-
-static bool snapObject(
- Scene *scene, ARegion *ar, Object *ob, float obmat[4][4], bool use_obedit,
- const float mval[2], const short snap_to,
- const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
- /* return args */
- float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
- Object **r_ob, float r_obmat[4][4])
-{
- bool retval = false;
-
- if (ob->type == OB_MESH) {
- BMEditMesh *em;
- DerivedMesh *dm;
- bool do_bb = true;
-
- if (use_obedit) {
- em = BKE_editmesh_from_object(ob);
- dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH);
- do_bb = false;
- }
- else {
- /* in this case we want the mesh from the editmesh, avoids stale data. see: T45978.
- * still set the 'em' to NULL, since we only want the 'dm'. */
- em = BKE_editmesh_from_object(ob);
- if (em) {
- editbmesh_get_derived_cage_and_final(scene, ob, em, CD_MASK_BAREMESH, &dm);
- }
- else {
- dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
- }
- em = NULL;
- }
-
- retval = snapDerivedMesh(
- ar, ob, dm, em, obmat, mval, snap_to, do_bb,
- ray_start, ray_normal, ray_origin, ray_depth,
- r_loc, r_no, r_dist_px, r_index);
-
- dm->release(dm);
- }
- else if (ob->type == OB_ARMATURE) {
- retval = snapArmature(
- ar, ob, ob->data, obmat, mval, snap_to,
- ray_start, ray_normal, ray_depth,
- r_loc, r_no, r_dist_px);
- }
- else if (ob->type == OB_CURVE) {
- retval = snapCurve(
- ar, ob, ob->data, obmat, mval, snap_to,
- ray_start, ray_normal, ray_depth,
- r_loc, r_no, r_dist_px);
- }
- else if (ob->type == OB_EMPTY) {
- retval = snapEmpty(
- ar, ob, obmat, mval, snap_to,
- ray_start, ray_normal, ray_depth,
- r_loc, r_no, r_dist_px);
- }
- else if (ob->type == OB_CAMERA) {
- retval = snapCamera(
- ar, scene, ob, obmat, mval, snap_to,
- ray_start, ray_normal, ray_depth,
- r_loc, r_no, r_dist_px);
- }
-
- if (retval) {
- if (r_ob) {
- *r_ob = ob;
- copy_m4_m4(r_obmat, obmat);
- }
- }
-
- return retval;
-}
-
-static bool snapObjectsRay(
- Scene *scene, View3D *v3d, ARegion *ar, Base *base_act, Object *obedit,
- const float mval[2], SnapSelect snap_select, const short snap_to,
- const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
- /* return args */
- float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
- Object **r_ob, float r_obmat[4][4])
-{
- Base *base;
- bool retval = false;
-
- if (snap_select == SNAP_ALL && obedit) {
- Object *ob = obedit;
-
- retval |= snapObject(
- scene, ar, ob, ob->obmat, true,
- mval, snap_to,
- ray_start, ray_normal, ray_origin, ray_depth,
- r_loc, r_no, r_dist_px, r_index, r_ob, r_obmat);
- }
-
- for (base = FIRSTBASE; base != NULL; base = base->next) {
- if ((BASE_VISIBLE_BGMODE(v3d, scene, base)) &&
- (base->flag & (BA_HAS_RECALC_OB | BA_HAS_RECALC_DATA)) == 0 &&
-
- ((snap_select == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 0) ||
- (ELEM(snap_select, SNAP_ALL, SNAP_NOT_OBEDIT) && base != base_act)))
- {
- Object *ob = base->object;
- Object *ob_snap = ob;
- bool use_obedit = false;
-
- /* for linked objects, use the same object but a different matrix */
- if (obedit && ob->data == obedit->data) {
- use_obedit = true;
- ob_snap = obedit;
- }
-
- if (ob->transflag & OB_DUPLI) {
- DupliObject *dupli_ob;
- ListBase *lb = object_duplilist(G.main->eval_ctx, scene, ob);
-
- for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) {
- bool use_obedit_dupli = (obedit && dupli_ob->ob->data == obedit->data);
- Object *dupli_snap = (use_obedit_dupli) ? obedit : dupli_ob->ob;
-
- retval |= snapObject(
- scene, ar, dupli_snap, dupli_ob->mat, use_obedit_dupli,
- mval, snap_to,
- ray_start, ray_normal, ray_origin, ray_depth,
- r_loc, r_no, r_dist_px, r_index, r_ob, r_obmat);
- }
-
- free_object_duplilist(lb);
- }
-
- retval |= snapObject(
- scene, ar, ob_snap, ob->obmat, use_obedit,
- mval, snap_to,
- ray_start, ray_normal, ray_origin, ray_depth,
- r_loc, r_no, r_dist_px, r_index, r_ob, r_obmat);
- }
- }
-
- return retval;
-}
-static bool snapObjects(
- Scene *scene, View3D *v3d, ARegion *ar, Base *base_act, Object *obedit,
- const float mval[2], SnapSelect snap_select, const short snap_to,
- float *ray_depth,
- float r_loc[3], float r_no[3], float *r_dist_px, int *r_index)
-{
- float ray_start[3], ray_normal[3], ray_orgigin[3];
-
- if (!ED_view3d_win_to_ray_ex(ar, v3d, mval, ray_orgigin, ray_normal, ray_start, true)) {
- return false;
- }
-
- return snapObjectsRay(
- scene, v3d, ar, base_act, obedit,
- mval, snap_select, snap_to,
- ray_start, ray_normal, ray_orgigin, ray_depth,
- r_loc, r_no, r_dist_px, r_index, NULL, NULL);
-}
-
bool snapObjectsTransform(
TransInfo *t, const float mval[2], SnapSelect snap_select,
- float r_loc[3], float r_no[3], float *r_dist_px)
+ float *dist_px,
+ float r_loc[3], float r_no[3])
{
float ray_dist = BVH_RAYCAST_DIST_MAX;
- Object *obedit = NULL;
- Base *base_act = NULL;
-
- if (t->flag & T_EDIT) {
- obedit = t->obedit;
- }
- if ((t->options & CTX_GPENCIL_STROKES) == 0) {
- base_act = t->scene->basact;
- }
-
- return snapObjects(
- t->scene, t->view, t->ar, base_act, obedit,
- mval, snap_select, t->scene->toolsettings->snap_mode,
+ return ED_transform_snap_object_project_view3d_ex(
+ t->tsnap.object_context,
+ &(const struct SnapObjectParams){
+ .snap_select = snap_select,
+ .snap_to = t->scene->toolsettings->snap_mode,
+ .use_object_edit = (t->flag & T_EDIT) != 0,
+ .use_object_active = (t->options & CTX_GPENCIL_STROKES) == 0,
+ },
+ mval, dist_px,
&ray_dist,
- r_loc, r_no, r_dist_px, NULL);
+ r_loc, r_no, NULL);
}
-bool snapObjectsContext(
- bContext *C, const float mval[2], SnapSelect snap_select,
- float r_loc[3], float r_no[3], float *r_dist_px)
-{
- ScrArea *sa = CTX_wm_area(C);
- View3D *v3d = sa->spacedata.first;
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
- Object *obedit = CTX_data_edit_object(C);
- float ray_dist = BVH_RAYCAST_DIST_MAX;
-
- return snapObjects(
- scene, v3d, ar, scene->basact, obedit,
- mval, snap_select, scene->toolsettings->snap_mode,
- &ray_dist,
- r_loc, r_no, r_dist_px, NULL);
-}
-
-bool snapObjectsEx(
- Scene *scene, View3D *v3d, ARegion *ar, Base *base_act, Object *obedit,
- const float mval[2], SnapSelect snap_select, const short snap_to,
- float *ray_depth,
- float r_loc[3], float r_no[3], float *r_dist_px)
-{
- return snapObjects(
- scene, v3d, ar, base_act, obedit,
- mval, snap_select, snap_to,
- ray_depth,
- r_loc, r_no, r_dist_px, NULL);
-}
-bool snapObjectsRayEx(
- Scene *scene, View3D *v3d, ARegion *ar, Base *base_act, Object *obedit,
- const float mval[2], SnapSelect snap_select, const short snap_to,
- const float ray_start[3], const float ray_normal[3], float *ray_depth,
- float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
- Object **r_ob, float r_obmat[4][4])
-{
- return snapObjectsRay(
- scene, v3d, ar, base_act, obedit,
- mval, snap_select, snap_to,
- ray_start, ray_normal, ray_start, ray_depth,
- r_loc, r_no, r_dist_px, r_index,
- r_ob, r_obmat);
-}
/******************** PEELING *********************************/
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
new file mode 100644
index 00000000000..e9209eea0e7
--- /dev/null
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -0,0 +1,1207 @@
+/*
+ * ***** 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 *****
+ */
+
+/** \file blender/editors/transform/transform_snap_object.c
+ * \ingroup edtransform
+ */
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+#include <stdio.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_kdopbvh.h"
+#include "BLI_memarena.h"
+#include "BLI_ghash.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_armature_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_DerivedMesh.h"
+#include "BKE_object.h"
+#include "BKE_anim.h" /* for duplis */
+#include "BKE_editmesh.h"
+#include "BKE_main.h"
+#include "BKE_tracking.h"
+
+#include "ED_transform.h"
+#include "ED_view3d.h"
+#include "ED_armature.h"
+
+#include "transform.h"
+
+typedef struct SnapObjectData {
+ BVHTreeFromMesh *bvh_trees[2];
+} SnapObjectData;
+
+
+struct SnapObjectContext {
+ Main *bmain;
+ Scene *scene;
+ int flag;
+
+ /* Optional: when performing screen-space projection.
+ * otherwise this doesn't take viewport into account. */
+ bool use_v3d;
+ struct {
+ struct View3D *v3d;
+ struct ARegion *ar;
+ } v3d_data;
+
+
+ /* Object -> SnapObjectData map */
+ struct {
+ GHash *object_map;
+ MemArena *mem_arena;
+ } cache;
+
+};
+
+/* -------------------------------------------------------------------- */
+
+/** \name Internal Object Snapping API
+ * \{ */
+
+static bool snapEdge(
+ ARegion *ar, const float v1co[3], const short v1no[3], const float v2co[3], const short v2no[3],
+ float obmat[4][4], float timat[3][3], const float mval_fl[2], float *dist_px,
+ const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], float *ray_depth,
+ float r_loc[3], float r_no[3])
+{
+ float intersect[3] = {0, 0, 0}, ray_end[3], dvec[3];
+ int result;
+ bool retval = false;
+
+ copy_v3_v3(ray_end, ray_normal_local);
+ mul_v3_fl(ray_end, 2000);
+ add_v3_v3v3(ray_end, ray_start_local, ray_end);
+
+ /* dvec used but we don't care about result */
+ result = isect_line_line_v3(v1co, v2co, ray_start_local, ray_end, intersect, dvec);
+
+ if (result) {
+ float edge_loc[3], vec[3];
+ float mul;
+
+ /* check for behind ray_start */
+ sub_v3_v3v3(dvec, intersect, ray_start_local);
+
+ sub_v3_v3v3(edge_loc, v1co, v2co);
+ sub_v3_v3v3(vec, intersect, v2co);
+
+ mul = dot_v3v3(vec, edge_loc) / dot_v3v3(edge_loc, edge_loc);
+
+ if (mul > 1) {
+ mul = 1;
+ copy_v3_v3(intersect, v1co);
+ }
+ else if (mul < 0) {
+ mul = 0;
+ copy_v3_v3(intersect, v2co);
+ }
+
+ if (dot_v3v3(ray_normal_local, dvec) > 0) {
+ float location[3];
+ float new_depth;
+ float screen_loc[2];
+ float new_dist;
+
+ copy_v3_v3(location, intersect);
+
+ mul_m4_v3(obmat, location);
+
+ new_depth = len_v3v3(location, ray_start);
+
+ if (ED_view3d_project_float_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+ new_dist = len_manhattan_v2v2(mval_fl, screen_loc);
+ }
+ else {
+ new_dist = TRANSFORM_DIST_MAX_PX;
+ }
+
+ /* 10% threshold if edge is closer but a bit further
+ * this takes care of series of connected edges a bit slanted w.r.t the viewport
+ * otherwise, it would stick to the verts of the closest edge and not slide along merrily
+ * */
+ if (new_dist <= *dist_px && new_depth < *ray_depth * 1.001f) {
+ float n1[3], n2[3];
+
+ *ray_depth = new_depth;
+ retval = true;
+
+ sub_v3_v3v3(edge_loc, v1co, v2co);
+ sub_v3_v3v3(vec, intersect, v2co);
+
+ mul = dot_v3v3(vec, edge_loc) / dot_v3v3(edge_loc, edge_loc);
+
+ if (r_no) {
+ normal_short_to_float_v3(n1, v1no);
+ normal_short_to_float_v3(n2, v2no);
+ interp_v3_v3v3(r_no, n2, n1, mul);
+ mul_m3_v3(timat, r_no);
+ normalize_v3(r_no);
+ }
+
+ copy_v3_v3(r_loc, location);
+
+ *dist_px = new_dist;
+ }
+ }
+ }
+
+ return retval;
+}
+
+static bool snapVertex(
+ ARegion *ar, const float vco[3], const short vno[3],
+ float obmat[4][4], float timat[3][3], const float mval_fl[2], float *dist_px,
+ const float ray_start[3], const float ray_start_local[3], const float ray_normal_local[3], float *ray_depth,
+ float r_loc[3], float r_no[3])
+{
+ bool retval = false;
+ float dvec[3];
+
+ sub_v3_v3v3(dvec, vco, ray_start_local);
+
+ if (dot_v3v3(ray_normal_local, dvec) > 0) {
+ float location[3];
+ float new_depth;
+ float screen_loc[2];
+ float new_dist;
+
+ copy_v3_v3(location, vco);
+
+ mul_m4_v3(obmat, location);
+
+ new_depth = len_v3v3(location, ray_start);
+
+ if (ED_view3d_project_float_global(ar, location, screen_loc, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+ new_dist = len_manhattan_v2v2(mval_fl, screen_loc);
+ }
+ else {
+ new_dist = TRANSFORM_DIST_MAX_PX;
+ }
+
+
+ if (new_dist <= *dist_px && new_depth < *ray_depth) {
+ *ray_depth = new_depth;
+ retval = true;
+
+ copy_v3_v3(r_loc, location);
+
+ if (r_no) {
+ normal_short_to_float_v3(r_no, vno);
+ mul_m3_v3(timat, r_no);
+ normalize_v3(r_no);
+ }
+
+ *dist_px = new_dist;
+ }
+ }
+
+ return retval;
+}
+
+static bool snapArmature(
+ ARegion *ar, Object *ob, bArmature *arm, float obmat[4][4],
+ const float mval[2], float *dist_px, const short snap_to,
+ const float ray_start[3], const float ray_normal[3], float *ray_depth,
+ float r_loc[3], float *UNUSED(r_no))
+{
+ float imat[4][4];
+ float ray_start_local[3], ray_normal_local[3];
+ bool retval = false;
+
+ invert_m4_m4(imat, obmat);
+
+ mul_v3_m4v3(ray_start_local, imat, ray_start);
+ mul_v3_mat3_m4v3(ray_normal_local, imat, ray_normal);
+
+ if (arm->edbo) {
+ EditBone *eBone;
+
+ for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
+ if (eBone->layer & arm->layer) {
+ /* skip hidden or moving (selected) bones */
+ if ((eBone->flag & (BONE_HIDDEN_A | BONE_ROOTSEL | BONE_TIPSEL)) == 0) {
+ switch (snap_to) {
+ case SCE_SNAP_MODE_VERTEX:
+ retval |= snapVertex(
+ ar, eBone->head, NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ retval |= snapVertex(
+ ar, eBone->tail, NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ break;
+ case SCE_SNAP_MODE_EDGE:
+ retval |= snapEdge(
+ ar, eBone->head, NULL, eBone->tail, NULL,
+ obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local,
+ ray_depth, r_loc, NULL);
+ break;
+ }
+ }
+ }
+ }
+ }
+ else if (ob->pose && ob->pose->chanbase.first) {
+ bPoseChannel *pchan;
+ Bone *bone;
+
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ bone = pchan->bone;
+ /* skip hidden bones */
+ if (bone && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
+ const float *head_vec = pchan->pose_head;
+ const float *tail_vec = pchan->pose_tail;
+
+ switch (snap_to) {
+ case SCE_SNAP_MODE_VERTEX:
+ retval |= snapVertex(
+ ar, head_vec, NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local,
+ ray_depth, r_loc, NULL);
+ retval |= snapVertex(
+ ar, tail_vec, NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ break;
+ case SCE_SNAP_MODE_EDGE:
+ retval |= snapEdge(
+ ar, head_vec, NULL, tail_vec, NULL,
+ obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local,
+ ray_depth, r_loc, NULL);
+ break;
+ }
+ }
+ }
+ }
+
+ return retval;
+}
+
+static bool snapCurve(
+ ARegion *ar, Object *ob, Curve *cu, float obmat[4][4],
+ const float mval[2], float *dist_px, const short snap_to,
+ const float ray_start[3], const float ray_normal[3], float *ray_depth,
+ float r_loc[3], float *UNUSED(r_no))
+{
+ float imat[4][4];
+ float ray_start_local[3], ray_normal_local[3];
+ bool retval = false;
+ int u;
+
+ Nurb *nu;
+
+ /* only vertex snapping mode (eg control points and handles) supported for now) */
+ if (snap_to != SCE_SNAP_MODE_VERTEX) {
+ return retval;
+ }
+
+ invert_m4_m4(imat, obmat);
+
+ copy_v3_v3(ray_start_local, ray_start);
+ copy_v3_v3(ray_normal_local, ray_normal);
+
+ mul_m4_v3(imat, ray_start_local);
+ mul_mat3_m4_v3(imat, ray_normal_local);
+
+ for (nu = (ob->mode == OB_MODE_EDIT ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) {
+ for (u = 0; u < nu->pntsu; u++) {
+ switch (snap_to) {
+ case SCE_SNAP_MODE_VERTEX:
+ {
+ if (ob->mode == OB_MODE_EDIT) {
+ if (nu->bezt) {
+ /* don't snap to selected (moving) or hidden */
+ if (nu->bezt[u].f2 & SELECT || nu->bezt[u].hide != 0) {
+ break;
+ }
+ retval |= snapVertex(
+ ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ /* don't snap if handle is selected (moving), or if it is aligning to a moving handle */
+ if (!(nu->bezt[u].f1 & SELECT) &&
+ !(nu->bezt[u].h1 & HD_ALIGN && nu->bezt[u].f3 & SELECT))
+ {
+ retval |= snapVertex(
+ ar, nu->bezt[u].vec[0], NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ }
+ if (!(nu->bezt[u].f3 & SELECT) &&
+ !(nu->bezt[u].h2 & HD_ALIGN && nu->bezt[u].f1 & SELECT))
+ {
+ retval |= snapVertex(
+ ar, nu->bezt[u].vec[2], NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ }
+ }
+ else {
+ /* don't snap to selected (moving) or hidden */
+ if (nu->bp[u].f1 & SELECT || nu->bp[u].hide != 0) {
+ break;
+ }
+ retval |= snapVertex(
+ ar, nu->bp[u].vec, NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ }
+ }
+ else {
+ /* curve is not visible outside editmode if nurb length less than two */
+ if (nu->pntsu > 1) {
+ if (nu->bezt) {
+ retval |= snapVertex(
+ ar, nu->bezt[u].vec[1], NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ }
+ else {
+ retval |= snapVertex(
+ ar, nu->bp[u].vec, NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ }
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+ return retval;
+}
+
+/* may extend later (for now just snaps to empty center) */
+static bool snapEmpty(
+ ARegion *ar, Object *ob, float obmat[4][4],
+ const float mval[2], float *dist_px, const short snap_to,
+ const float ray_start[3], const float ray_normal[3], float *ray_depth,
+ float r_loc[3], float *UNUSED(r_no))
+{
+ float imat[4][4];
+ float ray_start_local[3], ray_normal_local[3];
+ bool retval = false;
+
+ if (ob->transflag & OB_DUPLI) {
+ return retval;
+ }
+ /* for now only vertex supported */
+ if (snap_to != SCE_SNAP_MODE_VERTEX) {
+ return retval;
+ }
+
+ invert_m4_m4(imat, obmat);
+
+ mul_v3_m4v3(ray_start_local, imat, ray_start);
+ mul_v3_mat3_m4v3(ray_normal_local, imat, ray_normal);
+
+ switch (snap_to) {
+ case SCE_SNAP_MODE_VERTEX:
+ {
+ const float zero_co[3] = {0.0f};
+ retval |= snapVertex(
+ ar, zero_co, NULL, obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ break;
+ }
+ default:
+ break;
+ }
+
+ return retval;
+}
+
+static bool snapCamera(
+ ARegion *ar, Scene *scene, Object *object, float obmat[4][4],
+ const float mval[2], float *dist_px, const short snap_to,
+ const float ray_start[3], const float ray_normal[3], float *ray_depth,
+ float r_loc[3], float *UNUSED(r_no))
+{
+ float orig_camera_mat[4][4], orig_camera_imat[4][4], imat[4][4];
+ bool retval = false;
+ MovieClip *clip = BKE_object_movieclip_get(scene, object, false);
+ MovieTracking *tracking;
+ float ray_start_local[3], ray_normal_local[3];
+
+ if (clip == NULL) {
+ return retval;
+ }
+ if (object->transflag & OB_DUPLI) {
+ return retval;
+ }
+
+ tracking = &clip->tracking;
+
+ BKE_tracking_get_camera_object_matrix(scene, object, orig_camera_mat);
+
+ invert_m4_m4(orig_camera_imat, orig_camera_mat);
+ invert_m4_m4(imat, obmat);
+
+ switch (snap_to) {
+ case SCE_SNAP_MODE_VERTEX:
+ {
+ MovieTrackingObject *tracking_object;
+
+ for (tracking_object = tracking->objects.first;
+ tracking_object;
+ tracking_object = tracking_object->next)
+ {
+ ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
+ MovieTrackingTrack *track;
+ float reconstructed_camera_mat[4][4],
+ reconstructed_camera_imat[4][4];
+ float (*vertex_obmat)[4];
+
+ copy_v3_v3(ray_start_local, ray_start);
+ copy_v3_v3(ray_normal_local, ray_normal);
+
+ if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) {
+ BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object,
+ CFRA, reconstructed_camera_mat);
+
+ invert_m4_m4(reconstructed_camera_imat, reconstructed_camera_mat);
+ }
+
+ for (track = tracksbase->first; track; track = track->next) {
+ float bundle_pos[3];
+
+ if ((track->flag & TRACK_HAS_BUNDLE) == 0) {
+ continue;
+ }
+
+ copy_v3_v3(bundle_pos, track->bundle_pos);
+ if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+ mul_m4_v3(orig_camera_imat, ray_start_local);
+ mul_mat3_m4_v3(orig_camera_imat, ray_normal_local);
+ vertex_obmat = orig_camera_mat;
+ }
+ else {
+ mul_m4_v3(reconstructed_camera_imat, bundle_pos);
+ mul_m4_v3(imat, ray_start_local);
+ mul_mat3_m4_v3(imat, ray_normal_local);
+ vertex_obmat = obmat;
+ }
+
+ retval |= snapVertex(
+ ar, bundle_pos, NULL, vertex_obmat, NULL, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, NULL);
+ }
+ }
+
+ break;
+ }
+ default:
+ break;
+ }
+
+ return retval;
+}
+
+static int dm_looptri_to_poly_index(DerivedMesh *dm, const MLoopTri *lt)
+{
+ const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
+ return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly;
+}
+
+static bool snapDerivedMesh(
+ SnapObjectContext *sctx,
+ Object *ob, DerivedMesh *dm, BMEditMesh *em, float obmat[4][4],
+ const float mval[2], float *dist_px, const short snap_to, bool do_bb,
+ const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
+ float r_loc[3], float r_no[3], int *r_index)
+{
+ ARegion *ar = sctx->v3d_data.ar;
+ bool retval = false;
+ int totvert = dm->getNumVerts(dm);
+
+ if (totvert > 0) {
+ const bool do_ray_start_correction = (
+ ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX) &&
+ (sctx->use_v3d && !((RegionView3D *)sctx->v3d_data.ar->regiondata)->is_persp));
+ bool need_ray_start_correction_init = do_ray_start_correction;
+
+ float imat[4][4];
+ float timat[3][3]; /* transpose inverse matrix for normals */
+ float ray_start_local[3], ray_normal_local[3];
+ float local_scale, local_depth, len_diff;
+
+ invert_m4_m4(imat, obmat);
+ transpose_m3_m4(timat, imat);
+
+ copy_v3_v3(ray_start_local, ray_start);
+ copy_v3_v3(ray_normal_local, ray_normal);
+
+ mul_m4_v3(imat, ray_start_local);
+ mul_mat3_m4_v3(imat, ray_normal_local);
+
+ /* local scale in normal direction */
+ local_scale = normalize_v3(ray_normal_local);
+ local_depth = *ray_depth;
+ if (local_depth != BVH_RAYCAST_DIST_MAX) {
+ local_depth *= local_scale;
+ }
+
+ SnapObjectData *sod = NULL;
+
+ if (sctx->flag & SNAP_OBJECT_USE_CACHE) {
+ void **sod_p;
+ if (BLI_ghash_ensure_p(sctx->cache.object_map, ob, &sod_p)) {
+ sod = *sod_p;
+ }
+ else {
+ sod = *sod_p = BLI_memarena_alloc(sctx->cache.mem_arena, sizeof(*sod));
+ memset(sod, 0, sizeof(*sod));
+ }
+ }
+
+ if (do_bb) {
+ BoundBox *bb = BKE_object_boundbox_get(ob);
+
+ if (bb) {
+ BoundBox bb_temp;
+
+ /* We cannot aford a bbox with some null dimension, which may happen in some cases...
+ * Threshold is rather high, but seems to be needed to get good behavior, see T46099. */
+ bb = BKE_boundbox_ensure_minimum_dimensions(bb, &bb_temp, 1e-1f);
+
+ /* Exact value here is arbitrary (ideally we would scale in pixel-space based on 'dist_px'),
+ * scale up so we can snap against verts & edges on the boundbox, see T46816. */
+ if (ELEM(snap_to, SCE_SNAP_MODE_VERTEX, SCE_SNAP_MODE_EDGE)) {
+ BKE_boundbox_scale(&bb_temp, bb, 1.0f + 1e-1f);
+ bb = &bb_temp;
+ }
+
+ /* was local_depth, see: T47838 */
+ len_diff = BVH_RAYCAST_DIST_MAX;
+
+ if (!BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, &len_diff)) {
+ return retval;
+ }
+ need_ray_start_correction_init = false;
+ }
+ }
+
+ BVHTreeFromMesh *treedata = NULL, treedata_stack;
+
+ if (sctx->flag & SNAP_OBJECT_USE_CACHE) {
+ int tree_index = -1;
+ switch (snap_to) {
+ case SCE_SNAP_MODE_FACE:
+ tree_index = 1;
+ break;
+ case SCE_SNAP_MODE_VERTEX:
+ tree_index = 0;
+ break;
+ }
+ if (tree_index != -1) {
+ if (sod->bvh_trees[tree_index] == NULL) {
+ sod->bvh_trees[tree_index] = BLI_memarena_alloc(sctx->cache.mem_arena, sizeof(*treedata));
+ }
+ treedata = sod->bvh_trees[tree_index];
+ }
+ }
+ else {
+ if (ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX)) {
+ treedata = &treedata_stack;
+ memset(treedata, 0, sizeof(*treedata));
+ }
+ }
+
+ if (treedata) {
+ treedata->em_evil = em;
+ treedata->em_evil_all = false;
+ switch (snap_to) {
+ case SCE_SNAP_MODE_FACE:
+ bvhtree_from_mesh_looptri(treedata, dm, 0.0f, 4, 6);
+ break;
+ case SCE_SNAP_MODE_VERTEX:
+ bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6);
+ break;
+ }
+ }
+
+ if (need_ray_start_correction_init) {
+ /* We *need* a reasonably valid len_diff in this case.
+ * Use BHVTree to find the closest face from ray_start_local.
+ */
+ if (treedata && treedata->tree != NULL) {
+ BVHTreeNearest nearest;
+ nearest.index = -1;
+ nearest.dist_sq = FLT_MAX;
+ /* Compute and store result. */
+ BLI_bvhtree_find_nearest(
+ treedata->tree, ray_start_local, &nearest, treedata->nearest_callback, treedata);
+ if (nearest.index != -1) {
+ len_diff = sqrtf(nearest.dist_sq);
+ }
+ }
+ }
+ /* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already
+ * been *inside* boundbox, leading to snap failures (see T38409).
+ * Note also ar might be null (see T38435), in this case we assume ray_start is ok!
+ */
+ if (do_ray_start_correction) {
+ float ray_org_local[3];
+
+ copy_v3_v3(ray_org_local, ray_origin);
+ mul_m4_v3(imat, ray_org_local);
+
+ /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far
+ * away ray_start values (as returned in case of ortho view3d), see T38358.
+ */
+ len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */
+ madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local,
+ len_diff - len_v3v3(ray_start_local, ray_org_local));
+ local_depth -= len_diff;
+ }
+ else {
+ len_diff = 0.0f;
+ }
+
+ switch (snap_to) {
+ case SCE_SNAP_MODE_FACE:
+ {
+ BVHTreeRayHit hit;
+
+ hit.index = -1;
+ hit.dist = local_depth;
+
+ if (treedata->tree &&
+ BLI_bvhtree_ray_cast(treedata->tree, ray_start_local, ray_normal_local, 0.0f,
+ &hit, treedata->raycast_callback, treedata) != -1)
+ {
+ hit.dist += len_diff;
+ hit.dist /= local_scale;
+ if (hit.dist <= *ray_depth) {
+ *ray_depth = hit.dist;
+ copy_v3_v3(r_loc, hit.co);
+ copy_v3_v3(r_no, hit.no);
+
+ /* back to worldspace */
+ mul_m4_v3(obmat, r_loc);
+ mul_m3_v3(timat, r_no);
+ normalize_v3(r_no);
+
+ retval = true;
+
+ if (r_index) {
+ *r_index = dm_looptri_to_poly_index(dm, &treedata->looptri[hit.index]);
+ }
+ }
+ }
+ break;
+ }
+ case SCE_SNAP_MODE_VERTEX:
+ {
+ BVHTreeNearest nearest;
+
+ nearest.index = -1;
+ nearest.dist_sq = local_depth * local_depth;
+ if (treedata->tree &&
+ BLI_bvhtree_find_nearest_to_ray(
+ treedata->tree, ray_start_local, ray_normal_local,
+ &nearest, NULL, NULL) != -1)
+ {
+ const MVert *v = &treedata->vert[nearest.index];
+ retval = snapVertex(
+ ar, v->co, v->no, obmat, timat, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, r_no);
+ }
+ break;
+ }
+ case SCE_SNAP_MODE_EDGE:
+ {
+ MVert *verts = dm->getVertArray(dm);
+ MEdge *edges = dm->getEdgeArray(dm);
+ int totedge = dm->getNumEdges(dm);
+ const int *index_array = NULL;
+ int index = 0;
+ int i;
+
+ if (em != NULL) {
+ index_array = dm->getEdgeDataArray(dm, CD_ORIGINDEX);
+ BM_mesh_elem_table_ensure(em->bm, BM_EDGE);
+ }
+
+ for (i = 0; i < totedge; i++) {
+ MEdge *e = edges + i;
+ bool test = true;
+
+ if (em != NULL) {
+ if (index_array) {
+ index = index_array[i];
+ }
+ else {
+ index = i;
+ }
+
+ if (index == ORIGINDEX_NONE) {
+ test = false;
+ }
+ else {
+ BMEdge *eed = BM_edge_at_index(em->bm, index);
+
+ if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN) ||
+ BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))
+ {
+ test = false;
+ }
+ }
+ }
+
+ if (test) {
+ retval |= snapEdge(
+ ar, verts[e->v1].co, verts[e->v1].no, verts[e->v2].co, verts[e->v2].no,
+ obmat, timat, mval, dist_px,
+ ray_start, ray_start_local, ray_normal_local, ray_depth,
+ r_loc, r_no);
+ }
+ }
+
+ break;
+ }
+ }
+
+ if ((sctx->flag & SNAP_OBJECT_USE_CACHE) == 0) {
+ if (treedata) {
+ free_bvhtree_from_mesh(treedata);
+ }
+ }
+ }
+
+ return retval;
+}
+
+static bool snapObject(
+ SnapObjectContext *sctx,
+ Object *ob, float obmat[4][4], bool use_obedit, const short snap_to,
+ const float mval[2], float *dist_px,
+ const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
+ /* return args */
+ float r_loc[3], float r_no[3], int *r_index,
+ Object **r_ob, float r_obmat[4][4])
+{
+ ARegion *ar = sctx->v3d_data.ar;
+ bool retval = false;
+
+ if (ob->type == OB_MESH) {
+ BMEditMesh *em;
+ DerivedMesh *dm;
+ bool do_bb = true;
+
+ if (use_obedit) {
+ em = BKE_editmesh_from_object(ob);
+ dm = editbmesh_get_derived_cage(sctx->scene, ob, em, CD_MASK_BAREMESH);
+ do_bb = false;
+ }
+ else {
+ /* in this case we want the mesh from the editmesh, avoids stale data. see: T45978.
+ * still set the 'em' to NULL, since we only want the 'dm'. */
+ em = BKE_editmesh_from_object(ob);
+ if (em) {
+ editbmesh_get_derived_cage_and_final(sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
+ }
+ else {
+ dm = mesh_get_derived_final(sctx->scene, ob, CD_MASK_BAREMESH);
+ }
+ em = NULL;
+ }
+
+ retval = snapDerivedMesh(
+ sctx, ob, dm, em, obmat, mval, dist_px, snap_to, do_bb,
+ ray_start, ray_normal, ray_origin, ray_depth,
+ r_loc, r_no, r_index);
+
+ dm->release(dm);
+ }
+ else if (ob->type == OB_ARMATURE) {
+ retval = snapArmature(
+ ar, ob, ob->data, obmat, mval, dist_px, snap_to,
+ ray_start, ray_normal, ray_depth,
+ r_loc, r_no);
+ }
+ else if (ob->type == OB_CURVE) {
+ retval = snapCurve(
+ ar, ob, ob->data, obmat, mval, dist_px, snap_to,
+ ray_start, ray_normal, ray_depth,
+ r_loc, r_no);
+ }
+ else if (ob->type == OB_EMPTY) {
+ retval = snapEmpty(
+ ar, ob, obmat, mval, dist_px, snap_to,
+ ray_start, ray_normal, ray_depth,
+ r_loc, r_no);
+ }
+ else if (ob->type == OB_CAMERA) {
+ retval = snapCamera(
+ ar, sctx->scene, ob, obmat, mval, dist_px, snap_to,
+ ray_start, ray_normal, ray_depth,
+ r_loc, r_no);
+ }
+
+ if (retval) {
+ if (r_ob) {
+ *r_ob = ob;
+ copy_m4_m4(r_obmat, obmat);
+ }
+ }
+
+ return retval;
+}
+
+static bool snapObjectsRay(
+ SnapObjectContext *sctx,
+ SnapSelect snap_select, const short snap_to,
+ const float mval[2], float *dist_px,
+ /* special handling of active and edit objects */
+ Base *base_act, Object *obedit,
+ const float ray_start[3], const float ray_normal[3], const float ray_origin[3], float *ray_depth,
+ /* return args */
+ float r_loc[3], float r_no[3], int *r_index,
+ Object **r_ob, float r_obmat[4][4])
+{
+ Base *base;
+ bool retval = false;
+
+ if (snap_select == SNAP_ALL && obedit) {
+ Object *ob = obedit;
+
+ retval |= snapObject(
+ sctx, ob, ob->obmat, true, snap_to,
+ mval, dist_px,
+ ray_start, ray_normal, ray_origin, ray_depth,
+ r_loc, r_no, r_index, r_ob, r_obmat);
+ }
+
+ for (base = sctx->scene->base.first; base != NULL; base = base->next) {
+ if ((BASE_VISIBLE_BGMODE(sctx->v3d_data.v3d, sctx->scene, base)) &&
+ (base->flag & (BA_HAS_RECALC_OB | BA_HAS_RECALC_DATA)) == 0 &&
+
+ ((snap_select == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL)) == 0) ||
+ (ELEM(snap_select, SNAP_ALL, SNAP_NOT_OBEDIT) && base != base_act)))
+ {
+ Object *ob = base->object;
+ Object *ob_snap = ob;
+ bool use_obedit = false;
+
+ /* for linked objects, use the same object but a different matrix */
+ if (obedit && ob->data == obedit->data) {
+ use_obedit = true;
+ ob_snap = obedit;
+ }
+
+ if (ob->transflag & OB_DUPLI) {
+ DupliObject *dupli_ob;
+ ListBase *lb = object_duplilist(sctx->bmain->eval_ctx, sctx->scene, ob);
+
+ for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) {
+ bool use_obedit_dupli = (obedit && dupli_ob->ob->data == obedit->data);
+ Object *dupli_snap = (use_obedit_dupli) ? obedit : dupli_ob->ob;
+
+ retval |= snapObject(
+ sctx, dupli_snap, dupli_ob->mat, use_obedit_dupli, snap_to,
+ mval, dist_px,
+ ray_start, ray_normal, ray_origin, ray_depth,
+ r_loc, r_no, r_index, r_ob, r_obmat);
+ }
+
+ free_object_duplilist(lb);
+ }
+
+ retval |= snapObject(
+ sctx, ob_snap, ob->obmat, use_obedit, snap_to,
+ mval, dist_px,
+ ray_start, ray_normal, ray_origin, ray_depth,
+ r_loc, r_no, r_index, r_ob, r_obmat);
+ }
+ }
+
+ return retval;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Public Object Snapping API
+ * \{ */
+
+SnapObjectContext *ED_transform_snap_object_context_create(
+ Main *bmain, Scene *scene, int flag)
+{
+ SnapObjectContext *sctx = MEM_callocN(sizeof(*sctx), __func__);
+
+ sctx->flag = flag;
+
+ sctx->bmain = bmain;
+ sctx->scene = scene;
+
+ return sctx;
+}
+
+SnapObjectContext *ED_transform_snap_object_context_create_view3d(
+ Main *bmain, Scene *scene, int flag,
+ /* extra args for view3d */
+ ARegion *ar, View3D *v3d)
+{
+ SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, flag);
+
+ sctx->use_v3d = true;
+ sctx->v3d_data.ar = ar;
+ sctx->v3d_data.v3d = v3d;
+
+ if (sctx->flag & SNAP_OBJECT_USE_CACHE) {
+ sctx->cache.object_map = BLI_ghash_ptr_new(__func__);
+ sctx->cache.mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
+ }
+
+ return sctx;
+}
+
+static void snap_object_data_free(void *val)
+{
+ SnapObjectData *sod = val;
+ for (int i = 0; i < ARRAY_SIZE(sod->bvh_trees); i++) {
+ if (sod->bvh_trees[i]) {
+ free_bvhtree_from_mesh(sod->bvh_trees[i]);
+ }
+ }
+}
+
+void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx)
+{
+ if (sctx->flag & SNAP_OBJECT_USE_CACHE) {
+ BLI_ghash_free(sctx->cache.object_map, NULL, snap_object_data_free);
+ BLI_memarena_free(sctx->cache.mem_arena);
+ }
+
+ MEM_freeN(sctx);
+}
+
+
+bool ED_transform_snap_object_project_ray_ex(
+ SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float ray_start[3], const float ray_normal[3], float *ray_depth,
+ float r_loc[3], float r_no[3], int *r_index,
+ Object **r_ob, float r_obmat[4][4])
+{
+ Base *base_act = params->use_object_active ? sctx->scene->basact : NULL;
+ Object *obedit = params->use_object_edit ? sctx->scene->obedit : NULL;
+
+ return snapObjectsRay(
+ sctx,
+ params->snap_select, params->snap_to,
+ NULL, NULL,
+ base_act, obedit,
+ ray_start, ray_normal, ray_start, ray_depth,
+ r_loc, r_no, r_index,
+ r_ob, r_obmat);
+}
+
+/**
+ * Convenience function for snap ray-casting.
+ *
+ * Given a ray, cast it into the scene (snapping to faces).
+ *
+ * \return Snap success
+ */
+static bool transform_snap_context_project_ray_impl(
+ SnapObjectContext *sctx,
+ const float ray_start[3], const float ray_normal[3], float *ray_dist,
+ float r_co[3], float r_no[3])
+{
+ bool ret;
+
+ /* try snap edge, then face if it fails */
+ ret = ED_transform_snap_object_project_ray_ex(
+ sctx,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .snap_to = SCE_SNAP_MODE_FACE,
+ .use_object_edit = (sctx->scene->obedit != NULL),
+ },
+ ray_start, ray_normal, ray_dist,
+ r_co, r_no, NULL,
+ NULL, NULL);
+
+ return ret;
+}
+
+bool ED_transform_snap_object_project_ray(
+ SnapObjectContext *sctx,
+ const float ray_origin[3], const float ray_direction[3], float *ray_dist,
+ float r_co[3], float r_no[3])
+{
+ float ray_dist_fallback;
+ if (ray_dist == NULL) {
+ ray_dist_fallback = BVH_RAYCAST_DIST_MAX;
+ ray_dist = &ray_dist_fallback;
+ }
+
+ float no_fallback[3];
+ if (r_no == NULL) {
+ r_no = no_fallback;
+ }
+
+ return transform_snap_context_project_ray_impl(
+ sctx,
+ ray_origin, ray_direction, ray_dist,
+ r_co, r_no);
+}
+
+static bool transform_snap_context_project_view3d_mixed_impl(
+ SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float mval[2], float *dist_px,
+ bool use_depth,
+ float r_co[3], float r_no[3])
+{
+ float ray_dist = BVH_RAYCAST_DIST_MAX;
+ bool is_hit = false;
+
+ float r_no_dummy[3];
+ if (r_no == NULL) {
+ r_no = r_no_dummy;
+ }
+
+ const int elem_type[3] = {SCE_SNAP_MODE_VERTEX, SCE_SNAP_MODE_EDGE, SCE_SNAP_MODE_FACE};
+
+ BLI_assert(params->snap_to_flag != 0);
+ BLI_assert((params->snap_to_flag & ~(1 | 2 | 4)) == 0);
+
+ struct SnapObjectParams params_temp = *params;
+
+ for (int i = 0; i < 3; i++) {
+ if ((params->snap_to_flag & (1 << i)) && (is_hit == false || use_depth)) {
+ if (use_depth == false) {
+ ray_dist = BVH_RAYCAST_DIST_MAX;
+ }
+
+ params_temp.snap_to = elem_type[i];
+
+ if (ED_transform_snap_object_project_view3d(
+ sctx,
+ &params_temp,
+ mval, dist_px, &ray_dist,
+ r_co, r_no))
+ {
+ is_hit = true;
+ }
+ }
+ }
+
+ return is_hit;
+}
+
+/**
+ * Convenience function for performing snapping.
+ *
+ * Given a 2D region value, snap to vert/edge/face.
+ *
+ * \param sctx: Snap context.
+ * \param mval: Screenspace coordinate.
+ * \param dist_px: Maximum distance to snap (in pixels).
+ * \param use_depth: Snap to the closest element, use when using more than one snap type.
+ * \param r_co: hit location.
+ * \param r_no: hit normal (optional).
+ * \return Snap success
+ */
+bool ED_transform_snap_object_project_view3d_mixed(
+ SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float mval_fl[2], float *dist_px,
+ bool use_depth,
+ float r_co[3], float r_no[3])
+{
+ return transform_snap_context_project_view3d_mixed_impl(
+ sctx,
+ params,
+ mval_fl, dist_px, use_depth,
+ r_co, r_no);
+}
+
+bool ED_transform_snap_object_project_view3d_ex(
+ SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float mval[2], float *dist_px,
+ float *ray_depth,
+ float r_loc[3], float r_no[3], int *r_index)
+{
+ float ray_start[3], ray_normal[3], ray_orgigin[3];
+
+ if (!ED_view3d_win_to_ray_ex(
+ sctx->v3d_data.ar, sctx->v3d_data.v3d,
+ mval, ray_orgigin, ray_normal, ray_start, true))
+ {
+ return false;
+ }
+
+ Base *base_act = params->use_object_active ? sctx->scene->basact : NULL;
+ Object *obedit = params->use_object_edit ? sctx->scene->obedit : NULL;
+ return snapObjectsRay(
+ sctx,
+ params->snap_select, params->snap_to,
+ mval, dist_px,
+ base_act, obedit,
+ ray_start, ray_normal, ray_orgigin, ray_depth,
+ r_loc, r_no, r_index, NULL, NULL);
+}
+
+bool ED_transform_snap_object_project_view3d(
+ SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float mval[2], float *dist_px,
+ float *ray_depth,
+ float r_loc[3], float r_no[3])
+{
+ return ED_transform_snap_object_project_view3d_ex(
+ sctx,
+ params,
+ mval, dist_px,
+ ray_depth,
+ r_loc, r_no, NULL);
+}
+
+/** \} */
diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c
index bc7a8374c73..441fd446cd6 100644
--- a/source/blender/editors/util/editmode_undo.c
+++ b/source/blender/editors/util/editmode_undo.c
@@ -40,7 +40,7 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
-#include "BKE_blender.h"
+#include "BKE_blender_undo.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c
index 98efbb49ca7..2a58b1fd2ec 100644
--- a/source/blender/editors/util/undo.c
+++ b/source/blender/editors/util/undo.c
@@ -42,7 +42,7 @@
#include "BLT_translation.h"
-#include "BKE_blender.h"
+#include "BKE_blender_undo.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 73d1f99079d..be5a0ab4173 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -1488,7 +1488,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
function = gpu_lookup_function(name);
if (!function) {
fprintf(stderr, "GPU failed to find function %s\n", name);
- return 0;
+ return false;
}
node = GPU_node_begin(name);
@@ -1508,7 +1508,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
gpu_material_add_node(mat, node);
- return 1;
+ return true;
}
bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...)
@@ -1522,7 +1522,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
function = gpu_lookup_function(name);
if (!function) {
fprintf(stderr, "GPU failed to find function %s\n", name);
- return 0;
+ return false;
}
node = GPU_node_begin(name);
@@ -1569,7 +1569,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
gpu_material_add_node(mat, node);
- return 1;
+ return true;
}
int GPU_link_changed(GPUNodeLink *link)
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 18468c1674f..72a59e6843d 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -135,6 +135,13 @@ void linearrgb_to_srgb(vec4 col_from, out vec4 col_to)
col_to.a = col_from.a;
}
+void color_to_normal(vec3 color, out vec3 normal)
+{
+ normal.x = 2.0 * ((color.r) - 0.5);
+ normal.y = -2.0 * ((color.g) - 0.5);
+ normal.z = 2.0 * ((color.b) - 0.5);
+}
+
#define M_PI 3.14159265358979323846
#define M_1_PI 0.31830988618379069
@@ -369,6 +376,10 @@ void vec_math_average(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
outval = length(outvec);
outvec = normalize(outvec);
}
+void vec_math_mix(float strength, vec3 v1, vec3 v2, out vec3 outvec)
+{
+ outvec = strength*v1 + (1 - strength) * v2;
+}
void vec_math_dot(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
@@ -2701,9 +2712,12 @@ void node_object_info(out vec3 location, out float object_index, out float mater
random = 0.0;
}
-void node_normal_map(float strength, vec4 color, vec3 N, out vec3 result)
+void node_normal_map(vec4 tangent, vec3 normal, vec3 texnormal, out vec3 outnormal)
{
- result = N;
+ vec3 B = tangent.w * cross(normal, tangent.xyz);
+
+ outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * normal;
+ outnormal = normalize(outnormal);
}
void node_bump(float strength, float dist, float height, vec3 N, out vec3 result)
diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c
index 562bdecb842..8b4e95ac452 100644
--- a/source/blender/imbuf/intern/cineon/dpxlib.c
+++ b/source/blender/imbuf/intern/cineon/dpxlib.c
@@ -184,8 +184,8 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
}
else {
if (verbose) {
- printf("DPX: Bad magic number %lu in \"%s\".\n",
- (uintptr_t)header.fileHeader.magic_num, byteStuff);
+ printf("DPX: Bad magic number %u in \"%s\".\n",
+ header.fileHeader.magic_num, byteStuff);
}
logImageClose(dpx);
return NULL;
diff --git a/source/blender/imbuf/intern/stereoimbuf.c b/source/blender/imbuf/intern/stereoimbuf.c
index 19edce3da3b..a55cef60943 100644
--- a/source/blender/imbuf/intern/stereoimbuf.c
+++ b/source/blender/imbuf/intern/stereoimbuf.c
@@ -719,6 +719,9 @@ ImBuf *IMB_stereo3d_ImBuf(ImageFormatData *im_format, ImBuf *ibuf_left, ImBuf *i
IMB_stereo3d_write_dimensions(im_format->stereo3d_format.display_mode, false, ibuf_left->x, ibuf_left->y, &width, &height);
ibuf_stereo = IMB_allocImBuf(width, height, ibuf_left->planes, (is_float ? IB_rectfloat : IB_rect));
+ ibuf_stereo->rect_colorspace = ibuf_left->rect_colorspace;
+ ibuf_stereo->float_colorspace = ibuf_left->float_colorspace;
+
/* copy flags for IB_fields and other settings */
ibuf_stereo->flags = ibuf_left->flags;
diff --git a/source/blender/makesdna/DNA_fileglobal_types.h b/source/blender/makesdna/DNA_fileglobal_types.h
index fc7959c0043..b2ab0d2a08d 100644
--- a/source/blender/makesdna/DNA_fileglobal_types.h
+++ b/source/blender/makesdna/DNA_fileglobal_types.h
@@ -58,7 +58,7 @@ typedef struct FileGlobal {
/* minversion: in file, the oldest past blender version you can use compliant */
/* example: if in 2.43 the meshes lose mesh data, minversion is 2.43 then too */
/* or: in 2.42, subversion 1, same as above, minversion then is 2.42, min subversion 1 */
-/* (defines for version are in the BKE_blender.h file, for historic reasons) */
+/* (defines for version are in the BKE_blender_version.h file, for historic reasons) */
#endif
diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h
index 8790f736600..0c500e366a7 100644
--- a/source/blender/makesdna/DNA_material_types.h
+++ b/source/blender/makesdna/DNA_material_types.h
@@ -197,6 +197,10 @@ typedef struct Material {
short tot_slots;
short pad4[3];
+ /* multiple tangent (Normal Map node) */
+ char nmap_tangent_names[9][64]; /* [MAX_MTFACE+1][MAX_NAME]; +1 for empty name */
+ int nmap_tangent_names_count, pad5;
+
struct TexPaintSlot *texpaintslot; /* cached slot for painting. Make sure to recalculate before use
* with refresh_texpaint_image_cache */
ListBase gpumaterial; /* runtime */
@@ -305,6 +309,7 @@ typedef struct Material {
/* mode2 (is int) */
#define MA_CASTSHADOW (1 << 0)
#define MA_MODE2_PIPELINE (MA_CASTSHADOW)
+#define MA_TANGENT_CONCRETE (1 << 1)
/* mapflag */
#define MA_MAPFLAG_UVPROJECT (1 << 0)
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index 3a64890a84b..1f4e4df4660 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -274,6 +274,7 @@ typedef struct GaussianBlurVars {
typedef struct TextVars {
char text[512];
int text_size;
+ float color[4], shadow_color[4];
float loc[2];
float wrap_width;
char flag;
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index b428ab30784..1487dfa074e 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -580,7 +580,17 @@ static void rna_FModifier_blending_range(PointerRNA *ptr, float *min, float *max
*max = fcm->efra - fcm->sfra;
}
-static void rna_FModifier_verify_data_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+static void rna_FModifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ ID *id = ptr->id.data;
+ AnimData *adt = BKE_animdata_from_id(id);
+ DAG_id_tag_update(id, (GS(id->name) == ID_OB) ? OB_RECALC_OB : OB_RECALC_DATA);
+ if (adt != NULL) {
+ adt->recalc |= ADT_RECALC_ANIM;
+ }
+}
+
+static void rna_FModifier_verify_data_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
FModifier *fcm = (FModifier *)ptr->data;
const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
@@ -588,9 +598,11 @@ static void rna_FModifier_verify_data_update(Main *UNUSED(bmain), Scene *UNUSED(
/* call the verify callback on the modifier if applicable */
if (fmi && fmi->verify_data)
fmi->verify_data(fcm);
+
+ rna_FModifier_update(bmain, scene, ptr);
}
-static void rna_FModifier_active_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+static void rna_FModifier_active_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
FModifier *fm, *fmo = (FModifier *)ptr->data;
@@ -601,7 +613,8 @@ static void rna_FModifier_active_update(Main *UNUSED(bmain), Scene *UNUSED(scene
for (fm = fmo->next; fm; fm = fm->next) {
fm->flag &= ~FMODIFIER_FLAG_ACTIVE;
}
-
+
+ rna_FModifier_update(bmain, scene, ptr);
}
static int rna_FModifierGenerator_coefficients_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
@@ -885,7 +898,7 @@ static void rna_def_fmodifier_generator(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Additive",
"Values generated by this modifier are applied on top of "
"the existing values instead of overwriting them");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, generator_mode_items);
@@ -933,19 +946,19 @@ static void rna_def_fmodifier_function_generator(BlenderRNA *brna)
/* coefficients */
prop = RNA_def_property(srna, "amplitude", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(prop, "Amplitude", "Scale factor determining the maximum/minimum values");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "phase_multiplier", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(prop, "Phase Multiplier", "Scale factor determining the 'speed' of the function");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "phase_offset", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(prop, "Phase Offset", "Constant factor to offset time by for function");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "value_offset", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(prop, "Value Offset", "Constant factor to offset values by");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
/* flags */
prop = RNA_def_property(srna, "use_additive", PROP_BOOLEAN, PROP_NONE);
@@ -953,13 +966,13 @@ static void rna_def_fmodifier_function_generator(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Additive",
"Values generated by this modifier are applied on top of "
"the existing values instead of overwriting them");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "function_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type");
RNA_def_property_enum_items(prop, prop_type_items);
RNA_def_property_ui_text(prop, "Type", "Type of built-in function to use");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
}
/* --------- */
@@ -980,18 +993,18 @@ static void rna_def_fmodifier_envelope_ctrl(BlenderRNA *brna)
prop = RNA_def_property(srna, "min", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "min");
RNA_def_property_ui_text(prop, "Minimum Value", "Lower bound of envelope at this control-point");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "max", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "max");
RNA_def_property_ui_text(prop, "Maximum Value", "Upper bound of envelope at this control-point");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
/* Frame */
prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "time");
RNA_def_property_ui_text(prop, "Frame", "Frame this control-point occurs on");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
/* TODO: */
/* - selection flags (not implemented in UI yet though) */
@@ -1047,17 +1060,17 @@ static void rna_def_fmodifier_envelope(BlenderRNA *brna)
prop = RNA_def_property(srna, "reference_value", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "midval");
RNA_def_property_ui_text(prop, "Reference Value", "Value that envelope's influence is centered around / based on");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "default_min", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "min");
RNA_def_property_ui_text(prop, "Default Minimum", "Lower distance from Reference Value for 1:1 default influence");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "default_max", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "max");
RNA_def_property_ui_text(prop, "Default Maximum", "Upper distance from Reference Value for 1:1 default influence");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
}
/* --------- */
@@ -1087,26 +1100,26 @@ static void rna_def_fmodifier_cycles(BlenderRNA *brna)
RNA_def_property_enum_sdna(prop, NULL, "before_mode");
RNA_def_property_enum_items(prop, prop_type_items);
RNA_def_property_ui_text(prop, "Before Mode", "Cycling mode to use before first keyframe");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "cycles_before", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "before_cycles");
RNA_def_property_ui_text(prop, "Before Cycles",
"Maximum number of cycles to allow before first keyframe (0 = infinite)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
/* after */
prop = RNA_def_property(srna, "mode_after", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "after_mode");
RNA_def_property_enum_items(prop, prop_type_items);
RNA_def_property_ui_text(prop, "After Mode", "Cycling mode to use after last keyframe");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "cycles_after", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "after_cycles");
RNA_def_property_ui_text(prop, "After Cycles",
"Maximum number of cycles to allow after last keyframe (0 = infinite)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
}
/* --------- */
@@ -1135,46 +1148,46 @@ static void rna_def_fmodifier_limits(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_min_x", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FCM_LIMIT_XMIN);
RNA_def_property_ui_text(prop, "Minimum X", "Use the minimum X value");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "use_min_y", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FCM_LIMIT_YMIN);
RNA_def_property_ui_text(prop, "Minimum Y", "Use the minimum Y value");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "use_max_x", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FCM_LIMIT_XMAX);
RNA_def_property_ui_text(prop, "Maximum X", "Use the maximum X value");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "use_max_y", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FCM_LIMIT_YMAX);
RNA_def_property_ui_text(prop, "Maximum Y", "Use the maximum Y value");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "min_x", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "rect.xmin");
RNA_def_property_float_funcs(prop, NULL, "rna_FModifierLimits_minx_set", "rna_FModifierLimits_minx_range");
RNA_def_property_ui_text(prop, "Minimum X", "Lowest X value to allow");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "min_y", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "rect.ymin");
RNA_def_property_float_funcs(prop, NULL, "rna_FModifierLimits_miny_set", "rna_FModifierLimits_miny_range");
RNA_def_property_ui_text(prop, "Minimum Y", "Lowest Y value to allow");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "max_x", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "rect.xmax");
RNA_def_property_float_funcs(prop, NULL, "rna_FModifierLimits_maxx_set", "rna_FModifierLimits_maxx_range");
RNA_def_property_ui_text(prop, "Maximum X", "Highest X value to allow");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "max_y", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "rect.ymax");
RNA_def_property_float_funcs(prop, NULL, "rna_FModifierLimits_maxy_set", "rna_FModifierLimits_maxy_range");
RNA_def_property_ui_text(prop, "Maximum Y", "Highest Y value to allow");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
}
/* --------- */
@@ -1200,33 +1213,33 @@ static void rna_def_fmodifier_noise(BlenderRNA *brna)
RNA_def_property_enum_sdna(prop, NULL, "modification");
RNA_def_property_enum_items(prop, prop_modification_items);
RNA_def_property_ui_text(prop, "Blend Type", "Method of modifying the existing F-Curve");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "size");
RNA_def_property_ui_text(prop, "Scale", "Scaling (in time) of the noise");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "strength");
RNA_def_property_ui_text(prop, "Strength",
"Amplitude of the noise - the amount that it modifies the underlying curve");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "phase", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "phase");
RNA_def_property_ui_text(prop, "Phase", "A random seed for the noise effect");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "offset");
RNA_def_property_ui_text(prop, "Offset", "Time offset for the noise effect");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "depth");
RNA_def_property_ui_text(prop, "Depth", "Amount of fine level detail present in the noise");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
}
@@ -1247,36 +1260,36 @@ static void rna_def_fmodifier_stepped(BlenderRNA *brna)
prop = RNA_def_property(srna, "frame_step", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "step_size");
RNA_def_property_ui_text(prop, "Step Size", "Number of frames to hold each value");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "frame_offset", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "offset");
RNA_def_property_ui_text(prop, "Offset",
"Reference number of frames before frames get held "
"(use to get hold for '1-3' vs '5-7' holding patterns)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "use_frame_start", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FCM_STEPPED_NO_BEFORE);
RNA_def_property_ui_text(prop, "Use Start Frame", "Restrict modifier to only act after its 'start' frame");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "use_frame_end", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FCM_STEPPED_NO_AFTER);
RNA_def_property_ui_text(prop, "Use End Frame", "Restrict modifier to only act before its 'end' frame");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "start_frame");
RNA_def_property_float_funcs(prop, NULL, NULL, "rna_FModifierStepped_start_frame_range");
RNA_def_property_ui_text(prop, "Start Frame", "Frame that modifier's influence starts (if applicable)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
prop = RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "end_frame");
RNA_def_property_float_funcs(prop, NULL, NULL, "rna_FModifierStepped_end_frame_range");
RNA_def_property_ui_text(prop, "End Frame", "Frame that modifier's influence ends (if applicable)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_FModifier_update");
}
/* --------- */
@@ -1314,14 +1327,14 @@ static void rna_def_fmodifier(BlenderRNA *brna)
prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FMODIFIER_FLAG_MUTED);
RNA_def_property_ui_text(prop, "Muted", "F-Curve Modifier will not be evaluated");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
RNA_def_property_ui_icon(prop, ICON_MUTE_IPO_OFF, 1);
prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", FMODIFIER_FLAG_DISABLED);
RNA_def_property_ui_text(prop, "Disabled", "F-Curve Modifier has invalid settings and will not be evaluated");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
/* TODO: setting this to true must ensure that all others in stack are turned off too... */
prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
@@ -1337,7 +1350,7 @@ static void rna_def_fmodifier(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Restrict Frame Range",
"F-Curve Modifier is only applied for the specified frame range to help "
"mask off effects in order to chain them");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1); /* XXX: depends on UI implementation */
prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_NONE);
@@ -1345,32 +1358,32 @@ static void rna_def_fmodifier(BlenderRNA *brna)
RNA_def_property_float_funcs(prop, NULL, "rna_FModifier_start_frame_set", "rna_FModifier_start_frame_range");
RNA_def_property_ui_text(prop, "Start Frame",
"Frame that modifier's influence starts (if Restrict Frame Range is in use)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
prop = RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "efra");
RNA_def_property_float_funcs(prop, NULL, "rna_FModifer_end_frame_set", "rna_FModifier_end_frame_range");
RNA_def_property_ui_text(prop, "End Frame",
"Frame that modifier's influence ends (if Restrict Frame Range is in use)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
prop = RNA_def_property(srna, "blend_in", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "blendin");
RNA_def_property_float_funcs(prop, NULL, NULL, "rna_FModifier_blending_range");
RNA_def_property_ui_text(prop, "Blend In", "Number of frames from start frame for influence to take effect");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
prop = RNA_def_property(srna, "blend_out", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "blendout");
RNA_def_property_float_funcs(prop, NULL, NULL, "rna_FModifier_blending_range");
RNA_def_property_ui_text(prop, "Blend Out", "Number of frames from end frame for influence to fade out");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
/* influence */
prop = RNA_def_property(srna, "use_influence", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FMODIFIER_FLAG_USEINFLUENCE);
RNA_def_property_ui_text(prop, "Use Influence", "F-Curve Modifier's effects will be tempered by a default factor");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1); /* XXX: depends on UI implementation */
prop = RNA_def_property(srna, "influence", PROP_FLOAT, PROP_FACTOR);
@@ -1379,7 +1392,7 @@ static void rna_def_fmodifier(BlenderRNA *brna)
RNA_def_property_float_default(prop, 1.0f);
RNA_def_property_ui_text(prop, "Influence",
"Amount of influence F-Curve Modifier will have when not fading in/out");
- RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, NULL);
+ RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME_PROP, "rna_FModifier_update");
}
/* *********************** */
diff --git a/source/blender/makesrna/intern/rna_nla.c b/source/blender/makesrna/intern/rna_nla.c
index d09cac2a383..eb87eafe16c 100644
--- a/source/blender/makesrna/intern/rna_nla.c
+++ b/source/blender/makesrna/intern/rna_nla.c
@@ -50,9 +50,12 @@
/* needed for some of the validation stuff... */
#include "BKE_animsys.h"
+#include "BKE_depsgraph.h"
+#include "BKE_fcurve.h"
#include "BKE_nla.h"
-#include "BKE_fcurve.h"
+#include "DNA_object_types.h"
+
#include "ED_anim_api.h"
/* temp constant defined for these funcs only... */
@@ -102,7 +105,14 @@ static char *rna_NlaStrip_path(PointerRNA *ptr)
return BLI_strdup("");
}
-static void rna_NlaStrip_transform_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+static void rna_NlaStrip_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
+{
+ ID *id = ptr->id.data;
+
+ ANIM_id_update(scene, id);
+}
+
+static void rna_NlaStrip_transform_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
NlaStrip *strip = (NlaStrip *)ptr->data;
@@ -117,6 +127,8 @@ static void rna_NlaStrip_transform_update(Main *UNUSED(bmain), Scene *UNUSED(sce
BKE_nla_validate_state(iat->adt);
}
}
+
+ rna_NlaStrip_update(bmain, scene, ptr);
}
static void rna_NlaStrip_start_frame_set(PointerRNA *ptr, float value)
@@ -536,45 +548,45 @@ static void rna_def_nlastrip(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* XXX for now, not editable, since this is dangerous */
RNA_def_property_enum_items(prop, prop_type_items);
RNA_def_property_ui_text(prop, "Type", "Type of NLA Strip");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "extrapolation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "extendmode");
RNA_def_property_enum_items(prop, rna_enum_nla_mode_extend_items);
RNA_def_property_ui_text(prop, "Extrapolation", "Action to take for gaps past the strip extents");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "blendmode");
RNA_def_property_enum_items(prop, rna_enum_nla_mode_blend_items);
RNA_def_property_ui_text(prop, "Blending", "Method used for combining strip's result with accumulated result");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
/* Strip extents */
prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "start");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_start_frame_set", NULL);
RNA_def_property_ui_text(prop, "Start Frame", "");
- RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
prop = RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "end");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_end_frame_set", NULL);
RNA_def_property_ui_text(prop, "End Frame", "");
- RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
/* Blending */
prop = RNA_def_property(srna, "blend_in", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "blendin");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_blend_in_set", NULL);
RNA_def_property_ui_text(prop, "Blend In", "Number of frames at start of strip to fade in influence");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "blend_out", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "blendout");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_blend_out_set", NULL);
RNA_def_property_ui_text(prop, "Blend Out", "");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "use_auto_blend", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_AUTO_BLENDS);
@@ -582,7 +594,7 @@ static void rna_def_nlastrip(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Auto Blend In/Out",
"Number of frames for Blending In/Out is automatically determined from "
"overlapping strips");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
/* Action */
prop = RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
@@ -591,20 +603,20 @@ static void rna_def_nlastrip(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
RNA_def_property_editable_func(prop, "rna_NlaStrip_action_editable");
RNA_def_property_ui_text(prop, "Action", "Action referenced by this strip");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
/* Action extents */
prop = RNA_def_property(srna, "action_frame_start", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "actstart");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_start_frame_set", NULL);
RNA_def_property_ui_text(prop, "Action Start Frame", "First frame from action to use");
- RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
prop = RNA_def_property(srna, "action_frame_end", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "actend");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_end_frame_set", NULL);
RNA_def_property_ui_text(prop, "Action End Frame", "Last frame from action to use");
- RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
/* Action Reuse */
prop = RNA_def_property(srna, "repeat", PROP_FLOAT, PROP_NONE);
@@ -614,7 +626,7 @@ static void rna_def_nlastrip(BlenderRNA *brna)
* (minimum should still be > 0 though) if needed... */
RNA_def_property_range(prop, 0.1f, 1000.0f);
RNA_def_property_ui_text(prop, "Repeat", "Number of times to repeat the action range");
- RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "scale");
@@ -623,7 +635,7 @@ static void rna_def_nlastrip(BlenderRNA *brna)
* due to numeric errors */
RNA_def_property_range(prop, 0.0001f, 1000.0f);
RNA_def_property_ui_text(prop, "Scale", "Scaling factor for action");
- RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
/* Strip's F-Curves */
prop = RNA_def_property(srna, "fcurves", PROP_COLLECTION, PROP_NONE);
@@ -647,11 +659,11 @@ static void rna_def_nlastrip(BlenderRNA *brna)
prop = RNA_def_property(srna, "influence", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Influence", "Amount the strip contributes to the current result");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "strip_time", PROP_FLOAT, PROP_TIME);
RNA_def_property_ui_text(prop, "Strip Time", "Frame of referenced Action to evaluate");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
/* TODO: should the animated_influence/time settings be animatable themselves? */
prop = RNA_def_property(srna, "use_animated_influence", PROP_BOOLEAN, PROP_NONE);
@@ -659,19 +671,19 @@ static void rna_def_nlastrip(BlenderRNA *brna)
RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_influence_set");
RNA_def_property_ui_text(prop, "Animated Influence",
"Influence setting is controlled by an F-Curve rather than automatically determined");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "use_animated_time", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_TIME);
RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_time_set");
RNA_def_property_ui_text(prop, "Animated Strip Time",
"Strip time is controlled by an F-Curve rather than automatically determined");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "use_animated_time_cyclic", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_TIME_CYCLIC);
RNA_def_property_ui_text(prop, "Cyclic Strip Time", "Cycle the animated time within the action start & end");
- RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update"); /* is there a better update flag? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
/* settings */
prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
@@ -689,21 +701,21 @@ static void rna_def_nlastrip(BlenderRNA *brna)
prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_MUTED);
RNA_def_property_ui_text(prop, "Muted", "NLA Strip is not evaluated");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "use_reverse", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_REVERSE);
RNA_def_property_ui_text(prop, "Reversed",
"NLA Strip is played back in reverse order (only when timing is "
"automatically determined)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "use_sync_length", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_SYNC_LENGTH);
RNA_def_property_ui_text(prop, "Sync Action Length",
"Update range of frames referenced from action "
"after tweaking strip and its keyframes");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
}
static void rna_api_nlatrack_strips(BlenderRNA *brna, PropertyRNA *cprop)
@@ -775,7 +787,7 @@ static void rna_def_nlatrack(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Solo",
"NLA Track is evaluated itself (i.e. active Action and all other NLA Tracks in the "
"same AnimData block are disabled)");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaTrack_solo_set");
prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
@@ -786,7 +798,7 @@ static void rna_def_nlatrack(BlenderRNA *brna)
prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLATRACK_MUTED);
RNA_def_property_ui_text(prop, "Muted", "NLA Track is not evaluated");
- RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
+ RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
prop = RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLATRACK_PROTECTED);
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 7316c748442..a32967ecca7 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2632,7 +2632,7 @@ static void rna_def_curve_paint_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "error_threshold", PROP_INT, PROP_PIXEL);
RNA_def_property_range(prop, 1, 100);
- RNA_def_property_ui_text(prop, "Tolerance", "Allow deviation for a smoother, less preceise line");
+ RNA_def_property_ui_text(prop, "Tolerance", "Allow deviation for a smoother, less precise line");
prop = RNA_def_property(srna, "corner_angle", PROP_FLOAT, PROP_ANGLE);
RNA_def_property_range(prop, 0, M_PI);
diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c
index 6d7506f3911..9ba50641cc0 100644
--- a/source/blender/makesrna/intern/rna_scene_api.c
+++ b/source/blender/makesrna/intern/rna_scene_api.c
@@ -145,13 +145,22 @@ static void rna_Scene_ray_cast(
{
normalize_v3(direction);
- if (snapObjectsRayEx(
- scene, NULL, NULL, NULL, NULL,
- NULL, SNAP_ALL, SCE_SNAP_MODE_FACE,
+ SnapObjectContext *sctx = ED_transform_snap_object_context_create(
+ G.main, scene, 0);
+
+ bool ret = ED_transform_snap_object_project_ray_ex(
+ sctx,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .snap_to = SCE_SNAP_MODE_FACE,
+ },
origin, direction, &ray_dist,
- r_location, r_normal, NULL, r_index,
- r_ob, (float(*)[4])r_obmat))
- {
+ r_location, r_normal, r_index,
+ r_ob, (float(*)[4])r_obmat);
+
+ ED_transform_snap_object_context_destroy(sctx);
+
+ if (ret) {
*r_success = true;
}
else {
diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c
index e8a45e6a77d..68d4f7f7e51 100644
--- a/source/blender/makesrna/intern/rna_sequencer.c
+++ b/source/blender/makesrna/intern/rna_sequencer.c
@@ -2330,6 +2330,16 @@ static void rna_def_text(StructRNA *srna)
RNA_def_property_ui_range(prop, 0.0f, 1000, 1, -1);
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
+ prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "color");
+ RNA_def_property_ui_text(prop, "Color", "");
+ RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
+
+ prop = RNA_def_property(srna, "shadow_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "shadow_color");
+ RNA_def_property_ui_text(prop, "Shadow Color", "");
+ RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
+
prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "loc");
RNA_def_property_ui_text(prop, "Location", "Location of the text");
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 286ee276d7f..7720e1a1f1b 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -139,7 +139,7 @@ static void rna_userdef_dpi_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Po
/* font's are stored at each DPI level, without this we can easy load 100's of fonts */
BLF_cache_clear();
- BKE_userdef_state();
+ BKE_blender_userdef_refresh();
WM_main_add_notifier(NC_WINDOW, NULL); /* full redraw */
WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); /* refresh region sizes */
}
@@ -149,7 +149,7 @@ static void rna_userdef_virtual_pixel_update(Main *bmain, Scene *UNUSED(scene),
/* font's are stored at each DPI level, without this we can easy load 100's of fonts */
BLF_cache_clear();
- BKE_userdef_state();
+ BKE_blender_userdef_refresh();
/* force setting drawable again */
wmWindowManager *wm = bmain->wm.first;
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index f126e499fc2..0968d2aa5e0 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -506,9 +506,9 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
new_w[i] = dist;
}
else if (wmd->proximity_mode == MOD_WVG_PROXIMITY_GEOMETRY) {
- const short use_trgt_verts = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_VERTS);
- const short use_trgt_edges = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_EDGES);
- const short use_trgt_faces = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_FACES);
+ const bool use_trgt_verts = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_VERTS) != 0;
+ const bool use_trgt_edges = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_EDGES) != 0;
+ const bool use_trgt_faces = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_FACES) != 0;
if (use_trgt_verts || use_trgt_edges || use_trgt_faces) {
DerivedMesh *target_dm = obr->derivedFinal;
diff --git a/source/blender/nodes/shader/node_shader_util.h b/source/blender/nodes/shader/node_shader_util.h
index 2f96bdbe3df..4cb39e0f13b 100644
--- a/source/blender/nodes/shader/node_shader_util.h
+++ b/source/blender/nodes/shader/node_shader_util.h
@@ -55,7 +55,6 @@
#include "BLI_threads.h"
#include "BLI_utildefines.h"
-#include "BKE_blender.h"
#include "BKE_colortools.h"
#include "BKE_global.h"
#include "BKE_image.h"
diff --git a/source/blender/nodes/shader/nodes/node_shader_lamp.c b/source/blender/nodes/shader/nodes/node_shader_lamp.c
index 3b000d49822..d5dac3b7ff8 100644
--- a/source/blender/nodes/shader/nodes/node_shader_lamp.c
+++ b/source/blender/nodes/shader/nodes/node_shader_lamp.c
@@ -69,7 +69,7 @@ static int gpu_shader_lamp(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
return GPU_stack_link(mat, "lamp", in, out, col, energy, lv, dist, shadow, visifac);
}
- return 0;
+ return false;
}
void register_node_type_sh_lamp(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c
index 2af6e19565b..cd398cc8264 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mapping.c
+++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c
@@ -85,12 +85,12 @@ static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
GPUNodeLink *tdomin = GPU_uniform(&domin);
GPUNodeLink *tdomax = GPU_uniform(&domax);
- int result = GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
+ GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
- if (result && texmap->type == TEXMAP_TYPE_NORMAL)
+ if (texmap->type == TEXMAP_TYPE_NORMAL)
GPU_link(mat, "texco_norm", out[0].link, &out[0].link);
- return result;
+ return true;
}
void register_node_type_sh_mapping(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_normal_map.c b/source/blender/nodes/shader/nodes/node_shader_normal_map.c
index 13bf2a0fe43..642e5b296be 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal_map.c
+++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.c
@@ -46,12 +46,111 @@ static void node_shader_init_normal_map(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = attr;
}
-static int gpu_shader_normal_map(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static void node_shader_exec_normal_map(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
+ {
+ if (data) {
+ ShadeInput *shi = ((ShaderCallData *)data)->shi;
+
+ NodeShaderNormalMap *nm = node->storage;
+
+ float strength, vecIn[3];
+ nodestack_get_vec(&strength, SOCK_FLOAT, in[0]);
+ nodestack_get_vec(vecIn, SOCK_VECTOR, in[1]);
+
+ vecIn[0] = -2 * (vecIn[0] - 0.5f);
+ vecIn[1] = 2 * (vecIn[1] - 0.5f);
+ vecIn[2] = 2 * (vecIn[2] - 0.5f);
+
+ CLAMP_MIN(strength, 0.0f);
+
+ float *N = shi->vno;
+ int uv_index = 0;
+ switch (nm->space) {
+ case SHD_NORMAL_MAP_TANGENT:
+ if (nm->uv_map[0]) {
+ /* find uv map by name */
+ for (int i = 0; i < shi->totuv; i++) {
+ if (STREQ(shi->uv[i].name, nm->uv_map)) {
+ uv_index = i;
+ break;
+ }
+ }
+ }
+ else {
+ uv_index = shi->actuv;
+ }
+
+ float *T = shi->tangents[uv_index];
+
+ float B[3];
+ cross_v3_v3v3(B, N, T);
+ mul_v3_fl(B, T[3]);
+
+ for (int j = 0; j < 3; j++)
+ out[0]->vec[j] = vecIn[0] * T[j] + vecIn[1] * B[j] + vecIn[2] * N[j];
+ interp_v3_v3v3(out[0]->vec, N, out[0]->vec, strength);
+ break;
+
+ case SHD_NORMAL_MAP_OBJECT:
+ case SHD_NORMAL_MAP_BLENDER_OBJECT:
+ mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW), vecIn);
+ interp_v3_v3v3(out[0]->vec, N, vecIn, strength);
+ break;
+
+ case SHD_NORMAL_MAP_WORLD:
+ case SHD_NORMAL_MAP_BLENDER_WORLD:
+ mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), vecIn);
+ interp_v3_v3v3(out[0]->vec, N, vecIn, strength);
+ break;
+ }
+ normalize_v3(out[0]->vec);
+ }
+}
+
+static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- GPUNodeLink *normal;
- GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &normal);
+ NodeShaderNormalMap *nm = node->storage;
+ GPUNodeLink *negnorm;
+ GPUNodeLink *realnorm;
+ GPUNodeLink *strength;
+
+ float d[4] = {0, 0, 0, 0};
+
+ if (in[0].link)
+ strength = in[0].link;
+ else
+ strength = GPU_uniform(in[0].vec);
+
+ if (in[1].link) {
+ GPU_link(mat, "color_to_normal", in[1].link, &realnorm);
+ GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm);
+ }
+
+ GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength);
+ GPU_link(mat, "vec_math_negate", GPU_builtin(GPU_VIEW_NORMAL), &negnorm);
+
+ if (in[1].link) {
+ switch (nm->space) {
+ case SHD_NORMAL_MAP_TANGENT:
+ GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &out[0].link);
+ break;
+ case SHD_NORMAL_MAP_OBJECT:
+ case SHD_NORMAL_MAP_BLENDER_OBJECT:
+ GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_LOC_TO_VIEW_MATRIX), &out[0].link);
+ break;
+ case SHD_NORMAL_MAP_WORLD:
+ case SHD_NORMAL_MAP_BLENDER_WORLD:
+ GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_VIEW_MATRIX), &out[0].link);
+ break;
+ }
+ }
+
+ if (out[0].link) {
+ GPU_link(mat, "vec_math_mix", strength, out[0].link, negnorm, &out[0].link);
+ GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
+ }
- return GPU_stack_link(mat, "node_normal_map", in, out, normal);
+ return true;
}
/* node type definition */
@@ -60,12 +159,13 @@ void register_node_type_sh_normal_map(void)
static bNodeType ntype;
sh_node_type_base(&ntype, SH_NODE_NORMAL_MAP, "Normal Map", NODE_CLASS_OP_VECTOR, 0);
- node_type_compatibility(&ntype, NODE_NEW_SHADING);
+ node_type_compatibility(&ntype, NODE_NEW_SHADING | NODE_OLD_SHADING);
node_type_socket_templates(&ntype, sh_node_normal_map_in, sh_node_normal_map_out);
node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
node_type_init(&ntype, node_shader_init_normal_map);
node_type_storage(&ntype, "NodeShaderNormalMap", node_free_standard_storage, node_copy_standard_storage);
node_type_gpu(&ntype, gpu_shader_normal_map);
+ node_type_exec(&ntype, NULL, NULL, node_shader_exec_normal_map);
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_material.c b/source/blender/nodes/shader/nodes/node_shader_output_material.c
index bd98dc1279c..336536b21ee 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_material.c
+++ b/source/blender/nodes/shader/nodes/node_shader_output_material.c
@@ -43,7 +43,7 @@ static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *UNUSED(node)
GPU_stack_link(mat, "node_output_material", in, out, &outlink);
GPU_material_output_link(mat, outlink);
- return 1;
+ return true;
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_world.c b/source/blender/nodes/shader/nodes/node_shader_output_world.c
index ad7389fd56e..f95cc842720 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_world.c
+++ b/source/blender/nodes/shader/nodes/node_shader_output_world.c
@@ -42,7 +42,7 @@ static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *UNUSED(node), b
GPU_stack_link(mat, "node_output_world", in, out, &outlink);
GPU_material_output_link(mat, outlink);
- return 1;
+ return true;
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
index 2b43667a009..292221c9555 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
@@ -60,7 +60,6 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
ImageUser *iuser = NULL;
NodeTexImage *tex = node->storage;
int isdata = tex->color_space == SHD_COLORSPACE_NONE;
- int ret;
if (!ima)
return GPU_stack_link(mat, "node_tex_environment_empty", in, out);
@@ -77,21 +76,19 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
node_shader_gpu_tex_mapping(mat, node, in, out);
if (tex->projection == SHD_PROJ_EQUIRECTANGULAR)
- ret = GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
else
- ret = GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
- if (ret) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
- if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
- GPU_material_do_color_management(mat))
- {
- GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
- }
- BKE_image_release_ibuf(ima, ibuf, NULL);
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+ if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
+ GPU_material_do_color_management(mat))
+ {
+ GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
}
+ BKE_image_release_ibuf(ima, ibuf, NULL);
- return ret;
+ return true;
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c
index f87e792399b..f0a8cda045e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c
@@ -60,7 +60,6 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
ImageUser *iuser = NULL;
NodeTexImage *tex = node->storage;
int isdata = tex->color_space == SHD_COLORSPACE_NONE;
- int ret;
if (!ima)
return GPU_stack_link(mat, "node_tex_image_empty", in, out);
@@ -70,19 +69,18 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
node_shader_gpu_tex_mapping(mat, node, in, out);
- ret = GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
- if (ret) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
- if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
- GPU_material_do_color_management(mat))
- {
- GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
- }
- BKE_image_release_ibuf(ima, ibuf, NULL);
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+ if ((tex->color_space == SHD_COLORSPACE_COLOR) &&
+ ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
+ GPU_material_do_color_management(mat))
+ {
+ GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
}
+ BKE_image_release_ibuf(ima, ibuf, NULL);
- return ret;
+ return true;
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c
index 5cdbaf444f8..2ce38a068b7 100644
--- a/source/blender/nodes/shader/nodes/node_shader_texture.c
+++ b/source/blender/nodes/shader/nodes/node_shader_texture.c
@@ -123,22 +123,20 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
if (tex && tex->type == TEX_IMAGE && tex->ima) {
GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false);
- int ret = GPU_stack_link(mat, "texture_image", in, out, texlink);
+ GPU_stack_link(mat, "texture_image", in, out, texlink);
- if (ret) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
- if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
- GPU_material_do_color_management(mat))
- {
- GPU_link(mat, "srgb_to_linearrgb", out[1].link, &out[1].link);
- }
- BKE_image_release_ibuf(tex->ima, ibuf, NULL);
+ ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
+ if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
+ GPU_material_do_color_management(mat))
+ {
+ GPU_link(mat, "srgb_to_linearrgb", out[1].link, &out[1].link);
}
+ BKE_image_release_ibuf(tex->ima, ibuf, NULL);
- return ret;
+ return true;
}
- else
- return 0;
+
+ return false;
}
void register_node_type_sh_texture(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_vectMath.c b/source/blender/nodes/shader/nodes/node_shader_vectMath.c
index 45a11c5f799..26045dfca04 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vectMath.c
+++ b/source/blender/nodes/shader/nodes/node_shader_vectMath.c
@@ -130,10 +130,10 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN
}
break;
default:
- return 0;
+ return false;
}
- return 1;
+ return true;
}
void register_node_type_sh_vect_math(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c
index 35a12d52b2d..3c165cfcb8a 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c
+++ b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c
@@ -157,8 +157,6 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
struct GPUNodeLink *inputlink;
struct GPUNodeLink *fromto;
- int ret = 0;
-
const char *vtransform = "direction_transform_m4v3";
const char *ptransform = "point_transform_m4v3";
const char *func_name = 0;
@@ -180,24 +178,24 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
/* For cycles we have inverted Z */
/* TODO: pass here the correct matrices */
if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
- ret = GPU_link(mat, "invert_z", inputlink, &inputlink);
+ GPU_link(mat, "invert_z", inputlink, &inputlink);
}
- ret = GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
+ GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
- ret = GPU_link(mat, "invert_z", out[0].link, &out[0].link);
+ GPU_link(mat, "invert_z", out[0].link, &out[0].link);
}
}
else {
- ret = GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
+ GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
}
}
else
- ret = GPU_link(mat, "set_rgb", inputlink, &out[0].link);
+ GPU_link(mat, "set_rgb", inputlink, &out[0].link);
if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL)
- return GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
+ GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
- return ret;
+ return true;
}
void register_node_type_sh_vect_transform(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c
index a271162bd19..4861871e8d3 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c
@@ -42,7 +42,7 @@ static bNodeSocketTemplate sh_node_volume_absorption_out[] = {
static int node_shader_gpu_volume_absorption(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
{
- return 0;
+ return false;
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c
index cb1377348e5..0c5647b4ba8 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c
@@ -43,7 +43,7 @@ static bNodeSocketTemplate sh_node_volume_scatter_out[] = {
static int node_shader_gpu_volume_scatter(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
{
- return 0;
+ return false;
}
/* node type definition */
diff --git a/source/blender/nodes/texture/node_texture_util.h b/source/blender/nodes/texture/node_texture_util.h
index 9000cbb90d8..2263c271ccf 100644
--- a/source/blender/nodes/texture/node_texture_util.h
+++ b/source/blender/nodes/texture/node_texture_util.h
@@ -53,7 +53,6 @@
#include "BLI_threads.h"
#include "BLI_utildefines.h"
-#include "BKE_blender.h"
#include "BKE_colortools.h"
#include "BKE_global.h"
#include "BKE_image.h"
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index ce8f1247919..3c45cb93514 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -223,7 +223,11 @@ static PyObject *bpy_bmfaceseq_get(BPy_BMesh *self, void *UNUSED(closure))
}
PyDoc_STRVAR(bpy_bmloopseq_doc,
-"This meshes face sequence (read-only).\n\n:type: :class:`BMLoopSeq`"
+"This meshes loops (read-only).\n\n:type: :class:`BMLoopSeq`\n"
+"\n"
+".. note::\n"
+"\n"
+" Loops must be accessed via faces, this is only exposed for layer access.\n"
);
static PyObject *bpy_bmloopseq_get(BPy_BMesh *self, void *UNUSED(closure))
{
diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c
index 0dfff9b4a7b..69f1e297b43 100644
--- a/source/blender/python/generic/blf_py_api.c
+++ b/source/blender/python/generic/blf_py_api.c
@@ -332,17 +332,21 @@ PyDoc_STRVAR(py_blf_shadow_doc,
static PyObject *py_blf_shadow(PyObject *UNUSED(self), PyObject *args)
{
int level, fontid;
- float r, g, b, a;
+ float rgba[4];
- if (!PyArg_ParseTuple(args, "iiffff:blf.shadow", &fontid, &level, &r, &g, &b, &a))
+ if (!PyArg_ParseTuple(
+ args, "iiffff:blf.shadow",
+ &fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
+ {
return NULL;
+ }
if (level != 0 && level != 3 && level != 5) {
PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5)");
return NULL;
}
- BLF_shadow(fontid, level, r, g, b, a);
+ BLF_shadow(fontid, level, rgba);
Py_RETURN_NONE;
}
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index c09b39139c2..5bbfb4912e6 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -35,7 +35,7 @@
#include "BKE_appdir.h"
#include "BKE_global.h" /* XXX, G.main only */
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BKE_bpath.h"
#include "RNA_types.h"
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index 595bb7b0f22..17617a231b2 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -48,7 +48,7 @@
#include "BLI_utildefines.h"
#include "BKE_appdir.h"
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BKE_global.h"
#include "DNA_ID.h"
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c
index f9c0982a4c3..9cd6fe3da91 100644
--- a/source/blender/python/intern/bpy_driver.c
+++ b/source/blender/python/intern/bpy_driver.c
@@ -273,6 +273,22 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
if (driver_arg == NULL) {
driver_arg = PyFloat_FromDouble(0.0);
+ dvar->curval = 0.0f;
+ }
+ else {
+ /* no need to worry about overflow here, values from RNA are within limits. */
+ if (PyFloat_CheckExact(driver_arg)) {
+ dvar->curval = (float)PyFloat_AsDouble(driver_arg);
+ }
+ else if (PyLong_CheckExact(driver_arg)) {
+ dvar->curval = (float)PyLong_AsLong(driver_arg);
+ }
+ else if (PyBool_Check(driver_arg)) {
+ dvar->curval = (driver_arg == Py_True);
+ }
+ else {
+ dvar->curval = 0.0f;
+ }
}
}
else
diff --git a/source/blender/python/intern/bpy_library_write.c b/source/blender/python/intern/bpy_library_write.c
index ab239bbfa8c..f582cebb260 100644
--- a/source/blender/python/intern/bpy_library_write.c
+++ b/source/blender/python/intern/bpy_library_write.c
@@ -35,7 +35,7 @@
#include "BLI_path_util.h"
#include "BKE_library.h"
-#include "BKE_blender.h"
+#include "BKE_blendfile.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_report.h"
@@ -66,13 +66,15 @@ PyDoc_STRVAR(bpy_lib_write_doc,
" :type relative_remap: bool\n"
" :arg fake_user: When True, data-blocks will be written with fake-user flag enabled.\n"
" :type fake_user: bool\n"
+" :arg compress: When True, write a compressed blend file.\n"
+" :type compress: bool\n"
);
static PyObject *bpy_lib_write(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
{
static const char *kwlist[] = {
"filepath", "datablocks",
/* optional */
- "relative_remap", "fake_user",
+ "relative_remap", "fake_user", "compress",
NULL,
};
@@ -80,15 +82,16 @@ static PyObject *bpy_lib_write(PyObject *UNUSED(self), PyObject *args, PyObject
const char *filepath;
char filepath_abs[FILE_MAX];
PyObject *datablocks = NULL;
- bool use_relative_remap = false, use_fake_user = false;
+ bool use_relative_remap = false, use_fake_user = false, use_compress = false;
if (!PyArg_ParseTupleAndKeywords(
args, kwds,
- "sO!|$O&O&:write", (char **)kwlist,
+ "sO!|$O&O&O&:write", (char **)kwlist,
&filepath,
&PySet_Type, &datablocks,
PyC_ParseBool, &use_relative_remap,
- PyC_ParseBool, &use_fake_user))
+ PyC_ParseBool, &use_fake_user,
+ PyC_ParseBool, &use_compress))
{
return NULL;
}
@@ -100,6 +103,10 @@ static PyObject *bpy_lib_write(PyObject *UNUSED(self), PyObject *args, PyObject
write_flags |= G_FILE_RELATIVE_REMAP;
}
+ if (use_compress) {
+ write_flags |= G_FILE_COMPRESS;
+ }
+
BLI_strncpy(filepath_abs, filepath, FILE_MAX);
BLI_path_abs(filepath_abs, G.main->name);
diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h
index 12b97aedbd3..8b6dfb88b73 100644
--- a/source/blender/render/extern/include/RE_shader_ext.h
+++ b/source/blender/render/extern/include/RE_shader_ext.h
@@ -139,6 +139,7 @@ typedef struct ShadeInput {
float refcol[4], displace[3];
float strandco, tang[3], nmapnorm[3], nmaptang[4], stress, winspeed[4];
float duplilo[3], dupliuv[3];
+ float tangents[8][4]; /* 8 = MAX_MTFACE */
ShadeInputUV uv[8]; /* 8 = MAX_MTFACE */
ShadeInputCol col[8]; /* 8 = MAX_MCOL */
diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h
index cef3a073084..6de5da3795a 100644
--- a/source/blender/render/intern/include/render_types.h
+++ b/source/blender/render/intern/include/render_types.h
@@ -334,6 +334,8 @@ typedef struct ObjectRen {
char (*mcol)[MAX_CUSTOMDATA_LAYER_NAME];
int actmtface, actmcol, bakemtface;
+ char tangent_mask; /* which tangent layer should be calculated */
+
float obmat[4][4]; /* only used in convertblender.c, for instancing */
/* used on makeraytree */
diff --git a/source/blender/render/intern/include/renderdatabase.h b/source/blender/render/intern/include/renderdatabase.h
index 167ebc58030..b576d69d806 100644
--- a/source/blender/render/intern/include/renderdatabase.h
+++ b/source/blender/render/intern/include/renderdatabase.h
@@ -76,7 +76,7 @@ typedef struct VlakTableNode {
int *origindex;
int totmtface, totmcol;
float *surfnor;
- float *tangent;
+ float *tangent_arrays[MAX_MTFACE];
struct RadFace **radface;
} VlakTableNode;
@@ -137,7 +137,7 @@ struct MTFace *RE_vlakren_get_tface(struct ObjectRen *obr, VlakRen *ren, int n,
struct MCol *RE_vlakren_get_mcol(struct ObjectRen *obr, VlakRen *ren, int n, char **name, int verify);
int *RE_vlakren_get_origindex(struct ObjectRen *obr, VlakRen *vlak, int verify);
float *RE_vlakren_get_surfnor(struct ObjectRen *obr, VlakRen *ren, int verify);
-float *RE_vlakren_get_nmap_tangent(struct ObjectRen *obr, VlakRen *ren, int verify);
+float *RE_vlakren_get_nmap_tangent(ObjectRen *obr, VlakRen *vlak, int index, bool verify);
RadFace **RE_vlakren_get_radface(struct ObjectRen *obr, VlakRen *ren, int verify);
void RE_vlakren_get_normal(struct Render *re, struct ObjectInstanceRen *obi, struct VlakRen *vlr, float *nor);
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c
index eff021c9b14..1a0ef4e64d4 100644
--- a/source/blender/render/intern/source/bake_api.c
+++ b/source/blender/render/intern/source/bake_api.c
@@ -425,7 +425,7 @@ static TriTessFace *mesh_calc_tri_tessface(
if (tangent) {
DM_ensure_normals(dm);
- DM_calc_loop_tangents(dm);
+ DM_calc_loop_tangents(dm, true, NULL, 0);
tspace = dm->getLoopDataArray(dm, CD_TANGENT);
BLI_assert(tspace);
diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c
index a02c262d58d..69ae7433fff 100644
--- a/source/blender/render/intern/source/convertblender.c
+++ b/source/blender/render/intern/source/convertblender.c
@@ -302,7 +302,7 @@ static void calc_tangent_vector(ObjectRen *obr, VlakRen *vlr, int do_tangent)
typedef struct {
ObjectRen *obr;
-
+ int mtface_index;
} SRenderMeshToTangent;
/* interface */
@@ -335,7 +335,7 @@ static void GetTextureCoordinate(const SMikkTSpaceContext *pContext, float r_uv[
//assert(vert_index>=0 && vert_index<4);
SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num);
- MTFace *tface= RE_vlakren_get_tface(pMesh->obr, vlr, pMesh->obr->actmtface, NULL, 0);
+ MTFace *tface= RE_vlakren_get_tface(pMesh->obr, vlr, pMesh->mtface_index, NULL, 0);
const float *coord;
if (tface != NULL) {
@@ -369,7 +369,7 @@ static void SetTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[
//assert(vert_index>=0 && vert_index<4);
SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
VlakRen *vlr = RE_findOrAddVlak(pMesh->obr, face_num);
- float *ftang = RE_vlakren_get_nmap_tangent(pMesh->obr, vlr, 1);
+ float *ftang = RE_vlakren_get_nmap_tangent(pMesh->obr, vlr, pMesh->mtface_index, true);
if (ftang!=NULL) {
copy_v3_v3(&ftang[iVert*4+0], fvTangent);
ftang[iVert*4+3]=fSign;
@@ -455,7 +455,12 @@ static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, bool do_verte
sInterface.m_getNormal = GetNormal;
sInterface.m_setTSpaceBasic = SetTSpace;
- genTangSpaceDefault(&sContext);
+ for (a = 0; a < MAX_MTFACE; a++) {
+ if (obr->tangent_mask & 1 << a) {
+ mesh2tangent.mtface_index = a;
+ genTangSpaceDefault(&sContext);
+ }
+ }
}
}
@@ -1969,7 +1974,8 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
float xn, yn, zn, imat[3][3], mat[4][4]; //nor[3],
float *orco = NULL;
short (*loop_nors)[4][3] = NULL;
- bool need_orco = false, need_stress = false, need_nmap_tangent = false, need_tangent = false, need_origindex = false;
+ bool need_orco = false, need_stress = false, need_tangent = false, need_origindex = false;
+ bool need_nmap_tangent_concrete = false;
int a, a1, ok, vertofs;
int end, totvert = 0;
bool do_autosmooth = false, do_displace = false;
@@ -2004,9 +2010,11 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
if (ma->mode_l & MA_NORMAP_TANG) {
if (me->mtpoly==NULL) {
need_orco= 1;
- need_tangent= 1;
}
- need_nmap_tangent= 1;
+ need_tangent= 1;
+ }
+ if (ma->mode2_l & MA_TANGENT_CONCRETE) {
+ need_nmap_tangent_concrete = true;
}
}
}
@@ -2017,7 +2025,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
need_orco= 1;
need_tangent= 1;
}
- need_nmap_tangent= 1;
+ need_nmap_tangent_concrete = true;
}
/* check autosmooth and displacement, we then have to skip only-verts optimize
@@ -2130,14 +2138,13 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
/* store customdata names, because DerivedMesh is freed */
RE_set_customdata_names(obr, &dm->faceData);
- /* add tangent layer if we need one */
- if (need_nmap_tangent!=0 && CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1) {
- bool generate_data = false;
- if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) {
- dm->calcLoopTangents(dm);
- generate_data = true;
- }
- DM_generate_tangent_tessface_data(dm, generate_data);
+ /* add tangent layers if we need */
+ if ((ma->nmap_tangent_names_count && need_nmap_tangent_concrete) || need_tangent) {
+ dm->calcLoopTangents(
+ dm, need_tangent,
+ (const char (*)[MAX_NAME])ma->nmap_tangent_names, ma->nmap_tangent_names_count);
+ obr->tangent_mask = dm->tangent_mask;
+ DM_generate_tangent_tessface_data(dm, need_nmap_tangent_concrete || need_tangent);
}
/* still to do for keys: the correct local texture coordinate */
@@ -2257,7 +2264,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
CustomDataLayer *layer;
MTFace *mtface, *mtf;
MCol *mcol, *mc;
- int index, mtfn= 0, mcn= 0, mtng=0, mln = 0, vindex;
+ int index, mtfn= 0, mcn= 0, mln = 0, vindex;
char *name;
int nr_verts = v4!=0 ? 4 : 3;
@@ -2280,17 +2287,24 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
for (vindex=0; vindex<nr_verts; vindex++)
mc[vindex]=mcol[a*4+rev_tab[vindex]];
}
- else if (layer->type == CD_TANGENT && mtng < 1) {
- if (need_nmap_tangent != 0) {
- const float * tangent = (const float *) layer->data;
- float * ftang = RE_vlakren_get_nmap_tangent(obr, vlr, 1);
+ else if (layer->type == CD_TANGENT) {
+ if (need_nmap_tangent_concrete || need_tangent) {
+ int uv_start = CustomData_get_layer_index(&dm->faceData, CD_MTFACE);
+ int uv_index = CustomData_get_named_layer_index(&dm->faceData, CD_MTFACE, layer->name);
+ BLI_assert(uv_start >= 0 && uv_index >= 0);
+ if ((uv_start < 0 || uv_index < 0))
+ continue;
+ int n = uv_index - uv_start;
+
+ const float *tangent = (const float *) layer->data;
+ float *ftang = RE_vlakren_get_nmap_tangent(obr, vlr, n, true);
+
for (vindex=0; vindex<nr_verts; vindex++) {
copy_v4_v4(ftang+vindex*4, tangent+a*16+rev_tab[vindex]*4);
mul_mat3_m4_v3(mat, ftang+vindex*4);
normalize_v3(ftang+vindex*4);
}
}
- mtng++;
}
else if (layer->type == CD_TESSLOOPNORMAL && mln < 1) {
if (loop_nors) {
@@ -2398,7 +2412,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
}
if (recalc_normals!=0 || need_tangent!=0)
- calc_vertexnormals(re, obr, recalc_normals, need_tangent, need_nmap_tangent);
+ calc_vertexnormals(re, obr, recalc_normals, need_tangent, need_nmap_tangent_concrete);
}
MEM_SAFE_FREE(loop_nors);
diff --git a/source/blender/render/intern/source/multires_bake.c b/source/blender/render/intern/source/multires_bake.c
index 8eb6e7000ab..8c6d9c5f951 100644
--- a/source/blender/render/intern/source/multires_bake.c
+++ b/source/blender/render/intern/source/multires_bake.c
@@ -456,7 +456,7 @@ static void do_multires_bake(MultiresBakeRender *bkr, Image *ima, bool require_t
if (require_tangent) {
if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1)
- DM_calc_loop_tangents(dm);
+ DM_calc_loop_tangents(dm, true, NULL, 0);
pvtangent = DM_get_loop_data_layer(dm, CD_TANGENT);
}
diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c
index 39e4e7b048a..de08ea8d11c 100644
--- a/source/blender/render/intern/source/renderdatabase.c
+++ b/source/blender/render/intern/source/renderdatabase.c
@@ -70,6 +70,7 @@
#include "DNA_material_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_texture_types.h"
+#include "DNA_listBase.h"
#include "BKE_customdata.h"
#include "BKE_DerivedMesh.h"
@@ -379,19 +380,28 @@ float *RE_vlakren_get_surfnor(ObjectRen *obr, VlakRen *vlak, int verify)
return surfnor + (vlak->index & 255)*RE_SURFNOR_ELEMS;
}
-float *RE_vlakren_get_nmap_tangent(ObjectRen *obr, VlakRen *vlak, int verify)
+float *RE_vlakren_get_nmap_tangent(ObjectRen *obr, VlakRen *vlak, int index, bool verify)
{
- float *tangent;
+ float **tangents;
int nr= vlak->index>>8;
- tangent= obr->vlaknodes[nr].tangent;
- if (tangent==NULL) {
- if (verify)
- tangent= obr->vlaknodes[nr].tangent= MEM_callocN(256*RE_NMAP_TANGENT_ELEMS*sizeof(float), "tangent table");
+ tangents = obr->vlaknodes[nr].tangent_arrays;
+
+ if (index + 1 > 8) {
+ return NULL;
+ }
+
+ index = index < 0 ? 0: index;
+
+ if (tangents[index] == NULL) {
+ if (verify) {
+ tangents[index] = MEM_callocN(256*RE_NMAP_TANGENT_ELEMS*sizeof(float), "tangent table");
+ }
else
return NULL;
}
- return tangent + (vlak->index & 255)*RE_NMAP_TANGENT_ELEMS;
+
+ return tangents[index] + (vlak->index & 255)*RE_NMAP_TANGENT_ELEMS;
}
RadFace **RE_vlakren_get_radface(ObjectRen *obr, VlakRen *vlak, int verify)
@@ -414,7 +424,8 @@ VlakRen *RE_vlakren_copy(ObjectRen *obr, VlakRen *vlr)
VlakRen *vlr1 = RE_findOrAddVlak(obr, obr->totvlak++);
MTFace *mtface, *mtface1;
MCol *mcol, *mcol1;
- float *surfnor, *surfnor1, *tangent, *tangent1;
+ float *surfnor, *surfnor1;
+ float *tangent, *tangent1;
int *origindex, *origindex1;
RadFace **radface, **radface1;
int i, index = vlr1->index;
@@ -446,9 +457,11 @@ VlakRen *RE_vlakren_copy(ObjectRen *obr, VlakRen *vlr)
copy_v3_v3(surfnor1, surfnor);
}
- tangent= RE_vlakren_get_nmap_tangent(obr, vlr, 0);
- if (tangent) {
- tangent1= RE_vlakren_get_nmap_tangent(obr, vlr1, 1);
+ for (i=0; i < MAX_MTFACE; i++) {
+ tangent = RE_vlakren_get_nmap_tangent(obr, vlr, i, false);
+ if (!tangent)
+ continue;
+ tangent1 = RE_vlakren_get_nmap_tangent(obr, vlr1, i, true);
memcpy(tangent1, tangent, sizeof(float)*RE_NMAP_TANGENT_ELEMS);
}
@@ -789,8 +802,10 @@ void free_renderdata_vlaknodes(VlakTableNode *vlaknodes)
MEM_freeN(vlaknodes[a].origindex);
if (vlaknodes[a].surfnor)
MEM_freeN(vlaknodes[a].surfnor);
- if (vlaknodes[a].tangent)
- MEM_freeN(vlaknodes[a].tangent);
+ for (int b = 0; b < MAX_MTFACE; b++) {
+ if (vlaknodes[a].tangent_arrays[b])
+ MEM_freeN(vlaknodes[a].tangent_arrays[b]);
+ }
if (vlaknodes[a].radface)
MEM_freeN(vlaknodes[a].radface);
}
diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c
index d5fdcb2423a..bfdeed1e354 100644
--- a/source/blender/render/intern/source/shadeinput.c
+++ b/source/blender/render/intern/source/shadeinput.c
@@ -883,7 +883,10 @@ void shade_input_set_shade_texco(ShadeInput *shi)
float u = shi->u, v = shi->v;
float l = 1.0f + u + v, dl;
int mode = shi->mode; /* or-ed result for all nodes */
+ int mode2 = shi->mode2;
short texco = shi->mat->texco;
+ const bool need_mikk_tangent = (mode & MA_NORMAP_TANG || R.flag & R_NEED_TANGENT);
+ const bool need_mikk_tangent_concrete = (mode2 & MA_TANGENT_CONCRETE) != 0;
/* calculate dxno */
if (shi->vlr->flag & R_SMOOTH) {
@@ -904,8 +907,8 @@ void shade_input_set_shade_texco(ShadeInput *shi)
}
/* calc tangents */
- if (mode & (MA_TANGENT_V | MA_NORMAP_TANG) || R.flag & R_NEED_TANGENT) {
- const float *tangent, *s1, *s2, *s3;
+ if (mode & (MA_TANGENT_V | MA_NORMAP_TANG) || mode2 & MA_TANGENT_CONCRETE || R.flag & R_NEED_TANGENT) {
+ const float *s1, *s2, *s3;
float tl, tu, tv;
if (shi->vlr->flag & R_SMOOTH) {
@@ -942,14 +945,18 @@ void shade_input_set_shade_texco(ShadeInput *shi)
}
}
- if (mode & MA_NORMAP_TANG || R.flag & R_NEED_TANGENT) {
- tangent = RE_vlakren_get_nmap_tangent(obr, shi->vlr, 0);
+ if (need_mikk_tangent || need_mikk_tangent_concrete) {
+ int j1 = shi->i1, j2 = shi->i2, j3 = shi->i3;
+ float c0[3], c1[3], c2[3];
+ int acttang = obr->actmtface;
- if (tangent) {
- int j1 = shi->i1, j2 = shi->i2, j3 = shi->i3;
- float c0[3], c1[3], c2[3];
+ vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3);
- vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3);
+ /* cycle through all tangent in vlakren */
+ for (int i = 0; i < MAX_MTFACE; i++) {
+ const float *tangent = RE_vlakren_get_nmap_tangent(obr, shi->vlr, i, false);
+ if (!tangent)
+ continue;
copy_v3_v3(c0, &tangent[j1 * 4]);
copy_v3_v3(c1, &tangent[j2 * 4]);
@@ -965,13 +972,19 @@ void shade_input_set_shade_texco(ShadeInput *shi)
/* we don't normalize the interpolated TBN tangent
* corresponds better to how it's done in game engines */
- shi->nmaptang[0] = (tl * c2[0] - tu * c0[0] - tv * c1[0]);
- shi->nmaptang[1] = (tl * c2[1] - tu * c0[1] - tv * c1[1]);
- shi->nmaptang[2] = (tl * c2[2] - tu * c0[2] - tv * c1[2]);
+ shi->tangents[i][0] = (tl * c2[0] - tu * c0[0] - tv * c1[0]);
+ shi->tangents[i][1] = (tl * c2[1] - tu * c0[1] - tv * c1[1]);
+ shi->tangents[i][2] = (tl * c2[2] - tu * c0[2] - tv * c1[2]);
/* the sign is the same for all 3 vertices of any
* non degenerate triangle. */
- shi->nmaptang[3] = tangent[j1 * 4 + 3];
+ shi->tangents[i][3] = tangent[j1 * 4 + 3];
+
+ if (acttang == i && need_mikk_tangent) {
+ for (int m = 0; m < 4; m++) {
+ shi->nmaptang[m] = shi->tangents[i][m];
+ }
+ }
}
}
}
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index e5b98a1b735..ad8c31a32f3 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2197,12 +2197,6 @@ static int wm_event_inside_i(wmEvent *event, rcti *rect)
return 1;
if (BLI_rcti_isect_pt_v(rect, &event->x))
return 1;
- if (event->type == MOUSEMOVE) {
- if (BLI_rcti_isect_pt_v(rect, &event->prevx)) {
- return 1;
- }
- return 0;
- }
return 0;
}
@@ -2432,7 +2426,6 @@ void wm_event_do_handlers(bContext *C)
if ((action & WM_HANDLER_BREAK) == 0) {
ScrArea *sa;
ARegion *ar;
- int doit = 0;
/* Note: setting subwin active should be done here, after modal handlers have been done */
if (event->type == MOUSEMOVE) {
@@ -2484,8 +2477,6 @@ void wm_event_do_handlers(bContext *C)
if (CTX_wm_window(C) == NULL)
return;
- doit |= (BLI_rcti_isect_pt_v(&ar->winrct, &event->x));
-
if (action & WM_HANDLER_BREAK)
break;
}
@@ -2518,18 +2509,12 @@ void wm_event_do_handlers(bContext *C)
return;
}
- /* XXX hrmf, this gives reliable previous mouse coord for area change, feels bad?
- * doing it on ghost queue gives errors when mousemoves go over area borders */
- if (doit && win->screen->subwinactive != win->screen->mainwin) {
- win->eventstate->prevx = event->x;
- win->eventstate->prevy = event->y;
- //printf("win->eventstate->prev = %d %d\n", event->x, event->y);
- }
- else {
- //printf("not setting prev to %d %d\n", event->x, event->y);
- }
}
-
+
+ /* update previous mouse position for following events to use */
+ win->eventstate->prevx = event->x;
+ win->eventstate->prevy = event->y;
+
/* unlink and free here, blender-quit then frees all */
BLI_remlink(&win->queue, event);
wm_event_free(event);
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 498a3f5bdda..36b819d3495 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -74,6 +74,8 @@
#include "BKE_utildefines.h"
#include "BKE_autoexec.h"
#include "BKE_blender.h"
+#include "BKE_blendfile.h"
+#include "BKE_blender_undo.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
@@ -341,7 +343,7 @@ static void wm_init_userdef(bContext *C, const bool from_memory)
/* update tempdir from user preferences */
BKE_tempdir_init(U.tempdir);
- BKE_userdef_state();
+ BKE_blender_userdef_refresh();
}
@@ -551,7 +553,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
/* confusing this global... */
G.relbase_valid = 1;
- retval = BKE_read_file(C, filepath, reports);
+ retval = BKE_blendfile_read(C, filepath, reports);
/* when loading startup.blend's, we can be left with a blank path */
if (G.main->name[0]) {
G.save_over = 1;
@@ -572,12 +574,12 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
wm_window_match_do(C, &wmbase);
WM_check(C); /* opens window(s), checks keymaps */
- if (retval == BKE_READ_FILE_OK_USERPREFS) {
+ if (retval == BKE_BLENDFILE_READ_OK_USERPREFS) {
/* in case a userdef is read from regular .blend */
wm_init_userdef(C, false);
}
- if (retval != BKE_READ_FILE_FAIL) {
+ if (retval != BKE_BLENDFILE_READ_FAIL) {
if (do_history) {
wm_history_file_update();
}
@@ -690,7 +692,7 @@ int wm_homefile_read(bContext *C, ReportList *reports, bool from_memory, const c
if (!from_memory) {
if (BLI_access(startstr, R_OK) == 0) {
- success = (BKE_read_file(C, startstr, NULL) != BKE_READ_FILE_FAIL);
+ success = (BKE_blendfile_read(C, startstr, NULL) != BKE_BLENDFILE_READ_FAIL);
}
if (BLI_listbase_is_empty(&U.themes)) {
if (G.debug & G_DEBUG)
@@ -705,7 +707,7 @@ int wm_homefile_read(bContext *C, ReportList *reports, bool from_memory, const c
}
if (success == 0) {
- success = BKE_read_file_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL, true);
+ success = BKE_blendfile_read_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL, true);
if (BLI_listbase_is_empty(&wmbase)) {
wm_clear_default_size(C);
}
@@ -720,8 +722,8 @@ int wm_homefile_read(bContext *C, ReportList *reports, bool from_memory, const c
/* check new prefs only after startup.blend was finished */
if (!from_memory && BLI_exists(prefstr)) {
- int done = BKE_read_file_userdef(prefstr, NULL);
- if (done != BKE_READ_FILE_FAIL) {
+ int done = BKE_blendfile_read_userdef(prefstr, NULL);
+ if (done != BKE_BLENDFILE_READ_FAIL) {
read_userdef_from_memory = false;
printf("Read new prefs: %s\n", prefstr);
}
@@ -1352,7 +1354,7 @@ static int wm_userpref_write_exec(bContext *C, wmOperator *op)
BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_USERPREF_FILE);
printf("trying to save userpref at %s ", filepath);
- if (BKE_write_file_userdef(filepath, op->reports) == 0) {
+ if (BKE_blendfile_write_userdef(filepath, op->reports) == 0) {
printf("fail\n");
return OPERATOR_CANCELLED;
}
@@ -1631,6 +1633,7 @@ void WM_OT_open_mainfile(wmOperatorType *ot)
static int wm_revert_mainfile_exec(bContext *C, wmOperator *op)
{
bool success;
+ char filepath[FILE_MAX];
wm_open_init_use_scripts(op, false);
@@ -1639,7 +1642,8 @@ static int wm_revert_mainfile_exec(bContext *C, wmOperator *op)
else
G.f &= ~G_SCRIPT_AUTOEXEC;
- success = wm_file_read_opwrap(C, G.main->name, op->reports, !(G.f & G_SCRIPT_AUTOEXEC));
+ BLI_strncpy(filepath, G.main->name, sizeof(filepath));
+ success = wm_file_read_opwrap(C, filepath, op->reports, !(G.f & G_SCRIPT_AUTOEXEC));
if (success) {
return OPERATOR_FINISHED;
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index e08d0afb906..6300d2ed3c7 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -54,6 +54,7 @@
#include "BLO_writefile.h"
#include "BKE_blender.h"
+#include "BKE_blender_undo.h"
#include "BKE_context.h"
#include "BKE_screen.h"
#include "BKE_DerivedMesh.h"
@@ -492,10 +493,10 @@ void WM_exit_ext(bContext *C, const bool do_python)
RE_FreeAllRender();
RE_engines_exit();
- ED_preview_free_dbase(); /* frees a Main dbase, before free_blender! */
+ ED_preview_free_dbase(); /* frees a Main dbase, before BKE_blender_free! */
if (C && wm)
- wm_free_reports(C); /* before free_blender! - since the ListBases get freed there */
+ wm_free_reports(C); /* before BKE_blender_free! - since the ListBases get freed there */
BKE_sequencer_free_clipboard(); /* sequencer.c */
BKE_tracking_clipboard_free();
@@ -506,7 +507,7 @@ void WM_exit_ext(bContext *C, const bool do_python)
COM_deinitialize();
#endif
- free_blender(); /* blender.c, does entire library and spacetypes */
+ BKE_blender_free(); /* blender.c, does entire library and spacetypes */
// free_matcopybuf();
ANIM_fcurves_copybuf_free();
ANIM_drivers_copybuf_free();
@@ -534,10 +535,10 @@ void WM_exit_ext(bContext *C, const bool do_python)
/* option not to close python so we can use 'atexit' */
if (do_python) {
/* XXX - old note */
- /* before free_blender so py's gc happens while library still exists */
+ /* before BKE_blender_free so py's gc happens while library still exists */
/* needed at least for a rare sigsegv that can happen in pydrivers */
- /* Update for blender 2.5, move after free_blender because blender now holds references to PyObject's
+ /* Update for blender 2.5, move after BKE_blender_free because blender now holds references to PyObject's
* so decref'ing them after python ends causes bad problems every time
* the pyDriver bug can be fixed if it happens again we can deal with it then */
BPY_python_end();
@@ -562,7 +563,7 @@ void WM_exit_ext(bContext *C, const bool do_python)
ED_file_exit(); /* for fsmenu */
UI_exit();
- BKE_userdef_free();
+ BKE_blender_userdef_free();
RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 8a15237078a..e4ba3969824 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -67,7 +67,7 @@
#include "BLO_readfile.h"
#include "BKE_appdir.h"
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BKE_brush.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
@@ -3124,7 +3124,7 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
BLF_size(fontid, 1.5 * fstyle_points, 1.0f / U.dpi);
BLF_enable(fontid, BLF_SHADOW);
- BLF_shadow(fontid, 3, 0.0f, 0.0f, 0.0f, 0.5f);
+ BLF_shadow(fontid, 3, (const float[4]){0.0f, 0.0f, 0.0f, 0.5f});
BLF_shadow_offset(fontid, 1, -1);
/* draw value */
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 688be21cdd0..42f6585f152 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -457,7 +457,7 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wm
/* displays with larger native pixels, like Macbook. Used to scale dpi with */
/* needed here, because it's used before it reads userdef */
U.pixelsize = wm_window_pixelsize(win);
- BKE_userdef_state();
+ BKE_blender_userdef_refresh();
wm_window_swap_buffers(win);
@@ -834,7 +834,7 @@ void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
/* this can change per window */
U.pixelsize = wm_window_pixelsize(win);
- BKE_userdef_state();
+ BKE_blender_userdef_refresh();
}
}
@@ -1197,7 +1197,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
// printf("change, pixel size %f\n", GHOST_GetNativePixelSize(win->ghostwin));
U.pixelsize = wm_window_pixelsize(win);
- BKE_userdef_state();
+ BKE_blender_userdef_refresh();
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c
index 6078553426a..ea74c8074e5 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -148,6 +148,7 @@ struct wmWindowManager;
#include "../blender/collada/collada.h"
#include "../blender/compositor/COM_compositor.h"
#include "../blender/editors/include/ED_armature.h"
+#include "../blender/editors/include/ED_anim_api.h"
#include "../blender/editors/include/ED_buttons.h"
#include "../blender/editors/include/ED_clip.h"
#include "../blender/editors/include/ED_curve.h"
@@ -415,6 +416,7 @@ void delete_fcurve_key(struct FCurve *fcu, int index, bool do_recalc) RET_NONE
struct KeyingSetInfo *ANIM_keyingset_info_find_name (const char name[]) RET_NULL
struct KeyingSet *ANIM_scene_get_active_keyingset (struct Scene *scene) RET_NULL
int ANIM_scene_get_keyingset_index(struct Scene *scene, struct KeyingSet *ks) RET_ZERO
+void ANIM_id_update(struct Scene *scene, struct ID *id) RET_NONE
struct ListBase builtin_keyingsets;
void ANIM_keyingset_info_register(struct KeyingSetInfo *ksi) RET_NONE
void ANIM_keyingset_info_unregister(struct Main *bmain, KeyingSetInfo *ksi) RET_NONE
@@ -514,11 +516,18 @@ bool ED_texture_context_check_others(const struct bContext *C) RET_ZERO
bool ED_text_region_location_from_cursor(SpaceText *st, ARegion *ar, const int cursor_co[2], int r_pixel_co[2]) RET_ZERO
-bool snapObjectsRayEx(
- struct Scene *scene, struct View3D *v3d, struct ARegion *ar, struct Base *base_act, struct Object *obedit,
- const float mval[2], SnapSelect snap_select, short snap_mode,
- const float ray_start[3], const float ray_normal[3], float *ray_dist,
- float r_loc[3], float r_no[3], float *r_dist_px, int *r_index,
+SnapObjectContext *ED_transform_snap_object_context_create(
+ struct Main *bmain, struct Scene *scene, int flag) RET_NULL
+SnapObjectContext *ED_transform_snap_object_context_create_view3d(
+ struct Main *bmain, struct Scene *scene, int flag,
+ struct ARegion *ar, struct View3D *v3d) RET_NULL
+void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx) RET_NONE
+bool ED_transform_snap_object_project_ray_ex(
+ struct SnapObjectContext *sctx,
+ const struct SnapObjectParams *params,
+ const float ray_start[3], const float ray_normal[3], float *ray_depth,
+ /* return args */
+ float r_loc[3], float r_no[3], int *r_index,
struct Object **r_ob, float r_obmat[4][4]) RET_ZERO
void ED_lattice_editlatt_make(struct Object *obedit) RET_NONE
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index 273e5b33d0d..b7d8381639d 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -996,6 +996,15 @@ elseif(APPLE)
DESTINATION ${TARGETDIR_VER}/python
USE_SOURCE_PERMISSIONS
)
+
+ # Needed for distutils/pip
+ # get the last part of the include dir, will be 'python{version}{abiflag}',
+ get_filename_component(_py_inc_suffix ${PYTHON_INCLUDE_DIR} NAME)
+ install(
+ FILES ${PYTHON_INCLUDE_DIR}/pyconfig.h
+ DESTINATION ${TARGETDIR_VER}/python/include/${_py_inc_suffix}
+ )
+ unset(_py_inc_suffix)
endif()
# install blenderplayer bundle - copy of blender.app above. re-using macros et al
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 98e3a5c881c..d253cbad177 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -317,7 +317,7 @@ int main(
BLI_threadapi_init();
- initglobals(); /* blender.c */
+ BKE_blender_globals_init(); /* blender.c */
IMB_init();
BKE_images_init();
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index c2ded1f2b09..69765fc2341 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -44,7 +44,7 @@
#include "BLI_fileops.h"
#include "BLI_mempool.h"
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BKE_context.h"
#include "BKE_global.h"
diff --git a/source/creator/creator_signals.c b/source/creator/creator_signals.c
index b25d7c56f6e..80aba762cfc 100644
--- a/source/creator/creator_signals.c
+++ b/source/creator/creator_signals.c
@@ -59,7 +59,7 @@
#include BLI_SYSTEM_PID_H
#include "BKE_appdir.h" /* BKE_tempdir_base */
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_report.h"
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
index c2cfd8808a9..ec99de45918 100644
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
@@ -962,7 +962,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene,
if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1) {
bool generate_data = false;
if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) {
- DM_calc_loop_tangents(dm);
+ DM_calc_loop_tangents(dm, true, NULL, 0);
generate_data = true;
}
DM_generate_tangent_tessface_data(dm, generate_data);
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index eee53b775a9..a69a8eae55d 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -455,9 +455,9 @@ int main(int argc, char** argv)
init_nodesystem();
- initglobals();
+ BKE_blender_globals_init();
- // We load our own G.main, so free the one that initglobals() gives us
+ // We load our own G.main, so free the one that BKE_blender_globals_init() gives us
BKE_main_free(G.main);
G.main = NULL;
@@ -1132,7 +1132,7 @@ int main(int argc, char** argv)
}
}
- /* refer to WM_exit_ext() and free_blender(),
+ /* refer to WM_exit_ext() and BKE_blender_free(),
* these are not called in the player but we need to match some of there behavior here,
* if the order of function calls or blenders state isn't matching that of blender proper,
* we may get troubles later on */
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 76eb915a30d..9f173a567ee 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -134,7 +134,7 @@ extern "C" {
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_appdir.h"
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
#include "BLI_blenlib.h"
#include "GPU_material.h"
#include "MEM_guardedalloc.h"