From 55a3d48046377444a3c36ffe7a6164030d447f6f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 21 Apr 2017 17:26:27 +1000 Subject: [PATCH 01/10] Docs: diagram for reflect_v3_v3v3 --- source/blender/blenlib/intern/math_vector.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index dfecc3b556a..37897e2cd32 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -697,7 +697,19 @@ void bisect_v3_v3v3v3(float out[3], const float v1[3], const float v2[3], const /** * Returns a reflection vector from a vector and a normal vector - * reflect = vec - ((2 * DotVecs(vec, mirror)) * mirror) + * reflect = vec - ((2 * dot(vec, mirror)) * mirror). + * + *
+ * v
+ * +  ^
+ *  \ |
+ *   \|
+ *    + normal: axis of reflection
+ *   /
+ *  /
+ * +
+ * out: result (negate for a 'bounce').
+ * 
*/ void reflect_v3_v3v3(float out[3], const float v[3], const float normal[3]) { From c7a5c48cbad0062c55bf9fa6df2926646b2c3091 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 21 Apr 2017 10:58:01 +0200 Subject: [PATCH 02/10] CMake: Add option to link against system-wide Gflags library It is disabled by default, so should not affect existing configurations. Main benefits of this goes as: - Linux distros can use that to avoid libraries duplication and link blender package against gflags package from the system. - It it easier to test whether Blender works with updated version of Gflags prior to re-bundling the library. --- CMakeLists.txt | 28 +- build_files/cmake/Modules/FindGflags.cmake | 603 +++++++++++++++++++ build_files/cmake/Modules/GTestTesting.cmake | 4 +- build_files/cmake/macros.cmake | 8 +- extern/CMakeLists.txt | 4 +- intern/cycles/app/CMakeLists.txt | 2 +- intern/cycles/cmake/external_libs.cmake | 3 - intern/libmv/CMakeLists.txt | 3 +- intern/libmv/bundle.sh | 2 +- intern/libmv/intern/logging.cc | 22 +- source/blenderplayer/CMakeLists.txt | 5 +- tests/gtests/CMakeLists.txt | 1 + tests/gtests/testing/CMakeLists.txt | 2 +- tests/gtests/testing/testing_main.cc | 2 +- 14 files changed, 660 insertions(+), 29 deletions(-) create mode 100644 build_files/cmake/Modules/FindGflags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a91e1b655a..748ed649800 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -363,6 +363,10 @@ option(WITH_LIBMV "Enable Libmv structure from motion library" ON) option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." OFF) mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS) +# Logging/unbit test libraries. +option(WITH_SYSTEM_GFLAGS "Use system-wide Gflags instead of a bundled one" OFF) +mark_as_advanced(WITH_SYSTEM_GFLAGS) + # Freestyle option(WITH_FREESTYLE "Enable Freestyle (advanced edges rendering)" ON) @@ -1317,15 +1321,27 @@ endif() # Configure GLog/GFlags if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING)) + if(WITH_SYSTEM_GFLAGS) + find_package(Gflags) + if(NOT GFLAGS_FOUND) + message(FATAL_ERROR "System wide Gflags is requested but was not found") + endif() + # FindGflags does not define this, and we are not even sure what to use here. + set(GFLAGS_DEFINES) + else() + set(GFLAGS_DEFINES + -DGFLAGS_DLL_DEFINE_FLAG= + -DGFLAGS_DLL_DECLARE_FLAG= + -DGFLAGS_DLL_DECL= + ) + set(GFLAGS_NAMESPACE "gflags") + set(GFLAGS_LIBRARIES extern_gflags) + set(GFLAGS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/extern/gflags/src") + endif() + set(GLOG_DEFINES -DGOOGLE_GLOG_DLL_DECL= ) - - set(GFLAGS_DEFINES - -DGFLAGS_DLL_DEFINE_FLAG= - -DGFLAGS_DLL_DECLARE_FLAG= - -DGFLAGS_DLL_DECL= - ) endif() #----------------------------------------------------------------------------- diff --git a/build_files/cmake/Modules/FindGflags.cmake b/build_files/cmake/Modules/FindGflags.cmake new file mode 100644 index 00000000000..0a138c02465 --- /dev/null +++ b/build_files/cmake/Modules/FindGflags.cmake @@ -0,0 +1,603 @@ +# Ceres Solver - A fast non-linear least squares minimizer +# Copyright 2015 Google Inc. All rights reserved. +# http://ceres-solver.org/ +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of Google Inc. nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# Author: alexs.mac@gmail.com (Alex Stewart) +# + +# FindGflags.cmake - Find Google gflags logging library. +# +# This module will attempt to find gflags, either via an exported CMake +# configuration (generated by gflags >= 2.1 which are built with CMake), or +# by performing a standard search for all gflags components. The order of +# precedence for these two methods of finding gflags is controlled by: +# GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION. +# +# This module defines the following variables: +# +# GFLAGS_FOUND: TRUE iff gflags is found. +# GFLAGS_INCLUDE_DIRS: Include directories for gflags. +# GFLAGS_LIBRARIES: Libraries required to link gflags. +# GFLAGS_NAMESPACE: The namespace in which gflags is defined. In versions of +# gflags < 2.1, this was google, for versions >= 2.1 it is +# by default gflags, although can be configured when building +# gflags to be something else (i.e. google for legacy +# compatibility). +# +# The following variables control the behaviour of this module when an exported +# gflags CMake configuration is not found. +# +# GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION: TRUE/FALSE, iff TRUE then +# then prefer using an exported CMake configuration +# generated by gflags >= 2.1 over searching for the +# gflags components manually. Otherwise (FALSE) +# ignore any exported gflags CMake configurations and +# always perform a manual search for the components. +# Default: TRUE iff user does not define this variable +# before we are called, and does NOT specify either +# GFLAGS_INCLUDE_DIR_HINTS or GFLAGS_LIBRARY_DIR_HINTS +# otherwise FALSE. +# GFLAGS_INCLUDE_DIR_HINTS: List of additional directories in which to +# search for gflags includes, e.g: /timbuktu/include. +# GFLAGS_LIBRARY_DIR_HINTS: List of additional directories in which to +# search for gflags libraries, e.g: /timbuktu/lib. +# GFLAGS_ROOT_DIR, The base directory to search for Gflags. +# This can also be an environment variable. +# +# The following variables are also defined by this module, but in line with +# CMake recommended FindPackage() module style should NOT be referenced directly +# by callers (use the plural variables detailed above instead). These variables +# do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which +# are NOT re-called (i.e. search for library is not repeated) if these variables +# are set with valid values _in the CMake cache_. This means that if these +# variables are set directly in the cache, either by the user in the CMake GUI, +# or by the user passing -DVAR=VALUE directives to CMake when called (which +# explicitly defines a cache variable), then they will be used verbatim, +# bypassing the HINTS variables and other hard-coded search locations. +# +# GFLAGS_INCLUDE_DIR: Include directory for gflags, not including the +# include directory of any dependencies. +# GFLAGS_LIBRARY: gflags library, not including the libraries of any +# dependencies. + +# If GFLAGS_ROOT_DIR was defined in the environment, use it. +if(NOT GFLAGS_ROOT_DIR AND NOT $ENV{GFLAGS_ROOT_DIR} STREQUAL "") + set(GFLAGS_ROOT_DIR $ENV{GFLAGS_ROOT_DIR}) +endif() + +if(DEFINED GFLAGS_ROOT_DIR) + set(GFLAGS_ROOT_DIR_INCLUDE "${GFLAGS_ROOT_DIR}/include") + set(GFLAGS_ROOT_DIR_LIB "${GFLAGS_ROOT_DIR}/lib") +endif() + +# Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when FindGflags was +# invoked, necessary for MSVC. +macro(GFLAGS_RESET_FIND_LIBRARY_PREFIX) + if(MSVC) + set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}") + endif() +endmacro() + +# Called if we failed to find gflags or any of it's required dependencies, +# unsets all public (designed to be used externally) variables and reports +# error message at priority depending upon [REQUIRED/QUIET/] argument. +macro(GFLAGS_REPORT_NOT_FOUND REASON_MSG) + unset(GFLAGS_FOUND) + unset(GFLAGS_INCLUDE_DIRS) + unset(GFLAGS_LIBRARIES) + # Do not use unset, as we want to keep GFLAGS_NAMESPACE in the cache, + # but simply clear its value. + set(GFLAGS_NAMESPACE "" CACHE STRING + "gflags namespace (google or gflags)" FORCE) + + # Make results of search visible in the CMake GUI if gflags has not + # been found so that user does not have to toggle to advanced view. + mark_as_advanced(CLEAR GFLAGS_INCLUDE_DIR + GFLAGS_LIBRARY + GFLAGS_NAMESPACE) + + gflags_reset_find_library_prefix() + + # Note _FIND_[REQUIRED/QUIETLY] variables defined by FindPackage() + # use the camelcase library name, not uppercase. + if(Gflags_FIND_QUIETLY) + message(STATUS "Failed to find gflags - " ${REASON_MSG} ${ARGN}) + elseif(Gflags_FIND_REQUIRED) + message(FATAL_ERROR "Failed to find gflags - " ${REASON_MSG} ${ARGN}) + else() + # Neither QUIETLY nor REQUIRED, use no priority which emits a message + # but continues configuration and allows generation. + message("-- Failed to find gflags - " ${REASON_MSG} ${ARGN}) + endif() + return() +endmacro() + +# Verify that all variable names passed as arguments are defined (can be empty +# but must be defined) or raise a fatal error. +macro(GFLAGS_CHECK_VARS_DEFINED) + foreach(CHECK_VAR ${ARGN}) + if(NOT DEFINED ${CHECK_VAR}) + message(FATAL_ERROR "Ceres Bug: ${CHECK_VAR} is not defined.") + endif() + endforeach() +endmacro() + +# Use check_cxx_source_compiles() to compile trivial test programs to determine +# the gflags namespace. This works on all OSs except Windows. If using Visual +# Studio, it fails because msbuild forces check_cxx_source_compiles() to use +# CMAKE_BUILD_TYPE=Debug for the test project, which usually breaks detection +# because MSVC requires that the test project use the same build type as gflags, +# which would normally be built in Release. +# +# Defines: GFLAGS_NAMESPACE in the caller's scope with the detected namespace, +# which is blank (empty string, will test FALSE is CMake conditionals) +# if detection failed. +function(GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_TRY_COMPILE) + # Verify that all required variables are defined. + gflags_check_vars_defined( + GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY) + # Ensure that GFLAGS_NAMESPACE is always unset on completion unless + # we explicitly set if after having the correct namespace. + set(GFLAGS_NAMESPACE "" PARENT_SCOPE) + + include(CheckCXXSourceCompiles) + # Setup include path & link library for gflags for CHECK_CXX_SOURCE_COMPILES. + set(CMAKE_REQUIRED_INCLUDES ${GFLAGS_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES}) + # First try the (older) google namespace. Note that the output variable + # MUST be unique to the build type as otherwise the test is not repeated as + # it is assumed to have already been performed. + check_cxx_source_compiles( + "#include + int main(int argc, char * argv[]) { + google::ParseCommandLineFlags(&argc, &argv, true); + return 0; + }" + GFLAGS_IN_GOOGLE_NAMESPACE) + if(GFLAGS_IN_GOOGLE_NAMESPACE) + set(GFLAGS_NAMESPACE google PARENT_SCOPE) + return() + endif() + + # Try (newer) gflags namespace instead. Note that the output variable + # MUST be unique to the build type as otherwise the test is not repeated as + # it is assumed to have already been performed. + set(CMAKE_REQUIRED_INCLUDES ${GFLAGS_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES}) + check_cxx_source_compiles( + "#include + int main(int argc, char * argv[]) { + gflags::ParseCommandLineFlags(&argc, &argv, true); + return 0; + }" + GFLAGS_IN_GFLAGS_NAMESPACE) + if(GFLAGS_IN_GFLAGS_NAMESPACE) + set(GFLAGS_NAMESPACE gflags PARENT_SCOPE) + return() + endif() +endfunction() + +# Use regex on the gflags headers to attempt to determine the gflags namespace. +# Checks both gflags.h (contained namespace on versions < 2.1.2) and +# gflags_declare.h, which contains the namespace on versions >= 2.1.2. +# In general, this method should only be used when +# GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_TRY_COMPILE() cannot be used, or has +# failed. +# +# Defines: GFLAGS_NAMESPACE in the caller's scope with the detected namespace, +# which is blank (empty string, will test FALSE is CMake conditionals) +# if detection failed. +function(GFLAGS_CHECK_GFLAGS_NAMESPACE_USING_REGEX) + # Verify that all required variables are defined. + gflags_check_vars_defined(GFLAGS_INCLUDE_DIR) + # Ensure that GFLAGS_NAMESPACE is always undefined on completion unless + # we explicitly set if after having the correct namespace. + set(GFLAGS_NAMESPACE "" PARENT_SCOPE) + + # Scan gflags.h to identify what namespace gflags was built with. On + # versions of gflags < 2.1.2, gflags.h was configured with the namespace + # directly, on >= 2.1.2, gflags.h uses the GFLAGS_NAMESPACE #define which + # is defined in gflags_declare.h, we try each location in turn. + set(GFLAGS_HEADER_FILE ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h) + if(NOT EXISTS ${GFLAGS_HEADER_FILE}) + gflags_report_not_found( + "Could not find file: ${GFLAGS_HEADER_FILE} " + "containing namespace information in gflags install located at: " + "${GFLAGS_INCLUDE_DIR}.") + endif() + file(READ ${GFLAGS_HEADER_FILE} GFLAGS_HEADER_FILE_CONTENTS) + + string(REGEX MATCH "namespace [A-Za-z]+" + GFLAGS_NAMESPACE "${GFLAGS_HEADER_FILE_CONTENTS}") + string(REGEX REPLACE "namespace ([A-Za-z]+)" "\\1" + GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}") + + if(NOT GFLAGS_NAMESPACE) + gflags_report_not_found( + "Failed to extract gflags namespace from header file: " + "${GFLAGS_HEADER_FILE}.") + endif() + + if(GFLAGS_NAMESPACE STREQUAL "google" OR + GFLAGS_NAMESPACE STREQUAL "gflags") + # Found valid gflags namespace from gflags.h. + set(GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}" PARENT_SCOPE) + return() + endif() + + # Failed to find gflags namespace from gflags.h, gflags is likely a new + # version, check gflags_declare.h, which in newer versions (>= 2.1.2) contains + # the GFLAGS_NAMESPACE #define, which is then referenced in gflags.h. + set(GFLAGS_DECLARE_FILE ${GFLAGS_INCLUDE_DIR}/gflags/gflags_declare.h) + if(NOT EXISTS ${GFLAGS_DECLARE_FILE}) + gflags_report_not_found( + "Could not find file: ${GFLAGS_DECLARE_FILE} " + "containing namespace information in gflags install located at: " + "${GFLAGS_INCLUDE_DIR}.") + endif() + file(READ ${GFLAGS_DECLARE_FILE} GFLAGS_DECLARE_FILE_CONTENTS) + + string(REGEX MATCH "#define GFLAGS_NAMESPACE [A-Za-z]+" + GFLAGS_NAMESPACE "${GFLAGS_DECLARE_FILE_CONTENTS}") + string(REGEX REPLACE "#define GFLAGS_NAMESPACE ([A-Za-z]+)" "\\1" + GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}") + + if(NOT GFLAGS_NAMESPACE) + gflags_report_not_found( + "Failed to extract gflags namespace from declare file: " + "${GFLAGS_DECLARE_FILE}.") + endif() + + if(GFLAGS_NAMESPACE STREQUAL "google" OR + GFLAGS_NAMESPACE STREQUAL "gflags") + # Found valid gflags namespace from gflags.h. + set(GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}" PARENT_SCOPE) + return() + endif() +endfunction() + +# ----------------------------------------------------------------- +# By default, if the user has expressed no preference for using an exported +# gflags CMake configuration over performing a search for the installed +# components, and has not specified any hints for the search locations, then +# prefer a gflags exported configuration if available. +if(NOT DEFINED GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION + AND NOT GFLAGS_INCLUDE_DIR_HINTS + AND NOT GFLAGS_LIBRARY_DIR_HINTS) + message(STATUS "No preference for use of exported gflags CMake configuration " + "set, and no hints for include/library directories provided. " + "Defaulting to preferring an installed/exported gflags CMake configuration " + "if available.") + set(GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION TRUE) +endif() + +if(GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION) + # Try to find an exported CMake configuration for gflags, as generated by + # gflags versions >= 2.1. + # + # We search twice, s/t we can invert the ordering of precedence used by + # find_package() for exported package build directories, and installed + # packages (found via CMAKE_SYSTEM_PREFIX_PATH), listed as items 6) and 7) + # respectively in [1]. + # + # By default, exported build directories are (in theory) detected first, and + # this is usually the case on Windows. However, on OS X & Linux, the install + # path (/usr/local) is typically present in the PATH environment variable + # which is checked in item 4) in [1] (i.e. before both of the above, unless + # NO_SYSTEM_ENVIRONMENT_PATH is passed). As such on those OSs installed + # packages are usually detected in preference to exported package build + # directories. + # + # To ensure a more consistent response across all OSs, and as users usually + # want to prefer an installed version of a package over a locally built one + # where both exist (esp. as the exported build directory might be removed + # after installation), we first search with NO_CMAKE_PACKAGE_REGISTRY which + # means any build directories exported by the user are ignored, and thus + # installed directories are preferred. If this fails to find the package + # we then research again, but without NO_CMAKE_PACKAGE_REGISTRY, so any + # exported build directories will now be detected. + # + # To prevent confusion on Windows, we also pass NO_CMAKE_BUILDS_PATH (which + # is item 5) in [1]), to not preferentially use projects that were built + # recently with the CMake GUI to ensure that we always prefer an installed + # version if available. + # + # [1] http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_package + find_package(gflags QUIET + NO_MODULE + NO_CMAKE_PACKAGE_REGISTRY + NO_CMAKE_BUILDS_PATH) + if(gflags_FOUND) + message(STATUS "Found installed version of gflags: ${gflags_DIR}") + else() + # Failed to find an installed version of gflags, repeat search allowing + # exported build directories. + message(STATUS "Failed to find installed gflags CMake configuration, " + "searching for gflags build directories exported with CMake.") + # Again pass NO_CMAKE_BUILDS_PATH, as we know that gflags is exported and + # do not want to treat projects built with the CMake GUI preferentially. + find_package(gflags QUIET + NO_MODULE + NO_CMAKE_BUILDS_PATH) + if(gflags_FOUND) + message(STATUS "Found exported gflags build directory: ${gflags_DIR}") + endif() + endif() + + set(FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION ${gflags_FOUND}) + + # gflags v2.1 - 2.1.2 shipped with a bug in their gflags-config.cmake [1] + # whereby gflags_LIBRARIES = "gflags", but there was no imported target + # called "gflags", they were called: gflags[_nothreads]-[static/shared]. + # As this causes linker errors when gflags is not installed in a location + # on the current library paths, detect if this problem is present and + # fix it. + # + # [1] https://github.com/gflags/gflags/issues/110 + if(gflags_FOUND) + # NOTE: This is not written as additional conditions in the outer + # if(gflags_FOUND) as the NOT TARGET "${gflags_LIBRARIES}" + # condition causes problems if gflags is not found. + if(${gflags_VERSION} VERSION_LESS 2.1.3 AND + NOT TARGET "${gflags_LIBRARIES}") + message(STATUS "Detected broken gflags install in: ${gflags_DIR}, " + "version: ${gflags_VERSION} <= 2.1.2 which defines gflags_LIBRARIES = " + "${gflags_LIBRARIES} which is not an imported CMake target, see: " + "https://github.com/gflags/gflags/issues/110. Attempting to fix by " + "detecting correct gflags target.") + # Ordering here expresses preference for detection, specifically we do not + # want to use the _nothreads variants if the full library is available. + list(APPEND CHECK_GFLAGS_IMPORTED_TARGET_NAMES + gflags-shared gflags-static + gflags_nothreads-shared gflags_nothreads-static) + foreach(CHECK_GFLAGS_TARGET ${CHECK_GFLAGS_IMPORTED_TARGET_NAMES}) + if(TARGET ${CHECK_GFLAGS_TARGET}) + message(STATUS "Found valid gflags target: ${CHECK_GFLAGS_TARGET}, " + "updating gflags_LIBRARIES.") + set(gflags_LIBRARIES ${CHECK_GFLAGS_TARGET}) + break() + endif() + endforeach() + if(NOT TARGET ${gflags_LIBRARIES}) + message(STATUS "Failed to fix detected broken gflags install in: " + "${gflags_DIR}, version: ${gflags_VERSION} <= 2.1.2, none of the " + "imported targets for gflags: ${CHECK_GFLAGS_IMPORTED_TARGET_NAMES} " + "are defined. Will continue with a manual search for gflags " + "components. We recommend you build/install a version of gflags > " + "2.1.2 (or master).") + set(FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION FALSE) + endif() + endif() + endif() + + if(FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION) + message(STATUS "Detected gflags version: ${gflags_VERSION}") + set(GFLAGS_FOUND ${gflags_FOUND}) + set(GFLAGS_INCLUDE_DIR ${gflags_INCLUDE_DIR}) + set(GFLAGS_LIBRARY ${gflags_LIBRARIES}) + + # gflags does not export the namespace in their CMake configuration, so + # use our function to determine what it should be, as it can be either + # gflags or google dependent upon version & configuration. + # + # NOTE: We use the regex method to determine the namespace here, as + # check_cxx_source_compiles() will not use imported targets, which + # is what gflags will be in this case. + gflags_check_gflags_namespace_using_regex() + + if(NOT GFLAGS_NAMESPACE) + gflags_report_not_found( + "Failed to determine gflags namespace using regex for gflags " + "version: ${gflags_VERSION} exported here: ${gflags_DIR} using CMake.") + endif() + else() + message(STATUS "Failed to find an installed/exported CMake configuration " + "for gflags, will perform search for installed gflags components.") + endif() +endif() + +if(NOT GFLAGS_FOUND) + # Either failed to find an exported gflags CMake configuration, or user + # told us not to use one. Perform a manual search for all gflags components. + + # Handle possible presence of lib prefix for libraries on MSVC, see + # also GFLAGS_RESET_FIND_LIBRARY_PREFIX(). + if(MSVC) + # Preserve the caller's original values for CMAKE_FIND_LIBRARY_PREFIXES + # s/t we can set it back before returning. + set(CALLERS_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") + # The empty string in this list is important, it represents the case when + # the libraries have no prefix (shared libraries / DLLs). + set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}") + endif() + + # Search user-installed locations first, so that we prefer user installs + # to system installs where both exist. + list(APPEND GFLAGS_CHECK_INCLUDE_DIRS + ${GFLAGS_ROOT_DIR_INCLUDE} + /usr/local/include + /usr/local/homebrew/include # Mac OS X + /opt/local/var/macports/software # Mac OS X. + /opt/local/include + /usr/include + /sw/include # Fink + /opt/csw/include # Blastwave + /opt/lib/gflags/include) + + list(APPEND GFLAGS_CHECK_PATH_SUFFIXES + gflags/include # Windows (for C:/Program Files prefix). + gflags/Include) # Windows (for C:/Program Files prefix). + + list(APPEND GFLAGS_CHECK_LIBRARY_DIRS + ${GFLAGS_ROOT_DIR_LIB} + /usr/local/lib + /usr/local/homebrew/lib # Mac OS X. + /opt/local/lib + /usr/lib + /sw/lib # Fink + /opt/csw/lib # Blastwave + /opt/lib/gflags/lib) + list(APPEND GFLAGS_CHECK_LIBRARY_SUFFIXES + gflags/lib # Windows (for C:/Program Files prefix). + gflags/Lib) # Windows (for C:/Program Files prefix). + + # Search supplied hint directories first if supplied. + find_path(GFLAGS_INCLUDE_DIR + NAMES gflags/gflags.h + PATHS ${GFLAGS_INCLUDE_DIR_HINTS} + ${GFLAGS_CHECK_INCLUDE_DIRS} + PATH_SUFFIXES ${GFLAGS_CHECK_PATH_SUFFIXES}) + if(NOT GFLAGS_INCLUDE_DIR OR + NOT EXISTS ${GFLAGS_INCLUDE_DIR}) + gflags_report_not_found( + "Could not find gflags include directory, set GFLAGS_INCLUDE_DIR " + "to directory containing gflags/gflags.h") + endif(NOT GFLAGS_INCLUDE_DIR OR + NOT EXISTS ${GFLAGS_INCLUDE_DIR}) + + find_library(GFLAGS_LIBRARY NAMES gflags + PATHS ${GFLAGS_LIBRARY_DIR_HINTS} + ${GFLAGS_CHECK_LIBRARY_DIRS} + PATH_SUFFIXES ${GFLAGS_CHECK_LIBRARY_SUFFIXES}) + if(NOT GFLAGS_LIBRARY OR + NOT EXISTS ${GFLAGS_LIBRARY}) + gflags_report_not_found( + "Could not find gflags library, set GFLAGS_LIBRARY " + "to full path to libgflags.") + endif(NOT GFLAGS_LIBRARY OR + NOT EXISTS ${GFLAGS_LIBRARY}) + + # gflags typically requires a threading library (which is OS dependent), note + # that this defines the CMAKE_THREAD_LIBS_INIT variable. If we are able to + # detect threads, we assume that gflags requires it. + find_package(Threads QUIET) + set(GFLAGS_LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + # On Windows (including MinGW), the Shlwapi library is used by gflags if + # available. + if(WIN32) + include(CheckIncludeFileCXX) + check_include_file_cxx("shlwapi.h" HAVE_SHLWAPI) + if(HAVE_SHLWAPI) + list(APPEND GFLAGS_LINK_LIBRARIES shlwapi.lib) + endif() + endif() + + # Mark internally as found, then verify. GFLAGS_REPORT_NOT_FOUND() unsets + # if called. + set(GFLAGS_FOUND TRUE) + + # Identify what namespace gflags was built with. + if(GFLAGS_INCLUDE_DIR AND NOT GFLAGS_NAMESPACE) + # To handle Windows peculiarities / CMake bugs on MSVC we try two approaches + # to detect the gflags namespace: + # + # 1) Try to use check_cxx_source_compiles() to compile a trivial program + # with the two choices for the gflags namespace. + # + # 2) [In the event 1) fails] Use regex on the gflags headers to try to + # determine the gflags namespace. Whilst this is less robust than 1), + # it does avoid any interaction with msbuild. + gflags_check_gflags_namespace_using_try_compile() + + if(NOT GFLAGS_NAMESPACE) + # Failed to determine gflags namespace using check_cxx_source_compiles() + # method, try and obtain it using regex on the gflags headers instead. + message(STATUS "Failed to find gflags namespace using using " + "check_cxx_source_compiles(), trying namespace regex instead, " + "this is expected on Windows.") + gflags_check_gflags_namespace_using_regex() + + if(NOT GFLAGS_NAMESPACE) + gflags_report_not_found( + "Failed to determine gflags namespace either by " + "check_cxx_source_compiles(), or namespace regex.") + endif() + endif() + endif() + + # Make the GFLAGS_NAMESPACE a cache variable s/t the user can view it, and could + # overwrite it in the CMake GUI. + set(GFLAGS_NAMESPACE "${GFLAGS_NAMESPACE}" CACHE STRING + "gflags namespace (google or gflags)" FORCE) + + # gflags does not seem to provide any record of the version in its + # source tree, thus cannot extract version. + + # Catch case when caller has set GFLAGS_NAMESPACE in the cache / GUI + # with an invalid value. + if(GFLAGS_NAMESPACE AND + NOT GFLAGS_NAMESPACE STREQUAL "google" AND + NOT GFLAGS_NAMESPACE STREQUAL "gflags") + gflags_report_not_found( + "Caller defined GFLAGS_NAMESPACE:" + " ${GFLAGS_NAMESPACE} is not valid, not google or gflags.") + endif() + # Catch case when caller has set GFLAGS_INCLUDE_DIR in the cache / GUI and + # thus FIND_[PATH/LIBRARY] are not called, but specified locations are + # invalid, otherwise we would report the library as found. + if(GFLAGS_INCLUDE_DIR AND + NOT EXISTS ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h) + gflags_report_not_found( + "Caller defined GFLAGS_INCLUDE_DIR:" + " ${GFLAGS_INCLUDE_DIR} does not contain gflags/gflags.h header.") + endif(GFLAGS_INCLUDE_DIR AND + NOT EXISTS ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h) + # TODO: This regex for gflags library is pretty primitive, we use lowercase + # for comparison to handle Windows using CamelCase library names, could + # this check be better? + string(TOLOWER "${GFLAGS_LIBRARY}" LOWERCASE_GFLAGS_LIBRARY) + if(GFLAGS_LIBRARY AND + NOT "${LOWERCASE_GFLAGS_LIBRARY}" MATCHES ".*gflags[^/]*") + gflags_report_not_found( + "Caller defined GFLAGS_LIBRARY: " + "${GFLAGS_LIBRARY} does not match gflags.") + endif(GFLAGS_LIBRARY AND + NOT "${LOWERCASE_GFLAGS_LIBRARY}" MATCHES ".*gflags[^/]*") + + gflags_reset_find_library_prefix() + +endif() + +# Set standard CMake FindPackage variables if found. +if(GFLAGS_FOUND) + set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR}) + set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES}) +endif() + +# Handle REQUIRED / QUIET optional arguments. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GFLAGS DEFAULT_MSG + GFLAGS_INCLUDE_DIRS GFLAGS_LIBRARIES GFLAGS_NAMESPACE) + +# Only mark internal variables as advanced if we found gflags, otherwise +# leave them visible in the standard GUI for the user to set manually. +if(GFLAGS_FOUND) + mark_as_advanced(FORCE GFLAGS_INCLUDE_DIR + GFLAGS_LIBRARY + GFLAGS_NAMESPACE + gflags_DIR) # Autogenerated by find_package(gflags) +endif() diff --git a/build_files/cmake/Modules/GTestTesting.cmake b/build_files/cmake/Modules/GTestTesting.cmake index e688db35ef1..9fd082ee402 100644 --- a/build_files/cmake/Modules/GTestTesting.cmake +++ b/build_files/cmake/Modules/GTestTesting.cmake @@ -21,7 +21,7 @@ macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST) ${_current_include_directories} ${CMAKE_SOURCE_DIR}/tests/gtests ${CMAKE_SOURCE_DIR}/extern/glog/src - ${CMAKE_SOURCE_DIR}/extern/gflags/src + ${GFLAGS_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/extern/gtest/include ${CMAKE_SOURCE_DIR}/extern/gmock/include ) @@ -38,7 +38,7 @@ macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST) # needed for glog ${PTHREADS_LIBRARIES} extern_glog - extern_gflags) + ${GFLAGS_LIBRARIES}) if(WITH_OPENMP_STATIC) target_link_libraries(${NAME}_test ${OpenMP_LIBRARIES}) endif() diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index b7f6649e507..0221ac55e42 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -491,6 +491,9 @@ function(setup_liblinks target_link_libraries(${target} ${NDOF_LIBRARIES}) endif() endif() + if(WITH_SYSTEM_GFLAGS) + target_link_libraries(${target} ${GFLAGS_LIBRARIES}) + endif() # We put CLEW and CUEW here because OPENSUBDIV_LIBRARIES dpeends on them.. if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV) @@ -659,12 +662,15 @@ function(SETUP_BLENDER_SORTED_LIBS) extern_wcwidth bf_intern_libmv extern_glog - extern_gflags extern_sdlew bf_intern_glew_mx ) + if(NOT WITH_SYSTEM_GFLAGS) + list(APPEND BLENDER_SORTED_LIBS extern_gflags) + endif() + if(WITH_COMPOSITOR) # added for opencl compositor list_insert_before(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_compositor") diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 45aa4a9d94d..f7e98525b8b 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -99,7 +99,9 @@ if(WITH_LIBMV) endif() if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING)) - add_subdirectory(gflags) + if (NOT WITH_SYSTEM_GFLAGS) + add_subdirectory(gflags) + endif() add_subdirectory(glog) endif() diff --git a/intern/cycles/app/CMakeLists.txt b/intern/cycles/app/CMakeLists.txt index aabb8f63640..231ef58f7ae 100644 --- a/intern/cycles/app/CMakeLists.txt +++ b/intern/cycles/app/CMakeLists.txt @@ -45,7 +45,7 @@ if(CYCLES_STANDALONE_REPOSITORY) else() list(APPEND LIBRARIES bf_intern_glew_mx bf_intern_guardedalloc) if(WITH_CYCLES_LOGGING) - list(APPEND LIBRARIES extern_glog extern_gflags) + list(APPEND LIBRARIES extern_glog ${GFLAGS_LIBRARIES}) endif() endif() diff --git a/intern/cycles/cmake/external_libs.cmake b/intern/cycles/cmake/external_libs.cmake index 403a0540963..68e7f0a6eac 100644 --- a/intern/cycles/cmake/external_libs.cmake +++ b/intern/cycles/cmake/external_libs.cmake @@ -137,11 +137,8 @@ if(CYCLES_STANDALONE_REPOSITORY) else() if(WIN32) set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src/windows) - set(GFLAGS_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/gflags/src) else() set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src) - set(GFLAGS_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/gflags/src) endif() - set(GFLAGS_NAMESPACE "gflags") set(LLVM_LIBRARIES ${LLVM_LIBRARY}) endif() diff --git a/intern/libmv/CMakeLists.txt b/intern/libmv/CMakeLists.txt index cd89f1d84b5..b67a23b4159 100644 --- a/intern/libmv/CMakeLists.txt +++ b/intern/libmv/CMakeLists.txt @@ -41,9 +41,10 @@ if(WITH_LIBMV) add_definitions(${GFLAGS_DEFINES}) add_definitions(${GLOG_DEFINES}) add_definitions(${CERES_DEFINES}) + add_definitions(-DLIBMV_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) list(APPEND INC - ../../extern/gflags/src + ${GFLAGS_INCLUDE_DIRS} ../../extern/glog/src ../../extern/ceres/include ../../extern/ceres/config diff --git a/intern/libmv/bundle.sh b/intern/libmv/bundle.sh index b1a4be84e53..27e012f665f 100755 --- a/intern/libmv/bundle.sh +++ b/intern/libmv/bundle.sh @@ -122,7 +122,7 @@ if(WITH_LIBMV) add_definitions(\${CERES_DEFINES}) list(APPEND INC - ../../extern/gflags/src + \${GFLAGS_INCLUDE_DIRS} ../../extern/glog/src ../../extern/ceres/include ../../extern/ceres/config diff --git a/intern/libmv/intern/logging.cc b/intern/libmv/intern/logging.cc index 77b56ef4df3..9b8adf09a97 100644 --- a/intern/libmv/intern/logging.cc +++ b/intern/libmv/intern/logging.cc @@ -29,27 +29,29 @@ #include "libmv/logging/logging.h" void libmv_initLogging(const char* argv0) { + using LIBMV_GFLAGS_NAMESPACE::SetCommandLineOption; // Make it so FATAL messages are always print into console. char severity_fatal[32]; snprintf(severity_fatal, sizeof(severity_fatal), "%d", google::GLOG_FATAL); - google::InitGoogleLogging(argv0); - gflags::SetCommandLineOption("logtostderr", "1"); - gflags::SetCommandLineOption("v", "0"); - gflags::SetCommandLineOption("stderrthreshold", severity_fatal); - gflags::SetCommandLineOption("minloglevel", severity_fatal); + SetCommandLineOption("logtostderr", "1"); + SetCommandLineOption("v", "0"); + SetCommandLineOption("stderrthreshold", severity_fatal); + SetCommandLineOption("minloglevel", severity_fatal); } void libmv_startDebugLogging(void) { - gflags::SetCommandLineOption("logtostderr", "1"); - gflags::SetCommandLineOption("v", "2"); - gflags::SetCommandLineOption("stderrthreshold", "1"); - gflags::SetCommandLineOption("minloglevel", "0"); + using LIBMV_GFLAGS_NAMESPACE::SetCommandLineOption; + SetCommandLineOption("logtostderr", "1"); + SetCommandLineOption("v", "2"); + SetCommandLineOption("stderrthreshold", "1"); + SetCommandLineOption("minloglevel", "0"); } void libmv_setLoggingVerbosity(int verbosity) { + using LIBMV_GFLAGS_NAMESPACE::SetCommandLineOption; char val[10]; snprintf(val, sizeof(val), "%d", verbosity); - gflags::SetCommandLineOption("v", val); + SetCommandLineOption("v", val); } diff --git a/source/blenderplayer/CMakeLists.txt b/source/blenderplayer/CMakeLists.txt index 58bebc66a3e..e0afd84db82 100644 --- a/source/blenderplayer/CMakeLists.txt +++ b/source/blenderplayer/CMakeLists.txt @@ -177,10 +177,13 @@ endif() extern_wcwidth bf_intern_libmv extern_glog - extern_gflags extern_sdlew ) + if(NOT WITH_SYSTEM_GFLAGS) + list(APPEND BLENDER_SORTED_LIBS extern_gflags) + endif() + if(WITH_MOD_CLOTH_ELTOPO) list(APPEND BLENDER_SORTED_LIBS extern_eltopo) endif() diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt index ad77b1389f6..781da7bf452 100644 --- a/tests/gtests/CMakeLists.txt +++ b/tests/gtests/CMakeLists.txt @@ -6,6 +6,7 @@ if(WITH_GTESTS) add_definitions(${GFLAGS_DEFINES}) add_definitions(${GLOG_DEFINES}) + add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) # Otherwise we get warnings here that we cant fix in external projects remove_strict_flags() diff --git a/tests/gtests/testing/CMakeLists.txt b/tests/gtests/testing/CMakeLists.txt index 796f975ea65..defa51df664 100644 --- a/tests/gtests/testing/CMakeLists.txt +++ b/tests/gtests/testing/CMakeLists.txt @@ -24,7 +24,7 @@ set(INC . .. - ../../../extern/gflags/src + ${GFLAGS_INCLUDE_DIRS} ../../../extern/gtest/include ) diff --git a/tests/gtests/testing/testing_main.cc b/tests/gtests/testing/testing_main.cc index b2dcc445aca..e8104a2a026 100644 --- a/tests/gtests/testing/testing_main.cc +++ b/tests/gtests/testing/testing_main.cc @@ -28,7 +28,7 @@ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); - gflags::ParseCommandLineFlags(&argc, &argv, true); + BLENDER_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); return RUN_ALL_TESTS(); From 7a59d381cea8ed2ba11b8e14dad44e3e91390b07 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 21 Apr 2017 11:33:44 +0200 Subject: [PATCH 03/10] Cycles: Cleanup, indentation of comment Was broken after principled commit. --- intern/cycles/kernel/kernel_subsurface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/intern/cycles/kernel/kernel_subsurface.h b/intern/cycles/kernel/kernel_subsurface.h index 6c8b7cca4ce..17b3cf033a1 100644 --- a/intern/cycles/kernel/kernel_subsurface.h +++ b/intern/cycles/kernel/kernel_subsurface.h @@ -158,7 +158,7 @@ ccl_device void subsurface_scatter_setup_diffuse_bsdf(ShaderData *sd, ShaderClos sd->flag |= bsdf_principled_diffuse_setup(bsdf); /* replace CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID with this special ID so render passes - * can recognize it as not being a regular Disney principled diffuse closure */ + * can recognize it as not being a regular Disney principled diffuse closure */ bsdf->type = CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID; } } @@ -170,7 +170,7 @@ ccl_device void subsurface_scatter_setup_diffuse_bsdf(ShaderData *sd, ShaderClos sd->flag |= bsdf_diffuse_setup(bsdf); /* replace CLOSURE_BSDF_DIFFUSE_ID with this special ID so render passes - * can recognize it as not being a regular diffuse closure */ + * can recognize it as not being a regular diffuse closure */ bsdf->type = CLOSURE_BSDF_BSSRDF_ID; } } From aa2cff450914c945b6038b6413c2c0d951b0b0ea Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 21 Apr 2017 11:50:35 +0200 Subject: [PATCH 04/10] Cycles: Fix regression in SSS rendering after principled commit --- intern/cycles/kernel/kernel_subsurface.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/intern/cycles/kernel/kernel_subsurface.h b/intern/cycles/kernel/kernel_subsurface.h index 17b3cf033a1..fb4a054dcd0 100644 --- a/intern/cycles/kernel/kernel_subsurface.h +++ b/intern/cycles/kernel/kernel_subsurface.h @@ -162,7 +162,9 @@ ccl_device void subsurface_scatter_setup_diffuse_bsdf(ShaderData *sd, ShaderClos bsdf->type = CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID; } } - else if(CLOSURE_IS_BSSRDF(bssrdf->type)) { + else if(CLOSURE_IS_BSDF_BSSRDF(bssrdf->type) || + CLOSURE_IS_BSSRDF(bssrdf->type)) + { DiffuseBsdf *bsdf = (DiffuseBsdf*)bsdf_alloc(sd, sizeof(DiffuseBsdf), weight); if(bsdf) { From 470b54a37a8f509c18a2e7f5f46c7dd59c3509b8 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 21 Apr 2017 12:01:04 +0200 Subject: [PATCH 05/10] Cycles: Cleanup, indentation inside preprocessor --- intern/cycles/kernel/svm/svm_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 4a8cdb60952..cc9b840b13f 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -471,7 +471,7 @@ typedef enum ClosureType { #define CLOSURE_IS_BSDF_ANISOTROPIC(type) (type >= CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID && type <= CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID) #define CLOSURE_IS_BSDF_MULTISCATTER(type) (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID ||\ type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID || \ - type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) + type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) #define CLOSURE_IS_BSDF_OR_BSSRDF(type) (type <= CLOSURE_BSSRDF_BURLEY_ID) #define CLOSURE_IS_BSSRDF(type) (type >= CLOSURE_BSSRDF_CUBIC_ID && type <= CLOSURE_BSSRDF_BURLEY_ID) #define CLOSURE_IS_VOLUME(type) (type >= CLOSURE_VOLUME_ID && type <= CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID) From df84082c70dafde0aa3a6a474f7885788e507ae1 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 21 Apr 2017 12:26:04 +0200 Subject: [PATCH 06/10] Cycles: Cleanup, indentation in preprocessor --- intern/cycles/kernel/kernel_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 623f3728c69..9d5cad3f3e1 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -220,7 +220,7 @@ CCL_NAMESPACE_BEGIN # undef __TRANSPARENT_SHADOWS__ #endif #ifdef __NO_SHADOW_TRICKS__ -#undef __SHADOW_TRICKS__ +# undef __SHADOW_TRICKS__ #endif /* Random Numbers */ From 099816587a0e064fb6a52c82a737ae8814cf21df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 21 Apr 2017 11:04:47 +0200 Subject: [PATCH 07/10] Alembic: Construct ISampleSelector once and pass along No longer passing time as float and constructing ISampleSelectors all over the place. Instead, just construct an ISampleSelector once and pass it along. --- source/blender/alembic/intern/abc_camera.cc | 3 +-- source/blender/alembic/intern/abc_camera.h | 4 +-- source/blender/alembic/intern/abc_curves.cc | 10 +++---- source/blender/alembic/intern/abc_curves.h | 7 +++-- source/blender/alembic/intern/abc_mesh.cc | 27 ++++++++++--------- source/blender/alembic/intern/abc_mesh.h | 14 +++++++--- source/blender/alembic/intern/abc_nurbs.cc | 3 +-- source/blender/alembic/intern/abc_nurbs.h | 2 +- source/blender/alembic/intern/abc_object.cc | 9 +++++++ source/blender/alembic/intern/abc_object.h | 13 ++++----- source/blender/alembic/intern/abc_points.cc | 17 ++++++------ source/blender/alembic/intern/abc_points.h | 10 ++++--- .../blender/alembic/intern/abc_transform.cc | 3 ++- source/blender/alembic/intern/abc_transform.h | 2 +- source/blender/alembic/intern/alembic_capi.cc | 12 +++++---- 15 files changed, 78 insertions(+), 58 deletions(-) diff --git a/source/blender/alembic/intern/abc_camera.cc b/source/blender/alembic/intern/abc_camera.cc index 4f70b2a972c..33344f6c9c5 100644 --- a/source/blender/alembic/intern/abc_camera.cc +++ b/source/blender/alembic/intern/abc_camera.cc @@ -117,11 +117,10 @@ bool AbcCameraReader::valid() const return m_schema.valid(); } -void AbcCameraReader::readObjectData(Main *bmain, float time) +void AbcCameraReader::readObjectData(Main *bmain, const ISampleSelector &sample_sel) { Camera *bcam = static_cast(BKE_camera_add(bmain, m_data_name.c_str())); - ISampleSelector sample_sel(time); CameraSample cam_sample; m_schema.get(cam_sample, sample_sel); diff --git a/source/blender/alembic/intern/abc_camera.h b/source/blender/alembic/intern/abc_camera.h index fafb4d3eb39..0201dd9d6e1 100644 --- a/source/blender/alembic/intern/abc_camera.h +++ b/source/blender/alembic/intern/abc_camera.h @@ -55,7 +55,7 @@ public: bool valid() const; - void readObjectData(Main *bmain, float time); + void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); }; -#endif /* __ABC_CAMERA_H__ */ \ No newline at end of file +#endif /* __ABC_CAMERA_H__ */ diff --git a/source/blender/alembic/intern/abc_curves.cc b/source/blender/alembic/intern/abc_curves.cc index bf485c7ef61..d85d8df4d77 100644 --- a/source/blender/alembic/intern/abc_curves.cc +++ b/source/blender/alembic/intern/abc_curves.cc @@ -211,7 +211,7 @@ bool AbcCurveReader::valid() const return m_curves_schema.valid(); } -void AbcCurveReader::readObjectData(Main *bmain, float time) +void AbcCurveReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) { Curve *cu = BKE_curve_add(bmain, m_data_name.c_str(), OB_CURVE); @@ -219,8 +219,6 @@ void AbcCurveReader::readObjectData(Main *bmain, float time) cu->actvert = CU_ACT_NONE; cu->resolu = 1; - const ISampleSelector sample_sel(time); - ICompoundProperty user_props = m_curves_schema.getUserProperties(); if (user_props) { const PropertyHeader *header = user_props.getPropertyHeader(ABC_CURVE_RESOLUTION_U_PROPNAME); @@ -389,9 +387,11 @@ void read_curve_sample(Curve *cu, const ICurvesSchema &schema, const ISampleSele * object directly and create a new DerivedMesh from that. Also we might need to * create new or delete existing NURBS in the curve. */ -DerivedMesh *AbcCurveReader::read_derivedmesh(DerivedMesh * /*dm*/, const float time, int /*read_flag*/, const char ** /*err_str*/) +DerivedMesh *AbcCurveReader::read_derivedmesh(DerivedMesh * /*dm*/, + const ISampleSelector &sample_sel, + int /*read_flag*/, + const char ** /*err_str*/) { - ISampleSelector sample_sel(time); const ICurvesSchema::Sample sample = m_curves_schema.getValue(sample_sel); const P3fArraySamplePtr &positions = sample.getPositions(); diff --git a/source/blender/alembic/intern/abc_curves.h b/source/blender/alembic/intern/abc_curves.h index 71b0d205820..1ad6d0bf278 100644 --- a/source/blender/alembic/intern/abc_curves.h +++ b/source/blender/alembic/intern/abc_curves.h @@ -55,8 +55,11 @@ public: bool valid() const; - void readObjectData(Main *bmain, float time); - DerivedMesh *read_derivedmesh(DerivedMesh *, const float time, int read_flag, const char **err_str); + void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); + DerivedMesh *read_derivedmesh(DerivedMesh *dm, + const Alembic::Abc::ISampleSelector &sample_sel, + int read_flag, + const char **err_str); }; /* ************************************************************************** */ diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc index 79b891dbcd4..39186ec55dc 100644 --- a/source/blender/alembic/intern/abc_mesh.cc +++ b/source/blender/alembic/intern/abc_mesh.cc @@ -1021,17 +1021,15 @@ bool AbcMeshReader::valid() const return m_schema.valid(); } -void AbcMeshReader::readObjectData(Main *bmain, float time) +void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) { Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str()); m_object = BKE_object_add_only_object(bmain, OB_MESH, m_object_name.c_str()); m_object->data = mesh; - const ISampleSelector sample_sel(time); - DerivedMesh *dm = CDDM_from_mesh(mesh); - DerivedMesh *ndm = this->read_derivedmesh(dm, time, MOD_MESHSEQ_READ_ALL, NULL); + DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, MOD_MESHSEQ_READ_ALL, NULL); if (ndm != dm) { dm->release(dm); @@ -1050,9 +1048,11 @@ void AbcMeshReader::readObjectData(Main *bmain, float time) } } -DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str) +DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm, + const ISampleSelector &sample_sel, + int read_flag, + const char **err_str) { - ISampleSelector sample_sel(time); const IPolyMeshSchema::Sample sample = m_schema.getValue(sample_sel); const P3fArraySamplePtr &positions = sample.getPositions(); @@ -1092,7 +1092,7 @@ DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm, const float time, } CDStreamConfig config = get_config(new_dm ? new_dm : dm); - config.time = time; + config.time = sample_sel.getRequestedTime(); bool do_normals = false; read_mesh_sample(&settings, m_schema, sample_sel, config, do_normals); @@ -1239,7 +1239,7 @@ bool AbcSubDReader::valid() const return m_schema.valid(); } -void AbcSubDReader::readObjectData(Main *bmain, float time) +void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) { Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str()); @@ -1247,7 +1247,7 @@ void AbcSubDReader::readObjectData(Main *bmain, float time) m_object->data = mesh; DerivedMesh *dm = CDDM_from_mesh(mesh); - DerivedMesh *ndm = this->read_derivedmesh(dm, time, MOD_MESHSEQ_READ_ALL, NULL); + DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, MOD_MESHSEQ_READ_ALL, NULL); if (ndm != dm) { dm->release(dm); @@ -1255,7 +1255,6 @@ void AbcSubDReader::readObjectData(Main *bmain, float time) DM_to_mesh(ndm, mesh, m_object, CD_MASK_MESH, true); - const ISampleSelector sample_sel(time); const ISubDSchema::Sample sample = m_schema.getValue(sample_sel); Int32ArraySamplePtr indices = sample.getCreaseIndices(); Alembic::Abc::FloatArraySamplePtr sharpnesses = sample.getCreaseSharpnesses(); @@ -1286,9 +1285,11 @@ void AbcSubDReader::readObjectData(Main *bmain, float time) } } -DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str) +DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm, + const ISampleSelector &sample_sel, + int read_flag, + const char **err_str) { - ISampleSelector sample_sel(time); const ISubDSchema::Sample sample = m_schema.getValue(sample_sel); const P3fArraySamplePtr &positions = sample.getPositions(); @@ -1328,7 +1329,7 @@ DerivedMesh *AbcSubDReader::read_derivedmesh(DerivedMesh *dm, const float time, /* Only read point data when streaming meshes, unless we need to create new ones. */ CDStreamConfig config = get_config(new_dm ? new_dm : dm); - config.time = time; + config.time = sample_sel.getRequestedTime(); read_subd_sample(&settings, m_schema, sample_sel, config); if (new_dm) { diff --git a/source/blender/alembic/intern/abc_mesh.h b/source/blender/alembic/intern/abc_mesh.h index 64a3109232c..1b67c80cc72 100644 --- a/source/blender/alembic/intern/abc_mesh.h +++ b/source/blender/alembic/intern/abc_mesh.h @@ -100,9 +100,12 @@ public: bool valid() const; - void readObjectData(Main *bmain, float time); + void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); - DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str); + DerivedMesh *read_derivedmesh(DerivedMesh *dm, + const Alembic::Abc::ISampleSelector &sample_sel, + int read_flag, + const char **err_str); private: void readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start, @@ -121,8 +124,11 @@ public: bool valid() const; - void readObjectData(Main *bmain, float time); - DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str); + void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); + DerivedMesh *read_derivedmesh(DerivedMesh *dm, + const Alembic::Abc::ISampleSelector &sample_sel, + int read_flag, + const char **err_str); }; /* ************************************************************************** */ diff --git a/source/blender/alembic/intern/abc_nurbs.cc b/source/blender/alembic/intern/abc_nurbs.cc index d0b9561f679..eaef06fd6d1 100644 --- a/source/blender/alembic/intern/abc_nurbs.cc +++ b/source/blender/alembic/intern/abc_nurbs.cc @@ -239,7 +239,7 @@ static bool set_knots(const FloatArraySamplePtr &knots, float *&nu_knots) return true; } -void AbcNurbsReader::readObjectData(Main *bmain, float time) +void AbcNurbsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) { Curve *cu = static_cast(BKE_curve_add(bmain, "abc_curve", OB_SURF)); cu->actvert = CU_ACT_NONE; @@ -253,7 +253,6 @@ void AbcNurbsReader::readObjectData(Main *bmain, float time) nu->resolu = cu->resolu; nu->resolv = cu->resolv; - const ISampleSelector sample_sel(time); const INuPatchSchema &schema = it->first; const INuPatchSchema::Sample smp = schema.getValue(sample_sel); diff --git a/source/blender/alembic/intern/abc_nurbs.h b/source/blender/alembic/intern/abc_nurbs.h index 1b2e7a8391f..abe460a8988 100644 --- a/source/blender/alembic/intern/abc_nurbs.h +++ b/source/blender/alembic/intern/abc_nurbs.h @@ -54,7 +54,7 @@ public: bool valid() const; - void readObjectData(Main *bmain, float time); + void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); private: void getNurbsPatches(const Alembic::Abc::IObject &obj); diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc index c8716d55218..4c3c060be28 100644 --- a/source/blender/alembic/intern/abc_object.cc +++ b/source/blender/alembic/intern/abc_object.cc @@ -160,6 +160,15 @@ void AbcObjectReader::object(Object *ob) m_object = ob; } +DerivedMesh *AbcObjectReader::read_derivedmesh(DerivedMesh *dm, + const Alembic::Abc::ISampleSelector &UNUSED(sample_sel), + int UNUSED(read_flag), + const char **UNUSED(err_str)) +{ + return dm; +} + + static Imath::M44d blend_matrices(const Imath::M44d &m0, const Imath::M44d &m1, const float weight) { float mat0[4][4], mat1[4][4], ret[4][4]; diff --git a/source/blender/alembic/intern/abc_object.h b/source/blender/alembic/intern/abc_object.h index d5344533b55..a9dbaa89c97 100644 --- a/source/blender/alembic/intern/abc_object.h +++ b/source/blender/alembic/intern/abc_object.h @@ -170,15 +170,12 @@ public: virtual bool valid() const = 0; - virtual void readObjectData(Main *bmain, float time) = 0; + virtual void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) = 0; - virtual DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str) - { - (void)time; - (void)read_flag; - (void)err_str; - return dm; - } + DerivedMesh *read_derivedmesh(DerivedMesh *dm, + const Alembic::Abc::ISampleSelector &sample_sel, + int read_flag, + const char **err_str); /** Reads the object matrix and sets up an object transform if animated. */ void setupObjectTransform(const float time); diff --git a/source/blender/alembic/intern/abc_points.cc b/source/blender/alembic/intern/abc_points.cc index fc84759b1d9..d5ecf16b793 100644 --- a/source/blender/alembic/intern/abc_points.cc +++ b/source/blender/alembic/intern/abc_points.cc @@ -151,12 +151,12 @@ bool AbcPointsReader::valid() const return m_schema.valid(); } -void AbcPointsReader::readObjectData(Main *bmain, float time) +void AbcPointsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) { Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str()); DerivedMesh *dm = CDDM_from_mesh(mesh); - DerivedMesh *ndm = this->read_derivedmesh(dm, time, 0, NULL); + DerivedMesh *ndm = this->read_derivedmesh(dm, sample_sel, 0, NULL); if (ndm != dm) { dm->release(dm); @@ -178,8 +178,7 @@ void AbcPointsReader::readObjectData(Main *bmain, float time) void read_points_sample(const IPointsSchema &schema, const ISampleSelector &selector, - CDStreamConfig &config, - float time) + CDStreamConfig &config) { Alembic::AbcGeom::IPointsSchema::Sample sample = schema.getValue(selector); @@ -189,7 +188,7 @@ void read_points_sample(const IPointsSchema &schema, N3fArraySamplePtr vnormals; if (has_property(prop, "N")) { - const Alembic::Util::uint32_t itime = static_cast(time); + const Alembic::Util::uint32_t itime = static_cast(selector.getRequestedTime()); const IN3fArrayProperty &normals_prop = IN3fArrayProperty(prop, "N", itime); if (normals_prop) { @@ -200,9 +199,11 @@ void read_points_sample(const IPointsSchema &schema, read_mverts(config.mvert, positions, vnormals); } -DerivedMesh *AbcPointsReader::read_derivedmesh(DerivedMesh *dm, const float time, int /*read_flag*/, const char ** /*err_str*/) +DerivedMesh *AbcPointsReader::read_derivedmesh(DerivedMesh *dm, + const ISampleSelector &sample_sel, + int /*read_flag*/, + const char ** /*err_str*/) { - ISampleSelector sample_sel(time); const IPointsSchema::Sample sample = m_schema.getValue(sample_sel); const P3fArraySamplePtr &positions = sample.getPositions(); @@ -214,7 +215,7 @@ DerivedMesh *AbcPointsReader::read_derivedmesh(DerivedMesh *dm, const float time } CDStreamConfig config = get_config(new_dm ? new_dm : dm); - read_points_sample(m_schema, sample_sel, config, time); + read_points_sample(m_schema, sample_sel, config); return new_dm ? new_dm : dm; } diff --git a/source/blender/alembic/intern/abc_points.h b/source/blender/alembic/intern/abc_points.h index cb68dbca4d5..1f74351d302 100644 --- a/source/blender/alembic/intern/abc_points.h +++ b/source/blender/alembic/intern/abc_points.h @@ -59,14 +59,16 @@ public: bool valid() const; - void readObjectData(Main *bmain, float time); + void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); - DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str); + DerivedMesh *read_derivedmesh(DerivedMesh *dm, + const Alembic::Abc::ISampleSelector &sample_sel, + int read_flag, + const char **err_str); }; void read_points_sample(const Alembic::AbcGeom::IPointsSchema &schema, const Alembic::AbcGeom::ISampleSelector &selector, - CDStreamConfig &config, - float time); + CDStreamConfig &config); #endif /* __ABC_POINTS_H__ */ diff --git a/source/blender/alembic/intern/abc_transform.cc b/source/blender/alembic/intern/abc_transform.cc index 6e218cac429..c48be361877 100644 --- a/source/blender/alembic/intern/abc_transform.cc +++ b/source/blender/alembic/intern/abc_transform.cc @@ -36,6 +36,7 @@ extern "C" { using Alembic::AbcGeom::OObject; using Alembic::AbcGeom::OXform; +using Alembic::Abc::ISampleSelector; /* ************************************************************************** */ @@ -153,7 +154,7 @@ bool AbcEmptyReader::valid() const return m_schema.valid(); } -void AbcEmptyReader::readObjectData(Main *bmain, float /*time*/) +void AbcEmptyReader::readObjectData(Main *bmain, const ISampleSelector &UNUSED(sample_sel)) { m_object = BKE_object_add_only_object(bmain, OB_EMPTY, m_object_name.c_str()); diff --git a/source/blender/alembic/intern/abc_transform.h b/source/blender/alembic/intern/abc_transform.h index 59388e155dc..f2e2edf8010 100644 --- a/source/blender/alembic/intern/abc_transform.h +++ b/source/blender/alembic/intern/abc_transform.h @@ -69,7 +69,7 @@ public: bool valid() const; - void readObjectData(Main *bmain, float time); + void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); }; #endif /* __ABC_TRANSFORM_H__ */ diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc index e44f66b7e56..52a87d7c165 100644 --- a/source/blender/alembic/intern/alembic_capi.cc +++ b/source/blender/alembic/intern/alembic_capi.cc @@ -704,12 +704,13 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa chrono_t min_time = std::numeric_limits::max(); chrono_t max_time = std::numeric_limits::min(); + ISampleSelector sample_sel(0.0f); std::vector::iterator iter; for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { AbcObjectReader *reader = *iter; if (reader->valid()) { - reader->readObjectData(data->bmain, 0.0f); + reader->readObjectData(data->bmain, sample_sel); min_time = std::min(min_time, reader->minTime()); max_time = std::max(max_time, reader->maxTime()); @@ -922,6 +923,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader, } const ObjectHeader &header = iobject.getHeader(); + ISampleSelector sample_sel(time); if (IPolyMesh::matches(header)) { if (ob->type != OB_MESH) { @@ -929,7 +931,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader, return NULL; } - return abc_reader->read_derivedmesh(dm, time, read_flag, err_str); + return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str); } else if (ISubD::matches(header)) { if (ob->type != OB_MESH) { @@ -937,7 +939,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader, return NULL; } - return abc_reader->read_derivedmesh(dm, time, read_flag, err_str); + return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str); } else if (IPoints::matches(header)) { if (ob->type != OB_MESH) { @@ -945,7 +947,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader, return NULL; } - return abc_reader->read_derivedmesh(dm, time, read_flag, err_str); + return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str); } else if (ICurves::matches(header)) { if (ob->type != OB_CURVE) { @@ -953,7 +955,7 @@ DerivedMesh *ABC_read_mesh(CacheReader *reader, return NULL; } - return abc_reader->read_derivedmesh(dm, time, read_flag, err_str); + return abc_reader->read_derivedmesh(dm, sample_sel, read_flag, err_str); } *err_str = "Unsupported object type: verify object path"; // or poke developer From 45b9ee525d718b151fec92bc5f9503f23e0a58bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 21 Apr 2017 12:28:49 +0200 Subject: [PATCH 08/10] Alembic: fixed memory leak --- source/blender/editors/io/io_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c index ebe8898571d..af6f55d7a64 100644 --- a/source/blender/editors/io/io_cache.c +++ b/source/blender/editors/io/io_cache.c @@ -143,7 +143,7 @@ static int cachefile_reload_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); - BLI_listbase_clear(&cache_file->object_paths); + BLI_freelistN(&cache_file->object_paths); BKE_cachefile_reload(bmain, cache_file); return OPERATOR_FINISHED; From 9d819775b719b6e1e838c833d7d4fb576503b2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 21 Apr 2017 12:47:14 +0200 Subject: [PATCH 09/10] Alembic: properly initialising cachefile object paths list. --- source/blender/blenkernel/intern/cachefile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 3dce08eb756..ff0a776aa82 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -82,6 +82,7 @@ void BKE_cachefile_init(CacheFile *cache_file) cache_file->is_sequence = false; cache_file->scale = 1.0f; cache_file->handle_mutex = BLI_mutex_alloc(); + BLI_listbase_clear(&cache_file->object_paths); } /** Free (or release) any data used by this cachefile (does not free the cachefile itself). */ From 9c02990ac13a25968d8ec15da15129617d3f25d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 21 Apr 2017 14:11:13 +0200 Subject: [PATCH 10/10] Alembic import: changing cache modifier path no longer discards object paths This allows, for example, the path of an Alembic file to be changed from absolute to relative, without having to reconstruct all object paths. --- source/blender/blenkernel/intern/cachefile.c | 2 -- tests/python/bl_alembic_import_test.py | 37 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index ff0a776aa82..67c66d4e40b 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -221,7 +221,6 @@ void BKE_cachefile_clean(Scene *scene, CacheFile *cache_file) } #endif mcmd->reader = NULL; - mcmd->object_path[0] = '\0'; } } @@ -239,7 +238,6 @@ void BKE_cachefile_clean(Scene *scene, CacheFile *cache_file) } #endif data->reader = NULL; - data->object_path[0] = '\0'; } } } diff --git a/tests/python/bl_alembic_import_test.py b/tests/python/bl_alembic_import_test.py index cd23183ec06..33ccc49f301 100644 --- a/tests/python/bl_alembic_import_test.py +++ b/tests/python/bl_alembic_import_test.py @@ -85,6 +85,43 @@ class SimpleImportTest(unittest.TestCase): for ob in bpy.data.objects: self.assertEqual('Cube' in ob.name, ob.select) + def test_change_path(self): + import math + + fname = 'cube-rotating1.abc' + abc = self.testdir / fname + relpath = bpy.path.relpath(str(abc)) + + res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False) + self.assertEqual({'FINISHED'}, res) + cube = bpy.context.active_object + + # Check that the file loaded ok. + bpy.context.scene.frame_set(10) + x, y, z = cube.matrix_world.to_euler('XYZ') + self.assertAlmostEqual(x, 0) + self.assertAlmostEqual(y, 0) + self.assertAlmostEqual(z, math.pi / 2, places=5) + + # Change path from absolute to relative. This should not break the animation. + bpy.context.scene.frame_set(1) + bpy.data.cache_files[fname].filepath = relpath + bpy.context.scene.frame_set(10) + + x, y, z = cube.matrix_world.to_euler('XYZ') + self.assertAlmostEqual(x, 0) + self.assertAlmostEqual(y, 0) + self.assertAlmostEqual(z, math.pi / 2, places=5) + + # Replace the Alembic file; this should apply new animation. + bpy.data.cache_files[fname].filepath = relpath.replace('1.abc', '2.abc') + bpy.context.scene.update() + + x, y, z = cube.matrix_world.to_euler('XYZ') + self.assertAlmostEqual(x, math.pi / 2, places=5) + self.assertAlmostEqual(y, 0) + self.assertAlmostEqual(z, 0) + def main(): global args